2
$\begingroup$

Is there an algorithm explaining how to represent any gate in the matrix form? Suppose, the circuit is the following:

enter image description here

where $$ U := e^{iA\pi/4} = \begin{bmatrix} 0.35-0.85i & -0.35-0.15i \\ -0.35-0.15i & 0.35-0.85i \end{bmatrix} , $$

and the final $CU$ operator has the following matrix representation:

$$ \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0.35-0.85i & 0 & 0 & 0 & -0.35-0.15i & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0.35-0.85i & 0 & 0 & 0 & -0.35-0.15i\\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & -0.35-0.15i & 0 & 0 & 0 & 0.35-0.85i & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -0.35-0.15i & 0 & 0 & 0 & 0.35-0.85i \end{bmatrix} $$

The question is how to understand that the final matrix will be like this? And if to firstly apply the $H$ gate on the 0-th qubit, what it changes in matrix? Or to take another control qubit? In other words, I'm interested in the gate formation from the martrix point of view

$\endgroup$
0

1 Answer 1

6
$\begingroup$

The general way to construct a controlled unitary operator $U$ with the help of projectors is the following: \begin{equation} \label{eq:controlled} CU_{0, 1} = P_{|0\rangle} \otimes I + P_{|1\rangle} \otimes U \end{equation}
with $$ P_{|0\rangle} = |0\rangle\langle 0| \\ P_{|1\rangle} = |1\rangle\langle 1| $$

If there are $n$ qubits in between controlling and controlled qubit, $n$ identity matrices have to be tensored in between as well. If the index of the controlling qubit is larger than the index of the controlled qubit, the tensor products need to be inverted. Here is an example with qubit 2 controlling qubit 0: \begin{equation*} CU_{2, 0} = I \otimes I \otimes P_{|0\rangle} + U \otimes I \otimes P_{|1\rangle} \end{equation*}

$\endgroup$
3
  • $\begingroup$ works with paper and pen! Cool, thank you! $\endgroup$ Commented Jan 31, 2023 at 19:42
  • $\begingroup$ you said "in general", there are options when this solution does not work? $\endgroup$ Commented Jan 31, 2023 at 19:48
  • 1
    $\begingroup$ No exceptions that I'm aware of. $\endgroup$
    – rhundt
    Commented Jan 31, 2023 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.