Automata and Formal Languages

Automata and Formal Languages - CM0081
Turing Machines
Andrés Sicard-Ramírez
Universidad EAFIT
Semester 2017-2
Turing Machines
Alan Mathison Turing
(1912 – 1954)
Automata and Formal Languages - CM0081. Turing Machines
2/43
Turing Machines (TM)
Unbounded tape divided into discrete squares which contain symbols
from a finite alphabet
Automata and Formal Languages - CM0081. Turing Machines
3/43
Turing Machines (TM)
Unbounded tape divided into discrete squares which contain symbols
from a finite alphabet
Read/Write head
Automata and Formal Languages - CM0081. Turing Machines
4/43
Turing Machines (TM)
Unbounded tape divided into discrete squares which contain symbols
from a finite alphabet
Read/Write head
Finite set of instructions (transition function)
Automata and Formal Languages - CM0081. Turing Machines
5/43
Turing Machines (TM)
Unbounded tape divided into discrete squares which contain symbols
from a finite alphabet
Read/Write head
Finite set of instructions (transition function)
Move of a TM (tape symbol under the head, current state): change
state, rewrite the symbol and move the head one square
Automata and Formal Languages - CM0081. Turing Machines
6/43
Turing Machines
A Turing machine is a 7-tuple 𝑀 = (𝑄, Ξ£, Ξ“, 𝛿, π‘ž0 , 𝐡, 𝐹 ) where
𝑄: A finite set of states
Ξ£: An alphabet of input symbols
Ξ“: An alphabet of tape symbols (Ξ£ βŠ† Ξ“)
𝛿 ∢ 𝑄 × Ξ“ β†’ 𝑄 × Ξ“ × π·: A transition (partial) function
where 𝐷 = {𝐿, 𝑅} is the set of moves
π‘ž0 ∈ 𝑄: A start state
𝐡: The blank symbol (𝐡 ∈ Ξ“, 𝐡 βˆ‰ Ξ£)
𝐹 βŠ† 𝑄: A set of final or accepting states
Automata and Formal Languages - CM0081. Turing Machines
7/43
Transition Diagrams for Turing Machines
Example
π‘Œ /π‘Œ β†’
0/0 β†’
start
π‘ž0
0/𝑋 β†’
π‘Œ /π‘Œ β†’
π‘Œ /π‘Œ β†’
π‘ž3
𝐡/𝐡 β†’
π‘ž1
π‘Œ /π‘Œ ←
0/0 ←
1/π‘Œ ←
π‘ž2
𝑋/𝑋 β†’
π‘ž4
where Ξ£ = {0, 1} and Ξ“ = {0, 1, 𝑋, π‘Œ , 𝐡}.
Automata and Formal Languages - CM0081. Turing Machines
8/43
Transition Tables for Turing Machines
Example
The machine of the previous example is given by
𝑀 = ({π‘ž0 , π‘ž1 , π‘ž2 .π‘ž3 , π‘ž4 }, {0, 1}, {0, 1, 𝑋, π‘Œ , 𝐡}, 𝛿, π‘ž0 , 𝐡, {π‘ž4 }) where 𝛿 is
given by
state
π‘ž0
π‘ž1
π‘ž2
π‘ž3
π‘ž4
0
(π‘ž1 , 𝑋, 𝑅)
(π‘ž1 , 0, 𝑅)
(π‘ž2 , 0, 𝐿)
β€”
β€”
1
β€”
(π‘ž2 , π‘Œ , 𝐿)
β€”
β€”
β€”
Automata and Formal Languages - CM0081. Turing Machines
𝑋
β€”
β€”
(π‘ž0 , 𝑋, 𝑅)
β€”
β€”
π‘Œ
(π‘ž3 , π‘Œ , 𝑅)
(π‘ž1 , π‘Œ , 𝑅)
(π‘ž2 , π‘Œ , 𝐿)
(π‘ž3 , π‘Œ , 𝑅)
β€”
𝐡
β€”
β€”
β€”
(π‘ž4 , 𝐡, 𝑅)
β€”
9/43
Quintuples for Turing Machines
Example
The machine of the previous example is given by
𝑀 = ({π‘ž0 , π‘ž1 , π‘ž2 .π‘ž3 , π‘ž4 }, {0, 1}, {0, 1, 𝑋, π‘Œ , 𝐡}, 𝛿, π‘ž0 , 𝐡, {π‘ž4 }), where 𝛿 is
given by
π‘ž0 , 0, 𝑋, 𝑅, π‘ž1
π‘ž0 , π‘Œ , π‘Œ , 𝑅, π‘ž3
π‘ž1 , 0, 0, 𝑅, π‘ž1
π‘ž1 , 1, π‘Œ , 𝐿, π‘ž2
π‘ž1 , π‘Œ , π‘Œ , 𝑅, π‘ž1
π‘ž2 , 0, 0, 𝐿, π‘ž2
π‘ž2 , 𝑋, 𝑋, 𝑅, π‘ž0
π‘ž2 , π‘Œ , π‘Œ , 𝐿, π‘ž2
π‘ž3 , π‘Œ , π‘Œ , 𝑅, π‘ž3
π‘ž3 , 𝐡, 𝐡, 𝑅, π‘ž4
Automata and Formal Languages - CM0081. Turing Machines
10/43
Instantaneous Descriptions for Turing Machines
Definition (Instantaneous descriptions)
An instantaneous description of a TM is a string
𝑋1 𝑋2 β‹― π‘‹π‘–βˆ’1 π‘žπ‘‹π‘– 𝑋𝑖+1 β‹― 𝑋𝑛
where
i) π‘ž is the state of the TM,
ii) the head is scanning the 𝑖-th symbol from the left and
iii) 𝑋1 𝑋2 β‹― 𝑋𝑛 is the portion of the tape between the leftmost and
rightmost non-blank.
Automata and Formal Languages - CM0081. Turing Machines
11/43
Instantaneous Descriptions for Turing Machines
Notation
⊒ : Move of the TM 𝑀 from an instantaneous descriptions to another.
𝑀
βˆ—
⊒ : Zero o more moves of the TM 𝑀 .
𝑀
Automata and Formal Languages - CM0081. Turing Machines
12/43
Instantaneous Descriptions for Turing Machines
Example
0 0 1
π‘ž0
𝑋 0 1
π‘ž1
π‘ž0 001 ⊒ π‘‹π‘ž1 01 ⊒ 𝑋0π‘ž2 1
𝑀
𝑀
βˆ—
π‘ž0 001 ⊒ 𝑋0π‘ž2 1
𝑀
𝑋 0 1
π‘ž2
Automata and Formal Languages - CM0081. Turing Machines
13/43
Recursively Enumerable Languages
Definition (Language accepted by a TM)
Let 𝑀 = (𝑄, Ξ£, Ξ“, 𝛿, π‘ž0 , 𝐡, 𝐹 ) be a TM. The language accepted by 𝑀 is
βˆ—
𝐿(𝑀 ) = {𝑀 ∈ Ξ£βˆ— ∣ π‘ž0 𝑀 ⊒ 𝛼𝑝𝛽},
𝑀
βˆ—
where 𝑝 ∈ 𝐹 and 𝛼, 𝛽 ∈ Ξ“ .
Automata and Formal Languages - CM0081. Turing Machines
14/43
Recursively Enumerable Languages
Definition (Language accepted by a TM)
Let 𝑀 = (𝑄, Ξ£, Ξ“, 𝛿, π‘ž0 , 𝐡, 𝐹 ) be a TM. The language accepted by 𝑀 is
βˆ—
𝐿(𝑀 ) = {𝑀 ∈ Ξ£βˆ— ∣ π‘ž0 𝑀 ⊒ 𝛼𝑝𝛽},
𝑀
βˆ—
where 𝑝 ∈ 𝐹 and 𝛼, 𝛽 ∈ Ξ“ .
Definition (Recursively enumerable language)
A language 𝐿 is recursively enumerable if exists a TM 𝑀 such 𝐿 = 𝐿(𝑀 ).
Automata and Formal Languages - CM0081. Turing Machines
15/43
Recursively Enumerable Languages
Example
Let 𝑀 be the machine described by the previous diagram. Then
𝐿(𝑀 ) = {0𝑛 1𝑛 ∣ 𝑛 β‰₯ 1}.
See the simulation in the course website.
Automata and Formal Languages - CM0081. Turing Machines
16/43
Recursive Languages
Convention
We assume that a TM halts if it accepts.
Automata and Formal Languages - CM0081. Turing Machines
17/43
Recursive Languages
Convention
We assume that a TM halts if it accepts.
What about if the TM does not accept?
Automata and Formal Languages - CM0081. Turing Machines
18/43
Recursive Languages
Convention
We assume that a TM halts if it accepts.
What about if the TM does not accept?
Definition (Recursively enumerable (RE) language)
A language 𝐿 is RE if exists a TM 𝑀 such that 𝐿 = 𝐿(𝑀 ).
Definition (Recursive language)
A language 𝐿 is recursive if exists a TM 𝑀 such that
i) 𝐿 = 𝐿(𝑀 ) and
ii) 𝑀 always halt (even if it does not accept)
Automata and Formal Languages - CM0081. Turing Machines
19/43
Turing Machine Computable Functions
Number-theoretical functions
{𝑓 ∣ 𝑓 ∢ β„•π‘˜ β†’ β„•}
Automata and Formal Languages - CM0081. Turing Machines
20/43
Turing Machine Computable Functions
Number-theoretical functions
{𝑓 ∣ 𝑓 ∢ β„•π‘˜ β†’ β„•}
Codification
βƒ—βƒ—βƒ—βƒ—
𝑛 = 0𝑛 = 0⏟
β‹―0
for 𝑛 ∈ β„•
𝑛 times
βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
(𝑛1 , 𝑛2 , … , π‘›π‘˜ ) = βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑛1 1βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑛2 1 β‹― 1βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
π‘›π‘˜
Automata and Formal Languages - CM0081. Turing Machines
for (𝑛1 , 𝑛2 , … , π‘›π‘˜ ) ∈ β„•π‘˜
21/43
Turing Machine Computable Functions
Definition (Turing machine computable function)
A function 𝑓 ∢ β„• β†’ β„• is Turing machine computable iff exists a machine
𝑀 = (𝑄, {0, 1}, Ξ“, 𝛿, π‘ž0 , 𝐡) (there are not accepting states) such that for
all 𝑛 ∈ β„•:
From the initial instantaneous description π‘ž βƒ—βƒ—βƒ—βƒ—
𝑛 the machine halts with βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(𝑛)
0
on its tape, surrounded by blanks.
Automata and Formal Languages - CM0081. Turing Machines
22/43
Turing Machine Computable Functions
Definition (Turing machine computable function)
A function 𝑓 ∢ β„• β†’ β„• is Turing machine computable iff exists a machine
𝑀 = (𝑄, {0, 1}, Ξ“, 𝛿, π‘ž0 , 𝐡) (there are not accepting states) such that for
all 𝑛 ∈ β„•:
From the initial instantaneous description π‘ž βƒ—βƒ—βƒ—βƒ—
𝑛 the machine halts with βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(𝑛)
0
on its tape, surrounded by blanks.
Remark: The definition extends to functions 𝑓 ∢ β„•π‘˜ β†’ β„•.
Automata and Formal Languages - CM0081. Turing Machines
23/43
Turing Machine Computable Functions
Example
The proper subtraction function is Turing machine computable.
π‘šβˆΈπ‘›={
π‘šβˆ’π‘›
0
if π‘š β‰₯ 𝑛,
otherwise.
Initial instantaneous description: π‘ž0 0π‘š 10𝑛
Final information on the tape: 0π‘šβˆΈπ‘›
See the simulation in the course homepage.
Automata and Formal Languages - CM0081. Turing Machines
24/43
Equivalence between Function Computation and Language
Recognition
Example (Hopcroft, Motwani and Ullman [2007], Exercise 8.2.4)
Define the graph of a function 𝑓 ∢ β„• β†’ β„• to be the set of all strings
of the form [βƒ—βƒ—π‘₯,
βƒ—βƒ— βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(π‘₯)].
Automata and Formal Languages - CM0081. Turing Machines
25/43
Equivalence between Function Computation and Language
Recognition
Example (Hopcroft, Motwani and Ullman [2007], Exercise 8.2.4)
Define the graph of a function 𝑓 ∢ β„• β†’ β„• to be the set of all strings
of the form [βƒ—βƒ—π‘₯,
βƒ—βƒ— βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(π‘₯)].
A Turing machine is said to compute the function 𝑓 ∢ β„• β†’ β„• if,
started with π‘₯
βƒ—βƒ—βƒ—βƒ— on its tape, it halts (in any state) with βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(π‘₯) on its tape.
Automata and Formal Languages - CM0081. Turing Machines
26/43
Equivalence between Function Computation and Language
Recognition
Example (Hopcroft, Motwani and Ullman [2007], Exercise 8.2.4)
Define the graph of a function 𝑓 ∢ β„• β†’ β„• to be the set of all strings
of the form [βƒ—βƒ—π‘₯,
βƒ—βƒ— βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(π‘₯)].
A Turing machine is said to compute the function 𝑓 ∢ β„• β†’ β„• if,
started with π‘₯
βƒ—βƒ—βƒ—βƒ— on its tape, it halts (in any state) with βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—βƒ—
𝑓(π‘₯) on its tape.
Answer the following, with informal, but clear constructions.
Automata and Formal Languages - CM0081. Turing Machines
27/43
Equivalence between Function Computation and Language
Recognition
Example (cont.)
1. Show how, given a TM that computes 𝑓, you can construct a TM that
accepts the graph of 𝑓 as a language.
Automata and Formal Languages - CM0081. Turing Machines
28/43
Equivalence between Function Computation and Language
Recognition
Example (cont.)
1. Show how, given a TM that computes 𝑓, you can construct a TM that
accepts the graph of 𝑓 as a language.
2. Show how, given a TM that accepts the graph of 𝑓, you can construct
a TM that computes 𝑓.
Automata and Formal Languages - CM0081. Turing Machines
29/43
Equivalence between Function Computation and Language
Recognition
Example (cont.)
1. Show how, given a TM that computes 𝑓, you can construct a TM that
accepts the graph of 𝑓 as a language.
2. Show how, given a TM that accepts the graph of 𝑓, you can construct
a TM that computes 𝑓.
3. A function is said to partial if it may be undefined for some arguments.
If we extend the ideas of this exercise to partial functions, then we do
not require that the TM computing 𝑓 halts if its input π‘₯ is one of the
natural numbers for which 𝑓(π‘₯) is not defined.
Automata and Formal Languages - CM0081. Turing Machines
30/43
Equivalence between Function Computation and Language
Recognition
Example (cont.)
1. Show how, given a TM that computes 𝑓, you can construct a TM that
accepts the graph of 𝑓 as a language.
2. Show how, given a TM that accepts the graph of 𝑓, you can construct
a TM that computes 𝑓.
3. A function is said to partial if it may be undefined for some arguments.
If we extend the ideas of this exercise to partial functions, then we do
not require that the TM computing 𝑓 halts if its input π‘₯ is one of the
natural numbers for which 𝑓(π‘₯) is not defined.
Do your constructions for parts (1) and (2) work if the function 𝑓 is
partial? If not, explain how you could modify the constructions to make
it work.
Automata and Formal Languages - CM0081. Turing Machines
31/43
Restrictions to the Turing Machines
Automata and Formal Languages - CM0081. Turing Machines
32/43
Restrictions to the Turing Machines
Restrictions
Turing machines with semi-unbounded tapes
Automata and Formal Languages - CM0081. Turing Machines
33/43
Restrictions to the Turing Machines
Restrictions
Turing machines with semi-unbounded tapes
Multi-stack machines
Automata and Formal Languages - CM0081. Turing Machines
34/43
Restrictions to the Turing Machines
Restrictions
Turing machines with semi-unbounded tapes
Multi-stack machines
Theorem
The previous restrictions are equivalents to the Turing machines.
Automata and Formal Languages - CM0081. Turing Machines
35/43
Extensions to the Turing Machines
Automata and Formal Languages - CM0081. Turing Machines
36/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Automata and Formal Languages - CM0081. Turing Machines
37/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Mutil-dimensional tape Turing machines
Automata and Formal Languages - CM0081. Turing Machines
38/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Mutil-dimensional tape Turing machines
Multi-head Turing machines
Automata and Formal Languages - CM0081. Turing Machines
39/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Mutil-dimensional tape Turing machines
Multi-head Turing machines
Non-deterministic Turing machines
Automata and Formal Languages - CM0081. Turing Machines
40/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Mutil-dimensional tape Turing machines
Multi-head Turing machines
Non-deterministic Turing machines
Subroutines
Automata and Formal Languages - CM0081. Turing Machines
41/43
Extensions to the Turing Machines
Extensions
Multi-tape Turing machines
Mutil-dimensional tape Turing machines
Multi-head Turing machines
Non-deterministic Turing machines
Subroutines
Theorem
The previous extensions are equivalents to the Turing machines.
Automata and Formal Languages - CM0081. Turing Machines
42/43
References
Hopcroft, J. E., Motwani, R. and Ullman, J. D. (2007). Introduction to Automata
theory, Languages, and Computation. 3rd ed. Pearson Education.
Automata and Formal Languages - CM0081. Turing Machines
43/43