we now return to the question suppose a b are regular

We now return to the question: Suppose A, B are regular languages, - PowerPoint PPT Presentation

We now return to the question: Suppose A, B are regular languages, then not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w 1 w 2 : w 1 in A and w 2 in B } A* := { w 1 w 2 w k : k 0 , w i


  1. b* Example a* ab q 1 q 0 q a Accepts w = aaabbab w 1 =aaa w 2 =bb w 3 =ab r 0 =q 0 r 1 =q 1 r 2 =q 1 r 3 = ? w 1 = aaa  L( d (r 0 ,r 1 )) = L( d (q 0 ,q 1 )) = L(a*) w 2 = bb  L( d (r 1 ,r 2 )) = L( d (q 1 ,q 1 )) = L(b*)

  2. b* Example a* ab q 1 q 0 q a Accepts w = aaabbab w 1 =aaa w 2 =bb w 3 =ab r 0 =q 0 r 1 =q 1 r 2 =q 1 r 3 = q a w 1 = aaa  L( d (r 0 ,r 1 )) = L( d (q 0 ,q 1 )) = L(a*) w 2 = bb  L( d (r 1 ,r 2 )) = L( d (q 1 ,q 1 )) = L(b*) w 3 = ab  L( d (r 2 ,r 3 )) = L( d (q 1 ,q a )) = L(ab)

  3. Theorem:  DFA M  GNFA N : L(N) = L(M) Construction: To ensure unique transition between each pair: 1 U 0 1 0 To ensure unique final state, no transitions ingoing start state, no transitions outgoing final state: e e e e

  4. Theorem:  GNFA N  RE R : L(R) = L(N) Construction: S If N has 2 states, then N = q 0 q a thus R := S If N has > 2 states, eliminate some state q r  q 0 , q a : for every ordered pair q i , q j (possibly equal) that are connected through q r R 2 R 1 R 2 *R 3 U R 4 R 3 R 1 q i q r q j q i q j R 4 Repeat until 2 states remain

  5. Example: DFA → GNFA → RE DFA a b b,c q 2 q 1

  6. Example: DFA → GNFA → RE GNFA a b b U c e e q a q 2 q 0 q 1

  7. Example: DFA → GNFA → RE a b b U c e e q a q 2 q 0 q 1 Eliminate q 1 : re-draw GNFA with all other states b e q a q 2 q 0

  8. Example: DFA → GNFA → RE a b b U c e e q a q 2 q 0 q 1 Eliminate q 1 : find a path through q 1 b e q a q 2 q 0

  9. Example: DFA → GNFA → RE Ø a b b U c e e q a q 2 q 0 q 1 Eliminate q 1 : add edge to new GNFA Don't forget: no arrow means label Ø b e a* (b U c) U Ø e q a q 2 q 0

  10. Example: DFA → GNFA → RE a b b U c e e q a q 2 q 0 q 1 Eliminate q 1 : simplify RE on new edge b a* (b U c) e q a q 2 q 0

  11. Example: DFA → GNFA → RE a b b U c e e q a q 2 q 0 q 1 Eliminate q 1 : if no more paths through q 1 , start over b a* (b U c) e q a q 2 q 0

  12. Example: DFA → GNFA → RE b a* (b U c) e q a q 2 q 0 Eliminate q 2 : re-draw GNFA with all other states q a q 0

  13. Example: DFA → GNFA → RE b a* (b U c) e q a q 2 q 0 Eliminate q 2 : find a path through q 2 q a q 0

  14. Example: DFA → GNFA → RE b a* (b U c) e q a q 2 q 0 Eliminate q 2 : add edge to new GNFA a* (b U c) b* e U Ø q a q 0

  15. Example: DFA → GNFA → RE b a* (b U c) e q a q 2 q 0 Eliminate q 2 : simplify RE on new edge a* (b U c) b* q a q 0

  16. Example: DFA → GNFA → RE b a* (b U c) e q a q 2 q 0 Eliminate q 2 : if no more paths through q 2 , start over a* (b U c) b* q a q 0

  17. Example: DFA → GNFA → RE a* (b U c) b* q a q 0 Only two states remain: RE = a* (b U c) b*

  18. ANOTHER Example: DFA → GNFA → RE a DFA b q 3 q 1 c a c q 2 b

  19. ANOTHER Example: DFA → GNFA → RE a GNFA e e b q 3 q q 0 q 1 a c a c q 2 b

  20. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b re-draw GNFA with all other states e q 3 q a q 0 a q 2 b

  21. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b find a path through q 1 e q 3 q a q 0 a q 2 b

  22. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b add edge to new GNFA e e a*b U Ø q 3 q a q 0 a q 2 b

  23. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b find another path through q 1 e e a*b U Ø q 3 q a q 0 a q 2 b

  24. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b add edge to new GNFA e e a*b U Ø q 3 q a q 0 a e a*c U Ø q 2 b

  25. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b find another path through q 1 e e a*b U Ø q 3 q a q 0 a e a*c U Ø q 2 b

  26. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 don't forget current Eliminate q 1 : q 2 → q 3 edge! b add edge to This time is not Ø ! new GNFA e e a*b U Ø q 3 q a q 0 ca*b U a e a*c U Ø q 2 b

  27. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b find another path through q 1 e e a*b U Ø q 3 q a q 0 ca*b U a e a*c U Ø q 2 b

  28. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 don't forget current Eliminate q 1 : q 2 → q 2 edge! b add edge to new GNFA e e a*b U Ø q 3 q a q 0 ca*b U a e a*c U Ø q 2 ca*c U b

  29. ANOTHER Example: DFA → GNFA → RE a e e b q 3 q q 0 q 1 a c a c q 2 Eliminate q 1 : b when no more paths through q 1 , start over e a*b (and simplify q 3 q a q 0 REs) ca*b U a a*c q 2 ca*c U b

  30. ANOTHER Example: DFA → GNFA → RE e a*b q 3 q a q 0 ca*b U a a*c q 2 ca*c U b Eliminate q 2 : re-draw GNFA with all other states a*b e q 0 q 3 q a

  31. ANOTHER Example: DFA → GNFA → RE e a*b q 3 q a q 0 ca*b U a a*c q 2 ca*c U b Eliminate q 2 : find a path through q 2 a*b e q 0 q 3 q a

  32. ANOTHER Example: DFA → GNFA → RE e a*b q 3 q a q 0 ca*b U a a*c q 2 ca*c U b Eliminate q 2 : add edge to new GNFA a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a

  33. ANOTHER Example: DFA → GNFA → RE e a*b q 3 q a q 0 ca*b U a a*c q 2 Eliminate q 2 : ca*c U b when no more paths through q 2 , start over a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a

  34. ANOTHER Example: DFA → GNFA → RE a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a Eliminate q 3 : re-draw GNFA with all other states q 0 q a

  35. ANOTHER Example: DFA → GNFA → RE a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a Ø Eliminate q 3 : Ø find a path through q 3 don't forget: no arrow means Ø q 0 q a

  36. ANOTHER Example: DFA → GNFA → RE a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a Ø Eliminate q 3 : Ø add edge to new GNFA (a*c(ca*c U b)*(ca*b U a) U a*b) Ø* ε U Ø q 0 q a

  37. ANOTHER Example: DFA → GNFA → RE a*c(ca*c U b)*(ca*b U a) U a*b e q 0 q 3 q a Eliminate q 3 : when no more paths through q 3 , start over (and simplify REs) don't forget: Ø*= ε a*c(ca*c U b)*(ca*b U a) U a*b q 0 q a

  38. ANOTHER Example: DFA → GNFA → RE a*c(ca*c U b)*(ca*b U a) U a*b q 0 q a Only two states remain: RE = a*c(ca*c U b)*(ca*b U a) U a*b

  39. Recap: Here “  ” means “can be converted to” RE  DFA  NFA Any of the three recognize exactly the regular languages (initially defined using DFA)

  40. These conversions are used every time you enter an RE, for example for pattern matching using grep ● The RE is converted to an NFA ● Then the NFA is converted to a DFA ● The DFA representation is used to pattern-match Optimizations have been devised, but this is still the general approach.

  41. What language is NOT regular? Is { 0 n 1 n : n  0 } = {ε, 01, 0011, 000111, … } regular?

  42. Pumping lemma: L regular language   p  0  w  L, |w|  p  x,y,z : w= xyz, |y|> 0, |xy|  p  i  0 : xy i z  L Recall y 0 = e , y 1 = y, y 2 = yy, y 3 = yyy, ...

  43. Pumping lemma: L regular language   p  0  w  L, |w|  p  x,y,z : w= xyz, |y|> 0, |xy|  p  i  0 : xy i z  L We will not see the proof. But here's the idea: p := |Q| for DFA recognizing L If w  L, |w|  p, then during computation ∈ 2 states must be the same q Q y = portion of w that brings back to q can repeat y and still accept string

  44. Pumping lemma: L regular language   p  0 A  w  L, |w|  p  x,y,z : w= xyz, |y|> 0, |xy|  p  i  0 : xy i z  L Useful to prove L NOT regular. Use contrapositive: L regular language  A same as (not A)  L not regular

  45. Pumping lemma (contrapositive)  p  0 not A  L not regular  w  L, |w|  p  x,y,z : w = xyz, |y| > 0, |xy|  p  i  0 : xy i z  L To prove L not regular it is enough to prove not A Not A is the stuff in the box.

  46. Proving something like  bla  bla  bla  bla bla means winning a game Theory is all about winning games!

  47. Example NAME THE BIGGEST NUMBER GAME ● Two players: You, Adversary. ● Rules: First Adversary says a number. Then You say a number. You win if your number is bigger. Can you win this game?

  48. Example NAME THE BIGGEST NUMBER GAME ● Two players: You, Adversary. ● Rules: First Adversary says a number. Then You say a number. You win if your number is bigger. You have winning strategy: if adversary says x, you say x+1

  49. Example NAME THE BIGGEST NUMBER GAME ● Two players: You, Adversary.  ,  ● Rules: First Adversary says a number.  x  y : y > x Then You say a number. You win if your number is bigger. You have winning strategy: Claim is true if adversary says x, you say x+1

  50. Another example: Theorem:  NFA N  DFA M : L(M) = L(N) We already saw a winning strategy for this game What is it?

  51. Another example: Theorem:  NFA N  DFA M : L(M) = L(N) We already saw a winning strategy for this game The power set construction.

Recommend


More recommend