Physics

SWAP-Test State Overlap

Infer pure-state similarity from an ancilla while accounting for inconclusive outcomes.

By Riano · Published · Updated · Report a correction

SWAP-Test State Overlap

The SWAP test is a foundational quantum circuit used to estimate the overlap (inner product squared) between two unknown pure quantum states without fully characterizing them. It involves two input states, |ψa⟩ and |ψb⟩, and an ancilla qubit initialized to |0⟩. A controlled-SWAP (Fredkin) gate is applied, targeted on the two states and controlled by the ancilla (which is placed in a superposition).

Measuring overlap analytically

Consider two pure qubits |ψa⟩ = cos(θa/2)|0⟩ + sin(θa/2)|1⟩ and |ψb⟩ = cos(θb/2)|0⟩ + eiφsin(θb/2)|1⟩. Set θa = 90°, θb = 90°, and φ = 90°.

  1. The states are |ψa⟩ = 1/√2 |0⟩ + 1/√2 |1⟩ and |ψb⟩ = 1/√2 |0⟩ + i/√2 |1⟩.
  2. Their inner product ⟨ψa|ψb⟩ is (1/√2)(1/√2) + (1/√2)(i/√2) = 1/2 + i/2.
  3. The squared overlap |⟨ψa|ψb⟩|2 is (1/2)2 + (1/2)2 = 1/4 + 1/4 = 0.5.
  4. The probability of measuring the ancilla in state |0⟩ is P0 = (1 + |⟨ψa|ψb⟩|2) / 2 = (1 + 0.5) / 2 = 0.75.
  5. For m = 2 independent copies, the probability of obtaining all zeros is P02 = 0.752 = 0.5625.

Explore relative phases and orthogonality

Open the SWAP-Test State Overlap module to observe how relative angles impact the measurement outcome.

  1. Set First polar degrees to 90, Second polar degrees to 90, and Relative azimuth degrees to 90. The squared state overlap is 0.5 and the ancilla zero probability is 0.75.
  2. Change Relative azimuth degrees to 0. The vectors align identically, yielding an overlap of 1.0 and a definitive ancilla zero probability of 1.0. The test verifies they are the same state.
  3. Set First polar degrees to 0 and Second polar degrees to 180 (poles of the Bloch sphere). The states are orthogonal (|0⟩ and |1⟩), so the overlap is 0.0. The ancilla probability is 0.5, meaning the measurement yields random outcomes.
  4. Adjust Copies to observe how repeated measurements exponentially suppress the probability of an all-zero sequence when states are not identical.

Statistical certainty and generalizability

A single measurement of |0⟩ on the ancilla does not guarantee that the states are identical. It merely provides statistical evidence; complete certainty requires an infinite number of copies unless the states are known to be orthogonal. Additionally, the standard SWAP test analyzes the fidelity between pure states. Evaluating mixed states yields the trace of their product, which relates to but does not directly equal the Bures fidelity. Finally, the test does not reveal the actual quantum states or clone them, preserving the no-cloning theorem.

Primary sources and further reading

The SWAP test forms the basis of many quantum machine learning and fingerprinting protocols, allowing distance and similarity comparisons without fully extracting probability amplitudes.

  • Buhrman, H., Cleve, R., Watrous, J., & de Wolf, R. (2001). Quantum fingerprinting. Physical Review Letters, 87(16), 167902.arXiv:quant-ph/0102001. Explains the foundational controlled-SWAP circuit and its application to pure state comparison.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive SWAP-Test State Overlap module.

Try SWAP-Test State Overlap on Riano →

More in Physics