First Order Logic: First-order resolution. Valentin Goranko DTU - - PowerPoint PPT Presentation

first order logic first order resolution
SMART_READER_LITE
LIVE PREVIEW

First Order Logic: First-order resolution. Valentin Goranko DTU - - PowerPoint PPT Presentation

First Order Logic: First-order resolution. Valentin Goranko DTU Informatics September 2010 V Goranko First-order resolution The Propositional Resolution rule extended to first-order logic: C Q ( s 1 , . . . , s n ) , D Q ( s 1 , .


slide-1
SLIDE 1

V Goranko

First Order Logic: First-order resolution.

Valentin Goranko DTU Informatics September 2010

slide-2
SLIDE 2

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 clause from that clause set, because it cannot unify the two clauses in

  • rder to resolve them.

So, we need a stronger resolution rule.

slide-3
SLIDE 3

V Goranko

Two solutions

Solution 1: Ground resolution: generate sufficiently many ground instances of every clause over a Herbrand universe of the language. In the example, ground resolution would generate the ground clauses {P(f (c))} and {¬P(f (c))} for some constant symbol c. This method is sound and complete but inefficient, as it leads to the generation of too many unnecessary clauses. Ground resolution was introduced in: John Alan Robinson: A Machine-Oriented Logic Based on the Resolution Principle, JACM, 1965. Will not be discussed further. Solution 2: Resolution with unification.

slide-4
SLIDE 4

V Goranko

Substitutions of terms for variables revisited

s[t/x] is the result of simultaneous replacements of all occurrences

  • f 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 terms for 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 and then 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 terms

  • simultaneously. For instance:

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

slide-5
SLIDE 5

V Goranko

Composition of substitutions

Substitutions can be composed by consecutive application: the composition of substitutions τ and σ is a substitution τσ

  • btained 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))).

slide-6
SLIDE 6

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] .

slide-7
SLIDE 7

V Goranko

Unification of terms

A substitution σ that makes two terms s and t identical is called a unifier 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 terms

g(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.

slide-8
SLIDE 8

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 called a 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))) and

Q(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))).

slide-9
SLIDE 9

V Goranko

Most general unifiers

A unifier τ of two terms (or, atomic formulae) is more general than a unifier ρ, if ρ = τσ, where σ is some substitution and τσ is the composition 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)) and P(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 is more general than any unifier of theirs. Likewise for atomic formulae. If two terms (or, atomic formulae) are unifiable then they have a most general unifier. However, it need not be unique. In the example above, τ is a most general unifier, as well as the unifier [z/x, f (z)/y] for any variable z.

slide-10
SLIDE 10

V Goranko

Computing a most general unifier of list of terms

In order to unify two literals Q(s1, . . . , sn) and Q(t1, . . . , tn), we must unify their respective pairs of arguments, i.e., we are looking for a (most general) unifier of the system: t1 = s1, . . . tn = sn. Informally, we do that by computing a most general unifier (if one exists) of the first pair, then applying it to both lists of terms, then computing 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 algorithm recursively to the pair of lists of their respective arguments. The composition of all most general unifiers computed as above, if they all exist, is a most general unifier of the two input lists.

slide-11
SLIDE 11

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 subterms where p and q disagree (mismatch). If there is no mismatch, return θ. Else, let s and t be the first respective subterms in 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

slide-12
SLIDE 12

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.

slide-13
SLIDE 13

V Goranko

First-order resolution with unification

The first-order Resolution rule is combined with a preceding unification of the clausal set, in order to produce a complementary pair 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 general unifier of the respective literals in order not to weaken the resolvent unnecessarily.

slide-14
SLIDE 14

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 become P(a, f (a)).

slide-15
SLIDE 15

V Goranko

Derivations with first-order resolution

A resolution-based derivation of a formula C from a list of formulae A1, . . . , An, denoted A1, . . . , An, ⊢Res C, is a derivation of the empty clause {} from the set of clauses obtained from A1, . . . , An, ¬C, by successive applications of the rule Res. Theorem: The method of First-order Resolution is sound and complete, i.e., for every first-order formulae A1, . . . , An, C: A1, . . . , An, ⊢Res C iff A1, . . . , An, | = C. However, unlike Propositional Resolution, First-order Resolution may run forever, i.e., never terminate, in some cases when the conclusion does not follow logically from the premises. It may also run forever even when the conclusion follows logically from the premises, if unnecessary resolvents are produced. To avoid that, special strategies or additional mechanisms for disposal of used-up clauses need to be applied.

slide-16
SLIDE 16

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 resolution

employ it together with the rule Res.

slide-17
SLIDE 17

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 {}.

slide-18
SLIDE 18

V Goranko

First-order resolution with unification: Example 2

Prove that: If Everybody loves somebody and Everybody loves every lover then Everybody loves everybody.

  • 1. Formalize the assumptions and the goal conclusion, using the

predicate 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 .

slide-19
SLIDE 19

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] and

resolve {L(b, f (b))} and {¬L(b, f (b))} to obtain {}.

slide-20
SLIDE 20

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 .

slide-21
SLIDE 21

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] and

resolve: C5 = {¬R(f (w), w)}.

  • 3. Unify R(u, z) in C2 and C5 with MGU [f (w)/u, w/z] and

resolve: 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 is the set of natural numbers with R(x, y) interpreted as x < y.