Average-Case Verification of the Quantum Fourier Transform Enables Worst-Case Phase Estimation

The quantum Fourier transform (QFT) is a key primitive for quantum computing that is typically used as a subroutine within a larger computation, for instance for phase estimation. As such, we may have little control over the state that is input to the QFT. Thus, in implementing a good QFT, we may imagine that it needs to perform well on arbitrary input states. Verifying this worst-case correct behaviour of a QFT-implementation would be exponentially hard (in the number of qubits) in general, raising the concern that this verification would be impossible in practice on any useful-sized system. In this paper we show that, in fact, we only need to have good average-case performance of the QFT to achieve good worst-case performance for key tasks -- phase estimation, period finding and amplitude estimation. Further we give a very efficient procedure to verify this required average-case behaviour of the QFT.


Verification of quantum circuits
Massive efforts are currently being expended around the world on building large quantum computers, in academia and industry. Because of the fragility of quantum hardware and the quantum states it produces, it is crucial to be able to test that the hardware works as advertised. Such a test may involve some quantum hardware itself, but should be more "lightweight" than the procedure that is being tested, in order to avoid circularity.
There is an important issue with testing that is sometimes overlooked in high-level discussions of the topic: if the circuit of interest is a subroutine in a larger computation, then we may have little control of the state that is input to it; thus we would like to verify that it works on the worse-case input state. However, we can typically only test its behavior for an average-case input state, because there are far too many possible input states to test them all. In general, testing worst-case correctness of a given n-qubit circuit would take resources that scale exponentially in n. This means that efficient verification of worstcase correctness typically requires additional assumptions, ranging from restrictions on the class of circuits one is verifying (for instance Clifford circuits [FL11,dSLCP11,LW21]) to cryptographic assumptions (as in Mahadev's approach [Mah18], which also assumes the computation starts with a fixed initial state). For further discussion and pointers to related work on verification of quantum hardware, we refer to our recent paper [LW21] and to the general survey [EHW + 20]. 1 In this paper we focus on the situation where we want to apply a quantum Fourier transform (QFT), or its inverse, within the context of a larger quantum computation that we already trust to a sufficient extent. We will give a lightweight procedure for verifying certain average-case behaviour of the QFT circuit, given the ability only to apply it as a black-box. We will then show that this enables us to use the QFT to achieve good worst-case performance for key tasks-phase estimation, period finding and amplitude estimation.

The quantum Fourier transform
The quantum Fourier transform is one of the most important (possibly the most important) component of quantum algorithms. It is key in Shor's factoring algorithm [Sho97] and in the standard approach to amplitude estimation [BHMT02], which generalises Grover's search algorithm [Gro96] and which is an important subroutine in many other quantum algorithms. 2 Let N = 2 n and ω N = e 2πi/N . The n-qubit QFT is the unitary F N that maps n-bit basis state |k as where the "jk" in the exponent denotes multiplication of two n-bit integers. Interestingly, the complicated-looking Fourier basis state |k is actually a product state of n individual qubits: Leveraging this product structure, there is a well-known circuit of O(n 2 ) gates that implements F N exactly. It uses n Hadamard gates, O(n 2 ) controlled versions of R s = 1 0 0 e 2πi/2 s for different integers s, and a few SWAP gates at the end [NC00, Section 5.1]. One can also obtain an approximate circuit from this with only O(n log n) gates, by dropping the R s gates where s is bigger than c log n for some constant c [Cop94] (R s gates with large s are very close to the identity, so dropping them incurs very little error). The resulting circuit differs from F N by only an inverse-polynomially small error in operator norm.
One may also consider the inverse QFT F −1 N , where the phases are ω −jk N instead of ω jk N . This has equally efficient exact and approximate quantum circuits, since we can just reverse a circuit for F N and invert its gates to get a circuit for F −1 N .
2 It is often possible to avoid doing the full QFT in these applications. For instance, one can do phase estimation in a bit-by-bit manner [Kit95] or by using the block-encoding framework of [GSLW19] as done in [MRTC21,Ral21]; and one can do amplitude estimation by judiciously chosen numbers of Grover iterations [AR20]. However, replacing the QFT by "something else" raises the question of the verification of those "something else" components. In this paper our goal is not avoid the QFT but to show that it can be efficiently tested for average-case correctness, and then used in worst-case applications. We feel our results should actually favor the use of the QFT as a component in quantum algorithms: in this paper we come not to bury the QFT, but to praise it.

Testing a purported QFT or QFT −1
In this paper we are interested in the situation where we have a channel 3 C that we can run only as a black-box on states |ψ of our choice; C is supposed to implement F N , or F −1 N depending on the application. We would like to test to what extent C is correct. It is not practical to test whether C(|ψ ) is approximately the right state for all possible |ψ , since C could differ from F −1 N in only one "direction"; in fact, testing whether C(|k ) is close to F −1 N |k = |k for all k ∈ {0, 1} n requires Ω( √ 2 n ) runs of C. 4 However, it turns out that we can efficiently test whether C(|k ) and F −1 N |k are close on average over all k ∈ {0, 1} n . Fortunately, good performance on most Fourier basis states |k suffices for the applications we care about in the rest of the paper, which run the inverse QFT on individual Fourier basis states or mixtures thereof, or on superpositions dominated by a small number of Fourier basis states.
A Fourier basis state |k is a product state by Eq. (1), so it is relatively easy ("lightweight") to prepare, at least approximately. Each qubit in the product state |k is of the form 1 √ 2 (|0 + e iφ |1 ) for some phase φ that depends on k and on the location of the qubit. It suffices to prepare each of those qubits with O(log n) bits of precision 5 in the phase φ in order to prepare |k up to inverse-polynomially small error. One might be worried that this preparation effectively requires us to do an approximate QFT, which would defeat our purpose of testing a purported QFT black-box C; however, it is much easier to prepare known product states such as Fourier basis states than it is to implement a QFT on an arbitrary unknown state. In particular, in regimes starting from a few dozen qubits (which is the current state of the art of quantum hardware), preparing a Fourier basis state to sufficient precision seems doable while tomography on a channel C would already be prohibitively expensive.
Assuming we can prepare Fourier basis states |k sufficiently precisely, in Section 2 we give a simple test that approximates the average error (defined as infidelity, i.e., 1 minus fidelity) which C makes on Fourier basis states, up to additive approximation error ε. Our procedure uses O(1/ε 2 ) runs, each of which prepares an n-qubit product state (namely a random Fourier basis state), applies C to it, and measures the resulting n-qubit state in the computational basis.
1.4 Using an average-case-correct QFT −1 for worst-case phase estimation Suppose we have a channel C that has passed our test, so we can be confident that C is close in an average-case sense to the inverse QFT. What can we use C for? 3 A channel is a completely positive trace-preserving map on density matrices, in our case taking n-qubit mixed states to n-qubit mixed states. An n-qubit unitary is a special case of this. If channel C is run on pure state |ψ , then we will use the notation C(|ψ ) to abbreviate the resulting state C(|ψ ψ|). 4 This follows from the well-known fact that we need Ω( √ 2 n ) queries to a string x ∈ {0, 1} 2 n to decide whether x = 0 2 n [BBBV97], as follows. If we can make queries Ox : |k → (−1) x k |k and we define C as the n-qubit unitary OxF −1 N , then C = F −1 N if x = 0 2 n , and otherwise C is far from F −1 N on at least one input state |k . Accordingly, if we can distinguish those two cases with T runs of C, then T queries to x can decide whether x = 0 2 n , which implies T must be Ω( √ 2 n ). This lower bound is optimal, since we can Grover search [Gro96] over all k ∈ {0, 1} n to look for one where C|k differs significantly from F −1 N |k = |k . 5 Each bit of precision can be rotated in with one single-qubit gate Rs. To see that 2 log n bits of precision in each phase suffice, note that this gives a fidelity ≥ 1 − O(1/n 2 ) per qubit, which (because we are dealing with product states) multiplies out to a fidelity (1 − O(1/n 2 )) n ≥ 1 − O(1/n) for the n-qubit product state as a whole.
Phase estimation, originally due to Kitaev [Kit95], is the following application of the inverse QFT. Suppose we can apply an m-qubit unitary U in a controlled manner, and are given an eigenstate |φ of U with eigenvalue e 2πiθ for some unknown θ ∈ [0, 1). The goal is to estimate θ. Standard phase estimation (reviewed in Section 3.1 below) obtains an n-bit approximation to θ by using O(2 n ) controlled applications of U in order to (exactly or approximately) prepare the state F N |θ 1 . . . θ n , where θ 1 . . . θ n are the n most significant bits of the binary expansion of θ = 0.θ 1 . . . θ n . . . Applying an inverse QFT then gives us θ itself, or at least a good approximation of θ. Now suppose our channel C for the inverse QFT is only average-case correct. In that case phase estimation will fail if F N |θ 1 . . . θ n happens to be one of the Fourier basis states on which C fails significantly. However, in Section 3 we show how an average-case-correct C actually suffices to implement phase estimation in the worst case (assuming the other components of phase estimation work sufficiently well). We do this by a simple trick whereby we randomise the phase we are estimating. Then we can use our average-casecorrect C to recover a good approximation to that randomised phase with good probability, and afterwards undo the randomisation to obtain a good approximation to θ itself. A moderately small upper bound on the average-case error in the inverse QFT is good enough to make this work: in the case where the eigenphase θ can be written exactly with n bits of precision we can tolerate an average infidelity up to almost 1/2 (see end of Section 3.2), while for the more general case where θ needs more than n bits of precision we can tolerate an average infidelity up to 0.041 (see end of Section 3.3).
The advantage of this approach is that we can efficiently test whether a given C has small average-case error, while we cannot efficiently test whether C has small worst-case error. If the average error is a sufficiently small constant, then also a small constant approximation error ε suffices for this test, hence only a constant number of runs of C suffices to achieve high confidence in the approximate correctness of the inverse QFT.

Applications
As mentioned, two of the most important quantum algorithms known to date are Shor's algorithm for integer factoring [Sho97], whose quantum core is period-finding, and amplitude estimation [BHMT02]. Both rely on an inverse quantum Fourier transform, and both may fail miserably if that inverse Fourier transform happens to fail on the particular state that the algorithm applies it to. In Section 4 we show that both algorithms can still be made to work with high success probability if we only have an average-case-correct inverse QFT at our disposal.

Pros and cons of our approach
Before going into technical details let us clarify and emphasize several aspects of our approach.
First, our approach is only relevant for implementations of QFT (or QFT −1 ) that work reasonably well for most (inverse) Fourier basis states. This typically won't be true in a setting where a few of the gates in the circuit can be completely wrong. However, our approach is relevant for a QFT circuit where many (maybe even all) of the gates are slightly wrong in various ways, for instance if the per-gate error times the total number of gates (O(n log n) for the approximate QFT circuit) is at most a constant. If the number n of qubits is a few dozen, then a per-gate error on the order of 1/n log n is not very far from current technology. Second, apart from small average-case error (infidelity averaged over Fourier basis states) we don't assume much about C. This average-case error could arise in many ways, which could even be picked by our adversary: C could make a small error on most Fourier basis states, or be completely wrong on, say, a small constant fraction of those states, or anything in between. Our approach can deal with all these cases. We are not assuming any relatively benign and smooth error model such as depolarizing noise. This also illustrates the difference between worst-case and average-case error: C being completely wrong on some (maybe even a constant fraction of) Fourier basis states means it has terrible worst-case error, and yet our average-case to worst-case reduction shows that it can still be turned into something quite serviceable for worst-case applications. Even in the benign case of random rather than adversarial noise, the action of C is still likely to be worse on some Fourier basis states than on others, and our worst-case-to-average-case approach has the benefit of smoothing this out, reducing the worst-case error probability.
Third, if a channel C passed our test then we can conclude that it works well on an average Fourier basis state and hence (by our average-case-to-worst-case reduction) can be made to work well on all Fourier basis states. We can certainly not conclude that C will work well on arbitrary superpositions of Fourier basis states, since every state is a superposition of Fourier basis states, and testing that C works well on every possible state requires an exponential number of runs of C (see footnote 4). So a C that passed our test cannot just be used in every application of the inverse QFT. Fortunately, in the case of phase estimation, the inverse QFT will be applied to an individual Fourier basis state, or a mixture of Fourier basis states, or to a superposition state dominated by O(1) Fourier basis states. As we prove in Sections 3.2 and 3.3, in such cases a C that passed our test still works well enough.
Fourth, for the applications related to phase estimation, let us emphasize that we assume the state is measured in the computational basis right after the inverse QFT and all earlier non-QFT parts of the algorithm leading up to that state are essentially perfect. This is a strong assumption. For factoring via period-finding, the preparation of the periodic state involves a circuit for modular exponentiation which uses polynomially more gates (and hence is more prone to error) than the inverse QFT. Similarly, to do amplitude estimation with n bits of precision one can use an n-qubit approximate inverse QFT circuit with O(n log n) gates, which pales in significance (and error-proneness) compared to the roughly 2 n controlled Grover iterations that are done prior to the inverse QFT. Nevertheless, we feel it is a sensible modular approach to try to isolate parts of important algorithms that can be tested by themselves in a lightweight manner. The fact that the average-case error of the QFT can be efficiently tested in such a lightweight manner, and that small averagecase error suffices for many of its applications, should make the QFT a more attractive component to use in larger algorithms.

Testing average-case correctness of F −1 N on Fourier basis states
In this section we show how one can efficiently test, in a lightweight manner, that a given quantum channel C is close to the n-qubit inverse Fourier transform F −1 N on an average Fourier basis state. We can test average-case closeness to F N completely analogously, but for concreteness we focus on F −1 N in this section. We give a procedure to estimate the infidelity between C and F −1 N , averaged over the Fourier basis states, which is our measure of average-case error here. The fidelity between mixed states ρ and σ is defined as Fidelity is symmetric. It is 0 if ρ and σ are orthogonal, it is 1 if they are equal, and otherwise it lies in (0, 1). If σ = |ψ ψ| is pure, then F (ρ, |ψ ) = ψ|ρ|ψ . The infidelity between ρ and σ is defined as 1 minus fidelity. We now show that average infidelity of a purported inverse QFT is relatively easy to estimate.
Theorem 1. Let C be a channel from n qubits to n qubits, |k be a uniformly random Fourier basis state, and define the average infidelity between C and F −1 N by There exists a procedure that estimates η up to additive error ε, with success probability 1 − δ, using O(log(1/δ)/ε 2 ) runs, each of which prepares an n-qubit product state, runs C on it, and measures the resulting n-qubit state in the computational basis.
Proof. Choose k ∈ {0, 1} n uniformly at random and prepare n-qubit product state |k = F N |k . Run C on |k and measure the resulting state in the computational basis. Output 1 if the n-bit measurement outcome is k, and output 0 otherwise. Because F −1 N |k = |k is a pure state, we have The Chernoff bound implies that if we repeat this procedure r = O(log(1/δ)/ε 2 ) times, then the frequency of 0s among the r output bits equals η up to ±ε, except with probability ≤ δ. 6 Thus we have a procedure to test whether the average infidelity of our purported blackbox for the inverse QFT is small. The procedure has modest overhead: O(log(1/δ)/ε 2 ) runs, each involving a preparation of a Fourier basis state |k , one run of C, and one n-qubit measurement in the computational basis. Referring back to the discussion in the penultimate paragraph of Section 1.3, preparing |k can be done with polynomially small error using O(n) single-qubit gates, each with O(log n) bits of precision in their phase.
The same procedure could be used to test a black-box C for F N rather than for F −1 N ; the only difference is that we would prepare product state F −1 N |k at the start of each run rather than F N |k .
While we do not estimate average infidelity averaged over arbitrary states, or over an arbitrary orthonormal basis, averaging over the particular basis of Fourier basis states turns out to be sufficient for our purposes as we'll see next.
3 Using average-case-correct F −1 N for worst-case phase estimation We saw that it is hard to test a purported QFT or inverse-QFT black-box for worst-case correctness, but relatively easy to test it for average-case correctness on the set of QFT basis states. Here we will show that average-case correctness actually suffices for phase estimation even in the worst case.

Basic phase estimation
As mentioned in the introduction, in the setup for phase estimation we can apply an m-qubit unitary U in a controlled manner, and are given an eigenstate |φ of U with eigenvalue e 2πiθ for some unknown θ ∈ [0, 1). The goal is to estimate θ with roughly n bits of precision. We work on n + m qubits that start in state |0 n ⊗ |φ . We first apply n Hadamard gates to obtain the uniform superposition 1 √ 2 n j∈{0,1} n |j in the first register. Applying the (n + m)-qubit unitary gives a phase e 2πijθ to state |j |φ , where jθ is the product of n-bit integer j ∈ {0, . . . , 2 n − 1} and θ ∈ [0, 1). This puts the first register into the state The cost of V is O(2 n ) controlled applications of U . We assume the above is implemented perfectly, or with very small error. Now we apply (to the first register) a channel C that implements F −1 N and we measure the resulting n-qubit state in the computational basis, hoping that the resulting n bits give us the most significant bits of θ.
The simplest situation arises when the initial state |φ in the second register is an eigenstate of U with eigenphase θ = 0.θ 1 . . . θ n that requires only n bits of precision. In this case the state of Eq. (3) is F N |θ 1 . . . θ n . The inverse QFT will map this to |θ 1 . . . θ n , and the final measurement will give us the bits θ 1 . . . θ n with certainty. However, two complications can arise.
First, the initial state |φ could be a superposition of eigenstates of U (each with eigenphases requiring only n bits of precision) rather than one eigenstate. In this case phase estimation still gives useful results; the effect is the same as starting with a mixture of eigenstates in the second register. For example, if instead of one eigenstate |φ we start (in the second register) with a superposition α|φ +β|φ of two normalised eigenstates, with distinct associated n-bit phases θ and θ , respectively, then before the final measurement the state is α|θ 1 . . . θ n |φ +β|θ 1 . . . θ n |φ ; measuring the first n qubits gives θ with probability |α| 2 and gives θ with probability |β| 2 .
A second complication that can arise is when θ requires more than n bits of precision. In that case the state of Eq. (3) to which we apply C will be a superposition of n-qubit Fourier basis states: something of the form k α k |k rather than one Fourier basis state. If C is a perfect F −1 N then this doesn't matter: the resulting state after applying C will be k α k |k . However, if channel C is an imperfect implementation of the inverse QFT, then interference between different terms could cause trouble, and we have to be careful about this in the next subsections. For now, let us record the useful fact that the state of Eq. (3) is always dominated by a few Fourier basis states that correspond to good approximations of θ. Variants of this fact are already known (e.g. [CEMM98, Appendix C]) but for completeness we give a proof in the appendix. N = 2 n , θ ∈ [0, 1), and let coefficients α k ∈ C be such that

Proposition 2. Let
Let k * = 2 n θ ∈ {0, . . . , N − 1} be the n-bit integer corresponding to the first n bits in the binary expansion of θ, and S = {k * − K + 1, . . . , k * − 1, k * , k * + 1, . . . , k * + K} be the 2K integers "around" 2 n θ (these integers should be taken mod N ). Then k ∈S |α k | 2 can be made as small as we want by choosing K sufficiently large (independent of N ): Note that every k in the above set S provides an approximation of θ with small additive error, because |θ − k/N | < K/N (mod 1). It will suffice to take K = O(1) below. The above upper bound can probably be improved somewhat; in the appendix we also calculate numerical upper bounds on k ∈S |α k | 2 for small values of K.
3.2 Worst-case phase estimation via average-case-correct F −1 N : n-bit case Now we switch to the scenario where we do not have a perfect inverse QFT available, but instead have a channel C which has small average infidelity w.r.t. F −1 N in the sense of Theorem 1. Note that if C is usually close to F −1 N but not on the particular Fourier basis state F N |θ 1 . . . θ n that we (approximately) prepared using V , then recovering the particular phase θ that we are interested in may fail miserably, even if θ can be represented exactly with n bits of precision and all the other components of phase estimation work perfectly. In other words, an average-case-correct F −1 N does not guarantee that phase estimation works in the worst case, i.e., for each possible θ. However, we can do a relatively simple worst-case-to-average-case reduction to deal with the situation that C is not the perfect F −1 N . Our idea is to choose a uniformly random offset λ ∈ [0, 1) that can be described with n bits of precision, change the phase θ to θ = θ + λ mod 1, and then apply our purported F −1 N on the state and measure in the hope of obtaining an approximation of θ , from which we acn then subtract λ to obtain an approximation of θ itself. In this section we first describe what happens in the case where the unknown θ can be described exactly with n bits; in the next section we deal with the more subtle general case where θ needs more than n bits. Note that if θ can be described exactly by n bits, then θ = 0.θ 1 . . . θ n can be as well. In particular, θ 1 . . . θ n is now a uniformly random n-bit string and F N |θ 1 . . . θ n is a uniformly random Fourier basis state (on which C is likely to work well if its average infidelity w.r.t. F −1 N is small). Let us first consider how to change the phase. One way to do this is to change U to U = e 2πiλ U . This has the effect that the unitary V of Eq.
(2), with U replaced by U , induces an extra phase of e 2πijλ on basis state |j , resulting in However, a probably more efficient way to achieve the same is to leave U as it is, and instead modify the n Hadamard gates at the start of the phase estimation procedure. If we change the th Hadamard to a single-qubit gate that maps then the n-bit basis state |j = |j 1 . . . j n gets a phase n =1 e 2πij 2 n− λ = e 2πi( n =1 j 2 n− )λ = e 2πijλ .
Thus the uniform superposition 1 √ 2 n j∈{0,1} n |j that we prepared in the original phase estimation procedure now becomes Now we apply V of Eq.
We have thus changed the phase from θ to θ = θ + λ as desired. Applying a perfect F −1 N would give us |θ 1 . . . θ n with certainty, from which we learn θ = θ − λ mod 1. Now suppose we have a channel C available that is not the perfect F −1 N but that has small average infidelity w.r.t. the perfect F −1 N , averaged uniformly over the Fourier basis states |k : for some small constant η. This could be tested by running the procedure of Theorem 1.
Suppose we run C on a specific Fourier basis state |k , for some k ∈ {0, 1} n which would be the binary representation of the number θ. The intended n-bit outcome of a measurement in the computational basis on C(|k ) would be k. Define η k = 1 − k| C(|k ) |k , which is the probability of not getting the intended outcome. It could be the case that we happen to run C on a |k where η k is particularly large; the error probability η k could even be 1 for some k. In that case basic phase estimation would fail. However, we have Eq. (4). So if we do our worst-case-to-average-case reduction, shifting θ by a random λ (equivalently, changing k to a uniformly random k by adding a uniformly random n-bit integer N λ to it, mod N ), we obtain the following theorem: Theorem 3 (case where θ is an n-bit number). Let C be a channel from n qubits to n qubits with average infidelity ≤ η w.r.t. F −1 N (in the sense of Theorem 1). Let θ = 0.θ 1 . . . θ n ∈ {0, 1/2 n , . . . , (2 n −1)/2 n } be fixed, and λ ∈ {0, 1/2 n , . . . , (2 n −1)/2 n } be uniformly random. If we apply C to state 1 √ 2 n j∈{0,1} n e 2πij(θ+λ) |j , measure in the computational basis, and subtract λ from the measurement outcome, then we get θ except with probability ≤ η.
As long as η < 1/2, we can reduce the error probability to an arbitrarily small δ by O(log(1/δ)) repetitions.
The above theorem is for the basic case where the second register contains one eigenstate |φ of U , and the corresponding eigenphase can be described exactly with n bits of precision. Let us consider again the two complications mentioned near the end of Section 3.1. The first complication is where the state |φ in the second register is a superposition of multiple eigenstates of U rather than one eigenstate, but still assuming the eigenphases can all be decribed with at most n bits. In this case we may treat the first register as containing a mixture of different states, and still use Theorem 3. We will typically be using the estimated eigenphase to approximate some quantity of interest. If the obtained eigenphase would give a good approximation to that quantity with probability at least p in the case of a perfect F −1 N , then it will still give a good approximation with probability at least p(1 − η) in the case of our imperfect channel C; that is the situation we will be in for the application to period-finding in Section 4.1. The second complication mentioned in Section 3.1 (when the eigenphases need more than n bits) is more subtle, and we deal with it next.

Worst-case phase estimation via average-case-correct F −1 N : general case
If we run channel C on a superposition of Fourier basis states in the first register, then interference effects could occur between the different parts of the superposition when C is applied, and we have to be more careful. This is the situation when we do phase estimation for the case where the phase θ needs more than n bits of precision, as mentioned at the end of Section 3.1. We will now analyse what happens in this case in more detail. Fortunately, by Proposition 2 the state |ψ on which we apply C will still be dominated by O(1) Fourier basis states, each of which corresponds to a good approximation of θ. Choose integer K and let S be the set of 2K elements of Proposition 2. We can write |ψ as where |ρ is the normalised "rest" of the state (which consists of the non-S Fourier basis states and hence is orthogonal to the |k with k ∈ S), and |α ρ | 2 = 1 − k∈S |α k | 2 is small, depending on our choice of K.
The phase estimation procedure ends by measuring C(|ψ ) in the computational basis. Every k ∈ S will be a good measurement outcome, in the sense of corresponding to a good approximation of θ. If C were perfect then C(|ψ ) would be k α k |k , and measuring in the computational basis would give a good outcome k with probability k∈S |α k | 2 , which is close to 1 by Proposition 2. However, if C is not perfect then we have to worry about the interaction between the errors that C makes on the different parts of the state. The following easy lemma implies that measuring a state |ψ in a basis in which |ψ has small support, cannot increase probabilities by too much. Proof. Let M be the matrix on the right-hand side, and consider an arbitrary state |φ = j γ j |j . Using Cauchy-Schwarz, we have which implies the lemma.
In order to upper bound the probability of obtaining a bad outcome when measuring C(|ψ ψ|) in the computational basis, let P bad = k ∈S |k k| be the projector on the bad outcomes. Define η k = 1 − k| C(|k ) |k , which is the probability of getting a measurement outcome other than k when measuring C(|k ). We have E k [η k ] ≤ η by Eq. (4). For k ∈ S, we have Tr(|k k| C(|k )) + Tr(P bad C(|k )) ≤ Tr(C(|k )) = 1, hence Tr(P bad C(|k )) ≤ η k .
First consider the case that we do not shift θ by a random λ. Below we will use Lemma 4 twice, and also use the fact that the channel C is linear and preserves the positive semidefinite (psd) ordering 7 , to upper bound the probability that the final measurement outcome lies outside of S.

Pr[bad outcome] = Tr (P bad C(|ψ ψ|))
First apply Lemma 4 with T containing 2 states: |ρ and the normalised version of |ψ S = k∈S α k |k , so that |ψ = |ψ S |ψ S |ψ S + α ρ |ρ . We obtain: Apply Lemma 4 to |ψ S with T = S, and for the second term use Tr (P bad C (|ρ ρ|)) ≤ 1: The latter upper bound on the probability of a bad outcome could be large if the k ∈ S happen to be among the few k's that have large η k -values. However, the average over all N η k -values is small: at most η. Now consider the case where we do use our worst-caseto-average-case reduction, shifting all k by the same uniformly random n-bit integer N λ, and similarly shift the notion of a "bad outcome". Then we can upper bound the overall probability of a bad outcome by using linearity of expectation, as follows: Note the tradeoff here: |S| = 2K increases with our choice of K, while |α ρ | 2 decreases. We summarize the above calculations in a theorem, using Proposition 2 to bound |α ρ | 2 : Theorem 5 (case where θ may need more than n bits of precision). Let C be a channel from n qubits to n qubits with average infidelity ≤ η w.r.t. F −1 N (in the sense of Theorem 1). Let θ ∈ [0, 1) be fixed, and λ ∈ {0, 1/2 n , . . . , (2 n − 1)/2 n } be uniformly random. If we apply C to state 1 √ 2 n j∈{0,1} n e 2πij(θ+λ) |j , measure in the computational basis, and subtract λ from the measurement outcome, then for every integer K ≥ 1, the probability to get an outcome k ∈ {0, . . . , N − 1} such that |θ − k/N | > K/N (mod 1) is at most For example, if we use K = 4 (considering the |S| = 2K = 8 k's that are closest to 2 n θ to be the good measurement outcomes) and we set η ≤ 0.015, then the probability of a bad outcome will be < 0.497. Thus the probability of obtaining a good approximation of the phase θ is > 0.503, and we can amplify this success probability to be close to 1 by taking the median of multiple runs of this procedure.
We can improve these bounds on the tolerable average infidelity η a bit by plugging the numerical upper bounds on |α ρ | 2 from the end of the appendix into Eq. (5), taking N = 2 10 for concreteness (for other values of N the numbers are very similar). With K = 4 and using |α ρ | 2 ≈ 0.05 from the appendix, the probability of a bad outcome is ≤ 16η + 2(1 − 8η)0.05, which is < 0.5 as long as the average infidelity η is ≤ 0.026. With K = 3, using |α ρ | 2 ≈ 0.067 from the appendix, the probability of a bad outcome is ≤ 12η + 2(1 − 6η)0.067, which is < 0.5 as long as the average infidelity η is ≤ 0.032. With K = 2, using |α ρ | 2 ≈ 0.099 from the appendix, we can tolerate η ≤ 0.041. Even with these numerical improvements, the tolerable η is still much smaller here than in the case where θ is an n-bit number (Theorem 3): there we could tolerate any η < 1/2.
where p = |{z : 0 ≤ s + zr < N }| is the number of basis states occurring in the superposition. This p will be N/r rounded up; N has N/r "complete" sequences of r indices followed by one "incomplete" sequence of N − r N/r indices. Shor [Sho97] showed via classical number theory that the ability to find the period r given such a state suffices for factoring integers, and gave an efficient quantum algorithm for period-finding. Subsequently Kitaev [Kit95] showed how to do period-finding using phase estimation, and then Cleve, Ekert, Mosca, and Macchiavello [CEMM98] showed that Shor's and Kitaev's approaches to period-finding are basically the same. In order to do period-finding via phase estimation starting from a periodic state, we let U be the "+1 mod N " operator: It is easily verified that the eigenstates of U are the states F −1 N |j with corresponding eigenvalue ω j N = e 2πij/N . Note that n bits of precision suffice for each of these eigenphases. Because these eigenstates form a basis, any state |φ can be written as a superposition N −1 j=0 α j F −1 N |j of eigenstates of U with some coefficients α j . We already saw how phase estimation using U acts when we start with such a superposition in the second register: with probability |α j | 2 it returns the n-bit number j/N exactly. We now determine these α j coefficients for the case where our starting state is the periodic state |π s = j α j F −1 N |j , by multiplying |π s with F N (we do this only as a calculational device; we are not implementing the QFT physically): We now want to show that the amplitude is concentrated around integer multiples of N/r. First consider the special case where N/r happens to be an integer. If j = cN/r for some integer c ∈ {0, . . . , r − 1}, then we have ω jzr N = 1 for all z and hence |α j | 2 = p/N = 1/r; there are r such j's, each with squared amplitude 1/r, so the j's that are not integer multiples of N/r will have amplitude 0 in this case.
In the general case where N/r is not an integer, let j be the closest integer to cN/r for some c ∈ {0, . . . , r − 1} (i.e., j = cN/r + δ for δ ∈ (−1/2, 1/2]). Then x for x ∈ [0, π/2], and assuming δ = 0. If indeed δ = 0, then the probability that the measurement outcome j is one of the two integers in the interval (cN/r − 1, cN/r + 1) is ≥ 8/(π 2 r). 9 If δ = 0, then |α j | 2 = p/N ≥ 1/r. Accordingly, with probability ≥ 8/π 2 our measurement outcome j is cN/r (rounded up or down) for some random integer c ∈ {0, . . . , r − 1}. Note that in that case we have |j/N − c/r| < 1/N , so the known ratio j/N is a very good approximation to the unknown ratio c/r. Shor showed that if c and r are coprime (which, by classical number theory, happens with largish probability Ω(1/ log log r)), then continued-fraction expansion on the known ratio j/N yields the period r (as mentioned, this suffices for factoring).
Using our worst-case to average-case reduction, this method for period-finding still works when we only have a good-on-average inverse QFT for our phase estimation, provided the initial periodic state |π s is prepared sufficiently well and the other components of phase estimation (the unitary V from Eq. (2) and the n modified Hadamard gates) also work sufficiently well. Note that the relevant eigenphases can all be described by n bits here, so we only need to refer to the result in Section 3.2 and not to the more complicated result in Section 3.3, where the tolerable η is worse. By the result in Section 3.2, since the probability to find a good j is 8/π 2 using a perfect inverse QFT, this probability is still ≥ (1 − η)8/π 2 if we instead use a channel C that has average infidelity ≤ η w.r.t. the perfect inverse QFT. 9 It need not be the case that each of the two outcomes cN/r and cN/r has probability ≥ 4/(π 2 r), because one of them will correspond to a δ ∈ (−1/2, 1/2]. However, the sum of these two probabilities is at least 8/(π 2 r), which may be verified by noting that the function f (x) = sin(πx) 2 / sin(πx/p) 2 + sin(π(1 − x)) 2 / sin(π(1 − x)/p) 2 is at least 8p 2 /π 2 on the interval x ∈ [0, 1/2]. We note that this calculation is similar to that in the appendix; here, however, we have a superposition of eigenstates each with n-bit eigenphase; in the appendix similar calculations are needed to deal with the situation that the eigenphase needs more than n bits of precision.

Amplitude estimation
Suppose we have a unitary quantum algorithm A that maps |0 m → A|0 m = sin(µ)|φ 1 |1 + cos(µ)|φ 0 |0 , for some arbitrary normalised states |φ 1 and |φ 0 , and some angle µ ∈ [0, π/2]. We would like to estimate the angle µ or (which comes to the same thing) the amplitude sin(µ). Such "amplitude estimation" can be used for instance for optimal quantum approximate counting [BHMT02] and is a key component of many other quantum algorithms that involve estimating various quantities. For completeness we here sketch the elegant method of Brassard et al. [BHMT02] that reduces amplitude estimation to phase estimation. Consider the unitary where R 0 = 2|0 m 0 m | − I reflects about |0 m . This R 0 can be implemented using a circuit with O(m) elementary gates. Consider how U acts in the 2-dimensional space S spanned by |φ 1 |1 and |φ 0 |0 . 10 U is the product of two reflections: first I ⊗ Z reflects about |φ 0 |0 , and then AR 0 A −1 reflects about A|0 m . This product of two reflections corresponds (in the space S) to a rotation over twice the angle µ that exists between |φ 0 |0 and A|0 m = sin(µ)|φ 1 |1 + cos(µ)|φ 0 |0 . Such a rotation over angle 2µ has two eigenvectors in S, with respective eigenvalues e i2µ and e −i2µ . How do we use phase estimation to estimate µ? We start in state A|0 m , which lies in S and hence is some linear combination of the two eigenvectors (with unknown coefficients, but that doesn't matter). If we run phase estimation, then the output will either be an estimate of µ/π or of −µ/π (or rather, 1 − µ/π). Since we assumed µ ∈ [0, π/2], the phase µ/π that we're estimating lies in [0, 1/2]. If our estimate is in [0, 1/2] then we'll assume it's µ/π, and if our estimate is in [1/2, 1) then we'll assume it's 1 − µ/π. Either way we obtain a good estimate of µ.
This method still works with an only-good-on-average channel for F −1 N if we do our worst-case to average-case reduction. If we want n bits of precision in our estimate of µ, then the cost will be O(2 n ) applications of U . Note that here we need the more complicated result of Section 3.3, since the eigenphases ±µ/π may require more than n bits of precision.

Summary and future work
In this paper we did two things. First, we showed that one can efficiently test whether a given n-qubit channel C implements the inverse QFT well, on average over all Fourier basis states. Our procedure estimates (with success probability ≥ 1 − δ) the average (in)fidelity up to ±ε using O(log(1/δ)/ε 2 ) runs, each of which uses O(n) single-qubit gates to prepare a product state, one run of C, and a measurement in the computational basis.
Second, we showed that such an average-case-correct inverse QFT suffices to implement phase estimation in the worst case. This implies that an average-case-correct inverse QFT also suffices for period-finding (as in Shor's algorithm) and for amplitude estimation, provided the other components of those procedures work sufficiently well.
Practical methods of verification for large numbers of qubits will be vital for future quantum computers. Here we have shown that such verification is possible for several key algorithmic primitives. We feel it would be very interesting to find more examples of worst-case-to-average-case reductions for quantum computing.
One more example would be the quantum algorithm of Jordan [Jor05] for computing the gradient of a differentiable function f : R d → R, i.e., the vector of the d partial derivatives of f evaluated at a given point. Let's say we want to approximate the gradient with n bits of precision for each of its d entries. Jordan's algorithm sets up a uniform superposition over some grid of inputs (x 1 , . . . , x d ) in d n-qubit registers, then computes f once in the phase, and then applies an inverse QFT to each of the d registers. If f is affinelinear, i.e., there are coefficients a, b 1 , . . . , b d ∈ R such that f (x) = a + b 1 x 1 + · · · + b d x d for all x ∈ R n , and each b i can be represented exactly with n bits of precision, then the final state gives b 1 , . . . , b d which is exactly the gradient of f . If some of the b i 's need more than n bits of precision then at the end of the algorithm the ith register contains b i with high probability. This algorithm "costs" only one f -evaluation, d runs of the n-qubit inverse QFT, and O(dn) other elementary gates. In contrast, classical algorithms need d f -evaluations to compute the gradient. In the more general case where f is fairly smooth but only close to an affine-linear function on the grid of points that we feed into it, a much more complicated analysis due to Gilyén, Arunachalam, and Wiebe [GAW19] determines the complexity of approximating the gradient in various norms, in terms of how many times f needs to be evaluated.
What if we only have a good-on-average inverse QFT available? If f is affine-linear then one may confirm that the analysis of our Section 3.3 implies that Jordan's algorithm can still be made to work via our worst-case-to-average-case reduction. If f is only close to affine-linear then it is not clear what happens, and whether the more subtle analysis of [GAW19] can also be made to work with an imperfect inverse QFT. We leave this question to further work.
Our goal is to show that the total probability P = k∈S |α k | 2 of terms in the set S is close to 1. By applying inverse QFT to both sides of Eq. (6) and rewriting the geometric series, we have sin 2 (πx) sin 2 (π(x − k)/N ) (7) We will now prove an upper bound on the probability of error (the analysis is similar to that in [NC00] section 5.2.1).
sin 2 (πx) sin 2 (π(x − k)/N ) + 1 N 2 N/2 k=K+1 sin 2 (πx) sin 2 (π(x − k)/N ) The final inequality is easy to see because the function is maximised on [0, 1] at the two endpoints of that interval (x = 0 or x = 1). We use this bound in Proposition 2 in the body of the paper.
In fact, numerical evidence suggests that the above rigorous bound is rather loose. The probability of Eq. (7) is symmetric around x = 1/2, because replacing x by 1 − x leaves P invariant (replacing x by 1 − x interchanges the two squared amplitudes |α k * +k | 2 and |α k * −k+1 | 2 , leaving the sum of the pair invariant). Hence P has a local optimum at x = 1/2. Plotting the graphs for small K strongly suggests that P is actually minimised at x = 1/2. If this is indeed the case, then (using the symbolP to denote this conjectured bound)P Numerical evidence shows that this asymptotic bound is reasonably close to the sum for moderate-sized and large K, but still somewhat off for small K: • For K = 2, the proven upper bound for the error of Eq. (8) is 0.375, whereas the upper bound for the error using (9) is 0.135, and the numerical evaluation of the exact formula (7) for 1 − P for K = 2, e.g. N = 2 10 and x = 1/2, is 0.099.
• For K = 3, the proven upper bound for the error of Eq. (8) is 0.208, whereas the upper bound for the error using (9) is 0.081, and the numerical evaluation of the exact formula (7) for 1 − P for K = 3, e.g. N = 2 10 and x = 1/2, is 0.067.
• For K = 4, the proven upper bound for the error of Eq. (8) is 0.146, whereas the upper bound for the error using (9) is 0.058, and the numerical evaluation of the exact formula (7) for 1 − P for K = 4, e.g. N = 2 10 and x = 1/2, is 0.050.