Three-qubit gates

Some standard three-qubit gates, such as the Toffoli gate, the Fredkin gate and the Margolus gate, are often used in Quantum Computing. In the current version of cQASM, three-qubit gates such as Toffoli, Fredkin and Margolus are not part of of the language (yet). In order to use these gates, you need to use a version of the gates which is already decomposed into standard two-qubit gates. For your convenience we provide some standard decompsitions below for these gates, which you can simply copy and paste in your code. With OpenSquirrel, you can use the circuit builder to plug in these decompositions.

Depending on the connectivity of the backend, other, more efficient decompositions might be available.

Toffoli gate

The Toffoli gate, also known as the Controlled-Controlled NOT gate, is a three-qubit operation defined by:

 Toffoli=(1000000001000000001000000001000000001000000001000000000100000010)\ Toffoli= \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}

For more information see Toffoli gate on Wikipedia.

It can be decomposed as follows:

Export visualization

File format
Layout
Theme

Fredkin gate

The Fredkin gate, also known as the Controlled-SWAP gate, is a three-qubit operation defined by:

 Toffoli=(1000000001000000001000000001000000001000000000100000010000000001)\ Toffoli= \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}

For more information see Fredkin gate on Wikipedia.

A standard decomposition that uses adjacent 9 CNOT gates is:

Export visualization

File format
Layout
Theme

Margolus gate

The Margolus gate, which is sometimes referred to as the 'simplified' Toffoli gate, is equivalent to the Toffoli gate u to a single change of sign in the diagonal. Note that in quantum algorithms you cannot simply replace a Toffoli by a Margolus gate, because the phase change of one of the status is relevant form most algorithms.

 Margolus=(1000000001000000001000000001000000001000000001000000000100000010)\ Margolus= \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}

The decomposition requires only 3 CNOTs:

Export visualization

File format
Layout
Theme