-
Notifications
You must be signed in to change notification settings - Fork 74
Geometric Algebra in Python
This document outlines the development of Geometric Algebra (GA) in Python.
Argument to create yet another GA implementation.
For engineers and scientists to make use of Geometric Algebra they require computational support for the new data-types and operations GA introduces. In recent years Python has become a dominant language in the field of scientific and engineering software development, making it a suitable language for a GA implementation.
Why python?
- Significant number of scientists and engineers have moved to python. (community)
- Python has scientific ecosystem (integration)
- Syntax can become readable, so code looks like the math.
- Python's performance problems are being solved.
- Distribution system is fantastic.
Currently, there is no suitable GA module in python which supports the exploratory computing paradigm, as is generally used by scientific python community.
-
Arbitrary GA's up to reasonable dimensions, like 10.
-
Support syntax thats resemble math, not code. ie,
v = R*v*~R
-
Should act like the rest of exploratory computing stack numpy/scipy/pandas
-
Installable form PyPi and conda.
-
Performance. 8D GA's should no take 10s to instantiate. need to spec this
Some of these features may be contradictory. For example, a rotation (2) of a vector as R*v*~R
will be performed by python as (R*v)*~R
. But given R
and v
, we can do the rotation in about half the number of operations, so a performant code (5) would have to "compile" such an expression, which would seem to contradict the exploratory criterion (3). The point is that meeting these goals will be a balancing act.
There have historically been many GA implementations, some by mathematicians, some by computer scientists. A good outline of difficulties and methods to create GA implementation are made in "Geometric Algebra and its Application to Computer Graphics"
Also, important is Pablo Colapinto's work (available here).
- clifford : this package!
- quaternion : quaternion support for numpy. by @moble
- pyversor : port of versor to python by @tinglest
- ganga.js : recent javascript library
- [ga ] (https://github.com/institution/ga) : simple, pure-python implementation. hard to read.
-
Chris Doran (@chrisjdoran) has made arguments at AGACSE for using Haskel as an suitable language for GA. See https://github.com/ga , @lukeburns. an intersting feature which might be realizable in python is the lazy evaluation of objects (perhaps through use generators as return types).
-
For installation from PyPi, I've found that
pip
has made great strides recently in terms of binary distributions. In particular, if you need to compile code you can create amanylinux1
wheel, which will install the binary on any reasonable linux system. If you have access to mac or windows machines, you can also create binaries for those platforms easily. So basically,pip
is about as good at these things asconda
nowadays. -
I think there's potential for
numba
to be very useful for GA, using expressions constructed in python to create extremely fast numerical code. In particular, since python is so good for writing algorithms, it could be used (maybe withsympy
or similar) to figure out what operations a given GA needs, which components of multivectors need to be combined in what ways for any operation, etc., and then pass that tonumba
for compilation. In my experience,numba
generates code that is just as fast as my delicately hand-tuned C++ code.- A really promising feature of
numba
is its jitclass, which lets you basically write classes in python, but automatically compile them. So I can imagine writing code that takes in the signature of the GA you want, then automatically writes the main GA class containing subclasses for scalar, vector, bivector, spinor, pseudovector, multivector, whatever, and then feeds them into thejitclass
function, returning a bunch of fast objects that know how to operate on each other. The main problem at the moment is that — despite claims of support for_
and__
prefixed attributes — numba does not currently support the various operators like__add__
,__radd__
,__mul__
, etc., which would be necessary to make the syntax resemble math rather than code. There is hope, because this has been added to the goals for the numba 1.0 release (though that's probably a long way away). It would also be feasible to make lightweight python wrappers that know how to call those functions, which would be implemented in jitted functions.
- A really promising feature of
-
Being able to assume orthonormality obviously makes things a lot easier. And it's obviously possible to convert from a non-orthonormal basis to an orthonormal one on every call, but expensive and painful. Is there much demand for working in bases that are not orthonormal? Would it be sufficient to just write wrapper classes that do the transformation, but pay most attention to the orthonormal code?