# Toffoli circuit explanation [closed]

Can anyone explain me the behaviour of these two circuits? They contain Hadmard and rotation gates before the Toffoli gate. Results of simulation: • Welcome to QCSE! What's your question? As you said, between the barriers you have a toffoli. It looks like more context can help with an explanation. Nov 3 '20 at 21:01
• @luciano Thank you, I just saw a question containing this circuits, unfortunately I don't have more context, only I can provide the simulation result for circuits Nov 3 '20 at 21:10
• In a notebook code __ Nov 3 '20 at 21:17

In the first circuit after Hadamard gates (I suppose that initial state is $$|000\rangle$$ and I will use Qiskit's convention for labeling the qubits $$|q_2 q_1 q_0 \rangle$$):

$$|000\rangle \xrightarrow[]{\text{Hadamards}} \frac{1}{2}|0\rangle(|00\rangle + |01\rangle+|10\rangle + |11\rangle)$$

The $$R_x(0) = I$$, so it does noting. Then comes Toffoli gate (apply $$X$$ gate on the $$q_2$$ qubit if the other two (control qubits) are in $$|1\rangle$$ state):

$$\xrightarrow[]{\text{Toffoli}} \frac{1}{2}|0\rangle(|00\rangle + |01\rangle+|10\rangle) + \frac{1}{2}|111\rangle$$

In the second circuit $$R_x(\pi) = -iX$$ (we can neglect $$-i$$ term because it is a global phase here) and the combained action of Hadamards plus $$R_x(\pi)$$

$$|000\rangle \xrightarrow[]{\text{Hadamards + }R_x(\pi)} \frac{1}{2}|1\rangle(|00\rangle + |01\rangle+|10\rangle + |11\rangle)$$

Then Toffoli:

$$\xrightarrow[]{\text{Toffoli}} \frac{1}{2} |1\rangle (|00\rangle + |01\rangle+|10\rangle) + \frac{1}{2}|011\rangle$$

• No Thank you this is what i'm looking for, but dose your calculation now confirms the simulation or I have trouble reading simulation result!? Because in first case I don't see the '100' Nov 3 '20 at 21:28
• Or in the second case we don't have '111' Nov 3 '20 at 21:29
• @Farhad, I edited the answer, the problem was with the labeling convention...Qiskit uses this labeling convention in ket vectors $|q_2 q_1 q_0\rangle$ rather than $|q_0 q_1 q_2\rangle$ that I was using initially. Nov 3 '20 at 21:37
• Thank you for your response Nov 3 '20 at 21:39
• @Farhad, you are welcome :). I just want to suggest to rename the question with this title "Two circuits with Toffoli, Hadamard and $R_x$ gates". I think this title better describes the question. Nov 3 '20 at 21:50