CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2009/2010, Section 203 CPSC 121: Models of Computation
Menu January 8, 2010 Topics: Propositional Logic Logic Gates Pre-class reading: Today: Epp 1.1, 1.2, 1.4 Next week: Epp 1.5, 1.3 Handouts: Lab 0 (Part 1 and Part 2) Lab 1 Reminders: Online Quizzes 1 and 2 (deadline 9:00pm Sun, Jan 10) Labs and tutorials begin week of January 11 — Note: Lab 1 has a pre-lab component (worth marks) www: http://www.ugrad.cs.ubc.ca/~cs121/ WebCT Vista: http://www.vista.ubc.ca CPSC 121: Models of Computation
Example Propositions (Summary) Proposition 1: 2 + 3 = 5 Proposition 2: 5 + 3 × 5 = 20 Proposition 3: Intel’s original Pentium processor chip performed floating point division properly Proposition 4: (Goldbach) Every positive even integer greater than 2 can be written as the sum of two primes Proposition 5: Let n be a natural number. Then the natural number p ( n ) = n 2 + n + 41 is prime Proposition 6: (Euler) There are no positive integers a , b , c , d , such that a 4 + b 4 + c 4 = d 4 CPSC 121: Models of Computation
Propositional Logic A proposition is a statement that is true or false (but not both) We combine propositions together to create new propositions, called compound propositions We use logical connectives to combine propositions. Logical connectives also are called logical operators or Boolean operators after the English mathematician George Boole Three logical connectives, familiar from natural language, are: and, or and not CPSC 121: Models of Computation
Logical Connectives: and , or and not Let p and q be propositions. Then, p and q , called the conjunction of p and q , is written as p ∧ q p or q , called the disjunction of p and q , is written as p ∨ q not p is called the negation of p and is written as ∼ p (or ¬ p or p ) Notes: Notation can differ among authors and communities Although intuition about the meaning of logical connectives derives from natural language, we formally define their meaning using truth tables CPSC 121: Models of Computation
Truth Table: not Let p be a propositional variable p T F Start with truth values for p (1st column) CPSC 121: Models of Computation
Truth Table: not Let p be a propositional variable p ∼ p T F F T Start with truth values for p (1st column) Add truth values for ∼ p (2nd column) CPSC 121: Models of Computation
Truth Table: not Let p be a propositional variable p ∼ p T F F T Start with truth values for p (1st column) Add truth values for ∼ p (2nd column) CPSC 121: Models of Computation
Truth Table (2 Propositional Variables) Let p and q be two propositional variables. p T T F F Start with truth values for p (1st column) CPSC 121: Models of Computation
Truth Table (2 Propositional Variables) Let p and q be two propositional variables. p q T T T F F T F F Start with truth values for p (1st column) Add truth values for q (2nd column) CPSC 121: Models of Computation
Truth Table (2 Propositional Variables) Let p and q be two propositional variables. p q T T ∗ T F ∗ F T ∗ F F ∗ Start with truth values for p (1st column) Add truth values for q (2nd column) Now all possible combinations of truth values for p and q are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider CPSC 121: Models of Computation
Truth Table (2 Propositional Variables) Let p and q be two propositional variables. p q T T ∗ T F ∗ F T ∗ F F ∗ Start with truth values for p (1st column) Add truth values for q (2nd column) Now all possible combinations of truth values for p and q are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider CPSC 121: Models of Computation
Truth Tables: and and or p ∧ q p q p ∧ q T T T T F F F T F F F F Add truth values for p ∧ q (3rd column) CPSC 121: Models of Computation
Truth Tables: and and or p ∧ q p ∨ q p q p ∧ q p ∨ q T T T T T F F T F T F T F F F F Add truth values for p ∧ q (3rd column) Add truth values for p ∨ q (4th column) CPSC 121: Models of Computation
Truth Tables: and and or p ∧ q p ∨ q p q p ∧ q p ∨ q T T T T T F F T F T F T F F F F Add truth values for p ∧ q (3rd column) Add truth values for p ∨ q (4th column) CPSC 121: Models of Computation
Logical Connectives and , or and not are Universal There are other logical connectives, as we shall see. But, and , or and not are “universal” Any propositional formula can be expressed using these three and only these three logical connectives CPSC 121: Models of Computation
Truth Table: xor English has another meaning for “or” which we call exclusive or (xor) and denote ⊕ p ⊕ q p q p ⊕ q T T F T F T F T T F F F CPSC 121: Models of Computation
Truth Table: xor English has another meaning for “or” which we call exclusive or (xor) and denote ⊕ p ⊕ q p q p ⊕ q T T F T F T F T T F F F CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, 3 p q T T T T T F T F T T F F T Column 3 is always T. CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , 3 4 p q T F T T T F T F T F F T T F F F T F Column 3 is always T. Column 4 is always F . CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , p, 3 4 5 p q T F p T T T F T T F T F T F T T F F F F T F F Column 3 is always T. Column 4 is always F . Column 5 is p. CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , p, not p (denoted ∼ p), 3 4 5 6 p q T F p ∼ p T T T F T F T F T F T F F T T F F T F F T F F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼ p. CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , p, not p (denoted ∼ p), q, 3 4 5 6 7 p q T F p ∼ p q T T T F T F T T F T F T F F F T T F F T T F F T F F T F Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼ p. Column 7 is q. CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , p, not p (denoted ∼ p), q, not q (denoted ∼ q) 3 4 5 6 7 8 p q T F p ∼ p q ∼ q T T T F T F T F T F T F T F F T F T T F F T T F F F T F F T F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼ p. Column 7 is q. Column 8 is ∼ q CPSC 121: Models of Computation
More Examples Six (6) not very interesting examples: T, F , p, not p (denoted ∼ p), q, not q (denoted ∼ q) 3 4 5 6 7 8 p q T F p ∼ p q ∼ q T T T F T F T F T F T F T F F T F T T F F T T F F F T F F T F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼ p. Column 7 is q. Column 8 is ∼ q CPSC 121: Models of Computation
Question? How many distinct Boolean operators are there of 2 Boolean variables? Answer: There are 2 4 = 16 Consider the truth table template we saw before: p q T T ∗ T F ∗ F T ∗ F F ∗ The truth table has 4 rows since there are 2 × 2 distinct combinations of truth values for p and q. For each row, we have an entry, denoted by ∗ , that can be either true or false. Thus, there are 2 4 = 16 distinct truth tables for 2 Boolean variables CPSC 121: Models of Computation
Logic Gates NOT AND NOT input output input output 0 1 0 0 0 AND 1 0 0 1 0 1 0 0 1 1 1 OR OR XOR input output input output XOR 0 0 0 0 0 0 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 CPSC 121: Models of Computation
Logic Gates NAND NOR NAND input output input output 0 0 1 0 0 1 NOR 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1 1 0 CPSC 121: Models of Computation
2-input NAND and NOR Gates Each are Universal NOT, AND and OR gates can be implemented using only NAND gates (left side) or only NOR gates (right side). CPSC 121: Models of Computation
All 16 Logical Operators (with “Gate” Names) B B X N N N ∗ U U N A A X O O N ∗ O F F O N N O T T O ∗ p q R p q R D D R q p R ∗ T T T T T T T T T T F F F F F F F F T F T T T T F F F F T T T T F F F F F T T T F F T T F F T T F F T T F F F F T F T F T F T F T F T F T F T F CPSC 121: Models of Computation
Recommend
More recommend