Math
Grover's search
Explore amplitude amplification in an unstructured search. A phase oracle changes the sign of the marked amplitude without changing probabilities in the computational basis. The diffusion step turns relative phase into a higher success probability. Too many iterations reduce that probability again.

What happens
The phase oracle marks a candidate by changing its relative phase. Measuring immediately in the computational basis gives the same probabilities as before the oracle; this does not make relative phase unobservable in every measurement basis. Interference in the diffusion step converts the phase mark into amplitude amplification.
One Grover iteration consists of the oracle and diffusion. The success probability oscillates rather than converging: stop near the first maximum, then compare with later iterations. The query count scales with the square root of the search-space size for a single marked item; constructing the oracle and preparing data also have costs. The module shows an ideal state-vector simulation, exact rational amplitudes for its selected sizes, and reproducible sampled measurement counts.
Equations used in the module
Equations sin θ = 1/√N; after k turns the marked amplitude is sin((2k+1)θ) and the chance is its square one turn = one oracle call (a minus sign on the marked amplitude) + one reflection about the mean: a -> 2·mean − a optimal number of turns k* = floor(π/4·√N) = 3, 6, 12, 25 for N = 16, 64, 256, 1024; a blind search averages (N + 1)/2 = 8.5, 32.5, 128.5, 512.5 for N = 4^m the amplitude is an exact FRACTION, by the integer recursion u(k+1) = (2q² − 4)·u(k) − q⁴·u(k−1) with q = 2^(n/2), sin((2k+1)θ) = u(k)/q^(2k+1) sixteen items: 1/4, 11/16, 61/64, 251/256 (k* = 3), 781/1024, 1451/4096, −2339/16384 (k = 6, chance 0.0204 - worse than the 0.0625 it started at), … , 2269261/67108864 (k = 12) sixty-four items after six turns: 133988401/134217728 = 0.99829138070344925, which the register reproduces to the last bit measured against counted: 2000 runs at k* give 1913, 1994, 2000, 2000 hits for N = 16, 64, 256, 1024 - each inside three sigma of the exact chance


