Expand description
§octonion
Minimal, dependency-free, no_std octonion algebra for Rust.
This crate provides Octonion (an 8D hypercomplex number over f64) with
basic arithmetic, conjugation, norms, and inversion.
§Quick start
use octonion::Octonion;
let x = Octonion::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
// Basis elements square to -1.
assert_eq!(Octonion::E1 * Octonion::E1, -Octonion::ONE);
// Non-commutativity.
assert_eq!(Octonion::E1 * Octonion::E2, Octonion::E3);
assert_eq!(Octonion::E2 * Octonion::E1, -Octonion::E3);
// Conjugation, norm, inverse.
let _conj = x.conj();
let _norm_sq = x.norm_sqr();
let _inv = x.try_inverse().unwrap();§Notes
- Octonion multiplication is non-associative. If you need explicit grouping,
enable
alloc(on by default) and useParenorOctoExpr. - If an octonion lies in the quaternion subalgebra (its
e₄..e₇coefficients are exactly zero), you can callOctonion::as_quaternionto get aQuaternionViewthat supports associative multiplication.
§SIMD helpers
The octonion::simd module includes a direct coefficient expansion
simd::mul_direct (often easier for the compiler to auto-vectorize than the
default implementation).
On x86_64 with avx, simd::mul_simd_avx is available (currently a thin
wrapper around mul_direct).
§Features
alloc(default): enablesParen,OctoExpr, andsimd::mul_batch.alloc(default): enablesParen,OctoExpr, andsimd::mul_batch.e8: enablesoctonion::e8::IntegralOctonion(Cayley integers / E8 lattice).
To use this crate without allocation support:
octonion = { version = "0.1", default-features = false }§Examples and benches
- Colorized display demo:
cargo run --example display_demo - Benchmarks:
cargo bench
§Quick Start
use octonion::Octonion;
// Create an octonion from coefficients
let x = Octonion::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
// Use basis elements
let e1 = Octonion::E1;
let e2 = Octonion::E2;
// Basis elements square to -1
assert_eq!(e1 * e1, -Octonion::ONE);
// Octonion multiplication is non-commutative
assert_eq!(e1 * e2, Octonion::E3);
assert_eq!(e2 * e1, -Octonion::E3);
// Conjugation, norm, and inverse
let conj = x.conj();
let norm_sq = x.norm_sqr();
let inv = x.try_inverse().unwrap();§Mathematical Background
The octonions are an 8-dimensional normed division algebra over the reals. They extend the quaternions in the same way that the quaternions extend the complex numbers. An octonion can be written as:
x = a₀ + a₁e₁ + a₂e₂ + a₃e₃ + a₄e₄ + a₅e₅ + a₆e₆ + a₇e₇where a₀ through a₇ are real numbers and e₁ through e₇ are the
imaginary basis units.
§Properties
- Non-commutative:
xy ≠ yxin general - Non-associative:
(xy)z ≠ x(yz)in general - Alternative:
x(xy) = x²yand(xy)y = xy²(weaker than associativity) - Normed:
|xy| = |x||y|(the norm is multiplicative) - Division algebra: Every non-zero octonion has a multiplicative inverse
§Cayley-Dickson Construction
This crate implements octonion multiplication using the Cayley-Dickson
construction, which represents an octonion as a pair of quaternions (a, b):
(a, b)(c, d) = (ac - d*b, da + bc*)where * denotes quaternion conjugation.
§Features
no_stdcompatible- Zero dependencies
- No unsafe code
- Compile-time constructors via
const fn
Re-exports§
pub use simd::mul_direct;pub use simd::mul_simd_avx;
Modules§
- e8
- Integral Octonions (Cayley integers) over the E8 lattice.
- simd
- SIMD-accelerated octonion multiplication.
Macros§
- octo_
eval - Evaluates an octonion expression with explicit parenthesization.
- octo_
group - Evaluates an octonion expression with keyword-based grouping.
Structs§
- Octonion
- An octonion over
f64, represented in the standard basis. - Paren
- A builder for explicitly parenthesized octonion expressions.
- Quaternion
View - A view into an
Octonionthat is known to have zero coefficients fore₄throughe₇.
Enums§
- Octo
Expr - An unevaluated octonion expression tree.