pygae / galgebra

Symbolic Geometric Algebra/Calculus package for SymPy :crystal_ball:
https://galgebra.rtfd.io/
BSD 3-Clause "New" or "Revised" License
234 stars 62 forks source link
clifford-algebras geometric-algebra physics python quaternions symbolic

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.

For information on how GAlgebra is used in other projects, see Used by.

[!IMPORTANT] Readers of Prof. Alan Macdonald's Linear and Geometric Algebra and Vector and Geometric Calculus, please check out Migrating guide for readers of LAGA&VAGC below.

If you are coming from sympy.galgebra or brombo/galgebra (unlikely nowadays), please check out section the old Migration Guide.

Features

Geometric Algebra

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 &=  \mathtt{A \lt B} \\
  A \lfloor B &=  \mathtt{A \gt B} \\
  A/B &=  \texttt{A/B} \\
\end{aligned}\end{split}

Geometric Calculus

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 &=  \mathtt{grad \lt F} \\
  F \rfloor \bar{\nabla} &=  \mathtt{F \lt rgrad} \\
  \nabla \lfloor F &=  \mathtt{grad \gt F} \\
  F \lfloor \bar{\nabla} &= \mathtt{F \gt 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 &=  \mathtt{F \lt grad} \\
  \bar{\nabla} \rfloor F &=  \mathtt{rgrad \lt F} \\
  F \lfloor \nabla &=  \mathtt{F \gt grad} \\
  \bar{\nabla} \lfloor F &= \mathtt{rgrad \gt 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

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/ .

Installing GAlgebra

Prerequisites

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/ --nbval examples/primer/ test --nbval-current-env --nbval-sanitize-with test/.nbval_sanitize.cfg

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

Migration Guide

Migrating guide for readers of LAGA&VAGC

Readers of Linear and Geometric Algebra and Vector and Geometric Calculus might be guided by GAlgebra Primer (version November 29, 2022, accessed May, 2024) to download GAfiles.zip and copy gprinter.py, lt.py, mv.py, and GAlgebraInit.py¸ into where GAlgebra is installed.

These steps are NO LONGER NEEDED since GAlgebra 0.6.0 as they are merge into GAlgebra with tests, copying these files will cause conflicts and regressions of fixed bugs. Instead, you may follow the following steps:

pip uninstall galgebra
pip install git+https://github.com/pygae/galgebra.git

GAlgebra will be installed as 0.6.0-dev as 0.6.0 has not yet been finalized and published to PyPI.

For minor differences to those files, please check out the change log for GAlgebra 0.6.0. Also please note that:

Bundled Resources

Note that in the doc/books directory there are:

Star History

Star History Chart

Contributors

Made with contrib.rocks.

Citing This Library

For citation information, see our CITATION.md file.