Create and explore imaginative 3D worlds with our new product Dreamfield (opens in a new tab)
Papers
Topics
Authors
Recent
Search
2000 character limit reached

Context-Free Languages of String Diagrams

Published 16 Apr 2024 in cs.FL and math.CT | (2404.10653v1)

Abstract: We introduce context-free languages of morphisms in monoidal categories, extending recent work on the categorification of context-free languages, and regular languages of string diagrams. Context-free languages of string diagrams include classical context-free languages of words, trees, and hypergraphs, when instantiated over appropriate monoidal categories. Using a contour-splicing adjunction, we prove a representation theorem for context-free languages of string diagrams: every such language arises as the image under a monoidal functor of a regular language of string diagrams.

Authors (2)
Citations (5)

Summary

  • The paper constructs context-free monoidal languages, directly defined over string diagrams in monoidal categories, without linear encodings.
  • The framework simultaneously generalizes classical context-free word languages, context-free tree languages, and hyperedge-replacement graph languages by using categorical construction.
  • Through raw optics and optical contours, the paper establishes that every context-free monoidal language is the image of a regular monoidal language under a strict monoidal functor.
  • followup_questions

The paper develops a categorical theory of context-free languages whose words are replaced by morphisms in monoidal categories. Its central claim is that context-free structure can be formulated directly over string diagrams, without reducing diagrams to linear encodings. The resulting class, called context-free monoidal languages, simultaneously generalizes classical context-free word languages, context-free tree languages, and hyperedge-replacement graph languages. The main theorem establishes a representation result: every context-free monoidal language is the image, under a strict monoidal functor, of a regular monoidal language (2404.10653).

Conceptual framework

Classical formal languages are subsets of a free monoid. The paper adopts the categorical generalization in which a language is a set of morphisms in a category, and then extends it to strict monoidal categories, whose morphisms admit a compositional string-diagrammatic syntax. A polygraph supplies object sorts and generators with arbitrary input and output arities; the free strict monoidal category generated by the polygraph consists of string diagrams modulo the equations of strict monoidal categories.

This setting is substantially more expressive than ordinary word languages. Sequential composition models the composition of processes, while tensor product models independent parallel composition. A generator may have multiple inputs and outputs, permitting branching, merging, resource duplication, and arbitrary wiring patterns depending on the equations imposed on the category.

Figure 1

Figure 1: The free strict monoidal category generated by a polygraph, whose morphisms are string diagrams modulo isotopy and monoidal equations.

The paper’s starting point is the characterization of context-free grammars as morphisms into a category of contexts. For ordinary categories, a production such as

R→w1R1w2R2⋯RnwnR \to w_1R_1w_2R_2\cdots R_nw_n

is represented by a multimorphism whose arguments are the nonterminals and whose value is a word with holes. The holes are filled recursively by derivations. This formulation is due to the categorical treatment of context-free languages developed by Melliès and collaborators, and it generalizes the ordinary grammar formalism while preserving its derivational semantics.

For monoidal categories, however, ordinary spliced arrows are insufficient. A hole need not divide a diagram into a sequence of disjoint left-to-right pieces. It may be surrounded by wires on both sides, and the surrounding structure can interact with tensorial composition.

Figure 2

Figure 2: Spliced arrows decompose a morphism into ordered pieces, whereas monoidal diagram contexts permit holes surrounded by arbitrary tensorial wiring.

The paper therefore introduces diagram contexts, represented by string diagrams containing typed holes. A context with holes can be composed sequentially or in parallel, and the holes are treated symmetrically: their order is not intrinsically significant. Shufflings are used to make exchange admissible, ensuring that independently generated holes may be reordered without changing the represented context.

Regular monoidal languages

Before defining the context-free class, the paper reviews regular monoidal languages. These are accepted by nondeterministic monoidal automata, which generalize both ordinary finite automata and bottom-up tree automata.

A monoidal automaton consists of a finite polygraph Γ\Gamma, a finite set of states, transition relations for each generator, and initial and final state vectors. If a generator has arity nn and coarity mm, its transition relation maps an nn-tuple of input states to a set of mm-tuples of output states. Transitions extend inductively over sequential and tensor composition of diagrams.

This formalism recovers standard finite-state models as special cases:

  • generators of arity and coarity one yield nondeterministic finite automata;
  • generators with arbitrary arity and coarity one yield bottom-up regular tree automata;
  • more general arity and coarity support recognition of languages of process diagrams and graph-like structures.

Balanced parentheses already illustrate the distinction between ordinary regularity and monoidal regularity. The diagrammatic encoding introduces an auxiliary wire that records the state threading through the opening and closing generators.

Figure 3

Figure 3: A monoidal automaton recognizing balanced-parenthesis diagrams by propagating states along an auxiliary wire.

The paper proves that monoidal automata and regular monoidal grammars are equivalent presentations of the same class. A regular monoidal grammar is a morphism of finite polygraphs together with initial and final object words; its language is the image of derivations under the induced strict monoidal functor.

Regular monoidal languages are strictly limited. In particular, the language of unbraids on two strings is not regular monoidal. The proof uses a pumping lemma: sufficiently long factorizations through bounded intermediate interfaces must contain a repeatable segment. For unbraids, pumping such a segment necessarily destroys the required cancellation between over- and under-crossings. Thus the language has a context-free dependency that finite-state monoidal recognition cannot represent.

This result is important because it demonstrates that the subsequent context-free formalism is not merely a reformulation of regular diagram languages. It genuinely increases expressive power.

Context-free monoidal grammars

A context-free monoidal grammar over a strict monoidal category C\mathbb{C} is a morphism of finite symmetric multigraphs

Ψ ⁣:G⟶∣Ctx⁡(C)∣,\Psi \colon \mathcal{G} \longrightarrow |\operatorname{Ctx}(\mathbb{C})|,

together with a start symbol whose image is a pair of boundary objects (X,Y)(X,Y). Each grammar operation is a diagram context with holes, and each derivation is interpreted by recursively filling those holes. The generated language is the image of closed derivations under the induced symmetric multifunctor.

This definition preserves the essential locality of context-free rewriting: each production replaces one nonterminal by a finite diagram containing a finite collection of nonterminals. At the same time, the ambient monoidal category determines how the generated components may be composed, copied, permuted, connected, or otherwise identified.

Balanced parentheses are recovered by restricting to a single-sorted polygraph whose generators have arity and coarity one. The corresponding context-free monoidal grammar is therefore conservative over the classical theory.

Figure 4

Figure 4: Balanced parentheses represented as a context-free monoidal grammar in a single-wire monoidal category.

The framework also subsumes context-free tree grammars. A ranked terminal symbol becomes a generator with arbitrary arity and one output. Nonlinear variable use is represented in the free cartesian category by copying and deletion morphisms. Consequently, a production such as

A(x1,x2)→f(x1,A(x1,x2))A(x_1,x_2)\to f(x_1,A(x_1,x_2))

is expressed diagrammatically using a copying node for the repeated occurrence of x1x_1. The cartesian equations identify diagrams that differ only by the structural laws governing copying and deletion.

Figure 5

Figure 5: Cartesian structure supplies copying and deletion, allowing context-free monoidal grammars to express nonlinear tree-variable usage.

The same principle extends to hyperedge-replacement grammars. In a free hypergraph category, generators represent directed hyperedges and the special commutative Frobenius structure represents the admissible node wiring. A context-free monoidal grammar over this category is equivalent to a hyperedge-replacement grammar in normal form. The holes are placeholders for hyperedges with specified interfaces, and substitution is hyperedge replacement.

Figure 6

Figure 6: Hypergraph-category structure encodes the wiring patterns required for hyperedge-replacement grammars.

The paper also establishes elementary closure properties. Context-free monoidal languages are closed under union and under images of strict monoidal functors. The latter is particularly significant: semantic interpretation of diagrams can identify or transform generated morphisms while preserving context-free definability at the source level.

Raw optics and diagram contexts

The technical core of the paper is the construction of an adjunction suitable for monoidal contexts. Diagram contexts are symmetric because their holes may be exchanged, but this symmetry obscures the ordered decomposition required to construct a contour. The authors resolve this by introducing raw optics.

A raw optic decomposes a context with holes into a sequence of morphisms separated by hole interfaces. For holes (Ai,Bi)(A_i,B_i), a raw optic consists of morphisms of the form

S→M1⊗A1⊗N1,S \to M_1\otimes A_1\otimes N_1,

Mi⊗Bi⊗Ni→Mi+1⊗Ai+1⊗Ni+1,M_i\otimes B_i\otimes N_i \to M_{i+1}\otimes A_{i+1}\otimes N_{i+1},

and

Mn⊗Bn⊗Nn→T.M_n\otimes B_n\otimes N_n\to T.

The objects MiM_i and NiN_i record the tensorial material surrounding each hole. This decomposition is not unique: different choices of hole ordering and factorization may represent the same diagram context.

Figure 7

Figure 7: Distinct raw-optic decompositions can quotient to the same diagram context.

There is a full quotient multifunctor from raw optics to diagram contexts. The quotient forgets the chosen ordering and identifies raw decompositions that produce the same context. Every diagram context admits at least one raw representative, although the representative is generally non-unique.

The authors then define the optical contour of a multicategory. Each object AA in the multicategory produces two polarized objects, ALA^L and ARA^R. For every multimorphism

f ⁣:X1,…,Xn→Y,f\colon X_1,\ldots,X_n\to Y,

the contour introduces n+1n+1 sectors. The first sector enters the left boundary of YY, intermediate sectors connect the right boundary of one argument to the left boundary of the next, and the final sector exits through the right boundary of YY. The intermediate objects retain the surrounding tensorial interfaces of the raw optic.

Figure 8

Figure 8: The optical contour decomposes a multimorphism into entry, intermediate, and exit sectors surrounding its arguments.

The principal categorical result is the adjunction

Contour⁡⊣RawOptics⁡.\operatorname{Contour} \dashv \operatorname{RawOptics}.

A strict monoidal functor from the optical contour of a multicategory into C\mathbb{C} is equivalent to a multifunctor from the multicategory into raw optics over C\mathbb{C}. This adjunction is the monoidal analogue of the contour–splicing adjunction used in categorical treatments of ordinary context-free languages.

The construction is not merely formal. It identifies the exact information needed to linearize derivation structure without imposing a global left-to-right order on the original string diagrams. The contour retains tensorial boundaries in the objects of the generated monoidal category, rather than encoding all derivational structure as an auxiliary word language.

The representation theorem

The main theorem states that every context-free monoidal language is the image of a regular monoidal language under a strict monoidal functor (2404.10653).

More precisely, let a context-free monoidal grammar be given by a morphism

ϕ ⁣:G→Ctx⁡(C)\phi\colon G\to \operatorname{Ctx}(\mathbb{C})

and start symbol SS. The proof proceeds through four constructions.

First, the grammar is factored through raw optics. For every diagram context assigned to a production, one chooses an ordering of holes and a raw-optic decomposition. This yields a raw representative

ϕ~ ⁣:G′→RawOptics⁡(C).\widetilde{\phi}\colon G'\to \operatorname{RawOptics}(\mathbb{C}).

The factorization is explicitly non-unique, but every choice generates the same language after quotienting back to diagram contexts.

Second, the raw representative determines, by the optical-contour adjunction, a unique strict monoidal functor

Iϕ ⁣:Contour⁡(G′)→C.I_\phi\colon \operatorname{Contour}(G')\to\mathbb{C}.

Third, the derivations of G′G' rooted at SS are put into bijection with morphisms

Contour⁡(G′)(SL,SR).\operatorname{Contour}(G')(S^L,S^R).

Thus, the contour category supplies a regular monoidal language whose accepted diagrams are precisely the optical contours of grammar derivations.

Fourth, applying IϕI_\phi maps those contour diagrams to the original generated morphisms in C\mathbb{C}. Therefore,

L(G)=Iϕ(Lreg(R)),L(\mathcal{G}) = I_\phi\bigl(L_{\mathrm{reg}}(\mathcal{R})\bigr),

where R\mathcal{R} is the regular representative over the optical contour.

This result is structurally stronger than the classical Chomsky–Schützenberger representation theorem in one specific respect. The classical theorem represents a context-free language as the homomorphic image of the intersection of a Dyck language and a regular language. The categorical generalization for ordinary categories retains an analogous intersection component. In the monoidal setting developed here, no intersection with an additional context-free or Dyck language is required. The regular monoidal language of optical contours already contains the necessary derivational structure, and the monoidal functor performs the interpretation into the target category.

The claim should be understood carefully. It does not imply that regular and context-free monoidal languages coincide. The unbraid example demonstrates that regular monoidal languages are strictly less expressive. Rather, it states that every context-free monoidal language can be obtained by interpreting an appropriate regular language in another monoidal category. The additional expressive power resides in the target functor and its interpretation of contour generators, not in regular recognition over the original alphabet.

Figure 9

Figure 9: Symmetric structure permits the exchange of independently generated components while the contour construction preserves derivational interfaces.

Technical significance

The paper’s principal contribution is the identification of monoidal categories as a common algebraic setting for several apparently different context-free formalisms. The unification is not achieved by translating diagrams into ordinary strings or by selecting a canonical traversal of a graph. Instead, syntax, derivation, and semantic interpretation remain native to monoidal categories.

Three aspects are particularly significant.

First, diagram contexts generalize the notion of a nonterminal occurrence. A nonterminal is not merely a symbol at a position in a word; it is a typed hole with input and output interfaces embedded in a larger diagram. This supports non-linear topology and parallel composition directly.

Second, the use of raw optics isolates the noncanonical part of the construction. A raw representative chooses an ordering and factorization only as an intermediate proof device. The definition of the language remains invariant under the quotient to symmetric diagram contexts.

Third, the optical contour gives a categorical explanation for why the representation theorem does not require a separate Dyck language. In ordinary word derivations, balanced parentheses encode the nesting structure of derivation trees. In the monoidal setting, tensor products and the polarized boundary objects AL,ARA^L,A^R carry this information through the contour category itself.

Limitations and open questions

The theory is formulated primarily for strict monoidal categories, relying on the equivalence between general monoidal categories and strict ones. Although this is mathematically standard, applications involving explicit coherence data or non-strict computational representations may require a careful account of how presentations and functors transport the grammar.

The regular theory is developed over free strict monoidal categories, whereas context-free monoidal languages are defined over arbitrary strict monoidal categories. The paper notes that extending regular monoidal automata directly to non-free categories remains open. A plausible categorical formulation would use finite-state automata defined by lifting properties of factorization functors, but this is not established here.

The raw-optic factorization is non-unique. The representation theorem guarantees existence of a regular representative, but it does not provide a canonical choice or characterize when two representatives yield equivalent contour languages. This leaves a nontrivial invariance problem concerning the relationship between different hole orderings, different interface factorizations, and the induced monoidal functors.

The treatment is also generative rather than algorithmic. The paper does not provide a pushdown automaton model, a parsing algorithm, or complexity bounds for recognizing context-free monoidal languages. In particular, it remains open how the optical-contour construction should be converted into an effective parser and how the cost of parsing depends on structural parameters such as interface width or monoidal width.

Finally, the framework covers cartesian and hypergraph categories through additional equations and generators, but the generalization to other diagrammatic structures—such as double categories—remains only a stated direction. It is therefore unresolved which parts of the adjunction and representation theorem depend specifically on monoidal composition and which extend to broader categorical syntax.

Conclusion

“Context-Free Languages of String Diagrams” (2404.10653) defines a context-free language theory directly over morphisms in monoidal categories. Its diagram-context formalism captures classical context-free word languages, tree grammars, and hyperedge-replacement grammars within a single framework. The introduction of raw optics and optical contours yields the central representation theorem: every context-free monoidal language is the strict monoidal-functor image of a regular monoidal language. The result separates recognition from interpretation and shows that monoidal structure can internalize the derivational information that requires an auxiliary Dyck language in the classical representation theorem.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Tweets

Sign up for free to view the 1 tweet with 0 likes about this paper.