Cayley–Dickson numbers

Quaternions, octonions and the doubling ladder

One construction builds the complex numbers from the reals, the quaternions from the complex numbers, the octonions from the quaternions, and keeps going. Each step doubles the dimension and gives up one law of arithmetic. Everything here is exact.

The construction

A number of the next level is a pair (a,b)(a, b) of numbers of this one, with

(a,b)(c,d)=(ac−dˉb, da+bcˉ)(a,b)‾=(aˉ,−b). (a, b)(c, d) = (ac - \bar d b,\ da + b\bar c) \qquad \overline{(a, b)} = (\bar a, -b).

Starting from the reals, where aˉ=a\bar a = a, the pairs are the complex numbers with i=(0,1)i = (0, 1). Pairs of those are the quaternions, with j=(0,1)j = (0, 1) and k=(0,i)k = (0, i). Then come the octonions (dimension 8), the sedenions (16), and so on without end.

import { quaternions, octonions, sedenions, cayleyDickson, quaternion, octonion } from "@ratmath/complex/cayley";

const [one, i, j, k] = quaternions.units;
String(i.mul(j));              // "k"
String(j.mul(i));              // "-k": order matters
String(i.mul(j).mul(k));       // "-1": Hamilton's i j k = −1

const q = quaternion(1, 2, 3, 4);        // or quaternion("1 + 2i + 3j + 4k")
String(q.norm());              // "30"
String(q.conj());              // "1 - 2i - 3j - 4k"
String(q.inv());               // "1/30 - 1/15i - 1/10j - 2/15k"
String(q.mul("i"));            // "-2 + i + 4j - 3k"
String(quaternion("i").mul(q));// "-2 + i - 4j + 3k"

String(octonion("e1 + 2 e7").mul(octonion("1 - e3")));   // "e1 + e2 - 2 e4 + 2 e7"
cayleyDickson(5).dim;          // 32; levels 0 to 8 are available

Elements are immutable, with coordinates in .coeffs on the basis 1,e1,e2,…1, e_1, e_2, \dots (written 1,i,j,k1, i, j, k for the quaternions). The methods are add sub mul neg scale conj norm inv pow rightDivide leftDivide commutator associator equals. Arguments may be elements, numbers, coefficient lists or text.

What each level loses

LevelNameDimensionLosesStill has
0real numbers1order, and everything below
1complex numbers2order; zˉ=z\bar z = zcommutative, associative
2quaternions4commutativityassociative: a division ring
3octonions8associativityalternative, N(xy)=N(x)N(y)N(xy) = N(x)N(y), division
4sedenions16alternativity, the norm law, divisionflexible, power-associative, inverses

algebra.properties() finds these by exact computation instead of quoting them, and for the sedenions and beyond it returns an actual pair of zero divisors:

octonions.properties();
// { name: "octonions", dimension: 8, commutative: false, associative: false,
//   alternative: true, flexible: true, composition: true, zeroDivisors: null }

const [a, b] = sedenions.properties().zeroDivisors;
String(a);  String(b);         // "e1 + e10", "e4 - e15"
String(a.mul(b));              // "0", though neither factor is 0

Alternative means (xx)y=x(xy)(xx)y = x(xy) and (yx)x=y(xx)(yx)x = y(xx): any two elements generate an associative algebra, even though three do not. Flexible means (xy)x=x(yx)(xy)x = x(yx). Power-associative means xnx^n does not depend on how it is bracketed, which is why pow works at every level.

Norm and inverse

At every level xxˉ=xˉx=N(x)x\bar x = \bar x x = N(x), the sum of the squares of the coordinates, so x−1=xˉ/N(x)x^{-1} = \bar x / N(x) is a two-sided inverse of any nonzero xx. What changes is what an inverse is good for. Up to the octonions N(xy)=N(x)N(y)N(xy) = N(x)N(y), which makes xy=0xy = 0 impossible unless a factor is 0, and x=ab−1x = ab^{-1} solves xb=axb = a. In the sedenions the norm law fails, zero divisors appear, and xb=axb = a may have no solution or many; rightDivide and leftDivide check their answer there and refuse (code no-quotient) when it does not hold.

The norm law is a statement about sums of squares. For the complex numbers it is the two-square identity of Diophantus, for the quaternions Euler's four-square identity, for the octonions Degen's eight-square identity. Hurwitz proved in 1898 that there are no others: an identity of this kind exists only for 1, 2, 4 and 8 squares. The ladder goes on, but the good behaviour stops at the octonions.

Commutators and associators

[x,y]=xy−yx[x, y] = xy - yx measures the failure of commutativity and [x,y,z]=(xy)z−x(yz)[x, y, z] = (xy)z - x(yz) the failure of associativity.

const O = octonions;
String(O.basis(1).mul(O.basis(2)).mul(O.basis(4)));         // "e7"
String(O.basis(1).mul(O.basis(2).mul(O.basis(4))));         // "-e7"
String(O.basis(1).associator(O.basis(2), O.basis(4)));      // "2 e7"

Other fields

cayleyDickson(level, field) builds the algebra over any RatMath field object. Over CQ from the main entry point the level-2 algebra is the biquaternions (quaternions with complex coefficients), which do have zero divisors: (1+ii′)(1−ii′)=0(1 + ii')(1 - ii') = 0 where i′i' is the scalar one.

Try itEdit the code and run it with @ratmath/complex and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs