Anion logo

Anion Homepage


Updates

11-04-2008 - Version 4 released. Changes include:

05-04-2007 - Major changes - now supports a whole new batch of functions, some bugs have been fixed, and the code has been generally cleaned up.
26-03-2007 - Added support for left and right power functions.
22-03-2007 - Added support for exponential and log functions.
22-03-2007 - Added support for trigonometric functions.
22-03-2007 - Added support for hyperbolic functions.
22-03-2007 - Added support for arg function.
22-03-2007 - Added support for polar function.
22-03-2007 - Added support for pow function (real exponent).
22-03-2007 - Added support for pow function (real base).
22-03-2007 - Added support for square root function.


Anion - a real, complex, quaternion and octonion (and above) class for C++

Anion is a C++ class designed to operate like (and be compatible with) the standard complex C++ class, but for more general objects (including but not restricted to reals, complex numbers, quaternions and octonions). It is built around the Cayley-Dickson construction, which defines a method of extending the reals to form the complex numbers, extending the complex numbers to form the quaternions and so on. For more detail, search for the Cayley-Dickson construction.

The class is designed as a work-alike for the std::complex<double> type in C++, and supports all of the associated features (with some minor required changes). It is also interoperable with the std::complex<double> class, so for example addition, subtraction and multiplication (though not division, as in general we are not dealing with commutative objects) between objects works as would be expected. The following list summarises the main differences:


d_anion()

Constructors are:

Assignment operators:

Casting operators:

Parenthesis:

Miscellaneous member functions:

Macros:

Operators: All arithmetic operators should work as expected, except division by quaternions which we have chosen not to implement (one may define both right and left division, and it is not clear which should be chosen for the division operator). Stream input and output operators are also defined. Anionic multiplication is implemented as defined by the Cayley-Dickson construction. That is, if x = (a,b) and y = (c,d) are two anions then the anionic product is given by:

x*y = (a,b)*(c,d) = ( a*c - conj(d)*b , conj(a)*d + cb )


Function and Macros

Complex functions of a single variable can be extended to the quaternion case by noting that the set of numbers of the form R + q.I, where R and I are real and q is an imaginary unit anion are isomorphic to complex numbers by simple interchange of q and i (noting that q commutes with reals, qq = -1, and the conjugate of q is -q). So, given a quaternion a, write a = R + M, where R is real and M is entirely imaginary. If we further define I = abs(M) and q = angle(M) we may write x as:

a = R + q.I

If f is a complex valued function of a single complex variable then, writing:

f(z) = f_R(real(z),imag(z)) + i.f_I(real(z),imag(z))

then, given that q is indistinguishable from the complex imaginery element i so long as q is the only imaginery present, the natural extension of f to the anions is:

f(a) = f_R(R,I) + q.f_I(R,I)

For functions of more than one variable, however, there are difficulties due to the presence of multiple unit imaginary anions which do not in general act like i. In particular, they will not in general commute or multiply to give -1 in general. For this reason we largely avoid defining such functions here.

In some cases where functions are well defined for the complex case, for example acosh(-2), we could define an infinite number of results, as we are going from real to complex without a well defined unit anion q to base our result. If we assume q is complex (and we do) then q is defined up to sign and the sign can be taken care of. If, however, we don't so restrict q then we have an infinite family to chose from, and they all give valid answers. We use two approaches to this problem. By default, we give a complex result with q = i (the complex imaginary unit). Alternatively we provide an additional form of these function with a new argument that is used as the unit imaginary q. If the unit given is 0, however, this version reverts to q = i.

In what follows we define:

a = R + M = R + q.I (where R,I are real and q is unit)
b = S + N = S + r.T (where S,T are real and r is unit)
x = real
y = real

The following functions are provided>

Notes:

* for these functions a second version is provided where the complex imaginary q is explicitly defined as a final argument.
*** log(a) is calculated assuming a branch-cut on the negative real axis of the imaginary component.
**** for octonions and below, powl(b,logbl(a,b)) = a (likewise powr).
***** asin(a), acos(a) and atan(a) follow the recipe of Abramowitz and Stegun for calculation using code borrowed from gsl:
Trigonometric function identity table.
****** asinh(a), acosh(a) and atanh(a) are calculated using the formula:
Hyperbolic function identity table.


Download Anion

Anion is written by Alistair Shilton (a p s h at ee dot unimelb dot edu dot au), and is released under the GPL licence. Source code is available for download here. Source includes makefiles for both unix and djgpp, and should be relatively easy to adapt to other systems.


Old versions


Version 1 source.
Version 1 library pre-compiled for DJGPP.
Old beta source.
Old beta library pre-compiled for DJGPP.
Old alpha source.
Old alpha library pre-compiled for DJGPP.

Anion logo


This page, its contents and style, are the responsibility of the author and do not necessarily represent the views, policies or opinions of The University of Melbourne.

Created : 14th October, 2004

Last Modified : 20th March 2007
Maintained by : Alistair Shilton (a p s h at ee dot unimelb dot edu dot au)
 

Valid HTML 4.01!