Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax...

26
Introduction to Automated Theorem Proving Tudor Jebelean Jan 2007

Transcript of Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax...

Page 1: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

Introduction to Automated Theorem Proving

Tudor Jebelean

Jan 2007

Page 2: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

Contents

1 Propositional Logic 2

1.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.1.1 Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.1.2 Interesting equivalences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1.1.3 Transformation rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.1.4 The Resolution Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1.1.5 The Method of Davis and Putnam . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2 First-order Predicate Logic 14

2.1 Definition of syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.2 Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.3 Truth evaluation〈ϕ〉I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.3.1 Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.3.2 Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.3.3 Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.4 Skolem transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.5 Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

2.5.1 Resolution principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

2.5.2 Resolution method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.5.2.1 Correct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.5.2.2 Complete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1

Page 3: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

Chapter 1

Propositional Logic

1.1 Syntax

Propositional logic is a mathematical model of reasoning with elementary statements (or propositions).Such a proposition (like “It rains.”) has the only characteristic that it can be true or false, and thus it isdenoted by a “propositional symbol” (also called “propositional variable”) about which we only know thatit can be true or false.

Example:

" it rains︸ ︷︷ ︸A

and it is sunny︸ ︷︷ ︸ "

B

or for instance

" it rains︸ ︷︷ ︸A

and it is not sunny︸ ︷︷ ︸ "

¬B

The syntax of propositional logic consists in the definition of the set of all propositional logic formulae, orthe language of propositional logic formulae, which will contain formulae like:

L . . . Languagewith "words" like

A∧ B

A∧ ¬B(¬A∧ B)⇔ (A⇒ B)

A∧ ¬A

The languageL is defined over a certain setΣ of symbols: the parantheses, the logical connectives, thelogical constants, and an infinite setΘ of propositional variables.

Set of "symbols""alphabet"

Σ = (, ) ∪ ¬,∧,∨,⇒,⇔ ∪ T,F ∪ Θ

Note: Θ is the set of propositional variables. for instance this could beA, B,C,P,Q, . . . ,A1,A2, . . . . ThissetΘ is infinite, but enumerable.

All formulae are words over this alphabetΣ.

2

Page 4: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 3

Generalized Inductive Definition

(0) T,F ∈ L or one can also writeT,F ⊂ L

(1) if ϑ ∈ Θ︸︷︷︸"variable"

, then ϑ ∈ L︸ ︷︷ ︸"word", logical formula

(a propositional variableϑ "is" also a logical formula)

(2) if ϕ, ψ ∈ L , then ¬ϕ︸︷︷︸, (ϕ ∧ ψ)︸ ︷︷ ︸, (ϕ ∨ ψ)︸ ︷︷ ︸, (ϕ⇒ ψ)︸ ︷︷ ︸, (ϕ⇔ ψ)︸ ︷︷ ︸ ∈ L︸ ︷︷ ︸"are also words in the language"

(3) These are all the formulae.

Note thatΣ∗ also has the properties(0), (1)and(2). However,[3] means thatL is the smallest set havingthese properties. This allows us to use the structural induction principle in order to prove properties offormulae.

Atoms and literals. Formulae consisting in a single propositional variable are called“atoms” . Formulaeconsisting in an atom or a negated atom are called“literals” .

Notation: Sometimes we will denote¬ϕ by ϕ. Also, if L is a literal, we will denote byL the opposite ofL (that isA if L is A, andA if L is A).

Exercise: Formulate the grammar for the language of propositional logic.

P =

W→ T | F | A | B | C

W→ (¬W) | (W∧W) | . . .

GrammarG = ( Σ︸︷︷︸"alphabet"

, ΣN︸︷︷︸"nonterminal

symbols"

, S︸︷︷︸"nonterminalstart symbol"

, P︸︷︷︸set of

productions

)

Σ = T,F ∪ Θ ∪ (, ),¬,∨,∧,⇒,⇔

ΣN = W

S = ΣN

1.1.1 Semantics

Example: Intuitively, the meaning of “A∧ B” is that "this is only true if both A and B are true".

fA∧B T F

T T F

F F F

Table 1.1: Semantic value ofA∧ B.

Page 5: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 4

The semantic value (or the meaning) of the formulaA ∧ B is the functionfA∧B : IA,B → T,F, whereIA,B = I : A, B → T,F is the set of all assignments of truth values to the variablesA, B.

I is called an“interpretation” for the formulaA∧ B. IA,B is the“set of interpretations”for the formulaA∧ B.

As syntax is defined as the setL of all correct formulae, the semantics is defined as the setS of all possiblesemantic values:

S = IV |V ⊆ Θ.

The “semantic evaluation function” associates each formulaϕ from L to its semantic valuefϕ from S. Ifwe denote by Var(ϕ) the set of propositional variables occuring inϕ, then:

fϕ : IVar(ϕ) → T, F, fϕ(I ) = 〈ϕ〉I ,

where〈ϕ〉I is the“truth value ofϕ under the interpretation I”.

〈ϕ〉I (the truth evaluation of a formulaϕ under the interpretationI ) is defined inductively on the structureof formulae:

〈F〉I = F〈T〉I = T〈v〉I = I (ϑ), if v ∈ Θ

〈¬ϕ〉I = B¬(〈ϕ〉I )〈ϕ ∨ ψ〉I = B∨(〈ϕ〉I , 〈ψ〉I )〈ϕ∧ψ〉I = B∧(〈ϕ〉I , 〈ψ〉I )

. . .

The functionsB¬,B∨,B∧, . . . (boolean evaluation functions) are defined explicitely by truth tables foreach logical connective, and they can be seen as the semantic values of the logical connectives.

T F

F T

B∧ T F

T T F

F F F

B∨ T F

T T T

F T F

B⇒ T F

T T F

F T T

B⇔ T F

T T F

F F T

Table 1.2: The semantics of logical connectives

Example

〈(A∧ (A⇒ B))⇒ B〉I = B⇒(〈(A∧ (A⇒ B))〉I , 〈B〉I

)= B⇒

(B∧(〈A〉I , 〈(A⇒ B)〉I

), 〈B〉I

)= B⇒

(B∧(〈A〉I ,B⇒

(〈A〉I , 〈B〉I

)), 〈B〉I

)

= B⇒

B∧

T, B⇒ (T,F)︸ ︷︷ ︸F

︸ ︷︷ ︸F

,F

= T

Page 6: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 5

Model, validity, satisfiability. If 〈ϕ〉I = T, then we say “I satisfiesϕ” or “ I is a model ofϕ”.

If(for any I , fϕ(I ) = T

), then we say“ ϕ is valid” (otherwise it is“invalid” )

If(for any I , fϕ(I ) = F

), then we say“ ϕ is unsatisfiable”(otherwise it is“satisfiable”)

Example. The formulaA∧¬A is(((((("always false": The correct characterization for this is“unsatisfiable”:for all interpretationsI , fA∧¬A(I ) = F.

The formula (A⇒ (A⇒ B))⇒ B is(((((("always true". Correct is to say that it is“valid” : for all I , 〈. . . 〉I = T.

The following formula is“invalid”, but “satisfiable” : A∧ B (its truth value depends onI ).

Logical consequence. We say“the formulaψ is a logical consequence of the formulaeϕ1, . . . , ϕn” (alsodenoted asϕ1, . . . , ϕn |= ψ), if and only if:for all I, whenever〈ϕ1〉I = . . . = 〈ϕn〉I = T, then also〈ψ〉I = T.

Two Basic Theorems. When working in mathematics, the typical shape of the theorems we want toprove isϕ1, . . . , ϕn |= ψ. The following two theorems show how to reduce such a problem to establishingthe validity, respectively the insatisfiability, of a certain formula. The former is called“proof by refutation”and corresponds in fact to the known proof technique of “proof by contradiction”.

Theorem 1.ϕ1, . . . , ϕn |= ψ if and only if (ϕ1∧ . . .∧ϕn) =⇒ ψ is valid.

Theorem 2.ϕ1, . . . , ϕn |= ψ if and only if ϕ1∧ . . .∧ϕn∧¬ψ is unsatisfiable.

Logical equivalence. We say“ ϕ is equivalent toψ” , (also denoted asϕ ≡ ψ) if and only if ϕ |= ψ andψ |= ϕ.

1.1.2 Interesting equivalences

• Commutativity:

ϕ ∧ ψ ≡ ψ ∧ ϕ(same with∨ )

• Associativity:

ϕ1 ∧ (ϕ2 ∧ ϕ3) ≡ (ϕ1 ∧ ϕ2) ∧ ϕ3

(same with∨ )

• Idempotence:

ϕ ∧ ϕ ≡ ϕ(same with∨ )

This can be extended for more complex expressions, for example:(A∨ ((A∨ B) ∨ (C ∨ B))) ∨C ≡ (A∨ B∨C):

(((ϑ1 ∨ ϑ2) ∨ ϑ3) ∨ ϑ4) ∨ ϑ5 ≡ ϑ1 ∨ ϑ2 ∨ ϑ3 ∨ ϑ4 ∨ ϑ5

this can also be denoted :∨ϑ1, ϑ2, ϑ3, ϑ4, ϑ5

Page 7: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 6

• Properties of negation

¬¬ϕ ≡ ϕ

¬ϕ ∨ ϕ ≡ T

¬ϕ ∧ ϕ ≡ F

¬(ϕ ∨ ψ) ≡ (¬ϕ) ∧ (¬ψ)

¬(ϕ ∧ ψ) ≡ (¬ϕ) ∨ (¬ψ)

• Distributivity

ϕ ∧ (ψ1 ∨ ψ2) ≡ (ϕ ∧ ψ1) ∨ (ϕ ∧ ψ2)

ϕ ∨ (ψ1 ∧ ψ2) ≡ (ϕ ∨ ψ1) ∧ (ϕ ∨ ψ2)

• Elimination of⇒ and⇔

ϕ⇒ ψ ≡ (¬ϕ) ∨ ψ

ϕ⇔ ψ ≡ (ϕ⇒ ψ) ∧ (ψ⇒ ϕ)

≡ (¬ϕ ∨ ψ) ∧ (¬ψ ∨ ϕ)

≡ (ϕ ∧ ψ) ∨ (¬ϕ ∧ ¬ψ)

Example usage of rules:

A∨ B∨ ¬A ≡

(A∨ ¬A) ∨ B ≡

T ∨ B ≡ T

• Properties of truth constants

T ∨ ϕ ≡ T F ∨ ϕ ≡ ϕ

T ∧ ϕ ≡ ϕ F ∧ ϕ ≡ F

¬T ≡ F ¬F ≡ T

T⇒ ϕ ≡ ϕ F⇒ ϕ ≡ T (false implies anything)

(becauseT⇒ ϕ ≡ (¬T) ∨ ϕ ≡ F ∨ ϕ ≡ ϕ) (becauseF⇒ ϕ ≡ (¬F) ∨ ϕ ≡ T ∨ ϕ ≡ T)

ϕ⇒ T ≡ T ϕ⇒ F ≡ ¬ϕ

Exercise: Write the rules for the elimination of the truth constants for⇔ (in analogy toϕ ⇒ T ≡T andϕ⇒ F ≡ ¬ϕ)

Proofs of the equivalences For example, proveT ∨ ϕ ≡ T

By definition:

For anyI : (note that again, this only refers to

the relevant interpretations as explained above)

fT∨ϕ(I ) =? fT(I )

〈T ∨ ϕ〉I =? 〈T〉I

B∨(〈T〉I , 〈ϕ〉I ) =? 〈T〉I

=Yeah! T

Page 8: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 7

B∨ T F

T Either this case:T or this case:TF T F

Proof for¬¬ϕ ≡ ϕ

〈¬¬ϕ〉I =? 〈ϕ〉I

〈¬¬ϕ〉I ≡ B¬(〈¬ϕ〉I

)≡ B¬

(B¬(〈ϕ〉I))≡! 〈ϕ〉I

B¬ (B¬ (c)) ≡! c case

c = T B¬ (B¬ (T)) ≡Yeah! Tc = F B¬ (B¬ (F)) ≡Yeah! F

Another way to prove, is shown here with the example of provingϕ ∧ (ψ1 ∨ ψ2) ≡ (ϕ ∧ ψ1) ∨ (ϕ ∧ ψ2)

〈ϕ〉I 〈ψ1〉I 〈ψ2〉I ψ1 ∨ ψ2 LHS ϕ ∧ ψ1 ϕ ∧ ψ2 RHS

T T T T T T T T

T T F T T T F T

T F T . . . . . . . . . . . . . . .

T F F . . . . . . . . . . . . . . .

F T T . . . . . . . . . . . . . . .

F T F . . . . . . . . . . . . . . .

F F T . . . . . . . . . . . . . . .

F F F . . . . . . . . . . . . . . .

Note: LHS means Left Hand Side, RHS means Right Hand Side

Exercise: Complete this table.

1.1.3 Transformation rules

Equivalences can be used as transformation rules.

Eliminate¬

¬¬ϕ ≡ ϕ¬ϕ ∨ ϕ ≡ T¬ϕ ∧ ϕ ≡ F

Push negation:¬(ϕ ∨ ψ) ≡ (¬ϕ) ∧ (¬ψ)¬(ϕ ∧ ψ) ≡ (¬ϕ) ∨ (¬ψ)

By repeated application of this rule, any formula can be transformed such that the negation sign occursonly before atoms. Atoms and negated atoms are called“literals” . Atoms are calledpositive literalsandnegated atoms are callednegative literals.

Distributivity ϕ ∨ (ψ1 ∧ ψ2)≡

−→(ϕ ∨ ψ1) ∧ (ϕ ∨ ψ2)

Page 9: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 8

Note: Every formula can be transformed to aconjunction of disjunctions of literals!Conjunctive Normal Form (CNF):(. . . ∨ . . . ∨ . . .) ∧ . . . ∧ (. . . ∨ . . . ∨ . . .)

Note: Each of these underlined“disjunction of literals” is called“clause” , so a formula in CNF is aconjunction of clauses.

(A∧ (A⇒ B))⇒ B ≡ (Replace implications...)

¬(A∧ (¬A∨ B)) ∨ B ≡ (Push Negation/"De Morgan"...)

(¬A∨ ¬(¬A∨ B)) ∨ B ≡ (Push Negation ...)

(¬A∨ (¬¬A∧ ¬B)) ∨ B ≡ (Distributivity→ Second solution below)

( (¬A∨ A)︸ ︷︷ ︸T

∧ (¬A∨ ¬B)) ∨ B ≡

(¬A∨ (¬B∨ B)︸ ︷︷ ︸T

) ≡ T

Second solution:

(¬A∨ (¬¬A∧ ¬B)) ∨ B ≡ (Distributivity, other possiblity)

(¬A∨ ((A∨ B) ∧ (¬B∨ B)︸ ︷︷ ︸T

)) ≡

(¬A∨ A)︸ ︷︷ ︸T

∨ B

︸ ︷︷ ︸T

≡ T

Since every formula can be transformed into a CNF formula, it is sufficient to find proof methods for theformulae in CNF.

1.1.4 The Resolution Principle

“Resolution inference rule”:

C1 : L ∨C′1C2 : L ∨C′2

7→ C′1 ∨C′2︸ ︷︷ ︸

"resolvent of theclausesC1,C2"

For example:

A∨ B∨CA∨ B∨ P∨ Q

7→ B∨C ∨ P∨ Q

Page 10: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 9

Correctness of the resolution rule

L ∨C′1, L ∨C′2 |= C′1 ∨C′2

Remark: WhenC′1 is missing, then the resolvent isC′2,whenC′2 is missing, then the resolvent isC′1,when bothC′1 andC′2 are missing, then the resolvent isF.

Proof:

For an arbitrary interpretationI⟨L ∨C′1

⟩I = T =

⟨L ∨C′2

⟩I

By cases

〈L〉I = T :(otherwise

⟨L ∨C′2

⟩I= F) ⟨

C′2⟩

I= T⟨

L⟩

I= T :

(otherwise

⟨L ∨C′1

⟩I= F) ⟨

C′1⟩

I= T

, thus in either case⟨C′1 ∨C′2

⟩I= T

Remark.

(L ∨C1) ∧ (L ∨C2) . C′1 ∨C′2 !

(L ∨C1) ∧ (L ∨C2) ≡ (L ∨C1) ∧ (L ∨C2) ∧ (C′1 ∨C′2)

“resolution principle” : resolution inference rule and resolution method

“resolution method” : apply the resolution inference rule until you reach the empty clause.

Theorem (Completeness of the resolution method).If a set of clauses is unsatisfiable, then there exists a proof by resolution (that is: the empty clause can beobtained by repeated applications of resolution inference rule to the original clauses and to the new ones).

We illustrate the idea of the proof through and example.

Consider the set of clauses:

1. A∨ P

2. B∨ P

3. A∨ B

4. P

We represent all possible interpretations using a so called“semantic tree”, in which every path correspondsto an interpretation:

A

B

P P

B

A

B B

P P P P P P

A

B

P

Figure 1.1: Semantic tree

Page 11: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 10

The path〈A, B,P〉 represents the interpretation

A← TB← FP← F

If the path leading to a node corresponds to an interpretation which falsifies a clause, then we say that“theclause closes the node”. For instance, the clause (3) closes the node with the path〈A, B〉.

A

B

P P

B

A

B B

P P P P P P

A

B

P

x x x x x x

x

Figure 1.2: Semantic tree with closed nodes (1)

If every possible path has a closed node, than we say that“the tree is closed”. Note that a semantictree corresponding to an unsatisfiable formula is allways closed, because a path whose nodes are all opendefines an interpretation which satisfies the formula.

We convene to close every path as early as possible.

In a closed tree, there must be at least one node whose both sons are closed. If allways at least one of thesons is open, then one can construct an open path:

x x x xboth brothers closed only one brother closed

Figure 1.3: Both brothers closed versus one brother closed

When both brothers are closed, let us consider the clausesC1 andC2 which close them, and the atomLwhich corresponds to this branching. Since we close each path as early as possible, the atomL must occurin C2 and the literalL must occur inC1. Moreover, all the other literals present inC1 andC2 must befalsified on the path leading to the father:

Page 12: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 11

x x

L1

Ln

...

L L

C1 C2

C1

false

! "# $L!C !

1

! "# $L!C !

2

Figure 1.4: Consequence if both brothers are closed

Therefore, the clausesC1 andC2 are resolvable overL, and the resulting clauseC1∨C2 falsifies the father ora node above it. By adding this resolvent to the set of clauses, we obtain a formula whose closed semantictree issmallerthen before.

Thus, inductively, the closed tree will be reduced until the root is closed, which means that the empty clausewas produced.

In our example, one may apply this procedure as follows:

(1) A∨ P

(2) B∨ P

(3) A∨ B

(4) P

(5) A from (1) and (4)

(6) B from (2) and (4)

(7) A from (3) and (6)

(8)∨ from (5) and (7)

A A

B B

A

B

x

. . .

x

. . .

. . .

x

s

A A

. . .

x

. . .

x

A

(empty clause)

Figure 1.5: Semantic tree with closed nodes.

Page 13: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 12

In conclusion, if we make all possible resolutions on an unsatisfiable set of clauses, then we will allwaysobtain the empty clause.

1.1.5 The Method of Davis and Putnam

This method shows the unsatisfiability (or alternatively finds satisfying interpretations) of a set of proposi-tional clauses by alternating two types of steps:

• unit propagation,

• split.

Unit propagation is applied when the set of clauses contains a“unit clause” (that is a clause having onlyone literal, sayL). In this caseL is moved into a“list of assignments”and:

• all clauses containingL are removed (they cannot contribute better thanL at obtaining the emptyclause)

• L (the opposite ofL) is removed from all clauses where it occurs (this is just resolution).

By the former one may produce the empty clause, and then the current branch of the proof is closed. Theformula is unsatisfiable if this happens on all branches.

Note that by the former some new unit clauses may be produced. This process is repeated until thereare no unit clauses anymore. If the set of clauses becomes empty, then the formula is satisfiable and theinterpretation is given by the list of assignments which was constructed on the current branch.

Split is applied when there are no more unit clauses. One chooses one of the variables still present in theclause set, sayA, and splits the proof into two branches: one forA and one forA. These are taken as unitclauses and then one may apply unit propagation.

Examples:

This is an unsatisfiable set of clauses. By split onP, one obtains the new setQ,Q on each branch, andthen the empty clause.

initial set

P∨ QP∨ QP∨ QP∨ Q

P

QQ

P

QQ

This is a satisfiable set of clauses. First we apply unit propagation onR (just moveR into the list ofassignments). The by split onP one obtains the new setQ on each branch, and then by unit propagation(just movingQ into the assignment list), one obtains the empty set.

P∨ QP∨ QR

P : Q

P : Q

Page 14: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 1. PROPOSITIONAL LOGIC 13

R← T

T→ P P← T

↓ ↓

T→ Q Q← T

Page 15: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

Chapter 2

First-order Predicate Logic

Syntax Semantics

formula function overinterpretations

Figure 2.1: Syntax and Semantics

2.1 Definition of syntax

Formulae:

• terms

– variables, constants

– function symbols

• quantifiers

• logical connectives

2 Languages

Language of termsLT

Language of formulaeLF

Language of terms

LT

ϑ ∈ Θ, c ∈ C : are termsf ∈ F , t1, . . . , tn : terms, then

f (t1, . . . , tn) is term(these are all !)

14

Page 16: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 15

variables↓

Θ ,

constants↓

C are (infinite) sets of symbols

• F : set of “functional symbols”F =

⋃n∈NFn

– eachFn is infinite

– Fn ∩Fm = ∅ (disjoint)

– f ∈ Fn : “f has arity n”

∗ if n = 0, we don’t write f (), but f , which is a constant

∗ soC = F0

Language of formulae

LF

p ∈P , t1, . . . , tm : terms, thenP (t1, . . . , tm) is formula ("atom")

ϕ, ψ formulae, ϑ ∈ Θ : ∀ϑϕ,∃ϑϕ,¬ϕ, ϕ ∧ ψ, ϕ ∨ ψ,ϕ⇒ ψ, ϕ⇔ ψ are formulae

(these are all !)

• P “predicate symbols”

– P =⋃

m∈NPm, eachPm infinite,

– Pn ∩Pm = ∅ (disjoint)

– p ∈Pm : “p has arity m”

∗ if m= 0, we don’t writeP(), butP

∗ P propositional variable, so propositional logic is a subset of first-order predicate logic

Example

For every two points, there is one and only one line through the two points

∀x∀yP(x) ∧ P(y) ⇒ ∃z! (L(z) ∧ T(z, x, y))

P(x) : "x is point"L(z) : "z is line"T(z, x, y) : "z passes through x and y"

Schemata for “there exists exactly one”:

∃x!P(x) : ∃xP(x) ∧

∀yP(y)⇒ (x = y)︸ ︷︷ ︸more precise:Equal(x, y)

Written without∃!-Usage, and demonstrating terms “scope” and “bound”:

Page 17: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 16

∀x∀y

P(x) ∧ P(y)⇒ ∃z

(L(z) ∧ T(z, x, y)) ∧ ∀z

(L(z) ∧ T(z, x, y))⇒ (t = z)︸ ︷︷ ︸scope of the∀z quantifier

︸ ︷︷ ︸scope of the∃ quantifier,

variablez is bound in this scope

In the previous formula all variables are bound by quantifiers.

In the next formula there is an unbound (free) variable:

∃x x↑

bound

≤ y↑

free↑

whichy ?↑

no meaning is assigned toy

One cannot assign a semantics to this formula. Only the closed formulae (i. e. having no free variables)have semantics.

2.2 Semantics

f∀x∃yx≤y : I↓

interpretations

→ T,F

An interpretation for a formula contains all the elements which are necessary in order to evaluate the truthvalue of the formula: a domain for the variables, a concrete function for each function symbol (constantswill have elements of the domain), and a concrete predicate for each predicate symbol.

I :

"domain". . . D , ∅constant symbol. . . cI ∈ Dfunctional symbol. . .

(arity n)fI : Dn→ D

predicate symbol(arity m)

. . . pI : Dm→ T,F

Example:

∀x∃yx ≤ y

In order to evaluate quantified formulae, since the particular elements of the domain cannot occur in for-mulae, one uses the notion of“truth value under the interpretation and a certain assignment to the freevariables”. Not only that the formulae have truth values, but the terms also have values (under the inter-pretation and a certain assignment).

Page 18: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 17

I :

D = 0,1

≤I :x\y 0 1

0 T T

1 F T

⟨∀x∃yx ≤ y

⟩I= T iff foreachd ∈ D :⟨

∃yx ≤ y⟩Ix←0 ⟨

∃y0 ≤ y⟩

I

⟨∃yx ≤ y

⟩Ix←d

〈x ≤ y〉Ix←0,y←0 ⟨∃y1 ≤ y

⟩I

≤I

(〈x〉Ix←0,y←0 , 〈y〉

Ix←0,y←0

)≤I (0,0) = T

Example: predicate logic formula, interpretation and truth evaluation

∀x (P (x)⇒ Q ( f (x) ,a))

for instanceI :

D = 1,2aI = 1 (∈ D)

fI : D→ D

fI (1) = 1fI (2) = 1

PI : D→ T,F

PI (1) = TPI (2) = F

QI : D2→ T,F

QI 1 2

1 T F

2 F T

〈∀x (P (x)⇒ Q ( f (x) ,a))〉I = T

iff

〈P (x)⇒ Q ( f (x) ,a)〉Ix←d = T (for eachd ∈ D)

So for each element of the domain there is a case:

• Cased = 1:

〈P (x)⇒ Q ( f (x) ,a)〉Ix←1 = B⇒(〈P (x)〉Ix←1 , 〈Q ( f (x) ,a)〉Ix←1

)= B⇒

(PI

(〈x〉Ix←1

),QI

(〈 f (x)〉Ix←1 , 〈a〉

Ix←1

))= B⇒

(PI

(〈x〉Ix←1

),QI

(fI(〈x〉Ix←1

), 〈a〉Ix←1

))= B⇒

(PI (1) ,QI

(fI(〈x〉Ix←1

),aI

))= B⇒ (T,QI ( fI (1) ,1)) = B⇒ (T,QI (1,1))

= B⇒ (T,T) = T

• Cased = 2 :

〈P (x)⇒ Q ( f (x) ,a)〉Ix←2 = . . . = T

Page 19: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 18

2.3 Truth evaluation 〈ϕ〉I

2.3.1 Formula

T,F

P (t1, . . . , tn) 〈P (t1, . . . , tn)〉Iα = PI

(〈t1〉

Iα , . . . , 〈tn〉

)¬ϕ, ϕΩψ

∈ ∧,∨,⇒,⇔

〈ϕΩψ〉Iα = BΩ(〈ϕ〉Iα , 〈ψ〉

)〈¬ϕ〉Iα = B¬

(〈ϕ〉Iα)

∀ϑϕ (ϑ : variable symbol)〈∀ϑϕ〉

Iα = T iff(for eachd ∈ D, 〈ϕ〉Iα∪ϑ←d = T)

(of the interpretationI )

∃ϑϕ (ϑ : variable symbol)〈∃ϑϕ〉

Iα = T iff(for somed ∈ D, 〈ϕ〉Iα∪ϑ←d = T)

(of the interpretationI )

∀xP(x)⇒ ∃yQ(x, y)〈. . . 〉I . . . 〈. . . 〉

Ix←d . . . 〈. . . 〉

Ix←d,y←d

But what if x is already bound:

∀xP(x)⇒ ∃xQ(x, x)〈. . . 〉I . . . 〈. . . 〉

Ix←d . . . 〈. . . 〉

I

x← d, x← d↑

which x ?

”⋃

” : modify the assignment !(replace any otherϑ← . . . !

All variables must be bound.

All free variables are present in the assignmentα

2.3.2 Term

ϑ (∈ variable symbol set)〈ϑ〉Iα = 〈ϑ〉

I...,ϑ←d,... = d

(assume that there is such an assignmentϑ← d)c (∈ constant symbol set) 〈c〉Iα = cI

f (∈ functional symbol set) 〈 f (t1, . . . , tn)〉Iα = fI(〈t1〉

Iα , . . . , 〈tn〉

)

Page 20: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 19

2.3.3 Equivalence

Syntax Semantics

!

!f! = f"

Figure 2.2: Syntax, Semantics and semantical equivalence

Then we can define equivalence of two formulaeϕ andψ as that they’ve got the same semantical function.

Φ |= Ψ semantical logical consequence

♦ : ¬ (∀xϕ) ≡ ∃x (¬ϕ)

¬ (∃xϕ) ≡ ∀x (¬ϕ)

♣ : ∀x (ϕ ∧ ψ) ≡ (∀xϕ) ∧ (∀xψ)

∃x (ϕ ∨ ψ) ≡ (∃xϕ) ∨ (∃xψ)

∀x (ϕ ∨ ψ) ≡ (∀xϕ) ∨ ψ∃x (ϕ ∧ ψ) ≡ (∃xϕ) ∧ ψ

if x<ψ

"does not occur"

Substitution:

∀xϕ ≡ ∀yϕx←y

if y<ϕ

∃xϕ ≡ ∃yϕx←y

We try to prove♦:

For arbitary interpretationI :〈¬∀xϕ〉

I = 〈¬∀xϕ〉I = B¬

(〈∀xϕ〉

I

)= F iff

(〈∀xϕ〉

I = T

)iff

for eachd ∈ D : 〈ϕ〉Ix←d = T

= T iff . . .

(〈¬∃xϕ〉

I = F

)iff for somed ∈ D : 〈ϕ〉Ix←d = T

Page 21: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 20

A formula in “prenex normal form” is of the form:

(∀x∃y∃z∀t . . .

)︸ ︷︷ ︸all quantifiers

ϕ︸︷︷︸quantifier-free formula

The quantifier-free formula part can be transformed into CNF

"prenex formula"(with the quantifier free formula part in) CNF

"prenex normal form"

So, a formula inprenex normal formsomehow looks like:

(∀x∃y∃z∀t . . .

)((· · · ∨ · · · ∨ . . . ) ∧ · · · ∧ (· · · ∨ · · · ∨ . . . ))

2.4 Skolem transformation

A “skolem transformation” is ∃xP(x) P(a)if this is satisfiable→ then → this is sat.

this is sat.← then ← if this is sat.

Assume that we have an interpretationI that satisfies∃xP(x)

I :

DPI : D→ T,Ffor somed ∈ D : PI (d) = T

7→ I ′ :

DPI ′ = PI

aI ′ = dsoPI ′ (aI ) = T

(∃xϕ satisfiable) iff (ϕx←a satisfiable)

and more interesting:

(∃xϕ unsatisfiable) iff (ϕx←a unsatisfiable)

∀x∃yP(x, y)

I ′ . . . (D,PI )for eachd ∈ D

(there isd′ ∈ D,PI (d,d′) = T)

taked′ = fI (d)

←[ ∀xP (x, f (x))

I . . . (D,PI , fI )for eachd ∈ D

PI (d, fI (d)) = T

Note: Homework 5.5 was to show the other direction7→. Hint: Take an interpretation which is sat on theLHS and show that it is sat RHS.

(∀x∃yϕ unsatisfiable

)iff

(∀xϕy← f (x) unsatisfiable

)where f <ϕ

and more generally:(∀x1 . . .∀xn∃yϕ

)

(∀x1 . . .∀xnϕx← f (x1,...,xn)

)

Page 22: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 21

So, byskolem transformation, one can eliminate all the∃-quantifiers.

(∀x∃y∀z∀t∃w

)((· · · ∨ · · · ∨ . . . ) ∧ · · · ∧ (· · · ∨ · · · ∨ . . . ))︸ ︷︷ ︸

CNF↓ "skolem transform"(

∀x1 . . .∀xn

)((· · · ∨ · · · ∨ . . . ) ∧ · · · ∧ (· · · ∨ · · · ∨ . . . ))︸ ︷︷ ︸

CNF

One does not need to write the quantifiers(∀x1 . . .∀xn

)any more ! You simply assume that all are universally

quantified.

2.5 Resolution

“Resolution principle”:L ∨C1

L ∨C2

C1 ∨C2

For example:

∀xP(x)⇒ Q(x)P(a)

Q(a)

P(x) ∨ Q(a)P(a)

Q(a)

If (L1σ = L2σ),L1 ∨C1

L2 ∨C2

C1σ ∨C2σ

For example:

P(x,a) ∨ Q(x)instantiatex← b−−−−−−→

P(b,a) ∨ Q(b)

P(b, y) ∨ R(y)−−−−−−→y← a P(b,a) ∨ R(a)

Q(b) ∨ R(a)

Substitutionσ = x← b, y← a

Correctness:L1 ∨C1, L2 ∨C2 |= C1σ ∨C2σ

(whereL1σ = L2σ)

∀ϑϕ |= ∀ϑ1 . . .∀ϑnϕϑ←t

ϑ1, . . . , ϑn = FreeVars(t)∀x1 . . .∀xn

((L1 ∨C1) ∧

(L2 ∨C2

))⇒ (C1 ∨C2)

l (∀x1 . . .∀xnL1 ∨C1

)(∀x1 . . .∀xnL2 ∨C2

) |=(∀x1 . . .∀xnC1 ∨C2

) Completeness: Ifϕ unsatisfiable, thenϕ `Res (the empty clause)

2.5.1 Resolution principle

Theresolution principle, which is an inference rule:

L1 ∨C1

L2 ∨C2

L1σ = L2σ ` C1σ ∨C2σ

formulae which are not ground are[∀x]−−−→

implicitly universally quantified

P (x, f (a)) ∨ Q(x)P(b, y) ∨ R(y)

Q(b) ∨ R( f (x))︸ ︷︷ ︸"they are ground"

Substitutionσ = x← b, y← f (x)

Page 23: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 22

2.5.2 Resolution method

Theresolution methodis a proof system:

• Correct

• Complete

“Apply the resolution principle until you obtain the empty clause”.

2.5.2.1 Correct

L1σ ∨C1σ

L2σ ∨C2σ

Foralld ∈ D : 〈P(x)〉Ix←d = T

∀xP(x) |= ∀yP ( f (y))

x← f (y)

P (x) ` P ( f (y))

∀xP (x) ∨ Q (x)∀xP (x) ∨ R(x)

|= ∀xQ (x) ∨ R(x)

For anyd ∈ D : 〈Q (x) ∨ R(x)〉Ix←d = T

B∨

(⟨P (x)⟩Ix←d

, 〈Q (x)〉Ix←d

)= B∨

(B∨(〈P (x)〉Ix←d

), 〈Q (x)〉Ix←d

). . .

2.5.2.2 Complete

For doing this, we will introduce a special domain (“Herbrand universe”)

H = a, f (x) , f ( f (x)) , . . . (set of ground terms, which is∞enumerable)

H0 = constants

Hk+1 = Hk ∪ terms obtained by applying all functional symbols to all elements ofHk

H =⋃k∈N

Hk (can be constructed in a systematic way)

I :

H

fI : H → H fI (t) = ” f (” ` t ` ”)” (where ` denotes a concatenation of strings)PI : H → T,F

M = P (a) ,P ( f (a)) ,P ( f ( f (a))) , . . . ("atom set": set of ground atoms, which is∞enumerable)

An interpretationI is a list of ground literals (some are positive, some are not).

Page 24: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 23

One can write all possible interpretations as a tree.

......

......

......

......

P (a)P (a) P (a)

P (f(a))

P (f(f(a)))

¬ ¬

¬¬¬¬

!enumerable

Figure 2.3: ”Semantic tree”

H-satisfiable iff satisfiable

IH ⇐ (over someI/D)

TakeM and evaluating ground termsM =

”P (a) ”↑

PI (aI ) = T

, ”P ( f (a)) ”↑

PI ( fI (aI )) = T

, . . .

So practically it is sufficient so speak about terms ”P (a) ” instead ofPI (aI ) = T

P(a) (1)P (x) ∨ P ( f (x))P ( f ( f (a)))

So we can close the nodes

P (a)P (a)

P (f(f(a)))

¬ ¬

¬¬¬¬

P (f(x))

P (x)

x

x x x x

x

Figure 2.4: Semantic tree with closed nodes

⇒ The semantic tree is closed

Now if it would not be closed, one would have an infinite path somewhere where all clauses evaluate totrue.

Page 25: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 24

Conclusion: If ϕ is unsat, then the semantic tree is closed

AA

A∨ BB∨C

• P(a)

P (x) ∨ P ( f (x)) x← a x← f (a)

• P ( f ( f (a)))• P (a) ∨ P ( f (a))• P ( f (a)) ∨ P ( f ( f (a)))

Herbrand Theorem: If a formula is unsatisfiable, then there exists an unsatisfiable set of ground instancesof the clauses in the formula.

1. This theorem shows the remarkable fact that for proving in first order logic it is enough toreason about ground instances.

2. The theorem also suggests a procedure for proving: we enumerate all possible ground instancesof clauses, and for each new instance we test (by propositional logic!) whether the set is alreadyunsatisfiable.

3. Note that this is not a decision procedure: if the original set of clauses in satisfiable, then thisprocess will never terminate (thus, this is a semi-decision procedure).

4. However, this is the best we can hope for first order predicate logic: one can prove that there isno general decision procedure.

5. This proving procedure is not efficient: resolution is more efficient because it finds (by unifica-tion) the instances which are more likely to lead to contradiction.

The Herbrand theorem is important because it is a first step towards proving the completeness of theresolution method. Namely, since there exists an unsatisfiable set of ground instances of clauses, it follows(using the construction of the semantic tree), that there exists a deduction by resolution of the empty clause,over the ground instances of clauses.

The next step in proving the incompleteness is to show that there is a deduction by resolution of the emptyclause over the original set of clauses. This is done by “lifting” the ground deduction to a non-grounddeduction, using theLifting Lemma. The Lifting Lemma states that every resolvent of two ground instancesof clause is itself an instance of a resolvent of two original instances. Thus, we can replace each grounderesolution step by a resolution step over the non-ground clauses, and this is the “lifting” of the deduction.

The completeness of resolution is in fact equivalent toGödel’s Completeness Theorem, which is of greatimportance for the philosophy of logic and also of computer science.

Since resolution calculus is essentially equivalent to natural deduction calculus (used in Gödel’s theorem),one has the following:

If a formula is unsatisfiable, then one can obtain a contradiction by natural deduction, thusFalseis alogical consequence of it.

(A formula having the latter property is calledinconsistent, and a formulae from which False does notfollow are calledconsistent.)

By contraposition (reversed implication between the negations) one obtains:

If a formula is consistent, than it has a model (that is: an interpretation for which the formula evaluates toTrue).

This is the Gödel’s completeness theorem, which states the remarkable fact that for every noncontradictorytheory in first order predicate logic there exists a domain on which this theory holds.

Page 26: Introduction to Automated Theorem Proving€¦ · Chapter 1 Propositional Logic 1.1 Syntax Propositional logic is a mathematical model of reasoning with elementary statements (or

CHAPTER 2. FIRST-ORDER PREDICATE LOGIC 25

Moreover, the proof is constructive and (similarly to the proof of the Herbrand theorem) it actually exhibitsa concrete domain on which the theory holds: this is the Herbrand universe (that is set of ground terms),together with the functions and the predicates which occur in the theory, thus its construction only needsthe “syntactic material” which is already present in the respective theory.

When we want to solve a problem with the help of the computer, we start from an abstract model of theproblem (that is a logical theory) and we need to create a concrete domain on which the functions andthe predicates of the theory can be implemented. The completeness theorem shows that this is allwayspossible, and also gives us a general method to realize the implementation.