cpsc 121 models of computation
play

CPSC 121: Models of Computation Translate back and forth between - PowerPoint PPT Presentation

Pre Lecture Learning Goals By the start of the class, you should be able to: CPSC 121: Models of Computation Translate back and forth between simple natural language statements and propositional logic. Evaluate the truth of


  1. Pre – Lecture Learning Goals  By the start of the class, you should be able to: CPSC 121: Models of Computation  Translate back and forth between simple natural language statements and propositional logic.  Evaluate the truth of propositional logic statements using truth tables. Unit 1: Propositional Logic  Translate back and forth between propositional logic statements and circuits that assess the truth of those statements. George Tsiknis Based on slides by Patrice Belleville and Steve Wolfman Unit 1 - Propositional Logic 2 Quiz 1 Feedback In-Class Learning Goals   By the end of this unit, you should be able to:  Build computational systems to solve real problems, using both propositional logic expressions and equivalent digital logic circuits. o The light switches problem from the 1st online quiz. o The 7- or 4-segment LED displays we will discuss in class.  Building ground work for the Course Big Goals:  How do we model computational systems?  How do we build devices to compute?  We will discuss the open-ended question a bit later. Unit 1 - Propositional Logic Unit 1 - Propositional Logic 3 4 1

  2. Making a Truth Table Circuits to Logic Expressions  Note: when you write a truth table, always list the  How do we find the logical expression that combinations in the same order. corresponds to a circuit's output?  For instance, with 3 variables  First we write the operator for the gate that produces the o the first column contains 4 false followed by 4 true. circuit's output. o the second column contains 2 false, 2 true, 2 false, 2 true.  The operator's left argument is the expression that o and the third column alternates false with true. corresponds to the circuit for the first input of that gate.  With k variables, the first column has 2 k-1 false and then 2 k-1 true, the second column has 2 k-2 false and then 2 k-2 true  The operator's right argument is the expression that (twice), etc. corresponds to the circuit for the second input of that gate.  Another way is to  Build the logical expression for the left and right argument  start with the last column and one variable which will be the same way. assigned F and T  add one variable at a time duplicating what you have so far This is our First algorithm! and setting the new variable to F for the first copy and T for the second Unit 1 - Propositional Logic Unit 1 - Propositional Logic 5 6 Example 1 Example 2 What logical expression corresponds to the following  What does this circuit compute? circuit? a ⊕ c a ⊕ b ( ) ⊕ ( ) a ⊕ b c ⊕ d ( ) v ( ) ( ) ^ ~( ) Unit 1 - Propositional Logic Unit 1 - Propositional Logic 7 8 2

  3. Problem : Three-Switch How do we approach this? ?  Try to understand the “story”:  Design a circuit that changes the state of the light whenever any of the switches that control it is flipped.  what are the inputs and outputs?  Ideally your solution would work with any number!  Formalize the problem:  “Let a,b,c represent 3 switches from left to right”  Solve in propositional logic:  may create a truth table with the inputs and outputs  Try a simpler problem: o start with 1 switch; then try 2; then try 3 switches. o see if we can generalize to n switches. ?  Test your answer:  try some cases, or check some properties Unit 1 - Propositional Logic Unit 1 - Propositional Logic 9 10 ? ? One Switch One Switch  Let’s use: S = switch is on  Identifying inputs/outputs: consider these: out = light is on  Input 1 : the switch flipped  Truth table:  Input 2 : the switch is on  Output 1 : the light is on  Output 2 : the light changed state  Which are most useful for this problem?  Which of the following circuits solves the problem? a. Input 1 and Output 1 b. Input 1 and Output 2 1. c. Input 2 and Output 1 d. Input 2 and Output 2 2. e. None of these 3. Unit 1 - Propositional Logic Unit 1 - Propositional Logic 11 12 3

  4. Two Switches Two Switches ? ?  Circuit design tip: if you are not sure where to start while  Make sure we understand the problem first. designing a circuit,  Is the light on or off when both switches are “on”?  First build the truth table. A. On in every correct solution.  Then turn it into a circuit. B. Off in every correct solution.  For the two switches problem: C. Depends, but a correct solution should always do the  We can decide arbitrarily what the output is when all switches same thing with the same settings for the switches.. are OFF. D. Depends, and a correct solution might do different  This determines the output for all other cases! things at different times with the same settings for the  Let's see how... switches.  Truth table (suppose light OFF when all switches are E. Neither on nor off. OFF): Unit 1 - Propositional Logic Unit 1 - Propositional Logic 13 14 Two Switches Three Switches ? ?  Fill in the circuit’s truth table:  Two switches: which circuit(s) work(s) ?  Which output column(s) is(are) correct ? A B C D E None s 1 s 2 s 3 out out out out of T T T T F F T them T T F F T T F T F T F T F T T F F T F T F F T T F T F T F T F T F T F F F T T F F T F F F F T T F Unit 1 - Propositional Logic Unit 1 - Propositional Logic 15 16 4

  5. Three Switches 7-Segment LED Display ?  Suppose we decided to have the light OFF when all  Problem: design a circuit that displays the numbers 0 switches are OFF. What pattern do we observe? through 9 using seven LEDs (lights) in the shape  The light is ON if illustrated below.  What is the formula for it?   Now to generalize to n switches...  What do you think the answer is?   How can we convince ourselves that it is correct?  Mathematical induction Unit 1 - Propositional Logic Unit 1 - Propositional Logic 17 18 7-Segment LED Display 7-LED Display  Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape  Understanding the story: illustrated above. How many inputs to our circuit are there?  First: what’s the circuit’s job? a. One b. Seven  c. Ten d. Four e. None of these Unit 1 - Propositional Logic 19 20 5

  6. 7-LED Display – Input Values 7-LED Display-Input Lines  How many different “parameters” (wires) carry those  How many different values (messages) must the circuit understand? messages? (This is different than “how many inputs are there”.) (Not quite parameter like in CPSC 110… more like an input wire). a. One a. One b. Seven b. Seven c. Ten c. Ten d. Four d. Four e. None of these e. None of these 21 22 7-LED Display-Inputs 7-LED Display-Representing Inputs  How do we represent the inputs?  Here's how we will represent the inputs:  Use ? logical (true/false) values.  Each integer represented by 1 specific combination. # a b c d  Could we do this randomly? 0 F F F F 1 F F F T o Yes! 2 F F T F  But we won't 3 F F T T o How many of you know about binary representation? 4 F T F F  How many values we can represent with 5 F T F T  1 propositional variable : 6 F T T F 7 F T T T  2 propositional variables : 8 T F F F  3 " " : 9 T F F T  n " " : ... Notice the order: F's first. Unit 1 - Propositional Logic Unit 1 - Propositional Logic 23 24 6

  7. 7-LED Display-Outputs Simulate 7-LED Display  Understanding Outputs:  Let's simulate it with people (raising their hands) ...  Which other person's algorithm  How many outputs are there? do you need to know about? a. 1 a. No one else's b. 4 c. 7 b. Your neighbours d. 10 c. The person opposite to e. None of the above you d. Everybody else's e. None of the above . 26 Unit 1 - Propositional Logic Unit 1 - Propositional Logic 25 26 Analyzing One Segment Analyzing One Segment  What’s the truth table for the lower -left segment?  From the truth table, we can make an expression for each true row and OR them together. a. b. c. d. e. # a b c d out None of out out # a b c d out out Which logical statement is true 0 F F F F T these. F 0 0 F F F F F T only in this row? 1 F F F T F T 2 1 F F F T T F 2 F F T F T a. ~a  ~b  c  ~d F 6 2 F F T F F T 3 F F T T F b. a  b  c  d 8 3 F F T T T T F 4 F T F F F c. ~a  ~b  c  ~d 4 F T F F T 4 F F 5 F T F T F d. a  b  ~c  d T 7 5 F T F T T F 6 F T T F T F 9 6 F T T F F T e. None of these 7 F T T T F 3 7 F T T T T T F 8 T F F F T F 1 8 T F F F F T 9 T F F T F T 5 9 T F F T T F 27 28 7

Recommend


More recommend