10/7

advertisement
COS 109
Wednesday October 8
• Housekeeping
–
–
–
–
–
Assignment 1 returned today
Any questions on Assignment 3 or Lab 2
Any questions about course material
Homework extensions of due dates
Midterm scheduling
• Overview of today’s lecture
– Models of computation
(finite) state machines
Turing machines and Church’s thesis
–
–
–
–
Review of what we’ve covered on hardware
Quantitative and video break
An estimation problem
Beginning our discussion of software
Let’s revisit a program to print a number
GET
PRINT
STOP
•
get a number from keyboard into accumulator
print the number that's in the accumulator
What really happens when this is executed?
•
CPU listens to the keyboard until it receives a number
• CPU hears each digit
• When CPU hears the enter key, the number has been received
•
•
•
CPU accepts the number and puts it in the accumulator
CPU communicates command to printer to print the number
CPU stops
What actually happens in the CPU
NO
Listen
to
Keyboard
Hear
character
YES
Record
character
YES
Compute
input
number
Is last
character
ENTER?
NO
Stop
Print
Revisiting car safety
•
Excerpts from 3 articles
NYTimes(a) 9/27/15
Computerworld 9/23/15
NYTimes(b) 9/30/15
http://www.nytimes.com/2015/09/27/business/complex-car-software-becomes-the-weak-spot-under-the-hood.html
http://www.computerworld.com/article/2985283/telematics/a-diesel-whodunit-how-software-let-vw-cheat-on-emissions.html
http://www.nytimes.com/2015/10/01/technology/vw-scandal-shows-a-need-for-more-tech-not-less.html
Excerpts from the NYTimes(a) article
•
New high-end cars are among the most sophisticated machines on the
planet, containing 100 million or more lines of code. Compare that with
about 60 million lines of code in all of Facebook or 50 million in the Large
Hadron Collider
•
The unfolding scandal at Volkswagen — in which 11 million vehicles were
outfitted with software that gave false emissions results — showed how
a carmaker could take advantage of complex systems to flout
regulations
•
Days later, Fiat Chrysler, the maker of Jeep, announced a recall of 1.4
million vehicles to fix the flaws the hackers had identified — the first
known recall intended to address a possible hacking threat. (in response
to the video we saw)
Excerpts from the Computerworld article
•
•
•
•
•
In an interview with Autoblog, Thiruvengadam told how his group
drove a Volkswagen Jetta, a Passat and a BMW X5 for thousands of
miles along California's highways to get their emissions results.
While the Passat should have been among the lowest in emissions of
the three cars, tests showed 20 times the baseline level of
emissions the team had established for the cars.
Thiruvengadam said he hasn't researched the software that allowed
Volkswagen to cheat on the tests. But he did say "there were lots
of ways an electronic control unit could be programmed to identify
testing and change its fuel mapping toward low emission in those rare
scenarios."
For example, modern cars can sense when a hood is open for
dynamometer testing, "so a smart hood switch could double as a
defeat device."
Or, another sensor could detect when a vehicle's traction control
unit was disabled, which is required during emissions testing, and
place the emission system into a different mode.
Excerpts from the NYTimes(b ) article
•
•
•
Right now we are at an awkward in-between phase in the transformation
of the automobile — somewhere in the uncanny valley between the
mechanical horse of Henry Ford’s era and the intelligent, autonomous,
emissions-free, crash-free, networked fleet that will begin chugging
along our roads later this century. This transition period will mean
short-term turmoil. Cars today are lousy with code that can’t be
inspected, opening the way for scary hackings and cheats and also the
unforeseen complications of interactions between robots and humans.
Some of these problems call for obvious fixes. As many have pointed out
since the VW admission, the code in our cars (and other life-threatening
machines) shouldn’t be secret, but should allow for better inspection by
authorities and independent experts. Another obvious fix is to replace
the sort of lab-testing that VW was able to game with the kind of realworld analysis that uncovered its chicanery.
But to do that, we’ll need more technology, not less. We need more
sensors in cars and on roads and a network of computers watching the
data to figure out when vehicles are behaving in aberrant ways. In other
words, the best way to prevent cheating isn’t to make our cars dumber,
but to make the entire transportation grid smarter.
A simple state machine within the VW
Read
hood
sensor.
Is it
open?
YES
NO
Car may
be being
tested
Car is
being
driven
Machine has 2 states – testing and driving
Another simple state machine – a combination lock
Wrong
Test
Test
Correct
second Correct
first
number
number
Wrong
Wrong
Test
third
number
Correct
Open
Lock
Characteristics of a state machine
•
•
•
Has states
Has rules for transitions
Execution is step by step
–
Read a symbol from input, perform a transition (based on current state and input),
maybe write a symbol
CPU is like a finite state machine
•
Simple view
–
•
More realistic view
–
–
•
Fetch/Execute Cycle
When Fetching, instructions have to be decoded to determining actions
Execution often involves a number of steps
Similarly, we can think of processes as being defined by state
machines
A different state machine
• A machine to change small (value 1 or 2) tokens into large
(value 5) tokens
• How it works
– The states show the current balance
Starts at 0
– At each step, read input (i.e. see new token)
Perform transition based on whether it is value 1 or 2
– Once value 5 (or more) is reached, return a large token and restart
The full state machine
0
1
2/1
1
2
2/1
2
1
2
1
3
2
2/1
1
4
One last state machine
• Credit card checker
• Sample form
Limitations of state machines
•
•
Input size is finite
Input can be read in only one direction
•
Enter Alan Turing *38 and Alonzo Church *37
– Remove these restrictions and you have aa abstract computing device
that models what can be computed
Turing machine
• Tape on which characters from the alphabet can be
read/written
Control
Actions:
Read a character from the tape,
Based on your rules, perform the relevant transition
write a symbol on the tape
change state
move left or right or stay in place
A Turing machine program to add 2 numbers
•
•
Let the alphabet consist of the characters 1,0,#,$
The input is given as
– <first number in binary>#<second number in binary>$
•
•
Program is initialized in a state that shows a carry bit of zero
Program walks the tape looking for #
– character before # is recorded (in state), that space is overwritten with #
•
Program goes looking for $
– character before $ is recorded (in state),that space is overwritten with $
• State now knows how to add the 3 bits it has
•
•
– 3 bit, $ bit and carry bit yield sum bit and carry bit (recorded in
state)
Program goes down the tape to record the sum bit
Program loops back until there are no more characters to add
Turing machines
• Turing machine
– a simple model of a computer this is universal
– so, all computers have the same computational power
i.e., they can compute the same things
though they may vary enormously in speed, memory, etc.
– equivalence proven / demonstrated by simulation
any machine can simulate any other
a "universal Turing machine" can simulate any other Turing machine
• Church’s thesis (loosely interpreted)
– proved using methods of mathematical logic that every effectively
calculable function is a computable function
– effectively calculable functions can are computed by a method that
takes a finite number of steps
always terminates
produces a correct answer
can be done by a human by just following instructions
– such methods are called algorithms
One last item about Turing machines
• Turing machines can behave non-deterministically
There can be more than 1 rule that applies in a situation and the
machine can
choose a rule to apply or
perform all rules in parallel
Fundamental ideas
•
a computer is a general-purpose machine
– executes very simple instructions very quickly
– controls its own operation according to computed results
•
"von Neumann architecture"
– change what it does by putting new instructions in memory
– instructions and data stored in the same memory
– indistinguishable except by context
attributed to von Neumann (1946)
(and Charles Babbage, in the Analytical Engine (1830's))
– logical structure largely unchanged for 60+ years
– physical structures changing very rapdily
•
Turing machines
– all computers have exactly the same computational power:
they can compute exactly the same things; differ only in performance
– one computer can simulate another computer
a program can simulate a computer
Download