Package: kingdon
KingdonPythonic Geometric Algebra PackageFree software: MIT licenseDocumentation:https://kingdon.readthedocs.io.FeaturesKingdon 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,kingdonusesganja.jsfor visualization in notebooks,
making it an extremely well rounded GA package.In bullet points:Symbolically optimized.Leverage sparseness of input.numbaenabled for numerical computations.sympysupport for symbolic computations.ganja.jsenabled graphics in jupyter notebooks.Automatic broadcasting, such that transformations can be applied to e.g. point-clouds.Code ExampleIn order to demonstrate the power ofKingdon, let us first consider the common use-case of the
commutator product between a bivector and vector.In order to create an algebra, useAlgebra. When callingAlgebrawe 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 callinglocals().update(alg.blades):>>>fromkingdonimportAlgebra>>>alg=Algebra(3,0,1)>>>locals().update(alg.blades)>>>b=2*e12>>>v=3*e1>>>b.cp(v)(-6)*e2This example shows that only thee2coefficient 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,kingdonknows that in this case onlye2can be non-zero.Symbolic usageIf only a name is provided for a multivector,kingdonwill automatically populate all
relevant fields with symbols. This allows us to easily perform symbolic computations.>>>fromkingdonimportAlgebra>>>alg=Algebra(3,0,1)>>>b=alg.bivector(name='b')>>>b(b12)*e12+(b13)*e13+(b23)*e23+(b14)*e14+(b24)*e24+(b34)*e34>>>v=alg.vector(name='v')>>>v(v1)*e1+(v2)*e2+(v3)*e3+(v4)*e4>>>b.cp(v)(-b12*v1+b23*v3)*e2+(b12*v2+b13*v3)*e1+(-b13*v1-b23*v2)*e3+(-b14*v1-b24*v2-b34*v3)*e4It 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', e34=3)
>>> b
(b12) * e12 + (3) * e34
>>> v = alg.vector(e1=1, e3=1)
>>> v
(1) * e1 + (1) * e3
>>> w = b.cp(v)
>>> w
(-b12) * e2 + (-3) * e4AkingdonMultiVector with symbols is callable. So in order to evaluatewfrom the previous example,
for a specific value ofb12, simply callw:>>> w(b12=10)
(-10) * e2 + (-3) * e4Overview of OperatorsOperatorsOperationExpressionInfixInlineGeometric product$ab$a*ba.gp(b)Inner$a \cdot b$a|ba.ip(b)Scalar product$\langle a \cdot b \rangle_0$a.sp(b)Left-contraction$a \rfloor b$a.lc(b)Right-contraction$a \lfloor b$a.rc(b)Outer (Exterior)$a \wedge b$a ^ ba.op(b)Regressive$a \vee b$a & ba.rp(b)Conjugatebbya$a b \widetilde{a}$a >> ba.sw(b)Projectaontob$(a \cdot b) \widetilde{b}$a @ ba.proj(b)Commutator ofaandb$a \times b = \tfrac{1}{2} [a, b]$a.cp(b)Anti-commutator ofaandb$\tfrac{1}{2} \{a, b\}$a.acp(b)Sum ofaandb$a + b$a + ba.add(b)Difference ofaandb$a - b$a - ba.sub(b)Reverse ofa$\widetilde{a}$~aa.reverse()Squared norm ofa$a \widetilde{a}$a.normsq()Norm ofa$\sqrt{a \widetilde{a}}$a.norm()Normalizea$a / \sqrt{a \widetilde{a}}$a.normalized()Square root ofa$\sqrt{a}$a.sqrt()CreditsThis package was inspired by GAmphetamine.js.History0.1.0 (2023-08-12)First release on PyPI.