CSE 20 DISCRETE MATH Prof. Shachar Lovett Clicker frequency: CA
Todays topics Algorithms: number systems, binary representation Boolean logic Sections 1.3, in Jenkyns, Stephenson
Operations on binary numbers Add, subtract, multiply,… … first, how do we add? A. 111 B. 100 C D E. None of the above
One bit addition
One bit addition
One bit addition Carry: 0 1 1
One bit addition Carry:
How to add binary numbers? ? ? ? ? ?
How to add binary numbers? ? ? ? ? ? ? ? ? (carry) ? ? ? ? ?
How to add binary numbers? Two basic operations: One-Bit-Addition(bit1, bit2, carry) Next-carry(bit1, bit2, carry) ? ? ? ? ? ? ? ? (carry) ? ? ? ? ?
Numbers … logic … circuits
One bit addition One-Bit-Addition(bit1, bit2, carry) Bit1bit2carryOne-Bit-Addition FFFF FFTT FTFT FTTF TFFT TFTF TTFF TTTT T=1 F=0 Can we build this from “basic primitives”?
Logical operators JS pp Truth table is the definition of the operator! PQ P QP Q TTT TFF FTF FFF PQP v Q TTT TFT FTT FFF P~P TF FT
Logical operators JS pp PQ P QP Q TTT TFF FTF FFF PQP v Q TTT TFT FTT FFF P~P TF FT PQP XOR Q TT? TF? FT? FF? A.T, T, T, F B.T, F, F, T C.F, T, F, T D.F, F, F, T E.None of the above.
OR vs XOR A OR B: Either A, or B, or both A XOR B: Either A, or B, but not both In spoken language, we sometimes confuse them In mathematics, we needs to be precise
OR vs XOR A OR B: Either A, or B, or both A XOR B: Either A, or B, but not both In spoken language, we sometimes confuse them In mathematics, we needs to be precise You are at a restaurant. The menu says you can have either a salad or a soup. Mathematically, this is: A. OR B. XOR C. Both D. Neither
OR vs XOR A OR B: Either A, or B, or both A XOR B: Either A, or B, but not both In spoken language, we sometimes confuse them In mathematics, we needs to be precise You are at a birthday. The host asks: do you want ice-cream or cake (you can have both). Mathematically, this is: A. OR B. XOR C. Both D. Neither
Boolean expressions JS p. 83 How to translate to a truth table? Is there a unique way? A. Yes B. No (P Q) (~R)
Boolean expressions How to translate to a truth table? How many rows (not including header)? A. 2 B. 3 C. 4 D. 8 (P Q) (~R)
Boolean expressions PQR PQPQ ~R (P Q) (~R) FFF FFT FTF FTT TFF TFT TTF TTT
Boolean expressions PQR PQPQ ~R (P Q) (~R) FFFF FFTF FTFF FTTF TFFF TFTF TTFT TTTT
Boolean expressions PQR PQPQ ~R (P Q) (~R) FFFFT FFTFF FTFFT FTTFF TFFFT TFTFF TTFTT TTTTF
Boolean expressions PQR PQPQ ~R (P Q) (~R) FFFFTT FFTFFF FTFFTT FTTFFF TFFFTT TFTFFF TTFTTT TTTTFT
Truth table to expression PQR??? TTTT TTFT TFTT TFFF FTTF FTFF FFTT FFFF
DNFs DNF = Disjunctive Normal Form Literal: variable or its negation: P, ~P Term: AND of literals: P ~Q DNF: OR of terms: (P ~Q) (R P) ~P Theorem: any Boolean expression can be written as a DNF
Truth table to expression PQR??? TTTT TTFT TFTT TFFF FTTF FTFF FFTT FFFF
Truth table to expression PQR??? TTTT TTFT TFTT TFFF FTTF FTFF FFTT FFFF PQRPQR P Q ~R P ~Q R ~P ~Q R (P Q R) (P Q ~R) (P ~Q R) (~P ~Q R)
Truth tables and Circuits T“1”High voltage F“0”Low voltage
4 bit adder
Next class Quantifiers and paradoxes Read sections in Jenkyns, Stephenson Google “liar’s paradox”