Introduction
A fault-tolerant Boolean oracle U f ∣ x ⟩ ∣ b ⟩ = ∣ x ⟩ ∣ b ⊕ f ( x ) ⟩ U_f|x\rangle|b\rangle= |x\rangle|b \oplus f(x)\rangle U f ∣ x ⟩ ∣ b ⟩ = ∣ x ⟩ ∣ b ⊕ f ( x )⟩ has two costs: its T T T gates, each of which consumes a distilled magic state [1 , 2 ] , and its ancilla qubits beyond the inputs. Such oracles are the inner loop of Grover search [3 ] and of block encodings for the quantum singular value transform [4 ] .
The Toffoli gate Toff n \operatorname{Toff}_n Toff n has n − 1 n-1 n − 1 controls and one target, and on a computational-basis input it flips the target exactly when the control string x ∈ F 2 n − 1 x \in\mathbb{F}_2^{n-1} x ∈ F 2 n − 1 is all ones. For this gate the two costs pull against each other. Once n ≥ 4 n \ge4 n ≥ 4 , no Clifford+T T T circuit on its n n n qubits implements it exactly [5 , 6 ] , so an exact circuit needs an extra qubit. A clean ancilla, which starts and ends in ∣ 0 ⟩ |0\rangle ∣0 ⟩ , brings the cost to about 8 n 8n 8 n T T T gates, with or without a mid-circuit measurement [7 , 8 ] . A borrowed qubit, which may be in any state but must be restored, costs about 16 n 16n 16 n [7 , 9 ] . Neither count can drop below linear in n n n , since an exact circuit needs at least n n n T T T gates even with measurement and feedforward [10 Proposition 4.1] . Approximation alone does not help: for large n n n , a unitary circuit within diamond distance less than 1 / 2 1/2 1/2 of Toff n \operatorname{Toff}_n Toff n still needs n − 2 n-2 n − 2 T T T gates even with clean ancillae [11 Theorem 2] , where diamond distance is the worst-case distance between quantum channels.
Gosset, Kothari and Zhang (GKZ) showed that randomness removes this dependence on n n n [11 ] . If each call runs a freshly sampled Clifford+T T T circuit and only the averaged channel has to be within diamond distance ε \varepsilon ε of Toff n \operatorname{Toff}_n Toff n , then O ( log ( 1 / ε ) ) O(\log(1/\varepsilon)) O ( log ( 1/ ε )) T T T gates suffice. Their construction, which we call GKZ’s sampler, first flips every control, so that the target must flip exactly when the control string is all zeros. A parity of the controls is the sum modulo 2 of a subset of them. Each sampled circuit checks about log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) parities with uniformly random subsets and flips the target only if all of them are 0. The all-zeros string passes every check, and any other string fails each check with probability 1 / 2 1/2 1/2 , so it passes them all with probability about ε \varepsilon ε . Once the parities are computed, the only non-Clifford gate is a multi-controlled NOT on their values. A direct implementation computes them into fresh qubits (Figure 1 ) and so uses about log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) ancillae, a number GKZ do not optimize.
Figure 1. A direct implementation of one branch of GKZ’s sampler. A slash marks a bundle of qubits, and X ⊗ ( n − 1 ) X^{\otimes(n-1)} X ⊗ ( n − 1 ) flips every control. The CNOT circuit P P P writes the ℓ \ell ℓ sampled parities into ℓ \ell ℓ clean ancillae, and the open circle is a control active on 0. The multi-controlled NOT is the only non-Clifford gate, and P † P^\dagger P † returns the ancillae to ∣ 0 ⟩ |0\rangle ∣0 ⟩ .
We work in GKZ’s mixed model (Definition 6). A circuit implements a unitary U U U if it applies U U U up to a global phase. A mixture is a probability distribution over unitary Clifford+T T T circuits, called branches, which do not measure or adapt. Its error is the diamond distance of the averaged channel from the target, its cost is the largest T T T -count of a branch, and T ε m i x e d ( U ) \mathcal{T}^{\mathrm{mixed}}_{\varepsilon}(U) T ε mixed ( U ) is the least cost at error ε \varepsilon ε . The oracle of f : F 2 n → { 0 , 1 } f:\mathbb{F}_2^n\to\{0,1\} f : F 2 n → { 0 , 1 } acts on n + 1 n+1 n + 1 qubits, and Toff n \operatorname{Toff}_n Toff n acts on n n n . Our lower bounds allow any number of ancillae in any initial state, unless we say that the ancillae are clean. Throughout, ℓ = ⌈ log ( 4 / ε ) ⌉ \ell=\lceil\log(4/\varepsilon)\rceil ℓ = ⌈ log ( 4/ ε )⌉ is the number of parities a branch checks, and logarithms are to base 2.
Our results concern whether a mixture for U f U_f U f still needs extra qubits (§ 1.1 ), how close it comes to the lower bounds (§ 1.2 ), and which property of f f f determines its cost (§ 1.3 ).
Theorem 1 (the randomized Toffoli gate (informal version of Theorem 11)). If n ≥ ⌈ 3 ℓ / 2 ⌉ n\ge\lceil3\ell/2\rceil n ≥ ⌈ 3 ℓ /2 ⌉ , then Toff n \operatorname{Toff}_n Toff n has a mixture at diamond error ε \varepsilon ε whose branches use exactly 8 ℓ − 8 8\ell-8 8 ℓ − 8 T T T gates, no ancilla and no measurement. If only n ≥ ℓ + 2 n\ge\ell+2 n ≥ ℓ + 2 , the branches still use no ancilla and at most 16 ℓ − 32 16\ell-32 16 ℓ − 32 T T T gates.
The extra qubit is forced by a determinant. Every Clifford+T T T circuit on four or more qubits implements a unitary of determinant 1, while an oracle that flips the target on N N N control strings has determinant ( − 1 ) N (-1)^N ( − 1 ) N . An exact Toffoli gate flips it on one string. A branch that checks ℓ \ell ℓ linearly independent parities also flips the target on every other string whose ℓ \ell ℓ parities are all 0. These strings form a subspace of dimension n − 1 − ℓ n-1-\ell n − 1 − ℓ , so there are 2 n − 1 − ℓ 2^{n-1-\ell} 2 n − 1 − ℓ of them. This number is even when ℓ ≤ n − 2 \ell\le n-2 ℓ ≤ n − 2 , so the unitary such a branch must implement has determinant 1 and the obstruction does not apply. The parities depend only on the span of the sampled subsets, so a CNOT change of basis can overwrite at most ℓ \ell ℓ of the controls with them, and the branch runs on the gate’s own qubits. We draw the subsets linearly independent, which keeps GKZ’s error bound and makes the count above exact (Construction 8). The checks then become a multi-controlled NOT on these ℓ \ell ℓ controls, which can borrow the other n − 1 − ℓ n-1-\ell n − 1 − ℓ controls as work qubits.
Against a direct implementation of GKZ’s sampler, the branches save about ℓ \ell ℓ ancillae. Computing the parities in place still leaves one clean ancilla if the multi-controlled NOT is built on it, as in the cheapest exact constructions. Once n ≥ ⌈ 3 ℓ / 2 ⌉ n\ge\lceil3\ell/2\rceil n ≥ ⌈ 3 ℓ /2 ⌉ , the branches remove that qubit by borrowing idle controls instead, at the cost of one to five T T T gates (Table 1 ), which is worthwhile when a computation is limited by its number of logical qubits. With ℓ − 2 \ell-2 ℓ − 2 clean ancillae and measurement, the sampler can instead use a ladder of temporary logical-AND gates [12 , 13 ] and needs 4 ℓ − 1 4\ell-1 4 ℓ − 1 T T T gates [14 ] , about half of 8 ℓ − 8 8\ell-8 8 ℓ − 8 . We know of no other Clifford+T T T implementation of Toff n \operatorname{Toff}_n Toff n that uses no qubit beyond its own n n n and a number of T T T gates independent of n n n . Once n ≥ ⌈ 3 ℓ / 2 ⌉ n\ge\lceil3\ell/2\rceil n ≥ ⌈ 3 ℓ /2 ⌉ , the branches also use fewer T T T gates than every exact construction without a clean ancilla, and they need no measurement.
Table 1. T T T -counts for Toff n \operatorname{Toff}_n Toff n with m = n − 1 m=n-1 m = n − 1 controls. The branches are in bold. GKZ + X is GKZ’s sampler with its parities computed in place as in Construction 8 and its multi-controlled NOT built as in X. Computing them into fresh qubits instead, as in GKZ’s direct circuit, adds ℓ \ell ℓ ancillae. The Khattar–Gidney rows use the count without measurement of [8 Eq. (12)] ; with the measurement-based uncomputation of [7 ] the count is 8 m − 12 8m-12 8 m − 12 . At the entry marked †, n < ⌈ 3 ℓ / 2 ⌉ n < \lceil3\ell/2\rceil n < ⌈ 3 ℓ /2 ⌉ and the count is 16 ℓ − 16 d − 16 16\ell- 16d - 16 16 ℓ − 16 d − 16 with d = n − 1 − ℓ d=n-1-\ell d = n − 1 − ℓ [9 Theorems 2 and 10] .
Structured oracles
A branch of GKZ’s sampler flips the target exactly on the solutions of ℓ \ell ℓ linear equations over F 2 \mathbb{F}_2 F 2 , so it is itself a test of linear equations. Many useful oracles have the same form. The inputs that satisfy r r r independent equations form an affine subspace of dimension n − r n-r n − r , that is, of codimension r r r . CNOT gates can write the value of each equation onto one of the inputs, so the oracle of such a test is Toff r + 1 \operatorname{Toff}_{r+1} Toff r + 1 up to Clifford gates, and our branches extend to it. They also extend to an exclusive-or of J J J such oracles, built term by term at error ε / J \varepsilon/J ε / J each. We write 1 A \mathbf{1}_A 1 A for the indicator function of a set A A A .
Theorem 2 (affine decompositions (informal version of Theorem 12)). Let f = ⨁ j = 1 J 1 A j f=\bigoplus_{j=1}^{J}\mathbf{1}_{A_j} f = ⨁ j = 1 J 1 A j with A j A_j A j of codimension r j r_j r j , and put ℓ J = ⌈ log ( 4 J / ε ) ⌉ \ell_J=\lceil\log(4J/\varepsilon)\rceil ℓ J = ⌈ log ( 4 J / ε )⌉ . If n ≥ ⌈ 3 min { r j , ℓ J } / 2 ⌉ − 1 n\ge\lceil3\min\{r_j,\ell_J\}/2\rceil-1 n ≥ ⌈ 3 min { r j , ℓ J } /2 ⌉ − 1 for every j j j , then U f U_f U f has a mixture at diamond error ε \varepsilon ε with no ancilla, no measurement and at most 8 J ℓ J 8J\ell_J 8 J ℓ J T T T gates per branch, independently of n n n .
With J = 1 J=1 J = 1 , Theorem 2 covers the reflection about ∣ 0 α ⟩ \lvert0^\alpha\rangle ∣ 0 α ⟩ , which is Toff a \operatorname{Toff}_a Toff a up to Clifford gates and is used in amplitude amplification [3 ] and in the quantum singular value transform [4 ] . It also covers equality tests between two registers or against a fixed string. Membership in the solution set of a linear system, or in a linear code, is another example. For these oracles GKZ’s construction already gives O ( log ( 1 / ε ) ) O(\log(1/\varepsilon)) O ( log ( 1/ ε )) T T T gates [11 ] , and Theorem 2 removes its ancillae.
Larger J J J covers functions that split into disjoint pieces. The inputs that reach a leaf of a decision tree satisfy the conditions along its path, so they form an affine subspace. Different leaves share no input, so the function is an exclusive-or of one indicator per accepting leaf. The same holds for parity decision trees, which query parities of the input instead of single bits, and for disjunctive normal forms with disjoint terms. For these functions Theorem 2 matches, up to constants, the bound that GKZ obtain with ancillae [11 Theorem 5] .
These savings shrink when the oracle is called many times. If a computation makes N N N calls, each call needs error about ε / N \varepsilon/N ε / N , because diamond errors add up over a sequence of calls. So ℓ \ell ℓ grows like log ( N / ε ) \log(N/\varepsilon) log ( N / ε ) , and the branches pay off only on oracles with somewhat more than log ( N / ε ) \log(N/\varepsilon) log ( N / ε ) qubits (Figure 3 ).
Figure 3. T T T -count against n n n at ε = 10 − 6 \varepsilon= 10^{-6} ε = 1 0 − 6 , where ℓ = 22 \ell= 22 ℓ = 22 , for the constructions of Table 1 . Dotted lines mark n = ℓ + 2 = 24 n = \ell+ 2 = 24 n = ℓ + 2 = 24 and n = ⌈ 3 ℓ / 2 ⌉ = 33 n = \lceil3\ell/2 \rceil= 33 n = ⌈ 3 ℓ /2 ⌉ = 33 . Below n = 24 n = 24 n = 24 the branches need a clean ancilla and are not drawn. Between the lines they cost 16 ℓ − 16 d − 16 16\ell- 16d - 16 16 ℓ − 16 d − 16 with d = n − 1 − ℓ d = n - 1 - \ell d = n − 1 − ℓ idle controls, and from n = 33 n = 33 n = 33 on they cost 168. The exact circuits with at most one ancilla leave the frame at n = 30 n = 30 n = 30 and n = 56 n = 56 n = 56 , and GKZ + Khattar–Gidney, which is not drawn, lies one T T T gate below the branches.
Lower bounds and exact gates
GKZ proved that mixtures for Toff n \operatorname{Toff}_n Toff n need Ω ( min { n , log ( 1 / ε ) } ) \Omega(\min\{n,\log(1/\varepsilon)\}) Ω ( min { n , log ( 1/ ε )}) T T T gates, even with measurement and adaptivity [11 ] . They also showed that a mixture with t t t T T T gates can be simulated by a random choice of parity decision trees, each querying about t t t parities of the input [11 Theorem 23] . With its controls flipped, Toff n \operatorname{Toff}_n Toff n computes the negation of the OR function, and a standard calculation gives the exact number of parity queries a random decision tree needs for OR (Proposition 13). The following explicit bound for unitary mixtures is a corollary of their reduction, with leading constant 1, where the argument of their Theorem 3 gives about 1 / 4 1/4 1/4 but also covers measurement and adaptivity.
Theorem 3 (lower bound for the Toffoli gate (informal version of Theorem 14 )). For 0 < ε ≤ 1 / 2 0 < \varepsilon\le1/2 0 < ε ≤ 1/2 , every mixture of unitary Clifford+T T T circuits that approximates Toff n \operatorname{Toff}_n Toff n to diamond error ε \varepsilon ε has a branch with at least min { n − 1 , log ( ( 1 − ε ) / ε ) } − 2 \min\{n-1,\log((1-\varepsilon)/\varepsilon)\}-2 min { n − 1 , log (( 1 − ε ) / ε )} − 2 T T T gates.
By Theorem 3 , the branches of Theorem 1 are within a factor of eight of optimal up to an additive constant (Corollary 15 ). The same holds for GKZ’s sampler built on the best known clean-ancilla multi-controlled NOTs. In both constructions every branch is the exact oracle of some Boolean function, though not the one Toff n \operatorname{Toff}_n Toff n computes. For mixtures of this kind, Theorem 4 shows that closing the factor of eight is equivalent to finding exact multi-controlled NOTs with fewer T T T gates. Let t ( k ) t(k) t ( k ) be the least T T T -count of an exact k k k -controlled NOT with clean ancillae and no measurement. The stabilizer-nullity bound of Beverland et al. and Maslov’s construction give k + 1 ≤ t ( k ) ≤ 8 k − 9 k+1 \le t(k) \le8k-9 k + 1 ≤ t ( k ) ≤ 8 k − 9 for k ≥ 3 k \ge3 k ≥ 3 [10 Proposition 4.1], [6, Proposition 4] , and we know of no better bounds.
Theorem 4 (oracle branches and exact multi-controlled NOTs (informal version of Theorem 18 )). Let 0 < ε ≤ 1 / 2 0 < \varepsilon\le1/2 0 < ε ≤ 1/2 and n − 1 ≥ ℓ n-1 \ge\ell n − 1 ≥ ℓ . Among mixtures of circuits that each implement some Boolean oracle exactly, with any clean ancillae, the least branch T T T -count for Toff n \operatorname{Toff}_n Toff n at diamond error ε \varepsilon ε is between t ( K ) − 8 t(K)-8 t ( K ) − 8 and t ( K ) + 24 t(K)+24 t ( K ) + 24 , where K = ⌈ log ( 1 / ε ) ⌉ K=\lceil\log(1/\varepsilon)\rceil K = ⌈ log ( 1/ ε )⌉ .
GKZ’s sampler gives the upper bound [11 Theorem 1] , and the lower bound is new. So without a better exact multi-controlled NOT, closing the factor of eight needs branches that are not the exact oracle of any Boolean function, for example circuits that add input-dependent phases (Theorem 18 ).
Distance from affine and random sets
An affine function is a parity of some of the inputs or its negation, and its oracle needs no T T T gates, since CNOT and X X X gates implement it [15 ] . The function computed by Toff n \operatorname{Toff}_n Toff n differs from the affine function 0 on a single input, and by the intuition behind Theorem 3 that input is what costs T T T gates. This suggests measuring a general f f f by its distance from affine. Let δ \delta δ be the smallest fraction of inputs on which a non-affine f f f differs from an affine function, and call those inputs exceptional. Through GKZ’s reduction to decision trees, f f f needs at least log ( 1 / max { δ , 2 ε } ) − 3 \log(1/\max\{\delta,2\varepsilon\})-3 log ( 1/ max { δ , 2 ε }) − 3 T T T gates (Theorem 20 ). When the exceptional inputs form an affine subspace, this is tight up to a factor of eight and an additive constant (Corollary 21). At constant error the bound is only a constant, and the cost then depends on how the exceptional inputs are arranged. Theorem 5 compares the two extremes, a subspace and a set scattered at random.
Theorem 5 (distance does not determine the T T T -count (informal version of Theorem 28). Let 6 ≤ k ≤ n − 3 log n − 7 6 \le k \le n-3\log n-7 6 ≤ k ≤ n − 3 log n − 7 . Let A A A be an affine subspace of codimension k k k , and let R R R be a random set that contains each input independently with probability 2 − k 2^{-k} 2 − k . With probability at least 1 − 2 2 − n 1-2^{2-n} 1 − 2 2 − n over R R R , the following hold at ε = 1 / 4 \varepsilon=1/4 ε = 1/4 .
(1) Both 1 A \mathbf{1}_A 1 A and 1 R \mathbf{1}_R 1 R are at distance between 4 5 2 − k \frac{4}{5}2^{-k} 5 4 2 − k and 6 5 2 − k \frac{6}{5}2^{-k} 5 6 2 − k from affine.
The oracle of 1 A costs at most 24 T gates. (1) \text{The oracle of }1_{A}\text{ costs at most }24\,T\text{ gates.} \tag*{(1)} The oracle of 1 A costs at most 24 T gates. (1)
The oracle of 1 R costs 2 ( n − k ) / 2 ± O ( log n ) T gates with clean ancillae and 2 n − k ± O ( log n ) without ancillae. (2) \text{The oracle of }1_{R}\text{ costs }2^{(n-k)/2\pm O(\log n)}\,T\text{ gates with clean ancillae and }2^{n-k\pm O(\log n)}\text{ without ancillae.} \tag*{(2)} The oracle of 1 R costs 2 ( n − k ) /2 ± O ( l o g n ) T gates with clean ancillae and 2 n − k ± O ( l o g n ) without ancillae. (2)
Both functions are 0 on almost every input, so their exceptional inputs are A A A and R R R themselves, each about a 2 − k 2^{-k} 2 − k fraction of the inputs. They differ only in structure. Membership in A A A is decided by k k k parities, and at ε = 1 / 4 \varepsilon= 1/4 ε = 1/4 a branch of Theorem 2 checks just four random combinations of them. A random set has no such description: it meets every large subspace in about its expected fraction, so no few parities single it out. Counting makes this precise, since mixtures with few T T T gates can approximate far fewer functions than there are sets R R R .
The upper bounds hash the input to about n − k n-k n − k bits and implement the hashed set exactly (Proposition 27), and the lower bounds count the functions that cheap mixtures can approximate (Theorem 26 ). With clean ancillae the count adapts that of Gosset, Kothari and Wu [16 Lemma 4.8] , and without ancillae a finer count gives the larger bound. That count extends the exact no-ancilla counting bound of Low, Kliuchnikov and Schaeffer [17 Section 5] to mixtures at constant error.
Some sets of this density were already known to be expensive. Gosset, Kothari and Wu’s counting gives a function on n − k n-k n − k bits that needs Ω ( 2 ( n − k ) / 2 ) T \Omega(2^{(n-k)/2})\,T Ω ( 2 ( n − k ) /2 ) T gates even with measurement, and requiring the other k k k inputs to be 0 gives one of density about 2 − k 2^{-k} 2 − k . Earlier counting arguments for sparse sets apply only to exact circuits. Theorem 5 shows that a typical set of this density is expensive even at diamond error 1 / 4 1/4 1/4 and that matching upper bounds exist, so distance from affine does not determine the cost. For an oracle with no structure, randomness cannot remove the exponential cost, and clean ancillae reduce it only from about 2 n − k 2^{n-k} 2 n − k to about 2 ( n − k ) / 2 2^{(n-k)/2} 2 ( n − k ) /2 . An oracle whose exceptional inputs form an affine subspace stays cheap and needs no ancillae, by Theorem 2 .
§ 2 goes through one branch of the Toffoli construction and sketches the proofs, § 3 discusses related work, and § 4 the open problems. Appendix § 5 fixes notation and the model and reviews the multi-controlled NOTs we build on, Appendix § 6 proves the constructions, and Appendix § 7 proves the lower bounds. Python scripts that check the constructions and the numerical claims are available at https://github.com/arulrhikm/randomized-oracle-checks.
Technical overview
Warm-up: one branch
We first make the branch from § 1 precise. Write y = x ⊕ 1 y=x\oplus1 y = x ⊕ 1 for the control string with every bit flipped, so that Toff n \operatorname{Toff}_{n} Toff n flips the target exactly when y = 0 y=0 y = 0 . A branch picks subsets S 1 , … , S ℓ S_{1},\ldots,S_{\ell} S 1 , … , S ℓ of the controls whose indicator vectors are linearly independent over F 2 \mathbb{F}_{2} F 2 , uniformly at random among such choices. It flips the target when y y y has even parity on every S i S_i S i . A nonzero y y y passes all ℓ \ell ℓ tests with probability at most 2 − ℓ 2^{-\ell} 2 − ℓ (Construction 8), as it does for GKZ’s uniformly random subsets. A mixture of oracles that errs on each input with probability at most p p p is within diamond distance 4 p 4p 4 p of the target (Lemma 7 ), so ℓ = ⌈ log ( 4 / ε ) ⌉ \ell=\lceil\log(4/\varepsilon)\rceil ℓ = ⌈ log ( 4/ ε )⌉ gives error at most ε \varepsilon ε . When ℓ ≤ n − 2 \ell\le n-2 ℓ ≤ n − 2 , the determinant obstruction of § 1 does not apply (Proposition 9 ).
Completing the subsets to a basis gives an invertible CNOT circuit Γ \Gamma Γ whose first ℓ \ell ℓ outputs are the parities of y y y on S 1 , … , S ℓ S_{1},\ldots,S_{\ell} S 1 , … , S ℓ . Applying Γ \Gamma Γ , then an ℓ \ell ℓ -controlled NOT with controls active on 0, then Γ † \Gamma^\dagger Γ † implements the branch with no extra qubit (Figure 2 ). The multi-controlled NOT does not depend on the other n − 1 − ℓ n-1-\ell n − 1 − ℓ qubits. A circuit for it can therefore use them as borrowed work qubits, which may be in any state and are returned unchanged, as in the constructions of Barenco et al. [18 Lemma 7.2] . Maslov’s construction uses 8 ℓ − 8 T 8\ell-8\,T 8 ℓ − 8 T gates once ⌈ ( ℓ − 2 ) / 2 ⌉ \lceil(\ell-2)/2\rceil ⌈( ℓ − 2 ) /2 ⌉ such qubits are available, that is, once n ≥ ⌈ 3 ℓ / 2 ⌉ n\ge\lceil3\ell/2\rceil n ≥ ⌈ 3 ℓ /2 ⌉ [6 Proposition 5] . It is built from relative-phase Toffoli gates, whose phases cancel in pairs (Section A.2).
Figure 2. One branch of Theorem 1 , drawn as in Figure 1 but with no ancilla. The CNOT circuit Γ \Gamma Γ moves the ℓ \ell ℓ sampled parities onto the first ℓ \ell ℓ controls. The multi-controlled NOT uses the other n − 1 − ℓ n-1-\ell n − 1 − ℓ qubits as borrowed work qubits and returns them unchanged, and it is the only non-Clifford gate in the branch.
Table 1 and Figure 3 compare the T T T -counts of the branches of Theorem 1 with those of GKZ’s sampler built on three other multi-controlled NOTs and of exact constructions. Measurement and reset are counted as free. Every other construction in the table uses an extra qubit. Those without a clean ancilla need at least 384 T T T gates, against 88 to 352 for the branches. For n n n between ℓ + 2 \ell+2 ℓ + 2 and ⌈ 3 ℓ / 2 ⌉ − 1 \lceil3\ell/2\rceil-1 ⌈ 3 ℓ /2 ⌉ − 1 , the branches use Zindorf and Bose’s construction instead, which borrows the d = n − 1 − ℓ d=n-1-\ell d = n − 1 − ℓ idle controls [9 ] . Even there they can beat the
exact circuits with one clean ancilla, for example with 352 against 379 T T T gates at n = 50 n=50 n = 50 and ε = 10 − 10 \varepsilon=10^{-10} ε = 1 0 − 10 . From n = ℓ + 2 n=\ell+2 n = ℓ + 2 the branches need no ancilla and use fewer T T T gates than exact circuits with one borrowed qubit. They beat exact circuits with one clean ancilla once n > 4 ℓ / 3 + 1 n>4\ell/3+1 n > 4 ℓ /3 + 1 , and those with n − 3 n-3 n − 3 clean ancillae once n ≥ 2 ℓ n\ge2\ell n ≥ 2 ℓ .
Structured oracles
Theorem 2 applies the branch of § 2.1 to each term of an affine decomposition, so the only new questions are which terms to randomize and how their errors add. A term of codimension at most ℓ J \ell_J ℓ J is implemented exactly, as in the synthesis of exclusive-or sums of affine products [19 ] . A term of larger codimension is replaced by a branch that tests ℓ J \ell_J ℓ J random combinations of its equations. Such a term misses an input with probability at most 2 − ℓ J ≤ ε / ( 4 J ) 2^{-\ell_J}\le\varepsilon/(4J) 2 − ℓ J ≤ ε / ( 4 J ) . The misses of the J J J terms add, so each input is missed with probability at most ε / 4 \varepsilon/4 ε /4 , and Lemma 7 turns this into diamond error at most ε \varepsilon ε . Every Boolean function has such a decomposition, for instance with one term per accepting input, but J J J can then be exponential in n n n . A parity decision tree of depth D D D with J J J accepting leaves gives a decomposition that costs at most 8 J min { D , ℓ J } 8J\min\{D,\ell_J\} 8 J min { D , ℓ J } T T T gates when n ≥ ⌈ 3 min { D , ℓ J } / 2 ⌉ − 1 n\ge\lceil3\min\{D,\ell_J\}/2\rceil-1 n ≥ ⌈ 3 min { D , ℓ J } /2 ⌉ − 1 (Section B.2.1).
For example, the membership oracle of Grover search with J J J marked strings is an exclusive-or of J J J indicators of single points, so when n ≥ ⌈ 3 ℓ J / 2 ⌉ − 1 n\ge\lceil3\ell_J/2\rceil-1 n ≥ ⌈ 3 ℓ J /2 ⌉ − 1 it uses J ( 8 ℓ J − 8 ) J(8\ell_J-8) J ( 8 ℓ J − 8 ) T T T gates and no ancilla. Grover search makes about
2 n / 2 2^{n/2} 2 n /2 calls, so the error per call must be about ε t o t 2 − n / 2 \varepsilon_{\mathrm{tot}}2^{-n/2} ε tot 2 − n /2 . At n = 100 n = 100 n = 100 , J = 1 J = 1 J = 1 and ε t o t = 10 − 2 \varepsilon_{\mathrm{tot}} = 10^{-2} ε tot = 1 0 − 2 , this gives ℓ 1 = 59 \ell_1 = 59 ℓ 1 = 59 , and each call costs 464 T T T gates on the oracle’s own 101 qubits. The oracle is Toff 101 \operatorname{Toff}_{101} Toff 101 up to Clifford gates, so Table 1 applies with m = 100 m = 100 m = 100 . An exact circuit needs an extra qubit. Without measurement it uses 1568 T T T gates with a borrowed qubit [7 , 9 ] or 791 with a clean ancilla [7 ] , [8 Eq. (12)] , which is 3.4 and 1.7 times as many. Only constructions with clean ancillae do better: GKZ’s sampler uses 463 with one, and the AND ladder uses 399 with 98 and measurement. So even at the error that 2 50 2^{50} 2 50 calls demand, the branches free a qubit for one T T T gate per call.
Lower bounds for the Toffoli gate
The proof of Theorem 3 goes through parity decision trees. GKZ show that a mixture whose branches use t t t T T T gates can be simulated by a random choice of decision trees, each asking t + 1 t + 1 t + 1 parities of the input and then outputting any function of the answers [11 Theorem 23] . It therefore suffices to show that random trees with few queries cannot compute Toff n \operatorname{Toff}_n Toff n , which in the coordinates y y y of § 2.1 is the negation of OR on m = n − 1 m = n - 1 m = n − 1 bits. Fix one tree that asks q q q parities. All y y y in the kernel of these parities give the same answers, so the tree treats y = 0 y = 0 y = 0 like the 2 m − q − 1 2^{m-q} - 1 2 m − q − 1 nonzero points of this kernel and errs either at 0 or on all of them. Put half the weight on y = 0 y = 0 y = 0 and spread the other half over the nonzero inputs. Every such tree then errs with probability about 2 − q / 2 2^{-q}/2 2 − q /2 , and by Yao’s principle so does every random choice of trees. Error ε \varepsilon ε thus needs q ≈ log ( 1 / ε ) q \approx\log(1/\varepsilon) q ≈ log ( 1/ ε ) , as in the standard argument for one-sided Equality [20 , 21 ] . The bound is tight: a mixture of GKZ’s test with a tree of constant output meets it exactly (Proposition 13), and with the reduction this gives Theorem 3.
Theorem 4 needs a different argument. Decision-tree bounds stay below ⌈ log ( 1 / ε ) ⌉ \lceil\log(1/\varepsilon) \rceil ⌈ log ( 1/ ε )⌉ , so they cannot see the constant in front of log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) . The proof instead works with a single branch. For mixtures of oracles, diamond error ε \varepsilon ε bounds the error probability at every input by ε \varepsilon ε (Lemma 17), so some branch is correct at y = 0 y = 0 y = 0 and wrong on few other inputs. A random subspace of dimension about log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) that contains y = 0 y = 0 y = 0 then avoids all of those inputs with positive probability, and we restrict the branch to it. What remains is an exact multi-controlled NOT on about log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) controls.
Distance from affine and random sets
Theorem 20 extends the argument for Theorem 3 from Toff n \operatorname{Toff}_n Toff n to any f f f . Let a a a be the affine function closest to f f f , so that f f f and a a a differ on a fraction δ \delta δ of the inputs. Since the oracle of a a a needs no T T T gates, implementing U f U_f U f is as hard as implementing the oracle of f ⊕ a f \oplus a f ⊕ a , which is 1 exactly on the exceptional inputs. Put half the weight on the exceptional inputs and spread the other half over the rest. A tree that asks q q q parities gives the same answers on each coset of their kernel, which holds a 2 − q 2^{-q} 2 − q fraction of the inputs. It therefore errs with probability at least ( 2 − q − δ ) / 2 (2^{-q}-\delta)/2 ( 2 − q − δ ) /2 , and by Yao’s principle so does every random choice of trees. Error ε \varepsilon ε thus needs about log ( 1 / max { δ , 2 ε } ) \log(1/\max\{\delta,2\varepsilon\}) log ( 1/ max { δ , 2 ε }) queries.
When the exceptional inputs form an affine subspace A A A of codimension r r r , so that f = a ⊕ 1 A f=a\oplus1_A f = a ⊕ 1 A and δ = 2 − r \delta=2^{-r} δ = 2 − r , Theorem 2 builds the oracle from a single term with at most about 8 min { r , ℓ } 8\min\{r,\ell\} 8 min { r , ℓ } T T T gates. Against the lower bound above, this gives the factor of eight in Corollary 21. An exact implementation needs at least r + 1 r+1 r + 1 T T T gates, so randomization helps only when ℓ < r \ell<r ℓ < r , that is, roughly when δ ≲ ε / 4 \delta\lesssim\varepsilon/4 δ ≲ ε /4 .
For Theorem 5 , a Chernoff bound puts ∣ R ∣ |R| ∣ R ∣ within a factor of 6 / 5 6/5 6/5 of 2 n − k 2^{n-k} 2 n − k . Every affine function other than 0 differs from 1 R 1_R 1 R on about half the inputs, so the distance of 1 R 1_R 1 R from affine is about 2 − k 2^{-k} 2 − k . Decision-tree bounds stay below n − k + 3 n-k+3 n − k + 3 here, so the exponential bounds use counting instead. Averaging O ( n ) O(n) O ( n ) sampled branches and rounding recovers 1 R 1_R 1 R exactly, so a mixture with few T T T gates would give a short description of R R R . Circuits with t t t T T T gates have only 2 O ( t 2 + n t ) 2^{O(t^2+nt)} 2 O ( t 2 + n t ) possible acceptance-probability functions, or 2 O ( n t ) 2^{O(nt)} 2 O ( n t ) without ancillae (Lemma 25). There are 2 Ω ( 2 n − k ) 2^{\Omega(2^{n-k})} 2 Ω ( 2 n − k ) possible sets R R R , so t t t must be about 2 ( n − k ) / 2 2^{(n-k)/2} 2 ( n − k ) /2 with clean ancillae and about 2 n − k 2^{n-k} 2 n − k without.
The upper bounds hash the input to about n − k n-k n − k bits with a random CNOT circuit and implement the oracle of the hashed set exactly. An input outside R R R lands in the hashed set only with small probability, and this is the error of the mixture. With clean ancillae the hashed oracle follows the randomized construction of Li et al. for sparse lookup tables [22 Theorem 3.4] . Without ancillae it is built point by point from Zindorf and Bose’s multi-controlled NOT [9 ] , which borrows one of the unused inputs.
Related work
Campbell and Hastings showed that a random mixture of circuits can approximate a single-qubit rotation more cheaply than any one circuit, because the errors of the branches average out [23 , 24 ] . Gosset, Kothari and Zhang carried the idea to multi-qubit Boolean oracles [11 ] . They gave O ( log ( 1 / ε ) ) O(\log(1/\varepsilon)) O ( log ( 1/ ε )) T T T gates for Toff n \operatorname{Toff}_n Toff n and O ( ∥ f ^ ∥ 1 2 log ( 1 / ε ) ) O(\|\widehat{f}\|_1^2\log(1/\varepsilon)) O ( ∥ f ∥ 1 2 log ( 1/ ε )) for an arbitrary f f f , where ∥ f ^ ∥ 1 \|\widehat{f}\|_1 ∥ f ∥ 1 is the sum of the absolute Fourier coefficients of f f f . Theorem 1 computes their parities in place and borrows the idle controls, so each branch runs without ancillae, and Theorem 2 does the same for affine decompositions.
GKZ also proved a matching Ω ( min { n , log ( 1 / ε ) } ) \Omega(\min\{n,\log(1/\varepsilon)\}) Ω ( min { n , log ( 1/ ε )}) lower bound by generalizing stabilizer nullity, and bounded T T T -counts below by randomized parity decision trees. For mixtures of oracle branches, Theorem 4 shows that their construction, built on an optimal exact multi-controlled NOT, is optimal up to an additive constant. Girish, May, Parham and Yuen proved T T T -count lower bounds for mixtures through communication complexity, including with advice states [25 ] . Randomized non-adaptive parity decision trees are randomized linear sketches over F 2 \mathbb{F}_2 F 2 , studied by Kannan et al. and by Montanaro and Osborne [20 , 21 ] , and Propositions 13 and 19 use the standard averaging arguments from that setting.
Counting arguments give lower bounds for unstructured oracles. Low, Kliuchnikov and Schaeffer implemented the oracle of an arbitrary n n n -bit function with O ( 2 n ) O(\sqrt{2^n}) O ( 2 n ) T T T gates using ancillae, and proved a counting lower bound when the number of ancillae is restricted [17 ] . Gosset, Kothari and Wu settled the T T T -count of state preparation and diagonal unitaries by counting canonical forms whose size does not depend on the ancillae [16 ] . As GKZ note, this gives a Boolean oracle that needs Ω ( 2 n / 2 ) \Omega(2^{n/2}) Ω ( 2 n /2 ) T T T gates at constant error, even with measurement.
Sparse oracles have been studied separately. Li et al. determined the T T T -count of sparse classical data [22 ] , Luo and Li synthesized sparse Boolean functions with O ( n 3 / 4 / s ) O(n^{3/4}/\sqrt{s}) O ( n 3/4 / s ) Toffoli gates for a large support of size s s s [26 ] , and Nie and Zi counted the total gates of sparse Boolean oracles [27 ] . For one-bit oracles of sparse sets, the counting lower bounds of Li et al. and of Nie and Zi need exact implementations. Average-case error cannot capture these oracles, because such an oracle agrees with the identity on all but a small fraction of inputs. The approximate bounds of Li et al. assume at least two output bits [22 Theorem 5.1] , although they allow measurement and feedforward. Theorem 26 instead holds at constant diamond error for mixtures of unitary circuits, with clean ancillae or without, and for a random set with high probability.
Exact constructions differ in the number and kind of extra qubits they use. For exact Clifford+T T T circuits one ancilla always suffices [5 ] , as it does for reversible circuits of NOT, CNOT and Toffoli gates [28 ] . The determinant decides which oracles need that ancilla, namely those of full degree over F 2 \mathbb{F}_2 F 2 (Remark 10 ), and so rules out ancilla-free exact Toffoli gates on four or more qubits [6 ] . Avoiding the ancilla exactly would also need gates of exponential precision [29 ] . Randomized branches escape both obstructions, because no branch has to implement T o f f n \mathrm{Toff}_n Toff n exactly. The exact constructions of Table 1 fall into three groups. Some borrow idle qubits [6 , 9 , 18 ] . Others use one clean ancilla through conditionally clean ancillae [7 , 8 , 29 ] . The AND ladder uses many clean ancillae as temporary logical-AND gates [12 , 13 , 14 ] .
Reversible-logic synthesis builds the oracle of a Boolean function from an exclusive-or of products of literals, one multi-controlled NOT per term. Fazel, Thornton and Rice gave an early cascade construction [30 ] , and Meuli et al. compiled low-T T T oracles from such decompositions and from the multiplicative complexity of f f f [31 ] . Schaeffer and Perkowski allowed each factor to be a parity, so that each term is the indicator of an affine subspace [19 ] . Theorem 2 implements those terms without ancillae and randomizes the terms of large codimension, as GKZ’s sampler does for a single term.
Discussion and open problems
We do not know the constant in the T T T -count of randomized Toffoli gates. The branches use about eight T T T gates per bit of precision, and the best lower bound is about one. Algorithms such as Grover search call the oracle many times, so this constant multiplies their total T T T -count. Is T ε m i x e d ( T o f f n ) \mathcal{T}^{\mathrm{mixed}}_{\varepsilon}(\mathrm{Toff}_n) T ε mixed ( Toff n ) at least κ log ( 1 / ε ) \kappa\log(1/\varepsilon) κ log ( 1/ ε ) for some κ > 1 \kappa> 1 κ > 1 when n ≥ log ( 1 / ε ) n \ge\log(1/\varepsilon) n ≥ log ( 1/ ε ) ? For mixtures of oracle branches, Theorem 4 reduces this to whether lim inf k → ∞ t ( k ) / k > 1 \liminf_{k\to\infty} t(k)/k > 1 lim inf k → ∞ t ( k ) / k > 1 , a question about exact multi-controlled NOTs.
Which property of the exceptional set S S S determines the cost of f = a ⊕ 1 S f = a \oplus1_S f = a ⊕ 1 S with a a a affine? Theorem 5 settles the two extremes at constant error. Subspaces cost O ( 1 ) O(1) O ( 1 ) , while random sets of density 2 − k 2^{-k} 2 − k cost about 2 ( n − k ) / 2 2^{(n-k)/2} 2 ( n − k ) /2 with clean ancillae, so distance from affine alone does not decide the cost. Oracles in applications rarely sit at either extreme, and a compiler would want to know which of them are cheap without ancillae. A natural candidate measure is the least number J J J of affine subspaces whose indicators have exclusive-or 1 S 1_S 1 S . Theorem 2 bounds the cost above by about 8 J ℓ 8J\ell 8 J ℓ . Is it also bounded below by a function of J J J ? Our counting argument gives lower bounds only for random sets, not for a given S S S . It also fails with advice states, which can encode S S S , and we do not know whether random sets stay expensive with measurement and feedforward.
The branches matter most when logical qubits, rather than T T T gates, limit a computation. Magic-state cultivation may push computations toward that regime by making T T T states much cheaper [32 , 33 ] , though its cost under realistic postselection is still open [34 ] , and early fault-tolerant devices will have few logical qubits in any case [35 ] .
Amplitude estimation without ancillae, for example, reflects about ∣ 0 n ⟩ \lvert0^n\rangle ∣ 0 n ⟩ on its whole register at every step, so no qubit is free to serve as an ancilla [36 ] . Compilers also treat clean qubits as scarce and borrow idle ones where they can [37 ] . GKZ’s sampler, as written, computes its parities into clean ancillae, while the branches borrow only their own idle controls. Being unitary, the branches also avoid the mid-circuit measurements and classically controlled corrections of the measured constructions in Table 1 .
Like GKZ’s sampler, the branches are accurate only on average, so the control system must draw a fresh branch for every call, using about ℓ n \ell n ℓ n random bits. Each branch applies Γ \Gamma Γ and its inverse with O ( ℓ n ) O(\ell n) O ( ℓ n ) CNOT gates, about as many as GKZ’s direct circuit uses to compute its parities. We have not estimated space-time volume on a specific architecture.
The branches cost more when n n n is just above ℓ \ell ℓ . For ℓ + 2 ≤ n < ⌈ 3 ℓ / 2 ⌉ \ell+ 2 \le n < \lceil3\ell/2\rceil ℓ + 2 ≤ n < ⌈ 3 ℓ /2 ⌉ they can borrow only d = n − 1 − ℓ d = n - 1 - \ell d = n − 1 − ℓ idle controls and use 16 ℓ − 16 d − 16 T 16\ell- 16d - 16T 16 ℓ − 16 d − 16 T gates, up to twice the 8 ℓ − 8 8\ell- 8 8 ℓ − 8 they use with more idle controls. We do not know how to reach 8 ℓ + O ( 1 ) 8\ell+ O(1) 8 ℓ + O ( 1 ) with O ( 1 ) O(1) O ( 1 ) idle controls. The same question is open for exact multi-controlled NOTs with a few borrowed qubits, and an answer there would carry over to the branches directly.
Preliminaries
All logarithms are base 2 unless written as ln, and [ n ] = { 1 , … , n } [n]=\{1,\ldots,n\} [ n ] = { 1 , … , n } . We identify a subset S ⊆ [ n ] S\subseteq[n] S ⊆ [ n ] with its characteristic vector in F 2 n \mathbb{F}_2^n F 2 n , so ∣ S ∣ |S| ∣ S ∣ is also its Hamming weight. We write 1 \mathbf{1} 1 for the all-ones vector and 1 A \mathbf{1}_A 1 A for the indicator function of a set A A A .
For S , x ∈ F 2 n S,x\in\mathbb{F}_2^n S , x ∈ F 2 n , the parity S ⋅ x S\cdot x S ⋅ x is the mod-2 sum of the bits of x x x that S S S selects. The affine functions F 2 n → F 2 \mathbb{F}_2^n\to\mathbb{F}_2 F 2 n → F 2 are the maps x ↦ a ⋅ x ⊕ c x\mapsto a\cdot x\oplus c x ↦ a ⋅ x ⊕ c .
The oracle of a Boolean function f : F 2 n → F 2 f:\mathbb{F}_2^n\to\mathbb{F}_2 f : F 2 n → F 2 acts on n n n input qubits and one target qubit as U f ∣ x ⟩ ∣ b ⟩ = ∣ x ⟩ ∣ b ⊕ f ( x ) ⟩ U_f|x\rangle|b\rangle=|x\rangle|b\oplus f(x)\rangle U f ∣ x ⟩ ∣ b ⟩ = ∣ x ⟩ ∣ b ⊕ f ( x )⟩ . The Toffoli gate Toff n \operatorname{Toff}_n Toff n on n n n qubits is the oracle of the conjunction of n − 1 n-1 n − 1 bits, which are its controls.
Distances and synthesis models
For states ρ , σ \rho,\sigma ρ , σ , the trace distance is D ( ρ , σ ) = 1 2 ∥ ρ − σ ∥ 1 D(\rho,\sigma)=\frac{1}{2}\|\rho-\sigma\|_1 D ( ρ , σ ) = 2 1 ∥ ρ − σ ∥ 1 , where ∥ A ∥ 1 = Tr A † A \|A\|_1=\operatorname{Tr}\sqrt{A^\dagger A} ∥ A ∥ 1 = Tr A † A is the trace norm. We write ∥ A ∥ ∞ \|A\|_\infty ∥ A ∥ ∞ for the operator norm. For channels E , F \mathcal{E},\mathcal{F} E , F , the diamond distance is
D ⋄ ( E , F ) = 1 2 ∥ E − F ∥ ⋄ = max ρ D ( ( E ⊗ I ) ( ρ ) , ( F ⊗ I ) ( ρ ) ) . D_\diamond(\mathcal{E},\mathcal{F})=\frac{1}{2}\|\mathcal{E}-\mathcal{F}\|_\diamond=\max_\rho D\bigl((\mathcal{E}\otimes I)(\rho),(\mathcal{F}\otimes I)(\rho)\bigr). D ⋄ ( E , F ) = 2 1 ∥ E − F ∥ ⋄ = ρ max D ( ( E ⊗ I ) ( ρ ) , ( F ⊗ I ) ( ρ ) ) .
where ρ \rho ρ ranges over states of the channels’ input system and a reference system on which both act as the identity. We abbreviate D ⋄ ( E , U ) = D ⋄ ( E , Φ U ) D_\diamond(\mathcal{E},U)=D_\diamond(\mathcal{E},\Phi_U) D ⋄ ( E , U ) = D ⋄ ( E , Φ U ) , where Φ U ( ρ ) = U ρ U † \Phi_U(\rho)=U\rho U^\dagger Φ U ( ρ ) = U ρ U † .
Definition 6 (mixed implementations). A mixed implementation of U U U is a probability distribution over unitary Clifford+T T T circuits, called branches. Each branch acts on the qubits of U U U and on ancillae that start in ∣ 0 ⟩ |0\rangle ∣0 ⟩ and are discarded at the end. The error of the mixed implementation is the diamond distance of the averaged channel from U U U , and its cost is the largest number of T T T gates on any branch. The minimum cost at diamond error ε \varepsilon ε is T m i x e d ( U ) \mathcal{T}^{\mathrm{mixed}}(U) T mixed ( U ) . Most lower bounds in Section C also hold when the ancillae start in an arbitrary advice state, as stated there.
An ancilla is clean if it starts in ∣ 0 ⟩ |0\rangle ∣0 ⟩ and must be returned to ∣ 0 ⟩ |0\rangle ∣0 ⟩ . It is borrowed (often called dirty) if it may start in any state, even one entangled with the rest of the computation, and must be returned unchanged. A branch with no ancilla acts only on the qubits of U U U , but it may borrow some of them as work qubits.
The next lemma, from GKZ [11 Theorem 12] , bounds the diamond error of a mixture by the largest probability, over all inputs, that a random branch computes that input wrongly. We include its short proof.
Lemma 7 (error from pointwise miss probabilities). Let U U U be a unitary, and for each value of a random variable a a a let Π a \Pi_a Π a be a projector. If
∥ E a Π a ∥ ∞ ≤ p , \left\|\mathbb{E}_a\Pi_a\right\|_\infty\le p, ∥ E a Π a ∥ ∞ ≤ p , then the average of the channels Φ U ( I − 2 Π a ) \Phi_{U(I-2\Pi_a)} Φ U ( I − 2 Π a ) is within diamond distance 4 p 4p 4 p of U U U . In particular, let f f f be Boolean and let g a g_a g a be a random Boolean function. If Pr a [ g a ( x ) ≠ f ( x ) ] ≤ p \Pr_a[g_a(x)\ne f(x)]\le p Pr a [ g a ( x ) = f ( x )] ≤ p for every x x x , then
D ⋄ ( E a Φ U g a , Φ U f ) ≤ 4 p . D_\diamond\bigl(\mathbb{E}_a\Phi_{U_{g_a}},\Phi_{U_f}\bigr)\le4p. D ⋄ ( E a Φ U g a , Φ U f ) ≤ 4 p .
Proof. Each branch applies I − 2 Π a I-2\Pi_a I − 2 Π a and then U U U , and the final U U U does not change trace distances. So it suffices to compare the average of ( I − 2 Π a ) ψ ( I − 2 Π a ) (I-2\Pi_a)\psi(I-2\Pi_a) ( I − 2 Π a ) ψ ( I − 2 Π a ) with ψ \psi ψ . By convexity, the maximum in the diamond distance may be taken over pure inputs, so let ψ \psi ψ be a pure state of the system and the reference. Write Π ‾ = E a Π a \overline{\Pi}=\mathbb{E}_a\Pi_a Π = E a Π a for the averaged projector. Expanding the product gives
E a [ ( I − 2 Π a ) ψ ( I − 2 Π a ) ] − ψ = − 2 Π ‾ ψ − 2 ψ Π ‾ + 4 E a [ Π a ψ Π a ] . \mathbb{E}_a\bigl[(I-2\Pi_a)\psi(I-2\Pi_a)\bigr]-\psi=-2\overline{\Pi}\psi-2\psi\overline{\Pi}+4\mathbb{E}_a[\Pi_a\psi\Pi_a]. E a [ ( I − 2 Π a ) ψ ( I − 2 Π a ) ] − ψ = − 2 Π ψ − 2 ψ Π + 4 E a [ Π a ψ Π a ] .
Since ∥ A B ∥ 1 ≤ ∥ A ∥ ∞ ∥ B ∥ 1 \|AB\|_1 \le\|A\|_\infty\|B\|_1 ∥ A B ∥ 1 ≤ ∥ A ∥ ∞ ∥ B ∥ 1 and ψ \psi ψ has trace norm 1, each of the first two terms has trace norm at most 2 ∥ Π ‾ ∥ ∞ 2\|\overline{\Pi}\|_\infty 2∥ Π ∥ ∞ .
The last term is positive semidefinite, so its trace norm equals its trace. Since Π a 2 = Π a \Pi_a^2=\Pi_a Π a 2 = Π a , this trace is
4 E a Tr ( Π a ψ ) = 4 Tr ( Π ‾ ψ ) ≤ 4 ∥ Π ‾ ∥ ∞ . 4\mathbb{E}_a\operatorname{Tr}(\Pi_a\psi)=4\operatorname{Tr}(\overline{\Pi}\psi)\le4\|\overline{\Pi}\|_\infty. 4 E a Tr ( Π a ψ ) = 4 Tr ( Π ψ ) ≤ 4∥ Π ∥ ∞ .
The difference therefore has trace norm at most 8 ∥ Π ‾ ∥ ∞ ≤ 8 p 8\|\overline{\Pi}\|_\infty\le8p 8∥ Π ∥ ∞ ≤ 8 p , so the two states are at trace distance at most 4 p 4p 4 p . This holds for every pure input ψ \psi ψ , which proves the first statement.
For the second statement, take U = U f U=U_f U = U f and let Π a \Pi_a Π a project onto the inputs where g a g_a g a and f f f differ, with the target in ∣ − ⟩ |-\rangle ∣ − ⟩ :
Π a = ∑ x : g a ( x ) ≠ f ( x ) ∣ x ⟩ ⟨ x ∣ ⊗ ∣ − ⟩ ⟨ − ∣ . \Pi_a=\sum_{x:g_a(x)\ne f(x)}|x\rangle\langle x|\otimes|-\rangle\langle-|. Π a = x : g a ( x ) = f ( x ) ∑ ∣ x ⟩ ⟨ x ∣ ⊗ ∣ − ⟩ ⟨ − ∣.
An oracle U g U_g U g applies X g ( x ) X^{g(x)} X g ( x ) to the target on input x x x . Since X ∣ ± ⟩ = ± ∣ ± ⟩ X|\pm\rangle=\pm|\pm\rangle X ∣ ± ⟩ = ± ∣ ± ⟩ , it is diagonal in the basis ∣ x ⟩ ∣ ± ⟩ |x\rangle|\pm\rangle ∣ x ⟩ ∣ ± ⟩ : it fixes ∣ x ⟩ ∣ + ⟩ |x\rangle|+\rangle ∣ x ⟩ ∣ + ⟩ and multiplies ∣ x ⟩ ∣ − ⟩ |x\rangle|-\rangle ∣ x ⟩ ∣ − ⟩ by ( − 1 ) g ( x ) (-1)^{g(x)} ( − 1 ) g ( x ) . Hence U f † U g a U_f^\dagger U_{g_a} U f † U g a is diagonal too, with entry − 1 -1 − 1 on the range of Π a \Pi_a Π a and 1 1 1 elsewhere, so U g a = U f ( I − 2 Π a ) U_{g_a}=U_f(I-2\Pi_a) U g a = U f ( I − 2 Π a ) . The averaged projector is diagonal, with entry Pr a [ g a ( x ) ≠ f ( x ) ] ≤ p \Pr_a[g_a(x)\ne f(x)]\le p Pr a [ g a ( x ) = f ( x )] ≤ p at ∣ x ⟩ ∣ − ⟩ |x\rangle|-\rangle ∣ x ⟩ ∣ − ⟩ and 0 elsewhere, so its operator norm is at most p p p . The first statement then gives the second. □
Multi-controlled NOTs with borrowed qubits
Write C m X C^mX C m X for the m m m -controlled NOT, which flips its target when all m m m controls are 1. The constructions in Section B use three known circuits for it.
A relative-phase Toffoli gate is a Toffoli gate followed by a diagonal unitary on its three qubits. Maslov gives one with 4 T T T gates, against 7 for the Toffoli gate itself [6 Fig. 3] . Its inverse is the diagonal followed by the Toffoli gate. So when a relative-phase Toffoli gate and its inverse enclose gates that touch its three qubits only as controls, the two diagonals cancel and the pair acts as two exact Toffoli gates.
Borrowed qubits enter through the identity of Figure 4 . A borrowed qubit b b b holds an unknown bit. The target is toggled by x ∧ b x\land b x ∧ b , then b b b is toggled by the AND y y y of other controls, and then the target is toggled by x ∧ b x\land b x ∧ b again. The two toggles of the target differ by x ∧ y x\land y x ∧ y , so the target flips by x ∧ y x\land y x ∧ y whatever b b b held, and a final toggle of b b b by y y y restores it. Applied recursively along a chain, this builds C m X C^mX C m X from 4 ( m − 2 ) 4(m-2) 4 ( m − 2 ) Toffoli gates and m − 2 m-2 m − 2 borrowed qubits [18 Lemma 7.2] . Splitting the controls into two halves, each borrowing the other’s qubits, brings this down to one borrowed qubit and O ( m ) O(m) O ( m ) Toffoli gates [18 Lemma 7.3 and Corollary 7.4] . Only the Toffoli gates that act on the target must be exact, and the others may be relative-phase gates. Maslov also uses relative-phase gates with three controls, so that each borrowed qubit absorbs two controls. For m ≥ 4 m\ge4 m ≥ 4 this gives C m X C^mX C m X with ⌈ ( m − 2 ) / 2 ⌉ \lceil(m-2)/2\rceil ⌈( m − 2 ) /2 ⌉ borrowed qubits and 8 m − 8 8m-8 8 m − 8 T T T gates [6 Proposition 5] . For m = 3 m=3 m = 3 his circuit uses one borrowed qubit and 16 T T T gates [6 Eq. (5)] .
Figure 4. Toggle detection. The target is toggled by x ∧ b x \wedge b x ∧ b before and after b b b is toggled by y y y , so it flips by x ∧ b ⊕ x ∧ ( b ⊕ y ) = x ∧ y x \wedge b \oplus x \wedge(b \oplus y) = x \wedge y x ∧ b ⊕ x ∧ ( b ⊕ y ) = x ∧ y whatever b b b held. The last gate restores b b b .
Zindorf and Bose use a borrowed qubit differently. A rotation by 2 π 2\pi 2 π multiplies every state by − 1 -1 − 1 , so a 2 π 2\pi 2 π rotation of the borrowed qubit, controlled by the m m m controls and the target, is a multi-controlled Z Z Z whatever the borrowed qubit holds. Hadamard gates on the target turn it into C m X C^mX C m X . For m ≥ 5 m\ge5 m ≥ 5 they implement it with 16 ( m + 1 ) − 48 = 16 m − 32 16(m+1)-48=16m-32 16 ( m + 1 ) − 48 = 16 m − 32 T T T gates, and each further borrowed qubit, up to ⌊ ( m − 5 ) / 2 ⌋ \lfloor(m-5)/2\rfloor ⌊( m − 5 ) /2 ⌋ of them, saves 16 T T T gates [9 Theorems 2 and 10] .
Constructions without an ancilla
This appendix gives the constructions without an ancilla: the randomized Toffoli gate in Section B.1 and its extension to exclusive-ors of affine subspaces in Section B.2. Both test a few random parities of the input with one multi-controlled NOT. Inputs that the gate does not use serve as its borrowed work qubits.
The randomized Toffoli gate
Construction 8 (the sampled branch). Put ℓ = ⌈ log ( 4 / ε ) ⌉ \ell= \lceil\log(4/\varepsilon) \rceil ℓ = ⌈ log ( 4/ ε )⌉ and assume ℓ ≤ n − 1 \ell\le n - 1 ℓ ≤ n − 1 . The case ℓ > n − 1 \ell> n - 1 ℓ > n − 1 is the third part of Theorem 11 . Sample linearly independent a 1 , … , a ℓ ∈ F 2 n − 1 a_1,\ldots,a_\ell\in\mathbb{F}_2^{n-1} a 1 , … , a ℓ ∈ F 2 n − 1 by drawing uniformly random tuples until one is independent. Each draw succeeds with probability
Pr [ independent ] = ∏ i = 0 ℓ − 1 ( 1 − 2 i − n + 1 ) ≥ ∏ j = 1 ∞ ( 1 − 2 − j ) > 0.28 , \Pr[\text{independent}] = \prod_{i=0}^{\ell-1}(1-2^{i-n+1}) \ge\prod_{j=1}^{\infty}(1-2^{-j}) > 0.28, Pr [ independent ] = i = 0 ∏ ℓ − 1 ( 1 − 2 i − n + 1 ) ≥ j = 1 ∏ ∞ ( 1 − 2 − j ) > 0.28 ,
so fewer than four draws are needed on average. The branch then acts as follows.
Apply X X X to all n − 1 n-1 n − 1 controls.
Row-reduce a 1 , … , a ℓ a_1,\ldots,a_\ell a 1 , … , a ℓ , which keeps their common kernel, and complete them to a basis a 1 , … , a n − 1 a_1,\ldots,a_{n-1} a 1 , … , a n − 1 of F 2 n − 1 \mathbb{F}_2^{n-1} F 2 n − 1 with unit vectors on the n − 1 − ℓ n-1-\ell n − 1 − ℓ non-pivot coordinates. Apply a CNOT circuit Γ \Gamma Γ for the invertible linear map Γ y = ( a 1 ⋅ y , … , a n − 1 ⋅ y ) \Gamma y=(a_1\cdot y,\ldots,a_{n-1}\cdot y) Γ y = ( a 1 ⋅ y , … , a n − 1 ⋅ y ) , which needs O ( ℓ n ) O(\ell n) O ( ℓ n ) CNOT gates. We call the n − 1 n-1 n − 1 qubits that hold Γ y \Gamma y Γ y the data coordinates.
Apply C ℓ X C^\ell X C ℓ X with the first ℓ \ell ℓ data coordinates as controls, active on 0.
Apply Γ † \Gamma^\dagger Γ † and then the X X X layer again.
On a basis state, with y = x ⊕ 1 y=x\oplus1 y = x ⊕ 1 and g ( y ) = OR j ≤ ℓ ( a j ⋅ y ) g(y)=\operatorname{OR}_{j\le\ell}(a_j\cdot y) g ( y ) = OR j ≤ ℓ ( a j ⋅ y ) , the four steps give
∣ x ⟩ ∣ b ⟩ → 1 ∣ y ⟩ ∣ b ⟩ → 2 ∣ Γ y ⟩ ∣ b ⟩ |x\rangle|b\rangle\xrightarrow{1} |y\rangle|b\rangle\xrightarrow{2} |\Gamma y\rangle|b\rangle ∣ x ⟩ ∣ b ⟩ 1 ∣ y ⟩ ∣ b ⟩ 2 ∣Γ y ⟩ ∣ b ⟩
→ 3 ∣ Γ y ⟩ ∣ b ⊕ 1 ⊕ g ( y ) ⟩ → 4 ∣ x ⟩ ∣ b ⊕ h ( x ) ⟩ , \xrightarrow{3} |\Gamma y\rangle|b\oplus1\oplus g(y)\rangle\xrightarrow{4} |x\rangle|b\oplus h(x)\rangle, 3 ∣Γ y ⟩ ∣ b ⊕ 1 ⊕ g ( y )⟩ 4 ∣ x ⟩ ∣ b ⊕ h ( x )⟩ ,
where h ( x ) = 1 ⊕ g ( x ⊕ 1 ) h(x)=1\oplus g(x\oplus1) h ( x ) = 1 ⊕ g ( x ⊕ 1 ) . Step 3 flips the target exactly when every sampled parity of y y y vanishes, so the branch is the oracle U h U_h U h . It is GKZ’s branch, drawn in Figure 2 . GKZ draw the a j a_j a j uniformly, possibly dependent; the branch depends only on their span, so it can be computed in place either way, and we draw independent vectors only so that the counts below are exact.
Since Γ \Gamma Γ acts in place, no extra register holds the sampled parities. The other n − 1 − ℓ n-1-\ell n − 1 − ℓ data coordinates are idle during step 3, so C ℓ X C^\ell X C ℓ X can borrow them as work qubits.
Proposition 9 (determinants of the Toffoli gate and its branches). Let n ≥ 4 n\ge4 n ≥ 4 .
No Clifford+T T T circuit on the n n n qubits of Toff n \operatorname{Toff}_n Toff n implements it, even up to a global phase.
The oracle U h U_h U h of a branch of Construction 8 has determinant 1 if ℓ ≤ n − 2 \ell\le n-2 ℓ ≤ n − 2 and − 1 -1 − 1 if ℓ = n − 1 \ell=n-1 ℓ = n − 1 .
Proof. Both parts rest on one fact: every Clifford+T T T circuit on N ≥ 4 N\ge4 N ≥ 4 qubits has determinant 1 [5 ] . The determinant is multiplicative, so it suffices to check each gate. A gate G G G on j j j of the N N N qubits acts on the whole register as G ⊗ I G\otimes I G ⊗ I , whose determinant is det ( G ) 2 N − j \det(G)^{2^{N-j}} det ( G ) 2 N − j . The exponent is 2 N − 1 2^{N-1} 2 N − 1 for a one-qubit gate, a multiple of 8, and 2 N − 2 2^{N-2} 2 N − 2 for CNOT, a multiple of 4. With ω = e i π / 4 \omega=e^{i\pi/4} ω = e iπ /4 , the generators have
det T = ω , det S = i , det H = − 1 , det CNOT = − 1 , \det T=\omega,\qquad\det S=i,\qquad\det H=-1,\qquad\det\operatorname{CNOT}=-1, det T = ω , det S = i , det H = − 1 , det CNOT = − 1 ,
and ω 8 = i 8 = ( − 1 ) 8 = ( − 1 ) 4 = 1 \omega^{8}=i^{8}=(-1)^{8}=(-1)^{4}=1 ω 8 = i 8 = ( − 1 ) 8 = ( − 1 ) 4 = 1 . So every gate, and hence every circuit, has determinant 1. For the first part, suppose a circuit implements e i θ Toff n e^{i\theta}\operatorname{Toff}_{n} e i θ Toff n . The gate Toff n \operatorname{Toff}_{n} Toff n swaps ∣ 1 n − 1 , 0 ⟩ \lvert1^{n-1},0\rangle ∣ 1 n − 1 , 0 ⟩ and ∣ 1 n − 1 , 1 ⟩ \lvert1^{n-1},1\rangle ∣ 1 n − 1 , 1 ⟩ and fixes all other basis states, so det Toff n = − 1 \det\operatorname{Toff}_{n}=-1 det Toff n = − 1 and the circuit’s determinant is − e i θ 2 n -e^{i\theta2^{n}} − e i θ 2 n . This must equal 1, so e i θ e^{i\theta} e i θ is a root of unity. It is also the circuit’s matrix entry at ∣ 0 n ⟩ \lvert0^{n}\rangle ∣ 0 n ⟩ , which lies in Z [ 1 / 2 , i ] ⊂ Q ( ω ) \mathbb{Z}[1/\sqrt{2},i]\subset\mathbb{Q}(\omega) Z [ 1/ 2 , i ] ⊂ Q ( ω ) [5 ] , and the only roots of unity in Q ( ω ) \mathbb{Q}(\omega) Q ( ω ) are the powers of ω \omega ω . Hence e i θ = ω k e^{i\theta}=\omega^{k} e i θ = ω k and e i θ 2 n = ω k 2 n = 1 e^{i\theta2^{n}}=\omega^{k2^{n}}=1 e i θ 2 n = ω k 2 n = 1 , since 8 divides 2 n 2^{n} 2 n , a contradiction.
For the second part, U h U_h U h swaps ∣ x , 0 ⟩ \lvert x,0\rangle ∣ x , 0 ⟩ and ∣ x , 1 ⟩ \lvert x,1\rangle ∣ x , 1 ⟩ for each x x x with h ( x ) = 1 h(x)=1 h ( x ) = 1 and fixes all other basis states. It is a product of ∣ h − 1 ( 1 ) ∣ \lvert h^{-1}(1)\rvert ∣ h − 1 ( 1 )∣ disjoint transpositions, so det U h = ( − 1 ) ∣ h − 1 ( 1 ) ∣ \det U_h=(-1)^{\lvert h^{-1}(1)\rvert} det U h = ( − 1 ) ∣ h − 1 ( 1 )∣ . It remains to count these x x x . By Construction 8, h ( x ) = 1 h(x)=1 h ( x ) = 1 exactly when a j ⋅ y = 0 a_j\cdot y=0 a j ⋅ y = 0 for j = 1 , … , ℓ j=1,\ldots,\ell j = 1 , … , ℓ , where y = x ⊕ 1 y=x\oplus1 y = x ⊕ 1 . These are ℓ \ell ℓ independent linear equations, so exactly 2 n − 1 − ℓ 2^{n-1-\ell} 2 n − 1 − ℓ vectors y ∈ F 2 n − 1 y\in\mathbb{F}_2^{n-1} y ∈ F 2 n − 1 satisfy them. Since x ↦ x ⊕ 1 x\mapsto x\oplus1 x ↦ x ⊕ 1 is a bijection, ∣ h − 1 ( 1 ) ∣ = 2 n − 1 − ℓ \lvert h^{-1}(1)\rvert=2^{n-1-\ell} ∣ h − 1 ( 1 )∣ = 2 n − 1 − ℓ . This count is even when ℓ ≤ n − 2 \ell\le n-2 ℓ ≤ n − 2 and equals 1 when ℓ = n − 1 \ell=n-1 ℓ = n − 1 . □
The first part is the standard obstruction [5 , 6 , 28 ] .
Theorem 11 (the randomized Toffoli gate). Let 0 < ε < 1 0<\varepsilon<1 0 < ε < 1 and ℓ = ⌈ log ( 4 / ε ) ⌉ \ell=\lceil\log(4/\varepsilon)\rceil ℓ = ⌈ log ( 4/ ε )⌉ , so ℓ ≥ 3 \ell\ge3 ℓ ≥ 3 . If ℓ ≤ n − 1 \ell\le n-1 ℓ ≤ n − 1 , the branches of Construction 8 form a mixed implementation of Toff n \operatorname{Toff}_{n} Toff n at diamond error ε \varepsilon ε . The cost depends on the number d = n − 1 − ℓ d=n-1-\ell d = n − 1 − ℓ of idle data coordinates:
if n ≥ ⌈ 3 ℓ / 2 ⌉ n\ge\lceil3\ell/2\rceil n ≥ ⌈ 3 ℓ /2 ⌉ , each branch has a circuit with 8 ℓ − 8 8\ell-8 8 ℓ − 8 T T T gates, no ancilla and no measurement;
if ℓ + 2 ≤ n < ⌈ 3 ℓ / 2 ⌉ \ell+2\le n<\lceil3\ell/2\rceil ℓ + 2 ≤ n < ⌈ 3 ℓ /2 ⌉ , each branch has a circuit with 16 ℓ − 16 d − 16 ≤ 16 ℓ − 32 16\ell-16d-16\le16\ell-32 16 ℓ − 16 d − 16 ≤ 16 ℓ − 32 T T T gates, no ancilla and no measurement;
if n ≤ ℓ + 1 n\le\ell+1 n ≤ ℓ + 1 , Toff n \operatorname{Toff}_{n} Toff n has a mixed implementation at diamond error ε \varepsilon ε with one clean ancilla and O ( n ) O(n) O ( n ) T T T gates per branch.
Figure 3 plots the three regimes at ε = 10 − 6 \varepsilon=10^{-6} ε = 1 0 − 6 .
Proof of Theorem 11. For the error, fix an input x x x and let y = x ⊕ 1 y=x\oplus1 y = x ⊕ 1 . By Construction 8, the branch flips the target exactly when a j ⋅ y = 0 a_j\cdot y=0 a j ⋅ y = 0 for every j ≤ ℓ j\le\ell j ≤ ℓ . At y = 0 y=0 y = 0 this always holds, and Toff n \operatorname{Toff}_{n} Toff n flips the target too, so the branch is correct. At y ≠ 0 y\ne0 y = 0 the target Toff n \operatorname{Toff}_{n} Toff n does not flip the target, so the branch errs exactly when every a j a_j a j lies in the hyperplane { a : a ⋅ y = 0 } \{a:a\cdot y=0\} { a : a ⋅ y = 0 } , of dimension n − 2 n-2 n − 2 . A space of dimension k k k contains ∏ i = 0 ℓ − 1 ( 2 k − 2 i ) \prod_{i=0}^{\ell-1}(2^k-2^i) ∏ i = 0 ℓ − 1 ( 2 k − 2 i ) independent ordered ℓ \ell ℓ -tuples, since the i i i th vector must avoid the span of the earlier ones. Comparing k = n − 2 k=n-2 k = n − 2 with k = n − 1 k=n-1 k = n − 1 gives
Pr [ a j ⋅ y = 0 ∀ j ] = ∏ i = 0 ℓ − 1 2 n − 2 − 2 i 2 n − 1 − 2 i ≤ 2 − ℓ , \Pr[a_j\cdot y=0\ \forall j]=\prod_{i=0}^{\ell-1}\frac{2^{n-2}-2^i}{2^{n-1}-2^i}\le2^{-\ell}, Pr [ a j ⋅ y = 0 ∀ j ] = i = 0 ∏ ℓ − 1 2 n − 1 − 2 i 2 n − 2 − 2 i ≤ 2 − ℓ ,
since 2 n − 2 − 2 i ≤ 1 2 ( 2 n − 1 − 2 i ) 2^{n-2}-2^i\le\frac{1}{2}(2^{n-1}-2^i) 2 n − 2 − 2 i ≤ 2 1 ( 2 n − 1 − 2 i ) . So every input is computed wrongly with probability at most 2 − ℓ 2^{-\ell} 2 − ℓ , and Lemma 7 gives diamond error at most 4 ⋅ 2 − ℓ ≤ ε 4\cdot2^{-\ell}\le\varepsilon 4 ⋅ 2 − ℓ ≤ ε .
For the first part, the number of idle data coordinates is d = n − 1 − ℓ ≥ ⌈ 3 ℓ / 2 ⌉ − 1 − ℓ = ⌈ ( ℓ − 2 ) / 2 ⌉ d=n-1-\ell\ge\lceil3\ell/2\rceil-1-\ell=\lceil(\ell-2)/2\rceil d = n − 1 − ℓ ≥ ⌈ 3 ℓ /2 ⌉ − 1 − ℓ = ⌈( ℓ − 2 ) /2 ⌉ . By Section A.2, Maslov’s circuit for C ℓ X C^\ell X C ℓ X needs this many borrowed qubits and uses 8 ℓ − 8 8\ell-8 8 ℓ − 8 T T T gates, including ℓ = 3 \ell=3 ℓ = 3 , where 16 = 8 ℓ − 8 16=8\ell-8 16 = 8 ℓ − 8 . As noted after Construction 8, the idle coordinates can serve as these borrowed qubits. The X X X layers and Γ \Gamma Γ are Clifford, so the branch uses 8 ℓ − 8 8\ell-8 8 ℓ − 8 T T T gates, no ancilla and no measurement.
For the second part, n ≥ ℓ + 2 n\ge\ell+2 n ≥ ℓ + 2 gives d ≥ 1 d\ge1 d ≥ 1 , and n < ⌈ 3 ℓ / 2 ⌉ n<\lceil3\ell/2\rceil n < ⌈ 3 ℓ /2 ⌉ gives d ≤ ⌈ 3 ℓ / 2 ⌉ − 2 − ℓ = ⌊ ( ℓ − 3 ) / 2 ⌋ d\le\lceil3\ell/2\rceil-2-\ell=\lfloor(\ell-3)/2\rfloor d ≤ ⌈ 3 ℓ /2 ⌉ − 2 − ℓ = ⌊( ℓ − 3 ) /2 ⌋ . In particular this range is nonempty only when ℓ ≥ 5 \ell\ge5 ℓ ≥ 5 . Zindorf and Bose’s circuit for C ℓ X C^\ell X C ℓ X (Section A.2) can use the d d d idle coordinates as borrowed qubits, since d − 1 ≤ ⌊ ( ℓ − 5 ) / 2 ⌋ d - 1 \le\lfloor(\ell- 5)/2 \rfloor d − 1 ≤ ⌊( ℓ − 5 ) /2 ⌋ by the bound above. It uses
16 ( ℓ + 1 ) − 16 ( d − 1 ) − 48 = 16 ℓ − 16 d − 16 16(\ell+ 1) - 16(d - 1) - 48 = 16\ell- 16d - 16 16 ( ℓ + 1 ) − 16 ( d − 1 ) − 48 = 16 ℓ − 16 d − 16
T T T gates and is unitary, so the branch needs no ancilla and no measurement. For d = 1 d = 1 d = 1 the count is 16 ℓ − 32 16\ell- 32 16 ℓ − 32 , which Khattar and Gidney also give [7 Table 1] .
For the third part, suppose first that n = ℓ + 1 n = \ell+ 1 n = ℓ + 1 . No data coordinate is then idle, and for n ≥ 4 n \ge4 n ≥ 4 each branch has determinant − 1 -1 − 1 by Proposition 9 , so it cannot be built on its own n n n qubits. We implement its gate C ℓ X C^\ell X C ℓ X by Barenco et al.’s construction with one borrowed qubit (Section A.2), which uses O ( ℓ ) = O ( n ) O(\ell) = O(n) O ( ℓ ) = O ( n ) T T T gates. One clean ancilla serves as that qubit. If n ≤ ℓ n \le\ell n ≤ ℓ , the same construction implements Toff n \operatorname{Toff}_n Toff n exactly with one clean ancilla and O ( n ) O(n) O ( n ) T T T gates. □
Affine decompositions
This subsection extends the branches from the Toffoli gate to exclusive-ors of indicators of affine subspaces. Each term reduces to a multi-controlled NOT, so we first fix its cost. Let c ( m ) c(m) c ( m ) be the T T T -count of Maslov’s circuit for C m X C^m X C m X from Section A.2, which borrows ⌈ ( m − 2 ) / 2 ⌉ \lceil(m - 2)/2 \rceil ⌈( m − 2 ) /2 ⌉ idle qubits. For m ≤ 2 m \le2 m ≤ 2 the gate is a NOT, a CNOT or a Toffoli gate, so c ( 0 ) = c ( 1 ) = 0 c(0) = c(1) = 0 c ( 0 ) = c ( 1 ) = 0 and c ( 2 ) = 7 c(2) = 7 c ( 2 ) = 7 , and c ( m ) = 8 m − 8 c(m) = 8m - 8 c ( m ) = 8 m − 8 for m ≥ 3 m \ge3 m ≥ 3 .
Theorem 12 (affine decompositions). Let 0 < ε < 1 0 < \varepsilon< 1 0 < ε < 1 and f = ⨁ j = 1 J 1 A j f = \bigoplus_{j=1}^{J} 1_{A_j} f = ⨁ j = 1 J 1 A j , where each A j ⊆ F 2 n A_j \subseteq\mathbb{F}_2^n A j ⊆ F 2 n is an affine subspace cut out by r j r_j r j independent affine equations. Put ℓ J = ⌈ log ( 4 J / ε ) ⌉ \ell_J = \lceil\log(4J/\varepsilon) \rceil ℓ J = ⌈ log ( 4 J / ε )⌉ . If n ≥ ⌈ 3 min { r j , ℓ J } / 2 ⌉ − 1 n \ge\lceil3\min\{r_j,\ell_J\}/2 \rceil- 1 n ≥ ⌈ 3 min { r j , ℓ J } /2 ⌉ − 1 for every j j j , then U f U_f U f has a mixed Clifford+T T T implementation at diamond error ε \varepsilon ε with no ancilla, no measurement and
∑ j = 1 J c ( min { r j , ℓ J } ) ≤ 8 J ℓ J \sum_{j=1}^{J} c(\min\{r_j,\ell_J\}) \le8J\ell_J j = 1 ∑ J c ( min { r j , ℓ J }) ≤ 8 J ℓ J T T T gates per branch. The terms with r j ≤ ℓ J r_j \le\ell_J r j ≤ ℓ J are implemented exactly.
The hypothesis matches the first part of Theorem 11 , shifted by one because U f U_f U f has n n n inputs while Toff n \operatorname{Toff}_n Toff n has n − 1 n - 1 n − 1 controls. For n ≥ 3 n \ge3 n ≥ 3 it forces min { r j , ℓ J } < n \min\{r_j,\ell_J\} < n min { r j , ℓ J } < n . So every exact or sampled term is the oracle of an affine subspace of codimension less than n n n , which has an even number of points. By Remark 10 each term then has determinant 1 1 1 , which is why no ancilla is needed even when deg f = n \deg f = n deg f = n .
Proof of Theorem 12 . Write h j = 1 A j h_j = 1_{A_j} h j = 1 A j . Since U g U h = U g ⊕ h U_gU_h = U_{g\oplus h} U g U h = U g ⊕ h , we have U f = U h J ⋯ U h 1 U_f = U_{h_J}\cdots U_{h_1} U f = U h J ⋯ U h 1 , so it suffices to implement each U h j U_{h_j} U h j . Fix j j j , put r = r j r = r_j r = r j , and write A j = { x : B x = c } A_j = \{x : Bx = c\} A j = { x : B x = c } with B B B of full row rank r r r . As in Construction 8, complete the rows of B B B to a basis in the same way and apply the CNOT circuit Γ \Gamma Γ of the resulting invertible map, so that the first r r r data coordinates hold B x Bx B x . An X X X gate on each coordinate i i i with c i = 1 c_i = 1 c i = 1 then makes x ∈ A j x \in A_j x ∈ A j exactly when these r r r coordinates are all 0.
Suppose first that r ≤ ℓ J r \le\ell_J r ≤ ℓ J . Then C r X C^r X C r X on these coordinates, with controls active on 0, flips the target exactly when x ∈ A j x \in A_j x ∈ A j . Undoing the X X X gates and Γ \Gamma Γ gives U h j U_{h_j} U h j exactly with c ( r ) c(r) c ( r ) T T T gates. The circuit for C r X C^r X C r X borrows ⌈ ( r − 2 ) / 2 ⌉ \lceil(r - 2)/2 \rceil ⌈( r − 2 ) /2 ⌉ of the other n − r n - r n − r data coordinates, or none when r ≤ 2 r \le2 r ≤ 2 . There are enough, because the hypothesis n ≥ ⌈ 3 r / 2 ⌉ − 1 n \ge\lceil3r/2 \rceil- 1 n ≥ ⌈ 3 r /2 ⌉ − 1 gives n − r ≥ ⌈ r / 2 ⌉ − 1 = ⌈ ( r − 2 ) / 2 ⌉ n - r \ge\lceil r/2 \rceil- 1 = \lceil(r - 2)/2 \rceil n − r ≥ ⌈ r /2 ⌉ − 1 = ⌈( r − 2 ) /2 ⌉ .
Suppose next that r > ℓ J r > \ell_J r > ℓ J . Write z ∈ F 2 r z \in\mathbb{F}_2^r z ∈ F 2 r for the values of the r r r coordinates, so that x ∈ A j x \in A_j x ∈ A j exactly when z = 0 z = 0 z = 0 . We run the branch of Construction 8 on z z z , with r r r in place of n − 1 n - 1 n − 1 and ℓ J \ell_J ℓ J in place of ℓ \ell ℓ . It samples independent s 1 , … , s ℓ J ∈ F 2 r s_1,\ldots,s_{\ell_J} \in\mathbb{F}_2^r s 1 , … , s ℓ J ∈ F 2 r and moves the parities s k ⋅ z s_k \cdot z s k ⋅ z onto ℓ J \ell_J ℓ J of the coordinates by a CNOT circuit. It then applies C ℓ J X C^{\ell_J}X C ℓ J X with controls active on 0 and undoes the CNOT circuit, the X X X gates and Γ \Gamma Γ . The error computation in the proof of Theorem 11 applies unchanged. The branch is correct when z = 0 z = 0 z = 0 and errs with probability at most 2 − ℓ J 2^{-\ell_J} 2 − ℓ J at each z ≠ 0 z \ne0 z = 0 . By Lemma 7 , the averaged term is within 4 ⋅ 2 − ℓ J ≤ ε / J 4\cdot2^{-\ell_J} \le\varepsilon/J 4 ⋅ 2 − ℓ J ≤ ε / J of U h j U_{h_j} U h j . Its gate C ℓ J X C^{\ell_J}X C ℓ J X costs c ( ℓ J ) c(\ell_J) c ( ℓ J ) T T T gates and borrows ⌈ ( ℓ J − 2 ) / 2 ⌉ \lceil(\ell_J - 2)/2 \rceil ⌈( ℓ J − 2 ) /2 ⌉ of the other n − ℓ J n - \ell_J n − ℓ J data coordinates. There are enough, because n ≥ ⌈ 3 ℓ J / 2 ⌉ − 1 n \ge\lceil3\ell_J/2 \rceil- 1 n ≥ ⌈ 3 ℓ J /2 ⌉ − 1 gives n − ℓ J ≥ ⌈ ( ℓ J − 2 ) / 2 ⌉ n - \ell_J \ge\lceil(\ell_J - 2)/2 \rceil n − ℓ J ≥ ⌈( ℓ J − 2 ) /2 ⌉ .
Choose the randomness of the J J J terms independently. A branch for U f U_f U f is then one branch per term, applied in sequence, and the averaged channel is the composition of the J J J averaged term channels. Each is within ε / J \varepsilon/J ε / J of its U n , j U_{n,j} U n , j . The diamond distance is subadditive under composition, D ⋄ ( E 2 E 1 , F 2 F 1 ) ≤ D ⋄ ( E 1 , F 1 ) + D ⋄ ( E 2 , F 2 ) D_{\diamond}(\mathcal{E}_2\mathcal{E}_1,\mathcal{F}_2\mathcal{F}_1) \le D_{\diamond}(\mathcal{E}_1,\mathcal{F}_1) + D_{\diamond}(\mathcal{E}_2,\mathcal{F}_2) D ⋄ ( E 2 E 1 , F 2 F 1 ) ≤ D ⋄ ( E 1 , F 1 ) + D ⋄ ( E 2 , F 2 ) , so the averaged channel is within ε \varepsilon ε of U f U_f U f . Since c ( m ) ≤ 8 m c(m) \le8m c ( m ) ≤ 8 m , every branch uses at most ∑ j c ( min { r j , ℓ j } ) ≤ 8 J ℓ J \sum_j c(\min\{r_j,\ell_j\}) \le8J\ell_J ∑ j c ( min { r j , ℓ j }) ≤ 8 J ℓ J T T T gates and makes no measurement. It borrows only data coordinates and returns them unchanged, so it needs no ancilla. □ \square □
Every Boolean function has such a decomposition
Every Boolean function has such decompositions, and Theorem 12 applies to each of them.
The algebraic normal form writes f f f as an exclusive-or of monomials ∏ i ∈ S x i \prod_{i\in S}x_i ∏ i ∈ S x i . Each monomial is the indicator of the affine subspace { x : x i = 1 for all i ∈ S } \{x:x_i=1\text{ for all }i\in S\} { x : x i = 1 for all i ∈ S } , of codimension ∣ S ∣ |S| ∣ S ∣ .
Any partition of f − 1 ( 1 ) f^{-1}(1) f − 1 ( 1 ) into affine subspaces gives one, because the exclusive-or of the indicators of disjoint sets is the indicator of their union. Single points give J = ∣ f − 1 ( 1 ) ∣ J=|f^{-1}(1)| J = ∣ f − 1 ( 1 ) ∣ terms of codimension n n n .
The decomposition should be chosen with care. For example, the algebraic normal form of OR n \operatorname{OR}_n OR n has all 2 n − 1 2^n-1 2 n − 1 nonempty monomials, but OR n = 1 ⊕ 1 { 0 } \operatorname{OR}_n=1\oplus1_{\{0\}} OR n = 1 ⊕ 1 { 0 } is a single term of codimension n n n followed by an X X X gate on the target.
The pieces need not be disjoint. The intersection of two affine subspaces is empty or an affine subspace, so 1 A ∪ A ′ = 1 A ⊕ 1 A ′ ⊕ 1 A ∩ A ′ 1_{A\cup A'}=1_A\oplus1_{A'}\oplus1_{A\cap A'} 1 A ∪ A ′ = 1 A ⊕ 1 A ′ ⊕ 1 A ∩ A ′ is again such a decomposition. By Theorem 12 , few terms of small codimension give a cheap oracle. Finding the cheapest decomposition is the minimization of exclusive-or sums of affine products, for which reversible-logic synthesis has heuristics [19 , 30 ] .
A parity decision tree queries one parity of the input at each internal node and outputs a bit at each leaf. A tree of depth D D D with J J J accepting leaves gives such a decomposition. The inputs that reach a leaf satisfy the at most D D D equations along its path, so each nonempty accepting leaf is an affine subspace of codimension at most D D D . Distinct leaves are disjoint, so the second item above applies. Since c c c is nondecreasing, Theorem 12 implements the oracle of the tree’s function with at most J c ( min { D , ℓ J } ) Jc(\min\{D,\ell_J\}) J c ( min { D , ℓ J }) T T T gates and no ancilla when n ≥ ⌈ 3 min { D , ℓ J } / 2 ⌉ − 1 n\ge\lceil3\min\{D,\ell_J\}/2\rceil-1 n ≥ ⌈ 3 min { D , ℓ J } /2 ⌉ − 1 . With workspace, GKZ’s bound in terms of randomized parity decision trees gives O ( J min { D , ℓ J } ) O(J\min\{D,\ell_J\}) O ( J min { D , ℓ J }) [11 Theorem 5] .
Lower bounds
Every bound in this appendix holds for mixtures of unitary Clifford+T T T circuits with any number of ancillae in any advice state. The exceptions are Theorem 18 , Theorem 26 and the bounds with clean ancillae or none in Theorem 28, which need ancillae that start in ∣ 0 ⟩ |0\rangle ∣0 ⟩ .
Most of the bounds go through randomized parity decision trees. A non-adaptive randomized parity decision tree of depth q q q is a parity decision tree, as in Section B.2.1, whose q q q queries are drawn at random and fixed in advance. Formally, it is a probability distribution over pairs consisting of q q q parities of the input and a rule that maps their values to an output bit. It computes f f f with error ε \varepsilon ε if its output equals f ( x ) f(x) f ( x ) with probability at least 1 − ε 1-\varepsilon 1 − ε for every input x x x . Write RPDT ε n a ( f ) \operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f) RPDT ε na ( f ) for the least depth of such a tree. These trees are randomized linear sketches over F 2 \mathbb{F}_2 F 2 [20 ] , and the averaging arguments below are the standard ones from that setting [20 , 21 ] .
GKZ show that T ε m i x e d ( U f ) ≥ RPDT ε n a ( f ) − 1 \mathcal{T}^{\mathrm{mixed}}_{\varepsilon}(U_f)\ge\operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f)-1 T ε mixed ( U f ) ≥ RPDT ε na ( f ) − 1 , even when the ancillae start in an arbitrary advice state [11 Theorem 23 and its proof] . Girish, May, Parham and Yuen recover this reduction by a different technique [25 Eq. (21)] .
The Toffoli gate
Proposition 13 (randomized parity decision trees for OR). For m ≥ 1 m\ge1 m ≥ 1 , 0 ≤ ε < 1 0\le\varepsilon<1 0 ≤ ε < 1 and 0 ≤ q ≤ m 0\le q\le m 0 ≤ q ≤ m , let r q = ( 2 m − q − 1 ) / ( 2 m − 1 ) r_q=(2^{m-q}-1)/(2^m-1) r q = ( 2 m − q − 1 ) / ( 2 m − 1 ) , the probability that a fixed nonzero vector lies in a uniformly random subspace of F 2 m \mathbb{F}_2^m F 2 m of codimension q q q . Then:
RPDT ε n a ( OR m ) = min { q : r q ≤ ε / ( 1 − ε ) } \operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(\operatorname{OR}_m)=\min\{q:r_q\le\varepsilon/(1-\varepsilon)\} RPDT ε na ( OR m ) = min { q : r q ≤ ε / ( 1 − ε )} ;
GKZ’s test of depth min { q : r q ≤ ε } \min\{q:r_q\le\varepsilon\} min { q : r q ≤ ε } computes O R m \mathrm{OR}_m OR m with error ε \varepsilon ε , and this depth exceeds the exact value by at most one when ε ≤ 1 / 2 \varepsilon\le1/2 ε ≤ 1/2 ;
R P D T ε n a ( O R m ) ≥ min { m , log ( ( 1 − ε ) / ε ) } − 1 \mathrm{RPDT}^{\mathrm{na}}_{\varepsilon}(\mathrm{OR}_m)\ge\min\{m,\log((1-\varepsilon)/\varepsilon)\}-1 RPDT ε na ( OR m ) ≥ min { m , log (( 1 − ε ) / ε )} − 1 .
Proof of Proposition 13. For the second part, let q q q satisfy r q ≤ ε r_q\le\varepsilon r q ≤ ε . The test of Construction 8 chooses q q q linearly independent parities uniformly at random and outputs 0 exactly when all of them vanish. Their common kernel V V V is a uniformly random subspace of codimension q q q . The output is correct at x = 0 x=0 x = 0 , and at x ≠ 0 x\ne0 x = 0 it is wrong exactly when x ∈ V x\in V x ∈ V . Invertible linear maps send any nonzero vector to any other and leave the distribution of V V V unchanged, so Pr [ x ∈ V ] \Pr[x\in V] Pr [ x ∈ V ] is the same for every nonzero x x x . Averaging over the 2 m − 1 2^m-1 2 m − 1 nonzero vectors gives
Pr [ x ∈ V ] = ∣ V ∖ { 0 } ∣ 2 m − 1 = 2 m − q − 1 2 m − 1 = r q ≤ ε . \Pr[x\in V]=\frac{\lvert V\setminus\{0\}\rvert}{2^m-1}=\frac{2^{m-q}-1}{2^m-1}=r_q\le\varepsilon. Pr [ x ∈ V ] = 2 m − 1 ∣ V ∖ { 0 }∣ = 2 m − 1 2 m − q − 1 = r q ≤ ε .
For the first part, take a randomized tree of depth q q q with error at most ε \varepsilon ε . We show that r q ≤ ε / ( 1 − ε ) r_q\le\varepsilon/(1-\varepsilon) r q ≤ ε / ( 1 − ε ) . Let μ \mu μ give weight p = r q / ( 1 + r q ) p=r_q/(1+r_q) p = r q / ( 1 + r q ) to 0 and spread the remaining weight 1 − p 1-p 1 − p uniformly over the nonzero inputs. The tree errs with probability at most ε \varepsilon ε on every input, hence also on an input drawn from μ \mu μ . That error is an average over the deterministic trees in its support, so one of them errs with μ \mu μ -probability at most ε \varepsilon ε . Its queries have a common kernel V V V of codimension at most q q q . Every input in V V V gives the same answers, so the tree’s output is constant on V V V . If that output is 1, the tree errs at 0, with μ \mu μ -probability p p p . If it is 0, the tree errs on the at least 2 m − q − 1 2^{m-q}-1 2 m − q − 1 nonzero inputs of V V V , with μ \mu μ -probability at least ( 1 − p ) r q (1-p)r_q ( 1 − p ) r q . The choice of p p p makes these equal,
p = ( 1 − p ) r q = r q 1 + r q , p=(1-p)r_q=\frac{r_q}{1+r_q}, p = ( 1 − p ) r q = 1 + r q r q ,
so either way ε ≥ p = r q / ( 1 + r q ) \varepsilon\ge p=r_q/(1+r_q) ε ≥ p = r q / ( 1 + r q ) , which rearranges to r q ≤ ε / ( 1 − ε ) r_q\le\varepsilon/(1-\varepsilon) r q ≤ ε / ( 1 − ε ) . Since r q r_q r q decreases in q q q , the depth is at least the least q q q with this property.
To see that this depth is attained, let q q q be least with r q ≤ ε / ( 1 − ε ) r_q\le\varepsilon/(1-\varepsilon) r q ≤ ε / ( 1 − ε ) and put β = r q / ( 1 + r q ) \beta=r_q/(1+r_q) β = r q / ( 1 + r q ) , so that β ≤ ε \beta\le\varepsilon β ≤ ε . Consider the tree that outputs 1 with probability β \beta β and otherwise runs GKZ’s test of depth q q q . At 0 it errs only when it outputs 1, with probability β \beta β . At a nonzero input it errs only when the test misses, with probability ( 1 − β ) r q = β (1-\beta)r_q=\beta ( 1 − β ) r q = β . This tree has depth q q q and error β ≤ ε \beta\le\varepsilon β ≤ ε , which proves the first part.
For the gap in the second part, 2 m − q − 1 − 1 ≤ 1 2 ( 2 m − q − 1 ) 2^{m-q-1}-1\le\frac{1}{2}(2^{m-q}-1) 2 m − q − 1 − 1 ≤ 2 1 ( 2 m − q − 1 ) gives r q + 1 ≤ r q / 2 r_{q+1}\le r_q/2 r q + 1 ≤ r q /2 , and ε ≤ 1 / 2 \varepsilon\le1/2 ε ≤ 1/2 gives ε / ( 1 − ε ) ≤ 2 ε \varepsilon/(1-\varepsilon)\le2\varepsilon ε / ( 1 − ε ) ≤ 2 ε . So if q q q is the exact value, then r q + 1 ≤ r q / 2 ≤ ε r_{q+1}\le r_q/2\le\varepsilon r q + 1 ≤ r q /2 ≤ ε , and GKZ’s test needs depth at most q + 1 q+1 q + 1 .
For the third part, put γ = ε / ( 1 − ε ) \gamma=\varepsilon/(1-\varepsilon) γ = ε / ( 1 − ε ) . The condition r q ≤ γ r_q\le\gamma r q ≤ γ is equivalent to 2 m − q ≤ 1 + ( 2 m − 1 ) γ 2^{m-q}\le1+(2^m-1)\gamma 2 m − q ≤ 1 + ( 2 m − 1 ) γ , and the right side is at most 2 max { 1 , 2 m γ } 2\max\{1,2^m\gamma\} 2 max { 1 , 2 m γ } . Taking logarithms, every q q q with r q ≤ γ r_q\le\gamma r q ≤ γ , in particular the exact value, satisfies
q ≥ m − 1 − max { 0 , m + log γ } = min { m , log ( 1 / γ ) } − 1. q\ge m-1-\max\{0,m+\log\gamma\}=\min\{m,\log(1/\gamma)\}-1. q ≥ m − 1 − max { 0 , m + log γ } = min { m , log ( 1/ γ )} − 1.
□ \square □
Since r q ≤ 2 − q r_q\le2^{-q} r q ≤ 2 − q , the second part gives R P D T ε n a ( O R m ) ≤ ⌈ log ( 1 / ε ) ⌉ \mathrm{RPDT}^{\mathrm{na}}_{\varepsilon}(\mathrm{OR}_m)\le\lceil\log(1/\varepsilon)\rceil RPDT ε na ( OR m ) ≤ ⌈ log ( 1/ ε )⌉ . So no lower bound for T o f f n \mathrm{Toff}_n Toff n obtained through the GKZ reduction can exceed ⌈ log ( 1 / ε ) ⌉ − 1 \lceil\log(1/\varepsilon)\rceil-1 ⌈ log ( 1/ ε )⌉ − 1 .
Theorem 14 (lower bound for the Toffoli gate). For n ≥ 2 n\ge2 n ≥ 2 and 0 < ε ≤ 1 / 2 0<\varepsilon\le1/2 0 < ε ≤ 1/2 , every mixed Clifford+T T T implementation of T o f f n \mathrm{Toff}_n Toff n at diamond error ε \varepsilon ε , with any number of ancillae in any advice state, has a branch with at least min { n − 1 , log ( ( 1 − ε ) / ε ) } − 2 \min\{n-1,\log((1-\varepsilon)/\varepsilon)\}-2 min { n − 1 , log (( 1 − ε ) / ε )} − 2 T T T gates.
Proof of Theorem 14 . The Toffoli gate is an OR oracle up to X X X gates,
T o f f n = ( X ⊗ ( n − 1 ) ⊗ I ) U O R n − 1 X ⊗ n , \mathrm{Toff}_n=(X^{\otimes(n-1)}\otimes I) \, U_{\mathrm{OR}_{n-1}} \, X^{\otimes n}, Toff n = ( X ⊗ ( n − 1 ) ⊗ I ) U OR n − 1 X ⊗ n ,
since the target gains 1 ⊕ O R n − 1 ( x ⊕ 1 ) = x 1 ∧ ⋯ ∧ x n − 1 1\oplus\mathrm{OR}_{n-1}(x\oplus1)=x_1\wedge\cdots\wedge x_{n-1} 1 ⊕ OR n − 1 ( x ⊕ 1 ) = x 1 ∧ ⋯ ∧ x n − 1 . The X X X gates are Clifford, so adding them turns a mixed implementation of either gate into one of the other with the same T T T -count and error. The GKZ reduction and the third part of Proposition 13 with m = n − 1 m=n-1 m = n − 1 then give
T ε m i x e d ( T o f f n ) ≥ R P D T ε n a ( O R n − 1 ) − 1 ≥ min { n − 1 , log ( ( 1 − ε ) / ε ) } − 2. \mathcal{T}^{\mathrm{mixed}}_{\varepsilon}(\mathrm{Toff}_n)\ge\mathrm{RPDT}^{\mathrm{na}}_{\varepsilon}(\mathrm{OR}_{n-1})-1\ge\min\{n-1,\log((1-\varepsilon)/\varepsilon)\}-2. T ε mixed ( Toff n ) ≥ RPDT ε na ( OR n − 1 ) − 1 ≥ min { n − 1 , log (( 1 − ε ) / ε )} − 2.
Corollary 15 (within a factor of eight). Let 0 < ε ≤ 1 / 2 0 < \varepsilon\le1/2 0 < ε ≤ 1/2 and ℓ = ⌈ log ( 4 / ε ) ⌉ \ell= \lceil\log(4/\varepsilon) \rceil ℓ = ⌈ log ( 4/ ε )⌉ , and suppose n ≥ ⌈ 3 ℓ / 2 ⌉ n \ge\lceil3\ell/2 \rceil n ≥ ⌈ 3 ℓ /2 ⌉ . Let T ∗ T^* T ∗ be the least branch T T T -count of any mixed implementation of Toff n \operatorname{Toff}_n Toff n at diamond error ε \varepsilon ε , with any ancillae in any advice state. The branches of Theorem 11 use no ancilla and at most 8 T ∗ + 40 8T^* + 40 8 T ∗ + 40 T T T gates.
Proof of Corollary 15 . We compare the lower bound of Theorem 14 with the count 8 ℓ − 8 8\ell- 8 8 ℓ − 8 of Theorem 11 . The hypothesis on n n n gives
n − 1 ≥ ⌈ 3 ℓ / 2 ⌉ − 1 ≥ ℓ ≥ log ( 4 / ε ) ≥ log ( ( 1 − ε ) / ε ) . n - 1 \ge\lceil3\ell/2 \rceil- 1 \ge\ell\ge\log(4/\varepsilon) \ge\log((1-\varepsilon)/\varepsilon). n − 1 ≥ ⌈ 3 ℓ /2 ⌉ − 1 ≥ ℓ ≥ log ( 4/ ε ) ≥ log (( 1 − ε ) / ε ) .
so the minimum in Theorem 14 is log ( ( 1 − ε ) / ε ) \log((1-\varepsilon)/\varepsilon) log (( 1 − ε ) / ε ) . Using 1 − ε ≥ 1 / 2 1-\varepsilon\ge1/2 1 − ε ≥ 1/2 , we get
T ∗ ≥ log ( ( 1 − ε ) / ε ) − 2 ≥ log ( 1 / ε ) − 3. T^* \ge\log((1-\varepsilon)/\varepsilon) - 2 \ge\log(1/\varepsilon) - 3. T ∗ ≥ log (( 1 − ε ) / ε ) − 2 ≥ log ( 1/ ε ) − 3.
Since ℓ ≤ log ( 4 / ε ) + 1 \ell\le\log(4/\varepsilon) + 1 ℓ ≤ log ( 4/ ε ) + 1 , the branches use
8 ℓ − 8 ≤ 8 ( log ( 4 / ε ) + 1 ) − 8 = 8 log ( 1 / ε ) + 16 ≤ 8 ( T ∗ + 3 ) + 16 = 8 T ∗ + 40 8\ell- 8 \le8(\log(4/\varepsilon) + 1) - 8 = 8\log(1/\varepsilon) + 16 \le8(T^* + 3) + 16 = 8T^* + 40 8 ℓ − 8 ≤ 8 ( log ( 4/ ε ) + 1 ) − 8 = 8 log ( 1/ ε ) + 16 ≤ 8 ( T ∗ + 3 ) + 16 = 8 T ∗ + 40
T T T gates. □
For example, at ε = 10 − 10 \varepsilon= 10^{-10} ε = 1 0 − 10 we have ℓ = 36 \ell= 36 ℓ = 36 , and the least n n n with n ≥ ⌈ 3 ℓ / 2 ⌉ n \ge\lceil3\ell/2 \rceil n ≥ ⌈ 3 ℓ /2 ⌉ is 54. There the GKZ reduction with the exact value from Proposition 13 gives a lower bound of 33, while the branches use 280 T T T gates, a ratio of 8.5. The ratio tends to 8 as ε → 0 \varepsilon\to0 ε → 0 .
Oracle branches and exact multi-controlled NOTs
The branches of Construction 8, like those of GKZ’s sampler, each implement an exact oracle. This subsection shows that for such mixtures the cost of Toff n \operatorname{Toff}_n Toff n is pinned to the cost of exact multi-controlled NOTs. Let t ( k ) t(k) t ( k ) be the least T T T -count of a unitary Clifford+T T T circuit that implements C k X C^kX C k X exactly, with any number of clean ancillae and no measurement. Known bounds give k + 1 ≤ t ( k ) ≤ 8 k − 9 k + 1 \le t(k) \le8k - 9 k + 1 ≤ t ( k ) ≤ 8 k − 9 for k ≥ 3 k \ge3 k ≥ 3 [10 Proposition 4.1] , [6 Proposition 4] .
Lemma 16 (steps of t t t ). For every k ≥ 0 k \ge0 k ≥ 0 , t ( k ) ≤ t ( k + 1 ) ≤ t ( k ) + 8 t(k) \le t(k + 1) \le t(k) + 8 t ( k ) ≤ t ( k + 1 ) ≤ t ( k ) + 8 .
Proof. For the first inequality, C k X C^kX C k X is C k + 1 X C^{k+1}X C k + 1 X with one control fixed to 1. So run an optimal circuit for C k + 1 X C^{k+1}X C k + 1 X with that control on a clean ancilla, set to ∣ 1 ⟩ \lvert1\rangle ∣ 1 ⟩ by an X X X gate before the circuit and reset afterwards. This implements C k X C^kX C k X with t ( k + 1 ) t(k + 1) t ( k + 1 ) T T T gates.
For the second inequality, the case k = 0 k = 0 k = 0 holds because t ( 1 ) = 0 t(1) = 0 t ( 1 ) = 0 , as C 1 X C^1X C 1 X is a CNOT. For k ≥ 1 k \ge1 k ≥ 1 , merge two controls a a a , b b b of C k + 1 X C^{k+1}X C k + 1 X into one: write the AND of a a a and b b b into a clean ancilla c c c with a relative-phase Toffoli gate, which uses 4 T T T gates (Section A.2). Then apply an optimal circuit for C k X C^kX C k X with c c c in place of a a a and b b b , and undo the relative-phase gate with 4 more T T T gates. In between, C k X C^kX C k X touches a a a , b b b , c c c only as controls, so the two relative-phase gates act as exact Toffoli gates and c c c returns to ∣ 0 ⟩ \lvert0\rangle ∣ 0 ⟩ . The result implements C k + 1 X C^{k+1}X C k + 1 X with t ( k ) + 8 t(k) + 8 t ( k ) + 8 T T T gates. □
A mixed implementation has oracle branches if each branch implements an oracle U g U_g U g exactly and returns its ancillae to ∣ 0 ⟩ \lvert0\rangle ∣ 0 ⟩ , where the Boolean function g g g may depend on the branch. Write T ε , o r m i x e d \mathcal{T}^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}} T ε , or mixed for the least cost of such an implementation.
Lemma 17 (pointwise errors of oracle branches). If the oracle branches U g a U_{g_a} U g a average to within diamond distance ε \varepsilon ε of U f U_f U f , then Pr a [ g a ( x ) ≠ f ( x ) ] ≤ ε \Pr_a[g_a(x) \ne f(x)] \le\varepsilon Pr a [ g a ( x ) = f ( x )] ≤ ε for every x x x .
Proof. Fix x x x . Each branch returns its ancillae to ∣ 0 ⟩ \lvert0\rangle ∣ 0 ⟩ , so we may ignore them. Take a reference qubit R R R and the input
ψ = ( ∣ x ⟩ ∣ − ⟩ ∣ 0 ⟩ R + ∣ x ⟩ ∣ + ⟩ ∣ 1 ⟩ R ) / 2 . \psi= \left(\lvert x\rangle\lvert-\rangle\lvert0\rangle_R + \lvert x\rangle\lvert+\rangle\lvert1\rangle_R\right)/\sqrt{2}. ψ = ( ∣ x ⟩ ∣ − ⟩ ∣ 0 ⟩ R + ∣ x ⟩ ∣ + ⟩ ∣ 1 ⟩ R ) / 2 .
As in the proof of Lemma 7 , an oracle U g U_g U g multiplies ∣ x ⟩ ∣ − ⟩ \lvert x\rangle\lvert-\rangle ∣ x ⟩ ∣ − ⟩ by ( − 1 ) g ( x ) (-1)^{g(x)} ( − 1 ) g ( x ) and fixes ∣ x ⟩ ∣ + ⟩ \lvert x\rangle\lvert+\rangle ∣ x ⟩ ∣ + ⟩ , so the branch U g a U_{g_a} U g a maps ψ \psi ψ to
ψ a = ( ( − 1 ) g a ( x ) ∣ x , − , 0 ⟩ + ∣ x , + , 1 ⟩ ) / 2 . \psi_a = \left((-1)^{g_a(x)}\lvert x,-,0\rangle+ \lvert x,+,1\rangle\right)/\sqrt{2}. ψ a = ( ( − 1 ) g a ( x ) ∣ x , − , 0 ⟩ + ∣ x , + , 1 ⟩ ) / 2 .
Write ψ f \psi_f ψ f for the ideal output and ρ = E a ψ a ψ a † \rho= \mathbb{E}_a\psi_a\psi_a^\dagger ρ = E a ψ a ψ a † for the averaged output. If g a ( x ) = f ( x ) g_a(x)=f(x) g a ( x ) = f ( x ) then ψ a = ψ f \psi_a=\psi_f ψ a = ψ f . Otherwise the two differ by a relative sign and are orthogonal. Hence ⟨ ψ f ∣ ρ ∣ ψ f ⟩ = Pr a [ g a ( x ) = f ( x ) ] \langle\psi_f\lvert\rho\rvert\psi_f\rangle=\Pr_a[g_a(x)=f(x)] ⟨ ψ f ∣ ρ ∣ ψ f ⟩ = Pr a [ g a ( x ) = f ( x )] . For any projector P P P , D ( σ , ρ ) ≥ Tr P σ − Tr P ρ D(\sigma,\rho)\geq\operatorname{Tr}P\sigma-\operatorname{Tr}P\rho D ( σ , ρ ) ≥ Tr P σ − Tr P ρ , and taking P = ψ f ψ f † P=\psi_f\psi_f^\dagger P = ψ f ψ f † gives
ε ≥ D ( ψ f ψ f † , ρ ) ≥ 1 − ⟨ ψ f ∣ ρ ∣ ψ f ⟩ = Pr a [ g a ( x ) ≠ f ( x ) ] . \varepsilon\geq D(\psi_f\psi_f^\dagger,\rho)\geq1-\langle\psi_f\lvert\rho\rvert\psi_f\rangle=\Pr_a[g_a(x)\ne f(x)]. ε ≥ D ( ψ f ψ f † , ρ ) ≥ 1 − ⟨ ψ f ∣ ρ ∣ ψ f ⟩ = a Pr [ g a ( x ) = f ( x )] .
Together, Lemmas 7 and 17 show that for oracle branches the diamond error is the largest pointwise error up to a factor of 4:
max x Pr a [ g a ( x ) ≠ f ( x ) ] ≤ D ⋄ ≤ 4 max x Pr a [ g a ( x ) ≠ f ( x ) ] . \max_x\Pr_a[g_a(x)\ne f(x)]\leq D_\diamond\leq4\max_x\Pr_a[g_a(x)\ne f(x)]. x max a Pr [ g a ( x ) = f ( x )] ≤ D ⋄ ≤ 4 x max a Pr [ g a ( x ) = f ( x )] .
Theorem 18 (oracle branches and exact multi-controlled NOTs). Let 0 < ε ≤ 1 / 2 0<\varepsilon\leq1/2 0 < ε ≤ 1/2 and n − 1 ≥ ⌈ log ( 4 / ε ) ⌉ n-1\geq\lceil\log(4/\varepsilon)\rceil n − 1 ≥ ⌈ log ( 4/ ε )⌉ . Then
t ( ⌊ log ( ( 1 − ε ) / ε ) ⌋ ) ≤ T ε , o r m i x e d ( Toff n ) ≤ t ( ⌈ log ( 4 / ε ) ⌉ ) . t\left(\left\lfloor\log\left((1-\varepsilon)/\varepsilon\right)\right\rfloor\right)\leq\mathcal{T}^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}}(\operatorname{Toff}_n)\leq t\left(\left\lceil\log(4/\varepsilon)\right\rceil\right). t ( ⌊ log ( ( 1 − ε ) / ε ) ⌋ ) ≤ T ε , or mixed ( Toff n ) ≤ t ( ⌈ log ( 4/ ε ) ⌉ ) . With K = ⌊ log ( 1 / ε ) ⌋ K=\lfloor\log(1/\varepsilon)\rfloor K = ⌊ log ( 1/ ε )⌋ , this gives t ( K ) − 8 ≤ T ε , o r m i x e d ( Toff n ) ≤ t ( K ) + 24 t(K)-8\leq\mathcal{T}^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}}(\operatorname{Toff}_n)\leq t(K)+24 t ( K ) − 8 ≤ T ε , or mixed ( Toff n ) ≤ t ( K ) + 24 , so T ε , o r m i x e d ( Toff n ) / log ( 1 / ε ) \mathcal{T}^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}}(\operatorname{Toff}_n)/\log(1/\varepsilon) T ε , or mixed ( Toff n ) / log ( 1/ ε ) has the same lim inf and lim sup as t ( k ) / k t(k)/k t ( k ) / k when ε → 0 \varepsilon\to0 ε → 0 with n ≥ log ( 4 / ε ) + 1 n\geq\log(4/\varepsilon)+1 n ≥ log ( 4/ ε ) + 1 .
Proof. As in the proof of Theorem 14 , conjugating by X X X gates replaces Toff n \operatorname{Toff}_n Toff n by U f U_f U f with f = OR m f=\operatorname{OR}_m f = OR m and m = n − 1 m=n-1 m = n − 1 . This keeps oracle branches oracle branches and does not change T T T -counts.
For the upper bound, put ℓ = ⌈ log ( 4 / ε ) ⌉ ≤ m \ell=\lceil\log(4/\varepsilon)\rceil\leq m ℓ = ⌈ log ( 4/ ε )⌉ ≤ m and take GKZ’s sampler [11 Theorem 1] , that is, the branch of Construction 8, with its gate C ℓ X C^\ell X C ℓ X implemented by an optimal exact circuit with clean ancillae. Each branch is an oracle and uses t ( ℓ ) t(\ell) t ( ℓ ) T T T gates. By the error computation in the proof of Theorem 11 , every input is wrong with probability at most 2 − ℓ 2^{-\ell} 2 − ℓ , so Lemma 7 gives error at most 4 ⋅ 2 − ℓ ≤ ε 4\cdot2^{-\ell}\leq\varepsilon 4 ⋅ 2 − ℓ ≤ ε .
For the lower bound, take oracle branches U g a U_{g_a} U g a with error ε \varepsilon ε and put γ = ε / ( 1 − ε ) \gamma=\varepsilon/(1-\varepsilon) γ = ε / ( 1 − ε ) . We find a branch that computes OR exactly on a subspace of dimension about log ( 1 / γ ) \log(1/\gamma) log ( 1/ γ ) , and turn it into an exact C w X C^wX C w X . Let Z a = g a − 1 ( 0 ) Z_a=g_a^{-1}(0) Z a = g a − 1 ( 0 ) be the set of inputs that branch a a a rejects. The ideal f f f rejects only 0 0 0 , so Lemma 17 at 0 0 0 and summed over the nonzero inputs gives
Pr a [ 0 ∉ Z a ] ≤ ε and E a ∣ Z a ∖ { 0 } ∣ ≤ ε ( 2 m − 1 ) . \Pr_a[0\notin Z_a]\leq\varepsilon
\qquad\text{and}\qquad
\mathbb{E}_a\lvert Z_a\setminus\{0\}\rvert\leq\varepsilon(2^m-1). a Pr [ 0 ∈ / Z a ] ≤ ε and E a ∣ Z a ∖ { 0 }∣ ≤ ε ( 2 m − 1 ) .
Since ∣ Z a ∖ { 0 } ∣ ≥ 0 \lvert Z_a\setminus\{0\}\rvert\geq0 ∣ Z a ∖ { 0 }∣ ≥ 0 , conditioning on the event 0 ∈ Z a 0\in Z_a 0 ∈ Z a , which has probability at least 1 − ε 1-\varepsilon 1 − ε , raises its expectation by at most a factor 1 / ( 1 − ε ) 1/(1-\varepsilon) 1/ ( 1 − ε ) . Some branch therefore has
0 ∈ Z a and ∣ Z a ∖ { 0 } ∣ ≤ γ ( 2 m − 1 ) . 0\in Z_a
\qquad\text{and}\qquad
\lvert Z_a\setminus\{0\}\rvert\leq\gamma(2^m-1). 0 ∈ Z a and ∣ Z a ∖ { 0 }∣ ≤ γ ( 2 m − 1 ) .
We now look for a subspace W W W of dimension w = ⌊ log ( 1 / γ ) ⌋ w=\lfloor\log(1/\gamma)\rfloor w = ⌊ log ( 1/ γ )⌋ that avoids every nonzero input the branch rejects, that is, with W ∩ Z a = { 0 } W\cap Z_a=\{0\} W ∩ Z a = { 0 } . On such a W W W the branch rejects only 0 0 0 , so in coordinates of W W W it computes OR w \operatorname{OR}_w OR w . Note that w ≤ m w\leq m w ≤ m , since m ≥ log ( 4 / ε ) > log ( 1 / γ ) m\geq\log(4/\varepsilon)>\log(1/\gamma) m ≥ log ( 4/ ε ) > log ( 1/ γ ) .
To find W W W , choose it uniformly at random among subspaces of dimension w w w . By the symmetry argument in the proof of Proposition 13, each nonzero vector lies in W W W with probability ( 2 w − 1 ) / ( 2 m − 1 ) (2^w-1)/(2^m-1) ( 2 w − 1 ) / ( 2 m − 1 ) . The set Z a Z_a Z a has at most γ ( 2 m − 1 ) \gamma(2^m-1) γ ( 2 m − 1 ) nonzero vectors, so the expected number of them in W W W is at most γ ( 2 w − 1 ) < γ 2 w ≤ 1 \gamma(2^w-1)<\gamma2^w\leq1 γ ( 2 w − 1 ) < γ 2 w ≤ 1 , where the last step is the choice of w w w . A count whose expectation is below 1 is 0 for some choice, so some W W W contains no nonzero vector of Z a Z_a Z a . Since 0 ∈ Z a 0 \in Z_a 0 ∈ Z a , this W W W has W ∩ Z a = { 0 } W \cap Z_a = \{0\} W ∩ Z a = { 0 } .
It remains to turn this branch into an exact circuit for C X w C^w_X C X w . Let M M M be an invertible linear map with M ( F 2 w × { 0 } ) = W M(\mathbb{F}_2^w \times\{0\}) = W M ( F 2 w × { 0 }) = W . On w w w controls z z z , a target and m − w m-w m − w clean ancillae, apply the CNOT circuit of M M M , then the branch, then the CNOT circuit of M − 1 M^{-1} M − 1 . The input ( z , 0 m − w ) (z,0^{m-w}) ( z , 0 m − w ) becomes M ( z , 0 ) ∈ W M(z,0) \in W M ( z , 0 ) ∈ W . The branch adds g a ( M ( z , 0 ) ) = OR w ( z ) g_a(M(z,0)) = \operatorname{OR}_w(z) g a ( M ( z , 0 )) = OR w ( z ) to the target and leaves the input register unchanged, and M − 1 M^{-1} M − 1 restores ( z , 0 m − w ) (z,0^{m-w}) ( z , 0 m − w ) . So the circuit implements U OR w U_{\operatorname{OR}_w} U OR w exactly, returns its ancillae to ∣ 0 ⟩ \lvert0\rangle ∣ 0 ⟩ , and uses the branch’s T T T gates, which are at most the cost of the mixture. With X gates as in the proof of Theorem 14 it becomes C X w C^w_X C X w . Hence t ( w ) ≤ T ε , o r m i x e d ( T o f f n ) t(w) \le T^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}}(\mathrm{Toff}_n) t ( w ) ≤ T ε , or mixed ( Toff n ) with w = ⌊ log ( 1 / γ ) ⌋ = ⌊ log ( ( 1 − ε ) / ε ) ⌋ w = \lfloor\log(1/\gamma) \rfloor= \lfloor\log((1-\varepsilon)/\varepsilon) \rfloor w = ⌊ log ( 1/ γ )⌋ = ⌊ log (( 1 − ε ) / ε )⌋ .
For the second statement, ε ≤ 1 / 2 \varepsilon\le1/2 ε ≤ 1/2 gives
⌊ log ( ( 1 − ε ) / ε ) ⌋ ≥ K − 1 and ⌈ log ( 4 / ε ) ⌉ ≤ K + 3. \lfloor\log((1-\varepsilon)/\varepsilon) \rfloor\ge K-1 \qquad\text{and}\qquad\lceil\log(4/\varepsilon) \rceil\le K+3. ⌊ log (( 1 − ε ) / ε )⌋ ≥ K − 1 and ⌈ log ( 4/ ε )⌉ ≤ K + 3.
Since t t t is nondecreasing, the first statement and Lemma 16 give
t ( K ) − 8 ≤ t ( K − 1 ) ≤ T ε , o r m i x e d ( T o f f n ) ≤ t ( K + 3 ) ≤ t ( K ) + 24. t(K)-8 \le t(K-1) \le T^{\mathrm{mixed}}_{\varepsilon,\mathrm{or}}(\mathrm{Toff}_n) \le t(K+3) \le t(K)+24. t ( K ) − 8 ≤ t ( K − 1 ) ≤ T ε , or mixed ( Toff n ) ≤ t ( K + 3 ) ≤ t ( K ) + 24.
As ε → 0 \varepsilon\to0 ε → 0 , K K K runs through all large integers and differs from log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) by less than one. Dividing by log ( 1 / ε ) \log(1/\varepsilon) log ( 1/ ε ) therefore gives the statement about lim inf \liminf lim inf and lim sup . □ \limsup. \square lim sup . □
The distance from affine
The bounds so far concern the Toffoli gate. This subsection bounds every oracle in terms of one number, its distance from the nearest affine function. For an affine a a a , write δ = Pr x [ f ( x ) ≠ a ( x ) ] \delta= \Pr_x[f(x) \ne a(x)] δ = Pr x [ f ( x ) = a ( x )] for the fraction of inputs on which f f f and a a a differ. The distance from affine δ H ( f ) \delta_H(f) δ H ( f ) is the least such δ \delta δ . It is at most 1 / 2 1/2 1/2 , because a a a and a ⊕ 1 a \oplus1 a ⊕ 1 are both affine and one of them agrees with f f f on at least half of the inputs.
Proposition 19 (decision trees and the distance from affine). Let f f f be non-affine, let a a a be affine with δ = Pr x [ f ( x ) ≠ a ( x ) ] ≤ 1 / 2 \delta= \Pr_x[f(x) \ne a(x)] \le1/2 δ = Pr x [ f ( x ) = a ( x )] ≤ 1/2 , and let 0 < ε ≤ 1 / 2 0 < \varepsilon\le1/2 0 < ε ≤ 1/2 . Then
RPDT ε n a ( f ) ≥ min { log ( 1 / δ ) , log ( 1 / ε ) − 1 } − 2. \operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f) \ge\min\{\log(1/\delta),\log(1/\varepsilon)-1\}-2. RPDT ε na ( f ) ≥ min { log ( 1/ δ ) , log ( 1/ ε ) − 1 } − 2. Proof of Proposition 19. We reduce to the function e = f ⊕ a e=f\oplus a e = f ⊕ a , which is 1 only on the small set E = { x : e ( x ) = 1 } E=\{x:e(x)=1\} E = { x : e ( x ) = 1 } , of size ∣ E ∣ = δ 2 n |E|=\delta2^n ∣ E ∣ = δ 2 n . Since f f f is not affine, e e e is neither 0 nor 1, so both E E E and its complement are nonempty. A randomized tree for f f f of depth q q q , plus one query of the parity that defines a a a , is a randomized tree for e e e of depth q + 1 q+1 q + 1 with the same error. Hence
RPDT ε n a ( e ) ≤ RPDT ε n a ( f ) + 1 , \operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(e) \le\operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f)+1, RPDT ε na ( e ) ≤ RPDT ε na ( f ) + 1 , and it suffices to show that every randomized tree for e e e with error at most ε \varepsilon ε has depth q ≥ min { log ( 1 / δ ) , log ( 1 / ε ) − 1 } − 1 q \ge\min\{\log(1/\delta),\log(1/\varepsilon)-1\}-1 q ≥ min { log ( 1/ δ ) , log ( 1/ ε ) − 1 } − 1 .
Take such a tree, and let μ \mu μ put weight 1 / 2 1/2 1/2 uniformly on E E E and weight 1 / 2 1/2 1/2 uniformly on its complement. As in the proof of Proposition 13, some deterministic tree in its support errs with μ \mu μ -probability at most ε \varepsilon ε . Its queries have a common kernel V V V of codimension at most q q q , so its output is constant on each coset C C C of V V V . These cosets are large but meet E E E in few points, so the tree cannot isolate E E E :
If it outputs 1 on some coset C C C , it errs on at the least 2 n − q − δ 2 n 2^{n-q}-\delta2^n 2 n − q − δ 2 n points of C ∖ E C \setminus E C ∖ E , each of μ \mu μ -weight at least 2 − ( n + 1 ) 2^{-(n+1)} 2 − ( n + 1 ) . Its error is then at least
α = 2 − q − δ 2 . \alpha= \frac{2^{-q}-\delta}{2}. α = 2 2 − q − δ . If it outputs 0 everywhere, it errs on all of E E E , with μ \mu μ -probability 1 / 2 ≥ α 1/2 \ge\alpha 1/2 ≥ α .
Either way ε ≥ α \varepsilon\ge\alpha ε ≥ α , which rearranges to
2 − q ≤ 2 ε + δ ≤ 2 max { 2 ε , δ } , that is q ≥ min { log ( 1 / δ ) , log ( 1 / ε ) − 1 } − 1. 2^{-q} \le2\varepsilon+\delta\le2\max\{2\varepsilon,\delta\}, \qquad\text{that is}\qquad q \ge\min\{\log(1/\delta),\log(1/\varepsilon)-1\}-1. 2 − q ≤ 2 ε + δ ≤ 2 max { 2 ε , δ } , that is q ≥ min { log ( 1/ δ ) , log ( 1/ ε ) − 1 } − 1. Combining this with RPDT ε n a ( e ) ≤ RPDT ε n a ( f ) + 1 \operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(e) \le\operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f)+1 RPDT ε na ( e ) ≤ RPDT ε na ( f ) + 1 proves the proposition. \square
Theorem 20 (distance from affine). For every non-affine f f f and 0 < ε ≤ 1 / 2 0 < \varepsilon\le1/2 0 < ε ≤ 1/2 , every mixture of unitary Clifford+T T T circuits that approximates U f U_f U f to diamond error ε \varepsilon ε , with any number of ancillae in any advice state, has a branch with at least min { log ( 1 / δ H ( f ) ) , log ( 1 / ε ) − 1 } − 3 \min\{\log(1/\delta_H(f)),\log(1/\varepsilon)-1\}-3 min { log ( 1/ δ H ( f )) , log ( 1/ ε ) − 1 } − 3 T T T gates.
Proof of Theorem 20. Take an affine a a a attaining δ H ( f ) \delta_H(f) δ H ( f ) , which is at most 1 / 2 1/2 1/2 . The GKZ reduction and Proposition 19 give
T ε m i x e d ( U f ) ≥ RPDT ε n a ( f ) − 1 ≥ min { log ( 1 / δ H ( f ) ) , log ( 1 / ε ) − 1 } − 3. \mathcal{T}^{\mathrm{mixed}}_{\varepsilon}(U_f) \ge\operatorname{RPDT}^{\mathrm{na}}_{\varepsilon}(f)-1 \ge\min\{\log(1/\delta_H(f)),\log(1/\varepsilon)-1\}-3. T ε mixed ( U f ) ≥ RPDT ε na ( f ) − 1 ≥ min { log ( 1/ δ H ( f )) , log ( 1/ ε ) − 1 } − 3.
For the Toffoli gate, the AND of n − 1 n-1 n − 1 bits differs from the constant 0 0 0 only at the all-ones input, so δ H = 2 1 − n \delta_H=2^{1-n} δ H = 2 1 − n and Theorem 20 recovers Theorem 14 up to an additive constant. The bound is tight up to a factor of eight whenever f f f differs from an affine function on a single affine subspace, as the next corollary shows.
Corollary 21 (one exceptional subspace). Let f = a ⊕ 1 A f=a\oplus1_A f = a ⊕ 1 A , where a a a is affine and A A A is an affine subspace of codimension r ≥ 2 r\ge2 r ≥ 2 . Let 0 < ε ≤ 1 / 2 0<\varepsilon\le1/2 0 < ε ≤ 1/2 and ℓ = ⌈ log ( 4 / ε ) ⌉ \ell=\lceil\log(4/\varepsilon)\rceil ℓ = ⌈ log ( 4/ ε )⌉ , and let T ∗ T^* T ∗ be the least branch T T T -count of any mixture of unitary circuits that approximates U f U_f U f to diamond error ε \varepsilon ε , with any ancillae in any advice state. Then:
min { r , log ( 1 / ε ) − 1 } − 3 ≤ T ∗ ≤ 8 min { r , ℓ } − 8 \min\{r,\log(1/\varepsilon)-1\}-3\le T^*\le8\min\{r,\ell\}-8 min { r , log ( 1/ ε ) − 1 } − 3 ≤ T ∗ ≤ 8 min { r , ℓ } − 8 ;
when n ≥ ⌈ 3 min { r , ℓ } / 2 ⌉ − 1 n\ge\lceil3\min\{r,\ell\}/2\rceil-1 n ≥ ⌈ 3 min { r , ℓ } /2 ⌉ − 1 , the upper bound is attained with no ancilla and no measurement, and this construction uses at most 8 T ∗ + 48 8T^*+48 8 T ∗ + 48 T T T gates;
T ∗ = Θ ( log ( 1 / max { 2 − r , ε } ) ) T^*=\Theta(\log(1/\max\{2^{-r},\varepsilon\})) T ∗ = Θ ( log ( 1/ max { 2 − r , ε })) as min { r , log ( 1 / ε ) } → ∞ \min\{r,\log(1/\varepsilon)\}\to\infty min { r , log ( 1/ ε )} → ∞ .
Proof of Corollary 21. For the lower bound in the first part, f f f differs from a a a exactly on A A A , so δ H ( f ) ≤ 2 − r \delta_H(f)\le2^{-r} δ H ( f ) ≤ 2 − r . Also f f f is not affine: two distinct affine functions differ on half of the inputs or on all of them, while f f f differs from a a a on a fraction 2 − r ≤ 1 / 4 2^{-r}\le1/4 2 − r ≤ 1/4 . Theorem 20 then gives the lower bound, since log ( 1 / δ H ( f ) ) ≥ r \log(1/\delta_H(f))\ge r log ( 1/ δ H ( f )) ≥ r .
For the upper bound and the second part, U f = U a U 1 A U_f=U_aU_{1_A} U f = U a U 1 A , where U a U_a U a is a CNOT circuit, possibly with an X X X on the target. It is Clifford, so only U 1 A U_{1_A} U 1 A costs T T T gates. When n ≥ ⌈ 3 min { r , ℓ } / 2 ⌉ − 1 n\ge\lceil3\min\{r,\ell\}/2\rceil-1 n ≥ ⌈ 3 min { r , ℓ } /2 ⌉ − 1 , Theorem 12 with J = 1 J=1 J = 1 implements U 1 A U_{1_A} U 1 A with no ancilla and no measurement, using
c ( min { r , ℓ } ) ≤ 8 min { r , ℓ } − 8 c(\min\{r,\ell\})\le8\min\{r,\ell\}-8 c ( min { r , ℓ }) ≤ 8 min { r , ℓ } − 8
T T T gates, since c ( m ) ≤ 8 m − 8 c(m)\le8m-8 c ( m ) ≤ 8 m − 8 for m ≥ 2 m\ge2 m ≥ 2 . For smaller n n n the same circuits work with ⌈ ( min { r , ℓ } − 2 ) / 2 ⌉ \lceil(\min\{r,\ell\}-2)/2\rceil ⌈( min { r , ℓ } − 2 ) /2 ⌉ clean ancillae as their borrowed qubits, which T ∗ T^* T ∗ allows.
For the factor of eight in the second part, write L = min { r , log ( 1 / ε ) − 1 } − 3 L=\min\{r,\log(1/\varepsilon)-1\}-3 L = min { r , log ( 1/ ε ) − 1 } − 3 for the lower bound. Since ℓ ≤ log ( 1 / ε ) + 3 \ell\le\log(1/\varepsilon)+3 ℓ ≤ log ( 1/ ε ) + 3 ,
min { r , ℓ } ≤ min { r , log ( 1 / ε ) + 3 } ≤ L + 7 , \min\{r,\ell\}\le\min\{r,\log(1/\varepsilon)+3\}\le L+7, min { r , ℓ } ≤ min { r , log ( 1/ ε ) + 3 } ≤ L + 7 ,
and the construction uses at most 8 ( L + 7 ) − 8 = 8 L + 48 ≤ 8 T ∗ + 48 8(L+7)-8=8L+48\le8T^*+48 8 ( L + 7 ) − 8 = 8 L + 48 ≤ 8 T ∗ + 48 T T T gates. For the third part, both sides of the first part are Θ ( min { r , log ( 1 / ε ) } ) \Theta(\min\{r,\log(1/\varepsilon)\}) Θ ( min { r , log ( 1/ ε )}) , and min { r , log ( 1 / ε ) } = log ( 1 / max { 2 − r , ε } ) \min\{r,\log(1/\varepsilon)\}=\log(1/\max\{2^{-r},\varepsilon\}) min { r , log ( 1/ ε )} = log ( 1/ max { 2 − r , ε }) .
Toffoli gates, membership oracles of linear codes and all their affine shifts have this form. Each such U f U_f U f equals C r X C^rX C r X up to Clifford gates, so an exact implementation needs at least r + 1 r+1 r + 1 T T T gates [10 ] , while the exact constructions of Section 3 use about 8 r 8r 8 r .
Random exceptional sets
Two oracles at the same distance from affine can have very different costs. At constant error, the indicator of an affine subspace of codimension k k k is at distance about 2 − k 2^{-k} 2 − k from affine and costs O ( 1 ) O(1) O ( 1 ) T T T gates (Corollary 21). A random set R R R of the same density is at the same distance, but we show that it costs far more, in two steps.
Decision trees. A random set meets every coset of every subspace of small codimension in about its expected proportion. A shallow tree, whose output is constant on such cosets, then cannot separate R R R from its complement, so it needs depth close to n − k n-k n − k Theorem 24 . This adapts the affine-extractor argument of Kannan et al. [20, Lemmas B.2 and B.6]. As in Proposition 19, giving R R R half the weight keeps the error constant at every density.
Counting. Circuits with few T T T gates have few possible acceptance probabilities, too few to single out most sets of density 2 − k 2^{-k} 2 − k . So random sets need exponentially many T T T gates Theorem 26 , far more than decision trees can certify.
For R ⊆ F 2 n R \subseteq\mathbb{F}_2^n R ⊆ F 2 n with R R R and its complement nonempty, let μ R \mu_R μ R give weight 1 / 2 1/2 1/2 uniformly to R R R and weight 1 / 2 1/2 1/2 uniformly to its complement.
Lemma 22 (equidistribution on cosets). Let V ⊆ F 2 n V \subseteq\mathbb{F}_2^n V ⊆ F 2 n be a subspace of codimension q q q , let 0 < p ≤ 1 / 2 0 < p \le1/2 0 < p ≤ 1/2 and 0 ≤ η < 1 0 \le\eta< 1 0 ≤ η < 1 , and suppose ∣ ∣ C ∩ R ∣ − p ∣ C ∣ ∣ ≤ η p ∣ C ∣ ||C \cap R| - p|C|| \le\eta p|C| ∣∣ C ∩ R ∣ − p ∣ C ∣∣ ≤ η p ∣ C ∣ for every coset C C C of V V V . Then every rule that is constant on the cosets of V V V disagrees with 1 R \mathbf{1}_R 1 R with μ R \mu_R μ R -probability at least 1 2 − η 1 − η 2 \frac{1}{2} - \frac{\eta}{1-\eta^2} 2 1 − 1 − η 2 η .
Proof. Each coset receives nearly the same share of R R R as of its complement, so a rule that is constant on cosets cannot tell the two halves of μ R \mu_R μ R apart.
First, μ R \mu_R μ R is well defined. Summing the hypothesis over the 2 q 2^q 2 q cosets gives ∣ R ∣ ∈ [ 1 − η , 1 + η ] p 2 n |R| \in[1-\eta,1+\eta]p2^n ∣ R ∣ ∈ [ 1 − η , 1 + η ] p 2 n , so R R R is nonempty. Each coset has ∣ C ∖ R ∣ ≥ ( 1 − p − η p ) ∣ C ∣ > 0 |C \setminus R| \ge(1-p-\eta p)|C| > 0 ∣ C ∖ R ∣ ≥ ( 1 − p − η p ) ∣ C ∣ > 0 , so the complement of R R R is nonempty too.
Let
a C = ∣ C ∩ R ∣ ∣ R ∣ and b C = ∣ C ∖ R ∣ ∣ F 2 n ∖ R ∣ . a_C = \frac{|C \cap R|}{|R|}
\qquad\text{and}\qquad
b_C = \frac{|C \setminus R|}{|\mathbb{F}_2^n \setminus R|}. a C = ∣ R ∣ ∣ C ∩ R ∣ and b C = ∣ F 2 n ∖ R ∣ ∣ C ∖ R ∣ .
be the fractions of R R R and of its complement that lie in C C C . The hypothesis and the bound on ∣ R ∣ |R| ∣ R ∣ give a C ∈ 2 − q [ 1 − η 1 + η , 1 + η 1 − η ] a_C \in2^{-q}\left[\frac{1-\eta}{1+\eta},\frac{1+\eta}{1-\eta}\right] a C ∈ 2 − q [ 1 + η 1 − η , 1 − η 1 + η ] . The same holds for b C b_C b C , because ∣ C ∖ R ∣ |C \setminus R| ∣ C ∖ R ∣ and ∣ F 2 n ∖ R ∣ |\mathbb{F}_2^n \setminus R| ∣ F 2 n ∖ R ∣ are within relative error η p / ( 1 − p ) ≤ η \eta p/(1-p) \le\eta η p / ( 1 − p ) ≤ η of ( 1 − p ) ∣ C ∣ (1-p)|C| ( 1 − p ) ∣ C ∣ and ( 1 − p ) 2 n (1-p)2^n ( 1 − p ) 2 n . Both lie in the same interval of length 2 − q ⋅ 4 η 1 − η 2 2^{-q}\cdot\frac{4\eta}{1-\eta^2} 2 − q ⋅ 1 − η 2 4 η , and hence
∣ a C − b C ∣ ≤ 2 − q ⋅ 4 η 1 − η 2 . |a_C-b_C| \le2^{-q}\cdot\frac{4\eta}{1-\eta^2}. ∣ a C − b C ∣ ≤ 2 − q ⋅ 1 − η 2 4 η .
On a coset C C C the rule errs with μ R \mu_R μ R -probability a C / 2 a_C/2 a C /2 if it outputs 0 there and b C / 2 b_C/2 b C /2 if it outputs 1. Using ∑ C a C = ∑ C b C = 1 \sum_C a_C=\sum_C b_C=1 ∑ C a C = ∑ C b C = 1 and summing over the 2 q 2^q 2 q cosets, the rule errs with probability at least
1 2 ∑ C min { a C , b C } = 1 2 ( 1 − 1 2 ∑ C ∣ a C − b C ∣ ) ≥ 1 2 − η 1 − η 2 . \frac{1}{2}\sum_C\min\{a_C,b_C\}
=\frac{1}{2}\left(1-\frac{1}{2}\sum_C|a_C-b_C|\right)
\ge\frac{1}{2}-\frac{\eta}{1-\eta^2}. 2 1 C ∑ min { a C , b C } = 2 1 ( 1 − 2 1 C ∑ ∣ a C − b C ∣ ) ≥ 2 1 − 1 − η 2 η .
Lemma 23 (from cosets to decision trees). If the hypothesis of Lemma 22 holds with η ≤ 1 / 5 \eta\le1/5 η ≤ 1/5 for every subspace of codimension exactly q ≤ n q \le n q ≤ n , then RPDT ε n a ( 1 R ) ≥ q + 1 \operatorname{RPDT}^{\mathrm{na}}_\varepsilon(\mathbf{1}_R) \ge q+1 RPDT ε na ( 1 R ) ≥ q + 1 and T ε m i x e d ( U 1 R ) ≥ q \mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{\mathbf{1}_R}) \ge q T ε mixed ( U 1 R ) ≥ q for every ε ≤ 1 / 4 \varepsilon\le1/4 ε ≤ 1/4 , with any ancillae in any advice state.
Proof. Suppose a randomized tree of depth at most q q q has error at most ε \varepsilon ε . Averaging over μ R \mu_R μ R , some deterministic tree in its support errs with μ R \mu_R μ R -probability at most ε \varepsilon ε . Its queries have a common kernel V ′ V' V ′ of codimension at most q q q , and its output is constant on the cosets of V ′ V' V ′ . It is then also constant on the cosets of any subspace V ⊆ V ′ V \subseteq V' V ⊆ V ′ of codimension exactly q q q . The bound of Lemma 22 decreases in η \eta η , so applying it to V V V with η ≤ 1 / 5 \eta\le1/5 η ≤ 1/5 bounds the error below by
1 2 − 1 / 5 1 − 1 / 25 = 1 2 − 1 24 = 5 24 > 1 4 ≥ ε , \frac{1}{2}-\frac{1/5}{1-1/25}
=\frac{1}{2}-\frac{1}{24}
=\frac{5}{24}
>\frac{1}{4}\ge\varepsilon, 2 1 − 1 − 1/25 1/5 = 2 1 − 24 1 = 24 5 > 4 1 ≥ ε ,
a contradiction. Hence RPDT ε n a ( 1 R ) ≥ q + 1 \operatorname{RPDT}^{\mathrm{na}}_\varepsilon(\mathbf{1}_R) \ge q+1 RPDT ε na ( 1 R ) ≥ q + 1 , and the GKZ reduction gives T ε m i x e d ( U 1 R ) ≥ q \mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{\mathbf{1}_R}) \ge q T ε mixed ( U 1 R ) ≥ q .
Theorem 24 (random exceptional sets). Let n ≥ 2 n \ge2 n ≥ 2 and 1 ≤ k ≤ n 1 \le k \le n 1 ≤ k ≤ n , and let s ≥ 0 s \ge0 s ≥ 0 be an integer with q = n − k − s ≥ 0 q = n-k-s \ge0 q = n − k − s ≥ 0 and
2 s ≥ 52 ( q ( k + s + 1 ) + n + 3 ) . (3) 2^s \ge52\bigl(q(k+s+1)+n+3\bigr). \tag*{(3)} 2 s ≥ 52 ( q ( k + s + 1 ) + n + 3 ) . (3) Let R ⊆ F 2 n R \subseteq\mathbb{F}_2^n R ⊆ F 2 n contain each point independently with probability 2 − k 2^{-k} 2 − k , or be a uniformly random set of size 2 n − k 2^{n-k} 2 n − k . With probability at least 1 − 2 − n 1-2^{-n} 1 − 2 − n , every coset C C C of every subspace of codimension at most q q q satisfies ∣ C ∩ R ∣ = ( 1 ± 1 5 ) 2 − k ∣ C ∣ |C \cap R| = (1 \pm\frac{1}{5})2^{-k}|C| ∣ C ∩ R ∣ = ( 1 ± 5 1 ) 2 − k ∣ C ∣ . On this event, for every ε ≤ 1 / 4 \varepsilon\le1/4 ε ≤ 1/4 ,
RPDT ε n a ( 1 R ) ≥ n − k − s + 1 and T ε m i x e d ( U 1 R ) ≥ n − k − s , \operatorname{RPDT}^{\mathrm{na}}_\varepsilon(\mathbf{1}_R) \ge n-k-s+1
\qquad\text{and}\qquad
\mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{1_R}) \ge n-k-s, RPDT ε na ( 1 R ) ≥ n − k − s + 1 and T ε mixed ( U 1 R ) ≥ n − k − s , the latter for mixtures of unitary Clifford+T T T circuits with any ancillae in any advice state. If moreover k ≥ 2 k \ge2 k ≥ 2 and q ≥ 1 q \ge1 q ≥ 1 , then also δ H ( 1 R ) = ∣ R ∣ / 2 n ∈ [ 4 5 , 6 5 ] 2 − k \delta_H(\mathbf{1}_R)=|R|/2^n \in[\frac{4}{5},\frac{6}{5}]2^{-k} δ H ( 1 R ) = ∣ R ∣/ 2 n ∈ [ 5 4 , 5 6 ] 2 − k . Condition (1) holds for s = ⌈ 2 log ( n + 1 ) ⌉ + 6 s=\lceil2\log(n+1)\rceil+6 s = ⌈ 2 log ( n + 1 )⌉ + 6 , and also for some s = log n + log ( k + log n ) + O ( 1 ) s=\log n+\log(k+\log n)+O(1) s = log n + log ( k + log n ) + O ( 1 ) .
Proof. Fix a subspace V V V of codimension exactly q q q and a coset C C C of V V V . Then ∣ C ∣ = 2 n − q |C|=2^{n-q} ∣ C ∣ = 2 n − q , and X = ∣ C ∩ R ∣ X=|C\cap R| X = ∣ C ∩ R ∣ has mean 2 n − q − k = 2 s 2^{n-q-k}=2^s 2 n − q − k = 2 s . For independent inclusion, X X X is binomial. For a uniformly random set of fixed size it is hypergeometric, which satisfies the same Chernoff bounds [38 Theorem 4] . In both cases
Pr [ ∣ X − 2 s ∣ > 2 s / 5 ] ≤ 2 e − 2 s / 75 . \Pr\left[|X-2^s|>2^s/5\right]\le2e^{-2^s/75}. Pr [ ∣ X − 2 s ∣ > 2 s /5 ] ≤ 2 e − 2 s /75 .
The number of subspaces of codimension q q q is a Gaussian binomial coefficient, at most 2 q ( n − q ) ∏ i ≥ 1 ( 1 − 2 − i ) − 1 < 4 ⋅ 2 q ( n − q ) 2^{q(n-q)}\prod_{i\ge1}(1-2^{-i})^{-1}<4\cdot2^{q(n-q)} 2 q ( n − q ) ∏ i ≥ 1 ( 1 − 2 − i ) − 1 < 4 ⋅ 2 q ( n − q ) , and each has 2 q 2^q 2 q cosets. The probability that some coset fails is therefore at most
8 ⋅ 2 q ( n − q + 1 ) e − 2 s / 75 ≤ 2 − n . 8\cdot2^{q(n-q+1)}e^{-2^s/75}\le2^{-n}. 8 ⋅ 2 q ( n − q + 1 ) e − 2 s /75 ≤ 2 − n .
The last inequality is (1) after taking logarithms, since n − q = k + s n-q=k+s n − q = k + s and 75 ln 2 < 52 75\ln2<52 75 ln 2 < 52 . Every coset of a subspace of codimension q ′ < q q'<q q ′ < q is a disjoint union of cosets of a subspace of codimension q q q contained in it. The estimate therefore extends to all codimensions at most q q q . Lemma 23 with p = 2 − k p=2^{-k} p = 2 − k and η = 1 / 5 \eta=1/5 η = 1/5 gives the bounds on RPDT n a \operatorname{RPDT}^{\mathrm{na}} RPDT na and T m i x e d \mathcal{T}^{\mathrm{mixed}} T mixed .
For the distance, the case q ′ = 0 q'=0 q ′ = 0 gives ∣ R ∣ / 2 n ∈ [ 4 5 , 6 5 ] 2 − k |R|/2^n\in[\frac{4}{5},\frac{6}{5}]2^{-k} ∣ R ∣/ 2 n ∈ [ 5 4 , 5 6 ] 2 − k , which is the distance to the constant 0 0 0 . A non-constant affine a a a splits F 2 n \mathbb{F}_2^n F 2 n into the hyperplane cosets H 0 = a − 1 ( 0 ) H_0=a^{-1}(0) H 0 = a − 1 ( 0 ) and H 1 = a − 1 ( 1 ) H_1=a^{-1}(1) H 1 = a − 1 ( 1 ) . The case q ′ = 1 q'=1 q ′ = 1 gives ∣ R ∩ H 0 ∣ − ∣ R ∩ H 1 ∣ ≥ − 1 5 2 n − k − 2 |R\cap H_0|-|R\cap H_1|\ge-\frac{1}{5}2^{n-k-2} ∣ R ∩ H 0 ∣ − ∣ R ∩ H 1 ∣ ≥ − 5 1 2 n − k − 2 . When k ≥ 2 k\ge2 k ≥ 2 , it follows that
Pr x [ 1 R ( x ) ≠ a ( x ) ] = 1 2 + ∣ R ∩ H 0 ∣ − ∣ R ∩ H 1 ∣ 2 n ≥ 1 2 − 1 20 > 6 5 ⋅ 1 4 , \Pr_x[\mathbf{1}_R(x)\ne a(x)]
=\frac{1}{2}+\frac{|R\cap H_0|-|R\cap H_1|}{2^n}
\ge\frac{1}{2}-\frac{1}{20}>\frac{6}{5}\cdot\frac{1}{4}, x Pr [ 1 R ( x ) = a ( x )] = 2 1 + 2 n ∣ R ∩ H 0 ∣ − ∣ R ∩ H 1 ∣ ≥ 2 1 − 20 1 > 5 6 ⋅ 4 1 ,
so a a a is farther from 1 R \mathbf{1}_R 1 R than the constant 0 0 0 . The constant 1 1 1 is farther still.
For the choices of s s s , since q + ( k + s + 1 ) = n + 1 q+(k+s+1)=n+1 q + ( k + s + 1 ) = n + 1 , we have q ( k + s + 1 ) ≤ ( n + 1 ) 2 / 4 q(k+s+1)\le(n+1)^2/4 q ( k + s + 1 ) ≤ ( n + 1 ) 2 /4 . For s = ⌈ 2 log ( n + 1 ) ⌉ + 6 s=\lceil2\log(n+1)\rceil+6 s = ⌈ 2 log ( n + 1 )⌉ + 6 and n ≥ 2 n\ge2 n ≥ 2 ,
2 s ≥ 64 ( n + 1 ) 2 ≥ 13 ( n + 1 ) 2 + 52 ( n + 3 ) ≥ 52 ( q ( k + s + 1 ) + n + 3 ) . 2^s\ge64(n+1)^2\ge13(n+1)^2+52(n+3)\ge52\bigl(q(k+s+1)+n+3\bigr). 2 s ≥ 64 ( n + 1 ) 2 ≥ 13 ( n + 1 ) 2 + 52 ( n + 3 ) ≥ 52 ( q ( k + s + 1 ) + n + 3 ) .
Since q ≤ n q\le n q ≤ n , (1) also holds once 2 s ≥ 52 ( n ( k + s + 1 ) + n + 3 ) 2^s\ge52\bigl(n(k+s+1)+n+3\bigr) 2 s ≥ 52 ( n ( k + s + 1 ) + n + 3 ) , which is satisfied by some s = log n + log ( k + log n ) + O ( 1 ) s=\log n+\log(k+\log n)+O(1) s = log n + log ( k + log n ) + O ( 1 ) . □
Like the canonical-form count of Gosset, Kothari and Wu [16 Lemma 4.8] , the first bound in the following count does not depend on the number of ancillae.
Lemma 25 (few acceptance functions). Let U U U be a unitary Clifford+T T T circuit with at most t t t T T T gates on n n n input qubits, a target qubit and a a a ancillae, and let p U ( x ) p_U(x) p U ( x ) be the probability that measuring the target of U ∣ x ⟩ ∣ 0 ⟩ ⊗ a U|x\rangle|0\rangle^{\otimes a} U ∣ x ⟩ ∣0 ⟩ ⊗ a gives 1 1 1 . As U U U ranges over all such circuits, there are at most 2 ( t + 1 ) min { 2 t + n + 3 , 2 ( n + a ) + 3 } 2^{(t+1)\min\{2t+n+3,2(n+a)+3\}} 2 ( t + 1 ) m i n { 2 t + n + 3 , 2 ( n + a ) + 3 } distinct functions p U : F 2 n → [ 0 , 1 ] p_U:\mathbb{F}_2^n\to[0,1] p U : F 2 n → [ 0 , 1 ] .
Proof. The function p U p_U p U depends on U U U only through a little combinatorial data about the Pauli rotations in U U U , and we count that data. Up to a global phase, U = C R ( P t ) ⋯ R ( P 1 ) U=C\,R(P_t)\cdots R(P_1) U = C R ( P t ) ⋯ R ( P 1 ) with a Clifford C C C , Hermitian Paulis P j P_j P j and R ( P ) = exp ( − i π P / 8 ) R(P)=\exp(-i\pi P/8) R ( P ) = exp ( − iπ P /8 ) [39 ] , [11 proof of Lemma 22] . A circuit with fewer T T T gates is padded with P j = I P_j=I P j = I . Let Π \Pi Π project the target onto ∣ 1 ⟩ |1\rangle ∣1 ⟩ , put Q 0 = C † Z t g t C Q_0=C^\dagger Z_{\mathrm{tgt}}C Q 0 = C † Z tgt C , a Hermitian Pauli, and let y = ( x , 0 , 0 a ) y=(x,0,0^a) y = ( x , 0 , 0 a ) . Then p U ( x ) = ⟨ y ∣ U † Π U ∣ y ⟩ = ( 1 − ⟨ y ∣ A ∣ y ⟩ ) / 2 p_U(x)=\langle y|U^\dagger\Pi U|y\rangle=(1-\langle y|A|y\rangle)/2 p U ( x ) = ⟨ y ∣ U † Π U ∣ y ⟩ = ( 1 − ⟨ y ∣ A ∣ y ⟩) /2 with A = R ( P 1 ) † ⋯ R ( P t ) † Q 0 R ( P t ) ⋯ R ( P 1 ) A=R(P_1)^\dagger\cdots R(P_t)^\dagger Q_0R(P_t)\cdots R(P_1) A = R ( P 1 ) † ⋯ R ( P t ) † Q 0 R ( P t ) ⋯ R ( P 1 ) .
Conjugation by R ( P ) R(P) R ( P ) fixes a Pauli M M M that commutes with P P P and sends one that anticommutes with P P P to M ( I − i P ) / 2 M(I-iP)/\sqrt{2} M ( I − i P ) / 2 . Expanding term by term, A = ∑ S c S M S A=\sum_{S}c_SM_S A = ∑ S c S M S over S ⊆ { 1 , … , t } S\subseteq\{1,\ldots,t\} S ⊆ { 1 , … , t } , where M S M_S M S is the product of Q 0 Q_0 Q 0 and the P j P_j P j with j ∈ S j\in S j ∈ S in decreasing order of j j j , and each c S c_S c S depends only on which pairs among F 0 = Q 0 , F 1 = P 1 , … , F t = P t F_0=Q_0,F_1=P_1,\ldots,F_t=P_t F 0 = Q 0 , F 1 = P 1 , … , F t = P t anticommute. Write F i = σ i X ( v i ) Z ( w i ) F_i=\sigma_iX(v_i)Z(w_i) F i = σ i X ( v i ) Z ( w i ) with σ i ∈ { ± 1 , ± i } \sigma_i\in\{\pm1,\pm i\} σ i ∈ { ± 1 , ± i } and v i , w i ∈ F 2 n + 1 + a v_i,w_i\in\mathbb{F}_2^{n+1+a} v i , w i ∈ F 2 n + 1 + a . Since X ( v ) Z ( w ) X ( v ′ ) Z ( w ′ ) = ( − 1 ) w ⋅ v ′ X ( v + v ′ ) Z ( w + w ′ ) X(v)Z(w)X(v')Z(w')=(-1)^{w\cdot v'}X(v+v')Z(w+w') X ( v ) Z ( w ) X ( v ′ ) Z ( w ′ ) = ( − 1 ) w ⋅ v ′ X ( v + v ′ ) Z ( w + w ′ ) , each M S M_S M S is ± ∏ i ∈ S ∪ { 0 } σ i \pm\prod_{i\in S\cup\{0\}}\sigma_i ± ∏ i ∈ S ∪ { 0 } σ i times X ( v S ) Z ( w S ) X(v_S)Z(w_S) X ( v S ) Z ( w S ) , with the sign fixed by the bits w i ⋅ v j w_i\cdot v_j w i ⋅ v j , v S = ∑ i ∈ S ∪ { 0 } v i v_S=\sum_{i\in S\cup\{0\}}v_i v S = ∑ i ∈ S ∪ { 0 } v i and w S = ∑ i ∈ S ∪ { 0 } w i w_S=\sum_{i\in S\cup\{0\}}w_i w S = ∑ i ∈ S ∪ { 0 } w i . On the basis state y y y , ⟨ y ∣ X ( v ) Z ( w ) ∣ y ⟩ = ( − 1 ) w ⋅ y \langle y|X(v)Z(w)|y\rangle=(-1)^{w\cdot y} ⟨ y ∣ X ( v ) Z ( w ) ∣ y ⟩ = ( − 1 ) w ⋅ y if v = 0 v=0 v = 0 and 0 0 0 otherwise, and w ⋅ y w\cdot y w ⋅ y depends only on the coordinates of w w w on the input qubits.
Hence p U p_U p U is determined by four pieces of data:
the phases σ i \sigma_i σ i , with 4 t + 1 4^{t+1} 4 t + 1 choices,
the bits w i ⋅ v j w_i\cdot v_j w i ⋅ v j for i ≠ j i\ne j i = j , which also fix which pairs anticommute, with 2 t ( t + 1 ) 2^{t(t+1)} 2 t ( t + 1 ) choices,
the subspace of indicator vectors S ′ ∈ F 2 t + 1 S'\in\mathbb{F}_2^{t+1} S ′ ∈ F 2 t + 1 with ∑ i ∈ S ′ v i = 0 \sum_{i\in S'}v_i=0 ∑ i ∈ S ′ v i = 0 , with at most 2 ( t + 1 ) 2 2^{(t+1)^2} 2 ( t + 1 ) 2 choices,
the input coordinates of the w i w_i w i , with 2 n ( t + 1 ) 2^{n(t+1)} 2 n ( t + 1 ) choices.
The product is 2 ( t + 1 ) ( 2 t + n + 3 ) 2^{(t+1)(2t+n+3)} 2 ( t + 1 ) ( 2 t + n + 3 ) . Alternatively, p U p_U p U is determined by Q 0 , P 1 , … , P t Q_0,P_1,\ldots,P_t Q 0 , P 1 , … , P t themselves, each one of 2 ⋅ 4 n + 1 + a 2\cdot4^{n+1+a} 2 ⋅ 4 n + 1 + a Hermitian Paulis, which gives 2 ( t + 1 ) ( 2 ( n + a ) + 3 ) 2^{(t+1)(2(n+a)+3)} 2 ( t + 1 ) ( 2 ( n + a ) + 3 ) .
Theorem 26 (counting bound for random sets). Let n ≥ 2 n\ge2 n ≥ 2 , 1 ≤ k ≤ n 1\le k\le n 1 ≤ k ≤ n and 0 ≤ ε < 1 / 2 0\le\varepsilon<1/2 0 ≤ ε < 1/2 , put N = ⌈ ( n + 1 ) / ( 2 ( 1 / 2 − ε ) 2 ) ⌉ N=\lceil(n+1)/(2(1/2-\varepsilon)^2)\rceil N = ⌈( n + 1 ) / ( 2 ( 1/2 − ε ) 2 )⌉ , and let R R R be random as in Theorem 24 . With probability at least 1 − 2 1 − n 1-2^{1-n} 1 − 2 1 − n , every mixture of unitary Clifford+T T T circuits with clean ancillae that approximates U 1 R U_{1_R} U 1 R to diamond error ε \varepsilon ε has cost t t t with
N ( t + 1 ) ( 2 t + n + 3 ) ≥ 2 n − k − n , N(t+1)(2t+n+3)\ge2^{n-k}-n, N ( t + 1 ) ( 2 t + n + 3 ) ≥ 2 n − k − n , and every such mixture without ancillae has cost t t t with N ( t + 1 ) ( 2 n + 3 ) ≥ 2 n − k − n N(t+1)(2n+3)\ge2^{n-k}-n N ( t + 1 ) ( 2 n + 3 ) ≥ 2 n − k − n . At ε = 1 / 4 \varepsilon=1/4 ε = 1/4 , where N = 8 ( n + 1 ) N=8(n+1) N = 8 ( n + 1 ) , this gives
t ≥ 2 n − k − n 16 ( n + 1 ) − n − 1 t\ge\sqrt{\frac{2^{n-k}-n}{16(n+1)}}-n-1 t ≥ 16 ( n + 1 ) 2 n − k − n − n − 1 and
t ≥ 2 n − k − n 8 ( n + 1 ) ( 2 n + 3 ) − 1 t\ge\frac{2^{n-k}-n}{8(n+1)(2n+3)}-1 t ≥ 8 ( n + 1 ) ( 2 n + 3 ) 2 n − k − n − 1 with clean ancillae and without ancillae, respectively.
Proof. We show that a few branches of a cheap mixture already determine R R R , and that few sets arise this way. Fix a mixture with clean ancillae, cost t t t and diamond error ε \varepsilon ε , with branches U U U drawn from μ \mu μ , and put Q ( x ) = E U p U ( x ) Q(x)=\mathbb{E}_U p_U(x) Q ( x ) = E U p U ( x ) in the notation of Lemma 25. On input ∣ x ⟩ ∣ 0 ⟩ |x\rangle|0\rangle ∣ x ⟩ ∣0 ⟩ , measuring the target gives 1 R 1_R 1 R with probability Q ( x ) Q(x) Q ( x ) for the mixture and 1 R ( x ) 1_R(x) 1 R ( x ) for U 1 R U_{1_R} U 1 R . The diamond error bounds the trace distance between these outputs, so ∣ Q ( x ) − 1 R ( x ) ∣ ≤ ε |Q(x)-1_R(x)|\le\varepsilon ∣ Q ( x ) − 1 R ( x ) ∣ ≤ ε .
Let Q ^ ( x ) \widehat Q(x) Q ( x ) be the average of p U i ( x ) p_{U_i}(x) p U i ( x ) over N N N independent branches U 1 , … , U N U_1,\ldots,U_N U 1 , … , U N . By Hoeffding’s inequality [38 ] , for each x x x ,
Pr [ ∣ Q ^ ( x ) − Q ( x ) ∣ ≥ 1 2 − ε ] ≤ 2 e − 2 N ( 1 / 2 − ε ) 2 ≤ 2 e − ( n + 1 ) < 2 − n . \Pr\left[\left|\widehat Q(x)-Q(x)\right|\ge\frac{1}{2}-\varepsilon\right]\le2e^{-2N(1/2-\varepsilon)^2}\le2e^{-(n+1)}<2^{-n}. Pr [ Q ( x ) − Q ( x ) ≥ 2 1 − ε ] ≤ 2 e − 2 N ( 1/2 − ε ) 2 ≤ 2 e − ( n + 1 ) < 2 − n .
A union bound over the 2 n 2^n 2 n inputs leaves some sample with ∣ Q ^ ( x ) − 1 R ( x ) ∣ < 1 / 2 |\widehat Q(x)-1_R(x)|<1/2 ∣ Q ( x ) − 1 R ( x ) ∣ < 1/2 for all x x x , and then
R = { x : Q ^ ( x ) ≥ 1 / 2 } . R=\{x:\widehat Q(x)\ge1/2\}. R = { x : Q ( x ) ≥ 1/2 } .
Hence R R R belongs to the family F t \mathcal F_t F t of sets { x : 1 N ∑ i p V i ( x ) ≥ 1 / 2 } \{x:\frac{1}{N}\sum_i p_{V_i}(x)\ge1/2\} { x : N 1 ∑ i p V i ( x ) ≥ 1/2 } , where V 1 , … , V N V_1,\ldots,V_N V 1 , … , V N range over circuits with at most t t t gates. Lemma 25 gives ∣ F t ∣ ≤ 2 N L |\mathcal F_t|\le2^{N L} ∣ F t ∣ ≤ 2 N L with L = ( t + 1 ) ( 2 t + n + 3 ) L=(t+1)(2t+n+3) L = ( t + 1 ) ( 2 t + n + 3 ) . A random R R R rarely lands in F t \mathcal{F}_t F t . A uniformly random set of size 2 n − k 2^{n-k} 2 n − k is one of ( 2 n 2 n − k ) ≥ 2 k 2 n − k ≥ 2 2 n − k \binom{2^n}{2^{n-k}} \ge2^{k2^{n-k}} \ge2^{2^{n-k}} ( 2 n − k 2 n ) ≥ 2 k 2 n − k ≥ 2 2 n − k equally likely sets. Under independent inclusion with probability 2 − k ≤ 1 / 2 2^{-k} \le1/2 2 − k ≤ 1/2 , no set has probability above ( 1 − 2 − k ) 2 n ≤ e − 2 n − k < 2 − 2 n − k (1-2^{-k})^{2^n} \le e^{-2^{n-k}} < 2^{-2^{n-k}} ( 1 − 2 − k ) 2 n ≤ e − 2 n − k < 2 − 2 n − k . In both models Pr [ R ∈ F t ] < 2 N L − 2 n − k \Pr[R \in\mathcal{F}_t] < 2^{NL-2^{n-k}} Pr [ R ∈ F t ] < 2 N L − 2 n − k .
Take the largest t t t with N L < 2 n − k − n NL < 2^{n-k}-n N L < 2 n − k − n . With probability above 1 − 2 − n 1-2^{-n} 1 − 2 − n , the set R R R is not in F t \mathcal{F}_t F t , so every mixture for it costs more than t t t . As N L NL N L increases with t t t , the first inequality follows. Without ancillae, the second bound of Lemma 25 with a = 0 a=0 a = 0 replaces L L L by ( t + 1 ) ( 2 n + 3 ) (t+1)(2n+3) ( t + 1 ) ( 2 n + 3 ) and gives the second inequality. A union bound over the two cases gives probability 1 − 2 1 − n 1-2^{1-n} 1 − 2 1 − n . At ε = 1 / 4 \varepsilon=1/4 ε = 1/4 , the bound ( t + 1 ) ( 2 t + n + 3 ) ≤ 2 ( t + n + 1 ) 2 (t+1)(2t+n+3)\le2(t+n+1)^2 ( t + 1 ) ( 2 t + n + 3 ) ≤ 2 ( t + n + 1 ) 2 yields the two closed forms.
The first bound is positive once n − k ≥ 3 log n + 6 n-k\ge3\log n+6 n − k ≥ 3 log n + 6 . The proof uses only that the ancillae start in ∣ 0 ⟩ \lvert0\rangle ∣ 0 ⟩ , so it also covers branches that leave them in other states.
Proposition 27 (upper bounds for sparse sets). Let R ⊆ F 2 n R\subseteq\mathbb{F}_2^n R ⊆ F 2 n and τ = ⌈ log ( 4 ∣ R ∣ / ε ) ⌉ \tau=\lceil\log(4|R|/\varepsilon)\rceil τ = ⌈ log ( 4∣ R ∣/ ε )⌉ . If τ ≤ n \tau\le n τ ≤ n , then with clean ancillae T ε m i x e d ( U 1 R ) = O ( ∣ R ∣ / ε ) \mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{1_R})=O(\sqrt{|R|/\varepsilon}) T ε mixed ( U 1 R ) = O ( ∣ R ∣/ ε ) . If n ≥ τ + 1 n\ge\tau+1 n ≥ τ + 1 , then without ancillae T ε m i x e d ( U 1 R ) ≤ 16 τ ∣ R ∣ \mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{1_R})\le16\tau|R| T ε mixed ( U 1 R ) ≤ 16 τ ∣ R ∣ .
Proof. Hash x x x by a uniformly random full-rank linear map H : F 2 n → F 2 τ H:\mathbb{F}_2^n\to\mathbb{F}_2^\tau H : F 2 n → F 2 τ and accept when H x ∈ H ( R ) Hx\in H(R) H x ∈ H ( R ) . This never errs on R R R . For x ∉ R x\notin R x ∈ / R and r ∈ R r\in R r ∈ R , the nonzero vector x ⊕ r x\oplus r x ⊕ r lies in the kernel of H H H with probability at most 2 − τ 2^{-\tau} 2 − τ , so the error at x x x is at most ∣ R ∣ 2 − τ |R|2^{-\tau} ∣ R ∣ 2 − τ . As a parity decision tree this gives RPDT ε n a ( 1 R ) ≤ ⌈ log ( ∣ R ∣ / ε ) ⌉ \operatorname{RPDT}^{\mathrm{na}}_\varepsilon(1_R)\le\lceil\log(|R|/\varepsilon)\rceil RPDT ε na ( 1 R ) ≤ ⌈ log ( ∣ R ∣/ ε )⌉ (compare [20 Fact B.7] ).
The same hash gives circuits. A CNOT circuit brings H x Hx H x to τ \tau τ of the input qubits, the oracle of the τ \tau τ -bit function 1 H ( R ) 1_{H(R)} 1 H ( R ) acts there exactly, and the CNOT circuit is undone. Lemma 7 turns the miss probability into diamond error at most 4 ∣ R ∣ 2 − τ ≤ ε 4|R|2^{-\tau}\le\varepsilon 4∣ R ∣ 2 − τ ≤ ε .
With clean ancillae the oracle of 1 H ( R ) 1_{H(R)} 1 H ( R ) costs O ( 2 τ ) = O ( ∣ R ∣ / ε ) O(\sqrt{2^\tau})=O(\sqrt{|R|/\varepsilon}) O ( 2 τ ) = O ( ∣ R ∣/ ε ) T T T gates [17 Theorem 2] , [16 Lemma 2.1] , as in the randomized sparse QROM of Li et al. [22 ] . Without ancillae this oracle is an exclusive-or of at most ∣ R ∣ |R| ∣ R ∣ point indicators on τ \tau τ bits. Up to X X X gates each is a gate C τ X C^\tau X C τ X , which borrows one of the other n − τ ≥ 1 n-\tau\ge1 n − τ ≥ 1 inputs and costs at most 16 τ 16\tau 16 τ T T T gates (Section A.2). This gives T ε m i x e d ( U 1 R ) ≤ 16 τ ∣ R ∣ \mathcal{T}^{\mathrm{mixed}}_\varepsilon(U_{1_R})\le16\tau|R| T ε mixed ( U 1 R ) ≤ 16 τ ∣ R ∣ .
Theorem 28 (distance does not determine the T T T -count). Let n ≥ 18 n\ge18 n ≥ 18 and 2 ≤ k ≤ n − ⌈ 2 log ( n + 1 ) ⌉ − 7 2\le k\le n-\lceil2\log(n+1)\rceil-7 2 ≤ k ≤ n − ⌈ 2 log ( n + 1 )⌉ − 7 . Let A A A be an affine subspace of codimension k k k , and let R R R be random as in Theorem 24 . Then δ H ( 1 A ) = 2 − k \delta_H(1_A)=2^{-k} δ H ( 1 A ) = 2 − k and T 1 / 4 m i x e d ( U 1 A ) ≤ 24 \mathcal{T}^{\mathrm{mixed}}_{1/4}(U_{1_A})\le24 T 1/4 mixed ( U 1 A ) ≤ 24 . With probability at least 1 − 2 − n 1-2^{-n} 1 − 2 − n , also δ H ( 1 R ) ∈ [ 4 5 , 6 5 ] 2 − k \delta_H(1_R)\in[\frac45,\frac65]2^{-k} δ H ( 1 R ) ∈ [ 5 4 , 5 6 ] 2 − k and T 1 / 4 m i x e d ( U 1 R ) \mathcal{T}^{\mathrm{mixed}}_{1/4}(U_{1_R}) T 1/4 mixed ( U 1 R ) is at least
n − k − ⌈ 2 log ( n + 1 ) ⌉ − 6 n-k-\lceil2\log(n+1)\rceil-6 n − k − ⌈ 2 log ( n + 1 )⌉ − 6 with any ancillae in any advice state,
( 2 n − k − n ) / ( 16 ( n + 1 ) ) − n − 1 \sqrt{(2^{n-k}-n)/(16(n+1))}-n-1 ( 2 n − k − n ) / ( 16 ( n + 1 )) − n − 1 with clean ancillae, and
( 2 n − k − n ) / ( 8 ( n + 1 ) ( 2 n + 3 ) ) − 1 (2^{n-k}-n)/(8(n+1)(2n+3))-1 ( 2 n − k − n ) / ( 8 ( n + 1 ) ( 2 n + 3 )) − 1 without ancillae.
If also k ≥ 6 k\ge6 k ≥ 6 , then with the same probability T 1 / 4 m i x e d ( U 1 R ) \mathcal{T}^{\mathrm{mixed}}_{1/4}(U_{1_R}) T 1/4 mixed ( U 1 R ) is O ( 2 ( n − k ) / 2 ) O(2^{(n-k)/2}) O ( 2 ( n − k ) /2 ) with clean ancillae and O ( ( n − k ) 2 n − k ) O((n-k)2^{n-k}) O (( n − k ) 2 n − k ) without ancillae.
Proof. For 1 A 1_A 1 A , Theorem 12 with J = 1 J=1 J = 1 and ε = 1 / 4 \varepsilon=1/4 ε = 1/4 has ℓ 1 = ⌈ log 16 ⌉ = 4 \ell_1=\lceil\log16\rceil=4 ℓ 1 = ⌈ log 16 ⌉ = 4 . Since n ≥ 5 n\ge5 n ≥ 5 , it gives c ( min { k , 4 } ) ≤ c ( 4 ) = 24 c(\min\{k,4\})\le c(4)=24 c ( min { k , 4 }) ≤ c ( 4 ) = 24 T T T gates. The distance δ H ( 1 A ) = 2 − k \delta_H(1_A)=2^{-k} δ H ( 1 A ) = 2 − k holds because k ≥ 2 k\ge2 k ≥ 2 .
For 1 R 1_R 1 R , we apply Theorem 24 with s = ⌈ 2 log ( n + 1 ) ⌉ + 6 s=\lceil2\log(n+1)\rceil+6 s = ⌈ 2 log ( n + 1 )⌉ + 6 , which satisfies (1). The upper bound on k k k gives q = n − k − s ≥ 1 q=n-k-s\ge1 q = n − k − s ≥ 1 , so the theorem bounds δ H ( 1 R ) \delta_H(1_R) δ H ( 1 R ) and gives T 1 / 4 m i x e d ( U 1 R ) ≥ n − k − s = n − k − ⌈ 2 log ( n + 1 ) ⌉ − 6 ≥ 1 \mathcal{T}^{\mathrm{mixed}}_{1/4}(U_{1_R})\ge n-k-s=n-k-\lceil2\log(n+1)\rceil-6\ge1 T 1/4 mixed ( U 1 R ) ≥ n − k − s = n − k − ⌈ 2 log ( n + 1 )⌉ − 6 ≥ 1 . The bounds with clean ancillae and without ancillae are Theorem 26 , and a union bound over the two theorems gives the probability.
For the upper bounds, the same event gives ∣ R ∣ ≤ 6 5 2 n − k |R|\le\frac65 2^{n-k} ∣ R ∣ ≤ 5 6 2 n − k , so at ε = 1 / 4 \varepsilon=1/4 ε = 1/4 we have τ = ⌈ log ( 16 ∣ R ∣ ) ⌉ ≤ n − k + 5 \tau=\lceil\log(16|R|)\rceil\le n-k+5 τ = ⌈ log ( 16∣ R ∣ )⌉ ≤ n − k + 5 . When k ≥ 6 k\ge6 k ≥ 6 this is at most n − 1 n-1 n − 1 , and Proposition 27 gives the two bounds.
Together, the T T T -count of a random set is 2 ( n − k ) / 2 2^{(n-k)/2} 2 ( n − k ) /2 with clean ancillae and 2 n − k 2^{n-k} 2 n − k without, both up to factors polynomial in n n n . Decision trees cannot show this, since RPDT 1 / 4 n a ( 1 R ) ≤ ⌈ log ( 4 ∣ R ∣ ) ⌉ ≤ n − k + 3 \operatorname{RPDT}^{\mathrm{na}}_{1/4}(1_R)\le\lceil\log(4|R|)\rceil\le n-k+3 RPDT 1/4 na ( 1 R ) ≤ ⌈ log ( 4∣ R ∣ )⌉ ≤ n − k + 3 .
Acknowledgments
The author thanks Ryan O’Donnell, who introduced the author to this topic, engaged in helpful discussions, and suggested the one-clean-ancilla construction in part 3 of Theorem 11 . The author also thanks Junseo Lee for detailed feedback on earlier drafts.
AI Disclosure
Generative artificial intelligence tools (Claude) assisted the author in deriving and refining some of the proofs, in writing the verification code, and in drafting and revising the manuscript, including its structure, cross-references and comparisons with cited sources. The author reviewed and verified all AI-assisted arguments and text and takes full responsibility for the content of this work.