Quantum Circuits Library: Three-qubit gates

ToffoliGate

QuantumCircuitOpt.ToffoliGateFunction
ToffoliGate()

Three-qubit Toffoli gate, also known as the CCX (controlled-controlled-NOT) gate.

Circuit Representation

q_0: ──■──
       │
q_1: ──■──
     ┌─┴─┐
q_2: ┤ X ├
     └───┘

Matrix Representation

\[Toffoli = |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes CXGate = \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 & 1 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\]

source

CSwapGate

QuantumCircuitOpt.CSwapGateFunction
CSwapGate()

Three-qubit, controlled SwapGate, also known as the Fredkin gate.

Circuit Representation

q_0: ─■─
      │
q_1: ─X─
      │
q_2: ─X─

Matrix Representation

\[CSwapGate = \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}\]

source

CCZGate

QuantumCircuitOpt.CCZGateFunction
CCZGate()

Three-qubit controlled-controlled Z gate.

Circuit Representation

q_0: ─■─
      │
q_1: ─■─
      │
q_2: ─■─

Matrix Representation

\[CCZGate = \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 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \\ \end{pmatrix}\]

source

PeresGate

QuantumCircuitOpt.PeresGateFunction
PeresGate()

Three-qubit Peres gate. This gate is equivalent to ToffoliGate followed by the CNotGate in 3 qubits. Reference: https://doi.org/10.1103/PhysRevA.32.3266

Circuit Representation

q_0: ──■─────■──          
       │   ┌─┴─┐
q_1: ──■───┤ X ├
     ┌─┴─┐ └───┘
q_2: ┤ X ├──────
     └───┘

Matrix Representation

\[PeresGate = \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 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ \end{pmatrix}\]

source

RCCXGate

QuantumCircuitOpt.RCCXGateFunction
RCCXGate()

Three-qubit relative (or simplified) Toffoli gate, or the CCX gate. This gate is equivalent to ToffoliGate upto relative phases. The advantage of this gate is that it's implementation requires only three CNot (or CX) gates. Reference: https://arxiv.org/pdf/1508.03273.pdf

Matrix Representation

\[RCCXGate = \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 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -i \\ 0 & 0 & 0 & 0 & 0 & 0 & i & 0 \\ \end{pmatrix}\]

source

MargolusGate

QuantumCircuitOpt.MargolusGateFunction
MargolusGate()

Three-qubit Margolus gate, which is a simplified ToffoliGate and coincides with the Toffoli gate up to a single change of sign. The advantage of this gate is that its implementation requires only three CNot (or CX) gates. Reference: https://arxiv.org/pdf/quant-ph/0312225.pdf

Matrix Representation

\[MargolusGate = \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 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{pmatrix}\]

source

CiSwapGate

QuantumCircuitOpt.CiSwapGateFunction
CiSwapGate()

Three-qubit controlled version of the iSwapGate. Reference: https://doi.org/10.1103/PhysRevResearch.2.033097

Circuit Representation

q_0: ─────■─────
          │
      ┌───────┐
q_1: ─┤       ├─
      │ iSwap │   
q_2: ─┤       ├─ 
      └───────┘ 

Matrix Representation

\[CiSwapGate = \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 & i & 0 \\ 0 & 0 & 0 & 0 & 0 & i & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}\]

source