- Quantum Gates, Logic & Matrix -

Toffoli Gate (CCNOT)

In computer science, the Toffoli gate (also CCNOT gate), invented by Tommaso Toffoli, is a universal reversible logic gate, which means that any reversible circuit can be constructed from Toffoli gates. It is also known as the "controlled-controlled-not" gate, which describes its action.

A logic gate L is reversible if, for any output y, there is a unique input x such that applying L(x) = y. If a gate L is reversible, there is an inverse gate L′ which maps y to x for which L′(y) = x. From common logic gates, NOT is reversible, as can be seen from its truthtable below.
INPUTOUTPUT
01
10
The common AND gate is not reversible however. The inputs 00, 01 and 10 are all mapped to the output 0.
Reversible gates have been studied since the 1960s. The original motivation was that reversible gates dissipate less heat (or, in principle, no heat). In a normal gate, input states are lost, since less information is present in the output than was present at the input. This loss of information loses energy to the surrounding area as heat, because ofthermodynamic entropy. Another way to understand this is that charges on a circuit are grounded and thus flow away, taking a small quantity of energy with them when they change state. A reversible gate only moves the states around, and since no information is lost, energy is conserved.
More recent motivation comes from quantum computing. Quantum mechanics requires the transformations to be reversible but allows more general states of the computation (superpositions). Thus, the reversible gates form a subset of gates allowed by quantum mechanics and, if we can compute something reversibly, we can also compute it on a quantum computer.

## Universal Gate Any reversible gate must have the same number of input and output bits, by the pigeonhole principle. For one input bit, there are two possible reversible gates. One of them is NOT. The other is the identity gate which maps its input to the output unchanged. For two input bits, the only non-trivial gate is the controlled NOT gate which XORs the first bit to the second bit and leaves the first bit unchanged.

Truth table    Matrix form
INPUTOUTPUT
0  0  0  0
0101
1011
1110
$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}$
Unfortunately, there are reversible functions that cannot be computed using just those gates. In other words, the set consisting of NOT and XOR gates is not universal (see Functional completeness). If we want to compute an arbitrary function using reversible gates, we need another gate. One possibility is the Toffoli gate, proposed in 1980 by Toffoli.
This gate has 3-bit inputs and outputs. If the first two bits are set, it flips the third bit. The following is a table of the input and output bits:
Truth table                   Matrix form
INPUTOUTPUT
0
001001
010010
011011
100100
101101
110111
111110
$\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 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix}$
It can be also described as mapping bits a, b and c to a, b and c XOR (a AND b).
The Toffoli gate is universal; this means that for any Boolean function f(x1x2, ..., xm), there is a circuit consisting of Toffoli gates which takes x1x2, ..., xm and some extra bits set to 0 or 1 and outputs x1x2, ..., xmf(x1x2, ..., xm), and some extra bits (called garbage). Essentially, this means that one can use Toffoli gates to build systems that will perform any desired Boolean function computation in a reversible manner.

Fredkin Gate

The Fredkin gate (also CSWAP gate) is a computational circuit suitable for reversible computing, invented by Ed Fredkin. It is universal, which means that any logical or arithmetic operation can be constructed entirely of Fredkin gates. The Fredkin gate is the three-bit gate that swaps the last two bits if the first bit is 1.
The basic Fredkin gate is a controlled swap gate that maps three inputs (CI1I2) onto three outputs (CO1O2). The C input is mapped directly to the C output. If C = 0, no swap is performed; I1 maps to O1, and I2 maps to O2. Otherwise, the two outputs are swapped so that I1 maps to O2, and I2 maps to O1. It is easy to see that this circuit is reversible, i.e., "undoes itself" when run backwards. A generalized n×n Fredkin gate passes its first n-2 inputs unchanged to the corresponding outputs, and swaps its last two outputs if and only if the first n-2 inputs are all 1.
The Fredkin gate is the reversible three-bit gate that swaps the last two bits if the first bit is 1.
Truth tableMatrix form
INPUTOUTPUT
CI1I2CO1O2
0  0  0  0  0  0
001001
010010
011011
100100
101110
110101
111111
$\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}$
It has the useful property that the numbers of 0s and 1s are conserved throughout, which in the billiard ball model means the same number of balls are output as input. This corresponds nicely to the conservation of mass in physics, and helps to show that the model is not wasteful.

CNOT Gate

In computing science, the controlled NOT gate (also C-NOT or CNOT) is a quantum gate that is an essential component in the construction of a quantum computer. It can be used to disentangle EPR states. Specifically, any quantum circuit can be simulated to an arbitrary degree of accuracy using a combination of CNOT gates and single qubit rotations.

The CNOT gate flips the second qubit (the target qubit) if and only if the first qubit (the control qubit) is 1.
BeforeAfter
ControlTargetControlTarget
0000
0101
1011
1110
The resulting value of the second qubit corresponds to the result of a classical XOR gate.
The CNOT gate can be represented by the matrix:
$\operatorname{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}.$
The first experimental realization of a CNOT gate was accomplished in 1995. Here, a single Beryllium ion in a trap was used. The two qubits were encoded into an optical state and into the vibrational state of the ion within the trap. At the time of the experiment, the reliability of the CNOT-operation was measured to be on the order of 90%.

Transpose Matrix

In linear algebra, the transpose of a matrix A is another matrix AT (also written A′, Atr or At) created by any one of the following equivalent actions:

• reflect A over its main diagonal (which runs top-left to bottom-right) to obtain AT
• write the rows of A as the columns of AT
• write the columns of A as the rows of AT
$\begin{bmatrix} 1 & 2 \end{bmatrix}^{\mathrm{T}} = \, \begin{bmatrix} 1 \\ 2 \end{bmatrix}$
$\begin{bmatrix} 1 & 2 & 8 \\ 3 & 4 & 3 \\ 5 & 6 & 1 \end{bmatrix}^{\mathrm{T}} = \begin{bmatrix} 1 & 3 & 5\\ 2 & 4 & 6\\ 8 & 3 & 1 \end{bmatrix}$

Unitary Identity Matrix

In linear algebra, the identity matrix or unit matrix of size n is the n × n square matrix with ones on the main diagonal and zeros elsewhere. It is denoted by In, or simply by I if the size is immaterial or can be trivially determined by the context. (In some fields, such as quantum mechanics, the identity matrix is denoted by a boldface one, 1; otherwise it is identical to I.)

Unitary Matrix

In mathematics, a complex square matrix U is unitary if,

Where I is the identity matrix and U* is the conjugate transpose of U.