1 / 29

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453. FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. Some Homework 1 Statistics: Each question was graded out of 20 points. Max: 100 Mean: 78 Median: 79.02 Std Dev: 15.65. NOTE : Your 1st Project Report is Due Tuesday! Turn in your Homework! (New Homework on the Web).

malana
Download Presentation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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. 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

  2. Some Homework 1 Statistics: Each question was graded out of 20 points. Max: 100 Mean: 78 Median: 79.02 Std Dev: 15.65

  3. NOTE : Your 1st Project Report is Due Tuesday! Turn in your Homework! (New Homework on the Web)

  4. PDAs ARE EQUIVALENT TO CFGs THURSDAY Jan 31

  5. string pop push ε,ε → $ 0,ε→ 0 1,0→ε ε,$ → ε 1,0→ε

  6. CONTEXT-FREE GRAMMARS Production rules terminals variable A → 0A1 A → ε  (VΣ)*  000A111 A  0A1  00A11  000111 (yields) A *000111 (derives)

  7. A Language L is generated by a CFG  L is recognized by a PDA

  8. Suppose L is generated by a CFG G = (V, Σ, R, S) Construct P = (Q, Σ, Γ, , q, F) that recognizes L A Language L is generated by a CFG  L is recognized by a PDA

  9. Suppose L is generated by a CFG G = (V, Σ, R, S) Construct P = (Q, Σ, Γ, , q, F) that recognizes L ε,ε → S$ For each rule 'A → w’R: ε,A → wR For each terminal aΣ: a,a → ε ε,$ → ε

  10. S → aTb T → Ta | ε ε,ε → $ ε,ε → T ε,S → b ε,ε → T ε,ε → S ε,T → a ε,$ → ε ε,ε → a ε,T → ε a,a → ε b,b → ε

  11. S → aTb S*ab (derives) T → Ta | ε ε,ε → $ ε,ε → T ε,S → b ε,ε → T ε,ε → S ε,T → a ε,$ → ε ε,ε → a ε,T → ε a,a → ε b,b → ε

  12. Suppose L is generated by a CFG G = (V, Σ, R, S) Describe P = (Q, Σ, Γ, , q, F) that recognizes L : (1) Push $ and then S on the stack (2) Repeat the following steps forever: (a) Pop the stack, call the result X. (b) If X is a variable A, guess a rule that matches A and push result into the stack (c) If X is a terminal, read next symbol from input and compare it to terminal. If they’re different, reject. (d) If X is $: then accept iff no more input

  13. A Language L is generated by a CFG  L is recognized by a PDA

  14. A Language L is generated by a CFG  L is recognized by a PDA Given PDA P = (Q, Σ, Γ, , q, F) Construct a CFG G = (V, Σ, R, S) such that L(G) = L(P) First, simplify P to have the following form: (1) It has a unique accept state, qacc (2) It empties the stack before accepting (3) Each transition either pushes a symbol or pops a symbol, but not both at the same time

  15. SIMPLIFY ε,ε → $ 0,ε→ 0 q1 q0 1,0→ε ε,$ → ε q2 q3 1,0→ε

  16. SIMPLIFY ε,ε → E ε,ε → $ 0,ε→ 0 Q q1 q0 1,0→ε ε,ε → ε ε,$ → ε q2 q3 1,0→ε ε,ε → ε q4 ε,E → ε q5 ε,σ → ε

  17. SIMPLIFY ε,ε → E ε,ε → $ 0,ε→ 0 Q q1 q0 ε,ε → D 1,0→ε q’0 ε,$ → ε q2 q3 1,0→ε ε,D→ ε ε,ε → D q’3 ε,D → ε q4 ε,E → ε q5 ε,σ → ε

  18. Idea For Our Grammar G: For every pair of states p and q in PDA P, G will have a variable Apq whose production rules will generate all strings x that can take: P from p with an empty stack to q with an empty stack V = {Apq | p,qQ } S = Aq0qacc

  19. ε,ε → E ε,ε → $ 0,ε→ 0 Q q1 q0 ε,ε → D 1,0→ε q’0 ε,$ → ε q2 q3 1,0→ε ε,ε → D q’3  Aq0q1 generates? ε,D → ε Aq1q2 generates? q4 {0n1n | n > 0} ε,E → ε q5 Aq1q3 generates?  ε,σ → ε WANT: Apq generates all strings that take p with an empty stack to q with empty stack

  20. WANT: Apq generates all strings that take p with an empty stack to q with empty stack Let x be such a string • P’s first move on x must be a push • P’s last move on x must be a pop Two possibilities: 1. The symbol popped at the end is exactly the one pushed at the beginning 2. The symbol popped at the end is not the one pushed at the beginning

  21. x = ayb takes p with empty stack to q with empty stack 1. The symbol t popped at the end is exactly the one pushed at the beginning stack height r s a b input string pop t push t p q ─ ─ ─ ─ x ─ ─ ─ ─ δ(p, a, ε) → (r, t) Apq→ aArsb δ(s, b, t) → (q, ε)

  22. 2. The symbol popped at the end is not the one pushed at the beginning stack height input string p r q Apq→ AprArq

  23. Formally: V = {Apq | p, qQ } S = Aq0qacc For every p, q, r, s  Q, t  Γand a, b  Σε If (r, t)  (p, a, ε) and (q, ε)  (s, b, t) Then add the rule Apq→ aArsb For every p, q, r  Q, add the rule Apq→ AprArq For every p  Q, add the rule App→ ε

  24. For all x, Apqgenerates x  xcan bring P from p with an empty stack to q with an empty stack  Proof (by induction on the number of steps in the derivation of x from Apq): Inductive Step: Base Case: The derivation has 1 step: Appε Assume true for derivations of length ≤ k and prove true for derivations of length k+1: Apq* x in k+1 steps Apq → AprArq Apq → aArsb (r,t)  (p,a,ε) and (q, ε)  (s,b,t) state push state alphabet pop

  25. For all x, Apq generates x  x can bring P from p with an empty stack to q with an empty stack  Proof (by induction on the number of steps in the computation of P from p to q with empty stacks, on input x): Base Case: The computation has 0 steps So it starts and end in the same state: We must show that App* x But it must be that x = ε, so we are done

  26. Inductive Step: Assume true for computations of length ≤ k, we’ll prove true for computations of length k+1 Suppose that P has a computation where x brings p to q with empty stacks in k+1 steps Two cases: 1. The stack is empty only at the beginning and the end of this computation Write x as ayb. Ars* y by I.H., use Apq →aArsb 2. The stack is empty somewhere in the middle of the computation Write x as yz. Apr* y, Arq* z by I.H., Apq → AprArq

  27. A Language L is generated by a CFG  L is recognized by a PDA

  28. Corollary: Every regular language is context-free

  29. WWW.FLAC.WS

More Related