Lecture 9 First-Order Logic Reasoning and...

59
Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412: Symbolic AI Giles Reger February 2019 Giles Reger Lecture 9 February 2019 1 / 28

Transcript of Lecture 9 First-Order Logic Reasoning and...

Page 1: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Lecture 9 First-Order LogicReasoning and Transformation to Clausal Form

COMP24412: Symbolic AI

Giles Reger

February 2019

Giles Reger Lecture 9 February 2019 1 / 28

Page 2: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Aim and Learning Outcomes

The aim of this lecture is to:

Look at the saturation-based setting and the first step of transforming toclausal form

Learning Outcomes

By the end of this lecture you will be able to:

1 Recall the saturation loop and the main steps in it

2 Describe the clausal transformation pipeline

3 Transform general first-order formulas into clausal form

4 Identify points where this transformation could be optimised

5 Recall how to run Vampire to perform resolution and clausification

Giles Reger Lecture 9 February 2019 2 / 28

Page 3: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Unification (Recap)

In first-order logic every two terms have a most general unifier

A substitution σ is a unifier for two terms t1 and t2 if σ(t1) = σ(t2)

I avoid giving a very formal definition of more general but a unifier σ1 ismore general than σ2 if σ2(t) is always an instance of σ1(t)

There is a relatively straightforward algorithm for generating most generalunifiers called Robinsons Algorithm (does the obvious thing) but in realitywe compute unifiers using special data structures.

Giles Reger Lecture 9 February 2019 3 / 28

Page 4: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Clauses and Resolution (Recap)

A literal is an an atom or its negation. A clause is a disjunction of literals.

Clauses are implicitly universally quantified.

We can think of a clause as a conjunction implying a disjunction e.g.

(a1 ∧ . . . an)→ (b1 ∨ . . . ∨ bm)

An empty clause is false.

Resolution works on clauses

l1 ∨ C ¬l2 ∨ D

(C ∨ D)θθ = mgu(l1, l2)

Giles Reger Lecture 9 February 2019 4 / 28

Page 5: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Refutational Based Reasoning

We are going to look at a reasoning method that works by refutation.

Recall Γ |= φ if and only if Γ ∪ {¬φ} |= false

If we want to show that φ is entailed by Γ we can show that Γ ∪ {¬φ} isinconsistent

This is refutational based reasoning.

We will saturate Γ ∪ {¬φ} until there is nothing left to add or we havederived false.

If we do not find false then Γ 6|= φ.

There are some caveats we will meet later.

Giles Reger Lecture 9 February 2019 5 / 28

Page 6: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Refutational Based Reasoning

We are going to look at a reasoning method that works by refutation.

Recall Γ |= φ if and only if Γ ∪ {¬φ} |= false

If we want to show that φ is entailed by Γ we can show that Γ ∪ {¬φ} isinconsistent

This is refutational based reasoning.

We will saturate Γ ∪ {¬φ} until there is nothing left to add or we havederived false.

If we do not find false then Γ 6|= φ.

There are some caveats we will meet later.

Giles Reger Lecture 9 February 2019 5 / 28

Page 7: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)

|= happy(giles)

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 8: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)

¬rich(giles)false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 9: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)

¬rich(giles)false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 10: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)¬rich(giles)

false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 11: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)¬rich(giles)

false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 12: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)¬rich(giles)false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 13: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Resolving to false

¬rich(x) ∨ happy(x)rich(giles)¬happy(giles)¬rich(giles)false

We could have done it in the other order (picked ¬rich(x) first). We’ll findout later that it’s better to organise proof search to avoid this redundancy.

Giles Reger Lecture 9 February 2019 6 / 28

Page 14: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

What about Equality?

¬rich(father(x)) ∨ happy(x)rich(david)father(giles) = david

|= happy(giles)

Giles Reger Lecture 9 February 2019 7 / 28

Page 15: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

What about Equality?

¬rich(father(x)) ∨ happy(x)rich(david)father(giles) = david¬happy(giles)

¬rich(father(giles))

father(x) and david do not unify.

Giles Reger Lecture 9 February 2019 7 / 28

Page 16: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

What about Equality?

¬rich(father(x)) ∨ happy(x)rich(david)father(giles) = david¬happy(giles)

¬rich(father(giles))

father(x) and david do not unify.

Giles Reger Lecture 9 February 2019 7 / 28

Page 17: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

What about Equality?

¬rich(father(x)) ∨ happy(x)rich(david)father(giles) = david¬happy(giles)¬rich(father(giles))

father(x) and david do not unify.

Giles Reger Lecture 9 February 2019 7 / 28

Page 18: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

What about Equality?

¬rich(father(x)) ∨ happy(x)rich(david)father(giles) = david¬happy(giles)¬rich(father(giles))

father(x) and david do not unify.

Giles Reger Lecture 9 February 2019 7 / 28

Page 19: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Paramodulation

The paramodulation rule lifts the idea behind resolution to equality

C ∨ s = t l [u] ∨ D

(l [t] ∨ C ∨ D)θθ = mgu(s, u)

where u is not a variable.

For example

father(giles) = david ¬rich(father(x)) ∨ happy(x)

¬rich(david) ∨ happy(giles)

where u = father(x) and therefore θ = {x 7→ giles}.

Giles Reger Lecture 9 February 2019 8 / 28

Page 20: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Paramodulation

The paramodulation rule lifts the idea behind resolution to equality

C ∨ s = t l [u] ∨ D

(l [t] ∨ C ∨ D)θθ = mgu(s, u)

where u is not a variable.

For example

father(giles) = david ¬rich(father(x)) ∨ happy(x)

¬rich(david) ∨ happy(giles)

where u = father(x) and therefore θ = {x 7→ giles}.

Giles Reger Lecture 9 February 2019 8 / 28

Page 21: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Special case: unit equalities

The demodulation rule works with unit equalities

s = t l [u] ∨ D

(l [t] ∨ D)θθ = matches(s, u)

Note that u must be an instance of s.

Why is this special? The premise l [u] ∨ D becomes redundant. We’ll findout what that means properly next time but it means we can remove it.

Notice that we could apply this in either direction - this is going to lead toredundancy and later we will see that we should (where possible) orderequalities so that we rewrite more complicated things with simpler things.

Giles Reger Lecture 9 February 2019 9 / 28

Page 22: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Equality Resolution

We have another special case, is the following ever true?

∀x .f (x) 6= f (a)

e.g. for every input to f the result is not equal to applying f to a.

Functions in first-order logic are always total

So, no. We have a rule called equality resolution

s 6= t ∨ C

Cθθ = mgu(s, t)

e.g. if we can make two terms equal then any disequality is false.

Giles Reger Lecture 9 February 2019 10 / 28

Page 23: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Equality Resolution

We have another special case, is the following ever true?

∀x .f (x) 6= f (a)

e.g. for every input to f the result is not equal to applying f to a.

Functions in first-order logic are always total

So, no. We have a rule called equality resolution

s 6= t ∨ C

Cθθ = mgu(s, t)

e.g. if we can make two terms equal then any disequality is false.

Giles Reger Lecture 9 February 2019 10 / 28

Page 24: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Equality Resolution

We have another special case, is the following ever true?

∀x .f (x) 6= f (a)

e.g. for every input to f the result is not equal to applying f to a.

Functions in first-order logic are always total

So, no. We have a rule called equality resolution

s 6= t ∨ C

Cθθ = mgu(s, t)

e.g. if we can make two terms equal then any disequality is false.

Giles Reger Lecture 9 February 2019 10 / 28

Page 25: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

More Examples Using Vampire

Vampire is a first-order theorem prover

It works on Clauses and implements resolution (and lots of other rules)

It takes problems in either TPTP or STM-LIB format

cnf(one,axiom, ~rich(X) | happy(X)).

cnf(two,axiom, rich(giles)).

cnf(three, negated_conjecture, ~happy(giles)).

The above is TPTP format already in conjunctive normal form.

Giles Reger Lecture 9 February 2019 11 / 28

Page 26: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Saturation Based Reasoning

To decide Γ |= ϕ we are going to follow the below steps

1 Let NotDone = Γ ∪ {¬ϕ}2 Transform NotDone into clauses

3 Let Done be an empty set of clauses

4 Select a clause c from NotDone

5 Perform all inferences (e.g. resolution) between c and all clauses inDone putting any new children in NotDone

6 Move c to Done

7 If one of the children was false then return valid

8 If NotDone is empty stop otherwise go to 4

9 return not valid

Giles Reger Lecture 9 February 2019 12 / 28

Page 27: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Saturation Based Reasoning

To decide Γ |= ϕ we are going to follow the below steps

1 Let NotDone = Γ ∪ {¬ϕ}2 Transform NotDone into clauses

3 Let Done be an empty set of clauses

4 Select a clause c from NotDone

5 Perform all inferences (e.g. resolution) between c and all clauses inDone putting any new children in NotDone

6 Move c to Done

7 If one of the children was false then return valid

8 If NotDone is empty stop otherwise go to 4

9 return not valid

Giles Reger Lecture 9 February 2019 12 / 28

Page 28: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Transformation to Clausal Form

To go from general formula to set of clauses we’re going to go through thefollowing steps

1 Rectify the formula

2 Transform to Negation Normal Form

3 Eliminate quantifiers

4 Transform into conjunctive normal form

At any stage we might simplify using rules about true and false, e.g.false ∧ φ = false, and remove tautologies, e.g. p ∨ p.

Giles Reger Lecture 9 February 2019 13 / 28

Page 29: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Rectification

A formula is rectified if each quantifier binds a different variable and allbound variables are distinct from free ones.

To rectify a formula we identify any name clashes, pick one and rename itconsistently. It is important to work out which variables are in the scope ofa quantifier e.g.

∀x .(p(x) ∨ ∃x .r(x)) becomes ∀x(p(x) ∨ ∃y .r(y))

To automate this we typically rename bound variables starting with x0 etc.

Giles Reger Lecture 9 February 2019 14 / 28

Page 30: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Negation Normal Form

Apply rules in a completely deterministic syntactically-guided way

¬(F1 ∧ . . . ∧ Fn) ⇒ ¬F1 ∨ . . . ∨ ¬Fn¬(F1 ∨ . . . ∨ Fn) ⇒ ¬F1 ∧ . . . ∧ ¬Fn

F1 → F2 ⇒ ¬F1 ∨ F2

¬¬F ⇒ F

¬∀x1, . . . , xnF ⇒ ∃x1, . . . , xn¬F¬∃x1, . . . , xnF ⇒ ∀x1, . . . , xn¬F¬(F1 ↔ F2) ⇒ F1 ⊗ F2

¬(F1 ⊗ F2) ⇒ F1 ↔ F2

F1 ↔ F2 ⇒ (F1 → F2) ∧ (F2 → F1);

F1 ⊗ F2 ⇒ (F1 ∨ F2) ∧ (¬F1 ∨ ¬F2).

Where ⊗ is exclusive or. Can get an exponential increase in size.

Giles Reger Lecture 9 February 2019 15 / 28

Page 31: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Examples

(∀x .p(x))→ (∃x .p(x))

(∀x .(p(x) ∨ q(x))↔ (¬∃x .(¬p(x) ∧ ¬q(x)))

∀x , y , z .((f (x) = y ∧ f (x) = z)→ y = z)

∀x .((∃y .p(x , y))→ q(x)) ∧ p(a, b) ∧ ¬∃x .q(x)

Also, which of the above statements are valid or inconsistent?

Giles Reger Lecture 9 February 2019 16 / 28

Page 32: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∃x .∀y .((pizza(x) ∧ pizza(y) ∧ x 6= y)→ better(x , y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 33: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∃x .∀y .((pizza(x) ∧ pizza(y) ∧ x 6= y)→ better(x , y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 34: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∃x .∀y .((pizza(x) ∧ pizza(y) ∧ x 6= y)→ better(x , y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 35: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∃x .∀y .((pizza(x) ∧ pizza(y) ∧ x 6= y)→ better(x , y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 36: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∃x .∀y .(¬pizza(x) ∨ ¬pizza(y) ∨ x = y ∨ better(x , y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 37: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 38: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same house∃x .∃y .∃z .(x 6= y ∧ lives in(x , z) ∧ lives in(y , z))

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 39: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same housea 6= b ∧ lives in(a, c) ∧ lives in(b, c)

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∃x .φ[x ]) is true then there must besome domain constant d such that I(φ[d ]) is true.

Let a be a fresh constant symbol (a new name for the object that has toexist). As it is fresh we can freely let I(a) = d .(This requires the Axiom of Choice)

Giles Reger Lecture 9 February 2019 17 / 28

Page 40: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same housea 6= b ∧ lives in(a, c) ∧ lives in(b, c)

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∀x .∃y .φ[x , y ]) is true then for everydomain constant d1 there must be some other domain constant d2 suchthat I(φ[d1, d2]) is true. But how do we find d2 given d1?

Let f be a fresh function symbol whose interpretation can be made toselect the necessary domain constant.

Giles Reger Lecture 9 February 2019 17 / 28

Page 41: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same housea 6= b ∧ lives in(a, c) ∧ lives in(b, c)

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∀x .∃y .φ[x , y ]) is true then for everydomain constant d1 there must be some other domain constant d2 suchthat I(φ[d1, d2]) is true. But how do we find d2 given d1?

Let f be a fresh function symbol whose interpretation can be made toselect the necessary domain constant.

Giles Reger Lecture 9 February 2019 17 / 28

Page 42: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same housea 6= b ∧ lives in(a, c) ∧ lives in(b, c)

Everybody loves somebody∀x .∃y .loves(x , y)

Let I be some interpretation. If I(∀x .∃y .φ[x , y ]) is true then for everydomain constant d1 there must be some other domain constant d2 suchthat I(φ[d1, d2]) is true. But how do we find d2 given d1?

Let f be a fresh function symbol whose interpretation can be made toselect the necessary domain constant.

Giles Reger Lecture 9 February 2019 17 / 28

Page 43: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Existential Quantifiers

There is a best kind of pizza∀y .(¬pizza(a) ∨ ¬pizza(y) ∨ a = y ∨ better(a, y))

There are two different people who live in the same housea 6= b ∧ lives in(a, c) ∧ lives in(b, c)

Everybody loves somebody∀x .loves(x , f (x))

Let I be some interpretation. If I(∀x .∃y .φ[x , y ]) is true then for everydomain constant d1 there must be some other domain constant d2 suchthat I(φ[d1, d2]) is true. But how do we find d2 given d1?

Let f be a fresh function symbol whose interpretation can be made toselect the necessary domain constant.

Giles Reger Lecture 9 February 2019 17 / 28

Page 44: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Dealing with Universal Quantifiers

Forget about them

Giles Reger Lecture 9 February 2019 18 / 28

Page 45: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Skolemisation

This process is called Skolemisation and the new symbols we introduce arecalled Skolem constants or Skolem functions.

The rules are simply

∀x1, . . . , xnF ⇒ F

∃x1, . . . , xnF ⇒ F{x1 7→ f1(y1, . . . , ym), . . . , xn 7→ fn(y1, . . . , ym)},

where fi are fresh function symbols of the correct arrity and y1, . . . ym arethe free variables of F e.g. they are the things universally quantified in thelarger scope.

Remember that Skolem constants/functions act as witnesses forsomething that we know has to exist for the formula to be true.

Giles Reger Lecture 9 February 2019 19 / 28

Page 46: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Validity or Satisfiability Preserving?

Do these two formulas have the same models?

∃x .∀y .p(x , y) ∀y .p(a, y)

No - the first one does not need to interpret a

Do the formulas both have models?

Yes - there’s no negation, just make everything true

When we introduce new symbols we preserve satisfiability (the existence ofmodels) not validity (the same models).

However, most transformations are stronger than this and preserve modelson the initial signature.

Giles Reger Lecture 9 February 2019 20 / 28

Page 47: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Validity or Satisfiability Preserving?

Do these two formulas have the same models?

∃x .∀y .p(x , y) ∀y .p(a, y)

No - the first one does not need to interpret a

Do the formulas both have models?

Yes - there’s no negation, just make everything true

When we introduce new symbols we preserve satisfiability (the existence ofmodels) not validity (the same models).

However, most transformations are stronger than this and preserve modelson the initial signature.

Giles Reger Lecture 9 February 2019 20 / 28

Page 48: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Validity or Satisfiability Preserving?

Do these two formulas have the same models?

∃x .∀y .p(x , y) ∀y .p(a, y)

No - the first one does not need to interpret a

Do the formulas both have models?

Yes - there’s no negation, just make everything true

When we introduce new symbols we preserve satisfiability (the existence ofmodels) not validity (the same models).

However, most transformations are stronger than this and preserve modelson the initial signature.

Giles Reger Lecture 9 February 2019 20 / 28

Page 49: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Validity or Satisfiability Preserving?

Do these two formulas have the same models?

∃x .∀y .p(x , y) ∀y .p(a, y)

No - the first one does not need to interpret a

Do the formulas both have models?

Yes - there’s no negation, just make everything true

When we introduce new symbols we preserve satisfiability (the existence ofmodels) not validity (the same models).

However, most transformations are stronger than this and preserve modelson the initial signature.

Giles Reger Lecture 9 February 2019 20 / 28

Page 50: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Validity or Satisfiability Preserving?

Do these two formulas have the same models?

∃x .∀y .p(x , y) ∀y .p(a, y)

No - the first one does not need to interpret a

Do the formulas both have models?

Yes - there’s no negation, just make everything true

When we introduce new symbols we preserve satisfiability (the existence ofmodels) not validity (the same models).

However, most transformations are stronger than this and preserve modelson the initial signature.

Giles Reger Lecture 9 February 2019 20 / 28

Page 51: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

CNF Transformation

Now the only connectives left should be ∧ and ∨ and we need to push the∨ symbols under the ∧ symbols

The associated rule is

(A1 ∧ . . . ∧ Am) ∨ B1 ∨ . . . ∨ Bn ⇒ (A1 ∨ B1 ∨ . . . ∨ Bn) ∧· · · ∧

(Am ∨ B1 ∨ . . . ∨ Bn).

This can lead to exponential growth.

Giles Reger Lecture 9 February 2019 21 / 28

Page 52: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Looking at Vampire’s clausification

Run

./vampire --mode clausify problem

on problem file problem

It will sometimes do a lot more than what we’ve discussed above.

Vampire performs lots of optimisations e.g. naming subformulas, removingpure symbols, or unused definitions.

Giles Reger Lecture 9 February 2019 22 / 28

Page 53: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Examples

(∀x .p(x))→ (∃x .p(x))

(∀x .(p(x) ∨ q(x))↔ (¬∃x .(¬p(x) ∧ ¬q(x)))

∀x , y , z .((f (x) = y ∧ f (x) = z)→ y = z)

∀x .((∃y .p(x , y))→ q(x)) ∧ p(a, b) ∧ ¬∃x .q(x)

Also, which of the above statements are valid or inconsistent?

Giles Reger Lecture 9 February 2019 23 / 28

Page 54: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Optimisation (subformula naming)

To go from general formula to set of clauses we’re going to go through thefollowing steps

1 Rectify the formula

2 Transform to Equivalence Negation Form

3 Apply naming of subformulas

4 Transform to Negation Normal Form

5 Eliminate quantifiers

6 Transform into conjunctive normal form

Giles Reger Lecture 9 February 2019 24 / 28

Page 55: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Equivalence Negation Form

Push negations in but preserve equivalences

¬(F1 ∧ . . . ∧ Fn) ⇒ ¬F1 ∨ . . . ∨ ¬Fn¬(F1 ∨ . . . ∨ Fn) ⇒ ¬F1 ∧ . . . ∧ ¬Fn

F1 → F2 ⇒ ¬F1 ∨ F2

¬¬F ⇒ F

¬∀x1, . . . , xnF ⇒ ∃x1, . . . , xn¬F¬∃x1, . . . , xnF ⇒ ∀x1, . . . , xn¬F¬(F1 ↔ F2) ⇒ F1 ⊗ F2

¬(F1 ⊗ F2) ⇒ F1 ↔ F2

Only get a linear increase in size.

Giles Reger Lecture 9 February 2019 25 / 28

Page 56: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Subformula Naming

We want to get to a conjunction of disjunctions but this process can ‘blowup’ in general e.g.

p(x , y)↔ (q(x)↔ (p(y , y)↔ q(y))),

is equivalent to

p(x , y) ∨ ¬q(y) ∨ ¬p(y , y) ∨ ¬q(x))p(x , y) ∨ q(y) ∨ p(y , y) ∨ ¬q(x))p(x , y) ∨ p(y , y) ∨ ¬q(y) ∨ q(x))p(x , y) ∨ q(y) ∨ ¬p(y , y) ∨ q(x))

q(x) ∨ ¬q(y) ∨ ¬p(y , y) ∨ ¬p(x , y))q(x) ∨ q(y) ∨ p(y , y) ∨ ¬p(x , y))

p(y , y) ∨ ¬q(y) ∨ ¬q(x) ∨ ¬p(x , y))q(y) ∨ ¬p(y , y) ∨ ¬q(x) ∨ ¬p(x , y))

Giles Reger Lecture 9 February 2019 26 / 28

Page 57: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Subformula Naming

We can replace

p(x , y)↔ (q(x)↔ (p(y , y)↔ q(y))),

byp(x , y)↔ (q(x)↔ n(y));n(y)↔ (p(y , y)↔ q(y)).

to get the same number of clauses but each clause is simpler (better forreasoning).

In the case when the subformula F (x1, . . . , xk) has only positiveoccurrences in G , one can use the axiom n(x1, . . . , xk)→ F (x1, . . . , xk)instead of n(x1, . . . , xk)↔ F (x1, . . . , xk). This will lead to fewer clauses.

Giles Reger Lecture 9 February 2019 27 / 28

Page 58: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

Subformula Naming

Assigning a name n to F2 ↔ F3 yields two formulas

F1 ↔ n;n↔ (F2 ↔ F3),

where the second formula has the same structure as the original formulaF1 ↔ (F2 ↔ F3).

Giles Reger Lecture 9 February 2019 28 / 28

Page 59: Lecture 9 First-Order Logic Reasoning and …syllabus.cs.manchester.ac.uk/ugt/2018/COMP24412/2018...Lecture 9 First-Order Logic Reasoning and Transformation to Clausal Form COMP24412:

When to Name Subformulas?

Vampire uses a heuristic that that estimates how many clauses asubformula will produce and names that subformula if that number isabove a certain threshold.

Naming can not increase the number of clauses introduced but does notalways reduce.

The idea is the same as the optimised structural transformation in thepropositional case but we don’t always apply it as the cost on reasoning ismuch higher here.

Giles Reger Lecture 9 February 2019 29 / 28