# Coarse-grained self-testing

Irénée Frérot<EMAIL_ADDRESS>ICFO - Institut de Ciencies
Fotoniques, The Barcelona Institute of Science and Technology, 08860
Castelldefels (Barcelona), Spain  Max-Planck-Institut für Quantenoptik, Hans-
Kopfermann-Straße 1, 85748 Garching, Germany  Antonio Acín  ICFO - Institut de
Ciencies Fotoniques, The Barcelona Institute of Science and Technology, 08860
Castelldefels (Barcelona), Spain  ICREA - Institucio Catalana de Recerca i
Estudis Avançats, Pg. Lluis Companys 23, 08010 Barcelona, Spain

###### Abstract

Self-testing is a device-independent method that usually amounts to show that
the maximal quantum violation of a Bell’s inequality certifies a unique
quantum state, up to some symmetries inherent to the device-independent
framework. In this work, we enlarge this approach and show how a coarse-
grained version of self-testing is possible in which physically relevant
properties of a many-body system are certified. To this aim we study a Bell
scenario consisting of an arbitrary number of parties and show that the
membership to a set of (entangled) quantum states whose size grows
exponentially with the number of parties can be self-tested. Specifically, we
prove that a many-body generalization of the chained Bell inequality is
maximally violated if and only if the underlying quantum state is equal, up to
local isometries, to a many-body singlet. The maximal violation of the
inequality therefore certifies any statistical mixture of the exponentially-
many orthogonal pure states spanning the singlet manifold.

Bell’s inequalities (BIs) Bell (1964) constrain the correlation patterns
achievable by any local-hidden-variables model Einstein et al. (1935). Their
violation by quantum-entangled states establishes the radically non-local
nature of quantum statistical predictions Brunner et al. (2014). Analogously,
the correlation patterns achievable by measuring quantum-entangled states are
themselves also constrained – by quantum Bell’s inequalities (qBIs) Cirel’son
(1980); Brunner et al. (2014). Since the seminal work of Bell, BIs and qBIs
have emerged as central concepts in the quest for laying the information-
theoretic foundations of quantum physics Popescu and Rohrlich (1994);
Navascués et al. (2015); and in parallel, they have proved very powerful for
characterizing quantum devices and protocols from minimal assumptions Brunner
et al. (2014). The far-reaching conclusions which can be drawn from the
violation of BIs, both from a foundational and from a quantum-certification
perspective, rely fundamentally on their device-independent nature. Namely, in
contrast to quantum tomography Paris and Rehacek (2004); Flammia and Liu
(2011), Bell tests involve solely the statistics of measurement results, and
require no assumption about the Hilbert space of the system, neither about the
observables which are actually being measured.

The device-independent nature of Bell tests makes them especially suited to
robustly certify the new generation of quantum computers and simulators, where
the qubits are effective two-level systems, requiring very careful calibration
procedures in tomography protocols. For instance, the violation of a BI
certifies the preparation of an entangled state, regardless of the correct
calibration of the measurements. Quite remarkably, the maximal quantum
violation of a BI – reaching the quantum bound allowed by qBIs – may allow one
to certify, not only the generation of entanglement, but also the preparation
of the specific quantum state and even the measurements necessarily performed
to yield the observed correlations Mayers and Yao (2003), up to symmetries
inherent to the device-independent scenario, such as, e.g., local unitaries or
complex conjugation. In essence, this so-called self-testing phenomenon Mayers
and Yao (2003); Šupić and Bowles (2020) realizes the simultaneous tomography
of both a quantum state and measurements, without prior assumptions on the
system devices.

While the self-testing phenomenon has been known for a long time for the
celebrated Clauser-Horne-Shimony-Holt BI Clauser et al. (1969) (whose maximal
violation self-tests the spin singlet
$(|\uparrow\downarrow\rangle-|\downarrow\uparrow\rangle)/\sqrt{2}$ Tsirelson
(1993); Popescu and Rohrlich (1992)), for multi-partite devices composed of
$N\gg 1$ qubits it raises formidable challenges Šupić and Bowles (2020).
Indeed, as the Hilbert space dimension grows exponentially with $N$, one can
generically expect self-testing statements, which typically involve the
fidelity with some target state, to be highly sensitive to noise, possibly
exponentially, as $N$ increases. Instead of certifying a given target many-
body quantum state Takeuchi and Morimae (2018); Mckague (2010); Baccari et al.
(2020a), it is natural in a many-body context to aim at self-testing less
specific Goh et al. (2018); Baccari et al. (2020b); Makuta and Augusiak
(2021), yet physically relevant, global properties with a much better
precision.

Figure 1: Bell scenario. We consider a scenario with $k\geq 3$ binary-outputs
observables for each subsystem. In a Bell scenario, subsystems are treated as
black boxes, generating some ouput $\sigma_{a}^{(i)}=\pm 1$ when the setting
$a$ is implemented on subsystem $i$. Our self-testing procedure involves only
very coarse-grain features of the correlations between these output: two-body
correlations summed over all pairs of subsystems. If the corresponding data
point (yellow star) reaches the quantum bound of our Bell’s inequality (red
solid line), a many-body singlet is self-tested.

Here, we show that this form of coarse-grained certification is possible by
self-testing the membership of the unknown quantum state $\hat{\rho}$ to the
exponentially-degenerate subspace spanned by all many-body singlets, that is,
zero-eigenstates of the total spin $\hat{\bf
J}^{2}=[\sum_{i=1}^{N}\hat{X}^{(i)}/2]^{2}+[\sum_{i=1}^{N}\hat{Y}^{(i)}/2]^{2}+[\sum_{i=1}^{N}\hat{Z}^{(i)}/2]^{2}$
(with $\hat{X}^{(i)}$, $\hat{Y}^{(i)}$ and $\hat{Z}^{(i)}$ Pauli matrices for
party $i$). Specifically, we construct a BI whose maximal quantum violation is
obtained only by states $\hat{\rho}$ such that ${\rm Tr}[\hat{\rho}\hat{\bf
J}^{2}]=0$. We then show that the obtained certification is robust. From a
certification perspective, many-body singlets are ground states of Heisenberg
antiferromagnets Auerbach (1994), and emerge e.g. as low-energy states in
simulators of Hubbard models Koepsell et al. (2019); Chiu et al. (2019); Sun
et al. (2021); they can also be prepared in atomic vapors using feedback
schemes Behbood et al. (2014). From a fundamental perspective, our findings
show that the boundaries of the set of quantum correlations, defined by qBIs,
may correspond to exponentially degenerate entangled subspaces, and be reached
by entangled many-body states of extensive entropy (here, any mixture of
singlets, which span a subspace of dimension ${N\choose N/2}-{N\choose
N/2-1}\sim 2^{N}\sqrt{8/(\pi N^{3})}$ Arecchi et al. (1972)).

Definition of the Bell scenario. We consider a situation where $k\geq 3$
possible measurements $\bar{\sigma}_{a}^{(i)}$ ($a\in\\{0,1,\ldots k-1\\}$)
can be performed on each subsystem (or party) $i\in\\{1,2\ldots N\\}$ ($N$ is
even), with $\pm 1$ as possible outcomes (Fig. 1). In a device-independent
scenario, the $\bar{\sigma}_{a}^{(i)}$ operators are not known – in fact, even
the Hilbert space over which they act is unknown. They obey the constraint of
having $\pm 1$ as only eigenvalues, namely they square to the identity
operator: $[\bar{\sigma}_{a}^{(i)}]^{2}=\bar{\mathbb{1}}$; furthermore,
operators acting on different parties commute:
$[\bar{\sigma}_{a}^{(i)},\bar{\sigma}_{b}^{(j)}]=0$ for all $a,b$ if $i\neq
j$. Throughout this paper, the ‘bar’ notation $\bar{\sigma}_{a}^{(i)}$
indicates that the operator acts on the uncharacterized subsystem $i$.
Instead, the notation $\hat{\sigma}_{a}^{(i)}$ will denote a qubit operator
acting on a two-level system attached to party $i$. In a practical
implementation of the self-testing procedure, the parties are (effective) two-
level systems, and the $\bar{\sigma}_{a}^{(i)}$ operators must correspond to
projective measurements at equal angles in a given plane:
$\bar{\sigma}_{a}^{(i)}\equiv\hat{Z}^{(i)}\cos(a\pi/k)+\hat{X}^{(i)}\sin(a\pi/k)$;
this property is however not assumed, but instead is self-tested by the
maximal violation of the BI. Finally, when discussing Bell’s local-variable
models, we denote as $\sigma_{a}^{(i)}=\pm 1$ the corresponding measurement
outcome, which can be interpreted as a classical (Ising) spin Fine (1982);
Braunstein and Caves (1990); Frérot and Roscilde (2021).

In order to collect the data required for our self-testing procedure, the
many-body system is identically prepared many times, varying the local
measurement settings of the parties. Two-body correlators
$\langle\bar{\sigma}_{a}^{(i)}\bar{\sigma}_{b}^{(j)}\rangle:={\rm
Tr}[\bar{\rho}\bar{\sigma}_{a}^{(i)}\bar{\sigma}_{b}^{(j)}]$ are then
collected (for $i\neq j$). The following linear combination of two-body
correlators (invariant under all permutations of the parties) is then formed
Frérot and Roscilde (2021); Müller-Rigat et al. (2020):

${\cal B}=\frac{2}{k}\sum_{a,b=0}^{k-1}S_{ab}\cos[\pi(a-b)/k]$ (1)

where $S_{ab}=\sum_{i\neq
j}\langle\bar{\sigma}_{a}^{(i)}\bar{\sigma}_{b}^{(j)}\rangle$. For $k=3$, the
quantity ${\cal B}$ is the sum over all pairs of the quantity involved in the
so-called chained BI of Pearle and Braustein-Caves Pearle (1970); Braunstein
and Caves (1990); Frérot and Roscilde (2021). The chained inequality (for any
$k\geq 3$) is already known to self-test a spin singlet for $N=2$ Šupić et al.
(2016).

Introducing the collective operators
$\bar{S_{a}}=\sum_{i=1}^{N}\bar{\sigma}_{a}^{(i)}$, we have
$S_{ab}=\langle\bar{S_{a}}\bar{S_{b}}\rangle-\sum_{i}\langle\bar{\sigma}_{a}^{(i)}\bar{\sigma}_{b}^{(i)}\rangle$.
We introduce the vector notations
$[\bar{\bm{\sigma}}^{(i)}]^{T}=(\bar{\sigma}_{0},\cdots\bar{\sigma}_{k-1})^{(i)}$
and $\bar{\bf S}^{T}=(\bar{S}_{0},\ldots\bar{S}_{k-1})$, and the matrix
$M_{ab}=(2/k)\cos[\pi(a-b)/k]$. We may then rewrite Eq. (1) as:

${\cal B}=\langle\bar{\bf S}^{T}M\bar{\bf
S}\rangle-\sum_{i=1}^{N}\langle\bar{\bm{\sigma}}^{T}M\bar{\bm{\sigma}}\rangle^{(i)}~{}.$
(2)

The matrix $M$ is diagonalized as $M={\bf c}{\bf c}^{T}+{\bf s}{\bf s}^{T}$,
where ${\bf c}^{T}=\sqrt{2/k}[\cos(a\pi/k)]_{a=0}^{k-1}$ and ${\bf
s}^{T}=\sqrt{2/k}[\sin(a\pi/k)]_{a=0}^{k-1}$ are normalized orthogonal vectors
(${\bf s}^{T}{\bf c}=0$ and ${\bf s}^{T}{\bf s}={\bf c}^{T}{\bf c}=1$). As the
matrix $M$ is a rank-2 projector, it is therefore semi-definite positive, so
that $\langle\bar{\bf S}^{T}M\bar{\bf S}\rangle\geq 0$.

######  Lemma 1.

(Classical bound of the Bell’s inequality) For any Bell’s local-variable
model, ${\cal B}\geq B_{\rm c}$, with the classical bound $B_{\rm
c}=-\frac{2N}{k\sin^{2}[\pi/(2k)]}$.

###### Proof.

Recall that in this context, the $\sigma_{a}^{(i)}=\pm 1$ are just classical
Ising spins. First, we notice that for $N$ even, one may always achieve
$S_{a}=\sum_{i=1}^{N}\sigma_{a}^{(i)}=0$ for all $a\in\\{0,\dots,k-1\\}$, and
therefore $\langle{\bf S}^{T}M{\bf S}\rangle=0$. This is achieved by choosing
a given configuration $\sigma_{a}$ on half of the parties, and the
configuration $-\sigma_{a}$ on the remaining parties. The classical bound is
then found as: $B_{\rm c}=-N\max_{\bm{\sigma}\in\\{\pm
1\\}^{k}}({\bm{\sigma}}^{T}M{\bm{\sigma}})=-(2N/k)\max_{{\bm{\sigma}}\in\\{\pm
1\\}^{k}}\left|\sum_{a=0}^{k-1}\sigma_{a}e^{ia\pi/k}\right|^{2}=-2N/(k\sin^{2}[\pi/(2k)])$,
where the maximum is achieved by choosing, for instance, all $\sigma_{a}=+1$.
∎

After deriving the classical bound for our BI, we move to the derivation of
its maximal quantum violation.

######  Lemma 2.

(Quantum bound of the Bell’s inequality) For any choice of measurements on any
quantum state, ${\cal B}\geq B_{\rm q}$, with the quantum bound $B_{\rm
q}=-Nk$.

###### Proof.

To prove that ${\cal B}\geq-Nk$, we construct the Bell operator $\bar{\cal B}$
(such that ${\cal B}=\langle\bar{\cal B}\rangle$), shifted by its claimed
quantum bound $-Nk$. Using the property
$Nk\bar{\mathbb{1}}=\sum_{i=1}^{N}\sum_{a=0}^{k-1}[\bar{\sigma}_{a}^{(i)}]^{2}=\sum_{i=1}^{N}[\bar{\bm{\sigma}}^{T}\bar{\bm{\sigma}}]^{(i)}$,
we find:

$\bar{\cal B}+Nk\bar{\mathbb{1}}=({\bf c}^{T}\bar{\bf S})^{2}+({\bf
s}^{T}\bar{\bf
S})^{2}+\sum_{i=1}^{N}[\bar{\bm{\sigma}}^{T}(\mathbb{1}-M)\bar{\bm{\sigma}}]^{(i)}~{}.$
(3)

As mentioned, $\bar{\sigma}_{a}^{(i)}$ in this expression are generic
operators in an arbitrary Hilbert space with the only constraint that
$[\bar{\sigma}_{a}^{(i)}]^{2}=\bar{\mathbb{1}}$. Since $M$ is a projector, so
is $\mathbb{1}-M$, and hence $[\mathbb{1}-M]^{2}=\mathbb{1}-M$. This
decomposition therefore realizes a so-called sum-of-squares (SOS)
decomposition of the Bell’s inequality, showing that for any quantum state
$|\psi\rangle$ and two-outcome local observables $\bar{\sigma}_{a}^{(i)}$, we
have $\langle\psi|\bar{\cal B}|\psi\rangle+Nk\geq 0$. ∎

After deriving the quantum bound, we want to show that it can be attained by
measuring a many-body singlet; and conversely, that the maximal violation
self-tests a many-body singlet. To prove this result, it is first convenient
to identify conditions implied by the maximal quantum violation of the BI. To
do so, we introduce the two operators:

$\displaystyle\bar{Z}^{(i)}:=\sqrt{2/k}~{}{\bf
c}^{T}\bar{\bm{\sigma}}^{(i)}=\frac{2}{k}\sum_{a=0}^{k-1}\bar{\sigma}_{a}^{(i)}\cos\left(\frac{a\pi}{k}\right)$
(4a) $\displaystyle\bar{X}^{(i)}:=\sqrt{2/k}~{}{\bf
s}^{T}\bar{\bm{\sigma}}^{(i)}=\frac{2}{k}\sum_{a=0}^{k-1}\bar{\sigma}_{a}^{(i)}\sin\left(\frac{a\pi}{k}\right)~{}.$
(4b)

Defining the (hermitian) operators:

$\displaystyle\bar{S}_{z}:=\sum_{i=1}^{N}\bar{Z}^{(i)}~{}~{}~{};~{}~{}~{}\bar{S}_{x}:=\sum_{i=1}^{N}\bar{X}^{(i)}$
(5a)
$\displaystyle\bar{A}_{a}^{(i)}:=\bar{\sigma}_{a}^{(i)}-\frac{2}{k}\sum_{b=0}^{k-1}\bar{\sigma}_{b}^{(i)}\cos\left(\pi\frac{a-b}{k}\right)~{},$
(5b)

the SOS decomposition Eq. (3) reads:

$\bar{\cal
B}+Nk\bar{\mathbb{1}}=\frac{k}{2}(\bar{S}_{z}^{2}+\bar{S}_{x}^{2})+\sum_{i=1}^{N}\sum_{a=0}^{k-1}[\bar{A}_{a}{(i)}]^{2}~{}.$
(6)

The following Lemma 7 shows that $\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ [Eq. (4)]
act on a quantum state reaching the quantum bound like the Pauli matrices
$\hat{Z}^{(i)}$ and $\hat{X}^{(i)}$ act on a qubit:

######  Lemma 3.

Let $|\psi\rangle$ be a quantum state s.t. $\langle\psi|\bar{\cal
B}|\psi\rangle=-Nk$. We have:

$\displaystyle[\bar{Z}^{(i)}]^{2}|\psi\rangle=[\bar{X}^{(i)}]^{2}|\psi\rangle=|\psi\rangle~{},$
(7a) $\displaystyle(\bar{Z}\bar{X}+\bar{X}\bar{Z})^{(i)}|\psi\rangle=0~{}.$
(7b)

###### Proof.

First, it is straighforward to verify that if the parties hold qubits with
measurement operators
$\bar{\sigma}_{a}^{(i)}=\hat{Z}^{(i)}\cos(a\pi/k)+\hat{X}^{(i)}\sin(a\pi/k)$,
then indeed in Eq. (4) $\bar{Z}^{(i)}=\hat{Z}^{(i)}$ and
$\bar{X}^{(i)}=\hat{X}^{(i)}$. In order to prove Lemma 7, we shall exploit
conditions imposed by the SOS decomposition Eq. (6) being zero, and that are
necessary to reach the quantum bound:
$\sum_{p}\langle\psi|\bar{O}_{p}^{\dagger}\bar{O}_{p}|\psi\rangle=0$ iff for
all $p$, $\bar{O}_{p}|\psi\rangle=0$. Our proof proceeds in two steps: 1) we
show that $[\bar{Z}^{2}+\bar{X}^{2}]^{(i)}|\psi\rangle=2|\psi\rangle$; then 2)
that
$[\bar{Z}^{2}-\bar{X}^{2}]^{(i)}|\psi\rangle=0=[\bar{Z}\bar{X}+\bar{X}\bar{Z}]^{(i)}|\psi\rangle$.

1) For a moment, we drop the superscript $(i)$; the following equalities hold
for each subsystem. We have $\bar{Z}^{2}+\bar{X}^{2}=(2/k)[({\bf
c}^{T}\bar{\bm{\sigma}})({\bf c}^{T}\bar{\bm{\sigma}})+({\bf
s}^{T}\bar{\bm{\sigma}})({\bf
s}^{T}\bar{\bm{\sigma}})]=(2/k)\bar{\bm{\sigma}}^{T}[{\bf c}{\bf c}^{T}+{\bf
s}{\bf s}^{T}]\bar{\bm{\sigma}}=(2/k)\bar{\bm{\sigma}}^{T}M\bar{\bm{\sigma}}$.
The SOS implies that
$\bar{\bm{\sigma}}^{T}M\bar{\bm{\sigma}}|\psi\rangle=\bar{\bm{\sigma}}^{T}\bar{\bm{\sigma}}|\psi\rangle$,
which is equal to $k|\psi\rangle$. This shows that
$(\bar{Z}^{2}+\bar{X}^{2})|\psi\rangle=2|\psi\rangle$.

2) The second part of the proof starts from $\bar{A}_{a}^{(j)}|\psi\rangle=0$,
where $\bar{A}_{a}^{(j)}$ is defined in Eq. (5b). Inserting the definition of
$\bar{Z}^{(j)}$ and $\bar{X}^{(j)}$ [Eq. (4)], we obtain:

$[\bar{Z}\cos(a\pi/k)+\bar{X}\sin(a\pi/k)]^{(j)}|\psi\rangle=\bar{\sigma}_{a}^{(j)}|\psi\rangle~{}.$
(8)

We use Eq. (8) in the form:

$e^{2i\pi a/k}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle=[2e^{i\pi
a/k}\bar{\sigma}_{a}-(\bar{Z}+i\bar{X})]^{(j)}|\psi\rangle~{}.$ (9)

We define the operator $\bar{R}_{a}^{(j)}=[2e^{i\pi
a/k}\bar{\sigma}_{a}-(\bar{Z}+i\bar{X})]^{(j)}$, apply $\bar{R}_{a}^{(j)}$ to
the last equality, and sum over $a$. On the r.h.s, we simply have
$\sum_{a=0}^{k-1}\bar{R}_{a}^{(j)}\bar{R}_{a}^{(j)}=-k[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}$.
On the l.h.s, we need to evaluate
$\bar{R}_{a}^{(j)}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle$. From the SOS, we have
that $\sum_{j}\bar{Z}^{(j)}|\psi\rangle=\bar{S}_{z}|\psi\rangle=0$ and also
$\sum_{j}\bar{X}^{(j)}|\psi\rangle=\bar{S}_{x}|\psi\rangle=0$. We define
$\bar{\Sigma}_{Z}^{(j)}=\sum_{j^{\prime}\neq j}\bar{Z}^{(j)}$ and
$\bar{\Sigma}_{X}^{(j)}=\sum_{j^{\prime}\neq j}\bar{X}^{(j)}$, so that
$(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle=-(\bar{\Sigma}_{Z}-i\bar{\Sigma}_{X})^{(j)}|\psi\rangle$.
As the operators $\bar{\Sigma}_{Z}^{(j)}$ and $\bar{\Sigma}_{X}^{(j)}$ act on
subsystems $j^{\prime}\neq j$, they commute with any operator acting on $j$.
Therefore:

$\displaystyle\bar{R}_{a}^{(j)}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle=-\bar{R}_{a}^{(j)}(\bar{\Sigma}_{Z}-i\bar{\Sigma}_{X})^{(j)}|\psi\rangle$
(10)
$\displaystyle=-(\bar{\Sigma}_{Z}-i\bar{\Sigma}_{X})^{(j)}\bar{R}_{a}^{(j)}|\psi\rangle$
(11) $\displaystyle=-(\bar{\Sigma}_{Z}-i\bar{\Sigma}_{X})^{(j)}e^{2i\pi
a/k}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle$ (12) $\displaystyle=-e^{2i\pi
a/k}(\bar{Z}-i\bar{X})^{(j)}(\bar{\Sigma}_{Z}-i\bar{\Sigma}_{X})^{(j)}|\psi\rangle$
(13) $\displaystyle=e^{2i\pi
a/k}(\bar{Z}-i\bar{X})^{(j)}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle$ (14)

We now have $\bar{R}_{a}^{(j)}e^{2i\pi
a/k}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle=e^{4i\pi
a/k}[\bar{Z}^{(j)}-i\bar{X}^{(j)}]^{2}|\psi\rangle$. Summing over $a$, and
using that $\sum_{a=0}^{k-1}e^{4i\pi a/k}=0$ for all $k\geq 3$, we conclude
that $[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}|\psi\rangle=0$, namely:
$[\bar{Z}^{2}-\bar{X}^{2}+i(\bar{Z}\bar{X}+\bar{X}\bar{Z})]^{(j)}|\psi\rangle=0$.
Following the same reasoning interchanging the role of
$\bar{Z}^{(j)}+i\bar{X}^{(j)}$ and $\bar{Z}^{(j)}-i\bar{X}^{(j)}$ in Eq. (9),
we also have
$[\bar{Z}^{2}-\bar{X}^{2}-i(\bar{Z}\bar{X}+\bar{X}\bar{Z})]^{(j)}|\psi\rangle=0$.
Taking the sum and difference of these two inequalities, we obtain the
announced result 2): for all subsystems $j$,
$[\bar{Z}^{2}-\bar{X}^{2}]^{(j)}|\psi\rangle=0=[\bar{Z}\bar{X}+\bar{X}\bar{Z}]^{(j)}|\psi\rangle$.
This concludes our proof of Eq. (7), namely that $\bar{Z}^{(i)}$ and
$\bar{X}^{(i)}$ act on an unkown quantum state state $|\psi\rangle$ maximally
violating the Bell’s inequality as the Pauli operators $\hat{Z}^{(i)}$ and
$\hat{X}^{(i)}$ act on a qubit. ∎

We have now derived all the ingredients needed to prove the main result of
this work, namely the self-testing of many-body singlet states.

######  Theorem 1.

The maximal violation of the BI (1), ${\cal B}=-Nk$, is attained iff the state
is (up to a local isometry mapping each party onto a qubit) a many-body
singlet, with measurements
$\hat{\sigma}_{a}^{(i)}=\hat{Z}^{(i)}\cos(a\pi/k)+\hat{X}^{(i)}\sin(a\pi/k)$.

###### Proof.

($\Leftarrow$): For qubit measurements
$\hat{\sigma}_{a}^{(i)}=\hat{Z}^{(i)}\cos\theta_{a}+\hat{X}^{(i)}\sin\theta_{a}$,
we have ${\cal
B}=4\sum_{ab}M_{ab}\langle\hat{J}_{a}\hat{J}_{b}\rangle-N\sum_{ab}M_{ab}\cos(\theta_{a}-\theta_{b})$,
where $\hat{J}_{a}=(1/2)\sum_{i}\hat{\sigma}_{a}^{(i)}$ is a collective spin
component. For a many-body singlet, we have
$\langle\hat{J}_{a}\hat{J}_{b}\rangle=0$ for any measurement directions.
Choosing $\theta_{a}=a\pi/k$, we obtain ${\cal
B}=-(Nk/2)\sum_{ab}M_{ab}^{2}=-(Nk/2){\rm Tr}(M^{2})=-Nk$.

($\Rightarrow$): To prove the self-testing statement of Theorem 1, we use
Lemma 7 to construct the the so-called partial SWAP gate, the said isometry
mapping each party onto a qubit. As illustrated in Fig. 2, an extra qubit in
state $|+\rangle=(|0\rangle+|1\rangle)/\sqrt{2}$ is attached to each party,
and we apply locally:

$\displaystyle\Phi_{i}[\bar{\rho}_{i}]={\rm Tr}_{\rm
b.b}[\hat{U}^{(i)}(|+\rangle\langle+|\otimes\bar{\rho}_{i})(\hat{U}^{(i)})^{\dagger}]$
(15) $\displaystyle{\rm
with}~{}~{}\hat{U}^{(i)}=(c{\bar{X}}^{(i)})(\hat{H}\otimes\bar{\mathbb{1}})(c{\bar{Z}}^{(i)})$

where $\hat{H}$ is the Hadamard gate on the ancillary qubit, and ${\rm
Tr}_{\rm b.b}$ denotes a trace over black box $i$, namely the local degrees of
freedom which are not the qubit; and operator $c\bar{X}^{(i)}$ [resp.
$c\bar{Z}^{(i)}$] is a control-$\bar{X}^{(i)}$ gate [resp.
control-$\bar{Z}^{(i)}$], where the control is on the state of qubit $i$. The
SWAP gate consists in applying the partial SWAP gate to each party:
$\Phi=\otimes_{i=1}^{N}\Phi_{i}$.

Figure 2: Partial SWAP gate. To each party (black box), initially in the
(unknown) state $\bar{\rho_{i}}$, an ancillary qubit is attached and
initialized in the state $|+\rangle=(|0\rangle+|1\rangle)/\sqrt{2}$. The
partial SWAP gate is realized by successively applying a
control-$\bar{Z}^{(i)}$ gate, a Hadamard gate on the qubit, and a
control-$\bar{X}^{(i)}$ gate [$\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ are defined
in Eq. (4)]. The gate is completed by tracing over the black-box degrees of
freedom.

Now, let $\bar{\rho}$ be a quantum state reaching the quantum bound of the BI.
As discussed in See the Supplemental Material for: 1) a derivation of the
robustness statement [Eq. ()]; 2) a derivation of the generalized self-testing
statement based on Eq. (). , this implies that $\bar{Z}^{(i)}$ and
$\bar{X}^{(i)}$ act as unitaries, so that $\Phi_{i}$ (and $\Phi$) are
isometries; in the general case, $\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ must be
properly regularized See the Supplemental Material for: 1) a derivation of the
robustness statement [Eq. ()]; 2) a derivation of the generalized self-testing
statement based on Eq. (). . We then define the $N$-qubit state
$\hat{\rho}:=\Phi[\bar{\rho}]$, and show that $\hat{\rho}$ is a many-body
singlet. A key property is that applying $\bar{X}^{(i)}$ [resp.
$\bar{Z}^{(i)}$] to black box $i$ before applying the partial-SWAP gate is
equivalent to applying the Pauli operators $\hat{X}^{(i)}$ [resp.
$\hat{Z}^{(i)}$] to qubit $i$ after the partial-SWAP gate:
$\Phi[\bar{X}^{(i)}\bar{\rho}]=\hat{X}^{(i)}\hat{\rho}$ (and similarly for
$Z$). This can be checked by direct inspection of the partial SWAP gate, using
Lemma 7. Maximal violation of the BI also implies, via Eq. (6),
$\sum_{i=1}^{N}\bar{Z}^{(i)}\bar{\rho}=\bar{S}_{z}\bar{\rho}=0=\sum_{i=1}^{N}\bar{X}^{(i)}\bar{\rho}=\bar{S}_{x}\bar{\rho}$.
The same property holds after the SWAP gate:
$\hat{J}_{x}\hat{\rho}=\hat{J}_{z}\hat{\rho}=0$, where
$\hat{J}_{x}=\sum_{i=1}^{N}\hat{X}^{(i)}/2$ and
$\hat{J}_{z}=\sum_{i=1}^{N}\hat{Z}^{(i)}/2$ are collective spin observables
for the $N$ qubits. Since $[\hat{J}_{z},\hat{J}_{x}]=i\hat{J}_{y}$, this
implies in turn $\hat{J}_{y}\hat{\rho}=0$, or equivalently ${\rm Tr}[\hat{\bf
J}^{2}\hat{\rho}]=0$. Hence, maximal quantum violation of the BI self-tests a
many-body singlet, as announced as the main result of our paper. Additionally,
the measurements are also self-tested: as a consequence of Eq. (8), saturating
the quantum bound implies that the $\bar{\sigma}_{a}^{(i)}$ operators act on
the state like equispaced spin measurements in the $xz$ plane (a property
already proved for the chained inequality Pearle (1970); Braunstein and Caves
(1990) in the $N=2$ case Šupić et al. (2016)). This concludes the proof of
Theorem 1. ∎

Robustness. A self-testing statement can also be obtained for non-maximal
quantum violations. A robust self-testing statement consists in establishing
that if $\langle\bar{\cal B}\rangle+Nk\leq kN\epsilon$, then it is possible to
define global spin operators such that
$\langle\hat{J}_{z}^{2}+\hat{J}_{x}^{2}\rangle\leq f(N,\epsilon)$, with a
certain function $f$ such that $f(N,0)=0$. In See the Supplemental Material
for: 1) a derivation of the robustness statement [Eq. ()]; 2) a derivation of
the generalized self-testing statement based on Eq. (). , we establish such a
robustness statement, with a bound of the form:

$\langle\hat{J}_{z}^{2}+\hat{J}_{x}^{2}\rangle\leq\frac{N^{2}\epsilon}{4}\left[\sqrt{2/N}+\sqrt{r}\right]^{2}$
(16)

with $r\approx 752$ a numerical constant. For $N\to\infty$, the bound on
$\langle\hat{J}_{z}^{2}+\hat{J}_{x}^{2}\rangle$ scales as $O(N^{2}\epsilon)$

It is an open question whether this scaling could be improved. When
considering the qubit realisation leading to the maximal quantum violation,
from Eq. (6), it is clear that if one measures a $N$-qubit state along
$\hat{\sigma}_{a}^{(i)}=\hat{Z}^{(i)}\cos(a\pi/k)+\hat{X}^{(i)}\sin(a\pi/k)$,
then one obtains:

${\cal
B}+Nk=\frac{k}{2}\left\langle\left[\sum_{i=1}^{N}\hat{Z}^{(i)}\right]^{2}+\left[\sum_{i=1}^{N}\hat{X}^{(i)}\right]^{2}\right\rangle=2k\langle\hat{J}_{z}^{2}+\hat{J}_{x}^{2}\rangle~{}.$
(17)

In a real experiment, the preparation of a many-body singlet is not perfect,
and we have $2\langle\hat{J}_{z}^{2}+\hat{J}_{x}^{2}\rangle=\epsilon N$ with a
small, but finite $\epsilon$, yielding ${\cal B}+Nk=kN\epsilon$, that is a
$O(N\epsilon)$ scaling. Although this scaling assumes noiseless qubit
measurements, it suggests that the robustness bound (16) might be improved,
either using analytical techniques such as in See the Supplemental Material
for: 1) a derivation of the robustness statement [Eq. ()]; 2) a derivation of
the generalized self-testing statement based on Eq. (). , or resorting to
numerical techniques Yang et al. (2014).

Generalization. The self-testing scheme we have described can be extended to
certify more general coarse-grained features of the quantum state. Introducing
arbitrary local phases $\phi_{i}$, one considers the following quantity:

${\cal B}=\frac{2}{k}\sum_{a,b=0}^{k-1}\sum_{i\neq
j}\langle\bar{\sigma}_{a}^{(i)}\bar{\sigma}_{b}^{(j)}\rangle\cos[\pi(a-b)/k+\phi_{i}-\phi_{j}]~{}.$
(18)

In See the Supplemental Material for: 1) a derivation of the robustness
statement [Eq. ()]; 2) a derivation of the generalized self-testing statement
based on Eq. (). , we show that the above derivation presented for
$\phi_{i}=0$ can be extended to arbitrary $\phi_{i}$’s. The quantum bound for
Eq. (18) is also $-Nk$ and reaching it self-tests the property:
$\sum_{i,j}\cos(\phi_{i}-\phi_{j})\langle\hat{X}^{(i)}\hat{X}^{(j)}+\hat{Z}^{(i)}\hat{Z}^{(j)}\rangle=0$.
The self-tested measurements are the same as for $\phi_{i}=0$ (namely:
equally-spaced qubit measurements in the $xz$ plane). Equivalently, the BIs
described by Eq. (18) allow self-testing a many-body singlet on which local
rotations by angles $\phi_{i}$ around the $y$ axis have been performed, in the
same measurement setting.

Conclusions. The certification of quantum many-body systems is a timely
problem for which the device-independent framework provides useful tools, as
the certification does not rely on any assumptions on the devices. Self-
testing, possibly the strongest form of device-independent certification, has
so far focused on certifying unique, modulo some local operations, quantum
state and measurement operators. However, in a many-body context, it may be
useful to consider coarse-grained variants of self-testing, in which only some
physical properties of interest are certified from the observed statistics. In
this work we demonstrate the validity of this approach by showing how to self-
test, in a robust way, many-body singlets, defined by the sole condition ${\rm
Tr}[\hat{\rho}(\hat{J}_{x}^{2}+\hat{J}_{y}^{2}+\hat{J}_{z}^{2})]=0$ with
$\hat{\bf J}$ the collective spin. This very coarse-grain condition can be met
by states which are statistical mixtures of exponentially-many orthogonal pure
states, spanning the singlet manifold. To our knowledge, this represents the
first self-testing example of this kind, opening a new paradigm for the
certification of many-body quantum devices.

In itself, that such coarse-grain certification is simply possible represents
an intriguing result. Our specific self-testing scheme could already be
implemented in several platform able to implement individual qubit
measurements, and to prepare many-body singlets (either by cooling a trapped
Fermi gas interacting via a Hubbard-like Hamiltonian Koepsell et al. (2019);
Chiu et al. (2019), or by adiabatically preparing the ground state of an
antiferromagnetic Heisenberg model in a qubit ensemble Sun et al. (2021)),
which would demonstrate a supreme form of control over an entangled quantum
many-body system. More generally, it is an outstanding question to understand
the possibilities and limitations of this coarse-grain approach, and identify
other relevant properties, of the form $\langle\hat{O}\rangle=0$ with
$\hat{O}$ a positive semidefinite many-body observable, that can be robustly
self-tested. In our example, a key aspect is that the matrix $M$, defining the
BI via Eq. (2), is a projector. This suggests to replace $M$ by a more general
projector, or by a more general positive semidefinite matrix. A second
extension is to introduce spatial modulation in the coefficients of the BI,
and we presented a first result in this direction in Eq. (18).

###### Acknowledgements.

We acknowledge support from the Government of Spain (FIS2020-TRANQI and Severo
Ochoa CEX2019-000910-S), Generalitat de Catalunya (CERCA, AGAUR SGR 1381 and
QuantumCAT), the Fundació Cellex and Fundació Mir-Puig through an ICFO-MPQ
Postdoctoral Fellowship, ERC AdG CERQUTE, the AXA Chair in Quantum Information
Science.

## References

  * Bell (1964) J. S. Bell, Physics Physique Fizika 1, 195 (1964), URL https://link.aps.org/doi/10.1103/PhysicsPhysiqueFizika.1.195.
  * Einstein et al. (1935) A. Einstein, B. Podolsky, and N. Rosen, Phys. Rev. 47, 777 (1935), URL http://link.aps.org/doi/10.1103/PhysRev.47.777.
  * Brunner et al. (2014) N. Brunner, D. Cavalcanti, S. Pironio, V. Scarani, and S. Wehner, Rev. Mod. Phys. 86, 419 (2014), eprint arXiv: https://arxiv.org/abs/1303.2849, URL http://link.aps.org/doi/10.1103/RevModPhys.86.419.
  * Cirel’son (1980) B. S. Cirel’son, Letters in Mathematical Physics 4, 93 (1980), URL https://link.springer.com/article/10.1007/BF00417500.
  * Popescu and Rohrlich (1994) S. Popescu and D. Rohrlich, Foundations of Physics 24, 379 (1994), eprint arXiv: https://arxiv.org/abs/quant-ph/9508009, URL https://link.springer.com/article/10.1007%252FBF02058098.
  * Navascués et al. (2015) M. Navascués, Y. Guryanova, M. J. Hoban, and A. Acín, Nature communications 6, 1 (2015), eprint arXiv: https://arxiv.org/abs/1403.4621.
  * Paris and Rehacek (2004) M. Paris and J. Rehacek, _Quantum State Estimation_ , Lecture Notes in Physics (Springer Berlin Heidelberg, 2004), ISBN 9783540223290, URL https://www.springer.com/gp/book/9783540223290.
  * Flammia and Liu (2011) S. T. Flammia and Y.-K. Liu, Phys. Rev. Lett. 106, 230501 (2011), eprint arXiv: https://arxiv.org/abs/1104.4695, URL https://link.aps.org/doi/10.1103/PhysRevLett.106.230501.
  * Mayers and Yao (2003) D. Mayers and A. Yao, _Self testing quantum apparatus_ (2003), eprint quant-ph/0307205, URL https://arxiv.org/abs/quant-ph/0307205.
  * Šupić and Bowles (2020) I. Šupić and J. Bowles, Quantum 4, 337 (2020), ISSN 2521-327X, URL https://doi.org/10.22331/q-2020-09-30-337.
  * Clauser et al. (1969) J. F. Clauser, M. A. Horne, A. Shimony, and R. A. Holt, Phys. Rev. Lett. 23, 880 (1969), URL https://link.aps.org/doi/10.1103/PhysRevLett.23.880.
  * Tsirelson (1993) B. S. Tsirelson, Hadronic J. Suppl. 8, 329?345 (1993), URL https://www.tau.ac.il/~tsirel/download/hadron.pdf.
  * Popescu and Rohrlich (1992) S. Popescu and D. Rohrlich, Physics Letters A 169, 411 (1992), ISSN 0375-9601, URL http://www.sciencedirect.com/science/article/pii/0375960192908198.
  * Takeuchi and Morimae (2018) Y. Takeuchi and T. Morimae, Phys. Rev. X 8, 021060 (2018), URL https://link.aps.org/doi/10.1103/PhysRevX.8.021060.
  * Mckague (2010) M. Mckague, _Self-testing graph states_ (2010), eprint 1010.1989, URL https://arxiv.org/abs/1010.1989.
  * Baccari et al. (2020a) F. Baccari, R. Augusiak, I. Šupić, J. Tura, and A. Acín, Phys. Rev. Lett. 124, 020402 (2020a), eprint arXiv: https://arxiv.org/abs/1812.10428, URL https://link.aps.org/doi/10.1103/PhysRevLett.124.020402.
  * Goh et al. (2018) K. T. Goh, J. m. k. Kaniewski, E. Wolfe, T. Vértesi, X. Wu, Y. Cai, Y.-C. Liang, and V. Scarani, Phys. Rev. A 97, 022104 (2018), URL https://link.aps.org/doi/10.1103/PhysRevA.97.022104.
  * Baccari et al. (2020b) F. Baccari, R. Augusiak, I. Šupić, and A. Acín, Phys. Rev. Lett. 125, 260507 (2020b), eprint arXiv: https://arxiv.org/abs/2003.02285, URL https://link.aps.org/doi/10.1103/PhysRevLett.125.260507.
  * Makuta and Augusiak (2021) O. Makuta and R. Augusiak, New Journal of Physics 23, 043042 (2021), ISSN 1367-2630, URL http://dx.doi.org/10.1088/1367-2630/abee40.
  * Auerbach (1994) A. Auerbach, _Interacting Electrons and Quantum Magnetism_ , Graduate Texts in Contemporary Physics (Springer-Verlag, New York, 1994), ISBN 978-0-387-94286-5, URL https://www.springer.com/gp/book/9780387942865.
  * Koepsell et al. (2019) J. Koepsell, J. Vijayan, P. Sompet, F. Grusdt, T. A. Hilker, E. Demler, G. Salomon, I. Bloch, and C. Gross, Nature 572, 358 (2019), ISSN 1476-4687, number: 7769 Publisher: Nature Publishing Group, eprint arXiv: https://arxiv.org/abs/1811.06907, URL http://www.nature.com/articles/s41586-019-1463-1.
  * Chiu et al. (2019) C. S. Chiu, G. Ji, A. Bohrdt, M. Xu, M. Knap, E. Demler, F. Grusdt, M. Greiner, and D. Greif, Science 365, 251 (2019), ISSN 0036-8075, eprint arXiv: https://arxiv.org/abs/1810.03584, URL https://science.sciencemag.org/content/365/6450/251.
  * Sun et al. (2021) H. Sun, B. Yang, H.-Y. Wang, Z.-Y. Zhou, G.-X. Su, H.-N. Dai, Z.-S. Yuan, and J.-W. Pan, Nature Physics 17, 990–994 (2021), ISSN 1745-2481, URL http://dx.doi.org/10.1038/s41567-021-01277-1.
  * Behbood et al. (2014) N. Behbood, F. Martin Ciurana, G. Colangelo, M. Napolitano, G. Tóth, R. Sewell, and M. Mitchell, Physical Review Letters 113, 093601 (2014), publisher: American Physical Society, eprint arXiv: https://arxiv.org/abs/1403.1964, URL https://link.aps.org/doi/10.1103/PhysRevLett.113.093601.
  * Arecchi et al. (1972) F. T. Arecchi, E. Courtens, R. Gilmore, and H. Thomas, Phys. Rev. A 6, 2211 (1972), URL https://link.aps.org/doi/10.1103/PhysRevA.6.2211.
  * Fine (1982) A. Fine, Phys. Rev. Lett. 48, 291 (1982), URL https://link.aps.org/doi/10.1103/PhysRevLett.48.291.
  * Braunstein and Caves (1990) S. L. Braunstein and C. M. Caves, Annals of Physics 202, 22 (1990), ISSN 0003-4916, URL http://www.sciencedirect.com/science/article/pii/000349169090339P.
  * Frérot and Roscilde (2021) I. Frérot and T. Roscilde, Phys. Rev. Lett. 126, 140504 (2021), eprint arXiv: https://arxiv.org/abs/2004.07796, URL https://link.aps.org/doi/10.1103/PhysRevLett.126.140504.
  * Müller-Rigat et al. (2020) G. Müller-Rigat, A. Aloy, M. Lewenstein, and I. Frérot, _Many-body bell’s inequalities from average two-body correlations_ (2020), eprint 2012.08474, URL https://arxiv.org/abs/2012.08474.
  * Pearle (1970) P. M. Pearle, Phys. Rev. D 2, 1418 (1970), URL https://link.aps.org/doi/10.1103/PhysRevD.2.1418.
  * Šupić et al. (2016) I. Šupić, R. Augusiak, A. Salavrakos, and A. Acín, New Journal of Physics 18, 035013 (2016), eprint arXiv: https://arxiv.org/abs/1511.09220, URL https://doi.org/10.1088%2F1367-2630%2F18%2F3%2F035013.
  * (32) See the Supplemental Material for: 1) a derivation of the robustness statement [Eq. (16)]; 2) a derivation of the generalized self-testing statement based on Eq. (18).
  * Yang et al. (2014) T. H. Yang, T. Vértesi, J.-D. Bancal, V. Scarani, and M. Navascués, Phys. Rev. Lett. 113, 040401 (2014), eprint arXiv: https://arxiv.org/abs/1406.7127, URL https://link.aps.org/doi/10.1103/PhysRevLett.113.040401.

##  Appendix A Robustness

In this Appendix, we derive the robustness bound for the self-testing of the
many-body singlet state.

###  A.1 SWAP unitary

The SWAP unitary is based on the operators
$\bar{Z}^{(i)}=(2/k)\sum_{a=0}^{k-1}\sigma_{a}^{(i)}\cos(a\pi/k)$ and
$\bar{X}^{(i)}=(2/k)\sum_{a=0}^{k-1}\sigma_{a}^{(i)}\sin(a\pi/k)$, where
$i=1,\dots N$ labels the $i$-th party. To make the SWAP gate unitary, these
operators must first be regularized in order to make them unitary. In the main
text, we did not need to regularize these operators, as their unitary
character was an implicit consequence of the maximal violation of the Bell’s
inequality. The regularization is obtained in the following manner. First, we
notice that $\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ are hermitian by construction.
They therefore admit the following eigenvalue decomposition:
$\bar{Z}^{(i)}=\sum_{\alpha}P_{\alpha}\lambda_{\alpha}$ (and similarly for
$\bar{X}^{(i)}$), where $\\{P_{\alpha}\\}$ are paiwise orthogonal projectors
($P_{\alpha}P_{\beta}=P_{\alpha}\delta_{\alpha,\beta}$) summing to the
identity ($\sum_{\alpha}P_{\alpha}=\mathbb{1}$), and
$\lambda_{\alpha}\in\mathbb{R}$ are the corresponding eigenvalues. We then
define $\tilde{Z}^{(i)}=\sum_{\alpha}P_{\alpha}{\rm sign}(\lambda_{\alpha})$
(with the convention ${\rm sign}(0)=1$), which are unitary operators
($[\tilde{Z}^{(i)}]^{2}=\mathbb{1}$, and similarly
$[\tilde{X}^{(i)}]^{2}=\mathbb{1}$).
Adding an ancillary qubit initialized in $|+\rangle_{i}$ to each party, the
partial SWAP gate is defined as
$\Phi_{i}=(c\tilde{X}^{(i)})(H\otimes\mathbb{1})(c\tilde{Z}^{(i)})$, where $H$
is the Hadamard gate on the qubit, and $cA^{(i)}$ is the control-$A^{(i)}$
gate (with $A=X,Z$), where the control is on the qubit state. $\Phi_{i}$ is a
unitary transformation. The full SWAP gate is obtained by applying the partial
SWAP gate to all parties: $U_{\Phi}=\otimes_{i=1}^{N}\Phi_{i}$, which is also
unitary. Notice that the definition of the SWAP gate used in the robustness
proof is slightly different from the definition used in the main text: in the
main text, we introduced a partial trace over the black-box degrees of
freedom. Here, in contrast, we do not take the partial trace, and consider
instead a unitary transformation. The two definitions lead however to
equivalent statements.

###  A.2 Definition of the robustness problem

We define the collective spin observables for the qubits:

$\displaystyle S_{x}:=\sum_{i=1}^{N}X^{(i)}\otimes\mathbb{1}$ (19)
$\displaystyle S_{z}:=\sum_{i=1}^{N}Z^{(i)}\otimes\mathbb{1}$ (20)

where $X^{(i)}$ and $Z^{(i)}$ are the local Pauli matrices, and the identity
operator acts on the black-box degrees of freedom. Similarly, we define the
operators:

$\displaystyle\bar{S}_{x}:=\sum_{i=1}^{N}\mathbb{1}\otimes\bar{X}^{(i)}$ (21)
$\displaystyle\bar{S}_{z}:=\sum_{i=1}^{N}\mathbb{1}\otimes\bar{Z}^{(i)}$ (22)

where here the identity acts on the ancillary qubits. The shifted Bell
operator is:

${\cal
B}+Nk=\frac{k}{2}(\bar{S}_{x}^{2}+\bar{S}_{z}^{2})+\sum_{i=1}^{N}({\bm{\sigma}}^{T}[\mathbb{1}-M]{\bm{\sigma}})^{(i)}~{}.$
(23)

If the violation of the Bell’s inequality is such that $\langle{\cal
B}+Nk\rangle\leq Nk\epsilon$, then we have that
$\langle\bar{S}_{x}^{2}+\bar{S}_{z}^{2}\rangle\leq 2N\epsilon$. More
explicitly, denoting as $|\Psi\rangle$ the (unknown) quantum state of the
black-box degrees of freedom, we have:

$\langle\Psi|\langle+|^{\otimes
N}(\bar{S}_{x}^{2}+\bar{S}_{z}^{2})|+\rangle^{\otimes N}|\Psi\rangle\leq
2N\epsilon~{}.$ (24)

The goal is in turn to establish a non-trivial bound on
$\langle(S_{x}^{2}+S_{z}^{2})\rangle$ after application of the SWAP gate,
namely to bound the quantity ${\cal Q}$:

${\cal Q}:=\langle\Psi|\langle+|^{\otimes
N}U_{\Phi}^{\dagger}(S_{x}^{2}+S_{z}^{2})U_{\Phi}|+\rangle^{\otimes
N}|\Psi\rangle\leq~{}?$ (25)

Strategy of the proof. The strategy is to show that the operator
$S_{x}^{(\Phi)}:=U_{\Phi}^{\dagger}S_{x}U_{\Phi}$ is “close” to the operator
$\bar{S}_{x}$ (and similarly for
$S_{z}^{(\Phi)}:=U_{\Phi}^{\dagger}S_{z}U_{\Phi}$ and $\bar{S}_{z}$), in some
sense to define, and to use some form of the triangle inequality to obtain a
non-trivial bound. Specifically, defining
$\langle\cdot\rangle:=\langle\Psi|\langle+|^{\otimes N}\cdot|+\rangle^{\otimes
N}|\Psi\rangle$, we use that for any operators $A_{1}$ and $A_{2}$: $\langle
A_{1}^{\dagger}A_{1}\rangle=\langle
A_{2}^{\dagger}A_{2}\rangle+\langle(A_{1}-A_{2})^{\dagger}(A_{1}-A_{2})\rangle+\langle
A_{2}^{\dagger}(A_{1}-A_{2})\rangle+\langle(A_{1}-A_{2})^{\dagger}A_{1}\rangle$.
Using the Cauchy-Schwarz inequality, we have $|\langle
A_{2}^{\dagger}(A_{1}-A_{2})\rangle|\leq\sqrt{\langle
A_{2}^{\dagger}A_{2}\rangle\langle(A_{1}-A_{2})^{\dagger}(A_{1}-A_{2})\rangle}$,
so that we have $\langle A_{1}^{\dagger}A_{1}\rangle\leq[\sqrt{\langle
A_{2}^{\dagger}A_{2}\rangle}+\sqrt{\langle(A_{1}-A_{2})^{\dagger}(A_{1}-A_{2})\rangle}]^{2}$.
Applying this inequality with $(A_{1},A_{2})=(S_{x}^{(\Phi)},\bar{S}_{x})$ and
$(A_{1},A_{2})=(S_{z}^{(\Phi)},\bar{S}_{z})$, we obtain:

$\displaystyle{\cal
Q}=\langle[S_{x}^{(\Phi)}]^{2}+[S_{z}^{(\Phi)}]^{2}\rangle\leq\left[\sqrt{\langle\bar{S}_{x}^{2}+\bar{S}_{z}^{2}\rangle}\right.$
$\displaystyle+\left.\sqrt{\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}+[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle}\right]^{2}$
(26)

We already know that $\langle\bar{S}_{x}^{2}+\bar{S}_{z}^{2}\rangle\leq
2N\epsilon$, so that it remains to bound
$\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}+[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle$.
We will find a bound of the form
$\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}+[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle\leq
rN^{2}\epsilon$ for some numerical factor $r\approx 752$, which implies a
robustness statement of the form:

${\cal Q}\leq\left[\sqrt{2N\epsilon}+\sqrt{rN^{2}\epsilon}\right]^{2}\approx
rN^{2}\epsilon~{}.$ (27)

###  A.3 Bounding total spin fluctuations after the SWAP gate

One has to evaluate the squared norm of:
$[S_{z}^{(\Phi)}-\bar{S}_{z}]|+\rangle^{\otimes N}|\Psi\rangle$, and of
$[S_{x}^{(\Phi)}-\bar{S}_{x}]|+\rangle^{\otimes N}|\Psi\rangle$.

####  A.3.1 Two useful Lemmas

To derive the robustness bound, we shall make extensive use of two
inequalities:

######  Lemma 4.

For any operators $A_{a}^{(i)}$ and any vector $|v\rangle$, one has:

$\sum_{i}||\sum_{a}A_{a}^{(i)}|v\rangle||^{2}\leq\left[\sum_{a}\sqrt{\sum_{i}||A_{a}^{(i)}|v\rangle||^{2}}\right]^{2}$

###### Proof.

The proof is elementary. We first apply the triangle inequality to obtain:
$||\sum_{a}A_{a}^{(i)}|v\rangle||^{2}\leq\sum_{a,b}[||A_{a}^{(i)}|v\rangle||\times||A_{b}^{(i)}|v\rangle||]$.
Using then Cauchy-Schwarz inequality, we have that
$\sum_{i}[||A_{a}^{(i)}|v\rangle||\times||A_{b}^{(i)}|v\rangle||]\leq\sqrt{\sum_{i}||A_{a}^{(i)}|v\rangle||^{2}}\sqrt{\sum_{i}||A_{b}^{(i)}|v\rangle||^{2}}$,
from which we obtain the inequality of Lemma 4. ∎

######  Lemma 5.

For any operators $A_{i}$ and any vector $|v\rangle$, one has:

$||\sum_{i=1}^{K}A_{i}|v\rangle||^{2}\leq
K\sum_{i=1}^{K}||A_{i}|v\rangle||^{2}$

###### Proof.

The proof is elementary. We first use the triangle inequality:
$||\sum_{i=1}^{K}A_{i}|v\rangle||^{2}\leq[\sum_{i=1}^{K}||A_{i}|v\rangle||]^{2}=K^{2}[\sum_{i=1}^{K}(1/K)||A_{i}|v\rangle||]^{2}$.
We then use the concavity of the square root function: for all $x_{i}$,
$\sum_{i=1}^{K}\sqrt{x_{i}}/K\leq\sqrt{\sum_{i=1}^{K}x_{i}/K}$. Applying this
inequality for $x_{i}=||A_{i}|v\rangle||$, we conclude the proof of Lemma 5. ∎

####  A.3.2 First inequality

We have:
$S_{z}^{(\Phi)}=U_{\Phi}^{\dagger}[\sum_{i}Z^{(i)}\otimes\mathbb{1}]U_{\Phi}=\sum_{i}\Phi_{i}^{\dagger}[Z^{(i)}\otimes\mathbb{1}]\Phi_{i}$.
Hence, we have
$S_{z}^{(\Phi)}-\bar{S}_{z}=\sum_{i=1}^{N}\\{\Phi_{i}^{\dagger}[Z^{(i)}\otimes\mathbb{1}]\Phi_{i}-\mathbb{1}\otimes\bar{Z}^{(i)}\\}$
and similarly
$S_{x}^{(\Phi)}-\bar{S}_{x}=\sum_{i=1}^{N}\\{\Phi_{i}^{\dagger}[X^{(i)}\otimes\mathbb{1}]\Phi_{i}-\mathbb{1}\otimes\bar{X}^{(i)}\\}$.

Elementary manipulations of the partial SWAP gate show that:

$\Phi_{i}^{\dagger}[Z^{(i)}\otimes\mathbb{1}]\Phi_{i}|+\rangle_{i}|\Psi\rangle=|+\rangle_{i}\tilde{Z}^{(i)}|\Psi\rangle$
(28)

And similarly that:

$\Phi_{i}^{\dagger}[X^{(i)}\otimes\mathbb{1}]\Phi_{i}|+\rangle_{i}|\Psi\rangle=\frac{1}{\sqrt{2}}[|0\rangle_{i}\tilde{X}^{(i)}-|1\rangle_{i}\tilde{Z}^{(i)}\tilde{X}^{(i)}\tilde{Z}^{(i)}]|\Psi\rangle$
(29)

Applying then Lemma 5 with
$A_{i}=\Phi_{i}^{\dagger}[Z^{(i)}\otimes\mathbb{1}]\Phi_{i}-\mathbb{1}\otimes\bar{Z}^{(i)}$
and $|v\rangle=|+\rangle^{\otimes N}|\Psi\rangle$, we have
$||A_{i}|v\rangle||^{2}=||(\tilde{Z}-\bar{Z})^{(i)}|\Psi\rangle||^{2}$, and
hence:

$\langle[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle\leq
N\sum_{i=1}^{N}||(\tilde{Z}-\bar{Z})^{(i)}|\Psi\rangle||^{2}$ (30)

Similarly, applying Lemme 5 with
$A_{i}=\Phi_{i}^{\dagger}[X^{(i)}\otimes\mathbb{1}]\Phi_{i}-\mathbb{1}\otimes\bar{X}^{(i)}$
and $|v\rangle=|+\rangle^{\otimes N}|\Psi\rangle$, we have
$||A_{i}|v\rangle||^{2}=(1/2)|||0\rangle_{i}(\bar{X}-\tilde{X})^{(i)}|\Psi\rangle+|1\rangle_{i}(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||^{2}=(1/2)||(\bar{X}-\tilde{X})^{(i)}|\Psi\rangle||^{2}+(1/2)||(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||^{2}$.
Hence, by Lemma 5:

$\displaystyle\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}\rangle\leq\frac{N}{2}\sum_{i=1}^{N}\left[||(\bar{X}-\tilde{X})^{(i)}|\Psi\rangle||^{2}\right.$
$\displaystyle\left.+||(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||^{2}\right]$
(31)

####  A.3.3 Removing the regularized operators

As a second step, we derive inequalities which do not involve the regularized
(unitary) operators $\tilde{X}^{(i)}$ and $\tilde{X}^{(i)}$. Specifically,
since $\tilde{Z}^{(i)}$ is unitary and $[\tilde{Z}^{(i)}]^{2}=\mathbb{1}$, we
have
$||(\tilde{Z}-\bar{Z})^{(i)}|\Psi\rangle||=||(\mathbb{1}-\tilde{Z}\bar{Z})^{(i)}|\Psi\rangle||$.
Then, we use that
$\mathbb{1}-\tilde{Z}\bar{Z}=\mathbb{1}-|\bar{Z}|\leq(\mathbb{1}-|\bar{Z}|)(\mathbb{1}+|\bar{Z}|)=\mathbb{1}-\bar{Z}^{2}$.
Therefore:
$||(\tilde{Z}-\bar{Z})^{(i)}|\Psi\rangle||^{2}\leq||(\mathbb{1}-\bar{Z}^{2})^{(i)}|\Psi\rangle||^{2}$.
Similarly, we have that
$||(\tilde{X}-\bar{X})^{(i)}|\Psi\rangle||^{2}\leq||(\mathbb{1}-\bar{X}^{2})^{(i)}|\Psi\rangle||^{2}$.
We also have that
$||(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||=||(\bar{X}\tilde{Z}+\tilde{Z}\tilde{X})^{(i)}|\Psi\rangle||$.
Inserting $\tilde{Z}=\bar{Z}+\tilde{Z}-\bar{Z}$ and
$\tilde{X}=\bar{X}+\tilde{X}-\bar{X}$, we obtain
$\bar{X}\tilde{Z}+\tilde{Z}\tilde{X}=\bar{X}\bar{Z}+\bar{Z}\bar{X}+(\tilde{Z}-\bar{Z})\bar{X}+(\tilde{X}-\bar{X})\bar{Z}+\tilde{X}(\tilde{Z}-\bar{Z})$.
Applying then Lemma 4, we have:

$\displaystyle\sum_{i=1}^{N}||(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||^{2}\leq$
$\displaystyle\left[\sqrt{\sum_{i}||(\bar{Z}\bar{X}+\bar{X}\bar{Z})^{(i)}|\Psi\rangle||^{2}}\right.$
(32)
$\displaystyle+\sqrt{\sum_{i}||[(\tilde{Z}-\bar{Z})\bar{X}]^{(i)}|\Psi\rangle||^{2}}$
$\displaystyle+\sqrt{\sum_{i}||[(\tilde{X}-\bar{X})\bar{Z}]^{(i)}|\Psi\rangle||^{2}}$
$\displaystyle+\left.\sqrt{\sum_{i}||[\tilde{X}(\tilde{Z}-\bar{Z})]^{(i)}|\Psi\rangle||^{2}}\right]^{2}$

We then use the fact that $\tilde{X}^{(i)}$ is unitary (implying that
$||\tilde{X}^{(i)}||=1$), and bound the norm of operators $\bar{X}^{(i)}$ and
$\bar{Z}^{(i)}$ in the following way:
$||\bar{X}^{(i)}||=\frac{2}{k}||\sum_{a=0}^{k-1}\sin(a\pi/k)\sigma_{a}^{(i)}||\leq\frac{2}{k}\sum_{a=0}^{k-1}\sin(a\pi/k)=\frac{\sin(\pi/k)}{k\sin^{2}[\pi/(2k)]}\leq
4/\pi$. By a similar computation, we have
$||\bar{Z}^{(i)}||=\frac{2}{k}||\sum_{a=0}^{k-1}\cos(a\pi/k)\sigma_{a}^{(i)}||\leq\frac{2}{k}\sum_{a=0}^{k-1}|\cos(a\pi/k)|=\frac{2\sin[(\pi/k)\lfloor
k/2\rfloor-1/2]}{k\sin[\pi/(2k)]}\leq 4/\pi$. Using these bounds, we obtain:

$\displaystyle\sum_{i=1}^{N}||(\bar{X}+\tilde{Z}\tilde{X}\tilde{Z})^{(i)}|\Psi\rangle||^{2}$
$\displaystyle\leq$
$\displaystyle\left[\sqrt{\sum_{i}||(\bar{Z}\bar{X}+\bar{X}\bar{Z})^{(i)}|\Psi\rangle||^{2}}\right.$
(33) $\displaystyle+$
$\displaystyle\left(1+\frac{4}{\pi}\right)\sqrt{\sum_{i}||(\tilde{Z}-\bar{Z})^{(i)}|\Psi\rangle||^{2}}$
$\displaystyle+$
$\displaystyle\left.\frac{4}{\pi}\sqrt{\sum_{i}||(\tilde{X}-\bar{X})^{(i)}|\Psi\rangle||^{2}}\right]^{2}$

Putting everything together, we finally obtain:

$\langle[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle\leq
N\sum_{i=1}^{N}||(\mathbb{1}-\bar{Z}^{2})^{(i)}|\Psi\rangle||^{2}$ (34)
$\displaystyle\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}\rangle$
$\displaystyle\leq$
$\displaystyle\frac{N}{2}\sum_{i=1}^{N}||(\mathbb{1}-\tilde{X}^{2})^{(i)}|\Psi\rangle||^{2}$
(35) $\displaystyle+$
$\displaystyle\frac{N}{2}\left[\sqrt{\sum_{i=1}^{N}||(\bar{Z}\bar{X}+\bar{X}\bar{Z})^{(i)}|\Psi\rangle||^{2}}\right.$
$\displaystyle+$
$\displaystyle\left(1+\frac{4}{\pi}\right)\sqrt{\sum_{i=1}^{N}||(\mathbb{1}-\bar{Z}^{2})^{(i)}|\Psi\rangle||^{2}}$
$\displaystyle+$
$\displaystyle\left.\frac{4}{\pi}\sqrt{\sum_{i=1}^{N}||(\mathbb{1}-\bar{X}^{2})^{(i)}|\Psi\rangle||^{2}}\right]^{2}$

####  A.3.4 Form of the robustness bound

Our next step will be to find constants $\alpha_{0}$ and $\alpha_{1}$ such
that:

$\displaystyle\sum_{i=1}^{N}||(\bar{Z}\bar{X}+\bar{X}\bar{Z})^{(i)}|\Psi\rangle||^{2}\leq
N\epsilon\alpha_{0}$ (36)
$\displaystyle\sum_{i=1}^{N}||(\mathbb{1}-\bar{Z}^{2})^{(i)}|\Psi\rangle||^{2}\leq
N\epsilon\alpha_{1}$ (37)
$\displaystyle\sum_{i=1}^{N}||(\mathbb{1}-\bar{X}^{2})^{(i)}|\Psi\rangle||^{2}\leq
N\epsilon\alpha_{1}$ (38)

This will imply the following bounds:

$\displaystyle\langle[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle\leq
N^{2}\epsilon\alpha_{1}$ (39)
$\displaystyle\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}\rangle\leq\frac{N^{2}\epsilon}{2}\left\\{\right.$
$\displaystyle\left.\alpha_{1}+[\sqrt{\alpha_{0}}+(1+8/\pi)\sqrt{\alpha_{1}}]^{2}\right\\}~{}.$
(40)

Finding the constants $\alpha_{0}$ and $\alpha_{1}$ will be achived using the
condition $\langle{\cal B}+Nk\rangle\leq Nk\epsilon$, which implies, via the
SOS decomposition of Eq. (23), the following bound:

$\sum_{i=1}^{N}\langle\Psi|({\bm{\sigma}}^{T}[\mathbb{1}-M]{\bm{\sigma}})^{(i)}|\Psi\rangle\leq
Nk\epsilon~{}.$ (41)

We will use this inequality to derive bounds of the form:

$\displaystyle\sum_{j=1}^{N}||(\mathbb{1}-\frac{\bar{Z}^{2}+\bar{X}^{2}}{2})^{(j)}|\Psi\rangle||^{2}\leq
N\epsilon$ (42) $\displaystyle\sum_{j=1}^{N}||[(\bar{Z}\pm
i\bar{X})^{(j)}]^{2}|\Psi\rangle||^{2}\leq N\epsilon\alpha$ (43)

for a certain constant $\alpha$. Introducing the notations
$A_{0}^{(j)}=(\mathbb{1}-\frac{\bar{Z}^{2}+\bar{X}^{2}}{2})^{(j)}$ and
$A_{\pm}^{(j)}=[(\bar{Z}\pm i\bar{X})^{(j)}]^{2}=[\bar{Z}^{2}-\bar{X}^{2}\pm
i(\bar{X}\bar{Z}+\bar{Z}\bar{X})]^{(j)}$, we then use the decompositions:
$[\mathbb{1}-\bar{Z}^{2}]^{(j)}=[A_{0}-\frac{A_{+}+A_{-}}{4}]^{(j)}$;
$[\mathbb{1}-\bar{X}^{2}]^{(j)}=[A_{0}+\frac{A_{+}+A_{-}}{4}]^{(j)}$ and
$[\bar{Z}\bar{X}+\bar{X}\bar{Z}]^{(j)}=[\frac{A_{+}-A_{-}}{2i}]^{(j)}$.
Applying then Lemma 4, we obtain
$\alpha_{0}=\frac{1}{4}(\sqrt{\alpha}+\sqrt{\alpha})^{2}=\alpha$, and
similarly $\alpha_{1}=(1+\sqrt{\alpha}/2)^{2}$. In the next subsection, we
will establish Eqs. (42)-(43).

####  A.3.5 Exploiting the SOS decomposition of the Bell’s inequality

We first use the fact that
$({\bm{\sigma}}^{T}[\mathbb{1}-M]{\bm{\sigma}})^{(i)}=k\mathbb{1}-(k/2)(\tilde{X}^{2}+\tilde{Z}^{2})^{(i)}$.
The matrix $M$ being a projector, $1-M$ is also a projector, so that we have
$0\leq\mathbb{1}-(1/2)(\tilde{X}^{2}+\tilde{Z}^{2})^{(i)}\leq\mathbb{1}$. This
implies that
$\langle\langle\Psi|[\mathbb{1}-(1/2)(\tilde{X}^{2}+\tilde{Z}^{2})^{(i)}]|\Psi\rangle\leq||\mathbb{1}-(1/2)(\tilde{X}^{2}+\tilde{Z}^{2})^{(i)}|\Psi\rangle||^{2}$.
Therefore, from Eq. (41), we have the announced inequality Eq. (42). To obtain
Eq. (43), we first use the property $(1-M)^{2}=(1-M)$, together with the
explicit expression of the matrix $M_{ab}=(2/k)\cos[(a-b)\pi/k]$, to rewrite
Eq. (41) as:

$\sum_{j=1}^{N}\sum_{a=0}^{k-1}||\\{\sigma_{a}^{(j)}-\frac{2}{k}\sum_{b=0}^{k-1}\cos\left(\pi\frac{a-b}{k}\right)\sigma_{b}^{(j)}\\}|\Psi\rangle||^{2}\leq
Nk\epsilon~{}.$ (44)

We then decompose:

$\displaystyle\frac{2}{k}\sum_{b=0}^{k-1}\cos\left(\pi\frac{a-b}{k}\right)\sigma_{b}^{(j)}=$
$\displaystyle\frac{e^{ia\pi/k}}{2}(\bar{Z}-i\bar{X})^{(j)}+\frac{e^{-ia\pi/k}}{2}(\bar{Z}+i\bar{X})^{(j)}~{}.$
(45)

We introduce the notation:

$R_{a}^{(j)}:=2\sigma_{a}^{(j)}e^{ia\pi/k}-(\bar{Z}+i\bar{X})^{(j)}~{},$ (46)

so that Eq. (41) can be rewritten as:

$\sum_{j=1}^{N}\sum_{a=0}^{k-1}||R_{a}^{(j)}-e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}|\Psi\rangle||^{2}\leq
4Nk\epsilon~{}.$ (47)

We then introduce the operators:

$A_{a}^{(j)}:=R_{a}^{(j)}R_{a}^{(j)}-R_{a}^{(j)}e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}~{}.$
(48)

We note that the operator norm of $R_{a}^{(j)}$ is bounded. Indeed, we have
$(\bar{Z}+i\bar{X})^{(j)}=(2/k)\sum_{a=0}^{k-1}e^{ia\pi/k}\sigma_{a}^{(j)}$.
Hence, we have $||(\bar{Z}+i\bar{X})^{(j)}||\leq 2$ (by the triangle
inequality, and the property $||\sigma_{a}^{(j)}||=1$). Consequently, we have
$||R_{a}^{(j)}||\leq 4$. Therefore, we have the inequality:

$\sum_{j=1}^{N}\sum_{a=0}^{k-1}||A_{a}^{(j)}|\Psi\rangle||^{2}\leq
64Nk\epsilon~{}.$ (49)

We have the property that:

$\sum_{a=0}^{k-1}R_{a}^{(j)}R_{a}^{(j)}=-k[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}~{},$
(50)

which implies that:

$-k[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}=\sum_{a=0}^{k-1}A_{a}^{(j)}+\sum_{a=0}^{k-1}R_{a}^{(j)}e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}~{}.$
(51)

From Lemma 4, we have the following bound:

$\displaystyle\sum_{j=1}^{N}||k[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}|\Psi\rangle||^{2}\leq\left[\sqrt{\sum_{j=1}^{N}||\sum_{a=0}^{k-1}A_{a}^{(j)}|\Psi\rangle||^{2}}\right.$
$\displaystyle\left.+\sqrt{\sum_{j=1}^{N}||\sum_{a=0}^{k-1}R_{a}^{(j)}e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}|\Psi\rangle||^{2}}\right]^{2}~{}.$

Furthermore, from Lemma 5, we have the bound:

$\displaystyle\sum_{j=1}^{N}||\sum_{a=0}^{k-1}A_{a}^{(j)}|\Psi\rangle||^{2}$
$\displaystyle\leq$
$\displaystyle\sum_{j=1}^{N}k\sum_{a=0}^{k-1}||A_{a}^{(j)}|\Psi\rangle||^{2}$
(52) $\displaystyle\leq$ $\displaystyle 64Nk^{2}\epsilon$

It remains to bound
$\sum_{j=1}^{N}||\sum_{a=0}^{k-1}R_{a}^{(j)}e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}|\Psi\rangle||^{2}$.
First, we decompose
$R_{a}^{(j)}=e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}+R_{a}^{(j)}-e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}$.
Therefore, we have:

$\displaystyle\sum_{a=0}^{k-1}R_{a}^{(j)}e^{2ia\pi/k}(\bar{Z}-i\bar{X})^{(j)}=\sum_{a=0}^{k-1}e^{4ia\pi/k}[(\bar{Z}-i\bar{X})^{(j)}]^{2}$
$\displaystyle+\sum_{a=0}^{k-1}e^{2ia\pi/k}[R_{a}-e^{2ia\pi/k}(\bar{Z}-i\bar{X})]^{(j)}(\bar{Z}-i\bar{X})^{(j)}$

We have $\sum_{a=0}^{k-1}e^{4ia\pi/k}=0$ for all $k\geq 3$. Furthermore, using
Lemma 5 and the bound $||(\bar{Z}-i\bar{X})^{(j)}||\leq 2$, we conclude that:

$\displaystyle\sum_{i=1}^{N}||\sum_{a=0}^{k-1}e^{2ia\pi/k}R_{a}^{(j)}(\bar{Z}-i\bar{X})^{(j)}|\Psi\rangle||^{2}\leq$
$\displaystyle\sum_{i=1}^{N}4k\sum_{a=0}^{k-1}||[R_{a}-e^{2ia\pi/k}(\bar{Z}-i\bar{X})]^{(j)}|\Psi\rangle||^{2}$
$\displaystyle\leq 16Nk^{2}\epsilon$ (53)

Putting everything together, we have:

$\sum_{j=1}^{N}||[\bar{Z}^{(j)}+i\bar{X}^{(j)}]^{2}|\Psi\rangle||^{2}\leq
144N\epsilon~{}.$ (54)

Exchanging the role of $i$ and $-i$ from Eq. (46) onwards, one establishes the
similar inequality:

$\sum_{j=1}^{N}||[\bar{Z}^{(j)}-i\bar{X}^{(j)}]^{2}|\Psi\rangle||^{2}\leq
144N\epsilon~{}.$ (55)

Namely, we have proved Eq. (43) with the constant $\alpha=144$. Consquently,
we have $\alpha_{1}=(1+\sqrt{\alpha}/2)^{2}=49$. Finally, we have established
the following inequalities:

$\displaystyle\langle[S_{z}^{(\Phi)}-\bar{S}_{z}]^{2}\rangle\leq
49N^{2}\epsilon$ (56)
$\displaystyle\langle[S_{x}^{(\Phi)}-\bar{S}_{x}]^{2}\rangle\leq\frac{N^{2}\epsilon}{2}[49+(19+\frac{56}{\pi})^{2}]~{}.$
(57)

This implies, via Eq. (26), the bound on total spin fluctuations after the
SWAP gate:

$\langle[S_{x}^{(\Phi)}]^{2}+[S_{z}^{(\Phi)}]^{2}\rangle\leq
N^{2}\epsilon\left[\sqrt{2/N}+\sqrt{r}\right]^{2}$ (58)

with $r=49+[49+(19+\frac{56}{\pi})^{2}]/2\approx 752$

##  Appendix B Generalization with arbitrary local phases

In this section, we show how the derivation presented in the main text can be
extended to the following quantum Bell’s inequality:

${\cal B}=\frac{2}{k}\sum_{a,b=0}^{k-1}\sum_{i\neq
j}\langle\sigma_{a}^{(i)}\sigma_{b}^{(j)}\rangle\cos[\pi(a-b)/k+\phi_{i}-\phi_{j}]\geq-
Nk~{},$ (59)

where $\phi_{i}$ are local phases. We show that reaching the quantum bound
$-Nk$ self-tests the property:
$\sum_{i,j}\cos(\phi_{i}-\phi_{j})\langle\hat{X}^{(i)}\hat{X}^{(j)}+\hat{Z}^{(i)}\hat{Z}^{(j)}\rangle=0$,
and local measurements which are the same as for $\phi_{i}=0$ (equally-spaced
qubit measurements in the $xz$ plane).

In order to do so, similarly to what was done in the main text for
$\phi_{i}=0$, we introduce the collective variables
$\bar{S_{a}}=\sum_{i=j}^{N}\hat{\sigma}_{a}^{(j)}e^{i\phi_{j}}$. We have
again:
$S_{ab}=\langle\bar{S_{a}}\bar{S_{b}}\rangle-\sum_{i}\langle\hat{\sigma}_{a}^{(i)}\hat{\sigma}_{b}^{(i)}\rangle$.
We introduce the vector notations
$[{\bm{\sigma}}^{(i)}]^{T}=(\hat{\sigma}_{0},\cdots\hat{\sigma}_{k-1})^{(i)}$
and $\bar{\bf
S}^{\dagger}=(\bar{S}_{0}^{\dagger},\ldots\bar{S}_{k-1}^{\dagger})$, and the
matrix $M_{ab}=(2/k)\cos[\pi(a-b)/k]$. Eq. (59) then takes the same expression
as in the main text for $\phi_{i}=0$:

${\cal B}=\langle\bar{\bf S}^{\dagger}M\bar{\bf
S}\rangle-\sum_{i=1}^{N}\langle{\bm{\sigma}}^{T}M{\bm{\sigma}}\rangle^{(i)}~{}.$
(60)

The matrix $M$ is diagonalized as in the main text; and again, we have
$\langle{\cal B}\rangle\geq(-2N)/[k\sin^{2}(\frac{\pi}{2k})]$ for all
classical local-variable models.

The classical bound can be violated as follows. Measuring a $N$-qubit quantum
state along directions
$\hat{\sigma}_{a}^{(i)}=\hat{Z}^{(i)}\cos\theta_{a}+\hat{X}^{(i)}\sin\theta_{a}$
yields ${\cal
B}=4\sum_{ab}M_{ab}\langle[\hat{J}^{\prime}_{a}]^{\dagger}\hat{J}^{\prime}_{b}\rangle-N\sum_{ab}M_{ab}\cos(\theta_{a}-\theta_{b})$,
where $\hat{J}_{a}^{\prime}=(1/2)\sum_{j}\hat{\sigma}_{a}^{(j)}e^{i\phi_{j}}$.
Choosing $\theta_{a}=a\pi/k$, we obtain ${\cal B}=2k{\cal
S}-(Nk/2)\sum_{ab}M_{ab}^{2}$, where ${\cal
S}=\sum_{i,j}\cos(\phi_{i}-\phi_{j})\langle\hat{X}^{(i)}\hat{X}^{(j)}+\hat{Z}^{(i)}\hat{Z}^{(j)}\rangle$.
Whenever ${\cal S}=0$, we obtain ${\cal B}=-(Nk/2){\rm Tr}(M^{2})=-Nk$. We
will show that $B_{\rm q}=-Nk$ is the maximal violation allowed by quantum
physics, and that reaching this value self-tests ${\cal S}=0$.

We parallel the derivation presented in the main text. We have the sum-of-
squares (SOS) decomposition (recall that $\mathbb{1}-M=(\mathbb{1}-M)^{2}$):

$\hat{\cal B}+Nk\mathbb{1}=({\bf c}^{T}\bar{\bf S})^{\dagger}({\bf
c}^{T}\bar{\bf S})+({\bf s}^{T}\bar{\bf S})^{\dagger}({\bf s}^{T}\bar{\bf
S})+\sum_{i=1}^{N}[{\bm{\sigma}}^{T}(\mathbb{1}-M){\bm{\sigma}}]^{(i)}$ (61)

We can introduce the operators on which the self-testing procedure rely. The
$\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ have the same expression as in the main
text:

$\displaystyle\bar{Z}^{(i)}:=\sqrt{2/k}~{}{\bf
c}^{T}{\bm{\sigma}}^{(i)}=\frac{2}{k}\sum_{a=0}^{k-1}\hat{\sigma}_{a}^{(i)}\cos\left(\frac{a\pi}{k}\right)$
(62a) $\displaystyle\bar{X}^{(i)}:=\sqrt{2/k}~{}{\bf
s}^{T}{\bm{\sigma}}^{(i)}=\frac{2}{k}\sum_{a=0}^{k-1}\hat{\sigma}_{a}^{(i)}\sin\left(\frac{a\pi}{k}\right)~{}.$
(62b)

Introducing then the (hermitian) operators:

$\displaystyle\bar{S}_{z}=\sum_{i=1}^{N}[\cos\phi_{i}\bar{Z}^{(i)}-\sin\phi_{i}\bar{X}^{(i)}]$
(63a)
$\displaystyle\bar{S}_{x}=\sum_{i=1}^{N}[\cos\phi_{i}\bar{X}^{(i)}+\sin\phi_{i}\bar{Z}^{(i)}]$
(63b)
$\displaystyle\hat{A}_{a}^{(i)}:=\hat{\sigma}_{a}^{(i)}-\frac{2}{k}\sum_{b=0}^{k-1}\hat{\sigma}_{b}^{(i)}\cos\left(\pi\frac{a-b}{k}\right)~{},$
(63c)

the SOS decomposition reads explicitly:

$\hat{\cal
B}+Nk\mathbb{1}=\frac{k}{2}(\bar{S}_{z}^{2}+\bar{S}_{x}^{2})+\sum_{i=1}^{N}\sum_{a=0}^{k-1}[\hat{A}_{a}{(i)}]^{2}~{}.$
(64)

Notice that
$\bar{S}_{z}^{2}+\bar{S}_{x}^{2}=\sum_{i,j}\cos(\phi_{i}-\phi_{j})(\bar{Z}^{(i)}\bar{Z}^{(j)}+\bar{X}^{(i)}\bar{X}^{(j)})$.
This shows that measuring at equal angles in a given plane a $N$-qubit state
s.t.
$\sum_{i,j}\cos(\phi_{i}-\phi_{j})\langle\hat{X}^{(i)}\hat{X}^{(j)}+\hat{Z}^{(i)}\hat{Z}^{(j)}\rangle=0$
reaches the quantum bound $-Nk$. To prove the converse statement, we may
follow exactly the same proof as for $\phi_{i}=0$. To establish the fact that
$\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ act as the Pauli $\hat{Z}$ and $\hat{X}$
operator, we follow the derivation of the main text. The only difference is
between Eqs. (9) and (10) of the main text, where $\Sigma_{Z}^{(j)}$ and
$\Sigma_{X}^{(j)}$ [defined before Eq. (10)] are now:
$\Sigma_{Z}^{(j)}=\sum_{j^{\prime}\neq
j}[\cos\phi_{j^{\prime}}\bar{Z}^{(j^{\prime})}-\sin\phi_{j^{\prime}}\bar{X}^{(j^{\prime})}]$
and $\Sigma_{X}^{(j)}=\sum_{j^{\prime}\neq
j}[\cos\phi_{j^{\prime}}\bar{X}^{(j^{\prime})}+\sin\phi_{j^{\prime}}\bar{Z}^{(j^{\prime})}]$.
From the SOS being zero, we have that
$(\Sigma_{Z}-i\Sigma_{X})^{(j)}|\psi\rangle=-e^{-i\phi_{j}}(\bar{Z}-i\bar{X})^{(j)}|\psi\rangle$.
As the operator $\Sigma_{Z}^{(j)}-i\Sigma_{X}^{(j)}$ acts on subsystems
$j^{\prime}\neq j$, it commutes with any operator acting on $j$. The rest of
the proof goes as in the main text. We finally construct the SWAP gate on the
$\bar{Z}^{(i)}$ and $\bar{X}^{(i)}$ operators. To conclude, we notice that
maximal violation of the BI implies that
$\bar{S}_{z}\bar{\rho}=0=\bar{S}_{x}\bar{\rho}$. Hence the same property after
the partial-SWAP gate:
$\hat{J}^{\prime}_{x}\hat{\rho}=\hat{J}^{\prime}_{z}\hat{\rho}=0$, where
$\hat{J}^{\prime}_{x}=(1/2)\sum_{i=1}^{N}[\cos\phi_{i}\hat{X}^{(i)}+\sin\phi_{i}\hat{Z}^{(i)}]$
and
$\hat{J}_{z}^{\prime}=(1/2)\sum_{i=1}^{N}[\cos\phi_{i}\hat{Z}^{(i)}-\sin\phi_{i}\hat{X}^{(i)}]$.
Hence, maximal quantum violation of the BI self-tests
$4\langle(J_{x}^{\prime})^{2}+(J_{z}^{\prime})^{2}\rangle=0=\sum_{i,j}\cos(\phi_{i}-\phi_{j})\langle\hat{X}^{(i)}\hat{X}^{(j)}+\hat{Z}^{(i)}\hat{Z}^{(j)}\rangle$.