Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing...

21
1 KJH, ECE-548 12/8/2002 Turing Machine Turing Machine slides of Prof. K. J. Hintz used

Transcript of Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing...

Page 1: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

1

KJH, ECE-548 12/8/2002

Turing MachineTuring Machine

slides of Prof. K. J. Hintz used

Page 2: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

2

KJH, ECE-548 12/8/2002

Turing MachineTuring Machine

• An FSM Cannot Compute a NumberComprised of an Infinite Number of DigitsSince It Itself Is Finite.

• A Finite Method Can Be Developed toCompute an Infinite Length Number

• The Method Can Be Implemented byReading and Writing Intermediate Resultsfrom/to an Assumed Infinite Memory

Page 3: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

3

KJH, ECE-548 12/8/2002

Halting ProblemHalting Problem

• Difficulty with the Turing Machine– Not guaranteed to terminate– Don’t know when it will terminate

• Still an unsolved problem– Is there a method for analyzing a Turing

machine to determine if and when it willterminate its computation?

Page 4: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

4

KJH, ECE-548 12/8/2002

Turing MachineTuring Machine

• Devised by Alan Turing, 1937 paper*

• Definition of Computable

• Some Problems are Not Computable

* Turing, A. M., “On Computable Numbers, with an Application to the Entscheidungsproblem“, Proceedings of the London Mathematical Society, Series 2, 42:230-265 and 43:544-546, 1937.

Page 5: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

5

KJH, ECE-548 12/8/2002

Physical Model of TMPhysical Model of TM

Page 6: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

6

KJH, ECE-548 12/8/2002

PropertiesProperties

• Infinitely Long Readable/Writable TapeWith Fixed Left End

• Moveable Read/Write Tape Head– Only read/write to current position

• Finite State Machine for Control– Movement of tape head +/- 1 tape position only– Symbols written to tape

Page 7: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

7

KJH, ECE-548 12/8/2002

PropertiesProperties

• String on Tape– Left End of String at Left End of Tape– Tape Head Is Initially at Right End of String.

Left end of Tape Tape Head Initial Position

Page 8: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

8

KJH, ECE-548 12/8/2002

TM AlternativesTM Alternatives

• Multiple Heads• Infinite Tape in Both Directions• Tape Moves, Head Stationary• Increased Number of Symbols

None of These Changes Affect the BasicComputability of Turing Machines

Page 9: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

9

KJH, ECE-548 12/8/2002

TM Formal DefinitionTM Formal Definition

• A Turing Machine is a Quadruple

( )

{ }{ } { }

( ) { }( )

M T

Finite set of states Tape Symbols L, R

initial stateDeterministic transition function

:S S h L, R

=

∉ ∪

× → ∪ × ∪

SS

, , ,

#

Σ

Σ

Σ Σ

s

s

δ

δδ

Page 10: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

10

KJH, ECE-548 12/8/2002

TM ConfigurationTM Configuration

• The TM Configuration is a quadruple

( ){ }( ) { }( ) { }( )

C s, t , t, t

s Current Statet Sequence of symbols to the left of the tape head *t Current read symbol under the headt Sequence of symbols to the right of the tape head

T L R

L

R

=

∈ ∪ × × × − ∪

S h Σ Σ Σ Σ Λ

Σ

* * #

Page 11: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

11

KJH, ECE-548 12/8/2002

TM ConfigurationTM Configuration

• A Shorthand Notation( current state,

string with current head position underlined )e.g.,

( )q abbaab2 ,

Page 12: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

12

KJH, ECE-548 12/8/2002

TM Delta FunctionTM Delta Function

{ }( ) { }( )δ : S S× → ∪ × ∪Σ Σh L, R

PresentState

Read PresentSymbol

Next State & Symbol

q1 a ( p, b )

q2 # ( p, R )

If read an a, write a b.If read a blank (#), read-only, and move right one.

Page 13: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

13

KJH, ECE-548 12/8/2002

Two TM ExamplesTwo TM Examples

• Quantity Doubler:– State Table: head movement and write are done

in separate states– FSM: simultaneous write/move

• Odd Detector– Head movement and write are done

simultaneously

Page 14: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

14

KJH, ECE-548 12/8/2002

TM Example, 2XTM Example, 2X

( ){ }{ }

( ) ( )( ){ }�,L,s,#,s

1,#5,4,3,2,1,0

,,,

10

0

T2x

===Σ=

Σ=

δ

δ

ss

sS

SM

Tape Head Starting Position

Page 15: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

15

KJH, ECE-548 12/8/2002

TM Example, 2XTM Example, 2X

• Transition FunctionPS Input

# Input

1 Comment

s0 s1/L s0/L

s1 halt s2/# found a 1 to left, replace with #

s2 s3/R s3/R

Page 16: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

16

KJH, ECE-548 12/8/2002

TM Example, 2XTM Example, 2X

PS Input#

Input1

Comment

s3 s4/1 s3/R Move to right until at right-most end of string of 1’s

s4 s5/R

s5 s0/1 s5/R

Page 17: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

17

KJH, ECE-548 12/8/2002

# 1 1 # s0 # 1 # 1 1 # s0

# 1 1 # s1 # 1 # 1 1 # s1

# 1 # # s2 # # # 1 1 # s2

# 1 # # s3 # # # 1 1 # s3

# 1 # 1 # s4 # # 1 1 1 # s4

# 1 # 1 # s5 # # 1 1 1 # s5

# 1 # 1 1 # s0 # # 1 1 1 # s5

# 1 # 1 1 # s0 # # 1 1 1 # s5

TM Example, 2XTM Example, 2X

Page 18: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

18

KJH, ECE-548 12/8/2002

TM Example, 2XTM Example, 2X

# # 1 1 1 1 s5

# # 1 1 1 1 s0

# # 1 1 1 1 s0

# # 1 1 1 1 s0

# # 1 1 1 1 s0

# # 1 1 1 1 s0

# # 1 1 1 1 s1

Page 19: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

19

KJH, ECE-548 12/8/2002

FSM to Control 2x TMSimultaneous Write/MoveFSM to Control 2x TM

Simultaneous Write/Move

01

3

2

#/#,R

#/#,R

r / w, d

1/#,L

#/1,L1/1,L

1/1,L

1/1,R

#/1,R

Page 20: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

20

KJH, ECE-548 12/8/2002

TM Example 2, Odd Det.TM Example 2, Odd Det.

( ){ }{ }

( ) ( )( ){ }�,L,s,#,s

1,#1,0

,,,

10

0

T2x

===Σ=

Σ=

δ

δ

ss

sS

SM

Tape Head Starting Position

Page 21: Turing Machine - Computer Action Teamweb.cecs.pdx.edu/~mperkows/temp/Turing-Machine.pdf · Turing Machine • Devised by Alan Turing, 1937 paper* • Definition of Computable •

21

KJH, ECE-548 12/8/2002

TM Example 2, Odd Det.TM Example 2, Odd Det.

• Transition FunctionPS Input

# Input

1 Comment

s0 S0/#/R S1/#/R

s1 halt s0/#/R Halts if Odd