0% found this document useful (0 votes)
0 views

CH9

This document covers Turing machines, their components, and their functions, including how to construct and trace them. It discusses the language hierarchy, acceptance criteria, and examples of Turing machines that accept specific languages. The chapter also addresses determinism, halting conditions, and Turing's thesis.

Uploaded by

辣台妹
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

CH9

This document covers Turing machines, their components, and their functions, including how to construct and trace them. It discusses the language hierarchy, acceptance criteria, and examples of Turing machines that accept specific languages. The chapter also addresses determinism, halting conditions, and Turing's thesis.

Uploaded by

辣台妹
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 118

Formal Languages and Automata

CH9 Turing Machines


Learning Objectives
At the conclusion of the chapter, the student will be able to:
Describe the components of a standard Turing machine
State whether an input string is accepted by a Turing machine
Construct a Turing machine to accept a specific language
Trace the operation of a Turing machine transducer given a
sample input string
Construct a Turing machine to compute a simple function
State Turing’s thesis and discuss the circumstantial evidence
supporting it

2
Outline

1 The Standard Turing Machine

2 Combining Turing Machines for Complicated Tasks

3 Turing’s Thesis

3
Turing Machines
•Developed by Alan Turing in 1936
•More than just recognizing languages
•Foundation for modern theory of computation

4
5
The Language Hierarchy

n n n ?
a b c ww ?

Context-Free Languages
n n R
a b ww
Regular Languages

a* a *b *
Languages accepted by
Turing Machines

n n n
a b c ww

Context-Free Languages
n n R
a b ww
Regular Languages

a* a *b *
7
A Turing Machine
Tape
...... ......

Read-Write head

Control Unit

8
The Tape
No boundaries -- infinite length

...... ......

Read-Write head

The head moves Left or Right

9
...... ......

Read-Write head

The head at each time step:

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right

10
Example:
Time 0
...... ......
a b a c

Time 1
...... ......
a b k c
1. Reads a
2. Writes k

3. Moves Left
11
Time 1
...... ......
a b k c

Time 2
...... ......
a f k c

1. Reads b
2. Writes f
3. Moves Right
12
The Input String

Input string Blank symbol

...... ......
  a b a c   

head

There is no special input/output device.


Head starts at the leftmost position
of the input string

13
Input string Blank symbol

...... ......
  a b a c   

head

Remark: the input string is never empty

14
Turing Machine:

Input Tape
alphabet alphabet
States

M = (Q, , ,  , q0 , , F )

Transition Final
function states

Initial blank
state
15
States & Transitions
Write
Read Move Left

q1 a, b, L q2

Move Right

a, b, R
q1 q2
16
Transition Function (program)

a, b, R
q1 q2

 (q1, a) = (q2 , b, R)

17
Transition Function

q1 c, d , L q2

 (q1, c) = (q2 , d , L)

18
Example:

Time 1

...... ......
  a b a c   

q1
current state

q1 a, b, R q2
19
Time 1
...... ......
  a b a c   

q1

Time 2
...... ......
  a b b c   

q2
q1
a, b, R q2
20
Example:
Time 1
...... ......
  a b a c   

q1

Time 2
...... ......
  a b b c   

q2
a, b, L
q1 q2
21
Example:
Time 1
...... ......
  a b a c   

q1

Time 2

  a b b c g  
...... ......

q2
, g, R
q1 q2
22
Determinism
Turing Machines are deterministic

Allowed Not Allowed


a, b, R q2 a, b, R q2

q1 q1
q3 q3
b, d , L a, d , L

No lambda transitions allowed


Transition Function Is Partial
Example:
...... ......
  a b a c   

q1

a, b, R q2 Allowed:

q1
b, d , L q3
24
Halting

The machine halts if there are


no possible transitions to follow
Example:

...... ......
  a b a c   

q1
No transition
a, b, R q2 for input symbol c
q1 No possible transition

q3 HALT!!!
b, d , L
26
Final States
q1 q2 Allowed

q1 q2 Not Allowed

• Final states have no outgoing transitions

• In a final state the machine halts

27
Acceptance
If machine halts
Accept Input
in a final state

If machine halts
in a non-final state
Reject Input or
If machine enters
an infinite loop

28
Turing Machine Example
A Turing machine that accepts the language:
aa *

a, a, R
 = {a, b}
, , L
q0 q1

29
Time 0   a a a  

q0

a, a, R

, , L
q0 q1

30
Time 1   a a a  

q0

a, a, R

, , L
q0 q1

31
Time 2   a a a  

q0

a, a, R

, , L
q0 q1

32
Time 3   a a a  

q0

a, a, R

, , L
q0 q1

33
Time 4   a a a  

q1

a, a, R
Halt & Accept

, , L
q0 q1

34
Rejection Example

Time 0   a b a  

q0

a, a, R

, , L
q0 q1

35
Time 1   a b a  

q0
No possible Transition
a, a, R Halt & Reject

, , L
q0 q1

36
Infinite Loop Example

b, b, L
a, a, R

, , L
q0 q1
Time 0   a b a  

q0

b, b, L
a, a, R

, , L
q0 q1

38
Time 1   a b a  

q0

b, b, L
a, a, R

, , L
q0 q1

39
Time 2   a b a  

q0

b, b, L
a, a, R

, , L
q0 q1

40
Time 2   a b a  
q0
Time 3   a b a  

Infinite loop
q0
Time 4   a b a  
q0
Time 5   a b a  
q0 41
Because of the infinite loop:

•The final state cannot be reached

•The machine never halts

•The input is not accepted

42
Example 9.7
n n
Turing machine for the language {a b }
 a a b b  
q0
q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
43
Time 0  a a b b  

q0

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
44
Time 1  x a b b  

q1

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
45
Time 2  x a b b  

q1

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
46
Time 3  x a y b  

q2

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
47
Time 4  x a y b  

q2

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
48
Time 5  x a y b  

q0

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
49
Time 6  x x y b  

q1

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
50
Time 7  x x y b  

q1

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
51
Time 8  x x y y  

q2

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
52
Time 9  x x y y  

q2

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
53
Time 10  x x y y  

q0

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
54
Time 11  x x y y  

q3

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
55
Time 12  x x y y  

q3

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
56
Time 13  x x y y  

q4
Halt & Accept

q4 y, y, R y, y, L
y, y, R a, a, R a, a, L
, , L
y, y, R a , x, R b, y, L
q3 q0 q1 q2
x, x, R
57
Observation:

If we modify the
n n
machine for the language {a b }

we can also construct


n n n
a machine for the language {a b c }

58
Configuration
  c a b a  

q1

Instantaneous description: ca q1 ba

59
Time 4 Time 5

 x a y b    x a y b  

q2 q0

A Move: q2 xayb ┝ x q0 ayb

60
Time 4 Time 5

 x a y b    x a y b  

q2 q0

Time 6 Time 7

 x x y b    x x y b  

q1 q1

q2 xayb ┝ x q0 ayb ┝
 xx q1 yb ┝
 xxy q1 b
61
q2 xayb ┝
 x q0 ayb ┝
 xx q1 yb ┝ xxy q1 b


Equivalent notation: q2 xayb ┝ xxy q1 b

Infinite loop (TM never halt):  
x1qx2 ┝
62
Initial configuration: q0 w
Input string
w

 a a b b  

q0

63
The Accepted Language
For any Turing Machine M


L( M ) = {w : q0 w ┝
 x1 q f x2 }

Initial state Final state

The sequence of configurations leading to a halt state


will be called a computation.
64
Standard Turing Machine

Main features of the standard Turing machine:

• Deterministic

• Infinite tape in both directions

• Tape is the input/output file

65
Computing Functions
with
Turing Machines
A function f (w) has:

Domain: D Result Region: S

f (w)
w D f ( w)  S

“Transducer”

67
A function may have many parameters:

Example: Addition function

f ( x, y ) = x + y

68
Integer Domain

Decimal: 5

Binary: 101

Unary: 11111

We prefer unary representation:

∵easier to manipulate with Turing machines


69
Definition:

A function f is computable (Turing Computable)


if there is a Turing Machine M such that:

Initial configuration Final configuration

 w   f (w) 

q0 initial state qf final state

For all w D Domain


70
In other words:
A function f is computable (Turing Computable)
if there is a Turing Machine M such that:


q0 w ┝M q f f ( w)

Initial Final
Configuration Configuration

For all w D Domain


71
Example 9.9
The function f ( x, y ) = x + y is computable

x, y are integers

Turing Machine:

Input string: x0 y unary

Output string: xy 0 unary

72
x y

Start
 1 1  1 0 1  1 

q0
initial state

The 0 is the delimiter that


separates the two numbers

73
x y

Start
 1 1  1 0 1  1 

q0 initial state

x+ y

Finish  1 1  1 1 0 
qf final state

74
The 0 helps when we use
the result for other operations

x+ y

Finish  1 1  1 1 0 
qf final state

75
Turing machine for function f ( x, y ) = x + y

1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
76
Execution Example: Time 0

x y
x = 11 (2)
 1 1 0 1 1 
y = 11 (2)
q0
Final Result

x+ y
 1 1 1 1 0 

q4
77
Time 0  1 1 0 1 1 

q0
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
78
Time 1  1 1 0 1 1 

q0
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
79
Time 2  1 1 0 1 1 

q0
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
80
Time 3  1 1 1 1 1 

q1
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
81
Time 4  1 1 1 1 1 

q1
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
82
Time 5  1 1 1 1 1 

q1
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
83
Time 6  1 1 1 1 1 

q2
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
84
Time 7  1 1 1 1 0 

q3
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
85
Time 8  1 1 1 1 0 

q3
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
86
Time 9  1 1 1 1 0 

q3
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
87
Time 10  1 1 1 1 0 

q3
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
88
Time 11  1 1 1 1 0 

q3
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
q4
89
Time 12  1 1 1 1 0 

q4
1, 1, R 1, 1, R 1, 1, L

q0
0, 1, R q , , L q 1, 0, L q3
1 2

, , R
HALT & accept q4
90
Example 9.10
The function f ( x) = 2 x is computable

x is integer

Turing Machine:

Input string: x unary

Output string: xx unary


91
x

Start  1 1  1 

q0 initial state

2x

Finish  1 1  1 1 1 
qf final state
92
Turing Machine Pseudocode for f ( x) = 2 x

• Replace every 1 with $

• Repeat:
• Find rightmost $, replace it with 1

• Go to right end, insert 1

Until no more $ remain

93
Turing Machine for f ( x) = 2 x

1, $, R 1, 1, L 1, 1, R

, , L $, 1, R q2
q0 q1
, , R
, 1, L
q3

94
Example
Start Finish

 1 1   1 1 1 1 
q0 q3 1, 1, R
1, $, R 1, 1, L

, , L $, 1, R q2
q0 q1
, , R
, 1, L How about f(x, y) = x*y?
q3

95
Example 9.11
1 if x y
The function f ( x, y ) =
is computable 0 if x y

96
Turing Machine for

1 if x y
f ( x, y ) =
0 if x y

Input: x0 y

Output: 1 or 0
97
Turing Machine Pseudocode:

• Repeat
Match a 1 from x with a 1 from y
Until all of x or y is matched
• If a 1 from x is not matched
erase tape, write 1 ( x  y)
else
erase tape, write 0 ( x  y)

98
Outline

1 The Standard Turing Machine

2 Combining Turing Machines for Complicated Tasks

3 Turing’s Thesis

99
Combining Turing
Machines
Block Diagram

Turing
input Machine output

101
Example 9.12: x + y if x  y
f ( x, y ) =
0 if x y

 
qC , 0 w( x)0w( y ) ┝
 q A, 0 w( x)0w( y ) If x ≧ y  q A, f w( x + y )0
q A, 0 w( x)0w( y ) ┝
 
qC , 0 w( x)0w( y ) ┝
 qE , 0 w( x)0w( y ) If x < y qE , 0 w( x)0 w( y ) ┝
 qE , f 0

102
Example 9.13

Consider the macroinstruction

if a then qj else qk,

δ(qi, a) = (qj0, a, R) for all qi ϵ Q


δ(qi, b) = (qk0, b, R) for all qi ϵ Q, and all b ϵ Г – {a}
δ(qj0, c) = (qj, c, L) for all c ϵ Г
δ(qk0, c) = (qk, c, L) for all c ϵ Г
103
Example 9.14

Design a Turing machine that multiplies two positive integers in unary notation

1. Repeat the following steps until x contains no more 1’s


Find a 1 in x and replace it with another symbol a
Replace the leftmost 0 by 0y
2. Replace all a’s with 1’s

104
105
f(n)=n(n+2) f(n)=n4

f(n)=2n f(n)=n!

How about 2𝑛! ?


106
High level description (algorithm)

L={WWRW}

107
Outline

1 The Standard Turing Machine

2 Combining Turing Machines for Complicated Tasks

3 Turing’s Thesis

108
Turing’s thesis:

Any computation carried out


by mechanical means
can be performed by a Turing Machine
(1930)

109
Computer Science Law:
A computation is mechanical
if and only if
it can be performed by a Turing Machine

There is no known model of computation


more powerful than Turing Machines

110
Definition of Algorithm:

An algorithm for function f (w)


is a
Turing Machine which computes f (w)

111
Algorithms are Turing Machines

When we say:
There exists an algorithm

We mean:
There exists a Turing Machine
that executes the algorithm

112
Turing Thesis

Anything that can be done on any existing digital computer can also be
done by a Turing machine

No one has yet been able to suggest a problem, solvable by what we


intuitively consider an algorithm, for which a Turing machine program
cannot be written

Alternative models have been proposed for mechanical computation,


but none of them is more powerful than the Turing machine model

113
Short Quiz

Construct Turing machines that will accept the following


languages

◦ L={anbncn: n≥0}
◦ Even-length binary palindromes
◦L={w∈{0,1}∗∣w=wR, ∣w∣ is even}

114
Practice 9.1-1
Construct a Turing machine that accepts the language L =L(aaaa∗b∗).
Solution: A solution that accepts the language L is
a, a, R b, b, R
口: blank symbol

a, a, R a, a, R a, a, R b, b, R
q0 q1 q2 q3 q4
口 ,口 , L
口 ,口 , L
q5
115
Practice 9.1-10
Construct a Turing machine to compute the function f(w)=wR.

116
W

Start 口 1 1  1 口

q0 initial state

WR W

Finish
口 1 1  口 口 口

qf final state
117
Practice 9.1-13(b) f(x, y)=x+2y (unary representation)

𝑤 𝑥 0𝑤 𝑦 → 𝑤 𝑥 𝑤 𝑦 𝑤(𝑦)

Try f(x, y)=2x+3y

118

You might also like