Solving the Linear System
Simon's algorithm uses quantum parallelism to collect linearly independent bitstring samples, each orthogonal (in ) to a hidden string . The quantum part is finished once those samples are in hand; the final step is purely classical: solve a small linear system over the two-element field .
The constraint each sample imposes
After one query, Simon's circuit produces a uniformly random with the guarantee
where is addition mod 2 and the bit indices run from 0 (least significant) to . Equivalently, is orthogonal to over . Repeat the quantum circuit times (re-running until the samples are linearly independent) and you have a full set of equations.
Gaussian elimination over
The system with has a one-dimensional solution space when the oracle is balanced (i.e. ). Standard Gaussian elimination works unchanged except all arithmetic is mod 2: no fractions, just XOR.
For qubits the algorithm runs in time on a classical computer, so this post-processing adds no asymptotic cost to the overall exponential speedup over classical period finding.
A concrete 3-qubit example
Suppose and the hidden string is (decimal 5). The orthogonality condition becomes
so a measurement is valid only when bits 0 and 2 agree. After two independent quantum measurements we obtain, for instance:
| Sample (binary) | Decimal | Check: | |-----------------|---------|-------------------------------| | | 2 | ✓ | | | 7 | ✓ |
Substituting into the constraint gives . Substituting gives , i.e. . With the only solution is , confirming .
Try it
The starter code provides the two samples as integer bitvectors. Iterate over the non-zero candidates and return the unique that is orthogonal to every sample.
Sign in on the full site to ask questions and join the discussion.