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:
For more information see Toffoli gate on Wikipedia.
It can be decomposed as follows:
Fredkin gate
The Fredkin gate, also known as the Controlled-SWAP gate, is a three-qubit operation defined by:
For more information see Fredkin gate on Wikipedia.
A standard decomposition that uses adjacent 9 CNOT gates is:
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.
The decomposition requires only 3 CNOTs: