← The Lab
The Veiled Box · Lab · 9 of 9 · from pages 70 and 71

How wrong answers cancel. Grover's search

Four boxes, one hidden cat and a single look. How a quantum computer finds the cat by making the wrong answers cancel.

Choose your level. Each one adds to the one before.
From the book: four closed wooden boxes numbered 1 to 4 on a table, in plain ink against misty hills. Lettering: Deep dive. How wrong answers cancel. Four boxes. One holds the cat. A classical search may have to open three.
1 of 7

The ordinary way

Four closed boxes, and a cat hidden in one of them. An ordinary search, the kind any normal computer does, opens one box at a time. With luck, the first box holds the cat. If not, you keep going. After three empty boxes you know the cat is in the last one without opening it, so three looks is the worst case. Find the cat, then let the machine play a thousand games.

Pick a box
The cat is hidden in one of the four. Each look opens one box.

How many looks each game took games playedworked out exactly

Play a few games, or let the machine play a thousand. The dashed outlines show the shares worked out exactly. Notice where the average settles.

Going further

On average it takes a little over two looks: 2.25 if you stop when one box is left, or 2.5 if you insist on opening the last box to see the cat. Either way an ordinary search needs about half as many looks as there are boxes. With a million boxes that is about half a million looks, and an unlucky search needs 999,999. No cleverness helps: the boxes give no clue, so each look rules out just one box.

The maths

For N boxes, opened in any order, stopping when one box is left:

average looks = (N − 1)(N + 2) / 2N, worst case = N − 1

For N = 4 that gives 2.25 and 3. Opening the last box too gives (N + 1) / 2 = 2.5 on average, and at worst N = 4.

2 of 7

Spread the waves

A quantum search starts differently. Its qubits are put into a both-ways wave, a superposition, spread evenly over all four boxes at once, like the electron's wave over both slits. Every box gets the same ripple height, its amplitude: one half. A look, reading the qubits, picks just one box. The chance it picks a box is that box's height squared, and one half times one half is one quarter. So each box has one chance in four, no better than a blind guess. Spread the waves, then look.

Ripple height of each box can point up or down

Chance a look shows each box height squared

Notice that after the spread, 100 looks land on all four boxes about equally. The waves alone find nothing yet.

Going further

Two qubits are enough to name four boxes: 00, 01, 10 and 11. Putting each qubit into an even both-ways wave gives every name the same ripple height. Ten qubits name 1,024 boxes, and twenty name more than a million. This is not yet useful. A look at this wave shows one box at random, no better than a blind guess. The real work is still to come.

The maths

One qubit in an even both-ways wave has height 1/√2 for 0 and for 1. For two qubits the heights multiply:

½ (|00⟩ + |01⟩ + |10⟩ + |11⟩), (1/√2)(1/√2) = ½

Each chance is (½)² = ¼, and the four chances add to 1. The animation turns each qubit smoothly from 0 to its even wave, so the chances add to 1 at every moment.

3 of 7

Mark the right box

From the book: four boxes under a thin line. Gold bars stand on the line over boxes 1, 2 and 4. The bar over box 3 hangs below the line, upside down. Lettering: Step 2. A check that can recognise the cat, but not find it, turns the right box's ripple upside down. Chance is height squared, so each box is still one in four.

Next comes a quantum check, called the oracle, an old word for someone who knows the answer. It works like a lock that knows its key: it recognises the right box, though nobody has told us which box that is. It opens nothing. It turns the right box's ripple upside down, and that is all. Look now and you learn nothing. An upside-down height squared gives the same chance as an upright one, so every box is still one in four. The mark is hidden. Hide the cat, mark it, then look.

Ripple height of each box

Chance a look shows each box

Notice that the ripple over the cat's box flips, yet the chances on the right do not move at all.

Going further

The check is a small circuit built to recognise the answer, and it acts on the whole both-ways wave at once. Drawn as one of Feynman's arrows from explainer 5, the mark is a half turn: the length, and so the chance, never changes, only the direction. That is how the animation shows it. Ordinary chances cannot be negative, so no ordinary machine can hide information like this. Here you choose where the cat hides. In a real search nobody knows, and only the check can tell.

The maths

The oracle multiplies the right box's height by −1 and leaves the others alone:

O|x⟩ = −|x⟩ for the right box, O|x⟩ = |x⟩ otherwise

(−½)² = (½)² = ¼, so no single look can see the mark.

4 of 7

Mirror around the average

From the book: a chart of four gold bars of equal length, three up and one down, with a dashed line at the average height. Lettering: Step 3. Flip every wave around the average height, as if in a mirror.
From the book: the same chart after the mirror. Three bars have shrunk to nothing and the third stands twice as tall as before. Lettering: The three wrong ripples land at zero. The right one lands at twice its old height. Twice the height, four times the chance: one in four becomes certain.

Now the clever step. Find the average height of the four ripples. Three point up and one points down, so the average is low: one quarter. Then flip every ripple to the other side of that line, as if in a mirror. An upright ripple, a quarter above the line, lands a quarter below it: at zero. The upside-down one starts three quarters below the line and lands three quarters above it: at full height. The wrong boxes' ripples cancel to nothing, so a look can never pick them. Mark, mirror, look.

Ripple height of each box the average height

Chance a look shows each box

Chance of the cat: 25%

Notice that it is the ripple heights that cancel, not the chances: three heights land on zero, and only then are they squared. Mark and mirror a second time to see a round too many.

Going further

Like the mark, the mirror acts on all four ripples at once, and it needs no idea where the cat is. With exactly four boxes, one round of marking and mirroring gives certainty. Mark and mirror a second time and the cat's chance drops back to one in four: too many rounds overshoot. Lov Grover published the method in 1996, while working at Bell Labs.

The maths

Mirroring turns every height a into 2ā − a, where ā is the average height:

ā = (½ + ½ − ½ + ½) / 4 = ¼
2ā − ½ = 0, 2ā − (−½) = 1

As one operation on the whole wave the mirror is D = 2|s⟩⟨s| − I, where |s⟩ is the even spread of section 2.

5 of 7

Bigger searches

With more boxes, one round is not enough. Each round of marking and mirroring moves a little more height onto the right box, so you repeat it. The rounds needed grow only like the square root of the number of boxes. A million is a thousand times a thousand, so its square root is a thousand, and a little under that, about 785 rounds, does it. The ordinary way needs half a million looks. But stop in time. Extra rounds make the right box fade again. Change the boxes, then the rounds.

4a million
01,963
Best: 785 rounds

Chance that one look finds the cat quantum search, after each roundordinary search, after as many looks

Going further

In 1997 Charles Bennett, Ethan Bernstein, Gilles Brassard and Umesh Vazirani proved that no quantum method can search unsorted boxes with fewer than about the square root of the number of boxes in checks. Grover's search reaches that limit, so it is the best possible. The gain is called a quadratic, or square-root, speed-up. It is real, but it is not the vast exponential leap that headlines often promise. For a million boxes it means several hundred times fewer checks.

The maths

Call θ the angle with sin θ = 1/√N. After k rounds the chance of the right box is:

P(k) = sin²((2k + 1)θ), θ = arcsin(1/√N)
k_best ≈ π/(4θ) − ½ ≈ (π/4)√N

For N = 1,000,000: θ ≈ 0.001 radians, k_best = 785 and P ≈ 0.99999996. For N = 4: θ = 30°, and one round gives sin²(90°) = 1.

6 of 7

A record spoils the cancelling

Cancelling only works while the ripples can meet. Explainer 7 showed what stops that: a record. If a stray bit of air, light or heat bumps the machine and keeps a trace of which box its wave is over, that box can no longer cancel with the others. It is like a secret told to a thousand people: it can never be un-told. With a complete record, the search is back to a blind guess. Slide how much leaks out.

Chance a look shows each box, after one round

Chance of the cat: 100%
nonecomplete

Notice that the more of the secret leaks out, the more chance flows back to the wrong boxes, until the search is no better than a blind guess.

Going further

This leaking is called decoherence, and it is the main enemy of every quantum computer. Many machines are cooled close to absolute zero, the coldest possible temperature, and shielded from stray light and magnetism. Even so, their waves last only a limited time. A search over a million boxes needs hundreds of rounds in a row, so the waves must survive all of them. Machines that catch and fix their own errors are a large part of the work today.

The maths

A record multiplies every cross term between two boxes by c, from 1 (no record) to 0 (a complete one). After one round with four boxes:

P(right) = ¼ + ¾c, P(each wrong box) = (1 − c) / 4
7 of 7

Not everything at once

From the book: four wooden boxes on a desk. Box 3 stands open and a tabby cat looks out. Lettering: One look. The cat, every time. Grover's search, 1996. For a million boxes it needs under a thousand steps, not half a million. This is the real trick of a quantum computer: not trying everything at once, but making wrong answers cancel.

A popular story says a quantum computer tries every answer at once and reads them all. It cannot: a look only ever shows one box. The real trick is quieter. It arranges the ripples so that the wrong answers cancel and the right one grows, and only then takes a single look. One look. The cat, every time.

Going further

Grover's search weakens some secret codes without breaking them. Guessing a secret key would take about the square root of the usual effort, which roughly halves the key's effective length, so longer keys are the defence. The method shows the honest scale of quantum speed-ups: real, specific and often modest. Some other quantum methods, such as Peter Shor's of 1994 for finding the factors of large numbers, promise far bigger gains, but only for special problems with hidden patterns.

Words to keep

Amplitude
The ripple height of a possibility. It can point up or down, and its square is the chance.
Oracle
The marking step. A check that recognises the right answer and turns its ripple upside down, like a lock that knows its key.
Mirror step
Flipping every ripple height to the other side of the average height. The wrong answers cancel and the right one grows.
Quadratic speed-up
Needing only about the square root of the usual number of tries. Under a thousand rounds for a million boxes, instead of half a million looks.
The Veiled Box Lab · one explainer per idea, each building on the last
  1. p. 6Planck's kiln
  2. p. 7Light in lumps, atoms in steps
  3. p. 11Two slits
  4. p. 12One electron at a time
  5. p. 16When possibilities cancel
  6. p. 19Uncertainty
  7. p. 30Decoherence
  8. p. 52Bertlmann's socks
  9. p. 70How wrong answers cancel

The artwork is made with AI image tools under the author's direction. How these books are made · Privacy · andreaspolymitis.com