Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Quantum information foundations

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.

Synthetic decision model

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.

The swap-test signal depends on state overlap. Overlap Tr(ρσ) versus Probability. Original ideal teaching calculation. Not measured hardware data.
Sweep the density-operator overlap Tr(ρσ) from 0 to 1 for the ideal SWAP test on independently prepared inputs. Original ideal teaching calculation. Not measured hardware data.

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.
  1. P(0) = [1 + Tr(rho sigma)]/2. Pure states: Tr(rho sigma)=|<psi|phi>|^2.
Reference example with separately scoped figure · synthetic calculated results
ReferencePrediction
Original declared exampleIdentical 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.
Separate figure table: Sweep the density-operator overlap Tr(ρσ) from 0 to 1 for the ideal SWAP test on independently prepared inputs.
Overlap Tr(ρσ)Auxiliary zero
00.5
0.120.56
0.250.625
0.370.685
0.50.75
0.620.81
0.750.875
0.870.935
11

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

Back to this lab in the catalog