Fredkin Gate

The Fredkin gate is the moment a piece of classical wiring becomes a statement about physics. Written as the controlled-SWAP, it takes three qubits — one control, two targets — and obeys a single rule that a plumber would recognize: if the control reads 11, exchange the two target wires; if it reads 00, leave them be. On the eight computational basis states this is nothing but a permutation, and a stingy one at that: of the eight labels only ∣101⟩|101\rangle and ∣110⟩|110\rangle trade places, the other six sit perfectly still. A classical engineer would see a reversible routing switch and move on. What stops them is that the gate quietly obeys two conservation laws at once. It is reversible — as a permutation it is its own inverse, F2=IF^2=I, so no information is ever destroyed — and it is conservative: the number of 11s in the output equals the number in the input for every basis state, because swapping bits never creates or annihilates a 11. Edward Fredkin and Tommaso Toffoli built this second property into their 1982 billiard-ball model of computation, in which logic is done by elastic collisions of indestructible balls, tying Boolean algebra to the thermodynamics of a frictionless world. And yet, hemmed in by both constraints, the gate is still universal: pin an ancilla to a constant and it computes AND, NOT, and fan-out, enough to build any Boolean circuit. Turn it loose on a superposed control and the "if" is no longer resolved but written into a correlation — a coherent maybe-swap that is exactly the engine of the SWAP test, the standard circuit for asking how alike two unknown quantum states are.

Key takeaways
  • The Fredkin gate is the controlled-SWAP (CSWAP): a three-qubit gate that exchanges its two target qubits when the control is ∣1⟩|1\rangle and leaves them untouched when the control is ∣0⟩|0\rangle, i.e. ∣c,a,b⟩↦∣c, a⊕c(a⊕b), b⊕c(a⊕b)⟩|c,a,b\rangle\mapsto|c,\,a\oplus c(a\oplus b),\,b\oplus c(a\oplus b)\rangle.
  • As an 8×88\times8 permutation it moves only ∣101⟩↔∣110⟩|101\rangle\leftrightarrow|110\rangle and fixes the other six basis states, so it is real, symmetric, unitary, and its own inverse: F†=FF^\dagger=F, F2=IF^2=I.
  • It is conservative — it preserves the Hamming weight of every input — the canonical model of dissipationless reversible logic, and with a constant ancilla it is universal for classical reversible computation (AND, NOT, fan-out).
  • On a superposed control it becomes a coherent maybe-swap, F(α∣0⟩+β∣1⟩)∣ψ⟩∣ϕ⟩=α∣0⟩∣ψ⟩∣ϕ⟩+β∣1⟩∣ϕ⟩∣ψ⟩F(\alpha|0\rangle+\beta|1\rangle)|\psi\rangle|\phi\rangle=\alpha|0\rangle|\psi\rangle|\phi\rangle+\beta|1\rangle|\phi\rangle|\psi\rangle, generically entangling the control with target order.
  • Sandwiched between Hadamards it runs the SWAP test, reading the overlap of two states from P(control=0)=12(1+∣⟨ψ∣ϕ⟩∣2)P(\text{control}=0)=\tfrac12(1+|\langle\psi|\phi\rangle|^2) — a primitive of fidelity estimation and quantum machine learning.
  • Key idea: the Fredkin gate is a SWAP switched on by a control qubit — one conservative, reversible, self-inverse gate that is universal for classical logic and, acting coherently on superpositions, powers the SWAP test.
The core insight

The Fredkin gate is a SWAP switched on by a control qubit: it conditionally exchanges two wires, giving a single conservative, self-inverse, reversible gate that is universal for classical logic and acts coherently on superpositions to compare two quantum states.

Where this lives today

The Fredkin gate's afterlife is almost entirely the SWAP test, now a workhorse primitive across quantum information. Because P(control=0)=12(1+∣⟨ψ∣ϕ⟩∣2)P(\text{control}=0)=\tfrac12(1+|\langle\psi|\phi\rangle|^2) turns an inner product into a measurable frequency, it is the standard way to estimate state fidelity against a target, to detect entanglement (a controlled-SWAP between two copies of a state estimates the purity Tr(ρ2)\mathrm{Tr}(\rho^2)), and to compute kernels in quantum machine learning, where the similarity of two data-encoded states is exactly what a support-vector or clustering algorithm needs. Variational algorithms lean on it for cost-function evaluation, and destructive "Bell-basis" variants trade the controlled-SWAP for local measurements to save the expensive control qubit. On real hardware the gate is costly: compiled as one Toffoli plus two CNOTs it carries a TT-count of seven, so a SWAP test on nn-qubit registers needs nn controlled-SWAPs and on the order of 7n7n distilled magic states in a surface-code machine — which is why cutting controlled-SWAP TT-count is an active compilation problem. Direct realizations exist too: in 2016 a Griffith University group implemented a photonic quantum Fredkin gate acting on single-photon polarization without decomposing it into two-qubit gates, and controlled-SWAPs have since run on trapped-ion and superconducting platforms. The conservative-logic thread lives on in reversible-computing research, where the promise Fredkin and Toffoli made — computation approaching Landauer's zero-dissipation limit — remains a target for ultra-low-power logic.

The physical picture

Read the Fredkin gate first as a railroad switch and it is disappointingly tame. Two signal tracks run across the page and a third track, the control, throws the switch: control off, the signals pass straight through on their own rails; control on, the two are cross-connected and swap rails. Nothing is ever lost — a signal is only rerouted — which is the conservation property drawn in metal. Because a swap can only move a 11 from one wire to another, the gate can never change how many 11s are present, so it shuffles the eight basis states only within fixed Hamming-weight sectors. The weight-0 state ∣000⟩|000\rangle, the three weight-1 states, and ∣111⟩|111\rangle have nowhere to go, and among the three weight-2 states the only pair the control-on swap can exchange is ∣101⟩|101\rangle and ∣110⟩|110\rangle. The whole gate is that one transposition, and the first figure draws it honestly, the two moved labels flagged in red.

Figure
The Fredkin gate as a controlled routing switch and a basis-state permutation: the control dot with two × marks sends c,a,b to c, a⊕c(a⊕b), b⊕c(a⊕b), fixing six of the eight labels while exchanging only 101 ↔ 110 — a single transposition, so F is unitary and squares to the identity
Fredkin = controlled-SWAP: swap the targets iff the control is 1 control |c⟩ target |a⟩ target |b⟩ |c⟩ |a⊕c(a⊕b)⟩ |b⊕c(a⊕b)⟩ circuit symbol action on the eight basis states |000⟩|000⟩ |001⟩|001⟩ |010⟩|010⟩ |011⟩|011⟩ |100⟩|100⟩ |101⟩|110⟩ |110⟩|101⟩ |111⟩|111⟩ control 0 → six states fixed · control 1 → swap the two targets only 101 ↔ 110 exchanged, so F² = I and Hamming weight is conserved

Now hand the same gate a control in superposition and the switch stops choosing. Because FF is linear, a control spread across ∣0⟩|0\rangle and ∣1⟩|1\rangle is not read and resolved — both branches are written at once, and the gate ties whether-the-targets-were-swapped to the control's amplitude pattern. This is the coherent maybe-swap, and it is the whole reason the Fredkin gate matters to quantum information rather than only to reversible-logic theory. Put the control in ∣+⟩|+\rangle, load the two targets with unknown states ∣ψ⟩|\psi\rangle and ∣ϕ⟩|\phi\rangle, and the branch that swapped and the branch that did not now carry different target states — unless ∣ψ⟩=∣ϕ⟩|\psi\rangle=|\phi\rangle. A final Hadamard on the control makes those two branches interfere, and the probability of reading the control as 00 turns out to measure exactly how alike the two states are. The second figure is that circuit, the SWAP test, with the interference made numerical.

Figure
The SWAP test with real numbers: a control qubit is Hadamarded, controls a Fredkin swap of the two target states ψ and φ, and is Hadamarded again, giving P(control = 0) = ½(1 + squared overlap) — 0.5 for orthogonal states, 0.75 for the half-overlap pair 0 and + , and 1.0 for identical states
The SWAP test: P(control = 0) = ½(1 + |⟨ψ|φ⟩|²) reads the overlap H H |0⟩ |ψ⟩ |φ⟩ controlled-SWAP 0.5 0.75 1.0 0.50 0.75 1.00 orthogonal |⟨ψ|φ⟩|²=0 |0⟩ and |+⟩ |⟨ψ|φ⟩|²=½ identical |⟨ψ|φ⟩|²=1 P(control = 0) vs overlap

Two facts finish the picture. First, the target labels aa and bb are interchangeable — the gate is symmetric under swapping which target is which. Second, entanglement is not automatic: feed the gate a control already in a definite basis state, or identical targets ∣ψ⟩∣ψ⟩|\psi\rangle|\psi\rangle (which SWAP leaves alone), and the output is a plain product state. The gate earns its quantum keep only when the control carries a genuine superposition and the two targets differ, so that the swapped and unswapped branches point somewhere distinguishable.

The core equations

The most compact definition is a single line of modulo-2 arithmetic on the three bits, the reversible logic that names the gate. Everything below is a consequence of this rule plus linearity.

F ∣c,a,b⟩=∣c,  a⊕c(a⊕b),  b⊕c(a⊕b)⟩(1)F\,|c,a,b\rangle = |c,\; a\oplus c(a\oplus b),\; b\oplus c(a\oplus b)\rangle \qquad (1)

where: cc — control bit, c∈{0,1}c\in\{0,1\}; a,ba,b — the two target bits; ⊕\oplus — addition modulo 22 (XOR); c(a⊕b)c(a\oplus b) — logical AND of cc with a⊕ba\oplus b. The reading: the control passes through untouched, and each target is XORed with the quantity c(a⊕b)c(a\oplus b), which is nonzero only when the control is on and the targets differ — precisely the condition under which a swap changes anything. Evaluating the two control cases collapses the formula to a conditional swap, which is worth writing on its own because it is how the gate is used in practice.

F ∣0,a,b⟩=∣0,a,b⟩,F ∣1,a,b⟩=∣1,b,a⟩(2)F\,|0,a,b\rangle=|0,a,b\rangle,\qquad F\,|1,a,b\rangle=|1,b,a\rangle \qquad (2)

where: the c=0c=0 branch is the identity on the targets (a⊕0=aa\oplus0=a); the c=1c=1 branch exchanges them, since a⊕(a⊕b)=ba\oplus(a\oplus b)=b and b⊕(a⊕b)=ab\oplus(a\oplus b)=a. The reading: FF is the controlled-SWAP — off means pass-through, on means exchange. Made concrete as an operator on the eight-dimensional space, in the ordered basis ∣cab⟩=000,001,…,111|cab\rangle=000,001,\dots,111 with cc the most significant bit, the gate is a permutation matrix built from a 6×66\times6 identity and one 2×22\times2 swap block.

F=(1000000001000000001000000001000000001000000000100000010000000001)(3)F=\begin{pmatrix}1&0&0&0&0&0&0&0\\0&1&0&0&0&0&0&0\\0&0&1&0&0&0&0&0\\0&0&0&1&0&0&0&0\\0&0&0&0&1&0&0&0\\0&0&0&0&0&0&1&0\\0&0&0&0&0&1&0&0\\0&0&0&0&0&0&0&1\end{pmatrix} \qquad (3)

where: the only off-diagonal entries sit at indices 55 and 66, exchanging ∣101⟩↔∣110⟩|101\rangle\leftrightarrow|110\rangle. The reading: every row and column has a single 11, so the matrix merely relabels basis states and is automatically unitary; six labels map to themselves and one pair is transposed. Because that matrix is real and symmetric, it is at once Hermitian and unitary, which forces it to be its own inverse — the algebraic face of "swapping the same pair twice does nothing" — and its bit-permuting action makes the conservation law exact.

F†=F,F2=I,∑i(out)i=∑i(in)i(4)F^\dagger=F,\qquad F^2=I,\qquad \textstyle\sum_i(\text{out})_i=\sum_i(\text{in})_i \qquad (4)

where: F†F^\dagger — conjugate transpose (adjoint); II — the 8×88\times8 identity; (in)i,(out)i(\text{in})_i,(\text{out})_i — the ii-th input and output bits. The reading: self-adjointness plus unitarity collapse to F2=IF^2=I, and the Hamming weight (number of 11s) is unchanged because a swap moves a 11 without creating or destroying it. Lifting the conditional swap off the basis states gives the controlled-UU form that places the Fredkin gate in the general controlled-gate family, here with U=SWAPU=\mathrm{SWAP}.

F=∣0⟩⟨0∣⊗I4  +  ∣1⟩⟨1∣⊗SWAP(5)F = |0\rangle\langle0|\otimes I_4 \;+\; |1\rangle\langle1|\otimes \mathrm{SWAP} \qquad (5)

where: ∣0⟩⟨0∣, ∣1⟩⟨1∣|0\rangle\langle0|,\,|1\rangle\langle1| — orthogonal projectors on the control; I4I_4 — identity on the two-target space; SWAP\mathrm{SWAP} — the two-qubit exchange, itself CNOTa→b CNOTb→a CNOTa→b\mathrm{CNOT}_{a\to b}\,\mathrm{CNOT}_{b\to a}\,\mathrm{CNOT}_{a\to b}. The reading: the ∣0⟩|0\rangle branch applies the identity and the ∣1⟩|1\rangle branch applies SWAP, and because the projectors are orthogonal the two branches never interfere — replacing SWAP by any two-qubit UU gives a general controlled-UU. Since hardware exposes only one- and two-qubit gates, the Fredkin gate is compiled down; the standard identity conjugates a Toffoli (controlled-controlled-NOT) by two CNOTs, and is the route by which its non-Clifford cost is counted.

F=CNOTb→a  Toffolic,a→b  CNOTb→a(6)F = \mathrm{CNOT}_{b\to a}\;\mathrm{Toffoli}_{c,a\to b}\;\mathrm{CNOT}_{b\to a} \qquad (6)

where: CNOTb→a\mathrm{CNOT}_{b\to a} — CNOT with control bb, target aa; Toffolic,a→b\mathrm{Toffoli}_{c,a\to b} — controlled-controlled-NOT with controls c,ac,a and target bb. The reading: the two CNOTs are Clifford (cheap), so the gate's fault-tolerant cost is carried entirely by the Toffoli, and Derivation A tracks a basis state through the three layers to prove the identity. Finally, the quantum application that makes the gate famous: on a superposed control the Fredkin gate is a coherent maybe-swap, and inside the SWAP test its interference reads out the overlap of two states.

P(control=0)=12(1+∣⟨ψ∣ϕ⟩∣2)(7)P(\text{control}=0)=\tfrac12\big(1+|\langle\psi|\phi\rangle|^2\big) \qquad (7)

where: ∣ψ⟩,∣ϕ⟩|\psi\rangle,|\phi\rangle — the two states loaded into the targets; the control begins in ∣0⟩|0\rangle and is Hadamarded before and after FF. The reading: orthogonal states give P=12P=\tfrac12 (a coin flip), identical states give P=1P=1 (never fails), and the value in between estimates ∣⟨ψ∣ϕ⟩∣2|\langle\psi|\phi\rangle|^2 — derived in full in Derivation C.

Derivation AWhy conjugating a Toffoli by two CNOTs is a controlled-SWAP

The goal is to prove the compilation identity F=CNOTb→a Toffolic,a→b CNOTb→aF=\mathrm{CNOT}_{b\to a}\,\mathrm{Toffoli}_{c,a\to b}\,\mathrm{CNOT}_{b\to a} by tracking an arbitrary computational-basis state ∣c,a,b⟩|c,a,b\rangle through the three layers and showing it emerges as the Fredkin output ∣c, a⊕c(a⊕b), b⊕c(a⊕b)⟩|c,\,a\oplus c(a\oplus b),\,b\oplus c(a\oplus b)\rangle, then invoking linearity to extend the equality to every superposition. This is the identity a compiler actually uses to turn an abstract Fredkin gate into hardware primitives, and it is why the gate's expensive non-Clifford content is exactly that of a single Toffoli.

Step 1. Apply the first CNOTb→a\mathrm{CNOT}_{b\to a} (control bb, target aa): the target picks up the XOR of the two bits, ∣c,a,b⟩↦∣c, a⊕b, b⟩|c,a,b\rangle\mapsto|c,\,a\oplus b,\,b\rangle. Write a′=a⊕ba'=a\oplus b for the new middle bit. Why: this pre-processing loads the difference of the two targets onto one wire, so the Toffoli that follows can flip the other target conditioned on whether the targets differ.

Step 2. Apply Toffolic,a→b\mathrm{Toffoli}_{c,a\to b} (controls cc and the current middle bit a′a', target bb): the target bb flips by the AND of the two controls, ∣c,a′,b⟩↦∣c, a′, b⊕(c a′)⟩=∣c, a′, b⊕c(a⊕b)⟩|c,a',b\rangle\mapsto|c,\,a',\,b\oplus(c\,a')\rangle=|c,\,a',\,b\oplus c(a\oplus b)\rangle. Call the new bottom bit b′′=b⊕c(a⊕b)b''=b\oplus c(a\oplus b). Why: this is where the conditional logic happens — the target only changes when the control is on and the two targets were unequal, which is exactly the swap condition.

Step 3. Apply the last CNOTb→a\mathrm{CNOT}_{b\to a} (control bb, now holding b′′b'', target aa, now holding a′a'): the middle bit becomes a′⊕b′′=(a⊕b)⊕(b⊕c(a⊕b))=a⊕c(a⊕b)a'\oplus b''=(a\oplus b)\oplus\big(b\oplus c(a\oplus b)\big)=a\oplus c(a\oplus b), using b⊕b=0b\oplus b=0. The state is now ∣c, a⊕c(a⊕b), b⊕c(a⊕b)⟩|c,\,a\oplus c(a\oplus b),\,b\oplus c(a\oplus b)\rangle, precisely F∣c,a,b⟩F|c,a,b\rangle. Since this holds on all eight basis states, unitary linearity extends it to every input. Why: the self-inverse property of XOR, b⊕b=0b\oplus b=0, cleanly strips the difference bit back off the middle wire, leaving both targets carrying the correct conditionally-swapped values. *Direct 8×88\times8 matrix multiplication of the three factors reproduces the permutation of equation (3), exchanging only ∣101⟩↔∣110⟩|101\rangle\leftrightarrow|110\rangle.*

Go deeper · Derivation B · 1 minThe coherent maybe-swap and the entanglement it makes
Derivation BThe coherent maybe-swap and the entanglement it makes

The aim is to apply the unitary Fredkin gate to a control held in a genuine superposition and show that the output is, in general, an entangled state that correlates the control's value with the order of the two target states — the coherent maybe-swap that separates the quantum Fredkin gate from its classical reading. We use the controlled-UU form of equation (5), act branch by branch, and then check exactly when the correlation collapses back to a product state.

Step 1. Write the control as α∣0⟩+β∣1⟩\alpha|0\rangle+\beta|1\rangle with the targets loaded as ∣ψ⟩∣ϕ⟩|\psi\rangle|\phi\rangle, and expand F=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗SWAPF=|0\rangle\langle0|\otimes I+|1\rangle\langle1|\otimes\mathrm{SWAP} across the superposition by linearity. The gate does not sample the control and pick a branch; it acts on both halves at once. Why: linearity is the whole story — a quantum gate cannot "read then decide," so the conditional swap becomes a conditional correlation instead of a resolved outcome.

Step 2. Evaluate the ∣0⟩|0\rangle branch: the identity leaves the targets alone, giving α∣0⟩∣ψ⟩∣ϕ⟩\alpha|0\rangle|\psi\rangle|\phi\rangle. Evaluate the ∣1⟩|1\rangle branch: SWAP exchanges the targets, giving β∣1⟩∣ϕ⟩∣ψ⟩\beta|1\rangle|\phi\rangle|\psi\rangle. Adding them, F(α∣0⟩+β∣1⟩)∣ψ⟩∣ϕ⟩=α∣0⟩∣ψ⟩∣ϕ⟩+β∣1⟩∣ϕ⟩∣ψ⟩F(\alpha|0\rangle+\beta|1\rangle)|\psi\rangle|\phi\rangle=\alpha|0\rangle|\psi\rangle|\phi\rangle+\beta|1\rangle|\phi\rangle|\psi\rangle. Why: the control now labels which of two distinct target configurations is present, which is the operational signature of entanglement between the control and the targets.

Step 3. Ask when this factors. If ∣ψ⟩=∣ϕ⟩|\psi\rangle=|\phi\rangle the two branches carry the identical target state, the control factors out as α∣0⟩+β∣1⟩\alpha|0\rangle+\beta|1\rangle, and the output is a product — no entanglement. If ∣ψ⟩|\psi\rangle and ∣ϕ⟩|\phi\rangle differ, the branches are distinguishable and (for α,β≠0\alpha,\beta\neq0) the state cannot be written as a single tensor product. Why: this is the resource the SWAP test exploits — the amount of control–target entanglement is controlled by how different the two target states are, i.e. by their overlap. *For orthogonal targets the output is a maximally entangled control–target pair; for identical targets the reduced control state stays pure — consistent with the overlap formula derived next.*

Go deeper · Derivation C · 1 minThe SWAP test and its overlap readout
Derivation CThe SWAP test and its overlap readout

The purpose is to sandwich the Fredkin gate between two Hadamards on the control, compute the probability of measuring the control in ∣0⟩|0\rangle, and recover the overlap formula P0=12(1+∣⟨ψ∣ϕ⟩∣2)P_0=\tfrac12(1+|\langle\psi|\phi\rangle|^2) that turns an abstract inner product into a measurable frequency. This is the single most-used application of the gate: it estimates state similarity without ever learning either state, and it underlies fidelity checks, entanglement witnesses, and quantum kernel methods.

Step 1. Start with the control in ∣0⟩|0\rangle and the targets in ∣ψ⟩∣ϕ⟩|\psi\rangle|\phi\rangle, and apply the first Hadamard: H∣0⟩=12(∣0⟩+∣1⟩)H|0\rangle=\tfrac1{\sqrt2}(|0\rangle+|1\rangle), so the joint state is 12(∣0⟩+∣1⟩)∣ψ⟩∣ϕ⟩\tfrac1{\sqrt2}(|0\rangle+|1\rangle)|\psi\rangle|\phi\rangle. Why: the Hadamard is what puts the control's "if" into superposition, arming the coherent maybe-swap; without it the gate could only do classical routing.

Step 2. Apply the Fredkin gate using the previous derivation: the state becomes 12(∣0⟩∣ψ⟩∣ϕ⟩+∣1⟩∣ϕ⟩∣ψ⟩)\tfrac1{\sqrt2}\big(|0\rangle|\psi\rangle|\phi\rangle+|1\rangle|\phi\rangle|\psi\rangle\big). Why: the control now tags the two orderings of the targets, storing their difference as an entangled correlation that the second Hadamard will convert into interference.

Step 3. Apply the second Hadamard to the control, using H∣0⟩=12(∣0⟩+∣1⟩)H|0\rangle=\tfrac1{\sqrt2}(|0\rangle+|1\rangle) and H∣1⟩=12(∣0⟩−∣1⟩)H|1\rangle=\tfrac1{\sqrt2}(|0\rangle-|1\rangle): the state regroups to 12[∣0⟩(∣ψϕ⟩+∣ϕψ⟩)+∣1⟩(∣ψϕ⟩−∣ϕψ⟩)]\tfrac12\big[|0\rangle(|\psi\phi\rangle+|\phi\psi\rangle)+|1\rangle(|\psi\phi\rangle-|\phi\psi\rangle)\big]. Why: the Hadamard recombines the two branches so that the symmetric combination lands on ∣0⟩|0\rangle and the antisymmetric one on ∣1⟩|1\rangle — the difference between the states is routed onto the control outcome.

Step 4. Take the norm of the ∣0⟩|0\rangle component: P0=14∥∣ψϕ⟩+∣ϕψ⟩∥2=14(2+2 Re⟨ψϕ∣ϕψ⟩)=12(1+∣⟨ψ∣ϕ⟩∣2)P_0=\tfrac14\big\||\psi\phi\rangle+|\phi\psi\rangle\big\|^2=\tfrac14\big(2+2\,\mathrm{Re}\langle\psi\phi|\phi\psi\rangle\big)=\tfrac12\big(1+|\langle\psi|\phi\rangle|^2\big), using ⟨ψϕ∣ϕψ⟩=⟨ψ∣ϕ⟩⟨ϕ∣ψ⟩=∣⟨ψ∣ϕ⟩∣2\langle\psi\phi|\phi\psi\rangle=\langle\psi|\phi\rangle\langle\phi|\psi\rangle=|\langle\psi|\phi\rangle|^2. Why: identical states give P0=1P_0=1 (the test never fails), orthogonal states give P0=12P_0=\tfrac12 (a fair coin), and inverting ∣⟨ψ∣ϕ⟩∣2=2P0−1|\langle\psi|\phi\rangle|^2=2P_0-1 turns a measured frequency into the overlap. *For ∣ψ⟩=∣0⟩|\psi\rangle=|0\rangle, ∣ϕ⟩=∣+⟩|\phi\rangle=|+\rangle, ∣⟨ψ∣ϕ⟩∣2=12|\langle\psi|\phi\rangle|^2=\tfrac12 and P0=34=0.75P_0=\tfrac34=0.75; the cross term evaluates to ∣⟨ψ∣ϕ⟩∣2|\langle\psi|\phi\rangle|^2.*

Limiting cases

The pinned-input specializations below are where the gate's two faces — reversible logic and coherent comparison — become concrete, and they are the cases worth carrying in your head.

CaseResultMeaning
Control off∣0,a,b⟩↦∣0,a,b⟩\vert 0,a,b\rangle \mapsto \vert 0,a,b\ranglewith c=0c=0 the gate is the identity on the targets — a clean pass-through
Control on∣1,a,b⟩↦∣1,b,a⟩\vert 1,a,b\rangle \mapsto \vert 1,b,a\ranglewith c=1c=1 the two targets are exchanged — a plain SWAP
Pin one target to 0∣c,a,0⟩↦∣c, a∧cˉ, a∧c⟩\vert c,a,0\rangle \mapsto \vert c,\,a\wedge\bar c,\,a\wedge c\ranglefixing b=0b=0 makes the lower output a∧ca\wedge c (AND) and the upper output a∧cˉa\wedge\bar c — a route to universal logic
Pin one target to 1∣c,1,b⟩↦∣c, 1⊕c(1⊕b), b⊕c(1⊕b)⟩\vert c,1,b\rangle \mapsto \vert c,\,1\oplus c(1\oplus b),\,b\oplus c(1\oplus b)\ranglefixing a=1a=1 yields NOT and OR of c,bc,b, completing a functionally complete set
Identical targets∣c⟩∣ψ⟩∣ψ⟩↦∣c⟩∣ψ⟩∣ψ⟩\vert c\rangle\vert\psi\rangle\vert\psi\rangle \mapsto \vert c\rangle\vert\psi\rangle\vert\psi\rangleSWAP fixes ∣ψψ⟩\vert\psi\psi\rangle, so even a superposed control stays unentangled — the SWAP-test "always passes" limit

Worked examples

1 · Estimating an overlap with the SWAP test (fully worked)

Two single-qubit registers hold ∣ψ⟩=∣0⟩|\psi\rangle=|0\rangle and ∣ϕ⟩=∣+⟩=12(∣0⟩+∣1⟩)|\phi\rangle=|+\rangle=\tfrac1{\sqrt2}(|0\rangle+|1\rangle). Run the SWAP test. Find the exact probability of measuring the control in ∣0⟩|0\rangle, say what a single shot tells you, and estimate how many shots are needed to pin the overlap to ±0.01\pm0.01.

Step 1. Compute the overlap. ⟨ψ∣ϕ⟩=⟨0∣+⟩=12\langle\psi|\phi\rangle=\langle0|+\rangle=\tfrac1{\sqrt2}, so ∣⟨ψ∣ϕ⟩∣2=12=0.5|\langle\psi|\phi\rangle|^2=\tfrac12=0.5. The two states are neither identical nor orthogonal — they sit exactly halfway.

Step 2. Apply the readout formula (7): P0=12(1+0.5)=0.75P_0=\tfrac12(1+0.5)=\mathbf{0.75}, and correspondingly P1=1−P0=0.25P_1=1-P_0=\mathbf{0.25}. The control comes up 00 three times in four and 11 once in four. A single shot is nearly useless — a lone "00" is consistent with any overlap from 00 to 11 — because the test is a Bernoulli trial and the overlap lives in its bias, not in any one outcome.

Step 3. Invert to get the estimator: ∣⟨ψ∣ϕ⟩∣2=2P0−1|\langle\psi|\phi\rangle|^2=2P_0-1. Estimating P0P_0 from NN shots has standard error P0(1−P0)/N=0.75⋅0.25/N=0.433N\sqrt{P_0(1-P_0)/N}=\sqrt{0.75\cdot0.25/N}=\tfrac{0.433}{\sqrt N}, and the overlap error is twice that, 0.866N\tfrac{0.866}{\sqrt N}. Setting 0.866N≤0.01\tfrac{0.866}{\sqrt N}\le0.01 gives N≥(86.6)2≈7500N\ge(86.6)^2\approx\mathbf{7500} shots. The overlap is knowable to two decimals only after a few thousand repetitions — the price of learning a quantum inner product without ever measuring either state directly.

2 · A reversible AND gate and its garbage (fully worked)

Pin the lower target to the constant b=0b=0 and feed the control cc and upper target aa into a Fredkin gate. Tabulate the four classical inputs, identify the useful output, and account for the conservation law and the leftover "garbage" bits.

Step 1. Specialize equation (1) at b=0b=0: F∣c,a,0⟩=∣c, a⊕c⋅a, c⋅a⟩=∣c, a∧cˉ, a∧c⟩F|c,a,0\rangle=|c,\,a\oplus c\cdot a,\,c\cdot a\rangle=|c,\,a\wedge\bar c,\,a\wedge c\rangle, since a⊕ca=a(1−c)=a∧cˉa\oplus ca=a(1-c)=a\wedge\bar c. The lower output is a∧ca\wedge c, a logical AND of the control and the upper target.

Step 2. Tabulate all four inputs (c,a)(c,a) with b=0b=0:

ccaabbout ccout a∧cˉa\wedge\bar cout a∧ca\wedge c (AND)
000000
010010
100100
110101

The last column is exactly the AND truth table: it is 11 only for c=a=1c=a=1.

Step 3. Account for the bookkeeping. In every row the number of input 11s equals the number of output 11s — conservation holds line by line (e.g. row c=1,a=1c=1,a=1: two 11s in, two out). The AND lands on one wire; the other two outputs (cc and a∧cˉa\wedge\bar c) are garbage — bits the computation did not want but reversibility forbids discarding. A reversible circuit must carry or uncompute this garbage, which is why reversible arithmetic costs extra ancilla wires that a dissipative classical circuit would simply erase. On a fault-tolerant machine the same gate, compiled via equation (6), costs the non-Clifford budget of one Toffoli — a T-count of 7 magic states — which is what makes Fredkin-heavy reversible subroutines expensive to run.

Physics of the portrait

The Fredkin gate carries the fingerprints of a physicist who was convinced, more literally than almost anyone, that the universe is a computation — and who built a gate that computes without spending energy to prove that logic and thermodynamics are one subject.

Origins · 1 minEdward Fredkin and how this was discovered
EF
Edward Fredkin
1934–2023 · conservative logic, reversible computation, and the billiard-ball model

Edward Fredkin was one of the most unconventional figures in twentieth-century computing: a US Air Force fighter pilot who never finished college yet became a full professor at MIT, where he directed the storied Project MAC in the early 1970s. His obsession was "digital physics" — the radical hypothesis that space, time, and matter are ultimately discrete and that the cosmos runs like a giant cellular automaton — and it led him to ask how computation could be reconciled with physical law. Landauer had argued in 1961 that erasing a bit must dissipate at least kBTln⁡2k_BT\ln2 of heat, and Bennett had shown in 1973 that computation could in principle be made logically reversible and so escape that cost. Fredkin, with his student Tommaso Toffoli, pushed the idea to its physical limit in the 1982 paper "Conservative Logic" (Int. J. Theor. Phys. 21, 219): they introduced the conservative, reversible gate now bearing Fredkin's name and the billiard-ball computer, a model in which logic is done by elastic collisions of indestructible balls, a ball encoding a 11 and none ever created or destroyed — so the gate's Hamming-weight conservation is exactly ball-number conservation. Fredkin worked closely with Richard Feynman, the two friends teaching each other the physics of computation at Caltech. Toffoli's companion controlled-controlled-NOT and Fredkin's controlled-SWAP remain the two canonical universal reversible gates, and both were absorbed wholesale into the quantum circuit model, where reversibility is not a design choice but a law: every quantum gate is unitary, hence reversible, by construction.

History
1961
— Landauer links logically irreversible bit erasure to a minimum heat cost of kT ln 2
1973
— Bennett proves any computation can be recast as a logically reversible one
1980
— Toffoli introduces the reversible controlled-controlled-NOT, a universal reversible gate
1982
— Fredkin and Toffoli publish Conservative Logic, defining the Fredkin gate and the billiard-ball model
2016
— Patel and collaborators demonstrate a photonic quantum Fredkin gate directly, without decomposition

Going further

Texts. Nielsen and Chuang, Quantum Computation and Quantum Information, §1.4.1 (reversible logic and the Fredkin/Toffoli gates) and §3.2.5 · Preskill, Lecture Notes for Physics 219, Ch. 6 (classical and quantum reversible computation) · Watrous, The Theory of Quantum Information, Ch. 2 · Kitaev, Shen and Vyalyi, Classical and Quantum Computation, §2 · Mermin, Quantum Computer Science, Ch. 2 · Fredkin and Toffoli, "Conservative Logic," Int. J. Theor. Phys. 21, 219 (1982) · Buhrman, Cleve, Watrous and de Wolf, "Quantum Fingerprinting," Phys. Rev. Lett. 87, 167902 (2001) for the SWAP test. Key results to keep in mind: the 8×88\times8 permutation matrix follows from the action rule ∣c,a,b⟩↦∣c, a⊕c(a⊕b), b⊕c(a⊕b)⟩|c,a,b\rangle\mapsto|c,\,a\oplus c(a\oplus b),\,b\oplus c(a\oplus b)\rangle, with the single transposition ∣101⟩↔∣110⟩|101\rangle\leftrightarrow|110\rangle; the self-inverse and conservation properties F†=FF^\dagger=F, F2=IF^2=I; the compilation identity F=CNOTb→a Toffolic,a→b CNOTb→aF=\mathrm{CNOT}_{b\to a}\,\mathrm{Toffoli}_{c,a\to b}\,\mathrm{CNOT}_{b\to a} verified by direct basis tracking; the AND/NOT/fan-out specializations of the Boolean action; and the SWAP-test probability P0=12(1+∣⟨ψ∣ϕ⟩∣2)P_0=\tfrac12(1+|\langle\psi|\phi\rangle|^2), including the worked value P0=0.75P_0=0.75 for ∣ψ⟩=∣0⟩|\psi\rangle=|0\rangle, ∣ϕ⟩=∣+⟩|\phi\rangle=|+\rangle (overlap 12\tfrac12). All matrix entries are 00 or 11; the TT-count of 77 is the standard Toffoli figure.

Prerequisites. SWAP Gate · CNOT Gate · Controlled-U Gates · Quantum Circuit Model. Leads to. Circuit Identities and Equivalences · Controlled-Z Gate · Phase Gates (S and T).

Ask the tutor: ask me to run any three-qubit state through the Fredkin gate, walk the SWAP test end to end for two states you choose, or compile a controlled-SWAP down to Toffoli and CNOTs and count its T gates.

How is the Fredkin gate different from an ordinary SWAP gate?

A plain SWAP always exchanges its two qubits; the Fredkin gate exchanges its two targets only when the control qubit is ∣1⟩|1\rangle, and leaves them alone when the control is ∣0⟩|0\rangle. That extra control wire is the whole point. It lets the swap be conditioned on data, which is what makes the gate universal for reversible logic (pin an ancilla and you get AND). And when the control is in a superposition the gate does not pick a branch — it entangles the control with whether the swap happened, producing the coherent maybe-swap behind the SWAP test. An unconditional SWAP can do none of these things; it is just the c=1c=1 slice of the Fredkin gate.

What does "conservative" mean, and why did Fredkin care about it?

A conservative gate preserves the number of 11s (the Hamming weight) in every computational-basis input — it can move 11s between wires but never create or destroy one. The Fredkin gate qualifies because a swap only relocates bits. Fredkin cared because he wanted logic to model physics literally: in his and Toffoli's billiard-ball computer, a 11 is a ball and a 00 is empty space, and conservation of weight is just conservation of balls in a world of elastic collisions. Combined with reversibility (no information erased), conservation means computation can in principle approach Landauer's zero-dissipation limit — the deep link between logic and thermodynamics that motivated the whole conservative-logic program.

What is the SWAP test actually measuring, and what are its limits?

It measures a single real number: the squared overlap ∣⟨ψ∣ϕ⟩∣2|\langle\psi|\phi\rangle|^2 of the two target states, read from the probability P(control=0)=12(1+∣⟨ψ∣ϕ⟩∣2)P(\text{control}=0)=\tfrac12(1+|\langle\psi|\phi\rangle|^2). It does not reveal either state, which is why it respects no-cloning — you learn how alike two unknowns are without learning what they are. Its limits are statistical and one-sided. Statistical: each run is a coin flip biased by the overlap, so you need many shots (thousands for two-decimal precision) to estimate the probability. One-sided: a test that "passes" (control =0=0) does not prove the states are equal; orthogonal states still pass half the time. Only repeated failures certify that the states differ.

Is the Fredkin gate universal all by itself?

For classical reversible computation, essentially yes — a Fredkin gate together with the ability to supply constant ancilla bits and ignore garbage outputs can build any Boolean function. Pinning the lower target to 00 gives AND; setting the upper target to 11 gives NOT and a copy (fan-out); and AND with NOT is already functionally complete. It is not universal for quantum computation on its own, however: like all permutation gates it only maps basis states to basis states, so it cannot create the arbitrary superpositions a universal quantum set needs. Add single-qubit gates such as the Hadamard and TT and you recover full quantum universality, with the Fredkin (or Toffoli) supplying the multi-qubit non-linearity.

How expensive is a Fredkin gate to run on a real quantum computer?

More expensive than it looks, because hardware offers only one- and two-qubit gates. The standard compilation writes it as one Toffoli sandwiched by two CNOTs; the CNOTs are cheap Clifford gates, but the Toffoli is not, and in a fault-tolerant surface-code machine it must be built from non-Clifford TT gates — seven of them, each requiring a costly distilled magic state. So a Fredkin gate carries a TT-count of 77, and a SWAP test comparing two nn-qubit registers, which needs nn controlled-SWAPs, costs about 7n7n magic states plus the CNOT overhead. This is why counting Toffoli and Fredkin gates — really, counting their TT gates — is how architects price reversible subroutines inside larger quantum algorithms.

How is the Fredkin gate related to the Toffoli gate?

They are the two canonical universal reversible three-qubit gates, and they are close cousins. The Toffoli is the controlled-controlled-NOT (flip a target if both controls are 11); the Fredkin is the controlled-SWAP (exchange two targets if the control is 11). Each can be built from the other plus CNOTs — indeed F=CNOT Toffoli CNOTF=\mathrm{CNOT}\,\mathrm{Toffoli}\,\mathrm{CNOT} — so they share the same non-Clifford cost of seven TT gates and the same status as universal reversible primitives. Historically they arrived together: Toffoli introduced his gate in 1980, and he and Fredkin published both within the conservative-logic framework in 1982. The Toffoli tends to appear in arithmetic (it is a controlled adder's carry), the Fredkin in comparison and routing (the SWAP test, data-dependent multiplexing).

Does the Fredkin gate really connect logic to thermodynamics?

Yes, and that connection was its reason for existing. Landauer's principle says erasing one bit of information must dissipate at least kBTln⁡2k_BT\ln2 of heat, so irreversible gates like a conventional AND — which throw away inputs — have an unavoidable thermodynamic cost. The Fredkin gate is reversible (its inputs can always be recovered from its outputs) and conservative (it erases nothing and moves no "mass"), so in the idealized limit it can compute without any fundamental heat penalty. Fredkin and Toffoli's billiard-ball model made this vivid: frictionless elastic collisions perform logic at zero energy cost. Real devices never reach that limit, but the principle drives adiabatic and reversible-computing research aimed at ultra-low-power classical logic — and it is why the quantum circuit model, being unitary and hence reversible throughout, inherited these gates so naturally.

Before this

Where this leads