Models of Computation Boolean logic Logic circuits January 08, - - PowerPoint PPT Presentation

models of computation
SMART_READER_LITE
LIVE PREVIEW

Models of Computation Boolean logic Logic circuits January 08, - - PowerPoint PPT Presentation

CPSC 121 Models of Computation Boolean logic Logic circuits January 08, 2020 Patrice Belleville / Geoffrey Tien 1 Announcements Pre-lecture quiz #2 due Tuesday Jan.14, 19:00 Read Epp 4e/5e: Chapter 2.2 HW1 out soon, due Tuesday,


slide-1
SLIDE 1

CPSC 121 Models of Computation

Boolean logic Logic circuits

January 08, 2020 Patrice Belleville / Geoffrey Tien 1

slide-2
SLIDE 2

Announcements

  • Pre-lecture quiz #2 due Tuesday Jan.14, 19:00

– Read Epp 4e/5e: Chapter 2.2

  • HW1 out soon, due Tuesday, Jan.21, 19:00
  • Pre-lecture quiz #3 due Sunday, Jan.19, 19:00

– Read Epp 4e/5e: Chapter 2.5 – http://www.students.cs.ubc.ca/~cs-121/current/handouts /signed-binary- decimal-conversions.html – http://en.wikipedia.org/wiki/Binary_number

January 08, 2020 Patrice Belleville / Geoffrey Tien 2

slide-3
SLIDE 3

Logical operators

  • AND

∧ (between two variables or expressions)

  • OR

∨ (between two variables or expressions)

  • NOT

∼ (in front of a variable or expression)

  • Examples:

– 𝑍 = 𝐵 ∧ 𝐶 is read as "𝑍 equals 𝐵 AND 𝐶" – 𝑔 = 𝑦 ∨ 𝑧 is read as "𝑔 equals 𝑦 OR 𝑧" – 𝑎 = ~𝐵 is read as "𝑎 equals NOT 𝐵"

January 08, 2020 Patrice Belleville / Geoffrey Tien 3

slide-4
SLIDE 4

Truth tables

  • Shows the relationship between the values of the input

variables, and the value of the result of the operation

– compute the result, based on all possible combinations of the inputs

  • Example, inputs 𝑌, 𝑍, result 𝑎:

– let 𝑌 be "I'm nervous" – let 𝑍 be "My socks are too loose" – let 𝑎 be "Having a bad day at school", 𝑎 = 𝑌 ∧ 𝑍

January 08, 2020 Patrice Belleville / Geoffrey Tien 4

AND 𝑌 𝑍 𝑎 F F F F T F T F F T T T OR 𝐵 𝐶 𝐷 F F F F T T T F T T T T NOT 𝐺 𝐻 F T T F 𝑎 = 𝑌 ∧ 𝑍 𝐷 = 𝐵 ∨ 𝐶 𝐻 = ~𝐺

slide-5
SLIDE 5

Larger truth tables

  • As we introduce more variables, truth tables become larger to

accommodate all combinations of input values

– arrange the input combinations in a consistent, predictable order

  • Quick way:

– entries in rightmost input column alternate as "F T F T F T F T..." – entries in second column from right alternate as "F F T T F F T T ..." – entries in third column from right repeat as "F F F F T T T T ..." – fourth from right? – ... – What's the pattern for a system with 𝑙 variables?

January 08, 2020 Patrice Belleville / Geoffrey Tien 5

slide-6
SLIDE 6

Determining truth values for compound statements

  • Should I go to class? Let:

– 𝑏 = need it to graduate – 𝑐 = class is boring – 𝑑 = I'm stuck in traffic – 𝑒 = I slept in

  • 𝑕 = 𝑏 ∨ ~𝑐 ∧ ~(𝑑 ∨ 𝑒)

January 08, 2020 Patrice Belleville / Geoffrey Tien 6

via intermediate values

𝑏 𝑐 𝑑 𝑒 ? ? ? ? 𝑕 F F F F F F F T F F T F F F T T F T F F F T F T F T T F F T T T T F F F T F F T T F T F T F T T T T F F T T F T T T T F T T T T

slide-7
SLIDE 7

Digital logic circuits

January 08, 2020 Patrice Belleville / Geoffrey Tien 7

slide-8
SLIDE 8

Data representation

January 08, 2020 Patrice Belleville / Geoffrey Tien 8

  • Information in the real world can take many values, e.g.

– Temperature, weight, pressure (continuous, numeric) – Price, quantity (discrete, numeric) – Names, descriptions (discrete, alphabetic)

  • Data representation in digital systems uses voltage

– Voltage is also continuous – Control the voltage to two discrete levels

  • Two discrete voltage levels allow a binary alphabet

– {high, low}, {true, false}, {1, 0}

high low

slide-9
SLIDE 9

Logic gates

January 08, 2020 Patrice Belleville / Geoffrey Tien 9

  • Logic gates are electronic circuits that operate on one or more

input signals to produce an output signal(s).

– signal: a connection that can transmit one bit of information at a time

  • Electric signals exist throughout a digital system as high or

low voltages (we will call 1 or 0).

  • Gates are electronic circuits which produce the high and low

voltage equivalents of logic-1 (T) and logic-0 (F) output signals according to their specified truth tables

AND OR NOT, aka inverter

slide-10
SLIDE 10

From circuits to propositions

  • These gates correspond to the Boolean operations introduced

last class

– Can build circuits to evaluate logical propositions – e.g. "should I go to class?" 𝑕 = 𝑏 ∨ ~𝑐 ∧ ~(𝑑 ∨ 𝑒)

January 08, 2020 Patrice Belleville / Geoffrey Tien 10

...and back

AND OR NOT, aka inverter

  • Another useful (non-Boolean) function: XOR (exclusive-OR)

XOR 𝑌 𝑍 𝑎 F F F F T T T F T T T F 𝑎 = 𝑌 ⊕ 𝑍

slide-11
SLIDE 11

From circuits to propositions

  • Propositions can be used to model circuits

– Each variable corresponds to an input – The value of the proposition (for a given combination of input values) is the output of the circuit

January 08, 2020 Patrice Belleville / Geoffrey Tien 11

  • Example: the segments in a 7-segment display

– Each integer from 0 to 9 is represented by a specific combination of input values – We can write a proposition for each segment, which combinations of input values will activate the segment

slide-12
SLIDE 12

From circuits to propositions

  • Consider the following circuit:

January 08, 2020 Patrice Belleville / Geoffrey Tien 12

Exercise

  • Write a proposition corresponding to this circuit
  • What does this circuit compute?

– Complete a truth table for the proposition you obtained above – Study the truth table for patterns or characteristics, to express the circuit behaviour

The "bubble" means the value is inverted before entering the AND gate

slide-13
SLIDE 13

From circuits to propositions

  • What is the simplest logical expression that corresponds to the

following circuit?

January 08, 2020 Patrice Belleville / Geoffrey Tien 13

Exercise

Note the inversions on the outputs of the OR and AND gates These are called NOR and NAND gates and are logically equivalent to inverting the OR/AND functions. Also note the 3-input AND function.

slide-14
SLIDE 14

A (sort of) real problem

  • Consider the problem of designing a light that changes state

whenever any of the switches that control it is flipped. Ideally your solution would work with any number of switches!

January 08, 2020 Patrice Belleville / Geoffrey Tien 14

Light switches

?

slide-15
SLIDE 15

Light switches

  • How do we approach this?

– We first need to make sure we understand what we are designing – Then we use propositional logic to model the 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 𝑜 switches

January 08, 2020 Patrice Belleville / Geoffrey Tien 15

slide-16
SLIDE 16

Light switches

  • Making sure we understand what we are designing
  • Which of these would be usable (most useful) as the output of
  • ur circuit?

a) the switch is flipped b) the switch is on c) the light is on d) the light changed state

January 08, 2020 Patrice Belleville / Geoffrey Tien 16

Output

slide-17
SLIDE 17

Light switches

  • Making sure we understand what we are designing
  • Which of these would be usable (most useful) as the input of
  • ur circuit?

a) the switch is flipped b) the switch is on c) the light is on d) the light changed state

January 08, 2020 Patrice Belleville / Geoffrey Tien 17

Input

slide-18
SLIDE 18

Light switches

  • Make sure we understand the problem
  • For one switch, is the light on or off when the switch is "on"?

a) Always on b) Always off c) Depends, but a correct solution should always do the same thing d) Depends, and a correct solution might do different things at different times

January 08, 2020 Patrice Belleville / Geoffrey Tien 18

Requirements

slide-19
SLIDE 19

Light switches

  • Which circuit(s) is/are correct solution(s)?

a) b) c) d) two of (a), (b), (c) e) all three of (a), (b), (c)

January 08, 2020 Patrice Belleville / Geoffrey Tien 19

One switch

slide-20
SLIDE 20

Readings for this lesson

  • Pre-class quiz #2 due Tuesday Jan.14, 19:00

– Read Epp 4e/5e: Chapter 2.2

  • Homework #1 will be available soon!

– due Tuesday, Jan.21, 19:00

January 08, 2020 Patrice Belleville / Geoffrey Tien 20