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}

        
          version 1.0
qubits  4
X q[1] # bring qubit 1 to the |1> state
X q[2] # bring qubit 2 to the |1> state
H q[3] # bring qubit 3 to the|+> state
display #display qubit state
Toffoli q[1], q[2], q[3]
display #display qubit state
Toffoli q[0], q[1], q[3]
display #display qubit state
        
      
q[0]
 
 
 
 
 
q[1]
 
 
 
 
 
q[2]
 
 
 
 
 
q[3]
 
 
 
 
 

Note. On most hardware backends, a Toffoli gate cannot be implemented directly, but needs to be compiled to single- and two-qubit gates and mapped onto the qubit topology.

For more information see Toffoli gate on Wikipedia.