Education / Quantum Algorithms

Quantum Algorithms · Chapter 03

Phase Encoding

Deutsch’s algorithm turned two function values into two signs and let them interfere. Clean evaluation now lets us produce such signs for any function we can compute, and leave nothing else behind.

A sign is only the simplest phase, and two inputs are the smallest pattern. Whenever an operation changes a state only by a phase, can that phase be moved somewhere interference can read it? And can a whole pattern of signs on \(n\) qubits, or a phase finer than a sign, be read the same way?

We first show that kickback works for any unitary and any eigenstate, which gives a circuit that measures a phase. A layer of Hadamards then reads a sign pattern on \(n\) qubits in one step, provided the pattern has a special linear form; this recovers a hidden string with one query. Most hidden structure does not give so perfect a pattern, so Simon’s problem shows how random constraints from many runs, combined by classical algebra, reveal it, and introduces the vocabulary of groups and cosets that such structure needs. Finally we produce phases finer than a sign from computed numbers and bound the error their finite precision introduces.

Phases that advance steadily with a number, rather than flipping sign, are what the Fourier transform will read.

How can a function change relative phases without leaving a record of its input?

A phase is invisible until it is relative; once it is relative, interference can turn it into a measurement outcome.

In this chapter · 4 sections · 11 topics
  1. 3.1 Controlled Phases
    Topics in this section
    1. 3.1.1 Eigenstate targets
    2. 3.1.2 The Hadamard test
    3. 3.1.3 Bit oracles and phase oracles
  2. 3.2 Interference Readout
    Topics in this section
    1. 3.2.1 The Hadamard transform on many qubits
    2. 3.2.2 Bernstein–Vazirani
    3. 3.2.3 Deutsch–Jozsa and promise assumptions
  3. 3.3 Hidden Structure
    Topics in this section
    1. 3.3.1 Simon’s problem
    2. 3.3.2 Recovering the string
  4. 3.4 Phase Arithmetic
    Topics in this section
    1. 3.4.1 Phases from computed values
    2. 3.4.2 Phase kickback from modular addition
    3. 3.4.3 Precision and workspace restoration
Reading guide · preparation, aims, and assumptions

Encode information in relative phases and read it with interference: eigenstate kickback, the Hadamard test, sign patterns on many qubits, hidden-structure sampling, and finer phases from computed values.

Before you begin

Use clean oracles and phase oracles from the Coherent Computation chapter, and the Deutsch circuit and repetition bounds from the Quantum Algorithmic Thinking chapter.

What you should be able to do

The example to follow

The hidden linear function s·x: one query writes the sign pattern (−1)^{s·x} and one Hadamard layer reads s. Simon’s problem then replaces the perfect pattern by random constraints combined classically.

Scope and assumptions

Separations are in the black-box query model with clean oracles. Deutsch–Jozsa’s exponential separation is exact-versus-exact; Simon’s holds against bounded-error classical algorithms. Phase gates of arbitrary angle are ideal unless synthesis error is stated.

3.1

Controlled Phases

The \(\ket-\) target turned a bit flip into a sign. Does that depend on anything special about \(X\) and \(\ket-\)? If not, any unitary that changes some state only by a phase could hand that phase to a control qubit. We find the property that makes this work, then turn the kicked-back phase into a measurable probability. That settles how the two common forms of Boolean oracle, flipping a bit or flipping a sign, can be converted into each other.

3.1.1 Eigenstate targets§

eigenstateeigenvalue

The \(\ket-\) target worked because flipping it only multiplied it by \(-1\). Look for the same property in any unitary \(V\): a state \(\ket u\) that \(V\) changes only by a phase,

\[V\ket u=e^{i\phi}\ket u.\]

Such a state is an eigenstate of \(V\), and \(e^{i\phi}\) is its eigenvalue. Because \(V\) is unitary, it preserves lengths, so the eigenvalue has magnitude one: it is a pure phase. For \(V=X\), the eigenstates are \(\ket+\) with eigenvalue \(1\) and \(\ket-\) with eigenvalue \(-1\).

Now control \(V\) with a qubit in \(\ket+\):

\[\mathrm{C}V\,\frac{\ket0+\ket1}{\sqrt2}\ket u=\frac{\ket0\ket u+\ket1\,e^{i\phi}\ket u}{\sqrt2}=\frac{\ket0+e^{i\phi}\ket1}{\sqrt2}\otimes\ket u.\]

The target is untouched and factors out. The phase \(e^{i\phi}\), which was a global phase of \(V\ket u\) and therefore unobservable, is now a relative phase between the control branches. This is phase kickback in its general form. Applying \(V\) again multiplies \(\ket u\) by \(e^{i\phi}\) again, so \(V^k\ket u=e^{ik\phi}\ket u\), and controlled-\(V^k\) kicks back \(e^{ik\phi}\). Kickback needs three things: a target prepared in an eigenstate, controlled access to \(V\), and the eigenvalue being the information we want.

Phase kickback from an eigenstateWith the target in an eigenstate |u⟩ of V, controlled-V leaves the target unchanged and attaches the eigenvalue e^(iφ) to the control’s |1⟩ branch, where it is a relative phase. Read each circuit left to right; double lines carry classical measurement records.Phase kickback from an eigenstate|+⟩1/√2(|0⟩+e^(iφ)|1⟩)|u⟩|u⟩VV|u⟩=e^(iφ)|u⟩
With the target in an eigenstate \(\ket u\) of \(V\), controlled-\(V\) leaves the target unchanged and attaches the eigenvalue \(e^{i\phi}\) to the control’s \(\ket1\) branch, where it is a relative phase.

All three are real requirements. If \(\ket u\) is not an eigenstate, the target becomes entangled with the control and the clean factorization fails. If only an uncontrolled \(V\) is available, the phase stays global. And if many eigenstates are present at once, each contributes its own phase on its own branch. We will find, with phase estimation, that this produces a random sample of the eigenvalues rather than all of them.

Problems
  1. Find the eigenstates and eigenvalues of \(Z\) and of \(S=\mathrm{diag}(1,i)\). What does controlled-\(S\) do to \(\ket+\ket1\)?

    Show solutionHide solution

    \(Z\) has \(\ket0\) (eigenvalue \(1\)) and \(\ket1\) (eigenvalue \(-1\)). \(S\) has \(\ket0\) (eigenvalue \(1\)) and \(\ket1\) (eigenvalue \(i\)). Controlled-\(S\) on \(\ket+\ket1\) gives \(\frac{1}{\sqrt2}(\ket0+i\ket1)\ket1\): the phase \(i\) is kicked back onto the control.

  2. Apply controlled-\(X\) to \(\ket+\ket0\). Is \(\ket0\) an eigenstate of \(X\)? What goes wrong?

    Show solutionHide solution

    The result is \(\frac{1}{\sqrt2}(\ket{00}+\ket{11})\), an entangled state. \(\ket0\) is not an eigenstate of \(X\), so the target does not factor out: it records the control branch. This is the which-path record of Deutsch’s circuit in eigenstate language.

  3. Show that if \(V\ket u=e^{i\phi}\ket u\), then controlled-\(V^k\) kicks back \(e^{ik\phi}\). Why does this make powers of \(V\) useful for learning \(\phi\) precisely?

    Show solutionHide solution

    \(V^k\ket u=V^{k-1}e^{i\phi}\ket u=\cdots=e^{ik\phi}\ket u\), so the kicked-back phase is \(k\phi\). A small change in \(\phi\) becomes a \(k\)-times larger change in the measured phase, so interference experiments with large \(k\) are more sensitive. Phase estimation uses \(k=1,2,4,\ldots\) to read successive binary digits of \(\phi\). The price is that \(V^k\) costs up to \(k\) uses of \(V\).

3.1.2 The Hadamard test§

Hadamard test

A phase on the control is still a relative phase, which no computational-basis measurement sees. How do we turn it into a probability? A Hadamard does it. Apply \(H\) to \((\ket0+e^{i\phi}\ket1)/\sqrt2\):

\[\frac{1+e^{i\phi}}{2}\ket0+\frac{1-e^{i\phi}}{2}\ket1,\qquad \Pr[0]=\left|\frac{1+e^{i\phi}}{2}\right|^2=\frac{1+\cos\phi}{2}.\]

So measuring the control is a coin whose bias reveals \(\cos\phi\). This circuit, \(H\), controlled-\(U\), \(H\), measure, is the Hadamard test. It works even when the target is not an eigenstate. For a general state \(\ket\psi\), the same calculation gives

\[\Pr[0]=\frac{1+\operatorname{Re}\bra\psi U\ket\psi}{2}.\]

To see this, write the state before the final Hadamard as \(\frac{1}{\sqrt2}(\ket0\ket\psi+\ket1U\ket\psi)\). The Hadamard puts amplitude \(\frac12(\ket\psi+U\ket\psi)\) on control outcome \(0\), whose squared length is \(\frac14(2+\bra\psi U\ket\psi+\bra\psi U^\dagger\ket\psi)=\frac12(1+\operatorname{Re}\bra\psi U\ket\psi)\). Inserting \(S^\dagger\) on the control before the final Hadamard gives \(\frac12(1+\operatorname{Im}\bra\psi U\ket\psi)\) instead.

The Hadamard testTop: Pr[0]=1/2(1+Re⟨ψ| U|ψ⟩). Bottom: inserting S† on the control gives 1/2(1+Im⟨ψ| U|ψ⟩). The controlled-U is a composite operation and requires controlled access. Read each circuit left to right; double lines carry classical measurement records.The Hadamard testReal part|0⟩|ψ⟩HUHImaginary part|0⟩|ψ⟩HUS†H
Top: \(\Pr[0]=\tfrac12(1+\operatorname{Re}\bra\psi U\ket\psi)\). Bottom: inserting \(S^\dagger\) on the control gives \(\tfrac12(1+\operatorname{Im}\bra\psi U\ket\psi)\). The controlled-\(U\) is a composite operation and requires controlled access.
A phase becomes a biasFor an eigenstate with eigenvalue e^(iφ), the Hadamard test outputs 0 with probability (1+cosφ)/2 (solid) and the S† variant with probability (1+sinφ)/2 (dashed). Together they determine φ. Horizontal axis: eigenphase φ; vertical axis: Pr[0]. A phase becomes a bias00.510π/2π3π/22πeigenphase φPr[0]real partimaginary part
For an eigenstate with eigenvalue \(e^{i\phi}\), the Hadamard test outputs 0 with probability \((1+\cos\phi)/2\) (solid) and the \(S^\dagger\) variant with probability \((1+\sin\phi)/2\) (dashed). Together they determine \(\phi\).

How well does the Hadamard test read a phase? One run gives one bit. To estimate \(\cos\phi\) to precision \(\epsilon\) we need on the order of \(1/\epsilon^2\) runs, by Chebyshev’s inequality for averaged bits. And \(\cos\phi\) does not distinguish \(\phi\) from \(-\phi\). Phase estimation, and its iterative version with one control qubit, do better by combining such tests with controlled powers.

Problems
  1. Apply the Hadamard test with \(U=Z\) and \(\ket\psi=\ket+\). Compute \(\Pr[0]\) both from the formula and directly.

    Show solutionHide solution

    \(\bra+Z\ket+=\braket{+}{-}=0\), so \(\Pr[0]=\frac12\). Directly: controlled-\(Z\) on \(\ket+\ket+\) gives \(\frac12(\ket0(\ket0+\ket1)+\ket1(\ket0-\ket1))\); after \(H\) on the control the outcome-\(0\) branch is \(\frac{1}{2\sqrt2}\cdot2\ket0=\frac{1}{\sqrt2}\ket0\), with probability \(\frac12\).

  2. For an eigenstate with \(\phi=\pi/3\), what is \(\Pr[0]\)? How many runs are needed so that, by Chebyshev’s bound, the estimate of \(\Pr[0]\) is within \(0.01\) with probability at least \(0.9\)?

    Show solutionHide solution

    \(\Pr[0]=(1+\frac12)/2=\frac34\). Chebyshev with variance at most \(1/(4R)\): \(1/(4R\cdot10^{-4})\le0.1\) gives \(R\ge25{,}000\). Using the actual variance \(p(1-p)=3/16\) instead of \(1/4\) reduces this to \(18{,}750\).

  3. The Hadamard test estimates \(\cos\phi\). Explain why the outcomes for \(\phi\) and \(2\pi-\phi\) are identical, and how the \(S^\dagger\) variant resolves the ambiguity.

    Show solutionHide solution

    \(\cos(2\pi-\phi)=\cos\phi\), so the real-part test cannot tell them apart. The \(S^\dagger\) variant measures \(\sin\phi\), and \(\sin(2\pi-\phi)=-\sin\phi\). Together, \(\cos\phi\) and \(\sin\phi\) determine \(\phi\) modulo \(2\pi\). Running both tests is the classical analogue of measuring both quadratures of a wave.

3.1.3 Bit oracles and phase oracles§

bit oracle

Two forms of Boolean oracle appear in the literature: the bit oracle \(U_f\ket x\ket y=\ket x\ket{y\oplus f(x)}\) and the phase oracle \(O_f\ket x=(-1)^{f(x)}\ket x\). How do they relate?

From a bit oracle to a phase oracle is one query: put the target in \(\ket-\), as in Deutsch’s circuit. Or, if \(U_f\) is built by compute–copy–uncompute, replace the copy by a \(Z\) gate and save the target entirely.

The other direction is subtler. A phase oracle \(O_f\) cannot distinguish \(f\) from \(1\oplus f\): their phase oracles differ by the global factor \(-1\). A bit oracle can, since \(U_f\ket x\ket0\) and \(U_{1\oplus f}\ket x\ket0\) give different target values. So an uncontrolled phase oracle alone cannot implement a bit oracle. With a controlled phase oracle it can. Apply \(H\) to the target \(\ket y\), use the target as the control of \(O_f\), and apply \(H\) again:

\[\ket x\ket y\xrightarrow{H}\ket x\tfrac{1}{\sqrt2}\textstyle\sum_b(-1)^{yb}\ket b\xrightarrow{\mathrm{C}O_f}\ket x\tfrac{1}{\sqrt2}\sum_b(-1)^{b(y\oplus f(x))}\ket b\xrightarrow{H}\ket x\ket{y\oplus f(x)}.\]

A bit oracle from a controlled phase oracleThe target |y⟩ is moved to the Hadamard basis, used as the control of the phase oracle O_f, and moved back. The control-0 branch receives no sign, which fixes the global phase that an uncontrolled O_f leaves ambiguous. Read each circuit left to right; double lines carry classical measurement records.A bit oracle from a controlled phase oracle|x⟩|x⟩|y⟩|y⊕ f(x)⟩HO_fH
The target \(\ket y\) is moved to the Hadamard basis, used as the control of the phase oracle \(O_f\), and moved back. The control-0 branch receives no sign, which fixes the global phase that an uncontrolled \(O_f\) leaves ambiguous.

The controlled version fixes the global phase: the control-\(0\) branch gets no sign at all, so \(f\) and \(1\oplus f\) become distinguishable. This is a specific case of a general fact about controlled access: control turns a global phase into a relative one. When a paper says “given a phase oracle”, check whether controlled access is assumed.

Problems
  1. Verify the bit-from-phase construction on \(\ket x\ket0\) when \(f(x)=1\).

    Show solutionHide solution

    \(H\) gives \(\ket x\frac{1}{\sqrt2}(\ket0+\ket1)\). Controlled-\(O_f\) multiplies the \(b=1\) branch by \((-1)^{f(x)}=-1\): \(\ket x\frac{1}{\sqrt2}(\ket0-\ket1)\). \(H\) gives \(\ket x\ket1=\ket x\ket{0\oplus1}\).

  2. Show that one query to the bit oracle \(U_f\) implements the controlled phase oracle \(\ket c\ket x\mapsto(-1)^{c f(x)}\ket c\ket x\).

    Show solutionHide solution

    Use an extra target qubit in \(\ket0\). A CNOT from \(c\) gives \(\ket c\), and a Hadamard turns it into \(\ket+\) when \(c=0\) and \(\ket-\) when \(c=1\). Query \(U_f\): the \(\ket+\) target is unchanged by a flip and the \(\ket-\) target kicks back \((-1)^{f(x)}\), so the phase is \((-1)^{cf(x)}\) with no record left. Undo the Hadamard and the CNOT to return the target to \(\ket0\). By linearity this works on superpositions of \(c\) and \(x\). One query suffices.

  3. A phase oracle \(O_f\) is used in Deutsch–Jozsa. Does it matter that it cannot distinguish \(f\) from \(1\oplus f\)?

    Show solutionHide solution

    No. Deutsch–Jozsa asks only whether \(f\) is constant or balanced, and \(f\) and \(1\oplus f\) are in the same class. The global sign multiplies the final state and changes no probability. The ambiguity matters only for tasks whose answer distinguishes \(f\) from its complement.

3.2

Interference Readout

One phase query on \(n\) qubits writes a sign \((-1)^{f(x)}\) on all \(2^n\) inputs at once. Which sign patterns can a layer of Hadamards turn into a definite measurement outcome? We first find a formula for what \(n\) Hadamards do. It shows that one family of patterns is read perfectly, which hands us a hidden string in one query. The same formula then shows what a promise buys, and what happens on inputs that break it.

3.2.1 The Hadamard transform on many qubits§

Hadamard transformbitwise inner product

What does a layer of Hadamards do to a basis state of \(n\) qubits? On one qubit, \[H\ket x=\frac{1}{\sqrt2}\big(\ket0+(-1)^x\ket1\big)=\frac{1}{\sqrt2}\sum_{z\in\{0,1\}}(-1)^{xz}\ket z\]. On \(n\) qubits, apply \(H\) to each and multiply out:

\[H^{\otimes n}\ket x=\bigotimes_{j=1}^n\frac{1}{\sqrt2}\sum_{z_j}(-1)^{x_jz_j}\ket{z_j}=\frac{1}{\sqrt{2^n}}\sum_{z\in\{0,1\}^n}(-1)^{x\cdot z}\ket z,\]

where \(x\cdot z=x_1z_1\oplus\cdots\oplus x_nz_n\) is the bitwise inner product modulo two. The sign of each term is the parity of the positions where both strings have a \(1\). This is the Hadamard transform.

The signs of the two-qubit Hadamard transformEntry (x,z) is the sign of |z⟩ in H^(⊗2)|x⟩, namely (−1)^(x· z); every entry also carries the factor 1/2. Distinct rows are orthogonal, so a row pattern is mapped back to its label. Columns: x \ z, 00, 01, 10, 11. 00, +, +, +, +; 01, +, −, +, −; 10, +, +, −, −; 11, +, −, −, +The signs of the two-qubit Hadamard transformx \ z0001101100++++01+−+−10++−−11+−−+
Entry \((x,z)\) is the sign of \(\ket z\) in \(H^{\otimes2}\ket x\), namely \((-1)^{x\cdot z}\); every entry also carries the factor \(1/2\). Distinct rows are orthogonal, so a row pattern is mapped back to its label.

Two consequences follow. First, \(H^{\otimes n}\ket{0^n}\) is the uniform superposition, since \(0\cdot z=0\) for every \(z\). Second, \(H^{\otimes n}\) is its own inverse, because each \(H\) is. So if a state has the form \(2^{-n/2}\sum_x(-1)^{s\cdot x}\ket x\) for some string \(s\), then \(H^{\otimes n}\) maps it exactly to \(\ket s\). Sign patterns of this special “linear” form are read perfectly by one layer of Hadamards.

The rows of the table are orthogonal: for \(s\neq s'\), \[\sum_x(-1)^{s\cdot x}(-1)^{s'\cdot x}=\sum_x(-1)^{(s\oplus s')\cdot x}=0\], since a nonzero string \(t=s\oplus s'\) has \(t\cdot x=1\) for exactly half the \(x\). This cancellation identity has an analogue for complex roots of unity, which will drive the Fourier transform.

Problems
  1. Write \(H^{\otimes2}\ket{11}\) explicitly.

    Show solutionHide solution

    The signs are \((-1)^{11\cdot z}\): \(+\) for \(z=00\), \(-\) for \(01\), \(-\) for \(10\), \(+\) for \(11\). So \(H^{\otimes2}\ket{11}=\frac12(\ket{00}-\ket{01}-\ket{10}+\ket{11})=\ket-\ket-\).

  2. Show that for a nonzero string \(t\), exactly half of all \(x\in\{0,1\}^n\) have \(t\cdot x=1\).

    Show solutionHide solution

    Pick a position \(j\) with \(t_j=1\). Pair each \(x\) with \(x\) flipped in position \(j\). Flipping \(x_j\) changes \(t\cdot x\) by \(t_j=1\), so each pair contains one \(x\) with \(t\cdot x=0\) and one with \(t\cdot x=1\). The pairs partition all \(2^n\) strings.

  3. Express the zero-outcome amplitude after \(H^{\otimes n}O_fH^{\otimes n}\ket{0^n}\) for an arbitrary Boolean \(f\), and interpret it.

    Show solutionHide solution

    The amplitude of \(\ket{0^n}\) is \(\frac{1}{2^n}\sum_x(-1)^{f(x)}=1-2\frac{|f^{-1}(1)|}{2^n}\): one minus twice the fraction of ones. It is the average value of \((-1)^{f(x)}\). The circuit estimates the bias of \(f\), with outcome probability equal to the square of that bias.

3.2.2 Bernstein–Vazirani§

Bernstein–Vazirani algorithmhidden string

Suppose \(f_s(x)=s\cdot x\) for a hidden string \(s\in\{0,1\}^n\), and we have a clean oracle for \(f_s\). The task is to find \(s\).

A classical query returns one bit, \(s\cdot x\), which is one linear equation for the unknown \(s\). Querying \(x=e_j\) (a single \(1\) in position \(j\)) returns \(s_j\), so \(n\) queries suffice. They are also necessary for any classical algorithm: there are \(2^n\) possible strings, and \(k\) queries return \(k\) bits, which can distinguish at most \(2^k\) cases.

The quantum algorithm uses one query. Prepare \(H^{\otimes n}\ket{0^n}\) and the target \(\ket-\), query, and apply \(H^{\otimes n}\):

\[\ket{0^n}\xrightarrow{H^{\otimes n}}\frac{1}{\sqrt{2^n}}\sum_x\ket x\xrightarrow{O_{f_s}}\frac{1}{\sqrt{2^n}}\sum_x(-1)^{s\cdot x}\ket x\xrightarrow{H^{\otimes n}}\ket s.\]

The last step uses the self-inverse property of the Hadamard transform: the phase pattern is a row of the Hadamard table, so the Hadamard layer maps it to the corresponding basis state. Measuring returns \(s\) with certainty.

The Bernstein–Vazirani circuit for three input bitsOne query to the oracle for f_s(x)=s· x, with the target in |−⟩, writes the sign pattern (−1)^(s· x). The final Hadamard layer maps that pattern to |s⟩, so the measured bits are s₁s₂s₃ with certainty. Read each circuit left to right; double lines carry classical measurement records.The Bernstein–Vazirani circuit for three input bits|0⟩s₁|0⟩s₂|0⟩s₃|1⟩|−⟩HHHHU_(f_s)HHH
One query to the oracle for \(f_s(x)=s\cdot x\), with the target in \(\ket-\), writes the sign pattern \((-1)^{s\cdot x}\). The final Hadamard layer maps that pattern to \(\ket s\), so the measured bits are \(s_1s_2s_3\) with certainty.

Here is an \(n=3\) example with \(s=101\). The signs \((-1)^{s\cdot x}\) on \(x=000,001,\ldots,111\) are \(+,-,+,-,-,+,-,+\). The final amplitude of \(z\) is \(\frac18\sum_x(-1)^{(s\oplus z)\cdot x}\), which is \(1\) for \(z=101\) and \(0\) otherwise.

This is the Bernstein–Vazirani algorithm (1993/1997). Its query separation, one versus \(n\), holds for any success criterion, since the classical bound is an information count. Its cost is otherwise ordinary: \(2n+1\) Hadamards and \(n\) measurements around the oracle. And if \(f_s\) is given as a circuit we can read, \(s\) could often be found by inspecting the circuit; the speedup is relative to black-box access.

Problems
  1. For \(n=2\) and \(s=11\), list the four signs after the query and verify that the Hadamards produce \(\ket{11}\).

    Show solutionHide solution

    Signs \((-1)^{x_1\oplus x_2}\) on \(00,01,10,11\): \(+,-,-,+\). The state is \(\frac12(\ket{00}-\ket{01}-\ket{10}+\ket{11})=\ket-\ket-\), and \(H\otimes H\) maps it to \(\ket1\ket1\).

  2. Suppose the oracle is promised to compute \(s\cdot x\oplus b\) for unknown \(s\) and an unknown bit \(b\). What does the circuit return, and can it learn \(b\)?

    Show solutionHide solution

    The extra \(b\) multiplies every amplitude by \((-1)^b\), a global phase. The circuit still returns \(s\) with certainty but learns nothing about \(b\). One classical query at \(x=0^n\) returns \(b\) directly.

  3. An implementation of the oracle leaves the garbage bit \(x_1\) in its workspace. What does the circuit return for \(s=000\)?

    Show solutionHide solution

    With \(s=0^n\) there are no signs, but the workspace records \(x_1\). Branches with \(x_1=0\) and \(x_1=1\) cannot interfere, so the first qubit after its Hadamard is a fair coin instead of \(0\); the other qubits still give \(0\). The output is \(000\) or \(100\), each with probability \(\frac12\). Garbage converts an exact algorithm into a wrong one.

3.2.3 Deutsch–Jozsa and promise assumptions§

promise problem

The Deutsch–Jozsa algorithm is the same circuit with a different promise. What is the final amplitude of \(\ket{0^n}\) for an arbitrary Boolean \(f\)? The row of the Hadamard table for \(z=0^n\) has every sign \(+\), since \(x\cdot0^n=0\). So the amplitude is \(\frac{1}{2^n}\sum_x(-1)^{f(x)}\), the average of the signs. Under the promise that \(f\) is constant or balanced, that average is \(\pm1\) or \(0\), so the circuit outputs \(0^n\) with certainty for constant \(f\) and never for balanced \(f\). One query decides this promise problem exactly.

What about functions outside the promise? If \(f\) takes the value \(1\) on \(k\) of the \(2^n\) inputs, the zero outcome has probability \(\big(1-2k/2^n\big)^2\). For \(n=3\):

The zero outcome outside the promiseFor n=3, probability of the all-zero outcome when f takes the value 1 on k of the 8 inputs: (1−k/4)². Only k=0,8 (constant) and k=4 (balanced) give certain answers. Horizontal axis: number of inputs with f(x)=1; vertical axis: probability of all-zero outcome. The zero outcome outside the promise00.250.50.751012345678number of inputs with f(x)=1probability of all-zero outcome
For \(n=3\), probability of the all-zero outcome when \(f\) takes the value 1 on \(k\) of the 8 inputs: \((1-k/4)^2\). Only \(k=0,8\) (constant) and \(k=4\) (balanced) give certain answers.

Only \(k=0\), \(k=8\) (constant) and \(k=4\) (balanced) give certain answers. A function with \(k=3\) gives zero with probability \(1/16\). An algorithm that announced “balanced” whenever the outcome is nonzero would be making claims about inputs the problem never covered.

How hard is the promise problem classically? It depends on the success criterion. An exact deterministic algorithm needs \(2^{n-1}+1\) queries in the worst case, because \(2^{n-1}\) equal answers are still consistent with a balanced function. A randomized algorithm can query \(k\) random inputs and answer “constant” if all the values agree. It errs only on balanced functions, and then with probability \(2\cdot2^{-k}\), since all \(k\) values must land on the same side. So \(k=1+\log_2(1/\delta)\) queries give error at most \(\delta\). So Deutsch–Jozsa separates exact quantum and exact classical query complexity exponentially, but bounded-error classical algorithms close the gap. Bernstein–Vazirani’s separation is smaller (one versus \(n\)) but survives randomization. Simon’s problem, next, gives an exponential separation that survives randomization.

Problems
  1. For \(n=4\), compute the zero-outcome probability when \(f\) is \(1\) on 6 inputs.

    Show solutionHide solution

    \(1-2\cdot6/16=1/4\), so the probability is \(1/16\).

  2. Show that for a balanced \(f\), every nonzero outcome \(z\) is possible in principle but the probability distribution depends on \(f\). Give an example for \(n=2\).

    Show solutionHide solution

    The amplitude of \(z\) is \(\frac{1}{2^n}\sum_x(-1)^{f(x)\oplus z\cdot x}\). For \(f(x)=x_1\) (balanced), the pattern is a Hadamard row and the output is \(10\) with certainty. For \(f\) with values \(0,1,1,0\) on \(00,01,10,11\), the output is \(11\). For \(f\) with values \(0,1,0,1\), it is \(01\). Different balanced functions give different nonzero distributions; the promise guarantees only that \(00\) never occurs.

  3. A test suite checks a Deutsch–Jozsa implementation on the two constant functions and on \(f(x)=x_1\) only. Name an implementation bug that would pass this suite.

    Show solutionHide solution

    An oracle that reads only \(x_1\), computing \(x_1\) whenever it should compute some other balanced function, passes: on the three tested functions it is correct. So does a circuit that omits the final Hadamards on every qubit except the first, since for these functions the other qubits are \(\ket+\) before the final layer and are measured as random bits that the test may not check. A useful test suite includes balanced functions depending on every input bit and checks the full output string.

3.3

Hidden Structure

Bernstein–Vazirani read a hidden string in one shot because the phase pattern was exactly a row of the Hadamard table. What if the hidden structure gives no such perfect pattern? Then a single run cannot return the answer. We find instead that each run returns a random constraint on the hidden structure. A modest number of constraints, combined by classical linear algebra, determine the answer, and naming the structure involved prepares the same strategy for factoring.

3.3.1 Simon’s problem§

Simon’s problem

Can we hide a string in a function so that no single pattern reveals it? Let \(f:\{0,1\}^n\to\{0,1\}^n\) satisfy, for some hidden nonzero \(s\),

\[f(x)=f(y)\iff y=x\ \text{or}\ y=x\oplus s.\]

So \(f\) is two-to-one, and its collisions are exactly the pairs \(\{x,x\oplus s\}\). The task of Simon’s problem is to find \(s\).

Classically, the only way to learn about \(s\) is to find a collision \(f(x)=f(y)\), which reveals \(s=x\oplus y\). With \(k\) queries there are about \(k^2/2\) pairs, each colliding with probability about \(2^{-n}\), so on the order of \(2^{n/2}\) queries are needed. Simon proved this is a lower bound for any bounded-error classical algorithm.

The quantum circuit uses a clean bit oracle with an \(n\)-qubit output register. Prepare the uniform superposition, query, and measure the output register:

\[\frac{1}{\sqrt{2^n}}\sum_x\ket x\ket{f(x)}\ \xrightarrow{\text{measure output, see }f(x_0)}\ \frac{\ket{x_0}+\ket{x_0\oplus s}}{\sqrt2}.\]

The measurement leaves a superposition of the two inputs consistent with the observed value. We do not learn \(x_0\) usefully: it is random. But the difference between the two branches is \(s\), wherever they sit. Now apply \(H^{\otimes n}\). The amplitude of \(z\) is

\[\frac{1}{\sqrt{2^{n+1}}}\Big((-1)^{x_0\cdot z}+(-1)^{(x_0\oplus s)\cdot z}\Big)=\frac{(-1)^{x_0\cdot z}}{\sqrt{2^{n+1}}}\big(1+(-1)^{s\cdot z}\big).\]

It is zero whenever \(s\cdot z=1\), and has magnitude \(2/\sqrt{2^{n+1}}\) whenever \(s\cdot z=0\). The random \(x_0\) contributes only a phase. So each run returns a uniformly random \(z\) satisfying \(s\cdot z=0\).

Take \(n=3\) and \(s=110\). The collision pairs are \(\{000,110\}\), \(\{001,111\}\), \(\{010,100\}\) and \(\{011,101\}\). The condition \(s\cdot z=0\) reads \(z_1\oplus z_2=0\), so the circuit returns one of \(000\), \(001\), \(110\), \(111\), each with probability \(\tfrac14\).

One run of Simon’s algorithmBoth registers have n qubits. Measuring the output collapses the input onto a pair {x₀,x₀⊕ s}; the Hadamard layer turns the unknown x₀ into a phase and returns a random z with s· z=0. The output measurement may be omitted without changing the statistics of z. Read each circuit left to right; double lines carry classical measurement records.One run of Simon’s algorithm|0ⁿ⟩z|0ⁿ⟩f(x₀)1/√2(|x₀⟩+|x₀⊕ s⟩)H^(⊗ n)U_fH^(⊗ n)
Both registers have \(n\) qubits. Measuring the output collapses the input onto a pair \(\{x_0,x_0\oplus s\}\); the Hadamard layer turns the unknown \(x_0\) into a phase and returns a random \(z\) with \(s\cdot z=0\). The output measurement may be omitted without changing the statistics of \(z\).

Measuring the output register is not essential; leaving it unmeasured gives the same statistics for \(z\), since the output is never used again. It is a convenient way to see the state. The algorithm is due to Simon, On the Power of Quantum Computation (1994/1997).

Problems
  1. For \(n=3\) and \(s=110\), list the four collision pairs and the strings \(z\) the circuit can return.

    Show solutionHide solution

    Pairs: \(\{000,110\}\), \(\{001,111\}\), \(\{010,100\}\), \(\{011,101\}\). Allowed \(z\) satisfy \(z_1\oplus z_2=0\): \(000,001,110,111\), each with probability \(\frac14\).

  2. Why does the random \(x_0\) not spoil the result, even though different runs collapse onto different pairs?

    Show solutionHide solution

    \(x_0\) enters the amplitude of \(z\) only through the factor \((-1)^{x_0\cdot z}\), which has magnitude one. Whether \(z\) is allowed depends only on \(s\cdot z\). The Hadamard transform converts a shift of the pair, which is unknown, into a phase, which is invisible to measurement, while the spacing of the pair, which is \(s\), determines which outcomes occur.

  3. What does the circuit return if \(f\) is one-to-one (equivalently, \(s=0^n\))? How could an algorithm detect this case?

    Show solutionHide solution

    After measuring the output, the input is a single basis state \(\ket{x_0}\), and \(H^{\otimes n}\) gives every \(z\) with probability \(2^{-n}\). The samples then span all of \(\{0,1\}^n\) after about \(n\) runs, so no nonzero \(s\) satisfies all equations. The algorithm can detect this and report “one-to-one”, after confirming with classical checks if needed.

3.3.2 Recovering the string§

linear algebra over GF(2)classical post-processinggroupabelian groupsubgroupcoset

One run gives one equation \(s\cdot z=0\) over bits. How many runs determine \(s\), and how do we combine them? These are linear equations modulo two, and solving them is linear algebra over GF(2), arithmetic in which \(1+1=0\). Collect \(n-1\) linearly independent equations; then the solution space is \(\{0^n,s\}\), and the nonzero solution is \(s\). Gaussian elimination finds it in \(O(n^3)\) classical bit operations.

Return to \(n=3\) and \(s=110\). Suppose the runs return \(z=001\) and then \(z=111\). The equations are \(s_3=0\) and \(s_1\oplus s_2\oplus s_3=0\), so \(s_1=s_2\). The nonzero solution is \(s=110\). If the second run had returned \(000\) or \(001\) again, it would add no information, and we would run again.

Simon’s algorithm for n = 3 and s = 110Collision pairs {x,x⊕ s}, the strings z the circuit can return, and how two independent samples determine s by linear algebra modulo two. Columns: Collision pairs, Possible outputs z, Example run. {000,110}, {001,111}, 000, 001, sample z=001: s₃=0; {010,100}, {011,101}, 110, 111, sample z=111: s₁⊕ s₂⊕ s₃=0; each pair shares one value of f, each with probability 1/4, nonzero solution s=110Simon’s algorithm for n = 3 and s = 110Collision pairsPossible outputs zExample run{000,110}, {001,111}000, 001sample z=001: s₃=0{010,100}, {011,101}110, 111sample z=111:s₁⊕ s₂⊕ s₃=0each pair shares onevalue of feach with probability1/4nonzero solution s=110
Collision pairs \(\{x,x\oplus s\}\), the strings \(z\) the circuit can return, and how two independent samples determine \(s\) by linear algebra modulo two.

How many runs are needed? The samples are uniform over the \((n-1)\)-dimensional space of strings orthogonal to \(s\). If we already have \(k\) independent samples, they span \(2^k\) strings, so a new sample is dependent with probability \(2^{k}/2^{n-1}\). The expected wait for an independent one is \(1/(1-2^{k-n+1})\) runs. Writing \(j=n-1-k\) and summing over \(k=0,\ldots,n-2\),

\[\sum_{j=1}^{n-1}\frac{1}{1-2^{-j}}\le\sum_{j=1}^{n-1}\big(1+2^{1-j}\big)<(n-1)+2=n+1,\]

using \(1/(1-u)\le1+2u\) for \(0\le u\le\tfrac12\). So the expected number of runs is less than \(n+1\). A standard tail bound, which we quote, shows that \(n+O(\log(1/\delta))\) runs fail with probability below \(\delta\).

Simon’s algorithm uses \(O(n)\) queries against the classical \(\Omega(2^{n/2})\), an exponential separation for bounded-error algorithms in the black-box model.

What structure made it work, and will the same strategy work elsewhere? Three facts were used. Strings combine by XOR, and the result is again a string. The string \(0^n\) changes nothing, \(x\oplus0^n=x\). And every string undoes itself, \(x\oplus x=0^n\). A set with an operation that has these three properties (closure, an identity element, and an inverse for every element, together with the associativity that XOR has) is called a group. The integers \(\{0,1,\ldots,N-1\}\) under addition modulo \(N\) form another group, with identity \(0\) and the inverse of \(a\) equal to \(N-a\) for \(a\neq0\). In both examples the order of combination does not matter, \(x\oplus y=y\oplus x\) and \(a+b=b+a\); a group with this property is an abelian group.

The hidden pair \(\{0^n,s\}\) is itself a group under XOR, since \(s\oplus s=0^n\). A subset of a group that is a group under the same operation is a subgroup. The collision pair \(\{x_0,x_0\oplus s\}\) is the subgroup shifted by \(x_0\). A shifted copy \(x_0\oplus\{0^n,s\}\) of a subgroup is called a coset. Simon’s function is constant on each coset and takes different values on different cosets, so the measurement of \(f(x)\) collapsed the input onto a random coset.

In this language the algorithm is a template: a coherent query, a measurement that collapses onto a random coset of a hidden subgroup, a Fourier-type transform that turns the unknown shift into a harmless phase, and classical post-processing of several samples. For period finding the group of strings under XOR becomes the integers modulo \(N\) under addition, and the Hadamard transform becomes the quantum Fourier transform. Gaussian elimination is replaced by a number-theoretic method that recovers a fraction from a close approximation.

Problems
  1. For \(n=3\), suppose the samples are \(110\) and \(111\). Find \(s\).

    Show solutionHide solution

    Equations: \(s_1\oplus s_2=0\) and \(s_1\oplus s_2\oplus s_3=0\). Subtracting gives \(s_3=0\), and \(s_1=s_2\). Nonzero solution: \(s=110\).

  2. For \(n=4\), what is the probability that three samples are linearly independent?

    Show solutionHide solution

    The space has dimension 3, with 8 elements. The first sample must be nonzero: \(7/8\). The second must avoid the span of the first (2 elements): \(6/8\). The third must avoid a span of 4: \(4/8\). Product: \(\frac{7\cdot6\cdot4}{512}=\frac{168}{512}\approx0.33\). Low, but each extra run raises the chance quickly; the expected number of runs is below 5.

  3. Is the speedup of Simon’s algorithm a speedup for any practical problem?

    Show solutionHide solution

    Not directly: the problem is artificial, and its value is as a demonstration that black-box quantum query complexity can be exponentially smaller than bounded-error classical query complexity. Its structure inspired Shor’s algorithm, and variants of it have been used to attack certain symmetric-key constructions when an adversary has coherent access to a keyed function, an access assumption that must be stated with the claim.

3.4

Phase Arithmetic

So far every phase has been a sign, \(\pm1\). Many algorithms need finer phases: \(e^{2\pi iv/M}\) for a computed integer \(v\), or \(e^{i\theta(x)}\) for a computed angle. Can we produce them as cleanly as signs? Splitting \(v\) into bits gives one phase gate per bit. An adder acting on a special state gives the same phases from arithmetic alone. Both use finitely many bits, so we must then bound the error that finite precision introduces, and see how such errors accumulate over many uses.

3.4.1 Phases from computed values§

phase gatebinary fraction

How do we turn a computed integer into a phase? Suppose a clean computation writes an \(m\)-bit integer \(v=\sum_jv_j2^j\) into a register, and we want the phase \(e^{2\pi iv/2^m}\). The exponent splits into a sum over bits, so the phase splits into a product:

\[e^{2\pi iv/2^m}=\prod_{j=0}^{m-1}e^{2\pi iv_j2^j/2^m}=\prod_{j=0}^{m-1}P\!\left(\frac{2\pi}{2^{m-j}}\right)^{v_j},\]

where \(P(\theta)=\mathrm{diag}(1,e^{i\theta})\) is the phase gate. So apply \(P(2\pi/2^{m-j})\) to bit \(j\), one gate per bit, then uncompute \(v\). The highest bit gets \(P(\pi)=Z\), the next \(P(\pi/2)=S\), then \(P(\pi/4)=T\), and so on. The quantity \(v/2^m\) is the binary fraction \(0.v_{m-1}\cdots v_0\), and each bit contributes its own share of a full turn.

A phase from a computed integerC computes a three-bit value v=4v₂+2v₁+v₀ from x. Phase gates Z, S, T on the bits multiply by e^(2π iv/8); C⁻¹ then clears the register so that only the phase remains on |x⟩. Read each circuit left to right; double lines carry classical measurement records.A phase from a computed integer|x⟩e^(2π iv(x)/8)|x⟩v₂:|0⟩|0⟩v₁:|0⟩|0⟩v₀:|0⟩|0⟩CZSTC⁻¹
\(C\) computes a three-bit value \(v=4v_2+2v_1+v_0\) from \(x\). Phase gates \(Z\), \(S\), \(T\) on the bits multiply by \(e^{2\pi iv/8}\); \(C^{-1}\) then clears the register so that only the phase remains on \(\ket x\).

For \(m=3\) and \(v=5=101_2\): \(Z\) on \(v_2=1\) gives \(-1\), \(S\) on \(v_1=0\) gives \(1\), \(T\) on \(v_0=1\) gives \(e^{i\pi/4}\). The product is \(-e^{i\pi/4}=e^{i5\pi/4}=e^{2\pi i\cdot5/8}\). Correct.

The same idea applies with a real angle: if \(\theta(x)\) is computed to \(m\) bits as an approximation, applying the phase gates gives \(e^{i\tilde\theta(x)}\) with \(\tilde\theta\) the rounded angle. The cost is \(m\) controlled rotations plus computing and uncomputing \(\tilde\theta\). Small-angle rotations are not elementary in fault-tolerant gate sets; each must itself be synthesized to some accuracy, and that error must be counted too.

Problems
  1. Which phase gates produce \(e^{2\pi iv/16}\) for a four-bit \(v\), and what is the phase for \(v=6\)?

    Show solutionHide solution

    \(P(\pi)\) on \(v_3\), \(P(\pi/2)\) on \(v_2\), \(P(\pi/4)\) on \(v_1\), \(P(\pi/8)\) on \(v_0\). For \(v=6=0110_2\): \(S\) and \(T\) act, giving \(e^{i\pi/2}e^{i\pi/4}=e^{i3\pi/4}=e^{2\pi i\cdot6/16}\).

  2. Does the bitwise product formula still produce \(e^{2\pi iv/3}\) for an \(m\)-bit \(v\)? What changes in practice?

    Show solutionHide solution

    Yes: \(e^{2\pi iv/3}=\prod_jP(2\pi2^j/3)^{v_j}\) holds for any modulus, since the exponent is still a sum over bits. What changes is that the angles \(2\pi2^j/3\) are not multiples of \(\pi/2^k\), so they are not among the exactly implementable gates \(Z,S,T\) of a Clifford+\(T\) gate set. Each rotation must be synthesized approximately, and its error counted in the operator norm.

  3. A student applies the phase gates to the bits of \(v\) but forgets to uncompute \(v\). Describe the resulting state for an input superposition \(\sum_x\alpha_x\ket x\).

    Show solutionHide solution

    The state is \(\sum_x\alpha_xe^{2\pi iv(x)/2^m}\ket x\ket{v(x)}\) plus any garbage. The phases are present but the register \(\ket{v(x)}\) is a which-path record: branches with different \(v\) cannot interfere, so the phases are useless for any later interference on \(x\) alone.

3.4.2 Phase kickback from modular addition§

Fourier statephase-gradient trick

Can we avoid small rotation gates altogether? There is a second way, which reuses arithmetic instead. On an \(m\)-qubit register with \(M=2^m\), prepare the state

\[\ket\chi=\frac{1}{\sqrt M}\sum_{y=0}^{M-1}e^{-2\pi iy/M}\ket y.\]

Adding an integer \(v\) modulo \(M\) to this register multiplies it by a phase. Indeed, substituting \(z=y+v\bmod M\),

\[\frac{1}{\sqrt M}\sum_ye^{-2\pi iy/M}\ket{y+v}=\frac{1}{\sqrt M}\sum_ze^{-2\pi i(z-v)/M}\ket z=e^{2\pi iv/M}\ket\chi.\]

The phase is consistent modulo \(M\) because \(e^{-2\pi iM/M}=1\). So \(\ket\chi\) is an eigenstate of “add \(v\)”, with eigenvalue \(e^{2\pi iv/M}\). Kickback then says what to do: control the addition by the input. If a clean computation produces \(v(x)\) and we add it into \(\ket\chi\), the phase \(e^{2\pi iv(x)/M}\) is kicked back onto \(\ket x\), and \(\ket\chi\) is untouched.

Phase kickback from modular additionThe register holding |chi⟩=M^(−1/2)Σ_ye^(−2π iy/M)|y⟩ is an eigenstate of adding v modulo M, with eigenvalue e^(2π iv/M). A clean addition of a computed v(x) therefore kicks the phase back onto |x⟩ and leaves |chi⟩ unchanged for reuse. Read each circuit left to right; double lines carry classical measurement records.Phase kickback from modular addition|x⟩e^(2π iv(x)/M)|x⟩|chi⟩|chi⟩add v(x) mod M
The register holding \(\ket\chi=M^{-1/2}\sum_ye^{-2\pi iy/M}\ket y\) is an eigenstate of adding \(v\) modulo \(M\), with eigenvalue \(e^{2\pi iv/M}\). A clean addition of a computed \(v(x)\) therefore kicks the phase back onto \(\ket x\) and leaves \(\ket\chi\) unchanged for reuse.

This construction, sometimes called the phase-gradient trick, turns an adder into a bank of phase rotations. The state \(\ket\chi\) is prepared once and reused for every query, since it is never changed. It is a Fourier state; we will see that it is the quantum Fourier transform of a basis state. The cost is a reversible adder per phase operation plus a one-time preparation.

Problems
  1. For \(m=1\) (\(M=2\)), what is \(\ket\chi\), and what does “add \(v\) mod 2” do to it?

    Show solutionHide solution

    \(\ket\chi=\frac{1}{\sqrt2}(\ket0-\ket1)=\ket-\). Adding \(v\) mod 2 is \(X^v\), which multiplies \(\ket-\) by \((-1)^v=e^{2\pi iv/2}\). This is exactly the \(\ket-\) target of Deutsch’s circuit.

  2. For \(M=4\), verify by direct calculation that adding \(1\) maps \(\ket\chi\) to \(i\ket\chi\).

    Show solutionHide solution

    \(\ket\chi=\frac12(\ket0-i\ket1-\ket2+i\ket3)\). Adding \(1\) gives \[\frac12(\ket1-i\ket2-\ket3+i\ket0)=\frac12(i\ket0+\ket1-i\ket2-\ket3)=i\cdot\frac12(\ket0-i\ket1-\ket2+i\ket3)\].

  3. Why must the adder be exactly modulo \(M\) for the trick to work? What happens with an adder into an \((m+1)\)-bit register that does not wrap?

    Show solutionHide solution

    The proof substitutes \(z=y+v\bmod M\) and uses \(e^{-2\pi iM/M}=1\). Without wrapping, terms with \(y+v\ge M\) land outside the original register’s support, so the result is not proportional to \(\ket\chi\): the target changes and becomes entangled with \(v\), leaving a record.

3.4.3 Precision and workspace restoration§

phase erroroperator norm

Phases computed to finitely many bits are approximate. How much does that phase error matter? Suppose the intended phase oracle multiplies \(\ket x\) by \(e^{i\phi(x)}\), but the implementation uses \(\tilde\phi(x)\) with \(|\phi(x)-\tilde\phi(x)|\le\delta\) for every \(x\). On a basis state the error is

\[|e^{i\phi}-e^{i\tilde\phi}|=2\left|\sin\frac{\phi-\tilde\phi}{2}\right|\le|\phi-\tilde\phi|\le\delta.\]

On a normalized superposition \(\sum_x\alpha_x\ket x\), the error vector has squared length \(\sum_x|\alpha_x|^2|e^{i\phi(x)}-e^{i\tilde\phi(x)}|^2\le\delta^2\). So the state error is at most \(\delta\), for every input state. The largest such error over all normalized inputs is the operator norm of the difference of the two operations, here at most \(\delta\). Rounding \(\phi\) to the nearest multiple of \(2\pi/M\) gives \(\delta\le\pi/M\), so \(m=\log_2M\) bits give error \(O(2^{-m})\).

What happens when several approximate operations are composed? Suppose \(\|U_1-V_1\|\le\delta_1\) and \(\|U_2-V_2\|\le\delta_2\), all four unitary. Then

\[U_2U_1-V_2V_1=U_2(U_1-V_1)+(U_2-V_2)V_1.\]

Unitaries preserve lengths, so the first term has norm at most \(\delta_1\) and the second at most \(\delta_2\). The product therefore has error at most \(\delta_1+\delta_2\): an error introduced early is not amplified later. An algorithm using \(q\) approximate phase oracles therefore has total error at most \(q\delta\). To keep the total below \(\epsilon\), each oracle needs \(\delta\le\epsilon/q\), which costs only \(\log_2(q/\epsilon)\) bits of phase precision.

Phase precision as a resourceErrors are measured in operator norm, the largest change to any normalized state. Because unitaries preserve length, errors of composed operations add. Columns: Quantity, Bound, Consequence. One phase, error delta in angle, |e^(iφ)−e^(itildeφ)|≤delta, State error at most delta; Rounding to m bits, delta≤π/2^m, Error halves per extra bit; q approximate operations, total error ≤ qdelta, Need delta≤ε/q; Bits per operation, m≈log₂(π q/ε), Logarithmic in q/εPhase precision as a resourceQuantityBoundConsequenceOne phase, error deltain angle|e^(iφ)−e^(itildeφ)|≤deltaState error at mostdeltaRounding to m bitsdelta≤π/2^mError halves per extrabitq approximate operationstotal error ≤ qdeltaNeed delta≤ε/qBits per operationm≈log₂(π q/ε)Logarithmic in q/ε
Errors are measured in operator norm, the largest change to any normalized state. Because unitaries preserve length, errors of composed operations add.

Precision is not the only failure mode. Both constructions compute an intermediate value \(v(x)\) and must uncompute it. If \(v\) is left in its register, the branches \(\ket x\ket{v(x)}\) carry different records, and the phases cannot interfere, however precise they are. With clean phase oracles of known precision in hand, we can ask what structured phase patterns such as \(e^{2\pi ixy/N}\) reveal.

Problems
  1. An algorithm makes \(1000\) phase-oracle calls and needs total error at most \(10^{-3}\). How many bits of phase precision suffice per call?

    Show solutionHide solution

    Each call needs \(\delta\le10^{-6}\). Rounding to \(m\) bits gives \(\delta\le\pi/2^m\), so \(2^m\ge\pi\times10^6\), \(m\ge22\).

  2. Show that the product of two operations with errors \(\delta_1\), \(\delta_2\) has error at most \(\delta_1+\delta_2\). Write the approximations as \(\tilde A=A+E\), \(\tilde B=B+F\) with \(A,B,\tilde A\) unitary.

    Show solutionHide solution

    \[\tilde A\tilde B-AB=\tilde A(\tilde B-B)+(\tilde A-A)B=\tilde AF+EB\]. Since \(\tilde A\) and \(B\) are unitary they preserve lengths, so \(\|\tilde AF\psi\|=\|F\psi\|\le\delta_2\) and \(\|EB\psi\|\le\delta_1\) for normalized \(\psi\). The triangle inequality gives \(\delta_1+\delta_2\).

  3. If phase errors are random and independent across calls rather than worst-case, the total error often grows like \(\sqrt q\delta\) instead of \(q\delta\). Why should a resource estimate still usually state the worst-case bound?

    Show solutionHide solution

    The \(\sqrt q\) behavior needs an assumption about the error distribution (independence, zero mean) that a deterministic rounding procedure need not satisfy: rounding errors can be systematic and add coherently. The linear bound holds unconditionally. A paper may use the statistical estimate if it states and justifies the assumption.

Summary

Questions and worked problems

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

1. Quick check §

For n = 4 and s = 0110, give the sign of the |x⟩ term after the Bernstein–Vazirani query for x = 0101 and x = 0011.

Hint 1

The sign is (−1)^{s·x}.

Hint 2

Count positions where both s and x have a 1.

Worked solution

For x = 0101, s and x share a 1 only in the second position, so s·x = 1 and the sign is −. For x = 0011, they share a 1 only in the third position, so the sign is also −.

Revisit the relevant explanation

2. Quick check §

The target of a Hadamard test is \(\ket1\), an eigenstate of \(T=\mathrm{diag}(1,e^{i\pi/4})\). Compute \(\Pr[0]\) when the controlled operation is controlled-\(T\), and again when it is controlled-\(T^4\). Which of the two runs tells you more about the phase, and why?

Hint 1

Use \(\Pr[0]=(1+\cos\phi)/2\) with the kicked-back phase.

Hint 2

\(T^4=Z\).

Worked solution

Controlled-\(T\) kicks back \(\phi=\pi/4\), so \(\Pr[0]=(1+\cos\frac\pi4)/2\approx0.854\). Controlled-\(T^4=\)controlled-\(Z\) kicks back \(4\phi=\pi\), so \(\Pr[0]=0\): the outcome is \(1\) with certainty. The second run is deterministic, so a single shot settles a question about the phase (that \(4\phi\) is an odd multiple of \(\pi\)), while the first run is a biased coin that needs many repetitions to estimate. Powers of the unitary multiply the phase, and choosing powers so that the outcome becomes nearly certain is the idea behind phase estimation.

Revisit the relevant explanation

3. Quick check §

After a phase query on the uniform superposition of three qubits, the signs on \(x=000,001,\dots,111\) are \(+,+,-,-,+,+,-,-\). What does \(H^{\otimes3}\) produce, and why is the outcome certain?

Hint 1

Which bit of \(x\) does the sign depend on?

Hint 2

Signs of the form \((-1)^{s\cdot x}\) are mapped to \(\ket s\).

Worked solution

Writing \(x=x_1x_2x_3\), the sign is \(-\) exactly when the middle bit \(x_2=1\), so the pattern is \((-1)^{s\cdot x}\) with \(s=010\). That is a row of the Hadamard table, and since \(H^{\otimes3}\) is its own inverse it maps the state exactly to \(\ket{010}\). The outcome is certain because the sign pattern is linear; this is a Bernstein–Vazirani oracle with hidden string \(010\).

Revisit the relevant explanation

4. Worked problem §

In Simon’s algorithm with n = 3, the samples are 011 and 101. Find s, and say whether a third sample is needed.

Hint 1

Write s₂ ⊕ s₃ = 0 and s₁ ⊕ s₃ = 0.

Hint 2

Two independent equations in three unknowns leave a one-dimensional solution space.

Worked solution

The equations give s₂ = s₃ and s₁ = s₃, so s ∈ {000, 111}; the nonzero solution is s = 111. The two samples are independent and n − 1 = 2, so no third sample is needed. Check: 111·011 = 0 and 111·101 = 0.

Revisit the relevant explanation

5. Worked problem §

Run the Bernstein–Vazirani circuit on a function that is not linear: \(f(x_1x_2)=x_1\land x_2\). Compute the amplitude of each outcome \(z\) using \(\frac14\sum_x(-1)^{f(x)+x\cdot z}\). What can the measurement tell you about \(f\)?

Hint 1

Write \((-1)^{f(x)}=1-2[x=11]\).

Hint 2

\(\sum_x(-1)^{x\cdot z}\) is \(4\) for \(z=00\) and \(0\) otherwise.

Worked solution

Since \((-1)^{f(x)}=1-2[x=11]\), the amplitude is \(\frac14\big(\sum_x(-1)^{x\cdot z}-2(-1)^{z_1\oplus z_2}\big)=[z=00]-\frac12(-1)^{z_1\oplus z_2}\). This gives \(\frac12,\frac12,\frac12,-\frac12\) for \(z=00,01,10,11\). Every outcome has probability \(1/4\): the measurement is a uniformly random string. The sign pattern \(+,+,+,-\) is equally far from all four linear patterns, overlapping each with magnitude \(1/2\), so no outcome is favored. The Hadamard readout is perfect only for linear phase patterns; for other functions it samples the overlaps with linear patterns, and here they are all equal.

Revisit the relevant explanation

6. Worked problem §

In Simon’s algorithm with \(n=3\), each run returns a uniformly random string from the four strings orthogonal to \(s\), including \(000\). Compute the expected number of runs needed to collect two linearly independent samples. Compare with the bound \(n+1\) from the text.

Hint 1

The first useful sample must be nonzero.

Hint 2

With one nonzero sample \(z_1\), a new sample is useless if it is \(000\) or \(z_1\).

Worked solution

The first stage waits for a nonzero sample, which appears with probability \(3/4\), so it takes \(4/3\) runs on average. Once a nonzero \(z_1\) is held, a new sample adds information unless it lies in \(\{000,z_1\}\), which has probability \(2/4\); the expected wait is \(2\) runs. The total expectation is \(4/3+2=10/3\approx3.3\) runs, below \(n+1=4\). Each run uses one query, so about \(3.3\) queries on average, plus Gaussian elimination on two equations. For larger \(n\) the same staging gives \(\sum_{k=0}^{n-2}1/(1-2^{k-n+1})\), which stays below \(n+1\).

Revisit the relevant explanation

7. Worked problem §

For \(M=8\), write the phase-gradient state \(\ket\chi=\frac{1}{\sqrt8}\sum_ye^{-2\pi iy/8}\ket y\) and verify that adding \(v=3\) modulo \(8\) multiplies it by \(e^{3\pi i/4}\). Then suppose a library prepares \(\ket{\chi'}=\frac{1}{\sqrt8}\sum_ye^{+2\pi iy/8}\ket y\) instead. What phase does adding \(v\) produce, and how can you obtain the intended phase using the same state?

Hint 1

Substitute \(z=y+3\bmod 8\) and use \(e^{-2\pi i\cdot8/8}=1\).

Hint 2

Subtracting \(v\) is the inverse of adding \(v\).

Worked solution

After adding \(3\), the amplitude on \(\ket z\) is the old amplitude on \(\ket{z-3}\), namely \(e^{-2\pi i(z-3)/8}/\sqrt8=e^{6\pi i/8}e^{-2\pi iz/8}/\sqrt8\). So the state is \(e^{3\pi i/4}\ket\chi\), as claimed; wrap-around is harmless because the phases repeat with period \(8\). With \(\ket{\chi'}\) the same substitution gives the factor \(e^{-2\pi iv/8}\): the phase has the opposite sign. Running the adder backwards (subtracting \(v\)) then gives \(e^{+2\pi iv/8}\). Sign conventions of Fourier states must be checked, because a reversed phase passes every test that only looks at probabilities of a single query.

Revisit the relevant explanation

8. Misconception §

A student writes: “Phase kickback never changes the target, so any target state will do.” Test the claim with controlled-\(Z\), control in \(\ket+\), and target \(\ket+\). Compute the joint state and the Hadamard-test probability \(\Pr[0]\), and check it against \(\frac12(1+\mathrm{Re}\bra\psi U\ket\psi)\).

Hint 1

\(Z\ket+=\ket-\), which is orthogonal to \(\ket+\).

Hint 2

Branches with orthogonal target states cannot interfere.

Worked solution

The controlled-\(Z\) gives \(\frac{1}{\sqrt2}(\ket0\ket++\ket1\ket-)\). The target is now entangled with the control and holds a perfect record of the control branch, because \(\ket+\) and \(\ket-\) are orthogonal. After the Hadamard on the control, both outcomes have probability \(1/2\). The formula agrees: \(\bra+Z\ket+=0\), so \(\Pr[0]=\frac12\). The claim fails because kickback leaves the target unchanged only when the target is an eigenstate. Here \(\ket+\) is a superposition of the eigenstates \(\ket0\) and \(\ket1\), with eigenvalues \(+1\) and \(-1\), and the two phases land on different target components.

Revisit the relevant explanation

9. Extension §

The Hadamard test is run on an eigenstate with unknown phase φ, estimating cos φ to within ε. Show that the resulting uncertainty in φ is largest near φ = 0 and φ = π, and explain why using controlled-U² does not remove the ambiguity between φ and −φ.

Hint 1

A change δ in φ changes cos φ by about sin φ · δ.

Hint 2

cos(2φ) is also even in φ.

Worked solution

Since d(cos φ)/dφ = −sin φ, an error ε in cos φ gives an error of about ε/|sin φ| in φ, which blows up near φ = 0 and π, where the cosine is flat. Using U² kicks back 2φ and measures cos 2φ, which is still an even function of φ, so φ and −φ remain indistinguishable; only the sin φ test (with S†) resolves the sign. Phase estimation in the Fourier Methods chapter avoids both problems by reading phases with a Fourier transform.

Revisit the relevant explanation

10. Extension §

In Simon’s algorithm the samples are uniform over the \((n-1)\)-dimensional space \(s^\perp\) of strings orthogonal to \(s\). Show that \(n-1+t\) samples fail to span \(s^\perp\) with probability less than \(2^{-t}\). Use the fact that samples fail to span exactly when they all lie in some subspace of \(s^\perp\) of one lower dimension, and that \(s^\perp\) has \(2^{n-1}-1\) such subspaces.

Hint 1

A fixed subspace of one lower dimension contains half of \(s^\perp\).

Hint 2

Apply the union bound over all such subspaces.

Worked solution

Fix a subspace \(W\) of \(s^\perp\) of dimension \(n-2\). It contains half of \(s^\perp\), so a uniform sample lies in \(W\) with probability \(1/2\), and \(n-1+t\) independent samples all lie in \(W\) with probability \(2^{-(n-1+t)}\). If the samples fail to span, they lie in at least one such \(W\). There are \(2^{n-1}-1\) choices, so by the union bound \(\Pr[\text{fail}]\le(2^{n-1}-1)2^{-(n-1+t)}<2^{-t}\). With \(t=\log_2(1/\delta)\) extra runs, failure is below \(\delta\), giving the \(n+O(\log(1/\delta))\) query bound in the text. The bound is independent of which \(s\) is hidden.

Revisit the relevant explanation

Where this leads. the Fourier Methods chapter replaces the binary sign patterns by phases e^{2πixy/N}, read by the quantum Fourier transform, and combines controlled powers with kickback into phase estimation and period finding.

Search this book

Search the course.