Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nonregular languages & the pumping lemma

Similar presentations


Presentation on theme: "Nonregular languages & the pumping lemma"β€” Presentation transcript:

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.


Download ppt "Nonregular languages & the pumping lemma"

Similar presentations


Ads by Google