COMP6463 Overview of and Computation: Propositional Logic

Alwen Tiu

The Australian National University

2011

Alwen Tiu (ANU) COMP6463 2011 1 / 35 Outline

Lecture 1 Introduction to propositional logic: syntax and semantics. Lecture 2 Normal forms and the resolution proof method for unsatisfiability checking. Lecture 3 Efficient representation of boolean functions: Binary Decision Diagram (BDD). Lecture 4 Satisfiability checking: the DP and DPLL algorithms. Lecture 5 Methods for validity checking: the tableaux method and the compactness theorem. Slides will be made available at: http://users.rsise.anu.edu.au/~tiu/teaching/comp6463

Alwen Tiu (ANU) COMP6463 2011 2 / 35 References

Most standard textbooks on logic include a chapter on propositional logic,e.g., Michael Huth and Mark Ryan. Logic in Computer Science, Cambridge University Press, 2nd Edition, 2004. A. Aho and J.D. Ullman. Foundations of Computer Science (Chapter 12). Available online for free. http://infolab.stanford.edu/~ullman/focs.html For details of implementation of automated reasoning tools for propositional logic: John Harrison. Handbook of Practical Logic and Automated Reasoning. Cambridge University Press, 2009.

Alwen Tiu (ANU) COMP6463 2011 3 / 35 What is propositional logic?

Propositional logic is concerned with propositions, i.e., statements which can be either true or false, and compositions of their truth values. Atomic propositions can be any sentences, e.g.,

I It is raining. I Joe takes his umbrella. I x < 0. I x = 0. These sentences are considered atomic, i.e., the particular subjects/objects they mention are irrelevant. Atomic sentences are denoted by letters, such as, a, b, c, etc. These are called propositional variables.

Alwen Tiu (ANU) COMP6463 2011 4 / 35 Composing propositions

Atomic propositions can be composed to form complex sentences, e.g., It is raining and Joe takes his umbrella. Or x ≤ 0 or x = 0. We are interested in studying the of the combined propositions, and how their truth can be systematically computed. That is, assuming we know the truth values of atomic propositions, how do we compute or reason about the truth values of their compositions.

Alwen Tiu (ANU) COMP6463 2011 5 / 35 Some problems in propositional logic

The satisfiability (SAT) problem: given a (complex) formula, how do we assign truth values to the atomic propositions in the formula so that the formula becomes true? The validity problem: is a formula always true no matter how we assign truth values to atomic propositions? E.g., statements like “it is raining or it is not raining” is always true. The unsatisfiability problem: converse of the validity problem. Some statements cannot be made true, e.g., logical paradoxes like 1 “The following statement is true”. 2 “The preceding statement is false”.

Alwen Tiu (ANU) COMP6463 2011 6 / 35 Some applications of propositional logic

Propositional logic has many applications in different areas of computer science (apart from digitial circuits design). Complexity: the notion of NP-completeness was motivated by the satisfiability problem. Hardware and software verification: model state transitions of a complex system and its properties as propositional formulae, and use SAT solvers to prove its properties. Automated reasoning: many problems in automated reasoning can be translated into satisfiability problems in propositional logic. Artificial intelligence: knowledge representation, planning and diagnoses.

Alwen Tiu (ANU) COMP6463 2011 7 / 35 Syntax vs Semantics

One important feature of logic is the separation of the form (syntax) of a symbolic expression and its meaning (semantics). Typically, we are concerned with (i) some particular set of allowed formal expressions, and (ii) their corresponding meanings. The two are connected via an :

Interpretation Expression / Meaning

A big part of formal symbolic logic is the study of syntactic manipulation of the forms, independently of the semantics.

Alwen Tiu (ANU) COMP6463 2011 8 / 35 The syntax of propositional logic

Assume a countably infinite set of propositional variables, denoted by lower case letters, e.g., a, b, p, q, etc., representing atomic propositions. The language of formulae is defined inductively as follows:

I > (‘true’) and ⊥ (‘false’) are formulae. I Every propositional variable is a formula (also called an ). I If A is a formula then ¬A (‘not A’) is a formula. I If A and B are formulae then so are: I A ∧ B (A ‘and’ B), I A ∨ B (A ‘or’ B), I and A → B (A ‘implies’ B). A literal is an atomic formula or its , e.g., a, ¬a, c, ¬c, etc. Assume ¬ has the highest precedence, so ¬x ∨ y means (¬x) ∨ y.

Alwen Tiu (ANU) COMP6463 2011 9 / 35 Formulae as an inductive data type

The set of propositional formulae can be defined as an inductive data type in functional programming languages. A typical definition in Haskell-like language would look like this:

data Formula a = False | True | Atom a | Not (Formula a) | And (Formula a) (Formula a) | Or (Formula a) (Formula a) | Imp (Formula a) (Formula a)

Alwen Tiu (ANU) COMP6463 2011 10 / 35 Formulae as expression trees

A formula can also be viewed as a tree whose leaf nodes are propositional variables and ⊥ and >, and whose internal nodes are logical connectives. Example: the expression tree for (p → ¬q) ∨ ⊥

∨ nn @ nn @@ nnn @ nnn @@ nnn @ → n ⊥ ~ AA ~~ AA ~~ AA ~~ AA p ~ ¬

q

Alwen Tiu (ANU) COMP6463 2011 11 / 35 The structural induction principle for formulae

A useful proof principle to prove properties of a formula is by structural induction on the formation of the formula. To prove a property P holds for every formula F : Base cases: prove P for atomic formula, > and ⊥. Inductive cases:

I Assuming P holds for A (the induction hypothesis), show that P holds for ¬A. I Assuming P holds for A and B, show that P holds for A ∧ B, A ∨ B, and A → B.

Alwen Tiu (ANU) COMP6463 2011 12 / 35 Subformulae

A formula A is an immediate subformula of B if one of the following holds:

I B is ¬A; I B is A ∧ C, or C ∧ A, or A ∨ C, or C ∨ A, A → C or C → A, for some formula C. We write A ≺ B if A is an immediate subformula of B. Let ≺∗ be the transitive closure of ≺ . We say that A is a subformula of B if A ≺∗ B. View as expression trees, A is a subformula of B if A appears as a subtree in B.

Alwen Tiu (ANU) COMP6463 2011 13 / 35 Strong induction principle

Just as induction on natural numbers, we also have a strong induction principle on formulae, using the subformula relation. To prove a property P holds for every formula F : Base cases: if F is either an atomic formula or > or ⊥, then prove P for F directly. Inductive cases: otherwise, assuming P holds for every A such that A ≺∗ F , show that P holds for F .

Alwen Tiu (ANU) COMP6463 2011 14 / 35 Semantics

The meaning of a is simply true or false. The truth value of a formula depends on the interpretation of its propositional variables (as truth values). A boolean is a function from the set of propositional variables to truth values, i.e., the set {0, 1} (denoting ‘false’ and ‘true’). Given a boolean valuation M and a formula F , we write

M |= F

to denote that M is true under the valuation M, and

M 6|= F

if F is false under the valuation M.

Alwen Tiu (ANU) COMP6463 2011 15 / 35 Semantics

The relation |= is defined inductively on the structure of formulae as follows: M |= > ; M 6|= ⊥. M |= p iff (if and only if) M(p) = 1. M |= ¬A iff M 6|= A. M |= A ∧ B iff M |= A and M |= B. M |= A ∨ B iff M |= A or M |= B. M |= A → B iff M 6|= A or M |= B.

When M |= F holds, we say that M is a model for F .

Alwen Tiu (ANU) COMP6463 2011 16 / 35 Finite model property

Let Var(F ) bet the set of propositional variables in F . Then the truth value of F is dependent only on the valuations of Var(F ). Lemma

Let F be a formula and let M1 and M2 be two boolean valuations such that M1(p) = M2(p) for every p ∈ Var(F ). Then M1 |= F if and only if M2 |= F .

Proof. Exercise: prove by structural induction on F .

A consequence of this is that we can represent finitely all models of F .

Alwen Tiu (ANU) COMP6463 2011 17 / 35 Representing models of a formula

Since the truth value of a formula F depends only on the valuation of its propositional variables, a model M of F can be represented by listing the finite mappings on Var(F ). For example, if F = (a ∧ b) ∨ (c → d) then

M = {a 7→ 0, b 7→ 1, c 7→ 1, d 7→ 1}

is a model of F .

Alwen Tiu (ANU) COMP6463 2011 18 / 35 Boolean functions and truth tables

An easy way to characterise the semantics of logical connectives is to view them as boolean functions. A boolean variable x is a variable ranging over {0, 1}. We use x, y, z, possibly with subscripts, to denote boolean variables. So a propositional variable is a boolean variable. A f of n arguments is a function from {0, 1}n to {0, 1}. A boolean function can be defined via a truth table:

I the columns correspond to the variables and the output of the function, I the rows of the tables correspond to all possible combination of input and their output.

Alwen Tiu (ANU) COMP6463 2011 19 / 35 Truth tables for standard connectives The meaning of propositional connectives can be represented using truth tables.

x y (x ∧ y) x y (x ∨ y)

0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 x y (x → y) x ¬x 0 0 1 0 1 1 0 1 1 0 0 1 0 1 1 1

Alwen Tiu (ANU) COMP6463 2011 20 / 35 Truth tables of a compound formula

To build a truth table for a complex formula: add one column for each each subformula, starting from the smallest one, calculate its value from its immediate subformulae. Example: the truth table for ¬x ∧ (x ∨ y).

x y ¬x (x ∨ y) ¬x ∧ (x ∨ y)

0 0 1 0 0 01111 1 0 0 1 0 1 1 0 1 0 Notice that the row where the entry in the last column is 1 corresponds to the model of the formula, i.e.,

M = {x 7→ 0, y 7→ 1}.

Alwen Tiu (ANU) COMP6463 2011 21 / 35 Satisfiability and validity

An important question in propositional logic, and logic in general, is under what valuation a formula is true (or false). A formula F is satisfiable if it has a model, i.e., there exists a boolean valuation M such that M |= F . It is unsatisfiable if it has no model. A formula F is valid if it is true under all boolean valuation. Valid formulae are also called tautologies. Duality in logic: a formula F is valid if and only if ¬F is unsatisfiable. Validity and (un)satisfiability of a formula can be (inefficiently) checked using truth tables.

Alwen Tiu (ANU) COMP6463 2011 22 / 35 Example: satisfiability via truth tables Consider the formula: (p → q) → r. Its truth table is:

p q r (p → q)(p → q) → r

0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 1 1 1 1

A formula is satisfiable if its truth table has at least a ‘1’ in its last column. The valuations in the rows ending with a ‘1’ are models of the formula, e.g., the second row gives the model:

{p 7→ 0, q 7→ 0, r 7→ 1}.

Alwen Tiu (ANU) COMP6463 2011 23 / 35 Example: validity via truth tables

A formula is valid if the entries in the last column in its truth table are all ‘1’. For example, the formula p → (q → p) is valid:

p q (q → p) p → (q → p)

0 0 1 1 0 1 0 1 1 0 1 1 1 1 1 1

Alwen Tiu (ANU) COMP6463 2011 24 / 35 Example: logical paradoxes

Consider the following two statements:

s1 The following statement is true.

s2 The preceding statement is false. Encode these as a propositional logic formula and show that it is unsatisfiable.

Alwen Tiu (ANU) COMP6463 2011 25 / 35 Closure under substitutions

A useful property of valid formulae is that they remain valid if we uniformly replace one of its variables with an arbitrary formulae. Example: x ∨ ¬x is valid. If we replace x with (y ∨ z) then

(y ∨ z) ∨ ¬(y ∨ z)

is also valid. Exercise: prove that validity is closed under substitutions. Exercise: is satisfiability closed under substitutions?

Alwen Tiu (ANU) COMP6463 2011 26 / 35 Logical equivalence

A particular class of useful tautologies involves logical equivalence. Logical equivalence between two formulae A and B, written with A ≡ B, is defined as

(A → B) ∧ (B → A).

That is, A ≡ B is valid if and only if the above formula is valid. View as boolean functions, A ≡ B iff they A and B both represent the same function, i.e., they have identical truth tables.

Alwen Tiu (ANU) COMP6463 2011 27 / 35 Example: logical equivalence via truth tables

(x ∧ y) ≡ (y ∧ x), as can be seen from the following truth table:

x y (x ∧ y)(y ∧ x)

0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1

Alwen Tiu (ANU) COMP6463 2011 28 / 35 Some useful tautologies

Units: A ∧ > ≡ AA ∨ > ≡ > A ∧ ⊥ ≡ ⊥ A ∨ ⊥ ≡ A A ∨ ¬A ≡ > A ∧ ¬A ≡ ⊥ Idempotency: A ∧ A ≡ AA ∨ A ≡ A Commutativity: A ∧ B ≡ B ∧ AA ∨ B ≡ B ∨ A Associativity: A ∧ (B ∧ C) ≡ (A ∧ B) ∧ C A ∨ (B ∨ C) ≡ (A ∨ B) ∨ C Distributivity: A ∨ (B ∧ C) ≡ (A ∨ B) ∧ (A ∨ C) A ∧ (B ∨ C) ≡ (A ∧ B) ∨ (A ∧ C) Implication: A → B ≡ ¬A ∨ B de Morgan: ¬¬A ≡ A ¬(A ∧ B) ≡ ¬A ∨ ¬B ¬(A ∨ B) ≡ ¬A ∧ ¬B

Notation Because ∧ and ∨ are associative, we will omit parentheses when writing a series of conjuction/disjunction, e.g., instead of writing (a ∧ b) ∧ (c ∧ d) we simply write a ∧ b ∧ c ∧ d.

Alwen Tiu (ANU) COMP6463 2011 29 / 35 Reasoning with logical equivalence

Logical equivalence can be used to transform formula into equivalent ones. This is similar to equational reasoning in algebra: replace a (sub)formula with its logically equivalent one. Example: we can prove (A ∧ B) ≡ ¬(¬A ∨ ¬B) as follows

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

To prove that a formula F is valid, show that it can be transformed to > using logical equivalence.

Alwen Tiu (ANU) COMP6463 2011 30 / 35 Representing boolean functions as propositional formulae

There are 22n different boolean functions over n variables.

Every boolean function f (x1,..., xn) can be represented as a formula: Consider a representation of f as a truth table.

I For every row i in which the last entry is 1, form a formula Ci = l1 ∧ · · · ∧ ln where lj = xj if xj = 1, and lj = ¬xj , otherwise. 0 I Take the disjunction of all Ci s produced in the first step (if there are none then it’s ⊥). The resulting formula is a representation of f . Note that a boolean function may have more than one formula representation.

Alwen Tiu (ANU) COMP6463 2011 31 / 35 Example Consider a boolean function f of three arguments, defined below:

x y z f (x, y, z)

0 0 0 0 0011 0 1 0 0 0111 1 0 0 0 1 0 1 0 1101 1 1 1 0

It can be represented as the formula:

(¬x ∧ ¬y ∧ z) ∨ (¬x ∧ y ∧ z) ∨ (x ∧ y ∧ ¬z).

Alwen Tiu (ANU) COMP6463 2011 32 / 35 Complete set of connectives

The choice of {¬, ∨, ∧, →} as the basis for propositional logic is more or less driven by the development of philosophical logic. From a mathematical point of view, one can choose a different set of unary/binary connectives, provided we can show a certain ‘completeness’ property. A set of logical connectives S is complete if every boolean function of n variables can be represented as a formula using only those variables, >, ⊥ and connectives in S. Example: {¬, ∨, ∧} is a complete set of connectives, because we can represent truth tables using those connectives.

Alwen Tiu (ANU) COMP6463 2011 33 / 35 Example: complete sets of connectives

The set {¬, ∨} is complete, and so is {¬, ∧}. This is because ∨ can be expressed as ¬ and ∧, and ∧ can be expressed as ¬ and ∨. Define a binary connective ↑ as follows:

x y x ↑ y

0 0 1 0 1 0 1 0 0 1 1 0

Then the set {↑} is also complete, because we can encode ¬ and ∨:

¬x ≡ (x ↑ x)(x ∨ y) ≡ (x ↑ y) ↑ (x ↑ y).

Alwen Tiu (ANU) COMP6463 2011 34 / 35 Example: non-complete sets of connectives

Proving that a set of connectives is not complete is generally harder, and require the induction principles. Exercise: Prove that {∨, ∧} is not complete. Define ⊕ as follows: x y x ⊕ y

0 0 0 0 1 1 1 0 1 1 1 0 Exercise: Prove that {⊕} is not complete.

Alwen Tiu (ANU) COMP6463 2011 35 / 35