Computer Science 101

advertisement
Computer Science 101
Boolean Algebra
What’s next?

A new type of algebra – Helps us
• With logical reasoning
• Understand and design circuits of a computer

The “innards” of a computer
•
•
•
•
Basic circuits
Major components and how they work together
Low level instructions – machine language
How data and instructions are stored in computer
George Boole

English mathematician

1815-1864

1854: Introduction to the Laws of Thought

Boolean algebra
• Logic
• Set Theory
• Circuits
• Programming: Conditions in “while” and “if”
Boolean Constants and
Variables

In Boolean algebra, there are only two
constants.
•
•
•
•

True and False
On and Off
+5v and 0v
1 and 0
Boolean variables are variables that store
values that are Boolean constants.
Boolean Operator AND

If A and B are Boolean variables (or
expressions) then
A AND B
is True (1) if and only if both A and B have
values of True (1).

We denote the AND operation like
multiplication in ordinary algebra:
AB or A.B
Boolean Operator OR

If A and B are Boolean variables (or
expressions) then
A OR B
is True (1) if and only if at least one of A and B
has value of True (1).

We denote the OR operation like addition in
ordinary algebra:
A+B
Boolean Operator NOT

If A is a Boolean variable (or expression) then
NOT A
has the opposite value from A.

We denote the NOT operation by putting a bar
over the variable (or expression)
_
A
Boolean Expressions

As with ordinary algebra, a Boolean
expression is a well-formed expression
made from
•
•
•
•

Boolean constants
Boolean variables
Operators AND, OR and NOT
Parentheses
Example:
_
____
AB + (A+C)B
The value of a Boolean
expression

At any point, the value of a BE can be
computed using the current values of the
variables.

Unlike ordinary algebra, for a BE, there are
only finitely many possible assignments of
values to the variables; so, theoretically, we
can make a table, called a truth table that
shows the value of the BE for every possible
set of values of the variables.
Truth Table: _
____
E = AB + (A+C)B
A B C
0 0 0
_
B
_
AB
1
0
____ ____
A+C A+C (A+C )B E
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
1
1
1
0
1
0
1
1
1
0
0
1
1
0
0
1
1
1
1
0
0
0
0
0
0
0
0
1
1
0
0
0
0
1
1
In Python!
Laws of Algebra?

In ordinary algebra, we have a distributive
law :
A(B+C) = AB + AC

What does it mean to say this is a law?
• The left side has parentheses, right side
doesn’t.
• The left side has one multiplication and the
right side has two.
Laws of Algebra?

A(B+C) = AB + AC

No matter what the numerical values of A,
B, and C are, the two indicated
computations will have the same value.
Laws of Boolean Algebra
Identity
A+0=A, A.1=A
Zero Element
A.0=0, A+1=1
Idempotent
A+A=A, AA=A
Commutative
A+B=B+A, AB=BA
Associative
(A+B)+C=A+(B+C)
(AB)C=A(BC)
Distributive
A(B+C)=AB+AC
A+BC=(A+B)(A+C)
Laws of Boolean Algebra
Absorption
A+AB=A,
A(A+B)=A
DeMorgan
____ _ _
A+B =_A B
___
_,
AB = A +B
Complement
_
_
A+A =1, AA =0
Double
_ Complement
A=A
Boolean Expression
Simplification
_
_
____
(A+B )C + AC
_ + (B+C
_ ) _ _
= (A+B
_ )C + AC +
_ B_C
= (A+B
_ )C + _(A+B )C
= (A+B
_ )(C+C )
= (A+B
_ )1
= A+B
(DeMorgan)
(Distributive)
(Distributive)
(Complement)
(Identity)
Boolean Expression
Simplification
_ _
_
A B + AB
_ _+ AB _
_
=A
_ B_ + AB + AB
_ + AB
=B
_ (A +A) + A(B +B)
=B
_ 1+A1
=B+A
(Idempotent)
(Distributive)
(Complement)
(Identity)
Download