SWAP Gate

The SWAP gate does the most physically intuitive thing two qubits can do: it interchanges the states carried by two wires, sending ∣a⟩⊗∣b⟩|a\rangle\otimes|b\rangle to ∣b⟩⊗∣a⟩|b\rangle\otimes|a\rangle and, by linearity, carrying every superposition and every entangled correlation across with it. That plain description hides a genuine subtlety. Exchanging two qubits is not a tensor product of single-qubit gates — you cannot swap two wires with any amount of local twiddling — so SWAP is an honest two-qubit gate. Yet acting on a product state it creates no entanglement at all, because relabelling which wire holds which factor cannot correlate them. SWAP is the standing counterexample to the reflex that "two-qubit gate" means "entangling gate." As a matrix in the ordered basis {∣00⟩,∣01⟩,∣10⟩,∣11⟩}\{|00\rangle,|01\rangle,|10\rangle,|11\rangle\} it is the permutation that transposes the middle two amplitudes and fixes ∣00⟩,∣11⟩|00\rangle,|11\rangle. It is simultaneously real, symmetric, Hermitian, unitary, and its own inverse — a rare pile-up of properties. Its spectrum is fixed not by computation but by representation theory: the symmetric (triplet) subspace of dimension three carries eigenvalue +1+1 and the antisymmetric (singlet) carries −1-1, so Tr⁡SWAP=2\operatorname{Tr}\mathrm{SWAP}=2 and det⁡SWAP=−1\det\mathrm{SWAP}=-1. Written over the Pauli basis it is 12(II+XX+YY+ZZ)=12(I+σ⃗1⋅σ⃗2)\tfrac12(II+XX+YY+ZZ)=\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2), the isotropic Heisenberg exchange operator — the same object that fixes the energy of two coupled spins. Operationally SWAP is the workhorse of qubit routing: on hardware that couples only neighbouring qubits, a chain of SWAPs shuttles a logical qubit to where it is needed, and because each SWAP costs three CNOTs, minimising SWAP count is one of the central problems of circuit compilation. Its square root SWAP\sqrt{\mathrm{SWAP}}, unlike the full swap, is maximally entangling and, with single-qubit gates, universal.

Key takeaways
  • The SWAP gate exchanges its two inputs, SWAP ∣a,b⟩=∣b,a⟩\mathrm{SWAP}\,|a,b\rangle=|b,a\rangle; its matrix interchanges the ∣01⟩|01\rangle and ∣10⟩|10\rangle amplitudes and fixes ∣00⟩,∣11⟩|00\rangle,|11\rangle.
  • It is real, symmetric, Hermitian, unitary and involutory (SWAP2=I\mathrm{SWAP}^2=I), with eigenvalues +1+1 (triplet, threefold) and −1-1 (singlet, once), so Tr⁡=2\operatorname{Tr}=2 and det⁡=−1\det=-1.
  • It factors into exactly three alternating CNOTs, SWAP=CNOT1→2 CNOT2→1 CNOT1→2\mathrm{SWAP}=\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{2\to1}\,\mathrm{CNOT}_{1\to2} — the reversible XOR-swap, and three is the provable minimum.
  • Over the Pauli basis it is 12(II+XX+YY+ZZ)=12(I+σ⃗1⋅σ⃗2)\tfrac12(II+XX+YY+ZZ)=\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2), exactly the isotropic Heisenberg exchange operator.
  • SWAP creates no entanglement from a product state, but the partial swap e−iθ SWAPe^{-i\theta\,\mathrm{SWAP}} has concurrence ∣sin⁡2θ∣|\sin 2\theta|, peaking at θ=π/4\theta=\pi/4 where SWAP\sqrt{\mathrm{SWAP}} is maximally entangling and universal.
  • Key idea: SWAP is the exchange operator 12(I+σ⃗1⋅σ⃗2)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2) that swaps the ∣01⟩|01\rangle and ∣10⟩|10\rangle amplitudes; it factors into three alternating CNOTs, never entangles a product state, yet its square root maximally entangles.
The core insight

SWAP is the exchange operator 12(I+σ⃗1⋅σ⃗2)=12(II+XX+YY+ZZ)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2)=\tfrac12(II+XX+YY+ZZ) that swaps the amplitudes of ∣01⟩|01\rangle and ∣10⟩|10\rangle; it factors into three alternating CNOTs and, though it never entangles a product state, its square root SWAP\sqrt{\mathrm{SWAP}} is maximally entangling.

Where this lives today

SWAP is two things at once in a working quantum computer: a compiler abstraction and a physical interaction. As an abstraction it is the currency of qubit routing. Real processors — IBM's heavy-hex lattices, Google's grid of transmons, neutral-atom arrays — couple only physically adjacent qubits, so an algorithm that wants a gate between distant qubits must first SWAP one of them into place, run the gate, and often SWAP it back. Since each SWAP costs three CNOTs, and CNOTs are the noisiest, slowest operations on the device, the number and placement of inserted SWAPs dominate both circuit depth and error budget; deciding them optimally (the "qubit mapping and routing" problem) is NP-hard, and every serious transpiler — Qiskit, t∣\vertket⟩\rangle, and the rest — spends most of its effort here. As a physical interaction, SWAP and its square root are the native language of exchange-coupled hardware: in silicon and gallium-arsenide quantum dots following the Loss–DiVincenzo proposal, pulsing the tunnel barrier between two spins turns on the Heisenberg coupling for a controlled time, and a pulse area of a quarter-period realises SWAP\sqrt{\mathrm{SWAP}} directly, with no CNOT compilation at all. The SWAP test lives on as a primitive for fidelity estimation, quantum kernel evaluation in machine learning, and entanglement witnesses, while its fermionic cousin, the fSWAP, is a standard building block for simulating molecules and materials under the Jordan–Wigner mapping. The open frontiers are practical and sharp: routing-aware compilation that minimises SWAP overhead on ever-larger connectivity graphs, and exchange-only qubit encodings that aim to run entire algorithms using nothing but the physics of Heisenberg's 1926 interaction.

The physical picture

Picture two labelled wires carrying quantum states. The SWAP gate cuts and crosses them: whatever entered on wire 1 leaves on wire 2, and whatever entered on wire 2 leaves on wire 1. For a product input this is pure relabelling — no information is created or destroyed and no entanglement is generated — but for an entangled input the gate faithfully carries the correlations along with the swapped factors. The standard circuit symbol is two crosses joined by a vertical line, and the cleanest way to build it from the universal primitive is the reversible version of the classical trick that swaps two registers with no scratch space: XOR the first into the second, the second into the first, and the first into the second again. Three CNOTs, alternating direction, thread the bit-values through one another and land on the exchange.

Figure
A SWAP interchanges the two wires — whatever enters on qubit 1 leaves on qubit 2 and vice versa, so the basis state 0,1 becomes 1,0. Below, the identical map is assembled from three alternating CNOTs that thread the values a, a⊕b, b through each other, the reversible XOR-swap.
SWAP interchanges the wires : |a,b⟩ → |b,a⟩ , here |0,1⟩ → |1,0⟩ |0⟩ |1⟩ |1⟩ |0⟩ qubit 1 and qubit 2 trade their states no entanglement is created — only relabelling = three alternating CNOTs (the reversible XOR-swap) q1 q2 a b a a⊕b b a⊕b b a

Spectrally, SWAP is the exchange operator borrowed straight from many-body physics. It must act as +1+1 on any state symmetric under interchange and −1-1 on the antisymmetric singlet — that is what "swap the labels" means — so its eigenvalues are forced to be {+1,+1,+1,−1}\{+1,+1,+1,-1\}, and it is exactly 12(I+σ⃗1⋅σ⃗2)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2), the isotropic Heisenberg coupling. That connection is where the deepest surprise lives. Because SWAP2=I\mathrm{SWAP}^2=I, the gate is an involution, and its square root is well defined — a "half exchange." A full exchange never entangles, but the half exchange SWAP\sqrt{\mathrm{SWAP}} turns a product state into a maximally entangled one. The continuous family e−iθ SWAPe^{-i\theta\,\mathrm{SWAP}} interpolates smoothly between them, and its entangling power rises from nothing at θ=0\theta=0, to a maximum at θ=π/4\theta=\pi/4, and back to nothing at θ=π/2\theta=\pi/2 — the second figure makes this non-monotonic story quantitative.

Figure
Entangling power of the partial swap exp(−iθ·SWAP) acting on a product input: the concurrence C = sin 2θ over this range is exactly zero at θ = 0 (the identity) and at θ = π/2 (the full SWAP, which only relabels), but a full C = 1 at θ = π/4, where the gate is √SWAP — maximally entangling and, with single-qubit gates, universal.
Concurrence of e^(−iθ·SWAP) on a product input : C = |sin 2θ| 1.0 0.5 0.0 0 π/8 π/4 3π/8 π/2 exchange angle θ concurrence C C = 0 : identity (θ = 0) C = 1 : √SWAP (θ = π/4), maximally entangling C = 0 : full SWAP (θ = π/2)

The core equations

Everything begins with the explicit matrix in the computational basis, ordering rows and columns as ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle,|01\rangle,|10\rangle,|11\rangle. Reading the entries directly shows it is a permutation that leaves ∣00⟩,∣11⟩|00\rangle,|11\rangle untouched and interchanges the two "one excitation" states.

SWAP=(1000001001000001)(1)\mathrm{SWAP}=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{pmatrix} \qquad (1)

where: rows and columns run over the ordered basis ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle,|01\rangle,|10\rangle,|11\rangle; the off-diagonal 11's move the ∣01⟩|01\rangle and ∣10⟩|10\rangle amplitudes onto each other. The reading: the matrix is real and symmetric, so SWAP†=SWAP\mathrm{SWAP}^\dagger=\mathrm{SWAP}; its columns are orthonormal, so it is unitary; and it is a permutation, so applying it twice returns the identity. The permutation is the matrix expression of one plain sentence — the gate exchanges the two qubits — which extends by linearity from basis states to every superposition and entangled input.

SWAP ∣a,b⟩=∣b,a⟩,a,b∈{0,1}(2)\mathrm{SWAP}\,|a,b\rangle=|b,a\rangle,\qquad a,b\in\{0,1\} \qquad (2)

where: a,ba,b — the computational-basis values of the two qubits. The reading: on a product input ∣ψ⟩⊗∣ϕ⟩|\psi\rangle\otimes|\phi\rangle the output is ∣ϕ⟩⊗∣ψ⟩|\phi\rangle\otimes|\psi\rangle, still a product, so no entanglement appears; on an entangled input the correlations ride along with the swapped factors. The workhorse identity of hardware compilation writes SWAP as three CNOTs in alternating direction — the quantum realisation of the classical XOR-swap trick.

SWAP=CNOT1→2 CNOT2→1 CNOT1→2(3)\mathrm{SWAP}=\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{2\to1}\,\mathrm{CNOT}_{1\to2} \qquad (3)

where: CNOTi→j\mathrm{CNOT}_{i\to j} — a CNOT with control qubit ii and target qubit jj. The reading: the alternation of direction is essential — two CNOTs the same way do not give SWAP — and three is provably the minimum CNOT count for the exchange. Decomposed over the two-qubit Pauli basis, SWAP is the sum of the four "matched" tensor products, each entering with weight one half. This is its algebraic centre of gravity.

SWAP=12(I⊗I+X⊗X+Y⊗Y+Z⊗Z)(4)\mathrm{SWAP}=\tfrac12\left(I\otimes I+X\otimes X+Y\otimes Y+Z\otimes Z\right) \qquad (4)

where: X,Y,ZX,Y,Z — the single-qubit Pauli operators; II — the single-qubit identity. The reading: the coefficients are fixed by orthogonality of the Pauli basis, and the appearance of XX+YY+ZZXX+YY+ZZ — with no ZZZZ singled out — is what makes this the isotropic exchange. The same identity, rewritten with the Pauli vector σ⃗=(X,Y,Z)\vec\sigma=(X,Y,Z), exposes SWAP as the Heisenberg exchange operator of two spins — the bridge to condensed-matter physics and to the portrait below.

SWAP=12(I+σ⃗1⋅σ⃗2),σ⃗1⋅σ⃗2=XX+YY+ZZ(5)\mathrm{SWAP}=\tfrac12\left(I+\vec\sigma_1\cdot\vec\sigma_2\right),\qquad \vec\sigma_1\cdot\vec\sigma_2=XX+YY+ZZ \qquad (5)

where: σ⃗1⋅σ⃗2\vec\sigma_1\cdot\vec\sigma_2 — the dot product of the two spin operators, with eigenvalue +1+1 on the triplet and −3-3 on the singlet. The reading: this is Dirac's spin-exchange identity; the Heisenberg Hamiltonian H=−J σ⃗1⋅σ⃗2H=-J\,\vec\sigma_1\cdot\vec\sigma_2 is, up to a constant, −2J SWAP-2J\,\mathrm{SWAP}, so its time evolution is the partial swap. Two structural facts follow at once and pin down the gate's whole character; both can be read straight off equation (1).

SWAP†=SWAP,SWAP2=I(6)\mathrm{SWAP}^\dagger=\mathrm{SWAP},\qquad \mathrm{SWAP}^2=I \qquad (6)

where: †\dagger — conjugate transpose; II — the 4×44\times4 identity. The reading: Hermiticity makes SWAP a legitimate observable with eigenvalues ±1\pm1; combined with unitarity it forces the involution SWAP2=I\mathrm{SWAP}^2=I, so the gate is its own inverse — there is no separate "un-SWAP." The spectrum is not something to compute so much as to recognise, because the symmetric and antisymmetric subspaces are eigenspaces by construction.

spec⁡(SWAP)={+1,+1,+1,−1},Tr⁡=2,det⁡=−1(7)\operatorname{spec}(\mathrm{SWAP})=\{+1,+1,+1,-1\},\qquad \operatorname{Tr}=2,\qquad \det=-1 \qquad (7)

where: the +1+1 eigenvalue (multiplicity 3) belongs to the symmetric triplet subspace; the −1-1 eigenvalue (multiplicity 1) belongs to the antisymmetric singlet. The reading: Tr⁡=3(+1)+1(−1)=2\operatorname{Tr}=3(+1)+1(-1)=2 and det⁡=(+1)3(−1)=−1\det=(+1)^3(-1)=-1, both matching the explicit matrix. Finally, because SWAP2=I\mathrm{SWAP}^2=I, the exponential closes into a two-term formula, generating the continuous family of partial swaps that contains SWAP\sqrt{\mathrm{SWAP}}.

e−iθ SWAP=cos⁡θ I−isin⁡θ SWAP,SWAP=12 ⁣(200001+i1−i001−i1+i00002)(8)e^{-i\theta\,\mathrm{SWAP}}=\cos\theta\,I-i\sin\theta\,\mathrm{SWAP},\qquad \sqrt{\mathrm{SWAP}}=\tfrac12\!\begin{pmatrix}2&0&0&0\\0&1{+}i&1{-}i&0\\0&1{-}i&1{+}i&0\\0&0&0&2\end{pmatrix} \qquad (8)

where: θ\theta — the exchange angle; θ=π/2\theta=\pi/2 gives −i SWAP-i\,\mathrm{SWAP}, and θ=π/4\theta=\pi/4 gives SWAP\sqrt{\mathrm{SWAP}} up to a global phase. The reading: the full swap sits at θ=π/2\theta=\pi/2 and the identity at θ=0\theta=0; halfway between, at θ=π/4\theta=\pi/4, the gate is maximally entangling.

Derivation ASWAP equals three alternating CNOTs

The goal is to prove the compilation identity CNOT1→2 CNOT2→1 CNOT1→2=SWAP\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{2\to1}\,\mathrm{CNOT}_{1\to2}=\mathrm{SWAP} directly, by tracking an arbitrary basis state ∣a,b⟩|a,b\rangle through the three gates and watching the reversible XOR-swap thread the two bit-values through each other. Because a CNOT with control ii and target jj replaces the target by its XOR with the control and leaves the control alone, the whole calculation is bookkeeping in the field Z2\mathbb{Z}_2, using only a⊕a=0a\oplus a=0 and a⊕0=aa\oplus 0=a. Establishing it once is what licenses every later step in transpilation that trades a distant two-qubit gate for a routed nearest-neighbour one.

Step 1. Fix the action of each primitive: CNOT1→2∣x,y⟩=∣x, x⊕y⟩\mathrm{CNOT}_{1\to2}|x,y\rangle=|x,\,x\oplus y\rangle and CNOT2→1∣x,y⟩=∣x⊕y, y⟩\mathrm{CNOT}_{2\to1}|x,y\rangle=|x\oplus y,\,y\rangle. Why: capturing both CNOTs as a single XOR rule lets the composition be done as arithmetic on bits rather than as three 4×44\times4 matrix products.

Step 2. Apply the rightmost gate, CNOT1→2\mathrm{CNOT}_{1\to2}, to ∣a,b⟩|a,b\rangle: the target picks up the control, giving ∣a, a⊕b⟩|a,\,a\oplus b\rangle. Why: reading a circuit right to left, the first physical operation writes the parity a⊕ba\oplus b onto the second wire while the first is untouched.

Step 3. Apply CNOT2→1\mathrm{CNOT}_{2\to1}: now qubit 2 (holding a⊕ba\oplus b) controls qubit 1, sending ∣a, a⊕b⟩|a,\,a\oplus b\rangle to ∣a⊕(a⊕b), a⊕b⟩=∣b, a⊕b⟩|a\oplus(a\oplus b),\,a\oplus b\rangle=|b,\,a\oplus b\rangle, since a⊕a=0a\oplus a=0. Why: this is the middle move of the XOR-swap — the first register is overwritten with bb, and the a⊕aa\oplus a cancellation is the whole reason the trick needs no scratch qubit.

Step 4. Apply the last CNOT1→2\mathrm{CNOT}_{1\to2}: qubit 1 (now bb) controls qubit 2, giving ∣b, (a⊕b)⊕b⟩=∣b, a⟩|b,\,(a\oplus b)\oplus b\rangle=|b,\,a\rangle, again by b⊕b=0b\oplus b=0. This is SWAP∣a,b⟩\mathrm{SWAP}|a,b\rangle for all four basis states, so the operators are equal. Why: agreement on a basis is agreement as operators; and by the left–right symmetry of the construction, CNOT2→1 CNOT1→2 CNOT2→1\mathrm{CNOT}_{2\to1}\,\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{2\to1} is equally a valid SWAP. *Direct multiplication of the three 4×44\times4 CNOT matrices reproduces the SWAP permutation matrix exactly; three is the minimum, since a two-CNOT circuit cannot realise a gate whose permutation is an odd cycle on the full basis.*

Go deeper · Derivation B · 1 minThe spectrum from the exchange decomposition
Derivation BThe spectrum from the exchange decomposition

The aim is to read the eigenvalues of SWAP without diagonalising a matrix, by using the fact that "exchange the two labels" acts as +1+1 on symmetric states and −1-1 on antisymmetric ones, and then cross-checking against the Dirac form SWAP=12(I+σ⃗1⋅σ⃗2)\mathrm{SWAP}=\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2). The payoff is conceptual: the numbers {+1,+1,+1,−1}\{+1,+1,+1,-1\}, Tr⁡=2\operatorname{Tr}=2, det⁡=−1\det=-1 are not accidents of a particular matrix but are forced by the dimension counting of the symmetric and antisymmetric subspaces of two qubits.

Step 1. Decompose the two-qubit space into irreducibles of the exchange, C2⊗C2=Sym2 (dim⁡3)⊕Asym2 (dim⁡1)\mathbb{C}^2\otimes\mathbb{C}^2=\mathrm{Sym}^2\ (\dim 3)\oplus\mathrm{Asym}^2\ (\dim 1) — the triplet and the singlet. Why: SWAP commutes with nothing about the individual labels except their interchange, so its eigenspaces must be exactly the symmetric and antisymmetric sectors.

Step 2. Test the singlet ∣Ψ−⟩=12(∣01⟩−∣10⟩)|\Psi^-\rangle=\tfrac{1}{\sqrt2}(|01\rangle-|10\rangle): swapping the labels gives 12(∣10⟩−∣01⟩)=−∣Ψ−⟩\tfrac{1}{\sqrt2}(|10\rangle-|01\rangle)=-|\Psi^-\rangle, so its eigenvalue is −1-1. Why: the singlet is the one antisymmetric combination, and antisymmetry under exchange is precisely the eigenvalue −1-1 condition.

Step 3. Test the triplet: ∣00⟩|00\rangle and ∣11⟩|11\rangle are manifestly fixed, and ∣Ψ+⟩=12(∣01⟩+∣10⟩)|\Psi^+\rangle=\tfrac{1}{\sqrt2}(|01\rangle+|10\rangle) maps to itself, so all three carry eigenvalue +1+1. Why: symmetric states are unchanged by relabelling, giving the threefold +1+1 eigenspace and completing the count 3+1=43+1=4.

Step 4. Cross-check with the Dirac form: σ⃗1⋅σ⃗2\vec\sigma_1\cdot\vec\sigma_2 has eigenvalue +1+1 on the triplet and −3-3 on the singlet, so 12(I+σ⃗1⋅σ⃗2)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2) gives 12(1+1)=+1\tfrac12(1+1)=+1 and 12(1−3)=−1\tfrac12(1-3)=-1, and the invariants are Tr⁡=3−1=2\operatorname{Tr}=3-1=2, det⁡=(+1)3(−1)=−1\det=(+1)^3(-1)=-1. Why: the two independent routes — permutation symmetry and the spin-dot-product spectrum — agree exactly, which is the check that the exchange identity (5) is correct. *The eigenvalues {+1,+1,+1,−1}\{+1,+1,+1,-1\} with multiplicities 3,13,1 match dim⁡Sym2\dim\mathrm{Sym}^2 and dim⁡Asym2\dim\mathrm{Asym}^2; Tr⁡=2\operatorname{Tr}=2 and det⁡=−1\det=-1 agree with the direct matrix trace and determinant.*

Go deeper · Derivation C · 1 minWhy the full swap never entangles but the half swap maximally does
Derivation CWhy the full swap never entangles but the half swap maximally does

The purpose is to compute the entangling power of the whole partial-swap family e−iθ SWAPe^{-i\theta\,\mathrm{SWAP}} on a product input and to show that the concurrence is ∣sin⁡2θ∣|\sin 2\theta| — zero for both the identity and the full SWAP, and a maximal one exactly at the square root. The strategy is to use the closed exponential from equation (8), act on the product state ∣01⟩|01\rangle, and evaluate the two-qubit concurrence, whose vanishing is the definition of "not entangled." This is the calculation that resolves the article's central paradox: a genuine two-qubit gate that creates no entanglement, sitting a hair's breadth from one that creates the most possible.

Step 1. Expand the exponential using SWAP2=I\mathrm{SWAP}^2=I: the series closes to e−iθ SWAP=cos⁡θ I−isin⁡θ SWAPe^{-i\theta\,\mathrm{SWAP}}=\cos\theta\,I-i\sin\theta\,\mathrm{SWAP}. Why: an operator squaring to the identity behaves in an exponential exactly like the imaginary unit does, collapsing the infinite series to a cosine plus a sine, with no higher terms.

Step 2. Act on the product input ∣01⟩|01\rangle, for which SWAP∣01⟩=∣10⟩\mathrm{SWAP}|01\rangle=|10\rangle: the output is ∣Ψ(θ)⟩=cos⁡θ ∣01⟩−isin⁡θ ∣10⟩|\Psi(\theta)\rangle=\cos\theta\,|01\rangle-i\sin\theta\,|10\rangle. Why: the gate mixes only the {∣01⟩,∣10⟩}\{|01\rangle,|10\rangle\} subspace, so a single-excitation product input stays inside that two-dimensional block, making the amplitudes trivially readable.

Step 3. Evaluate the concurrence C=2∣a00a11−a01a10∣C=2|a_{00}a_{11}-a_{01}a_{10}| with a01=cos⁡θa_{01}=\cos\theta, a10=−isin⁡θa_{10}=-i\sin\theta, and a00=a11=0a_{00}=a_{11}=0: this gives C=2∣cos⁡θ (−isin⁡θ)∣=2sin⁡θcos⁡θ=∣sin⁡2θ∣C=2|\cos\theta\,(-i\sin\theta)|=2\sin\theta\cos\theta=|\sin 2\theta|. Why: for a pure two-qubit state the concurrence is twice the modulus of the amplitude determinant, and its vanishing is exactly the product-state (unentangled) condition, so this one number tracks the full entanglement.

Step 4. Read the three landmarks: at θ=0\theta=0 the gate is II and C=0C=0; at θ=π/2\theta=\pi/2 it is the full SWAP and C=0C=0 again; at θ=π/4\theta=\pi/4 it is SWAP\sqrt{\mathrm{SWAP}} and C=1C=1, the maximum. Why: the full swap merely relabels wires, so it must leave a product input a product; the half swap catches the state exactly halfway across, in a balanced superposition of "swapped" and "not swapped," which is maximal entanglement. *The concurrence formula C(θ)=∣sin⁡2θ∣C(\theta)=|\sin 2\theta| gives C(0)=C(π/2)=0C(0)=C(\pi/2)=0 and C(π/4)=1C(\pi/4)=1; applying the explicit SWAP\sqrt{\mathrm{SWAP}} matrix of (8) to ∣01⟩|01\rangle gives 12[(1+i)∣01⟩+(1−i)∣10⟩]\tfrac12[(1+i)|01\rangle+(1-i)|10\rangle], whose concurrence is 11.*

Limiting cases

Special inputs and parameter limits make SWAP's split personality — inert relabeller here, maximal entangler a quarter-turn away — concrete.

CaseResultMeaning
Product inputSWAP (∣ψ⟩⊗∣ϕ⟩)=∣ϕ⟩⊗∣ψ⟩\mathrm{SWAP}\,(\vert\psi\rangle\otimes\vert\phi\rangle)=\vert\phi\rangle\otimes\vert\psi\rangleThe factors are exchanged; no entanglement is created.
Symmetric inputSWAP ∣ψ⟩=+∣ψ⟩, ∣ψ⟩∈Sym2\mathrm{SWAP}\,\vert\psi\rangle=+\vert\psi\rangle,\ \vert\psi\rangle\in\mathrm{Sym}^2The triplet {∣00⟩,∣11⟩,12(∣01⟩+∣10⟩)}\{\vert00\rangle,\vert11\rangle,\tfrac{1}{\sqrt2}(\vert01\rangle+\vert10\rangle)\} is the +1+1 eigenspace.
Antisymmetric inputSWAP 12(∣01⟩−∣10⟩)=−12(∣01⟩−∣10⟩)\mathrm{SWAP}\,\tfrac{1}{\sqrt2}(\vert01\rangle-\vert10\rangle)=-\tfrac{1}{\sqrt2}(\vert01\rangle-\vert10\rangle)The singlet is the unique −1-1 eigenstate, giving det⁡SWAP=−1\det\mathrm{SWAP}=-1.
Half swap (θ=π/4\theta=\pi/4)SWAP\sqrt{\mathrm{SWAP}} has concurrence C=1C=1 on ∣01⟩\vert01\rangleMaximally entangling; with single-qubit gates it is a universal set.
Full swap (θ=π/2\theta=\pi/2)e−iπ/2 SWAP=−i SWAPe^{-i\pi/2\,\mathrm{SWAP}}=-i\,\mathrm{SWAP}, C=0C=0Back to pure relabelling, up to a global phase — the entangling power has returned to zero.

Worked examples

1 · The half swap builds a Bell pair while the full swap builds nothing (fully worked)

Apply SWAP\sqrt{\mathrm{SWAP}} to the product state ∣01⟩|01\rangle and quantify the entanglement, then contrast with the full SWAP.

Step 1. Act with the explicit matrix from equation (8). Only the middle block is nontrivial, so SWAP ∣01⟩=12[(1+i)∣01⟩+(1−i)∣10⟩]\sqrt{\mathrm{SWAP}}\,|01\rangle=\tfrac12\big[(1+i)|01\rangle+(1-i)|10\rangle\big]. Check the norm: ∣1+i2∣2+∣1−i2∣2=12+12=1|\tfrac{1+i}{2}|^2+|\tfrac{1-i}{2}|^2=\tfrac12+\tfrac12=1, a valid state.

Step 2. Read the amplitudes into the concurrence C=2∣a00a11−a01a10∣C=2|a_{00}a_{11}-a_{01}a_{10}|: here a00=a11=0a_{00}=a_{11}=0, a01=1+i2a_{01}=\tfrac{1+i}{2}, a10=1−i2a_{10}=\tfrac{1-i}{2}, so a01a10=(1+i)(1−i)4=24=12a_{01}a_{10}=\tfrac{(1+i)(1-i)}{4}=\tfrac{2}{4}=\tfrac12. Then C=2∣0−12∣=1C=2\big|0-\tfrac12\big|=\mathbf{1}. The output is maximally entangled — locally equivalent to a Bell state.

Step 3. Contrast the full SWAP: SWAP ∣01⟩=∣10⟩\mathrm{SWAP}\,|01\rangle=|10\rangle, a product state, with a10=1a_{10}=1 and every other amplitude zero, so C=2∣0−0∣=0C=2|0-0|=\mathbf{0}. Same single-excitation input, same subspace, opposite verdict: the full exchange relabels, the half exchange entangles.

Step 4. Sanity-check against the family formula. Writing SWAP\sqrt{\mathrm{SWAP}} as e−iπ/4 SWAPe^{-i\pi/4\,\mathrm{SWAP}} up to phase, the concurrence should be ∣sin⁡(2⋅π4)∣=∣sin⁡π2∣=1|\sin(2\cdot\tfrac{\pi}{4})|=|\sin\tfrac{\pi}{2}|=1, and the full swap at θ=π/2\theta=\pi/2 gives ∣sin⁡π∣=0|\sin\pi|=0. Both match Derivation 3 and the second figure exactly.

2 · Estimating state overlap with the SWAP test (fully worked)

A controlled-SWAP between two registers ∣ψ⟩,∣ϕ⟩|\psi\rangle,|\phi\rangle, sandwiched between Hadamards on an ancilla, outputs the ancilla in ∣0⟩|0\rangle with probability P0=12+12∣⟨ψ∣ϕ⟩∣2P_0=\tfrac12+\tfrac12|\langle\psi|\phi\rangle|^2. Evaluate it for identical, orthogonal, and half-overlapping states.

Step 1. Identical states, ∣ψ⟩=∣ϕ⟩|\psi\rangle=|\phi\rangle: the overlap is ∣⟨ψ∣ψ⟩∣2=1|\langle\psi|\psi\rangle|^2=1, so P0=12+12(1)=1P_0=\tfrac12+\tfrac12(1)=\mathbf{1}. The ancilla never reads 11 — a certain "same" outcome.

Step 2. Orthogonal states, e.g. ∣ψ⟩=∣0⟩|\psi\rangle=|0\rangle, ∣ϕ⟩=∣1⟩|\phi\rangle=|1\rangle: the overlap is ∣⟨0∣1⟩∣2=0|\langle0|1\rangle|^2=0, so P0=12+12(0)=0.5P_0=\tfrac12+\tfrac12(0)=\mathbf{0.5}. The ancilla is a fair coin — the maximally "different" signal.

Step 3. Half-overlapping states, ∣ψ⟩=∣0⟩|\psi\rangle=|0\rangle, ∣ϕ⟩=∣+⟩=12(∣0⟩+∣1⟩)|\phi\rangle=|+\rangle=\tfrac{1}{\sqrt2}(|0\rangle+|1\rangle): the overlap is ∣⟨0∣+⟩∣2=∣12∣2=12|\langle0|+\rangle|^2=|\tfrac{1}{\sqrt2}|^2=\tfrac12, so P0=12+12(12)=34=0.75P_0=\tfrac12+\tfrac12(\tfrac12)=\tfrac34=\mathbf{0.75}.

Step 4. Invert to read the physics: measuring P0P_0 over many shots gives ∣⟨ψ∣ϕ⟩∣2=2P0−1|\langle\psi|\phi\rangle|^2=2P_0-1, ranging from 11 (identical) through 00 (orthogonal). The SWAP test turns a swap's ±1\pm1 eigenvalue structure into a direct, destructive-test-free estimate of fidelity — the reason it anchors quantum kernel methods and entanglement diagnostics.

Physics of the portrait

SWAP is not named for a person, but its deepest identity is: the operator 12(I+σ⃗1⋅σ⃗2)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2) is the isotropic Heisenberg exchange, the interaction Werner Heisenberg introduced in 1926 to explain why identical particles feel a force with no classical analogue. The gate a compiler inserts to route a qubit is, physically, a full turn of that same exchange clock.

Origins · 1 minWerner Heisenberg and how this was discovered
WH
Werner Heisenberg
1901–1976 · the exchange interaction whose isotropic form ½(I + σ₁·σ₂) is the SWAP operator

Werner Heisenberg was, at twenty-three, the author of the matrix mechanics that launched modern quantum theory, and at twenty-six the discoverer of the uncertainty principle that bears his name — but the thread that reaches the SWAP gate is his 1926 work on the exchange interaction. Puzzling over the spectrum of helium, Heisenberg realised that the indistinguishability of the two electrons forces their joint wavefunction to be antisymmetric, and that this symmetry requirement produces an energy splitting — between symmetric (para) and antisymmetric (ortho) spatial states — that has no counterpart in classical physics and is far larger than any magnetic dipole coupling. Recast in spin language, the resulting effective interaction is H=−J σ⃗1⋅σ⃗2H=-J\,\vec\sigma_1\cdot\vec\sigma_2, the Heisenberg exchange, and in 1928 he built it into the first quantum theory of ferromagnetism, explaining how a material can magnetise itself. Paul Dirac soon sharpened the algebra, writing the exchange as a genuine permutation operator, 12(1+σ⃗1⋅σ⃗2)\tfrac12(1+\vec\sigma_1\cdot\vec\sigma_2) — which is precisely the SWAP gate. Heisenberg received the 1932 Nobel Prize in Physics, and his later career was shadowed by his leadership of the German wartime nuclear program, a role still debated by historians. The physics endures cleanly: every exchange-coupled spin qubit runs on his interaction, and the quarter-turn of that coupling, SWAP\sqrt{\mathrm{SWAP}}, is the entangling gate of an entire hardware platform. The gate is an unnamed monument to the idea that exchanging identical particles is itself a physical operation.

History
1926
— Heisenberg identifies the exchange interaction behind the helium spectrum and, soon after, magnetism
1929
— Dirac writes spin exchange as the permutation operator ½(1 + σ₁·σ₂), i.e. the SWAP operator
1982
— Fredkin and Toffoli define the controlled-SWAP as a conservative reversible logic gate
1998
— Loss and DiVincenzo propose exchange-coupled spin qubits whose native two-qubit gate is √SWAP
2001
— Buhrman, Cleve, Watrous and de Wolf introduce the SWAP test for estimating state overlap

Going further

Texts. Nielsen & Chuang, Quantum Computation and Quantum Information, §1.3.4 (circuit basics) and §4.3 (controlled operations and the three-CNOT SWAP) · Preskill, Lecture Notes for Physics 219, Ch. 5 · Watrous, The Theory of Quantum Information, Ch. 2 · Wilde, Quantum Information Theory, Ch. 3 (the SWAP test) · Kitaev, Shen & Vyalyi, Classical and Quantum Computation, §8 · Mermin, Quantum Computer Science, Ch. 2. The key results in this article are: (i) the three-CNOT product CNOT1→2 CNOT2→1 CNOT1→2=SWAP\mathrm{CNOT}_{1\to2}\,\mathrm{CNOT}_{2\to1}\,\mathrm{CNOT}_{1\to2}=\mathrm{SWAP}, confirmed by direct 4×44\times4 multiplication; (ii) the Pauli and Dirac forms 12(II+XX+YY+ZZ)=12(I+σ⃗1⋅σ⃗2)=SWAP\tfrac12(II+XX+YY+ZZ)=\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2)=\mathrm{SWAP}, with spectrum {+1,+1,+1,−1}\{+1,+1,+1,-1\}, Tr⁡=2\operatorname{Tr}=2, det⁡=−1\det=-1; (iii) the partial-swap concurrence C=∣sin⁡2θ∣C=|\sin 2\theta|, with SWAP\sqrt{\mathrm{SWAP}} giving C=1C=1 on ∣01⟩|01\rangle; (iv) the SWAP-test probability P0=12+12∣⟨ψ∣ϕ⟩∣2P_0=\tfrac12+\tfrac12|\langle\psi|\phi\rangle|^2, evaluating to P0=1,0.75,0.5P_0=1,0.75,0.5 for overlaps 1,12,01,\tfrac12,0. The identification of 12(I+σ⃗1⋅σ⃗2)\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2) with the Heisenberg exchange is Dirac's spin-exchange identity.

Prerequisites. The CNOT Gate · The Quantum Circuit Model · Pauli Gates (X, Y, Z) · Controlled-U Gates. Leads to. Circuit Identities and Equivalences · Universal Gate Sets · The Controlled-Z Gate.

Ask the tutor: ask me to thread a basis state through the three CNOTs, watch SWAP\sqrt{\mathrm{SWAP}} build a Bell pair, or work out the SWAP-test probability for any two states you choose.

Is the SWAP gate an entangling gate or not?

No — and this is the single most common confusion about it. SWAP is a genuine two-qubit gate, meaning no product of single-qubit gates can reproduce it, but acting on a product state it simply relabels which wire holds which factor: SWAP(∣ψ⟩⊗∣ϕ⟩)=∣ϕ⟩⊗∣ψ⟩\mathrm{SWAP}(|\psi\rangle\otimes|\phi\rangle)=|\phi\rangle\otimes|\psi\rangle, still a product. Its entangling power is exactly zero. What is entangling is its square root: SWAP\sqrt{\mathrm{SWAP}} turns ∣01⟩|01\rangle into a maximally entangled state. The whole family e−iθ SWAPe^{-i\theta\,\mathrm{SWAP}} has entangling power ∣sin⁡2θ∣|\sin 2\theta|, which vanishes at θ=0\theta=0 (identity) and θ=π/2\theta=\pi/2 (full SWAP) but is maximal at θ=π/4\theta=\pi/4. So "two-qubit gate" and "entangling gate" are not synonyms, and SWAP is the textbook proof.

Why exactly three CNOTs, and why must they alternate direction?

Three is the minimum, and alternation is essential. Two CNOTs in the same direction cancel, since CNOT1→22=I\mathrm{CNOT}_{1\to2}^2=I; two in opposite directions leave a residual entangling structure that is not the swap. The three-CNOT circuit works because it is the reversible version of the classical XOR-swap: XOR qubit 1 into 2, then 2 into 1, then 1 into 2 again, and the two a⊕a=0a\oplus a=0 cancellations conspire to leave ∣a,b⟩↦∣b,a⟩|a,b\rangle\mapsto|b,a\rangle with no scratch space. That three is a genuine lower bound follows from CNOT-counting arguments: SWAP is the "hardest" permutation to build, and any correct circuit needs at least three CNOTs. On real hardware this is why routing is expensive — every wire crossing you insert costs three of your noisiest gates.

What does it mean that SWAP is the Heisenberg exchange operator?

The identity SWAP=12(I+σ⃗1⋅σ⃗2)\mathrm{SWAP}=\tfrac12(I+\vec\sigma_1\cdot\vec\sigma_2) says the gate is, up to a constant, the isotropic Heisenberg coupling σ⃗1⋅σ⃗2\vec\sigma_1\cdot\vec\sigma_2 between two spins — the interaction Heisenberg introduced to explain atomic spectra and ferromagnetism. Physically, the antisymmetry requirement on identical particles produces an effective spin–spin coupling whose Hamiltonian is −J σ⃗1⋅σ⃗2-J\,\vec\sigma_1\cdot\vec\sigma_2; letting that Hamiltonian evolve for a time is exactly applying the partial swap e−iθ SWAPe^{-i\theta\,\mathrm{SWAP}}. This is not a metaphor: in spin-qubit hardware you literally turn on the exchange coupling between two electrons, and the swap you get is the physics of the exchange interaction, not a compiled abstraction. The gate and the many-body interaction are the same operator wearing two hats.

Why is √SWAP called a universal gate when SWAP is not?

Universality is about what you can build. The full SWAP, together with single-qubit gates, cannot generate all two-qubit unitaries, because it never entangles — you would be stuck with products of local operations and relabellings. But SWAP\sqrt{\mathrm{SWAP}} is entangling, and a general theorem says that almost any single entangling two-qubit gate, combined with arbitrary single-qubit gates, is universal — it can approximate any unitary on any number of qubits to arbitrary precision. So {SWAP, single-qubit gates}\{\sqrt{\mathrm{SWAP}},\ \text{single-qubit gates}\} is a universal set, which matters because SWAP\sqrt{\mathrm{SWAP}} is the native gate of exchange-coupled spin qubits. You do not have to compile a CNOT; the hardware hands you a universal entangler directly.

What is the SWAP test actually measuring, and why is it useful?

The SWAP test estimates the overlap ∣⟨ψ∣ϕ⟩∣2|\langle\psi|\phi\rangle|^2 between two unknown quantum states without ever measuring the states destructively in a fixed basis. You put an ancilla in ∣0⟩|0\rangle, apply a Hadamard, use it to control a SWAP between the two registers, apply a second Hadamard, and measure the ancilla: it reads 00 with probability 12+12∣⟨ψ∣ϕ⟩∣2\tfrac12+\tfrac12|\langle\psi|\phi\rangle|^2. The mechanism is interference on the ancilla, driven by the fact that SWAP has eigenvalue +1+1 on symmetric and −1-1 on antisymmetric combinations of the two registers. Averaging over shots gives the fidelity between the states, which is why the SWAP test underlies quantum kernel methods in machine learning, fidelity estimation, and entanglement witnesses. It converts a spectral property of the swap into a laboratory number.

Why does SWAP dominate the cost of compiling circuits to real hardware?

Because real devices are sparsely connected. A two-qubit gate can only be applied between qubits that share a physical coupler, so any algorithm calling for a gate between non-adjacent qubits must first move one of them next to the other — and the only way to move a qubit's state is to SWAP it, step by step, along the coupling graph. Each SWAP costs three CNOTs, the slowest and noisiest operations available, so a handful of long-range gates can balloon into dozens of extra CNOTs' worth of routing. Choosing which qubits to place where, and which SWAPs to insert, to minimise this overhead is the qubit mapping and routing problem, which is NP-hard; it is where transpilers spend most of their time and where much of a circuit's final error accumulates. Better connectivity and smarter routing are two of the main levers for improving near-term performance.

Before this

Where this leads