Theory of Computation 1 Munotes
Theory of Computation 1 Munotes
1
AUTOMATA THEORY
Unit Structure
1.0 Objectives
1.1 Introduction
1.2 Definition of an Automaton
1.3 Finite Automaton
1.4 Transition Systems
1.4.1 Properties of Transition Systems
.in
1.5 Acceptability by Finite Automaton
1.6 Non-deterministic Finite StateMachines
es
1.7 DFA and NDFA equivalence
1.8 Mealy and Moore Machines
ot
1.0 OBJECTIVES
After going through this chapter, the learner will be able to:
1.1 INTRODUCTION
Automata theory is the study of abstract machines and computational
problems. It is a theory in theoretical computer science and the
1
Theory of Computation word automata originate from a Greek word that means "self-acting, self-
willed, self-moving". In this chapter, we will discuss much in detail about
what is an automaton, its types, and conversion among the types.
.in
Fig. 1.2 Components of an Automaton
es
(i) Input: It indicates the value taken from the input alphabet and
applied to the automaton at the discrete instant of time. Represented as
I1, I2, …., In.
ot
(ii) Output: It refers to the response of the automaton based on the input
taken. Represented as O1, O2, …., On.
un
(iii) State: At a specific instant of time, the automaton can take any state.
Represented as q1, q2, …., qn
(iv) State Relation: It refers to the next state of automaton based on the
m
2
(ii) = finite non empty set of input symbols (input alphabet) Automata Theory
(iii) = direct transition function (a function that maps Q× into Q which
describes the change of states)
(iv) q0= initial state
Symbol Description
.in
Start state
es
Intermediate state
ot
Final state
un
State\Input 0 1
q0 q2 q1
q1 q3 q0
q2 q0 q3
*q3 q1 q2
Note: → near the state represents “start” state and * represents the final
state
3
Theory of Computation Solution: The automaton is represented using the transition diagram given
below,
0010 is an accepted string whereas 101 is not an accepted string. For any
string to be accepted, it should commence from the start state (vertex) and
end atthe final state (vertex).
1.4.1 Properties of Transition Systems
Property 1: The state of thesystem can be changed only by an input
.in
symbol.
Property 2: For all strings xand input symbols b,
es
(q, bx) = ((q, b), x)
xb. Consider example 1.4, where string “0010” is the acceptable string of
the automaton. Here the state reads the first symbol of string “0010” say,
“0” where the start state was q0. After which it would have reached the
next state say, q2. Thus, the prefix of q2 would be the string “0”. The same
m
State\Input 0 1
q0 q2 q1
q1 q3 q0
q2 q0 q3
*q3 q1 q2
4
Which among the following string is/are acceptable? Automata Theory
(i) 101010 (ii) 11100
Solution:
The automaton is represented using the transition diagram given below,
(i) 101010
.in
es
ot
un
m
Since the final state q3 is reached at the end of the string, the string
“101010” is acceptable by the finite automaton.
Note: The ↓ indicates the current input symbol which is in the process by
the automaton.
(ii) 11100
5
Theory of Computation Since the state q1 is not a final state which was reached at the end of the
string, the string “11100” is not acceptable by the finite automaton.
.in
es
Fig. 1.6 Non-deterministic Finite State Machine
ot
It can be noted that at state q0 with the input symbol “0”, the machine can
either reach state q1or q2. Similarly, at state q2 with the input symbol “1”,
un
the machine can either reach state q2 itself or q1. This property makes the
automaton non-deterministic.
A non-deterministic finite automaton (NDFA) is represented using 5-tuple
m
(iii) = direct transition function (a function that maps Q× into Q which
describes the change of states)
(iv) q0 = initial state
6
The transition state table for Figure 1.6 is given below, Automata Theory
State\Input 0 1
q0 {q1, q2} -
*q1 q0 q2
q2 - {q1, q2}
Note: The above transition state table for and NDFA contains a subset of
states at {q0,0} and {q2, 1}
.in
• For one input symbol, NDFA can have zero, one, or more than one
move for a specific state.
Consider a non-deterministic finite automaton (NDFA) is represented
es
using 5-tuple such as (Q, , , q0, F) and deterministic finite automaton
(DFA) is represented using 5-tuple such as (Q’, , , q0, F’). The steps for
converting an NDFA to DFA are listed below.
ot
Step 3: For every state which is added to Q’, find the possible set of states
for each input symbol with the help of the transition state table. Two of the
following actions are to be performed.
m
7
Theory of Computation Solution:
Step 1: Initially let Q’ be an empty set
State\Input 0 1
- - -
Step 2: Add the start vertex q0 to Q’
State\Input 0 1
q0 {q1, q3} {q2, q3}
Step 3: For every state which is added to Q’, find the possible set of states
for each input symbol with the help of the transition state table. Two of the
following actions are to be performed.
.in
• If the state is not a new entrant, then ignore
New state 1: {q1, q3}
es
Check both q1andq3 entries from the NDFA transition table
State\Input 0 1
q0
ot
State\Input 0 1
q0 {q1, q3} {q2, q3}
{q1, q3} q1 q3
{q2, q3} q3 q2
New state 3: q1
State\Input 0 1
q0 {q1, q3} {q2, q3}
{q1, q3} q1 q3
{q2, q3} q3 q2
q1 q1 q3
8
New state 4: q2 Automata Theory
State\Input 0 1
q0 {q1, q3} {q2, q3}
{q1, q3} q1 q3
{q2, q3} q3 q2
q1 q1 q3
q2 q3 q2
New state 5: q3
State\Input 0 1
q0 {q1, q3} {q2, q3}
{q1, q3} q1 q3
{q2, q3} q3 q2
.in
q1 q1 q3
q2 q3 q2
*q3 - -
es
Step 5: All the states that contain the final state of NDFA are marked as
the final state.
ot
State\Input 0 1
un
q1 q1 q3
q2 q3 q2
*q3 - -
9
Theory of Computation Solution: The transition state table is generated as,
State\Input 0 1
q0 {q0, q1} {q0}
q1 - q2
*q2 - -
State\Input 0 1
- - -
State\Input 0 1
.in
q0 es {q0, q1} {q0}
Step 3: For every state which is added to Q’, find the possible set of states
for each input symbol with the help of the transition state table. Two of the
following actions are to be performed.
ot
State\Input 0 1
q0 {q0, q1} {q0}
{q0, q1} {q0, q1} {q0, q2}
State\Input 0 1
q0 {q0, q1} {q0}
{q0, q1} {q0, q1} {q0, q2}
{q0, q2} {q0, q1} {q0}
10
Step 5: All the states that contain the final state of NDFA are marked as Automata Theory
the final state.
State\Input 0 1
q0 {q0, q1} {q0}
{q0, q1} {q0, q1} {q0, q2}
*{q0, q2} {q0, q1} {q0}
.in
represented using the transition state table.
Next State
es
Present State Input 0 Input 1
State Output State Output
q1 q4 0 q2 1
ot
q2 q1 1 q4 0
q3 q3 1 q3 0
un
*q4 q2 0 q1 1
For an input string “1011”, the transition states are given by q1 ->q2 ->q1 ->
m
Next State
Present State Output
Input 0 Input 1
q1 q4 q2 1
q2 q1 q4 0
q3 q3 q3 0
*q4 q2 q1 1
For an input string “1011”, the transition states are given by q1 ->q2 ->q1 ->
q2 -> q4. The output string is “1010”
11
Theory of Computation
1.9 MINIMIZING AUTOMATA
Suppose there is a DFA (Q, , , q0, F) which recognizes a language
LThen the minimized DFA (Q’, , , q0, F’) can be constructed for
language L as:
Step 1: We will divide Q (set of states) into two sets.
One set will contain all final states and the other set will contain non-final
states.
Step2: Initialize k = 1
Step 3: Find Qk by partitioning the different sets of Qk-1. In each set of Qk-
1, take all possible pairs of states. If two states of a set are distinguishable,
we will split the sets into different sets in Qk.
Step 4: Stop when Qk = Qk-1 (No change in the partition)
Step 5: All states of one set are merged into one. No. of states in
minimized DFA will be equal to no. of sets in Qk.
.in
Consider the example of DFA given below:
es
ot
un
Step1. Q0 will have two sets of states. One set will contain the final states
m
of DFA and another set will contain the remaining states. So,Q0 =
{{q1,q2,q4}, {q0, q3, q5}}.
Step 2. To calculate Q1, check whether sets of partition Q0 can be
partitioned or not.
i) For set { q1, q2, q4} :
Since q1 and q2 are not distinguishable and q1 and q4 are also not
distinguishable, So q2 and q4 are not distinguishable. So, { q1, q2, q4} set
will not be partitioned in Q1.
.in
es
1.10 SUMMARY
ot
.in
2.5 Languages and Their Relations
2.6 Recursive Enumerable Sets
es
2.7 Operations on Languages
2.8 Languages and Automata
ot
2.9 Summary
2.0 OBJECTIVES
un
After going through this chapter, the learner will be able to:
2.1 INTRODUCTION
Linguists were trying in the early 1950s to define preciselyvalid sentences
and give structural descriptions of sentences. They wanted todefine formal
grammar (i.e. to describe the rules of grammar in a rigorousmathematical
way) to describe English. Itwas Noam Chomsky who gave a mathematical
model of grammar in 1956.Although it was not useful for describing
natural languages such as English, itturned alit to be useful for computer
languages.
14
2.2 DEFINING GRAMMAR Formal Languages
.in
S, A, and B are Non-terminal symbols;
a and b are Terminal symbols
es
S is the Start symbol, S ∈ N
Productions, P : S → AB, A → a, B → b
ot
1. S ⇒ ab
m
2. S ⇒bb
3. S ⇒aba
4. S ⇒aab
Hence, the language generated by G, L(G) = {ab, bb, aba, aab}.
xαy⇒Gxβy
15
Theory of Computation Let us consider the grammar,
G = ({S, A}, {a, b}, S, {S → aAb, aA → aaAb, A → ε })
Some of the strings that can be derived are,
L(G)={W|W ∈ ∑*, S ⇒G W}
.in
If L(G1) = L(G2), the Grammar G1 is equivalent to the Grammar G2.
Suppose we have the following grammar,
es
G = {S, A, B} T = {a, b} P = {S → AB, A → aA|a, B → bB|b}
The language generated by this grammar L(G) = {ab, a2b, ab2,
ot
a2b2, ………}
= {am bn | m ≥ 1 and n ≥ 1}
un
According to Noam Chomsky, there are four types of grammar such as,
16
Formal Languages
.in
Type-3 grammars generate regular languages. Type-3 grammars must
have a single non-terminal on the left-hand side and a right-hand side
consisting of a single terminal or single terminal followed by a single non-
es
terminal.
The productions must be in the form X → a or X → aY
ot
rule.
Example 2.4.1
m
A→ε
A → a | aB
B→b
Type - 2 Grammar
Type-2 grammars generate context-free languages.
The productions must be in the form A → γ
where A ∈ N (Non-terminal)
17
Theory of Computation Example 2.4.2
S→Aa
A→a
A → aA
A → abc
A→ε
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages.
The productions must be in the form, α A β → α γ β
where A ∈ N (Non-terminal)
.in
The strings α and β may be empty, but γ must be non-empty.
The rule S → ε is allowed if S does not appear on the right side of any
rule. The languages generated by these grammars are recognized by a
es
linear bounded automaton.
Example 2.4.3
ot
AB → AbBc
A → bcA
un
B→b
Type - 0 Grammar
m
Regular Languages are the most restricted types of languages and are
accepted by finite automata. Regular Expressions are used to denote
regular languages. An expression is regular if,
.in
Regular Languages: A language is regular if it can be expressed in terms
of a regular expression.
recognized by the Turing machine which means it will enter into the final
state for the strings of language and may or may not enter into rejecting
state for the strings which are not part of the language. It means the Turing
un
machine can loop forever for the strings which are not a part of the
language. RE languages are also called Turing recognizable languages.
1. Union
If L1 and If L2 are two regular languages, their union L1 ∪ L2 will also be
regular.
For example,
L1 = {an | n ≥ 0} and L2 = {bn | n ≥ 0}
L3 = L1 ∪ L2 = {an ∪ bn | n ≥ 0} is also regular.
2. Intersection
If L1 and If L2 are two regular languages, their intersection L1 ∩ L2 will
also be regular.
For example,
L1= {am bn | n ≥ 0 and m ≥ 0} and L2= {am bn ∪ bn am | n ≥ 0 and
m ≥ 0}
L3 = L1 ∩ L2 = {am bn | n ≥ 0 and m ≥ 0} is also regular.
19
Theory of Computation 3. Concatenation
If L1 and If L2 are two regular languages, their concatenation L1.L2 will
also be regular.
For example,
L1 = {an | n ≥ 0} and L2 = {bn | n ≥ 0}
L3 = L1.L2 = {am . bn | m ≥ 0 and n ≥ 0} is also regular.
4. Kleene Closure
If L1 is a regular language, its Kleene closure L1* will also be regular.
For example,
L1 = (a ∪ b)
L1* = (a ∪ b)*
5. Complement
If L(G) is a regular language, its complement L’(G) will also be regular.
The complement of a language can be found by subtracting strings that are
in L(G) from all possible strings.
For example,
L(G) = {an | n > 3}
.in
L’(G) = {an | n <= 3}
2.9 SUMMARY
A grammar is a quadruple G = (N, Σ, P, S)
Strings may be derived from other strings using the productions in
grammar.
The set of all strings that can be derived from a grammar is said to be
the language generated from that grammar.
20
According to Noam Chomsky, there are four types of grammar such Formal Languages
as Type 0 (Unrestricted grammar), Type 1 (Context-sensitive
grammar), Type 2 (Context-free grammar), and Type 3 (Regular
grammar)
Regular Languages are the most restricted types of languages and are
accepted by finite automata.
Regular Expressions are used to denote regular languages.
Recursive Enumerable languages or type-0 languages are generated
by type-0 grammars.
Union, Intersection, Concatenation, Kleene Closure, Complement are
some of the operations on languages.
.in
es
ot
un
m
21
Unit II
3
REGULAR SETS AND REGULAR
GRAMMAR
Unit Structure
3.0 Objectives
3.1 Introduction
3.2 Regular Grammar
3.3 Regular Expressions
.in
3.3.1 Regular Expressions Identities
3.3.2 Regular Language Definition and Examples
es
3.4 Finite automata and Regular Expressions
3.5 Pumping Lemma and its Applications
ot
3.8 Summary
3.9 References
m
3.0 OBJECTIVES
After the end of this unit, Students will be able to:
22
3.1 INTRODUCTION Regular Sets and Regular
Grammar
In this chapter we are learn the concept of the Regular Expression. We
first describe regular expressions as a means of representing subsets of
strings over ∑ and prove that regular sets are exactlythose accepted by
finite automata (FA) or transition systems. We study about pumping
lemma for regularLanguages to prove that certain Languages are not
regular. Then we studyclosure properties of regular sets. At the and we
discuss the relation between regular sets and regular grammars
.in
Where ɛ is a special symbol called NULL then this grammar called as
regular Grammar.
Regular Grammar having two types:
es
ot
un
m
23
Theory of Computation 3.3 REGULAR EXPRESSIONS
The regular expressions are useful for representing certain sets of strings
in an Algebraic fashion. Here, these describe the languages accepted by
finite state automata. We give a formal recursive definition of regular
expressions over ∑ as follows:
1. Any terminal symbol (i.e. an element of ∑), ε and Ø are regular
expressions. When we view a in ∑ as a regular expression, we denote
it by a.
2. The union of two regular expressions R, and R, written as R1 + R2,is
also a regular expression.
3. The concatenation of two regular expressions Rj and R2, written as Rj
R2, is also a regular expression.
4. The iteration (or closure) of a regular expression R written as R*, is
also a regular expression. 5. If R is a regular expression, then (R) is
also a regular expression.
.in
5. The regular expressions over ∑are precisely those obtained
recursively by the application of the rules 1-5 once or several times.
Notes:
es
1. We use x for a regular expression just to distinguish it from the
symbol (or string) x.
ot
.in
5. P* = P++ ε
6. P* P* = P*
es
7. (PQ) * P= P(QP) *
8. (P+Q) *=(P*Q*)*=(L*+M*)*
ot
L = a, b, c, d
So, from above strings Regular Expression represents Language L
consisting of
Stringsover {a, b}
Q.3 Find out regular language of Regular Expression a*+ b+ + c + d
Solution:
To find out language for Regular Expression = a*+ b+ + c + d
.in
We can take all possible strings from the given expression
Consider, r = a* + b+ + c + d
es
For our understanding break the given regular expression into parts
Then, the possible strings in language are
ot
a* = ε , a , aa, aaa,…….
un
a* = ε , a, aa, aaa,…..
26
a*b = b, ab, aab, aaab,…… Regular Sets and Regular
Grammar
c+ = c, cc, ccc, cccc,………
.in
present. It may have zero or more occurrences of leading a's and b's and
trailing a's and b's.
So the required regular expression for given language will be
es
r= (a + b) * a (a + b) *
Q.6 Find out a regular expression for a language L over ∑ *, where ∑ =
ot
{0, 1} such thatevery string in the language begin and end with either 00
or 11.
un
Solution:
Here given that string must begin and end with either 00 or 11 so we will
denote regularexpression as (00+ 11). Now in between zero or more
m
q0
2. r=
q0 q01
3. r=a
.in
a
q0
es q10
the forms of r.
Case1: r = a + b
un
q2 q3
ϵ ϵ
m
q1 q4
ϵ ϵ
b
q6 q5
Case: 2 r = ab
a ϵ b
q q q q
0 1 2 3
Case 3 r = a*
ϵ
ϵ q0 a q1 ϵ q2 q3
28
Examples 1 Regular Sets and Regular
Grammar
Draw FA with ϵ moves for the regular expression given as a (a+b)*.
Solution:
Using the above methods, steps for converting given regular expression to
FA
a
ϵ q1 q2 ϵ
q0 q5
ϵ ϵ
b
Step: 1 q3 q4
.in
a
ϵ q2 ϵq 3
ϵ ϵ
es
q0 q1 q6 q7
ϵb ϵ
ot
ϵ q4 q5
un
a
ϵ q5
q4
a ϵ ϵ ϵϵ
ϵ q9
ϵbϵ q0 q1 q2 q3 q8
q7
q6
ϵ
Step: 3
Final FA with ϵ moves for a (a+b)*
29
Theory of Computation Solution:
Using the rules for converting regular expression to FA with ϵ moves we
can get FA with ϵ moves for (a*+b*) as in following figure:
.in
Step: 3Final FA with ϵ moves for (a*+ b*)
es
∴ M= ({q0,q1,q2,q3,q4,q5,q6,q7,q8}, {a, b}, p,q0,q9)
ot
Proof:
Let L (M) be a regular language accepted be a given DFA, M = (Q1 Ʃ, δ,
q0, F) with some particular number of notes ‘n’
Consider an input of ‘n’ or more symbols a1, a2, a3 ... am, m>nand for i =
1,2,3,……..m
Let δ (q0, a1, a2, ….ai,) = q1
It is not possible for each of the (n+1) states q0, q1, q2… qnto be distinct;
because there are only ‘n’ states and to recognize the string of length m ≥
n it requires at least (n+1) states if we want them to be distinct.
Thus, there exists two integers ‘j’ and ‘k’ where, 0 ≤ j < k ≤ Such that qj =
qkConsider the transition diagram for the DFA M, as given in the
following figure.
30
Regular Sets and Regular
Grammar
aj+1……….ak
a1………..aj ak+1………..a
qj =qk m qm
q0
m
It qm⊂F i.e. if qmis final state that means, “ a1, a2,…..am” is in L (M), then
“a1,a2………aj,ak+1 ak+2……am” is also in L(m); since there is a path from
.in
q0 to qm that goes through qjbut not around the loop labeled aj+1 …..ak.
Similarly, we can go around the loop as many times as we like and the
resultant string will still be in L (m).
es
i.e. a1……..aj (aj+1ak)I ak+1 …….am⊂ L(M)
For any i≥0 (i.e closure – zero or more occurrences) Hence the proof.
ot
word in 'L' and │Z│ ≥ n, we may write z = uvw in such a waythat │uv│ ≤
n, │v │. i.e. 1 ≤ │v│≤ n and for all i ≥ 0, u vl w is in L.Proof (of the
formal statement):
m
Consider, z = a, a,
u = a, a2
V =aj +1……..ak
W= ak+1
Using above consideration, the previous proof can be a proof for theformal
statement.
Application of pumping Lemma:
It is a dominant tool for demonstrating certain languages non-regular.
Given a language, with the assistance of pumping lemma, we can define
whether it is a regular language or non-regular language.
31
Theory of Computation Example: 1
Prove that, the following language is non-regular using Pumping lemma,
.in
c) Let ‘ɭ’ be the constant of pumping lemma.
d) Let z = aɭ. bɭ+l, where
es
Length of z = │2│ = ɭ + ɭ + 1 = 2 ɭ + 1
e) By Pumping lemma we can write ‘z’ as
ot
z = uvw where,
un
1 ≤│v│ ≤ ɭ
anduv'w for i ≥ 0 is in L.
m
f) Let i = 2
as we know, from Pumping lemma,
i≤│ v│ ≤ ɭ
(2 ɭ +1) +1 ≤ │uv2 w│ ≤ ɭ + (2 ɭ + 1)
Because, │uvw │= 2 ɭ + 1
Therefore,
2 ɭ + 2 ≤ │uv2w│ ≤ 3 ɭ + 1
g) 2 ɭ + 2 ≤ │ u v2 w│ ≤ 3 ɭ + 1
i.e. 2 ɭ + 1 < │u v2w│ < 3 ɭ + 2
Consider, ɭ = 1
3 < │uv²w│ < 5
32
i.e. length= 4 (not odd) Regular Sets and Regular
Grammar
for, ɭ = 2
5 < 1 uv2w│ < 8
i.e. length = 6, 7 (not always odd)
Thus, the length of "uv2w" is not always add. That means "uv2w" isnot
in L.
But that is the paradox with Pumping lemma. Therefore, as per our
assumption that 'L' is regular, must be wrong,
Therefore, given language L = {anbn+ 1 │n > 0} is non-regular.
Example: 2 Prove that L = {aibjck │k >i + j} is not regular.
Solution:
Step: 1 Assume that L is regular. Let L = T (M) for some DFA with n
.in
States.
Step: 2 Let w = anbnc3n in L
es
By pumping lemma we write w = xyz with │xy│≤ n and │y│ ≥ 0
Now consider
ot
w = anbnc3n
w = xyz
un
xy = ai for some i ≤ n
Step: 3 Then xyk+1 z = an+jkbnc3n
m
∴ L is not regular.
33
Theory of Computation If a class of language is closed under a specificoperation thatfact isentitled
as closure property of the class of language.
Theorems
1. The regular sets are closed under union, concatenation and
Kleene closure. If X and Y are regular sets.
Then X U Y, (X + Y), X Y and X*are also regular
Proof:
X+Y that means the language of all words in either X orY. Regular
expressions forX and Y are r1 and r2 respectively.
Then r1 + r2 is regular expression for X U Y
r1r2 regular expressionfor XY.
r1*is regular expression for X*.
.in
Therefore, all three types of these sets of words adefinable by regular
expressions and so are themselves regular sets.
2. Regular set is closed under complementation. If X is regular set,
es
then X'is also regular.
Proof:
Let X be X (M). Some of states of this FA, M are final states and some are
not.Let's reverse the states of each state, i.e., if it was a final state make it
m
34
Regular Sets and Regular
Grammar
.in
es
ot
un
Above Finite Automata shows that it accept all strings other than aba and
aTherefore, we can prove that complement of regular set is also regular.
3. The regular sets are closed under intersection. If X and Y are
m
regular sets.
Then X ∩ Yis also regular
Proof:
By Using De-Morgan’s Law
X ∩ Y = (X' U Y') ' = (X'+Y')’ this can be stated by Venn diagram
(X' U Y')
35
Theory of Computation
(X'+Y')’
.in
es
We observed above Venn diagram the language X ∩ Y consists of all
ot
words that are not in either X' or Y'. Since X and Y are regular, then so are
X' and Y'. Since X' and Y'are regular, so is X' + Y'. And since X' and Y' is
regular, then so is (X' + Y')’, which meansX ∩ Y, is regular.
un
Regular Sets
Regular set is theset that represents the value of the Regular
Expression.
The class of Regular Set over ∑ is defined as
a) Every finite set of words over alphabet ∑ (including Ø, the empty set
or nullset) is a regular set.
b) If X and Y are regular sets over then X U Y (union) and X
Y(concatenation) are also regular sets.
c) If P is a regular set over alphabet ∑ then so its closure i.e. S is the
smallest class
In other words, the class of regular sets over alphabet ∑containing all
finite sets of words over alphabet ∑ and closed under union, concatenation
and star operation.
36
Note: Any set which is predictable by an FSM is regular; and conversely, Regular Sets and Regular
every regular set can be predictable by some FSM. Regular set is Grammar
represented by value of regular expression.
Properties of Regular Sets
Property 1. The union of tworegular sets is regular
Proof:
Let us take two regular expression
r1 = (aa)* and r2 = a (aa)*
So X = {ε, aa, aaaa, aaaaaa…} (even length h strings including NULL)and
Y = {a, aaa,aaaaa,aaaaaaa,……….} (odd length strings excluding NULL)
X U Y ={ε, a, aa, aaa, aaaa,aaaaa,……….}
(allpossible length strings including NULL)
.in
(X U Y) = a* (this is also regular expression itself)
and Y = {ε, aa, aaaa, aaaaaa,…….} (even length strings including NULL)
X ∩ Y = { aa, aaaa, aaaaaa,…….} (even length strings excluding NULL)
X ∩ Y = aa(aa)* (this is also regular expression itself)
.in
X - Y = a(aa)* (this is also regular expression itself)
r = {01+10+11+10}
So X = {01, 10, 11, 10}
m
.in
expression (0+1)001(0+1) *)
(X U Y) = a* (this is also regular expression itself)
es
∴Concatenation of two sets is regular
Regular Grammar:
ot
The languages generated using this grammar means regular languages are
primitive and can be generated and generated using FSM (finite state
machine). These regular languages can also be expressed by expressions
called as regular expression.
Depending on the position of a non-terminal whether it is leftmost or
rightmost, regular grammar is further classified as
1) Left-linear grammar and
2) Right-linear grammar.
1) Left-linear grammar:
We know, regular grammar can contain at the most one non-terminal on
the right-hand side of its production. If this variable looks as the leftmost
symbol on the right-hand side, the regular grammar is called as be left-
linear grammar,Following are forms of productions in left-linear grammar
are
39
Theory of Computation A → Bx, A → ε or A→x
Where, 'A' and 'B' are non-terminal and 'x' is a string of terminals.
e.g. Consider the following grammar
G = ({S, B, A), (a, b), P, S)
Where, 'P' contains following set of production rule,
S → Aa │ Bb
A→ Bb
B → Balb
Above grammar is left-linear in each production has only one nonterminal
on the right-hand side and that is the leftmost symbol on the right-hand
side.
2) Right-linear grammar:
.in
A regular grammar contains of productions with at the most onenon-
terminal on the right-hand side and the right most symbol appears on the
right-hand side of the production then the grammar is called right-linear
es
grammar
Following are forms of productions in right-linear grammar are
ot
A →x B,
A → x or
un
A→ε
Where, 'A' and 'B' are non-terminal and 'x' is a string of terminals.
m
3.8 SUMMARY
Regular set is the set that represents the value of the Regular
Expression.
3.9 REFERENCES
1) Theory of Computer Science, K. L. P Mishra, Chandrasekharan,
PHI,3rdEdition
2) Introduction to Computer Theory, Daniel Cohen, Wiley,2ndEdition
3) Introductory Theory of Computer Science, E.V. Krishnamurthy,
.in
Affiliated East-West Press.
4) Introduction to Languages and the Theory of Computation, John E
Martin, McGraw-HillEducation.
es
3.10 REVIEW QUESTIONS
ot
2) Regular set
3) Regular Grammar
m
41
4
CONTEXT FREE LANGUAGE
Unit Structure
4.0 Objectives
4.1 Introduction
4.2 Context-free Languages
4.3 Derivation Tree
4.4 Ambiguity of Grammar
4.5 CFG simplification
4.6 Normal Forms
.in
4.6.1 Chomsky Normal Form
4.6.2 Greibach Normal Form
es
4.7 Pumping Lemma for CFG
4.8 Summary
ot
4.9 References
4.10 Review Questions
un
4.0 OBJECTIVES:
At the end of this unit, Students will be able to:
m
42
4.1 INTRODUCTION Context-free Languages
This Chapter deals with concepts of grammar and especially about context
free Grammarand Context-free Languages.It gives details information
about Derivation, Derivation Tree and Ambiguous Grammar.The need of
Simplification of Grammar means we can remove Ambiguity of Grammar.
Also discussion about Normal Forms and Properties of CFL.The property
of CFG is that all productions are of form one Non-terminal→ finite string
or terminals and/or nonterminal. The language created by a CFG is called
a context-free language.
.in
S → aSb │ ab
Find the CFL generated by the above grammar.
Solution:
es
Let us start listing or generating the strings that we can generatewith the
above CFG. Let us start with minimal length string. Let usnumber the
productions as,
ot
S => ab
ii) To start with new derivation, we can have,
S => aSb , rule (1)
=> aabb , rule (2)
iii) S => aSb , rule (1)
=> aaSbb , rule (1)
=> aaabbb , rule (2)
iv) S => aSb , rule (1)
=> aaSbb , rule (1)
=> aaaSbbb , rule (1)
=> aaaabbbb , rule (2)
43
Theory of Computation Thus, the language can be listed in the form of set as,
L = {ab, aabb, aaabbb, aaaabbbb…….}
i.e. L = (an bn │n ≥ 1)
Thus, the CFG which is given to us defines the language containingstrings
of the form an bn for n ≥ 1.
Q.2. Write a grammar for generating strings over Ʃ= {a} containing
anynumber
(zero or-more) of 'a's.
Solution:
Zero number of 'a's can be generated using production
SE → ϵ (ϵ - production)
If we want one or more 'a's we can generate them with
.in
S → a │as
Combining the two, the grammar that we get is
es
S → aS │ a│ ϵ
We can represent the grammar formally as
ot
44
=> aaas , rule (1) Context-free Languages
.in
i.e "aaba".
S => aS , rule (1)
es
=> aaS , rule (1)
=> aabS , rule (2)
ot
S→ aS │bs│ a │b
This grammar now cannot generate an empty string i.e the
stringcontaining zero number of 'a's and zero number of 'b's, because P
does notconsist of the production of the form, S → ϵ.
Closure Properties of CFL:
The flexibility of the rule of context – free grammars is used to establish
closure results for the set of context free languages. Operations that
preserve context free languages provide another tool for proving that
languages are context free. These operations along with pumping lemma,
can also the used to show that certain languages are not context free.
Properties:
i. CFL’S are closed under union.
ii. CFL’S are closed under concatenation.
45
Theory of Computation iii. CFL’S are closed under kleene closure and positive closure.
Formalization of the Grammar:
For building a formal model, we should consider two aspects of thegiven
grammar:
1) The generative capacity of the grammar i.e, the grammar used'
shouldgenerate all and only the sentences of the language for which it
is written
2) Grammatical constituents, like terminals and non-terminals.
A grammar that is based on the constituent structure as describedabove, is
called as constituent structure grammar or phase structuregrammar.
Formal Definition of Grammar:
A phrase structure grammar is denoted by a quadruple of the form,
G = (V, T, P, S)
.in
Where,
V: Finite set of non-terminals (variables)
es
T: finite set of terminals.
S: S is a non-terminals N called as the starting symbol,corresponding to
the sentence symbol.
ot
α→B
Where, α, β ⊂ (V U T)* and 'α' involving at least one symbol from ‘V’i.e.
at least one non-terminal.
m
Here we know,
V ∩ T = Ø = null set.
‘α' and 'β' consists of any number of terminals as well asnon-terminals and
they are usually termed as sentential forms. Chomsky had classified the
grammars in four major categories. Outof which there is one, with the
productions of the form
A→α
Where, 'A' is any non-terminal
and 'α' is any sentential formis called as Context-free grammar.
As we can observe in this typeof grammar there is a restriction that, on the
left hand side of eachproduction there should be only one Non-terminal,
e.g. The grammar thatwe have considered generating statement 'Dog runs'
46
can also be consideredas an example of context free grammar, in short, Context-free Languages
termed as CFG.
.in
S → a A S│a
A → S b A / S S / ba
es
Derive "aabbaa" using leftmost derivation and rightmost derivation.
Solution:
ot
Rule (1) S → AS
Rule (2) S → a
m
47
Theory of Computation (ii) Rightmost derivation:
S => a A S by using rule (1)
=> a A a by using rule (2)
=> a S b A a by using rule (4)
=> a S b b a a by using rule (5)
=> a a b b a a by using rule (2)
When a string is to be generated from the given production rules, then it
will be veryconvenient to shown the generation of string pictorially. This
generation (also calledderivation) when drawn graphically takes a tree
form and so it is called derivation tree oralso called parse tree. We observe
the following regarding the derivation tree.
i. The root node in the derivation tree is always labelled with the start
symbol as all strings are imitative from start symbol
ii. All the leaf nodes are labeled with some terminal symbols of the
.in
grammar. (i.e. the elements of Ʃ). So these nodes are called terminal
nodes.
iii. All other nodes are labelled with some non-terminal symbols of the
es
grammar (i.e. the elements of VN). These are called non-terminal
nodes.
iv. If the string w of the language generated by the grammar has a length
n, then there are n terminal nodes, arranged from left to right.
ot
A→a
B→b
48
S Context-free Languages
S S
S S
Figure 1.1
Derivation tree for string ab
Draw the derivation tree for a string aabbaa using following Grammar G.
G = (VN, Ʃ, P, S), where
.in
VN = (S, A) Ʃ = {a, b} and
P = S → aAS
es
S→a
A → SbA
ot
A → SS
A → ba
un
Solution:As Sis the start symbol, any string generated by the grammer will
be derived from S
m
So we will use
S → aAS.
Obviously we will not use S → a to start with as then we cannot create
anything other than a
Since we want to generate aabbaa. We should select a proper A-
production such that it generates a string beginning with a followed by
So we select
A → SbA
So we get
S→ aSbAS
S→ aabAS
49
Theory of Computation Now we want that A-production which results in a String that begins with
b followedby a. So we must choose A→ba.
So
S→ aabbas
Which then gives S→ aabbaa the required string. This is shown as below.
S→ aAS
S→ aSbAS by A → SbA
S→ aabAS by S → a
S→ aabbaS by A→ ba
S→ aabbaa by S→ a
The derivation tree is as shown Fig. 2.
S
.in
a s
es
A a
S A
ot
a b
un
b a
For the following grammar show the derivation tree for aaabbabbba.
m
P = S → AB│ bA
A → a │As│ bAA
B→ b │bS│ aBB
The derivation of the string is as follows
Start with S
→ aB
→ aaBB
→ aaaBBB
50
→ aaabSBB Context-free Languages
→ aaabbABB
→ aaabbaBB
→ aaabbabB
→ aaabbabbS
→ aaabbabbA
→ aaabbabbba
The derivation tree will be as shown in Fig.4.
S
a B
a B
.in
B b S
a B b A
es
B
b S a
ot
b A
un
a
m
51
Theory of Computation It is Crucial however to note that the ordering used does not matter the
generatedstring. e.g. a given string can be derived using either leftmost or
rightmost derivation.Consider the string ab and the above grammar again.
The two derivations are as shownbelow.
S→AB S → AB
S→aB S → Ab
S→aD S → ab
(a) Left most (b) Rightmost
As stated above, the ordering does not disturb the generated string.
However in manyapplications, it is Convenient to use leftmost derivation.
For the grammar,
S → aB 1bA
A → a│aS│bAA
.in
B → b│bS │aBB
Example:1Write leftmost and rightmost derivation for the string
es
aaabbabbba
Solution:
ot
Leftmost derivation
S→ aB
un
→ aabB
→ aaaBBB
m
→ aaabSBB
→ aaabbABB
→ aaabbaBB
→ aaabbabB
→ aaabbabbs
→ aaabbabbbA
→ aaabbabbba
Right most derivation
a→ aB
→ aaB
52
→ aaBbs Context-free Languages
→ aaBbbA
→ aaBbba
→ aaaBBbba
→ aaaBbbba
→ adabSbbba
→ aaabbAbbba
→ aaabbabbba
For the following grammar, give the leftmost and rightmost derivation for
the string
abaabb.
G = (VN, Ʃ, P, S), where
.in
VN =S. X = {a, b}
P = {S → X baa X
es
S → ax
X→Xa
ot
X→Xb
un
S→ X b aa X
→ Xa baa X
→ ab aa X
→ abaa Xb
→ abaaa X bb
→ abaa bb
Rightmost derivation is as follows
S→ Xbaa X
→ Xbaa Xb
→ XbaaX bb
→ Xbaa blb
53
Theory of Computation → Xa baa bb
→ ab aa bb
P = S → aS │Sa │a
Now, consider a string a4 (i.e. aaa). This string can be derived in
thefollowing different ways as shown in following figure.
S S S S
.in
a a a a
S S S S
es
a a a a
S S S S
ot
a a a a
un
Example: 1
We will now discuss the best example of an ambiguous grammarthat rises
in the context of compiler design. Consider the followgrammar.
P = {S→ S + S│S + S│ d
This grammar is for generating arithmetic expressions made up of
operators + and *.Undertake the terminal d stands for digit. Now consider
a string 5 + 6 * 7. We knowthatexpression of a grammar. But the string
can be derived in two differentshown in following Figure and so the
grammar is ambiguous. Therefore, the grammar is ambiguous.
54
Context-free Languages
S S
S + S S * S
S S * S
S + S
d d
d d d
Fig. Two ways to derive a string d + d*d
.in
1) Each variable and each terminal of CFG should appear in thederivation
of at least one word in L (G)
2) There should not be productions of the form A→ B, where 'A' and'B'
are both non-terminals.
es
Simplification of Grammar
Method 1. Removal of Useless Symbol:
ot
55
Theory of Computation Examples: Simplification of Grammar
i. S → AB │a S
A →a A
S→a
A→a
Step: 2 A is Useless
.in
S → a
ii. S → AB │ BC
es
A → aAa │ aAa
B → Bb │b
ot
D → a D │d
un
Step 1 – C Useless
S → AB
m
A → aAa │aAb
B → Bb │ b
D → d D │d
Step 2 - A & d ARE Useless
A whole grammar is useless
A is useless because no sentence will be derived from D
D is useless because it is not been used in any derived process.
Method 2. Elimination of unit production
A production of the form 'A → B' where, 'A' and 'B' both arenon-
terminals, are called ds. Unit productions. All other productions(including
ϵ - productions) are Non unit productions.
56
Context-free Languages
Elimination Rule:
For every pair of non-terminals 'A' and 'B',
i) If the CFG has a unit production of the form 'A → B' or,
ii) If there is a chain of unit productions leading from 'A' to 'B' such as,
A => X1 => X2 =>…..... => B
Where, all Xis (i > 0) are non- terminals, then introduce newproduction (s)
according to the rule stated as follows:
"If the non-unit productions for 'B' are,
B → α1 │ α2│...
Where, ‘α1, α2’ ... are all sentential forms (not containing only onenon-
terminal)
.in
then, create the productions for 'A' as,
A → α1, │α2│…….
es
Single capital letters replaced with its production
Examples: Simplification of Grammar
ot
1) A→B
B → a │b
→ A→B
un
A → a │b
m
2) S → Sool │ F
F → S ││ O │F
T → OS l │ l │ lSlO
→ S → SOOl│F
F → SllO │OSl │ l│lSlO
3) S → A │bb → S → A │bb
A → B │b A→S│a│b
B → S │a s → S │a │ b │bb
S → a │b │bb
57
Theory of Computation
.in
not add that to the final grammar.
Examples: Simplification of Grammar
i. S → a S a │b S b │ϵ
es
→ S → a S a │ b S b │ aa │ bb
ot
ii. S → AB
A → A │BB │ Bb
un
B→b│aA│ϵ
→ S → AB │ A
m
A → SA │BB │ Bb │b │ B │ S
B → b │aA│ a
iii. S → ABA
A → aA │ ϵ
B → bB │ ϵ
→ S → ABA │AA│ BA│ AB│ B │A│ ϵ
A → Aa │ a
B → bB │ b
S → ABA│ AA │BA │AB│ B │A
A → aA│ a
B → bB│ b
58
4.6 NORMAL FORMS Context-free Languages
.in
Note the difference between the CNF and the form of productions we
came across in the previous section. The CNF the RHS of each of the
production will either contain exactly two nonterminal or a single
es
terminal, while as in the previous form, the RHS of each of the production
will either contain string of nonterminal or a single terminal. Thus, CNF is
more restricted than the previous one.
ot
Also, that any context-free language that does not contain ϵ as a word has
a CFO in CNF that generates exactly it. However, if the CFL contains ϵ,
then when we convert the CFG into CNF, the ϵ word drops out of the
un
59
Theory of Computation Now all the productions except S → ASA and S → BSB are in required
form. Toconvert these productions into the required form we add
additional non-terminals, say
R1, R2………etc
So we get
S→ AR1
S→ AA
S→ BB
S → BR2
S→ a
S→ b
A→a
.in
B→ b
R1 → SA
es
R2 → SB
The grammar is now in CNF.
ot
A → bAA│ as│a
B→ aBB │ aS│b
m
60
So the grammar in CNF will be, Context-free Languages
S → YA│XB
A → YR1│XS│a
B → XR2 │YS│b
X→a
Y→b
R1 → AA
R2 → BB
Example 3: Convert the following CFG into CNF.
S → aaaaS │ aaaa
Which generates the language a4nfor n = 1, 2, 4……
.in
Solution: In the first step we get
S→ AAAAS
es
S → AAAA
A→a
ot
Now,
S → AR1
un
R1 → AR2
R₂ → AR4
m
R4→ AS
S → AR4
R4 → AR5
R5 → AA
A→a
The grammar is now in CNF.
4.6.2 Greibach Normal Form:
We will now look at one more normal form of the grammar.
61
Theory of Computation Definition:
If each production in a CFG is of the form
A → aB, where
a is a terminal andB is a string of non-terminals (possibly empty), then the
grammar is in GreibachNormal Form (GNF).
For example, the following grammar is in GNF.
S → bA │ aB
A → bAA│aS │a
B → aBB │bS│b
All the productions start with a terminal on RHS and followed by a
string,non-terminals (sometimes ε).
Before looking at how to convert a given grammar into GNF, we have to
.in
discuss two important auxiliary results, which are helpful for converting a
grammar to GNF.
Lemma: 1: If A → Bγ is a production, where A and B are non-terminals
es
and they are B- production of the form
B → β1 │ β2│……. │βs then
We can replace the production A → Bγ by
ot
A → Bi γ │1 ≤ і ≤ S
For example, take into consideration following grammar
un
A → Bab
B → aA │ bB │ aa │ AB
m
.in
conversion purpose) respectively, the productions will be then
A1 → A2 A2 │α
A2 → A1 A1 │b
es
and
We leave A2 → b as it is in the required form.
ot
A2 → aA1
i.e. by replacing the first A1 on RHS of A2 → A1A1 by definition of A1.
Now the Production A2 → aA1 is in required form. But we need to use
m
Lemma 2 for
A2→ A2A2A1 as it is of form A → Aα.
Apply Lemma 2 to the productions of A2. A2 productions are
A2 → A2 A2 A1
A2 → aA1
A2 → b
Here, β1 = αA1, β2 = b, α = A2 A1
So we have now by adding new non-terminal.
A2 → aA1│b
A2 → aA1 Z₂│bZ2
Z2 → A₂ A1
Z2 → A2 A1Z2
63
Theory of Computation Now all A2 productions are in required form.
Now we will save to consider the A1, production,
A1 → A2A2│a
Out of these A1 → a is in required form.
So consider, A1 → A₂A₂
Applying Lemma 1, we get
A1 → aA1 A2│ bA₂│ aA1 Z2A2│ bZ2 A2
So adding to this list the A1 → a production, we have retained all A1
productions and they are
A1 → aA1 A2│bA2│ aA1 Z2, A2, │bZ2A2│ a
Now we amend Z2 productions. Applying lemma to Z2 productions we get
Z2 → aA1 A1│ bA1│aA1 Z2 A1│ bZ2 A1
Z2 → aA1 A1 Z2│bA1 Z2│aA1 Z2 A1 Z2│bA1, Z2
So the grammar in GNF will be
.in
G’ = (A1, A2, Z2,}, {a, b}, P’, A1)
P’ =
es
Where
A1 → a│aA1 A2│bA2│aA1 Z2 A2│ bZ2 A2
ot
A₂ → aA1│b│ aA1 Z2 │b Z₂
Z2 → aA1 A1│bA1│aA1 Z2A1│bZ2A1
un
64
Lemma: 1 (The pumping lemma for context-free languages): Context-free Languages
4.8 SUMMARY
Context-free Languages
It is language generated by CFG means Context Free Grammar;
.in
A phrase structure grammar is denoted by a quadruple of the form,
G = (V, T, P, S)
es
Closure Properties of CFL:
i) CFL’S are closed under union.
ii) CFL’S are closed under concatenation.
iii) CFL’S are closed under kleene closure and positive closure.
ot
Ambiguity of Grammar:
A CFG is called ambiguous if for at least one word in the language that it
un
CFG simplification
Method 1. Removal of Useless Symbol:
Method 2. Elimination of unit production
Method 3. Removal of ϵ production:
4.9 REFERENCES
1. Theory of Computer Science, K. L. P Mishra, Chandrasekharan,
PHI,4rd Edition
2. Introduction to Computer Theory, Daniel Cohen, Wiley,2ndEdition
3. Introductory Theory of Computer Science, E.V. Krishnamurthy,
Affiliated East-West Press.
4. Introduction to Languages and the Theory of Computation, John E
Martin, McGraw-Hill Education
65
Theory of Computation 4.10 REVIEW QUESTIONS:
1. Define following terms.
a) Derivation Tree
b) CFG
2. What is Context Free Language (CFL)?
3. Find the Context Free Language (CFL) associated with the CFG.
S → aB | bA
A → a | aS | bAA
B → b | bS | aBB
4. Construct CFG for
L= {a m b n c m | n, m ≥ 1}
5. Remove ambiguity from following grammars.
a) S → aS | Sa |ϵ
.in
b) S → SS | AB
A → Aa | a
es
B → Bb | b
6. Draw Derivation Tree for a substring “001100”.
ot
S → aAab | Aba
A → aS | bB
m
B → ASb | a
66
5
PUSHDOWN AUTOMATA
Unit Structure
5.0 Objectives
5.1 Introduction
5.2 Definition of PDA
5.2.1 Elements in PDM
5.2.2 Model of Pushdown Automaton
5.2.3 Pictorial Representation for PDA
5.2.4 Construction of PDA
.in
5.3 Acceptance by PDA
5.3.1 PDA acceptance by Final State
es
5.3.2 PDA acceptance by Empty Stack
5.4 PDA and CFG
ot
5.5 Summary
5.6 References
un
5.0 OBJECTIVES
m
5.1 INTRODUCTION
In this chapter we are learn the concept of the PDA. In case of FSM, we
have seen that it does not have memory to remember arbitrarily long
sequences of the input. So PDM (Pushdown Stack-Memory Machine) is
more powerful than FSM (Finite Automata Machine) and more
capabilities. FSM accept only the regularlanguages and PDM is consider
as a CFL-acceptor or CFL-recognizer. While FA is a mathematical model
67
Theory of Computation of FSM likewise PDA (Push-down Automata) is mathematical model of
PDM.
.in
A PDM is a collection of eight elements described as follows:
1. An input alphabets. (Ʃ)
2. An input tape (bounded on one end and unbounded or infinite in
es
theother direction). Initially, input string is written on the tape with
restof the tape blank.
3. An alphabet of stack symbols. Γ
ot
.in
es
5.2.3 Pictorial Representation forPDA:
ot
state for everyPDA and either 'accept or reject would be the final halt state
dependingon the input, whether machine has accepted it or rejected it
"Read stateis a conditional block and represented like that because
depending on whatsymbol read, the machine could go to different states.
m
69
Theory of Computation
Start Start the Process
.in
Push a < letter >i.e some symbol on
es
to block and proceed.
Push < letter >
ot
Or
Push < letter >
un
m
70
Pushdown Automata
Example: 1
Construct PDA recognizing the language accepted by the DFA given
in following figure.
b a
a
- +
b
An Example DFA
Solution:
As we know the DFA given in above figure is the acceptor for the regular
.in
language represented by regular expression.
b * a a* (b b* a a*)
We can construct the PDA equivalent to given DFA as shown in
es
following figure.
ot
Start
b
un
b
a
b
m
Read Read
1 2
Accept
b Reject a
71
Theory of Computation moves to ‘accept’ state as shown. Let us simulate the working of the PDA
for the strings ‘bbaaba’ and ‘baaabab’.
Simulation for string bbaaba.
.in
es
Thus the string ‘bbaaba’ is accepted by the designed PDA
ot
72
Q.2 Construct PDA recognizing the language accepted by the DFA Pushdown Automata
given in the following figure.
An example DFA
PDA can be constructed as shown in above diagram. We can see that state
‘Read1’ of PDA is analog our to state ‘1’ at given DFA. Similarly, ‘Read2’
is analogous to state ‘2’ and ‘Read3’ is with state ‘3’ of the given DFA.
Obviously ‘Read1’ and ‘Read2’ are non-final states and reading blank ‘b’
indicating end of input string in that state causes machine to move to the
reject indicating the input string given is rejected by the PDA.
.in
es
ot
un
.in
.
.
es
R
Top of Stack
ot
74
i.e. Pushdown Automata
.
.
B Top of Stack
R
ii. After we read 1st 'a' we don't change the state, as we have to read
next all 'a's and add 'B' to stack. The variation between 1st ‘a’ and
remaining all ‘a’s can be made by observing at top of stack (TOS)
For 1st ‘a’ - TOS is R
For residual ‘a’s - TOS is B
.in
We write transition for residual a's as
iii. Now in the same state, if 'b' befalls on input tape i.e. the situation is
δ(q0, b, B)
un
Then we have to pop one 'B' plate from stack which matches the current 'b'
with beforeadded 1 'a' i.e. (qı ,ϵ ).
m
δ (qo, b, B) → (q1,ϵ)
b. δ (q1, b, B) → (q1, ϵ)
Here we pop all 'B's for all 'b's occurring in input tape and be in self loop
as the same actionis to be recurrent for (n-1) times so no need to change
.in
the state.
c. (Step iii)
δ (q1, ϵ, B) → ERROR
es
state
vi. After step (v) is over, we may have the condition that current state is
q1 top of stack is R andinput symbols can be a, b, or ϵ
ot
a. If (step i)
b. If δ (q1, ϵ ,(step
R) Accept
ii)
un
state
δ(qı, b, R) ERROR
c. if δ(qı,(step
a, R) iv)
→ ERROR
state
state
m
Where, δ is
δ (q0, a, R) =(q0, BR), δ (q0, b, R) = ERROR,
δ (qo, ϵ, R) ERROR, δ (qo, a, B) = (q0, BB),
δ (qo, b, B) (91, E), δ (qo, ϵ, B) = ERROR,
δ (q1, a, B) ERROR, δ (q1, b, B) = (q1, ϵ),
δ (q1, ϵ, B) ERROR, δ (q1, ϵ, R) = ACCEPT,
δ (q1, b, R) ERROR, δ (q1, a, R) = ERROR
76
1. Construct PDA for the language Pushdown Automata
n n
L = {a b │ n ≥ 0}
Solution:
The language set for L
L ={ɛ, ab, aabb, aaabbb....)
This language is same as L = {anbn │n ≥ 1}
In example 2 except the extra string ϵ in this example.
So the same 8 can be written as in 2 example except the transition which
accepts 'ϵ' as a string andgoes to error state in 2 example, so in its place
that transition, we have to write the transition as
.in
PDA can be given as
M = ({qo, q1}, {a, b, c}, δ, q0{q1})
es
Where, & is
δ (q0, a, R) = (q0, BR), δ (q0, b, R) = ERROR,
ot
77
Theory of Computation 5.3 ACCEPTANCE BY PDA
PDA accepts its input by consuming it and entering an accepting state. We
call this approach “acceptance by final state”.There is a second approach
to defining the language of PDA, we call it. Language “accepted by empty
stack”, i.e. the set of strings that cause the PDA to empty its stack, starting
from initial ID.
5.3.1 PDA acceptance by Final State:
The way of defining a language accepted is similar to the way a finite
automaton receives inputs. Thatis, we designate some states as final states
and define the accepted language as the set of all inputsfor which some
choice of moves causes the Pushdown automaton to enter a final state,
Formal Definition: Language acceptance by Final State
Let P = (Q, Ʃ,Γ, δ, q0, Z0, F) be a PDA then L(P), the language accepted
by P by final state is
.in
{w │(q0, w, Z0) * (q, ϵ, α)} P
For some state q in F and any stack string a. That is, starting in the new ID
with w waiting on theinput, P consumes w from the input and enters an
es
accepting state. The contents of the stack at thattime are irrelevant.
Examples:
ot
78
Pushdown Automata
.in
es
5.3.2 PDA acceptance by Empty Stack:
To define the language known to be the set of all inputs for which some
ot
order ofmoves causes the pushdown automaton to empty its stack. This
language is referred to as thelanguage recognized by empty stack.
Formal Definition: Language accepted by Empty Stack
un
79
Theory of Computation 1. Consider the language in above example and consider the PDA in
thatexample.This example never empties the stack.
N(P).
Instead of transition
δ (q1, ϵ, Z0) (q2, Z0) we add
Now P pops the last symbol off its stack as it accepts and L(P) = N(P) =
Lwwr.
Consider the same string 1111.
.in
es
ot
un
m
80
iii. The languages which are accepted in empty stack by some Pushdown Automata
PDA.
Figure
Conversion of a Context FreeLanguage (in GNF) to Push down
Automata (PDA)
Theorem:
.in
If L is a context free language, then we can construct a PDA a accepting
L by empty stack
i.e. L = N(A).
es
We can construct A by making use of Productions in G.
Step 1: Construction of A
ot
A = ({q), ∑, VN∪ ∑, δ, q, S, ɸ)
where, transition functionδ is defined by the following rules:
m
81
Theory of Computation ThenA can empty the PDS on application ofi/p string w. The first move of
A is by a ε -move corresponding to S →u1 A1 α1. The PDA erasers S and
stores u1 A1 α1, then using R2, the PDA erasers the symbols in ul by
processing a prefix of w. Now the topmost symbol in PDS is A1.
Once again by applying the ε -move corresponding to A1 → u2A2 α2, the
PDA erases A2 and stores u2A2 α2 above α1. Proceeding in this way,
thePDS empties the PDS by processing the entire string w.
Example 1:
Construct a PDA A equivalent to the following context free grammar:
S → OBB, B → OS | 1 | 0.
Test whether 0104 is in N(A).
Solution:
A is defined as:
.in
({q}, {0, 1}, {S, B, 0, 1}, δ, q, S, ɸ)
The transition functionδ is
es
R1: δ(q, 0, S) = (q, BB)
R2: δ(q, 0, B) = {(q, 0S), (q, ε)} and δ(q, 1, B) → (q, S)
ot
82
Solution: Pushdown Automata
.in
δ(q, a, a) = {(q, ∈)}
Machine).
m
83
Theory of Computation If S a ϵ then the conversion is given as
δ (q0, a , S) (q0, ϵ)
5.6 REFERENCES:
1. Theory of Computer Science, K. L. P Mishra, Chandrasekharan,
PHI,3rd Edition
2. Introduction to Computer Theory, Daniel Cohen, Wiley,2nd Edition
3. Introductory Theory of Computer Science, E.V. Krishnamurthy,
Affiliated East-West Press.
.in
4. Introduction to Languages and the Theory of Computation, John E
Martin, McGraw-Hill Education.
84
Unit III
6
LINEAR BOUND AUTOMATA
Unit Structure
6.0 Objectives
6.1 Introduction
6.2 Linear Bound Automata
6.3 The Linear Bound Automata Model
6.4 Linear Bound Automata and Languages
6.5 Review Questions
.in
6.6 Summary
6.7 References
es
6.0 OBJECTIVES
ot
6.1 INTRODUCTION
85
Theory of Computation 6.2 LINEAR BOUND AUTOMATA
.in
Halt (LBA) = {< M,w > |M is an LBA and M halts on w} is decidable.
An LBA that stops on input w must stop in at most α(|w|) steps.
es
Membership problem
The membership problem is solvable for linear bounded automata.
ot
machine.
Definition: A Non-deterministic Turing Machine with a finite length tape
space fill by the input is called Linear Bound Automata(LBA).
LBA is defined as :
M=(Q,∑, Г,δ,q0,ML,MR,,F)
Where,
Q is a nonempty finite set of states
Figure 6.1
.in
ML and MR are boundaries for a tape. ML is entered in leftmost end of the
input tape and avoids the Read/Write head from getting off the left end of
the tape. MR is entered in rightmost end of the input tape and avoids the
es
Read/Write head from getting off the right end of the tape. Both end
markers should be at their respective ends, and Read/Write head should
not write any other symbol over both end-markers.
ot
Examples:
1) {an bncn/ n ≥ 1}
un
87
Theory of Computation Proof :
If L is a CSL, then L is accepted by some LBA.
Let G = (N, Σ, S, P) be the given grammar such that L(G) = L.
.in
sentential form is longer than w, LBA halts without accepting.
Productions that can erase everything but the unmodified copy of the
string, provided that the simulated moves of M applied to the other
copy cause M to accept.
Linearly bounded memory machine:
The linearly bounded memory machine is similar to a Turing machine,
except that it has, instead of a potentially infinite tape forcomputation,
only the portion of the tape containing the input string plus two squares on
the tape to hold the end markers. Such a restriction reduces the machine's
88
power to recognize certain types of strings. It has been shown that even Linear Bound Automata
when the length of the tape is increased as a linear function of the length
of the input string, the computational ability of the machine remains the
same. Hence, such a machine is called a linearly bounded memory
machine. It recognizes a class of languages known as context-sensitive
languages.
.in
compiler languages lie between context-sensitive and context-free
languages.
A linear bounded automaton is a non-deterministic Turing machine which
es
has a single tape whose length is not infinite but bounded by a linear
function of the length of the input string.
ot
Machine with only one tape and having the length same as input string.
Example:
m
ID of LBA
89
Theory of Computation In LBA, the ID is denoted by (q, w, k) where q ∈ Q, w ∈ Г and k is some
integer between 1 and n.The transition of the IDs is similar except that if k
changes to (k – 1), then Read/Write head moves to the left and if move to
(k + 1) then head moves to the right.
Languages accepted by LBA is:
The language accepted by LBA is defined as the set :
{w∈{∑ - {ML, MR} )* | (q0, ML, w,MR, 1) * ├ (q, α, i) for some q ∈ F and
for some integer i between 1 and n.
First it start at initial state with Read/Write head reading the left end
marker (ML), M halt over the right-end marker (MR) in final state,
otherwise w is rejected.
.in
The production rules for the generative grammar are constructed as in the
case of TM. The following additional productions are needed in the case
of LBA:
es
aiqf MR → qfMR, for all ai∈ Г
ML qf MR → MLqR , ML qf → qf
ot
90
2 Context-free A→ α Linear Bound Automata
Pushdown
1 Context-sensitive α →β Linear-bounded
enumerable(α, β ∈(V ∪ ∑)
(unrestricted) α contains a variable)
Example
.in
es
Example 1: Construct an LBA for {anbncn | n ≥ 1}
ot
Solution:
The tape alphabet for an LBA,is finite, but it may be considerably bigger
un
than the input alphabet. So we can store more information on a tape than
just an input string or related sentential form.
Consider following,
m
let, Γ = {a, b, c, a, b, c}, and Σ = {a, b, c}. Occurrences of bold letters can
serve as markers for positions of interest.
To test whether an input string has the form anbncn
1) Scan string to ensure it has form akbmcnfor k, m, n ≥ 1.
Along the way, mark leftmost a, b, c.likeaaabbbccc.
2) Scan string again to see if it’s the rightmost a, b, c that are marked.
If yes for all three, ACCEPT.
If yes for some but not all of a, b, c, REJECT.
3) Scan string again moving the ’markers’ one position to the right.
Like aaabbbccc becomes aaabbbccc. Then Go to 2. All this can be done
by a
91
Theory of Computation LBA.
.in
If finally only capital letters remain between the border ♯ signs, then
the automaton accepts (the input).
Formally, letM=(Q,∑, Г,δ,q0,ML,MR,,F)
es
LBA = ({q0, q1, q2, q3, q4, qf}, {a,b,c}, {a,b,c,A,B,C},δ, q0, ML, ,MR, {qf})
be a deterministic LBA, where δ consists of the next transitions:
ot
1. δ (q0, MR) = (qf, MR, Halt) – the empty word is accepted by LBA.
2. δ (q0, a) = (q1, A, Right) – the first (leftmost) a is rewritten to A and
un
92
12. δ (q3, b) = (q3, b, Left) – by moving the head of the automaton to Linear Bound Automata
the left.
13. δ (q3, C) = (q3, C, Left) – capital letters C,B are skipped in state q3
14. δ (q3, B) = (q3, B, Left) – by moving the head of the automaton to
the left.
15. δ (q0, A) = (q3, A, Right) – the head is positioned after the last A
and the state is changed to q0.
16. δ (q4, B) = (q3, B, Right) – if there is a B after the last A the state is
changed to q4.
17. δ (q4, B) = (q4, B, Right) – in state q4 capital letters B and C are
skipped
18. δ (q4, C) = (q4, C, Right) – by moving the head to the right.
19. δ (qf, MR) = (qf, MR, Accept) – if in q4 there were only capital
letters on the tape, LBA accepts.
.in
6.5 REVIEW QUESTIONS
es
1. Define Linear Bound Automata.
2. Write note on ID of LBA.
ot
6.6 SUMMARY
1. Linear Bound Automata design to accept context-sensitive languages.
m
6.7 REFERENCES
93
7
TURING MACHINES
Unit Structure
7.0 Objectives
7.1 Introduction
7.2 Turing Machine Definition
7.3 Representations
7.4 Acceptabilityby Turing Machines
7.5 Designing and Description of Turing Machines
7.6 TuringMachine Construction
.in
7.7 Variants of Turing Machine
7.8 Review Questions
es
7.9 Summary
7.10 References
ot
7.0 OBJECTIVES
un
7.1 INTRODUCTION
Turing machine (TM) was invented by Alan Turing in Turing 1936, which
is big achievement in the field of finite-state computing machines. Initially
was specially design for the computing of real numbers.TM is very
powerful than Linear Bound Automata. Today this machine use as a
foundational model for computability in theoretical computer science.TM
can effectively represent its configuration using a simple notation like as
ID's of PDA.TM has a infinite size tape, use to accept Recursive
Enumerable Languagegenerated by Type-0 Grammar. The machine can
read/ write and also move in both (left and write) directions. The machine
producesdesired output based on its input.
94
Why Turing Machines? Turing Machines
They can do everything a computer can do and vice versa. But takes a
lot more time. Is not practical and indeed its not what is implemented
in today’s computer.
.in
infinite length tape and tape is divided into cells on which input is given. It
has a head which reads the input tape. A state register stores the state of
the Turing machine. After reading an input symbol, it is replaced with
another symbol, its internal state is changed, and it moves from one cell to
es
the right or left. If the TM reaches the final state, the input string is
accepted, otherwise rejected.
ot
95
Theory of Computation 7.3 REPRESENTATIONS
.in
and γ has all the remaining symbols of input string.
Example: Consider following TM. Obtain its ID.
es
ot
un
Figure 7.1
Current symbol under Read/Write head is a7.
m
∴ The ID is
Figure 7.2
96
Moves in Turing machine Turing Machines
The δ(q, xi) changes the ID of TM. This change is called move.
If δ(q, xi) = (P, y, L)
Take input string x1, x2, ….Xn.
Currentsymbol under Read/Write head- xi
ID before processing symbol xi
x1x2…….xi-1 q xi+1…..Xn
ID after processing symbol xi
x1x2……. xi-2 P xi-1 y xi+1…..Xn
∴It is represented as
x1x2…….xi-1 q xi…..Xn├ x1… xi-2 P xi-1 y xi+1…..Xn.
.in
If δ(q, xi) = (P, y, R)
Then the ID become:
es
x1x2…….xi-1q xi…..Xn├ x1x2… xi-1 y P xi+1 …..Xn.
Thus Ii ├ Ikdefine the relationship between IDs.
ot
ii)Transition table:
a) The transition function δ
Q x Ґ → Q x Ґ x {L,R}
States Q stored in table rows and table column shows each of the tape
symbols Ґ.
b) Each pair (Q , Ґ ) is represented by a triple (Q, Ґ, {L,R}) as:
If δ (qi, a) = (α, β, γ) then we write (α, β, γ) under qith row and ath column.
In transition table we get entry as:
State qi on input symbol 'a' goes to or changes to state ' γ ', by replacing the
input symbol 'a' by ' α' and moves the tape head one cell in direction of ' β'.
97
Theory of Computation iii)Representation by Transition Diagram
a) Every state implies to one vertex.
b) Transition of states represented by directed edges.
Here, the directed edge from state qi to qj with label (α, β, γ) it indicates transition
δ(qi,, α) = (qi, β, γ)
The symbol α will replaced with β and tape head moves to L , or R direction
according to the value ofγ.
Every Edge in the transition diagram is represented by 5-tuple (qi, α, β, γ, qj).
.in
A language isaccept by Turing Machines if it enters into a final state for
any input string w. If input not present in the language TM enters it into a
rejecting state. A recursively enumerable language is which isgenerated
es
by Type-0 grammar is accepted by a Turing machine. The set of languages
accepted using a turing machine is often called Recursively Enumerable
languages or RE languages. Recursive means for any number of times
ot
repeating the same set of rules and enumerable means a list of elements.
Formal Definition ofTuring Machines,
un
M = (Q, ∑, Г, δ, q0, B, F)
L(M) is the set of strings w ∈ ∑*, such that q0w ├ α p β for some state p
in F and any tape strings α and β. The TM ‘M’ does not accept w if the
m
98
Hence, Turing Machines
Α BRq2 BRq1
.in
scanned symbols. It can be remembering this by going to the next unique
state.
ii) By changing the state if there is a change in the written symbol or when
es
there is a change in the movement of Read/Write head we can minimize
the number of states.
7.5.2 Description of Turing Machines:
ot
ii) Near the end of alphabet as....X, Y, Z, Capital letters are used for tape
symbols that mayor may not be input symbols.
iii) B is generally represents Blank symbol.
m
iv) At the end of alphabet lower case letters are strings of input symbols.
v) Greek letters are used for strings of tape symbols.
vi) Letterslike q, p and nearby letters are states of machine.
99
Theory of Computation i) We use 2 tape symbols X and Y for a and b respectively.
ii) We replace a by X. Move right replace first b found by Y. move right find last
c replace it Blank `B'.
iii) Repeat step 2 until all a's, b's and c's. If no more a's, b's and c's are
present – Accept otherwise Reject the string.
Replacement Logic:
Mark 'a' then move right.
Mark 'b' then move right
Mark 'c' then move left
Come to far left till we get 'X'
Repeat above steps till all 'a', 'b' and 'c' are marked
At last if everything is marked that means string is accepted.
Let’s consider the string,
Direction aabbccB (String)
.in
→ XaYbccB
← XaYbcBB
es
→ XYYcB
← XYYBB
ot
→ XYYBA accept
Representation by Transition table method
un
A B c X Y Z
q3 (q4, B, L)
q6 Accept state
100
7.7 VARIANTS OF TURING MACHINE Turing Machines
.in
es
ot
Figure 7.3
un
model.
Figure 7.4 (6.3)
Here the input string is a1, a2,a3, ... an. Whenthe input string placed on tape,
it is loaded with all blank symbols (B) to the left of a1 and to the right of
an. So if q0 is the initial state of the TM, ID corresponding to the initial
state will be q0, a1, a2, s….. an,B.
3) MultitapeTuringMachine(MTT):
For every Multitape Turing Machine there is an equivalent single tape
Turing Machine. In MTT number of tapes and read/write heads increased.
All the indivisual tape will have there own respective tape heads. For this
assumption is that all the tapes are two way infinite. It contains finite
control with k number of heads.
101
Theory of Computation
Figure 7.4
Depending upon the state of finite control, in single move the symbols
scanned by each of the tape heads, the machine can
a) Change the state.
b) Print a new symbol on each of the cells scanned by its tape head.
c) Then independently move each tape head, one cell to the left or
.in
right or keep it stable.
4) Single tapeTuring Machine:
es
A Turing Machine consists of only one tape with infinite length on which
read and write head can be performedoperation. The tape consists of
infinite cells on which each cell either contains input symbol or a special
ot
Figure 7.5
5) Non-deterministic Turing Machine(NTM):
Non-deterministic TM plays an important role in FAs and PDAs. It is
convenient but not essential in caseofFA.
Deterministic Turing machines have enough computing power that
nondeterministic fails to add any more. Non-deterministic TM differs from
deterministic TM, we have seen earlier, in the function δ, such that for
each state q and tape symbol X, δ (q, x) is a set of triples like,
102
Turing Machines
.in
The existence of other computations that halt in non-accepting states or
fail to halt altogether is irrelevant.
es
Language Acceptedby NTM
The language accepted by a machine is the set of strings accepted by the
M as mention in above point .
ot
103
Theory of Computation Suppose the string is ababbabaΔ. The simulation for ababbabaΔ can be
shown as follows:
Now, we will see how this Turing machine will work for ababbabaΔ.
Initially, state is q0 and head points to a as:
.in
We will move left and check if it is a:
es
ot
104
Move right up to Δ in search of b as: Turing Machines
.in
es
We will move left and check if it is a, then replace it by Δ as:
ot
un
105
Theory of Computation Replace b by * and move right up to Δ as:
.in
es
Go to HALT state
ot
106
Solution: Turing Machines
Logic for 1's complement
1. Scan input string from left to right
2. Convert '1' into '0'
3. Convert '0' into '1'
4. When BLANK is reached move towards left(i.e.start of input
string).
Consider, TAPE movement for string "1010111"
Sequential explanation of TAPE movement
1. Input is given as "1010111" (scan string from left to right)
2. Convert '1' into '0' and move one step right
3. Convert '0' into '1' and move one step right
4. Convert '1' into '0' and move one step right
5. Convert '0' into '1' and move one step right
.in
6. Convert '1' into '0' and move one step right
7. Convert '1' into '0' and move one step right
es
8. Convert '1' into '0' and move one step right
When BLANK (in right) is reached, string is finished. So move to start of
string (optional).
ot
107
Theory of Computation Let,
1's complement is written into the TAPE in place of input string.
Input String : 1010111
Output String : 0101000
State Transition Diagram
We have designed state transition diagram for 1's complement as follows:
1. Replace '1' with '0' and vice versa.
2. When BLANK is reached move towards left
3. Using state 'q2' we reach start of the string.
4. When we reach to BLANK in left we move one step right to point start
of string.
5. qf is final state
.in
es
Example 3:
ot
Logic:
we will convert a 0 to x and 1 to y. After continuously doing it a point is
reached when all 0’s and 1’s has been converted into x and x respectively.
Now, we are on the midpoint of the string.
Now, convert all x's and y's on the left of the midpoint into 0's and 1's.
Now the first half the string is in the form of 0 and 1. The second half of
the string is in the form of x and y.
Now, again start from the beginning of the string. If you have a 0 then
convert it into x and move right till reaching the second half, here if we
find x then convert it into a blank(B). Then traverse back till find an x or a
x. We convert the 0 or 1 at the right of it into x or y respectively and
correspondingly, convert its x or y in the second half of string into a
blank(B).
108
Continue this till converted all symbols on the left part of the string into x Turing Machines
and y and all symbols on the right of string into blanks. When one part is
completely converted but still some symbols in the other half are left
unchanged then the string will not be accepted. If we did not find an x or y
in the second half for a corresponding 0 or 1 respectively in the first half.
Then also string will not be accepted.
State Transition Diagram
.in
es
ot
un
Example 4:
m
.in
es
7.8 REVIEW QUESTIONS
ot
7.9 SUMMARY
110
3) Variants of TM: Turing Machines
i) Multitrack TM
ii) Two-way TM
iii) Multiple tape TM
iv) Single tape TM
v) Non-deterministic TM
7.10 REFERENCES
.in
es
ot
un
m
111
8
UNDECIDABILITY
Unit Structure
8.0 Objectives
8.1 Introduction
8.2 The Church-Turing thesis
8.3 Universal Turing Machine
8.4 Halting Problem
8.5 Introduction to Unsolvable Problems
8.8Review Questions
.in
8.9 Summary
8.10 References
es
8.0 OBJECTIVES
8.1 INTRODUCTION
112
Church's theorem, the Church-Turing thesis, and the creation of λ- Undecidability
calculus, or the Church λ operator.
There are various equivalent formulations of the Church-Turing thesis.
Formulation of the Church-Turing thesis is: “ Anything that can be
computed on any computational device can also be computed on a Turing
machine”.
or
“a problem can be solved by an algorithm iff it can be solved by a Turing
Machine”
or
“A common one is that every effective computation can be carried out by
a Turing machine. “
In the 1930s, two researchers– Alan Turing from England and Alonzo
Church from theUS – started analyzing the question of what can be
.in
computed. They used two different approaches to answer this question:
• Alan Turing, with hiscomputational analysis of Turing machines, what
es
we would now consider computer engineering and computer
architecture;
• On the other hand, Church focused on what can be described – i.e., on
ot
.in
capabilities like any other TM can do, this machine is called Universal
Turing Machine(UTM). It can simulate the behaviour of any TM, which
capable of running any algorithm.
es
This machine should have the capability of imitating any TM T, given the
following information in its tape:
ot
114
● Theorem2: There is a Turing machine UTM called the universal Turing Undecidability
machine that, when run on ⟨M, w⟩, where M is a Turing machine and w is
a string, simulates M running on w.
● The observable behavior of UTM is the following:
.in
To achieve this we assume that M is a standard TM which accepts by
halting. The action of UTM, U is represented by:
es
Let R(M) be the representation of machine M with string w.
ot
un
m
Figure 8.1
The output labeled 'loop' shows that the computation of U does not
terminate. If M halts and accepts input w, U does the same.
If M does not halt with w, neither does U. The machine U is called
universal since the computationof any TM M can be simulated by U.
In universal machineconstruction is for to design the string representation
of a turing machine. Because of the ability to encode arbitrary symbols as
strings over {0, 1}, we consider truing machines with input alphabet {0,
1} and tape alphabet {0, 1, B}. The states of turing machine are assumed
to be named {qo, q1 ...... qn} whereqo as start state.
115
Theory of Computation Formal Definition
Turing machine M is defined by its transition function(δ). A transition of a
standard turing machine is given as:
δ (qi, x) = [qj) y, d]
Symbol Encoding
0 1
1 11
B 111
q0 1
q1 11
.in
qn n+1
L 1
R 11
es
Consider the following TM:
ot
UTM Simulation of T
UTM can simulate T, one step at a time. Steps are as follows:
Step 1:Scan the square (cell) on the state area of the tape and read the
symbol that T reads and initial state of T.
Step 2: Move the tape over program area containing the description of T
find out the row pointed by the symbol, read in step 1.
116
Step 3: Find the column pointed by the statesymbol in which T resides Undecidability
and then read the triple (new state ,symbol to be replace and direction of
the tape movement) in the intersection of this column with the row found
in step 2.
Step 4: Move the tape to the appropriate cell in the data area, replace the
symbol, move the head in required direction, read next symbol and
finally read the state area, replace the state and scanned symbol. And go to
step 1.
Let end(z) denote the encoding of a symbol z. A transition δ (qi, x) = [qj,
y, d] isencodedbythestring end(qi) 0end(x) 0end(qj) 0end(y) 0end(d)
The components of transitions are separated by 0's. Two of consecutive
0’s are used to show separate transition. The beginning and ending of the
representation are designed by 3 0's.
Example: Let M = (Q, {0, 1}, {0, 1, B), δ, q1,B, {q2}) be a TM.
Assume Q = {q1, q2, .....qn}
.in
Let's consider 0, 1, and B as X1, X2, and x3 respectively.
D1 and D2are head movements for directions L and R respectively.
es
Consider the following move:
δ (qi, Xj) = (qk, Xl, Dm)
ot
Where each codei is of each above form, this code is beginning and ending
with 111. Each move of M is encoded by one of the codei. Each codeiis
separated by two consecutive 11’s. Thus the encoding will be unique.
Above imitation algorithm have problem. since here we have only one-
dimensional linear tape on the UTM, we require two-dimensional
description of T unless we use some coding to convert the two-
dimensional information into one-dimensional.
:. So we can design a UTM in following way.
117
Theory of Computation The Turing machine is described as a multitape. TM as shown:
.in
Figure 8.2
es
Operation of UTM is as follows:
i) Examine the input to make sure that the code for M is valid code for
ot
some TM. If not U halts without accepting. For invalid codes are assumed
to represent the TM with no moves, and such a TM accepts no inputs, this
un
action is correct.
ii) Initialize the second tape to contain the input w, in its encoded form.
i.e. for each 0 of w, place 10 on the second tape, and for each 1 of w, place
m
100 there.
(Blanks on the simulated tape of M, which are represented by 1000, will
not actually appear on that tape, all cells beyond those used for w will hold
the blank of U.
However, U knows that, should it look for a simulated symbol of M and
find its blank, it must replace that blank by the sequence 1000 to simulate
the blank of M)
iii) Place simulated 0,at thestart state of M, on the third tape and move the
head of U's second tape to the first simulated cell.
iv) For simulate the move of M, U search it on its first tape for the
transition of 0i 1 0j 1 0k 1 0l 1 0m where 0i is state on third tape, and 0j is
tape symbol of M which begins at the position on tape 2 scanned by U.
This is the transition of one M which create next one. U should:
118
a) Change the contents of third tape to 0k. Means it should able simulate Undecidability
the state change of M, for that change , U first changes all the 0’s on
tape 3 to blanks and then copies 0k from tape 1 to tape 3.
c) Now, move the head on tape2 to the position of the next 1 to the left or
right respectively, depending on weather m = 1 (move left) or m = 2
(move right) . Therefore U makes move of M to the left or to the right.
v) If there is no match in M for transition that matches the simulated state
and tape symbol, then in (iv), no transition will be found. Thus M halts
in the simulated
Configurationand U must do likewise.
vi) If M enters into its accepting state, then U accept.
.in
8.4 HALTING PROBLEM es
Before start to study Halting Problem, let’s learn some concepts:
Computability theory –It is the branch of theory of computation
which studies the problems of computationally solvable using
ot
problem that can be posed as a yes-no question for the input values.
Like is there any solution to a particular problem? The answer would
be either yes or no. Simply a decision problem is any arbitrary yes/no
question on an infinite set of inputs.
Turing machine –Now we know very well that, a Turing machine is
a mathematical model of computation. A Turing machine is a general
example of a CPU which controls all data manipulation work,
performed by a computer. Turing machine can be of halting as well as
non halting type and it depends on algorithm and input associated
with the algorithm.
Decidable language –
A decision problem P is said to be decidable (i.e., have an algorithm)
if the language L of all yes instances to P is decidable.
Example-
119
Theory of Computation (I) (Acceptance problem for DFA) Given a DFA does it accept a
given word?
(II) (Emptiness problem for DFA) Given a DFA does it accept any
word?
(III) (Equivalence problem for DFA) Given two DFAs, do they accept
the same language?
If answer to above examples is yes then language generated by above is
decidable.
Undecidable language –
A decision problem P is said to be undecidable if the language L of
all yes instances to P is not decidable or a language is undecidable if
it is not decidable. An undecidable language maybe a partially
decidable language or something else but not decidable. If a language
is not even partially decidable , then there exists no Turing machine
for such language.
.in
Halting is a situation in the program that tells us on certain input will
accept it and halt or reject it and halt and it would never go into an
infinite loop. Basically halt shows terminating the current program or
algorithm execution on particular input condition.
es
So can we have an algorithm which will tell us that is given program will
halt or not. In terms of Turing machine, will it terminate when run on
ot
way is to run the program and check whether it halts or not.We can solve
the halting problem question in such a way also: Given a program
written in some programming language(c/c++/java) will it ever get into
m
.in
Halting Problem representing as a Set
The conventional representation of decision problems is the set of objects
es
processing or satisfying the property in question:
The halting set:K = {(i, x) program i will eventually halt if run with input
x} represents the halting problem.
ot
Figure 8.3
121
Theory of Computation where,
e(M): Encoding of M
i.e. e(M) is for example a set of 5-tuples (q, X1, p, r, R) that describe the
TM.
.in
For example, ifA is the problem of finding some root of x4- 3x2+ 2 = 0
and Bis the problem of finding some root of x2- 2 = 0, then A is reducible
toB. As x2- 2 is a factor of x4-+ - 3x2+ 2, a root of x2- 2 = 0 is also a root
es
of x4-+ - 3x2+ 2.
Note:IfA is reducible to B and Bis decidable then A is decidable. If Ais
ot
Theorem
un
Proof :
We assume that HALTTMis decidable, and get a contradiction. Let M1
be the TM such that T(M1 ) = HALTTM and let M1halt eventually on all
(M, w).We construct a TM M2 as follows:
1. For M2, (M, w) is an input.
2. The TM M1 acts on (M, w).
3. If M1 rejects (M, w) then M2rejects (M, ,w).
4. If M1 accepts (M, w),simulate the TM M on the input string w until M
halts.
5. If M has accepted w, M2 accepts (M, w); otherwise M2rejects (M, w).
122
When M1 accepts (M, w) (in step 4), the Turing machine M halts on w. Undecidability
In this case either an accepting state q or a state q' such that δ(q', a) is
undefined till some symbol a in w is reached. In the first case (the first
alternative of step 5) M2accepts (M. w). In the second case (the second
alternative of step 5) M2 rejects (M, w).
It follows from the definition of M2that M2halts eventually.
Also,T(M2) = {(M, w) | The Turing machine accepts w} = ATM
This is a contradiction since ATM isundecidable.
.in
There are problems that cannot be solved by TMs and hence by computers
so the concept of Unsolvability comes in front.
Solving a problem can be viewed as recognizing a language. The
es
unsolvability can be seen in terms of language recognition.
Suppose that a language is acceptable but not decidable. Then given a
ot
string a TM that accept the language starts the computation. At any point
of time if TM is running, there is no way of telling whether it is in an
infinite loop or along the way to a solution and it needs more time.
un
123
Theory of Computation 5. Given two TMs, M1 and M2, over the same alphabet, do M1 and M2 halt
on the same set of input strings?
b) Unsolvable Problems about (General) Grammars:
Unsolvability results can also be shown about grammars, using
reductions.These
problems are unsolvable.
.in
c) Unsolvable Problems about Context-Free Grammars(CFG)
The following are undecidable:
es
1. Given a context-free grammar G, is L(G) = Σ∗ ?
2. Given two CFG G1 and G2, is L(G1) = L(G2)?
ot
.in
Theorem
A(REX) is a decidable language.
es
Proof:
The following TM P decides AREX.
ot
8.9 SUMMARY
125
Theory of Computation A transition of a standard turing machine is given as:
δ (qi, x) = [qj) y, d]
Where qi, qj∈ Q, x, y ∈ Г and d ∈ {L, R)
8.10 REFERENCES
.in
es
ot
un
m
126