Computer Science 101 Boolean Algebra. What’s next? A new type of algebra – Helps us A new type...

Post on 24-Dec-2015

213 views 0 download

Transcript of Computer Science 101 Boolean Algebra. What’s next? A new type of algebra – Helps us A new type...

Computer Science Computer Science 101101

Boolean AlgebraBoolean Algebra

What’s next?What’s next?

A new type of algebra – Helps usA new type of algebra – Helps us• With logical reasoningWith logical reasoning• Understand and design circuits of a computerUnderstand and design circuits of a computer

The “innards” of a computerThe “innards” of a computer• Basic circuitsBasic circuits• Major components and how they work togetherMajor components and how they work together• Low level instructions – machine languageLow level instructions – machine language• How data and instructions are stored in How data and instructions are stored in

computercomputer

George BooleGeorge Boole

English mathematicianEnglish mathematician

1815-18641815-1864

1854: 1854: Introduction to the Laws of ThoughtIntroduction to the Laws of Thought

Boolean algebraBoolean algebra• LogicLogic• Set TheorySet Theory• CircuitsCircuits• Programming: Conditions in “while” and “if”Programming: Conditions in “while” and “if”

Boolean Constants and Boolean Constants and VariablesVariables

In Boolean algebra, there are only In Boolean algebra, there are only two constants.two constants.• True and FalseTrue and False• On and OffOn and Off• +5v and 0v+5v and 0v• 1 and 01 and 0

Boolean variables are variables that Boolean variables are variables that store values that are Boolean store values that are Boolean constants.constants.

Boolean Operator ANDBoolean Operator AND

If A and B are Boolean variables (or If A and B are Boolean variables (or expressions) then expressions) then

A AND BA AND B

is True (1) if and only if is True (1) if and only if bothboth A and B A and B have values of True (1).have values of True (1).

We denote the AND operation like We denote the AND operation like multiplication in ordinary algebra:multiplication in ordinary algebra:

AB or AAB or A..BB

Boolean Operator ORBoolean Operator OR

If A and B are Boolean variables (or If A and B are Boolean variables (or expressions) then expressions) then

A OR BA OR B

is True (1) if and only if is True (1) if and only if at least one at least one ofof A A and B has value of True (1).and B has value of True (1).

We denote the OR operation like addition We denote the OR operation like addition in ordinary algebra:in ordinary algebra:

A+BA+B

Boolean Operator NOTBoolean Operator NOT

If A is a Boolean variable (or expression) If A is a Boolean variable (or expression) then then

NOT ANOT A

has the opposite value from A.has the opposite value from A.

We denote the NOT operation by putting a We denote the NOT operation by putting a bar over the variable (or expression)bar over the variable (or expression)

__AA

Boolean ExpressionsBoolean Expressions

As with ordinary algebra, a Boolean As with ordinary algebra, a Boolean expression is a well-formed expression expression is a well-formed expression made frommade from• Boolean constantsBoolean constants• Boolean variablesBoolean variables• Operators AND, OR and NOTOperators AND, OR and NOT• ParenthesesParentheses

Example: _ ____Example: _ ____ AB + (A+C)B AB + (A+C)B

The value of a Boolean The value of a Boolean expressionexpression

At any point, the value of a BE can be At any point, the value of a BE can be computed using the current values of the computed using the current values of the variables.variables.

Unlike ordinary algebra, for a BE, there Unlike ordinary algebra, for a BE, there are only finitely many possible are only finitely many possible assignments of values to the variables; assignments of values to the variables; so, theoretically, we can make a table, so, theoretically, we can make a table, called a called a truth tabletruth table that shows the value that shows the value of the BE for every possible set of values of the BE for every possible set of values of the variables.of the variables.

Truth Table: _ ____Truth Table: _ ____ E = AB + (A+C)B E = AB + (A+C)B

A B C B_

AB_

A+C A+C____

(A+C____

)B E0 0 0 1 0 0 1 0 0

0 0 1 1 0 1 0 0 0

0 1 0 0 0 0 1 1 1

0 1 1 0 0 1 0 0 0

1 0 0 1 1 1 0 0 11 0 1 1 1 1 0 0 11 1 0 0 0 1 0 0 01 1 1 0 0 1 0 0 0

In Python!In Python!

Laws of Algebra?Laws of Algebra?

In ordinary algebra, we have a In ordinary algebra, we have a distributive distributive lawlaw ::

A(B+C) = AB + ACA(B+C) = AB + AC

What does it mean to say this is a What does it mean to say this is a law?law?• The left side has parentheses, right side The left side has parentheses, right side

doesn’t.doesn’t.• The left side has one multiplication and The left side has one multiplication and

the right side has two.the right side has two.

Laws of Algebra?Laws of Algebra?

A(B+C) = AB + ACA(B+C) = AB + AC

No matter what the numerical values No matter what the numerical values of A, B, and C are, the two indicated of A, B, and C are, the two indicated computations will have the same computations will have the same value.value.

Laws of Boolean AlgebraLaws of Boolean Algebra

Identity Zero ElementA+0=A, A.1=A A.0=0, A+1=1

Idempotent CommutativeA+A=A, AA=A A+B=B+A, AB=BA

Associative Distributive(A+B)+C=A+(B+C) A(B+C)=AB+AC(AB)C=A(BC) A+BC=(A+B)(A+C)

Laws of Boolean AlgebraLaws of Boolean Algebra

Absorption DeMorganA+AB=A, A+B

____ = A

_ B_

,A(A+B)=A AB

___ = A

_ +B

_

Complement Double ComplementA+A

_ =1, AA

_ =0 A

__ = A

Boolean Expression Boolean Expression SimplificationSimplification

(A+B_

)C + AC_

+ (B+C____

)= (A+B

_ )C + AC

_ + B

_ C_

(DeMorgan)= (A+B

_ )C + (A+B

_ )C

_ (Distributive)

= (A+B_

)(C+C_

) (Distributive)= (A+B

_ )1 (Complement)

= A+B_

(Identity)

Boolean Expression Boolean Expression SimplificationSimplification

A_

B_

+ AB_

+ AB= A

_ B_

+ AB_

+ AB_

+ AB (Idempotent)= B

_ (A

_ +A) + A(B

_ +B) (Distributive)

= B_

1 + A 1 (Complement)= B

_ + A (Identity)