Resolution Theorem Proving: Robert Keller February 2011

Download as pdf or txt
Download as pdf or txt
You are on page 1of 141

Resolution

Theorem Proving

Robert Keller
February 2011
What is this?
• Resolution is a special kind of theorem
proving used in:

• Automated theorem proving and reasoning,


where the goal is complete automation

• Databases and Answer Extraction (AI)

• Prolog language (a subset of general resolution)

• Resolution forms a complete proof system for


refutation.
History
• Resolution was introduced by Prof.
J. Alan Robinson in 1965 at Syracuse U.

• There were previous hints at it by


D. Prawitz (1960, for the function-free
case) and Herbrand (1930’s).
How it works
• A logic formula is first negated, then
converted into “clausal form”.
(Some heavy logic is wired into this step.)

• In clausal form, quantifiers have been


eliminated.

• The clausal form is proved by refutation, i.e.


showing that its negation is unsatisfiable.
Two Types of Resolution
• Predicate calculus resolution:
• Our main objective

• Propositional resolution:
• Needed to understand predicate resolution

• Big role in algorithms and complexity theory


(NP completeness, for example)
Propositional Form of Resolution
• A literal is a proposition symbol or its
negation.

• A clause is a disjunction of literals.

• The negation of the formula to be proved is


first converted to a clause set, effectively a
conjunction of those clauses.

• The original formula is a theorem iff the set of


clauses is not satisfiable.
Resolution Schematic

iff original
formula
is valid
Negated ⊥
Formula Clauses
Formula
resolvents

negate clausify
Example
• Clause set:
• p ∨ ¬q
• ¬q ∨ ¬r
• q

• This clause set is satisfiable:


• Valuation p = T, q = T, r = F will satisfy it.
Example
• Clause set:
• p ∨ ¬q
• q∨r
• ¬p
• ¬r

• This clause set is unsatisfiable:


• There is no valuation that makes all formulas T at the same
time.

• Why not?
We’d need p = r = F in order to satisfy all clauses,
but then there is no way to set q so that all clauses are
satisfied.
Conjunctive Normal Form
• A clause set is another way of representing a
propositional formula.

• A formula is in conjunctive normal form (CNF)


iff it is a conjunction of disjunctions of literals

(an “and” of “ors” of propositions and their


negations”
Sets
• Throughout this discussion, we want
each clause to be a mathematical set,
meaning that duplicates literals are
eliminated.

• Likewise, a set of clauses (i.e. CNF) has


no clause duplicated.
Example
• Clause set:
• p ∨ ¬q
• q∨r
• ¬p
• ¬r

• is representable as

{{p, ¬q}, {q, r}, {¬p}, {¬r}}

where the ∨ connective is implicit within clauses, and


the ∧ connective is implicit among them.
Equivalence of Propositional Formulas

• Two propositional formulas are


equivalent (≡) iff they are satisfied by
the same valuations.

• Examples:
• p∧¬q ≡ ¬(q∨¬p)
• p→(q→r) ≡ (p∧q)→r
Equivalence of Clause Sets
• Two clause sets are called equivalent if they
are satisfied by the same set of valuations.

• In particular, if two clause sets are


equivalent, they are either:

• both satisfiable, or
• both unsatisfiable
How General is the Clausal Form?
• Claim: Every propositional formula can be
represented in clausal form.
• Examples:
• p ∨ q in clausal form is {p ∨ q} (one clause)

• p ∧ q in clausal form is {p, q} (two clauses)

• p → q in clausal form is {¬p ∨ q} (one clause)

• p ↔ q in clausal form is {¬p ∨ q, p ∨ ¬q} (two clauses)


Extreme Cases

• ∅ or {}, the empty set of clauses, is equivalent to


True

(as T is the identity for the ∧ operation, and a set of


clauses is a conjunction)

• Note: Every valuation satisfies every clause in {},


because there are no clauses to satisfy.

• {⊥} or {∅} or {{}}, the set containing the empty


clause, is equivalent to False.
The Empty Clause
• The empty clause is ⊥,
sometimes denoted by an empty box ❒.

• Do not confuse the empty clause with an


empty set of clauses.

• Observation: Any clause set containing the


empty clause is unsatisfiable, because no
valuation can make ⊥ true.

Example: {¬p ∨ q, p, ⊥}
Conversion to Clausal Form
• We rely on rules that can be proved in
propositional logic:

• Commutative
• A∧B≡B∧A
• A∨B≡B∨A
• Distributive
• A ∧ (B ∨ C) ≡ (A ∧ B) ∨ (A ∧ C)
• A ∨ (B ∧ C) ≡ (A ∨ B) ∧ (A ∨ C)
• DeMorgan
• ¬(A ∧ B) ≡ ¬A ∨ ¬B
• ¬(A ∨ B) ≡ ¬A ∧ ¬B
Conversion to Clausal Form
1. Replace each ϕ → ψ with (¬ϕ ∨ ψ).

2. Replace each ϕ ↔ ψ with (¬ϕ ∨ ψ) ∧ (ϕ ∨ ¬ψ).

3. Push ¬ inward, toward proposition symbols:


• Replace ¬(ϕ ∧ ψ) with (¬ϕ ∨ ¬ψ).
• Replace ¬(ϕ ∨ ψ) with (¬ϕ ∧ ¬ψ).
• Replace ¬¬ϕ with ϕ.

4. Push ∨ inward toward literals:


• Replace χ ∨ (ϕ ∧ ψ) with (χ ∨ ϕ) ∧ (χ ∨ ψ).
• Replace (ϕ ∧ ψ) ∨ χ with (ϕ ∨ χ) ∧ (ψ ∨ χ).
Example of Conversion to Clauses
• ¬(p → (¬q ∧ (r ∧ ¬ s))) replace →
• ¬(¬p ∨ (¬q ∧ (r ∧ ¬ s))) push ¬ inward
• ¬¬p ∧ ¬(¬q ∧ (r ∧ ¬ s)) delete ¬¬
• p ∧ ¬(¬q ∧ (r ∧ ¬ s)) push ¬ inward
• p ∧ (¬¬q ∨ ¬(r ∧ ¬s)) delete ¬¬
• p ∧ (q ∨ ¬(r ∧ ¬s)) push ¬ inward
• p ∧ (q ∨ ¬r ∨ ¬¬s) delete ¬¬
• p ∧ (q ∨ ¬r ∨ s) conjuncts are clauses
• {p, q ∨ ¬r ∨ s}
Try this one
• (¬p ∧ (¬q → (r ↔ s)))
Clausal Form from a Truth Table
• A truth table is typically thought of as displaying one of possibly
many disjunctive normal forms (DNF).

• Each row is a min-term:

p1* ∧ p2* ∧ . . . ∧ pn* where pi* indicates a literal.

• The overall truth-function is a disjunction of min-terms:


∨(p * ∧ p * ∧ . . . ∧ p *) over the rows for which the result is T.
1 2 n
Example: Truth Table
p q r value
F F F F
F F T F

(¬p∧q∧¬r) F T F T

(¬p∧q∧r) F T T T

(p∧¬q∧¬r) T F F T
T F T F
(p∧q∧¬r) T T F T

(p∧q∧r) T T T T

A DNF: (¬p∧q∧¬r) ∨ (¬p∧q∧r) ∨ (p∧¬q∧¬r) ∨ (p∧q∧¬r) ∨ (p∧q∧r)


Clausal Form from Truth Table
• A DNF has the value True exactly when at
least one of the disjuncts does, e.g.
(¬p∧q∧¬r) ∨ (¬p∧q∧r) ∨ …

• Similarly a CNF has the value False exactly


when at least one of the conjuncts does, e.g.
(p ∨ q ∨ r) ∧ (p ∨ q ∨ ¬r) ∧ (¬p ∨ q ∨ ¬r)

• Hence we can “read off” a CNF from the False


rows of the table.
Example: Clausal Form from Truth Table
p q r value
F F F F (p ∨ q ∨ r)
F F T F (p ∨ q ∨ ¬r)
F T F T
F T T T
T F F T
T F T F (¬p ∨ q ∨ ¬r)
T T F T
T T T T

A CNF: (p ∨ q ∨ r) ∧ (p ∨ q ∨ ¬r) ∧ (¬p ∨ q ∨ ¬r)


Housekeeping: Reduced Clause Sets
• A clause set is reduced provided:
• No literal occurs multiple times in any clause.
• p ∨ ¬q ∨ p is disallowed in a reduced set.

• No clause contains a literal and its negation.


• p ∨ q ∨ ¬p is disallowed in a reduced set.

• Any clause set S is equivalent to a reduced set


reduce(S):
• Replace multiple occurrences of a literal
with a single occurrence of the literal.

• Drop any clauses containing a literal and its negation.


(Such clauses are equivalent to T, and do thus do not affect
satisfiability of the set of clauses.)

• Replace multiple occurrences of a clause (as a set) with a single


occurrence.
reduce example
reduce({p ∨ ¬q ∨ p,
p ∨ q ∨ ¬p ∨ q}) =

{p ∨ ¬q}
Resolution Method
• Input: A reduced set of clauses.

• Output: A set of clauses equivalent to the


input set, such that the original set is
unsatisfiable iff the final set contains the
empty clause ⊥.

• There is no valuation that satisfies ⊥, much


less ⊥ together with other clauses.
How Resolution Works
• Do Repeatedly, until no further steps can be taken:
• From the set of clauses, pick a pair from which a new
clause, called the “resolvent”, can be created.
(Must resolve the pair to find this out.)

• Add the resolvent to the set.

• If ⊥ is ever added to the set, stop. The original set of


clauses is unsatisfiable.

• Conversely, if the original set of clauses is


unsatisfiable, it is possible to eventually derive ⊥.
What is the Resolvent?
• Suppose p is a proposition symbol.

• If the set contains clauses of both forms


• p∨ϕ
• ¬p ∨ ψ

where ϕ and ψ are formulas (either could be empty),
then the resolvent is the reduced version of

ϕ ∨ ψ.

• p and ¬p are said to be “clashing” literals.


Resolution as a Deduction Rule
p∨ϕ ¬p ∨ ψ
ϕ∨ψ (in reduced form)

where p is any proposition symbol and


ϕ and ψ are clauses (possibly empty).
Example of Resolvents
• Consider the clauses
• p ∨ ¬q ∨ ¬s
• q ∨ r ∨ ¬s

• A resolvent (based on literal q) is:


• p ∨ r ∨ ¬s
Example of Resolvents
• Consider the clauses
• p∨r
• ¬r
• The resolvent is:
• p
Example of Resolvents
• Consider the clauses
• p
• ¬p

• Since p and ¬p occur in different


clauses, the resolvent is:
• ⊥
Example of Resolvents
• Consider the clauses
• p ∨ ¬q ∨ r
• q ∨ ¬r ∨ ¬s

• One resolvent (based on literal q) is:


• p ∨ r ∨ ¬r ∨ ¬s
• Another (based on literal r) is:
• p ∨ q ∨ ¬q ∨ ¬s

• Both of these would be dropped in reducing,


however, since each contains a literal and its
negation.
Resolution Algorithm
• Start with a set S of reduced clauses.

• while S does not contain ⊥ and the following


step adds something new to S:

• Add to S the resolvent R of any two clauses


such that R is not already in S.

• The original S is unsatisfiable iff ⊥ is in S.


Unit Clauses
• A clause with exactly one literal is called a
unit clause.

• The penultimate step prior to resolving to ⊥


will be to resolve two unit clauses.

• Resolving a unit clause with a clause having


n > 0 literals results in a clause with fewer
than n literals.
Note on choice of clauses
• Preferring unit clauses is a good
heuristic.
Example 1 (Highlighting unit clauses)
• S = {p ∨ ¬q, q ∨ r, ¬p, ¬r}
resolve p ∨ ¬q with ¬p, adding ¬q to S.

• S = {p ∨ ¬q, q ∨ r, ¬p, ¬r, ¬q}


resolve q ∨ r with ¬q, adding r to S.

• S = {p ∨ ¬q, q ∨ r, ¬p, ¬r, ¬q, r}


resolve ¬r ∨ r adding ⊥ to S.

• Stop ⊥ ∈ S.

• The original S is unsatisfiable, as ⊥ ∈ S.


Example 2
• S = {p ∨ ¬q, q ∨ r, ¬p}
Resolve p ∨ ¬q with ¬p, adding ¬q to S.

• S = {p ∨ ¬q, q ∨ r, ¬p, ¬q}


Resolve q ∨ r with ¬q, adding r to S.

• S = {p ∨ ¬q, q ∨ r, ¬p, ¬q, r}


Resolve p ∨ ¬q with q ∨ r, adding p ∨ r to S.

• S = {p ∨ ¬q, q ∨ r, ¬p, ¬q, r, p ∨ r}


Stop. No new resolvents are possible. The original set is
satisfiable, as ⊥ ∉ S.
Soundness: A valuation satisfying
both p ∨ ϕ and ¬p ∨ ψ satisfies ϕ ∨ ψ.
• Suppose ν satisfies both p ∨ ϕ and ¬p ∨ ψ.

• Either ν(p) = T or ν(p) = F.

• If ν(p) = T, then ν(¬p) = F. In order to satisfy


¬p ∨ ψ then, ν(ψ) = T. Thus ν(ϕ ∨ ψ) = T.

• If ν(p) = F, in order to satisfy p ∨ ϕ, ν(ϕ) = T.


Thus ν(ϕ ∨ ψ) = T.

• Thus adding the resolvent preserves the


valuations that satisfy the set of clauses.
Completeness
• Completeness is more complicated and we
will not prove it here.

• We’d have to show that if a set is


unsatisfiable, there is a set of resolution steps
that result in the empty clause.

• For a constructive proof, see: J. Gallier, 2006:


http://www.cis.upenn.edu/~cis510/tcl/resol.pdf
Resolution Algorithm Termination
• Closure is always achievable.

• The set of distinct reduced clause sets for a given set


of proposition symbols is finite.

• At worst, every possible clause (regarding reordering


of symbols as equivalent) will be generated.

• How many distinct clauses can there be for n


proposition symbols?
Resolution in tabular form
1. p ∨ ¬q Premise
2. q∨r Premise
3. ¬r Premise
4. ¬p Premise
5. q Resolution 2, 3
6. p Resolution 1, 5
7. ⊥ Resolution 6, 4
Resolution as a Tree

p ∨ ¬q q∨r ¬r ¬p

children
nodes are p
resolvents

Try resolving these clause sets:
• ¬p ∨ ¬q ∨ ¬r,
¬q ∨ r,
q ∨ s,
¬s,
p

• p ∨ ¬q ∨ r,
q ∨ r,
¬p
Sometimes a DAG is more appropriate
than a tree for showing all options

p∨q p ∨ ¬q ¬p ∨ ¬q ¬p ∨ q

p ¬q ¬p q

We avoid identifying
⊥ ⊥ the two ⊥ nodes,so as
not to confuse the two
sets of antecedents.
Useful Editing Short-cuts
• Uncomplemented Literal Lemma

If a literal appears in one or more clauses, but its


complement appears in no clause, then every clause
containing that literal can be deleted from the set
without changing satisfiability.

• Rationale: The literal in question can be assigned T


without loss of generality, thus clauses containing it
cannot affect satisfiability.
Example of Uncomplemented Literal Lemma

• ¬p ∨ q ∨ r,
¬q ∨ r,
q ∨ s,
¬s,
p
• r occurs only uncomplemented.
• The clause set is unsatisfiable iff the following set is:
• q ∨ s,
¬s,
p
• and this set is unsatisfiable iff ¬s is unsatisfiable
(which it isn’t).
Further Editing Short-Cuts
• Unit Clause Lemma:

If a unit cause (clause with only one literal L)


exists within the set, the following operation may be performed
without affecting satisfiability:

• Remove all clauses containing L.

• Remove the complement of L from all remaining clauses.

• Rationale: The literal in question must be assigned T in a


satisfying interpretation. Hence all clauses containing it will be T
and contribute nothing to the set. Likewise, its complement must
be assigned F, and contribute nothing to the individual clauses.
Example of Unit Clause Lemma
• ¬p ∨ q ∨ r,
¬q ∨ r,
q ∨ s,
¬s,
p

• ¬s is a unit clause. The complement of ¬s is s.

• The clause set is unsatisfiable iff the following set is:


¬p ∨ q ∨ r,
¬q ∨ r,
q,
p
etc.
Further Useful Optimizations
Subsumption Lemma:

• One clause subsumes another if the former’s literals are a


subset of the latter’s.

• If one clause of a set subsumes another, the subsumed clause


(the larger one) can be dropped from the set.

• Rationale: If C subsumes D, then any interpretation satisfying C


must also satisfy D (because the literals are disjoined). Thus the
satisfiability of the set of clauses is unaffected if D is removed.
Example of Subsumption Lemma
• ¬p ∨ q ∨ r,
¬p ∨ r,
p∨r∨q
• The second clause subsumes the first.

• The clause set is unsatisfiable iff the following set is:


• ¬p ∨ r,
p∨r∨q
Common Special Case of Clause Set
• Often we want to prove a sequent such as:
• ϕ11∧ ϕ12∧ … ∧ϕ1m1→ ψ1 ,
ϕ21∧ ϕ22∧ … ∧ϕ2m2→ ψ2 , “axioms”
...
ϕn1∧ ϕn2∧ … ∧ϕnmn→ ψn
|– χ1∧ χ2∧ . . . ∧ χp “theorem”
where each symbol represents a literal.

• This can be done by showing that the following clause


set is unsatisfiable:

{¬ϕ11∨ ¬ϕ12∨ … ∨¬ϕ1m1 ∨ ψ1,


¬ϕ21 ∨ ¬ϕ22∨ … ∨¬ϕ1m2 ∨ ψ2,
...
¬ϕn1 ∨ ¬ϕn2∨ … ∨¬ϕnmn∨ ψn,
¬χ1∨ ¬χ2∨ . . . ∨ ¬χp}
Strategic Optimizations
• Unit-Preference: Prefer resolving with unit
clauses. These reduce the size of resulting
clauses.

• Set-of-Support: Divide the clauses into two


sets:
• A known-satisfiable subset.
• Other
• Always resolve with an “other” or a clause
derived from one.
• The latter are called the “set of support”
(SOS).
Set-of-Support
• Showing that the following clause set is
unsatisfiable:

{¬ϕ11∨ ¬ϕ12∨ … ∨¬ϕ1m1 ∨ ψ1,


¬ϕ21 ∨ ¬ϕ22∨ … ∨¬ϕ1m2 ∨ ψ2,
... Satisfiable “axioms”
¬ϕn1 ∨ ¬ϕn2∨ … ∨¬ϕnmn∨ ψn,

¬χ1∨ ¬χ2∨ . . . ∨ ¬χp} Initial set of support


Horn Clauses
• A Horn clause is one in which there is
at most one non-negated literal:
• ¬ϕ1∨ ¬ϕ2∨ … ∨¬ϕm ∨ ψ (one non-negated)
or
• ¬ϕ1∨ ¬ϕ2∨ … ∨¬ϕm (no non-negated)

• Horn clause are the basis of the Prolog language,


where:
¬ϕ1∨ ¬ϕ2∨ … ∨¬ϕm ∨ ψ
is written
ψ :- ϕ1, ϕ2, . . . ϕm.
interpreted as
ϕ1∧ ϕ2∧ … ∧ϕm→ ψ
If m = 0, then we just write
ψ.
Prolog uses a special form of resolution to do its
work (“SLD” = Selective Linear Definite resolution)

• {p ∨ ¬r ∨ ¬s, Dialog with Prolog:


r ∨ ¬q,
s ∨ ¬q, consult(user).
q,
¬p, Non-negated p :- r, s.
} literals in red. r :- q.
s :- q.
becomes in Prolog syntax: q.
^D
• p :- r, s.
r :- q. | ?- p.
s :- q. yes
q.
?- p.
Resolution Theorem Provers
• Prolog cannot handle general negation

• Resolution theorem provers can

• Examples: Prover9, Vampire, …


• Extends the former program “Otter”

• Developed at Argonne National Laboratory

• Free download for all platforms

• http://www.cs.unm.edu/~mccune/prover9/

• Also includes Mace for constructing counterexamples


Prover9 GUI (- is “not”, | is “or”)
Prover9 Proof ($F is empty clause)
Resolution for Predicate Logic
• Predicate Clausal Form:
• A literal is an atomic formula or its negation
(instead of a proposition symbol or its negation).

• The variables of each clause are


implicitly ∀-quantified.

• The variables of each clause are thus independent


from the other clauses; even if they are they same, they
should be thought of as being different (e.g. implicitly
rename by indexing with a clause number).
Example: Predicate Clausal Form
• Clause set {p(X), q(X, Y), ¬q(X, X) ∨ p(X)}
stands for the conjunction

• ∀X p(X)
∧∀X ∀Y q(X, Y)
∧∀X ∀Y (¬q(X, X) ∨ p(X))

which is the same as


• ∀X1 p(X1)
∧∀X2 ∀Y2 q(X2, Y2)
∧∀X3 ∀Y3 (¬q(X3, X3) ∨ p(X3))

i.e. the clause set


• {p(X1), q(X2, Y2), ¬q(X3, X3) ∨ p(X3)}
How General is This?
• We will see later that it is completely
general, as far as showing
unsatisfiability is concerned.
Examples of Predicate Clausal Form

• ¬man(X) ∨ mortal(X)
• man(socrates)
• ¬mortal(socrates)

• These clauses can be used to prove the


syllogism:
• All men are mortal.
• Socrates is a man.
• Therefore Socrates is mortal.
Resolution for Predicate Clauses
• To resolve predicate clauses, it is no longer
sufficient to look for just a literal and its
negation in two distinct clauses, e.g. X in

¬q(X, X) ∨ p(X)
¬p(Z) ∨ r(Z, Y)
• For one thing, the identity of the variables is
independent in each.
• For another, the arguments are generally
terms, not just simple variables:
¬q(X, X) ∨ p(f(X))
¬p(X) ∨ r(g(X), c)
Example of What Resolution Must Do

• Suppose we have derived three formulas


(where c is a constant symbol):
• p(c)
• ∀X (p(X) → q(f(X))
• ∀X (q(X) → r(X, g(X))

• We would expect to be able to infer


• q(f(c))
• r(f(c), g(f(c)))

• Resolution must be able to handle such things.


Equivalent Clausal Form
• The clausal form of
• p(c)
• ∀X (p(X) → q(f(X))
• ∀X (q(X) → r(X, g(X))
is
• {p(c), ¬p(X) ∨ q(f(X)), ¬q(X) ∨ r(X, g(X))}

• Resolution has to “make a connection”


between p(c) and p(X), and
between q(f(X)) and q(X).
Unification
• The “connection” alluded to on the previous
slide is known as unification.

• Two atoms are unifiable if there is a


uniform set of substitutions of terms for
their variables that makes them identical.

• If such a substitution set exists, it is applied


to all literals in the formulas prior to
resolution.
Unification Examples
• Consider atoms p(c), p(X)
(c is a constant, X a variable).

• These terms are unifiable, since the


substitution [c/X] (substitute c for X)
makes them identical.
Unification Examples
• Consider q(c, d), q(X, X)
(c and d are constants, X a variable).

• These terms are not unifiable.

• Distinct constant symbols do not unify. There is no


substitution that will make them identical.

• (Note: This is not the same as saying constant


symbols cannot be equated. They can, with a
separate equation such as c = d. Equality is handled
separately.)
Renaming Apart
• Consider p(X, f(a)) vs. p(g(Y), f(X))

• These might appear not to unify, since we would have


a conflict [g(Y)/X] vs. [a/X].

• However, if we rename the variables in the second


clause we get:
p(X, f(a)) vs. p(g(Z), f(W)).
• These unify, using [g(Z)/X, a/W].

• Note: Renaming apart is done only at the start of


considering unification of two clauses, and all
variables in the clause are renamed uniformly.
Notation for Variable Substitutions
• In general, a substitution consists of a set of
bindings of variables to terms, e.g.

β = [Z/X, f(Z, c)/Y, c/W]

• If τ is a term, then τβ denotes the result of making


the substitutions β in for variables in τ, e.g.

if τ = p(X, g(Y, W))


then τβ = p(Z, g(f(Z, c), c))
Composing Variable Substitutions
• If β and γ are substitutions and τ is a term, then (τβ)γ
denotes the result of first applying β to τ, then γ to the
result, e.g.
τ = p(X, g(Y, W)) literal
β = {Z/X, f(Z, c)/Y, c/W} sub
γ = {V/Z} sub
(τβ)γ = p(V, g(f(V, c), c))

• The composition βγ of substitutions β and γ is the


substitution such that for all terms τ
τ(βγ) = (τβ)γ
e.g. {V/X, f(V, c)/Y, c/W} above
Unifiers
• A set of substitutions that unifies two
literals is called a unifier.
More Unification Examples
Term 1 Term 2 Unifier, if any?

p(X, X) p(f(Y), f(Z))

p(X, X) p(f(Y), g(Y))

p(X, Y) p(Z, f(Z))

p(X, f(X)) p(g(Y), W)

p(X, f(X)) p(f(Y), Y)


Even More Unification Examples

Term 1 Term 2 Unifier, if any?


p(X, Y) p(f(Z), g(Z))

p(X, f(X)) p(f(Z), U)

p(f(X), g(X)) p(f(U), U)

p(f(X), f(X)) p(c, c)

p(f(X), g(X)) p(Y, g(Y))


Most General Unifiers (mgu)
• If two literals unify at all, they have a “most general
unifier”, one which adds no unneeded constraints.

• Example: p(X) vs. p(f(Y)) could be unified with the


substitution
[f(c)/X, c/Y].

• However, this would not be the most general, since


we could leave Y as a variable:
[f(Z)/X]
and each of the original literals would unify with this.
Generality of Substitutions
• Substitution β is as general as substitution ν
if there is a γ such that ν = β γ.

• To say that β is a “most general unifier”


means that is as general as any unifier.
Find the MGU or indicate non-unifiable

Term 1 Term 2 MGU?


p(X, Y) p(Z, Z)

p(X, c) p(Y, Y)

p(f(X), Y) p(W, f(Z))

p(f(X), Y) p(Z, Y)

p(f(Z), g(X)) p(Y, g(Y))


MGU Algorithm (Martelli & Montanari)
• Input: Two terms, or two atoms, τ1, τ2, already renamed apart.
• Output: Either the most general unifier for τ1, τ2, or “not unifiable”.

• S := {[τ1, τ2]}; // functions as a sort-of stack


µ := the empty substitution;
while( S ≠∅ )
remove a pair [L, R] from S; // pop case
if( L = R ) (1)
do nothing;
else if( L=f(s1, s2, …, sn) and R=f(t1, t2, …, tn) ) // same f, n (2)
S := S ∪ {[s1, t1], [s2, t2],… [sn, tn]}; // pushes
else if( L = x where x is a variable not occurring in R) (3)
µ := µ[R/x]; // composing
S := applytoallpairs([R/x], S);
else if( R = x where x is a variable not occurring in L) (4)
µ := µ[L/x];
S := applytoallpairs([L/x], S);
else return “not unifiable”; (5)
return µ as the MGU;
Intuitive Unification
• Remember when two things don’t unify:
• Distinct constant symbols don’t unify.
• Terms with outermost function symbols that are distinct don’t
unify.
• A term with an outermost function symbol doesn’t unify with a
constant.
• Two terms with the same outermost function symbol don’t
unify if some of their arguments don’t pairwise unify.

• Remember that substitutions are cumulative


during unification.
Example
• p(X, f(X)) vs. p(Y, f(Y)) initial
• S := {[p(X, f(X)), p(Y, f(Y))]}
• µ := []

• Remove [p(X, f(X)), p(Y, f(Y))] case 2


• S := {[X, Y], [f(X), f(Y)]}

• Remove [X, Y] case 3


• µ := [Y/X]; S := {[f(Y), f(Y)]}

• Remove [f(Y), f(Y)] case 1


• S := {}

• Result: unifiable with mgu [Y/X]


Diagrammatically
• p(X, f(X))
⏐ ↑ substitution [Y/X]
p(Y, f(Y))

• p(Y, f(Y))
⏐ ⏐ ⏐ ⏐
p(Y, f(Y))
Example
• p(X, f(X)) vs. p(f(Y), Y) initial
• S := {[p(X, f(X)), p(f(Y), Y)]}
• µ := {}

• Remove [p(X, f(X)), p(f(Y), Y)] case 2


• S := {[X, f(Y)], [f(X), Y]}

• Remove [X, f(Y)] case 3


• µ := [f(Y)/X]; S := {[f(f(Y)), Y]}

• Remove [f(f(Y)), Y] case 5


• Result: not unifiable
Diagrammatically
• p(X, f(X))
⏐ ↑↓ substitution [f(Y)/X]
p(f(Y), Y)

• p(f(Y), f(f(Y)))
⏐ ⏐ ↓ occur check fails, not unifiable
p(f(Y), Y)
Example
• p(X, g(Z), X) vs. p(f(Y), Y, W) initial
• S := {[p(X, g(Z), X), p(f(Y), Y, W)]}
• µ := {}

• Remove [p(X, g(Z), X), p(f(Y), Y, W)] case 2


• S := {[X, f(Y)], [g(Z), Y], [X, W]}

• Remove [X, f(Y)] case 3


• µ := [f(Y)/X]; S := {[g(Z), Y], [f(Y), W]}

• Remove [g(Z), Y] case 4


• µ := [f(g(Z))/X, g(Z)/Y]; S := {[f(g(Z)), W]}

• Remove [f(g(Z)), W] case 4


• µ := [f(g(Z))/X, g(Z)/Y, f(g(Z))/W]; S := {}

• Result: unifiable with


mgu [f(g(Z))/X, g(Z)/Y, f(g(Z))/W]
Diagrammatically
• p(X, g(Z), X) vs.
⏐ ↑ substitution [f(Y)/X]
p(f(Y), Y, W)

• p(f(Y), g(Z), f(Y)) vs.


⏐ ⏐⏐ ↓ substitution [g(Z)/Y, f(g(Z))/X]
p(f(Y), Y, W)

• p(f(g(Z)), g(Z), f(g(Z))) vs.


⏐ ⏐⏐ ⏐ ⏐ ↓ substitution [f(g(Z))/W, g(Z)/Y, f(g(Z))/X]
p(f(g(Z)), g(Z), W)

• p(f(g(Z)), g(Z), f(g(Z))) vs.


⏐ ⏐⏐ ⏐ ⏐ ⏐ substitution [f(g(Z))/W, g(Z)/Y, f(g(Z))/X]
p(f(g(Z)), g(Z), f(g(Z)))
Note on Unification in Prolog
• In Prolog, unification is used in goal matching
and in the = (unify) operator.

• However, Prolog’s unification is slightly


abridged: it bypasses the “occur check”:
X = f(X)
will unify in Prolog, but not in ordinary
unification. In effect, X gets bound to the
infinite term:
f(f(f(…)))
Checking Unifiability with Prolog
• As long as there are no occur-check
violations, can use = to test.

$ /opt/local/bin/swipl
Welcome to SWI-Prolog

?- p(X, g(Z), X) = p(f(Y), Y, W).

X = f(g(Z)),
Y = g(Z),
W = f(g(Z))
Try These
τ1 τ2 mgu
(or not unifiable)
p(X, f(X), d) p(c, f(c), Y)

p(f(g(X)), g(Z)) p(f(Y), Y)

p(f(g(X)), Z) p(g(Y), Y)

p(f(g(X)), X) p(f(g(h(Z))), h(Z))


Resolving Predicate Calculus Clauses
• Resolvable clauses must contain literals with the same
predicate symbol but of opposite sign (one negated, the
other not).

• Pick two such literals, one from each clause.

• Rename the clauses apart.

• Determine whether the literals are unifiable, with mgu µ.


If they are, apply µ to all literals in both clauses. If not, the
clauses don’t resolve on these particular literals.

• In the modified clauses, remove all instances of the


modified literals used in unification, and form the
disjunction of the remaining literals.
Complete Predicate Resolution Process

• The process is similar the propositional


case, except that we have to
• rename variables, then
• unify literals prior to resolution, and
• apply the mgu to all literals in the two clauses, before
obtaining the resolvent.

• There are also a special issue:


“factoring”, that needs to be
considered.
Example of Predicate Resolution
• Clauses:
• ¬man(X) ∨ mortal(X)
• man(socrates)
• ¬mortal(socrates)

¬man(X) ∨ mortal(X) ¬mortal(socrates)


[socrates/X]

¬man(socrates) man(socrates)


Example Resolving Predicate Clauses
• clause 1: p(X, g(Z), X) ∨ q(X, h(Z))
• clause 2: ¬p(f(Y), Y, W) ∨ r(f(Y), g(W))
• These are already renamed apart.

• The first literals of each unify with mgu


[f(g(Z))/X, g(Z)/Y, f(g(Z))/W]

• Apply the mgu to both clauses:


• clause 1’: p(f(g(Z)), g(Z), f(g(Z))) ∨ q(f(g(Z)), h(Z))
• clause 2’: ¬p(f(g(Z)), g(Z), f(g(Z))) ∨ r(f(g(Z)), g(f(g(Z))))
• Remove the instances of the unified atoms and form the
disjunction.
• Resolvent: q(f(g(Z)), h(Z)) ∨ r(f(g(Z)), g(f(g(Z))))
Example of Predicate Resolution
• Clauses:
• ¬p(X) ∨ q(f(X), X))
• p(g(b))
• ¬q(Y, Z)

¬p(X) ∨ q(f(X), X) ¬q(Y, Z)


[f(Z)/Y, Z/X]

¬p(Z) p(g(b))
[g(b)/Z]

Unit Preference
• As with propositional resolution,
resolving with unit clauses first is a
good heuristic.
Try This Set
1. ¬e(X) ∨ q(X) ∨ s(X, f(X))
2. ¬e(X) ∨ q(X) ∨ r(f(X))
3. p(a)
4. e(a)
5. ¬s(a, Y) ∨ p(Y)
6. ¬p(X) ∨ ¬q(X)
7. ¬p(X) ∨ ¬r(X)
Remember to treat clauses as sets.
• q(b, X) ∨ p(X) ∨ q(b, a)
• ¬q(Y, a) ∨ p(Y)
• These are already renamed apart.

• unify q(b, X) with ¬q(Y, a)


• mgu is [a/X, b/Y]

• Modified clauses:
• q(b, a) ∨ p(a) ∨ q(b, a)
• ¬q(b, a) ∨ p(b)

• There are two instances of q(b, a) in the first clause; both


are removed in resolving.
• Resolvent: p(a) ∨ p(b)
Binary Resolution and Factoring
• What we have seen so far is “binary”
resolution — unifying two literals to achieve a
resolvent.

• In general, binary resolution is not enough.

• We might need to “factor” two or more


literals in the same clause to make progress.
Factoring
• Two or more literals of the same sign in one
clause can be unified (without renaming
apart) so that the resulting literals can be
collapsed into one.

• The resulting clause is called a factor of the


original.

• The factor (with all variables quantified) is


logically implied by the more-general original
(with all variables quantified).
Factoring Example
• Consider the clause:

P(x) ∨ P(f(y)) ∨ ¬Q(x)

• The first two literals can be unified using the


substitution [f(y)/x].

• The resulting factor is:

P(f(y)) ∨ ¬Q(f(y))

• (∀x ∀y (P(x) ∨ P(f(y)) ∨ ¬Q(x))) → ∀y (P(f(y)) ∨ ¬Q(f(y)))


is valid
Use of Factoring
• Suppose our clause set includes:
P(x) ∨ P(f(y)) ∨ ¬Q(x)
¬P(f(a))

• With binary resolution, we’d get the resolvent:


P(x) ∨ ¬Q(x).

• If we first factor, to get P(f(y)) ∨ ¬Q(f(y)) as on the


previous slide, we can get a resolvent ¬Q(f(a)), which
is better.
Full Resolution of Two Clauses
• Binary resolution of the clauses.

• Binary resolution of one clause with a factor


of the other.

• Binary resolution of factors of both clauses.


Case Where Factoring is Necessary

• P(x) ∨ P(y)
• ¬P(a) ∨ ¬P(b)
• Without factoring, generate:
• P(y) ∨ ¬P(b)
• P(x) ∨ ¬P(a)
• and more similar clauses,
but never the empty clause.
Case Where Factoring is Necessary

• P(x) ∨ P(y)
• ¬P(a) ∨ ¬P(b)
• With factoring, get factor p(x) from first
clause, then generate:
• ¬P(b)
• ⊥
Clausal Form for Predicate Logic
• Often, we’ll want to prove a sequent of
the form
• ∀x ∀y (…)
• ∀x ∀y (…)
|– ___
• For premises of the form ∀x ∀y (…) where … has no
quantifiers, we can just drop the quantifiers.

• We need to negate the conclusion ____.


Mushroom Example
1. Every fungus is a mushroom or a toadstool.

2. Every boletus is a fungus.

3. All toadstools are poisonous.

4. No boletus is a mushroom.

5. Specimen b is a boletus.

6. Therefore: Specimen b is poisonous.


Mushroom Example
1. ∀X fungus(x) → (mushroom(X) ∨ toadstool(X))

2. ∀X boletus(X) → fungus(X)

3. ∀X toadstool(X) → poisonous(X)

4. ∀X boletus(X) → ¬mushroom(X)

5. boletus(b)

6. Therefore: poisonous(b)
Mushroom Clauses
1. ¬fungus(X) ∨ mushroom(X) ∨ toadstool(X)

2. ¬boletus(X) ∨ fungus(X)

3. ¬toadstool(X) ∨ poisonous(X)

4. ¬boletus(X) ∨ ¬mushroom(X)

5. boletus(b)

6. ¬poisonous(b) (negated conclusion)


Mushroom Clauses in Prover9
-fungus(x) | mushroom(x) | toadstool(x).

-boletus(x) | fungus(x).

-toadstool(x) | poisonous(x).

-boletus(x) | -mushroom(x).

boletus(b).

Goal:

poisonous(b).
Prover9 Output for Mushrooms
Checking Unifiability with Prover9
• In contrast to Prolog,
Prover9 does use an occur-check.
unification succeeds unification fails due to occur-check

Proof:
Clausal Form for Predicate Logic
• Often, we’ll want to prove a sequent of the form
• ∀x ∀y (…),
• ∀x ∀y (…)
|– ∀x ∀y (…)

• For premises of the form ∀x ∀y (…) where … has no quantifiers,


we can just drop the quantifiers.

• We need to negate the conclusion, so that will become


¬∀x ∀y (…) which is equivalent to

∃x ∃y ¬(…).

We cannot simply drop the quantifiers in this case!!


Clausal Form for Predicate Logic
• Consider the sequent

∀y p(y) |– ∀y p(x)

• The premise translates to a clause

p(y)

• The conclusion is negated to become ∃x ¬p(x).

• How do we handle this?


Skolem Constants/Functions to the Rescue!

• To get rid of the quantifier in

∃x ¬p(x)

we use a trick:

Create a new constant, say b (called a Skolem constant) and replace x


with that:

¬p(b)

• Some thought will show that:

There is an interpretation that satisfies ¬p(b) iff there is one that satisfies
the original formula ∃x ¬p(x).

• Colloquially, we get to pick the value for b in finding a satisfying


interpretation, just as we get to pick the value for x in ∃x.
Clausal Form for Predicate Logic
• Consider the sequent

∀y p(y) |– ∀x p(x)

• The premise translates to a clause

p(y)

• The negated conclusion translates to a clause, where b is a


Skolem function.

¬p(b)

• We are good to go!

• Resolution produces ⊥ in 1 step.


Another Example
• Consider the sequent

∃x ∀y p(x, y) |–∀y ∃x p(x, y)


• Premise clause:

p(b, y)

• Conclusion clause:

¬p(x, c)

Resolution produces ⊥ in 1 step.


Another Example
• Consider the sequent

∀x a(x) -> ∃x b(x) |– ∃x (a(x) -> b(x))

• Premise clause:

¬a(c) ∨ b(d)
• Conclusion clauses:

a(x)
¬b(x)

Resolution produces ⊥ in 2 steps.


Skolem Functions for the General Case
• ∀x ∀y … ∃v …
• v is replaced with f(x, y, …)
• f is a new function symbol, the arguments of which are the ∀
quantified variables on the left.

• The rationale here is that “the v” that exists


depends on x, y, … .

• Again, there is an interpretation satisfying the original formula iff


there is an interpretation satisfying the revised formula.
Example: Skolem with Arguments
• Prove: “The composition of two onto [surjective] functions
is onto.”

• Represent the two functions as binary predicates.


F(x, y) means y is the image of x.

• “F is onto”: ∀y ∃x F(x, y)
• “G is onto”: ∀z ∃y G(y, z)

• “H is the composition of F and G”:

∀x ∀y ∀z ((F(x,y)∧G(y,z)) → H(x, z))


∧ ∀x ∀z (H(x, z) → ∃y (F(x,y)∧G(y,z)))

• “H is onto”: ∀z ∃x H(x, z)
Translation to Clausal Form
• ∀y ∃x F(x, y) becomes F(f(x), y) [f is a Skolem function]
• ∀z ∃y G(y, z) becomes G(g(z), z) [g is a Skolem function]

• ∀x ∀y ∀z ((F(x,y)∧G(y,z)) → H(x, z)) becomes


¬F(x, y) ∨ ¬G(y, z) ∨ H(x, z)

• ∀x ∀z (H(x, z) → ∃y (F(x,y)∧G(y,z))) becomes


• ¬H(x, z) ∨ F(x, h(x, z)) [h is a Skolem function]
• ¬H(x, z) ∨ G(h(x, z), z)

• ¬∀z ∃x H(x, z) becomes ∃z∀x ¬H(x, z),


which as a clause is:

• ¬H(x, a) [a is a Skolem constant]


Resolution Proof
1. F(f(x), y) Premises
2. G(g(z), z)
3. ¬F(x, y) ∨ ¬G(y, z) ∨ H(x, z)
4. ¬H(x, z) ∨ F(x, h(x, z))
5. ¬H(x, z) ∨ G(h(x, z), z)
6. ¬H(x, a)

7. ¬F(x, y) ∨ ¬G(y, a) from 3, 6


8. ¬G(y, a) from 1, 7
9. ⊥ from 2, 8

(3 and 4 were not needed in the proof.)


How to get a clause form in general?
• First convert the formula into “prenex form”
(all quantifiers are outside on the left). [The parts of
this form are the “prefix” and the “matrix”.]

• Skolemize ∃ quantified variables.

• Drop ∀ quantifiers.

• Convert the resulting matrix to CNF.


Conversion to Prenex Form
• Replace all connectives other than ∧∨¬
with their ∧∨¬ counterparts.

• Push negations inward

• Pull quantifiers to the outside using the


rules on the next page.
Basic Prenex Quantifier Rules
(for pulling quantifiers to the outside)

• We can show that the following replacements are equivalent.


• Here ⇒ means “replace with”
1. (∀x F) ∧ G ⇒ ∀x (F ∧ G), provided x is not free in G
2. (∀x F) ∨ G ⇒ ∀x (F ∨ G), provided x is not free in G
3. (∃x F) ∧ G ⇒ ∃x (F ∧ G), provided x is not free in G
4. (∃x F) ∨ G ⇒ ∃x (F ∨ G), provided x is not free in G
• plus the symmetric counterparts of these rules with G part quantified
instead of the F part.
• Renaming some variables may be need to enable the rule to be applied
• Example:
(∃x F[x]) ∧ (∀x G[x]) ⇒ (by renaming second x)
(∃x F[x]) ∧ (∀y G[y]) ⇒ (by rule 3, as x is not free)
(∃x (F[x] ∧ (∀y G[y])) ⇒ (by rule 1 symmetric counterpart)
∃x ∀y (F[x] ∧ G[y])
Example of Prenex Conversion
• ∀x ∀y((∃z(p(x, z) ∧ p(y, z)) → ∃u q(x, y, u))

• ∀x ∀y(¬(∃z(p(x, z) ∧ p(y, z)) ∨ ∃u q(x, y, u))

• ∀x ∀y((∀z ¬(p(x, z) ∧ p(y, z)) ∨ ∃u q(x, y, u))

• ∀x ∀y((∀z (¬p(x, z) ∨ ¬p(y, z)) ∨ ∃u q(x, y, u))

• ∀x ∀y ∀z(¬p(x, z) ∨ ¬p(y, z) ∨ ∃u q(x, y, u))

• ∀x ∀y ∀z ∃u(¬p(x, z) ∨ ¬p(y, z) ∨ q(x, y, u))

prefix matrix
Completion of Conversion
• ∀x ∀y ∀z ∃u(¬p(x, z) ∨ ¬p(y, z) ∨ q(x, y, u))

• Skolemize as f(x, y, z) and drop ∀x ∀y ∀z

• ¬p(x, z) ∨ ¬p(y, z) ∨ q(x, y, f(x, y, z))


Example: Group Theory Clauses
• f is the group operation, e is the equality predicate

• ∀x ∀y ∀x e(f(x, f(y, z)), f(f(x, y), z))


becomes
e(f(x, f(y, z)), f(f(x, y), z))

• ∀x e(f(x, u), x)
becomes
e(f(x, u), x)

• ∀x e(f(x, i(x)), u)
becomes
e(f(x, i(x)), u)
Example: Equality Theory Clauses
• We need to axiomatize equality predicate e, e.g.

• ∀x e(x, x)
becomes
e(x, x)

• ∀x ∀y ∀u ∀v (e(x, y)∧ e(v, w)) → e(f(x, v), f(y, w))


becomes
¬e(x, y) ∨ ¬e(u, v) ∨ e(f(x, v), f(y, w))

• ∀x ∀y e(x, y) → e(y, x)
becomes
¬e(x, y) ∨ e(y, x)

etc.
Example of Group Theory Clauses with Negated Conclusion

1. e(f(x, f(y, z)), f(f(x, y), z))


2. e(f(x, u), x)
3. e(f(x, i(x)), u)
4. e(x, x)
5. ¬e(x, y) ∨ ¬e(v, w) ∨ e(f(x, v), f(y, w))
6. ¬e(x, y) ∨ e(y, x)
7. ¬e(x, y) ∨ ¬e(y, z) ∨ e(x, z)

8. ¬e(i(i(b)), b)

This is to show that ∀x e(i(i(x)), x):

“In a group, the inverse of the inverse of an element is the


element itself.”
Equality: Paramodulation
• Prover9 has a built-in equality, so the
approach illustrated in the previous example
is not generally necessary.

• Equality can be handled, for example, by the


“paramodulation” rule, which essentially
captures one of the two ND rules for equality:
Justification of Rules
Using Natural Deduction: ∀∧ Rule a.

Proviso is introduced
by prefixing
ʻWHERE x NOTIN G ISʼ
in Jape.
For equivalence, we need the
converse of each rule: ∀∧ Rule b.

Need the non-empty


universe assumption
in this direction.

Otherwise, there is
no way to get G by itself.
Justification of Rules
Using Natural Deduction: ∀∨ Rule a.
Justification of Rules
Using Natural Deduction: ∀∨ Rule b.
Justification of Rules
Using Natural Deduction: ∃∨ a.
Non-empty universe assumption, needed in 7-11
Justification of Rules
Using Natural Deduction: ∃∨ b.
Justification of Rules
Using Natural Deduction: ∃∧ a.
Justification of Rules
Using Natural Deduction: ∃∧ b.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy