Education / Quantum Algorithms

Quantum Algorithms · Chapter 04

Fourier Methods

Phase encoding gave us two ways to read phases. The Hadamard test reads one phase as the bias of a coin, and a layer of Hadamards reads a whole pattern of signs \((-1)^{s\cdot x}\) in one step. Simon’s problem showed how such reads, repeated and combined classically, uncover a hidden subgroup.

Many problems produce a richer pattern: phases that advance steadily with a number, \(e^{2\pi ixy/N}\), like the hand of a clock. Periodic functions produce them, and so do controlled powers of a unitary acting on one of its eigenstates. Signs are the case \(N=2\). Which transform reads a clock pattern for general \(N\), and can we build it with few gates?

We find that transform, the quantum Fourier transform, from the requirement that clock patterns for different numbers be distinguishable, and build it with \(O(n^2)\) gates on \(n\) qubits. Feeding it the phases kicked back by controlled powers gives phase estimation, which reads the eigenvalues of a unitary to many digits. Modular multiplication has the order of a number as an eigenphase, so phase estimation finds orders, and continued fractions recover the order from an approximate sample. A short classical argument then turns orders into factors, which is Shor’s algorithm, and the same strategy solves a whole family of hidden subgroup problems.

Fourier sampling returns a useful outcome only with some probability, which raises the question of how to make a small probability large.

How does a repeated pattern become a measurable frequency?

The Fourier transform turns an unknown shift into an invisible phase and a hidden period into a visible frequency.

In this chapter · 4 sections · 14 topics
  1. 4.1 The Fourier Transform
    Topics in this section
    1. 4.1.1 Roots of unity and cancellation
    2. 4.1.2 Periodic states and frequency peaks
    3. 4.1.3 Circuit construction
    4. 4.1.4 Approximation and cost
  2. 4.2 Phase Estimation
    Topics in this section
    1. 4.2.1 Controlled powers and kickback
    2. 4.2.2 Exact phases
    3. 4.2.3 Resolution and success probability
    4. 4.2.4 Superpositions of eigenstates
  3. 4.3 Order Finding
    Topics in this section
    1. 4.3.1 Modular multiplication as a unitary
    2. 4.3.2 Eigenstates and the sample s/r
    3. 4.3.3 Continued fractions
  4. 4.4 Factoring and Hidden Structure
    Topics in this section
    1. 4.4.1 From order to factors
    2. 4.4.2 Resources
    3. 4.4.3 Hidden subgroup problems
Reading guide · preparation, aims, and assumptions

Build the quantum Fourier transform and use it with controlled powers and kickback to estimate eigenphases, find orders, and factor integers.

Before you begin

Use phase kickback, controlled powers, the Hadamard test, and Simon’s algorithm from the Phase Encoding chapter, and reversible arithmetic from the Coherent Computation chapter.

What you should be able to do

The example to follow

Phase estimation with three control qubits on φ = 3/8, then order finding for a = 7 modulo 15 and for a = 2 modulo 21, the latter with continued fractions on the outcome 85/512.

Scope and assumptions

Gates are ideal; controlled powers are assumed available, and their cost is counted explicitly. The factoring speedup is relative to the best known classical algorithm, not a proven separation.

4.1

The Fourier Transform

Which unitary reads a pattern of steadily advancing phases, as the Hadamard transform reads signs? The requirement that the patterns for different numbers be perfectly distinguishable fixes it. Once we have the transform, we ask what it does to a state whose amplitudes repeat with some period. A general unitary on \(n\) qubits needs exponentially many gates, so we then look for structure that gives a short circuit, and finally ask which of its gates can be dropped.

4.1.1 Roots of unity and cancellation§

root of unityquantum Fourier transform

Kickback from controlled powers will leave a register of dimension \(N\) in a state like

\[\frac{1}{\sqrt N}\sum_{k=0}^{N-1}e^{2\pi ijk/N}\ket k.\]

Each basis state carries a phase that advances by the same step \(2\pi j/N\), like the hand of a clock. Suppose \(j\) is an unknown integer between \(0\) and \(N-1\). Can a measurement tell us \(j\)? In the computational basis every outcome has probability \(1/N\), whatever \(j\) is. The information sits entirely in the phases.

From the readout of Deutsch’s circuit we know what would make \(j\) readable: the states for different \(j\) must be orthogonal, and then a change of basis maps each one to \(\ket j\). Are they orthogonal? Write \(\omega=e^{2\pi i/N}\). The inner product of the states for \(j\) and \(j'\) is \(\frac1N\sum_k\omega^{(j'-j)k}\), so we need to know when such sums vanish.

The powers \(1,\omega,\omega^2,\ldots,\omega^{N-1}\) are \(N\) equally spaced points on the unit circle, the \(N\)th roots of unity, and \(\omega^N=1\). For an integer \(k\) not divisible by \(N\), they cancel:

\[\sum_{x=0}^{N-1}\omega^{kx}=0.\]

Here is a proof that needs no geometry. Call the sum \(S\). Multiplying by \(\omega^k\) shifts every term to the next one, and the last term \(\omega^{k(N-1)}\) becomes \(\omega^{kN}=1\), the first. So \(\omega^kS=S\). Since \(\omega^k\neq1\), \(S=0\). Geometrically, \(N\) arrows equally spaced around a circle (or wound around it several times) sum to nothing. When \(N\) divides \(k\), every term is \(1\) and the sum is \(N\).

The eighth roots of unityThe powers of omega=e^(2π i/8) are eight equally spaced unit arrows. Their sum is zero, and so is the sum of omega^(kx) over x for any k not divisible by 8: the arrows are evenly spread, possibly winding several times around the circle. The eighth roots of unity1omegaomega²omega³omega⁴omega⁵omega⁶omega⁷omega=e^(2π i/8), omega⁸=1Σ_(x=0)⁷omega^x=0Σ_(x=0)⁷omega^(2x)=0Σ_(x=0)⁷omega^(8x)=8
The powers of \(\omega=e^{2\pi i/8}\) are eight equally spaced unit arrows. Their sum is zero, and so is the sum of \(\omega^{kx}\) over \(x\) for any \(k\) not divisible by 8: the arrows are evenly spread, possibly winding several times around the circle.

For \(j\neq j'\) the difference \(j'-j\) lies strictly between \(-N\) and \(N\) and is not zero, so \(N\) does not divide it, and the inner product vanishes. Each state has length one. So the \(N\) clock states are orthonormal, and they form a basis. The unitary that maps each basis state to its clock state is the quantum Fourier transform:

\[F_N\ket x=\frac{1}{\sqrt N}\sum_{y=0}^{N-1}\omega^{xy}\ket y.\]

It sends an orthonormal basis to an orthonormal basis, so it is unitary. Its inverse \(F_N^\dagger\ket y=\frac{1}{\sqrt N}\sum_x\omega^{-xy}\ket x\) maps the clock state for \(j\) back to \(\ket j\), which is the readout we wanted.

For \(N=2\), \(\omega=-1\) and \(F_2=H\). For \(N=2^n\), \(F_N\) is not \(H^{\otimes n}\): the Hadamard transform uses signs \((-1)^{x\cdot z}\) with the bitwise product, while \(F_N\) uses \(\omega^{xy}\) with ordinary multiplication of integers. The two are Fourier transforms over the two groups we have met: bit strings under XOR, and integers under addition modulo \(N\).

Problems
  1. Write \(F_4\) as a matrix with rows indexed by \(y\) and columns by \(x\).

    Show solutionHide solution

    With \(\omega=i\), entry \((y,x)\) is \(\frac12i^{xy}\). Rows: \(\frac12(1,1,1,1)\), \(\frac12(1,i,-1,-i)\), \(\frac12(1,-1,1,-1)\), \(\frac12(1,-i,-1,i)\).

  2. Check directly that \(1+\omega^2+\omega^4+\omega^6=0\) for \(N=8\), and that \(1+\omega^4+\omega^8+\omega^{12}=0\).

    Show solutionHide solution

    For \(N=8\), \(\omega^2=i\), so the first sum is \(1+i-1-i=0\). \(\omega^4=-1\), so the second is \(1-1+1-1=0\). In both cases \(8\nmid k\).

  3. Show that \(F_N^2\ket x=\ket{-x\bmod N}\). What is \(F_N^4\)?

    Show solutionHide solution

    \[F_N^2\ket x=\frac1N\sum_y\sum_z\omega^{xy}\omega^{yz}\ket z=\frac1N\sum_z\big(\sum_y\omega^{y(x+z)}\big)\ket z\]. The inner sum is \(N\) when \(z\equiv-x\) and \(0\) otherwise. So \(F_N^2\) is the reflection \(x\mapsto-x\), and \(F_N^4=I\).

4.1.2 Periodic states and frequency peaks§

periodfrequency

What does \(F_N\) do to a state whose amplitudes repeat? Take \(N=8\) and the state supported on every second position,

\[\ket{\psi_0}=\tfrac12(\ket0+\ket2+\ket4+\ket6).\]

Figure guide. The figure plots a period-2 amplitude comb on an 8-dimensional register before and after the discrete Fourier transform \(F_8\). Compare the input spacing \(r=2\) against the output frequency peaks to see where constructive interference concentrates the probability.

What to observe

Two outcomes, \(0\) and \(4\), each with probability \(\frac12\). A pattern of period 2 in a register of size 8 produces peaks at multiples of \(8/2=4\).

The amplitude of \(\ket y\) is \(\frac{1}{2\sqrt8}\sum_{k=0}^{3}\omega^{2ky}\). With \(\omega^2=e^{2\pi i/4}\), this is a sum of fourth roots of unity raised to the power \(y\): it is \(4\) when \(4\mid y\) and \(0\) otherwise. So

\[F_8\ket{\psi_0}=\tfrac{1}{\sqrt2}(\ket0+\ket4).\]

Now shift the pattern by one: \(\ket{\psi_1}=\tfrac12(\ket1+\ket3+\ket5+\ket7)\). Every term gains an extra factor \(\omega^{y}\), so \(F_8\ket{\psi_1}=\tfrac{1}{\sqrt2}(\ket0-\ket4)\). The probabilities are unchanged. The Fourier transform converts a shift into a phase, exactly as the Hadamard transform did in Simon’s algorithm, and a phase is invisible to measurement.

A period-2 pattern becomes two frequenciesProbabilities before and after F₈ for the state 1/2(|0⟩+|2⟩+|4⟩+|6⟩). Four positions spaced by 2 become two frequencies spaced by 8/2=4. Shifting the input pattern by one changes only phases of the output, not these probabilities. Horizontal axis: basis label x or y; vertical axis: probability. A period-2 pattern becomes two frequencies00.250.501234567basis label x or yprobabilitybefore: |ψ₀⟩after F₈
Probabilities before and after \(F_8\) for the state \(\tfrac12(\ket0+\ket2+\ket4+\ket6)\). Four positions spaced by 2 become two frequencies spaced by \(8/2=4\). Shifting the input pattern by one changes only phases of the output, not these probabilities.

In general, if \(r\) divides \(N\) and a state is uniform on \(x_0,x_0+r,x_0+2r,\ldots\), its Fourier transform is uniform over the \(r\) multiples of \(N/r\), the frequencies \(0,N/r,2N/r,\ldots\), with phases depending on \(x_0\). For \(N=8\) and \(r=2\) these are \(0\) and \(4\), as we found. Measuring gives a random frequency \(kN/r\), which carries information about \(r\). When \(r\) does not divide \(N\), the peaks are no longer exact: they spread over nearby integers, and recovering \(r\) then needs more work.

Problems
  1. For \(N=8\), compute \(F_8\) of \(\tfrac{1}{\sqrt2}(\ket0+\ket4)\).

    Show solutionHide solution

    The amplitude of \(y\) is \(\frac{1}{4}(1+\omega^{4y})=\frac14(1+(-1)^y)\): \(\frac12\) for even \(y\) and \(0\) for odd. So the result is \(\frac12(\ket0+\ket2+\ket4+\ket6)\). Period 4 gives frequencies at multiples of 2. (This also follows from \(F_8^2\) being \(x\mapsto-x\).)

  2. For \(N=12\) and a state uniform on \(\{1,4,7,10\}\) (period 3), which outcomes occur after \(F_{12}\)?

    Show solutionHide solution

    Multiples of \(12/3=4\): outcomes \(0,4,8\), each with probability \(\frac13\). The offset \(x_0=1\) contributes only phases \(\omega^{y}\).

  3. A student measures one outcome, \(4\), in the \(N=12\) example. Can they conclude \(r=3\)? What about the outcome \(0\)?

    Show solutionHide solution

    From \(4=kN/r\) with \(k=1\) they would get \(r=3\), but \(k\) is unknown: \(4=2\cdot12/6\) is also consistent with \(r=6\) (outcomes \(0,2,4,\ldots\)). The outcome \(0\) carries no information at all. Several samples are needed: the gcd of the observed outcomes and \(N\) gives \(N/r\) with high probability.

4.1.3 Circuit construction§

controlled phase gateproduct representation

A unitary on \(n=\log_2N\) qubits is a \(2^n\times2^n\) matrix; a general one needs exponentially many gates. The Fourier transform is special. Write \(x=\sum_jx_j2^j\) and \(y=\sum_ky_k2^k\). The phase \(\omega^{xy}=e^{2\pi ixy/2^n}\) depends on \(xy/2^n\) only modulo one, and

\[\frac{xy}{2^n}=\sum_k y_k\,\frac{x\,2^k}{2^n}\equiv\sum_ky_k\,(0.x_{n-k-1}\cdots x_1x_0)\pmod 1,\]

because multiplying \(x\) by \(2^k\) shifts its binary point, and the integer part contributes nothing. Each output bit \(y_k\) receives a phase determined by a binary fraction of the input bits. The sum over \(y\) therefore factors into a product over output bits:

\[F_N\ket x=\bigotimes_{k=n-1}^{0}\frac{\ket0+e^{2\pi i\,(0.x_{n-k-1}\cdots x_0)}\ket1}{\sqrt2},\]

with the highest output bit written first. This product representation says the output is unentangled for every basis input, and each factor can be built separately. The highest output bit gets \(e^{2\pi i\,0.x_0}=(-1)^{x_0}\), a Hadamard on \(x_0\). The lowest gets the full fraction \(0.x_{n-1}\cdots x_0\).

The circuit builds the factors in place. Apply \(H\) to the top input bit \(x_{n-1}\), giving phase \(e^{2\pi i\,0.x_{n-1}}\); then controlled phase gates \(P(\pi/2)\) from \(x_{n-2}\), \(P(\pi/4)\) from \(x_{n-3}\), and so on, add \(0.0x_{n-2}\), \(0.00x_{n-3}\), …, completing the factor for \(y_0\). Repeat on the next wire with one fewer rotation. The factors end in reversed order, so swaps restore the bit order.

The quantum Fourier transform on three qubitsInputs x₂x₁x₀, high bit on top. Each wire receives a Hadamard and controlled phase gates P(π/2), P(π/4) from lower bits, building the factors of the product representation in reverse order; the final swap restores the order. Output y₂y₁y₀. Read each circuit left to right; double lines carry classical measurement records.The quantum Fourier transform on three qubits|x₂⟩y₂|x₁⟩y₁|x₀⟩y₀HP_(π/2)P_(π/4)HP_(π/2)H
Inputs \(x_2x_1x_0\), high bit on top. Each wire receives a Hadamard and controlled phase gates \(P(\pi/2)\), \(P(\pi/4)\) from lower bits, building the factors of the product representation in reverse order; the final swap restores the order. Output \(y_2y_1y_0\).

The circuit uses \(n\) Hadamards, \(n(n-1)/2\) controlled phase gates, and \(\lfloor n/2\rfloor\) swaps: \(O(n^2)\) gates for a transform on a space of dimension \(2^n\). The inverse \(F_N^\dagger\) is the same circuit run backwards with negated angles. The construction, and its approximate version below, are due to Coppersmith (1994).

Problems
  1. Use the product representation to write \(F_4\ket{2}\) and check it against the matrix of \(F_4\).

    Show solutionHide solution

    \(x=2\): \(x_1=1\), \(x_0=0\). High output factor: \(\frac{1}{\sqrt2}(\ket0+e^{2\pi i\,0.0}\ket1)=\ket+\). Low factor: \(\frac{1}{\sqrt2}(\ket0+e^{2\pi i\,0.10}\ket1)=\frac{1}{\sqrt2}(\ket0-\ket1)\). Product: \(\frac12(\ket{00}-\ket{01}+\ket{10}-\ket{11})\), amplitudes \((1,-1,1,-1)/2\) for \(y=0,1,2,3\). The column \(x=2\) of \(F_4\) is \(\frac12(1,i^2,i^4,i^6)=\frac12(1,-1,1,-1)\).

  2. How many controlled phase gates does the \(n=10\) QFT use, and what is the smallest angle?

    Show solutionHide solution

    \(10\cdot9/2=45\) controlled phase gates. The smallest is \(P(2\pi/2^{10})=P(\pi/512)\), between the top and bottom wires.

  3. The QFT acts on \(2^n\) amplitudes with \(O(n^2)\) gates, while the classical fast Fourier transform of a list of \(2^n\) numbers takes \(O(n2^n)\) operations. Why is this not an exponential speedup for computing Fourier transforms of data?

    Show solutionHide solution

    The QFT transforms amplitudes, which cannot be read out: measurement returns one sample \(y\) with probability \(|\hat\alpha_y|^2\). Loading \(2^n\) classical numbers into amplitudes costs about \(2^n\) operations, and estimating \(2^n\) output coefficients costs at least \(2^n\) runs. The QFT is fast as a step inside an algorithm whose input is produced coherently and whose output is a few samples, as in phase estimation and period finding.

4.1.4 Approximation and cost§

approximate QFT

The smallest rotations in the QFT have angles \(2\pi/2^n\). For large \(n\) they are physically tiny and, in fault-tolerant gate sets, expensive to synthesize. Do we need them?

A controlled phase \(\mathrm{C}P(\theta)\) differs from the identity only on \(\ket{11}\), by \(e^{i\theta}-1\), whose magnitude is at most \(|\theta|\). So omitting it changes the operation by at most \(|\theta|\) in operator norm. By the error-composition bound for products of unitaries, omitting several gates changes the whole circuit by at most the sum of their angles. If we drop every rotation with angle below \(2\pi/2^b\), each wire loses rotations \(2\pi/2^{b+1},2\pi/2^{b+2},\ldots\), totalling less than \(2\pi/2^b\). Over \(n\) wires, the approximate QFT has error less than \(2\pi n/2^b\).

Exact and approximate Fourier transformsDropping controlled rotations with angle below 2π/2^b changes the transform by less than 2π n/2^b in operator norm. Counts are for n qubits; each kept rotation must still be synthesized in a fault-tolerant gate set. Columns: Version, Controlled rotations, Error. Exact QFT, n(n−1)/2, 0; Keep rotations ≥ 2π/2^b, at most n(b−1), <2π n/2^b; Target error ε, O(nlog(n/ε)), ≤ε with b≈log₂(2π n/ε)Exact and approximate Fourier transformsVersionControlled rotationsErrorExact QFTn(n−1)/20Keep rotations ≥ 2π/2^bat most n(b−1)<2π n/2^bTarget error εO(nlog(n/ε))≤ε with b≈log₂(2π n/ε)
Dropping controlled rotations with angle below \(2\pi/2^b\) changes the transform by less than \(2\pi n/2^b\) in operator norm. Counts are for \(n\) qubits; each kept rotation must still be synthesized in a fault-tolerant gate set.

To reach error \(\epsilon\), choose \(b\approx\log_2(2\pi n/\epsilon)\). Each wire then keeps at most \(b\) rotations, so the gate count falls from \(O(n^2)\) to \(O(n\log(n/\epsilon))\). In phase estimation a modest constant error in the QFT only slightly lowers the success probability, so \(b\) of order \(\log n\) suffices. Each remaining rotation must still be synthesized, and its synthesis error is added to the total in the same way. When a resource estimate quotes the QFT as “\(O(n^2)\) gates”, ask whether it is exact or approximate, and in which gate set.

Problems
  1. For \(n=1000\) and target error \(\epsilon=10^{-3}\), estimate \(b\) and the number of controlled rotations in the approximate QFT.

    Show solutionHide solution

    \(2\pi n/\epsilon\approx6.3\times10^6\), so \(b\approx23\). Each wire keeps at most 22 controlled rotations (angles \(\pi/2\) through \(2\pi/2^{23}\)), so about \(22\times1000=22{,}000\), versus \(499{,}500\) for the exact QFT.

  2. Prove \(|e^{i\theta}-1|\le|\theta|\).

    Show solutionHide solution

    \[|e^{i\theta}-1|=|e^{i\theta/2}-e^{-i\theta/2}|=2|\sin(\theta/2)|\le|\theta|\], since \(|\sin u|\le|u|\).

  3. The approximate QFT bound adds errors linearly. Why is that safe even though the omitted gates are not the last ones in the circuit?

    Show solutionHide solution

    The composition argument writes the difference between two products as a sum of terms, each containing one error factor surrounded by unitaries. Unitaries preserve lengths, so the position of an error inside the circuit does not amplify it. That is why the bound holds regardless of where the omitted gates sit.

4.2

Phase Estimation

The Hadamard test reads an eigenphase one noisy bit at a time, so precision \(\epsilon\) costs about \(1/\epsilon^2\) runs. Can we read many digits of the phase at once? Controlled powers of the unitary kick back a clock pattern onto a register of control qubits, and the inverse Fourier transform reads that pattern. We first do this for a phase that is an exact grid point, then bound how well it works for any phase. Finally we ask what happens when the target is not an eigenstate at all.

4.2.1 Controlled powers and kickback§

phase estimationcontrolled powers

How do we write a clock pattern whose step is an unknown eigenphase? Let \(U\) be a unitary with eigenstate \(\ket u\) and eigenvalue \(e^{2\pi i\phi}\), where \(0\le\phi<1\). Phase estimation is the task of finding \(\phi\). Assume we can prepare \(\ket u\) and apply controlled-\(U^{2^j}\) for \(j=0,\ldots,m-1\).

Take \(m\) control qubits, each in \(\ket+\). Control qubit \(j\) (counting the lowest as \(j=0\)) controls \(U^{2^j}\), which kicks back \(e^{2\pi i\,2^j\phi}\) onto its \(\ket1\) branch, because \(U^k\ket u=e^{2\pi ik\phi}\ket u\). The target stays \(\ket u\). The control register becomes

\[\bigotimes_{j=m-1}^{0}\frac{\ket0+e^{2\pi i\,2^j\phi}\ket1}{\sqrt2}=\frac{1}{\sqrt{2^m}}\sum_{k=0}^{2^m-1}e^{2\pi ik\phi}\ket k,\]

where the equality expands the product: a basis state \(\ket k\) with bits \(k_j\) collects the phase \(\prod_je^{2\pi i\,k_j2^j\phi}=e^{2\pi ik\phi}\). This state is the steady phase ramp the Fourier transform was built to read.

Phase estimation with three control qubitsThe target holds an eigenstate |u⟩ of U with eigenvalue e^(2π iφ). Control j applies U^(2ʲ) and receives the phase e^(2π i2ʲφ); the inverse Fourier transform F† (a composite operation) maps the resulting phase ramp to the digits of φ. Read each circuit left to right; double lines carry classical measurement records.Phase estimation with three control qubits|0⟩j₂|0⟩j₁|0⟩j₀|u⟩|u⟩HHHUU²U⁴F†
The target holds an eigenstate \(\ket u\) of \(U\) with eigenvalue \(e^{2\pi i\phi}\). Control \(j\) applies \(U^{2^j}\) and receives the phase \(e^{2\pi i2^j\phi}\); the inverse Fourier transform \(F^\dagger\) (a composite operation) maps the resulting phase ramp to the digits of \(\phi\).

The controlled powers are the expensive part. Controlled-\(U^{2^j}\) built by repeating controlled-\(U\) costs \(2^j\) uses, so all powers together cost \(1+2+\cdots+2^{m-1}=2^m-1\) uses of controlled-\(U\). Each extra bit of precision doubles the cost. For some unitaries, \(U^{2^j}\) has a shortcut. Modular multiplication by \(a\), raised to the power \(2^j\), is multiplication by \(a^{2^j}\bmod L\), which costs the same as multiplication by \(a\) once \(a^{2^j}\) is precomputed classically. That shortcut is what makes Shor’s algorithm efficient. For many other unitaries, including those that simulate physical systems, there is generally no such shortcut, and the doubling is real.

Problems
  1. For \(m=2\) and \(\phi=1/4\), write the control register after the controlled powers.

    Show solutionHide solution

    Phases \(e^{2\pi ik/4}=i^k\): \(\frac12(\ket0+i\ket1-\ket2-i\ket3)\). In product form, the high control (which controls \(U^2\)) gets \(e^{2\pi i\cdot2/4}=-1\), and the low control gets \(i\): \(\frac{1}{\sqrt2}(\ket0-\ket1)\otimes\frac{1}{\sqrt2}(\ket0+i\ket1)\).

  2. How many uses of controlled-\(U\) does phase estimation with \(m=20\) need if powers are made by repetition?

    Show solutionHide solution

    \(2^{20}-1=1{,}048{,}575\). Precision of about \(10^{-6}\) costs about a million uses: the cost scales as \(1/\epsilon\).

  3. Why must the eigenstate \(\ket u\) be the same for every controlled power, and what happens if each power is applied to a fresh copy of \(\ket u\) instead?

    Show solutionHide solution

    Kickback leaves \(\ket u\) unchanged, so one copy can serve all the controlled powers. Using fresh copies also works when \(\ket u\) is an exact eigenstate: each copy factors out. The difference matters when the target is a superposition of eigenstates: with one shared target, all controls are kicked by the same eigenvalue, so the outcome reflects a single eigenphase. With separate copies, different controls would sample different eigenphases and the bits would not form a consistent estimate.

4.2.2 Exact phases§

inverse quantum Fourier transform

When does the inverse transform read the phase perfectly? Compare the control register with the Fourier transform of a basis state. With \(M=2^m\),

\[F_M\ket j=\frac{1}{\sqrt M}\sum_ke^{2\pi ijk/M}\ket k.\]

If \(\phi=j/M\) exactly, for an integer \(j\), the control register is \(F_M\ket j\). Applying the inverse quantum Fourier transform \(F_M^\dagger\) returns \(\ket j\), and measuring gives \(j\) with certainty. In binary, \(\phi=0.j_{m-1}\cdots j_0\): phase estimation reads the first \(m\) binary digits of the phase.

Here is an \(m=3\) example. Let \(\phi=3/8=0.011_2\). The controls receive phases \(e^{2\pi i\cdot3/8}\) (lowest, from \(U\)), \(e^{2\pi i\cdot6/8}\) (from \(U^2\)), and \(e^{2\pi i\cdot12/8}=e^{2\pi i\cdot4/8}=-1\) (highest, from \(U^4\)). The register is \(F_8\ket3\), and \(F_8^\dagger\) maps it to \(\ket{011}\).

Phase estimation for φ = 3/8 = 0.011 in binaryEach control qubit carries the phase 2ʲφ modulo one, which depends only on the digits of φ after position j. The highest control holds the last digit as a sign; the inverse Fourier transform removes the known contributions and reads every digit exactly. Columns: Control, Applies, Phase 2ʲφ mod 1, Binary. j=0 (lowest), U, 3/8, 0.011; j=1, U², 6/8, 0.11; j=2 (highest), U⁴, 4/8, 0.1Phase estimation for φ = 3/8 = 0.011 in binaryControlAppliesPhase 2ʲφ mod 1Binaryj=0 (lowest)U3/80.011j=1U²6/80.11j=2 (highest)U⁴4/80.1
Each control qubit carries the phase \(2^j\phi\) modulo one, which depends only on the digits of \(\phi\) after position \(j\). The highest control holds the last digit as a sign; the inverse Fourier transform removes the known contributions and reads every digit exactly.

The product form explains why the digits come out separately. Control qubit \(j\) carries phase \(e^{2\pi i\,2^j\phi}\), and multiplying \(\phi\) by \(2^j\) shifts its binary point, so modulo one this phase depends only on the digits of \(\phi\) from position \(j+1\) onward. The highest control, with \(U^{2^{m-1}}\), carries \(e^{2\pi i\,0.j_0}=\pm1\): it holds the last digit as a sign, readable by a single Hadamard. The others need the controlled phase corrections inside \(F_M^\dagger\), which subtract the contributions of digits already known. If we measure the highest control first, those corrections can be applied classically, one digit at a time, so a single control qubit suffices; we build that version once measurement becomes a technique of its own.

Problems
  1. For \(m=2\) and \(\phi=1/4\), apply \(F_4^\dagger\) to the control register \(\frac12(\ket0+i\ket1-\ket2-i\ket3)\) left by the controlled powers.

    Show solutionHide solution

    The register \(\frac12(\ket0+i\ket1-\ket2-i\ket3)\) is the column \(x=1\) of \(F_4\), that is \(F_4\ket1\). So \(F_4^\dagger\) gives \(\ket1=\ket{01}\), and \(\phi=1/4=0.01_2\).

  2. For \(m=3\), which outcomes are possible when \(\phi=1/2\)? When \(\phi=0\)?

    Show solutionHide solution

    \(\phi=1/2=4/8\) gives \(j=4=100\) with certainty. \(\phi=0\) gives \(j=0\). Both are exact grid points.

  3. A student applies \(F_M\) instead of \(F_M^\dagger\) at the end. What is measured for \(\phi=3/8\), \(m=3\)?

    Show solutionHide solution

    \(F_8\cdot F_8\ket3=\ket{-3\bmod8}=\ket5\), since \(F_N^2\ket x=\ket{-x\bmod N}\). The output is \(5\), corresponding to \(5/8=1-3/8\): the sign of the phase is reversed. With the opposite sign convention for \(F\), the roles of \(F\) and \(F^\dagger\) swap; consistency between kickback sign and transform sign is what matters.

4.2.3 Resolution and success probability§

phase resolution

Most phases are not exact multiples of \(1/M\). Then the inverse transform cannot concentrate all amplitude on one outcome. How much lands near the right answer?

The amplitude of outcome \(j\) is the overlap of the register with \(F_M\ket j\):

\[a_j=\frac1M\sum_{k=0}^{M-1}e^{2\pi ik(\phi-j/M)}.\]

Write \(\Delta=\phi-j/M\). This is a geometric series with ratio \(e^{2\pi i\Delta}\), so

\[|a_j|^2=\frac{1}{M^2}\left|\frac{1-e^{2\pi iM\Delta}}{1-e^{2\pi i\Delta}}\right|^2=\frac{\sin^2(\pi M\Delta)}{M^2\sin^2(\pi\Delta)}.\]

For the nearest grid point, \(|\Delta|\le\frac{1}{2M}\). Using \(|\sin(\pi M\Delta)|\ge2M|\Delta|\) (since \(\sin u\ge2u/\pi\) on \([0,\pi/2]\)) and \(|\sin\pi\Delta|\le\pi|\Delta|\), we get \(|a_j|^2\ge4/\pi^2\approx0.405\). The distribution is peaked around \(M\phi\), and falls off roughly as \(1/(M\Delta)^2\).

Phase estimation for a phase between grid pointsOutcome probabilities for M=8 and φ=0.3, so Mφ=2.4. The two nearest grid points 2 and 3 carry probability about 0.84; the distribution falls off roughly as the inverse square of the distance from Mφ. Horizontal axis: outcome j; vertical axis: probability. Phase estimation for a phase between grid points00.20.40.601234567outcome jprobabilityMφ=2.4
Outcome probabilities for \(M=8\) and \(\phi=0.3\), so \(M\phi=2.4\). The two nearest grid points 2 and 3 carry probability about 0.84; the distribution falls off roughly as the inverse square of the distance from \(M\phi\).

For \(M=8\) and \(\phi=0.3\), so that \(M\phi=2.4\), the outcomes \(2\) and \(3\) have probabilities about \(0.58\) and \(0.26\); together \(0.84\). The phase resolution is \(1/M\): outcomes within one grid spacing are likely, and outcomes \(e\) spacings away have probability falling like \(1/e^2\). How do we buy more confidence? A quoted bound (Cleve, Ekert, Macchiavello, and Mosca, 1998; Nielsen and Chuang, Section 5.2.1) says that to obtain \(\phi\) to within \(2^{-t}\) with probability at least \(1-\delta\), it suffices to use \(m=t+\lceil\log_2(2+1/(2\delta))\rceil\) control qubits. Repetition also works. Suppose each run lands within the target interval with probability above one half, and we take the median of \(R\) runs. The median falls outside the interval only if at least half the runs do, and by the majority-vote bound that probability falls exponentially in \(R\).

In terms of cost: precision \(\epsilon\) needs \(M\approx1/\epsilon\), hence about \(1/\epsilon\) uses of controlled-\(U\). Compare the Hadamard test, whose \(1/\epsilon^2\) runs each used \(U\) once. This quadratic improvement, \(1/\epsilon\) instead of \(1/\epsilon^2\), comes from coherence across the controlled powers, and amplitude estimation will achieve the same improvement for probabilities.

Problems
  1. For \(M=4\) and \(\phi=1/8\), compute the probabilities of outcomes \(0\) and \(1\).

    Show solutionHide solution

    For \(j=0\), \(\Delta=1/8\): \(\sin^2(\pi/2)/(16\sin^2(\pi/8))=1/(16\times0.1464)\approx0.427\). For \(j=1\), \(\Delta=-1/8\): the same, \(0.427\). The phase sits exactly between two grid points, and each neighbour gets about \(0.43\), just above \(4/\pi^2\).

  2. How many control qubits give \(\phi\) to within \(2^{-10}\) with probability at least \(0.99\), by the bound above?

    Show solutionHide solution

    \(1/(2\delta)=50\), so \(\lceil\log_2 52\rceil=6\), and \(m=16\). That costs \(2^{16}-1=65{,}535\) uses of controlled-\(U\).

  3. Why does the nearest-grid-point bound \(4/\pi^2\) not tell us the probability of an answer within \(1/M\) of \(\phi\)? Give a better lower bound for that event.

    Show solutionHide solution

    An answer within \(1/M\) includes the two grid points bracketing \(\phi\), not just the nearest one. Their probabilities sum to at least \(8/\pi^2\approx0.81\): with \(\Delta\) and \(\Delta-1/M\) on either side, the sum \[\frac{\sin^2(\pi M\Delta)}{M^2}\big(\frac{1}{\sin^2\pi\Delta}+\frac{1}{\sin^2\pi(1/M-\Delta)}\big)\] is minimized when \(\phi\) is midway, giving at least \(8/\pi^2\).

4.2.4 Superpositions of eigenstates§

eigenbasis expansion

What if the target is not an eigenstate? We would like to write it as a combination of eigenstates and let linearity handle each one. Two facts are needed. First, eigenstates of a unitary with different eigenvalues are orthogonal. Suppose \(U\ket u=\lambda\ket u\) and \(U\ket v=\mu\ket v\) with \(\lambda\neq\mu\). Then

\[\braket uv=\braket{Uu}{Uv}=\lambda^*\mu\braket uv.\]

Since \(|\lambda|=1\), \(\lambda^*=1/\lambda\), so \(\lambda^*\mu=\mu/\lambda\neq1\), and therefore \(\braket uv=0\). Second, the eigenstates of a unitary can be chosen to form an orthonormal basis. This is the spectral theorem of linear algebra, which we assume. Together they let us write any state as \(\ket\psi=\sum_sc_s\ket{u_s}\), with \(U\ket{u_s}=e^{2\pi i\phi_s}\ket{u_s}\) and \(\sum_s|c_s|^2=1\). This eigenbasis expansion is the key: phase estimation is linear, so it acts on each term separately:

\[\ket{0^m}\ket\psi\longmapsto\sum_sc_s\,\ket{\tilde\phi_s}\ket{u_s},\]

where \(\ket{\tilde\phi_s}\) is the control register that phase \(\phi_s\) would produce. Measuring the controls returns an estimate of one \(\phi_s\), chosen with probability \(|c_s|^2\), and leaves the target close to \(\ket{u_s}\) (exactly, if the phases are distinct grid points).

Phase estimation on a superposition of eigenstatesFor |ψ⟩=Σ_sc_s|u_s⟩, phase estimation returns an estimate of one eigenphase φ_s, chosen with probability |c_s|², and leaves the target close to |u_s⟩. It samples eigenvalues; it does not list them. Columns: Target component, Outcome, Probability, Target afterwards. c₀|u₀⟩, estimate of φ₀, |c₀|², ≈|u₀⟩; c₁|u₁⟩, estimate of φ₁, |c₁|², ≈|u₁⟩; vdots, vdots, vdots, vdotsPhase estimation on a superposition of eigenstatesTarget componentOutcomeProbabilityTarget afterwardsc₀|u₀⟩estimate of φ₀|c₀|²≈|u₀⟩c₁|u₁⟩estimate of φ₁|c₁|²≈|u₁⟩vdotsvdotsvdotsvdots
For \(\ket\psi=\sum_sc_s\ket{u_s}\), phase estimation returns an estimate of one eigenphase \(\phi_s\), chosen with probability \(|c_s|^2\), and leaves the target close to \(\ket{u_s}\). It samples eigenvalues; it does not list them.

Two consequences shape what follows. First, phase estimation samples eigenvalues; it does not list them. To learn the eigenvalue of one particular eigenstate \(\ket{u_0}\), we need an initial state with substantial overlap \(|c_0|^2\) with it, and the expected number of repetitions is about \(1/|c_0|^2\). Preparing such a state can be the hard part. Second, phase estimation followed by measurement prepares an eigenstate. That makes it a filter. Polynomial transformations, developed later, refine this filter so that it acts on all eigenvalues coherently without measuring.

Order finding, next, exploits the first consequence in an unusual way: there, the easy-to-prepare state \(\ket1\) is an equal superposition of eigenstates, and the random eigenphase it yields is exactly what we need.

Problems
  1. \(U=Z\) and \(\ket\psi=\cos\theta\ket0+\sin\theta\ket1\). With one control qubit, what outcomes occur and with what probabilities?

    Show solutionHide solution

    The eigenphases are \(\phi=0\) for \(\ket0\) and \(\phi=1/2\) for \(\ket1\). With \(m=1\) both are exact. Outcome \(0\) with probability \(\cos^2\theta\) (target left in \(\ket0\)), outcome \(1\) with probability \(\sin^2\theta\) (target \(\ket1\)).

  2. If the ground state has overlap \(|c_0|^2=0.01\) with the initial state, how many runs of phase estimation are expected before the ground energy appears?

    Show solutionHide solution

    Each run yields the ground eigenphase with probability about \(0.01\), so on average about 100 runs. And recognizing it requires knowing it is the smallest observed, which needs enough runs to be confident no lower value was missed.

  3. Is the post-measurement target always an exact eigenstate? Consider two eigenphases that round to the same outcome.

    Show solutionHide solution

    No. If two eigenphases \(\phi_1\ne\phi_2\) both produce substantial amplitude on outcome \(j\), observing \(j\) leaves the target in a superposition of \(\ket{u_1}\) and \(\ket{u_2}\). Phase estimation resolves eigenvalues only to within its resolution \(1/M\). Eigenstates whose phases differ by less than that are not separated.

4.3

Order Finding

Take integers \(a\) and \(L\) with no common factor, and multiply by \(a\) repeatedly modulo \(L\). How long until we return to \(1\)? No efficient classical method for answering this is known. Phase estimation could answer it if the answer were an eigenphase of a unitary we can implement. We build that unitary from modular multiplication and find that the answer appears in the denominators of its eigenphases. An easy state turns out to be a superposition of exactly the right eigenstates. The sample it yields is only an approximation, so we finally need a classical way to recover a fraction with small denominator from a close approximation.

4.3.1 Modular multiplication as a unitary§

ordermodular exponentiation

Which unitary carries the question? Let \(L\) have \(n\) bits and \(\gcd(a,L)=1\). On an \(n\)-qubit register define

\[U_a\ket y=\ket{ay\bmod L}\quad(0\le y<L),\qquad U_a\ket y=\ket y\quad(L\le y<2^n).\]

Because \(a\) has an inverse modulo \(L\), multiplication by \(a\) permutes the residues \(0,\ldots,L-1\), so \(U_a\) is a permutation and hence unitary. It can be built from reversible modular addition, using \(O(n^2)\) gates with schoolbook arithmetic.

The return time is visible in the orbit of \(1\): \(1\to a\to a^2\to\cdots\to a^{r-1}\to1\). Take \(L=15\), \(a=7\):

\[1\to7\to49\bmod15=4\to28\bmod15=13\to91\bmod15=1,\]

The smallest \(r>0\) with \(a^r\equiv1\pmod L\) is the order of \(a\) modulo \(L\), so here \(r=4\). Classically, finding \(r\) by stepping along the orbit takes up to \(r\) steps, and \(r\) can be nearly as large as \(L\), exponential in \(n\).

The orbit of 1 under multiplication by 7 modulo 15U₇ cycles 1→7→4→13→1, so the order is r=4. Classically, finding r by following the orbit can take a number of steps comparable to L. Columns: k, 0, 1, 2, 3, 4. 7ᵏ mod 15, 1, 7, 4, 13, 1The orbit of 1 under multiplication by 7 modulo 15k012347ᵏ mod 15174131
\(U_7\) cycles \(1\to7\to4\to13\to1\), so the order is \(r=4\). Classically, finding \(r\) by following the orbit can take a number of steps comparable to \(L\).

For phase estimation we need controlled-\(U_a^{2^j}\). Since \(U_a^{2^j}=U_{a^{2^j}\bmod L}\), compute \(a^{2^j}\bmod L\) classically by repeated squaring, \(m\) squarings in all, and build a controlled multiplier by that constant. All the controlled powers together form modular exponentiation, \(\ket k\ket y\mapsto\ket k\ket{a^ky\bmod L}\), which costs \(m\) controlled multiplications, \(O(mn^2)\) gates. This avoids the exponential cost of building each power by repeating controlled-\(U_a\).

Problems
  1. Find the order of \(2\) modulo \(21\) by listing powers.

    Show solutionHide solution

    \(2,4,8,16,32\bmod21=11,22\bmod21=1\). So \(r=6\).

  2. Why must \(\gcd(a,L)=1\) for \(U_a\) to be unitary? Give a counterexample with \(L=15\).

    Show solutionHide solution

    If \(a\) shares a factor with \(L\), multiplication by \(a\) is not injective modulo \(L\). For \(a=5\): \(5\cdot0=0\) and \(5\cdot3=15\equiv0\), so \(\ket0\) and \(\ket3\) map to the same state, which no unitary can do. (Finding such an \(a\) by luck would factor \(L\) directly, via \(\gcd(a,L)\).)

  3. Compute \(7^{2^j}\bmod15\) for \(j=0,1,2\) by repeated squaring, and say which multipliers the phase estimation circuit with \(m=3\) uses.

    Show solutionHide solution

    \(7^1=7\), \(7^2=49\equiv4\), \(7^4=4^2=16\equiv1\). The controlled multipliers are by \(7\), \(4\), and \(1\); the last is the identity, consistent with \(r=4\) dividing \(4\).

4.3.2 Eigenstates and the sample s/r§

order finding

What are the eigenstates of \(U_a\)? Since \(U_a\) cycles \(1\to a\to\cdots\to a^{r-1}\to1\), it acts on the orbit like a shift on \(r\) positions. We saw with periodic states that the Fourier transform turns a shift into a phase, so Fourier-type states on the orbit should be eigenstates. For \(s=0,1,\ldots,r-1\), define

\[\ket{u_s}=\frac{1}{\sqrt r}\sum_{k=0}^{r-1}e^{-2\pi isk/r}\ket{a^k\bmod L}.\]

Applying \(U_a\) shifts \(k\) to \(k+1\), and the same substitution we used for the phase-gradient state gives \(U_a\ket{u_s}=e^{2\pi is/r}\ket{u_s}\). The eigenphases are \(s/r\): the order is in the denominator.

We cannot prepare \(\ket{u_s}\) without knowing \(r\). But we do not need to. Sum over \(s\):

\[\frac{1}{\sqrt r}\sum_{s=0}^{r-1}\ket{u_s}=\frac1r\sum_k\Big(\sum_se^{-2\pi isk/r}\Big)\ket{a^k}=\ket1,\]

because the inner sum is \(r\) for \(k=0\) and \(0\) otherwise. The state \(\ket1\), trivial to prepare, is an equal superposition of all \(r\) eigenstates. This is the heart of order finding: since phase estimation acts on a superposition of eigenstates term by term, phase estimation on \(\ket1\) returns an estimate of \(s/r\) for a uniformly random \(s\in\{0,\ldots,r-1\}\).

Order finding by phase estimationThe control register has m≈2n qubits; the target has n qubits and starts in |1⟩, an equal superposition of the eigenstates |u_s⟩. The modular exponentiation box, |k⟩|y⟩↦|k⟩|aᵏy mod L⟩, is the controlled powers and contains most of the gates. Read each circuit left to right; double lines carry classical measurement records.Order finding by phase estimation|0^m⟩j≈2^m s/r|1⟩H^(⊗ m)aᵏ y mod LF†
The control register has \(m\approx2n\) qubits; the target has \(n\) qubits and starts in \(\ket1\), an equal superposition of the eigenstates \(\ket{u_s}\). The modular exponentiation box, \(\ket k\ket y\mapsto\ket k\ket{a^ky\bmod L}\), is the controlled powers and contains most of the gates.

For \(L=15\), \(a=7\), \(r=4\), and \(m=3\) control qubits, the phases \(s/4\in\{0,\frac14,\frac12,\frac34\}\) are exact grid points \(j/8\) with \(j\in\{0,2,4,6\}\). Each outcome occurs with probability \(\frac14\). The outcome \(6\) gives \(6/8=3/4\), so \(r=4\). The outcome \(4\) gives \(1/2\), which suggests \(r=2\); checking \(7^2\bmod15=4\neq1\) rejects it, and another run is needed. The outcome \(0\) gives nothing.

Problems
  1. Verify \(U_a\ket{u_1}=e^{2\pi i/4}\ket{u_1}\) for \(L=15\), \(a=7\).

    Show solutionHide solution

    \(\ket{u_1}=\frac12(\ket1-i\ket7-\ket4+i\ket{13})\). Applying \(U_7\): \(\ket1\to\ket7\), \(\ket7\to\ket4\), \(\ket4\to\ket{13}\), \(\ket{13}\to\ket1\). Result: \[\frac12(\ket7-i\ket4-\ket{13}+i\ket1)=i\cdot\frac12(\ket1-i\ket7-\ket4+i\ket{13})\]. And \(e^{2\pi i/4}=i\).

  2. With \(r=6\) and \(s\) uniform, what is the probability that \(\gcd(s,6)=1\), so that the reduced fraction \(s/r\) has denominator exactly \(6\)?

    Show solutionHide solution

    \(s\in\{1,5\}\) out of six values: probability \(1/3\). Otherwise the fraction reduces (\(2/6=1/3\), \(3/6=1/2\), …) and yields a divisor of \(r\). Combining the denominators from two runs by their least common multiple recovers \(r\) with good probability.

  3. Why does it not matter that phase estimation is run on \(\ket1\) rather than on a single eigenstate, given that the answer we want is \(r\), not a particular \(s\)?

    Show solutionHide solution

    Every eigenphase \(s/r\) carries the same denominator \(r\) (before reduction). A random \(s\) is as good as a chosen one, and often better: we could not choose \(s\) anyway. The randomness costs only occasional reductions \(\gcd(s,r)>1\), which repetition handles.

4.3.3 Continued fractions§

continued fractionconvergent

When \(r\) does not divide \(2^m\), phase estimation returns an integer \(j\) with \(j/2^m\approx s/r\). How do we recover \(r\) from an approximation? Two facts help. The fraction \(s/r\) has a small denominator, \(r<L\), and the approximation can be made very good. We need a way to find the fractions with small denominators that lie close to a given number.

Euclid’s algorithm supplies one. Take a worked case. Let \(L=21\) and \(a=2\). The powers of \(2\) modulo \(21\) are \(2,4,8,16,11,1\), so \(r=6\). Take \(m=9\), so \(2^m=512\). Suppose \(s=1\); then \(512/6\approx85.3\), and the most likely outcome is \(j=85\). Run Euclid on \(85/512\):

\[512=6\cdot85+2,\qquad85=42\cdot2+1,\qquad2=2\cdot1.\]

The quotients say that

\[\frac{85}{512}=\cfrac{1}{6+\cfrac{1}{42+\cfrac12}},\]

written \([0;6,42,2]\). An expression \(a_0+1/(a_1+1/(a_2+\cdots))\) of this kind is a continued fraction. Stopping it early gives the convergents, here \(0\), \(\tfrac16\), \(\tfrac{42}{253}\), \(\tfrac{85}{512}\). Each convergent is a fraction with a small denominator that approximates the number well. The last convergent with denominator below \(L=21\) is \(1/6\). Candidate \(r=6\); check \(2^6=64\equiv1\pmod{21}\). Confirmed.

When is the fraction we want guaranteed to be a convergent? Number theory supplies the answer, which we quote (Legendre’s theorem; see Hardy and Wright, An Introduction to the Theory of Numbers, Theorem 184): if

\[\left|\frac{j}{2^m}-\frac sr\right|<\frac{1}{2r^2},\]

then \(s/r\), in lowest terms, is one of the convergents of \(j/2^m\). How many control qubits make this hold? When phase estimation returns the nearest grid point, \(|j/2^m-s/r|\le1/2^{m+1}\). Since \(r<L\), it suffices that \(1/2^{m+1}\le1/(2L^2)\), that is, \(2^m\ge L^2\), or about \(m=2n\). In the example, \(512\ge441\), and indeed \(|85/512-1/6|=1/1536<1/72\).

Recovering r = 6 from the outcome 85/512Euclid’s algorithm gives 85/512=[0;6,42,2]. The last convergent with denominator below L=21 is 1/6, so the candidate order is 6, confirmed by 2⁶≡1 (mod 21). Columns: Euclid step, Quotient, Convergent. 85/512: 0 whole parts, a₀=0, 0/1; 512=6·85+2, a₁=6, 1/6; 85=42·2+1, a₂=42, 42/253; 2=2·1, a₃=2, 85/512Recovering r = 6 from the outcome 85/512Euclid stepQuotientConvergent85/512: 0 whole partsa₀=00/1512=6·85+2a₁=61/685=42·2+1a₂=4242/2532=2·1a₃=285/512
Euclid’s algorithm gives \(85/512=[0;6,42,2]\). The last convergent with denominator below \(L=21\) is \(1/6\), so the candidate order is 6, confirmed by \(2^6\equiv1\pmod{21}\).

The overall order-finding procedure is then: run phase estimation on \(\ket1\) with \(m\approx2n+1\); compute the continued-fraction convergents of \(j/2^m\); for each denominator \(q<L\), test whether \(a^q\equiv1\); combine denominators from a few runs by least common multiples if needed. Why might a run fail? The nearest grid point appears with probability at least \(4/\pi^2\). And if \(s\) and \(r\) share a factor, the convergent is \(s/r\) in lowest terms, whose denominator is only a divisor of \(r\). The chance that a random \(s\) shares no factor with \(r\) is at least of order \(1/\log\log r\), a quoted number-theory estimate (Shor, 1997), and in practice usually much larger; a constant number of repetitions, plus classical checks, gives high confidence. The quantum part does one thing: it produces a sample of \(s/r\) to high precision. Everything else is classical number theory.

Problems
  1. Phase estimation with \(m=4\) returns \(j=13\), and the order is known to satisfy \(r\le5\). Use continued fractions to find \(s/r\).

    Show solutionHide solution

    Euclid on \(13/16\): \(16=1\cdot13+3\), \(13=4\cdot3+1\), \(3=3\cdot1\). So \(13/16=[0;1,4,3]\), with convergents \(0\), \(1\), \(\tfrac45\), \(\tfrac{13}{16}\). The last convergent with denominator at most 5 is \(4/5\), and \(|13/16-4/5|=1/80<1/(2\cdot5^2)\), so it meets the convergent condition. Candidate \(r=5\), to be checked by computing \(a^5\bmod L\).

  2. In the \(L=21\) example, suppose the run returns \(j=171\) (from \(s=2\)). What does the continued fraction give, and what should be done?

    Show solutionHide solution

    \(171/512\approx0.334\). Euclid: \(512=2\cdot171+170\), \(171=1\cdot170+1\), \(170=170\cdot1\). Convergents \(0,\tfrac12,\tfrac13,\ldots\). The best with small denominator is \(1/3\) (\(s/r=2/6\) reduced). Test \(2^3=8\not\equiv1\): rejected. The denominator 3 divides \(r\). A second run giving, say, denominator 2 or 6 lets us take the lcm: \(\mathrm{lcm}(3,2)=6\), which checks.

  3. Why is \(m\approx2n\) needed rather than \(m\approx n\)?

    Show solutionHide solution

    Two distinct fractions with denominators below \(L\) can be as close as about \(1/L^2\). To single out \(s/r\) among them we need error below \(1/(2r^2)\ge1/(2L^2)\), which requires resolution \(2^{-m}\) of order \(1/L^2\), so \(m\approx2\log_2L=2n\). With only \(n\) bits, several small-denominator fractions would be consistent with the measurement.

4.4

Factoring and Hidden Structure

We can now find orders efficiently. Why would anyone want orders? Because a short classical argument turns an order into a factor of \(L\). With that argument the algorithm is complete, and we can ask what it costs in gates and qubits. Then we ask which feature of order finding, shared with Simon’s problem, made Fourier sampling work, and for which other groups the same strategy succeeds.

4.4.1 From order to factors§

Shor’s algorithmfactoring reduction

How can an order reveal a factor? Suppose \(L\) is odd, not a prime power, and we want a nontrivial factor. Pick \(a\) at random in \(\{2,\ldots,L-1\}\). If \(\gcd(a,L)>1\), we have a factor already. Otherwise find the order \(r\) of \(a\). If \(r\) is even, then

\[a^r-1=(a^{r/2}-1)(a^{r/2}+1)\equiv0\pmod L.\]

So \(L\) divides the product. It does not divide \(a^{r/2}-1\), since \(r\) is the smallest exponent with \(a^r\equiv1\). If also \(a^{r/2}\not\equiv-1\pmod L\), then \(L\) does not divide \(a^{r/2}+1\) either, and the prime factors of \(L\) must be split between the two factors. Then \(\gcd(a^{r/2}-1,L)\) is a nontrivial factor, computed by Euclid’s algorithm.

For \(L=15\), \(a=7\), \(r=4\): \(7^2=49\equiv4\), and \(\gcd(3,15)=3\), \(\gcd(5,15)=5\). For \(L=21\), \(a=2\), \(r=6\): \(2^3=8\), \(\gcd(7,21)=7\), \(\gcd(9,21)=3\).

Shor’s reduction from factoring to order findingOnly the order-finding step is quantum. For odd L with at least two distinct prime factors, each random a succeeds with probability at least 1/2; failures lead back to a new random choice. Flowchart. Pick a random a. If gcd(a, L) > 1, a factor is found. Otherwise run quantum order finding to get r. If r is even and a^(r/2) is not −1 mod L, gcd(a^(r/2) ± 1, L) are factors; if not, pick a new a. Example L = 21, a = 2: gcd is 1, r = 6, 2^3 = 8 ≢ −1, and gcd(7, 21) = 7, gcd(9, 21) = 3.Shor’s reduction from factoring to order findingEXAMPLE L = 21yesnoyesno: new aPick random a, 1<a<Lgcd(a,L)>1?factor foundQuantum order finding: rr even anda^(r/2)≢−1?gcd(a^(r/2)±1,L) are factorsa=2gcd(2,21)=12⁶=64≡1, so r=6(the quantum step)r even; 2³=8≢−1 (mod 21)gcd(7,21)=7gcd(9,21)=3
Only the order-finding step is quantum. For odd \(L\) with at least two distinct prime factors, each random \(a\) succeeds with probability at least 1/2; failures lead back to a new random choice.

This factoring reduction can fail: \(r\) may be odd, or \(a^{r/2}\equiv-1\). For \(L=15\), \(a=14\) has \(r=2\) and \(14\equiv-1\), so the gcds are trivial. How often does it fail? For \(L=15\) the coprime choices are \(a=2,4,7,8,11,13,14\), and only \(a=14\) fails. A quoted number-theory result (Nielsen and Chuang, Appendix 4) says that for odd \(L\) with at least two distinct prime factors, a random coprime \(a\) succeeds with probability at least \(1/2\). So a few random choices suffice. This is Shor’s algorithm (1994/1997). Prime powers \(L=p^k\) are detected and factored classically.

Problems
  1. Factor \(L=35\) with \(a=2\), given that the order is \(r=12\).

    Show solutionHide solution

    \(2^6=64\equiv29\pmod{35}\), which is not \(-1\equiv34\). \(\gcd(28,35)=7\) and \(\gcd(30,35)=5\). So \(35=5\times7\).

  2. For \(L=15\), which \(a\in\{2,4,7,8,11,13,14\}\) lead to failure of the reduction?

    Show solutionHide solution

    Orders: \(2\to4\), \(4\to2\), \(7\to4\), \(8\to4\), \(11\to2\), \(13\to4\), \(14\to2\). Check \(a^{r/2}\): \(2^2=4\), \(4^1=4\), \(7^2=4\), \(8^2=4\), \(11^1=11\), \(13^2=4\), \(14^1=14\equiv-1\). Only \(a=14\) fails. (Also \(a=1\) trivially.) For \(a=11\): \(\gcd(10,15)=5\), \(\gcd(12,15)=3\), success.

  3. Why can the reduction not be used for prime \(L\), and how is that case handled?

    Show solutionHide solution

    A prime has no nontrivial factors; for prime \(L\) the gcds are always trivial. Primality is tested efficiently by classical algorithms (for example Miller–Rabin), so the algorithm checks primality first. Prime powers are detected by checking whether \(L^{1/k}\) is an integer for small \(k\).

4.4.2 Resources§

resource estimate

Where does the cost of Shor’s algorithm go? Take an \(n\)-bit \(L\) and follow the circuit from left to right.

Phase estimation needs about \(2n\) control qubits, and each controls one modular multiplication by a precomputed constant. With schoolbook arithmetic a multiplication costs \(O(n^2)\) gates, so modular exponentiation costs \(O(n^3)\) gates and dominates. Faster multiplication algorithms lower the exponent asymptotically. The arithmetic acts on an \(n\)-qubit target with \(O(n)\) workspace.

The inverse QFT on \(2n\) qubits then costs \(O(n^2)\) gates exactly, or \(O(n\log n)\) approximately. If its corrections are applied after measurement by classical feedback, one recycled control qubit replaces all \(2n\). What remains is classical: continued fractions, gcds and modular checks, all polynomial in \(n\), repeated over a few runs.

Where the cost of Shor’s algorithm goesAsymptotic counts for an n-bit modulus with schoolbook arithmetic. Concrete estimates for cryptographic sizes also depend on the error-correction scheme, physical error rates, and arithmetic optimizations. Columns: Component, Gates, Qubits. Modular exponentiation, O(n³), n plus O(n) workspace; Inverse QFT, O(n²), or O(nlog n) approximate, 2n, or 1 recycled; Continued fractions, gcd, classical, polynomial, none; Repetitions, a few runs, noneWhere the cost of Shor’s algorithm goesComponentGatesQubitsModular exponentiationO(n³)n plus O(n) workspaceInverse QFTO(n²), or O(nlog n)approximate2n, or 1 recycledContinued fractions, gcdclassical, polynomialnoneRepetitionsa few runsnone
Asymptotic counts for an \(n\)-bit modulus with schoolbook arithmetic. Concrete estimates for cryptographic sizes also depend on the error-correction scheme, physical error rates, and arithmetic optimizations.

Asymptotically this is polynomial, \(O(n^3)\), against the best known classical algorithm, the number field sieve, which runs in time roughly \(\exp(c\,n^{1/3}(\log n)^{2/3})\). The speedup is superpolynomial, but it is a comparison with the best known classical method: no proof rules out a fast classical factoring algorithm.

What does this mean for a real key? A concrete resource estimate must fix the error-correction scheme and hardware assumptions. Factoring a 2048-bit RSA modulus requires billions of logical operations, each protected by error correction. A careful 2019 estimate found about 20 million noisy physical qubits running for about eight hours (Gidney and Ekerå); a 2025 estimate by Gidney reduced this to under a million noisy qubits running for under a week, using improved arithmetic and error-correction techniques (Gidney 2025). Such estimates depend on assumed physical error rates and cycle times, and they change as methods improve.

Problems
  1. Roughly how much does the \(O(n^3)\) gate count grow from \(n=1024\) to \(n=2048\)?

    Show solutionHide solution

    By a factor of \(2^3=8\). The number field sieve’s running time grows by a much larger factor over the same range, which is why key sizes that are comfortable classically are vulnerable to a large quantum computer.

  2. Which part of Shor’s algorithm would you optimize first to reduce a resource estimate, and why?

    Show solutionHide solution

    Modular exponentiation: it contains almost all the gates (\(O(n^3)\) versus \(O(n^2)\) for the QFT) and much of the workspace. Practical improvements come from better arithmetic circuits (windowing, approximate or Montgomery arithmetic, coset representations) and from error-correction overheads for the Toffoli gates they use.

  3. “Shor’s algorithm proves that quantum computers are exponentially faster than classical ones.” Correct this statement.

    Show solutionHide solution

    Shor’s algorithm factors in polynomial time, superpolynomially faster than the best known classical algorithm. No one has proved that factoring requires superpolynomial classical time, so this is not a proof of separation. Moreover, the advantage holds for factoring and related problems (discrete logarithms), not for computation in general.

4.4.3 Hidden subgroup problems§

hidden subgroup problem

What do Simon’s problem and order finding have in common? In each, a function \(f\) on a group is constant on the cosets of a hidden subgroup and distinct across cosets. In Simon’s problem the group is \(\{0,1\}^n\) under XOR and the subgroup is \(\{0,s\}\). In order finding the group is the integers under addition and the subgroup is the multiples of \(r\), since \(a^x\) is constant on each coset \(x_0+r\mathbb Z\) and differs between cosets. The task in the hidden subgroup problem is to find the subgroup.

The algorithm is the same in both: evaluate \(f\) on a uniform superposition, measure the output to collapse onto a random coset, apply the Fourier transform of the group, and measure. The Fourier transform turns the random coset shift into a phase and leaves a sample that constrains the subgroup. Classical processing of a few samples recovers it.

Hidden subgroup problemsThe same pattern, superposition, evaluation, coset collapse, Fourier transform, sampling, solves the problem efficiently for abelian groups. For the nonabelian cases shown, no efficient quantum algorithm is known. Columns: Problem, Group, Hidden subgroup, Status. Simon, {0,1}ⁿ under XOR, {0,s}, efficient; Order finding, integers under +, multiples of r, efficient; Discrete logarithm, mathbb Z_N×mathbb Z_N, a line, efficient; Dihedral HSP, dihedral group, reflection subgroup, subexponential; Graph isomorphism, symmetric group, automorphisms, openHidden subgroup problemsProblemGroupHidden subgroupStatusSimon{0,1}ⁿ under XOR{0,s}efficientOrder findingintegers under +multiples of refficientDiscretelogarithmmathbb Z_N×mathbb Z_Na lineefficientDihedral HSPdihedral groupreflectionsubgroupsubexponentialGraph isomorphismsymmetric groupautomorphismsopen
The same pattern, superposition, evaluation, coset collapse, Fourier transform, sampling, solves the problem efficiently for abelian groups. For the nonabelian cases shown, no efficient quantum algorithm is known.

Does it work for every group? For every finite abelian group it works efficiently, as a quoted result. Discrete logarithms, the basis of elliptic-curve cryptography, are an abelian hidden subgroup problem over \(\mathbb Z_N\times\mathbb Z_N\), solved in Shor’s same paper. For some nonabelian groups, where the order of combination matters, the same Fourier sampling is known to give too little information per sample. A polynomial number of queries still suffices in principle, but no efficient way to process them is known. The table lists two such cases, the dihedral and symmetric groups; for the dihedral group the best known algorithm (Kuperberg) is subexponential, not polynomial.

Fourier methods resolve periodicity, but they return useful outcomes only with some probability, and estimating a quantity to precision \(\epsilon\) still costs on the order of \(1/\epsilon\) controlled operations. When a useful outcome has small probability, can we make it large without knowing the outcome in advance?

Problems
  1. Identify the group, the hidden subgroup, and the cosets for order finding with \(a=7\), \(L=15\), restricted to \(x\in\{0,\ldots,15\}\).

    Show solutionHide solution

    The group is the integers modulo \(16\) under addition (the control register). The hidden subgroup is \(\{0,4,8,12\}\), the multiples of \(r=4\). The cosets are \(\{0,4,8,12\}\), \(\{1,5,9,13\}\), \(\{2,6,10,14\}\), \(\{3,7,11,15\}\), on which \(7^x\bmod15\) takes the values \(1,7,4,13\).

  2. In Simon’s problem, what plays the role of the Fourier transform, and what plays the role of continued fractions?

    Show solutionHide solution

    The Hadamard transform \(H^{\otimes n}\) is the Fourier transform of \(\{0,1\}^n\) under XOR. Gaussian elimination over GF(2) plays the role of continued fractions: it combines the samples \(z\) with \(s\cdot z=0\) into the subgroup \(\{0,s\}\).

  3. Why does an efficient algorithm for the hidden subgroup problem on the symmetric group not follow from the abelian case, even though the same circuit can be written down?

    Show solutionHide solution

    The circuit can be written, and a polynomial number of queries suffices information-theoretically, but extracting the subgroup from the samples is the problem. For nonabelian groups the Fourier transform has matrix-valued components, the measured representation alone carries little information about many subgroups, and known measurements on single cosets cannot distinguish them efficiently. Whether some cleverer joint measurement on many cosets can be implemented efficiently is open.

Summary

Questions and worked problems

Attempt each question before opening a hint. Explain your reasoning, then compare it with the solution.

1. Quick check §

Compute F₈ applied to (|1⟩ + |5⟩)/√2.

Hint 1

The amplitude of y is (ω^y + ω^{5y})/4 with ω = e^{2πi/8}.

Hint 2

ω^{4y} = (−1)^y.

Worked solution

The amplitude of y is ω^y(1 + (−1)^y)/4, which is ω^y/2 for even y and 0 for odd y. So the output is ½(|0⟩ + ω²|2⟩ + ω⁴|4⟩ + ω⁶|6⟩) = ½(|0⟩ + i|2⟩ − |4⟩ − i|6⟩): period 4 gives frequencies at multiples of 2, with phases set by the offset 1.

Revisit the relevant explanation

2. Quick check §

Use the product representation to write \(F_8\ket5\) as a product of three one-qubit states, highest output bit first. Check one amplitude against the definition \(F_8\ket x=\frac{1}{\sqrt8}\sum_y\omega^{xy}\ket y\).

Hint 1

\(5=101_2\), so \(x_2=1,x_1=0,x_0=1\).

Hint 2

The factors carry the binary fractions \(0.x_0\), \(0.x_1x_0\), and \(0.x_2x_1x_0\).

Worked solution

The three phases are \(e^{2\pi i\,0.1_2}=-1\), \(e^{2\pi i\,0.01_2}=i\), and \(e^{2\pi i\,0.101_2}=e^{2\pi i\cdot5/8}\). So \(F_8\ket5=\frac{\ket0-\ket1}{\sqrt2}\otimes\frac{\ket0+i\ket1}{\sqrt2}\otimes\frac{\ket0+e^{5\pi i/4}\ket1}{\sqrt2}\). Check \(y=7=111_2\): the product gives \((-1)(i)e^{5\pi i/4}/\sqrt8=e^{i\pi(1+1/2+5/4)}/\sqrt8=e^{11\pi i/4}/\sqrt8=e^{3\pi i/4}/\sqrt8\). The definition gives \(\omega^{35}/\sqrt8=e^{2\pi i\cdot35/8}/\sqrt8=e^{2\pi i\cdot3/8}/\sqrt8=e^{3\pi i/4}/\sqrt8\). They agree.

Revisit the relevant explanation

3. Quick check §

Take \(L=15\) and \(a=4\). Find the order \(r\), list the phase-estimation outcomes with \(m=3\) control qubits and their probabilities, and say whether the factoring reduction succeeds.

Hint 1

\(4^2=16\equiv1\pmod{15}\).

Hint 2

The eigenphases are \(s/r\), and with \(m=3\) they are grid points \(j/8\).

Worked solution

The order is \(r=2\). Starting from \(\ket1\), phase estimation returns \(s/2\) for \(s\in\{0,1\}\), which are the exact grid points \(0/8\) and \(4/8\): outcomes \(0\) and \(4\), each with probability \(1/2\). Outcome \(4\) gives \(1/2\), so \(r=2\), confirmed by \(4^2\equiv1\). Outcome \(0\) gives nothing and the run is repeated. For the reduction, \(r\) is even and \(4^{1}=4\not\equiv-1\pmod{15}\), so \(\gcd(4-1,15)=3\) and \(\gcd(4+1,15)=5\) are the factors.

Revisit the relevant explanation

4. Worked problem §

Phase estimation with m = 4 is applied to an eigenstate with φ = 0.2. Which two outcomes are most likely, and approximately what are their probabilities?

Hint 1

Mφ = 3.2, so the nearest grid points are 3 and 4.

Hint 2

Use |a_j|² = sin²(πMΔ)/(M² sin²(πΔ)) with Δ = φ − j/16.

Worked solution

For j = 3, Δ = 0.0125: sin²(0.2π)/(256 sin²(0.0125π)) ≈ 0.3455/(256 × 0.001541) ≈ 0.876. For j = 4, Δ = −0.05: sin²(0.8π)/(256 sin²(0.05π)) ≈ 0.3455/(256 × 0.02447) ≈ 0.055. So outcome 3 (estimate 0.1875) has probability about 0.88 and outcome 4 about 0.06.

Revisit the relevant explanation

5. Worked problem §

Phase estimation with \(m=3\) is applied to an eigenstate with \(\phi=5/16\), exactly halfway between the grid points \(2/8\) and \(3/8\). Compute the probabilities of outcomes \(2\) and \(3\) from \(|a_j|^2=\sin^2(\pi M\Delta)/(M^2\sin^2\pi\Delta)\). Compare their sum with the nearest-grid-point bound \(4/\pi^2\), and say what this worst case means for choosing \(m\).

Hint 1

For both outcomes \(|\Delta|=1/16\), so \(M\Delta=\pm1/2\).

Hint 2

\(\sin(\pi/16)\approx0.1951\).

Worked solution

For \(j=2\) and \(j=3\), \(|\Delta|=1/16\), so \(\sin^2(\pi M\Delta)=\sin^2(\pi/2)=1\) and \(|a_j|^2=1/(64\sin^2(\pi/16))\approx1/(64\times0.03806)\approx0.411\). Each nearest neighbor has probability about \(0.41\), just above \(4/\pi^2\approx0.405\), and together they have about \(0.82\). The remaining \(0.18\) spreads over outcomes farther away (\(0.051\) each for \(1\) and \(4\), less beyond). A phase halfway between grid points is the worst case: no single outcome is likely. So the guarantees are stated as “within one grid spacing”, and extra control qubits or repetitions with a median are added to raise the confidence.

Revisit the relevant explanation

6. Worked problem §

In order finding with \(L=21\), \(a=2\) (\(r=6\)), and \(m=9\), the run with \(s=5\) most likely returns \(j=427\). Expand \(427/512\) as a continued fraction, list its convergents, and recover \(r\).

Hint 1

Run Euclid’s algorithm on \((427,512)\).

Hint 2

Keep the last convergent with denominator below \(L=21\).

Worked solution

Euclid’s algorithm gives \(427=0\cdot512+427\), \(512=1\cdot427+85\), \(427=5\cdot85+2\), \(85=42\cdot2+1\), \(2=2\cdot1\). So \(427/512=[0;1,5,42,2]\). The convergents are \(0,\ 1,\ \tfrac56,\ \tfrac{211}{253},\ \tfrac{427}{512}\). The last one with denominator below \(21\) is \(5/6\), giving candidate \(r=6\); the check \(2^6=64\equiv1\pmod{21}\) confirms it. The approximation is close enough: \(|427/512-5/6|=1/1536<1/(2\cdot36)\), as the continued-fraction theorem requires.

Revisit the relevant explanation

7. Worked problem §

For \(L=21\), apply the factoring reduction with \(a=4\), \(a=5\), and \(a=8\). Find each order classically and say which choices give a factor.

Hint 1

List powers modulo \(21\) until you reach \(1\).

Hint 2

The reduction fails if \(r\) is odd or \(a^{r/2}\equiv-1\equiv20\).

Worked solution

For \(a=4\): \(4,16,64\equiv1\), so \(r=3\), which is odd. The reduction fails. For \(a=5\): \(5,4,20,16,17,1\), so \(r=6\), but \(5^3\equiv20\equiv-1\), so \(\gcd(5^3+1,21)=21\) and \(\gcd(5^3-1,21)=\gcd(124,21)=1\), both trivial. It fails. For \(a=8\): \(8^2=64\equiv1\), so \(r=2\), and \(8\not\equiv-1\). Then \(\gcd(7,21)=7\) and \(\gcd(9,21)=3\), so it succeeds. Two of three choices fail here, though the theorem only promises success with probability at least \(1/2\) over a random coprime \(a\). Each failure costs another run of order finding, and the classical checks reveal it.

Revisit the relevant explanation

8. Misconception §

A student runs phase estimation with \(U=Z\) on the target \(\ket+\) and expects to obtain the “average phase” \(\phi=1/4\), halfway between the eigenphases \(0\) and \(1/2\). Using two control qubits, compute what is actually observed and what the target is left in.

Hint 1

\(\ket+=(\ket0+\ket1)/\sqrt2\), and \(Z\) has eigenphases \(0\) on \(\ket0\) and \(1/2\) on \(\ket1\).

Hint 2

Phase estimation acts on each eigenstate term separately.

Worked solution

Write \(\ket+=\frac{1}{\sqrt2}(\ket0+\ket1)\), eigenstates of \(Z\) with phases \(0\) and \(1/2\). Both are exact two-bit grid points, so phase estimation produces \(\frac{1}{\sqrt2}(\ket{00}\ket0+\ket{10}\ket1)\). Measuring the controls gives \(00\) (phase \(0\)) or \(10\) (phase \(1/2\)), each with probability \(1/2\), and the target collapses to the matching eigenstate. The outcome \(01\), phase \(1/4\), never occurs. Phase estimation samples one eigenphase with probability \(|c_s|^2\). An average over runs estimates \(\sum_s|c_s|^2\phi_s\), but no single run reports it, and the average is generally not an eigenphase at all.

Revisit the relevant explanation

9. Extension §

Factor L = 33 using a = 5, by finding the order of 5 modulo 33 classically and applying the reduction. Then explain how many control qubits phase estimation would use.

Hint 1

Compute powers of 5 modulo 33 until you reach 1.

Hint 2

33 has 6 bits, so m ≈ 2n.

Worked solution

Powers of 5 mod 33: 5, 25, 26, 31, 23, 16, 14, 4, 20, 1, so r = 10. Then 5⁵ ≡ 23 (not −1 ≡ 32), and gcd(22, 33) = 11, gcd(24, 33) = 3, so 33 = 3 × 11. With n = 6 bits, m ≈ 2n = 12 (or 13) control qubits ensure 2^m ≥ L², so that continued fractions recover s/10 from a successful run.

Revisit the relevant explanation

10. Extension §

Suppose the order is \(r=12\) and each order-finding run returns the reduced fraction \(s/r\) for a uniformly random \(s\in\{0,\dots,11\}\). (a) What is the probability that a single run reveals \(r\) directly, as the reduced denominator? (b) Two runs return \(3/12=1/4\) and \(10/12=5/6\). Show that the least common multiple of their denominators gives \(r\). (c) What is the probability that two independent runs determine \(r\) in this way?

Hint 1

The reduced denominator is \(r/\gcd(s,r)\).

Hint 2

The lcm of the denominators is \(r/\gcd(s_1,s_2,r)\); use \(12=2^2\cdot3\).

Worked solution

(a) The denominator equals \(12\) exactly when \(\gcd(s,12)=1\), that is \(s\in\{1,5,7,11\}\): probability \(1/3\). (b) The denominators are \(4\) and \(6\), and \(\mathrm{lcm}(4,6)=12=r\). Check \(a^{12}\equiv1\) to confirm. (c) The lcm of the two denominators is \(12/\gcd(s_1,s_2,12)\), so it equals \(12\) unless both \(s\) are even or both are multiples of \(3\). Since \(s\) is uniform modulo \(12\), these events are independent: \(\Pr=(1-\tfrac14)(1-\tfrac19)=\tfrac34\cdot\tfrac89=\tfrac23\). Combining samples doubles the success chance relative to a single run, which is why the procedure collects denominators from a few runs before testing.

Revisit the relevant explanation

Where this leads. the Amplitude Manipulation chapter turns small success probabilities into large ones with pairs of reflections, and combines amplification with phase estimation into amplitude estimation.

Search this book

Search the course.