# Quantum weight enumerators and tensor networks

ChunJun Cao and Brad Lackey C. Cao is at the Institute for Quantum Information
and Matter, California Institute of Technology.B. Lackey is at Microsoft
Quantum, Microsoft Corporation.

###### Abstract

We examine the use of weight enumerators for analyzing tensor network
constructions, and specifically the quantum lego framework recently
introduced. We extend the notion of quantum weight enumerators to so-called
tensor enumerators, and prove that the trace operation on tensor networks is
compatible with a trace operation on tensor enumerators. This allows us to
compute quantum weight enumerators of larger codes such as the ones
constructed through tensor network methods more efficiently. We also provide a
general framework for quantum MacWilliams identities that includes tensor
enumerators as a special case.

###### Index Terms:

Quantum codes, weight enumerators, tensor networks, MacWilliams identity

This work has been submitted to the IEEE for possible publication. Copyright
may be transferred without notice, after which this version may no longer be
accessible.

###### Contents

  1. I Introduction
  2. II Definitions
  3. III Scalar enumerators
  4. IV Vector enumerators
  5. V Tensor enumerators
  6. VI All quantum MacWilliams identities
  7. VII Tensor networks

##  I Introduction

The weight enumerator of a classical code counts the number of codewords at
each Hamming weight, typically presented as a polynomial in a single
indeterminate $z$ where the coefficient of $z^{w}$ is the number of codewords
of Hamming weight $w$. The distance of the code can be extracted as the
smallest (nonzero) degree where the enumerator has a positive coefficient. The
MacWilliams identity [1] famously relates the weight enumerator of a code with
that of its dual code.

Shor and Laflamme introduced two quantum weight enumerators [2] related by an
analogue of the MacWilliams identity. For stabilizer codes, the $A$-enumerator
counts the number of stabilizers at each Hamming weight (i.e. the number of
non-identity Pauli operators) while the $B$-enumerator counts the number of
logical operators at each Hamming weight. The distance of a stabilizer code is
then the smallest degree where the coefficient (up to appropriate
normalization) of $B$ strictly exceeds that of $A$. For completeness, we will
recount this in Section III below. Note that in terms of error detection, the
difference of $B$ and $A$ expresses the probability of an undetected error
even when the underlying code is not a stabilizer code [3].

Other quantum enumerators have been introduced, such as the “shadow”
enumerator of [4, 5] to create bounds on the length, dimension, and distance
for which quantum codes can exist. In [6, 7], the authors introduce quantum
enumerators for asymmetric errors that count the types of Pauli operators that
appear in a stabilizer/logical operator.

In this work we introduce a quantum weight enumerator formalism for tensor
network constructions of quantum codes and in particular those from the recent
quantum lego formalism [8]111See also a related approach [9].. We will also
examine its detailed applications to quantum error correcting codes using
tensor networks in a companion paper [10]. In particular, the enumerators of
Shor and Laflamme (or Hu, et al.) are “scalar” enumerators in our theory. We
introduce vector and tensor enumerators whose coefficients are scalar
enumerators, and show that tracing these enumerators in a tensor network
recovers the Shor and Laflamme enumerators. We prove an analogue of the
MacWilliams identity for tensor enumerators (Theorem V.2).

We also prove tensor enumerators are well-behaved under tensor product of the
underlying networks: the tensor enumerator of a tensor product is the tensor
product of the component enumerators (Proposition V.3). We also show that the
trace of two legs in a tensor network extends to tensor enumerators, in that
the enumerator of the trace can be computed by performing the trace of tensor
enumerator along the corresponding legs (Theorem VII.1). In this way we can
compute enumerators of large quantum codes constructed through tensor network
methods.

##  II Definitions

A unitary basis on a Hilbert space $\mathfrak{H}$ of $\dim(\mathfrak{H})=q$ is
a set of unitary operators $\mathcal{E}$ containing $I$ that form an
orthonormal basis of $L(\mathfrak{H})$, in that
$\operatorname{Tr}(EF^{\dagger})=0$ if $E\not=F$ [11]. While quantum weight
enumerators can be defined relative to a general unitary basis, to obtain
important results such as a MacWilliams identity we require the basis have
some additional structure. We focus on a class of “nice error bases” [12, 13],
those with Abelian index group [14]. To avoid unnecessary repetition, we will
simply refer to these as an “error basis” formally defined as follows.

######  Definition II.1.

An _error basis_ on a Hilbert space is a unitary basis $\mathcal{E}$ that
additionally satisfies

$EF=\omega(E,F)FE$ (II.1)

for all $E,F\in\mathcal{E}$, where $\omega(E,F)\in\mathbb{C}$ satisfies
$\omega(E,F)^{r}=1$ for some fixed $r$.

Perhaps the most important example of such a basis in the (generalized) Pauli
group. This group is generated by operators $X,Z$, where

$Z|{j}\rangle=\zeta^{j}|{j}\rangle\text{ and }X|{j}\rangle=|{j+1\text{ (mod
$q$)}}\rangle,$

where $\zeta=e^{2\pi i/q}$. That is, the eigenvalues of $Z$ are the $q$-th
roots-of-unity, and on its eigenbasis $X$ acts as cyclic shift. Then
$XZ=\zeta^{-1}ZX$. The Pauli basis is

$\mathcal{P}=\\{X^{a}Z^{a^{\prime}}\>:\>a,a^{\prime}\in\\{0,\dots,q-1\\}\\},$

and
$\omega(X^{a}Z^{a^{\prime}},X^{b}Z^{b^{\prime}})=\zeta^{(a^{\prime}b-ab^{\prime})}$.

Given an error basis for $\mathfrak{H}$, we obtain one for
$\mathfrak{H}^{\otimes n}$ via

$\mathcal{E}^{n}=\\{E_{1}\otimes\cdots\otimes E_{n}\>:\>\text{ each
}E_{j}\in\mathcal{E}\\}.$

Equation (II.1) holds where we define $\omega$ on
$\mathcal{E}^{n}\times\mathcal{E}^{n}$ to be the product of the $\omega$ on
each component. In particular, for the Pauli group
$\omega(X^{\mathbf{a}}Z^{\mathbf{a}^{\prime}},X^{\mathbf{b}}Z^{\mathbf{b}^{\prime}})=\zeta^{\mathbf{a}^{\prime}\cdot\mathbf{b}-\mathbf{a}\cdot\mathbf{b}^{\prime}}$,
where $X^{\mathbf{a}}=X^{a_{1}}\otimes\cdots\otimes X^{a_{n}}$ and similarly
for the the other terms.

The weight of such an operator is the number of non-identity tensor factors it
contains, $\mathrm{wt}(E_{1}\otimes\cdots\otimes
E_{n})=|\\{r\>:\>E_{r}\not=I\\}|$. Write $\mathcal{E}^{n}[d]$ for the set of
weight $d$ operators in the error basis.

Given an error basis $\mathcal{E}$ on a Hilbert space $\mathcal{H}$, Shor and
Laflamme [2] define two quantum weight enumerators222We opt for the
normalization in [4] as opposed to that in [2], and take a different
convention in conjugate linearity. for a pair of Hermitian operators $M_{1}$
and $M_{2}$,

$\displaystyle A_{d}(M_{1},M_{2})$
$\displaystyle=\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(E^{\dagger}M_{1})\operatorname{Tr}(EM_{2}),$
(II.2) $\displaystyle B_{d}(M_{1},M_{2})$
$\displaystyle=\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(E^{\dagger}M_{1}EM_{2}).$
(II.3)

We will often drop $M_{1},M_{2}$ from this notation when they are understood.
While it is not obvious from this definition, both these values are invariant
under local unitary transformations. That is, if $U=U_{1}\otimes\cdots\otimes
U_{n}$ is any local unitary then

$A_{d}(UM_{1}U^{\dagger},UM_{2}U^{\dagger})=A_{d}(M_{1},M_{2})$

and similarly for $B_{d}$. For completeness, we provide a proof in §III but
will show this in a broader context in later sections.

######  Definition II.2.

The _weight enumerator polynomials_ $A$ and $B$ are

$\displaystyle A(z)$
$\displaystyle=\sum_{d=0}^{n}A_{d}z^{d}=\sum_{E\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}M_{1})\operatorname{Tr}(EM_{2})z^{\mathrm{wt}(E)}$
$\displaystyle B(z)$
$\displaystyle=\sum_{d=0}^{n}B_{d}z^{d}=\sum_{E\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}M_{1}EM_{2})z^{\mathrm{wt}(E)}.$

We will often find it useful to consider the enumerator polynomials in
homogeneous form:

$A(w,z)=w^{n}A(z/w)=\sum_{d=0}^{n}A_{d}(M_{1},M_{2})w^{n-d}z^{d},$

and similar for $B$. These two enumerators are not independent, being linked
by the quantum MacWilliams identity [2, 4]. In the case of
$\mathfrak{H}=(\mathbb{C}^{q})^{\otimes n}$ this reads:

$B(w,z)=A\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q}\right).$

We will provide a simple proof of this in §VI below, as a consequence of a
more general result.

For classical codes with an alphabet size greater than two, a so-called
complete enumerator may be constructed that also has desirable properties such
as a MacWilliams identity [1, 15]. Hu, Yang, and Yau [6] noted that quantum
codes can be viewed in this light. For each $R\in\mathcal{E}$ introduce a
weight function that counts the number of occurrences of $R$ as a factor,
$\mathrm{wt}_{R}(E_{1}\otimes\cdots\otimes E_{n})=|\\{r\>:\>E_{r}=R\\}|$ and
an indeterminate $u_{R}$. The complete enumerator polynomials are

$\displaystyle E(z)$
$\displaystyle=\sum_{G\in\mathcal{E}^{n}}\operatorname{Tr}(G^{\dagger}M_{1})\operatorname{Tr}(GM_{2})\prod_{R\in\mathcal{E}}u_{R}^{\mathrm{wt}_{R}(G)}$
$\displaystyle F(z)$
$\displaystyle=\sum_{G\in\mathcal{E}^{n}}\operatorname{Tr}(G^{\dagger}M_{1}GM_{2})\prod_{R\in\mathcal{E}}u_{R}^{\mathrm{wt}_{R}(G)}.$

Note that these polynomials are homogeneous of degree $n$. They are related to
the usual Shor-Laflamme enumerators by $A(w,z)=E(w,z,\dots,z)$ and
$B(w,z)=F(w,z,\dots,z)$.

In the case of the Pauli basis $\mathcal{P}$ of local dimension $q$, Hu, Yang,
and Yau also introduce a double enumerator [7]. We define $X$ and $Z$ weights
by

$\displaystyle\mathrm{wt}^{X}(P_{1}\otimes\cdots\otimes P_{n})$
$\displaystyle=|\\{j\>:\>P_{j}=X^{a}Z^{a^{\prime}}\text{ where }a\not=0\\}|$
$\displaystyle\mathrm{wt}^{Z}(P_{1}\otimes\cdots\otimes P_{n})$
$\displaystyle=|\\{j\>:\>P_{j}=X^{a}Z^{a^{\prime}}\text{ where
}a^{\prime}\not=0\\}|.$

For the Pauli group on $\mathbb{C}^{2}$ we have
$\mathrm{wt}^{X}(\sigma_{x})=\mathrm{wt}^{X}(\sigma_{y})=1$ and
$\mathrm{wt}^{Z}(\sigma_{y})=\mathrm{wt}^{Z}(\sigma_{z})=1$ (other values
being zero). The double enumerator polynomials are

$\displaystyle C(x,z)$
$\displaystyle=\sum_{P\in\mathcal{P}^{n}}\operatorname{Tr}(P^{\dagger}M_{1})\operatorname{Tr}(PM_{2})x^{\mathrm{wt}^{X}(P)}z^{\mathrm{wt}^{Z}(P)}$
$\displaystyle D(x,z)$
$\displaystyle=\sum_{P\in\mathcal{P}^{n}}\operatorname{Tr}(P^{\dagger}M_{1}PM_{2})x^{\mathrm{wt}^{X}(P)}z^{\mathrm{wt}^{Z}(P)}.$

To homogenize the double enumerators, we need to introduce two variables $w,y$
and define $C(w,x,y,z)=w^{n}y^{n}C(x/y,z/w)$ and similarly for $D$. That is,
we homogenize in bidegree $(n,n)$ where $y$ is the homogenizing variable for
$x$ and $w$ is that for $z$.

Both the double and complete enumerators are connected with versions of the
quantum MacWilliams identity [7]. Like the MacWilliams identity for the Shor-
Laflamme enumerators, these will follow from a more general approach given in
§VI.

##  III Scalar enumerators

Fix an error basis on a Hilbert space $\mathfrak{H}$. The scalars in our
theory are weight enumerator polynomials with respect to this basis. We will
focus on the Shor-Laflamme enumerator polynomials $A,B\in\mathbb{R}[w,z]$, but
most of our results also apply the double and complete enumerator polynomials
of Hu, Yang, and Yau, $C,D\in\mathbb{R}[w,x,y,z]$ and
$E,F\in\mathbb{R}[\\{u_{R}\\}]$.

Write $|E|$ for the support of $E$: the set of indices $j$ with $E_{j}\not=I$.
In particular, the weight of $E$ is the cardinality of $|E|$. Let
$U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary transformation on
$\mathfrak{H}^{\otimes n}$. Note $|U^{\dagger}EU|=|E|$ for any
$E\in\mathcal{E}^{n}$. As the elements of $\mathcal{E}^{n}$ form an orthogonal
basis (under trace-norm) for $\mathfrak{H}^{\otimes n}$ we can write

$U^{\dagger}EU=\frac{1}{q^{n}}\sum_{|F|=|E|}\operatorname{Tr}(U^{\dagger}EUF^{\dagger})F$

as the trace vanishes unless $|F|=|U^{\dagger}EU|=|E|$. Identically

$U^{\dagger}E^{\dagger}U=\frac{1}{q^{n}}\sum_{|F|=|E|}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)F^{\dagger}.$

######  Lemma III.1.

We have

$\displaystyle\frac{1}{q^{n}}\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)\operatorname{Tr}(U^{\dagger}EUG^{\dagger})$
$\displaystyle\qquad=\left\\{\begin{array}[]{cl}q^{n}&\text{ if
$F=G\in\mathcal{E}^{n}[d]$}\\\ 0&\text{ otherwise.}\end{array}\right.$

###### Proof.

From above, for any $E\in\mathcal{E}^{n}[d]$ we have

$\displaystyle q^{n}$
$\displaystyle=\operatorname{Tr}(I)=\operatorname{Tr}(E^{\dagger}E)$
$\displaystyle=\frac{1}{q^{2n}}\sum_{F,G\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)\operatorname{Tr}(U^{\dagger}EUG^{\dagger})\operatorname{Tr}(F^{\dagger}G)$
$\displaystyle=\frac{1}{q^{n}}\sum_{F\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)\operatorname{Tr}(U^{\dagger}EUF^{\dagger}).$

Exchanging the role of $E$ and $F$ in this final expression proves the claimed
result with $F=G\in\mathcal{E}^{n}[d]$. If $F=G$ but it is not in
$\mathcal{E}^{n}[d]$ then we have already seen
$\operatorname{Tr}(U^{\dagger}EUF^{\dagger})=0$ for any
$E\in\mathcal{E}^{n}[d]$.

Finally, if $F\not=G$ then similar to the above

$\displaystyle 0$
$\displaystyle=\operatorname{Tr}(FG^{\dagger})=\operatorname{Tr}(UFU^{\dagger}UG^{\dagger}U^{\dagger})$
$\displaystyle=\frac{1}{q^{2n}}\sum_{E_{1},E_{2}\in\mathcal{E}^{n}[d]}\operatorname{Tr}(UFU^{\dagger}E_{1}^{\dagger})\operatorname{Tr}(UG^{\dagger}U^{\dagger}E_{2})\operatorname{Tr}(E_{1}E_{2}^{\dagger})$
$\displaystyle=\frac{1}{q^{n}}\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(UFU^{\dagger}E^{\dagger})\operatorname{Tr}(UG^{\dagger}U^{\dagger}E)$
$\displaystyle=\frac{1}{q^{n}}\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)\operatorname{Tr}(U^{\dagger}EUG^{\dagger})$

as claimed. ∎

######  Theorem III.1.

Let $U$ be any local unitary on $\mathfrak{H}^{\otimes n}$. Then

$A(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})=A(z;M_{1},M_{2}).$

###### Proof.

We expand $M_{1}=\frac{1}{q^{n}}\sum_{F}\operatorname{Tr}(F^{\dagger}M_{1})F$
and similarly
$M_{2}=\frac{1}{q^{n}}\sum_{G}\operatorname{Tr}(GM_{2})G^{\dagger}$. Then from
the lemma,

$\displaystyle A(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle\quad=\sum_{d=0}^{n}\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UM_{1})\operatorname{Tr}(U^{\dagger}EUM_{2})z^{d}$
$\displaystyle\quad=\tfrac{1}{q^{2n}}\sum_{d=0}^{n}\sum_{F,G}\sum_{E\in\mathcal{E}^{n}[d]}\operatorname{Tr}(U^{\dagger}E^{\dagger}UF)\operatorname{Tr}(U^{\dagger}EUG^{\dagger})$
$\displaystyle\quad\qquad\qquad\cdot\operatorname{Tr}(F^{\dagger}M_{1})\operatorname{Tr}(GM_{2})z^{d}$
$\displaystyle\quad=\sum_{d=0}^{n}\sum_{F\in\mathcal{E}^{n}_{d}}\operatorname{Tr}(F^{\dagger}M_{1})\operatorname{Tr}(FM_{2})z^{d}=A(z;M_{1},M_{2}).$

∎

One could provide a similar proof for the invariance of $B$, however this
follows immediately from the quantum MacWilliams identity:

$\displaystyle B(w,z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle=A\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};UM_{1}U^{\dagger},UM_{2}U^{\dagger}\right)$
$\displaystyle=A\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2}\right)$
$\displaystyle=B(w,z;M_{1},M_{2}).$

Note that none of $C$, $D$, $E$, or $F$ are locally unitarily invariant as
they depend on counting specific Pauli operators in each factor.

######  Lemma III.2.

We have

$A(z;M_{1}\otimes M_{1}^{\prime},M_{2}\otimes
M_{2}^{\prime})=A(z;M_{1},M_{2})\cdot A(z;M_{1}^{\prime},M_{2}^{\prime})$

and similarly for $B,C,D,E,F$.

###### Proof.

Note that weights are additive in the sense that if $\mathrm{wt}(E_{1})=d_{1}$
and $\mathrm{wt}(E_{2})=d_{2}$ then $\mathrm{wt}(E_{1}\otimes
E_{2})=d_{1}+d_{2}$. Then

$\displaystyle A(z;M_{1},M_{2})\cdot A(z;M_{1}^{\prime},M_{2}^{\prime})$
$\displaystyle\
=\left(\sum_{E_{1}}\operatorname{Tr}(E_{1}^{\dagger}M_{1})\operatorname{Tr}(E_{1}M_{1}^{\prime})z^{\mathrm{wt}(E_{1})}\right)$
$\displaystyle\qquad\cdot\left(\sum_{E_{2}}\operatorname{Tr}(E_{2}^{\dagger}M_{2})\operatorname{Tr}(E_{2}M_{2}^{\prime}))z^{\mathrm{wt}(E_{2})}\right)$
$\displaystyle\ =\sum_{E_{1},E_{2}}\operatorname{Tr}((E_{1}\otimes
E_{2})^{\dagger}(M_{1}\otimes M_{2}))$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}((E_{1}\otimes
E_{2})(M_{1}^{\prime}\otimes
M_{2}^{\prime}))z^{\mathrm{wt}(E_{1})+\mathrm{wt}(E_{2})}$
$\displaystyle=A(z;M_{1}\otimes M_{1}^{\prime},M_{2}\otimes M_{2}^{\prime}).$

The proofs for $B,C,D,E,F$ are similar and so omitted. ∎

######  Example III.1 ([2]).

Let $\Pi_{\mathcal{C}}$ be the projection onto $[[n,k]]$ binary stabilizer
code $\mathfrak{C}$, and write $\mathcal{S}=\mathcal{S}(\mathcal{C})=\langle
S_{1},\dots,S_{n-k}\rangle$ for its stabilizer group. Then

$\Pi_{\mathcal{C}}=\frac{1}{2^{n-k}}\prod_{j=1}^{n-k}(I+S_{j})=\frac{1}{2^{n-k}}\sum_{S\in\mathcal{S}}S.$

For any Pauli operator $P\in\mathcal{P}^{n}$ we have

$\sum_{S\in\mathcal{S}}\operatorname{Tr}(PS)=\left\\{\begin{array}[]{cl}2^{n}&\text{
if $P\in\mathcal{S}$,}\\\ 0&\text{otherwise.}\end{array}\right.$

Therefore

$A_{d}=\frac{1}{4^{n-k}}\sum_{P\in\mathcal{P}^{n}[d]}\sum_{S,S^{\prime}\in\mathcal{S}}\operatorname{Tr}(PS)\operatorname{Tr}(PS^{\prime})=4^{k}\cdot\left|\mathcal{E}_{d}\cap\mathcal{S}\right|.$

That is, properly normalized, the weight enumerator

$\frac{1}{4^{k}}\cdot
A(z;\mathfrak{C})=\sum_{d=0}^{n}\left|\mathcal{P}^{n}[d]\cap\mathcal{S}\right|z^{d}$

counts the number of stabilizers of each weight.

If a Pauli operator $P\in\mathcal{N}=\mathcal{N}(\mathfrak{C})$ (the
normalizer of the code) then $P\Pi_{\mathfrak{C}}=\Pi_{\mathfrak{C}}P$ and so

$\operatorname{Tr}(P\Pi_{\mathfrak{C}}P\Pi_{\mathfrak{C}})=\operatorname{Tr}(\Pi_{\mathfrak{C}})=2^{k}.$

On the other hand, if $P\not\in\mathcal{N}$ then there is some $j_{0}$ where
$PS_{j_{0}}=-S_{j_{0}}P$. Thus

$P\Pi_{\mathfrak{C}}P\Pi_{\mathfrak{C}}\propto(I-S_{j_{0}})(I+S_{j_{0}})\prod_{j\not=j_{0}}(I\pm
S_{j})(I+S_{j})=0.$

Therefore

$B_{d}=\sum_{P\in\mathcal{P}^{n}[d]}\operatorname{Tr}(P\Pi_{\mathfrak{C}}P\Pi_{\mathfrak{C}})=2^{k}\cdot\left|\mathcal{E}_{d}\cap\mathcal{N}\right|,$

and

$\frac{1}{2^{k}}B(z;\mathfrak{C})=\sum_{d=0}^{n}\left|\mathcal{P}^{n}[d]\cap\mathcal{N}\right|z^{d}$

counts the number of normalizers of each weight. Hence, the distance of the
code $\mathfrak{C}$ is the smallest $d$ such that $A_{d}\not=B_{d}$.

Note that the above example carries over to $q$-ary stabilizer codes [16],
adjusting the normalization appropriately. The double and complete weight
enumerators further refine this information allowing separate analysis of $X$
and $Z$ errors [17, 18, 19].

######  Lemma III.3.

Let $\Pi=|{\psi}\rangle\langle{\psi}|$ be the projector onto any state. Then
$A(z;\Pi)=B(z;\Pi)$.

###### Proof.

For each $d=0,\dots,n$

$\displaystyle B_{d}$
$\displaystyle=\sum_{E\in\mathcal{E}_{d}}\operatorname{Tr}(E^{\dagger}|{\psi}\rangle\langle{\psi}|E|{\psi}\rangle\langle{\psi}|)=\sum_{E\in\mathcal{E}_{d}}|\langle{\psi}|E|{\psi}\rangle|^{2}$
$\displaystyle=\sum_{E\in\mathcal{E}_{d}}\operatorname{Tr}(E^{\dagger}|{\psi}\rangle\langle{\psi}|)\operatorname{Tr}(E|{\psi}\rangle\langle{\psi}|)=A_{d}.$

∎

######  Definition III.1.

Let $\mathfrak{C}$ be a $[[n,k]]$ quantum code. Its _encoding tensor_ is the
(unnormalized) Choi state

$|{T_{\mathfrak{C}}}\rangle=\sum_{x\in\mathbb{F}_{2}^{k}}|{x_{L}}\rangle\otimes|{x}\rangle=\sum_{x\in\mathbb{F}_{2}^{k}}U(|{x}\rangle\otimes|{0}\rangle^{\otimes(n-k)})\otimes|{x}\rangle,$

where $U$ is the unitary encoding map of the code.

######  Theorem III.2.

Let $\mathfrak{C}$ be a $[[n,1]]$-stabilizer code,
$|{T_{\mathfrak{C}}}\rangle$ its encoding tensor, and
$\Pi=|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|$. Then

$A_{d}(\Pi)=\tfrac{1}{4}A_{d}(\mathfrak{C})+\tfrac{1}{2}B_{d-1}(\mathfrak{C})-\tfrac{1}{4}A_{d-1}(\mathfrak{C}).$

In particular, the distance of the code is the smallest $d$ such that
$A_{d+1}(\Pi)>\tfrac{1}{4}A_{d+1}(\mathfrak{C})$.

###### Proof.

First note that the normalizer of the code is the disjoint union

$\mathcal{N}(\mathfrak{C})=\mathcal{S}(\mathfrak{C})\cup\bar{X}\mathcal{S}(\mathfrak{C})\cup\bar{Y}\mathcal{S}(\mathfrak{C})\cup\bar{Z}\mathcal{S}(\mathfrak{C})$

where $\bar{X},\bar{Y},\bar{Z}$ are any choice of representations for the
logical Pauli operators. Recall that
$\frac{1}{2}B_{d}(\mathfrak{C})=|\mathcal{N}(\mathfrak{C})\cap\mathcal{E}_{d}|$
and
$\frac{1}{4}A_{d}(\mathfrak{C})=|\mathcal{S}(\mathfrak{C})\cap\mathcal{E}_{d}|$,
and so the number of proper logical operators of weight $d$ is
$\tfrac{1}{2}B_{d}(\mathfrak{C})-\tfrac{1}{4}A_{d}(\mathfrak{C})$.

The encoding tensor state $|{T_{\mathfrak{C}}}\rangle$ is a stabilizer state
(namely a $[[n+1,0]]$-stabilizer code). If we write the unencoded qubit as the
$(n+1)^{\text{st}}$ qubit of the state, the stabilizers of this state form the
disjoint union

$\displaystyle\mathcal{S}(|{T_{\mathfrak{C}}}\rangle)$
$\displaystyle=(\mathcal{S}(\mathfrak{C})\otimes
I)\cup(\bar{X}\mathcal{S}(\mathfrak{C})\otimes X)$
$\displaystyle\qquad\cup(-\bar{Y}\mathcal{S}(\mathfrak{C})\otimes
Y)\cup(\bar{Z}\mathcal{S}(\mathfrak{C})\otimes Z)$

where we have abused notation slightly to write, say,
$\bar{X}\mathcal{S}(\mathfrak{C})\otimes X=\\{\bar{X}S\otimes
X\>:\>S\in\mathcal{S}(\mathfrak{C})\\}$. The weight $d$ elements of
$\mathcal{S}(\mathfrak{C})\otimes I$ are naturally bijective with those of
$\mathcal{S}(\mathfrak{C})$, of which there are
$\frac{1}{4}A_{d}(\mathfrak{C})$ of them. The weight $d$ elements of
$\bar{X}\mathcal{S}(\mathfrak{C})\otimes X$ are naturally bijective with the
weight $d-1$ elements of $\bar{X}\mathcal{S}(\mathfrak{C})$, and similarly for
$\bar{Y}$ and $\bar{Z}$. Hence there are
$\tfrac{1}{2}B_{d-1}(\mathfrak{C})-\tfrac{1}{4}A_{d-1}(\mathfrak{C})$ of these
in total. ∎

To illustrate this theorem, consider the perfect $[[5,1,3]]$ code and its
encoding tensor, which is the perfect $[[6,0,4]]$ tensor, that play a
prominent role in the constructions of [20],

$\displaystyle\tfrac{1}{4}\cdot A_{[[5,1,3]]}(z)$ $\displaystyle=1+15z^{4},$
$\displaystyle\tfrac{1}{2}\cdot B_{[[5,1,3]]}(z)$
$\displaystyle=1+30z^{3}+15z^{4}+18z^{5}$ $\displaystyle A_{[[6,0,4]]}(z)$
$\displaystyle=1+45z^{4}+18z^{6}.$

Clearly this theorem cannot not hold for $k>1$. In fact, one would not expect
any natural extension of this result to $k>1$ using the scalar enumerators we
have discussed above. Consider for instance $k=2$; the encoding tensor will be
stabilized by sets of operators
$(\bar{X}\otimes\bar{I})\mathcal{S}(\mathfrak{C})\otimes X\otimes I$ and
$(\bar{X}\otimes\bar{Y})\mathcal{S}(\mathfrak{C})\otimes X\otimes Y$, among
others. In weight $d$, operators in the first set are counted in
$B_{d}(\mathcal{C})$ and $A_{d+1}(\Pi)$ while those in the second set are also
counted in $B_{d}(\mathcal{C})$ but in $A_{d+2}(\Pi)$. Hence to obtain such a
result as in the theorem, we would need to know how to decompose
$B_{d}(\mathcal{C})$ into counts of logical operators based on the weight of
the logical operator they represent. To illustrate this point, consider the
$2\times 2$ Bacon-Shor codes as a $[[4,2,2]]$ stabilizer code, and it encoding
tensor as a $[[6,0,3]]$ stabilizer state, that play a prominent role in the
constructions of [8],

$\displaystyle\tfrac{1}{16}A_{[[4,2,2]]}(z)$ $\displaystyle=1+3z^{4},$
$\displaystyle\tfrac{1}{4}B_{[[4,2,2]]}(z)$
$\displaystyle=1+18z^{2}+24z^{3}+21z^{4},$ $\displaystyle A_{[[6,0,3]]}(z)$
$\displaystyle=1+8z^{3}+21z^{4}+24z^{5}+10z^{6}.$

Nonetheless, as
$A(w,z;|{\psi}\rangle\langle{\psi}|)=B(w,z;|{\psi}\rangle\langle{\psi}|)$ we
have the $A$-enumerator of an encoding tensor (or rank-one projection in
general) is invariant under the quantum MacWilliams transform, akin to the
situation of classical self-dual codes. Thus enumerator polynomials of
encoding tensors cannot be arbitrary, but must lie in the invariant ring of
the group

$G=\left\langle\frac{1}{q}\left(\begin{array}[]{cc}1&q^{2}-1\\\
1&-1\end{array}\right)\right\rangle.$

As $|G|=2$ this ring is trivial to compute and we conclude

$A(w,z;\Pi)\in\mathbb{R}[w+(q-1)z,w^{2}+(q-2)wz+(q^{2}-q+1)z^{2}].$

In the case of $q=2$, we can make this more explicit as

$\displaystyle A(w,z;|{0}\rangle\langle{0}|)=w+z,$ $\displaystyle
A(w,z;|{\beta}\rangle\langle{\beta}|)=w^{2}+3z^{2},$

where $\beta=\frac{1}{\sqrt{2}}(|{00}\rangle+|{11}\rangle)$ is the Bell state.
That is, the enumerator polynomial of any state lies in the ring freely
generated by the enumerators of a one-qubit state and a maximally entangled
two-qubit state.

Still working with $q=2$, we refine this somewhat for codes whose encoding
tensors are “even” in the sense that all their stabilizers have even Hamming
weight, such as the Bell state or the $[[6,0,4]]$ tensor as shown above. Then,
the enumerator lies in the invariant ring of

$\left\langle\frac{1}{2}\left(\begin{array}[]{cc}1&3\\\
1&-1\end{array}\right),\left(\begin{array}[]{cc}1&0\\\
0&-1\end{array}\right)\right\rangle,$

which is isomorphic to the dihedral group $D_{6}$. Again this has small order,
so the invariant ring is easily computed using the algebraic software Sage
[21], yielding for any projector onto any even encoding tensor

$\displaystyle A(w,z;\Pi)$
$\displaystyle\in\mathbb{R}[w^{2}+3z^{2},w^{6}+15w^{4}z^{2}+15w^{2}z^{4}+33z^{6}]$
$\displaystyle\quad=\mathbb{R}[A(w,z;|{\beta}\rangle\langle{\beta}|),\
A(w,z;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)]$

where $|{T_{\mathfrak{C}}}\rangle$ is the encoding tensor of the code
$\mathfrak{C}$ with stabilizer group $\mathcal{S}(\mathfrak{C})=\langle
YYIII,YIYII,YIIYI,YIIIY\rangle$.

##  IV Vector enumerators

Ultimately, we will be interested in “tensor” enumerators, which are tensors
whose coefficients are scalar enumerators as above. We find it illuminating to
first start with the case of vector enumerators, which are single index tensor
enumerators. In our first two results, we will see these do not behave like
vectors, in that local unitary action transforms the vector via an adjoint
representation, and that vector enumerators support a natural trace operation
to scalar enumerators. Hence a vector enumerator will be presented as the
coefficients of a matrix, whose rows and columns are indexed by the elements
of our unitary basis $\mathcal{E}$.

Formally, let $\mathcal{E}$ be an error basis on $\mathfrak{H}$, and as before
write $\mathcal{E}^{n-1}=\\{E_{1}\otimes\dots\otimes
E_{n-1}\>:\>E_{1},\dots,E_{n-1}\in\mathcal{E}\\}$ and
$\mathcal{E}^{n-1}[d]=\\{E\in\mathcal{E}^{n-1}\>:\>\mathrm{wt}(E)=d\\}$. Fix a
“leg” $j\in\\{1,\dots,n\\}$ and for $E\in\mathcal{E}$ and
$F\in\mathcal{E}^{n-1}$ define

$E\otimes_{j}F=F_{1}\otimes\cdots\otimes F_{j-1}\otimes E\otimes
F_{j}\otimes\cdots F_{n-1}\in\mathcal{E}^{n}.$

That is, $E\otimes_{j}F$ has $E$ is inserted as the $j$-th factor into $F$.
For a pair of elements of this basis $(E,E^{\prime})$ define weights

$\displaystyle A^{(j)}_{d}(E,E^{\prime};M_{1},M_{2})$ (IV.1)
$\displaystyle\quad=\sum_{F\in\mathcal{E}^{n-1}[d]}\operatorname{Tr}((E\otimes_{j}F)^{\dagger}M_{1})\operatorname{Tr}((E^{\prime}\otimes_{j}F)M_{2}),$
$\displaystyle B^{(j)}_{d}(E,E^{\prime};M_{1},M_{2})$ (IV.2)
$\displaystyle\quad=\sum_{F\in\mathcal{E}^{n-1}[d]}\operatorname{Tr}((E\otimes_{j}F)^{\dagger}M_{1}(E^{\prime}\otimes_{j}F)M_{2}).$

These enumerators are related to the usual $A$-weight (II.2) and $B$-weight
(II.3) of $M_{1}$ and $M_{2}$, refined by specifying the error operators
$E,E^{\prime}$ that appear in factor $j$. Note that the weights of the
operators $E$ and $E^{\prime}$ do not contribute to $A^{(j)}_{d}$ or
$B^{(j)}_{d}$.

These enumerators are indexed by $(E,E^{\prime})$ and so may be viewed as the
coefficients of a matrix. Let $e_{E,E^{\prime}}$ be the matrix unit, which is
$1$ in $(E,E^{\prime})$ position and zero elsewhere. Write
$V=\mathrm{span}_{\mathbb{R}}\\{e_{E,E^{\prime}}\>:\>E,E^{\prime}\in\mathcal{E}\\}$
for this matrix space.

######  Definition IV.1.

The _vector enumerators_ of “leg” $j$ are

$\displaystyle\mathbf{A}^{(j)}(z;M_{1},M_{2})$
$\displaystyle=\sum_{E,E^{\prime}\in\mathcal{E}}\sum_{d=0}^{n}A^{(j)}_{d}(E,E^{\prime};M_{1},M_{2})z^{d}e_{E,E^{\prime}},$
$\displaystyle\mathbf{B}^{(j)}(z;M_{1},M_{2})$
$\displaystyle=\sum_{E,E^{\prime}\in\mathcal{E}}\sum_{d=0}^{n}B^{(j)}_{d}(E,E^{\prime};M_{1},M_{2})z^{d}e_{E,E^{\prime}},$

where $A^{(j)}_{d}$ and $B^{(j)}_{d}$ are defined in (IV.1) and (IV.2).

These enumerators are elements of $\mathbb{R}[z]\otimes_{\mathbb{R}}V$, which
is to say vectors in $V$ whose coefficients are real polynomials in $z$. We
can trace vector enumerators down to scalar enumerators, which is captured in
the following result, whose proof is obvious.

######  Lemma IV.1.

Consider
$\widetilde{\mathrm{tr}}:\mathbb{R}[z]\otimes_{\mathbb{R}}V\to\mathbb{R}[z]$
by linearly extending

$\widetilde{\mathrm{tr}}(e_{E,E^{\prime}})=\left\\{\begin{array}[]{cl}1&\text{
if $E=E^{\prime}=I$,}\\\ z&\text{ if $E=E^{\prime}\not=I$,}\\\ 0&\text{ if
$E\not=E^{\prime}$.}\end{array}\right.$

Then $\widetilde{\mathrm{tr}}(\mathbf{A}^{(j)}(z))=A(z)$ and
$\widetilde{\mathrm{tr}}(\mathbf{B}^{(j)}(z))=B(z)$.

Note that vector enumerators are not invariant under local unitary operations.
Rather, they are covariant with respect to an adjoint, or “Bloch sphere”
style, representation of unitaries on $V$. Specifically, let $U$ be a unitary
on $\mathfrak{H}$ and define $c_{EF}\in\mathbb{C}$ by
$U^{\dagger}EU=\sum_{G}Gc_{GE}$, where
$c_{GE}=\frac{1}{q}\operatorname{Tr}(U^{\dagger}EUG^{\dagger})$. We also have
$U^{\dagger}E^{\dagger}U=\sum_{G}G^{\dagger}c^{*}_{GE}$, and
$UEU^{\dagger}=\sum_{G}c^{*}_{EG}G$ and
$UE^{\dagger}U^{\dagger}=\sum_{G}c_{EG}G^{\dagger}$. Now define the action of
$U$ on the matrix space $V$ by

$\Lambda(U)(e_{E,E^{\prime}})=\sum_{G,G^{\prime}}c^{*}_{EG}c_{E^{\prime}G^{\prime}}e_{G,G^{\prime}}.$

We will formalize this in the next section. In particular, the following
result is a special case of Theorem V.1 below and so we do not provide a proof
here.

######  Theorem IV.1.

Let $U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary operator. Then

$\mathbf{A}^{(j)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})=\Lambda(U_{j})\left(\mathbf{A}^{(j)}(z;M_{1},M_{2})\right).$

Just as scalar enumerators, vector enumerators behave nicely under tensor
product. We state this formally as follows. Again, the proof of this result
follows immediately from the general case of tensor enumerators, Proposition
V.3, and so is omitted.

######  Proposition IV.1.

Let $M_{1}\otimes N_{1}$ and $M_{2}\otimes N_{2}$ be Hermitian operators on
$\mathfrak{H}\otimes\mathfrak{K}$ where
$\mathfrak{H}=\bigotimes_{j=1}^{n}\mathfrak{H}_{j}$ and
$\mathfrak{K}=\bigotimes_{k=1}^{m}\mathfrak{K}_{k}$. Then for $j=1,\dots,n$ we
have

$\displaystyle\mathbf{A}^{(j)}(z;M_{1}\otimes N_{1},M_{2}\otimes N_{2})$
$\displaystyle\qquad=\mathbf{A}^{(j)}(z;M_{1},M_{2})A(z;N_{1},N_{2}).$

and for $j=n+1,\dots,n+m$ we have

$\displaystyle\mathbf{A}^{(j)}(z;M_{1}\otimes N_{1},M_{2}\otimes N_{2})$
$\displaystyle\qquad=A(z;M_{1},M_{2})\mathbf{A}^{(j-n)}(z;N_{1},N_{2}).$

Analogous formulas hold for $\mathbf{B}^{(j)}$ and $B$.

When $M_{1}=M_{2}=\Pi_{\mathfrak{C}}$ the projection onto a binary stabilizer
code $\mathfrak{C}$, the vector enumerators carry refined information about
the structure of the stabilizer and normalizer groups of $\mathfrak{C}$. In
general, vector enumerators are matrices, however as long as the underlying
code has distance $d\geq 2$ these matrices are diagonal except in a degenerate
case (see Theorem IV.2 below). The coefficients along the diagonal are
polynomials that are themselves are a form of scalar enumerator. For
$P=I,X,Y,Z$, the coefficient of $e_{P,P}$ in $\mathbf{A}^{(j)}$ (respectively
$\mathbf{B}^{(j)}$) counts the number of stabilizers (respectively logical
operators) of each weight with the side condition that its $j^{\text{th}}$
factor is $P$.

######  Example IV.1.

Consider the vector enumerator of the logical leg in an encoding of a
$[[n,1]]$ binary stabilizer code $\mathfrak{C}$. Recall from the proof of
Theorem III.2 above that if $|{T_{\mathfrak{C}}}\rangle$ is the encoding
state, then the stabilizer of this state is the disjoint union

$\displaystyle\mathcal{S}(|{T_{\mathfrak{C}}}\rangle)$
$\displaystyle=(\mathcal{S}(\mathfrak{C})\otimes
I)\cup(\bar{X}\mathcal{S}(\mathfrak{C})\otimes X)$
$\displaystyle\qquad\cup(-\bar{Y}\mathcal{S}(\mathfrak{C})\otimes
Y)\cup(\bar{Z}\mathcal{S}(\mathfrak{C})\otimes Z)$

and the projection onto this state is

$\displaystyle|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|$
$\displaystyle=\frac{1}{2^{n+1}}\sum_{S\in\mathcal{S}(\mathfrak{C})}S\otimes
I+\bar{X}S\otimes X$ $\displaystyle\qquad\qquad\qquad-\bar{Y}S\otimes
Y+\bar{Z}S\otimes Z.$

Now, for any $P=I,X,Y,Z$ we have

$\operatorname{Tr}((F\otimes
P)|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)=\left\\{\begin{array}[]{cl}\pm
1&\text{if $F\in\bar{P}\mathcal{S}(\mathfrak{C})$}\\\
0&\text{otherwise.}\end{array}\right.$

Therefore

$\displaystyle\mathbf{A}^{(n+1)}(z;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)$
$\displaystyle\qquad=\sum_{P=I,X,Y,Z}\sum_{d=0}^{n}|\bar{P}\mathcal{S}(\mathfrak{C})\cap\mathcal{E}^{n}_{d}|z^{d}e_{P,P}.$

In particular,

$\displaystyle A(\mathfrak{C})$
$\displaystyle=\mathbf{A}^{(n+1)}(I,I;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)\text{
and }$ $\displaystyle B(\mathfrak{C})$
$\displaystyle=\sum_{P=I,X,Y,Z}\mathbf{A}^{(n+1)}(P,P;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|).$

######  Lemma IV.2.

Let $\mathfrak{C}$ be a $[[n,k]]$ stabilizer code. Then for
$P\not=P^{\prime}\in\mathcal{P}$,

  1. 1.

$\mathbf{A}^{(j)}(P,P^{\prime})$ is nonzero if and only if
$PP^{\prime}\otimes_{j}I^{\otimes(n-1)}$ is a stabilizer;

  2. 2.

$\mathbf{B}^{(j)}(P,P^{\prime})$ is nonzero if and only if
$\mathbf{A}^{(j)}(P,P^{\prime})$ is nonzero.

###### Proof.

Recall that if $\Pi=\frac{1}{2^{n-k}}\sum_{S\in\mathcal{S}(\mathfrak{C})}S$ is
the projector onto the code space, then
$\operatorname{Tr}((P\otimes_{j}Q)\Pi)\not=0$ if and only if
$P\otimes_{j}Q\in\mathcal{S}(\mathfrak{C})$. Now
$\mathbf{A}^{(j)}(P,P^{\prime})$ is nonzero if and only if there exists some
$Q\in\mathcal{P}^{n-1}$ such that

$\operatorname{Tr}((P\otimes_{j}Q)\Pi)\operatorname{Tr}((P^{\prime}\otimes_{j}Q)\Pi)\not=0,$

and hence both
$(P\otimes_{j}Q),(P^{\prime}\otimes_{j}Q)\in\mathcal{S}(\mathfrak{C})$ and so
is their product $PP^{\prime}\otimes_{j}I^{\otimes(n-1}$.

Now $\mathbf{B}^{(j)}(P,P^{\prime})\not=0$ if and only if there is a $Q$ such
that

$\operatorname{Tr}((P\otimes_{j}Q)\Pi(P^{\prime}\otimes_{j}Q)\Pi)\not=0,$

which happens if and only if $(P\otimes_{j}Q)\in\mathcal{N}(\mathfrak{C})$,
and

$(P\otimes_{j}Q)(P^{\prime}\otimes_{j}Q)=(PP^{\prime}\otimes_{j}I^{\otimes(n-1})\in\mathcal{S}(\mathfrak{C}).$

∎

######  Theorem IV.2.

Let $\mathfrak{C}$ be a $[[n,k,d]]$ stabilizer code of distance $d\geq 2$.
Then every for every $j=1,\dots,n$ we have either:

  1. 1.

there is a Pauli operator $P$ and code $\mathfrak{C}^{\prime}$ such that

$\displaystyle\mathbf{A}^{(j)}(\mathfrak{C})$
$\displaystyle=A(\mathfrak{C}^{\prime})\cdot(e_{I,I}+e_{I,P}+e_{P,I}+e_{P,P}),$
$\displaystyle\mathbf{B}^{(j)}(\mathfrak{C})$
$\displaystyle=B(\mathfrak{C}^{\prime})\cdot(e_{I,I}+e_{I,P}+e_{P,I}+e_{P,P});$

  2. 2.

or $\mathbf{A}^{(j)}(\mathfrak{C})$ and $\mathbf{B}^{(j)}(\mathfrak{C})$ are
diagonal.

###### Proof.

From the lemma, if $\mathbf{A}^{(j)}(\mathfrak{C})$ has off-diagonal terms
then $P\otimes_{j}I^{\otimes(n-1)}\in\mathcal{S}(\mathfrak{C})$ for some $P$.
This implies $\mathfrak{C}=|{\psi}\rangle\otimes_{j}\mathfrak{C}^{\prime}$
where $|{\psi}\rangle$ is the $+1$-eigenstate of $P$ and
$\mathfrak{C}^{\prime}$ is a $(n-1)$-qubit stabilizer code. By Proposition
IV.1 we have
$\mathbf{A}^{(j)}(\mathfrak{C})=\mathbf{A}^{(j)}(|{\psi}\rangle\langle{\psi}|)A(\mathfrak{C}^{\prime})$
and
$\mathbf{B}^{(j)}(\mathfrak{C})=\mathbf{B}^{(j)}(|{\psi}\rangle\langle{\psi}|)B(\mathfrak{C}^{\prime})$,
and it is straightforward to show

$\mathbf{A}^{(j)}(|{\psi}\rangle\langle{\psi}|)=\mathbf{B}^{(j)}(|{\psi}\rangle\langle{\psi}|)=e_{I,I}+e_{I,P}+e_{P,I}+e_{P,P}.$

∎

Recall the “cleaning lemma” [22, Lemma 1] relates the supports of logical
Pauli operators on a stabilizer code. It states: for any subset of qubits $J$
either there exists a nontrivial logical Pauli operators supported on $J$, or
every logical Pauli operator has a representation is that is trivial on $J$
(that is it can be “cleaned” from $J$). In particular, if $|J|<d$, the
distance of the code, then no nontrivial logical operator can be supported on
$J$. Thus any subset of qubits of size less than the distance of the code can
be cleaned. We are interested in a stronger notion of cleaning: every Pauli
operator on $J$ extends to a stabilizer of the code. As there are $4^{|J|}$
Pauli operators on $J$ but only $2^{n-k}$ stabilizers, we must have
$|J|\leq\frac{1}{2}(n-k)$. In this case, we can clean logical operators from
$J$ as follows: given any logical Pauli operator $L$, we take the Pauli
operator on $J$ given by $\left.L\right|_{J}$, and extend this to a stabilizer
$S$. Then $LS$ is equivalent to $L$ and trivial on $J$.

######  Corollary IV.1.

Let $\mathfrak{C}$ be a stabilizer code and $|{T_{\mathfrak{C}}}\rangle$ its
encoding tensor. Then for any logical qubit $j$ we have
$\mathbf{A}^{(j)}(|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)$ is
diagonal.

###### Proof.

By construction, along every logical leg $j$ every local Pauli operator gives
rise to a stabilizer of $|{T_{\mathfrak{C}}}\rangle$, and thus logical legs
can be cleaned. Moreover, these stabilizers are not of the form
$P\otimes_{j}I^{\otimes(n-1)}$ and therefore in the theorem we are in the case
of $\mathbf{A}^{(j)}(|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|)$
being diagonal. ∎

######  Definition IV.2.

The _reduced_ enumerator $\tilde{\mathbf{A}}^{(j)}$ is the diagonal of
$\mathbf{A}^{(j)}$. Namely, if
$\textbf{A}^{(j)}=\sum_{E,E^{\prime}}\sum_{d=0}^{n-1}A^{(j)}_{d}(E,E^{\prime})z^{d}e_{E,E^{\prime}}$
then

$\tilde{\textbf{A}}^{(j)}=\sum_{E}\sum_{d=0}^{n-1}A^{(j)}_{d}(E)z^{d}e_{E,E}.$

Identically, $\tilde{\mathbf{B}}^{(j)}$ is the restriction of
$\textbf{B}^{(j)}$ to the diagonal.

The content of the above theorem can be captured as: if $d\geq 2$ then, except
in a trivial case, $\textbf{A}^{(j)}=\tilde{\textbf{A}}^{(j)}$ (and similarly
$\textbf{B}^{(j)}=\tilde{\textbf{B}}^{(j)}$) for each $j=1,\dots,n$. To
simplify the notation, we will write $e_{E}=e_{E,E}$ when working with reduced
enumerators.

Next we present the analogue of the quantum MacWilliams identity for vector
enumerators. This theorem is a special case of that for tensor enumerators and
hence we omit the proof. We hasten to point out that the components of
$\mathbf{A}^{(j)}$ and $\mathbf{B}^{(j)}$ are polynomials of degree at most
$n-1$, hence their homogenization are of degree exactly $n-1$. That the
overall degree is one less than that of the scalar enumerators is the genesis
of an additional factor of $\frac{1}{q}$, which has been incorporated into the
map $\Psi$.

######  Theorem IV.3.

For an error basis $\mathcal{E}$ on $\mathfrak{H}=\mathbb{C}^{q}$ and
$M_{1},M_{2}$ being Hermitian operators on $\mathfrak{H}^{\otimes n}$, each
leg $j=1,\dots,n$ has

$\mathbf{B}^{(j)}(w,z;M_{1},M_{2})=\Psi\left[\mathbf{A}^{(j)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2})\right]$

where
$\Psi(e_{E,E^{\prime}})=\frac{1}{q^{2}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})e_{F,F^{\prime}}$.

While this theorem focuses on vector enumerator analogues of the Shor-Laflamme
enumerator polynomials, there are vector enumerator extensions of the double
and complete enumerators by Hu, Yang, and Yau, $C$, $D$, $E$, and $F$.
Similarly $\mathbf{C}^{(j)}$ and $\mathbf{D}^{(j)}$, and $\mathbf{E}^{(j)}$
and $\mathbf{F}^{(j)}$, are related by MacWilliams identities. The form of
these identities, and their proofs, is covered in §VI below.

Note that the diagonal elements $e_{E,E}$ are left invariant under $\Psi$.
Namely we compute

$\displaystyle\Psi(e_{E,E})$
$\displaystyle=\tfrac{1}{q^{2}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}EF^{\prime}E^{\dagger})e_{F,F^{\prime}}$
$\displaystyle=\tfrac{1}{q^{2}}\sum_{F,F^{\prime}}\omega(E,F^{\prime})\operatorname{Tr}(F^{\dagger}F^{\prime})e_{F,F^{\prime}}$
$\displaystyle=\tfrac{1}{q}\sum_{F}\omega(E,F)e_{F,F}.$

This is the discrete Wigner transform on $\mathcal{E}$, and hence we have the
following result.

######  Corollary IV.2.

Let $\mathcal{E}$ be an error basis on $\mathfrak{H}=(\mathbb{C}^{q})$. Then
for any Hermitian operators $M_{1},M_{2}$ on $\mathfrak{H}^{\otimes n}$ and
leg $j=1,\dots,q$ we have

$\tilde{\mathbf{B}}^{(j)}(w,z;M_{1},M_{2})=\Psi\left[\tilde{\mathbf{A}}^{(j)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2})\right]$

where $\Psi(e_{E})=\tfrac{1}{q}\sum_{F\in\mathcal{E}}\omega(E,F)e_{F}$ is the
discrete Wigner transform on $\mathcal{E}$.

The vector analogue of the quantum MacWilliams identity above allows us prove
that the vector enumerators $\mathbf{B}^{(j)}$ behave contravariantly,
analogous to the covariance Theorem IV.1 above for $\mathbf{A}^{(j)}$.

######  Lemma IV.3.

$\Psi\circ\Lambda(U)=\Lambda(U^{\dagger})\circ\Psi$ for any unitary $U$.

###### Proof.

By direct computation:

$\displaystyle\Psi\left[\Lambda(U)(e_{E,E^{\prime}}))\right]=\sum_{G,G^{\prime}}c_{EG}^{*}c_{E^{\prime}G^{\prime}}\Psi(e_{G,G^{\prime}})$
$\displaystyle\quad=\sum_{G,G^{\prime}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}GF^{\prime}(G^{\prime})^{\dagger})c_{EG}^{*}c_{E^{\prime}G^{\prime}}e_{F,F^{\prime}}$
$\displaystyle\quad=\sum_{F,F^{\prime}}\operatorname{Tr}\left[F^{\dagger}\left(\sum_{G}c_{EG}^{*}G\right)F^{\prime}\left(\sum_{G^{\prime}}c_{E^{\prime}G^{\prime}}(G^{\prime})^{\dagger}\right)\right]e_{F,F^{\prime}}$
$\displaystyle\quad=\sum_{F,F^{\prime}}\operatorname{Tr}[F^{\dagger}(UEU^{\dagger})F^{\prime}(U(E^{\prime})^{\dagger}U^{\dagger})]e_{F,F^{\prime}}$
$\displaystyle\quad=\sum_{F,F^{\prime}}\operatorname{Tr}[(U^{\dagger}F^{\dagger}U)E(U^{\dagger}F^{\prime}U)(E^{\prime})^{\dagger})]e_{F,F^{\prime}}$
$\displaystyle\quad=\sum_{F,F^{\prime}}\sum_{G,G^{\prime}}\operatorname{Tr}[G^{\dagger}EG^{\prime}(E^{\prime})^{\dagger}]c_{FG}c_{F^{\prime}G^{\prime}}^{*}e_{F,F^{\prime}}$
$\displaystyle\quad=\sum_{G,G^{\prime}}\operatorname{Tr}(G^{\dagger}EG^{\prime}(E^{\prime})^{\dagger}]\Lambda(U^{\dagger})(e_{G,G^{\prime}})$
$\displaystyle\quad=\Lambda(U^{\dagger})(\Psi(e_{G,G^{\prime}})).$

∎

######  Theorem IV.4.

Let $U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary transformation.
Then

$\mathbf{B}^{(j)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})=\Lambda(U_{j}^{\dagger})\left(\mathbf{B}^{(j)}(z;M_{1},M_{2})\right).$

###### Proof.

From the lemma, and Theorems IV.1 and IV.3:

$\displaystyle\mathbf{B}^{(j)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle\quad=\Psi\left[\mathbf{A}^{(j)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};UM_{1}U^{\dagger},UM_{2}U^{\dagger})\right]$
$\displaystyle\quad=\Psi\left[\Lambda(U_{j})\mathbf{A}^{(j)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2})\right]$
$\displaystyle\quad=\Lambda(U_{j}^{\dagger})\Psi\left[\mathbf{A}^{(j)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2})\right]$
$\displaystyle\quad=\Lambda(U_{j}^{\dagger})\mathbf{B}^{(j)}(z;M_{1},M_{2}).$

∎

##  V Tensor enumerators

Tensor enumerators are the natural extension of the vector enumerators of the
previous section to multiple legs. Consider a subset
$J=\\{j_{1},\dots,j_{m}\\}\subseteq\\{1,\dots,n\\}$. Then extending the
notation above, for $E\in\mathcal{E}^{m}$ and $F\in\mathcal{E}^{n-m}$ write
$E\otimes_{J}F$ for the operator where for each $k=1,\dots,m$ we insert
$E_{k}$ as the $j_{k}$-th factor into $F$. Our tensor enumerators will be
associated to the space $V^{\otimes m}$, where
$V=\mathrm{span}_{\mathbb{R}}\\{e_{E,E^{\prime}}\>:\>E,E^{\prime}\in\mathcal{E}\\}$;
we will find it convenient to reorder the indexing of these formal basis
elements so that for $E,E^{\prime}\in\mathcal{E}^{m}$ we have

$e_{E,E^{\prime}}=e_{E_{1},E^{\prime}_{1}}\otimes\cdots\otimes
e_{E_{m},E^{\prime}_{m}}\in V^{\otimes m}.$

Tensor enumerators will be elements of
$\mathbb{R}[z]\otimes_{\mathbb{R}}V^{\otimes m}$. That is, they are tensors
whose coefficients are weight enumerators.

Formally define the weights

$\displaystyle A^{(J)}_{d}(E,E^{\prime};M_{1},M_{2})$ (V.1)
$\displaystyle\quad=\sum_{F\in\mathcal{E}^{n-m}[d]}\operatorname{Tr}((E\otimes_{J}F)^{\dagger}M_{1})\operatorname{Tr}((E^{\prime}\otimes_{J}F)M_{2}),$
$\displaystyle B^{(J)}_{d}(E,E^{\prime};M_{1},M_{2})$ (V.2)
$\displaystyle\quad=\sum_{F\in\mathcal{E}^{n-m}[d]}\operatorname{Tr}((E\otimes_{J}F)^{\dagger}M_{1}(E^{\prime}\otimes_{J}F)M_{2}).$

As with the vector enumerators, weights of $E$ and $E^{\prime}$ are not
included in these expressions.

######  Definition V.1.

The _tensor enumerators_ of set of legs $J$ are then

$\displaystyle\mathbf{A}^{(J)}(z;M_{1},M_{2})$
$\displaystyle\qquad=\sum_{E,E^{\prime}\in\mathcal{E}^{m}}\sum_{d=0}^{n-m}A^{(J)}_{d}(E,E^{\prime};M_{1},M_{2})z^{d}e_{E,E^{\prime}},$
$\displaystyle\mathbf{B}^{(J)}(z;M_{1},M_{2})$
$\displaystyle\qquad=\sum_{E,E^{\prime}\in\mathcal{E}^{m}}\sum_{d=0}^{n-m}B^{(J)}_{d}(E,E^{\prime};M_{1},M_{2})z^{d}e_{E,E^{\prime}},$

where $A^{(J)}_{d}$ and $B^{(J)}_{d}$ are defined in (V.1) and (V.2).

We can extend the weighted trace of Lemma IV.1 above to link tensor
enumerators of different degrees. Let $K\subset J$, with $|K|=k$ and $|J|=m$.
Then any element of $\mathcal{E}^{m}$ can be written as $F\otimes_{K}E$ for
$F\in\mathcal{E}^{k}$ and $E\in\mathcal{E}^{m-k}$. We define
$\widetilde{\mathrm{tr}}^{J}_{K}:\mathbb{R}[z]\otimes_{\mathbb{R}}V^{\otimes
m}\to\mathbb{R}[z]\otimes_{\mathbb{R}}V^{\otimes k}$ by linearly extending

$\widetilde{\mathrm{tr}}^{J}_{K}(e_{F\otimes_{K}E,F^{\prime}\otimes_{K}E^{\prime}})=\left\\{\begin{array}[]{cl}z^{\mathrm{wt}(E)}e_{F,F^{\prime}}&\text{if
$E=E^{\prime}$}\\\ 0&\text{if $E\not=E^{\prime}$.}\end{array}\right.$

The proof of the following result is a straightforward computation and so is
left for the reader.

######  Proposition V.1.

Let $K\subset J$. Then
$\widetilde{\mathrm{tr}}^{J}_{K}(\mathbf{A}^{(J)}(z))=\mathbf{A}^{(K)}(z)$,
and similarly for $\mathbf{B}^{(J)}$.

As in the previous section, the action of the unitary group on our error basis
naturally defines a representation on the vector space $V$. This extends
naturally to local unitary operators on $V^{\otimes m}$. In fact, the
following definition makes sense and the theorem holds for any
$U\in\mathcal{U}(\mathfrak{H}^{\otimes m})$, not just local ones.

######  Definition V.2.

Let $\mathcal{E}$ be an error group on a Hilbert space $\mathcal{H}$, and
$V=\mathrm{span}\\{e_{E,E^{\prime}}\\}_{E,E^{\prime}\in\mathcal{E}}$. Define
$\Lambda:\mathcal{U}(\mathfrak{H})\to L(V)$ by

$\Lambda(U)(e_{E,E^{\prime}})=\sum_{G,G^{\prime}\in\mathcal{E}}c_{EG}^{*}c_{E^{\prime}G^{\prime}}e_{G,G^{\prime}},$

where $U^{\dagger}EU=\sum_{G}Gc_{GE}$. Then (without additional decoration)
$\Lambda:\mathcal{U}(\mathfrak{H})^{\otimes m}\to L(V^{\otimes m})$ as the
$m$-fold tensor product of $\Lambda$.

Note that in this definition,
$c_{GE}=\frac{1}{q}\operatorname{Tr}(G^{\dagger}U^{\dagger}EU)$. By exchanging
the roles of $E$ and $G$, and conjugating, we get
$c^{*}_{EG}=\frac{1}{q}\operatorname{Tr}(G^{\dagger}UEU^{\dagger})$ and thus

$\Lambda(U^{\dagger})(e_{E,E^{\prime}})=\sum_{G,G^{\prime}\in\mathcal{E}}e_{G,G^{\prime}}c_{GE}c^{*}_{G^{\prime}E^{\prime}}.$

######  Theorem V.1.

Let $U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary operator on
$\mathfrak{H}^{\otimes n}$, and let $J\subseteq\\{1,\dots,n\\}$ be any subset
of legs. Then

$\mathbf{A}^{(J)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})=\Lambda(U_{J})\left(\mathbf{A}^{(J)}(z;M_{1},M_{2})\right),$

where $U_{J}=\bigotimes_{j\in J}U_{j}$.

###### Proof.

We write

$\displaystyle\mathbf{A}^{(J)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle\quad=\sum_{E,E^{\prime}}\sum_{F}\operatorname{Tr}((E^{\dagger}\otimes_{J}F^{\dagger})UM_{1}U^{\dagger})$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}((E^{\prime}\otimes_{J}F)UM_{2}U^{\dagger})z^{\mathrm{wt}(F)}e_{E,E^{\prime}}$
$\displaystyle\quad=\
\sum_{E,E^{\prime}}\sum_{F}\operatorname{Tr}((U_{J}^{\dagger}EU_{J}\otimes_{J}\hat{U}F\hat{U})^{\dagger}M_{1})$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}((U_{J}^{\dagger}E^{\prime}U_{J}\otimes_{J}\hat{U}^{\dagger}F\hat{U})M_{2})z^{\mathrm{wt}(F)}e_{E,E^{\prime}}$

where $U_{J}=\bigotimes_{j\in J}U_{j}$ and $\hat{U}=\bigotimes_{j\not\in
J}U_{j}$. The invariance of this expression under $\hat{U}$ follows exactly as
in Theorem III.1. For $U_{J}$ we expand as above

$\displaystyle\mathbf{A}^{(J)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle=\sum_{E,E^{\prime},G,G^{\prime}}\sum_{F}c^{*}_{GE}c_{G^{\prime}E^{\prime}}\operatorname{Tr}((G\otimes_{J}F)^{\dagger}M_{1})$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}((G^{\prime}\otimes_{J}F)M_{2})z^{\mathrm{wt}(F)}e_{E,E^{\prime}}$
$\displaystyle=\sum_{G,G^{\prime}}\sum_{F}\operatorname{Tr}((G\otimes_{J}F)^{\dagger}M_{1})\operatorname{Tr}((G^{\prime}\otimes_{J}F)M_{2})$
$\displaystyle\qquad\qquad\cdot
z^{\mathrm{wt}(F)}\Lambda(U_{J})(e_{G,G^{\prime}})$
$\displaystyle=\Lambda(U_{J})\left(\mathbf{A}^{(J)}(z;M_{1},M_{2})\right).$

∎

The weighted trace operation is compatible with local unitary action, as the
following result shows.

######  Proposition V.2.

Let $U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary operator on
$\mathfrak{H}^{\otimes n}$, and let $K\subset J\subseteq\\{1,\dots,n\\}$. Then

$\Lambda(U_{K})\circ\widetilde{\mathrm{tr}}^{J}_{K}=\widetilde{\mathrm{tr}}^{J}_{K}\circ\Lambda(U_{J}).$

###### Proof.

Write $k=|K|$ and $m=|J|$. Then the left side of this equation on a basis
element of $V^{\otimes m}$ is

$\displaystyle\Lambda(U_{K})[\widetilde{\mathrm{tr}}^{J}_{K}(e_{E\otimes_{K}F,E^{\prime}\otimes_{K}F})]=z^{\mathrm{wt}(F)}\Lambda(U_{K})(e_{E,E^{\prime}})$
$\displaystyle\quad=z^{\mathrm{wt}(F)}\sum_{G,G^{\prime}\in\mathcal{E}^{k}}c^{*}_{EG}c_{E^{\prime}G^{\prime}}e_{G,G^{\prime}},$

while
$\Lambda(U_{K})[\widetilde{\mathrm{tr}}^{J}_{K}(e_{E\otimes_{K}F,E^{\prime}\otimes_{K}F^{\prime}})]=0$
when $F\not=F^{\prime}$.

Now we compute

$\displaystyle\widetilde{\mathrm{tr}}^{J}_{K}[\Lambda(U_{J})(e_{E\otimes_{K}F,E\otimes_{K}F^{\prime}})]$
$\displaystyle\quad=\sum_{G,G^{\prime},H,H^{\prime}}c^{*}_{EG}c^{*}_{FH}c_{E^{\prime}G^{\prime}}c_{F^{\prime}H^{\prime}}\widetilde{\mathrm{tr}}^{J}_{K}(e_{G\otimes_{K}H,G^{\prime}\otimes
H^{\prime}}),$
$\displaystyle\quad=\sum_{H\in\mathcal{E}^{m-k}}z^{\mathrm{wt}(H)}c^{*}_{FH}c_{F^{\prime}H}\cdot\sum_{G,G^{\prime}\in\mathcal{E}^{k}}c^{*}_{EG}c_{E^{\prime}G^{\prime}}e_{G,G^{\prime}}.$

From Lemma III.1,

$\displaystyle\sum_{H\in\mathcal{E}^{m-k}[d]}\operatorname{Tr}(U^{\dagger}H^{\dagger}UF)\operatorname{Tr}(U^{\dagger}HU(F^{\prime})^{\dagger})$
$\displaystyle\quad=q^{2(m-k)}\sum_{H\in\mathcal{E}^{m-k}[d]}c^{*}_{FH}c_{F^{\prime}H}$
$\displaystyle\quad=\left\\{\begin{array}[]{cl}q^{2(m-k)}&\text{if
$F=F^{\prime}\in\mathcal{E}^{m-k}[d]$}\\\
0&\text{otherwise.}\end{array}\right.$

Therefore

$\sum_{H\in\mathcal{E}^{m-k}}z^{\mathrm{wt}(H)}c^{*}_{FH}c_{F^{\prime}H}=\left\\{\begin{array}[]{cl}z^{\mathrm{wt}(F)}&\text{if
$F=F^{\prime}$}\\\ 0&\text{otherwise,}\end{array}\right.$

and so the right side of the equation coincides with the left on every element
of $V^{\otimes m}$. ∎

A crucial property we will need is that tensor enumerators are homomorphic
under the tensor product. That is, the tensor enumerator of a tensor product
is the tensor product of the individual enumerators. Formally this captured in
the following result.

######  Proposition V.3.

Let $M_{1},M_{2}$ and $N_{1},N_{2}$ be Hermitian operators on Hilbert spaces
$\mathfrak{H}$ and $\mathfrak{K}$ respectively, and let $J$ and $K$ be subsets
of legs on each of these spaces. Then

$\displaystyle\mathbf{A}^{(J\cup K)}(z;M_{1}\otimes N_{1},M_{2}\otimes N_{2})$
$\displaystyle\qquad=\
\mathbf{A}^{(J)}(z;M_{1},M_{2})\otimes\mathbf{A}^{(K)}(z;N_{1},N_{2}),$

and similarly for $\mathbf{B}$.

###### Proof.

Just as in the proof of Lemma III.2 this is a direct computation:

$\displaystyle\mathbf{A}^{(J\cup K)}(z;M_{1}\otimes N_{1},M_{2}\otimes N_{2})$
$\displaystyle=\sum_{\scriptsize\begin{array}[]{c@{,\:}c}E\hfil,\>&E^{\prime}\\\
F\hfil,\>&F^{\prime}\end{array}}\sum_{G,H}\operatorname{Tr}\left[((E\otimes_{J}G)\otimes(F\otimes_{K}H))^{\dagger}(M_{1}\otimes
N_{1})\right]$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}\left[((E^{\prime}\otimes_{J}G)\otimes(F^{\prime}\otimes_{K}H))(M_{2}\otimes
N_{2})\right]$ $\displaystyle\qquad\qquad\cdot
z^{\mathrm{wt}(G)+\mathrm{wt}(H)}e_{E,E^{\prime},F,F^{\prime}}$
$\displaystyle\quad=\sum_{E,E^{\prime},G}\operatorname{Tr}((E\otimes_{J}G)^{\dagger}M_{1})\operatorname{Tr}((E^{\prime}\otimes_{J}G)M_{2})z^{\mathrm{wt}(G)}$
$\displaystyle\qquad\cdot\sum_{F,F^{\prime},H}\operatorname{Tr}((F\otimes_{K}H)^{\dagger}N_{1})\operatorname{Tr}((F^{\prime}\otimes_{K}H)M^{\prime}_{2})z^{\mathrm{wt}(H)}$
$\displaystyle\qquad\qquad\cdot e_{E,E^{\prime}}\otimes e_{F,F^{\prime}}$
$\displaystyle\quad=\mathbf{A}^{(J)}(z;M_{1},M_{2})\otimes\mathbf{A}^{(K)}(z;N_{1},N_{2}).$

∎

In Lemma IV.2 above, we showed that a nonzero off-diagonal term in a vector
enumerator indicates the existence of a stabilizer supported on the leg of the
vector enumerator. This results carries over to general tensor enumerators
with an identical proof, which we state below for completeness. However unlike
in Theorem IV.2 for vector enumerators, we do not expect tensor enumerators
with off-diagonal terms to factor; the proof of that theorem relied critically
on the fact that any code stabilized by a Pauli of the form
$P\otimes_{j}I^{\otimes(n-1)}$ must have a separable factor.

######  Proposition V.4.

Let $\mathfrak{C}$ be a $[[n,k]]$ stabilizer code and $J$ be a set of legs of
size $m$. Then for $P\not=P^{\prime}\in\mathcal{P}^{m}$,

  1. 1.

$\mathbf{A}^{(J)}(P,P^{\prime})$ is nonzero if and only if
$PP^{\prime}\otimes_{J}I^{\otimes(n-m)}$ is a stabilizer;

  2. 2.

$\mathbf{B}^{(J)}(P,P^{\prime})$ is nonzero if and only if
$\mathbf{A}^{(J)}(P,P^{\prime})$ is nonzero.

Exactly as with vector enumerators, the logical legs of the encoding map of a
quantum code can be cleaned and therefore its tensor enumerator must be
diagonal. This follows from the above proposition. In fact, the components of
the enumerator contain the Shor-Laflamme enumerators of the code.

######  Proposition V.5.

Let $\mathfrak{C}$ be a $[[n,k]]$ binary quantum code and
$|{T_{\mathfrak{C}}}\rangle$ the state associated to its encoding map. Let $L$
be the legs of $|{T_{\mathfrak{C}}}\rangle$ corresponding to the logical
operators. Then

$\displaystyle A(\mathfrak{C})$
$\displaystyle=4^{k}\cdot\mathbf{A}^{(L)}(I,I;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|),\text{
and}$ $\displaystyle B(\mathfrak{C})$
$\displaystyle=2^{k}\cdot\sum_{P\in\mathcal{P}^{k}}\mathbf{A}^{(L)}(P,P;|{T_{\mathfrak{C}}}\rangle\langle{T_{\mathfrak{C}}}|).$

Finally, we state the MacWilliams identity for tensor enumerators. This
includes as a special case the MacWilliams identities for scalar and vector
enumerators, and is in turn a special case of a general framework for quantum
MacWilliams identities covered in the next section. Specifically the following
theorem is a special case of Corollary VI.6 below.

######  Theorem V.2.

Let $\mathcal{E}$ be an error basis on $\mathfrak{H}=\mathbb{C}^{q}$, and
$M_{1},M_{2}$ Hermitian operators on $\mathfrak{H}^{\otimes n}$. Let
$J\subseteq\\{1,\dots,n\\}$ be a subset of size $m$. Then

$\mathbf{B}^{(J)}(w,z;M_{1},M_{2})=\Psi\left[\mathbf{A}^{(J)}\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2}\right)\right]$

where
$\Psi(e_{E,E^{\prime}})=\frac{1}{q^{2m}}\sum_{F,F^{\prime}\in\mathcal{E}^{m}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})e_{F,F^{\prime}}$.

Just as we did with vector enumerators, we can use the MacWilliams identity to
prove the contravariant behavior of the $\mathbf{B}$ tensor enumerator.

######  Corollary V.1.

Let $U=U_{1}\otimes\cdots\otimes U_{n}$ be a local unitary operator on
$\mathfrak{H}^{\otimes n}$, and let $J\subseteq\\{1,\dots,n\\}$ be any subset
of legs. Then

$\mathbf{B}^{(J)}(z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})=\Lambda(U_{J}^{\dagger})\left(\mathbf{B}^{(J)}(z;M_{1},M_{2})\right),$

where $U_{J}=\bigotimes_{j\in J}U_{j}$.

###### Proof.

From the theorem, Theorem V.1, and Lemma IV.3 we have

$\displaystyle\mathbf{B}^{(J)}(w,z;UM_{1}U^{\dagger},UM_{2}U^{\dagger})$
$\displaystyle\quad=\Psi\left[\mathbf{A}^{(J)}\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};UM_{1}U^{\dagger},UM_{2}U^{\dagger}\right)\right]$
$\displaystyle\quad=\Psi\left[\Lambda(U_{J})\mathbf{A}^{(J)}\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2}\right)\right]$
$\displaystyle\quad=\Lambda(U^{\dagger}_{J})\Psi\left[\mathbf{A}^{(J)}\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2}\right)\right]$
$\displaystyle\quad=\Lambda(U_{J}^{\dagger})\left(\mathbf{B}^{(J)}(z;M_{1},M_{2})\right).$

∎

##  VI All quantum MacWilliams identities

Let $\mathcal{E}$ be an error basis on $\mathfrak{H}$.

######  Definition VI.1.

A _weight function_ is defined as any function
$\mathrm{wt}:\mathcal{E}^{2}\to\mathbb{Z}_{\geq 0}^{k}\cup\\{\bot\\}$. A
weight function is _scalar_ if it is supported on the diagonal:
$\mathrm{wt}(E,E^{\prime})=\bot$ whenever $E\not=E^{\prime}$. Given a tuple
$(\mathrm{wt}_{1},\dots,\mathrm{wt}_{n})$ of such functions, we define
$\mathbf{wt}:\mathcal{E}^{2n}\to\mathbb{Z}_{\geq 0}^{k}\cup\\{\bot\\}$ by

$\displaystyle\mathbf{wt}(E_{1}\otimes E^{\prime}_{1}\otimes\cdots\otimes
E_{n}\otimes E^{\prime}_{n})$
$\displaystyle\quad=\mathrm{wt}_{1}(E_{1},E^{\prime}_{1})+\cdots+\mathrm{wt}_{n}(E_{n},E^{\prime}_{n}),$

where we define $t+\bot=\bot$ for any $t\in\mathbb{Z}_{\geq
0}^{k}\cup\\{\bot\\}$.

For a $k$-tuple of indeterminates $\mathbf{u}=(u_{1},\dots,u_{k})$ we write

$\mathbf{u}^{\mathbf{wt}(E,E^{\prime})}=\left\\{\begin{array}[]{cl}\prod_{j=1}^{k}u_{j}^{\mathbf{wt}(E,E^{\prime})_{j}}&\text{if
$\mathbf{wt}(E,E^{\prime})\not=\bot$}\\\ 0&\text{if
$\mathbf{wt}(E,E^{\prime})=\bot$.}\end{array}\right.$

Here $\mathbf{wt}(E,E^{\prime})_{j}$ is the $j$-th coordinate of
$\mathbf{wt}(E,E^{\prime})$.

For example, the usual (homogeneous) quantum weight enumerator uses variables
$(w,z)$ and has weight function

$\mathrm{wt}(E,E^{\prime})=\left\\{\begin{array}[]{cl}(1,0)&\text{if
$E=E^{\prime}=I$}\\\ (0,1)&\text{if $E=E^{\prime}\not=I$}\\\ \bot&\text{if
$E\not=E^{\prime}$.}\end{array}\right.$

The (homogeneous) double enumerator for the usual Pauli group uses variables
$(w,x,y,z)$ and has

$\mathrm{wt}(E,E^{\prime})=\left\\{\begin{array}[]{cl}(1,0,1,0)&\text{if
$E=E^{\prime}=I$}\\\ (0,1,1,0)&\text{if $E=E^{\prime}=X$}\\\
(0,1,0,1)&\text{if $E=E^{\prime}=Y$}\\\ (1,0,0,1)&\text{if
$E=E^{\prime}=Z$}\\\ \bot&\text{if $E\not=E^{\prime}$.}\end{array}\right.$

The complete enumerator of an error basis $\mathcal{E}$ has variables
$\\{u_{E}\\}_{E\in\mathcal{E}}$ and the weight $\mathrm{wt}(E,E)$ has a $1$ in
the $E$-th position and zero elsewhere, while for $E\not=E^{\prime}$ the
weight $\mathrm{wt}(E,E^{\prime})=\bot$.

For vector enumerators, their weight functions are composed from two weight
functions. In all but one coordinate we have a scalar weight function, such as
any of those above. In the one remaining coordinate we have variables
$\\{e_{E,E^{\prime}}\\}_{E,E^{\prime}\in\mathcal{E}}$ and the weight function
where $\mathrm{wt}(E,E^{\prime})$ equal to $1$ in the $(E,E^{\prime})$
position and zero elsewhere. Hence, the overall set of variables consists of
the scalar variables and $\\{e_{E,E^{\prime}}\\}$. The latter set of variables
has the feature that every monomial has precisely one of these appearing
linearly, hence our interpretation as a vector with polynomial coefficients.

Tensor enumerators are natural extensions of vector enumerators, where in each
leg of the tensor we take a _distinct_ copy of the weight function
$\mathrm{wt}(E,E^{\prime})$ above. That is for an order $m$ tensor, we have
variables $\\{e_{E_{1},E^{\prime}_{1}},\dots,e_{E_{m},E^{\prime}_{m}}\\}$ and
the weight function in the $j$-th leg of the tensor is
$\mathrm{wt}(E_{j},E^{\prime}_{j})$ that has a $1$ is $(E_{j},E^{\prime}_{j})$
position for variable $e_{E_{j},E^{\prime}_{j}}$ and zero elsewhere.

We define enumerators of Hermitian operators $M_{1},M_{2}$ over a weight
function $\mathbf{wt}$ as

$\displaystyle A(\mathbf{u};M_{1},M_{2})$
$\displaystyle=\sum_{E,E^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}M_{1})\operatorname{Tr}(E^{\prime}M_{2})\mathbf{u}^{\mathbf{wt}(E,E^{\prime})}$
$\displaystyle B(\mathbf{u};M_{1},M_{2})$
$\displaystyle=\sum_{E,E^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}M_{1}E^{\prime}M_{2})\mathbf{u}^{\mathbf{wt}(E,E^{\prime})}.$

This recovers scalar, vector, and tensor enumerators over any of weight
functions given above as special cases.

Given a weight function $\mathrm{wt}:\mathcal{E}^{2}\to\mathbb{Z}_{\geq
0}^{k}\cup\\{\bot\\}$, consider the function
$f(E,E^{\prime})=\mathbf{u}^{\mathrm{wt}(E,E^{\prime})}$. We define a form of
generalized discrete Wigner transform of this function as

$\displaystyle\hat{f}(D,D^{\prime})$
$\displaystyle=\frac{1}{q^{2}}\sum_{E,E^{\prime}}\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})f(E,E^{\prime})$
$\displaystyle=\frac{1}{q^{2}}\sum_{E,E^{\prime}}\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})\mathbf{u}^{\mathrm{wt}(E,E^{\prime})}.$

######  Theorem VI.1.

Let $\mathcal{E}$ be an error basis on $\mathfrak{H}$, and let $\mathbf{wt}$
be associated to weight functions $(\mathrm{wt}_{1},\dots,\mathrm{wt}_{n})$,
where each $\mathrm{wt}_{j}:\mathcal{E}^{2}\to\mathbb{Z}_{\geq
0}^{k}\cup\\{\bot\\}$. Suppose there exists an algebraic mapping
$\Phi(\mathbf{u})=(\Phi_{1}(\mathbf{u}),\dots,\Phi_{k}(\mathbf{u}))$ where
each $j=1,\dots,n$ has:

$\Phi(\mathbf{u})^{\mathrm{wt}_{j}(D,D^{\prime})}=\tfrac{1}{q^{2}}\sum_{E,E^{\prime}}\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})\mathbf{u}^{\mathrm{wt}_{j}(E,E^{\prime})}.$
(VI.1)

Then the enumerators for this weight function satisfy

$B(\mathbf{u};M_{1},M_{2})=A(\Phi(\mathbf{u});M_{1},M_{2}).$

###### Proof.

We begin by expressing

$\displaystyle M_{1}$
$\displaystyle=\frac{1}{q^{n}}\sum_{D\in\mathcal{E}^{n}}\operatorname{Tr}(D^{\dagger}M_{1})D,$
$\displaystyle M_{2}$
$\displaystyle=\frac{1}{q^{n}}\sum_{D^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(D^{\prime}M_{2})(D^{\prime})^{\dagger}.$

Then

$\displaystyle
B(\mathbf{u};M_{1},M_{2})=\sum_{E,E^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}M_{1}E^{\prime}M_{2})\mathbf{u}^{\mathbf{wt}(E,E^{\prime})}$
$\displaystyle\quad=\frac{1}{q^{2n}}\sum_{D,D^{\prime},E,E^{\prime}\in\mathcal{E}^{n}}\left(\operatorname{Tr}(D^{\dagger}M_{1})\operatorname{Tr}(D^{\prime}M_{2})\right.$
$\displaystyle\qquad\qquad\qquad\qquad\qquad\left.\cdot\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})\mathbf{u}^{\mathbf{wt}(E)}\right).$

Now,

$\displaystyle\frac{1}{q^{2n}}\sum_{E,E^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})\mathbf{u}^{\mathbf{wt}(E,E^{\prime})}$
$\displaystyle\qquad=\frac{1}{q^{2n}}\sum_{E,E^{\prime}\in\mathcal{E}^{n}}\prod_{j=1}^{n}\operatorname{Tr}(E_{j}^{\dagger}D_{j}E^{\prime}_{j}(D^{\prime}_{j})^{\dagger})\mathbf{u}^{\mathrm{wt}_{j}(E_{j},E^{\prime}_{j})}$
$\displaystyle\qquad=\prod_{j=1}^{n}\frac{1}{q^{2}}\sum_{E,E^{\prime}\in\mathcal{E}}\operatorname{Tr}(E^{\dagger}D_{j}E^{\prime}(D^{\prime}_{j})^{\dagger})\mathbf{u}^{\mathrm{wt}_{j}(E,E^{\prime})}$
$\displaystyle\qquad=\prod_{j=1}^{n}\Phi(\mathbf{u})^{\mathrm{wt}_{j}(D_{j},D^{\prime}_{j})}=\Phi(\mathbf{u})^{\mathbf{wt}(D,D^{\prime})}.$

Therefore,

$\displaystyle B(\mathbf{u};M_{1},M_{2})$
$\displaystyle\qquad=\sum_{D,D^{\prime}\in\mathcal{E}^{n}}\operatorname{Tr}(D^{\dagger}M_{1})\operatorname{Tr}(D^{\prime}M_{2})\Phi(\mathbf{u})^{\mathbf{wt}(D,D^{\prime})}$
$\displaystyle\qquad=A(\Phi(\mathbf{u});M_{1},M_{2}).$

∎

So to obtain a quantum MacWilliams identity, we need to provide an algebraic
map that satisfies condition (VI.1) for each tensor factor. In all of the
cases we examine below, the form of this map is determined by simplifying the
generalized discrete Wigner transform when applied to the weight function
monomial.

######  Corollary VI.1.

Let $\mathcal{E}$ be any error basis on $\mathfrak{H}=\mathbb{C}^{q}$,
variables $\mathbf{u}=\\{u_{E}\\}_{E\in\mathcal{E}}$, and the complete weight
function $\mathrm{wt}$ given implicitly by
$\mathbf{u}^{\mathrm{wt}(E,E^{\prime})}=u_{E}$ when $E=E^{\prime}$ and zero
when $E\not=E^{\prime}$. Let $A$ and $B$ be the complete weight enumerators
associated to this weight function. Then

$B(\\{u_{D}\\};M_{1},M_{2})=A\left(\frac{1}{q}\sum_{E\in\mathcal{E}}\omega(D,E)u_{E};M_{1},M_{2}\right).$

###### Proof.

For any scalar weight function

$\displaystyle\frac{1}{q^{2}}\sum_{E,E^{\prime}}\operatorname{Tr}(E^{\dagger}DE^{\prime}(D^{\prime})^{\dagger})\mathbf{u}^{\mathrm{wt}(E,E^{\prime})}$
$\displaystyle\quad=\frac{1}{q^{2}}\sum_{E}\operatorname{Tr}(E^{\dagger}DE(D^{\prime})^{\dagger})\mathbf{u}^{\mathrm{wt}(E,E)}$
$\displaystyle\quad=\frac{1}{q^{2}}\sum_{E}\omega(D,E)\operatorname{Tr}(D(D^{\prime})^{\dagger})\mathbf{u}^{\mathrm{wt}(E,E)}$
$\displaystyle\quad=\left\\{\begin{array}[]{cl}\tfrac{1}{q}\sum_{E}\omega(D,E)\mathbf{u}^{\mathrm{wt}(E,E)}&\text{if
$D=D^{\prime}$}\\\ 0&\text{if $D\not=D^{\prime}$.}\end{array}\right.$

Hence for $D=D^{\prime}$ we take

$\Phi(\mathbf{u})^{\mathrm{wt}(D,D)}=\Phi_{D}(\mathbf{u})=\frac{1}{q}\sum_{E}\omega(D,E)u_{E},$

which then satisfies condition (VI.1) of the theorem. When $D\not=D^{\prime}$
we have $0=0$, which is always satisfied. ∎

######  Corollary VI.2 ([2],[4]).

For any error basis $\mathcal{E}$ on $\mathfrak{H}=\mathbb{C}^{q}$ the Shor-
Laflamme enumerators satisfy

$B(w,z;M_{1},M_{2})=A\left(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2}\right).$

###### Proof.

We can reduce from the complete enumerator of the previous result by setting
$u_{I}=w$ and $u_{D}=z$ for $D\not=I$. So in the case $D=D^{\prime}=I$ we have

$\Phi_{I}(w,z)=\frac{1}{q}\sum_{E\in\mathcal{E}}u_{E}=\frac{w+(q^{2}-1)z}{q}.$

While for any $D=D^{\prime}\not=I$ we have

$\displaystyle\Phi_{D}(w,z)$
$\displaystyle=\frac{1}{q}\sum_{E}\omega(D,E)u_{E}$
$\displaystyle=\frac{1}{q}\left(w-z+z\cdot\sum_{E}\omega(D,E)\right)=\frac{w-z}{q}.$

All $\Phi_{D}(w,z)$ are equal, so $\Phi(w,z)=(\Phi_{I}(w,z),\Phi_{D}(w,z))$ is
well defined and satisfies condition (VI.1). ∎

The double weight enumerator of Hu, Yang, and Yau, for both the binary [6] and
non-binary [7] Pauli bases, are defined over homogeneous variables
$(w,x,y,z)$. When $q>2$, we can define a refined double weight enumerator over
variables $\mathbf{u}=(\mathbf{x},\mathbf{z})=(x_{0},\cdots
x_{q-1},z_{0},\cdots,z_{q-1})$ using the scalar weight function implicitly
defined via

$(\mathbf{x},\mathbf{z})^{\mathrm{wt}(X^{a}Z^{b},X^{a}Z^{b})}=x_{a}z_{b},$

and zero otherwise.

######  Corollary VI.3.

For the Pauli basis $\mathcal{P}$ on $\mathfrak{H}=\mathbb{C}^{q}$, the
refined double quantum weight enumerators defined by the weight function above
satisfy

$\displaystyle B(x_{a},z_{b};M_{1},M_{2})$
$\displaystyle\qquad=A(\tfrac{1}{\sqrt{q}}\sum_{d}\zeta^{ad}z_{d},\tfrac{1}{\sqrt{q}}\sum_{c}\zeta^{-bc}x_{c};M_{1},M_{2}),$

where $\zeta=e^{2\pi i/q}$.

###### Proof.

Write
$\Phi(\mathbf{x},\mathbf{z})=(\Theta_{a}(\mathbf{x},\mathbf{z}),\Psi_{b}(\mathbf{x},\mathbf{z}))$.
When $D=D^{\prime}=X^{a}Z^{b}$ we require

$\displaystyle(\Phi(\mathbf{x},\mathbf{z}))^{\mathrm{wt}(X^{a}Z^{b},X^{a}Z^{b})}=\Theta_{a}(\mathbf{x},\mathbf{z})\cdot\Psi_{b}(\mathbf{x},\mathbf{z})$
$\displaystyle\qquad=\frac{1}{q}\sum_{c,d}\zeta^{ad-
bc}(\mathbf{x},\mathbf{z})^{\mathrm{wt}(X^{c}Z^{d},X^{c}Z^{d})}$
$\displaystyle\qquad=\frac{1}{q}\sum_{c,d}\zeta^{ad-bc}x_{c}z_{d}$
$\displaystyle\qquad=\left(\frac{1}{\sqrt{q}}\sum_{c}\zeta^{-bc}x_{c}\right)\left(\frac{1}{\sqrt{q}}\sum_{d}\zeta^{ad}z_{d}\right).$

Therefore, the condition (VI.1) is satisfied for

$\Theta_{a}(\mathbf{x},\mathbf{z})=\frac{1}{\sqrt{q}}\sum_{d}\zeta^{ad}z_{d}\text{
and
}\Psi_{b}(\mathbf{x},\mathbf{z})=\frac{1}{\sqrt{q}}\sum_{c}\zeta^{-bc}x_{c}.$

When $D\not=D^{\prime}$ we need $0=0$, which always holds. ∎

######  Corollary VI.4 ([7]).

For the Pauli basis $\mathcal{P}$ on $\mathfrak{H}=\mathbb{C}^{q}$, then the
double quantum weight enumerators of Hu, Yang, and Yau satisfy:

$\displaystyle D(w,x,y,z;M_{1},M_{2})$
$\displaystyle\qquad=C\left(\tfrac{y+(q-1)x}{\sqrt{q}},\tfrac{w-z}{\sqrt{q}},\tfrac{w+(q-1)}{\sqrt{q}},\tfrac{y-x}{\sqrt{q}};M_{1},M_{2}\right)$

###### Proof.

We can reduce from the refined double enumerator above by setting $x_{0}=y$
and $x_{a}=x$ for $a>0$, and $z_{0}=w$ and $z_{b}=z$ for $b>0$. Then

$\displaystyle\Theta_{0}(w,x,y,z)$
$\displaystyle=\tfrac{1}{\sqrt{q}}(w+(q-1)z)$
$\displaystyle\Theta_{a}(w,x,y,z)$
$\displaystyle=\tfrac{1}{\sqrt{q}}(w-z+z\sum_{d}\zeta^{ad})$
$\displaystyle=\tfrac{1}{\sqrt{q}}(w-z)\text{ for any $a>0$}$
$\displaystyle\Psi_{0}(w,x,y,z)$ $\displaystyle=\tfrac{1}{\sqrt{q}}(y+(q-1)x)$
$\displaystyle\Psi_{b}(w,x,y,z)$
$\displaystyle=\tfrac{1}{\sqrt{q}}(y-x+x\sum_{d}\zeta^{ad})$
$\displaystyle=\tfrac{1}{\sqrt{q}}(y-x)\text{ for any $b>0$.}$

Since $\Theta_{a}$ and $\Psi_{b}$ remain the same for any $a,b>0$, any choice
of these provide a well defined transform that satisfies (VI.1). ∎

######  Corollary VI.5 ([7]).

For the Pauli basis $\mathcal{P}$ on $\mathfrak{H}=\mathbb{C}^{q}$, the
complete quantum enumerators of Hu, Yang, and Yau satisfy

$F(u_{ab};M_{1},M_{2})=E(\tfrac{1}{q}\sum_{c,d}\zeta^{ad-
bc}u_{cd};M_{1},M_{2})$

where $\zeta=e^{2\pi i/q}$.

###### Proof.

The complete weight function is essentially the identity, hence for
$D=D^{\prime}=X^{a}Z^{b}$ we require we require

$\displaystyle\Phi(\mathbf{u})^{\mathrm{wt}(X^{a}Z^{b},X^{a}Z^{b})}=\Phi_{(a,b)}(\mathbf{u})$
$\displaystyle\qquad=\frac{1}{q}\sum_{c,d}\zeta^{ad-
bc}\mathbf{u}^{\mathrm{wt}(X^{c}X^{d},X^{c}x^{d})}=\frac{1}{q}\sum_{c,d}\zeta^{ad-
bc}u_{cd}.$

When $D\not=D^{\prime}$ we need $0=0$, which is always satisfied. ∎

Finally we consider the vector and tensor enumerators over any scalar system
that satisfies a MacWilliams identity, such as any of those above.

######  Corollary VI.6.

Let $\mathcal{E}$ be an error basis on $\mathfrak{H}=\mathbb{C}^{q}$ and
$\widetilde{\mathrm{wt}}$ be any scalar weight function that satisfies
condition (VI.1) of the theorem for algebraic map $\Phi(\mathbf{u})$. Let
$J=\\{j_{1},\dots,j_{m}\\}\subseteq\\{1,\dots,n\\}$ and define $\mathbf{wt}$
on $(\mathcal{E}\times\mathcal{E})^{n}$ implicitly by

$\displaystyle(\mathbf{u},\mathbf{e}_{1},\dots,\mathbf{e}_{m})^{\mathbf{wt}(E,E^{\prime})}$
$\displaystyle\quad=\left(\prod_{k\not\in
J}\mathbf{u}^{\widetilde{\mathrm{wt}}(E_{k},E^{\prime}_{k})}\right)e_{E_{j_{1}},E^{\prime}_{j_{1}}}\cdots
e_{E_{j_{m}},E^{\prime}_{j_{m}}},$

where each set of variables
$\mathbf{e}_{j}=\\{e_{E,E^{\prime}}\\}_{E,E^{\prime}\in\mathcal{E}}$. Define
enumerators $\mathbf{A}^{(J)}$ and $\mathbf{B}^{(J)}$ by this weight function.
Then for any Hermitian operators $M_{1},M_{2}$ on $\mathfrak{H}^{\otimes n}$,

$\mathbf{B}^{(J)}(\mathbf{u};M_{1},M_{2})=\Psi[\mathbf{A}^{(J)}(\Phi(\mathbf{u});M_{1},M_{2})]$

where
$\Psi(e_{E,E^{\prime}})=\frac{1}{q^{2m}}\sum_{F,F^{\prime}\in\mathcal{E}^{m}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})e_{F,F^{\prime}}$.

###### Proof.

This is immediate. For the legs not in $J$, condition (VI.1) of the theorem is
satisfied by assumption. For the legs of $J$, we have
$\Psi(e_{E,E^{\prime}})=\frac{1}{q^{2m}}\sum_{F,F^{\prime}\in\mathcal{E}^{m}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})e_{F,F^{\prime}}$
is condition (VI.1) of the theorem. ∎

##  VII Tensor networks

Figure 1: Holographic code from [23] with a cut line. Only three legs cross
the cut, hence the weight enumerators of this code can be computed by tracing
two tensor enumerators with three legs.

Given a tensor network state expressed in the computational basis of
$(\mathbb{C}^{q})^{\otimes n}$,

$|{T}\rangle=\sum_{j_{1},\cdots,j_{n}}c_{j_{1},\cdots,j_{n}}|{j_{1},\dots,j_{n}}\rangle,$

we define its trace on, say, legs $1$ and $2$ to be

$\wedge^{1,2}|{T}\rangle\propto\sum_{j}\sum_{j_{3},\cdots,j_{n}}c_{j,j,j_{3}\cdots,j_{n}}|{j_{3},\dots,j_{n}}\rangle.$

Note that we may need to renormalize to get a state of norm one. Writing
$|{\beta}\rangle=\frac{1}{\sqrt{q}}\sum_{j}|{jj}\rangle$, we can informally
write

$\wedge^{1,2}|{T}\rangle=(\langle{\beta}|\otimes I^{\otimes n-2})|{T}\rangle$

or more generally
$\wedge^{j,k}|{T}\rangle=(\langle{\beta}|\otimes_{j,k}I^{\otimes
n-2})|{T}\rangle$ using the notation of the previous sections.

For a general Hermitian operator $M$ on $(\mathbb{C}^{q})^{\otimes n}$, and
legs $1\leq j<k\leq n$ implicitly define $\wedge^{j,k}M$ on
$(\mathbb{C}^{q})^{\otimes(n-2)}$ by

$\operatorname{Tr}(A(\wedge^{j,k}M))=\operatorname{Tr}((|{\beta}\rangle\langle{\beta}|\otimes_{j,k}A)M)$

for any operator $A$ on $(\mathbb{C}^{q})^{\otimes(n-2)}$.

Now consider any error basis $\mathcal{E}$ on $\mathfrak{H}=\mathbb{C}^{q}$.
Note that for any $E,F$ we have that $E\otimes E^{*}$ commutes with $F\otimes
F^{*}$ since $EF=\omega(E,F)FE$ implies that
$E^{*}F^{*}=\omega(E,F)^{-1}F^{*}E^{*}$ and so

$\displaystyle(E\otimes E^{*})(F\otimes F^{*})$
$\displaystyle\qquad=\omega(E,F)\omega(E,F)^{-1}(F\otimes F^{*})(E\otimes
E^{*}).$

######  Lemma VII.1.

For any error basis $\mathcal{E}$ on $\mathfrak{H}=\mathbb{C}^{q}$ we have

$|{\beta}\rangle\langle{\beta}|=\frac{1}{q^{2}}\sum_{E\in\mathcal{E}}E\otimes
E^{*}.$

###### Proof.

As $|{\beta}\rangle\langle{\beta}|$ is an operator on
$\mathfrak{H}\otimes\mathfrak{H}$ we can write

$|{\beta}\rangle\langle{\beta}|=\sum_{E,F}c_{E,F}E\otimes F.$

But,

$\displaystyle c_{E,F}$
$\displaystyle=\tfrac{1}{q^{2}}\operatorname{Tr}(|{\beta}\rangle\langle{\beta}|(E\otimes
F)^{\dagger})$
$\displaystyle=\tfrac{1}{q^{3}}\sum_{j,k}\langle{j,j}|E^{\dagger}\otimes
F^{\dagger}|{k,k}\rangle$
$\displaystyle=\tfrac{1}{q^{3}}\sum_{j,k}\langle{k}|E^{*}|{j}\rangle\langle{j}|F^{\dagger}|{k}\rangle$
$\displaystyle=\tfrac{1}{q^{3}}\operatorname{Tr}(E^{*}F^{\dagger})=\left\\{\begin{array}[]{cl}\frac{1}{q^{2}}&\text{
if $F=E^{*}$}\\\ 0&\text{otherwise.}\end{array}\right.$

∎

Recall that tensor enumerators lie in

$\mathbb{R}[z]\otimes_{\mathbb{R}}V^{\otimes
m}=\mathrm{span}_{\mathbb{R}[z]}\\{e_{E,E^{\prime}}\>:\>E,E^{\prime}\in\mathcal{E}^{\otimes
m}\\}.$

We define the trace on legs $j,k$ on this space as

$\wedge^{j,k}e_{E,E^{\prime}}=e_{E\setminus\\{E_{j},E_{k}\\},E^{\prime}\setminus\\{E^{\prime}_{j},E^{\prime}_{k}\\}}$

if $E_{k}=E_{j}^{*}$ and $E^{\prime}_{k}=(E^{\prime}_{j})^{*}$, and zero
otherwise. We extend linearly to all of
$\mathbb{R}[z]\otimes_{\mathbb{R}}V^{\otimes m}$.

######  Theorem VII.1.

Suppose $j,k\in J\subseteq\\{1,\dots,m\\}$. Then

$\wedge^{jk}\mathbf{A}^{(J)}(z;M_{1},M_{2})=\mathbf{A}^{(J\setminus\\{j,k\\})}(z;\wedge^{j,k}M_{1},\wedge^{j,k}M_{2}),$

and similarly for $\mathbf{B}^{(J)}$.

###### Proof.

For A we directly compute,

$\displaystyle\wedge^{jk}\mathbf{A}^{(J)}(z;M_{1},M_{2})$ $\displaystyle\
=\sum_{E,E^{\prime},F}\left[\operatorname{Tr}((E\otimes_{J}F)^{\dagger}M_{1})\operatorname{Tr}((E^{\prime}\otimes_{J}F)M_{2}\right]$
$\displaystyle\qquad\qquad\cdot
z^{\mathrm{wt}(F)}\left[\wedge^{j,k}e_{E,\bar{E}}\right]$ $\displaystyle\
=\sum_{F}\sum_{\tilde{E},\tilde{E}^{\prime}}\sum_{G,G^{\prime}}\left\\{\operatorname{Tr}([((G\otimes
G^{*})\otimes_{j,k}\tilde{E})\otimes_{J}F]^{\dagger}M_{1})\right.$
$\displaystyle\qquad\qquad\cdot\left.\operatorname{Tr}([((G^{\prime}\otimes(G^{\prime})^{*})\otimes_{j,k}\tilde{E}^{\prime})\otimes_{J}F]M_{2})\right\\}$
$\displaystyle\qquad\qquad\cdot
z^{\mathrm{wt}(F)}e_{\tilde{E},\tilde{E}^{\prime}}$ $\displaystyle\
=\sum_{\tilde{E},\tilde{E}^{\prime},F}\operatorname{Tr}((\tilde{E}\otimes_{J\setminus\\{j,k\\}}F)^{\dagger}(\wedge^{j,k}M_{1}))$
$\displaystyle\qquad\qquad\cdot\operatorname{Tr}((\tilde{E}^{\prime}\otimes_{J\setminus\\{j,k\\}}F)(\wedge^{j,k}M_{2}))z^{\mathrm{wt}(F)}e_{\tilde{E},\tilde{E}^{\prime}}$
$\displaystyle\
=\mathbf{A}^{(J\setminus\\{j,k\\})}(z;\wedge^{jk}M_{1},\wedge^{jk}M_{2})$

where we write $\tilde{E}=E\setminus\\{E_{j},E_{k}\\}$ and similarly for
$\tilde{E}^{\prime}$.

For B we appeal to the MacWilliams identity. Recall the generalized discrete
Wigner transform:

$\Psi^{(m)}(e_{E,E^{\prime}})=\frac{1}{q^{2m}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})e_{F,F^{\prime}}.$

Here we decorate the transform as we will be working in multiple degrees. We
have

$\displaystyle\wedge^{j,k}[\Psi^{(m)}(e_{E,E^{\prime}})]=\frac{1}{q^{2m}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}EF^{\prime}(E^{\prime})^{\dagger})(\wedge^{j,k}e_{F,F^{\prime}})$
$\displaystyle\qquad=\frac{1}{q^{2m}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}E_{j}F^{\prime}(E^{\prime}_{j})^{\dagger})\operatorname{Tr}(F^{\mathrm{tr}}E_{k}(F^{\prime})^{*}(E^{\prime}_{k})^{\dagger})$
$\displaystyle\qquad\qquad\qquad\cdot\sum_{\tilde{F},\tilde{F}^{\prime}}\operatorname{Tr}(\tilde{F}^{\dagger}\tilde{E}\tilde{F}^{\prime}(\tilde{E}^{\prime})^{\dagger})e_{\tilde{F},\tilde{F}^{\prime}}$
$\displaystyle\qquad=\frac{1}{q^{4}}\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}E_{j}F^{\prime}(E^{\prime}_{j})^{\dagger})\operatorname{Tr}(F^{\mathrm{tr}}E_{k}(F^{\prime})^{*}(E^{\prime}_{k})^{\dagger})$
$\displaystyle\qquad\qquad\qquad\cdot\Psi^{(m-2)}(e_{\tilde{E},\tilde{E}^{\prime}}),$

where like above we have written $\tilde{E}=E\setminus\\{E_{j},E_{k}\\}$, and
similarly for $F,E^{\prime},F^{\prime}$.

Now,

$\displaystyle\sum_{F,F^{\prime}}\operatorname{Tr}(F^{\dagger}E_{j}F^{\prime}(E^{\prime}_{j})^{\dagger})\operatorname{Tr}(F^{\mathrm{tr}}E_{k}(F^{\prime})^{*}(E^{\prime}_{k})^{\dagger})$
$\displaystyle\quad=\sum_{F,F^{\prime}}\operatorname{Tr}((F\otimes
F^{*})^{\dagger}(E_{j}\otimes
E_{k})(F^{\prime}\otimes(F^{\prime})^{*})(E^{\prime}_{j}\otimes
E^{\prime}_{k})^{\dagger})$
$\displaystyle\quad=q^{4}\operatorname{Tr}(|{\beta}\rangle\langle{\beta}|(E_{j}\otimes
E_{k})|{\beta}\rangle\langle{\beta}|(E^{\prime}_{j}\otimes
E^{\prime}_{k})^{\dagger})$
$\displaystyle\quad=q^{4}\langle{\beta}|E_{j}\otimes
E_{k}|{\beta}\rangle\langle{\beta}|E^{\prime}_{j}\otimes
E^{\prime}_{k}|{\beta}\rangle.$

But just as we have above

$\displaystyle\langle{\beta}|E_{j}\otimes E_{k}|{\beta}\rangle$
$\displaystyle=\tfrac{1}{q}\sum_{r,s}\langle{r,r}|E_{j}\otimes
E_{k}|{s,s}\rangle$
$\displaystyle=\tfrac{1}{q}\sum_{r,s}\langle{s}|E_{j}^{\mathrm{tr}}|{r}\rangle\langle{r}|E_{k}|{s}\rangle$
$\displaystyle=\tfrac{1}{q}\operatorname{Tr}(E_{j}^{\mathrm{tr}}E_{k})=\left\\{\begin{array}[]{cl}1&\text{
if $E_{k}=E_{j}^{*}$}\\\ 0&\text{otherwise.}\end{array}\right.$

Thus, $e_{\tilde{E},\tilde{E}^{\prime}}=\wedge^{j,k}(e_{E,E})$ and

$\displaystyle\wedge^{j,k}[\Psi^{(m)}(e_{E,E^{\prime}})]$
$\displaystyle=\Psi^{(m-2)}(e_{\tilde{E},\tilde{E}^{\prime}})$
$\displaystyle=\Psi^{(m-2)}(\wedge^{j,k}(e_{E,E^{\prime}})).$

Therefore,

$\displaystyle\wedge^{j,k}\mathbf{B}^{(J)}(w,z;M_{1},M_{2})$ $\displaystyle\
=\wedge^{j,k}\Psi^{(m)}\left[\mathbf{A}^{(J)}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};M_{1},M_{2})\right]$
$\displaystyle\
=\Psi^{(m-2)}\left[\mathbf{A}^{(J\setminus\\{j,k\\})}(\tfrac{w+(q^{2}-1)z}{q},\tfrac{w-z}{q};\wedge^{j,k}M_{1},\wedge^{j,k}M_{2})\right]$
$\displaystyle\
=\mathbf{B}^{(J\setminus\\{j,k\\})}(w,z;\wedge^{j,k}M_{1},\wedge^{j,k}M_{2}).$

∎

Figure 2: Left: the encoding map of a $[[25,1,4]]$ surface code written as a
tensor network. Right: contraction of tensor enumerators. Each tensor
$\mathbf{A}^{(J)}(z)$ is a tensor enumerator constructed from the
corresponding lego on the left.

######  Example VII.1.

Consider the holographic code from [23] as shown in Figure 1 above. This five
logical qubit shallow holographic code only has 20 physical qubits, and so it
would not be numerically challenging to compute its enumerators directly from
the definitions. However, it is an informative example that we can illustrate
much more easily using tensor tracing. Namely, there are only three legs
across the blue cut in the figure and hence we can compute the three index
tensor enumerator above the cut separately. For example, above the cut the
left Bacon-Shor code (say in the $Y$-gauge) has tensor enumerator

$\displaystyle\mathbf{A}^{(3,4)}_{[[4,1,2]]}$
$\displaystyle=e_{I,I}+z^{2}e_{I,X}+z^{2}e_{X,I}+z^{2}e_{X,X}$
$\displaystyle\qquad+z^{2}e_{Z,Z}+ze_{Z,Y}+ze_{Y,Z}+z^{2}e_{Y,Y}.$

Note that the two legs on the boundary will never be traced, and so we need
only track the tensor for remaining two legs, legs 3 and 4 by our counting.
The tensor enumerator for the perfect tensor with legs 4, 5, and 6 has 64
nonzero terms and so we will not write out $\mathbf{A}^{(4,5,6)}$ explicitly,
however each coefficient is simply a single monomial. Tracing leg 3 of
$\mathbf{A}^{(3,4)}_{[[4,1,2]]}$ with leg 6 of $\mathbf{A}^{(4,5,6)}$ produces
a new tensor enumerator with 3 legs and 64 terms. Tracing the result of this
with the tensor enumerator of the right Bacon-Shor code again produces a
tensor enumerator with 3 legs and 64 terms.

When we trace in the perfect tensor on the left (or right) of lower wedge we
will expand to four legs across the cut, and therefore will need to store a
tensor enumerator with 256 terms. But this is the largest cut needed and so
the enumerator of the whole code can be computing by manipulating tensors
consisting of 256 enumerators. In some sense, this is optimal as tensor
enumerator of the middle Bacon-Shor code has 4 legs itself, albeit only eight
of its 256 terms are nonzero.

######  Example VII.2.

Recall that the surface code can be built from contracting encoding isometries
of the $[[5,1,2]]$ codes [8]. Its encoding map has a non-trivial kernel and
can be represented graphically by Figure 2 (left). We take the upward pointing
legs as inputs while the downward pointing ones as outputs (physical qubits).
The blue and red rank-1 tensors are $|+\rangle$ and $|0\rangle$ respectively.

By taking each lego on the left diagram, we may construct its corresponding
tensor enumerator polynomial, represented by a blue tensor in Figure 2
(right). The network contraction yields the overall scalar enumerator of the
entire code.

The examples we construct so far have a small number qubits such that their
enumerators can also be computed by brute force. However, we should keep in
mind that the tensor network method is far more scalable [10]. For example,
the surface code tensor network may be easily extended to larger sizes. In
Fig. 3, we obtain the coefficients of the double enumerator $C(x,z)$ of a
surface code on a strip with $748$ qubits. Recall that it captures the $X,Z$
weight distribution of the stabilizer elements. To contrast with the brute
force method, computing the same enumerator polynomial will involve checking
the weights of at least $2^{747}$ terms, which is clearly infeasible.

Figure 3: Plot of $\log C[d_{x},d_{z}]$, where $C[d_{x},d_{z}]$ are the
coefficients of the double enumerator of a 3-by-150 surface code.
$d_{x},d_{z}$ are the $X$ and $Z$ weights respectively.

## References

  * [1] Jessie MacWilliams.  A theorem on the distribution of weights in a systematic code.  Bell System Technical Journal, 42(1):79–94, 1963.
  * [2] Peter Shor and Raymond Laflamme.  Quantum analog of the MacWilliams identities for classical coding theory.  Physical review letters, 78(8):1600, 1997.
  * [3] Alexei E Ashikhmin, Alexander M Barg, Emanuel Knill, and Simon N Litsyn.  Quantum error detection. I. statement of the problem.  IEEE transactions on Information Theory, 46(3):778–788, 2000.
  * [4] Eric M Rains.  Quantum weight enumerators.  IEEE Transactions on Information Theory, 44(4):1388–1394, 1998\.
  * [5] Eric M Rains.  Shadow bounds for self-dual codes.  IEEE Transactions on Information Theory, 44(1):134–139, 1998.
  * [6] Chuangqiang Hu, Shudi Yang, and Stephen S-T Yau.  Complete weight distributions and MacWilliams identities for asymmetric quantum codes.  IEEE Access, 7:68404–68414, 2019.
  * [7] Chuangqiang Hu, Shudi Yang, and Stephen S-T Yau.  Weight enumerators for nonbinary asymmetric quantum codes and their applications.  Advances in Applied Mathematics, 121:102085, 2020.
  * [8] ChunJun Cao and Brad Lackey.  Quantum lego: building quantum error correction codes from tensor networks.  PRX Quantum, 3(2):020332, 2022.
  * [9] Terry Farrelly, David K. Tuckett, and Thomas M. Stace.  Local tensor-network codes.  arXiv e-prints, page arXiv:2109.11996, September 2021.
  * [10] ChunJun Cao, Michael Gullans, Brad Lackey, and Zitao Wang.  In preparation.
  * [11] Reinhard F Werner.  All teleportation and dense coding schemes.  Journal of Physics A: Mathematical and General, 34(35):7081, 2001\.
  * [12] Emanuel Knill.  Group representations, error bases and quantum codes.  arXiv preprint quant-ph/9608049, 1996.
  * [13] Emanuel Knill.  Non-binary unitary error bases and quantum codes.  arXiv preprint quant-ph/9608048, 1996.
  * [14] AA Klappenecker and M Rotteler.  Beyond stabilizer codes I. Nice error bases.  IEEE Transactions on Information Theory, 48(8):2392–2395, 2002\.
  * [15] Florence Jessie MacWilliams and Neil James Alexander Sloane.  The theory of error correcting codes, volume 16.  Elsevier, 1977.
  * [16] Alexei Ashikhmin and Emanuel Knill.  Nonbinary quantum stabilizer codes.  IEEE Transactions on Information Theory, 47(7):3065–3072, 2001\.
  * [17] Lev Ioffe and Marc Mézard.  Asymmetric quantum error-correcting codes.  Physical Review A, 75(3):032345, 2007.
  * [18] Pradeep Kiran Sarvepalli, Andreas Klappenecker, and Martin Rotteler.  Asymmetric quantum ldpc codes.  In 2008 IEEE International Symposium on Information Theory, pages 305–309. IEEE, 2008.
  * [19] Ashley M Stephens, Zachary WE Evans, Simon J Devitt, and Lloyd CL Hollenberg.  Asymmetric quantum error correction via code conversion.  Physical Review A, 77(6):062335, 2008.
  * [20] Fernando Pastawski, Beni Yoshida, Daniel Harlow, and John Preskill.  Holographic quantum error-correcting codes: toy models for the bulk/boundary correspondence.  Journal of High Energy Physics, 2015:149, June 2015.
  * [21] The Sage Developers.  SageMath, the Sage Mathematics Software System (Version 9.5), 2022.  https://www.sagemath.org.
  * [22] Sergey Bravyi and Barbara Terhal.  A no-go theorem for a two-dimensional self-correcting quantum memory based on stabilizer codes.  New Journal of Physics, 11(4):043029, 2009.
  * [23] ChunJun Cao and Brad Lackey.  Approximate Bacon-Shor code and holography.  Journal of High Energy Physics, 2021(5):127, May 2021.