Automataetl They Are Very Helpful
Automataetl They Are Very Helpful
Transition system: A Transition system is a Determine the initial and final states.
finite directed labeled graph in which each q0 & q1 q3
vertex(node) represents a state and the directed
101011 will be accepted.
edge indicates the transmission of a state and
111010 will be rejected.
the edges are labeled with input/output.
Properties of Transition Functions:
0/0 1/1
1/0 Property 1: δ(q, ∧) = q is a finite automata, This
q0 q1 means that the state of the system can be changed
0/0 only by an input symbol.
Fig. A Transition System. Property 2:- for all strings w and input symbol a
In Figure, the initial state is represented by a δ(q,aw) = δ(δ (q,a)w)
circle with an arrow pointing toward it, the final δ(q,wa)= δ( δ(q,w),a)
state by two concentric circles and the other This property gives the state after the automaton
states are represented by a circle. The edges are consumes or reads the first symbol of a string aw.
labeled by input/output (eq. 1/0 or 1/1).
Ex: prove that for any input transition function δ
For example, if the system is in the state q0 & the and for any two input string x and y.
input is 1 is applied, the system moves to state q1
δ(q, xy) = δ(δ(q, x), y)
as there is a directed edge from q0 to q1 with
label1/0. It output 0. Proof: By method pf mathematical induction
Definition of Transition System: A transition 1. Basis: on |y| i.e. length of y when |y|=1,
System consist of 5-tuple (Q,Σ, δ, Q0, F). y=a∈Σ.
I. Here Q,∑ and F are finite non empty set of L.H.S= δ (q,xa)
states, the input alphabets, and set of final = δ( δ(q,x),a) (by using prop. 2)
states respectively, as in the case of FA. =R.H.S.
II. Q0 ⊆Q and Q0 is the non-empty set of initial 2. Induction Hypothesis: Assume the result
state. for all string x and string y with |y|=n.
III. δ is finite Q×Σ → Q . 3. Let y be a string of length n+1.
Write y=y1a, where |y1| = n.
In other words, if (q1, ω, q2) is in δ. It means that
L.H.S. = δ(q,xy1a) = δ (q,x1a) where
the graph starts at the vertex q1, goes along a set
x1=xy1
of edges and reaches the vertex q2.
= δ( δ(q,x1)a) ( by using prop. 2).
A Transition system accepts a string w in Σ* if = δ( δ(q,xy1) a )
i). There exists a path which originates from = δ( δ( δ(q,x), y1 ) a ) by step 2.result
some initial state, goes along the arrows and = δ( δ(q,x)y1a)
terminates at some final state. = δ( δ(q,x)y) = R.H.S.
ii). The path value obtained by concatenation of By the principle of mathematical
all- edge-labels of the path is equal to w. induction, this is true for all strings.
0 qf
(110)* (0+1)
a q0 a F q0 1 F
0 q1 1
b q0 b F 1
1+0
a q0 1 q1 0 F
a+b q0 F
b
a 1
c (10+111+11010)
(a+b)c q0 q1 F
b F 0 q1
a 1 1
a∗ 0 q2
F
q4 0
a 1
aa∗ a q3
q0 F
Difference between DFA and NDFA is only in δ. Example: Design a FA over alphabet Σ = {0, 1},
for DFA outcome is a state, i.e. an element of Q; which accepts the set of strings either start with
for NDFA, the outcome is a subset of Q. 01 and or end with 01.
Here we have two states A & B. so we have to let A = { q1, q2, q3, q4, q8},where
define possible transitions from these states and
δ ( S , b ) = ∈ - closure ( move ({P}, b ))
we continue the process until no next state remain
= ∈ - closure ( ϕ ) = ϕ.
to be considered.
δ ( A , a ) = ∈ - closure ( move ({ q1, q2, q3,
δ ( A , a ) = ∈ - closure ( move ({ q3, q5, qf}, a ))
q4, q8}, a )) = ∈ - closure (q5)
= ∈ - closure ( move ( ϕ ) ) = ϕ.
= {q2, q3, q4, q5, q7, q8} (next state)
δ ( A , b ) = ∈ - closure ( move ({ q3, q5, qf}, b )) let B ={q2, q3, q4, q5, q7, q8}
= ∈ - closure ( move ( ϕ ) ) = ϕ.
δ ( A , b ) = ∈ - closure ( move ({ q1, q2, q3,
δ ( B , a ) = ∈ - closure ( move ({q4, q5, qf }, a ))
q4, q8}, b )) = ∈ - closure (q6, qf)
= ∈ - closure ( move ( ϕ ) ) = ϕ.
= {q2, q3, q4, q6, q7, q8, qf} (next state)
δ ( B , b ) = ∈ - closure ( move ({q4, q5, qf }, b )) let C = {q2, q3, q4, q6, q7, q8, qf}
= ∈ - closure ( move ( ϕ ) ) = ϕ.
δ ( B , a ) = ∈ - closure ( move ({q2, q3, q4, q5,
Table for DFA q7, q8}, a )) = ∈ - closure(q5)
state/Σ a b ={q2, q3, q4, q5, q7, q8} =B
⟶S A B
A ϕ ϕ δ ( B , b ) = ∈ - closure ( move ({q2, q3, q4, q5,
B ϕ ϕ q7, q8}, b )) = ∈ - closure (q6, qf)
= {q2, q3, q4, q6, q7, q8, qf} = C.
Q = { S, A, B }
δ ( C , a ) = ∈ - closure ( move ({q2, q3, q4, q6,
Σ = { a, b}
q7, q8, qf}, a )) = ∈ - closure(q5)
F = { A, B } a A
={q2, q3, q4, q5, q7, q8}=B
S
δ ( C , b ) = ∈ - closure ( move ({q2, q3, q4, q6,
b B q7, q8, qf}, b )) = ∈ - closure (q6, qf)
= {q2, q3, q4, q6, q7, q8, qf} = C.
Example: Consider the following NFA with ∧ -
moves. Construct an equivalent DFA. state/Σ a b
a ⟶S A ∅
∧ q3 q5 ∧
A B C
a ∧ ∧ ∧ b B B C
P q1 q2 q7 q8 q9 C B C
∧ ∧ A b b
b a
q4 q6
S a C
∧ b
Figure: NFA having ∧ - moves B
let M = ( Q, Σ, δ, S, F ) is an equivalent DFA a
S = ∈ - closure (initial state of NFA) a
= ∈ - closure (P) (state reachable from P on
input ∈ - including P) 2. Removal of Null Moves
= { P } (next state) The basic Strategies for the removal of null
δ ( S , a ) = ∈ - closure ( move ({ P }, a )) string are as follows:
= ∈ - closure (q1) Let A and B be the two states connected by a
= { q1, q2, q3, q4, q8} (next state) null string ∧.
0,1 0, 1
Step 2: The finite automaton corresponding to q7 1
0
the regular expression cd* consists of an arc with ∧ ∧ ∧ ∧
q0 q5 q1 q2 q6 qf
the c. this arc comes from the previous state of
1 0
the finite automaton from where cd* follows q8
sequentially. This arc ends on a state, say A, on (d)
which there is a loop to indicate the nuber of 0,1
0,1 q7 1
repetitions (including zero) of d. The part of the 0
finite automaton corresponding to the regular q2
q1
expression cd* is shown in figure 2.
1 0
Step 3: The finite automaton corresponding to q8
the regular expression e, consists of an arc with
(e)
label e coming from a previous state and ending
into some state, say F. since e is the last part of Example: Construct the FA equivalent to the
the total regular expression (a + b )*cd*e, F has regular expression 10 + ( 0 + 11) 0*1
to be a final state. The part of the finite Solution: (Construction of transition graph): First
automaton corresponding to the regular we construct the transition graph with ∧-moves
expression e is shown in figure 3. then eliminate ∧-moves.
Step 4: The complete finite automaton for the 10 + ( 0 + 11) 0*1
regular expression (a + b )*cd*e can be obtained q0 qf
by combining the finite automata in fig 1 -3 (a)
10
serially, as shown in figure 4.
d
a, b q0 qf
Previous c
A
S State ( 0 + 11) 0*1
Figure 2 (b)
Figure 1 q1
a, b d 0
1
Previous e c e
F S A F 0 qf
State q0
1
Figure 3 Figure 4 ∧
0+11
q2 q3
Example: Construct the FA equivalent to the RE
(0 + 1)*(00 + 11)(0 + 1)* (c)
q1 0
Solution: (Construction of transition graph): First
we construct the transition graph with ∧-moves 1
then eliminate ∧-moves. 0 qf
q0 0 1
(0 + 1)*(00 + 11)(0 + 1)* 1 ∧
q0 qf q2 q3
(a) q4
1 (d)
(0 + 1)* (00 + 11) (0 + 1)* q1 0
q0 q1 q2 qf 1
(b)
(0 + 1) (0 + 1) 0 qf
q0
(00 + 11) 0 1
∧ ∧ ∧ ∧ 1
q0 q5 q1 q2 q6 qf q2
1 d
(e)
Example: Design a grammar generating the Example: Design a grammar generating the
language L = { wcwR| w ∈ (a, b)+}. language L = { anbncn | n ≥ 1 }.
Solution: (a, b)+ indicates that w contain at Solution: Every string w belonging to the
least one symbol. The example strings are in language begins with a substring containing a
the language L are aca, abcba, bbcbb, aacaa, symbols. This follows a substring of equal
abbcbba, . . . Thus productions P are number of b symbols, which further follows
S ⟶ aSa | bSb | aXa| bXb the substring of same number of c symbols.
X⟶c The example strings in the language L are abc,
Example: Design a grammar generating the aaabbbccc, aabbcc, aaaabbbbcccc, . . . etc. Thus
language L = {anbn | n ≥ 1 }. the productions P are:
S ⟶ aSXc | abc
Solution: Every string contains equal number
cX ⟶ Xc
of a’s and b’s. Every string w in L contains a
bX ⟶ bb
substring of a’s followed by a substring of
equal number of b’s. The example strings in it can be seen that every string in the language
the language L are ab, aabb, aaaabbbb, aaabbb, L has the length 3n.
. . . . Thus productions P are Example: Design a grammar generating the
S ⟶ aSb | ab language L = { ww | w ∈ (a, b)+ }
Example: Design a grammar generating the Solution: we see that each string in the language
language L = { ancmbn | m, n ≥ 1 }. L is of the length 2n (n ≥ 1). The first substring
Solution: every string w belonging to the of length n is the same as that of the subsequent
language begins with a substring containing a substring of length n. The example strings in the
symbols. this follows a substring of c symbols. language L are aa, abab, bbbb, baba, bbabba,
the substring of c’s follows the substring of b babbab, . . . . thus productions P are :
symbols and the number of b’s is the same as S ⟶ XYZ
that of a’s. the example strings in the language XY ⟶ aXA | bXB
are acb, accb, aacccbbb, aaaccbbb, . . . . Thus, AZ ⟶ YaZ
we have the set of productions P as follows: BZ ⟶ YbZ
S ⟶ aSb | aXb Aa ⟶ aA
X⟶ cX | c. Ab ⟶ bA
Ba ⟶ aB
Example: Design a grammar generating the
Bb ⟶ bB
language L = { anbm |m, n ≥ 1 }.
aY ⟶ Ya
Solution: every string w belonging to the bY ⟶ Yb
language begins with a substring containing a
XY ⟶ ∧
symbols. This follows substring of b symbols
Z⟶∧
and the number of b’s are independent of a’s.
Example: Design a grammar for a language of
The example strings in the language L are ab,
all palindromes over {a, b}.
aab, abb, aabbbb, abbb, abbb, etc. Thus the
productions P are: Solution: The basis for our grammar is as
S ⟶ AB follows:
A ⟶ aA | a Note: Final state is also known as Accepting state.
B ⟶ bB | b
0
q3/0
1 1 0
Moore and Mealy Machines: Finite automata 0
with output: The finite automata which we were q0/0 q2/0
considered in the earlier have binary output i.e. 1 1
either they accept the string or they do not accept q1/1
the string. This acceptability was decided on the 0
basis of the reachability of final state by the Transition graph
initial state. Now, we remove this restriction and input string ⟶ 0111
consider the model where the outputs can be
chosen from some other alphabets. q0 0 q3 1 q0 1 q1 1 q2
The value of the output function Z(t) in the most output ⟶ 00010
general case is a function of the present state q(t)
and present input x(t), i.e. Definition: A Mealy machine has 6-tuple
Z(t) = λ(q(t), x(t) ) (Q, Σ, Δ,δ, λ,q0), where
Where λ is called the output function. This I. Q is a finite set of states.
generalized model is usually called the mealy II. Δ is the output alphabet,
machine. III. Σ is the input alphabet,
if the output function Z(t) depends only on the IV. δ is the transition function Σ × Q into Q.
present state and is independent of the current V. λ is the output function mapping Σ × Q into Δ.
input, the output function may be written as VI. q0 is initial state.
Z(T) = λ(q(t))
this restricted model is called the Moore machine. Example: Mealy Machine
q1 0 q3 0 q2 1 q4 1 q3
Output String = 0100
Note: for a Moore machine, if the input string is Present a=0 a=1
of length n, the output string is of length n+1. The State Next O/p Next O/p
first output is λ(q0) for all output strings. In the ⟶q1 q3 0 q20 0
case of a Mealy machine if the input string is of q20 q1 1 q40 0
q21 q1 1 q41 1
length n, the output string is also same length. q3 q21 1 q1 1
q40 q41 1 q3 0
Convert the Following Moore Machine to Mealy
q41 q41 1 q3 0
Machine.
Convert the Following Mealy Machine to Moore Present Next State Output
Machine. State a=0 a=1 (λ)
⟶q1 q21 q31 ∧
Present a=0 a=1 q21 q22 q31 z1
State Next O/p Next O/p q22 q22 q31 z2
⟶q1 q3 0 q2 0 q3 q21 q32 z1
q2 q1 1 q4 0 q3 q21 q32 z2
q3 q2 1 q1 1
q4 q4 1 q3 0
Question: Design a Moore machine which counts By the analyzing mealy machine transition
the occurrence of substring aab in input string. diagram, we can easily notice that it is also finite
Solution: Let the Moore machine be automata without any final state and output is
M0 = (Q, Σ, Δ, δ, λ,q0) there for input-symbol on corresponding
Q = { q0, q1, q2, q3 } transition. Output for every input symbol is
Σ = { a, b} represented as level on each transition
We will design this machine in such a way that corresponding output. For e.q. in between q1 and
machine prints out the character 0 except for q3, q2 is labeled by 0/1, 0 is input symbol and 1 is the
which prints a 1. To get q3, we must come from output symbol.
state q2 and have 1st read b. To get state q2, we
Question: Design a mealy machine, which prints
must read atleast two a’s in a row, having started
1’s complement of input bit string over alphabet
in any state.
Σ = { 0, 1}.
Δ={0,1}
Solution: If input string is 101110 then 1’s
λ’(q0) = 0, λ’(q1) = 0, λ’(q2) = 0, λ’(q3) = 1 complements of 101110 will be 010001, so we
The following machine will counts aab have to design a mealy machine which will print
occurrence for us. output 010001 for the input string 10110.
a
M0 = (Q, Σ, Δ, δ, λ,q0)
a
Q = { q0 }
a
q0/0 q0/1 q0/0 b q0/1 Σ = { 0, 1}
b Δ={0,1}
a
b b q0 is the initial state.
0/0 1/0 q2
1/0 0/1
We can directly apply the method since the graph Pumping Leema for regular
does not contain any ∧-move and there is only Languages/Regular Sets:
one initial state. Pumping Lemma: let M = (Q, Σ, δ, q0, F ) be a
q1 = q2b + q3a + ∧ finite automaton with n states. let L be the regular
set accepted by M. let x ∈ L and |x|≥ n, then there
q2 = q1a
exists μνω such that x = μνω, ν ≠ ∧ and μνmω ∈ L
q3 = q1b
for each m ≥ 0.
q4 = q2a + q3b + q4a + q4b
Proof: suppose that the set Q has n elements. for
q1 = q2b + q3b + ∧ any string x in L with length atleast n. of we write
q1 = q1ab + q1ba + ∧ x = a1a2…an;
q1 = q1 (ab + ba ) + ∧ then the sequence of n+1 states.
R =R P + Q ⟷ QP* q0 = δ * ( q 0 , ∧ )
q1 = ∧ .(ab + ba )* q1 = δ* ( q0 , a1 )
q1 = (ab + ba )* q2 = δ* ( q0 , a1a2 )
q3 = δ* ( q0 , a1a2a3 )
. . .
Example:-
1 0, 1 q n = δ * ( q 0 , a 1a 2. . . a n )
0 ν
1 0 µ ω
q1 q2 q3
q0 qi qf
We can directly apply the method since the graph
suppose qi = qi + p
does not contain any ∧-move and there is only
0≤i≤i+p≤n
one initial state.
then
q1 = q10 + ∧
δ * ( q 0 , a 1a 2. . . a i ) = q i
q2 = q11 + q21
δ* ( qi , ai+1ai+2. . . ai+p ) = qi+p = qi
q3 = q20 + q3( 0 + 1 )
δ* ( qi , ai+p+1ai+p+2. . . an ) = qf ∈ F
q1 = q10 + ∧
To simplify the notation,
R = RP + Q ⟷ QP*
let μ = a1a2. . . ai
q1 = ∧.(0)* = 0 *
ν = ai+1ai+2. . . ai+p
q2 = q11 + q21
ω = ai+p+1ai+p+2. . . an
q2 = 0*1 + q21
R = Q + RP ⟷ QP* if i 0 will be
if i + p 0 will be
q2 = 0*11*
As the final states are q1 and q2, we need not since δ* ( qi , ν ) = qi , have δ* ( qi , νm ) = qi for
solve q3. every m ≥ 0 and it follows that
q1 + q2 δ* ( q0 , μνmω ) = qf for every m ≥ 0 since p > 0
0* + 0*11* and i + p ≤ n.
0* (∧ + 11*) = 0*1* Note: The decomposition is valid only for strings
of length greater than or equal to the number of
states. for such a string x = μνω as many times as Hence, | μν2ω | strictly lies between n 2 and ( n +
we like and get strings of the form μνmω which 1)2, but is not equal to any one of them. thus, |
are longer than μνω and are in L. by considering μν2ω | is not a perfect square and so μν2ω ∉ L. but
the path from q0 to qi and then the path from qi to by pumping lemma, μν2ω ∈ L. this is
qf ( without going through the loop), we get a contradiction. thus L is not regular.
path ending in a final state with path value μω (
this corresponds to the case when m = 0). Example: Show that L = { aQ | Q is a prime} is
not a regular.
Application of Pumping Lemma:
Solution: Step 1: We suppose L is a regular. let n
This problem can be used to prove that certain
be the number of states in the finite automaton
sets are not regular. we now give the steps needed
accepting L.
for proving that a given set is not regular.
Step 2: Let Q be a prime number greater than n.
Step 1: Assume that L is regular. Let n be the
let x = aQ. by pumping lemma, x be written as x =
number of states in the corresponding FA.
μνω, with |μν|≤ n and |ν| > 0. μ , ν, ω are simply
Step 2: Choose a string x such that |x| ≥ n, use strings of a’s. so ν = ap for some p ≥ 1 (and ≤ n).
pumping lemma to write x = μνω with |μν|≤ n and
Step 3: let m = Q+1, the |μνmω|
|ν| > 0.
= |μνω| + | νm-1| = Q + (m-1)p = Q + QP =
m
Step 3: Find a suitable integer m such that μν ω Q(1+p).
∈ L. this contradicts our assumption Hence L is
by pumping lemma, μνmω ∈ L. but |μνmω|= Q +
not regular.
Qp = Q(1+p) and Q(1+p) is not prime. so μν mω ∉
2
Example: Show that the set L = { a i | I ≥ 1 } is
L. this is contradiction. thus L is not regular.
not regular.
Example: Show that L = { 0i1i | i≥1} is not
1 4 9 16
Sol: L = {∧, a , a , a , a , . . . } regular.
= { ∧, a, aaaa, aaaaaaaaa, . . . } Solution: Step 1: Suppose L is regular. Let n be
Step 1: Suppose L is regular. let n be the number the number of states in the finite automaton
of states in finite automaton accepting L. accepting L.
2
Step 2: let x = a n . then |x| = n 2 > n. by Step 2: let x = 0n1n. then |x| = 2n > n. by pumping
pumping lemma, we can write x= μνω with |μν|≤ lemma, we write x = μνω with |μν|≤ n and |ν| > 0.
n and |ν| > 0.
2
Step 3: we want to find m, s the μνmω ∈ L for
Step 3: Consider μν ω. getting a contradiction. the string ν can be in any
| μν2ω | = | μ | + 2|ν| + |ω | > |μ | + |ν| + |ω| as |ν| > of the following:
0. case 1: ν has only 0’s i.e. ν = 0k for some k≥1.
this means case 2: ν has only 1’s i.e. ν = 1l for some l≥1.
n 2 = | μνω | = |μ | + |ν| + |ω| < | μν2ω | case 3: ν has both 0’s and 1’s i.e. ν = 0k1l for
as |μν|≤ n we have |ν|≤ n. therefore some k, l≥1.
| μν2ω | =| μ | + 2|ν| + |ω | ≤ n 2 + n. in case 1, we can take m=0, as μνω = 0n1n, μω=
0n-k1n. as k≥1, n-k≠n so μω ∉ L.
i.e.
In case 2, we can take m =0, as μνω = 0n1n, μω=
n 2 <| μν2ω | ≤ n 2 + n < n 2 + n + n + 1 0n1n-l. as l≥1, n-l≠n so μν∉ L.
n 2 <| μν2ω | < ( n + 1)2
In case 3, we can take m =2, as μνω = 0n-k0k1l1n-l. The term ‘closure property’ relates to a
μν2ω = 0n-k0k1l0k1l1n-l, as μν2ω is not of the form mathematical system (structure) containing a set
0n1n, μν2ω∉ L. thus in all the cases we get a and operations performed on the elements of the
contradiction. Thus L is not regular. set. For example, let I+ be the set of positive
integers and addition (+) and subtraction (-) be the
Example: Show that L = {zz | z∈{a, b}*} is not two operations performed on the elements of this
regular. set. When the addition operation is performed on
Sol: Step 1: suppose L is regular, let n be the the elements of this set the result obtained is some
number of states in the automaton M accepting L. positive integer and belongs I+. When the
subtraction operation is performed, the result
Step 2: let us consider zz = anbanb in L |zz| = obtained may or may not belongs to I+. Thus the
2(n+1) > n. we can apply pumping lemma to execution of the addition operation does not
write zz = μνω with |μν|≤ n and |ν| > 0. violate the boundary of the set I+ whereas
Step 3: We want to find m so that μνmω ∈ L for subtraction may do so. We say that the set I+ is
getting a contradiction. the string ν can be in only closed over the addition operation but not over
one of the following form: subtraction. Similarly, a set of all 3 × 3matrices is
closed over the operation of addition, subtraction
case 1: ν has no b’s i.e. y =ak for some k≥1.
and transpose, but not over the operation of the
case 2: ν has only one b. determinant.
we may note that ν can not have two b’s if so |ν| ≥
Every regular set can be expressed by its
n+2. but |ν| ≤ |μν| ≤ n.
corresponding regular expression. In addition, for
in case 1, we can take m =0. then μν0ω = μω is of every regular expression, there exists a
the for an-kbanb, here n-k ≠ n, we can not write μω corresponding regular set. If an operation
in the form so μω ∉ L. performed on regular set(s) leads to another set,
In case 2, we can take m = 0. then μν0ω = μω has which is also regular, then the regular set(s) are
only one b ( as one b is removed from μνω, b closed over that operation.
being in ν). so μω∉ L as any element in L should
The regular sets are closed over the operations of
have an even number of a’s and an even number
union, concatenation, transpose, complement,
of b’s. thus in both case, we get a contradiction.
intersection, difference and Kleene’s star.
therefore, L is not regular.
1. Regular sets are closed over the union
2n
Example: Is L = {a | n ≥ 1} regular? operation.
Solution: We can write a2n as aa(a2)m, where m ≥ Proof: let S1 and S2 be two regular sets
0 } is simply {a2 }* so L is represented by the associated with regular expressions R1 and R2
regular expression aa(P)*, where P represents respectively. Let there be a set S3 = ( S1 ∪ S2).
{a2}. the corresponding FA is shown in figure: then every element of S3 can be expressed
either by expression R1, R2 or both. Thus, the
a set S3 can be generated by the regular
q2
a a
q0 q1 qf a expression (R1 + R2). The association of S3
with regular sets has generated a regular set,
Pumping lemma fails to solve this problem regular sets are closed over the Union
because this is a regular grammar. operation.
2. Regular sets are closed over the concatenation
Closure properties of Regular sets: operation.
d0,1
Fo
Proof: let S1 and S2 be te two regular sets. C1 belongs to the language set L and those in the
since S2 is a regular set, s 2 is also a regular class C2 do not belongs to L.
set, (S1 ∩ s 2) is also a regular set. The language L can be implemented on the finite
state machine (FSM) such that each state in the
S1 ∩ s 2 = S1 – S2 is also a regular set.
FSM corresponds to a particular class.
Therefore, regular sets are closed over the
intersection operation. FA contains minimum two states.
7. Regular sets are closed over the Kleene’s
1. where the strings belonging to the class
star. C1 reach the final state and
proof: The closure over Kleene’s star(∗) is 2. Other where the strings belonging to the
also known as Kleene’s closure. closure of a class C2 reach the non-final state. Thus,
regular set over Kleene’s star means that if R the language L can be implemented using
is a regular expression, then R* is also a a FA.
regular expression. 0 0
1
Let R be a regular expression and M be its
F
corresponding finite automaton, as shown in S
figure, 1
Since L1 is regular.
q0 qk qf
qi Similarly consider a language L2 over {0, 1} such
that all strings belonging to L2 wnd with 00.
Now wrap around the finite automaton M and
all the string classified into 5-classes.
superimpose the final state qf with the initial state
q0 to make the initial state as the final state and to Class C1: string length less than 2 I.e. ∧, 0, 1.
create a new finite automaton, say M’ as shown Class C2: those ending with 00.
in figure. Class C3: those ending with 01.
Class C4: those ending with 10.
q0 qk
qi Class C5: those ending with 11.
1 0
Now if a string ω is accepted by the finite 0
0 qf
automaton M, then M’ accepts all the strings that q0 q1
involve the repetition of ω. such as ∧, ω, ωω,
1
ωωω and so on. Thus, M’ is a finite automaton
for R*. since there exists a finite automaton for since L2 is regular
R*, it is a regular set corresponding to R*. Hence, “If the number of equivalent classes over a
regular sets are closed over Kleene’s closure. language L is finite then the language L is
regular”. This statement is refered to as Myhill-
Myhill-Nerode Theorem [ Equivalent classes
Nerode theorem.
and Regular Languages]: Consider a language
L with Σ = {0, 1} such that a string ω belong to L L3 = {0n1n|n>0} to recognize this machine should
if and only if it ends with 0. we can categorized, be able to remember how many 0’s it has seen
all the strings into two categories ( classes), those and if the no. of 1’s is exactly the same as that of
ending with 0(say class C1) and those ending number of 0’s. However, the FSM is devoid of
with 1(say class C2). All the strings in the class any kind of memory the 0 count and match it
with the 1 count. the no. of equivalent classes belongs to L6, otherwise it does not since the
generated by the language L3 over {0,1}* is number of equivalent classes. for L6 is finite(9),
infinite, with each class corresponding to number the language L6 can be implemented on the FSM
of 0’s on any string. Since the number equivalent and therefore L6 is regular.
classes are not finite, according to Myhill-Nerode Current Input Symbol
theorem, the language L3 is not regular. state 0 1 2 3 4 5 6 7 8 9
⟶ q0 q0 q1 q2 q3 q4 q5 q6 q7 q8 q0
Consider a language L4 = {w|w is palindrome q1 q1 q2 q3 q4 q5 q6 q7 q8 q0 q1
over {a,b}}. q2 q2 q3 q4 q5 q6 q7 q8 q0 q1 q2
q3 q3 q4 q5 q6 q7 q8 q0 q1 q2 q3
Now, the recursive definition of a palindrome q4 q4 q5 q6 q7 q8 q0 q1 q2 q3 q4
over {a, b} is as follows: q5 q5 q6 q7 q8 q0 q1 q2 q3 q4 q5
∧ - is a palindrome q6 q6 q7 q8 q0 q1 q2 q3 q4 q5 q6
q7 q7 q8 q0 q1 q2 q3 q4 q5 q6 q7
a – is a palindrome
q8 q8 q0 q1 q2 q3 q4 q5 q6 q7 q8
b – is a palindrome
if a string x is a palindrome then axa, bxb are Minimization of Finite Automata:
palindromes.
Definition: Two state q1 and q2 are equivalent (
To recognize L4, a machine should be able to denoted by q1≡q2). if both δ(q1, x) and δ(q2, x) are
mark the middle of the string and match the final states or both of them are non final state for
symbols on the both sides of the middle. FSM all x∈Σ*.
has no memory, so counting is n’t possible.
As it is difficult to construct δ(q1, x) and δ(q2, x)
another possible mechanism is to create a class
for all x∈Σ* because there are an infinite number
corresponding to the string before the middle of
of strings in Σ*.
the input string and to match this class with the
class of the reverse string after the middle. if they Definition: Two states q1 and q2 are k-equivalent(
are same then the string is a palindrome. k≥ 0 ) if both δ(q1, x) and δ(q2, x) are final states
Otherwise, it is not. However the number of or both non final states for all strings x of length
possible classes for the string before the middle is k or less.
infinite; hence the language L4 can not be Example:
implemented on a finite automaton and hence, is Current State Input State
not regular. a b
⟶q0 q1(N) q4(N)
L5 = {ww | w is a string over {0.1} is not regular} q1 q5(N) qf(F)
because the language L5 belongs to the same q2 qf(F) q5(N)
group as the language L4. q3 q6(N) q4(N)
q4 qf(F) q5(N)
L6 over Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; a string w
q5 q5(N) q3(N)
over Σ* belongs to L6 if the number formed by w q6 q5(N) qf(F)
is divisible by 9. q0(N) qf(F)
qf
For example: 9, 18, 27, . . . are belongs to L6 1,
2, 3, . . . rest does not belongs to L6. a) 0-level equivalence: The only string with
Here string can be divided into 9 equivalent length zero i.e. ∧, if ∧ is applied on any state
classes, with each class corresponding to a qi remains on the same state qi.
remainder 0 to 8. if remainder 0, then the string if ∧ is applied in state qf we get final state.
π0 = {{q3}, { q0, q1, q2, q4, q5, q6, q7 }}. As {q3 } Q13 = {q2}, Q33 = {q1, q7 }, Q23 = {q6 }, Q43 = {q3,
can not be partitioned further. q5}, Q53 = {q0, q4 }.
Q11 = {q3 }, Q21 = {q2, q4 }, Q31 = {q7 }, Q41 = π3 ={{q2}, {q1, q7 }, {q6 }, {q3, q5}, {q0, q4 }}.
{q0, q1, q5, q6 } π3 = π2 (πn+1 = πn )
π1 = {{q3 }, {q2, q4 }, {q7 }, {q0, q1, q5, q6 }} Hence at higher level, we will get the same
Q12 = {q3}, Q32 = {q7 }, Q22 = {q0, q6 }, Q42 = {q1, equivalence.
q5}, Q52 = {q2, q4 }. Q’ = {[ q2], [q1, q7 ], [q6 ], [q3, q5], [q0, q4] }
Thus q0’ = [q0, q4], F’ = [ q2].
π2 = {{q3 }, {q0, q6}, {q7 }, {q1, q5}, {q2, q4 }}
Equivalence of Two Finite Automata: Two
Q13 = {q3}, Q33 = {q7 }, Q23 = {q0, q6 }, Q43 = {q1,
finite automata over Σ are equivalent if they
q5}, Q53 = {q2, q4 }.
accept the same set of strings over Σ. when two
π3 = {{q3 }, {q0, q6}, {q7 }, {q1, q5}, {q2, q4 }} finite automata are not equivalent; there is some
π3 = π2 (πn+1 = πn ) string ω over Σ satisfying the following: One
Hence at higher level, we will get the same automaton reaches a final state on application of
equivalence. ω, whereas the other automaton reaches a non-
final state.
Q’ = {[q3 ], [q0, q6], [q7 ], [q1, q5], [q2, q4 ]}
Comparison Method: Let M and M’ be two
q0’ = [q0, q6] F’ = [q3].
finite automata over Σ. we construct a
Example 2: comparison table consisting of n+1 columns,
Current State Input Symbol where n is the number of input symbols. the first
0 1 column consists of pair of vertices of the form (q,
⟶q0 q1(N) q5(N) q’) where q∈M and q’∈M’.
q1 q6(N) q2(F)
q2 q0(N) q2(F) Case 1: If we reach a pair of (q, q’) such that q is
q3 q2(F) q6(N) final state of M and q’ is a non-final of M’ or
q4 q7(N) q5(N) vice-versa, we terminate the construction and
q5 q2(F) q6(N) conclude that M and M’ are not equivalent.
q6 q6(N) q4(N)
q7 q6(N) q2(F) Case 2: Here the construction is terminated when
no new element appears in the second and
By Step 1: subsequent columns which are not in the first
column (i.e. when all the elements in the second
Q10 = F = {q2}, Q20 = Q – Q10 = { q0, q1, q3, q4, q5,
and subsequent column appear in the first
q6, q7 }
column). In this case we conclude that M and M’
π0 = {{q2}, { q0, q1, q3, q4, q5, q6, q7 }}. As {q2 } are equivalent.
can not be partitioned further.
Example:
Q11 = {q2 }, Q21 = {q3, q5 }, Q31 = {q1, q7 }, Q41 =
Consider the following two DFAs M and M’ over
{q0, q4, q6 }
{0, 1} given in figure. determine M and M’ are
π1 ={ {q2 }, {q3, q5 }, {q1, q7 }, {q0, q4, q6 }} c
equivalent.
Q12 = {q2}, Q32 = {q1, q7 }, Q22 = {q6 }, Q42 = {q3, d
q1
q5}, Q52 = {q0, q4 }.
q3
π2 ={{q2}, {q1, q7 }, {q6 }, {q3, q5}, {q0, q4 }}. d d c
c
q2
gp
T= {Ram, Sham, Tom, Geeta, ate, ran, If G = ({S}, {0,1}, { S ⟶ 0S1, S ⟶ ∧}, S ), find
walked, quickly, slowly} L(G).
P is the collection of rules described above Sol: As S ⟶ ∧ is a production. S ⟹ ∧. So ∧ is in
G
(the rules are called productions). L(G).
S is the special symbol denoting a sequence. also, for all n≥ 1.
The sentences are obtained by i) starting with S ⟹ 0S1 ⟹ 02S12 ⟹. . . ⟹ 0nS1n⟹0n1n
G G G G G
S ii) replacing words using the productions therefore,
and iii) terminating when a string of 0n1n ∈ L(G) for n≥ 1.
terminals is obtained.
L(G) = {0n1n |n≥ 1}
Definition: A phrase – structure grammar (or
Context-Free Grammars: A context-free
simply a grammar) is (VN, T, P, S), where
grammar (CFG) is denoted by G = {V,T,P,S},
i) VN is a finite non empty set whose where V and T are finite sets of variables and
elements are called variables ( non- terminals respectively. we assume V and T are
terminals). disjoint. P is a finite set of productions, each
ii) T is a finite non-empty set whose elements production is of the form A⟶α. where A is a
are called terminals. variable and α is a string of symbols from (V∪T)*
iii) VN ∩ T ≠ Φ. finally S is a special variable called the start
iv) S is a special variable (i.e. an element of symbol.
VN) called start symbol.
The right-hand side of a CFG is not restricted and it
v) P is a finite set whose elements are α⟶β,
may be null or a combination of variables and
where α and β are strings on VN ∪ T. α has at
terminals. The possible length of right-hand
least one symbol from VN. The elements of P
sentential from ranges from 0 to ∞ i.e. 0 ≤ | α | ≤ ∞.
are called productions or productions rules.
Note:
Type 2: Type 2 grammar is called context free Derivation Trees: A natural way of exhibiting
grammars. A production of the form α⟶β, where the structure of a derivation is to draw a
α,β ∈ (VN, T)* is known as type 2 production and derivation tree or parse tree. At the root of the
the language generated by the type of grammars tree is the variable with which the derivation
is called context-free language (CFL). begins. Interior (intermediated) nodes are
For example: S ⟶S + S, S ⟶S ∗ S, S ⟶ id are variables and leaf nodes are terminals.
type 2 productions.
For example: CFG S ⟶ S + S | S ∗ S | a | b and
Type 1: Type 1 are context sensitive grammars construct the derivation trees for all productions.
(CSGs). if all productions of a grammar are of for the production
type 1 then grammar is known as type 1
grammar. i) S⟶S∗S
S
In CSG, there is left context or right context or
both. For example, production αAβ ⟶ αaβ. In
this α is left context or β is right context of A and S ∗ S
A is the variable which is replaced by a. the
production of S ⟶ ∧ is allowed in type 1. If ∧ is ii) S ⟶S+S
S
in L(G), but S should not appear on the right hand
side of any production. for example, productions iii) S ⟶a
S ⟶ AB, S ⟶ ∧, A ⟶ c are type 1 productions, S + S
but the production of type A ⟶ Sc is not
allowed. a
(Note: we assume that ∧ is the context on left and
iv) S ⟶b
right). S
Type 0: These types of grammar are also known
as phrase-structure grammars, and RHS of these b
are free from any restriction. All grammars are
type 0 grammars. If ω ∈ L(G) then it is represented by a tree called
For example: productions of type AS ⟶ aS, SB derivation tree or parse tree satisfying the
⟶ Sb, S ⟶ ∧ are type 0 productions. following
Classifying the Type of grammars:
1. The root has label S ( the starting
1. Type 0 grammars include Type 1, Type 2, symbol).
Type 3 grammars. 2. The all interior (internal) vertices (nodes)
2. Type 1 grammars include Type 2 and Type 3 are labeled with variables.
grammars. 3. The leaves or terminal nodes are labeled
3. Type 2 grammar includes Type 3 grammars. with ∧ or terminal symbols.
Type 0 Turing 4. If A ⟶ α1 α2 α3. . . αn is a production in
Phrase structured Grammars Machine G, then A becomes the parent of nodes
labeled α1, α2, α3,. . . ,αn and
C.F.G. Push down 5. The collection of leaves from left to right
Type 2 Automata produces string ω.
Regular grammers
Finite
Type 3
Automata
C.S.G.
Type
k: Aut1 Linear Bounded
Autmata
Leftmost derivation’s tree of previous example. Elimination of Left Recursion: let the variable
S A has left recursive productions as follows:
a a
Replace the terminal b by a new variable Xb, If αj is a terminal then replace it by a variable
and the terminal a by Xa, we get An+j consider the next Ai- production and go
S ⟶ AACD | ACD | AAC | CD |AC | XaC | Xa to step 5.
6. If Ai ⟶ α1 α2 … αn, where α1 is a variable,
A ⟶ XaAXb | Xa Xb
then preform the following:
C ⟶ XaC | Xa If α1 is same as Ai, then remove the left-
D ⟶ XaDXa | XbDXb | XaXa | XbXb recursion and go to step 5.
Xa ⟶ a, Xb ⟶ b Else replace α1 by all RHS of α1-productions
Final Step: one by one. Consider the remaining Ai-
S ⟶ AT1 T1 ⟶ AT2 T2 ⟶ CD productions, which are not in GNF and go to
step 5.
S ⟶ AT2
7. Exit.
S ⟶ AU1 U1 ⟶ AC
Advantages of GNF:
A ⟶ XaW1 W1 ⟶ AXb
1. Avoids Left Recursion
A ⟶ XaXb 2. Always has terminal in leftmost position in
C ⟶ XaC | a RHS of each production.
D ⟶ XaY1 Y1 ⟶ DXa 3. Helps select production correctly.
D ⟶ XbZ1 Z1 ⟶ DXb 4. Guarantees derivation length no longer than
D ⟶ XaXb | XaXb string length.
Xa ⟶ a Example: G = ({A1, A2, A3}, {a, b}, P, A1},
where P consists of the following production
Xb ⟶ b
rules.
Griebach Normal Form: Every Context-Free
A1 ⟶ A2A3
Language L without ∧ can be generated by a
A2 ⟶ A3A1 | b
grammar for which every production is of the
A3 ⟶ A1A2 | a
form A ⟶aα, where A is a variable, a is a
Convert it into GNF.
terminal and α is a string of variable (possibly
empty or (α ∈ VN∗ )). Solution: (Renaming is not required)
Consider the A1-production
A grammar in GNF is the natural generalization
A1 ⟶ A2A3 (Not in GNF)
of a regular grammar ( right linear).
Replacing A2 by its RHS, we get
Method for converting a CFG into GNF :
A1 ⟶ bA3 (In GNF)
1. Eliminate the NULL productions
2. Change the intermediate terminal into A1 ⟶ A3A1A3 (Not in GNF)
variables. Now, consider A1 ⟶ A3A1A3 and replacing A3
3. Remove all the variables of G as A1, A2, A3, . by its RHS, we get
. . , An. A1 ⟶ aA1A3 (In GNF)
4. Repeat Step 5 and Step 6 for I = 1, 2, . . . , n A1 ⟶ A1A2A1A3 (Not in GNF)
5. If Ai ⟶ a α1 α2 … αn, where a∈ T, and αj is a
So, A1-productions are A1 ⟶ bA3 | aA1A3 |
variable or a terminal symbol.
A1A2A1A3.
Repeat for j = 1, 2,. . . , m
Now, Consider A1 ⟶ A1A2A1A3 and removing
left recursion, we get
Model of Push-Down Automata: It consists of a 2. In the second type of move, the input
finite tape, a reading head, which reads from the symbol is not read from the tape and
NDPDA
tape, a stack memory (Push-down store). topmost symbol of the stack is used. The
topmost of the stack is modified without
reading the input symbol. It is also known
Reading Top of
Head as ∧ - move.
Stack
Storing Direction
Finite
Non-deterministic PDA : NPDA has finite
Removing Direction
State
Control number of choices for its inputs. A NPDA
accepts an Input if a sequence of choices lead to
some final state or cause PDA to empty its stack.
Design a PDA to accept language {anbn | n>0 } Design a PDA for language {anbman | m, n ≥ 1 }.
Solution: Solution
δ ( q0, a, Z0 ) ⊢ (q1, aZ0 ) δ ( q0, a, Z0 ) ⊢ (q1, aZ0 )
δ ( q1, a, a ) ⊢ (q1, aa ) δ ( q1, a, a ) ⊢ (q1, aa )
δ ( q1, b, a ) ⊢ (q2, ∧ ) δ ( q1, b, a ) ⊢ (q2, a )
δ ( q2, b, a ) ⊢ (q2, ∧ ) δ ( q2, b, a ) ⊢ (q2, a )
δ ( q2, ∧, Z0 ) ⊢ (qf, Z0 ) δ ( q2, a, a ) ⊢ (q3, ∧ )
δ ( q3, a, a ) ⊢ (q3, ∧ )
Note: LL parsers (left to right scan using δ ( q3, ∧, Z0 ) ⊢ (qf, Z0 )
Leftmost derivation) usually are top-down
parsers, and LR parser ( left to right scan; Design a PDA for language L = {anbn+2 | n ≥ 1 }
Rightmost derivation in reverse order ) usually
Solution:
are bottom –up parsers.
δ ( q0, a, Z0 ) ⊢ (q1, aZ0 )
Design a PDA to accept language {wcwR | w ∈ δ ( q1, a, a ) ⊢ (q1, aa )
(a+b)* } δ ( q1, b, a ) ⊢ (q2, a )
Solution: δ ( q2, b, a ) ⊢ (q3, a )
δ ( q3, b, a ) ⊢ (q3, ∧ )
δ ( q0, a, Z0 ) ⊢ (q1, aZ0 ) δ ( q3, ∧, Z0 ) ⊢ (qf, Z0 )
δ ( q0, b, Z0 ) ⊢ (q1, bZ0 )
δ ( q1, a, a ) ⊢ (q1, aa )
Parsing: The importance of a grammer is that it
δ ( q1, b, a ) ⊢ (q1, ba )
δ ( q1, a, b ) ⊢ (q1, ab ) provides the platform to describe ( generate or
δ ( q1, b, b ) ⊢ (q1, bb ) produce ) a certain language.
δ ( q1, c, a ) ⊢ (q2, a ) 1. Syntax: It means the grammatical
δ ( q1, c, b ) ⊢ (q2, b )
construct of a program.
δ ( q2, a, a ) ⊢ (q2, ∧ )
δ ( q2, b, b ) ⊢ (q2, ∧ ) 2. Semantics: It means, the meaning of a
δ ( q2, ∧, Z0 ) ⊢ (qf, Z0 ) program. it is all about the operations that
are to be carried out by some means.
We define parsing, Parsing is a technique to
Design a PDA for language L = {ancb2n | n ≥ 1 }
construct a parse (derivation) tree or to check
Solution: whether there is some leftmost derivation or not
δ ( q0, a, Z0 ) (q1, aaZ0 ) for a given word (string) using a certain grammar.
⊢
δ ( q1, a, a ) ⊢ (q1, aaa ) if the syntax of a given string is correct then the
δ ( q1, c, a ) ⊢ (q2, a ) answer is ‘YES’ otherwise the answer is ‘NO’.
δ ( q2, b, a ) ⊢ (q2, ∧ ) In general parsing is categorized into two
δ ( q2, ∧, Z0 ) ⊢ (qf, Z0 )
categories.
1. Top-down parsing
Solution 2:
2. Bottom-up parsing
δ ( q0, a, Z0 ) ⊢ (q1, aZ0 ) Top-Down Parsing: We start with initial symbol
δ ( q1, a, a ) ⊢ (q1, aa )
and replace the leftmost variable in each step and
δ ( q1, c, a ) ⊢ (q2, a )
δ ( q2, b, a ) ⊢ (q3, a ) finally get the string. This approach is known as
δ ( q3, b, a ) ⊢ (q2, ∧ ) top-down parsing. In the parse tree, start symbol
δ ( q2, ∧, Z0 ) ⊢ (qf, Z0 ) is root, terminals are leaves (input symbols) and
other nodes are variables. we start from the root Bottom-up parsing: The basic idea of a bottom-
and replacing the intermediate nodes one by one up parser is that we start with input string and
from left to right reach the leaves. this is the replace the terminal(s) by respective variable
reason why this approach is known as top-down such that these replacements lead to the starting
approach. This approach is also known as symbol of the grammar So, in each step, we
recursive descent parsing. reduce the input string to reach the starting
S⟶ * ω symbol. This approach is reverse of the top-down
approach.
(From the starting symbol to generate sentence)
Bottom-up parser reads the input symbol from left
Note: If a leftmost derivation is constructed by
and uses rightmost derivation in reverse order like
looking k symbols ahead in the given string, then
predictive parsing, with most tables, have we use
the grammar is known as LL(k) grammar. Due to
stack to push symbols. If the first few symbol
non-determinism problem in the grammar , we
(sentential form) at the top of the stack match the
have to use LL(k) approach in the parsing. we
RHS of some variable, then we pop out these
can reduce the non-determinism to some extent
symbols from the stack and we push that variable
by converting a grammar in CNF and removing
(left-hand-side of production on the stack). This is
the left recursion and left factoring.
called a reduction. another name for bottom-up
A grammar G having the property to look k (k ≥ parsers is shift-reduce(SR) parsers.
1) symbols ahead in the given string to parse that
given string is known as LL(k) grammar. ‘Handles’ are the sequences (terminals and
variables or both) on the stack that match with
Example: let grammar G=({S, A, B}, {a, b}, P, some RHS in the given grammar productions and
S) where P1 : S ⟶ aA after replacement lead to the start symbol. there
S ⟶ bB are three actions in the bottom-up parsing.
S ⟶ ∧.
1. ‘Shift’ the current input(token) on the
A ⟶ aS and
stack and read the next token.
B ⟶ bS
2. ‘Reduce’ by some suitable LHS of
Design the parsing Table. production rule.
Variable Symbols 3. ‘Acceptance’ Final reduction, which
∧ a b leads to starting symbol.
S P3 P1 P2
A ϵ P4 ϵ Context Free Grammar is G = {VN, T, P, S },
B ϵ ϵ P5 design the parsing table and parse the string
babbba and check ω ∈ L(G)?
How to implement a Parser: A parser is a
program, which read input string, using certain P1: S⟶bAB Parsing Table
P2: S⟶aAB Variables Symbols
context-free grammar and finds a leftmost
P3: A⟶aA ∧ a b
derivation or construct a parse tree. S ϵ P2 P1
P4: B⟶bB
There are two forms of parsers: P5: A ⟶ b A ϵ P3 P5
1. Top-down parsers: Construct parse tree P6: B ⟶ a B ϵ P 6 P4
from root toward leaves. Suppose: ω = babbba ∈ L(G) ?
2. Bottom-up parsers: Construct parse tree P1 P3 P5 P4 P4
S ⟶ bAB ⟶ baAB ⟶ babB ⟶ babbB ⟶
from leaves to root. P6babbba.
babbbB ⟶
Note: Both top-down and bottom-up parsers scan
the input from left to right. Hence babbba ∈ L(G). YES
F T’ ∧
Note: All languages (Regular Language, CFL, TM. Alan Turing describes such a machine. Its
CSL, Type 0 (pharse structured) language) are existence means that there is a turing machine
accepted by TM. A language that is accepted by a known as UTM, which is capable of running any
TM is known as recursive enumerable(R.E.). algorithm. The key idea is to think of the
being enumerable means, a TM precisely lists all description of a Turing machine itself as data.
the strings of the language. Some type-0 we think a UTM as a reprogrammable TM.
languages are not decidable by TMs known as A universal Turing Machine takes as input the
recursive set (language). For a recursive language description of a turing machine along with the
a TM always halts for its member strings and initial tape contents, and simulates the behavior
rejects other. of any individual TM. Building such an UTM
appears to be a daunting task.
Computation with Turing Machine: we
represent integer numbers on the tape in forms of Problem: Design a TM for L = { w: w ∈ (a + b )*
0. suppose i is a positive integer, the 0i represents } ending in substring abb.
this integer numbers.
Post Correspondence Problem (PCP): Post’s Note: If the first substring used in PCP is always
correspondence problem is a combinatorial xi and yi, then PCP is known as the modified Post
problem formulated by Emil Post in 1946. This Correspondence Problem.
problem has many applications in the field theory
of formal languages. Unrestricted Grammars: An Unrestricted or
phrase-structure grammar is a 4-tuple G= (VN, T,
Definition: A correspondence system P is a finite P, S) where VN and T are disjoint sets of variables
set of ordered pairs of no empty strings over and terminals respectively, S is an element of V
some alphabet. called the start symbol; and P is a set of
productions of the form
Let Σ be an alphabet, then P is finite subset of Σ+
α ⟶β
× Σ*. A match or solution P is any string w∈ Σ
such that pairs (u1, v1), (u2, v2), . . . , (un, vn)∈P where α, β ∈ (VN ∪ T )* and α contains at least
one variable.
Context-Sensitive Grammar and Languages: ⟶ ∧). Also, when G1 has S ⟶ ∧, S does not
A Context-Sensitive grammar (CSG) is an appear on the right-hand side of any production.
unrestricted grammar in which every production So G1 is context sensitive. this proves lcfl ⊆ lcsl.
has the from α ⟶β Property 3: lrl ⊆ lcfl ⊆ lcsl ⊆ l0. this follows from
α ⟶β with |β| ≥ | α| properties 1 and properties 2.
Property 4: lrl ⊂≠ lclf ⊂≠ lcsl ⊂≠ l0.
A context-Sensitive language (CSL) is a language
that can generated by such a grammar. Computability (Basic Concept):
A slightly different characterization of these we start with the definition of partial and total
language makes it easier to understand the phrase functions.
context sensitive. A language is context-sensitive ⟶ A partial function f from X to Y is a rule
if and only if it can be generated by a grammar in which assigns to every element of X atmost one
which every production has the form element of Y.
αAβ ⟶ αXβ ⟶ A total function from X to Y is a rule which
Where α, β, and X are the strings of variables assigns to every element of X a unique element
and/or terminals, with X not null, and A is a of Y. for example:, If R denotes the set of all real
variable such a production may allow A to be numbers, the rule f from R to itself given by f(r)
replaced by X. depending on the context. = +√r is a partial function since f(r) is not defined
The production of type S ⟶ ∧ is allowed in type as a real number when r is negative. But g(r) = 2r
1 if ∧ is in L(G), but S should not appear on right is a total function from R to itself.
hand side of any production. Remarks: A partial or total function from Xk to
For example, Productions S ⟶ AB, S ⟶ ∧, A X is also called a function of k variables and
⟶ c are type 1 productions, but the production of denoted by f(x1, x2, . . . , xn). for example, f(x1,
type A ⟶ Sc is not allowed. Atmost every x2) = 2x1 + x2 is a function of two variables.
language can be thought as CSL. f(1,2) = 4, 1 and 2 are called arguments and 4 is
called a value. g(w1 , w2) = w1w2 is a function of
Note: If left or right context is missing then we
two variables ( w1, w2 ∈ Σ* ); g(ab,aa) = abaa, ab
assume that ∧ is the context.
and aa are called arguments and abaa is a value.
Relation between Languages of Classes (
Languages And Their Relation): let l0, lcsl, lcfl, lrl Primitive Recursive Functions:
denote the family of type 0 languages, context A function is primitive recursive if
sensitive languages, context free languages and 1. It is an initial function
regular languages respectively. 2. It is obtained from recursion or
Property 1: From the definition, it follows that lrl composition of initial functions.
⊆ l0, lcfl ⊆ l0. Most Popular total functions are primitive
Property 2: lcfl ⊆ lcsl. The inclusion relation is not recursive functions; however some total
immediate as we allow A ⟶ ∧ in context free functions are not. for example, the ackerman
grammar even when A ≠ S, but not in context- function is total but not primitive recursive.
sensitive grammars ( we allow only S ⟶ ∧ in Initial functions: the initial funvctions over N
context sensitive grammars). a context free are given below:
grammar G with productions of the A ⟶ ∧ is S(4) = 5, Z(7) = 0
equivalent to a context-free grammar G1 which
has no productions of the form A ⟶ ∧ (except S