PPT

advertisement
CSE 311: Foundations of Computing
Fall 2013
Lecture 3: Logic and Boolean algebra
announcements
Reading assignments
– Propositional Logic
1.1 -1.3 7th Edition
1.1 -1.2 6th Edition
– Boolean Algebra
12.1 – 12.3 7th Edition
11.1 – 11.3 6th Edition
combinational logic circuits
Design a circuit to compute the majority of 3 bits.
What about majority of 5 bits?
some other gates
NAND
¬đ‘‹ ∧ ¬đ‘Œ
NOR
¬đ‘‹ ∨ ¬đ‘Œ
XOR
𝑋⊕𝑌
XNOR
𝑋 ↔ 𝑌, 𝑋 = 𝑌
X
Y
X
Y
X
Y
X
Y
Z
X
0
0
1
1
Y
0
1
0
1
Z
1
1
1
0
Z
X
0
0
1
1
Y
0
1
0
1
Z
1
0
0
0
Z
X
0
0
1
1
Y
0
1
0
1
Z
0
1
1
0
Z
X
0
0
1
1
Y
0
1
0
1
Z
1
0
0
1
review: logical equivalence
Terminology: A compound proposition is a
Tautology if it is always true
Contradiction if it is always false
Contingency if it can be either true or false
pīƒšīƒ˜p
pīƒ…p
(p ī‚Ž q) īƒ™ p
(p īƒ™ q) īƒš (p īƒ™ īƒ˜ q) īƒš (īƒ˜ p īƒ™ q) īƒš (īƒ˜ p īƒ™ īƒ˜ q)
review: logical equivalence
p and q are logically equivalent if and only if
p ī‚Ģ q is a tautology
i.e. p and q have the same truth table
The notation p ī‚ē q denotes p and q are
logically equivalent
Example:
pī‚ēīƒ˜īƒ˜p
p
īƒ˜p
īƒ˜īƒ˜p
pī‚Ģīƒ˜īƒ˜p
review: De Morgan’s laws
īƒ˜ (p īƒ™ q) ī‚ē īƒ˜ p īƒš īƒ˜ q
īƒ˜ (p īƒš q) ī‚ē īƒ˜ p īƒ™ īƒ˜ q
What are the negations of:
The Yankees and the Phillies will play
in the World Series.
It will rain today or it will snow on New Year’s Day.
review: De Morgan’s laws
Example: īƒ˜ (p īƒ™ q) ī‚ē (īƒ˜ p īƒš īƒ˜ q)
p q īƒ˜p
T
T
T
F
F
T
F
F
īƒ˜q
īƒ˜pīƒšīƒ˜q
pīƒ™q
īƒ˜ (p īƒ™ q)
īƒ˜ (p īƒ™ q) ī‚Ģ (īƒ˜ p īƒš īƒ˜ q)
review: Law of Implication
(p ī‚Ž q) ī‚ē (īƒ˜ p īƒš q)
p
q
T
T
T
F
F
T
F
F
pī‚Žq īƒ˜p
īƒ˜pīƒšq
(p ī‚Ž q) ī‚Ģ (īƒ˜ p īƒš q)
understanding connectives
• Reflect basic rules of reasoning and logic
• Allow manipulation of logical formulas
– Simplification
– Testing for equivalence
• Applications
– Query optimization
– Search optimization and caching
– Artificial Intelligence
– Program verification
review: properties of logical connectives
•
•
•
•
•
•
•
•
•
Identity
Domination
Idempotent
Commutative
Associative
Distributive
Absorption
Negation
De Morgan’s Laws
Textbook: 1.3 7th Edition/1.2 6th Edition,
Table 6
some equivalences related to implication
pī‚Žq
pī‚Žq
pīƒšq
pīƒ™q
pī‚Ģq
pī‚Ģq
pī‚Ģq
īƒ˜ (p ī‚Ģ q)
ī‚ē
ī‚ē
ī‚ē
ī‚ē
ī‚ē
ī‚ē
ī‚ē
ī‚ē
īƒ˜pīƒšq
īƒ˜qī‚Žīƒ˜p
īƒ˜pī‚Žq
īƒ˜ (p ī‚Ž īƒ˜ q)
(pī‚Ž q) īƒ™ (q ī‚Ž p)
īƒ˜pī‚Ģīƒ˜q
(p īƒ™ q) īƒš (īƒ˜ p īƒ™ īƒ˜ q)
pī‚Ģīƒ˜q
some equivalences related to implication
pī‚Žq
ī‚ē
īƒ˜qī‚Žīƒ˜p
logical proofs
To show P is equivalent to Q
– Apply a series of logical equivalences to
subexpressions to convert P to Q
To show P is a tautology
– Apply a series of logical equivalences to
subexpressions to convert P to T
prove this is a tautology
(p īƒ™ q) ī‚Ž (p īƒš q)
prove this is a tautology
(p īƒ™ (p ī‚Ž q)) ī‚Ž q
proving non-equivalence
(p ī‚Ž q) ī‚Ž r
p ī‚Ž (q ī‚Ž r)
boolean logic
Combinational logic
– output 𝑡 = 𝐹 input 𝑡
Sequential logic
– output 𝑡 = 𝐹 output 𝑡−1 , input 𝑡
• output dependent on history
• concept of a time step (clock)
An algebraic structure consists of
– a set of elements B = {0, 1}
– binary operations { + , • } (OR, AND)
– and a unary operation { ’ } (NOT )
a quick combinational logic example
Calendar subsystem:
# of days in a month (to control watch display)
– used in controlling the display of a wrist-watch
LCD screen
– inputs: month, leap year flag
– outputs: number of days
Example: (March, non-leap year) → 31
implementation in software
integer number_of_days (month, leap_year_flag){
switch (month) {
case 1: return (31);
case 2: if (leap_year_flag == 1) then
return (29) else return (28);
case 3: return (31);
...
case 12: return (31);
default: return (0);
}
}
20
implementation with combinatorial logic
Encoding:
- how many bits for each input/output?
- binary number for month
month
0000
- four wires for 28, 29, 30, and 31
month
d28
d29
leap
d30
d31
0001
0010
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
leap
–
–
0
1
–
–
–
–
–
–
–
–
–
–
–
–
–
d28
–
0
1
0
0
0
0
0
0
0
0
0
0
0
–
–
–
d29
–
0
0
1
0
0
0
0
0
0
0
0
0
0
–
–
–
d30
–
0
0
0
0
1
0
1
0
0
1
0
1
0
–
–
–
d31
–
1
0
0
1
0
1
0
1
1
0
1
0
1
–
–
–
implementation with combinatorial logic
Truth-table to logic to switches to gates
d28 = “1 when month=0010 and leap=0”
d28 = m8'•m4'•m2•m1'•leap‘
d31 = “1 when month=0001 or month=0011 or ... month=1100”
d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) +
... + (m8•m4•m2'•m1')
d31 = can we simplify more?
month
leap
d28 d29 d30 d31
0000
0001
0010
0010
0011
0100
...
1100
1101
111–
–
–
0
1
–
–
–
0
1
0
0
0
–
0
0
1
0
0
–
0
0
0
0
1
–
1
0
0
1
0
–
–
–
0
–
–
0
–
–
0
–
–
1
–
–
implementation with combinatorial logic
d28 = m8'•m4'•m2•m1'•leap’
d29 = m8'•m4'•m2•m1'•leap
d30 = (m8'•m4•m2'•m1') + (m8'•m4•m2•m1') +
(m8•m4'•m2'•m1) + (m8•m4'•m2•m1)
= (m8'•m4•m1') + (m8•m4'•m1)
d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) +
(m8'•m4•m2'•m1) + (m8'•m4•m2•m1) +
(m8•m4'•m2'•m1') + (m8•m4'•m2•m1') +
(m8•m4•m2'•m1')
combinational logic
•
•
•
•
•
Switches
Basic logic and truth tables
Logic functions
Boolean algebra
Proofs by re-writing and by truth table
Download