turing machines - university of bristoli 1936:invented the turing machine and the concept of...

52
COMS11700 Turing machines Ashley Montanaro [email protected] Department of Computer Science, University of Bristol Bristol, UK 21 March 2014 Ashley Montanaro [email protected] COMS11700: Turing machines Slide 1/15

Upload: others

Post on 15-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

COMS11700

Turing machines

Ashley [email protected]

Department of Computer Science, University of BristolBristol, UK

21 March 2014

Ashley [email protected]

COMS11700: Turing machines Slide 1/15

Page 2: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

IntroductionWe have seen two models of computation: finite automata and pushdownautomata. We now discuss a model which is much more powerful: theTuring machine.

A Turing machine is like a finite automaton, with three major differences:I It can write to its tape;I It can move both left and right;I The tape is infinite in one direction.

a b b a a . . .

Control

Initially, the input is provided on the left-hand end of the tape, and followedby an infinite sequence of blank spaces (“ ”).

Ashley [email protected]

COMS11700: Turing machines Slide 2/15

Page 3: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

IntroductionWe have seen two models of computation: finite automata and pushdownautomata. We now discuss a model which is much more powerful: theTuring machine.

A Turing machine is like a finite automaton, with three major differences:I It can write to its tape;I It can move both left and right;I The tape is infinite in one direction.

a b b a a . . .

Control

Initially, the input is provided on the left-hand end of the tape, and followedby an infinite sequence of blank spaces (“ ”).

Ashley [email protected]

COMS11700: Turing machines Slide 2/15

Page 4: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

a b b a a . . .

q0

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 5: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c b b a a . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 6: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 7: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q3

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 8: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 9: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 10: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 11: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 12: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example

c a b a a c . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 3/15

Page 13: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Alan Turing (1912-1954)I 1936: Invented the Turing machine and the concept of computability.I 1939-1945: Worked at Bletchley Park on cracking the Enigma

cryptosystem and others.I 1946-1954: Work on practical computers, AI, mathematical biology, ...I 1952: Convicted of indecency. Died of cyanide poisoning in 1954.I 2014: Received a royal pardon.

Pic: Wikipedia/Bletchley Park

Ashley [email protected]

COMS11700: Turing machines Slide 4/15

Page 14: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

I Turing machines have two special states: an accept state and a rejectstate.

I If the machine enters the accept or reject state, it halts (stops).

I If it doesn’t ever enter either of these states, it never halts (i.e. it runsforever).

I The language L(M) recognised by a Turing machine M is the set

{x | M halts in the accept state on input x}

I For some language L, if there exists a Turing machine M such thatL = L(M), we say that L is Turing-recognisable. (These languagesare also sometimes called recursively enumerable.)

Ashley [email protected]

COMS11700: Turing machines Slide 5/15

Page 15: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

I Turing machines have two special states: an accept state and a rejectstate.

I If the machine enters the accept or reject state, it halts (stops).

I If it doesn’t ever enter either of these states, it never halts (i.e. it runsforever).

I The language L(M) recognised by a Turing machine M is the set

{x | M halts in the accept state on input x}

I For some language L, if there exists a Turing machine M such thatL = L(M), we say that L is Turing-recognisable. (These languagesare also sometimes called recursively enumerable.)

Ashley [email protected]

COMS11700: Turing machines Slide 5/15

Page 16: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

I Turing machines have two special states: an accept state and a rejectstate.

I If the machine enters the accept or reject state, it halts (stops).

I If it doesn’t ever enter either of these states, it never halts (i.e. it runsforever).

I The language L(M) recognised by a Turing machine M is the set

{x | M halts in the accept state on input x}

I For some language L, if there exists a Turing machine M such thatL = L(M), we say that L is Turing-recognisable. (These languagesare also sometimes called recursively enumerable.)

Ashley [email protected]

COMS11700: Turing machines Slide 5/15

Page 17: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

I Turing machines have two special states: an accept state and a rejectstate.

I If the machine enters the accept or reject state, it halts (stops).

I If it doesn’t ever enter either of these states, it never halts (i.e. it runsforever).

I The language L(M) recognised by a Turing machine M is the set

{x | M halts in the accept state on input x}

I For some language L, if there exists a Turing machine M such thatL = L(M), we say that L is Turing-recognisable. (These languagesare also sometimes called recursively enumerable.)

Ashley [email protected]

COMS11700: Turing machines Slide 5/15

Page 18: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

I Turing machines have two special states: an accept state and a rejectstate.

I If the machine enters the accept or reject state, it halts (stops).

I If it doesn’t ever enter either of these states, it never halts (i.e. it runsforever).

I The language L(M) recognised by a Turing machine M is the set

{x | M halts in the accept state on input x}

I For some language L, if there exists a Turing machine M such thatL = L(M), we say that L is Turing-recognisable. (These languagesare also sometimes called recursively enumerable.)

Ashley [email protected]

COMS11700: Turing machines Slide 5/15

Page 19: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Describing Turing machinesWe can describe a Turing machine by its state diagram.

I As with DFAs and PDAs, we have a graph whose vertices are labelledby states of the machine, and whose edges are labelled by possibletransitions.

q1 q2a→ b,R

I A label of the forma→ b,R

means that on reading tape symbol a, the machine writes b to thetape and then moves right.

I Another example: a labela,b→ L

means that on reading either tape symbol a or b, the machine doesn’twrite anything to the tape and then moves left.

Ashley [email protected]

COMS11700: Turing machines Slide 6/15

Page 20: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Describing Turing machinesWe can describe a Turing machine by its state diagram.

I As with DFAs and PDAs, we have a graph whose vertices are labelledby states of the machine, and whose edges are labelled by possibletransitions.

q1 q2a→ b,R

I A label of the forma→ b,R

means that on reading tape symbol a, the machine writes b to thetape and then moves right.

I Another example: a labela,b→ L

means that on reading either tape symbol a or b, the machine doesn’twrite anything to the tape and then moves left.

Ashley [email protected]

COMS11700: Turing machines Slide 6/15

Page 21: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Describing Turing machinesWe can describe a Turing machine by its state diagram.

I As with DFAs and PDAs, we have a graph whose vertices are labelledby states of the machine, and whose edges are labelled by possibletransitions.

q1 q2a→ b,R

I A label of the forma→ b,R

means that on reading tape symbol a, the machine writes b to thetape and then moves right.

I Another example: a labela,b→ L

means that on reading either tape symbol a or b, the machine doesn’twrite anything to the tape and then moves left.

Ashley [email protected]

COMS11700: Turing machines Slide 6/15

Page 22: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

Imagine we want to test membership in the language

LEQ = {w#w | w ∈ {0,1}∗}.

x ∈ LEQ if it is made up of two equal bit-strings, separated by a # symbol.

Idea for recognising this language

1. Our algorithm will scan forwards and backwards, testing eachcorresponding pair of bits either side of the # for equality in turn.

2. We can overwrite each bit with an x symbol after checking it so wedon’t check the same bits twice.

Ashley [email protected]

COMS11700: Turing machines Slide 7/15

Page 23: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines

Imagine we want to test membership in the language

LEQ = {w#w | w ∈ {0,1}∗}.

x ∈ LEQ if it is made up of two equal bit-strings, separated by a # symbol.

Idea for recognising this language

1. Our algorithm will scan forwards and backwards, testing eachcorresponding pair of bits either side of the # for equality in turn.

2. We can overwrite each bit with an x symbol after checking it so wedon’t check the same bits twice.

Ashley [email protected]

COMS11700: Turing machines Slide 7/15

Page 24: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

State diagram (Sipser, Figure 3.10)

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

#→ R

1→x,R

#→ R

0,1→ R

→ R

x→ R

#→ R

0,1→ R

0→x,L

x→ R

1→x,

Lx→ R

#→ L

0,1,x→ L 0,1→ L

x→ R

Ashley [email protected]

COMS11700: Turing machines Slide 8/15

Page 25: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

0 1 # 0 1 . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 26: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # 0 1 . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 27: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # 0 1 . . .

q2

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 28: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # 0 1 . . .

q4

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 29: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # x 1 . . .

q6

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 30: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # x 1 . . .

q7

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 31: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # x 1 . . .

q7

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 32: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x 1 # x 1 . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 33: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x 1 . . .

q3

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 34: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x 1 . . .

q5

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 35: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x 1 . . .

q5

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 36: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q6

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 37: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q6

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 38: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q7

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 39: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q1

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 40: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q8

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 41: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q8

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 42: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

q8

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 43: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Example: testing whether 01#01 ∈ LEQ

q1

q3

q8

q2

q5

qaccept

q4

q6 q7

0→x,

R

# → R

1→x,R

# → R

0,1 → R

→ R

x → R

# → R

0,1 → R

0→x, L

x → R

1→x,

Lx → R

# → L

0,1,x → L 0,1 → L

x → R

x x # x x . . .

qaccept

Ashley [email protected]

COMS11700: Turing machines Slide 9/15

Page 44: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition

DefinitionA Turing machine is described by a 7-tuple (Q,Σ, Γ, δ,q0,qaccept,qreject),where:

1. Q is the set of states,2. Σ is the input alphabet (which must not contain ),3. Γ is the tape alphabet, where ∈ Γ and Σ ⊆ Γ,4. δ : Q × Γ→ Q × Γ× {L,R} is the transition function,5. q0 ∈ Q is the start state,6. qaccept is the accept state,7. qreject is the reject state, where qreject 6= qaccept.

Ashley [email protected]

COMS11700: Turing machines Slide 10/15

Page 45: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

ExampleThe Turing machine we just saw is described by

({q1, . . . ,q8,qaccept,qreject}, {0,1,#}, {0,1,#,x, }, δ, q1, qaccept, qreject)

where the transition function δ is defined by the table

0 1 # xq1 q2,x,R q3,x,R q8,Rq2 q2,R q2,R q4,Rq3 q3,R q3,R q5,Rq4 q6,x,L q4,Rq5 q6,x,L q5,Rq6 q6,L q6,L q7,L q6,Lq7 q7,L q7,L q1,Rq8 q8,R qaccept,R

Blank entries in the table correspond to transitions where the machinerejects.

Ashley [email protected]

COMS11700: Turing machines Slide 11/15

Page 46: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition (2)

I The full description of what a Turing machine M is doing at any pointin time is called its configuration.

I We write uqv for the configuration where:I the tape to the left of the current position contains u;I the tape to the right of the current position (and including the current

position) contains v (followed by an infinite number of ’s);I the machine is in state q.

I For example, 01q3110 describes the following situation:

0 1 1 1 0 . . .

q3

Ashley [email protected]

COMS11700: Turing machines Slide 12/15

Page 47: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition (2)

I The full description of what a Turing machine M is doing at any pointin time is called its configuration.

I We write uqv for the configuration where:I the tape to the left of the current position contains u;I the tape to the right of the current position (and including the current

position) contains v (followed by an infinite number of ’s);I the machine is in state q.

I For example, 01q3110 describes the following situation:

0 1 1 1 0 . . .

q3

Ashley [email protected]

COMS11700: Turing machines Slide 12/15

Page 48: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition (3)

I Configuration C1 yields C2 if M can go from C1 to C2 in one step. So:I uaqjbv yields uqk acv if δ(qj , b) = (qk , c, L);I uaqjbv yields uacqk v if δ(qj , b) = (qk , c,R).

I If M is at the left-hand end of the tape, it cannot move any further tothe left; but M can move arbitrarily far to the right (the tape is one-wayinfinite).

I M accepts input x if there is a sequence of configurations C1, . . . ,Cksuch that:

1. C1 is the start configuration of M on input x ;2. For all 1 ≤ i ≤ k − 1, Ci yields Ci+1;3. Ck is an accepting configuration (M is in state qaccept).

Ashley [email protected]

COMS11700: Turing machines Slide 13/15

Page 49: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition (3)

I Configuration C1 yields C2 if M can go from C1 to C2 in one step. So:I uaqjbv yields uqk acv if δ(qj , b) = (qk , c, L);I uaqjbv yields uacqk v if δ(qj , b) = (qk , c,R).

I If M is at the left-hand end of the tape, it cannot move any further tothe left; but M can move arbitrarily far to the right (the tape is one-wayinfinite).

I M accepts input x if there is a sequence of configurations C1, . . . ,Cksuch that:

1. C1 is the start configuration of M on input x ;2. For all 1 ≤ i ≤ k − 1, Ci yields Ci+1;3. Ck is an accepting configuration (M is in state qaccept).

Ashley [email protected]

COMS11700: Turing machines Slide 13/15

Page 50: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Turing machines: formal definition (3)

I Configuration C1 yields C2 if M can go from C1 to C2 in one step. So:I uaqjbv yields uqk acv if δ(qj , b) = (qk , c, L);I uaqjbv yields uacqk v if δ(qj , b) = (qk , c,R).

I If M is at the left-hand end of the tape, it cannot move any further tothe left; but M can move arbitrarily far to the right (the tape is one-wayinfinite).

I M accepts input x if there is a sequence of configurations C1, . . . ,Cksuch that:

1. C1 is the start configuration of M on input x ;2. For all 1 ≤ i ≤ k − 1, Ci yields Ci+1;3. Ck is an accepting configuration (M is in state qaccept).

Ashley [email protected]

COMS11700: Turing machines Slide 13/15

Page 51: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Real-world implementations

As well as being a mathematical tool, a Turing machine is a real machinethat we can build. . .

I http://aturingmachine.com/index.php

I http://www.legoturingmachine.org

Ashley [email protected]

COMS11700: Turing machines Slide 14/15

Page 52: Turing machines - University of BristolI 1936:Invented the Turing machine and the concept of computability. I 1939-1945:Worked at Bletchley Park on cracking the Enigma cryptosystem

Summary and further reading

I A Turing machine is a generalisation of a finite automaton which hasaccess to an infinite tape which it can read from and write to.

I Turing machines can perform complicated computations (althoughwriting these down formally can be a painful process).

I Further reading: Sipser §3.1.

Ashley [email protected]

COMS11700: Turing machines Slide 15/15