Qiskit generates the following matrix for this 3-qubit CNOT circuit. Can anyone explain how do we get this mathematically ?
Asked
Active
Viewed 236 times
1 Answers
4
- Write all the unit standard basis vectors in vector form: $|000\rangle\to[1,0,0,0,0,0,0,0]$,$|001\rangle\to[0,1,0,0,0,0,0,0]$ and so on.
- Write the output of the circuit for each vector
- Put them all in a matrix, where the columns of the matrix are the ouputs.
Example for CNOT gate (two qubits) using little endian Qiskit
$|q_1q_0\rangle$ convention with control on qubit 0 and qubit 1 as target
- The basis states are $|00\rangle\to[1,0,0,0]$, $|01\rangle\to[0,1,0,0]$, $|10\rangle\to[0,0,1,0]$ and $|11\rangle\to[0,0,0,1]$
- The ouputs are (same order) $|00\rangle\to[1,0,0,0]$, $|11\rangle\to[0,0,0,1]$, $|10\rangle\to[0,0,1,0]$ and $|01\rangle\to[0,1,0,0]$
- The resulting matrix is (outputs vectors as columns)
$$\mathrm{CNOT}_{0,1}=\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0 \end{bmatrix}$$
More in Qiskit textbook multiqubit gates.
You can try to do the same for three qubits and a CNOT.
Alternatively, if you do understand braket notation and do not want to use vectors you can just write the matrix in ket-bra form by knowing how are the basis vectors are modified by the gate
$$\mathrm{CNOT}_{0,1}=|00\rangle\langle 00|+|11\rangle\langle 01|+|10\rangle\langle 10|+|01\rangle\langle 11|$$.

Mauricio
- 2,296
- 3
- 25