arXiv is now an independent nonprofit! Learn more
License: arXiv.org perpetual non-exclusive license
arXiv:1601.07601v3 [quant-ph] 09 Apr 2019

Improved classical simulation of quantum circuits dominated by Clifford gates

Sergey Bravyi Affiliation: IBM T.J. Watson Research Center, Yorktown Heights NY 10598    David Gosset Affiliation: Walter Burke Institute for Theoretical Physics and Institute for Quantum Information and Matter, California Institute of Technology
August 24, 2026
Abstract

The Gottesman-Knill theorem asserts that a quantum circuit composed of Clifford gates can be efficiently simulated on a classical computer. Here we revisit this theorem and extend it to quantum circuits composed of Clifford and TT gates, where TT is the single-qubit 4545^{\circ} phase shift. We assume that the circuit outputs a bit string xx obtained by measuring some subset of ww qubits. Two simulation tasks are considered: (1) computing the probability of a given output xx, and (2) sampling xx from the output probability distribution. It is shown that these tasks can be solved on a classical computer in time poly(n,m)+20.5tt3poly(n,m)+2^{0.5t}t^{3} and poly(n,m)+20.23tt3w3poly(n,m)+2^{0.23t}t^{3}w^{3} respectively, where tt is the number of TT-gates, mm is the total number of gates, and nn is the number of qubits. The proposed simulation algorithms may serve as a verification tool for medium-size quantum computations that are dominated by Clifford gates. The main ingredient of both algorithms is a subroutine for approximating the norm of an nn-qubit state which is given as a linear combination of χ\chi stabilizer states. The subroutine runs in time χn3ϵ2\chi n^{3}\epsilon^{-2}, where ϵ\epsilon is the relative error. We also develop techniques for approximating tensor products of “magic states” by linear combinations of stabilizer states. To demonstrate the power of the new simulation methods, we performed a classical simulation of a hidden shift quantum algorithm with 4040 qubits, a few hundred Clifford gates, and nearly 5050 TT-gates.

I Introduction

The path towards building a large-scale quantum computer will inevitably require verification and validation of small quantum devices. One way to check that such a device is working properly is to simulate it on a classical computer. This becomes impractical at some point because the cost of classical simulation typically grows exponentially with the size of a quantum system. With this fundamental limitation in mind it is natural to ask how well we can do in practice.

Simulation methods which store a complete description of an nn-qubit quantum state as a complex vector of size 2n2^{n} are limited to a small number of qubits n30n\approx 30. For example, a state-of-the art implementation has been used to simulate Shor’s factoring algorithm with 31 qubits and roughly half a million gates [1]. For certain restricted classes of quantum circuits it is possible to do much better [2, 3, 4, 5, 6]. Most significantly, the Gottesman-Knill theorem allows efficient classical simulation of quantum circuits composed of gates in the so-called Clifford group [2]. In practice this allows one to simulate such circuits with thousands of qubits [3, 1]. It also means that a quantum computer will need to use gates outside of the Clifford group in order to achieve useful speedups over classical computation. The full power of quantum computation can be recovered by adding a single non-Clifford gate to the Clifford group. A simple choice is the single-qubit T=|00|+eiπ/4|11|T=|0\rangle\langle 0|+e^{i\pi/4}|1\rangle\langle 1| gate; the Clifford+TT gate set obtained in this way is a natural instruction set for small-scale fault-tolerant quantum computers based on the surface code [7, 8], and has been at the centre of a recent renaissance in classical techniques for compiling quantum circuits [9, 10, 11].

In this paper we present two new algorithms for classical simulation of quantum circuits over the Clifford+TT gate set. The runtime of the algorithms is polynomial in the number of qubits and the number of Clifford gates in the circuit but exponential in the number of TT gates, or TT-count. This exponential scaling is sufficiently mild that we anticipate a classical simulation of Clifford+TT circuits with a few hundred qubits and TT-count t50t\leq 50 can be performed on a medium-size computer cluster. Thus our algorithms may serve as a verification tool for small quantum computations dominated by Clifford gates. Such computations arise naturally if a logical quantum circuit is realized fault-tolerantly using some stabilizer code. The first demonstrations of logical quantum circuits using the surface code are likely to be dominated by Clifford gates due to a high implementation cost associated with logical TT-gates [12, 13].

To describe our results let us fix some notation. A Clifford+TT quantum circuit of length mm acting on nn qubits is a unitary operator U=UmU2U1U=U_{m}\cdots U_{2}U_{1}, where each UjU_{j} is a one- or two-qubit gate from the set {H,S,T,CNOT}\{H,S,T,CNOT\} where HH is the Hadamard gate and S=|00|+i|11|S=|0\rangle\langle 0|+i|1\rangle\langle 1|. We shall write m=c+tm=c+t, where cc is the number of Clifford gates (H,S,CNOTH,S,CNOT) and tt is the number of TT-gates also known as the TT-count. Applying UU to the initial state |0n|0^{n}\rangle and measuring some fixed output register Qout[n]Q_{out}\subseteq[n] in the 0,10,1-basis generates a random bit string xx of length w=|Qout|w=|Q_{out}|. A string xx appears with probability

Pout(x)=0n|UΠ(x)U|0n,P_{out}(x)=\langle 0^{n}|U^{\dagger}\Pi(x)U|0^{n}\rangle, (1)

where Π(x)\Pi(x) projects QoutQ_{out} onto the basis state |x|x\rangle and acts trivially on the remaining qubits.

Our first result is a classical Monte Carlo algorithm that approximates the probability Pout(x)P_{out}(x) for a given string x{0,1}wx\in\{0,1\}^{w} with a specified relative error ϵ\epsilon and a failure probability pfp_{f}. The algorithm has runtime

τ=O((w+t)(c+t)+(n+t)3+2βtt3ϵ2log(pf1)),\tau=O\left((w+t)(c+t)+(n+t)^{3}+2^{\beta t}t^{3}\epsilon^{-2}\log(p_{f}^{-1})\right), (2)

where β1/2\beta\leq 1/2 is a constant that depends on the implementation details. For example, assuming that ϵ\epsilon and pfp_{f} are some fixed constants and wtncw\leq t\leq n\leq c, the runtime becomes

τ=O(n3+ct+2βtt3).\tau=O(n^{3}+ct+2^{\beta t}t^{3}).

Our second result is a classical algorithm that allows one to sample the output string xx from a distribution which is ϵ\epsilon-close to PoutP_{out} with respect to the L1L_{1}-norm. The sampling algorithm has runtime

τ=O~(w(w+t)(c+t)+w(n+t)3+2γtt3w3ϵ4),\tau=\tilde{O}\left(w(w+t)(c+t)+w(n+t)^{3}+2^{\gamma t}t^{3}w^{3}\epsilon^{-4}\right), (3)

where the O~\tilde{O} notation hides a factor logarithmic in ww and ϵ1\epsilon^{-1}, and

γ2log2(cos(π/8))0.228\gamma\leq-2\log_{2}{\left(\cos{(\pi/8)}\right)}\approx 0.228 (4)

is a constant that depends on the implementation details. We expect the sampling algorithm to be practical when ww is small and ϵ\epsilon is not too small. For example, assuming that the circuit outputs a single bit (w=1w=1), ϵ\epsilon is a fixed constant, and tnct\leq n\leq c, the runtime becomes

τ=O(n3+ct+2γtt3).\tau=O(n^{3}+ct+2^{\gamma t}t^{3}).

Both algorithms can be divided into independent subroutines with a runtime O(t3)O(t^{3}) each and thus support a large amount of parallelism. We provide pseudocode for the main subroutines used in the algorithms and a timing analysis for the MATLAB implementation 11 1 The MATLAB implementation of the sampling algorithm is available upon request to the authors. in the Supplemental Material.

Since the simulation runtime is likely to be dominated by the terms exponential in tt, one may wish to minimize the exponents β\beta, γ\gamma in Eqs. (2,3). These exponents are related to the stabilizer rank [15] of a magic state

|A=21/2(|0+eiπ/4|1).|A\rangle=2^{-1/2}(|0\rangle+e^{i\pi/4}|1\rangle).

Recall that a tt-qubit state is called a stabilizer state if it has the form V|0tV|0^{t}\rangle, where VV is a quantum circuit composed of Clifford gates. Stabilizer states form an overcomplete basis in the Hilbert space of tt qubits. Let χt(δ)\chi_{t}(\delta) be the smallest integer χ\chi such that AtA^{\otimes t} can be approximated with an error at most δ\delta by a linear combination of χ\chi stabilizer states (here the approximating state ψ\psi should satisfy |At|ψ|21δ|\langle A^{\otimes t}|\psi\rangle|^{2}\geq 1-\delta). The runtime scaling in Eq. (2) holds for any exponent β\beta such that χt(0)=O(2βt)\chi_{t}(0)=O(2^{\beta t}) for all sufficiently large tt. Using the results of [15] one can choose β=(1/6)log2(7)0.47\beta=(1/6)\log_{2}{(7)}\approx 0.47. Stronger upper bounds on the stabilizer rank χt(0)\chi_{t}(0) could improve the runtime scaling in Eq. (2). Likewise, the runtime scaling in Eq. (3) holds for any exponent γ\gamma such that χt(δ)=O(2γt)\chi_{t}(\delta)=O(2^{\gamma t}) for any constant δ>0\delta>0 and all sufficiently large tt. For simplicity here we assumed that the precision parameter ϵ\epsilon in Eq. (3) is a constant. In this paper we propose a systematic method of finding approximate stabilizer decompositions of AtA^{\otimes t} which yields an upper bound χt(δ)=O(2γtδ1)\chi_{t}(\delta)=O(2^{\gamma t}\delta^{-1}), where γ0.228\gamma\approx 0.228, see Eq. (4). We conjecture that this upper bound is tight.


   

Figure 1: Output single-qubit probability distributions obtained by a classical simulation of the hidden shift quantum algorithm on n=40n=40 qubits. Only one half of all qubits are shown (qubits 21,22,,4021,22,\ldots,40). The final state of the algorithm is |s=U|0n|s\rangle=U|0^{n}\rangle, where ss is the hidden shift string to be found and UU is a Clifford+TT circuit with the TT-count t=40t=40 (left) and t=48t=48 (right). In both cases the circuit UU contains a few hundred Clifford gates. For each qubit the probability of measuring ‘1’ in the final state is indicated in blue. The xx-axis labels indicate the correct hidden shift bits. The entire simulation took several hours on a laptop computer.

We implemented our classical sampling algorithm in MATLAB and used it to simulate a class of benchmark quantum circuits on n=40n=40 qubits, with a few hundred Clifford gates, and TT-count t48t\leq 48. Specifically, we simulated a quantum algorithm which solves the hidden shift problem for non-linear Boolean functions [16]. An instance of the hidden shift problem is defined by a pair of oracle functions f,f:𝔽2n{±1}f,f^{\prime}\,:\,\mathbb{F}_{2}^{n}\to\{\pm 1\} and a hidden shift string s𝔽2ns\in\mathbb{F}_{2}^{n}. It is promised that ff is a bent (maximally non-linear) function, that is, the Hadamard transform of ff takes values ±1\pm 1. It is also promised that ff^{\prime} is the Hadamard transform of the shifted version of ff, that is,

f(x)=2n/2y𝔽2n(1)xyf(ys)for all x𝔽2n.f^{\prime}(x)=2^{-n/2}\sum_{y\in\mathbb{F}_{2}^{n}}(-1)^{x\cdot y}f(y\oplus s)\quad\mbox{for all $x\in\mathbb{F}_{2}^{n}$}. (5)

Here \oplus stands for the bit-wise XOR. The goal is to learn the hidden shift ss by making as few queries to ff and ff^{\prime} as possible. The classical query complexity of this problem is known to be linear in nn, see Theorem 8 of Ref. [16]. In the quantum setting, ff and ff^{\prime} are given as diagonal nn-qubit unitary operators OfO_{f} and OfO_{f^{\prime}} such that Of|x=f(x)|xO_{f}|x\rangle=f(x)|x\rangle and Of|x=f(x)|xO_{f^{\prime}}|x\rangle=f^{\prime}(x)|x\rangle for all x𝔽2nx\in\mathbb{F}_{2}^{n}. A quantum algorithm can learn ss by making a single query to each of these oracles, as can be seen from the identity [16]

|s=U|0n,UHnOfHnOfHn.|s\rangle=U|0^{n}\rangle,\quad U\equiv H^{\otimes n}O_{f^{\prime}}H^{\otimes n}O_{f}H^{\otimes n}. (6)

This hidden shift problem is ideally suited for our benchmarking task for two reasons. First, the algorithm produces a deterministic output, i.e., the output is a computational basis state |s|s\rangle for some nn-bit string ss. Because of this we achieve the most favorable runtime scaling in Eq. (3) since each bit of ss can be learned by calling the sampling algorithm with a single-qubit output register (w=1w=1) and a constant statistical error ϵ\epsilon. Second, the TT-count of the algorithm can be easily controlled by choosing a suitable bent function. Indeed, the non-oracle part of the algorithm consists only of Hadamard gates. We show that for a large class of bent functions ff (from the so-called Maiorana-McFarland family) the oracles OfO_{f} and OfO_{f^{\prime}} can be constructed using Clifford gates and only a few TT gates, see the Supplemental Material for details.

The numerical simulations were performed for two randomly generated instances of the hidden shift problem with n=40n=40 qubits. For each of these instances we simulated the quantum circuit for the hidden shift algorithm, i.e., the circuit implementing the unitary UU described above. The TT-counts of the two simulated circuits are t=40t=40 and t=48t=48 respectively. Since the hidden shift ss is known beforehand, we are able to verify correctness of the simulation. Our results are presented in Fig. 1. As one can see from the plots, the output probability distribution of each qubit has most of its weight at the corresponding value of the hidden shift bit. Only the output probabilities for qubits 21,22,,4021,22,\ldots,40 are shown because our algorithm perfectly recovered the first half of the hidden shift bits 1,2,,201,2,\ldots,20. This perfect recovery occurs due to the special structure of the chosen bent functions, see the Supplemental Material for further details.

The rest of the paper is organized as follows. In Section II we give an overview of our main techniques. In Section III we summarize some basic facts concerning stabilizer states. We present our classical simulation algorithms for Clifford+TT circuits in Section IV. Finally, we show how to approximate tensor products of magic states by linear combinations of stabilizer states in Section V. In the Supplemental Material we provide pseudocode for the main subroutines used in our algorithms, and we discuss further details of the simulations reported in Fig. 1.

II Sketch of techniques

Following Ref. [15], we simulate a Clifford+TT circuit classically using three basic steps. First, each TT-gate in the original circuit is replaced by a certain gadget that contains only Clifford gates and a 0,10,1-measurement. The Clifford gates may be classically controlled by the measurement outcome. The gadget consumes one copy of the magic state |A|A\rangle. This gives an equivalent ‘gadgetized’ circuit acting on a non-stabilizer initial state that contains tt copies of |A|A\rangle. We show how to remove all intermediate measurements from the gadgetized circuit by replacing the outcomes of these measurements by random uniform postselection bits. Accordingly, we replace the classically controlled Clifford gates by a suitable random ensemble of uncontrolled Clifford gates. Second, the initial magic state AtA^{\otimes t} is represented (exactly or approximately) as a linear combination of χ2n\chi\ll 2^{n} stabilizer states. The action of the gadgetized circuit on each term in this linear combination can be efficiently simulated using the standard Gottesman-Knill theorem since the gadgetized circuit contains only Clifford gates. This allows us to represent the final state before the measurement of QoutQ_{out} as a linear combination of χ\chi stabilizer states. We simulate the measurement of QoutQ_{out} on this final state independently for each term in the linear combination (we also have to simulate certain additional post-selective measurements introduced at the first step). This is possible due to the fact that 0,10,1-measurements map stabilizer states to stabilizer states. The final post-measurement state is a linear combination of at most χ\chi stabilizer states. The third and the most time consuming step is computing the norm of the post-measurement state. This norm is simply related to the quantity of interest, such as the output probability Pout(x)P_{out}(x). We show how to obtain a square-root speedup in this step compared with Ref. [15] reducing the runtime scaling from χ2\chi^{2} to χ\chi. This is achieved using a novel subroutine for approximating the norm of a linear combination of stabilizer states. The subroutine has runtime O(χt3ϵ2)O(\chi t^{3}\epsilon^{-2}), where χ\chi is the number of terms in the linear combination, tt is the number of qubits, and ϵ\epsilon is the relative error. We expect that this subroutine may find applications in other contexts. We achieve a further speedup compared with Ref. [15] by reducing the scaling χ20.47t\chi\approx 2^{0.47t} to χ20.23t\chi\approx 2^{0.23t} by developing techniques for approximate stabilizer decompositions of AtA^{\otimes t}. Although in general the simulation algorithm based on approximate stabilizer decomposition cannot accurately compute individual probabilities of the output distribution, we show that it can be used for sampling from the output distribution with a small statistical error.

III Stabilizer formalism

Before moving further, let us state some facts concerning stabilizer groups and stabilizer states. Let 𝒫n{\cal P}_{n} be the nn-qubit Pauli group. Any element of 𝒫n{\cal P}_{n} has the form imP1Pni^{m}P_{1}\otimes\cdots\otimes P_{n}, where each factor PaP_{a} is either the identity or a single-qubit Pauli operator X,Y,ZX,Y,Z and m4m\in\mathbb{Z}_{4}. An abelian subgroup 𝒢𝒫n{\cal G}\subseteq{\cal P}_{n} is called a stabilizer group if I𝒢-I\notin{\cal G}. Each stabilizer group has the form 𝒢=G1,,Gr{\cal G}=\langle G_{1},\ldots,G_{r}\rangle for some generating set of pairwise commuting self-adjoint Pauli operators G1,,Gr𝒢G_{1},\ldots,G_{r}\in{\cal G} such that |𝒢|=2r|{\cal G}|=2^{r}. The integer rr is called the dimension of 𝒢{\cal G} and is denoted r=dim(𝒢)r=\dim{({\cal G})}. A state ψ\psi is said to be stabilized by 𝒢{\cal G} if Pψ=ψP\psi=\psi for all P𝒢P\in{\cal G}. States stabilized by 𝒢{\cal G} span a “codespace” of dimension 2nr2^{n-r}. A projector onto a codespace has the form

Π𝒢=2rP𝒢P.\Pi_{\cal G}=2^{-r}\sum_{P\in{\cal G}}P. (7)

A pure nn-qubit state ψ\psi is a stabilizer state iff |ψ=U|0n|\psi\rangle=U|0^{n}\rangle for some Clifford unitary UU. Any stabilizer state ψ\psi is uniquely defined (up to the overall phase) by a stabilizer group 𝒢𝒫n{\cal G}\subseteq{\cal P}_{n} of dimension nn such that ψ\psi is the only state stabilized by 𝒢{\cal G}. Let 𝒮n{\cal S}_{n} be the set of all nn-qubit stabilizer states. This set is known to be a 22-design [17], that is,

|𝒮n|1ψ𝒮n|ψψ|2=dμ(ϕ)|ϕϕ|2,|{\cal S}_{n}|^{-1}\sum_{\psi\in{\cal S}_{n}}|\psi\rangle\langle\psi|^{\otimes 2}=\int d\mu(\phi)|\phi\rangle\langle\phi|^{\otimes 2}, (8)

where the integral is with respect to the Haar measure on the set of all normalized nn-qubit states ϕ\phi.

Throughout the paper we assume that stabilizer states are represented in a certain standard form defined in Appendix B. In this representation, three basic tasks can be performed efficiently. First, one can compute the inner product between stabilizer states [3, 18, 15]. More precisely, consider stabilizer states ψ,ϕ𝒮n\psi,\phi\in{\cal S}_{n}. Then ψ|ϕ=b2p/2eiπm/4\langle\psi|\phi\rangle=b2^{-p/2}e^{i\pi m/4} for some b=0,1b=0,1, integer p[0,n]p\in[0,n] and m8m\in\mathbb{Z}_{8} that can be computed in time O(n3)O(n^{3}), see Ref. [15]. Pseudocode for computing the inner product ψ|ϕ\langle\psi|\phi\rangle can be found in Appendix C. Secondly, a projection of any stabilizer state onto the codespace of any stabilizer code is a stabilizer state which is easy to compute. More precisely, suppose 𝒢𝒫n{\cal G}\subseteq{\cal P}_{n} is a stabilizer group and φ𝒮n\varphi\in{\cal S}_{n}. Then Π𝒢|φ=b2p/2|ϕ\Pi_{\cal G}|\varphi\rangle=b2^{-p/2}|\phi\rangle for some b=0,1b=0,1, some integer p0p\geq 0, and stabilizer state ϕ𝒮n\phi\in{\cal S}_{n}. One can compute b,p,ϕb,p,\phi in time O(rn2)O(rn^{2}) as explained in Appendix E. Recall that r=dim(𝒢)r=\dim{({\cal G})}. Finally, one can generate a random stabilizer state drawn from the uniform distribution on 𝒮n{\cal S}_{n} in time O(n2)O(n^{2}), see Appendix D.

IV Classical simulation algorithms

First consider the task of approximating the output probability Pout(x)P_{out}(x). The algorithm described below consists of two stages with runtimes

τ1=O((w+t)(c+t)+(n+t)3)\tau_{1}=O\left((w+t)(c+t)+(n+t)^{3}\right)

and

τ2=O(2βtt3ϵ2log(pf1)).\tau_{2}=O(2^{\beta t}t^{3}\epsilon^{-2}\log(p_{f}^{-1})).

The first stage computes a stabilizer group 𝒢𝒫t{\cal G}\subseteq{\cal P}_{t} and an integer uu such that

Pout(x)=2uAt|Π𝒢|At.P_{out}(x)=2^{-u}\langle A^{\otimes t}|\Pi_{\cal G}|A^{\otimes t}\rangle. (9)

We begin by replacing each TT-gate in the original circuit UU by the well-known gadget [19] shown in Fig. 2. The gadget implements the TT-gate by performing Clifford gates CNOT, SS, and a 0,10,1-measurement. Each measurement outcome appears with the probability 1/21/2. The gate SS is applied only if the outcome is ’1’. The gadget also consumes one copy of the magic state |A|A\rangle which is destroyed in the process.

Refer to caption
Figure 2: The TT-gate gadget. The Clifford gate SS is classically controlled by the measurement outcome. Both outcomes appear with probability 1/21/2.

Suppose we postselect the outcome ’0’ in each gadget, i.e. replace each measurement by a projector |00||0\rangle\langle 0|. This removes the classically controlled SS-gates such that each gadget adds a single CNOT to the original circuit UU. Let VV be the modified version of UU. By definition, VV acts on n+tn+t qubits and contains c+tc+t Clifford gates. Let us agree that the tt ancillary qubits initialized in the magic state are appended at the end of nn computational qubits such that the circuit VV acts on the initial state |0nAt|0^{n}A^{\otimes t}\rangle. Combining the final measurement projector Π(x)=|xx|QoutIelse\Pi(x)=|x\rangle\langle x|_{Q_{out}}\otimes I_{else} with the projectors |00||0\rangle\langle 0| acting on the ancillary qubits gives a projector

Π=Π(x)|0t0t|\Pi=\Pi(x)\otimes|0^{t}\rangle\langle 0^{t}|

acting on n+tn+t qubits such that

Pout(x)=2t0nAt|VΠV|0nAt.P_{out}(x)=2^{t}\langle 0^{n}A^{\otimes t}|V^{\dagger}\Pi V|0^{n}A^{\otimes t}\rangle. (10)

Here we noted that the postselection probability is 2t2^{-t}. Obviously, Π=Π𝒲\Pi=\Pi_{\cal W} for a stabilizer group 𝒲𝒫n+t{\cal W}\subseteq{\cal P}_{n+t} of dimension w+tw+t. Namely, let q(j)q(j) be the jj-th qubit of QoutQ_{out}. Generators of 𝒲{\cal W} are Rj=(1)xjZq(j)R_{j}=(-1)^{x_{j}}Z_{q(j)} for j=1,,wj=1,\ldots,w and Rw+j=Zn+jR_{w+j}=Z_{n+j} for j=1,,tj=1,\ldots,t. Since the conjugation by VV maps Pauli operators to Pauli operators, we get VΠ𝒲V=Π𝒱V^{\dagger}\Pi_{{\cal W}}V=\Pi_{\cal V}, where 𝒱{\cal V} is a stabilizer group of dimension w+tw+t generated by Rj=VRjV𝒫n+tR_{j}^{\prime}=V^{\dagger}R_{j}V\in{\cal P}_{n+t} with j=1,,w+tj=1,\ldots,w+t. Assuming that the action of a single Clifford gate on a Pauli operator can be computed in time O(1)O(1), one can compute each generator RjR_{j}^{\prime} in time O(c+t)O(c+t). Accordingly, 𝒱{\cal V} can be computed in time O((w+t)(c+t))O((w+t)(c+t)).

Let 𝒱0{\cal V}_{0} be the subgroup of 𝒱{\cal V} that includes all Pauli operators which act as II or ZZ on each of the first nn qubits. Let v=dim(𝒱0)v=\dim{({\cal V}_{0})}. A generating set Q1,,Qv𝒱0Q_{1},\ldots,Q_{v}\in{\cal V}_{0} can be computed in time O(n(w+t)+(w+t)3)=O((n+t)3)O(n(w+t)+(w+t)^{3})=O((n+t)^{3}) using standard linear algebra. We get

0n|VΠV|0n=0n|Π𝒱|0n=2wt+v0n|Π𝒱0|0n.\langle 0^{n}|V^{\dagger}\Pi V|0^{n}\rangle=\langle 0^{n}|\Pi_{\cal V}|0^{n}\rangle=2^{-w-t+v}\langle 0^{n}|\Pi_{{\cal V}_{0}}|0^{n}\rangle. (11)

since 0n|P|0n=0\langle 0^{n}|P|0^{n}\rangle=0 P𝒱𝒱0\;\forall\;P\in{\cal V}\setminus{\cal V}_{0}. Define tt-qubit Pauli operators Gi=0n|Qi|0nG_{i}=\langle 0^{n}|Q_{i}|0^{n}\rangle, i=1,,vi=1,\ldots,v. These operators pairwise commute since 𝒱0{\cal V}_{0} is abelian and QiQ_{i} commute with each other on the first nn qubits. If IG1,,Gv-I\in\langle G_{1},\ldots,G_{v}\rangle then there exists Q𝒱0Q\in{\cal V}_{0} with I=0n|Q|0n-I=\langle 0^{n}|Q|0^{n}\rangle and therefore

Π𝒱|0n=Π𝒱Q|0n=Π𝒱|0n=0\Pi_{\cal V}|0^{n}\rangle=\Pi_{\cal V}Q|0^{n}\rangle=-\Pi_{\cal V}|0^{n}\rangle=0

in which case Pout(x)=0P_{out}(x)=0 and we are done. Let us now consider the case IG1,,Gv-I\notin\langle G_{1},\ldots,G_{v}\rangle. In this case let 𝒢𝒫t{\cal G}\subseteq{\cal P}_{t} be the stabilizer group generated by G1,,GvG_{1},\ldots,G_{v} and r=dim(𝒢)r=\dim{({\cal G})}. One can check the condition IG1,,Gv-I\notin\langle G_{1},\ldots,G_{v}\rangle and compute rr in time O(t3)O(t^{3}). Without loss of generality, 𝒢=G1,,Gr{\cal G}=\langle G_{1},\ldots,G_{r}\rangle. Noting that 𝒱0{\cal V}_{0} must contain 2vr2^{v-r} elements acting trivially on the last tt qubits yields 0n|Π𝒱0|0n=Π𝒢\langle 0^{n}|\Pi_{{\cal V}_{0}}|0^{n}\rangle=\Pi_{\cal G}. This proves Eq. (9) with u=wvu=w-v and the stabilizer group 𝒢{\cal G} defined above. Combining all the steps needed to compute 𝒢{\cal G} gives the promised runtime τ1=O((w+t)(c+t)+(n+t)3)\tau_{1}=O((w+t)(c+t)+(n+t)^{3}).

The second stage of the algorithm computes the expectation value in Eq. (9) by decomposing |At|A^{\otimes t}\rangle into a linear combination of stabilizer states. Suppose

|At=a=1χya|φa|A^{\otimes t}\rangle=\sum_{a=1}^{\chi}y_{a}|\varphi_{a}\rangle (12)

for some stabilizer states φa𝒮t\varphi_{a}\in{\cal S}_{t} and some coefficients yay_{a}. For each a=1,,χa=1,\ldots,\chi compute ba{0,1}b_{a}\in\{0,1\}, an integer pa0p_{a}\geq 0 and a stabilizer state ϕa𝒮t\phi_{a}\in{\cal S}_{t} such that

Π𝒢|φa=ba2pa/2|ϕa.\Pi_{\cal G}|\varphi_{a}\rangle=b_{a}2^{-p_{a}/2}|\phi_{a}\rangle.

see Appendix E for details. As stated above, this computation takes time O(χt3)O(\chi t^{3}). Introducing new coefficients za=2(u+pa)/2yabaz_{a}=2^{-(u+p_{a})/2}y_{a}b_{a} and using Eqs. (9,12) one gets

Pout(x)=ψ2,|ψ=a=1χza|ϕa,ϕa𝒮t.P_{out}(x)=\|\psi\|^{2},\quad|\psi\rangle=\sum_{a=1}^{\chi}z_{a}|\phi_{a}\rangle,\quad\phi_{a}\in{\cal S}_{t}. (13)

Here ϕa\phi_{a} are tt-qubit stabilizer states. Below we describe a randomized algorithm that takes as input a tt-qubit state ψ\psi, a target error parameter ϵ>0\epsilon>0 and a failure probability pfp_{f}. The algorithm computes a real number ξ\xi which, with probability at least 1pf1-p_{f}, approximates the norm of ψ\psi with relative error ϵ\epsilon. The running time of the algorithm is O(χt3ϵ2log(pf1))O(\chi t^{3}\epsilon^{-2}\log(p_{f}^{-1})). The key idea is to approximate ψ2\|\psi\|^{2} by computing inner products between ψ\psi and randomly chosen stabilizer states.

We shall first consider the special case where the failure probability is 1/41/4; at the end we describe how to reduce it to a given value pf1p_{f}^{-1}. Let θ𝒮t\theta\in{\cal S}_{t} be a random stabilizer state drawn from the uniform distribution. Define expectation values

M2𝔼θ|θ|ψ|2andM4𝔼θ|θ|ψ|4.M_{2}\equiv\mathbb{E}_{\theta}|\langle\theta|\psi\rangle|^{2}\quad\mbox{and}\quad M_{4}\equiv\mathbb{E}_{\theta}|\langle\theta|\psi\rangle|^{4}.

Using Eq. (8) one can compute M2M_{2} and M4M_{4} by pretending that θ\theta is drawn from the Haar measure. Standard formulas for the integrals over the unit sphere yield

M2=ψ2dandM4=2ψ4d(d+1),whered2t.M_{2}=\frac{\|\psi\|^{2}}{d}\quad\mbox{and}\quad M_{4}=\frac{2\|\psi\|^{4}}{d(d+1)},\quad\mbox{where}\quad d\equiv 2^{t}. (14)

Suppose θ1,,θL𝒮t\theta_{1},\ldots,\theta_{L}\in{\cal S}_{t} are random independent stabilizer states. Define a random variable

ξ=dLi=1L|θi|ψ|2.\xi=\frac{d}{L}\sum_{i=1}^{L}|\langle\theta_{i}|\psi\rangle|^{2}. (15)

From Eq. (14) one infers that the expected value of ξ\xi is ξ¯=𝔼(ξ)=ψ2\bar{\xi}=\mathbb{E}(\xi)=\|\psi\|^{2} and the standard deviation of ξ\xi is

σ=d2L1(M4M22)=d1d+1L1/2ϕ2.\sigma=\sqrt{d^{2}L^{-1}(M_{4}-M_{2}^{2})}=\sqrt{\frac{d-1}{d+1}}L^{-1/2}\|\phi\|^{2}.

For large tt one has σL1/2ψ2\sigma\approx L^{-1/2}\|\psi\|^{2}. By the Chebyshev inequality, Pr[|ξξ¯|2σ]14\mathrm{Pr}{\left[\,{|\xi-\bar{\xi}|\geq 2\sigma}\,\right]}\leq\frac{1}{4}. Thus

(1ϵ)ψ2ξ(1+ϵ)ψ2(1-\epsilon)\|\psi\|^{2}\leq\xi\leq(1+\epsilon)\|\psi\|^{2} (16)

with probability at least 3/43/4 provided that L=4ϵ2L=4\epsilon^{-2}.

Now let us discuss how to reduce the failure probability (from 1/41/4) so that it is below a given value pf1p_{f}^{-1}. To achieve this, we compute independent estimates ξ1,ξ2,ξJ\xi_{1},\xi_{2},\ldots\xi_{J} using the above procedure and output the median ξmed\xi_{\mathrm{med}} of these values. It is a simple fact that this procedure reduces the failure probability to below pf1p_{f}^{-1} using only J=O(log(pf1))J=O(\log(p_{f}^{-1})) estimates (see Lemma 6.1 of Ref. [20]). With this choice, the probability that Eq. (16) holds with ξ\xi replaced by ξmed\xi_{\mathrm{med}} is at least 1pf1-p_{f}.

The inner product θi|ψ=a=1χzaθi|ϕa\langle\theta_{i}|\psi\rangle=\sum_{a=1}^{\chi}z_{a}\langle\theta_{i}|\phi_{a}\rangle in Eq. (15) can be computed in time O(χt3)O(\chi t^{3}) since θi\theta_{i} and ϕa\phi_{a} are stabilizer states of tt qubits. It follows that Pout(x)=ψ2P_{out}(x)=\|\psi\|^{2} can be approximated in time O(χt3ϵ2log(pf1))O(\chi t^{3}\epsilon^{-2}\log(p_{f}^{-1})), as promised.

Since the runtime grows linearly with χ\chi, we would like to choose a stabilizer decomposition in Eq. (12) with a small rank χ\chi. Clearly, the optimal choice is χ=χt\chi=\chi_{t}, where χtχt(0)\chi_{t}\equiv\chi_{t}(0) is the stabilizer rank defined in the introduction. Unfortunately, the exact value of χt\chi_{t} is unknown. Using the identity

|A2=12(|00+i|11)+eiπ/42(|01+|10)|A^{\otimes 2}\rangle=\frac{1}{2}(|00\rangle+i|11\rangle)+\frac{e^{i\pi/4}}{2}(|01\rangle+|10\rangle) (17)

one can see that A2A^{\otimes 2} is a linear combination of two stabilizer states, that is, χ2=2\chi_{2}=2. By dividing tt qubits into t/2t/2 pairs and applying the decomposition Eq. (17) to each pair one gets χt2t/2\chi_{t}\leq 2^{t/2}. The results of [15] give a slightly better bound χt2βt\chi_{t}\leq 2^{\beta t} with β0.47\beta\approx 0.47. This completes the analysis of the first algorithm.

Remark 1: If 𝒢{\cal G} has a small dimension, namely, r<βr<\beta, it can be easier to compute Pout(x)P_{out}(x) directly from Eqs. (7,9) which yield Pout(x)P𝒢At|P|AtP_{out}(x)\sim\sum_{P\in{\cal G}}\langle A^{\otimes t}|P|A^{\otimes t}\rangle. Clearly, each term in the sum can be computed in time O(t)O(t), so the overall runtime becomes O(t|𝒢|)=O(t2r)O(t|{\cal G}|)=O(t2^{r}).

Remark 2: An alternative strategy to estimate the expectation value in Eq. (9) is to compute the inner products

Π𝒢θi|At=a=1χyaΠ𝒢θi|φa\langle\Pi_{\cal G}\theta_{i}|A^{\otimes t}\rangle=\sum_{a=1}^{\chi}y_{a}\langle\Pi_{\cal G}\theta_{i}|\varphi_{a}\rangle

for i=1,,Li=1,\ldots,L. Here φa\varphi_{a} are the stabilizer states defined in Eq. (12) and θi\theta_{i} are random stabilizer states. The same arguments as above show that

At|Π𝒢|At=Π𝒢At2dLi=1L|Π𝒢θi|At|2.\langle A^{\otimes t}|\Pi_{\cal G}|A^{\otimes t}\rangle=\|\Pi_{\cal G}A^{\otimes t}\|^{2}\approx\frac{d}{L}\sum_{i=1}^{L}|\langle\Pi_{\cal G}\theta_{i}|A^{\otimes t}\rangle|^{2}.

This may be beneficial in the regime LχL\ll\chi since one has to compute the action of Π𝒢\Pi_{\cal G} only LL times rather than χ\chi times.

Let us now describe the algorithm that allows one to sample xx from the distribution PoutP_{out} with statistical error ϵ\epsilon. As before, we replace each TT-gate in the original circuit UU by the gadget shown on Fig. 2, prepare all magic states |A|A\rangle at the very first time step, and permute the qubits such that the initial state is |0nAt|0^{n}A^{\otimes t}\rangle. Let yj{0,1}y_{j}\in\{0,1\} be the outcome of the measurement performed in the jj-th gadget and y=(y1,,yt)y=(y_{1},\ldots,y_{t}). Let VyV_{y} be the Clifford circuit on n+tn+t qubits corresponding to measurement outcomes yy. Each gadget with yj=0y_{j}=0 contributes a CNOT gate to VyV_{y}, whereas each gadget with yj=1y_{j}=1 contributes a CNOT and the SS-gate to VyV_{y}. Thus VyV_{y} contains c+t+|y|c+t+|y| gates. A composition of all gadgets and Clifford gates of UU implements a trace preserving completely positive (TPCP) map

Φ(ρ)=y(In|yy|)VyρVy(In|yy|).\Phi(\rho)=\sum_{y}(I_{n}\otimes|y\rangle\langle y|)V_{y}\rho V_{y}^{\dagger}(I_{n}\otimes|y\rangle\langle y|).

Here InI_{n} is the nn-qubit identity operator and the sum runs over all tt-bit strings yy. Suppose first that Φ\Phi is applied to a state ρin=|0n0n||AA|t\rho_{in}=|0^{n}\rangle\langle 0^{n}|\otimes|A\rangle\langle A|^{\otimes t}. Then the final state of the nn computational qubits is U|0nU|0^{n}\rangle regardless of yy and each yy appears with probability 2t2^{-t}. Thus

Φ(ρin)=U|0n0n|UI2t.\Phi(\rho_{in})=U|0^{n}\rangle\langle 0^{n}|U^{\dagger}\otimes\frac{I}{2^{t}}. (18)

Next suppose that Φ\Phi is applied to a state ρ~in=|0n0n||ψψ|\tilde{\rho}_{in}=|0^{n}\rangle\langle 0^{n}|\otimes|\psi\rangle\langle\psi|, where ψ\psi is a linear combination of χ\chi stabilizer states φ1,,φχ𝒮t\varphi_{1},\ldots,\varphi_{\chi}\in{\cal S}_{t} that approximates AtA^{\otimes t} with a small error:

|ψ=a=1χza|φa,|At|ψ|21ϵ2/25.|\psi\rangle=\sum_{a=1}^{\chi}z_{a}|\varphi_{a}\rangle,\quad\quad|\langle A^{\otimes t}|\psi\rangle|^{2}\geq 1-\epsilon^{2}/25. (19)

Here zaz_{a} are some coefficients and we assume ψ\psi has unit norm. The error ϵ2/25\epsilon^{2}/25 is sufficient to ensure that the output distribution of the overall simulation algorithm is ϵ\epsilon-close to PoutP_{out}. From Eq. (19) one gets

ρinρ~in1=|AA|t|ψψ|125ϵ.\|\rho_{in}-\tilde{\rho}_{in}\|_{1}=\|\,|A\rangle\langle A|^{\otimes t}-|\psi\rangle\langle\psi|\,\|_{1}\leq\frac{2}{5}\epsilon. (20)

By definition of Φ\Phi,

Φ(ρ~in)=ypy|ϕyϕy||yy|,\Phi(\tilde{\rho}_{in})=\sum_{y}p_{y}\,|\phi_{y}\rangle\langle\phi_{y}|\otimes|y\rangle\langle y|, (21)

where

py=0nψ|Vy(In|yy|)Vy|0nψp_{y}=\langle 0^{n}\otimes\psi|V_{y}^{\dagger}(I_{n}\otimes|y\rangle\langle y|)V_{y}|0^{n}\otimes\psi\rangle (22)

and ϕy\phi_{y} are normalized tt-qubit states defined by

|ϕy=py1/2y|Vy|0nψ.|\phi_{y}\rangle=p_{y}^{-1/2}\langle y|V_{y}|0^{n}\otimes\psi\rangle. (23)

Clearly, pp is a normalized probability distribution on the set of tt-bit strings. The state ϕy\phi_{y} is defined only for py>0p_{y}>0. Combining Eqs. (18,20,21) and tracing out the last tt qubits of Φ(ρin)\Phi(\rho_{in}) and Φ(ρ~in)\Phi(\tilde{\rho}_{in}) one infers that

U|0n0n|Uypy|ϕyϕy|125ϵ.\|\,U|0^{n}\rangle\langle 0^{n}|U^{\dagger}-\sum_{y}p_{y}|\phi_{y}\rangle\langle\phi_{y}|\,\|_{1}\leq\frac{2}{5}\epsilon. (24)

Here we noted that TPCP maps do not increase the trace distance. Combining Eqs. (18,20,21) and tracing out the first nn qubits of Φ(ρin)\Phi(\rho_{in}) and Φ(ρ~in)\Phi(\tilde{\rho}_{in}) shows that the distribution pp satisfies pu125ϵ\|p-u\|_{1}\leq\frac{2}{5}\epsilon, where uu is the uniform distribution on the set of tt-bit strings. Using this fact and Eq. (24) we arrive at

U|0n0n|U12ty|ϕyϕy|145ϵ.\|\,U|0^{n}\rangle\langle 0^{n}|U^{\dagger}-\frac{1}{2^{t}}\sum_{y}|\phi_{y}\rangle\langle\phi_{y}|\,\|_{1}\leq\frac{4}{5}\epsilon. (25)

For each tt-bit string yy define a probability distribution Pouty(x)=ϕy|Π(x)|ϕy{P}^{y}_{out}(x)=\langle\phi_{y}|\Pi(x)|\phi_{y}\rangle. Below we give an algorithm which takes as input yy and ϵ\epsilon and produces a sample from a distribution P~outy\tilde{P}^{y}_{out} which satisfies

Pouty(x)P~outy(x)1ϵ/5\|{P}^{y}_{out}(x)-\tilde{P}^{y}_{out}(x)\|_{1}\leq\epsilon/5 (26)

Our algorithm to approximately sample from PoutP_{out} has two steps. We first generate a random uniformly distributed tt-bit string yy and then we sample xx from P~outy\tilde{P}^{y}_{out}. From Eqs. (25,26) we see that the distribution over outputs x{0,1}wx\in\{0,1\}^{w} produced by this algorithm approximates PoutP_{out} within error ϵ\epsilon in the trace norm.

We are now ready to describe how to sample from P~outy\tilde{P}_{out}^{y} satisfying Eq. (26). We first describe how to compute an approximation to Pouty(x)P_{out}^{y}(x) with relative error δ\delta. Note that

Pouty(x)=0nψ|Vy(Π(x)|yy|)Vy|0nψ0nψ|Vy(In|yy|)Vy|0nψ.P^{y}_{out}(x)=\frac{\langle 0^{n}\otimes\psi|V_{y}^{\dagger}(\Pi(x)\otimes|y\rangle\langle y|)V_{y}|0^{n}\otimes\psi\rangle}{\langle 0^{n}\otimes\psi|V_{y}^{\dagger}(I_{n}\otimes|y\rangle\langle y|)V_{y}|0^{n}\otimes\psi\rangle}. (27)

Here we used Eqs. (22,23). Repeating the same arguments as in the derivation of Eq. (9) one gets

Pouty(x)=2uψ|Π𝒢|ψ2vψ|Π|ψP^{y}_{out}(x)=\frac{2^{-u}\langle\psi|\Pi_{\cal G}|\psi\rangle}{2^{-v}\langle\psi|\Pi_{\cal H}|\psi\rangle} (28)

for some stabilizer groups 𝒢,𝒫t{\cal G},{\cal H}\subseteq{\cal P}_{t} and integers u,vu,v that can be computed in time τ1=O((w+t)(c+t)+(n+t)3)\tau_{1}=O((w+t)(c+t)+(n+t)^{3}). We already know a randomized algorithm which computes ψ|Π𝒢|ψ\langle\psi|\Pi_{\cal G}|\psi\rangle and ψ|Π|ψ\langle\psi|\Pi_{\cal H}|\psi\rangle with a relative error δ\delta in time τ2=O(χt3δ2log(pf1))\tau_{2}=O(\chi t^{3}\delta^{-2}\log(p_{f}^{-1})). Recall that pfp_{f} is the probability that the algorithm does not achieve the desired approximation. Thus we can compute Pouty(x)P^{y}_{out}(x) with a relative error 2δ2\delta in time τ1+τ2\tau_{1}+\tau_{2}.

Now consider the task of sampling from PoutyP^{y}_{out}. Assume for simplicity that Qout={1,2,,w}Q_{out}=\{1,2,\ldots,w\}. For each j=1,,w1j=1,\ldots,w-1 define conditional probabilities

Pouty(z|x1,,xj1)=Pouty(x1,,xj1,z)Pouty(x1,,xj1),P^{y}_{out}(z|x_{1},\ldots,x_{j-1})=\frac{P^{y}_{out}(x_{1},\ldots,x_{j-1},z)}{P^{y}_{out}(x_{1},\ldots,x_{j-1})}, (29)

where z{0,1}z\in\{0,1\}. Suppose the bits x1,,xj1x_{1},\ldots,x_{j-1} have already been sampled (initially j=1j=1). Then the next bit xjx_{j} can be sampled by tossing a coin with bias Pouty(0|x1,,xj1)P^{y}_{out}(0|x_{1},\ldots,x_{j-1}). Things are complicated by the fact that we cannot exactly compute this conditional probability. We use the same simulation strategy except that at each step the conditional probability Pouty(0|x1,,xj1)P^{y}_{out}(0|x_{1},\ldots,x_{j-1}) is replaced by an approximation qjq_{j}. Here we require that with probability at least 1pf1-p_{f}, both qjq_{j} and 1qj1-q_{j} approximate the conditional probabilities Pouty(0|x1,,xj1)P^{y}_{out}(0|x_{1},\ldots,x_{j-1}) and Pouty(1|x1,,xj1)P^{y}_{out}(1|x_{1},\ldots,x_{j-1}) respectively with relative error O(δ)O(\delta). Such an approximation qjq_{j} can be computed in time O(τ1+τ2)O(\tau_{1}+\tau_{2}) using the procedure described above for approximating the probabilities on the right-hand side of Eq. (29). Indeed, first compute a,ba,b which, with probability at least 1pf1-p_{f}, approximate Pouty(0|x1,,xj1)P^{y}_{out}(0|x_{1},\ldots,x_{j-1}) and Pouty(1|x1,,xj1)P^{y}_{out}(1|x_{1},\ldots,x_{j-1}) respectively with relative error δ\delta. If aba\leq b then we set qj=aq_{j}=a while if b<ab<a then we set qj=1bq_{j}=1-b.

We now analyze the resulting simulation algorithm and show that we can ensure Eq. (26) by choosing approximation error δ=O(ϵw1)\delta=O(\epsilon w^{-1}) and failure probability pf=O(ϵw1)p_{f}=O(\epsilon w^{-1}). Let us first suppose that all probabilities qjq_{j} computed by the algorithm achieve the desired approximation δ\delta (i.e., no failures occur). Conditioned on this event we see that the output distribution produced by the algorithm approximates Pouty(x)P_{out}^{y}(x) with relative error O(δw)O(\delta w). This conditional probability distribution can therefore be made ϵ/10\epsilon/10-close (say) to PoutyP_{out}^{y} by choosing δ=O(ϵw1)\delta=O(\epsilon w^{-1}). It remains to show that by choosing pf=O(ϵw1)p_{f}=O(\epsilon w^{-1}) we can ensure that the output distribution P~outy\tilde{P}^{y}_{out} of the simulation algorithm is ϵ/10\epsilon/10-close to the distribution conditioned on no failures. This follows because the algorithm computes O(w)O(w) probabilities {qj}\{q_{j}\} in total and choosing pf=O(ϵw1)p_{f}=O(\epsilon w^{-1}) we can ensure that all of them are computed to within the desired approximation error δ\delta, with probability at least 1ϵ/201-\epsilon/20. With this choice we have P~outy=(1ϵ/20)PA+ϵ/20PB\tilde{P}^{y}_{out}=(1-\epsilon/20)P_{A}+\epsilon/20P_{B} where PAP_{A} is the distribution conditioned on no failures, and thus P~outyPA1ϵ/10\|\tilde{P}^{y}_{out}-P_{A}\|_{1}\leq\epsilon/10 as claimed.

The overall running time of this algorithm is τ1+τ2\tau_{1}^{\prime}+\tau_{2}^{\prime}, where τ1=O(wτ1)=O(w(w+t)(c+t)+w(n+t)3)\tau_{1}^{\prime}=O(w\tau_{1})=O(w(w+t)(c+t)+w(n+t)^{3}) and τ2=O(wτ2)=O(χw3t3ϵ2log(wϵ1))\tau_{2}^{\prime}=O(w\tau_{2})=O(\chi w^{3}t^{3}\epsilon^{-2}\log(w\epsilon^{-1})).

Remark: This algorithm can be modified slightly to handle certain Clifford+TT circuits which use measurement and classical control. To see how, recall that in the TT-gate gadget from Fig. 2, a single qubit is measured in the computational basis (yielding both outcomes with equal probability) and a Clifford operation is classically controlled on the measurement outcome. In our simulation algorithm the measurement is replaced by a uniformly chosen postselection bit yjy_{j}. Exactly the same strategy can be used for other simple gadgets which involve measurement and classical control. For example, the Toffoli gate can be implemented as a Clifford+TT circuit with only four TT-gates if we allow two ancillas, measurement, and classical control [13](otherwise it requires seven TT-gates [21, 22]). Fortunately it is possible to use the less costly circuit with four TT-gates in the above simulation algorithm by including one additional postselection bit per Toffoli gate.

V Approximating magic states

In this section we show how to compute a decomposition Eq. (19) with χ=O(2γtϵ2)\chi=O(2^{\gamma t}\epsilon^{-2}), where γ\gamma satisfies Eq. (4). Define a state

|H=cos(π/8)|0+sin(π/8)|1.|H\rangle=\cos(\pi/8)|0\rangle+\sin(\pi/8)|1\rangle.

We note that the magic state |A|A\rangle is equivalent to |H|H\rangle modulo Clifford gates and a global phase, |A=eiπ/8HS|H|A\rangle=e^{i\pi/8}HS^{\dagger}|H\rangle. Thus it suffices to construct a state

|ψ=a=1χza|φa,φ1,,φχ𝒮t|\psi\rangle=\sum_{a=1}^{\chi}z_{a}|\varphi_{a}\rangle,\quad\varphi_{1},\ldots,\varphi_{\chi}\in{\cal S}_{t} (30)

such that ψ=1\|\psi\|=1,

|Ht|ψ|21δandχ=O(2γtδ1)|\langle H^{\otimes t}|\psi\rangle|^{2}\geq 1-\delta\quad\mbox{and}\quad\chi=O(2^{\gamma t}\delta^{-1}) (31)

for all sufficiently small δ>0\delta>0.

Our starting point is the identity

|Ht=1(2ν)tx𝔽2t|x~1x~2x~t|H^{\otimes t}\rangle=\frac{1}{(2\nu)^{t}}\sum_{x\in\mathbb{F}_{2}^{t}}|\tilde{x}_{1}\otimes\tilde{x}_{2}\otimes\ldots\otimes\tilde{x}_{t}\rangle (32)

where |0~|0|\tilde{0}\rangle\equiv|0\rangle, |1~H|0=21/2(|0+|1)|\tilde{1}\rangle\equiv H|0\rangle=2^{-1/2}(|0\rangle+|1\rangle), and

νcos(π/8).\nu\equiv\cos(\pi/8).

The right-hand side of Eq. (32) is a uniform superposition of 2t2^{t} non-orthogonal stabilizer states labeled by elements of the vector space 𝔽2t\mathbb{F}_{2}^{t}. We shall construct an approximation ψ\psi which is a uniform superposition of states |x~1x~2x~t|\tilde{x}_{1}\otimes\tilde{x}_{2}\otimes\ldots\otimes\tilde{x}_{t}\rangle over a linear subspace of 𝔽2t\mathbb{F}_{2}^{t}.

Let L(t,k)L(t,k) be the set of all kk-dimensional linear subspaces 𝔽2t{\cal L}\subseteq\mathbb{F}_{2}^{t}. We will fix kk below. For each L(t,k){\cal L}\in L(t,k) define a state

|=12kZ()x|x~1x~2x~t|{\cal L}\rangle=\frac{1}{\sqrt{2^{k}Z({\cal L})}}\sum_{x\in{\cal L}}|\tilde{x}_{1}\otimes\tilde{x}_{2}\otimes\cdots\otimes\tilde{x}_{t}\rangle (33)

where

Z()x2|x|/2.Z({\cal L})\equiv\sum_{x\in{\cal L}}2^{-|x|/2}. (34)

Using the identity a~|b~=2|ab|/2\langle\tilde{a}|\tilde{b}\rangle=2^{-|a\oplus b|/2}, where a,b{0,1}a,b\in\{0,1\}, and the fact that {\cal L} is a linear subspace one can easily check that ||{\cal L}\rangle is a normalized state, |=1\langle{\cal L}|{\cal L}\rangle=1. We take our approximation ψ\psi from Eq. (30) to be Eq. (33) for a suitably chosen subspace L(t,k){\cal L}^{\star}\in L(t,k), which gives an approximate decomposition of HtH^{\otimes t} using χ=2k\chi=2^{k} stabilizer states. How small can we hope to make kk? Using the fact that H|0~=H|1~=ν\langle H|\tilde{0}\rangle=\langle H|\tilde{1}\rangle=\nu we see that

|Ht||2=2kν2tZ()|\langle H^{\otimes t}|{\cal L}\rangle|^{2}=\frac{2^{k}\nu^{2t}}{Z({\cal L})} (35)

From this we immediately get a lower bound on kk. Indeed, since Z()1Z({\cal L})\geq 1 we will need 2kν2t(1δ)2^{k}\geq\nu^{-2t}(1-\delta) to achieve the desired approximation. Below we describe a randomized algorithm which outputs a subspace {\cal L}^{\star} with 2k=O(δ1ν2t)2^{k}=O(\delta^{-1}\nu^{-2t}). Thus for constant δ\delta we achieve the best possible scaling of kk with tt. We will use the following fact about random subspaces of 𝔽2t\mathbb{F}_{2}^{t}.

Lemma 1.

Let L(t,k){\cal L}\in L(t,k) be chosen uniformly at random. Then

𝔼(Z())1+2kν2t.\mathbb{E}(Z({\cal L}))\leq 1+2^{k}\nu^{2t}. (36)
Proof.

By linearity, we have

𝔼(Z())=1+x𝔽2t02|x|/2𝔼(χ(x)),\mathbb{E}(Z({\cal L}))=1+\sum_{x\in\mathbb{F}_{2}^{t}\setminus 0}2^{-|x|/2}\cdot\mathbb{E}(\chi_{\cal L}(x)), (37)

where χ(x)\chi_{\cal L}(x) is the indicator function of {\cal L}. The expectation value 𝔼(χ(x))\mathbb{E}(\chi_{\cal L}(x)) with respect to {\cal L} for a fixed xx is (2k1)/(2t1)(2^{k}-1)/(2^{t}-1). Thus we arrive at

𝔼(Z())\displaystyle\mathbb{E}(Z({\cal L})) =1+(2k1)(2t1)x𝔽2t02|x|/2\displaystyle=1+\frac{(2^{k}-1)}{(2^{t}-1)}\sum_{x\in\mathbb{F}_{2}^{t}\setminus 0}2^{-|x|/2}
=1+(2k1)(2t1)(2tν2t1)\displaystyle=1+\frac{(2^{k}-1)}{(2^{t}-1)}\left(2^{t}\nu^{2t}-1\right)
1+2kν2t.\displaystyle\leq 1+2^{k}\nu^{2t}.

As a corollary, there exists at least one L(t,k){\cal L}\in L(t,k) such that Z()1+2kν2tZ({\cal L})\leq 1+2^{k}\nu^{2t}. We now fix kk to be the unique positive integer satisfying

42kν2tδ2.4\geq 2^{k}\nu^{2t}\delta\geq 2. (38)

Consider a subspace L(t,k){\cal L}\in L(t,k) chosen uniformly at random. Using Markov’s inequality and Lemma 36 we get

Pr[Z()(1+2kν2t)(1+δ/2)1]\displaystyle\mathrm{Pr}\left[\frac{Z({\cal L})}{(1+2^{k}\nu^{2t})(1+\delta/2)}\geq 1\right] 𝔼(Z())(1+2kν2t)(1+δ/2)\displaystyle\leq\frac{\mathbb{E}(Z({\cal L}))}{(1+2^{k}\nu^{2t})\left(1+\delta/2\right)}
1δ2+δ.\displaystyle\leq 1-\frac{\delta}{2+\delta}.

For a given L(t,k){\cal L}\in L(t,k) we may compute Z()Z({\cal L}) in time O(2k)O(2^{k}). By randomly choosing O(1/δ)O(1/\delta) subspaces {\cal L} we obtain one {\cal L}^{\star} satisfying

Z()(1+2kν2t)(1+δ/2)Z({\cal L}^{\star})\leq(1+2^{k}\nu^{2t})(1+\delta/2) (39)

with constant probability. Plugging Eq. (39) into Eq. (35) we see that

|Ht||2\displaystyle|\langle H^{\otimes t}|{\cal L}^{\star}\rangle|^{2} 1(1+2kν2t)(1+δ/2)\displaystyle\geq\frac{1}{\left(1+2^{-k}\nu^{-2t}\right)(1+\delta/2)}
1(1+δ/2)2\displaystyle\geq\frac{1}{(1+\delta/2)^{2}}
1δ,\displaystyle\geq 1-\delta,

where in the second line we used Eq. (38). The state |ψ=||\psi\rangle=|{\cal L}^{\star}\rangle obtained in this way therefore satisfies Eq. (31) with

χ=2k4ν2tδ1=O(ν2tδ1)=O(2γtδ1).\chi=2^{k}\leq 4\nu^{-2t}\delta^{-1}=O(\nu^{-2t}\delta^{-1})=O(2^{\gamma t}\delta^{-1}). (40)

This algorithm has running time O(ν2tδ2)O(\nu^{-2t}\delta^{-2}), since we must check the condition Eq. (39) for each of the O(δ1)O(\delta^{-1}) randomly sampled elements of L(t,k)L(t,k) (note that the time required to sample each element is O(poly(t))O(poly(t))).

Remark: One may ask whether a stronger bound on χ\chi can be obtained by truncating the expansion of HtH^{\otimes t} in some other basis of stabilizer states. For example, consider the standard 0,10,1-basis of tt qubits. The expansion of HtH^{\otimes t} in this basis is concentrated on basis vectors x𝔽2tx\in\mathbb{F}_{2}^{t} with Hamming weight |x|=(1ν2)t±O(t1/2)|x|=(1-\nu^{2})t\pm O(t^{1/2}). The number of such basis vectors scales as χ2tH2(ν2)20.6t\chi\sim 2^{tH_{2}(\nu^{2})}\approx 2^{0.6t}, where H2(p)H_{2}(p) is the binary Shannon entropy function. Thus replacing the 0~,1~\tilde{0},\tilde{1}-basis by the 0,10,1-basis gives a significantly worse bound on χ\chi.

As noted above, taking δ\delta to be a constant our construction has the best possible scaling χ=O(ν2t)\chi=O(\nu^{-2t}) of any decomposition of the form Eq. (33). In fact, we prove the following lower bound on the stabilizer rank of HtH^{\otimes t}.

Lemma 2.

Consider a state |ψ=a=1χza|ϕa|\psi\rangle=\sum_{a=1}^{\chi}z_{a}|\phi_{a}\rangle, where ϕa𝒮t\phi_{a}\in{\cal S}_{t}. Suppose ψ=1\|\psi\|=1 and |ψ|Ht|f|\langle\psi|H^{\otimes t}\rangle|\geq f. Then χν2tf2z2\chi\geq\nu^{-2t}f^{2}\|z\|^{-2}, where z=(z1,,zχ)χz=(z_{1},\ldots,z_{\chi})\in\mathbb{C}^{\chi}.

Proof.

First, let us show that

Ftmaxϕ𝒮t|ϕ|Ht|=νt.F_{t}\equiv\max_{\phi\in{\cal S}_{t}}|\langle\phi|H^{\otimes t}\rangle|=\nu^{t}. (41)

The lower bound FtνtF_{t}\geq\nu^{t} is obvious since 0t|Ht=νt\langle 0^{\otimes t}|H^{\otimes t}\rangle=\nu^{t}. We shall use induction in tt to show that FtνFt1F_{t}\leq\nu F_{t-1}. Consider some fixed tt and let Ft=|ϕ|Ht|F_{t}=|\langle\phi|H^{\otimes t}\rangle| for some ϕ𝒮t\phi\in{\cal S}_{t}. Suppose we measure the first qubit of ϕ\phi in the 0,10,1 basis. Let PaP_{a} be the probability of getting the outcome a=0,1a=0,1. It is well-known that Pa{0,1,1/2}P_{a}\in\{0,1,1/2\} for any stabilizer state ϕ\phi. Consider three cases.

Case 1: P0=1P_{0}=1. Then |ϕ=|0|ψ|\phi\rangle=|0\rangle\otimes|\psi\rangle for some ψ𝒮t1\psi\in{\cal S}_{t-1} and Ft=ν|ψ|H(t1)|νFt1F_{t}=\nu|\langle\psi|H^{\otimes(t-1)}\rangle|\leq\nu F_{t-1}.

Case 2: P0=0P_{0}=0. Then |ϕ=|1|ψ|\phi\rangle=|1\rangle\otimes|\psi\rangle for some ψ𝒮t1\psi\in{\cal S}_{t-1} and Ft=1ν2|ψ|H(t1)|<νFt1F_{t}=\sqrt{1-\nu^{2}}|\langle\psi|H^{\otimes(t-1)}\rangle|<\nu F_{t-1}.

Case 3: P0=1/2P_{0}=1/2. Then

|ϕ=21/2(|0|ψ0+|1|ψ1)|\phi\rangle=2^{-1/2}\left(|0\rangle\otimes|\psi_{0}\rangle+|1\rangle\otimes|\psi_{1}\rangle\right)

for some ψ0,ψ1𝒮t1\psi_{0},\psi_{1}\in{\cal S}_{t-1}. By triangle inequality,

Ft21/2(ν+1ν2)Ft1=νFt1.F_{t}\leq 2^{-1/2}(\nu+\sqrt{1-\nu^{2}})F_{t-1}=\nu F_{t-1}.

The base of induction F1=νF_{1}=\nu is trivial. This proves Eq. (41). From Eq. (41) one gets

f|ψ|Ht|νta=1χ|za|νtχ1/2z.f\leq|\langle\psi|H^{\otimes t}\rangle|\leq\nu^{t}\sum_{a=1}^{\chi}|z_{a}|\leq\nu^{t}\chi^{1/2}\|z\|.

This is equivalent to the statement of the lemma. ∎

We conjecture that any approximate stabilizer decomposition of HtH^{\otimes t} that achieves a constant approximation error must use at least Ω(ν2t)\Omega(\nu^{-2t}) stabilizer states.

VI Acknowledgments

DG acknowledges funding provided by the Institute for Quantum Information and Matter, an NSF Physics Frontiers Center (NFS Grant PHY-1125565) with support of the Gordon and Betty Moore Foundation (GBMF-12500028). SB thanks Alexei Kitaev for helpful discussions and comments.

Appendix A: Quadratic forms

The remaining sections provide more details on implementation of our algorithms. Appendix A presents some basic facts about quadratic forms over finite fields and describes a subroutine for computing certain exponential sums. The standard form of stabilizer states used in all our algorithms is defined in Appendix B. Then we present algorithms for computing the inner product between stabilizer states (Appendix C), generating a random uniformly distributed stabilizer state (Appendix D), and computing the action of Pauli measurements on stabilizer states (Appendix E). The three algorithms have running time O(n3)O(n^{3}), O(n2)O(n^{2}), and O(n2)O(n^{2}) respectively, where nn is the number of qubits. We provide pseudocode for all algorithms and report timing analysis for a MATLAB implementation. Appendix F describes simulation of the hidden shift algorithm.

Below we consider functions that map binary vectors to integers modulo eight. We define a special class of such functions that are analogous to quadratic forms over the real field. The definition of 8\mathbb{Z}_{8}-valued quadratic forms given below was proposed to us by Kitaev [23]. Analogous definitions and computations using 4\mathbb{Z}_{4}-valued quadratic forms can be found in [24]. For a general theory of quadratic forms over a finite field see Ref. [25]. Throughout the rest of the paper arithmetic operations ±\pm are performed modulo eight (unless stated otherwise), whereas addition of binary vectors modulo two is denoted \oplus. Elements of 𝔽2n\mathbb{F}_{2}^{n} are considered as binary row vectors. A binary inner product between vectors x,y𝔽2nx,y\in\mathbb{F}_{2}^{n} will be denoted (x,y)i=1nxiyi(mod2)(x,y)\equiv\sum_{i=1}^{n}x_{i}y_{i}{\pmod{2}}. A set of binary matrices of size a×ba\times b is denoted 𝔽2a×b\mathbb{F}_{2}^{a\times b}. A transpose of a matrix MM is denoted MTM^{T}.

Recall that a subset 𝒦𝔽2n{\cal K}\subseteq\mathbb{F}_{2}^{n} is a called an affine space of dimension kk iff 𝒦=(𝒦)h{\cal K}={\cal L}({\cal K})\oplus h for some kk-dimensional linear subspace (𝒦)𝔽2n{\cal L}({\cal K})\subseteq\mathbb{F}_{2}^{n} and a shift vector h𝔽2nh\in\mathbb{F}_{2}^{n}. Note that 𝒦{\cal K} uniquely determines (𝒦){\cal L}({\cal K}), namely, (𝒦)={xy:x,y𝒦}{\cal L}({\cal K})=\{x\oplus y\,:\,x,y\in{\cal K}\}. The shift vector hh however is not uniquely defined. Obviously, |𝒦|=|(𝒦)|=2k|{\cal K}|=|{\cal L}({\cal K})|=2^{k}.

Definition 1.

Consider an affine space 𝒦𝔽2n{\cal K}\subseteq\mathbb{F}_{2}^{n}. A function q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8} is called a quadratic form iff there exists a function J:(𝒦)×(𝒦)8J\,:\,{\cal L}({\cal K})\times{\cal L}({\cal K})\to\mathbb{Z}_{8} such that

q(xyz)+q(z)q(xz)q(yz)=J(x,y)q(x\oplus y\oplus z)+q(z)-q(x\oplus z)-q(y\oplus z)=J(x,y) (42)

for all z𝒦z\in{\cal K} and for all x,y(𝒦)x,y\in{\cal L}({\cal K}).

Informally, Eq. (42) demands that a discrete analogue of the second derivative 2qxy\frac{\partial^{2}q}{\partial x\partial y} evaluated at some point z𝒦z\in{\cal K} does not depend on zz, as it is the case for quadratic forms over the real field. The next lemma states properties of the function J(x,y)J(x,y) that follow from Eq. (42).

Lemma 3.

The function J(x,y)J(x,y) defined by Eq. (42) is a symmetric bilinear form that takes values 0,4(mod8)0,4\pmod{8}. Namely, J(x,y)=J(y,x)J(x,y)=J(y,x), J(0,y)=0J(0,y)=0, J(xx′′,y)=J(x,y)+J(x′′,y)J(x^{\prime}\oplus x^{\prime\prime},y)=J(x^{\prime},y)+J(x^{\prime\prime},y), and J(x,y)=0,4(mod8)J(x,y)={0,4\pmod{8}} for all x,x,x′′,y(𝒦)x,x^{\prime},x^{\prime\prime},y\in{\cal L}({\cal K}).

Proof.

Let x=xx′′x=x^{\prime}\oplus x^{\prime\prime}. Substituting xxx\leftarrow x^{\prime} in Eq. (42) gives

J(x,y)=q(xyz)+q(z)q(xz)q(yz).J(x^{\prime},y)=q(x^{\prime}\oplus y\oplus z)+q(z)-q(x^{\prime}\oplus z)-q(y\oplus z).

Substituting xx′′x\leftarrow x^{\prime\prime} and zzxz\leftarrow z\oplus x^{\prime} in Eq. (42) gives

J(x′′,y)=q(xyz)+q(xz)q(xz)q(xyz).J(x^{\prime\prime},y)=q(x\oplus y\oplus z)+q(x^{\prime}\oplus z)-q(x\oplus z)-q(x^{\prime}\oplus y\oplus z).

This shows that J(x,y)=J(x,y)+J(x′′,y)J(x,y)=J(x^{\prime},y)+J(x^{\prime\prime},y). The identities J(0,y)=0J(0,y)=0 and J(x,y)=J(y,x)J(x,y)=J(y,x) follow trivially from Eq. (42). Replacing zz by zxz\oplus x in Eq. (42) yields

J(x,y)=q(yz)+q(xz)q(z)q(xyz).J(x,y)=q(y\oplus z)+q(x\oplus z)-q(z)-q(x\oplus y\oplus z).

Combining this and Eq. (42) one gets 2J(x,y)=02J(x,y)=0, that is, J(x,y)=0(mod4)J(x,y)={0\pmod{4}}. ∎

As a corollary, one gets q(xz)q(z){0,2,4,6}q(x\oplus z)-q(z)\in\{0,2,4,6\} for all z𝒦z\in{\cal K} and for all x(𝒦)x\in{\cal L}({\cal K}). This can be checked by choosing x=yx=y in Eq. (42) and using the fact that J(x,x){0,4}J(x,x)\in\{0,4\}.

Suppose g1,,gk(𝒦)g^{1},\ldots,g^{k}\in{\cal L}({\cal K}) is some fixed basis of (𝒦){\cal L}({\cal K}), h𝒦h\in{\cal K} is some fixed shift vector, and x𝒦x\in{\cal K}. Then

x=hx1g1xkgk,xi{0,1}.x=h\oplus x_{1}g^{1}\oplus\ldots\oplus x_{k}g^{k},\quad x_{i}\in\{0,1\}.

We shall write x(x1,,xk)\vec{x}\equiv(x_{1},\ldots,x_{k}) to avoid confusion between a point x𝒦x\in{\cal K} and its coordinates. Applying Eq. (42) and Lemma 3 one can describe qq in a basis-dependent way as

q(x)=Q+a=1kDaxa+1a<bkJa,bxaxb,q(\vec{x})=Q+\sum_{a=1}^{k}D_{a}x_{a}+\sum_{1\leq a<b\leq k}J_{a,b}x_{a}x_{b}, (43)

where Qq(h)8Q\equiv q(h)\in\mathbb{Z}_{8},

Da=q(gah)q(h){0,2,4,6},D_{a}=q(g^{a}\oplus h)-q(h)\in\{0,2,4,6\}, (44)
Ja,b=Jb,a=J(ga,gb){0,4}.J_{a,b}=J_{b,a}=J(g^{a},g^{b})\in\{0,4\}. (45)

We shall consider JJ as a symmetric k×kk\times k matrix. Although Eq. (43) depends only on off-diagonal matrix elements of JJ, it will be convenient to retain the diagonal of JJ. Combining Eqs. (42,43) one gets

Ja,a=2Da,1ak.J_{a,a}=2D_{a},\quad 1\leq a\leq k. (46)

A connection between quadratic forms and stabilizer states is established by the following lemma.

Lemma 4.

Any nn-qubit stabilizer state can be uniquely written as

|𝒦,q2k/2x𝒦eiπ4q(x)|x,|{\cal K},q\rangle\equiv 2^{-k/2}\sum_{x\in{\cal K}}e^{\frac{i\pi}{4}q(x)}|x\rangle, (47)

where 𝒦𝔽2n{\cal K}\subseteq\mathbb{F}_{2}^{n} is an affine space of dimension 0kn0\leq k\leq n and q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8} is a quadratic form.

Proof.

The claim that any stabilizer state can be written in the form Eq. (47) follows from the explicit characterization of quadratic forms Eqs. (43,44,45) and the canonical form of stabilizer states derived in Refs. [5, 26, 27]. The uniqueness of the decomposition Eq. (47) is obvious. ∎

Next let us describe how the representation of qq transforms under various basis changes. Suppose R𝔽2k×kR\in\mathbb{F}_{2}^{k\times k} is an invertible matrix. Consider a basis change

gab=1kRa,bgb(mod2),g^{a}\leftarrow\sum_{b=1}^{k}R_{a,b}\,g^{b}{\pmod{2}}, (48)

where 1ak1\leq a\leq k. The shift vector hh remains unchanged. Applying Eq. (43) where x\vec{x} is chosen as the aa-th row of RR, one can easily check that the coefficients (Q,D,J)(Q,D,J) transform according to QQQ\leftarrow Q,

Dab=1kRa,bDb+1b<ckJb,cRa,bRa,c,D_{a}\leftarrow\sum_{b=1}^{k}R_{a,b}D_{b}+\sum_{1\leq b<c\leq k}J_{b,c}R_{a,b}R_{a,c}, (49)

and

JRJRT.J\leftarrow RJR^{T}. (50)

The matrix multiplications are performed in the ring 8\mathbb{Z}_{8}. Next consider a basis change that alters the shift vector,

hhy,wherey=a=1kyaga(mod2).h\leftarrow h\oplus y,\quad\mbox{where}\quad y=\sum_{a=1}^{k}y_{a}g^{a}{\pmod{2}}. (51)

Using Eq. (44) one can easily check that the coefficients (Q,D,J)(Q,D,J) transform according to

QQ+a=1kDaya+1a<bkJa,byayb,Q\leftarrow Q+\sum_{a=1}^{k}D_{a}y_{a}+\sum_{1\leq a<b\leq k}J_{a,b}y_{a}y_{b}, (52)
DaDa+b=1kJa,byb,D_{a}\leftarrow D_{a}+\sum_{b=1}^{k}J_{a,b}y_{b}, (53)

and JJJ\leftarrow J.

The above rules determine the representation (Q,D,J)(Q,D,J) of qq in any basis of 𝒦{\cal K}. What is the cost of computing this representation ? Clearly, all updates can be expressed as a constant number of matrix-matrix (matrix-vector) multiplications with 8\mathbb{Z}_{8}-valued matrices of size kk. Thus the updates have cost O(k3)O(k^{3}) in the worst case. We shall often consider basis changes Eq. (48) such that the matrix RR is sparse. Let |R||R| be the total number of non-zeros in RR. Using sparse matrix-matrix multiplication one can perform all updates in Eqs. (49,50) in time O(|R|2)O(|R|^{2}). Indeed, let waw_{a} be the number of non-zeros in the aa-th row of RR. One can update DaD_{a} and Ja,bJ_{a,b} for any fixed a,ba,b in time wa2w_{a}^{2} and wawbw_{a}w_{b} respectively. Thus DD and JJ can be updated in time O((a=1kwa)2)=O(|R|2)O((\sum_{a=1}^{k}w_{a})^{2})=O(|R|^{2}). Since the updates Eq. (53,52) require time O(k2)O(k^{2}) and |R|k|R|\geq k, the overall time is O(|R|2)O(|R|^{2}). We conclude that computing the representation (Q,D,J)(Q,D,J) of qq in the new basis takes time

τupdate=O(min(k3,|R|2)).\tau_{update}=O(\min{(k^{3},|R|^{2})}). (54)

In the rest of this section we show how to compute certain exponential sums associated with quadratic forms, namely,

W(q)x𝔽2keiπ4q(x),W(q)\equiv\sum_{x\in\mathbb{F}_{2}^{k}}e^{i\frac{\pi}{4}q(\vec{x})}, (55)

where q(x)q(\vec{x}) is defined by Eq. (43). Of course, the addition in Eq. (55) is over the complex field. Our algorithm takes as input the data k,Q,D,Jk,Q,D,J describing q(x)q(\vec{x}) and outputs W(q)W(q). The algorithm has running time O(k3)O(k^{3}). It will be used as a subroutine for computing the inner product between two stabilizer states, see Appendix C.

It will be convenient to consider a more general sum

W(𝒦,q)=x𝒦eiπ4q(x),W({\cal K},q)=\sum_{x\in{\cal K}}e^{i\frac{\pi}{4}q(x)}, (56)

where 𝒦=(𝒦)h{\cal K}={\cal L}({\cal K})\oplus h is an affine space and q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8} is a quadratic form on 𝒦{\cal K}. Clearly, Eq. (55) is a special case of Eq. (56). Let us say that g1,,gk(𝒦)g^{1},\ldots,g^{k}\in{\cal L}({\cal K}) is a canonical basis of (𝒦){\cal L}({\cal K}) iff the set of basis vectors can be partitioned into disjoint subsets

[k]=𝒟1𝒟rMS,[k]={\cal D}_{1}\cup\ldots\cup{\cal D}_{r}\cup M\cup S, (57)

such that

|𝒟1|==|𝒟r|=2,|S|1,|{\cal D}_{1}|=\ldots=|{\cal D}_{r}|=2,\quad|S|\leq 1, (58)
Ja,a={0ifaS,4ifaS.J_{a,a}=\left\{\begin{array}[]{rcl}0&\mbox{if}&a\notin S,\\ 4&\mbox{if}&a\in S.\\ \end{array}\right. (59)
aMJa,b=0b[k]S,a\in M\quad\Rightarrow\quad J_{a,b}=0\quad\forall b\in[k]\setminus S, (60)

and 𝒟i={a,b}{\cal D}_{i}=\{a,b\} implies

Ja,b=4andJa,c=Jb,c=0cS{a,b}.J_{a,b}=4\quad\mbox{and}\quad J_{a,c}=J_{b,c}=0\quad\forall c\notin S\cup\{a,b\}. (61)

Some of the subsets in Eq. (57) can be empty. Let us write

𝒟j={a(j),b(j)},j=1,,r.{\cal D}_{j}=\{a(j),b(j)\},\quad j=1,\ldots,r.

Assume that (𝒦){\cal L}({\cal K}) is already equipped with a canonical basis g1,,gkg^{1},\ldots,g^{k} and show how to compute the sum W(𝒦,q)W({\cal K},q). Suppose first S=S=\emptyset. By repeatedly applying Eq. (43) and using Eqs. (58,60,61) one can check that

q(x)=Q+j=1rqj(xa(j),xb(j))+cMDcxc.q(\vec{x})=Q+\sum_{j=1}^{r}q_{j}(x_{a(j)},x_{b(j)})+\sum_{c\in M}D_{c}x_{c}. (62)

where qj:𝔽228q_{j}\,:\,\mathbb{F}_{2}^{2}\to\mathbb{Z}_{8} is defined by

qj(y,z)=4yz+Da(j)y+Db(j)z.q_{j}(y,z)=4yz+D_{a(j)}y+D_{b(j)}z. (63)

Examination of Eqs. (56,62,63) reveals that the sum W(𝒦,q)W({\cal K},q) factorizes into a product of O(k)O(k) terms such that each term can be computed in time O(1)O(1). Specifically,

W(𝒦,q)=eiπ4QcM(1+eiπ4Dc)j=1rΓj,W({\cal K},q)=e^{i\frac{\pi}{4}Q}\cdot\prod_{c\in M}\left(1+e^{i\frac{\pi}{4}D_{c}}\right)\cdot\prod_{j=1}^{r}\Gamma_{j}, (64)

where

Γj=1+eiπ4Da(j)+eiπ4Db(j)eiπ4(Da(j)+Db(j))\Gamma_{j}=1+e^{i\frac{\pi}{4}D_{a(j)}}+e^{i\frac{\pi}{4}D_{b(j)}}-e^{i\frac{\pi}{4}(D_{a(j)}+D_{b(j)})} (65)

Combining Eqs. (64,65) one can compute W(𝒦,q)W({\cal K},q) in time O(k)O(k).

Consider now the remaining case SS\neq\emptyset. Since |S|1|S|\leq 1, we have S={s}S=\{s\} for some s[k]s\in[k]. By repeatedly applying Eq. (43) and using Eqs. (58,60,61) one can check that

q(x)\displaystyle q(\vec{x}) =\displaystyle= Q+Dsxs+j=1rqj(xa(j),xb(j),xs)\displaystyle Q+D_{s}x_{s}+\sum_{j=1}^{r}q_{j}(x_{a(j)},x_{b(j)},x_{s}) (66)
+cM(Dcxc+Jc,sxcxs),\displaystyle+\sum_{c\in M}(D_{c}x_{c}+J_{c,s}x_{c}x_{s}),

where qj:𝔽238q_{j}\,:\,\mathbb{F}_{2}^{3}\to\mathbb{Z}_{8} is defined by

qj(y,z,σ)=4yz+Ja(j),syσ+Jb(j),szσ+Da(j)y+Db(j)z.q_{j}(y,z,\sigma)=4yz+J_{a(j),s}y\sigma+J_{b(j),s}z\sigma+D_{a(j)}y+D_{b(j)}z. (67)

We have W(𝒦,q)=W0+W1W({\cal K},q)=W_{0}+W_{1}, where

Wσx𝒦:xs=σeiπ4q(x),σ=0,1.W_{\sigma}\equiv\sum_{x\in{\cal K}\,:\,x_{s}=\sigma}\;e^{i\frac{\pi}{4}q(\vec{x})},\quad\sigma=0,1. (68)

Examination of Eqs. (66,67) reveals that WσW_{\sigma} factorizes into a product of O(k)O(k) terms such that each term can be computed in time O(1)O(1). Specifically,

Wσ=eiπ4(Q+σDs)cM(1+eiπ4(Dc+σJc,s))j=1rΓj(σ),W_{\sigma}=e^{i\frac{\pi}{4}\left(Q+\sigma D_{s}\right)}\prod_{c\in M}\left(1+e^{i\frac{\pi}{4}(D_{c}+\sigma J_{c,s})}\right)\cdot\prod_{j=1}^{r}\Gamma_{j}(\sigma), (69)

where

Γj(σ)\displaystyle\Gamma_{j}(\sigma) =\displaystyle= 1+exp[iπ4(Ja(j),sσ+Da(j))]\displaystyle 1+\exp{\left[i\frac{\pi}{4}\left(J_{a(j),s}\sigma+D_{a(j)}\right)\right]} (70)
+exp[iπ4(Jb(j),sσ+Db(j))]\displaystyle+\exp{\left[i\frac{\pi}{4}\left(J_{b(j),s}\sigma+D_{b(j)}\right)\right]}
exp[iπ4(Ja(j),sσ+Jb(j),sσ+Da(j)+Db(j))].\displaystyle-\exp{\left[i\frac{\pi}{4}\left(J_{a(j),s}\sigma+J_{b(j),s}\sigma+D_{a(j)}+D_{b(j)}\right)\right]}.

Combining Eqs. (69,70) one can compute W0+W1W_{0}+W_{1} in time O(k)O(k).

To transform an arbitrary basis g1,,gkg^{1},\ldots,g^{k} of (𝒦){\cal L}({\cal K}) into the canonical form we shall use a version of the Gram-Schmidt orthogonalization. It involves at most kk basis changes Eq. (48) with sparse matrices RR such that |R|=O(k)|R|=O(k). Computing the coefficients (D,J)(D,J) in the canonical basis thus takes time O(k|R|2)=O(k3)O(k|R|^{2})=O(k^{3}), see Eq. (54).

Recall that Da{0,2,4,6}D_{a}\in\{0,2,4,6\}. Define a subset

S={a[k]:Da{2,6}}.S=\{a\in[k]\,:\,D_{a}\in\{2,6\}\}.

If SS is non-empty, pick an arbitrary element sSs\in S. Perform a basis change gagagsg^{a}\leftarrow g^{a}\oplus g^{s} for each aS\sa\in S\backslash s. From Eq. (49) one gets DaDa+Ds+Ja,s{0,4}D_{a}\leftarrow D_{a}+D_{s}+J_{a,s}\in\{0,4\} for all aS\sa\in S\backslash s and DaDaD_{a}\leftarrow D_{a} for all aSa\notin S. Set S={s}S=\{s\}. Now we can assume that Da{0,4}D_{a}\in\{0,4\} for all aSa\notin S for some subset SS such that |S|1|S|\leq 1. From Eq. (46) we infer

Ja,a=0for all aS.J_{a,a}=0\quad\mbox{for all $a\notin S$}. (71)

Let us say that a pair of basis vectors (ga,gb)(g^{a},g^{b}) with a,bSa,b\notin S is a dimer if it obeys Eq. (61), that is, Ja,b=4J_{a,b}=4 and Ja,c=Jb,c=0J_{a,c}=J_{b,c}=0 for all cS{a,b}c\notin S\cup\{a,b\}. Note that a basis vector can belong to at most one dimer. Let us say that a basis vector gag^{a} with aSa\notin S is a monomer if it obeys Eq. (60), that is, Ja,b=0J_{a,b}=0 for all b[k]Sb\in[k]\setminus S. Partition the set of basis vectors into four disjoint sets,

[k]=𝒟MSE,[k]={\cal D}\cup M\cup S\cup E, (72)

such that 𝒟{\cal D} is the union of all dimers, MM is the union of all monomers, and EE is the complement of 𝒟MS{\cal D}MS. By definition, a basis has a canonical form iff EE is empty. Initially 𝒟{\cal D}, MM are empty, and EE is the complement of SS. Suppose EE is non-empty. Pick any aEa\in E. If Ja,b=0J_{a,b}=0 for all bEb\in E, move aa from EE to MM. Otherwise Ja,b=4J_{a,b}=4 for some bEb\in E. Let us define a binary matrix 𝑱\boldsymbol{J} corresponding to JJ such that 𝑱a,b=1\boldsymbol{J}_{a,b}=1 if Ja,b=4J_{a,b}=4 and 𝑱a,b=0\boldsymbol{J}_{a,b}=0 otherwise. Perform a basis change

gcgc𝑱a,cgb𝑱b,cgafor all cE{a,b}.g^{c}\leftarrow g^{c}\oplus\boldsymbol{J}_{a,c}g^{b}\oplus\boldsymbol{J}_{b,c}g^{a}\quad\mbox{for all $c\in E\setminus\{a,b\}$}. (73)

Using Eq. (71) one can check that the new basis vectors obey J(gc,ga)=J(gc,gb)=0J(g^{c},g^{a})=J(g^{c},g^{b})=0 for all c𝒟ME{a,b}c\in{\cal D}ME\setminus\{a,b\}. Thus we can move a,ba,b from EE to 𝒟{\cal D} by creating a new dimer 𝒟i={a,b}{\cal D}_{i}=\{a,b\} in Eq. (57). By repeating the above steps at most kk times one makes E=E=\emptyset. Furthermore, the RR matrices corresponding to the basis change Eq. (73) are sparse since any row of RR contains at most three non-zero elements. Thus the original basis is transformed into the canonical form by O(k)O(k) basis changes Eq. (48) with sparse matrices RR such that |R|=O(k)|R|=O(k). This has cost O(k|R|2)=O(k3)O(k|R|^{2})=O(k^{3}). We summarize the algorithm below.

function ExponentialSum(Q,D,JQ,D,J)   S{a[k]:Da{2,6}}S\leftarrow\{a\in[k]\,:\,D_{a}\in\{2,6\}\}   if SS\neq\emptyset then    Pick any aSa\in S    for bS{a}b\in S\setminus\{a\} do      gbgbgag^{b}\leftarrow g^{b}\oplus g^{a}    end for    Update (D,J)(D,J) using Eqs. (49,50)    S{a}S\leftarrow\{a\}   end if   \triangleright Now Ja,a=0J_{a,a}=0 for all aSa\notin S   E[k]SE\leftarrow[k]\setminus S   MM\leftarrow\emptyset   r0r\leftarrow 0   while EE\neq\emptyset do    Pick any aEa\in E    K{bEa:Ja,b=4}K\leftarrow\{b\in E\setminus a\,:\,J_{a,b}=4\}    if K=K=\emptyset then      \triangleright Found a new monomer {a}\{a\}      MMaM\leftarrow M\cup a      EEaE\leftarrow E\setminus a    else      Pick any bKb\in K      for cE{a,b}c\in E\setminus\{a,b\} do       gcgc𝑱a,cgb𝑱b,cgag^{c}\leftarrow g^{c}\oplus\boldsymbol{J}_{a,c}g^{b}\oplus\boldsymbol{J}_{b,c}g^{a}      end for      Update (D,J)(D,J) using Eqs. (49,50)      \triangleright Now {a,b}\{a,b\} form a new dimer      rr+1r\leftarrow r+1, 𝒟r{a,b}{\cal D}_{r}\leftarrow\{a,b\}      EE{a,b}E\leftarrow E\setminus\{a,b\}    end if   end while   if S=S=\emptyset then    Compute W(𝒦,q)W({\cal K},q) from Eq. (64)   else    Compute W0,1W_{0,1} from Eq. (69)    Set W(𝒦,q)=W0+W1W({\cal K},q)=W_{0}+W_{1}   end if end function

Comments: The basis vectors gag^{a} only serve a notational purpose to describe the basis change matrix RR that must be used in the update formulas Eqs. (49,50). There are no actual data representing gag^{a} or operations performed with them. For example, the first for loop corresponds to a matrix R=IbS{a}(eb)TeaR=I\oplus\sum_{b\in S\setminus\{a\}}(e^{b})^{T}e^{a}, where eae^{a} is the binary vector with a single ‘11’ at the aa-th position. As was shown in Ref. [15], the sum W(𝒦,q)W({\cal K},q) can be represented by a triple of integers p0p\geq 0, m8m\in\mathbb{Z}_{8}, and ϵ{0,1}\epsilon\in\{0,1\} such that W(𝒦,q)=ϵ2p/2eiπm/4W({\cal K},q)=\epsilon\cdot 2^{p/2}\cdot e^{i\pi m/4}. Our implementation of the algorithm uses such representation for all intermediate sums to avoid roundoff errors. Timing analysis for a MATLAB implementation is reported in Table 1.

Appendix B: Standard form of stabilizer states

Suppose |𝒦,q𝒮n|{\cal K},q\rangle\in{\cal S}_{n} is a stabilizer state of nn qubits defined in Eq. (47). An affine space 𝒦=(𝒦)h𝔽2n{\cal K}={\cal L}({\cal K})\oplus h\subseteq\mathbb{F}_{2}^{n} of dimension kk will be represented by a tuple

(n,k,h𝔽2n,G,G¯𝔽2n×n),(n,k,h\in\mathbb{F}_{2}^{n},G,\bar{G}\in\mathbb{F}_{2}^{n\times n}),

such that (𝒦){\cal L}({\cal K}) is spanned by the first kk rows of the matrix GG and G¯(G1)T\bar{G}\equiv(G^{-1})^{T}, that is,

GG¯T=I(mod2).G\bar{G}^{T}=I{\pmod{2}}. (74)

We shall write gag^{a} and g¯a\bar{g}^{a} for the aa-th row of GG and G¯\bar{G} respectively. Thus (𝒦)=span(g1,,gk){\cal L}({\cal K})=\mathrm{span}(g^{1},\ldots,g^{k}) and (ga,g¯b)=δa,b(g^{a},\bar{g}^{b})=\delta_{a,b} for 1a,bn1\leq a,b\leq n. We shall refer to gag^{a} and g¯a\bar{g}^{a} as the primal and the dual basis vectors.

A quadratic form q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8} will be specified by a list of coefficients (Q,D,J)(Q,D,J) that describe q(x)q(\vec{x}) in the basis g1,,gkg^{1},\ldots,g^{k} of (𝒦){\cal L}({\cal K}), see Eqs. (43,44,45), with the shift vector hh. Thus, a stabilizer state |𝒦,q|{\cal K},q\rangle of nn qubits is described by the following data:

(n,k,h,G,G¯,Q,D,J),(n,k,h,G,\bar{G},Q,D,J),

where Q8Q\in\mathbb{Z}_{8}, D1,,Dk{0,2,4,6}D_{1},\ldots,D_{k}\in\{0,2,4,6\}, and JJ is a symmetric k×kk\times k such that Ja,b{0,4}J_{a,b}\in\{0,4\} for all a,ba,b. A valid data must satisfy conditions Eq. (74) and Eq. (46).

We shall often use a subroutine that alters a stabilizer state |𝒦,q|{\cal K},q\rangle by shrinking the affine space 𝒦{\cal K} reducing its dimension by one. Namely, consider a vector ξ𝔽2n\xi\in\mathbb{F}_{2}^{n} and α𝔽2\alpha\in\mathbb{F}_{2}. Define

=𝒦{x𝔽2n:(ξ,x)=α}.{\cal M}={\cal K}\cap\{x\in\mathbb{F}_{2}^{n}\,:\,(\xi,x)=\alpha\}. (75)

Clearly, {\cal M} is an affine space which is either empty, or =𝒦{\cal M}={\cal K}, or {\cal M} has dimension k1k-1. Below we describe an algorithm that takes as input a stabilizer state |𝒦,q|{\cal K},q\rangle and computes the standard form of the state |,q|{\cal M},q\rangle (or reports that {\cal M} is empty). Here it is understood that the form qq is restricted onto {\cal M}. The algorithm has runtime O(kn)O(kn). First we note that

=h{y(𝒦):(ξ,y)=β},{\cal M}=h\oplus\{y\in{\cal L}({\cal K})\,:\,(\xi,y)=\beta\},

where β=α(ξ,h)\beta=\alpha\oplus(\xi,h). Let

S={a[k]:(ξ,ga)=1}.S=\{a\in[k]\,:\,(\xi,g^{a})=1\}.

One can compute SS in time O(kn)O(kn). If S=S=\emptyset and β=1\beta=1 then {\cal M} is empty. If S=S=\emptyset and β=0\beta=0 then =𝒦{\cal M}={\cal K}. Otherwise pick any element iSi\in S and remove ii from SS. Change the basis of (𝒦){\cal L}({\cal K}) according to

gagagifor aS.g^{a}\leftarrow g^{a}\oplus g^{i}\quad\mbox{for $a\in S$}.

Change the dual basis according to

g¯ig¯iaSg¯a.\bar{g}^{i}\leftarrow\bar{g}^{i}\oplus\sum_{a\in S}\bar{g}^{a}.

Now (ga,g¯b)=δa,b(g^{a},\bar{g}^{b})=\delta_{a,b} for all a,ba,b. The basis change requires time O(kn)O(kn). Let us also swap the ii-th and the kk-th basis vectors. Updating the coefficients (D,J)(D,J) using Eqs. (49,50) takes time O(k2)=O(kn)O(k^{2})=O(kn). Now basis vectors g1,,gk1g^{1},\ldots,g^{k-1} are orthogonal to ξ\xi and (ξ,gk)=1(\xi,g^{k})=1. Thus

=hspan(g1,,gk1)h(),{\cal M}=h^{\prime}\oplus\mathrm{span}(g^{1},\ldots,g^{k-1})\equiv h^{\prime}\oplus{\cal L}({\cal M}),

where h=hβgkh^{\prime}=h\oplus\beta g^{k} is the new shift vector. Update the coefficients (Q,D)(Q,D) using Eqs. (52,53), where y=βgky=\beta g^{k}. This takes time O(k)O(k). Now restricting the form qq onto {\cal M} is equivalent to removing the kk-th row/column from the matrix JJ and removing the kk-th element from DD. We obtained the standard form of the state |,q|{\cal M},q\rangle. The entire algorithm is summarized below.

function Shrink(|𝒦,q,ξ,α|{\cal K},q\rangle,\xi,\alpha)   S{a[k]:(ξ,ga)=1}S\leftarrow\{a\in[k]\,:\,(\xi,g^{a})=1\}   βα(ξ,h)\beta\leftarrow\alpha\oplus(\xi,h)   if S=S=\emptyset and β=1\beta=1 then    return EMPTY   end if   if S=S=\emptyset and β=0\beta=0 then    return SAME   end if   Pick any iSi\in S   SS{i}S\leftarrow S\setminus\{i\}   for aSa\in S do     gagagig^{a}\leftarrow g^{a}\oplus g^{i}    Update (D,J)(D,J) using Eqs. (49,50)   end for   g¯ig¯iaSg¯a\bar{g}^{i}\leftarrow\bar{g}^{i}\oplus\sum_{a\in S}\bar{g}^{a}   Swap gig^{i} and gkg^{k}. Swap g¯i\bar{g}^{i} and g¯k\bar{g}^{k}.   Update (D,J)(D,J) using Eqs. (49,50)   hhβgkh\leftarrow h\oplus\beta g^{k}   Update (Q,D)(Q,D) using Eqs. (52,53)   Remove the kk-th row/column from JJ   Remove the kk-th element from DD   kk1k\leftarrow k-1   return SUCCESS end function

To simplify notations, here we assume that the function SHRINK modifies the data describing the input state. The function reports whether the new affine space 𝒦{\cal K} is empty or the same as the initial space. It reports SUCESS whenever the dimension of the affine space has been reduced by one. The function has runtime O(kn)O(kn). Sometimes we shall use a “lazy” version of the function that does not update the coefficients of qq. We shall use the notation SHRINK for such lazy version.

Appendix C: The inner product

Consider a pair of nn-qubit stabilizer states

|ϕα=|𝒦α,qα,α=1,2|\phi_{\alpha}\rangle=|{\cal K}_{\alpha},q_{\alpha}\rangle,\quad\alpha=1,2

with the standard forms (n,kα,hα,Gα,G¯α,Qα,Dα,Jα)(n,k_{\alpha},h_{\alpha},G_{\alpha},\bar{G}_{\alpha},Q_{\alpha},D_{\alpha},J_{\alpha}). Below we describe an algorithm that computes the inner product

ϕ2|ϕ1=2(k1+k2)/2x𝒦1𝒦2eiπ4(q1(x)q2(x)).\langle\phi_{2}|\phi_{1}\rangle=2^{-(k_{1}+k_{2})/2}\sum_{x\in{\cal K}_{1}\cap{\cal K}_{2}}e^{i\frac{\pi}{4}(q_{1}(x)-q_{2}(x))}. (76)

in time O(n3)O(n^{3}). First we note that x𝒦2x\in{\cal K}_{2} iff

xh2(𝒦2)=span(g21,,g2k2).x\oplus h_{2}\in{\cal L}({\cal K}_{2})=\mathrm{span}(g_{2}^{1},\ldots,g_{2}^{k_{2}}).

Thus x𝒦2x\in{\cal K}_{2} iff xh2x\oplus h_{2} is orthogonal to all dual basis vectors g¯2a\bar{g}_{2}^{a} with k2<ank_{2}<a\leq n. Here and below gαbg_{\alpha}^{b} and g¯αb\bar{g}_{\alpha}^{b} denote the bb-th row of GαG_{\alpha} and G¯α\bar{G}_{\alpha} respectively. Thus

𝒦𝒦1𝒦2=b=k2+1n{x𝒦1:(g¯2b,x)=(h2,g¯2b)}.{\cal K}\equiv{\cal K}_{1}\cap{\cal K}_{2}=\bigcap_{b=k_{2}+1}^{n}\{x\in{\cal K}_{1}\,:\,(\bar{g}_{2}^{b},x)=(h_{2},\bar{g}_{2}^{b})\}.

One can compute the standard form of |𝒦,q1|{\cal K},q_{1}\rangle by nk2n-k_{2} calls to the function SHRINK defined in Appendix B with ξ=g¯2b\xi=\bar{g}_{2}^{b} and α=(h2,g¯2b)\alpha=(h_{2},\bar{g}_{2}^{b}) for b=k2+1,,nb=k_{2}+1,\ldots,n. This takes time

τ1=O((nk2)k1n)\tau_{1}=O((n-k_{2})k_{1}n)

since we have to call SHRINK nk2n-k_{2} times.

Let 𝒦=(n,k,h,G,G¯){\cal K}=(n,k,h,G,\bar{G}) be the standard form of 𝒦{\cal K} and (Q1,D1,J1)(Q_{1},D_{1},J_{1}) be the coefficients of q1q_{1} restricted onto 𝒦{\cal K} in the basis g1,,gkg^{1},\ldots,g^{k} (as usual, gag^{a} is the aa-th row of GG).

The next step so the compute coefficients (Q2,D2,J2)(Q_{2},D_{2},J_{2}) of the form q2q_{2} restricted to 𝒦{\cal K} in the basis g1,,gkg^{1},\ldots,g^{k} with the shift vector hh. We note that

h=h2a=1k2yag2a,whereya=(hh2,g¯2a).h=h_{2}\oplus\sum_{a=1}^{k_{2}}y_{a}g_{2}^{a},\quad\mbox{where}\quad y_{a}=(h\oplus h_{2},\bar{g}_{2}^{a}).

One can compute y1,,yk2y_{1},\ldots,y_{k_{2}} in time O(k2n)O(k_{2}n) and then compute the updated coefficients (Q2,D2)(Q_{2},D_{2}) from Eqs. (52,53). This takes time O(k22)O(k_{2}^{2}). A simple algebra shows that (𝒦)=(𝒦1)(𝒦2){\cal L}({\cal K})={\cal L}({\cal K}_{1})\cap{\cal L}({\cal K}_{2}), that is, ga(𝒦2)g^{a}\in{\cal L}({\cal K}_{2}) for all a=1,,ka=1,\ldots,k. Define a matrix RR of size k×k2k\times k_{2} such that

ga=b=1k2Ra,bg2b(mod2),1ak.g^{a}=\sum_{b=1}^{k_{2}}R_{a,b}g_{2}^{b}{\pmod{2}},\quad 1\leq a\leq k.

Using the dual basis of 𝒦2{\cal K}_{2} one gets Ra,b=(ga,g¯2b)R_{a,b}=(g^{a},\bar{g}_{2}^{b}). One can compute the entire matrix RR in time O(kk2n)O(kk_{2}n). Then the coefficients (D2,J2)(D_{2},J_{2}) in the basis g1,,gkg^{1},\ldots,g^{k} can be computed from Eqs. (49,50) which takes time O(kk22)O(kk_{2}^{2}), see Eq. (54). (Here we used a slightly stronger version of Eq. (54) taking into account that RR is a rectangular matrix.) The runtime up to this point is

τ2=τ1+O(kk2n).\tau_{2}=\tau_{1}+O(kk_{2}n).

Now the restrictions of both forms q1,q2q_{1},q_{2} onto 𝒦{\cal K} are defined in the same basis g1,,gkg^{1},\ldots,g^{k} and the same shift vector hh. Thus qq1q2q\equiv q_{1}-q_{2} has coefficients (Q,D,J)(Q,D,J), where Q=Q1Q2Q=Q_{1}-Q_{2}, D=D1D2D=D_{1}-D_{2}, and J=J1J2J=J_{1}-J_{2}. We get

ϕ2|ϕ1=2(k1+k2)/2W(Q,D,J),\langle\phi_{2}|\phi_{1}\rangle=2^{-(k_{1}+k_{2})/2}\cdot W(Q,D,J),

where W(Q,D,J)W(Q,D,J) is the exponential sum Eq. (55) that can be computed in time O(k3)O(k^{3}), see Appendix A. The overall running time is thus

τ=τ2+O(k3)=O((nk2)k1n+kk2n+k3)=O(n3).\tau=\tau_{2}+O(k^{3})=O((n-k_{2})k_{1}n+kk_{2}n+k^{3})=O(n^{3}).

We summarize the entire inner product algorithm below.

function InnerProduct((|𝒦1,q1,|𝒦2,q2(|{\cal K}_{1},q_{1}\rangle,|{\cal K}_{2},q_{2}\rangle)   𝒦𝒦1{\cal K}\leftarrow{\cal K}_{1}   for b=k2+1b=k_{2}+1 to nn do    α(h2,g¯2b)\alpha\leftarrow(h_{2},\bar{g}_{2}^{b})    ϵ\epsilon\leftarrowSHRINK(|𝒦,q1,g¯2b,α)(|{\cal K},q_{1}\rangle,\bar{g}_{2}^{b},\alpha)    if ϵ=\epsilon=EMPTY then      return 00    end if   end for   \triangleright Now 𝒦=𝒦1𝒦2=(n,k,h,G,G¯){\cal K}={\cal K}_{1}\cap{\cal K}_{2}=(n,k,h,G,\bar{G})   for a=1a=1 to k2k_{2} do    ya(hh2,g¯2a)y_{a}\leftarrow(h\oplus h_{2},\bar{g}_{2}^{a})    for b=1b=1 to kk do      Rb,a(gb,g¯2a)R_{b,a}\leftarrow(g^{b},\bar{g}_{2}^{a})    end for   end for   h2h2a=1k2yag2a=hh_{2}\leftarrow h_{2}\oplus\sum_{a=1}^{k_{2}}y_{a}g_{2}^{a}=h   Update (Q2,D2)(Q_{2},D_{2}) using Eqs. (52,53) with yy   Update (D2,J2)(D_{2},J_{2}) using Eqs. (49,50) with RR   \triangleright Now q1q_{1}, q2q_{2} are defined in the same basis   QQ1Q2Q\leftarrow Q_{1}-Q_{2}   DD1D2D\leftarrow D_{1}-D_{2}   JJ1J2J\leftarrow J_{1}-J_{2}   return 2(k1+k2)/22^{-(k_{1}+k_{2})/2}\cdotExponentialSum(Q,D,J)(Q,D,J) end function

Comments: As before, we assume that the output is converted to a triple of integers (ϵ,p,m)(\epsilon,p,m) such that ϕ2|ϕ1=ϵ2p/2eiπm/4\langle\phi_{2}|\phi_{1}\rangle=\epsilon\cdot 2^{p/2}\cdot e^{i\pi m/4}. If both k1k_{1} and k2k_{2} are small, one can compute the intersection 𝒦1𝒦2{\cal K}_{1}\cap{\cal K}_{2} directly by solving a linear system

a=1k1xag1ab=1k2ybg2b=h1h2\sum_{a=1}^{k_{1}}x_{a}g_{1}^{a}\oplus\sum_{b=1}^{k_{2}}y_{b}g_{2}^{b}=h_{1}\oplus h_{2}

with k1+k2k_{1}+k_{2} variables and nn equations. This provides a shift vector and a basis for 𝒦{\cal K} in time O(n(k1+k2)2)O(n(k_{1}+k_{2})^{2}). Then one can compute the updated coefficients of q1q_{1} and q2q_{2} in the new basis in time O(k(k12+k22))O(k(k_{1}^{2}+k_{2}^{2})). Thus the overall running time is

τ=O(k12n+k22n+k3)\tau=O(k_{1}^{2}n+k_{2}^{2}n+k^{3}) (77)

which is linear in nn provided that both k1,k2=O(1)k_{1},k_{2}=O(1). We note however that the vast majority of stabilizer states have kαnk_{\alpha}\approx n, see Appendix D, so the above method provides no speedup in the generic case.

The timing analysis of the function InnerProduct reported in Table 1 was performed for inner products x~|ϕ\langle\tilde{x}|\phi\rangle, where ϕ𝒮n\phi\in{\cal S}_{n} is drawn from the uniform distribution (as described in Appendix D), x𝔽2nx\in\mathbb{F}_{2}^{n} is a random uniformly distributed string, and |x~|x~1x~2x~n|\tilde{x}\rangle\equiv|\tilde{x}_{1}\otimes\tilde{x}_{2}\otimes\cdots\otimes\tilde{x}_{n}\rangle, where |0~=|0|\tilde{0}\rangle=|0\rangle and |1~=H|0|\tilde{1}\rangle=H|0\rangle. This choice is justified since our simulation algorithm only requires inner products of the above form.

Appendix D: Random stabilizer states

Let us now describe an algorithm that generates a random uniformly distributed stabilizer state |𝒦,q𝒮n|{\cal K},q\rangle\in{\cal S}_{n}. The algorithm has average-case runtime O(n2)O(n^{2}) and the worst-case runtime O(n3)O(n^{3}).

For each 0kn0\leq k\leq n define a subset of stabilizer states

𝒮nk={|𝒦,q𝒮n:dim(𝒦)=k}.{\cal S}_{n}^{k}=\{|{\cal K},q\rangle\in{\cal S}_{n}\,:\,\dim{({\cal K})}=k\}.

For example, 𝒮n0{\cal S}_{n}^{0} includes all basis vectors, whereas 𝒮nn{\cal S}_{n}^{n} includes stabilizer states supported on all basis vectors. Our algorithm first picks a random integer d=0,1,,nd=0,1,\ldots,n drawn from a distribution

P(d)=|𝒮nnd|m=0n|𝒮nm|P(d)=\frac{|{\cal S}_{n}^{n-d}|}{\sum_{m=0}^{n}|{\cal S}_{n}^{m}|} (78)

and generates a random subspace 𝒦𝔽2n{\cal K}\subseteq\mathbb{F}_{2}^{n} of dimension k=ndk=n-d. To compute P(d)P(d) we need the following fact.

Lemma 5.
|𝒮nnd|=82n+12[n(n+1)d(d+1)]a=1d12dna12a.|{\cal S}_{n}^{n-d}|=8\cdot 2^{n+\frac{1}{2}\left[n(n+1)-d(d+1)\right]}\cdot\prod_{a=1}^{d}\frac{1-2^{d-n-a}}{1-2^{-a}}. (79)

for any d=1,,nd=1,\ldots,n and |𝒮nn|=82n+12n(n+1)|{\cal S}_{n}^{n}|=8\cdot 2^{n+\frac{1}{2}n(n+1)}.

Proof.

Let kndk\equiv n-d. The number of kk-dimensional linear subspaces 𝔽2n{\cal L}\subseteq\mathbb{F}_{2}^{n} is known to be

Γnk=Γnd=m=0d12n2m2d2m\Gamma_{n}^{k}=\Gamma_{n}^{d}=\prod_{m=0}^{d-1}\frac{2^{n}-2^{m}}{2^{d}-2^{m}}

For a given {\cal L} there are 2nk2^{n-k} affine spaces 𝒦{\cal K} such that 𝒦=h{\cal K}={\cal L}\oplus h for some shift vector hh. Finally, for a given affine space 𝒦{\cal K} there are

Λnk=822k2k(k1)/2\Lambda_{n}^{k}=8\cdot 2^{2k}\cdot 2^{k(k-1)/2}

quadratic forms q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8}. Here the three factors represent the number of choices for the coefficients (Q,D,J)(Q,D,J) in Eqs. (43,44,45) respectively (recall that the diagonal of JJ is determined by DD, see Eq. (46)). It follows that |𝒮nk|=2nkΓnkΛnk|{\cal S}_{n}^{k}|=2^{n-k}\cdot\Gamma_{n}^{k}\cdot\Lambda_{n}^{k}, which gives Eq. (79). ∎

One can rewrite Eq. (78) as

P(d)=η(d)m=0nη(m),P(d)=\frac{\eta(d)}{\sum_{m=0}^{n}\eta(m)}, (80)

where η(0)=1\eta(0)=1 and

η(d)=2d(d+1)/2a=1d12dna12a\eta(d)=2^{-d(d+1)/2}\cdot\prod_{a=1}^{d}\frac{1-2^{d-n-a}}{1-2^{-a}}

for d=1,,nd=1,\ldots,n. One can compute a lookup table for the function η(d)\eta(d) offline since it depends only on nn. Clearly, d=O(1)d=O(1) with high probability. Thus, the average-case online complexity of sampling dd from the distribution P(d)P(d) is O(1)O(1).

We start by choosing the zero shift vector such that 𝒦{\cal K} is a random linear space of dimension kk. We shall generate 𝒦{\cal K} by repeatedly picking a random matrix X𝔽2d×nX\in\mathbb{F}_{2}^{d\times n} until XX has rank dd and then choosing 𝒦=ker(X){\cal K}=\ker{(X)}. It is well-known that XX has rank dd with probability

pn,d=a=0d1(12n+a)max{1/4,12n+d}.p_{n,d}=\prod_{a=0}^{d-1}(1-2^{-n+a})\geq\max{\{1/4,1-2^{-n+d}\}}.

Note that pn,dp_{n,d} is exponentially close to 11 whenever d=O(1)d=O(1). Thus XX has full rank after O(1)O(1) attempts with high probability. Furthermore, one can compute the rank of XX in time O(nd2)O(nd^{2}) using the Gaussian elimination by bringing XX into the row echelon form. It is also well-known that conditioned on XX having full rank, the subspace ker(X)\ker{(X)} is distributed uniformly on the set of all subspaces of 𝔽2n\mathbb{F}_{2}^{n} of dimension ndn-d. Thus we can choose 𝒦=ker(X){\cal K}=\ker{(X)}.

The next step is computing n×nn\times n matrices GG and G¯\bar{G} such that 𝒦{\cal K} is spanned by the first kk rows of GG and GG¯T=IG\bar{G}^{T}=I. Let us first set 𝒦=𝔽2n{\cal K}=\mathbb{F}_{2}^{n} and G=G¯=IG=\bar{G}=I. Choose a zero quadratic form q(x)=0q(x)=0 for all x𝒦x\in{\cal K}. Let ξa\xi^{a} be the aa-th row of the matrix XX. One can make 𝒦{\cal K} orthogonal to ξ1,,ξd\xi^{1},\ldots,\xi^{d} by making dd calls to the function SHRINK(|𝒦,q,ξa,0){}^{*}(|{\cal K},q\rangle,\xi^{a},0) defined in Appendix B. (Recall that SHRINK does not update the coefficients of qq.) Finally we shift 𝒦{\cal K} by a random uniformly distributed vector h𝔽2nh\in\mathbb{F}_{2}^{n}. At this point 𝒦{\cal K} is a random affine space represented in the standard form. It remains to choose random coefficients of the quadratic form q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8} in the basis g1,,gkg^{1},\ldots,g^{k}. Since qq must be distributed uniformly on the set of all quadratic forms q:𝒦8q\,:\,{\cal K}\to\mathbb{Z}_{8}, we must choose Q8Q\in\mathbb{Z}_{8}, Da{0,2,4,6}D_{a}\in\{0,2,4,6\}, and Ja,b{0,4}J_{a,b}\in\{0,4\} for a<ba<b as random uniform elements of the respective sets. Then the entire matrix JJ is determined by Jb,a=Ja,bJ_{b,a}=J_{a,b} and Ja,a=2Da,aJ_{a,a}=2D_{a,a}, see Eq. (46). The entire algorithm is summarized below.

function RandomStabilizerState(nn)   Compute P(0),,P(n)P(0),\ldots,P(n) from Eq. (80)   Sample d{0,1,,n}d\in\{0,1,\ldots,n\} from P(d)P(d)   kndk\leftarrow n-d   repeat    Pick random X𝔽2d×nX\in\mathbb{F}_{2}^{d\times n}   until rank(X)=d\mathrm{rank}{(X)}=d   GIG\leftarrow I, G¯I\bar{G}\leftarrow I, h0kh\leftarrow 0^{k}   𝒦(n,k,h,G,G¯){\cal K}\leftarrow(n,k,h,G,\bar{G})   \triangleright Now 𝒦=𝔽2n{\cal K}=\mathbb{F}_{2}^{n} is full binary space   qq\leftarrow all-zeros function on 𝒦{\cal K}   for a=1a=1 to dd do    ξ\xi\leftarrow aa-th row of XX    SHRINK(|𝒦,q,ξ,0){}^{*}(|{\cal K},q\rangle,\xi,0)   end for   \triangleright Now 𝒦=ker(X){\cal K}=\ker{(X)}   \triangleright 𝒦{\cal K} has the standard form   Pick random h𝔽2nh\in\mathbb{F}_{2}^{n}   Pick random Q8Q\in\mathbb{Z}_{8}   Pick random Da{0,2,4,6}D_{a}\in\{0,2,4,6\}   Pick random Ja,b=Jb,a{0,4}J_{a,b}=J_{b,a}\in\{0,4\} for aba\neq b   Set Ja,a=2Da(mod8)J_{a,a}=2D_{a}{\pmod{8}}   return (n,k,h,G,G¯,Q,D,J)(n,k,h,G,\bar{G},Q,D,J) end function

Each call to SHRINK takes time O(n2)O(n^{2}), see Appendix B, whereas each computation of rank(X)\mathrm{rank}(X) takes time O(dn2)O(dn^{2}). Thus the entire algorithm takes time O(dn2)O(dn^{2}). Since d=O(1)d=O(1) with high probability, see above, the average runtime is O(n2)O(n^{2}), whereas the worst-case runtime is O(n3)O(n^{3}). Timing analysis for a MATLAB implementation is reported in Table 1.

Appendix E: Pauli measurements

Suppose |𝒦,q𝒮n|{\cal K},q\rangle\in{\cal S}_{n} is a stabilizer state of nn qubits represented in the standard form and P𝒫nP\in{\cal P}_{n} is a Pauli operator. Define an operator

P+12(I+P).P_{+}\equiv\frac{1}{2}(I+P).

It is well-known that P+P_{+} maps stabilizer states to (unnormalized) stabilizer states. Note that P+P_{+} is a projector if PP is self-adjoint and 2P+\sqrt{2}P_{+} is a unitary Clifford operator if P=PP^{\dagger}=-P. Below we describe an algorithm that computes the normalization and the standard form of the state P+|𝒦,qP_{+}|{\cal K},q\rangle. The algorithm has runtime O(n2)O(n^{2}). We shall be mostly interested in the case when P+P_{+} is a projector (although our algorithm applies to the general case). Note that a projector onto the codespace of any stabilizer code with a stabilizer group 𝒢𝒫n{\cal G}\subseteq{\cal P}_{n} can be written as a product of at most nn projectors P+P_{+} associated with some set of generators of 𝒢{\cal G}. Thus a projected state Π𝒢|𝒦,q\Pi_{\cal G}|{\cal K},q\rangle can be computed in time O(n3)O(n^{3}) using the above algorithm.

Let 𝒦=(n,k,h,G,G¯){\cal K}=(n,k,h,G,\bar{G}) be the standard form of 𝒦{\cal K} and

P=imZ(ζ)X(ξ),m4,ξ,ζ𝔽2n.P=i^{m}Z(\zeta)X(\xi),\quad m\in\mathbb{Z}_{4},\quad\xi,\zeta\in\mathbb{F}_{2}^{n}. (81)

We shall consider two cases depending on whether or not ξ(𝒦)\xi\in{\cal L}({\cal K}). This inclusion can be checked in time O(kn)O(kn) by computing inner products ξa=(ξ,g¯a)\xi_{a}=(\xi,\bar{g}^{a}) with a=1,,ka=1,\ldots,k. Namely, ξ(𝒦)\xi\in{\cal L}({\cal K}) iff ξ=a=1kξaga(mod2)\xi=\sum_{a=1}^{k}\xi_{a}g^{a}{\pmod{2}}.

Case 1: ξ(𝒦)\xi\in{\cal L}({\cal K}). Define a function

χ(x)=q(xξ)q(x).\chi(x)=q(x\oplus\xi)-q(x). (82)

By definition of a quadratic form one has

χ(hy)=χ(h)+J(ξ,y)for all y(𝒦).\chi(h\oplus y)=\chi(h)+J(\xi,y)\quad\mbox{for all $y\in{\cal L}({\cal K})$}. (83)

The state P+|𝒦,qP_{+}|{\cal K},q\rangle can be written as

2k/21x𝒦eiπ4q(x)(1+im(1)(ζ,x)eiπ4χ(x))|x.2^{-k/2-1}\sum_{x\in{\cal K}}e^{i\frac{\pi}{4}q(x)}\left(1+i^{m}(-1)^{(\zeta,x)}e^{i\frac{\pi}{4}\chi(x)}\right)|x\rangle. (84)

Perform a change of variable x=hyx=h\oplus y with y(𝒦)y\in{\cal L}({\cal K}). Using Eq. (83) one can rewrite the above state as

2k/21y(𝒦)eiπ4q(hy)(1+eiπ4(ω+λ(y)))|hy,2^{-k/2-1}\sum_{y\in{\cal L}({\cal K})}e^{i\frac{\pi}{4}q(h\oplus y)}\left(1+e^{i\frac{\pi}{4}(\omega+\lambda(y))}\right)|h\oplus y\rangle, (85)

with

ω=2m+4(ζ,h)+q(hξ)q(h){0,2,4,6}\omega=2m+4(\zeta,h)+q(h\oplus\xi)-q(h)\in\{0,2,4,6\} (86)

and

λ(y)=4(ζ,y)+J(ξ,y){0,4}.\lambda(y)=4(\zeta,y)+J(\xi,y)\in\{0,4\}. (87)

Let us first compute ω\omega. We have

ξ=a=1kξaga(mod2),ξa=(g¯a,ξ).\xi=\sum_{a=1}^{k}\xi_{a}g^{a}{\pmod{2}},\quad\xi_{a}=(\bar{g}^{a},\xi). (88)

The decomposition Eq. (88) can be computed in time O(kn)O(kn). Once the coefficients ξa\xi_{a} are known, one can compute ω\omega from

ω=2m+4(ζ,h)+a=1kDaξa+1a<bkJa,bξaξb.\omega=2m+4(\zeta,h)+\sum_{a=1}^{k}D_{a}\xi_{a}+\sum_{1\leq a<b\leq k}J_{a,b}\xi_{a}\xi_{b}. (89)

This takes time O(kn)O(kn).

Suppose first that ω{0,4}\omega\in\{0,4\}. Then eiπ4ω=±1e^{i\frac{\pi}{4}\omega}=\pm 1 and thus

1+eiπ4(ω+λ(y))={2ifλ(y)+ω=0(mod8)0ifλ(y)+ω=4(mod8).1+e^{i\frac{\pi}{4}(\omega+\lambda(y))}=\left\{\begin{array}[]{rcl}2&\mbox{if}&\lambda(y)+\omega=0{\pmod{8}}\\ 0&\mbox{if}&\lambda(y)+\omega=4{\pmod{8}}.\\ \end{array}\right.

We get

P+|𝒦,q=2k/2xeiπ4q(x)|x.P_{+}|{\cal K},q\rangle=2^{-k/2}\sum_{x\in{\cal M}}e^{i\frac{\pi}{4}q(x)}|x\rangle. (90)

where

=𝒦{x𝔽2n:λ(hx)=ω}.{\cal M}={\cal K}\cap\{x\in\mathbb{F}_{2}^{n}\,:\,\lambda(h\oplus x)=\omega\}. (91)

Let us choose a vector γ𝔽2n\gamma\in\mathbb{F}_{2}^{n} such that λ(y)=4(γ,y)\lambda(y)=4(\gamma,y) for all y(𝒦)y\in{\cal L}({\cal K}). We shall look for

γ=b=1kηbg¯b(mod2),ηb{0,1}.\gamma=\sum_{b=1}^{k}\eta_{b}\bar{g}^{b}{\pmod{2}},\quad\eta_{b}\in\{0,1\}. (92)

Choosing y=gay=g^{a} and using (ga,g¯b)=δa,b(g^{a},\bar{g}^{b})=\delta_{a,b} one gets

4ηa=λ(ga)=4(ζ,ga)+J(ξ,ga),1ak.4\eta_{a}=\lambda(g^{a})=4(\zeta,g^{a})+J(\xi,g^{a}),\quad 1\leq a\leq k. (93)

To compute (ζ,ga)(\zeta,g^{a}) and J(ξ,ga)J(\xi,g^{a}) consider expansions Eq. (88) and

ζ=a=1nζag¯a(mod2),ζa=(ga,ζ).\zeta=\sum_{a=1}^{n}\zeta_{a}\bar{g}^{a}{\pmod{2}},\quad\zeta_{a}=(g^{a},\zeta). (94)

One can compute all the coefficients ζ1,,ζk\zeta_{1},\ldots,\zeta_{k} in time O(kn)O(kn). The fact that J(x,y)J(x,y) is a bilinear form implies

4ηa=4ζa+b=1kJa,bξb,1ak.4\eta_{a}=4\zeta_{a}+\sum_{b=1}^{k}J_{a,b}\xi_{b},\quad 1\leq a\leq k. (95)

Thus η1,,ηk\eta_{1},\ldots,\eta_{k} can be computed in time O(kn)O(kn). Let ω=4ω\omega=4\omega^{\prime} with ω{0,1}\omega^{\prime}\in\{0,1\}. We arrived at

=𝒦{x𝔽2n:(γ,x)=α},αω(γ,h).{\cal M}={\cal K}\cap\{x\in\mathbb{F}_{2}^{n}\,:\,(\gamma,x)=\alpha\},\quad\alpha\equiv\omega^{\prime}\oplus(\gamma,h).

The standard form of the state defined in Eq. (90) can be computed by calling the function SHRINK(|𝒦,q,γ,α)(|{\cal K},q\rangle,\gamma,\alpha), see Appendix B, which takes time O(kn)O(kn).

Next suppose that ω{2,6}\omega\in\{2,6\}. Then eiπ4ω=±ie^{i\frac{\pi}{4}\omega}=\pm i and thus

1+eiπ4(ω+λ(y))={2eiπ4ifλ(y)+ω=2(mod8)2eiπ4ifλ(y)+ω=6(mod8)1+e^{i\frac{\pi}{4}(\omega+\lambda(y))}=\left\{\begin{array}[]{rcl}\sqrt{2}e^{i\frac{\pi}{4}}&\mbox{if}&\lambda(y)+\omega=2{\pmod{8}}\\ \sqrt{2}e^{-i\frac{\pi}{4}}&\mbox{if}&\lambda(y)+\omega=6{\pmod{8}}\\ \end{array}\right.

We shall choose a quadratic form λ:𝒦8\lambda^{\prime}\,:\,{\cal K}\to\mathbb{Z}_{8} such that

λ(hy)={0ifλ(y)=0,2ifλ(y)=4.\lambda^{\prime}(h\oplus y)=\left\{\begin{array}[]{rcl}0&\mbox{if}&\lambda(y)=0,\\ 2&\mbox{if}&\lambda(y)=4.\\ \end{array}\right. (96)

Define

σ={1ifω=2,1ifω=6.\sigma=\left\{\begin{array}[]{rcl}1&\mbox{if}&\omega=2,\\ -1&\mbox{if}&\omega=6.\\ \end{array}\right. (97)

Then the state in Eq. (85) can be written as

P+|𝒦,q=2(k+1)/2x𝒦eiπ4q(x)|x=21/2|𝒦,qP_{+}|{\cal K},q\rangle=2^{-(k+1)/2}\sum_{x\in{\cal K}}e^{i\frac{\pi}{4}q^{\prime}(x)}|x\rangle=2^{-1/2}|{\cal K},q^{\prime}\rangle (98)

with a quadratic form

q(x)=σ+q(x)σλ(x).q^{\prime}(x)=\sigma+q(x)-\sigma\lambda^{\prime}(x). (99)

To get the standard form of |𝒦,q|{\cal K},q^{\prime}\rangle we need to choose λ(x)\lambda^{\prime}(x) satisfying Eq. (96) and compute the coefficients of λ(x)\lambda^{\prime}(x) in the basis g1,,gkg^{1},\ldots,g^{k} of (𝒦){\cal L}({\cal K}). First, let us compute the basis-dependent representation of λ(y)\lambda(y). Suppose y=a=1kyaga(mod2)y=\sum_{a=1}^{k}y_{a}g^{a}{\pmod{2}} and let y=(y1,,yk)\vec{y}=(y_{1},\ldots,y_{k}). Substituting Eqs. (88,94) into Eq. (87) one gets

λ(y)=4a=1kηaya,\lambda(\vec{y})=4\sum_{a=1}^{k}\eta_{a}y_{a},

where ηa{0,1}\eta_{a}\in\{0,1\} are defined by Eq. (95). For any z1,,zk{0,1}z_{1},\ldots,z_{k}\in\{0,1\} one has the following identity:

2(z1zk)=2a=1kza41a<bkzazb(mod8).2(z_{1}\oplus\cdots\oplus z_{k})=2\sum_{a=1}^{k}z_{a}-4\sum_{1\leq a<b\leq k}z_{a}z_{b}{\pmod{8}}.

Choose za=ηayaz_{a}=\eta_{a}y_{a} such that λ(y)=4(z1zk)\lambda(\vec{y})=4(z_{1}\oplus\cdots\oplus z_{k}). Then a function λ(y)\lambda^{\prime}(y) satisfying Eq. (96) has a basis-dependent representation λ(y)=2(z1zk)\lambda^{\prime}(\vec{y})=2(z_{1}\oplus\cdots\oplus z_{k}), that is,

λ(hy)=2a=1kηaya41a<bkηaηbybyb.\lambda^{\prime}(h\oplus y)=2\sum_{a=1}^{k}\eta_{a}y_{a}-4\sum_{1\leq a<b\leq k}\eta_{a}\eta_{b}\,y_{b}y_{b}. (100)

To summarize, the coefficients of the form qq^{\prime} in the basis g1,,gkg^{1},\ldots,g^{k} are (Q,D,J)(Q^{\prime},D^{\prime},J^{\prime}), where

Q=Q+σ,Da=Da2σηa,Q^{\prime}=Q+\sigma,\quad D_{a}^{\prime}=D_{a}-2\sigma\eta_{a}, (101)

and

Ja,b=Ja,b+4ηaηbfor ab.J_{a,b}^{\prime}=J_{a,b}+4\eta_{a}\eta_{b}\quad\mbox{for $a\neq b$}. (102)

This determines the standard form of |𝒦,q|{\cal K},q^{\prime}\rangle.

Case 2: ξ(𝒦)\xi\notin{\cal L}({\cal K}). Then ξx𝒦\xi\oplus x\notin{\cal K} for any x𝒦x\in{\cal K} and thus the states |𝒦,q|{\cal K},q\rangle and P|𝒦,qP|{\cal K},q\rangle are supported on disjoint subsets of basis vectors. Define an affine space =()h{\cal M}={\cal L}({\cal M})\oplus h of dimension k+1k+1, where (){\cal L}({\cal M}) is spanned by (𝒦){\cal L}({\cal K}) and ξ\xi. We equip (){\cal L}({\cal M}) with a basis g1,,gk+1g^{1},\ldots,g^{k+1}, where gk+1ξg^{k+1}\equiv\xi. Then any vector xx\in{\cal M} can be written in a basis-dependent way as

x=ha=1k+1xaga(mod2).x=h\oplus\sum_{a=1}^{k+1}x_{a}g^{a}{\pmod{2}}.

Let x=(x1,,xk+1)\vec{x}=(x_{1},\ldots,x_{k+1}). A simple algebra shows that

P+|𝒦,q=21k/2xeiπ4q(x)|x=21/2|,q,P_{+}|{\cal K},q\rangle=2^{-1-k/2}\sum_{x\in{\cal M}}e^{i\frac{\pi}{4}q^{\prime}(x)}|x\rangle=2^{-1/2}|{\cal M},q^{\prime}\rangle, (103)

where q:8q^{\prime}\,:\,{\cal M}\to\mathbb{Z}_{8} is a quadratic form defined by

q(x)=q(x)+[2m+4(ζ,hξ)]xk+1+4a=1kζaxaxk+1.q^{\prime}(\vec{x})=q(\vec{x})+\left[2m+4(\zeta,h\oplus\xi)\right]x_{k+1}+4\sum_{a=1}^{k}\zeta_{a}x_{a}x_{k+1}. (104)

Here it is understood that q(x)q(\vec{x}) depends only on the first kk coordinates of xx. Thus the coefficients of qq^{\prime} in the chosen basis of (){\cal L}({\cal M}) are Q=QQ^{\prime}=Q, D=[D,2m+4(ζ,hξ)]D^{\prime}=[D,2m+4(\zeta,h\oplus\xi)], and

J=[J4𝜻T4𝜻4m].J^{\prime}=\left[\begin{array}[]{c|c}J&4\boldsymbol{\zeta}^{T}\\ \hline\cr 4\boldsymbol{\zeta}&4m\\ \end{array}\right]. (105)

Here 𝜻(ζ1,,ζk)\boldsymbol{\zeta}\equiv(\zeta_{1},\ldots,\zeta_{k}) is a row vector.

It remains to compute the standard form of {\cal M}. Below we define a function EXTEND(𝒦,ξ)({\cal K},\xi) that takes as input an affine space 𝒦=(n,k,h,G,G¯){\cal K}=(n,k,h,G,\bar{G}) and a vector ξ𝔽2n\xi\in\mathbb{F}_{2}^{n}. If ξ(𝒦)\xi\in{\cal L}({\cal K}), the function does nothing. Otherwise, the function outputs an affine space =(n,k+1,h,H,H¯){\cal M}=(n,k+1,h,H,\bar{H}) such that the first kk rows of GG and HH are the same and the (k+1)(k+1)-th row of HH equals ξ\xi. Since the function EXTEND is very similar to the function SHRINK defined in Appendix B, we just state the algorithm skipping the analysis.

function {\cal M}=Extend(𝒦,ξ{\cal K},\xi)   S{a[n]:(ξ,g¯a)=1}S\leftarrow\{a\in[n]\,:\,(\xi,\bar{g}^{a})=1\}   TS{k+1,,n1,n}T\leftarrow S\cap\{k+1,\ldots,n-1,n\}   if T=T=\emptyset then    \triangleright ξ(𝒦)\xi\in{\cal L}({\cal K})    return 𝒦{\cal K}   end if   Pick any iTi\in T   SS{i}S\leftarrow S\setminus\{i\}   for aSa\in S do     g¯ag¯ag¯i\bar{g}^{a}\leftarrow\bar{g}^{a}\oplus\bar{g}^{i}   end for   gigiaSgag^{i}\leftarrow g^{i}\oplus\sum_{a\in S}g^{a}   \triangleright Now gi=ξg^{i}=\xi   Swap gig^{i} and gk+1g^{k+1}. Swap g¯i\bar{g}^{i} and g¯k+1\bar{g}^{k+1}.   return (n,k+1,h,G,G¯)(n,k+1,h,G,\bar{G}) end function

It has runtime O(n2)O(n^{2}). We do not have to update the coefficients of qq^{\prime} since Eq. (104) defines qq^{\prime} in the basis g1,,gk,ξg^{1},\ldots,g^{k},\xi which coincides with the new basis of {\cal M}. We conclude that the projected state 21/2|,q2^{-1/2}|{\cal M},q^{\prime}\rangle can be computed in time O(n2)O(n^{2}).

Below we summarize the entire algorithm as a function MeasurePauli that takes as input a stabilizer state |𝒦,q𝒮n|{\cal K},q\rangle\in{\cal S}_{n} and a Pauli operator P𝒫nP\in{\cal P}_{n}. The function returns the norm of the projected state Γ=P+|𝒦,q\Gamma=\|P_{+}|{\cal K},q\rangle\|. If Γ0\Gamma\neq 0, the function computes the standard form of the projected state P+|𝒦,qP_{+}|{\cal K},q\rangle. As before, we assume that the function can modify the data describing the input state.

function Γ\Gamma=MeasurePauli(|𝒦,q,P|{\cal K},q\rangle,P)   \triangleright P=imZ(ζ)X(ξ)P=i^{m}Z(\zeta)X(\xi)   \triangleright 𝒦=(n,k,h,G,G¯){\cal K}=(n,k,h,G,\bar{G})   \triangleright q=(Q,D,J)q=(Q,D,J)   for a=1a=1 to kk do    ξa(g¯a,ξ)\xi_{a}\leftarrow(\bar{g}^{a},\xi), ζa(ga,ζ)\zeta_{a}\leftarrow(g^{a},\zeta)   end for   ξa=1kξaga(mod2)\xi^{\prime}\leftarrow\sum_{a=1}^{k}\xi_{a}g^{a}{\pmod{2}}   Compute ω{0,2,4,6}\omega\in\{0,2,4,6\} using Eq. (89)   if ξ=ξ\xi^{\prime}=\xi and ω{0,4}\omega\in\{0,4\} then    Compute η1,,ηk\eta_{1},\ldots,\eta_{k} using Eq. (95)    γa=1kηaga(mod2)\gamma\leftarrow\sum_{a=1}^{k}\eta_{a}g^{a}{\pmod{2}}    ωω/4\omega^{\prime}\leftarrow\omega/4    αω(η,h)\alpha\leftarrow\omega^{\prime}\oplus(\eta,h)    ϵ\epsilon\leftarrowSHRINK(|𝒦,q,γ,α)(|{\cal K},q\rangle,\gamma,\alpha)    if ϵ=\epsilon=EMPTY then      Γ0\Gamma\leftarrow 0      return    end if    if ϵ=\epsilon=SAME then      Γ1\Gamma\leftarrow 1      return    end if    if ϵ=\epsilon=SUCCESS then      Γ21/2\Gamma\leftarrow 2^{-1/2}      return    end if   end if   if ξ=ξ\xi^{\prime}=\xi and ω{2,6}\omega\in\{2,6\} then    σ2(ω/2)\sigma\leftarrow 2-(\omega/2)    Compute (Q,D,J)(Q^{\prime},D^{\prime},J^{\prime}) using Eqs. (101,102)    (Q,D,J)(Q,D,J)(Q,D,J)\leftarrow(Q^{\prime},D^{\prime},J^{\prime})    Γ21/2\Gamma\leftarrow 2^{-1/2}    return   end if   if ξξ\xi^{\prime}\neq\xi then    𝒦{\cal K}\leftarrowEXTEND(𝒦,ξ)({\cal K},\xi)    D[D,2m+4(ζ,hξ)]D\leftarrow[D,2m+4(\zeta,h\oplus\xi)]    JJJ\leftarrow J^{\prime}, where JJ^{\prime} is defined in Eq. (105)    Γ21/2\Gamma\leftarrow 2^{-1/2}    return   end if end function

Number of qubits 𝟏𝟎\bf 10 𝟐𝟓\bf 25 𝟓𝟎\bf 50 𝟕𝟓\bf 75 𝟏𝟎𝟎\bf 100 nn
MeasurePauli 0.270.27 0.30.3 0.40.4 0.50.5 0.60.6 O(n2)O(n^{2})
RandomStabilizerState 0.20.2 0.30.3 0.80.8 1.71.7 2.82.8 O(n2)O(n^{2})
InnerProduct 0.50.5 1.51.5 3.53.5 6.56.5 8.98.9 O(n3)O(n^{3})
ExponentialSum 0.30.3 0.80.8 2.22.2 4.44.4 88 O(n3)O(n^{3})
Table 1: Average runtime in milliseconds for a MATLAB implementation of our algorithms. Simulations were performed on a laptop with 2.6GHz Intel i5 Dual Core CPU.

Appendix F: Simulation of the hidden shift algorithm

Refer to caption
Figure 3: Gadget from Ref. [13] implementing the Toffoli gate. The two control qubits and the target qubit are denoted c1,c2c_{1},c_{2} and tt respectively. Both measurement outcomes appear with probability 1/21/2. The final controlled-ZZ gate on qubits c1,c2c_{1},c_{2} is applied only if the measurement outcome is ‘11’.

Here we provide further details of the simulations reported in Fig. 1. Recall that we simulate a circuit

U=HnOfHnOfHn,U=H^{\otimes n}O_{f^{\prime}}H^{\otimes n}O_{f}H^{\otimes n}, (106)

where Of|x=f(x)|xO_{f}|x\rangle=f(x)|x\rangle and Of|x=f(x)|xO_{f^{\prime}}|x\rangle=f^{\prime}(x)|x\rangle are oracle circuits for some bent functions f,f:𝔽2n{+1,1}f,f^{\prime}\,:\,\mathbb{F}_{2}^{n}\to\{+1,-1\} such that

f(x)=2n/2y𝔽2n(1)xyf(ys)for all x𝔽2n.f^{\prime}(x)=2^{-n/2}\sum_{y\in\mathbb{F}_{2}^{n}}(-1)^{x\cdot y}f(y\oplus s)\quad\mbox{for all $x\in\mathbb{F}_{2}^{n}$}. (107)

Here s𝔽2ns\in\mathbb{F}_{2}^{n} is the hidden shift that can be found from |s=U|0n|s\rangle=U|0^{n}\rangle. In our simulations the hidden shift ss was chosen at random from the uniform distribution. The function ff was chosen from (a subclass of) the Maiorana McFarland family of bent functions. In general, a Maiorana McFarland bent function is defined as follows. Suppose nn is even. Let

g:𝔽2n/2𝔽2andπ:𝔽2n/2𝔽2n/2g:\mathbb{F}_{2}^{n/2}\rightarrow\mathbb{F}_{2}\quad\mbox{and}\quad\pi:\mathbb{F}_{2}^{n/2}\rightarrow\mathbb{F}_{2}^{n/2}

be any Boolean function and any permutation respectively. For any such pair g,πg,\pi we may define a bent function f:𝔽2n{+1,1}f:\mathbb{F}_{2}^{n}\rightarrow\{+1,-1\} according to

f(x,y)=(1)g(x)+yπ(x)x,y𝔽2n/2.f(x,y)=(-1)^{g(x)+y\cdot\pi(x)}\qquad x,y\in\mathbb{F}_{2}^{n/2}. (108)

The Hadamard transform of ff is given by

2n/2u,v(1)ux+vyf(u,v)=(1)xπ1(y)+g(π1(y)).2^{-n/2}\sum_{u,v}(-1)^{u\cdot x+v\cdot y}f(u,v)=(-1)^{x\cdot\pi^{-1}(y)+g(\pi^{-1}(y))}. (109)

In our simulations we only used bent functions of the form Eq. (108) with π=I\pi=I (the identity permutation). The Boolean function gg was chosen at random, as explained below. Letting OgO_{g} be the n/2n/2-qubit diagonal unitary

Og|x=(1)g(x)|xx𝔽2n/2O_{g}|x\rangle=(-1)^{g(x)}|x\rangle\quad x\in\mathbb{F}_{2}^{n/2}

we see that a quantum circuit which implements the nn-qubit unitary oracle Of|x,y=f(x,y)|x,yO_{f}|x,y\rangle=f(x,y)|x,y\rangle can be decomposed as

Of=(i=1n/2CZi,i+n/2)OgIO_{f}=\left(\prod_{i=1}^{n/2}CZ_{i,i+n/2}\right)O_{g}\otimes I

where CZ=diag(1,1,1,1)CZ=\mathrm{diag}(1,1,1,-1) is the two-qubit controlled-ZZ gate. Here the tensor product separates the first n/2n/2 qubits from the last n/2n/2. Likewise, from Eqs. (107,109) one infers that

Of=[(i=1n/2CZi,i+n/2)IOg]Z(s)O_{f^{\prime}}=\left[\left(\prod_{i=1}^{n/2}CZ_{i,i+n/2}\right)I\otimes O_{g}\right]Z(s)

Note that the total TT-count of the circuit UU is twice the TT-count of OgO_{g}. To construct a circuit implementing OgO_{g} we chose a sequence of gates from the set {Z,CZ,CCZ}\{Z,CZ,CCZ\}, where CCZCCZ is the controlled-controlled-Z gate. We first fixed the number of CCZCCZ gates (five and six for the simulations reported in the left/right plots of Fig. 1 respectively), and then produced a circuit OgO_{g} alternating the CCZCCZ gates (on a randomly chosen triple of qubits) with random sequences of 200200 Clifford gates from the set {Z,CZ}\{Z,CZ\}. Note that the CCZCCZ gate can be replaced by the Toffoli gate using the identity

CCZ=(IIH)Toff(IIH).CCZ=(I\otimes I\otimes H)\mathrm{Toff}(I\otimes I\otimes H). (110)

To decompose Toffoli gates into Clifford and TT-gates we used a gadget proposed by Jones [13], see Fig. 3. The gadget uses four TT-gates, two ancillary qubits initialized in the state |0|0\rangle, several Clifford gates, and the 0,10,1-measurement. The final Clifford gate is classically controlled by the measurement outcome. To simulate the gadget we use the trick described in the remark between Eqs. (29, 30). Namely, in our simulation the measurement of the ancillary qubit is replaced by postselection on a random output bit yy in exactly the same way as was done for the TT-gate gadget. The second ancilla in the gadget is never measured and is returned to the state |0|0\rangle at the output; this ancilla is reused by all Toffolis in the circuit.

The simulation algorithm we implemented differs in some small details from the algorithm analyzed in the main text of the paper. To produce each data point in Fig. 1 we first fixed the output qubit q{1,2,,40}q\in\{1,2,\ldots,40\}. We then estimated the ratio (cf. Eq. (27))

Pouty(1)=0Nψ|Vy(|11|q|yy|)Vy|0Nψ0Nψ|Vy(In+1|yy|)Vy|0Nψ.P^{y}_{out}(1)=\frac{\langle 0^{N}\otimes\psi|V_{y}^{\dagger}(|1\rangle\langle 1|_{q}\otimes|y\rangle\langle y|)V_{y}|0^{N}\otimes\psi\rangle}{\langle 0^{N}\otimes\psi|V_{y}^{\dagger}(I_{n+1}\otimes|y\rangle\langle y|)V_{y}|0^{N}\otimes\psi\rangle}. (111)

for a randomly chosen postselection bit-string yy. For us N=n+nancN=n+n_{anc} where n=40n=40 is the number of qubits in the original circuit to be simulated while nancn_{anc} is the number of ancillae initialized in the state |0|0\rangle which are used for the Toffoli gadgets. Since each Toffoli gadget requires two ancilla, one of which is shared by all of them, we have nanc=1+TFn_{anc}=1+\mathrm{TF} where TF\mathrm{TF} is the number of Toffoli gadgets used. In Eq. (111) the number of postselection bits is |y|=t+TF|y|=t+\mathrm{TF} where tt is the number of TT-gates in the circuit (including the four TT-gates within each Toffoli gadget). The unitary VyV_{y} is a (n+1+TF+t)(n+1+\mathrm{TF}+t)-qubit Clifford unitary which is obtained by replacing all Toffoli gadgets and TT gate gadgets by the appropriate Clifford circuits obtained by postselecting on the measurement outcomes defined by the bit string yy. Finally, the state ψ\psi in Eq. (111) is a tt-qubit state which approximates tt copies of the magic state |At|A\rangle^{\otimes t}. In particular, ψ\psi was derived from a kk-dimensional subspace \cal{L} of 𝔽2t\mathbb{F}_{2}^{t} in the manner described in the main text of the paper. In our simulations we used k=11k=11 (left plot in Fig. 1) and k=12k=12 (right plot in Fig. 1). The fidelities were |At|ψ|0.81|\langle A^{\otimes t}|\psi\rangle|\approx 0.81 and |At|ψ|0.69|\langle A^{\otimes t}|\psi\rangle|\approx 0.69 respectively.

To estimate Pouty(1)P^{y}_{out}(1) we computed integers u,vu,v and stabilizer groups ,𝒢\cal{F},\cal{G} such that

0Nψ|Vy(|11|q|yy|)Vy|0Nψ=2uψ|Π|ψ\langle 0^{N}\otimes\psi|V_{y}^{\dagger}(|1\rangle\langle 1|_{q}\otimes|y\rangle\langle y|)V_{y}|0^{N}\otimes\psi\rangle=2^{-u}\langle\psi|\Pi_{\cal{F}}|\psi\rangle (112)

and

0Nψ|Vy(|00|q|yy|)Vy|0Nψ=2vψ|Π𝒢|ψ\langle 0^{N}\otimes\psi|V_{y}^{\dagger}(|0\rangle\langle 0|_{q}\otimes|y\rangle\langle y|)V_{y}|0^{N}\otimes\psi\rangle=2^{-v}\langle\psi|\Pi_{\cal{G}}|\psi\rangle (113)

and then, if Π0\Pi_{\cal{F}}\neq 0 and Π𝒢0\Pi_{\cal{G}}\neq 0, we computed approximations α,β\alpha,\beta to the quantities Eqs. (113,112) using the norm estimation procedure described in the main text. The number of random stabilizer states sampled by the norm estimation procedure was chosen to be 100100 (left plot in Fig. 1) or 5050 (right plot in Fig. 1). Our estimate of Pouty(1)P_{out}^{y}(1) was then α/(α+β)\alpha/(\alpha+\beta) (cf. Eq. (111)). Note that if either Π=0\Pi_{\cal{F}}=0 or Π𝒢=0\Pi_{\cal{G}}=0 then α,β\alpha,\beta, and Pouty(1)P_{out}^{y}(1) can be computed without ever calling the norm estimation subroutine. This special case occured for all qubits 1,2,,201,2,\ldots,20 in both our simulations (as well as for some of the other data points).

References

  • [1] D. Wecker and K. M. Svore, preprint arXiv:1402.4467 (2014).
  • [2] D. Gottesman, preprint quant-ph/9807006 (1998).
  • [3] S. Aaronson and D. Gottesman, Phys. Rev. A 70, 052328 (2004).
  • [4] I. Markov and Y. Shi, SIAM J. on Comp. 38, 963 (2008).
  • [5] M. Van den Nest, Quant. Inf. Comp. 10, 0258 (2010).
  • [6] H. Pashayan, J. Wallman, and S. Bartlett, preprint arXiv:1503.07525 (2015).
  • [7] S. Bravyi and A. Kitaev, preprint quant-ph/9811052 (1998).
  • [8] A. Fowler, M. Mariantoni, J. M. Martinis, and A. N. Cleland, Phys. Rev. A 86, 032324 (2012).
  • [9] V. Kliuchnikov, D. Maslov, and M. Mosca, Quant. Inf. and Comp. 13, 607 (2013).
  • [10] P. Selinger, Quant. Inf. and Comp. 15, 159 (2015).
  • [11] N. J. Ross and P. Selinger, preprint arXiv:1403.2975 (2014).
  • [12] A. Fowler, S. Devitt, and C. Jones, Scientific Reports 3, 1939 (2013).
  • [13] C. Jones, Physical Review A 87, 022328 (2013).
  • [14] Note1, The MATLAB implementation of the sampling algorithm is available upon request to the authors.
  • [15] S. Bravyi, G. Smith, and J. Smolin, preprint arXiv:1506.01396 (2015).
  • [16] M. Rötteler, in Proceedings of the 21st ACM-SIAM Symposium on Discrete Algorithms (2010), pp. 448–457.
  • [17] C. Dankert, R. Cleve, J. Emerson, and E. Livine, Phys. Rev. A 80, 012304 (2009).
  • [18] H. J. García, I. Markov, and A. Cross, Quant. Inf. and Comp. 14, 683 (2014).
  • [19] X. Zhou, D. W. Leung, and I. L. Chuang, Phys. Rev. A 62, 052316 (2000).
  • [20] M. R. Jerrum, L. G. Valiant, and V. V. Vazirani, Theoretical Computer Science 43, 169 (1986).
  • [21] M. Amy, D. Maslov, M. Mosca, and M. Roetteler, Computer-Aided Design of Integrated Circuits and Systems, IEEE Transactions on 32, 818 (2013), eprint 1206.0758.
  • [22] D. Gosset, V. Kliuchnikov, M. Mosca, and V. Russo, Quant. Inf. and Comp. 14, 1261 (2014).
  • [23] A. Kitaev, private communication (2003).
  • [24] K.-U. Schmidt, Information Theory, IEEE Transactions on 55, 5803 (2009).
  • [25] M. Araújo (2011), URL http://www.math.ist.utl.pt/~ggranja/manuel.pdf.
  • [26] J. Dehaene and B. De Moor, Phys. Rev. A 68, 042318 (2003).
  • [27] H. García-Ramírez, Ph.D. thesis, The University of Michigan (2014).