# Quaternions Package

This package implements Hamilton's quaternion algebra. Quaternions have the form where , , , and are real numbers. The symbols , , and are multiplied according to the rules . 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 package imitates the Wolfram Language*'*s 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 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+Jc+Kd.

Quaternion[a,b,c,d] | the quaternion number |

QuaternionQ[w] | tests whether w is a quaternion number |

FromQuaternion[w] | transforms the Quaternion object w to the symbolic form a+Ib+Jc+Kd |

ToQuaternion[w] | transforms w to a Quaternion object if possible |

Defining, testing, and transforming quaternions.

In[1]:= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

The primary purpose of this package is to define arithmetic for quaternions. It adds rules to Plus, Minus, Times, Divide, and, most importantly, NonCommutativeMultiply. It is only legal to use Times when multiplying two nonquaternions or a quaternion by a scalar (i.e. real) number. When multiplying two quaternions, you must use NonCommutativeMultiply.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

Although quaternions are whole algebraic objects, just as with complex numbers, it is sometimes useful to look at their component parts. These objects form a vector space over the real numbers, with their standard basis being . You may use standard Wolfram Language techniques for extracting the individual components. However, there are other vector‐type parameters such as length and direction that you may want to look at as well.

The projection of a quaternion onto space, the nonreal part of the quaternion, is called the pure quaternion part. This plays a role similar to the pure imaginary part of a complex number.

Re[w] | the real part Re w |

Conjugate[w] | the quaternion conjugate |

Abs[w] | the absolute value |

AbsIJK[w] | the magnitude of the pure quaternion part of w |

Norm[w] | the sum of the squares of the components of w |

Sign[w] | the sign of the quaternion w |

AdjustedSignIJK[w] | the sign of the pure quaternion part of w, adjusted so its first nonzero component is positive |

Component functions of quaternions.

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

For a complex number , is defined by . The package defines in a similar way, using the pure quaternion part of q instead of the pure imaginary part of a complex number. Indeed, it makes analogous definitions for the following elementary functions: Exp, Log, Cos, Sin, Tan, Sec, Csc, Cot, ArcCos, ArcSin, ArcTan, ArcSec, ArcCsc, ArcCot, Cosh, Sinh, Tanh, Sech, Csch, Coth, ArcCosh, ArcSinh, ArcTanh, ArcSech, ArcCsch, and ArcCoth.

In[13]:= |

Out[13]= |

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

The functions so far have been intended to work with quaternions whose components are arbitrary real numbers. Just as the integers and Gaussian integers are interesting subsets of the reals and complexes, there is a special subset of the quaternions called the quaternion integers. This subset is a little broader than you might expect. It includes not only those quaternions that have all integer components, but also those quaternions that have all components being odd multiples of . In this subset there are 24 quaternions that have multiplicative inverses. These are the units of the algebra. They correspond roughly to , , , and in the Gaussian integers.

Round[w] | the closest integer quaternion to w |

OddQ[w] | tests whether the quaternion w is odd |

EvenQ[w] | tests whether the quaternion w is even |

IntegerQuaternionQ[w] | tests whether the quaternion w is an integer quaternion |

UnitQuaternions | the list of 24 units of Hamilton's division algebra |

UnitQuaternionQ[w] | tests whether w is a unit quaternion |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

Given a quaternion and a unit quaternion , then and are, respectively, right and left associates of . It is useful to choose an arbitrary associate and call it the primary associate. This package chooses the associate with the largest real component.

LeftAssociates[w] | the list of 24 left associates of the quaternion w |

RightAssociates[w] | the list of 24 right associates of the quaternion w |

PrimaryLeftAssociate[w,side] | the primary left associate of the quaternion w |

PrimaryRightAssociate[w,side] | the primary right associate of the quaternion w |

The associates of an integer quaternion.

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

Quaternion multiplication is noncommutative, so there are two greatest common denominators, one for the left side and one for the right. Since this function depends on the value returned by PrimaryLeftAssociate and PrimaryRightAssociate, the RightGCD and LeftGCD are not unique.

LeftGCD[w,u] | the greatest common left divisor of w and u |

RightGCD[w,u] | the greatest common right divisor of w and u |

Mod[w,u] | w modulo u (remainder on division of w by u) |

Some integer division functions.

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

PrimeQ has the option GaussianIntegers->True that checks to see if a number is prime with respect to the Gaussian integers. This package extends PrimeQ farther to check if a number is prime with respect to the quaternions.

Lagrange proved that every integer can be expressed as a sum of squares of, at most, four integers. Therefore, given an integer n, there is a quaternion q with integer components such that q**Conjugate[q]==n. So no integer is prime with respect to the quaternions. In fact, a quaternion integer is prime if and only if its norm is prime in the usual sense.

PrimeQ[n,Quaternions->True] | test whether n is a prime with respect to the quaternions |

An extension of PrimeQ.

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

In[27]:= |

Out[27]= |