DeepPractise
DeepPractise

Simon’s Algorithm

Track: Quantum Algorithms · Difficulty: Intermediate · Est: 15 min

Simon’s Algorithm

Overview

Simon’s algorithm is an early “period-finding” algorithm. It is historically important because it was one of the first clear examples where quantum algorithms can use interference + measurement to uncover hidden structure with dramatically fewer oracle queries than classical strategies (in the black-box model).

Problem setting:

You are given oracle access to a function

f:{0,1}n{0,1}nf:\{0,1\}^n\to\{0,1\}^n

with the promise that there exists a secret string s0ns\neq 0^n such that:

  • for every xx, f(x)=f(xs),f(x)=f(x\oplus s),
  • and these are the only collisions (so ff is 2-to-1).

Goal: find the hidden period ss.

Intuition

The algorithm uses a very “quantum” style of information extraction:

  1. Query the oracle in a superposition over all xx.
  2. Measure the output register. This doesn’t give ss directly, but it collapses the input into a superposition of two values that are paired by the hidden period: 12(x+xs).\tfrac{1}{\sqrt{2}}(|x\rangle+|x\oplus s\rangle).
  3. Apply Hadamards to the input. This converts the “two-point structure” into a constraint on what you can measure.
  4. Repeat to gather multiple constraints.
  5. Solve for ss using classical reasoning.

The key idea: measurement gives you constraints that are consistent with ss. After enough repeats, those constraints determine ss.

This is entanglement and measurement used operationally:

  • entanglement ties input and output,
  • measuring output forces input into a structured superposition,
  • interference reveals information about the hidden structure.

Algorithm Structure

High-level steps:

  1. Prepare two nn-qubit registers: input and output, starting at 0n0n|0^n\rangle|0^n\rangle.
  2. Apply HnH^{\otimes n} to the input to create a uniform superposition over xx.
  3. Query the oracle once: x0xf(x).|x\rangle|0\rangle \mapsto |x\rangle|f(x)\rangle.
  4. Measure the output register. This collapses the input to a superposition of two inputs that share the same output.
  5. Apply HnH^{\otimes n} to the input register.
  6. Measure the input register to get a bitstring yy.
  7. Repeat steps 1–6 to collect several different yy values.
  8. Use classical post-processing to reconstruct ss from the collected constraints.

Formal Description

After step 2, the joint state is

12nxx0n.\frac{1}{\sqrt{2^n}}\sum_x |x\rangle|0^n\rangle.

After the oracle:

12nxxf(x).\frac{1}{\sqrt{2^n}}\sum_x |x\rangle|f(x)\rangle.

Now measure the output register. Because ff is 2-to-1 with period ss, observing some value f(x0)f(x_0) tells you the input must be either x0x_0 or x0sx_0\oplus s. So the input collapses to

12(x0+x0s).\tfrac{1}{\sqrt{2}}\big(|x_0\rangle + |x_0\oplus s\rangle\big).

Apply HnH^{\otimes n}. The result is a superposition where many measurement outcomes cancel. What survives are outcomes yy that satisfy a parity-like constraint with ss.

A standard way to state this constraint is:

ys=0    (mod 2).y\cdot s = 0 \;\;\text{(mod 2)}.

Interpretation (no heavy algebra):

  • each measured yy is a bitstring that is “compatible” with the hidden period,
  • collecting multiple such yy values gives enough information to determine ss.

This is why Simon’s algorithm is a period-finding method: it turns a hidden XOR-period into measurable constraints.

Worked Example

Take n=2n=2 and secret period s=11s=11. Then the constraint ys=0y\cdot s=0 becomes:

y1y2=0,y_1\oplus y_2 = 0,

meaning y1=y2y_1=y_2. So the measured yy values can only be:

  • 0000 or 1111.

A single run might produce 0000 (which is not very informative by itself), but repeated runs will also produce 1111. With enough samples, you can infer that the hidden period must be 11.

This example illustrates the workflow:

  • each run gives a constraint-consistent sample,
  • classical post-processing combines them into the secret.

Turtle Tip

Turtle Tip

In Simon’s algorithm, measurement is not the “end.” Measurement is how you extract constraints, then classical processing turns constraints into the hidden period.

Common Pitfalls

Common Pitfalls
  • Don’t expect one run to reveal ss. The algorithm is designed to produce constraint samples; you need multiple runs.
  • Don’t get stuck on the algebra. The operational story is: collapse to paired inputs, then Hadamards turn that pairing into measurable constraints.

Quick Check

Quick Check
  1. After measuring the output register, what kind of superposition does the input register collapse into?
  2. What kind of information does each measured yy provide about ss?

What’s Next

Simon’s algorithm is a bridge from simple interference tricks to deeper period-finding ideas. Next we turn to Grover-style search at a conceptual level: Grover’s algorithm uses amplitude amplification to bias measurement toward marked solutions.