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

Unit V (TM) - Part1n

The document describes the Chomsky Hierarchy, which classifies formal languages according to the type of grammar used to generate them. It lists the classes from most powerful to least powerful as: undecidable, partially decidable (Turing-acceptable), decidable, context-sensitive, context-free, and regular. Each level is also known as a type with undecidable as type 0, context-sensitive as type 1, context-free as type 2, and regular as type 3.

Uploaded by

Stuti Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Unit V (TM) - Part1n

The document describes the Chomsky Hierarchy, which classifies formal languages according to the type of grammar used to generate them. It lists the classes from most powerful to least powerful as: undecidable, partially decidable (Turing-acceptable), decidable, context-sensitive, context-free, and regular. Each level is also known as a type with undecidable as type 0, context-sensitive as type 1, context-free as type 2, and regular as type 3.

Uploaded by

Stuti Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

The Chomsky Hierarchy

Non Turing-Acceptable: Un-decidable

Turing-Acceptable: partially decidable

Turing Acceptable: decidable

Context-sensitive

Context-free

Regular

Fall 2006 Costas Busch - RPI 1


• Recursively enumerable languages are also known as type
0 languages.

• Context-sensitive languages are also known as type 1


languages.

• Context-free languages are also known as type 2


languages.

• Regular languages are also known as type 3 languages.

2
A TM accepts a language if it enters into a final state
for any input string w.

A language L is recursively enumerable (generated by


Type-0 grammar) if there exists a TM which will
accept (and therefore halt) for all inputs which are in
language L. But may or may not halt for all strings
which are not in language L.

A language L is recursive if there exists a TM that


accepts every string of the language and rejects
every string that is not in the language. The TM will
halt every time and give an answer (accepted or
rejected) for each and every string input.
A language is decidable language if it is a recursive
language . All decidable languages are recursive
languages and vice-versa.

A language is partially decidable language if it is a


recursive enumerable language .

A language is Un-decidable language if it is not


decidable. An Un-decidable language sometimes be
partially decidable but not decidable. If a language is
not even partially decidable then there exists no TM
for the language .
Recursive Language TM will always accept
Recursively Enumerable Language TM will halt sometimes and may not halt sometimes
Decidable Language Recursively Language
Partially Decidable Language Recursively Enumerable Language
Un-decidable Language No TM for that language
Turing Machine
A TM is a Tape that is unbounded both directions allowing any
number of left and right moves. It is deterministic in the sense that
δ defines at most one move for each configuration.

………. B B 0 1 1 0 0 B B

Finite
Control

A TM is a two-way infinite tape, broken into cells, each containing


one symbol with two-way read/write tape head. An input string is
placed on the tape, padded to the left and right infinitely with
blanks B, read/write head is positioned at the left end of input
string.
and Finite control, i.e. a program, containing the position of the
read head, current symbol being scanned, and the current
state.
In one move, depending on the current state and the current
symbol being scanned, the TM
1) changes state,
2) prints a symbol over the cell being scanned, and
3) moves its tape head one cell left or right.
Why TM not PDA?
A PDA can comparison two symbols at a time whereas A TM can
compare more than two symbols at a time. E.g. A PDA can be
constructed for L= {anbn|n>=1} but a TM can be constructed
for L= {anbn|n>=1} and L= {anbncn|n>=1} both.
A Deterministic Turing Machine is a seven-tuple:
M = (Q, Σ, Γ, δ, q0, B, F) where
Q A finite set of states
Σ A finite input alphabet, which is a subset of Γ– {B}
Γ A finite tape alphabet, which is a strict superset of Σ
B A distinguished blank symbol, which is in Γ
q0 The initial/starting state, q0 is in Q
F A set of final/accepting states, which is a subset of Q
δ A next-move function, which is a mapping (i.e., may
be undefined) from
Q x Γ –> Q x Γ x {L,R} (Note: {L,R} means left or right move)
Symbol to Move
Transition Diagram Symbol to be write direction
be read

q0 a, X, L q1
Note: Here Γ– {B} means subset of tau excluding Blank
Rules for Constructing/computing Operations in Turing Machine:

1. Read the current symbol on tape


2. Update the same symbol
3. Move exactly one cell (left or right)

Computation can 1) Halt and Accept


2) Halt and Reject
3) Loop means machine fails to halt

Transition Function Description δ(q0,a) -> (q1,X,R)

Transition Table
a
q0 q1,X,R
Example :Construct TM for L= {0n1n|n>=1}
Solution: The set of strings generated from the above language L={ 01,0011,000111,……..}
Let us construct Turing Machine for string 0011
B X X Y Y B

Control
unit

0,0,R 0,0,L
Y,Y,R Y,Y,L
0,X,R 1,Y,L
qq0 qq1 qq2

X,X,R

Y,Y,R Y,Y,R

qq3 B,B,R
qqf
Example :Construct TM for L= {0n1n|n>=1}
Solution: The set of strings generated from the above language L={ 01,0011,000111,……..}
Let us construct Turing Machine for string 0011
B 0 0 1 1 B

0,0,R 0,0,L
Y,Y,R Y,Y,L
0,X,R 1,Y,L
qq2
qq0 qq1

X,X,R

Y,Y,R Y,Y,R

qq3 qqf
B,B,R
δ(q0,0) -> (q1, X,R)
δ(q1,0) -> (q1, 0,R)
Transition function of above Turing Machine: δ(q1,1) -> (q2, Y,L)
δ(q2,0) -> (q2, 0,L)
δ(q1,Y) -> (q1, Y,R)
δ(q2,Y) -> (q2, Y,L)
δ(q2,X) -> (q0, X,R)
δ(q0,Y) -> (q3, Y,R)
δ(q3,Y) -> (q3, Y,R)
δ(q3,B) -> (qf, B,R)
Transition function table of TM for above language

State 0 1 X Y B
q0 q1,X,R q3,Y,R

q1 q1,0,R q2,Y,L q1,Y,R

q2 q0,0,L q0,X,R q2,Y,L

q3 q3,Y,R qf,B,R

qf Halt &
Accept
0,0,R 0,0,L
Y,Y,R Y,Y,L
B 0 0 1 1 B
0,X,R 1,Y,L
qq2
qq0 qq1

X,X,R

Y,Y,R Y,Y,R

qq3 qqf
B,B,R

q00011⊢ Xq1011⊢ X0q111 ⊢ Xq20Y1 ⊢ q2X0Y1 ⊢ Xq00Y1 ⊢ XXq1Y1 ⊢ XXYq11 ⊢ XXq2YY


⊢ Xq2XYY ⊢ XXq0YY ⊢ XXYq3Y ⊢ XXYYq3 ⊢ XXYYq3B ⊢ XXYYBqf 4+3=7

B B B 1 1 1 1 1 1 1 B B B

1,1,R
1,1,R
HALT
B,1,R B,B,L 1,B,R
qq1
qq0 qq2 qq3
Instantaneous description for the string 0011 on above turing machine
q00011⊢Xq1011 ⊢X0q111 ⊢Xq20Y1 ⊢q2X0Y1 ⊢Xq00Y1 ⊢XXq1Y1 ⊢XXYq11⊢XXq2YY
⊢Xq2XYY ⊢XXq0YY ⊢XXYq3Y ⊢XXYYq3 ⊢XXYYBqf Halt and accepted by final state

Explanation: Step1: q00011 means initially , TM takes string 0011 at state q0.
Step2: Xq1011 means reader reads 0 from tape and updates with X and move to right of X.
state changes to q1. (Note: X,0,R in transition diagram)
Step3: X0q111 means reader reads 0 from tape and makes no updating and remains on q1
and moves right of 0 . (Note: 0,0,R in transition diagram)
Step4: Xq20Y1 means reader reads 1 from tape and updates with Y and moves to left of
0.state changes to q2. (Note: Y,1,L in transition diagram)
Step5: q2X0Y1 means reader reads 0 on q2 and makes no updating and reader moves to left
of X and state remains to q2. (Note: 0,0,L in transition diagram)
Step6: Xq00Y1 means reader reads X from tape and makes no updating and moves to right
of X. state changes to q0. (Note: X,X,R in transition diagram)
Step7: XXq1Y1 means reader reads 0 from tape at q0 and updates with X and moves to right
of X. State changes to q1. (Note: 0,X,R in transition diagram)
Step8: XXYq11 means reader reads Y from tape at q1 and makes no updating and moves to
right of Y. state remains to q1. (Note: Y,Y,R in transition diagram)
Step9: XXq2YY means reader reads symbol 1 from tape at state q1 and updates with Y and
reader moves to left of Y symbol and state changes to q2. (Note: 1,Y,L in transition diagram)
Step10: Xq2XYY means reader reads symbol Y from tape and makes no updating and
reader moves to left of X symbol and state remains to q2. (Note: Y,Y,L in transition diagram)
Step11: XXq0YY means reader reads symbol X on state q2 and makes no updating and
reader moves to right of X. State changes to q0. (Note: X,X,R in transition diagram)
Step12: XXYq3Y means reader reads Y on q0 and makes no updating and moves to right
of Y. State changes to q3. (Note: Y,Y,R in transition diagram)
Step13: XXYYq3 means reader reads Y on q3 and makes no updating and moves to right
of Y. State remains to q3. (Note: Y,Y,R in transition diagram)
Step14: XXYYBqf means reader reads B (Blank cell) on q3 and updates with B and moves
to right of B. State changes to qf. Now processing halt and given string is accepted at final
state qf. (Note: B,B,R in transition diagram)
Practice Q:
1. Construct Turing machine and write Instantaneous description for L={aⁿbⁿcⁿ|n>=1}

2. Construct Turing machine and write Instantaneous description for L={wcw|w ∈(a,b)*}

3. Construct Turing machine and write Instantaneous description for L={wwR|w ∈(a,b)*}
TM as computer of integer functions
1. TM as adder

2. TM as substractor

3. TM as multiplication

4. TM as unary to
binary converter

Questions for practice

1. Construct TM for string having even number of 1’s over Σ={0,1}

2. Construct TM for string having even length over Σ={a, b}

3. Construct TM for string having substring aba over Σ={a, b}


Note: See all the links repeatedly to understand the concept clearly. Still you have problem to
understand, write or call me. 4.
A problem whose language is recursive is said to be
decidable.

A problem is Un-decidable if there exists no algorithm


that takes as input an instance of the problem and
determine whether the answer to that instance is Yes
or No.

The problems that are un-decidable are:

1. The Halting Problem and

2. The Post Correspondence Problem


Church-Turing Thesis
Turing Thesis (Weak form): Any thing we would regard as
“computable” can be computed by Turing Machine.
Turing Thesis (Strong form): Any thing we would regard as
efficiently computable can be computed in polynomial time
by TM.

Church – Turing Thesis:

1. Anything that can be done on any existing digital computer


can also be done by Turing machine.
2. No one has yet been able to suggest a problem, solvable by
what we intuitively consider an algorithm for which a TM
program can not be written.
3. Alternatively model has been proposed for mechanical
computation but none of them is more powerful than the
Turing Machine Model.
POST CORRESPONDACE PROBLEM

The PCP is an un-decidable problem that is


introduced by Emil Post in 1946.

Definition: Let Σ be an alphabet with at least two lists of strings


A and B where A=w1w2w3….wi and B = x₁x₂x₃…..xi.
The problem is to determine if there exist a sequence
of one or more integers i1,i2…..ip such that
Wi1wi2….wip = xi1xi2………xip.
(wi,xi) is called corresponding pair
In PCP, We have something called Domino in
which we have to parts i.e. top part(Numerator)
and bottom part (Denominator).

In PCP, we need to find a sequence of dominos


such that the top and bottom strings are same.
For this task, we may use any domino any
number of times.
EXAMPLES: X Y X Y
1 1 111 1 10 101
2 10111 10 2 011 11
3 10 0 3 101 011

To solve these PCP problems, see https://www.youtube.com/watch?v=VZNN1OGoqr8&t=313s


PRACTICE Q.: Set of dominos in the form of Xi/Yi are ab/aba, ba/abb, b/ab, abb/b, a/bab
In the Modified PCP, there is an additional
requirement on a solution that the first pair on the
list X and List Y must be the first pair in the solution.
More formally, an instance of MPCP is two list
X= w1,w2,w3, ... wi and Y= x1,x2,x3, ....xi

And a solution is list of 0 or more integers i1,i2,... ip


such that
W1,wi1, ...wip = x1,xi1,xi2 .... ,xip

X Y
1 11 1
2 1 111
3 10 0
HALTING PROBLEM

Alan Turing proved the existence of un-decidable problems in 1936 by


finding an example, the now famous "halting problem":
Based on its code and an input, will a particular program ever finish
running?
// countup
// count down
Include<stdio.h>
Include<stdio.h>
main()
main()
{
{
num=1;
int num=10;
while(num=0)
while(num!=0)
{ printf(“%d”, num);
{ printf(“%d”, num);
num++;
num--;
}
}
It counts up forever, since num will never
That program will halt,
equal 0.
since num eventually becomes 0.
No algorithm exists that can analyze any program's code and determine
whether it halts or not.
In order to prove that such an algorithm cannot possibly exist, Turing used
a "proof of contradiction".
This is the problem of determining whether for the given TM M over Σ=
{a,b} and input string w over Σ will halt when run on some particular
given input string w?
Proof:
Let us assume that TM(M,w) where M is a algorithm and w is input.

w Halt
Program Not Halt

Dec-halt(P,I) Un-Dec-halt(dec-halt)
{ {
If P halts on I If (dec-halt(P,I) == halt)
return halts loop forever
else else
return loop return
} }
Note that it's not actually running the programs, it's looking at their code and deciding
based on the code structure.
This is the proof by contradiction

Hence, Halting problem is the problem that you can’t decide a


particular machine will halt on a particular input for specific
program.

This is the proof that the Halting problem is un-decidable.

You might also like