Browse course

Tutorial 9. FOL inference

Exercise sheet
Unification  

For each of the following pairs of terms determine whether they can be unified. If so, provide the unifier:

  1. LiesBetween Munich y z and LiesBetween x Milan Rome
  2. SitsBeween Mary x x and SitsBetween x Jane y
  3. Between x Rome Rome and Negation Between Rome y x
  4. Negation BornIn fatherOf motherOf x London and Negation BornIn fatherOf y x
  5. Negation Human x and Negation Human fatherOf x
  6. Human fatherOf y x and Human x fatherOf y
Solution
  1. Unifiable with [x / Munich, y / Milan, z / Rome].
  2. Not unifiable since x would need to be both Mary and Jane, which is impossible.
  3. Not unifiable since one formula is a negation and the other isn’t.
  4. Unifiable with [x / London, y / motherOf London]
  5. Not unifiable since whatever x would be it can’t give you fatherOf x.
  6. Unifiable by [x / fatherOf y]
Robinson’s Algorithm  

The first algorithms for unification is due to John Alan Robinson , the father of resolution.

To check whether two FOL literals can be unified, the algorithm proceeds as follows:

  1. Check if either both formulas begin with a negation or neither does. If so, proceed. Otherwise, the formulas are not unifiable.

  2. Check if the predicate in both formulas is the same. If it is, continue. If it is not, the formulas are not unifiable.

  3. We can assume, at this point, that the form of the formulas is covered by one of the two cases:

    • Pⁿ s₁ … sₙ and Pⁿ t₁ … tₙ

    • Negation Pⁿ s₁ … sₙ and Negation Pⁿ t₁ … tₙ

    In both cases, to unify the formulas, we need to find a substitution σ, such that s₁σ = t₁σ, …, sₙσ = tₙσ, that is the result of substituting within these terms must make each pair identical.

    To express this requirement, we make a list of these pairs:

    Eq = [ [s₁, t₁], ..., [sₙ, tₙ] ]

    The algorithm aims to step-wise construct the desired substitution σ. We start with the empty substitution σ = [ ], and go through each pair [sᵢ, tᵢ] of our list. We distinguish the following cases:

    • Case 1: sᵢ = tᵢ. The terms are already identical, we can remove them from Eq.

    • Case 2. sᵢ ≠ tᵢ and sᵢ is some variable, while tᵢ is not. First, check if sᵢ occurs in tᵢ. If so, like when sᵢ = x and tᵢ = fatherOf x, then we can stop the entire procedure since no unification is possible. Otherwise, we apply the substitution [sᵢ / tᵢ] to all other pairs, add it to σ, and remove the pair [sᵢ, tᵢ] from the set.

    • Case 3. sᵢ ≠ tᵢ and tᵢ is some variable, while sᵢ is not. Again, we first check if tᵢ occurs within sᵢ and terminate the entire algorithm if it does. Otherwise, we apply the substitution [tᵢ / sᵢ] to all other pairs, add it to σ, and remove the pair [sᵢ, tᵢ] from the set.

    • Case 4. sᵢ ≠ tᵢ and neither sᵢ nor tᵢ is a variable. Then we check the form of sᵢ and tᵢ. Only if they are of the following forms, we continue:

    sᵢ = fᵐ s₁' … sₘ'   and   tᵢ = fᵐ t₁' … tₘ'

    That is, both terms are the result of applying the same function term to a sequence of terms. If they are not, unification is impossible and we can terminate the algorithm. If they are of this form, we add all the following corresponding pairs to Eq:

    [ [s₁', s₂'], ..., [sₙ', tₙ'] ]
  4. By going through all the pairs, deleting pairs when substitutions are possible or trivial (Cases 1—3), and recursively adding new pairs (Case 4), one of two things will happen:

    • Either we hit a termination condition in one of the cases and conclude that unification isn’t possible.

    • Or we end up with an empty list and a full list of substitutions σ to apply. In that case, σ is a unifier and the terms and thus literals are indeed unifiable.

Apply this algorithm to check your work in Exercise 1.

Solution
  1. Steps 1. & 2. of the algorithm all succeed with no difficulty. So, we check the pairs:

    E = {[Munich, y],[y, Milan], [z, Rome]

    Applying cases 2. and 3. gives us the substitution:

    [x / Munich, y / Milan, z / Rome]
  2. Steps 1. & 2. of the algorithm all succeed with no difficulty. So, we check the pairs:

    E = {[Mary, x], [x, Jane], [x, y]}

    Applying Case 3. with [Mary, x] gives us:

    {[Mary, Jane], [Mary, y]}

    Case 4. tells us to stop when we reach [Mary, Jane]. There is no substitution possible.

  3. Check 1. already fails, the two aren’t unifiable.

  4. Steps 1. & 2. of the algorithm all succeed with no difficulty. So, we check the pairs:

    E = {[fatherOf motherOf x, fatherOf y], [London, x]}

    Step 4 gives us for [fatherOf motherOf x, fatherOf y]:

    E = {[motherOf x, y], [London, x]}

    Applying rule 3. and 4. gives us the substitution:

    [x / London, y / motherOf x]

    which unifies the two formulas.

  5. Steps 1. & 2. of the algorithm all succeed with no difficulty. So, we check the pairs:

    E = { [fatherOf y, x], [x, fatherOf y]}

    which gives us by rule 3 the set

    E = { [fatherOf y, fatherOf y] }

    with substitution [x / fatherOf y], which terminates the algorithm.

Skolemization  

Skolemize the following formulas:

  1. ( exists y₁ Human y₁ Conjunction forall x₁ Mortal x₁)

  2. forall x₁( forall x₂ exists y₁(IsFriendOf x₁ y₁ Conjunction IsFriendOf x₂ y₁) Disjunction exists y₂ Negation IsFriendOf x₁ y₂)

  3. exists y₁ exists y₂ IsFriendOf y₁ y₂

Solution
  1. (Human skolem₁ Conjunction forall x₁ Mortal x₁)

  2. forall x₁( forall x₂(IsFriendOf x₁ skolem₁ x₁ x₂ Conjunction IsFriendOf x₂ skolem₁ x₁ x₂) Disjunction Negation IsFriendOf x₁ skolem₂ x₁)

  3. IsFriendOf skolem₁ skolem₂

Drinker Paradox  

Consider the following inference:

exists x InPub x Therefore exists x (InPub x Conjunction (IsDrinking x Implication forall x(InPub x Implication IsDrinking x)))

In natural language: There’s somebody in the pub, so there’s somebody in the pub, such that if they are drinking, then everybody in the pub is drinking. This is known as the drinker paradox .

Use the method of resolution to show that this inference is deductively valid in FOL. That is:

  1. Form the set of the premise and negation of conclusion.

  2. Transform all formulas into equisatisfiable CNF. Note that the Skolemization of an existential that doesn’t depend on any universals is just a constant skolem. It’s important to document your work, which transformations you’re applying, but you can apply several steps simultaneously.

  3. Apply resolution with unification to derive the empty sequent { }. And conclude that the initial set is unsatisfiable and the inference thus valid.

Solution
  1. The set is:

    { exists x InPub x, Negation exists x (InPub x Conjunction (IsDrinking x Implication forall x(InPub x Implication IsDrinking x)))}
  2. Here are the results of the procedure:

    • The transformation of exists x InPub x just involves one step (Skolemization), which immediately gives us:

      InPub skolem₁
    • The other formula requires some more steps:

      • Negation exists x (InPub x Conjunction (IsDrinking x Implication forall x(InPub x Implication IsDrinking x)))}

      • Two applications of r₀ give:

        Negation exists x (InPub x Conjunction ( Negation IsDrinking x Disjunction forall x( Negation InPub x Disjunction IsDrinking x)))
      • Then we push negations inwards with r₁-r₃ and r₆:

        forall x ( Negation InPub x Disjunction (IsDrinking x Conjunction exists x (InPub x Conjunction Negation IsDrinking x)))
      • Next we make the variables unique:

        forall x₁ ( Negation InPub x₁ Disjunction (IsDrinking x₁ Conjunction exists y₁ (InPub y₁ Conjunction Negation IsDrinking y₁)))
      • Then we Skolemize:

        forall x₁ ( Negation InPub x₁ Disjunction (IsDrinking x₁ Conjunction (InPub skolem₂ x₁ Conjunction Negation IsDrinking skolem₂ x₁)))
      • And drop the universal:

        ( Negation InPub x₁ Disjunction (IsDrinking x₁ Conjunction (InPub skolem₂ x₁ Conjunction Negation IsDrinking skolem₂ x₁)))
      • Finally, repeated distribution gives us:

        ( Negation InPub x₁ Disjunction IsDrinking x) Conjunction ( Negation InPub x Disjunction InPub skolem₂ x) Conjunction ( Negation InPub x Disjunction Negation IsDrinking skolem₂ x))
    • For the resolution, we therefore work with the sets:

      {InPub skolem₁}   { Negation InPub x₁ , IsDrinking x₁}
      { Negation InPub x₁, InPub skolem₂ x}   { Negation InPub x₁, Negation IsDrinking skolem₂ x₁}

      Here’s a derivation of { } from this using resolution:

Natural deduction  

Find logical proofs in FOL natural deduction for the following logical laws. Note that some of these require open Classical.

Duality Laws
  1. Negation forall xA(x) nvdash exists x Negation A(x)
  2. exists x Negation A(x) nvdash Negation forall xA(x)
  3. Negation exists xA(x) nvdash forall x Negation A(x)
  4. forall x Negation A(x) nvdash Negation exists xA(x)
Distribution Laws
  1. forall x(A(x) Conjunction B(x)) nvdash forall xA(x) Conjunction forall xB(x)
  2. forall xA(x) Conjunction forall xB(x) nvdash forall x (A(x) Conjunction B(x))
  3. exists x(A(x) Disjunction B(x)) nvdash exists xA(x) Disjunction exists xB(x)
  4. exists x A(x) Disjunction exists x B(x) nvdash exists x(A(x) Disjunction B(x))
Interaction Laws
  1. forall xA(x) nvdash exists xA(x)
  2. exists x forall yR(x,y) nvdash forall y exists xR(x,y)
  3. exists xA(x) Implication C nvdash forall x(A(x) Implication C), assuming that x is not free in C
  4. forall xA(x) Implication C nvdash exists x(A(x) Implication C), assuming that x is not free in C.
Solution

Duality Laws

  1. Negation forall xA(x) nvdash exists x Negation A(x) (This one’s a bit more difficult)

  2. exists x Negation A(x) nvdash Negation forall xA(x)

  3. Negation exists xA(x) nvdash forall x Negation A(x)

  4. forall x Negation A(x) nvdash Negation exists xA(x)

Distribution Laws

  1. forall x(A(x) Conjunction B(x)) nvdash forall xA(x) Conjunction forall xB(x)

  2. forall xA(x) Conjunction forall xB(x) nvdash forall x (A(x) Conjunction B(x))

  3. exists x(A(x) Disjunction B(x)) nvdash exists xA(x) Disjunction exists xB(x)

  4. exists x A(x) Disjunction exists x B(x) nvdash exists x(A(x) Disjunction B(x))

Interaction Laws

  1. forall xA(x) nvdash exists xA(x)

  2. exists x forall yR(x,y) nvdash forall y exists xR(x,y)

  3. exists xA(x) Implication C nvdash forall x(A(x) Implication C), assuming that x is not free in C

  4. forall xA(x) Implication C nvdash exists x(A(x) Implication C), assuming that x is not free in C.

Lean  

Verify your work from the previous exercise in Lean. Here’s a template for the work. You can follow the link below to work in the interactive environment.

Lean_Logo
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
variable (Term : Type) (A B : Term  Prop) (R : Term  Term  Prop) (C : Prop)

/-! Duality Laws -/

theorem duality_one_ltr (h : ¬∀x, A x) : x, ¬A x := by
  sorry

theorem duality_one_rtl (h : x, ¬A x) : ¬∀x, A x := by
  sorry

theorem duality_two_ltr (h : ¬∃x, A x) : x, ¬A x := by
  sorry

theorem duality_two_rtl (h : x, ¬A x) : ¬∃x, A x := by
  sorry

/-! Duality Laws -/

theorem all_over_and_rtl (h: x, A x  B x) : (x, A x)  (x, B x) := by 
  sorry

theorem all_over_and_ltr (h: (x, A x)  (x, B x)) : x, A x   B x := by
  sorry

theorem exists_over_or_rtl (h: x, A x  B x) : (x, A x)  (x, B x) := by
  sorry

theorem exists_over_or_ltr (h: (x, A x)  (x, B x)) : x, A x  B x := by
  sorry

/-! Interaction Laws -/

theorem existential_import (h: x, A x) : x, A x := by
  sorry

theorem switcheroo (h : x, y, R x y) : y, x, R x y := by
  sorry

theorem exists_to_forall (h: (x, A x)  C) : x, A x  C := by
  sorry

theorem forall_to_exists (h: (x, A x)  C) : x, A x  C := by
  sorry

Follow this link to work in the digital playground.

Solution

Credit: Alexander Apers

Lean_Logo
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
variable (Term : Type) (A B : Term  Prop) (R : Term  Term  Prop) (C : Prop) 

open Classical

/-! Duality Laws -/
theorem duality_one_ltr (h : ¬∀x, A x) : x, ¬A x := by
  apply byContradiction
  intro neg_concl
  apply h 
  intro x
  apply byContradiction
  intro neg_A_c
  apply neg_concl
  apply Exists.intro 
  exact neg_A_c


theorem duality_one_rtl (h : x, ¬A x) : ¬∀x, A x := by
  intro forallxAx
  apply Exists.elim h
  intro x negAc
  apply negAc
  apply forallxAx x


theorem duality_two_ltr (h : ¬∃x, A x) : x, ¬A x := by
  intro x Ac
  apply h
  apply Exists.intro 
  exact Ac


theorem duality_two_rtl (h : x, ¬A x) : ¬∃x, A x := by
  intro existsxAx 
  apply Exists.elim existsxAx
  intro x
  apply h x


/-! Duality Laws -/
theorem all_over_and_rtl (h: x, A x  B x) : (x, A x)  (x, B x) := by 
  apply And.intro 
  intro x
  apply And.left
  apply h x
  intro x
  apply And.right
  apply h x


theorem all_over_and_ltr (h: (x, A x)  (x, B x)) : x, A x   B x := by
  intro x
  apply And.intro
  apply And.left h x
  apply And.right h x
  

theorem exists_over_or_rtl (h: x, A x  B x) : (x, A x)  (x, B x) := by
  apply Exists.elim h
  intro x AcorBc
  apply Or.elim AcorBc
  intro Ac
  apply Or.inl 
  apply Exists.intro 
  exact Ac
  intro Bc
  apply Or.inr
  apply Exists.intro
  exact Bc


theorem exists_over_or_ltr (h: (x, A x)  (x, B x)) : x, A x  B x := by
  apply Or.elim h
  intro existsxAx
  apply Exists.elim existsxAx
  intro x Ac
  apply Exists.intro
  apply Or.inl Ac 
  intro existsxBx
  apply Exists.elim existsxBx
  intro x Bc
  apply Exists.intro
  apply Or.inr Bc


/-! Interaction Laws -/
-- note: This proof requires explicitly telling lean we are working with a non-empty domain. 
-- Since this was not discussed in the textbook it is not expected that you are able to do this.
-- solved by Johannes
theorem existential_import [Inhabited Term] (h: x, A x) : x, A x := by
  apply Exists.intro
  apply h 
  exact default

theorem switcheroo (h : x, y, R x y) : y, x, R x y := by
  intro y
  apply Exists.elim h
  intro x Rcd
  apply Exists.intro 
  apply Rcd


theorem exists_to_forall (h: (x, A x)  C) : x, A x  C := by
  intro x Ad
  apply h
  apply Exists.intro
  exact Ad

-- note: this proof also required a non-empty domain
-- solved by Johannes
theorem forall_to_exists [Inhabited Term] (h: (x, A x)  C) : x, A x  C := by
  apply byContradiction
  intro neg_existsxAxtoC
  apply neg_existsxAxtoC
  · apply Exists.intro (default : Term)
    intro Ad
    apply h
    apply byContradiction
    intro neg_allxAx
    apply neg_existsxAxtoC
    apply Exists.elim
    · apply duality_one_ltr 
      exact neg_allxAx
    · intro c neg_Ac
      apply Exists.intro
      · intro Ac
        apply False.elim
        apply neg_Ac Ac

You can review the code in the lean plaground by following this link .