Skip to main content

Symbolic Geometric Algebra/Calculus package for SymPy.

Project description

GAlgebra

Symbolic Geometric Algebra/Calculus package for SymPy.

PyPI PyPI - Python Version Python CI Documentation Status DOI

Development Status

PyPI - Status GitHub contributors Codecov Maintainability

brombo/galgebra was originally written by Alan Bromborsky, but was no longer actively maintained, and as of 2019-11-25 no longer exists.

pygae/galgebra is a community fork, maintained by Pythonic Geometric Algebra Enthusiasts.

The fork supports Python 3, increases test coverage, sets up CI and linters, maintains releases to PyPI, improves docs and has many bug fixes, see Changelog.

Features

Geometric Algebra

  • Arbitrary Vector Basis and Metric
  • Scalar, Vector, Bivector, Multivector, Pseudoscalar, Spinor, Blade
  • Basic Geometic Algebra Operations
    • Sum Difference
    • Geometric Product
    • Outer and Inner Products
    • Left and Right Contractions
    • Reverse, Dual, Exponential
    • Commutator
    • Projection, Reflection, Rotation
    • Reciprocal Frames
  • Inspecting Base/Blade Representation
  • Symbolic Manipulations
    • expand, factor, simplify, subs, trigsimp etc.

Overloaded Python operators for basic GA operations:

\begin{split}\begin{aligned}
  A+B &=  \texttt{A+B} \\
  A-B &=  \texttt{A-B} \\
  AB &=  \texttt{A*B} \\
  A \wedge B &=  \mathtt{A \verb!^! B} \\
  A \cdot B &=  \texttt{A|B} \\
  A \rfloor B &=  \texttt{A<B} \\
  A \lfloor B &=  \texttt{A>B} \\
  A/B &=  \texttt{A/B} \\
\end{aligned}\end{split}

Geometric Calculus

  • Geometric Derivative
  • Submanifolds
  • Linear Transformations
  • Differential Operators

The various derivatives of a multivector function is accomplished by multiplying the gradient operator vector with the function:

\begin{aligned}
  \nabla F &=  \texttt{grad*F} \\
  F \bar{\nabla} &=  \texttt{F*rgrad} \\
  \nabla {\wedge}F &=  \mathtt{grad \verb!^! F} \\
  F {\wedge}\bar{\nabla} &=  \mathtt{F \verb!^! rgrad} \\
  \nabla \cdot F &=  \texttt{grad|F} \\
  F \cdot \bar{\nabla} &=  \texttt{F|rgrad} \\
  \nabla \rfloor F &=  \texttt{grad<F} \\
  F \rfloor \bar{\nabla} &=  \texttt{F<rgrad} \\
  \nabla \lfloor F &=  \texttt{grad>F} \\
  F \lfloor \bar{\nabla} &= \texttt{F>rgrad}
\end{aligned}
\begin{aligned}
  F \nabla &=  \texttt{F*grad} \\
  \bar{\nabla} F &=  \texttt{rgrad*F} \\
  F {\wedge}\nabla &=  \mathtt{F \verb!^! grad} \\
  \bar{\nabla} {\wedge}F &=  \mathtt{rgrad \verb!^! F} \\
  F \cdot \nabla &=  \texttt{F|grad} \\
  \bar{\nabla}\cdot F &=  \texttt{rgrad|F} \\
  F \rfloor \nabla &=  \texttt{F<grad} \\
  \bar{\nabla} \rfloor F &=  \texttt{rgrad<F} \\
  F \lfloor \nabla &=  \texttt{F>grad} \\
  \bar{\nabla} \lfloor F &= \texttt{rgrad>F}
\end{aligned}

Tip: an example for getting grad and rgrad of a 3-d Euclidean geometric algebra in rectangular coordinates:

from sympy import symbols
from galgebra.ga import Ga

o3d = Ga('e', g=[1,1,1], coords=symbols('x,y,z',real=True))
(grad,rgrad) = o3d.grads()

Printing

  • Enhanced Console Printing
  • Latex Printing
    • out-of-the-box support for Jupyter Notebook
    • PDF generation and croping support if you have pdflatex/pdfcrop installed

Getting Started

After installing GAlgebra (see section Installing GAlgebra below), in a Jupyter Notebook:

from sympy import symbols
from galgebra.ga import Ga

from galgebra.printer import Format
Format(Fmode = False, Dmode = True)

st4coords = (t,x,y,z) = symbols('t x y z', real=True)
st4 = Ga('e',
         g=[1,-1,-1,-1],
         coords=st4coords)

M = st4.mv('M','mv',f = True)

M.grade(3).Fmt(3,r'\langle \mathbf{M} \rangle _3')

You will see:

\begin{aligned}   \langle \mathbf{M} \rangle _3 =& M^{txy}  \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y} \\  &  + M^{txz}  \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{z} \\  &  + M^{tyz}  \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z} \\  &  + M^{xyz}  \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z}  \end{aligned}

You may also check out more examples here.

For detailed documentation, please visit https://galgebra.readthedocs.io/ .

NOTE: If you are coming from sympy.galgebra or brombo/galgebra, please check out section Migration Guide below.

Installing GAlgebra

Prerequisites

  • Works on Linux, Windows, Mac OSX
  • Python >= 3.8
    • 0.5.0 was the last supported release for Python 3.5-3.7
    • 0.4.x was the last supported release series for Python 2.7
  • SymPy >= 1.3
    • Only SymPy 1.12 is tested via CI, see .github/workflows/ci.yml for more details
    • 0.5.0 was the last supported release for SymPy 1.7

Installing GAlgebra From PyPI (Recommended for users)

pip install galgebra

Then you are all set!

Installing GAlgebra From Source (Recommended for developers)

To install from the latest source code of GAlgebra:

git clone https://github.com/pygae/galgebra.git
cd galgebra
pip install -e .

Note that the optional -e argument is used here for a developer install so modifying the source will take effect immediately without the need of reinstallation.

Now you may run tests to verify the installation, run from the root of the repository:

pip install pytest
pytest test

Further, to run the complete test suite including the ones using nbval, just run:

pip install nbval
pytest --nbval examples/ipython/ test --nbval-current-env --nbval-sanitize-with test/.nbval_sanitize.cfg

This could take more than 10 minutes, please be patient.

Migration Guide

Note: The APIs have changed since the era of sympy.galgebra and brombo/galgebra, some properties and methods are deprecated, the supported versions of Python and SymPy have also changed, please check Changelog and further update your scripts accordingly besides the following. If you encounter any problems, feel free to open an issue!

Migrating from sympy.galgebra

GAlgebra is no longer part of SymPy since 1.0.0, if you have an import like this in your source:

from sympy.galgebra.ga import *

Simply remove the sympy. prefix before galgebra then you are good to go:

from galgebra.ga import *

Migrating from brombo/galgebra

The setgapth.py way to install is now deprecated by pip install galgebra and all modules in GAlgebra should be imported from galgebra, for example:

from galgebra.printer import Format, Eprint, latex, GaPrinter
from galgebra.ga import Ga
from galgebra.mv import Mv, Nga

Bundled Resources

Note that in the doc/books directory there are:

  • BookGA.pdf which is a collection of notes on Geometric Algebra and Calculus based of "Geometric Algebra for Physicists" by Doran and Lasenby and on some papers by Lasenby and Hestenes.
  • galgebra.pdf which is the original main doc of GAlgebra in PDF format, while the math part is still valid, the part describing the installation and usage of GAlgebra is outdated, please read with caution or visit https://galgebra.readthedocs.io/ instead.
  • Macdonald which contains bundled supplementary materials for Linear and Geometric Algebra and Vector and Geometric Calculus by Alan Macdonald, see here and here for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

galgebra-0.5.1.tar.gz (93.8 kB view details)

Uploaded Source

Built Distribution

galgebra-0.5.1-py3-none-any.whl (97.7 kB view details)

Uploaded Python 3

File details

Details for the file galgebra-0.5.1.tar.gz.

File metadata

  • Download URL: galgebra-0.5.1.tar.gz
  • Upload date:
  • Size: 93.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for galgebra-0.5.1.tar.gz
Algorithm Hash digest
SHA256 29aa932e987e037a64931443dd29c8152349a83ec622d39dcbdc0994ad5dd359
MD5 aa936c886396fdcd138be1c8af662a40
BLAKE2b-256 e451e5c34fe85ea928f813cf9b9bc91b5afe6bbe2a734107a2e044b384086a4b

See more details on using hashes here.

File details

Details for the file galgebra-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: galgebra-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 97.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for galgebra-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa1b7f0ffda74489cbb167407bd8ca21b8f1fe4e04cf8c8e608cda7a5f2d2d0
MD5 517e62b50fc973adee6ab9985071bc82
BLAKE2b-256 d85ea56ac23f5f4836734d505cc92337facb403aa128fb30dffff7ab48aa8f1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page