Fast algorithms for classical specifications of stabiliser states and Clifford gates

Extracted source text · arXiv 2311.10357

\documentclass{article}[fullpage]

\usepackage{amsfonts,amsmath,amsthm,amssymb,braket,enumerate,enumitem,xcolor,float}
\usepackage[margin=2cm]{geometry}
\usepackage[backref,hidelinks]{hyperref}
\usepackage{comment}
\usepackage{todonotes}
\usepackage{authblk}
\usetikzlibrary{quantikz2}
\usepackage{algorithm}
\usepackage{algorithmic}

\usepackage{tikz,ifdraft,wrapfig}
\usetikzlibrary{arrows,positioning,matrix,backgrounds,calc,fit}
\tikzcdset{
every matrix/.style={ampersand replacement=\&}
}

\newcommand{\wilf}[1]{{\color{blue}Wilf: #1}}
\newcommand{\todoc}[1]{{\color{red} #1}}

\usepackage{thmtools}
\usepackage{thm-restate}


\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

\newcommand{\A}{\mathbb{A}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\I}{\mathbb{I}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\T}{\mathbb{T}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\cA}{\mathcal{A}}
\newcommand{\cC}{\mathcal{C}}
\newcommand{\cD}{\mathcal{D}}
\newcommand{\cK}{\mathcal{K}}
\newcommand{\cL}{\mathcal{L}}
\newcommand{\cP}{\mathcal{P}}
\newcommand{\cS}{\mathcal{S}}
\newcommand{\cU}{\mathcal{U}}
%\newcommand{\K}{\bar{k}}
\newcommand{\K}{K}
\newcommand{\zd}{(\Z_d)}


\newcommand{\kz}{\ket{\vec{z\,}}}

\newcommand{\Spec}{\text{Spec}}

\newtheorem{theorem}{Theorem}
\newtheorem{defn}{Definition}
\newtheorem{cor}{Corollary}
\newtheorem{claim}{Claim}
\newtheorem{lemma}{Lemma}
\newtheorem{conj}{Conjecture}
\theoremstyle{remark}
\newtheorem{remark}{Remark}
\newtheorem{example}[equation]{Example}
\newcommand{\supp}{\ensuremath{\text{supp}}}


\author[1]{Nadish de Silva}
\author[2]{Wilfred Salmon}
\author[1]{Ming Yin}

\affil[1]{Department of Mathematics, Simon Fraser University}
\affil[2]{Department of Applied Mathematics and Theoretical Physics, University of Cambridge}

\title{\vspace{-1cm}Fast algorithms for classical specifications \\of stabiliser states and Clifford gates}



\begin{document}

\date{} 
\maketitle

\begin{abstract}
The stabiliser formalism plays a central role in quantum computing, error correction, and fault-tolerance.  Stabiliser states are used to encode quantum data.  Clifford gates are those which can be easily performed fault-tolerantly in the most common error correction schemes.  Their mathematical properties are the subject of significant research interest.

Numerical experiments are critical to formulating and testing conjectures involving the stabiliser formalism.  Conversions between different specifications of stabiliser states and Clifford gates are also important components of classical algorithms for simulating quantum circuits.  

In this note, we provide fast methods for verifying that a vector is a stabiliser state, and interconverting between its specification as amplitudes, a quadratic form, and a check matrix.  We use these to rapidly check if a given unitary matrix is a Clifford gate and to convert between the matrix of a Clifford gate and its compact specification as a stabiliser tableau.   For example, we extract the stabiliser tableau of a Clifford gate matrix with $N^2$ entries, which naively requires $O(N^3 \log N)$ time, in time $O(N \log N)$.

Our methods outperform the best-known brute force methods by some orders of magnitude with asymptotic improvements that are exponential in the number of qubits.  We provide example implementations of our algorithms in Python.
\end{abstract}

\vspace{1cm}
\tableofcontents


\newpage

\section{Overview}
Stabiliser states on $n$-qubits admit three convenient descriptions: as a vector of amplitudes, as a check matrix, and as a triple containing an affine subspace of $\Z_2^n$, a quadratic form, and a linear map.  Clifford gates admit two convenient descriptions: as a unitary matrix or as a stabiliser tableau, i.e. a set of $2n$ Pauli gates representing the images of basic Pauli gates under conjugation.  

In Section \ref{background}, we provide the necessary definitions and outline these descriptions.  We also describe the na\"{i}ve brute force methods for verifying that a vector or matrix is a stabiliser state or a Clifford gate respectively and for interconverting between their descriptions.

In Sections \ref{stabsec} and \ref{cliffsec}, we develop novel theory concerning stabiliser states and Clifford gates respectively.  We use these developments to give much faster algorithms for verifying that a vector or matrix is a stabiliser state or a Clifford gate.  We also give much faster algorithms for interconverting between their descriptions, in the cases where the most straightforward method is not already very fast or where no straightforward method is known. 

Python implementations of these algorithms can be found at \url{https://github.com/ndesilva/stabiliser-tools}.

\section{Background}\label{background}

Let $n$ be a positive integer and $N = 2^n$.  We denote the computational basis states of an $n$-qubit system by $\kz \in \C^N$ for $\vec z \in \Z_2^n$.  Given $n$ unitaries $U_1, ..., U_n$ and a vector $\vec{p}$ of $n$ integers, we denote by $U^{\vec{p}}$ the product $U_1^{p_1} \cdots U_n^{p_n}$.  The basic Pauli gates are $Z_i,X_i$: i.e. $Z,X$ respectively on the $i$-th qubit and identity on all others.  Thus, $Z^{\vec p}$ and $X^{\vec q}$, with $\vec p, \vec q \in \Z_2^n$, are defined by \begin{equation}\label{paulidef}Z^{\vec p} \kz = (-1)^{\vec p \cdot \vec z} \kz \quad \quad \quad X^{\vec q} \ket{\vec z + \vec q} \end{equation} where the addition is entrywise and in $\Z_2$.

\begin{defn}\label{paulidefn}The group of \emph{Pauli gates} is the subgroup of $\cU(2^n)$ generated by the basic Pauli gates and $i \I$: \begin{equation}\cP_n = \{(-1)^c (-i)^d X^{\vec{q\,}}  Z^{\vec{p}} \; | \;  (\vec{p}, \vec{q\,}) \in \Z_2^{2n}, \; c,d \in \Z_2 \}.\end{equation}
\end{defn}

The Pauli gates $X^{\vec{q_1\,}} Z^{\vec{p_1}}$ and $X^{\vec{q_2\,}} Z^{\vec{p_2}}$ commute if and only if $[(\vec{p_1}, \vec{q_1}),(\vec{p_2}, \vec{q_2})] \equiv \vec{p_1}\cdot \vec{q_2} - \vec{p_2}\cdot \vec{q_1} = 0$ over $\Z_2$.  A set of Pauli gates is said to be independent if no nontrivial product of them is a multiple of the identity matrix. 

\subsection{Stabiliser states}

Here, we define stabiliser states and the three ways they can be specified (in the first case, precisely, and in the latter two cases, up to phase).

\begin{defn}\label{stabsbgrpdefn}A \emph{stabiliser subgroup} is a maximal abelian subgroup $\cS$ of $\cP_n$ that does not contain $-\I$.
\end{defn}

The stabiliser subgroups $\cS \subset \cP_n$ are all of size $N$.  A stabiliser subgroup can be specified (nonuniquely) by a \emph{check matrix}: a $n \times (2n+1)$ matrix over $\Z_2$ \begin{equation}\begin{bmatrix}
\vec{q_1} & \vec{p_1} & c_1\\
\vdots & \vdots\\
\vec{q_n} & \vec{p_n} & c_n\\
\end{bmatrix}\end{equation} that collates a set of $n$ Pauli gates $(-1)^{c_i} (-i)^{\vec{p} \cdot \vec{q}} Z^{\vec{p}} X^{\vec{q\,}}$ that generate $\cS$.



\begin{defn}\label{stabdefn}A \emph{stabiliser state} is a state $\ket{s} \in \C^{N}$ such that: \begin{equation}P\ket{s} = \ket{s}\end{equation} for all $P \in \cS$ in some stabiliser subgroup $\cS \subset \cP_n$.
\end{defn}

A stabiliser state $\ket{s}$ is specified up to phase by a (nonunique) check matrix for the stabiliser subgroup $\cS_{\ket{s}} = \{P \in \cP_n \;|\; P\ket{s} = \ket{s}\}$.

\begin{theorem}[Dehaene-De Moor \cite{dehaene2003clifford}, 2003]\label{dehaenedemoor}Every stabiliser state $\ket{s}$ (up to phase and normalisation) is specified by a triple $(\cA, Q, \ell)$ where $\cA \subset \Z_2^n$ is the affine subspace $V + \vec{z_0}$ for $V \subset \Z_2^{n}$ a vector subspace and $\vec{z_0} \in \Z_2^{n}$, $Q:V\to\Z_2$ is a quadratic form, and $\ell: V\to\Z_2$ is a linear map: \begin{equation}\label{ddeqn}\ket{s} \propto \sum_{\vec z \in V}  (-1)^{Q(\vec z)} i^{\ell(\vec z)} \ket{\vec z + \vec{z_0}}.\end{equation}
    
\end{theorem}

We have thus described three ways of specifying a stabiliser state (up to phase): 
\begin{enumerate}[label=(S\arabic*)]
    \item as a complex vector of amplitudes: an element of $\C^N$,
    \item as an affine subspace, a linear map, and a quadratic form: an element of $(\Z_2^{n})^{k+1} \times \Z_2^n \times \Z_2^{n(n+1)}$,
    \item as a check matrix: an element of $(\Z_2^{2n+1})^{n}$.
\end{enumerate}

We will refer to second description as the \emph{affine subspace triple} of a stabiliser state for brevity.  Here, $\cA$ is of dimension $k$ and can be specified by $k$ basis vectors $\vec z_1, ..., \vec z_k$ and a shift vector $\vec z_0$.

The brute force test for whether $\ket{\psi}\in\C^N$ is a stabiliser state requires iterating through each of the $N^2$ Pauli gates $P$, computing $P\ket{\psi}$, and determining the number of Pauli gates that stabilise $\ket{\psi}$.  Verifying the other descriptions is straightforward and fast.  

The brute force method to convert a description from (S1) to (S3), is essentially to iterate through the Pauli gates until a stabiliser group is constructed.  To convert a description from (S3) to (S1), one constructs the one-dimensional projection onto the state by summing all the Pauli gates in its stabiliser group and finding the projector's $+1$-eigenvector.  This is very costly as it involves multiplying and inverting matrices of size $N$.  Methods of converting (S1) or (S3) to (S2) are not immediately obvious.

\subsection{Clifford gates}

\begin{defn}\label{cliffdefn}The group of \emph{Clifford gates} is the normaliser of the group of Pauli gates as a subgroup of the unitary matrices $\cU(N)$: \begin{equation}\cC_n = \{C \in \cU(N) \;|\; C \cP_n C^* \subseteq \cC_n \}.\end{equation}
\end{defn}

The Clifford gates, up to phase, are in correspondence with  \emph{conjugate tuples} \cite[Definition 3.6]{de2021efficient} of Pauli gates: these are $n$-tuples of pairs of Pauli gates $((U_1,V_1),...,(U_n,V_n))$ such that $U_i^2 = V_i^2 = \mathbb{I}$, $U_i V_j = (-1)^{\delta_{ij}} V_j U_i$, $U_i U_j = U_j U_i$, and $V_i V_j = V_j V_i$ \cite[Theorem 3.11]{de2021efficient}.  A Clifford gate $C$, up to phase, corresponds to the conjugate tuple $((CZ_1C^*,CX_1X^*),...,(CZ_nC^*,CX_nC^*))$.   Each such Pauli, being of order 2, is of the form $(-1)^c(-i)^{\vec{p}\cdot\vec{q}} Z^{\vec{p}} X^{\vec{q\,}}$ and thus specified by $2n+1$ bits.

The conjugate tuple specification of a Clifford gate is thus vastly more compact ($4n^2 + 2n$ bits vs. $N^2$ complex numbers) and can be used more easily to e.g. act on stabiliser states in check matrix form or conjugate Pauli gates expressed as vectors in $\Z_2^{2n+1}$.  It is well known in the literature as the \emph{stabiliser tableau} of the Clifford gate.

%\todoc{Third description as symplectic matrix + bits?}

We have thus described %three 
two ways of specifying a Clifford gate (up to phase):
\begin{enumerate}[label=(C\arabic*)]
    \item as a complex matrix $C$: an element of $\C^{N \times N}$,
    \item as a conjugate tuple of Pauli gates $U_i = CZ_iC^*, V_i = CX_iC^*$: an element of $((\Z_2^{2n+1})^{2})^n$,
    %\item as an affine symplectic map of $\Z_2^n$: an element of $\Z_2^{2n \times 2n} \times \Z_2^n$.
\end{enumerate}

The brute force method to verify that a matrix $M$ is a Clifford gate is to conjugate the basic Pauli gates and verify that the results are also Pauli gates; this requires multiplying many matrices of size $N$ which requires roughly $N^3$ steps.  Verifying the other descriptions is straightforward and fast.


%Converting between descriptions (C2) and (C3) is straightforward and fast.  The brute force method to convert a description from (C1) $\to$ (C2) or (C3) is essentially to conjugate the basic Pauli gates as above.  The converse direction is described in \cite[Theorem 3.9]{de2021efficient}; there, it requires a conversion between descriptions (S1) $\to$ (S3) of a stabiliser state.  We can therefore use our new methods to improve the conversion (C2) $\to$ (C1) below.  

The brute force method to convert a description from (C1) to (C2) is to conjugate the basic Pauli gates as above.  The converse direction is described in \cite[Theorem 3.9]{de2021efficient}; there, it requires a conversion between descriptions (S1) to (S3) of a stabiliser state.  We can therefore use our new methods to improve the conversion (C2) to (C1) below.  

%\todoc{Paragraph about places where you care about deciding whether states/unitaries are stabilisers/cliffords?}\\

\section{Stabiliser states}\label{stabsec}

Here, we describe a rapid method for extracting from a vector of amplitudes of a stabiliser state its affine subspace triple: that is, the conversion (S1) $\to$ (S2).  Our method also immediately gives an algorithm for verifying that a complex vector is a stabiliser state: accept the input if the conversion completes without error.  We also show that the conversions between a check matrix and an affine subspace triple and vice versa---(S3) $\to$ (S2) and (S2) $\to$ (S3)---can be done very quickly.

\subsection{Amplitudes to an affine subspace triple}

Theorem \ref{dehaenedemoor} already imposes strong constraints on the amplitudes $\braket{\vec z\, | s}$ of a stabiliser state $\ket{s}$: up to a common factor, they must take values in $\{\pm 1, \pm i\}$ and the support $\supp(\ket{s}) = \{\vec z \in \Z_2^n \;|\; \braket{\vec z\, | s} \neq 0\}$ of $\ket{s}$ is an affine subspace $\cA = V + \vec{z_0}$ of dimension $k \leq n$. We can break converting the amplitudes of $\ket{s}$ to an affine subspace triple into two stages:

\begin{enumerate}
    \item Find a basis $\vec{z_1}, ..., \vec{z_k}$ for $V$ and $\vec{z_0}$ such that the support $\supp(\ket{s}) = \cA = V + \vec{z_0}$.
    \item Find the coefficients of the quadratic form $Q$ and the linear map $\ell$  as in Theorem \ref{dehaenedemoor}.
\end{enumerate}

To perform the first step, we convert $\supp(\ket{s})$ into a vector space by taking $\vec z_0$ to be the first element of $\supp(\ket{s})$ and subtracting $\vec z_0$ from every element of $\supp(\ket{s})$.  Upon sorting this list of $2^k$ labels, the basis vectors $\vec{z_i}$ are simply those whose position in the list is a power of 2.  This is a consequence of the following lemma.

\begin{lemma}\label{orderedvectorbasis}
    For any $m \in \mathbb{N}$ and any $\vec x = (x_{m},...,x_1) \in \Z_2^m$, denote by $I(\vec x)$ its corresponding integer $\sum_{i=1}^{m} x_i 2^{i-1}$.
    Suppose $V \subseteq \Z_2^n$ is a subspace of dimension $k$ that inherits a linear order via $I$; enumerating the elements of $V$ in this order, $V = \{\vec{v_0}, ..., \vec v_{2^k-1}\}$.  Then the map $T: \Z_2^k \to V$ given by $T(\vec x) = \vec v_{I(\vec x)}$ is a linear isomorphism.

\end{lemma}

\begin{proof}

Let $L: V \to \{0,...,n\}$ return the position of the leftmost digit, counting from the right end; $L(v_0) = 0$.  This function is clearly nondecreasing.

For $j \in \{1,...,k\}$: $\vec w_j = \vec v_{2^{j-1}}$ and $p_j = L(\vec w_j)$; $p_0 = 0$.  

For $j \in \{0,...,k\}$: define $V_j = \{\vec v_0, ..., \vec v_{2^j - 1} \} = \{ \vec v \in V \;|\; \vec v < \vec w_{j+1} \}$.

We will prove the following claim by induction: $L^{-1}( \{p_0, ..., p_j\} ) = V_j$ for $j \in \{0,...,k\}$.

This trivially holds for $j = 0$; assume it holds for $j$.  Using the definition of $V_j$ and the induction hypothesis to establish two containments respectively, we see that:
$L^{-1}(p_{j+1}) = V_j + \vec w_{j+1}$.
This set contains $2^j$ distinct, consecutive elements, including $\vec w_{j+1}$, and is disjoint from $V_j$.  It is thus equal to $V_{j+1} \setminus V_j$ and our claim is proved.

Thus, $\{p_k, ..., p_1\}$ are distinct and so $(\vec w_k, ..., \vec w_1)$ is an ordered basis of $V$.

Let $T: \Z_2^k \to V$ be given by $T(\vec{x}) = \sum_{i=1}^k x_i \vec w_i$.  We can prove that $\sum_{i=1}^k x_i \vec w_i = \vec v_{I(\vec x)}$ for each $V_j$ by induction on $j$.  This requires the fact that adding $\vec w_{j+1}$ to elements of $V_j$ is an order-preserving operation.  Suppose that $\vec v < \vec v' \in V_j$.  Then $\vec v' + \vec w_{j+1} < \vec v + \vec w_{j+1}$ only if $\vec w_{j+1}$ contains a 1 at the rightmost position in which  $\vec v$ and $\vec v'$ differ.  In this case, $\vec v + \vec v' + \vec w_{j+1} \in V_{j+1} \setminus V_j$ but is strictly less than $\vec w_{j+1}$; a contradiction.
\end{proof}

Having extracted $\vec z_0$ and transformed the support such that  $\supp(\ket{s}) = V = \{\sum_i \alpha_i \vec{z_i} \;|\; \alpha_i \in \Z_2\}$ we can determine $Q, \ell$ as functions of the vectors $\vec \alpha$.  From the amplitudes corresponding to members of the support with $\vec \alpha$ having Hamming weight 1, we can extract $\ell$.  Similarly, from the amplitudes corresponding to members of the support with $\vec \alpha$ having Hamming weight 1 or 2, we can extract $Q$.  Each such $\vec \alpha$ gives an equation: \begin{equation}\label{amplinsys}
\sum_{1\leq i \leq j \leq k} c_{ij} \alpha_i \alpha_j = Q\left(\sum_i \alpha_i \vec{z_i}\right).\end{equation}  We simply need to solve this inhomogenous linear system of $k(k+1)/2$ equations for the coefficients $c_{ij}$.

\begin{algorithm}[H]
\floatname{algorithm}{Algorithm 1:  }
\renewcommand{\thealgorithm}{}
\caption{Convert the amplitudes of a stabiliser state to an affine subspace triple, i.e. (S1) $\to$ (S2)}
\label{s1tos2}
\vspace{0.2cm}
\begin{enumerate}
\item Choose $\vec z_0$ to be the binary label for the first nonzero amplitude.  Subtract $\vec z_0$ from each element of $\supp(\ket{s}) = V + \vec z_0$ to transform it to the vector space $V$.

\item Sort the binary labels of $\supp(\ket{s}) = V$.  Taking those labels whose position is a power of 2 gives a basis $\{\vec z_i\}$ for this vector space.

\item Extract $\ell$ by inspecting the amplitudes corresponding to $\vec z_i$ and observing whether they are real or imaginary. 

\item Extract $Q$ by solving the linear system \eqref{amplinsys}.


%\item Convert the $U_i,V_i$ to an affine symplectic map in $Sp(n,\Z_d) \ltimes \Z_d^{2n}$.

\end{enumerate}

\end{algorithm} 


\subsection{Verifying a vector is a stabiliser state}

One can immediately use the above algorithm to verify that a given vector is a stabiliser state by accepting only at the point that a conversion is made successfully.  

Some additional checks are required since we are not assuming that our input is a valid stabiliser state.  We must first check whether the support of the state has size $2^k$. Then, we see whether the support is an affine space by shifting it and using Lemma \ref{orderedvectorbasis}.  Additionally, we must check that the non-zero amplitudes of the state are consistent with $Q$ and $\ell$.

\subsection{Check matrix to an affine subspace triple}

We will show that with minimal calculations, one can effectively read off the affine subspace triple data of a stabiliser state from its check matrix.  We begin by establishing some required relations between a stabiliser state expressed as an affine subspace triple and the Pauli gates that stabilise it.  Here, we will switch convention slightly from the expression of a stabiliser state in equation \eqref{ddeqn} for convenience by introducing a translation into the ket labels.  An arbitrary stabiliser state $\ket{s}$ can be expressed in the form \begin{equation}
    \ket{s} \propto \sum_{\vec z \in V} (-1)^{Q(\vec z)} i^{\ell(\vec z)}  \ket{\vec z + \vec z_0}
\end{equation} where $V \subset \Z_2^n$ is a vector subspace of dimension $k \leq n$, $\vec z_0 \in \Z_2^n$, and $Q, \ell: V \to \Z_2$ .

Suppose $P = (-1)^c (-i)^{\vec p \cdot \vec q} X^{\vec q} Z^{\vec p}$ stabilises $\ket{s}$: $P\ket{s} = \ket{s}$.  We can see immediately that $\vec q \in V$ or else $P$ changes the support of $\ket{s}$.  Moreover, by comparing the amplitudes of  $\ket{s}$ and $P\ket{s}$, we find that \begin{equation}\label{imgcondn}\ell(\vec{q\,}) = \vec p \cdot \vec q\end{equation}\begin{equation}\label{stabcondn}
    \text{For all }\vec z \in V: \quad Q(\vec z) = c + Q(\vec z + \vec q) + \vec p \cdot (\vec z + \vec q + \vec z_0) + (\vec p \cdot \vec{q\,}) \ell(\vec z) \text{ over } \Z_2.
\end{equation}

Choose $B$ to be a $\Z_2$-bilinear form such that $Q(\vec z) = B(
\vec z, \vec z)$; for example if $Q(\vec z) = \vec z^{\,T} \tilde Q \vec z$ for the upper triangular matrix $\tilde Q$, then we can take $B(
\vec z, \vec z{\,'}) = \vec z^{\,T} \tilde Q \, \vec z{\,'}$.  We can then express equation \eqref{stabcondn} as \begin{equation}
    [B(\vec q, \vec z) + \prescript{\text{T}\!}{}B(\vec q, \vec z) + (\vec p \cdot \vec{q\,}) \ell(\vec z) + \vec p \cdot \vec z] + [B(\vec q, \vec q) + \vec p \cdot (\vec q + \vec z_0) + c]= 0
\end{equation} where the first term is a linear function of $\vec z \in V$ and the second term is a constant.  This can hold only if both terms are identically zero.  Therefore:
\begin{equation}\label{ceqn}
c = \vec p \cdot (\vec q + \vec z_0) + B(\vec q, \vec q)
\end{equation}\begin{equation}\label{pxeqn}
\vec p \cdot \vec z = B(\vec q, \vec z) + \prescript{\text{T}\!}{}B(\vec q, \vec z) + (\vec p \cdot \vec q) \ell(\vec z)
\end{equation} where the latter equality is as linear functions from $V$ to $\Z_2$.  For each $\vec q \in V$, there is precisely one choice of $c$ and one choice of $\vec p$, up to adding an element of $V^\perp$, such that $P\ket{s} = \ket{s}$.

Now, suppose we are given a check matrix of a stabiliser state.  Without loss of generality, we may perform row reduction and assume that the first $2n$ columns are in reduced echelon form:
\begin{equation}\begin{bmatrix}\label{reducedcheck}
\vec{q_1} & \vec{p_1} & c_1\\
\vdots & \vdots\\
\vec{q_k} & \vec{p_k} & c_k\\
\vec{0} & \vec{\rho_1} & \gamma_1\\
\vdots & \vdots\\
\vec{0} & \vec \rho_{n-k} & \gamma_{n-k}\\
\end{bmatrix}\end{equation}

We can immediately take the $\vec q_i$ as a basis for $V$.  The shift $\vec z_0$ is any solution to the system of $n-k$ equations $\rho_i \cdot \vec z_0 = \gamma_i$.  By equation \eqref{imgcondn} and the fact that all the stabilising Pauli gates must have order 2, we can extract $\ell$ and define it on the basis for $V$ via the equations $\ell(\vec q_i) = \vec p_i \cdot \vec q_i$.

We can extract the diagonal entries of $\tilde Q$ by rearranging equation \eqref{ceqn} \begin{equation}\label{diagq}
\tilde Q_{ii} = B(\vec q_i, \vec q_i) = c_i + \vec p_i \cdot (\vec q_i + \vec z_0).
\end{equation}  
We can extract the strictly upper triangular entries of $\tilde Q$, i.e.  $\tilde Q_{ij}$ for $1 \leq i < j \leq k$, by rearranging equation \eqref{pxeqn}:\begin{equation}\label{offdiags}
\tilde Q_{ij} = B(\vec q_i, \vec q_j) = B(\vec q_i, \vec q_j) + \prescript{\text{T}\!}{}B(\vec q_i, \vec q_j) = \vec p_i \cdot \vec q_j + (\vec p_i \cdot \vec q_i)(\vec p_j \cdot \vec q_j).
\end{equation}


\begin{algorithm}[H]
\floatname{algorithm}{Algorithm 2:  }
\renewcommand{\thealgorithm}{}
\caption{Convert the check matrix of a stabiliser state to an affine subspace triple, i.e. (S3) $\to$ (S2)}
\label{s3tos2}
\vspace{0.2cm}
\begin{enumerate}
\item Row reduce the first two columns whilst updating the sign bits consistently to ensure that the resulting check matrix represents the same stabiliser state up to phase.  Label the result as in equation \eqref{reducedcheck}.

\item Take the $\vec q_i$ as a basis for $v$ and a solution to $\rho_i \cdot \vec z_0 = \gamma_i$ for the shift $\vec z_0$. 

\item Compute $\ell(\vec q_i) = \vec q_i \cdot \vec p_i$ and store these as a vector representing $\ell$ in the ordered basis $\{\vec q_1,...,\vec q_k\}$ of $V$.

\item Compute a matrix representing $Q$ relative to the same ordered basis using equations \eqref{diagq} and \eqref{offdiags}.


%\item Convert the $U_i,V_i$ to an affine symplectic map in $Sp(n,\Z_d) \ltimes \Z_d^{2n}$.

\end{enumerate}

\end{algorithm} 



\subsection{Affine subspace triple to a check matrix}

We have shown above that it is relatively straightforward to read off the affine subspace triple data from a check matrix.  Here, we reverse this process. Suppose we are given a basis $\{\vec v_1,...,\vec v_k\}$ for $V \subset \Z_2^n$, a shift vector $\vec z_0 \in \Z_2^n$, a $k \times k$ upper triangular matrix $\tilde Q$ over $\Z_2$, and a vector $\ell \in \Z_2^k$.

As in equation \eqref{reducedcheck}, we can generate the $\vec q_i$ by row reducing the basis $\vec v_i$; we store the resulting change of basis matrix of $\Z_2^k$ and use it to update $\tilde Q,\ell$.  The updated $\tilde Q$ may no longer be upper triangular but can made so by taking $\tilde Q + \tilde Q_l + (\tilde Q_l)^\text{T}$ where $\tilde Q_l$  is the strictly lower triangular part of $\tilde Q$.   

Applying equation \eqref{pxeqn} to $(\vec p, \vec q) = (\rho_i, \vec 0)$, we see that the $\rho_i$ can be taken to be a basis of the null space of matrix whose rows are $\vec q_i$, i.e. of $V^\perp$.  We can then extract $\gamma_i$ using $\gamma_i = \vec \rho_i \cdot \vec z_0$.

Using equations \eqref{imgcondn} and \eqref{pxeqn} we can use our given $\tilde Q$ and $\ell$ to give linear systems for each $\vec p_i$:\begin{equation}\label{pilinsys}
\vec p_i \cdot \vec q_j = \tilde Q_{ij} + \ell(\vec q_i) \ell(\vec q_j).
\end{equation}
These determine each $\vec p_i$ in the basis $\{\vec q_1,...,\vec q_k\}$ up to an element of $V^\perp$.

Finally, we compute the $c_i$ using equation \eqref{ceqn}:\begin{equation}
    c_i = \vec p_i \cdot (\vec q_i + \vec z_0) + \tilde Q_{ii}
\end{equation}


\begin{algorithm}[H]
\floatname{algorithm}{Algorithm 3:  }
\renewcommand{\thealgorithm}{}
\caption{Convert the affine subspace triple of a stabiliser state to a check matrix, i.e. (S2) $\to$ (S3)}
\label{s2tos3}
\vspace{0.2cm}
\begin{enumerate}
\item Row reduce the basis $\{\vec v_1, ..., \vec v_k\}$ of V to find $\{\vec q_1, ..., \vec q_k\}$ and a basis $\{\vec \rho_1, ...,\vec \rho_{n-k}\}$ of the null space of $V$.

\item Update $\tilde Q, \ell$ using the change of basis matrix of the previous Step.  Convert $\tilde Q$ to an upper triangular matrix representing the same quadratic form.

\item Compute $\gamma_i = \vec \rho_i \cdot \vec z_0$.

\item Find each of the $\vec p_i$ by solving the underdetermined linear systems of equation \eqref{pilinsys}.

\item Compute $c_i = \vec p_i \cdot (\vec q_i + \vec z_0) + \tilde Q_{ii}$.


%\item Convert the $U_i,V_i$ to an affine symplectic map in $Sp(n,\Z_d) \ltimes \Z_d^{2n}$.

\end{enumerate}

\end{algorithm} 


\section{Clifford gates}\label{cliffsec}

In this section, we describe a highly efficient algorithm for extracting from a Clifford gate $C$, given by its matrix elements, its conjugate tuple: the $2n$ Pauli gates $U_i = CZ_iC^*, V_i = CX_iC^*$.  It can also be used to check if a given unitary matrix $U$ is a Clifford gate.  It works by building upon our above algorithm for extracting generators for the stabiliser group of a stabiliser vector.

\subsection{Matrix entries to a conjugate tuple}

The conjugate tuple $U_i = CZ_iC^*, V_i = CX_iC^*$, expressed as $2n$ elements of $\Z_2^{n+1}$, of a Clifford gate can be found in two steps.

We begin by extracting the $U_i$ by examining the stabiliser group of the first column of $C$.  To justify this calculation, we require some lemmata.

\begin{lemma}For a Clifford gate $C$, the stabiliser group of $C\ket{\vec 0}$ is generated by $U_i = CZ_iC^*$.
\end{lemma}

\begin{proof}
    $U_i (C \ket{\vec 0}) = C Z_i \ket{\vec 0} = C \ket{\vec 0}$.  The $U_i$ are independent since the $Z_i$ are.
\end{proof}

We can rapidly extract a set of generators $P_i$ for this stabiliser subgroup using the techniques of the previous section.  Since $P_i$ and $U_i$ generate the same stabiliser subgroup, we have that $P_i = U^{\vec{\rho_i}}$ for some $\vec{\rho}_i \in \Z_2^n$.  Thus,
\begin{equation}\label{eqn:pi_eqn}
    P_i \,C \kz = U^{\vec{\rho_i}} C \kz = C Z^{\vec{\rho_i}} \kz = (-1)^{\vec{\rho_i}\cdot \vec{z}} C\kz.
\end{equation}

We can thus extract the vectors $\vec{\rho_i}$ by computing $P_i \,C \kz$ for $\vec{z}$ having Hamming weight 1.  Note that Pauli-vector multiplication can be done more quickly than by using standard matrix-vector multiplication by instead reindexing the vector and introducing appropriate sign changes.

We know that the $\rho_i$ are linearly independent since the $P_i$ are independent.  We may thus invert the matrix whose columns are  $\rho_i$; we call the rows of this inverse $\mu_i$.  It is a consequence of the following lemma that $U_i = P_i^{\mu_i}$.

\begin{lemma}\label{mconjzlemma}
    Suppose that $M$, $U_i$ are matrices of size $N \times N$, with $M$ unitary, such that for all $\vec{z} \in \Z_2^n$ \begin{equation}\label{uimkz}U_i M \kz = (-1)^{z_i} M \kz.\end{equation}  Then $M$ conjugates the $Z_i$ to $U_i$; that is, $M Z_i M^* = U_i$.
\end{lemma}

\begin{proof}
    Multiplying \eqref{uimkz} by $\bra{\vec{z_2}} M^*$ we see that $\bra{\vec{z_2}} M^* U_i M \ket{\vec{z_1}} = (-1)^{z_i} \delta_{\vec{z_1},\vec{z_2}}$ and thus $ M^* U_i M = Z_i$.
\end{proof}

Having found the $U_i$, we must now find the $V_i$.  Our strategy will be to find Pauli gates $W_i$ of order 2 such that $U_i$ and $W_j$ anticommute if and only if $i=j$.  We will then correct these to get the $V_i$ by querying as few entries of $C$ as possible.

Constructing the $W_i$ is straightforward.  If $U_i \propto X^{\vec q_i}Z^{\vec p_i}$, define $U$ to be the $n \times 2n$ matrix over $\Z_2$ whose $i$-th row is $(\vec q_i, \vec p_i)$.  As these rows are linearly independent, $U^+ = U^T (UU^T)^{-1}$ is a right inverse: $UU^+ = \mathbb{I}$.  We may thus take $W_i$ to be $(-i)^{\vec \alpha_i \cdot \vec \beta_i} X^{\vec \beta_i}Z^{\vec \alpha_i}$ where $(\vec \alpha_i, \vec \beta_i)$ is the $i$-th column of $U^+$.

Each $V_i$ differs from $W_i$ by a product of the $U_j$ as a result of the following lemma.

\begin{lemma}
Suppose the $n$ Pauli gates $U_i$ generate a stabiliser group, the Pauli gates $V_i$, $W_i$ are of order 2, and that $V_i$ commutes (or anticommutes) with $U_i$ if and only if  $W_i$ does.  Then $V_i = (-1)^{c_i}(-i)^{d_i} W_i U^{\vec v_i}$ for some $\vec v_i \in \Z_2^n$ and $c_i, d_i \in \Z_2$.
\end{lemma}

\begin{proof}
    Define the Pauli gates $T_i = i^{d_i}W_i V_i$ where $d_i$ is 0 if $W_i$ and $V_i$ commute and 1 if they anticommute.  They commute with every $U_j$: $T_i U_j = i^{d_i}W_i V_i U_j = i^{d_i}U_j W_i V_i = U_j T_i$.  Further, the $T_i$ are of order 2.  Therefore, by Definition \ref{stabsbgrpdefn}, for each $i$, either $T_i$ or $-T_i$ is a member of the stabiliser group generated by $U_i$.
\end{proof}

Therefore, our final task is to find the $V_i$ is to determine the appropriate $\vec v_i \in \Z_2^n$ and $c_i, d_i \in \Z_2$.
\begin{align}\label{comparecols}
C\ket{\vec z + \vec e_i} &= C X_i \kz\\ 
&= V_i C \kz\\  
&= (-1)^{c_i}(-i)^{d_i} W_i U^{\vec v_i} C \kz\\ 
&= (-1)^{c_i}(-i)^{d_i} W_i C Z^{\vec v_i} \kz\\  
&= (-1)^{\vec v_i \cdot \vec z \,+\, c_i}(-i)^{d_i} W_i  \,\, C \kz\label{comparecols2}
\end{align}
where $\vec e_i$ is the $i$-th unit vector of $\Z_2^n$.

By comparing the relative phases of the columns of $C$ corresponding to $\vec z$ and $\vec z + \vec e_i$, we gain information about the required variables $\vec v_i, c_i, d_i$.  Choosing $\vec z = \vec 0$, we determine the $c_i, d_i$.  Choosing $\vec z$ to be of Hamming weight 1, we determine the components of the $\vec v_i$.  

To determine the relative phases of two columns, we need only check two nonzero entries: one from each column. To avoid potentially having to perform a high number of checks for columns that contain many zeros, we can compute the support of each column first. We do this using that the fact that the support of $C\ket{\vec{z}}$ is the same as $W^{\vec{z}}C\ket{\vec{0}}$, as each $U_i$ either stabilises or antistabilise every column.

\begin{algorithm}[H]
\floatname{algorithm}{Algorithm 4:  }
\renewcommand{\thealgorithm}{}
\caption{Extract the conjugate tuple of a Clifford gate $C$, i.e. (C1) $\to$ (C2)}
\label{c1toc2}
\vspace{0.2cm}
\begin{enumerate}
\item Compose Algorithms 1 and 3 to extract generators $P_i$ for the stabiliser group of $C\ket{\vec{0}}$

\item For each $\vec z$ with Hamming weight 1, use rapid Pauli-vector multiplication to compute $P_i \,C\kz$ and inspect its
the first nonzero entry.  Find that $P_i \, C \kz = (-1)^{\vec{\rho_i} \cdot \vec z} \kz$ for some $\vec{\rho_i}\in \Z_2^n$.

\item Invert the $n \times n$ matrix over $\Z_2$ whose columns are $\vec{\rho_i}$ to find one with rows $\vec{\mu_i}$. Conclude that $U_i = P^{\vec \mu_i}$.

\item Compute the bitstrings specifying the $W_i$ (up to sign) by taking the pseudoinverse of the matrix whose rows are the bitstrings specifying the $U_i$.

\item Correct the $W_i$ to $V_i$ using equations \eqref{comparecols} and \eqref{comparecols2} by comparing two nonzero entries of the $\vec z$-th and $\vec z + \vec e_i$-th columns of $C$ for $\vec z$ being $\vec 0$ or having Hamming weight 1.

%\item Convert the $U_i,V_i$ to an affine symplectic map in $Sp(n,\Z_d) \ltimes \Z_d^{2n}$.

\end{enumerate}

\end{algorithm} 



\subsection{Verifying a matrix is a Clifford gate}

One can use the above algorithm to verify that a given matrix $M$ is a Clifford gate by accepting only at the point that a conversion is made successfully.  Since we are not assuming that $M$ is a Clifford gate, we must add a few additional checks.  

In Step 2, in order to verify that $P_i \, M \kz = (-1)^{\vec{\rho_i} \cdot \vec z} \kz$, we must construct the full vector $P_i \, M \kz$ (using rapid Pauli-vector multiplication) rather than only inspecting the first nonzero entry.  Moreover, having constructed the $\vec{\rho_i}$ from the $\vec z$-th columns for $\vec z$ with Hamming weight 1, we must check that all other columns are consistent with these equations. 

Once we have verified that every column is correctly stabilised or antistabilised by the $U_i$, every column of the matrix is determined up to a phase. Thus, when finding the $\vec{v}_i$ we still need only check the ratio between two nonzero entries. However, two more additional checks are required: firstly, that our candidate $V_i$ commute. Secondly, we must verify that the relative phase of each of the remaining columns is consistent with the $V_i$.  We do this by iterating through the Gray code \cite{Bitner1976gray}. The Gray code has the useful property that any two consecutive codewords differ only at a single bit. Since the support of $C\ket{\vec{z}+\vec{e}_i}$ is the same as $V_i \, C\kz$, we can update a nonzero index of the $\vec{z}$-th column to a nonzero index of the $\vec{z}+\vec{e}_i$-th column by adding $\vec{q_i}$ where $V_i \propto X^{\vec q_i}Z^{\vec p_i}$.

In Step 5, however, it remains sufficient to compare only two nonzero entries from the appropriate columns to correct the $W_i$ to $V_i$.  This is a consequence of the following lemma that is proved similarly to Lemma \ref{mconjzlemma}:

\begin{lemma}\label{mconjxlemma}
    Suppose that $M$, $V_i$ are matrices of size $N \times N$, with $M$ unitary, such that for all $\vec{z} \in \Z_2^n$ \begin{equation}\label{vimkz}V_i M \kz =  M \ket{\vec z + \vec e_i}.\end{equation}  Then $M$ conjugates the $X_i$ to $V_i$; that is, $M X_i M^* = V_i$.
\end{lemma}


\subsection{Conjugate tuple to a matrix}

To rapidly construct the matrix of a Clifford gate (up to phase) given its conjugate tuple, we employ Theorem 3.9 of \cite{de2021efficient}.

\begin{theorem}The unitary $C$ that carries each $(Z_i,X_i)$ to $(U_i,V_i)$ under conjugation is given by: 
\begin{equation}C \kz = V^{\vec{z}} \ket{u_0} \end{equation}
where $\vec{z} \in \Z_2^n$ and $\ket{u_0} = C \ket{0}$ is a simultaneous eigenvector of the $U_1, ..., U_n$ with eigenvalue 1.
\end{theorem}

The simultaneous eigenvector of the $U_1,\ldots,U_n$ with eigenvalue 1 can be quickly computed with Algorithm 3 above.  Here, we again make use of the fast method for Pauli-vector multiplication.


%\subsection{Conjugate tuple to an affine symplectic map}

%\subsection{Affine symplectic map to a conjugate tuple}


\section{Complexity analyses}
We explicitly consider the complexity of each of our Algorithms as well as the other interconversions and verification algorithms based on them.

\subsection{Stabiliser states}

\noindent\textbf{Algorithm 1:}
\begin{enumerate}
    \item Finding the nonzero amplitudes takes $O(N)$ time; adding $\vec{z_0}$ to each element then takes $O(Nn)$ operations.
    \item Sorting the binary labels takes time $O(k 2^k)$, where $k$ is the dimension of support.
    \item Extracting $\ell$ takes time $O(n)$.
    \item Extracting $Q$ takes time $O(n^2)$.
\end{enumerate}
In the case that $k$ is very small, the dominant step of the Algorithm is Step 1. However, if $k = \Omega(n)$, Step 2 will dominate and Algorithm 1 runs in time $O(N\log N)$. \\

\noindent\textbf{Algorithm 2:}
\begin{enumerate}
    \item Gaussian elimination takes time $O(n^3)$.
    \item Finding a solution to the row reduced equation takes time $O(n)$.
    \item Computing $\ell$ takes time $O(k)$, where $k$ is the dimension of the affine space.
    \item Computing $Q$ takes time $O(k^2)$.
\end{enumerate}
Thus, Algorithm 2 runs in time $O(n^3)$.\\

\noindent\textbf{Algorithm 3:}
\begin{enumerate}
    \item Row reducing takes time $O(nk^2)$, where $k$ is the dimension of $V$. Finding a null basis for the null space then takes time $O((n-k)k)$.
    \item Computing $Q$ and $\ell$ can be done in parallel with Step 1, altering after each row reduction. Each update takes constant time (as it corresponds to swapping a row or adding two rows together) and thus this does not affect the complexity of Step 1.
    \item This takes $O((n-k)n)$ steps.
    \item This takes $O(kn)$ steps.
\end{enumerate}
In general, when $k = \Omega (n)$, Algorithm 3 runs in time $O(n^3)$. \\

\noindent\textbf{(S1) $\to$ (S3).}  Our algorithm is the composition of Algorithms 1 and 3, and thus requires $O(N \log N)$ time. By comparison, The brute-force approach requires multiplying a stabiliser vector by up to $4^n = N^2$ Pauli gates in the worst case.  Each multiplication requires on the order of $N$ operations so we can estimate the asymptotic time complexity as $\sim N^3$. \\

\noindent\textbf{Verifying (S1).} In addition to Algorithm 1, we must run the extra two checks described: checking the support is an affine space and that the coefficients are consistent. Suppose that the support has size $2^k$, checking the support is an affine space using Lemma 1 takes time $O(nk2^k)$ (in the worst case we take the sum of $k$ basis vectors, each of length $n$). Evaluating $i^{\ell(\vec{z})}(-1)^Q(\vec{z}))$ takes time $O(k^2)$ and verifying coefficients takes time $O(2^k nk)$. In general, when $k=\Omega(n)$, these steps both dominate and thus our algorithm runs in time $O(N \log ^2 N)$.

This is exponentially faster than the $N^2$ steps required to construct the stabiliser group via the brute force algorithm. Note that to verify a vector, one must look at every element at least once, giving an $\Omega(N)$ lower bound.\\

\noindent\textbf{(S3) $\to$ (S1).} First, we run Algorithm 2 to move to (S2) form. Letting $k$ be the dimension of the affine space, we then must iterate through the affine space evaluating the quadratic form. Computing the vector given the coefficients of the basis takes time $O(nk)$ (there are at worst $k$ basis vectors of length $n$) and evaluating the coefficient takes time $O(k^2)$. Thus producing the vector amplitudes takes time $O(2^k nk)$, which is $O(N \log^2 N)$ in the worst case.

By comparison, the standard method of converting a check matrix to a vector of amplitudes requires summing over all $N^2$ Pauli gates in the stabiliser group to construct a rank-1 projector and then fnding its $+1$-eigenvector.  This requires roughly $\sim N^3$ steps.

\subsection{Clifford gates}

\noindent\textbf{Algorithm 4:}
\begin{enumerate}
    \item This takes $O(N\log N)$ time, as discussed above.
    \item In the worst case, we search for $O(N)$ time to find a non-zero element of a given column. Once we have found one for each column of Hamming weight 1, taking time $O(Nn)$, we can extract all the $\vec{\rho}_i$ vectors in time $O(n^2)$.
    \item It takes time $O(n^3)$ to find the pseudoinverse of the $U$.  In fact, the output of Algorithm 1 gave us the row-reduced version of $U$; by keeping track of the row operations when running algorithm 2, we can construct the pseudoinverse simultaneously. We then require $O(n^2)$ time to find each of the $W_i$.
    \item Comparing relative phase of the columns corresponding to Hamming weight 1 and 2 takes time $O(n^3)$ as there are $n^2$ such columns and finding a non-zero element takes time $O(n)$. Then, finding the $V_i$ involves multiplying each $W_i$ by $O(n)$ Pauli, where each Pauli multiplication takes time $O(n)$.  This step thus also runs in time $O(n^3)$.
\end{enumerate}
The algorithm is dominated by Steps 1 and 2, and thus takes time $O(N \log N)$. By comparison, conjugating the basic Pauli gates requires $\Omega(nN^3)$ steps.\\

\noindent\textbf{Verifying (C1).}\\
Compared to Algorithm 4, we must also check the consistency of equation \eqref{eqn:pi_eqn} on all the columns of $C$, check that the $V_i$ commute and check the relative phases between all of the columns. Verifying that a column is an stabilised or antistabilised by a Pauli gate takes time $O(Nn)$, we do this for every column and every $U_i$ giving $O(N^2n^2)$ steps. Checking that the $V_i$ commute and are Hermitian takes time $O(n^3)$. Checking the relative phase of all the columns takes time $O(Nn)$ as at every step of the Gray code we add two vectors of length $n$ to find a non-zero entry. Thus, our verification is dominated by checking the consistency of the columns and takes time $O(N^2\log^2 N)$. \\
This is an exponential improvement over conjugating the basic Pauli gates, which takes time $\Omega(nN^3)$. Note that to verify a matrix, one must look at every element at least once, giving an $\Omega(N^2)$ lower bound.\\

\noindent\textbf{(C2) $\to$ (C1).}  The time savings of our approach is the same as that of the conversion (S1) $\to$ (S3).

\section{Acknowledgments}
ND acknowledges support from the Canada Research Chair program, NSERC Discovery Grant RGPIN-2022-03103, the NSERC-European Commission project FoQaCiA, and the Faculty of Science of Simon Fraser University. Wilfred Salmon was supported by the EPSRC and Hitachi.

%\section{Declarations}
%The authors have no relevant financial or non-financial interests or competing interests to declare that are relevant to the content of this article.

\bibliographystyle{abbrv}
{\footnotesize
\bibliography{cliff}}

\end{document}


\begin{defn}
An ordered pair of unitaries $(U,V) \in \cU(d^n) \times \cU(d^n)$ is a \emph{conjugate pair} if
\begin{enumerate}\itemsep0em 
\item $U^d = \I$ and $V^d = \I$,
\item $UV = \omega VU$.
\end{enumerate}
\end{defn}

\begin{defn}
A \emph{conjugate tuple} $\{(U_1,V_2), ..., (U_n,V_n)\}$ is an ordered set of $n$ conjugate pairs of $n$-qudit gates such that any two elements of distinct pairs commute.
\end{defn}

\begin{theorem}\label{C3fromtuples}
Gates of the third level of the Clifford hierarchy, up to phase, are in bijective correspondence with conjugate tuples of Clifford gates.
\end{theorem}

\begin{lemma}\label{c3eqns}
Suppose $U = \omega^{x} D X^{\vec{q}}$, $V = \omega^{y} E X^{\vec{\beta}}$, for $D, E \in \cD_3^2$; $x,y \in \Z_d$; and $\vec{q}, \vec{\beta} \in \Z_d^2$.  Suppose further that $D = D[\omega^\phi] Z^{\vec{a}}$ and $E = E[\omega^\psi] Z^{\vec{b}}$ where $\phi(\vec{z\,}) = d_1 z_1^2 + d_2 z_2^2 + d_3 z_1 z_2$; $\psi(\vec{z\,}) = e_1 z_1^2 + e_2 z_2^2 + e_3 z_1 z_2$; and $\vec{a}, \vec{b} \in \Z_d^2$.

Then $UV = \omega^c VU$ for $c \in \Z_d$ if and only if, modulo $d$:
\begin{align*} 2 d_1 \beta_1 + d_3 \beta_2 -2 e_1 q_1 - e_3 q_2 &\equiv 0 \\
 d_3 \beta_1 + 2 d_2 \beta_2  -e_3 q_1 - 2 e_2 q_2  &\equiv 0 \\
 \psi(\vec{q}) + \vec{a} \cdot \vec{\beta}  - \phi(\vec{\beta}) - \vec{b} \cdot \vec{q}  &\equiv c.
\end{align*}
\end{lemma}




One can then apply Theorem \ref{semicliff} to verify that each conjugate tuple arises from a semi-Clifford gate.  It is sufficient to verify that the kernel of the matrix $$\begin{pmatrix}
u_1 & v_1 & s_1 & t_1 \\
u_2 & v_2 & s_2 & t_2 \\
u_3 & v_3 & s_3 & t_3 \end{pmatrix}$$ contains a Lagrangian semibasis, where $u_i, v_i, s_i, t_i$ are the coefficients of the homogeneous quadratic polynomial of $U,V,S,T$ respectively.  This is because for any Pauli $P_1$ and homogeneous quadratic $\phi$, there is a Pauli $P_2$ such that $P_1 D[\omega ^\phi] = D[\omega ^\phi] P_2$.


As we have seen, Pauli gates are in correspondence with elements of the group $\Z_d^{2n+1}$ with multiplication inherited from $\mathsf{H}_n(\Z_d)$.  

The $*$-automorphisms of the vector space $\cL(\C^{d^n})$ of linear operators on $\C^{d^n}$ are in correspondence with unitaries up to phase, i.e. $\cU(d^n)/\mathbb{T}$, as a consequence of the Skolem-Noether theorem.  Thus, Clifford gates are determined by their images under conjugation of the basis of phaseless Pauli gates.
\begin{thebibliography}{1}

\bibitem{Bitner1976gray}
J.~R. Bitner, G.~Ehrlich, and E.~M. Reingold.
\newblock Efficient generation of the binary reflected {G}ray code and its applications.
\newblock {\em Commun. ACM}, 19(9):517–521, sep 1976.

\bibitem{de2021efficient}
N.~de~Silva.
\newblock Efficient quantum gate teleportation in higher dimensions.
\newblock {\em Proceedings of the Royal Society A}, 477(2251):20200865, 2021.

\bibitem{dehaene2003clifford}
J.~Dehaene and B.~De~Moor.
\newblock Clifford group, stabilizer states, and linear and quadratic operations over {GF}(2).
\newblock {\em Physical Review A}, 68(4):042318, 2003.

\end{thebibliography}