Interacting Quantum Observables: Categorical Algebra and Diagrammatics

This paper has two tightly intertwined aims: (i) To introduce an intuitive and universal graphical calculus for multi-qubit systems, the ZX-calculus, which greatly simplifies derivations in the area of quantum computation and information. (ii) To axiomatise complementarity of quantum observables within a general framework for physical theories in terms of dagger symmetric monoidal categories. We also axiomatize phase shifts within this framework. Using the well-studied canonical correspondence between graphical calculi and symmetric monoidal categories, our results provide a purely graphical formalisation of complementarity for quantum observables. Each individual observable, represented by a commutative special dagger Frobenius algebra, gives rise to an abelian group of phase shifts, which we call the phase group. We also identify a strong form of complementarity, satisfied by the Z and X spin observables, which yields a scaled variant of a bialgebra.


Introduction
Quantum theory is arguably the single most successful scientific theory. While it is now almost a century old, many new results have been discovered by approaching quantum theory from a computational and/or information theoretic perspective, signalling the potential for a quantum information technology revolution. This approach has also led to important progress in more traditional areas of physics, for example, in condensed matter physics and statistical physics, e.g. [4], and it has provided a breath of fresh air for quantum foundations research [7,43,45,72]. Most importantly, this recent wave of progress has clearly shown that much remains to be discovered concerning the quantum world, and how we reason about it.
Since von Neumann's seminal book in 1932, the language in which quantum theory is explained and is understood has been (and still is) that of Hilbert spaces. It is in this language that we understand key quantum mechanical concepts such as observables and complementarity thereof. While quantum information and computation (QIC) has proposed new concepts and paradigms to approach the quantum world, it has not augmented the language of quantum theory accordingly. This is in sharp contrast to the typical practice in computer science, where new perspectives and concepts are tightly intertwined with corresponding high-level language features. To make a blunt analogy, we can think of the Hilbert space formalism, where states mainly boil down to arrays of complex numbers, on the same footing as the arrays of 0's and 1's used during the Stone Age years of computer science. So one may wonder: high-level languages b 1 b 2 . . . b n ∈ B n 'our aim' (c 1 c 2 · · · c n ) T ∈ C n , where B n stands for strings of Booleans {0, 1} and C n for vectors of complex numbers.
A related issue is that of axiomatizing quantum theory. Despite its obvious correctness, as a language to describe quantum theory, the Hilbert space formalism seems somewhat ad hoc from a conceptual perspective. The first to acknowledge this was von Neumann himself, who for this reason denounced his own Hilbert space formalism in 1935 (see [10]), only three years after he published it. There have been many attempts to approach quantum theory in terms of mathematical structures other than Hilbert spaces [22], in the hope that this would enhance conceptual insight, but it is fair to say that none of these have provided a sufficient payoff, if any at all.
The recent advent of QIC has shed significant new light on this issue. None of the axiomatic approaches of the previous century provided an adequate mathematical vehicle for the description of compound systems, even when given the description of individual systems. On the other hand, focusing on compoundness has produced immense progress within QIC. This includes important foundational insights such as the no-cloning theorem [31,77], physical phenomena such as quantum teleportation [8], quantum algorithms such as polynomial time factoring [71] and computational schemes such as measurementbased quantum computing [64]. Historically speaking, it was Schrödinger who emphasized compoundness as early as 1935 [67].
In this paper, we aim to catch two flies at once. We introduce a simple, intuitive, graphical high-level language, in which the atomic primitives correspond to a pair of complementary observables, and we perform an axiomatic analysis of complementarity within the very general framework of symmetric monoidal categories (SMCs). These two are related by the fact that 4 there is a tight correspondence between graphical languages and SMCs [47,69], tracing back to Penrose's work on tensor networks [61].
The diagrammatic notation is intuitive in use, but also formally rigorous (see section 4), and can lead to great simplications in proofs. From a pragmatic point of view, the graphical language provides a compact syntax for manipulating the linear operations which are the basic elements of quantum mechanics, and it can replace more special-purpose notations such as quantum circuits [59] or the measurement calculus for measurement-based quantum computing [30], and unify these in one setting.
From an axiomatic point of view, monoidal categories are the most general mathematical framework where composing systems (cf the tensor product '⊗' in the Hilbert space framework) is a fundamental action-see [17] for a more detailed discussion. Since its inception in [1], formulating quantum mechanics within monoidal categories and developing corresponding diagrammatic languages has become an active area of research.
The bottom line is: crafting a simple intuitive graphical high-level language, on the one hand, and performing an axiomatic study that places the composition of systems at the forefront, on the other hand, are in fact one and the same thing! Our particular focus here is complementarity of quantum observables. In classical physics, all observables are compatible: they admit sharp values at the same time. In contrast, quantum observables are typically incompatible and cannot be assigned sharp values simultaneously. In most axiomatic approaches, incompatibility is a negative property, captured in mathematical terms by the fact that some equality fails to hold: operators that do not commute [44], probabilities that fail to obey Kolmogorov's axioms [63], convex sets that fail to provide a simplex structure [55,56] and lattices that do not enjoy distributivity [11,46].
In this paper, we will take a more constructive stance and study the positive capabilities of a pair of maximally incompatible observables, called complementary or unbiased, and show how these capabilities are exploited in QIC. Doing so will lead to an unexpected connection between quantum computation and the area of Hopf algebras and quantum groups [13,50], where graphical methods have also proved to be very fruitful [73].
Altogether, we obtain a rich theory from rather minimal hypotheses. Many computations with elementary quantum logic gates can be carried out within this theory of interacting observables, as can many algorithms and protocols. To give one very basic example, the fact that the composite of two ∧X-gates is the identity boils down to the graphical derivation: where the dotted area is a purely graphical characterization of complementarity.
In the example above, we reasoned by rewriting: that is, by locally replacing some part of a diagram with a diagram equal to it. This is one of the distinctive methods of equational reasoning in graphical languages. The notion of rewriting as a formal mathematical tool has a long history in computer science (the textbooks [5] and [40] provide detailed references), and the Z X -calculus introduced in this paper has indeed been implemented in a software tool [32]- [34].
Specific physical concepts give rise to specific kinds of equations over diagrams. As the example above shows, complementary observables introduce changes in topology, characterized by disconnecting components between the red and green dots. On the other hand, in the case of compatible observables, connected components can be contracted [23,54]. The following table  5 illustrates this: the green components are defined in terms of one observable, and the red ones in terms of a complementary one.
For both of the depicted interactions, complementarity yields two disconnected components, while for compatible observables connectedness is preserved. This topological distinction has very important implications for the capabilities of complementary observables in quantum informatics. The disconnectedness of the graphical form shows the absence of information flow from one component to the other, a dynamic counterpart to the fact that knowledge of one observable in a pair of complementary observables yields no knowledge of the other observable.
We also provide an axiomatic account of phase shifts relative to an observable. This leads to the mathematical concept of a phase group. Together, our account of complementarity and phase groups provides a universal language for reasoning about multiple two-level systems, or in modern language, qubits. For example, is an important computation in the context of measurement-based quantum computing [65], which in Hilbert space terms would involve computations with 32 × 32 matrices. This example provides a straightforward translation between quantum computational models, transforming a measurement-based configuration into a circuit.
From a mathematical perspective, we formalize observables in terms of algebras: Frobenius algebras, bialgebras, etc. These structures do not depend on having an underlying Hilbert space, or indeed any linear structure whatsoever; therefore we can study complementary observables at a much greater level of generality than the usual Hilbert space formulation of quantum mechanics. The results will apply in any 'quantum-like' theories that bear the necessary algebraic structures. The minimal mathematical environment to support these structures is generally a dagger SMC or †-SMC [2,68]. By working in an SMC, we can study the central features of quantum mechanics and quantum computation, without reference to Hilbert space at all. This research programme was initiated by Abramsky and one of the authors in [1].
In previous work, it was already established that the observables themselves correspond to certain commutative Frobenius algebras [27,28]. We now explain how conceptual analysis leads to this algebraic structure, via a contrapositive of the no-cloning theorem [31,77].
While the no-cloning theorem suggests a fundamental limitation of QIC compared to its classical counterpart, a positive reading of it reveals that quantum states may be copied if they are known to lie in a given basis. In other words, a quantum state may be treated as 6 classical data, and therefore copied freely, if it is an eigenstate of a known, non-degenerate observable. (Throughout this paper we will treat 'orthonormal basis' and 'non-degenerate observable' as synonyms, and commit abuses like 'measuring against a basis' and so on.) More concretely, given a finite dimensional Hilbert space H with a basis A = {|a i } i , the copying operation δ: |a i → |a i ⊗ |a i encodes the basis A as those states that it effectively copies; the no-cloning theorem guarantees that the basis vectors are the only states with this property. Note here that δ may be realized as a unitary map on H ⊗ H with one input fixed, for example, by U : |a i ⊗ |a j → |a i ⊗ |a i+ j where the sum is taken in Z n . Now, let be the linear functional on H defined by |a i → 1 for each i. In more conceptual terms, uniformly erases the elements of the basis A. Further, when is applied to an output of δ we get the identity map: ( In algebraic terms, is the co-unit for the co-multiplicationδ. Together the pair (δ, ) form a special commutative †-Frobenius algebra on H. Previous work established the remarkable fact that every algebra of this kind on a finite dimensional Hilbert space arises as a pair of copying and erasing operations for some orthonormal basis [27,28]. Since these algebras correspond precisely to non-degenerate quantum observables, we refer to them as observable structures. Observable structures (δ, ) and (δ , ) that correspond to complementary observables enjoy a special relationship: the main body of this paper is dedicated to explicating just that relationship, and a great deal of additional algebraic structure that follows.
Structure of this paper. This paper contains two self-contained parts, each of which could be read independently of the other: Part I. Comprising sections 2 and 3, the first part is an informal presentation of a graphical calculus based on the interaction of complementary observables. Effectively we begin at the end, by presenting a calculus that demonstrates many of the key ideas of the theory, but without presenting the theory itself until part II. It also serves to familiarize the reader with graphical reasoning, a tool that we will use throughout this paper. We rely here on some familiarity with quantum computing terminology for the examples, but no other background. Section 2 introduces the ZX-calculus, a graphical language and a set of equational rules that are based on the Pauli Z and X spin observables, and specially tuned for use in quantum computation. Quantum systems are represented as diagrams, and these can be rewritten according to the equations in order to prove statements about the corresponding quantum systems. This language is universal in the sense that any operation on n qubits can be expressed in it, as shown in section 2.4.
In section 3, we demonstrate a variety of applications: simulating quantum circuits and transforming measurement-based computations into equivalent circuits for example. These examples are small, but the ZX-calculus is appropriate for real use, and has been used to prove non-trivial results in this area [37]. Part II. The main body of the paper, sections 4-10 provide an axiomatic analysis of complementary observables within the general framework of †-SMC. Throughout, we will use graphical notation as much as possible.
From this point onwards, the Pauli Z and X spin observables will only be one example among all possible pairs of complementary observables. This will reveal additional properties enjoyed by the Z and X observables, as compared with other pairs of complementary observables. Also from this point onwards, Hilbert spaces are simply one particular model of the axiomatic abstract algebra, and since interpretations in other models may be useful, concepts will be introduced in full generality. For example, the observables in Spekkens' toy theory [72] are also captured by our analysis. Section 4 reviews the necessary category-theoretic background, in particular †-SMCs and their graphical notation. We rely on the work of Joyal and Street [47] and Selinger [69] to establish the validity of the graphical calculus as a rigorous mathematical syntax and not simply a sketch.
Returning briefly to the concrete Hilbert space setting, section 5 defines the notions of state basis and coherent unbiased basis for Hilbert spaces and studies their relation to quantum observables. These concepts play a key role in this paper, in abstract form, and to our knowledge have not appeared in the literature yet.
The technical core of the paper begins with section 6, which provides the definition of observable structure-also known as special commutative †-Frobenius algebra-and establishes its basic properties, including the 'spider theorem', giving the normal form for expressions in the language of observable structures. Before arriving at the definition of complementarity, in section 7 we provide a category-theoretic account of an important related concept, namely the phase relative to an observable. Every observable structure gives rise to an Abelian group of phases, which behave particularly well with respect to the normal form theorem for diagrams involving observables. We refer to this result as the 'decorated spider' theorem.
In section 8, we characterize complementarity for observable structures. In section 9, we identify a special kind of complementary observables, which we refer to as closed. These include the complementary observables that are relevant to quantum computing. We moreover provide further, equivalent, characterizations of these closed complementary observables. All of these equivalent characterizations take the form of some sort of commutativity, be it either commutativity of multiplication and a comultiplication, commutativity of a multiplication and an operation, or commutativity of operations. These commutation properties present a remarkable contrast to the usual characterization of incompatibility as non-commutativity. The technical development concludes in section 10, by examining how the phase groups of complementary observables act on each other to produce 'interference' phenomena. Part III: Coda. Section 11 returns to the beginning by demonstrating how the general theory expounded in part II produces the ZX-calculus of part I. We note which rules hold on other pairs of complementary observables, and show where the particular features of the Z and X observables appear in the calculus.
Finally, section 12 addresses the most obvious omission so far; it deals with nondeterminism and classical data flow.
About this paper. The genesis of the current paper was an attempt to apply observable structures [23,27]-then called classical structures-to a diagrammatic notation for measurement-based quantum computation [35]. An initial report on these results was first presented at the icalp conference in 2008 [18], albeit under severe space restrictions. During the intervening period the theory was under active development in Oxford, and several papers have appeared making use of the key ideas and applying them in various settings: in 8 measurement-based quantum computation [36,37], in the study of Spekkens' toy theory and non-locality [19,20], quantum protocols [29], complementarity in the category of relations [19,41,60], among others. This paper is the first complete presentation of our categorical treatment of complementary observables, and it corrects several errors in the earlier paper.

The ZX (or green-red) graphical calculus
The state space of the elementary quantum computational unit, the qubit, is denoted by Q := C 2 . The vectors of the computational basis or Z -basis are written as |0 , |1 , while those of the X -basis are written as On the Bloch sphere these bases can be represented as follows: where the green dots represent the elements of the X -basis and the red dots represent those of the Z -basis. These bases consist of the eigenvectors of the Pauli spin matrices, and correspond to the possible outcomes upon measuring the spin of the electron along the Z -and X-axes, respectively. Our interest in these particular spins stems from the fact that they are the simplest example of complementary observables.
In this section, we will present a graphical calculus, specific to the Z -and X-spin observables, which is a special case of the general theory that we develop later in this paper. As well as demonstrating the main features of the full theory, this simplified calculus is sufficiently powerful to carry out many calculations useful in the context of quantum computation, as the examples in section 3 will demonstrate. This framework refers exclusively to the mathematics underlying quantum computation and not to any details of how the operations are implemented, which makes it ideal for unifying various approaches to quantum computation. For example, we can demonstrate equivalence between different quantum computational models.

The ZX language: networks of wires and dots
The ZX-calculus consists of components joined by wires, similar to electronic circuit diagrams or flow charts. The simplest non-trivial diagram in the language is simply a wire running from 9 top to bottom: We think of diagrams as being enclosed in a box with a certain number of points through which wires enter and leave; that is, each diagram has a fixed interface. Exactly one wire must be present at each point of the interface, and we must distinguish which wire is connected to which point. Indeed, this is the only difference between the two diagrams below.
It is not important whether crossing wires pass over or under (i.e. we are in a symmetric setting, not a braided one [48]). Wires may bend, linking two outputs to form a cap, or two inputs to form a cup.
From here on, the inputs and outputs will not be named, and are distinguished simply by their ordering from left to right. We write D: m → n to indicate that the diagram D has m inputs and n outputs.
Aside from wires, the ZX-calculus contains four kinds of components: • Z vertices (green dots), labelled by an angle α ∈ [0, 2π), called the phase. These can have any number of inputs or outputs (including none).
• X vertices (red dots), labelled by a phase. These too can have any number of inputs or outputs (including none).
• H vertices (yellow squares). These must have exactly one input and one output. • √ D vertices (black diamonds). These may not have any inputs or outputs.
We refer to the Z and X vertices as 'spiders', and make the convention that if α = 0 the angle is omitted. Diagrams are built from these generators-straight, crossing and bending wires and Z , X , H and √ D vertices-in two manners.
• Placing them side-by-side: Notation: Given D: m → n and D : m → n their tensor product is denoted by D ⊗ D : m + m → n + n .
• Connecting outputs to inputs: Therefore, the terms of graphical ZX-language are networks of vertices of each type, straight, crossing and bent wires: In such a network, there can be no 'loose wires': every wire must terminate at a vertex, or else be an input or output. Important examples are those spiders with two inputs and one output (cf a binary operation), with no input and one output (cf initiation of a value) which we will call a point, with one input and two outputs (cf copying) and with one input and no output (cf erasing): As we will see shortly, these unlabelled spiders play a special role in the calculus, as do those labelled by π.

The ZX-equational rules
In addition to the rules for constructing diagrams, the calculus consists of a set of equations that specify how one diagram may be transformed into another. These rules are presented in figure 1. We now expand on these rules and give some examples of their use.

2.2.1.
The T-rule. The informally stated T-rule will be made more precise in sections 4.3-4.5. For practical purposes, the intuitive reading of 'only the topology matters' suffices: the wires of the diagram may be arbitrarily stretched, bent, twisted, tied in knots, etc, without altering the meaning of the diagram, provided the connections are maintained. More precisely, after identifying (e.g. by enumerating) the inputs and the outputs, any topological deformation of the internal structure of the network yields a network that is equal to the given one.
Two important examples of such 'homotopic rewrites' are In fact, these two rules can also be seen as consequences of the S-rules, when introducing a green dot on the caps and cups as in (S2); see example 2.4 below. The reason for considering them within the T-rule will become clear in section 4.5.

The B-rules.
The B1-rule can be read loosely as 'green copies red points' and 'red copies green points', in both cases 'up to a diamond'.
The B2-rule is a powerful commutation principle, and generates a whole family of equations, allowing alternating cycles of red and green dots to be replaced with simpler graphs; see [36].

Example 2.5. An important equation derivable from the B-rules is the following:
This equation is obtained as follows: Note that the step labelled (B1) in fact applies a version of that rule deformed by (T), without altering the topology. We could do this more explicitly using the T 1 and T 2 examples as follows: Rules (B ) and (B2) are known informally as the Hopf law and the bialgebra law. Together, the B-rules state that the interactions of different coloured spiders produce a structure we call a scaled bialgebra, which differs from a bialgebra only by a normalizing factor. The fact that these structures naturally arise whenever we have complementary observables is one of the main insights of this paper, and will be developed further in section 8.

The K-rules.
These rules are concerned with special properties of spiders with phase α = π . Rule (K1) states that dots labelled by π commute with spiders of the other colour, i.e. X 1 1 (π) is a homomorphism of the comultiplication Z 1 2 (0), and vice versa. Example 2.6. Thanks to rule (K1), points with phase π can also be copied just like points with phase zero: Since the points labelled by π or 0 can be copied, we call these classical points; then Z 1 1 (π) and X 1 1 (π ) are called classical maps. 4 (Of course, K stands for 'klassical'.) In the next section, we will see that Z 1 1 (π ) and X 1 1 (π) are interpreted by the familiar Z and X gates, respectively.
Rule (K2) states that dots labelled by π invert the phase of dots of the other colour.
2.2.5. The C-rule. This rule allows the H vertex to function as an explicit colour changing operation that transforms 'green structures' into 'red structures' and vice versa. In the next section, we will see that the H vertex is interpreted by the familiar Hadamard gate, exchanging the X and Z bases.

Example 2.8. Some special cases of this rule are
Note that (C 3 ) asserts that H is self-inverse. The C-rule effectively allows H vertices to commute with coloured dots, changing their colour in the process.

2.2.6.
The D-rules. The (D2) rule states that two black diamonds are equal to a loop of wire, itself the result of composing a cup and a cap. We will see in the next section that the loop represents the dimension of the underlying Hilbert space, and spacial juxtaposition is a form of multiplication, justifying the name √ D for the diamond. The (D1) rule 'almost follows' from the other rules: which would yield the desired result if could be cancelled.

Interpreting the ZX-calculus in Hilbert space
Given a diagram D with n inputs and m outputs, we construct a corresponding linear map D: Q n → Q m as follows.

Definition 2.9 (interpretation of generators
The order in which we divide the diagram into pieces does not matter to the final result, so long as the 'cuts' do not pass through any vertices or any points where wires cross or any points of inflection of a wire-more accurately: just those inflection points where the gradient of the wire changes sign. (These last two may be thought of as the 'vertices' defining σ Q , and η Q and Q , respectively.) Example 2.13. The following diagram can be divided up as follows: Unlike the diagram, the resulting matrix is rather large (16 × 32), so it is not shown here. Any other factorization of the diagram, for example, produces the same interpretation.
Example 2.14. According to the T-rule, the diagram of example 2.13 above is equivalent to the one shown below: As one might hope, this gives the same interpretation.

Remark 2.15.
A linear map f : C → C is completely determined by the value f (1). For this reason, and since Q 0 = C, the Hilbert space interpretation of a diagram with no inputs or outputs-a map from C to itself-is simply a complex number. This proposition can largely be verified by computing the maps corresponding to the left and right sides of each of the equational rules given in figure 1, and observing that they are equal. However, to show that the T-rule is correct, different techniques are required. We will return to this point, and the (non)-issue of the factorization order, in section 4.3.
The converse of proposition 2.16 is false: there exist diagrams D 1 and D 2 that represent the same linear map but which are not equal by the rules of the ZX-calculus. For example, the following diagrams are not equivalent in the calculus: but their interpretation as linear maps is the Euler-angle decomposition, This equation is equivalent to Van den Nest's theorem on local complementation of graph states [75], as shown elsewhere by Perdrix and one of the present authors [36]. We remark upon this fact for two reasons: firstly, as warning that not every true fact about Hilbert space quantum mechanics can be derived using the ZX-calculus, although a great many equations used in quantum information processing can be. Secondly, since the equational theory of the ZX-calculus is strictly weaker than that of Hilbert spaces, it is more general. Therefore, there are models of the calculus which are distinct from the usual Hilbert space interpretation of quantum mechanics. All such models contain a large fragment of quantum mechanics-viewed as an equational theory-but facts like Van den Nest's theorem need not hold.
Remark 2.17. The points in the calculus are not normalized. This is required for reasons of simplicity; if we were to normalize σ Q and η Q , then the (T1) rule would require additional scalar multipliers, and hence so would the (S1) rule, and so on.

Universality of the ZX-calculus
We claim that we now have enough expressive power to write down any arbitrary linear map from n qubits to m qubits. The green and red phases, respectively, 18 correspond to rotations of angle α, respectively, around the Z -and X -axis on the Bloch sphere: Combining both the 'green' and the 'red' phases allows us to write down any arbitrary one-qubit unitary in terms of its Euler-angle decompositions on the Bloch sphere: The controlled-NOT gate is defined by (5) Standard results in quantum computing [59] state that ∧X gates and arbitrary one-qubit unitaries suffice to construct any n-qubit unitary map. As equations (4) and (5) show, the ZX-calculus contains this universal gate set, and hence can represent any n-qubit unitary map. Arbitrary n-qubit states can therefore be represented as the image of any n-qubit state-for example -under a well-chosen unitary. Finally, allows us to obtain any arbitrary linear map f from n qubits to m qubits from some n + m qubit state | , by relying on the diagrammatic incarnation of map-state duality [1]: (6) Summarizing all this:

Adjoints and inner products
Definition 3.1. Let D: m → n be a diagram; then its adjoint, D † : n → m, is a diagram constructed by reflecting D in the horizontal axis, and negating all the angles that occur in D.
Example 3.2. Given the diagram D, we form its adjoint D † as shown: We claim that D is unitary. Half of the required proof is shown below.
The 'horizontal application' of the B -rule can be decomposed as follows: from which it follows that pairs of wires between green and red dots can be eliminated. It remains to be shown that The following is self-evident:  Recall that any diagram D: 0 → n has a (possibly unnormalized) n-qubit state as its Hilbert space interpretation; such diagrams therefore correspond to kets |D in Dirac notation. Since Dirac's bra is the adjoint of a ket, we now see how to define the inner product of two diagrams.

20
Given A, B: 0 → n we have • B) has no inputs or outputs; hence by remark 2.15, it denotes complex number, as required.
Example 3.6. We can compute the inner product of Z 0 1 (α) with itself.
The result is 2 because the 'states' are not normalized.
Since the result is independent of j and k, this calculation shows that the X and Z bases are mutually unbiased.
Example 3.8. Suppose that U is a diagram encoding some complicated unitary operation U , acting on n + 1 qubits. Suppose its input is |00 · · · 0 : what is the amplitude for observing the output |1 at its last output? We need to compute: When U is presented using the generators of the ZX-calculus, a great simplification is (usually) possible, making this expression (usually) easy to compute.

Quantum circuits
As we have already seen in section 2.4, the ZX-calculus can represent the basic gates used in quantum circuits. The rules of the calculus can give short graphical proofs of many circuit identities.

The ∧X gate.
We have already seen the controlled-NOT gate: It is manifestly self-adjoint. We can prove that it is also unitary: An elementary exercise is to show that a sequence of three ∧X gates can be used to swap to qubits. A graphical proof of this fact is given below.
While this is a well-known property for ∧X, our proof holds in much greater generality than qubits, since as we will see in the remainder of this paper, the graphical calculus applies in much greater generality. This example relies on the bialgebra law (B2), which is a stronger principle than the Hopf law (B ) used in the previous example. The relationship between these two laws will be spelled out in section 9.
In section 2.4, the ∧X gate was introduced by checking that its diagram denoted the correct linear map. However, we can describe ∧X by the following 'behavioural specification': when the control input is|0 , the target qubit is left unchanged; when the control qubit is|1 , the target qubit is flipped. Letting represent one of the two red classical points, that is, either = |0 or = |1 , we can supply a qubit to the control input (the left input, connected to the green dot), and obtain the following proof: Note that in each case the control qubit passes through the gate unchanged, while the target input is either the identity or the Pauli X, depending on the value of the control qubit, thus meeting the specification. Further, the colour symmetry of this proof demonstrates that if we operate in the Z -basis (i.e. |+ = and |− = ), the roles of left and right are exchanged.

3.2.2.
The ∧Z gate. Since Z = H XH , we can obtain the ∧Z gate from the ∧X gate by conjugating the target qubit with H gates, as shown below: We can immediately read off two properties of this gate from its graphical representation: it is self-adjoint, and it is symmetric in its inputs. It is also unitary:

The quantum Fourier transform.
Lying at the centre of many quantum algorithmsincluding Shor's famous factoring algorithm [71]-the quantum Fourier transform is one of the most important quantum processes. The equations of the diagrammatic calculus are strong enough to simulate it.
To write down the required circuit, we must realize a controlled phase gate, where the phase is an arbitrary angle α; this is shown below-the control qubit is on the left. (One can prove the correctness of this diagram using a behavioural description in a similar fashion to the treatment of the ∧X in section 3.2.1.) The only gates that are required to construct the circuit implementing the quantum Fourier transform are the Hadamard and the ∧Z α -see for example [59]. The circuit for the two-qubit QFT is shown below.
How can we simulate this circuit? First, we choose an input state, in this case |10 = ; then we simply concatenate the input to the circuit, and begin rewriting according to the equations of the theory, as shown below.
The final diagram in the sequence is simply the tensor product (|0 − |1 ) ⊗ (|0 + i|1 ), which is indeed the desired result. In passing we remark on another feature of the graphical language: since the last diagram is a disconnected graph, it represents a separable quantum state.

Measurement-based quantum computing
Measurement-based quantum computation [49] uses the state-changing effect of quantum measurements to carry out the computation, typically propagating these changes through entangled states. The simplest example is the teleportation protocol [8], which can be viewed as the identity function computed via a Bell state. A more powerful model is Raussendorf and Briegel's one-way quantum computer [64,65], which provides a computationally universal model almost entirely based on single-qubit measurements acting on a large cluster state.
The graphical notation of the ZX-calculus is ideal for representing these entangled states, and its equations accurately capture the changes in these states induced by measuring their constituent parts. Remark 3.9. The ZX-calculus, as presented in this section, cannot represent the nondeterministic behaviour of measurements. Rather, we replace measurements by projections onto some particular outcome. One could view this as post-selection, but it would be more accurate to understand that each diagram represents one particular run of an experiment, and the particular outcome that was measured, rather than averaging over all possible runs. The restriction to pure states is not an intrinsic limitation of this approach. It is a deliberate choice, made in order to simplify the presentation of the calculus. The formal apparatus used here was introduced in [27] to represent the classical control structure and the branching behaviour of quantum measurements. In section 12, we present three extensions to the calculus to handle non-determinism and mixedness.
3.3.1. The teleportation protocol. The teleportation protocol [8] consists of two main components: the preparation of the Bell state and the Bell basis measurement. As described 24 in section 2.3, the (unnormalized) Bell state is represented by a cap, and its corresponding projection by a cup: Combining these two elements, we obtain an almost trivial proof of the correctness of teleportation, in the case where Alice observes |00 + |11 .
The role of classical communication is hidden in this picture, but it is revealed by a more detailed look at the Bell basis measurement. Let α, β ∈ {0, π}. Ranging over the four possible (α, β) pairs in the diagram below gives the four possible outcomes of a Bell basis measurement: (Note that the boxed part of the diagram is simply the circuit that rotates the Bell basis onto the X -basis.) This description of the protocol displays the Pauli errors that are introduced if Alice observes the other possible outcomes.
From this we can derive a complete description of the protocol, and show, including Bob's corrections, which are classically correlated to Alice's observations. The first equation is the preceding derivation collapsed into one step, while the last two equations use the spider rules and the fact that 2α = 2β = 0.

3.3.2.
The state transfer protocol. This protocol was introduced by Pedrix [62] to reduce the resources required for measurement-based quantum computing. The core of the protocol is a measurement which projects onto a two-dimensional (2D) eigenspace: It is easily seen that P Z ⊗Z is self-adjoint and idempotent: (8) and hence a projector.
Consider now a protocol, which initially assumes two qubits, one in an unknown state and one in the state . We want to transfer |ψ from the first qubit to the second, and this can be done by means of two projections: since by application of the S-rule we have The protocol can be extended by performing the second, single-qubit measurement in the phaseshifted basis |0 ± e iα |1 .
This minor change allows the protocol to apply an arbitrary Z -rotation to its input; the protocol can be modified in the obvious way to perform an X -rotation, and hence any single-qubit unitary.

Multipartite states.
In our graphical language, a quantum state is nothing more than a diagram with no inputs; the outputs correspond to the individual qubits making up the state. The interior of the diagram-i.e. its graph structure-describes how these qubits are related. This notation is ideal for representing large entangled states. Cluster states, which are used in measurement-based quantum computing [65], can be prepared in several ways and the ZX-calculus provides short proofs of their equivalence. For example, the original scheme describes a ∧Z interaction between qubits initially prepared in the state |+ ; in our notation this is Z 0 1 or . Hence a one-dimensional cluster state can be presented diagrammatically as: where the boxes delineate the individual |+ preparations and ∧Z operations. Alternatively, the cluster state can be prepared by applying a Hadamard gate to one part of a Bell pair to obtain states of the form | = |0+ + |1− , and then 'fusing' these entangled pairs [76]. The required fusion operation is exactly (9) and a 1D cluster prepared with this method looks like: Again, dashed lines indicate the individual components. Whereas conventional methods require some calculation to show that these methods of preparation produce the same state, using the spider theorem, the two diagrammatic forms are immediately equivalent: From the example of the 1D cluster, it is easy to see how to construct diagrams corresponding to arbitrary graph states. Indeed given a graph state |G , with the underlying graph G, we represent |G by the same graph G, with green dots at each vertex and H gates on each edge; to complete the construction we must add one output wire at each green vertex.
While graph states are important in measurement-based quantum computation, they are not the only kind of interesting entangled states. As an illustration of universality of the graphical language, we present graphical representatives of the two non-comparable classes of genuine three-qubit entangled states 5 . As can be directly read from the interpretation given in section 2.3, the GHZ state is simply a three-legged spider: The simple form of this state hints at its importance for the algebraic structures to be introduced later in this paper. This algebraic role, particularly in relation to the phase group, has been used to explain non-locality [20]. The W state, however, is less obvious: This representation supports the intuition that while the GHZ state is globally entangled, the W is rather to be conceived as a pairwise entanglement between each pair of qubits that make up the three-partite system [38]. The algebraic properties of the W state have been studied elsewhere by Kissinger and one of the present authors [21].

3.3.4.
The one-way model. The graphical language is ideal for studying different models of quantum computation in the same setting. In this section, we will present several computations using the one-way model [64], and translate them into equivalent quantum circuits using the rules of ZX-calculus. We use the measurement calculus notation introduced by Danos et al [30], and borrow their examples.
For our purposes, a measurement calculus program, called a pattern, consists of a sequence of commands of the following kinds: • E i j -apply a ∧Z operation to qubits i and j, • M α i -measure the qubit i in the basis |0 ± e iα |1 . The commands occur in the order given: first initializations, then entanglement and then measurement. Any quibit that is not initialized is an input; any not measured is an output.
Since, in the ZX-calculus, measurements are replaced by projections, the conditional operations of the measurement calculus have been omitted; see section 12 and [37] for a more complete treatment. We make the convention that the observed outcome of each measurement will be the +1 outcome-that is, the projection onto |0 + e iα |1 . With this convention the elements of the measurement calculus can be translated by the following table:

Example 3.10. Consider a measurement-based program involving four qubits, which computes a ∧X gate upon its inputs. In the syntax of the measurement calculus, this pattern is written as
Reading from right to left, this specifies that qubits 3 and 4 should be prepared in a |+ state, then ∧Z operations should be applied pairwise between qubits 1 and 3, 2 and 3 and 3 and 4; finally X basis measurements should be performed upon qubits 2 and 4. Qubits 1 and 2 are the inputs and qubits 1 and 4 are the outputs. We represent this pattern diagrammatically as The spider theorem allows this one-way program to be rewritten to a ∧X gate in three steps: Example 3.11. Our next example is a one-way program implementing an arbitrary one-qubit unitary. Recall that any single-qubit unitary map U has a Euler decomposition such that U = Z γ X β Z α . Such a unitary can be implemented by the following five-qubit measurement pattern:

The graphical form of this pattern is shown below:
A sequence of simple rewrites shows that the one-way program intended to compute such a unitary does indeed produce the desired map.
Remark 3.12. The reader may object that the 'post-selection' of one particular set of measurement outcomes reduces the number of diagrams significantly and thus gives a misleading air of feasibility to these techniques. In practice, the pure state version of the ZXcalculus needs only a minor extension to handle the full behaviour of the one-way model, without any combinatorial explosion. We sketch this extension in section 12; full details can be found in [37].

Symmetric monoidal categories and graphical reasoning
The preceding sections presented the ZX-calculus as a fait accompli, without any serious justification for its axioms other than its utility in certain calculations. This section, and those that follow, will present the firm mathematical foundation upon which the calculus is built. This section will outline the basic concepts of SMCs without going into too much technical detail; we aim to provide the reader with just enough background to follow the subsequent material, and provide many references where complete and detailed expositions can be found.
A category consists of objectsA, B, C, . . . and, for each pair of objects A, B, a collection of morphisms f, g, h, . . . : A → B. From a physical perspective, the objects can be thought of as physical systems and each morphism f : A → B as a physical process that transforms a system of type A to a system of type B. Here, 'type' should not be confused with 'state'. For example, 'type' could be a qubit or a field or a certain classical system, and each of these admits many states. For a computer scientist, the objects may be data types, and f : A → B would be a program accepting input of type A and producing output of type B. In mathematics the objects are typically structures of a certain kind, e.g. sets or groups or vector spaces, and f : A → B is a structure-preserving map, e.g. a function or a group homomorphism or a linear map.
Pairs of morphisms where the domain of one matches the codomain of the other may be composed: for each such pair, f : A → B and g: B → C, we write the composite g • f : A → C. In the case of physical processes g • f can be interpreted as 'process gafter process f '; in the case of structure-preserving maps the composition of morphisms is just ordinary function composition. Composition is assumed to be associative. One also assumes the existence of units for this composition; more precisely, for all A there exist identity morphisms 1 A : A → A such that for all f : A → B and all g: As a physical process this would stand for the void process, or in operational terms, 'doing nothing' 6 .
In addition to the 'sequential' composition operation − • −, an SMC also comes with 'parallel' composition − ⊗ −. For two physical systems A and B there is a compound systemA ⊗ B and for each pair of physical processes f : For mathematical objects, ⊗ then indicates a compound mathematical object of a certain kind, built from two 'smaller' ones, e.g. using the Cartesian product of sets or the direct product of groups or the tensor product of vector spaces. One also assumes a unit object I, which is such that composing A with I, one leaves A essentially unchanged. Finally, for each pair of objects A and B, one assumes a swap morphismσ A,B : A ⊗ B → B ⊗ A. The remaining axioms of an SMC then play two roles: • bifunctoriality states how the two modes of composition interact; • the existence of a number of natural isomorphisms and coherence conditions between these formalize the meaning of 'essentially' when saying that A ⊗ I is 'essentially' the same as A. 7 The swap morphisms are also natural isomorphisms; these embody the canonical connection between A ⊗ B and B ⊗ A 8 .
All of these conditions have a straightforward physical interpretation and are satisfied for most standard mathematical constructions of compound objects.
Since there are two modes of composition, SMCs naturally lend themselves to a twodimensional syntax we call the graphical (or diagrammatic) calculus, where the vertical axis corressponds to the sequential composition '•', and the horizontal axis to the tensor product '⊗'. Moreover, when expressed in the graphical language, the coherence conditions for SMCs become trivial as a consequence of some very powerful theorems, so they play no further role in this paper. Hence, while below we do state the symbolic definition of a symmetric monoidal category, it is not crucial for the remainder of this paper. The graphical language is both clearer and closer to the physical intuition; the reader who prefers the graphical language can skip ahead to section 4.3.
A more detailed account of the physical intuition behind SMCs can be found in [14,17,24]. The work [24] is an extensive tutorial specifically written to provide the appropriate background on the kind of category that is required for this paper. Other tutorials that may be of help are [3,6]. Mac Lane's standard textbook on category theory is of interest to a mathematical audience [57].
The graphical calculus for SMCs can be traced back to Penrose's work in the early 1970s [61], but it was turned into a formal discipline only after the work of Freyd and Yetter, and Joyal and Street, was published around 1990 [42,47]. A physicist-friendly presentation is again given in [14,17,24], and a specifically targeted tutorial is given in [24]. A recent comprehensive survey paper on graphical languages for more general monoidal categories, which settles a number of caveats of the earlier literature, is [69]. The reader interested in learning more may also find [6,53,73] helpful.  7 For example, although for all practical purposes the sets X × (Y × Z ) and (X × Y ) × Z are equivalent, they are strictly speaking not the same: the first one contains elements of the form (x, (y, z)) while the second one contains elements of the form ((x, y), z). Making this notion of equivalence mathematically precise is what makes the explicit definition of an SMC somewhat heavy-handed. 8 Now, (x, y) and (y, x) are no longer 'essentially the same', but they still are canonically connected via the operation 'swapping elements'. A morphism f : A → B has domainA and codomainB. We will sometimes refer to objects as types, to A as the input type and to B as the output type.

Symmetric monoidal categories
In order to precisely state the definition of an SMC we need to introduce two auxiliary concepts: functors and natural transformations. While these definitions may seem rather abstract, the only examples of them that will be needed are familiar ones: the tensor product, and isomorphisms between tensor products of objects.
By explicitly stating some basic category-theoretic notions the reader may get a sense of why even many mathematicians consider category theory as 'very abstract'; in contrast, the diagrammatic calculus shows that specific parts of category theory, namely SMCs and in particular their graphical calculus, can make certain mathematical structures much more intuitive and easier to manipulate. and

Definition 4.4.
A bifunctor is a functor of two arguments F : C × C → D, that is a functor in each argument separately, i.e., for all objects X and arrows f : A → B, g: B → C in C, and all objects X and arrows f : A → B , g : B → C in C', we have: which additionally satisfies In essence, a functor is a map between categories that preserves the structure of the category, i.e. composition and identities. We will also need maps between functors. for all arrows f : Notation and terminology: Each directed path in the diagram above determines a composition of two maps: G( f ) • τ A on the upper path and τ B • F( f ) on the lower. The phrase 'the square commutes' means that both paths in this directed graph are equal, i.e.
If two objects in category are naturally isomorphic then they are isomorphic, 'for structural reasons' and not because of any particular details of the objects themselves. The following definition provides a key example.
and a natural associativity isomorphism which are subject to certain coherence equations, which we omit.
The bifunctor − ⊗ − is called the tensor product or monoidal tensor. The maps λ, ρ and α are called the monoidal structure maps. A monoidal category is called strict when the structure maps are all identities; that is, when the objects made isomorphic by λ, ρ and α are in fact equal. The following theorem by Mac Lane justifies our omission of the coherence equations for the structure maps.

Theorem 4.7. Every monoidal category is equivalent to a strict monoidal category.
For details we refer the reader to [57]. Henceforward all the monoidal categories we consider will be strict, although we will frequently use the symbols λ A and ρ A for clarity, for example, when composing an arrow of type B → A with one of type A ⊗ I → C.

Definition 4.8. A symmetric monoidal category is a monoidal category equipped with a natural symmetry isomorphism
A,B = σ B,A and again subject to some coherence conditions which we omit. If C is an SMC, then σ is counted among its structure maps. Unlike the other structure maps, σ cannot be replaced by the identity without losing essential structure. Again see [57] for details of the coherence conditions, which are summarized in the following theorem [52]: Theorem 4.9 (Kelly-Mac Lane). Let f and g be parallel natural isomorphisms in a symmetric monoidal category, both constructed from identities and the structure maps by tensoring and composition; then f = g.
Essentially, this result says that when one uses the structure maps to permute the factors of a tensor product, only the permutation matters, not how it was constructed. 9 The preceding definitions may seen rather intimidating to those unfamiliar with category theory, but there is no need to be alarmed: SMCs are among the most ubiquitous of mathematical structures! Example 4.10. The SMC (FdHilb, ⊗, C), often written simply as FdHilb, has finite dimensional Hilbert spaces as objects and linear maps as its morphisms, which compose by ordinary composition of linear maps. The familiar Kronecker tensor product is the monoidal tensor, and the field of complex numbers C-which is a 1D Hilbert space over itself-is the tensor unit.
The requirement that the monoidal tensor be a bifunctor reduces to the following wellknown property of linear maps: We indeed also have H C ⊗ H via the natural isomorphism: it is easily checked that natural transformations are always basis independent. See [24] for a detailed description of (FdHilb, ⊗, C). Example 4.11. Let (ZX, ⊗, 0) denote the SMC whose objects are natural numbers, and whose arrows f : n → m are diagrams of the ZX-calculus, as described in section 2, with n inputs and m outputs. The identity arrows are diagrams consisting of straight wires from inputs to outputs, and composition is achieved by plugging inputs to outputs.
The tensor product on objects is addition n ⊗ m := n + m, and the unit object is zero: n ⊗ 0 = n + 0 = n. Tensor product of two diagrams is juxtaposition, and the identity map 1 0 is just the empty diagram. By its construction, ZX is evidently a strict monoidal category. We leave to the reader the task of constructing the symmetry maps σ n,m from crossings of wires.
We remark in passing that the assignment from a diagram D to its corresponding linear map D, described in section 2.3, defines a functor from ZX to FdHilb.
In the categorical setting, the internal structure of the objects is hidden-abstracted away; the state spaces are effectively reduced to labels which determine when morphisms may be composed. However, in FdHilb and many other important examples, the internal structure of the spaces may be reconstructed via the structure of the morphisms into that space.  So the elements of FdHilb(C, H) are the points of the object H. To distinguish between the linear map ψ and the vector ψ(1) we will denote the latter by |ψ . As processes, we can think of these points ψ : C → H also as preparation procedures.
A point : I → A ⊗ B is a state of the compound system A ⊗ B, and this state may or may not be entangled. If it is not entangled, then we have that is, the state factors in state ψ A of system A and state ψ B of system B. It is entangled if such a factorization does not exist. If the category bears a certain additional structure, e.g. compactness as described in section 4.4, then the existence of entangled states can be guaranteed, which in turn enables the derivation of teleportation-like protocols [1].
In many categories, the points can reveal a great deal about the arrows. For example, in a vector space, two linear maps are equal if they agree on a small number of points, namely a basis. To tell if two functions are equal, it suffices to evaluate them on every element of their domain. The analogous procedure is not possible in every category. More precisely, a set of points K ⊆ C(I, A) is called a basis for A if for all objects B, and all arrows f, g: A → B, we have If every object of C has a basis, then we say that Chas enough points. Fortunately, the examples of interest here do have enough points, and section 5 describes the particular forms of bases that will be of interest in later sections. More explicitly, we can define to be the scalar multiplication of morphism f : A → B by the scalar c. The scalars, in any monoidal category, form a commutative monoid with respect to composition [51]. From the definition of scalar multiplication it follows that Intuitively, in the language of SMCs, if a scalar appears in the description of a morphism, it does not matter where it appears: its effect is that of a global multiplier for the entire morphism.  (10) coincides with the usual linear algebraic notion, for which (11) and (12) indeed hold. The commutative monoid of scalars is isomorphic to the monoid of the complex numbers (C, ·, 1). For more details, again see [24].

The † functor
Following [1,2,68], we augment SMCs with additional structure that plays an essential role in the quantum mechanical formalism.
which assigns to each morphism f : A → B an adjoint morphism f † : B → A, which coherently preserves the monoidal structure, that is, Further, for the natural isomorphisms λ, ρ, α and σ of the symmetric monoidal structure, the adjoint and the inverse coincide.
The category Rel that has sets as objects, relations as morphisms and relational composition is a †-SMC with the Cartesian product of sets as the monoidal structure, and the relational converse as the † functor. The unit object for the monoidal structure is the singleton set { * }, since X × { * } X for any set X , and the monoid of scalars is now isomorphic to the Boolean monoid (B, ∧, 1), since there are only two relations r : { * } → { * }, namely the empty relation and the identity relation. The involution for the monoid of scalars is now trivial. We write FRel when restricting to finite sets. In Rel the points of an object X are not its elements but its subsets-a detailed discussion is given in [14,24]. While at first sight (F)Rel seems to have little to do with physics, it enables one to encode a surprising number of quantum phenomena. For example, Spekkens' toy quantum theory [72] can be embedded within it as a sub- †-SMC Spek [19,20]. This succinct categorical presentation of this toy theory is moreover the only currently available rigorous mathematical presentation of it. Example 4.21 (projective spaces). The passage from vectors to states comes with a radical change of the mathematical description of the spaces: from vector spaces to projective spaces, which drove von Neumann into the advent of lattice theory and quantum logic [9,66]. Meanwhile, 75 years later, it is fair to say that the quantum logic research programme failed in reaching its ambitious goals, the main problem being the failure to account for the tensor product description of compound quantum systems. However, at the level of monoidal categories, which has the tensor built in as a primitive concept, the passage from vector spaces to projective spaces proceeds without any loss of the structures that play a role in this paper [15]. Let FdHilb p be the category that has the same objects as FdHilb but whose morphisms are equivalence classes of FdHilb-morphisms, given by the equivalence relation In FdHilb p the states are now indeed the rays of the Hilbert space, together with one point representing the zero vector. The points for the two-dimensional Hilbert space in FdHilb p , the set FdHilb p (C, C 2 ), correspond to the points of the Bloch sphere.
Operationally, the meaningful scalars are the probability amplitudes. In FdHilb, the scalars are the complex numbers, hence too many, and in FdHilb p there are only two, hence too few. The solution consists of enriching FdHilb p with probabilistic weights, i.e. to consider morphisms of the form r · f , where r ∈ R + and f a morphism in FdHilb p . Therefore, let FdHilb wp be the category whose objects are those of FdHilb and whose morphisms are equivalence classes of FdHilb-morphisms for A detailed categorical account of FdHilb wp is given in [15]. The three categories considered above are related via inclusions: The theorems proven in this paper apply to all of these.

Diagrammatic calculus
In diagrammatic calculus, morphisms in SMCs are represented by boxes, input types by input wires and output types by output wires. Identities can be represented by wires only. Hence, 1 A : A → A and f : A → B are, respectively, are depicted as The input types and output type of a box can themselves be compound and the unit object I is represented by no wire; a morphism f : The identity on the monoidal unit 1 I : I → I is represented by, equivalently, an 'empty picture' (be it either a wire or a box)-hence the graphical representation of an equation of the form s = 1 I leaves the right-hand side empty. The symmetry natural isomorphisms σ A,B : A ⊗ B B ⊗ A are depicted as: These boxes 10 , straight wires and crossings of wires are the only graphical elements that make up the graphical language. We can compose morphisms in an SMC in two ways, and similarly, we can compose these graphical elements in two ways, depicted by connecting matching outputs and inputs by wires and tensor by juxtaposing wires or boxes side by side. Hence are respectively, are depicted as (16) where A, B, C and D may themselves be compound as in (14). Morphisms that play special roles may of course be given special graphical representations, sometimes other than boxes. The connection between this graphical language and the symbolic definition of SMCs is established as follows.
Definition 4.23. By isomorphism of diagrams we mean that there is a bijective correspondence between boxes and wires which preserves the manner in which boxes and wires are connectedsymmetry (cf (15)) is interpreted as a pair of crossing wires.
We will use equality '=' to denote isomorphic diagrams. Examples are Each represents (part of) an axiom of SMCs, namely commutation of: 10 Although 'box' should be understood figuratively: we allow ourselves other shapes as well.

38
This correspondence instantiates a perfect correspondence between the symbolic representation and the graphical presentation of SMCs: Theorem 4.24 ). An equation expressed in the symbolic language of SMCs follows from the axioms of SMCs if and only if it holds up to isomorphism of diagrams in the graphical language.
As Selinger pointed out in [68], this result straightforwardly extends to †-SMCs, when representing the adjoint by vertical reflection. This requires breaking the symmetry of the boxes used above, and f : A → B and f † : B → A will now be, respectively, depicted as (19) Note that reflecting twice leaves the box invariant, exposing the involutive nature of the adjoint.

Graphical reasoning
In the following sections, the graphical language will be preferred to conventional linear syntax. Before proceeding, we briefly discuss the question of equational reasoning in the graphical language: when do two diagrams denote the same mathematical object? When are two diagrams equal? There are two basic elements: isomorphism of diagrams, as discussed above; and substitution. Together these principles allow us to reason by rewriting.
The first principle, isomorphism, requires little elaboration beyond the discussion of section 4.3. The graphical language is a syntax for describing certain mathematical objects, namely the arrows of symmetric monoidal categories; theorem 4.24 states that two diagrams denote equal arrows when they are isomorphic (in the sense of definition 4.23).
However, the axioms of SMCs are rather weak, so the isomorphism principle will not suffice. We must impose other equations on our diagrams to obtain our results. For example, consider an arrow f : A → A. The statement that f is unitary is expressed by the equations Since this equation is a property of the particular morphism f , there is no hope to absorb it into some overarching global principle, in the way that theorem 4.24 absorbs the axioms of SMCs. Indeed, most of the equations in this paper are of this sort, naked identifications that must be imposed on the langauge. We deal with these via substitution. From a syntactic point of view, the meaning of an equation such as (20) is that whenever f † • f is found lurking inside some larger expression, it can be replaced by 1 A without changing the meaning of the containing expression. The same method of substitution applies in the graphical language.
The equations above can be easily translated into diagrams: To perform the substitution, we isolate the part of the diagram corresponding to one side of the equation, and form a new diagram by replacing that part with the other side of the equation.
Since two equal diagrams must have the same type, such a replacement is always possible. In general, when presented with a diagram d, any vertical line (which does not intersect any box or wire) divides the diagram into two parts, f and g, each of which is a valid diagram, and which are related by the equation d = f ⊗ g. Similarly, any horizontal line (which may cut wires, but avoids boxes and points where wires cross) will divide d into two sub-diagrams, f and g , which satisfy d = f • g . By a sequence of such horizontal and vertical divisions, the diagram can be cut into squares each of which contains an atomic element of the graphical language: a single box, a single crossing of wires or a single straight wire. Each atomic square corresponds to a single symbol in standard notation, and hence the factorization yields a symbolic expression equivalent to the diagram. The desired substitution can be performed on the symbolic expression, and a new diagram constructed. We can pass freely from the symbolic representation to the graphical representation and back.
The above justification for substitution is admittedly rather sketchy. Joyal and Street [47] provide a rigorous presentation with all the details. In practice, there is no need to divide a diagram into atomic pieces: it suffices to isolate the part to be substituted. We will apply this technique throughout this paper.

Correctness of graphical reasoning in ZX-calculus
The cautious reader will be aware that the T-rule of the ZX-calculus in section 2-'only the topology of the diagram matters'-stretches well beyond the graphical reasoning techniques outlined above. As well as being a †-SMC, ZX has a richer structure, and enjoys a correspondingly stronger analogue to theorem 4.24.

Definition 4.25. A dagger compact (closed) category is a †-SMC in which for each object
A there exists dual object A * and a morphism η A : I → A * ⊗ A subject to certain coherence equations (for which see [1,68]).
Throughout this paper, we will take A * = A; this self-duality requires some additional coherence axioms, for which see [70].
For the present purposes the required equations reduce to a very simple form. Denoting η A graphically by , the equations that need to be satisfied are This result may be used in the ZX-calculus due the last two equations of the S2-rule, which allows us to consider the caps and cups as part of the overall categorical structure. In what follows, these equations will typically not hold. A collection of many other theorems on diagrammatic languages can be found in [69].

Vector bases and state bases of observables
Before delving into the categorical treatment of observables, we briefly recall the relevant notions in the concrete setting of Hilbert space quantum mechanics. All Hilbert spaces involved will be finite dimensional. We will denote the set of rays in a Hilbert space H, which we refer to as the state space, by H itself. To distinguish between states and vectors, we write [[ψ]] to denote the unique state containing the (non-zero) vector |ψ . Similarly, i c i |v i is the state spanned by vector i c i |v i .
All observables considered will be non-degenerate:

for all i. Two vector bases (or two observables) are complementary (or mutually unbiased) if each vector (or state) in one of these vector bases (or observables) is unbiased relative to the other vector basis (or observable).
The key physical fact here is that when a state is unbiased to some observable, all the outcomes of that observable are equally likely. If classical data are encoded in the eigenbasis of some observable, for example a classical bit encoded as a qubit in the basis {|0 , |1 }, then measuring an unbiased observable will effectively erase that data, regardless of which outcome is observed.
A vector basis of a Hilbert space is characterized by the following property: Proof. Let f be a regular linear map, and letf be the corresponding map of states. Let  Given a vector basis, we can turn it into an observable by forgetting the phases of each of the basis vectors, which we formalize by passing to equivalence classes. To construct a vector basis from an observable, we have to choose a phase for each basis element. This construction factors over the construction of state bases as follows: Two mutually unbiased state bases (MUSBs) are coherent iff the erasing point of each is contained in the observable of the other.
These notions of coherence coincide along the bijection of proposition 5.5: and W ∈ sv(T ) we have i V = i v i | w 1 |v i = |w 1 and i W = |v 1 . Hence, we obtain coherence if w 1 |v 1 |w 1 = |w 1 and v 1 |w 1 |v 1 = |v 1 , that is, v 1 |w 1 = 1. This can be realized by choosing an appropriate overall phase for V relative to W.
Pairs of observables arise from coherent bases: Proof. Given a pair of MUVBs, forget all phases to obtain the corresponding pair of induced observables. Then adjoin as an erasing point to each of these a state of the other, in order to obtain coherent MUSBs. Now we can rely on proposition 5.8 to obtain coherent MUVBs that induce the same observable as the initial one.

Algebras and observables
In the introduction of this paper, we already indicated how conceptual analysis leads to an algebraic characterization of bases and observables. Here we review this theory in technical detail. Its main purpose is a characterization of bases in the language of †-SMCs-i.e. with no reference to vectors, sums, linear combinations, etc.-allowing bases to be defined in purely diagrammatic terms. As we shall also see, the diagrammatic presentation of bases admits very simple calculational rules in terms of the so-called 'spiders'-indeed, those that play a central role in the ZX-calculus.

Monoids, comonoids and observable structures
Recall that a monoid is a triple (M, •, 1 • ) with M a set, • an associative multiplication, and 1 • ∈ M is its unit. The multiplication is a map: and we can also represent the unit as a map e • : I → M :: where I := { } is a singleton set. The associativity and unit laws of the monoid can now be rewritten in terms of composition of maps and the Cartesian product: where σ M,M : (x, y) → (y, x). More generally, commutative monoids can be defined internally in any SMC.
By reversing the types and the order of composition we obtain a new concept. (X, δ, ) consisting of an object X equipped with a comultiplicationδ: X → X ⊗ X and a counit :

Definition 6.2. An internal cocommutative comonoid in an SMC is a triple
Note that in a †-SMC each internal commutative monoid is also an internal cocommutative comonoid, for δ := m † and := e † , and vice versa. Now consider a set X and let δ: X → X × X be the function that copies entries, i.e. δ :: x → (x, x). Since δ is a function it is also a relation, namely and as a relation it admits a relational converse, obtained by exchanging the two entries in the pairs that make up that relation. The relational converse to δ, relates pairs (x, x) ∈ X × X to x ∈ X , while it does not relate pairs (x, y) ∈ X × X for x = y to anything. Let : X → I be the function that erases entries, i.e. : x → . When conceived as a relation, admits a relational converse which now relates ∈ I to each x ∈ X . The copying/erasing pair (δ, ) is a comonoid in Rel, and the pair (m, e) consisting of their respective converses is a monoid in Rel. The pair (m, δ) moreover satisfies another remarkable property:

Remark 6.3. This interesting property first appeared in the literature as part of Carboni and
Walters' axiomatization of the category Rel in [12], where they introduced the notion of a Frobenius algebra in an SMC C, as a quintuple of morphisms where (X, m, e) is an internal commutative monoid and (X, δ, ) is an internal cocommutative comonoid, which together satisfy the Frobenius law-see (40) below.
This also shows that the basis {|ψ i } i is faithfully encoded in the linear map δ alone and that does not carry any additional data.

46
Conversely, all observable structures in FdHilb arise from bases: Theorem 6.7. [28] All observable structures in FdHilb are of the form (43).
So observable structures provide an axiomatic characterization of bases in †-SMC language, with no reference to the linear structure of the underlying vector spaces. Example 6.8. Each observable structure in FdHilb induces an observable structure in FdHilb wp in an obvious manner. But in the light of proposition 5.5, the correspondence in FdHilb between observable structures and vector bases becomes one between observable structures and state bases in FdHilb wp . Note that does not define a unique δ anymore. In addition, we need to specify that i |ψ i , the erasing point of the state basis, provides the unit for the comultiplication:  (35), (36) was noted by Edwards and one of the authors in [19]. The observable structures in FRel have been classified by Pavlovic in [60], in terms of groups. The notion of observable structure also applies to non-standard quantum-like theories. For example, it provides a generalized notion of basis for Spekkens' toy theory [19], despite the lack of an underlying vector space structure.
When the monoidal structure is strict, which is always the case in the graphical language, observable structures obey the following remarkable theorem, which follows from results in [53,54]-a direct derivation is given in [23]. Theorem 6.11 (normal form). Let δ n : A → A ⊗n be defined by the recursion (47) If f : A ⊗n → A ⊗m is a morphism generated from the observable structure (A, δ, ), the symmetric monoidal structure maps, and the adjoints of all of these, and if the graphical representation of f is connected, then we have (48) Hence, f only depends on the object A and the number of inputs n and outputs m. Theorem 6.12 (spider rules). When representing the unique morphism with n inputs and m outputs of theorem 6.11 as an 'n + m-legged spider': then these spiders obey the following composition rule: (49) i.e. when two spiders 'share legs' then these two spiders 'fuse' into a single spider. Also, the 1 + 1-legged spider must be equal to the identity: (50) and thirdly, spiders are invariant under 'leg swapping': (51) Conversely, given a family {δ † m • δ n |n, m ∈ N} of morphisms, the equations defining an observable structure can be recovered from (49), (50) and (51), hence providing an alternative characterization of observable structures now purely in terms of spiders.

Example 6.13. We have
The spider rules enabled us to define the ZX-calculus of section 2 in terms of spiders obeying rules (49) and (50), rather than algebras. The swapping of remaining rule (51) was eliminated by (implicitly) allowing freedom of how to spiders may be connected, absorbing the symmetry into the graph structure (see example 2.3). Here we have been more explicit. The angles labelling the spiders of the ZX-calculus will be explained below in section 7.

Proof. Equations
Diagrammatically, we denote f * and f * , respectively, as The green squares indicate the dependence of f * and f * on the observable structures on A and B; when there is no risk of confusion we omit the colouration and rely simply on the position 49 of the indicated corner to distinguish between f , f † , f * and f * . We follow [68] in representing the conjugate by horizontal reflection and the transpose by a 180 • rotation: which is consistent with the fact that  Proof. We will depict the two distinct observable structures in green and red, respectively. Then, repeatedly relying on †-compactness, we have so the circles induced by the two observable structures coincide.

Remark 6.22.
In the language of †-compact categories, the circle is formed by taking the trace of the identity morphism; in a finite dimensional Hilbert space this will always give the dimension, hence the terminology dim A.

Classical points and generalized bases
We now provide a category-theoretic counterpart to the role played by basis vectors/states in FdHilb and FdHilb wp . Definition 6.23. Given an observable structure (A, δ, ), a morphism k : I → A is a classical point iff it is a self-conjugate comonoid homomorphism, that is, graphically: Remark 6.24. The notation reflects 'sensitivity to conjugation', while the notation reflects 'invariance under conjugation'. We used in (52) to express invariance under conjugation, and given this fact, we used in (53) and (54). The following is a category-theoretic generalization of a notion of basis, either in the sense of proposition 5.2 or in the sense of proposition 5.4, which, respectively, applies to the categories FdHilb and FdHilb wp .

It is called a state basis iff for all B and all f, g: A → B, we have
One can easily construct new observable structures by combining old ones, as in the following proposition. Proposition 6.28. Two observable structures (A, δ A , A ) and (B, δ B , B ) canonically induce an observable structure on A ⊗ B with (57) and (58) Moreover, if k : I → A is a classical point for (A, δ A , A ) and k : I → B is a classical point for

Definition 6.29. We say that the monoidal tensor lifts vector bases iff for all vector bases
-hence it follows that the observable structure (A ⊗ B, δ A⊗B , A⊗B ) is also vector basis. Similarly, the monoidal tensor lifts state bases iff Since observable structures induce †-compact structures we have the following.

Proposition 6.30. Monoidal tensors always lift vector bases and state bases.
Proof. We have where the marked equivalences rely on the vector/state basis assumption.

Phase shifts and a generalized spider theorem
In the preceding section, we saw that observable structures correspond to bases of our state space; now we introduce an abstract notion of phase relative to a given basis, and generalize theorems 6.11 and 6.12 to incorporate such phase shifts. Proof. Associativity, commutativity and that † is the monoid's unit, i.e.

A monoid structure on points
follow immediately from internal monoid laws for (A, δ † , † )-see (39) above-and conjugation is an involution since δ † is self-conjugate-see corollary 6.18.
Example 7.4. Let δ Z : C 2 → C 2 ⊗ C 2 be defined by δ : |i → |ii . The induced multiplication Z is just point-wise multiplication in the standard basis: Indeed, the same will be true for any observable structure, provided we write the vectors in the corresponding basis.
As well as giving an involutive commutative monoid on the points of A, we can use δ † to lift this monoid up to the endomorphisms of A.
and we denote the range of by (A, A).
Proposition 7.6. The map is an isomorphism of involutive commutative monoids: that is, explicitly: and hence commutativity is inherited: Proof. Preservation of monoid multiplication and unit follows directly from the unit and commutativity law of the internal monoid. By the spider rules, we have that is, conjugation of points is mapped to the adjoint of endomorphisms.
Note that the notation of endomorphisms in (A, A) is invariant under 180 • rotation. This is justified by the following proposition.

Proposition 7.7. Each (ψ) ∈ (A, A) is equal to its transpose.
Proof. We have where we have relied on the spider rules.
Proof. By the spider rules, all three diagrams normalize to so they are all indeed equal.
The following proposition shows that the inner-product structure on points is subsumed by the commutative involutive monoid structure on points. Proposition 7.9. For points ψ, φ : I → A in C we have Proof. Using the definition of the transpose for φ † = (φ * ) * we obtain where again we used the spider rules.

The decorated spider theorem
Theorem 7.10 (normal form with points). If f : A ⊗n → A ⊗m is a morphism generated from the observable structure (A, δ, ), the symmetric monoidal structure maps, and the adjoints of all of these, points ψ i : I → A (exactly one occurrence for each i), and if the graphical representation of f is connected, then we have Proof. If neither δ nor δ † occurs in f , then the result is trivial. Otherwise, all points ψ i occurring in f may be lifted to (ψ i ); by virtue of proposition 7.8, these commute freely with the observable structure, and hence can all be collected together. The result now follows by applying theorem 6.11. Theorem 7.10 is a strict generalization of theorem 6.11: diagrams with equal numbers of inputs n and outputs m are equal whenever the product of points occurring in them is also equal. The theorem gives a specific normal form to which this entire class of diagrams is equal; we also have corresponding decorated spider rules. i.e. if two decorated spiders 'share legs', then these two spiders 'fuse' together into a single decorated spider provided we 'multiply decorations'. This is of course the form of the spider rule in the ZX-calculus. This situation admits generalization to arbitrary †-SMCs. The expression α α * denotes 'convolution' of α with itself; since the point † represents the uniform distribution over the basis defining δ, this definition indeed captures the usual understanding of what it means for a vector to be unbiased with respect to a basis. The following shows that this is exactly correct. Lemma 7.16. Let α, k : I → A be points of A such that α is unbiased and normalized, and k is classical, for (A, δ, ); then (72) Proof. We have where we relied on the fact that scalars are always self-transpose, used (53), used the adjoint to the unbiasedness law and finally used (54).

Remark 7.17. To retrieve the usual definition of unbiasedness,
we simply divide; however, since we operate in an arbitrary †-SMC, the scalars form a commutative monoid rather than a group, so dividing is not always possible. Hence the form (72) for the unbiasedness law.
Suppose that α is unbiased; then, by the spider rules, we have as required. The other direction of the proof is essentially the same.
Since unitary maps are invertible, they form a group, and this group structure transfers back onto the unbiased points. In particular, we have |θ 1 |θ 2 = |θ 1 + θ 2 , i.e. the operation is simply addition modulo 2π, which is an Abelian group with minus as inverse. This group of phases played a key role in proving universality of the ZX-calculus in section 2.4. Example 7.23. Phase groups can provide an algebraic witness for physical differences between theories. For example, as shown in [20], the toy model category Spek (cf example 4.20) and the category Stab (a restriction of FdHilb to the qubit stabilizer states) are essentially the same except for the phase groups of their respective qubits. In the case of Spek the phase group is the Klein four group Z 2 × Z 2 , whereas for Stab the phase group is the cyclic four group Z 4 . This difference in phase groups is closely connected with the fact that while states in Spek always admit a local hidden variable representation, in Stab there are states that do not, namely the GHZ state [58]. Example 7.24. Using decorated spider notation, we can set and for α unbiased relative to (A, δ, ), again by the decorated spider rules, it follows that these morphisms define an observable structure. Hence, each element of the phase group transforms the given observable structure into a new observable structure.

Complementarity is equivalent to the Hopf law
For observable structures (A, δ Z , Z ) and (A, δ X , X ) in a †-SMC, we will denote the corresponding induced †-compact structures respectively as (A, η Z ) and (A, η X ). First we study complementarity for pairs of observable structures on the same object with coinciding induced †-compact structures, and then we study the slightly more involved case of non-coinciding induced †-compact structures-cf remark 6.16.

Observable structures with coinciding †-compact structures
First we define complementarity for observable structures in arbitrary †-SMCs in a manner that makes explicit reference to their classical points, simply in analogy to the usual definition in the Hilbert space quantum theory, and then we show that this definition can be equivalently restated without any reference to points. • comp1 whenever z : We abbreviate complementary observable structures as COS.
Notation. Graphically we distinguish two distinct observable structures in terms of their colour. To emphasize that a classical point k : I → A is copied by an observable structure of one colour, say green, whereas it is unbiased with respect to an observable structure of another colour, say red, we denote them by that is, the outside colour indicates which observable structure copies this point, whereas the inner colour shows to which observable structure the point is unbiased.
The fact that we denote these points in a manner that is invariant under conjugation is a consequence of the trivial observation that classical points of one colour are not only selfconjugate for 'their own colour' (cf corollary 6.18), but also self-conjugate for 'another colour' provided induced †-compact structures coincide: and (A, δ X , X ) are observable structures with (75) then for classical points k : I → A of (δ Z , Z ) and k : I → A of (δ X , X ), we have (76) (77) In the updated notation for classical points of COS, the comonoid homomorphism laws governing classical points become and the mutual unbiasedness conditions become Proof. We need to show when applying the left-hand side and the right-hand side of the Hopf law to an element of the basis that both sides are equal, for all the elements of the basis. For the case of a vector basis, we have and for the case of a state basis we moreover have: where the first equation relies on coinciding †-compact structures.

The general case: dualizers as antipodes
The results of this section still hold when the †-compact structures induced by the two COS do coincide, provided we extend the observable structures formalism with dualizers, as described in [26] by Paquette, Perdrix and one of the present authors. Proof. The (A, η X )-conjugate to d Z X • k is, using lemma 8.7, since the (A, η Z )-transpose to k is also its adjoint.  [13,50,73], with the dualizer playing the role of the antipode.

Closed complementary observable structures
In this section, we study a special class of complementary observable structures, which we refer to as closed. While in the previous section we recovered the B -rule of the ZX-calculus, which captures complementarity on-the-nose, the B-rules capture this stronger form of complementarity for observable structures. The main theorem of this section provides a number of equivalent characterizations of closedness. The bottom line will be that certain pairs of observable structures form a scaled variant of the usual notion of a bialgebra [13,50,73]. The defining equations of a bialgebra involve a commutation condition of the multiplication of one algebra with the comultiplication of the other, as well as one of the (co)multiplication of one algebra with the (co)unit of the other. We identify the scaled analogues to these conditions for closed complementary observable structures in sections 9.2 and 9.1, respectively. Again, we assume that the †-compact structures induced by the complementary observable structures coincide.

Coherence for observable structures
In this section, we provide a category-theoretic generalization of the concrete notion of coherence for complementary vector and state bases-cf definition 5.7. The green and red observable structures of the ZX-calculus also enjoy this property. First we set and denote this scalar by √ D for reasons we explain below.
for this scalar is not arbitrary but is imposed by the fact that Z is the unit for the comultiplication δ Z . To see this, it suffices to post-compose both sides of coher1 with Z ⊗ X , which results in Dually, condition coher2 asserts the same relationship between † Z and (A, δ X , X ). Example 9.3. For the case of FdHilb and FdHilb wp this category-theoretic notion of coherence coincides with that of definition 5.7. For these cases, theorem 5.9 indicates that the requirement of coherence entails no loss of generality. Now we justify the notation √ D for .
Lemma 9.4. If (A, δ Z , Z ) and (A, δ X , X ) are two observable structures whose induced †compact structures coincide, then we have: Proof. By corollary 6.18, we know that Z and X are both self-conjugate; hence: The result follows from the fact that the dualizer is trivial when the induced †-compact structures coincide.

Commutation for observable structures
Several notions of commutation may apply to observable structures. In this section, we consider three of these, one of which will complete the definition of a scaled bialgebra; in the ZXcalculus, this is the powerful B2-rule. Remark 9.6. One should clearly distinguish the notions of commutation that we consider in this paper from that of commuting observables as found in most of the quantum theory literature. The kind of observables considered here are complementary, and are thus non-commuting in the usual sense. What we wish to expose here is that certain alternative notions of commutation, which are useful in computations, do apply for the specific case of complementary observables.
Notation. For an observable structure (A, δ Z , Z ), with classical points K Z depicted in green, and an observable structure (A, δ X , X ) depicted in red, we set for all k ∈ K Z : The use of two colours in this graphical representation reflects its dependence on two observable structures. We denote this morphism by X (k). By lemma 7.15 we know that, when k is unbiased for (A, δ X , X ), this morphism is unitary if and only if k † • k = D. Therefore, it is more convenient to consider classical points to have length √ D rather than being normalized. The comonoid homomorphism laws governing classical points then become where we somewhat abusively depict √ D by as in the case of coherent observable structures. If these observables are complementary, the equations of definition 8.1 become Remark 9.7. The similarity between the graphical notation for X (k) and that of the classical points for COS in section 8 anticipates theorem 9.24 below. Definition 9.8. Observable structure (A, δ Z , Z ) with classical points K Z , and observable structure (A, δ X , X ) with classical points K X , obey operator commutation iff for all k ∈ K Z and all k ∈ K X Definition 9.9. Observable structure (A, δ Z , Z ) with classical points K Z , and observable structure (A, δ X , X ), obey comultiplicative commutation iff for all k ∈ K Z Remark 9.10. While this equation seems akin to the defining equation for classical points, it carries a lot more structure. The reason for this is the involvement of two observable structures, which is exposed by the colouring. To see that the choice of scalars is not arbitrary, we can, for example, either assume coherence or the Hopf law for the observable structures, both resulting in Definition 9.13. A scaled bialgebra is a pair of coherent observable structures that satisfy bialgebraic commutation, that is, all together: Remark 9.14. As announced above, if we remove the scalars from the definition of a scaled bialgebra and adjoin the equation Z • † X = 1 I -which is trivial anyway when taken 'up to a scalar'-then we obtain the usual notion of a bialgebra [13,50,73]. Theorem 9.15. Each scaled bialgebra satisfies the Hopf law.
Proof. See the derivation of the B -rule in section 2.2; note that the 1st step uses †-compactness and the 4th step uses coherence i.e. the green comultiplication copies the red unit. While at first sight the three notions of commutation we have introduced in this section look very different, in fact, they boil down to the same thing in all of our example categories, as we shall see in theorem 9.24 below.

Closedness for observable structures
Definition 9.17. The classical points K Z of an observable structure (A, δ Z , Z ) are closed for another observable structure (A, δ X , X ) iff for all k, k ∈ K Z we have From the assumption that the induced †-compact structures coincide, since by corollary 6.18 and definition 6.23 we have that δ X , k and k are all self-conjugate, it follows that the composite k X k is also self-conjugate. Hence, setting: the closedness requirement is depicted graphically as Remark 9.18. If the observable structures are coherent, then the normalization condition is also trivially satisfied. If classical points were taken to be normalized, then we would take √ D · k X k rather than k X k in definition 9.17.
Remark 9.19. Again, similarly to remark 9.7, this notation that seems to indicate that k X k is unbiased to (A, δ X , X ) anticipates theorem 9.24 below.
We now show that on every Hilbert space we can find a pair of closed COS, and hence by theorem 5.9 we can find a pair of closed coherent COS. Proposition 9.20. In FdHilb there exist pairs of closed coherent COS on Hilbert spaces C n for any dimension n ∈ N.
Proof. Without loss of generality we take the first observable structure as being defined by the standard basis on C n , i.e. δ : |i → |i ⊗ |i with the erasing point † = i |i . Note that the multiplication induced by this observable structure is point-wise: We need to find a basis which contains † , is unbiased with respect to the standard basis and is closed under . It is routine to check that the family where j and k range from 0 to n − 1, and ω n = e 2π i/n , provides an orthonormal basis satisfying these conditions. We choose |0 as the erasing point.
is not closed when x is irrational. Similar counterexamples can be constructed for dimensions d 6. This shows that the notion of closed COS is strictly stronger than that of COS.
Since closed COS exist for all dimensions, for most practical purposes we can assume that COS are both coherent and closed. Closed COS moreover behave well with respect to the monoidal structure, in that the canonical induced observable structures of proposition 6.28, which are defined on the tensor space, inherit both complementarity and closedness. Proposition 9.23. Let (A, δ Z , Z ) and (A, δ X , X ) be coherent COS such that (δ Z , Z ) is closed with respect to (δ X , X ), and let (B, δ Z , Z ) and (B, δ X , X ) be coherent COS such that (δ Z , Z ) is closed with respect to (δ X , X ); then the canonical observable structure on the joint space (A ⊗ B, δ Z ⊗ δ Z , Z ⊗ Z ) is both complementary and closed with respect to (A ⊗ B, δ X ⊗ δ X , X ⊗ X ). Proof. We show all required implications graphically:

Our main theorem on pairs of closed observable structures
• bialge ⇒ comul: Here we assumed that √ D has an inverse.
• comul ⇒ closed: (88) • comul ⇒ oper: (89) • closed ⇒ bialge: The assumption that the classical points for the green observable structure constitute a vector basis, together with the fact that the monoidal tensor lifts vector bases, implies bialgebraic commutation. By coherence we have (91) so the result holds when there is a state basis for the green observable structure. Steps 2-4 assume that the induced †-compact structures coincide.
• oper ⇒ bialge: where the last step assumes that induced †-compact structures coincide. This concludes this proof.

Remark 9.25. We leave it to the reader to see how '2B (+ Coh)' factors into requirements for oper ⇒ comul and comul ⇒ bialge.
The examples of COS discussed in proposition 9.20 satisfy all the equations stated in theorem 9.24. In particular, they constitute scaled bialgebras. These equations are strictly stronger than the Hopf law by theorem 9.15, and hence all pairs of observable structures that satisfy them are COS.

Further group structure and the classical automorphisms
In section 7.4, we saw how the Abelian group of phase shifts arose naturally from the presence of unbiased points for a given observable structure. When we have a pair of COS, the two phase groups can interfere with each other, an interaction that arises from the special role of the classical points within each phase group.
In the following, suppose that (A, δ Z , Z ) and (A, δ X , X ) are coherent COS which jointly form a scaled bialgebra. Let U Z denote all the unbiased points for (δ Z , Z ), and let K Z denote its classical points; define U X and K X similarly. By virtue of complementarity we have K X ⊆ U Z and K Z ⊆ U X . Recall that by proposition 7.19, (U Z , Z ) is an Abelian group, isomorphic to the phase group of (δ Z , Z ). Theorem 10.1. K X is a subgroup of (U Z , Z ) either if K X is finite or if the two observable structures give rise to the same †-compact structure.
Proof. K X is always a submonoid of U Z because of the closure and coherence of the two observable structures; any finite submonoid is a subgroup. Alternatively, given a point x ∈ K X , its inverse in U Z is given by its conjugate with respect to the †-compact structure of (δ Z , Z ); by the definition of classicality, x is self-conjugate with respect to the †-compact structure of (δ X , X ). Hence, if these †-compact structures agree (cf proposition 8.2), x −1 = x in U Z , so K X is a subgroup. Remark 10.2. Shared †-compact structure is a powerful assumption. The proof above indicates that in the case of coinciding †-compact structures, not only do the classical points within U Z form a subgroup, but the resulting group is a product of copies of S 2 . In the case of qubits described by X and Z spins, the †-compact structure is shared, and the resulting classical subgroup is just S 2 . Proposition 10.3. For all x ∈ K X , Z (x) is a left action on U Z and, in particular, is a permutation on K X .
Proof. For any ψ : I → A, we have Z (x) • ψ = x Z ψ by definition; that this is a permutation on K X follows from the closure of K X . Theorem 10.4. Suppose that k ∈ K Z , and define K = X (k); then K is a group automorphism of U Z .
Proof. Graphically we depict K as: Since k ∈ U X , K is unitary and hence is invertible. We must show that if α ∈ U Z then also K • α ∈ U Z . This holds if and only if Z (K • α) is unitary; we show this directly: where the equations are by the comultiplication property, the unitarity of K , the unbiasedness of α and the unitarity of K again. It remains to be shown that K is a homomorphism of the group structure.
The equations are: the definition of K ; the bialgebra law; the classical property of k; and the definition of K .
The equation simply uses coherence of δ X and Z ; the result follows by dividing by the scalar factor as per lemma 7.16.
where we relied upon the comultiplication property of K and the unbiasedness of α, showing that the inverse K • α in U Z is K • α −1 as required. Hence, K is an automorphism of U Z .
is an Abelian group of automorphisms on U Z whose action is defined The possibility that the classical points will act as automorphisms on the corresponding phase group gives rise to 'interference' phenomena; this is illustrated by the example of the quantum Fourier transform of section 3.2.3.
In the following section we provide an example of the structure exposed in this section, for the spin Z and X observables, and show its role in the ZX-calculus.

Deriving the ZX -calculus
The preceding sections derived the basic properties of complementary observable structures in an arbitrary †-SMC. The resulting theory, although very rich, may feel rather abstract. This abstraction is a necessary consequence of working with arbitrary observable structures, without specifying exactly what they are. In any concrete setting, given a fixed pair of observable structures, the remainder of the structure can be constructed via simple direct computations. This section will focus on a single concrete example and demonstrate how to construct all the structures found in the earlier part of the paper for a given pair of complementary observables. Working in the category of finite dimensional Hilbert spaces, we choose a pair of complementary observable structures over C 2 -those corresponding to the Z and X spin observables-and show how this choice produces a concrete graphical theory for reasoning about qubits. The resulting theory is the ZX-calculus of sections 2 and 3: this section will justify the simplified syntax of the ZX-calculus and show that the rules of the calculus (shown in Figure 1) can be derived from the theorems of the preceding sections.
As already noted in examples 4.10 and 4.19, the category of finite dimensional Hilbert spaces is a †-SMC, and hence the use of graphical notation is justified by theorem 4.24. This is already enough to justify the first two generators of the ZX-calculus, namely the straight and crossing wires. Since qubits are the only system of interest, the type labels will be dropped from the edges of diagrams: all edges are implicitly labelled by C 2 . Having introduced the edges, we now turn to the vertices.
The first vertices to be considered are those defining the 'green' observable structure (δ Z , Z ), corresponding to the Z -spin observable, which is defined on C 2 via the linear maps, As discussed in example 7.22, the points that are unbiased for (δ Z , Z ) have the form |α Z = |0 + e iα |1 , where 0 α < 2π, and hence the phase group consists of matrices of the form The group (U Z , Z ) is therefore isomorphic to the circle, and the operation Z is addition modulo 2π. The Pauli-Z matrix is given by Z (π). Note also that e i e i so we can drop the 'corners' from the diagrammatic notation and simply write the negative angle in its place.
The spider rules (theorem 7.11) justify the first part of the ZX-calculus syntax, the family of 'green' vertices Z m n (α), along with rule (S1) and the first part of rule (S2). The X-observable structure is essentially the same: defining (δ X , X ) as follows: it is easy to verify that the corresponding phase group consists of rotations around X , that is, matrices of the form generated by the (unnormalized) unbiased points |α X = √ 2(cos α 2 |0 + i sin α 2 |1 ). We can simplify the notation as we did for the Z -observable: Of course, the decorated spider rules also apply to (δ X , X ), and this produces the 'red' family of the ZX-calculus, the vertices X m n (α). To complete rule (S2), we appeal to one property not derived from the formalism of complementary observables, namely the fact that (δ Z , Z ) and (δ X , X ) induce the same compact structure: Table 1. Translation between general and simplified graphical notation.
Hence, we obtain the remaining part of rule (S2), as well as the bending wires.
Further, since each object now comes with a unique †-compact structure, we can treat the category as †-compact, and appeal to theorem 4.26. This justifies rule (T), 'only the topology matters'.
Having noted that (δ Z , Z ) and (δ X , X ) generate the same †-compact structure, we may also appeal to lemma 9.4, that is Now, setting (D1), proposition 9.5 produces rule (D2) of the ZX-calculus. The definition of δ Z immediately shows that the classical points of the Z observable are |0 and |1 ; these points are unbiased for (δ X , X ), corresponding to the angles 0 and π in (U X , X ). Similarly, the classical points of δ X are |+ and |− , which are unbiased for (δ Z , Z ), and again correspond to the angles 0 and π. This being the case, we can again simplify the graphical notation, and dispense with the two-coloured dots used in sections 8 and 9 in favour of a simpler convention: a dot is unbiased for the observable structure of the same colour; if it is labelled by π or zero then it is classical for the other structure. In the ZX-calculus there is no need for dots of any other kind, so we disallow them. The translation between the more general graphical language and the simplified version used in the ZX-calculus is summarized in table 1.
Since each structure's classical points are unbiased for the other structure, (δ Z , Z ) and (δ X , X ) are complementary as per definition 8.1. Furthermore, we have † X = √ 2|0 and † Z = √ 2|+ , so the two observable structures are also coherent as in definition 9.1, implying rule (B1) of the ZX-calculus.
The classical points of Z correspond to the angles 0 and π within the phase group of X and vice versa. Since these angles form a two-element subgroup within the circle group, (δ X , X ) and (δ Z , Z ) form a closed pair of complementary observable structures, as per definition 9.17. Noting that the triple {|0 , |1 , |+ } forms a state basis for C 2 , the conditions for theorem 9.24 are satisfied: from whence, bialgebraic commutation (definition 9.11) implies rule (B2) and comultiplicative commutation (definition 9.9) implies rule (K1). The remaining piece of the structure to be described is the action of K Z on U Z discussed in section 10. Since X 1 1 (π ) = X we see that the non-trivial element of K Z sends |α Z → | − α Z ; X assigns elements of U Z to their inverses. The action of K X on U X is exactly dual. This provides the rule (K2) of the ZX-calculus. The group structure is summarized in table 2.
The preceding has shown that the ZX-calculus, with one exception, is readily deduced from the algebraic properties of the Z and X observables: indeed everything else followed from that choice. The single exception is the H vertex and the associated rule (C). The addition of a special symbol for the Hadamard gate is simply to make certain calculations easier, and it is not essential to the calculus.

Non-determinism, mixed states and classical data flow
The graphical treatment so far has been limited to pure states, and therefore does not capture the full behaviour of quantum measurements, decoherence, classical control, and a host of other phenomena of great practical importance in quantum computation. This section will present three different extensions of the graphical lanaguage to account for mixed states, and dispense with the simplified treatment of measurements as projections. We briefly describe each of these, and provide the same example in each one: the quantum teleportation protocol. For full details, see the references.
The most general is Selinger's CPM construction [68] which, given any category of 'pure states' and 'pure maps', constructs a category of 'mixed states' and 'completely positive maps'. Within the resulting category, Paquette, Pavlovic and one of the present authors defined a plethora of classicality-related concepts such as decoherence, measurement, probability distribution, stochastic map, function on classical data, etc., by relying on observable structure [25]-some of these results were already present in Carboni and Walters' seminal paper [12]. An axiomatic account of Selinger's CPM construction and classical concepts therein was provided by Perdrix and an author of this paper [16,29]; this introduces a new element into the graphical calculus corresponding to the environment, and a corresponding axiom (and some 'coherence conditions'). Finally, Perdrix and Coecke have introduced a version of the ZX-calculus parameterized by a set of variables that encode the outcome of measurements, and the dependence of other elements on them. These conditional diagrams have been used in the context of measurement-based quantum computation to study determinism and information flow [37].
These three approaches are alternatives, and depending on the situation, one may be preferable to another. [25,68] We extend the graphical language by a construction that is formally similar to the way in which classical probabilities are described by density operators. Graphically, classical data and classical operations are represented by a single wire, while quantum data and quantum operations are represented by double wires. The passage from a double wire to a single wire via a dot encodes decoherence. This encoding, 1 wire/box classical = 2 wires/boxes quantum , is also present in the Dirac notation; for a mixed state i ω i |ψ i ψ i | the classical probabilistic state (ω 1 , . . . , ω n ) occurs only once, while the quantum states occur both as a ket |ψ i and as a bra ψ i |. Pure quantum operations, controlled pure quantum operations and destructive measurements are of the form: respectively, where for clarity we choose to colour the classical wires in the colour of the observable structure whose classical points will encode the classical data. In fact, the spiders of the graphical language were initially introduced under the name classical structures in [27] to model classical data in quantum informatic protocols. Hence, in this setting, a single concept can account for quantum observables, complementarity and phases, as well as for classical information flow. We will be very brief on the use of spiders in order to describe classical data flow; see [25] for more details. Example 12.1. We claim that the following constitutes the quantum teleportation protocol, including the classical correction:

The CPM construction and classical concepts therein
The green and the red wires represent the two qubits Alice has to send to Bob to inform him of the measurement outcome. The Bell state, Bob's Pauli corrections and Alice's Bell basis measurement can be rewritten, respectively, as Hence, they are of the forms shown above.
The picture might seem somewhat complicated; the reason for this is that in order to display the quantum-classical distinction graphically, all the quantum operations are doubled. If we hide one of the copies it becomes much clearer what is going on: We demonstrate that the measurement and corrections in this picture are indeed the ones we claim them to be. By 'selecting' the control operation, that is, by inserting a classical point and the mixed ones, for example, as rounded variants of the pure ones: We then introduce a new graphical element , one for each object, which is coherent with the †-compact structure, and is subject to an axiom: which is valid for all pure morphisms f : A → B and g : A → C.
To obtain a precise match with the CPM construction, we also need a purification axiom which states that any mixed morphism can be obtained from a pure one by composing the latter with the environment. From (104) it follows that classical channels, that is are idempotent [29]. Here the colour reflects how the classical data was obtained, i.e., in which measurement. This idempotence is in fact the only equation that plays some role in the teleportation protocol, which now goes as follows:

Conditional diagrams [37]
While the previous two approaches represent classical information flow internally, as particular wires in the diagrams, the final alternative presentation of non-determinism ignores the issue of (classical) information flow and focuses on classical correlations that are mediated externally. Let V be a set of formal variables. A conditional diagram is a diagram D of the ZX-calculus and, for each Z and X vertex v in D, an associated subset U v ⊆ V, possibly empty. A valuation is a function f : V → {0, 1}. Each pair (D, f ) of a conditional diagram and a valuation determines an evaluated diagramD f , which is obtained from D by modifying the phase α at each vertex v as follows: and forgetting the sets U v . Each variable corresponds to a two-valued measurement and each valuation f corresponds to a possible set of measurement outcomes. The evaluated diagram D f corresponds to the process that occurs when the measurement outcomes corresponding to f 79 are observed, including both the side-effect of the measurement itself and any other operations which depend classically on its outcome.
Since each D f is a diagram of the ZX-calculus, it has an associated linear map, D f , as described in section 2.3. We construct a superoperator for D by summing over all possible valuations: Conditional diagrams can use the same equational rules as the plain ZX-calculus, with the proviso that a rule can only be applied in D if it could be applied to every D f . The conditional diagrams approach is essentially a formalization of the informal reasoning demonstrated in section 3.3.1, as the following example will clearly demonstrate. The crux of the encoding is that the subdiagram denotes the superoperator ρ → +|ρ|+ + −|ρ|− , and thus correctly encodes the measurement.
The conditional diagram approach is very well suited to the one-way model, since the quantum part of the system can be very complicated, whereas the classical information flow can usually be taken for granted. For many purposes, for example to translate a one-way pattern to a circuit, we need not evaluate any valuation, and can simply use the equational rules on the conditional diagram directly.
The measurement calculus [30] includes several commands that depend upon on classical bits, here ranged over by s and t: • s [M α j ] t -measure qubit j in the basis |0 + e (−1) s i(α+tπ ) |1 . • X s j and Z s j -apply a Pauli X operator (or Z) to qubit j, if s = 1; otherwise do nothing.
Taking V to be the set of measured qubits in the pattern, the measurement calculus can be

Conclusion
In this paper we introduced a simple and intuitive-but at the same time universal-graphical calculus for qubits, the ZX-calculus, and have given many example applications. We studied its mathematical underpinning in great detail, in particular: • We obtained a purely diagrammatic characterization of complementarity that extends to observable structures in arbitrary †-SMCs, in terms of the Hopf law: • We identified a strong form of complementarity for observable structures in arbitrary †-SMCs when the observable structures form a scaled bialgebra: We identified a number of equivalent alternative formulations: k ' k k , k k , k k , • We identified a group structure on phases for observable structures in arbitrary †-SMCs, and proved a generalization of the spider rules, now involving phases: .
As already mentioned at the end of the introduction, our results have meanwhile been applied in many contexts, ranging from quantum information and quantum foundations to automated reasoning. We end the paper by mentioning a number of issues that require further exploration: • Is there an elegant extension of the ZX-calculus to a ZXY-calculus? Note that this will necessarily involve the dualizers of section 8.2. Would such a ZXY-calculus be different when either modelling Stab or Spek? (cf example 7.23.) • What is the precise connection between the stabilizer formalism and our graphical reasoning scheme? (Given that both are adequate tools for studying measurement-based quantum computing.) Is the stabilizer formalism and quantum error correction fully captured by the ZX-calculus?
• Theorem 10.1 adds extra structure with a clear physical interpretation to the phase group: while the elements of K may be seen as measurement outcomes, the corresponding cosets can be interpreted as choices of measurements. This may provide the foundation for an axiomatic analysis of non-locality and contextuality. Some work in this direction has already been performed [39].
• Can the ZX-calculus elegantly model many-body states other than graph states, e.g. matrix product states or other states arising in condensed matter physics?
• Does our characterization of complementarity extend in some way or other to observables described by infinite dimensional Hilbert spaces? What is the connection of the above depicted laws with canonical commutation relations?