Help understanding the complex matrix representation of quaternions Using the basis $ B = \{1, j\}$, one can show that quaternions can be represented by 2x2 complex matrices as follows:
\begin{pmatrix}
z & w\\
-\bar{w} & \bar{z}\\
\end{pmatrix}
I would like some help to understand this.
Lets say $z = a + bi, w = c + di$
Then we can represent the quaternion $h = a + bi + cj + dk$ as $z + wj$.
I would have thought that to find the matrix representation of complex numbers we would see what would happen if we multiply $z + wj$ by the basis elements. This would mean the first column of our matrix would be $(z + wj)(1) = z + wj = 
         \begin{bmatrix}
           z \\
           w \\
         \end{bmatrix}$
And the second column would be $(z + wj)(j) = zj + wj^{2} = zj - w =          \begin{bmatrix}
           -w \\
           z \\
         \end{bmatrix}$
So I would have thought the matrix representation would be 
\begin{pmatrix}
z & -w\\
w & z\\
\end{pmatrix}
I have a feeling I have some large misunderstanding about what I'm doing, I'm just following the same approach I did to find matrix representations of complex numbers with real 2x2 matrices and matrix representations of quaternions with real 4x4 matrices. 
e.g. with complex numbers, using a basis of $B = \{1, i\}$, and a complex number $a + bi$ where $a$ and $b $ are :
$(a + bi)(1) = a+ bi = \begin{bmatrix}
           a \\
           b \\
         \end{bmatrix}$
$(a + bi)(i) = ai -b = \begin{bmatrix}
           -b \\
           a \\
         \end{bmatrix}$
Which gives us the matrix 
\begin{pmatrix}
a & -b\\
b & a\\
\end{pmatrix}
Which is correct. The same approach worked for me for quaternions and real 4x4 matrices. 
 A: Given a quaternion $q$ and a complex number $\lambda$, for scalar multiplication you can either apply $\lambda$ to $q$ from the left (i.e. $\lambda q$) or from the right (i.e. $q\lambda$). This means you can interpret $\mathbb{H}$ as a left complex vector space or as a right complex vector space. Now consider the left and right multiplication maps
$$ L_p(x)=px, \qquad R_p(x)=xp. \tag{1}$$
Then $L_p(x\lambda)=L_p(x)\lambda$ for all complex numbers, so $L_p$ is a linear transformation of $\mathbb{H}$ as a right complex vector space. And $R_p(\lambda x)=\lambda R_p(x)$, so $R_p$ is a linear transformation of $\mathbb{H}$ as a left complex vector space.
However, $L_p$ is not linear if we treat $\mathbb{H}$ as a left complex vector space, and $R_p$ is not linear if we treat $\mathbb{H}$ as a right vector space. This is because $\mathbb{H}$ is not commutative. (Exercise.)
Using $\{1,\mathbf{j}\}$ as a basis for $\mathbb{H}$ as a complex vector space, you would write an arbitrary quaternion as $z+w\mathbf{j}$ if you're thinking left vector space, and write $z+\mathbf{j}w$ if you're thinking right vector space. (Also notice $w$ comes before $z$ in the alphabet, so we're backwards alphabetically.) You're thinking left vector space but you're examining the right-linear transformation $L_p$. That's problematic.
If you look at $L_p$ and think right vector space, you should get
$$ \begin{bmatrix} z & -\overline{w} \\ w & \phantom{-}\overline{z} \end{bmatrix}. \tag{2} $$
(Exercise.)
Representing quaternions as matrices using $R_p$ is problematic since $R_p\circ R_q\ne R_{pq}$. Indeed, this would be a function $\mathbb{H}\to M_2(\mathbb{C})$ which is not a homomorphism but rather an anti-homomorphism, i.e. it satisfies $R_p\circ R_q=R_{qp}$ (the order of multiplication is reversed). In order to turn it into a homomorphism proper, one must either (pre)compose it with an anti-automorphism of $\mathbb{H}$ or (post)compose with an anti-automorphism of $M_2(\mathbb{C})$. Quaternion conjugation satisfies $\overline{pq}=\overline{q}\,\overline{p}$ and matrix transpose satisfies $(AB)^T=B^TA^T$, so we can use these as anti-automorphisms.
In the case of quaternion conjugation, we can take $p=z+w\mathbf{j}$, then its conjugate $\overline{p}=\overline{z}-w\mathbf{j}$, then the matrix of $R_{\overline{p}}$ you can calculate (exercise) to be
$$ \begin{bmatrix} \overline{z} & \overline{w} \\ -w & z \end{bmatrix}, \tag{3} $$
and if instead you just calculated $R_p$'s matrix and took the transpose you'd get $(2)$ again.
Complex conjugation (applied entry-wise to a matrix) is an automorphism of $M_2(\mathbb{C})$, i.e. it satisfies $\overline{AB}=\overline{A}\,\overline{B}$, so we may compose it with any of the representations above to get another valid representation.
A: Here is the code for Mathematica that uses the $2\times 2$ complex matrix representation of quaternions:
Clear["Global`*"]
Unprotect[Dot];
Dot[x_?NumberQ, y_] := x y;
Protect[Dot];
Matrix /: Matrix[x_?MatrixQ] := 
  First[First[x]] /; x == First[First[x]] IdentityMatrix[Length[x]];
Matrix /: NonCommutativeMultiply[Matrix[x_?MatrixQ], y_] := 
  Dot[Matrix[x], y];
Matrix /: NonCommutativeMultiply[y_, Matrix[x_?MatrixQ]] := 
  Dot[y, Matrix[x]];
Matrix /: Dot[Matrix[x_], Matrix[y_]] := Matrix[x . y];
Matrix /: Matrix[x_] + Matrix[y_] := Matrix[x + y];
Matrix /: x_?NumericQ + Matrix[y_] := 
  Matrix[x IdentityMatrix[Length[y]] + y];
Matrix /: x_?NumericQ Matrix[y_] := Matrix[x y];
Matrix /: Matrix[x_]*Matrix[y_] := Matrix[x . y] /; x . y == y . x;
Matrix /: Power[Matrix[x_?MatrixQ], y_?NumericQ] := 
  Matrix[MatrixPower[x, y]];
Matrix /: Power[Matrix[x_?MatrixQ], Matrix[y_?MatrixQ]] := 
  Exp[Matrix[y] . Log[Matrix[x]]];
Matrix /: Im[Matrix[x_?MatrixQ]] := Matrix[Im[x]]
Matrix /: Re[Matrix[x_?MatrixQ]] := Matrix[Re[x]]
Matrix /: Arg[Matrix[x_?MatrixQ]] := Matrix[Arg[x]]

$Post2 = FullSimplify[FullSimplify[# /. i -> Matrix[( {
               {I, 0},
               {0, -I}
              } )] /. j -> Matrix[( {
              {0, 1},
              {-1, 0}
             } )] /. k -> Matrix[( {
             {0, I},
             {I, 0}
            } ) ] /. 
        f_[args1___?NumericQ, Matrix[mat_], args2___?NumericQ] :> 
         Matrix[MatrixFunction[f[args1, #, args2] &, mat]]] /. 
      Matrix[{{a_, c_}, {d_, b_}}] :> 
       Re[a] + Im[a] i + Re[c] j + Im[c] k ] /. 
    Matrix[{{a_, c_}, {d_, b_}}] :> 
     Re[a] + Im[a] i + Re[c] j + Im[c] k &;
$Post = Nest[$Post2, #, 3] &;

After executing this, you can use quaternions (expressions of i, j and k) in normal expressions with other numbers. The multiplication of quaternions is evaluated only if the quaternions commute, in other cases use non-commutative multiplication operator (**), it is evaluated always.
Test:
In:=Log[(i + 5) ** (j - 1)]

Out:=1/18 (-2 Sqrt[3] (i - 5 j - k) (Pi - ArcTan[(3 Sqrt[3])/5]) + 9 Log[52])

