I'm trying to understand how to apply tensor products on a 3 qbit systems (or well at least 2 qbits). Let's take a basic example:
where $$\lvert \psi \rangle = \lvert q2q1q0\rangle $$ with q2 being the most signifiant bit and q0 the least significant (matching the above schematic for the circuit).
H matrix (for a single qbit): $$H = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$
I understand that I need to use the identity matrix & tensor product in order to format the Hadamard matrix (and any other in the circuit) to be applied to 3 qbits. What I do not understand is how, generally, I determine the order of the tensor product? In order words, with the above description, should I do:
$M=(H\otimes I)\otimes I = \frac{1}{\sqrt{2}} \begin{bmatrix} I & 0 & I & 0\\ 0 & I & 0 & I\\ I & 0 & -I & 0\\ 0 & I & 0 & -I\\ \end{bmatrix}$
or
$M=(I\otimes I)\otimes H = \begin{bmatrix} H & 0 & 0 & 0\\ 0 & H & 0 & 0\\ 0 & 0 & H & 0\\ 0 & 0 & 0 & H\\ \end{bmatrix}$
More generally, how should I think about why the correct one is the right one? What is the logic I need to understand with regards to the "extension" of my gate's matrices and in which order I need to apply the Identity matrices in the tensor product?