propositional calculus - drexel universitykschmidt/cs270/lectures/5/5.pdf · propositional calculus...

63
Propositional Calculus Math Foundations of Computer Science

Upload: doandiep

Post on 07-Mar-2018

226 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Propositional Calculus

Math Foundations of Computer Science

Page 2: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

2

Propositional Calculus Objective: To provide students with the

concepts and techniques from propositional calculus so that they can use it to codify logical statements and to reason about these statements. To illustrate how a computer can be used to carry out formal proofs and to provide a framework for logical deduction.

Page 3: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Propositional Calculus

Topics Motivation Boolean functions and expressions Rules of Boolean Algebra Logic Minimization Tautologies and automatic verification of

tautologies Satisfiability Propositional calculus in ACL2 Application to Circuit Design

Page 4: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Readings

Chapter 2 “Propositional Logic,” in Reasoning About Programs, P. Manolios

Chapters 12 and 13 from Aho and Ullman Optional Electronic text on “Logic and

Proofs” Sign up at oli.cmu.edu (online learning

initiative) Part of the course and logic tutors are

available for free, the full course has a fee of $40 (Course key drexelandp)

Page 5: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Word Problem

Tom likes Jane if and only if Jane likes Tom. Jane likes Bill. Therefore, Tom does not like Jane. Let p denote “Tom likes Jane” Let q denote “Jane likes Tom” Let r denote “Jane likes Bill” ((p ≡ q) ∧ r)→ ¬p encodes the above claim The claim is not valid as the assignment p =

true, q = true, and r = true evaluates to false

Page 6: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

6

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 7: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

7

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 8: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

8

Limitations of Propositional Calculus

Propositions hide the information in the predicates they abstract.

Sometimes properties of the hidden information is required to make further deductions.

E.G. for integers a,b, and c, (a < b) && (b < c) implies that a < c; however, this can not be deduced without using the order properties of the integers.

The predicate calculus allows the use of predicates to encode this additional information.

E.G. we can introduce a parameterized predicate lt(a,b) to encode the predicate a < b. Properties such as lt(a,b) && lt(b,c) ≡ lt(a,c) can be asserted. This type of notation and deduction is called predicate calculus and will be discussed later.

Page 9: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

9

Boolean Functions A Boolean variable has

two possible values (true/false) (1/0).

A Boolean function has a number of Boolean input variables and has a Boolean valued output.

A Boolean function can be described using a truth table.

There are 22n Boolean function of n variables.

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

f

x0

x1

s

Multiplexor function

Page 10: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

10

Boolean Expressions

An expression built up from variables, and, or, and not.

x y x ∧ y

0 0 0

0 1 0

1 0 0

1 1 1

x y x ∨ y

0 0 0

0 1 1

1 0 1

1 1 1

x ¬x

0 1

1 0

and or not

Page 11: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

11

Boolean Expressions

BExpr := Constant: T|F [t | nil] Variable [symbol] Negation: ¬ BExpr [(not BExpr)] And: BExpr ∧ BExpr [(and BExpr BExpr) Or: BExpr ∨ Bexpr [(or BExpr BExpr)]

Page 12: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Expression Trees

Boolean expressions can be represented by a binary tree

Internal nodes are operators Leaf nodes are operands Consider p ∧ (1 ∨ ¬ q):

p ∨

1 ¬

q

Page 13: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Evaluation (defun bool-eval (expr env)

(cond

( (is-constant expr) expr )

( (is-variable expr) (lookup expr env) )

( (is-not expr) (not (bool-eval (op expr) env)) )

( (is-or expr) (or (bool-eval (op1 expr) env) (bool-eval (op2 expr) env)) )

( (is-and expr) (and (bool-eval (op1 expr) env) (bool-eval (op2 expr) env)) )

))

Page 14: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Short Circuit Evaluation (defun sc-eval (expr env)

(cond

( (is-constant expr) expr )

( (is-variable expr) (lookup expr env) )

( (is-not expr) (not (sc-eval (op expr) env)) )

( (is-or expr) (if (sc-eval (op1 expr) env) t (sc-eval (op2 expr) env) ) )

( (is-and expr) (if (sc-eval (op1 expr) env) (sc-eval (op2 expr) env) nil ) )

))

Page 15: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

If-then-else The ternary boolean

function ite(p,q,r) can be used to represent ¬, ∨, and ∧ ¬p ≡ ite(p,0,1) p ∨ q ≡ ite(p,1,q) p ∧ q ≡ ite(p,q,0)

p q r ite(p,q,r)

0 0 0 0

0 0 1 1

0 1 0 0

0 1 1 1

1 0 0 0

1 0 1 0

1 1 0 1

1 1 1 1

Page 16: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Conversion to ite Expression

Any Boolean expression can be converted to an equivalent expression using ite

(bool-eval expr env) ≡ (ite-eval (bool2ite expr) env)

p ∨

1 ¬

q

ite

p

1

q

ite

ite

0

1

0 1

Page 17: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

bool2ite (defun bool2ite (expr)

(cond

( (is-constant expr) expr )

( (is-variable expr) expr )

( (is-not expr) (list 'ite (bool2ite (op1 expr)) nil t) )

( (is-or expr) (list 'ite (bool2ite (op1 expr))

t (bool2ite (op2 expr))) )

( (is-and expr) (list 'ite (bool2ite (op1 expr))

(bool2ite (op2 expr)) nil) )

)

)

Page 18: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Ite-eval (defun ite-eval (expr env)

(cond

( (is-constant expr) expr )

( (is-variable expr) (lookup expr env) )

( (is-ite expr) (if (ite-eval (op1 expr) env)

(ite-eval (op2 expr) env)

(ite-eval (op3 expr) env)) )

)

)

Page 19: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Equivalence of Conversion

Want to prove that (bool-eval expr env) = (ite-eval (bool2ite expr) env)

Lemma ite 1. ¬p ≡ ite(p,0,1) 2. p ∨ q ≡ ite(p,1,q) 3. p ∧ q ≡ ite(p,q,0)

p q ite(p,0,1) ¬p ite(p,1,q) p ∨ q ite(p,q,0) p ∧ q

0 0 1 1 0 0 0 0

0 1 1 1 1 1 0 0

1 0 0 0 1 1 0 0

1 1 0 0 1 1 1 1

Page 20: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Equivalence of Conversion

(bool-eval expr env) = (ite-eval (bool2ite expr) env)

Proof by induction on expr using Lemma ite [Base case] constant or variable. In this case

(bool2ite expr) = expr and bool-eval and ite-eval return the same thing

Page 21: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Equivalence of Conversion

[Not] Assume (bool-eval expr1 env) = (ite-eval (bool2ite expr1)) (ite-eval (bool2ite ‘(not expr1)) env) = (ite-eval ‘(ite (bool2ite expr1) nil t) env) [by def of

bool2ite] = (not (ite-eval (bool2ite expr1) env)) [by Lemma ite

part 1] = (not (bool-eval expr1 env)) [by IH] = (bool-eval ‘(not expr1) env) [by def of bool-eval]

Page 22: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Equivalence of Conversion

[Or] Assume (bool-eval expr1 env) = (ite-eval (bool2ite expr1)) and (bool-eval expr2 env) = (ite-eval (bool2ite expr2)) (ite-eval (bool2ite ‘(or expr1 expr2)) env) = (ite-eval ‘(ite (bool2ite expr1) t (bool2ite expr2)) env)

[by def of bool2ite] = (or (ite-eval (bool2ite expr1) env) (ite-eval (bool2ite

expr2) env)) [by Lemma ite part 2] = (or (bool-eval expr1 env) (bool-eval expr2 env)) [by

IH] = (bool-eval ‘(or expr1 expr2) env) [by def of bool-eval]

Page 23: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Equivalence of Conversion

[And] Assume (bool-eval expr1 env) = (ite-eval (bool2ite expr1)) and (bool-eval expr2 env) = (ite-eval (bool2ite expr2)) (ite-eval (bool2ite ‘(and expr1 expr2)) env) = (ite-eval ‘(ite (bool2ite expr1) (bool2ite expr2) nil)

env) [by def of bool2ite] = (and (ite-eval (bool2ite expr1) env) (ite-eval (bool2ite

expr2) env)) [by Lemma ite part 3] = (and (bool-eval expr1 env) (bool-eval expr2 env)) [by

IH] = (bool-eval ‘(and expr1 expr2) env) [by def of bool-

eval]

Page 24: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Exercise

Implement a recursive function to convert ite expressions to boolean expressions (ite2bool iexpr) Use and define the following helper functions (is-ite expr)

Check for ‘(ite … )

(is-itenot iexpr) Check for ‘(ite iexpr nil t)

(is-iteor iexpr) Check for ‘(ite iexpr t iexpr)

(is-iteand iexpr) Check for ‘(ite iexpr iexpr nil)

Page 25: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution (defun is-itenot (iexpr) (and (equal (op2 iexpr) nil) (equal (op3 iexpr) t))) (defun is-iteor (iexpr) (equal (op2 iexpr) t)) (defun is-iteand (iexpr) (equal (op3 iexpr) nil))

Page 26: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution (defun ite2bool (iexpr) (cond ( (is-constant iexpr) iexpr ) ( (is-variable iexpr) iexpr ) ( (is-ite iexpr) (cond ( (is-itenot iexpr) (list 'not (ite2bool (op1 iexpr))) ) ( (is-iteor iexpr) (list 'or (ite2bool (op1 iexpr)) (ite2bool (op3 iexpr))) ) ( (is-iteand iexpr) (list 'and (ite2bool (op1 iexpr)) (ite2bool (op2 iexpr))) ) ))))

Page 27: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution Remark

Note that there is one overlap in Not (ite p nil t) Or (ite p t q) And (ite p q nil) (ite p t nil) = (and p t) = (or p nil) = p

This implies (ite2bool (bool2ite ‘(and p t)) = (or p t) not equal to the initial expression

However, (ite2bool (bool2ite expr)) ≡ expr, i.e. (booleval expr) = (ite2bool (bool2ite expr))

Page 28: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Correctness of ite2bool

Use induction to prove (equiv (ite2bool (bool2ite expr)) expr) Base case: expr is a constant or variable (not expr) (or expr1 expr2) (and expr1 expr2)

Page 29: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution

Show (equiv (ite2bool (bool2ite expr)) expr) Base case: if expr is a constant or variable then

(ite2bool (bool2ite expr)) = (ite2bool expr) = expr [by def]

[Not] Assume (equiv (ite2bool (bool2ite expr)) expr) (ite2bool (bool2ite (not expr))) = (ite2bool (list ‘ite (bool2ite expr) nil t))) [by def b2ite] = (not (ite2bool (bool2ite expr))) [by def ite2bool and

Lemma ite ] ≡ (not expr) [by IH]

Page 30: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution

[Or] Assume (equiv (ite2bool (bool2ite expr1)) expr1) and (equiv (ite2bool (bool2ite expr2) expr2) (ite2bool (bool2ite (or expr1 expr2))) = (ite2bool (list ‘ite (bool2ite expr1) t (bool2ite

expr2))) [by def of bool2ite] = (or (ite2bool (bool2ite expr1)) (ite2bool

(bool2ite expr2))) [by def of ite2bool and Lemma ite]

≡ (or expr1 expr2) [by IH]

Page 31: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Solution

[And] Assume (equiv (ite2bool (bool2ite expr1)) expr1) and (equiv (ite2bool (bool2ite expr2) expr2) (ite2bool (bool2ite (and expr1 expr2))) = (ite2bool (list ‘ite (bool2ite expr1) (bool2ite

expr2) nil)) [by def of bool2ite] ≡ (and (ite2bool (bool2ite expr1)) (ite2bool

(bool2ite expr2))) [by def of ite2bool and Lemma ite]

≡ (and expr1 expr2) [by IH]

Page 32: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

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 33: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

33

Boolean Expressions A Boolean expression is a Boolean function Any Boolean function can be written as a Boolean

expression Disjunctive normal form (sums of products) For each row in the truth table where the output is true,

write a product such that the corresponding input is the only input combination that is true

Not unique

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 34: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

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) DeMorgan’s laws:

The reason for simplifying is to obtain shorter expressions, which we will see leads to simpler logic circuits.

Page 35: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

35

Simplification of Boolean Expressions

Simplifying multiplexor expression using Boolean algebra

Verify that the boolean function corresponding to this

expression as the same truth table as the original function.

Page 36: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Simplifying Expression Trees

Constant folding

p ∨

1 ¬

q

p 1

p

Page 37: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Assignment Implement and test (bool-simp expr) (bool-simp expr) returns a simplified boolean

expression using the following simplifications 1. evaluate all constant subexpressions

2. (not (not expr)) -> expr

3. (and t expr) -> expr

4. (and expr t) -> expr

5. (and nil expr) -> nil

6. (and expr nil) -> nil

7. (or t expr) -> t

8. (or expr t) -> t

9. (or nil expr) -> expr

10. (or expr nil) -> expr

Page 38: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Assignment

Simplification (2) is done through the helper routine not-simp. Simplifications (3)-(6) are done through the helper routine and-simp. Simplifications (7)-(10) are done through the helper routine or-simp.

bool-simp traverses the boolean expression and recursively simplifies all operands to not, or and and and calls the appropriate helper routineto perform operator specific simplifiations and constant evaluation.

Page 39: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Assignment

Prove the following lemmas 1. (bool-eval '(not expr) env) = (bool-eval (not-

simp expr) env) 2. (bool-eval '(and expr1 expr2) env) = (bool-eval

(and-simp expr1 expr2) env) 3. (bool-eval '(or expr1 expr2) env) = (bool-eval

(or-simp expr1 expr2) env) 4. (bool-eval expr env) = (bool-eval (bool-simp

expr) env)

Page 40: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Assignment

Prove using induction on expr that (bool-eval expr env) = (bool-eval (bool-simp

expr) env) Prove by induction that (bool-simp expr) Has no double negations Is either a constant or an expression with no

constants Write an is-simplified function to test whether the

output of (bool-simp expr) satisfies this property

Page 41: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

41

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

Page 42: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

42

Tautologies A 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 43: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

43

Exercise

Derive the tautology x → y ≡ ¬ x ∨ y from 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 44: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

44

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 has been provided.

Page 45: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Satisfiability

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

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

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

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

Page 46: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Satisfiability

Checking to see if a formula f is satisfiable can be done by searching a truth table for a true entry 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 satisfiable can be done by checking if ¬ f is a tautology

An assignment that evaluates to false provides a counter example to validity

Page 47: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Propositional Logic in ACL2

In beginner mode and above ACL2S B !>QUERY

(thm (implies (and (booleanp p) (booleanp q))

(iff (implies p q) (or (not p) q))))

<< Starting proof tree logging >>

Q.E.D.

Summary

Form: ( THM ...)

Rules: NIL

Time: 0.00 seconds (prove: 0.00, print: 0.00, proof tree: 0.00, other: 0.00)

Proof succeeded.

Page 48: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Propositional Logic in ACL2 ACL2 >QUERY

(thm (implies (and (booleanp p) (booleanp q))

(iff (xor p q) (or p q))))

**Summary of testing**

We tested 500 examples across 1 subgoals, of which 1 (1 unique) satisfied

the hypotheses, and found 1 counterexamples and 0 witnesses.

We falsified the conjecture. Here are counterexamples:

[found in : "Goal''"]

(IMPLIES (AND (BOOLEANP P) (BOOLEANP Q) P) (NOT Q))

-- (P T) and (Q T)

Page 49: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

49

Karnaugh Map A Karnaugh map is a two dimensional version of a

truth table. It can be used to simplify Boolean expressions expressed as sums of products.

y=0 y=1

x=0 1 1

x=1 0 1

This example shows the Karnaugh table for the truth table defining implication. There is a 1 in each box corresponding to each value of p and q where x → y is true and a 0 where it is false.

Page 50: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

50

Logic Minimization We want a sum of products that is true for all of the

boxes with 1’s (a cover). One such cover is obtained using a product for each individual box. A simpler expression can be obtained using the literals !x and y which cover the first row and the second column respectively.

This shows that x → y ≡ ¬ x ∨ y This can be generalized to more the one variable (Sec.

12.5)

Page 51: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

51

Logic Circuits A single line labeled x is a logic circuit. One end is the input

and the other is the output. If A and B are logic circuits so are:

and gate or gate inverter (not)

A B

A

A B

Page 52: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

52

Logic Circuits Given a boolean expression it is easy to write

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

expression

x0

x1

s

Page 53: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

53

Logic Circuits

Here is the circuit for the simplified multiplexor expression

x0

x1

s

Page 54: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

54

Nand Nand – negation of the conjunction

operation: A nand gate is an inverted and gate:

x y x | y

0 0 1

0 1 1

1 0 1

1 1 0

Page 55: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

Nand is functionally complete

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

Page 56: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

56

Decoder A decoder is a logic circuit that has n inputs (think of

this as a binary number) and 2n outputs. The output corresponding to the binary input is set to 1 and all other outputs are set to 0.

d0

d1

d2

d3

b0

b1

Page 57: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

57

Encoder An encoder is the opposite of a decoder. It is

a logic circuit that has 2n inputs and n outputs. The output equal to the input line (in binary) that is set to 1 is set to 1.

d0

d1

d2

d3

b0

b1

Page 58: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

58

Multiplexor A multiplexor is a switch which routes n

inputs to one output. The input is selected using a decoder.

d0

d1

d2

d3

s0 s1

Page 59: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

XOR

“One or the other, but not both”

Notation for circuits:

x y

x y x ⊕ y

0 0 0

0 1 1

1 0 1

1 1 0

Page 60: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

60

Exercise Derive a truth table for the output bits (Sum and

CarryOut) of a full adder. Using the truth table derive a sum of products

expression for Sum and CarryOut. Draw a circuit for these expressions.

Using properties of Boolean algebra and Karnaugh Maps to simplify your expressions. Draw the simplified circuits.

Sum

CarryIn

CarryOut

a

b

Page 61: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

61

Solution Derive a truth table for the output bits (Sum and

CarryOut) of a full adder.

𝑠 = 𝑎�𝑏�𝑐𝑖 + 𝑎�𝑏𝑐𝑖� + 𝑎𝑏�𝑐𝑖� + 𝑎𝑏𝑐𝑖

𝑐𝑜 = 𝑏𝑐𝑖 + 𝑎𝑐𝑖 + 𝑎𝑏 + 𝑎𝑏𝑐𝑖

a b CarryIn Sum CarryOut0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1

Page 62: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

62

Solution Simplification

𝑐𝑜 = 𝑏𝑐𝑖 + 𝑎𝑐𝑖 + 𝑎𝑏 + 𝑎𝑏𝑐𝑖 𝑐𝑜 = 𝑏𝑐𝑖 + 𝑎𝑐𝑖 + 𝑎𝑏(1 + 𝑐𝑖)

𝑐𝑜 = 𝑏𝑐𝑖 + 𝑎𝑐𝑖 + 𝑎𝑏𝑎 𝑐𝑜 = 𝑏𝑐𝑖 + 𝑎𝑐𝑖 + 𝑎𝑏

𝑠 = 𝑎�𝑏�𝑐𝑖 + 𝑎�𝑏𝑐𝑖� + 𝑎𝑏�𝑐𝑖� + 𝑎𝑏𝑐𝑖 𝑠 = (𝑎�𝑏 + 𝑎𝑏�)𝑐𝑖� + (𝑎𝑏 + 𝑎�𝑏�)𝑐𝑖 𝑠 = (𝑎 ⊕ 𝑏)𝑐𝑖� + (𝑎 ⊕ 𝑏)𝑐𝑖

𝑠 = (𝑎 ⊕ 𝑏⊕ 𝑐𝑖�)

Page 63: Propositional Calculus - Drexel Universitykschmidt/CS270/Lectures/5/5.pdf · Propositional Calculus ... s . Multiplexor function . 10 . Boolean Expressions ... Expression Trees

63

Full Adder

Sum = parity(a,b,CarryIn) a ⊕ b ⊕ c + a•b•c ≡ a ⊕ b ⊕ c

CarryOut = majority(a,b,CarryIn) b•CarryIn + a•CarryIn + a•b + a•b•CarryIn ≡ b•CarryIn + a•CarryIn + a•b

a b CarryIn Sum CarryOut0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1

Sum

CarryIn

CarryOut

a

b

b

CarryOut

a

CarryIn

b

a

CarryIn

Sum