<<

Propositional Logic Propositional Logic: Contents

and of Propositional Logic

• Satisfiability (SAT)

• Tableau Algorithm for SAT

• Structural induction

• Semantic consequence and

• Conjunctive and (CNF and DNF)

Logic in Computer Science 2 Formulas of propositional Logic

The alphabet of propositional logic consists of

• an infinite p1, p2,... of atomic formulas;

• the logical connectives:

– ¬ (‘not’), called negation; – ∧ (‘and’), called conjunction; – ∨ (‘or’), called disjunction;

• brackets: ( and ).

Remarks:

• atomic formulas are also called propositional variables;

• we use letters p, q, r and indexed letters q1, q2,... to denote atomic for- mulas.

Logic in Computer Science 3 Formulas of propositional logic

The set P of all formulas of propositional logic is defined inductively:

• all atomic formulas are formulas;

• if P is a formula, then ¬P is a formula;

• if P and Q are formulas, then (P ∧ Q) is a formula;

• if P and Q are formulas, then (P ∨ Q) is a formula;

• Nothing else is a formula.

Remarks:

• So, formulas are just strings over a certain alphabet without truth values or meaning.

• We use P , Q, R and indexed letters such as P1,P2,...,Q1,Q2,... to de- note formulas of propositional logic.

Logic in Computer Science 4 Truth Values

An I is a which assigns to any pi a

I(pi) ∈ {0, 1}.

• If I(pi) = 1, then pi is called true under the interpretation I.

• If I(pi) = 0, then pi is called false under the interpretation I.

Given an assignment I we can compute the truth value of compound formulas step by step using so-called truth tables.

Logic in Computer Science 5 Truth tables: negation

The negation ¬P of a formula P is true when P is false and false otherwise:

Definition Suppose an interpretation I is given and we know the value I(P ). Then the value I(¬P ) is computed by

 0 if I(P ) = 1 I(¬P ) = 1 if I(P ) = 0

Corresponding :

P ¬P 1 0 0 1

Logic in Computer Science 6 Truth tables: conjunction

The conjunction (P ∧ Q) is true if and only if both P and Q are true.

Definition Suppose an interpretation I is given and we know I(P ) and I(Q). Then

 1 if I(P ) = 1 and I(Q) = 1 I(P ∧ Q) = 0 if I(P ) = 0 or I(Q) = 0

Corresponding truth table:

P Q (P ∧ Q) 1 1 1 1 0 0 0 1 0 0 0 0

Logic in Computer Science 7 Truth tables: disjunction

The disjunction (P ∨ Q) is true if and only if P is true or Q is true.

Definition Suppose an interpretation I is given and we know I(P ) and I(Q). Then

 1 if I(P ) = 1 or I(Q) = 1 I(P ∨ Q) = 0 if I(P ) = 0 and I(Q) = 0

Corresponding truth table:

P Q (P ∨ Q) 1 1 1 1 0 1 0 1 1 0 0 0

Logic in Computer Science 8 Truth under an interpretation

So, given an interpretation I, we can compute the truth value I(P ) of any formula P under I.

• If I(P ) = 1, then P is called true under the interpretation I.

• If I(P ) = 0, then P is called false under the interpretation I.

Logic in Computer Science 9 Example

List the Interpretations I such that P = ((p1 ∨ ¬p2) ∧ p3) is true under I.

p1 p2 p3 ¬p2 (p1 ∨ ¬p2) P 1 1 1 0 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 0

P is true under I1,I2, and I3, where

• I1(p1) = I1(p2) = I1(p3) = 1,

• I2(p1) = I2(p3) = 1 and I2(p2) = 0,

• I3(p1) = I3(p2) = 0 and I3(p3) = 1.

Logic in Computer Science 10 Truth table for (¬P ∨ Q)

P Q ¬P (¬P ∨ Q) 1 1 0 1 1 0 0 0 0 1 1 1 0 0 1 1

(¬P ∨ Q) represents the assertion ‘if P is true, then Q is true’. Define a ‘new’ connective → by: (P → Q) = (¬P ∨ Q).

In what follows we use (P → Q) as an abbreviation for (¬P ∨ Q).

Logic in Computer Science 11 Truth table for ((P → Q) ∧ (Q → P ))

P Q (P → Q) (Q → P ) ((P → Q) ∧ (Q → P )) 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 1 1

((P → Q) ∧ (Q → P )) represents the assertion ‘P is true if and only if Q is true’. Define a ‘new’ connective ↔ by:

(P ↔ Q) := ((P → Q) ∧ (Q → P )).

In what follows we use (P ↔ Q) as an abbreviation for ((P → Q) ∧ (Q → P )).

Logic in Computer Science 12 Satisfiability

Definition A formula P is satisfiable if and only if there exists an interpretation I such that I(P ) = 1.

Examples

• Every atomic formula p is satisfiable: given p, take the interpretation I with I(p) = 1.

• ¬p is satisfiable: take the interpretation I with I(p) = 0. Then I(¬p) = 1.

• (p ∧ ¬p) is not satisfiable: for any interpretation I, I(p ∧ ¬p) = 0.

• (p ∧ ¬q) is satisfiable: take the interpretation I with I(p) = 1 and I(q) = 0.

Logic in Computer Science 13 Satisfiability and Puzzles (1)

Isaac and Albert were excitedly describing the result of the Third Annual Inter- national Science Fair Extravaganza in Sweden. There were three contestants, Louis, Rene, and Johannes. Isaac reported that Louis won the fair, while Rene came in second. Albert, on the other hand, reported that Johannes won the fair, while Louis came in second. In fact, neither Isaac nor Albert had given a correct report of the results of the science fair. Each of them had given one true statement and one false statement. What was the actual placing of the three contestants?

(Credits: based on slides by Andrei Voronkov)

Logic in Computer Science 14 Encoding into SAT

We take atomic formulas L1,L2,L3,R1,R2,R3,J1,J2,J3 with the intuitive meaning:

• L1: Louis came in first, L2: Louis came in second, L3: Louis came in third.

• R1: Rene came in first, R2: Rene came in second, R3: Rene came in third.

• J1: Johannes came in first, J2: Johannes came in second, J3: Johannes came in third.

We represent the information about Isaac’s report using the formula J:

• J = ((L1 ∧ ¬R2) ∨ (¬L1 ∧ R2))

We represent the information about Albert’s report using the formula A:

• A = ((J1 ∧ ¬L2) ∨ (¬J1 ∧ L2))

Logic in Computer Science 15 Encoding into SAT

We have to encode additional information. Namely,

• everybody comes in at exactly one place: represent this using (P1 ∧ P2), where

P1 = ((L1 ∨ L2 ∨ L3) ∧ (R1 ∨ R2 ∨ R3) ∧ (J1 ∨ J2 ∨ J3))

and

P2 = (¬(L1 ∧ L2) ∧ ¬(L1 ∧ L3) ∧ ¬(L2 ∧ L3) ∧ ¬(R1 ∧ R2) ··· )

• Only one person can come in first, etc: represent this using Q, where

Q = (¬(L1 ∧ R1) ∧ ¬(L2 ∧ R2) ∧ ¬(L3 ∧ R3) ∧ (R1 ∧ J1) ··· )

Any interpretation I with I(J ∧ A ∧ P1 ∧ P2 ∧ Q) = 1 corresponds to a possible placing of the three contestants.

Logic in Computer Science 16 Note on Conjunctions and Disjunctions

On the previous slide, we have used formulas (P1 ∧ · · · ∧ Pn) and (P1 ∨ · · · ∨ Pn) which we have not defined yet. Note that according to the syntax of proposi- tional formulas we use brackets whenever we form the conjunction/disjunction of two formulas.

(P1 ∧ · · · ∧ Pn) is defined by induction over n as follows:

• (P1) = P1;

• (P1 ∧ · · · ∧ Pn+1) = ((P1 ∧ · · · ∧ Pn) ∧ Pn+1);

(P1 ∨ · · · ∨ Pn) is defined by induction over n as follows:

• (P1) = P1;

• (P1 ∨ · · · ∨ Pn+1) = ((P1 ∨ · · · ∨ Pn) ∨ Pn+1);

Logic in Computer Science 17 Checking Satisfiability (SAT)

We want an algorithm that checks whether a given propositional formula is satisfiable. In other words, for a given P , we search for an interpretation I such that I(P ) = 1. If this search is successful, then the output of the algorithm should be

• “yes, P is satisfiable”.

If no such interpretation can be found, then the output of the algorithm should be

• “no, P is not satisfiable”.

Logic in Computer Science 18 SAT applications

SAT has numerous applications in computer and information science. Here are some:

• Circuit design: e.g., when are two circuits equivalent?

• Model checking: does a program represented as a graph structure satisfy its specification?

• Planning in artificial intelligence;

• Haplotyping in bioinformatics: derive haplotype data from genotype data.

Logic in Computer Science 19 Satisfiability checking based on Truth Tables

Here is an algorithm checking satisfiability that is directly based on truth tables:

1. Let P be the input formula;

2. Using truth tables, compute the value I(P ) for all interpretations I;

3. if an I is found such that I(P ) = 1, then output “P is satisfiable”;

4. If no such I is found, output “P is not satisfiable”.

If P is not satisfiable, then this algorithms requires the computation of I(P ) for 2n many interpretations I, where n is the number of atomic formulas in P . Thus the running time of this algorithm is exponential. Major open problem in computer science: does there exist an algorithm check- ing satisfiability that runs in polynomial time? This problem is also known as the P=NP problem.

Logic in Computer Science 20 Tableau Method

Intuition: to check satisfiability of P , we apply tableau rules to P that make explicit the constraints that P imposes on formulas occuring in P (subformulas).

If all sequences of rule applications lead to an “obviously unsatisfiable” con- straint, then P is unsatisfiable. If at least one sequence of rule applications leads to a constraint that cannot be decomposed further and does not con- tain an obviously unsatisfiable set of constraints, then P is satisfiable.

A constraint S is a finite set of propositional formulas. S is satisfiable if there exists an interpretation I such that I(P ) = 1 for all P ∈ S.

Logic in Computer Science 21 Tableau method (Intuition)

To check satisfiable of P , one starts with constraint {P }. Then, one applies rules that reflect the following facts:

• if (P ∧ Q) is satisfiable, then {P, Q, (P ∧ Q)} is satisfiable;

• if ¬¬P is satisfiable, then {P, ¬¬P } is satisfiable;

• if ¬(P ∨ Q) is satisfiable, then {¬P, ¬Q, ¬(P ∨ Q)} is satisfiable.

• if (P ∨ Q) is satisfiable, then {P, (P ∨ Q)} is satisfiable or {Q, (P ∨ Q)} is satisfable;

• if ¬(P ∧Q) is satisfiable, then {¬P, ¬(P ∧Q)} is satisfiable or {¬Q, ¬(P ∧Q)} is satisfiable;

To avoid “branching”, we first consider satisfiability of formulas not containing any (P ∨ Q) and ¬(P ∧ Q).

Logic in Computer Science 22 Ingredients of the algorithm (partial)

• A constraint S is a finite set of propositional formulas;

• A constraint S contains a clash if there exists a formula P such that P ∈ S and ¬P ∈ S.

• A non-branching completion rule is of the form

S =⇒ S0,

where S, S0 are constraints.

• A constraint S is complete if no completion rule is applicable to S.

Logic in Computer Science 23 Completion Rules (partial)

Assume that S does not contain a clash (if it does, no rule is applicable).

(∧-rule) S =⇒∧ S ∪ {P,Q} if (a) (P ∧ Q) ∈ S and (b) {P,Q} 6⊆ S.

(¬¬-rule) S =⇒¬ S ∪ {P } if (a) ¬¬P ∈ S and (b) P 6∈ S.

(¬∨-rule) S =⇒¬∨ S ∪ {¬P, ¬Q} if (a) ¬(P ∨ Q) ∈ S and (b) {¬P, ¬Q} 6⊆ S.

Logic in Computer Science 24 Example 1

We check satisfiability of P = ((¬p ∧ q) ∧ ¬¬r).

Set S0 = {((¬p ∧ q) ∧ ¬¬r)}.

• An application of =⇒∧ gives

S1 = S0 ∪ {(¬p ∧ q), ¬¬r}.

• An application of =⇒∧ gives

S2 = S1 ∪ {¬p, q}

• An application of =⇒¬ gives

S3 = S2 ∪ {r}

Note that S3 = {P, (¬p ∧ q), ¬¬r, ¬p, q, r}.

Logic in Computer Science 25 Example 1 (continued)

S3 = {P, (¬p ∧ q), ¬¬r, ¬p, q, r}.

• No completion rule is applicable to S3;

• Thus, S3 is complete.

• S3 does not contain any clash.

• Thus, the output is “P is satisfiable”.

S3 describes an interpretation I under which P is true. Namely, we set for any atomic formula x from P :

• I(x) = 1 if, and only if, x ∈ S3.

Thus, I(q) = I(r) = 1 and I(p) = 0. Then I(P ) = 1.

Logic in Computer Science 26 Example 2

We check satisfiability of P = ((p ∧ q) ∧ ¬¬¬p).

Set S0 = {((p ∧ q) ∧ ¬¬¬p)}.

• An application of =⇒∧ gives

S1 = S0 ∪ {(p ∧ q), ¬¬¬p}.

• An application of =⇒∧ gives

S2 = S1 ∪ {p, q}

• An application of =⇒¬ gives

S3 = S2 ∪ {¬p}

Note that S3 = {P, (p ∧ q), ¬¬¬p, p, q, ¬p}. Thus S3 contains a clash: p ∈ S3 and ¬p ∈ S3 and we output “P is not satisfiable”.

Logic in Computer Science 27 Tableau Path (partial)

A sequence

S0,S1,...,Sn of constraints is a tableau path if for any i < n at least one of the following conditions is satisfied:

• Si =⇒∧ Si+1

• Si =⇒¬∨ Si+1

• Si =⇒¬ Si+1

Logic in Computer Science 28 The tableau algorithm (partial)

• A tableau path S0,...,Sn is complete if Sn is complete.

• A tableau path S0,...,Sn contains a clash if Sn contains a clash.

To check satisfiability of a formula P , do the following:

• Generate a tableau path starting with the constraint {P };

• If the tableau path is complete and does not contain a clash, then output “P is satisfiable”.

• If the tableau path contains a clash, then output “P is not satisfiable”.

Logic in Computer Science 29 Example 3

We check satisfiability of P = ((p ∧ q) ∧ ¬(p ∨ q)).

Set S0 = {((p ∧ q) ∧ ¬(p ∨ q))}.

• An application of =⇒∧ gives

S1 = S0 ∪ {(p ∧ q), ¬(p ∨ q)}.

• An application of =⇒∧ gives

S2 = S1 ∪ {p, q}

• An application of =⇒¬∨ gives

S3 = S2 ∪ {¬p, ¬q}

S3 contains a clash: p ∈ S3 and ¬p ∈ S3 and we output “P is not satisfiable”.

Logic in Computer Science 30 Analysing the Tableau Algorithm (partial)

To show that the tableau algorithm does what it is supposed to do, one has to show the following. Let P be a propositional formula.

• Termination: The algorithm terminates: there is no infinite tableau path

S0,S1,... starting with {P }.

• Soundness: If there exists a complete tableau path S0,S1,...,Sn with

{P } = S0 and without clash, then P is satisfiable.

• Completeness: If P is satisfiable, then no tableau path (generated by the

three rules above) S0,S1,...,Sn with {P } = S0 contains a clash.

For the proof, we require definitions and proofs by structural induction. This will be done later.

Logic in Computer Science 31 Branching

How to deal with formulas containing (P ∨ Q) or ¬(P ∧ Q)? Recall that

• if (P ∨ Q) is satisfiable, then {P, (P ∨ Q)} is satisfiable or {Q, (P ∨ Q)} is satisfable;

• if ¬(P ∧Q) is satisfiable, then {¬P, ¬(P ∧Q)} is satisfiable or {¬Q, ¬(P ∧Q)} is satisfiable;

Thus, we have to explore different ways to satisfy a formula.

Logic in Computer Science 32 Example 4

We check satisfiability of P = ((p ∧ ¬p) ∨ (q ∧ q)).

Set S0 = {P }.

• An application of =⇒∨ gives

S1 = S0 ∪ {p ∧ ¬p} or S2 = S0 ∪ {(q ∧ q)}.

• We first try to satisfy S1. An application of =⇒∧ to S1 gives

S3 = S1 ∪ {p, ¬p}

which contains a clash. We have been unsuccessful.

• We now try to satisfy S2. An application of =⇒∧ to S2 gives

S4 = S2 ∪ {q, q}

S4 does not contain a clash and is complete.

Logic in Computer Science 33 Example 4 (continued)

We have two tableau paths

S0,S1,S3 S0,S2,S4

The second path is complete and does not contain a clash. Thus, the output is “P is satisfiable”.

Recall that S4 = {P, (q ∧ q), q}. S4 also describes an interpretation I under which P is true, namely I(q) = 1.

Logic in Computer Science 34 Ingredients of the algorithm (complete)

• A constraint S is a finite set of propositional formulas;

• A constraint S contains a clash if there exists a formula P such that P ∈ S and ¬P ∈ S.

• A non-branching completion rule is of the form

S =⇒ S0,

where S, S0 are constraints.

• A branching completion rule is of the form

S =⇒ S1 or S2,

where S, S1,S2 are constraints.

• A constraint S is complete if no completion rule is applicable to S.

Logic in Computer Science 35 Completion Rules

Assume that S does not contain a clash (if it does, no rule is applicable).

(∧-rule) S =⇒∧ S ∪ {P,Q} if

(a) (P ∧ Q) ∈ S and (b) {P,Q} 6⊆ S.

(¬¬-rule) S =⇒¬ S ∪ {P } if (a) ¬¬P ∈ S and (b) P 6∈ S.

(¬∨-rule) S =⇒¬∨ S ∪ {¬P, ¬Q} if (a) ¬(P ∨ Q) ∈ S and (b) {¬P, ¬Q} 6⊆ S.

(∨-rule) S =⇒∨ S ∪ {P } or S ∪ {Q} if (a) (P ∨ Q) ∈ S and (b) P 6∈ S and Q 6∈ S.

(¬∧-rule) S =⇒¬∧ S ∪ {¬P } or S ∪ {¬Q} if (a) ¬(P ∧ Q) ∈ S and (b) ¬P 6∈ S and ¬Q 6∈ S.

Logic in Computer Science 36 Tableau Path

A sequence

S0,S1,...,Sn of constraints is a tableau path if for any i < n at least one of the following conditions is satisfied:

• Si =⇒∧ Si+1

• Si =⇒¬∨ Si+1

• Si =⇒¬ Si+1

• for some S:

Si =⇒¬∧ Si+1 or S or Si =⇒¬∧ S or Si+1

• for some S:

Si =⇒∨ Si+1 or S or Si =⇒∨ S or Si+1

Logic in Computer Science 37 The tableau algorithm

• A tableau path S0,...,Sn is complete if Sn is complete.

• A tableau path S0,...,Sn contains a clash if Sn contains a clash.

To check satisfiability of a formula P , do the following:

• Generate tableau paths starting with the constraint {P };

• If there is a tableau path that is complete and does not contain a clash, then output “P is satisfiable”.

• If no such tableau path can be found (i.e., all complete tableau paths starting with P contain a clash), then output “P is not satisfiable”.

Logic in Computer Science 38 Example 5

We check satisfiability of P = (((¬p ∨ q) ∧ p) ∧ ¬¬q).

Set S0 = {P }.

• An application of =⇒∧ gives S1 = S0 ∪ {((¬p ∨ q) ∧ p), ¬¬q}.

• An application of =⇒∧ gives S2 = S1 ∪ {(¬p ∨ q), p}.

• An application of =⇒∨ gives

S3 = S2 ∪ {¬p}

S3 contains a clash: ¬p ∈ S3 and p ∈ S3.

• The other possible application of =⇒∨ to S2 gives

S4 = S2 ∪ {q}

S4 is complete and does not contain a clash.

Logic in Computer Science 39 Example 5 (continued)

We have two tableau paths

S0,S1,S2,S3 S0,S1,S2,S4

The second path is complete and does not contain a clash. Thus, the output is “P is satisfiable”.

Recall that S4 = {P, ((¬p ∨ q) ∧ p), p, ¬¬q, (¬p ∨ q), q}.

S4 also describes an interpretation I under which P is true. Namely, we set for any atomic formula x from P :

• I(x) = 1 if, and only if, x ∈ S4.

Thus, I(p) = I(q) = 1. Then I(P ) = 1.

Logic in Computer Science 40 Example 6

We check satisfiability of P = (((¬p ∨ q) ∧ p) ∧ ¬q).

Set S0 = {P }.

• An application of =⇒∧ gives S1 = S0 ∪ {((¬p ∨ q) ∧ p), ¬q}.

• An application of =⇒∧ gives S2 = S1 ∪ {(¬p ∨ q), p}.

• An application of =⇒∨ gives

S3 = S2 ∪ {¬p}

S3 contains a clash: ¬p ∈ S3 and p ∈ S3.

• The other possible application of =⇒∨ gives

S4 = S2 ∪ {q}

S4 contains a clash: q ∈ S4 and ¬q ∈ S4.

Logic in Computer Science 41 Example 6 (continued)

We have two tableau paths

S0,S1,S2,S3 S0,S1,S2,S4

Both contain a clash. Thus, the output is “P is not satisfiable”.

Logic in Computer Science 42 Analysing the Tableau Algorithm

To show that the tableau algorithm does what it is supposed to do, one has to show the following. Let P be a propositional formula.

• Termination: The algorithm terminates: there are only finitely many tableau paths starting with {P }.

• Soundness: If there exists a complete tableau path S0,S1,...,Sn with

S0 = {P } without clash, then P is satisfiable.

• Completeness: If P is satisfiable, then there exists a complete tableau

path S0,S1,...,Sn with S0 = {P } without clash.

For the proof, we require definitions and proofs by structural induction. We first introduce this important concept.

Logic in Computer Science 43 Definitions by structural induction

Many important functions F which have as domain the set of all propositional formulas are defined by specifying the values

• F (pi), for all propositional variables pi,

• F (P ∧ Q), given the values F (P ) and F (Q),

• F (P ∨ Q), given the values F (P ) and F (Q),

• F (¬P ), given the value F (P ).

Such a definition is called a definition by structural induction. (The idea should be familar from proofs by induction for natural numbers.)

Logic in Computer Science 44 Example 1: Interpretations

The definition of interpretations I was given by structural induction. To define an interpretation I it is sufficient to define

• I(pi) for all atomic formulas pi.

The values I(P ), P an arbitrary propositional formula, are then given by means of truth tables. In other words, truth tables define the values

• I(P ∧ Q), given the values I(P ) and I(Q),

• I(P ∨ Q), given the values I(P ) and I(Q),

• I(¬P ), given the value I(P ).

Logic in Computer Science 45 Example 2: Subformulas

The function sub(P ) giving the subformulas of a formula P is defined by struc- tural induction as follows:

• sub(pi) = {pi}, for all atomic formulas pi,

• sub(P ∧ Q) = {(P ∧ Q)} ∪ sub(P ) ∪ sub(Q)

• sub(P ∨ Q) = {(P ∨ Q)} ∪ sub(P ) ∪ sub(Q)

• sub(¬P ) = {¬P } ∪ sub(P ).

The set sub(P ) is called the set of subformulas of P .

Logic in Computer Science 46 Subformulas

Compute sub(P ) for P = ((p1 ∧ ¬p2) ∨ ¬p3).

sub(P ) = {P } ∪ sub(p1 ∧ ¬p2) ∪ sub(¬p3)

= {P } ∪ {(p1 ∧ ¬p2)} ∪ sub(p1) ∪ sub(¬p2) ∪ sub(¬p3)

= {P, (p1 ∧ ¬p2)} ∪ {p1} ∪ {¬p2} ∪ sub(p2) ∪ {¬p3} ∪ sub(p3)

= {P, (p1 ∧ ¬p2), p1, ¬p2, p2, ¬p3, p3}

Logic in Computer Science 47 Example 3: Length of a formula

The function L(P ) giving the length of a formula is defined by structural induc- tion as follows:

• L(pi) = 1, for all atomic formulas pi,

• L(P ∧ Q) = 1 + L(P ) + L(Q),

• L(P ∨ Q) = 1 + L(P ) + L(Q),

• L(¬P ) = 1 + L(P ).

L(P ) is called the length of formula P .

Logic in Computer Science 48 Length of a formula

Compute L(P ) for P = ¬(p0 ∧ ¬p1).

L(P ) = 1 + L(p0 ∧ ¬p1)

= 1 + 1 + L(p0) + L(¬p1)

= 1 + 1 + 1 + 1 + L(p1)

= 5.

Logic in Computer Science 49 Proofs by structural induction

Statements about objects defined by structural induction can often be proved by structural induction. We illustrate this proof method by means of the following example. (|sub(P )| denotes the number of subformulas of P .)

Theorem For every formula P : |sub(P )| ≤ L(P ). Proof The proof is by structural induction. In other words, we show:

1. for all atomic formulas pi: |sub(pi)| ≤ L(pi);

2. for all formulas P and Q: if |sub(P )| ≤ L(P ) and |sub(Q)| ≤ L(Q), then |sub(P ∧ Q)| ≤ L(P ∧ Q);

3. for all formulas P and Q: if |sub(P )| ≤ L(P ) and |sub(Q)| ≤ L(Q), then |sub(P ∨ Q)| ≤ L(P ∨ Q);

4. for every formula P : if |sub(P )| ≤ L(P ), then |sub(¬P )| ≤ L(¬P ).

Logic in Computer Science 50 We now check (1.)-(4.):

1. |sub(pi)| = 1 ≤ 1 = L(pi).

2. Suppose |sub(P )| ≤ L(P ) and |sub(Q)| ≤ L(Q). Then

|sub(P ∧ Q)| = |{P ∧ Q} ∪ sub(P ) ∪ sub(Q)|

≤ 1 + |sub(P )| + |sub(Q)|

≤ 1 + L(P ) + L(Q)

= L(P ∧ Q).

3. Exercise.

4. Exercise.

Logic in Computer Science 51 Termination of the tableau algorithm

Assume P is given. We have to show that there are only finitely many tableau paths {P } = S0,S1,...,Sn. Let sub¬(P ) = sub(P ) ∪ {¬Q | Q ∈ sub(P )}.

Now observe for any tableau path {P } = S0,S1,...,Sn:

¬ • S0 ⊂ S1 ⊂ · · · ⊂ Sn ⊆ sub (P ).

Hence

• the length of any tableau path {P } = S0,S1,...,Sn is not greater than |sub¬(P )|

• and the number of such tableau paths is not greater that |sub¬(P )||sub¬(P )|.

(Here, by X ⊂ Y we denote that X is a proper of Y .)

Logic in Computer Science 52 Soundness of the tableau algorithm

Let {P } = S0,S1,...,Sn be a complete tableau path such that Sn does not contain a clash. We define an interpretation I by

 1 if pi ∈ Sn I(pi) = 0 if pi 6∈ Sn

We show the following claim by structural induction:

Claim 1

• I(Q) = 1 for all Q ∈ Sn;

• I(Q) = 0 for all ¬Q ∈ Sn.

Since P ∈ Sn, we obtain I(P ) = 1. Thus P is satisfiable.

Logic in Computer Science 53 The steps of the structural induction

We have to show:

1. Claim 1 holds for all atomic formulas pi;

2. if Claim 1 holds for P1 and P2, then Claim 1 holds for (P1 ∧ P2);

3. if Claim 1 holds for P1 and P2, then Claim 1 holds for (P1 ∨ P2);

4. if Claim 1 holds for Q, then it holds for ¬Q.

Logic in Computer Science 54 Proof of Point 1

Let pi be an atomic formula. We have to show

(a) I(pi) = 1 if pi ∈ Sn;

(b) I(pi) = 0 if ¬pi ∈ Sn.

Point (a) follows by definition of I. For Point (b),

• assume that ¬pi ∈ Sn.

• Since Sn does not contain a clash, pi 6∈ Sn.

• Hence, by definition of I, I(pi) = 0.

Logic in Computer Science 55 Proof for Point 2

Assume Claim 1 holds for P1 and P2.

Suppose (P1 ∧ P2) ∈ Sn.

• Then, by non-applicability of =⇒∧ to Sn, P1 ∈ Sn and P2 ∈ Sn;

• By induction hypothesis, I(P1) = 1 and I(P2) = 1;

• Hence I(P1 ∧ P2) = 1.

Suppose ¬(P1 ∧ P2) ∈ Sn.

• Then, by non-applicability of =⇒¬∧ to Sn, ¬P1 ∈ Sn or ¬P2 ∈ Sn;

• By induction hypothesis, I(P1) = 0 or I(P2) = 0;

• Hence I(P1 ∧ P2) = 0.

Logic in Computer Science 56 Proof for Point 3

Assume Claim 1 holds for P1 and P2.

Suppose (P1 ∨ P2) ∈ Sn.

• Then, by non-applicability of =⇒∨ to Sn, P1 ∈ Sn or P2 ∈ Sn;

• By induction hypothesis, I(P1) = 1 or I(P2) = 1;

• Hence I(P1 ∨ P2) = 1.

Suppose ¬(P1 ∨ P2) ∈ Sn.

• Then, by non-applicability of =⇒¬∨ to Sn, ¬P1 ∈ Sn and ¬P2 ∈ Sn;

• By induction hypothesis, I(P1) = 0 and I(P2) = 0;

• Hence I(P1 ∨ P2) = 0.

Logic in Computer Science 57 Proof for Point 4

Assume Claim 1 holds for Q. We show Claim 1 for ¬Q.

Suppose ¬Q ∈ Sn.

• By induction hypothesis, I(Q) = 0.

• Hence I(¬Q) = 1.

Suppose ¬¬Q ∈ Sn.

• Then, by non-applicability of =⇒¬¬ to Sn, Q ∈ Sn.

• By induction hypothesis, I(Q) = 1;

• Hence I(¬Q) = 0.

Logic in Computer Science 58 Completeness of the tableau algorithm

Assume that P is satisfiable.

We have to construct a complete tableau path {P } = S0,S1,...,Sn such that

Sn does not contain a clash. Let I be an interpretation with I(P ) = 1. We construct the tableau path as follows: Let S0 = {P } and assume that

S0 ⊂ S1 ⊂ · · · ⊂ Si have already been defined such that I(Q) = 1 for all Q ∈ Si. Then Si does not contain a clash. If no completion rule is applicable, then the path is complete and we are done. Now assume that a completion rule is applicable. We show that we can apply the rule in such a way that Si =⇒ Si+1 and I(Q) = 1 for all Q ∈ Si+1.

Logic in Computer Science 59 Construction of Si+1

1. If P1 ∧ P2 ∈ Si and =⇒∧ is applicable, then set Si+1 = Si ∪ {P1,P2}. Then

I(P1) = I(P2) = 1 since I(P1 ∧ P2) = 1. Thus I(Q) = 1 for all Q ∈ Si+1.

2. Otherwise, if ¬(P1 ∨ P2) ∈ Si and =⇒¬∨ is applicable, then set Si+1 =

Si ∪ {¬P1, ¬P2}. Then I(¬P1) = I(¬P2) = 1 since I(¬(P1 ∨ P2)) = 1. Thus

I(Q) = 1 for all Q ∈ Si+1.

3. Otherwise, if ¬¬P1 ∈ Si and =⇒¬ is applicable, then set Si+1 = Si ∪ {P1}.

Then I(P1) = 1 since I(¬¬P1) = 1. Thus I(Q) = 1 for all Q ∈ Si+1.

Logic in Computer Science 60 Construction of Si+1

1. Otherwise, if ¬(P1 ∧ P2) ∈ Si and =⇒¬∧ is applicable, then I(¬P1) = 1 or

I(¬P2) = 1 since I(¬(P1 ∧ P2)) = 1. In the first case let Si+1 = Si ∪ {¬P1}.

In the second case let Si+1 = Si ∪ {¬P2}. In both cases I(Q) = 1 for all

Q ∈ Si+1.

2. Otherwise, if (P1 ∨ P2) ∈ Si and =⇒∨ is applicable, then I(P1) = 1 or

I(P2) = 1 since I(P1 ∨ P2) = 1. In the first case let Si+1 = Si ∪ {P1}. In the

second case let Si+1 = Si ∪ {P2}. In both cases I(Q) = 1 for all Q ∈ Si+1.

Logic in Computer Science 61 Modern SAT solvers

High performance SAT solvers are not tableau based. They are based on modern versions of

• the Davis-Putnam-Logemann-Loveland algorithm (DPLL) developed in the 1960s (which is based on a very general proof method called resolution);

• and on stochastic local search algorithms.

Many solvers are available as free and open source software.

Logic in Computer Science 62

Definition A tautology is a formula which is true under all interpretations.

Example All formulas of the form P ∨ ¬P are tautologies, because

I(P ∨ ¬P ) = 1 for all interpretations I:

P ¬P P ∨ ¬P 1 0 1 0 1 1

Observation: A formula P is a tautology if, and only if, ¬P is not satisfiable.

Logic in Computer Science 63 Contradiction

Definition A contradiction is a formula which is false under all interpretations.

Example All formulas of the form P ∧ ¬P are tautologies, because

I(P ∧ ¬P ) = 0 for all interpretations I:

P ¬P P ∧ ¬P 1 0 0 0 1 0

Observation: A formula P is a contradiction if, and only if, P is not satisfiable

Logic in Computer Science 64 Semantic consequence

Definition Suppose X is a finite set of formulas and P is a formula. Then P fol- lows from X (is a semantic consequence of X) if the following holds for every interpretation I:

If I(Q) = 1 for all Q ∈ X, then I(P ) = 1.

This is denoted by X |= P.

Logic in Computer Science 65 Example 1

Show {p1 ∧ p2} |= p1 ∨ p2. Solution:

p1 p2 p1 ∧ p2 p1 ∨ p2 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 0

The statement follows, because in any row where the column for p1∧p2 contains

1 the column for p1 ∨ p2 also contains 1.

Logic in Computer Science 66 Example 2

Show {p1} 6|= p2.

Solution: Take the interpretation I with I(p1) = 1 and I(p2) = 0.

Logic in Computer Science 67 Example 3

We show that ∅ |= P if, and only if, P is a tautology.

(⇒) Assume P is not a tautology. Take interpretation I with I(P ) = 0. Then I(Q) = 1 for all Q ∈ ∅, but I(P ) 6= 1, Hence ∅ 6|= P . (⇐) Assume ∅ 6|= P . Take interpretation I with I(Q) = 1 for all Q ∈ ∅ and I(P ) 6= 1. Then P is not a tautology.

Logic in Computer Science 68 Example 4 (ex falso quodlibet)

We show that {(P ∧ ¬P )} |= Q holds for all formulas Q.

Let Q be arbitrary. There is no interpretation I such that I(P ∧ ¬P ) = 1. Thus, if I is an interpretation such that I(P ∧ ¬P ) = 1, then I(Q) = 1. Thus {(P ∧ ¬P )} |= Q.

Logic in Computer Science 69 Reduction to Satisfiability

Recall that we call a finite set S of formulas satisfiable if there exists an interpre- tation I such that I(Q) = 1 for all Q ∈ S.

Note that the set S = {Q1,...,Qn} is satisfiable if, and only if, the formula ob- tained by taking the conjunction of all Q1,...,Qn, (Q1 ∧ ... ∧ Qn), is satisfiable.

Observation For every finite set S of formulas and every formula P : S |= P if, and only if, S ∪ {¬P } is not satisfiable.

Thus, we can use the tableau algorithm to check semantic consequence: to check whether S |= P check that S ∪ {¬P } is not satisfiable.

Logic in Computer Science 70 Example

We check {p ∧ q} |= p ∨ q. To this end, we have to show that

S0 = {p ∧ q, ¬(p ∨ q)} is not satisfiable. We do this using the tableau algorithm:

• an application of =⇒∧ to S0 gives

S1 = S0 ∪ {p, q, ¬(p ∨ q)}

• an application of =⇒¬∨ to S1 gives

S2 = S1 ∪ {¬p, ¬q}

S2 contains a clash: {p, ¬p} ⊆ S2. Thus, all tableau paths starting with S0 contain a clash. Hence S0 is not satisfiable.

Logic in Computer Science 71 Logical equivalence

Definition Two formulas P and Q are called equivalent if they have the same truth value under every possible interpretation. In other words, P and Q are equivalent if I(P ) = I(Q) for every interpretation I. This is denoted by

P ≡ Q.

Observation For any two formulas P and Q: P ≡ Q if, and only if, neither (P ∧ ¬Q) nor (Q ∧ ¬P ) are satisfiable.

Thus, we can use the tableau algorithm to check logical equivalence: to check whether P ≡ Q check that (P ∧ ¬Q) is not satisfiable and (Q ∧ ¬P ) is not satisfiable.

Logic in Computer Science 72 Laws for equivalences

The following equivalences can be checked using the tableau algorithm or by truth tables:

• Associative laws:

P ∨ (Q ∨ R) ≡ (P ∨ Q) ∨ R,P ∧ (Q ∧ R) ≡ (P ∧ Q) ∧ R

• Commutative laws:

P ∨ Q ≡ Q ∨ P,P ∧ Q ≡ Q ∧ P

Logic in Computer Science 73 Laws for Equivalence

• Distributive laws:

P ∧ (Q ∨ R) ≡ (P ∧ Q) ∨ (P ∧ R),P ∨ (Q ∧ R) ≡ (P ∨ Q) ∧ (P ∨ R)

• Complement law: ¬¬P ≡ P

• De Morgan’s laws:

¬(P ∨ Q) ≡ ¬P ∧ ¬Q, ¬(P ∧ Q) ≡ ¬P ∨ ¬Q.

Logic in Computer Science 74 Proof of {(p ∧ (q ∨ r))} |= ((p ∧ q) ∨ (p ∧ r))

We have to show that S0 = {(p ∧ (q ∨ r)), ¬((p ∧ q) ∨ (p ∧ r))} is not satisfiable.

• an application of =⇒∧ to S0 gives

S1 = S0 ∪ {p, (q ∨ r)}

• an application of =⇒¬∨ to S1 gives

S2 = S1 ∪ {¬(p ∧ q), ¬(p ∧ r)}

Logic in Computer Science 75 Continue by decomposing (q ∨ r) ∈ S2 (1)

First option:

• an application of =⇒∨ to (q ∨ r) ∈ S2 gives

S3 = S2 ∪ {q}

• an application of =⇒¬∧ to ¬(p ∧ q) ∈ S3 gives S4 = S3 ∪ {¬p} which contains the clash {p, ¬p}.

• the other application of =⇒¬∧ to ¬(p ∧ q) ∈ S3 gives S5 = S3 ∪ {¬q} which contains the clash {q, ¬q}.

Thus, every complete tableau path starting with S0,S1,S2,S3 contains a clash.

Logic in Computer Science 76 Continue by decomposing (q ∨ r) ∈ S2 (2)

Second option:

• an application of =⇒∨ to (q ∨ r) ∈ S2 gives S6 = S2 ∪ {r}.

• an application of =⇒¬∧ to ¬(p ∧ r) ∈ S6 gives S7 = S6 ∪ {¬p} which contains the clash {p, ¬p}.

• the other application of =⇒¬∧ to ¬(p ∧ r) ∈ S6 gives S8 = S6 ∪ {¬r} which contains the clash {r, ¬r}.

Thus, every complete tableau path starting with S0,S1,S2,S6 contains a clash.

We can conclude that all complete tableau paths starting with S0 contain a clash.

Logic in Computer Science 77 Conjunctive and disjunctive normal form

• A formula (P1 ∨ P2 ∨ · · · ∨ Pn) is called a disjunction of P1,...,Pn;

• Similarly, (P1 ∧ P2 ∧ · · · ∧ Pn) is called a conjunction of P1,...,Pn;

• A formula which is either an atomic formula or its negation is called a lit- eral;

• A formula is in (CNF) if it is a conjunction of dis- junctions of literals.

• A formula is in disjunctive normal form (DNF) if it is a disjunction of conjunc- tions of literals.

Logic in Computer Science 78 Examples

• p1, ¬p1, ¬p5 are literals. They are also in CNF and in DNF.

• (p ∨ q) is in CNF and in DNF.

• ((p1 ∨ p2) ∧ (¬p1 ∨ p3)) and ((p1 ∨ p2) ∧ ¬p1) are in CNF and not in DNF.

• ((p1 ∧ p2) ∨ (¬p1 ∧ p3)) and (p ∨ (p ∧ ¬p)) are in DNF and not in CNF.

Logic in Computer Science 79 CNF

Theorem (1) Every formula is equivalent to a formula in CNF. (2) Every formula is equivalent to a formula in DNF. Proof of (1) Suppose a formula P is given. We transform P to a formula in CNF using the Laws of equivalence: Step 1. Apply De Morgan’s laws and Complement law

¬¬P ≡ P until negation (¬) occurs in front of atomic formulas only. Step 2. Apply Distributive law

P ∨ (Q ∧ R) ≡ (P ∨ Q) ∧ (P ∨ R) and Commutative laws until the formula is in CNF.

Logic in Computer Science 80 Example

Transform (¬(p0 ∨ p1) ∨ (p2 ∧ p1)) into CNF.

(¬(p0 ∨ p1) ∨ (p2 ∧ p1)) is equivalent to (de Morgan’s Law)

((¬p0 ∧ ¬p1) ∨ (p2 ∧ p1)) is equivalent to (Distributive law)

(((¬p0 ∧ ¬p1) ∨ p2) ∧ ((¬p0 ∧ ¬p1) ∨ p1)) is equivalent to (Distributive law)

((¬p0 ∨ p2) ∧ (¬p1 ∨ p2) ∧ (¬p0 ∧ ¬p1) ∨ p1)) is equivalent to (Distributive law)

((¬p0 ∨ p2) ∧ (¬p1 ∨ p2) ∧ (¬p0 ∨ p1) ∧ (¬p1 ∨ p1)).

Logic in Computer Science 81