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

13BSC203 Turing Machine

Uploaded by

Song Hyo yoo
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)
16 views

13BSC203 Turing Machine

Uploaded by

Song Hyo yoo
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/ 64

BCS203 Software Specifications

Turing Machines

Dr. May Mahmoud


2

Turing Machines

Costas Busch - RPI


3

The Language Hierarchy

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

a* a *b *
Costas Busch - RPI
4

Languages accepted by
Turing Machines

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

a* a *b *
Costas Busch - RPI
5

A Turing Machine
Tape
...... ......

Read-Write head
Control Unit

Costas Busch - RPI


6

The Tape

No boundaries -- infinite length

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

Read-Write head

The head moves Left or Right

Costas Busch - RPI


7

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

Read-Write head

The head at each time step:

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

Costas Busch - RPI


Example: 8

Time 0
...... ......
a b a c

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

1. Reads a
2. Writes k
3. Moves Left
Costas Busch - RPI
9
Time 1
...... ......
a b k c

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

1. Reads b
2. Writes f
3. Moves Right
Costas Busch - RPI
10

The Input String

Input string Blank symbol

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

head

Head starts at the leftmost position


of the input string

Costas Busch - RPI


12

States & Transitions

Read Write
Move Left

q1 a → b, L q2

Move Right

q1 a → b, R q2
Costas Busch - RPI
13
Example:

Time 1

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

q1
current state

q1 a → b, R q2
Costas Busch - RPI
14

Time 1

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

q1

Time 2

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

q2

q1 a → b, R q2
Costas Busch - RPI
Example: 15

Time 1

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

q1

Time 2

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

q2

q1 a → b, L q2
Costas Busch - RPI
16
Example:
Time 1

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

q1

Time 2

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

q2

q1  → g, R q2
Costas Busch - RPI
17

Determinism
Turing Machines are deterministic

Allowed Not Allowed


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

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

No lambda transitions allowed


Costas Busch - RPI
18

Partial Transition Function


Example:

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

q1

a → b, R q2
Allowed:

No transition
q1 for input symbol c
b → d, L q3
Costas Busch - RPI
19

Halting

The machine halts if there are


no possible transitions to follow

Costas Busch - RPI


20
Example:

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

q1

a → b, R q2
No possible transition
q1
HALT!!!
b → d, L q3
Costas Busch - RPI
21

Final States

q1 q2 Allowed

q1 q2 Not Allowed

• Final states have no outgoing transitions

• In a final state the machine halts

Costas Busch - RPI


22

Acceptance
If machine halts
Accept Input in a final state

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

Costas Busch - RPI


23

Turing Machine Example


A Turing machine that accepts the language:

aa *

a → a, R

 → , L
q0 q1

Costas Busch - RPI


24

Time 0   a a a  

q0

a → a, R

 → , L
q0 q1

Costas Busch - RPI


25

Time 1   a a a  

q0

a → a, R

 → , L
q0 q1

Costas Busch - RPI


26

Time 2   a a a  

q0

a → a, R

 → , L
q0 q1

Costas Busch - RPI


27

Time 3   a a a  

q0

a → a, R

 → , L
q0 q1

Costas Busch - RPI


28

Time 4   a a a  

q1

a → a, R Halt & Accept

 → , L
q0 q1

Costas Busch - RPI


29
Rejection Example

Time 0   a b a  

q0

a → a, R

 → , L
q0 q1
Costas Busch - RPI
30

Time 1   a b a  

q0
No possible Transition

a → a, R Halt & Reject

 → , L
q0 q1
Costas Busch - RPI
31

Infinite Loop Example


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

b → b, L
a → a, R

 → , L
q0 q1

Costas Busch - RPI


32

Time 0   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

Costas Busch - RPI


33

Time 1   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

Costas Busch - RPI


34

Time 2   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

Costas Busch - RPI


35

Time 2   a b a  
q0
  a b a  

Infinite loop
Time 3

q0
Time 4   a b a  
q0
Time 5   a b a  
q0
Costas Busch - RPI
36

Because of the infinite loop:

•The final state cannot be reached

•The machine never halts

•The input is not accepted

Costas Busch - RPI


37

Another Turing Machine Example


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
Costas Busch - RPI
38

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
Costas Busch - RPI
39

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
Costas Busch - RPI
40

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
Costas Busch - RPI
41

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
Costas Busch - RPI
42

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
Costas Busch - RPI
43

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
Costas Busch - RPI
44

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
Costas Busch - RPI
45

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
Costas Busch - RPI
46

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
Costas Busch - RPI
47

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
Costas Busch - RPI
48

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
Costas Busch - RPI
49

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
Costas Busch - RPI
50

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
Costas Busch - RPI
51

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
Costas Busch - RPI
52

Observation:

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

we can easily construct


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

Costas Busch - RPI


53

Formal Definitions
for
Turing Machines

Costas Busch - RPI


54

Transition Function

q1 a → b, R q2

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

Costas Busch - RPI


55

Transition Function

q1 c → d, L q2

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

Costas Busch - RPI


56
Turing Machine:

Input Tape
alphabet alphabet
States

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

Transition Final
function states

Initial blank
state
Costas Busch - RPI
57

Configuration

  c a b a  

q1

Instantaneous description: ca q1 ba

Costas Busch - RPI


58
Time 4 Time 5

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

q2 q0

A Move: q2 xayb  x q0 ayb

Costas Busch - RPI


59
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


Costas Busch - RPI
60

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


Equivalent notation: q2 xayb  xxy q1 b

Costas Busch - RPI


61

Initial configuration: q0 w

Input string

 a a b b  

q0

Costas Busch - RPI


62

The Accepted Language


For any Turing Machine M


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

Initial state Final state

Costas Busch - RPI


63

Standard Turing Machine


The machine we described is the standard:

• Deterministic

• Infinite tape in both directions

•Tape is the input/output file

Costas Busch - RPI


Check-in
• Trace the processing of the input aaaabb using this
TM, use instantaneous description starting with
q0aaaabb, will the string be accepted
Solution
• q0aaaabbB |- xq1aaabbB |- xxq2aabbB |- xxaq2abbB |-
xxaaq2bbB |- xxaq3aybB |- xxq3aaybB |- xq3xaaybB |-
xxq0aaybB |- xxxq1aybB | xxxxq2ybB |- xxxxyq2bB |-
xxxxq3yyB |- xxxq3xyyB |- xxxxq0yyB |- xxxxyq4yB |-
xxxxyyq4B|- xxxxyyBq5

• Accepted

• Bonus question, what language does this machine


accept ? {a2nbn | n>=0}

You might also like