1 / 20

CSC3130 Formal Languages and Automata Theory

CSC3130 Formal Languages and Automata Theory. Tutorial 8: Assignment 3, Pumping Lemma and Closure Tutor: Jeff Choi 9 th Week, Fall 2003. Question 1. Construction of CFG Hints: Think about the inductive definition, see Tutorial 6 for examples

milt
Download Presentation

CSC3130 Formal Languages and Automata Theory

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. CSC3130 Formal Languages and Automata Theory Tutorial 8: Assignment 3, Pumping Lemma and Closure Tutor: Jeff Choi 9th Week, Fall 2003

  2. Question 1 • Construction of CFG • Hints: • Think about the inductive definition, see Tutorial 6 for examples • Recognize the substrings that each variable represent • Be careful of “extreme cases”e.g. Does ε belongs to the language? What if an and n = 0? • Be careful of the “special case” pitfall e.g. the set of all strings over {0, 1} with equal number of 0’s and 1’s, 0n1n is only a special case

  3. Question 2 • Recognize the substrings that each variable represent • Describe the language using either set notation or English.

  4. Question 3 • Show a string that has multiple leftmost derivations from the start symbol • Equivalently: multiple rightmost derivations or multiple parse trees • Making the CFG unambiguous, see Tutorial 6 for example • Explain briefly why you have a unique parse tree for any strings accepted by your unambiguous CFG

  5. Question 4 • Show that every RL is a CFL • Hint: • Every RL can be described by a RE • Every CFL can be described by a CFG • Show that we can construct a CFG for every RE

  6. Question 5 • See Tutorial 7 for example on conversion into CNF and GNF • Make sure there is no -production nor unit-production

  7. Clarifying GNF • Example: S  AB | BC A  AB | a B  AA | CB | b C  a | b • Step1: variables order, A1 = S, A2 = A, A3 = B, A4 = C A1 A2A3 | A3A4 A2  A2A3 | a A3  A2A2 | A4A3 | b A4 a | b

  8. Clarifying GNF • Step 2: Transform the rules to the form Ai Aj where i < j for i = 1 to 4 do for each rule Ai Aj where i > j, do substitution for each rule Ai Ai, remove left recursion end for • The rules of A1 are fine A1 A2A3 | A3A4 A2  A2A3 | a A3  A2A2 | A4A3 | b A4 a | b

  9. Clarifying GNF • For the rules of A2, we remove left recursion A1 A2A3 | A3A4 A2  aB1 | a A3  A2A2 | A4A3 | b A4 a | b B1 A3B1| A3 A1 A2A3 | A3A4A2  A2A3 | aA3  A2A2 | A4A3 | bA4 a | b Replace: X  1 | 2 | … | nX  X1 | X2 | … | Xn By: X  1 | 2 | … | n X  1Z | 2Z | … | nZ Z  1 |  2 | … |  n Z  1Z |  2Z | … |  nZ

  10. Clarifying GNF • For the rules of A3, we do substitution A1 A2A3 | A3A4 A2  aB1 | a A3  aB1A2 | aA2 | A4A3 | b A4 a | b B1 A3B1| A3 • The rules of A4 are fine A1 A2A3 | A3A4 A2  aB1 | a A3  A2A2 | A4A3 | b A4 a | b B1  A3B1| A3

  11. Clarifying GNF • Step 3: substitute backward, A4, A3, A2, A1, B1 A1 aB1A3 | aA3 | aB1A2A4 | aA2A4 | aA3A4 | bA3A4 | bA4 A2  aB1 | a A3  aB1A2 | aA2 | aA3 | bA3 | b A4 a | b B1 aB1A2B1 | aA2B1 | aA3B1 | bA3B1 | bB1| aB1A2 | aA2 | aA3 | bA3 | b A1 A2A3 | A3A4 A2  aB1 | a A3  aB1A2 | aA2 | A4A3 | b A4 a | b B1 A3B1| A3

  12. Simpler Variable Ordering • Example: S  AB | BC A  AB | a B  AA | CB | b C  a | b • Simpler variables order, A1 = S, A2 = B, A3 = A, A4 = C A1 A3A2 | A2 A4 A2  A3A3 | A4A2 | b A3  A3A2 | a A4 a | b

  13. Question 6 and 7 • See Tutorial 6 for examples on simplification of CFG • Removal of -production, determines the nullable symbols • Removal of unit-productions, determines the unit pairs • For Question 7, the given CFG provides hints on the correct order of the steps in CFG simplification, do it carefully.

  14. Common Errors in Assignment 2 • Pumping Lemma for Regular Set • Closure Properties

  15. How to apply Pumping Lemma? • To show a language L is not regular: • Assume L is regular • Pick n the constant of Pumping Lemma • Pick a string w  L (which may depends on n) where |w| ≥ n • Divide w into xyz such that y   and |xy| ≤ n • Pick constant k ≥ 0and shows that xykz  L • By Pumping Lemma, xykz  L, contradiction

  16. Example • L = {anbn | n > 0} • Assume L is regular • Pick n the constant of Pumping Lemma • Pick w be anbn and |w| = 2n ≥ n • Divide w into x = ap, y = an-p, z = bnwhere p < n, y   and |xy| = p + n  p ≤ n • Pick k = 0and the string xy0z = xz = apbn  L • By Pumping Lemma, xykz  L, contradiction

  17. Another Method • We want to prove that L = {anbn | n = 0,1,2,…} is non-regular. Prove by contradiction: • Assume that there is a DFA M that recognizes L. Let n be the total number of states in M. • Consider the acceptance of the input arbr where r  n: b a a a b b qπ(0) qπ(1) qπ(r) qπ(r+1) qπ(2r) …... …...

  18. Another Method • Since r  n and M has only n states, there must be at least one state visited twice in the first r transitions. Let this state be visited at the ith and the jth steps, where j > i and (j – i) ≥ 1. • By skipping the loop, ar-(j-i)br should also be accepted by M, but this is contradictory since ar-(j-i)br  L qπ(i)= qπ(j) qπ(2r) F The path in M when reading arbr qπ(0)

  19. What is Closure Properties? • A set of languagesG is said to be closed under an operation opif the application of opto languages L G will result in another language L’  G

  20. Example • Is G = the set of all languages over Σ={0, 1} that have no strings with substring “010”, closed under complementation? • To arrive at a contradiction: • Pick a language L G, e.g. pick a set of string {101}, and NOT a single string “101” • complementation of L is (Σ*  L) and NOT flipping between 0 and 1, e.g. the complement of {101} is { |   Σ* and   101} and NOT {010} • Show that (Σ*  L)  G

More Related