controlled 3 qubits
Fredkin
Controlled swap of two target qubits conditioned on a single control qubit.
The Fredkin (CSWAP) gate swaps the two target qubits when the control qubit is in the $|1\rangle$ state, and acts as identity when the control is $|0\rangle$.
$$ \mathrm{CSWAP} = \begin{bmatrix} 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{bmatrix} $$
Properties
- Self-inverse and Hermitian: $\mathrm{CSWAP}^\dagger = \mathrm{CSWAP}$.
- Classical reversible and conservative; it preserves Hamming weight in the computational basis.
- Can be decomposed into CNOT and Toffoli gates or into a small set of two-qubit gates.
Usage
- Conditional routing and permutation of qubits in a circuit.
- Reversible classical logic and quantum algorithms that require controlled swaps.
The unitary, drawn
Every entry of the matrix as a disc. The area is the transition probability $|U_{jk}|^2$; the colour and the hand are the phase. Rows are outputs $\langle j|$, columns inputs $|k\rangle$, in the computational basis.
Phase
Disc area $= |U_{jk}|^2$. Hover an entry for its value, or take the JSON.
SDK support
How to call this gate in each framework. Hover a ⓘ for a note; the support matrix compares every gate at once.
| SDK | Name |
|---|---|
| Qiskit | qiskit.circuit.library.CSwapGate |
| PennyLane | pennylane.CSWAP |
| Cirq | cirq.CSWAP ⓘ |
| Q# | — ⓘ |
| PyQuil | pyquil.gates.CSWAP |
| Braket | braket.circuits.gates.CSwap |
| BQSKit | — ⓘ |
| Qibo | — ⓘ |
| pytket | pytket.circuit.OpType.CSWAP |
| Stim | — |
| OpenQASM | stdgates.inc: cswap |