conversions & pumping lemma cpsc 388 fall 2001 ellen walker hiram college

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

Post on 19-Jan-2016

213 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Conversions & Pumping LemmaCPSC 388 Fall 2001Ellen WalkerHiram College

  • For every r.e. there is a DFA...If we can construct an NFA, thats good enoughProve by induction:Base cases: , , a (element of ) -- build an NFA for each.Step cases: r | s , rs , r* -- build resulting NFA from NFAs from r and/or s

  • Base Cases

    e

    a

    a

  • A Generic NFAInitial and (single) accept stateFor multiple accept states, add e-transitions from all accept states to one Arbitrary labeled connections (and other states) as well

  • NFA for Concatenation (rs)

  • NFA for choice (r | s)

  • NFA for star (a*)

  • Completing the ProofBecause 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

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

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

    s

    t

    r

    v

  • Extending to Larger DFAsFor any state that is neither initial nor final, compute r.e. for each path *through* the stateReplace the state by links labeled with the full regular expressionsRepeat until all states are initial or final, then make a choice of all paths

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

  • A Regular GrammarA regular grammar is a grammar with all rules of the formX -> aX -> 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

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

  • A non-regular languageAll strings of the form a*b* where the number of as is equal to the number of bsThis language requires a way of keeping track of how many as weve seen -- but the only way we can keep track is by the number of states!

  • Proving a Language Non-RegularI tried real hard and couldnt come up with a DFA, NFA, or regular expression -- not a proof!

    There is a property that all regular languages have that this one doesnt -- now thats a proof

  • Long Strings Need LoopsA 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)

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

  • Using the Pumping LemmaPick a string in the language that is longer than NShow that there is no way to divide it up according to the rules of the lemmaTherefore, by contradiction, the language cannot be regular

  • An example: a*b*, #as = #bs1. Assume its regular. Pick the string with N as and N bs2. Since |xy| N, y must have all as3. Pumping xyyz has too many as4. But the pumping lemma said that string had to be in the language.5. We have a contradiction, so the language is not regular.

  • Notes on applying the pumping lemmaIt only has to fail for one string in the language(But) It has to fail for all legal assignments of xyzSometimes its easier to pump down to xz instead of pumping up to xyyz

  • L= a* where the number of as is square1. Assume the language is regular. Pick the string of N2 as2. If we divide it we have |xy| N3. xyyz is at most (N2+N) as.4. But, the next biggest square is N2+N+1 (so this string cannot be accepted)!5. So the pumping lemma doesnt hold, so the language is not regular.

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

Recommended

View more >