# Is it possible to make N-way Controlled-NOTs out of Toffoli gates, without extra work bits?

I'm working on exercise 4.29 of Nielsen and Chuang:

Find a circuit containing O(n^2) Toffoli, CNOT, and single qubit gates which implements a $C^n(X)$ gate (for n >3), using no work qubits.

As part of solving this exercise, I'm trying to figure out if the task of making a NOT-controlled-by-N-bits is possible classically (i.e. without using single qubit gates, except the NOT gate).

This is trivial to do if you have work bits initialized to 0 available, but I haven't been able to figure out how to do it without work bits. I'm also not sure how to approach an impossibility proof.

The main thing I've figured out is that, if I could make $Increment$ and $Decrement$ gates, then I could do it like this:

   ____    ____
--|    |--|    |---    --•--
--|    |--|    |---    --•--
--| +1 |--| -1 |--- == --•--
--|    |--|    |---    --•--
--|    |--|____|---    --•--
--|____|-----------    --X--


But I also can't figure out how to make those gates, at least not without the many-controlled-not gate I'm trying to make.

Is this even possible (the limited-to-classical case, not the exercise)?

It's not possible.

A reversible computation always corresponds to a permutation of the state space. When working on three bits, a Toffoli corresponds to a single swap in the state space (it swaps 111 for 110). When working on four or more bits, a Toffoli gate always corresponds to an even number of swaps in the state space. This is because it performs a swap for each possible state of the uninvolved bits, and there are an even number of such states. For example, a Toffoli applied to the first three bits of a four bit system swaps 111_0 for 110_0 and swaps 111_1 for 110_1. Even number of swaps.

Permutations have a parity. A permutation that can be implemented with an even number of swaps has even parity. Permutations that can be implemented with an odd number of swaps have odd parity. The composition of two even parity permutations will also be an even parity permutation. Odd parity permutations can't be reached by composing even parity permutations.

This means the Toffoli gate can't perform a CCCNOT without workspace, because the action of the CCCNOT on the state space is an odd parity permutation but the action of the Toffoli is an even parity permutation. The single CNOT and NOT gates have the same problem. You need an extra work bit (or quantum gates like $$X^{1/8}$$) to break the parity barrier.

Slight twist on this not being possible.

If you have any ancilla bits, even ones in an unknown state that you don't own, you can create a $C^3$NOT from $C^2$NOTs. Do this:

C1 ─•───•─── C1
│   │
C2 ─•───•─── C2
│   │
C3 ─┼─•─┼─•─ C3
│ │ │ │
T ─┼─X─┼─X─ T + (C1 * C2 * C3)
│ │ │ │
E ─X─•─X─•─ E


So in practice you can make higher CNOT gates out of Toffoli gates. You just use any other bits that happen to be in the circuit as working space. You don't need the extra bits to be initialized to 0, and you won't trash them, but they do need to be present (they're catalysts).

So, in an $M$ bit circuit, you can at least make up to $C^\left\lceil \frac{M}{2} \right\rceil$NOT gates out of Toffoli gates by using the other half of the bits as workspace. You can also keep re-using one extra bit and the target bit as alternating workspaces, letting you get up to $C^{M-1}$NOTs, but that seems to require a quadratic number of gates.