Wolfram Function Repository
Instantuse addon functions for the Wolfram Language
Function Repository Resource:
Represent a quaternion object
ResourceFunction["Quaternion"][a,b,c,d] returns the quaternion number a+bⅈ+cⅉ+d𝕜. 
Get the quaternion 1+2ⅈ+3ⅉ+4𝕜:
In[1]:= 

Out[1]= 

Add two quaternions:
In[2]:= 

Out[2]= 

Use NonCommutativeMultiply (**) to multiply quaternions:
In[3]:= 

Out[3]= 

This multiplication is noncommutative:
In[4]:= 

Out[4]= 

In the conjugate of a quaternion, all the signs of the nonreal components are reversed:
In[5]:= 

Out[5]= 

The sign of a quaternion is defined in the same way as the sign of a complex number. It is the “direction” of the quaternion:
In[6]:= 

Out[6]= 

Get the standard Euclidean length:
In[7]:= 

Out[7]= 

The exponential of a quaternion can be quite complicated:
In[8]:= 

Out[8]= 

Just as with complex numbers, it is important to beware of branch cuts:
In[9]:= 

Out[9]= 

A four‐dimensional analog of de Moivre’s theorem is used for calculating powers of quaternions:
In[10]:= 

Out[10]= 

Round for quaternions returns a Quaternion in which either all components are integers or all components are odd multiples of 1/2:
In[11]:= 

Out[11]= 

A quaternion is even if its norm is even:
In[12]:= 

Out[12]= 

In[13]:= 

Out[13]= 

Just as with complex numbers, the quaternion Mod works:
In[14]:= 

Out[14]= 

You can specify a quaternion as the modulus:
In[15]:= 

Out[15]= 

This work is licensed under a Creative Commons Attribution 4.0 International License