CPSC 121: Models of Computation Module 2: Conditionals and Logical - - PowerPoint PPT Presentation

cpsc 121 models of computation
SMART_READER_LITE
LIVE PREVIEW

CPSC 121: Models of Computation Module 2: Conditionals and Logical - - PowerPoint PPT Presentation

CPSC 121: Models of Computation Module 2: Conditionals and Logical Equivalences Module 2: Coming up... Pre-class quiz #3: due Wednesday September 19 th at 19:00. Assigned reading for the quiz: Epp, 4th edition: 2.5 Epp, 3rd edition: 1.5


slide-1
SLIDE 1

CPSC 121: Models of Computation

Module 2: Conditionals and Logical Equivalences

slide-2
SLIDE 2

CPSC 121 – 2018W T1 2

Module 2: Coming up...

Pre-class quiz #3: due Wednesday September 19th at 19:00.

Assigned reading for the quiz:

Epp, 4th edition: 2.5 Epp, 3rd edition: 1.5 http://en.wikipedia.org/wiki/Binary_numeral_system Also read:

http://www.ugrad.cs.ubc.ca/~cs121/current/handouts/signed- binary-decimal-conversions.html

Assignment #1 is due Monday September 24th at 16:00.

slide-3
SLIDE 3

CPSC 121 – 2018W T1 3

Module 2: Coming up...

Pre-class quiz #4: tentatively due Monday September 24th at 19:00.

Assigned reading for the quiz:

Epp, 4th edition: 2.3 Epp, 3rd edition: 1.3 Rosen, 6th edition: 1.5 up to the bottom of page 69. Rosen, 7th edition: 1.6 up to the bottom of page 75.

slide-4
SLIDE 4

CPSC 121 – 2018W T1 4

Module 2: Conditionals and Logical Equivalences

By the start of this class you should be able to

Translate back and forth between simple natural language statements and propositional logic, now with conditionals and biconditionals. Evaluate the truth of propositional logical statements that include conditionals and biconditionals using truth tables Given a propositional logic statement and an equivalence rule, apply the rule to create an equivalent statement.

slide-5
SLIDE 5

CPSC 121 – 2018W T1 5

Module 2: Conditionals and Logical Equivalences

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

CPSC 121: the BIG questions:

We are not quite ready yet to directly address any

  • f the big questions.

Our discussion of propositional logic gets us closer to proving facts about our algorithms. We will look at circuits a bit more, and talk about a multiplexer: a component that is very useful when building computers.

slide-6
SLIDE 6

CPSC 121 – 2018W T1 6

Module 2: Conditionals and Logical Equivalences

By the end of this unit, you should be able to

Explore alternate forms of propositional logic statements by application of equivalence rules, especially in order to simplify complex statements

  • r massage statements into a desired form.

Evaluate propositional logic as a “model of computation” for combinational circuits, including at least one explicit shortfall (e.g., referencing gate delays, fan-out, transistor count, wire length, instabilities, shared sub-circuits, etc.).

slide-7
SLIDE 7

CPSC 121 – 2018W T1 7

Module 2: Conditionals and Logical Equivalences

Module Outline:

Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises

slide-8
SLIDE 8

CPSC 121 – 2018W T1 8

Module 2.1: Logic vs Everyday English

Be careful! The meaning of if p then q in propositional logic is not quite the same as in normal language.

Consider: if it's 20ºC tomorrow, then I will come to UBC in shorts and T-shirt. Suppose it's -2ºC and snowing. Based on the above proposition, will I come to UBC in shorts and T- shirt?

a) Yes b) No c) Maybe

slide-9
SLIDE 9

CPSC 121 – 2018W T1 10

Module 2.1: Logic vs Everyday English

Consider the proposition

p: If you fail the final exam, then you will fail the course

You need to distinguish between

The truth value of p (whether or not I lied). The truth value of the conclusion (whether or not you failed the course).

slide-10
SLIDE 10

CPSC 121 – 2018W T1 11

Module 2.1: Logic vs Everyday English

If you fail the final exam, will you pass the course?

a) Yes b) No c) Maybe

slide-11
SLIDE 11

CPSC 121 – 2018W T1 13

Module 2.1: Logic vs Everyday English

If you pass the final exam, will you pass the course?

a) Yes b) No c) Maybe

slide-12
SLIDE 12

CPSC 121 – 2018W T1 15

Module 2: Conditionals and Logical Equivalences

Module Outline:

Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises

slide-13
SLIDE 13

CPSC 121 – 2018W T1 16

Module 2.2: Logical Equivalence Proofs

How do we write a logical equivalence proof?

We state the theorem we want to prove. We indicate the beginning of the proof by Proof: We start with one side and work towards the other,

  • ne step at a time,

without forgetting to justify each step usually we will simplify the more complicated proposition, instead of trying to complicate the simpler one.

We indicate the end of the proof by QED or

slide-14
SLIDE 14

CPSC 121 – 2018W T1 17

Module 2.2: Logical Equivalence Proofs

Example: prove that (~a ^ b) v a ≡ a v b Proof:

(~a ^ b) v a ≡ a v (~a ^ b) commutative law ≡ (a v ~a) ^ (a v b) distributive law ≡ ≡ a v b identity law

What is missing?

a) (a v b) b) F ^ (a v b) c) a ^ (a v b) d) Something else e) Not enough info to tell

slide-15
SLIDE 15

CPSC 121 – 2018W T1 19

Module 2.2: Logical Equivalence Proofs

Name Rule Name Rule Identity laws p ^ T ≡ p p v F ≡ p Universal bounds laws p ^ F ≡ F p v T ≡ T Idempotent laws p ^ p ≡ p p v p ≡ p Commutative laws p ^ q ≡ q ^ p p v q ≡ q v p Associative laws p ^ (q ^ r) ≡ (p ^ q) ^ r p v (q v r) ≡ (p v q) v r Distributive laws p v (q ^ r) ≡ (p v q) ^ (p v r) p ^ (q v r) ≡ (p ^ q) v (p ^ r) Absorption laws p v (p ^ q) ≡ p p ^ (p v q) ≡ p Negation laws p ^ ~p ≡ F p v ~p ≡ T Double negative law ~(~p) ≡ p DeMorgan's laws ~(p ^ q) ≡ (~p) v (~q) ~(p v q) ≡ (~p) ^ (~q) Definition of ⊕ p ⊕ q ≡ (p v q) ^ ~(p ^ q) Definition of → p → q ≡ ~p v q Contrapositive law p → q ≡ (~q) → (~p)

slide-16
SLIDE 16

CPSC 121 – 2018W T1 20

Module 2.2: Logical Equivalence Proofs

Examples: prove that

~p → ~q ≡ q → p ~p q ≡ (~p q) ~ (~q p) ∧ ∨ ∧ ∨

We will do these on the board with the slides providing a list of equivalences.

slide-17
SLIDE 17

CPSC 121 – 2018W T1 21

Module 2: Conditionals and Logical Equivalences

Module Outline:

Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises

slide-18
SLIDE 18

CPSC 121 – 2018W T1 22

Module 2.3: Multiplexers

Propositional Logic is not a perfect model of how gates work. To understand why, we will look at a multiplexer

A circuit that chooses between two or more values. In its simplest form, it takes 3 inputs

An input a, an input b, and a control input select. It outputs a if select is false, and b if select is true.

slide-19
SLIDE 19

CPSC 121 – 2018W T1 23

Module 2.3: Multiplexers

Truth table:

a b select

  • utput

F F F F F F T F F T F F F T T T T F F T T F T F T T F T T T T T

slide-20
SLIDE 20

CPSC 121 – 2018W T1 24

Module 2.3: Multiplexers

Here is one possible implementation: Let us see why this may not work as we expect...

select

slide-21
SLIDE 21

CPSC 121 – 2018W T1 25

Module 2.3: Multiplexers

Suppose a, b, select are initially T Assume the gate delay is 10ns

T T T T T F F

select

slide-22
SLIDE 22

CPSC 121 – 2018W T1 26

Module 2.3: Multiplexers

How long will it take before output reflects any changes in a, b, select and is stable?

a) 10ns b) 20ns c) 30ns d) 40ns e) It may never be stable

T T T T T F F

select ▷

slide-23
SLIDE 23

CPSC 121 – 2018W T1 28

Module 2.3: Multiplexers

Now we switch select to F. At time 5ns:

T F T T T F F

select

slide-24
SLIDE 24

CPSC 121 – 2018W T1 29

Module 2.3: Multiplexers

At time 10ns:

T F T T F F T

select

slide-25
SLIDE 25

CPSC 121 – 2018W T1 30

Module 2.3: Multiplexers

At time 20ns: Note: the output is now F

F F T T F T T

select

slide-26
SLIDE 26

CPSC 121 – 2018W T1 31

Module 2.3: Multiplexers

At time 30ns: Note: the output is now T again.

T F T T F T T

select

slide-27
SLIDE 27

CPSC 121 – 2018W T1 32

Module 2.3: Multiplexers

The cause of the problem:

the information from select travels on two different paths to the output these paths contain different numbers of gates so the shorter path may affect the output until the information on the longer path catches up.

slide-28
SLIDE 28

CPSC 121 – 2018W T1 33

Module 2.3: Multiplexers

Which one(s) of the following operation may cause an instability?

a) Changing a or b only b) Changing select, when at exactly one of a, b is F c) Changing select, when both a, b are F d) Both (a) and (b) e) None of (a), (b) or (c).

select ▷

slide-29
SLIDE 29

CPSC 121 – 2018W T1 35

Module 2.3: Multiplexers

Here is a multiplexer that avoid the instability:

select

slide-30
SLIDE 30

CPSC 121 – 2018W T1 36

Module 2: Conditionals and Logical Equivalences

Module Outline:

Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises

slide-31
SLIDE 31

CPSC 121 – 2018W T1 37

Module 2.4: More exercises

Consider the code:

if target = value then if lean-left-mode = true then call the go-left() routine else call the go-right() routine else if target < value then call the go-left() routine else call the go-right routine

Let gl mean “the go-left() routine is called”. Complete the following: gl ↔

slide-32
SLIDE 32

CPSC 121 – 2018W T1 38

Module 2.4: More exercises

Consider:

The Java [String] equals() method returns true if and only if the argument is not null and is a String

  • bject that represents the same sequence of

characters as this object. Let n1: the string is null n2: the argument is null nt: the method returns true s: the two objects are strings that represent the same sequence of characters.

slide-33
SLIDE 33

CPSC 121 – 2018W T1 39

Module 2.4: More exercises

Is the sentence logically equivalent to nt ↔ (n1 ^ n2) v s? Why or why not?

Prove:

(a ^ ~b) v (~a ^ b) ≡ (a v b) ^ ~ (a ^ b)