PL Model Checking Efficient PL Model Checking
PL Model Checking Efficient PL Model Checking
– If ∀M ¬S, then S is provably false • WALKSAT: Local search for satisfiability: Pick a symbol
to flip (toggle TRUE/FALSE), either using min-conflicts or
– Otherwise (∃M1 S ∧ ∃M2 ¬S): S is satisfiable choosing randomly
but neither provably true or provably false • …or you can use any local or global search algorithm!
1
Reminder: Inference rules for FOL
• Inference rules for propositional logic apply to
FOL as well
Automating FOL
– Modus Ponens, And-Introduction, And-Elimination, …
• New (sound) inference rules for use with
inference
quantifiers:
– Universal elimination
– Existential introduction
with Generalized
– Existential elimination
– Generalized Modus Ponens (GMP)
Modus Ponens
2
Generalized Modus Ponens Our rules are Horn clauses
• General case: Given • A Horn clause is a sentence of the form:
– atomic sentences P1, P2, ..., PN P1(x) ∧ P2(x) ∧ ... ∧ Pn(x) → Q(x)
– implication sentence (Q1 ∧ Q2 ∧ ... ∧ QN) → R where
• Q1, ..., QN and R are atomic sentences
– ≥ 0 Pis and 0 or 1 Q
– substitution subst(θ, Pi) = subst(θ, Qi) for i=1,...,N
– the Pis and Q are positive (i.e., non-negated) literals
– Derive new sentence: subst(θ, R)
• Substitutions • Equivalently: P1(x) ∨ P2(x) … ∨ Pn(x) where the
– subst(θ, α) denotes the result of applying a set of Pi are all atomic and at most one is positive
substitutions defined by θ to the sentence α • Prolog is based on Horn clauses
– A substitution list θ = {v1/t1, v2/t2, ..., vn/tn} means to
replace all occurrences of variable symbol vi by term ti • Horn clauses represent a subset of the set of
– Substitutions made in left-to-right order in the list sentences representable in FOL
– subst({x/Cheese, y/Mickey}, eats(y,x)) =
eats(Mickey, Cheese)
3
Forward & Backward Reasoning Forward chaining
• We usually talk about two reasoning strategies:
Forward and backward ‘chaining’ • Proofs start with the given axioms/premises in
• Both are equally powerful KB, deriving new sentences using GMP until
the goal/query sentence is derived
• You can also have a mixed strategy
• This defines a forward-chaining inference
procedure because it moves “forward” from the
KB to the goal [eventually]
• Inference using GMP is sound and complete
for KBs containing only Horn clauses
4
Backward chaining Backward chaining algorithm
• Backward-chaining deduction using GMP is also
complete for KBs containing only Horn clauses
• Proofs start with the goal query, find rules with that
conclusion, and then prove each of the antecedents
in the implication
• Keep going until you reach premises
• Avoid loops: check if new subgoal is already on
the goal stack
• Avoid repeated work: check if new subgoal
– Has already been proved true
– Has already failed
5
Mixed strategy Completeness of GMP
• Many practical reasoning systems do both forward • GMP (using forward or backward chaining) is
and backward chaining complete for KBs that contain only Horn clauses
• The way you encode a rule determines how it is • not complete for simple KBs with non-Horn clauses
used, as in • The following entail that S(A) is true:
% this is a forward chaining rule 1. (∀x) P(x) → Q(x)
spouse(X,Y) => spouse(Y,X). 2. (∀x) ¬P(x) → R(x)
% this is a backward chaining rule 3. (∀x) Q(x) → S(x)
wife(X,Y) <= spouse(X,Y), female(X). 4. (∀x) R(x) → S(x)
• Given a model of the rules you have and the kind • If we want to conclude S(A), with GMP we cannot,
of reason you need to do, it’s possible to decide since the second one is not a Horn clause
which to encode as FC and which as BC rules. • It is equivalent to P(x) ∨ R(x)
FOL Inference
2. r(X) :- neg(p(X)).
3. (∀x) Q(x) → S(x)
3. s(X) :- q(X).
4. (∀x) R(x) → S(x)
4. s(X) :- r(X).
– We should not use \+ or not (in SWI) for negation
since it means “negation as failure”
– Prolog explores possible proofs independently
with Resolution
– It can’t take a larger view and realize that one
branch must be true since p(x) ∨ ~p(x) is always true
6
Resolution
Resolution covers many cases
• Resolution is a sound and complete inference
procedure for unrestricted FOL • Modes Ponens
• Reminder: Resolution rule for propositional logic: – from P and P → Q derive Q
– P1 ∨ P2 ∨ ... ∨ Pn – from P and ¬ P ∨ Q derive Q
– ¬P1 ∨ Q2 ∨ ... ∨ Qm • Chaining
– Resolvent: P2 ∨ ... ∨ Pn ∨ Q2 ∨ ... ∨ Qm – from P → Q and Q → R derive P → R
• We’ll need to extend this to handle – from (¬ P ∨ Q) and (¬ Q ∨ R) derive ¬ P ∨ R
quantifiers and variables • Contradiction detection
– from P and ¬ P derive false
– from P and ¬ P derive the empty clause (=false)
7
A resolution proof tree Resolution refutation
~P(w) v Q(w) ~Q(y) v S(y)
• Given a consistent set of axioms KB and goal sentence Q,
show that KB |= Q
~True v P(x) v R(x) • Proof by contradiction: Add ¬Q to KB and try to prove
P(x) v R(x) false, i.e.:
(KB |- Q) ↔ (KB ∧ ¬Q |- False)
• Resolution is refutation complete: it can establish that a
~P(w) v S(w)
~R(w) v S(w)
given sentence Q is entailed by KB, but can’t (in general)
generate all logical consequences of a set of sentences
• Also, it cannot be used to prove that Q is not entailed by KB
• Resolution won’t always give an answer since entailment is
S(x) v R(x)
only semi-decidable
– And you can’t just run two proofs in parallel, one trying to prove Q and
the other trying to prove ¬Q, since KB might not entail either one
S(A)
Notation
old/new false
negated query
8
questions to be answered
• How to convert FOL sentences to conjunctive normal
form (a.k.a. CNF, clause form): normalization and
skolemization
Converting
• How to unify two argument lists, i.e., how to find their
most general unifier (mgu) q: unification
• How to determine which two clauses in KB should be
to CNF
resolved next (among all resolvable pairs of clauses) :
resolution (search) strategy
9
Converting sentences to clausal form An example
(∀x)(P(x) → ((∀y)(P(y) → P(f(x,y))) ∧ ¬(∀y)(Q(x,y) → P(y))))
6. Remove universal quantifiers by (1) moving them all to the
2. Eliminate →
left end; (2) making the scope of each the entire sentence;
and (3) dropping the “prefix” part (∀x)(¬P(x) ∨ ((∀y)(¬P(y) ∨ P(f(x,y))) ∧ ¬(∀y)(¬Q(x,y) ∨ P(y))))
Ex: (∀x)P(x) ⇒ P(x) 3. Reduce scope of negation
(∀x)(¬P(x) ∨ ((∀y)(¬P(y) ∨ P(f(x,y))) ∧(∃y)(Q(x,y) ∧ ¬P(y))))
7. Put into conjunctive normal form (conjunction of
disjunctions) using distributive and associative laws 4. Standardize variables
(P ∧ Q) ∨ R ⇒ (P ∨ R) ∧ (Q ∨ R) (∀x)(¬P(x) ∨ ((∀y)(¬P(y) ∨ P(f(x,y))) ∧(∃z)(Q(x,z) ∧ ¬P(z))))
5. Eliminate existential quantification
(P ∨ Q) ∨ R ⇒ (P ∨ Q ∨ R)
(∀x)(¬P(x) ∨((∀y)(¬P(y) ∨ P(f(x,y))) ∧(Q(x,g(x)) ∧ ¬P(g(x)))))
8. Split conjuncts into separate clauses
6. Drop universal quantification symbols
9. Standardize variables so each clause contains only variable
names that do not occur in any other clause (¬P(x) ∨ ((¬P(y) ∨ P(f(x,y))) ∧(Q(x,g(x)) ∧ ¬P(g(x)))))
Example
7. Convert to conjunction of disjunctions
(¬P(x) ∨ ¬P(y) ∨ P(f(x,y))) ∧ (¬P(x) ∨ Q(x,g(x))) ∧
Unification
(¬P(x) ∨ ¬P(g(x)))
8. Create separate clauses
¬P(x) ∨ ¬P(y) ∨ P(f(x,y))
¬P(x) ∨ Q(x,g(x))
¬P(x) ∨ ¬P(g(x))
9. Standardize variables
¬P(x) ∨ ¬P(y) ∨ P(f(x,y))
¬P(z) ∨ Q(z,g(z))
¬P(w) ∨ ¬P(g(w))
10
Unification Unification algorithm
• Unification is a “pattern-matching” procedure procedure unify(p, q, θ)
– Takes two atomic sentences, called literals, as input Scan p and q left-to-right and find the first corresponding
terms where p and q “disagree” (i.e., p and q not equal)
– Returns “Failure” if they do not match and a
If there is no disagreement, return θ (success!)
substitution list, θ, if they do
Let r and s be the terms in p and q, respectively,
• That is, unify(p,q) = θ means subst(θ, p) = subst(θ, q) for where disagreement first occurs
two atomic sentences, p and q If variable(r) then {
• θ is called the most general unifier (mgu) Let θ = union(θ, {r/s})
• All variables in the given two literals are implicitly Return unify(subst(θ, p), subst(θ, q), θ)
} else if variable(s) then {
universally quantified
Let θ = union(θ, {s/r})
• To make literals match, replace (universally quantified) Return unify(subst(θ, p), subst(θ, q), θ)
variables by terms } else return “Failure”
end
11
Practice example
Did Curiosity kill the cat
Resolution
• Jack owns a dog
• Every dog owner is an animal lover
• No animal lover kills an animal
• Either Jack or Curiosity killed the cat, who is named Tuna.
example
• Did Curiosity kill the cat?
∃x Dog(x) ∧ Owns(Jack,x)
∀x (∃y) Dog(y) ∧ Owns(x, y) →
Practice example AnimalLover(x)
∀x AnimalLover(x) → (∀y Animal(y) →
Did Curiosity kill the cat • Convert to clause form ¬Kills(x,y))
Kills(Jack,Tuna) ∨ Kills(Curiosity,Tuna)
Cat(Tuna)
• Jack owns a dog. Every dog owner is an animal lover. No A1. (Dog(D)) ∀x Cat(x) → Animal(x)
animal lover kills an animal. Either Jack or Curiosity killed Kills(Curiosity, Tuna)
the cat, who is named Tuna. Did Curiosity kill the cat? A2. (Owns(Jack,D))
• These can be represented as follows: B. (¬Dog(y), ¬Owns(x, y), AnimalLover(x))
A. (∃x) Dog(x) ∧ Owns(Jack,x) C. (¬AnimalLover(a), ¬Animal(b), ¬Kills(a,b))
B. (∀x) ((∃y) Dog(y) ∧ Owns(x, y)) → AnimalLover(x) D. (Kills(Jack,Tuna), Kills(Curiosity,Tuna))
C. (∀x) AnimalLover(x) → ((∀y) Animal(y) → ¬Kills(x,y))
E. Cat(Tuna)
D. Kills(Jack,Tuna) ∨ Kills(Curiosity,Tuna)
E. Cat(Tuna) F. (¬Cat(z), Animal(z))
F. (∀x) Cat(x) → Animal(x) GOAL • Add the negation of query:
G. Kills(Curiosity, Tuna) ¬G: ¬Kills(Curiosity, Tuna)
12
The proof tree
The resolution refutation proof
¬G D
R1: ¬G, D, {} (Kills(Jack, Tuna)) {}
search
clauses produced by KB and the negation of the goal
• When a pair of clauses generates a new resolvent
clause, add a new node to the tree with arcs directed
from the resolvent to the two parent clauses
strategies
• Resolution succeeds when a node containing the False
clause is produced, becoming the root node of the tree
• A strategy is complete if its use guarantees that the
empty clause (i.e., false) can be derived whenever it is
entailed
13
Strategies Example
• There are a number of general (domain-independent) 1. Battery-OK ∧ Bulbs-OK → Headlights-Work
strategies that are useful in controlling a resolution 2. Battery-OK ∧ Starter-OK → Empty-Gas-Tank ∨ Engine-Starts
theorem prover
3. Engine-Starts → Flat-Tire ∨ Car-OK
• We’ll briefly look at the following:
4. Headlights-Work
– Breadth-first
5. Battery-OK
– Length heuristics
6. Starter-OK
– Set of support
7. ¬Empty-Gas-Tank
– Input resolution
8. ¬Car-OK
– Subsumption
9. Goal: Flat-Tire ?
– Ordered resolution
14
Length heuristics
1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work
2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
• Shortest-clause heuristic:
3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK Generate a clause with the fewest literals first
4. Headlights-Work
5. Battery-OK
• Unit resolution:
6. Starter-OK Prefer resolution steps in which at least one parent
7. ¬Empty-Gas-Tank clause is a “unit clause,” i.e., a clause containing a
8. ¬Car-OK single literal
9. ¬Flat-Tire
1,4 10. ¬Battery-OK ∨ ¬Bulbs-OK – Not complete in general, but complete for Horn
1,5 11. ¬Bulbs-OK ∨ Headlights-Work clause KBs
2,3 12. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Flat-Tire ∨ Car-OK
2,5 13. ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
2,6 14. ¬Battery-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
2,7 15. ¬Battery-OK ¬ Starter-OK ∨ Engine-Starts
16. … [and we’re still only at Level 1!]
Set of support
1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work
2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
• At least one parent clause must be the negation of
3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK the goal or a “descendant” of such a goal clause
4. Headlights-Work (i.e., derived from a goal clause)
5. Battery-OK
6. Starter-OK • When there’s a choice, take the most recent
7. ¬Empty-Gas-Tank descendant
8. ¬Car-OK
9. ¬Flat-Tire • Complete, assuming all possible set-of-support
1,5 10. ¬Bulbs-OK ∨ Headlights-Work clauses are derived
2,5 11. ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
12. ¬Battery-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
• Gives a goal-directed character to the search (e.g.,
2,6
2,7 13. ¬Battery-OK ¬ Starter-OK ∨ Engine-Starts like backward chaining)
3,8 14. ¬Engine-Starts ∨ Flat-Tire
3,9 15. ¬Engine-Starts ¬ Car-OK
16. … [this doesn’t seem to be headed anywhere either!]
15
1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work 1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work
2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts 2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK 3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK
4. Headlights-Work 4. Headlights-Work
5. Battery-OK 5. Battery-OK
6. Starter-OK 6. Starter-OK
7. ¬Empty-Gas-Tank 7. ¬Empty-Gas-Tank
8. ¬Car-OK 8. ¬Car-OK
9. ¬Flat-Tire 9. ¬Flat-Tire
9,3 10. ¬Engine-Starts ∨ Car-OK 9,3 10. ¬Engine-Starts ∨ Car-OK
10,2 11. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Car-OK 10,8 11. ¬Engine-Starts
10,8 12. ¬Engine-Starts 11,2 12. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank
11,5 13. ¬Starter-OK ∨ Empty-Gas-Tank ∨ Car-OK 12,5 13. ¬Starter-OK ∨ Empty-Gas-Tank
11,6 14. ¬Battery-OK ∨ Empty-Gas-Tank ∨ Car-OK 13,6 14. Empty-Gas-Tank
11,7 15. ¬Battery-OK ∨ ¬Starter-OK ∨ Car-OK 14,7 15. FALSE
16. … [a bit more focused, but we still seem to be wandering] [Hooray! Now that’s more like it!]
Simplification heuristics
• Subsumption:
1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work
Eliminate sentences that are subsumed by (more 2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
specific than) an existing sentence to keep KB small 3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK
4. Headlights-Work
– If P(x) is already in the KB, adding P(A) makes no sense – 5. Battery-OK
P(x) is a superset of P(A) 6. Starter-OK
– Likewise adding P(A) ∨ Q(B) would add nothing to the KB 7. ¬Empty-Gas-Tank
8. ¬Car-OK
• Tautology: 9. ¬Flat-Tire
16
Input resolution Ordered resolution
• Search for resolvable sentences in order (left to
• At least one parent must be one of the input right)
sentences (i.e., either a sentence in the original KB
• This is how Prolog operates
or the negation of the goal)
• Resolve the first element in the sentence first
• Not complete in general, but complete for Horn
clause KBs • This forces the user to define what is important in
generating the “code”
• Linear resolution
– Extension of input resolution
• The way the sentences are written controls the
– One of the parent sentences must be an input sentence or
resolution
an ancestor of the other sentence
– Complete
17