Class 34 Models of Computation CS 200 Computer

  • Slides: 28
Download presentation
Class 34: Models of Computation CS 200: Computer Science David Evans University of Virginia

Class 34: Models of Computation CS 200: Computer Science David Evans University of Virginia 15 April 2002 CS 200 Spring 2002 http: //www. cs. virginia. edu/~evans Computer Science

Menu • • Are complexity classes really meaningful? How can we model computation? Turing

Menu • • Are complexity classes really meaningful? How can we model computation? Turing Machines Universal Turing Machine 15 April 2002 CS 200 Spring 2002 2

Complexity Classes • We claimed problem complexity doesn’t depend on the language or computer:

Complexity Classes • We claimed problem complexity doesn’t depend on the language or computer: problems are in class P and NP regardless of what kind of computer you have • In PS 7, we saw that if you have a quantum computer you solve a problem that has no known polynomial time solution on a “normal computer” in polynomial time. • This should bother you! 15 April 2002 CS 200 Spring 2002 3

Computability • Does our computer model change whether or not something is undecidable? No

Computability • Does our computer model change whether or not something is undecidable? No – we proved things we undecidable by showing a contradiction. It doesn’t depend on how we model computers. 15 April 2002 CS 200 Spring 2002 4

How should we model a Computer? Colossus (1944) Cray-1 (1976) Apollo Guidance Computer (1969)

How should we model a Computer? Colossus (1944) Cray-1 (1976) Apollo Guidance Computer (1969) IBM 5100 (1975) 5

Modeling Computers • Input – Without it, we can’t describe a problem • Output

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 15 April 2002 CS 200 Spring 2002 6

Modeling Input Punch Cards Altair BASIC Paper Tape, 1976 15 April 2002 Engelbart’s mouse

Modeling Input Punch Cards Altair BASIC Paper Tape, 1976 15 April 2002 Engelbart’s mouse and keypad CS 200 Spring 2002 7

Simplest Input • Non-interactive: like punch cards and paper tape • One-dimensional: just a

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 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). 15 April 2002 CS 200 Spring 2002 8

Modeling Output • Blinking lights are cool, but hard to model • Output is

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 15 April 2002 CS 200 Spring 2002 9

Modeling Processing • Evaluation Rules – Given an input on our tape, how do

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 15 April 2002 0 1 1 0 0 0 200 Spring 2002 10 Is that. CSenough to model a computer?

Modeling Processing • Read, write and move is not enough • We also need

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? 15 April 2002 CS 200 Spring 2002 11

Finite State Machines 1 0 Start 2 1 # 0 1 HAL T 15

Finite State Machines 1 0 Start 2 1 # 0 1 HAL T 15 April 2002 CS 200 Spring 2002 12

Hmmm…maybe we don’t need those infinite tapes after all? not a paren ) #

Hmmm…maybe we don’t need those infinite tapes after all? not a paren ) # ERRO R 15 April 2002 2 1 Start not a paren ( ) HAL T CS 200 Spring 2002 What if the next input symbol is ( in state 2? 13

How many states do we need? not a paren ) # ERRO R 15

How many states do we need? not a paren ) # ERRO R 15 April 2002 not a paren 2 1 Start not a paren ( ( ) HAL T CS 200 Spring 2002 3 ) not a paren ( ) 4 14 (

Finite State Machine • There are lots of things we can’t compute with only

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 15 April 2002 CS 200 Spring 2002 15

FSM + Infinite Tape • Start: – FSM in Start State – Input on

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 15 April 2002 CS 200 Spring 2002 16

Matching Parentheses • Repeat until halt: – Find the leftmost ) • If you

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 15 April 2002 CS 200 Spring 2002 17

Matching Parentheses (, (, R X, X, R Start 1 #, 1, # Opps!

Matching Parentheses (, (, R X, X, R Start 1 #, 1, # Opps! There is a problem with this as Spencer noticed in class. It will report the wrong result for input like ((). 15 April 2002 Fixing it is left for you. Input: ) Write: X Move: L (, X, R HAL T CS 200 Spring 2002 ), X, L X, X, L 2: look for ( #, 0, # 18

Turing Machine • This is a “Turing Machine” • Alan Turing, On computable numbers:

Turing Machine • This is a “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? 15 April 2002 CS 200 Spring 2002 19

Describing Turing Machines z z z z ), X, L ), #, R (,

Describing Turing Machines z z z z ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R #, 1, - HAL T #, 0, - Finite State Machine z z z Turing. Machine : : = < Alphabet, Tape, FSM > Alphabet : : = { Symbol* } Tape : : = < Left. Side, Current, Right. Side > One. Square : : = Symbol | # Current : : = One. Square Left. Side : : = [ Square* ] Right. Side : : = [ Square* ] Everything to left of Left. Side is #. Everything to right of Right. Side is #. 15 April 2002 z CS 200 Spring 2002 20

 ), #, R Start #, 1, # 1 ), X, L (, X,

), #, R Start #, 1, # 1 ), X, L (, X, R HAL T (, #, L 2: look for ( #, 0, # Describing Finite State Machines Turing. Machine : : = < Alphabet, Tape, FSM > FSM : : = < States, Transition. Rules, Initial. State, Halting. States > States : : = { State. Name* } Initial. State : : = State. Name must be element of States Halting. States : : = { State. Name* } all must be elements of States Transition. Rules : : = { Transition. Rule* } Transition. Rule : : = < State. Name, ; ; Current State Transition Rule is a procedure: One. Square, ; ; Current square State. Name X One. Square State. Name, ; ; Next State. Name X One. Square X Direction One. Square, ; ; Write on tape Direction > ; ; Move tape 15 April 2002 CS 200 Spring 2002 21 Direction : : = L, R, #

 ), #, R 1 Start ), X, L (, X, R (, #,

), #, R 1 Start ), X, L (, X, R (, #, L 2: look for ( Example Turing Machine #, 0, # HAL T Turing. Machine : : = < Alphabet, Tape, FSM > FSM : : = < States, Transition. Rules, Initial. State, Halting. States > Alphabet : : = { (, ), X } States : : = { 1, 2, HALT } Initial. State : : = 1 Halting. States : : = { HALT } Transition. Rules : : = { < 1, ), 2, X, L >, < 1, #, HALT, 1, # >, < 1, ), #, R >, < 2, (, 1, X, R >, < 2, #, HALT, 0, # >, < 2, ), #, L >, } #, 1, # 15 April 2002 CS 200 Spring 2002 22

Enumerating Turing Machines • Now that we’ve decided how to describe Turing Machines, we

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 1 s • TM= Photomosaic Program • TM= Windows. XP 3523796834721038296738259873 3672349872381692309875823987609823712347823 Not the real numbers – they would be much bigger! 15 April 2002 CS 200 Spring 2002 23

Universal Turing Machines 15 April 2002 CS 200 Spring 2002 24

Universal Turing Machines 15 April 2002 CS 200 Spring 2002 24

Universal Turing Machine P Number of TM I Input Tape Universal Turing Machine Output

Universal Turing Machine P Number of TM I Input Tape Universal Turing Machine Output Tape for running TM-P in tape I Can we make a Universal Turing Machine? also, just a number! 15 April 2002 CS 200 Spring 2002 25

Yes! • 5, 495 bits • Marvin Minsky designed a Universal Turing Machine with

Yes! • 5, 495 bits • Marvin Minsky designed a Universal Turing Machine with 4 symbols and 7 states! http: //www. verostko. com/manchester/text-page. html 15 April 2002 CS 200 Spring 2002 26

Church-Turing Thesis • Any mechanical computation can be performed by a Turing Machine •

Church-Turing Thesis • Any mechanical computation can be performed by a Turing Machine • There is a TM-n corresponding to every decidable problem • We can simulate one step on any “normal” (classical mechanics) computer with a constant number of steps on a TM: – If a problem is in P on a TM, it is in P on an i. Mac, CM 5, Cray, Palm, etc. 15 April 2002 CS 200 Spring 2002 27

Charge • Wednesday, Friday: – Lambda Calculus model of computation – Very different from

Charge • Wednesday, Friday: – Lambda Calculus model of computation – Very different from Turing Machines, but we will show that it is exactly as powerful! • Project Feedback: I will either email you before Wednesday, or return comments on Wednesday 15 April 2002 CS 200 Spring 2002 28