SlideShare a Scribd company logo
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

Ch2 automata.pptx
Ch2 automata.pptxCh2 automata.pptx
Ch2 automata.pptx
TemesgenAzezew
 
Ch02
Ch02Ch02
Ch02
Hankyo
 
Flat unit 3
Flat unit 3Flat unit 3
Flat unit 3
VenkataRaoS1
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
Zahid Parvez
 
automata theory bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
automata theory                   bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...automata theory                   bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
automata theory bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
manishatapale
 
Regular expression
Regular expressionRegular expression
Regular expression
Rajon
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
Radhakrishnan Chinnusamy
 
Normal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.pptNormal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.ppt
Karthik Rohan
 
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
sunitachalageri1
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
MrRRajasekarCSE
 
theory of computation lecture 02
theory of computation lecture 02theory of computation lecture 02
theory of computation lecture 02
8threspecter
 
Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
奕安 陳
 
Automata theory
Automata theoryAutomata theory
Automata theory
Pardeep Vats
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free Grammer
HASHIR 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.pdf
ry54321288
 
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
Rushabh2428
 
hghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghgggggggggggggggggggggggggggggggggghghghghhghghgggggggggggggggggggggggggggggggggg
hghghghhghghgggggggggggggggggggggggggggggggggg
adugnanegero
 
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
wigewej294
 

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
 
automata theory bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
automata theory                   bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...automata theory                   bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
automata theory bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvb...
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Normal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.pptNormal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.ppt
 
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
 

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.pptx
RaviAr5
 
Pytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptxPytho-Chapter-4-Functions.pptx
Pytho-Chapter-4-Functions.pptx
RaviAr5
 
06-Strings.pptx
06-Strings.pptx06-Strings.pptx
06-Strings.pptx
RaviAr5
 
uid 3.4- MKH.pptx
uid 3.4- MKH.pptxuid 3.4- MKH.pptx
uid 3.4- MKH.pptx
RaviAr5
 
Communication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptxCommunication Theory-ISE -VIT.pptx
Communication Theory-ISE -VIT.pptx
RaviAr5
 
Apti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptxApti Slide Incub 2022.pptx
Apti Slide Incub 2022.pptx
RaviAr5
 

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

欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
ahmedendrise81
 
How To Fix The Key Not Detected Issue In Mercedes Cars
How To Fix The Key Not Detected Issue In Mercedes CarsHow To Fix The Key Not Detected Issue In Mercedes Cars
How To Fix The Key Not Detected Issue In Mercedes Cars
Integrity Motorcar
 
Antique Plastic Traders Company Profile
Antique Plastic Traders Company ProfileAntique Plastic Traders Company Profile
Antique Plastic Traders Company Profile
Antique Plastic Traders
 
What Could Cause The Headlights On Your Porsche 911 To Stop Working
What Could Cause The Headlights On Your Porsche 911 To Stop WorkingWhat Could Cause The Headlights On Your Porsche 911 To Stop Working
What Could Cause The Headlights On Your Porsche 911 To Stop Working
Lancer Service
 
Hero Glamour Xtec Brochure | Hero MotoCorp
Hero Glamour Xtec Brochure | Hero MotoCorpHero Glamour Xtec Brochure | Hero MotoCorp
Hero Glamour Xtec Brochure | Hero MotoCorp
Hero MotoCorp
 
Skoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda PerthSkoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda Perth
Perth City Skoda
 
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
bouvoy
 
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
Fifth Gear Automotive Argyle
 
TRAINEES-RECORD-BOOK- electronics and electrical
TRAINEES-RECORD-BOOK- electronics and electricalTRAINEES-RECORD-BOOK- electronics and electrical
TRAINEES-RECORD-BOOK- electronics and electrical
JohnCarloPajarilloKa
 
Renal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffffRenal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffff
RehanRustam2
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
Hyundai Motor Group
 
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
Import Motorworks
 
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
Fifth Gear Automotive Cross Roads
 
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
mymwpc
 
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
mymwpc
 
Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?
jennifermiller8137
 
Things to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your carThings to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your car
jennifermiller8137
 
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptxStatistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
coc7987515756
 
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs  Consulting SMEs.pptxEmpowering Limpopo Entrepreneurs  Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Precious Mvulane CA (SA),RA
 

Recently uploaded (20)

欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
欧洲杯比赛投注官网-欧洲杯比赛投注官网网站-欧洲杯比赛投注官网|【​网址​🎉ac123.net🎉​】
 
How To Fix The Key Not Detected Issue In Mercedes Cars
How To Fix The Key Not Detected Issue In Mercedes CarsHow To Fix The Key Not Detected Issue In Mercedes Cars
How To Fix The Key Not Detected Issue In Mercedes Cars
 
Antique Plastic Traders Company Profile
Antique Plastic Traders Company ProfileAntique Plastic Traders Company Profile
Antique Plastic Traders Company Profile
 
What Could Cause The Headlights On Your Porsche 911 To Stop Working
What Could Cause The Headlights On Your Porsche 911 To Stop WorkingWhat Could Cause The Headlights On Your Porsche 911 To Stop Working
What Could Cause The Headlights On Your Porsche 911 To Stop Working
 
Hero Glamour Xtec Brochure | Hero MotoCorp
Hero Glamour Xtec Brochure | Hero MotoCorpHero Glamour Xtec Brochure | Hero MotoCorp
Hero Glamour Xtec Brochure | Hero MotoCorp
 
Skoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda PerthSkoda Octavia Rs for Sale Perth | Skoda Perth
Skoda Octavia Rs for Sale Perth | Skoda Perth
 
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
一比一原版(UNITEC毕业证)UNITEC理工学院毕业证成绩单如何办理
 
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
5 Warning Signs Your Mercedes Exhaust Back Pressure Sensor Is Failing
 
TRAINEES-RECORD-BOOK- electronics and electrical
TRAINEES-RECORD-BOOK- electronics and electricalTRAINEES-RECORD-BOOK- electronics and electrical
TRAINEES-RECORD-BOOK- electronics and electrical
 
Renal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffffRenal elimination.pdf fffffffffffffffffffff
Renal elimination.pdf fffffffffffffffffffff
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
 
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
What Are The Immediate Steps To Take When The VW Temperature Light Starts Fla...
 
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
5 Red Flags Your VW Camshaft Position Sensor Might Be Failing
 
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
一比一原版(OP毕业证)奥塔哥理工学院毕业证成绩单如何办理
 
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
一比一原版(AUT毕业证)奥克兰理工大学毕业证成绩单如何办理
 
Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?Digital Fleet Management - Why Your Business Need It?
Digital Fleet Management - Why Your Business Need It?
 
Things to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your carThings to remember while upgrading the brakes of your car
Things to remember while upgrading the brakes of your car
 
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptxStatistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
Statistics5,c.xz,c.;c.;d.c;d;ssssss.pptx
 
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs  Consulting SMEs.pptxEmpowering Limpopo Entrepreneurs  Consulting SMEs.pptx
Empowering Limpopo Entrepreneurs Consulting SMEs.pptx
 

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