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

chapter 6 part 1

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)
11 views

chapter 6 part 1

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/ 81

Chapter 6

Turing Machines

1
Turing Machines
Turing machines (TMs) were introduced
by Alan Turing in 1936

They are more powerful than both


finite automata and pushdown automata.
In fact, they are as powerful as any
computer we have ever built.

2
The Language Hierarchy

n n n ?
a b c
Context-Free Languages
n n
a b
Regular Languages
a* a *b *
3
Languages accepted by
Turing Machines
n n n
a b c
Context-Free Languages
n n
a b
Regular Languages
a* a *b *
4
Basic design of Turing machine
Tape
......

Read-Write head
Control Unit

5
The Tape

No boundaries -- infinite length


......

Read-Write head

The head moves Left or Right

6
......

Read-Write head

The head at each time step:

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
7
TM instructions (transition functions)
Each Turing machine instruction contains the
following five parts:
The current machine state.
A tape symbol read from the current tape
cell.
A tape symbol to write into the current tape
cell.
The next machine state.
A direction for the tape head to move.

Two inputs, three outputs: T(i, a) = (b, j, R)


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

Time 1
a b k c ......

1. Reads a
2. Writes k
3. Moves Left
9
Time 1
a b k c ......

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

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

Input string Blank symbol

a b a c ......

head

Head starts at the leftmost position


of the input string
11
Input string Blank symbol

a b a c ......

head

Remark: the input string is never empty

12
States & Transitions

Read Write
Move Left

(a , b, L )
q1 q2

Move Right
(a, b, R)
q1 q2
13
Example:
Time 1
a b a c ......

q1
current state

(a, b, R)
q1 q2
14
Time 1
a b a c ......

q1

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

q2
(a, b, R)
q1 q2
15
Example:
Time 1
a b a c ......

q1

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

q2
( a , b, L )
q1 q2
16
Example:
Time 1
a b a c ......

q1

Time 2
a b b c g ......

q2
( ,g, R)
q1 q2
17
Determinism
Turing Machines are deterministic

Allowed Not Allowed


(a, b, R) q2 (a, b, R) q2

q1 q1
(b , d , L ) q3 ( a, d , L ) q3

18
Partial Transition Function
Example:

a b a c ......

q1

(a, b, R) q2 Allowed:

q1 No transition
for input symbol c
(b , d , L ) q3
19
Halting

The machine halts if it arrives at the


accepting states or if there are
no possible transitions to follow.

20
Example:

a b a c ......

q1

(a, b, R) q2
No possible transition
q1
HALT!!!
(b , d , L ) q3
21
Final States

q1 q2 Allowed

q1 q2 Not Allowed

• Final states have no outgoing transitions

• In a final state the machine halts


22
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
23
Turing Machine Example

A Turing machine that accepts the language:


aa *

(a, a, R )

( , ,L)
q0 q1

24
Time 0
a a a

q0

(a, a, R )

( , ,L)
q0 q1

25
Time 1
a a a

q0

(a, a, R )

( , ,L)
q0 q1

26
Time 2

a a a

q0

(a, a, R )

( , ,L)
q0 q1

27
Time 3

a a a

q0

(a, a, R )

( , ,L)
q0 q1

28
Time 4

a a a

q1

(a, a, R )
Halt & Accept

( , ,L)
q0 q1

29
Rejection Example

Time 0
a b a

q0

(a, a, R )

( , ,L)
q0 q1
30
Time 1
a b a

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

( , ,L)
q0 q1
31
Infinite Loop Example
A Turing machine
for language aa * b( a  b) *

(b , b , L )
(a, a, R )

( , ,L)
q0 q1

32
Time 0 a b a

q0

(b , b , L )
(a, a, R )

q0 ( , ,L) q1

33
Time 1
a b a

q0

(b , b , L )
(a, a, R )

q0 ( , ,L) q1

34
Time 2
a b a

q0

(b , b , L )
(a, a, R )

q0 ( , ,L) q1

35
Time 2 a b a
q0
Time 3 a b a
q0
Time 4 a b a
q0

Time 5 a b a
q0
36
Because of the infinite loop:

•The final state cannot be reached

•The machine never halts

•The input is not accepted

37
Formal Definitions
for
Turing Machines

38
Turing Machine:

Input Tape
alphabet alphabet
States

M  (Q, , ,  , q0 , qacc , qrej )

Transition
Reject state
function

Initial Accept state


state
39
Transition Function

(a, a, R )
q1 q2

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

40
Transition Function

(c , d , L )
q1 q2

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

41
Example : Consider aTuring machine with following
transitions:

• (q0 , a ) = (q1 , a, R )
• (q0 , b ) = (q1 , b, R )
• (q0, ) = (q1 , , R )
• (q1 , a ) = (q0 , a, L )
• (q1 , b ) = (q0 , b, L )
• (q1 , ) = (q0 , , R )

What does this Turing machine do?

42
Configuration

c a b a

q1

Instantaneous description: ca q1 ba

43
TM configurations
• The configuration of a Turing machine is
the current setting i.e.
– Current state These three items are a
configuration of the TM
– Current tape contents
– Current head location
• Configurations are represented in a special way:
– When the TM is in state q, and
– The contents of the tape is two strings uv, and
– The head is on the leftmost position of string v
– Then we represent this configuration as “u q v ”- this
string is the Instantaneous Description (ID).

44
Configurations of TMs
• Example: 1011q7011111

q7

... 1011011111 □ □ □ ...

45
Instantaneous Descriptions of a
Turing Machine

 Initially, a TM has a tape consisting


of a string of input symbols
surrounded by an infinity of blanks in
both directions.

 The TM is in the start state, and the


head is at the leftmost input symbol.

46
Standard Turing Machine

The machine we described is the standard:

• Deterministic

• Infinite tape in one directions

•Tape is the input/output file

47
Construction of Turing Machines

48
Example I
• Given: w is a bitstring
• Construct TM that accepts the language
L ={w: w contains at least two 0s}

49
Example I (Cont’d)
1  1, R 1  1, R

0  0, R
q0 q3
0  0, R

q4

50
Example II
• Construct TM that accepts the
language
L= {anbn : n  1 }

51
Design
• Check first symbol is an a
– If not, then reject
– If so, replace with X (to mean counted) and begin
recursion
• Move to the right all the way to the first unread
b, and mark it with Y
• Move back (to the left) all the way to the last
marked X, and then move one position to the
right.
• If the next position is a, then go to step 2.
• Else move all the way to the right to ensure there
are no excess bs. If not move right to the next
blank symbol and stop & accept.
52
Example II
n n
Turing machine for the language {a b }

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 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
54
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
55
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
56
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
57
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
58
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
59
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
60
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
61
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
62
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
63
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
64
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
65
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
66
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
67
Observation:

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

we can easily construct


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

68
Turing Languages

69
Recursively Enumerable
and
Recursive Languages

70
Definition: Let M = (Q, Σ, Г, δ, q0, qacc, qrej)
be a TM, and let w be a string in Σ*. Then
w is accepted by M iff
q0w |—* α1 qf α2
where qf is in F and α1 and α2 are in Г*

Definition: Let M = (Q, Σ, Г, δ, q0, qacc, qrej)


be a TM. The language accepted by M,
denoted L(M), is the set
{w | w is in Σ* and w is accepted by M}

71
Notes:

– If x is not in L(M) then M may enter an


infinite loop, or halt in a non-final state.

– Some TMs halt on all inputs, while others


may not. In either case the language
defined by TM is still well defined.

72
Definition:
A language is recursively enumerable
if some Turing machine accepts it

73
Let L be a recursively enumerable language

and M the Turing Machine that accepts it

For string w:
if w L then M halts in a final state

if w L then M halts in a non-final state


or loops forever
74
This definition implies only that there exists
a TM M, such that for every wL,

q0 w |-* x1 qf x2

The definition says nothing about what


happens for w L;
…it may be that the machine halts in a
non- final sate or it never halts and goes
into an infinite loop.

75
Definition:
A language is recursive
if some Turing machine accepts it
and halts on any input string

In other words:
A language is recursive if there is
a membership algorithm for it
76
Let L be a recursive language

and M the Turing Machine that accepts it

For string w:

if w L then M halts in a final state

if w L then M halts in a non-final state

77
What do you think is the advantage of
being recursive language over recursively
enumerable language?

Assuming you are presented a string w,


and you would like to know whether w is in
the language.

78
Examples of Recursively Enumerable Languages

 L = {w  {a, b}* : w contains at least one a}


 L = {w  {a, b}* : w contains a double a}

79
Non- Recursively Enumerable

Recursively Enumerable

Recursive

80
Notes:
The set of all recursive languages is
a subset of the set of all recursively
enumerable languages

A TM is not recursive or recursively


enumerable, rather a language is
recursive or recursively enumerable.

81

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy