Chapte Chapter 1: Nuts and ts and Bolts CS105: Great Insights in - - PowerPoint PPT Presentation

chapte chapter 1 nuts and ts and bolts
SMART_READER_LITE
LIVE PREVIEW

Chapte Chapter 1: Nuts and ts and Bolts CS105: Great Insights in - - PowerPoint PPT Presentation

Chapte Chapter 1: Nuts and ts and Bolts CS105: Great Insights in Com ights in Computer Science Comput omputers Design: a hierarchy of par hy of parts Interactions between par een parts are simple and well-defined They are


slide-1
SLIDE 1

Chapte Nuts and

CS105: Great Insights in Com

Chapter 1: ts and Bolts

ights in Computer Science

slide-2
SLIDE 2

Comput

  • Design: a hierarchy of par
  • Interactions between par

well-defined

  • They are dependent not

technology as on ideas

  • These ideas have almos

the electronics out of w built

  • mputers

hy of parts een parts are simple and e dependent not so much on

  • n ideas

e almost nothing to do with

  • ut of which computers are
slide-3
SLIDE 3

From thinking

  • George Boole:
  • logic of human thought

thinking to bits

an thought -> math operations

slide-4
SLIDE 4

From thinking

  • George Boole:
  • logic of human thought
  • invented a language

manipulating logical determining whether true (Boolean Algeb

thinking to bits

an thought -> math operations anguage for describing and

  • gical statements and

hether or not they were Algebra)

slide-5
SLIDE 5

From thinking

  • George Boole:
  • logic of human thought
  • invented a language

manipulating logical determining whether true (Boolean Algeb

  • Claude Shannon: Build

equivalent to expressions

thinking to bits

an thought -> math operations anguage for describing and

  • gical statements and

hether or not they were Algebra) hannon: Build electrical circuits pressions in Boolean Algebra

slide-6
SLIDE 6

The Low

  • Chemistry has its molec
  • Physics has its elementar
  • Math has its sets.
  • Computer science has
  • They are the smalles
  • True (1, on)
  • False (0, off)

he Lowly Bit

molecules. elementary particles. e has its bits. allest unit of information.

slide-7
SLIDE 7

What’s a

  • Like “ginormous” (giganti

“motel” (motor + hotel); More?

  • It’s a contraction of “b

Claude Shannon, attributed

  • In our decimal (base ten)

digit can be any of the ten v

  • In the binary (base 2) num

can be any of the two v

What’s a “Bit”?

(gigantic + enormous) or hotel); it is a portmanteau. binary digit”, used by hannon, attributed to John Tukey. base ten) number system, a

  • f the ten values 0,...,9.

e 2) number system, a digit

  • f the two values 0 or 1.
slide-8
SLIDE 8

Why a

  • Bits have the property
  • simple: There’s no s

distinction to be made.

  • powerful: sequences

seemingly anything!

Why a Bit?

  • perty of being...

s no smaller discrete to be made. equences of bits can represent thing!

slide-9
SLIDE 9

0/1, Black/

  • Escher created

spectacular images with just a single distinction.

  • “...God divided the

light from the darkness.” (Genesis Chapter 1)

Black/White

slide-10
SLIDE 10

Bits Abound

  • Nearly everything has gone di
  • Digital sound: groups

acoustic intensity at di

  • Digital images: groups

color at each particular location: pixel.

ts Abound

ng has gone digital.

  • und: groups of bits represent the

ity at discrete time points. groups of bits represent the h particular discrete image

slide-11
SLIDE 11

“Regular” A

  • Variables stand for num
  • x = 3, p = 22/7, a = −2
  • Binary operations (two
  • addition: 2 + 3 = 5; subtraction: 1 − 4 = −3
  • multiplication: 2/3 x 7/4 =
  • Unary operations (one num
  • negation: −(11) = −11, square root: √16 = 4

egular” Algebra

tand for numbers. = −2 (two numbers in, one out) addition: 2 + 3 = 5; subtraction: 1 − 4 = −3 2/3 x 7/4 = 7/6 (one number in, one out) negation: −(11) = −11, square root: √16 = 4

slide-12
SLIDE 12

Boolean A

  • Variables stand for bits
  • x = True, p = False,
  • Binary operations (two
  • and (“conjunction”): T
  • or (“disjunction”): True
  • Unary operations (one num
  • not (“negation”): not (
  • olean Algebra

tand for bits (True/False). alse, z = x and p (two bits in, one out)

  • n”): True and False = False

): True or False = True (one number in, one out) : not (False) = True

slide-13
SLIDE 13

Follow the R

  • When is it ok to be in an R m
  • lder than 16 or you hav

with you.

  • x: Person is older than
  • y: Person is accompani

guardian.

  • x or y: Person can see

the Rules #1

to be in an R movie? You are

  • u have an adult guardian

der than 16 .

  • mpanied by an adult

an see an R-rated movie.

slide-14
SLIDE 14

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = ?

” Examples

eeing the movie with his

= ?

slide-15
SLIDE 15

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T

” Examples

eeing the movie with his

= True

slide-16
SLIDE 16

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = ?

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= ?

slide-17
SLIDE 17

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = T

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= True

slide-18
SLIDE 18

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = T
  • Seth is 16 and is there w
  • x = False, y = True, x or y = ?

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= True

there with both of his parents.

= ?

slide-19
SLIDE 19

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = T
  • Seth is 16 and is there w
  • x = False, y = True, x or y = T

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= True

there with both of his parents.

= True

slide-20
SLIDE 20

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = T
  • Seth is 16 and is there w
  • x = False, y = True, x or y = T
  • Jessica is 13 and is ther

school.

  • x = False, y = False, x or y

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= True

there with both of his parents.

= True

and is there with friends from

= ?

slide-21
SLIDE 21

“OR” Exampl

  • Bill is 22 and is seeing the m

stepdad.

  • x = True, y = True, x or y = T
  • Samantha is 17 and is s
  • x = True, y = False, x or y = T
  • Seth is 16 and is there w
  • x = False, y = True, x or y = T
  • Jessica is 13 and is ther

school.

  • x = False, y = False, x or y

” Examples

eeing the movie with his

= True

17 and is seeing the movie alone.

= True

there with both of his parents.

= True

and is there with friends from

= False

slide-22
SLIDE 22

Follow the R

  • All vehicles parked on Un

must be registered and Rutgers permit.

  • x: Car is registered.
  • y: Car displays a valid Rutger
  • x and y: Car can be park

the Rules #2

ked on University property and display a valid alid Rutgers permit. be parked at Rutgers.

slide-23
SLIDE 23

“AND” Exampl

  • Bill’s car is registered and di
  • x = True, y = True, x and y = ?

” Examples

ed and displays a valid permit.

= ?

slide-24
SLIDE 24

“AND” Exampl

  • Bill’s car is registered and di
  • x = True, y = True, x and y = T
  • Samantha’s is registered, but the per
  • x = True, y = False, x and y =

” Examples

ed and displays a valid permit.

= True

stered, but the permit fell off.

= ?

slide-25
SLIDE 25

“AND” Exampl

  • Bill’s car is registered and di
  • x = True, y = True, x and y = T
  • Samantha’s is registered, but the per
  • x = True, y = False, x and y =
  • Al’s registration expired,
  • x = False, y = True, x and y =

” Examples

ed and displays a valid permit.

= True

stered, but the permit fell off.

= False

pired, but his permit is still ok.

= ?

slide-26
SLIDE 26

“AND” Exampl

  • Bill’s car is registered and di
  • x = True, y = True, x and y = T
  • Samantha’s is registered, but the per
  • x = True, y = False, x and y =
  • Al’s registration expired,
  • x = False, y = True, x and y =
  • Jessica is visiting with no r
  • x = False, y = False, x and y

” Examples

ed and displays a valid permit.

= True

stered, but the permit fell off.

= False

pired, but his permit is still ok.

= False

ith no registration or permit.

y = ?

slide-27
SLIDE 27

“AND” Exampl

  • Bill’s car is registered and di
  • x = True, y = True, x and y = T
  • Samantha’s is registered, but the per
  • x = True, y = False, x and y =
  • Al’s registration expired,
  • x = False, y = True, x and y =
  • Jessica is visiting with no r
  • x = False, y = False, x and y

” Examples

ed and displays a valid permit.

= True

stered, but the permit fell off.

= False

pired, but his permit is still ok.

= False

ith no registration or permit.

y = False

slide-28
SLIDE 28

Follow the R

  • It is not allowed by feder

provide tobacco produc persons under 18 year

  • x: Person is under 18.
  • not x: Person can buy tobac

the Rules #3

by federal law to

  • products to

18 years of age. under 18. an buy tobacco

slide-29
SLIDE 29

“NOT” Exampl

  • Samantha is 17 and is
  • x = True, not x = ?

T” Examples

17 and is buying cigarettes.

slide-30
SLIDE 30

“NOT” Exampl

  • Samantha is 17 and is
  • x = True, not x = False

T” Examples

17 and is buying cigarettes.

slide-31
SLIDE 31

“NOT” Exampl

  • Samantha is 17 and is
  • x = True, not x = False
  • Seth is 21 and purchas
  • x = False, not x = ?

T” Examples

17 and is buying cigarettes. 21 and purchased a cigar.

slide-32
SLIDE 32

“NOT” Exampl

  • Samantha is 17 and is
  • x = True, not x = False
  • Seth is 21 and purchas
  • x = False, not x = True

T” Examples

17 and is buying cigarettes. 21 and purchased a cigar.

slide-33
SLIDE 33

And, Or,

  • The most important logi
  • r, and not.
  • x and y is True only if
  • x or y is True only if
  • not x is True only if x
  • A lot like their English m

unambiguous.

nd, Or, Not

tant logical operations are and, ue only if both x and y are True. ue only if either x or y are True. ue only if x is False. nglish meanings, but

slide-34
SLIDE 34

A B A and B

False False False False True False True False False True True True

A

False F False True F True

  • Order of operations: Parenthes

And, Or,

B A or B

False False True True False True True True

A not A

False True True False

: Parentheses, not, and, or

nd, Or, Not

slide-35
SLIDE 35

Relating And/

  • Note: not (not x) = x
  • DeMorgan’s Law: not fl
  • not (x and y) = (not
  • not (x or y) = (not x) and (

ng And/Or/Not

: not flips ands and ors (not x) or (not y) ) and (not y)

slide-36
SLIDE 36

DeMorgan’s Law

  • x: Car is registered.
  • y: Car displays a valid R
  • accepted = x and y
  • not (accepted) if
  • either Car is not regist
  • r Car does not displa
  • not (x and y) = (not x) or

eMorgan’s Law Example

alid Rutgers permit. registered (not x) display a valid permit (not y) t x) or (not y)

slide-37
SLIDE 37

More Exampl

  • x = True, y= False, z = F
  • not x = ? not z = ?
  • x and y = ? y or z = ?
  • y or (x and not z) = ?

e Examples

= False

slide-38
SLIDE 38

Implementing

  • Clearly, our brains can handl

expressions.

  • But, can we automate them

ementing Logic

ns can handle these sorts of automate them?

slide-39
SLIDE 39

Implementing

  • Clearly, our brains can handl

expressions.

  • But, can we automate them
  • Yes, obviously, but let’s

simple way to do it befor fancier stuff.

ementing Logic

ns can handle these sorts of automate them? , but let’s start with a really to do it before we move on to

slide-40
SLIDE 40

lightOn = A = False lightOn = A = True

http://scratch.mit.edu/projects/cs105/35907

Simple C

False

tOn = True

Switch A is either

  • n or off making

the light either on

  • r off: lightOn=A.

Symbols: battery switch bulb ground (completes circuit)

105/35907

mple Circuit

slide-41
SLIDE 41

Multiple Sw

A = False B = True D = False C = True

http://scratch.m

  • jects/cs105/

iple Switches

Switches A and B are wired in parallel: either will light the bulb. Switches C and D are wired in series: both are needed to light the bulb.

http://scratch.mit.edu/pr

  • jects/cs105/35905

tch.mit.edu/pr s105/35909

slide-42
SLIDE 42

Multiple C

A B

Special switches allow a singl switch to control two circuits

tiple Circuits

light1 = ? light2 = ?

a single mechanical ircuits simultaneously.

slide-43
SLIDE 43

Multiple C

A B ligh

tiple Circuits

A B light1 F F F T T F T T A B light2 F F F T T F T T

light1 = ? light2 = ?

slide-44
SLIDE 44

Multiple C

A B ligh

tiple Circuits

A B light1 F F F T T F T T A B light2 F F F T T F T T

light1 = ? light2 = ?

slide-45
SLIDE 45

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T F T T A B light2 F F F T T F T T

light1 = ? light2 = ?

slide-46
SLIDE 46

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T F T T A B light2 F F F T T F T T

light1 = ? light2 = ?

slide-47
SLIDE 47

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T F T T A B light2 F F F F T T F T T

light1 = ? light2 = ?

slide-48
SLIDE 48

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T F T T A B light2 F F F F T T F T T

light1 = ? light2 = ?

slide-49
SLIDE 49

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T F T T A B light2 F F F F T T F T T

light1 = ? light2 = ?

slide-50
SLIDE 50

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T A B light2 F F F F T T F T T

light1 = ? light2 = ?

slide-51
SLIDE 51

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T A B light2 F F F F T T F T T

light1 = ? light2 = ?

slide-52
SLIDE 52

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T A B light2 F F F F T F T F T T

light1 = ? light2 = ?

slide-53
SLIDE 53

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T A B light2 F F F F T F T F T T

light1 = ? light2 = ?

slide-54
SLIDE 54

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T A B light2 F F F F T F T F T T

light1 = ? light2 = ?

slide-55
SLIDE 55

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T A B light2 F F F F T F T F T T

light1 = ? light2 = ?

slide-56
SLIDE 56

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T A B light2 F F F F T F T F T T

light1 = ? light2 = ?

slide-57
SLIDE 57

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T A B light2 F F F F T F T F F T T

light1 = ? light2 = ?

slide-58
SLIDE 58

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T A B light2 F F F F T F T F F T T

light1 = ? light2 = ?

slide-59
SLIDE 59

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T A B light2 F F F F T F T F F T T

light1 = ? light2 = ?

slide-60
SLIDE 60

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T T A B light2 F F F F T F T F F T T

light1 = ? light2 = ?

slide-61
SLIDE 61

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T T A B light2 F F F F T F T F F T T

light1 = ? light2 = ?

slide-62
SLIDE 62

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T T A B light2 F F F F T F T F F T T T

light1 = ? light2 = ?

slide-63
SLIDE 63

Multiple C

A B ligh

tiple Circuits

A B light1 F F F F T T T F T T T T A B light2 F F F F T F T F F T T T

light1 = ? light2 = ?

slide-64
SLIDE 64

Multiple C

A B ligh

tiple Circuits

A B light2 F F F F T F T F F T T T

light1 = A or B light2 = ?

slide-65
SLIDE 65

Multiple C

A B

tiple Circuits

light1 = A or B light2 = A and B

slide-66
SLIDE 66

miniN

  • There’s a pile of objects
  • On her turn, a player can tak
  • ne or two objects.
  • Players alternate.
  • The player to take the l

miniNim

  • f objects, say 10.

ayer can take away either e the last object wins.

slide-67
SLIDE 67

Ideas?

  • The Strategy?

Ideas?

slide-68
SLIDE 68

Nim5Bot: Game

  • Let’s start by considering

the 5-object version.

  • We’ll design a strategy for

the computer “C” to beat the user “U”.

  • t: Game Tree

beat the

slide-69
SLIDE 69

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

slide-70
SLIDE 70

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

slide-71
SLIDE 71

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

??

slide-72
SLIDE 72

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

C takeOne

slide-73
SLIDE 73

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

slide-74
SLIDE 74

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

slide-75
SLIDE 75

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

slide-76
SLIDE 76

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

??

slide-77
SLIDE 77

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

??

slide-78
SLIDE 78

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

C takeOne

slide-79
SLIDE 79

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

2 left

slide-80
SLIDE 80

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

2 left

takeOne takeTwo

slide-81
SLIDE 81

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

2 left

takeOne takeTwo

C

slide-82
SLIDE 82

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

2 left

takeOne takeTwo

C

slide-83
SLIDE 83

Nim5Bot: Game

  • Let’s start by

considering the 5-

  • bject version.
  • We’ll design a

strategy for the computer “C” to beat the user “U”.

  • t: Game Tree

5 left

takeOne takeTwo

3 left

takeOne takeTwo

C C

2 left

takeOne takeTwo

C U

slide-84
SLIDE 84

Nim5Bot: Game

  • Let’s start by considering

the 5-object version.

  • We’ll design a strategy for

the computer “C” to beat the user “U”.

  • t: Game Tree

5 left 3 left

takeOne takeTwo

2 left

takeOne takeTwo takeOne takeTwo

C C C U

beat the

slide-85
SLIDE 85

Backwards I

  • There’s a powerful idea
  • Many decision making

solved optimally by reas from the end of the gam

  • We know how to win
  • We use this to win from
  • We use this to win from
  • Chess: removed pieces

ards Induction

ful idea here: making problems can be y by reasoning backwards the end of the game. to win from 1 or 2. to win from 4 or 5. to win from 7 or 8. pieces don’t return.

slide-86
SLIDE 86

Further Consi

  • To win miniNim: if poss

leave opponent with a m

  • Why does it work? W

3; if opponent has a m her with next smaller

  • What if goal is to not
  • What if we can take 1, 2, or

round? 2 or 3? 1 or 3? Is rule?

her Considerations

if possible, remove pieces to ith a multiple of 3.

  • rk? We win if opponent has

has a multiple of 3, can leave aller multiple of 3. take the last object? take 1, 2, or 3 objects per 3? 1 or 3? Is there a general

slide-87
SLIDE 87

Complete Ni

  • fiveLeft = True
  • threeLeft = fiveLeft and takeOne
  • twoLeft = fiveLeft and takeTwo1
  • C-Win = (threeLeft and (takeOne
  • r takeTwo2)) or (twoLeft and

takeOne2)

  • U-Win = twoLeft and takeTwo2

ete Nim5 Logic

5 left 3 left

takeOne1 takeTwo1

2 left

takeOne2 takeTwo2 takeOne2 takeTwo2

C C C U

One1 One2

slide-88
SLIDE 88

tw

Nim5 Ci

takeOne1 takeTwo1 fiveLeft U-Win twoLeft threeLeft

m5 Circuit

C-Win takeTwo2 takeOne2

http://scratch.mit.edu/pro jects/cs105/35736

slide-89
SLIDE 89

What a Headache!

  • Encoding Nim10 with s

Why?

  • Since some switches

places, needs more than a doubl switch.

  • Since values are reus
  • f different circuits.
  • Appears to need a separ
  • utput: Gets too com

a Headache!

10 with switches is a nightmare. itches are used in multiple

  • re than a double-throw

are reused, hard to keep track to need a separate circuit for each too complex too fast.

slide-90
SLIDE 90

Bits, Inside

Inputs: Switches

takeOne1 takeTwo1 takeOne2 takeTwo2

Nim Player

nside and Out

Outputs: Lights

You win! I win!

slide-91
SLIDE 91

Bits, Inside

A = False B = True

Inputs: Switches Inside: Logi

AND AND AND AND NOT NOT

nside and Out

light2On = True light1On = False

Outputs: Lights de: Logic

OR OR OR OR OT

slide-92
SLIDE 92

Need a New

  • Let’s consider an alternate w

“and” and “or” logic.

  • Makes simple things
  • Makes complex things
  • That’s a tradeoff we can

a New Approach

an alternate way of building things more complex. things much simpler! adeoff we can deal with.

slide-93
SLIDE 93

The Magi he Magic Box

slide-94
SLIDE 94

The Magi he Magic Box

slide-95
SLIDE 95

The Magi he Magic Box

slide-96
SLIDE 96

The Magi he Magic Box

slide-97
SLIDE 97

The Magi he Magic Box

slide-98
SLIDE 98

The Magi he Magic Box

slide-99
SLIDE 99

The Magi he Magic Box

slide-100
SLIDE 100

A

How does i

lightOn = ?

does it Work?

?

slide-101
SLIDE 101

A

How does i

lightOn = ? A = False

does it Work?

?

slide-102
SLIDE 102

A

How does i

lightOn = ?

does it Work?

?

slide-103
SLIDE 103

A

How does i

lightOn = Tru

does it Work?

True

slide-104
SLIDE 104

A = False

Switch Sw

lightOn = Tru

tch Switcher

lightOn = ?

True

A = True

slide-105
SLIDE 105

A = False

Switch Sw

lightOn = Tru

tch Switcher

lightOn = ?

True

A = True

slide-106
SLIDE 106

A = False

Switch Sw

lightOn = Tru Before, we used switches to c now, we will use current (v control switches (which con

tch Switcher

lightOn = False

True

A = True es to control the flow of current; ent (via electromagnetism) to ch control the flow of current)!

slide-107
SLIDE 107

Relay Circuit: A rcuit: A = F, B = F

slide-108
SLIDE 108

Relay Circuit: A rcuit: A = F, B = F

slide-109
SLIDE 109

Relay Circuit: A rcuit: A = F, B = T

slide-110
SLIDE 110

Relay Circuit: A rcuit: A = F, B = T

slide-111
SLIDE 111

Relay Circuit: A rcuit: A = F, B = T

slide-112
SLIDE 112

Relay Circuit: A rcuit: A = T, B = F

slide-113
SLIDE 113

Relay Circuit: A rcuit: A = T, B = F

slide-114
SLIDE 114

Relay Circuit: A rcuit: A = T, B = F

slide-115
SLIDE 115

Relay Circuit: A rcuit: A = T, B = T

slide-116
SLIDE 116

Relay Circuit: A rcuit: A = T, B = T

slide-117
SLIDE 117

Relay Circuit: A rcuit: A = T, B = T

slide-118
SLIDE 118

Relay Circuit: A rcuit: A = T, B = T

What is this?

  • A. NOT gate
  • B. AND gate
  • C. OR gate
  • D. AND-OR gate
slide-119
SLIDE 119

Relay Circuit: A rcuit: A = T, B = T

slide-120
SLIDE 120

And One For ne For “Not”

slide-121
SLIDE 121

And One For

NOT

ne For “Not”

NOT

slide-122
SLIDE 122

And One For

  • We saw several slides

ago that a single relay “inverts” its input signal, turning a True to a False and vice versa.

  • These output summaries

are known as “truth tables”.

ne For “Not”

alse aries

A B

False True True False NOT GATE

A B

B = not A

A B

slide-123
SLIDE 123

Abstraction: The

  • Our new relay-based

“and” and “not” gates take current, not switches, as input.

  • As a result, they are

easier to chain together.

  • The original switch-based

scheme did not support this kind of modularity.

  • n: The Black Box

take based

AND GATE NOT GATE NOT GATE NOT GATE

A B C

slide-124
SLIDE 124

A Third Black

A B C

False False False True True False True True

hird Black Box

AND GATE NOT GATE NOT GATE NOT GATE

A B C

slide-125
SLIDE 125

A Third Black

A B C

False False False False True True True False True True True True

hird Black Box

AND GATE NOT GATE NOT GATE NOT GATE

A B C

slide-126
SLIDE 126

Complete Ni

  • fiveLeft = True
  • threeLeft = fiveLeft and takeOne
  • twoLeft = fiveLeft and takeTwo1
  • C-Win = (threeLeft and (takeOne
  • r takeTwo2)) or (twoLeft and

takeOne2)

  • U-Win = twoLeft and takeTwo2

ete Nim5 Logic

5 left 3 left

takeOne1 takeTwo1

2 left

takeOne2 takeTwo2 takeOne2 takeTwo2

C C C U

One1 One2

slide-127
SLIDE 127

Simplified Nim5

fiveLeft threeLeft twoLeft takeOne1 ta takeTwo1

AND GATE

True

ed Nim5 Circuit

C-Win U-Win takeOne2 takeTwo2

AND GATE OR GATE OR GATE AND GATE AND GATE

slide-128
SLIDE 128

How to Make

  • switches/relays
  • hydraulic valves
  • tinkertoys
  • silicon: semiconductors/trans
  • soap bubble
  • DNA
  • quantum material
  • ptics
  • Make a Gate

tors/transistors

slide-129
SLIDE 129

Movi Movie

slide-130
SLIDE 130

NOT Gate (v3)

1 1

slide-131
SLIDE 131

Or Gate (v4)

1 1

Relea

1

Release bottom row first

slide-132
SLIDE 132

Wire, transmitting bi

1

itting bits (v1)

1

slide-133
SLIDE 133

Could It Wor

  • My domino “or” gate requi
  • The first Pentium proces

transistors, or roughly 800K

  • So, perhaps 19M domi
  • World record for domino toppl
  • Oh, and the Pentium di

60M times a second, w might require a week to s

  • uld It Work?

gate requires 24 dominoes. processor had 3.3M

  • ughly 800K gates.

dominoes needed. domino toppling: 4M. entium did its computations

  • nd, whereas dominoes

eek to set up once.

slide-134
SLIDE 134

But There Are Lot

  • iPod: 60Gb. 1Gb = one

billion bytes, each of which is 8 bits.

  • Format uses 128 Kbps

(kilobits or 1000 bits per second of sound).

  • So, 62,500 minutes of

sound or 15,000 songs at 4 minutes per song.

  • Screen: 320x240 pixels,

each of which stores 1 byte each of R,G,B intensity (24 bits). That’s 76,800 pixels and 1.8M bits.

  • At 30 frames per sec.,

that’s 55.3 million bits per second or 144 min. of (quiet) video.

here Are Lots of Them

slide-135
SLIDE 135
  • 1 Byte = 8 Bits
  • 1 Kilobyte (KB) = 1,000 Byt
  • 1 Megabyte (MB) = 1,000 Kiloby
  • 1 Gigabyte (GB) = 1,000 M

= 1,000,000 = 1,000,000,

  • You can also have kilobits,

Number of

000 Bytes 1,000 Kilobytes = 1,000,000 Bytes 000 Megabytes 000,000 Kilobytes 000,000,000 Bytes ilobits, megabits and gigabits

umber of Bits

slide-136
SLIDE 136

An Exampl

  • When you download a file,

your download speed in kilobit

  • For example, I am downloading

Firefox, which is 17.6 MB

  • This means that the file cont
  • 17.6 megabytes = 17,600

bytes

  • = 140,800,000 bits

An Example

nload a file, you will most likely see peed in kilobits per second downloading a copy of Mozilla 6 MB for the mac he file contains 17,600 kilobytes = 17,600,000

slide-137
SLIDE 137

An Example C

  • If my download speed is 300

second, how long will it tak file?

  • 100 kilobits = 100,000 bits
  • 140,800,000 bits * 1 second
  • = 469 seconds = 7.8 minut

Example Continued

peed is 300 (kbps) kilobits per ill it take me to download the 000 bits 1 second / 300,000 bits 7.8 minutes

slide-138
SLIDE 138

Another Exam

  • Your digital camera is 10 m

happen to know that each see why later in this class)

  • First, how many bits are in
  • 10 megapixels = 10,000 k

pixels

  • = 240,000,000 bits
  • = 30,000,000 bytes = 30,000
  • = 30 megabytes per pic

her Example

is 10 megapixels and you hat each pixel is 24 bits (we will class) are in each picture? 000 kilopixels = 10,000,000 = 30,000 kilobytes per picture

slide-139
SLIDE 139

Another Exam

  • Now, if you have a 4 gigaby

pictures can you take?

  • 4 gigabytes = 4,000 megaby
  • 4,000 megabytes * 30 megaby
  • = 133 pictures

Example Cont....

4 gigabyte card, how many 000 megabytes 30 megabytes / 1 picture