comp20121, ‘power’ part: section 3petera/2121/slides/lecture7.pdfturing: the man who was alan...

116
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: [email protected] School of Computer Science, University of Manchester COMP20121 - Section 0 – p.1/307

Upload: others

Post on 25-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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: [email protected]

School of Computer Science, University of Manchester

COMP20121 - Section 0 – p.1/307

Page 2: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

COMP20121, ‘power’ part: section 3

LECTURE SEVENSection 3: Turing machines

COMP20121 - Section 3 – p.139/307

Page 3: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing: The man

Who was Alan Turing?

COMP20121 - Section 3 – p.140/307

Page 4: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing: The man

Who was Alan Turing?

• Founder of computer science,

• mathematician, philosopher,

• codebreaker, strange visionary

COMP20121 - Section 3 – p.140/307

Page 5: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 6: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 7: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 8: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 9: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 10: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 11: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Overview

• With these machines the notion of a

language associated with an automaton

can be refined: a language can be decided

or recognized.

COMP20121 - Section 3 – p.142/307

Page 12: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Overview

• With these machines the notion of a

language associated with an automaton

can be refined: a language can be decided

or recognized.

• We finish by giving an overview over a

hierarchy of languages.

COMP20121 - Section 3 – p.142/307

Page 13: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Automata with random-access memory

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

• to keep the idea of ‘state’;

COMP20121 - Section 3 – p.143/307

Page 14: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Automata with random-access memory

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

• to keep the idea of ‘state’;

• to describe automaton via transitions;

COMP20121 - Section 3 – p.143/307

Page 15: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Automata with random-access memory

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

• to keep the idea of ‘state’;

• to describe automaton via transitions;

• a simple description.

COMP20121 - Section 3 – p.143/307

Page 16: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Automata with random-access memory

Idea: Give random-access read-writememory 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 inmemory.

COMP20121 - Section 3 – p.143/307

Page 17: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Transition function

A transition should depend on:

• the current state;

COMP20121 - Section 3 – p.144/307

Page 18: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Transition function

A transition should depend on:

• the current state;

• the content of memory cell(s?).

COMP20121 - Section 3 – p.144/307

Page 19: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 20: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 21: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 22: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Actions

What actions should the machine be able

to carry out?

• Read from memory;

COMP20121 - Section 3 – p.145/307

Page 23: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Actions

What actions should the machine be able

to carry out?

• Read from memory;

• write to memory;

COMP20121 - Section 3 – p.145/307

Page 24: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 25: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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 toassume that the memory is arranged

linearly.

COMP20121 - Section 3 – p.145/307

Page 26: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

The memory

• We think of the memory as an infinite

tape.

COMP20121 - Section 3 – p.146/307

Page 27: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

The memory

• We think of the memory as an infinite

tape.. . .a b a b. . .

COMP20121 - Section 3 – p.146/307

Page 28: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 29: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 30: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• As before, we assume the language weare interested in is built of letters from analphabet Σ.

COMP20121 - Section 3 – p.147/307

Page 31: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• As before, we assume the language weare interested in is built of letters from analphabet Σ.

• We need to be able to denote in the textthat a memory cell might be empty.

COMP20121 - Section 3 – p.147/307

Page 32: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• As before, we assume the language weare interested in is built of letters from analphabet Σ.

• We need to be able to denote in the textthat a memory cell might be empty.

• For that we use the symbol .

COMP20121 - Section 3 – p.147/307

Page 33: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• As before, we assume the language weare interested in is built of letters from analphabet Σ.

• We need to be able to denote in the textthat a memory cell might be empty.

• For that we use the symbol .

• Sometimes there are other symbols wewant to be able to write onto the tape.

COMP20121 - Section 3 – p.147/307

Page 34: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• Therefore we assume that there is analphabet T of tape symbols with theproperty that

• all symbols of Σ are contained in T and

COMP20121 - Section 3 – p.148/307

Page 35: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• Therefore we assume that there is analphabet T of tape symbols with theproperty that

• all symbols of Σ are contained in T and

• the symbol is contained in T .

COMP20121 - Section 3 – p.148/307

Page 36: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Alphabets

• Therefore we assume that there is analphabet T of tape symbols with theproperty 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

Page 37: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Transition function

Therefore the transition function will take• the current state from Q,

COMP20121 - Section 3 – p.149/307

Page 38: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 39: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-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

Page 40: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-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• a new state from Q,

COMP20121 - Section 3 – p.149/307

Page 41: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-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• a new state from Q,• a symbol to write onto the tape from T ,

COMP20121 - Section 3 – p.149/307

Page 42: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-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• 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

Page 43: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-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• 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

Page 44: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing machine

Definition 14 A Turing machine or TM overthe tape alphabet ∈ T ⊇ Σ consists of

• a finite set of states Q;

COMP20121 - Section 3 – p.150/307

Page 45: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing machine

Definition 14 A Turing machine or TM overthe tape alphabet ∈ T ⊇ Σ consists of

• a finite set of states Q;

• a start state q• ∈ Q;

COMP20121 - Section 3 – p.150/307

Page 46: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing machine

Definition 14 A Turing machine or TM overthe 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

Page 47: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Turing machine

Definition 14 A Turing machine or TM overthe 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 × Tto (Q × T × {L, R, N}) ∪ {stop}.

COMP20121 - Section 3 – p.150/307

Page 48: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turingmachine can

• manipulate the input string;

COMP20121 - Section 3 – p.151/307

Page 49: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turingmachine can

• manipulate the input string;

• process the input string several times;

COMP20121 - Section 3 – p.151/307

Page 50: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turingmachine can

• manipulate the input string;

• process the input string several times;

• write to a random-access memory.

COMP20121 - Section 3 – p.151/307

Page 51: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Comparison: TMs versus PDAs

Unlike a pushdown automaton, a Turingmachine can

• manipulate the input string;

• process the input string several times;

• write to a random-access memory.

Like a pushdown automaton, a Turingmachine may run forever (on some inputstrings).

COMP20121 - Section 3 – p.151/307

Page 52: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example

We typically give a Turing machine via itstransition table.

COMP20121 - Section 3 – p.152/307

Page 53: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example

We typically give a Turing machine via itstransition table.

For example:δ a b

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

1 stop stop stop

COMP20121 - Section 3 – p.152/307

Page 54: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example

We typically give a Turing machine via itstransition table.

For example:δ a b

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

1 stop stop stop

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

COMP20121 - Section 3 – p.152/307

Page 55: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Acceptance of a string by a TM.

Definition 15 We say that a string α

is accepted by a Turing machineif, 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 atthat time is an accepting state.

COMP20121 - Section 3 – p.153/307

Page 56: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 57: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–II

δ a b

0 (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

Page 58: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–II

δ a b

0 (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

Page 59: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–II

δ a b

0 (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

Page 60: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

Page 61: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–III

δ a b

0 (0, , R) (1, , R) stop

1 stop stop stop

Then the language accepted by the

machine is

COMP20121 - Section 3 – p.157/307

Page 62: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–III

δ a b

0 (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

Page 63: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Example–III

δ a b

0 (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

Page 64: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

A more sophisticated example

Consider the following Turing machine withonly accepting state 0.

δ a b

0 (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

Page 65: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

A more sophisticated example

Consider the following Turing machine withonly accepting state 0.

δ a b

0 (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

Page 66: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

A more sophisticated example

Consider the following Turing machine withonly accepting state 0.

δ a b

0 (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

Page 67: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 68: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 69: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 70: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 71: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 72: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 73: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 74: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 75: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 76: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 77: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 78: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 79: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 80: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 81: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 82: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 83: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 84: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 85: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 86: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 87: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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

Page 88: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine

δ a b

0 (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 themachine.

COMP20121 - Section 3 – p.159/307

Page 89: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Configurations

We use a configuration

x1x2 · · ·xiqxi+1 · · ·xn

to describe a situation where

COMP20121 - Section 3 – p.160/307

Page 90: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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 allcells to the left of x1 and to the right ofxn are blank;

COMP20121 - Section 3 – p.160/307

Page 91: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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 cellholding xi+1.

COMP20121 - Section 3 – p.160/307

Page 92: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Configurations

We use a configuration

x1x2 · · ·xiqxi+1 · · ·xn

to describe a situation where

Control unit

x2x1· · · · · ·· · ·xi xi+1 xn· · ·

State: q

COMP20121 - Section 3 – p.160/307

Page 93: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 94: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 95: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 96: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 97: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 98: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 99: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 100: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 101: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 102: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 103: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 104: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 105: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 106: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 107: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 108: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 109: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 110: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 111: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 112: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 113: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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

Page 114: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

Running a Turing machine–II

δ a b

0 (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)

0

. . .. . .

COMP20121 - Section 3 – p.161/307

Page 115: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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

of configurations the machine goes

through.

COMP20121 - Section 3 – p.161/307

Page 116: COMP20121, ‘power’ part: section 3petera/2121/Slides/lecture7.pdfTuring: The man Who was Alan Turing? 1936-38: Princeton University. Ph.D. Logic, algebra, number theory 1938-39:

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