Boolean Algebra Computer Science 1611. AND (today is Monday) AND (it is raining) (today is Monday)...

Preview:

Citation preview

Boolean Algebra

Computer Science 1611

AND

(today is Monday) AND (it is raining) (today is Monday) AND (it is not raining) (today is Friday) AND (it is raining) (today is Friday) AND (it is not raining)

OR

(today is Monday) OR (it is raining) (today is Monday) OR (it is not raining) (today is Friday) OR (it is raining) (today is Friday) OR (it is not raining)

NOT (today is Monday) OR NOT (it is raining) (today is Monday) OR (it is raining) (today is Friday) AND NOT(it is raining) (today is Friday) AND (it is raining) (today is Monday) AND NOT(it is raining) (today is Monday) AND (it is raining) (today is Friday) OR NOT (it is raining) (today is Friday) OR (it is raining)

IMPLIES (A B)

A B is False only when A is True and B is False.

In other words, A B is True except when the premise (A) is True and the conclusion (B) is False.

A B is logically equivalent to

(NOT A) OR B

Truth Table (AND, OR, NOT)

Mon rain NOT M NOT r M AND r M OR r

T T

T F

F T

F F

Truth Table (AND, OR, NOT)

Mon rain NOT M NOT r M AND r M OR r

T T F F

T F F T

F T T F

F F T T

Truth Table (AND, OR, NOT)

Mon rain NOT M NOT r M AND r M OR r

T T F F T

T F F T F

F T T F F

F F T T F

Truth Table (AND, OR, NOT)

Mon rain NOT M NOT r M AND r M OR r

T T F F T T

T F F T F T

F T T F F T

F F T T F F

Truth Tables

A AND B is True only when both A and B are true.

A OR B is always True unless both A and B are false.

NOT A changes the value from True to False or False to True.

IMPLIES (A B)A B NOT A (NOT A) OR B A B

T T F T T

T F F F F

F T T T F

F F T T F

Writing AND, OR, NOT

A AND B = A ^ B = AB A OR B = A V B = A+B NOT A = ~A = A’ TRUE = T = 1 FALSE = F = 0

Example

Write the truth table for A(A’ + B) + AB’ (section 7.5, AE, p 308, exercise #3a)

First, write in words: A AND (NOT A OR B) OR (A AND NOT B)

Then do a truth table with the following columns: A, B, NOT A, NOT B, NOT A OR B, A AND NOT B, A AND (NOT A OR B), whole expression.

X = A (A’ + B) + AB’

A B NOT A

NOT B

NOT A OR B

A AND NOT B

A AND (A’+B)

X

T T F F T F T T

T F F T F T F T

F T T F T F F F

F F T T T F F F

Exercise

Write the truth table for (A + A’) B First, write in words. Then do a truth table.

Solution to (A + A’) B

A B NOT A A OR NOT A (A OR NOT A)

AND B

T T F T T

T F F T F

F T T T T

F F T T F

Boolean Algebra

Boolean Algebra is made up of two constants (True and False)

Several operators - AND, OR, NOT, XOR, NOR, NAND

XOR = either a or b but not both NOR = NOT OR NAND = NOT AND

Boolean Algebra

The = in Boolean Algebra means equivalent Two statements are equivalent if they have the

same truth table. For example,

True = True, a = a,

Boolean Algebra - Identities

A OR True = True A OR False = A A OR A = A A OR B = B OR A

(commutative)

A AND True = A A AND False = False A AND A = A A AND B = B AND A

(commutative)

Associative and Distributive Identities

A AND (B AND C) = (A AND B) AND C A OR (B OR C) = (A OR B) OR C A OR (B AND C) = (A OR B) AND (A OR C) A AND (B OR C) = (A AND B) OR (A AND C) Exercise: using truth tables prove -

A AND (A OR B) = A

Solution: A AND (A OR B) = A

A B A OR B A AND (A OR B)

T T T T

T F T T

F T T F

F F F F

Using Identities

A OR (B AND C) = (A OR B) AND (A OR C) A AND (B OR C) = (A AND B) OR (A AND C) A AND (A OR B) = A A OR A = A Exercise - using identities prove:

A OR (A AND B) = A = A AND (A OR B) = A A OR (A AND B) = (A OR A) AND (A OR B)

Identities with NOT

NOT (NOT A) = A A OR NOT A = True A AND NOT A = False On and on and on and on …

DeMorgan’s Laws

NOT (A OR B) = NOT A AND NOT B~ (A + B) = (~A) (~B)

NOT (A AND B) = NOT A OR NOT B~ (AB) = ~ A + ~ B

Exercise - Simplify the following with identitiesNOT (NOT A AND B)

Solving a Truth Table

1. Select lines in the table for which the result is 1 (T)2. For each of those

a) Find the P, Q valuesb) Build an AND statement with the variable itself if its value is 1 (T), and

with the negation of the variable if its value is 0 (F)

3. Use OR to connect the statements in step 2.Ref: AE Text, section 7.2, p. 281

Solving a Truth Table

A B X When you see a True value in the X column, you must have a term in the expression. Each term consists of some combination of the variables AB. The A value will be NOT A when the truth value of A is False – the B value will be NOT B when the truth value of B is false. They will be connected by OR.

T T T

T F T

F T F

F F F

For example,

X = AB + AB’ = (A AND B) OR ( A AND NOT B)

Exercise 1: Solving a Truth Table

A B X When you see a True value in the X column, you must have a term in the expression. Each term consists of some combination of the variables AB. The A value will be NOT A when the truth value of A is False – the B value will be NOT B when the truth value of B is false. They will be connected by OR.

T T T

T F F

F T T

F F F

Solve the Truth Table given above.

Recommended