SlideShare a Scribd company logo
1 of 53
Grammar
 A grammar G is a quadruple (V, Σ, R, S), where:
 V is the rule alphabet, which contains nonterminals
(symbols that are used in the grammar but that do not
appear in strings in the language) and terminals
(symbols that can appear in strings generated by G),
 Σ (the set of terminals) is a subset of V,
 R (the set of rules) is a finite set of rules of the form
αβ,
 S (the start symbol) is a nonterminal.
1
Chomsky Hierarchy
 Types of Grammar:
1. Type 0 grammar(Phrase Structured Grammar)
2. Type 1 grammar(Context Sensitive Grammar)
3. Type 2 grammar(Context Free Grammar)
4. Type 3 grammar(Regular Grammar)
2
Phrase Structured Grammar
 A Phrase Structured Grammar/ Unrestricted Grammar / Type 0 Grammar G
is a quadruple (V, Σ, R, S), where:
 V is the rule alphabet, which contains non terminals and terminals.
 Σ (the set of terminals) is a subset of V,
 R (the set of rules) is a finite set of rules of the form αβ,
 S (the start symbol) is a nonterminal.
 Here, all rules in R must:
 αβ,
 Where, α Ꞓ(VUT)+ and β Ꞓ(VUT)*
 Eg: S  aAb | ε
aAbAA
bAa
 Language: Recursively Enumerable Language
 Machine: Turing Machine
 Most Powerful grammar. 3
Context Sensitive Grammar
 A Context Sensitive Grammar / Type 1 G is a quadruple (V, Σ, R, S), where:
 V is the rule alphabet, which contains non terminals and terminals,
 Σ (the set of terminals) is a subset of V,
 R (the set of rules) is a finite set of rules of the form αβ,
 S (the start symbol) is a nonterminal.
 In a Context Sensitive Grammar, rules :
 There is restriction on the length of β. The length of β should be at least as
much as the length of α. |β| ≥ |α|
 α and β Ꞓ (VUT)+. i.e. ε cannot appear on LHS or RHS of any rule. It is an
ε-free grammar.
 Machine: Linear Bounded Automata
 Language: Context Sensitive Language
 Eg: SaAb
aAbAA
bAaa 4
Context Free Grammar
 A Context Free Grammar/ Type 2 Grammar G is a quadruple (V, Σ, R, S),
where:
 V is the rule alphabet, which contains non terminals and terminals,
 Σ (the set of terminals) is a subset of V,
 R (the set of rules) is a finite set of rules of the form Aα,
 S (the start symbol) is a nonterminal.
 In a context free grammar, all rules in R must be of the form:
 A α, Where
 A Single Nonterminal & αꞒ(VUT)*
 Machine: Push Down Automata
 Language: Context Free Language
 Eg:- SaB/bA/ε
AaA/b
BbB/a/ ε
5
Regular Grammar
 A regular grammar G is a quadruple (V, Σ, R, S), where:
 V is the rule alphabet, which contains nonterminals (symbols that are used in
the grammar but that do not appear in strings in the language) and terminals
(symbols that can appear in strings generated by G),
 Σ (the set of terminals) is a subset of V,
 R (the set of rules) is a finite set of rules of the form αβ,
 S (the start symbol) is a nonterminal.
 In a regular grammar, all rules in R must:
 have a left-hand side that is a single nonterminal, and
 have a right-hand side that is ε or a single terminal or a single terminal followed
by a single nonterminal.
 So S → a, S → ε, and T → aS are legal rules in a regular grammar.
 Machine: Finite Automata
 Language: Regular language
6
Finite State Machine to
Regular Grammar
 Procedure:
 V(Nonterminals): States of DFSM
 Σ(Terminals): Alphabets of DFSM
 S=q0 i.e., start state of DFSM is start
symbol of grammar
 Rules:
 If δ(qi,a)=qj then introduce the rule as: qiaqj
 If q Ꞓ F i.e., if q is the final state in FSM, then
introduce the rule as: qε
7
Obtain a grammar to generate
string of any numbers of a’s
 Transition: Rules:
 S is a final State Sε
 δ(S,a)=S SaS
SO, the Grammar is:
SaS / ε
OR SaS
S ε
Language generated is: L={an:n ≥0}
8
S
a
Obtain a grammar to generate
string of at least one a.
 Transition: Rules:
 A is a final State A ε
 δ(S,a)=A SaA
 δ(A,a)=A AaA
So, the Grammar is:
SaA
AaA/ε
Language generated is: L={an:n ≥1}
9
A
a
S a
Obtain a grammar to generate
string of any no. of a’s and b’s.
 Transition: Rules:
 S is a final State Sε
 δ(S,a)=S SaS
 δ(S,b)=S SbS
So, the Grammar is:
SaS/ bS/ε
Language generated is: L={(a+b)n:n ≥0}
10
S
a,b
Obtain a grammar to generate
string of at least two a’s
 Transition: Rules:
 B is a final State Bε
 δ(S,a)=A SaA
 δ(A,a)=B AaB
 δ(B,a)=B BaB
So, the Grammar is:
SaA
A aB
BaB/ε 11
B
S a
a
A
a
Obtain a grammar to generate
string of at multiple’s of three a’s
 SaA / ε
 A->aB
 BaS
12
B
S a
a
A
a
 Transitions Rules
 δ(S,a)=A SaA
 δ(A,a)=S AaS
 S is final state Sε
G=(V, Σ, R,S)
V={S,A,a}
Σ ={a}
S is start symbol
R={SaA/ ε
AaS}
13
 Obtain a grammar to accept the
language L={w:|w|mod 3>0, wꞒ{a}*}
14
B
a
a
A
a
S
Show a regular grammar for each of the
following languages:
1. {w Ꞓ {a, b}* : w contains an even number of a’s and an odd number of
b’s}.
2. {w Ꞓ {a, b}* : w does not end in aa}.
3. {w Ꞓ {a, b}* : w does not contain the substring aabb}.
15
grammartofsm(G: regular grammar) =
1. Create in M a separate state for each nonterminal in V.
2. Make the state corresponding to S the start state.
3. If there are any rules in R of the form X → w, for some w Ꞓ Σ, then create an
additional state labeled #.
4. For each rule of the form X → w Y, add a transition from X to Y labeled w.
5. For each rule of the form X → w, add a transition from X to # labeled w.
6. For each rule of the form X → ε, mark state X as accepting.
7. Mark state # as accepting.
8. If M is incomplete (i.e., there are some (state, input) pairs for which no
transition is defined), M requires a dead state. Add a new state D. For every (q,
i) pair for which no transition has already been defined, create a transition from
q to D labeled i. For every i in Σ, create a transition from D to D labeled i.
SaB
16
 (a+b)=>a, b
 (a+b)*=>ε,a,b,ab,ba,aab,bba,aba,bab,
aaaa,bbbb
 (a.b)*=> ε,ab,abab,ababab
 Ba,bbba,aaaa,bbbb
17
Example 7.2 Strings that End with aaaa
 Let L = {w Ꞓ {a, b}* : w ends with the pattern aaaa}. Alternatively,
L = (a U b)* aaaa.
 The following regular grammar defines L:
S → aS δ(S,a)=S
/* An arbitrary number of a’s and b’s can be generated before
S → bS δ(S,b)=S /* the pattern starts.
S → aB δ(S,a)=B /* Generate the first a of the pattern.
B → aC δ(B,a)=C /* Generate the second a of the pattern.
C → aD δ(C,a)=D /* Generate the third a of the pattern.
D → a δ(D,a)=ε /* Generate the last a of the pattern and
quit.
18
Contd….
19
Applying grammartofsm to this grammar, we get:
Notice that the machine that grammartofsm builds is not necessarily
deterministic.
C
S a a
B
a / b
a D a #
S
δ(S,a)=S
δ(S,b)=S
δ(S,a)=B /* Generate the first a of the pattern.
δ(B,a)=C /* Generate the second a of the pattern.
δ(C,a)=D /* Generate the third a of the pattern.
δ(D,a)=ε
Example 7.3 The Missing
Letter Language
 Let Σ = {a, b, c}. LMissing = {w : there is a symbol ai Ꞓ Σ not appearing in w}
 The job of S is to generate some string in LMissing. It does that by choosing a
first character of the string and then choosing which other character will be
missing.
 The job of A is to generate all strings that do not contain any a’s.
 The job of B is to generate all strings that do not contain any b’s. And the job
of C is to generate all strings that do not contain any c’s.
20
A → bA
A → cA
A → ε
B → aB
B → cB
B → ε
C → aC
C → bC
C → ε
S → ε
S → aB δ(S,a)=B
S → aC δ(S,a)=C
S → bA δ(S,b)=A
S → bC δ(S,b)=C
S → cA δ(S,c)=A
S → cB δ(S,c)=B
21
B
b,c
a,c
A
a,b
C
S a,c
a,b
b,c
22
Regular Expression:
a(bUaa)*a
DFSM:
W
a
a
T
b
a
a #
S
L = {w ∈ {a, b}* : every a in w is immediately followed by at least one b}.
23
a) Write a regular expression that describes L.
(ab ∪ b)*
b) Write a regular grammar that generates L.
S → bS
S → aT
T → bS
S → ε
c) Construct an FSM that accepts L.
a T
b
S
b
b) {w ∈ {a, b}* : w does not end in aa}.
 Regular Grammar
S → aA | bB | ε
A → aC | bB | ε
B → aA | bB | ε
C → aC | bB
24
C
a
a
A
b b
B
S
b a
b
a
25
Properties of Regular
Languages
Reading: Chapter 4
26
Topics
1) How to prove whether a given
language is regular or not?
1) Pumping Lemma Theorem
2) Some examples to prove language is not
regular
2) Closure properties of regular
languages
27
Some languages are not
regular
When is a language is regular?
if we are able to construct one of the
following: DFSM or NFSM or  -NFSM or regular
expression
When is it not?
If we can show that no FSM can be built for a
language
28
How to prove languages are
not regular?
What if we cannot come up with any FSM?
A) Can it be language that is not regular?
B) Or is it that we tried wrong approaches?
How do we decisively prove that a language
is not regular?
“The hardest thing of all is to find a black cat in a dark room,
especially if there is no cat!” -Confucius
The Pumping Theorem for
Regular Languages
 Theorem: If L is a regular language, then:
 Ǝk ≥ 1 (∀ strings w Ꞓ L, where |w| ≥ k (Ǝ x, y, z (w = xyz, |xy| ≤ k,
y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L)))).
 Proof: The proof is the argument that we gave above: If L is regular
then it is accepted by some DFSM M = (K, Σ, δ, s, A). Let k be |K|.
Let w be any string in L of length k or greater. By Theorem 8.5, to
accept w, M must traverse some loop at least once. We can carve w
up and assign the name y to the first substring to drive M through a
loop. Then x is the part of w that precedes y and z is the part of w that
follows y.
29
The Pumping Theorem for
Regular Languages
 We show that each of the last three conditions must then hold:
1. |xy| ≤ k : M must not only traverse a loop eventually when reading w, it must
do so for the first time by at least the time it has read k characters. It can read
k-1 characters without revisiting any states. But the kth character must, if no
earlier character already has, take M to a state it has visited before. Whatever
character does that is the last in one pass through some loop.
2. y ≠ ε: since M is deterministic, there are no loops that can be traversed by .
3. ∀ q ≥ 0 (xyqz Ꞓ L): y can be pumped out once (which is what happens if q = 0)
or in any number of times (which happens if q is greater than 1) and the
resulting string must be in L since it will be accepted by M.
 It is possible that we could chop y out more than once and still generate a
string in L, but without knowing how much longer w is than k, we don’t know
any more than that it can be chopped out once.
30
The Pumping Theorem for
Regular Languages
 The Pumping Theorem tells us something that is true of every regular
language.
 Generally, if we already know that a language is regular, we won’t
particularly care about what the Pumping Theorem tells us about it. But
suppose that we are interested in some language L and we want to know
whether or not it is regular.
 If we could show that the claims made in the Pumping Theorem are not true
of L, then we would know that L is not regular.
 In particular, we will use it to construct proofs by contradiction.
 We will say, “If L were regular, then it would possess certain properties.
But it does not possess those properties. Therefore, it is not regular.”
31
Example 8.8 AnBn is not
Regular
 Let L be AnBn = {anbn : n ≥ 0}. We can use the Pumping Theorem to show that L is
not regular.
 If it were, then there would exist some k such that any string w, where |w| ≥ k, must
satisfy the conditions of the theorem. We show one string w that does not.
 Let w = akbk. Since |w| = 2k, w is long enough and it is in L, so it must satisfy the
conditions of the Pumping Theorem. So there must exist x, y, and z, such that w =
xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L).
 But we show that no such x, y, and z exist. Since we must guarantee that |xy| ≤ k, y
must occur within the first k characters and so y = ap for some p.
 Since we must guarantee that y ≠ε, p must be greater than 0. Let q = 2. (In other
words, we pump in one extra copy of y.) The resulting string is ak+pbk.
 The last condition of the Pumping Theorem states that this string must be in L, but
it is not since it has more a’s than b’s.
 Thus there exists at least one long string in L that fails to satisfy the conditions
of the Pumping Theorem.
 So L = AnBn is not regular. 32
L={anbn}
 w=a……….ab……….b=====2n
n n
 w= x y z
 |xy|<=k<=|w|;;; k=n
i.e. xy=an & z=bn
 Assume y=ap
then x=an-p
w=an-papbn = an-p+pbn= anbn
 So, let n=4,a4b4 p=1,then we get, w=a3a1b4
 According to pumping lemma, if w belong to regular language then xyqz Ꞓ L
for q≥0.
 Now let q=2,
 w=a3a1+2b4=a6b4
w=an+qbn ∉ L
33
The Even Palindrome
Language is Not Regular
 Let L be PalEven = {wwR : w Ꞓ {a, b}*}. PalEven is the language of even-length
palindromes of a’s and b’s.
 We can use the Pumping Theorem to show that PalEven is not regular.
 If it were, then there would exist some k such that any string w, where |w| ≥ k, must
satisfy the conditions of the theorem. We show one string w that does not.
 We will choose w so that we only have to consider one case for where y could fall.
 Let w = akbkbkak.
 w=akbk & wR=bkak
 Since |w| = 4k and w is in L, w must satisfy the conditions of the Pumping Theorem.
So there must exist x, y, and z, such that w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L).
Since |xy| ≤ k, y must occur within the first k characters and so y = ap for some p.
 Since y ≠ε, p must be greater than 0. Let q = 2. The resulting string is ak+pbkbkak. If p
is odd, then this string is not in PalEven because all strings in PalEven have even
length. If p is even then it is at least 2, so the first half of the string has more a’s than
the second half does, so it is not in PalEven.
 So L = PalEven is not regular.
34
 w=a……….ab……….bb……….ba……….a
k k k k
 w= x y z & |w|=4k
i.e. xy=ak & z=bkbkak
 Assume y=ap
then x=ak-p
w=ak-papbk bkak= akbkbkak
 So, let k=4, p=2,then we get,
w=a2a2b4b4a4
 According to pumping lemma, if w belong to regular language then
xyqz Ꞓ L for q≥0.
 Now let q=3,
 w=a2a2+3b4b4a4=a7b4b4a4
w=ak-p+p+qbkbkak =ak+qbkbkak ∉ L 35
Example 8.12 The Language with
More a’s Than b’s is Not Regular
 Let L = {anbm : n > m}. We can use the Pumping Theorem to show that L is not regular. If
it were, then there would exist some k such that any string w, where |w| ≥ k, must satisfy
the conditions of the theorem. We show one string w that does not.
1. Let w = ak+1bk. Since |w| = 2k+1 and w is in L, w must satisfy the conditions of the
Pumping Theorem.
2. So there must exist x, y, and z, such that w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L).
Since |xy| ≤ k, y must occur within the first k characters and so y = ap for some p.
3. Since y ≠ε, p must be greater than 0. There are already more a’s than b’s, as required by
the definition of L.
4. If we pump in, there will be even more a’s and the resulting string will still be in L. But
we can set q to 0 (and so pump out).
5. The resulting string is then ak+1-pbk. Since p > 0, k+1-p ≤ k, so the resulting string no longer
has more a’s than b’s and so is not in L.
6. There exists at least one long string in L that fails to satisfy the conditions of the Pumping
Theorem.
7. So L is not regular. 36
The Pumping Lemma for
Regular Languages
What it is?
The Pumping Lemma is a property
of all regular languages.
How is it used?
A technique that is used to show
that a given language is not regular
37
38
Pumping Lemma for Regular
Languages
Let L be a regular language
Then there exists some constant N such that for
every string w  L s.t. |w|≥N, there exists a
way to break w into three parts, w=xyz,
such that:
1. y≠ 
2. |xy|≤N
3. For all k≥0, all strings of the form xykz  L
This property should hold for all regular languages.
Definition: N is called the “Pumping Lemma Constant”
39
The Purpose of the Pumping
Lemma for RL
 To prove that some languages cannot
be regular.
Closure properties of Regular
Languages
40
41
Closure properties for Regular
Languages (RL)
 Closure property:
 If a set of regular languages are combined using an
operator, then the resulting language is also regular
 Regular languages are closed under:
 Union, intersection, complement
 Difference
 Reversal
 Kleene closure
 Concatenation
 Homomorphism
 Inverse homomorphism
This is different
from Kleene
closure
Now, lets prove all of this!
42
RLs are closed under union
 IF L and M are two RLs THEN:
 they both have two corresponding regular
expressions, R and S respectively
 (L U M) can be represented using the regular
expression R+S
 Therefore, (L U M) is also regular
How can this be proved using FSMs?
43
RLs are closed under
complementation
q0
qF1
qF2
qFk
…
qi
DFSM for L
q0
qF1
qF2
qFk
…
qi
DFSM for L
 If L is an RL over ∑, then L=∑*-L
 To show L is also regular, make the following
construction Convert every final state into non-final, and
every non-final state into a final state
Assumes q0 is a non-final state. If not, do the opposite.
44
RLs are closed under
intersection
 A quick, indirect way to prove:
 By DeMorgan’s law:
 L ∩ M = (L U M)
 Since we know RLs are closed under union
and complementation, they are also closed
under intersection
 A more direct way would be construct a
finite automaton for L ∩ M
45
DFSM construction for L ∩ M
 AL = DFSM for L = {QL, ∑ , qL,FL, δL }
 AM = DFSM for M = {QM, ∑ , qM,FM, δM }
 Build AL ∩ M = {QLx QM,∑, (qL,qM), FLx FM,δ}
such that:
 δ((p,q),a) = (δL(p,a), δM(q,a)), where p in QL, and q
in QM
 This construction ensures that a string w will
be accepted if and only if w reaches an
accepting state in both input DFSMs.
46
DFSM construction for L ∩ M
q0
qF1
qF2
…
qi
DFSM for L
p0
pF1
pF2
…
pi
DFSM for M
qj
a
pj
a
(qF1 ,pF1)
…
DFSM for LM
a
(qi ,pi) (qj ,pj)
(q0 ,p0)
47
RLs are closed under set
difference
 We observe:
 L - M = L ∩ M
 Therefore, L - M is also regular
Closed under intersection
Closed under
complementation
48
RLs are closed under reversal
Reversal of a string w is denoted by wR
 E.g., w=00111, wR=11100
Reversal of a language:
 LR = The language generated by
reversing all strings in L
Theorem: If L is regular then LR is also
regular
49
 -NFSM Construction for LR
q0
qF1
qF2
qFk
…
qi qj
a
DFSM for L
New -NFSM for LR
New start
state
q’0



Make the
old start state
as the only new
final state
Reverse all transitions
Convert the old set of final states
into non-final states
What to do if q0 was
one of the final states
in the input DFSM?
50
If L is regular, LR is regular (proof
using regular expressions)
 Let E be a regular expression for L
 Given E, how to build ER?
 Basis: If E= , Ø, or a, then ER=E
 Induction: Every part of E (refer to the part as “F”)
can be in only one of the three following forms:
1. F = F1+F2
 FR = F1
R+F2
R
2. F = F1F2
 FR = F2
RF1
R
3. F = (F1)*
 (FR)* = (F1
R)*
51
Homomorphisms
 Substitute each symbol in ∑ (main alphabet)
by a corresponding string in T (another
alphabet)
 h: ∑--->T*
 Example:
 Let ∑={0,1} and T={a,b}
 Let a homomorphic function h on ∑ be:
 h(0)=ab, h(1)=
 If w=10110, then h(w) = abab = abab
 In general,
 h(w) = h(a1) h(a2)… h(an)
53
FSM Construction for h(L)
q0
qF1
qF2
qFk
…
qi qj
a
DFSM for L
- Build a new FSM that simulates h(a) for every symbol a transition in
the above DFSM
- The resulting FSM may or may not be a DFSM, but will be a FSM for h(
Replace every edge
“a” by
a path labeled h(a)
in the new DFSM
Given a DFSM for L, how to convert it into an FSM for h(L)?
h(a)
54
Inverse homomorphism
 Let h: ∑--->T*
 Let M be a language over alphabet T
 h-1(M) = {w | w  ∑* s.t., h(w)  M }
Claim: If M is regular, then so is h-1(M)
 Proof:
 Let A be a DFSM for M
 Construct another DFSM A’ which encodes h-1(M)
 A’ is an exact replica of A, except that its transition
functions are s.t. for any input symbol a in ∑, A’
will simulate h(a) in A.
 δ(p,a) = δ(p,h(a))
The set of strings in ∑*
whose homomorphic translation
results in the strings of M
Given a DFSM for M, how to convert it into an FSM for h-1(M)?

More Related Content

Similar to RegularLanguageProperties [Autosaved].pptx

CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR Zahid Parvez
 
Regular expression
Regular expressionRegular expression
Regular expressionRajon
 
context free grammars automata therory and compiler design
context free grammars automata therory and compiler designcontext free grammars automata therory and compiler design
context free grammars automata therory and compiler designsunitachalageri1
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 028threspecter
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring奕安 陳
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free GrammerHASHIR RAZA
 
Context free grammars
Context free grammarsContext free grammars
Context free grammarsRonak Thakkar
 
contextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdfcontextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdfry54321288
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarRushabh2428
 
hghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghgggggggggggggggggggggggggggggggggghghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghggggggggggggggggggggggggggggggggggadugnanegero
 
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdfwigewej294
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2gadisaAdamu
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationPrafullMisra
 

Similar to RegularLanguageProperties [Autosaved].pptx (20)

Ch2 automata.pptx
Ch2 automata.pptxCh2 automata.pptx
Ch2 automata.pptx
 
Ch02
Ch02Ch02
Ch02
 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
context free grammars automata therory and compiler design
context free grammars automata therory and compiler designcontext free grammars automata therory and compiler design
context free grammars automata therory and compiler design
 
To lec 03
To lec 03To lec 03
To lec 03
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 02
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free Grammer
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
contextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdfcontextfreegrammars-120925004035-phpapp02.pdf
contextfreegrammars-120925004035-phpapp02.pdf
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
hghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghgggggggggggggggggggggggggggggggggghghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghgggggggggggggggggggggggggggggggggg
 
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdf
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's Classification
 

More from RaviAr5

Excel Pivot Tables April 2016.pptx
Excel Pivot Tables April 2016.pptxExcel Pivot Tables April 2016.pptx
Excel Pivot Tables April 2016.pptxRaviAr5
 
Pytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptxPytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptxRaviAr5
 
06-Strings.pptx
06-Strings.pptx06-Strings.pptx
06-Strings.pptxRaviAr5
 
uid 3.4- MKH.pptx
uid 3.4- MKH.pptxuid 3.4- MKH.pptx
uid 3.4- MKH.pptxRaviAr5
 
Communication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptxCommunication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptxRaviAr5
 
Apti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptxApti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptxRaviAr5
 

More from RaviAr5 (6)

Excel Pivot Tables April 2016.pptx
Excel Pivot Tables April 2016.pptxExcel Pivot Tables April 2016.pptx
Excel Pivot Tables April 2016.pptx
 
Pytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptxPytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptx
 
06-Strings.pptx
06-Strings.pptx06-Strings.pptx
06-Strings.pptx
 
uid 3.4- MKH.pptx
uid 3.4- MKH.pptxuid 3.4- MKH.pptx
uid 3.4- MKH.pptx
 
Communication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptxCommunication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptx
 
Apti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptxApti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptx
 

Recently uploaded

Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryCall me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryPooja Nehwal
 
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...shivangimorya083
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...amitlee9823
 
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...amitlee9823
 
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国ezgenuh
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataaritradey27234
 
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办ezgenuh
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...nirzagarg
 
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorHow To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorAndres Auto Service
 
Hyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai Motor Group
 
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!AutoScandia
 
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...amitlee9823
 
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...anilsa9823
 
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...amitlee9823
 

Recently uploaded (20)

Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryCall me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
 
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
 
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
 
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
 
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
一比一原版(UVic学位证书)维多利亚大学毕业证学历认证买留学回国
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tata
 
(INDIRA) Call Girl Surat Call Now 8250077686 Surat Escorts 24x7
(INDIRA) Call Girl Surat Call Now 8250077686 Surat Escorts 24x7(INDIRA) Call Girl Surat Call Now 8250077686 Surat Escorts 24x7
(INDIRA) Call Girl Surat Call Now 8250077686 Surat Escorts 24x7
 
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
 
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorHow To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
 
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
 
Hyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRC
 
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
 
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls East Of Kailash 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Saket 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
 
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
 
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
 

RegularLanguageProperties [Autosaved].pptx

  • 1. Grammar  A grammar G is a quadruple (V, Σ, R, S), where:  V is the rule alphabet, which contains nonterminals (symbols that are used in the grammar but that do not appear in strings in the language) and terminals (symbols that can appear in strings generated by G),  Σ (the set of terminals) is a subset of V,  R (the set of rules) is a finite set of rules of the form αβ,  S (the start symbol) is a nonterminal. 1
  • 2. Chomsky Hierarchy  Types of Grammar: 1. Type 0 grammar(Phrase Structured Grammar) 2. Type 1 grammar(Context Sensitive Grammar) 3. Type 2 grammar(Context Free Grammar) 4. Type 3 grammar(Regular Grammar) 2
  • 3. Phrase Structured Grammar  A Phrase Structured Grammar/ Unrestricted Grammar / Type 0 Grammar G is a quadruple (V, Σ, R, S), where:  V is the rule alphabet, which contains non terminals and terminals.  Σ (the set of terminals) is a subset of V,  R (the set of rules) is a finite set of rules of the form αβ,  S (the start symbol) is a nonterminal.  Here, all rules in R must:  αβ,  Where, α Ꞓ(VUT)+ and β Ꞓ(VUT)*  Eg: S  aAb | ε aAbAA bAa  Language: Recursively Enumerable Language  Machine: Turing Machine  Most Powerful grammar. 3
  • 4. Context Sensitive Grammar  A Context Sensitive Grammar / Type 1 G is a quadruple (V, Σ, R, S), where:  V is the rule alphabet, which contains non terminals and terminals,  Σ (the set of terminals) is a subset of V,  R (the set of rules) is a finite set of rules of the form αβ,  S (the start symbol) is a nonterminal.  In a Context Sensitive Grammar, rules :  There is restriction on the length of β. The length of β should be at least as much as the length of α. |β| ≥ |α|  α and β Ꞓ (VUT)+. i.e. ε cannot appear on LHS or RHS of any rule. It is an ε-free grammar.  Machine: Linear Bounded Automata  Language: Context Sensitive Language  Eg: SaAb aAbAA bAaa 4
  • 5. Context Free Grammar  A Context Free Grammar/ Type 2 Grammar G is a quadruple (V, Σ, R, S), where:  V is the rule alphabet, which contains non terminals and terminals,  Σ (the set of terminals) is a subset of V,  R (the set of rules) is a finite set of rules of the form Aα,  S (the start symbol) is a nonterminal.  In a context free grammar, all rules in R must be of the form:  A α, Where  A Single Nonterminal & αꞒ(VUT)*  Machine: Push Down Automata  Language: Context Free Language  Eg:- SaB/bA/ε AaA/b BbB/a/ ε 5
  • 6. Regular Grammar  A regular grammar G is a quadruple (V, Σ, R, S), where:  V is the rule alphabet, which contains nonterminals (symbols that are used in the grammar but that do not appear in strings in the language) and terminals (symbols that can appear in strings generated by G),  Σ (the set of terminals) is a subset of V,  R (the set of rules) is a finite set of rules of the form αβ,  S (the start symbol) is a nonterminal.  In a regular grammar, all rules in R must:  have a left-hand side that is a single nonterminal, and  have a right-hand side that is ε or a single terminal or a single terminal followed by a single nonterminal.  So S → a, S → ε, and T → aS are legal rules in a regular grammar.  Machine: Finite Automata  Language: Regular language 6
  • 7. Finite State Machine to Regular Grammar  Procedure:  V(Nonterminals): States of DFSM  Σ(Terminals): Alphabets of DFSM  S=q0 i.e., start state of DFSM is start symbol of grammar  Rules:  If δ(qi,a)=qj then introduce the rule as: qiaqj  If q Ꞓ F i.e., if q is the final state in FSM, then introduce the rule as: qε 7
  • 8. Obtain a grammar to generate string of any numbers of a’s  Transition: Rules:  S is a final State Sε  δ(S,a)=S SaS SO, the Grammar is: SaS / ε OR SaS S ε Language generated is: L={an:n ≥0} 8 S a
  • 9. Obtain a grammar to generate string of at least one a.  Transition: Rules:  A is a final State A ε  δ(S,a)=A SaA  δ(A,a)=A AaA So, the Grammar is: SaA AaA/ε Language generated is: L={an:n ≥1} 9 A a S a
  • 10. Obtain a grammar to generate string of any no. of a’s and b’s.  Transition: Rules:  S is a final State Sε  δ(S,a)=S SaS  δ(S,b)=S SbS So, the Grammar is: SaS/ bS/ε Language generated is: L={(a+b)n:n ≥0} 10 S a,b
  • 11. Obtain a grammar to generate string of at least two a’s  Transition: Rules:  B is a final State Bε  δ(S,a)=A SaA  δ(A,a)=B AaB  δ(B,a)=B BaB So, the Grammar is: SaA A aB BaB/ε 11 B S a a A a
  • 12. Obtain a grammar to generate string of at multiple’s of three a’s  SaA / ε  A->aB  BaS 12 B S a a A a
  • 13.  Transitions Rules  δ(S,a)=A SaA  δ(A,a)=S AaS  S is final state Sε G=(V, Σ, R,S) V={S,A,a} Σ ={a} S is start symbol R={SaA/ ε AaS} 13
  • 14.  Obtain a grammar to accept the language L={w:|w|mod 3>0, wꞒ{a}*} 14 B a a A a S
  • 15. Show a regular grammar for each of the following languages: 1. {w Ꞓ {a, b}* : w contains an even number of a’s and an odd number of b’s}. 2. {w Ꞓ {a, b}* : w does not end in aa}. 3. {w Ꞓ {a, b}* : w does not contain the substring aabb}. 15
  • 16. grammartofsm(G: regular grammar) = 1. Create in M a separate state for each nonterminal in V. 2. Make the state corresponding to S the start state. 3. If there are any rules in R of the form X → w, for some w Ꞓ Σ, then create an additional state labeled #. 4. For each rule of the form X → w Y, add a transition from X to Y labeled w. 5. For each rule of the form X → w, add a transition from X to # labeled w. 6. For each rule of the form X → ε, mark state X as accepting. 7. Mark state # as accepting. 8. If M is incomplete (i.e., there are some (state, input) pairs for which no transition is defined), M requires a dead state. Add a new state D. For every (q, i) pair for which no transition has already been defined, create a transition from q to D labeled i. For every i in Σ, create a transition from D to D labeled i. SaB 16
  • 17.  (a+b)=>a, b  (a+b)*=>ε,a,b,ab,ba,aab,bba,aba,bab, aaaa,bbbb  (a.b)*=> ε,ab,abab,ababab  Ba,bbba,aaaa,bbbb 17
  • 18. Example 7.2 Strings that End with aaaa  Let L = {w Ꞓ {a, b}* : w ends with the pattern aaaa}. Alternatively, L = (a U b)* aaaa.  The following regular grammar defines L: S → aS δ(S,a)=S /* An arbitrary number of a’s and b’s can be generated before S → bS δ(S,b)=S /* the pattern starts. S → aB δ(S,a)=B /* Generate the first a of the pattern. B → aC δ(B,a)=C /* Generate the second a of the pattern. C → aD δ(C,a)=D /* Generate the third a of the pattern. D → a δ(D,a)=ε /* Generate the last a of the pattern and quit. 18
  • 19. Contd…. 19 Applying grammartofsm to this grammar, we get: Notice that the machine that grammartofsm builds is not necessarily deterministic. C S a a B a / b a D a # S δ(S,a)=S δ(S,b)=S δ(S,a)=B /* Generate the first a of the pattern. δ(B,a)=C /* Generate the second a of the pattern. δ(C,a)=D /* Generate the third a of the pattern. δ(D,a)=ε
  • 20. Example 7.3 The Missing Letter Language  Let Σ = {a, b, c}. LMissing = {w : there is a symbol ai Ꞓ Σ not appearing in w}  The job of S is to generate some string in LMissing. It does that by choosing a first character of the string and then choosing which other character will be missing.  The job of A is to generate all strings that do not contain any a’s.  The job of B is to generate all strings that do not contain any b’s. And the job of C is to generate all strings that do not contain any c’s. 20 A → bA A → cA A → ε B → aB B → cB B → ε C → aC C → bC C → ε S → ε S → aB δ(S,a)=B S → aC δ(S,a)=C S → bA δ(S,b)=A S → bC δ(S,b)=C S → cA δ(S,c)=A S → cB δ(S,c)=B
  • 23. L = {w ∈ {a, b}* : every a in w is immediately followed by at least one b}. 23 a) Write a regular expression that describes L. (ab ∪ b)* b) Write a regular grammar that generates L. S → bS S → aT T → bS S → ε c) Construct an FSM that accepts L. a T b S b
  • 24. b) {w ∈ {a, b}* : w does not end in aa}.  Regular Grammar S → aA | bB | ε A → aC | bB | ε B → aA | bB | ε C → aC | bB 24 C a a A b b B S b a b a
  • 26. 26 Topics 1) How to prove whether a given language is regular or not? 1) Pumping Lemma Theorem 2) Some examples to prove language is not regular 2) Closure properties of regular languages
  • 27. 27 Some languages are not regular When is a language is regular? if we are able to construct one of the following: DFSM or NFSM or  -NFSM or regular expression When is it not? If we can show that no FSM can be built for a language
  • 28. 28 How to prove languages are not regular? What if we cannot come up with any FSM? A) Can it be language that is not regular? B) Or is it that we tried wrong approaches? How do we decisively prove that a language is not regular? “The hardest thing of all is to find a black cat in a dark room, especially if there is no cat!” -Confucius
  • 29. The Pumping Theorem for Regular Languages  Theorem: If L is a regular language, then:  Ǝk ≥ 1 (∀ strings w Ꞓ L, where |w| ≥ k (Ǝ x, y, z (w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L)))).  Proof: The proof is the argument that we gave above: If L is regular then it is accepted by some DFSM M = (K, Σ, δ, s, A). Let k be |K|. Let w be any string in L of length k or greater. By Theorem 8.5, to accept w, M must traverse some loop at least once. We can carve w up and assign the name y to the first substring to drive M through a loop. Then x is the part of w that precedes y and z is the part of w that follows y. 29
  • 30. The Pumping Theorem for Regular Languages  We show that each of the last three conditions must then hold: 1. |xy| ≤ k : M must not only traverse a loop eventually when reading w, it must do so for the first time by at least the time it has read k characters. It can read k-1 characters without revisiting any states. But the kth character must, if no earlier character already has, take M to a state it has visited before. Whatever character does that is the last in one pass through some loop. 2. y ≠ ε: since M is deterministic, there are no loops that can be traversed by . 3. ∀ q ≥ 0 (xyqz Ꞓ L): y can be pumped out once (which is what happens if q = 0) or in any number of times (which happens if q is greater than 1) and the resulting string must be in L since it will be accepted by M.  It is possible that we could chop y out more than once and still generate a string in L, but without knowing how much longer w is than k, we don’t know any more than that it can be chopped out once. 30
  • 31. The Pumping Theorem for Regular Languages  The Pumping Theorem tells us something that is true of every regular language.  Generally, if we already know that a language is regular, we won’t particularly care about what the Pumping Theorem tells us about it. But suppose that we are interested in some language L and we want to know whether or not it is regular.  If we could show that the claims made in the Pumping Theorem are not true of L, then we would know that L is not regular.  In particular, we will use it to construct proofs by contradiction.  We will say, “If L were regular, then it would possess certain properties. But it does not possess those properties. Therefore, it is not regular.” 31
  • 32. Example 8.8 AnBn is not Regular  Let L be AnBn = {anbn : n ≥ 0}. We can use the Pumping Theorem to show that L is not regular.  If it were, then there would exist some k such that any string w, where |w| ≥ k, must satisfy the conditions of the theorem. We show one string w that does not.  Let w = akbk. Since |w| = 2k, w is long enough and it is in L, so it must satisfy the conditions of the Pumping Theorem. So there must exist x, y, and z, such that w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L).  But we show that no such x, y, and z exist. Since we must guarantee that |xy| ≤ k, y must occur within the first k characters and so y = ap for some p.  Since we must guarantee that y ≠ε, p must be greater than 0. Let q = 2. (In other words, we pump in one extra copy of y.) The resulting string is ak+pbk.  The last condition of the Pumping Theorem states that this string must be in L, but it is not since it has more a’s than b’s.  Thus there exists at least one long string in L that fails to satisfy the conditions of the Pumping Theorem.  So L = AnBn is not regular. 32
  • 33. L={anbn}  w=a……….ab……….b=====2n n n  w= x y z  |xy|<=k<=|w|;;; k=n i.e. xy=an & z=bn  Assume y=ap then x=an-p w=an-papbn = an-p+pbn= anbn  So, let n=4,a4b4 p=1,then we get, w=a3a1b4  According to pumping lemma, if w belong to regular language then xyqz Ꞓ L for q≥0.  Now let q=2,  w=a3a1+2b4=a6b4 w=an+qbn ∉ L 33
  • 34. The Even Palindrome Language is Not Regular  Let L be PalEven = {wwR : w Ꞓ {a, b}*}. PalEven is the language of even-length palindromes of a’s and b’s.  We can use the Pumping Theorem to show that PalEven is not regular.  If it were, then there would exist some k such that any string w, where |w| ≥ k, must satisfy the conditions of the theorem. We show one string w that does not.  We will choose w so that we only have to consider one case for where y could fall.  Let w = akbkbkak.  w=akbk & wR=bkak  Since |w| = 4k and w is in L, w must satisfy the conditions of the Pumping Theorem. So there must exist x, y, and z, such that w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L). Since |xy| ≤ k, y must occur within the first k characters and so y = ap for some p.  Since y ≠ε, p must be greater than 0. Let q = 2. The resulting string is ak+pbkbkak. If p is odd, then this string is not in PalEven because all strings in PalEven have even length. If p is even then it is at least 2, so the first half of the string has more a’s than the second half does, so it is not in PalEven.  So L = PalEven is not regular. 34
  • 35.  w=a……….ab……….bb……….ba……….a k k k k  w= x y z & |w|=4k i.e. xy=ak & z=bkbkak  Assume y=ap then x=ak-p w=ak-papbk bkak= akbkbkak  So, let k=4, p=2,then we get, w=a2a2b4b4a4  According to pumping lemma, if w belong to regular language then xyqz Ꞓ L for q≥0.  Now let q=3,  w=a2a2+3b4b4a4=a7b4b4a4 w=ak-p+p+qbkbkak =ak+qbkbkak ∉ L 35
  • 36. Example 8.12 The Language with More a’s Than b’s is Not Regular  Let L = {anbm : n > m}. We can use the Pumping Theorem to show that L is not regular. If it were, then there would exist some k such that any string w, where |w| ≥ k, must satisfy the conditions of the theorem. We show one string w that does not. 1. Let w = ak+1bk. Since |w| = 2k+1 and w is in L, w must satisfy the conditions of the Pumping Theorem. 2. So there must exist x, y, and z, such that w = xyz, |xy| ≤ k, y≠ε, and ∀ q ≥ 0 (xyqz Ꞓ L). Since |xy| ≤ k, y must occur within the first k characters and so y = ap for some p. 3. Since y ≠ε, p must be greater than 0. There are already more a’s than b’s, as required by the definition of L. 4. If we pump in, there will be even more a’s and the resulting string will still be in L. But we can set q to 0 (and so pump out). 5. The resulting string is then ak+1-pbk. Since p > 0, k+1-p ≤ k, so the resulting string no longer has more a’s than b’s and so is not in L. 6. There exists at least one long string in L that fails to satisfy the conditions of the Pumping Theorem. 7. So L is not regular. 36
  • 37. The Pumping Lemma for Regular Languages What it is? The Pumping Lemma is a property of all regular languages. How is it used? A technique that is used to show that a given language is not regular 37
  • 38. 38 Pumping Lemma for Regular Languages Let L be a regular language Then there exists some constant N such that for every string w  L s.t. |w|≥N, there exists a way to break w into three parts, w=xyz, such that: 1. y≠  2. |xy|≤N 3. For all k≥0, all strings of the form xykz  L This property should hold for all regular languages. Definition: N is called the “Pumping Lemma Constant”
  • 39. 39 The Purpose of the Pumping Lemma for RL  To prove that some languages cannot be regular.
  • 40. Closure properties of Regular Languages 40
  • 41. 41 Closure properties for Regular Languages (RL)  Closure property:  If a set of regular languages are combined using an operator, then the resulting language is also regular  Regular languages are closed under:  Union, intersection, complement  Difference  Reversal  Kleene closure  Concatenation  Homomorphism  Inverse homomorphism This is different from Kleene closure Now, lets prove all of this!
  • 42. 42 RLs are closed under union  IF L and M are two RLs THEN:  they both have two corresponding regular expressions, R and S respectively  (L U M) can be represented using the regular expression R+S  Therefore, (L U M) is also regular How can this be proved using FSMs?
  • 43. 43 RLs are closed under complementation q0 qF1 qF2 qFk … qi DFSM for L q0 qF1 qF2 qFk … qi DFSM for L  If L is an RL over ∑, then L=∑*-L  To show L is also regular, make the following construction Convert every final state into non-final, and every non-final state into a final state Assumes q0 is a non-final state. If not, do the opposite.
  • 44. 44 RLs are closed under intersection  A quick, indirect way to prove:  By DeMorgan’s law:  L ∩ M = (L U M)  Since we know RLs are closed under union and complementation, they are also closed under intersection  A more direct way would be construct a finite automaton for L ∩ M
  • 45. 45 DFSM construction for L ∩ M  AL = DFSM for L = {QL, ∑ , qL,FL, δL }  AM = DFSM for M = {QM, ∑ , qM,FM, δM }  Build AL ∩ M = {QLx QM,∑, (qL,qM), FLx FM,δ} such that:  δ((p,q),a) = (δL(p,a), δM(q,a)), where p in QL, and q in QM  This construction ensures that a string w will be accepted if and only if w reaches an accepting state in both input DFSMs.
  • 46. 46 DFSM construction for L ∩ M q0 qF1 qF2 … qi DFSM for L p0 pF1 pF2 … pi DFSM for M qj a pj a (qF1 ,pF1) … DFSM for LM a (qi ,pi) (qj ,pj) (q0 ,p0)
  • 47. 47 RLs are closed under set difference  We observe:  L - M = L ∩ M  Therefore, L - M is also regular Closed under intersection Closed under complementation
  • 48. 48 RLs are closed under reversal Reversal of a string w is denoted by wR  E.g., w=00111, wR=11100 Reversal of a language:  LR = The language generated by reversing all strings in L Theorem: If L is regular then LR is also regular
  • 49. 49  -NFSM Construction for LR q0 qF1 qF2 qFk … qi qj a DFSM for L New -NFSM for LR New start state q’0    Make the old start state as the only new final state Reverse all transitions Convert the old set of final states into non-final states What to do if q0 was one of the final states in the input DFSM?
  • 50. 50 If L is regular, LR is regular (proof using regular expressions)  Let E be a regular expression for L  Given E, how to build ER?  Basis: If E= , Ø, or a, then ER=E  Induction: Every part of E (refer to the part as “F”) can be in only one of the three following forms: 1. F = F1+F2  FR = F1 R+F2 R 2. F = F1F2  FR = F2 RF1 R 3. F = (F1)*  (FR)* = (F1 R)*
  • 51. 51 Homomorphisms  Substitute each symbol in ∑ (main alphabet) by a corresponding string in T (another alphabet)  h: ∑--->T*  Example:  Let ∑={0,1} and T={a,b}  Let a homomorphic function h on ∑ be:  h(0)=ab, h(1)=  If w=10110, then h(w) = abab = abab  In general,  h(w) = h(a1) h(a2)… h(an)
  • 52. 53 FSM Construction for h(L) q0 qF1 qF2 qFk … qi qj a DFSM for L - Build a new FSM that simulates h(a) for every symbol a transition in the above DFSM - The resulting FSM may or may not be a DFSM, but will be a FSM for h( Replace every edge “a” by a path labeled h(a) in the new DFSM Given a DFSM for L, how to convert it into an FSM for h(L)? h(a)
  • 53. 54 Inverse homomorphism  Let h: ∑--->T*  Let M be a language over alphabet T  h-1(M) = {w | w  ∑* s.t., h(w)  M } Claim: If M is regular, then so is h-1(M)  Proof:  Let A be a DFSM for M  Construct another DFSM A’ which encodes h-1(M)  A’ is an exact replica of A, except that its transition functions are s.t. for any input symbol a in ∑, A’ will simulate h(a) in A.  δ(p,a) = δ(p,h(a)) The set of strings in ∑* whose homomorphic translation results in the strings of M Given a DFSM for M, how to convert it into an FSM for h-1(M)?

Editor's Notes

  1. School of EECS, WSU
  2. School of EECS, WSU
  3. School of EECS, WSU
  4. School of EECS, WSU
  5. School of EECS, WSU
  6. School of EECS, WSU
  7. School of EECS, WSU
  8. School of EECS, WSU
  9. School of EECS, WSU
  10. School of EECS, WSU
  11. School of EECS, WSU
  12. School of EECS, WSU
  13. School of EECS, WSU
  14. School of EECS, WSU
  15. School of EECS, WSU
  16. School of EECS, WSU
  17. School of EECS, WSU
  18. School of EECS, WSU
  19. School of EECS, WSU
  20. School of EECS, WSU