SWAP Gate
The SWAP gate does the most physically intuitive thing two qubits can do: it interchanges the states carried by two wires, sending to 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 it is the permutation that transposes the middle two amplitudes and fixes . 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 and the antisymmetric (singlet) carries , so and . Written over the Pauli basis it is , 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 , unlike the full swap, is maximally entangling and, with single-qubit gates, universal.
- The SWAP gate exchanges its two inputs, ; its matrix interchanges the and amplitudes and fixes .
- It is real, symmetric, Hermitian, unitary and involutory (), with eigenvalues (triplet, threefold) and (singlet, once), so and .
- It factors into exactly three alternating CNOTs, — the reversible XOR-swap, and three is the provable minimum.
- Over the Pauli basis it is , exactly the isotropic Heisenberg exchange operator.
- SWAP creates no entanglement from a product state, but the partial swap has concurrence , peaking at where is maximally entangling and universal.
- Key idea: SWAP is the exchange operator that swaps the and amplitudes; it factors into three alternating CNOTs, never entangles a product state, yet its square root maximally entangles.
SWAP is the exchange operator that swaps the amplitudes of and ; it factors into three alternating CNOTs and, though it never entangles a product state, its square root 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, tket, 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 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.
Spectrally, SWAP is the exchange operator borrowed straight from many-body physics. It must act as on any state symmetric under interchange and on the antisymmetric singlet — that is what "swap the labels" means — so its eigenvalues are forced to be , and it is exactly , the isotropic Heisenberg coupling. That connection is where the deepest surprise lives. Because , the gate is an involution, and its square root is well defined — a "half exchange." A full exchange never entangles, but the half exchange turns a product state into a maximally entangled one. The continuous family interpolates smoothly between them, and its entangling power rises from nothing at , to a maximum at , and back to nothing at — the second figure makes this non-monotonic story quantitative.
The core equations
Everything begins with the explicit matrix in the computational basis, ordering rows and columns as . Reading the entries directly shows it is a permutation that leaves untouched and interchanges the two "one excitation" states.
where: rows and columns run over the ordered basis ; the off-diagonal 's move the and amplitudes onto each other. The reading: the matrix is real and symmetric, so ; 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.
where: — the computational-basis values of the two qubits. The reading: on a product input the output is , 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.
where: — a CNOT with control qubit and target qubit . 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.
where: — the single-qubit Pauli operators; — the single-qubit identity. The reading: the coefficients are fixed by orthogonality of the Pauli basis, and the appearance of — with no singled out — is what makes this the isotropic exchange. The same identity, rewritten with the Pauli vector , exposes SWAP as the Heisenberg exchange operator of two spins — the bridge to condensed-matter physics and to the portrait below.
where: — the dot product of the two spin operators, with eigenvalue on the triplet and on the singlet. The reading: this is Dirac's spin-exchange identity; the Heisenberg Hamiltonian is, up to a constant, , 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).
where: — conjugate transpose; — the identity. The reading: Hermiticity makes SWAP a legitimate observable with eigenvalues ; combined with unitarity it forces the involution , 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.
where: the eigenvalue (multiplicity 3) belongs to the symmetric triplet subspace; the eigenvalue (multiplicity 1) belongs to the antisymmetric singlet. The reading: and , both matching the explicit matrix. Finally, because , the exponential closes into a two-term formula, generating the continuous family of partial swaps that contains .
where: — the exchange angle; gives , and gives up to a global phase. The reading: the full swap sits at and the identity at ; halfway between, at , the gate is maximally entangling.
The goal is to prove the compilation identity directly, by tracking an arbitrary basis state through the three gates and watching the reversible XOR-swap thread the two bit-values through each other. Because a CNOT with control and target replaces the target by its XOR with the control and leaves the control alone, the whole calculation is bookkeeping in the field , using only and . 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: and . Why: capturing both CNOTs as a single XOR rule lets the composition be done as arithmetic on bits rather than as three matrix products.
Step 2. Apply the rightmost gate, , to : the target picks up the control, giving . Why: reading a circuit right to left, the first physical operation writes the parity onto the second wire while the first is untouched.
Step 3. Apply : now qubit 2 (holding ) controls qubit 1, sending to , since . Why: this is the middle move of the XOR-swap — the first register is overwritten with , and the cancellation is the whole reason the trick needs no scratch qubit.
Step 4. Apply the last : qubit 1 (now ) controls qubit 2, giving , again by . This is 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, is equally a valid SWAP. *Direct multiplication of the three 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
The aim is to read the eigenvalues of SWAP without diagonalising a matrix, by using the fact that "exchange the two labels" acts as on symmetric states and on antisymmetric ones, and then cross-checking against the Dirac form . The payoff is conceptual: the numbers , , 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, — 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 : swapping the labels gives , so its eigenvalue is . Why: the singlet is the one antisymmetric combination, and antisymmetry under exchange is precisely the eigenvalue condition.
Step 3. Test the triplet: and are manifestly fixed, and maps to itself, so all three carry eigenvalue . Why: symmetric states are unchanged by relabelling, giving the threefold eigenspace and completing the count .
Step 4. Cross-check with the Dirac form: has eigenvalue on the triplet and on the singlet, so gives and , and the invariants are , . 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 with multiplicities match and ; and 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
The purpose is to compute the entangling power of the whole partial-swap family on a product input and to show that the concurrence is — 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 , 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 : the series closes to . 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 , for which : the output is . Why: the gate mixes only the subspace, so a single-excitation product input stays inside that two-dimensional block, making the amplitudes trivially readable.
Step 3. Evaluate the concurrence with , , and : this gives . 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 the gate is and ; at it is the full SWAP and again; at it is and , 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 gives and ; applying the explicit matrix of (8) to gives , whose concurrence is .*
Limiting cases
Special inputs and parameter limits make SWAP's split personality — inert relabeller here, maximal entangler a quarter-turn away — concrete.
| Case | Result | Meaning |
|---|---|---|
| Product input | The factors are exchanged; no entanglement is created. | |
| Symmetric input | The triplet is the eigenspace. | |
| Antisymmetric input | The singlet is the unique eigenstate, giving . | |
| Half swap () | has concurrence on | Maximally entangling; with single-qubit gates it is a universal set. |
| Full swap () | , | Back 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 to the product state 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 . Check the norm: , a valid state.
Step 2. Read the amplitudes into the concurrence : here , , , so . Then . The output is maximally entangled — locally equivalent to a Bell state.
Step 3. Contrast the full SWAP: , a product state, with and every other amplitude zero, so . 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 as up to phase, the concurrence should be , and the full swap at gives . 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 , sandwiched between Hadamards on an ancilla, outputs the ancilla in with probability . Evaluate it for identical, orthogonal, and half-overlapping states.
Step 1. Identical states, : the overlap is , so . The ancilla never reads — a certain "same" outcome.
Step 2. Orthogonal states, e.g. , : the overlap is , so . The ancilla is a fair coin — the maximally "different" signal.
Step 3. Half-overlapping states, , : the overlap is , so .
Step 4. Invert to read the physics: measuring over many shots gives , ranging from (identical) through (orthogonal). The SWAP test turns a swap's 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 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
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 , 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, — 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, , 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.
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 , confirmed by direct multiplication; (ii) the Pauli and Dirac forms , with spectrum , , ; (iii) the partial-swap concurrence , with giving on ; (iv) the SWAP-test probability , evaluating to for overlaps . The identification of 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 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: , still a product. Its entangling power is exactly zero. What is entangling is its square root: turns into a maximally entangled state. The whole family has entangling power , which vanishes at (identity) and (full SWAP) but is maximal at . 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 ; 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 cancellations conspire to leave 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 says the gate is, up to a constant, the isotropic Heisenberg coupling 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 ; letting that Hamiltonian evolve for a time is exactly applying the partial 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 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 is a universal set, which matters because 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 between two unknown quantum states without ever measuring the states destructively in a fixed basis. You put an ancilla in , apply a Hadamard, use it to control a SWAP between the two registers, apply a second Hadamard, and measure the ancilla: it reads with probability . The mechanism is interference on the ancilla, driven by the fact that SWAP has eigenvalue on symmetric and 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.