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

All sections

Saved
Skip Learn navigation
Encyclopedia
Explainer

A quantum program can compare two states without reading out both

Even identical mixed states can produce either ancilla outcome in a swap test. The measured overlap of two identical mixed inputs equals their purity. In machine-learning applications, the cost of preparing both input states still belongs in the comparison.

Edition released Coverage: Overview · Technical · Research
On this page

Explanation

Suppose a laboratory can prepare two quantum states but does not have a full classical description of either one. A comparison can still be possible. The swap test uses a controlled interchange and an auxiliary qubit to make the similarity of the two preparations affect a measurable probability. It does not print both states and compare their entries. It asks a narrower question that can be useful in its own right. This distinction is a good antidote to the idea that a quantum calculation must return every detail of its internal state to accomplish something meaningful.

For pure inputs, the probability of one auxiliary outcome is one half times one plus the squared magnitude of the states' overlap. Identical states give that outcome with certainty, while orthogonal states give it with probability one half. Many preparations are required to estimate the probability. For mixed inputs, the same circuit instead accesses the Hilbert-Schmidt overlap, the trace of their matrix product. That quantity is not interchangeable with every definition of state fidelity. In particular, two identical mixed states need not make the auxiliary outcome deterministic. The input class and the similarity measure therefore need to appear together when the test is described.

Compare identical pure states, orthogonal pure states and the same maximally mixed state prepared twice. Their different auxiliary-outcome probabilities expose exactly what the test measures. An application also pays to prepare both inputs and implement the controlled operation. A similarity estimator can be useful without establishing an end-to-end advantage for a machine-learning task. The practical question is whether the overlap is the quantity the application needs and whether the full preparation-and-measurement workflow is competitive at the required precision. That assessment is separate from the ideal identity.

Suppose two laboratories prepare what they describe as the same mixed state and a swap-test experiment returns ancilla zero less than every time. It is tempting to conclude that the preparations must differ. The maximally mixed example shows why that conclusion is premature: even identical mixed density matrices can produce a probability below one under this test.

For independent inputs, the relevant overlap is Tr(rho sigma). With equal mixed inputs it becomes purity. To interpret an observed score, identify whether the intended comparison concerns pure-state overlap, mixed-state fidelity, preparation purity or another quantity. Those concepts can agree in special cases without being interchangeable in general. Also preserve the independence assumption: the product-input derivation cannot simply be applied to an arbitrary correlated joint preparation. A useful similarity story begins with the mathematical quantity the circuit measures, then explains how that quantity answers the application's actual question.

Declared model

The swap-test signal depends on state overlap

Inputs and assumptions

Sweep the density-operator overlap Tr(ρσ) from 0 to 1 for the ideal SWAP test on independently prepared inputs.

Mathematical expression

P(auxiliary zero)=[1+Tr(ρσ)]/2. For mixed inputs this overlap is not generally the squared Uhlmann fidelity.

Worked interpretation

Preserved calculated values — synthetic model
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

Model boundaries

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.

Original ideal teaching calculation. Not measured hardware data.

Misconception and correction

Misconception: The overlap of two encoded states automatically measures the classical similarity the application needs.

Correction: Similarity of encoded states is not automatically similarity under the classical metric a user wanted. Encoding, normalization and the chosen observable define the relationship.

Worked derivation

For pure inputs |ψ> and |φ>, interference between swapped and unswapped branches produces p(0)=[1+|<ψ|φ>|²]/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.

Identical pure states give p(0)=1; orthogonal pure states give one half. Identical maximally mixed qubit states give three quarters.

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.

Additional scientific distinctions

The swap test estimates p(0)=(1+Tr(rho sigma))/2 when its two independently prepared inputs are rho and sigma. An ideal probability 0.82 implies Tr(rho sigma)=2(0.82)-1=0.64. This number does not identify either state, since many state pairs have the same Hilbert–Schmidt overlap. A sampled frequency has statistical uncertainty, and its linear conversion multiplies an absolute probability uncertainty by two.

For pure inputs, Tr(rho sigma) is the squared overlap and agrees with the squared-fidelity convention. For mixed inputs it is generally not Uhlmann fidelity. For example, rho=sigma=I/2 gives overlap 1/2 while the fidelity of a state with itself is one. The circuit also requires supplying both inputs repeatedly. State preparation, accepted-trial frequency and controlled-swap implementation remain part of a complete application assessment.

Sources