Chapte Nuts and
CS105: Great Insights in Com
Chapter 1: ts and Bolts
ights in Computer Science
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
CS105: Great Insights in Com
ights in Computer Science
well-defined
technology as on ideas
the electronics out of w built
hy of parts een parts are simple and e dependent not so much on
e almost nothing to do with
an thought -> math operations
manipulating logical determining whether true (Boolean Algeb
an thought -> math operations anguage for describing and
hether or not they were Algebra)
manipulating logical determining whether true (Boolean Algeb
equivalent to expressions
an thought -> math operations anguage for describing and
hether or not they were Algebra) hannon: Build electrical circuits pressions in Boolean Algebra
molecules. elementary particles. e has its bits. allest unit of information.
“motel” (motor + hotel); More?
Claude Shannon, attributed
digit can be any of the ten v
can be any of the two v
(gigantic + enormous) or hotel); it is a portmanteau. binary digit”, used by hannon, attributed to John Tukey. base ten) number system, a
e 2) number system, a digit
distinction to be made.
seemingly anything!
s no smaller discrete to be made. equences of bits can represent thing!
spectacular images with just a single distinction.
light from the darkness.” (Genesis Chapter 1)
acoustic intensity at di
color at each particular location: pixel.
ng has gone digital.
ity at discrete time points. groups of bits represent the h particular discrete image
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
tand for bits (True/False). alse, z = x and p (two bits in, one out)
): True or False = True (one number in, one out) : not (False) = True
with you.
guardian.
to be in an R movie? You are
der than 16 .
an see an R-rated movie.
stepdad.
eeing the movie with his
= ?
stepdad.
eeing the movie with his
= True
stepdad.
eeing the movie with his
= True
17 and is seeing the movie alone.
= ?
stepdad.
eeing the movie with his
= True
17 and is seeing the movie alone.
= True
stepdad.
eeing the movie with his
= True
17 and is seeing the movie alone.
= True
there with both of his parents.
= ?
stepdad.
eeing the movie with his
= True
17 and is seeing the movie alone.
= True
there with both of his parents.
= True
stepdad.
school.
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
= ?
stepdad.
school.
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
must be registered and Rutgers permit.
ked on University property and display a valid alid Rutgers permit. be parked at Rutgers.
ed and displays a valid permit.
= ?
ed and displays a valid permit.
= True
stered, but the permit fell off.
= ?
ed and displays a valid permit.
= True
stered, but the permit fell off.
= False
pired, but his permit is still ok.
= ?
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 = ?
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
provide tobacco produc persons under 18 year
by federal law to
18 years of age. under 18. an buy tobacco
17 and is buying cigarettes.
17 and is buying cigarettes.
17 and is buying cigarettes. 21 and purchased a cigar.
17 and is buying cigarettes. 21 and purchased a cigar.
unambiguous.
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
A B A and B
False False False False True False True False False True True True
A
False F False True F True
B A or B
False False True True False True True True
A not A
False True True False
: Parentheses, not, and, or
: not flips ands and ors (not x) or (not y) ) and (not y)
alid Rutgers permit. registered (not x) display a valid permit (not y) t x) or (not y)
= False
expressions.
ns can handle these sorts of automate them?
expressions.
simple way to do it befor fancier stuff.
ns can handle these sorts of automate them? , but let’s start with a really to do it before we move on to
lightOn = A = False lightOn = A = True
http://scratch.mit.edu/projects/cs105/35907
False
tOn = True
Switch A is either
the light either on
Symbols: battery switch bulb ground (completes circuit)
105/35907
A = False B = True D = False C = True
http://scratch.m
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
tch.mit.edu/pr s105/35909
A B
Special switches allow a singl switch to control two circuits
light1 = ? light2 = ?
a single mechanical ircuits simultaneously.
A B ligh
A B light1 F F F T T F T T A B light2 F F F T T F T T
light1 = ? light2 = ?
A B ligh
A B light1 F F F T T F T T A B light2 F F F T T F T T
light1 = ? light2 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
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 = ?
A B ligh
A B light2 F F F F T F T F F T T T
light1 = A or B light2 = ?
A B
light1 = A or B light2 = A and B
ayer can take away either e the last object wins.
the 5-object version.
the computer “C” to beat the user “U”.
beat the
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
??
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
C takeOne
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
??
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
??
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
C takeOne
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
2 left
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
2 left
takeOne takeTwo
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
2 left
takeOne takeTwo
C
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
2 left
takeOne takeTwo
C
considering the 5-
strategy for the computer “C” to beat the user “U”.
5 left
takeOne takeTwo
3 left
takeOne takeTwo
C C
2 left
takeOne takeTwo
C U
the 5-object version.
the computer “C” to beat the user “U”.
5 left 3 left
takeOne takeTwo
2 left
takeOne takeTwo takeOne takeTwo
C C C U
beat the
solved optimally by reas from the end of the gam
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.
leave opponent with a m
3; if opponent has a m her with next smaller
round? 2 or 3? 1 or 3? Is rule?
if possible, remove pieces to ith a multiple of 3.
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
takeOne2)
5 left 3 left
takeOne1 takeTwo1
2 left
takeOne2 takeTwo2 takeOne2 takeTwo2
C C C U
One1 One2
tw
takeOne1 takeTwo1 fiveLeft U-Win twoLeft threeLeft
C-Win takeTwo2 takeOne2
http://scratch.mit.edu/pro jects/cs105/35736
Why?
places, needs more than a doubl switch.
10 with switches is a nightmare. itches are used in multiple
are reused, hard to keep track to need a separate circuit for each too complex too fast.
Inputs: Switches
takeOne1 takeTwo1 takeOne2 takeTwo2
Nim Player
Outputs: Lights
You win! I win!
A = False B = True
Inputs: Switches Inside: Logi
AND AND AND AND NOT NOT
light2On = True light1On = False
Outputs: Lights de: Logic
OR OR OR OR OT
“and” and “or” logic.
an alternate way of building things more complex. things much simpler! adeoff we can deal with.
A
lightOn = ?
?
A
lightOn = ? A = False
?
A
lightOn = ?
?
A
lightOn = Tru
True
A = False
lightOn = Tru
lightOn = ?
True
A = True
A = False
lightOn = Tru
lightOn = ?
True
A = True
A = False
lightOn = Tru Before, we used switches to c now, we will use current (v control switches (which con
lightOn = False
True
A = True es to control the flow of current; ent (via electromagnetism) to ch control the flow of current)!
What is this?
ago that a single relay “inverts” its input signal, turning a True to a False and vice versa.
are known as “truth tables”.
alse aries
A B
False True True False NOT GATE
A B
B = not A
A B
“and” and “not” gates take current, not switches, as input.
easier to chain together.
scheme did not support this kind of modularity.
take based
AND GATE NOT GATE NOT GATE NOT GATE
A B C
A B C
False False False True True False True True
AND GATE NOT GATE NOT GATE NOT GATE
A B C
A B C
False False False False True True True False True True True True
AND GATE NOT GATE NOT GATE NOT GATE
A B C
takeOne2)
5 left 3 left
takeOne1 takeTwo1
2 left
takeOne2 takeTwo2 takeOne2 takeTwo2
C C C U
One1 One2
fiveLeft threeLeft twoLeft takeOne1 ta takeTwo1
AND GATE
True
C-Win U-Win takeOne2 takeTwo2
AND GATE OR GATE OR GATE AND GATE AND GATE
tors/transistors
NOT Gate (v3)
1 1
Or Gate (v4)
1 1
Relea
1
Release bottom row first
Wire, transmitting bi
1
itting bits (v1)
1
transistors, or roughly 800K
60M times a second, w might require a week to s
gate requires 24 dominoes. processor had 3.3M
dominoes needed. domino toppling: 4M. entium did its computations
eek to set up once.
billion bytes, each of which is 8 bits.
(kilobits or 1000 bits per second of sound).
sound or 15,000 songs at 4 minutes per song.
each of which stores 1 byte each of R,G,B intensity (24 bits). That’s 76,800 pixels and 1.8M bits.
that’s 55.3 million bits per second or 144 min. of (quiet) video.
= 1,000,000 = 1,000,000,
000 Bytes 1,000 Kilobytes = 1,000,000 Bytes 000 Megabytes 000,000 Kilobytes 000,000,000 Bytes ilobits, megabits and gigabits
your download speed in kilobit
Firefox, which is 17.6 MB
bytes
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
second, how long will it tak file?
peed is 300 (kbps) kilobits per ill it take me to download the 000 bits 1 second / 300,000 bits 7.8 minutes
happen to know that each see why later in this class)
pixels
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
pictures can you take?
4 gigabyte card, how many 000 megabytes 30 megabytes / 1 picture