Function Repository Resource:

Quaternion

Source Notebook

Represent a quaternion object

Contributed by: Wolfram Staff

ResourceFunction["Quaternion"][a,b,c,d]

returns the quaternion number a+bⅈ+c+d𝕜.

Details and Options

Quaternions have the form a+b+c+d𝕜 where a, b, c and d are real numbers.
The symbols , and 𝕜 are multiplied according to the rules 2=2=𝕜2=ⅈ ⅉ 𝕜=-1.
Quaternions are an extension of the complex numbers and work much the same except that their multiplication is not commutative. For instance, ⅈⅉ=-ⅉⅈ.
Because of the similarities between quaternions and complex numbers, this function imitates the Wolfram Languages treatment of complex numbers in many ways.
To provide a clear distinction between quaternions and complex numbers all quaternions should be entered using the form ResourceFunction["Quaternion"][a,b,c,d] where a, b, c and d are real numbers.
Only limited support is offered to the symbolic form a+Ib+J c+Kd.

Examples

Basic Examples (3) 

Get the quaternion 1+2ⅈ+3ⅉ+4𝕜:

In[1]:=
ResourceFunction["Quaternion"][1, 2, 3, 4]
Out[1]=

Add two quaternions:

In[2]:=
ResourceFunction["Quaternion"][1, 2, 3, 4] + ResourceFunction["Quaternion"][2, 3, 4, 5]
Out[2]=

Use NonCommutativeMultiply (**) to multiply quaternions:

In[3]:=
ResourceFunction["Quaternion"][2, 0, -6, 3] ** ResourceFunction["Quaternion"][1, 3, -2, 2]
Out[3]=

This multiplication is noncommutative:

In[4]:=
ResourceFunction["Quaternion"][1, 3, -2, 2] ** ResourceFunction["Quaternion"][2, 0, -6, 3]
Out[4]=

Properties and Relations (7) 

In the conjugate of a quaternion, all the signs of the nonreal components are reversed:

In[5]:=
q = Conjugate[ResourceFunction["Quaternion"][4, -3, 1, -2]]
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]:=
Sign[q]
Out[6]=

Get the standard Euclidean length:

In[7]:=
Abs[q]
Out[7]=

The exponential of a quaternion can be quite complicated:

In[8]:=
E^ResourceFunction["Quaternion"][2, 3, 1, 6]
Out[8]=

Just as with complex numbers, it is important to beware of branch cuts:

In[9]:=
Sin[Cos[ResourceFunction["Quaternion"][.3, .1, .5, .5]]]
Out[9]=

A four‐dimensional analog of de Moivre’s theorem is used for calculating powers of quaternions:

In[10]:=
ResourceFunction["Quaternion"][1, 2, 0, 1]^2.5
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]:=
Round[ResourceFunction["Quaternion"][1/2, 3, 4, 5/2]]
Out[11]=

A quaternion is even if its norm is even:

In[12]:=
EvenQ[ResourceFunction["Quaternion"][2, 3, 4, 5]]
Out[12]=
In[13]:=
EvenQ[Norm[ResourceFunction["Quaternion"][2, 3, 4, 5]]]
Out[13]=

Just as with complex numbers, the quaternion Mod works:

In[14]:=
Mod[ResourceFunction["Quaternion"][-3, 4, 1, 2], 3]
Out[14]=

You can specify a quaternion as the modulus:

In[15]:=
Mod[ResourceFunction["Quaternion"][1, 3, 4, 1], ResourceFunction["Quaternion"][3, 4, 1, 2]]
Out[15]=

Version History

  • 1.0.0 – 10 July 2019

Related Resources

License Information