Professional Documents
Culture Documents
Outline
• What is a deductive database system?
• Some basic concepts
• Basic inference mechanism for logic programs
• Datalog programs and their evaluation
Deductive Databases
Deductive
Database + Inference
database
By evaluating rules against facts, new facts can be derived, which in turn
can be used to answer queries. It makes a database system more powerful.
Deductive Databases
- term
A term is a constant, a variable or an expression
of the form f(t1, t2, ..., tn), where t1, t2, ..., tn are
terms and f is a function symbol.
- Example: a, b, c, f(a, b), g(a, f(a, b)), x, y,
g(x, y)
- n-ary predicate
An n-ary predicate symbol is a symbol p
appearing in an expression of the form p(t1, t2, ..., tn),
called an atom, where t1, t2, ..., tn are terms. p(t1, t2, ...,
tn) can only evaluate to true or false.
- Example: p(a, b), q(a, f(a, b)), p(x, y)
Deductive Databases
- literal
A literal is either an atom or its negation.
- Example: p(a, f(a, b)), p(a, f(a, b))
- (well-formed) formula
- A well-formed (logic) formula is defined
inductively as follows:
- An atom is a formula.
- If P and Q are formulas, then so are P,
(PQ), (PQ), (PQ), and (PQ).
- If x is a variable and P is a formula containing
x, then (xP) and (xP) are formulas.
Deductive Databases
- clause
- A clause is an expression of the following
form:
A1 A2 ... An B1 ... Bm
where Ai and Bj are atoms.
- The above expression can be written in the
following equivalent form:
consequent B1 ... Bm A1 ... An
antecedent
or
B1, ..., Bm A1 , ..., An
Deductive Databases
- clause
A B A B A B BA
1 1 1 1 1 1
0 1 1 0 1 1
1 0 0 1 0 0
0 0 1 0 0 1
- Horn clause
A Horn clause is a clause with the head containing only
one positive atom.
Bm A1 , ..., An
Deductive Databases
- fact
- A fact is a special Horn clause of the following
form:
B
with all variables in B being instantiated. (B
can be simply written as B.)
- logic program
A logic program is a set of Horn clauses.
Deductive Databases
Facts:
james
supervise(franklin, john),
supervise(franklin, ramesh),
supervise(franklin, joyce) franklin jennifer
supervise(james, franklin),
supervise(jennifer, alicia),
supervise(jennifer, ahmad),
john ramesh joyce alicia ahmad
supervise(james, jennifer).
Rules:
superior(X, Y) supervise(X, Y),
superior(X, Y) supervise(X, Z), superior(Z, Y),
subordinary(X, Y) superior(Y, X).
Deductive Databases
- Example:
- Example:
1. superior(X, Y) supervise(X, Y). (rule 1)
2. superior(X, Y) supervise(X, Z), superior(Z, Y). (rule 2)
known facts:
supervise(franklin, john), supervise(franklin, ramesh),
supervise(franklin, joyce), supervise(james, franklin),
supervise(jennifer, alicia), supervise(jennifer, ahmad),
supervise(james, jennifer).
For all other possible (X, Y) combinations supervise(X, Y) is false.
derived facts:
superior(franklin, john), superior(franklin, ramesh),
superior(franklin, joyce), superior(jennifer, alicia),
superior(jennifer, ahmad), superior(james, franklin),
superior(james, jennifer), superior(james, john),
superior(james, ramesh), superior(james, joyce),
superior(james, alicia), superior(james, ahmad).
For all other possible (X, Y) combinations superior(X, Y) is false.
Deductive Databases
The above interpretation is also a model for the rules (1) and (2) since each
of them evaluates always to true under the interpretation. For example,
superior(X, Y) supervise(X, Y)
The model is also the minimal model for the rule (1) and (2) and the
corresponding facts since eliminating any element from the model
will make some facts or instatiated rules evaluate to false.
For example,
eliminating supervise(franklin, john) from the model will make this fact
no more true under the interpretation;
- Inference mechanism
In general, there are two approaches to evaluating logical
programs: bottom-up and top-down.
- Bottom-up mechanism
(also called forward chaining and bottom-up resolution)
1. The inference engine starts with the facts and applies
the rules to generate new facts. That is, the inference
moves forward from the facts toward the goal.
2. As facts are generated, they are checked against the
query predicate goal for a match.
Deductive Databases
- Example
query goal: superior(james, Y)?
rules and facts are given as above.
- Example:
1. superior(X, Y) supervise(X, Y). (rule 1)
2. superior(X, Y) supervise(X, Z), superior(Z, Y). (rule 2)
known facts:
supervise(franklin, john), supervise(franklin, ramesh),
supervise(franklin, joyce), supervise(james, franklin),
supervise(jennifer, alicia), supervise(jennifer, ahmad),
supervise(james, jennifer).
For all other possible (X, Y) combinations supervise(X, Y) is false.
domain = {james, franklin, john, ramesh, joyce, jennifer, alicia, ahmad}
superior(james, Y)?
- Top-down mechanism
(also called back chaining and top-down resolution)
1. The inference engine starts with the query goal and
attempts to find matches to the variables that lead to
valid facts in the database. That is, the inference moves
backward from the intended goal to determine facts that
would satisfy the goal.
2. During the course, the rules are used to generate
subgoals. The matching of these subgoals will lead to
the match of the intended goal.
Deductive Databases
- Example
query goal: ?-superior(james, Y)
rules and facts are given as above.
Query: ?-superior(james, Y)
supervise(james, Z)
Z=frankiln Z=jennifer
superior(franklin, Y) superior(jennifer, Y)
Deductive Databases
- Condition of safty:
A rule is safe if each variable in it is limited.
A program is safe if each rule in it is safe.
Deductive Databases
Exampel:
superior(X, Y) supervise(X, Y),
superior(X, Y) supervise(X, Z), superior(Z, Y),
subordinary(X, Y) superior(Y, X),
supervisor(X, Y) employee(X), supervise(X, Y),
over_40K_emp(X) employee(X), salary(X, Y), Y40000,
under_40K_supervisor(X) supervisor(X), not(over_40K_emp(X)),
main_productx _emp(X ) employee(X), workson(X, productx, Y), Y 20,
president(X) employee(X), not(supervise(Y, X)).
Deductive Databases
supervisor under_40K_supervisor
subordinate
g0 = ,
gi+1 = E(gi),
If there exits some g such that g = E(g), g is called the fixed point.
The least among all fixed points of E(...) is called the least fixed
point.
- evaluation of fixed points
If at some time we have E i(g0) = E i+1(g0),
E i(g0) = E (E( ... E(g0) ... )) then E i(g0) is the fixed point of the
i function E(...). It is also the least fixed
point of E(...).
Deductive Databases
Example:
a(X, Y) = p(X, Y) X,Y(p(X, Z) a(Z, Y))
p = {(f, j), (f, r), (f, jo), (je, a), (je, ah), (ja, f), (ja, je)}
a0 = { }
a1 = {(f, j), (f, r), (f, jo), (je, a), (je, ah), (ja, f), (ja, je)}
a2 = {(f, j), (f, r), (f, jo), (je, a), (je, ah), (ja, f), (ja, je),
(ja, j), (ja, r), (ja, jo), (ja, a), (ja, ah)}
a3 = a2 least fixed point
The least fixed point of the above equation is also called the
transitive closure of p.
Deductive Databases
sg = E1(sg, sibling) sg R1
sibling = E2(sibling) sibling R2
R1 = E1(R1, R2)
R2 = E2(R2)
Deductive Databases
bert
alice george
derek pat
frank
Deductive Databases
Jacobi: Gauss-Seidel:
The advantage of the semi-naive method is that at each step a differential term
Di is used in each equation instead of the whole Ri. In this way, the time
complexity of a computation is decreased drastically.
Deductive Databases
Two-phase evaluation:
1st phase: evaluate magic rules to generate a magic set.
2nd phase: evaluate modified rules, by which that magic
set is used to restrict the computation.
Deductive Databases