README (original) (raw)

Quaternions and octonions in R

CRAN_Status_Badge

Overview

The onion package provides functionality for working with quaternions and octonions in R. A detailed vignette is provided in the package.

Informally, the quaternions, usually denoted , are a generalization of the complex numbers represented as a four-dimensional vector space over the reals. An arbitrary quaternion represented as

[ q=a + b\mathbf{i} + c\mathbf{j}+ d\mathbf{k}](https://latex.codecogs.com/png.latex?%0Aq%3Da%20%2B%20b%5Cmathbf%7Bi%7D%20%2B%20c%5Cmathbf%7Bj%7D%2B%20d%5Cmathbf%7Bk%7D%0A " q=a + b + c+ d ")

where and are the quaternion units linked by the equations

[ \mathbf{i}2= \mathbf{j}2= \mathbf{k}^2= \mathbf{i}\mathbf{j}\mathbf{k}=-1.](https://latex.codecogs.com/png.latex?%0A%5Cmathbf%7Bi%7D%5E2%3D%0A%5Cmathbf%7Bj%7D%5E2%3D%0A%5Cmathbf%7Bk%7D%5E2%3D%0A%5Cmathbf%7Bi%7D%5Cmathbf%7Bj%7D%5Cmathbf%7Bk%7D%3D-1\. " 2= 2= ^2= =-1.")

which, together with distributivity, define quaternion multiplication. We can see that the quaternions are not commutative, for while , it is easy to show that . Quaternion multiplication is, however, associative (the proof is messy and long).

Defining

[ \left( a+b\mathbf{i} + c\mathbf{j}+ d\mathbf{k}\right){-1}= \frac{1}{a2 + b^2 + c^2 + d^2} \left(a-b\mathbf{i} - c\mathbf{j}- d\mathbf{k}\right)](https://latex.codecogs.com/png.latex?%0A%5Cleft%28%20a%2Bb%5Cmathbf%7Bi%7D%20%2B%20c%5Cmathbf%7Bj%7D%2B%20d%5Cmathbf%7Bk%7D%5Cright%29%5E%7B-1%7D%3D%0A%5Cfrac%7B1%7D%7Ba%5E2%20%2B%20b%5E2%20%2B%20c%5E2%20%2B%20d%5E2%7D%0A%5Cleft%28a-b%5Cmathbf%7Bi%7D%20-%20c%5Cmathbf%7Bj%7D-%20d%5Cmathbf%7Bk%7D%5Cright%29%0A " ( a+b + c+ d)^{-1}= (a-b - c- d) ")

shows that the quaternions are a division algebra: division works as expected (although one has to be careful about ordering terms).

The octonions are essentially a pair of quaternions, with a general octonion written

a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k}+e\mathbf{l}+f\mathbf{il}+g\mathbf{jl}+h\mathbf{kl}

(other notations are sometimes used); Baez gives a multiplication table for the unit octonions and together with distributivity we have a well-defined division algebra. However, octonion multiplication is not associative and we have in general.

Installation

You can install the released version of onion from CRAN with:

The onion package in use

The basic quaternions are denoted H1, Hi, Hj and Hk and these should behave as expected in R idiom:

Function rquat() generates random quaternions:

Octonions

Octonions follow the same general pattern and we may show nonassociativity numerically:

References

Further information

For more detail, see the package vignette

vignette("onionpaper")