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

Automataetl They Are Very Helpful

The document defines and describes automata and finite automata. It provides definitions for an automaton as a system that performs functions without human intervention, accepting inputs and converting them into outputs. It then defines the five components of a finite automaton: states, input alphabet, transition function, initial state, and final/accepting states. The document proceeds to describe the components of a finite automaton model including the input tape, reading head, and finite control. It concludes by defining a transition system and its components, which models state transitions in a finite automaton.

Uploaded by

Michael Mangahas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Automataetl They Are Very Helpful

The document defines and describes automata and finite automata. It provides definitions for an automaton as a system that performs functions without human intervention, accepting inputs and converting them into outputs. It then defines the five components of a finite automaton: states, input alphabet, transition function, initial state, and final/accepting states. The document proceeds to describe the components of a finite automaton model including the input tape, reading head, and finite control. It concludes by defining a transition system and its components, which models state transitions in a finite automaton.

Uploaded by

Michael Mangahas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

lOMoARcPSD|28454638

Automata(Etl) - They are very helpful

Theory of automata (University of Gujrat)

Studocu is not sponsored or endorsed by any college or university


Downloaded by Michael Mangahas ([email protected])
lOMoARcPSD|28454638

Definition of an Automaton:-An Automaton is Description of a Finite Automata (Finite State


defined as a system that preforms certain Machine): A Finite automaton can be represented
functions without human intervention. it accepts by five-tuple structure M(Q,Σ, δ, q0, F), where
raw material and energy as input and converts 1. Q is a finite non empty set of states.
them into the final product under the guidance of 2. Σ is a finite non empty set of inputs called
control signals. or an automata is defined as a
the input alphabets.
system where energy, materials, and information
3. is a function which maps Q × Σ into Q
are transformed, transmitted and used for
performing some functions without direct and is called transmission function (next
involvement of man. Ex: Any automatic machine state function) (present state × input
like printing machine, washing machine etc. alphabet→ next state).
4. q0 ∈ Q is the initial state.

i1 5. F⊆ Q is the set of final states (may be more


AUTOMATON o1
i2 o2 than 1).
i3 Note: Q×Σ* into Q means Present state × String
q1, q2, … ,qn
...
...

oq of input symbols(including Λ ) → Next State.


ip
Model of a automaton String being processed
$ $ $ $ $ $
Characteristics of automaton: Reading Head Input Tape
1. Input: i1, i2,…,ip are the input of the model
each of which can take a finite number of Finite Control
fixed values from an input I. Block diagram of a finite automaton
2. Output: o1, o2,…,oq are the outputs of the
I) Input tape: The input tape is divided onto
model each of which can give the finite
squares, each square containing a single
number of fixed values to an output O.
symbol from the input alphabet Σ. The end
3. States: At any instant of time the automaton
squares of the tape contain the end marker
can be in one of the states q1, q2, … ,qn.
$. The absence of the end markers
4. States Relation: The next state of an
indicates that the tape is of infinite long.
automaton at any instant of time is determine
Input string is processed from left to right.
by the present state and present input.
II) Reading Head: The head examines only
5. Output relation: The output is related to
one square at a time and can move one
either state only or to both the input and the
square either to the left or to the right, we
state.
restrict the movement of reading head
Note: An automaton in which the output depends only to the right side.
only on the input is called an automaton without a III) Finite Control: The input to the finite
memory. Ex:- logic gate. An automaton in which control will usually be the ‘Symbol’ under
the output depends on the state and input is called the reading head and the ‘present state’ of
an automaton with a finite memory. Ex:- flip- the machine. Outputs will be A). A motion
flops, shift register, Mealy machine. An of R-head along the tape to the next
automaton in which the output depends only on square. B). The next state of the finite
the states of the machine is called Moore state machine given by δ(q,a).
Machine.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

1/0 Ex.:- prove that if δ(q,x) = δ(q,y), then


0/1 ^/0 δ(q,xz) = δ(q,yz) for all strings z in Σ+.
q0 q1 q3
Sol:- δ(q,xz) = δ( δ(q,x)z) by previous results.
^/0
0/0 1011/0 = δ( δ(q,y)z) (given)
q2
=(q,yz) (reverse the previous result)

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Regular Languages: a regular language over an Acceptability of a string by a finite Automation:


alphabet Σ is one that can be obtained from these basic Definition: A string x is accepted by a finite automaton
languages using the operations Union, Concatenation M=(Q, Σ, δ, q0, F) if δ(q0, x)=q for some q∈ F.
and Kleene* (Kleene* operation arises from the
This is basically the acceptability of a string by
concatenation to produce infinite languages).
the final state,
A regular language can be described by explicit Example: The FSM is given below
formula { } by leaving out the set of { } or replacing Table: Input symbol
them with ( ) and replacing ∪ by +; the result is called State 0 1
a regular expression. q0 q2 q1
q1 q3 q0
Language Corresponding q2 q0 q3
Regular Expression q3 q1 q2
1. {^} ^
2. {0} 0
3. {001} or ({0},{0},{1}) 001 1 q1 0
4. {0,1} or ({0}∪{1}) 0+1
1
5. {0,10} or ({0} ∪ {10}) 0+10 0
6. {1,^}{001} (1+^)001 q0 q3
7. {110}*{10} (110)*(0+1) 0 1
8. {1}*{10} (1)*10 or 1*0 or 1+0 0 1
*
9. {10,111,11010} (10+111+11010)* q2
10. {0,10}*{{11}*U{001,^}) (0+10)*((11)*+001+^)
Here Q = { q0, q1, q2, q3 }
Definition: Regular Languages and Regular Σ = {0, 1 }
Expressions over Σ: The set R of regular languages F = { q0 }
over Σ and the corresponding regular expressions are Input String(x) = 110101
defined as follows:
1. Φ is an element of R, then the corresponding RE is Φ. δ( q0, 110101 ) ⟹ δ( q1, 10101 ) ⟹
2. {^} is an element of R, then corresponding RE is ^. δ( q0, 0101 ) ⟹ δ( q2, 101 ) ⟹ δ( q3, 01 ) ⟹
3. For each a∈Σ is an element of R, and the
corresponding RE is a. δ( q1, 1 ) ⟹ δ( q0, ∧ ) ⟹ q0
4. If L1 and L2 are any element of R and r1 and r2 are 1 1 q ⟶ 0 q ⟶1 0 1
Hence q0 ⟶ q1 ⟶ 0 2 q3 ⟶ q1 ⟶ q0
corresponding RE. This ↓ indicates that the current input symbol is
a. L1∪L2 are any element of R and the being processed by machine.
corresponding RE is (r1+r2).
Non-Deterministic FSM:
b. L1L2 is an elements of any element of R and The concept of non-determinism plays a central
the corresponding RE is (r1r2). role in both the theory of languages and the
c. L1* is an elements of R and the corresponding theory of computation, and it is useful to
RE is (r1*). understand this notion fully in a very simple
Note: Only those languages that can be obtained context initially. The finite automaton model
by using statements 1 to 4 are regular languages allows zero, one, or more transitions from a state
over Σ. on the same input symbol. This model is called a
nondeterministic finite automaton(NFA).

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

For one input there is one or more output states. a


a∗a(NFA) a
0 1 q0 F
0
q0 q1
a c
1 1 (a+b)(c+d) q0 q1 F
q2 b d
a ,b
Figure: Transition system representing NDA
(a + b)∗
If an automaton is in a state {q0} and the input F
symbol is 0, what will be the next state?, from
figre it is clear that next state will be either {q0} a ,b F
Φ q0
or {q1}. Some moves of the machine cannot be
determined uniquely by the input symbol and the Some regular Expression and their corresponding FA
present state. Such machines are called NDA.
Definition: A Non-Deterministic Finite Automata q0
∈, ∧
(NDFA) is a 5 tuple (Q, Σ, δ, q0, F), where
q0 0 F
I) Q is a finite non-empty set of states. 0
0 0
II) Σ is a finite non-empty set of inputs. 001 q0 q1 q2 1 F
III) δ is the transition function mapping from 0 ,1
0+1 q0 F
Q×∑ into 2Q which is the power set of Q,
the set of all subset of Q.
0
IV) q0 ∈ Q is the initial state; and 0 + 10 q0 F
V) F ⊆ Q is the set of final states. 1 q1 0
Some rules to generate FA ∧
(1 + ∧ ) 001 0 0
q0 q1 q2 q3 1 F
∈, ∧ q0 1

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Facts of designing Procedure of FA Solution: By the analysis of problem, it is clear


we can describe some facts or observation of FA that FA will accepts the strings such as 01,
a. In the designing of the FA, first of all we 01111, 010000, 000101, 0001101,….
have to analyze the set of strings i.e. 0, 1
language which is accepted by the FA.
0 1
b. Make sure that every state is check for the q0 q1 q2
output state for every input symbol of Σ.
1
c. Make sure that no state must have two
different output states for a single input q3 1
symbol. 0 0
0
d. Make sure that there is one initial state and
at least one final state in transition diagram 1 q4 0
of FA.
1
Example: Construct a FA that accepts set strings
q5
where the number of 0’s in every string is
multiple of three over alphabet Σ = {0, 1}. Example: Design a FA which accepts the
Solution: Multiple of three means number of 0’s language L= {w/ w has both an even number of
on the string may be 0, 3, 6, 9, 12, . . . 0’s and an even number of 1’s over alphabets Σ
1 = {0, 1}}.
Solution:
1 q1 1
0
q0 1 q1
q0
0 0 0 0
0 1
0
q2 q3
q2 1
1
Example: Design FA for the Language example:NFA
L ={(01)I 12j | i≥1, j≥1}. 0
0 ,1
Solution: By analysis Language L, it is clear that 1 1
q0 q1 q2
FA will accepts strings start with any number of
01(not empty) and end with even number of 1’s. 0
1 ∧
0 1
q3 0 q4
0 1 1 1 q4
q0 q1 q2 q3
w =0100
0 0 ,1
0
1 0 δ(q0, 0100) = { q0, q3, q4 }
q5
since q4 is an accepting state, the input string will
0, 1 be accepted by NDFA.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Example: NFA II. Any NDFA is a more general machine


without being more powerful.
0 ,1
q0
1 0 ,1 0 ,1 let M = ( Q, Σ, q0, δ, F ) is an NFA.
q1 q2 q3
M1= (Q1, Σ, q1, δ1, F1 ) is a DFA.
δ* (q0, 11) = ∪ δ ( r , 1 ) I) Q1 = 2Q
r ∈(q0,1) II) q1 = { q0 }
III) Σ =Σ
= ∪δ(r,1)
r∈(q0,q1) IV) F1 = { q ∈ Q1 and q ∩ F ≠ ∅ }
V) δ1 (q, a ) = ∪ δ ( r, a )
= δ(q0,1)∪δ(q1,1)
r∈q
{ q0, q1 } ∪ { q2 } δ1 ([q1, q2, … , qi] , a ) = δ(q1, a) ∪ δ(q2, a)
δ* ( q0 , 01 ) = ∪ δ ( r, 1 ) ∪…∪ δ(qi, a)
r ∈(q0,0) equivalently
= ∪ δ ( r, 1 ) δ1 ([q1, q2, … , qi] , a ) = [ p1, p2, . . ., pj]
r ∈ { q0 }
if and only if
= δ (q0, 1 )
δ1 ({q1, q2, … , qi} , a ) = {p1, p2, . . . , pj }
= {q0, q1 }
δ1 (q1, x ) = [q1, q2, … , qi]
δ* (q0, 111) = ∪ δ ( r, 1 )
if and only if
r ∈(q0,11)
δ (q0, x ) = {q1, q2, … , qi}
= ∪ δ ( r, 1 )
Prove by using Mathematical Induction
r ∈{q0, q1, q2}
= δ(q0, 1 ) ∪ δ(q1, 1 ) ∪ δ(q2, 1) 1. Basis: |x| = 0
δ (q0, ∧ ) = { q0 } and
= { q0, q1 } ∪ { q2 } ∪ { q3 }
= { q0, q1, q2, q3 } δ1 (q1, ∧) = q1 = {q0}
so the equation is true.
The Equivalence of DFA and NDFA: 2. Assume equation is true for all string y with
or Prove that for every NFA, there is an |y| = m
corresponding FA which simulate the behavior δ1 (q1, y) = δ (q0, y)
of NFA. for every string L. 3. let x be a string of length m+1.
Solution: Before describing the equivalence of x= ya
NFA and DFA, let us take a look at the term δ1 (q1, ya) = δ1 (δ1 (q1, y),a )
equivalence. The term equivalence means ‘equal = δ1 (δ (q0, y),a )
in some respect’. For example, a BA degree is
= ∪ δ ( r, a)
equivalent to an B.E. degree, as both are bachelor r ∈(q0,y)
degrees, and for appearing in the civil services = δ ( q0, ya )
examination, either of them is equally applicable.
However, both are not equal, as a person with a
Examples: Construct a deterministic automaton
BA degree cannot be appointed as engineer and a equivalent to M = ( [q0, q1], {0,1}, δ, q0 , {q0} )
person with a BA degree cannot be appointed as a where δ is
history teacher. state/ Σ 0 1
I. A DFA can simulate the behavior of NDFA ⟶q0 q0 q1
by increasing the number of states. q1 q1 q0q1

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Solution: Sol: M1 = (2Q, {a,b}, δ, [q0], F )


i. The states are subset of {q0, q1} i.e. {Φ}, F = [q3], [q0. q3], [q1, q3], [q2, q3], [q0, q1, q3],
{q0}, {q1}, { q0, q1}. [q0, q2, q3], [q1, q2, q3] and [q0, q1, q2, q3]
ii. [q0] is initial state.
iii. [q0] and [q0, q1] are final states, both state/ Σ 0 1
⟶[q0] [q0, q1] [q0]
states contain q0.
[q0,q1] [q0,q1,q2] [q0, q1]
iv. Transition table for DFA [q0,q1,q2] [q0, q1, q2, q3] [q0,q1,q3]
state/ Σ 0 1 [q0,q1,q3] [q0,q1,q2] [q0,q1,q2]
Φ Φ Φ [q0, q1, q2, q3] [q0, q1, q2, q3] [q0, q1, q2, q3]
⟶[q0] [q0] [q1]
[q1] [q1] [q0, q1] Example: Convert he NFA given in Figure to
its equivalent DFA.
[q0, q1] [q0, q1] [q0, q1]
a,b
When M has n-states, the corresponding FA has
a b
2n states. However, we need not to construct δ q1 q2 qf
for all these 2n states. But only for those states
are reachable from {q0}, we halt on when no Transition table for the NFA in figure
more new states appear under the input. Current State Input Symbol
Example: Find a deterministic acceptor a b
equivalent to M = ( [q0, q1, q2 ], {a, b}, δ, q0, ⟶q1 q1, q2 q1
{q2} ) where δ is q2 __ qf
qf __ __
state/ Σ 0 1
⟶q0 q0, q1 q2 Transition Table for DFA corresponding to DFA
q1 q0 q1 Current State Input Symbol
q2 __ q0, q1 a b
⟶[q1] [q1, q2] [q1]
Solution: [q1, q2] [q1, q2] [q1, qf]
M = { 2Q, {a,b}, δ, [q0], F’ } [q1, qf] [q1, q2] [q1]
F’ = { [ q2], [q0, q2], [q1. q2], [q0, q1, q2] } Example: Convert the NFA given in Table to
state/ Σ 0 1 Corresponding DFA.
⟶[q0] [q0, q1] [q2] Transition Table for an NFA
[q2] __ [q0, q1] Current State Input Symbol
[q0, q1 ] [q0, q1 ] [ q1, q2] 0 1
[ q1, q2] [q0] [q0, q1] ⟶q1 q2 qf
q2 __ q3
Example: Find a deterministic acceptor q3 q4 q3
equivalent to q4 q3, qf __
M = ({q0, q1, q2, q3}, {a,b}, δ, q0, {q3} ) qf __ q1
where δ is

state/ Σ 0 1 Transition Table for DFA corresponding to DFA


⟶q0 q0, q1 q0 Current State Input Symbol
q1 q2 q1 0 1
q2 q3 q3 ⟶[q1] [q2] [qf]
__ q2 [q2] ϕ [q3]
q3 [q3] [q4] [q3]

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

[q4] [q3, qf] ϕ 1. ∈ - closure(q): Set of states which are


[qf] ϕ [q1] reachable from state q on ∈ - input including
[q3, qf] [q4] [q1, q3] state q. It is equivalent to one state of
[q1, q3] [q2, q4] [q3, qf] equivalent DFA.
[q2, q4] [q3, qf] [q3] 2. move(q,a) = set of reachable states on input a
Example: Convert the NFA fiven in table to its from state q.
corresponding DFA.
∈ - closure ( move ( q,a)): Next state from
Transition Table for an NFA state q on input a ( Note: ∈ - closure( ∅ ) = ∅ )
Current State Input Symbol
0 1 Initial state of equivalent DFA is ∈ - closure(),
⟶q0 q1 q0, q2 is the initial state of given NFA and final
q1 q2 q0 states are those sets, which have atleast one
q2 q0 __ final state of given NFA.
Example: Consider the NFA with ∧ - moves
Transition Table for DFA corresponding to DFA shown in figure.
Current State Input Symbol a
∧ q1 q3 ∧
0 1
⟶ [q0] [q1] [q0, q2] ∧ ∧
[q1] [q2] [q0] q0 q5 qf
∧ ∧
[q2] [q0] ϕ
[q0, q2] [q0, q1] [q0, q2] b
q2 q4
[q0, q1] [q1, q2] [q0, q2]
[q1, q2] [q0, q2] [q0] ∧
ϕ ϕ ϕ Fig: NFA with ∧ - moves.

NFA with ∧-moves : Find the equivalent DFA.


a Sol: M = ( Q, Σ, δ, S, F )
∧ S1 S3 ∧
S = ∈ - closure (initial state of NFA)
∧ ∧
S S5 S6 = ∈ - closure (q0) (state reachable from q0
∧ ∧ on input ∈ - including q0)
b
S2 S4 = { q0, q1, q2 }
∧ δ ( S , a ) = ∈ - closure ( move ({ q0, q1, q2 },
a ))
Fig:- NFA with ∧- moves = ∈ - closure (q3)
If there is a NFA M with ∧- moves, then there
= { q3, q5, qf} (next state)
exists an equivalent DFA M1 which has equal string
let A = { q3, q5, qf}.
recognizing power or if some NFA M with ∧-
moves accepts an input string w, then there exists where
an equivalent DFA M1 which also accepts w. δ ( S , b ) = ∈ - closure ( move ({ q0, q1, q2 },
b ))
Method for constructing equivalent DFA from = ∈ - closure (q4)
given NFA with ∧-moves. = {q4, q5, qf }
1. Using ∈ - closure Method let B = {q4, q5, qf }
we use two operations ∈ - closure and move().

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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 ∧.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Strategy 1: If A is an initial state, then move A to b) Concatenation


overlap B with all its connected structures as
shown in figure. f1 f2

a a
∧ q0 = q1 q2
A B A ∧
f’1 f’2
Strategy 2: If B is a final state, then move B to
overlap A with all its connected structures as
Concatenation(PQ)
shown in figure.
a
a c) Kleene*

A B B ∧
f1
Strategy 3: If A is the initial state and B is the
final state, then move A to overlap B with all its ∧
qf q1 ∧
connected structures and make A the final state
as shown in figure. f’1
a ∧
a

B A
A Kleenee* P*
Strategy 4: If both A and B are normal states ( Equivalent of FA to a Regular Set: The method
neither final nor initial), either can be moved to going to give for constructing a finite automaton
overlap the other with all its connected equivalent to a given regular expression is called
structures. subset method which involves two steps.
Note: If there is confusion in removing the null Step 1: Construct a transition graph equivalent to
moves, remove them using ∈-closure as the regular expression using ∧- moves. This is
discussed earlier. done by kleene’s theorem.
Kleene’s Theorem: Step 2: Construct the transition table for the
transition graph obtained in step 1. Using the
method conversion of NFA to DFA & construct
(c) the equivalent DFA.
(a) (b)
Example:- Construct a finite automaton for the
a) Union regular language represented by the regular
f1 expression (a + b )*cd*e.
∧ Solution: The following steps details the
q1

f’1 ∧ creation of the finite automaton for the given
q8 expression:
q0 ∧
∧ Step 1: The regular expression (a + b)* means
f2 ∧
q2 the repetition of the symbol a and b any number
of times (including zero) and in any order. Thus,
f’2
the automaton for this part of the regular
expression is given by loop that repeats for both
Union(P + Q ) a and b at any state as shown in figure i.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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)

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

An alphabet a or b is a palindrome. If a string x 11. String of even length


is palindrome then the strings axa and bxb are - (aa + ab + ba + bb)*
also palindromes. thus the grammar can be 12. String with odd number of 1’s
designed as follows: - 0* ( 10*10* )* 10*
S ⟶ aSa | bSb | a | b | aa | bb. 13. String of length of 6 or less.
- (∧ + 0 + 1 )6
Example: Design a grammar for a language L 14. Strings ending with 1 and not containing 00
over {a, b} such that each string in L contains - ( 1 + 01 )+
equal number of a’s and b’s. 15. Language of C identifiers.
Solution: The string can start with either a or - ( l + _) ( l + d + _ )*
b. Thus, we have the production 16. Real Literals in Pascal
S ⟶ aX | bY - sd+(pd+ + pd+Esd+ + Esd+ )
17. Strings Containing exactly 2 0’s
Now the design of X should be such that it
- 1*01*01*
inserts one b more than a in the output string.
18. String containing atleast 2 0’s.
Similarly, design of Y should be such that it
- 1* 0 ( 1 + 0 ) * 0 ( 1 + 0 ) *
inserts one a more than b in the output string,
19. Strings that do not end with 01.
Thus, we have
- ∧ + 1 + (0 + 1 )*0 + ( 0 + 1 )*11
X ⟶ b | aXX | bS 20. Strings that begin or end with 00 or 11.
Y ⟶ a | bYY | aS - (00 + 11) (0 + 1 )* + ( 0 + 1 )* ( 00 + 11 )
Questions: Find the regular expression 21. Strings not containing the substring 00
corresponding to following: - ( ∧ + 0 ) ( 1 + 10 )* or ( 1 + 10 )* ( ∧ + 0 )
22. Strings in which the number of 0’s is even
1. a, b ∈ Σ starting from (abb) - 1* ( 01* 01* ) *
- abb ( a + b )* 23. Strings containing no more than one
2. a, b ∈ Σ ending with (baa) occurrence of the string 00.
- ( a + b )* baa - ( 1 + 01 )* ( ∧ + 0 + 00 ) ( 1 + 10 )*
3. a, b ∈ Σ ending with (baa) and starting 24. Strings in which every 0 is followed
with (abb). immediately by 11.
- abb ( a + b )* baa - 1* ( 011+ )*
4. a, b ∈ Σ containing exactly 2a’s 25. { 0, 1, 2}
- b*ab*ab* - 0+1+2
5. a, b ∈ Σ containing atmost 2a’s 26. { 1 2n + 1
|n>0}
- b* + b*ab* + b*ab*ab* - ( 11 )+ 1
6. a, b ∈ Σ containing atleast 2a’s 27. { w ∈ { a, b }* | w has only one a }
- b*a ( a + b)* a (a + b)* - b*ab*
7. a, b ∈ Σ containing abb as substring 28. Set of all strings over { 0, 1} which has
- ( a + b)* abb (a + b )* atmost 2 0’s.
8. String of length 2. - 1+ + 1*01* + 1*01*01*
- (a + b) (a + b) or ( a + b)2 29. { a2, a5, a8, . . . }
9. String of length 6. - (aaa)*aa
- (a+b)(a+b)(a+b)(a+b)(a+b)(a+b) 30. { an | n is divisible by 2 or 3 or n = 5 }
10. String of length 2 or less. - (aa)* + (aaa)* + aaaaa
- (∧+a+b)(∧+a+b) 31. Strings beginning and ending with a.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

- a ( a + b )* a 2. Text Editor: smart and speedy text


32. Strings having atmost one pair 0’s or editors can be constructed using FA.
atmost one pair of 1’s. 3. Spell checkers: spell checkers can be
- ( 1 + 01)* + ( 1 + 01)* 00 ( 1 + 10)* + designed using FA. In our computer
( 0 + 10 )* + ( 0 + 10)*11(0 + 01 )* system, we have a dictionary, FA can
33. String in which number of occurrences of recognize the correctness of a word and
a is divisible by 3. can give the appropriate suggestion to the
- ( b* a b* a b* a b*)* users also.
34. String with 3 consecutive 4. Sequential Circuits: FA can also be used
- ( a + b )* bbb ( a + b )* to design sequential circuits.
35. Strings beginning with 00 5. Image Processing.
- 00 ( 0 + 1 )* 6. Natural Language Processing.
36. String ending with 00 and beginning with 1. 7. Internet Browsers: To scan large body of
- 1 ( 0 + 1 )* 00 information.
8. Communication: Designing of protocols
Difference between DFA and NDFA
for exchange of information.
Sr. DFA NDFA 9. Pattern matching.
1. Deterministic Non-Deterministic 10. Forensic Science
Finite Automata Finite Automata 11. Cellular machines uses cellular Automata
2. Every transition is Multiple transition for Limitations of Finite Automaton:
unique and an input on a state are
deterministic in possible, which means FA is most restricted model of automatic
nature. moves are non- machines. It is an abstract model of a computer
deterministic in nature. system. a FA has following limitations:
3. Null-transitions Null-transitions are 1. The memory is limited.
are not allowed allowed. 2. Memory is read-only memory.
4. Requires less Requires more 3. Memory is sequentially accessed.
memory as memory as transition 4. FA has only string recognizing power.
transition diagram diagrams needs more 5. Head movement is restricted in one
needs less number number of states. direction, either from left to right or from
of states.
right to left.
5. Range of Range of transition is 6. Limited Computability mean it can act
transition is δ:Q×Σ⟶2Q like a scanner FA are not computing
δ:Q×Σ⟶Q. devices but these act only as scanner.
6. All DFA’s are All DFA are NDFA. 7. Periodicity: FA cannot remember large
NDFA’s but vice amount of information or strings of large
versa is not true. size.
8. Impossibility of Multiplications: Full
Applications of Finite Automaton. length of multiplier and multiplicand
cannot be stored.
1. Lexical Analyzers: Lexical analysis is a
9. Binary Response: Response of FA is
part of compilation and used to recognize
binary either accepted or rejected after a
the validity of input programs. Whether
long sequence of moves.
the input program is grammatically
constructed or not.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Definition: A Moore machine has 6-tuple Present Next State


State a=0 a=1
(Q, Σ, Δ,δ, λ,q0), where state output state output
I. Q is a finite set of states. ⟶q1 q3 0 q2 0
II. Σ is the input alphabet, q2 q1 1 q4 0
q3 q2 1 q1 1
III. Δ is the output alphabet,
q4 q4 1 q3 0
IV. δ is the transition function Σ × Q into Q.
V. λ is the output function mapping Q into Δ. q3
VI. q0 is initial state.
0/1
Example: Moore Machine 0/1
Present Next State Output q1 q4
state a=0 a=1 (λ )
⟶q0 q3 q1 0
q1 q1 q2 1 q2
q2 q2 q3 0
Transition graph
q3 q3 q0 0
Input string : 0011

q1 0 q3 0 q2 1 q4 1 q3
Output String = 0100

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Present Next State Output Present Next State Output


State a=0 a=1 (λ) State a=0 a=1 (λ)
⟶q0 q3 q1 0 ⟶q1 q3 q20 1
q1 q1 q2 1 q20 q1 q40 0
q2 q2 q3 0 q21 q1 q41 1
q3 q3 q0 0 q3 q21 q1 0
q40 q41 q3 0
q41 q41 q3 1
Present a=0 a=1
State Next O/p Next O/p
⟶q0 q3 0 q1 1
q1 q1 1 q2 0
q2 q2 0 q3= 0 Convert the Following Mealy Machine to Moore
q3 q3 0 q0 0 Machine.
Convert the Following Moore Machine to Mealy
Machine. Present a=0 a=1
State Next O/p Next O/p
Present Next State Output ⟶q1 q2 z1 q3 z1
State a=0 a=1 (λ) q2 q2 z2 q3 z1
⟶q1 q1 q2 0 q3 q2 z1 q3 z2
q2 q1 q3 0
q3 q1 q3 1
Present a=0 a=1
State Next O/p Next O/p
Present a=0 a=1 ⟶q1 q21 z1 q31 z1
State Next O/p Next O/p q21 q22 z2 q31 z1
⟶q1 q1 0 q2 0 q22 q22 z2 q31 z1
q2 q2 0 q3 1 q3 q21 z1 q32 z2
q3 q3 0 q0 1 q3 q21 z1 q32 z2

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Question: Construct a mealy machine which 0/1


calculates the residue mod-4 for each binary q0
string treated as binary integer.
Solution: When we divide any number by 4 then 1/0
remainder can be 0, 1, 2, &3. so clearly mealy
machine will have four states. Question: Construct a mealy machine which
Let the Mealy machine be calculate residue mod-4 for each binary string
M0 = (Q, Σ, Δ, δ, λ,q0) treated as binary integer.
Q = { q1, q2, q3, q4 } Solution:
Σ = { a, b} M0 = (Q, Σ, Δ, δ, λ,q0)
Δ={0,1} Q = { q0, q1, q2, q3 }
q1 is the initial state & δ is transition function. Σ = { 0, 1}
λ’( q1, 0 ) = 0 λ’ ( q1, 1 ) = 0 Δ = { 0, 1, 2, 3}
λ’( q2, 0 ) = 1 λ’ ( q2, 1 ) = 0
λ’( q3, 0 ) = 1 λ’ ( q3, 1 ) = 1 0/0 1/3
λ’( q4, 0 ) = 1 λ’ ( q4, 1 ) = 0 1/1 1/3
Transition Diagram for M0 is as follows: q0 q1 q3
0/1
1/1 0/2
q1 1/0 q2 0/0 0/2

0/0 1/0 q2

1/0 0/1

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Arden’s Theorem: let P and Q be two regular Conversion of FA to Regular Expression.


expressions over Σ. If P does not contain ∧, then
Example: The transition system is given in figure.
the following equation in R, is
R = Q + RP ---(i) a a b a

has a unique solution QP*---(ii) q1 q2 q3


b a
Proof: let us First check if QP* is a solution to Prove that the strings recognized are
(i). To check this, let us substitute R by QP* on ( a + a ( b + aa)* b )* a ( b + aa ) * a
both sides of (i)
we can directly apply the method since the graph
R = Q + RP = Q + QP*P = Q (∧ + P*P) = QP* does not contain any ∧-move and there is only
Hence eqn(i) is satisfied when R = QP*. This one initial state.
means R = QP* is a solution of eqn(i). q1 = q1a + q2b + ∧
Let us check if it is the only solution. To do this, q2 = q1a + q2b + q3a
replace R by Q + RP on the Right Hand Side. of q3 = q2a
eqn(ii), we get reduce the number of unknowns by repeated
substitution.
R = Q + RP = Q + ( Q + RP )P
q2 = q1a + q2b + q3a
= Q + QP + RP2
q2 = q1a + q2b + q2aa
= Q + QP + ( Q + RP )P2
q2 = q1a + q2( b + aa )
= Q + QP + QP2 + RP3
R= Q+R P ⟷ QP*
...
2 i i+1 q2 = q1a( b + aa )*
= Q + QP + QP + … + QP + RP
Now substitute q2 in q1
= Q ( ∧ + P + P2 + … + Pi) + RPi+1
q1 = q1a + q2b + ∧
We now show that any solution of equation (i) is
equivalent to QP*. q1 = q1a + q1a ( b + aa )*b + ∧
q1 = q1( a + a(b + aa )* + ∧
Let w be the string of length I in the set R. then w
R = R P + Q ⟷ QP*
belongs to the set Q ( ∧ + P + P2 + … + Pi) +
q1 = ∧.( a + a(b + aa )*)*
RPi+1. As P does not contain ∧, RPi+1 has no
string less than i+1. This means that w belongs to = ( a + a(b + aa )*)*
the set RPi+1. This means that w belongs to the set q2 = ( a + a ( b + aa )*)*a( b + aa )*
Q ( ∧ + P + P2 + … + Pi) and hence to QP*. q3 = ( a + a ( b + aa )*)*a( b + aa )*a
Rules for using Arden’s Theorem: Since q3 is a final state, the set of strings
recognized by the graph.
1. The transition graph does n’t have ∧- moves. Example: a
2. It has only one initial state.
q1 q2
3. Vi the regular expression ( of final state) b
represents the set of strings accepted by the a
system ( Vi is final state). b a
4. q = Σ qi (incoming edge) alphabets + ∧ (only
for initial state). q3
b
q4

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Proof: Let S1 and S2 be the two regular sets 0 1


1
associated with the regular expressions R1 and q0 q1
R2 respectively. Let there be a set S3 created
by the concatenation of the elements of S1 and 0
S2 in order. Now each string belonging to S3 is
such that it can be decomposed into two parts, q2 0,1
with the first belonging to S1 (corresponding
to R1) and the second to S2 (corresponding to If final state is reachable from initial state then LT
R2). Thus, every element of S3 can be is also regular.
generated by the regular expression R1R2. The 4. Regular sets are closed over the complement
association of S3 with a regular expression operation
(R1R2) indicates that S3 is a regular set. Since Proof: let L be a regular set(language) over
concatenation of two regular sets has the character set Σ; then its complement L is
generated a regular set, regular sets are closed a set of all string over Σ* that are not in L,
over concatenation operation.
that is L = Σ* - L.
3. Regular sets are closed over the transpose
Let M be the finite automaton for the language
(string reversal) operation.
L. now, covert all the final states ofM to non-
Proof: Let S1 be a regular set associated with
final states and vice versa to generate a new
the regular expression R1. let M1 be the finite
finite automaton, say M’. Now, if for a string
automaton corresponding to R1. Now, for
ω, M stops in final state the M’ stops in the
every string (w ∈ S1), there is a path in M1
non-final state and vice-
from the initial state to final state. Now, the
following operations are performed on M1 to versa. Hence M’ is the finite automaton for
create a new finite automaton, say M2. Since there is a finite automaton for , is
a. Reverse the direction of every arc/arm. a regular set. Hence, regular sets are closed
b. Change the initial state ( origionally in over the complement operation.
M1) to the final state. 5. Regular sets are closed over intersection
c. Create a new start state S and connect it operation
to all the acceptor states of M1 using ∧- Proof: let S1 and S2 be two regular sets.
transitions. Therefore, their complements s1 s2
and
d. Remove all ∧-transitions.
are also regular sets. Union of s 1 and s 2,
Let S2 be a set of all strings accepted by M2.
that is, ( s 1 ∪ s 2) is also a regular sets.
Now every string (x∈S2) is reverse
(transpose) of some string (w∈S1) thus S2 is a Complement of ( s 1 ∪ s 2), that is, ( s1 s 2 )
set of transposed strings of S1. Since S2 is is also a regular set.
associated with a finite automaton M2, it is
associated with a regular expression, Hence By De Morgan’s Law, S1 ∩ S2 = ( s1 s2 ). 
S2 is a regular set has created another regular Hence, (S1 ∩ S2) is also a regular set.
set, regular sets are loosed over the transpose Therefore, regular sets are closed over the
operation. intersection operation.
0 1 6. Regular sets are closed over the difference
1
q0 q1 operation.

d0,1
Fo

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

if ∧ is applied in state any other state,


we get non final state. Current Input Symbol
The state of state Q can be partitioned state aaa aab aba abb baa bab bba bbb
into two subsets: {qf} and {q0, q1, q2, q3, q0 q5(N) q3(N) q0(N) qf(N) q0(N) qf(N) q5(N) q3(N)
q3 q5(N) q3(N) q0(N) qf(N) q0(N) qf(N) q5(N) q3(N)
q4, q5, q6}
This partition is denoted by
q1 q5(N) q3(N) q0(N) q4(N) q1(N) q4(N) q0(N) qf(N)
π0 = { {q0, q1, q2, q3, q4, q5, q6}, {qf}} q6 q5(N) q3(N) q3(N) q4(N) q1(N) q4(N) q0(N) qf(N)
b) 1- Level equivalence: The strings with
length one are a and b, equivalence at q2 q1(N) q4(N) q0(N) qf(N) q5(N) q3(N) q6(N) q4(N)
level 1 can exists if and only if, there q4 q1(N) q4(N) q0(N) qf(N) q5(N) q3(N) q6(N) q4(N)
exists equivalence at level 0. Hence, qf
cannot be equivalent to any other state at Algorithm (minimization of Finite
level 1. Automaton):
1) The state q0, q3, & q5 have same
behavior. These state lead to a non-final Step 1: (construction of π0): By definition of 0-
state for both the strings a and b. level equivalence, π0 = {Q10, Q20 } where Q10 is
2) The state q2 and q4 have the same the set of all final states and Q20 = Q – Q10.
behavior a- F, b-NF. Step 2: (Construction of πk+1 and πk ): let Qik be
Hence the set partition for 1-level any subset in πk. if q1 and q2 are in Qik, they are
equivalence is as follows: (k+1)-equivalent provided δ(q1, a ) and δ(q2, a )
π1 = { {q0, q3, q5}, {q1,q6}, {q2 q4}}, {qf}} are in the same equivalent class in πk for every
a∈Σ.
Current Input String
state aa ab ba bb if so, q1 and q2 are (k+1)- equivalent. in this way,
q0 q5(N) qf(F) qf(F) q5(N) Qik is further divided into (k+1)-equivalent
q3 q5(N) qf(F) qf(F) q5(N) classes. repeat this for every Qik in πk to get all
q5 q5(N) q3(N) q6(N) q4(N)
the elements of πk+1.
q1 q5(N) q3(N) q0(N) qf(F) Step 3: Construct πn for n = 1, 2, … until πn =
q6 q5(N) q3(N) q0(N) qf(F) πn+1.

q2 q0(N) qf(F) q5(N) q3(N) Example:


q4 q0(N) qf(F) q5(N) q3(N)
Current State Input Symbol
a b
c) 2-Level equivalence: The string length two ⟶q0 q1(N) q0(N)
is aa, ab, ba & bb. Equivalence at level 2 can q1 q0(N) q2(N)
exist. If there is equivalence at level 1. q2 q3(F) q1(N)
{q0, q3, q5}, {q1,q6}, {q2 q4} q3 q3(F) q0(N)
q4 q3(F) q5(N)
π2 = { {q0, q3},{q5}, {q1,q6}, {q2 q4}, {qf}} q5 q6(N) q4(N)
d) 3-level equivalence: the strings with length q6 q5(N) q6(N)
q7 q6(N) q3(F)
three are aaa, aab, aba, abb, baa, bab, bba,
and bbb.
By Step 1:
π3 = { {q0, q3},{q5}, {q1,q6}, {q2 q4}, {qf}}
Q10 = {q3}, Q20 = Q – Q10
π3 is same as π2. Hence, no further division is
possible.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

π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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Figure: Automaton M from q2 and q5 respectively. As q1 is a final state


c in M1 and q6 is a non-final state in M2, we see that
M1 and M2 are not equivalent: we can also not
d that q1 id dd-reachable from q1 and hence dd is
q4 q7
accepted by M1. dd is not acceptable by M2 as
c only q6 is dd-reachable from q4, but q6 is non-
d d c final.
c
q5 q6 Current state Input Symbol
d
c d
(q,q’) (qc,qc’) (qd,qd’)
Figure: Automaton M’ (q1,q4) (q1,q4) (q2,q5)
(q2,q5) (q3,q7) (q1,q6)
Sol: The initial states in M and M’ are q1 and q4
respectively. Hence the first element of the first
column in the comparison table must be (q1, Grammar: Before giving the definition of
q4). the first element in the second column in grammar, we shall study, two types of sentences
(q1, q4) since both q1 and q4 are c-reachable in English, with a view to formalizing the
from the respective initial states. construction of theses sentences. The sentences
we consider are those with a noun and a verb, or
Current State Input Symbol those with a noun-verb and adverb (such as ‘Ram
(q, q’) c (qc, qc’) d (qd, qd’) ate quickly’ or ‘Sham ran’). the sentences ‘Ram
⟶(q1, q4) (q1, q4) (q2, q5)
(q2, q5) (q3, q6) (q1, q4) are quickly’ has the words ‘Ram’, ‘ate’, ‘quickly’
(q3, q6) (q2, q7) (q3, q6) written in that order. If we replace ‘Ram’ by
(q2, q7) (q3, q6) (q1, q4) ‘sham’, ‘tom’, etc. i.e. be any verb in the past
tense, and ‘quickly’ by ‘slowly’ i.e. by an adverb,
we get other grammatically correct sentences so
As we do not get a pair of (q, q’), where q is a
the structure of ‘Ram ate quickly’ can be given as
final state and q’ is a non-final state( or vice-
<noun><verb><adverb>.
versa) at every row, we proceed all the
elements. Therefore M and M’ are equivalent. for <noun>, we can substitute ‘Ram’, ‘Sham’,
‘Tom’ etc.
Example: show that the automat M1 and M2
defined by figure are not equivalent. for <verb>, we can substitute ‘ate’, ‘ran’,
c ‘walked’ etc.
c
for <adverb>, we can substitute ‘quickly’,
d q4 c
q7 ‘slowly’ etc.
q1
c we have to note that <noun> <verb> <adverb>
d d c
q3 d c
c is not a sentence but only the description of a
c particular type of sentence. if we replace
q2 q5 q6
d
d <noun> <verb> and <adverb> by suitable
Sol: The initial states in M1 and M2 are q1 and q4 words, we get actual grammatically correct
respectively. Hence the first column in sentences.
comparison table is (q1, q4). q2 and q5 are d- Let S be a variable denoting a sentence. Now we
reachable from q1 and q4. we see fro the can form the following rules to generate two
comparison table that q1 and q6 are d-reachable types of sentences.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Productions: 1. Reverse Substitution is not permitted.


S ⟶ <noun><verb><adverb> | <noun><verb> 2. No inversion operation is permitted, for
example:, if S ⟶ AB is production, it is not
<noun> ⟶ Ram|Sham|Tom|Geeta necessary that AB ⟶ S is a production.
<verb>⟶ ran|ate|walked Remarks: The derivation of a string is complete
<adverb> ⟶ slowly|quickly when the working string can not be modified. If
the final string does not contain any variable, it is
let us denote the collection of rules given above
a sentence in the language. if the final string
by P.
contains a variable, it is a sentential form and in
If our vocabulary is thus restricted to ‘Ram’, this case the production generator gets ‘stuck’.
‘Sham’, ‘Geeta’, ‘Tom’, ‘ran’, ‘ate’, ‘walked’,
‘quickly’ and ‘slowly’, and our sentences are of Definition: The language generated by a
the form <noun><verb><adverb> and grammar G (denoted by L(G)) is defined as
{ω∈T*|S ⟹ * ω}. The elements of L(G) are called
<noun><verb>, we can describe the grammar by G
a 4-tuple. sentences L(G) is the set of all terminal strings
derived from the start symbol S.
(VN, T, P, S), where
VN = {<noun>, <verb>, <adverb>} Example:

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:

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

As we know that a CFG has no context neither P4: S ⟶ b (RHS is terminal )


left nor right. this is why, it is known as context- Hence the given grammar is CFG.
free. Many programming languages have
Leftmost derivation: for ω = a ∗ a + b
recursive structure that can be defined by CFGs.
S ⟹ S ∗ S ( using S ⟶S ∗ S)
Example: Consider a grammar G = (V, T, P, S) L
having productions. S ⟶ aSa | bSb | ∧. check the ⟹ a ∗ S ( using S ⟶ a)
L
productions and find the languages generated. ⟹ a ∗ S + S ( using S ⟶S + S )
L
Sol: let ⟹ a ∗ a + S ( using S ⟶ a )
L
P1: S ⟶ aSa (RHS is terminal variable terminal) ⟹ a ∗ a + b ( using S ⟶ b )
L
P2: S ⟶ bSb (RHS is terminal variable terminal) The last symbol from the left is b, so using S ⟶ b ).
P3: S ⟶ ∧ (RHS is null string). (Note: Leftmost variable is highlighted in each step).
Since all productions are of the form A ⟶α,
Rightmost Derivation:- for ω = a ∗ a + b.
where α ∈ (V ∪T)*. hence G is a CFG.
S ⟹ S ∗ S ( using S ⟶S ∗ S)
Language Generated: R
S ⟹ S ∗ S + S ( using S ⟶S + S)
S⟹ aSa or bSb R
S⟹ anSan or bnSbn (using n step (since, in the above sentential form second
derivation) symbol from the right is ∗ so, we can not use S
n m m n
S ⟹ a b Sb a or bnamSambn ⟶ a|b. therefore, we use S ⟶S + S ).
(using m step ⟹ S ∗ S + b (using S ⟶ b )
derivation) R
S ⟹ anbmbman or bnamambn (using ⟹ S ∗ a + b (using S ⟶ a )
R
S⟶∧ ⟹ a ∗ a + b (using S ⟶ a )
R *
So L(G) = {ωω : ω ∈ (a+b) } R
(Note: Rightmost variable is highlighted in each step).
Leftmost and Rightmost Derivation: Chomsky classification of Grammars|
Leftmost derivation: if G = (V, T, P, S) is a Languages (Chomsky Hierarchy): Noam
* chomsky has classified all grammars in four
CFG and ω ∈ L(G) then a derivation S ⟹ω is
L categories ( type 0 to type 3) based on the right
called leftmost derivation iff all steps involved in
hand side forms of the productions.
derivation have leftmost variable replacement
only. Type 3: This is most restricted type. productions
Rightmost derivation: if G = (V, T, P, S) is a of type A ⟶α or A ⟶αB|Bα. where A, B ∈ VN,
CFG and ω ∈ L(G) then a derivation S ⟹ω * is and α ∈ T are known as type 3 or regular
R
called rightmost derivation iff all steps involved grammar productions. in production of type 3. S
in derivation have rightmost variable replacement ⟶ ∧ is also allowed, if ∧ is in generated
only. language.
Example: Consider the grammar S ⟶S + S | S ∗ for example: production S ⟶ aS, S ⟶ a are type
S | a | b. find the leftmost and rightmost 3 production.
derivations for string ω = a ∗ a + b. Left-linear production: A ⟶ Ba
Sol: let Right-linear production: A ⟶ aB
P1: S ⟶S + S (RHS is variable terminal variable) a left linear or right linear grammar is called
P2: S ⟶S ∗ S (RHS is variable terminal variable) regular grammar. The language generated by a
P3: S ⟶ a (RHS is terminal ) regular grammar is known as regular language.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Leftmost derivation’s tree of previous example. Elimination of Left Recursion: let the variable
S A has left recursive productions as follows:

A ⟶ Aα1|Aα2|Aα3|…|Aαn|β1| β2| β3|…| βn


S ∗ S
Where β1, β2, …, βn do not begin with A, then we
replace A-productions by
a S + S
A ⟶ β1 A’| β2 A’| β3 A’|…| βn A’

a b Where A’⟶ α1A’| α2A’| α3A’|…| αnA’|∧.


Ambiguity: A grammar G is ambiguous if there Example: CFG E ⟶ E + T | T
exists some string ω ∈ L(G) for which there are
T⟶T∗F|F
two or more distinct derivation trees or there are
two of more distinct leftmost derivations. F ⟶ id.
i.e. Where E is the starting symbol and id is the
terminal. Remove the left recursion (if any).
Ambiguity is a negative property of a grammar
and it is usually (but not always) possible to find Sol: Recursive production are
an equivalent unambiguous grammar. An E⟶E+T , T⟶T∗F
‘inherently ambiguous language’ is a language Eliminating Left Recursion:
for which no unambiguous grammar exists.
E ⟶ E + T is replaced by E ⟶ TE’
Example of Ambiguity: Where E’ ⟶ +TE’ | ∧
S ⟶S+S|a T ⟶ T ∗ F is replaced by T ⟶ FT’
ω=a+a+a Where T’ ⟶ ∗ FT’ | ∧
Left-most derivation So, productions of G are:
a) S ⇒ S + S ⇒ a + S ⇒ a + S + S ⇒ a + a + E’ ⟶ +TE’
L L L L
S⇒a+a+a S E’ ⟶ +TE’ | ∧
L
T ⟶ FT’
T’ ⟶ ∗ FT’ | ∧
S + S
F ⟶ id.
Left Factoring: Two or more productions of a
a S + S variable A of the grammar G are said to have left
factoring if A – productions are of the form
a a A ⟶ αβ1| αβ2| αβ3|…| αβn, where βi ∈ (VN ∪ T)*
and does not start with α. All these A-productions
b) S ⇒ S + S ⇒ S + S + S ⇒ a + S + S ⇒ a
L L L L have common left factor α.
+a+S⇒a+a+a
L S Elimination of Left Factoring: let the variable A
has (left factoring) productions as follows:

S + S A ⟶ αβ1| αβ2| αβ3|…| αβn|γ1| γ2| γ3|…| γn, where


β1, β2, β3, … , βn and γ1, γ2, γ3, … , γn, do not
contain α as a prefix, then we replace A-
S + S a production by,

a a

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

A ⟶ αA’ | γ1| γ2| γ3|…| γn Removing Null productions: Consider


Where A’ ⟶ β1| β2| β3|…| βn the Null production X ⟶ ∧ & for every
non-null production
Example: Consider the grammar S ⟶ aSa | aa
Y ⟶ αXβ, where α, β ∈ (VN ∪ T )*.
and remove the left factoring ( if any).
a) Add enough productions of the form
Sol: S ⟶ aSa and S ⟶ aa, Y ⟶ αβ such that αβ ≠ ∧.
we have α = a as a left factoring, we get the b) Delete the production X ⟶ ∧.
productions:
S ⟶ aS’ Example: S ⟶ aSa | bSb | ∧.

S’ ⟶ Sa | a Sol: S ⟶ aSa | bSb | aa | bb

Removal of Ambiguity: for removing ambiguity Example: S ⟶ aS | aA | ∧, A ⟶ ∧

i) Remove the Left Recursion. Solution: S ⟶ aS | aA | a | a


ii) Remove the Left Factoring. S ⟶ aS | a
(This is heuristic approach for removal of Example: S ⟶ a | Xb | aYa,
ambiguity). X⟶Y|∧
Example: Y⟶b|X
S⟶S+S|S∗S|a|b Solution: S ⟶ a | Xb | aYa | b | aa
Sol: Step 1: X⟶Y
Find left recursive statement Y⟶b|X
S⟶S+S
Removal of Unit Production: A production of
S⟶S∗S
the type A ⟶ B, where A, B are variables is
After removing left recursion
called unit production. These productions create
S ⟶ aS’ | bS’
indirection and this result into requirement of
S’ ⟶+SS’ | ∗SS’ | ∧ extra steps in deriving the terminal strings.
Now check for ambiguous string ω =
a ∗ a + a. For example: Consider the grammar S ⟶ aA | a
S ⟹ aS’ A⟶B
S ⟹ a ∗S S’ B⟶C
S ⟹ a ∗ a S’ S’
C ⟶ aS
S ⟹ a ∗ a + a S’ S’ S’
Solution: we find S ⟹ aA ⟹ bS ⟹ aC ⟹ aaS.
S ⟹ a ∗ a + a ∧ S’ S’
It means we are getting as after two intermediate
S ⟹ a ∗ a + a ∧ S’
steps, A ⟹ B ⟹ C ⟹ aS. So, we have the
S⟹a∗a+a∧≡a∗a+a
production S ⟶ aaS, instead of A ⟶ B, B ⟶ C,
So, we conclude that removal of left recursion (
C ⟶ aS, which create indirection.
and left factoring also) helps in removal on
ambiguity of the ambiguous grammar. Steps for removing unit production.
Simplification of CFG : Step 1: Collect all the unit productions
i) Removal of Null productions:
Step 2: if A ⟹ A1 ⟹ A2 ⟹ . . . ⟹An ⟹ ω,
Definition: A production A ⟶ ∧ is called
where is string of terminals, then replace the RHS
a ‘null production’ and variable B having
* ∧ is called null variable. of A by ω and remove the productions
production B ⟹
A1 ⟶ A2 ⟶ . . . ⟶ An ⟶ ω

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Example: Consider the grammar S ⟶ aS | bS | A W2 = { A, C } ∪ { A1 | A1 ⟶ α with α ∈ ( ∑ ∪


| B, A ⟶ a, B ⟶ b remove the unit productions { A, C } )∗ }
( if any). = { A, C } ∪ { S } as we have S ⟶ CA.
Solution: we have two unit productions: S ⟶ A W3 = { A, C, S } ∪ { A1 | A1 ⟶ α with α ∈ ( ∑ ∪
and S ⟶ B and from variable A and B we get { A, C } )∗ }
terminals a and b respectively. So, replacing the = { A, C, S } ∪ ϕ = W2
occurrences of A and B variables in S
VN’ = W2 = { S, A, C }
productions, we get simplified productions:
P’ = { A1 ⟶ α|A1, α ∈ ( VN’ ∪ ∑ )∗ }
S ⟶ aS | bS | a | b.
P’ = { S ⟶ CA, A ⟶a, C ⟶b }
Removal of useless Symbol: The symbols that Thus,
can be used in any production due to their G1 = ({S, A, C} , { a, b},
unavailability in the productions or inability in { S ⟶ CA, A ⟶a, C ⟶b }, S )
deriving the terminal(s) are known as useless Step 2: W1 = { S }
symbols.
W2 = { S } ∪ { A, C } [because S ⟶ CA ]
Example: Consider the grammar S ⟶ aS | bS a | = { S, A, C }
b, A ⟶ a, B ⟶ b, in this symbols (variables) W3 = { S, A, C } ∪ { a, b} = { S, A, C, a, b}
A and B cannot be used because we can reach the [because A ⟶ a, C ⟶ b ]
variables A and B from the starting symbol S. so As W3 = VN’ ∪ T, P’’ = P’
A and B are useless symbols and these are
Therefore G’ = ({S, A, C} , { a, b}, { S ⟶ CA, A
removed from the grammar.
⟶a, C ⟶b }, S ) is reduced grammar.
Now, the simplified grammar is Example:
S ⟶ aS | bS | a | b. S ⟶ aAa, A ⟶ Sb | bCC | DaA, C ⟶ abb | DD,
Application of Grammars: E ⟶ aC, D ⟶aDa
1. Specifying syntax of programming Solution: Step 1: W1 = {c} as C ⟶ abb be
languages. production with terminals string on RHS.
2. Representation symtactic structure in W2 = {C} ∪ {E, A } as E ⟶ aC and A ⟶ bCC
natural languages, = { C, E, A }
3. Model of computation.
W3 = { C, E, A } ∪ { S } as S ⟶ aAa
Order in which defects should be Removed:
= { C, E, A, S}
1. Eliminate null productions
W4 = { C, E, A, S} ∪ ϕ = W3 ∪ ϕ = W3
2. Eliminate Unit productions
Hence
3. Eliminate non-reachable Non-terminals
VN’ = W3 = {S, A, C, E}
Reduced Form:
P’ = {S ⟶ aAa, A ⟶ Sb | bCC, C ⟶ abb, E ⟶
Example: Find the reduced grammar equivalent
aC }
to the grammar G whose productions are S ⟶AB
G1 = (VN’, {a, b}, P’, S)
| CA, B ⟶ BC | AB, A ⟶ a, C ⟶ aB|b.
Step 2: We start with W1 = { S }
Solution:
As we have S ⟶ aAa
Step 1: W1 = { A, C } as A ⟶ a and C ⟶ b be
productions with a terminal string on RHS. W2 = {S} ∪ {A, a}
As A ⟶ Sb | bCC

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

W3 = {S, A, a} ∪ { S, b, C } = {S, A, C, a, b} There is no NULL production and Unit


As we have C ⟶ abb production.
W4 = W3 ∪ {a, b} = W3 Consider P1 : Replace the terminal a by a new
Hence variable A, we get
P’’ = { A ⟶ α | A1 ∈ W3 } S ⟶ ASA,
= { S ⟶ aAa, A ⟶ Sb | bCC, C ⟶ abb} Now, replace SA by a new variable X1 and so,
Therefore S ⟶ AX1, where
G’ = ({ S, A, C} , {a, b}, P’’, S) is reduced X1 ⟶SA ( In CNF)
grammar. A ⟶ a (In CNF)
Consider P2: Replace the terminal b by a new
Normal Forms: In Context free productions, we
variable B, we get
have no restriction on RHS. If, we restrict the
RHS in different manner and this results into S ⟶ BSB, now, replace SB by a new variable Y2
different normal forms. and so, S ⟶ BY2, where
Y2⟶ SB (In CNF)
“If G is a CFG and productions of G satisfy
B ⟶ b (In CNF)
certain restrictions, then G is said to in a normal
form”. Thus grammar G is in CNF has following

Two popular and important normal forms are: productions


S ⟶ AX1 | BX2 | a | b
1. Chomsky Normal Form (CNF) and
2. Griebach Normal Form (GNF). A ⟶ a, B ⟶ b
Chomsky Normal Form: A Context-free X1 ⟶ SA, Y2 ⟶ SB.
grammar is in Chomsky Normal Form (CNF) if Example: Let G be the grammar with
every production is of one of the two types. productions
A ⟶ BC (<variable> ⟶ <Variable> < Variable> ) S ⟶ AACD
A ⟶ aAb | ∧
A ⟶ a (< variable > ⟶ <Terminal> )
C ⟶ aC | a
Where A, B and C are variables and a is a
terminal symbol. D ⟶ aDa | bDb | ∧.
Solution: Step 1: Remove the Null-productions:
Methods for converting a CFG to CNF:
The nullable Variables are A and D.
Step 1: Eliminate NULL productions
S ⟶ AACD | ACD | AAC | CD | AC | C
Step 2: Eliminate UNIT productions.
A ⟶ aAb | ab
Step 3: Change the RHS to single terminal or C ⟶ aC | a
string of two variables.
D ⟶ aDa | bDb | aa | bb
Example:
Step 2: Remove Unit – productions
S ⟶ aSa | bSb | a | b, convert it into CNF.
S ⟶ aC | a and delete S ⟶ C
Solution: Let P1 : S ⟶ aSa (Not in CNF)
Step 3: S ⟶ AACD | ACD | AAC | CD |AC | aC |
P2 : S ⟶ bSb (Not in CNF)
a A ⟶ aAb | ab
P3 : S ⟶ a ( In CNF) C ⟶ aC | a
P4 : S ⟶ b ( In CNF) D ⟶ aDa | bDb | aa |bb

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

A1 ⟶ bA3A4 | bA3 (In GNF) A4 ⟶ aA1A3A2A1A1A3A4| aA1A3A2A1A1A3


A1 ⟶ aA1A3A4| aA1A3 (In GNF) where Now, all A4-productions are in GNF. All
A4 ⟶ A2A1A3A4| A2A1A3 productions are in GNF.
(A4 is a new variable and it is a production that is Example: E ⟶ E + T | T,
not in GNF) T ⟶ T ∗ F | F,
So, now all A1-productions are in GNF. Consider F ⟶ ( E ) | a,
A2-productions:
Solution:
A2 ⟶ A3A1 (Not in GNF) Eliminate the Unit Productions
A2 ⟶ b (In GNF) T ⟶ T ∗ F | ( E ) | a,
Now, consider A2 ⟶ A3A1 and replacing A3 by E ⟶ E + T | T ∗ F |( E ) | a,
its RHS, we get The equivalent grammars without
A2 ⟶ aA1 (In GNF) unit productions is, G1 = (V, T, P1, S ),
A2 ⟶ A1A2A1 (Not in GNF) where P1 consists of
Now, consider A2 ⟶ A1A2A1 and replacing A1 i) E ⟶ E + T | T ∗ F |( E ) | a,
by its RHS, we get ii) T ⟶ T ∗ F | ( E ) | a,
A2 ⟶ bA3A4A2A1 (In GNF) iii) F ⟶ ( E ) | a,
A2 ⟶ bA3A2A1 (In GNF) Step 2: Reduce the Terminals into Variables
A2 ⟶ aA1A3A4A2A1 (In GNF) We introduce new variables A, B, C
corresponding to +, ∗, ) respectively. The
A2 ⟶ aA1A3A2A1 (In GNF)
modified productions are
So, all A2-productions are in GNF.
i) E ⟶ EAT | TBF |( EC | a,
Consider A3-productions:
ii) T ⟶ TBF |( EC | a,
A3 ⟶ a (In GNF) iii) F ⟶ ( E ) | a,
A3 ⟶ A1A2 (Not in GNF) iv) A ⟶ +,
Now, consider A3 ⟶ A1A2 and replacing A1 by v) B ⟶ ∗,
its RHS, we get vi) C⟶)
A3 ⟶ bA3A4A2 (In GNF) Step 3: The variables A, B, C, F, T and E are
renamed as A1, A2, A3, A4, A5, A6 respectively.
A3 ⟶ bA3A2 (In GNF)
The productions becomes
A3 ⟶ aA1A3A4A2 (In GNF)
A1 ⟶ + (In GNF)
A3 ⟶ aA1A3A2 (In GNF)
A2 ⟶ ∗ (In GNF)
Consider A4-productions:
A3 ⟶ ) (In GNF)
A4 ⟶ A2A1A3A4| A2A1A3 (Not in GNF)
A4 ⟶ ( A6A3 (In GNF)
Replacing A2 by its RHS, we get
A4 ⟶ a (In GNF)
A4 ⟶ bA1A3A4| bA1A3
A5 ⟶ A5A2A4 (Not in GNF)
A4 ⟶ aA1A3A4| aA1A3
A5 ⟶ ( A6 A3 (In GNF)
A4 ⟶ bA3A4A2A1A1A3A4| bA3A4A2A1A1A3
A5 ⟶ a (In GNF)
A4 ⟶ bA3A2A1A1A3A4| bA3A2A1A1A3
A6 ⟶ A6A1A5 (Not in GNF)
A4 ⟶ aA1A3A4A2A1A1A3A4| aA1A3A4A2A1A1A3

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

A6 ⟶ A5A2A4 (Not in GNF) A8 ⟶ A1A5A8 | A1A5


A6 ⟶(A6A3 (In GNF) and replacing A1 by its RHS, we get
A6 ⟶ a (In GNF) A8 ⟶ ∗A5A8 | ∗A5 (In GNF)
Production A1, A2, A3 and A4 are in GNF. Now, all the productions are in GNF. Hence
Consider production A5-production grammar is in GNF.
A5 ⟶ A5A2A4 (Not in GNF) Applications Of CFG:
and renaming left recursion, we get 1. Parser Design
2. Design of Natural Languages
A5 ⟶ ( A6 A3 A7 | ( A6 A3 (In GNF)
Construction.
A5 ⟶ aA7 | a 3. Design of Mark-up Languages.
A7 ⟶ A2A4A7 | A2A4
(A7 is a new variable and it is production that Defects in CFG:
 It may restrict the grammar from
is Not in GNF).
generating the string (No generation of
So, now all A5- productions are in GNF.
terminal)
Consider A6-productions  It may involve multiple Names and
A6 ⟶ A6A1A5 (Not in GNF) definitions so confusion.
A6 ⟶ A5A2A4 (Not in GNF)  Illegal operation (null production misused).
now, Consider A6 ⟶ A5A2A4 and replacing A5  Symbols not appearing any sentential form.
 In CFG, not necessary to use all symbols.
by its RHS, we get
Push-Down Automata
A6 ⟶ aA7A2A4 | aA2A4 (In GNF)
Push-Down Automata: A PDA is a tool to
A6 ⟶ (A6A3A7A2A4 |(A6A3A7A2A4 (In GNF)
implement context-free languages (CFLs). The
Now, Consider A6 ⟶ A6A1A5 and removing biggest drawback of finite automata is absence of
left recursion, we get memory. there is no mechanism to remember the
A6 ⟶ (A6A3A8 |(A6A3 count of Input symbol or to match.
A6 ⟶ aA8 | a let us consider L= {0n1n | n ≥ 1 } .This is a
A6 ⟶ aA7A2A4A8 | aA7A2A4 | aA2A4A8 | aA2A4 context free language but not regular.
A6 ⟶ (A6A3A7A2A4A8 |(A6A3A7A2A4 (S ⟶ 0S1 | 01 } generates L.
A6 ⟶ (A6A3A2A4A8 |(A6A3A2A4 A Finite automata cannot accept L, i.e. strings of
the form 0n1n as it has to remember the number of
All above A6 grammar are in GNF.
0’s in a string and so it will require an infinite
A8 ⟶ A1A5A8 | A1A5 (Not in GNF) number of states. this difficulty can be avoided by
(A8 is a new variable and it is production is not adding an auxiliary memory in the form of stack.
in GNF). To implement the language L on the PDA, the 0’s
So, now all A6-productions are in GNF. in the given string are added to stack. when a
symbol 1 is encountered in the Input string, 0 is
Consider A7-production
removed from the stack. thus the matching of
A 7 ⟶ A 2A 4A 7 | A 2A 4
number of 0’s and number of 1’s is done. An
and replacing A2 by its RHS, we get empty stack at the consumption of the string
A7 ⟶ +A4 | +A4A7 (In GNF) indicates the acceptance of the string by the PDA.
Consider A8-production

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

Z0 Deterministic PDA : pda is deterministic if:


Initial
Symbol Stack 1. for each q in Q and Z in Γ, whenever δ(q,
∧, Z) is non empty, then δ(q, a, Z) is
Definition (Mathematical Description of PDA) : empty for all a in ∑.
A PDA Consists of & tuple ( Q, Σ, Γ, δ, q0, Z0, F ) 2. For no q in Q, and Z in Γ, and a in Σ∪
1. Q is a finite and non-empty set of states. {∧} does δ(q, a, Z) contains more than
2. Σ is a finite and non-empty set of input one element.
alphabets. Acceptance by PDA: A PDA has final state like δ
3. Γ is a set of symbols that can be pushed into ( q0, ω, Z0 ) ⊢∗ (F, ∧, γ), γ ∈ Γ∗
the stack.
Design a PDA to accept strings with More a’s
4. δ is the transition function which maps from
than b’s.
Q × (Σ ∪ {∧ } ) × Γ to Q × Γ∗ (finite subset).
5. q0 ∈ Q is the initial (starting ) state. Solution:
6. Z0 ∈ Γ is the initial (starting) stack symbol. δ ( q0, a, Z0 ) ⊢ (q1, aZ0 )
7. F ⊆ Q is the set of final states. δ ( q0, b, Z0 ) ⊢ (q1, bZ0 )
δ ( q1, a, a ) ⊢ (q1, aa )
Moves of Push-down Automata: The move of δ ( q1, a, b ) ⊢ (q1, ∧ )
PD means that what are the options to proceed δ ( q1, b, a ) ⊢ (q1, ∧)
further after reading inputs in some state and δ ( q1, b, b ) ⊢ (q1, bb )
δ ( q 1, ∧ , a ) ⊢ (qf, a )
writing some string on the stack. PDA is basically
non-deterministic device having some finite
number of choices of moves in each situation. Design a PDA to accept the language {ancan | n ≥
1}
The move will be of two types:
Solution:
1. In first type, an Input symbol is read from δ ( q0, a, Z0 ) ⊢ (q1, aZ0 )
the tape, and depending upon the topmost δ ( q1, a, a ) ⊢ (q1, aa )
DPDA

symbol on the stack and present state, PDA δ ( q1, c, a ) ⊢ (q2, a )


has number of choices to proceed next. δ ( q2, a, a ) ⊢ (q2, ∧ )
Ex: δ ( q, a, Z ) ⊢ {(q, β ) } δ ( q2, ∧, Z0 ) ⊢ (qf, Z0 )
q ∈ Q, β ∈ Γ∗ .

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Context-Free grammar is G = {VN, T, P, S}, 4.2 For every production X ⟶ α in P, make a


design the parsing table and parse the string ω= a transition function.
+ a ∗ a. δ(q, Λ, X ) ⊢ (q, α )
productions are: 4.3 For every terminal a∈Σ, make a transition
P1 : S ⟶ F + S function.
P2 : S ⟶ F ∗ S δ(q, a, a ) ⊢ (q, Λ)
P3: S ⟶ F 4.4 To indicate the end of the string, we put a
P4 : F ⟶ a marker $ at the end of the string. this marker is
Parsing Table used to remove the initial symbol Z0 from the
push-down store to make the stack empty.
∧ a + ∗ a+ +a a∗ ∗a aa ++ +∗ ∗+ ∗∗
δ(q, $, Z0 ) ⊢ (qf, $Z0 )
S ϵ P3 ϵ ϵ P1 ϵ P2 ϵ ϵ ϵ ϵ ϵ ϵ
Design Parsing table and Top-Down parser for
F ϵ P4 ϵ ϵ P4 ϵ P4 ϵ ϵ ϵ ϵ ϵ ϵ
given productions.
S E⟶E+T
E⟶T
T⟶T∗F
F + S
T⟶F
F⟶(E)
a F ∗ S F ⟶ x1
F F ⟶ x2
a Solution:
Remove Left Recursion and Left Factoring.
b
P1 P4 P2 P4 P3 P1: E’ ⟶ +TE’
S⟶F+S⟶a+S⟶a+F∗S⟶a+a∗S⟶
P P2: E ⟶ TE’
a + a ∗ F ⟶4 a + a ∗ a.
P3: E’ ⟶ ∧
Hence the string a + a ∗ a ∈ L(G). YES P4: T’ ⟶ ∗FT’
Rules to Construct Top-Down Parser: P5: T ⟶ FT’
Step 1: Remove left recursion, if any, from the P6: T’ ⟶ ∧
production set P.
P 7: F ⟶ ( E )
Step 2: Remove the left factoring, if any, from the
P8: F ⟶ xN
production set P.
P 9: N ⟶ 1
Step 3: Since the PDA takes one symbol at a
time, reduce the given grammar into LL(1). P10: N ⟶ 2
step 4: Now design the PDA as follow: we have LL(1) grammar.
4.1 To put the starting symbol S in the pushdown E
store. make a transition function δ(q0, Λ, Z0 ) ⊢
(q, SZ0 ) (q0 ⟶ initial state) T E’

F T’ ∧

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Parsing Table: q (x2) $ TE’Z0 R16


q (x2) $ FT’E’Z0 R4
V/T ∧ x 1 2 ( ) + ∗ q (x2) $ (E)T’E’Z0 R7
E ϵ P2 ϵ ϵ P2 ϵ ϵ ϵ q x2) $ E)T’E’Z0 R13
E’ P3 ϵ ϵ ϵ ϵ ϵ P1 ϵ q x2) $ TE’)T’E’Z0 R1
T ϵ P5 ϵ ϵ P5 ϵ ϵ ϵ q x2) $ FT’E’)T’E’Z0 R4
T’ P6 ϵ ϵ ϵ ϵ ϵ ϵ P4 q x2) $ xNT’E’)T’E’Z0 R8
F ϵ P8 ϵ ϵ P7 ϵ ϵ ϵ q 2) $ NT’E’)T’E’Z0 R15
N ϵ ϵ P9 P10 ϵ ϵ ϵ ϵ q )$ 2T’E’)T’E’Z0 R10
q )$ T’E’)T’E’Z0 R12
Parser: q )$ E’)T’E’Z0 R6
q )$ )T’E’Z0 R3
Rule Input output Step q $ T’E’Z0 R14
R0 δ(q0, Λ, Z0 ) ⊢ (q, EZ0 ) 4.1 q $ E’Z0 R6
q $ Z0 R3
R1 δ(q, Λ, E) ⊢ (q, TE’ ) 4.2 qf $Z0 R18
R2 δ(q, Λ, E’) ⊢ (q, +TE’ ) 4.2
R3 δ(q, Λ, E’) ⊢ (q, ∧) 4.2
R4 δ(q, Λ, T) ⊢ (q, FT’ ) 4.2 Rules to Construct bottom-up parser:
R5 δ(q, Λ, T’) ⊢ (q, ∗FT’ ) 4.2
Rule 1: δ(q, a, Z0) ⊢ (q, aZ0) a ∈ T
R6 δ(q, Λ, T’) ⊢ (q, ∧) 4.2
R7 δ(q, Λ, F) ⊢ (q, ( E )) 4.2 Rule 2: δ(q, a, ∧) ⊢ (q, a) a ∈ T
R8 δ(q, Λ, F) ⊢ (q, xN) 4.2 Rule 3: δ(q, ∧, aR) ⊢ (q, A) a ∈ T, aR is reverse
R9 δ(q, Λ, N) ⊢ (q, 1) 4.2 of a. for each A ⟶α
R10 δ(q, Λ, N) ⊢ (q, 2) 4.2
Rule 4: δ(q, ∧, S) ⊢ (qf, ∧)
R11 δ (q, 1, 1 ) ⊢ (q, ∧) 4.3 Design bottom-up parser for given productions
R12 δ (q, 2, 2 ) ⊢ (q, ∧) 4.3
Productions:
R13 δ (q, (, ( ) ⊢ (q, ∧) 4.3
R14 δ (q, ), ) ) ⊢ (q, ∧) 4.3 E⟶E+T
R15 δ (q, x, x ) ⊢ (q, ∧) 4.3 E⟶T
R16 δ (q, +, + ) ⊢ (q, ∧) 4.3
R17 δ (q, ∗, ∗ ) ⊢ (q, ∧) 4.3 T⟶T∗F
T⟶F
R18 δ(q, $, Z0) ⊢ (qf, $Z0) 4.4
F⟶(E)
F ⟶ x1
Consider ω = x1 + (x2). parse on above PDA. F ⟶ x2
State Unread Input PushDown Rule
store used Solution:
q0 x1 + (x2) $ Z0
q x1 + (x2) $ EZ0 R0 Here E is the starting symbol and +, ∗, (, ), x1 &
q x1 + (x2) $ TE’Z0 R1 x2 are terminals. a ∈ T.
q x1 + (x2) $ FT’E’Z0 R4
q x1 + (x2) $ xNT’E’Z0 R8 Pro Input Output R
q 1 + (x2) $ NT’E’Z0 R15 duc ul
q 1 + (x2) $ 1T’E’Z0 R9 tio e
q + (x2) $ T’E’Z0 R11 ns
q + (x2) $ E’Z0 R6 P1 δ(q, a, Z0) ⊢ (q,aZ0) 1
q + (x2) $ +TE’Z0 R2 P2 δ(q, a, ∧) ⊢ (q, a) 2

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

P3 δ(q, ∧, ⊢ (q, E) 3 E⟶E+T Design a CFG for the language L = { 0n12n | n≥


T+E) 0}
P4 δ(q, ∧, T) ⊢ (q, E) 3 E⟶T
Solution: At n = 0, ∈ becomes a valid string in
P5 δ(q, ∧, ⊢ (q, T) 3 T⟶T∗F
F∗T) the language L. The corresponding production is
P6 δ(q, ∧, F) ⊢ (q, T) 3 T⟶F S → ∈.
P7 δ(q, ∧,)E() ⊢ (q, F) 3 F⟶(E) To incorporate the double numbers of 1s as 0s,
P8 δ(q, ∧, 1x) ⊢ (q, F) 3 F ⟶ x1 the production used in S → 0S11. Every
P9 δ(q, ∧, 2x) ⊢ (q, F) 3 F ⟶ x2 transitive substitution of S inserts double the
P10 δ(q, ∧, E) ⊢ (qf, ∧) 4
number of 1s following 0s.
S → ∈ | 0S11 | 011
Consider ω = x1 +( x2) parse on PDA.
Design a CFG for the language L over { 0, 1 } to
Sta Rest of Stack action Produ generate all possible strings of even length.
te Input ction
Solution: The number 0 is considered to be even.
q x1 + ( x2) Z0
q 1 + (x2) x Z0 Shift P1 The string of length 0 is ∈ and the corresponding
q + (x2) 1x Z0 Shift P2 production is S → ∈. A String of length 2 over
q +( x2) F Z0 Reduce P8 {0, 1} consists of one of the strings 00, 01, 10, or
q + (x2) T Z0 Reduce P6 11. The corresponding productions are S → 00 |
q + (x2) E Z0 Reduce P4 01 | 10 | 11.
q (x2) +E Z0 Shift P2
q x2) (+E Z0 Shift P2 An even length of string of length 2n ( n > 1 )
q 2) x(+E Z0 Shift P2 contains one or more repetitions of the strings 00,
q ) 2x(+E Z0 Shift P2 01, 10, or 11. The corresponding productions are
q ) F(+E Z0 Reduce P9 S → 00 | 01 | 10 | 11.
q ) T(+E Z0 Reduce P6
q ) E(+E Z0 Reduce P4 Hence, the productions set for the CFG G
q ∧ )E(+E Z0 Shift P2 corresponding to the CFL L is
q ∧ F+E Z0 Reduce P7 S → ∈ | 00 | 01 | 10 | 11 | 00S | 01S | 10S | 11S
q ∧ T+EZ0 Reduce P6
q ∧ EZ0 Reduce P3 Design a CFG for the language L over {0, 1} to
qf ∧ Z0 Reduce P10 generate all the strings having alternate sequence
of 0 and 1.
Design a CFG for the language L = {0n1n | n ≥ 0 } Solution: The minimum string length in L is 2.
Solution: At n = 0, ∈ becomes a valid string in The corresponding strings are 01 or 10. If a string
the language L. The corresponding production is ω in L begins with 01, then it should follow a
S → ∈. repetition of 01 and terminate with either 01 or 0,
To incorporate the equal numbers of 0s and 1s, and if it begins with 10, then it should follow a
the production used is S → 0S1. Every transitive repetition of 10 and terminate either with 10 or 1.
substitution of S inserts an equal number of 0s The corresponding productions in CFG are
and 1s. S → 01 | 10 | 01A | 10B
Hence, the production set for the CFG G A → 01A | 0 | 01
corresponding to CFL L is B → 10B | 1 | 10
S → ∈ | 0S1 | 01

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Design a CFG generating the set of odd-length S ⟶ BCD


strings in {a, b }* with middle symbol a. B ⟶ 0B1 | Λ
Solution: S → aSa | aSb | bSa | bSb | a. D ⟶ 1D0 | Λ
Design a CFG generating the set of even-length C ⟶ 1 | 1C
strings in {a, b }* with the two middle symbols.
Turing Machine
Solution: S → aSa | aSb | bSa | bSb | aa | bb
We need such machines that can perform
Design a CFG generating the set of odd-length recognizing as well as computation. Without
strings in {a, b}* whose first, middle, and last computational capability a machine is not much
symbols are all the same. useful as desired. We have computer system,
Solution: S → aTa | bUb which is capable of doing recognizing as well as
computational. so, we are interested in designing
T → aTa | aTb | bTa | bTb | a
of an automaton(machine) that can solve both
U → aUa | aUb | bUa | bUb | b.
objectives.
Design the CFG equivalent to a Regular
1. Recognizing
Expression ( 011 + 1 )* (01)*.
2. Computation
Solution: S → AC
A ⟶ Λ|BA A Turing machine is a generalization of a PDA,
B ⟶ 011 | 1 which uses a ∞-tape instead of ‘a tape and stack’.
C ⟶ Λ | DC the potential length of the tape is assumed to be
infinite and divided into cells. One cell can hold
D ⟶ 01
one input symbol. The head of TM is capable to
Design the CFG equivalent to a Regular read as well as write on the tape and move left or
Expression ( 100 + 1 ) ( 1 )* ( 011 + 1 )+ Solution: right or remain stationary. Turing machines
S ⟶ ABD accept the languages are known as type 0
A ⟶ 100 | 1 languages or the recursively enumerable (RE)
B ⟶ Λ |1B languages.
C ⟶ D | DC
Note: One thesis called Church’s thesis support
D ⟶ 011 | 1
the fact that a Turing machine can simulate the
Design the CFG equivalent to language L = { behavior of a general-purpose computer system.
0i1j0k | j = I + k } The church-turing thesis states that any algorithm
Solution: L = 0i 1i+k 0k procedure that can be carried out by human
begins/computer can be carried out by turing
0i 1i 1k 0k
machine. It has been universally accepted by
S ⟶ AB
computer scientist that the turing machine
A ⟶ 0A1 | Λ
provides an ideal theoretical model of a
B ⟶ 1B0 | Λ computer.
Design the CFG equivalent to language L = {
Model of a Turing Machine: The turing
0i1j0k | j > i + k }
machine can be thought of as finite control
Solution: j = i + j + k
connected to a R/W head. It has one tape which is
0i 1i+j+k 0k
divided into a number of cells. The block diagram
0i 1i 1m 1k 0k
of the basic model for Turing is

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

β β β α1 α2 αn β β β Depending upon the number of moves in


transition, a TM be deterministic or non-
deterministic. If TM has almost one move in a
Read/ Write Finite state Infinite Tape transition then it is called deterministic TM
Head Control (DTM), if one or more than one move is in a
transition table it is called non-deterministic TM
Each cell can store only one symbol. The input to (NTM). A standard TM reads one cell of the tape
and output from the the finite state automaton are and changes its state (optional) and moves left or
effected by the R/W head which can examine one right one cell.
cell at a time. In one move, the machine examines
The halt state(h) means the stopping point of
the present symbol under the R/W head on the
processing by a TM when TM processes some
tape and the present state of an automaton to
input then TM may fall into one of these given
determine
below:
i. a new symbol to be written on the tape in
a. Halting State(h)
the cell under the R/W head.
b. Non-Halting State( non-final)
ii. a motion of the R/W head along the tape:
c. Loop (finite or infinite)
either the head moves one cell left(L), or
d. Crash and
one cell right(R).
e. Hang State (Undefined Transition)
iii. The next state of the automaton, and
iv. Whether to half or not. When TM reads inputs on the tape then it keeps
write on the tape and when it halts or stops the
Mathematical description of a Turing Machine: processing then whatever written on the tape is
A Turing Machine M is described by 7-tuple the output of the TM. So, we have no need to
namely (Q, Σ, Γ, δ, q0, β, F), where have final states as such. When TM does not stop
its processing and it is on for infinite time this
i. Q is a finite non empty set of states. situation is known as infinite loop and when head
ii. Σ is a non empty set of symbols, damages the tape then it is known as crash. for
iii. Γ is a finite non-empty set of symbols some input, if TM does not decide what to do,
including β. β ∪ Σ = Γ, then we will say that TM is in hang state. A TM
iv. δ is a transition function which maps can stop its processing in halting state or in non-
from Q × Γ to Q × Γ × (L|R|S) halting states.
i.e. (q, x) ⊢ (q’, y, D ) D is direction of
movement of R/W head: D= L or R or S Halting Problem: A turing machine accepts a
according as the movement is to the left language means that the TM will stop eventually
or right or stationary. in a halting state for each word that is in the
Note: i. The acceptability of a string is language. Halting state does not mean the
decided by the reachability from the initial accepting state but it is additional state similar to
state to some final state. accepting state. However, if the word is not in the
ii. δ may not be defined for some elements language then Turing machine may stop in
of Q × Γ. halting or non-halting state or loop forever or
v. q0 ∈ Q is the initial state. crash. In this case, we can never be sure whether
vi. β ∈ Γ represent the blank on the tape, the given word is accepted or rejected i.e. the
vii. F is set of final states. Turing machine does not decide the word
problem (known as halting problem of TM).

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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.

For example: Solution:


State a b β
5
1. 5 is represented by 0 as shown in figure. ⟶q0 q1, a, R q0, b, R ___
β β β 0 0 0 0 0 β β β q1 q1, a, R q2, b, R ___
q2 q1, a, R q3, b, R ___
q3 q1, a, R q0, b, R qf, β, L
2. integers 2 and 4 are represented by 02104 as
*qf ___ ___ ___
shown in figure.
β β β 0 0 1 0 0 0 0 β β β Transition Graph:

Note: If f1 is defined for all the arguments a1, b, b, R a, a, R a, a, R


a2, . . . ,an then f1 is known as total recursive a, a, R b, b, R b, b, R β, β, L
function. “The total recursive function is q0 q1 q2 q3 q4
a, a, R
analogous to recursive langages”. A function
b, b, R
f(a1, a2, . . . , an) computed by a TM is known as
partial recursive function analogous to the TM for L = (a + b )*abb
recursive enumerable set (RE languages).
Problem: Design a TM for finding n mod 2.
TM Computable Functions Solution:
State 0 β
⟶q0 q0, 0 , R q1, β, L
Total Recursive Functions Partial Recursive Functions q1 q2, β, L qf, β, L
Recursive Languages Recursive Enumerable Languages q2 q1, β, L q3, β, R
q3 __ qf, 0, L
Input Process Input Process *qf __ __
TM Always Halts TM may or may not Halt
Transition Graph For n mod 2
0, 0, L β, β, L
UNIVERSAL TURING MACHINE (UTM):
A Universal Turing machine is a specific Turing β, β, L 0, β, L β, β, R β, 0, L
machine that can simulate the behavior of any 0, β, L

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

2. The R/W head keeps moving towards the


The Encoding of a simple TM (The Encoding right till the input string is crossed and the
function e): First we associate to each tape first blank symbol β after the string is
symbol (including β), to each state (including reached.
accepting and rejecting ) and to each of the three 3. From this blank, turn one cell left and reach
directions, a string of 0;s. let the last symbol of the input string. If it is 1,
S(β) =0 convert it into a blank.
S ( ai) = 0i+1 4. Now, after converting the last 1 symbol to β,
Result of String the R/W head keeps moving towards the left
S(A) = 0 Acceptance
till a blank symbol β is reached.
S(R) = 00 Rejection
States 5. As the first blank is found move the head
S(qi) = 0i+2 State on the TM toward right and repeat step 1 to step 4 till all
Direction 0’s are cancelled by the corresponding 1’s.
S(S) = 0 Stationary Direction on TM 6. If the cancellation process is completed
S(L) = 00 Left Direction on TM successfully, then the string is accepted,
S(R) = 000 Right Direction on TM otherwise there are residual un-cancelled 0s
and 1s, then the string is not accepted.
Problem: Design a TM over Σ = {1} to accept
the language L = { 1m | m is odd }. Current Input Symbol
Solution: State ↓ 0 1 β
State ↓ 1 β ⟶q0 (q1, β, R ) __ __
⟶q0 q1, 1, R __ q1 (q1, 0, R ) (q1, 1, R ) (q2, β, L )
*q1 q0, 1, R __ q2 __ (q3, β, L )
q3 (q3, 0, L ) (q3, 1, L ) (q4, β, R )
The asterisk (*) before q1 indicates that q1 is q4 (q1, β, R ) __ (qf, β, R )
*qf __ __ __
a final state.
let consider the string 1111 Design a Turing Machine over Σ = { 0 } to accept
ββq01111ββ ⟶ ββ1q1111ββ ⟶ ββ11q011ββ ⟶ the language L = {0m | m is even}.
ββ111q11ββ ⟶ ββ1111q0ββ Solution: The problem is similar to the previous
Since the TM halts on q0, the string 1111 is one. The only change is that now q0 is a final
not accepted. state and q1 is non-final state. The transition table
Transition Graph: shown in table provides the complete set of
1, 1, R
transition function.
q0 *q1
1, 1, R Current Input Symbol
Problem: Design TM over Σ = {0, 1} to accept state ↓ 0 β
⟶∗q0 (q1, 0 , R) __
the language L = {0m 1m | m > 0 }.
q1 (q0, 0 , R) __
Solution: The example strings in the language L
are 01, 0011, 000111, 00001111, . . . Design a Turing machine over Σ = {0} to accept
let the string be 000111 the language L = { 0m | m is multiple of 3}.
Solution: The example strings in the language L
The string recognition process of the TM is: are ϵ, 000, 000000, 000000000, … Normally, the
R/W head points to the first 0 of the input string
1. Read the first symbol 0 of the string and
ω in the state q0. If the length of the string ω,
convert this 0 to blank(β).
|ω| = 0, then it is a null string and the R/W

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

points to an arbitrary blank on the Turing tape Current Input Symbol


in the state q0. In this case, the Turing machine State ↓ 0 1 β
halts. Since zero is a multiple of 3, the Turing ⟶q0 (q1, β, R) __ __
q1 (q1, 0, R) (q1, 1, R) (q2, β, L)
machine has to halt in the final state.
q2 __ (q3, β, L) __
Therefore, q0 is declared as a final state. q3 __ (q4, β, L) __
q4 __ (q5, 1, L) (q6, β, R)
Current Input Symbol
q5 (q5, 0, L) (q5, 1, L) (q0, β, R)
state ↓ 0 β
q6 __ __ (qf, β, R)
⟶∗q0 (q1, 0 , R) __
*qf __ __ __
q1 (q2, 0 , R) __
q2 (q0, 0 , R) __ Design a Turing machine to compute m – n
Design a Turing machine over Σ = { 0, 1} to where m and n are positive integers and m > n.
accept the language L = { 0m12m | m > 0}. Current Input Symbol
Solution: The example strings in the language L State ↓ 0 1 β
⟶q0 (q1, β, R) __ __
are 011, 001111, 000111111,… The r/w head
q1 (q1, 0, R) (q1, 1, R) __
points to the first symbol of the input string in the q2 __
(q2, 0, R) (q3, β, L)
string in the state q0. q3 (q4, β, L) (qf, 0, L) __
The recognition process of the string on the q4 (q4, 0, L) (q5, 1, L) __
Turing machine is as follows: q5 (q5, 0, L) __ (q6, β, R)
q6 (q1, β, R) __ __
1. The r/w head reads the first symbol 0 of the *qf __ __ __
input string and converts this 0 into a blank (β).
2. The r/w head keeps moving towards the
Design a Turing machine to compute m  n
right till the input string is crossed and the
where m and n are positive integers.
first blank after the string is reached.
3. From this blank, the r/w head turns one cell Curren Input State
to the left and reaches the last symbol of the State↓ 0 1 x y β
input string. If the last two symbols in the ⟶q0 (q1 ,x, R) (q9 ,1,L ) __ __ __
string are 11, then the match occurs. q1 (q1,0,R) (q2,1,R) __ __ __
a. If the match occurs, then the r/w q2 (q 3 ,y,R) (q 7 ,1,L) __ __ __
q3 (q3,0,R) (q4,1,R) __ __ __
head converts both 1 symbols to q4 (q4,0,R) __ __ __ (q5,0,L)
blanks one by one. The r/w head
traverses back to the beginning of the
remaining string and perform the q5 (q5,0,L) (q6,1,L) __ __ __
matching and cancellation of one 0 by q6 (q 6 ,0,L) __ __ (q 2,y,R) __
11. This process is repeated till all 0s q7 __ (q8,1,L) __ (q7,0,L) __
q8 (q8,0,L) __ (q0,x,R) __ __
are matched by the corresponding 11
q9 __ __ (q9,0,L) __ (qf. β, R)
pair. If this occurs, then it indicates
the acceptance of the string.
b. If the match does not occur at any *qf __ __ __ __ __
stage, the process stops in a non-final
state and indicates the rejection of the
string.

The transition table is:

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

Design a TM over Σ = {a, b} to accept the and w = u1 u2 u3. . . un = v1 v2 v3 . . . vn for some n


language L = {wwR | w ∈ (a, b)* } > 0. The selected pairs (u1, v1), (u2, v2), . . . , (un,
Solution: vn) are not necessary distinct.
Current Input Symbol Let string u1 u2 u3. . . un are in U and string v1 v2
State ↓ a b β v3 . . . vn are in V, then
⟶q0 (q1, β, R ) (q4, β, R ) (qf, β, R )
q1 (q1, a, R ) (q1, b, R ) (q2, β, L ) U = { u1 u2 u3. . . um } and V = { v1 v2 v3 . . . vm}
q2 (q3, β, L ) for some m>0.
q3 (q3, a, L ) (q3, b, L ) (q0, β, R ) PCP is to determine whether there is any match
q4 (q4, a, R ) (q4, b, R ) (q5, β, R ) or not for a given correspondence system.
q5 __ (q3, β, L ) __
*qf __ __ __ The PCP is to determine whether or not there
exist I, where 1 ≤ i ≤ m such that
Design a TM to compute m+n where m and n are ui1. . . uin = vi1. . . vin
positive integers. Example: Does the PCP with two lists u = (b,
Sol: Initially two integers m and n are separated bab3, ba ) and v = (b3, ba, a ) have a solution.
by ‘1’ symbol on the Turing tape. bab3 b b ba = ba b3 b3 a
u2 u1 u1 u3 v2 v1 v1 v3
β β β 0 0 0 1 0 0 0 0 0 β β β
The numbers to be added 3 and 5.
Example: Does the PCP given below have a
After the addition operation, the Turing tape solution?
contains the result of addition.
1 2 3 4 5
β β β 0 0 0 0 0 0 0 0 β β β ui 10 01 0 100 1
vi 101 100 10 0 010
Current Input Symbol
State ↓ 0 1 β Solution:
⟶q0 (q0, 0, R ) (q1, 0, R ) __
q1 (q1, 0, R ) __ (q2, β, R ) 10 1 01 0 100 100 0 100
q2 (qf, β, L ) __ __ 101 010 100 10 0 0 10 0
*qf __ __ __ 1 5 2 3 4 4 3 4

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.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

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

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

U32 {2, 4, 7} = 4, U31 {2, 4, 7} = 2, U33 {2, 4, Solution:


7} = 7 f(0) = 1 and f(n+1) = h(n, f(n))
where h(x,y) = S(x) ∗ y.
Zero function Z defined by Z(x) = 0.
Definition: A total function over N is called
Successor function S defined by S(x) = x+1.
primitive recursive.
Projection function UNi{x1, x2, . . . ,xN) = xi
1. If it is any one of the three initial functions,
The initial functions over Σ are given below.
or
nil(abab) = ∧ 2. If it can be obtained by applying composition
cons a(abab) = aabab and recursion a finite number of times to the
cons b(abab) = babab set of initial functions.
nil(x) = ∧
Example: Show that the function f1(x, y) = x
cons a(x) = ax
+ y is primitive recursive OR
cons b(x) = bx
addition function of two integers are
Note: we note that cons a(x) and cons b(x)
primitive recursive.
simply denote the concatenation of the
Solution: f1 is a function of two variables.
‘constant’ string a and x, and concatenation of If we want f1 to be defined by recursion, f1
the ‘constat’ string b and x. for x and y (in equation).
definition: If f1, f2, . . . , fn are partial f1(m, 0 ) = m
functions of n variables and g is a partial f1( m , n+1) = f(m, n ) + 1 = S(f1(m, n))
function of k variables then the composition for example. consider f1(5, 2)
of g with f1, f2, . . . , fk is a partial function of n f1(5, 2) = S(f1(5, 1))
variables defined by g(f1(x1, x2, . . . ,xn),f2(x1, = f1(5, 1,) + 1
x2, . . . ,xn), . . . , fk(x1, x2, . . . , xn)). = S(f1(5, 0 )) + 1
Example: let f1(x, y ) = x + y, = f1(5, 0 ) + 1 + 1
f2( x, y ) = 2x, =5+1+1
f3 ( x, y ) = xy and = 7.
g(x, y, z) = x + y + z be a function over N. Hence f1 is a primitive recursive function.
then g(f1(x, y ), f2(x, y ), f3(x, y) ) = g(x + y,
Example: The function f2(x, y) x ∗ y is primitive
2x, xy ) = x + y + 2x + xy.
recursive.
Example:
Solution: As multiplication of Two natural
let f1 (x1, x2) = x1x2, number is simply repeated addition, f2 has to be
f2(x1, x2 ) = ∧ primitive recursive. we prove this as follow
f3 (x1, x2 ) = x1 and f2(x, 0 ) = 0
g(x1, x2, x3 ) = x2x3 be the function over Σ. f2(x, y+1) = x ∗ (y + 1)
Then g(f1(x1, x2 ), f2(x1, x2 ), f3(x1, x2) )
= f2(x, y ) + x
= g(x1x2, ∧, x1 ) = ∧x1 = x1
= f1( f2 ( x, y ), x)
Example:
Example: Show that the concatenation of two
Define n! by recursion string over {a, b} is primitive recursive.

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

solution: and behavior of the algorithm usually depends on


we have defined concatenation as the input size. Algorithm may consist of various
number of loops, nested or in sequence. The HP
f(∧, w2 ) = w2
asks the question:
f( a1, a2, . . . ,an, w2 ) = a1f1(a2, . . . ,an, w2 ) where
w1, w2 ∈Σ*. Given a program and an input to the program,
we defined f using initial functions a follows: determine if the program will eventually stop
when it is given that input?
f(∧, w1 ) = cons ∧(w1) = w1 and
f( a1, a2, . . . ,an, w2 ) = cons a1 (f(a2, . . . ,an, w2 )) One thing we can do here to find the solution of
HP. let the program run with the given input and
for example, consider f(ab, cd),
if the program stops and we conclude that
f(ab, cd) = cons a f(b, cd) problem is solved. But, if the program does not
= af(b, cd) stop on a reasonable amount of time, we can not
= acons bf(∧, cd) conclude that it would not stop. The question is:
“How long we can wait… ?”. The waiting time
= ab f(∧, cd)
may be long enough to exhaust whole life. So, we
= abcd (since f(a,w1) = w1 ) can not take it as easier as it seems to be we want
Hence concatenation is primitive recursive specific answer either “YES” or “NO”, and hence
function. some algorithm to decide answer.
Application of FA:
The importance of the halting problem lies in the
1. NFA and DFA are used in passes parser
construction of Compliers. fact that it is the first problem which was proved
2. Pattern Recognition undecidable.
3. Programming language processing -in
scanning phase of compilation for CHURCH’S Thesis: A FA is a device having
recognizing tokens. finite states and operates on a string of symbols
4. Text pattern matching with the fixed and finite set of rules. A PDA and
5. Signal processing TM are more powerful machines than FA. A TM
6. Design Controllers for systems (Washing captures behaviors of FA and PDA as well as
Machines, Industrial processes).
general-purpose computer system. We take TM
to be equivalent to an algorithm. Nothing will be
Detail (Halting Problem): The halting problem considered as algorithm if it can not be
is a decision problem which is informally stated implemented as a TM.
as follows:
The principle that TMs are formal versions of
“Given a description of an algorithm and a algorithms and no computational procedure will
description of its initial arguments, determine be considered as an algorithm unless it can be
whether the algorithm, when executed with these implemented as a TM is known as church’s
arguments, ever halts. The alternative is that a thesis.
given algorithm runs forever without halting.
According to the church’s thesis, behavior of a
Alan Turing proved in 1936 that there is no general purpose computer can be simulated by
general method or algorithm which can solve the some TM. It is a thesis, not a theorem because it
halting problem for all possible inputs. An is not a mathematical result. As we have
infinite or finite in length depending on the input discussed that a TM can perform all the

Downloaded by Michael Mangahas ([email protected])


lOMoARcPSD|28454638

computations (recognization and computation)


which are carried out by a general-purpose digital
computer.

Allan Turing also suggested in his Turing’s thesis


“Any computation that can be performed by
mechanical means can also be performed by
some TM”. Again, we have to define terms
“mechanical means”. If we consider this, then the
model of TM comes true.

Some arguments for accepting the church’s thesis


are as follows:

1. No one has been able to suggest a counter


example to disprove it till now.
2. Some TMs can also perform anything
that can be performed by digital
computer.

There are several alternate models of computation


like random access machine (RAM), Post
machine(PM) etc., but none is more powerful than
TM.

For more Notes Follow http://www.edutechlearners.com

Downloaded by Michael Mangahas ([email protected])

You might also like