Regular Grammar
Regular Grammar
Regular Language
Regular expressions
To prove this theorem one must prove that for given regular
grammar it is possible to construct equivalent FSM or from FSM
it is possible to get the regular grammar
Method for conversion from Regular Grammar to
FSM
• Create in M a separate state for each non terminal in V.
• Make the state corresponding to S the start state.
• If there are any rules in R of the form X → w, for some w € ∑
then create an additional state labelled #.
• For each rule of the form X → wY, add a transition from X to Y
labelled w.
• For each rule of the form X → w, add a transition from X to #
labelled w.
• For each rule of the form X → ɛ, mark state X as accepting.
• Mark state # as accepting.
Method for conversion from FSM to Regular
Grammar
• Conversion from FSM to regular Grammar
Regular. A simple FSM with five states just counts the total number
of characters.
Not Regular. L consists of all strings of the form a*b* where the
number of a’s is five more than the number of b’s. So we need infinite
number of states to model this.
Closure Properties of Regular Languages
and L2 = L(R2).
By the definition of RE
L1U L2.
regular language.
language.
h(L) = { h(w) : w € L }
A homomorphism of regular languages is regular
Proof: by counter example
Let L is a regular language, we have to prove that h(L) is
also regular.
∑ = { a, b} and string w = abab
h(a) = 00
h(b) = 11
regular language.
The inverse homomorphism of regular language is regular
Let h-1(L) = { w : w € L }
• If L is regular then we know that h(L) is also regular.
• Since L is regular there exists some FSM
M = ( K, ∑, δ, s, A) which accepts L.
• Then h(L) must also accepted by M.
• For complement of L ie: ¬L is also regular which is accepted
by FSM M’ where Final states of M becomes non final states
and all the non final states of M become the final states.
• Clearly ¬L is accepted’ by M.
• The inverse homomorphic language of ¬L is h-1 (L) is also
accepted by M’.
• So , h-1 (L) is also regular.
Pumping Lemma For Regular Languages
(To show languages are not regular)
To show that a language is regular
• A regular expression .
• FSM .
• A finite list of the equivalence classes of ~ L
• A regular grammar
• By using the closure properties that we have
proved hold for the regular languages.
To show that languages are not regular:
• Every regular language L can be accepted by an FSM
M with a finite number of states.
• If L is infinite, then there must be at least one loop in
M.
• All sufficiently long strings in L must be characterized
by one or more repeating patterns corresponding to
the substrings that drive M through its loops.
Consider the following 5 state FSM:
• It can accept infinite number of strings.
Theorem:
Let L be a regular language. Then there exists a constant
‘k’
(number of states in FSM which depends on L) such that
for every string ‘w’ in L such that |w| ≥ k, we can break w
into three strings, w = xyz, such that:
|y| > 0 ie: y ≠ ε
|xy| ≤ k
For all q ≥ 0, the string xyqz is also in L
Proof
Suppose L = L(M) for some DFSM ‘M’ and L is regular
language.
Suppose ‘M’ has ’k’ number of states.
Consider any string w = a1a2a3………………..am of length ’m’
where m ≥ k
• Since |w| ≥ k, by the pigeonhole principle it is not
possible to have distinct transitions, since there are only
‘k’ different states. So one of the state can have a loop.
• Different integers i and j with 0 ≤ i < j ≤ k, such that qi = qj.
Now we can break the string w = xyz as follows:
x = a1a2a3……………..ai.
y = ai+1, ai+2, ……..aj ( loop string where i = j)
z = aj+1, aj+2,…………..am.
• x’ may be empty in the case that i= 0. Also ‘z’ may be
empty if j = k = m. However, y cannot be empty,
since ‘i’ is strictly less than ‘j’.
• Thus for any integer q ≥ 0, xyqz is also accepted by
DFSM ‘M’; that is for a language L to be a regular,
xyqz is also in L for all q ≥ 0.
Show that L = { anbn | n ≥ 0 } is not regular
• Assume that given language L is regular language and
there exist some ‘k’ number of states
• Let w = ak bk Since |w| = k + k = 2k ≥ k, we can split
‘w’ into xyz such that |xy| ≤ k and |y | ≥ 1 as
w = xyz
• Since |xy| <= k, y must occur within the first k
characters and so y = ap for some p. Also y ≠ε,
p must be greater than 0.
x = ak – p y = ap z = bk
• According to pumping lemma, language to be
regular, xyqz € L for all q ≥ 0.
• Let q =2 and the resulting string w = ak – p (ap)2 bk
where p ≥ 1 = ak + p bk must be in L.
• But it is not since it has more a’s than more b’s.
• Thus there exists at least one long string w in L that
fails to satisfy the conditions of the Pumping
Theorem. So anbn | n ≥ 0 is not regular.