3 Propositional Logic · 3.1 Syntax IDefinition 3.0 An alphabet Σ consists of a finite or...

96
3 Propositional Logic 3.1 Syntax 3.2 Semantics 3.3 Equivalence and Normal Forms 3.4 Proof Procedures 3.5 Properties Propositional Logic (25th October 2007) 1

Transcript of 3 Propositional Logic · 3.1 Syntax IDefinition 3.0 An alphabet Σ consists of a finite or...

3 Propositional Logic

3.1 Syntax

3.2 Semantics

3.3 Equivalence and Normal Forms

3.4 Proof Procedures

3.5 Properties

Propositional Logic (25th October 2007) 1

3.1 Syntax

I Definition 3.0 An alphabet Σ consists of a finite or countably infinite set. Theelements of this set are calles symbols. Without loss of generality (Wlog) weassume that Λ 6∈ Σ.

The set of words (or strings) over Σ is denoted by Σ∗ and is defined as follows:

1. Λ ∈ Σ∗.2. If w ∈ Σ∗ and a ∈ Σ, then aw ∈ Σ∗.3. There are no other words in Σ∗.

Λ is called empty word or empty string.

I Example Let Σ = {1, 2}. We can form the following words:

Λ, 1Λ, 2Λ, 11Λ, 12Λ, 21Λ, 22Λ, 111Λ, . . . .

Propositional Logic (25th October 2007) 2

3.1 Alphabet of Propositional Logic

I Definition 3.1 An alphabet of propositional logic consists of

. a (countably) infinite set R = {p1, p2, . . .} of propositional variables,

. the set {¬/1, ∧/2, ∨/2, →/2, ↔/2} of connectives, and

. the special characters “(” and “)”.

I Indices are sometimes omitted.

I We will occasionally use other letters to denote variables.

I Propositional variables are also called nullary relation symbols.

I Different alphabets of propositional logic differ in R.

Propositional Logic (25th October 2007) 3

Propositional Formulas

I Definition 3.2A (propositional) atomic formula, briefly called atom, is a propositional variable.

I Definition 3.3 The set of propositional formulas is the smallest set L(R) with thefollowing properties:

1. If F is an atomic formula, then F ∈ L(R).2. If F ∈ L(R), then ¬F ∈ L(R).3. If ◦/2 is a binary connective, F, G ∈ L(R), then (F ◦ G) ∈ L(R).

I Does such a smallest set exist?

. There are sets, which satisfy all properties.

. The intersection of such sets satisfies the properties too.

. The smallest set is the intersection of all sets satisfying the properties.

I Notation A (possibly indexed) denotes an atom,F , G, H (possibly indexed) denote propositional formulas.

Propositional Logic (25th October 2007) 4

Structural Induction

I How can we prove properties of sets of formulas?

I Theorem 3.4 (Principle of structural induction)Every propositional formula has a property E, if the following conditions are met:

1. Induction Base: Every atom has property E.2. Induction Steps:

If F has property E, then ¬F has property E as well.If ◦/2 is a binary connective, and F and G have property E,then (F ◦ G) has property E as well.

I Proof Let E be the set of all formulas satisfying E.

. E ⊆ L(R).

. E satisfies the three conditions of definition 3.3.

. Because L(R) is the smallest set satisfying these conditions,L(R) ⊆ E must hold. qed

Propositional Logic (25th October 2007) 5

Structural RecursionI How can we define functions acting on formulas?

I Theorem 3.5 (Principle of structural recursion)Let M be an arbitrary setand let the following functions be given:

. fooR : R → M ,

. foo¬ : M → M ,

. foo◦ : M × M → M for ◦ ∈ {∧, ∨, →, ↔}.

Then there is exactly one function foo : L(R) → M

satisfying the following conditions:

1. Recursion base foo(A) = fooR(A) for all A ∈ R.2. Recursion steps

foo(¬G) = foo¬(foo(G)) for all G ∈ L(R).foo((G1 ◦ G2)) = foo◦(foo(G1), foo(G2)) for all G1, G2 ∈ L(R).

I Proof Exercise

Propositional Logic (25th October 2007) 6

Structural Recursion – Example

I M = N.

I foo1R(A) = 0 for all A ∈ R.

I foo1¬(X) = X for all X ∈ M .

I foo1◦(X, Y ) = X + Y + 1 for all ◦ ∈ {∧, ∨, →, ↔} and all X, Y ∈ M .

I We obtain:

foo1(F ) =

8<:0 if F is an atom,foo1(G) if F is of the form ¬G,foo1(G1) + foo1(G2) + 1 if F is of the form (G1 ◦ G2).

I Often foo1R, foo1¬ and foo1◦ are not explicitely specified.

I foo is a function symbol af a meta language.

Propositional Logic (25th October 2007) 7

Structural Recursion – More Examples

I foo2(F ) =

8<:1 if F is an atom,foo2(G) if F is of the form ¬G,foo2(G1) + foo2(G2) if F is of the form (G1 ◦ G2).

counts the number of occurrences of atoms in F .

I foo3(F ) =

8<:F if F is an atom,¬foo3(G) if F is of the form ¬G,foo3(G1) ◦ foo3(G2) if F is of the form (G1 ◦ G2).

eliminates parentheses in F .

I foo4(F ) = {Λ} ∪

8>><>>:∅ if F is an atom,{1π | π ∈ foo4(G)} if F is of the form ¬G,{1π1 | π1 ∈ foo4(G1)} ∪ {2π2 | π2 ∈ foo4(G2)}

if F is of the form (G1 ◦ G2)

computes the set of positions in F .

Propositional Logic (25th October 2007) 8

Subformulas

I Definition 3.6 Let F be a propositional formula. The set of subformulas of F isthe smallest set of formulas S(F ) satisfying the following conditions:

1. F ∈ S(F ).2. If ¬G ∈ S(F ), then G ∈ S(F ).3. If (G1 ◦ G2) ∈ S(F ), then G1, G2 ∈ S(F ).

I Example

S(¬((p1 → p2) ∨ p1))= {¬((p1 → p2) ∨ p1), ((p1 → p2) ∨ p1), (p1 → p2), p1, p2}.

Propositional Logic (25th October 2007) 9

3.2 Semantics

I What is the meaning of ¬((p1 → p2) ∨ p1)?

I Here: formulas may be true or false binary logic.

Propositional Logic (25th October 2007) 10

3.2.1 The Structure of the Truth Values

I A structure consists of a set of individuals and a set of functions defined on it.

I The set of truth values W is the set {>, ⊥}.

I Unary functions of type W → W:

. Negation ¬∗: ¬∗(>) = ⊥ and ¬∗(⊥) = >.

. Identity.

. Projections onto ⊥ and >.

I Binary functions of type W × W → W:

. Conjunction ∧∗/2.

. Disjunction ∨∗/2.

. Implication →∗ /2.

. NAND ↑ ∗/2.

. NOR ↓∗ /2.

. Equivalence ↔∗ /2. Etc.

Propositional Logic (25th October 2007) 11

The Functions over the Set of Truth Values

∧∗ ∨∗ →∗ ←∗ ↑∗ ↓∗ 6→∗ 6←∗

> > > > > > ⊥ ⊥ ⊥ ⊥> ⊥ ⊥ > ⊥ > > ⊥ > ⊥⊥ > ⊥ > > ⊥ > ⊥ ⊥ >⊥ ⊥ ⊥ ⊥ > > > > ⊥ ⊥

↔∗ 6↔∗

> > > ⊥ > ⊥ > ⊥ > ⊥> ⊥ ⊥ > > ⊥ > ⊥ ⊥ >⊥ > ⊥ > > ⊥ ⊥ > > ⊥⊥ ⊥ > ⊥ > ⊥ ⊥ > ⊥ >

. Here negation, conjunction, disjunction, implication, equivalence.

Propositional Logic (25th October 2007) 12

3.2.2 Interpretations and Models

I Definition 3.7 A (propositional) interpretation I = (W, ·I) consists of the set Wand a mapping ·I : L(R) → W with:

[F ]I =

8<:w ∈ W if F ∈ R,¬∗[G]I if F is of the form ¬G,([G1]I ◦∗ [G2]I) if F is of the form (G1 ◦ G2).

I An interpretation I = (W, ·I) is uniquely definedby specifying how ·I acts on propositional variables.

I Recall that A denotes an atom.

I We will sometimes identify an interpretation I = (W, ·I) with {A | [A]I = >}.

I We often write F I instead of [F ]I.

I I (possibly indexed) denotes an interpretation.

Propositional Logic (25th October 2007) 13

Satisfiability of Formulas

I Definition 3.10 Let F ∈ L(R).

. F is called satisfiableif there is an interpretation I = (W, ·I) with F I = >.

. F is called valid (or F is a tautology)if for all interpretations I = (W, ·I) we have: F I = >.

. F is called falsifiableif there is an interpretation I = (W, ·I) with F I = ⊥.

. F is called unsatisfiableif for all interpretations I = (W, ·I) we have: F I = ⊥.

Propositional Logic (25th October 2007) 14

Models

I Definition 3.11 An interpretation I = (W, ·I) is called model for a propositionalformula F , in symbols I |= F , if F I = >.

I Abbreviations

. If I is not a model for the formula F , i. e. if F I = ⊥, then we write I 6|= F .

. If F is valid, then we write |= F .

Propositional Logic (25th October 2007) 15

Validity and Unsatisfiability

I Theorem 3.12 A propositional formula F is valid (|= F ), iff ¬F is unsatisfiable.

I Proof |= F iff all interpretations are models for F

iff no interpretation is a model for ¬F

iff ¬F is unsatisfiable. qed

Propositional Logic (25th October 2007) 16

Satisfiability of a Set of Formulas

I Definition 3.13 Let G be a set of formulas.

. G is satisfiable,if there is an interpretation mapping each element F ∈ G to >.

. An interpretation I is called model for G, in symbols I |= G,if I is model for all F ∈ G.

Propositional Logic (25th October 2007) 17

Logical Consequence

I Definition 3.14 A propositional formula F is a (propositional) consequence of aset of propositional formulas G, in symbols G |= F , iff for every interpretation I

we have: if I |= G, then I |= F as well.

I Exercises

. Does {p, (p → q)} |= q hold?

. Does {(p ∨ q)} |= q hold?

. Does {(p ∧ ¬p)} |= q hold?

I Theorem 3.15 Let F, F1, . . . , Fn be propositional formulas.{F1, . . . , Fn} |= F holds iff |= ((. . . (F1 ∧ F2) ∧ . . . ∧ Fn) → F ) holds.

I Proof Exercise

Propositional Logic (25th October 2007) 18

Truth Tabling

I How can we compute the value of a formula F

under all possible interpretations?

I Computing a truth table:

1 Let m = |S(F )| be the number of subformulas of F .2 Let n = |{p ∈ R | p ∈ S(F )}|

be the number of propositional variables occurring in F .3 Form a table with 2n rows and m columns,

where the first n columns are marked bythe n propositional variables occurring in F ,the last column is marked by F , andthe remaining columns are marked by the other subformulas of F .

4 Fill in the first n columns with > und ⊥ as follows:In the first column fill in alternating downwards >⊥>⊥ . . .,in the second column >>⊥⊥ . . ., etc.

5 Calculate the values in the remaining columns usingthe known functions on the set of truth values.

Propositional Logic (25th October 2007) 19

Working with Truth Tables

I Let F be a formula and T a corresponding truth table. Then:

. F is satisfiable iff T contains a row with > in the last column.

. F is valid iff all rows in T have > in the last column.

. F is falsifiable iff T contains a row with ⊥ in the final column.

. F is unsatisfiable iff all rows T have ⊥ in the final column.

I We can apply truth tabling to decide whether G |= F holds for finite G Exercise.

I ExerciseWrite a (Prolog) program which generates a truth table for a given formula F .

Propositional Logic (25th October 2007) 20

3.3 Equivalence and Normal Forms

3.3.1 Semantic Equivalence

I Definition 3.16 Two propositional formulas F and G are semantically equivalent,in symbols F ≡ G, if for all interpretations I we have: I |= F iff I |= G.

I Observe ≡ is an equivalence relation:

. ≡ is reflexive: F ≡ F .

. ≡ is symmetric: If F ≡ G, then G ≡ F .

. ≡ is transitive: If F ≡ G and G ≡ H, then F ≡ H.

This follows immediately from Definition 3.16 Exercise.

Propositional Logic (25th October 2007) 21

Well-Known Semantic Equivalences

I Theorem 3.17 The following equivalences hold:

(F ∧ F ) ≡ F

(F ∨ F ) ≡ F idempotency

(F ∧ G) ≡ (G ∧ F )(F ∨ G) ≡ (G ∨ F ) commutativity

((F ∧ G) ∧ H) ≡ (F ∧ (G ∧ H))((F ∨ G) ∨ H) ≡ (F ∨ (G ∨ H)) associativity

((F ∧ G) ∨ F ) ≡ F

((F ∨ G) ∧ F ) ≡ F absorption

(F ∧ (G ∨ H)) ≡ ((F ∧ G) ∨ (F ∧ H))(F ∨ (G ∧ H)) ≡ ((F ∨ G) ∧ (F ∨ H)) distributivity

Propositional Logic (25th October 2007) 22

Theorem 3.17 (continued)

I Theorem 3.17 (continued) The following equivalences hold:

¬¬F ≡ F double negation

¬(F ∧ G) ≡ (¬F ∨ ¬G)¬(F ∨ G) ≡ (¬F ∧ ¬G) de Morgan

(F ∨ G) ≡ F , if F is valid(F ∧ G) ≡ G, if F is valid tautology

(F ∨ G) ≡ G, if F is unsatisfiable(F ∧ G) ≡ F , if F is unsatisfiable unsatisfiability

(F ↔ G) ≡ ((F ∧ G) ∨ (¬G ∧ ¬F )) equivalence

(F → G) ≡ (¬F ∨ G) implication

I Proof Exercise

Propositional Logic (25th October 2007) 23

Positions

I Recall

foo4(F ) = {Λ} ∪

8>><>>:∅ if F is an atom,{1π | π ∈ foo4(G)} if F is of form ¬G,{1π1 | π1 ∈ foo4(G1)} ∪ {2π2 | π2 ∈ foo4(G2)}

if F is of the form (G1 ◦ G2).

I foo4(F ) is the set of positions in a propositional logic formula F .

I Notation We denote this set also with P(F ).

I Positions are words over {1, 2}, where Λ denotes the empty word.

Propositional Logic (25th October 2007) 24

Replacements

I The subformula of F at position π ∈ P(F ),in symbols F dπe, is defined by:

1. F dΛe = F .2. F d1πe = Gdπe, if F is of the form ¬G.3. F diπe = Gidπe, if F is of the form (G1 ◦ G2) and i ∈ {1, 2}.

I The replacement of the subformula of F at position π ∈ P(F ) by H,in symbols F dπ 7→ He, is defined by:

1. F dΛ 7→ He = H,2. F d1π 7→ He = ¬(Gdπ 7→ He), if F is of the form ¬G.3. F d1π 7→ He = (G1dπ 7→ He ◦ G2), if F is otf (G1 ◦ G2).4. F d2π 7→ He = (G1 ◦ G2dπ 7→ He), if F is otf (G1 ◦ G2).

Propositional Logic (25th October 2007) 25

The Replacement Theorem

I Theorem 3.18 (Replacement Theorem)Let F ∈ L(R), π ∈ P(F ), F dπe = G and G ≡ H.Then, F ≡ F dπ 7→ He.

I Proof Structural induction on π.

I Induction basis Let π = Λ.

. F = F dΛe = G ≡ H = F dΛ 7→ He.√

I Induction hypothesis (IH) The theorem holds for π′.

Propositional Logic (25th October 2007) 26

Proof Replacement Theorem (Continuation)

I Induction step Let π = iπ′. We distinguish two cases:

i = 1 π = 1π′ ∈ P(F ), hence F must be otf ¬F ′ or (G1 ◦ G2).

¬F ′ F d1π′ 7→ He = (¬F ′)d1π′ 7→ He = ¬(F ′dπ′ 7→ He).From IH we conclude: F ′ ≡ F ′dπ′ 7→ HeHence, for all interpretations I we find:

[F ]I = [¬F ′]I Assumption= ¬∗[F ′]I Def I

= ¬∗[F ′dπ′ 7→ He]I IH and Def ≡= [¬(F ′dπ′ 7→ He)]I Def I

= [(¬F ′)d1π′ 7→ He]I Def replacement= [F d1π′ 7→ He]I Assumption

Hence, F ≡ F d1π′ 7→ He √

(G1 ◦ G2) analogously

i = 2 analogously qed

Propositional Logic (25th October 2007) 27

Agreement

I If π 6∈ P(F ) then F dπ 7→ He := F .

I Let F dπe = G.If it is obvious from the context which subformula G is to be replaced,then we write F dG 7→ He instead of F dπ 7→ He.

I Theorem 3.18 allows to replace all occurrences of the connectives ↔ and →.

. Wlog we consider only formulas over R ∪ {¬, ∧, ∨, (, )}.

Propositional Logic (25th October 2007) 28

3.3.2 Negation Normal Form

I Definition 3.19 A propositional formula F is in negation normal form if all negationsigns ¬ occurring in F appear directly in front of propositional variables.

I Proposition 3.20 There is an algorithm which transforms any formula into asemantically equivalent formula in negation normal form.

I Algorithm Given F . While F is not in negation normal form do:

. Select a subformula of F having the form ¬G with G 6∈ R.

. If ¬G = ¬¬H, then replace ¬¬H by H.

. If ¬G = ¬(G1 ∧ G2), then replace ¬(G1 ∧ G2) by (¬G1 ∨ ¬G2).

. If ¬G = ¬(G1 ∨ G2), then replace ¬(G1 ∨ G2) by (¬G1 ∧ ¬G2).

Propositional Logic (25th October 2007) 29

The Rules of the Algorithm

I The rules will be abbreviated by:

¬¬H

H

¬(G1 ∧ G2)(¬G1 ∨ ¬G2)

¬(G1 ∨ G2)(¬G1 ∧ ¬G2)

I The algorithm is (don’t care) non-deterministic!

I Example

¬(r ∨ ¬(¬p ∧ q)) ≡ (¬r ∧ ¬¬(¬p ∧ q)) de Morgan≡ (¬r ∧ (¬p ∧ q)) double negation

Propositional Logic (25th October 2007) 30

3.3.3 Clause Form

I Definition 3.21A literal is a propositional variable, or a negated propositional variable.

I Notation

. L (possible indexed) denotes a literal.

. Generalized disjunction

[F1, . . . , Fn] = (. . . ((F1 ∨ F2) ∨ F3) ∨ . . . ∨ Fn)

. Generalized conjunction

〈F1, . . . , Fn〉 = (. . . ((F1 ∧ F2) ∧ F3) ∧ . . . ∧ Fn)

. Observe [F ] = F and 〈F 〉 = F . Hence, [F ] ≡ F and 〈F 〉 ≡ F .

. Empty generalized disjunction: [ ] with [ ]I = ⊥ for all I.

. Empty generalized conjunction: 〈〉 with 〈〉I = > for all I.

. Observe (G ∨ [ ]) ≡ G and (G ∧ 〈〉) ≡ G.

Propositional Logic (25th October 2007) 31

Clauses

I Definition 3.22

. A clause is a generalized disjunction [L1, . . . , Ln], n ≥ 0,where every Li, 1 ≤ i ≤ n, is a literal.

. A dual clause is a generalized conjunction 〈L1, . . . , Ln〉, n ≥ 0,where every Li, 1 ≤ i ≤ n, is a literal.

. A formula is in conjunctive normal form, or clause form, iff it is of the form〈C1, . . . , Cm〉, m ≥ 0, and if every Cj, 1 ≤ j ≤ m, is a clause.

. A formula is in disjunctive normal form, or dual clause form, iff it is of theform [C1, . . . , Cm], m ≥ 0, and if every Cj, 1 ≤ j ≤ m, is a dual clause.

I Notation C (possibly indexed) denotes a clause.

Propositional Logic (25th October 2007) 32

An Observation

I Let F be a formula in clause form. The following holds:

. F is unsatisfiable if a clause occurring in F is unsatisfiable.

. A clause is unsatisfiable iff it is of the form [ ].

Propositional Logic (25th October 2007) 33

Transformation into Clause Form

I Theorem 3.23

1 There is an algorithm which transforms any formula into a semanticallyequivalent formula in clause form.

2 There is an algorithm which transforms any formula into a semanticallyequivalent formula in dual clause form.

I Proof of 1

. We have to specify the algorithm.

. We have to show that the algorithm is correct or sound,i.e., if it outputs G given F ,then G must be in clause form and F ≡ G must hold.

. We have to show that the algorithm terminates,i.e., it stops in finite time given F .

Propositional Logic (25th October 2007) 34

An Algorithm for the Transformation into Clause Form

I Input: A propositional formula F .Output: A formula, which is in conjunctive normal form and is equivalent to F .G := 〈[F ]〉. (G is a conjunction of disjunctions.)While G is not in conjunctive normal form do:

Select a non-clausal element H from G.Select a non-literal element K from H.Apply the rule among the following ones which is applicable.

¬¬D

D

(D1 ∧ D2)D1 | D2

¬(D1 ∧ D2)¬D1, ¬D2

(D1 ∨ D2)D1, D2

¬(D1 ∨ D2)¬D1 | ¬D2

I A rule DD′ is applicable to K if K is of the form D.

If applied, then K is replaced by D′.

I A rule DD1|D2

is applicable to K if K is of the form D.If applied, H is replaced by two disjunctions:The first one is obtained from H by replacing the occurrence of D by D1.The second one is obtained from H by replacing the occurrence of D by D2.

Propositional Logic (25th October 2007) 35

An Example and a Lemma

I Example〈[¬(p ∨ (¬(p ∧ q) ∧ ¬r))]〉〈[¬p], [¬(¬(p ∧ q) ∧ ¬r)]〉〈[¬p], [¬¬(p ∧ q), ¬¬r]〉

〈[¬p], [(p ∧ q), ¬¬r]〉〈[¬p], [(p ∧ q), r]〉

〈[¬p], [p, r], [q, r]〉

I Lemma 3.24 If a propositional formula G is a conjunction of disjunctions andG′ is obtained from G by applying one of the rules of the algorithm,then G′ is a conjunction of disjunctions and G ≡ G′.

I Proof Exercise.

Propositional Logic (25th October 2007) 36

Induction Principle for While-Loops

I A loop invariant for a while-loop W is a statement E having the following property:If E holds, then E still holds after one execution of the body of W .

I Theorem 3.25 (Induction Principle for While-Loops)If a statement E holds before entering a loop W , and is a loop invariant for W ,then E holds after termination of W as well (if W terminates).

I Proof Literature.

Propositional Logic (25th October 2007) 37

Soundness of the Algorithm

I Let F be the given propositional formula and let E be the statement:G ist a conjunction of disjunctions and F ≡ G holds.

. Initially G is defined to be 〈[F ]〉.

. Because F ≡ 〈[F ]〉 holds, E holds before entering the while-loop.

. From Lemma 3.24 we learn that E is a loop invariant for the while-loop.

. Hence, by Theorem 3.25 E holds when the loop has terminated.

. The loop terminates only when G is in conjunctive normal form. The algorithm is sound!

Propositional Logic (25th October 2007) 38

Termination of the Algorithm

I When does a non-deterministic algorithm terminate?

. Weak TerminationThere is at least one way to execute the algorithm such that it terminates.

. Strong Termination The algorithm terminates independently ofwhich choice we make in the non-deterministic situations.

I Definition 3.26 The function r , called rank of a propositional formula, is definedover L(R) as follows:

r(H) =

8>><>>:0 if H is a literal,r(F ) + 1 if H is of the form ¬¬F ,r(F ) + r(G) + 1 if H is of the form (F ∧ G) or (F ∨ G),r(¬F ) + r(¬G) + 1 if H is of the form ¬(F ∧ G) or ¬(F ∨ G).

Propositional Logic (25th October 2007) 39

Multisets

I A multiset is comparable to a set,but the individual elements may occur multiple times in it.

I Here multisets of natural numbers.

. {̇1, 1, 2, 2, 2, 3}̇.

. M1 � M2 holds iff M2 is obtained from M1 by deleting a number n fromM1 and replacing it by finitely many numbers which are all less than n.

. {̇1, 1, 2, 2, 2, 3}̇ � {̇1, 1, 1, 1, 2, 2, 2, 2}̇.

. Observation there cannot be infinitely long sequences (Mi | i ≥ 0) offinite multisets of natural numbers such that M0 � M1 � . . ..Proof see Dershowitz, Manna: Proving Termination with Multiset Orderings,CACM 22, 465-475 (1979).

Propositional Logic (25th October 2007) 40

Proof of TerminationI Let G = 〈[H11, . . . , H1,n1], . . . , [Hm1, . . . , Hmnm]〉. We define:

f(G) = {̇n1Xj=1

r(H1j), . . . ,

nmXj=1

r(Hmj)}̇

I Observation With every execution of the while-loop, the associated multisetsbecome smaller with respect to �/2 (Proof Exercise) Termination. qed

I Example〈[¬(p ∨ (¬(p ∧ q) ∧ ¬r))]〉 {̇5}̇〈[¬p], [¬(¬(p ∧ q) ∧ ¬r)]〉 {̇0, 4}̇〈[¬p], [¬¬(p ∧ q), ¬¬r]〉 {̇0, 3}̇〈[¬p], [(p ∧ q), ¬¬r]〉 {̇0, 2}̇〈[¬p], [(p ∧ q), r]〉 {̇0, 1}̇〈[¬p], [p, r], [q, r]〉 {̇0, 0, 0}̇

I Observation If G is in clause form, then f(G) = {̇0, . . . , 0}̇ andthe number of clauses occurring in G is equal tothe number of occurrences of 0 in f(G).

Propositional Logic (25th October 2007) 41

3.4 Proof Methods

I {F1, . . . , Fn} |= F

iff (〈F1, . . . , Fn〉 → F ) is valid

iff ¬(〈F1, . . . , Fn〉 → F ) is unsatisfiable

iff 〈F1, . . . , Fn, ¬F 〉 is unsatisfiable.

I Truth tabling

I Resolution

I Semantic tableaus

I Calculus of natural deduction

I Sequent calculus

I Connection method

I Hilbert systems

Propositional Logic (25th October 2007) 42

3.4.1 Resolution

I Resolution is a method to show unsatisfiability of formulas.

I Here: Wlog we assume that formulas are in clause form.

I A formula in clause form in unsatisfiable if

. it contains the empty clause, or

. it can be transformed into a semantically equivalent formula which containsthe empty clause.

I Resolution is search for the empty clause using an appropriate inference rule.

Propositional Logic (25th October 2007) 43

Example

I Some FactsK1 If it is hot and humid, then it will rain.K2 If it is humid, then it is hot.K3 It is humid now.

I Question

K4 Will it rain?

I Introducing propositional variablesp it is hotq it is humidr it will rain

I FormalizationF1 ((p ∧ q) → r)F2 (q → p)F3 q

F4 r

Propositional Logic (25th October 2007) 44

Example (continued)

{((p ∧ q) → r), (q → p), q} |= r

iff(〈((p ∧ q) → r), (q → p), q〉 → r) is valid

iff¬(〈((p ∧ q) → r), (q → p), q〉 → r) is unsatisfiable

iff〈((p ∧ q) → r), (q → p), q, ¬r〉 is unsatisfiable

iff〈[¬p, ¬q, r], [¬q, p], [q], [¬r]〉 is unsatisfiable

Propositional Logic (25th October 2007) 45

How to Show Unsatisfiability?

I Recall〈[¬p, ¬q, r], [¬q, p], [q], [¬r]〉

I Observation{[¬p, ¬q, r], [q]} |= [¬p, r]

I Hence

〈[¬p, ¬q, r], [¬q, p], [q], [¬r]〉 ≡ 〈[¬p, ¬q, r], [¬q, p], [q], [¬r], [¬p, r]〉

Propositional Logic (25th October 2007) 46

Resolution Rule

I Definition 3.27 Let C1 be a clause where the atom A occurs,and C2 a clause where the negated atom ¬A occurs.Let C be the result of performing the following steps:

1. Remove all occurrences of A from C1.2. Remove all occurrences of ¬A from C2.3. Combine the clauses obtained in this way disjunctively.

C was generated applying the (propositional) resolution rule to C1 and C2,where A is the literal that was resolved upon.We also call C the resolvent of C1 and C2 wrt A.

I C may be the resolvent of C1 and C1.

Propositional Logic (25th October 2007) 47

Derivations and Refutations

I Definition 3.28 Let F = 〈C1, . . . , Cn〉 be a formula in clause form.

1. The sequence (Ci | 1 ≤ i ≤ n) is a resolution derivation for F .2. If (Ci | 1 ≤ i ≤ m) is a resolution derivation for F , and Cm+1 is obtained

by applying the resolution rule to two elements from (Ci | 1 ≤ i ≤ m),then (Ci | 1 ≤ i ≤ m + 1) is a resolution derivation for F .

3. A resolution derivation for F which contains the empty clause [ ] is calledresolution refutation for F .

I F may contain [ ].

I It suffices to consider refutations in which [ ] occurs once.

I We may assume that [ ] is the last clause in a refutation.

Propositional Logic (25th October 2007) 48

Example (continued)

1 [¬p, ¬q, r]2 [¬q, p]3 [q]4 [¬r]5 [¬q, ¬q, r] res(1, 2)6 [r] res(3, 5)7 [ ] res(4, 6)

Propositional Logic (25th October 2007) 49

Resolution Proofs

I Definition 3.29 Let F be a propositional formula,and G a formula in clause form equivalent to ¬F .

. A propositional resolution proof for F is a resolution refutation for G.

. F is called theorem of the resolution calculus,if there is a resolution proof for F .

. We denote by `r F , that F has a resolution proof.

I Requirements

. Soundness If `r F , then |= F .

. Completeness If |= F , then `r F .

I Observation

. Let F be a formula with n propositional variables.

. (F ∧ (p ∧ ¬p)) is unsatisfiable.

. The proof consists of a single resolution step!

Propositional Logic (25th October 2007) 50

3.4.4 Further Proof Methods and Calculi

I Definition 3.35 A calculus consists of

. an alphabet,

. a language,

. a set of axioms, i. e., a set of formulas of the language, and

. a set of inference rules defining the provability relation.

I Definition 3.36 Let L be a logic and C a calculus, both defined over the samealphabet and the same language. Let |= be the logical consequence relation of Land ` the provability relation of C.

. C is sound wrt L, if for every formula F of the language we find:if ` F holds then so does |= F.

. C is complete wrt L, if for every formula F of the language we find:if |= F holds then so does ` F.

Propositional Logic (25th October 2007) 51

A Characterization of Calculi

I Definition 3.37 A calculus is

. positive, if its axioms are valid;

. negative, if its axioms are unsatisfiable;

. generating, if it operates by proving a formula starting out from the axioms;

. analyzing, if it operates by reducing the formula to be proved to the axioms.

Propositional Logic (25th October 2007) 52

Additional Calculi and Methods

I Calculi

. Semantic Tableaus

. Hilbert Systems

. Calculus of Natural Deduction

. Sequent Calculus

. Davis-Putman-Logeman-Loveland (DPLL) Procedure

. Connection Method

I Model Generation

. Greedy Satisfiability Testing

. Binary Decision Diagrams

Propositional Logic (25th October 2007) 53

Natural Deduction

I Gentzen 1935: How to represent logical reasoning in mathematics?

. Calculus of natural deduction.

I It’s alphabet is the alphabet of propositional logic.

I Remember [ ] denotes some unsatisfiable formula.

I It’s language is the language of propositional logic.

Propositional Logic (25th October 2007) 54

An Introductory Example

I Suppose we want to show the validity of

((p ∨ (q ∧ r)) → ((p ∨ q) ∧ (p ∨ r))).

I A proof could look like the following:

Assume that (p ∨ (q ∧ r)) holds. We distinguish two cases:(i) Assume that p holds.

Hence, (p ∨ q) must hold.(ii) Assume that (q ∧ r) holds.

Hence, q and, consequently, (p ∨ q) must hold.Thus, (p ∨ q) must hold in any case. (1)Likewise, we conclude that (p ∨ r) must hold. (2)From (1) and (2) we conclude that ((p ∨ q) ∧ (p ∨ r)) holds.

We can now cancel the assumption and, thus, obtaina proof of ((p ∨ (q ∧ r)) → ((p ∨ q) ∧ (p ∨ r))).

Propositional Logic (25th October 2007) 55

Inference Rules – Example

I Elimination of the implication

G (G → F )(→E)

F

I Schema which needs to be instantiated, e.g.,

(p ∧ q) ((p ∧ q) → (q ∧ p))(→E)

(q ∧ p)

Propositional Logic (25th October 2007) 56

Derivations – Some Notation

I Derivations have the form of trees, where the nodes are labeled by formulas.

I Derivations will be denoted by5

I A derivation where the root is labeled by F is denoted by

5F

This will be called a derivation of F .

I A formula labeling a leaf node in a derivation is called hypothesis or assumption.

I If we want to single out a hypothesis G in a derivation of F , then we will write

G

5F

This will be called a derivation of F from G.

Propositional Logic (25th October 2007) 57

Derivations – More Notation

I Some inference rule will cancel hypotheses.

I If a hypothesis has been cancelled, then this will be denotedby marking the hypothesis with b c.

I The hypotheses cancelled by the application a of a rule as well as a itselfwill be marked by a unique index.

Propositional Logic (25th October 2007) 58

Natural Deduction - Inference Rules

I Negation

[ ](f)

G

b¬F c5[ ]

(raa)F

bF c5[ ]

(¬I)¬F

F ¬F(¬E)

[ ]

I Conjunction

F G(∧I)

(F ∧ G)

(F ∧ G)(∧E)

F

(F ∧ G)(∧E)

G

I Disjunction

F(∨I)

(F ∨ G)

G(∨I)

(F ∨ G)(F ∨ G)

bF c5H

bGc5H

(∨E)H

Propositional Logic (25th October 2007) 59

Natural Deduction – Inference Rules (Continued)

I Implication

bGc5F

(→I)(G → F )

b¬F c5

¬G(→I)

(G → F )

G (G → F )(→E)

F

I Equivalence

bGc5F

bF c5G

(↔I)(G ↔ F )

G (G ↔ F )(↔E)

F

F (G ↔ F )(↔E)

G

Propositional Logic (25th October 2007) 60

Derivations (1)

I The set of derivations in the calculus of natural deductionis the smallest set X with the following properties

1 L(R) ⊆ X .2 If

5H1

is a derivation in X andH1

H2

is the instance of a rule r ∈ {(f), (∧E), (∨I)}, then

5H1 rH2

is a derivation in X.

Propositional Logic (25th October 2007) 61

Derivations (2)3 If

H1

5H2

is a derivation in X , j is a new index, and

bH1c5H2

H3

is an instance of a rule r ∈ {(raa), (¬I), (→I)}, then

bH1cj

5H2

rj

H3

is a derivation in X .The hypothesis H1 was cancelled by the application of the rule.

Propositional Logic (25th October 2007) 62

Derivations (3)

4 If51 52

H1 , H2

are derivations in X and if51

H1

52

H2

H3

is an instance of a rule r ∈ {(¬E), (→E), (↔E)}, then

51

H1

52

H2 rH3

is a derivation in X .

Propositional Logic (25th October 2007) 63

Derivations (4)

5 IfF G

51 52 53

(F ∨ G) , H , H

are derivations in X and j is a new index, then

51

(F ∨ G)

bF cj

52

H

bGcj

53

H(∨E)j

H

is a derivation in X.The hyotheses F and G are cancelled by the application of (∨E).

Propositional Logic (25th October 2007) 64

Derivations (5)

6 IfG F

51 52

F , G

are derivations in X and j is a new index, then

bGcj

51

F

bF cj

52

G(↔ I)j

(G ↔ F )

is a derivation in X .The hypotheses G and F are cancelled by the application of (↔ I).

Propositional Logic (25th October 2007) 65

Proofs

I An element of X is called derivation of F in the calculus of natural deductionif in its tree representation the root node is labeled by F .

I A proof of F in the calculus of natural deduction is a derivation of F

in the calculus of natural deduction, where each hypothesis is cancelled.This will be denoted by `n F .

I A Simple Example A proof of (p → p)

bpc1

(→ I)1

(p → p)

Propositional Logic (25th October 2007) 66

The Introductory Example Revisited

b(p ∨ (q ∧ r))c1

bpc2

(∨I)

(p ∨ q)

b(q ∧ r)c2

(∧E)

q

(∨I)

(p ∨ q)

(∨E)2

(p ∨ q)

b(p ∨ (q ∧ r))c1

bpc3

(∨I)

(p ∨ r)

b(q ∧ r)c3

(∧E)

r

(∨I)

(p ∨ r)

(∨E)3

(p ∨ r)

(∧I)

((p ∨ q) ∧ (p ∨ r))

(→I)1

((p ∨ (q ∧ r)) → ((p ∨ q) ∧ (p ∨ r)))

. Please compare this to the informal proof given at the beginning.

Propositional Logic (25th October 2007) 67

Lemmas (1)

I Subderivations may occur over and over again, e.g.,

¬¬F b¬F c1

(¬E)[ ]

(raa)1

F

I Idea Generate such derivations once and for all,specify corresponding inference rules called lemmas,and apply the lemmas in addition to the usual inference rules.

I In the example we obtain¬¬F

(l1)F

Propositional Logic (25th October 2007) 68

Lemmas (2)

I The lemma

¬(F ∧ G) F(l2)

¬G

I and its derivation

¬(F ∧ G)

F bGc1

(∧I)(F ∧ G)

(¬E)[ ]

(¬I)1

¬G

Propositional Logic (25th October 2007) 69

Lemmas (3)

I The lemma

¬(F ∧ G) G(l3)

¬F

I and its derivation

¬(F ∧ G)

bF c1G

(∧I)(F ∧ G)

(¬E)[ ]

(¬I)1

¬F

Propositional Logic (25th October 2007) 70

Lemmas (4)

I The lemma

¬(F ∨ G)(l4)

(¬F ∧ ¬G)

I and its derivation

¬(F ∨ G)

bF c1

(∨I)(F ∨ G)

(¬E)[ ]

(¬I)1

¬F

¬(F ∨ G)

bGc2

(∨I)(F ∨ G)

(¬E)[ ]

(¬I)2

¬G(∧I)

(¬F ∧ ¬G)

Propositional Logic (25th October 2007) 71

Another Example Demonstrating the Use of Lemmas

I A proof of (p ∨ ¬p)

b¬(p ∨ ¬p)c1

(l4)(¬p ∧ ¬¬p)

(∧E)¬¬p

(l1)p

b¬(p ∨ ¬p)c1

(l4)(¬p ∧ ¬¬p)

(∧E)¬p

(¬E)[ ]

(raa)1

(p ∨ ¬p)

Propositional Logic (25th October 2007) 72

Some Remarks on Natural Deduction

I Lemmas shorten proofs, but enlarge the search space.

I The calculus of natural deduction is sound and complete.

I Human readable proofs versus machine generated proofs.

I Sequent calculus.

I Proof theory.

Propositional Logic (25th October 2007) 73

Sequent Calculus

I A sequent is an expression of the form F ` G,where F and G are multisets of formulas.

I Notation We use the following abbreviations:

{̇F1, . . . , Fn}̇ F1, . . . , Fn.F∪̇{̇G}̇ F, G.

I The inference rules are of the form

S1 . . . Sn

rS

or

rS

Propositional Logic (25th October 2007) 74

Sequent Calculus: Axiom, Cut and Structural Rules

Axiom Cut

axH, F ` G, H

F ` G, H H, F ` Gcut

F ` G

Structural rules

H, H, F ` Gcl

H, F ` G

F ` G, H, Hcr

F ` G, H

Propositional Logic (25th October 2007) 75

Sequent Calculus: Logical Rules

Rules for the left hand side Rules for the right hand side

F ` G, H1 H2, F ` G→ l

(H1 → H2), F ` G

H1, F ` G, H2→ r

F ` G, (H1 → H2)

H1, H2, F ` G∧l

(H1 ∧ H2), F ` G

F ` G, H1 F ` G, H2∧r

F ` G, (H1 ∧ H2)

H1, F ` G H2, F ` G∨l

(H1 ∨ H2), F ` G

F ` G, H1, H2∨r

F ` G, (H1 ∨ H2)

F ` G, H¬l

¬H, F ` G

H, F ` G¬r

F ` G, ¬H

Propositional Logic (25th October 2007) 76

Sequent Calculus: Soundness and Completeness

I A proof of the sequent S in the sequent calculus is defined as follows:

. An axiom of the form rS

is a proof of S.

. If T1, . . . , Tn are proofs of S1, . . . , Sn respectively and the sequent

calculus contains a rule of the formS1 . . . Sn

rS

, thenT1 . . . Tn

rS

is a proof

of S.

I The propositional sequent calculus is sound and complete.

I Subformula property: all formulas occurring in the condition of a ruleoccur as subformulas in the conclusion of the rule.

. Only the cut rule violates this property.

. Gentzen’s “Hauptsatz”: Cuts can be removed in sequent calculus proofs.

Propositional Logic (25th October 2007) 77

3.5 Properties

I Compactness Theorem

I Soundness and Completeness Theorems

Propositional Logic (25th October 2007) 78

3.5.1 Compactness Theorem – Introduction

I How can we decide whether a possibly infinite set of formulas is satisfiable?

I Idea We test all finite subsets.

I Remember ≡ is an equivalence relation on L(R).

I Let L(R, n) ⊆ L(R) be the set of formulas in which only the variablesp1, . . . , pn occur.

I There are 2n different interpretations for L(R, n).

I How many different equivalence classes are defined by ≡ on L(R, n)?

. 22n.

Propositional Logic (25th October 2007) 79

Compactness Theorem

I Theorem 3.39 (Compactness Theorem)A set F of propositional formulas is satisfiableiff every finite subset G ⊆ F is satisfiable.

I Proof Let F be a (possibly infinite) set of formulas. We have to show:

(a) If F is satisfiable, so is each finite G ⊆ F .(b) If each G ⊆ F is satisfiable, so is F .

. (a) follows immediately from the definition of satisfiability for sets.

. To show (b) we have to prove the existence of a model for F starting fromthe models for each finite G ⊆ F .

Propositional Logic (25th October 2007) 80

Proof of Part (b) of the Compactness Theorem

I Suppose, each finite G ⊆ F is satisfiable.

I Let Gn = F ∩ L(R, n).

I There are at most k ≤ 22ndifferent equivalence classes on Gn defined by ≡.

I Let G1, . . . , Gk be representatives of these equivalence classes.

I Hence, for each G ∈ Gn there is an i, 1 ≤ i ≤ k, with G ≡ Gi.

I Hence, each model for {G1, . . . , Gk} is also a model for Gn.

I Because {G1, . . . , Gk} is a finite subset of F , it has a model.

I Let In be this model.

I Because G1 ⊆ G2 ⊆ . . . ⊆ Gn, In is also a model for all Gj, 1 ≤ j ≤ n.

Propositional Logic (25th October 2007) 81

Proof of Part (b) of the Compactness Theorem (continued)

I We construct a model I for F as follows:Set I := ∅, K0 := N and n = 1.Do the following:

If there are infinitely many j ∈ Kn−1 with [pn]Ij = > , then setI := I ∪ {pn} and Kn := Kn−1 \ {j | [pn]Ij = ⊥}, (>)

else setKn := Kn−1 \ {j | [pn]Ij = >}. (⊥)

Set n := n + 1.Goto “Do the following”.

I I is an interpretation.

I By induction the following proposition E(n) can be proven:

Kn contains infinitely many elements andfor all m ∈ Kn with m > n we find: [pi]Im = [pi]I for all 1 ≤ i ≤ n.

Proof Exercise.

Propositional Logic (25th October 2007) 82

Proof of Part (b) of the Compactness Theorem (continued)

I To show: I is a model for F .

I Let F be an arbitrary but fixed element of F .

I There are at most finitely many propositional variables occurring in F .

I Let pn be the variable with the highest index.

I Then, F ∈ Gn ⊆ Gn+1 ⊆ . . .

and each interpretation In, In+1, . . . is a model for F .

I Because of E(n) we find:

. Kn contains infinitely many elements.

. For all m ∈ K with m > n we find: [pi]Im = [pi]I for all 1 ≤ i ≤ n.

I Select m ∈ Kn with m > n.

I Because Im is a model for F and F contains only the variables p1, . . . , pn,I must be a model for F as well.

I Because F is an arbitrary element from F , I must also be a model for F . qed

Propositional Logic (25th October 2007) 83

Implications of the Compactness Theorem

I The proof is not constructive.

I We may negate both sides of the compactness theorem.

I Corollary 3.40 A set of propositional formulas is unsatisfiableiff one of its finite subsets is unsatisfiable.

I Procedure to prove unsatisfiability of F :

. We generate all finite subsets of F in a systematic wayand test them for unsatisfiability.

Propositional Logic (25th October 2007) 84

3.5.2 Soundness and Completeness Theorems

I Lemma 3.41 (Propositional Resolution Lemma) Let F = 〈C1, . . . , Cn〉 be apropositional formula in clause form with the clauses Ci, 1 ≤ i ≤ n, and letC be a resolvent of two clauses from F . Then F ≡ (F ∧ C) holds.

I Proof To show I |= (F ∧ C) iff I |= F .⇒ immediate.⇐ Suppose I |= F . Let C be the resolvent of C1 and C2 wrt A.

. Let C′1 = C1 “without” A and C′

2 = C2 “without” ¬A.. Then C = (C′

1 ∨ C′2).

. Case 1 I |= A.

Then, I 6|= ¬A.

Because I |= C2 we conclude I |= C′2.

Hence, I |= C.

. Case 2 I 6|= A.

Because I |= C1 we find I |= C′1.

Hence I |= C. qed

Propositional Logic (25th October 2007) 85

An Implication of the Resolution Lemma

I Corollary 3.41(a) Let F = 〈C1, . . . , Cn〉 be a propositional logic formulain clause form with clauses Ci, 1 ≤ i ≤ n, andlet D1, . . . , Dm be the computed resolvents in a resolution derivation from F .Then, F ≡ 〈F, D1, . . . , Dn〉.

I Proof Induction over n Exercise.

Propositional Logic (25th October 2007) 86

Resolution Method

I Theorem 3.42 (Soundness and Completeness of the Prop. Resolution Method)Let F be a propositional formula. |= F iff `r F .

I Proof Soundness To show If `r F , then |= F .

. Suppose `r F .

. By Definition 3.29 we find a resolution refutation for ¬F ,i.e. by Definition 3.28, a resolution derivation for ¬F containing [ ].

. By Theorem 3.23 we may assume wlog that ¬F is in clause form.

. Let C1, . . . , Cn, [ ] be all resolvents computed in the refutation.

. By the Corollary 3.41(a) we find

¬F ≡ 〈¬F, C1, . . . , Cn, [ ]〉.

. Because [ ] is unsatisfiable we conlude by Theorem 3.17 that ¬F ≡ [ ],i.e. ¬F ist unsatisfiable.

. Applying Theorem 3.12 we find |= F .

Propositional Logic (25th October 2007) 87

Completeness of the Resolution Method

I Proof Completeness To show If |= F , then `r F .

. Suppose |= F .

. By Theorem 3.23 we find a formula G in clause form with G ≡ ¬F .

. By Theorem 3.12 we find that G is unsatisfiable.

. To show: there is a resolution refutation for G

. The proof is by induction on the number n of propositional variablesoccurring in G.

I n = 0 Then G = 〈[ ], . . . , [ ]〉 and we are done.

I n ⇒ n + 1 Assume that the proposition holds for n, i.e.if G is unsatisfiable and in G occur only the variables p1, . . . , pn,then there is a resolution refutation for G.

. Wlog we may assume that p1, . . . , pn are the n variables occurring in G

Exercise.

Propositional Logic (25th October 2007) 88

Completeness of the Resolution Method (continued)

I Let G′ be a formula in clause form in which the variables p1, . . . , pn+1 occur.

. Let G′> be the formula obtained from G′ by

II deleting each clause, in which pn+1 occurs, andII deleting each occurrence of ¬pn+1.

. Let G′⊥ be the formula obtained from G′ by

II deleting each clause, in which ¬pn+1 occurs, andII deleting each occurrence of pn+1.

. We find: G′> and G′

⊥ are unsatisfiable if G′ is unsatisfiable Exercise.

Propositional Logic (25th October 2007) 89

Completeness of the Resolution Method (continued)

I Applying the induction assumption we find refutations for G′⊥ and G′

>.

I resolvents G′> resolvents G′.

Case 1 resolution refutation for G′. Case 2 resolution derivation with [¬pn+1, . . . ¬pn+1] as last entry.

I resolvents G′⊥ resolvents G′.

Case 1 resolution refutation for G′. Case 2 resolution derivation with [pn+1, . . . , pn+1] as last entry.

I If case 2 was selected twice, then compute the resolvent of[pn+1, . . . , pn+1] and [¬pn+1, . . . , ¬pn+1] resolution refutation for G′.

I An application of the induction principle yields the desired result. qed

Propositional Logic (25th October 2007) 90

Satisfiability

I Up to now Does |= F hold?

I Now Is F satisfiable?

. Goal To find a model for F .

. Applications optimization problems, planning problems, etc.

. Method “greedy satisfiability testing” (gsat)

Propositional Logic (25th October 2007) 91

Some Definitions

I Let F be a formula in clause form.

I C ∈ F iff clause C occurs in F .

I Fu(I) = {C | C ∈ F and I 6|= C}.

I flip(I, p) denotes the interpretation obtained from I

by reversing the truth value assigned to p.

I rank(I, F, p) = |Fu(I)| − |Fu(flip(I, p))|denotes the rank of F wrt I and p.

Propositional Logic (25th October 2007) 92

Satisfiability Testing

I maxtries, maxloops ∈ N.

I initial selects an arbitrary interpretation I for F .

I pick selects an arbitrary element from a set of propositional variables.

I flip implements flip.

I rank impements rank.

Propositional Logic (25th October 2007) 93

A Generic AlgorithmInput: A propositional formula F in clause form.Output: A model for F, if one is found,

or “no model found”.

procedure gensat(F)for J := 1 to maxtries doI := initial(F);for K := 1 to maxloops doif I |= F then return I;I := flip(I,pick(hillclimb(F,I)));

end for;end for;return ‘no model found’;

end gensat;

Propositional Logic (25th October 2007) 94

HillclimbingInput: A propositional formula F in clause form and an interpretation I.Output: A set of variables occurring in F.

procedure hillclimb(F,I);r := rnd(0,1);return {p | select(F,I,p,r) = >};

end hillclimb;

gsat

select(F, I, p, r) =

> if rank(F, I, p) = max{rank(F, I, p′) | p′ ∈ R},

⊥ otherwise.

gwsat

select(F, I, p, r) =

8>><>>:> if r ≥ r′

and rank(F, I, p) = max{rank(F, I, p′) | p′ ∈ R},

> if r < r′ and p occurs in Fu(I),⊥ otherwise.

where r’ is some fixed value in [0, 1].

Propositional Logic (25th October 2007) 95

Some Results

I 3-CNF formulas(formulas in conjunctive normal form, each clause containing 3 literals).

I maxtries = 1, maxloops = N × 100,where N is the number of variables occurring in F .

N variant forced unforced100 gsat 76.1% 23.5%

gwsat 100% 82.2%200 gsat 75.3% 8.4%

gwsat 99% 48.7%300 gsat 77.0% 2.7%

gwsat 100% 26.3%500 gsat 70.2% −

gwsat 100% −

I maxtries = 15 : 26.3% 98.8%.

Propositional Logic (25th October 2007) 96