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

cpsc 121 models of computation
SMART_READER_LITE
LIVE PREVIEW

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

CPSC 121: Models of Computation Unit 2: Conditionals and Logical Equivalences CPSC 121 2011W T2 Unit 2: Conditionals and Logical Equivalences The third online quiz is due Sunday at 21:00. Assigned reading for the quiz: Epp, 4 th


slide-1
SLIDE 1

CPSC 121 – 2011W T2

CPSC 121: Models of Computation

Unit 2: Conditionals and Logical Equivalences

slide-2
SLIDE 2

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

The third online quiz is due Sunday at 21:00.

 Assigned reading for the quiz:

 Epp, 4 th edition: 2.5  Epp, 3 rd edition: 1.5  Rosen, any edition: not much

 http://en.wikipedia.org/wiki/Binary_numeral_system

 Also read:

 http://www.ugrad.cs.ubc.ca/~cs121/2009W1/Handouts/signed-

binary-decimal-conversions.html

Assignment #1 is due Thursday at 17:00.

slide-3
SLIDE 3

CPSC 121 – 2011W T2

Unit 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-4
SLIDE 4

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

Quiz 2 feedback:

 Very well done.  We discussed the open-ended question as part of

the previous topic, so there is no need to go over it again.

slide-5
SLIDE 5

CPSC 121 – 2011W T2

Unit 1: Propositional Logic

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

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 a circuits a bit more, and talk about a multiplexer: an component that is very useful when building computers.

slide-6
SLIDE 6

CPSC 121 – 2011W T2

Unit 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 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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-8
SLIDE 8

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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-9
SLIDE 9

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

a) Yes b) No c) Maybe

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

a) Yes b) No c) Maybe

slide-10
SLIDE 10

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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,

 one 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-11
SLIDE 11

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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-12
SLIDE 12

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

Name Rule Name Rule Identity law p ^ T ≡ p p v F ≡ p Domination law p ^ F ≡ F p v T ≡ T Idempotent law p ^ p ≡ p p v p ≡ p Commutative law p ^ q ≡ q ^ p p v q ≡ q v p Associative law p ^ (q ^ r) ≡ (p ^ q) ^ r p v (q v r) ≡ (p v q) v r Distributive law p v (q ^ r) ≡ (p v q) ^ (p v r) p ^ (q v r) ≡ (p ^ q) v (p ^ r) Absorption law p v (p ^ q) ≡ p p ^ (p v q) ≡ p Negation law p ^ ~p ≡ F p v ~p ≡ T Double negative law ~(~p) ≡ p DeMorgan's law ~(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-13
SLIDE 13

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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-14
SLIDE 14

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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-15
SLIDE 15

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

Here is one possible implementation (call select “c”): Let us see why this may not work as we expect...

slide-16
SLIDE 16

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

T T T T T F F

slide-17
SLIDE 17

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

a) 5ns b) 10ns c) 20ns d) 30ns e) 40ns f) It may never be stable g) None of the above.

T T T T T F F

slide-18
SLIDE 18

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

T F T T T F F

slide-19
SLIDE 19

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

At time 10ns:

T F T T F F T

slide-20
SLIDE 20

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

F F T T F T T

slide-21
SLIDE 21

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

T F T T F T T

slide-22
SLIDE 22

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

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

a) Changing a only b) Changing b only c) Changing c, when at least one of a, b is F d) Both (a) and (b) e) All of (a), (b) and (c) f) None of (a), (b) and (c)

slide-23
SLIDE 23

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

Here is a multiplexer that avoid the instability:

slide-24
SLIDE 24

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

For additional practice:

 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-25
SLIDE 25

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

 Consider: “The Java [String] equals() method returns true if

and only if the argument is not null and is a String object 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.

 Is the sentence logically equivalent to nt ↔ (n1 ^ n2) v s?

Why or why not?

slide-26
SLIDE 26

CPSC 121 – 2011W T2

Unit 2: Conditionals and Logical Equivalences

 Prove:

(a ^ ~b) v (~a ^ b) (a v b) ^ ~ (a ^ b) 