# computing a quantum circuit by hand (CNOT on non-computational basis states)

I'm trying to compute the state of a particular circuit using Dirac notation but I get stuck after a while .. you can find the circuit there. The numerical coefficients do not matter and I want to compute it for any rotation parameter. So far here's what I've done :

Computing the three states after rotation :

$$R_X(\theta_1) |0⟩ = |\phi_1⟩= \cos(\frac{\theta_1}{2})|0⟩ - i \sin(\frac{\theta_1}{2}) |1⟩$$

$$R_Y(\theta_2) |0⟩ = |\phi_2⟩ = \cos(\frac{\theta_2}{2}) |0⟩ + \sin(\frac{\theta_2}{2}) |1⟩$$

$$R_Y(\theta_3) |0⟩ = |\phi_3⟩ = \cos(\frac{\theta_3}{2}) |0⟩ + \sin(\frac{\theta_3}{2}) |1⟩$$

I then compute the joint state $$|\phi_1 \phi_2⟩$$ :

$$|\phi_1 \phi_2⟩ = (\cos(\frac{\theta_1}{2}) |0⟩ - i \sin(\frac{\theta_1}{2}) |1⟩) \otimes (\cos(\frac{\theta_2}{2}) |0⟩ + \sin(\frac{\theta_2}{2}) |1⟩)$$

$$= \cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |00⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |01⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |10⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |11⟩$$

I then compute the CNOT gate with control $$|\phi_1⟩$$ and target $$|\phi_2⟩$$ :

$$CNOT(|\phi_1 \phi_2⟩) = \cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |00⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |01⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |11⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |10⟩$$

But then I'm not sure how to compute the last CNOT gate.. I could do it using matrix computation but the whole point is being able to do this kind of computation quickly by hand.

If you include the third qubit in your state, now, you have

$$(\cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |00⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |01⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) |11⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) |10⟩)\otimes(\cos(\frac{\theta_3}{2})|0⟩+\sin(\frac{\theta_3}{2})|1⟩)$$

Then you expand this:

$$\cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|000⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|010⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|110⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2})\cos(\frac{\theta_3}{2}) |100⟩$$

$$+ \cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|001⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|011⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|111⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2})\sin(\frac{\theta_3}{2}) |101⟩$$

Then do the CNOT on each basis state, changing the third bit iff the second bit is 1:

$$\cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|000⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|011⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \cos(\frac{\theta_3}{2})|111⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2})\cos(\frac{\theta_3}{2}) |100⟩$$

$$+ \cos(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|001⟩ + \cos(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|010⟩ - i \sin(\frac{\theta_1}{2}) \cos(\frac{\theta_2}{2}) \sin(\frac{\theta_3}{2})|110⟩ - i \sin(\frac{\theta_1}{2}) \sin(\frac{\theta_2}{2})\sin(\frac{\theta_3}{2}) |101⟩$$

... and that's your final state! Kind of a mess as you can see; there's a reason people avoid computing these by hand. :)

• you were very brave for computing it ! I hoped there would be some kind of shortcut but I guess not really. Thanks a lot, I'll put your answer as accepted. – nathan raynal Feb 25 '20 at 0:00