Simon's Algorithm
Suppose you are handed a black box that computes a function on -bit strings. You are told it is either one-to-one or exactly two-to-one in a very structured way. Somewhere hidden inside is a nonzero string . It satisfies if and only if . Finding classically requires an exponential number of queries in the worst case. This is because collisions are rare and hard to stumble upon by chance. Simon's algorithm solves this problem with only a linear number of quantum queries. It does so with a mechanism strikingly different from ordinary search. This problem is not just a curiosity. It is the first oracle problem to show an exponential separation between quantum and classical query complexity. This is strictly stronger than the constant-versus-linear gap of the The Bernstein-Vazirani Algorithm. More importantly, the algorithmic pattern it introduces is significant. That pattern is: query in superposition, measure to obtain linear constraints, solve those constraints classically. This is precisely the template that Shor's factoring algorithm generalizes. Simon's problem is the "toy version" of the hidden subgroup problem. Understanding it deeply is the cleanest route to understanding quantum advantage. It shows why quantum computers can crack structured problems that look intractable classically. The big picture: quantum superposition lets you evaluate at every input simultaneously. But you cannot simply "read off" from that superposition. Measurement collapses everything. Simon's insight is to engineer interference carefully. This ensures measurement produces not the answer directly, but a random linear constraint on the answer. Repeat enough times, and solve the resulting linear system over . Then falls out. This article builds that mechanism from the ground up. It covers the precise problem statement, the circuit, and the linear-algebra argument for why it works. It also covers the query complexity lower bound that makes the speedup meaningful. Finally, it covers the historical context that led straight to Shor's algorithm. By the end you will be able to trace the full circuit by hand on a 2-qubit example. You will explain exactly why classical algorithms are exponentially handicapped. You will also see the direct algebraic bridge from Simon's problem. This bridge leads to the The Quantum Fourier Transform-based algorithms that follow it.
- Simon's problem: find hidden nonzero such that , given oracle access to .
- Quantum algorithm uses oracle queries; the best classical algorithm needs queries — an exponential gap.
- Mechanism: Hadamard–oracle–Hadamard produces a superposition supported only on strings with .
- Each run yields one random linear equation over ; about independent equations pin down uniquely.
- Final step is classical linear algebra (Gaussian elimination), not quantum — the quantum part only generates constraints.
- Historically the first exponential quantum/classical query separation, and the direct template for Shor's algorithm.
Simon's algorithm converts a hard search for a hidden string into an easy classical linear system, by using quantum interference to force every measurement outcome to satisfy a linear constraint on the secret.
The idea
Simon's problem. Fix . You are given oracle (black-box) access to a function
(for some ) with the promise that there exists a secret string , , such that for all ,
Equivalently, is exactly two-to-one, and its only collisions are pairs . The goal is to determine using as few queries to as possible. (The case is sometimes folded in as " is injective," but the standard promise problem assumes .)
Why this is hard classically. A classical algorithm can only learn about by evaluating it at chosen points and comparing outputs. To find , you essentially need to find a collision: two distinct inputs with . Because is otherwise injective, the "collision density" is exactly what a birthday-paradox argument controls: if you query points, the number of pairs is , and each pair collides only if it happens to differ by — a -in- chance for uniformly random points. To get a constant probability of finding a collision, you need queries. This is not merely a weakness of one algorithm; it is a provable information-theoretic lower bound (a standard hybrid/adversary argument shows any classical algorithm, randomized included, needs queries with high probability of failure below that).
The quantum idea in one sentence. Query on a uniform superposition of all , then use interference (via Hadamards) so that, upon measurement, you obtain a uniformly random satisfying the linear constraint , where is the mod-2 inner product. This uses the same phase-kickback/Hadamard-oracle machinery that powers The Bernstein-Vazirani Algorithm, but here the function itself is unknown and structured rather than a known linear form — the quantum step reveals a constraint, not the answer. Collect roughly such constraints (each of the form ), treat them as a homogeneous linear system over the field , and solve for by Gaussian elimination. This is where linear algebra over GF(2) becomes essential: solving linear systems over the two-element field is exactly the same algorithmic exercise as over the reals, just with all arithmetic done mod 2.
How it works
The circuit
Simon's algorithm uses "input" qubits and "output" qubits (workspace for the oracle), all initialized to . The oracle is a unitary
which computes reversibly by XOR-ing the result into an ancilla register. One round of the algorithm: 1. Prepare . 2. Apply Hadamard to the first register, giving
3. Apply the oracle :
4. Measure the second register. This is the crucial "collapse" step; you get some outcome for the that produced it — but because is two-to-one, two values of map to : namely and . The first register collapses to
(You never actually need to know or ; measuring the second register is a bookkeeping step that can even be omitted, since discarding an unmeasured register that is entangled but never touched again has the same effect on the reduced state of the first register.) 5. Apply to the first register. Using the identity , the state becomes
The bracket equals if and if . So the amplitude survives only for with , and the surviving amplitudes all have magnitude , i.e. the state is
6. Measure the first register in the standard basis. The outcome is uniformly random over the -element subspace (the orthogonal complement of under the GF(2) inner product). Each run of steps 1–6 yields one linear equation on the unknown . Run the circuit repeatedly (each time is an independent fresh query to ), collect equations, and solve.
Full algorithm with classical post-processing
``` Algorithm SIMON(oracle f over {0,1}^n, promise: 2-to-1 with hidden shift s or injective) equations := empty list # each entry is a bit vector in GF(2)^n repeat until equations span an (n-1)-dimensional space:
# --- quantum subroutine, one query to f --- prepare |0>^n tensor |0>^m apply H^{⊗n} to first register apply U_f : |x>|0> -> |x>|f(x)> measure second register (result discarded) apply H^{⊗n} to first register measure first register -> outcome y in {0,1}^n
# --------------------------------------------- if y != 0^n: add y to equations # constraint: y . s = 0 (mod 2)
# classical post-processing: solve the homogeneous linear system
# { y . s = 0 (mod 2) for each y in equations }
# over GF(2), using Gaussian elimination. solve for the 1-dimensional solution space of s (excluding s = 0) let s_candidate := the nonzero solution found
# verification (classical, 2 extra queries) if f(0^n) == f(s_candidate) and s_candidate != 0^n: return s_candidate # confirmed hidden shift else: return "f is injective (s = 0)" # promise resolved the other way ``` Two points deserve emphasis. First, the quantum subroutine never touches directly — it only ever hands you a random hyperplane constraint. Second, the linear system might, with some probability, fail to have full rank after rounds if the sampled 's happen to be linearly dependent; the fix is simply to keep sampling until you have linearly independent nonzero vectors, then solve. A short classical check () confirms the answer, since a wrong guess would fail this test with the correct .
Complexity & correctness
Query complexity. Each round of the quantum subroutine makes exactly one query to . The expected number of rounds needed to accumulate linearly independent vectors in (each round contributes a fresh uniformly random vector in the hyperplane , which has dimension ) is in expectation — this follows the same coupon-collector-style argument used for random linear codes: the probability that a new uniformly random vector in an -dimensional space lands inside the span of previously collected independent vectors is at most , so the expected number of "wasted" draws is bounded by a constant multiple of . Hence:
Classical post-processing (Gaussian elimination on an system over ) costs bit operations (or with fast matrix multiplication, though this is rarely the bottleneck). The total algorithm therefore runs in expected time , using oracle queries — an exponential improvement over the classical query lower bound.
Classical lower bound (why the gap is real, not an artifact). Consider a classical (even randomized) algorithm that queries at points adaptively. As long as no two queried points collide (i.e., no ), every observed output looks exactly like it would for an injective function — the algorithm gets zero information distinguishing "there is a hidden " from "there is no collision yet." Since is unknown and effectively uniformly random over nonzero strings (from the algorithm's point of view), the chance that any particular pair of queried points collides is about , and by a union bound over the pairs, the probability of finding any collision after queries is . For this to be a constant, you need . This is the same birthday-bound argument that underlies collision-finding lower bounds throughout cryptography.
Correctness proof sketch (the quantum part). The key algebraic fact, proven in step 5 above, is:
This is a direct consequence of expanding both Hadamard transforms and using
which vanishes unless . The resulting distribution over (ignoring the irrelevant global phase , which disappears upon computing measurement probabilities ) is exactly uniform over the elements of the subspace . This uniformity is essential: it guarantees that repeated independent runs behave like independent uniform draws from , which is what makes the "collect independent vectors" argument work cleanly, rather than some biased sampling that might get stuck.
Correctness of the classical step. The set of solutions to a consistent homogeneous linear system over forms a subspace of . If the span all of (dimension ), the solution space of the system has dimension exactly , so it consists of exactly — pinning down uniquely (up to knowing it's the nonzero one). This is why we insist on collecting linearly independent vectors: fewer than that leaves a solution space of dimension , i.e. more than one nonzero candidate, and the algorithm would need to disambiguate with extra oracle calls (checking vs.\ for each candidate) — still efficient, but this is why the standard analysis targets full rank directly.
Honesty about tradeoffs.
- The algorithm is a promise problem solver: it assumes truly has the two-to-one structure. Without that structural promise, there is no known way to beat classical brute force for generic Boolean functions — the speedup is not "quantum computers search faster in general," it is "quantum computers exploit hidden algebraic structure."
- The expected number of rounds is , but this is a randomized (Las Vegas–style) guarantee, not a worst-case fixed bound; a small number of "wasted" rounds (where is linearly dependent on previous ones, or ) is expected and simply discarded.
- The oracle model hides the cost of implementing as a reversible circuit; in any real problem you must additionally show that itself is efficiently constructible, exactly as in the reductions used to derive Shor's algorithm from a hidden-subgroup oracle.
Worked example
Take , so inputs and are 2-bit strings. Suppose the hidden shift is and is defined (one valid choice satisfying the promise) as:
| 00 | 01 |
| 01 | 10 |
| 10 | 10 |
| 11 | 01 |
Check the promise: and ✓. and ✓. Good — exactly two-to-one with shift .
Round 1. Start with . Apply :
Apply :
Measure the second register. Say the outcome is . The surviving terms are those with : and . The first register collapses (up to normalization) to
Apply to this state. Using :
Summing and renormalizing ( times the sum, then dividing by overall):
Normalizing: . Measuring gives or , each with probability . Check the theory: the surviving 's should satisfy with . Indeed and (mod 2) — both survive, matching the two nonzero amplitudes above. ( and are correctly annihilated.) Suppose we measure . This gives equation: .
Round 2. Repeat the whole circuit independently. Suppose this time we measure — this is the trivial "all-zero" outcome, which gives the equation , uninformative. We discard it (it happens with probability times something — here , since has only 2 elements when , and is always one of them). We must query again.
Round 3. Independent repeat. Suppose we measure again. Same equation as round 1: . No new information — but for we only need independent equation, and we already had it from round 1.
Post-processing. We have the single independent equation , i.e. . Over excluding the zero vector, the solutions with are ; discarding (excluded by promise), the unique candidate is
Verification. Check : both equal . ✓ Confirmed: , matching the planted secret. This trace shows all the moving parts: the informative equation (), the useless equation (, which must be filtered out and does occur with nontrivial probability), and the classical linear-algebra step that turns one bit equation into the final answer.
Common pitfalls & traps
| Pitfall | What goes wrong | Fix |
|---|---|---|
| Treating as a valid constraint | It's always in (trivially true, ), gives no information | Discard all-zero measurement outcomes; they don't count toward your needed equations |
| Assuming measurements always give independent equations | Repeated/dependent 's can occur; naively stopping at round risks a rank-deficient system | Explicitly check rank via Gaussian elimination; keep sampling (expected extra rounds) until rank is |
| Forgetting to verify the candidate | A rank-deficient or numerically mis-solved system can output a spurious | Always confirm with the cheap classical check |
| Conflating this with Grover-style amplitude amplification | Simon's speedup is not a quadratic search speedup; it's an exponential query separation from structure, different mechanism entirely | Keep clear: Grover trades query count for quadratic gain in unstructured search; Simon exploits algebraic promise for exponential gain |
| Misapplying the promise (assuming any many-to-one works) | The two-to-one-with-XOR-shift structure is essential; a function with other collision patterns breaks the derivation in step 5 | Always double check literally satisfies before applying the algorithm |
| Ignoring the cost of implementing reversibly | The oracle abstraction can hide exponential classical circuit cost for computing | Confirm has an efficient (poly-size) reversible circuit before claiming an end-to-end speedup |
Pioneers & history
Origins · 1 minDaniel R. Simon and how this was discovered
Daniel Simon introduced the problem and algorithm bearing his name in a 1994 paper, motivated by the search for oracle problems separating quantum and classical query complexity by more than the Deutsch–Jozsa/Bernstein–Vazirani-style linear gaps known at the time. His construction was the first to demonstrate a provable exponential separation, and it directly inspired Peter Shor, who generalized the "quantum Fourier sampling reveals hidden periodicity" mechanism to give an efficient factoring algorithm the following year.
Where this matters
Simon's algorithm is rarely deployed "as is" in industry, since real-world problems seldom present a black-box function with an exact two-to-one XOR-shift promise handed to you. Its importance is structural and pedagogical: it is the cleanest demonstration that quantum query complexity can be exponentially smaller than classical query complexity, and it is the direct conceptual ancestor of Shor's algorithm. The pattern — put a register in superposition, query an oracle, use Hadamards (more generally the The Quantum Fourier Transform) to convert entanglement into interference, measure to extract linear or periodic constraints, then finish with classical number theory or linear algebra — recurs throughout the hidden subgroup problem framework that unifies factoring, discrete logarithm, and related cryptanalytic quantum algorithms. Concretely, this matters for post-quantum cryptography: RSA and Diffie–Hellman security rest on the classical hardness of factoring and discrete log, both instances of hidden subgroup problems that succumb to Simon-style quantum Fourier sampling (via Shor's algorithm). Understanding Simon's algorithm is the standard on-ramp used in quantum algorithms courses (and in NIST's own explanatory materials on post-quantum cryptography) to explain why certain cryptosystems are considered quantum-vulnerable while others (lattice-based schemes, hash-based signatures) are believed to resist this style of attack — because they lack the clean abelian hidden-shift/hidden-subgroup structure that Simon's mechanism exploits. It is also a staple benchmark for early fault-tolerant and NISQ-era quantum hardware demonstrations of "quantum advantage on a structured promise problem," precisely because its circuit is shallow and its correctness condition is easy to verify classically.
Ask the tutor: How does the hidden subgroup problem framework generalize Simon's linear-shift structure to the periodic structure Shor's algorithm exploits for factoring?
Is Simon's algorithm ever used directly in real applications?
Not typically as a standalone tool, because real problems rarely arrive with the exact two-to-one XOR-shift promise it requires. Its lasting importance is as the cleanest example of an exponential quantum/classical query separation and as the direct template that Peter Shor generalized into the factoring algorithm. It is taught primarily to build intuition for how quantum Fourier-type interference converts a hard search into a sequence of easy linear (or later, arithmetic) constraints, a pattern reused throughout the hidden subgroup problem framework underlying most known exponential quantum speedups.
How is this different from Grover's algorithm's speedup?
Grover's algorithm gives a quadratic speedup for unstructured search — from classical queries to quantum queries — and it works for essentially any function with no special structure, via amplitude amplification. Simon's algorithm gives an exponential speedup, but only because the oracle is promised to have very specific algebraic structure (an exact two-to-one XOR-periodicity). The mechanisms are unrelated: Grover rotates a state vector geometrically toward the marked item; Simon uses linear interference to extract constraints on a hidden parameter. Exponential speedups generally require structure; Grover's generality is exactly why its speedup is only quadratic.
Why do we need roughly n, not fewer, measurement rounds?
The hidden string s lives in an n-dimensional vector space over GF(2), and s is only determined up to sign-free scalar multiples in this field, i.e. uniquely as the nonzero solution to a linear system. To pin down a 1-dimensional solution space inside an n-dimensional space, you need a system of rank n−1. Each successful (nonzero) quantum measurement yields one new linear constraint, but some constraints turn out to be linearly dependent on previous ones and don't increase the rank. Coupon-collector-style analysis shows the expected number of rounds to reach full rank is O(n), not exactly n.
What happens if the promise is violated, e.g., f is actually injective?
If is injective (no hidden shift at all, i.e., effectively ), the algorithm still runs, but the measured 's will end up spanning the entire space rather than an -dimensional subspace, since there is no nontrivial to confine them to. Gaussian elimination on a full-rank system yields only the trivial solution . The final classical check for any nonzero candidate will fail, correctly signaling "no hidden shift found," which is exactly the intended behavior for the promise-problem's other branch.
Does Simon's algorithm need error correction or fault tolerance to run on real hardware?
Not fundamentally — the circuit is shallow: two layers of Hadamards and a single oracle call per round, followed by measurement. This makes it a popular small-scale demonstration on near-term noisy devices for showing quantum interference producing structured randomness. However, on real noisy hardware, gate errors can flip bits in the measured 's, corrupting some of the linear equations; running enough extra rounds and using majority voting or outlier-rejection heuristics on redundant equations mitigates this without requiring full fault tolerance, unlike Shor's algorithm's practical factoring instances, which do need error correction at meaningful problem sizes.
How does this connect conceptually to the Quantum Fourier Transform used later in Shor's algorithm?
The Hadamard transform used in Simon's algorithm is exactly the quantum Fourier transform over the group . Shor's algorithm generalizes this to the quantum Fourier transform over (or more generally over finite abelian groups), used to detect periodicity in the integers rather than in GF(2)-linear structure. Both algorithms follow the identical template: superpose, query an oracle encoding hidden structure, Fourier transform to convert period/shift information into a measurable frequency or constraint, then finish with classical number theory or linear algebra.
Why is the birthday-bound classical lower bound considered tight and not just a weak heuristic?
The bound is not just intuition; it can be formalized rigorously using an adversary or hybrid argument that bounds the statistical distinguishability between the "hidden shift" oracle and a truly random injective oracle after any fixed number of queries. Since both oracles behave identically on all queried points until a collision is found, and the probability of any specific pair colliding is , a union bound over query pairs gives the matching upper bound on success probability. This makes the exponential quantum/classical query gap for Simon's problem a proven, not conjectured, separation.