# Toffoli gate as FANOUT

I was searching for examples of quantum circuits to exercise with Q# programming and I stumbled on this circuit: From: Examples of Quantum Circuit Diagrams - Michal Charemza

During my introductory courses in quantum computation, we were taught that the cloning of a state is forbidden by the laws of QM, while in this case the first contol qubit is copied on the third, target, qubit.

I quickly tried to simulate the circuit on Quirk, something like this, that sort of confirms the cloning of the state in output on the first qubit. Measuring the qubit before the Toffoli gate shows that is in fact no real cloning, but instead a change on the first control qubit, and an equal output on the first and third qubit.

By making simple math, it can be shown that the "cloning" happens only if the third qubit is in initial state 0, and that only if on the first qubit is not performed a "spinning operation" (as indicated on Quirk) on Y or X.

I tried writing a program in Q# that only confirmed which is aforesaid.

I struggle in understanding how the first qubit is changed by this operation, and how something similar to a cloning is possible.

• It's an excellent question, and thank you for taking effort to format it so nicely. Jul 16, 2018 at 6:06
• Apr 17, 2021 at 16:10

To simplify the question consider CNOT gate instead of Toffoli gate; CNOT is also fanout because

\begin{align} |0\rangle|0\rangle \rightarrow |0\rangle|0\rangle\\ |1\rangle|0\rangle \rightarrow |1\rangle|1\rangle \end{align}

and it looks like cloning for any basis state $x\in\{0,1\}$ \begin{align} |x\rangle|0\rangle \rightarrow |x\rangle|x\rangle \end{align}

but if you take a superposition $|\psi\rangle=\alpha|0\rangle + \beta|1\rangle$ then

\begin{align} (\alpha|0\rangle+\beta|1\rangle)|0\rangle \rightarrow \alpha|0\rangle|0\rangle+ \beta|1\rangle|1\rangle \end{align}

so generally

\begin{align} |\psi\rangle|0\rangle\not\rightarrow|\psi\rangle|\psi\rangle \end{align}

and fanout is not cloning.

As for the question of how the first qubit is changed - it is now entangled with the second qubit.

• in other words, because the no-cloning theorem says that there cannot be any unitary able to clone nonorthogonal states, while orthogonal states can be cloned without problems
– glS
Jul 16, 2018 at 20:52

The no cloning theorem says that there is no circuit which creates independent copies of all quantum states. Mathematically, no cloning states that:

$$\forall C: \exists a,b: C \cdot \Big( (a|0\rangle + b|1\rangle)\otimes|0\rangle \Big) \neq (a|0\rangle + b|1\rangle) \otimes (a|0\rangle + b|1\rangle)$$

Fanout circuits don't violate this theorem. They don't make indepedent copies. They make entangled copies. Mathematically, they do:

$$\text{FANOUT} \cdot \Big( (a|0\rangle + b|1\rangle) \otimes |0\rangle \Big) = a|00\rangle + b|11\rangle$$

So everything is fine because $a|00\rangle + b|11\rangle$ is not the same thing as $(a|0\rangle + b|1\rangle) \otimes (a|0\rangle + b|1\rangle)$.

The answer is that the no-cloning theorem states that you cannot clone an arbitrary unknown state.

This circuit does not violate the no-cloning theorem, because let's look at what it does when the input is $$\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$$. The output at the third register still has to be a $$|0\rangle$$ or a $$|1\rangle$$.

Therefore it's impossible for this circuit to clone an arbitrary state $$|\psi\rangle$$, and one example of a state that it cannot clone is: $$\frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$$.

• @NeildeBeaudrap: The original question has $|x\rangle$, so I'm saying that it only works when $|x\rangle$ is 0 or 1 but not when it's in a superposition. You changed it to $|\psi\rangle$, is it necesasry to have a different symbol? Jul 16, 2018 at 8:10