1 / 23

Conversions & Pumping Lemma

Conversions & Pumping Lemma. CPSC 388 Fall 2001 Ellen Walker Hiram College. For every r.e. there is a DFA. If we can construct an NFA, that’s good enough Prove by induction: Base cases: , , a (element of ) -- build an NFA for each.

melindahall
Télécharger la présentation

Conversions & Pumping Lemma

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College

  2. For every r.e. there is a DFA... • If we can construct an NFA, that’s good enough • Prove by induction: • Base cases: , , a (element of ) -- build an NFA for each. • Step cases: r | s , rs , r* -- build resulting NFA from NFA’s from r and/or s

  3. Base Cases •  • e • a

  4. A Generic NFA • Initial and (single) accept state • For multiple accept states, add e-transitions from all accept states to one • Arbitrary labeled connections (and other states) as well

  5. NFA for Concatenation (rs)

  6. NFA for choice (r | s)

  7. NFA for star (a*)

  8. Completing the Proof • Because every r.e. can be constructed from basic r.e. (and each has an NFA) • And there are only 3 ways to combine r.e.’s (and we have NFA for each) • Therefore, we can create an NFA for every regular expression

  9. From DFA to R.E. • Every expression that a DFA accepts is represented by a path from an initial state to an accept state • If there are intermediate states, they can be deleted and represented by the r.e.’s necessary to get past them.

  10. R.E. from 2-state DFA This DFA accepts (r+ts*v)*ts* (Consider all paths from initial to final)

  11. Extending to Larger DFA’s • For any state that is neither initial nor final, compute r.e. for each path *through* the state • Replace the state by links labeled with the full regular expressions • Repeat until all states are initial or final, then make a choice of all paths

  12. Now find the expression for... • All strings that do not contain the sequence “ab” • Use • R.E. -> NFA for not-L ((a+b)*ab(a+b)*) • NFA -> DFA • Swap accept vs. not accept states (for L) • DFA -> R.E.

  13. A Regular Grammar • A regular grammar is a grammar with all rules of the form • X -> a • X -> aY (left linear rule) • X -> Ya (right linear rule) • Either left-linear or right-linear rules may be used, but not both in the same grammar

  14. Left-linear Grammar to NFA • X -> a • a-transition from X to accept state • (a can be e) • X -> aY • a-transition from X to Y • (Y can be X) • Use the same idea to take NFA to grammar!

  15. A non-regular language • All strings of the form a*b* where the number of a’s is equal to the number of b’s • This language requires a way of keeping track of how many a’s we’ve seen -- but the only way we can keep track is by the number of states!

  16. Proving a Language Non-Regular • “I tried real hard and couldn’t come up with a DFA, NFA, or regular expression…” -- not a proof! • “There is a property that all regular languages have that this one doesn’t…” -- now that’s a proof

  17. Long Strings Need Loops • A DFA has a finite number of states (N) • If we have N (or more) characters in a string, we must have visited one of the states twice within the first N-1 chars. • Therefore, there must be a loop. • Therefore, we can repeat part of the string an arbitrary # of times (including 0)

  18. A Pumping Lemma • Every string that is accepted by a DFA and is longer than N (number of states) can be divided into 3 parts (xyz), where • The length of xy ≤ N • The length of y>0 • The strings xz, xyyz, xyyyz, etc. are also in the language • (i.e. “y” is the part accepted by the loop)

  19. Using the Pumping Lemma • Pick a string in the language that is longer than N • Show that there is no way to divide it up according to the rules of the lemma • Therefore, by contradiction, the language cannot be regular

  20. An example: a*b*, #a’s = #b’s 1. Assume it’s regular. Pick the string with N a’s and N b’s 2. Since |xy| ≤ N, y must have all a’s 3. “Pumping” xyyz has too many a’s 4. But the pumping lemma said that string had to be in the language. 5. We have a contradiction, so the language is not regular.

  21. Notes on applying the pumping lemma • It only has to fail for one string in the language • (But…) It has to fail for all legal assignments of xyz • Sometimes it’s easier to “pump down” to xz instead of “pumping up” to xyyz

  22. L= a* where the number of a’s is square 1. Assume the language is regular. Pick the string of N2 a’s 2. If we divide it we have |xy| ≤ N 3. xyyz is at most (N2+N) a’s. 4. But, the next biggest square is N2+N+1 (so this string cannot be accepted)! 5. So the pumping lemma doesn’t hold, so the language is not regular.

  23. Proving a language... • Regular: • Give a regular expression • Give a finite automaton (NFA or DFA) • Create a regular grammar • Non-Regular: • Proof by contradiction using the pumping lemma

More Related