In Quantum Computing we learned the rules of the game. A state is a list of amplitudes, gates act on it as unitary matrices, and a measurement returns one outcome with probability given by a squared amplitude. With those rules we followed a few algorithms, such as Deutsch’s and Grover’s, step by step.
Following an algorithm is not the same as designing one. A quantum computer does not try every answer and hand back the best; its final measurement returns a single outcome. Faced with a new problem, which decisions turn it into a circuit whose likely outcome is the answer we want?
We answer with the smallest case, Deutsch’s problem: does a hidden one-bit function give the same output on both inputs? A claim of speed means nothing until the question is fixed, so we fix it first. The question decides what access to the function we must assume. That access lets us encode the answer in signs and make the signs interfere, and a leftover record would block the interference, so we learn to remove it. The interfering amplitudes must then be read, which forces a choice of measurement and a count of repetitions. Only then can we prove the circuit correct for a whole family of inputs and compare its full cost with the best classical method.
The same decisions, made with stronger tools, build every algorithm in the rest of the course.
How do we turn a computational problem into a quantum procedure whose answer can actually be read?
Every quantum algorithm in this course is built by the same sequence of decisions; Deutsch’s problem shows each one in its simplest form.
Reading guide · preparation, aims, and assumptions
Learn the design process that the whole course follows: state the problem and access, encode the property, engineer interference, construct the readout, prove correctness, and account for resources.
Before you begin
Use amplitudes, Hadamard gates, reversible oracles \(U_f\), measurement probabilities, and global versus relative phase, as developed in Quantum Computing.
What you should be able to do
State a computational problem with its input family, promise, output type, and success criterion.
Distinguish coherent oracle access from classical data and identify which related operations are separate assumptions.
Derive the output amplitudes of the Deutsch circuit and explain why a target record destroys interference.
Compute the effect of repetition on decision and estimation tasks.
Separate a fixed-size query separation from an asymptotic or end-to-end advantage.
The example to follow
Deutsch’s problem: decide whether a hidden one-bit function has equal outputs, using one coherent query. The same design is then extended to the n-bit Deutsch–Jozsa family.
Scope and assumptions
All gates and oracles are ideal. Query counts exclude oracle construction. The Deutsch–Jozsa separation is exact and worst-case; it disappears against bounded-error classical algorithms.
1.1
Defining the Problem
What exactly must an algorithm hand back, for which inputs, and with what guarantee? If we leave this vague, a claimed speedup may answer an easier question than the one posed, or it may be compared with a classical method that was asked for more. So we first pin down the inputs and the required answer for a hidden one-bit function. Then we ask how the kind of answer, a bit, a witness, a number or a sample, changes what an algorithm must extract.
Imagine a sealed device with one input switch and one output lamp. Set the switch to \(x\in\{0,1\}\) and the lamp shows a bit \(f(x)\). The wiring inside is fixed but hidden. Your job is not to reconstruct the device. Your job is to report one property of it: do the two switch positions give the same lamp?
Write the required answer as
\[d=f(0)\oplus f(1),\]
where \(\oplus\) is addition modulo two. The answer \(d=0\) means the outputs agree, and \(d=1\) means they differ. There are exactly four possible devices, and we can list them all.
Each row is one hidden device. The algorithm must output \(d=f(0)\oplus f(1)\): it must separate the rows into two classes, not identify the row.
Look at what this table asks for. Two of the four functions share each answer. The algorithm must separate the rows into two groups, not identify the row. That is less than the full truth table. Can we learn less more cheaply?
A classical procedure that is allowed to look at the lamp can certainly compare both outputs. Can it do so with one look? Suppose it sets the switch to \(0\) and sees \(f(0)=0\). Rows one and two are both still possible, and they have different answers. The same happens whichever input is tried first and whichever value appears. One inspection cannot determine \(d\) with certainty, because the unseen value changes the answer.
Three pieces of the problem statement are now explicit, and every later chapter will ask for the same three. The input family is the set of instances the algorithm must handle: here, all four functions. A promise is a restriction on that family which the algorithm may assume without checking. Deutsch’s problem needs none, since every one-bit function either agrees or disagrees with itself across inputs. For an \(n\)-bit function the analogous promise “constant or balanced” is a genuine restriction, and an algorithm that relies on it may give meaningless output on functions that break it. The success criterion says what counts as a correct run. Here we demand the right \(d\) with certainty on every row. Later problems allow error probability, say at most \(1/3\) per instance. That allowance must be granted to classical and quantum methods alike before their costs are compared.
Problems
Without looking back, list the four one-bit Boolean functions and the required output \(d\) for each. Which pairs of functions must the algorithm treat identically?
Show solutionHide solution
The functions are \(f\equiv0\), \(f(x)=x\), \(f(x)=1\oplus x\), and \(f\equiv1\), with \(d=0,1,1,0\). The algorithm must give the same output for the two constant functions and the same output for the two balanced ones. It is allowed to be unable to tell \(f\equiv0\) from \(f\equiv1\).
Suppose the problem is changed to “report \(f(0)\) and \(f(1)\).” Show that any algorithm, classical or quantum, that reads one classical bit from each run needs at least two runs, whatever happens inside a run.
Show solutionHide solution
There are four equally possible answers, so the output must carry two bits. One run produces one classical bit, and one bit can distinguish at most two cases. Two runs are necessary. This is an information-counting argument, independent of the mechanism. It shows why the quantum algorithm in this chapter answers the one-bit question \(d\) and nothing more.
For \(n\)-bit inputs, a student proposes the “promise” that \(f\) is either constant or has exactly one input with \(f(x)=1\). Give an algorithm that may rely on this promise and output an answer on any \(f\). What does it output on a function with two ones, and is that a bug?
Show solutionHide solution
Any rule that answers correctly on the promised functions is acceptable; for instance, query every input and report “constant” if all values agree and “one marked” otherwise. On a function with two ones it reports “one marked”, which is neither true nor false relative to the problem: such inputs are outside the promise, and the specification places no requirement on them. It is a bug only if the promise was never part of the stated problem. Stating promises explicitly prevents an algorithm from being credited with work it does not do.
Deutsch’s task asks for one bit. What changes when a task asks for something else? Take one Boolean function \(f\) on \(N\) inputs, and call an input marked when \(f(x)=1\). We can ask four different questions about the same \(f\).
First, is there any marked input? The answer is yes or no. A task whose answer is one bit is a decision problem.
Second, which input is marked? Now the answer is a witness: some \(x\) with \(f(x)=1\), or a report that none exists. This is a search problem. A witness can usually be checked with one more evaluation of \(f\), so a search algorithm that sometimes fails can still recognize its successes.
Third, how many inputs are marked? Let \(p\) be the fraction of marked inputs. An exact count may be expensive, so we ask instead for a number \(\tilde p\) with \(|\tilde p-p|\le\epsilon\), allowing failure with probability at most \(\delta\). This is an estimation problem. Its statement needs two numbers, the tolerance \(\epsilon\) and the failure probability \(\delta\). No single evaluation of \(f\) can check its answer.
Fourth, can we have a typical marked input? A sampling problem asks for a random output whose distribution is close to a target \(q(x)\), for example the uniform distribution over marked inputs. No single output is right or wrong. Only the distribution over many runs can be judged.
Does an algorithm for one of these questions answer the others? Not cheaply. Estimating \(p\) to within \(0.01\) does not produce any marked input. Producing one marked input says almost nothing about how many there are. So the kind of question must be fixed before two algorithms can be compared.
Quantum algorithms add a fifth kind of output: a quantum state handed to a later computation. A procedure that prepares a state whose amplitudes are proportional to the entries of a vector \(v\) has not output \(v\). Reading even one entry to accuracy \(\epsilon\) generally needs on the order of \(1/\epsilon^2\) repetitions of the whole procedure, and listing all \(N\) entries is at least as costly as \(N\). Algorithms for linear systems, later in the course, produce exactly such states, so this distinction will matter there.
So the second item of every problem statement in this course is the output type: a bit, a string, an estimate with tolerance and confidence, a sample with a distance to the target distribution, or a state with a fidelity requirement. Without it, “faster” has no meaning.
Problems
Classify each task: (a) find a prime factor of \(L\); (b) decide whether \(L\) is prime; (c) estimate the fraction of 20-bit strings satisfying a formula to within \(0.05\); (d) output a uniformly random satisfying assignment.
Show solutionHide solution
(a) Search: a witness is required, and it can be checked by division. (b) Decision. (c) Estimation, with tolerance \(0.05\); a confidence level must also be specified. (d) Sampling: success is judged by the output distribution, not by any one output.
A procedure outputs a marked item with probability \(1/4\) per run and otherwise outputs an unmarked one. Marked items can be recognized with one evaluation of \(f\). How many runs, with checking, make the probability of never seeing a marked item at most \(10^{-3}\)?
Show solutionHide solution
Each run fails independently with probability \(3/4\), so \(R\) runs all fail with probability \((3/4)^R\). We need \((3/4)^R\le10^{-3}\), that is, \(R\ge\ln(10^{3})/\ln(4/3)\approx24.01\), so \(R=25\) runs suffice, with 25 checking evaluations. Checking is what lets us stop at the first success and trust it.
A colleague claims: “My circuit prepares \(\sum_x v_x\ket x\) for a vector \(v\) of length \(N=2^{30}\) using only \(30\) qubits and \(10^4\) gates, so it computes \(v\) exponentially faster than any classical program.” What is wrong with the comparison?
Show solutionHide solution
The classical program outputs all \(2^{30}\) entries; the circuit outputs a state from which a measurement returns one index \(x\), with probability \(|v_x|^2\). Recovering the entries would take at least on the order of \(N\) repetitions, plus more for precision. The two procedures solve different problems. A fair claim must name a task that the state actually serves, such as estimating one specified quantity, and compare against the best classical method for that same task.
1.2
Specifying Access
An algorithm needs a way to learn about its input. For classical algorithms this is usually reading memory, and we rarely think about it. For quantum algorithms the form of access decides what is even possible: can the input be consulted on a superposition of questions? Can that consultation be undone? Can it be controlled by another qubit? We write the access down as a contract and then charge for every use.
1.2.1 Classical data, quantum states, and oracles§
The first register selects the input and is left unchanged. The second, the target, is flipped exactly when \(f(x)=1\). On the four basis states, \(U_f\) is a permutation, so it is unitary; applying it twice restores everything, so \(U_f^{-1}=U_f\). One application of \(U_f\) is one query, whatever state it is applied to.
Why does “whatever state” matter? Because \(U_f\) is linear, it can act on a superposition of inputs, which the lamp cannot. Prepare the input in \(\ket+=(\ket0+\ket1)/\sqrt2\) and the target in \(\ket0\). One query gives
\(U_f\) is the two-register oracle, a composite operation. After the query both values of \(f\) appear in the state, but measuring both registers returns one input with its value.
Figure guide. The figure shows the bit-oracle circuit \(U_f\) acting on an equal superposition \(\frac{1}{\sqrt2}(\ket0+\ket1)\ket0\) and then measuring both registers in the computational basis. Trace the two branches to see why a direct measurement reveals only a single value \(f(x)\) rather than the parity \(d=f(0)\oplus f(1)\).
What to observe
The measurement returns \((0,f(0))\) or \((1,f(1))\), each with probability \(1/2\). Either way we learn one value of \(f\) and nothing about the other, so \(d\) is not determined: we are exactly where the classical single look left us. Writing both values into a superposition is not the same as being able to read them.
Access with this property, where a single use acts linearly on a superposition of questions, is called coherent access. It is an assumption about the problem, not a consequence of quantum mechanics. A physical lamp on a lab bench offers no such operation. When \(f\) is given as a classical program, we can build \(U_f\) from reversible gates, as we will do when we turn classical programs into oracles, and its cost is then a gate count, not an abstract query.
Problems
Write out the \(4\times4\) matrix of \(U_f\) for \(f(x)=x\) in the basis order \(00,01,10,11\), and identify it as a familiar gate.
Show solutionHide solution
\(U_f\) fixes \(00\) and \(01\) and swaps \(10\leftrightarrow11\). Its matrix has rows \((1,0,0,0)\), \((0,1,0,0)\), \((0,0,0,1)\), \((0,0,1,0)\). This is CNOT with the input as control and the target as target.
Apply \(U_f\) for \(f(x)=1\oplus x\) to \(\frac{1}{\sqrt2}(\ket0+\ket1)\ket0\) and give the probabilities of the four measurement outcomes.
Show solutionHide solution
The state becomes \((\ket0\ket1+\ket1\ket0)/\sqrt2\). Outcomes \(01\) and \(10\) each have probability \(1/2\); \(00\) and \(11\) never occur. Each outcome reveals one value of \(f\).
Someone defines a “quantum oracle” as \(V_f\ket x=\ket{f(x)}\) on one qubit. For which \(f\) is \(V_f\) a valid quantum operation, and why does the two-register form avoid the problem?
Show solutionHide solution
\(V_f\) is unitary only when \(f\) is a bijection, that is, \(f(x)=x\) or \(f(x)=1\oplus x\). For a constant \(f\) it maps \(\ket0\) and \(\ket1\) to the same state, which no unitary can do. Keeping \(x\) and adding \(f(x)\) into a separate target makes every \(f\) give a permutation of basis states, so every \(f\) has a valid oracle.
1.2.2 Available operations and hidden preparation costs§
The oracle contract says what \(U_f\) does. Later algorithms will want more: to undo an operation, to control it, to reuse a state, or to start from a table of numbers. Does the contract supply these? We try each in turn and see where it fails.
Suppose we must undo a unitary \(U\). For \(U_f\) this is free, because \(U_f\) is its own inverse. For a general \(U\) handed to us as a sealed box, we can only apply \(U\) itself. If we know a gate sequence for \(U\), we can reverse its order and invert each gate. Without that sequence, applying \(U^\dagger\) is an extra capability, called inverse access.
Next suppose we want \(U\) to act only on the branch where a control qubit is \(1\). From a gate sequence we can control each gate. But a sealed box is known only by its effect on states, and that effect does not fix a global phase: \(U\) and \(e^{i\alpha}U\) act identically. Once controlled, the phase \(e^{i\alpha}\) multiplies only the branch where the control is \(1\). It has become a relative phase between branches, which interference can detect. So the controlled box must be specified separately, phase included. This capability is controlled access.
Now suppose an algorithm needs a state \(\ket\psi\) several times and we hold one copy. Could we copy it? No procedure copies an unknown state; this is the no-cloning theorem. So we must be given either a preparation circuit or many copies, and the number of copies is a resource.
Finally, suppose the input is a classical table of \(N\) numbers. The algorithm wants them as amplitudes, or as an oracle it can query in superposition. Neither exists until a circuit builds it. Such a data loading circuit must read the table, so its cost can be comparable to \(N\). If we assume loading is free, an apparent speedup may come from that assumption alone.
Each form of access is a separate assumption. Possessing one does not provide the others, and each must be implemented and paid for in an end-to-end cost.
Each of these capabilities returns later. Amplitude amplification uses a preparation and its inverse. Phase estimation uses controlled powers of a unitary. Linear-system solvers assume that a matrix is stored inside a larger unitary. In each case the speedup is stated relative to that access, and the access must be implemented and paid for in a full accounting. A box labelled \(U_f\) in a circuit diagram can contain thousands of elementary gates and its own workspace.
Problems
A gate sequence \(U=G_3G_2G_1\) is known, where \(G_1\) acts first. Write a sequence for \(U^\dagger\).
Show solutionHide solution
\(U^\dagger=G_1^\dagger G_2^\dagger G_3^\dagger\): apply \(G_3^\dagger\) first, then \(G_2^\dagger\), then \(G_1^\dagger\). Both the order and each gate are inverted.
Two boxes implement \(U\) and \(e^{i\pi/2}U\). Show that they are indistinguishable when used uncontrolled, but that their controlled versions produce different states on \(\frac{1}{\sqrt2}(\ket0+\ket1)\ket\psi\).
Show solutionHide solution
Uncontrolled, the outputs \(U\ket\psi\) and \(iU\ket\psi\) differ by a global phase, so every measurement probability agrees. Controlled, they give \(\frac{1}{\sqrt2}(\ket0\ket\psi+\ket1U\ket\psi)\) and \(\frac{1}{\sqrt2}(\ket0\ket\psi+i\ket1U\ket\psi)\). The factor \(i\) is now a relative phase between control branches: after a Hadamard on the control, the outcome probabilities generally differ. A sealed box therefore does not determine its own controlled version.
An algorithm needs the amplitude-encoded state \(\sum_{x}v_x\ket x/\|v\|\) for a classical vector \(v\) with \(N\) entries, and then uses \(O(\log N)\) further gates. Explain why its total cost cannot be stated as \(O(\log N)\) without further assumptions.
Show solutionHide solution
Preparing the state from the classical list requires reading all \(N\) entries in general, and known generic preparation circuits use a number of gates growing with \(N\). Only if the vector has special structure, or a preparation routine is supplied as part of the input model, can preparation be cheap. The \(O(\log N)\) count describes the processing after loading, not the end-to-end algorithm.
1.3
Designing Interference
We have seen that one coherent query produces a state containing both function values, yet a direct measurement reveals only one. Something must happen between the query and the measurement. That something is interference: we arrange for contributions from the two inputs to meet in the same final amplitude, adding when they agree and cancelling when they differ. Designing that meeting, and removing anything that would stop it, is the core of the craft.
We want \(f(0)\) and \(f(1)\) to contribute to the same amplitude with signs that depend on the values. Signs combine the way we need: \((-1)^{f(0)}+(-1)^{f(1)}\) is \(\pm2\) when the values agree and \(0\) when they differ. So aim to put the function values into signs.
The target state \(\ket-=(\ket0-\ket1)/\sqrt2\) does this. Flipping it only changes its sign, \(X\ket-=-\ket-\). So when the oracle flips the target, the state picks up a factor \(-1\), and when it does not, nothing changes:
\[U_f\ket{x}\ket-=(-1)^{f(x)}\ket{x}\ket-.\]
The target ends in the same state \(\ket-\) for both inputs, and the function value has moved into a sign on the input. This is phase kickback; the resulting map \(\ket x\mapsto(-1)^{f(x)}\ket x\) is called a phase oracle. Now query with the input in \(\ket+\):
The two signs are relative phases between the input branches, which a Hadamard can turn into probabilities. Using \(H\ket0=(\ket0+\ket1)/\sqrt2\) and \(H\ket1=(\ket0-\ket1)/\sqrt2\), the input becomes
If the values agree, the amplitude of \(\ket1\) is zero and the amplitude of \(\ket0\) has magnitude one. If they differ, the reverse. Measuring the input therefore returns \(d\) with certainty.
Register order is input, then target. The Hadamards prepare \(\ket+\ket-\); the query kicks \((-1)^{f(x)}\) onto the input; the final Hadamard turns the relative sign into the bit \(d\). The target is not measured.
Starting from \(\ket0\ket1\), two Hadamards prepare \(\ket+\ket-\). Register order is input first, then target. The target is never measured. Notice what the design required: we first wrote down the quantity we wanted, \((-1)^{f(0)}\pm(-1)^{f(1)}\), and then chose the encoding and the final gate to produce it as an amplitude. That direction of reasoning, from desired amplitude back to circuit, is the habit this course tries to build.
Problems
Track the full two-qubit state through the circuit for \(f(x)=x\), at the three marked slices.
Show solutionHide solution
After the first Hadamards, \(\ket+\ket-\). After the query, \(\frac{1}{\sqrt2}(\ket0-\ket1)\ket-=\ket-\ket-\). After the final Hadamard on the input, \(\ket1\ket-\). The measurement returns \(1=d\).
Repeat for \(f\equiv1\). What is the final state, and why does its overall sign not matter?
Show solutionHide solution
The query multiplies both branches by \(-1\): \(-\ket+\ket-\). The final Hadamard gives \(-\ket0\ket-\). The factor \(-1\) is a global phase; every measurement probability is unchanged, and the outcome is \(0=d\).
Replace the final Hadamard on the input by the gate \(S=\mathrm{diag}(1,i)\) followed by a Hadamard. Compute the probability of outcome \(1\) for a balanced and a constant function. What design principle does the failure illustrate?
Show solutionHide solution
Before the final gates the input is \(\pm\frac{1}{\sqrt2}(\ket0\pm\ket1)\): plus for constant, minus for balanced. \(S\) turns these into \(\frac{1}{\sqrt2}(\ket0+i\ket1)\) and \(\frac{1}{\sqrt2}(\ket0-i\ket1)\). A Hadamard sends both to states with equal magnitudes on \(\ket0\) and \(\ket1\), so outcome \(1\) has probability \(1/2\) in both cases. The readout must map the two encoded states to distinct basis states; a phase gate that rotates them onto states the final measurement cannot separate destroys the answer.
Why not keep the simpler target \(\ket0\)? Let us see exactly what goes wrong, because the same failure will reappear inside every larger algorithm.
Figure guide. The figure compares phase kickback on target \(\ket-\) against a bit-oracle write into target \(\ket0\) for \(f(x)=x\). Follow the target register in the \(\ket0\) circuit through the final Hadamard gate on the input to see how the unreset target record suppresses interference.
What to observe
Measuring \(d=1\) on the input has probability \(1/2\). Because the target holds a record \(\ket{f(x)}\) of which input branch occurred, contributions ending with different target records belong to orthogonal subspaces and cannot cancel.
The query gives \((\ket{00}+\ket{11})/\sqrt2\). Applying \(H\) to the first qubit,
There is a minus sign, as in the successful circuit, but it sits on \(\ket{11}\), while the plus sign it would need to cancel sits on \(\ket{10}\). Those are different basis states of the pair. Amplitudes add only when they belong to the same complete configuration, so nothing cancels. Each input outcome has probability \(1/4+1/4=1/2\).
With target \(\ket0\) and \(f(x)=x\), the query makes the target a copy of the input. After the Hadamard, the minus sign sits on \(\ket{11}\) and cannot cancel the plus sign on \(\ket{10}\); the input outcome is a fair coin.
The target has become a which-path record: its value tells which input branch produced each term. Whenever two branches carry orthogonal records, they cannot interfere, and it makes no difference whether anyone looks at the record. Ignoring it does not erase it. The \(\ket-\) target avoided creating a distinguishing record in the first place: it ends in the same state on both branches, so the branches differ only by a sign on the input, and the sign can be made to cancel.
In larger algorithms some temporary record is unavoidable. Computing \(f\) from a formula usually leaves intermediate values in scratch qubits, and those values depend on \(x\). We will remove them by running the computation backwards after its answer has been used. For now, the design rule is simple to state: everything that distinguishes branches meant to interfere must be gone before they meet.
Problems
In the failed circuit with target \(\ket0\), compute the outcome probabilities on the input for the constant function \(f\equiv0\).
Show solutionHide solution
The query does nothing, leaving \(\ket+\ket0\). The Hadamard returns \(\ket0\ket0\), so the input reads \(0\) with certainty. Constant functions leave no record, since both branches get the same target value; the failure appears only for balanced functions, where it gives a fair coin.
After the query with target \(\ket0\), apply a second CNOT from the input to the target (a copy of the oracle for \(f(x)=x\)) before the final Hadamard. What does the input measurement give now for \(f(x)=x\)?
Show solutionHide solution
The second CNOT returns the state to \(\ket+\ket0\): it undoes the record. The Hadamard then gives \(\ket0\ket0\), outcome \(0\), even though \(d=1\). Erasing the record restores interference, but here it also erases the function information: the two queries cancel completely. Uncomputation must remove intermediate records while keeping the answer in a form that survives, which is what the \(\ket-\) target does by holding it in a phase.
A student argues: “The target is never measured in the failing circuit, so it cannot affect the input’s statistics.” Give a one-line counterexample from this subsection and state the correct principle.
Show solutionHide solution
For \(f(x)=x\), the unmeasured target changes the input’s probability of \(1\) from \(1\) (with \(\ket-\)) to \(1/2\) (with \(\ket0\)). The correct principle: an unmeasured system that is correlated with the branches still prevents those branches from interfering. What matters is whether the record exists, not whether it is read.
1.4
Constructing the Readout
The last step of an algorithm converts amplitudes into classical output. Choosing that step is part of the design, not an afterthought: the measurement must separate the states that encode different answers, and when it cannot do so perfectly, we must say how many repetitions buy how much confidence.
Look at the input register just before the final Hadamard. Constant functions leave it in \(\pm\ket+\) and balanced functions in \(\pm\ket-\). Measured directly in the computational basis, both give a fair coin. The answer is fully present, but this measurement is blind to it.
What makes the answer readable at all is that \(\ket+\) and \(\ket-\) are orthogonal: \(\braket{+}{-}=\frac12(1\cdot1+1\cdot(-1))=0\). Orthogonal states can be distinguished with certainty by measuring in a basis that contains them. The Hadamard is the change of basis that does this, since \(H\ket+=\ket0\) and \(H\ket-=\ket1\). Applying \(H\) and then measuring in the computational basis is the same as using \(\{\ket+,\ket-\}\) as the measurement basis.
The factor \((-1)^{f(0)}\) is a global phase and changes no probability. So the circuit separates the two classes of function but cannot tell the two members of each class apart. That loss is not a defect: we asked only for \(d\). It is also a warning. What if the states \(\ket a\) and \(\ket b\) encoding two answers were not orthogonal? If they were identical, every measurement would give them the same statistics, and the best we could do is guess, right half the time. Between orthogonal and identical, a quoted result of Helstrom (1969) gives the smallest error probability for two equally likely pure states:
It is \(0\) when the overlap is \(0\) and \(\tfrac12\) when the overlap is \(1\), matching the two extremes. So designing an algorithm includes making the answer states orthogonal, or nearly so.
Constant functions leave the input along \(\ket+\) and balanced functions along \(\ket-\), up to sign. These states are orthogonal, so a measurement in their basis separates them with certainty; the Hadamard rotates that basis onto \(\ket0,\ket1\).
Problems
Verify that \(H\) maps \(\ket+\) to \(\ket0\) and \(\ket-\) to \(\ket1\) by multiplying amplitude lists.
Show solutionHide solution
\(H\) has rows \(\frac{1}{\sqrt2}(1,1)\) and \(\frac{1}{\sqrt2}(1,-1)\). On \(\ket+=\frac{1}{\sqrt2}(1,1)\) it gives \((\frac12+\frac12,\frac12-\frac12)=(1,0)\). On \(\ket-=\frac{1}{\sqrt2}(1,-1)\) it gives \((0,1)\).
Suppose a faulty preparation makes the two answer states \(\ket{a}=\cos(\pi/8)\ket0+\sin(\pi/8)\ket1\) and \(\ket b=\cos(\pi/8)\ket0-\sin(\pi/8)\ket1\), equally likely. Compute their overlap and the best possible error probability.
Show solutionHide solution
\(\braket ab=\cos^2(\pi/8)-\sin^2(\pi/8)=\cos(\pi/4)=1/\sqrt2\). The best error is \(\frac12(1-\sqrt{1-1/2})=\frac12(1-1/\sqrt2)\approx0.146\). No choice of measurement can do better.
Is it possible to modify the Deutsch circuit so that one run reports \(d\) and \(f(0)\)? Use the output state to argue.
Show solutionHide solution
No. Within each class the final states differ only by the global phase \((-1)^{f(0)}\), so they are physically identical and no measurement can distinguish them. More generally, one run that ends in one measured bit cannot yield two bits of information. Any circuit using one query that reports \(f(0)\) correctly with certainty would contradict that argument.
1.4.2 Success probability, precision, and repetition§
Deutsch’s circuit is exact. Most algorithms are not: they output a correct answer with some probability less than one, or an estimate with some error. The readout procedure must then say how runs are combined and what the combination guarantees.
Boosting a decision. Suppose a decision algorithm is correct with probability at least \(3/4\) on every input. Run it three times independently and take a majority vote. The majority is right if at least two runs are right:
What do more runs buy? With single-run success \(3/4\), fifteen runs give a correct majority with probability about \(0.983\), and thirty-one runs about \(0.9987\). In general, write the single-run success as \(\tfrac12+\gamma\). A quoted result, the Chernoff–Hoeffding bound, says that the majority of \(R\) independent runs is wrong with probability at most \(e^{-2\gamma^2R}\). The failure probability falls exponentially in \(R\) as long as \(\gamma>0\). At \(\gamma=0\) every run is a coin flip, and voting cannot help.
Probability that the majority of \(R\) independent runs is correct, when each run is correct with probability \(p\). Above \(p=1/2\) the curves steepen as \(R\) grows; at \(p=1/2\) voting cannot help.
Searching with a checker. If a run finds a valid answer with probability \(p\) and validity can be checked, then \(R\) independent runs all fail with probability \((1-p)^R\le e^{-pR}\). About \(\ln(1/\delta)/p\) runs bring the failure below \(\delta\). The checker is essential; without it we would not know which run to believe.
Estimating a probability. Suppose a measured bit is \(1\) with unknown probability \(p\), and we average \(R\) independent results. The average has mean \(p\) and variance \(p(1-p)/R\le1/(4R)\); variance is the expected squared deviation from the mean. Whenever the average misses \(p\) by more than \(\epsilon\), its squared deviation exceeds \(\epsilon^2\). Since the mean squared deviation is at most \(1/(4R)\), the probability of such a miss is at most
This is Chebyshev’s inequality. It shows that precision \(\epsilon\) costs on the order of \(1/\epsilon^2\) repetitions. Halving the error quadruples the work. Amplitude estimation, built later from amplitude amplification, reduces this to order \(1/\epsilon\), at the price of longer circuits and stronger access assumptions. Repetition counts belong in every resource statement.
One more requirement hides in the word “independent.” Repetitions must use fresh preparations. Re-measuring the same post-measurement state returns the same outcome and adds no information.
Problems
A decision algorithm is correct with probability \(2/3\). What is the success probability of a majority vote over three runs?
Show solutionHide solution
\((2/3)^3+3(2/3)^2(1/3)=8/27+12/27=20/27\approx0.74\). The improvement from \(0.67\) is modest; more runs are needed for high confidence.
Using the Chebyshev bound, how many runs guarantee \(|\bar p-p|\le0.01\) with failure probability at most \(0.05\)? Compare with \(\epsilon=0.001\).
Show solutionHide solution
We need \(1/(4R\epsilon^2)\le0.05\), so \(R\ge5/\epsilon^2\). For \(\epsilon=0.01\), \(R=50{,}000\); for \(\epsilon=0.001\), \(R=5{,}000{,}000\). Ten times the precision costs a hundred times the runs. (Sharper bounds reduce the constant but not the \(1/\epsilon^2\) scaling.)
A decision algorithm is correct with probability exactly \(1/2\) on some inputs. Explain why majority voting cannot help on those inputs, and why “correct with probability at least \(1/2+c\)” for a fixed \(c>0\) is the standard requirement.
Show solutionHide solution
If each run is right with probability exactly \(1/2\), the number of correct runs is symmetric about \(R/2\), so the majority is right with probability at most \(1/2\) for every \(R\): the runs carry no information about the answer. With a fixed advantage \(c\), the expected number of correct runs exceeds \(R/2\) by \(cR\), and the probability of the majority being wrong decays exponentially in \(c^2R\). Then any target confidence costs only a constant factor in repetitions, independent of input size.
1.5
Establishing an Advantage
We now have a correct circuit using one query where any classical method needs two. Is that a quantum advantage? It is a precise statement about one access model and one problem size. To claim more, we must prove correctness for a whole family of inputs that grows, compare against the best classical method under the same rules, and count every resource, not just the convenient one.
Substituting the four rows of the table into the output formula gives the final states \(\ket0\ket-\), \(\ket1\ket-\), \(-\ket1\ket-\), and \(-\ket0\ket-\). That checks every allowed input. It is also more than a check: the formula \(\frac12\big((-1)^{f(0)}\pm(-1)^{f(1)}\big)\) explains why the answer comes out, which is what lets us generalize.
And there is nothing to scale yet. Deutsch’s problem has one size. A query count of one versus two is a constant-factor statement about a fixed problem. It cannot be extrapolated to say anything about how costs grow. To claim that one method scales better than another we need a family of problems indexed by a size \(n\), a proof of correctness for every allowed input of every size, and expressions for how each resource grows with \(n\) and with the requested accuracy.
Here is the first such family; we develop it fully when we study phase encoding. Let \(f:\{0,1\}^n\to\{0,1\}\) be promised to be either constant or balanced (a balanced function takes the value \(1\) on exactly half its inputs). Run the same design on \(n\) input qubits: Hadamards on all of them, one phase query, Hadamards again. The amplitude of the all-zero outcome is
\[\frac{1}{2^n}\sum_{x\in\{0,1\}^n}(-1)^{f(x)},\]
which is \(\pm1\) for a constant function and \(0\) for a balanced one. One query decides the promise problem exactly for every \(n\). That is a statement about a family, and its proof is a single line valid for all \(n\). It is the Deutsch–Jozsa algorithm.
The slash marks an \(n\)-qubit register; each \(H\) box is \(n\) Hadamards. The zero outcome has amplitude \(2^{-n}\sum_x(-1)^{f(x)}\): magnitude one for a constant function and zero for a balanced one.
Generalizing correctly also means keeping the assumptions in view. For \(n=1\) the promise was automatic; for \(n\ge2\) it is not. A function with three ones among eight inputs gives zero-outcome amplitude \((5-3)/8=1/4\), so the circuit outputs “constant” with probability \(1/16\) and something else otherwise. On such inputs the output means nothing, and the problem statement must say so.
Problems
For \(n=2\) and the balanced function \(f(x_1x_2)=x_1\), compute the zero-outcome amplitude directly from the sum.
Show solutionHide solution
The values on \(00,01,10,11\) are \(0,0,1,1\), giving signs \(+,+,-,-\). The sum is \(0\), so the amplitude of \(00\) is \(0\) and the circuit never reports “constant”.
For a constant function on \(n\) bits, show that the final state is \(\pm\ket{0^n}\ket-\), using \(H^{\otimes n}\ket{0^n}=2^{-n/2}\sum_x\ket x\) and the fact that \(H^{\otimes n}\) is its own inverse.
Show solutionHide solution
The first Hadamards give \(2^{-n/2}\sum_x\ket x\). A constant phase query multiplies every term by the same \((-1)^c\). The second Hadamards invert the first, returning \((-1)^c\ket{0^n}\). The target stays \(\ket-\) throughout.
A paper reports that its quantum circuit solved a 3-qubit instance of a problem using 5 gates where a classical program used 12 operations, and concludes that the method is “exponentially faster.” List what is missing from this argument.
Show solutionHide solution
A single instance size gives no growth rate. Missing are: a family of instances indexed by size; a correctness proof for all of them; resource counts as functions of size and accuracy, including state preparation, oracle construction, repetitions, and readout; and a comparison with the best known classical method for the same task and success criterion, not merely one classical program. “Exponentially” is a claim about asymptotics that one data point cannot support.
1.5.2 Classical baselines and complete resource costs§
A speedup is a comparison against a classical baseline: the best known classical method for the same task, under the same access and success criterion. Both sides must play the same game. For Deutsch’s problem the game is query complexity: count only uses of the function, under exact success. Classically two queries are necessary; quantumly one suffices. Could a randomized classical algorithm do better with one query if it is allowed to err?
No better than guessing. Pick the four functions uniformly at random and fix the algorithm’s internal coin flips. Whichever input it queries, the other value is a fresh fair bit, independent of what it saw. So \(d\) is a fair bit given everything the algorithm knows, and any output rule is right with probability exactly \(1/2\) on average. Averaging over the algorithm’s coins preserves this, so on at least one of the four functions the success probability is at most \(1/2\). Random guessing already achieves \(1/2\) on every input. The quantum circuit gives certainty.
That is the query comparison. Complete resource accounting lists more. For the circuit as drawn, with ideal oracle access:
Ideal oracle access is assumed. A concrete implementation must add the cost of building the oracle, which the query count deliberately excludes.
The table separates resources that are often blurred. A query count is not a runtime. A runtime comparison would include building the oracle on both sides, the gates, the measurement, and any classical processing, all under the same allowed error. For Deutsch’s problem in particular, if \(f\) is given as a small classical circuit, evaluating it twice classically is cheap and the quantum version saves essentially nothing. The value of the example lies elsewhere: it isolates the mechanism of phase kickback plus interference, which becomes powerful when the same mechanism acts on exponentially many inputs at once.
Problems
In the Deutsch–Jozsa setting with \(n\)-bit inputs and exact success, show that a deterministic classical algorithm may need \(2^{n-1}+1\) queries.
Show solutionHide solution
An adversary answers \(0\) to the first \(2^{n-1}\) distinct queries. After those, both a constant-zero function and a balanced function (with ones on every unqueried input) are consistent. The algorithm cannot answer with certainty until one more query distinguishes them, so \(2^{n-1}+1\) queries are needed in the worst case, and that many always suffice.
Now allow error. A randomized classical algorithm queries \(k\) uniformly random inputs and reports “constant” if all answers agree. Bound its error probability on a balanced function and compare its cost to the exact case.
Show solutionHide solution
On a balanced function each query, if drawn independently and uniformly, gives each value with probability \(1/2\). All \(k\) answers agree with probability \(2\cdot2^{-k}=2^{1-k}\). With \(k=11\) the error is below \(10^{-3}\), independent of \(n\). The exponential gap with exact algorithms collapses to a constant once bounded error is allowed. A claimed separation must state which success criterion it uses.
A colleague implements the Deutsch–Jozsa oracle for a specific \(f\) given as a classical circuit with \(g\) gates, and reports “one query versus \(2^{n-1}+1\).” What should the end-to-end gate count include, and does the exponential gap survive against a bounded-error classical method?
Show solutionHide solution
The quantum count includes the reversible oracle (on the order of \(g\) gates plus cleanup, by compute–copy–uncompute), \(2n\) Hadamards, and \(n\) measurements: about \(O(g+n)\). The bounded-error classical method evaluates \(f\) on a constant number of random inputs, costing \(O(g)\). Against that baseline there is no exponential gap at all. The exponential separation is real only for exact, worst-case query complexity in the black-box model.
1.6
Combining Techniques
We have now made every design decision once, for one small problem. Do the same decisions apply, in the same order, to problems we have not met? To find out, we first lay the decisions of the case study side by side and see which one carried the algorithm. Then we ask how a new algorithm can be assembled from techniques, each of which answers one of those decisions.
Which of our decisions did the real work, and which were bookkeeping? Written in order, the decisions form a design process, and we can apply it to any proposed quantum algorithm. Each row of the table is one decision, posed as a question.
Each row is a design question that applies to every algorithm in the course. The answers for Deutsch’s problem are developed in the sections before this one.
The decisive step was the encoding. We needed the parity of two values, so we encoded those values as signs and made the signed amplitudes meet in one output amplitude. The \(\ket-\) target made the oracle change a relative phase without leaving a record, and the final Hadamard converted that phase relation into a classical bit. Everything else was bookkeeping, but bookkeeping that would have hidden a mistake if skipped.
Replace the oracle target \(\ket-\) by \(\ket+\), keeping everything else. Predict the output for every function.
Show solutionHide solution
Since \(X\ket+=\ket+\), the oracle leaves \(\ket+\ket+\) unchanged for every \(f\). The final Hadamard sends the input to \(\ket0\), so the circuit always reports \(0\). It is right for constant functions and wrong for balanced ones. Coherent access alone is not enough; the target must respond to the oracle in the useful way.
Apply the checklist to this task: given coherent access \(U_f\) to \(f:\{0,1\}\to\{0,1\}\), output \(f(0)\). What does the checklist suggest, and how many queries are needed?
Show solutionHide solution
The required output is a single function value; no interference is needed. Query \(U_f\ket0\ket0=\ket0\ket{f(0)}\) and measure the target: one query, no superposition. The checklist prevents overengineering: superposition and interference help only when the desired property is a relation among many values.
The checklist says to “prove correctness for the family.” For Deutsch’s problem we checked four rows. Why is the formula-based argument still preferable, even though exhaustive checking is complete here?
Show solutionHide solution
The formula shows which feature of the construction produces the result: signs adding or cancelling. That explanation transfers to the \(n\)-bit case, where exhaustive checking of \(2^{2^n}\) functions is impossible, and it reveals exactly which assumptions (the promise, the \(\ket-\) target, the Hadamard readout) the result depends on. A table of four tests proves the small case but teaches nothing about the next one.
1.6.2 From reusable constructions to new algorithms§
technique · composition
For a new problem, the same questions apply in the same order. What must be learned, and what does the input representation allow? Which encoding makes amplitudes or phases depend on that property? Which branches must interfere, and what records would stop them? What measurement would reveal the answer, and how often must it be repeated? How do all costs grow with size and accuracy, and what is the best classical method for the same task?
The rest of the course supplies tools for answering these questions, organized by technique rather than by famous algorithm. Named algorithms appear as applications or combinations.
Named algorithms are applications or compositions of techniques. Later chapters reuse the analysis of earlier ones rather than repeating it.
The techniques overlap and build on one another. Phase estimation is controlled powers plus phase kickback plus an inverse Fourier transform. Amplitude estimation is amplification plus phase estimation. Later, a matrix stored inside a larger unitary will be turned into a set of rotations, so that the reflections of a walk act on that matrix. When a chapter uses an earlier technique, it says so and reuses the earlier analysis instead of repeating it.
Our next obstacle is already visible. Realistic function evaluation needs scratch space, and scratch space that remembers the input is exactly the kind of which-path record that destroyed interference when we used the target \(\ket0\). So we next build function evaluations that leave precisely the intended output and restore their temporary storage.
Problems
From the table, which techniques does standard phase estimation combine? Which does amplitude estimation add?
Show solutionHide solution
Phase estimation combines controlled powers of a unitary, phase kickback onto control qubits, and the inverse quantum Fourier transform. Amplitude estimation applies phase estimation to the amplification iterate, so it adds reflections about a prepared state and a marked subspace.
Sketch, at the level of the checklist, a design for this task: given coherent access to \(f:\{0,1\}^2\to\{0,1\}\), decide the parity \(f(00)\oplus f(01)\oplus f(10)\oplus f(11)\). (You need not find the optimal query count.)
Show solutionHide solution
The required output is a parity of four values. One option: use the one-bit Deutsch circuit twice, once on the restriction \(x_1=0\) and once on \(x_1=1\) (fix the first bit, superpose the second), obtaining \(f(00)\oplus f(01)\) and \(f(10)\oplus f(11)\) with one query each, then XOR classically. Two queries, exact. Classically four are needed. (In fact two quantum queries are also necessary for parity of four bits, a known lower bound.)
Explain in two sentences why “quantum parallelism” alone—evaluating \(f\) on a superposition of all inputs—is not a technique in the sense of this course.
Show solutionHide solution
Evaluating on a superposition creates a state containing all values, but a measurement then returns only one of them, as we saw for the one-query superposition of Deutsch’s problem. A technique must say how the values are made to interfere so that a desired global property becomes a likely measurement outcome; parallel evaluation is merely the starting point of that work.
Summary
Every quantum algorithm begins with a precise specification of the computational problem, the input access model, the target output, and the allowed failure probability \(\varepsilon\).
Superposition alone does not solve problems; quantum advantage comes from steering amplitudes through unitary transformations so wrong branches cancel by destructive interference while target branches reinforce.
Honest resource accounting tracks oracle queries, two-qubit gate count, circuit depth, ancilla workspace, and classical pre- or post-processing separately.
Questions and worked problems
Attempt each question before opening a hint. Explain your reasoning, then compare it with the solution.
A one-bit oracle is used with target \(\ket0\) and input \(\ket+\), followed by a Hadamard on the input. For which of the four functions does the input measurement give the correct \(d\) with certainty?
Hint 1
Constant functions leave no record in the target.
Hint 2
For balanced functions, compute the state after the Hadamard.
Worked solution
For the two constant functions the target is the same on both branches, the input returns to \(\ket0\), and the output 0 is correct with certainty. For the two balanced functions the target records the input, and the outcome is a fair coin. So only the constant functions are handled correctly.
Run the Deutsch circuit (input \(\ket0\), target \(\ket1\), Hadamards on both, one query, Hadamard on the input) for \(f(x)=1\oplus x\). Write the two-qubit state after the query and after the final Hadamard. Which outcome is measured, and what does the overall sign mean?
Hint 1
Use \(U_f\ket x\ket-=(-1)^{f(x)}\ket x\ket-\) with \(f(0)=1\), \(f(1)=0\).
Hint 2
\((-\ket0+\ket1)/\sqrt2=-\ket-\).
Worked solution
After the Hadamards the state is \(\ket+\ket-\). The query multiplies the \(\ket0\) branch by \((-1)^{1}=-1\) and leaves the \(\ket1\) branch alone, giving \(\frac{-\ket0+\ket1}{\sqrt2}\ket-=-\ket-\ket-\). The final Hadamard maps \(\ket-\) to \(\ket1\), so the state is \(-\ket1\ket-\) and the input reads \(1=d\) with certainty, as it should for a balanced function. The factor \(-1=(-1)^{f(0)}\) multiplies the whole state: it is a global phase and changes no probability, which is why the circuit cannot tell \(f(x)=1\oplus x\) from \(f(x)=x\).
You are handed a sealed box that applies \(U_f\ket x\ket y=\ket x\ket{y\oplus f(x)}\) and nothing else. For each operation, say whether it comes free with the box, can be built from it, or is a separate assumption: (a) applying \(U_f\) to a superposition of inputs; (b) \(U_f^{-1}\); (c) controlled-\(U_f\); (d) a second copy of the state \(U_f\ket+\ket0\) produced by an earlier query.
Hint 1
Applying \(U_f\) twice restores every basis state.
Hint 2
For (c), try computing \(f(x)\) into a fresh qubit, using it, and computing it again.
Worked solution
(a) Free: coherent access is exactly the assumption that one use acts linearly on superpositions. (b) Free for this oracle, because \(U_f^2=I\), so \(U_f^{-1}=U_f\); for a general sealed unitary the inverse would be a separate assumption. (c) Buildable at a price: compute \(f(x)\) into a fresh qubit \(\ket0\) with one query, apply a Toffoli gate controlled on the control qubit and that fresh qubit with the real target as its target, then query again to return the fresh qubit to \(\ket0\). The cost is two queries and one extra qubit; it works because this oracle has no troublesome global phase. (d) Not available: no procedure copies an unknown state, so a second copy needs a second preparation and a second query.
For the Deutsch–Jozsa circuit with n = 3, a function has f(x) = 1 on exactly two of the eight inputs. Compute the probability that the circuit outputs the all-zero string. What should an algorithm relying on the promise do with this input?
Hint 1
The zero amplitude is \(2^{-n}\sum_x(-1)^{f(x)}\).
Hint 2
Six inputs contribute +1 and two contribute −1.
Worked solution
The amplitude is (6 − 2)/8 = 1/2, so the all-zero outcome has probability 1/4. The function is neither constant nor balanced, so it lies outside the promise; the specification requires nothing on it, and the circuit's output carries no guaranteed meaning.
For the two-bit Deutsch–Jozsa circuit, take the balanced function \(f(x_1x_2)=x_1\oplus x_2\). Compute the amplitude of every outcome \(z=z_1z_2\), using the fact that the final amplitude is \(\frac14\sum_x(-1)^{f(x)+x\cdot z}\), where \(x\cdot z=x_1z_1\oplus x_2z_2\). Repeat for \(f(x)=1\oplus x_1\). What pattern do you see?
Hint 1
Write \(f(x)=x\cdot a\) for a fixed string \(a\).
Hint 2
The sum is \(4\) when every term is \(+1\) and \(0\) when half the terms are \(-1\).
Worked solution
For \(f(x)=x_1\oplus x_2=x\cdot 11\), the exponent is \(x\cdot(11\oplus z)\). When \(z=11\) every term is \(+1\) and the amplitude is \(1\); for any other \(z\) the string \(11\oplus z\) is nonzero, exactly half the four inputs give \(-1\), and the amplitude is \(0\). The circuit outputs \(11\) with certainty. For \(f(x)=1\oplus x_1\), the exponent is \(1+x\cdot(10\oplus z)\), so the outcome \(10\) has amplitude \(-1\) and all others \(0\). Both functions are balanced and both give a nonzero string, as the promise problem requires. But more is true: whenever \(f(x)=a\cdot x\) (possibly complemented), the circuit returns \(a\) itself. That observation is the Bernstein–Vazirani algorithm developed in the Phase Encoding chapter.
A decision algorithm is correct with probability \(3/4\) per run. Compute the exact success probability of a majority vote over five independent runs and compare it with the three-run value \(27/32\). Then a search procedure finds a checkable witness with probability \(0.1\) per run: how many runs bring the failure probability below \(10^{-6}\)?
Hint 1
The majority of five is correct when at least three runs are correct.
Hint 2
Use \((1-p)^R\le e^{-pR}\).
Worked solution
With \(q=3/4\), \(\Pr[\ge3\text{ correct}]=\binom53q^3(1-q)^2+\binom54q^4(1-q)+q^5=\frac{270+405+243}{1024}=\frac{918}{1024}=\frac{459}{512}\approx0.896\). Three runs gave \(27/32\approx0.844\); two more runs cut the failure probability from about \(0.156\) to about \(0.104\), and further runs keep shrinking it exponentially. For the search, \(e^{-0.1R}\le10^{-6}\) requires \(R\ge10\ln10^6\approx138.2\), so \(139\) runs suffice (the exact bound \((0.9)^R\le10^{-6}\) gives \(132\)). Each run is checked with one extra evaluation of \(f\), which belongs in the total cost.
Each run of an estimation circuit uses one query and \(40\) other gates and outputs a bit that is \(1\) with unknown probability \(p\). Using the Chebyshev bound, how many runs guarantee \(|\bar p-p|\le0.02\) with failure probability at most \(0.1\)? Give the total query and gate counts, and say what happens to both if the tolerance is halved.
Hint 1
Require \(1/(4R\epsilon^2)\le\delta\).
Hint 2
Every repetition repeats the whole circuit, including its preparation.
Worked solution
We need \(R\ge1/(4\delta\epsilon^2)=1/(4\times0.1\times0.0004)=6250\) runs. Each run is a fresh preparation, so the cost is \(6250\) queries and \(6250\times40=250\,000\) further gates, plus classical averaging. Halving the tolerance to \(0.01\) multiplies \(R\) by four: \(25\,000\) queries and one million gates. The resource statement must therefore say which tolerance and confidence were assumed; quoting the cost of one circuit hides a factor that grows as \(1/\epsilon^2\). (Chebyshev is loose: sharper bounds lower the constant, but not the \(1/\epsilon^2\) dependence.)
After one query with target \(\ket-\), a student discards the target qubit, reasoning that it may still hold information about \(f\). Another student wants to reuse it for a second query on a fresh input register. Who is right? Compare with the target \(\ket0\).
Hint 1
Write the joint state after \(U_f\ket\psi\ket-\) as a product.
Hint 2
With target \(\ket0\), is the joint state a product?
Worked solution
The second student. Since \(U_f\big(\sum_x a_x\ket x\big)\ket-=\big(\sum_x(-1)^{f(x)}a_x\ket x\big)\otimes\ket-\), the target leaves the query in exactly the state it entered, unentangled with the input. It holds no record of \(f\) or of the input branch, so it can be reused for any number of later queries; throwing it away is harmless but wasteful. With target \(\ket0\) the state after the query is \(\sum_xa_x\ket x\ket{f(x)}\), which is generally entangled: the target is a which-path record. Reusing it would carry that record into the next computation, and discarding it does not undo the damage, because the branches it distinguishes can no longer interfere.
A bounded-error quantum algorithm for a decision problem succeeds with probability 0.6 per run. How many runs make the majority vote fail with probability at most 0.01, using the bound that the majority of R runs fails with probability at most \(e^{-2Rc^2}\), where c = 0.1 is the advantage over 1/2? What does this imply about the definition of bounded error?
Hint 1
Solve \(e^{-2R(0.01)}\le0.01\).
Hint 2
The number of runs does not depend on input size.
Worked solution
We need 0.02R ≥ ln 100 ≈ 4.61, so R = 231 runs suffice by this bound. The count depends only on the advantage and the target confidence, not on the input size. That is why any fixed advantage above 1/2 (often stated as success 2/3) defines the same class of efficiently solvable problems: amplifying to any constant confidence costs only a constant factor.
Deutsch’s original approach used the target \(\ket0\). After the query on \(\ket+\ket0\), apply a Hadamard to both qubits and measure both. Compute the probability of each outcome pair \((a,b)\). Show that when \(b=1\) the input outcome \(a\) equals \(d\) with certainty, while \(b=0\) carries no information. What is the overall success probability, and why is this weaker than the one-query circuit with target \(\ket-\)?
Hint 1
The amplitude of \((a,b)\) is \(\frac{1}{2\sqrt2}\sum_x(-1)^{xa+f(x)b}\).
Hint 2
Treat \(b=0\) and \(b=1\) separately.
Worked solution
Starting from \(\frac{1}{\sqrt2}\sum_x\ket x\ket{f(x)}\), the Hadamards give amplitude \(\frac{1}{2\sqrt2}\big[(-1)^{f(0)b}+(-1)^{a+f(1)b}\big]\) for \((a,b)\). If \(b=0\) this is \(\frac{1}{2\sqrt2}(1+(-1)^a)\): outcome \(a=0\) with probability \(1/2\) whatever \(f\) is, so nothing is learned. If \(b=1\) it is nonzero only when \(a=f(0)\oplus f(1)=d\), with probability \(1/2\). So half the time the procedure reports \(d\) with certainty and flags that it has done so; the other half it must report “don’t know” and query again. The expected number of queries is \(2\), no better than classical. The \(\ket-\) target removes the useless \(b=0\) branch by preparing the target in the state that the \(b=1\) measurement selected, which is why it succeeds every time.
Where this leads. the Coherent Computation chapter builds clean coherent subroutines: function evaluations that leave the answer and restore their scratch space, so that temporary records do not block interference.