Level 3 · Algorithms
Simon’s Algorithm: The First Exponential Quantum Speed-Up, Worked Step by Step
About 5,123 words · roughly 23 minute read · sources checked December 3, 2026
Simon’s problem is one of the most important toy problems in quantum computing. It is artificial: nobody needs to solve it for its own sake. But it was the first problem with a proven exponential gap between what a quantum computer needs and what a classical computer needs, measured in the number of calls to a black box. And the technique that solves it, a Fourier transform followed by classical linear algebra, is the same technique that Peter Shor later used to factor numbers.
In this lesson we build the algorithm from scratch. We start with the problem, then build the circuit, then follow a complete example on three qubits where every state is written out. After that we count how many runs are needed and how likely it is to succeed, which turns out to have a surprisingly clean answer. We then look at the classical side: how to solve the equations that the quantum computer produces, and why no classical algorithm can avoid exponentially many queries. We finish with how Simon’s idea led to Shor’s algorithm, and what the limits of the result are.
A note on honesty. I did not run Qiskit in my environment, because it was not installed. All numbers in this lesson were computed with my own NumPy simulation or with exact formulas, and I say which. The sample-count table was checked two ways: by an exact formula and by a Monte Carlo simulation of 20,000 trials. The two agree to within sampling noise, and I give both. I did not open Simon’s original paper in this session, so I describe the problem in its standard textbook form and say so where it matters.
You should have read the lessons on superposition, quantum gates and the Deutsch–Jozsa algorithm before this one. Deutsch–Jozsa and Bernstein–Vazirani use the same two-register pattern, and Simon’s algorithm is the next step up in that family.
What you will learn
- What Simon’s problem asks and what the promise about the black box means.
- How the circuit works, with the state written out after every step.
- A complete worked example on three qubits, including every measurement outcome.
- How to turn the measured bit strings into the hidden string using linear algebra over GF(2).
- How many runs you need, with exact probabilities and a table.
- Why a classical computer needs exponentially many queries.
- How Simon’s idea connects to Shor’s algorithm, and where the comparison stops being fair.
Helpful first: Deutsch–Jozsa and Bernstein–Vazirani in Qiskit, Quantum Algorithms.
The problem: a hidden XOR mask
Start with a black box, which computer scientists call an oracle. The black box computes a function f that takes an n-bit string as input and returns an n-bit string as output. You cannot look inside it. You can only feed it inputs and read outputs, and each such call is called a query. The goal is to learn something hidden about f using as few queries as possible.
The promise is this. There is a secret n-bit string s, not equal to all zeros. The function f has the property that two different inputs give the same output exactly when they differ by s. In symbols, f(x) = f(y) if and only if y = x ⊕ s, where ⊕ means bitwise exclusive-or, which is addition of each bit without carrying. Such a function is two-to-one: every output value is produced by exactly two inputs, and those two inputs are partners under the mask s. The task is to find s.
A refresher on XOR
XOR of two bits is 0 if they are equal and 1 if they differ. For bit strings we apply it position by position. For example, 101 ⊕ 110 = 011, because the first bits are equal (1 and 1 give 0), the second bits differ (0 and 1 give 1), and the third bits differ (1 and 0 give 1). Two facts about XOR are used constantly in this lesson. First, anything XORed with itself is zero: x ⊕ x = 000. Second, XOR is its own inverse: if y = x ⊕ s then x = y ⊕ s. That is why the two inputs that share an output are partners: apply the mask once and you move from one to the other, apply it again and you come back.
| x | x ⊕ 110 | Pair |
|---|---|---|
| 000 | 110 | {000, 110} |
| 001 | 111 | {001, 111} |
| 010 | 100 | {010, 100} |
| 011 | 101 | {011, 101} |
With n = 3 and the secret s = 110, the eight inputs split into four partner pairs. A valid f must give the same output within a pair and different outputs between pairs.
Worked example
A concrete function that satisfies the promise
- Take n = 3 and s = 110. Define f(x) as the smaller of x and x ⊕ s, read as a number.
- Then f(000) = f(110) = 0, f(001) = f(111) = 1, f(010) = f(100) = 2, and f(011) = f(101) = 3. I computed this directly: the eight outputs are 0, 1, 2, 3, 2, 3, 0, 1 for the inputs 0 to 7.
- Every output appears exactly twice, and each pair of inputs with the same output differs by 110. So the promise holds.
Now the question: how many queries do you need to find s? If you query two inputs and get the same output, you have found a pair, and the XOR of the two inputs is s. But you cannot tell in advance which pairs collide. The function looks random except for that hidden structure. We will see that a classical algorithm must keep querying until it gets lucky, and that Simon’s quantum algorithm needs only about n queries.
Why this problem matters
The speed-up is measured in queries to the black box, not in running time on a real machine. That is a clean way to prove a gap, because the argument does not depend on any clever classical trick. But it also means the problem is an oracle problem: a real-world version needs a real function that someone can compute efficiently, and that is where Shor’s algorithm comes in later.
What a classical computer has to do
Suppose you query f on inputs x₁, x₂, x₃, and so on, and write down the outputs. As long as all the outputs are different, you have learned nothing about s, except that none of the queried inputs are partners. The moment two outputs match, you know that the two inputs are partners, and the XOR of those inputs is s.
In the worst case you have to query more than half of all the inputs. There are 2ⁿ inputs and they form 2ⁿ⁻¹ partner pairs. If you query one member from each of 2ⁿ⁻¹ different pairs, you see 2ⁿ⁻¹ different outputs and still know nothing. The next query must land in an already-seen pair, so the worst case is 2ⁿ⁻¹ + 1 queries for a deterministic algorithm. I computed this value for several sizes:
| n (bits) | Inputs 2ⁿ | Classical worst-case queries 2ⁿ⁻¹ + 1 |
|---|---|---|
| 2 | 4 | 3 |
| 3 | 8 | 5 |
| 4 | 16 | 9 |
| 5 | 32 | 17 |
| 8 | 256 | 129 |
| 10 | 1,024 | 513 |
| 20 | 1,048,576 | 524,289 |
| 30 | 1,073,741,824 | 536,870,913 |
Worst-case number of queries for a deterministic classical algorithm. The count doubles with each extra bit.
A randomised classical algorithm does better on average, using what is called the birthday effect. If you query about 2^(n/2) random inputs, the chance that two of them are partners becomes substantial, in the same way that in a group of 23 people two often share a birthday. So the best classical algorithms need on the order of 2^(n/2) queries, which is still exponential in n. The standard textbook statement is that any classical algorithm, even a randomised one, needs exponentially many queries. I did not open a source for the formal proof, so I present the statement as the standard result and not as something I verified here.
| n (bits) | About 2^(n/2) (birthday scale) |
|---|---|
| 10 | 32 |
| 20 | 1,024 |
| 30 | 32,768 |
| 40 | 1,048,576 |
| 60 | 1,073,741,824 |
The scale of a randomised classical search. These are orders of magnitude, not exact query counts, and the exact constant depends on the algorithm.
Compare these with the quantum count, which we will derive later: about n queries, plus a small constant. For n = 60 the classical scale is around a billion queries, and the quantum count is about sixty.
The quantum circuit
The circuit uses two registers of n qubits each. The first register, the input register, holds the inputs x. The second register, the output register, receives f(x). The oracle is a unitary operation U_f that maps |x⟩|b⟩ to |x⟩|b ⊕ f(x)⟩. That is the standard way to compute a function reversibly: instead of replacing b by f(x), we XOR f(x) into it, so that the operation can be undone.
- Prepare both registers in |0…0⟩.
- Apply a Hadamard gate to every qubit of the input register. This puts the input register into an equal superposition of all 2ⁿ inputs.
- Apply the oracle U_f once. Now the two registers are correlated: each input x is paired with its output f(x).
- Measure the output register. You get some value v, uniformly at random from the 2ⁿ⁻¹ possible output values. This step collapses the input register.
- Apply a Hadamard gate to every qubit of the input register again.
- Measure the input register. The result is a bit string y.
- Repeat the whole procedure and collect several strings y₁, y₂, …. Solve the resulting equations to find s.
Let us follow the states. After step 2, the joint state is (1/√2ⁿ) Σₓ |x⟩|0⟩, where the sum runs over all 2ⁿ inputs. After step 3 it becomes (1/√2ⁿ) Σₓ |x⟩|f(x)⟩. Notice that each output value appears twice in this sum, once for each of the two partner inputs.
Step 4 measures the output register and sees a particular value v. Only the terms with f(x) = v survive. Because f is two-to-one, exactly two inputs give this output: some x₀ and its partner x₀ ⊕ s. The input register collapses to an equal superposition of just these two:
|x₀⟩ + |x₀ ⊕ s⟩
───────────────────── (input register after measuring the output v)
√2This is the crucial point. We have a quantum state that depends on s, but we cannot read s from it directly: if we measured now, we would see x₀ or x₀ ⊕ s with equal probability, and a single random input tells us nothing. The second layer of Hadamard gates is what converts the hidden structure into something measurable.
Why the second Hadamard layer reveals s
To see what the second layer of Hadamard gates does, we need the rule for applying Hadamard gates to every qubit at once. On a basis state |x⟩ of n qubits, the result is (1/√2ⁿ) Σ_y (−1)^(x·y) |y⟩. Here x·y is the dot product of the two bit strings modulo 2: multiply bit by bit, add up, and keep only whether the total is even or odd. The factor (−1)^(x·y) is +1 when x·y is even and −1 when it is odd.
Apply this to our collapsed state (|x₀⟩ + |x₀ ⊕ s⟩)/√2. The amplitude on each output string y is a sum of two terms:
amplitude of |y⟩ = (1/√2ⁿ⁺¹) · [ (−1)^(x₀·y) + (−1)^((x₀ ⊕ s)·y) ]
= (1/√2ⁿ⁺¹) · (−1)^(x₀·y) · [ 1 + (−1)^(s·y) ]The bracket [1 + (−1)^(s·y)] equals 2 if s·y is even and 0 if s·y is odd. So the amplitude is zero for every y with s·y = 1, and non-zero for every y with s·y = 0. The unknown starting point x₀ only contributes an overall sign, so it drops out of the probabilities completely. That is the whole trick: whatever random x₀ the measurement happened to pick, the final probabilities depend only on s.
Counting the surviving strings: exactly half of all 2ⁿ strings satisfy s·y = 0, because s is non-zero. That is 2ⁿ⁻¹ strings, and they get equal probability 1/2ⁿ⁻¹ each, since the squared amplitudes must add to 1. So each run of the circuit returns a uniformly random string y from the set {y : y·s = 0}.
The key statement
Every measured string y satisfies y·s = 0 (mod 2). Each run gives one linear equation about the unknown bits of s. A different random y each time gives a different equation. Collect enough independent equations and s is determined.
A complete worked example with n = 3
Let us run the whole algorithm for n = 3 and s = 110, so the secret has bits s₂ = 1, s₁ = 1, s₀ = 0. I will use the function from the problem section, built in the standard way described below, and I simulated the full six-qubit circuit to check every claim.
The oracle
A simple way to build an oracle that satisfies the promise is this. Copy the input into the output register with three CNOT gates, so the output register holds x. Then pick any position j where s has a 1, here the lowest one, j = 1. Add a second layer of CNOT gates, controlled by input qubit j, that XOR the string s into the output register. The function computed is f(x) = x ⊕ (x_j · s): when bit j of x is 1, the output gets s XORed in; otherwise it does not.
| Input x | f(x) = x ⊕ (x₁ · 110) |
|---|---|
| 000 | 000 |
| 001 | 001 |
| 010 | 100 |
| 011 | 101 |
| 100 | 100 |
| 101 | 101 |
| 110 | 000 |
| 111 | 001 |
The oracle function used in my simulation. Each output appears exactly twice, and the pairs are {000, 110}, {001, 111}, {010, 100}, {011, 101}: the pairs differ by 110, as required.
Check one pair by hand. Inputs 010 and 100 differ by 110, since 010 ⊕ 100 = 110. Both give output 100. Inputs 011 and 101 also differ by 110 and both give 101. Good.
The measurement outcomes
Following the argument above, each run should return a string y with y·s = 0, where s = 110 and the dot product multiplies matching positions. For y = y₂y₁y₀, y·s = y₂·1 + y₁·1 + y₀·0 = y₂ + y₁ modulo 2. So y·s = 0 exactly when y₂ = y₁. The strings satisfying this are 000, 001, 110 and 111. I ran the full circuit on the simulator and got exactly these four, each with probability 0.25, and probability 0 for the other four strings.
| y | y·s mod 2 | Probability in one run |
|---|---|---|
| 000 | 0 | 0.25 |
| 001 | 0 | 0.25 |
| 010 | 1 | 0 |
| 011 | 1 | 0 |
| 100 | 1 | 0 |
| 101 | 1 | 0 |
| 110 | 0 | 0.25 |
| 111 | 0 | 0.25 |
Measured distribution from my simulation of the six-qubit circuit. Qiskit’s printed order puts qubit 0 on the right, and the strings above use that same order.
Solving for s
Suppose two runs return y = 001 and y = 111. Each gives an equation:
- y = 001 gives s₀ = 0 (only the last bit of y is 1).
- y = 111 gives s₂ + s₁ + s₀ = 0, which with s₀ = 0 becomes s₂ = s₁.
The unknown s has three bits. The two equations leave only s = 000 or s = 110 as possibilities (the choice s₂ = s₁ = 0 or s₂ = s₁ = 1, with s₀ = 0). The promise says s is not zero, so s = 110. Two independent samples were enough, which is n − 1 = 2.
Now suppose the first two runs happened to return 000 and 110. The string 000 gives the equation 0 = 0, which tells us nothing, because the zero string satisfies every equation. So after those two runs we know only s₂ + s₁ = 0 from 110, and s still has several possibilities: 110 and 001 and 111 would all satisfy it, since 001 has s₂ + s₁ = 0. We need another sample. This is why the number of runs is not fixed in advance.
How many runs do you need?
Each run returns a string uniformly at random from the 2ⁿ⁻¹ strings with y·s = 0. These strings form a subspace of dimension n − 1 over the two-element field, the set of bit strings with XOR as addition. To pin down s, we need n − 1 independent strings, meaning a set none of which is the XOR of others. The question is how many random draws it takes to collect n − 1 independent ones.
There is an exact answer. Suppose you already have k independent strings. They span 2ᵏ strings out of the 2ⁿ⁻¹ available, so a new random draw is useless with probability 2ᵏ/2ⁿ⁻¹. The chance of a useful draw is 1 − 2^(k − (n − 1)). The expected number of draws is the sum of the reciprocals of these probabilities, for k from 0 to n − 2.
expected draws = Σ for k = 0 … n−2 of 1 / ( 1 − 2^(k − (n−1)) )
| n | Exact expected runs | Monte Carlo (20,000 trials) |
|---|---|---|
| 2 | 2.0 | not run |
| 3 | 3.3333 | 3.3285 |
| 4 | 4.4762 | 4.4759 |
| 5 | 5.5429 | not run |
| 8 | 8.5989 | not run |
| 10 | 10.6047 | not run |
| 20 | 20.6067 | not run |
| 30 | 30.6067 | not run |
Expected number of runs of the quantum circuit. The exact column is from the formula; the Monte Carlo column is my own simulation of random draws, run only for n = 3 and 4. They agree to within sampling noise.
The pattern is neat. For large n the expected number of runs settles to about n − 1 + 1.6067, that is, about n + 0.6. You need roughly one run per bit of s, plus a little extra for the draws that happen to be dependent. The exponential classical count of 2ⁿ⁻¹ + 1 has been replaced by a count that grows linearly in n.
The probability of success after a fixed number of runs
In practice you often fix the number of runs in advance. The probability that k random strings span the whole (n − 1)-dimensional space has a similarly neat form. For k = n − 1, the product of (1 − 2^(−j)) for j = 1 to n − 1, which tends to about 0.2888 as n grows. I computed the exact values with a small Markov-chain calculation:
| n | k = n − 1 | k = n | k = n + 1 | k = n + 2 | k = n + 5 | k = n + 10 |
|---|---|---|---|---|---|---|
| 3 | 0.375 | 0.6562 | 0.8203 | 0.9082 | 0.9883 | 0.9996 |
| 4 | 0.3281 | 0.6152 | 0.7947 | 0.894 | 0.9864 | 0.9996 |
| 8 | 0.2911 | 0.5798 | 0.7716 | 0.881 | 0.9846 | 0.9995 |
| 10 | 0.2894 | 0.5781 | 0.7705 | 0.8803 | 0.9845 | 0.9995 |
| 20 | 0.2888 | 0.5776 | 0.7701 | 0.8801 | 0.9845 | 0.9995 |
Probability that k runs give enough independent strings to determine s, from my exact calculation. Beyond n + 10 runs the failure probability is below 0.05% for every n shown.
Two practical lessons come out. First, running exactly n − 1 times succeeds less than a third of the time for large n; you should plan on about n + 10 runs to be 99.9% sure. Second, the required number of extra runs does not grow with n. Whether you are finding a 10-bit secret or a 1,000-bit secret, ten extra runs give the same confidence. In total the quantum algorithm uses on the order of n queries to the oracle.
An important detail about the output measurement
Each run uses the oracle once. The measurement of the output register in step 4 is not a query; it only selects which partner pair the input register collapses to. Some descriptions skip this step and measure only the input register at the end. The statistics for y are the same either way.
The classical half: solving equations over GF(2)
The quantum computer produces strings. A classical computer finishes the job. After collecting several strings y₁, y₂, … you have a system of equations y_k · s = 0 (mod 2), and you want the non-zero solution s. This is ordinary Gaussian elimination, with one simplification: the only numbers are 0 and 1, and adding means XOR.
Here is a 4-bit example you can check by hand. Let the secret be s = 1011, so the bits are s₃ = 1, s₂ = 0, s₁ = 1, s₀ = 1. A string y is a possible output exactly when y₃s₃ + y₂s₂ + y₁s₁ + y₀s₀ is even. Since s₂ = 0, this reduces to y₃ + y₁ + y₀ being even, and the bit y₂ is free.
Worked example
Solving a 4-bit case
- Three runs return y = 0100, y = 1010 and y = 0011. Check that each is valid: for 0100 the sum y₃ + y₁ + y₀ is 0; for 1010 it is 1 + 1 + 0 = 2, which is even; for 0011 it is 0 + 1 + 1 = 2, which is even.
- The string 0100 gives the equation s₂ = 0, since only bit 2 of y is 1.
- The string 1010 gives s₃ + s₁ = 0, so s₃ = s₁.
- The string 0011 gives s₁ + s₀ = 0, so s₁ = s₀.
- Together: s₃ = s₁ = s₀ and s₂ = 0. The secret is non-zero, so all three equal bits must be 1, which gives s = 1011.
The three equations were independent, which is exactly n − 1 = 3 for n = 4. If one of the runs had returned 0000, or a repeat of an earlier string, it would have added nothing, and a further run would have been needed.
The cost of the classical part
Gaussian elimination on about n equations with n unknowns takes on the order of n³ simple steps, and each step is a single bit operation on strings of length n. That is polynomial in n, trivial compared with the exponential query count. So the total cost of Simon’s algorithm is on the order of n oracle queries plus a polynomial amount of classical work.
def solve_simon(samples, n):
# samples: list of ints y with y . s = 0 (mod 2)
# Gaussian elimination over GF(2): keep a reduced basis
basis = {} # pivot bit -> row
for y in samples:
for bit in range(n - 1, -1, -1):
if not (y >> bit) & 1: continue
if bit in basis: y ^= basis[bit]
else: basis[bit] = y; break
# the free variable gives s; try all strings consistent with the basis
cands = [s for s in range(1, 2**n)
if all(bin(r & s).count('1') % 2 == 0 for r in basis.values())]
return cands # a single candidate once n-1 independent samples are inThe routine keeps a basis of the strings seen so far, discarding any sample that is a combination of earlier ones. When the basis has n − 1 rows, exactly one non-zero s is orthogonal to all of them.
From Simon to Shor
Simon’s problem looks like a curiosity, but it has the same shape as factoring. Simon’s function has a hidden period under XOR: f(x) = f(x ⊕ s). The function in Shor’s algorithm, f(x) = aˣ mod N, has a hidden period under ordinary addition: f(x) = f(x + r), where r is the order of a modulo N. In both cases, the quantum computer puts the input in superposition, evaluates the function, and applies a Fourier-type transform that turns the hidden period into measurable peaks. The Hadamard transform is the Fourier transform over the group of bit strings with XOR; the quantum Fourier transform is the Fourier transform over the integers modulo 2ᵗ.
In both algorithms a classical post-processing step finishes the job. In Simon’s case it is solving linear equations over GF(2); in Shor’s case it is the continued-fraction expansion plus a greatest-common-divisor calculation. The previous lessons on this site (the Fourier transform, phase estimation and Shor’s algorithm) follow the same pattern. Cleve, Ekert, Macchiavello and Mosca’s 1997 paper, whose abstract I opened, makes the broader point that several algorithms can be seen as instances of one pattern, with multi-particle interference favouring the correct outcome.
| Feature | Simon’s algorithm | Shor’s algorithm (order finding) |
|---|---|---|
| Hidden structure | f(x) = f(x ⊕ s) | f(x) = f(x + r) |
| Group | Bit strings under XOR | Integers modulo 2ᵗ under addition |
| Transform | Hadamard on every qubit | Quantum Fourier transform |
| Outcome of one run | Random y with y·s = 0 | Random multiple of 2ᵗ/r, roughly |
| Classical finish | Linear algebra over GF(2) | Continued fractions and gcd |
| Where the black box comes from | Assumed oracle | Modular exponentiation, which is computable |
Side-by-side comparison. Shor’s algorithm is not a literal special case of Simon’s, but it follows the same plan.
The last row is where the two diverge in an important way. Simon’s function is an oracle: the speed-up is measured in queries, and nobody has a useful, naturally occurring function that satisfies Simon’s promise. In Shor’s algorithm the function is explicit and efficiently computable, so the speed-up is for a real task, factoring. That is why Shor’s algorithm matters in practice and Simon’s does not.
A fair comparison
A query advantage does not by itself imply a running-time advantage on real data. For Simon’s problem the advantage is exponential in queries, and I have not claimed any running-time result beyond the n queries and polynomial classical post-processing.
A Qiskit outline
The listing below builds the Simon circuit for a chosen secret s, using the CNOT-based oracle described earlier. I could not run it, because Qiskit was not installed in my environment, so treat it as a careful draft and test it on your own machine. My simulation with the same gates gave the four outcomes 000, 001, 110 and 111 with probability 0.25 each, for s = 110.
from qiskit import QuantumCircuit
def simon_circuit(s: str):
n = len(s) # s like '110'; s[0] is the leftmost bit
bits = [int(b) for b in reversed(s)] # bits[i] = bit i, qubit 0 = rightmost
qc = QuantumCircuit(2 * n, n)
qc.h(range(n)) # superposition of all inputs
for i in range(n): # copy x into the output register
qc.cx(i, n + i)
j = min(i for i in range(n) if bits[i] == 1)
for i in range(n): # add s when bit j of x is 1
if bits[i] == 1:
qc.cx(j, n + i)
qc.h(range(n)) # second Hadamard layer
qc.measure(range(n), range(n)) # read the input register only
return qcWhen you run this with s = '110', you should see only the strings 000, 001, 110 and 111, each about a quarter of the time. If you see others, the most common cause is the bit-order reversal: check which position is j. Then collect the printed strings, ignore any repeats, and solve the equations with the routine above.
The oracle in this listing is a toy one: it already knows s, because it was built from s. In a real oracle problem, someone hands you a black box without telling you s. The listing exists to let you test the algorithm, not to find unknown secrets.
Common misunderstandings
- “Simon’s algorithm finds s in one run.” It does not. Each run gives one equation, and you need about n of them.
- “The quantum computer evaluates f on all inputs and reads out the answer.” The oracle is called once per run, and the individual outputs are never read. What you read is a string that satisfies an equation about s.
- “Any random y is useful.” The string y = 00…0 always satisfies y·s = 0 but carries no information, and some random strings repeat or depend on earlier ones.
- “The speed-up applies to real functions.” It applies to functions with Simon’s promise. The promise is strong, and a real problem would have to have it.
- “Simon’s algorithm breaks encryption.” It does not by itself. Some research has studied how Simon-type structure appears in certain symmetric ciphers, but I did not open a source on that here, so I make no claim beyond saying the idea is studied.
- Mixing up the bit order. In Qiskit the printed string has qubit 0 on the right. That is a presentation issue, not an error in the algorithm.
Frequently asked questions
Why does the output register need to be measured?
Measuring the output collapses the input register to a partner pair. If you skip the measurement the statistics for the input register after the final Hadamards come out the same, because the output register is in a mixture that does not affect them. Textbooks often include the step to make the reasoning clearer.
What if s = 000?
Then f is one-to-one rather than two-to-one, and the measured strings y are uniform over all 2ⁿ strings. You would see no equation that rules anything out. That is the reason the problem excludes s = 000 from the promise; a variant of the problem asks you to decide which case you are in, which I did not analyse here.
Is the exponential gap real or just a feature of oracles?
It is real as a statement about queries. It does not translate automatically into a gap for tasks without an oracle. The later algorithms, such as Shor’s, turn this idea into a gap for an explicit task, though they depend on the assumption that factoring is hard for classical computers, which is not proven.
How is this different from Deutsch–Jozsa?
Deutsch–Jozsa needs one quantum query where a deterministic classical algorithm needs up to 2ⁿ⁻¹ + 1, but a randomised classical algorithm solves it with a handful of queries with high probability. Simon’s problem, by contrast, defeats randomised classical algorithms too; that is why it is considered a stronger separation. This comparison is the standard textbook one, and I did not re-verify it from a source here.
Can I run this on real hardware?
For tiny n, yes in principle. The circuit needs two registers of n qubits and about 2n CNOT gates plus Hadamards. On noisy devices, errors will produce strings that violate y·s = 0, and the classical solver will then give inconsistent equations, so you need a way to handle noise. I did not test this on hardware.
Practice questions
Check yourself
For n = 4 and s = 0110, which of 0010, 0001, 0110, 1001, 1111 can appear as an output y?
Only bits 2 and 1 of s are 1, so y·s = y₂ + y₁ mod 2. 0010: 0 + 1 = 1, odd, so it cannot appear. 0001: 0, valid. 0110: 1 + 1 = 0, valid. 1001: 0, valid. 1111: 1 + 1 = 0, valid. Four of the five can appear.
How many different strings can appear as an output y for general n and s ≠ 0?
2ⁿ⁻¹, since exactly half of all strings have even overlap with s.
Why do two runs giving the same y not help?
The second equation is identical to the first, so it adds no new information. You need independent strings.
For n = 10, about how many runs do you expect to need?
About 10.6, from the exact formula in the table (10.6047).
What is the classical worst-case query count for n = 20?
2¹⁹ + 1 = 524,289.
Why does the unknown starting point x₀ not matter in the final measurement?
It contributes only the overall sign (−1)^(x₀·y) to each amplitude, and signs disappear when you square to get probabilities.
Summary
- Simon’s problem: find a hidden non-zero mask s such that f(x) = f(y) exactly when y = x ⊕ s.
- Classically, the worst case is 2ⁿ⁻¹ + 1 queries; the standard result is that even randomised algorithms need exponentially many.
- The quantum circuit uses Hadamards, one oracle call and Hadamards again, and returns a random y with y·s = 0.
- About n runs give n − 1 independent equations; the expected count is about n + 0.6 for large n, and n + 10 runs succeed with probability above 99.9% in my tables.
- A classical solver over GF(2) finishes the job in polynomial time.
- The same plan, with a different group and a different transform, becomes Shor’s algorithm.
References and further reading
I did not open a source for Simon’s original paper or for the formal statement of the classical lower bound in this session. The problem statement, the circuit and the classical lower bound are given in their standard textbook form, and I flag that. I did open the arXiv abstract of Cleve, Ekert, Macchiavello and Mosca (1997), which presents several algorithms as instances of one pattern. All probabilities, tables and the worked example are from my own exact calculations and a simulation I wrote. Qiskit was not installed, so no Qiskit code was run.
- Quantum Algorithms Revisited (arXiv (Cleve, Ekert, Macchiavello, Mosca, 1997)) Opened the abstract page. Presents several quantum algorithms as instances of one phase-estimation-like pattern.
Key terms in the dictionary