Title: Discussion
1Discussion 19Resolution with Predicate
Calculus
2Topics
- Horn Clauses
- Dropping Quantifiers
- Unification
- Resolution
3Horn Clause
- For resolution, the premises are in CNF.
- CNF ( ? ? ) ? ( ? ? ) ? ? ( ? ? )
- Each ( ? ? ) is a clause.
- A horn clause is a disjunction of literals that
contains at most one positive (non-negative)
literal. - Horn clause P ? ?Q ? ?R
- Horn clause P
- Horn clause ?P
- Not a horn clause P ? Q ? ?R ? too many positive
literals - Note that, in general, a horn clause is an
implication with a conjunction of all positive
literals on the lhs and one positive
(non-negated) literal on the rhs. - Horn clause P ? ?Q ? ?R ? ?Q ? ?R ? P ? ?(Q ? R)
? P - ? (Q ? R) ? P
- Degenerate cases
- Horn clause P ? F ? P ? ?T ? P ? T ? P
- Horn clause ?P ? ?P ? F ? P ? F
- Horn clause ?P1 ? ?P2 ? ? ?Pn ? ?(P1 ? P2 ?
? Pn) ? F - ? P1 ? P2 ? ? Pn ? F
- Not a horn clause P ? Q ? ?R ? ?R ? P ? Q ? R ?
(P ? Q)
4Horn Clauses Appear in 3 Forms
- One positive literal and one or more negative
literals. - e.g. P ? ?Q ? ?R ? (Q ? R) ? P
- These are the Datalog rules.
- One positive literal and no negative literals.
- i.e. P ? T ? P
- We see P by itself as being true.
- These are the Datalog facts.
- No positive literal.
- ?P ? P ? F or ?P1 ? ?P2 ? ? ?Pn ? P1 ? P2 ? ?
Pn ? F - When the consequent is false, we wonder whats
going on. - These are the Datalog queries ? either one query
or several.
5Horn Clauses with Variables and Quantifiers
- For horn clauses in Datalog, we put all clauses
in Prenex Normal Form. - Further, to be a valid horn clause, all variables
must be universally quantified. - Sample horn clauses with variables and
quantifiers - ?x?y?z(?P(x,y) ? ?Q(x,z) ? R(z))
- ?x(?R(x))
- Now we discard the universal quantifiers but
dont forget them. One consequence is that
variables are local to their own horn clause
(i.e. the xs in P and Q are the same x, but the
xs in P and R are different). - ?P(x,y) ? ?Q(x,z) ? R(z)
- ?R(x)
- We then convert the horn clauses to implications
with all positive literals. - P(x,y) ? Q(x,z) ? R(z)
- R(x) ? F
- Finally, we modify the syntax so that it
corresponds to Datalog. - R(z) - P(x,y),Q(x,z)
- R(x)?
6Instantiation Resolution
- Because every variable is universally quantified,
we can instantiate it to any (and every) constant
in the domain. (We are in context of a
derivation, so all statements are true either by
assumption, premise, or by a rule of inference.) - R(a) - P(x,y),Q(x,a) Sza
- R(a)? Sxa
- So, were asking if R(a) is true, but the rule
says that R(a) is true if - P(x,y) ? Q(x,a) is true. Formally, we are doing
resolution - ?P(x,y) ? ?Q(x,a) ? R(a)
- ?R(a)
- ?P(x,y) ? ?Q(x,a)
- We can resolve only when the complementary
literals are instantiated identically (unified).
R(a) ? ?P(x,y) ? ?Q(x,a) ?R(a) ?P(x,y) ?
?Q(x,a)
7Example
- If R(x,y) ? P(x,z) ? Q(z,y)
- P(a,b)
- Q(b,j)
- Q(b,k)
- Then R(a,j)
- support 1. ?P(x,z) ? ?Q(z,y) ? R(x,y)
- strategy 2. P(a,b)
- 3. Q(b,j)
- 4. Q(b,k)
- 5. ?R(a,j) ?conclusion
- unification 6. ?P(a,z) ? ?Q(z,j) ? R(a,j) UI,
Sxa Syj - 7. ?P(a,z) ? ?Q(z,j) res 5,6
- unification 8. ?P(a,b) ? ?Q(b,j) Szb
- 9. ?Q(b,j) res 2,8
- 10. (succeed!) res 9,3
Domain a,b,j,k
8Example ? Same, but with Meaning
- If aunt(x,y) ? sister(x,z) ? parent(z,y)
- sister(ann,bob)
- parent(bob,jay)
- parent(bob,kay)
- Then aunt(ann,jay)
- 1. ?sister(x,z) ? ?parent(z,y) ? aunt(x,y)
- 2. sister(ann,bob)
- 3. parent(bob,jay)
- 4. parent(bob,kay)
- 5. ?aunt(ann,jay) ?conclusion
- 6. ?sister(ann,z) ? ?parent(z,jay) ?
aunt(ann,jay) UI, Sxann Syjay - 7. ?sister(ann,z) ? ?parent(z,jay) res 5,6
- 8. ?sister(ann,bob) ? ?parent(bob,jay) Szbob
- 9. ?sister(ann,bob) res 3,8
- 10. (succeed!) res 2,9
Domain ann,bob,jay,kay
9Example ? in CS236 Datalog Notation
- Facts
- sister('ann','bob').
- parent('bob','jay').
- parent('bob','kay').
- Rules
- aunt(x,y) - sister(x,z), parent(z,y).
- Queries
- aunt('ann','jay')?
- Observe for aunt('ann','jay') we have exactly
the previous proof! - Output yes.
10Example ? with Variables
- What do we do for aunt('ann',x)?
- Try all proofs with all substitutions from the
domain ? if a substituted value v for x works,
output v. - Whats the domain? Usual choice is all constants
in the facts 'ann', 'bob', 'jay', 'kay' - Try first to prove aunt('ann','ann'). (Assume
support strategy) - 1. ?aunt('ann','ann') ?conclusion
- 2. aunt('ann','ann') - sister('ann',z),
parent(z,'ann'). Sxann - Now observe that the resolution of 1 2 is
- ?sister('ann',z) ? ?parent(z,'ann') (s?p)?a ?
?(s?p)?a - And that this is only F if both sister('ann',z)
and parent(z,'ann') are T. Thus, we can
essentially start over and prove these using
resolution one at a time as sub-proofs.
11- 1. ?aunt('ann',x) ?conclusion
- 2. ?aunt('ann','ann') Sxann
- 3. aunt('ann','ann') - sister('ann',z),
parent(z,'ann'). Sxann Syann
3a. ?sister('ann',z) ?conclusion 3b.
?sister('ann','ann') Szann 3c. (fail!) cant
resolve, no fact sister('ann','ann')
So, we try the next element of the domain for z,
namely, bob. 3a. ?sister('ann',z) ?conclusion
3b. ?sister('ann','bob') Szbob 3c.
(succeed!) resolution with fact
sister('ann','bob')
Great! Lets try the 2nd half with bob (the zs
must be the same). 3d. ?parent(z,'ann') ?conclu
sion 3e. ?parent('bob','ann') Szbob 3f.
(fail!) again, no fact parent('bob','ann') In
fact, z'jay', z'kay' all fail on both sister
and parent. So, we backtrack to step 2 and try
the next element of the domain for x, namely,
'bob'.
12- Continuing
- 2. ?aunt('ann','bob') ?conclusion w/Sxbob
- 3. aunt('ann','bob') - sister('ann',z),
parent(z,'bob'). Sxann Sybob - 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','ann') Szann
- 3c. (fail!) no fact sister('ann','ann')
- So, we try the next element of the domain for z,
namely, bob. - 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','bob') Szbob
- 3c. (succeed!) res with fact
sister('ann','bob') - 3d. ?parent(z,'bob') ?conclusion
- 3e. ?parent('bob','bob') Szbob
- 3f. (fail!) no fact parent('bob','bob')
- Further, z'jay' fails, z'kay' fails, so, we
backtrack again.
13- Continuing with next element in domain for x,
namely 'jay' - 2. ?aunt('ann','jay') Sxjay
- 3. aunt('ann','jay') - sister('ann',z),
parent(z,'jay'). Sxann Syjay - 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','ann') Szann
- 3c. (fail!) no fact sister('ann','ann')
- 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','bob') Szbob
- 3c. (succeed!) res with fact
sister('ann','bob') - 3d. ?parent(z,'jay') ?conclusion
- 3e. ?parent('bob','jay') Szbob
- 3f. (succeed!) res with fact
parent('bob','jay') - So, both sub-proofs are satisfied and we output
x'jay'. - Are there any more?
- From what point do we continue?
14- We can continue from as if we had failed,
choosing the next element in domain for z, namely
'jay' - 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','jay') Szjay
- 3c. (fail!) no fact sister('ann','jay')
- 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','kay') Szkay
- 3c. (fail!) no fact sister('ann','kay')
- So, we again backtrack to step 2 and the next
element for x - (Alternatively, since we have succeeded, we can
jump back to the query and try the next element
of the domain at that level.)
15- Try to resolve using last element of domain for
x, namely, 'kay' - 2. ?aunt('ann','kay') Sxkay
- 3. aunt('ann','kay') - sister('ann',z),
parent(z,'kay'). Sxann Sykay - 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','ann') Szann
- 3c. (fail!) no fact sister('ann','ann')
- 3a. ?sister('ann',z) ?conclusion
- 3b. ?sister('ann','bob') Szbob
- 3c. (succeed!) res with fact
sister('ann','bob') - 3d. ?parent(z,'kay') ?conclusion
- 3e. ?parent('bob','kay') Szbob
- 3f. (succeed!) res with fact
parent('bob','kay') - So, we output x'kay'.
- Continuing, as if we had failed, we try z 'jay'
and z 'kay', which both fail. (Alternatively,
since we succeeded, we can jump back to the query
and try the next element of the domain at that
level.) Weve tried all possible substitutions,
so were done.
16High-Level Overview
Sx'ann'
Fail (sister)
'ann'
'ann'
Fail (parent)
'bob'
Fail (sister)
'jay'
Fail (sister)
'kay'
Fail (sister)
'ann'
'bob'
Fail (parent)
'bob'
Fail (sister)
'jay'
Fail (sister)
'kay'
Fail (sister)
'ann'
'jay'
Facts sister('ann','bob').
parent('bob','jay'). parent('bob','kay'). Rule
s aunt(x,y) - sister(x,z),
parent(z,y). Queries aunt('ann',x)?
Succeeds!
'bob'
Fail (sister)
'jay'
Fail (sister)
'kay'
Fail (sister)
'ann'
'kay'
Succeeds!
'bob'
Fail (sister)
'jay'
Fail (sister)
'kay'
17- Thank goodness computers can do this faster and
better than we can. - Project 3