Geometry of Interaction for ZX-Diagrams

ZX-Calculus is a versatile graphical language for quantum computation equipped with an equational theory. Getting inspiration from Geometry of Interaction, in this paper we propose a token-machine-based asynchronous model of both pure ZX-Calculus and its extension to mixed processes. We also show how to connect this new semantics to the usual standard interpretation of ZX-diagrams. This model allows us to have a new look at what ZX-diagrams compute, and give a more local, operational view of the semantics of ZX-diagrams.


Introduction
Quantum computing is a model of computation where data is stored on the state of particles governed by the laws of quantum physics.The theory is well established enough to have allowed the design of quantum algorithms whose applications are gathering interests from both public and private actors [1, 2, 3].
One of the fundamental properties of quantum objects is to have a dual interpretations.In the first one, the quantum object is understood as a particle: a definite, localized point in space, distinct from the other particles.Light can be for instance regarded as a set of photons.In the other interpretation, the object is understood as a wave: it is "spread-out" in space, possibly featuring interference.This is for instance the interpretation of light as an electromagnetic wave.
The standard model of computation uses quantum bits (qubits) for storing information and quantum circuits [4] for describing quantum operations with quantum gates, the quantum version of Boolean gates.Although the pervasive model for quantum computation, quantum circuits' operational semantics is only given in an intuitive manner.A quantum circuit is understood as some sequential, low-level assembly language where quantum gates are opaque black-boxes.In particular, quantum circuits do not natively feature any formal operational semantics giving rise to abstract reasoning, equational theory or well-founded rewrite system.
From a denotational perspective, quantum circuits are literal description of tensors and applications of linear operators.These can be described with the historical matrix interpretation [4], or with the more recent sum-over-paths semantics [5,6] -this can be regarded as a wave-style semantics.In such a semantics, the state of all of the quantum bits of the memory is mathematically represented as a vector in a (finite dimensional) Hilbert

16:2
Geometry of Interaction for ZX-Diagrams space: the set of quantum bits is a wave flowing in the circuit, from the inputs to the output, while the computation generated by the list of quantum gates is a linear map from the Hilbert space of inputs to the Hilbert space of outputs.
In recent years, an alternative model of quantum computation with better formal properties than quantum circuits has emerged: the ZX-Calculus [7].Originally motivated by a categorical interpretation of quantum theory, the ZX-Calculus is a graphical language that represents linear maps as special kinds of graphs called diagrams.Unlike the quantum circuit framework, the ZX-Calculus comes with a sound and complete [8,9], well-defined equational theory on a small set of canonical generators making it possible to reason on quantum computation by means of local graph rewriting.
The canonical semantics of a ZX diagram consists in a linear operator.This operator can be represented as a matrix or through the more recent sum-over-path semantics [10].But in both cases, these semantics give a purely functional, wave-style interpretation to the diagram.Nonetheless, this graphical language -and its equational theory-has been shown to be amenable to many extensions and is being used in a wide spectrum of applications ranging from quantum circuit optimization [11,12], verification [13,14,15] and representation such as MBQC patterns [16] or error-correction [17,18].
The standard models for both quantum circuits and ZX-Calculus is therefore based on a wave-style interpretation.An alternative operational interpretation of quantum circuit following a particle-style semantics has recently been investigated in the literature [19].In this model, quantum bits are intuitively seen as tokens flowing inside the wires of the circuit.Formally, a quantum circuit is interpreted as a token-based automata, based on Geometry of Interaction (GoI) [20,21,22,23].Among its many instantiations, GoI can be seen as a procedure to interpret a proof-net [24]-graphical representation of proofs of linear logic [25]-as a token-based automaton [26,27].The flow of a token inside a proof-net characterises an invariant of the proof-its computational content.This framework is used in [19] to formalize the notion of qubits-as-tokens flowing inside a higher-order term representing a quantum computation-that is, computing a quantum circuit.However, in this work, quantum gates are still regarded as black-boxes, and tokens are purely classical objects requiring synchronicity: to fire, a two-qubit gate needs its two arguments to be ready.
As a summary, despite their ad-hoc construction, quantum circuits can be seen from two perspectives: computation as a flow of particles (i.e.tokens), and as a wave passing through the gates.On the other hand, although ZX-Calculus is a well-founded language, it still misses such a particle-style perspective.

In this paper, we aim at giving a novel insight on the computational content of a ZX term in an asynchronous way, emphasizing the graph-like behavior of a ZX-diagram.
Following the idea of using a token machine to exhibit the computational content of a proof-net or a quantum circuit, we present in this paper a token machine for the ZX-Calculus.To exemplify the versatility of the approach, we show how to extend it to mixed processes [28,29].To assess the validity of the semantics, we show how it links to the standard interpretation of ZX-diagrams.While the standard interpretation of ZX-diagrams proceeds with diagram decomposition as tensors and products of matrices, the tokens flowing inside the diagram really exploits the connectivity of the diagram.
This ability illustrates one fundamental difference between our approach and the one in [19].The latter follows a classical control approach: if qubits can be in superposition, each qubit inhabits a token sitting in one single position in the circuit.For instance, on the circuit on the right, the state of the two tokens Although the two tokens can be regarded as being in superposition, their position is not.In our system, tokens and positions can be superposed.The second fundamental difference lies in the asynchronicity of our token-machine.Unlike [19], we rely on the canonical generators of ZX-diagrams: tokens can travel through these nodes in an asynchronous manner.For instance, in the above circuit the orange token has to wait for the blue token before crossing the CNOT gate.As illustrated in Table 1, in our system one token can interact with multi-wire nodes.Finally, as formalized in Theorem 27, a third difference is that compared to [19], the token-machine we present is non-oriented: in the circuit above, tokens have to start on the left and flow towards the right of the circuit whereas our system is agnostic on where tokens initially "start".
Plan of the paper.The paper is organized as follows : in Section 2 we present the ZX-Calculus and its standard interpretation into Qubit, and its axiomatization.
In Section 3 we present the actual asynchronous token machine and its semantics and show that it is sound and complete with regard to the standard interpretation of ZX-diagrams.Finally, in Section 4 we present an extension of the ZX-Calculus to mixed processes and adapt the token machine to take this extension into account.
Proofs are in the appendix.

The ZX-Calculus
The ZX-Calculus is a powerful graphical language for reasoning about quantum computation introduced by Bob Coecke and Ross Duncan [7].A term in this language is a graph -called a string diagram-built from a core set of primitives.In the standard interpretation of ZX-Calculus, a string diagram is interpreted as a matrix.The language is equipped with an equational theory preserving the standard interpretation.

Pure Operators
The so-called pure ZX-diagrams are generated from a set of primitives, given on the right: the Identity, Swap, Cup, Cap, Green-spider and H-gate: , e0 e1 , e0 e1 , ...
We shall be using the following labeling convention: wires (edges) are labeled with e i , taken from an infinite set of labels E. We take for granted that distinct wires have distinct labels.
The real number α attached to the green spiders is called the angle.ZX-diagrams are read top-to-bottom: dangling top edges are the input edges and dangling edges at the bottom are output edges.For instance, Swap has 2 input and 2 output edges, while Cup has 2 input edges and no output edges.We write E(D) for the set of edge labels in the diagram D, and I(D) (resp.O(D)) for the list of input edges (resp.output edges) of D. We denote :: the concatenation of lists.ZX-primitives can be composed either sequentially or in parallel : We write ZX for the set of all ZX-diagrams.Notice that when composing diagrams with (_ • _), we "join" the outputs of the top diagram with the inputs of the bottom diagram.

Geometry of Interaction for ZX-Diagrams
This requires that the two sets of edges have the same cardinality.The junction is then made by relabeling the input edges of the bottom diagram by the output labels of the top diagram.
▶ Convention 1.We define a second spider, red this time, by composition of Green-spiders and H-gates, as shown on the right., with sequential and parallel composition.We write the Cap as η and the Cup as ϵ.We write Z n k (α) (resp, X n k ) for the green-node (resp, red-node) of n inputs, k outputs and parameter α and H for the H-gate.In the remainder of the paper we omit the edge labels when not necessary .Finally, by abuse of notation a green or red node with no explicit parameter holds the angle 0: ... ...
In the standard interpretation [7], a diagram D is mapped to a map between finite dimensional Hilbert spaces of dimensions some powers of 2: If D has n inputs and m outputs, its interpretation is a map D :

Properties and structure
In this section, we list several definitions and known results that we shall be using in the remainder of the paper.See e.g.[30] for more information.
Universality.ZX-diagrams are universal in the sense that for any linear map f : n → m, there exists a diagram D of ZX such that D = f .The price to pay for universality is that different diagrams can possibly represent the same quantum operator.There exists however a way to deal with this problem: an equational theory.Several equational theories have been designed for various fragments of the language [31,32,8,33,34,9].
Core axiomatization.Despite this variety, any ZX axiomatization builds upon the core set of equations provided in Figure 1, meaning that edges really behave as wires that can be bent, tangled and untangled.They also enforce the irrelevance on the ordering of inputs and outputs for spiders.Most importantly, these rules preserve the standard interpretation given in Section 2.2.We will use these rules -sometimes referred to as "only connectivity matters"-, and the fact that they preserve the semantics extensively in the proofs of the results of the paper.

Completeness.
The ability to transform a diagram D 1 into a diagram D 2 using the rules of some axiomatization zx (e.g. the core one presented in Figure 1) is denoted zx The axiomatization is said to be complete whenever any two diagrams representing the same operator can be turned into one another using this axiomatization.Formally: It is common in quantum computing to work with restrictions of quantum mechanics.Such restrictions translate to restrictions to particular sets of diagrams -e.g. the π 4 -fragment which consists of all ZX-diagrams where the angles are multiples of π 4 .There exists axiomatizations that were proven to be complete for the corresponding fragment (all the aforementioned references tackle the problem of completeness).
The developments of this paper are given for the ZX-Calculus in its most general form, but everything in the following also works for fragments of the language.
Input and output wires.An important result which will be used in the rest of the paper is the following: To see how this can be true, simply add cups or caps to turn input edges to output edges (or vice versa), and use the fact that we work modulo the rules of Figure 1.

Geometry of Interaction for ZX-Diagrams
When k = n, this isomorphism is referred to as the map/state duality.A related but more obvious isomorphism between ZX-diagrams is obtained by permutation of input wires (resp.output wires).We can also consider the notions of paths, distance and cycles of usual multi-graphs.We denote Paths(e 0 , e n ) the set of paths from edge e 0 to e n .We denote Paths(D) (resp.Cycles(D)) the set of paths (resp.cycles) of diagram D. For a path p, we denote |p| its length.We denote d(e 0 , e n ) the distance i.e. the length of the shortest path between e 0 and e n .

A Token Machine for ZX-diagrams
Inspired by the Geometry of Interaction [20,21,22,23] and the associated notion of token machine [26,27] for proof nets [24], we define here a first token machine on pure ZX-diagrams.
The token consists of an edge of the diagram, a direction (either going up, noted ↑, or down, noted ↓) and a bit (state).The idea is that, starting from an input edge the token will traverse the graph and duplicate itself when encountering an n-ary node (such as the green and red) into each of the input / output edges of the node.Notice that it is not the case for token machines for proof-nets where the token never duplicates itself.This duplication is necessary to make sure we capture the whole linear map encoded by the ZX-diagram.Due to this duplication, two tokens might collide together when they are on the same edge and going in different directions.The result of such a collision will depend on the states held by both tokens.For a cup, cap or identity diagram, the token will simply traverse it.As for the Hadamard node the token will traverse it and become a superposition of two tokens with opposite states.Therefore, as tokens move through a diagram, some may be added, multiplied together, or annihilated.

shall omit the commas and simply write (e d b). The set of tokens on D is written tk(D). A token state s is then a multivariate polynomial over C, evaluated in tk(D). We define tkS(D) := C[tk(D)] the algebra of multivariate polynomials over tk(D).
In the token state , where the t k,i 's are tokens, the components    ▶ Convention 6.In token states, the sum (+) stands for the superposition while the product stands for additional tokens within a given diagram.We follow the usual convention of algebras of polynomials: for instance, if t i stands for some token (e i d i b i ), then (t 1 + t 2 )t 3 = (t 1 t 2 ) + (t 1 t 3 ), that is, the superposition of t 1 ,t 2 flowing in D and t 1 ,t 3 flowing in D. Similarly, we consider token states modulo commutativity of sum and product, so that for instance the monomial t 1 t 2 is the same as t 2 t 1 .Notice that 0 is an absorbing element for the product (0 × t = 0) and that 1 is a neutral element for the same operation (1 × t = t).

Diffusion and Collision Rules
The tokens in a ZX-diagram D are meant to move inside D. The set of rules presented in this section describes an asynchronous evolution, meaning that given a token state, we will rewrite only one token at a time.The synchronous setting is discussed in Section 5.
▶ Definition 7 (Asynchronous Evolution).Token states on a diagram D are equipped with two transition systems: a collision system (⇝ c ), whose effect is to annihilate tokens; a diffusion sub-system (⇝ d ), defining the flow of tokens within D. The two systems are defined as follows.With X ∈ {d, c} and 1 ≤ j ≤ n i , if t i,j are tokens in tk(D), then using Convention 6,

to the rules of Table 1. In the table, each rule corresponds to the interaction with the primitive diagram constructor on the left-hand-side.
Variables x and b span {0, 1}, and ¬ stands for the negation.In the green-spider rules, e iαx stands for the the complex number cos(αx) + i sin(αx) and not an edge label.
Finally, as it is customary for rewrite systems, if (→) is a step in a transition system, (→ * ) stands for the reflexive, transitive closure of (→).
We aim at a transition system marrying both collision and diffusion steps.However, for consistency of the system, the order in which we apply them is important as illustrated by the following example.
▶ Example 8. Consider the equality given by the ZX equational theories: = .

Geometry of Interaction for ZX-Diagrams
If we drop a token with bit 0 at the top, we hence expect to get a single token with bit 0 at the bottom.We underline the token that is being rewritten at each step.This is what we get when giving the priority to collisions: Notice that the collision (c ↑ 0)(c ↓ 0) rewrites to 1, and therefore the product (d ↓ 0) × 1 = (d ↓ 0).If however we decide to ignore the priority of collisions, we may end up with a non-terminating run, unable to converge to (d ↓ 0): We therefore set a rewriting strategy as follows.
▶ Definition 9 (Collision-Free).A token state s of tkS(D) is called collision-free if for all s ′ ∈ tkS(D), we have s ̸ ⇝ c s ′ .
▶ Definition 10 (Token Machine Rewriting System).We define a transition system ⇝ as exactly one ⇝ d rule followed by all possible ⇝ c rules.In other words, t ⇝ u if and only if there exists t ′ such that t ⇝ d t ′ ⇝ * c u and u is collision-free.In [19], a token arriving at an input of a gate is blocked until all the inputs of the gates are populated by a token, at which point all the tokens go through at once (while obviously changing the state).The control is purely classical: it is causal.In our approach, the state of the system is global and there is no explicit notion of qubit.Instead, tokens collect the operation that is to be applied to the input qubits.

Strong Normalization and Confluence
The token machine Rewrite System of Definition 10 ensures that the collisions that can happen always happen.The system does not a priori forbid two tokens on the same edge, provided that they have the same direction.However this is something we want to avoid as there is no good intuition behind it: We want to link the token machine to the standard interpretation, which is not possible if two tokens can appear on the same edge.
In this section we show that, under a notion of well-formedness characterizing token uniqueness on each edge, the Token State Rewrite System (⇝) is strongly normalizing and confluent.).In the following, we shall simply refer to such subterms as "terms of s".

▶
▶ Example 12.In the (piece of) diagram presented on the right, the blue directed line p = (e 0 , e 1 , e 2 , e 3 , e 4 ) is a path.The orientation of the edges in the path is represented by the arrow heads, and e 3 for instance is ↓-oriented in p which implies that we have P (p, (e 3 ↑ x)) = −1.▶ Definition 13 (Well-formedness).Let D be a ZX-diagram, and s ∈ tkS(D) a token state on D. We say that s is well-formed if for every term t in s and every path p ∈ Paths(D) we have P (p, t) ∈ {−1, 0, 1}.
▶ Proposition 14 (Invariance of Well-Formedness).Well-formedness is preserved by (⇝): if s ⇝ * s ′ and s is well-formed, then s ′ is well-formed.◀ Well-formedness prevents the unwanted scenario of having two tokens on the same wire, and oriented in the same direction (e.g.(e 0 ↓ x)(e 0 ↓ y)).As shown in the Proposition 15, this property is in fact stronger.
▶ Proposition 15 (Full Characterisation of Well-Formed Terms).Let D be a ZX-diagram, and s ∈ tkS(D) be not well-formed, i.e. there exists a term t in s, and p ∈ Paths(D) such that |P (p, t)| ≥ 2. Then we can rewrite s ⇝ s ′ such that a term in s ′ has a product of at least two tokens of the form (e 0 , d, _).◀ Although well-formedness prevents products of tokens on the same wire, it does not guarantee termination: for this we need to consider polarities along cycles.
▶ Proposition 16 (Invariant on Cycles).Let D be a ZX-diagram, and c ∈ Cycles(D) a cycle.Let t 1 , . . ., t n be tokens, and s be a token state such that t 1 ...t n ⇝ * s.Then for every non-null term t in s we have This proposition tells us that the polarity is preserved inside a cycle.By requiring the polarity to be 0, we can show that the token machine terminates.This property is defined formally in the following.
▶ Definition 17 (Cycle-Balanced Token State).Let D be a ZX-diagram, and t a term in a token state on D. We say that t is cycle-balanced if for all cycles c ∈ Cycles(D) we have P (c, t) = 0. We say that a token state is cycle-balanced if all its terms are cycle-balanced.
To show that being cycle-balanced implies termination, we need the following intermediate lemma.This essentially captures the fact that a token in the diagram comes from some other token that "traveled" in the diagram earlier on.
▶ Lemma 18 (Rewinding).Let D be a ZX-diagram, and t be a term in a well-formed token state on D, and such that t ⇝ * i λ i t i , with (e n , d, x) ∈ t 1 .If t is cycle-balanced, then there exists a path p = (e 0 , ..., e n ) ∈ Paths(D) such that e n is d-oriented in p, and P (p, t) = 1.◀ We can now prove strong-normalization.
▶ Theorem 19 (Termination of well-formed, cycle-balanced token state).Let D be a ZXdiagram, and s ∈ tkS(D) be well-formed.The token state s is strongly normalizing if and only if it is cycle-balanced.◀ Intuitively, this means that tokens inside a cycle will cancel themselves out if the token state is cycle-balanced.Since cycles are the only way to have a non-terminating token machine, we are sure that our machine will always terminate.

Semantics and Structure of Normal Forms
In this section, we discuss the structure of normal forms, and relate the system to the standard interpretation presented in Section 2.
▶ Proposition 23 (Single-Token Input).Let D : n → m be a connected ZX-diagram with λ q |y 1,q , ..., y m,q ⟩⟨x 1,q , ..., x k−1,q , x k+1,q , ..., x n,q | Then: This proposition conveys the fact that dropping a single token in state x on wire a k gives the same semantics as the one obtained from the standard interpretation on the ZX-diagram, with wire a k connected to the state |x⟩.Proposition 23 can be made more general.However, we first need the following result on ZX-diagrams: λ ′ q |y 1,q , ..., y m,q ⟩ then: In the ZX-Calculus, the CNOT-gate (up to some scalar) can be constructed as follows: On classical inputs, this gate applies the NOT-gate on the second bit if and only if the first bit is at 1. Therefore if we apply the state |10⟩ to it we get 1 √ 2 |11⟩.We demonstrate how the token machine can be used to get this result.Following Proposition 25, we start by initialising the Token Machine in the token state (a 1 ↓ 1)(a 2 ↓ 0), matching the input state |10⟩.
We underline each step that is being rewritten, and take the liberty to sometimes do several rewrites in parallel at the same time.
The final token state corresponds to 1 √ 2 |11⟩, as described by Proposition 25.Notice that during the run, each invariants presented before holds and that due to confluence we could have rewritten the tokens in any order and still obtain the same result.This proposition is a direct generalization of the proposition 23.It shows we can compute the output of a diagram provided a particular input state.We can also recover the semantics of the whole operator by initialising the starting token state in a particular configuration.

▶ Theorem 27 (Arbitrary Wire Initialisation). Let D be a connected ZX-diagram, with
, and e ∈ E(D) ̸ = ∅ such that (e ↓ x)(e ↑ x) ⇝ * t x for x ∈ {0, 1} with t x terminal (the rewriting terminates by Corollary 22).Then: which matches the actual matrix of the standard interpretation.
▶ Remark 29.At this point, it is legitimate to wonder about the benefits of the token machine over the standard interpretation for computing the semantics of a diagram.Let us first notice that when computing the semantics of a diagram à la Theorem 27, we get in the token state one term per non-null entry in the associated matrix (the one obtained by the standard interpretation).We can already see that the token-based interpretation can be interesting if the matrix is sparse, the textbook case being Z n n whose standard interpretation requires a 2 n × 2 n matrix, while the token-based interpretation only requires two terms (each with 2n tokens).
Secondly, we can notice that we can "mimic" the standard interpretation with the token machine.Consider a diagram decomposed as a product of slices (tensor product of generators) for the standard interpretation.Then, for the token machine, without going into technical details, we can follow the strategy that consists in moving token through the diagram one slice at a time.This essentially computes the matrix associated with each slice and its composition.
The point of the token machine however, is that it is versatile enough to allow for more original strategies, some of which may have a worst complexity, but also some of which may have a better one.

Extension to Mixed Processes
The token machine presented so far worked for so-called pure quantum processes i.e. with no interaction with the environment.To demonstrate how generic our approach is, we show how to adapt it to the natural extension of mixed processes, represented with completely positive maps (CPM).This in particular allows us to represent quantum measurements.
M F C S 2 0 2 1 16:12 Geometry of Interaction for ZX-Diagrams

ZX-diagrams for Mixed Processes
The interaction with the environment can be modeled in the ZX-Calculus by adding a unary generator to the language [28,29], that intuitively enforces the state of the wire to be classical.We denote with ZX the set of diagrams obtained by adding this generator.Similar to what is done in quantum computation, the standard interpretation .for ZX maps diagrams to CPMs.If D ∈ ZX we define D as ρ → D † • ρ • D , and we set as ρ → Tr(ρ), where Tr(ρ) is the trace of ρ.There is a canonical way to map a ZX -diagram to a ZX-diagram in a way that preserves the semantics: the so-called CPM-construction [35].We define the map (conveniently named) CPM as the map that preserves compositions (_ • _) and (_ ⊗ _) and such that: Where [D] cj is D where every angle α has been changed to −α.
With respect to what happens to edge labels, notice that every edge in D can be mapped to 2 edges in CPM(D).We propose that label e induces label e in the first copy, and e in the second, e.g, for the identity diagram: e0 −→ e0 e0 In the general ZX-Calculus, it has been shown that the axiomatization itself could be extended to a complete one by adding only 4 axioms [29].

Token Machine for Mixed Processes
We now aim to adapt the token machine to ZX , the formalism for completely positive maps.To do so we give an additional state to each token to mimic the evolution of two token on CPM(D).

▶ Definition 31. Let D be a ZX-diagram. A -token is a quadruplet (p, d, x, y) ∈ E(D) × {↓
, ↑} × {0, 1} × {0, 1}.We denote the set of -tokens on D by tk (D).A -token-state is then a multivariate polynomial over C, evaluated in tk (D).We denote the set of -token-states on D by tkS (D) In other words, the difference with the previous machine is that tokens here have an additional state (e.g.y in (a ↓ x, y)).The rewrite rules are given in appendix in Table 3.
It is possible to link this formalism back to the pure token-states, using the existing CPM construction for ZX-diagrams.We extend this map by CPM : tkS (D) → tkS(CPM(D)), defined as: Since CPM(D) can be seen as two copies of D where is replaced by , each token in D corresponds to two tokens in CPM(D), at the same spot but in the two copies of D. The two states x and y represent the states of the two corresponding tokens.
We can then show that this rewriting system is consistent:  Table 2 The rewrite rules for ⇝ , where δ is the Kronecker delta.
The notions of polarity, well-formedness and cycle-balancedness can be adapted, and we get strong normalization (Theorem 19), confluence (Corollary 21), and uniqueness of normal forms (Corollary 22) for well-formed and cycle-balanced token states.

Conclusion and Future Work
In this paper, we presented a novel particle-style semantics for ZX-Calculus.Based on a token-machine automaton, it emphasizes the asynchronicity and non-orientation of the computational content of a ZX-diagram.Compared to existing token-based semantics of quantum computation such as [19], our proposal furthermore support decentralized tokens where the position of a token can be in superposition.
As quantum circuits can be mapped to ZX-diagrams, our token machines induce a notion of asynchronicity for quantum circuits.This contrasts with the notion of token machine defined in [19] where some form of synchronicity is enforced.
Our token machines give us a new way to look at how a ZX-diagram computes with a more local, operational approach.This could lead to extensions of the ZX-Calculus with more expressive logical and computational constructs, such as recursion.
As a final remark, we notice that this formalism naturally extends to other graphical languages for qubit quantum computation, and even for tensor networks.It suffices to adapt the diffusion rewriting steps to the generators at hand, which is always possible in the setting of finite dimensional Hilbert spaces, and if needs be to adapt the states in tokens to the dimension of the wire they go through (e.g. if a wire in a tensor network is of dimension 4, the state spans {0, 1, 2, 3}).

6
Rewrite Rules for Mixed Processes 7

Proofs of Section 3
Proof of Proposition 14.Let D be a ZX-diagram, and s be a well-formed token state on D. Consider a rewrite s ⇝ s ′ .We want to show that for all paths p in D, if P (p, t) ∈ {−1, 0, 1} for all terms t of s, then P (p, t ′ ) ∈ {−1, 0, 1} for all terms t ′ in s ′ .
M F C S 2 0 2 1 16:16 Geometry of Interaction for ZX-Diagrams Table 3 The rewrite rules for ⇝ , where δ is the Kronecker delta.
Let t be a term of s, and e 0 be the edge where a rewriting occurs.If the rewriting does not affect t, then the well-formedness of t obviously holds.If it does, and t ⇝ c,d q t q , we have to check two cases: Collision: let p ∈ Paths(D).If no tokens remain in the term t q , then P (p, t q ) = 0. Otherwise: if e 0 / ∈ p, then P (p, t q ) = P (p, t) if e 0 ∈ p, then P (p, t q ) = P (p, t) + 1 − 1 because the two tokens have alternating polarity Diffusion: let p ∈ Paths(D), and (e 0 , d, x) ⇝ d q λ q i∈S (e i , d i , x i,q ) (this captures all possible diffusion rules).
if e 0 / ∈ p and ∀i, e i / ∈ p, then P (p, t q ) = P (p, t) if e 0 ∈ p and ∃k ∈ S, e k ∈ p, then ∀i ̸ = k, e i / ∈ p, because the generator can only be passed through once by the path p.We have P (p, (e 0 , d, x)) = P (p, (e k , d k , x k,q )) by the definition of orientation in a path, which means that ∀q, P (p, t q ) = P (p, t) if e 0 ∈ p and ∀i, e i / ∈ p, then, either i) p ends with e 0 and e 0 is d-oriented in p, or ii) p starts with e 0 and e 0 is ¬d-oriented in p.In both cases, since that p \ {e 0 } is still a path, we have P (p \ {e 0 }, t) ∈ {−1, 0, 1} and since P (p, t q ) = P (p \ {e 0 }, t), we deduce that t q is still well-formed if e 0 / ∈ p but ∃k ∈ S, e k ∈ p, either e k is an extremity of p, or ∃k ′ , e k ′ ∈ p.In the latter case, the tokens in e k and e k ′ will have alternating polarity in p, so ∀q, P (p, t q ) = P (p, t) + 1 − 1.In the first case, we can show in a way similar to the previous point, that P (p, t q ) = P (p \ {e k }, t) ∈ {−1, 0, 1} ◀ Proof of Proposition 15.Let t be a term in s, and p = (e 0 , ..., e n ) such that P (p, t) ≥ 2 (if P (p, t) ≤ −2, can can simply take the reversed path).We can show that we can rewrite t into a token state with term t ′ = (e i , d, _)(e i , d, _)t ′′ .We do so by induction on n = |p| − 1.
If n = 0, we have a path constituted of one edge, such that |P (p, t)| ≥ 2.Even after doing all possible collisions, we are left with |P (p, t)| tokens on e 0 , and oriented accordingly.
For n + 1, we look at e 0 , build p ′ := (e 1 , ..., e n ), and distinguish four cases.If there is no token on e 0 , we have P (p ′ t) = P (p, t), so the result is true by induction hypothesis on p ′ .If we have a product of at least two tokens going in the same direction, the result is directly true.If we have exactly one token going in each direction, we apply the collision rules, and still have P (p ′ , t) = P (p, t), so the result is true by induction hypothesis on p ′ .Finally, if we have exactly one token (e 0 , d, _) on e 0 , either e 0 is not d-oriented, in which case P (p ′ , t) = P (p, t) + 1, or e 0 is d-oriented, in which case the adequate diffusion rule on (e 0 , d, _) will rewrite t ⇝ q t q with P (p ′ , t q ) = P (p, t).◀ Proof of Proposition 16.The proof can be adapted from the proof of Proposition 14, by forgetting the cases related to the extremity of the paths, as well as the null terms (which can arise from collisions).It can then be observed that the quantity P in this simplified setting is more than bounded to {−1, 0, 1}, but preserved.◀ Proof of Lemma 18.We reason by induction on the length k of the rewrite that leads from t to i λ i t i .
If k = 0, we have (e n , d, x) ∈ t, so the path p := (e n ) is sufficient.
For k + 1, suppose t ⇝ i λ i t i , and 1 .By induction hypothesis, there is p = (e 0 , ..., e n ) such that P (p, t 1 ) = 1.We now need to look at the first rewrite from t.
[⇐]: We are going to show for the reciprocal that, if t is well-formed, and if the constraint P (c, t) = 0 is verified for every cycle c, then any generator in the diagram can be visited at most once.More precisely, we show that if a generator is visited in a term t, then it cannot be visited anymore in all the terms derived from t.However, the same generator can be visited once for each superposed term (e.g.once in t 1 and once in t 2 for the token state t 1 + t 2 ).Consider an edge e with token exiting generator g in the term t.Suppose, by reductio ad absurdum, that a token will visit g again in t ′ (obtained from t), by edge e n with orientation d.By Lemma 18, there exists a path p = (e 0 , ..., e n ) such that P (p, t) = 1 and e n is d-oriented.Since e / ∈ p (we would not have a path then), then p ′ := (e 0 , ..., e n , e) is a path (or possibly a M F C S 2 0 2 1 16:18 Geometry of Interaction for ZX-Diagrams cycle) such that P (p ′ , t) = 2.This is forbidden by well-formedness.Hence, every generator can be visited at most once.As a consequence, the lexicographic order (#g, #tk) (where #g is the number of non-visited generators in the diagram, and #tk the number of tokens in the diagram) strictly reduces with each rewrite.This finishes the proof of termination.◀ Proof of Proposition 20.We are going to reason on every possible pair of rewrite rules that can be applied from a single token s.Notice first, that if the two rules are applied on two different terms of s, such that the rewriting of a term creates a copy of the other, they obviously commute, so In the case where s = αt + βt 1 + s 0 such that t 1 ⇝ s ′ and t ⇝ i λ i t i , we have: Then, we can, in the following, focus on pairs of rules applied on the same term.The term we focus on is obviously collision-free, by hypothesis and by preservation of collision-freeness by ⇝.
Suppose the two rewrites are applied on tokens at positions e and e ′ .We may reason using the distance between the two edges.
the case d(e, e ′ ) = 0 would imply a collision, which is impossible by collision-freeness if d(e, e ′ ) ≥ 3, the two rules still don't interfere, they commute (up to collisions which do not change the result) if d(e, e ′ ) = 2, there will be common collisions (i.e.collisions between tokens created by each of the diffusions), however, the order of application of the rules will not change the bits in the tokens we will apply a collision on, so the result holds if d(e, e ′ ) = 1, then the two tokens have to point to the same generator.If they didn't, (e, e ′ ) would form a path such that |P ((e, e ′ ), t)| = 2 which is forbidden by well-formedness.We can then show the property for all generators: Case e0 e1 .
Let us first notice that, using the map/state duality, we have . Hence, we can, w.l.o.g.consider in the following that n = 1.We also notice that thanks to the confluence of the rewrite system, we can consider diagrams up to "topological deformations", and hence ignore cups and caps.
We then proceed by induction on the number N of "non-wire generators" (i.e.Z-spider, X-spiders and H-gates) of D, using the fact that the diagram is connected: If N = 0, then D = , where the result is obvious.
. The result in this base case is then a straightforward verification (self-loops in green and red nodes simply give rise to collisions that are handled as expected).
For N + 1, there exists D ′ with N non-wire generators and such that (we should actually take into account the self loops, but they do not change the result).Let us look at the first two cases, since the last one can be induced by composition.
, then D ′ is necessarily connected, by connectivity of D. Then: where by induction hypothesis λ ′ q |y 1,q , ..., y m,q ⟩ so: , we can decompose D ′ in its connected components: where the first is the diffusion through a Z-spider, and the second set of rewrites is the induction hypothesis applied to each connected component.

Proof of Lemma 24.
There exist several methods to build a diagram D f such that D f = f , using the universality of quantum circuits together with the map/state duality [7], or using normal forms [34].The novelty here is that the diagram should be connected.This problem can be fairly simply dealt with: Suppose we have such a D f that has several connected components.We can turn it into an equivalent diagram that is connected.Let us consider two disconnected components of D f .Each of these disconnected components either has at least one wire, or is one of { α , α }.In either case, we can use the rules of ZX ((I g ) or (H)) to force the existence of a green node.These green nodes in each of the connected components can be "joined" together like this: q=1 λ q |x 1,q , ..., x n,q ⟩.Consider now a derivation from the token state (a ′ ↓ 0) in D • D ′ : ... .We can easily see that a rewriting of the token states (e ↓ 0)(e ↑ 0) and (e ↓ 1)(e ↑ 1) in D correspond step by step to a rewriting of the token states (e 0 ↓ 0)(e 1 ↑ 0) and (e 0 ↓ 1)(e 1 ↑ 1) in D ′ .We can then focus on D ′ , whose interpretation is taken to be q=1 λ ′ q y ′ 1,q , ..., y ′ m+1,q x ′ 1,q , ..., x ′ λ ′ q δ 0,y ′ m+1,q δ 0,x ′ n+1,q y ′ 1,q , ..., y ′ m,q x ′ 1,q , ..., x ′ n,q + 2 m+n+2 q=1 λ ′ q δ 1,y ′ m+1,q δ 1,x ′ n+1,q y ′ 1,q , ..., y ′ m,q x ′ 1,q , ..., x ′ n,q We now have to consider two cases: D ′ is still connected: By Proposition 23, for x ∈ {0, 1}: We hence have (e 0 ↓ 0)(e 1 ↑ 0) ⇝ * t 0 = 2 m+n+2 q=1 λ ′ q δ 0,y ′ m+1,q δ 0,x ′ n+1,q i (a i ↑ x ′ i,q ) i (b i ↓ y ′ i,q ) (e 0 ↓ 1)(e 1 ↑ 1) ⇝ * t 1 = 2 m+n+2 q=1 λ ′ q δ 1,y ′ m+1,q δ 1,x ′ n+1,q i (a i ↑ x ′ i,q ) i (b i ↓ y ′ i,q ) so t 0 + t 1 corresponds to the interpretation of D. D ′ is now disconnected: Since D was connected, the two connected components of D were connected through e.Hence, D ′ only has two connected components, one connected to e 0 and the other to e 1 .By applying Proposition 23 to both connected components, we get the desired result.◀

Proof of Section 4
Proof of Theorem 32.Diffusion rules are trivial.Beware in the case of the Ground, as the CPM will produce a cup, the ⇝ does not produce a new token when applying the Trace-Out rule, meanwhile the ⇝ machine will do two rewriting rules to pass through the cup.◀

▶
Convention 2. We write σ for a permutation of wires, i.e any diagram generated by
Theorem 3 is essential: it allows us to transpose notions of graphs into ZX-Calculus.It is for instance possible to define a notion of connectivity.▶ Definition 4 (Connected Components).Let D be a non-empty ZX-diagram.Consider all of the possible decompositions with D 1 , ..., D k ∈ ZX and σ, σ ′ permutations of wires: largest such k is called the number of connected components of D. It induces a decomposition.The induced D 1 , ..., D n are called the connected components of D. If D has only one connected component, we say that D is connected.
the state of n tokens in the process of flowing in the diagram D. A token state is understood as a superposition -a linear combinationof multi-tokens flowing in the diagram. e0 Definition 11 (Polarity of a Term in a Path).Let D be a ZX-diagram, and p ∈ Paths(D) be a path in D. Let t = (e, d, x) ∈ tk(D).Then:

▶ Proposition 20 (▶
Local Confluence).Let D be a ZX-diagram, and s ∈ tkS(D) be wellformed and collision-free.Then, for all s 1 , s 2 ∈ tkS(D) such that s 1 ⇝ s ⇝ s 2 , there exists s ′ ∈ tkS(D) such that s 1 ⇝ * s ′ * ⇝ s 2 .◀ Corollary 21 (Confluence).Let D be a ZX-diagram.The rewrite system ⇝ is confluent for well-formed, collision-free and cycle-balanced token states.◀ ▶ Corollary 22 (Uniqueness of Normal Forms).Let D be a ZX-diagram.A well-formed and cycle-balanced token state admits a unique normal form under the rewrite system ⇝.◀ M F C S 2 0 2 1 16:10 Geometry of Interaction for ZX-Diagrams

28 .
If we take back the diagram from Example 26 and decide to initialize any wire e of the diagram in the state (e ↓ 0)(e ↑ 0) + (e ↓ 1)(e ↑ 1) and apply the rewriting as in Theorem 27 we in fact end up with the token state 1

▶
Example 30.A ZX -diagram and its associated CPM construction is shown on the right (without names on the wires for simplicity).