603 Database Systems
Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E.
Lecture 25Lecture 25
A First Course in Database Systems
Deductive Databases
RULES:
Although formally all variables in a clause are universally quantified, we will sometimes refer to variables that occur in the body of the clause, but not in its head, as if they are existentially quantified inside the body.
Deductive DatabasesExample:
grandfather rule can be read:
“For all X and Y, X is the grandfather of Y if there exists a Z such that X is the father of Z and Z is the father of Y.”
(X,Y){(grandfather(X, Y)) ( (Z) | father (X, Z),
father (Z, Y))}.
Deductive Databases
Incorporate rules into our framework of logical deduction:
To incorporate rules into our framework of logical deduction, we need the law of modus ponens.
Modus ponens states that from B and A B we can deduce A.
Deductive DatabasesThe Law of Universal Modus Ponens:
RULE: R = (A B1 , B2 , ……….Bn )
FACTS: B’1 .
B’ 2 .
.
.
B’ n .
A’ can be deduced, if
A’ B’1 , B’2 , ……….B’n is an instance of R.
Universal Modus Ponens include identity and instantiation as a special cases.
Deductive DatabasesComplete definition of the concept of a logic program and its associated concept of logical consequence:
Definition: A logic program is a finite set of rules.
Definition: An existentially quantified goal G is a logical consequence of a program P if there is a clause in P with a ground instance A B1 , B2 , ……….Bn , n 0,
such that are logical consequences of P and A is an instance of G.
Deductive DatabasesUniversal Modus Ponens:
Consider the query son(S, haran)?
Rule: son(X,Y) father (Y,X), male(X).
The substitution {X=lot, Y=haran} applied to the rule gives the instance
son(lot, haran) father (haran,lot), male(lot).
Both goals in the body of this rule are facts in the database.
Deductive DatabasesUniversal Modus Ponens:
In the previous query the modus ponens implies the query with answer S=lot.
The rule for son is correct, but is an incomplete specification of the relationship.
A new rule expressing this relationship can be added, namely
son(X,Y) mother(Y,X), male(X).
Deductive Databases
Grandparent rules:
grandparent(X,Y) father(X,Y), father(Y,Z).
grandparent(X,Y) father(X,Y), mother(Y,Z).
grandparent(X,Y) mother(X,Y), father(Y,Z).
grandparent(X,Y) mother(X,Y), mother(Y,Z).
More precise way of expressing these rules.
The Deductive Databases
Rules for son and grandparent:
son(X,Y) parent(Y,X), male(X).
grandparent(X,Y) parent(X,Z), parent(X,Y).
Deductive Databases
parent(X,Y) father(X,Y).
parent(X,Y) mother(X,Y).
A collection of rules with the same predicate in the head, such as the pair of parent rules , is called a procedure.
Deductive DatabasesAn abstract interpreter for logic programs:Input: A ground query Q and a program P
Output: yes if a proof of Q form P was found,
no otherwise
Algorithm:
Initialize the resolvent to Q
while the resolvent A1 , A2 , ……….An is not empty
begin
choose a goal Ai , 1 i n, and a ground instance of a clause A B1 , B2 , ……….Bn , n 0, in P, such that
A = Ai (If no such clause exists, exit the while loop);
determine the new resolvent
A1 ,... Ai-1 , ………. , B1 , B2 , ……….Bk , Ai+1 ,... An
end
If the resolvent is empty, output yes, otherwise output no.
Deductive DatabasesSimple Problem :
If Fido goes wherever John goes and if John is at
School, where is Fido?
Rule: (X ) [At (John, X) At(Fido, X)]
Fact: At(John, School)
Query: ( X ) At (Fido, X)?
Where is Fido?
Rule
Facts
QueryResultant fact(answers)
Deductive Database
Deductive DatabasesResolution Process(rule of inference):
Applied to a pair of parent clauses
Produce a derived clause (inferred clause)
Deductive DatabasesConversion of Predicate Calculus Formula into clausal form includes the following steps:
Step 1. Remove Implications
X [X, man(X) human(X)]
becomes X [X, ~ man(X) # human(X)]
Step 2. Moving negations inward
~ (human (caesar) & living (caesar))
becomes ~ human(caesar) # ~ living (caesar)
Deductive Databases
Conversion of Predicate Calculus Formula into clausal form includes the following steps(continued):
Step 3. Skolemising - removing existential
quantifiers
X (X, female(X) & mother of (X, eve))
etc.
Deductive DatabasesOnce we have the PC formula in clausal form we can then apply the resolution process to prove the goal!!
In resolution refutation, we first negate the goal and then add the negation to the set.
The set is then converted to a set of clauses and resolution is used to derive a contradiction, represented by an empty clause, NIL
Deductive Databases
When we get NIL,
The answer is provided.
Deductive Databases
Fact 1: (X ) [At (John, X) At(Fido, X)] =>Axiom 1
Fact 2: At(John, School)=> Axiom 2
Query:( X ) At (Fido, X)? => conjecture
Where is Fido?
Deductive Databases
Resolution Refutation:
Conjecture: ( X ) At (Fido, X)?
Negation of conjecture: ( X ) ~At (Fido, X)?
( X ) ~At (Fido, X) in clausal form is ~At (Fido, X)
Deductive DatabasesRefutation TREE(negate the goal):~At (Fido, X) ~At (John, X) # At(Fido, X)
(negation of conjecture) (Axiom 1)
~At (John, X) At(John, School)
(Axiom 2)
NIL (X ) [At (John, X) At(Fido, X)]
in clausal form becomes ~At (John, X) # At(Fido, X) and ~At (Fido, X) + ~At (John, X) # At(Fido, X) becomes ~At (John, X)
~At (John, X) + At(John, School)
becomes NIL
Deductive DatabasesExtracting the Answer:
~At (Fido, X) # At(Fido, X) ~At (John, X) # At(Fido, X)
~At (John, X) # At(Fido, X)
At (John, School)
At (Fido, School)
X get bound to School
Deductive Databases
Company Database:
Facts: supervise(franklin, john).
supervise(franklin, ramesh).
supervise(franklin, joyce).
supervise(jennifer, alicia).
supervise(jennifer, ahmad).
supervise(james, franklin).
supervise(james, jennifer).
...
Deductive Databases
Rules:
superior(X,Y):- supervise(X,Y).
superior(X,Y):- supervise(X,Z), superior(Z,Y).
subordinate(X,Y):-superior(Y,X).
Queries:
superior(james, Y)?
superior(james,joyce)?
Deductive Databases
The supervisory TREE:
james
franklin jennifer
john ramesh joyce alicia ahmad
Deductive DatabasesFact: supervise predicate
Rules: superior predicate
superior predicate
subordinate predicate
head :- body
conclusion premise
Deductive DatabaseQueries:
superior (james, Y)?
superior (james, joyce)?
NOTE: predicate with constant as
argument => ground or instantiated predicate!!
Deductive Databases
Next Lecture
MORE Deductive
Databases