You are on page 1of 32

CHNG 3

L thuyt tnh ton

M HNH M
MY TURING

(Theory of Computation)

(Turing Machines Model)

PGS.TS. Phan Huy Kh


Khnh
phkhanh@dut.udn.vn,
phkhanh@dut.udn.vn, khanhph29@gmail.com

Chng 3

Alan Mathison Turing (23/06/1912 07/06/1954)


07/06/1954)
nh
nh to
ton h
hc,logic h
hc v mt m h
hc ng
ngi Anh
th
thng
c xem l
l cha
ca ng
ngnh Khoa h
hc M
My t
tnh
2/189

The Chomsky
Chomskys Language Hierarchy

Handicapped machines
DFA

Languages accepted by
Turing Machines

2-way DFA has equivalent power

Context-Sensitive Languages
anbncn ?
ww ?

Tape is read-only
Tape length is a constant
PDA

2-way PDA has a little more power (can accept { ww | w* }


Tape is read-only, but stack is writable
Stack has only LIFO (last-in, first-out) access
Tape length is constant, but stack is not bounded

Regular Languages

a * a *b*

DFA

(Push-Down Deterministic Finite Automaton) limitations

Tape head moves only one direction

Context-Free Languages
a n b n wwR

PDA

(Deterministic Finite Automaton) limitations

Tape head moves only one direction

What

about:

Writable, 2-way tape?


Random-access stack?

3/189

4/189

Introduction to Turing Machines (TM)


TM)

Computability
Computible

(there is an algorithm)

TM:

a formal model of a (digital) computer


running a particular program

Equivalence of DFAs

The

String membership in a regular language

formalisms equivalent :

Random Access Machines

Uncomputible

Partial recursive functions (Kleene, 1952)

Equivalence of CFGs

-calculus (Church, 1936)

Emptiness of the complement of a CFL


(emptiness of CFL is computible)

Post systems (Post, 1943)


etc...

Whether a C program ever terminates

these were preceded by the work of Kurt Godel, 1931,


which in his incompleteness theorem showed that there was no
way for a computer to answer all mathematical problems

All

How to prove it?

5/189

L thuyt tnh ton -- Ch.3 - My Turing

TM is the invention of Alan Turing, 1936

Other

Determining valid executions of a PDA

6/189

M t
t tng qu
qut m
my Turing
Input string

Blank symbol

Tape

...

A Turing Machine

b a c

...

Read-Write head

Mt bng v h
hn c
c hai ph
pha tr
tri v
v ph
phi

Mt u c-ghi c hay ghi ln bng,


bng, theo hai chi
chiu

Mt b nh
nh ph
ph hu h
hn x
xc
nh tr
trng th
thi

Mt cu v
vo
c
t trn bng

Mt chng tr
trnh l
lm ho
hot
ng m
my Turing
7/189

8/189

M t
t chi ti
tit c
cc th
thnh ph
phn TM
Bng

M t
t chi ti
tit c
cc th
thnh ph
phn (2)

l
lm vi
vic :

Mt

c chia th
thnh c
cc lin ti
tip

b
b nh
nh ph
ph hu h
hn :

Ti
Tip c
cn
c n
ni dung t
ti m
mi th
thi i
im

Mi ch
cha m
mt k t
t no
a S
S c
c ch
cha k t
t tr
trng (blank symbol),, ho
hoc #

C th
th thay
i
c n
ni dung

Ph
t gi
gia t nh
nht hai k t
t #
Phn cu c
c ch (usable part) wS*
Ng
Ngi ta vi
vit #w#

Mi ph
phn t
t ca b
b nh
nh ph
ph xc
nh m
mt tr
trng th
thi

B nh
ngha
nh ph
ph
c li
lit k l
lc
nh ngh

cghi :

Chng

c hay ghi (l
(lm thay
i) n
ni dung t
tng c
ca bng

tr
trnh :

Tp h
hp h
hu h
hn c
cc quy t
tc

Di chuy
chuyn m
mt v
v tr
tr qua ph
phi, ho
hoc tr
tri, tng ng v
vi m
mt

Lm thay
i n
ni dung trn bng v
v ni dung b
b nh
nh ph
ph

Ti m
ch duy nh
nht m
mt
c
c, ho
hoc
c ghi
mi th
thi i
im, ch

9/189

10/189

A Turing Machine
Input tape

The Tape

Input String w *

...

...

...

No boundaries -- infinite length

...

Read-Write head
The head moves Left or Right

Read-Write head
Control Unit / Transition Diagram

The head at each time step:


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

L thuyt tnh ton -- Ch.3 - My Turing

12/189

Example Moves Left :

Example Moves Right :

Time 0

...

a b

...

...

...

...

Time 1

...

b k

c
1. Reads

Time 1

b k

...

...

Time 2

1. Reads
2. Writes

2. Writes

3. Moves Right

3. Moves Left
13/189

14/189

The Input String


Input string
...

a b a c

States & Transitions

Write

Read

Blank symbol
...

q1

head

Move Left

a b, L

q2
Move Right

Head starts at the leftmost position


of the input string

Remark: the input string is never empty

q1

a b, R

q2

15/189

16/189

Example Moves Right :


Time 1

...

a b aa c
current state

...

q1

...

Time 1

...

a b a c
current state

q1

Time 2

a b bb c
a b, R

Example Moves Left :

...

...

q2
q1

q2
17/189

L thuyt tnh ton -- Ch.3 - My Turing

...

...

q1

Time 2

a b bb c

a b, L

q2

q2
18/189

Example:

Determinism (n/ti
n/t
n/ti
n/tt
nh)

Time 1

...

a b a c
current state
Time 2

...

Mi k t c xong ch tng ng vi mt dch chuyn duy nht

a b, R
...

q2

b d,L q
3

q1

c e,L

q2

g, R

Not Allowed

Allowed

q1

a b b c g

q1

Turing Machines are deterministic :

...

q2

a b, R

q2

a d, L

q3

q1

q1

No epsilon transitions allowed


19/189

20/189

Partial Transition Function

Halting

Example:
...

a b a c

...
The machine halts if there are
no possible transitions to follow

q1
a b, R

q2

Allowed:

q1
b d, L

No transition
for input symbol c

q3

21/189

22/189

Example:
...

Final States

a b a c

...

q1
a b, R

q2

b d, L

q3

q1

No possible transition
HALT!!!

q2

Allowed

q1

q2

Not Allowed

Final states have no outgoing transitions


In a final state the machine halts

23/189

L thuyt tnh ton -- Ch.3 - My Turing

q1

24/189

Acceptance

Turing Machine Example (1)

Accept Input

If machine halts
in a final state

A Turing machine that accepts the language:

(This Turing machine mimic a DFA)

Reject Input

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

aa* = a+

a a, R
q0

, L

q1

25/189

Turing Machine Example (2)


Time 0

26/189

Turing Machine Example (3)


Time 2

a a a

a a a

q0
Time 1

a a a

a a, R

q0

q0

, L

a a a

Time 3

q0

a,
a, R
aa

q1

q0

q0

, L

q1

27/189

28/189

Rejection Example (1)

Turing Machine Example (4)


Time 4

Time 0

a a a

a b a
q0

q1
Halt & Accept

a a, R
q0

, L

q0

q1
29/189

L thuyt tnh ton -- Ch.3 - My Turing

a a, R

, L

q1
30/189

Rejection Example (2)

Infinite Loop Example (1)


A Turing machine
for language aa * +b( a + b) *

a b a

Time 1

q0
No possible Transition

a a, R
q0

Halt & Reject

, L

b b, L
a a, R
q0

q1

, L

q1

31/189

32/189

Infinite Loop Example (2)

Infinite Loop Example (3)

a b a

Time 0

a b a

Time 1

q0

q0

b b, L
a a, R
q0

b b, L
a a, R

, L

q0

q1

, L

q1

33/189

34/189

Infinite Loop Example (4)

Infinite Loop Example (5)


Time 2

a b a

Time 2

b b, L
a a, R
q0

q0

q0

, L

Time 3

q0

Time 4

a
q0

q1

Time 5
35/189

L thuyt tnh ton -- Ch.3 - My Turing

q0

36/189

Infinite Loop Result

Another TM Example
T = <, Q, P>
Mt cch khc m t ngn gn TM
= {1, #}, hoc = {1} Nu khng mun ch k t trng ca bng
Q = {q1, q2, q3}
P = { q1, 1 1, R, q2,
c mt s chn s 1, v li q1
q2, 1 1, R, q1,
1|1, R
q1, # #, L, q3,
q3, 1 1, L, q3,
2
1
1|1, R
q3, 1 1, R, q3,
q3, 1 #, R, q1 }
1|#, R
#|#, L

Because of the infinite loop:


The final state cannot be reached

The machine never halts


The input is not accepted

q3

1|1, R
Bi
Bitp
tp::M
Mt
thot
hotng
ng
on
onnhn
nhncu
cu111111
111111??

Tha nhn cu c s chn s 1

37/189

TM for the language anbn (1)

1|1, L

38/189

TM for the language anbn (2)

a a b b

Time 0

q0

q4

y y, R
q3

, L

y y, R

q0

y y, R
a a, R

a x, R

q1

y y, L
a a, L

b y, L

x x, R

q2

X, Y

q3

, L

y y, R

q0

q3

, L

y y, R

q0

b y, L

x x, R

q2
40/189

x a b b

Time 2

q1
y y, R

q1

y y, L
a a, L

TM for the language anbn (4)

x a b b

q4

y y, R
a a, R

a x, R

39/189

TM for the language anbn (3)


Time 1

q4

y y, R

q1

y y, R
a a, R

a x, R

q1

y y, L
a a, L

b y, L

x x, R

L thuyt tnh ton -- Ch.3 - My Turing

q2
41/189

y y, R
q3

q4
, L

y y, R

q0

y y, R
a a, R

a x, R

q1

y y, L
a a, L

b y, L

x x, R

q2
42/189

TM for the language anbn (5)

TM for the language anbn (6)

x a y b

Time 3

x a y b

Time 4

q2

q3

y y, R
a a, R

q4

y y, R

, L

y y, R

q0

q2

a x, R

q1

y y, L
a a, L

b y, L

x x, R

q2

q3

, L

y y, R

q0

q3

, L

y y, R

q0

y y, R
a a, R
q1

y y, L
a a, L

b y, L

q2

q4

y y, R
q3

, L

y y, R

q0

y y, R

q0

q1

q2
46/189

x x y y

Time 8

q2

y y, R
a a, R

a x, R

b y, L

x x, R

q1

q3

q1

y y, L
a a, L

TM for the language anbn (10)

x x y b

, L

y y, R
a a, R

a x, R

45/189

TM for the language anbn (9)

y y, R

44/189

q1

a x, R

q4

q2

x x y b

Time 6

x x, R

Time 7

b y, L

TM for the language anbn (8)

x a y b

q4

q1

y y, L
a a, L

x x, R

q0
y y, R

y y, R
a a, R

a x, R

43/189

TM for the language anbn (7)


Time 5

q4

y y, R

y y, L
a a, L

b y, L

x x, R

L thuyt tnh ton -- Ch.3 - My Turing

q2
47/189

y y, R
q3

q4
, L

y y, R

q0

y y, R
a a, R

a x, R

q1

y y, L
a a, L

b y, L

x x, R

q2
48/189

TM for the language anbn (11)

TM for the language anbn (12)

x x y y

Time 9

x x y y

Time 10

q2

q4

y y, R
q3

, L

y y, R

q0

q0

y y, R
a a, R

a x, R

q1

y y, L
a a, L

b y, L

x x, R

q2

q3

, L

y y, R

q0

q1

q3

, L

y y, R

q0

q1

x x y y

Time 12

y y, L
a a, L

b y, L

x x, R

q2
51/189

x x y y

Halt & Accept

q4

q4

y y, R
a a, R

y y, R
q3

, L

y y, R

q0

a x, R

q1

y y, R
q3

q4
, L

y y, R

q0

a x, R

q1

y y, L
a a, L

x x, R

L thuyt tnh ton -- Ch.3 - My Turing

b y, L

x x, R

If we modify the TM
for the Context-Free Language

b y, L

y y, L
a a, L

y y, R
a a, R

q2
52/189

Observation:

TM for the language anbn (15)


Time 13

50/189

q3

y y, R
a a, R

a x, R

q2

TM for the language anbn (14)

x x y y

q4

b y, L

x x, R

q3

y y, R

y y, L
a a, L

y y, R
a a, R

a x, R

49/189

TM for the language anbn (13)


Time 11

q4

y y, R

{a b }

we can easily construct a TM


n n n
for the Context-Sensitive Language { a b c }

q2
53/189

54/189

Algorithm for Accepting anbncn, n1

TM Accepting anbncn, n1
a/a, R ; y/y, R
a/x, R

b/b, R ; z/z, R

b/y, R

q0

q1

z/z, L ; b/b, L
y/y, L ; a/a, L

c/z, L
q2

q3

x/x, R
y/y, R
z/z, R

#/#, L

q4
y/y, R

q5

Idea:
Idea: Finding
Finding matching
matching
a,b,c
a,b,c and
and replacing
replacing by
by x,y,z
x,y,z
q6

accepting matched x,y,z

z/z, R

Algorithm
input abc:
q0abc xq1bc xyq2c xq3yz q3xyz xq0yz xyq4z xyzq5B xyzBq6B
input a2b2c2:
q0 a2b2c2 xaq1b2c2 xayq2bc2 xaybq2c2 xayq3bzc xaq3ybzc
xq3aybzc q3xaybzc xq0aybzc xxq1ybzc xxyyq2zc xxyyq3zz
xq3xyyzz xxq0yyzz xxyyq4zz xxyyzzq5B xxyyzzBq6B
55/189

Begin
While Cha g
gp x
x Do
Gp a, ghi x
x ; Do qua R
R While Cha g
gp b
b Od
Gp b, ghi y
y ; Do qua R
R While Cha g
gp c
c Od
Gp c, ghi z
z ; Do qua L
L While Cha g
gp x
x Od
Qua R
R
Od
Do Qua R
R While Gp y
y Od
b/b, R, z/z, R z/z, L, b/b, L
a/a, R, y/y, R
y/y, L, a/a, L
Do Qua R
R While Gp z
z Od
a/x, R
b/y, R
c/z, L
If
Gp #
#
q0
q1
q2
q3
Then Qua L, Yes
Yes
x/x, R
No
Else
No
y/y, R
Fi
z/z, R

End

q4

#/#, L
q5

y/y, R

q6

56/189

z/z, R

Transition Function
A Move to right:

Formal Definitions
for
Turing Machines

q1

a b, R

q2

(q1, a ) = (q2 , b, R)
A Move to left:

q1

c d, L

q2

(q1, c) = (q2 , d , L)
58/189

Turing Machine:

States

Input
alphabet

Configuration
Tape
alphabet

c a b a

q1

M = (Q, , , , q0 , , F )

Instantaneous description:
Transition
function

Initial
state

Set of
Final states

ca q1 ba

blank
59/189

L thuyt tnh ton -- Ch.3 - My Turing

60/189

10

Transition
Time i

Transition process
Time i+1

x a y b

x a y b

q2

q0

A Move:

Time 1
x a y b

Time 2
x a y b

q2

q0

Time 3
x x y b

q2 xayb x q0 ayb

Time 4
x x y b

q1

q1

q2 xayb

x q0

ayb

xx q1

yb

xxy q1 b

61/189

62/189

Transition process

Notation

q2 xayb x q0 ayb xx q1 yb xxy q1 b

Input string

Equivalent notation:

q2 xayb

q0 w

Initial configuration:

a a b b

xxy q1 b

q0
63/189

TM computes palindromes

The Accepted Language

L( M)

| q0

nh du con a
mt tri nht

x1 q f x2 }

Initial state

q3

#|#, R

#|#, R

Vt qua tri
q4

Gp # qua phi
b|#, L

q5

qf F

Odd palindrome

a|#, L

b|#, R

Final state

#|#, L

q6

a|a, L
b|b, L

q7

#|#, R

Odd palindrome

a|a, R
b|b, R

L(M) is the Language Accepted by TM M

#|#, R

Even palindrome

65/189

L thuyt tnh ton -- Ch.3 - My Turing

# | #, L

q2

a|#, R
q1

nh du con a
mt phi nht

a|a, R
b|b, R Gp # li li

Vt qua phi

For any Turing Machine (TM) M:

={w

64/189

Ex1: w=abbbba?
Ex2: Draw M: L(M)=w#w for = {a, b, c} ?

66/189

11

Definitions

Standard Turing Machine


The machine we described is the standard:

The

languages accepted by TM
are called Recursively Enumerable (lit k quy)
Recursion is related to recursion in programs
Enumerable means there is some TM that can enumerate the strings in the
language

language is Recursive if it is accepted by some TM


that halts on all inputs

Deterministic
Infinite tape in both directions

We'll

usually assume that


TM halt if they enter a final state

Tape is the input/output file (online)

67/189

68/189

Notation

f ( w)

A function
Domain:

Computing Functions
with
Turing Machines

w D

has:

Result Region:

f (w)

f ( w) R

f can be TotaL or Partial Function


70/189

Data representation
Integer Domain
A function may have many parameters
The number of parameters is called arity
Example:

Addition function

f ( x, y ) = x + y

Thp phn

Binary:

101

Nh phn

Unary:

11111

n phn

We prefer unary representation:

with 2-arity

easier to manipulate with TMs, first


71/189

L thuyt tnh ton -- Ch.3 - My Turing

Decimal:

72/189

12

In other words:

Definition:

f
A function
is computable if
there is a Turing Machine M such that:
Initial configuration

For all

q f final state

w D

q f f ( w)

f (w)

q0 initial state

q0 w

Final configuration

f
A function
is computable if
there is a Turing Machine M such that:

Initial
Configuration

Final
Configuration

For all

Domain

w D

Domain

73/189

74/189

Example
The function

Input representation

f ( x, y ) = x + y is computable

x, y

are integers

Start

1 1

1 0 1 L 1

initial state q0

Turing Machine:
Input string:

x0 y

unary

Output string:

xy 0

unary

The 0 is the delimiter that


separates the two numbers
75/189

76/189

Computing Function
y

x
Start

1 1

Computing Function

The 0 helps when we use


the result for other operations

1 0 1 L 1

q0 initial state

x+ y

x+ y
Finish

1 1

1 1 0

q f final state

L thuyt tnh ton -- Ch.3 - My Turing

Finish

1 1

1 1 0

q f final state
77/189

78/189

13

Execution Example (1)

Turing machine for function

f ( x, y ) = x + y
1 1, R

1 1, R

x = 11 (2)
y = 11 (2)

1 1, L
Time 0

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

x+ y

1 1 0 1 1

Draw TM for inc(x), dec(x), double(x), x*y?

q4

79/189

80/189

Execution Example (2)

Execution Example (3)

1 1 0 1 1

Time 1

1 1 0 1 1
q0

q0

1 1, R

1 1 1 1 0

q0

Exercice:

Time 0

Final Result

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

, R

q4

81/189

Execution Example (4)


Time 2

Execution Example (5)

1 1 0 1 1

Time 3

1 1 1 1 1

q0

1 1, R

82/189

q1

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

L thuyt tnh ton -- Ch.3 - My Turing

83/189

, R

q4

84/189

14

Execution Example (6)


Time 4

Execution Example (7)

1 1 1 1 1

Time 5

1 1 1 1 1

q1

q1

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

, R

q4

85/189

Execution Example (8)


Time 6

Execution Example (9)

1 1 1 1 1

Time 7

1 1 1 1 0

q2

1 1, R

1 1, R

q3

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

, R

q4

87/189

Execution Example (10)


Time 8

88/189

Execution Example (11)

1 1 1 1 0

Time 9

1 1 1 1 0

q3

1 1, R

86/189

q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

L thuyt tnh ton -- Ch.3 - My Turing

89/189

, R

q4

90/189

15

Execution Example (12)


Time 10

Execution Example (13)

1 1 1 1 0

Time 11

q3

1 1, R

1 1 1 1 0
q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R

q4

91/189

Execution Example (14)


Time 12

, R

q4

Another Example: f(x) = 2x


The function

1 1 1 1 0

f ( x) = 2 x

q4

1 1, R

1 1, R

1 1, L

HALT & accept

Another Example: f(x) = 2x

Output string:

1 1

q4

unary

xx

unary
94/189

Replace every 1 with $

TM Pseudocode for f(x) = 2x

(2)

A
A Tip!
Tip!

Repeat:
Find rightmost $, replace it with 1

2x
1 1

is integer

93/189

q0 initial state

Finish

is computable

, R

x
Start

(1)

Turing Machine:
Input string:

q0 0 1, R q1 , L q2 1 0, L q3

92/189

1 1 1

Go to right end, insert 1


Until no more $ remain

q f final state
95/189

L thuyt tnh ton -- Ch.3 - My Turing

96/189

16

Example TM for f(x) = 2x

TM compute succ(n)
Finish

Start

1 1 1 1

1 1

q0

q3

1 $, R

1 1, L

1 1, R

q 0 , L q1 $ 1, R
1.
1.Replace
Replaceevery
every11with
with$$
2.
2.Repeat:
Repeat:
Find
Findrightmost
rightmost$,
$,
replace
replaceititwith
with11
Go
to
Go toright
rightend,
end,insert
insert11
3.
3.Until
Untilno
nomore
more$$remain
remain

, R
q3

T = <, Q, P> ; = { 0, 1, # } ; Q = {q1, q2, q3}


P = { q1, 1 1, R, q1,
q2, 0 1, L, q3,
q1, 0 0, R, q1,
q2, 1 0 L, q2,
q1, # #, L, q2,
q2, # 1, L, q3 }
1|0, L
1|1, R

q2

0|1, L

q1

1, L

q3
#|1, L

97/189

0|0, R

#|1, R

Find a 1|1, R

X|X, L

X|X, R

q1

a|X, L

q0

0|1, R
#|#, L

98/189

Another Example
The function is
computable

1|0, L

if

x> y

if

x y

Turing Machine for

q3

x0 y

Input:

0|0, R

X|#, L

f ( x, y ) =

Increment 1

1|1, R

q2

Input string:
#aaaaaa#
Output string? #110###

Exercice:
Exercice:Draw
DrawTM
TM for
for Inverse?
Inverse?

Output:

or

99/189

100/189

TM move RWH to the right at nth = 2

Turing Machine Pseudocode:


Repeat

Assume that in the Input Tape, we have Input String w1$w2$$wk

Match a 1 from
Until all of

q2

0|0, R

An example: Unary to Binary Conversion

Erase X

#|#, L

or

x with a 1 from y
y

is matched

If a 1 from x is not matched


erase tape, write 1
else
erase tape, write 0

( x > y)
( x y)
101/189

L thuyt tnh ton -- Ch.3 - My Turing

wi , $

Draw a TM in order to move RWH to the right at w3:


P = { q1, x x, R, q1, vi x
q1, $ $, R, q2, vi $
q2, x x, R, q2, vi x
Tng
Di RWH
RWH v
v v
v tr
tr n,
n,
Tng qut
qut :: Di
q2, $ $, R, q3, vi y
vi
vi nn t
t trc
trc cu
cu vo
vo
q3, x x, L, q4, vi x }
n$w
$w22$$w
$$wkk
n$w11$w
x|x, R
x | x, R
x\
x\

q1

y | y, L

$ | $, R
$

q2

q3

x | x, L
x

q4
102/189

17

CopyG : G* (G*)2 or w w#w

TM move RWH one case to the right


# 0

##

0#

P = { q1, 0
q1, 1
q(0), 0
1#
q(0), 1
q(1), 0
q(1), 1
q(0), #
q(1), #
1 | 0, R Restore 0,
#
q(#), 0
to the right q(#), 1
}
0 | #, R

Or
# 1

##
0 | 0, R

Remember 0
0 | #, R
q1

q(0)

0 | 1, R

#, R, q(0),
#, R, q(1),
0, R, q(0),
0, R, q(1),
1, R, q(0),
1, R, q(1),
0, R, q(#),
1, R, q(#),
#, R, q(0),
#, R, q(1)

0 | 0, R

1 | a, R

Remember 1

b | b, R

a | 1, R
b | b, L
b | 0, R
b | b, L

0 | b, R
# | #, L

q(1)
# | 1, R

q3

q1

# | 1, R
1 | #, R

b | b, R
# | 0, L

q4

q5

q6

Restore 1

1 | 1, L
0 | 0, R

1 | 1, R

103/189

1 | 1, R

1 | 1, L

# | 1, L

q2

q#

1 | 0, R

0 | 0, L

1 | 1, R

w w#wRR?

0 | 0, L

104/189

Block Diagram

Combining Turing Machines


input

Turing
Machine

output

106/189

Example:

f ( x, y ) =

x + y if x > y

0
x, y

x, y

Comparer

if x y

Turings Thesis

Adder

x+ y

Eraser

x> y
x y

107/189

L thuyt tnh ton -- Ch.3 - My Turing

18

Computer Science Law:

Turings thesis*:
Any computation carried out
by mechanical means
can be performed by a Turing Machine
(1930)

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

Thesis:
Thesis: AA Accepted
Accepted Statement
Statement but
but not
not Demontration
Demontration
109/189

Definition of Algorithm:

110/189

Algorithms are Turing Machines

An algorithm for function f (w)


is a
Turing Machine which computes f (w)

When we say:
There exists an algorithm
We mean:
There exists a Turing Machine
that executes the algorithm

111/189

112/189

The Standard Model


Infinite Tape

aababbcac a

Variations
of the Turing Machine

Read-Write Head

(Left or Right)

Control Unit
Deterministic

114/189

L thuyt tnh ton -- Ch.3 - My Turing

19

Variations of the Standard Model

Variations of the Standard Model


The variations form different
Turing Machine Classes

Turing machines with:


1. Stay-Option
2. Semi-Infinite Tape
3. Off-Line
4. Multitape
5. Multidimensional
6. Nondeterministic

We want to prove:

(or Equivalence)

Each Class has the same

power

with the Standard Model


What is the Same Power of two classes?
115/189

116/189

Notion

Demonstration

Same Power of two classes means:

Simulation: a technique to prove same power

Both classes of Turing machines accept


the same languages

M1 of first class
there is a machine M 2 of second class

Simulate the machine of one class


with a machine of the other class

For any machine


such that:

L( M1 ) = L( M 2 )

And vice-versa

First Class
Original Machine

M1

Second Class
Simulation Machine

M2
M1

117/189

Correspondence of the
configurations

Correspondence of the
configurations

Configurations in the Original Machine


correspond to configurations
in the Simulation Machine
Original Machine:

Simulation Machine:

d 0 d1

d 0 d1 L

118/189

dn
d n
119/189

L thuyt tnh ton -- Ch.3 - My Turing

Final Configuration

Original Machine:

df

Simulation Machine:

d f

The Simulation Machine


and the Original Machine
accept the same language
120/189

20

Example:

Turing Machines with StayStay-Option


The head can stay in the same position

aababbcac a

Time 1

aababbcac a

q1
Time 2

Left, Right, Stay

b ab abb c ac a
L,R,S: moves

q2
121/189

Theorem:

q1 a b, S

q2

Proof of Part 1 :
Part 1: Stay-Option Machines
are at least as powerful as
Standard machines

Stay-Option Machines
have the same power with
Standard Turing machines

Proof: a Standard machine is also


a Stay-Option machine
(that never uses the S move)
123/189

Proof of Part 2 :

Stay-Option Machine

q1

a standard machine can simulate


a Stay-Option machine

125/189

L thuyt tnh ton -- Ch.3 - My Turing

124/189

Simulation for Left moves

Part 2: Standard Machines


are at least as powerful as
Stay-Option machines

Proof:

122/189

a b, L

q2

Simulation in Standard Machine

q1 a b, L

q2

Similar for Right moves

126/189

21

Example

Simulation for Stay


Stay-Option Machine

q1

a b, S

Stay-Option Machine:

q1 a b, S q2

q2

q1

q2

x x, R

For every symbol

baba

q2

Simulation in Standard Machine:


1

q3

aaba

x
127/189

Turing Machines with Multiple Track Tape

baba

baba

q3

q2

q1

a b a b
b a c d

track 1
track 2

q1

track 1
track 2

a c a b
b d c d

one symbol

track 1
track 2

q2
q1

(b, a ) (c, d ), L

q2

129/189

Turing Machines with SemiSemi-Infinite Tape

# a b a c

128/189

Turing Machines with Double Track Tape

Standard Machine--Multiple Track Tape

a b a b
b a c d

aaba

q1

Simulation in Standard Machine

a b, L

130/189

Standard SemiSemi-Infinite Tape

Standard Turing machines


simulate
Semi-infinite tape machines:

...

Trivial

131/189

L thuyt tnh ton -- Ch.3 - My Turing

132/189

22

SemiSemi-Infinite Tape Standard (1)

SemiSemi-Infinite Tape Standard (2)

Semi-infinite tape machines simulate


Standard Turing machines:
Standard machine
.........
.........

Standard machine

.........

.........

a b c d e
reference point

Semi-infinite tape machine with two tracks

Semi-infinite tape machine


.........

Right part # d e

Left part


# c b a

.........

133/189

134/189

SemiSemi-Infinite Tape Standard (3)

SemiSemi-Infinite Tape Standard (4)

Standard machine

Standard machine

q2

q1

Right part

q2L

q1L

q2R

q1R

Right part

q1R

Left part

q1L

SemiSemi-Infinite Tape Standard (5)

Standard machine

a b c d e

( x, a ) ( x, g ), L

q2R

q2L
136/189

SemiSemi-Infinite Tape Standard (5)

.........

Time 2
.........

Standard machine

g b c d e

q1

.........

q2
Semi-infinite tape machine

Semi-infinite tape machine


Right part # d e
Left part

(a, x) ( g , x), R

For all symbols

135/189

Time 1
.........

q2

Semi-infinite tape machine

Semi-infinite tape machine


Left part

a g, R

q1


c
a
b
#

.........

q1L

L thuyt tnh ton -- Ch.3 - My Turing

137/189

Right part # d e
Left part


g
c
b
#
q2L

.........

138/189

23

At the border:

Semi-infinite tape machine

Semi-infinite tape machine


Right part

Left part

q1R
q1L

(# , # ) (# , # ), R

(# , # ) (# , # ), R

Time 1
Right part # d e

# c b g

Left part

q1L

.........

q1L

q1R

Time 2
Right part # d e

# c b g

Left part

q1R

139/189

Theorem:

.........

140/189

The OffOff-Line Machine (M


(My v
vi bng t
tch r
ri)

Input File

a b c

Semi-infinite tape machines


have the same power with
Standard Turing machines

read-only
Control Unit
read-write

Tape

g d e
141/189

142/189

1. Copy input file to tape


Off-line machines simulate
Standard Turing Machines:

Standard machine

a b c

Off-line machine:
Off-line machine

1. Copy input file to tape

Input File

2. Continue computation as in
Standard Turing machine

a b c

143/189

L thuyt tnh ton -- Ch.3 - My Turing

Tape

a b c

144/189

24

2. Do computations as in Turing machine


Standard Turing machines simulate
Off-line machines:

Standard machine

a b c
q1
Off-line machine
Tape

Input File

a b c

a b c

Use a Standard machine


with four track tape to keep track
of the Off-line input file
and tape contents

q1
145/189

Reference point

Off-line Machine
Tape

Input File

e f g

a b c d

Four track tape -- Standard Machine

# a b
# 0 0
e f
0 1

c d
1 0
g
0

146/189

Input File
head position
Tape
head position
147/189

# a b
# 0 0
e f
0 1

Input File
head position
Tape
head position

c d
1 0
g
0

Repeat for each state transition:


Return to reference point
Find current input file symbol
Find current tape symbol
Make transition

148/189

Theorem:

Multitape TMs (1)


Control unit

Off-line Machines
have the same power with
Stansard Machines

Tape 1

a b c

Tape 2

e f g

Input

149/189

L thuyt tnh ton -- Ch.3 - My Turing

150/189

25

Multitape Standard

Multitape TMs (2)


Tape 1

Time 1

Tape 2

Multitape machines simulate


Standard Machines:

e f g
q1

a b c
q1
Time 2

a g c
q2

q1

Use just one tape

e d g
q2

(b, f ) ( g , d ), L, R

q2
151/189

152/189

Standard Multitape
Multitape Machine

Standard machines simulate


Multitape machines:

Tape 1

Tape 2

e f g h

a b c

Standard machine:
Standard machine with four track tape

Use a multi-track tape


A tape of the Multiple tape machine
corresponds to a pair of tracks

a
0
e
0

b
1
f
0

c
0
g h
1 0

Tape 1
head position
Tape 2
head position

153/189

Reference point

#
#
#
#

a
0
e
0

b
1
f
0

c
0
g h
1 0

154/189

Theorem:

Tape 1
head position
Tape 2
head position

Repeat for each state transition:


Return to reference point
Find current symbol in Tape 1
Find current symbol in Tape 2
Make transition

155/189

L thuyt tnh ton -- Ch.3 - My Turing

Multi-tape machines
have the same power with
Standard Turing Machines

156/189

26

L = {a nb n }

Same power doesnt imply same speed:


Language

Standard machine:

L = {a nb n }

Go back and forth

Acceptance Time
Standard machine

Two-tape machine

n2

times

Two-tape machine:

b n to tape 2
n
Leave a on tape 1

( n steps)

Compare tape 1 and tape 2

( n steps)

Copy

( n steps)

157/189

158/189

MultiDimensional Turing Machines


Two-dimensional tape

y
Multidimensional machines simulate
Standard machines:

c a

MOVES: L,R,U,D
U: up
D: down

x
Use one dimension
HEAD

Position: +2, -1
159/189

160/189

Two-dimensional machine

y
Standard machines simulate
Multidimensional machines:

c
a

Standard machine:
Use a two track tape

Standard Machine

Store symbols in track 1


Store coordinates in track 2
161/189

L thuyt tnh ton -- Ch.3 - My Turing

x
q1

c
symbols
a
b

1
1
2
1
#
#
#
#
coordinates
1
q1
162/189

27

Standard machine:

Theorem:

Repeat for each transition

MultiDimensional Machines
have the same power
with Standard Turing Machines

Update current symbol


Compute coordinates of next position
Go to new position

163/189

164/189

NonDeterministic Turing Machines

Nondeterministic choices

a b, L

q2

a b, L

a c, R
q3

Choice 1

b b c

Non Deterministic Choice


165/189

q2

Time 0

a b c

q1

q1
a c, R

q2

q3
Time 1

q1
Choice 2

c b c
q3

166/189

Notion
Input string w is accepted if
this a possible computation

q0 w

Initial configuration

NonDeterministic Machines simulate


Standard (deterministic) Machines:

x qf y
Final Configuration

Every deterministic machine


is also a nondeterministic machine

Final state
167/189

L thuyt tnh ton -- Ch.3 - My Turing

168/189

28

Non-Deterministic Choices
Computation 1

Deterministic machines simulate


NonDeterministic machines:

Computation 2

q1

q1

Keeps track of all possible computations

q4

q5

q4
q6

169/189

q3

q2

q3

q2

Deterministic machine:

q5
q6

q7

q7

170/189

Simulation
a b, L
Deterministic machine:

q2

NonDeterministic machine
Time 0

q1

Keeps track of all possible computations

a b c

a c, R

q3

q1

Deterministic machine

Stores computations in a
two-dimensional tape

#
#
#
#

# # #
a b c
q1
# # #

# #
#
#
#

Computation 1

171/189

172/189

NonDeterministic machine

a b, L

Time 1

q2

b b c

Choice 1

c b c
q3

Choice 2

q2

q1

a c, R

#
#
#
#

q3

Deterministic machine
# # # # # #
b b c #
Computation 1
q2
#
c b c #
Computation 2
q3
#
173/189

L thuyt tnh ton -- Ch.3 - My Turing

Repeat
Execute a step in each computation:
If there are two or more choices
in current computation:
1. Replicate configuration
2. Change the state in the replica

174/189

29

Remark:
The simulation
in the Deterministic machine
takes time exponential time compared
to the NonDeterministic machine

Theorem: NonDeterministic Machines


have the same power with
Deterministic machines

175/189

176/189

A limitation of Turing Machines:


Turing Machines are hardwired
they execute
only one program

A Universal Turing Machine

Real Computers are re-programmable


Solution: Universal Turing Machine
(My Turing vn nng, hay ph qut)
Attributes:
Reprogrammable machine
Simulates any other Turing Machine
178/189

Universal Turing Machine

Universal Turing Machine

Simulates any other Turing Machine M

Description of transitions of M

Tape 1
Description of M

Universal
Turing
Machine

Input of Universal Turing Machine:

Tape 2
Tape contents of M
Tape 3

Initial tape contents of M

State of M
179/189

L thuyt tnh ton -- Ch.3 - My Turing

Three tapes

180/189

30

Encoding in Tape 1

Encoding in Tape 1

Tape 1

Tape 1

Description of M

Description of M

We describe TM M as a string of symbols:

We encode

Alphabet Encoding

Symbols:
Encoding:

State Encoding

M as a string of symbols

11

111

1111

States:

q1

q2

q3

q4

Encoding:

11

111

1111

181/189

182/189

Encoding in Tape 1

Encoding in Tape 1

Tape 1

Tape 1

Description of M

Description of M

Head Move Encoding

Move:

Encoding:

11

Transition Encoding

Transition:

(q1, a) = (q2 , b, L)

Encoding:

1 0 1 0 11 0 11 0 1
Using 0 for Separator

183/189

184/189

Encoding in Tape 1

Universal Turing Machine

Tape 1

Tape

Description of M

Transitions:

(q1, a) = (q2 , b, L)

1 contents of Universal TM M:

encoding of the simulated machine


as a binary string of 0s and 1s

Machine Encoding

TM is described
with a binary string of 0s and 1s

(q2 , b) = (q3 , c, R)

Encoding:

1 0 1 0 11 0 11 0 1 00 11 0 1 10 111 0 111 0 11
Using 00 for Transition Separator

185/189

L thuyt tnh ton -- Ch.3 - My Turing

186/189

31

Question: How powerful is RAM?

Language of Turing Machines

Can

RAMs compute functions/languages that TMs


cannot?

The set of Turing machines forms a language,


therefore :

Can

RAMs compute functions/languages significantly


faster then TMs?

each string of the language


is the binary encoding of a TM

Theorem:

L = { 010100101, 00100100101111, 111010011110010101, }

TM 1,

TM 2,

A TM can simulate a RAM, provided that the elementary RAM


instructions can themselves be simulated by a TM

...

187/189

188/189

Proof
The idea is to use a multitape TM M
to perform simulation:
Tape

1:

keeps program
# and *, i.e.,

instructions vi in binary, numbered, and separated by


#0*v0#1*v1#10*v2##i*vi#

Tape

2: keeps data registers:

Tape

3: keeps program counter

Tape

4: keeps data address register

#0*r0#1*r1#10*r2##i*ri#

189/189

L thuyt tnh ton -- Ch.3 - My Turing

32

You might also like