Class 30: Models of Computation: David Evans

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

Class 30:

Models of
Computation

CS200: Computer Science


University of Virginia David Evans
Computer Science http://www.cs.virginia.edu/evans
Menu
• How can we model computation?
• Turing Machines
• Universal Turing Machine

2 April 2004 CS 200 Spring 2004 2


How should we model a Computer?
Colossus (1944)

Cray-1 (1976)

Apollo Guidance
Computer (1969)

2 April 2004 CS 200 Spring 2004 3


IBM 5100 (1975)
Modeling Computers
• Input
– Without it, we can’t describe a problem
• Output
– Without it, we can’t get an answer
• Processing
– Need some way of getting from the input to the
output
• Memory
– Need to keep track of what we are doing

2 April 2004 CS 200 Spring 2004 4


Modeling Input

Punch Cards

Altair BASIC Paper Tape, 1976

2 April 2004
Engelbart’s mouse and keypad
CS 200 Spring 2004 5
Simplest Input
• Non-interactive: like punch cards and
paper tape
• One-dimensional: just a single tape of
values, pointer to one square on tape
0 0 1 1 0 0 1 0 0 0

How long should the tape be?


Infinitely long! We are modeling a computer, not
building one. Our model should not have silly
practical limitations (like a real computer does).
2 April 2004 CS 200 Spring 2004 6
Modeling Output
• Blinking lights are
cool, but hard to
model
• Output is what is
written on the
tape at the end of
a computation
Connection Machine CM-5, 1993

2 April 2004 CS 200 Spring 2004 7


Modeling Processing
• Evaluation Rules
– Given an input on our tape, how do we
evaluate to produce the output
• What do we need:
– Read what is on the tape at the current square
– Move the tape one square in either direction
– Write into the current square

0 0 1 1 0 0 1 0 0 0

2 April 2004 Is thatCSenough to model a computer?8


200 Spring 2004
Modeling Processing
• Read, write and move is not enough
• We also need to keep track of what we are
doing:
– How do we know whether to read, write or
move at each step?
– How do we know when we’re done?
• What do we need for this?

2 April 2004 CS 200 Spring 2004 9


Finite State Machines

0 1
0

Start 1 2

1
#
HAL
T
2 April 2004 CS 200 Spring 2004 10
Hmmm…maybe we don’t need
those infinite tapes after all?
not a ( not a
paren paren

Start 1 2
)
)
# What if the
next input symbol
ERRO HAL
is ( in state 2?
R T
2 April 2004 CS 200 Spring 2004 11
How many states do we need?
not a ( not a
paren paren
not a
Start 1 2 paren
(
)
)
)
3 not a
paren
#
(
ERRO HAL
R T 4
)
2 April 2004 CS 200 Spring 2004 12
(
Finite State Machine
• There are lots of things we can’t compute
with only a finite number of states
• Solutions:
– Infinite State Machine
• Hard to describe and draw
– Add a tape to the Finite State Machine

2 April 2004 CS 200 Spring 2004 13


FSM + Infinite Tape
• Start:
– FSM in Start State
– Input on Infinite Tape
– Pointer to start of input
• Move:
– Read one input symbol from tape
– Follow transition rule from current state
• To next state
• Write symbol on tape, and move L or R one square
• Finish:
– Transition to halt state
2 April 2004 CS 200 Spring 2004 14
Matching Parentheses
• Repeat until halt:
– Find the leftmost )
• If you don’t find one, the parentheses match,
write a 1 at the tape head and halt.
– Replace it with an X
– Look left for the first (
• If you find it, replace it with an X (they matched)
• If you don’t find it, the parentheses didn’t match –
end write a 0 at the tape head and halt
2 April 2004 CS 200 Spring 2004 15
Matching Parentheses
Input: )
(, (, R Write: X ), X, L
Move: L X, X, L
X, X, R

2: look
Start 1 for (
(, X, R

#, 1, # #, 0, #
HAL
Will this report the
correct result for (()?
T
2 April 2004 CS 200 Spring 2004 16
Matching Parentheses
(, (, R
X, X, L
X, X, R ), X, L

2: look
Start
1 (, X, R for (

#, #, L

#, 1, # #, 0, #

3: look
X, X, L for ( HAL
T
#, 1, #
(, 0, #
2 April 2004 CS 200 Spring 2004 17
Turing Machine
• Alan Turing, On computable numbers: With
an application to the
Entscheidungsproblem, 1936
– Turing developed the machine abstraction to
show the halting problem really leads to a
contradiction
– Our informal argument, depended on assuming
we could do if and everything else except
halts?

2 April 2004 CS 200 Spring 2004 18


Describing Turing Machines
z z z z z z z z z z z z z z z z z z z z

), X, L
TuringMachine ::= < Alphabet, Tape, FSM >
), #, R

(, #, L
Alphabet ::= { Symbol* }
1
2:
look
for (
Tape ::= < LeftSide, Current, RightSide >
Start

(, X, R
OneSquare ::= Symbol | #
Current ::= OneSquare
HAL
#, 1, - T #, 0, -
LeftSide ::= [ Square* ]
Finite State Machine RightSide ::= [ Square* ]

Everything to left of LeftSide is #.


Everything to right of RightSide is #.

2 April 2004 CS 200 Spring 2004 19


), X, L
), #, R (, #, L
Describing
Start 1 (, X, R
2: look
for ( Finite State
#, 1, # HAL #, 0, #
Machines
T
TuringMachine ::= < Alphabet, Tape, FSM >
FSM ::= < States, TransitionRules, InitialState, HaltingStates >
States ::= { StateName* }
InitialState ::= StateName must be element of States
HaltingStates ::= { StateName* } all must be elements of States
TransitionRules ::= { TransitionRule* }
TransitionRule ::=
< StateName, ;; Current State Transition Rule is a procedure:
OneSquare, ;; Current square StateName X OneSquare
StateName, ;; Next State  StateName X OneSquare X Direction
OneSquare, ;; Write on tape
Direction > ;; Move tape
2 April 2004 CS 200 Spring 2004 20
Direction ::= L, R, #
), X, L
), #, R (, #, L
Example
Start 1 (, X, R
2: look
for ( Turing
#, 1, # HAL #, 0, #
Machine
T
TuringMachine ::= < Alphabet, Tape, FSM >
FSM ::= < States, TransitionRules, InitialState, HaltingStates >
Alphabet ::= { (, ), X }
States ::= { 1, 2, HALT }
InitialState ::= 1
HaltingStates ::= { HALT }
TransitionRules ::= { < 1, ), 2, X, L >,
< 1, #, HALT, 1, # >,
< 1, ), #, R >,
< 2, (, 1, X, R >,
< 2, #, HALT, 0, # >,
< 2, ), #, L >,}
2 April 2004 CS 200 Spring 2004 21
Enumerating Turing Machines
• Now that we’ve decided how to describe
Turing Machines, we can number them
• TM-5023582376 = balancing parens
• TM-57239683 = even number of 1s
• TM- = Photomosaic Program
3523796834721038296738259873

• TM- = WindowsXP
3672349872381692309875823987609823712347823

Not the real


numbers – they
would be much
bigger!
2 April 2004 CS 200 Spring 2004 22
Demo

Electronic Flash Cards for Learning Languages


Edward Mitchell, Justin Pan, Qi Wang and Chalermpong Worawannotai

http://www.people.virginia.edu/~cw7r/cs200/

2 April 2004 CS 200 Spring 2004 23


Charge
• Next week:
– Lambda Calculus model of computation
– Very different from Turing Machines, but we
will show that it is exactly as powerful!

2 April 2004 CS 200 Spring 2004 24

You might also like