= Swap test
{wiki}
The <swap test> estimates the overlap of two <pure states> without requiring their classical descriptions. Prepare an auxiliary <qubit> in $|0\rangle$, apply a <Hadamard gate>, a <Fredkin gate> controlled by that auxiliary <qubit>, and another <Hadamard gate>. Then measure the auxiliary <qubit> in the <computational basis>.
For target states $|a\rangle,|b\rangle$, the auxiliary-zero branch has unnormalized target vector $(|a\rangle|b\rangle+|b\rangle|a\rangle)/2$. Its squared <norm> is therefore
$$
p_0=\frac12\left(1+|\langle a|b\rangle|^2\right).
$$
Identical <pure states> give $p_0=1$, while <pure states> with zero <inner product> give $p_0=1/2$. A single zero outcome does not certify equality; repeated trials estimate the <probability>. The calculation is a direct projection onto the symmetric target subspace using the <SWAP gate>.
Back to article page