2

Hadamard gate matrix is:

$$\frac{1}{\sqrt2}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}$$

The matrix for $|0\rangle$ is:

$$\begin{bmatrix}1 \\ 0\end{bmatrix}$$

I am unable to understand, how can I apply Hadamard gate on $|0\rangle$? The matrix representing $|0\rangle$ is of dimension 2 * 1 and the matrix representing Hadamard gate is of dimension 2 * 2 (so the matrix multiplication is not possible)

glS
  • 24,708
  • 5
  • 34
  • 108
Kumar
  • 219
  • 2
  • 7
  • Note that: $(2 \times 2)(2 \times 1) = 2 \times 1$. The dimension of the two number in the inside are the same so it is possible. Remember that matrix multiplication is row by columns. So if the number of elements in the row of $A$ is the same as the number of elements in the column of $B$ then $AB$ is valid. – KAJ226 Oct 05 '20 at 05:22

3 Answers3

5

Applying quantum gates to quantum states is indeed represented as matrix multiplication. To multiply two matrices, you need only one dimension to match:

$$\frac{1}{\sqrt2}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix} \begin{bmatrix}1 \\ 0\end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \cdot 1 + 1 \cdot 0 \\ 1 \cdot 1 + (-1) \cdot 0 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\ 1\end{bmatrix}$$

Mariia Mykhailova
  • 9,010
  • 1
  • 12
  • 39
  • Thanks a lot. I was confused between H * |0> and |0> * H... Is it correct to always assume that it is * |0> rather than |0> * irrespective of the gate we are talking.... – Kumar Oct 05 '20 at 06:02
  • 1
    Yes, the state is always a column vector, and the gate matrix is applied from the left of the vector – Mariia Mykhailova Oct 05 '20 at 06:10
4

|0> is actually a vector, not a matrix. Applying the Hadamard gate (shortly, H) to |0> means computing a matrix vector multiplication:

$H|0\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{|0\rangle + |1\rangle}{\sqrt{2}}$

Michele Amoretti
  • 1,554
  • 7
  • 11
  • Thanks a lot. I was confused between H * |0> and |0> * H... Is it correct to always assume that it is * |0> rather than |0> * irrespective of the gate we are talking.... – Kumar Oct 05 '20 at 06:03
0

Here's a link to a great matrix multiplier tool:

https://matrixcalc.org/en/

Lizzo
  • 309
  • 4
  • 10