A Structural and Nominal Syntax for Diagrams
Dan R Ghica (University of Birmingham), Aliaume Lopez (ENS Cachan)

TL;DR
This paper proposes a unified syntax for diagrams that combines the categorical combinator approach with conventional label-based languages, maintaining semantics and equational properties.
Contribution
It introduces a novel framework that reconciles combinator and label-based diagram syntax without altering existing semantics or equational theories.
Findings
Unified syntax preserves existing semantics.
Provides sound and complete equational theories.
Bridges categorical and conventional diagram languages.
Abstract
The correspondence between monoidal categories and graphical languages of diagrams has been studied extensively, leading to applications in quantum computing and communication, systems theory, circuit design and more. From the categorical perspective, diagrams can be specified using (name-free) combinators which enjoy elegant equational properties. However, conventional notations for diagrammatic structures, such as hardware description languages (VHDL, Verilog) or graph languages (Dot), use a different style, which is flat, relational, and reliant on extensive use of names (labels). Such languages are not known to enjoy nice syntactic equational properties. However, since they make it relatively easy to specify (and modify) arbitrary diagrammatic structures they are more popular than the combinator style. In this paper we show how the two approaches to diagram syntax can be reconciled…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
A Structural and Nominal Syntax for Diagrams
Dan R. Ghica University of BirminghamENS Cachan, Université Paris-Saclay
Aliaume Lopez ENS Cachan, Université Paris-Saclay
Abstract
The correspondence between monoidal categories and graphical languages of diagrams has been studied extensively, leading to applications in quantum computing and communication, systems theory, circuit design and more. From the categorical perspective, diagrams can be specified using (name-free) combinators which enjoy elegant equational properties. However, conventional notations for diagrammatic structures, such as hardware description languages (VHDL, Verilog) or graph languages (Dot), use a different style, which is flat, relational, and reliant on extensive use of names (labels). Such languages are not known to enjoy nice syntactic equational properties. However, since they make it relatively easy to specify (and modify) arbitrary diagrammatic structures they are more popular than the combinator style. In this paper we show how the two approaches to diagram syntax can be reconciled and unified in a way that does not change the semantics and the existing equational theory. Additionally, we give sound and complete equational theories for the combined syntax.
1 Specifying graphs
Graphs and their visual representations (diagrams) are an appealing way of describing many kinds of systems, in particular circuits. Work originated in the study of quantum computation [2] has exploited the connection between various classes of graphs and monoidal categories, going back to the seminal work of Joyal and Street [15], to add a layer of structure which makes reasoning about and with diagrams not just intuitive but also mathematically rigorous. Subsequently this connection was extended in many surprising and interesting directions, from computational linguistics [18], to modelling signal flow [5] and synchronous [10] or asynchronous [9] circuits. New automated reasoning tools based on diagrams, rather than the usual linear algebraic syntax, are a particularly exciting development (see http://globular.science/). This convenient and elegant interplay between the dual categorical and diagrammatic methods are by now a mature and rich area of research [19].
Although these developments convincingly establish the usefulness of categorical diagrammatics in reasoning about many kinds of systems, we note that little has been suggested in terms of a workable syntax which is conceptually compatible with it, but also with conventional notations, which are unstructured and relational. Examples of the latter are hardware description languages such as Verilog and VHDL, or graph languages such as Dot (see http://www.graphviz.org/). Indeed, in the literature the categorical combinators are usually taken as an implicit diagram syntax. Whereas such a syntax is expressive enough to describe the desired classes of graphs, it is often not as convenient as the alternatives. Although categorical combinators can be elegant and succinct in certain situation, point-free languages of combinators generally hold little appeal as concrete syntax (e.g. APL).
Conventional diagram syntax lacks structure. It is a “flat” relational description of the graph. Whereas the categorical combinators are name-free, conventional syntax uses an abundance of names, for nodes and sometimes even for edges. Although these languages are widely used, they are broadly considered both inelegant and unwieldy, and purely structural alternatives have been proposed [3].
Before diving into technicalities let us consider a simple motivating example. Consider the diagram below, consisting of two components and , the first with one input and three outputs and second with three inputs and one output, connected in the obvious way:
In the categorical, combinator-style, specification such a diagram would be succinctly written as the composition , of and . A VHDL-style description would look more verbose:
module fg(input u; output v)begin component f(input x1; output y1, y2, y3); component g(input z1, z2, z3; output t1); wire y1, z1; wire y2, z2; wire y3, z3; wire u, x1; wire t1, v;endThis is the diagram annotated with all the names used above:
In highly structured diagrams the categorical notation is concise and elegant. However, realistic circuits may also use arbitrary connections. Consider a variation of the circuit above:
The flat description can be adjusted to cope with arbitrary connector reassignments:
module fg(input u1, u2; output v1, v2)begin component f(input x1; output y1, y2, y3); component g(input z1, z2, z3; output t1); wire y1, z1; wire y3, z3; wire y2, v2; wire u2, z2; wire u1, x1; wire t1, v1;end
The categorical style description is now more intricate, requiring a mix of sequential (;) and parallel (tensor, ) composition along with the use of structural combinators such as the single connector (identity, ) and crossing connector (symmetry, ):
The combinator-style variable-free syntax is appealing for highly structured diagrams and awkward for arbitrary ones, whereas the flat and unstructured syntax seems useful in the case of unstructured and unnecessarily verbose for structured graphs. Without advocating one style or the other, in this paper we present a syntax which shows that the two are compatible. Our contributions are therefore as follows:
Preserving and extending the equational theory. 2. 2.
Possibly eliminating the need for structural combinators. 3. 3.
Preserving and conserving the expressiveness of the underlying diagrams. 4. 4.
Reasoning equationally in the new syntax.
2 Uniflow diagrams
A PROP (abbreviation of products and permutations) is a strict symmetric monoidal category where every object is a natural number [12]. We give a graph semantics of PROPs based on Kissinger’s framed point graphs [16]. Let a labelled directed acyclic graph (DAG) be a DAG equipped with a partial injection and a relation such that the transitive and reflexive closure of is a partial order on . Let a labelled interfaced DAG (LIDAG) be a labelled DAG with two distinguished lists of unlabelled nodes representing the “input” and “output” ports. Unlabelled nodes are called wire nodes, and edges connecting them are called wires. A wire homeomorphism [16, Sec. 5.2.1] is any insertion or removal of wire nodes along wires which does not otherwise change the shape of the graph. Two LIDAGs are considered to be equivalent if they are graph isomorphic up to renaming vertices and wire homeomorphisms. The quotienting of LIDAGs by this equivalence gives us framed point DAGs [16, Def. 5.3.1], which we will call uniflow diagrams. We give a syntax for uniflow diagram as follows:
[TABLE]
where are the constants and variables. The language is essentially that of symmetrical monoidal categorical combinators (identity, symmetry, composition, tensor) over a signature, extended with variables and a binding construct we read as link and in . We equip this language with a type system, where judgements are of the form is a set of input variables, of output variables and a partial order on their (disjoint) union, called the anchor of the diagram (Fig. 1). The anchor relation is a syntactic discipline used to prevent the inadvertent introduction of cycles. Note that and have the same typing rules as the constants. The type represents a uniflow diagram with (unlabelled) inputs and (unlabelled) outputs. Given a relation we denote by its transitive and reflexive closure. For any set , we define
We give a concrete graph-theoretic semantics of the uniflow diagram. We may write if for some and some partial order . The semantics is defined by induction on the typing derivation. The meaning of a judgement is a uniflow diagram \bigl{(}V,I,O,E,f:V\rightharpoonup K\uplus\mathbb{A}\bigr{)} such that is a set of names and the relation is a partial order on the vertices labelled by variables which is compatible with , i.e. if then there exist unique vertices such that and there is no path in from back to . We write this as The structural combinators are interpreted as in Fig. 2.
Let stand for list concatenation or cons-ing. And let the “zipping” of two lists be defined in the usual way (, and ). If unambiguous we may use a list to also mean the set of elements of that list.
Assuming that The interpretation of the two forms of composition is:
[TABLE]
Note that since diagrams are defined up to relabelling nodes, these definitions are always good. In case of name clashes nodes can be given fresh names.
Constants are interpreted as below, with labels for the input and output ports of the constant.
[TABLE]
The rule for strengthening the anchor is interpreted as
[TABLE]
The restriction on being a proper partial order ensures that the interpretation of the rule is well defined.
Let if and undefined otherwise. The new construct is the link:
[TABLE]
The link can be visualised as below, including the wire homeomorphism:
Lemma 1** (Soundness).**
Any well typed term denotes a valid uniflow diagram.
The useful connection between diagrams and monoidal categories is given by this proposition:
Proposition 2**.**
Given a term , the diagram is a morphism in the strict free symmetric monoidal category (SMC) over signature of constants and (uninterpreted) variables.
By “uninterpreted variables” we mean simply that the variables from are morphism variables in the categorical signature with types and respectively. This is just Thm. 3.12 from [19], which is restating the classic result from [15]. For frame-point graphs this is Thm. 5.5.10 in [16].
Note that this does not make the semantics categorical, since the link construction is not defined categorically but only concretely. However, any term (with our without link) corresponds to a diagram which can be described categorically. An immediate consequence of Prop. 2 is that all derivations of a well typed term produce the same uniflow diagram, possibly with a different anchoring relation.
Lemma 3**.**
The type system of uniflow diagrams is coherent up to the anchoring relation.
Note that different derivations may require different anchoring relations, even though the underlying diagrams are equal as FPGs.
Lemma 4** (Definability).**
Any uniflow diagram is definable just in terms of composition, tensor, link.
Proof.
We introduce exactly two link nodes on each connector (a wire homeomorphism) and we label them with fresh variable names. Suppose there are wires and boxes, inputs and outputs. Let us denote by where the labels associated with input connectors and by where the labels associated with the output connectors. Let (respectively ) be the labels of the th input (respectively output) for each constant occurrence . Let Let . The term is . A link is created if there is an edge between the nodes labelled by and in , with chosen from the variables introduced above. should be a closed form. It is straightforward to show that this is indeed denotes the desired diagram. We only need to prove that this is well typed. The subterm is clearly well typed. Moreover, we can always extend the order with any before linking without creating cycles because the starting graph is a DAG. ∎
The construction in the proof is just the flat nominal notation used by conventional graph languages.
Theorem 5**.**
For any term there exist terms and such that is link-free and is free of structural combinators (identity, symmetry) and
Example 1**.**
Symmetry at any type, e.g. can be defined in combinatorial or nominal style:
[TABLE]
Any for can be defined from , and identity at any non-zero type can be defined from . We sometimes write the identity as just .
Example 2**.**
*We can now revisit our introductory example. The most succinct description mixes variables and structural connectors: *
It can be easily checked that all equational properties of the underlying PROP are carried over to the syntax. We interpret as the equality of the uniflow diagrams represented by and (ignoring the anchoring order). The equations are now parametrised by the set of free variables, as in Fig. 3, assuming integers etc. are chosen so that the terms are well-typed.
We can now turn our attention to the equational theory of uniflow diagrams (Fig. 3). Since is a binding construct, we expect alpha-equivalence to hold, which is reflected in a new axiom, Eqn. 10. Variable renaming and the set of free variables are defined in the obvious way. For name management we also have new equations for scope extrusion (Eqn. 11–14). Finally, the connection between variables and the structural connectors, namely identity, is given in Eq. 15.
Theorem 6**.**
The equational theory of uniflow diagrams is sound and complete for the given semantics.
Proof.
The soundness is immediate. For completeness, consider two terms such that . We first rename all bound variables using alpha-equivalence, then, using Eqns. 11 and 13 we move all binders into global scope. In case the resulting terms are link-free the equation is provable because the terms denote morphism in the free strict symmetric monoidal category over signature extended with the uninterpreted variables (Prop. 2). Suppose that one of the terms has an outermost link, so it has form . We reason diagrammatically about term , which is a morphism in the free SMC over extended with . We can always redraw the diagram to an isomorphic diagram in which the nodes labelled by and are adjacent:
This diagrammatic equivalence can be proved in the equational theory of the uniflow diagrams, noting that and the identities at can be defined in terms of and . Moreover, the diagram on the right will correspond to a term which has subterm , with variables not occurring anywhere else. So we can apply Eqns. 11 and 13 repeatedly until the link binder only binds this subterm, . Then we use Eqn. 15 to replace this subterm with the identity. We repeat the process until all binders are eliminated. ∎
3 Biflow diagrams
Let us consider now strict symmetric traced monoidal categories and their associated diagrammatic language, biflow diagrams [8]. Biflow diagrams are labelled directed graphs with vertices and edges , equipped with a partial injection from vertices to labels. Biflow diagrams are labelled directed graphs with interfaces , lists of unlabelled ports, equivalent up to vertex renaming and wire homeomorphism. In other words, biflow diagrams are uniflow diagrams minus the anchoring relation, similar to Kissinger’s FPGs. The increased expressiveness of the diagrammatic language is reflected into a relaxation of the type system. The type judgements are , similar to the uniflow case but without an anchoring relation. The rules are also similar, with the addition of new rules for trace (Fig. 4).
If the trace is over the unit we omit the superscript. Traces for need not be included as primitive, as they can be constructed out of unit traces.
The diagrammatic interpretation is the same as in the previous section, omitting the anchoring order on vertices. The interpretation of the unit trace operator is the standard one, a feedback edge between the top input and output ports. Assuming that , For equational completeness we also include the (trivial) trace over 0, . Soundness holds, immediately.
Lemma 7** (Biflow definability).**
Any biflow diagram is definable in terms of composition, tensor, link.
Theorem 8**.**
For any term in the language of biflow diagrams, there are forms and such that is link-free and is free of structural combinators (identity, symmetry, trace) and
In the equational theory we inherit all the equations from the previous section, plus the trace equations [13]. All the additional equations are given in Fig. 5. Surprisingly, we do not need new equations for link, except for scope extrusion in the presence of trace (Eqn. 23).
Other relations between trace and link can be derived in the existing equational theory. The proposition below is clearly sound in the model, corresponding to the two alternative descriptions of a back-link, using trace or link.
Proposition 9**.**
**
Proof.
[TABLE]
∎
Theorem 10**.**
The equational theory of biflow diagram is sound and complete for the given semantics.
Note: Diagrams corresponding to compact-closed categories can be described analogously.
4 Monoid and comonoid structures
In the specification of diagrams corresponding to circuits and systems two kinds of structural components are used quite extensively: the splitting of two connectors and the joining of two connectors. A monoid, in this particular diagrammatic context is a pair of constant morphisms where is the multiplication and the unit, interpreted as the following biflow diagrams corresponding to “joining two connectors” and, respectively, to a “dangling output” connector:
.
Conversely, a co-monoid consist of a co-multiplication corresponding to “splitting” two connectors and a co-unit , a “dangling input”.
.
The monoid should be associative, commutative and have a unit law. The corresponding diagrams are in Fig. 6. The co-monoid should be co-associative, co-commutative and have a co-unit, with the equations and diagrams the converse of the above.
Other laws that apply in some contexts are Frobenius () and the special law (). Diagrammatically they are:
If all these equations are satisfied, any structure constructed out of the multiplication, co-multiplication, unit and co-unit can be reduced to a canonical form called informally a spider diagram [7]. Informally, all such constructions will denote a diagram of shape equivalent to
Precisely how these equations are chosen and how they are incorporated into the underlying graph model presents many choices that must be dealt with on a case-by-case basis, depending on the intended applications. In the next sequel we consider two interesting scenarios, but more variations are possible.
4.1 Comonoid structure
One natural way to add a comonoid structure to a biflow diagram is by adding constant morphisms and with the semantics of the previous section. The wire-homeomorphism, which consists of the removal of all possible unlabelled nodes (or, conversely, the insertion of spurious unlabelled nodes) carry over in the obvious way to the new setting. Note that in the absence of the monoid structure all wire nodes, by construction, have exactly one incoming and one outgoing edge. With the monoid structure in place, every wire node has exactly one incoming edger and zero, one or more outgoing edges and wire homeomorphisms need to re-assign the target of the edge. The FPG such that is undefined ( is a wire node) is (still) homeomorphic to the FPG Diagrammatically, the homeomorphism is represented as:
The associativity, co-commutativity and co-unit laws now come then directly from the new wire homeomorphism. For example is:
To reflect the fact that wire nodes have now exactly one incoming and zero or more outgoing edges we update the type system to allow contraction and weakening for input variables while output variables preserve the linear discipline, as seen if Fig. 7.
Even though the semantics of link remains the same, the graph invariants are different because of the presence of the co-multiplication and the co-unit. The diagram for is still the connection of (the single) occurrence of the node labelled with to the (zero or more) occurrences of the node(s) labelled with , followed by the removal of the labels. The mathematical formulation is the same as before (Eqn. 1), except for the anchoring relation.
Lemma 11** (Biflow comonoid definability).**
Any biflow diagram with a comonoid structure is definable in terms of composition, tensor and link.
From this it follows immediately that the link construct is enough in terms of expressiveness, making the explicit use of the co-unit and the co-multiplication optional.
Theorem 12**.**
For any term in the language of biflow diagrams with comonoids, there are forms and such that is link-free and is free of structural combinators (identity, symmetry, trace, comultiplication, counit) and
The equational theory of the diagrammatic language is extended by the following two new equations:
Theorem 13**.**
The equational theory of biflow diagrams with a comonoid is sound and complete for the given semantics.
An analogous link syntax and equational theory for a monoid structure is obvious.
4.2 Frobenius structure
A particularly useful combination of the monoid and the comonoid structures uses the Frobenius and special axioms, leading to so-called spider diagrams [7]. Syntactically, besides the new constants and , the monoid multiplication and unit, the type judgements now lose all linearity, with link nodes useable zero, one or more times both as input and output (Fig. 8).
Theorem 14**.**
For any term in the language of biflow diagrams with a Frobenius structure, there are forms and such that is link-free and is free of structural combinators (identity, symmetry, trace, (co)multiplication, (co)unit) and
The two equations for the monoid structure are: .
Theorem 15**.**
The equational theory of biflow diagrams with a Frobenius structure is sound and complete for the given semantics.
Note that the interaction of the monoid and co-monoid is not necessarily subject to the Frobenius law in diagrammatic languages. This is not a structure that is well studied in its own right, but it turns out to occur naturally in the treatment of digital circuits [11]. The syntax in this case is less natural and the equational properties are more elusive, but the expressiveness and convenience of the notation remains an important attribute.
5 Example
In this section we are giving an example of circuit-like system which has both structural features and arbitrary connections, namely a neural network. We will employ a free use of all the methods of specification available (TMC with monoid and co-monoid and the link operation) to give a succinct and informative description which is, in our subjective opinion, preferable to both the purely structural or the purely relational descriptions. These will be left as reader exercises.
The net we use as an example is the gated recurrent unit [6], a simplification of the popular long short-term memory net [14] which is broadly used in wide range of applications, from machine translation to image classification. The basic cell of the net has the following architecture, where , are activation functions and arithmetic operations.
Let be the (definable) co-monoid on a pair of inputs. The mixed-syntax and the purely structural notations for the GRU cell are:
[TABLE]
Note that in the above the variables can have any width, not necessarily unit.
A recurrent neural net consists of GRU cell with a recurrent link. For practical application, instead of a recurrent link, a finite unfolding of the net is often used:
The two nets can be described as and , respectively.
6 Related and further work
We have shown how variables can be used within a structural framework for diagram syntax. We showed how from the point of view of expressiveness the structural and the nominal syntax can be equivalent and complementary, if the use of variables is constrained by a suitable type system. We have highlighted a neat correspondence between non-linearity and the presence of a monoid or co-monoid structure in the diagram. By extending the structural notation with the new link construct we showed that the existing equational properties are preserved and, moreover, this new structure itself has good equational properties. We believe that the combination of structural and nominal syntax can sometimes improve the readability and usability of diagram languages. Although this paper is only concerned with syntax, it is part of a larger research effort aimed at creating hardware languages more similar to programming languages in terms of their categorical [10] and operational semantics [11]. As further work we intend to create structural conservative extensions of diagram languages such as VHDL, Simulink or Dot.
Several theoretical aspects we have not studied, but remain subject for further work. The most intriguing perhaps is the categorical semantics for the link structure itself. Similar diagrammatic structures have been conjectured in the study of higher-order -calculus, with the input and output links modelled as adjoint profunctors and a link-like operation modelled as their composition [20]. A smaller issue, but practically important, is understanding the syntax and the axiomatisation of links for diagrams with monoid and comonoid structures in the absence of the Frobenius law. These structures occur in diagrams modelling systems with directed flow of information, such as digital circuits, which are well motivated by applications. Finally, the various definability results (e.g. Lem. 4) suggest the possibility of arriving at normal forms for various classes of diagrams.
In terms of the graph semantics, the frame point graphs is not the only possible starting point. Cospans of graphs [17] or hypergraphs [4] have also been used as semantics for diagrammatic monoidal categories. These alternative presentations may arguably offer, to the theorist, more conceptual clarity. What we find attractive about FPGs is the fact that they can be presented in a concrete way, eliding much of the categorical apparatus. We believe this could make our work accessible to a broader audience. Moreover, the link construct is particularly easy to interpret in FPGs. However, these alternative semantic frameworks along with categorical semantics are being investigated.
Acknowledgement:
This work was supported in part by EPSRC grant EP/P004490/1.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1]
- 2[2] Samson Abramsky & Bob Coecke (2004): A Categorical Semantics of Quantum Protocols . In: 19th IEEE Symposium on Logic in Computer Science (LICS 2004), 14-17 July 2004, Turku, Finland, Proceedings , pp. 415–425, 10.1109/LICS.2004.1319636 . · doi ↗
- 3[3] Per Bjesse, Koen Claessen, Mary Sheeran & Satnam Singh (1998): Lava: Hardware Design in Haskell . In: Proceedings of the third ACM SIGPLAN International Conference on Functional Programming (ICFP ’98), Baltimore, Maryland, USA, September 27-29, 1998. , pp. 174–184, 10.1145/289423.289440 . · doi ↗
- 4[4] Filippo Bonchi, Fabio Gadducci, Aleks Kissinger, Pawel Sobocinski & Fabio Zanasi (2016): Rewriting modulo symmetric monoidal structure . In: Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’16, New York, NY, USA, July 5-8, 2016 , pp. 710–719, 10.1145/2933575.2935316 . · doi ↗
- 5[5] Filippo Bonchi, Pawel Sobocinski & Fabio Zanasi (2015): Full Abstraction for Signal Flow Graphs . In: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015 , pp. 515–526, 10.1145/2676726.2676993 . · doi ↗
- 6[6] Kyunghyun Cho, Bart van Merrienboer, Çaglar Gülçehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk & Yoshua Bengio (2014): Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation . In: Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing, EMNLP 2014, October 25-29, 2014, Doha, Qatar, A meeting of SIGDAT, a Special Interest Group of the ACL , pp. 1724–1734. Available at http://aclweb.org/anthology/D/D 14/
- 7[7] Bob Coecke & Ross Duncan (2008): Interacting Quantum Observables . In: Automata, Languages and Programming, 35th International Colloquium, ICALP 2008, Reykjavik, Iceland, July 7-11, 2008, Proceedings, Part II - Track B: Logic, Semantics, and Theory of Programming & Track C: Security and Cryptography Foundations , pp. 298–310, 10.1007/978-3-540-70583-3_25 . · doi ↗
- 8[8] V. E. Căzănescu & Gheorghe Stefănescu (1990): Towards a New Algebraic Foundation of Flowchart Scheme Theory . Fundam. Inf. 13(2), pp. 171–210. Available at http://dl.acm.org/citation.cfm?id=97367.97373 .
