# Towards a Minimal Stabilizer ZX-calculus

The stabilizer ZX-calculus is a rigorous graphical language for reasoning about quantum mechanics. The language is sound and complete: one can transform a stabilizer ZX-diagram into another one if and only if these two diagrams represent the same quantum evolution or quantum state. We show that the stabilizer ZX-calculus can be simplified, removing unnecessary equations while keeping only the essential axioms which potentially capture fundamental structures of quantum mechanics. We thus give a significantly smaller set of axioms and prove that meta-rules like only the topology matters', colour symmetry' and upside-down symmetry', which were considered as axioms in previous versions of the language, can in fact be derived. In particular, we show that most of the remaining rules of the language are necessary, however leaving as an open question the necessity of two rules. These include, surprisingly, the bialgebra rule, which is an axiomatisation of complementarity, the cornerstone of the ZX-calculus. Furthermore, we show that a weaker ambient category -- a braided autonomous category instead of the usual compact closed category -- is sufficient to recover the topology meta rule.

## Authors

• 5 publications
• 8 publications
• 9 publications
02/21/2020

### PBS-calculus: A Graphical Language for Quantum-Controlled Computations

We introduce the PBS-calculus to represent and reason on quantum computa...
09/06/2021

### Quantum CPOs

We introduce the monoidal closed category qCPO of quantum cpos, whose ob...
10/12/2018

### The rational fragment of the ZX-calculus

We introduce here a new axiomatisation of the rational fragment of the Z...
05/05/2022

### Completeness of Sum-Over-Paths for Toffoli-Hadamard and the Clifford Hierarchy

The "Sum-Over-Paths" formalism is a way to symbolically manipulate linea...
02/22/2021

### Kindergarden quantum mechanics graduates (...or how I learned to stop gluing LEGO together and love the ZX-calculus)

This paper is a spiritual child' of the 2005 lecture notes Kindergarten...
06/22/2020

### Computer Algebra in Physics: The hidden SO(4) symmetry of the hydrogen atom

Pauli first noticed the hidden SO(4) symmetry for the Hydrogen atom in t...
04/09/2020

### Open Diagrams via Coend Calculus

Morphisms in a monoidal category are usually interpreted as processes, a...
##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

The zx

-calculus is a high-level and intuitive graphical language for pure qubit quantum mechanics (QM), based on category theory

[CD11]. It comes with a set of rewrite rules that potentially allow this graphical calculus to be used to replace matrix-based formalisms entirely for certain classes of problems. However, this replacement is only possible without losing deductive power if the zx-calculus is complete for this class of problems, i.e. if any equality that is derivable using matrices can also be derived graphically.

The first fragment of the zx-calculus shown to be complete was the stabilizer zx-calculus [Bac14a]. This fragment consists of the zx-diagrams involving angles which are multiples of only. The fragment of quantum theory that can be represented by stabilizer zx-diagrams is the so-called stabilizer quantum mechanics [Got97]. Stabilizer QM is a non trivial fragment of quantum mechanics which is in fact efficiently classically simulatable [Got98] but which nevertheless exhibits many important quantum properties, like entanglement and non-locality. It is furthermore of central importance in areas such as quantum error correcting codes [NC10] and measurement-based quantum computation [RB01].

A subset of these rules is also complete for the single-qubit Clifford+T group [Bac14b]. Other fragments of the zx-calculus have recently been completed, these include the full Clifford+T fragment [JPV17a] as well as the full zx-calculus [NW17]. Nevertheless, we focus here on the stabilizer zx-calculus because it is the core of the overall language: all the fundamental structures – e.g. the axiomatisation of complementary bases [CD11] – are present in this fragment. The rule sets for larger parts of the formalism include the rules of the stabilizer zx-calculus.

Now that the question of completeness has been resolved, we turn our attention to simplifying the zx-calculus, removing unnecessary equations while keeping only the essential axioms, which potentially capture fundamental structures of quantum mechanics. This process also simplifies the development, and potentially the efficiency, of automated tools for quantum reasoning, e.g. Quantomatic [KMF].

In a preliminary version of this work [BPW17], we gave a set of axioms that is significantly smaller than the usual one, containing just nine explicit rewrite rules. Previous rule sets usually contained about a dozen explicit rules and used the convention that any rule also holds with the colours red and green swapped or with the diagrams flipped upside-down, effectively nearly quadrupling the available set of rewrite rules222Some rules are symmetric under the operations of swapping the colours and/or flipping them upside-down, hence the effective rule set is not quite four times the size of the explicitly-given one.. We showed that the colour symmetric and upside-down versions of the remaining rewrite rules can in fact be derived, so the convention is no longer required.

Here, we extend this work by showing that most of the remaining rules are indeed necessary, i.e. they cannot be derived from the other rules. Yet for two rules, the question of their necessity remains open; this includes the bialgebra rule which formalises the notion of complementary bases and thus plays core role in the language.

Having shown previously that meta-rules like ‘colour symmetry’ and ‘upside-down symmetry’, which were considered as axioms in previous versions of the language, can in fact be derived, we now consider the ‘only the topology matters’ rule, which means that two diagrams represent the same matrix whenever one can be transformed into the other by moving components around without changing their connections. This meta-rule is an essential property of quantum diagrammatic reasoning, and refines the axioms of the ambient compact closed category. Indeed, the axioms of a compact closed category guarantee that two isomorphic diagrams are equivalent [Sel10]. Roughly speaking, the ‘only the topology matters’ meta-rule implies additionally that any two inputs or outputs of a generator can be freely exchanged. We show that a single additional explicit rewrite rule is sufficient to derive the meta-rule ‘only the topology matters’ from the simplified stabilizer zx-calculus together with the axioms of the ambient compact closed category (Section 4.1). More surprisingly, we show that a weaker ambient category is enough, namely a braided autonomous category (Section 4.2). Graphically, this means that 3-dimensional isotopy is enough to derive the ‘only the topology matters’ meta-rule.

A preliminary version of this work has been published in the proceedings of the QPL’16 conference [BPW17]. Soundness and completeness of the simplified zx-calculus are proved in [BPW17], together with the minimality of the scalar axioms (IV) and (ZO). In the present extended version, we prove the necessity of (almost) all the other rules of the language (section 3), and we also consider the simplification of the ambient category (section 4).

## 2 A Simplified Stabilizer zx-calculus

The zx-calculus is a graphical language based on categorical quantum mechanics. The underlying category makes the diagrammatic notation rigorous.

Here, we focus on the stabilizer fragment of the zx-calculus, as that encompasses many important aspects of the full language while also being complete. We introduce first the simplified rule set that forms the core of this paper. The previous version of the calculus will be presented later.

### 2.1 Diagrams and standard interpretation

A diagram of the stabilizer zx-calculus with inputs and outputs is generated by:

scalars-s//spideralpha scalars-s//spiderredalpha
scalars-s//swap scalars-s//Id
scalars-s//cup scalars-s//cap

where , , and is denoted by an empty diagram. Because of their many ‘legs’, red and green dots are often called ‘spiders’.

These components can be combined using the following two operations:

• Spacial composition: for any and , is constructed by placing and side-by-side, to the right of .

• Sequential composition: for any and , is constructed by placing above , connecting the outputs of to the inputs of .

When equal to , the phase angles of the green and red dots may be omitted:

 \tikzfigscalars−s//spiderg:=\tikzfigscalars−s//spidergz\tikzfigscalars−s//spiderr:=\tikzfigscalars−s//spiderrz

With natural numbers as objects and diagrams as morphisms, it is obvious that the underlying category of the stabilizer zx-calculus is a monoidal category.

The standard interpretation of the zx-diagrams associates with any diagram a linear map , where denotes the complex numbers. The interpretation is inductively defined as follows:

For green dots, , and when , is a matrix with columns and rows such that all entries are except the top left one which is and the bottom right one which is , e.g.:

For any , , where and for any , . E.g.,

For example, consider the following diagram:

 \tikzfigscalars//interpretationexample

Its standard interpretation can be found as follows:

 =((10000001)⊗(1001))∘⎛⎜ ⎜ ⎜⎝eiπ4(cos(\nicefracπ4)~{}~{}-isin(\nicefracπ4)-isin(\nicefracπ4)cos(\nicefracπ4))⊗1√2⎛⎜ ⎜ ⎜⎝10010110⎞⎟ ⎟ ⎟⎠⎞⎟ ⎟ ⎟⎠ =eiπ42⎛⎜ ⎜ ⎜⎝10−i0010−i0−i01−i010⎞⎟ ⎟ ⎟⎠

The rules of the underlying category ensure that all the different decompositions of the diagram yield the same interpretation. In terms of category theory, the standard interpretation is a monoidal functor from the category of stabilizer zx-diagrams to the category of finite dimensional Hilbert spaces.

The linear maps that can be represented by stabilizer zx-diagrams correspond to the so-called stabilizer fragment of quantum mechanics [Got97]. Note that zx-diagrams with arbitrary angles (no longer necessarily multiples of ) are universal: for any and any linear map , there exists a diagram such that [CD11]. When restricted to angles that are multiples of , zx-diagrams are approximately universal, i.e. any linear map can approximated to arbitrary accuracy by such a zx-diagram. In this paper, we focus on the core of the zx-calculus formed by the stabilizer zx-diagrams.

### 2.2 The rewrite rules

The zx-calculus is not just a notation: it comes with a set of rewrite rules that allow equalities to be derived entirely graphically. We are considering the stabilizer zx-calculus here because it is the fragment with the smallest complete set of rewrite rules. Complete here means that any equality that can be derived using matrices can also be derived graphically using that set of rewrite rules [Bac14a, Bac15].

We introduce a new, simpler, set of rules for the stabilizer zx-calculus (Figure 1) which consist in 9 axioms, plus the ‘only topology matters’ axiom described below. The set of axioms of Figure 1 is significantly simpler and more compact than the previous versions of the stabilizer ZX-calculus. However we prove in the next section that the set of axioms is complete. In section 3 we prove that most of these axioms are necessary in the sense that they cannot be derived using the other axioms of the language.

In addition to those explicit rules there is also a meta-rule: ‘only the topology matters’ [CD11], which means that two diagrams represent the same matrix whenever one can be transformed into the other by moving components around without changing their connections. E.g.

 \tikzfigscalars−s//capswap =\raisebox4.267913pt\tikzfigscalars−s//capf\tikzfigscalars−s//yanking1 = \tikzfigscalars−s//yangkingline \tikzfigscalars−s//commute1= \tikzfigscalars−s//commute2 \tikzfigscalars−s//bendingnew =\tikzfigscalars−s//nonbending

This rule combines properties of the underlying category with symmetry properties of the diagram components: namely the fact that spiders are symmetric under interchange of any two legs, and that diagram components are invariant under (partial) transpose. The latter is graphically denoted by bending inputs into outputs, or conversely.

### 2.3 Soundness and completeness of the simplified stabilizer zx-calculus

The simplified rule set is shown to be sound and complete in [BPW17]. Both properties are proved by reference to the previous version of the language, shown in Figure 2. This version of the language was set out in [Bac15], where it was also shown to be complete. Its soundness follows from the soundness of the original language as well as the new rules [CD11, Bac15].

Some of the derivations only work within the stabilizer fragment, e.g. the rule (K2) is only derived for .

## 3 On the necessity of the rewrite rules in the simplified set

Ideally, we would like to simplify the set of rewrite rules for the zx-calculus until each remaining rule is necessary, i.e. provably cannot be derived from the others. Yet, while we have necessity proofs for many of the rules in Figure 1, there are still some open questions in this area. Nevertheless, we do have a minimality proof for rules explicitly dealing with scalars.

### 3.1 Minimality of the scalar axioms

The previous version of the zx-calculus as given in Figure 2 had three rules explicitly dedicated to scalars: (SR), (ZO), and (ZS). The former contains no non-scalars, the latter are considered to be ‘about’ scalars because they formalise properties of the zero scalar scalars-s//RZ00pi.

The simplified zx-calculus no longer contains the star node, and it only has two scalar rules: (IV) and (ZO). This set of rules is minimal for scalars in the sense that both of those axioms are necessary [BPW17]. Indeed, the inverse rule (IV) cannot be derived using the other rules of the simplified zx-calculus as it is the only rule which equates an empty diagram and a non empty diagram. The necessity of the zero rule (ZO) is proved using an alternative interpretation of the diagrams, which is sound for all the rules of the language except for the zero rule.

### 3.2 Necessity of other rules

As shown in [DP09, DP14], the Euler decomposition rule (EU) is not derivable from the other rules of the zx-calculus excluding the zero rule (ZO). This means that the Euler decomposition rule is necessary even in the presence of the zero rule: if there was some derivation for (EU) involving (ZO), then the zero scalar scalars//gnpi must appear in at least one diagram of (EU) as scalars//gnpi has no inverse and therefore cannot be cancelled. This argument for the necessity of (EU) also applies to (EU).

###### Lemma 1.

The copy rule (B1) is necessary.

###### Proof.

There is no other rewrite rule in Figure 1 that can transform a diagram with two connected outputs into one with two disconnected outputs. ∎

###### Lemma 2.

The colour change rule (H) is necessary.

###### Proof.

There is no other rewrite rule in Figure 1 that matches red dots of degree four or higher, or red spiders with non-zero phases. ∎

###### Lemma 3.

The spider rule (S1) is necessary.

###### Proof.

There is no other rewrite rule in Figure 1 that can transform a dot of degree four or higher into a diagram containing lower-degree dots. (The rule (H) matches dots of high degree, but only transforms them to dots of the same degree.) ∎

###### Lemma 4.

The rule (S3L) is necessary.

###### Proof.

There is no other rewrite rule in Figure 1 that can transform a wire incident on a node (Hadamard, green dot, or red dot) to a wire not incident on any node. ∎

We have shown that rules (S1), (B1), (EU), (H), (IV), (S3L), and (ZO) are necessary. This leaves (S3R) and (B2). For those rules, we have no conclusive necessity proofs, though we do know that at least one of the two is necessary.

###### Lemma 5.

Either (B2) or (S3R) is necessary.

###### Proof.

Consider an alternative interpretation functor which acts like the usual interpretation functor on green dots, wires, and the empty diagram, but adds complex phases to red dots (depending on their degree) and to Hadamard nodes:

The effect of this interpretation is to add a complex phase to a diagram that depends on the sum of the degrees of the red dots minus the number of Hadamard nodes, all taken modulo 4. It is straightforward to check that most rules in Figure 1 are sound under this interpretation, the exceptions being (B2) and (S3R). ∎

The two parts of (S3) are very similar, so it is understandable that it would be difficult to determine whether they are independent of each other. It is more vexing not to be able to prove whether the bialgebra rule (B2) is necessary. Indeed the bialgebra rule (B2) plays a central role in the language: it is the cornerstone of the axiomatisation of complementary bases. Thus, it would be unexpected for the bialgebra rule to be derivable from the other rules. In fact, the rewrite rules can be modified to make (B2) the only rule that is not sound under , as detailed below in Section 3.3. Yet this comes at the cost of introducing additional scalars in several rules and as a consequence losing the necessity proof for (S3L).

While the bialgebra rule (B2) is at the heart of the characterisation of complementary bases, the interpretation of the (S3R) rule is that the two bases – one characterised by the green dots, the other by the red dots – are inducing the same compact structure. Indeed, each colour is inducing a compact structure, i.e. a pair of a ‘cup’ and a ‘cap’ that satisfy a ‘snake equation’ like in Figure 3. There is no a priori reason that those two compact structures should coincide. Thus, deciding whether (S3R) is necessary is exactly the question of deciding whether the other rules of the language force the compact structures induced by the green and the red dots, respectively, to coincide.

### 3.3 Modified rewrite rules in which the bialgebra law is necessary

The bialgebra rule (B2) can be made necessary while retaining soundness and completeness by modifying two of the other rewrite rules as follows.

Replace (S3) by (S3) and the following rule:

 \tikzfigscalars//S3tilde (1)

 \tikzfigscalars//IVtilde2 (2)

where the right-hand side denotes an empty diagram.

In the resulting rule set, (B2) is the only rule that is not sound under .

The rule replacing (IV) is necessary by the same argument as (IV) itself. Additionally, by Lemma 4, at least one of (S3) and (1) is necessary, but it is unclear whether they both are.

## 4 Simplifying the ambient category

In the previous sections, we have shown how to simplify the explicit rewrite rules of the stabilizer zx-calculus and how to eliminate the colour-swap and upside-down symmetry meta-rules. There is one rule we have not touched, namely the meta-rule ‘only the topology matters’. We now consider how to replace this powerful meta rule with other sets of assumptions based on the graphical axioms for specific categories.

### 4.1 Compact closed category / Isomorphism

The standard route [CD11] for axiomatising graphical properties like ‘only the topology matters’ in a categorical framework is based on compact closed categories [Sel07, Sel10]. Assuming that we work with a compact closed category means assuming that the equations in Figure 3 are satisfied. It additionally implies that arbitrary maps can slide freely along either wire in a crossing. Graphically, this means that any two isomorphic diagrams are equal. It is straightforward to check that all of the above rules are sound for the zx-calculus with the topology rule.

At first sight, it seems like the compact closed structure is significantly less powerful than the topology rule: in particular, working in a compact closed category does not directly imply any symmetry properties for the nodes, like the ability to swap legs or bend inputs into outputs:

 \tikzfigscalars−s//commute1= \tikzfigscalars−s//commute2 \tikzfigscalars−s//bendingnew =\tikzfigscalars−s//nonbending (3)

Nevertheless, it is possible to derive all of these properties using just one more rewrite rule in addition to the ones given in Figure 1, namely:

 \tikzfigscalars//s2red (S2′)

Under the assumption that ‘only the topology matters’, this equation can be derived from (S3). We conjecture that, under the weaker assumption of a compact closed structure, those two rules are independent, although we do not have a proof of this.

###### Theorem 6.

When working in a compact closed category, the rules in Figure 1 together with (S2) are complete for the stabilizer zx-calculus.

###### Proof.

To prove completeness, we first derive all the rewrite rules in Figure 2 one by one. This has additional intricacies compared to the original completeness proof, due to the more restrictive underlying assumptions. The second part is a proof that the topology meta rule – and in particular, the symmetry properties of the nodes – follows from the assumptions. The constituent lemmas of those proofs can be found in Appendix A. ∎

### 4.2 Braided autonomous category / 3D isotopy

In this subsection, we take a less standard approach for making the topology meta rule rigorous: we work in an ambient category which implies only that diagrams which are 3D-isotopic are equal (whereas a compact closed category implies that all isomorphic diagrams are equal). We show that, combined with the other rules of the zx-calculus, 3D-isotopy is enough to recover the ‘only the topology matters’ meta-rule.

3D-isotopy is a natural equivalence of diagrams which can be axiomatised using the Reidemeister moves [Rei32] (see Figure 4), the snake equations (see Figure 3), as well as the property that arbitrary maps can slide freely along either wire in a braiding. In a categorical setting, the Reidemeister move (R2) follows from the invertibility of a braiding, while (R3) follows from the coherence axioms of a braided monoidal category and the naturality of a braiding. Therefore, 3D-isotopy is modelled by a braided autonomous category augmented with the loop axiom (R1) [Sel10], which appears so useful that it is exploited by several graphical languages for quantum information and computation [RV17, JLW16].

The following technicality arises: when the ambient category is braided rather than symmetric, one needs to specify which way the wires cross in each crossing. The only crossing occurring in the rules of the language is in the bialgebra rule (B2), which we transform into the following braided rule (the choice of how the wires cross is arbitrary):

 \tikzfigscalars//b2snewbraid1b (B2′′)
###### Theorem 7.

When working in a braided autonomous category, the rules in Figure 1 with (B2) replaced by (B2), the rule (S2), and the loop rule (R1) are complete for the stabilizer zx-calculus.

###### Proof.

The idea is to prove that the braiding is self inverse, meaning the category we are working in is actually symmetric monoidal:

 \tikzfigscalars//braidselfinvb (4)

The proof of this equation and its constituent lemmas are given in Appendix B.

Once we know we have a symmetric monoidal category, we can show commutativity of green copy and co-copy as well as their colour-swapped versions by Lemmas 50, 51, 52, 53, and 54. Along with (S3), we obtain the symmetry of cap and cup. Therefore, we come back to the situation described in the previous subsection: working in a compact closed category. ∎

## 5 Conclusion and perspectives

The stabilizer zx-calculus has a complete set of rewrite rules, which allow any equality that can be derived using matrices to also be derived graphically. We introduce a simplified but still complete version of the stabilizer zx-calculus with significantly fewer rewrite rules. In particular, many rules obtained from others by swapping colours and/or flipping diagrams upside-down are no longer assumed. Our aim is to minimise the axioms of the language in order to pinpoint the fundamental structures of quantum mechanics, and also simplify the development and the efficiency of automated tools for quantum reasoning, like Quantomatic [KMF].

Among the nine remaining rules of the language, only two are not proved to be necessary, although we know that at least one of them is. The problem of the minimality of the language is left as an open question and can essentially be phrased as follows: do the rules of the language (without the (S3R) rule) force the two compact structures, induced by the red and green generators respectively, to coincide?

The simplified stabilizer zx-calculus can also serve as a backbone for further developments, in particular concerning the full calculus (allowing arbitrary angles). Several rules we showed to be derivable in the stabilizer zx-calculus are also derivable in the full zx-calculus: e.g. (ZS), which is valid for arbitrary angles, and (K1). The derivation of (K2) on the other hand is valid for the stabilizer fragment only. Recently, new rules, including the so-called supplementarity, have been proved to be necessary for the (full) zx-calculus [PW16, JPVW17] and in particular for the -fragment of the zx-calculus, which corresponds to the so called Clifford+T quantum mechanics. Even if supplementarity and (K2) rules can be derived in the stabilizer zx-calculus, a future project is to establish a simple, possibly minimal, set of axioms for the stabilizer zx-calculus which contains the rules known to be necessary for arbitrary angles (like supplementarity or (K2)), while avoiding rules which are in some sense specific to the fragment, e.g. (EU).

The fragment of zx-calculus made of the diagrams involving angles multiple of only, is known to be complete for the real stabilizer quantum mechanics [DP14], which is the basis of a full language for real quantum mechanics [JPV17b]. A perspective is to provide a simplified version of the real stabilizer zx-calculus, in particular considering the rules for which we fail to prove the necessity for the stabilizer zx-calculus.

We have also proved that the meta-rule ‘only the topology matters’ can be derived from the rules of the language together with 3D-isotopy. The latter means that the ambient category is a braided autonomous category which additionally satisfies the Reidemeister rule (R1). We leave as an open question the necessity of the (R1) rule for deriving the topology meta-rule. The emergence of braided categories in this context opens new avenues for considering fermionic quantum mechanics [PP10, DR13].

A future step would be to extend the search for minimal complete rule sets to the Clifford+T fragment [JPV17a] or the full zx-calculus [NW17].

## Acknowledgements

The authors would like to thank Bob Coecke, Ross Duncan, Emmanuel Jeandel, Aleks Kissinger, and Renaud Vilmart for valuable discussions. This research was done while MB was at the School of Mathematics, University of Bristol. QW acknowledges funding from Région Lorraine. MB has received funding from EPSRC via grant EP/L021005/1 and from the European Research Council under the European Union’s Seventh Framework Programme (FP7/2007-2013) ERC grant agreement no. 334828. The paper reflects only the authors’ views and not the views of the ERC or the European Commission. The European Union is not liable for any use that may be made of the information contained therein. No new data were created during this study.

## Appendix A Completeness proof for the zx-calculus in a compact closed category

We prove completeness by showing that the rewrite rules of Figure 2 plus the topology meta rule can be derived from the new rule set, which now consists of the rules in Figure 1, (S2), and the axioms of a dagger compact closed category.

Under the assumption that ‘only the topology matters’, we get the upside-down versions of all rewrite rules effectively free by simply applying cups or caps to all outputs or inputs. In a compact closed category, this is no longer the case, because we no longer have the symmetries of the ‘spiders’ given in (3). Nevertheless, as in [BPW17], we derive the rules in Figure 2 (minus (ZS) and with (SR) replaced by (IV), like in the original completeness proof there) one-by-one, each together with its colour-swapped and upside-down variants, in the order: (H), (S1) & (S3), (B1), (IV), (B2), (S1), (K1), (EU), (K2), (ZO). Afterwards, we show that the symmetries of the ‘spiders’ – swapping or bending of ‘legs’ – can now be derived.

We begin by showing that the Hadamard node is self-inverse. To do this, we first need to derive the colour-swapped version of (S2).

###### Lemma 8.

A green node with one input and one output is equal to the identity using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

###### Proof.

By the compact structure, we have:

 \tikzfigscalars//ruels2prf1=\tikzfigscalars//ruels2prf2=\tikzfigscalars//ruels2prf3=\tikzfigscalars//ruels2prf4=\tikzfigscalars//ruels2prf5

where we also used the rules (S1) and (S3). ∎

Equations (S2) and (5) together with (H) are sufficient to prove the following two lemmas: the self-inverse property of the Hadamard node and the colour-swapped version of the colour-change rule. The proofs are analogous to those in [BPW17].

###### Lemma 9.

The Hadamard node is self-inverse using using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

###### Lemma 10.

The colour-swapped version of (H) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//hswap (7)

The upside-down version of (H) is itself, and similarly for the upside-down version when the colours in (H) are swapped.

Additionally, we can show that the Hadamard node is invariant under transpose.

###### Lemma 11.

The Hadamard node is invariant under transpose using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, i.e.:

###### Proof.

We use (S3), (H), and (6):

The result then follows by the compact structure. ∎

###### Lemma 12.

The upside-down flipped version of (S3) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//inducedcompactstructure−2wireflip (10)
###### Proof.

By Lemma 8, we have:

 \tikzfigscalars//s4proof

where we have used the rules (S1) and (S3), and the compact structure. ∎

###### Lemma 13.

The upside-down flipped version of (S1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//s1slide (11)
###### Proof.

First note that by the rule (S1) we have:

 \tikzfigscalars//copyandcompact

Using these inductively, together with the compact structure, (S3) and (10), we obtain:

 \tikzfigscalars//s1slideprf1=\tikzfigscalars//s1slideprf2=\tikzfigscalars//s1slideprf3=\tikzfigscalars//s1slideprf4=\tikzfigscalars//s1slideprf52=\tikzfigscalars//s1slideprf6

which is the desired result. ∎

###### Lemma 14.

The colour-swapped version of (S1), and its upside-down flipped version can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//rules1red\tikzfigscalars//s1slidered (12)
###### Proof.

This follows immediately from (S1) and (11) via the colour change rule (H) and (6). ∎

Since the colour-swapped version of (S3) already exists in (S3), we need only to prove the colour-swapped upside-down version.

###### Lemma 15.

The flipped upside-down colour-swapped version of (S3) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//s3ruleredflip (13)
###### Proof.

Apply (S2) and (12) to create red dots from the left-hand side of the above:

 \tikzfigscalars//s3ruleredflipproof

The result then follows by (S3) and the compact structure. ∎

###### Lemma 16.

The red-green scalar can be flipped upside-down without changing its value using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//scalarflip (14)
###### Proof.

This follows from (S3) and the spider rules. ∎

A similar property holds for the inverse of the red-green scalar. As a consequence of this, we do not need to worry about the orientation of scalars when deriving the upside-down version of a rewrite rule. Since the upside-down version of the scalar is also its colour-swapped version, the same is true when colour-swapping rewrite rules.

###### Lemma 17.

The colour-swapped version of (B1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//greencopyrule (15)
###### Proof.

This follows immediately from applying Hadamard nodes to all outputs of (B1) by (H), (7), and (6). ∎

###### Lemma 18.

The upside-down version of (B1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//b1ruleflipped (16)
###### Proof.

By (S1), (S3), and (10), the green co-copy map can be turned into a green copy map with curved inputs and outputs. We then find:

 \tikzfigscalars//b1ruleflippedprf1=\tikzfigscalars//b1ruleflippedprf2=\tikzfigscalars//b1ruleflippedprf3=\tikzfigscalars//b1ruleflippedprf4=\tikzfigscalars//b1ruleflippedprf5=\tikzfigscalars//b1ruleflippedprf6

using (S3), (11), (B1), and (12). ∎

###### Lemma 19.

The colour-swapped and flipped upside-down version of (B1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//b1flipswap (17)
###### Proof.

This follows from applying Hadamard nodes to all inputs of (16) via (H), (6), and (7). ∎

While the compact structure allows the removal of twists in cups and caps, it is not immediately clear what to do with a twist in an otherwise straight wire. The following lemma will therefore be useful.

###### Lemma 20.

A sideways loop can be removed using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//swapbend (18)
###### Proof.

By the compact structure, the ‘cup’ at the bottom of the loop can be twisted back on itself. Then:

 \tikzfigscalars//swapbendprf1

using (S3), (10), (11), (5) and the compact structure. ∎

Using (S3), (S1), (13), (12), (B2), (16) and (10), we can now prove the Hopf law. Again, the proof is analogous to that in [BPW17].

###### Lemma 21 (Hopf law).

The Hopf law holds using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, i.e.:

 \tikzfigscalars//hopf (19)

Furthermore, the following Lemmas 22, 23, and 24 follow. In each of these cases, the diagrams required for the proof are the ones given in [BPW17], though the arguments for why one diagram can be transformed into the next may be different, as we are now using the axioms of a compact closed category instead of the topology rule.

###### Lemma 22.

A dot can be decomposed using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//dotdecomp (20)
###### Lemma 23.

The following alternative inverse rule can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//inverserule (IV)
###### Lemma 24.

(B2) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//b2s (21)

We now proceed with deriving colour-swapped versions of known rules.

###### Lemma 25.

The colour-swapped version of (B2) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//b2flip (22)
###### Proof.

This follows immediately from (B2) via (H), (6), and (7). ∎

Flipping (B2) upside-down has the same effect as swapping the colours, so there are only two versions of this rule. Additionally, (S1) can now be proved, along with its colour-swapped version.

###### Lemma 26.

The rule (S1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//s1primeprf1=\tikzfigscalars//s1primeprf5 (23)
###### Lemma 27.

The colour-swapped version of (S1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//s1primeswap (24)
###### Proof.

This follows from (23) via (H), (7), (S3), (10), (13) and (6). ∎

The upside-down version of (S1) is (S1) itself, and the same holds for the colour-swapped version. These results enable the derivation of Lemmas 28 and 29, as well as Corollaries 30 and 31. Where no proofs are given, the diagrams are the same as those in [BPW17].

###### Lemma 28.

The red state with phase is equal to the green state with phase , up to some scalars, using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//piby2trans (25)

Composing with the Hadamard node on both sides of (25), we get:

 \tikzfigscalars//piby2transcolorch (26)
###### Lemma 29.

Using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, the application of a red co-copy map to two green states with phases and yields the red state with zero phase:

 \tikzfigscalars//piby2multiply (27)
###### Corollary 30.

Two green nodes with no inputs or outputs and phases and , respectively, are equal to two copies of the red-green scalar using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//piby2saclarmultiply (28)
###### Corollary 31.

Using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, the scalars in (25) and (26) can be brought to the other side:

 \tikzfigscalars//piby2whitetored (29)
 \tikzfigscalars//piby2redtowhite (30)

Those in turn lead to Lemmas 32, 33, 34, and 35.

###### Lemma 32.

The inner product between a green state of any phase and the red zero-phase effect is equal to the red-green scalar using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//angledelete (31)
###### Lemma 33.

Using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, a green phase shift is equal, up to normalisation, to a loop with a Hadamard in it:

 \tikzfigscalars//anglefreepi (32)
###### Lemma 34.

The green -phase state is copied by the red copy map, up to normalisation, using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//pidotcopy (33)
###### Lemma 35.

(K1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k1 (34)
###### Lemma 36.

The upside-down version of (K1) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k1flip (35)
###### Proof.

By the red spider rule (11), it suffices to prove that

 \tikzfigscalars//k1prf1flip

By (34), (S3) and its upside-down equivalents, the spider rules, and the compact structure, we have:

 \tikzfigscalars//k1prf2flip

The result then follows by induction over the number of inputs and/or outputs. ∎

###### Lemma 37.

The colour-swapped versions of (K1) and its upside-down version can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k1swap (36)
###### Proof.

This follows immediately from (H), (7), and (6). ∎

We now have all the prerequisites for the proof of Lemma 38 and thus Lemmas 39.

###### Lemma 38.

Using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category, the rule (EU) also holds with the signs of the phases flipped:

 \tikzfigscalars//eulertwoform (37)
###### Lemma 39.

(EU) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

###### Lemma 40.

The colour-swapped version of (EU) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

###### Proof.

This follows immediately from (38) via (H), (7), and (6). ∎

The upside-down flipped version of (EU) is just itself.

With the Euler decomposition rule, we can now prove Lemma 41.

###### Lemma 41.

(K2) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k2s (40)

where .

###### Lemma 42.

The upside-down version of (K2) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k2sflip (41)

where .

###### Proof.

By (40), we have:

 \tikzfigscalars//k2sflipproof

using (IV), the -copy rule (34), the red spider rule (12), and (31). ∎

###### Lemma 43.

The colour-swapped versions of (K2) and its upside-down equivalent can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//k2sswap (42)

where .

###### Proof.

These follow immediately from the colour change rule (H), (7), and (6). ∎

The last remaining rule is (ZO), which can now be derived as in [BPW17].

###### Lemma 44.

The colour-swapped and/or flipped upside-down versions of (ZO) can be derived using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//zo1swapflip (43)
###### Proof.

These follow immediately from the colour change rule (H), (7), and (6). ∎

We have now proved all the explicitly-stated rewrite rules of the zx-calculus as contained in Figure 2. It remains to show that the ‘only the topology matters’ meta-rule can be derived from our assumptions.

To do this, we first prove various symmetry properties of dots: they are commutative, i.e. invariant under swapping any two inputs or two outputs, and inputs can be bent into outputs, or conversely.

###### Lemma 45.

The green co-copy map is commutative using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//greencommute (44)
###### Proof.

The obvious rewrite rule for removing a wire crossing is (B2). We rewrite the diagram until that can be applied, using (S2), the spider rules, and the Hopf law (which is used twice, symmetrically). This covers the rewrite steps in the top row. The rule (B2) is applied over the line break.

 \tikzfigscalars//greencommuteprf

We then use the spider rule, the Hopf law again, the upside-down copy law, and (S2) to simplify the diagram again, thus completing the proof. ∎

###### Lemma 46.

The green copy map is commutative using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//greencommuteflip (45)
###### Proof.

We have upside-down versions of all the rules used in the proof of that the green co-copy map is commutative (Lemma 45). That proof can therefore be straightforwardly repeated upside-down. ∎

The colour-swapped versions of the above Lemmas also hold:

###### Lemma 47.

Both the red copy and co-copy maps are commutative using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//redcommuteflipswap (46)
###### Proof.

These follow immediately from applying Hadamard nodes to all inputs and outputs of Lemmas 45 and 46 by the colour-swapped colour change rule (7) and the symmetric structure. ∎

We now show that the distinction between inputs and outputs of dots does not matter. By the spider rules, it suffices to consider ternary dots.

###### Lemma 48.

An input of a green dot can be bent around to become an output using the rules in Figure 1, (S2), and the axioms of a dagger compact closed category:

 \tikzfigscalars//spiderbend (47)
###### Proof.

Use (S3) and the spider rule:

 \tikzfigscalars//spiderbendproof (48)

By commutativity of dots, it does not matter which input is bent. ∎

Similar arguments apply for bending inputs to the left rather than to the right, for bending outputs into inputs (in either direction), and for red rather than green dots.

###### Theorem 49.

The ‘only the topology matters’ rule can be derived from the rewrite rules in Figure 1 together with (S2) and the axioms of a compact closed category.

###### Proof.

The topology rule states that two diagrams are equal if they are isomorphic, i.e. if it is possible to transform one into the other by moving components around while keeping their connections the same.

To show that the topology rule follows from the new set of rewrite rules and the assumption of a compact closed category, we thus need to show that none of the following matter for the interpretation of a diagram:

• the position of nodes in the plane,

• whether a wire is straight or curved,

• whether a wire is an input or an output for a given node, and

• the order in which wires are incident on a given node.

First, note that in graphical calculi for monoidal categories, horizontal distance does not carry information: only the order of components does. Still, using the naturality of the swap map, the horizontal order of internal nodes can be changed, e.g.:

 \tikzfigscalars//horizontal (49)

Similarly, the vertical distance of components does not matter as wires are identity maps and can therefore be arbitrarily long or short. The only situation in which changing the vertical position of a node could cause problems is the following: consider two nodes and and assume there is a wire that is an output of and an input of . That implies that must be further ‘up’ in the diagram than if the wire is to be drawn as a straight line. But by the snake rules, wires may curve, therefore the problem can be resolved as shown in the following example, where the green node is and the red one :

 \tikzfigscalars//vertical (50)

Usually, inputs for the diagram as a whole are found at the top and outputs at the bottom. Additionally, the horizontal order of inputs (or outputs) is used to distinguish them. Nevertheless, if some other identifying decoration is added to input/output vertices, they too can be moved around without loss of information. Thus, the position of nodes in a diagram can be changed at will without changing the interpretation of the diagram, i.e. it is not relevant information.

Next we need to show that the only relevant information about wires is which nodes they connect. By commutativity of dots (Lemmas 45, 46, and 47), the order in which the wires are incident on a node does not matter. Because of the self-transpose property of the Hadamard node (Lemma 11) and the ability to bend inputs of dots into outputs or conversely (Lemma 48), it is not necessary to distinguish whether a wire is an input or an output for a given node. Finally, the snake rules allow curved wires to be straightened or conversely, so the shape of wires does not matter. The only remaining relevant piece of information about a wire is its end nodes.

Components in a diagram can therefore be moved around at will, and wires curved or straightened, without changing the interpretation: i.e. two diagrams that are isomorphic represent the same matrix. ∎

We have shown that all the rewrite rules in Figure 2 along with their colour-swapped and/or upside-down counterparts can be derived from the rules in Figure 1 together with (S2) and the axioms of a compact closed category. Furthermore, we have shown in Theorem 49 that the topology meta rule can also be derived. As the rules of Figure 2 together with the topology meta rule are known to be complete for the stabilizer zx-calculus, this implies that the rules in Figure 1 together with (S2) and the axioms of a compact closed category are also complete for the stabilizer zx-calculus, which is the claim of Theorem 6.

## Appendix B Proofs for zx-calculus in braided autonomous category

First note that we still have the Hopf law (19) as long as we replace the twist and (B2) with their braided versions (R1) and (B2), respectively, in the proof of Lemma 21. Thus, we have a braided version of (B2) and its colour-swapped version:

 \tikzfigscalars//b2braid (51)

Now we can prove the braided commutativity of green co-copy:

###### Lemma 50.

The green co-copy map is braided commutative:

 \tikzfigscalars//greencommutebraid (52)
###### Proof.

The obvious rewrite rule for removing a wire crossing is the braided (B2), i.e, (51). We rewrite the diagram so that can be applied, using (S2), the spider rules, and the Hopf law (which is used twice, symmetrically). This covers the rewrite steps in the top row. (51) is applied over the line break.

 \tikzfigscalars//greencommuteprfbraid

We then use the spider rule, the Hopf law again, the upside-down copy law, and (S2) to simplify the diagram again, thus completing the proof. ∎

###### Lemma 51.

The green copy map is braided commutative:

 \tikzfigscalars//greencommuteflipbraid (53)
###### Proof.

We have upside-down versions of all the rules used in the proof of that the green co-copy map is braided commutative (Lemma 50). That proof can therefore be straightforwardly repeated upside-down. ∎

The colour-swapped versions of the above Lemmas also hold:

###### Lemma 52.

Both the red copy and co-copy maps are braided commutative:

 \centerline\tikzfigscalars//redcommutebraid\tikzfigscalars//redcommuteflipbraid (54)
###### Proof.

These follow immediately from applying Hadamard nodes to all inputs and outputs of Lemmas 50 and 51 by the colour-swapped colour change rule (7) and the symmetric structure. ∎

Once we have the braided commutativity of green co-copy, the inversely braided commutativity can be obtained immediately:

###### Lemma 53.

The green co-copy map is inversely braided commutative:

 \tikzfigscalars//greencommutebraid2 (55)
###### Proof.
 \tikzfigscalars//greencommutebraid2prf

Here we used the inverse property of the braiding and Lemma 50. ∎

As a consequence, we have inversely braided commutativity of green copy, red copy and co-copy.

###### Lemma 54.

The maps of green copy, red copy and co-copy are inversely braided commutative:

 \centerline\tikzfigscalars//greencommuteflipbraid2\tikzfigscalars//redcommuteflipbraid2\tikzfigscalars//redcommutebraid2 (56)

With the 3D isotopy of diagrams in a braided autonomous category, we derive the inversely braided version of (B2).

###### Lemma 55.

The braided bialgebra rule holds with the inverse braiding:

 \tikzfigscalars//b2braid2nd (57)
###### Proof.
 \tikzfigscalars//b2braid2ndprf

We flip the first diagram but keep the linear order of the edges entering and exiting, with respect to the 3D isotopy. Then we use equations (51), (53) and (56). ∎

###### Lemma 56.

The braiding is in fact symmetric.

###### Proof.

Begin by rewriting the diagram until the braided bialgebra rule can be applied, using the Hopf law and the spider rules:

 \tikzfigscalars//braidsymmetry

We then apply the inversely braided bialgebra rule and reverse the initial rewrite steps. ∎