COMP20121 The Implementation and Power of Computer Languages Power - - PowerPoint PPT Presentation

comp20121 the implementation and power of computer
SMART_READER_LITE
LIVE PREVIEW

COMP20121 The Implementation and Power of Computer Languages Power - - PowerPoint PPT Presentation

COMP20121 The Implementation and Power of Computer Languages Power Part http://www.cs.man.ac.uk/ petera/2121/index.html . Peter Aczel room: CS2.52, tel: 56155 petera@cs.man.ac.uk email: School of Computer Science, University of


slide-1
SLIDE 1

COMP20121 The Implementation and Power of Computer Languages ‘Power’ Part

http://www.cs.man.ac.uk/∼petera/2121/index.html .

Peter Aczel room: CS2.52, tel: 56155 email:

petera@cs.man.ac.uk

School of Computer Science, University of Manchester

COMP20121 - Section 0 – p.1/307

slide-2
SLIDE 2

COMP20121, ‘power’ part: section 3 LECTURE SEVEN

Section 3: Turing machines

COMP20121 - Section 3 – p.139/307

slide-3
SLIDE 3

Turing: The man

Who was Alan Turing?

COMP20121 - Section 3 – p.140/307

slide-4
SLIDE 4

Turing: The man

Who was Alan Turing?

  • Founder of computer science,
  • mathematician, philosopher,
  • codebreaker, strange visionary

COMP20121 - Section 3 – p.140/307

slide-5
SLIDE 5

Turing: The man

Who was Alan Turing?

1912 (23 June): Birth, Paddington, London 1931-34: Undergraduate at King’s College, Cambridge University 1935: Elected fellow of King’s College, Cambridge 1936: The Turing machine, computability, universal machine

COMP20121 - Section 3 – p.140/307

slide-6
SLIDE 6

Turing: The man

Who was Alan Turing?

1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39: Return to Cambridge. Introduced to German Enigma cipher machine 1939-40: The Bombe, machine for Enigma decryption 1939-42: Breaking of U-boat Enigma, saving battle of the Atlantic

COMP20121 - Section 3 – p.140/307

slide-7
SLIDE 7

Turing: The man

Who was Alan Turing?

1943-45: Chief Anglo-American crypto consultant. Electronic work. 1945: National Physical Laboratory, London 1946: Computer and software design leading the world. 1947-48: Programming, neural nets, and artificial intelligence 1948: Manchester University

COMP20121 - Section 3 – p.140/307

slide-8
SLIDE 8

Turing: The man

Who was Alan Turing?

1949: First serious mathematical use of a computer 1950: The Turing Test for machine intelligence 1951: Elected FRS. Non-linear theory of biological growth 1952: Arrested as a homosexual, loss of security clearance 1953-54: Unfinished work in biology and physics 1954 (7 June): Death (suicide) by cyanide poisoning, Wilmslow, Cheshire.

COMP20121 - Section 3 – p.140/307

slide-9
SLIDE 9

Overview

  • In this section we introduce automata

which are more powerful than PDAs. They are known as Turing machines.

COMP20121 - Section 3 – p.141/307

slide-10
SLIDE 10

Overview

  • In this section we introduce automata

which are more powerful than PDAs. They are known as Turing machines.

  • These automata have read/write

memory, so they can access data they have stored in arbitrary order.

COMP20121 - Section 3 – p.141/307

slide-11
SLIDE 11

Overview

  • With these machines the notion of a

language associated with an automaton can be refined: a language can be decided

  • r recognized.

COMP20121 - Section 3 – p.142/307

slide-12
SLIDE 12

Overview

  • With these machines the notion of a

language associated with an automaton can be refined: a language can be decided

  • r recognized.
  • We finish by giving an overview over a

hierarchy of languages.

COMP20121 - Section 3 – p.142/307

slide-13
SLIDE 13

Automata with random-access memory

Idea: Give random-access read-write memory to automaton. We want:

  • to keep the idea of ‘state’;

COMP20121 - Section 3 – p.143/307

slide-14
SLIDE 14

Automata with random-access memory

Idea: Give random-access read-write memory to automaton. We want:

  • to keep the idea of ‘state’;
  • to describe automaton via transitions;

COMP20121 - Section 3 – p.143/307

slide-15
SLIDE 15

Automata with random-access memory

Idea: Give random-access read-write memory to automaton. We want:

  • to keep the idea of ‘state’;
  • to describe automaton via transitions;
  • a simple description.

COMP20121 - Section 3 – p.143/307

slide-16
SLIDE 16

Automata with random-access memory

Idea: Give random-access read-write memory to automaton. We want:

  • to keep the idea of ‘state’;
  • to describe automaton via transitions;
  • a simple description.

Idea: With read-write random-access memory, we can store input string in memory.

COMP20121 - Section 3 – p.143/307

slide-17
SLIDE 17

Transition function

A transition should depend on:

  • the current state;

COMP20121 - Section 3 – p.144/307

slide-18
SLIDE 18

Transition function

A transition should depend on:

  • the current state;
  • the content of memory cell(s?).

COMP20121 - Section 3 – p.144/307

slide-19
SLIDE 19

Transition function

A transition should depend on:

  • the current state;
  • the content of memory cell(s?).

A transition should lead to:

  • a sequence of actions;

COMP20121 - Section 3 – p.144/307

slide-20
SLIDE 20

Transition function

A transition should depend on:

  • the current state;
  • the content of memory cell(s?).

A transition should lead to:

  • a sequence of actions;
  • a new state.

COMP20121 - Section 3 – p.144/307

slide-21
SLIDE 21

Transition function

A transition should depend on:

  • the current state;
  • the content of memory cell(s?).

A transition should lead to:

  • a sequence of actions;
  • a new state.

(Compare PDAs.)

COMP20121 - Section 3 – p.144/307

slide-22
SLIDE 22

Actions

What actions should the machine be able to carry out?

  • Read from memory;

COMP20121 - Section 3 – p.145/307

slide-23
SLIDE 23

Actions

What actions should the machine be able to carry out?

  • Read from memory;
  • write to memory;

COMP20121 - Section 3 – p.145/307

slide-24
SLIDE 24

Actions

What actions should the machine be able to carry out?

  • Read from memory;
  • write to memory;
  • move to different memory cell.

COMP20121 - Section 3 – p.145/307

slide-25
SLIDE 25

Actions

What actions should the machine be able to carry out?

  • Read from memory;
  • write to memory;
  • move to different memory cell.

The easiest way of doing this is to assume that the memory is arranged linearly.

COMP20121 - Section 3 – p.145/307

slide-26
SLIDE 26

The memory

  • We think of the memory as an infinite

tape.

COMP20121 - Section 3 – p.146/307

slide-27
SLIDE 27

The memory

  • We think of the memory as an infinite

tape.

. . . a b a b . . .

COMP20121 - Section 3 – p.146/307

slide-28
SLIDE 28

The memory

  • Can do without memory addresses if we

assume there is one read/write head pointing at the ‘current’ memory cell and which can move along the tape.

. . . a b a b . . .

read/write head

COMP20121 - Section 3 – p.146/307

slide-29
SLIDE 29

The memory

  • This head is connected to a control unit

which tells it what to do (depending on the current state and the content of the current memory cell).

. . . a b a b

Control unit

. . .

read/write head

COMP20121 - Section 3 – p.146/307

slide-30
SLIDE 30

Alphabets

  • As before, we assume the language we

are interested in is built of letters from an alphabet Σ.

COMP20121 - Section 3 – p.147/307

slide-31
SLIDE 31

Alphabets

  • As before, we assume the language we

are interested in is built of letters from an alphabet Σ.

  • We need to be able to denote in the text

that a memory cell might be empty.

COMP20121 - Section 3 – p.147/307

slide-32
SLIDE 32

Alphabets

  • As before, we assume the language we

are interested in is built of letters from an alphabet Σ.

  • We need to be able to denote in the text

that a memory cell might be empty.

  • For that we use the symbol

.

COMP20121 - Section 3 – p.147/307

slide-33
SLIDE 33

Alphabets

  • As before, we assume the language we

are interested in is built of letters from an alphabet Σ.

  • We need to be able to denote in the text

that a memory cell might be empty.

  • For that we use the symbol

.

  • Sometimes there are other symbols we

want to be able to write onto the tape.

COMP20121 - Section 3 – p.147/307

slide-34
SLIDE 34

Alphabets

  • Therefore we assume that there is an

alphabet T of tape symbols with the property that

  • all symbols of Σ are contained in T and

COMP20121 - Section 3 – p.148/307

slide-35
SLIDE 35

Alphabets

  • Therefore we assume that there is an

alphabet T of tape symbols with the property that

  • all symbols of Σ are contained in T and
  • the symbol

is contained in T .

COMP20121 - Section 3 – p.148/307

slide-36
SLIDE 36

Alphabets

  • Therefore we assume that there is an

alphabet T of tape symbols with the property that

  • all symbols of Σ are contained in T and
  • the symbol

is contained in T . Note that T might contain other symbols.

COMP20121 - Section 3 – p.148/307

slide-37
SLIDE 37

Transition function

Therefore the transition function will take

  • the current state

from Q,

COMP20121 - Section 3 – p.149/307

slide-38
SLIDE 38

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

COMP20121 - Section 3 – p.149/307

slide-39
SLIDE 39

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

  • and will return

COMP20121 - Section 3 – p.149/307

slide-40
SLIDE 40

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

  • and will return
  • a new state

from Q,

COMP20121 - Section 3 – p.149/307

slide-41
SLIDE 41

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

  • and will return
  • a new state

from Q,

  • a symbol to write onto the tape from T ,

COMP20121 - Section 3 – p.149/307

slide-42
SLIDE 42

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

  • and will return
  • a new state

from Q,

  • a symbol to write onto the tape

from T ,

  • a direction

from {L, R, N}. A move is one step in that direction.

COMP20121 - Section 3 – p.149/307

slide-43
SLIDE 43

Transition function

Therefore the transition function will take

  • the current state

from Q,

  • the content of the current cell

from T ,

  • and will return
  • a new state

from Q,

  • a symbol to write onto the tape

from T ,

  • a direction

from {L, R, N}. A move is one step in that direction.

  • Alternatively, the machine might stop.

COMP20121 - Section 3 – p.149/307

slide-44
SLIDE 44

Turing machine

Definition 14 A Turing machine or TM over the tape alphabet

∈ T ⊇ Σ consists of

  • a finite set of states Q;

COMP20121 - Section 3 – p.150/307

slide-45
SLIDE 45

Turing machine

Definition 14 A Turing machine or TM over the tape alphabet

∈ T ⊇ Σ consists of

  • a finite set of states Q;
  • a start state q• ∈ Q;

COMP20121 - Section 3 – p.150/307

slide-46
SLIDE 46

Turing machine

Definition 14 A Turing machine or TM over the tape alphabet

∈ T ⊇ Σ consists of

  • a finite set of states Q;
  • a start state q• ∈ Q;
  • a set F ⊆ Q of accepting states;

COMP20121 - Section 3 – p.150/307

slide-47
SLIDE 47

Turing machine

Definition 14 A Turing machine or TM over the tape alphabet

∈ T ⊇ Σ consists of

  • a finite set of states Q;
  • a start state q• ∈ Q;
  • a set F ⊆ Q of accepting states;
  • a transition function that maps Q × T

to (Q × T × {L, R, N}) ∪ {stop}.

COMP20121 - Section 3 – p.150/307

slide-48
SLIDE 48

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turing machine can

  • manipulate the input string;

COMP20121 - Section 3 – p.151/307

slide-49
SLIDE 49

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turing machine can

  • manipulate the input string;
  • process the input string several times;

COMP20121 - Section 3 – p.151/307

slide-50
SLIDE 50

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turing machine can

  • manipulate the input string;
  • process the input string several times;
  • write to a random-access memory.

COMP20121 - Section 3 – p.151/307

slide-51
SLIDE 51

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turing machine can

  • manipulate the input string;
  • process the input string several times;
  • write to a random-access memory.

Like a pushdown automaton, a Turing machine may run forever (on some input strings).

COMP20121 - Section 3 – p.151/307

slide-52
SLIDE 52

Example

We typically give a Turing machine via its transition table.

COMP20121 - Section 3 – p.152/307

slide-53
SLIDE 53

Example

We typically give a Turing machine via its transition table. For example:

δ a b (0, a, R) (1, b, R)

stop

1

stop stop stop

COMP20121 - Section 3 – p.152/307

slide-54
SLIDE 54

Example

We typically give a Turing machine via its transition table. For example:

δ a b (0, a, R) (1, b, R)

stop

1

stop stop stop

To see what this machine does with an input string, we first have to define what it means for a TM to accept an input string.

COMP20121 - Section 3 – p.152/307

slide-55
SLIDE 55

Acceptance of a string by a TM.

Definition 15 We say that a string α is accepted by a Turing machine if, when

  • started in the initial state
  • with the head positioned on the first

(left-most) character of α and

  • the tape otherwise empty

the Turing machine halts and the state at that time is an accepting state.

COMP20121 - Section 3 – p.153/307

slide-56
SLIDE 56

Example–II

Assume that the Turing machine given by the transition table

δ a b 0 (0, a, R) (1, b, R) stop 1

stop stop stop has only one accepting state, namely 0.

COMP20121 - Section 3 – p.154/307

slide-57
SLIDE 57

Example–II

δ a b (0, a, R) (1, b, R)

stop

1

stop stop stop

Then the language accepted by the machine is

COMP20121 - Section 3 – p.155/307

slide-58
SLIDE 58

Example–II

δ a b (0, a, R) (1, b, R)

stop

1

stop stop stop

Then the language accepted by the machine is the language of all words consisting entirely of as.

COMP20121 - Section 3 – p.155/307

slide-59
SLIDE 59

Example–II

δ a b (0, a, R) (1, b, R)

stop

1

stop stop stop

Then the language accepted by the machine is the language of all words consisting entirely of as. At the end of the calculation, the input string is untouched.

COMP20121 - Section 3 – p.155/307

slide-60
SLIDE 60

Example–III

Assume that the Turing machine given by the transition table

δ a b 0 (0, , R) (1, , R) stop 1

stop stop stop has only one accepting state, namely 0.

COMP20121 - Section 3 – p.156/307

slide-61
SLIDE 61

Example–III

δ a b (0, , R) (1, , R)

stop

1

stop stop stop

Then the language accepted by the machine is

COMP20121 - Section 3 – p.157/307

slide-62
SLIDE 62

Example–III

δ a b (0, , R) (1, , R)

stop

1

stop stop stop

Then the language accepted by the machine is the language of all words consisting entirely of as.

COMP20121 - Section 3 – p.157/307

slide-63
SLIDE 63

Example–III

δ a b (0, , R) (1, , R)

stop

1

stop stop stop

Then the language accepted by the machine is the language of all words consisting entirely of as. At the end of the calculation, the input string has been destroyed.

COMP20121 - Section 3 – p.157/307

slide-64
SLIDE 64

A more sophisticated example

Consider the following Turing machine with

  • nly accepting state 0.

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

COMP20121 - Section 3 – p.158/307

slide-65
SLIDE 65

A more sophisticated example

Consider the following Turing machine with

  • nly accepting state 0.

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

What is the language accepted by this Turing machine?

COMP20121 - Section 3 – p.158/307

slide-66
SLIDE 66

A more sophisticated example

Consider the following Turing machine with

  • nly accepting state 0.

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

What is the language accepted by this Turing machine? Not so easy!

COMP20121 - Section 3 – p.158/307

slide-67
SLIDE 67

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-68
SLIDE 68

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-69
SLIDE 69

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-70
SLIDE 70

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-71
SLIDE 71

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-72
SLIDE 72

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-73
SLIDE 73

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . . a

COMP20121 - Section 3 – p.159/307

slide-74
SLIDE 74

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . .

COMP20121 - Section 3 – p.159/307

slide-75
SLIDE 75

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . .

COMP20121 - Section 3 – p.159/307

slide-76
SLIDE 76

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . .

COMP20121 - Section 3 – p.159/307

slide-77
SLIDE 77

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . .

COMP20121 - Section 3 – p.159/307

slide-78
SLIDE 78

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . b a b . . .

COMP20121 - Section 3 – p.159/307

slide-79
SLIDE 79

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a b . . .

COMP20121 - Section 3 – p.159/307

slide-80
SLIDE 80

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a b . . .

COMP20121 - Section 3 – p.159/307

slide-81
SLIDE 81

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a b . . .

COMP20121 - Section 3 – p.159/307

slide-82
SLIDE 82

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a b . . .

COMP20121 - Section 3 – p.159/307

slide-83
SLIDE 83

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a . . .

COMP20121 - Section 3 – p.159/307

slide-84
SLIDE 84

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a . . .

COMP20121 - Section 3 – p.159/307

slide-85
SLIDE 85

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . a . . .

COMP20121 - Section 3 – p.159/307

slide-86
SLIDE 86

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . . . .

COMP20121 - Section 3 – p.159/307

slide-87
SLIDE 87

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . . . .

COMP20121 - Section 3 – p.159/307

slide-88
SLIDE 88

Running a Turing machine

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . . . .

Hence the word ababa is accepted by the machine.

COMP20121 - Section 3 – p.159/307

slide-89
SLIDE 89

Configurations

We use a configuration

x1x2 · · · xiqxi+1 · · · xn

to describe a situation where

COMP20121 - Section 3 – p.160/307

slide-90
SLIDE 90

Configurations

We use a configuration

x1x2 · · · xiqxi+1 · · · xn

to describe a situation where

  • the content of the tape is x1 · · · xn

(where the xj are from T ), and all cells to the left of x1 and to the right of

xn are blank;

COMP20121 - Section 3 – p.160/307

slide-91
SLIDE 91

Configurations

We use a configuration

x1x2 · · · xiqxi+1 · · · xn

to describe a situation where

  • the current state is q;
  • the head currently points at the cell

holding xi+1.

COMP20121 - Section 3 – p.160/307

slide-92
SLIDE 92

Configurations

We use a configuration

x1x2 · · · xiqxi+1 · · · xn

to describe a situation where

Control unit

x2 x1 · · · · · · · · · xi xi+1 xn · · ·

State: q

COMP20121 - Section 3 – p.160/307

slide-93
SLIDE 93

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

0ababa

. . . a b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-94
SLIDE 94

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

1baba

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-95
SLIDE 95

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

b1aba

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-96
SLIDE 96

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

ba1ba

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-97
SLIDE 97

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

bab1a

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-98
SLIDE 98

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

baba1

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-99
SLIDE 99

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

bab3a

. . . b a b . . . a

COMP20121 - Section 3 – p.161/307

slide-100
SLIDE 100

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

ba5b

. . . b a b . . .

COMP20121 - Section 3 – p.161/307

slide-101
SLIDE 101

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

b5ab

. . . b a b . . .

COMP20121 - Section 3 – p.161/307

slide-102
SLIDE 102

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

5bab

. . . b a b . . .

COMP20121 - Section 3 – p.161/307

slide-103
SLIDE 103

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

5 bab

. . . b a b . . .

COMP20121 - Section 3 – p.161/307

slide-104
SLIDE 104

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

0bab

. . . b a b . . .

COMP20121 - Section 3 – p.161/307

slide-105
SLIDE 105

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

2ab

. . . a b . . .

COMP20121 - Section 3 – p.161/307

slide-106
SLIDE 106

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

a2b

. . . a b . . .

COMP20121 - Section 3 – p.161/307

slide-107
SLIDE 107

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

ab2

. . . a b . . .

COMP20121 - Section 3 – p.161/307

slide-108
SLIDE 108

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

a4b

. . . a b . . .

COMP20121 - Section 3 – p.161/307

slide-109
SLIDE 109

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

5a

. . . a . . .

COMP20121 - Section 3 – p.161/307

slide-110
SLIDE 110

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

5 a

. . . a . . .

COMP20121 - Section 3 – p.161/307

slide-111
SLIDE 111

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

0a

. . . a . . .

COMP20121 - Section 3 – p.161/307

slide-112
SLIDE 112

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

1

. . . . . .

COMP20121 - Section 3 – p.161/307

slide-113
SLIDE 113

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

3

. . . . . .

COMP20121 - Section 3 – p.161/307

slide-114
SLIDE 114

Running a Turing machine–II

δ a b (1, , R) (2, , R)

stop 1

(1, a, R) (1, b, R) (3, , L)

2

(2, a, R) (2, b, R) (4, , L)

3

(5, , L)

stop

(0, , N)

4 stop

(5, , L) (0, , N)

5

(5, a, L) (5, b, L) (0, , R)

. . . . . .

COMP20121 - Section 3 – p.161/307

slide-115
SLIDE 115

Running a Turing machine–II

Hence the word ababa is accepted by the machine. We normally would not keep repeating the transition function, just give the sequence

  • f configurations the machine goes

through.

COMP20121 - Section 3 – p.161/307

slide-116
SLIDE 116

Running a Turing machine–II

0ababa → 1baba → 1baba → 1baba → 1baba → 1baba → b1aba → ba1ba → bab1a → baba1 → bab3a → ba5b → b5ab → 5bab → 5 bab → 0bab → 2ab → a2b → ab2 → a4b → 5a → 5 a → 0a → 1 → 3 → 0 stop

COMP20121 - Section 3 – p.161/307