1 / 48

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 7: Kleene ’s Theorem

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 7: Kleene ’s Theorem. Chapter 7: Kleene’s Theorem Regular expressions, Finite Automata, transition graphs are all the same!!. Chapter 7: Kleene ’s Theorem. Method of proof

falala
Download Presentation

CSI 3104 /Winter 2006 : Introduction to Formal Languages Chapter 7: Kleene ’s Theorem

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. CSI 3104 /Winter 2006: Introduction to Formal Languages Chapter 7: Kleene’s Theorem Chapter 7: Kleene’s Theorem Regular expressions, Finite Automata, transition graphs are all the same!! Zaguia/Stojmenovic

  2. Chapter 7: Kleene’s Theorem • Method of proof Let A,B,C be sets such that AB, BC, CA. Then A=B=C. Remark:Regular expressions, finite automata, and transition graphs each define a set of languages. Zaguia/Stojmenovic

  3. Chapter 7: Kleene’s Theorem Kleene’s Theorem Any language that can be defined by a regular expression, or finite automaton, or transition graph can be defined by all three methods. Zaguia/Stojmenovic

  4. Chapter 7: Kleene’s Theorem Proof of Kleen’s theorem: It is enough to prove each of the lemmas below. Lemma 1: Every language that can be defined by a finite automaton can also be defined by a transition graph. Lemma 2: Every language that can be defined by a transition graph can also be defined by a regular expression. Lemma 3: Every language that can be defined by a regular expression can also be defined by a finite automaton. FA  TG  RE  FA Zaguia/Stojmenovic

  5. Chapter 7: Kleene’s Theorem Lemma 1:Every language that can be defined by a finite automaton can also be defined by a transition graph. Proof:By definition, every finite automaton is a transition graph. Lemma 2:Every language that can be defined by a transition graph can also be defined by a regular expression. Proof:Byconstructive algorithm, which works • for every transition graph • in a finite number of steps Zaguia/Stojmenovic

  6. b 2 1– ab … aa 4 5– 3– … b 2 1 L … ab L 4 3 – aa 5 L Chapter 7: Kleene’s Theorem 1st step: transform to a transition graph with a single start state. Zaguia/Stojmenovic

  7. b b 9+ 9 … L … aa aa + b aba 12+ L aba 12 b L L … L L – + L L Chapter 7: Kleene’s Theorem 2nd step:and a single final state Result is an equivalent transition graph, of the form: Zaguia/Stojmenovic

  8. r1 r1 r1+ r2+ r3 … … … … x … … 3 7 x r3 r2 r2 … … r1 + r2 3 7 Chapter 7: Kleene’s Theorem 3a. Combine edges that have the same starting and ending state. Zaguia/Stojmenovic

  9. r1 r2 … – + r35 r1+r2+…+r35 – + Chapter 7: Kleene’s Theorem 3a. Combine edges Zaguia/Stojmenovic

  10. … r1 r3 3 1 2 … … r1r3 1 3 r2 … … r1 r3 3 1 2 … … r1r2*r3 1 3 Chapter 7: Kleene’s Theorem 3b. Eliminate states one by one: bypass and state elimination operation Zaguia/Stojmenovic

  11. 3 r2 r3 … r4 … r1 4 2 1 r5 … 5 … 3 r1r2*r3 … … r1r2*r4 4 1 … r1r2*r5 5 Chapter 7: Kleene’s Theorem Bypass state 2 One incoming edge to state 2 Zaguia/Stojmenovic

  12. 4 1 a ab ba L L + 2 – bbb L L b 5 3 Chapter 7: Kleene’s Theorem bypass state 2, paths through state 2: 1 24, 125, 324, 325 Zaguia/Stojmenovic

  13. 4 1 a ab ba L L + 2 – bbb L L b 5 3 aba*ba 4 1 L L aba*b + – bbba*b L L 5 3 bbba*ba Chapter 7: Kleene’s Theorem Zaguia/Stojmenovic

  14. r3 11 7 r4 r1 … … r5 4 2 r6 r2 5 9 r1r3*r4 11 7 r1r3*r5 … r1r3*r6 … 4 r2r3*r4 r2r3*r5 9 5 r2r3*r6 Chapter 7: Kleene’s Theorem Even with many paths through state 2, always an equivalent GTG. Zaguia/Stojmenovic

  15. r2 r3 … … r4 1 2 3 r1 r1 r2*r3 … … r4 r2*r3 1 3 Chapter 7: Kleene’s Theorem Special cases 3  2 1, 121 Zaguia/Stojmenovic

  16. r8 r4 r2 r5 r1 1 2 r7 3 r3 r6 r9 r8+r2 r4*r5 1 r7+r6 r4*r5 3 r1+r2 r4*r3 r9+r6 r4*r3 Chapter 7: Kleene’s Theorem 3 21, 323, 1 21, 123 Zaguia/Stojmenovic

  17. + a,b aa aa,bb – bb + + – (aa+bb)(a+b)*(aa+bb) Chapter 7: Kleene’s Theorem Example 1 Zaguia/Stojmenovic

  18. aa+bb aa+bb – L ab+ba 1 2 ab+ba + L aa+bb L L + 1 – aa,bb L aa,bb L + 1 – ab,ba (ab+ba)(aa+bb)*(ab+ba) + (aa+bb)+(ab+ba)(aa+bb)*(ab+ba) ab,ba + – [(aa+bb)+(ab+ba)(aa+bb)*(ab+ba)]* Chapter 7: Kleene’s Theorem EXAMPLE2: EVEN-EVEN Zaguia/Stojmenovic

  19. Chapter 7: Kleene’s Theorem Transition Graph  Regular Expression • Algorithm (and proof) • Add (if necessary) a unique start state without incoming edges and a unique final state without outgoing edges. For each state that is not a start state or a final state, repeat steps 2 and 3. • Do a bypass and state elimination operation. • Combine edges that have the same starting and ending state. • Combine the edges between the start state and the final state. The label on the only remaining edge is the regular expression result. If there is none, the regular expression is . Zaguia/Stojmenovic

  20. Chapter 7: Kleene’s Theorem Lemma 3:Every language that can be defined by a regular expression can also be defined by a finite automaton. Proof:By constructive algorithm starting from the recursive definition of regular expressions, we build FA. Zaguia/Stojmenovic

  21. Chapter 7: Kleene’s Theorem • Remember: Given an alphabet , the set of regular expressions is defined by the following rules. • For every letter in , the letter written in bold is a regular expression. Λ is a regular expression. • If r1 and r2 are regular expressions, so is r1+r2. • If r1 and r2 are regular expressions, so is r1 r2. • If r1 is a regular expression, so is r1*. • Nothing else is a regular expression. Zaguia/Stojmenovic

  22. Chapter 7: Kleene’s Theorem Lemma 3:Every language that can be defined by a regular expression can also be defined by a finite automaton. Proof:By constructive algorithm starting from the recursive definition of regular expressions • There is an FA that accepts only the empty word (Λ) and an FA that accepts only a single letter. • If there is an FA that accepts the language defined by r1 and an FA that accepts the language defined by r2, then there is an FA that accepts the language r1+r2. • If there is an FA that accepts the language defined by r1 and an FA that accepts the language defined by r2, then there is an FA that accepts the language defined by their concatenation r1r2. • If there is an FA that accepts the language defined by r then there is an FA that accepts the language defined by r*. Thus for every regular expression, we can construct a FA. Zaguia/Stojmenovic

  23. Chapter 7: Kleene’s Theorem Build a finite automaton that accepts the language: (a+b)*(aa+bb)(a+b)* Rule: • The letter a 1 • The letter b 1 • The word aa (using 1) 3 • The word bb (using 2) 3 • The expression aa+bb (using 3 and 4) 2 • The expression a+b (using 1 and 2) 2 • The expression (a+b)* (using 6) 4 • The expression (a+b)*(aa+bb) (using 7 and 5) 3 • The expression (a+b)*(aa+bb)(a+b)* (using 8 and 7) 3 Zaguia/Stojmenovic

  24. all S all S + all S x all S except x – + all S Chapter 7: Kleene’s Theorem Rule 1 The language Λ Only the letter x Zaguia/Stojmenovic

  25. a b –x1 x2x1 x2 x3 x1 +x3 x3x3 a,b b a a +x3 –x1 x2 b b y2 +y1 b a b +y1 y3 y2 y2 y4 y1 y3 y1 y4 y4 y2 y3 a a a a b y3 y4 b Chapter 7: Kleene’s Theorem Rule 2: r1+r2, Example 1 All word containing aa EVEN-EVEN Zaguia/Stojmenovic

  26. Combine two tables into one New state name a b Zaguia/Stojmenovic

  27. a 11+ 8+ a a a b b a 6 9 1+ 3 b b a b b b b b a b a b 12+ 10 5 2 a a b a 4+ 7+ a Chapter 7: Kleene’s Theorem Result: r1+r2 Zaguia/Stojmenovic

  28. Chapter 7: Kleene’s Theorem Algorithm 1: r1+r2 Input: FA 1: alphabet:  states: x1, x2, x3,… start state: x1 FA 2: alphabet:  states: y1, y2, y3,… start state: y1 plus final states and transitions The new FA: alphabet: states: z1, z2, z3,… start state: x1 or y1 transitions: if zi= xj or yk and xj xnew and yk ynew (for input p) then znew= (xnew or ynew) for input p. If xnew or ynew is a final state, then znew is a final state. Zaguia/Stojmenovic

  29. a b –x1 x2x1 +x2 x2 x1 b a a x1– x2+ b a b a b –y1 y1 y2 +y2 y1 y2 b y1– y2+ a Chapter 7: Kleene’s Theorem Example 2. (words ending in a) (words ending in b) Zaguia/Stojmenovic

  30. a b –x1 x2x1 +x2 x2 x1 b a a x1– x2+ b – x1 or y1 a b a b a b –y1 y1 y2 +y2 y1 y2 a b b b y1– y2+ + + a a x1 or y2 x2 or y1 Chapter 7: Kleene’s Theorem algorithm 1 (words ending in a) (words ending in b) Zaguia/Stojmenovic

  31. x1 or y2 + x1 or y1 – x2 or y2 + x2 or y1 + a x1 or y2 + x1 or y1 – a b b a b a x2 or y1 + x2 or y2 + b Chapter 7: Kleene’s Theorem • Algorithm 2: Put all pairs (xi or yj) in the transition table Zaguia/Stojmenovic

  32. b a,b a,b + – a a,b b b a – + a Chapter 7: Kleene’s Theorem Rule 3: r1r2, Example 1 second letter is b odd number of a’s Zaguia/Stojmenovic

  33. b a,b a,b + – a a,b b b a – + a Chapter 7: Kleene’s Theorem ab|abbaa abab|baa Exercize for home study Zaguia/Stojmenovic

  34. b a,b a a x1– x2 x3+ b a b b a b a z2 z3 z4+ z1– b a a b b y1– y2+ a Chapter 7: Kleene’s Theorem Example 2 r1: all with aa r2: words ending in b r1r2 Zaguia/Stojmenovic

  35. b a z2 z3 z1– b Chapter 7: Kleene’s Theorem a b b a z4+ a We start by creating the states z1=x1and z2=x2 (z2, a)= x3 “we continue on AF1” OR y1 ”we move to AF2, since x3 is a final state in AF1” (z2, a) = x3 or y1= z3 -running FA1 -beginning FA2 (y1 added to x3) -running FA2 (z3, a) = x3 or y1= z3 (z3, b) = x3 or y1 or y2 = z4 + (z4, a)= x3 or y1=z3 (z4, b)= x3 or y1 or y2 = z4 + Zaguia/Stojmenovic

  36. Chapter 7: Kleene’s Theorem Rule 3: Concatenation: Summary of the Algorithm • Add a state z for every state of the first automaton that is possible to go through before arriving at a final state. • Rename each final state x of FA1 as z = (x or y1), where y1 is the start state of the second automaton. • Starting from the states added at step 2, add states: x (state such that execution continues on 1st automaton) z= OR y (state such that execution continues on 2nd automaton} 4. Label every state that contains a final state from the second automaton as a final state. Zaguia/Stojmenovic

  37. State transition rule • State z= xi or yj1 or yj2 … • xi on a to xi’ • yj1 on a to yj1’ • yj2 to a to yj2’ • Then z on a to z’= xi’ or yj1’ or yj2’ … • Add y1 to z if xi’ + and not listed already • Sort yj’s and eliminate duplications in z • z is + if at least one of its own yj’s is + on FA2 Zaguia/Stojmenovic

  38. b a,b a a x1+ x2+ x3 b a,b y1– y2+ a,b Chapter 7: Kleene’s Theorem Example 3 r1: no double a r2: odd number of letters Zaguia/Stojmenovic

  39. x1 or y1 x2 or y2 or y1 a z2 + z1 – a b b b a,b z3+ z4 + x1 or y2 or y1 x3 or y1 or y2 Chapter 7: Kleene’s Theorem r1r2: all words except L Zaguia/Stojmenovic

  40. a,b b x1– x3+ a a,b x2 a b b y1– y2+ a Chapter 7: Kleene’s Theorem Example 4 r1: words starting with b r2: words ending in b Zaguia/Stojmenovic

  41. a z1– z3 b a a b a,b b z2 z4+ b a b a b z4+ z6+ z1– z2 a a a b b a b z3 z5 z7+ b a Chapter 7: Kleene’s Theorem r1r2 r2r1 Zaguia/Stojmenovic

  42. a b a x3+ x2+ x1+ a,b b x4 a,b Chapter 7: Kleene’s Theorem r: a* + aa*b r*: words without double b, and that do not start with b. Rule 4: r*, Example 1 Zaguia/Stojmenovic

  43. a z2+ a b a a z1+ z3+ z5+ a,b b b b z4 Chapter 7: Kleene’s Theorem z1=x1 ± (z1, a) = x1 or x2= z2 + (z1,b) = x4= z4 (z2,a)= x1 or x2 =z2 (z2, b)= x1 or x3 or x4= z3 + (z3, a)=z4 (z3,b) = z4 (z3,a)= x1 or x2 or x4= z5 + (z3, b)= x4 = z4 (z5,a)= x1 or x2 or x4= z5 (z5, b)= x1 or x3 or x4= z3 r* Zaguia/Stojmenovic

  44. Chapter 7: Kleene’s Theorem Rule 4: Kleene Star: Algorithm: case + Given: an FA whose states are {-x1, x2, x3, …} • Rename every +xi state in FA as xi or x1 • Make the transition table where new states may be created • some intended xi or x1 states may be ‘expanded’ by the time they are reached, or could be split into few states, following transitions; e.g. x3 or x4 became x3 or x4 or x1 =z3 when reached from z2 • Add a + state. • + states are those that contain at least one + from the original FA. Zaguia/Stojmenovic

  45. a b a b a x1 or x2 + x1– a b x1– x2+ b b x1 b a b + a x1 or x2 + a Chapter 7: Kleene’s Theorem Example 2 Words ending in a z1=x1 _ (z1, a) = x1 or x2= z2 + (z1,b) = z1 (z2,a)= x1 or x2 =z2 (z2, b)= x1=z1  Problem with Λ: add state+ Zaguia/Stojmenovic

  46. a z1+ z2 a a a b b b x1– x2+ a,b b z3+ Chapter 7: Kleene’s Theorem Example 3 Words with an odd number of b’s. Λ and words with at least one b. Zaguia/Stojmenovic

  47. b a,b a x2 a b a y1– y2+ b x1+ x3 b b a a x4+ b a x2 a,b a a a b b b x1 y1 y2+ x3 – b b a a a b x4+ Chapter 7: Kleene’s Theorem Rule 2: r1+r2 Zaguia/Stojmenovic

  48. a b a w1– w2+ b a a,b b b a x2 x3+ x1 – a b b a a,b a b a b w2 w1– x1 x2 x3+ b a Chapter 7: Kleene’s Theorem Rule 3: r1r2 Zaguia/Stojmenovic

More Related