Download - Boolean Logic
![Page 1: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/1.jpg)
Boolean Logic
Chapter 4 (Sections 4.1 and 4.2)
![Page 2: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/2.jpg)
The Roots: Logic1848 George Boole The Calculus of Logic
chocolate and nuts and mint
![Page 3: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/3.jpg)
The Roots: Logic
cheese and (pepperoni or sausage)
![Page 4: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/4.jpg)
Boolean Searching
• crane silk
• Washington (pin,button,charm)
![Page 5: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/5.jpg)
What’s the “Native Language” of Our Computers?
The first “computers” were actually people who crunched numbers.
The Mathematical Tables Project
NY in the 1940’s
http://gridtalk-project.blogspot.com/2010/09/when-computers-were-human.html Top Secret Rosies: http://www.cnn.com/2011/TECH/innovation/02/08/women.rosies.math/index.html?hpt=C2
![Page 6: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/6.jpg)
Would You Like the Job?
![Page 7: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/7.jpg)
Babbage’s Analytical Engine
In 1833 Charles Babbage (1791-1871) conceived a plan for a general purpose calculating machine. It was designed to contain a store, a mill, capable of performing the four operations of arithmetic, an input/output system which used punched cards, and a printer to display the results. The engine would have been steam-driven and programmed by the punched cards. It was designed in great detail on paper but it was never completed. This is a portion of the mill with a printing mechanism.
![Page 8: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/8.jpg)
What’s the “Native Language” of Our Computers?
CDC 6600 c. 1980
![Page 9: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/9.jpg)
Computing Today
![Page 10: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/10.jpg)
Computing Is About Boolean Logic
The rules of the logic tell us how to manipulate inputs and produce outputs.
We define the rules so that we get answers that are useful to us.
![Page 11: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/11.jpg)
Boolean Operators
NOT
P
TrueFalse
![Page 12: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/12.jpg)
Boolean Operators
NOT
P
True FalseFalse True
![Page 13: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/13.jpg)
Boolean Operators
AND
P Q P QTrue TrueTrue FalseFalse TrueFalse False
![Page 14: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/14.jpg)
Boolean Operators
AND
P Q P QTrue True TrueTrue False FalseFalse True FalseFalse False False
![Page 15: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/15.jpg)
Boolean Operators
OR
P Q P QTrue TrueTrue FalseFalse TrueFalse False
![Page 16: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/16.jpg)
Boolean Operators
OR
P Q P QTrue True TrueTrue False TrueFalse True TrueFalse False False
![Page 17: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/17.jpg)
Boolean Operators
IMPLIES
P Q P QTrue TrueTrue FalseFalse TrueFalse False
![Page 18: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/18.jpg)
Boolean Operators
IMPLIES
P Q P QTrue True TrueTrue False FalseFalse True TrueFalse False True
![Page 19: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/19.jpg)
Boolean Operators
EQUIVALENCE
P Q P QTrue TrueTrue FalseFalse TrueFalse False
![Page 20: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/20.jpg)
Boolean Operators
EQUIVALENCE
P Q P QTrue True TrueTrue False FalseFalse True FalseFalse False True
![Page 21: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/21.jpg)
Boolean Logic
P Q P P Q P Q P Q P QTrue True False True True True TrueTrue False False True False False FalseFalse True True True False True FalseFalse False True False False True True
![Page 22: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/22.jpg)
Using Boolean Logic
P Q P
True True
True False
False True
False False
P ((P Q) Q)
![Page 23: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/23.jpg)
Using Boolean Logic
P Q P P Q
True True False
True False False
False True True
False False True
P ((P Q) Q)
![Page 24: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/24.jpg)
Using Boolean Logic
P Q P P Q P Q
True True False True
True False False True
False True True True
False False True False
P ((P Q) Q)
![Page 25: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/25.jpg)
Using Boolean Logic
P Q P P Q A B (P Q) Q
True True False True True
True False False True False
False True True True True
False False True False True
P ((P Q) Q)
![Page 26: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/26.jpg)
Using Boolean Logic
P Q P P Q P Q (P Q) Q P ((P Q) Q)
True True False True True True
True False False True False False
False True True True True True
False False True False True True
P ((P Q) Q)
![Page 27: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/27.jpg)
Using Boolean Logic
P Q P P Q P Q (P Q) Q P ((P Q) Q)
True True False True True True False
True False False True False False False
False True True True True True True
False False True False True True True
P ((P Q) Q)
![Page 28: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/28.jpg)
Another ExampleE H N S E H ((E H) N S
True True True True TrueTrue True True True TrueTrue False True True
True False True TrueTrue True True TrueTrue True True TrueTrue False TrueTrue False True
![Page 29: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/29.jpg)
Another ExampleE H N S E H ((E H) N S
True True True True TrueTrue True True True TrueTrue False True True
True False True TrueTrue True True TrueTrue True True TrueTrue False TrueTrue False True
((Exhausted HidingPlaceNearby) Nightime) StopToSleep
![Page 30: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/30.jpg)
Boolean Logic
P Q P P Q P Q P Q P QTrue True False True True True TrueTrue False False True False False FalseFalse True True True False True FalseFalse False True False False True True
Let’s practice.
![Page 31: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/31.jpg)
Booleans in Pythondef chocolate(): password = input("Type your password: ") while password != "chocolate": password = input("Try again: ") print("Got it!!")
![Page 32: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/32.jpg)
Booleans in Pythondef for_dummies(): password = input("Type your password: ") tries = 0 while password != "chocolate" and tries < 5: password = input("Try again: ") tries +=1 if tries == 5: print("Okay, you've tried hard enough") else: print("Got it!!")
![Page 33: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/33.jpg)
Booleans in Pythondef for_dummies1(): password = input("Type your password: ") tries = 0 while not(password == "chocolate" or tries >= 5): password = input("Try again: ") tries +=1 if tries == 5: print("Okay, you've tried hard enough") else: print("Got it!!")
![Page 34: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/34.jpg)
Boolean Identities
This notation:
• Multiply for AND• Add for OR
![Page 35: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/35.jpg)
Proving These Things
A B A B (A B)True True True FalseTrue False False TrueFalse True False TrueFalse False False True
A B A B A BTrue True False False FalseTrue False False True TrueFalse True True False TrueFalse False True True True
Prove the first of deMorgan’s laws:
(A B) A B
![Page 36: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/36.jpg)
Proving These Things
A B A B (A B)True True True FalseTrue False False TrueFalse True False TrueFalse False False True
A B A B A BTrue True False False FalseTrue False False True TrueFalse True True False TrueFalse False True True True
Prove the first of deMorgan’s laws:
(A B) A B
![Page 37: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/37.jpg)
Satisfiability
A Boolean formula is satisfiable if and only if there is some row of the truth table that is T.
P Q P P Q P Q (P Q) Q P ((P Q) Q)
True True False True True True False
True False False True False False False
False True True True True True True
False False True False True True True
The job of a SAT solver is to determine satisfiability.
![Page 38: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/38.jpg)
Using Boolean Expressions
(W C D) (W A D)
Is this expression satisfiable?
![Page 39: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/39.jpg)
Using Boolean Expressions
(Wounded CanRun Daylight) (Wounded InAmbulance Daylight)
Is this expression satisfiable?
![Page 40: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/40.jpg)
Binary Boolean Operators
P Q
T T T T T T T T T T F F F F F F F FT F T T T T F F F F T T T T F F F FF T T T F F T T F F T T F F T T F FF F T F T F T F T F T F T F T F T F
What about the other 12 columns?
![Page 41: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/41.jpg)
Boolean Operators
Exclusive Or XOR
P Q P QTrue TrueTrue FalseFalse TrueFalse False
Chips OR Fries
![Page 42: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/42.jpg)
Boolean Operators
Exclusive Or XOR
P Q P QTrue True FalseTrue False TrueFalse True TrueFalse False False
Chips OR Fries
![Page 43: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/43.jpg)
Boolean Operators
Not And NAND
P Q NANDTrue True TrueTrue False FalseFalse True FalseFalse False False
![Page 44: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/44.jpg)
Boolean Operators
Not And NAND
P Q NANDTrue True True FalseTrue False False TrueFalse True False TrueFalse False False True
![Page 45: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/45.jpg)
Boolean Operators
Not Or NOR
P Q NORTrue True TrueTrue False TrueFalse True TrueFalse False False
![Page 46: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/46.jpg)
Boolean Operators
Not Or NOR
P Q NORTrue True True FalseTrue False True FalseFalse True True FalseFalse False False True
![Page 47: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/47.jpg)
Binary Boolean Operators
P Q NAND NOR
T T T T T T T T T T F F F F F F F FT F T T T T F F F F T T T T F F F FF T T T F F T T F F T T F F T T F FF F T F T F T F T F T F T F T F T F
![Page 48: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/48.jpg)
Boolean Circuits
NOT
![Page 49: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/49.jpg)
Boolean Circuits
AND
![Page 50: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/50.jpg)
Boolean Circuits
OR
![Page 51: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/51.jpg)
Boolean Circuits
XOR
![Page 52: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/52.jpg)
Boolean Circuits
NAND
![Page 53: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/53.jpg)
Boolean Circuits
NOR
![Page 54: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/54.jpg)
Boolean Gates• Not
• And
• Or
• XOR
• NAND
• NOR
![Page 55: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/55.jpg)
Circuits That ComputeBuilding an Adder
0 0 1 1+ 0 + 1 + 0 + 1 0 1 1 1 0
A half adder:
![Page 56: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/56.jpg)
Circuits That ComputeBuilding an Adder
0 0 1 1+ 0 + 1 + 0 + 1 0 1 1 1 0
A half adder:
![Page 57: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/57.jpg)
Circuits That ComputeBuilding an Adder
0 0 1 1+ 0 + 1 + 0 + 1 0 1 1 1 0
A full adder:
![Page 58: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/58.jpg)
Reasoning About Circuits (and Programs)
• CircuitA Specification
• ProgramB Specification
![Page 59: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/59.jpg)
Satisfiability
Recall: A Boolean formula is satisfiable if and only if there is some row of the truth table that is T.
P Q P P Q P Q (P Q) Q P ((P Q) Q)
True True False True True True False
True False False True False False False
False True True True True True True
False False True False True True True
The job of a SAT solver is to determine satisfiability.
![Page 60: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/60.jpg)
Reasoning About Circuits (and Programs)
• CircuitA Specification
• ProgramB Specification
So we want to assure that:
(CircuitA Specification)
is not satisfiable.
![Page 61: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/61.jpg)
Other Applications of SAT Solvers
• Cryptography
• Artificial Intelligence:• Planc Problem solved• Is new fact1 consistent with what we already know?
![Page 62: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/62.jpg)
Other Applications of SAT Solvers
• Is new fact1 consistent with what we already know?
(T A) L H TD TU A
U H L
Put another way, is the following formula satisfiable?
((T A) L) (H T) (D T ) (U A ) (U H L )
![Page 63: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/63.jpg)
Other Applications of SAT Solvers
• Is new fact1 consistent with what we already know?
So what’s the problem? Write out the truth table and we are done.
(T A) L (Texan Aggie) Longhorn H T Houston TexanD T Dallas TexanU A UT Aggie
U H L UT Houston Longhorn
![Page 64: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/64.jpg)
How Big Are the Truth Tables?
P Q RTrue True TrueTrue True FalseTrue False True
True False FalseFalse True TrueFalse True FalseFalse False TrueFalse False False
![Page 65: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/65.jpg)
Back to the Longhorn Problem
(T A) L H TD TU A
U H L
How many rows in the truth table for this?
![Page 66: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/66.jpg)
The Longhorn Problem
T A L H D UTrue True True True True TrueTrue True True True TrueTrue False True True True
True False True TrueTrue True True True TrueTrue True True TrueTrue False True TrueTrue False True
![Page 67: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/67.jpg)
2n
0
200000
400000
600000
800000
1000000
1200000
1 3 5 7 9 11 13 15 17 19 21
![Page 68: Boolean Logic](https://reader035.vdocument.in/reader035/viewer/2022062520/56816296550346895dd30d58/html5/thumbnails/68.jpg)
But Practical Solutions Exist
They routinely solve problems with hundreds of thousands of variables.