Pythonic Geometric Algebra Package
Project description
Kingdon
Pythonic Geometric Algebra Package
Free software: MIT license
Documentation: https://kingdon.readthedocs.io.
โจ Try kingdon in your browser โจ
Cite as:
@misc{roelfs2025willingkingdoncliffordalgebra,
title={The Willing Kingdon Clifford Algebra Library},
author={Martin Roelfs},
year={2025},
eprint={2503.10451},
archivePrefix={arXiv},
primaryClass={cs.MS},
url={https://arxiv.org/abs/2503.10451},
}
Features
Kingdon is a Geometric Algebra (GA) library which combines a Pythonic API with
symbolic simplification and just-in-time compilation to achieve high-performance in a single package.
It support both symbolic and numerical GA computations.
Moreover, kingdon uses ganja.js for visualization in notebooks,
making it an extremely well rounded GA package.
In bullet points:
Symbolically optimized.
Leverage sparseness of input.
ganja.jsenabled graphics in jupyter notebooks.Agnostic to the input types: work with GAโs over
numpyarrays,PyTorchtensors,sympyexpressions, etc. Any object that overloads addition, subtraction and multiplication makes for valid multivector coefficients inkingdon.Automatic broadcasting, such that transformations can be applied to e.g. point-clouds.
Compatible with
numbaand other JIT compilers to speed-up numerical computations.
Code Example
In order to demonstrate the power of Kingdon, let us first consider the common use-case of the
commutator product between a bivector and vector.
In order to create an algebra, use Algebra. When calling Algebra we must provide the signature of the
algebra, in this case we shall go for 3DPGA, which is the algebra \(\mathbb{R}_{3,0,1}\).
There are a number of ways to make elements of the algebra. It can be convenient to work with the basis blades directly.
We can add them to the local namespace by calling locals().update(alg.blades):
>>> from kingdon import Algebra
>>> alg = Algebra(3, 0, 1)
>>> locals().update(alg.blades)
>>> b = 2 * e12
>>> v = 3 * e1
>>> b * v
-6 ๐โ
This example shows that only the e2 coefficient is calculated, despite the fact that there are
6 bivector and 4 vector coefficients in 3DPGA. But by exploiting the sparseness of the input and by performing symbolic
optimization, kingdon knows that in this case only e2 can be non-zero.
Symbolic usage
If only a name is provided for a multivector, kingdon will automatically populate all
relevant fields with symbols. This allows us to easily perform symbolic computations.
>>> from kingdon import Algebra
>>> alg = Algebra(3, 0, 1)
>>> b = alg.bivector(name='b')
>>> b
b01 ๐โโ + b02 ๐โโ + b03 ๐โโ + b12 ๐โโ + b13 ๐โโ + b23 ๐โโ
>>> v = alg.vector(name='v')
>>> v
v0 ๐โ + v1 ๐โ + v2 ๐โ + v3 ๐โ
>>> b.cp(v)
(b01*v1 + b02*v2 + b03*v3) ๐โ + (b12*v2 + b13*v3) ๐โ + (-b12*v1 + b23*v3) ๐โ + (-b13*v1 - b23*v2) ๐โ
It is also possible to define some coefficients to be symbolic by inputting a string, while others can be numeric:
>>> from kingdon import Algebra, symbols
>>> alg = Algebra(3, 0, 1)
>>> b = alg.bivector(e12='b12', e03=3)
>>> b
3 ๐โโ + b12 ๐โโ
>>> v = alg.vector(e1=1, e3=1)
>>> v
1 ๐โ + 1 ๐โ
>>> w = b.cp(v)
>>> w
3 ๐โ + (-b12) ๐โ
A kingdon MultiVector with symbols is callable. So in order to evaluate w from the previous example,
for a specific value of b12, simply call w:
>>> w(b12=10)
3 ๐โ + -10 ๐โ
Overview of Operators
Operation |
Expression |
Infix |
Inline |
|---|---|---|---|
Geometric product |
$ab$ |
|
|
Inner |
$a \cdot b$ |
|
|
Scalar product |
$\langle a \cdot b \rangle_0$ |
|
|
Left-contraction |
$a \rfloor b$ |
|
|
Right-contraction |
$a \lfloor b$ |
|
|
Outer (Exterior) |
$a \wedge b$ |
|
|
Regressive |
$a \vee b$ |
|
|
Conjugate |
$a b \widetilde{a}$ |
|
|
Project |
$(a \cdot b) \widetilde{b}$ |
|
|
Commutator of |
$a \times b = \tfrac{1}{2} [a, b]$ |
|
|
Anti-commutator of |
$\tfrac{1}{2} \{a, b\}$ |
|
|
Sum of |
$a + b$ |
|
|
Difference of |
$a - b$ |
|
|
โDivideโ |
$a b^{-1}$ |
|
|
Inverse of |
$a^{-1}$ |
|
|
Reverse of |
$\widetilde{a}$ |
|
|
Grade Involution of |
$\hat{a}$ |
|
|
Clifford Conjugate of |
$\bar{a} = \hat{\widetilde{a}}$ |
|
|
Squared norm of |
$a \widetilde{a}$ |
|
|
Norm of |
$\sqrt{a \widetilde{a}}$ |
|
|
Normalize |
$a / \sqrt{a \widetilde{a}}$ |
|
|
Square root of |
$\sqrt{a}$ |
|
|
Dual of |
$a*$ |
|
|
Undual of |
|
||
Grade |
$\langle a \rangle_k$ |
|
Credits
This package was inspired by GAmphetamine.js.
History
0.1.0 (2023-08-12)
First release on PyPI.
0.2.0 (2024-01-09)
Multivectors now have map and filter methods to apply element-wise operations to the coefficients.
Make matrix representations of expressions using expr_as_matrix.
Bugfixes.
0.3.0 (2024-03-11)
Much faster codegen by the introduction of a GAmphetamine.js inspired RationalPolynomial class, which now replaces SymPy for codegen. Particularly for inverses this is orders of magnitude faster.
Performed a numbotomy: numba is no longer a dependency since it actually didnโt add much in most cases. Instead the user can now provide the Algebra with any wrapper function, which is applied to the generated functions. This can be numba.njit, but also any other decorator.
0.3.2 (2024-03-18)
Fixed a high priority bug in the graph function.
Fixed a bug that stopped multivectors from being callable.
1.0.0 (2024-04-17)
Kingdon now has proper support for ganja.js animations and the graphs are interactive!
Indexing a multivector will no longer access coefficients. The whole promise of GA is coordinate independence, so why would you need to access coefficients? Instead, slicing a multivector will pass on that information to the underlying datastructures (e.g. numpy array or pytorch tensor), and will return a new multivector. Moreover, you can use the new slicing syntax to set values as well. If you really still need access to the coefficients, there is always the getattr syntax or the .values() method.
1.0.5 (2024-06-26)
Blades by grade syntax: alg.blades.grade(2).
Fixed โdefineโ error in ganja.js integration, kingdon now works with reveal.js voila template.
1.0.6 (2024-07-10)
Bugfixes to ganja.js integration: * Make sure camera is an object before checking for โmvโ key. * Improved draggable points for PGA.
1.1.0 (2024-08-10)
Map and filter now support two argument functions. If such a funtion is provided, map/filter is applied on key, value pairs.
Added exponential function for simple objects.
Raising a mv to 0.5 is now correctly interpreted as a square root. This enables e.g. automatic differentiation.
1.1.2 (2024-11-15)
Improved printing, especially for multivector with array or multivector coefficients.
pretty_blade options added to algebra, to allow users to choose the printing of basis blades.
getattr bugfix
1.2.0 (2024-12-16)
Binary operators are now broadcasted across lists and tuples, e.g. R >> [point1, point2].
Projection (@) and conjugation (>>) are now symbolically optimized by default.
Matrix reps made with expr_as_matrix now have better support for numerical (and multidimensional) multivectors.
1.3.0 (2025-03-10)
Added custom basis support! You can now choose your own basis, to reduce the number of sign swaps. E.g. e31 instead of e13 for the j quaternion.
Added Algebra.fromname alternative constructor, to initiate popular algebras with optimized bases, identical to GAmphetamine.js.
Codegen has been made 2-15 times faster for basic operators.
Updated the documentation.
1.3.1 (2025-06-06)
Bugfix release: * matrix reps are now correct in all signatures (including custom signatures). * Fixed setattr discrepancy when trying to set a basis blade with setattr. * Support copying multivectors
1.4.0 (2025-07-11)
Massive large algebra improvement! * In theory up to 36 dimensions are supported* * Above d > 6 kingdon switches to large algebra mode and attempts to make optimizations * Exotic algebras like 2DCSGA (R5,3), Mother Algebra (R4,4) and 3DCCGA (R6,3) are no longer out of reach, see teahouse! * Bugfix: multivectors now take priority over numpy arrays in binary operators even when the numpy array is on the left.
2.0.0 (2026-02-10)
Length of a multivector is now defined such that multivectors are sequences if their coefficients are arrays. This allows users to iterate over e.g. point clouds naturally.
Improved documentation for array syntax.
Large algebra performance improvements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kingdon-2.0.0.tar.gz.
File metadata
- Download URL: kingdon-2.0.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90fde767ddab35826c72c81d33aa957c2b94356704ce71c7c21c0cc6f40a3ae1
|
|
| MD5 |
848144f3bccc46d1718204e7e9d2ed0a
|
|
| BLAKE2b-256 |
25f3fc7304cd73d2d38b85295d6ac5fa67740a6f565872c1aeefc6469cab4baf
|
File details
Details for the file kingdon-2.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: kingdon-2.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09cef9930bc94d59e3e885c9ecc4adaa6f32a4993b6ff4c4db132c4b8eb639fc
|
|
| MD5 |
90fe7bd3ae45cc858af4a1dcbf2d52f8
|
|
| BLAKE2b-256 |
f1c2ff11628bc2cc9fc351f2d53ffacbcd6c115c4326dbe2886db183eeea3883
|