Simon’s Algorithm
Simon's algorithm solves a structured search problem exponentially faster on a quantum computer than on any classical one. It was the first clear evidence of an exponential quantum speedup (Simon, 1994) and directly inspired Shor's factoring algorithm.
The problem
You are given a black-box function that is either one-to-one or two-to-one. In the two-to-one case there is a hidden nonzero string such that
where denotes bitwise XOR. Your task is to find .
Classically you need queries on average. Simon's quantum algorithm uses only queries.
The circuit
The circuit uses qubits: input qubits (register A) and ancilla qubits (register B).
- Uniform superposition. Apply to register A.
- Query the oracle. Apply so that .
- Hadamard again. Apply to register A.
- Measure register A.
After step 1 the state is
After step 2:
Because is two-to-one with period , each output value appears for exactly the pair and . After the second on register A, interference ensures that every measurement outcome satisfies
Running the circuit times yields independent linear equations over ; Gaussian elimination then recovers .
A concrete 2-qubit example
Take and . We need for all :
| | | | |-----|---------------|--------| | 00 | 11 | 0 | | 01 | 10 | 1 | | 10 | 01 | 1 | | 11 | 00 | 0 |
A simple oracle realizing this is . In circuit language: CNOT(0, 2) copies qubit 0 into qubit 2, then CNOT(1, 2) XORs qubit 1 into qubit 2, leaving in qubit 2.
After the full circuit the allowed measurement outcomes for qubits 0 and 1 must satisfy , i.e. only and can appear. Working through the algebra: the four-qubit state just before measurement is
so each of these four basis states has probability .
Try it
Complete the oracle in the starter code. The grader checks the full probability distribution over all 4 qubits; the correct circuit places equal probability on , , , and (and zero everywhere else).
Sign in on the full site to ask questions and join the discussion.