# Exploring quantum weight enumerators from the $n$-qubit parallelized SWAP
test

Fei Shi  QICI Quantum Information and Computation Initiative, Department of
Computer Science, The University of Hong Kong, Pokfulam Road, Hong Kong  Kaiyi
Guo  School of Physics, Peking University, Beijing 100871, China  Xiande Zhang
School of Mathematical Sciences, University of Science and Technology of
China, Hefei, 230026, People’s Republic of China  Hefei National Laboratory,
University of Science and Technology of China, Hefei, 230088, China  Qi Zhao
<EMAIL_ADDRESS>QICI Quantum Information and Computation Initiative,
Department of Computer Science, The University of Hong Kong, Pokfulam Road,
Hong Kong

###### Abstract

Quantum weight enumerators play a crucial role in quantum error-correcting
codes and multipartite entanglement. They can be used to investigate the
existence of quantum error-correcting codes and $k$-uniform states. In this
work, we build the connection between quantum weight enumerators and the
$n$-qubit parallelized SWAP test. We discover that each shadow enumerator
corresponds precisely to a probability in the $n$-qubit parallelized SWAP
test, providing a computable and operational meaning for the shadow
enumerators. Due to the non-negativity of probabilities, we obtain an elegant
proof for the shadow inequalities. Concurrently, we can also calculate the
Shor-Laflamme enumerators and the Rains unitary enumerators from the $n$-qubit
parallelized SWAP test. For applications, we employ the $n$-qubit parallelized
SWAP test to determine the distances of quantum error-correcting codes, and
the $k$-uniformity of pure states. Our results indicate that quantum weight
enumerators can be efficiently estimated on quantum computers, and opening a
path to calculate the distances of quantum error-correcting codes.

Introduction.— Shor and Laflamme introduced quantum weight enumerators for
quantum error-correcting codes (QECCs) as a method to characterize them
shor1997quantum . Rains also introduced two additional weight enumerators
known as the unitary enumerators and the shadow enumerators rains1998quantum ;
rains1999quantum . These quantum weight enumerators provide a powerful tool
for investigating the existence of QECCs. For example, they have been employed
to investigate the existence of asymmetric quantum codes
sarvepalli2009asymmetric , entanglement-assisted codes lai2017linear , hybrid
codes grassl2017codes , and quantum amplitude damping codes ouyang2020linear .
Furthermore, the distance of a QECC is an important parameter, which
represents its error-correcting capability. The distance of a QECC can be
characterized by the quantum weight enumerators shor1997quantum ;
rains1998quantum ; rains1999quantum . However, effective methods to calculate
these quantum weight enumerators and determine the distances of QECCs through
quantum circuits are currently lacking.

Quantum weight enumerators are also related to multipartite entanglement
scott2004multipartite . A $k$-uniform state is an $n$-partite pure state which
has the property that all its reductions to $k$ parties are maximally mixed
scott2004multipartite . Specially, an
$\left\lfloor\frac{n}{2}\right\rfloor$-uniform state is also called an
absolutely maximally entangled (AME) state helwig2012absolute , which is
maximally entangled across every bipartition. The existence of $k$-uniform
states and AME states has attracted a lot of attention goyeneche2014genuinely
; feng2017multipartite ; li2019k ; zang20193 ; pang2019two ;
goyeneche2015absolutely ; helwig2012absolute ; rather2022thirty ;
huber2018bounds ; goyeneche2018entanglement ; huber2017absolutely ;
horodecki2022five ; shi2022k ; shi2023bounds ; feng2023constructions ;
zang2021quantum ; raissi2020constructions ; chen2021new ; shen2021absolutely ;
raissi2022general ; pang2021quantum ; goyeneche2016multipartite ;
pang2020multipartite . The non-negativity of quantum weight enumerators gives
some nonexistence results for $k$-uniform states and AME states
rains1999quantum ; scott2004multipartite ; huber2018bounds ; shi2022k ;
shi2023bounds . $k$-Uniform states can be used for quantum secret sharing
helwig2012absolute  and quantum information masking shi2021k . Recently,
$k$-uniform states have been proven to be useful for accelerating quantum
simulation zhao2024entanglement . In the existing literature, determining the
$k$-uniformity of an unknown state has not been thoroughly explored.

For a stabilizer code, the Shor and Laflamme enumerators describe the weight
distribution of the Pauli strings in the stabilizer group shor1997quantum .
The Rains unitary enumerators represent the sum of the subsystem purities of
the QECCs rains1999quantum . While both of these quantum enumerators have
well-defined physical counterparts, the shadow enumerators, due to its
complexity, currently lack a corresponding operational interpretation.

In this work, we build the connection between quantum weight enumerators and
the $n$-qubit parallelized SWAP test. The SWAP test can be used to calculate
the overlap between two quantum states barenco1997stabilization  and
concentratable entanglement beckey2021computable ; cullen2022calculating ;
schatzki2022hierarchy . In the $n$-qubit parallelized SWAP test of $\rho$ and
$\sigma$, we find that the probabilities and the local purities can be
converted into each other. As a consequence, we show that each probability
corresponds to a shadow enumerator, which provides a computable and
operational meaning for the shadow enumerators. Since each probability is non-
negative, we also provide an elegant proof for the shadow inequalities via
parallelized SWAP test circuits. Furthermore, we show that both the Shor-
Laflamme enumerators and the Rains unitary enumerators can be calculated from
the probabilities in the $n$-qubit parallelized SWAP test, which can be used
to determine the distances of QECCs, and the $k$-uniformity of pure states.
Finally, we analyse the robustness of the Rains enumerators when it is
calculated using the $n$-qubit parallelized SWAP test.

$\rho$ | $\sigma$ | $p(0)$ | $p(1)$ | $p(2)$ | $p(k),3\leq k\leq n$
---|---|---|---|---|---
$|0_{n}\rangle$ | $|0_{n}\rangle$ | $1$ | $0$ | $0$ | $0$
$|\mathop{\rm W}_{n}\rangle$ | $|\mathop{\rm W}_{n}\rangle$ | $\frac{n+1}{2n}$ | $0$ | $\frac{1}{n^{2}}$ | $0$
$|\mathop{\rm GHZ}_{n}\rangle$ | $|\mathop{\rm GHZ}_{n}\rangle$ | $\frac{2^{n-1}+1}{2^{n}}$ | $0$ | $\frac{1}{2^{n}}$ | $\frac{1+(-1)^{k}}{2^{n+1}}$
$|0_{n}\rangle$ | $|1_{n}\rangle$ | $\frac{1}{2^{n}}$ | $\frac{1}{2^{n}}$ | $\frac{1}{2^{n}}$ | $\frac{1}{2^{n}}$
$|\mathop{\rm W}_{n}\rangle$ | $|0_{n}\rangle$ | $\frac{1}{2}$ | $\frac{1}{2n}$ | $0$ | $0$
$|\mathop{\rm W}_{n}\rangle$ | $|1_{n}\rangle$ | $\frac{1}{2^{n-1}}$ | $\frac{n-1}{2^{n-1}n}$ | $\frac{n-2}{2^{n-1}n}$ | $\frac{n-k}{2^{n-1}n}$
$|\mathop{\rm GHZ}_{n}\rangle$ | $|0_{n}\rangle$ | $\frac{2^{n}+1}{2^{n+1}}$ | $\frac{1}{2^{n+1}}$ | $\frac{1}{2^{n+1}}$ | $\frac{1}{2^{n+1}}$
$|\mathop{\rm GHZ}_{n}\rangle$ | $|\mathop{\rm W}_{n}\rangle$ | $\frac{2^{n-2}+1}{2^{n}}$ | $\frac{2^{n-2}+n-1}{2^{n}n}$ | $\frac{n-2}{2^{n}n}$ | $\frac{n-k}{2^{n}n}$
Table 1: The probability distribution of the $n$-qubit parallelized SWAP test
of $\rho$ and $\sigma$, where
$\rho,\sigma\in\\{|0_{n}\rangle,|1_{n}\rangle,|\mathop{\rm
W}_{n}\rangle,|\mathop{\rm GHZ}_{n}\rangle\\}$ ($|0_{n}\rangle$ is the
$n$-qubit state $|0\rangle|0\rangle\cdots|0\rangle$, $|1_{n}\rangle$ is the
$n$-qubit state $|1\rangle|1\rangle\cdots|1\rangle$, $|\mathop{\rm
W}_{n}\rangle$ is the $n$-qubit W state, and $|\mathop{\rm GHZ}_{n}\rangle$ is
the $n$-qubit GHZ state). We denote $p(k)=p({\bf z})$ for $\mathop{\rm
wt}({\bf z})=k$, ${\bf z}\in\mathbb{Z}_{2}^{n}$.

The $n$-qubit parallelized SWAP test.— For a subset
$S\subseteq[n]:=\\{1,2,\ldots,n\\}$, we denote $S^{c}:=[n]\setminus S$. For a
vector ${\bf z}=(z_{1},z_{2},\ldots,z_{n})\in\mathbb{Z}_{2}^{n}$, we denote
$\mathop{\rm supp}({\bf z}):=\\{i\mid z_{i}=1,\ \text{for}\ 1\leq i\leq n\\}$,
and $\mathop{\rm wt}({\bf z}):=|\mathop{\rm supp}({\bf z})|$. Let ${\bf
u}=(u_{1},u_{2},\ldots,u_{n}),{\bf
v}=(v_{1},v_{2},\ldots,v_{n})\in\mathbb{Z}_{2}^{n}$, the inner product of
${\bf u}$ and ${\bf v}$ is ${\bf u}\cdot{\bf
v}=\sum_{i=1}^{n}u_{i}v_{i}=|\mathop{\rm supp}({\bf u})\cap\mathop{\rm
supp}({\bf v})|$. For the Hilbert space $\bigotimes_{i=1}^{n}{\cal H}_{i}$, we
assume $\mathop{\rm Dim}({\cal H}_{i})=d_{i}$ for $1\leq i\leq n$. Moreover,
the overlap between two $n$-partite states $\rho$ and $\sigma$ is defined as
$\mathop{\rm Tr}(\rho\sigma)$.

Let $\rho$ and $\sigma$ be two quantum states on $\bigotimes_{i=1}^{n}{\cal
H}_{i}$, then the $n$-qubit parallelized SWAP test for $\rho$ and $\sigma$ is
given in Fig. 1. Let $p({\bf z})$ be the probability of measuring ${\bf
z}\in\mathbb{Z}_{2}^{n}$ bitstring on the $n$ control qubits, then we can
express $p({\bf z})$ as a function of the overlaps between the reduced states
of $\rho$ and $\sigma$.

###### Proposition 1

In the $n$-qubit parallelized SWAP test of $\rho$ and $\sigma$, we have

$p({\bf z})=\frac{1}{2^{n}}\sum_{S\subseteq[n]}(-1)^{|S\cap T|}\mathop{\rm
Tr}(\rho_{S}\sigma_{S}),$ (1)

where ${\bf z}\in\mathbb{Z}_{2}^{n}$, and $T=\mathop{\rm supp}({\bf z})$.

The proof of Proposition 1 is given in Appendix. Proposition 1 extends the
results from Ref. beckey2021computable , which only considers the case when
$\rho=\sigma$ is an $n$-qubit pure state. We present some examples for the
$n$-qubit parallized SWAP test with some equal pure states and some non-equal
pure states in Table 1.

The overlap between two $n$-partite states $\rho$ and $\sigma$, i.e.
$\mathop{\rm Tr}(\rho\sigma)$ can be computed from the standard SWAP test
barenco1997stabilization ; buhrman2001quantum ; garcia2013swap ;
cincio2018learning ; harrow2013testing . Then $2^{n}$ standard SWAP tests are
needed to compute $\mathop{\rm Tr}(\rho_{T}\sigma_{T})$ for all
$T\subseteq[n]$. However, we show that only one $n$-qubit parallelized SWAP
test is enough to compute the overlap $\mathop{\rm Tr}(\rho_{T}\sigma_{T})$
for all $T\subseteq[n]$.

###### Proposition 2

Assume $\rho$ and $\sigma$ are two quantum states on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$. Let $T$ be a subset of $[n]$, then

$\mathop{\rm Tr}(\rho_{T}\sigma_{T})=\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z}),$ (2)

where ${\bf t}\in\mathbb{Z}_{2}^{n}$, and $\mathop{\rm supp}({\bf t})=T$.

The proof of Proposition 2 is given in Appendix. Note that the probability
distribution of the $n$-qubit parallelized SWAP test of $\rho$ and $\sigma$
can also be used to characterize $\rho$ and $\sigma$ to some extent. For
example, $p(0)=1$ if and only if
$\rho=\sigma=\bigotimes_{i=1}^{n}|\psi_{i}\rangle\\!\langle\psi_{i}|$; $p({\bf
z})=\frac{1}{2^{n}}$ for all ${\bf z}\in\mathbb{Z}_{2}^{n}$ if and only if
$\rho_{T}\sigma_{T}=\mathbf{0}$ for all $\emptyset\neq T\subseteq[n]$ (see
Appendix for the proof).

Figure 1: Quantum circuit for the $n$-qubit parallelized SWAP test of two
$n$-partite states $\rho$ and $\sigma$, where each $A_{i}$ is an ancilla
qubit, $H$ is a Hadamard gate, and each control swap gate is performed on
$A_{i}$, $B_{i}$, and $C_{i}$.

Connection to the shadow enumerators.— Let $M$ and $N$ be two positive
operators on $\bigotimes_{i=1}^{n}{\cal H}_{i}$, and $T$ be an arbitrary
subset of $[n]$, then the _shadow enumerator_ of $M$ and $N$ on $T$ is defined
by rains1998quantum

$S_{T}(M,N)=\sum_{S\subseteq[n]}(-1)^{|S\cap T|}\mathop{\rm Tr}({\mathop{\rm
Tr}}_{S^{c}}(M){\mathop{\rm Tr}}_{S^{c}}(N)),$ (3)

and the _shadow inequality_ is rains2000polynomial

$S_{T}(M,N)\geq 0.$ (4)

Let $\rho$ and $\sigma$ be two quantum states on $\bigotimes_{i=1}^{n}{\cal
H}_{i}$, and $T\subseteq[n]$, we can also define the _normalized shadow
enumerator_ of $\rho$ and $\sigma$ on $T$ as

$s_{T}(\rho,\sigma)=\frac{1}{2^{n}}\sum_{S\subseteq[n]}(-1)^{|S\cap
T|}\mathop{\rm Tr}(\rho_{S}\sigma_{S}),$ (5)

and the shadow inequality is equivalent to

$s_{T}(\rho,\sigma)\geq 0.$ (6)

The shadow inequalities play an important role in quantum information theory.
Firstly, the shadow inequalities give $2^{n-1}-1$ monogamy inequalities (see
Appendix),

$\sum_{S\subseteq[n]}(-1)^{|S\cap T|}C_{S|S^{c}}^{2}(|\psi\rangle)\leq 0,\
|T|\ \text{is even},\ \emptyset\neq T\subseteq[n],$ (7)

where $|\psi\rangle\in\bigotimes_{i=1}^{n}{\cal H}_{i}$,
$C_{S|S^{c}}(|\psi\rangle)=\sqrt{2(1-\mathop{\rm Tr}(\rho_{S}^{2}))}$ is the
concurrence wootters1998entanglement , and $\rho_{S}=\mathop{\rm
Tr}_{S^{c}}|\psi\rangle\\!\langle\psi|$. Specially, if $n=3$ and
$T=\\{1,2\\}$, we would obtain the triangle inequality zhu2015generalized ;
yang2022entanglement

$C_{3|12}^{2}(|\psi\rangle)\leq
C_{1|23}^{2}(|\psi\rangle)+C_{2|13}^{2}(|\psi\rangle).$ (8)

Secondly, the shadow inequalities can also be used to show some non-existence
results for AME states, which are maximally entangled across every bipartition
gisin1998bell ; higuchi2000entangled ; helwig2012absolute ; gour2010all ;
scott2004multipartite ; huber2018bounds . For example, assume $|\psi\rangle$
is an AME state in $(\mathbb{C}^{2})^{\otimes 4}$. In the shadow inequality,
let $\rho=\sigma=|\psi\rangle\\!\langle\psi|$, and $T=\\{1,2,3,4\\}$, then

$\displaystyle\sum_{S\subseteq[4]}(-1)^{|S\cap T|}\mathop{\rm
Tr}(\rho_{S}^{2})=$ $\displaystyle
1-\binom{4}{1}\times\frac{1}{2}+\binom{4}{2}\times\frac{1}{4}$ (9)
$\displaystyle-\binom{4}{3}\times\frac{1}{2}+1=-\frac{1}{2}<0.$

Hence, AME states in $(\mathbb{C}^{2})^{\otimes 4}$ do not exist
higuchi2000entangled ; huber2018bounds . Furthermore, the shadow inequalities
can be used to give some upper bounds on the distances of QECCs
rains1999quantum ; shi2023bounds .

Now, we are in a position to present our main result, which establishes the
connection between the shadow enumerators and the $n$-qubit parallelized SWAP
test.

###### Proposition 3

Let $\rho$ and $\sigma$ be two quantum states on $\bigotimes_{i=1}^{n}{\cal
H}_{i}$, and $|T|\subseteq[n]$, then

$s_{T}(\rho,\sigma)=p({\bf z}),$ (10)

where ${\bf z}\in\mathbb{Z}_{2}^{n}$, and $\mathop{\rm supp}({\bf z})=T$.

Proposition 3 is obtained from Proposition 1 and Eq. (5). According to
Proposition 3, we give a computable and operational meaning for the shadow
enumerators, i.e., the normalized shadow enumerator of $\rho$ and $\sigma$ on
$T$ is the probability of measuring ${\bf z}\in\mathbb{Z}_{2}^{n}$
($\mathop{\rm supp}({\bf z})=T$) bitstring on the $n$ control qubits in the
$n$-qubit parallelized SWAP test of $\rho$ and $\sigma$. Since $p({\bf z})\geq
0$, we also provide an elegant proof for the shadow inequalities. Furthermore,
since the $n$-qubit parallelized SWAP test can be implemented on a quantum
computer buhrman2001quantum ; garcia2013swap ; cincio2018learning ;
harrow2013testing , we can efficiently estimate the shadow enumerators. Note
that Table 1 also lists the shadow enumerators of some equal pure states and
non-equal pure states.

Connection to the Shor-Laflamme enumerators and the Rains unitary
enumerators.— For the Hilbert space $\bigotimes_{i=1}^{n}{\cal H}_{i}$, we
always assume $\mathop{\rm Dim}({\cal H}_{i})=d$ for $1\leq i\leq n$ in the
following content. Let $\\{e_{j}\\}_{j\in\mathbb{Z}_{d^{2}}}$ be an
orthonormal basis acting on ${\cal H}_{i}$ for $1\leq i\leq n$, which
satisfies $\mathop{\rm
Tr}(e_{j}^{\dagger}e_{j^{\prime}})=\delta_{jj^{\prime}}d$ and
$e_{0}=\mathbb{I}_{d}$, where $\mathbb{I}_{d}$ is the identity matrix of order
$d$. Note that $\\{e_{j}\\}_{j\in\mathbb{Z}_{d^{2}}}$ can be chosen from the
generalized Pauli matrices bertlmann2008bloch . A local error basis ${\cal
E}=\\{E_{\alpha}\\}_{\alpha\in\mathbb{Z}_{d^{2}}^{n}}$ acting on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$ consists of
$E_{\alpha}=e_{\alpha_{1}}\otimes e_{\alpha_{2}}\otimes\cdots\otimes
e_{\alpha_{n}}$, where $e_{\alpha_{i}}$ acts on ${\cal H}_{i}$ for $1\leq
i\leq n$, and
$\alpha=(\alpha_{1},\alpha_{2},\ldots,\alpha_{n})\in\mathbb{Z}_{d^{2}}^{n}$.
The weight of $E_{\alpha}$ is defined as $\mathop{\rm
wt}(E_{\alpha}):=\mathop{\rm wt}(\alpha)$. Let $\rho$ and $\sigma$ be two
quantum states on $\bigotimes_{i=1}^{n}{\cal H}_{i}$, the (unnormalized)
_Shor–Laflamme enumerators_ shor1997quantum  are defined as

$\displaystyle A_{j}(\rho,\sigma)$ $\displaystyle=\sum_{\mathop{\rm
wt}(E_{\alpha})=j,E_{\alpha}\in{\cal E}}\mathop{\rm
Tr}(E_{\alpha}\rho)\mathop{\rm Tr}(E_{\alpha}^{\dagger}\sigma);$ (11)
$\displaystyle B_{j}(\rho,\sigma)$ $\displaystyle=\sum_{\mathop{\rm
wt}(E_{\alpha})=j,E_{\alpha}\in{\cal E}}\mathop{\rm Tr}(E_{\alpha}\rho
E_{\alpha}^{\dagger}\sigma).$

The _Rains unitary enumerators_ rains1998quantum  are defined as

$\displaystyle A_{j}^{\prime}(\rho,\sigma)$
$\displaystyle=\sum_{|T|=j,T\subseteq[n]}\mathop{\rm Tr}(\rho_{T}\sigma_{T});$
(12) $\displaystyle B_{j}^{\prime}(\rho,\sigma)$
$\displaystyle=\sum_{|T|=j,T\subseteq[n]}\mathop{\rm
Tr}(\rho_{T^{c}}\sigma_{T^{c}}).$

The Shor–Laflamme enumerators shor1997quantum  and the Rains unitary
enumerators rains1998quantum  can be used to characterize QECCs. Let ${\cal
Q}$ be a subspace of $\bigotimes_{i=1}^{n}{\cal H}_{i}$ with dimension $K$,
then ${\cal Q}$ is an _$((n,K,\delta))_{d}$ QECC_ if for all states
$|\psi\rangle\in{\cal Q}$, and errors $E_{\alpha}\in{\cal E}$ with
$\mathop{\rm wt}(E_{\alpha})<\delta$,

$\langle\psi|E_{\alpha}|\psi\rangle=C(E_{\alpha}),$ (13)

where $\delta$ is called the _distance_ of the code, $C(E_{\alpha})$ is a
constant which depends only on $E_{\alpha}$. Specially, ${\cal Q}$ is called
_pure_ if $C(E_{\alpha})=\frac{\mathop{\rm Tr}(E_{\alpha})}{d^{n}}$. An
$((n,K,\delta))_{d}$ QECC can detect all the errors acting on at most
$\delta-1$ subsystems, and correct all the errors acting on at most
$\left\lfloor\frac{\delta-1}{2}\right\rfloor$ subsystems. We also denote
${\cal Q}$ as the normalized projector on this subspace. The Shor-Laflamme
enumerators (Rains unitary enumerators) of QECCs refer to $A_{j}({\cal
Q},{\cal Q})$ and $B_{j}({\cal Q},{\cal Q})$ ($A_{j}^{\prime}({\cal Q},{\cal
Q})$ and $B_{j}^{\prime}({\cal Q},{\cal Q})$). For simplicity, we denote
$A_{j}:=A_{j}({\cal Q},{\cal Q})$ and $B_{j}=B_{j}({\cal Q},{\cal Q})$
($A_{j}^{\prime}:=A_{j}^{\prime}({\cal Q},{\cal Q})$ and
$B_{j}^{\prime}=B_{j}^{\prime}({\cal Q},{\cal Q})$). The subspace ${\cal Q}$
of $\bigotimes_{i=1}^{n}{\cal H}_{i}$ with dimension $K$ is an
$((n,K,\delta))_{d}$ QECC if and only if $KB_{j}=A_{j}$ for $0<j<\delta$ (or
$KB_{\delta-1}^{\prime}=A_{\delta-1}^{\prime}$) rains1998quantum ;
scott2004multipartite . Specially, $Q$ is a pure $((n,K,\delta))_{d}$ QECC if
and only if $B_{j}=A_{j}=0$ for $0<j<\delta$ (or
$KB_{\delta-1}^{\prime}=A_{\delta-1}^{\prime}=\binom{n}{\delta-1}d^{1-\delta}$)
rains1998quantum ; scott2004multipartite . In particular, one dimensional QECC
$((n,1,\delta))_{d}$ refers only to the pure QECC.

For a stabilizer code, the Shor-Laflamme enumerator $A_{j}$ counts the number
of Pauli strings with weight $j$ in the stabilizer group, while the Shor-
Laflamme enumerator $B_{j}$ counts the same for the centralizer of the
stabilizer group rains1999quantum . For a non-stabilizer code, $A_{j}$ can be
interpreted as the two-norms of the $j$-body correlations of the code, while
$B_{j}$ can be understood as the distance enumerator of an associated
classical code 9738648 . The Rains unitary enumerators can be understood as
the binomial moments of the distance distribution for associated classical
codes ashikhmin2000quantum . The Shor-Laflamme enumerators and the Rains
unitary enumerators can be used to give some linear programming bounds for
various types of QECCs shor1997quantum ; rains1998quantum ; lai2017linear ;
grassl2017codes ; ouyang2020linear . The famous bound for an
$((n,K,\delta))_{d}$ QECC is the quantum Singltion bound: $K\leq
d^{n-2\delta+2}$, which can be also obtained from the Shor-Laflamme
enumerators and the Rains unitary enumerators rains1999nonbinary .

Based on Proposition 2, we can express both the Shor-Laflamme enumerators and
the Rains unitary enumerators as functions of the probabilities in the
$n$-qubit parallelized SWAP test.

###### Proposition 4

Assume $\rho$ and $\sigma$ are two quantum states on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$, then we have

$\displaystyle A_{j}(\rho,\sigma)=$
$\displaystyle\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\times$ (14)
$\displaystyle\sum_{\mathop{\rm wt}({\bf t})=k,{\bf
t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z});$ $\displaystyle B_{j}(\rho,\sigma)=$
$\displaystyle\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\times$
$\displaystyle\sum_{\mathop{\rm wt}({\bf t})=n-k,{\bf
t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z});$ $\displaystyle A_{j}^{\prime}(\rho,\sigma)=$
$\displaystyle\sum_{\mathop{\rm wt}({\bf t})=j,{\bf
t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z});$ $\displaystyle B_{j}^{\prime}(\rho,\sigma)=$
$\displaystyle\sum_{\mathop{\rm wt}({\bf t})=n-j,{\bf
t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z}).$

The proof of Proposition 4 is given in Appendix. Proposition 4 shows that we
can compute both the Shor–Laflamme enumerators and the Rains unitary
enumerators from the $n$-qubit parallelized SWAP test.

Determination of the distances for QECCs.— Given an unknown normalized
projector ${\cal Q}$, we can determine the distance $\delta$ of the
corresponding QECC by using the $n$-qubit parallelized SWAP test. Firstly, we
need to apply the $n$-qubit parallelized SWAP test of ${\cal Q}$ and ${\cal
Q}$ to obtain the probability distribution. Secondly, we need to calculate the
purity $\mathop{\rm Tr}({\cal Q}^{2})$ by using Proposition 2, and the
dimension of ${\cal Q}$ is equal to $\frac{1}{\mathop{\rm Tr}({\cal Q}^{2})}$.
Thirdly, we need to calculate the Rains unitary enumerators (we only consider
the Rains unitary enumerators for simplicity) by using Proposition 4. Finally,
we need to check whether $\frac{1}{\mathop{\rm Tr}({\cal
Q}^{2})}B_{\delta-1}^{\prime}=A_{\delta-1}^{\prime}$.

Next, we show an example. Given an unknown 5-qubit normalized projector ${\cal
Q}_{5}$, we want to determine its distance. Assume that we obtain the
probability distribution (shadow enumerators) from the $5$-qubit parallelized
SWAP test of ${\cal Q}_{5}$ and ${\cal Q}_{5}$: $p(0)=\frac{9}{32}$,
$p(1)=\frac{3}{64}$, $p(2)=\frac{3}{64}$, $p(3)=0$, $p(4)=0$
$p(5)=\frac{1}{64}$, where $p(k)=p({\bf z})$ for $\mathop{\rm wt}({\bf z})=k$,
${\bf z}\in\mathbb{Z}_{2}^{5}$. Then we can calculate the purity $\mathop{\rm
Tr}({\cal Q}_{5}^{2})=\frac{1}{2}$, and the dimension of ${\cal Q}_{5}$ is
$2$. By calculating the Rains unitary enumerators, we have
$2B_{2}^{\prime}=A_{2}^{\prime}=\frac{5}{2}$, and $2B_{3}^{\prime}\neq
A_{3}^{\prime}$. Thus we can determine that the distance of ${\cal Q}_{5}$ is
$3$. Actually, ${\cal Q}_{5}$ is the five-qubit code knill2001benchmarking ,
which is a pure $((5,2,3))_{2}$ QECC,

$\displaystyle{\cal Q}_{5}=$
$\displaystyle\frac{1}{32}(\mathbb{I}_{32}+XZZXI)(\mathbb{I}_{32}+IXZZX)\times$
(15) $\displaystyle(\mathbb{I}_{32}+XIXZZ)(\mathbb{I}_{32}+ZXIXZ),$

where $X,Z,I$ are the Pauli matrices. See Appendix for the complete quantum
weight enumerators of the five-qubit code $((5,2,3))_{2}$, the Steane code
$((7,2,3))_{2}$ steane1996multiple  and the Shor code $((9,2,3))_{2}$
shor1995scheme .

Determination of the $k$-uniformity for pure states— A pure $((n,1,k+1))_{d}$
QECC ${\cal Q}$ is a $k$-uniform pure state in $\bigotimes_{i=1}^{n}{\cal
H}_{i}$ scott2004multipartite ; huber2020quantum ; shi2021k , which has the
property that all its reductions to $k$ parties are maximally mixed. By using
the quantum Singlton bound, $k\leq\left\lfloor\frac{n}{2}\right\rfloor$. In
particular, a $\left\lfloor\frac{n}{2}\right\rfloor$-uniform state is an AME
state. For example, the $n$-qubit $\mathop{\rm GHZ}$ state is a $1$-uniform
state, and the $2$-qubit Bell state is an AME state. According to the previous
results, we can also determine the $k$-uniformity of an unknown pure state.
Note that, we only need to consider $A^{\prime}_{j}$, since
$A^{\prime}_{j}=B^{\prime}_{j}$ for a pure state. Given an unknown $4$-qubit
pure state $\rho_{4}=|\psi\rangle\\!\langle\psi|$, assume that we obtain the
probability distribution from the $4$-qubit parallelized SWAP test of
$\rho_{4}$ and $\rho_{4}$: $p(0)=\frac{1}{2}$,
$p(0011)=p(0110)=p(1001)=p(1100)=\frac{1}{16}$, $p(0101)=p(1010)=\frac{1}{8}$,
and $p({\bf z})=0$ for other ${\bf z}\in\mathbb{Z}_{2}^{4}$. By calculating
the Rains unitary enumerators, we have $A^{\prime}_{1}=2$,
$A_{3}^{\prime}\neq\frac{3}{2}$. Therefore, we determine that $\rho_{4}$ is a
$1$-uniform state. Actually,

$\displaystyle\rho_{4}=$
$\displaystyle\frac{1}{16}(\mathbb{I}_{16}+XZIZ)(\mathbb{I}_{16}+ZXZI)\times$
(16) $\displaystyle(\mathbb{I}_{16}+IZXZ)(\mathbb{I}_{16}+ZIZX),$

which is obtained from the graph states hein2004multiparty .

Note that one may think of directly determining the $k$-uniformity of a pure
state by calculating the local purity of the pure state on each $s$
subsystems, such as using the standard SWAP test barenco1997stabilization ;
buhrman2001quantum ; garcia2013swap ; cincio2018learning ; harrow2013testing
or two two-body gates nakazato2012measurement . However, if the local purity
is not equal to $\frac{1}{d^{s}}$, one need to compute the local purity on
each $s-1$ subsystems, and so on. This method would consume a lot of
resources. In contrast, a single $n$-qubit parallel SWAP test is sufficient to
calculate all the local purities.

Robustness of the Rains enumerators— When preparing a QECC in experiment,
noise is inevitable, which leads to a certain distance between the prepared
QECC and the target QECC. In this context, what kind of impact will this have
on the Rains enumerator? Let ${\cal Q}$ be the target QECC. In the $n$-qubit
parallelized SWAP test, we need to prepare two copies of ${\cal Q}$. By the
no-cloning theorem, we have to prepare two QECCs separately. Due to the noise,
we may prepare ${\cal Q}^{\prime}$ and ${\cal Q}^{\prime\prime}$, where the
trace distance between ${\cal Q}^{\prime}$ (${\cal Q}^{\prime\prime}$) and
${\cal Q}$ satisfies $D({\cal Q}^{\prime},{\cal Q})\leq\epsilon_{1}$ ($D({\cal
Q}^{\prime\prime},{\cal Q})\leq\epsilon_{2}$). However, if $\epsilon_{1}$ and
$\epsilon_{2}$ are small enough, then the Rains enumerators will also be very
close.

###### Proposition 5

If $D({\cal Q}^{\prime},{\cal Q})\leq\epsilon_{1}$ and $D({\cal
Q}^{\prime\prime},{\cal Q})\leq\epsilon_{2}$, then $|A^{\prime}_{j}({\cal
Q}^{\prime},{\cal Q}^{\prime\prime})-A^{\prime}_{j}({\cal Q},{\cal Q})|\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2})$ and $|B^{\prime}_{j}({\cal
Q}^{\prime},{\cal Q}^{\prime\prime})-B^{\prime}_{j}({\cal Q},{\cal Q})|\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2})$.

The proof of Proposition 5 is given in Appendix. When measuring probabilities
in the $n$-qubit parallelized SWAP test, some errors may occur, which will
also have a certain impact on the Rains enumerators. We do not intend to
discuss this issue in this work.

Conclusions.— We have built the connection between quantum weight enumerators
and the $n$-qubit parallelized SWAP test. We have shown that the shadow
enumerators correspond to the probabilities of measuring bitstrings on the $n$
control qubits of the $n$-qubit parallelized SWAP test. Additionally, we have
shown that both the Shor-Laflamme enumerators and the Rains unitary
enumerators can be expressed as functions of these probabilities. Utilizing
these functions, we have also introduced a technique to determine the
distances of QECCs and the $k$-uniformity of pure states. It is interesting to
compute the quantum weight enumerators and the distance of quantum error-
correcting codes by using our method in experiment.

Acknowledgements.— We thank Yu Ning, Wenjun Yu, Xingjian Zhang, Tianfeng Feng,
Jue Xu, and Yue Wang for their helpful discussion and suggestions. F.S., K.G.
and Q.Z. were supported HKU Seed Fund for Basic Research for New Staff via
Project 2201100596, Guangdong Natural Science Fund via Project
2023A1515012185, National Natural Science Foundation of China (NSFC) via
Project No. 12305030 and No. 12347104, Hong Kong Research Grant Council (RGC)
via No. 27300823, N_HKU718/23, and R6010-23, Guangdong Provincial Quantum
Science Strategic Initiative GDZX2200001. X.Z. was supported by the Innovation
Program for Quantum Science and Technology 2021ZD0302902, the NSFC under
Grants No. 12171452 and No. 12231014, and the National Key Research and
Development Programs of China 2023YFA1010200 and 2020YFA0713100.

## References and Notes

  * (1) P. Shor and R. Laflamme, “Quantum analog of the macwilliams identities for classical coding theory,” _Physical review letters_ , vol. 78, no. 8, p. 1600, 1997.
  * (2) E. M. Rains, “Quantum weight enumerators,” _IEEE Transactions on Information Theory_ , vol. 44, no. 4, pp. 1388–1394, 1998.
  * (3) ——, “Quantum shadow enumerators,” _IEEE transactions on information theory_ , vol. 45, no. 7, pp. 2361–2366, 1999.
  * (4) P. K. Sarvepalli, A. Klappenecker, and M. Rötteler, “Asymmetric quantum codes: constructions, bounds and performance,” _Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences_ , vol. 465, no. 2105, pp. 1645–1672, 2009.
  * (5) C.-Y. Lai and A. Ashikhmin, “Linear programming bounds for entanglement-assisted quantum error-correcting codes by split weight enumerators,” _IEEE Transactions on Information Theory_ , vol. 64, no. 1, pp. 622–639, 2017.
  * (6) M. Grassl, S. Lu, and B. Zeng, “Codes for simultaneous transmission of quantum and classical information,” in _2017 IEEE International Symposium on Information Theory (ISIT)_. IEEE, 2017, pp. 1718–1722.
  * (7) Y. Ouyang and C.-Y. Lai, “Linear programming bounds for quantum amplitude damping codes,” in _2020 IEEE International Symposium on Information Theory (ISIT)_. IEEE, 2020, pp. 1875–1879.
  * (8) A. J. Scott, “Multipartite entanglement, quantum-error-correcting codes, and entangling power of quantum evolutions,” _Physical Review A_ , vol. 69, no. 5, p. 052330, 2004.
  * (9) W. Helwig, W. Cui, J. I. Latorre, A. Riera, and H.-K. Lo, “Absolute maximal entanglement and quantum secret sharing,” _Physical Review A_ , vol. 86, no. 5, p. 052335, 2012.
  * (10) D. Goyeneche and K. Życzkowski, “Genuinely multipartite entangled states and orthogonal arrays,” _Physical review A_ , vol. 90, no. 2, p. 022316, 2014.
  * (11) K. Feng, L. Jin, C. Xing, and C. Yuan, “Multipartite entangled states, symmetric matrices, and error-correcting codes,” _IEEE Transactions on Information Theory_ , vol. 63, no. 9, pp. 5618–5627, 2017.
  * (12) M.-S. Li and Y.-L. Wang, “$k$-uniform quantum states arising from orthogonal arrays,” _Physical Review A_ , vol. 99, no. 4, p. 042332, 2019.
  * (13) Y. Zang, H. Zuo, and Z. Tian, “3-uniform states and orthogonal arrays of strength 3,” _International Journal of Quantum Information_ , vol. 17, no. 01, p. 1950003, 2019.
  * (14) S.-Q. Pang, X. Zhang, X. Lin, and Q.-J. Zhang, “Two and three-uniform states from irredundant orthogonal arrays,” _npj Quantum Information_ , vol. 5, no. 1, p. 52, 2019.
  * (15) D. Goyeneche, D. Alsina, J. I. Latorre, A. Riera, and K. Życzkowski, “Absolutely maximally entangled states, combinatorial designs, and multiunitary matrices,” _Physical Review A_ , vol. 92, no. 3, p. 032316, 2015.
  * (16) S. A. Rather, A. Burchardt, W. Bruzda, G. Rajchel-Mieldzioć, A. Lakshminarayan, and K. Życzkowski, “Thirty-six entangled officers of euler: Quantum solution to a classically impossible problem,” _Physical Review Letters_ , vol. 128, no. 8, p. 080507, 2022.
  * (17) F. Huber, C. Eltschka, J. Siewert, and O. Gühne, “Bounds on absolutely maximally entangled states from shadow inequalities, and the quantum macwilliams identity,” _Journal of Physics A: Mathematical and Theoretical_ , vol. 51, no. 17, p. 175301, 2018.
  * (18) D. Goyeneche, Z. Raissi, S. Di Martino, and K. Życzkowski, “Entanglement and quantum combinatorial designs,” _Physical Review A_ , vol. 97, no. 6, p. 062326, 2018.
  * (19) F. Huber, O. Gühne, and J. Siewert, “Absolutely maximally entangled states of seven qubits do not exist,” _Physical review letters_ , vol. 118, no. 20, p. 200502, 2017.
  * (20) P. Horodecki, Λ. Rudnicki, and K. Życzkowski, “Five open problems in quantum information theory,” _PRX Quantum_ , vol. 3, no. 1, p. 010101, 2022.
  * (21) F. Shi, Y. Shen, L. Chen, and X. Zhang, “$k$-uniform states in heterogeneous systems,” _IEEE Transactions on Information Theory_ , vol. 68, no. 5, pp. 3115–3129, 2022.
  * (22) F. Shi, Y. Ning, Q. Zhao, and X. Zhang, “Bounds on $k$-uniform quantum states,” _arXiv preprint arXiv:2310.06378v2_ , 2023.
  * (23) K. Feng, L. Jin, C. Xing, and C. Yuan, “Constructions of $k$-uniform states in heterogeneous systems,” _IEEE Transactions on Information Theory_ , 2023.
  * (24) Y. Zang, P. Facchi, and Z. Tian, “Quantum combinatorial designs and $k$-uniform states,” _Journal of Physics A: Mathematical and Theoretical_ , vol. 54, no. 50, p. 505204, 2021.
  * (25) Z. Raissi, A. Teixidó, C. Gogolin, and A. Acίn, “Constructions of $k$-uniform and absolutely maximally entangled states beyond maximum distance codes,” _Physical Review Research_ , vol. 2, no. 3, p. 033411, 2020.
  * (26) G. Chen, X. Zhang, and Y. Guo, “New results for 2-uniform states based on irredundant orthogonal arrays,” _Quantum Information Processing_ , vol. 20, pp. 1–11, 2021.
  * (27) Y. Shen and L. Chen, “Absolutely maximally entangled states in tripartite heterogeneous systems,” _Quantum Information Processing_ , vol. 20, pp. 1–23, 2021.
  * (28) Z. Raissi, A. Burchardt, and E. Barnes, “General stabilizer approach for constructing highly entangled graph states,” _Physical Review A_ , vol. 106, no. 6, p. 062424, 2022.
  * (29) S. Pang, X. Zhang, S.-M. Fei, and Z.-J. Zheng, “Quantum $k$-uniform states for heterogeneous systems from irredundant mixed orthogonal arrays,” _Quantum Information Processing_ , vol. 20, no. 4, p. 156, 2021.
  * (30) D. Goyeneche, J. Bielawski, and K. Życzkowski, “Multipartite entanglement in heterogeneous systems,” _Physical Review A_ , vol. 94, no. 1, p. 012346, 2016.
  * (31) S. Pang, X. Zhang, J. Du, and T. Wang, “Multipartite entanglement states of higher uniformity,” _Journal of Physics A: Mathematical and Theoretical_ , vol. 54, no. 1, p. 015305, 2020.
  * (32) F. Shi, M.-S. Li, L. Chen, and X. Zhang, “$k$-uniform quantum information masking,” _Physical Review A_ , vol. 104, no. 3, p. 032601, 2021.
  * (33) Q. Zhao, Y. Zhou, and A. M. Childs, “Entanglement accelerates quantum simulation,” _arXiv preprint arXiv:2406.02379_ , 2024.
  * (34) A. Barenco, A. Berthiaume, D. Deutsch, A. Ekert, R. Jozsa, and C. Macchiavello, “Stabilization of quantum computations by symmetrization,” _SIAM Journal on Computing_ , vol. 26, no. 5, pp. 1541–1557, 1997.
  * (35) J. L. Beckey, N. Gigena, P. J. Coles, and M. Cerezo, “Computable and operationally meaningful multipartite entanglement measures,” _Physical Review Letters_ , vol. 127, no. 14, p. 140501, 2021.
  * (36) A. R. Cullen and P. Kok, “Calculating concentratable entanglement in graph states,” _Physical Review A_ , vol. 106, no. 4, p. 042411, 2022.
  * (37) L. Schatzki, G. Liu, M. Cerezo, and E. Chitambar, “A hierarchy of multipartite correlations based on concentratable entanglement,” _arXiv preprint arXiv:2209.07607_ , 2022.
  * (38) H. Buhrman, R. Cleve, J. Watrous, and R. De Wolf, “Quantum fingerprinting,” _Physical Review Letters_ , vol. 87, no. 16, p. 167902, 2001.
  * (39) J. C. Garcia-Escartin and P. Chamorro-Posada, “Swap test and hong-ou-mandel effect are equivalent,” _Physical Review A_ , vol. 87, no. 5, p. 052330, 2013.
  * (40) L. Cincio, Y. Subaχsι, A. T. Sornborger, and P. J. Coles, “Learning the quantum algorithm for state overlap,” _New Journal of Physics_ , vol. 20, no. 11, p. 113022, 2018.
  * (41) A. W. Harrow and A. Montanaro, “Testing product states, quantum merlin-arthur games and tensor optimization,” _Journal of the ACM (JACM)_ , vol. 60, no. 1, pp. 1–43, 2013.
  * (42) E. M. Rains, “Polynomial invariants of quantum codes,” _IEEE Transactions on Information Theory_ , vol. 46, no. 1, pp. 54–59, 2000.
  * (43) W. K. Wootters, “Entanglement of formation of an arbitrary state of two qubits,” _Physical Review Letters_ , vol. 80, no. 10, p. 2245, 1998.
  * (44) X.-N. Zhu and S.-M. Fei, “Generalized monogamy relations of concurrence for n-qubit systems,” _Physical Review A_ , vol. 92, no. 6, p. 062345, 2015.
  * (45) X. Yang, Y.-H. Yang, and M.-X. Luo, “Entanglement polygon inequality in qudit systems,” _Physical Review A_ , vol. 105, no. 6, p. 062402, 2022.
  * (46) N. Gisin and H. Bechmann-Pasquinucci, “Bell inequality, bell states and maximally entangled states for n qubits,” _Physics Letters A_ , vol. 246, no. 1-2, pp. 1–6, 1998.
  * (47) A. Higuchi and A. Sudbery, “How entangled can two couples get?” _Physics Letters A_ , vol. 273, no. 4, pp. 213–217, 2000.
  * (48) G. Gour and N. R. Wallach, “All maximally entangled four-qubit states,” _Journal of Mathematical Physics_ , vol. 51, no. 11, 2010.
  * (49) R. A. Bertlmann and P. Krammer, “Bloch vectors for qudits,” _Journal of Physics A: Mathematical and Theoretical_ , vol. 41, no. 23, p. 235303, 2008.
  * (50) A. Nemec and A. Klappenecker, “A combinatorial interpretation for the shor-laflamme weight enumerators of cws codes,” _IEEE Transactions on Information Theory_ , vol. 68, no. 7, pp. 4549–4552, 2022.
  * (51) A. E. Ashikhmin, A. M. Barg, E. Knill, and S. N. Litsyn, “Quantum error detection. i. statement of the problem,” _IEEE transactions on information theory_ , vol. 46, no. 3, pp. 778–788, 2000.
  * (52) E. M. Rains, “Nonbinary quantum codes,” _IEEE Transactions on Information Theory_ , vol. 45, no. 6, pp. 1827–1832, 1999.
  * (53) E. Knill, R. Laflamme, R. Martinez, and C. Negrevergne, “Benchmarking quantum computers: the five-qubit error correcting code,” _Physical Review Letters_ , vol. 86, no. 25, p. 5811, 2001.
  * (54) A. Steane, “Multiple-particle interference and quantum error correction,” _Proceedings of the Royal Society of London. Series A: Mathematical, Physical and Engineering Sciences_ , vol. 452, no. 1954, pp. 2551–2577, 1996.
  * (55) P. W. Shor, “Scheme for reducing decoherence in quantum computer memory,” _Physical review A_ , vol. 52, no. 4, p. R2493, 1995.
  * (56) F. Huber and M. Grassl, “Quantum codes of maximal distance and highly entangled subspaces,” _Quantum_ , vol. 4, p. 284, 2020.
  * (57) M. Hein, J. Eisert, and H. J. Briegel, “Multiparty entanglement in graph states,” _Physical Review A_ , vol. 69, no. 6, p. 062311, 2004.
  * (58) H. Nakazato, T. Tanaka, K. Yuasa, G. Florio, and S. Pascazio, “Measurement scheme for purity based on two two-body gates,” _Physical Review A_ , vol. 85, no. 4, p. 042316, 2012.
  * (59) C. Eltschka, F. Huber, O. Gühne, and J. Siewert, “Exponentially many entanglement and correlation constraints for multipartite quantum states,” _Physical Review A_ , vol. 98, no. 5, p. 052317, 2018.
  * (60) F. Huber, “Positive maps and trace polynomials from the symmetric group,” _Journal of Mathematical Physics_ , vol. 62, no. 2, 2021.
  * (61) P. J. Coles, M. Cerezo, and L. Cincio, “Strong bound between trace distance and hilbert-schmidt distance for low-rank states,” _Physical Review A_ , vol. 100, no. 2, p. 022103, 2019.

##  Appendix A The proofs of Propositions 1 and 2

Firstly, we need to use the following two lemmas.

###### Lemma 1

rains2000polynomial  Assume $\rho$ and $\sigma$ are two quantum states on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$. Let $s_{k}$ be a swap operator that swaps
the $k$-th subsystem of $\rho$ and the $k$-th subsystem of $\sigma$, and
$(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}$, then

$\mathop{\rm Tr}\left((s_{1}^{a_{1}}\otimes s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})(\rho\otimes\sigma)\right)=\mathop{\rm Tr}(\rho_{S}\sigma_{S}),$
(17)

where $S=\mathop{\rm supp}(a_{1},a_{2},\ldots,a_{n})$.

Proof.  Here, we give a different proof from that in Ref. rains2000polynomial
. Firstly, we consider the simple case $\rho=M_{1}\otimes
M_{2}\otimes\cdots\otimes M_{n}$, and $\sigma=N_{1}\otimes
N_{2}\otimes\cdots\otimes N_{n}$. Assume
$S=\\{i_{1},i_{2},\cdots,i_{k}\\}\subseteq[n]$, and $\\{u_{k}\\}$ and
$\\{v_{k}\\}$ are two computational bases of ${\cal H}_{k}$ for $1\leq k\leq
n$. Then

$\displaystyle\mathop{\rm Tr}\left((s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})(\rho\otimes\sigma)\right)=\mathop{\rm
Tr}\left((\rho\otimes\sigma)(s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes s_{n}^{a_{n}})\right)$ (18)
$\displaystyle=\sum_{u_{1},u_{2},\ldots u_{n},v_{1},v_{2},\ldots v_{n}}\langle
u_{1}|\langle u_{2}|\cdots\langle u_{n}|\langle v_{1}|\langle
v_{2}|\cdots\langle v_{n}|(\rho\otimes\sigma)(s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})|u_{1}\rangle|u_{2}\rangle\cdots|u_{n}\rangle|v_{1}\rangle|v_{2}\rangle\cdots|v_{n}\rangle$
$\displaystyle=\sum_{u_{1},u_{2},\ldots u_{n},v_{1},v_{2},\ldots v_{n}}\langle
u_{1}|\langle u_{2}|\cdots\langle u_{n}|\langle v_{1}|\langle
v_{2}|\cdots\langle
v_{n}|\rho\otimes\sigma|u_{1}\rangle\cdots|v_{i_{1}}\rangle\cdots|v_{i_{k}}\rangle\cdots|u_{n}\rangle|v_{1}\rangle\cdots|u_{i_{1}}\rangle\cdots|u_{i_{k}}\rangle\cdots|v_{n}\rangle$
$\displaystyle=\sum_{u_{1},u_{2},\ldots u_{n},v_{1},v_{2},\ldots v_{n}}\langle
u_{1}|M_{1}|u_{1}\rangle\cdots\langle
u_{i_{1}}|M_{i_{1}}|v_{i_{1}}\rangle\langle
v_{i_{1}}|N_{i_{1}}|u_{i_{1}}\rangle\cdots\langle
u_{i_{k}}|M_{i_{k}}|v_{i_{k}}\rangle\langle
v_{i_{k}}|N_{i_{k}}|u_{i_{k}}\rangle\cdots\langle v_{n}|N_{n}|v_{n}\rangle$
$\displaystyle=\prod_{t\notin S}\mathop{\rm Tr}(M_{t})\prod_{t\notin
S}\mathop{\rm Tr}(N_{t})\prod_{t\in S}\mathop{\rm Tr}(M_{t}N_{t})$
$\displaystyle=\mathop{\rm Tr}(\rho_{S}\sigma_{S}).$

For general $\rho$ and $\sigma$, we know that
$\rho=\sum_{i}a_{i}M_{1}^{(i)}\otimes M_{2}^{(i)}\otimes\cdots\otimes
M_{n}^{(i)}$, and $\sigma=\sum_{j}b_{j}N_{1}^{(j)}\otimes
N_{2}^{(j)}\otimes\cdots\otimes N_{n}^{(j)}$. Then

$\mathop{\rm Tr}\left((s_{1}^{a_{1}}\otimes s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})(\rho\otimes\sigma)\right)=\sum_{i,j}a_{i}b_{j}\prod_{t\notin
S}\mathop{\rm Tr}(M_{t}^{(i)})\prod_{t\notin S}\mathop{\rm
Tr}(N_{t}^{(j)})\prod_{t\in S}\mathop{\rm Tr}(M_{t}^{(i)}N_{t}^{(j)}),$ (19)

and

$\displaystyle\mathop{\rm Tr}(\rho_{S}\sigma_{S})$ $\displaystyle=\mathop{\rm
Tr}\left(\left(\sum_{i}a_{i}\prod_{t\notin S}\mathop{\rm
Tr}(M_{t}^{(i)})\bigotimes_{t\in
S}M_{t}^{(i)}\right)\cdot\left(\sum_{j}b_{j}\prod_{t\notin S}\mathop{\rm
Tr}(N_{t}^{(j)})\bigotimes_{t\in S}N_{t}^{(j)}\right)\right)$ (20)
$\displaystyle=\sum_{i,j}a_{i}b_{j}\prod_{t\notin S}\mathop{\rm
Tr}(M_{t}^{(i)})\prod_{t\notin S}\mathop{\rm Tr}(N_{t}^{(j)})\prod_{t\in
S}\mathop{\rm Tr}(M_{t}^{(i)}N_{t}^{(j)})$

Therefore, we have $\mathop{\rm Tr}\left((s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})(\rho\otimes\sigma)\right)=\mathop{\rm Tr}(\rho_{S}\sigma_{S})$.

###### Lemma 2

Let ${\bf u}\in\mathbb{Z}_{2}^{n}$, then

$\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf
u}}=\left\\{\begin{array}[]{ll}0,&\text{if}\ {\bf u}\neq\mathbf{0};\\\
2^{n},&\text{if}\ {\bf u}=\mathbf{0}.\\\ \end{array}\right.$ (21)

Alternatively,

$\sum_{S\subseteq[n]}(-1)^{|S\cap T|}=\left\\{\begin{array}[]{ll}0,&\text{if}\
T\neq\emptyset;\\\ 2^{n},&\text{if}\ T=\emptyset.\\\ \end{array}\right.$ (22)

where $T\subseteq[n]$.

Proof.  If ${\bf u}=\mathbf{0}$, then it is easy to see that $\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf u}}=2^{n}$. Let
$\textbf{e}_{i}\in\mathbb{Z}_{2}^{n}$ with $\mathop{\rm
supp}(\textbf{e}_{i})=\\{i\\}$ for $1\leq i\leq n$. If ${\bf
u}\neq\mathbf{0}$, then there exists an $i\in\mathop{\rm supp}(\textbf{u})$
such that $(-1)^{\textbf{e}_{i}\cdot{\bf u}}=-1$. We have

$-\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf
u}}=(-1)^{\textbf{e}_{i}\cdot{\bf u}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf u}}=\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{(\textbf{e}_{i}+{\bf z})\cdot{\bf u}}=\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf u}}.$ (23)

Therefore, $\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf u}}=0$
if ${\bf u}\neq\mathbf{0}$.

Now, we can prove Propositions 1 and 2.

###### Proposition 1

In the $n$-qubit parallelized SWAP test of $\rho$ and $\sigma$, we have

$p({\bf z})=\frac{1}{2^{n}}\sum_{S\subseteq[n]}(-1)^{|S\cap T|}\mathop{\rm
Tr}(\rho_{S}\sigma_{S}),$ (24)

where ${\bf z}\in\mathbb{Z}_{2}^{n}$, and $T=\mathop{\rm supp}({\bf z})$.

Proof.  Assume that the spectral decompositions of $\rho$ and $\sigma$ are
$\rho=\sum_{i}p_{i}|\psi_{i}\rangle\\!\langle\psi_{i}|$ and
$\sigma=\sum_{j}q_{j}|\phi_{j}\rangle\\!\langle\phi_{j}|$ respectively, where
$0\leq p_{i},q_{j}\leq 1$, $\sum_{i}p_{i}=1$, and $\sum_{j}q_{j}=1$. Then
$\rho\otimes\sigma=\sum_{i,j}p_{i}q_{j}|\psi_{i}\rangle|\phi_{j}\rangle\langle\psi_{i}|\langle\phi_{j}|$.
In the $n$-qubit parallelized SWAP test, we only need to consider the ensemble
$\\{p_{i}q_{j},|\psi_{i}\rangle|\phi_{j}\rangle\\}$. Through the $n$-qubit
parallelized SWAP test, we have

$\displaystyle|0\rangle|0\rangle\cdots|0\rangle|\psi_{i}\rangle|\phi_{j}\rangle\xrightarrow{H}$
$\displaystyle\frac{1}{2^{\frac{n}{2}}}\sum_{(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}}|a_{1}\rangle|a_{2}\rangle\cdots|a_{n}\rangle|\psi_{i}\rangle|\phi_{j}\rangle$
$\displaystyle\xrightarrow{\text{control \ SWAP}}$
$\displaystyle\frac{1}{2^{\frac{n}{2}}}\sum_{(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}}|a_{1}\rangle|a_{2}\rangle\cdots|a_{n}\rangle((s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})|\psi_{i}\rangle|\phi_{j}\rangle)$
$\displaystyle\xrightarrow{H}$
$\displaystyle\frac{1}{2^{n}}\sum_{(b_{1},b_{2},\ldots,b_{n})\in\mathbb{Z}_{2}^{n}}\sum_{(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}}(-1)^{\sum_{i=1}^{n}a_{i}b_{i}}|b_{1}\rangle|b_{2}\rangle\cdots|b_{n}\rangle((s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}})|\psi_{i}\rangle|\phi_{j}\rangle)$ $\displaystyle=$
$\displaystyle|\Psi_{i,j}\rangle,$

where $s_{k}$ is a swap operator that swaps the $k$-th subsystem of
$|\psi_{i}\rangle$ and the $k$-th subsystem of $|\phi_{j}\rangle$ for $1\leq
k\leq n$.

Let ${\bf z}=(b_{1},b_{2},\cdots,b_{n})\in\mathbb{Z}_{2}^{n}$, then the
probability

$\displaystyle p({\bf z})=$
$\displaystyle\sum_{i,j}p_{i}q_{j}\langle\Psi_{i,j}||b_{1}\rangle\\!\langle
b_{1}|\otimes|b_{2}\rangle\\!\langle
b_{2}|\otimes\cdots\otimes|b_{n}\rangle\\!\langle
b_{n}|\otimes\mathbb{I}|\Psi_{i,j}\rangle$ $\displaystyle=$
$\displaystyle\sum_{i,j}p_{i}q_{j}\frac{1}{2^{n}}\left(\sum_{(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}}(-1)^{\sum_{i=1}^{n}a_{i}b_{i}}\langle\psi_{i}|\langle\phi_{j}|(s_{1}^{a_{1}}\otimes
s_{2}^{a_{2}}\otimes\cdots\otimes s_{n}^{a_{n}})\right)\cdot$
$\displaystyle\frac{1}{2^{n}}\left(\sum_{(c_{1},c_{2},\ldots,c_{n})\in\mathbb{Z}_{2}^{n}}(-1)^{\sum_{i=1}^{n}c_{i}b_{i}}(s_{1}^{c_{1}}\otimes
s_{2}^{c_{2}}\otimes\cdots\otimes
s_{n}^{c_{n}})|\psi_{i}\rangle|\phi_{j}\rangle\right)$ $\displaystyle=$
$\displaystyle\frac{1}{4^{n}}\sum_{(a_{1},a_{2},\ldots,a_{n})\in\mathbb{Z}_{2}^{n}}\sum_{(c_{1},c_{2},\ldots,c_{n})\in\mathbb{Z}_{2}^{n}}(-1)^{\sum_{i=1}^{n}(a_{i}+c_{i})b_{i}}\mathop{\rm
Tr}\left((s_{1}^{a_{1}+c_{1}}\otimes s_{2}^{a_{2}+c_{2}}\otimes\cdots\otimes
s_{n}^{a_{n}+c_{n}})\sum_{i,j}p_{i}q_{j}|\psi_{i}\rangle|\phi_{j}\rangle\langle\psi_{i}|\langle\phi_{j}|\right)$
$\displaystyle=$
$\displaystyle\frac{1}{2^{n}}\sum_{(d_{1},d_{2},\ldots,d_{n})\in\mathbb{Z}_{2}^{n}}(-1)^{\sum_{i=1}^{n}d_{i}b_{i}}\mathop{\rm
Tr}\left((s_{1}^{d_{1}}\otimes s_{2}^{d_{2}}\otimes\cdots\otimes
s_{n}^{d_{n}})(\rho\otimes\sigma)\right)$
$\displaystyle\xlongequal[]{\mathop{\rm
supp}(d_{1},d_{2},\cdots,d_{n})=S}\frac{1}{2^{n}}\sum_{S\subseteq[n]}(-1)^{|S\cap
T|}\mathop{\rm Tr}(\rho_{S}\sigma_{S}),$

where the last equation is obtained from Lemma 1.

###### Proposition 2

Assume $\rho$ and $\sigma$ are two quantum states on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$. Let $T$ be a subset of $[n]$, then

$\mathop{\rm Tr}(\rho_{T}\sigma_{T})=\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z}),$ (25)

where ${\bf t}\in\mathbb{Z}_{2}^{n}$, and $\mathop{\rm supp}({\bf t})=T$.

Proof.  Firstly, we need to prove a fact: assume $S,T\subseteq[n]$, then

$\sum_{R\subseteq[n]}(-1)^{|R\cap T|+|S\cap
R|}=\left\\{\begin{array}[]{ll}0,&\text{if}\ S\neq T;\\\ 2^{n},&\text{if}\
S=T.\\\ \end{array}\right.$ (26)

The proof of this fact is as follows. If $S=T$, then
$\sum_{R\subseteq[n]}1=2^{n}$. We only need to consider the case $S\neq T$.
There exist two unique vectors ${\bf u},{\bf v}\in\mathbb{Z}_{2}^{n}$, such
that $\mathop{\rm supp}({\bf u})=S$ and $\mathop{\rm supp}({\bf v})=T$. Then

$\sum_{R\subseteq[n]}(-1)^{|R\cap T|+|S\cap R|}=\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf v}+{\bf u}\cdot{\bf
z}}=\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot({\bf u}+{\bf
v})}=\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{w}},$ (27)

where $\textbf{w}={\bf u}+{\bf v}$. Since $S\neq T$, we have
$\textbf{w}\neq\mathbf{0}$. By Lemma 2, we have $\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{w}}=0$. Thus
$\sum_{R\subseteq[n]}(-1)^{|R\cap T|+|S\cap R|}=0$ for $S\neq T$.

Now, we can prove this proposition, that is

$\displaystyle\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z})=$ $\displaystyle\sum_{R\subseteq[n]}(-1)^{|R\cap
T|}\left(\frac{1}{2^{n}}\sum_{S\subseteq[n]}(-1)^{|S\cap R|}\mathop{\rm
Tr}(\rho_{S}\sigma_{S})\right)$ (28) $\displaystyle=$
$\displaystyle\frac{1}{2^{n}}\sum_{S\subseteq[n]}\sum_{R\subseteq[n]}(-1)^{|R\cap
T|+|S\cap R|}\mathop{\rm Tr}(\rho_{S}\sigma_{S})$ $\displaystyle=$
$\displaystyle\frac{1}{2^{n}}\sum_{S=T}\sum_{R\subseteq[n]}(-1)^{|R\cap
T|+|S\cap R|}\mathop{\rm Tr}(\rho_{S}\sigma_{S})$ $\displaystyle=$
$\displaystyle\mathop{\rm Tr}(\rho_{T}\sigma_{T}).$

##  Appendix B Characterizing $\rho$ and $\sigma$ from the $n$-qubit
parallelized SWAP test of $\rho$ and $\sigma$

In the $n$-qubit parallelized SWAP test of $\rho$ and $\sigma$,

  1. (i)

$p(\mathbf{0})=1$ if and only if
$\rho=\sigma=\bigotimes_{i=1}^{n}|\psi_{i}\rangle\\!\langle\psi_{i}|$;

  2. (ii)

$p({\bf z})=\frac{1}{2^{n}}$ for all ${\bf z}\in\mathbb{Z}_{2}^{n}$ if and
only if $\rho_{T}\sigma_{T}=\mathbf{0}$ for all $\emptyset\neq T\subseteq[n]$.

Proof.  (i) If
$\rho=\sigma=\bigotimes_{i=1}^{n}|\psi_{i}\rangle\\!\langle\psi_{i}|$, then
$\mathop{\rm Tr}(\rho_{T}\sigma_{T})=1$ for all $T\subseteq[n]$. Thus
$p(\mathbf{0})=1$.

If $p(\mathbf{0})=1$, then $p({\bf z})=0$ for ${\bf z}\neq\mathbf{0}$.
According to Proposition 2, we have $\mathop{\rm Tr}(\rho_{T}\sigma_{T})=1$
for all $T\subseteq[n]$. Assume
$\rho=\sum_{i}p_{i}|\psi_{i}\rangle\\!\langle\psi_{i}|$ and
$\sigma=\sum_{j}q_{j}|\phi_{j}\rangle\\!\langle\phi_{j}|$, where $0\leq
p_{i},q_{j}\leq 1$, $\sum_{i}p_{i}=1$, and $\sum_{j}q_{j}=1$. We have

$\mathop{\rm
Tr}(\rho\sigma)=\sum_{i,j}p_{i}q_{j}|\langle\psi_{i}|\phi_{j}\rangle|^{2}=1,$
(29)

then we obtain $|\langle\psi_{i}|\phi_{j}\rangle|=1$ for all $i,j$, i.e.,
$|\psi_{i}\rangle=w_{i,j}|\phi_{j}\rangle$, where $w_{i,j}\in\mathbb{C}$, and
$|w_{i,j}|=1$ for all $i,j$. This implies that $\rho=\sigma$, and $\rho$ is a
pure state. Moreover, we obtain that $\rho_{T}=\sigma_{T}$, and $\rho_{T}$ is
a pure state for all $T\subseteq[n]$. Thus there exists
$|\psi_{i}\rangle\in{\cal H}_{i}$ for $1\leq i\leq n$, such that
$\rho=\sigma=\bigotimes_{i=1}^{n}|\psi_{i}\rangle\\!\langle\psi_{i}|$.

(ii) If $\rho_{T}\sigma_{T}=\mathbf{0}$ for all $\emptyset\neq T\subseteq[n]$,
then $\mathop{\rm Tr}(\rho_{T}\sigma_{T})=0$ for all $\emptyset\neq
T\subseteq[n]$. Note that $\mathop{\rm Tr}(\rho_{T}\sigma_{T})=1$ if
$T=\emptyset$. Thus $p({\bf z})=\frac{1}{2^{n}}$ for all ${\bf
z}\in\mathbb{Z}_{2}^{n}$.

If $p({\bf z})=\frac{1}{2^{n}}$ for all ${\bf z}\in\mathbb{Z}_{2}^{n}$, then
$\mathop{\rm Tr}(\rho_{T}\sigma_{T})=\frac{1}{2^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot{\bf t}}$, where ${\bf
t}\in\mathbb{Z}_{2}^{n}$, and $\mathop{\rm supp}({\bf t})=T$. By Lemma 2, we
obtain that $\mathop{\rm Tr}(\rho_{T}\sigma_{T})=0$ for all $\emptyset\neq
T\subset[n]$. By Eq. (29), we know that if $\mathop{\rm Tr}{\rho\sigma}=0$,
then $\rho\sigma=\mathbf{0}$. Thus, $\rho_{T}\sigma_{T}=\mathbf{0}$ for all
$\emptyset\neq T\subseteq[n]$.

##  Appendix C Monogamy inequalities from the shadow inequalities

Assume $|\psi\rangle\in\bigotimes_{i=1}^{n}{\cal H}_{i}$. The concurrence
acrross the bipartition $S|S^{c}$ is defined as
$C_{S|S^{c}}(|\psi\rangle)=\sqrt{2(1-\mathop{\rm Tr}(\rho_{S}^{2}))}$
wootters1998entanglement , where $\rho_{S}=\mathop{\rm
Tr}_{S^{c}}|\psi\rangle\\!\langle\psi|$. Let $T\neq\emptyset$, then

$\sum_{S\subseteq[n]}(-1)^{|S\cap
T|}C_{S|S^{c}}^{2}(|\psi\rangle)=\sum_{S\subseteq[n]}(-1)^{|S\cap
T|}2(1-\mathop{\rm Tr}(\rho_{S}^{2}))=-2\sum_{S\subseteq[n]}(-1)^{|S\cap
T|}\mathop{\rm Tr}(\rho_{S}^{2})\leq 0.$ (30)

where the second equation is obtained from Lemma 2, and the last inequality is
from the shadow inequalities.

Therefore, the shadow inequalities give $2^{n}-1$ monogamy inequalities
eltschka2018exponentially ; huber2021positive ,

$\sum_{S\subseteq[n]}(-1)^{|S\cap T|}C_{S|S^{c}}^{2}(|\psi\rangle)\leq
0,\quad\emptyset\neq T\subseteq[n].$ (31)

Note that $C_{S|S^{c}}(|\psi\rangle)=C_{S^{c}|S}(|\psi\rangle)$. Moreover,
when $|T|$ is odd, $(-1)^{|S\cap T|}+(-1)^{|S^{c}\cap T|}=0$. Then
$\sum_{S\subseteq[n]}(-1)^{|S\cap T|}C_{S|S^{c}}^{2}(|\psi\rangle)=0$, when
$|T|$ is odd. Thus, there are $2^{n-1}-1$ monogamy inequalities,

$\sum_{S\subseteq[n]}(-1)^{|S\cap T|}C_{S|S^{c}}^{2}(|\psi\rangle)\leq
0,\quad|T|\ \text{is even},\emptyset\neq T\subseteq[n].$ (32)

##  Appendix D The proof of Proposition 4

###### Proposition 4

Assume $\rho$ and $\sigma$ are two quantum states on
$\bigotimes_{i=1}^{n}{\cal H}_{i}$, then we have

$\displaystyle A_{j}(\rho,\sigma)$
$\displaystyle=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\sum_{\mathop{\rm
wt}({\bf t})=k,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z});$ (33)
$\displaystyle B_{j}(\rho,\sigma)$
$\displaystyle=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\sum_{\mathop{\rm
wt}({\bf t})=n-k,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z});$
$\displaystyle A_{j}^{\prime}(\rho,\sigma)$ $\displaystyle=\sum_{\mathop{\rm
wt}({\bf t})=j,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z});$
$\displaystyle B_{j}^{\prime}(\rho,\sigma)$ $\displaystyle=\sum_{\mathop{\rm
wt}({\bf t})=n-j,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z}).$

Proof.  By Proposition 2, we have

$A_{j}^{\prime}(\rho,\sigma)=\sum_{|T|=j,T\subseteq[n]}\mathop{\rm
Tr}(\rho_{T}\sigma_{T})=\sum_{\mathop{\rm wt}({\bf t})=j,{\bf
t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf
z}\cdot\textbf{t}}p({\bf z}).$ (34)

According to Ref. rains1998quantum ; huber2018bounds , we know that
$B_{j}^{\prime}(\rho,\sigma)=A_{n-j}^{\prime}(\rho,\sigma)$,
$A_{j}(\rho,\sigma)=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}A_{k}^{\prime}(\rho,\sigma)$,
and
$B_{j}(\rho,\sigma)=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}B_{k}^{\prime}(\rho,\sigma)$.
Thus,

$\displaystyle B_{j}^{\prime}(\rho,\sigma)$ $\displaystyle=\sum_{\mathop{\rm
wt}({\bf t})=n-j,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z});$ (35)
$\displaystyle A_{j}(\rho,\sigma)$
$\displaystyle=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\sum_{\mathop{\rm
wt}({\bf t})=k,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z});$
$\displaystyle B_{j}(\rho,\sigma)$
$\displaystyle=\sum_{k=0}^{j}(-1)^{j-k}\binom{n-k}{j-k}d^{k}\sum_{\mathop{\rm
wt}({\bf t})=n-k,{\bf t}\in\mathbb{Z}_{2}^{n}}\sum_{{\bf
z}\in\mathbb{Z}_{2}^{n}}(-1)^{{\bf z}\cdot\textbf{t}}p({\bf z}).$

##  Appendix E Quantum weight enumerators of the five-qubit code, the Steane
code and the Shor code

$A_{j}$ | $A_{0}$ | $A_{1}$ | $A_{2}$ | $A_{3}$ | $A_{4}$ | $A_{5}$ | $A_{6}$ | $A_{7}$ | $A_{8}$ | $A_{9}$
---|---|---|---|---|---|---|---|---|---|---
${\cal Q}_{5}$ | $1$ | $0$ | $0$ | $0$ | $15$ | $0$ | $-$ | $-$ | $-$ | $-$
${\cal Q}_{7}$ | $1$ | $0$ | $0$ | $0$ | $21$ | $0$ | $42$ | $0$ | $-$ | $-$
${\cal Q}_{9}$ | $1$ | $0$ | $9$ | $0$ | $27$ | $0$ | $75$ | $0$ | $144$ | $0$
$B_{j}$ | $B_{0}$ | $B_{1}$ | $B_{2}$ | $B_{3}$ | $B_{4}$ | $B_{5}$ | $B_{6}$ | $B_{7}$ | $B_{8}$ | $B_{9}$
${\cal Q}_{5}$ | $\frac{1}{2}$ | $0$ | $0$ | $15$ | $\frac{15}{2}$ | $9$ | $-$ | $-$ | $-$ | $-$
${\cal Q}_{7}$ | $\frac{1}{2}$ | $0$ | $0$ | $\frac{21}{2}$ | $\frac{21}{2}$ | $63$ | $21$ | $\frac{45}{2}$ | $-$ | $-$
${\cal Q}_{9}$ | $\frac{1}{2}$ | $0$ | $\frac{9}{2}$ | $\frac{39}{2}$ | $\frac{27}{2}$ | $\frac{207}{2}$ | $\frac{75}{2}$ | $\frac{333}{2}$ | $72$ | $\frac{189}{2}$
$A_{j}^{\prime}$ | $A_{0}^{\prime}$ | $A_{1}^{\prime}$ | $A_{2}^{\prime}$ | $A_{3}^{\prime}$ | $A_{4}^{\prime}$ | $A_{5}^{\prime}$ | $A_{6}^{\prime}$ | $A_{7}^{\prime}$ | $A_{8}^{\prime}$ | $A_{9}^{\prime}$
${\cal Q}_{5}$ | $1$ | $\frac{5}{2}$ | $\frac{5}{2}$ | $\frac{5}{4}$ | $\frac{5}{4}$ | $\frac{1}{2}$ | $-$ | $-$ | $-$ | $-$
${\cal Q}_{7}$ | $1$ | $\frac{7}{2}$ | $\frac{21}{4}$ | $\frac{35}{8}$ | $\frac{7}{2}$ | $\frac{21}{8}$ | $\frac{7}{4}$ | $\frac{1}{2}$ | $-$ | $-$
${\cal Q}_{9}$ | $1$ | $\frac{9}{2}$ | $\frac{45}{4}$ | $\frac{147}{8}$ | $\frac{171}{8}$ | $18$ | $\frac{93}{8}$ | $\frac{45}{8}$ | $\frac{9}{4}$ | $\frac{1}{2}$
$B_{j}^{\prime}$ | $B_{0}^{\prime}$ | $B_{1}^{\prime}$ | $B_{2}^{\prime}$ | $B_{3}^{\prime}$ | $B_{4}^{\prime}$ | $B_{5}^{\prime}$ | $B_{6}^{\prime}$ | $B_{7}^{\prime}$ | $B_{8}^{\prime}$ | $B_{9}^{\prime}$
${\cal Q}_{5}$ | $\frac{1}{2}$ | $\frac{5}{4}$ | $\frac{5}{4}$ | $\frac{5}{2}$ | $\frac{5}{2}$ | $1$ | $-$ | $-$ | $-$ | $-$
${\cal Q}_{7}$ | $\frac{1}{2}$ | $\frac{7}{4}$ | $\frac{21}{8}$ | $\frac{7}{2}$ | $\frac{35}{8}$ | $\frac{21}{4}$ | $\frac{7}{2}$ | $1$ | $-$ | $-$
${\cal Q}_{9}$ | $\frac{1}{2}$ | $\frac{9}{4}$ | $\frac{45}{8}$ | $\frac{93}{8}$ | $18$ | $\frac{171}{8}$ | $\frac{147}{8}$ | $\frac{45}{4}$ | $\frac{9}{2}$ | $1$
Table 2: The Shor-Laflamme enumerators and the Rains enumerators of the five-
qubit code ${\cal Q}_{5}$, the Steane code ${\cal Q}_{7}$ and the Shor code
${\cal Q}_{9}$.

The normalized projectors of the five-qubit code $((5,2,3))_{2}$, the Steane
code $((7,2,3))_{2}$ and the Shor code $((9,2,3))_{2}$ are

$\displaystyle{\cal Q}_{5}=$
$\displaystyle\frac{1}{32}(\mathbb{I}_{32}+XZZXI)(\mathbb{I}_{32}+IXZZX)\times$
(36) $\displaystyle(\mathbb{I}_{32}+XIXZZ)(\mathbb{I}_{32}+ZXIXZ),$
$\displaystyle{\cal Q}_{7}=$
$\displaystyle\frac{1}{128}(\mathbb{I}_{128}+IIIXXXX)(\mathbb{I}_{128}+IXXIIXX)\times$
$\displaystyle(\mathbb{I}_{128}+XIXIXIX)(\mathbb{I}_{128}+IIIZZZZ)\times$
$\displaystyle(\mathbb{I}_{128}+IZZIIZZ)(\mathbb{I}_{128}+ZIZIZIZ),$
$\displaystyle{\cal Q}_{9}=$
$\displaystyle\frac{1}{512}(\mathbb{I}_{512}+ZZIIIIIII)(\mathbb{I}_{512}+ZIZIIIIII)\times$
$\displaystyle(\mathbb{I}_{512}+IIIZZIIII)(\mathbb{I}_{512}+IIIZIZIII)\times$
$\displaystyle(\mathbb{I}_{512}+IIIIIIZZI)(\mathbb{I}_{512}+IIIIIIZIZ)\times$
$\displaystyle(\mathbb{I}_{512}+XXXXXXIII)(\mathbb{I}_{512}+XXXIIIXXX),$

respectively, where $\mathbb{I}_{n}$ is the identity matrix of order $n$, and
$X,Z,I$ are the Pauli matrices. Note that the five-qubit code and the Steane
code are pure codes, and the Shor code is an impure code. In the $5$-qubit
parallelized SWAP test of ${\cal Q}_{5}$ and ${\cal Q}_{5}$, we obtain the
probability distribution (shadow enumerators): $p(0)=\frac{9}{32}$,
$p(1)=\frac{3}{64}$, $p(2)=\frac{3}{64}$, $p(5)=\frac{1}{64}$, $p({\bf z})=0$
for others. In the $7$-qubit parallelized SWAP test of ${\cal Q}_{7}$ and
${\cal Q}_{7}$, we obtain the probability distribution: $p(0)=\frac{45}{256}$,
$p(1)=\frac{3}{128}$, $p(2)=\frac{3}{128}$,
$p(0010110)=p(0011001)=p(0100101)=p(0101010)=p(1000011)=p(1001100)=p(1110000)=p(1101001)=p(1100110)=p(1011010)=p(1010101)=p(0111100)=p(0110011)=p(0001111)=\frac{3}{256}$,
$p(7)=\frac{1}{256}$, $p({\bf z})=0$ for others. The probability distribution
of the $9$-qubit parallelized SWAP test of ${\cal Q}_{9}$ and ${\cal Q}_{9}$
is as follows.

Let $A=\\{1,2,3\\}$, $B=\\{4,5,6\\}$, $C=\\{7,8,9\\}$.

$p(0)=\frac{189}{1024}.$ (37)

$p(1)=\frac{1}{64}.$ (38)

$p({\bf z}\mid\mathop{\rm wt}({\bf
z})=2)=\left\\{\begin{array}[]{ll}\frac{25}{1024}&\mathop{\rm supp}({\bf
z})\subseteq A,\ \text{or}\ \mathop{\rm supp}({\bf z})\subseteq B,\ \text{or}\
\mathop{\rm supp}({\bf z})\subseteq C;\\\ \\\ \frac{1}{256}&\text{other
cases}.\\\ \end{array}\right.$ (39)

$p({\bf z}\mid\mathop{\rm wt}({\bf
z})=3)=\left\\{\begin{array}[]{ll}\frac{1}{64}&\mathop{\rm supp}({\bf z})=A,\
\text{or}\ \mathop{\rm supp}({\bf z})=B,\ \text{or}\ \mathop{\rm supp}({\bf
z})=C;\\\ \\\ \frac{1}{1024}&|\mathop{\rm supp}({\bf z})\cap A|=1,|\mathop{\rm
supp}({\bf z})\cap B|=1,\ \text{and}\ |\mathop{\rm supp}({\bf z})\cap C|=1.\\\
\end{array}\right.$ (40)

$p({\bf z}\mid\mathop{\rm wt}({\bf
z})=4)=\left\\{\begin{array}[]{ll}\frac{1}{256}&A\subseteq\mathop{\rm
supp}({\bf z}),\ \text{or}\ B\subseteq\mathop{\rm supp}({\bf z}),\ \text{or}\
C\subseteq\mathop{\rm supp}({\bf z});\\\ \\\ \frac{5}{1024}&|\mathop{\rm
supp}({\bf z})\cap A|=2,|\mathop{\rm supp}({\bf z})\cap B|=2,\ \text{or}\
|\mathop{\rm supp}({\bf z})\cap A|=2,|\mathop{\rm supp}({\bf z})\cap C|=2,\\\
&\text{or}\ |\mathop{\rm supp}({\bf z})\cap B|=2,|\mathop{\rm supp}({\bf
z})\cap C|=2.\\\ \end{array}\right.$ (41)

$\displaystyle p({\bf z}\mid\mathop{\rm wt}({\bf z})=5)=\frac{1}{1024}$
$\displaystyle A\subseteq\mathop{\rm supp}({\bf z}),|\mathop{\rm supp}({\bf
z})\cap B|=1,|\mathop{\rm supp}({\bf z})\cap C|=1,$ (42)
$\displaystyle\text{or}\ B\subseteq\mathop{\rm supp}({\bf z}),|\mathop{\rm
supp}({\bf z})\cap A|=1,|\mathop{\rm supp}({\bf z})\cap C|=1,$
$\displaystyle\text{or}\ C\subseteq\mathop{\rm supp}({\bf z}),|\mathop{\rm
supp}({\bf z})\cap A|=1,|\mathop{\rm supp}({\bf z})\cap B|=1.$

$p({\bf z}\mid\mathop{\rm wt}({\bf
z})=6)=\left\\{\begin{array}[]{ll}\frac{1}{256}&\mathop{\rm supp}({\bf
z})=A\cup B,\ \text{or}\ \mathop{\rm supp}({\bf z})=A\cup C,\ \text{or}\
\mathop{\rm supp}({\bf z})=B\cup C;\\\ \\\ \frac{1}{1024}&|\mathop{\rm
supp}({\bf z})\cap A|=2,|\mathop{\rm supp}({\bf z})\cap B|=2,|\mathop{\rm
supp}({\bf z})\cap C|=2.\\\ \end{array}\right.$ (43)

$p({\bf z}\mid\mathop{\rm wt}({\bf z})=7)=\frac{1}{1024}\quad A\cup
B\subseteq\mathop{\rm supp}({\bf z}),\ \text{or}\ A\cup C\subseteq\mathop{\rm
supp}({\bf z}),\ \text{or}\ B\cup C\subseteq\mathop{\rm supp}({\bf z}).$ (44)

$p(9)=\frac{1}{1024}.$ (45)

$p({\bf z})=0.\quad\text{for others}$ (46)

The Shor-Laflamme enumerators and the Rains enumerators of these three codes
are given in Table 2.

##  Appendix F The proof of Proposition 5

###### Proposition 5

If $D({\cal Q}^{\prime},{\cal Q})\leq\epsilon_{1}$ and $D({\cal
Q}^{\prime\prime},{\cal Q})\leq\epsilon_{2}$, then $|A^{\prime}_{j}({\cal
Q}^{\prime},{\cal Q}^{\prime\prime})-A^{\prime}_{j}({\cal Q},{\cal Q})|\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2})$ and $|B^{\prime}_{j}({\cal
Q}^{\prime},{\cal Q}^{\prime\prime})-B^{\prime}_{j}({\cal Q},{\cal Q})|\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2})$.

Proof.  Our proof is inspired by Refs. coles2019strong ; beckey2021computable
. Let ${\cal Q}^{\prime}_{T}$ and ${\cal Q}_{T}$ be the reduced states on
subsystem $T$, then

$\displaystyle|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}^{2})-\mathop{\rm
Tr}({\cal Q}_{T}^{2})|$ $\displaystyle=|\mathop{\rm Tr}(({\cal
Q}^{\prime}_{T}+{\cal Q}_{T})({\cal Q}^{\prime}_{T}-{\cal Q}_{T}))|$ (47)
$\displaystyle\leq||{\cal Q}^{\prime}_{T}+{\cal Q}_{T}||_{2}||{\cal
Q}^{\prime}_{T}-{\cal Q}_{T}||_{2}\qquad$ Cauchy-Schwarz inequality
$\displaystyle\leq(||{\cal Q}^{\prime}_{T}||_{2}+||{\cal Q}_{T}||_{2})||{\cal
Q}^{\prime}_{T}-{\cal Q}_{T}||_{2}\qquad$ triangle inequality
$\displaystyle\leq 2||{\cal Q}^{\prime}_{T}-{\cal Q}_{T}||_{2}\qquad$ the
purity is less than or equal to 1 $\displaystyle\leq 2||{\cal
Q}^{\prime}_{T}-{\cal Q}_{T}||_{1}\qquad$ the monotonicity of the Schatten
norms $\displaystyle\leq 2||{\cal Q}^{\prime}-{\cal Q}||_{1}\qquad$ the
monotonicity of the trace norm under CPTP maps $\displaystyle=4D({\cal
Q}^{\prime},{\cal Q})\leq 4\epsilon_{1}$

Similarly, we can also show that $|\mathop{\rm Tr}({{\cal
Q}^{\prime\prime}}_{T}^{2})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|<4\epsilon_{2}$.
Note that $D({\cal Q}^{\prime},{\cal Q}^{\prime\prime})\leq D({\cal
Q}^{\prime},{\cal Q})+D({\cal Q}^{\prime\prime},{\cal
Q})\leq\epsilon_{1}+\epsilon_{2}$. Next,

$\displaystyle|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|$
$\displaystyle=|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T}-{{\cal Q}^{\prime}}_{T}^{2}+{{\cal
Q}^{\prime}}_{T}^{2}-{\cal Q}_{T}^{2})|$ (48) $\displaystyle\leq|\mathop{\rm
Tr}({{\cal Q}^{\prime}}_{T}{({\cal Q}^{\prime\prime}}_{T}-{{\cal
Q}^{\prime}}_{T}))|+|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}^{2}-{\cal
Q}_{T}^{2})|$ $\displaystyle\leq||{{\cal Q}^{\prime}}_{T}||_{2}||{{\cal
Q}^{\prime\prime}}_{T}-{{\cal Q}^{\prime}}_{T}||_{2}+4\epsilon_{1}$
$\displaystyle\leq||{{\cal Q}^{\prime\prime}}_{T}-{{\cal
Q}^{\prime}}_{T}||_{2}+4\epsilon_{1}$ $\displaystyle\leq||{{\cal
Q}^{\prime\prime}}_{T}-{{\cal Q}^{\prime}}_{T}||_{1}+4\epsilon_{1}$
$\displaystyle\leq||{{\cal Q}^{\prime\prime}}-{{\cal
Q}^{\prime}}||_{1}+4\epsilon_{1}$ $\displaystyle=2D({\cal Q}^{\prime},{\cal
Q}^{\prime\prime})+4\epsilon_{1}\leq
2(\epsilon_{1}+\epsilon_{2})+4\epsilon_{1}.$

Similiarly, $|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|=|\mathop{\rm
Tr}({{\cal Q}^{\prime}}_{T}{{\cal Q}^{\prime\prime}}_{T}-{{\cal
Q}^{\prime\prime}}_{T}^{2}+{{\cal Q}^{\prime\prime}}_{T}^{2}-{\cal
Q}_{T}^{2})|\leq 2(\epsilon_{1}+\epsilon_{2})+4\epsilon_{2}$, then

$2|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|\leq
2(\epsilon_{1}+\epsilon_{2})+4\epsilon_{1}+2(\epsilon_{1}+\epsilon_{2})+4\epsilon_{2}.$
(49)

We have

$|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|\leq
4(\epsilon_{1}+\epsilon_{2}).$ (50)

Next,

$\displaystyle|A^{\prime}_{j}({\cal Q}^{\prime},{\cal
Q}^{\prime\prime})-A^{\prime}_{j}({\cal Q},{\cal Q})|$
$\displaystyle=\left|\sum_{|T|=j,T\subseteq[n]}\mathop{\rm Tr}({{\cal
Q}^{\prime}}_{T}{{\cal Q}^{\prime\prime}}_{T}-{\cal Q}_{T}^{2})\right|$ (51)
$\displaystyle\leq\binom{n}{j}|\mathop{\rm Tr}({{\cal Q}^{\prime}}_{T}{{\cal
Q}^{\prime\prime}}_{T})-\mathop{\rm Tr}({\cal Q}_{T}^{2})|$ $\displaystyle\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2}).$

Moreover, $|B^{\prime}_{j}({\cal Q}^{\prime},{\cal
Q}^{\prime\prime})-B^{\prime}_{j}({\cal Q},{\cal Q})|=|A^{\prime}_{n-j}({\cal
Q}^{\prime},{\cal Q}^{\prime\prime})-A^{\prime}_{n-j}({\cal Q},{\cal Q})|\leq
4\binom{n}{j}(\epsilon_{1}+\epsilon_{2}).$