This lecture slide contains:
- Difference between FA, PDA and TM
- Formal definition of TM
- TM transition function and configuration
- Designing TM for different languages
- Simulating TM for different strings
2. Chomsky Hierarchy
2
▪ Chomsky hierarchy represents the class of languages that are
accepted by the different machine.
▪ The category of language in Chomsky’s Hierarchy is given
below:
1) Type 0 – Unrestricted Grammar
2) Type 1 – Context Sensitive Grammar
3) Type 2 – Context Free Grammar
4) Type 3 – Regular Grammar
▪ Two major models of automata:
• Generators
– with output and without input
– tell us how to generate all strings in a Language L
• Acceptors
– with input and without output
– tell us if a specific string is in Language L
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
3. FA >> Schematic Diagram
3
Finite control
a ba a b input
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Finite Automaton
▸ The control represents the states and transition function.
▸ The tape contains the input string.
▸ The arrow represents the input head, pointing at the next input symbol to be read.
FA can remember a finite amount of information
4. PDA >> Schematic Diagram
4
z
Finite control
b cc a a
x
y
stack
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Based on the characteristics of CFG containing recursive rules,
how can we apply a finite state machine to CFG?
▸ The idea to reach the goal is to add a memory device to a FSM.
Push Down Automaton
▸ Input string
▹ Same as FSM
▹ Cannot back up
▸ Stack operations on each transition
▹ READ + POP or, IGNORE
▹ PUSH or, IGNORE
PDA can remember an infinite amount of information but the memory is usable in LIFO manner
5. TM – Turing Machine
5
Turing Machine
▸Similar to finite automata but with an unlimited and unrestricted memory.
▸TM model uses an infinite tape as its unlimited memory. Initially the tape contains only the input string and is blank
everywhere else.
▸The tape head can read and write symbols and move around on the tape. If the machine needs to store information, it
may write this information on the tape. To read the information that it has written, the machine can move its head back
over it.
▸The outputs accept and reject are obtained by entering designated accepting and rejecting states, if it doesn’t enter an
accepting or a rejecting state it will go on forever, never halting.
▸TM can do everything that a real computer can do. The problems that a TM can’t solve are beyond the theoretical limits
of computation.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
6. TM >> Schematic Diagram
6
▸ A Turing Machine can both write on the tape and read from it.
▸ The read-write head can move both to the left and to the right.
▸ The tape is infinite.
▸ The special states for rejecting and accepting take effect immediately.
▸ The ˽ symbol represents blank cell.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
control
a ab b ˽ input˽
7. TM >> Formal Definition
7
A Turing Machine is a 7-tuple, (Q, 𝛴, 𝛤, 𝛿, q0, qaccept, qreject), where Q, 𝛴, 𝛤 are all finite sets and
▸ Q is the set of states
▸ 𝛴 is the input alphabet not containing the blank symbol ˽
▸ 𝛤 is the tape alphabet, where ˽ 𝜖 𝛤 and 𝛴 ⊆ 𝛤
▸ 𝛿 : Q x 𝛤 → Q x 𝛤 x { L, R } is the transition function
▸ q0 𝜖 Q is the start state
▸ qaccept 𝜖 Q is the accept state and
▸ qreject 𝜖 Q is the reject state, where qreject ≠ qaccept
Outcomes: accept, reject, or loop
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
8. TM >> Transition Function
8
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
q
a b a b ˽ ˽
𝛿(q, a) = (r, b, L)
r
a b b b ˽ ˽
L = left
Transition Function,
𝛿(q, a) = (r, b, L)
Mechanism :
When the machine is in a certain state q and
the head is over a tape square containing a symbol a,
The machine writes the symbol b replacing the a,
and goes to state r.
The third component is either L or R and indicates whether the
head moves to the left or right after writing.
9. TM >> Languages
9
Turing-recognizable Language / Recursively Enumerable Language
▸ A language is Turing-recognizable if some Turing machine recognizes it.
▸ TM can fail to accept an input by entering the qreject state and rejecting, or by looping.
This causes a problem to decide whether the machine is in looping state or taking long time to compute.
Turing-decidable Language / Recursive Language
▸ Turing machines that halt on all inputs are called deciders because they always make a decision to accept or reject and
such machines never loop.
▸ A language is Turing-decidable or simply decidable if some TM decides it.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
10. TM >> L = { 0n 1n | n >= 1 }
10
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Formal Definition
Q = { q0, q1, q2, q3, q4 }
Σ = { 0, 1 }
𝛤 = { 0, 1, X, Y, ˽ }
𝛿 is described the following transition table:
Start state = q0
qaccept = q4
qreject = { }
0 1 X Y ˽
q0
(q1, X, R) - - (q3, Y, R) -
q1
(q1, 0, R) (q2, Y, L) - (q1, Y, R) -
q2
(q2, 0, L) - (q0, X, R) (q2, Y, L) -
q3
- - - (q3, Y, R) (q4, B, R)
q4
- - - - -
11. TM >> Configuration
11
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
q
a b a b ˽ ˽
𝛿(q, a) = (r, b, L)
r
a b b b ˽ ˽
L = left
Configuration: abqab
Configuration: arbbb
Start configuration: q0 w
Accepting configuration: the state of the accepting
configuration is qaccept
Rejecting configuration: the state of the rejecting
configuration is qreject
Accepting and Rejecting configurations are halting
configurations and do not yield further configuration.
– The configuration C1 yields configuration C2 if the
TM can legally go from C1 to C2 in a single step.
For example,
ua qi bv yields u qj acv ; if 𝛿(qi, b) = (qj, c, L)
and
ua qi bv yields uac qj v ; if 𝛿(qi, b) = (qj, c, R)
12. TM >> Machine 1 – L = {w # w | w ∈ {0,1}* }
12
Check acceptability for the following strings:
▸ 1011#1011
▸ 001#100
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
13. TM >> Machine 1 – L = {w # w | w ∈ {0,1}* }
13
How this machine computes … … …
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
14. TM >> Machine 1 – L = {w # w | w ∈ {0,1}* }
14
Acceptability checking: 011#011
Sequence of configurations:
q1 011#011˽
x q2 11#011˽
x1 q2 1#011˽
x11 q2 #011˽
x11# q4 011˽
x11 q6 #x11˽
x1 q7 1#x11˽
x q7 11#x11˽
q7 x11#x11˽
x q111#x11˽
xx q31#x11˽
xx1 q3 #x11˽
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
xx1# q5 x11˽
xx1#x q5 11˽
xx1# q6 xx1˽
xx1 q6 #xx1˽
xx q7 1#xx1˽
x q7 x1#xx1˽
xx q11#xx1˽
xxx q3 #xx1˽
xxx# q5 xx1˽
xxx#x q5 x1˽
xxx#xx q5 1˽
xxx#x q6 xx˽
xxx# q6 xxx˽
xxx q6 #xxx˽
xx q7 x#xxx˽
xxx q1 #xxx˽
xxx# q8 xxx˽
xxx#x q8 xx˽
xxx#xx q8 x˽
xxx#xxx q8 ˽
xxx#xxx˽ qaccept
15. TM >> Machine 1 – L = {w # w | w ∈ {0,1}* }
15
Acceptability checking: 001#100
Sequence of configurations:
q1 001#100˽
x q2 01#100˽
x0 q2 1#100˽
x01 q2 #100˽
x01# q4 100˽
Rejected, no transition exists.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
16. TM >> Machine 2 – TM for Addition
16
TM for computing sum:
Each number is represented as a sequence
of 0’s i.e. 2 = 00, 3 = 000
Input: 0 0 0 0 c 0 0 0 // 4 + 3
Output: 0 0 0 0 0 0 0 // 7
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
17. TM >> Machine 3 – TM for Subtraction
17
TM for computing difference from bigger
integer to smaller one:
Each number is represented as a sequence
of 0’s i.e. 2 = 00, 3 = 000
Input: 0 0 0 0 0 c 0 0 0 // 5 - 3
Output: 0 0 // 2
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
18. TM >> Machine 4 – TM for Comparator (A<B)
18
TM for comparing two numbers:
Each number is represented as a sequence of 0’s
i.e. 2 = 00, 3 = 000
Input: 11 0 1111 // 2 < 4
Output: 0 X X 1 1 // 1’s remain in the right
side, so second argument is greater.
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
19. TM >> Machine 5 – TM for Comparator (A=B)
19
TM for comparing two numbers:
Each number is represented as a sequence of 0’s
i.e. 2 = 00, 3 = 000
Input: 111 0 111 // 3 = 3
Output: XXX0XXX // no 1’s remain in both
sides, so A=B
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
20. TM >> Machine 6 – L = {0n 1n 2n | n >=1 }
20
Check acceptability for the following strings:
▸ 001122
▸ 0001112222
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
21. TM >> Machine 7 – L = { an bm an+m | n,m >=1 }
21
Check acceptability for the following strings:
▸ aabbbaaaaa
▸ aabaaaa
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
22. TM >> Machine 8 – L = {wwr | w ∈ {0,1}* }
22
Check acceptability for the following strings:
▸ 00111100
▸ 10100101
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
23. TM >> Machine 9 – L = {ww | w ∈ {0,1}* }
23
Check acceptability for the following strings:
▸ 101101
▸ 101110
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
24. TM >> Machine 10 – L = {ai dj ck | i>j>k and k>=1}
24
Check acceptability for the following strings:
▸ aaabbc
▸ aabbccc
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
25. TM >> Machine 11 – L = {ai dj ck | i<j<k and i>=1}
25
Check acceptability for the following strings:
▸ aaabbc
▸ abbccc
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
26. TM >> Machine 12 – L = { 02 𝑛
| n >=0 }
26
Check acceptability for the following strings:
▸ 0000
▸ 00000
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
27. 27
References:
- Chapter 3(section 3.1), Introduction to the Theory of Computation, 3rd Edition by Michael Sipser
- Reference website: https://www.geeksforgeeks.org/turing-machine-in-toc/
THANKS!
Any questions?
You can find me at imam@cse.uiu.ac.bd