direct automaton construction for parikh s theorem
play

Direct automaton construction for Parikhs Theorem Abhishek Mukati, - PowerPoint PPT Presentation

Direct automaton construction for Parikhs Theorem Abhishek Mukati, Rishi Tulsyan, Shubham Waghmare November 23, 2018 Abhshek, Rishi, Shubham Automata Construction November 23, 2018 1 / 61 Parikhs Theorem Theorem Every CFL has the same


  1. Direct automaton construction for Parikh’s Theorem Abhishek Mukati, Rishi Tulsyan, Shubham Waghmare November 23, 2018 Abhshek, Rishi, Shubham Automata Construction November 23, 2018 1 / 61

  2. Parikh’s Theorem Theorem Every CFL has the same Parikh image as some regular language. Parikh’s proof of theorem Given a CFG G, the proof produces (implicitly) an automaton or regular expression whose language has the same Parikh image as G. Constructed automata is of size O(n n ), where n - number of variables in the CNF of G. Enhanced automaton construction Given a CFG G, construct an automaton explicitly. Instead of O(n n ), only O(4 n ) states. Abhshek, Rishi, Shubham Automata Construction November 23, 2018 2 / 61

  3. Terms and Notations Context Free Grammar G=( V , T , P , S ) V is set of variables, denoted as A 1 , A 2 , A 3 ,...... T is a set of terminal symbols, denoted as a, b, c..... S is the start variable. → α where α ∈ (V U T) ∗ P is a set of productions of the form A i − If w is a word over some T, we denote by Π T (w) the Parikh image of w over alphabet T. Π T (w)maps a character in T to its number of occurrences in w. Abhshek, Rishi, Shubham Automata Construction November 23, 2018 3 / 61

  4. Terms and Notations Cont. Context Free Grammar G=( V , T , P , S ) The Parikh image of a language L over T is { Π T ( w ) | w ∈ L } . It is denoted by Π T (L). Examples :- Π { a , b , c } (bccba) = (1, 2, 2) where (1, 2, 2) stands for { ( a , 1) , ( b , 2) , ( c , 2) } Π { a , b , c } (cabaaabb) = (4, 3, 1) α / V means α projected on V α / T means α projected on T A pair ( α, β ) is a step , denoted by α ⇒ β , if there exists a production → γ and α 1 , α 2 ∈ ( V ∪ T) ∗ such that: α = α 1 A α 2 and β = α 1 γα 2 . A − Transition t( α ⇒ β ) = (Π V ( α ), γ / T , Π V ( β )) where, α , β ∈ ( V ∪ T ) ∗ Abhshek, Rishi, Shubham Automata Construction November 23, 2018 4 / 61

  5. k-Parikh automaton of G The k-Parikh automaton of G is the NFA M k G = (Q, T ∗ , δ , q 0 , q f ) n= | V | Q= { (x 1 .... x n ) ∈ N n | � n i =1 x i ≤ k } δ = { t( α ⇒ β ) | α ⇒ β is a step and Π V ( α ), Π V ( β ) ∈ Q } q f = Π V ( ǫ ) = (0, ..... , 0) q 0 = Π V (S); Abhshek, Rishi, Shubham Automata Construction November 23, 2018 5 / 61

  6. 3-Parikh Automaton Example A 1 − → A 1 A 2 | a A 2 → bA 2 aA 2 | cA 1 Transition example: (0, 2) c − → (1, 1) A 2 A 2 → cA 1 A 2 Abhshek, Rishi, Shubham Automata Construction November 23, 2018 6 / 61

  7. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 7 / 61

  8. Theorem If G is a context-free grammar with n variables and degree m, then L(G) and L(M nm +1 ) have same Parikh image. G the degree of G denoted by m := -1 + max {| γ / V | ( A → γ ) ∈ P } ;i.e., m+1 is the maximal number of variables on the right hand sides. For the above grammar G, n=2 and m=1, which means L(G) = Π L(M 3 G ). Abhshek, Rishi, Shubham Automata Construction November 23, 2018 8 / 61

  9. Proof of L ( M k G ) ⊆ Π L ( G ) Claim σ → q be a run of M k G on the word σ ∈ T ∗ , then there exists If k ≥ 1, let q 0 − a step sequence S ⇒ ∗ α satisfying Π V ( α ) = q Π T ( α ) = Π T ( σ ) Proof of claim (by induction on length of path): If l = 0 then σ = ǫ , so α = S and Π V ( S ) = q 0 and Π T ( S ) = Π T ( ǫ ) → q ′ γ σ ′ If l > 0, let σ = σ ′ γ and q 0 − − → q , then according to I.H.: S ⇒ ∗ α ′ where Π V ( α ′ ) = q ′ and Π T ( α ′ ) = Π T ( σ ′ ) Since q ′ γ → q is a transition there exists a step α 1 A α 2 ⇒ α 1 γ ′ α 2 and − a production A → γ ′ where Π V ( α 1 A α 2 ) = q ′ , Π V ( α 1 γ ′ α 2 ) = q and γ ′ / T = γ Abhshek, Rishi, Shubham Automata Construction November 23, 2018 9 / 61

  10. Claim’s proof cont. Since Π V ( α ′ ) = q ′ = Π V ( α 1 A α 2 ), α ′ = α ′ 1 A α ′ 2 for some α ′ 1 , α ′ 2 2 so that S ⇒ ∗ α ′ ⇒ α and Let α = α ′ 1 γ ′ α ′ = Π V ( α ′ 1 γ ′ α ′ Π V ( α ) 2 ) = Π V ( α ′ 1 A α ′ 2 ) − Π V ( A ) + Π V ( γ ′ ) = Π V ( α ′ ) − Π V ( A ) + Π V ( γ ′ ) = Π V ( α 1 A α 2 ) − Π V ( A ) + Π V ( γ ′ ) = Π V ( α 1 γ ′ α 2 ) = q = Π T ( α ′ 1 γ ′ α ′ Π T ( α ) 2 ) = Π T ( α ′ 1 A α ′ 2 ) + Π T ( γ ′ ) = Π T ( α ′ ) + Π T ( γ ′ ) = Π T ( α ′ ) + Π T ( γ ) = Π T ( σ ′ ) + Π T ( γ ) = Π T ( σ ) Abhshek, Rishi, Shubham Automata Construction November 23, 2018 10 / 61

  11. Proof of L ( M k G ) ⊆ Π L ( G ) from the claim σ If σ ∈ L ( M k G ), then there is a run q 0 − → Π V ( ǫ ) From the claim, there exists a step sequence S ⇒ ∗ α satisfying Π V ( α ) = Π V ( ǫ ) = (0 , 0 , ..., 0) and Π T ( α ) = Π T ( σ ) So α ∈ T ∗ and hence α ∈ L ( G ) Since Π T ( α ) = Π T ( σ ), we have α = Π σ Abhshek, Rishi, Shubham Automata Construction November 23, 2018 11 / 61

  12. Notations and Definitions Yield of a parse tree t is denoted by Y ( t ) Set of yields of a set T of trees by Y ( T ) A child of t is a subtree of t whose root is a child of the root of t . A child is proper if its root is not a leaf. The dimension d ( t ) of a parse tree is defined as follows : If t has no proper children then d ( t ) = 0. Otherwise let t 1 , t 2 , ... t r be the proper children of t sorted s . t . d ( t 1 ) ≥ d ( t 2 ) ≥ ... ≥ d ( t r ). Then � d ( t 1 ) if r = 1 or d ( t 1 ) > d ( t 2 ) d ( t ) = d ( t 1 ) + 1 if d ( t 1 ) = d ( t 2 ) The set of parse trees with dimension k is denoted by T ( k ) Fact 2.1 : The height of a tree, h ( t ) > d ( t ). Abhshek, Rishi, Shubham Automata Construction November 23, 2018 12 / 61

  13. Proof idea of L ( G ) ⊆ Π L ( M nm +1 ) G Definition A derivation S ⇒ α 0 ⇒ ... ⇒ α l has index k if ∀ i ∈ { 0 , ..., l } , the word ( α i ) / V has length atmost k . The set of words derivable through derivations of index k is denoted by L k ( G ). Clearly L 1 ( G ) ⊆ L 2 ( G ) ⊆ L 3 ( G ) ⊆ ... and L ( G ) = � k ≥ 1 L k ( G ) We can prove L ( G ) ⊆ Π L ( M nm +1 ) by proving G L ( G ) ⊆ Π L nm +1 ( G ) (Collapse Lemma) -proved using � n i =0 Y ( T ( i ) ) Y ( T ) ⊆ Π Y ( T ( k ) ) ⊆ L km +1 ( G ) L k ( G ) ⊆ Π L ( M k G ) Abhshek, Rishi, Shubham Automata Construction November 23, 2018 13 / 61

  14. Lemma 2.1 Lemma 2.1 Y ( T ) ⊆ Π ∪ n i =0 Y ( T ( i ) ) Π (Yields of all the parse trees) ⊆ Π ( Union of Yields of all the parse trees of dimension i, where (i=0 to n)) Proof Idea For every parse tree t ∈ T , we can find a parse tree t’ ∈ T ( i ) , such that: Π ( Y ( t )) = Π ( Y ( t’ )) d ( t ′ ) = i ≤ n . (n = | V | ) Abhshek, Rishi, Shubham Automata Construction November 23, 2018 14 / 61

  15. Lemma 2.1: Proof - Preliminaries In this proof, we write t = t 1 t 2 to denote that t 1 is a parse tree except that exactly one leaf is labelled by a variable, say A 2 , instead of a terminal. t 2 is a parse tree with root A 2 . t is obtained from t 1 and t 2 by replacing the leaf A 2 of t 1 by the tree t 2 . Figure: Tree t. Figure: Tree t1 and t2. Abhshek, Rishi, Shubham Automata Construction November 23, 2018 15 / 61

  16. Lemma 2.1: Proof - Preliminaries Ω − equivalence Two trees t, t’ are Ω -equivalent if: They have same number of nodes. The sets of variables in t and t ′ coincide. Y ( t ) = Π Y ( t’ ) Compact tree A tree t is compact if d ( t ) ≤ K ( t ). where K ( t ) denotes the number of variables that appear in t . K ( t ) ≤ n . Why? Proof Idea For every parse tree t ∈ T , we can find a parse tree t’ ∈ T ( i ) , such that: Π ( Y ( t )) = Π ( Y ( t’ )) d ( t ′ ) = i ≤ n . (n = | V | ) Abhshek, Rishi, Shubham Automata Construction November 23, 2018 16 / 61

  17. Compactify(t) Compactify(t) transforms a tree t into an Ω − equivalent compact tree. Steps : 1 If t is compact then return t and terminate. 2 If t is not compact then: 2.1 Let t 1 , ..... t r be the proper children of t , r ≥ 1. 2.2 For every 1 ≤ i ≤ r : t i := Compactify( t i ). (i.e., replace in t the subtree t i , by the result of compactifying t i . 2.3 Let x be the smallest index 1 ≤ x ≤ r such that K ( t x ) = max i K ( t i ). 2.4 Choose an index y � = x such that d ( t y ) = max i d ( t i ). 2.5 Choose subtrees t a x , t b x of t x and subtrees t a y , t b y , t c y of t y such that: i t x = t a x . t b x and t y = t a y . ( t b y . t c y ) ; and ii the roots of t b x , t b y and t c y are labelled by the same variable. 2.6 Remove t b y from t y and insert it into t x . t x = t a x .( t b y . t b x ) ; t y = t a y . t c y . 2.7 Goto (1). Abhshek, Rishi, Shubham Automata Construction November 23, 2018 17 / 61

  18. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 18 / 61

  19. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 19 / 61

  20. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 20 / 61

  21. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 21 / 61

  22. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 22 / 61

  23. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 23 / 61

  24. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 24 / 61

  25. Example Abhshek, Rishi, Shubham Automata Construction November 23, 2018 25 / 61

Recommend


More recommend