# Quaternions

Many are familiar with the idea of imaginary/complex numbers but in 1843, Hamilton invented hypercomplex numbers. Initially, he created three components such that they had the form $\inline&space;a+bi+cj$ where $\inline&space;j^2=-1$. This however raised a problem when multiplying complex numbers. We can test this concept by multiplying it by itself.

$(a+bi+cj)(a+bi+cj)$
$a(a+bi+cj)+bi(a+bi+cj)+cj(a+bi+cj)$
$a^2+abi+acj+abi+b^2i^2+bcij+acj+bcij+c^2j^2$
$a^2-b^2-c^2+2abi+2acj+2bcij$

All the terms make sense but the problem is the multiplication of $\inline&space;i$ and $\inline&space;j$. One may think the answer here would be $\inline&space;-1$ but to avoid assumptions Hamilton defined a fourth term $\inline&space;k$ such that $\inline&space;k=ij$ and $\inline&space;k^2=-1$. In fact, even the assumption of commutativity was not made in multiplication. If you multiply both sides of $\inline&space;k=ij$ by $\inline&space;k$ on the right side, the resulting equation is $\inline&space;ijk=-1$. By left and right multiplication on known equations, a multitude of relationships between $\inline&space;i,&space;j$ and $\inline&space;k$ can be formed.

$\inline&space;i(ijk)=-i\rightarrow&space;-jk=-i\rightarrow&space;jk=i$
$\inline&space;j(jk)=ji\rightarrow&space;ji=-k$
$\inline&space;kj=(ij)(j)\rightarrow&space;kj=-i$
$\inline&space;ik=i(ij)\rightarrow&space;ik=-j$
$\inline&space;ki=(-ji)(i)&space;\rightarrow&space;ki=j$

These relationships are often shown with a table.

 i j k i -1 k -j j -k -1 i k j -i -1

There is even a relationship between these complex variables and cross products. If one thinks of $\inline&space;i,&space;j$ and $\inline&space;k$ as the corresponding Cartesian unit vectors, one can perform quaternion multiplication by taking cross products between vectors. For example, $\inline&space;\hat{i}&space;\times&space;\hat{j}&space;=&space;\hat{k}$ for the vectors and $\inline&space;ij=k$ for the quaternions.

Basically, a quaternion is a hypercomplex number of the form $\inline&space;a+bi+cj+dk$. The conjugate would be $\inline&space;a-bi-cj-dk$. The norm or length $\inline&space;|H|$ of any quaternion $\inline&space;H$ is $\inline&space;\sqrt{a^2+b^2+c^2+d^2}$ or $\inline&space;\sqrt{HH^*}$.

These quaternions come in many different forms but here are two.

1. $\inline&space;2&space;\times&space;2$

Sometimes, these are represented using $\inline&space;2&space;\times&space;2$ Pauli Matrices.

$\inline&space;I=i\sigma_z=\begin{bmatrix}&space;i&space;&&space;0\\&space;0&space;&&space;-i&space;\end{bmatrix}$
$\inline&space;J=i\sigma_y=\begin{bmatrix}&space;0&space;&&space;1\\&space;-1&space;&&space;0&space;\end{bmatrix}$
$\inline&space;K=i\sigma_x=\begin{bmatrix}&space;0&space;&&space;i\\&space;i&space;&&space;0&space;\end{bmatrix}$

The square of all these matrices are the negative identity matrix. One can test this is works by multiplying any two of the matrices and checking that the correct result comes out ($\inline&space;IJ=K$ for example). These matrices are also anti-commutative as they should be.

Because for any given quaternion $\inline&space;H=a+bi+cj+dk$, the $\inline&space;2\times2$ matrix representation would be the following.

$\inline&space;H=\begin{bmatrix}&space;a+bi&space;&&space;c+di\\&space;-c+di&space;&&space;a-bi&space;\end{bmatrix}=&space;\begin{bmatrix}&space;A&space;&&space;B\\&space;-B*&space;&&space;A&space;\end{bmatrix}$

$\inline&space;A$ and $\inline&space;B$ are regular complex numbers. The great thing about this form is you can take the Hermitian of the matrix $\inline&space;H^\dagger$ (conjugate transpose) to get the quaternion’s conjugate. You can also take its determinant to get its length. In fact, you can rewrite $\inline&space;H$ as $\inline&space;A+Bj$. Observe the following.

$\inline&space;A+Bj=(a+bi)+(c+di)j$
$\inline&space;=a+bi+cj+dij$
$\inline&space;=a+bi+cj+dk$
$\inline&space;=H$

2. Scalar-vector

Quaternions can be represented as scalar vector combinations $\inline&space;(a,v)$ where for any given quaternion $\inline&space;a+bi+cj+dk$, $\inline&space;v=(b,c,d)$. This scalar vector combination is generally the most common. The following properties of quaternions make this form very useful.

$\inline&space;H^*=(a,&space;-v)$
$\inline&space;|H|=\sqrt{a^2+|v|^2}$
$\inline&space;H_1H_2=(a_1a_2-v_1\cdot&space;v_2,&space;a_1v_2+a_2v_1+v_1\times&space;v_2)$

This is just scratching the surface of quaternions. It is everywhere in mathematics, physics, and computer science and most known for providing easy methods to do 3D rotations and, in the process, avoiding gimbal lock.

Technically, there are such things as octonions (7 imaginary components instead of 3) which help in higher dimensional analysis, sedenions (15 imaginary), etc.  At these higher dimensions, weird things occur. For example, octonions lose associativity and sedenions lose alternativity. Also notice, there only exists hypercomplex numbers in dimensions that the cross products exists (cross products only exist in 3 and 7 dimensions nontrivially). There are also variations of this number system. Hyperbolic quaternions are the same as quaternions but squaring any “imaginary” element will yield 1 instead of -1. Tessarines are hypercomplex numbers that have commutative algebras. Coquaternions are hypercomplex numbers that have zero divisors ($\inline&space;ax=0$), nilpotent elements ($\inline&space;x^a=0$), and idempotent elements ($\inline&space;x*x=x$). A biquaternion is a quaternion with complex coefficients. In fact, there are even three types of complex numbers themselves: ordinary, split ($\inline&space;a+bj$ where $\inline&space;j^2=-1$), and dual ($\inline&space;a+b\epsilon$ where $\inline&space;\epsilon^2=0$). For each, there exists a type a hypercomplex biquaternion: ordinary, split, and dual. I might start a whole page talking about just hypercomplex numbers because in mathematics, there really are no bounds to creativity.

If you want to learn more or know where I learn this from, watch UC Davis’s lecture on quaternions, Numberphile, and read Wolfram Mathworld.