2
$\begingroup$

Qiskit generates the following matrix for this 3-qubit CNOT circuit. Can anyone explain how do we get this mathematically ?

This is the Quantum Circuit

This is the Output of Unitary Simulator

$\endgroup$
0

1 Answer 1

4
$\begingroup$
  1. 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.
  2. Write the output of the circuit for each vector
  3. 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 enter image description here

  1. 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]$
  2. 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]$
  3. 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|$$.

$\endgroup$

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