# What is the matrix representation of a generic two-qubit controlled unitary operation?

I have been taught that an arbitrary two qubit controlled unitary (first qubit control, second qubit target) can be represented as

$$\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & a & b\\ 0 & 0 & c & d \end{matrix}$$

I can write down some controlled unitary gates (CZ, CNOT, etc) to convince myself of this but I haven't been able to find a way to derive this from scratch.

I would like to find a similar matrix representation for the case where the first qubit is now target and the second qubit is control.

Note that if you have the first qubit as the control qubit, and the second qubit as the target, then you can write $$CU$$ gate as follow:

$$CU_{12} = |0\rangle \langle 0| \otimes I + |1 \rangle \langle 1| \otimes U$$

If you work this out then this is equivalent to the matrix representation of

$$CU_{12} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{11} & u_{12} \\ 0 & 0 & u_{21} & u_{22} \end{pmatrix} \hspace{1 cm} \textrm{where} \ \ U = \begin{pmatrix} u_{11} & u_{12} \\ u_{21} & u_{22} \end{pmatrix}$$

So for instance, if $$U = X$$ then you have the familarity $$CNOT_{12}$$ gate (with the first qubit being controlled and the second being the target)

$$CNOT_{12} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}$$

As for the case where the first qubit is the target and the second qubit as the controlled, then you can write it as

$$CU_{21} = I \otimes |0\rangle \langle 0| + U\otimes |1\rangle \langle1|$$

I will let you work out the matrix representation here.

A final note that might help while you working out all the details yourself: $$|0\rangle \langle 0 | = \begin{pmatrix}1 \\ 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \end{pmatrix} = \begin{pmatrix}1 & 0 \\ 0 & 0 \end{pmatrix} \hspace{1 cm} |1\rangle \langle 1 | = \begin{pmatrix}0 \\ 1\end{pmatrix} \begin{pmatrix} 0 & 1 \end{pmatrix} = \begin{pmatrix}0 & 0 \\ 0 & 1 \end{pmatrix}$$

For your first question, you are right, so here are 2 examples:

And for the second question, since operation happen only in case second qubit is 1, and nothing is changing when second qubit is 0:

Edit: you should look seperatly, what the gate is doing seperatly to each state in the $$|x_1 x_2\rangle$$ state. In cases that the control is zero, the state is not changing, therfore multiplied by one, without adding any other states (the rest of the row is 3 zeros).

In cases that the control is 1, the qubit changes as it was changes is it was only 1 qubit gate on the target alone, while you ignore the 1 in the control.

Another way to see, in case first is control, for any unitary $$U$$:

$$CU(|00\rangle+|01\rangle+|10\rangle+|11\rangle)=(|00\rangle+|01\rangle)+|1\rangle \otimes U(|0\rangle+|1\rangle)$$

• could you explain a bit how you went about constructing the matrix. How did you know (10, 01) (11, 10) (01, 10) and (10, 11) are supposed to be zeros? Mar 6, 2022 at 21:27
• I editted the answer Mar 6, 2022 at 21:54