1 Overview 1 2 Conversion to Normal Form 1 3 Unification: Definition and Procedure 4 4 Sample Proof-by-Refutation 6
At this point, we have all the machinery in place to automate theorem proving in first-order logic. More specifically, our goal is solve the logical entailment problem: KB |= A? At a high-level, our strategy is as follows:
3. Using unification and resolution, search for a refutation: i.e., a proof of ⊤→⊥. The rest of this lecture details these steps and traces through an example.
Thefollowing algorithmconvertsanarbitraryformulaof first-orderlogicintoaset ofquantifier-free formulas in normal form.
1. Eliminate implications.
2. Move negations inwards.
– Rewrite ¬¬φ as φ.
Since variables are standardized apart, this step is sound. Otherwise, if we rewrite ∀xP (x)∨ ∀xQ(x)as ∀xP (x)∨Q(x),themeaningof theformulachanges. Forexample,let P = black and Q = white. The latter formula is true of piano keys, all of which are either black or white. But the original formula is not true of piano keys, since it is neither the case that all piano keys are black nor that all piano keys are white.
At this point the formula is in prenex normal form.
5. Skolemize to eliminate existential quantifiers. Rewrite quantified formulas of the form
∀x1 ,...,xn ∃yφ(xi,y)
as ∀x1 ,...,xn φ(xi, skm(x1 ,...,xn))
where skm is a new function symbol that does not appear elsewhere in the database. The subscript m denotes the mth Skolemization, thereby ensuring that skm has not appeared previously. For example, the Skolemization of this formula:
∀x, y(x<y)→∃z(x<z)∧ (z<y)
is this formula: ∀x, y(x<y)→ (x< sk(x, y))∧ (sk(x, y)<y)
where sk(x, y)denotes,for example,thefunctionthat averages(thedenotations of) x and y. The following example is an incorrect Skolemization. The premise states “everyone has a mother;” the conclusion states “sk1 is everyone’s mother.”
∀x ∃y mother of(x)= y
∀x mother of(x)= sk1
The following is a correct Skolemization: it states that “sk1 (x)is x’s mother.”
∀x ∃y mother of(x)= y ∀x mother of(x)= sk1 (x)
Lemma: Given any first-order formula ∀x1 ,...,xn ∃yψ in prenex normal form, there exists a corresponding Skolemized formula ∀x1 ,...,xn ψ|{sk(x1 ,...,xn)/y} s.t. the two are equisatisfiable, meaning either both have a model or neither does (though the models need not coincide).
Remark: Aformula(inprenex normalform) anditsSkolemization are notlogically equiv
alent. Exercise: Let φ be an atomic formula, and let sk be a function symbol not occurring in φ. Show that ∀xφ|{sk(x)/y} |= ∀x ∃yφ, but ∀x ∃yφ �|= ∀xφ|{sk(x)/y} .
(Note: Theknowledgebaseis nowin conjuctive normalform(CNF).)
8. Split conjunctions: split up formulas like φ ∧ ψ into two separate entries in the knowledge base, namely φ and ψ.
9. Flattennesteddisjunctions: flattenformulasoftheform((φ ∨ ψ)∨ χ)into φ ∨ ψ ∨ χ. (This is often done along the way.)
10. Eliminate negations by reintroducing implications.
Example: [Ginsberg1993] If a house is big and old, then it is a lot of work to maintain, unless it comes with a housecleaner and doesn’t have a garden.
We express this sentence of first-order logic using the predicates big, old, work, cleans, and garden, as well as the “type” predicates isa house, isa man, and isa garden:
∀h (isa house(h)∧ big(h)∧ old(h))→ work(h)∨ (∃m isa man(m)∧ cleans(m, h)∧ ¬∃g isa garden(g)∧ garden(g, h))
To demonstrate how to convert a sentence of first-order logic such as this one to normal form, we work with the following simplification which does not include type predicates:
∀h big(h)∧ old(h)→ work(h)∨ (∃m cleans(m, h)∧ ¬∃g garden(g, h))
∀h ¬ (big(h)∧ old(h))∨ work(h)∨ (∃m cleans(m, h)∧ ¬∃g garden(g, h)) ∀h ¬big(h)∨¬old(h)∨ work(h)∨ (∃m cleans(m, h)∧∀g ¬garden(g, h))
3. Standardize variables apart: If the formula were,
∀x ¬big(x)∨¬old(x)∨ work(x)∨ (∃y cleans(y, x)∧∀y ¬garden(y, x))
we could rewrite it as it is written in the previous step.
(¬big(h)∨¬old(h)∨ work(h)∨ cleans(sk cleans(h),h))∧ (¬big(h)∨¬old(h)∨ work(h)∨¬garden(g, h))
8. Split conjuctions:
¬big(h)∨¬old(h)∨ work(h)∨ cleans(sk cleans(h),h) ¬big(h)∨¬old(h)∨ work(h)∨¬garden(g, h)
big(h)∧ old(h)→ work(h)∨ cleans(sk cleans(h),h) big(h)∧ old(h)∧ garden(g, h)→ work(h)
An expression isatermoraformulaof first-orderlogic. Giventwoexpressions e1 ,e2 ,a unifier of e1 and e2 is a substitution σ of terms to variables s.t. e1 |σ = e2 |σ. Given two substitutions σ and τ that unify expressions e1 and e2 , σ is moregeneral than τ iff there existsθ s.t. e1 |τ = e1 |σθ = e2 |σθ = e2 |τ. Intuitively, σ is moregeneral than τ iff σ is less constraining than τ iff σ bindsfewer variables to terms than τ . As an example, consider the expressions g(f (x)) and g(y). The substitution τ = {1/x, f (1)/y} unifies these terms forming g(f (1)). More generally, σ = {f (x)/y} unifies these terms, with θ = {1/x}, as follows: g(f (x))|τ = g(f (x))|σθ = g(f (1))= g(y)|σθ = g(y)|τ.
Given two expressions e1 and e2 ,themostgeneral unification(mgu) algorithm returns the most general substitution σ s.t. e1 |σ = e2 |σ. The mgu algorithm pattern matches as follows:
mgu(e1 ,e2 ,σ)
Inputs expressions e1 and e2 , substitution σ
Output most general unifier σ
(a) if occurs(u, v),fail
′′ ′′
(b) else mgu(e1 ,e 2 ,σ ′ ), whereσ ′ = σ ∪{v/u}, e = e1 |σ′ , and e = e2 |σ′
12
3. else if v is a variable
(a) if occurs(v, u),fail
′′ ′′
(b) else mgu(e1 ,e 2 ,σ ′ ), whereσ ′ = σ ∪{u/v}, e1 = e1 |σ′ , and e2 = e2 |σ′
4. else if neither u nor v are variables, fail
Table 1: Unification Algorithm.
disagree(e1 ,e2 )
Inputs expressions e1 and e2
Output first pair of subexpressions of e1 and e2 that disagree
1. if either of e1 or e2 is a variable or symbol
2. else recursively check if subexpressions of e1 and e2 disagree: return disagree(first(e1 ), first(e2 ))or disagree(rest(e1 ), rest(e2 ))
Table 2: Disagreement Subroutine.
Unification relies on a subroutine that finds the first disagreement between two expressions by recursively comparing the expressions’ constituents(seeTable 2). Soundimplementations of unification also make use of a further subroutine that checks whether one expression occurs within another(see Table 3).
Exercise: Compute the most general unifier or state why no unifier exists, for the following pairs of expressions:
• R(f (x, x),a)and R(f (y, f (y, a)),a)
occurs(x, t)
| Inputs | variable x and term t | ||
|---|---|---|---|
| Output | if | x occurs in t, then return true | |
| if | x does not occur in | t, then return false | |
Table 3: Occurs Check Subroutine.
Solution: No unifier exists, since occurs check fails on y ∈ f (y, a).
• f (f (y, x),x)and f (f (v, f (b, v)),f (u, a))
Solution: The most general unifier σ = {f (b, a)/x, a/y, a/v, b/u}, since f (f (y, x),x)|σ = f (f (a, f (b, a)),f (b, a))= f (f (v, f (b, v)),f (u, a))|σ.
Example: Today is a day, and further, it is one on which we have class. If we have class on a day, thenthatday iseitherTuesday orThursday. IfitisTuesday,thenthe students can relax(students workhard on weekends). If the students are relaxing,thentheirprofessor can relax. Theprofessor can also relax if it is Thursday, since s/he does not teach again until the following Tuesday. Noah is a student. Amy is a professor. (In fact, Amyis Noah’s professor.) Can anyone relax today?
To express this scenario in the language of first-order logic, we introduce the following alphabet:
A = {today, yesterday, tomorrow,..., sunday, monday, tuesday,..., noah, amy,..., prof of(·), C, D, T, H, S, P, R}.
Thedaysinouralphabetareintended torepresentthemselves. Similarly,thenamesareintendedto represent the people being named. The function prof of(·)takes as input a student and returns that student’sprofessor. And thepredicatesincludedin our alphabet canbe understood asfollows:
Using this alphabet, the following formulas express our knowledge base in first-order logic (in normalform). Thefinal sentencerepresentsthenegationof thequery, “Cananyonerelaxtoday?”.
of(x3 ),d3 )
Thefollowingproof-by-refutation shows someone(namely,Noah’sprofessor) can relaxtoday.
D(d1 )∧ C(d1 )→ T (d1 )∨ H(d1 ) ⊤→ D(today)
{today/d1 }
C(today)→ T (today)∨ H(today) ⊤→ C(today) ⊤→ T (today)∨ H(today)
.
.
.
. ⊤→ T (today)∨ H(today) T (d2 )∧ S(x2 )→ R(x2 ,d2 ) ⊤→ D(today) D(x3 )∧ S(x3 )∧ R(x3 ,d3 )→ R(p
{today/d2 }
S(x2 )→ R(x2 , today)∨ H(today) S(x3 )∧ R(x3 ,d3 )→ R(prof S(x2 )→ R(prof
of(x2 ), today)∨ H(today)
.
.
.
.
S(x2 )→ R(prof
of(x2 ), today)∨ H(today) ⊤→ S(noah)
{noah/x2 }
⊤→ R(prof
of(noah), today)∨ H(today) R(x, d)→⊥
{prof
⊤→ H(today)
.
.
.
. ⊤→ H(today) H(x4 )∧ P (d4 )→ R(x4 ,d4 )
{today/d4 }
P (x4 )→ R(x4 , today) ⊤→ P (prof of(noah)) {prof of(noah)/x4 }⊤→ R(prof
of(noah), today)
⊤→⊥