encyclopegia.org

Swap test

The swap test is a procedure in quantum computation that is used to check how much two quantum states differ, appearing first in the work of Barenco et al.[src] and later rediscovered by Harry Buhrman, Richard Cleve, John Watrous, and Ronald de Wolf.[src] It appears commonly in quantum machine learning, and is a circuit used for proofs-of-concept in implementations of quantum computers.[src] Formally, the swap test takes two input states |\phi\rangle and |\psi\rangle and outputs a Bernoulli random variable that is 1 with probability \textstyle\frac{1}{2} - \frac{1}{2} ^2 (where the expressions here use bra–ket notation).[src] This allows one to, for example, estimate the squared inner product between the two states, ^2 , to \varepsilon additive error by taking the average over O(\textstyle\frac{1}{\varepsilon^2}) runs of the swap test.[src] This requires O(\textstyle\frac{1}{\varepsilon^2}) copies of the input states.[src] The squared inner product roughly measures "overlap" between the two states, and can be used in linear-algebraic applications, including clustering quantum states.[src]

The swap test is a procedure in quantum computation that is used to check how much two quantum states differ, appearing first in the work of Barenco et al.[src] and later rediscovered by Harry Buhrman, Richard Cleve, John Watrous, and Ronald de Wolf.[src] It appears commonly in quantum machine learning, and is a circuit used for proofs-of-concept in implementations of quantum computers.[src] Formally, the swap test takes two input states |\phi\rangle and |\psi\rangle and outputs a Bernoulli random variable that is 1 with probability \textstyle\frac{1}{2} - \frac{1}{2} ^2 (where the expressions here use bra–ket notation).[src] This allows one to, for example, estimate the squared inner product between the two states, ^2 , to \varepsilon additive error by taking the average over O(\textstyle\frac{1}{\varepsilon^2}) runs of the swap test.[src] This requires O(\textstyle\frac{1}{\varepsilon^2}) copies of the input states.[src] The squared inner product roughly measures "overlap" between the two states, and can be used in linear-algebraic applications, including clustering quantum states.[src] ==Explanation of the circuit== Consider two states: |\phi\rangle and |\psi\rangle .[src] The state of the system at the beginning of the protocol is |0, \phi, \psi\rangle .[src] After the Hadamard gate, the state of the system is \frac{1}{\sqrt{2}}(|0, \phi, \psi\rangle + |1, \phi, \psi\rangle) .[src] The controlled SWAP gate transforms the state into \frac{1}{\sqrt{2}}(|0, \phi, \psi\rangle + |1, \psi, \phi\rangle) .[src] The second Hadamard gate results in \frac{1}{2}(|0, \phi, \psi\rangle + |1, \phi, \psi\rangle + |0, \psi, \phi\rangle - |1, \psi, \phi\rangle) = \frac{1}{2}|0\rangle(|\phi, \psi\rangle + |\psi, \phi\rangle) + \frac{1}{2}|1\rangle(|\phi, \psi\rangle - |\psi, \phi\rangle) The measurement gate on the first qubit ensures that it's 0 with a probability of P(\text{First qubit} = 0) = \frac{1}{2} \Big( \langle \phi | \langle \psi | + \langle \psi | \langle \phi | \Big) \frac{1}{2} \Big( | \phi \rangle | \psi \rangle + | \psi \rangle | \phi \rangle \Big) = \frac{1}{2} + \frac{1}{2} ^2 when measured.[src] If \psi and \phi are orthogonal ( ^2 = 0) , then the probability that 0 is measured is \frac{1}{2} .[src] If the states are equal ( ^2 = 1) , then the probability that 0 is measured is 1.[src] In general, for P trials of the swap test using P copies of |\phi\rangle and P copies of |\psi\rangle , the fraction of measurements that are zero is 1 - \textstyle\frac{1}{P} \textstyle\sum_{i = 1}^{P} M_i , so by taking P \rightarrow \infty , one can get arbitrary precision of this value.[src] Below is the pseudocode for estimating the value of |\langle \psi | \phi \rangle |^2 using P copies of |\psi\rangle and |\phi\rangle : Inputs P copies each of the n qubits quantum states |\psi\rangle and |\phi\rangle Output An estimate of |\langle \psi | \phi \rangle |^2 for j ranging from 1 to P: initialize an ancilla qubit A in state |0\rangle apply a Hadamard gate to the ancilla qubit A for i ranging from 1 to n: apply CSWAP to \psi_i and \phi_i (the ith qubit of the jth copy of |\psi\rangle and |\phi\rangle ), with A as the control qubit apply a Hadamard gate to the ancilla qubit A measure A in the Z basis and record the measurement M j as either a 0 or 1 compute s = 1 - \textstyle\frac{2}{P} \textstyle\sum_{i = 1}^{P} M_i .[src] return s as our estimate of |\langle \psi | \phi \rangle |^2 ==See also== Hadamard test ==References==[src]

24 sentences · 24 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Swap test." encyclopegia.org, 2026, https://encyclopegia.org/wiki/swap-test. Accessed 02 December 2026.

Chicago

"Swap test." encyclopegia.org. Accessed December 2, 2026. https://encyclopegia.org/wiki/swap-test.

APA

encyclopegia.org. (2026). Swap test. Retrieved December 2, 2026, from https://encyclopegia.org/wiki/swap-test

Accessed December 2, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1373018416 · 0.5 · snapshot enwiki-001373018416

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.