A Framework for Rewriting Families of String Diagrams
MM. Fernández and I. Mackie (Eds.): TERMGRAPH 2018.EPTCS 288, 2019, pp. 63–76, doi:10.4204/EPTCS.288.6 c (cid:13)
V. ZamdzhievThis work is licensed under theCreative Commons Attribution License.
A Framework for Rewriting Families of String Diagrams
Vladimir Zamdzhiev
Université de Lorraine, CNRS, Inria, LORIA, F 54000 Nancy, France
We describe a mathematical framework for equational reasoning about infinite families of stringdiagrams which is amenable to computer automation. The framework is based on context-free familiesof string diagrams which we represent using context-free graph grammars. We model equationsbetween infinite families of diagrams using rewrite rules between context-free grammars. Ourframework represents equational reasoning about concrete string diagrams and context-free familiesof string diagrams using double-pushout rewriting on graphs and context-free graph grammarsrespectively. We prove that our representation is sound by showing that it respects the concretesemantics of string diagrammatic reasoning and we show that our framework is appropriate forsoftware implementation by proving the membership problem is decidable.
String diagrams have found applications across a range of areas in computer science and related fieldssuch as concurrency [12], systems theory [2], quantum computing [3] and others. A string diagram isa graph-like structure which consists of a collection of nodes together with a collection of (possiblyopen-ended) wires connecting nodes to each other (cf. Figure 1a). However, in some application scenarios,it is necessary to reason not just about individual string diagrams, but about entire families of stringdiagrams (cf. Figure 2). For example, in quantum computing, algorithms and protocols are often describedby a family of quantum circuits (diagrams), parameterised by the number of input qubits (wires).However, as the size of a system grows, reasoning about large (families) of string diagrams becomescumbersome and error-prone. These issues can be alleviated by using a diagrammatic proof assistant, suchas Quantomatic [9], which can automate the reasoning process. Of course, this necessitates developing aformal framework which can represent such families of string diagrams.We will represent individual string diagrams using string graphs [7]. A (directed) string graph is a(directed) graph with two kinds of vertices – wire vertices and node vertices. Wire vertices have in-degreeand out-degree at most one and are used to represent the (open-ended) wires of string diagrams; nodevertices can be adjacent only to wire-vertices (cf. Figure 1b).The primary contribution of this work is to improve the results of [6], which laid the foundation for therepresentation of context-free families of string diagrams and the methods used for equationally reasoningabout them. All of the results in this paper are described in detail in the author’s PhD thesis [17]. We (a) (b)
Figure 1:
String diagram (a) and its string graph representation (b). A Framework for Rewriting Families of String Diagrams ···
Figure 2:
Family of string diagrams. will represent families of string diagrams and equational reasoning for them by context-free grammars ofstring graphs and DPO rewriting of these grammars, respectively.
We begin by introducing some notation and, because of lack of space, briefly recalling the theory of
B-edNCE graph grammars (see [4] or [17, Chapter 2] for the full definitions). Throughout the rest of thepaper, we consider graphs whose vertices are labelled over an alphabet Σ and whose edges are labelledover an alphabet Γ . ∆ ⊆ Σ is the alphabet of terminal vertex labels ; N ⊆ ∆ is the alphabet of node-vertexlabels and W = ∆ − N is the alphabet of wire-vertex labels . Definition 1 (Graph [4]) . A graph over an alphabet of vertex labels Σ and an alphabet of edge labels Γ isa tuple H = ( V , E , λ ) , where V is a finite set of nodes, E ⊆ { ( v , γ , w ) | v , w ∈ V , v (cid:54) = w , γ ∈ Γ } is the set ofedges and λ : V → Σ is the vertex labelling function. Remark . The framework which we describe works with both directed and undirected graphs, where thelatter requires only a small simplification of some definitions. To retain generality, all definitions withinthe paper are stated for directed graphs, but many of our examples show undirected graphs (as they makefor more interesting examples). In our notion of graph, self-loops are not allowed and parallel edges areallowed as long as they have distinct labels. This requirement is commonly imposed by node-replacementgraph grammars in the litereature.
Definition 3 (Extended Graph [4]) . An Extended Graph over Σ and Γ is a pair ( H , C ) , where H is a graphand C ⊆ Σ × Γ × Γ × V H × { in , out } . C is called a connection relation and its elements ( σ , β , γ , x , d ) arecalled connection instructions . The set of all extended graphs over Σ and Γ is denoted by EGR Σ , Γ .An extended graph provides the necessary information on how a specific graph can be used to replacea nonterminal vertex and connect it to the local neighbourhood of the nonterminal vertex that is to bereplaced. In the literature, extended graphs are commonly referred to as graphs with embedding [4].If we are given a mother graph ( H , C H ) with a nonterminal vertex v ∈ H and a daughter graph ( D , C D ) ,then the substitution of ( D , C D ) for v in ( H , C H ) , denoted by ( H , C H )[ v / ( D , C D )] , is given by the extendedgraph constructed in the following way: for every connection instruction ( σ , β , γ , x , in ) ∈ C D and for every σ -labelled vertex w in the mother graph for which there is a β -labelled edge going in to the nonterminalvertex v of the mother graph, then the substitution process will establish a γ -labelled edge from w to x .This should become more clear after referring to Example 9. The meaning for ( σ , β , γ , x , out ) is analogous.Next, we define the concept of an edNCE Graph Grammar. edNCE is an abbreviation for N eighbourhood C ontrolled E mbedding for d irected graphs with dynamic e dge relabelling. Definition 4 (edNCE Graph Grammar [4]) . An edNCE Graph Grammar is given by a pair G = ( P , S ) ,where P is a finite set of productions and S ∈ Σ − ∆ is the initial nonterminal label. Productions are ofthe form X → ( D , C ) , where X ∈ Σ − ∆ is a nonterminal label and ( D , C ) ∈ EGR Σ , Γ is an extended graph. . Zamdzhiev p : = X → ( D , C ) , we shall say that the left-hand side of p is X and denote it with lhs ( p ) .The right-hand side of p is the extended graph ( D , C ) and we denote it with rhs ( p ) . Vertices which havea label from ∆ are called terminal vertices and vertices with labels from Σ − ∆ are called nonterminalvertices . An (extended) graph is called terminal if all of its vertices are terminal.Instead of presenting grammars using set-theoretic notation, we will often present them graphically asit is more compact and intuitive. We will use the same notation as in [4], which we now explain. Thegrammar of Figure 3 has three productions. In each production, the nonterminal symbol is written in thetop-left corner of the box. The content of the box is simply the graph which replaces its correspondingnonterminal in a derivation. Any edges crossing the box are the connection instructions which indicatehow to connect the graph within the box to its outside context. Definition 5 (Extended Graph homomorphism) . Given two extended graphs ( H , C H ) , ( K , C K ) ∈ EGR Σ , Γ ,an extended graph homomorphism between ( H , C H ) and ( K , C K ) is a function f : V H → V K , such that f isa graph homomorphism from H to K and if ( σ , β , γ , x , d ) ∈ C H then ( σ , β , γ , f ( x ) , d ) ∈ C K . Definition 6 (Derivation [4]) . For a graph grammar G = ( P , S ) and extended graphs H , H (cid:48) , let v ∈ V H be anon-terminal vertex with label X and p : X → ( D , C ) be a production (copy) of the grammar, such that H and D are disjoint. We say H = ⇒ v , p H (cid:48) is a derivation step if H (cid:48) = H [ v / ( D , C )] . A sequence of derivationsteps H = ⇒ v , p H = ⇒ v , p · · · = ⇒ v n , p n H n is called a derivation . We write H = ⇒ ∗ H (cid:48) if there exists aderivation from H to H (cid:48) . A derivation H = ⇒ ∗ H (cid:48) is concrete if H (cid:48) is terminal. Definition 7 (Graph Grammar Language [4]) . A sentential form of an edNCE grammar G = ( P , S ) is agraph H such that sn ( S , z ) = ⇒ ∗ H for some z , where sn ( S , z ) is the (extended) graph that has only onevertex given by z , its label is S and the graph has no edges and no connection instructions. The graphlanguage induced by G is the set of all terminal sentential forms modulo graph isomorphism. Definition 8 (B-edNCE grammar [4]) . An edNCE grammar G = ( P , S ) is boundary , or a B-edNCEgrammar, if for every production X → ( D , C ) , we have that D contains no edges between nonterminalvertices and C does not contain connection instructions of the form ( σ , β , γ , x , d ) where σ is a nonterminallabel. Example 9.
The language of the B-edNCE grammar from Figure 3(a) consists of the string graphrepresentations of the string diagrams from Figure 2. The (concrete) derivation which produces the stringgraph from Figure 1(b) is shown in Figure 3(b).
XS XX XXS = ⇒ = ⇒ X = ⇒ (a)(b) = ⇒ X Figure 3: A B-edNCE grammar of undirected graphs (a) and a concrete derivation from it (b).6
A Framework for Rewriting Families of String Diagrams sK n = sS n Figure 4: Equational schema
In this section, we present our framework which allows us to equationally reason about entire familiesof string diagrams (as opposed to individual string diagrams). As a motivating example, we considerthe local complementation rule [3] of the ZX-calculus (used in quantum computing), which is crucialfor establishing a decision procedure for equality of diagrams in the calculus. The essential data of therule is given by the equational schema in Figure 4. where sK n is the complete string graph on n vertices(consisting of n nodes connected to each other via wires consisting of 1 wire vertex) and sS n is the star string graph on n vertices (the string graph representation of Figure 2). In both cases, every node has alsoexactly one open-ended wire attached to it. As we saw in Example 9, edNCE grammars may represent the { sS n } n ∈ N family, but unfortunately, theycannot represent the { sK n } n ∈ N family [17, Section 3.3]. However, it is well-known that (B)-edNCEgrammars can represent the family of complete graphs and if we think of the edges of a complete graphas if they are representing a wire with a single wire vertex, then we can recover the latter family. Thisidea may be easily formalized and allows us to slightly extend the expressive power of edNCE grammars,while still retaining crucial decidability properties (like the membership problem).As a first step, we refine the alphabet of edge labels by introducing E ⊆ Γ to be the alphabet of encoding edge labels. Essentially, the idea described above is formalized by using graph grammarswhich generate graphs that contain some encoding edges which are subsequently decoded using a simpleconfluent and terminating DPO rewrite system. Definition 10 (Encoded string graph [6]) . An encoded string graph is a string graph where we additionallyallow edges with labels α ∈ E to connect pairs of node-vertices. Edges labelled by some α ∈ E will becalled encoding edges. Definition 11 (Decoding system [6]) . A decoding system T is a set of DPO rewrite rules of the form: σ σ α σ σ σ σ H one for every triple ( α , σ , σ ) ∈ E × N × N , where the LHS consists of a single edge with encodinglabel α ∈ E connecting a σ -labelled node-vertex to a σ -labelled node-vertex, and the RHS is a stringgraph which contains the same two node-vertices and at least one additional vertex while containing noinputs, outputs, or encoding labels. Theorem 12.
Any decoding system T is confluent and terminating.
Given an (encoded string) graph, decoding is the process of applying all of the rules of T to the graph.As the above theorem shows, this is a very simple process which may even be done in a single step. If H isan encoded string graph, we shall say that H (cid:48) has been decoded from H , and denote this with H = ⇒ T ∗ H (cid:48) , if the graph H (cid:48) is the result of applying all rules from T to H , such that H (cid:48) contains no encoding edges. . Zamdzhiev Lemma 13.
Given two graphs H , H (cid:48) with H = ⇒ T ∗ H (cid:48) , where T is a decoding system, then H is an encodedstring graph iff H (cid:48) is a string graph. Definition 14 (Encoded B-edNCE grammar) . An encoded B-edNCE grammar is a pair B = ( G , T ) , where G is a B-edNCE grammar and T is a decoding system. A concrete derivation for an encoded B-edNCEgrammar B = ( G , T ) with S the initial nonterminal, consists of a concrete derivation in G followed bya decoding in T , which we denote as sn ( S , z ) = ⇒ G ∗ H = ⇒ T ∗ H or simply with sn ( S , z ) = ⇒ B ∗ H if thegraph H is not relevant for the context. Definition 15 (B-ESG grammar) . A Boundary Encoded String Graph ( B-ESG ) grammar is an encodedB-edNCE grammar B = ( G , T ) , subject to some additional coherence conditions, which we omit for lackof space (see [17, Chapter 4]).The coherence conditions from the above definition are both necessary (up to normal form) andsufficient to generate languages of string graphs, as the next two theorems show. Theorem 16.
Every graph in the language of a B-ESG grammar is a string graph.
Theorem 17.
Given an encoded B-edNCE grammar B = ( G , T ) , such that L ( B ) is a language consistingof string graphs, then there exists a B-ESG grammar B (cid:48) = ( G (cid:48) , T ) , such that L ( B (cid:48) ) = L ( B ) . Moreover, G (cid:48) can be constructed effectively from G and L ( G (cid:48) ) = L ( G ) . Example 18.
The language of the B-ESG grammar B = ( G , T ) below is the family { sK n } n ∈ N . XS XX X αα α αααα α = ⇒ T sK is derived by first generating a graph with encoding edges (labelled α ) followed by decoding: α αα X = ⇒ G L = ⇒ G L α X α αα = ⇒ G L = ⇒ G L S X ααα α αα ααα = ⇒ T ∗ The grammar from Example 9 is also a B-ESG grammar when equipped with any decoding system (whichdoes not have an effect on the generated language, because the grammar does not contain encoding edges).
Theorem 19.
The membership problem for B-ESG grammars is decidable.
Definition 20 (Grammar homomorphism) . Given two edNCE grammars G = ( P , S ) and G = ( P , S ) ,a grammar homomorphism from G to G is a function m : P → P , together with a collection of extendedgraph homomorphisms (cf. Definition 5) m p i : rhs ( p i ) → rhs ( m ( p i )) one for each production p i ∈ P ,such that lhs ( p i ) = lhs ( m ( p i )) . Definition 21 (Category of B-ESG grammars) . The category of B-ESG grammars over a decoding system T , denoted B-ESG T , or simply B-ESG if T is clear from the context, has objects B-ESG grammars B = ( G , T ) . A morphism h between two B-ESG grammars B = ( G , T ) and B = ( G , T ) is a grammarhomomorphism h : G → G . Theorem 22.
B-ESG T is a partially adhesive category (cf. [7]). The above theorem means that DPO rewriting of B-ESG grammars themselves is well-behaved,provided that some additional matching conditions (which are fully characterised) are satisfied [17,Chapter 5].8
A Framework for Rewriting Families of String Diagrams
We saw how to represent families of string graphs, next we explain how to represent equational schemasbetween such families. That is, we wish to establish a constructive bijection between the graphs of onefamily and the graphs of the other. We may do so if we require that the pair of B-ESG grammars havea 1-1 correspondence between their productions and so do the nonterminal vertices in correspondingproductions. This allows us to perform parallel concrete derivations between the two grammars and wemay thus establish the constructive bijection we required.
Definition 23 (Extended graph rewrite rule) . An extended graph rewrite rule is a pair of monomorphisms L l ←− I r −→ R , where all objects are extended graphs. Definition 24.
Given extended graphs G and D where x ∈ V G is a (nonterminal) vertex, and givenmonomorphisms m : G → G (cid:48) and m : D → D (cid:48) , then m ( v ) : = (cid:40) m ( v ) if v ∈ V G m ( v ) if v ∈ V D is the induced substituted monomorphism m : G [ x / D ] → G (cid:48) [ m ( x ) / D (cid:48) ] , which we denote by SM ( m , m , x ) . Definition 25 (Rewrite rule substitution) . Given extended graph rewrite rules B : = L l ←− I r −→ R and B : = L l ←− I r −→ R , with (non-terminal) vertex v ∈ I then the substitution of B for v in B , denoted B [ v / B ] is given by the extended graph rewrite rule B : = L l ←− I r −→ R , where L : = L [ l ( v ) / L ] , I : = I [ v / I ] , R : = R [ r ( v ) / R ] , l : = SM ( l , l , v ) and r : = SM ( r , r , v ) . Definition 26 (B-edNCE Pattern) . A B-edNCE pattern is a triple of B-edNCE grammars B : = G L l ←− G I r −→ G R , where l and r are grammar monomorphisms which are bijections between the productionsof all three grammars. Moreover, l and r are also label-preserving bijections between the nonterminalsin corresponding productions of the grammars. In addition, all three grammars have the same initialnonterminal label. If p is a production in G L , then B p will refer to the extended graph rewrite rule rhs ( p ) l p (cid:48) ←− rhs ( p (cid:48) ) r p (cid:48) −→ rhs ( p (cid:48)(cid:48) ) , where p (cid:48) and p (cid:48)(cid:48) are the corresponding productions of p in G I and G R respectively, and l p (cid:48) and r p (cid:48) are the components (cf. Definition 20) of the monomorphisms l and r atproduction p (cid:48) .These conditions ensure that we may perform parallel derivations in the sense that at each step weapply corresponding productions and replace corresponding nonterminals in all three grammars. Definition 27 (B-edNCE Pattern Instantiation) . Given a B-edNCE pattern G L l ←− G I r −→ G R , a parallelinstantiation is a triple of concrete derivation sequences of the following form: sn ( S , v ) = ⇒ G L v , l ( p ) H (cid:48) = ⇒ G L l ( v ) , l ( p ) H (cid:48) = ⇒ G L l ( v ) , l ( p ) · · · = ⇒ G L l ( v n ) , l ( p n ) H (cid:48) n sn ( S , v ) = ⇒ G I v , p H = ⇒ G I v , p H = ⇒ G I v , p · · · = ⇒ G I v n , p n H n sn ( S , v ) = ⇒ G R v , r ( p ) H (cid:48)(cid:48) = ⇒ G R r ( v ) , r ( p ) H (cid:48)(cid:48) = ⇒ G R r ( v ) , r ( p ) · · · = ⇒ G R r ( v n ) , r ( p n ) H (cid:48)(cid:48) n The language of B , denoted L ( B ) , is the set of all graph rewrite rules H (cid:48) n l n ←− H n r n −→ H (cid:48)(cid:48) n obtained byperforming concrete parallel derivations, where l n and r n are induced by the derivation process. Definition 28 (Production input/output/isolated vertex) . Given a B-ESG grammar B , we say that awire-vertex w is a production input (output) if its in-degree (out-degree) is zero and it has no incoming(outgoing) connection instructions. w is a production isolated wire-vertex if it is both a production inputand a production output. . Zamdzhiev Definition 29 (B-ESG rewrite rule) . A B-ESG rewrite rule is a span of monos B L l ←− B I r −→ B R , where B L = ( G L , T ) , B I = ( G I , T ) , B R = ( G R , T ) , such that G L l ←− G I r −→ G R is a B-edNCE pattern such that forevery triple of corresponding productions p L , p I , p R in G L , G I , G R respectively, we have: Boundary: p I contains only nonterminal vertices and isolated wire-vertices and it contains no edges,connection instructions or node-vertices. IO1: l and r are surjections on the production inputs (outputs) between p I and p L , p I and p R respectively. IO2:
For every wire-vertex w ∈ p I , l ( w ) and r ( w ) are both a production input (output) in p L and p R respectively.Moreover, the grammars G I , G L , G R must be in a certain normal form (cf. [17, Section 5.3]). Definition 30 (B-ESG Rewrite Rule Instantiation) . Given a B-ESG rewrite rule B : = B L l ←− B I r −→ B R , aparallel instantiation is a B-edNCE pattern instantiation for G L l ←− G I r −→ G R followed by a decoding: sn ( S , v ) = ⇒ G L v , l ( p ) H (cid:48) = ⇒ G L l ( v ) , l ( p ) H (cid:48) = ⇒ G L l ( v ) , l ( p ) · · · = ⇒ G L l ( v n ) , l ( p n ) H (cid:48) n = ⇒ T ∗ F (cid:48) sn ( S , v ) = ⇒ G I v , p H = ⇒ G I v , p H = ⇒ G I v , p · · · = ⇒ G I v n , p n H n = ⇒ T ∗ Fsn ( S , v ) = ⇒ G R v , r ( p ) H (cid:48)(cid:48) = ⇒ G R r ( v ) , r ( p ) H (cid:48)(cid:48) = ⇒ G R r ( v ) , r ( p ) · · · = ⇒ G R r ( v n ) , r ( p n ) H (cid:48)(cid:48) n = ⇒ T ∗ F (cid:48)(cid:48) The language of B , denoted L ( B ) , is the set of all rewrite rules F (cid:48) l F ←− F r F −→ F (cid:48)(cid:48) obtained by performingparallel derivations, where the embeddings F (cid:48) l F ←− F r F −→ F (cid:48)(cid:48) are induced by the derivation process. Theorem 31.
The language of every B-ESG rewrite rule consists solely of string graph rewrite rules.
Example 32.
Let B L = ( G L , T ) be the B-ESG grammar representing { sK n } n ∈ N from Example 18 andlet B R = ( G R , T ) , where G R is the grammar representing { sS n } n ∈ N from Figure3. Given this data,there is a unique (and constructive) choice for a B-ESG grammar B I and embeddings l , r , such that B : = B L l ←− B I r −→ B R is a B-ESG rewrite rule. B I = ( G I , T ) , where G I is given by: XS XX X and l and r are the obvious grammar embeddings. A derivation of a string graph rewrite rule relating sK and sS is given by a derivation involving 4 (parallel) steps in the B-edNCE grammars and a decoding: S = ⇒ G R X = ⇒ G R X = ⇒ G R = ⇒ G I = ⇒ T ∗ XS = ⇒ G I = ⇒ G I XX α = ⇒ G L X X α = ⇒ G L α αα αα α αα = ⇒ T ∗ αα S ααα = ⇒ G L = ⇒ G L α = ⇒ G I XX = ⇒ T ∗ = ⇒ G R where there are obvious induced embeddings of the middle string graph into the other two (details omitted).0 A Framework for Rewriting Families of String Diagrams
Next, we show how to model equational reasoning by applying an equational schema to a context-freefamily of diagrams. We begin by first showing that DPO rewriting (which we use to model equationalreasoning for graphs and grammars) behaves well with respect to graph substitution (which we use forlanguage generation). We use the notation H (cid:32) mB H (cid:48) to indicate that the DPO rewrite of the (extended)graph H using the (extended) graph rewrite rule B at matching m is the (extended) graph H (cid:48) . Theorem 33.
Given boundary extended graphs H , H (cid:48) , D , D (cid:48) , such that H (cid:32) m B H (cid:48) and D (cid:32) m B D (cid:48) , whereB : = L l ←− I r −→ R , B : = L l ←− I r −→ R , v ∈ V I and where m , m are matchings (subject to someadditional conditions), then H [ m ◦ l ( v ) / D ] (cid:32) m B H (cid:48) [ f ◦ r ( v ) / D (cid:48) ] , where B : = B [ v / B ] and m = SM ( m , m , l ( v )) . In terms of diagrams, given the following two DPO rewrites:L H K I R H (cid:48) l r m s k f g g I k K L D (cid:48) f r R m s D l then the following diagram is also a DPO rewrite:L [ l ( v ) / L ] H [ m ◦ l ( v ) / D ] K [ k ( v ) / K ] I [ v / I ] R [ r ( v ) / R ] H (cid:48) [ f ◦ r ( v ) / D (cid:48) ] l r m s k f g where each x is the obvious substituted monomorphism (cf. Definition 24). Definition 34 (B-ESG rewrite) . Given a B-ESG rewrite rule B = B L l ←− B I r −→ B R with initial nonterminallabel S and a B-ESG grammar B H , such that B H is in normal form (cf. [17, Section 5.3]), then wewill say that the B-ESG rewrite of B H using B over a matching m : G L → G H , is the B-ESG grammar B M = ( G M , T ) , denoted by B H (cid:32) B , m B M , where G M is given by the DPO rewrite: G L G H G K G I G R G M l rm s k fg Theorem 35.
Given a B-ESG rewrite B H (cid:32) B , m B M , as in Definition 34, where the matching m satisfiessome additional conditions (cf. [17, Section 5.4]), then the rewrite B H (cid:32) B , m B M is admissible with respectto L ( B ) in the following sense: if ( K , K (cid:48) ) is a parallel instantiation (cf. Definition 30) of ( B H , B M ) , thenthere exists a sequence of string graph rewrite rules s , . . . , s n ∈ L ( B ) , such that K (cid:32) s · · · (cid:32) s n K (cid:48) . Example 36.
Consider the equational schema in Figure 5. It can be derived from its left-hand sideby applying the equational schema from Figure 4. Moreover, this application respects the concretesemantics of the graph families in the sense that every instantiation of the former schema can be obtained . Zamdzhiev sK n = sS n Figure 5: Derived equational schema.by applying a specific instantiation of the latter schema. We now show how to model this using ourframework. The left-hand side of Figure 5 is represented by the B-ESG grammar B H = ( G H , T ) givenbelow (left). By performing a B-ESG rewrite using the B-ESG rewrite rule from Example 32, we get thegrammar B P = ( G P , T ) given below (right), which correctly represents the right-hand side of Figure 5. XS XX X αα α αααα α = ⇒ T X XS XX α = ⇒ T Moreover, this rewrite respects the concrete semantics, because for any parallel instantiation ( K , K (cid:48) ) of thetwo grammars above, the string graph K may be rewritten into the string graph K (cid:48) by applying a concretestring graph rewrite rule induced by the B-ESG rewrite rule from Example 32. In the previous section we presented a running example which showed how to model the local complemen-tation rule for the ZX-calculus. We now provide another example, namely of the Generalised Bialgebrarule, which is an important distributivity law for several diagrammatic calculi, including the ZX-calculus.We will show how this can be represented using our framework.The generalised bialgebra rule is given by the equational schema of string diagrams given by (1): ········· ··· = ······ (1) where the LHS has m green nodes each of which is connected to all n red nodes and, in addition, all greenand red nodes have exactly one input/output wire. The inputs are the open-ended wires at the bottom andthe outputs are the open-ended wires at the top of the diagram. We will call this family of string diagrams sK m , n . The RHS family we call sS m , n and it (necessarily) has m inputs and n outputs.In order to represent this rule using our framework, we first have to describe a B-ESG grammar thatdescribes the LHS of (1). A good choice is the grammar B L = ( G L , T ) given by: XS XX X α = ⇒ T Y YY α Y α A Framework for Rewriting Families of String Diagrams
Next, we have to represent the RHS of (1). We remark that our choice of grammar has to be consistentwith the one just constructed in order to satisfy the requirements of our framework. A suitable choice isthe grammar B R = ( G R , T ) given by: XS XX X α = ⇒ T YY YY
Our framework ensures that we may now uniquely construct an interface grammar by just taking thenonterminal vertices and inputs/outputs from each production of either grammar B L or B R . We name theresulting grammar B I = ( G I , T ) : XS XX X α = ⇒ T YY YY
There are now obvious grammar embeddings l and r , such that B : = ( B L l ←− B I r −→ B R ) is a B-ESG rewritepattern. The pattern B therefore encodes the rewrite rule sK m , n (cid:32) sS m , n . Of course, by swapping B L and B R we may represent the other direction of equation (1), but we shall only consider the left-to-rightdirection in this example.Our framework guarantees that for any specific choice of m and n , we get a string graph DPO rewriterule sK m . n (cid:32) sS m , n . The parallel derivation of B which produces the DPO rewrite rule sK , (cid:32) sS , isgiven by: SS = ⇒ G L = ⇒ G R = ⇒ G L = ⇒ G R = ⇒ G L = ⇒ G R = ⇒ T ∗ = ⇒ T ∗ X X X = ⇒ G L Y = ⇒ G L Y α αα α αα = ⇒ G L ααα = ⇒ G I X = ⇒ T ∗ = ⇒ G I S = ⇒ G I = ⇒ G I = ⇒ G I YX = ⇒ G I YXX X X = ⇒ G R = ⇒ G R Y Y = ⇒ G R Observe that the middle derivation is uninteresting, because it is uniquely determined by either of theother two derivations by just taking the nonterminal vertices and the inputs/outputs in correspondingproductions. Once the derivation process is over, the result is the DPO rewrite rule sK , (cid:32) sS , : ← (cid:45) (cid:44) → . Zamdzhiev ··· ········· If we apply the equational schema (1) to it, then we get the derived equational schema (2): ········· ··· = ······ (2) To represent this rewrite in our framework, we start by constructing a B-ESG grammar for the LHS of (2).We choose the grammar B H = ( G H , T ) as follows: XS XX X α = ⇒ T Y YY α Y α The previously constructed grammar rewrite rule B may now be matched into B H and the DPO rewritecan be performed, yielding the grammar B P = ( G P , T ) : XS XX X α = ⇒ T YY YY
Observe that B P correctly represents the RHS of (2) and that the derived rewrite pattern B (cid:48) : = ( B H ← (cid:45) B I (cid:44) → B P ) correctly represents the derived equational schema (2). More concretely, because the matchsatisfies the strong requirements imposed by our framework, the performed rewrite is admissible withrespect to B in the following sense. For any parallel derivation ( B H , B P ) = ⇒ ∗ ( H , P ) , the string graph H can be rewritten to the string graph P using a sequence of DPO rewrite rules induced by B (in thisspecific case, this may be done using a single DPO rule). For instance, consider the parallel derivation of ( B H , B P ) = ⇒ ∗ ( H , , P , ) :4 A Framework for Rewriting Families of String Diagrams SS = ⇒ G H = ⇒ G P = ⇒ G H = ⇒ G P = ⇒ G H = ⇒ G P = ⇒ T ∗ = ⇒ T ∗ X X X = ⇒ G H Y = ⇒ G H Y α αα α αα = ⇒ G H ααα X X X = ⇒ G P = ⇒ G P Y Y = ⇒ G P Then string graph rewrite rule sK , (cid:32) sS , from above (which is induced by B ) can be matched into thestring graph H , and the DPO rewrite yields the string graph P , . In this way, our framework soundlymodels equational reasoning with families of string diagrams. Related work.
B-ESG rewrite patterns are similar to the pair grammars approach presented in [13]. Inthat paper the author defines a pair of graph grammars whose productions are in bijection which moreoverpreserves the nonterminals within them. As a result, parallel derivations are defined in a similar way to ourB-ESG rewrite patterns. However, the author uses a different notion of grammar which is less expressivethan ours.The pair grammars approach has inspired the development of triple graph grammars [16]. In thisapproach, the author uses a triple of grammars ( L , C , R ) , which also share a bijective correspondencebetween their productions. In this sense, they are similar to our B-ESG rewrite rules. However, themiddle grammar C is used to relate graph elements from L to graph elements of R in a more powerfulway compared to our approach. We simply use the middle grammar in order to identify the interface andinterior elements for performing DPO rewrites. However, the grammar model used in [16] is based onmonotonic single-pushout (SPO) productions with no notion of nonterminal elements. These grammarsare not expressive enough for our purposes.Another way of formalising families of string diagrams is by using !-graphs [5, 11]. !-graphs havea considerably simpler graphical presentation compared to B-ESG grammars. This is the underlyingmechanism which Quantomatic uses for representing families of string diagrams. Unfortunately, !-graphsalso have somewhat limited expressive power. In fact, the original motivation for developing B-ESGgrammars was to address these shortcomings. Detailed comparisons in terms of expressivity of the twoformalisms are available in [17, 8].A third way of representing families of string diagrams is by using a programming language designedto generate such diagrams. Examples include Proto-Quipper-M [15, 10] and EWire [14]. Even thoughthese languages have not been studied in terms of their formal expressive power, it seems very likelythat they both have higher expressive power, but worse decidability properties compared to !-graphs andB-ESG grammars (e.g. the membership problem is unlikely to be decidable). We introduced B-ESG grammars which are slightly extended context-free graph grammars that generatestring graphs and which therefore represent families of string diagrams. We showed that by carefullyrelating the productions of a triple of grammars we are able to correctly represent equational schemas of . Zamdzhiev graphs . More recently, a new representationof string diagrams using hypergraphs has been proposed [1] which has a simpler and more elegantmeta-theory (e.g. no need to quotient wire-vertices on wires) and which also enjoys better categoricalproperties (e.g. adhesivity vs partial adhesivity). As part of future work, we will consider developinga new framework which can represent families of string diagrams using hypergraph grammars , whichalso enjoy better structural and algebraic properties compared to B-edNCE grammars. The crucial ideaspresented in this paper should carry through straightforwardly to the hypergraph setting, but it remains tobe seen whether the hypergraph representation has adequate expressive power in terms of the languages itcan generate.
Acknowledgements.
I would like to thank Aleks Kissinger for many fruitful discussions and also forhis supervision of my PhD studies, during which time these results were discovered. I also thank my otherformer supervisors, Samson Abramsky and Bob Coecke, for providing excellent advice during this time.
References [1] F. Bonchi, F. Gadducci, A. Kissinger, P. Soboci´nski & F. Zanasi (2016):
Rewriting Modulo SymmetricMonoidal Structure . LICS ’16, doi:10.1145/2933575.2935316.[2] F. Bonchi, P. Sobocinski & F. Zanasi (2015):
Full Abstraction for Signal Flow Graphs . In:
POPL 2015 ,doi:10.1145/2676726.2676993.[3] Ross Duncan & Simon Perdrix (2009):
Graph States and the Necessity of Euler Decomposition . In:
Mathe-matical Theory and Computational Practice , doi:10.1007/978-3-642-03073-4_18.[4] J. Engelfriet & G. Rozenberg (1997):
Node Replacement Graph Grammars . In Grzegorz Rozenberg, ed-itor:
Handbook of Graph Grammars and Computing by Graph Transformations, Volume 1: Foundations ,doi:10.1142/9789812384720_0001.[5] A. Kissinger, A. Merry & M. Soloviev (2012):
Pattern graph rewrite systems . In: 8th International Workshopon
Developments in Computational Models , doi:10.4204/EPTCS.143.5.[6] A. Kissinger & V. Zamdzhiev (2015):
Equational Reasoning with Context-Free Families of String Diagrams .In:
Graph Transformation - 8th International Conference, ICGT 2015 , doi:10.1007/978-3-319-21145-9_9.[7] Aleks Kissinger (2012):
Pictures of Processes: Automated Graph Rewriting for Monoidal Categories andApplications to Quantum Computing . PhD thesis. Oxford University. http://arxiv.org/abs/1203.0202 .[8] Aleks Kissinger & Vladimir Zamdzhiev (2015): !-graphs with trivial overlap are context-free . In:
ProceedingsGraphs as Models, GaM 2015, London, UK, 11-12 April 2015. , doi:10.4204/EPTCS.181.2.[9] Aleks Kissinger & Vladimir Zamdzhiev (2015):
Quantomatic: A Proof Assistant for Diagrammatic Reasoning .In:
CADE 2015 , doi:10.1007/978-3-319-21401-6_22.[10] Bert Lindenhovius, Michael Mislove & Vladimir Zamdzhiev (2018):
Enriching a Linear/Non-linear LambdaCalculus: A Programming Language for String Diagrams . In:
LICS 2018 , doi:10.1145/3209108.3209196.[11] A. Merry (2014):
Reasoning with !-Graphs . DPhil Thesis, University of Oxford, http://arxiv.org/abs/1403.7828 .[12] J. Meseguer & U. Montanari (1988):
Petri Nets Are Monoids: A New Algebraic Foundation for Net Theory .In:
LICS 1988 , doi:10.1109/LICS.1988.5114. A Framework for Rewriting Families of String Diagrams [13] Terrence W. Pratt (1971):
Pair grammars, graph languages and string-to-graph translations . Journal ofComputer and System Sciences
Classical Control and Quantum Circuits in Enriched Category Theory . Electr. Notes Theor. Comput. Sci.
A categorical model for a quantum circuit description language . In:
QPL 2017. , doi:10.4204/EPTCS.266.11.[16] Andy Schürr (1995):
Specification of graph translators with triple graph grammars . In:
Graph-TheoreticConcepts in Computer Science , doi:10.1007/3-540-59071-4_45.[17] V. Zamdzhiev (2016):
Rewriting context-free families of string diagrams . Ph.D. thesis, University of Oxford.Available at https://ora.ox.ac.uk/objects/uuid:4138e2fe-5382-429b-a3f6-67f8770e2cd3https://ora.ox.ac.uk/objects/uuid:4138e2fe-5382-429b-a3f6-67f8770e2cd3