Download presentation
Presentation is loading. Please wait.
1
Nonregular languages & the pumping lemma
CS 350 β Fall 2018 gilray.org/classes/fall2018/cs350/
2
Is the language L regular
Is the language L regular? Can we model it using a finite automaton (NFA/DFA)? πΏ={ a π b π |πββ}
3
Essentially the same as the language of matching parenthesis!
Is the language L regular? Can we model it using a finite automaton (NFA/DFA)? πΏ={ a π b π |πββ} Essentially the same as the language of matching parenthesis! πΏ β² ={ ( π ) π |πββ}
4
aaaaaaaaaaaaaaabbbbbbbbbbbbbbb
The DFA state after reading this prefix, must encode , an unbounded number. π π aaaaaaaaaaaaaaabbbbbbbbbbbbbbb π
5
aaaaaaaaaaaaaaabbbbbbbbbbbbbbb
The number of states in the DFA modeling L would thus need to be countably infinite. (This reasoning is informalβthe forthcoming pumping lemma will help make it rigorous.) aaaaaaaaaaaaaaabbbbbbbbbbbbbbb π Just as here, the DFA needs to record that bs must be encountered to accept. π
6
The pumping lemma (for regular languages): (a necessary, but not sufficient, condition for regular languages) If L is a regular language, then there exists some non-zero constant length, p β β β§ p > 0, such that any string w in the language of at least length p, w β L β§ |w| β₯ p, can be subdivided into three substrings with a non-empty middle substring, w = xyz β§ yβ Ξ΅, such that p β₯ |xy| and all strings made instead from zero or more repetitions of the middle substring, y, must also be in the language: { xynz | n β β } β L.
7
All finite languages are regular!
Language {s1, β¦, sn} can be encoded as regular expression: s1 | s2 | s3 | β¦ | sn For example, the language of strings aβ¦z with 1 character removed: bcdβ¦xyz | acβ¦.yz | abdeβ¦yz | β¦ | abβ¦wxz | aβ¦vwxy
8
All finite languages are regular!
b π π a π π π a π π π
9
Note: for a finite language, we do not require kleene star
to define a regular expression and we do not need loops to define a finite automaton! (In fact, these are our only way of defining a language of infinitely many strings using an RE/DFA/NFA!) Thus the language defined by a RE/NFA/DFA may contain infinitely many strings, but if-so, all sufficiently long strings must exhibit a pattern/regularity in how the language generates an infinite number of stringsβa pattern that may be characterized by looping/repetition.
10
The pumping lemma (for regular languages):
If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
11
The pumping lemma in terms of a DFA
We fix p to be the number of states in the DFA q0 qF w Some path must accept a string w of length at least p (or language L is finite)
12
The pumping lemma in terms of a DFA
To accept the string w, must traverse a loop at least once. wp-1 w1 q2 q0 qp-1 q1 . . . qp-2 w0 wp-2 This is due to the pigeonhole principle. Avoiding a loop as long as possible, we could cross p-1 edges to p distinct statesβthe pth letter in w (wp-1), however, must still return to some previously seen state.
13
The pumping lemma in terms of a DFA
there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| β§ |xyz| β₯ p such that, for all n β β, xynz β L q0 qF w = xyz We know this must be true becauseβby the pigeonhole principleβthere must be some state (need not be qF), call it qy, that is visited more than once!
14
The pumping lemma in terms of a DFA
there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| β§ |xyz| β₯ p such that, for all n β β, xynz β L y q0 qF z qy x We know this must be true becauseβby the pigeonhole principleβthere must be some state, call it qy, that is visited more than once!
15
The pumping lemma as a proposition
If L is a regular language, then βπββ.π>0 βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ
16
Contrapositive of the pumping lemma!
Β¬βπββ.π>0 βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
17
Contrapositive of the pumping lemma!
βπββ.π>0 Β¬βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
18
Contrapositive of the pumping lemma!
βπββ.π>0 βπ€βπΏ.|π€|β₯π Β¬βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
19
Contrapositive of the pumping lemma!
βπββ.π>0 βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π Β¬βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
20
Contrapositive of the pumping lemma!
βπββ.π>0 βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
21
βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π
The pumping lemma as an adversarial game βFor allβ means that we must remain general & assume an adversary may pick any value for p βπββ.π>0 βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
22
βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π
The pumping lemma as an adversarial game βπββ.π>0 βThere existsβ here means we may select a particular string w to suite our proof strategy. βπ€βπΏ.|π€|β₯π βπ₯,π¦,π§β Ξ£ β .π€=π₯π¦π§β§|π¦|>0β§|π₯π¦|β€π βπββ.π₯ π¦ π π§βπΏ Then L is not a regular language!
23
Try an example: use the pumping lemma to show that the language L is not regular.
πΏ={ a π b π |πββ}
24
Try an example: use the pumping lemma to show that the language L is not regular.
πΏ={ a π b π |πββ} First, without loss of generality, we assume the pumping length is p. If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
25
Try an example: use the pumping lemma to show that the language L is not regular.
πΏ={ a π b π |πββ} Second, to show the lemma is not true of all sufficiently long strings w in L, it suffices to show there exists a sufficiently long string w in L for which the lemma does not hold. (Recall De Morganβs Laws.) If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
26
Try an example: use the pumping lemma to show that the language L is not regular.
πΏ={ a π b π |πββ} We choose the string apbp as a sufficiently long string w, where the pumping lemma should hold (if L were regular), but does not. If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
27
Try an example: use the pumping lemma to show that the language L is not regular.
πΏ={ a π b π |πββ} Thus, for the pumping lemma to hold, we must be able to decompose apbp into substrings xyz such that |xy| is not greater than p, y is nonempty, and y can be repeated any number of times. If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
28
aaaaaaaaaaaaaaabbbbbbbbbbbbbbb
Try an example: use the pumping lemma to show that the language L is not regular. πΏ={ a π b π |πββ} πβ₯|π₯π¦| aaaaaaaaaaaaaaabbbbbbbbbbbbbbb |π₯| |π¦|>0 If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
29
aaaaaaaaaaaaaaabbbbbbbbbbbbbbb
There we cannot remove y, or βpumpβ it more than once without upsetting the balance of as and bs! Therefore, L is not regular. πΏ={ a π b π |πββ} πβ₯|π₯π¦| aaaaaaaaaaaaaaabbbbbbbbbbbbbbb |π₯| |π¦|>0 If L is a regular language, then there exists a pumping length p β β β§ p > 0, such that for all strings w where w β L β§ |w| β₯ p, there exists strings x,y,z β Ξ£* where w = xyz β§ yβ Ξ΅ β§ p β₯ |xy| such that, for all n β β, xynz β L
30
πΏ={ π 1 β¦ π π |πβββ§ π π β{a,b}β§ π π = π π+1βπ }
Try an example: use the pumping lemma to show that the language, L, of all palindromes over alphabet {a,b} is not regular. πΏ={ π 1 β¦ π π |πβββ§ π π β{a,b}β§ π π = π π+1βπ }
31
πΏ={ π 1 β¦ π π |πβββ§ π π β{a,b}β§ π π = π π+1βπ }
Try an example: use the pumping lemma to show that the language, L, of all palindromes over alphabet {a,b} is not regular. πΏ={ π 1 β¦ π π |πβββ§ π π β{a,b}β§ π π = π π+1βπ } We assume L is regular and, without loss of generality, that the pumping length is some positive integer p. Select string w to be apbap. If the pumping lemma held, it would be the case that w = apbap = xyz where |xy| is no larger than p, |y| is nonzero, and xyyz is also in language L. Since string y must be am for some positive integer m, the string xyyz would be ap+|y|bap which cannot be a palindrome as the stringβs only b is off-center.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.