on language equations and grammar coalgebras for context
play

On Language Equations and Grammar Coalgebras for Context-free - PowerPoint PPT Presentation

On Language Equations and Grammar Coalgebras for Context-free Languages Jurriaan Rot and Joost Winter Leiden University and Centrum Wiskunde & Informatica September 2, 2013 Behavioural differential equations CALCO 11


  1. On Language Equations and Grammar Coalgebras for Context-free Languages Jurriaan Rot and Joost Winter Leiden University and Centrum Wiskunde & Informatica September 2, 2013

  2. Behavioural differential equations CALCO ’11 (Winter/Bonsangue/Rutten): Context-free languages, Coalgebraically. . . . . . behavioural differential equations / Brzozowski derivatives Example: o ( x ) = 1 x a = xy x b = 0 o ( y ) = 0 y a = 0 y b = 1

  3. Behavioural differential equations CALCO ’11 (Winter/Bonsangue/Rutten): Context-free languages, Coalgebraically. . . . . . behavioural differential equations / Brzozowski derivatives Example: o ( x ) = 1 x a = xy x b = 0 o ( y ) = 0 y a = 0 y b = 1 . . . gives . . . { a n b n | n ∈ N } � x � = � y � = { b }

  4. ◮ These systems correspond to coalgebras for the functor 2 × P ω ( − ∗ ) A . . .

  5. ◮ These systems correspond to coalgebras for the functor 2 × P ω ( − ∗ ) A . . . ◮ . . . and can be extended to (infinite) deterministic automata by enforcing o ( x + y ) = o ( x ) ∨ o ( y ) ( x + y ) a = x a + y a o ( xy ) = o ( x ) ∧ o ( y ) ( xy ) a = x a y + o ( x ) y a ✲ P ω ( X ∗ ) ✲ P ( A ∗ ) X ⊂ � − � η � � � � ∼ p ′ � = p ′ ˆ � � � ✛ � ❄ 2 × P ω ( X ∗ ) A 2 × P ( A ∗ ) A ✲ id × � − � A

  6. Grammars and the Greibach normal form Context-free grammars are systems: p : X → P ω (( X + A ) ∗ ) A CFG is in Greibach normal form iff p ( x ) ⊆ 1 + A ( X + A ) ∗ for all x ∈ X giving an isomorphism: P ω (( X + A ) ∗ ) GNF ∼ = 2 × P ω ( X ∗ ) A Hence, grammars in GNF are 2 × P ω ( − ∗ ) A -coalgebras.

  7. Correctness via grammar derivations ◮ CALCO 2011: coalgebraic semantics coincides with classical semantics of context-free languages. ◮ Shown via leftmost derivations in a grammar.

  8. Correctness via grammar derivations ◮ CALCO 2011: coalgebraic semantics coincides with classical semantics of context-free languages. ◮ Shown via leftmost derivations in a grammar. ◮ Context-free languages can also be seen as (least) solutions to grammars, regarded as systems of equations. ◮ Question: can we directly relate these systems of equations to coalgebraic semantics?

  9. On solutions Example: x = 1 + axb Unique solution: x = { a n b n | n ∈ N }

  10. On solutions Example: x = 1 + axb Unique solution: x = { a n b n | n ∈ N } ◮ Such systems of equations (based on the Boolean semiring) always have a least solution. ◮ If it corresponds to a grammar in GNF, this solution is unique.

  11. Formalizing solutions Definition: a solution is any mapping s : X → P ( A ∗ ) making the following diagram commute: ✲ P ( A ∗ ) X s ✲ [ s , η ] ♯ p ❄ P ω (( X + A ) ∗ ) ♯ : inductive extension based on union and concatenation

  12. Solutions and GNF For grammars in GNF, solutions correspond to mappings making the following diagram commute: ✲ P ( A ∗ ) X s � � � � ∼ p ′ � = � � � � ❄ ✲ 2 × P ( A ∗ ) A 2 × P ω ( X ∗ ) A id × ( s ♯ ) A

  13. A lemma Coalgebraic semantics diagram: ✲ P ω ( X ∗ ) ✲ P ( A ∗ ) X ⊂ � − � η � � � � ∼ p ′ = � p ′ ˆ � � � ✛ � ❄ 2 × P ω ( X ∗ ) A 2 × P ( A ∗ ) A ✲ id × � − � A Here � − � is an algebra homomorphism, or: � x + y � = � x � ∪ � y � and � xy � = � x �� y �

  14. A lemma Coalgebraic semantics diagram: ✲ P ω ( X ∗ ) ✲ P ( A ∗ ) X ⊂ � − � η � � � � ∼ p ′ = � p ′ ˆ � � � ✛ � ❄ 2 × P ω ( X ∗ ) A 2 × P ( A ∗ ) A ✲ id × � − � A Here � − � is an algebra homomorphism, or: � x + y � = � x � ∪ � y � and � xy � = � x �� y � and hence we obtain: Lemma ( � − � ◦ η ) ♯ = � − � .

  15. A theorem Coalgebraic semantics and classical semantics coincide: Theorem Given a (classical) system in GNF, � − � ◦ η is the unique solution.

  16. A proof From the diagram ✲ P ω ( X ∗ ) ✲ P ( A ∗ ) X ⊂ � − � η � � � � ∼ p ′ = � p ′ ˆ � � � ✛ � ❄ 2 × P ω ( X ∗ ) A 2 × P ( A ∗ ) A ✲ id × � − � A

  17. A proof From the diagram ✲ P ω ( X ∗ ) ✲ P ( A ∗ ) X ⊂ � − � η � � � � ∼ p ′ = � p ′ ˆ � � � ✛ � ❄ 2 × P ω ( X ∗ ) A 2 × P ( A ∗ ) A ✲ id × � − � A we obtain (by applying the lemma and deleting the diagonal arrow) ✲ P ( A ∗ ) X � − � ◦ η � � � � ∼ p ′ = � � � � � ❄ ✲ 2 × P ( A ∗ ) A 2 × P ω ( X ∗ ) A id × (( � − � ◦ η ) ♯ ) A which is precisely the (unique) classical solution diagram for GNF.

  18. A generalization (1) ◮ Standard generalization: formal languages ⇒ formal power series ◮ Boolean semiring B ⇒ arbitrary semiring K ◮ generalization of P ( A ∗ ): � := { f : A ∗ → K } K � � A � (also a semiring)

  19. A generalization (2) By applying the following replacements we can generalize our main result to arbitrary commutative semirings: 2 ↔ K P ω ( − ∗ ) ↔ K �−� P ( − ∗ ) ↔ K � �−� �

  20. Conclusions and future work ◮ A more categorical look at the coalgebraic view of context-free languages. ◮ Essence: diagram manipulation + � − � is an algebra morphism. ◮ Works more generally for power series over a commutative semiring. ◮ Generalization to other operations, e.g. complement and intersection: straightforward. ◮ Q: Can these results be further generalized to noncommutative semirings.

Recommend


More recommend