hyprat: rational hypercomplex numbers
hyprat provides an immutable Hy class for exact, rational-valued
hypercomplex numbers built via the Cayley-Dickson construction:
rank 0 -> a plain fractions.Fraction (a "real")
rank 1 -> Hy(real, imag) (a "complex" number)
rank 2 -> Hy(h1, h2), h1/h2 rank 1 (a "quaternion")
rank 3 -> Hy(h3, h4), h3/h4 rank 2 (an "octonion")
rank n -> Hy(x, y), x/y rank (n-1)
All arithmetic (+ - * /), conjugation, norms, and inverses are
defined recursively by the standard Cayley-Dickson formulas, so the
same class correctly represents rational complex numbers, quaternions,
octonions, and beyond – all with exact fractions.Fraction
arithmetic, no floating-point rounding.
Installation
hyprat requires Python 3.9 or later and has no runtime dependencies.
pip install git+https://github.com/alreich/hyper_rationals.git
Optional extras: interop (SymPy, numpy-quaternion, quaternionic and NumPy,
needed by the to_*/from_* interoperability methods and by
to_matrix/from_matrix), test, docs and dev (everything).
For example:
pip install "hyprat[interop] @ git+https://github.com/alreich/hyper_rationals.git"
Quickstart
>>> from hyprat import Hy
>>> z = Hy('5/2', '-16/5')
>>> str(z)
'(5/2-16/5j)'
>>> q = Hy(Hy(1, 2), Hy(3, 4)) # a rational quaternion
>>> str(q)
'(1+2i+3j+4k)'
>>> i = Hy(Hy(0, 1), Hy(0, 0))
>>> j = Hy(Hy(0, 0), Hy(1, 0))
>>> str(i * j)
'(k)'
>>> Hy.from_array([1, 2, 3, 4]) # same quaternion, from a flat list
Hy(Hy('1', '2'), Hy('3', '4'))
Contents
- Usage
- Constructing Hypercomplex Numbers, Recursively, via the Class
Hy - Other Ways to Construct Hypercomplex Numbers
- Arithmetic
- More on Random Hypercomplex Numbers
- Units
- LaTeX rendering
- Matrix representation
- Split-hypercomplex numbers and other signatures
- Interoperability with Other Quaternion Packages
- Interoperability with
gint(Gaussian Integers and Rationals) - Hurwitz Integers (the Class
Hu)
- Constructing Hypercomplex Numbers, Recursively, via the Class
- API Reference
- Bibliography
- Introductory Lecture Notes
- Expository / Review Articles
- Survey Papers
- Tutorials & Pedagogical Introductions
- Seminal / Foundational Papers
- Short Research Notes & Expository Overviews
- Matrix Representations of Octonions and the Cayley-Dickson Tower
- Hurwitz Quaternions, Factorization and Sums of Four Squares