1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

32
1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

Transcript of 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

Page 1: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

1

Fundamentals of Computer Science

Propositional Logic(Boolean Algebra)

Page 2: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

2

What is Propositional logic?

• Propositional logic is a mathematical model that allows us to reason about the truth or falsehood of logical expressions.

• Propositional logic is used in the design of computer circuits.

• Propositional logic is made up of propositions.• A proposition is any statement that evaluates to

one of the truth values TRUE or FALSE.

Page 3: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

3

Propositional Variables

• A proposition variable is a variable that stands for some proposition. For example,

p c < d

NOT p NOT (c < d)

means “is equivalent to” or “has the same Boolean value as”.

• In this class I will use the terms propositional and Boolean interchangeably.

Page 4: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

4

Logical Expressions• Logical expressions are made up of

– Boolean variables

– Boolean constants

– Boolean operators

• There is no strict naming convention for Boolean variables.

• There are only two Boolean constants, TRUE and FALSE.

• There are many Boolean operators, the most frequently used being NOT, AND, and OR.

Page 5: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

5

Truth Tables• Boolean functions are commonly displayed using

truth tables.• The truth tables for the NOT, AND, and OR

operators are as follows.

A NOT A A B A AND B A B A OR B

0 1 0 0 0 0 0 0

1 0 0 1 0 0 1 1

1 0 0 1 0 1

1 1 1 1 1 1

Page 6: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

6

Truth Tables• Other Boolean operators include XOR (exclusive

or), NAND (not-and), and NOR (not-or).• NAND and NOR transistors are well represented

in circuit design due to their simplicity.

A B A XOR B A B A NAND B A B A NOR B

0 0 0 0 0 1 0 0 1

0 1 1 0 1 1 0 1 0

1 0 1 1 0 1 1 0 0

1 1 0 1 1 0 1 1 0

Page 7: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

7

Transistor Implementation of Elementary Logic Gates

Page 8: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

8

Precedence of Logical Operators• The order of precedence is..

1. NOT (highest)

2. NAND

3. NOR

4. AND

5. OR

6. (lowest)

Page 9: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

9

Shorthand Notations for Boolean Operators

• NOT A A• A NAND B AB• A NOR B A+B• A AND B AB• A OR B A+B

Common misconceptions:

AB AB A+B A+B

Page 10: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

10

Evaluating Complex Boolean Expressions with Truth Tables

• Truth tables can be used to verify the equality of inequality of two or more Boolean expressions.

• The size of a truth table grows exponentially relative to the number of variables in the Boolean expression.– The number of entries (rows) in a truth table is 2n

where n represents the number of variables in the expression.

• Truth tables are one of the principle tools used in digital circuit design.

Page 11: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

11

Evaluating Complex Boolean Expressions with Truth Tables

AB + CA A(B + C)A B C AB C CA AB+CA B+C A(B+C)

0 0 0 0 1 0 0 1 0

0 0 1 0 0 0 0 0 0

0 1 0 0 1 0 0 1 0

0 1 1 0 0 0 0 1 0

1 0 0 0 1 1 1 1 1

1 0 1 0 0 0 0 0 0

1 1 0 1 1 1 1 1 1

1 1 1 1 0 0 1 1 1

Page 12: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

12

Boolean IdentitiesBoolean identities are rules used to simplify Boolean expressions.

Page 13: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

13

Proof of DeMorgan’s Law

X + Y = XY

Page 14: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

14

More Useful Boolean Identities

Page 15: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

15

Circuit Design Problem

• Design a combinational circuit that determines if a binary value in the range of 0 to 7 (000b to 111b) is prime.

• P(A,B,C) 1 if the value ABC is prime and 0 if ABC is not prime.

Circuit P

A

B

C

High-level block diagram

Page 16: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

16

Circuit Design Problem• Steps to developing the “Prime” circuit:

1. Construct the truth table.

2. Express the value of the truth table as a Boolean expression in sum of the min terms format.

3. Using Boolean identities, simplify the Boolean expression.

4. Draw the circuit from the simplified Boolean expression.

Page 17: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

17

Circuit Design Problem

1. Draw the truth tableA, B, and C are the inputs to the circuit; P is the output. A, B, and C collectively represent a single three digit unsigned binary number. A is the most significant digit and C is the least significant digit. If the digit is prime the output, P, is high (1); if the digit is not prime the output, P, is low (0).

Page 18: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

18

Circuit Design Problem2. Express the value of the truth

table in sum of the min terms format.

Notice that each term in the expression corresponds to the values for A, B, and C when P is high

Page 19: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

19

Circuit Design Problem

3. Using Boolean identities, simplify the Boolean expression.

Simplest form

Page 20: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

20

Circuit Design Problem4. Draw the circuit from the simplified Boolean

expression.

Circuit P

A

B

C

Page 21: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

21

Digital Logic Gates

Page 22: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

22

Digital Logic Gates

Page 23: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

23

Implementation of Boolean Functions with Gates

Both of these circuits are logically equivalent. However, version (b) saves on performance, space, and cost.

Page 24: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

24

Karnaugh Maps• Karnaugh maps (a.k.a. k-maps) provide an

alternative technique for simplifying Boolean expressions.

• K-maps are most commonly used for Boolean expressions containing 2, 3, or 4 variables.

• Steps to using a k-map in a digital design1. Construct the truth table.

2. Transfer the value (output) of the truth table to an appropriate size k-map.

3. Group the appropriate elements of the k-map.

4. Convert the groupings to the resulting simplified Boolean expression.

Page 25: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

25

Karnaugh Map Grouping Rules

• Each grouping must be a power of 2: 1, 2, 4, 8, 16, etc.

• Each grouping must be in the shape of a square or a rectangle - no diagonals are allowed.

• Groupings may overlap.• Each grouping should be as large as possible so as

to minimize the total number of groupings.• Each grouping should have at least one element

that is not a part of another grouping.

Page 26: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

26

Karnaugh Map ExampleUsing a Karnaugh map to generate a simplified Boolean expression for the prime number problem.

Page 27: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

27

Three-Variable K-Map Interpretation

• Each box in the k-map corresponds to a row in the truth table. Row 1 is m0, row 2 is m1, etc.

• The boxes do not follow a strict sequential numbering.• The labeled brackets in illustration (b) show where the

corresponding variable has a value of 1.

Page 28: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

28

Karnaugh Map Interpretation

• The grouping of 4 is completely inside the area of the k-map

where C 1. This gives us the term C.

• The grouping of 2 is completely inside the area of the k-map

where B 1, and completely outside the area where A 1. This gives us the term AB.

Page 29: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

29

Two-Variable Karnaugh Maps

• mi represents a min-term

– m0 = 00

– m1 = 01

– m2 = 10

– m3 = 11

Page 30: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

30

Four-Variable Karnaugh Maps

Page 31: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

31

“Don’t Care” ConditionsOccasionally there will be combinations of inputs that will never occur for one reason or another. For those combinations we can label the outputs as don’t-cares by putting an ‘X’ in the corresponding output field. An ‘X’ may be treated either as a 0 or a 1 in k-map simplification.

Page 32: 1 Fundamentals of Computer Science Propositional Logic (Boolean Algebra)

32

Propagation Delay for an Inverter Gate