Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Toffoli gate

From Wikipedia, the free encyclopedia


Jump to: navigation, search

Circuit representation of Toffoli gate

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.

Contents
[hide]

• 1 Background
• 2 Universality and Toffoli gate
• 3 Related logic gates
• 4 Relation to quantum computing
• 5 See also

• 6 References

[edit] Background
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(x) = y. From common logic gates, NOT is reversible, as can be seen
from its truthtable below.

INPUT OUTPUT
0 1
1 0

The common AND gate is not reversible however. The inputs 00, 01 and 10 all get
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
of thermodynamic entropy. Another way to understand this is that charges on a circuit
are grounded and thus flow away, taking a small charge 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.

[edit] Universality and Toffoli 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


INPUT OUTPUT
0 0 0 0
0 1 0 1
1 0 1 1
1 1 1 0

Unfortunately, there are reversible functions which cannot be computed using just
those gates. In other terms, the set consisting of NOT and XOR gates is not universal
(see functional completeness). If we would like to compute an arbitrary function by
reversible gates, we need another gate. One possibility is the Toffoli gate, proposed in
1980 by Toffoli.[1]

This gate has a 3-bit input and output. If the first two bits are set, it flips the third bit.
Following is a table over the input and output bits:

Truth table Matrix form


INPUT OUTPUT
0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 0
0 1 1 0 1 1
1 0 0 1 0 0
1 0 1 1 0 1
1 1 0 1 1 1
1 1 1 1 1 0
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(x1, x2, ..., xm),
there is a circuit consisting of Toffoli gates which takes x1, x2, ..., xm and some extra
bits set to 0 or 1 and outputs x1, x2, ..., xm, f(x1, x2, ..., 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.

[edit] Related logic gates

Fredkin & Toffoli Billiard Ball Model for Gates

• The Fredkin gate is a reversible 3-bit gate that swaps the last two bits if the
first bit is 1; a controlled-swap operation.

• The n-bit Toffoli gate is a generalization of Toffoli gate. It takes n bits x1,
x2, ..., xn as inputs and outputs n bits. The first n−1 output bits are just x1, ...,
xn−1. The last output bit is (x1 AND ... AND xn−1) XOR xn.
• The Toffoli gate can be realized by five two-qubit quantum gates.[2]

• This gate is one of the reversible-gate cases that can be modeled with billiard
balls, the billiard ball modeling was introduced by Fredkin and Toffoli.[3] An
example of how the collisions are used to model an electronic gate is shown in
the figure.

Three-input universal logic gate


Logic gates are used to build computer chips. Reversible logic gates are of interest
because they could in principle generate useful results for less heat generated
(Landauer 1961). The nand gate is universal among irreversible logic gates, in the
sense that it is possible to simulate any irreversible logic gate with a network of these
gates. The Fredkin and Toffoli gates were the first gates to be proved universal among
reversible logic gates. However, this universality is not unusual in the space of 3 input
and 3 output reversible gates.

A reversible logic gate of n input bits must have n output bits, by the pigeonhole
principle. The reversibility requirements means that each of the 2n input combinations
must have one and only one output combination - they must be a one-to-one map.
Thus the outputs for the inputs are simply some permutation of the inputs, and so the
number of n-input reversible gates is 2n! .
For a three-input gate, this number is 8!, around 40 thousand.

Let us define an define an equivalence relation: two gates are equivalent if the outputs
of one can be gotten by rearranging the bits of the outputs of the other. That is, if we
simply relabel the wires attached to the output terminals of the gate. Every gate, then,
is a member of a 6-member equivalency class bringing the total number of possible
gates down to 8000 or so. The three-input identity gate:

Input 0 01010101
Input 1 00110011
Input 2 00001111
Output 0 01010101
Output 1 00110011
Output 2 00001111

is equivalent to this gate:

Input 0 01010101
Input 1 00110011
Input 2 00001111
Output 0 00110011
Output 1 01010101
Output 2 00001111

which merely swaps outputs 0 and 1.

We shall abbreviate the truth table above by treating columns as octal numbers and
rows as hexadecimal numbers (a redundancy, but a useful one). The three-input
identity table may be written [01234567:AA/CC/0F], and the second table above
[02134657=CC/AA/0F]'. The first set of digits gives the output for each possible
input, and the second set gives the truth table for each of the three outputs. As you can
see, these two tables

Omitting duplicates gives us around 8000 possible gates.

We are interested in universality. Any one output of a three-input logic gate can have
28 possible truth tables for the 8 distinct input values. A logic gate (or set of logic
gates) is universal when suitable cascades of gates can be constructed to give us any
of these 256 truth tables.

Surprisingly, it turns out that almost all of the 8 thousand or so 3/3 reversible gates are
universal in this sense.

There are 269 exceptions. One of them is the "straight through" gate.

7 of them provide access to 8 possible truth tables. These are:


• [45670123=AA:CC:0F] is not universal - 8 truth tables accessible
• [46025713=F0:AA:33] is not universal - 8 truth tables accessible
• [46570213=CC:AA:0F] is not universal - 8 truth tables accessible
• [67234501=AA:0F:33] is not universal - 8 truth tables accessible
• [67452301=AA:33:0F] is not universal - 8 truth tables accessible
• [64752031=CC:55:0F] is not universal - 8 truth tables accessible
• [76543210=55:33:0F] is not universal - 8 truth tables accessible

These ones are those that provide a "not" operator. The 8 truth tables are the 8 ways
you can not or not-not each of the 3 inputs.

The remaining exceptions all provide access to 16 truth tables. One example is
[75462013=C3:99:0F]. As you can see, this table performs an Exclusive Or (XOR).
The 16 truth tables that this gate and presumably all the others provide access to are:

• The 8 results provided by "not" alone


• The 3 ways you can XOR two different inputs
• The 3 ways you can ~XOR two different inputs
• The XOR of all 3 inputs
• The ~XOR of all 3 inputs

The possible logic gates form a group, with the "set of all gates that XOR some of the
inputs" (etc) being a subgroup.

In summary: almost all 3 input/3 output reversible logic gates are universal in the
sense that a network of them can produce any result. Thus the Fredkin and Toffoli
gates are not remarkable in being universal.

[edit] See also


• Reversible computing
• Fredkin gate
• Toffoli Gate

You might also like