propositional logic - computer science

81
Propositional Logic

Upload: others

Post on 28-Oct-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Propositional Logic - Computer Science

Propositional Logic

Page 2: Propositional Logic - Computer Science

Propositional Logic: Contents

• Syntax and Semantics of Propositional Logic

• Satisfiability (SAT)

• Tableau Algorithm for SAT

• Structural induction

• Semantic consequence and logical equivalence

• Conjunctive and disjunctive normal form (CNF and DNF)

Logic in Computer Science 2

Page 3: Propositional Logic - Computer Science

Formulas of propositional Logic

The alphabet of propositional logic consists of

• an infinite set 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

Page 4: Propositional Logic - Computer Science

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 ormeaning.

• 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

Page 5: Propositional Logic - Computer Science

Truth Values

An interpretation I is a function which assigns to any atomic formula pi a truthvalue

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 formulasstep by step using so-called truth tables.

Logic in Computer Science 5

Page 6: Propositional Logic - Computer Science

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

I(¬P ) =

{0 if I(P ) = 11 if I(P ) = 0

Corresponding truth table:

P ¬P1 00 1

Logic in Computer Science 6

Page 7: Propositional Logic - Computer Science

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

I(P ∧Q) =

{1 if I(P ) = 1 and I(Q) = 10 if I(P ) = 0 or I(Q) = 0

Corresponding truth table:

P Q (P ∧Q)1 1 11 0 00 1 00 0 0

Logic in Computer Science 7

Page 8: Propositional Logic - Computer Science

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

I(P ∨Q) =

{1 if I(P ) = 1 or I(Q) = 10 if I(P ) = 0 and I(Q) = 0

Corresponding truth table:

P Q (P ∨Q)1 1 11 0 10 1 10 0 0

Logic in Computer Science 8

Page 9: Propositional Logic - Computer Science

Truth under an interpretation

So, given an interpretation I, we can compute the truth value I(P ) of anyformula 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

Page 10: Propositional Logic - Computer Science

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 11 1 0 0 1 01 0 1 1 1 11 0 0 1 1 00 1 1 0 0 00 1 0 0 0 00 0 1 1 1 10 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

Page 11: Propositional Logic - Computer Science

Truth table for (¬P ∨Q)

P Q ¬P (¬P ∨Q)1 1 0 11 0 0 00 1 1 10 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

Page 12: Propositional Logic - Computer Science

Truth table for ((P → Q) ∧ (Q→ P ))

P Q (P → Q) (Q→ P ) ((P → Q) ∧ (Q→ P ))1 1 1 1 11 0 0 1 00 1 1 0 00 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

Page 13: Propositional Logic - Computer Science

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 withI(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

Page 14: Propositional Logic - Computer Science

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 insecond.

In fact, neither Isaac nor Albert had given a correct report of the results ofthe science fair. Each of them had given one true statement and one falsestatement. What was the actual placing of the three contestants?

(Credits: based on slides by Andrei Voronkov)

Logic in Computer Science 14

Page 15: Propositional Logic - Computer Science

Encoding into SAT

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

• 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: Johannescame 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

Page 16: Propositional Logic - Computer Science

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 possibleplacing of the three contestants.

Logic in Computer Science 16

Page 17: Propositional Logic - Computer Science

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/disjunctionof 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

Page 18: Propositional Logic - Computer Science

Checking Satisfiability (SAT)

We want an algorithm that checks whether a given propositional formula issatisfiable.

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 shouldbe

• “no, P is not satisfiable”.

Logic in Computer Science 18

Page 19: Propositional Logic - Computer Science

SAT applications

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

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

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

• Planning in artificial intelligence;

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

Logic in Computer Science 19

Page 20: Propositional Logic - Computer Science

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 ) for2n many interpretations I, where n is the number of atomic formulas in P . Thusthe 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 theP=NP problem.

Logic in Computer Science 20

Page 21: Propositional Logic - Computer Science

Tableau Method

Intuition: to check satisfiability of P , we apply tableau rules to P that makeexplicit 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 applicationsleads 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 existsan interpretation I such that I(P ) = 1 for all P ∈ S.

Logic in Computer Science 21

Page 22: Propositional Logic - Computer Science

Tableau method (Intuition)

To check satisfiable of P , one starts with constraint {P}. Then, one applies rulesthat 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)} issatisfable;

• 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 containingany (P ∨Q) and ¬(P ∧Q).

Logic in Computer Science 22

Page 23: Propositional Logic - Computer Science

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 =⇒ S′,

where S, S′ are constraints.

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

Logic in Computer Science 23

Page 24: Propositional Logic - Computer Science

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

Page 25: Propositional Logic - Computer Science

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

Page 26: Propositional Logic - Computer Science

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 anyatomic 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

Page 27: Propositional Logic - Computer Science

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

Page 28: Propositional Logic - Computer Science

Tableau Path (partial)

A sequenceS0, S1, . . . , Sn

of constraints is a tableau path if for any i < n at least one of the followingconditions is satisfied:

• Si =⇒∧ Si+1

• Si =⇒¬∨ Si+1

• Si =⇒¬ Si+1

Logic in Computer Science 28

Page 29: Propositional Logic - Computer Science

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

Page 30: Propositional Logic - Computer Science

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

Page 31: Propositional Logic - Computer Science

Analysing the Tableau Algorithm (partial)

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

• Termination: The algorithm terminates: there is no infinite tableau pathS0, 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 thethree rules above) S0, S1, . . . , Sn with {P} = S0 contains a clash.

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

Logic in Computer Science 31

Page 32: Propositional Logic - Computer Science

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)} issatisfable;

• 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

Page 33: Propositional Logic - Computer Science

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

Page 34: Propositional Logic - Computer Science

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 underwhich P is true, namely I(q) = 1.

Logic in Computer Science 34

Page 35: Propositional Logic - Computer Science

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 =⇒ S′,

where S, S′ 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

Page 36: Propositional Logic - Computer Science

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

Page 37: Propositional Logic - Computer Science

Tableau Path

A sequenceS0, S1, . . . , Sn

of constraints is a tableau path if for any i < n at least one of the followingconditions 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

Page 38: Propositional Logic - Computer Science

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 pathsstarting with P contain a clash), then output “P is not satisfiable”.

Logic in Computer Science 38

Page 39: Propositional Logic - Computer Science

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

Page 40: Propositional Logic - Computer Science

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 forany 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

Page 41: Propositional Logic - Computer Science

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

Page 42: Propositional Logic - Computer Science

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

Page 43: Propositional Logic - Computer Science

Analysing the Tableau Algorithm

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

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

• Soundness: If there exists a complete tableau path S0, S1, . . . , Sn withS0 = {P} without clash, then P is satisfiable.

• Completeness: If P is satisfiable, then there exists a complete tableaupath S0, S1, . . . , Sn with S0 = {P} without clash.

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

Logic in Computer Science 43

Page 44: Propositional Logic - Computer Science

Definitions by structural induction

Many important functions F which have as domain the set of all propositionalformulas 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 shouldbe familar from proofs by induction for natural numbers.)

Logic in Computer Science 44

Page 45: Propositional Logic - Computer Science

Example 1: Interpretations

The definition of interpretations I was given by structural induction. To definean 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 meansof 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

Page 46: Propositional Logic - Computer Science

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

Page 47: Propositional Logic - Computer Science

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

Page 48: Propositional Logic - Computer Science

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

Page 49: Propositional Logic - Computer Science

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

Page 50: Propositional Logic - Computer Science

Proofs by structural induction

Statements about objects defined by structural induction can often be provedby 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

Page 51: Propositional Logic - Computer Science

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

Page 52: Propositional Logic - Computer Science

Termination of the tableau algorithm

Assume P is given. We have to show that there are only finitely many tableaupaths {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 subset of Y .)

Logic in Computer Science 52

Page 53: Propositional Logic - Computer Science

Soundness of the tableau algorithm

Let {P} = S0, S1, . . . , Sn be a complete tableau path such that Sn does notcontain a clash.

We define an interpretation I by

I(pi) =

{1 if pi ∈ Sn

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

Page 54: Propositional Logic - Computer Science

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

Page 55: Propositional Logic - Computer Science

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

Page 56: Propositional Logic - Computer Science

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

Page 57: Propositional Logic - Computer Science

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

Page 58: Propositional Logic - Computer Science

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

Page 59: Propositional Logic - Computer Science

Completeness of the tableau algorithm

Assume that P is satisfiable.

We have to construct a complete tableau path {P} = S0, S1, . . . , Sn such thatSn does not contain a clash.

Let I be an interpretation with I(P ) = 1. We construct the tableau path asfollows: 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 notcontain a clash. If no completion rule is applicable, then the path is completeand we are done.

Now assume that a completion rule is applicable. We show that we can applythe rule in such a way that Si =⇒ Si+1 and I(Q) = 1 for all Q ∈ Si+1.

Logic in Computer Science 59

Page 60: Propositional Logic - Computer Science

Construction of Si+1

1. If P1 ∧P2 ∈ Si and =⇒∧ is applicable, then set Si+1 = Si ∪ {P1, P2}. ThenI(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. ThusI(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

Page 61: Propositional Logic - Computer Science

Construction of Si+1

1. Otherwise, if ¬(P1 ∧ P2) ∈ Si and =⇒¬∧ is applicable, then I(¬P1) = 1 orI(¬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 allQ ∈ Si+1.

2. Otherwise, if (P1 ∨ P2) ∈ Si and =⇒∨ is applicable, then I(P1) = 1 orI(P2) = 1 since I(P1∨P2) = 1. In the first case let Si+1 = Si∪{P1}. In thesecond case let Si+1 = Si ∪ {P2}. In both cases I(Q) = 1 for all Q ∈ Si+1.

Logic in Computer Science 61

Page 62: Propositional Logic - Computer Science

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 the1960s (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

Page 63: Propositional Logic - Computer Science

Tautology

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 ∨ ¬P1 0 10 1 1

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

Logic in Computer Science 63

Page 64: Propositional Logic - Computer Science

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 ∧ ¬P1 0 00 1 0

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

Logic in Computer Science 64

Page 65: Propositional Logic - Computer Science

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 everyinterpretation I:

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

This is denoted byX |= P.

Logic in Computer Science 65

Page 66: Propositional Logic - Computer Science

Example 1

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

Solution:

p1 p2 p1 ∧ p2 p1 ∨ p2

1 1 1 11 0 0 10 1 0 10 0 0 0

The statement follows, because in any row where the column for p1∧p2 contains1 the column for p1 ∨ p2 also contains 1.

Logic in Computer Science 66

Page 67: Propositional Logic - Computer Science

Example 2

Show {p1} 6|= p2.

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

Logic in Computer Science 67

Page 68: Propositional Logic - Computer Science

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

Page 69: Propositional Logic - Computer Science

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

Page 70: Propositional Logic - Computer Science

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: tocheck whether S |= P check that S ∪ {¬P} is not satisfiable.

Logic in Computer Science 70

Page 71: Propositional Logic - Computer Science

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

Page 72: Propositional Logic - Computer Science

Logical equivalence

Definition Two formulas P and Q are called equivalent if they have the sametruth value under every possible interpretation. In other words, P and Q areequivalent 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 checkwhether P ≡ Q check that (P ∧ ¬Q) is not satisfiable and (Q ∧ ¬P ) is notsatisfiable.

Logic in Computer Science 72

Page 73: Propositional Logic - Computer Science

Laws for equivalences

The following equivalences can be checked using the tableau algorithm or bytruth 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

Page 74: Propositional Logic - Computer Science

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

Page 75: Propositional Logic - Computer Science

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

Page 76: Propositional Logic - Computer Science

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} whichcontains 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

Page 77: Propositional Logic - Computer Science

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} whichcontains 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 aclash.

Logic in Computer Science 77

Page 78: Propositional Logic - Computer Science

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 conjunctive normal form (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

Page 79: Propositional Logic - Computer Science

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

Page 80: Propositional Logic - Computer Science

CNF

Theorem (1) Every formula is equivalent to a formula in CNF. (2) Every formula isequivalent to a formula in DNF.

Proof of (1)

Suppose a formula P is given. We transform P to a formula in CNF using theLaws 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

Page 81: Propositional Logic - Computer Science

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