Sign in
← Atlas
Exact & formalGatesMulti-controlled gate

Fredkin (CSWAP) gate

A three-qubit controlled-swap gate that conditionally exchanges two target qubits, useful for reversible routing logic and as a component of the SWAP test for state overlap.

fredkinconditional swapthree qubitconservative logic

Atlas stars stay in the public catalog. Saving this entry to your workspace starts an unstarred private copy.

Fredkin is the conditional-routing counterpart to Toffoli's conditional-logic: instead of computing a Boolean function it moves data, and unlike Toffoli it is also conservative (it preserves the total Hamming weight of the two target bits).

Circuit & simulation
control=1: |1,0,1⟩ → |1,1,0⟩100%
control=0: targets unchanged100%
What this takes and returns
Takes3 qubitsWhat joins here

Takes a 3-qubit register and states no assumption about what is on it. That is the whole condition: anything returning 3 qubits can feed it.

3 entries meet this end · 1 entry lines up on shape, composition unverified. Named below.

Returns3 qubitsWhat joins here

Returns a 3-qubit register a next stage can take. This is the end that joins.

2 entries meet this end · 14 entries line up on shape, composition unverified. Named below.

A unitary. The same register goes in and comes out, and this entry states no assumption about what is on it — which is what lets anything of the same width feed it. See all 29 →

Shapes fit before this, composition unverified 1

The widths and types line up. What is not established is everything a width does not carry — the basis convention, the normalisation, the state each was written to start from — so this is not a claim that the two compose.

How it works

Definition

CSWAPc,a,b=c,(1c)a+cb,(1c)b+ca={c,a,bc=0c,b,ac=1\mathrm{CSWAP}|c,a,b\rangle = |c,\, (1-c)a + cb,\, (1-c)b + ca\rangle = \begin{cases} |c,a,b\rangle & c=0 \\ |c,b,a\rangle & c=1 \end{cases}

As an 8×88\times 8 permutation matrix, CSWAP\mathrm{CSWAP} is the identity on the four c=0c=0 basis states and the identity except for exchanging 101110|101\rangle\leftrightarrow|110\rangle on the c=1c=1 block (the 100|100\rangle and 111|111\rangle states, having a=ba=b, are unaffected by the swap).

Action and conservation law

Unlike Toffoli, which computes a genuinely new bit (the AND), CSWAP\mathrm{CSWAP} only ever permutes its two target bits. This makes it conservative: the Hamming weight of the two target qubits is invariant under CSWAP\mathrm{CSWAP}, a structural property Fredkin and Toffoli's original 1982 paper on conservative reversible logic used to model computation with a fixed particle count.

Decomposition

The naive decomposition is a CNOT–Toffoli–CNOT sandwich (target bb CNOT-copied onto aa's role, a Toffoli implementing the conditional exchange, then the CNOT undone) — 2 CNOTs plus 1 Toffoli, which itself costs 6 more CNOTs. Smolin and DiVincenzo (1996) improved on this with an explicit five-two-qubit-gate construction, showing the naive count is not optimal and giving numerical evidence that five is minimal.

Key identities

  • CSWAP2=I\mathrm{CSWAP}^2 = I: applying the same controlled-swap twice restores the input.
  • CSWAP\mathrm{CSWAP} is the core primitive of the SWAP test: preparing a control qubit in +|+\rangle, applying CSWAP\mathrm{CSWAP} between two unknown states, then measuring the control in the XX basis estimates ψϕ2|\langle\psi|\phi\rangle|^2 without ever measuring ψ|\psi\rangle or ϕ|\phi\rangle directly.
  • Like Toffoli, CSWAP\mathrm{CSWAP} has no native two-qubit hardware realization and must be compiled from the elementary gate set for execution.
Implementation
Native
fredkin-cswap.qasm
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
x q[0];
x q[2];
cswap q[0], q[1], q[2];
Quantum vs classical

Classical baseline

Use a classical state-vector or matrix simulation at the same width, precision, and measurement objective.

Quantum claim

The quantum record demonstrates a state or operator behavior; it does not make classical simulation or communication costs disappear.

How to compare

Compare fidelity, samples, gate depth, noise, memory, and the cost of preparing and reading the state.

Declared gaps

Nobody has reviewed this record for gaps yet.

Literature & references
Five two-bit quantum gates are sufficient to implement the quantum Fredkin gate1996 · John A. Smolin, David P. DiVincenzo

Gives a five two-qubit-gate construction of the Fredkin (CSWAP) gate, improving on the naive CNOT–Toffoli–CNOT sandwich.

doi.org/10.1103/physreva.53.2855
Elementary gates for quantum computation1995 · Adriano Barenco, Charles H. Bennett, Richard Cleve, David P. DiVincenzo, Norman Margolus, Peter Shor, Tycho Sleator, John A. Smolin, Harald Weinfurter

Shows that single-qubit U(2) gates plus CNOT are universal and gives explicit decompositions for controlled-U, Toffoli, and Fredkin gates.

arxiv.org/abs/quant-ph/9503016