Equivalence of quantum circuits

I have these 2 quantum circuits:

Are they equivalent?I think they are but I cannot understand how this could be possible.Lets assume that the initial condition of the first circuit is:]

Lets assume that gate A transforms any qubit $$\begin{pmatrix} f\\ e \end{pmatrix}$$ into: $$\begin{pmatrix} f'\\ e' \end{pmatrix}$$ and gate B transforms any 2 qubit system from: $$\begin{pmatrix} gi\\ gj\\ hi\\ hj \end{pmatrix}$$ into: $$\begin{pmatrix} gi\\ gj\\ hi''\\ hj'' \end{pmatrix}$$

Lets take the first system.From a initial condition of:

$$\begin{pmatrix} ac\\ ad\\ bc\\ bd \end{pmatrix}$$ after gate A it becomes: $$\begin{pmatrix} a'c\\ a'd\\ b'c\\ b'd \end{pmatrix}$$ and after controlled gate B it becomes: $$\begin{pmatrix} a'c\\ a'd\\ b'c''\\ b'd'' \end{pmatrix}$$ Now lets take the second system.From a initial condition of: $$\begin{pmatrix} ac\\ ad\\ bc\\ bd \end{pmatrix}$$ after gate B it becomes:

$$\begin{pmatrix} ac\\ ad\\ bc''\\ bd'' \end{pmatrix}$$ and after gate A it becomes: $$\begin{pmatrix} a'c\\ a'd\\ b'c''\\ b'd'' \end{pmatrix}$$ so the 2 are equivalent?But this cannot be correct , intuitively it is not correct.Where am I wrong here?

Your problem is that your notation is leading you astray. In your first way of writing the circuit, you have the gate $$B$$ achieving the change in amplitudes $$b'c\rightarrow b'c''$$ while in the second you have $$bc\rightarrow bc''$$ assuming that those two $$c''$$ should be the same. There is no reason that they should be.

To illustrate this more concretely, consider $$A$$ and $$B$$ both being the not gate, and both qubits start in $$|0\rangle$$. In the first case, you get $$\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}\rightarrow\begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \end{bmatrix}\rightarrow \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix}$$ while in the second case, you get $$\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}\rightarrow\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}\rightarrow \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \end{bmatrix}.$$ The initial conditions for the controlled-B gate are different between the two cases, so give different outputs.

• But the gate is the same so they should be the same.Well obviously the initial condition is the same and the gates are the same. Mar 28 at 16:05
• but the initial conditions are not the same. $b'c$ and $bc$ are different initial conditions. Mar 28 at 16:26
• u mean before the gate B is acted on the system?True but I dont see why it would make such a big difference. Mar 28 at 16:29
• It makes all the difference. Mar 28 at 16:32

The circuits are not equivalent in general. As an example, take $$A = B = X$$. The unitary matrices representing the circuits are different:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator

qc1 = QuantumCircuit(2)
qc1.x(0)
qc1.cx(0, 1)
display(qc1.draw())
display(Operator(qc1).draw('latex'))

qc2 = QuantumCircuit(2)
qc2.cx(0, 1)
qc2.x(0)
display(qc2.draw())
display(Operator(qc2).draw('latex'))


• Hi.Can you spot my mistake in the calculations? Mar 28 at 16:19

No, these two circuits won't be equivalent in general.

Reasoning with states might not be the easiest way to understand it, I found expressing $$A$$ and $$B$$ in terms of matrices more clear.

Consider $$A = \begin{pmatrix}a_{11}&a_{12}\\ a_{21}&a_{22}\end{pmatrix}$$ and $$B = \begin{pmatrix}b_{11}&b_{12}\\ b_{21}&b_{22}\end{pmatrix}$$.

The $$A$$ gate applied to the first qubit correspond to the operator (written in block matrix notation):

$$\begin{pmatrix} a_{11}I_2 & a_{12}I_2 \\ a_{21}I_2& a_{22}I_2 \end{pmatrix}$$

where $$I_2$$ is the $$2\times2$$ identity matrix.

The controlled-$$B$$ gate has matrix representation:

$$\begin{pmatrix} I_2 & 0 \\ 0& B \end{pmatrix}$$

Hence, the first circuit seen overall as a matrix is:

$$\begin{pmatrix} a_{11}I_2 & a_{12}I_2 \\ a_{21}B& a_{22}B \end{pmatrix}$$

Whereas the second circuit is:

$$\begin{pmatrix} a_{11}I_2 & a_{12}B \\ a_{21}I_2& a_{22}B \end{pmatrix}$$

As a result, the circuits can only be equivalent if $$a_{21}I_2 = a_{21}B$$ and $$a_{12}I_2 = a_{12}B$$.

This condition is never met unless $$a_{21} = a_{12} = 0$$ i.e. the matrix $$A$$ is diagonal (or in the trivial case $$B=I_2$$).

You can check that taking $$A=B=X$$ doesn't give you an equivalence between the circuit, but taking $$A=Z$$ and $$B=X$$ does as $$Z$$ is a diagonal matrix.