Class 14: Modeling Computers

25
Class 14: Modeling Computer s cs1120 Fall 2011 David Evans 23 September 2011 Monday’s class will meet in Rice Hall Bagel Shop Area

description

Modeling ComputersFinite State MachinesTuring Machines

Transcript of Class 14: Modeling Computers

Page 1: Class 14: Modeling Computers

Class 14: Modeling Computers

cs1120 Fall 2011David Evans23 September 2011

Monday’s class will meet in Rice Hall Bagel Shop Area

Page 2: Class 14: Modeling Computers

2

Plan

Modeling ComputersTuring’s ModelProgramming Turing Machines

Page 3: Class 14: Modeling Computers

3

What makes a good model?

Copernicus

F = GM1M2 / R2

Newton Ptolomy

Page 4: Class 14: Modeling Computers

4

How should we model a Computer?

Apollo Guidance Computer (1969)

Colossus (1944)

Cray-1 (1976)

Palm Pre (2009)Flickr: louisvolantApple II (1977)

Honeywell Kitchen Computer (1969)

Turing invented the model we’ll use today in 1936. What “computer” was he modeling?

Page 5: Class 14: Modeling Computers

5

“Computers” before WWII

Page 6: Class 14: Modeling Computers

6

Mechanical Computing

Page 7: Class 14: Modeling Computers

7

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

Page 8: Class 14: Modeling Computers

8

Modeling Input

Engelbart’s mouse and keypad

Punch Cards

Altair BASIC Paper Tape, 1976

Page 9: Class 14: Modeling Computers

9

Turing’s Model

“Computing is normally done by writing certain symbols on paper. We may suppose this paper is divided into squares like a child’s arithmetic book.”

Alan Turing, On computable numbers, with an application to the Entscheidungsproblem, 1936

Page 10: Class 14: Modeling Computers

10

Modeling Pencil and Paper

# C S S A 7 2 3

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).

Page 11: Class 14: Modeling Computers

11

Modeling Output

• Blinking lights are cool, but hard to model

• Use the tape: output is what is written on the tape at the end

Connection Machine CM-5, 1993

Page 12: Class 14: Modeling Computers

12

Modeling Processing (Brains)

Look at the current state of the computation

Follow simple rules about what to do next

Page 13: Class 14: Modeling Computers

13

Modeling Processing

Evaluation RulesGiven 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 squareMove the tape one square in either directionWrite into the current square

0 0 1 1 0 0 1 0 0 0

Is that enough to model a computer?

Page 14: Class 14: Modeling Computers

14

Modeling Processing

Read, write and move is not enoughWe 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?

Page 15: Class 14: Modeling Computers

15

Finite State Machines

1Start 2

HALT

10

1#

0

Page 16: Class 14: Modeling Computers

16

Hmmm…maybe we don’t need those infinite tapes after all?

1Start 2

HALT

(not a paren

)#

not a paren

)

ERROR

What if thenext input symbolis ( in state 2?

Page 17: Class 14: Modeling Computers

17

How many states do we need?

1Start 2

HALT

(not a paren

)#

not a paren

)

ERROR

3

not a paren

(

)

4(

)

not a paren

(

Page 18: Class 14: Modeling Computers

18

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 define, draw, and reason about

Add an infinite tape to the Finite State Machine

Page 19: Class 14: Modeling Computers

19

Modeling Processing (Brains)

Follow simple rulesRemember what you are doing

“For the present I shall only say that the justification lies in the fact that the human memory is necessarily limited.” Alan Turing

Page 20: Class 14: Modeling Computers

20

FSM + Infinite Tape

Start: FSM in Start StateInput on Infinite TapePointer to start of input

Step:Read one input symbol from tapeWrite symbol on tape, and move L or R one squareFollow transition rule from current state

Finish:Transition to halt state

Page 21: Class 14: Modeling Computers

21

Turing’s Model: Turing Machine

1

Start

2

Input: #Write: #Move:

# 1 0 1 1 0 1 1... ...1 0 1 1 0 1 1 1 #

Input: 1Write: 0Move:

Input: 1Write: 1Move:

Input: 0Write: 0Move: 3

Input: 0Write: #Move: Halt

Infinite Tape: Finite set of symbols, one in each square Can read/write one square each step

Controller:Limited (finite) number of states

Follow rules based on current state and read symbol

Write one square each step, move left or right or halt, change state

Page 22: Class 14: Modeling Computers

22

Church-Turing ThesisAll mechanical computers are

equally powerful (except for practical limits like memory size, time, display, energy, etc.)

Some Turing machine can simulate any mechanical computer

Any computer that can simulate a Turing machine, can simulate any mechanical computer

Alonzo Church, 1903-1995

Alan Turing, 1912-1954

Take on faith for now: we will argue this more convincingly near the end of the course!

Page 23: Class 14: Modeling Computers

23

Turing Machine Summary

Model Input, Output, and Scratch MemoryInfinite tape, divided into discrete squaresEach square can contain a single symbol from a finite alphabet

Model ProcessingFinite State Machine

Keep track of a finite state (in your head)Follow transition rules:

next state = f(current state, input symbol)

Page 24: Class 14: Modeling Computers

24

ExampleMonday’s class will meet in Rice Hall Bagel Shop Area

Page 25: Class 14: Modeling Computers

25

Charge

PS4 Posted Today, due Monday 3 OctoberExam 1: out October 7, due October 12

Covers: Problem Sets 1-4 including PS CommentsCourse Book Chapters 1-6Classes 1-18

Monday’s class in Rice Hall