The swap test
Estimate the squared overlap of two pure quantum states with an interference experiment.
- Relate ancilla statistics to pure-state overlap.
- Work an overlap calculation from the three-wire circuit.
- Explain how the interpretation changes for mixed states.
Before you begin: Tensor products, controlled gates, inner products and repeated measurements.
Compare states through interference
Section titled “Compare states through interference”Suppose two programs prepare states and . We want to know how similar the preparations are without first reconstructing every amplitude. The swap test estimates their squared overlap,
For normalised pure states, lies between zero and one. It equals one when the states differ only by an overall phase, and zero for orthogonal states. Each test consumes fresh preparations, so the ability to repeatedly prepare both states is part of the input model.
Draw the three-register experiment
Section titled “Draw the three-register experiment”Use one ancilla and two equal-size target registers. Prepare the ancilla in , apply , apply a controlled-SWAP between the targets, apply another to the ancilla and measure it. The controlled-SWAP exchanges the target registers only in the ancilla’s 1 branch.
Before the last , the joint state is
The two routes interfere when the final recombines them. Their overlap is
Consequently,
The probability of zero ranges from one half to one. Even two orthogonal states produce zero half of the time. One zero outcome therefore gives weak evidence by itself; repeated trials supply the estimate.
The controlled-SWAP appears as a control dot joined to two crossed symbols. The plot uses and . Its minimum probability is one half, making the baseline visible.
Checkpoint. Orthogonal inputs give . Does that mean they overlap halfway? No. The zero-probability formula has a one-half baseline; subtract it before interpreting the overlap.
Worked example: a sixty-degree rotation
Section titled “Worked example: a sixty-degree rotation”Take
Their inner product is , its squared magnitude is , and the ancilla’s zero probability is . If a run of 800 tests gives 500 zeros, then
This is an illustrative record consistent with the ideal value. Its approximate standard error is . Sampling error concerns uncertainty about the observed circuit’s statistics; noise in preparation, SWAP operations or readout can change those statistics.
Explore the meaning of “same”
Section titled “Explore the meaning of “same””Freely vary in the plotted family and inspect both and . Then compare with . Both states give 50/50 in the Z basis, but their overlap is zero, so the ideal swap test gives ancilla zero half the time. A single fixed-basis histogram can therefore miss a large state difference.
Next compare with . The test gives zero with certainty because an overall phase describes the same physical pure state. Compare that with changing only one component’s sign: the resulting relative phase can change the overlap and the measured result.
For separate mixed-state inputs and , the same experiment measures
This quantity is the Hilbert–Schmidt overlap. It is generally different from the usual mixed-state fidelity. For example, two identical maximally mixed qubits have and , so the test gives , even though the input density matrices are identical. That example clarifies why the pure-state assumption matters.
Exercises
Section titled “Exercises”-
For inputs and , find and .
-
With orthogonal pure inputs, what is the chance of ten independent zero outcomes?
-
What resources grow with register size?
Worked answers
-
and .
-
. A string of zeros supports a similarity claim statistically; finite data do not prove equality.
-
both prepared registers and the controlled register swap, which expands into multiple physical gates and may require routing.
Check your understanding
Section titled “Check your understanding”A swap test has ideal P(0)=0.9 for pure inputs. What is their squared overlap?
Answer: 0.8. F=2(0.9)-1.
The swap test compares preparations by interfering the unchanged and exchanged register orders. Always state the input-state assumption and translate the ancilla probability into the intended overlap.
Sources
Section titled “Sources”Buhrman, Cleve, Watrous and de Wolf, quantum fingerprinting and the comparison test; Aharonov, Jones and Landau, ancilla interference framework. The examples, mixed-state calculation and plot data above are original.
Ready for the next step?
Your progress stays in this browser.