text
stringlengths
0
8.13M
z z'
Figure 2.6: The Toffoli gate.
43
The function computed by this gate is shown in the ’truth’ table below.
x y z x’ y’ z’
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
The functional relations between inputs and outputs can be written
x =x
y =y
y =(x y) z
∧ ⊕
The first two bits, x and y, can be regarded as control bits, they are not
changedbythe gate. Insteadthe ANDofxandy determineswhetherthe third
bit z is flipped or not. The third bit can therefore be regarded as a target bit.
This terminology is used in quantum computation.
The reversibility of the Toffoli gate can be seen in exactly the same way as
for the CNOT gate.
The Toffoli gate turns out to be universal for reversible computation. This
is easily seen as it can be wired as to mimic a NAND gate. Fixing the z-input
wiretobe1,wegetz =(x y) 1= (x y)=x/y. Thisisseenbyrestricting
∧ ⊕ ¬ ∧
the truth table to the rows where z =1.
x y z x’ y’ z’
0 0 1 0 0 1
0 1 1 0 1 1
1 0 1 1 0 1
1 1 1 1 1 0
It can also be wired to mimic a two-wire FANOUT. Fixing the first input
to 1 and the third to 0, the bit on the second input appears on the second and
thirdoutput. Thisisseenbyrestrictingthetruthtabletotherowswherex=1
and z =0.
44
x y z x’ y’ z’
1 0 0 1 0 0
1 1 0 1 1 1
Clearly y =y and z =y.
′ ′
The bits that are fixed to constant values in these constructions are called
ancilla bits.
We should also mention the Fredkin gate in this context. It is a universal
reversiblegatewiththreeinputsandthreeoutputs. Ithasonecontrolbitxand
two target bits y and z.15 If the control bit is 0, the target bits goes through
unchanged, whereas if the control bit is 1, the target bits are swapped, i.e.
y =z and z =y.
′ ′
The Toffoli gate is more useful in quantum computation.
2.4.3 Reversible circuits and un-computation
Relying on the universality of Toffoli gates, a circuit wired with NAND and
FANOUT gates can be rewired into a reversible circuit. In order to do that,
extra ”ancilla” bits are needed. Furthermore, the Toffoli gates outputs one or
two extra bits (depending on whether they mimic FANOUT or NAND) not
needed in the computation. These bits only serve the purpose of making the
computation reversible. The extra output bits from each Toffoli gate add up
to what essentially amounts to ”garbage”. It would be nice to be able to have
the ancilla bits in a standard state and to get rid off the garbage bits. Simply
erasing them will not do, as that would spoil the reversibility. However, there
is a procedure to clean up the garbage using precisely this reversibility!
Suppose we have a non-reversible circuit computing a function f on some
n-bitinputx. We wanttodothiscomputationreversiblywhilecleaningupthe
garbage. If the non-reversible computation is represented as
x f(x), (2.18)
we can represent the reversible computation as
(x,a) (f(x),g(x)), (2.19)
where a denotes the ancilla bits needed to wire the Toffoli gates and g(x)
denotesthe resultinggarbagebits. Theancillabits, aswellasxcanbe thought
of as bit strings stored in appropriately sized registers.
Inorderto putthe ancillabits inastandardstate,weallowthe use ofNOT
gates. These are reversible. Then all ancilla bits can be 0’s, using NOT gates
where 1’s are needed. So now we have (x,¯0) (f(x),g(x)) with ¯0 denoting a
bit string with just 0’s.
15Tobeconsistentwithterminology,weoughttospeakaboutinputandoutputwiresinstead
ofinputandoutputbits. Howeverthisiscommonabuseoflanguage.
45
Furthermore, allowing the use of the CNOT gates (also reversible), we can
do two things. First, a copy of the input bit string x can be made, so that the
computation now reads
(x,¯0,¯0) (x,x,¯0) (x,f(x),g(x)) (2.20)
→ →
where the first arrow corresponds to the copying action of the initial CNOT
gates.
Now we can introduce the idea of uncomputation. This is a procedure that
allowsus togetridofthe garbagebits byinvertingthe circuit, andsoto speak,
uncompute the garbageback to ¯0. But of course,the result of the computation
f(x) must be saved before. This can be done by introducing a fourth input
registery withthesamesizeastheregisterneededtostoretheresultf(x). The
register y is not used until the computation of f(x) is finished. Then CNOT