The ZX calculus and the ZH calculus use diagrams to denote and to compute properties of quantum operations, and other multi-linear operators described by tensor networks.
These calculi involve `rewrite rules', which are algebraic manipulations of the tensor networks through transformations of diagrams.
The way in which diagrams denote tensor networks is through a semantic map, which assigns a meaning to each diagram in a compositional way.
Slightly different semantic maps, which may prove more convenient for one purpose or another (e.g., analysing unitary circuits versus analysing counting complexity), give rise to slightly different rewrite systems.
Through a simple application of measure theory on discrete sets, we describe a semantic map for ZX and ZH diagrams for qudits of any dimension ${D \!>\! 1}$, well-suited to represent unitary circuits, and admitting simple rewrite rules.
In doing so, we reproduce the `well-tempered' semantics of Ref. [19] for ZX and ZH diagrams in the case ${D \!=\! 2}$.
We demonstrate rewrite rules for the `stabiliser fragment' of the ZX calculus and a `multicharacter fragment' of the ZH calculus; and demonstrate relationships which would allow the two calculi to be used interoperably as a single `ZXH calculus'.

§ INTRODUCTION

The ZX calculus [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] and the ZH calculus [30, 31, 32, 33, 34, 35, 19] are notational systems for quantum computation, and other problems which can be mapped onto tensor networks [33, 36, 37, 38, 39, 40].
They use annotated graphs — `ZX diagrams' and `ZH diagrams' — to denote tensor networks, in a way which may be used to represent quantum circuits.
They are also equipped with with rules to perform computations without recourse to exponentially large matrices, through transformations of diagrams.
While complicated procedures may require diagrams of mounting complexity to analyse, in many cases the ZX- and ZH-calculi simplify the analysis of many-qubit procedures.
In recent years, it has also become more common to consider versions of the ZX- and ZH-calculi which denote operations on qudits [8, 12, 23, 27, 28, 29, 35, 41].
These promise the same benefits for analysis of procedures on qudits, as the corresponding rewrite systems on qubits.

Most treatments of the ZX-calculus [3, 4, 5, 6, 7, 9, 10, 11, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27] and the ZH-calculus [30, 31, 32, 19, 34, 35] are `scalar exact', in that diagram transformations preserve the exact meaning as an operator over $\C$, without glossing over normalisation factors.
Such scalar factors are irrelevant for certain applications (e.g., the analysis of quantum circuits without measurement); but they are important when describing procedures which have probabilistic elements (e.g., postselection), or problems in which the numerical value of some coefficient is the subject of interest [40].
To keep track of scalar factors, one might have to account for changes to the normalising factors with each rewrite, either explicitly or through scalar gadgets: disconnected subdiagrams which obliquely denote normalising factors.

It is of practical interest to consider what presentations of the ZX- or ZH-calculus avoid frequent changes to the scalar gadgets or normalising factors associated with the diagrams.
An appropriate choice of presentation may also allow the two calculi to be combined into a single rewrite system (a `ZXH calculus') to transform diagrams using the rules of each [19, 36, 38], allowing the user to make use of the intuitions offered by both calculi.

In previous work [19], one of us addressed this issue of bookkeeping of scalars for ZX- and ZH-diagrams on qubits, by considering a carefully modified notational convention for these diagrams.
The result, described as `well-tempered' versions of these calculi, are scalar exact but do not introduce modifications to the scalar factors for the most often-used rewrites.
These well-tempered versions of the ZX- and ZH-calculi are also well-suited to work together, representing a convenient presentation of a ZXH calculus.
However, while the `well-tempered' notation was determined systematically and led to simpler rewrite rules, the notational convention itself (i.e., the meanings which are assigned to the simplest diagrams) is slightly unweildly.
Furthermore, this analysis did not address the same issue of scalars which arises for versions of these calculi for qudits of dimension $D > 2$.

In this work, we consider how different normalisations of the ZX- and ZH-calculus may be expressed in a more uniform way, by representing operators on qudits (of any fixed dimension $D>1$) through the use of integrals with respect to a discrete measure.
We may summarise these results, as follows.

Versatile generators for ZX and ZH diagrams.

Let $D > 1$ be an integer, and let $\cH \cong \C^D$.
We present a version of the ZX calculus on qudits with state-space $\cH$, with generator nodes

\begin{equation}
\label{eqn:ZXnodeFamilies}
\begin{gathered}
\qquad
\tikzfig{ZX-green-phase-dot-arity}
\;,\qquad
\tikzfig{ZX-red-phase-dot-arity}
\;,\qquad
\tikzfig{ZX-H-plus-box}
\;,\qquad
\tikzfig{ZX-H-minus-box}
\;\;,
\end{gathered}
\end{equation}

where $m,n \in \N$ and $\Theta: \Z \to \C$ is a function which assigns amplitudes to elements of $[D]$.
We call these generators `green dots', `red dots', and `Hadamard plus boxes', and `Hadamard minus boxes'.
(In using functions $\Theta: \Z \to \C$ to parameterise green and red dots, we loosely follow Wang [23].
When $\Theta$ is absent, we assume the constant function $\Theta(x) = 1$; if instead a parameter $\theta \in \R$ is provided, we assume the function $\Theta(x) = \e^{i\theta x}$.)
We also present a version of the ZH calculus for qudits with Hilbert space $\cH$, with generator nodes

\begin{equation}
\label{eqn:ZHnodeFamilies}
\begin{gathered}
\qquad\;\;
\tikzfig{ZH-white-dot-arity}
\tikzfig{ZH-H-phase-box-arity}
\tikzfig{ZH-gray-dot-arity}
\tikzfig{ZH-gen-not-dot}
\;\;,
\end{gathered}
\end{equation}

where $m,n \in \N$, $c \in \Z$, and $\mathrm{A} : \Z \to \C$.
We call these generators `white dots', `H-boxes', `gray dots', and `generalised-not dots'.
We follow Ref. [19] in considering the gray and not dots to be (primitive) generators, rather than gadgets or `derived generators', e.g., as in Refs. [30, 35].

(We adopt the convention of using functions $\mathrm A: \Z \to \C$ for the sake of uniformity with our presentation of ZX diagrams, but allow a complex unit $\alpha \in \C^\times$ to stand for the function $\mathrm{A}(t) = \alpha^t$.
We define some short-hand notations below for functions $\mathrm{A}(t) = \e^{2\pi i c t/D}$ for $c \in \Z$.)

Simple semantics for qudit ZX and ZH generators, via integrals.

We label the standard basis states of $\cH$ by $\ket{x}$ for $x \in [D]$, where we take the somewhat unconventional choice
We suggest this convention to support rewrites which become possible for arbitrary $D>1$.
This choice is independent of the main idea of our work, which is the use discrete integrals such as the one shown in Eqn. (<ref>); this article promotes a few other such independently motivated conventions (such as the amplitude functions $\Theta, \mathrm A: \Z \to \C$) which seem fruitful.

\begin{equation}
\;\,=\;\,
{(-\tfrac{1}{2}D, \tfrac{1}{2}D] \;\cap\; \Z}
\;\,=\;\,
\{ L_D,\, L_D{+}1,\, \ldots,\, U_D{-}1,\, U_D\}
\end{equation}

for ${L_D = -\lfloor \!\!\:\tfrac{D-1}{2}\!\!\: \rfloor}$ and $U_D = \lfloor \!\!\;\tfrac{D}{2}\!\!\; \rfloor$.
(Note that $[D] = \{0,1\}$ for $D = 2$, but that $L_D$ is negative for ${D \!>\! 2}$.)
We define simple semantics for both sets of generators above, using a notion of integration over $[D]$.
Specifically: we consider a measure $\mu$ on subsets of $[D]$, defined by $\mu(S) = \#S \cdot \nu^2$, where $\#S$ is the cardinality of $S \subset [D]$ and $\nu > 0$ is some real number which we later characterise.
For functions $f: \Z \to \C$, this allows us to define integrals over $[D]$,

\begin{equation}
\label{eqn:introducing-discrete-integral}
\int\limits_{\mathclap{x \in [D]}}
\;:=\;
\int\limits_{\mathclap{x \in [D]}}
f(x) \; \mathrm d\mu(x)
\;:=\;
\sum_{x \in [D]}\! f(x) \, \nu^2\,,
\end{equation}

where for the sake of brevity, we leave the measure $\mu$ implicit in the left-hand expression.
Such integrals allow us to express sums with certain normalising factors more uniformly, by absorbing the factors into the measure $\mu$ by an appropriate choice of $\nu > 0$.
We also define non-normalised point-mass distributions $\kket{x} = \tfrac{1}{\nu} \ket{x} \in \cH$, expressly to obtain

\begin{equation}
%	\bbra{z} \Biggl(\;\;\;
%		\int\limits_{\mathclap{x \in [D]}}
%			f(x) \; \kket{x}
%	\Biggr)
%	\;=\;
\int\limits_{\mathclap{x \in [D]}}
\bbracket{z}{x}  \; f(x)
%	\;=\;
%		 \sum_{x \in \Z_D}\! f(x) \, \bracket{z}{x}
\;=\;
\end{equation}

[4]
similarly to the way that Dirac measures may be used with integration over $\R$.
(We elaborate on this notion in Section <ref>.)
We then define a semantic map $\sem{\,\cdot\,}$ on the ZX and ZH generators as follows:

\begin{equation}
\label{eqn:idealised-ZX-ZH-integrals}%
\mspace{-120mu}
\begin{aligned}{}
\Biggsem{\!\!\!\tikzfig{ZX-green-phase-dot-arity}\!\!\!}
\,&=\,
\int\limits_{\mathclap{x \in [D]}}
\Theta(x) \; \kket{x}^{\!\otimes n}\bbra{x}^{\!\!\;\otimes m}
%	    \;\mathrm d\mu(x)
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\!\!\: \tikzfig{ZX-H-plus-box} \!\!\:}
\,&=
\mathop{\int \!\!\!\! \int}\limits_{\mathclap{x,k \in [D]}}
\e^{2\pi i k x \!\!\;/\!\!\; D} \kket{k}\bbra{x}
%  		\; \mathrm d\mu(x) \; \mathrm d\mu(k)
\mspace{-100mu}
% -----------------------------------------------------
\\[.75ex]
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZX-red-phase-dot-arity}\!\!\!}
\,&=\,
\int\limits_{\mathclap{k \in [D]}}
\Theta(k) \; \kket{\smash{\omega^{-k}}}\sox{n} \bbra{\smash{\,\omega^{k}\,}}\sox{m}
%	    \;\mathrm d\mu(k) ,
%  	\mspace{-30mu}
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\!\!\: \tikzfig{ZX-H-minus-box} \!\!\:}
\,&=\,
\mathop{\int \!\!\!\! \int}\limits_{\mathclap{x,k \in [D]}}
\e^{-2\pi i k x \!\!\;/\!\!\; D} \kket{k}\bbra{x}
%  		 \; \mathrm d\mu(x) \; \mathrm d\mu(k)
\mspace{-100mu}
% -----------------------------------------------------
\\[.75ex]
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZH-H-phase-box-arity}\!\!}
\,&=
\mathop{\int \!\!\!\!\int}_{%
\mathclap{
{\substack{x \in [D]^m \\ y\in [D]^n}}
\!\mathrm{A}(x_1 \!\cdot \!\cdot\! \cdot x_m y_1 \!\cdot \!\cdot\! \cdot  y_n)\;
\kket{y}\bbra{x}
%      \; \mathrm d\mu^m(x) \; \mathrm d\mu^n(y)
\,,
%  	\mspace{-60mu}
% -----------------------------------------------------
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZH-white-dot-arity}\!\!}
\!\:&=\;
\int\limits_{\mathclap{x \in [D]}}
\kket{x}^{\!\otimes n}\!\bbra{x}^{\!\!\;\otimes m}
%    \; \mathrm d\mu(x)
\,,
\mspace{-100mu}
% -----------------------------------------------------
\\[-.25ex]
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZH-gray-dot-arity}\!\!}
\,&=\,
\mathop{\int \!\!\!\!\int}_{%
\mathclap{
{\substack{x \in [D]^m \\ y\in [D]^n}}
\bbracket{\big.\,
\smash{\textstyle \sum\limits_h x_h + \sum\limits_k y_k}
\,}{0}
\;
\kket{y}\bbra{x}
%    \,\; \mathrm d\mu^m(x) \; \mathrm d\mu^n(y)
\,,
%  	\mspace{-60mu}
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\tikzfig{ZH-gen-not-dot}}
\,&=\;
\int\limits_{\mathclap{x \in [D]}}
\kket{-c{-}x}\bbra{x}
%  		\; \mathrm d\mu(x)
\,,
\mspace{-100mu}
\end{aligned}
\end{equation}

$\kket{\smash{\omega^k}} = \smash{\tfrac{1}{\sqrt D}} \sum_x \omega^{-kx} \,\kket{x}$ is an $\omega^k$-eigenstate of the operator $X$, for $\omega = \e^{2\pi i / D}$ a primitive $D\textsuperscript{th}$ root of unity and $X$ the cyclic shift operator given by $X \ket{a} = \ket{a{+}1}$.
Here and elsewhere in our work, any expression $E$ which indexes a standard basis vector $\ket{E}$ or point-mass distribution $\kket{E}$ should be understood as being reduced mod $D$ in that context, to an element of $[D] \subset (-\tfrac{1}{2}D, \tfrac{1}{2}D]$.

The precise semantics defined above depends on the parameter $\nu$, which governs the normalisation of the measure $\mu$ on subsets of $[D]$.

Simple rewrites for qudit ZX and ZH diagrams.

We show that imposing the constraint that
\tikz \draw (0,0) -- ++(0.375,0) node (g) [small H box] {\tp} -- ++(0.375,0);
\;}$ is a unitary operator, suffices to fix the value $\nu = D^{-1/4}$, so that $\mu([D]) = \sqrt D$.
This allows us to define a system of scalar-exact rewrites for ZX and ZH diagrams for arbitrary $D>1$ which involve very few scalar gadgets.
A selection of such rewrites is presented in Figures <ref>  & <ref>, which we prove sound in Appendix <ref>.
(Figure <ref> presents some equivalences between ZX and ZH diagrams; Figure <ref> presents how some well-known operators  would be represented by diagrams involving ZX and ZH generators.)
— Note that these rewrites have not been chosen either to be either minimal or complete.
Rather, we hope to demonstrate representative rewrites to persuade the reader that fixing the semantics as we do above, is likely to be beneficial to the exploration of versions of these calculi for qudits of various dimensions.

\begin{gather*}
\begin{tikzpicture}
\setlength\rulediagramwd{3.5em}
\rewriterule		[ZX-GI]	{\vtikzfig[-0ex]{ZX-green-id}}
\setlength\rulediagramwd{4.5em}
\nextrewriterule	[ZX-RI]	{\vtikzfig[-0ex]{ZX-2c-red-dots}}
\setlength\rulediagramwd{5.0em}
\nextrewriterule	[ZX-HI]	{\vtikzfig[-0ex]{ZX-H-id}}
%		\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\setlength\rulediagramwd{3em}
\rewritetarget 				{\vtikzfig[-0ex]{id-wire}}
\end{tikzpicture}
\\[-14.0ex]
\end{gather*}

\begin{align*}{}
\mspace{-48mu}
\setlength\rulediagramwd{4.875em}
\begin{gathered}
\begin{tikzpicture}
\rewriterule		[ZX-GF]	{\vtikzfig[-0ex]{ZX-green-fn-phase-fuse}}
\setlength\rulediagramwd{4em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\rewritetarget 				{\vtikzfig[-0ex]{ZX-green-fn-phase-sum}}
\end{tikzpicture}
\end{gathered}
\mspace{-48mu}
\setlength\rulediagramwd{5em}
\begin{gathered}
\begin{tikzpicture}
\rewriterule		[ZX-GFP]	{\vtikzfig{ZX-green-phase-fuse}}
\setlength\rulediagramwd{4em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.1875,0)$);
\rewritetarget 					{\vtikzfig[-0ex]{ZX-green-phase-sum}}
\end{tikzpicture}
\end{gathered}
\mspace{-48mu}
\setlength\rulediagramwd{5em}
\begin{gathered}
\begin{tikzpicture}
\rewriterule		[ZX-GFS]	{\vtikzfig[-0ex]{ZX-green-stab-fuse}}
\setlength\rulediagramwd{4em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.1875,0)$);
\rewritetarget 					{\vtikzfig{ZX-green-stab-sum}}
\end{tikzpicture}
\end{gathered}
\mspace{-48mu}
\\[-10.5ex]
\end{align*}

\begin{align*}
\mspace{-24mu}
\begin{gathered}
\setlength\rulediagramwd{7em}
\begin{tikzpicture}
\setlength\rulediagramwd{6em}
\rewriterule		[ZX-RGC]	{\vtikzfig[-1ex]{ZX-red-phase-dot}}
\setlength\rulediagramwd{4.25em}
\rewritetarget 					{\vtikzfig[-1ex]{ZX-green-phase-w-H}}
\end{tikzpicture}
\\[-1ex]
\begin{tikzpicture}
\setlength\rulediagramwd{6em}
\rewriterule		[ZX-RGB]		{\vtikzfig[-1ex]{ZX-bialg-many}}
\setlength\rulediagramwd{4.25em}
\rewritetarget 					{\vtikzfig[-1ex]{ZX-bott-many}}
\end{tikzpicture}
\\[-3ex]
\begin{tikzpicture}
\setlength\rulediagramwd{6em}
\rewriterule		[ZX-CPY]	{\hspace*{-2ex}\vtikzfig{ZX-red-copy}\hspace*{1ex}}
\setlength\rulediagramwd{3.5em}
\rewritetarget 					{\hspace*{-1ex}\vtikzfig{ZX-red-copies}\hspace*{1ex}}
\end{tikzpicture}
\\[-5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{5.25em}
\rewriterule		[ZX-NS]		{\vtikzfig{ZX-green-phase-nots}}
\setlength\rulediagramwd{4em}
\rewritetarget 					{\hspace*{-2ex}\vtikzfig{ZX-green-negated-phase-gadget}}
\end{tikzpicture}
\\[-5.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{8em}
\rewriterule		[ZX-RS]		{\vtikzfig[-0ex]{ZX-conjugate-stab-dot}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.625,0)$);
\rewritetarget 					{\vtikzfig[.5ex]{ZX-shear-gadget}}
\end{tikzpicture}
\mspace{-18mu}
\end{gathered}
&& &&
\setlength\rulediagramwd{10em}
\begin{gathered}
\begin{tikzpicture}
\setlength\rulediagramwd{5.25em}
\rewriterule		[ZX-Z]		{\vtikzfig[-3ex]{ZX-zero-and-green-lollipop}}
\setlength\rulediagramwd{4em}
\rewritetarget 					{\hspace*{-2ex}\vtikzfig[-3ex]{ZX-zero-and-red-lollipop}}
\end{tikzpicture}
\\[-0.0ex]
\mspace{-18mu}
\setlength\rulediagramwd{3.25em}
\begin{tikzpicture}
\rewriterule		[ZX-ZCP]		{\vtikzfig[-0ex]{ZX-nonzero-stab-phase-dot}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\setlength\rulediagramwd{5.25em}
\nextrewriterule	[ZX-ZSP]		{\vtikzfig[-0ex]{ZX-awkward-quadratic-scalar-dot}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.4375,0)$);
\setlength\rulediagramwd{3.25em}
\rewritetarget 					{\vtikzfig[-0ex]{ZX-zero-scalar-dot}}
\end{tikzpicture}
\\[-2.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{9em}
\rewriterule		[ZX-MH]	{\hspace*{-2ex}\vtikzfig{ZX-green-red-multiedge}\hspace*{1ex}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (.25,0)$);
\rewritetarget 					{\hspace*{-1ex}\vtikzfig{ZX-multiplier-gadget}\hspace*{1ex}}
\end{tikzpicture}
\mspace{-36mu}
\\[-2.5ex]
\begin{tikzpicture}
\rewriterule		[ZX-ME]		{\vtikzfig{ZX-green-red-multiedge-lollipop}}
\setlength\rulediagramwd{8.5em}
\rewritetarget 					{\hspace*{-2ex}\vtikzfig{ZX-red-quadratic-lollipop}}
\end{tikzpicture}
\\[-2.5ex]
\mspace{-18mu}
\setlength\rulediagramwd{7.5em}
\begin{gathered}
\begin{tikzpicture}
\rewriterule		[ZX-MEH]		{\vtikzfig{ZX-multiedge-Hopf}}
\setlength\rulediagramwd{4.4375em}
\nextrewriterule	[ZX-A]		{\vtikzfig[1ex]{ZX-antipode}}
\setlength\rulediagramwd{3.25em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\rewritetarget 					{\vtikzfig[1ex]{ZX-dc}}
\end{tikzpicture}
\end{gathered}
\end{gathered}
\\[-11.0ex]
\end{align*}

\begin{gather*}
\setlength\rulediagramwd{5em}
\begin{tikzpicture}
\rewriterule		[ZX-PU]	{\vtikzfig[-0ex]{ZX-phase-gadget}}
\setlength\rulediagramwd{6em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\nextrewriterule	[ZX-SU]	{\vtikzfig[-0ex]{ZX-stab-scalar-unit}}
\setlength\rulediagramwd{5.75em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\nextrewriterule	[ZX-GU]	{\vtikzfig[-1ex]{ZX-conjugate-quadratic-dots}}
\setlength\rulediagramwd{2.5em}
\rewritetarget 				{\vtikzfig[-0.0ex]{empty}}
\end{tikzpicture}
\\[-7.5ex]
\end{gather*}

Various scalar-exact rewrites (including axioms and corollaries) on ZX diagrams, which are sound for the semantics described in Eqn. (<ref>) subject to $\nu = D^{-1/4}$.
Chains of rewrites $\Big.\cD_j \!\xleftrightarrow{\!\!\:\textsf{(x)}\!\:} \cdots \leftrightarrow \cD_{\!\!\;f}$ are intended to indicate that $\cD_j \!\xleftrightarrow{\!\!\:\textsf{(x)}\!\:}\! \cD_{\!\!\;f}$ is either an axiom or notable corollary.
Throughout, we have $\theta, \phi \in \R$, and $\Theta, \Phi: \Z \to \C$, and $a, a_1, a_2, b, b_1, b_2, c \in \Z$.
We define the constant $0$ function, $\mathrm Z: \Z \to \{ 0 \}$.
We let $1 < t < D$ be a divisor of $D$, $1 < t' < t$ be a divisor of $t$ (and thus also of $D$), $u \in \N$ an integer which has no common factors $t>1$ with $D$ (sometimes interpreted as an element $u \in \Z_D^\times$), and $\tilde a \in \Z$ an integer which is not a multiple of $D$.
Many of the rules involve green dots or red dots parameterised by a label ${[\:\! a\:\!]}$ or ${[\:\!a \s b\:\!]}$ for $a,b \in \Z$ : these stand respectively for the amplitude functions $x \mapsto \tau^{-2ax}$ and $x \mapsto \tau^{-2ax - bx^2}$, where $\tau = \exp(\pi i (D^2 {+} 1)/D)$.
An annotation $\neg$ on a red or green dot indicates a dimension-dependent parameter ${[\!\:-\sigma \!\:]}$, where $\sigma = 0$ for $D$ odd and $\sigma = 1$ for $D$ even.
Soundness proofs for these rewrites may be found in Appendix <ref>.

\begin{align*}
\mspace{-36mu}
\begin{gathered}
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-GW]	{\vtikzfig{ZX-green-dot}\;\;\;}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-white-dot}}
\end{tikzpicture}
\\[-4ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-RG]	{\vtikzfig{ZX-red-dot}}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-gray-dot}}
\end{tikzpicture}
\\[-2.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-GP]	{\vtikzfig[-1ex]{ZX-green-phase-dot}}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-white-H-gadget}}
\end{tikzpicture}
\\[-7.25ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-WH]	{\vtikzfig{ZX-green-fn-lollipop}}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-H-fn-lollipop}}
\end{tikzpicture}
\end{gathered}
\mspace{0mu}&&%
%	\Bigg\vert
\begin{gathered}
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-RN]		{\vtikzfig{ZX-red-c-dot}}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-gen-not-dot}}
\end{tikzpicture}
\\[-5.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZXH-RA]	{\vtikzfig{ZX-red-phase-free-dot}}
\setlength\rulediagramwd{3.75em}
\rewritetarget 					{\vtikzfig{ZH-gray-id}}
\end{tikzpicture}
\\[2ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4em}
\rewriterule		[ZXH-HP]		{\vtikzfig{ZX-H-plus-box}}
\setlength\rulediagramwd{3.5em}
\rewritetarget 					{\vtikzfig{ZH-H-plus1-box}}
\end{tikzpicture}
\\[-2.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{4em}
\rewriterule		[ZXH-HM]		{\vtikzfig{ZX-H-minus-box}}
\setlength\rulediagramwd{3.5em}
\rewritetarget 					{\vtikzfig{ZH-H-minus1-box}}
\end{tikzpicture}
\end{gathered}
\mspace{-36mu}&&%
%	\Bigg\vert
\mspace{-24mu}&&
\setlength\rulexnwd{5em}
\begin{gathered}
\begin{tikzpicture}
\setlength\rulediagramwd{1.5em}
\rewriterule		[ZXH-GH0]	{\vtikzfig{ZX-green-phase-free-deg0-dot}}
\setlength\rulediagramwd{0em}
\rewritetarget 					{\vtikzfig{ZH-sqrtD-scalar-gadget}}
\end{tikzpicture}
\\[-5.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{2.5em}
\rewriterule		[ZXH-GH]	{\vtikzfig{ZX-green-Theta-deg0-dot}}
\setlength\rulediagramwd{1em}
\rewritetarget 					{\vtikzfig{ZH-Theta-integral-gadget}}
\end{tikzpicture}
\\[-1ex]
\begin{tikzpicture}
\setlength\rulediagramwd{5.25em}
\rewriterule		[ZXH-S0]	{\vtikzfig[-0ex]{ZX-Theta-0-phase-gadget}}
\setlength\rulediagramwd{1.75em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\rewritetarget 					{\vtikzfig[-0ex]{ZH-Theta-0-phase-gadget}}
\end{tikzpicture}
\\[-4ex]
\begin{tikzpicture}
\setlength\rulediagramwd{5.25em}
\rewriterule		[ZXH-S]	{\vtikzfig{ZX-Theta-c-phase-gadget}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.25,0)$);
\setlength\rulediagramwd{1.5em}
\rewritetarget 					{\vtikzfig{ZH-Theta-c-phase-gadget}}
\end{tikzpicture}
\end{gathered}
\end{align*}

Sound rewrites between the ZX generators and the ZH generators, subject to the semantics of Eqn. (<ref>).
Some of these rewrites are special cases or (together with ZX- or ZH-rewrites) easy corollaries of the others.
For instance,  follows from , , and fusion of green dots; while  is an immediate consequence of .
Soundness proofs for these rewrites may be found in Appendix <ref>.

\begin{gather*}
\begin{tikzpicture}
\setlength\rulediagramwd{4.25em}
\rewriterule		[ZH-WI]	 	{\vtikzfig{ZH-white-id}}
\nextrewriterule	[ZH-WQS]	{\vtikzfig{ZH-white-special-w-invSqrtD}}
\nextrewriterule	[ZH-AI]		{\vtikzfig{ZH-2antipode}}
\setlength\rulediagramwd{4.5em}
\nextrewriterule	[ZH-HI]		{\vtikzfig{ZH-H-id}}
\setlength\rulediagramwd{3em}
\rewritetarget 					{\vtikzfig{id-wire}}
\end{tikzpicture}
\\[-5.25ex]
\setlength\rulediagramwd{6em}
\begin{tikzpicture}
\rewriterule		[ZH-WF]	 	{\vtikzfig[-1ex]{ZH-white-fuse}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\nextrewriterule	[ZH-GWC]	{\vtikzfig{ZH-gray-w-unitH}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{6.5em}
\nextrewriterule	[ZH-WNS]	{\vtikzfig{ZH-not-dot-symm}}
\setlength\rulediagramwd{4.5em}
\rewritetarget 					{\vtikzfig[-1ex]{ZH-white-dot}}
\end{tikzpicture}
\\[-3.5ex]
\setlength\rulediagramwd{6em}
\begin{tikzpicture}
\rewriterule		[ZH-GF]		{\vtikzfig[-1ex]{ZH-gray-fuse}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\nextrewriterule	[ZH-GL]		{\vtikzfig{ZH-gray-dot-w-lollipop}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{6.5em}
\nextrewriterule	[ZH-WGC]	{\vtikzfig{ZH-white-w-unitH}}
\setlength\rulediagramwd{4.5em}
\rewritetarget 					{\vtikzfig[-1ex]{ZH-gray-dot}}
\end{tikzpicture}
\\[-3.5ex]
\begin{aligned}
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{7em}
\rewriterule		[ZH-MEH]		{\vtikzfig[.25ex]{ZH-multiedge-Hopf}}
\setlength\rulediagramwd{4.5em}
\nextrewriterule	[ZH-A]	 	{\vtikzfig[.5ex]{ZH-antipode}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{3em}
\rewritetarget 					{\vtikzfig{ZH-dc}}
\end{tikzpicture}
\end{aligned}
\Bigg\vert
\mspace{-9mu}&&
\begin{aligned}
\begin{tikzpicture}
%	\setlength\rulediagramwd{5.25em}
\rewriterule		[ZH-WGB]	{\vtikzfig{ZH-bialg-white-gray}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\rewritetarget 					{\vtikzfig[-1ex]{ZH-bott-white-gray}}
\end{tikzpicture}
\end{aligned}
\end{aligned}
\\[-6.5ex]
\begin{aligned}
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{5.25em}
\rewriterule		[ZH-HM]		{\vtikzfig[.5ex]{ZH-mult}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{3.5em}
\rewritetarget 					{\!\!\!\!\!\!\vtikzfig[1.5ex]{ZH-H-prod-prep}}
\end{tikzpicture}
\end{aligned}
\Bigg\vert
\mspace{-9mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{2.5em}
\rewriterule		[ZH-HU]		{\vtikzfig{ZH-H0-prep}}
\setlength\rulediagramwd{1.5em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\rewritetarget 					{\vtikzfig{ZH-white-prep}\!\!\!\!}
\end{tikzpicture}
\end{aligned}
\Bigg\vert
\mspace{-9mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{6em}
\rewriterule		[ZH-EC]		{\vtikzfig[-.5ex]{ZH-exponent-compl}}
\setlength\rulediagramwd{5.5em}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\rewritetarget 					{\vtikzfig[1.5ex]{ZH-exponent-compl-gadget}}
\end{tikzpicture}
\end{aligned}
\end{aligned}
\\[-6.0ex]
\begin{aligned}
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{6.5em}
\rewriterule		[ZH-MF]		{\vtikzfig[-1ex]{ZH-H-complicated-fuse}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{4.25em}
\rewritetarget 					{\vtikzfig[-1ex]{ZH-H-complicated-phase-box}}
\end{tikzpicture}
\end{aligned}
\Bigg\vert
\mspace{-18mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{4.5em}
\rewriterule		[ZH-MCA]	{\!\!\!\!\vtikzfig[1.5ex]{ZH-multichar-add}}
\setlength\rulediagramwd{3em}
\rewritetarget 					{\!\!\!\!\vtikzfig[1ex]{ZH-multichar-prep}\!\!\!}
\end{tikzpicture}
\end{aligned}
\mspace{-18mu}
\Bigg\vert
\mspace{-18mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{4.5em}
\rewriterule		[ZH-UM]		{\vtikzfig{ZH-double-mult-unit}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{3.5em}
\rewritetarget 					{\vtikzfig{ZH-joint-mult-unit}}
\end{tikzpicture}
\end{aligned}
\end{aligned}
\\[-3.75ex]
\mspace{-9mu}
\begin{aligned}
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{10em}
\setlength\rulexnwd{3em}
\rewriterule		[ZH-O]		{\vtikzfig[.25ex]{ZH-ortho-join}}
\rewritetarget 					{\vtikzfig{ZH-ortho-star}}
\end{tikzpicture}
\end{aligned}
%	\mspace{9mu}
\Bigg\vert
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{7.5em}
\rewriterule		[ZH-HWB]	{\vtikzfig{ZH-bialg-white-H}}
\setlength\rulediagramwd{6.5em}
\rewritetarget 					{\!\!\!\!\vtikzfig[1ex]{ZH-bott-white-varH}\!\!\!}
\end{tikzpicture}
\\[-1.5ex]
\begin{tikzpicture}
%	\setlength\rulediagramwd{5em}
\rewriterule		[ZH-HMB]		{\vtikzfig{ZH-bialg-alt-white-H}}
%	\setlength\rulediagramwd{4em}
\rewritetarget 						{\vtikzfig{ZH-bott-alt-H-gray}}
\end{tikzpicture}
\\[-3.5ex]
\begin{tikzpicture}
\setlength\rulediagramwd{5.5em}
\rewriterule		[ZH-ME]			{\vtikzfig{ZH-multiplier}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\setlength\rulediagramwd{6.5em}
\rewritetarget 						{\vtikzfig{ZH-white-gray-multiedge}}
\end{tikzpicture}
\end{aligned}
\end{aligned}
\\[-5.25ex]
\begin{aligned}
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{4.5em}
\rewriterule		[ZH-ND]		{\vtikzfig[.25ex]{ZH-not1-not2}}
\setlength\rulediagramwd{5em}
\rewritetarget 					{\vtikzfig{ZH-not-transport}}
\end{tikzpicture}
\end{aligned}
\bigg\vert
\mspace{-9mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{5.5em}
\rewriterule		[ZH-NH]			{\vtikzfig{ZH-gen-not-gadget}}
\setlength\rulediagramwd{3em}
\rewritetarget 						{\vtikzfig{ZH-var-not-dot}}
\end{tikzpicture}
\end{aligned}
\bigg\vert
\mspace{-9mu}&&
\begin{aligned}
\begin{tikzpicture}
\setlength\rulediagramwd{3em}
\rewriterule		[ZH-NA]	 	{\vtikzfig[.25ex]{ZH-not-antipode}}
%	\setlength\rulediagramwd{4.5em}
%		\nextrewriterule	[ZH-2HG]	{\vtikzfig{ZH-double-H}}
\coordinate (anchor-next-diagram) at ($(anchor-next-diagram) + (-.125,0)$);
\rewritetarget 					{\vtikzfig{ZH-gray-id}}
\end{tikzpicture}
\end{aligned}
\end{aligned}
\\[-8.75ex]
\end{gather*}

Various scalar-exact rewrites (including axioms and corollaries) on ZH diagrams, which are sound for the semantics described in Eqn. (<ref>) subject to $\nu = D^{-1/4}$.
Chains of rewrites $\Big.\cD_j \!\xleftrightarrow{\!\!\:\textsf{(x)}\!\:} \cdots \leftrightarrow \cD_{\!\!\;f}$ are intended to indicate that $\cD_j \!\xleftrightarrow{\!\!\:\textsf{(x)}\!\:}\! \cD_{\!\!\;f}$ is either an axiom or notable corollary.
Throughout, we have $k \in \N$, $a,b,c, c_1, c_2 \in \Z$ (which may be evaluated modulo $D$); $u,v \in \Z_D^\times$ ; $\mathrm A, \mathrm B: \Z \to \C$; and $\alpha \in \C^\times$.
H-boxes which are labeled inside with an integer parameter such as $c \in \Z$, indicates an amplitude of $\omega^c = \e^{2\pi i c/D}$; H-boxes labelled with $\texttt+$ or $\texttt-$ indicate $c = \pm 1$ (see Figure <ref>).
A not dot labeled with $\neg$ indicates a dimension-dependent parameter $-\sigma \in \Z$, where $\sigma = 0$ for $D$ odd and $\sigma = 1$ for $D$ even; more generally, not-dots may be parameterised by $c \in \Z$ for the sake of convenience and reduced modulo $D$ to an element of $[D]$.
Soundness proofs for these rewrites may be found in Appendix <ref>.

\begin{align*}{}
\\[-7.5ex]
\begin{aligned}{}
\mspace{-21mu}
\Bigsem{\!%
\vtikzfig[-1ex]{ZX-kket-a}
\,}
\!\!\;&=
\kket{a}
% ==
\\[.5ex]
% ==
\mspace{-21mu}
\Bigsem{\!%
\vtikzfig[-1ex]{ZX-kket-omega-a}
\,}
\!\!\;&=
\kket{\smash{\omega^a}}
% ==
\\[.5ex]
% ==
\mspace{-21mu}
\Bigsem{\,
\vtikzfig[-1ex]{ZX-X}
\,}
\!\!\;&=\:\!
%	\sum_{\mathclap{x\in \Z_D}}
%		\ket{x{+}1}\bra{x}
%	\,=:\,
% ==
\\[.5ex]
% ==
\mspace{-21mu}
\Bigsem{\,
\vtikzfig[-1ex]{ZX-Z}
\,}
\!\!\;&=\:\!
%	\sum_{\mathclap{x\in \Z_D}}
%		\omega^x \ket{x}\bra{x}
%	\,=:\,
% ==
\end{aligned}
\begin{aligned}
\Sem{5.5ex}{\,
\vtikzfig[-2.00ex]{ZX-CNOT-alt-gadget}
\,}
\!\!\;&=\,
%	\sum_{\mathclap{x,y \in \Z_D}} \ket{x, y{+}cx}\bra{x, y}
%	\,=\,
\mathrm{CX}
\\[1.5ex]
\Sem{5.5ex}{\,
\vtikzfig[-2.25ex]{ZX-CZ-gadget}
\,}
\!\!\;&=\,
%	\sum_{\mathclap{x,y \in \Z_D}} \omega^{xy} \ket{x, y}\bra{x, y}
%	\,=\,
\mathrm{CZ}
\end{aligned}
\begin{aligned}
\Bigsem{\tikzfig{ZH-scalar-box}}
\!\!\;&=\:\!
\alpha
%	\Bigsem{\,
%		\vtikzfig[-2ex]{ZH-gray-id}
%	\,}
%	\!\!\;&=\:\!
%	\sum_{\mathclap{x \in \Z_D}} \ket{-x}\bra{x}
\\[1ex]
\Sem{8.0ex}{\,
\vtikzfig[-1.75ex]{ZXH-CCZ-c-gadget}
\!\!\;&=\!\:
\mathrm{CCZ}^c
\end{aligned}
\begin{aligned}
\bigsem{\,
\vtikzfig[-1.75ex]{ZX-H-plus-box}
\,}
\!\!\;&=\!\:
\tfrac{1}{\sqrt D} \sum_{\mathclap{k,x \in [D]}} \omega^{kx} \!\:\ket{k}\bra{x}
\mspace{-36mu}
\\[-1.5ex]
\Sem{5.0ex}{\,
\vtikzfig[-1.75ex]{ZH-diag-A-gate}
\!\!\;&=\,
\sum_{\mathclap{x,y \in [D]}} \mathrm A(xy) \,\ket{x,y}\bra{x,y}
\mspace{-36mu}
\\[1ex]
\Bigsem{\,
\vtikzfig[-1.75ex]{ZX-diag-Theta-gate}
\,}
\!\!\;&=\!\:
\sum_{\mathclap{x \in [D]}} \Theta(x) \,\ket{x}\bra{x}
\mspace{-36mu}
\\[-1ex]
\end{aligned}
\\[-5.0ex]
\end{align*}

A selection of simple diagrams to represent vectors and unitary operators, subject to the semantics of Eqn. (<ref>) and $\nu = D^{-1\!\!\;/\!\!\;4}$.
We let $\alpha \in \C^\times$, $a,c \in [D]$, and $\mathrm A, \Theta: \Z \to \C$.
In this case, ${\lvert a \rangle\!\!\!\;\rangle} = D^{\!\:1\!\!\;/\!\!\;4} {\lvert a \rangle}$ and ${\lvert \omega^a \rangle\!\!\!\;\rangle} = D^{\!\:1\!\!\;/\!\!\;4} {\lvert \omega^a \rangle}$.
We define $X  {\lvert t \rangle}  = {\lvert t{+}1 \rangle} $ and $Z {\lvert t \rangle}  = \omega^t {\lvert t \rangle}$ to be the usual generalised Pauli operators on $\cH$, and $\mathrm{CX} {\lvert x,y \rangle} = {\lvert x, y{+}x \rangle}$ and $\mathrm{CZ} {\lvert x,y \rangle} = \omega^{xy} {\lvert x, y \rangle}$ to be the (integer-)controlled versions of those same operators.
These constructions are discussed in Section <ref>.

The special case $D=2$.
In addition to being a promising approach to defining ZX and ZH calculi with simple rewrite systems on qudits, this approach to interpreting ZX and ZH diagrams reproduces
Strictly speaking, the calculi of Ref. [19] involve red and green dots with parameters $\theta \in \R$, H-boxes with parameters $\alpha \in \C$, only one type of Hadamard box instead of two, and a `nu box' which is entirely missing in the calculus presented here.
We may bridge these differences in the case $D=2$ by considering the special case of red and green dots parameterised by functions $\Theta(x) = \exp(i\theta x)$ for $\theta \in \R$, H-boxes parameterised by $\mathrm A(x) = \alpha^x$ for $\alpha \in \C$, identifying both the Hadamard plus and minus boxes with the single Hadamard box of Ref. [19], and replacing the nu-boxes with some suitable scalar gadgets (such as H-boxes parameterised by powers of $\nu = D^{-1/4}$).
the `well-tempered' semantic map $\sem{\,\cdot\,}_\nu$ described in Ref. [19] for $D=2$.
In this way, Eqns. (<ref>) provide a more intuitive definition of those semantics, and extends them to arbitrary $D>1$.

Related work.

As we note above, there is recent and ongoing work [8, 12, 23, 27, 28, 29, 35, 41] on ZX, ZH, and related calculi on qudits of dimension $D>2$, though often considering the special case where $D$ is an odd prime.
Our work is strongly influenced in particular by certain ideas of Booth and Carette [27] and Roy [35], and we are aware of parallel work by collaborations involving these authors [42, 43].
However, we have reason to believe that our work is distinguished in presenting convenient semantics for both ZX and ZH diagrams for arbitrary ${D\!>\!1}$.
In particular, our work is intended only to present results which hold for arbitrary $D$ (albeit allowing for minor variations between the cases of $D$ even and $D$ odd).

Structure of the paper.
Section <ref> provides what background we rely upon in number theory and measure theory, and also for the ZX and ZH calculi, to present our results.
Section <ref> introduces discrete measures on $[D]$ and integrals on $[D]$, and considers constraints on normalisation which may be  motivated by particular presentations of the discrete Fourier transform $\hat f$ of a function $f: \Z \to \C$.
In Section <ref>, we demonstrate how this yields convenient representations of generalised Clifford gates on $\cH$, as well as general diagonal operations.
In Section <ref>, we outline a normal form for qudit ZH diagrams for all $D>1$, building on a similar construction for $D \!=\! 2$. [30].
In Section <ref>, we remark on the relationship between this construction and the development of the `well-tempered' semantics for ZX and ZH diagrams for $D=2$.
(Throughout, we refer the reader to the various Appendices for particularly technical details which may be of interest.)
We conclude in Section <ref> with a summary and general commentary on these results.

§ PRELIMINARIES

§.§ Mathematical preliminaries

Number theory.
Let $D>1$ be a fixed integer, and $\omega = \e^{2\pi i \!\!\;/\!\!\;D}$.
We assume some basic familiarity with number theory, in particular with $\Z_D$, the integers modulo $D$.
While it is common to associate $\Z_D$ with the set $\{0,1,\ldots,D\!-\!1\}$ of  non-negative `residues' of integers modulo $D$, one might also associate them $\Z_D$ with a set of `signed residues' $[D] = {(-\tfrac{1}{2}D, \tfrac{1}{2} D] \;\!\cap\;\! \Z} = \{L_D,L_D{+}1,\ldots,U_D{-}1,U_D\}$, where $L_D = {-\lfloor\!\!\:\tfrac{D-1}{2}\!\!\:\rfloor}$ and $U_D = {\lfloor\!\!\;\tfrac{D}{2}\!\!\;\rfloor}$.
We may then occasionally substitute $\Z_D$ for $[D]$ when this is unlikely to cause confusion: this will most often occur in the context of expressions such as $\omega^{xy}$, which is well-defined modulo $D$ in each of the variables $x$ and $y$ (i.e., adding any multiple of $D$ to either $x$ or $y$ does not change the value of the expression).
In such an expression, while we may intend for one of $x$ or $y$ or both may be an element of $\Z_D$ in principle, they would in practise be interpreted as a representative integer $x,y \in [D]$.

Measure theory.
We rely only on a modest amount of measure theory, as follows.
For a set $X$, let $\wp(X)$ be the power-set of $X$.
We may define a $\sigma$-algebra on $X$ to be a set $\Sigma \subset \wp(X)$ which contains $X$, which is closed under set complements ($S \in \Sigma \,\Leftrightarrow\, X \!\!\;\setminus\!\!\; S \in \Sigma$), and which is closed under countable unions (if $S_1, S_2, \ldots \in \Sigma$, then $S_1 \cup S_2 \cup \cdots \in \Sigma$).
The purpose of defining $\Sigma$ is to allow the notion of a measure $\mu: \Sigma \to \R \cup \{+\infty\}$ to be defined, where the sets $S \in \Sigma$ are the ones which have a well-defined measure.
Such a function $\mu$ is a measure, if and only if $\mu(\varnothing) = 0$, $\mu(S) \ge 0$ for all $S \in \Sigma$, and if

\begin{equation}
\mu\bigl(S_1 \cup S_2 \cup \cdots\bigr) = \mu(S_1) + \mu(S_2) + \cdots
\end{equation}

for any sequence of disjoint sets $S_j \in \Sigma$.
An example is the $\sigma$-algebra $\Sigma$ consisting of all countable unions of intervals over $\R$, with $\mu$ defined by assigning $\mu(J) = b{\!\;-\!\;}a$ to any interval $J \!\!\;=\!\!\; (a,b)$, $J \!\!\;=\!\!\; (a,b]$, $J \!\!\;=\!\!\; [a,b)$, or $J \!\!\;=\!\!\; [a,b]$ for $a \le b$.
A somewhat more exotic measure is the Dirac distribution $\mu_\delta$ on $\R$, for which $\mu_\delta(S) \!\!\;=\!\!\; 1$ if $0 \in S$, and $\mu_\delta(S) \!\!\;=\!\!\; 0$ otherwise.
For more remarks on the Dirac distribution and related concepts, see Appendix <ref>.
However, we will be mainly interested in measures $\mu$ which can be defined on the subsets of $[D]$, in which $\mu(\{x\})$ is the same for every singleton set.

§.§ ZX and ZH diagrams

ZX and ZH diagrams are both systems of `string diagrams'.
ZX diagrams are effective for representing operations generated by single-qubit rotations and controlled-NOT gates.
In most cases (excepting, e.g., Refs. [20, 27]), it rests on the unitary equivalence of two sets of conjugate bases.
ZH diagrams were developed as an alternative notation to ZX diagrams, to facilitate reasoning about quantum circuits over the Hadamard-Toffoli gate set [44, 45].
In each case, the diagrams are composed of dots or boxes, and wires.
These diagrams can be described as being a composition of `generators',
which typically consist of one (or zero) dots/boxes with some amount of meta-data, and any number (zero or more) directed wires, where the direction is usually represented by an orientation in the diagram.
(In this article, wires are oriented left-to-right, though they are also allowed to bend upwards or downwards.)

Composition of diagrams.

For two generators (or two more complicated diagrams) $\cD_1$ and $\cD_2$, we may define composite diagrams $\cD_1 \!\!\;\otimes\!\!\; \cD_2$ and $\cD_1 \!\!\;\mathbin;\!\!\; \cD_2$, which we  represent schematically by

\begin{equation}
\begin{aligned}
\begin{tikzpicture}
\node (D) at (0,0) [draw=black, line width=.75pt,
minimum width=1em, minimum height=9ex]
{$\cD_1 \otimes \cD_2$};
\foreach \dy in {-0.45,-0.35,-0.25,-0.15,0.15,0.25,0.35,0.45} {
\draw ($(D.west) + (0,\dy)$) -- ++(-0.25,0);
\draw ($(D.east) + (0,\dy)$) -- ++(0.25,0);
\end{tikzpicture}
\end{aligned}
\;\;=\;\;
\begin{aligned}
\begin{tikzpicture}
\node (D1) at (0,.75) [draw=black, line width=.75pt,
minimum width=1em, minimum height=4ex]
\node (D2) at (0,0) [draw=black, line width=.75pt,
minimum width=1em, minimum height=4ex]
\foreach \n in {D1,D2} {%
\foreach \dy in {-0.15,-0.05,0.05,0.15} {
\draw ($(\n.west) + (0,\dy)$) -- ++(-0.25,0);
\draw ($(\n.east) + (0,\dy)$) -- ++(0.25,0);
\end{tikzpicture}
\end{aligned}\quad;
\qquad
\qquad
\begin{aligned}
\begin{tikzpicture}
\node (D) at (0,0) [draw=black, line width=.75pt,
minimum width=1em, minimum height=5ex]
{$\cD_1 \mathbin; \cD_2$};
\foreach \dy in {-0.15,-0.05,0.05,0.15} {
\draw ($(D.west) + (0,\dy)$) -- ++(-0.25,0);
\draw ($(D.east) + (0,\dy)$) -- ++(0.25,0);
\end{tikzpicture}
\end{aligned}
\;\;=\;\;
\begin{aligned}
\begin{tikzpicture}
\node (D1) at (0,0) [draw=black, line width=.75pt,
minimum width=1em, minimum height=4ex]
\node (D2) at (1.125,0) [draw=black, line width=.75pt,
minimum width=1em, minimum height=4ex]
\foreach \n in {D1,D2} {%
\foreach \dy in {-0.15,-0.05,0.05,0.15} {
\draw ($(\n.west) + (0,\dy)$) -- ++(-0.25,0);
\draw ($(\n.east) + (0,\dy)$) -- ++(0.25,0);
\end{tikzpicture}
\end{aligned}\quad,
\end{equation}

which we call the `parallel' and `serial' composition of $\cD_1$ and $\cD_2$.
In the latter case we require that the number of output wires of $\cD_1$ (on the right of $\cD_1$) equal the number of input wires of $\cD_2$ (on the left of $\cD_2$), for the composition to be well-defined.

Semantic maps.

ZX and ZH diagrams are assigned a meaning, e.g., as operators over $\C$, through a semantic map $\sem{\,\cdot\,}$ which maps each generator to some scalar, functional, or operator.
To each generator $\cD$ with $m$ input wires and $n$ output wires, one assigns an operator $\sem{\cD}: \cH\sox{m} \to \cH\sox{n}$ for some fixed vector space $\cH$ over $\C$.
(For ZX and ZH diagrams over qubits, one takes $\cH \cong \C^2$; more generally one may consider $\cH \cong \C^D$ to consider a qudit of dimension $D>1$, as we do in this article.)
This semantic map is defined to be consistent with respect to composition, in the sense that

\begin{equation}
\Bigsem{\cD_1 \otimes \cD_2} \;=\; \bigsem{\cD_1} \otimes \bigsem{\cD_2},
\qquad
\qquad
\Bigsem{\cD_1 \mathbin; \cD_2} \;=\; \bigsem{\cD_2} \circ \bigsem{\cD_1},
\end{equation}

where the reversal of the order for sequential composition comes from the  convention of considering matrices as acting on a column vector on their right (so that function application is consistent between diagrams and operators).
This allows diagrams to denote multi-linear operators on $\cH$ in a straight-forward way.
The semantics of the ZX and ZH generators are usually defined to facilitate certain ways of reasoning about multilinear maps on $\cH$, through how the diagrams represent those operators.

Wire generators / compact structure.
To represent string diagrams to represent operations in which some qudits are being permuted or left unaffected, we also consider generators consisting only of wires.
Furthermore, we are interested in allowing deformations of diagrams in which the generators are flex-symmetric [46].

We consider four such generators, to which we assign semantics as follows:

\begin{gather}
\label{eqn:stringGenerators}
\mspace{-24mu}
\bigsem{\tikzfig{id-wire}\,}
\mathbf 1
\sum_{\mathclap{x \in [D]}}
\ket{x}\bra{x}
\mspace{15mu}
\biggsem{\!\!\:\tikzfig{swap}}
\sum_{\mathclap{x,y \in [D]}}
\ket{y,\!\!\:x\!\:}\bra{x,\!\!\:y\!\:},
\mspace{15mu}
\biggsem{\!\!\:\tikzfig{cup}}
\sum_{\mathclap{x \in [D]}}
\ket{x,\!\!\:x\!\:},
\mspace{15mu}
\biggsem{\!\!\:\tikzfig{cap}}
\sum_{\mathclap{x \in [D]}}
\bra{x,\!\!\:x\!\:}.
\mspace{-9mu}
\end{gather}

Semantics for ZX generators.
The usual approach to assigning semantics to ZX generators is by considering the green and red dots to represent similar operations, subject to different (conjugate) choices of orthonormal basis, and a unitary `Hadamard' (or Fourier transform) gate relating the two bases.
Conventionally, one indexes the standard basis of $\cH$ by $\ket{0}, \ket{1}, \ldots, \ket{D{-}1}$, in short by $\ket{x}$ for $x \in [D]$ defined by $[D] = \{0,1,\ldots,D{-}1\}$.
We instead take $[D] = {(-\tfrac{1}{2}D, \tfrac{1}{2}D] \!\:\cap\!\: \Z}$ as above, and index the standard basis by $\ket{L_D}$, $\ket{L_D{-}1}$, …, $\ket{-1}$, $\ket{0}$, $\ket{+1}$, …, $\ket{U_D}$.
We then define `green' (lighter-coloured) dots in terms of an action on the basis $\ket{x}$, and the `red' (darker-coloured) dots in terms of an action on the basis $\ket{\smash{\omega^x}}$, where $\ket{\smash{\omega^k}} = \smash{\tfrac{1}{\sqrt D} \sum_x \omega^{-kx} \ket{x}}$ for $k \in [D]$.
In the notation of Booth and Carette [27], we have $\ket{\smash{\omega^k}} = \ket{k\:\!{:} X}$, up to a relabeling of the basis elements of $\cH$.
Specifically: for a green dot with angular parameters $\boldsymbol \theta \in \R^{[D]}$, one conventionally assigns the interpretion $\smash{\sum_{x \in [D]} \e^{i \theta_x} \ket{x}^{\!\otimes n}\!\bra{x}^{\!\!\;\otimes m}}$; and one assigns the interpretation $\smash{\sum_{x \in [D]} \e^{i \theta_x} \ket{\smash{\omega^x}}^{\!\otimes n}\!\bra{\smash{\omega^x}}^{\!\!\;\otimes m}}$ to a red dot with parameter $\boldsymbol\theta$.
For $D>2$, taking such a conventional interpretation does not yield a `flexsymmetric' [46] calculus, in effect because $\bra{\smash{\omega^a}}\trans = \ket{\smash{\omega^a}}^\ast = \ket{\smash{\omega^{-a}}}$.
In particular, this would mean that

\begin{equation}
\label{eqn:red-deg-2-dots-flexsymmetric}
\biggsem{\,%
\begin{aligned}~\\[-2ex]
\begin{tikzpicture}
\node (X) at (0,0) [X dot, label=above:\small$\boldsymbol\theta$] {};
\draw (X) -- ++(.625,0);
\draw (X) -- ++(-.125,0) arc (270:90:.3125) -- ++(.75,0);
\end{tikzpicture}
\end{aligned}
\,}
\;=\;
\biggsem{\!\! %
\begin{aligned}
\begin{tikzpicture}
\node (X) at (0,0) [X dot, label=left:\small$\boldsymbol\theta$] {};
\draw (X) .. controls (0.125,0.3175) .. ++(.625,0.3125);
\draw (X) .. controls (0.125,-0.3125) .. ++(.625,-0.3125);
\end{tikzpicture}
\end{aligned}
\,}
\;=\;
\biggsem{\,%
\begin{aligned}~\\[-4.5ex]
\begin{tikzpicture}
\node (X) at (0,0) [X dot, label=below:\small$\boldsymbol\theta$] {};
\draw (X) -- ++(.625,0);
\draw (X) -- ++(-.125,0) arc (90:270:.3125) -- ++(.75,0);
\end{tikzpicture}
\end{aligned}
\,}
\end{equation}

would not hold: the first would denote $\sum_x \e^{i\theta_x} \ket{\smash{\omega^{-x}, \omega^x}}$, the second would denote $\sum_x \e^{i\theta_x} \ket{\smash{\omega^x, \omega^x}}$, and the third would denote $\sum_x \e^{i\theta_x} \ket{\smash{\omega^x, \omega^{-x}}}$.
Specifically, this represents a way in which such a calculus would fail to have the useful syntactic property that “only the connectivity matters” [1, 13]; and other inconveniences would also arise, which would make these diagrams more difficult to work with.
In order to avoid this problem, we endorse the convention adopted Refs. [27, 28] of involving a generator which is related to the green dot by different unitary transformations on the inputs and outputs.
We then interpret the generators of Eqn (<ref>) as operators using a model $\sem{\,\cdot\,}$  which typically satisfies the following:

\begin{equation}{}
\label{eqn:ZX-conventional-model}
\mspace{-36mu}
\begin{aligned}{}
\Biggsem{\!\!\!\tikzfig{ZX-green-phase-dot-arity}\!\!\!}
\sum_{x \in [D]} \!
\Theta(x) \, \ket{x}^{\!\otimes n}\!\bra{x}^{\!\!\;\otimes m}
\mspace{-18mu}
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\!\!\: \tikzfig{ZX-H-plus-box} \!\!\:}
\sum_{k \in [D]} \!\!\!\;
\ket{k}\bra{\smash{\omega^{k}}}
\,=
\text{\small$\dfrac{1}{\sqrt D}$}\mathop{\sum \sum}_{x,k \in [D]}
\e^{2\pi i k x / D} \ket{x}\bra{k}
\mspace{-18mu}
% -----------------------------------------------------
\\[0.75ex]
% -----------------------------------------------------
\mspace{-18mu}
\Biggsem{\!\!\!\tikzfig{ZX-red-phase-dot-arity}\!\!\!}
\sum_{k \in [D]} \!\!\!\;
\Theta(k) \,
\ket{\smash{\omega^{-k}}}\sox{n} \!\bra{\smash{\:\!\omega^{k}}\;\!}\sox{m}
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\!\!\: \tikzfig{ZX-H-minus-box} \!\!\:}
\sum_{k \in [D]}\!
\ket{\smash{\omega^{k}}}\bra{k}
\,=
\text{\small$\dfrac{1}{\sqrt D}$}\mathop{\sum \sum}_{x,k \in [D]}
\e^{-2\pi i k x / D} \ket{x}\bra{k}
\mspace{-18mu}
\end{aligned}
\mspace{-48mu}
\end{equation}

where we allow a general function $\Theta(x)$ for $\Theta: \Z \to \C$ in place of a phase parameter $\e^{i\theta_x}$ given by a vector $\boldsymbol{\theta} \in \R^{[D]}$.
For the case $D=2$, Ref. [19] shows advantages to including scalar factors different from $+1$ for a semantic map following Eqn. (<ref>).
Our work is to describe one fruitful way to choose such scalar factors.
We can recover the usual convention of parameterising nodes by a simple phase angle when desired, by adopting a short-hand in which an angle $\theta$ stands for the function $\Theta(x) = \e^{i\theta x}$ and a vector $\boldsymbol \theta \in \R^{[D]}$ stands for the function $\Theta(x) = \e^{i\theta_x}$.
Note that the semantics for the $\smash{\tikzfig{ZX-H-plus-box}}$ box, makes it proportional to the quantum Fourier transform over $\Z_D$.

Semantics for ZH generators.

The main feature of ZH diagrams is the use of the H boxes to represent scalar coefficients in a symmetric way depending on products of indices.
We typically interpret the generators of Eqn (<ref>) as operators using a model $\sem{\,\cdot\,}$ which satisfies the following:

\begin{equation}{}
\label{eqn:ZH-conventional-model}
\mspace{-18mu}
\begin{aligned}
\Biggsem{\!\!\!\tikzfig{ZH-white-dot-arity}\!\!}
\sum_{x \in [D]}
\ket{x}^{\!\otimes n}\!\bra{x}^{\!\!\;\otimes m}
% -----------------------------------------------------
% -----------------------------------------------------
\Bigsem{\tikzfig{ZH-gen-not-dot}}
\sum_{x \in \Z_D} \ket{-c{-}x}\bra{x}
\mspace{-18mu}
% -----------------------------------------------------
\\[.25ex]
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZH-H-phase-box-arity}\!\!}
\mathop{\sum \sum}_{%
\mathclap{
{x \in [D]^m\!\!\!\;,\, y\in [D]^n}
\,
\mathrm{A}(x_1 \!\cdot\!\cdot\!\cdot x_m y_1 \!\cdot\!\cdot\!\cdot y_n) \,
\ket{y}\!\!\bra{x}
% -----------------------------------------------------
% -----------------------------------------------------
\Biggsem{\!\!\!\tikzfig{ZH-gray-dot-arity}\!\!}
\mathop{\sum \sum}_{%
\mathclap{\substack{
{x \in \Z_D^m \!\!\:,}
\,
{y \in \Z_D^n} \\[.5ex]
\sum\limits_h x_h + \sum\limits_k y_k \;\!=\, 0
\;\;
\ket{y}\!\!\bra{x}
\mspace{-24mu}
\\[-2ex]
\end{aligned}%
\end{equation}

where we allow a general function $\mathrm A: \Z \to \C$ in place of an amplitude $\alpha \in \C$ which one would conventionally use to parameterise H-boxes.
Again, we can recover the usual convention by adopting the short-hand, that an amplitude $\alpha \in \C^\times$ stands for the function $\mathrm{A}(t) = \alpha^t$ for $t \in \Z$.
Note that our convention of indexing the basis vectors of $\cH$ by $\ket{x}$ for $x \in [D] = \{L_D, L_D{+}1, \ldots, U_D{-}1, U_D\}$, means that for $D > 2$ we the exponential function $t \mapsto \alpha^t$ for $\alpha = 0$ is not well-defined.
We may instead consider a more function $\mathbf X_{\{0\}}: \Z \to \C$ given by $\mathbf X_{\{0\}}(t) = 1$ for $t = 0$, with $\mathbf X_{\{0\}}(t) = 0$ otherwise; this substitution is adequate to play the same role that $\mathrm{A}(t) = \alpha^t$ plays for $\alpha = 0$ where  $t \in \{0,1,\ldots, D{-}1\}$, e.g., in certain applications to counting complexity [33, 40].
In particular, we fix the semantics so that

\begin{equation}
\label{eqn:ZH-scalar-box}
\Bigsem{\tikzfig{ZH-scalar-box}}
\;\,=\;\,\;
\sum_{\mathclap{\text{(singleton)}}}
\;
\alpha^{\text{(empty product)}} \cdot 1
\;=\;
\alpha^1
\;=\;
\alpha.
\end{equation}

Note that for the H-boxes, we consider the products of the input and output labels $x_1, \ldots, x_m, y_1, \ldots, y_m$ as integers in the context of the expression $\mathrm A(x_1 \cdots y_m)$.
By contrast, for the gray dots and the not-dots, we adopt an interpretation of the elements of $[D]$ as integers modulo $D$, and consider $\Z_D$ arithmetic in the labels of the point-mass functions.
(For instance, for the gray dots, we constrain the summation indices $x \in \Z_D^m$ and $y \in \Z_D^n$, so that the sum of their entries is ${0 \in \Z_D}$ .)

Rewrite systems.
In addition to merely denoting operators over $\C$, we may perform calculations using ZX and ZH diagrams, by considering transformations of diagrams $\cD_1 \mapsto \cD_2$ that satisfy $\sem{\cD_1} = \sem{\cD_2}$.
This is occasionally relaxed, to consider rewrite systems for which $\sem{\cD_1} \propto \sem{\cD_2}$; systems in which equality holds may be called scalar exact to emphasise this fact.
A rewrite which preserves semantics in this way, are said to be sound for that semantic map $\sem{\,\cdot\,}$; which rewrites have this property depends on the choice of $\sem{\,\cdot\,}$.
A separate, more difficult to analyse property is how easy a rewrite system is to use.
We suggest that rewrite systems, in which the most commonly used rewrite rules can be expressed simply, are to be preferred over others; but this depends on obtaining a semantic map $\sem{\,\cdot\,}$ for which such a rewrite system is sound.
In Ref. [19], in the case $D=2$, one of us formulated just such a semantic map $\sem{\,\cdot\,}_\nu$ for both ZX and ZH diagrams.
However, the semantics assigned to the ZX and ZH generators by $\sem{\,\cdot\,}_\nu$ is non-obvious, presenting a different obstacle to working with those semantics.
This raises the question of how one might obtain semantics for the ZX and ZH generators, which are themselves easily to express and reason about, and also  leads to a system of rewrites which is simple and easy to reason about.

§ QUDIT OPERATORS AS MULTI-LINEAR MAPS ON A MEASURE SPACE

In this section, we consider how we may express sums and multilinear operators on $\cH \cong \C^D$, in terms of integrals over $[D]$ with a discrete measure.
We then consider the constraints imposed on Ockhamic semantic map of ZX- and ZH-generators, by requiring that they be simply expressed by such integrals.
We then describe some of the consequences of these semantics for rewrite systems on these diagrams.

§.§ Measures and integration over $\Z_D$

We may consider the $\sigma$-algebra $\mathcal B = \wp([D])$, consisting of all subsets of $[D]$, and define the measure ${\mu: \mathcal B \to \R}$ on this $\sigma$-algebra given by

\begin{equation}
\mu(S) \;=\; \# S \cdot \nu^2,
\end{equation}

for some $\nu > 0$ which in principle may be chosen freely.
(Here, $\# S$ simply denotes the number of elements of $S$.)
Let $N = D \nu^2$ represent the measure that we assign to the entire set $[D]$ in that $\mu([D]) = N$; we also have $\mu(\{a\}) = \nu^2 = N/D$ for an arbitrary singleton $a \in [D]$.

This presents $[D]$ as a measure space, the purpose of which is to allow us to define (multi-)linear operators on $\cH$ as arising from integrals with respect to that measure.
For a function $f: \Z \to \C$, we may define a notion of integration of $f$ over a subset $S \subset [D]$:

\begin{equation}
\label{eqn:integral-over-ZD}
\begin{aligned}[b]
\int\limits_{x \in S} \!f(x) \;	\mathrm d\mu(x)
\;&=\;
\sum_{x \in S}	\, f(x) \, \mu(\{x\})
\;=\,
\sum_{x \in S} f(x) \,\nu^2,
\text{and in particular}\
N &= \int\limits_{\mathclap{x \in [D]}} 1 \cdot \mathrm d\mu(x)\,,
\end{aligned}
\end{equation}

consistent with the notion of normalisation of $N$ for the entire measure space $[D]$.

Our use of integrals and discrete measures in this way is standard, if somewhat uncommon in quantum information theory: see Ref. [47] for a comparable example
(though in our work, we sometimes emphasise the measure more).
Nor are we the first to use integration in relation to describing diagrammatic calculi: see for instance the work of Majid [29], which however is much more concerned with defining a form of the ZX calculus to non-(co-)commutative algebras and co-algebras.
By contrast, our intent is explicitly to draw attention to integrals as an means of defining multi-linear operators on $\cH$, as an approach to defining semantic maps for ZX and ZH diagrams.

We may apply this notion of integration to operator-valued functions, as is typical for wave-functions in quantum mechanics.
For instance, one may define

\begin{equation}
\int\limits_{x \in S} \! f(x) \,\ket{x}\, \mathrm d\mu(x)
\;=\;
\nu^2 \sum_{x \in S}\, f(x) \, \ket{x}.
\end{equation}

Note that in the usual approach to describing wave-functions over $\R$, one takes $\ket{x}$ to represent a point-mass distribution (i.e., it isn't a vector $\vec v \in \C^\R$ for which $v_x = 1$), so that the following equality holds:

\begin{equation}
\bra{z} \Biggl[\;\; \int\limits_{\mathclap{x \in \R}} f(x) \!\;\ket{x} \, \mathrm dx \,\Biggr]
\int\limits_{\mathclap{x \in \R}} f(x) \!\;\delta_z(x) \, \mathrm dx \,
\,=\,
\end{equation}

where here $\delta_z(x)$ is a shifted Dirac distribution (see Appendix <ref> for more details).
In the vector space $\cH$, to avoid notational confusion, we prefer to reserve the symbol `$\ket{x}$' to represent a unit-norm standard basis vector (i.e., a vector $\vec v \in \cH$ such that $v_x = 1$); but we may introduce a symbol `$\kket{x}$' which denotes the vector $\kket{x}  \,=\, \tfrac{1}{\nu} \ket{x}$, specifically so that we may write

\begin{equation}{}
\mspace{-18mu}
\label{eqn:initial-attempt-point-mass-distribution}
\begin{aligned}[b]
\bbra{z} \Biggl[\, \int\limits_{\;x \in [D]} \!\!\!f(x) \;\kket{x} \; \mathrm d\mu(x) \:\!\Biggr]
\,&=\!\!
\int\limits_{\;x \in [D]} \!\!\!f(x) \;\bbracket{z}{x} \; \mathrm d\mu(x)%	\mspace{-36mu}
\;=\;
\nu^2\! \sum_{x \in [D]} \! f(x) \frac{\bracket{z}{x}}{\nu^2}
%	\mspace{-36mu}
\,=\;
\,,
\end{aligned}
\end{equation}

and also

\begin{equation}{}%~\\[-1ex]
\mspace{-18mu}
\label{eqn:resolution-of-the-identity}
\begin{aligned}[b]
\int\limits_{\;x \in [D]} \!\!\!\kket{x}\bbra{x} \; \mathrm d\mu(x)
\;&=\;
\nu^2  \sum_{x \in [D]} \! \frac{\ket{x}\bra{x}}{\nu^2}
%	\mspace{-36mu}
\,=\;
\sum_{x \in [D]} \ket{x}\bra{x}
\;=\;
\mathbf 1
\,.
\end{aligned}
\end{equation}

This notation `$\kket{x}$' for a possibly-non-normalised basis vector provides us the flexibility to consider which measures $\mu: \mathcal B \to \R$ are best suited for defining convenient semantics for ZX and ZH generators, while retaining the features provided by Dirac distributions over $\R$

The above is in principle all the background that is necessary to interpret these integrals over $[D]$, as we use them in this article.
However, it is also possible to interpret this notion of integration over $[D]$ in terms of integration over $\Z_D$, which in turn may be interpreted in terms of integration over a continuous group.
Readers who are interested in such an interpretation may find it in Appendix <ref>.

§.§ Constraints on normalisation motivated by the Fourier transform

A precise value for $\nu>0$ or for $N > 0$ is something that can only be fixed by imposing constraints on the way that we represent certain integrals, operators, or functionals.
We are particularly interested in the constraints imposed by how one would represent the discrete Fourier transform over $\Z_D$, as an analogue of the Fourier transform over $\R$.

For a function $f: \Z_D \to \C$, in analogy to a common representation of the Fourier transform of a real-valued function,
We emulate the presentation of the Fourier transform in terms of an oscillation frequency $k$ (as the more common convention of angular frequency $2\pi k$ used by physicists does not admit an obvious definition over the integers mod $D$).
The factor of $1\!\!\;/\!\!\;D$ in the exponent, which is the main notational difference between Eqn. (<ref>) and the usual Fourier transform over $\R$, can be shown to arise from formal connections between the Fourier transform over $\R$ and representations of functions $f: \Z_D \to \C$ in terms of discrete distributions on $\R$
(see Appendix <ref>).
Note also the presence of a minus sign in the exponent, which for historical reasons is absent in the usual definition of the quantum Fourier transform.
suppose that we wished to describe the (discrete) Fourier transform of $f$ by a function $\hat f: \Z_D \to \C$ given by

\begin{equation}
\label{eqn:FT-of-f}
\hat f(k)
\;=\;
\int\limits_{\;\mathclap{x \in \Z_D}}
\e^{-2\pi i k x / D} \, f(x)\;\mathrm d\mu(x) ,
\end{equation}

where here we adopt a notion of integration over $\Z_D$ induced by the one described above for $[D]$.
Differing conventions exist for how one might normalise the Fourier transform, over $\R$ or indeed over $\Z_D$ : in particular, opinions could differ about whether Eqn. (<ref>) should be modified by including a non-trivial scalar factor on the right-hand side.
Whether this should be done is connected to the question of whether we consider the Fourier transform to preserve the measure $\mu$ of $\Z_D$, the separate question of whether we consider it to preserve the $\ell_2$ norm of the functions it acts on in an appropriate sense, and the further question of what the measure $N = \mu(\Z_D)$ should be.

We adopt the convention of defining the Fourier transform of $f: \Z_D \to \C$ as in Eqn. (<ref>).
It will be useful (again in analogy to standard practise in physics) to use $f$ to describe a `wave-function',
Note that $\kket{f}$ is not necessarily a unit vector; whether $\kket{f} \in \cH$ is normalised depends on the values taken by $f$.

\begin{equation}
\kket{f}
\;:=\;
\int\limits_{\;\mathclap{x \in \Z_D}}
f(x) \; \kket{x} \; \mathrm d\mu(x)\,.
\end{equation}

Whether the Fourier transform “preserves the measure of $\Z_D$”, is the question of how we should interpret the domain of $\hat f$ as a measure space $(\Z_D,\mu')$, where $\mu'$ in principle may differ from $\mu$.
This may seem like quite a technical consideration, but it is in principle unavoidable in physics when performing Fourier analysis over $\R$, as it is connected to the choice of units for the domain of the function $f$ and for its Fourier transform $\hat f$.
We would write

\begin{equation}
\label{eqn:initial-ket-f-hat}
\kket{\:\!\smash{\hat f}\;\!}
\;=\;
\int\limits_{\;\mathclap{k \in \Z_D}}
\hat f(k) \, \kket{k} \; \mathrm d\mu'(k)\,,
\end{equation}

integrating with respect to that different measure, for which $\mu'(\Z_D) = N'$ might differ from $N$.
Taking $\mu' \ne \mu$ would imply that the domain of the Fourier transform, consisting of functions $f: (\Z_D,\mu) \to \C$, is strictly speaking not the same as the codomain $\hat f: (\Z_D,\mu') \to \C$.
The string diagrams that would result, would involve wires of more than one type.
While not impossible in principle, this is a departure from the usual approach of defining the ZX and ZH calculus, in which the wires all have the same type.
For the sake of simplicity — both in analysis of integrals, and in the design of ZX and ZH calculi — we prefer to conceive of $f$ and $\hat f$ as having the same measure space $(\Z_D,\mu)$ for their domains.
Identifying $\mu' = \mu$, we may simplify Eqn. (<ref>) to

\begin{equation}
\label{eqn:ket-f-hat}
\begin{aligned}[b]
\kket{\:\!\smash{\hat f}\;\!}
\;&=\,
\int\limits_{\;\mathclap{k \in \Z_D}}
\hat f(k) \, \kket{k} \; \mathrm d\mu(k)
\;=\,
\mathop{\int \!\!\!\! \int}\limits_{\;\mathclap{k,x \in \Z_D}}
\e^{-2\pi i k x / \!\!\: D}  f(x) \;\kket{k} \;\mathrm d\mu(x) \; \mathrm d\mu(k)
\,.
\end{aligned}
\end{equation}

This would then motivate the definition for the discrete Fourier transform operator $F$ over $\Z_D$, as

\begin{align}
\label{eqn:integral-FT}
\;&=\;
\mathop{\int \!\!\!\! \int}\limits_{\;\mathclap{k,x \in \Z_D}}
\e^{-2\pi i k x / D} \;\kket{k}\bbra{x} \;\mathrm d\mu(x) \; \mathrm d\mu(k)
\;,
\end{align}

so that $F\kket{f} = \kket{\smash{\hat f}\:\!}$.

The question of whether the Fourier transform preserves the norm, is precisely  the question of whether $F$ is unitary.
We adopt the convention that $F$ is indeed unitary, to allow it to directly represent a possible transformation of state-vectors over $\cH$.
This has the further benefit that the inverse Fourier transform can be expressed simularly to the Fourier transform, i.e., without scalar factors:

\begin{equation}{}
\label{eqn:integral-inv-FT}
\mspace{-18mu}
\mathop{\int \!\!\!\! \int}\limits_{\;\mathclap{x,k \in \Z_D}}
\e^{2\pi i k x / D} \,\kket{x}\bbra{k} \;\mathrm d\mu(k) \; \mathrm d\mu(x)
\,,
\mspace{-9mu}
\end{equation}

so that in particular we may write

\begin{equation}{}
\mspace{-18mu}
\,=\,
\bbra{x} F\herm \kket{\smash{\hat f}\:\!}
\,=
\int\limits_{\;\mathclap{k \in \Z_D}}
\e^{2\pi i k x / D} \; \hat f(k) \;\mathrm d\mu(k)
\,,
\end{equation}

again in close analogy to the standard definition of the Fourier transform over $\R$.

The definition of $F$ in Eqn. (<ref>) and the constraint that it should be unitary, imposes a constraint on the measure $\mu$ on $\Z_D$.
We first prove a routine Lemma (which will be of some use in the Appendices in simplifying iterated integrals):

Let $\omega = \e^{2\pi i\!\!\;/\!\!\;D}$ and $E \in [D]$.
\mathop{\text{\LARGE $\int$}}\limits_{\mathclap{k \in \Z_D}}
\omega^{Ek} \; \mathrm d\mu(k)
\,=\,
\bbracket{E}{0} \, D\nu^4.

This holds by reduction to the usual exponential sum:

\begin{equation*}
\begin{aligned}[b]
\int\limits_{\mathclap{k \in [D]}}
\e^{2\pi i Ek/\!\!\:D} \; \mathrm d\mu(k)
\;=\;
\nu^2 \! \sum_{k \in [D]}
\bigl(\omega^E\bigr)^k
\left\{
\begin{aligned}
\nu^2\cdot \omega^{E L_D} \cdot \text{\small$\dfrac{(\omega^E)^D-1}{\omega-1}$}\,
,&~ ~	\text{if $\omega^{E} \ne 1$}
\\[2ex]
\nu^2 \cdot D
,&~ ~	\text{if $\omega^{E} = 1$}
\end{aligned}
\right\}
\;&=\;
\delta_{E,0} \; D\nu^2
\\[-2.5ex]&=\;
\bracket{E}{0} D\nu^2
\\[1.5ex]&=\;
\bbracket{E}{0} \, D\nu^4	\;.
\end{aligned}
\qedhere
\end{equation*}

We may apply this in the case of the Fourier transform as follows.
If $F$ as expressed in Eqn. (<ref>) is unitary, we have

\begin{equation}
\label{eqn:constraint-on-N-via-FT}
\begin{aligned}[b]
\mathbf 1
\;=\;
F\herm F
\;&=\;
\Biggl[\;\;\;
\mathop{\int \!\!\!\! \int}\limits_{%
\mathclap{
y,h \in [D]
\e^{2\pi i hy/\!\!\:D} \; \kket{y} \bbra{h} \;
\mathrm d\mu(y) \; \mathrm d\mu(h)
\Biggr]
\Biggl[\;\;\;
\mathop{\int \!\!\!\! \int }\limits_{%
\mathclap{
k,x \in [D]
\e^{-2\pi i kx/\!\!\:D} \; \kket{k} \bbra{x} \;
\mathrm d\mu(k) \; \mathrm d\mu(x)
\Biggr]
\\&=\;
\mathop{\int \!\!\!\! \int \!\!\!\! \int \!\!\!\! \int}\limits_{%
\mathclap{
y,h,k,x \in [D]
\e^{2\pi i (hy - kx)/\!\!\:D} \; \kket{y} \bbracket{h}{k} \bbra{x} \;
\mathrm d\mu(y) \; \mathrm d\mu(h) \; \mathrm d\mu(k) \; \mathrm d\mu(x)
\\[1.5ex]&=\;
\mathop{\int \!\!\!\! \int \!\!\!\! \int}\limits_{%
\mathclap{
y,k,x \in [D]
\e^{2\pi i k(y - x)/\!\!\:D} \; \kket{y} \bbra{x} \;
\mathrm d\mu(y) \; \mathrm d\mu(k) \; \mathrm d\mu(x)
\\[1ex]&=\;
\mathop{\int \!\!\!\! \int}\limits_{%
\mathclap{
y,x \in [D]
}} \;\;
\Biggl[\;\;\; \int\limits_{\mathclap{k \in [D]}}
\e^{2\pi i k(y - x)/\!\!\:D} \; \mathrm d\mu(k)  \Biggr]
\; \kket{y} \bbra{x} \;
\mathrm d\mu(y) \; \mathrm d\mu(x)
\\[1ex]&=\;
\mathop{\int \!\!\!\! \int}\limits_{%
\mathclap{
y,x \in [D]
}} \;
\Bigl[ D\nu^4 \cdot \bbracket{y}{x} \Bigr]
\; \kket{y} \bbra{x} \;
\mathrm d\mu(y) \; \mathrm d\mu(x)
\,=\;
D\nu^4 \!
\mathop{\int}\limits_{%
\mathclap{
x \in [D]
}} \kket{x} \bbra{x} \;
\mathrm d\mu(x)
\,=\,
D\nu^4 \cdot \mathbf 1
\,.
\end{aligned}
\mspace{-18mu}
\end{equation}

This implies that $\nu = D^{-1/4}$
(or equivalently, $N = \mu(\Z_D) = D \nu^2 = \sqrt D$).

It may be of interest to consider, how imposing a value for $N$ different from $\sqrt D$ would affect the presentation of the Fourier transform, or the relationships between the measures of the domain of a function $f: (\Z_D,\mu) \to \C$ and that of $\hat f$.
We discuss this in Appendix <ref>.

§ APPLICATION TO ZX- AND ZH-CALCULI

There are a number of convenient consequences to defining a discrete integral on $[D]$ as we do in the preceding Section, firstly for analysis of the Fourier transform and certain discrete integrals of roots of unity, and for sound rewrite systems on ZX and ZH diagrams when we assign semantics for the ZX and ZH generators as we do in Eqn. (<ref>).
In this section, we demonstrate these features — in part to demonstrate how simple operators would be denoted using our semantics for the ZX and ZH generators, but also in part to demonstrate how those same operators can be denoted using discrete integrals.

Fourier basis distributions.
We defined the vectors $\kket{\smash{\omega^k}}$ on page discn:define-ket-omega essentially as a formal (super-normalised) analogue of the orthonormal Fourier basis states $\ket{\smash{\omega^k}}$.
As a simple consequence of choosing the normalisation for integrals over $[D$], so that the Fourier transform is a unitary transformation on wave-functions, we may express the vectors $\kket{\smash{\omega^k}}$ quite simply (dropping the $\mathrm d\mu(x)$ for brevity):

\begin{equation}
\label{eqn:Fourier-basis}
\kket{\smash{\omega^k}}
\;=\;
F \kket{k}
\;=\;
\int\limits_{\mathclap{x \in [D]}} \omega^{-kx} \,\kket{x}	\;.
\end{equation}

Quadratic Gaussian integrals.
Following Ref. [50], define the complex unit $\tau = \e^{\pi i(D^2 + 1)/D}$, which is relevant to the analysis of stabiliser circuits on qudits of dimension $D$.
To analyse such circuits using ZX diagrams, the following integral will be relevant:

\begin{equation}
\label{eqn:quadratic-Gauss-integral}
\Gamma(a,b,D)
\;:=\;
\int\limits_{\mathclap{x \in [D]}} \tau^{2ax + bx^2}	\;.
\end{equation}

Evaluating this discrete integral is connected with the subject of quadratic Gaussian sums, which we address in some detail Appendix <ref>.
As a result of the normalisation convention for our discrete integrals, it is possible to show (see Eqn. (<ref>) on page eqn:quadratic-Gauss-integral-formula) that $\bigl\lvert \Gamma(a,b,D) \bigr\rvert = 1$ when $b$ is a multiplicative unit modulo $D$ (e.g., $b = \pm 1$); if $a = 0$ as well, $\Gamma(a,b,D)$ is a power of $\e^{\pi i /4}$.
More generally, $ \Gamma(a,b,D)$ will either be $0$, or have magnitude $\sqrt t$, where $t = \gcd(b,D)$.
Specifically, we have $\Gamma(a,b,D) = 0$ if $a$ is not divisible by $t$, or if ${(D +\!\!\; Db/t^2)} \in \Z$ is odd; and $\lvert \Gamma(a,b,D) \rvert = \sqrt{t}$ otherwise.
In particular, $\Gamma(0,0,D) \,=\, \int_x 1 \; \mathrm d\mu(x) \,=\,  \sqrt{D}$.

The stabiliser fragment of ZX for qudits of dimension $D$.
The scalar $\tau$ is defined in such a way that $\tau^2 = \omega$, but also so that $\tau X\herm Z\herm$ is an operator of order $D$, where $X$ and $Z$ given by

\begin{equation}
X \ket{t}	\;=\;	\ket{t+1},
\qquad\qquad
Z \ket{t}	\;=\;	\omega^t \ket{t},
\end{equation}

are the $D$-dimensional generalised Pauli operators.
(As always, arithmetic performed in the kets are evaluated modulo $D$.)
Choosing $\tau$ in this way makes it possible [50] to define a simple and uniform theory of unitary stabiliser circuits on qudits of dimension $D$, generated by the single-qudit operators
Note that the definitions below are equivalent to those of Ref. [50], despite the different convention we adopt for the labeling of the standard basis.
For each $x \in [D]$, we either have $x \ge 0$ or $x < 0$: in the latter case the relative phases $\tau^{\raisebox{-0.125ex}{$\scriptscriptstyle 2ax + bx^2$}}$ remain well-defined on substitution of values $x < 0$ with $D+x$, as $\tau^{\raisebox{-0.125ex}{$\scriptscriptstyle 2a(D+x) + b(D+x)^2$}} = \tau^{\raisebox{-0.125ex}{$\scriptscriptstyle 2aD + 2ax + bD^2 + 2bD + bx^2$}} =  \tau^{\raisebox{-0.125ex}{$\scriptscriptstyle 2ax + bx^2$}}$ (using the fact that $\tau^{\raisebox{-0.125ex}{$\scriptscriptstyle D^2$}} = \tau^{\raisebox{-0.125ex}{$\scriptscriptstyle 2D$}} = 1$ for both even and odd $D$).

\begin{align}
\,&=
\int\limits_{\mathclap{x\in[D]}} \tau^{\,x^2} \;\kket{x}\bbra{x}
\;;
\,&=
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{k,x\in[D]}} \tau^{-2kx} \;\kket{k}\bbra{x}
\;;
\,&=
\int\limits_{\mathclap{x\in[D]}} \kket{ux}\bbra{x}
\quad
\text{for various $u \in \Z_D^\times$},
\end{align}

and either one of the two-qudit operators

\begin{align}
\mathrm{CX}
\,&=
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y\in[D]}} \kket{x}\bbra{x} \otimes \kket{x{+}y}\bbra{y}
\;;
\mathrm{CZ}
\,&=
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y\in[D]}} \tau^{2xy}\;\kket{x,y}\bbra{x,y} \;.
\end{align}

Using a slightly different notational convention to Booth and Carette [27], we may easily denote these with ZX diagrams using the semantics of Eqn. (<ref>).
For $a,b \in \Z$, when parameterising a green or red dot, let $[a \s b]$ stand for the amplitude function $\Theta(x) = \tau^{2ax + bx^2}$, so that

\begin{align}{}
\biggsem{\!\!\!%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (z) at (0,0.375) [Z dot, label=left:\small{$[a \s b]$}] {};
\draw (z) -- ++(.5,0);
\end{tikzpicture}
\end{aligned}\,}
\,&=\,
\int\limits_{\mathclap{x \in [D]}}\!
\tau^{\,2ax \,+\, bx^2} \,\kket{x}
\;;
\biggsem{\!\!\!%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0.375) [X dot, label=left:\small{$[a \s b]$}] {};
\draw (x) -- ++(.5,0);
\end{tikzpicture}
\end{aligned}\,}
\,&=\,
\int\limits_{\mathclap{k \in [D]}}\!
\tau^{\,2ak \,+\, bk^2} \,\kket{\smash{\omega^{-k}}}
\;;
\end{align}

generalising these to dots with multiple edges (or with none) similarly to Ref. [27].
When $b = 0$, we may abbreviate this function simply by $[a]$, so that
we may then easily represent the operators $S$, $Z$, and $X$ as $1 \to 1$ dots:

\begin{align}
\mspace{-18mu}
\biggsem{\,
\vtikzfig[-1ex]{ZX-Z}
\,}
\,&=\,
\int\limits_{\mathclap{x \in [D]}}\!
\tau^{2x}	\;
\kket{x}\bbra{x}
\;=\;
\;;
\qquad\qquad\qquad
\qquad
\biggsem{\,%
\begin{aligned}{}
%		~\\[-1.25ex]
\begin{tikzpicture}[]
\node  at (0,0.375) [Z dot, fill=none, draw=none, label=below:\phantom{\footnotesize{$[\;\!0 \s 1\;\!]$}}] {};
\node (x) at (0,0.375) [Z dot, label=above:\footnotesize{$[\;\! 0 \s 1\;\!]$}] {};
\draw (x) -- ++(.625,0);
\draw (x) -- ++(-.625,0);
\end{tikzpicture}
\end{aligned}\,}
\,=\,
\int\limits_{\mathclap{x \in [D]}}\!
\tau^{\,x^2}	\;
\kket{x}\bbra{x}
\;=\;
\;;
\mspace{-12mu}
\\[1.25ex]
\mspace{-18mu}
\label{eqn:ZX-X-gadget}
\biggsem{\,
\vtikzfig[-1ex]{ZX-X}
\,}
\,&=\,
%		\mathop{\int\!\!\!\!\int}\limits_{\mathclap{h,k \in [D]}}\!
%			 \,\Bigl(
%			 	\tau^{-2k}	\;
%				\kket{\smash{\omega^{-k}}}\bbra{\smash{\omega^{k}}}
%			\Bigr)
%			\Bigl(
%				\kket{\smash{\omega^{-h}}}\bbra{\smash{\omega^{h}}}
%			\Bigr)
%	\,=\,
\int\limits_{\mathclap{h \in [D]}}\!
\tau^{2h}	\;
\kket{\smash{\omega^{h}}}\bbra{\smash{\omega^{h}}}
\,=\,
\;.
\mspace{-12mu}
\end{align}

We may also represent the states $\kket{a}$ and $\kket{\omega^a}$ straightforwardly (albeit with the use of auxiliary red dots to represent an antipode operator, mapping $\kket{\omega^a} \mapsto \kket{\smash{\omega^{-a}}}$ and $\kket{a} \mapsto \kket{-a}$ for $a \in \Z_D$):

\begin{align}
\mspace{-18mu}
\biggsem{\!%
\vtikzfig[-1ex]{ZX-kket-omega-a}
\,}
\,&=\,
\mathop{\int \!\!\!\!\int}\limits_{\mathclap{k,x \in [D]}}\!
\tau^{2ax} \,\kket{\smash{\omega^{-k}}}\bbracket{\smash{\omega^k}}{x}
%	\,=
%		\int\limits_{\mathclap{k \in [D]}}\;
%			\Biggl(\;\;\;
%				\int\limits_{\mathclap{x \in [D]}}
%					\omega^{x(k+a)}
%			\!
%			\Biggr)\;\!
%			\kket{\smash{\omega^{-k}}}
%	\,=\!\:
%		\int\limits_{\mathclap{k \in [D]}}	\!\!\;
%			\bbracket{k\!+\!a}{0} \!\;
%			\kket{\smash{\omega^{-k}}}
\;=\;
\kket{\smash{\omega^a}}
\,;
\mspace{-12mu}
\\[1.25ex]
\mspace{-18mu}
\biggsem{\!%
\vtikzfig[-1ex]{ZX-kket-a}
\,}
\,&=\,
\mathop{\int \!\!\!\! \int}\limits_{\mathclap{h,k \in [D]}}\!
\tau^{2ah} \,\kket{\smash{\omega^{-k}}}
\bbracket{\smash{\omega^k}}{\smash{\omega^{-h}}}
%	\,=
%		\int\limits_{\mathclap{k \in [D]}}\!
%			\omega^{ak}  \,\kket{\smash{\omega^k}}
%	\,=
%		\int\limits_{\mathclap{x \in [D]}}
%		\Biggl(\;\;\;
%			\int\limits_{\mathclap{k \in [D]}}\!
%				\omega^{k(x-a)}
%		\!
%		\Biggr)
%		\kket{x}
%	\,=
%		\int\limits_{\mathclap{x \in [D]}}
%		\bbracket{x}{a}
%		\; \kket{x}
\;=\;
\kket{a}
\,.
\mspace{-12mu}
\end{align}

The remaining operators may be expressed without any phases, using multi-edges between green and red dots, or using Hadamard boxes:

\begin{align}
%	\Biggsem{\,
%		\vtikzfig[-1ex]{ZX-CNOT-gadget}
%	\,}
%	=
\Biggsem{\,
\vtikzfig[-1ex]{ZX-CNOT-alt-gadget}
\,}
\mathrm{CX}
\;,
\Biggsem{\,%
\begin{aligned}{}
%		~\\[-1.25ex]
\begin{tikzpicture}[]
\node (c) at (0,0) [Z dot] {};
\draw (c) -- ++(.375,0);
\draw (c) -- ++(-.375,0);
\node (t) at ($(c) + (0,-.75)$) [Z dot] {};
\draw (t) -- ++(.375,0);
\draw (t) -- ++(-.375,0);
\draw (c) -- node [midway, small H box] {\tp} (t);
\end{tikzpicture}
\end{aligned}\,}
\,&=\,
\mathrm{CZ}
\;,
\Biggsem{\,\begin{aligned}
\begin{tikzpicture}
\node (Z) [Z dot] at (0,0) {};
\draw (Z) -- ++(-0.375,0);
\node (G) [X dot] at (1.125,0) {};
\draw (G) -- ++(0.375,0) node [X dot] {} -- ++(0.375,0);
\draw [out=70,in=110] (Z) to (G);
\draw [out=45,in=135] (Z) to (G);
\draw [out=-45,in=-135] (Z) to (G);
\draw [out=-70,in=-110] (Z) to (G);
\node at ($(Z)!0.375!(G) + (0,0.0875)$) {$\vdots$};
\node at ($(Z)!0.5875!(G) + (0,0.)$) {$\left. \begin{matrix} \\[4ex] \end{matrix}\right\} \! u$};
\end{tikzpicture}
\end{aligned}}
\,&=\,
\;.
\end{align}

(The diagram shown for $M_u$ also generalises to operators $M_u = \int_x \kket{ux}\bbra{x}$ for $u$ not a multiplicative unit modulo $D$, though in that case the operator will not be invertible.)
Finally, dots of degree $0$ frequently have a simple interpretation:

\begin{equation}{}
\mspace{-18mu}
\Bigsem{\!
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0.375) [Z dot, label=left:\footnotesize{$[a \s b]\!$}] {};
\end{tikzpicture}
\end{aligned}\,}
\;=\,
\int\limits_{\mathclap{x \in [D]}} \tau^{2ax + bx^2}
\Gamma(a,b,D)
\,=\;
\left\{
\begin{aligned}
\sqrt{t\,} \cdot \e^{i\gamma}		,
&\quad	\text{if $t = \gcd(b,D)$ and $a$ is divisible by $t$};
\\
&\quad	\text{otherwise},
\end{aligned}
\right.
\mspace{-18mu}
\end{equation}

where $\gamma$ is a phase parameter described in more detail in Eqn. (<ref>); where in particular for $b$ a multiplicative unit modulo $D$, this represents a global phase factor.
This provides a diagrammatic language which is capable of expressing the rewrites similar to those described by Ref. [27], while involving fewer scalar factors; and the semantics can be easily described through the use of discrete integrals over $[D]$.
To make our presentation of the ZX-calculus complete for the stabilizer fragment (i.e., for the subtheory in which all amplitudes are given by ${[\!\:a \s b \!\:]}$ for various $a,b \in \Z$),
Note in particular that we do not present any rules which are clear analogues to the rules , ,  , or  of Ref. [27].
We expect that such rules would be necessary to demonstrate completeness for the stabiliser fragment of ZX for $D>2$ prime.
Still more work still may be necessary to demonstrate completeness for composite $D$, thoigh possibly in the case where $D$ is square-free may prove to be simpler than the general case.
it would suffice to describe rewrites for particular values of $D$ which force an interpretation of $\!
\tikz \node [Z dot, label=left:\footnotesize{$[a \s b]\!$}] {};
\,$
as being either $\Gamma(a,b,D)$ or $\Gamma(a,b,D)^\ast$.

Multipliers and multicharacters in qudit ZH.

In practise, it would be cumbersome to reason about multiplication operators $M_u$ or iterated $\mathrm{CX}$ or $\mathrm{CZ}$ gates using parallel edges between dots.
Booth and Carette describe [27] how these may be denoted using recursively defined gadgets called `multipliers', denoted
\draw (0,0) -- node [midway, rfarr] {\t c} (1,0);
\,$
for $c \in \N$, which represent a limited form of scalable ZX notation [51, 52].
Using discrete integrals and the semantics described in Eqn. (<ref>), we would simply write

\begin{equation}
\Biggsem{\,\begin{aligned}
\begin{tikzpicture}
\node (a) [rfarr] at (0,0) {\t c};
\draw (a) -- ++(-0.4375,0);
\draw (a) -- ++(0.5,0);
\end{tikzpicture}
\end{aligned}}
\;=\;
\Biggsem{\,\begin{aligned}
\begin{tikzpicture}
\node (Z) [Z dot] at (0,0) {};
\draw (Z) -- ++(-0.375,0);
\node (G) [X dot] at (1.125,0) {};
\draw (G) -- ++(0.375,0) node [X dot] {} -- ++(0.375,0);
\draw [out=70,in=110] (Z) to (G);
\draw [out=45,in=135] (Z) to (G);
\draw [out=-45,in=-135] (Z) to (G);
\draw [out=-70,in=-110] (Z) to (G);
\node at ($(Z)!0.375!(G) + (0,0.0875)$) {$\vdots$};
\node at ($(Z)!0.5875!(G) + (0,0.)$) {$\left. \begin{matrix} \\[4ex] \end{matrix}\right\} \! c$};
\end{tikzpicture}
\end{aligned}}
%	\Biggsem{\,\begin{aligned}
%	\begin{tikzpicture}
%		\node (Z) [white dot] at (0,0) {};
%		\draw (Z) -- ++(-0.375,0);
%		\node (G) [gray dot] at (1.125,0) {};
%		\draw (G) -- ++(0.375,0) node [gray dot] {} -- ++(0.375,0);
%		\draw [out=70,in=110] (Z) to (G);
%		\draw [out=45,in=135] (Z) to (G);
%		\draw [out=-45,in=-135] (Z) to (G);
%		\draw [out=-70,in=-110] (Z) to (G);
%		\node at ($(Z)!0.375!(G) + (0,0.0875)$) {$\vdots$};
%		\node at ($(Z)!0.5875!(G) + (0,0.)$) {$\left. \begin{matrix} \\[4ex] \end{matrix}\right\} \! c$};
%	\end{tikzpicture}
%	\end{aligned}}
%	\Bigsem{\;\begin{aligned}
%	\begin{tikzpicture}
%		\node (K) [H box] at (0,0) {\t{c}};
%		\draw (K) -- ++(-0.5,0);
%		\draw (K) -- ++(0.5,0) node [small H box] {\tm} -- ++(0.5,0);
%	\end{tikzpicture}
%	\end{aligned}\;}
%	M_k
\;=\;
\int\limits_{\mathclap{x \in [D]}} \kket{cx}\bbra{x}
\;.
\end{equation}

Using these multipliers, Booth and Carette <cit.> then define `Fourier boxes' $
\begin{aligned}
\begin{tikzpicture}
\node (K) [H box] at (0,0) {\t{c}};
\draw (K) -- ++(-0.5,0);
\draw (K) -- ++(0.5,0);
\end{tikzpicture}
\end{aligned}
\,:=\,
\begin{aligned}
\begin{tikzpicture}
\node (a) [rfarr] at (0,0) {\t c};
\node (K) [small H box] at ($(a) + (0.625,0)$) {\tp};
\draw (a) -- ++(-0.5,0);
\draw (K) -- ++(0.375,0);
\draw (a) -- (K);
\end{tikzpicture}
\end{aligned}
$ (using our notation for Hadamard boxes), with semantics given by

\begin{equation}
\Bigsem{\;\begin{aligned}
\begin{tikzpicture}
\node (K) [H box] at (0,0) {\t{c}};
\draw (K) -- ++(-0.5,0);
\draw (K) -- ++(0.5,0);
\end{tikzpicture}
\end{aligned}\;}
\;=\;
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y \in [D]}}
\omega^{cxy} \; \kket{y}\bbra{x}
\;.
\end{equation}

As a ZH generator, this is an H-box with an amplitude parameter $\omega^c$.
Using this as a primitive, and composing this with the inverse
\draw (0,0) -- node [midway, small H box] {\tm} (.75,0);
\,$
of the positive Hadamard box
\draw (0,0) -- node [midway, small H box] {\tp} (.75,0);
\,$, we may directly describe multipliers instead as a ZH gadget, also loosely following Roy [35]:

\begin{equation}
\begin{aligned}
\begin{tikzpicture}
\node (K) [H box] at (0,0) {\t{c}};
\node (h) [small H box] at ($(K) + (0.625,0)$) {\tm};
\draw (K) -- ++(-0.5,0);
\draw (h) -- ++(0.375,0);
\draw (K) -- (h);
\end{tikzpicture}
\end{aligned}
\;\;=:\;\;
\begin{aligned}
\begin{tikzpicture}
\node (a) [rfarr] at (0,0) {\t c};
\draw (a) -- ++(-0.5,0);
\draw (a) -- ++(0.5,0);
\end{tikzpicture}
\end{aligned}
\;\;.
\end{equation}

The amplitude parameter $\omega^c$ corresponds to a character function $\uchi_c: \Z \to \C$ given by $\uchi_c(x) = \omega^{cx}$, which is well-defined modulo $D$, and which we may then regard as a character on $\Z_D$.
The function $\Z \x \Z \to \C$ given by $(x,y) \mapsto \uchi_c(xy)$ is a bicharacter, which is also well-defined modulo $D$ on each of its arguments; and more generally we may consider multicharacters, which are functions $\Z_D \x \cdots \x \Z_D \to \C$ given by $(x_1, \ldots, x_n) \mapsto \omega^{c x_1 \cdots x_n}$.
We may call H-boxes with any number of edges, and with amplitude parameter $\omega^c$ for some $c \in \Z_D$, a ($\Z_D$-)multicharacter box.
We may use multiplier gadgets and multicharacter boxes themselves to usefully describe unitary transformations:

\begin{align}
%	\Sem{10ex}{\,
%		\vtikzfig[-1.75ex]{ZXH-CNOT-c-gadget}
%	\,}
%	\,&=\,
\Sem{8.5ex}{\,
\vtikzfig[-2ex]{ZXH-CNOT-c-alt-gadget}
\,}
\mathrm{CX}^c
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y \in [D]}}
\kket{x,y\!\:{+}\!\:cx}\bbra{x,y}
\;,
\Sem{7ex}{\,
\vtikzfig[-1.5ex]{ZXH-CZ-c-gadget}
\,}
\mathrm{CZ}^c
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y \in [D]}}
\omega^{cxy} \; \kket{x,y}\bbra{x,y}
\;.
\end{align}

Note that for $c \in \Z_D$, we may also easily describe unitary transformations operations which are in general not stabiliser operators over $\Z_D$, such as highly-controlled-$X$ and -$Z$ operators.
For example:

\begin{align}{}
\mspace{-48mu}
\Sem{9ex}{\;
\vtikzfig[-2.00ex]{ZXH-CCNOT-c-alt-gadget}
\;}
\mathrm{CCX}^c
\mathop{\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{x,y,z \in [D]}}
\!
\kket{x,y,z\!\:{+}\!\:cxy}\bbra{x,y,z}
\,,
\Sem{9ex}{\,\;\vtikzfig[-1.75ex]{ZXH-CCZ-c-gadget}\,\;}
\mathrm{CCZ}^c
\mathop{\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{x,y,z \in [D]}}
\!
\omega^{cxyz} \, \kket{x,y,z}\bbra{x,y,z}
\,.
\mspace{-36mu}
\end{align}

General controlled gates in qudit ZH.
The above construction is not special to multicharacters over $\Z_D$, and can also be used in conjunction with an arbitrary amplitude $\alpha \in \C^\times$ (yielding a unitary operator if and only if $\lvert \alpha \rvert = 1$), or indeed a more general function $\mathrm A: \Z \to \C$:

\begin{align}{}
\mspace{-39mu}
\Sem{11ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(1,0);
\draw (x) -- ++(-.375,0);
\node (w) at ($(x) + (0,.5875)$) [white dot] {};
\draw (w) -- ++(1,0);
\draw (w) -- ++(-.375,0);
\node (y) at ($(x) + (0,-.5875)$) [white dot] {};
\draw (y) -- ++(1,0);
\draw (y) -- ++(-.375,0);
\node (z) at ($(y) + (0,-.5875)$) [white dot] {};
\draw (z) -- ++(1,0);
\draw (z) -- ++(-.375,0);
\node [H box, label=right:\small$\!\!\:\alpha$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (w) -- (p);
\draw (x) -- (p);
\draw (y) -- (p);
\draw (z) -- (p);
\end{tikzpicture}
\end{aligned}\;}
\begin{split}
\mathop{\int\!\!\!\!\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{w,x,y,z \in [D]}}\!
\alpha^{wxyz} \; \kket{w,\!\!\;x,\!\!\;y,\!\!\;z}\bbra{w,\!\!\;x,\!\!\;y,\!\!\;z}
\\[.5ex]&\;\;\;\;{}=\;
\mathop{\sum}\limits_{\mathclap{w,x,y,z \in [D]}} \,
\alpha^{wxyz} \, \ket{w,\!\!\;x,\!\!\;y,\!\!\;z}\bra{w,\!\!\;x,\!\!\;y,\!\!\;z} \!\:,
\end{split}
\Sem{11ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(1,0);
\draw (x) -- ++(-.375,0);
\node (w) at ($(x) + (0,.5875)$) [white dot] {};
\draw (w) -- ++(1,0);
\draw (w) -- ++(-.375,0);
\node (y) at ($(x) + (0,-.5875)$) [white dot] {};
\draw (y) -- ++(1,0);
\draw (y) -- ++(-.375,0);
\node (z) at ($(y) + (0,-.5875)$) [white dot] {};
\draw (z) -- ++(1,0);
\draw (z) -- ++(-.375,0);
\node [H box, label=right:\small$\!\!\:\mathrm{A}$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (w) -- (p);
\draw (x) -- (p);
\draw (y) -- (p);
\draw (z) -- (p);
\end{tikzpicture}
\end{aligned}\;}
\begin{split}
\mathop{\int\!\!\!\!\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{w,x,y,z \in [D]}}\!
\mathrm{A}(wxyz) \; \kket{w,\!\!\;x,\!\!\;y,\!\!\;z}\bbra{w,\!\!\;x,\!\!\;y,\!\!\;z}
\\[.5ex]&\;\;\;\;{}=\;
\mathop{\sum}\limits_{\mathclap{w,x,y,z \in [D]}}\,
\mathrm{A}(wxyz) \, \ket{w,\!\!\;x,\!\!\;y,\!\!\;z}\bra{w,\!\!\;x,\!\!\;y,\!\!\;z}
\!\:.
\end{split}
\mspace{-42mu}
\end{align}

Note that here one must recall that the variables of integration are integers, and in particular that the product of the variables of integration are evaluated in $\Z$.
It is for the application of multiply-controlled $\alpha$ gates for $\alpha \in \C^\times$, that we have chosen to index the standard basis by $[D] = \{L_D, L_D{+}1, \ldots, U_D{-}1, U_D\}$, where $L_D$ is negative for $D > 2$.
The set $[D]$ admits a simple involution,

\begin{equation}
\neg: [D] \to [D] \;;
\qquad\qquad\qquad
\neg x
\::=\;
\sigma - x\,,
\qquad
\text{where $\sigma = U_D + L_D = \begin{cases}
1, & \text{if $D$ is even};
\\
0, & \text{if $D$ is odd} ,
\end{cases}
\end{equation}

so that $\neg x = 1 - x$ for $D$ even, and $\neg x = -x$ for $D$ odd.
A similar involution $\neg x = \tilde \sigma - x$ exists for alternative definitions of $[D]$, consisting of a sequence of $D$ consecutive integers.
For instance: for the more conventional choice $[D] = \{0,1,\ldots,D{-}1\}$, one would take $\tilde \sigma = D{-}1$ for all $D>1$.
This leads to rewrites which motivated us, on aesthetic grounds, to consider what definition of $[D]$ would yield the smallest possible value of $\sigma$ for various $D>1$.
This is what leads us to advocate the convention $[D] = \{L_D, L_D{+}1, \ldots, U_D{-}1, U_D\}$ for $L_D = -\lfloor \!\!\:\tfrac{D-1}{2}\!\!\: \rfloor$ and $U_D = \lfloor \!\!\;\tfrac{D}{2}\!\!\; \rfloor$, most notably given that $\sigma = 0$ for all odd $D$.
If we define the syntactic sugar $\smash{\,\tikz
\draw (0,0) -- node [midway, not dot, label=above:\footnotesize$\neg$] {} (.75,0);
\, := \,
\,\tikz
\draw (0,0) -- node [midway, not dot, label=above:\footnotesize$-\sigma$] {} (.75,0);
\,}$, we may show that

\begin{align}{}
\begin{aligned}[b]{}
\mspace{-39mu}
\Sem{15ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(1,0);
\draw (x) -- ++(-1,0);
\node (w) at ($(x) + (0,.5875)$) [white dot] {};
\draw (w) -- ++(1,0);
\draw (w) -- node [midway, not dot, label=above:\footnotesize$\neg$] {} ++(-1,0);
\node (y) at ($(x) + (0,-.5875)$) [white dot] {};
\draw (y) -- ++(1,0);
\draw (y) -- ++(-1,0);
\node (z) at ($(y) + (0,-.5875)$) [white dot] {};
\draw (z) -- ++(1,0);
\draw (z) -- ++(-1,0);
\node [H box, label=right:\small$\!\!\:\alpha$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (w) -- (p);
\draw (x) -- (p);
\draw (y) -- (p);
\draw (z) -- (p);
\end{tikzpicture}
\end{aligned}\;}
\,&=\,
\Sem{15ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(1,0);
\draw (x) -- ++(-.5,0);
\node (w) at ($(x) + (0,.5875)$) [white dot] {};
\draw (w) -- node [midway, not dot, label=above:\footnotesize$\neg$] {} ++(1,0);
\draw (w) -- ++(-.5,0);
\node (y) at ($(x) + (0,-.5875)$) [white dot] {};
\draw (y) -- ++(1,0);
\draw (y) -- ++(-.5,0);
\node (z) at ($(y) + (0,-.5875)$) [white dot] {};
\draw (z) -- ++(1,0);
\draw (z) -- ++(-.5,0);
\node [H box, label=right:\small$\!\!\:\alpha$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (w) -- node [pos=0.3125, not dot, label=left:\footnotesize$\neg\!\!\!\;$] {} (p);
\draw (x) -- (p);
\draw (y) -- (p);
\draw (z) -- (p);
\end{tikzpicture}
\end{aligned}\;}
\;=
\mathop{\int\!\!\!\!\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{w,x,y,z \in [D]}}\!
\alpha^{(\sigma - w)xyz} \; \kket{\neg w,x,y,z}\bbra{w,x,y,z}
\\[-3ex]&=
\mathop{\int\!\!\!\!\int\!\!\!\!\int\!\!\!\!\int}\limits_{\mathclap{w,x,y,z \in [D]}}\!
\alpha^{\sigma xyz} \alpha^{- wxyz} \; \kket{\neg w,x,y,z}\bbra{w,x,y,z}
\;=\,
\Sem{15ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(-.5,0);
\node (w) at ($(x) + (0,.5875)$) [white dot] {};
\draw (w) -- ++(-.5,0);
\node (y) at ($(x) + (0,-.5875)$) [white dot] {};
\draw (y) -- ++(-.5,0);
\node (z) at ($(y) + (0,-.5875)$) [white dot] {};
\draw (z) -- ++(-.5,0);
\node [H box, label=right:\small$\!\!\:\alpha^{-1}$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (w) -- (p);
\draw (x) -- (p);
\draw (y) -- (p);
\draw (z) -- (p);
\coordinate (w') at ($(w) + (1.5,0)$);
\node [white dot] (x') at ($(x) + (1.5,0)$) {};
\node [white dot] (y') at ($(y) + (1.5,0)$) {};
\node [white dot] (z') at ($(z) + (1.5,0)$) {};
\draw (w) -- (w');
\draw (x) -- (x');
\draw (y) -- (y');
\draw (z) -- (z');
\node [H box, label=right:\small$\!\!\:\alpha^{\sigma}$] (p') at ($(x')!0.5!(y') + (.375,0)$) {};
\draw (x') -- (p');
\draw (y') -- (p');
\draw (z') -- (p');
\draw (w') -- node [midway, not dot, label=above:\footnotesize$\neg$] {} ++(1,0);
\draw (x') -- ++(1,0);
\draw (y') -- ++(1,0);
\draw (z') -- ++(1,0);
\end{tikzpicture}
\end{aligned}\;}
\!\;.
\mspace{-36mu}
\end{aligned}%
\end{align}

As a consequence, for a green node with arbitrary phase parameter $\theta \in \R$ (representing an amplitude function $\Theta(x) = \e^{i\theta x}$), it is possible to show that

\begin{equation}
\Sem{9ex}{\;
\begin{aligned}
\begin{tikzpicture}
\node (Z) at (0,0) [Z dot, label=above:\small$\theta$] {};
\node (h1) at (-.5,0.375) [not dot, label=above:\small$\neg$] {};
\node (h2) at (-.5,-0.375) [not dot, label=below:\small$\neg$] {};
\draw (Z) .. controls (-0.3175,0.375) .. (h1) -- ++(-0.375,0);
\draw (Z) .. controls (-0.3175,-0.375) .. (h2) -- ++(-0.375,0);
\node (dots) at ($(Z) + (-0.5,0.125)$) {\footnotesize$\mathbf\vdots$};
\node (h1) at (.5,0.375) [not dot, label=above:\small$\neg$] {};
\node (h2) at (.5,-0.375) [not dot, label=below:\small$\neg$] {};
\draw (Z) .. controls (0.3175,0.375) .. (h1) -- ++(0.375,0);
\draw (Z) .. controls (0.3175,-0.375) .. (h2) -- ++(0.375,0);
\node (dots) at ($(Z) + (0.5,0.125)$) {\footnotesize$\mathbf\vdots$};
\end{tikzpicture}
\end{aligned}\; }
\;=\;
\Sem{10ex}{\;
\begin{aligned}
\begin{tikzpicture}
\node (Z) at (0,0) [Z dot, label=above:\small$-\theta$] {};
\draw (Z) .. controls (-0.3175,0.375) .. ++(-0.75,.375);
\draw (Z) .. controls (-0.3175,-0.375) .. ++(-0.75,-.375);
\node (dots) at ($(Z) + (-0.5,0.125)$) {\footnotesize$\mathbf\vdots$};
\draw (Z) .. controls (0.3175,0.375) ..  ++(0.75,.375);
\draw (Z) .. controls (0.3175,-0.375) .. ++(0.75,-.375);
\node (dots) at ($(Z) + (0.5,0.125)$) {\footnotesize$\mathbf\vdots$};
\node (H) at ($(Z) + (-0.4375,0.75)$) [small H box, label=right:\small$\e^{i\theta\sigma}_{\big.}$] {};
\node at ($(Z) + (-0.4375,-0.75)$) [small H box, fill=none, draw=none, label=right:\phantom{\small$\e^{i\theta\sigma}$}] {};
\end{tikzpicture}
\end{aligned}\;},
\end{equation}

generalising the situation in conventional presentations of the ZX calculus for $D = 2$, in which red $\pi$-phase dots play the role of the $\neg\;\!$-dots.

Remark on the above constructions.

Throughout the above, the operators, vectors, and scalars may be defined simply using integrals and the super-normalised point-mass distributions $\kket{x}$.
These lead to straightforward representations of a variety of unitary operators.
We have also, incidentally, set out a convention for representing stabiliser phases for ZX diagrams and for indexing basis states of $\cH$, which we feel are helpful to present the vectors $\kket{a}$ and $\kket{\smash{\omega^a}}$ themselves, and the Pauli and Clifford operators on $\cH$ for arbitrary $D > 1$.
These conventions allow us to analyse $\Z_D$-multicharacters in the case of ZH diagrams, and are nearly sufficient to analyse the stabiliser fragment over $\Z_D$ in the case of ZX diagrams at least for $D$ prime (apart from an absence of rules to reason about scalars).

Remark on rewrites.
The discussion above only begins to touch on the way in which these semantics for ZX and ZH diagrams, supports simple and useful rewrites.
A greater variety of rewrites which are sound for these semantics are demonstrated in Figures <ref>–<ref> (on pages fig:ZX-rewrites & fig:ZH-rewrites), with proofs given in Appendix <ref>.
While there is clearly work still to be done to demonstrate complete versions of  these calculi (sufficient to prove equality of diagrams through rewrites alone), we hope that this section provides a convincing demonstration that developing useful and complete qudit ZX-, ZH-, and ZXH-calculi is possible, through the use of semantics expressed as discrete integrals in this way.

§ SKETCH OF A QUDIT NORMAL FORM FOR ZH

In this Section, we outline a normal form for ZH diagrams, which together with standard techniques for ZH normal forms [30] suffice for any $D > 1$ to denote an arbitrary operator on $\cH$.

We may use the more general amplitude functions $\mathrm{A}: \Z \to \C$ to define more fine-grained operators than with amplitude parameters alone.
For instance, let $\Char_{S}$ be the characteristic function of a set $S \subseteq \Z$ (so that $\Char_{S}(t) = 0$ if $t \notin S$, and $\Char_{S}(t) = 1$ otherwise), and let $\mathbf V_{S}(t) = (-1)^{\Char_{S}(t)}$.
Then for $D > 2$, the operation

\begin{align}{}
\mspace{-39mu}
\Sem{8ex}{\;%
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(1.5,0);
\draw (x) -- ++(-.375,0);
\node (y) at ($(x) + (0,-1)$) [white dot] {};
\draw (y) -- ++(1.5,0);
\draw (y) -- ++(-.375,0);
\node [H box, label=right:\small$\!\!\:\mathbf V_{\{1\}}$] (p) at ($(x)!0.5!(y) + (.375,0)$) {};
\draw (x) -- (p);
\draw (y) -- (p);
\end{tikzpicture}
\end{aligned}\;}
\,&=\,
\mathop{\int\!\!\!\!\int}\limits_{\mathclap{x,y \in [D]}}
\mathbf V_{\{1\}}(xy) \; \kket{x,y}\bbra{x,y}
\;=\;
\mathbf 1 \;-\; 2 \Bigl( \ket{\texttt{-1},\texttt{-1}}\bra{\texttt{-1},\texttt{-1}} \;+\;\ket{\texttt{+1},\texttt{+1}}\bra{\texttt{+1},\texttt{+1}} \Bigr)
\mspace{-36mu}
\end{align}

induces a sign of $-1$ on the $\ket{\texttt{-1},\texttt{-1}}$ and $\ket{\texttt{+1},\texttt{+1}}$ components of the two qudits it acts on (as these are precisely the basis states $\ket{x,y}$ for which $xy = +1 \in \Z$).
This is one drawback to the choice to index the standard basis by elements of $\{L_D,L_D{+}1,\ldots,U_D{-}1,U_D\}$ where $L_D$ may be  negative.
A more conventional choice of $[D] = \{0,1,\ldots,D{-}1\}$ would see a similar operation induce a sign only on the $\ket{\texttt{+1},\texttt{+1}}$ component, which would make possible a significant simplification of the normal form described just below.

We may use similar gadgets as the basis of a normal form for qudit ZH diagrams.
For an arbitrary number $m \ge 0$ of input wires, we may consider a gadget of the form
Similar constructions are in many cases possible using a gadget of the form illustrated on the

right — where $\boldsymbol \epsilon_\alpha(t) = \alpha$ for $t = 1$ and $\boldsymbol \epsilon_\alpha(t) = 1$ otherwise — relying on the fact that $1 - x^2 = \pm 1$ has no solutions over the integers except for $x = 0$, in which case $1 - x^2 = +1$.
However, to be more precise, we must consider the conditions under which $\rho_D(-\rho_D(-1{-}x)) \!\:\cdot\!\: \rho_D(1{-}x) = \pm 1$ admits solutions for $x \in [D]$; and specifically when $D = 4$ and $x = 2$, we have $\rho_4(-\rho_4(-1{-}x)) \!\:\cdot\!\: \rho_4(1-x) = (-1) \!\cdot\! (-1) = +1$.
Constructions which single out $\kket{x} = \kket{t}\sox{n}$ for a fixed $t \in \Z$ will likely fail for some single value of $D$, for similar reasons.

\begin{aligned}[t]~\\[-6ex]
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(-1,0);
\node (y) at ($(x) + (0,-1.75)$) [white dot] {};
\draw (y) -- ++(-1,0);
\node (dots) at ($(x)!0.5!(y) + (-.75,0.09875)$) {$\vdots$};
\node (dots) at ($(x)!0.5!(y) + (-.75,0.09875)$) {$\vdots$};
\node [Z dot] (p) at ($(x)!0.5!(y) + (.875,0)$) {};
\draw (x) .. controls ++(.375,-.125) and ++(-.125,.375) .. node [midway, not dot, label=above:\footnotesize$\;-1$] {} (p);
\draw (x) .. controls ++(.125,-.375) and ++(-.375,.125) .. node [pos=0.3125, not dot, label=left:\footnotesize$+1\!\!\;$] {}
node [pos=0.625, gray dot] {} (p);
\draw (y) .. controls ++(.375,.125) and ++(-.125,-.375) .. node [midway, not dot, label=below:\footnotesize$\;-1$] {} (p);
\draw (y) .. controls ++(.125,.375) and ++(-.375,-.125) .. node [pos=0.3125, not dot, label=left:\footnotesize$+1\!\!\;$] {} node [pos=0.625, gray dot] {} (p);
\node [H box, label=right:$\!\!\:\boldsymbol \epsilon_\alpha$] at (p) {};
\end{tikzpicture}
\end{aligned}

\begin{align}{}
\label{eqn:ZH-phase-only-on-Us-gadget}
\mspace{-39mu}
%		\Sem{11ex}
\begin{aligned}{}
\begin{tikzpicture}[]
\node (x) at (0,0) [white dot] {};
\draw (x) -- ++(-.75,0);
\node (y) at ($(x) + (0,-1.5)$) [white dot] {};
\draw (y) -- ++(-.75,0);
\node (brace) at ($(x)!0.5!(y) + (-1.25,0)$) {%
$m \left\{ \begin{matrix} \\[10ex] \end{matrix} \right.$
\node (dots) at ($(x)!0.5!(y) + (-0.375,0.09875)$) {$\vdots$};
\node [Z dot] (p) at ($(x)!0.5!(y) + (.75,0)$) {};
\draw (x) .. controls ++(.375,-.125) and ++(-.125,.375) .. node [midway, not dot, label=above:\footnotesize$\;\;\;1{-}\sigma$] {} (p);
\draw (x) .. controls ++(.125,-.375) and ++(-.375,.125) .. (p);
\draw (y) .. controls ++(.375,.125) and ++(-.125,-.375) .. node [midway, not dot, label=below:\footnotesize$\;\;\;1{-}\sigma$] {} (p);
\draw (y) .. controls ++(.125,.375) and ++(-.375,-.125) .. (p);
\node [H box, label=right:$\mathbf M^{(2m)}_\alpha$] (p) at ($(x)!0.5!(y) + (.75,0)$) {};
\end{tikzpicture}
\end{aligned}}
\;,
\qquad\qquad
\text{where $
\mathbf M^{(k)}_\alpha(t)
\;=\;
\begin{cases}
\alpha,	&	\text{if $t = U_{\!D}^{\,k}$};
\\
1,		&	\text{otherwise}.
\end{cases}
\mspace{-36mu}
\end{align}

We may describe the behaviour of this gadget as it acts on standard basis states.
Each input wire of this gadget admits a state $\kket{x_j}$, and copies it to produce a pair $\kket{x_j, x_j}$.
One copy is then acted on with a $(1{-}\sigma)$-not-dot, yielding a state ${\kket{x_j,\, \rho_D(\sigma{-}1{-}x_j)}} = {\kket{x_j,\, \rho_D(\neg x \:\!{-}\:\!1)}}$, where $\rho_D : \Z \to [D]$ is a map which reduces each integer modulo $D$ to a representative in $[D]$.
(The map $\rho_D$ is implicit in many of the transformations in which one might prefer to evaluate arithmetic modulo $D$: it arises here because we must map the associate the expression $\sigma{-}1{-}x_j$ , which we might prefer to implicitly evaluate modulo $D$ in the basis labels, to an explicit element of $\Z$.)
The $\mathbf M^{(2m)}_\alpha$ box then maps $\kket{x} \mapsto \alpha$ if and only if

\begin{equation}
\label{eqn:normal-form-gadget-constraint}
%	\tilde M_m(x)
\prod_{j=1}^n	\Bigl( x_j \cdot \rho_D(\neg x - 1)  \Bigr)
\;=\;
\end{equation}

and maps $\kket{x} \mapsto +1$ otherwise.

For $x \in \Z^m$, Eqn. (<ref>) is satisfied only if ${x_j \cdot \rho_D(\neg x - 1)} {{}= \pm U_{\!\!\:D}^{\,2}}$ for each $x_j$ individually, as $U_D \in [D]$ is the element with the largest absolute value.

* Note that $\rho_D(\neg x - 1) \,\ne\, \neg x - 1$ if and only if $\neg x = L_D$, which is to say precisely when $x = U_D$: in this case, we have $x \cdot \rho_D(\neg x - 1) = U_{\!\!\:D}^{\,2}$.

* Otherwise, for $x < U_D$, we have $x \cdot \rho_D(\neg x - 1) = x \cdot (\neg x - 1) = \sigma x - x - x^2$.
For $D$ even, we have $\sigma x - x - x^2 = -x^2$; for $D$ odd, we instead have  $\sigma x - x - x^2 = -x^2 = -x(x+1)$.
The absolute values of these expressions are bounded strictly below $U_{\!\!\;D}^{\,2}$ in either case.

Then Eqn. (<ref>) is satisfied if and only if $x_j = U_D$ for each $1 \le j \le m$.
The action of the gadget in Eqn. (<ref>) is then to map $\kket{U_{\!\!\:D}}\sox{m} \mapsto \alpha$ and $\kket{x} \mapsto +1$ for all other $x \in [D]^m$.

Using gadgets of this form, we may express any operator $\Omega: \cH\sox{m} \to \cH\sox{n}$ in terms of its coefficients, in a similar manner to the normal form for ZH diagrams in $D=2$ presented by Backens and Kissinger [30].
That is, we may take any operator, transform it into a vector using cup operators, use white dots to make copies of each qudit in the standard basis (one copy for every coefficient of the operator), and then apply not-dots and gadgets of the form in Eqn. (<ref>) to fix the value of each coefficient $\alpha_{x,y} = \bbra{x} \,\Omega\, \kket{y} = \nu^{-m-n} \, \Omega_{\!\;x,y}$ for $x \in [D]^m$ and $y \in [D]^n$.

Remark on the above construction.

We do not expect that the rewrite rules that we have set out, for ZX or ZH diagrams, suffice to transform arbitrary diagrams to such a normal form.
We leave open the problem of demonstrating rewrites to transform arbitrary qudit ZH diagrams into a form such as the one we have sketched here, or a similar one.
We do think that it is likely that simple rewrite rules can be found, which might allow the gadget of Eqn. (<ref>) to be expressed using only phase-amplitude gadgets.
However, setting out such rules is beyond the scope of our current work, which is simply to present an advantageous semantic map for ZX and ZH diagrams through discrete integrals.

§ THE CASE $D = 2$, AND `OCKHAMIC' SEMANTIC MAPS

Notice that the normalisation $\nu = D^{-1/4}$, and the corresponding semantics, essentially reproduces the `well-tempered' semantics of ZX and ZH diagrams [19] in the case that $D = 2$.

The process by which we obtain this semantic map in this article, may appear very different from how the well-tempered interpretation was devised in Ref. [19].
In the latter case, a family of `Ockhamic' semantic maps were considered which differed from each other in the values of normalising scalar factors for each of the generators, subject to some constraints.
(We discuss and generalise the notion of `Ockhamic semantic maps' of ZX diagrams and of ZH diagrams in Appendix <ref>.)
A specific semantic map was then isolated by imposing successive constraints in the form of equations on the semantics of specific diagrams.
This effectively solved for a semantic map, for which certain rewrite rules were sound.
However, it must be admitted that the analysis of Ref. [19] does not provide any particular intuition for why $\nu = D^{-1/4}$ should be a natural parameter to govern the relationships between the ZX and ZH generators.

In this article, we instead set out a semantic map, making use of discrete integrals and an accompanying system of point-mass distributions, with the intent that he ZX and ZH generators should be as simple as possible within that framework.
The precise semantics were determined by the single parameter $\nu$, which we then fixed by constraining the representation of the (quantum) Fourier transform.
However: it is worth noting that the framework of discrete integrals and (what we have here called) `accompanying' point-mass distributions, implicitly impose some of the constraints that were explicitly imposed in Ref. [19].
Specifically: by choosing our notation so that

\begin{equation}
\int\limits_{\mathclap{x \in [D]}} \kket{x}\sox{n}\bbracket{x}{a}
\;\;=\;\;
\kket{a}\sox{n}
\end{equation}

it is not difficult to show that we automatically ensure the correctness of a number of rewrites including , , ,  , , , and  for the semantics of Eqn. (<ref>).
In this way, we may regard the framework of discrete integrals and accompanying point-mass distributions as simplifying both the results and the methodology of Ref. [19].
This provides a clarification and a theoretical justification of the `well-tempered' semantics, and indeed an extension of them to all $D > 1$.

Note that choosing the interpretations of Eqn. (<ref>) just for the ZH generators, does not in fact impose any constraints on either the measure $\mu$ on $[D]$.
In the analysis of Section <ref>, we show that (taken on their own), the semantics of Eqn. (<ref>) for the ZH generators only imposes the constraint on the interpretation that the generators must be related to each other by simple geometric progressions related to the parameter $\nu$, but does not fix what $\nu$ should be.
(If we take ${\nu \!=\! 1}$, Eqn. (<ref>) reproduces the original semantics provided by Backens and Kissinger [30] for the ZH generators for ${D\!=\!2}$.)
In effect, the ZH calculus prioritises the standard basis to such an extent that it does not impose any strong relationships between that basis and any other, and in so doing leaves $\nu$ unconstrained.
It is the single constraint on the ZX generators, that $\kket{\smash{\omega^k}} = \int_x \omega^{-kx} \,\kket{x}$ should be unitarily equivalent to $\kket{x}$, which suffices to fix the measure $\mu$ and thus to fix specific semantics for all of the generators through Eqn. (<ref>).

§ SUMMARY AND DISCUSSION

We have presented an version of the ZX-and ZH-calculi over qudits of dimension $D>1$, with an interpretation of the generators given through simple discrete integrals over a set $[D]$ of representatives of $\Z_D$, using an accompanying set of point-mass distributions $\kket{x}$ as the basis for the definition of operators.
This integral is determined by a measure $\mu$ on $[D]$, which we constrain through a choice of representation for the Fourier transform.
This latter constraint fixes a measure such that $\mu(\{\ast\}) = D^{-1/2}$ and $\mu([D]) = \sqrt D$.
With respect to this measure, we have demonstrated simple rewrite rules which are sound for this interpretation.
Continued work on these calculi (either as separate calculi or a unified calculus) is necessary to demonstrate completeness, ideally while retaining the features which promise to make these interpretations of the calculi easy to use.

In addition to the use of discrete integrals, we have made one other significant and unusual choice of representation: to index the standard basis by $[D] = (-\tfrac{1}{2}D,\tfrac{1}{2}D]$ rather than $\{0,1,\ldots,D{-}1\}$.
Many of the results in our work (in particular: all those to do with the stabiliser fragment of ZX, and multicharacter boxes in ZH) will hold equally well with either set of labels for the standard basis.
In particular, both are equally adequate for representing what results might rest on interpreting arithmetic on the labels as taking place in the ring $\Z_D$, for those expressions which are well-defined modulo $D$.
Our choice of labels is motivated by certain elegant features of the special case $D=2$, concerning an involution $\neg : [D] \to [D]$ given by $\neg x = \sigma - x$.
Our notational choice is then motivated by imposing the constraint that $[D] = \{0,1\}$ for $D = 2$, and then requiring $\sigma$ to be as small and simply expressed as possible for all $D > 1$ subject to that constraint.
For $[D] = (-\tfrac{1}{2}D,\tfrac{1}{2}D]$, this yields the involutions $\neg x = 1-x$ for $D$ even and $\neg x = -x$ for $D$ odd.
We look forward to feedback on this choice of convention, and are interested in whether there would be any comparable notational conveniences to selecting the labels $\{0,1,\ldots,D{-}1\}$ instead.
The simplification of the normal form that would be made possible is worth noting, but we would suggest that this benefit should be assigned an importance based on how often a practitioner might expect to compute  a normal form.

We note that both in our choice of involution $\neg: [D] \to [D]$ and in the stabiliser fragment of ZX, there is a significant distinction between the cases of $D$ even and $D$ odd.
In particular: in the stabiliser fragment of ZX, we are concerned with phases which are powers of $\tau = \e^{\pi i(D^2 + 1)/D}$, but for $D$ even this is a $2D\textsuperscript{th}$ root of unity, while for $D$ odd it is a $D\textsuperscript{th}$ root of unity.
It is remarkable that, despite this distinction, the semantics which one obtains for nodes such as
\tikz \node [Z dot, label=left:\footnotesize{$[a \s b]\!$}] {};
\,$
should be consistent for all dimensions $D>1$, in that (a) it denotes  a complex phase whenever $b$ is a multiplicative unit modulo $D$, (b) it denotes the scalar $\sqrt{D} = \mu([D])$ for $a=b=0$, and (c) more generally, the magnitude of the scalar that it denotes is either $0$ or $\sqrt{t\,}$ for $t = \gcd(b,D)$.
It should be noted that there will be other respects in which the case of $D$ even will be significantly more complicated than $D$ odd: see Ref. [50] for more details.
However, as our work manages to present a simple and unifying presentation for the stabiliser fragment of ZX over all dimensions $D>1$, perhaps these can be managed so long as one remains mindful of the other major distinction, of whether $D$ is prime or composite.

We conclude with a highly speculative thought regarding discrete measures.
A significant constraint which we imposed on the measure $\mu$ on $[D]$
— interpreted as a measure on $\Z_D$ — was that the Fourier transform should be interpretable as an involution $\C^{(\Z_D,\mu)} \to \C^{(\Z_D,\mu)}$ on functions on the measure space $(\Z_D,\mu)$, rather than a bijection $\C^{(\Z_D,\mu)} \to \C^{(\Z_D,\mu')}$ between functions on distinct measure spaces $(\Z_D,\mu)$ and $(\Z_D,\mu')$.
This may seem like a necessary but technical step; from the perspective of conventional presentations of ZX diagrams, it is necessary, if all of the wires are to have the same type.
However, it is noteworthy that many quantum algorithms have a structure similar to Fourier sampling, in which some classical operation (with a distinguished control register) is made to act on some state which is in not in the standard basis, but rather in a superposition (often through the involvement of the Fourier transform), after which the amplitudes of the different components are made to interfere (often through the involvement of the inverse Fourier transform).
In this respect, many quantum algorithms have a structure which suggest the possibility of changes in the datatype associated with a physical qubit at different stages of the algorithm.
Could it be that it would be more appropriate on the logical level, to have multiple types of qubit — a `standard' type and a `Fourier' type, possibly among others  — than to have just a single type of logical qubit?
It would be interesting to consider what insights into the structure of quantum algorithms might arise, by considering multiple types of qubit or quantum register apart from distinctions of dimension and resister size, and contrasting the roles in which they play in existing quantum algorithms.
Should such a program prove to be non-trivial, it is conceivable that this could give rise to new insights into structured quantum programming.

§ ACKNOWLEDGEMENTS

NdB would like to thank Patrick Roy, Titouan Carette, John van de Wetering, and Robert Booth for helpful technical discussions.

[1]
B. Coecke and R. Duncan.
Interacting quantum observables: categorical algebra and diagrammatics.
New. J. Phys 13 (043016), 2011.
DOI: ;
See also [arXiv:0906.4725].

[2]
R. Duncan and S. Perdrix.
Graph States and the Necessity of Euler Decomposition.
Mathematical Theory and Computational Practice (pp. 167–177), 2009.
DOI: ;
See also [arXiv:0902.0500].

[3]
M. Backens.
Making the stabilizer ZX-calculus complete for scalars.
Electronic Proceedings in Theoretical Computer Science 195 (pp. 17–32), 2015.

[4]
S. Perdrix and Q. Wang.
Supplementarity is Necessary for Quantum Diagram Reasoning.
Proceedings of 41st International Symposium on Mathematical Foundations of Computer Science (76:1–76:14), 2016.
DOI: ;
see also [arXiv:1506.03055].

[5]
M. Backens, S. Perdrix, and Q. Wang.
A Simplified Stabilizer ZX-calculus.
Electronic Proceedings in Theoretical Computer Science 236 (pp. 1–20), 2017.
DOI: ;
See also [arXiv:1602.04744],

[6]
E. Jeandel, S. Perdrix, R. Vilmart, and Q. Wang.
ZX-Calculus: Cyclotomic Supplementarity and Incompleteness for Clifford+T Quantum Mechanics.
Proceedings of 42nd International Symposium on Mathematical Foundations of Computer Science (11:1–11:13), 2017.
DOI: ;
See also [arXiv:1702.01945].

[7]
B. Coecke and A. Kissinger.
Picturing Quantum Processes: A First Course in Quantum Theory and Diagrammatic Reasoning.
Cambridge University Press, 2017.
DOI: .

[8]
X. Gong and Q. Wang.
Equivalence of Local Complementation and Euler Decomposition in the Qutrit ZX-calculus.
[arXiv:1704.05955], 2017.

[9]
K. F. Ng and Q. Wang.
A universal completion of the ZX-calculus.

[arXiv:1706.09877], 2017.

[10]
E. Jeandel, S. Perdrix, and R. Vilmart.
A Complete Axiomatisation of the ZX-Calculus for Clifford+T Quantum Mechanics.
33rd Annual ACM/IEEE Symposium on Logic in Computer Science (pp. 559–568), 2018.
DOI: ;
See also [arXiv:1705.11151], 2017.

[11]
K. F. Ng and Q. Wang.
Completeness of the ZX-calculus for Pure Qubit Clifford+T Quantum Mechanics.

[arXiv:1801.07993], 2018.

[12]
Q. Wang.
Qutrit ZX-calculus is Complete for Stabilizer Quantum Mechanics.
Electronic Proceedings in Theoretical Computer Science 266 (pp. 58–70), 2018.
DOI: ;
See also [arXiv:1803.00696].

[13]
B. Coecke and Q. Wang.
ZX-rules for 2-qubit Clifford+T quantum circuits.
Lecture Notes in Computer Science 11106 (pp. 144–161), 2018.
DOI: ;
See also [arXiv:1804.05356].

[14]
R. Vilmart.
A Near-Minimal Axiomatisation of ZX-Calculus for Pure Qubit Quantum Mechanics.
34th Annual ACM/IEEE Symposium on Logic in Computer Science (pp. 1–10), 2019.
DOI: ;
See also [arXiv:1812.09114],

[15]
R. Vilmart.
A ZX-Calculus with Triangles for Toffoli-Hadamard, Clifford+T, and Beyond.
Electronic Proceedings in Theoretical Computer Science 287 (pp. 313–344), 2019.
DOI: ;
See also [arXiv:1804.03084],

[16]
E. Jeandel, S. Perdrix, and R. Vilmart.
Completeness of the ZX-Calculus.

[arXiv:1903.06035], 2019.

[17]
Q. Wang.
An algebraic axiomatisation of ZX-calculus.

[arXiv:1911.06752], 2019.

[18]
Q. Wang.
ZX-calculus over arbitrary commutative rings and semirings (extended abstract).

[arXiv:1912.01003], 2019.

[19]
N. de Beaudrap.
Well-tempered ZX and ZH calculi.
Electronic Proceedings in Theoretical Computer Science 340 (pp. 13–45), 2021.
DOI: ;
See also [arXiv:2006.02557].

[20]
Q. Wang.
Algebraic complete axiomatisation of ZX-calculus with a normal form via elementary matrix operations.
[arXiv:2007.13739], 2020.

[21]
J. van de Wetering.
ZX-calculus for the working quantum computer scientist.
[2012.13966], 2020.

[22]
A. Toumi, R. Yeung, and G. de Felice.
Diagrammatic Differentiation for Quantum Machine Learning.
Electronic Proceedings in Theoretical Computer Science 343 (pp. 132–144), 2021.
DOI: ;
See also [arXiv:2103.07960].

[23]
Q. Wang.
Qufinite ZX-calculus: a unified framework of qudit ZX-calculi.
[arXiv:2104.06429], 2021.

[24]
Q. Wang, R. Yeung, and M. Koch.
Differentiating and Integrating ZX Diagrams.
[arXiv:2201.13250], 2022.

[25]
E. Jeandel, S. Perdrix, and M. Veshchezerova.
Addition and Differentiation of ZX-diagrams.
[arXiv:2202.11386], 2022.

[26]
T. Stollenwerk and S. Hadfield.
Diagrammatic Analysis for Parameterized Quantum Circuits.
[arXiv:2204.01307], 2022.

[27]
R. I. Booth and T. Carette.
Complete ZX-Calculi for the Stabiliser Fragment in Odd Prime Dimensions.
47th International Symposium on Mathematical Foundations of Computer Science (pp. 24:1–24:15), 2022.
DOI: ;
See also [arXiv:2204.12531].

[28]
J. van de Wetering and L. Yeh.
Phase gadget compilation for diagonal qutrit gates.
[arXiv:2204.13681], 2022.

[29]
S. Majid.
Quantum and braided ZX calculus.
J. Phys. A: Math. Theor. 55 (254007), 2022.
DOI: ;
See also [arXiv:2103.07264].

[30]
M. Backens and A. Kissinger.
ZH: A Complete Graphical Calculus for Quantum Computations Involving Classical Non-linearity.
Electronic Proceedings in Theoretical Computer Science 287 (pp. 23–42), 2019.
DOI: ;
See also [arXiv:1805.02175].

[31]
J. van de Wetering and S. Wolffs.
Completeness of the Phase-free ZH-calculus.
[], 2019.

[32]
S. Kuijpers, J. van de Wetering, and A. Kissinger.
Graphical Fourier Theory and the Cost of Quantum Addition.
[], 2019.

[33]
N. de Beaudrap, A. Kissinger, and K. Meichanetzidis.
Tensor Network Rewriting Strategies for Satisfiability and Counting.
Electronic Proceedings in Theoretical Computer Science 340 (pp. 46–59), 2021.
DOI: ;
See also [arXiv:2004.06455].

[34]
M. Backens, A. Kissinger, H. Miller-Bakewell, J. van de Wetering, and S. Wolffs.
Completeness of the ZH-calculus.
[arXiv:2103.06610], 2021.

[35]
P. Roy.
Qudit ZH-calculus.
MSc. Thesis, University of Oxford.

Available at

(accessed 27 February 2023).

[36]
R. D. P. East, J. van de Wetering, N. Chancellor, and A. G. Grushin.
AKLT-states as ZX-diagrams: diagrammatic reasoning for quantum states.
PRX Quantum 3 (010302), 2022.
DOI: ;
See also [arXiv:2012.01219].

[37]
A. Townsend-Teague and K. Meichanetzidis.
Classifying Complexity with the ZX-Calculus: Jones Polynomials and Potts Partition Functions.
Accepted submission to QPL 2022.
[arXiv:2103.06914], 2021.

[38]
R. D. P. East, P. Martin-Dussaud, and J. van de Wetering.
Spin-networks in the ZX-calculus.
[arXiv:2111.03114], 2021.

[39]
G. de Felice and B. Coecke.
Quantum Linear Optics via String Diagrams.
Accepted submission to QPL 2022.

[40]
T. Laakkonen, K. Meichanetzidis, and J. van de Wetering.
A Graphical #SAT Algorithm for Formulae with Small Clause Density.
[arXiv:2212.08048], 2022.

[41]
B. Poór, Q. Wang, R. A. Shaikh, L. Yeh, R. Yeung, and B. Coecke.
Completeness for arbitrary finite dimensions of ZXW-calculus, a unifying calculus,
[arXiv:2302.12135], 2023.

[42]
P. Roy, J. van de Wetering, L. Yeh.
Title to be determined.
Submission to QPL 2023, to appear.

[43]
B. Poór, R. I. Booth, T. Carette, J. van de Wetering, L. Yeh.
The Qupit Stabiliser ZX-travaganza: Simplified Axioms, Normal Forms and Graph-Theoretic Simplification.
Submission to QPL 2023, to appear.

[44]
Y. Shi.
Both Toffoli and Controlled-NOT Need Little Help to Do Universal Quantum Computing.
Quantum Information & Compututation 3 (pp. 84–92), 2003.

[45]
D. Aharonov.
A Simple Proof that Toffoli and Hadamard are Quantum Universal.
[], 2003.

[46]
T. Carette.
Wielding the ZX-calculus, Flexsymmetry, Mixed States, and Scalable Notations.
Ph.D. Thesis, Loria, Université de Lorraine, 2021.

[47]
D. Schlingemann.
Cluster States, Algorithms and Graphs.
Quantum Info. & Comput. 4 (pp. 287–324), 2004.
DOI: ;
See also [arXiv:quant-ph/0305170].

[48]
A. Córdoba.
Dirac combs.
Lett. Math. Phys. 17 (pp. 191–196), 1989.

[49]
T. Carette and E. Jeandel.
A recipe for quantum graphical languages.
47th International Colloquium on Automata, Languages, and Programming (pp.  118:1–118:17), 2020.
DOI: ;
See also [arXiv:2008.04193].

[50]
N. de Beaudrap.
A linearized stabilizer formalism for systems of finite dimension.
Quant. Info. & Comp. 13 (pp. 73–115), 2013.
DOI: ;
See also [].

[51]
T. Carette, D. Horsman, and S. Perdrix.
SZX-Calculus: Scalable Graphical Quantum Reasoning.
Proceedings of 44th International Symposium on Mathematical Foundations of Computer Science (55:1–55:15), 2019.
DOI: ;
See also [].

[52]
T. Carette, Y. D'Anello, and S. Perdrix.
Quantum Algorithms and Oracles with the Scalable ZX-calculus.
Electronic Proceedings in Theoretical Computer Science 343 (pp. 193–209), 2021.
DOI: ;
See also [].

§ DISCRETE MEASURES ON $\R$

§.§ Dirac deltas

When analysing functions on $\R$, it is not uncommon to consider a Dirac distribution $\delta$ (also known as the `Dirac delta'), which is defined in such a way that for an interval $J \subset \R$,

\begin{equation}
\label{eqn:dirac-delta}
\int\limits_{\mathclap{x \in J}} f(x) \, \delta(x-a) \; \mathrm dx
\;=\;
\begin{cases}
f(a),	& \text{if $a \in J$};
\\[.5ex]
0,		&	\text{otherwise}.
\end{cases}
\end{equation}

One may conceive of $\delta(x)$ as the limit of a family of formally definable functions, such as the Gaussians $\mathcal N_{1\!\!\;/n}(x) = \smash{\tfrac{n}{\sqrt 2\pi}\,\e^{-(n x)^2/2}}$ as $n \to \infty$.
In principle, one may consider it as syntactic sugar for a measure $\mu_\delta$ on $\R$, which for any interval $J \subset \R$ satisfies $\mu(J) = 1$ if $0 \in J$, and $\mu(J) = 0$ otherwise: we call this a `point-mass distribution'.
We may write $\delta_a(x) = \delta(x - a)$ for any $a \in \R$, so that $\delta_a$ describes a point-mass distribution at $a \in \R$: that is, a measure $\mu_a$ such that $\mu_a(S) = 1$ if $a \in S$, and $\mu_a(S) = 0$ otherwise.
(More generally, a point-mass distribution is any distribution of the form $p_a \delta_a$ for $p_a \ne 0$: the `mass' of such a distribution is then $p_a$.)
The purpose of the Dirac distributions would then be to allow us to write $\,\int_J f(x) \,\delta_a(x) \,\mathrm dx = \int_J f(x) \,\delta(x-a) \,\mathrm dx\,$ in place of $\,\int_J f(x\!+\!a) \, \mathrm d\mu_a\,$.
This provides a notational bridge between the discrete measures $\mu_a$ and the more common (Lebesgue) measure, so that we may perform analysis as though consistently working with a single variety of integration.

§.§ Impulses and Dirac combs

A discrete measure $\rho$ on $\R$ is a measure which is a linear combination of a countable (and possibly finite) number of such point-mass distributions.
While such measures are not real-valued functions on $\R$, we may say that $\rho(a) \ne 0$ if for any function $f: \R \to \C$, we have $\int_{(a\!\!\:-\!\!\:\epsilon,a\!\!\:+\!\!\:\epsilon)} f(x)\,\rho(x)\,\mathrm dx \,\longrightarrow\, p_a f(a)$ for some $p_a \ne 0$, as $\epsilon \to 0$.
We may refer to the contributions of the point-mass distributions as `impulses': for a discrete measure $\rho$, we say that $\rho$ has an impluse at $a$ if $\rho(a) \ne 0$ in this sense.

We define the Dirac comb $\Sh$ (see, e.g., Ref. [48]) as a discrete distribution, consisting of a sequence of a sum of unit point-mass distributions on $\Z$:

\begin{equation}
\label{eqn:integer-comb}
\Sh(x)
\,=\,
\sum_{t \in \Z}	\,\delta_t(x)
\;.
\end{equation}

The Dirac comb is its own Fourier transform, which allows us to also express it as:

\begin{equation}
\label{eqn:FT-integer-comb}
\Sh(x)
\,=\,
\sum_{k \in \Z} \e^{2\pi ikx}
\,=\,
\sum_{k \in \Z} \e^{-2\pi ikx} .
\end{equation}

We may use the Dirac comb to express any function $\phi: \Z \to \C$ as a complex linear combination of impulses at the integers: if we let $\phi': \R \to \C$ be any extension of $\phi$ to the real numbers, we may define the complex-valued discrete `distribution' $\mathbf I \:\! \phi$ on $\R$, by

\begin{equation}
\label{eqn:discrete-complex-distribution-via-impulses}
\mathbf I \:\! \phi(x)
\;=\;
\Sh(x) \,\phi'(x)
\;=\;
\sum_{t \in \Z}	\,\delta_t(x) \,\phi(t),
\end{equation}

This will allow us to express sums on integers, in terms of integrals over $\R$: for instance, for any integers $a < b$, we then have

\begin{equation}
\int\limits_{\mathclap{(a,b]}} \mathbf I \!\: \phi(x) \; \mathrm dx
\;=\;
\sum_{\mathclap{a < t\le b}}
\phi(t);
\end{equation}

in particular, we have $\int_{(a,b]} \Sh(x)\,\mathrm dx = b-a$, which is the number of integers in the interval $(a,b]$.
Finally, we may consider normalised versions of the Dirac comb with impulses at integer multiples of any interval length $\ell > 0$:

\begin{equation}
\label{eqn:normalised-comb}
\Sh_\ell(x)
\,=\,
\ell \,\sum_{t \in \Z}	\,\delta_{\ell t}(x)
\,=\,
\ell \,\sum_{t \in \Z}	\,\delta(x - \ell t)
\,=\,
\ell \,\sum_{k \in \Z} \e^{2\pi ikx/\ell}
\end{equation}

The leading scalar factor of $\ell$ in these sums, ensures that for $a < b$ which are integer multiples of $\ell$, we again have $\int_{(a,b]} \Sh(x)\,\mathrm dx = b-a$.
We may then use this to define a generalisation of $\mathbf I$, to embed functions $\phi: \Z \to \C$ as complex-valued measures in $\R$, but with impulses at intervals of $\ell > 0$: for $\phi'$ again any extension of $\phi$ to $\R$, we define

\begin{equation}
\label{eqn:scaled-discrete-complex-distribution-via-impulses}
\mathbf I_\ell \;\! \phi(x)
\;=\;