first order logic: =1= first-order resolution

21
V Goranko First Order Logic: First-order resolution. Valentin Goranko DTU Informatics September 2010

Upload: others

Post on 20-Mar-2022

17 views

Category:

Documents


0 download

TRANSCRIPT

V Goranko

First Order Logic:First-order resolution.

Valentin GorankoDTU Informatics

September 2010

V Goranko

First-order resolution

The Propositional Resolution rule extended to first-order logic:

C ∨ Q(s1, . . . , sn), D ∨ ¬Q(s1, . . . , sn)

C ∨ D

This rule, however, is not strong enough.

Example: the clause set

{{P(x)}, {¬P(f (y))}}

is not satisfiable, as it corresponds to the unsatisfiable formula

∀x∀y(P(x) ∧ ¬P(f (y))).

However, the resolution rule above cannot derive an empty clausefrom that clause set, because it cannot unify the two clauses inorder to resolve them.

So, we need a stronger resolution rule.

V Goranko

Two solutions

Solution 1: Ground resolution: generate sufficiently many groundinstances of every clause over a Herbrand universe of the language.

In the example, ground resolution would generate the groundclauses {P(f (c))} and {¬P(f (c))} for some constant symbol c .

This method is sound and complete but inefficient, as it leads tothe generation of too many unnecessary clauses.

Ground resolution was introduced in:John Alan Robinson: A Machine-Oriented Logic Based on theResolution Principle, JACM, 1965.

Will not be discussed further.

Solution 2: Resolution with unification.

V Goranko

Substitutions of terms for variables revisiteds[t/x ] is the result of simultaneous replacements of all occurrencesof x in s by t. For instance:

f (g(x), f (y , x)) [g(a)/x ] = f (g(g(a)), f (y , g(a))).

This can generalize to simultaneous substitutions of several termsfor different variables, denoted s[t1/x1, . . . , tk/xk ]. For instance:

f (g(x), f (y , x)) [g(y)/x , f (x , b)/y ] = f (g(g(y)), f (f (x , b), g(y))).

Given the substitution σ = [t1/x1, . . . , tk/xk ], the set of variables{x1, . . . , xk} is called the domain of σ.

Simultaneity is important: if we first substituted g(y) for x andthen f (x , b) for y the result would have been different (and wrong).

Substitution in a literal is a substitution in all of it argument termssimultaneously. For instance:

P(x , f (x , y), g(y)) [g(y)/x , a/y ] = P(g(y), f (g(y), a), g(a)).

V Goranko

Composition of substitutions

Substitutions can be composed by consecutive application:the composition of substitutions τ and σ is a substitution τσobtained by applying τ followed by applying σ to the result, i.e.,tτσ = (tτ)σ (note the order). For instance:

f (g(x), f (y , x)) [f (x , y)/x ][g(a)/x , x/y ] =

f (g(f (x , y)), f (y , f (x , y))) [g(a)/x , x/y ] =

f (g(f (g(a), x)), f (x , f (g(a), x))).

V Goranko

Computing the composition of substitutions

The composition of two substitutions τ = [t1/x1, . . . , tk/xk ] and σcan be computed as follows:

1. Extend dom(τ) to cover dom(σ) by adding to τ substitutions[x/x ] for every variable x in dom(σ) \ dom(τ).

2. Apply the substitution σ simultaneously to all terms[t1, . . . , tk ] to obtain the substitution [t1σ/x1, . . . , tkσ/xk ].

3. Remove from the result all cases xi/xi , if any.

Example:

[f (x , y)/x , x/y ][y/x , a/y , g(y)/z ] =[f (x , y)/x , x/y , z/z ][y/x , a/y , g(y)/z ]= [f (y , a)/x , y/y , g(y)/z ]= [f (y , a)/x , g(y)/z ] .

V Goranko

Unification of terms

A substitution σ that makes two terms s and t identical is called aunifier of s and t. Examples:

• the substitution [f (y)/x ] unifies the terms x and f (y);

• the substitution [f (c)/x , c/y , c/z ] unifies the termsg(x , f (f (z))) and g(f (y), f (x)).

• There is no unifier for the pair of terms f (x) and g(y),nor for the pair of terms f (x) and x .

V Goranko

Unification of atomic formulae

A substitution σ that makes the (respective arguments of the)atomic formulae Q(s1, . . . , sn) and Q(t1, . . . , tn) identical is calleda unifier of Q(s1, . . . , sn) and Q(t1, . . . , tn). Examples:

• [f (y)/x ] unifies P(x) and P(f (y));

• [f (c)/x , c/y , c/z ] unifies Q(x , c , f (f (z))) andQ(f (y), z , f (x)).

Indeed, the results of applying the substitution σ are:Q(x , c, f (f (z)))σ = Q(f (c), c , f (f (c))),Q(f (y), z , f (x))σ = Q(f (c), c , f (f (c))).

V Goranko

Most general unifiers

A unifier τ of two terms (or, atomic formulae) is more general thana unifier ρ, if ρ = τσ, where σ is some substitution and τσ is thecomposition of σ with τ (i.e, σ applied after τ).

Remark: Every unifier is ’more general’ than itself.Better terminology: ’at least as general’.

Example: ρ = [c/x , f (c)/y ] is a unifier of the literals P(f (x)) andP(y), but τ = [f (x)/y ] is a more general unifier than ρ, becauseρ = τσ, where σ = [c/x ].

A unifier of two terms is their most general unifier (MGU) if it ismore general than any unifier of theirs.Likewise for atomic formulae.

If two terms (or, atomic formulae) are unifiable then they have amost general unifier. However, it need not be unique.

In the example above, τ is a most general unifier, as well as theunifier [z/x , f (z)/y ] for any variable z .

V Goranko

Computing a most general unifier of list of terms

In order to unify two literals Q(s1, . . . , sn) and Q(t1, . . . , tn), wemust unify their respective pairs of arguments, i.e., we are lookingfor a (most general) unifier of the system:

t1 = s1,...tn = sn.

Informally, we do that by computing a most general unifier (if oneexists) of the first pair, then applying it to both lists of terms, thencomputing a most general unifier of the next pair (if there is one)in the resulting lists, applying it to the resulting lists of terms, etc.

In order to unify the current pair of terms we apply the algorithmrecursively to the pair of lists of their respective arguments.

The composition of all most general unifiers computed as above, ifthey all exist, is a most general unifier of the two input lists.

V Goranko

Algorithm for computing most general unifiers

procedure mgu(p, q)θ := ε (the empty substitution).Scan p and q simultaneously, left-to-right,and search for the first corresponding subtermswhere p and q disagree (mismatch).

If there is no mismatch, return θ.Else, let s and t be the first respective subtermsin p and q where mismatch occurs.

If variable(s) and s /∈ Var(t) thenθ := compose(θ,[t/s]);θ := compose(θ, mgu(pθ,qθ)).

Else, if variable(t) and t /∈ Var(s) thenθ := compose(θ,[s/t]);θ := compose(θ, mgu(pθ,qθ)).

Else, return failure.end

V Goranko

Examples of computing most general unifiers

1. Literal 1: parents(x, father(x), mother(Bill)),Literal 2: parents(Bill, father(Bill), y),

MGU: [Bill/x, mother(Bill)/y].

2. Literal 1: parents(x, father(x), mother(Bill)).Literal 2: parents(Bill, father(y), z).

MGU: [Bill/x, Bill/y, mother(Bill)/z].

3. Literal 1: parents(x, father(x), mother(Jane)).Literal 2: parents(Bill, father(y), mother(y)).

MGU: [Bill/x, Bill/y, ...failure].Therefore, MGU does not exist.

4. Term 1: g(x , f (x)).Term 2: g(f (y), y).

MGU: [f(y)/x, . . . failure]. MGU does not exist.

V Goranko

First-order resolution with unification

The first-order Resolution rule is combined with a precedingunification of the clausal set, in order to produce a complementarypair of literals in the resolving clauses:

Res :C ∨ Q(s1, . . . , sn), D ∨ ¬Q(t1, . . . , tn)

(C ∨ D)σ

where:

(i) the two clauses have no variables in common(achieved by renaming of variables, if necessary), and

(ii) σ is an MGU of the literals Q(s1, . . . , sn) and Q(t1, . . . , tn).

We require that the unifier applied in the rule is a most generalunifier of the respective literals in order not to weaken theresolvent unnecessarily.

V Goranko

First-order resolution with unification:some examples of applications of the rule

{P(x)}, {¬P(f (y))}{}

(MGU : [f (y)/x ])

{P(a, y), Q(y)}{¬P(x , b),Q(x)}{Q(b),Q(a)}

(MGU : [a/x , b/y ])

{P(a, y), Q(y)}{¬P(x , f (x)), Q(f (x))}{Q(f (a))}

(MGU : [a/x , f (a)/y ])

Note that both literals in the resolvent become equal.

{P(a, y), P(x , f (x))}{¬P(x , f (a))}{}

(MGU : [a/x , f (a)/y ]).

Note that, after unification, both literals in the first clause becomeP(a, f (a)).

V Goranko

Derivations with first-order resolution

A resolution-based derivation of a formula C from a list offormulae A1, . . . ,An, denoted A1, . . . ,An,`Res C , is a derivation ofthe empty clause {} from the set of clauses obtained fromA1, . . . ,An,¬C , by successive applications of the rule Res.

Theorem: The method of First-order Resolution is sound andcomplete, i.e., for every first-order formulae A1, . . . ,An,C :

A1, . . . ,An,`Res C iff A1, . . . ,An, |= C .

However, unlike Propositional Resolution, First-order Resolutionmay run forever, i.e., never terminate, in some cases when theconclusion does not follow logically from the premises.

It may also run forever even when the conclusion follows logicallyfrom the premises, if unnecessary resolvents are produced.To avoid that, special strategies or additional mechanisms fordisposal of used-up clauses need to be applied.

V Goranko

First-order resolution:factoring

• Factoring:

{. . .P(s),P(t) . . .}{. . .P(s) . . .}σ

, (σ = MGU(s, t))

• Example:

{P(x),P(c),¬Q(x , y)}{P(c),¬Q(c, y)}

(MGU : [c/x ])

• Factoring is a sound rule. Some systems of FOL resolutionemploy it together with the rule Res.

V Goranko

First-order resolution with unification:Example 1

Prove with the method of First-order resolution that:

∀x(P(x)→ Q(x)) |= ∀xP(x)→ ∀xQ(x) :

1. Transform

{∀x(P(x)→ Q(x)),¬(∀xP(x)→ ∀xQ(x))}to clausal form:

{¬P(x),Q(x)}, {P(y)}, {¬Q(c)}for some Skolem constant c .

2. Successive applications of Res:2.1 Unify P(x) and P(y) with MGU [y/x ].

Then resolve {¬P(y),Q(y)} and {P(y)} to obtain {Q(y)}.2.2 Unify Q(c) and Q(y) with MGU [c/y ].

Then resolve {¬Q(c)} and {Q(c)} to obtain {}.

V Goranko

First-order resolution with unification:Example 2

Prove that:

If Everybody loves somebodyand Everybody loves every loverthen Everybody loves everybody.

1. Formalize the assumptions and the goal conclusion, using thepredicate L(x , y) meaning ‘x loves y ’:Everybody loves somebody: ∀x∃yL(x , y).Everybody loves every lover: ∀x(∃yL(x , y)→ ∀zL(z , x)).Everybody loves everybody: ∀x∀yL(x , y).

2. Transform the set{∀x∃yL(x , y), ∀x(∃yL(x , y)→ ∀zL(z , x)), ¬(∀x∀yL(x , y))}to clausal form:

{L(x , f (x))}, {¬L(x1, y), L(z , x1)}, {¬L(a, b)},

for some Skolem constants a, b and a Skolem function f .

V Goranko

Now, apply Res repeatedly to the resulting set of clauses

{L(x , f (x))}, {¬L(x1, y), L(z , x1)}, {¬L(a, b)} :

1. Unify L(z , x1) and L(a, b) with MGU [b/x1, a/z ] and resolve{¬L(b, y), L(a, b)} and {¬L(a, b)} to obtain {¬L(b, y)}.

2. Unify L(x , f (x)) and L(b, y) with MGU [b/x , f (b)/y ] andresolve {L(b, f (b))} and {¬L(b, f (b))} to obtain {}.

V Goranko

First-order resolution with unification:Example 3

Check if

∀x∃yR(x , y),∀x∀y∀z((R(x , y)∧R(y , z))→ R(x , z)) |= ∃xR(x , x) :

Transform

{∀x∃yR(x , y), ∀x∀y∀z((R(x , y)∧R(y , z))→ R(x , z)),¬(∃xR(x , x))}

to clausal form:

C1 = {R(x , f (x))},C2 = {¬R(u, y),¬R(y , z),R(u, z)},C3 = {¬R(v , v)}

for some unary Skolem function f .

V Goranko

Successive applications of Res to the clausal set

C1 = {R(x , f (x))},C2 = {¬R(u, y),¬R(y , z),R(u, z)},C3 = {¬R(v , v)}

1. Unify R(u, z) in C2 and C3, with MGU [v/u, v/z ] and resolve:C4 = {¬R(v , y),¬R(y , v)}.2. Unify R(v , y) in C4 and C1 with MGU [w/x ,w/y , f (w)/v ] andresolve: C5 = {¬R(f (w),w)}.3. Unify R(u, z) in C2 and C5 with MGU [f (w)/u,w/z ] andresolve: C6 = {¬R(f (w), y),¬R(y , f (w))}.4. Unify R(f (w), y) in C6 and C1 with MGU[f (w)/x , f (f (f (w))/y ] and resolve:C7 = {¬R(f (f (w)), f (w))}, etc.

Thus, an infinite set of clauses can be generated:{¬R(f (w),w)}, {¬R(f (f (w)), f (w))}, {¬R(f (f (f (w))), f (f (w)))}, . . .but the empty clause cannot be derived.

In fact, the logical consequence does not hold. A countermodel isthe set of natural numbers with R(x , y) interpreted as x < y .