2

I have a question about how to transform a quantum gate into the matrix representation. For example, we all know the 2-qubit gate--CNOT, can be written like \begin{pmatrix} 1& 0& 0& 0 \\ 0& 1& 0& 0 \\ 0& 0& 0& 1 \\ 0& 0& 1& 0 \\ \end{pmatrix} and its image is shown on the lefe side of the following picture: enter image description here

However, I don't konw how to transform the 3-qubit gate into matrix representation. It doesn't look like to directly utilize tensor product technique, and therefore I want to know how to transform them? Probabily in $C_1T_3Q_3$ or in $C_2T_5Q_6$ these more general situation, where $C_k$ stands for the k-th control qubit, $Q_j$ stands for the j-th target qubit, and $Q_i$ means that there are i qubits in total.

glS
  • 24,708
  • 5
  • 34
  • 108
Vertero
  • 23
  • 3
  • related: https://quantumcomputing.stackexchange.com/q/10098/55 – glS Nov 04 '22 at 08:22
  • Have a look at this question: https://quantumcomputing.stackexchange.com/questions/9180/how-do-i-write-the-matrix-for-a-cz-gate-operating-on-nonadjacent-qubits In the answer provided just interchange $Z$ with $X$. – Martin Vesely Nov 04 '22 at 10:29

1 Answers1

0

One fairly straightforward method is to enumerate all the computational basis states in order: 000, 001, 010, 011, 100, 101, 110, 111. You can label each row and column in order. So, for example, the bottom-left matrix element has a column label 000 and row label 111. For each such matrix element, (say, row: a, column: b), you act your gate $U$ on the basis state $|a\rangle$ and ask what its amplitude is for producing $|b\rangle$. That's the matrix element: $U_{a,b}=\langle b|U|a\rangle$.

Remember that if you ever find an element has absolute value 1, all other elements in that row and column are 0. So, for the toffoli gate, I might look at $U|000\rangle$. This tells me what the first column is: 1 in the top left element (the 000 row) and 0 everywhere else.

DaftWullie
  • 57,689
  • 3
  • 46
  • 124
  • OK, I see... This brute force method can actually solve this problem. But I wonder if there is a more effective way to solve this problem (although it can be solved by the computer through solving the equations). – Vertero Nov 04 '22 at 08:47
  • That really depends on your initial specification of the gate. If you're only thinking about controlled-not gates and acting them on different pairs of qubits, there are of course much easier ways. For example, for your three-qubit circuit: $|0\rangle\langle 0|\otimes I\otimes I+|1\rangle\langle 1|\otimes I\otimes X$. – DaftWullie Nov 04 '22 at 09:03