Completeness of the ZH-calculus

There are various gate sets used for describing quantum computation. A particularly popular one consists of Clifford gates and arbitrary single-qubit phase gates. Computations in this gate set can be elegantly described by the ZX-calculus, a graphical language for a class of string diagrams describing linear maps between qubits. The ZX-calculus has proven useful in a variety of areas of quantum information, but is less suitable for reasoning about operations outside its natural gate set such as multi-linear Boolean operations like the Toffoli gate. In this paper we study the ZH-calculus, an alternative graphical language of string diagrams that does allow straightforward encoding of Toffoli gates and other more complicated Boolean logic circuits. We find a set of simple rewrite rules for this calculus and show it is complete with respect to matrices over $\mathbb{Z}[\frac12]$, which correspond to the approximately universal Toffoli+Hadamard gateset. Furthermore, we construct an extended version of the ZH-calculus that is complete with respect to matrices over any ring $R$ where $1+1$ is not a zero-divisor.


Introduction
Graphical calculi give us a compact way to express and reason about complex, interacting processes using string diagrams. String diagrams represent processes that can compose in sequence or parallel using a notation consisting of boxes or nodes connected by wires. Notably, wires can be left 'open' at one or both ends to indicate inputs and outputs of the composed process. For example, depicting sequential composition as • and parallel composition as ⊗, we can translate expressions such as the following one into a string diagram: Such notation has proven convenient for expressing compositions and tensor products of linear maps (as used extensively in quantum theory), and more generally for expressing morphisms in a generic symmetric monoidal category. A graphical calculus is both a collection of graphical building-blocks and a collection of equations between string diagrams that we can use to transform one diagram into another, typically equivalent, one. One of the best-studied graphical calculi is the ZX-calculus [11,12,14,44], which has been applied extensively in the study of quantum circuits and related structures in quantum computation (e.g. measurement-based quantum computing [6,19,31], fault-tolerant quantum computations [18,24,28], error-correcting codes [10], circuit optimisation [20,22,32], and classical simulation [33,35]). ZX-diagrams consist of spiders, a type of well-behaved linear map that is depicted by coloured dots: Quantum circuits lie at the heart of the circuit model of quantum computation, which represents the quantum part of the computation as a large unitary operator arising from compositions and tensor products of basic gates [41]. There are many choices of basic gates which are universal, in the sense that they can construct or approximate arbitrary 2 n × 2 n unitary matrices. A popular choice is the Clifford+phase set of gates: This set of gates is universal, here in the sense that it can exactly express any unitary matrix. A common finite restriction of this infinite set is the Clifford+T gate set, which replaces Z α with T := Z π/4 . This set of gates is able to approximate any unitary up to arbitrary finite precision. A further restriction to the Clifford gate set (CNOT, H, S := T 2 ) is no longer universal, and in fact yields only circuits that can be efficiently simulated on a classical computer [1]. Nevertheless, Clifford circuits play an important role in quantum computation [41], quantum error correction [7,23,25], and many quantum communication protocols.
Notably, these three important families of circuits map straightforwardly to three fragments of the ZX-calculus: where parameters are restricted to integer multiples of π 2 (Clifford), restricted to integer multiples of π 4 (Clifford+T), or are unrestricted (Clifford+phase). Furthermore, each of these fragments of the ZX-calculus has been proven complete in the sense that two ZX-diagrams which evaluate to the same linear operator are provably equal using just diagram rewrite rules [4,29,40].
However, the ZX-calculus remains closely tied to the structure of the Clifford+phase family of circuits. The further one gets from this family, the more awkward it becomes to work with computations using the ZX-calculus. For instance, the CNOT gate ('controlled-NOT') can be expressed quite simply in the ZX-calculus:

= CNOT
In contrast, the 'controlled-controlled-NOT', commonly referred to as the Toffoli gate, is considerably more complicated, with typical presentations requiring many more generators which cannot be easily manipulated using the ZX-calculus rules [14,Ex. 12.10].
The problem with the Toffoli gate is that it acts on basis states in a manner that is not Z 2 -affine. For example, the Boolean CNOT is the map CNOT : {0, 1} 2 → {0, 1} 2 given by CNOT(x, y) = (x, x ⊕ y), where ⊕ denotes XOR. Such a Boolean function is called affine, in analogy to the theory of polynomials, since it only contains terms of multiplicative degree at most 1 that are then added together (XOR acts as addition on the field Z 2 ). Similarly, we say the NOT gate N OT (x) = x ⊕ 1 is affine, since again it is a sum of terms of degree at most 1. In the ZX-calculus there are two main types of generators: Z-spiders and X-spiders. Both of these are closely related to affine Boolean functions: the Z-spider is based on the COPY Boolean map COPY(x) = (x, x), while the X-spider is based on XOR. As being affine is baked into the generators, some tricks are required to represent non-affine Boolean functions in the ZX-calculus, such as the Toffoli gate TOF(x, y, z) = (x, y, (x · y) ⊕ z) that contains the degree-2 term x · y.
The way we solve this issue in this paper is by introducing a third diagrammatic type of generator beyond the Z and X spiders: the H-box. An n-input 0-output H-box is defined by |x 1 · · · x n ⟩ → (−1) x1·...·xn . This can then be used in combination with Z-spiders (i.e. copy maps) to represent the 'controlled-controlled-Z' gate, and thus the Toffoli gate.
Another way to view the H-box generator is as a generalisation of the Hadamard gate to a linear map with an arbitrary number of inputs and outputs.
With this new generator comes a new set of graphical rewrite rules that allow us to reason more efficiently about quantum computation involving non-affine Boolean functions. The resulting graphical language is called the ZH-calculus, since its main generators are Z-spiders and H-boxes. The main topic of this paper is to show that various fragments of the ZH-calculus are complete. Specifically, we find a set of particularly simple and compelling rewrite rules (see Figure 1) that are complete for the approximately universal Toffoli-Hadamard gate set. 1 Arguably, this is the smallest complete rule set for an approximately universal fragment of quantum computing (we discuss this claim in more detail in Section 2.3). Building on this work, we show that for any ring where 2 := 1 + 1 is not a zero divisor, we can generalise the ZH-calculus in order to express all matrices over this ring, and we exhibit a complete set of rules for this generalisation as well.
This article is based on a conference paper by Backens and Kissinger [5] which first introduced the ZH-calculus and proved completeness for the ZH-calculus with complex parameters, an unpublished preprint of van de Wetering and Wolffs [45] which proved completeness for the phase-free fragment of the calculus, and the DPhil thesis of Miller-Bakewell [39] which showed how the ZHcalculus and its completeness could be extended to arbitrary rings. The formal developments in those papers have been expanded and unified, and the technical content has been extended significantly in three ways: we find a simpler complete rule set for the phase-free fragment, we give a completely self-contained proof of phase-free completeness based on an encoding of arithmetic into ZH, and we extend the ZH-calculus to any ring where 2 := 1 + 1 is not a zero divisor.

Related work
In the earliest complete version of the ZX-calculus, a new generator, the 'triangle', was introduced in order to represent non-affine Boolean functions [40]. This has later also been used to prove completeness of the fragment corresponding to the Toffoli+Hadamard gate set that we also study [47], as well as to find an axiomatisation of the ZX-calculus over arbitrary rings [52]. In [16], a complete ruleset for classical circuits, i.e. natural number matrices, was found which uses almost the same ruleset as we do in the phase-free fragment. The difference is that [16] treats the AND gate as an atomic non-symmetric generator, while we decompose it into H-boxes. 2 The seminal complete graphical language for the related fragment of integer matrices is the ZW-calculus [26] which has generators based on the two different types of entanglement that are possible in tripartite qubit systems [13]. The related language ring R [39] was designed to unify the study of qubit graphical calculi parameterised by phase rings, and indeed both parameterised ZH (Section 7) and the interpretation of ZH as operations on Boolean functions (Section 2.3) fit into this scheme. Therefore there are natural maps from ring B to ZH and from ring R to ZH R , the second of which is exhibited in [39]. Note that [9] shows that, under certain assumptions, there are only three basic graphical calculi for qubits: ZX, ZW, and ZH. The results presented in the current paper prove that the youngest of these calculi, ZH, is complete, concluding the program of finding complete graphical calculi for qubits.
Using the ZH-calculus, an efficient description of hypergraph states can be given [37], which allows for a description of ZH-diagrams in terms of path-sums [2,49,51]. There is also a close connection between ZH-diagrams and quantum multiple-valued decision diagrams [50]. The ZHcalculus has been used to give a graphical description of AKLT states, a particularly canonical type of condensed matter system [17], and of spin-networks [21].

Overview of the paper and structure of the main proof
In Section 2 we introduce the ZH-calculus. We present and motivate the rewrite rules and we introduce the notation we will use throughout the paper (the rules can be found in Figure 1, their Boolean counterparts that motivate them can be found in Figure 2). Note that in particular, in subsection 2.5, we define 'labelled H-boxes', which are derived generators that form an essential ingredient to our proof of completeness of the ZH-calculus.
The majority of the paper, Sections 3-6, is devoted to this proof of completeness. First, in Section 3, we prove several special cases of three families of equations that lie at the core of our completeness proof. These families are called 'multiply', 'intro', and 'average' (see, respectively, (M a,b ), (I a ) and (A a,b )) and apply to labelled H-boxes.
contain only real numbers. However, such real unitaries can simulate with constant overhead unitaries with complex entries [43]. The notion of approximate universality is here hence different than that of Clifford+T , and might better be called 'computationally universal'. We will however not make this technical distinction in the remainder of the paper.
Then, in Section 4, we introduce normal form diagrams. A normal form diagram corresponds in a precise way to the matrix the diagram represents, and hence is unique for a given underlying linear map. Given two diagrams representing the same linear map, the ability to reduce both of them to normal form then shows that they can be transformed into the same diagram, and hence that the calculus is complete. In this section, we give a proof that the reduction to normal form can be done conditional on having proved all instances of multiply, intro and average. This conditional proof works by showing that each generator can be transformed into normal form (Lemmas 4.5 and 4.20), that a tensor product of normal forms can be reduced to normal form (Corollary 4.12), and that connecting any of the wires in a normal form results in a diagram that can again be brought to normal form (Corollary 4.19). With these steps and the condition, any diagram can be brought into normal form (Proposition 4.21). It remains to prove all instances of multiply, intro and average.
In Section 5, we prove that we can do basic arithmetic on the labels of H-boxes: addition of H-box labels in Proposition 5.10, and multiplication of H-box labels (which is exactly the general multiply rule) in Proposition 5.16. Then, in Section 6, we give proofs of the general average rule (Proposition 6.2) and general intro rule (Proposition 6.4). Together with the conditional reduction to normal form, this finishes our proof of completeness (Theorem 6.5). The reason we structured the proof like this, starting with a conditional proof of the reduction to normal form, is because some of the proofs in Sections 5 and 6 use this reduction to normal form (with a careful analysis that shows the required instances of average, intro and multiply were all proved in Section 3), since we could not find a more direct way to prove them.
In Section 7, we shift to studying the ZH-calculus over arbitrary rings. We prove its completeness by assuming the multiply, intro, and average rules as axioms. Then in Section 8, we study a couple of modifications to the calculus and its rules. We end with some concluding remarks in Section 9.

The ZH-calculus
The ZH-calculus is a graphical language for expressing maps with zero or more inputs and outputs as certain string diagrams called ZH-diagrams. As a convention, we will draw inputs as wires entering the bottom of the diagram and outputs as wires exiting the top.
Throughout this paper, we will distinguish formal ZH-diagrams D : m → n with m input wires and n output wires, from their standard interpretation as linear maps D : (C 2 ) ⊗m → (C 2 ) ⊗n , where (C 2 ) ⊗m ∼ = C 2 m is the m-fold tensor product of the 2D vector space C 2 . Remark 2.1. In categorical terms, ZH-diagrams are morphisms in the free PROP ZH presented by the ZH-calculus, considered as a symmetric monoidal category, and − is a strong monoidal functor from ZH to (Vect C , ⊗), the category of finite-dimensional complex vector spaces, with the monoidal product given by the tensor product. Though familiarity with symmetric monoidal categories and PROPs is not required to read this paper, the interested reader can find an accessible introduction in Chapter 2 of [53].

The generators
ZH-diagrams have three types of generators: Z-spiders represented by white dots, H-boxes represented by white boxes, and a star generator represented by . These generators are interpreted as linear maps on copies of C 2 . We denote the standard (also called computational) basis of C 2 in Dirac notation as: We will be using this Dirac 'ket' notation |ψ⟩ to denote a state in a vector space. We will also denote the 'bra' ⟨ψ| for the linear map that calculates the inner product with |ψ⟩. That is, inputting a state |ϕ⟩ gives ⟨ψ| (|ϕ⟩) = ⟨ψ|ϕ⟩. The computational basis states |0⟩ and |1⟩ extend naturally to a basis for (C 2 ) ⊗n by interpreting bitstrings as tensor products: |x 1 . . . x n ⟩ := |x 1 ⟩ ⊗ · · · ⊗ |x n ⟩ We can define the interpretation of Z-spiders and H-boxes in terms of these basis states. Zspiders and H-boxes can have any number of inputs and outputs, and are then interpreted as the following linear maps: where · denotes the map from diagrams to matrices. The sum in the second equation is over all i 1 , . . . , i m , j 1 , . . . , j n ∈ {0, 1} so that an H-box represents a matrix with all entries equal to 1, except the bottom right element, which is −1.
Finally we have the generator star, which has zero inputs and outputs. Its interpretation is: Straight and curved wires have the following interpretations: When two diagrams are juxtaposed, the corresponding linear map is the tensor product (a.k.a. Kronecker product) of the matrices corresponding to the individual diagrams. A sequential composition of two diagrams is interpreted as the matrix product of the matrices corresponding to the individual diagrams: Some diagram motifs appear so often that we create shorthands for them, called derived generators. We define the derived grey spider and the grey spider with a NOT as: The generator acts as XOR on the computational basis while ¬ acts as NOT: In some of the later sections there will be diagrams with many NOTs. To avoid overcrowding, we will draw a red dashed edge for an edge between Z-spiders with a NOT on it: We also introduce the derived negate spider (a white NOT): The negate white spider with one input and output acts like the Z gate:

The rules
The ZH-calculus comes with a set of rewrite rules shown in Figure 1. Of the 8 rules in Figure 1, 7 are 'obvious' in the sense that they express simple properties of the structure of the underlying Boolean functions (see Section 2.3). The only outlier is (o) which seems more arbitrary. In Section 8.1 we will see that we can replace (o) with two smaller rules. Additionally, the calculus has the meta-rule that only topology matters. This means that two diagrams are considered equal when one can be topologically deformed into the other, while respecting the order of the inputs and outputs. Finally, the two generators are considered to be symmetric and undirected, so that the following equations also hold: Proof. It is straightforward to check that the symmetry properties for each generator and the finite rules of Figure 3 are sound by concrete calculation. (ba 1 ) and (ba 2 ) can both be reduced to a finite set of equations for which soundness is easily checked and from which the general infinite family of rules can be derived using induction (see for instance [14,Theorem 9.71]). The rules (zs) and (hs) express equations related to Frobenius algebras for which soundness can also be checked in a standard manner, see for instance [15]. Soundness of the meta rule 'only topology matters' follows by considering the string diagrams as morphisms in a compact closed category [42]. ■ The converse to soundness is completeness. Determining that the ZH-calculus is complete will be the main objective of this paper. A third important property of diagrammatic languages is universality. It can be seen from the definitions of the generators that their interpretations as linear maps are all matrices over Z[ 1 2 ], and therefore all ⊗-and •-products of the generators also have interpretations as matrices over Z[ 1 2 ]. Universality means that we can represent any matrix over Z[ 1 2 ] using the ZH-calculus. We cannot prove this property yet, but it will follow immediately from Theorem 4.4. These matrices, and hence the ZH-calculus, are closely related to the approximately universal gate set Toffoli+Hadamard [3]. We discuss the precise connection in more detail in Section 8.4.

Motivation for the rewrite rules
Let us give some motivation for the rewrite rules of Figure 1. Each of the three main (derived) generators of the ZH-calculus, the Z-spiders, X-spiders and H-boxes, corresponds to a family of Boolean functions. Using this correspondence, each of the rules of Figure 1 can be seen to be equivalent to an equation that holds between Boolean functions.
In order to make this correspondence, we first recall that we can lift a Boolean function f : {0, 1} n → {0, 1} m to a linear mapf : C 2 n → C 2 m by its action on the computational basis states: Define the COPY family of Boolean functions COPY n : {0, 1} → {0, 1} n by COPY(x) = (x, . . . , x). Then COPY n is equal as a linear map to the Z-spider with a single input and n outputs. Similarly, the X-spider with n inputs and a single output is equal to XOR n , while the single input, single output NOT generator is, unsurprisingly, equal to NOT.
Seeing this, one might wonder why we simply did not choose some other generator that can represent the AND directly. The reason for this is that it is in fact useful to represent the inputs and outputs of AND asymmetrically.
Indeed, the COPY and XOR maps are symmetric under interchange of the inputs and outputs, a property also known as flexsymmetry [8]: This property is not true for AND: . . . . . .
We can now re-express the rules of Figure 1 with all the generators presented as Boolean functions, as shown in Figure 2  of Figure 1 when we translate the Boolean functions back into the generators according to (5). The other three are not equal, but can be proven to be equivalent using the first five equations (which we will do below), and hence the two rulesets are equivalent. For the representation of (o) we introduce two new Boolean 'predicates': Recall that the linear map corresponding to the cap is ⟨00| + ⟨11|, and hence we can interpret IS-EQUAL as selecting for the case where both inputs are equal to one another. Similarly IS-0 is just ⟨0| and selects for its input to be 0. Let us demonstrate how the rules of Figure 2 suffice to prove the rules of Figure 1. We will ignore scalar factors for these derivations (correct scalars can be introduced by repeated use of Lemma 2.3). First, let us derive (ba 1 ) from its Boolean counterpart. We denote the usage of the 'Boolean version' of (ba 1 ) by ( The converse proofs that the rules of Figure 1 imply those of Figure 2 are similar (and will also implicitly follow from completeness of the ZH-calculus). Looking at Figure 2 we see that (zs) and (hs) express the associativity of COPY, respectively AND, and that (id) and (hh) express the triviality of COPY and AND when they have only a single input. We see that the only difference between (ba 1 ) and (ba 2 ) is which Boolean function comes before the COPY. These rules are in fact special cases of the rule that any Boolean function copies through COPY [14,Prop. 8.19]. The rule (m) expresses that NOT is self-inverse, and finally there is (o), which requires some more explanation. On both sides of the equation, the middle input is copied and sent to both AND gates, but one of the copies is negated. Hence the output of at least one of the AND gates will be zero, so that the only way for the outputs of these AND gates to be equal is if they are both zero. This is the property that (o) expresses. As this is still not a particularly concise motivation, we present in Section 8.1 an alternative pair of rules that can replace (o) and which do have a more concise motivation.
It might be surprising that this rule set expressing identities about Boolean functions suffices to reason about quantum computation. However, what is not apparent from this rule set is that the AND gate is 'broken up' into two parts, given by the H-boxes and the Hadamard. The Hadamard gives the 'Fourier transform' between the Z and X spiders and relates the COPY and XOR maps in a way that does not follow easily from their definition as Boolean functions. In fact, in [16], a calculus for integer matrices is presented using XOR, COPY and AND as generators, and which uses a rule set that is essentially the same as that of Figure 2, but with (o) replaced by the rules we present in Section 8.1. Hence, the difference between this 'classical' calculus and our 'quantum' calculus is the usage of the Hadamard and the necessity of negative numbers this requires.
Beyond having a nice interpretation in terms of Boolean identities, our rule set is furthermore arguably preferable to that of other (approximately) universal complete graphical calculi for qubits in terms of simplicity. This is because: 1. It only requires a small number of rules (8, of which one is actually superfluous, cf. Section 8.2).
2. Each of these rules only involve a few (derived) generators.

3.
A priori, the set of generators does not involve any further information, such as a label taken from a ring or group.
Accepted in Compositionality on 2022-11-07. Click on the title to verify.

4.
As a result, no rule involves a 'side condition' on the elements of the ring or group.
While there are other calculi that satisfy items 1) and 2) -notably ZX π/4 [29], universal ZX [46], ring [39], and ZQ [38] also only require a small number of rules -each of these requires either a complicated side condition on at least one the rules, or directly encodes properties of the underlying ring in its generators. Other calculi like ZW [26] and ∆ZX [47] also do not have a lot of rules, but many of them lack a clear interpretation.
This is of course not to say that those calculi are 'worse', but just that the ZH-calculus has a particularly elegant set of rewrite rules, which somehow neatly capture the complexity of quantum computing.

Basic derived rules
In this section we will prove some basic but useful rewrite rules that we will use throughout the paper. Since the statements and proofs are often very short we will state all the lemmas first and then all the proofs. Lemmas 2.3-2.8 are different ways to cancel or simplify scalar diagrams. Lemmas 2.9-2.14 are various ways to simplify the derived generators. Lemmas 2.15-2.20 and 2.29 give ways to commute Z's, NOTs and Hadamards through the other generators. Lemmas 2.21-2.28 govern the interaction of states with generators (mostly showing that many states can copy through a generator), and finally Lemma 2.30 is the Hopf rule that holds between the Z and X spider. While some of these lemmas are direct special cases of the rules, in particular of (ba 1 ) and (ba 2 ), we include them here for convenience of reference, and to give a more complete set of 'state commutation' rules. Note that for Lemma 2.15, if m = 0, then instead of the 's, there is a single ; similarly for Lemma 2.16, if m = 0, then instead of the 's, there is a single .
Proof of Lemma 2.11. Proof of Lemma 2.17. Proof of Lemma 2.28.

Labelled H-boxes
The matrix corresponding to an H-box is filled with 1's, except for the bottom right position where there is a −1. Calculating the matrix of some other diagrams in the ZH-calculus, we see that their matrix is similar, but instead of a −1 in the bottom right corner there is some other number a ∈ Z. In order to make this connection clearer, we introduce some new notation, where we write an H-box with a label of a inside it, to denote it is equal to a vector of 1's with an a in the bottom position. When talking about labelled H-boxes in text, we will often write H(a) to denote we are referring to an H-box labelled by a (leaving the arity implicit, which should be clear from context).
We begin with H-boxes of arity 1, corresponding to vectors ( 1 a ), which we will define inductively for non-negative integers using a 'successor' gadget; H-boxes labelled by negative integers will then be defined from the positive ones using a 'negate' gadget.  and for any a ∈ Z such that a ≥ 0, define: Accepted in Compositionality on 2022-11-07. Click on the title to verify.
The 'successor gadget' used in this definition might appear a bit strange. As a matrix, it is in fact equal to the previously considered triangle generator in the ZX-calculus [40,47]: This triangle has the following interpretation as a matrix: We could have introduced the triangle as an additional derived generator. However, as can be seen from its matrix, it is not self-adjoint and hence the orientation of the node matters. To avoid the complications that come from that, we elect not to use the triangle and to simply write out its form as a ZH-diagram as in (10).
is not the only H-box with a particularly simple representation. Indeed, we have Definition 2.32. For any a ∈ Z such that a < −1, we define the corresponding degree-1 H-box by applying a negate spider: The negation gadget plays nicely with the H-box labels. In particular by Lemma 2.14, H-box labels satisfy −(−a) = a. We also have consistency with the simpler representations of H(a) for a ∈ {−1, 0, 1}:

2.5
Definition 2.33. Labelled H-boxes of arbitrary arity are defined as: This is consistent with (hh) for arity-1 H-boxes of arbitrary label (using Lemma 2.3). Certain higher-arity H-boxes have relatively simple label-free forms, in particular, for the −1labelled H-box we have: Accepted in Compositionality on 2022-11-07. Click on the title to verify.
for the 0-labelled H-box we have: for the 1-labelled H-box we have: and for the 2-labelled H-box we have: There are some scalar cancellation rules associated to these labelled H-boxes:

!-box notation
Many of the calculations in the remainder of the paper are greatly simplified by the use of !-box notation [34]. A !-box (pronounced 'bang box') in a string diagram represents a part of the diagram that is able to fan out arbitrarily. That is, the contents of a !-box, along with any wires into or out of the !-box, can be copied n times for any non-negative integer n. For example, the !-box diagram below represents the following family of (concrete) string diagrams, one for each n: All of the resulting string diagrams are well-defined because all of our generators can have arbitrary arities. We can also use !-boxes in diagram equations, as long as each !-box on the LHS has a corresponding !-box on the RHS, and the inputs/outputs in each !-box match. Such a rule represents a family of equations where each pair of corresponding !-boxes is replicated n times, e.g. we can re-express (17) as: Note the dashed box on the right-hand side of the first equation denotes an empty diagram. With this notation, the definition of grey spiders (1) becomes Additionally, the rules (zs), (hs), (ba 1 ), and (ba 2 ) from Figure 1 become: Note that the red dashed NOT-edges defined in (2) behave well when crossing !-box borders.

Annotated !-boxes
Many of our diagrams -in particular the normal forms that will be defined in Section 4.1 -have a repeating structure involving multiple H-boxes with different labels. To write such diagrams more concisely, we introduce a limited extension of the usual !-box notation, which allows !-boxes to be indexed by the elements of a totally ordered finite set. Standard !-boxes allow infinite families of diagrams to be represented in a single diagram, whereas annotated !-boxes simply offer a more concise representation of a single diagram with repeated structure, instantiated once for each element of the finite set.
Definition 2.37. An annotated !-box is a !-box with a label of the form 'x ∈ X', where X is a totally ordered finite set and x is a variable that may appear in labels inside the !-box.
In the following, we will use a large box labelled D x to denote an arbitrary ZH-diagram whose labels may contain the parameter x. Given a diagram containing an annotated !-box, we recursively define an equivalent diagram without the annotated !-box. The base case is that of a !-box indexed over the empty set, which is instantiated zero times: For the recursive case, X is non-empty. Thus it has a maximum element, which we denote m := max X. We construct an equivalent diagram where the !-box is indexed by the smaller set X \ {m}. This is done by copying the contents of the !-box (including all external wires) once, immediately to the right of the !-box, and replacing each occurrence of x inside the new subdiagram by m: Remark 2.38. This definition straightforwardly extends to diagrams containing multiple disjoint annotated !-boxes, which is all we need in this paper.
It can also be applied in reverse: any time a diagram contains multiple copies of the same subdiagram, up to changes in labels, these can be combined into an annotated !-box.
We will often use bit strings for indexing annotated !-boxes; the motivation for this will become clear with the introduction of normal-form diagrams in Section 4.1. As an example, indexing over the finite set B 2 := {00, 01, 10, 11}, we can write expressions such as: Since annotated !-boxes correspond to unique diagrams (rather than infinite families of diagrams), their appearance in equations is less constrained than that of unlabelled !-boxes. Nevertheless, some care is needed if the annotated !-boxes contain inputs or outputs of the diagram as a whole.
The simplest such equations correspond directly to allowed equations for unlabelled !-boxes: they have corresponding annotated !-boxes on the LHS and RHS, which are both indexed by the same finite set. Inputs and outputs coming out of a labelled !-box are matched to those of the same index on the other side of the equality. For example: If an annotated !-box contains diagram inputs or outputs, it must either have a corresponding annotated !-box on the other side of the equality, or it must match a !-box labelled by a sub-or superset (possibly the empty set) as in (20). This is to avoid complications caused by the need to keep the order of external wires consistent. For annotated !-boxes that do not contain any diagram inputs or outputs, such ordering issues do not arise because of the meta rule 'only topology matters'. Lemmas 2.39 and 2.40 below give examples of diagram equations where the annotated !-boxes on the two sides do not match in the same strict way.
Note that we can recover the behaviour of normal, un-labelled !-boxes by interpreting a !-box without a label as being indexed by an arbitrary totally ordered finite set, e.g.
x ∈ X (for any totally ordered finite sets X and Y ) In particular, this means that any derived rewrite rule involving un-labelled !-boxes can also be applied to annotated !-boxes with arbitrary labels.
Lemma 2.39. An annotated !-box indexed by a bit string can be 'expanded' according to one of the bits, as long as it does not contain any inputs or outputs of the diagram as a whole. Here, the box labelled D ⃗ b denotes an arbitrary diagram parameterised by ⃗ b.
Proof. Note that the set B n can be split into two pieces, based on whether the most significant bit is 0 or 1: The result therefore follows by completely expanding the annotated !-boxes on each side according to Definition 2.37 and applying the meta-rule 'only topology matters'. ■ Lemma 2.40. An annotated !-box containing two disconnected diagram components can be split into two boxes indexed over the same set, as long as the original annotated !-box does not contain any inputs or outputs of the diagram as a whole. Here, X is an arbitrary totally ordered finite set and the boxes labelled D x and D ′ x denote arbitrary diagrams parameterised by x.
Accepted in Compositionality on 2022-11-07. Click on the title to verify.
Proof. Note that for any set X, The result therefore follows follows from Definition 2.37 and the meta-rule 'only topology matters'. ■ The condition about annotated !-boxes in Lemmas 2.39 and 2.40 not containing any inputs or outputs of the diagram as a whole is to avoid issues caused by the need to keep the order of external wires consistent. We have drawn the contents of the annotated !-boxes as being connected only to Zspiders, since this covers all our applications. Nevertheless, the result generalises straightforwardly to X-spiders and H-boxes as well.
The following notation will be useful when working with annotated !-boxes.
Proof. This follows immediately from Lemma 2.19 via Definition 2.41. ■

Special cases of multiply, intro and average
Now that we have all the necessary definitions and basic rewrite rules, we can start our proof of completeness. We will proceed as outlined in Section 1.2, first introducing three families of rewrite rules that use the labelled H-boxes of Section 2.5, which will play an important part in proving completeness. Proving that these rewrite rules hold in full generality is difficult however. In this section we will only prove these rewrite rules for certain small integers. The general proofs are postponed until Section 6, after we have introduced and studied the normal form diagrams in Section 4. Note that starting from here, we will no longer necessarily write all the lemmas used in a rewrite step in a proof. In particular, we will often suppress uses of Lemma 2.3 and just treat and as each other's inverses. We will often also let uses of spider fusion (zs) be implicit.

The multiply rule
We claim that the following identity holds in the ZH-calculus for all integers a and b: We refer to this as the multiply rule. Proving this is quite involved and will be postponed until Section 5. The usefulness of this rule comes from the following generalisation to arbitrary arity. Proof.
This states that if two labelled H-boxes are connected to exactly the same set of white spiders that we can fuse the H-boxes together by multiplying their labels. For certain small values of b we can easily prove this rule.

The intro rule
A second family of rules that is particularly useful is the following: We refer to this as the intro rule as it allows us to introduce new wires to an H-box. As is the case for the multiply rule, this rule has a generalisation to arbitrary arity. But unlike the multiply rule, it will often be useful to apply the rule multiple times in succession to connect it to a larger set of wires.

Lemma 3.3.
If the ZH-calculus proves I a , then it also proves the following !-boxed version 3 . The natural numbers m and n are arbitrary, but note that the annotated !-box depends on n.
Proof. First, let us prove the following equation: Now, we prove the claim by induction on n, beginning with the base case where n = 1. Note that n = 0 is valid but trivial. In the derivation below we use a !-box to show that m is arbitrary.
For the inductive step, assume the lemma holds for n copies of the lower white node. In the calculation below, (*) denotes the induction step. (zs)

zs)
Accepted in Compositionality on 2022-11-07. Click on the title to verify.

a a a
This corresponds to the outer product as will become clear from the normal form definition in Section 4.1.
We will prove that the intro rule holds for all integers in Section 6. But first we will directly prove the intro rule for certain simple integers. To do this we will need two lemmas.

The average rule
The final family of rewrite rules we will need is the following.
We call this rule the average rule, because on the right-hand side it adds the numbers together, but also multiplies it with a 'NOT 2' H-box, that acts like multiplying by a half; cf. Lemma 8.7. We will prove that this rule holds for all integers in Section 6. For now, we will prove it for certain combinations of integers.
Lemma 3.8. If the ZH-calculus proves (A a,b ), then it also proves the following:

Normal forms
Our completeness proof relies on showing that every diagram can be reduced to a certain unique normal form. In this section we will introduce this normal form, and establish a strategy for reducing diagrams to normal form. This strategy requires that we have proven the multiply, intro, and average rule for all integers. Hence, this section results in a completeness proof that is 'conditional' on the multiply, intro, and average rule being provable in the ZH-calculus for all integers.

Normal form diagrams
Our normal form diagrams will be 'state-like' in that all of the wires will be connected to the top of the diagram. This is because we can convert between states and operators by simply bending inputs to become outputs and vice versa. This transforming of an operator into a state is known as map-state duality or the Choi-Jamio lkowski isomorphism.
A key part of this normal form, is that we can easily represent the Schur product of two states, i.e. the pointwise product, in the ZH-calculus. For states ψ, ϕ, write ψ * ϕ for their Schur product. Then representing states by large white boxes we have the following identity: Here the i-th output of ψ and ϕ is plugged into a for each i. It follows from (zs) that * is associative and commutative, so we can write k-fold Schur products ψ 1 * ψ 2 * . . . * ψ k without ambiguity. For any finite set J with |J| = k, let j∈J ψ j be the k-fold Schur product.
As shown in the next lemma, the indexing maps ι ⃗ b from Definition 2.41 interact nicely with the Schur product.
where H n (a ⃗ b ) is the arity-n H-box (considered as a state) labelled by some values a ⃗ b for all ⃗ b ∈ B n , and k ∈ N. We say the normal-form is reduced when either k = 0 or at least one of the labels a ⃗ b cannot be factored by two (i.e. is odd).
A normal form diagram can be seen as a collection of n spiders, fanning out to 2 n H-boxes, each with a distinct configuration of NOT's corresponding to the 2 n bitstrings in B n , together with a global scalar. Diagrammatically, normal forms are: Note that the number of outputs in a normal form diagram is the same as the exponent of B in the !-box annotation. To avoid cluttering the notation too much, we will only rarely make this explicit in diagrams.
The additional condition for being reduced ensures uniqueness of normal form diagrams.
Proof. The map ι ⃗ b is a permutation that acts on computational basis elements as |⃗ c⟩ → ⃗ c ⊕ ⃗ b ⊕ ⃗ 1 .
In particular, it sends the basis element ⃗ 1 to ⃗ b . Hence ι ⃗ b • H n (a ⃗ b ) is a vector with a ⃗ b in the ⃗ b-th component and 1 everywhere else. The Schur product of all such vectors indeed gives the RHS of (25) up to the global scalar of 1 2 k that is added by k . So now suppose two different normal form diagrams have equal interpretation (25). We need to show that the diagrams are then equal, which boils down to showing k = k ′ and The left-hand side is an integer, and so the right-hand side must be so as well. Hence, if k < k ′ , then all the a ′ ⃗ b must be divisible by 2, which contradicts the assumption of being a reduced normal form (since in this case k ′ ̸ = 0). Hence, k = k ′ , and hence a ⃗ b = a ′ ⃗ b as required. ■ Because reduced normal forms are unique, two diagrams in reduced normal form are equal if and only if the linear maps the diagrams represent are equal, and hence, the calculus is complete if we can bring all diagrams to reduced normal form.
Some simple diagrams can readily be brought to reduced normal form: Before we continue to the more general procedure to reduce diagrams to normal form we have to prove some results about how to deal with scalars and factors of 2 in normal forms in order to reduce the diagram. Lemma 4.8. Given integers a ⃗ b for which we have proven (M 2,a ⃗ b ) we can prove:

Conditional reduction to normal form
For bigger diagrams we will show that if a part of the diagram is in normal form, we can 'consume' the rest of the diagram generator by generator to write the entire diagram into normal form. This procedure requires that we have proven the multiply, average and intro rule for all integers. Since this is difficult to do, we will first show the general procedure for bringing a diagram to normal form assuming we have proven these identities. We will then be able to 'bootstrap' the proof for the general multiply, average and intro rule using the simple cases of these rules we have already proven.
We need to show that any generator of the ZH-calculus -H-boxes, Z-spiders, and any type of wiring -can be brought to normal form, that tensor products of normal forms can be brought to normal form, and that any diagram consisting of a normal form composed with a generator in some way can also be brought to normal form. Once we have this we know that any ZH-diagram can be brought to normal form, and hence, if two ZH-diagrams represent the same linear map they must then be equal to the same ZH-diagram. Proof. Starting from the left-hand side, which we expand using the indexed !-box notation, we calculate: The last diagram is a normal form diagram with n + 1 outputs, i.e. the desired result. ■ The most difficult step is to show that contraction with a white dot preserves normal forms. This requires a couple of lemmas.
First, we present a more general form of the (o) rule that allows us to disconnect wires in a more general way. In practice, Lemma 4.13 is usually applied in diagrams that are close to normal form, so that the H-boxes are connected to multiple white spiders. This allows the lemma to be applied multiple times in succession. Example 4.14. Consider the following derivation, which will arise in the proof of Proposition 6.2. For each rewrite step, the parts of the diagram that are uninvolved have been greyed out to clarify the process.
In the first application of Lemma 4.13, the top leftmost spider is the important one. The rewrite step splits the bottom spider to separate the first H-box from the others, as the first H-box is the only one that is connected to the leftmost spider via an X node:  . . .
Proof. If n = 1, the !-boxes on both sides are indexed over the one-element set, so the result follows straightforwardly from the definition of annotated !-boxes in Section 2.7 and removal of the white spider via (id). Note that there are zero stars in this case.
For n > 1, by Lemma 2.39, we can equivalently express the LHS as We can then apply Lemma 4.13 to split the bottom spider in two: By Lemma 2.40, we can then split the !-box into two parts, indexed over the same set to obtain: We now have two copies of a graph which is very similar to the LHS of (26), but for one fewer bit. We can thus repeat the process above to split each of the two spiders using the second bit of the bitstring, then the third, and so on, until -spiders only connect pairs of H-spiders that disagree on the least significant bit.
Each application of Lemma 4.13 introduces a star, so we need to count how many times that lemma is used in total. For the first bit of B n−1 , the lemma is applied once. Afterwards, the diagram has separated into two indexed !-boxes and Lemma 4.13 needs to be applied to each part. Continuing in this way, the number of !-boxes which need to be split doubles in each step. Hence we introduce 1 + 2 + . . . + 2 n−2 = 2 n−1 − 1 stars.
Note that at the end of this process, each !-box will be indexed over a one-element set, so according to the definition of annotated !-boxes we can simply drop them. By replacing 2-legged -spiders with cups using (id), and applying the definition of annotated !-boxes to re-introduce indexing over B n−1 , we obtain the RHS of (26). ■ Lemma 4.16. For any a ⃗ b we have . . .
Proof. First, we introduce a scalar H (2) and get this in the !-box using Lemma 3.3 (the !-boxed form of the Intro rule): . . .

NF ′
Proof. Starting from an arbitrary normal form, with a plugged into the right most output, we first expand the annotated !-box: Now the diagram is ready for application of Lemma 4.15, followed by the average rule: This diagram can now be brought to normal form by application of Lemma 4.16. Note the stars exactly cancel the white dots introduced by that lemma. ■ Our strategy will now be to show that any diagram can be decomposed into H-boxes, combined via the operations of extension, convolution, and contraction. This will give our completeness proof.
To simplify the decomposition of diagrams into H-boxes, we prove a few corollaries.
Proof. Applying a to a pair of outputs has the same result as convolving with a cup, then contracting one of the outputs. That is, we can decompose (27)  We can decompose any Z-spider with n ≥ 2 incident wires as a tensor product of (n − 1) cups, with each cup -ed with its neighbours: = · · · · · · (zs) If n = 2, no are needed and the equality is by (id) instead of (zs). In either case, the diagram can be brought into normal form by applying To assist in this, let us prove a few lemmas that will help reduce diagrams to normal form when we have these rules for certain values of a and b. As we already have many individual cases of those rules -see Lemma 3.2 for (M a,b ) and Lemma 3.7 for (I a ), as well as Section 3.3 for (A a,b ) -these lemmas can already be applied to many diagrams.
. . . 2 n − 1 Accepted in Compositionality on 2022-11-07. Click on the title to verify. A a 0⃗ c ,a 1⃗ c and A a 0⃗ c ,−a 1⃗

If we also have
Proof. We start by manipulating the !-boxes and layout, and then perform the rewriting: . . .
The following lemma allows us to (dis)connect integer-labelled H-boxes that are connected to a superset of a given 0-labelled H-box.
Proof. The proof is analogous to that of Lemma 4.22, using Lemma 4.23 instead of (M −1,a 1⃗ c ). ■

Arithmetic
In this section we show we can do simple arithmetic with labelled H-boxes. Namely we will show first that the following equation holds for all integers a and b.
Hence, we can add H-box labels together. This will be crucial for when we will prove the general average rule in Section 6. Secondly, we will prove the multiply rule for all integers.

Proving addition for natural numbers
First we will prove (28) for natural numbers, which requires showing that (28) acts as expected when b = 1, and that furthermore the 'addition gadget' of (28) is associative. For this we need a couple of lemmas. The next lemma, while looking deceptively simple, has a quite involved proof, requiring repeated use of Lemma 4.13. It was found by translating both sides to normal form, and then simplifying the intermediate steps.

Proving addition for all integers
To generalise addition to arbitrary integers, we need two more lemmas.  This lemma actually only shows that the successor operation has a one-sided inverse. But by conjugating the top and bottom using a negate spider, we see that this is in fact a two-sided inverse.

Proving multiplication
In this section we will show that the multiply rule introduced in Section 3.1 holds for all integers: It is in any case clear that this operation is commutative, associative and the unit is the 1-labelled H-box. To prove that this indeed acts as multiplication it then suffices to prove it distributes over addition, which requires a bit of set-up to prove.
For the step denoted (*), note that Proof. For n = 0 this is straightforward. We prove by induction, so assume it holds for some n.
In the calculation below we denote the induction step by (*). and similarly for b, so the multiplication reduces to that of non-negative numbers. If there are two copies of ¬ , they cancel by Lemma 2.14. ■

Completeness
We write ZH ⊢ D 1 = D 2 when D 1 and D 2 can be proven to be equal using the rules of the ZH-calculus. The ZH-calculus is complete when In Proposition 4.21, a 'conditional' completeness result was proven, that shows that if the ZHcalculus can prove the average, intro and multiply rule for all integers, then the ZH-calculus is complete. Proposition 5.16 shows that the multiply rule holds for all integers, so that it remains to prove the intro and average rule. That is what we will do in this section.
First, we will establish the average rule. Proof. It suffices to show that: As then Accepted in Compositionality on 2022-11-07. Click on the title to verify. For the RHS of (30), first recall that we can bring the X-spider to normal form using Lemma 6.1, and hence: Again, this is a normal form diagram, this time with a 000 = a 001 = 2, a 011 = −1, a 100 = a 101 = 0 and a 010 = a 110 = a 111 = 1. Now we apply the first part of Lemma 4.22 (note the changes due to the H-box being on the third output): We have a ⃗ c0 = ±a ⃗ c1 for all ⃗ c ∈ B 2 , so the two H-boxes in each copy of the !-box contain either equal or opposite integers. By Lemma 3.7 we have (I a ) for all a ∈ {−1, 0, 1, 2}, so we can use Lemma 3.10. Thus, Up to a partial transpose, this sequence of rewriting steps corresponds to Combining everything and bending back the legs, we find

This is the same as the RHS. ■
It now remains to prove (I a ) for all integers a. We can reduce this problem to proving it for natural numbers using the following lemma. Proof. We bend all the wires up for a more easy presentation. The proof is then straightforward: Because we have (I −1 ) (Lemma 3.7), we get (I −a ) if we have (I a ). ■ Proposition 6.4. The ZH-calculus proves (I a ) for all integers a.
Proof. By the previous lemma it suffices to prove (I n ) for all natural numbers. Note that we have (I 0 ) and (I 1 ) so that by induction it suffices to show that we can get (I n+1 ) out of (I n ). We will show that: This is sufficient because then: For the final step, note that the coefficients a ⃗ cbd of the normal-form diagram are ±1, indeed a 0101 = a 0111 = a 1101 = a 1111 = −1 and a ⃗ cbd = 1 otherwise. We have (I 1 ) and (I −1 ) by Lemma 3.7. Thus we can use the first equalities from Lemmas 3.10 and 3.11. This transformation corresponds to For each ⃗ c and b, we have z ⃗ cb0 = ±z ⃗ cb1 , and by Lemma 3.7 we have (I 0 ), (I 1 ) and (I −1 ). Hence we can again apply the first part of Lemma 4.22, followed by the first equalities of Lemmas 3.10 and 3.11.
Note that x ⃗ cb0 x ⃗ cb1 = 0 for all ⃗ cb, so we use the same process for the final 0-labelled H-box.

The ZH-calculus over arbitrary rings
The ZH-calculus as defined above represents matrices over Z[ 1 2 ]. To handle these efficiently, we introduced integer labels on H-boxes. In this section, we extend this idea: we allow H-boxes to be labelled a priori by elements of some ring R. As a result, diagrams can express matrices in R-bit, the full subcategory of R-modules where the objects are of the form (R ⊕ R) ⊗n . This means our diagrams are interpreted as matrices of shape 2 n × 2 m with entries in R. The conditions on R and the ways in which we show completeness will be the core of this section. We will dub this new calculus ZH R , or 'ZH over R', with the original phase-free calculus simply called 'ZH' without a subscript. The ruleset of ZH R will be a strict superset of the rules of Figure 1, and hence anything we have already proven for ZH will remain true in ZH R .
The original ZH-calculus as introduced in [5] represented matrices over the complex numbers, and hence in our notation is called ZH C . The utility of ZH C is that it can describe evolutions of qubits. This does not need to be the only useful choice of ring: The ZW-calculus is similarly parametrised by a commutative ring [27], and this flexibility is what allowed for the proof of completeness for Clifford+T ZX via ZW Z[ 1 2 ] [29] 5 . We will show that we can make ZH R sound, complete, and universal into R-bit provided that R is commutative with 1 ̸ = 0, and the element 2 is not a zero-divisor. Unitarity of the ring is required so that we can preserve the interpretation of the generator, which uses 0 and 1. Commutativity of R is required because we require the following isometry of diagrams to be sound: The condition on the element 2 is needed since otherwise we would no longer have a welldefined relationship allowing us to go between white spiders and grey spiders as in (NOT) and (X). Likewise we would no longer be able to freely introduce pairs of Hadamard gates via the (hh) rule. These relationships are so important that we exclude the case where 2 is a zero-divisor from this paper and leave it to future work.
We will first deal with the case where 1 2 ∈ R in Section 7.1, and afterwards we will adapt the results to work when 1 2 ̸ ∈ R in Section 7.2. When 1 2 ∈ R we will show that is equal to the H( 1 2 ) box with no inputs or outputs, and hence the generator is superfluous. The completeness result for when 1 2 ∈ R uses the rules given in Figure 3, which are a superset of the rules given in Figure 1. If the ring R does not contain 1 2 but does contain 2, which is not a zero-divisor, then the ring R[ 1 2 ] is well defined. We can then use the completeness of ZH R[ 1 2 ] and the introduction of a meta-rule to eliminate all instances of the generator to give completeness of ZH R for 1 2 / ∈ R. Note that the ZH-calculus as introduced in Section 2 is not the same as ZH R for any R, since in the ZH-calculus the labels are from Z but the interpretation is into Z[ 1 2 ]-bit.

ZH-calculus over rings with a half
In this section we will take R to be a commutative unital ring that contains 1 2 (and so 2 is not a zero-divisor). We generalise the labelled H-boxes of Section 2.5 by letting the H-boxes in ZH R be labelled by any element r ∈ R: . . . r . . . . . , j n ∈ {0, 1} so that the H-box above represents a matrix with all entries equal to 1, except the bottom right element, which is r. If the label is −1 (so that it matches the usual H-box of Section 2.1) we will usually leave out the label. Besides these more general H-boxes, the other generators are identical to those found in Section 2.1. Note that because 1 2 ∈ R, the star generator is redundant: We will derive the corresponding diagrammatic equality later in Lemma 7.9. We could therefore use just the following generators when 1 2 ∈ R: . . .
But in order to retain compatibility with the previous results, we will continue to write to represent the scalar 1 2 . As before, we define the grey spiders and NOT gate of (1) as derived generators. With these generators and derived generators established we can state our theorem of universality.
Theorem 7.1. The calculus ZH R is universal over R-bit, shown using the unique normal form diagram: Proof. The equation above was demonstrated in the proof of Theorem 4.4. The lack of stars in this version comes from noting that every element in R is divisible by 2 (as 1 2 ∈ R) and so stars are always subsumed into the ring elements a ⃗ b in the reduced normal form. ■ Now let us establish our ruleset for the ZH-calculus over R. The rules for ZH R are given in Figure 3 along with the same 'only topology matters' meta rule and all the same symmetry conditions as before:

=
Here, a ∈ R is arbitrary. In comparison to the rules of Figure 1, (HS) has been generalised from (hs) to allow arbitrary labelled H-boxes and (U) has been added to relate the white dot to an H-box labelled by the 1 element of the ring. The rules (M), (A) and (I) already appeared in Section 3 as (M a,b ), (I a ) and (A a,b ), but there they were derived rules that applied to integer labelled H-boxes, while here they are axioms that relate the ring elements of R. Note that it is not immediately obvious that the Z-labelled H-boxes of Section 2.5 correspond to the R-labelled H-boxes of the ZH R -calculus. We will prove this imminently, though first we observe the soundness of ZH R .    With these equivalences established, we will now use induction to show that the labelled Hboxes in ZH are equivalent (using the rules of ZH R ) to the corresponding H-boxes in ZH R . Proposition 7.8. All the integer labelled H-boxes of the ZH-calculus (Section 2.5) are provably equal in ZH R to the corresponding labelled H-box in the ZH R -calculus.
Proof. We will denote a labelled ZH H-box of Section 2.5 by H(n ′ ) to distinguish it from a generator of the ZH R -calculus. We have for every n ∈ {1, 2, 3, . . . } ⊂ R: Here the induction step is denoted by (*). Note that we first used the average rule as an axiom of ZH R acting on the generators (written (A)), and then as a derived rule from the original ZHcalculus (Proposition 6.2). For negative integers we simply note that the definition of negation (13) corresponds precisely to multiplying by −1 in (M).
These rules enable us to multiply scalars at will, and in particular eliminate scalars by multiplying by the inverse (when the inverse exists in R). Finally we will prove that the star generator is equal to the scalar 1 2 in ZH R . With the correspondence to the standard ZH-calculus now firmly established, we can easily adapt our previous results to prove that ZH R is complete. Theorem 7.10. Let R be a commutative unital ring with 1 2 ∈ R. Then the ZH R -calculus is complete, i.e. for any ZH R -diagrams D 1 and D 2 , if D 1 = D 2 , then D 1 can be transformed into D 2 using the rules of Figure 3.
Proof. As the rules of Figure 3 are a superset of those of Figure 1, anything we have proven for ZH remains provable in ZH R . We have also shown in Proposition 7.8 that all the labelled (ZH) H-boxes used in the completeness proof are equivalent to their ZH R -calculus counterparts. In particular, the reduction to normal form conditional on having proved (M a,b ), (I a ) and (A a,b ) of Section 4.2 remains valid. But now, instead of having to prove the multiplication, introduction and average rules, we have them assumed as axioms. Thus, we can transform any ZH R -diagram into reduced normal form, and hence the calculus is complete. ■

The ZH-calculus over rings without a half
The ZH R -calculus when R does not contain a half is slightly trickier to deal with. As before, we will assume that R is a commutative unital ring. But instead of assuming that 1 2 ∈ R, we will merely assume that 2 is not a zero-divisor.
With these conditions, R embeds faithfully into R[ 1 2 ], and so ZH R as defined in Section 7.1 has a non-universal interpretation into R[ 1 2 ]-bit. We could then add the generator creating a universal interpretation into R[ 1 2 ]-bit. This is essentially the process one follows to go from ZH Z to our 'phase-free' ZH, but also raises the question of 'why not just start with ZH R[ 1 2 ] instead?' We present in this subsection a definition of ZH R , with 1 2 / ∈ R, that is universal for R-bit and is complete using the same rules as ZH R when 1 2 ∈ R, with the exception of an additional 'scalar cancellation' meta-rule.
Since we want to have an interpretation into R-bit we will no longer be able to use the generator, which in turn makes the definition of the derived generators (X) and (NOT) invalid. Instead we will promote the grey spiders from being derived generators to, simply, generators. Hence, our list of generators becomes: The ruleset of the ZH R -calculus when 1 2 ̸ ∈ R consists of the rules of Figure 3, where now the grey spiders are considered to be actual generators, and the usual symmetries of the generators. In addition, as the grey spiders are now no longer defined in terms of the other generators, we introduce the following rules to relate the generators to one another, which are scaled versions of the definitions of the grey spiders (1) · · · · · · · · · (2NOT) Finally, we will also need the following cancellation meta-rule to get completeness when 1 2 / ∈ R:

Replacing the (o) rule
Of all the basic rules of the ZH-calculus in Figure 1 the ortho rule (o) seems a bit out of place. In this section we will see that we can replace it with two other rules, namely Lemmas 2.28 and 5.1. These two rules can be rephrased as statements about the AND gate. Namely, up to some simple rewriting, Lemma 2.28 says that if we post-select the AND gate with ⟨1| that this post-selection copies through: Lemma 5.1 can be rephrased as stating that a COPY gate followed by an AND gate applied to its outputs is just the identity: Lemmas 2.28 and 5.1 show that these two rules can be proved by the basic ZH-calculus rules including (o). In this section we will show the converse: that assuming just the rules of Figure 1 except for (o), together with the Lemmas 2.28 and 5.1 we can prove (o). Note that all the basic lemmas of Section 2.4 are proven without the usage of (o) (except for Lemma 2.28), and hence can be used in this section.
Before proving (o), we need to prove a number of lemmas that are essentially statements in Boolean logic.  Proof. The proof of Lemmas 2.28 and 5.1 shows the forward direction: that the standard ruleset of the ZH-calculus, including (o), implies the two lemmas. For the converse direction, recall that the only one of the basic derived rules in Section 2.4 whose proof required (o) was Lemma 2.28, which is now one of our axioms. Note that we have proven Lemma 8.5 using just Lemma 5.1, ZHcalculus axioms other than (o), and the basic derived rules. Proving (o) from Lemma 8.5, other ZH axioms, and basic derived rules will therefore give the desired result. To make the application of intermediate rules clearer, we re-arrange the diagrams of (o) so the wire which is usually an output is now the middle input instead:

The (hh) rule is not necessary
It turns out that (hh) can actually be derived from the other rules. Before proving this, since the proof of Lemma 2.3 uses (hh), we will need to find a different way to cancel scalars first. The following turns out to suffice: The fact that we can derive (hh) from the other rules raises the question whether any other rules are also not necessary. We hypothesise that they are in fact all needed. It is at least the case that (zs) and (hh) are necessary: they are the only rules that relate higher-arity spiders, respectively H-boxes, to lower arity ones (this argument can be formalised by presenting alternative interpretations into linear maps that change what higher-arity spiders/H-boxes correspond to). (id) is also necessary as it is the only rule that relates a generator to the identity wire. At least one of (ba 1 ) and (ba 2 ) is necessary as they are the only ones that relate an empty diagram to a non-empty diagram (the n = m = 0 case). We do not know of any argument for the necessity of the other rules (m) and (o), although it seems likely that they are both necessary.

Merging the intro and average rule
The intro rule (I) and the average rule (A) can be subsumed by a single larger rule. Before we present this rule, let us first present an alternative to (A) that holds when the ring contains a half. Lemma 8.7. Let R be a ring with a half. In the presence of the other rules in Figure 3, (A) is equivalent in ZH R to the following rule: Proof. As the LHS of (A) agrees with the LHS of (37), it suffices to show that the RHS of both are equal. Note first that: ). Let R be a ring with a half. In the presence of the other rules of Figure 3, the combination of the rules (I) and (A) is equivalent to the following rule: Proof. As the ZH R -calculus is complete with the rules presented in Figure 3, and (39) is easily shown to be sound for any a and b, the equation (39) can be proven using (I) and (A) for any particular choice of a and b. Alternatively, by using the ZH-calculus over the polynomial ring in two variables R [a, b], there is also a proof of it using the variables a and b directly. It hence remains to show that (39) together with ( Figure 3) \ {(A), (I)} implies both (I) and (A). We will first prove (37). By plugging a white dot into the top wire of (39) we get this, except for a scalar factor that will be shown to cancel afterwards: Hence, (40) and (41)   We can now apply the argument of Lemma 8.7 to get (A). ■

ZH-calculus as a complete language for Toffoli+Hadamard circuits
The ZH-calculus presented in Section 2 is universal and complete for matrices over the ring Z[ 1 2 ]. As shown in [3], the unitary matrices over Z[ 1 2 ] correspond to circuits generated by Toffoli and H ⊗ H, or in other words, circuits consisting of Toffoli gates and an even number of Hadamard gates. The reason these matrices, and thus the ZH-calculus, are restricted to an even number of Hadamard gates is because of the normalisation of the individual binary H-boxes: we have = 1 1 1 −1 , which differs from the unitary Hadamard gate by a factor of 1 √ 2 . With all generators being interpreted as matrices over Z[ 1 2 ], a diagram containing an odd number of binary H-boxes can hence not be normalised to be unitary.
We chose to define the interpretation of the generator to be 1 2 , because it led to the simplest possible calculus. By redefining the interpretation of this generator, we can make ZH-diagrams Accepted in Compositionality on 2022-11-07. Click on the title to verify. represent matrices M = ( 1 √ 2 ) n A where A is a matrix over Z, which correspond precisely to the matrices generated by the Toffoli+Hadamard gate set [3]. We do this by redefining the generator to represent 1 √ 2 instead of 1 2 . By replacing every occurrence of by two stars in the definitions of Section 2, and in all the derivations of the preceding sections, all the derivations remain sound under this new interpretation. In particular, the derivation that each diagram can be reduced to normal form remains true. For almost any diagram we can also bring the diagram to reduced normal form, with one class of exceptions: if the diagram represents the zero matrix then the reduced normal form should contain no stars. However, when we reinterpret the star (and thus double the number of occurrences in the rewrite rules) we see that all rewrite rules preserve the parity of the number of stars in the diagram. Hence, the following equality that says that 1 √ 2 ·0 = 0 is not derivable with those rules: Adding this as another rewrite rule solves this edge case and we still get a complete calculus, but now for matrices of the form ( 1 √ 2 ) n A where A only contains integers.

Conclusion
We studied the ZH-calculus, a graphical language for reasoning about qubit quantum computing.
We found a small set of rewrite rules motivated by basic identities between Boolean functions that allowed us to prove completeness of the fragment that corresponds to the Toffoli-Hadamard gateset. We then extended the ZH-calculus so that it can represent matrices over arbitrary rings where 2 is not a zero divisor. We found an extended ruleset that is complete for any such ring. We have argued that our calculus, both the parameter-free one, as well as the one complete over any ring, is the simplest complete graphical calculus for an approximately universal fragment of quantum computing found so far. Of the rules of the ZH-calculus as presented in Figure 1, we showed that (hh) is actually not necessary, as it can be proven from the others. We believe that the rest are all necessary for completeness. In Section 8.1 we showed that (o) can be replaced by two smaller and simpler to understand rules. It might perhaps be possible to show that only one of these suffices, which would give us a simpler axiomatisation. For the ZH R -calculus we required a meta-rule to cancel scalars when 1 2 ̸ ∈ R. It is not clear at the moment whether the calculus is complete without this meta-rule. The phase-free calculus with its translation to Boolean functions elucidates the relationship between classical computation and universal quantum computation using the Toffoli-Hadamard gate set. Correspondingly, the ZH-calculus over arbitrary rings should be useful for analysing universal quantum computation with multiply-controlled gates as well as quantum computation or error-correction schemes involving hypergraph states. The Fourier-transform relationship between the ZH-calculus over C and the ZX-calculus [36] also points towards the usefulness of combining the ZX-and ZH-calculus, and translating between them. Indeed, [17] already exhibits a combined calculus called the ZXH-calculus. Whether on its own or in combination with other graphical languages, the ZH-calculus has applications in a broad range of areas of quantum computing.