What does the swap test reveal and what does it leave unknown?
A swap test compares states, not arbitrary datasets for free
Source research checked . Teaching calculations are ideal models.
Prepare two independent registers with states ρ and σ and one auxiliary qubit. The ideal swap test applies a Hadamard, a controlled swap and another Hadamard to the auxiliary qubit. Its zero probability contains the overlap Tr(ρσ). State preparation and controlled-swap implementation remain resources of the experiment.
The mixed-state example is especially useful: two identical density matrices do not necessarily yield a zero outcome every time. For equal mixed inputs, the swap-test overlap equals purity. A good article explains which property is being estimated and keeps preparation cost visible when discussing machine-learning applications.
Figure and table scope: Sweep the density-operator overlap Tr(ρσ) from 0 to 1 for the ideal SWAP test on independently prepared inputs.
Derivation step 1: For pure inputs |ψ> and |φ>, interference between swapped and unswapped branches produces p(0)=[1+|<ψ|φ>|²]/2.
Derivation step 2: Linearity extends the expression to mixed states as p(0)=[1+Tr(ρσ)]/2. The overlap is not automatically the same quantity as every convention called fidelity.
Derivation step 3: Identical pure states give p(0)=1; orthogonal pure states give one half. Identical maximally mixed qubit states give three quarters.
Derivation step 4: A measured fraction estimates p(0) over repeated independently prepared input pairs. It does not reveal the complete input state or all entries of a classical dataset.
Separate challenge: The observed ideal zero probability is 0.82. What overlap does the formula imply? Does that single number identify either input state?
Worked challenge answer: Tr(ρσ)=2×0.82-1=0.64. Many pairs of states share that overlap, so it does not identify either state. Statistical uncertainty in an observed frequency would propagate through the same linear transformation.
Start with the assumptions
- Ideal controlled-SWAP circuit and independently supplied input copies. The pure-state comparison is supported by the primary quantum-fingerprinting paper; the mixed-state identity is derived directly in the calculation bank.
P(auxiliary zero)=[1+Tr(ρσ)]/2. For mixed inputs this overlap is not generally the squared Uhlmann fidelity.

Compare the input regimes
Each case uses invented inputs. The results follow from this model and do not describe measured hardware.
Reference example with separately scoped figure
Complete inputs
- reference scenario
- Compare pure identical inputs, pure orthogonal inputs and two maximally mixed qubits.
- separate figure scope
- Sweep the density-operator overlap Tr(ρσ) from 0 to 1 for the ideal SWAP test on independently prepared inputs.
- P(0) = [1 + Tr(rho sigma)]/2. Pure states: Tr(rho sigma)=|<psi|phi>|^2.
| Reference | Prediction |
|---|---|
| Original declared example | Identical pure: P(0)=1. Orthogonal pure: P(0)=1/2. Identical maximally mixed qubits: Tr[(I/2)^2]=1/2, so P(0)=3/4. |
| Overlap Tr(ρσ) | Auxiliary zero |
|---|---|
| 0 | 0.5 |
| 0.12 | 0.56 |
| 0.25 | 0.625 |
| 0.37 | 0.685 |
| 0.5 | 0.75 |
| 0.62 | 0.81 |
| 0.75 | 0.875 |
| 0.87 | 0.935 |
| 1 | 1 |
The declared reference example predicts: Identical pure: P(0)=1. Orthogonal pure: P(0)=1/2. Identical maximally mixed qubits: Tr[(I/2)^2]=1/2, so P(0)=3/4.
Try the reasoning: The observed ideal zero probability is 0.82. What overlap does the formula imply? Does that single number identify either input state?
Sources and model boundaries
- IBM Quantum Learning: formulations of measurements ↗
Primary scientific context for an original ideal teaching example. Source research checked 19 October 2026; site integration inspected 20 October 2026. These are different checks.
- Buhrman, Cleve, Watrous and de Wolf: Quantum fingerprinting ↗
Primary scientific context for an original ideal teaching example. Source research checked 19 October 2026; site integration inspected 20 October 2026. These are different checks.