kingdonclifford numerical GA packagegalgebra symbolic packagetfga tensor-flow packagenumga JAX/numpy backendsThese libraries are all very good within their area of specialization. However, in keeping with the principles of Python, we'd like to
Add GA to any workflow
kingdon Design Philosophy¶kingdon was developed with the following goals in mind:
ganja.js enabled graphics in jupyter notebooks.Add GA to any workflow
Dual numbers $\mathbb{R}_{0,0,1}$ can be used for automatic differentiation:
>>> from kingdon import Algebra
>>> dualalg = Algebra(r=1)
>>> x = dualalg.multivector(e='x', e0=1)
>>> x
x + 1 𝐞₀
>>> x**3
(x**3) + (3*x**2) 𝐞₀
And because dual numbers support $+, -, *, /$ and $\sqrt{}$, we can use them as multivector coefficients in other algebras!
>>> alg = Algebra(3, 0, 1)
>>> tvals = numpy.linspace(0, 3)
>>> t = alg.multivector(e=dualalg.multivector(e=tvals, e0=1))
>>> R = (t * alg.blades.e12).exp(...)
More on this later...
Let's explain the inner workings of kingdon by means of a simple example:
Within $\mathbb{R}_{2, 0, 1}$ (2DPGA) consider the inner product between a bivector $B$ and a vector $v$:
$$ w = B \cdot v $$
To perform this computation symbolically with kingdon looks as follows:
>>> from kingdon import Algebra
>>> alg = Algebra(2, 0, 1)
>>> B = alg.bivector(name='B')
>>> B
B01 𝐞₀₁ + B02 𝐞₀₂ + B12 𝐞₁₂
>>> v = alg.vector(name='v')
>>> v
v0 𝐞₀ + v1 𝐞₁ + v2 𝐞₂
>>> B | v
(B01*v1 + B02*v2) 𝐞₀ + (B12*v2) 𝐞₁ + (-B12*v1) 𝐞₂
Binary representation of basis blades:
| blades | 1 | 𝐞₀ | 𝐞₁ | 𝐞₂ | 𝐞₀₁ | 𝐞₀₂ | 𝐞₁₂ | 𝐞₀₁₂ |
|---|---|---|---|---|---|---|---|---|
| keys | 000 | 001 | 010 | 100 | 011 | 101 | 110 | 111 |
kingdon multivectors are mappings of key/value pairs:
| vector | bivector |
|---|---|
>>> v = alg.vector(name='v')
>>> v
v0 𝐞₀ + v1 𝐞₁ + v2 𝐞₂
>>> v.keys()
(1, 2, 4)
>>> v.values()
[v0, v1, v2]
|
>>> B = alg.bivector(name='B')
>>> B
B01 𝐞₀₁ + B02 𝐞₀₂ + B12 𝐞₁₂
>>> B.keys()
(3, 5, 6)
>>> B.values()
[B01, B02, B12]
|
The kingdon internals are lazy: code is only generated once it is needed.
>>> alg = Algebra(2, 0, 1)
>>> alg.ip
OperatorDict(codegen=<function codegen_ip at 0x0000025BFE604DC0>, ..., operator_dict={})
B | v will cause the code to be generated and excecuted with B and v as input. >>> alg.ip
OperatorDict(codegen=<function codegen_ip at 0x0000025BFE604DC0>, ..., operator_dict={
((3, 5, 6), (1, 2, 4)): ((1, 2, 4), <function codegen_ip_112_x_14 at 0x...>)
})
def codegen_ip_112_x_14(A, B):
[a01, a02, a12] = A
[b0, b1, b2] = B
return [a01*b1+a02*b2, a12*b2, -a12*b1]
kingdon uses the "sparsity" of the input (and performs symbolic optimization when applicable).
Advanced customization:
graded mode to reduce the number of types.cse to eliminate common subexpressionswrapper function to decorate the generated code with, e.g.@numba.njit
def codegen_ip_112_x_14(A, B):
[a01, a02, a12] = A
[b0, b1, b2] = B
return [a01*b1+a02*b2, a12*b2, -a12*b1]
simp_func is a filter function that is applied after every call, e.g. sympy.simplify in symbolic mode or lambda x: abs(x) > 1e-9 for numerical input.symbolcls/codegen_symbolcls specify the symbol class to use during codegen and when making symbolic multivectors.Flanders Make is a strategic research centre for the make industry in the Flanders region of Belgium.
I'd like to share with you the usage of kingdon in two projects at Flanders Make:
Nedschroef & covid ventilator examples

Core principle: represent each tolerance zones using a torsor (screw): $$ T = \begin{pmatrix} u \\ v \\ w \\ \alpha \\ \beta \\ \gamma \end{pmatrix} \qquad \rightarrow \qquad T = u \mathbf{e}_{01} + v \mathbf{e}_{02} + w \mathbf{e}_{03} + \alpha \mathbf{e}_{23} + \beta \mathbf{e}_{13} + \gamma \mathbf{e}_{12} $$


This whole presentation has been a live demo!
kingdon¶Just like ganja.js has its coffeeshop, kingdon has its teahouse: https://tbuli.github.io/teahouse/.

Ganja usage is tolerated in the Teahouse!
Or just install using pip install kingdon!
Common technique: Stack-up analysis. Stack-up is typically done in 1D or 2D, e.g. with the advanced tool that is Excel.
Stack-up software is readily available, with some going up to 3D. Inventor Tolerance Analysis, Creo EZ Tolerance Analysis, 3DCS Variation Analyst (Dedicated software)
We want to go beyond 1D stack-up analysis