Complexity of (R)2DCFG On the Complexity of pure 2D Context-free Grammars Achille Frigeri Dipartimento di Matematica “Francesco Brioschi” Politecnico di Milano joint work Marcello M. Bersani & Alessandra Cherubini September 21, 2012
Complexity of (R)2DCFG Introduction Initial motivations One-dimensional languages - consolidated theory Two-dimensional languages The theory is getting consolidated Various classes are known Regular languages are not really defined TS best candidate Expressiveness hierarchy is getting to be complete Sometimes, classes are not comparable
Complexity of (R)2DCFG Introduction Plan Motivations Extend classes of languages Study new closures extending the theory Need for comparisons among classes - hierarchy Algorithm for parsing - complexity
Complexity of (R)2DCFG Introduction Example of word What is a two-dimensional language Alphabet Σ of finite symbols Definition A bidimensional language L ⊆ Σ ∗∗ is a set of two-dimensional arrays over alphabet Σ L = cross of • over ⋄ Σ = { • , ⋄ } ⋄ • ⋄ ⋄ ⋄ • ⋄ ⋄ ⋄ • ⋄ ⋄ ⋄ ⋄ • ⋄ ⋄ ⋄ • ⋄ ⋄ • • • • • ⋄ • ⋄ ⋄ ⋄ • • • ⋄ • ⋄ ⋄ ⋄ • • • • • • ⋄ ⋄ ⋄ • ⋄ ⋄ ⋄
Complexity of (R)2DCFG Introduction Classes considered Formalism defining languages Automata Grammars Expressions Logic Algebra
Complexity of (R)2DCFG Classes of languages considered Compositional classes Local languages L = squares with diagonal of • • ◦ ◦ ◦ • ◦ ◦ • ◦ ◦ • ◦ ◦ , ◦ • ◦ , , ... ◦ • ◦ ◦ • ◦ ◦ ◦ • ◦ ◦ ◦ • Alphabet: Γ = { ◦ , • } ∪ { # } Local factors to build pictures: • ◦ ◦ • ◦ ◦ ◦ ◦ • , ◦ , ◦ , ◦ ◦ • ◦ ◦ Boundaries (removed after construction): # # # # # # • , ◦ , # , ... # • ◦
Complexity of (R)2DCFG Classes of languages considered Compositional Tiling Systems Projection of Local languages: Local alphabet: Γ Final alphabet: Σ Projection: π : Γ → Σ L = squares of ⋄ Γ = { • , ◦ } , Σ = { ⋄ } • ◦ ◦ ⋄ ⋄ ⋄ π : { ◦→⋄ , •→⋄ } ◦ • ◦ − − − − − − − − − → ⋄ ⋄ ⋄ ◦ ◦ • ⋄ ⋄ ⋄ Cannot be defined by local construction ( π is needed).
Complexity of (R)2DCFG Classes of languages considered Compositional Comparison Tiling Systems - Local LOC Tiling System ∪ , ∩ ∪ , ∩ R-C concat R-C concat Closures rotation rotation complement NOT complement Membership P NP-complete Emptiness D U Other EMSO, 2-way OTA, C-free REG exp
Complexity of (R)2DCFG Classes of languages considered Grammars How to classify grammars Set of rules defined by terminals - alphabet constituting final pictures; T = { a , b } non terminals - intermediate alphabet realizing projection; N = { A , B } set of rules; A → aBa , ... Two classes: Isometric : rules do not modify the dimensions of the area on which they are applied → → . . . Non-isometric : rules transform a starting axiom by means of successive expansions of its sub-pictures. → → . . .
Complexity of (R)2DCFG Classes of languages considered Grammars Regional Tile Grammars Isometric grammars A sub-picture is substituted with an isometric sub-picture according to a rule of the grammar N = { • , • , • , • } • • • • → • • • , ... • • • A “blue” area of • is replaced with an isometric subpicture of the form defined on the right. • • • • • • • • rule • • • • − − − → • • • • • • • • • • • •
Complexity of (R)2DCFG Classes of languages considered Pr˚ uˇ sa grammar Non-Isometric grammars A non-terminal is substituted with a sub-picture according to a rule of the grammar N = { • , • , • } , T = { • } • • • → | • , ... • • Each non-terminal is substituted with the subpicture defined on the right. · • • · • • • • • → • → · • • → · • • • • · · • · ·
Complexity of (R)2DCFG Classes of languages considered Grammars (R)P2DCFL (Regularly controlled) Pure 2D Context-free Grammar • Pure: non-terminals not allowed • Tables of row/column rules strictly separated arbitrarily applied on the picture sequence of rule can be controlled by a regular language x x y → x y x x → | b c c: , r: y z → b z b y → z Derivation: x y x x x y x x c r c y − → x y x − → − → b z c b b z b c
Complexity of (R)2DCFG Classes of languages considered Grammars (R)P2DCFL Language of squares of • • c: • → • • , r: • → • Since each derivation is legal, we need a control language over the alphabet of rules L = ( cr ) ∗ • • • • • c r cr • − → • • → − − → • • • • • • • • Note that a P2DCFG is a RP2DCFG with control Γ ∗
Complexity of (R)2DCFG Classes of languages considered Comparisons of grammar Comparison Regional - Pr˚ uˇ sa - (R)P2DCFL RTG Pr˚ uˇ sa (R)P2DCFL ∪ ∪ , ∩ Transposition R/C • R-C concat Reflection Closures NOT ∪ P and R/C ◦ Rotation rotation ∪ R , NOT ∩ P Projection NOT complement P P ,1 , P R ,1 ∈ P P NP P ,5 , NP R ,2 Emptiness ? ? trivial Other Normal form Normal form Normal form
Complexity of (R)2DCFG Result Normal form Normal form Definition A (R)P2DCFG is in normal form if all productions have the form a → α or a → t β with | α | = | β | = 2 . Remark! Pure grammars do not have normal form! Theorem Each P2DCF and RP2DCF grammar is equivalent to a RP2DCFG in normal form. Example c 1 i : a → aα 1 c 2 c i : a → abcd � i : α 1 → bα 2 c 3 i : α 2 → cd
Complexity of (R)2DCFG Result Parsing complexity Parsing P2DCFL Theorem The general problem of the membership of a picture into a language generated by a P2DCFG is NP-complete. Φ = ( x 1 ∨ x 2 ∨ ¬ x 4 ) ∧ ( x 2 ∨ ¬ x 3 ∨ ¬ x 4 ) ∧ ( ¬ x 1 ∨ ¬ x 3 ∨ x 4 ) 1 0 P M N M − − P P M M x 1 = 1, x 3 = 0, x 4 = 1 p Φ = − − − − − − − − − − → 1 1 M N N M 0 0 1 N N P Also, x 1 = 0, x 2 = 0, x 4 = 1 and ...
Complexity of (R)2DCFG Result Parsing complexity We define a P2DCF grammar G generating the smallest set of pictures over the alphabet { P , N , M } which correspond to satisfiable CNF formulae: p Φ ∈ L ( G ) iff Φ is satisfiable generate the truth table of a satisfiable formula with n clauses over m literals/variables each column has at least one 1 C 1 C 2 . . . C n l ( x 1 ) · · M l ( x 2 ) 1 · 1 p { 0,1, M } = . . . l ( x m ) · 1 M
Complexity of (R)2DCFG Result Parsing complexity build a formula which has p { 0,1, M } as truth table C 1 C 2 . . . C n C 1 C 2 . . . C n l ( x 1 ) · · x 1 · · M M l ( x 2 ) · x 2 · · P P N N . . . . . . l ( x m ) · · · · M x m M x 2 → 1 ¬ x 2 → 1
Complexity of (R)2DCFG Result Parsing complexity Parsing P2DCFL over unary alphabet Theorem The parsing of a language generated by a pure 2D context free grammar with unary alphabet is in P . Parsing problem � system of two Diophantine equations. h 1 x 1 + h 2 x 2 + · · · + h t x t = n If gcd ( h 1 , . . . , h t ) = 1 , every n � C can be written as a conical combination of h 1 , . . . , h t
Complexity of (R)2DCFG Result Parsing complexity Example G = ( { a } , { c : a → a 3 | a 6 } , { r : a → ( a 2 ) t | ( a 7 ) t } , a ( 2,3 ) ) . Deciding a ( n , m ) ∈ L ( G ) amounts to verifying � x c 1 ( 3 − 1 ) + x c 2 ( 6 − 1 ) = n − 3 y r 1 ( 2 − 1 ) + y r 2 ( 7 − 1 ) = m − 2 has solutions x c i , y r i � 0 .
Complexity of (R)2DCFG Result Parsing complexity Parsing RP2DCFL over (at least) binary alphabet Theorem The general problem of the membership of a picture to a language generated by a RP2DCFG with (at least) two symbols is NP-complete. Definition Let { S 1 , . . . S n } be a family of finite sets and C ⊆ { S 1 , . . . S n } . We say that C is a k -set-covering for � n i = 1 S i when S j ∈ C S j = � n � i = 1 S i and | C | � k . The set-covering problem is defined for a family { S 1 , . . . S n } and with respect to a positive integer k and it requires to check whether there exists a k -set-covering for { S 1 , . . . S n } . We define a RP2DCF grammar defining the language of pictures representing family of sets S = { S 1 , . . . , S n } which are k -set-covering of � n i = 1 S i = s 1 , s 2 , . . . , s m
Complexity of (R)2DCFG Result Parsing complexity Parsing RP2DCFL over (at least) binary alphabet S = { S 1 , . . . , S n } , � n i = 1 S i = σ 1 , σ 2 , . . . , σ m σ 1 σ 2 . . . σ m S 1 ∗ X ∗ S 2 X ∗ X p S = . . . S n X ∗ ∗
Complexity of (R)2DCFG Result Parsing complexity Generating a picture is in two phase and ruled by r k − 1 ( r 1 + r 2 ) build a k -cover of � n i = 1 S i r : { X → t α , ∗ → t β | α ∈ { ∗ X | X ∗ | X 2 } , β ∈ Σ 2 } ∗ → X X r X X X − ∗ X X freely add rows without altering the k -cover by r 1 , r 2 r 1 : { X → t α , ∗ → t β | α ∈ { X ∗ | X 2 } , β ∈ Σ 2 }
Recommend
More recommend