0% found this document useful (0 votes)
6 views32 pages

Theory of Computation: ND Hung

Uploaded by

6522780384
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)
6 views32 pages

Theory of Computation: ND Hung

Uploaded by

6522780384
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/ 32

Theory of Computation

ND HUNG

Sirindhorn International Institute of Technology


[email protected]

October 10, 2021

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 1 / 26


1 Turing Machines (TM)

2 Combining TMs

3 Recursive languages

4 Recursive Functions

5 Recursively Enumerable Languages

6 Extensions of Turing Machines

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 2 / 26


Turing Machines (TM)

Turing Machine (TM)

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 3 / 26


Turing Machines (TM)

Turing Machine (TM)


#
I of states (finite
. .

the set
. .

the alphabet out of


Definition ↑/ It gets
infinite
A Turing machine is a 5-tuple M = (K , ⌃, , s, H) where t an

loop.
atsee
- -

K is a finite set of states, Lithentofhating


⌃ is an alphabet containing the blank symbol t and the left end
symbol ., but not containing the symbols ! and ,
s 2 K is the initial state,
H ✓ K is the set of halting states, inputstateinput
Occurrent syma
new symbol
, the A
transition operation
function, is a function from (K H) ⇥ ⌃ to
memory
K ⇥ (⌃ [ { , !}) such that
- - -start ofThe tape*
D
next
for all q 2 K H there exists p such that (q, .) = (p, !), and -

state for all q 2 K H, and a 2 ⌃ {.}, if (q, a) = (p, b) then b 6= .


It

D
never

onto
writes down
the memory
.
OnlyaHart anysnot A
ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 4 / 26
Turing Machines (TM)

Turing Machine (TM)

h : halting state

transition &1 J

"
D/
-
-
,
aa a a

O air . (80 , Danaa) I

↓ (g ,
Daaca) [D/)
↓ (gI , Dana) [a/W]

(00 DWaaa) [r/-)
,

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 5 / 26


Turing Machines (TM)

Turing Machine (TM)

a)

w/r
Do-

68 h
0
2
DI-

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 6 / 26


Turing Machines (TM)

Turing Machine (TM)


Example: A Turing machine for accepting start state
L = {! 2 {a, b}⇤ &
| |!| is even} is M = (K , ⌃, , s, H) where
K = {s, q0 , q1 , y , n}, H = {y, n}
D
↑ initial config
becap reject (S
⌃ = {a, b}
: (K H) ⇥ ⌃ ! K ⇥ (⌃ [ { , !})
,
D) A

cursor
input
q (q, ) M accepts aa: string
s t (q0 , !) ↓ &
.
Z

&
- (s, .taa) `M (q0 , taa) `M
q0 t (y, t) 24 - -

>
-
(q1 , taa) `M (q0 , taat) `M
q0 a (q1 , !)
M
1

(y , taat) sop/LT
q0 b
z
(q1 , !)
q1 t (n, t) M rejects a:
q1 a (q0 , !)
Z
(s, .ta) `M (q0 , ta) `M
q1 b (q0 , !) (q1 , tat) `M (n, tat)
2
STOP
/HALT
ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 7 / 26
Turing Machines (TM)

Turing Machine (TM) syntactic >


-
(G2 DWabac,
D
sugar =
(G ,
Dra , back

A configuration of a Turing machine M = (K , ⌃, , s, H) is a member


Acurrent
state
of (82 Draca WWL) , -

For eDra,
K ⇥ .⌃⇤ ⇥ (⌃⇤ ⇥ (⌃ {t}) [ {e})

Definition
-
empty strings
DLet (q1 , !1 a1 u1 ) and (q2 , !2 a2 u2 ) be configurations of M. Then
it. we can
ignore
(q1 , !1 a1 u1 ) `M (q2 , !2 a2 u2 )

if and only if for some b 2 ⌃ [ { , !}, (q1 , a1 ) = (q2 , b) and one of


the following cases holds 5 : symbol -
> replace the cell's etr.

D : more ptr to the LHS


1. b 2 ⌃, !1 = !2 , u1 = u2 and a2 = b
,

D - i m RHS

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 8 / 26


Turing Machines (TM)

Turing Machine (TM)

Definition
2. b = , !1 = !2 a2 , and either
a. u2 = a1 u1 , if a1 6= t or u1 6= e, or
b. u2 = e, if a1 = t and u1 = e
3. b =!, !2 = !1 a1 , and either
a. u1 = a2 u2
b. u1 = u2 = e and a2 = t

(p Dabc)
,
p ,
Dab

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 9 / 26


Turing Machines (TM)

Turing Machine (TM)

the machine returns a result .


result

A halted configuration is of the form (h, !1 a!2 ) with h 2 H.


E

A computation is a sequence of configurations C1 , C2 , . . . , Cn


such that C1 `M C2 `M · · · `M Cn . We say that the computation
has length n and C1 yields Cn .
M is said to halt on input ! iff (s, .t!) yields some halted
D configuration.
*

Dah Du
·

IS ,
,

be the
same

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 10 / 26


Combining TMs

Symbol writing machine


Ma tape
write's to the
RHS
. Me Me
For each symbol a 2 ⌃ [ { , !} {.}, Ma is a Turing machine
which writes the symbol a into the scanned tape square, i.e.
Ma = ({s, h}, ⌃, , s, {h}) where (s, b) = (h, a) for each
b 2 ⌃ {.}.
Notations: for short, we often write
a for Ma : write 'a' to the current cell
=

L for M : more pr to LHS .

R for M! : more ptr to RHS ,

-
Lt : Finds the first blank square to the left of the currently scanned
symbol (p Dw abcdWefg) +in (p X Wabed Lefg)
, ,

Rt : Finds the first blank square to the right of the currently scanned
symbol (p DWabedWefgWhij) thr
,

Exercises: Study Examples 4.1.5,>


4.1.6, 4.1.7, 4.1.8, 4.1.9, 4.1.10 in
-

textbook (p D WabedLefgWhij)
,

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 11 / 26


Combining TMs

The rules for Combining Machines


Suppose M1 = (K1 , ⌃, 1 , s1 , H1 ), M2 = (K2 , ⌃, 2 , s2 , H2 ) and
M3 = (K3 , ⌃, 3 , s3 , H3 )
① Let M work
,
D until it halfs,

- if clauses & Peek the curr · all .

③ If the all atm is


let Me work,
·
a
,

① If the all oth is


ob Let M, work
M = (K , ⌃, , s, H) where K = K1 [ K2 [ K3 , s = s1 , H = H2 [ H 3 . For
,

each 2 ⌃, q 2 K H, (q, ) is defined as follows


If qnon-halting
state
2 K1 H1 , then (q, ) = 1 (q, )

YAAD
-

If q 2 K2 H2 , then (q, ) = 2 (q, )


If q 2 K3 H3 , then (q, ) = 3 (q, )
Ifhalting
state of
q 2 H1 , then (q,Ma
-
) if = a; (q, ) = (s3 , )bif = b
) = (s2 , nd
a
ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 12 / 26
Recursive languages

Recursive languages
re

defined 81
.
Lang rec can be as a recursive
-
An initial configuration is of the form (s, .t!) recursive
algo ,

Definition
Given is a Turing machine M = (K , ⌃, , s, H) with H = {y, n}. Any
halting configuration whose state is y is said to be an accepting (y ) . -

configuration while a halting configuration whose state is n is said to


be a rejecting configuration. (n - ,

For an input ! 2 (⌃ {t, .})⇤ , we say that


M accepts ! if (s, .t!) yields an accepting configuration. t(y ,+
M rejects ! if (s, .t!) yields an rejecting configuration. (n - ]

2) M gets stuck in an O-loop ,


we won't get answer .

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 13 / 26


Recursive languages

Recursive languages do
ALT
-M
has .

M tell if it
*
Deciding : can

Definition
accepts/rejects an input string.
Let ⌃0 ✓ ⌃ {t, .} be an alphabet, called input alphabet. We say
that M decides a language L ✓ ⌃⇤0 if for any string ! 2 ⌃⇤0 ,
If ! 2 L then M accepts !
If ! 62 L (i.e. ! 2 ⌃⇤0 L) then M rejects !
A language L is called recursive if it is decided by some Turing
machine.
Note: if TM M decides a language L ✓ ⌃⇤0 , then M halts on any ! 2 ⌃⇤0 ,
but M is not required to halt on ! 2 ⌃⇤ ⌃⇤0 (see supplementary note
for further discussion)

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 14 / 26


Recursive languages

Recursive languages
Example: Show that L0 = {an bn | n 0} is recursive.
(s Dabb) in it config aabb
,. t dabb `d
.

. t dadb `d

a .tdadb `Lt
. t dadb `R
+ a b b
. t dadb `d
=>

-
. t dddb `R
b
. t dddb `R +
. t dddb `d
a
Sample run: *
~.taabb `
R
. t dddd `Lt + o of $
-. t aabb `d .tdddd `R *
. t dabb `R . t dddd `⇤R -
Y. t dabb `R D . t ddddt `y
D . t ddddt

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 15 / 26


Recursive languages

Recursive languages

Example: Show that L1 = {an bn c n | n 0} is recursive.

- -

oo
Dr aabbxx

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 16 / 26


Recursive languages

Recursive languages

Example: Any regular language is recursive.


Let M = (K , ⌃, , s, F ) be a DFA. We can build a TM
M 0 = (K [ {y, n}, ⌃0 , 0 , s0 , {y , n}) that decides L(M) as follows
⌃0 = ⌃ [ {., t} a

0 :K ⇥ ⌃0 ! (K [ {y , n}) ⇥ (⌃0 [{ , !}) where -


>
&
(s0 , t) = (s, !)
P q
0
(p, a) = ( (p, a), !) for p 2 K , a 2 ⌃
(p, t) = (y, t) for p 2 F G(p a)
0
=
(p, t) = (n, t) for p 62 F
0 ,

(g -)

w
=
,

-
>
scan through
- make state trans .

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 17 / 26


Recursive Functions

Recursive Functions f(w,, W, Wa


I ...
.,
. .

Modern comp
:
We treat math &1 as

Definition tape manipulation .

M
Let M = (K , ⌃, , s, {h}), ⌃0 ✓ (⌃ {t, .} and ! 2 ⌃⇤0 . If

(s, .t!) `⇤M (h, .tu)

then u is called the output of M on input ! and denoted by M(!). We


say that
1. M computes function f : ⌃⇤0 ! ⌃⇤0 if for any ! 2 ⌃⇤0 , M(!) = f (!).
2. M computes function f : Nk ! N (k 1) if for all binary numbers
!1 , . . . , !k , M(!1 ; . . . ; !k ) = f (!1 , . . . , !k ) where f (!1 , . . . , !k ) is
also in binary representation.
A function f is recursive if there is a Turing machine computing f .
X / v U
+,
-

, , , , , ...

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 18 / 26


Recursive Functions

Recursive Functions
Example: Show that succ(n) = n + 1 and d(n) = 2n are recursive
functions. succ(101) 110 =

0
= 1
D 0
R⊔ L 1 L⊔
L
D ↑

Me Sa
1 S! L ⊔
Revised

tru
I
DLI01
the shift-right machine
-

*
+ DW/10
ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 19 / 26
Recursively Enumerable Languages

Recursively Enumerable Languages


definite of y/n yet
.
~
answer

Definition to beek the current state


have

Let M = (K , ⌃, , s, H), ⌃0 ✓ (⌃ {t, .} and L ✓ ⌃⇤0 . We say that M


semidecides L if for any string ! 2 ⌃⇤0 :

! 2 L iff M halts on input !

A language L is called recursively enumerable if it is semidecided by


some Turing machine.
T o
Lang rec . can be explained/tenbor
Theorem: algo mud
gives yu by a recursive


answer ,

If a language is recursive then it is also recursively enumerable.


If a language is recursive then its complement is also recursive.
L= Carba/n > on / I
ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 20 / 26
Extensions of Turing Machines

There are several important extensions of Turing machines. However,


all these extensions of TM can be simulated by the standard model.
1 Several tapes instead of one
2 Random access memory
-addr >
- data
(no more wait)
-

3 Nondeterministism : transition f -
> tranation rel1
We focus on the multi-tape extension.

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 21 / 26


Extensions of Turing Machines

Multi-tape Turing Machines

A k-tape Turing machine consists of a finite control together with k


infinite tapes. Each tape is scanned by a read/write head. The
machine can in one step sense the symbols scanned by all its heads
and then depending on those symbols and it s current state, rewrite
some of those scanned squares or move some of the heads to the left
or right.

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 22 / 26


Extensions of Turing Machines

Multi-tape Turing Machines ouis


input
Gaddn . tapes

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 23 / 26


Extensions of Turing Machines

Multi-tape Turing Machines

Definition
A k-tape Turing machine is a 5-tuple M = (K , ⌃, , s, H) where
statiodnetaaa
=
states

K , ⌃, s, H are as in the definition of ordinary Turing machine, and


, the transition function, is a function
Ult(K H) ⇥ ⌃k ! K ⇥ (⌃ [ { , !})k

Take a
-
>
u
memory
next operation
cuw ,

state meak peek state


on each tape
of le tapes
at the sam time

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 24 / 26


Extensions of Turing Machines

Multi-tape Turing Machines

y/o answer

Exercise: Design a two-tapes machine to decide


L = {!c! | ! 2 {a, b}⇤ } where c 62 {a, b}
~

WCW
abaa
-
c
ama

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 25 / 26


Extensions of Turing Machines

Multi-tape Turing Machines


Extending Turing machines with more than one tape does not increase

F
the power of the machines.

Theorem: Let k > 1 and M = (K , ⌃, , s, H) be a k-tape Turing


machine. Then there is a standard Turing machine
M 0 = (K 0 , ⌃0 , 0 , s0 , H) where ⌃0 ✓ ⌃, and such that for any
! 2 (⌃ {t, .})⇤

M halts on input x with output y on its first tape after t steps

if and only if

M 0 halts on input x with the same output after a polynomial number of


steps of t and the size of x.

ND HUNG (ICT, SIIT) Chapter 4: Turing Machines October 10, 2021 26 / 26


Useful Subroutines for Denigning TMs

L go left
3 of questions
type

R go right
① Compute arithmatic
functions :

Ly ecan to LHS until W is found f(n) = 2n + 1

Ry scan to RHS until W is found ② Check conditions :

E misd
f(n)-dif
s

Sh stiff entire tape to LHS

S stiff entire tape to RHS ③ Lang recog :


.

R
qwEZ /num)
*
L =

M& return O Dent@

M1 return 1 DWW + DL1

Arithmicinitialth
# 2
# f(n)
contain
- In
-n

&2 f(m) = 2n + 1 +Q1 -


Q

&3 f(m) = 2n +
3 @f(n) = n + 1 : mis var
len
Dr0100 + DW0101
.

& f(u)
-

= So *
D201011 D 2011
A
D41111 + D41004
25 f(a ,
b) = a + b

DLGD
L
Dr10000
Dr1d90
Espe
2

Sh misod
t
& flul =

Sh mise
s

& ful =

&3 f(m) = i mod ?

Tum
3

Q an yu *
(g Daabb)
.
+ (y ,
D ...
)
*
* (go Draab) + (n Dr )
an yo ,
Q2
...

n , ,

&3 an bncamym

anywanyn
I
Multi-tape Turing Machine

- Attach each instruction with the tape index .

(M go left

Ru go right
Idea
-

Ly ecan to LHS until W is found D Main tape shores

the input arguments

R scan to RHS until W is found land the output)

S stiff entire tape to LHS ② Extra tapes =

temporary variables

Su stiff entire tape to RHS

"
③ Config :

M& return O Pent@ (DUw ,


DX
,
. . . )
-
main extra

M1" return 1 DLN + DL1


tape tapes

>
Drop
ri
the take
simp :

- Trt
1
. Split the input arguments in the main tape.

Iman -

1
. Scand to tefts to find next W 4 Read t all
. .

writed y
.
2 Moved to teHS for I cell .
If not W
,
write it
?
KHS
More
move
.
3 to teHS for I cell
.
moved tells
1 2
go to 4
.
Otherwise scan
,
to LHS for L
,
2 .
Copy the
string in the main tape to the extra one .

aa
1
. Moved 200 RHS
,

.
2 Read" all
?
If not W write it
,
L
to 1
go
Otherwise scanti to LHS to find W
,
Create of the the
.
3 a reversed
capy string in

store the result in the extra


main tape and one .

a
1
. Scan" to RHS to find W DRY-- > REir
.
2

3
.
More' to LHS

Move
?
to RHS
&
4 .
Read" all
If not W write? it
,

to 2
go
2
Otherwise scan to LHS
,
4 Check if the input is the WWWR .
.
etring in
language
Use to create wh before
the extra tape comparing
the second part of the string
.

F * second part

+
-
MOD
* RE'Ro rlf- Rhiz

& bur &


wer

42 MID ?

xt =
y -
-
create a
where return
reversed
copy x = W

-
compare

rymbd
each

You might also like