cpsc 121 models of computation module 1 propositional
play

CPSC 121: Models of Computation Module 1: Propositional Logic By - PowerPoint PPT Presentation

CPSC 121: Models of Computation Module 1: Propositional Logic By the start of the class, you should be able to: Translate back and forth between simple natural language statements and propositional logic. Evaluate the truth of propositional


  1. CPSC 121: Models of Computation Module 1: Propositional Logic By the start of the class, you should be able to: Translate back and forth between simple natural language statements and propositional logic. Evaluate the truth of propositional logic statements Module 1: Propositional Logic using truth tables. Translate back and forth between propositional logic statements and circuits that assess the truth of those statements. CPSC 121 – 2020W T2 2 Module 1: Propositional Logic Module 1: Coming up... Quiz 1 feedback: What is coming up? Very very well done overall. Second pre-class quiz: due tomorrow September Be careful: 16 th at 19:00. ~a v ~b is not the same as ~(a v b). Assigned reading for the quiz: ~a ^ ~b is not the same as ~(a ^ b). We will discuss the open-ended question a bit later. Epp, 5 th or 4 th edition: 2.2 Epp, 3 rd edition: 1.2 Rosen, 6 th or 7 th edition: 1.1 from page 6 onwards. Assignment #1 due Monday September 28 th , 2020 at 19:00. CPSC 121 – 2020W T2 3 CPSC 121 – 2020W T2 4

  2. Module 1: Coming up... Module 1: Propositional Logic ? ? ? What is coming up? CPSC 121: the BIG questions: ? ? Third pre-class quiz: due Wednesday September We are not yet ready to directly address any of the 23 rd at 19:00. big questions. ? ? Assigned reading for the quiz: But this module lays out the ground work for all of ? ? them. ? Epp, 5 th edition: 2.5 Epp, 4th edition: 2.5 + ? http://www.ugrad.cs.ubc.ca/~cs121/current/handouts ? /signed-binary-decimal-conversions.html ? ? http://en.wikipedia.org/wiki/Binary_numeral_system ? ? ? CPSC 121 – 2020W T2 5 CPSC 121 – 2020W T2 7 Module 1: Propositional Logic Module 1: Propositional Logic By the end of this module, you should be able Module outline: to: Writing a truth table Build computational systems to solve real problems, From circuits to propositions using both propositional logic expressions and Light switches equivalent digital logic circuits, 7-segment displays The light switches problem from the 1st pre-class quiz. More exercises The 7- or 4-segment LED displays we will discuss in class. CPSC 121 – 2020W T2 8 CPSC 121 – 2020W T2 9

  3. Module 1.1: Writing a truth table Module 1.1: Writing a truth table Must the combinations in a truth table be listed We will always start with false (you will see why in a specific order? later). With 3 variables: Our recommendation: the first column contains 4 false followed by 4 true. the second column contains 2 false, 2 true, 2 false, 2 true. Why? and the third column alternates false with true. CPSC 121 – 2020W T2 10 CPSC 121 – 2020W T2 11 Module 1.2: Writing a truth table Module 1.2: Writing a truth table With k variables: Another way to get the same list of combinations: the first column has 2 k-1 false and then 2 k-1 true Write a truth table with k-1 variables twice. the second column has 2 k-2 false and then 2 k-2 true (twice) etc. F F F T T F T T F F F T T F T T CPSC 121 – 2020W T2 12 CPSC 121 – 2020W T2 13

  4. Module 1.2: Writing a truth table Module 1.2: Writing a truth table Another way to get the same list of combinations: Another way to get the same list of combinations: Write a truth table with k-1 variables twice. Write a truth table with k-1 variables twice. Add false in front of the first copy, and true in front of Add false in front of the first copy, and true in front of the second one. the second one. F F F F F F T F F T T F F T F T T F T T F F T F F F T T F T T F T T F T T T T T CPSC 121 – 2020W T2 14 CPSC 121 – 2020W T2 15 Module 1: Propositional Logic Module 1.2: From circuits to propositions We can use propositions to model circuits: Module outline: Each variable corresponds to an input. Writing a truth table The value of the proposition (for a given combination of input values) is the output of the circuit. From circuits to propositions Example: the segments in a 7 segment display Light switches 7-segment displays More exercises CPSC 121 – 2020W T2 16 CPSC 121 – 2020W T2 17

  5. Module 1.2: From circuits to propositions Module 1.2: From circuits to propositions Example (continued) We will spend time designing circuits, but first We use ? inputs (variables). how to we go from a circuit to the proposition Each integer from 0 to 9 is represented by a specific that models its output? combination of input values. Example: what does this circuit compute? We can write a proposition that tells us for which combinations of input values the segment should be turned on. CPSC 121 – 2020W T2 18 CPSC 121 – 2020W T2 19 Module 1.2: From circuits to propositions Module 1.2: From circuits to propositions To find the logical expression that corresponds Example: to a circuit's output: First we write the operator for the gate that produces the circuit's output. The operator's left argument is the expression for the circuit connected to the gate's first input. The operator's right argument is the expression for the circuit connected to the gate's second input. What does this circuit compute? This is our first algorithm! CPSC 121 – 2020W T2 20 CPSC 121 – 2020W T2 21

  6. Module 1.2: From circuits to propositions Module 1: Propositional Logic What is the simplest logical expression that Module outline: corresponds to the following circuit? Writing a truth table From circuits to propositions Light switches 7-segment displays More exercises CPSC 121 – 2020W T2 22 CPSC 121 – 2020W T2 23 Module 1.3: Light switches Module 1.3: Light switches How do we approach this? Consider again: We first need to make sure we understand what we Design a light that changes state whenever any of are designing. the switches that control it is flipped. Ideally your Then we use propositional logic to model the solution would work with any number! circuit’s desired output. It’s helpful to start with very simple versions of the problem First try 1 switch. Then try 2 switches. Then try 3 switches. Then see if we can generalize to n switches. CPSC 121 – 2020W T2 24 CPSC 121 – 2020W T2 25

  7. Module 1.3: Light switches Module 1.3: Light switches Making sure we understand what we are Making sure we understand what we are designing. designing. Which of these would be usable (most useful) as Which of these would be usable (most useful) as the output of our circuit? input to our circuit? a) the switch is flipped a) the switch is flipped b) the switch is on b) the switch is on c) the light is on c) the light is on d) the light changed state d) the light changed state ▷ ▷ CPSC 121 – 2020W T2 26 CPSC 121 – 2020W T2 28 Module 1.3: Light switches Module 1.3: Light switches One switch: One switch: make sure we understand the problem first. Which circuit(s) is/are correct solution(s) ? Is the light on or off when the switch is “on”? a) a) Always on. b) b) Always off. c) Depends, but a correct solution should always do c) the same thing. d) Depends, and a correct solution might do different things at different times. d) two of a, b, c. e) all three of a, b, c. ▷ ▷ CPSC 121 – 2020W T2 30 CPSC 121 – 2020W T2 32

  8. Module 1.3: Light switches Module 1.3: Light switches Two switches: Two switches: which circuit(s) work(s) ? make sure we understand the problem first. a) Is the light on or off when both switches are “on”? b) a) Always on. c) b) Always off. c) Depends, but a correct solution should always do the same thing for a given setting of the switches. d) Both a and b work. d) Depends, and a correct solution might do different e) Both b and c work. things at different times for the same setting of the switches. ▷ ▷ CPSC 121 – 2020W T2 34 CPSC 121 – 2020W T2 36 Module 1.3: Light switches Module 1.3: Light switches Circuit design tip: if you are not sure where to What pattern do we observe? start while designing a circuit, The light is ON if First determine the inputs and the output Then build the truth table. Now to generalize to n switches... Finally turn it into a circuit. For the three switches problem: What do you think the answer is? We can decide arbitrarily what the output is when all three switches are OFF. How can we convince ourselves that it is correct? This determines the output for all other cases! Mathematical induction Let's see how... CPSC 121 – 2020W T2 38 CPSC 121 – 2020W T2 39

  9. Module 1: Propositional Logic Module 1.3: 7-segment displays Module outline: Problem: design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) Writing a truth table in the shape illustrated below. From circuits to propositions Light switches 7-segment displays More exercises CPSC 121 – 2020W T2 40 CPSC 121 – 2020W T2 41 Module 1.4: 7-segment displays Module 1.4: 7-segment displays How do we represent the inputs? Understanding: what is the smallest number of inputs (wires going into the circuit) possible? Use ? logical (true/false) values. a) 1 Each integer represented by 1 specific combination of input values. b) 4 Could we do this arbitrarily? c) 7 Yes! d) 10 But we won't e) None of the above How many of you know about binary representation? ▷ CPSC 121 – 2020W T2 42 CPSC 121 – 2020W T2 43

Recommend


More recommend