propositional calculus: boolean algebra and...

24
Propositional Calculus: Boolean Algebra and Simplification CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Upload: lamtruc

Post on 08-Jun-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Propositional Calculus:Boolean Algebra and

Simplification

CS 270: Mathematical Foundations of Computer Science

Jeremy Johnson

Page 2: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Propositional Calculus

TopicsMotivation: Simplifying Conditional

ExpressionsRules of Boolean AlgebraEquational ReasoningProofs Using Truth TablesTautologies and Automatic Verification of

TautologiesArguments, Satisfiability and Truth Trees

Page 3: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

3

Programming Example Boolean expressions arise in conditional statements. It is

possible to abstract the relations with boolean variables (propositions that are either true or false). Using this abstraction one can reason and simplify conditional statements.

if ((a < b) || ((a >= b) && (c == d))) then { … } else { … } Let p denote the relation (a<b) and q denote the relation

(c == d). The above expression is then equal to

p || !p && q

Page 4: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

4

Programming Example (cont) The previous expression is equivalent (two expressions are

equivalent if they are true for the same values of the variables occurring in the expressions) to a simpler expression

(p || !p && q) ≡ p || q

We can see this since if p is true both expressions are true, and if p is false, then !p is true and (!p && q) is true exactly when q is true.

Page 5: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Boolean Algebra

The Boolean operators ∨ and ∧ are analogous to addition and multiplication with true and false playing the roles of 1 and 0. Complement is used for negation.

This provides a compact notation and suggests appropriate algebraic simplification

Similar properties hold such as the associative, commutative, and distributive identities.

Page 6: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

6

Sums of Products Disjunctive normal form, using the notation of

Boolean Algebra, corresponds to a sum of products

E.G. (multiplexor function)

s x0 x1 f

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Page 7: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Properties of Boolean Algebra Boolean expressions can be simplified using rules of Boolean

algebra Identity law: A + 0 = A and A ● 1 = A. Zero and One laws: A + 1 = 1 and A ● 0 = 0 Inverse laws: Idempotent laws: A + A = A = A ● A Commutative laws: A + B = B + A and A ● B = B ● A. Associative laws:A + (B + C) = (A + B) + C and A ● (B ● C) = (A ● B) ● C. Distributive laws: A ● (B + C) = (A ● B) + (A ● C) and

A + (B ● C) = (A + B) ● (A + C)

Double Negation: ̅�̅�𝐴 = 𝐴𝐴 DeMorgan’s laws:

Page 8: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

8

Simplification of Boolean Expressions

Simplifying multiplexor expression using Boolean algebra

Equational reasoning: replace subexpressions by equivalent expressions Reflexive, Symmetric, Transitive

Verify that the boolean function corresponding to this expression as the same truth table as the original function.

Page 9: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

9

Logic CircuitsGiven a boolean expression it is easy to write

down the corresponding logic circuitHere is the circuit for the original multiplexor

expression

x0

x1

s

Page 10: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

10

Logic Circuits

Here is the circuit for the simplified multiplexor expression

x0

x1

s

Page 11: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Nand is functionally complete

Using DeMorgan’s Law, ¬ and ∧ are enough to generate all Boolean functionsAll boolean functions can be implemented

using nand gates (and, or and not can be implemented using nand)not:

and:

or:

x y x | y

0 0 1

0 1 1

1 0 1

1 1 0

Page 12: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

12

Conjunctive Normal FormConjunctive normal form (products of

sums) Conjunction of clauses (disjunction of literals)

For each row in the truth table where the output is false, write a sum such that the corresponding input not in that row Alternatively use Demorgan’s law for the

negation of dnf for ¬f (zero rows) Duality (swap and/or true/false)

E.G. (multiplexor function)(𝑠𝑠 + 𝑥𝑥0 + 𝑥𝑥1)⋅(𝑠𝑠 + 𝑥𝑥0 + 𝑥𝑥1)⋅(�̅�𝑠 + 𝑥𝑥0 + 𝑥𝑥1)⋅ (�̅�𝑠 +𝑥𝑥0 + 𝑥𝑥1)

s x0 x1 f

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Page 13: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

13

Additional Notation Several additional Boolean functions of two variables have

special meaning and are given special notation. By our previous results we know that all boolean functions can be expressed with not, and, and or; so the additional notation is simply a convenience.

x y x → y

0 0 1

0 1 1

1 0 0

1 1 1

implication

x y x ≡ y

0 0 1

0 1 0

1 0 0

1 1 1

equivalence

x y x ⊕ y

0 0 0

0 1 1

1 0 1

1 1 0

xor

Page 14: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

14

TautologiesA tautology is a boolean expression that is always

true, independent of the values of the variables occurring in the expression. The properties of Boolean Algebra are examples of tautologies.

Tautologies can be verified using truth tables. The truth table below shows that x → y ≡ ¬ x ∨ y

x y x → y ¬ x ∨ y

0 0 1 1

0 1 1 1

1 0 0 0

1 1 1 1

Page 15: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

15

Exercise

Derive the tautology x → y ≡ ¬ x ∨ yfrom the sum of products expression obtained from the truth table for x → y. You will need to use properties of Boolean algebra to simplify the sum of products expression to obtain the desired equivalence.

Page 16: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

16

Solution

Derive the tautology x → y ≡ ¬ x ∨ y

𝑥𝑥 → 𝑦𝑦 ≡ (¬𝑥𝑥 ∧ ¬𝑦𝑦) ∨ ¬𝑥𝑥 ∧ 𝑦𝑦 ∨ 𝑥𝑥 ∧ 𝑦𝑦≡ (¬𝑥𝑥 ∧ ¬𝑦𝑦) ∨ (¬𝑥𝑥 ∧ 𝑦𝑦) ∨ ¬𝑥𝑥 ∧ 𝑦𝑦 ∨ 𝑥𝑥 ∧ 𝑦𝑦≡ ¬𝑥𝑥 ∧ (¬𝑦𝑦 ∨ 𝑦𝑦) ∨ ¬𝑥𝑥 ∨ 𝑥𝑥 ∧ 𝑦𝑦≡ (¬𝑥𝑥 ∧ 𝑇𝑇) ∨ (𝑇𝑇 ∧ 𝑦𝑦)≡ ¬𝑥𝑥 ∨ 𝑦𝑦

x y x → y

0 0 1

0 1 1

1 0 0

1 1 1

Page 17: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

17

Tautology Checker A program can be written to check to see if a Boolean

expression is a tautology.

Simply generate all possible truth assignments for the variables occurring in the expression and evaluate the expression with its variables set to each of these assignments. If the evaluated expressions are always true, then the given Boolean expression is a tautology.

A similar program can be written to check if any two Boolean expressions E1 and E2 are equivalent, i.e. if E1 ≡ E2. Such a program will be written later in the term.

Page 18: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Satisfiability

A formula is satisfiable if there is an assignment to the variables that make the formula true

A formula is falsifiable if there is an assignment to the variables that make the formula false

A formula is contradictory if all assignments to variables eval to false

A formula is valid if all assignments to variables eval to true (a valid formula is a tautology)

The negation of a valid formula is not satisfiable A formula is invalid if there is an assignment to

variables that eval to false (counterexample)

Page 19: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Satisfiability

Checking to see if a formula f is satisfiable can be done by searching a truth table for a true entry or truth tree construction Exponential in the number of variables Does not appear to be a polynomial time algorithm

(satisfiability is NP-complete) There are efficient satisfiability checkers that work

well on many practical problems

Checking whether f is invalid can be done by checking if ¬ f is satisfiable. An assignment that makes ¬ f satisfiable provides a counterexample

Page 20: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Arguments

An argument is a list of premises followed by a conclusion ϕ1,…,ϕn ∴ψ

An argument is valid if any assignment that makes the premises true also makes the conclusion true

An argument is invalid if there is some assignment that makes the premises true but does not make the conclusion true If we negate the conclusion we can search for counterexamples

by looking for an assignment that makes the premises and negated conclusion true

Page 21: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Arguments and Formulas

An argument

ϕ1,…,ϕn ∴ψ

is valid if and only if the formula

(ϕ1 ∧ … ∧ ϕn)→ψ

is a tautology

Page 22: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Truth Tree Construction

• ϕ ∧ ψ

• ϕ ∨ ψ

• ϕ→ ψ

(ϕ ∧ ψ) ϕψ

(ϕ ∨ ψ)

ϕ ψ

(ϕ → ψ)

¬ϕ ψ

Page 23: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Truth Tree Construction

• ¬(ϕ ∧ ψ)

• ¬(ϕ ∨ ψ)

• ¬(ϕ→ ψ)

• ¬ ¬ ϕ

¬(ϕ ∧ ψ)

¬ϕ ¬ψ

¬(ϕ ∨ ψ) ¬ϕ¬ψ

¬(ϕ → ψ) ϕ

¬ψ

¬¬ϕ ϕ

Page 24: Propositional Calculus: Boolean Algebra and Simplificationjjohnson/2016-17/fall/CS270/Lectures/3/BoolAlg.pdf · Conjunctive Normal Form Conjunctive normal form (products of sums)

Example Truth Tree