cd5560 faber formal languages, automata and models of computation lecture 10
DESCRIPTION
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10 Mälardalen University 2010. Content The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL Midterm Exam 2: Context-Free Languages. Pumping Lemma for CFL’s. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/1.jpg)
1
CD5560
FABER
Formal Languages, Automata and Models of Computation
Lecture 10
Mälardalen University
2010
![Page 2: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/2.jpg)
2
Content
The Pumping Lemma for CFLApplications of the Pumping Lemma for CFL
Midterm Exam 2: Context-Free Languages
![Page 3: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/3.jpg)
3
Pumping Lemma for CFL’s
![Page 4: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/4.jpg)
4
Comparison to Regular Language Pumping Lemma/Condition
![Page 5: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/5.jpg)
5
What’s Difference between CFL’s and Regular Languages?
In regular languages, a single substring “pumps”
...... ......q
![Page 6: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/6.jpg)
6
What’s Difference between CFL’s and Regular Languages?
In CFL’s, multiple substrings can be “pumped”– Consider the language {anbn | n > 0}
– No single substring can be pumped and allow us to stay in the language
– However, there do exist pairs of substrings which can be pumped resulting in strings which stay in the language
Thus, a modified pumping lemma applies.
![Page 7: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/7.jpg)
7
Pumping Conditions for RL and CFL
A language L satisfies the RL pumping condition if: – there exists an integer m > 0
such that– for all strings x in L of length at
least m– there exist strings u, v, w such
that• x = uvw and• |uv| ≤ m and• |v| ≥ 1 and• For all i ≥ 0, uviw is in L
A language L satisfies the CFL pumping condition if: – there exists an integer m > 0
such that– for all strings x in L of length at
least m– there exist strings u, v, w, y, z
such that• x = uvwyz and• |vwy| ≤ m and• |vy| ≥ 1 and• For all i ≥ 0, uviwyiz is in L
![Page 8: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/8.jpg)
8
Pumping Lemma
All CFL’s satisfy the CFL pumping condition
All languages over {a,b}
“Pumping Languages”
CFL’s
![Page 9: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/9.jpg)
9
Implications
• We can use the pumping lemma to prove a language L is not a CFL– Show L does not satisfy the CFL pumping
condition• We cannot use the pumping lemma to prove
a language is CFL– Showing L satisfies the pumping condition
does not guarantee that L is context-free
All languages over {a,b}
“Pumping Languages”
CFL’s
![Page 10: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/10.jpg)
10
Pumping Lemma
What does it mean?
![Page 11: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/11.jpg)
11
Pumping Condition
• A language L satisfies the CFL pumping condition if: – there exists an integer m > 0 such that– for all strings x in L of length at least m– there exist strings u, v, w, y, z such that
• x = uvwyz and• |vwy| ≤ m and• |vy| ≥ 1 and• For all i ≥ 0, uviwyiz is in L
![Page 12: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/12.jpg)
12
v and y can be pumped
• Let x = abcdefg be in L• Then there exist substrings v and y in x such
that v and y can be repeated (pumped) and the resulting string is still in L– uviwyiz is in L for all i ≥ 0
1) x in L2) x = uvwyz3) For all i ≥ 0, uviwyiz is in L
![Page 13: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/13.jpg)
13
For example x = abcdefg
v = cd and y = f
uv0wy0z = uwz = abeg is in L
uv1wy1z = uvwyz = abcdefg is in L
uv2wy2z = uvvwyyz = abcdcdeffg is in L
uv3wy3z = uvvvwyyyz = abcdcdcdefffg is in L
…
![Page 14: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/14.jpg)
14
What the other parts mean
A language L satisfies the CFL pumping condition if: – there exists an integer m > 0 such that– for all strings x in L of length at least m
• x must be in L and have sufficient length
![Page 15: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/15.jpg)
15
What the other parts mean
– there exist strings u, v, w, y, z such that• x = uvwyz and• |vwy| ≤ m and
–v and y are contained within m characters of x–Note: these are NOT necessarily the first m
characters of x• |vy| ≥ 1 and
–v and y cannot both be l,–One of them might be l, but not both
• For all i ≥ 0, uviwyiz is in L
![Page 16: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/16.jpg)
16
Pumping Lemma
Applying it to prove a specific language L is not context-free
![Page 17: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/17.jpg)
17
How we use the Pumping Lemma
• We choose a specific language L
For example {aj bj cj | j > 0}
• We show that L does not satisfy the pumping condition
• We conclude that L is not context-free
![Page 18: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/18.jpg)
18
Showing L “does not pump”
A language L satisfies the CFL pumping condition if: – there exists an integer n >
0 such that– for all strings x in L of
length at least m– there exist strings u, v, w,
y, z such that• x = uvwyz and• |vwy| ≤ m and• |vy| ≥ 1 and• For all i ≥ 0, uviwyiz is
in L
A language L does not satisfy the CFL pumping condition if: – for all integers m of sufficient
size– there exists a string x in L of
length at least m such that– for all strings u, v, w, y, z
such that• x = uvwyz and• |vwy| ≤ m and• |vy| ≥ 1
– There exists a i ≥ 0 such that uviwyiz is not in L
![Page 19: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/19.jpg)
19
Example Languages
• TWOCOPIES = {ww | w is in {a,b}* }– abbabb is in TWOCOPIES but abaabb is not
• EQUAL3 = {the set of strings over {a, b, c} such that the number of a’s equals the number of b’s equals the number of c’s}
• {ai bj ck | i < j < k}
![Page 20: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/20.jpg)
20
More Pumping Lemma Applications
![Page 21: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/21.jpg)
21
The Pumping Lemma for CFL
there exists an integer such that m
for any string mwLw || ,
we can write
For infinite context-free language L
uvxyzw
with lengths 1||and || vymvxy
and 0 allfor , iLzxyuv ii
![Page 22: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/22.jpg)
22
The Pumping Lemma for CFL
There exists an integer such that m
mwGLw || ),(
can be written
Let be a context free grammar. G
uvxyzw
with lengths 1||and || vymvxy
and 0 allfor , iLzxyuv ii
![Page 23: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/23.jpg)
23
Regular Languages
}{ nnba }{ RwwContext-Free Languages
Non-regular languages
Unrestricted grammar languages
}0:{ ncba nnn
**ba
![Page 24: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/24.jpg)
24
Theorem The language
}*},{:{ bawwwL
is not context free
Proof Use the Pumping Lemma
for context-free languages
![Page 25: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/25.jpg)
25
Assume the contrary - that
is context-free
Since is context-free and infinite
we can apply the pumping lemma
L
L
}*},{:{ bawwwL
![Page 26: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/26.jpg)
26
Pumping Lemma gives a number
such that:
m
we pick: Lbaba mmmm
}*},{:{ bawwwL
Pick any string of
with length at least mL
![Page 27: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/27.jpg)
27
We can write:
}*},{:{ bawwwL
uvxyzbaba mmmm
Pumping Lemma says:
Lzxyuv ii for all 0i
with lengths mvxy || 1|| vyand
![Page 28: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/28.jpg)
28
We examine all the possible locations
of string in vxy
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
mmmm baba
![Page 29: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/29.jpg)
29
Case 1: vxy is within the firstma
bbaabbaa ........................v
m m m
u z
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
x y
m
1kav 2kay 121 kk
![Page 30: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/30.jpg)
30
bbaabbaa ..................................2v
21 kkm m m
u z
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
x 2y
m
Case 1: vxy is within the firstma
1kav 2kay 121 kk
![Page 31: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/31.jpg)
31
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
Case 1: vxy is within the firstma
121 kk
Lzxyuvbaba mmmkkm 2221
![Page 32: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/32.jpg)
32
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
Case 1: vxy is within the firstma
Contradiction!
Lzxyuvbaba mmmkkm 2221
Lzxyuv 22However, from Pumping Lemma:
![Page 33: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/33.jpg)
33
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
bbaabbaa ........................v
m m m
u zx y
m
is in the first
is in the firstCase 2: mamb
vy
1kav 2kby 121 kk
![Page 34: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/34.jpg)
34
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
bbaabbaa ....................................2v
1km 2km m
u zx 2y
m
is in the first
is in the firstCase 2: mamb
vy
1kav 2kby 121 kk
![Page 35: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/35.jpg)
35
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
is in the first
is in the firstCase 2: mamb
vy
121 kk
Lzxyuvbaba mmkmkm 2221
![Page 36: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/36.jpg)
36
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
is in the first
is in the firstCase 2: mamb
vy
Lzxyuvbaba mmkmkm 2221
Contradiction!
Lzxyuv 22However, from Pumping Lemma:
![Page 37: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/37.jpg)
37
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
bbaabbaa ........................v
m m m
u zx y
m
is in the first
overlaps the firstCase 3: mmbamb
vy
21 kk bav 3kby 1, 21 kk
![Page 38: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/38.jpg)
38
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
is in the first
overlaps the firstCase 3: mmbamb
vy
21 kk bav 3kby 1, 21 kk
2v zx 2y
bbaabbbbaaaa .................................m 2k 3km
u
m1k m
![Page 39: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/39.jpg)
39
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
is in the first
overlaps the firstCase 3: mmbamb
vy
Lzxyuvbabbaa mmkmkkm 22321
1, 21 kk
![Page 40: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/40.jpg)
40
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
is in the first
overlaps the firstCase 3: mmbamb
vy
Lzxyuvbabbaa mmkkkm 22321
Contradiction!
Lzxyuv 22However, from Pumping Lemma:
![Page 41: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/41.jpg)
41
Overlaps the first
in the firstCase 4:
bbaabbaa ........................v
m m m
u z
mvxy || 1|| vyuvxyzbaba mmmm
}*},{:{ bawwwL
x y
m
mammba
vy
Analysis is similar to case 3
![Page 42: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/42.jpg)
42
Other cases: vxy is within
mmmm babaor
or
mmmm baba
mmmm baba
Analysis is similar to case 1: mmmm baba
![Page 43: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/43.jpg)
43
More cases: vxy overlaps
mmmm baba ormmmm baba
Analysis is similar to cases 2,3,4:
mmmm baba
![Page 44: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/44.jpg)
44
Since , it is impossible for
to overlap:
There are no other cases to consider
mvxy ||vxy
mmmm baba
nor normmmm baba mmmm baba
neither
![Page 45: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/45.jpg)
45
In all cases we obtained a contradiction
Therefore: The original assumption that
is context-free must be wrong
Conclusion: is not context-freeL
}*},{:{ bawwwL
END OF PROOF
![Page 46: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/46.jpg)
46
Regular Languages
}{ nnba }{ RwwContext-Free Languages
Non-regular languages
Unrestricted grammar languages
}0:{ ncba nnn
**ba
}{ww
![Page 47: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/47.jpg)
47
Theorem The language
is not context free
Proof Use the Pumping Lemma
for context-free languages
}0:{ ! naL n
![Page 48: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/48.jpg)
48
Since is context-free and infinite
we can apply the pumping lemma
L
Assume to the contrary that
is context-free
L
}0:{ ! naL n
![Page 49: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/49.jpg)
49
Pumping Lemma gives a magic number
such that:
m
we pick: Lam !
Pick any string of with length at least mL
}0:{ ! naL n
![Page 50: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/50.jpg)
50
We can write: uvxyzam !
Pumping Lemma says:
Lzxyuv ii for all 0i
}0:{ ! naL n
with lengths mvxy || 1|| vy and
![Page 51: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/51.jpg)
51
We examine all the possible locations
of string in vxy !ma
mvxy || 1|| vyuvxyzam !
There is only one case to consider
}0:{ ! naL n
![Page 52: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/52.jpg)
52
v
!m
u zx y
1kav 2kay mkk 211
aa ...............
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
![Page 53: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/53.jpg)
53
2v
21! kkm
u zx 2y
1kav 2kay
aa ...........................
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
mkk 211
![Page 54: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/54.jpg)
54
2v
km !
u zx 2y
1kav 2kay
aa ...........................
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
mk 1
21 kkk
![Page 55: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/55.jpg)
55
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
mk 1
zxyuva km 22!
![Page 56: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/56.jpg)
56
)!1(
)1(!
!!
!!
m
mm
mmm
mmkm
)!1(!! mkmm
mk 1Since
2m we have:for
![Page 57: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/57.jpg)
57
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
Lzxyuva km 22!
)!1(!! mkmm
![Page 58: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/58.jpg)
58
mvxy || 1|| vyuvxyzam !
}0:{ ! naL n
Lzxyuva km 22!
Lzxyuv 22
Contradiction!
However, from Pumping Lemma:
![Page 59: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/59.jpg)
59
We obtained a contradiction
Therefore: The original assumption that
is context-free must be wrong
Conclusion: is not context-freeL
}0:{ ! naL n
END OF PROOF
![Page 60: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/60.jpg)
60
Regular Languages
**ba
Context-free languages
Unrestricted grammar languages}0:{ ncba nnn
}0:{ nba nn
}},{:{ bawww
}*},{:{ bawwwR
}0:{ ! nan }0:{2
nba nn
![Page 61: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/61.jpg)
61
Theorem The language
is not context free
Proof Use the Pumping Lemma
for context-free languages
}0:{2
nbaL nn
![Page 62: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/62.jpg)
62
Since is context-free and infinite
we can apply the pumping lemma
L
Assume to the contrary that
is context-free
L
}0:{2
nbaL nn
![Page 63: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/63.jpg)
63
Pumping Lemma gives a number
such that:
m
we pick: Lba mm 2
Pick any string of with length at least mL
}0:{2
nbaL nn
![Page 64: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/64.jpg)
64
We can write:
with lengths andmvxy || 1|| vy
uvxyzba mm 2
Pumping Lemma says:
Lzxyuv ii for all 0i
}0:{2
nbaL nn
![Page 65: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/65.jpg)
65
We examine all the possible locations
of string in vxy
mvxy || 1|| vyuvxyzba mm 2
mm ba2
}0:{2
nbaL nn
![Page 66: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/66.jpg)
66
Most complicated case:
bbaa ...........................v
2m m
u zx y
is in
is inmamb
vy
}0:{2
nbaL nn
mvxy || 1|| vyuvxyzba mm 2
![Page 67: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/67.jpg)
67
bbaa ...........................v
2m m
u zx y
1kav 2kby
}0:{2
nbaL nn
mkk 211
mvxy || 1|| vyuvxyzba mm 2
![Page 68: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/68.jpg)
68
bbaa ...........................v
2m m
u zx y
1kav 2kby
Most complicated sub-case: 01 k 02 k
}0:{2
nbaL nn
mkk 211
and
mvxy || 1|| vyuvxyzba mm 2
![Page 69: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/69.jpg)
690v
12 km 2km
u zx 0y
bbaa ..................
}0:{2
nbaL nn
1kav 2kby
Most complicated sub-case: 01 k 02 k
mkk 211
and
mvxy || 1|| vyuvxyzba mm 2
![Page 70: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/70.jpg)
70
}0:{2
nbaL nn
1kav 2kby
Most complicated sub-case: 01 k 02 k
mkk 211
and
zxyuvba kmkm 00212
mvxy || 1|| vyuvxyzba mm 2
![Page 71: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/71.jpg)
71
12
2
222
12
)1()(
km
mm
mkm
01 k 02 k mkk 211and
221
2 )( kmkm
![Page 72: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/72.jpg)
72
}0:{2
nbaL nn
221
2 )( kmkm
Lzxyuvba kmkm 00212
mvxy || 1|| vyuvxyzba mm 2
![Page 73: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/73.jpg)
73
}0:{2
nbaL nn
Lzxyuvba kmkm 00212
However, from Pumping Lemma:
Lzxyuv 00
Contradiction!
mvxy || 1|| vyuvxyzba mm 2
![Page 74: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/74.jpg)
74
When we examine the rest of the cases
we also obtain a contradiction
![Page 75: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/75.jpg)
75
In all cases we obtained a contradiction
Therefore: The original assumption that
is context-free must be wrong
Conclusion: is not context-freeL
}0:{2
nbaL nn
END OF PROOF
![Page 76: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/76.jpg)
76
Check your knowledge before midterm exam!
Selected Examplesof
CF Language Problems
![Page 77: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/77.jpg)
77
Let G be the grammar with productions:
Claim: L(G) = L
||
bBcB
BaScS
}:{ mnkcbaL kmn Find a CFG for the following language
Example
![Page 78: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/78.jpg)
78
Proof:Consider the following derivation:
(the first * applies S aSc n times, the second * to B bBc m times)
Since all words in L(G) must follow this pattern in their derivations, it is clear that L(G) L
Find a CFG for the following language
||
bBcB
BaScS
}:{ mnkcbaL kmn
)(
**
mncmbna
ncmcBmbnancBnancSnaS
![Page 79: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/79.jpg)
79
Consider w L, w = anbmc(n + m) for some n, m 0
The derivation
S * anScn anBcn * anbmBcmcn anbmc(n + m) clearly produces w for any n, m.
L L(G) L L(G)
G is a CFG for L
Find a CFG for the following language
}:{ mnkcbaL kmn
END OF PROOF
||
bBcB
BaScS
![Page 80: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/80.jpg)
80
}:{ 32 NnbaL nn Find a PDA and CFG for the following language
Example
Is the automaton deterministic? Yes. It acts in a unique way in each state, no -transitions.
fqiq
/, 23 ab22 /, aa
/, 23 ab
![Page 81: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/81.jpg)
81
CFG : 32| SbaS
}:{ 32 NnbaL nn
fqiq
/, 23 ab22 /, aa
/, 23 ab
![Page 82: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/82.jpg)
82
}2:},{{ ba nnbaxL Find a PDA and CFG for the following language
Example
bb
aa
/,
/,
/,
/,
/,
/,
aab
aba
aab
baa
PDA
![Page 83: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/83.jpg)
83
CFG :
SSbSaSaaSaSbaSbSaS ||||
}2:},{{ ba nnbaxL bb
aa
/,
/,
/,
/,
/,
/,
aab
aba
aab
baa
![Page 84: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/84.jpg)
84
Consider the following two languages:
L1 ={w : w is made from a’s and b’s
and the length of w is a multiple of 10}
L2 = {anbn: n 0}
}:{ tenofmultipleNOTisnnbnaL
Prove that the language L is context-free
Example
![Page 85: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/85.jpg)
85
L1 ={w : w is made from a’s and b’s and the length of w is a multiple of ten}
L2 = {anbn: n 0}
Let L1 denote the complement of L1. We have that L = L1 L2.
L1 is a regular language, since we can easily build a finite automaton with 10 states that accepts any string in this language.
L1 is regular too, since regular languages are closed under complement.
![Page 86: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/86.jpg)
86
The language L2 is context-free.
The grammar is: S aSb |
Therefore, the language L = L1 L2 is also context-free,
since context-free languages are closed under regular intersection (Regular Closure).
END O PROOF
![Page 87: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/87.jpg)
87
}||,},{,:{ nxbaxNnaxL n Find a PDA and CFG for the following language
Example
CFG
babAaAA
AASaS
|||
||
ababaaabaAaaabAaa
AAaaAASaaASaS
Production ex.
![Page 88: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/88.jpg)
88
}||,},{,:{ nxbaxNnaxL n
PDA
fqiq
babAaAA
AASaS
|||/,
||/,
/,
/,
bb
aa
S/,
![Page 89: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/89.jpg)
89
}different are symbols finishing theand starting the
,:},{{ ba nnbaxL
Find a PDA and CFG for the following language
Example
PDA /,a
/,
/,
/,
/,
ba
bb
ab
aa
bb /,
/, ab /,a
/, a
/,
/,
/,
/,
ba
bb
ab
aa
![Page 90: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/90.jpg)
90
}different are symbols finishing theand starting the
,:},{{ ba nnbaxL
/,a
/,
/,
/,
/,
ba
bb
ab
aa
bb /,
/, ab /,a
/, a
/,
/,
/,
/,
ba
bb
ab
aa
CFG, direct construction
•Strings start and finish with different symbols
•Strings contain at least one more a than b
bAaaAbS |
bAAAbAAAbaAaA ||||(we must have AA here as only one A just balances b)
![Page 91: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 10](https://reader033.vdocument.in/reader033/viewer/2022051316/56815275550346895dc0a43b/html5/thumbnails/91.jpg)
91
http://www.liacs.nl/~hoogeboo/praatjes/tarragona/schoolpda-VIII.pdf
Famous Pushdown AutomataExamples