CPSC 121: Models of Computation Instructor: Bob Woodham - - PowerPoint PPT Presentation

cpsc 121 models of computation
SMART_READER_LITE
LIVE PREVIEW

CPSC 121: Models of Computation Instructor: Bob Woodham - - PowerPoint PPT Presentation

CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2009/2010, Section 203 CPSC 121: Models of Computation Menu January 8, 2010 Topics:


slide-1
SLIDE 1

CPSC 121: Models of Computation

Instructor: Bob Woodham woodham@cs.ubc.ca

Department of Computer Science University of British Columbia

Lecture Notes 2009/2010, Section 203

CPSC 121: Models of Computation

slide-2
SLIDE 2

Menu January 8, 2010

Topics: Propositional Logic Logic Gates Pre-class reading: Today: Epp 1.1, 1.2, 1.4 Next week: Epp 1.5, 1.3 Handouts: Lab 0 (Part 1 and Part 2) Lab 1 Reminders: Online Quizzes 1 and 2 (deadline 9:00pm Sun, Jan 10) Labs and tutorials begin week of January 11 — Note: Lab 1 has a pre-lab component (worth marks) www: http://www.ugrad.cs.ubc.ca/~cs121/ WebCT Vista: http://www.vista.ubc.ca

CPSC 121: Models of Computation

slide-3
SLIDE 3

Example Propositions (Summary)

Proposition 1: 2 + 3 = 5 Proposition 2: 5 + 3 × 5 = 20 Proposition 3: Intel’s original Pentium processor chip performed floating point division properly Proposition 4: (Goldbach) Every positive even integer greater than 2 can be written as the sum of two primes Proposition 5: Let n be a natural number. Then the natural number p(n) = n2 + n + 41 is prime Proposition 6: (Euler) There are no positive integers a, b, c, d, such that a4 + b4 + c4 = d4

CPSC 121: Models of Computation

slide-4
SLIDE 4

Propositional Logic

A proposition is a statement that is true or false (but not both) We combine propositions together to create new propositions, called compound propositions We use logical connectives to combine propositions. Logical connectives also are called logical operators or Boolean

  • perators after the English mathematician George Boole

Three logical connectives, familiar from natural language, are: and, or and not

CPSC 121: Models of Computation

slide-5
SLIDE 5

Logical Connectives: and, or and not

Let p and q be propositions. Then, p and q, called the conjunction of p and q, is written as p ∧ q p or q, called the disjunction of p and q, is written as p ∨ q not p is called the negation of p and is written as ∼ p (or ¬p or p) Notes: Notation can differ among authors and communities Although intuition about the meaning of logical connectives derives from natural language, we formally define their meaning using truth tables

CPSC 121: Models of Computation

slide-6
SLIDE 6

Truth Table: not

Let p be a propositional variable p T F Start with truth values for p (1st column)

CPSC 121: Models of Computation

slide-7
SLIDE 7

Truth Table: not

Let p be a propositional variable p ∼p T F F T Start with truth values for p (1st column) Add truth values for ∼p (2nd column)

CPSC 121: Models of Computation

slide-8
SLIDE 8

Truth Table: not

Let p be a propositional variable p ∼p T F F T Start with truth values for p (1st column) Add truth values for ∼p (2nd column)

CPSC 121: Models of Computation

slide-9
SLIDE 9

Truth Table (2 Propositional Variables)

Let p and q be two propositional variables. p T T F F Start with truth values for p (1st column)

CPSC 121: Models of Computation

slide-10
SLIDE 10

Truth Table (2 Propositional Variables)

Let p and q be two propositional variables. p q T T T F F T F F Start with truth values for p (1st column) Add truth values for q (2nd column)

CPSC 121: Models of Computation

slide-11
SLIDE 11

Truth Table (2 Propositional Variables)

Let p and q be two propositional variables. p q T T ∗ T F ∗ F T ∗ F F ∗ Start with truth values for p (1st column) Add truth values for q (2nd column) Now all possible combinations of truth values for p and q are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider

CPSC 121: Models of Computation

slide-12
SLIDE 12

Truth Table (2 Propositional Variables)

Let p and q be two propositional variables. p q T T ∗ T F ∗ F T ∗ F F ∗ Start with truth values for p (1st column) Add truth values for q (2nd column) Now all possible combinations of truth values for p and q are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider

CPSC 121: Models of Computation

slide-13
SLIDE 13

Truth Tables: and and or

p ∧ q p q p ∧ q T T T T F F F T F F F F Add truth values for p ∧ q (3rd column)

CPSC 121: Models of Computation

slide-14
SLIDE 14

Truth Tables: and and or

p ∧ q p ∨ q p q p ∧ q p ∨ q T T T T T F F T F T F T F F F F Add truth values for p ∧ q (3rd column) Add truth values for p ∨ q (4th column)

CPSC 121: Models of Computation

slide-15
SLIDE 15

Truth Tables: and and or

p ∧ q p ∨ q p q p ∧ q p ∨ q T T T T T F F T F T F T F F F F Add truth values for p ∧ q (3rd column) Add truth values for p ∨ q (4th column)

CPSC 121: Models of Computation

slide-16
SLIDE 16

Logical Connectives and, or and not are Universal

There are other logical connectives, as we shall see. But, and,

  • r and not are “universal”

Any propositional formula can be expressed using these three and only these three logical connectives

CPSC 121: Models of Computation

slide-17
SLIDE 17

Truth Table: xor

English has another meaning for “or” which we call exclusive or (xor) and denote ⊕ p ⊕ q p q p ⊕ q T T F T F T F T T F F F

CPSC 121: Models of Computation

slide-18
SLIDE 18

Truth Table: xor

English has another meaning for “or” which we call exclusive or (xor) and denote ⊕ p ⊕ q p q p ⊕ q T T F T F T F T T F F F

CPSC 121: Models of Computation

slide-19
SLIDE 19

More Examples

Six (6) not very interesting examples: T, 3 p q T T T T T F T F T T F F T Column 3 is always T.

CPSC 121: Models of Computation

slide-20
SLIDE 20

More Examples

Six (6) not very interesting examples: T, F , 3 4 p q T F T T T F T F T F F T T F F F T F Column 3 is always T. Column 4 is always F .

CPSC 121: Models of Computation

slide-21
SLIDE 21

More Examples

Six (6) not very interesting examples: T, F , p, 3 4 5 p q T F p T T T F T T F T F T F T T F F F F T F F Column 3 is always T. Column 4 is always F . Column 5 is p.

CPSC 121: Models of Computation

slide-22
SLIDE 22

More Examples

Six (6) not very interesting examples: T, F , p, not p (denoted ∼p), 3 4 5 6 p q T F p ∼p T T T F T F T F T F T F F T T F F T F F T F F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼p.

CPSC 121: Models of Computation

slide-23
SLIDE 23

More Examples

Six (6) not very interesting examples: T, F , p, not p (denoted ∼p), q, 3 4 5 6 7 p q T F p ∼p q T T T F T F T T F T F T F F F T T F F T T F F T F F T F Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼p. Column 7 is q.

CPSC 121: Models of Computation

slide-24
SLIDE 24

More Examples

Six (6) not very interesting examples: T, F , p, not p (denoted ∼p), q, not q (denoted ∼q) 3 4 5 6 7 8 p q T F p ∼p q ∼q T T T F T F T F T F T F T F F T F T T F F T T F F F T F F T F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼p. Column 7 is q. Column 8 is ∼q

CPSC 121: Models of Computation

slide-25
SLIDE 25

More Examples

Six (6) not very interesting examples: T, F , p, not p (denoted ∼p), q, not q (denoted ∼q) 3 4 5 6 7 8 p q T F p ∼p q ∼q T T T F T F T F T F T F T F F T F T T F F T T F F F T F F T F T Column 3 is always T. Column 4 is always F . Column 5 is p. Column 6 is ∼p. Column 7 is q. Column 8 is ∼q

CPSC 121: Models of Computation

slide-26
SLIDE 26

Question?

How many distinct Boolean operators are there of 2 Boolean variables? Answer: There are 24 = 16 Consider the truth table template we saw before: p q T T ∗ T F ∗ F T ∗ F F ∗ The truth table has 4 rows since there are 2 × 2 distinct combinations of truth values for p and q. For each row, we have an entry, denoted by ∗, that can be either true or false. Thus, there are 24 = 16 distinct truth tables for 2 Boolean variables

CPSC 121: Models of Computation

slide-27
SLIDE 27

Logic Gates

AND OR XOR NOT

NOT input

  • utput

1 1 OR input

  • utput

1 1 1 1 1 1 1 AND input

  • utput

1 1 1 1 1 XOR input

  • utput

1 1 1 1 1 1

CPSC 121: Models of Computation

slide-28
SLIDE 28

Logic Gates

NAND NOR

NAND input

  • utput

1 1 1 1 1 1 1 NOR input

  • utput

1 1 1 1 1

CPSC 121: Models of Computation

slide-29
SLIDE 29

2-input NAND and NOR Gates Each are Universal

NOT, AND and OR gates can be implemented using only NAND gates (left side) or only NOR gates (right side).

CPSC 121: Models of Computation

slide-30
SLIDE 30

All 16 Logical Operators (with “Gate” Names)

B ∗ B X N N N U ∗ U N A A X O O N O F ∗ F O N N O T T O p q R p ∗ q R D D R q p R T T T T T T T T T T F F F F F F F F T F T T T T F F F F T T T T F F F F F T T T F F T T F F T T F F T T F F F F T F T F T F T F T F T F T F T F

CPSC 121: Models of Computation

slide-31
SLIDE 31

All 16 Logical Operators (with “Gate” Names)

B ∗ B X N N N U ∗ U N A A X O O N O F ∗ F O N N O T T O p q R p ∗ q R D D R q p R T T T T T T T T T T F F F F F F F F T F T T T T F F F F T T T T F F F F F T T T F F T T F F T T F F T T F F F F T F T F T F T F T F T F T F T F

∗ The operator whose truth values are given in this column is

called implication. Implication is very important in formal logic (and we’ll return to it shortly). Note, however, that implication is not a named gate (in hardware)

CPSC 121: Models of Computation

slide-32
SLIDE 32

All 16 Logical Operators (with “Gate” Names)

B ∗ B X N N N U ∗ U N A A X O O N O F ∗ F O N N O T T O p q R p ∗ q R D D R q p R T T T T T T T T T T F F F F F F F F T F T T T T F F F F T T T T F F F F F T T T F F T T F F T T F F T T F F F F T F T F T F T F T F T F T F T F

∗ The operator whose truth values are given in this column is

called implication. Implication is very important in formal logic (and we’ll return to it shortly). Note, however, that implication is not a named gate (in hardware)

CPSC 121: Models of Computation

slide-33
SLIDE 33

Why Truth Tables?

We use truth tables to:

1

Define the meaning of logical connectives

2

Construct (simple) proofs in propositional logic

3

Design (simple) combinational circuits

CPSC 121: Models of Computation

slide-34
SLIDE 34

Truth Table (3 Propositional Variables)

Let p, q and r be three propositional variables p T T T T F F F F Start with truth values for p (1st column).

CPSC 121: Models of Computation

slide-35
SLIDE 35

Truth Table (3 Propositional Variables)

Let p, q and r be three propositional variables p q T T T T T F T F F T F T F F F F Start with truth values for p (1st column). Add truth values for q (2nd column).

CPSC 121: Models of Computation

slide-36
SLIDE 36

Truth Table (3 Propositional Variables)

Let p, q and r be three propositional variables p q r T T T T T F T F T T F F F T T F T F F F T F F F Start with truth values for p (1st column). Add truth values for q (2nd column). Add truth values for r (3rd column).

CPSC 121: Models of Computation

slide-37
SLIDE 37

Truth Table (3 Propositional Variables)

Let p, q and r be three propositional variables p q r T T T ∗ T T F ∗ T F T ∗ T F F ∗ F T T ∗ F T F ∗ F F T ∗ F F F ∗ Start with truth values for p (1st column). Add truth values for q (2nd column). Add truth values for r (3rd column). Now all possible combinations of truth values for p, q and r are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider

CPSC 121: Models of Computation

slide-38
SLIDE 38

Truth Table (3 Propositional Variables)

Let p, q and r be three propositional variables p q r T T T ∗ T T F ∗ T F T ∗ T F F ∗ F T T ∗ F T F ∗ F F T ∗ F F F ∗ Start with truth values for p (1st column). Add truth values for q (2nd column). Add truth values for r (3rd column). Now all possible combinations of truth values for p, q and r are represented and we can add additional columns for the truth values of the particular compound statements we wish to consider

CPSC 121: Models of Computation

slide-39
SLIDE 39

(Harder) Question

How many distinct Boolean operators are there of n Boolean variables? Answer: There are 2(2n) The truth table has 2n rows since there are that number of distinct combinations of truth values for the n variables. For each row, we have an entry that can be either true or false. Thus, there are 2(2n) distinct truth tables for n Boolean variables We use truth tables as a proof method for propositional logic. But, this is feasible only when the number of variables is small. There are other proof methods for propositional logic that we will need to consider

CPSC 121: Models of Computation