GithubHelp home page GithubHelp logo

pygae / galgebra Goto Github PK

View Code? Open in Web Editor NEW
222.0 17.0 62.0 54.36 MB

Symbolic Geometric Algebra/Calculus package for SymPy :crystal_ball:

Home Page: https://galgebra.rtfd.io/

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
geometric-algebra clifford-algebras quaternions physics python

galgebra's Introduction

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.

Note

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, please check out section Migration Guide below.

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 &= \mathtt{A \lt B} \\\ A \lfloor B &= \mathtt{A \gt 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 &= \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

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

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

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

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

  • GAlgebraInit.py is renamed to primer.py and can be imported like from galgebra.primer import * but it's usage is discouraged, although it saves some boilerplate code, this is not part of GAlgebra's maintained API, GAlgebra might remove it in future.
  • Some notebooks from the zip is included in GAlgebra in examples/primer.

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.
    • Particularly, GAlgebraPrimer.pdf is an archived version of GAlgebra Primer by Alan Macdonald, last updated on November 29, 2022.

Star History

Star History Chart

Contributors

Made with contrib.rocks.

Citing This Library

For citation information, see our CITATION.md file.

galgebra's People

Contributors

abrombo avatar arsenovic avatar dependabot[bot] avatar ear-development avatar eric-wieser avatar hugohadfield avatar meuns avatar moble avatar utensil avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

galgebra's Issues

Implementing overdot notation

As brought up by @FreddyBaudine here, @brombe originally described a way to implement the overdot notation in Python as Split Differential Operator which is described in 2.3.4 of GAlgebra: a Geometric Algebra Module for Sympy by Alan Bromborsky .

The overdot notation is used for describing the scope of ∇ which has been used in Geometric Algebra for Physicists by Chris Doran; Anthony Lasenby and many other books and papers. A very brief definition would be

image

( a snapshot taken from hout07.pdf in Course materials of Physical Applications of Geometric Algebra
on http://geometry.mrao.cam.ac.uk/home/teaching-resources/ )

This issue does not mean there is a development plan for implementing overdot notation as either Split Differential Operator or other forms but a place to discuss it.

answers from ga.Ga.mvr and ga.Ga.ReciprocalFrame are different (brombo/galgebra#5)

@chaowenGUO commented on Mar 9, 2016

I use the following code to produce reciprocal frame
import ga
base=ga.Ga('a b')
a,b=base.mv()
ar,br=base.mvr()
but ar|a does not return 1

Moreover, I try to output base.E() after base.mvr(), it does not output a^b. Instead, it outputs a scalar.

Later, I try to use base.ReciprocalFrame(base.mv()) to get the reciprocal frame, then the answer is correct. So why the answers from ga.Ga.mvr and ga.Ga.ReciprocalFrame are different? It seems that mvr() does not return the reciprocal frame, what does it actually do?
reciprocal

@brombo commented on Mar 10, 2016

mvr is also messing up base.E(). I am working to fix this. Thank you
for breaking the code it really helps me.

@brombo commented on Mar 10, 2016

Pushed correction to galgebra on github. In future if you have code in
notebook please attach as ipynb file.

@chaowenGUO commented on Mar 11, 2016

Thank you, now mvr works ok. But you seems to forget to remove line 343 in ga.py
print 'self.e =', self.e
So when I call ga.Ga, it will automatically print the pseudoscalar

@brombo commented on Mar 11, 2016

Will fix it. What are you using GA for?

@chaowenGUO commented on Mar 11, 2016

Before the fix, the following code is working:
import ga,sympy
u,v=sympy.symbols('u,v',real=True)
x,y,z=sympy.symbols('x,y,z',Function=True)
surface=ga.Ga('e1 e2',coords=(u,v),X=[x(u,v),y(u,v),z(u,v)])
print surface.mv()

But now:
It produces the following error:
Traceback (most recent call last):
File "test.py", line 4, in
surface=ga.Ga('e1 e2',coords=(u,v),X=[x(u,v),y(u,v),z(u,v)])
File "/home/ken/Downloads/galgebra-master/galgebra/ga.py", line 327, in init
self.build_reciprocal_basis(self.gsym)
File "/home/ken/Downloads/galgebra-master/galgebra/ga.py", line 1386, in build_reciprocal_basis
self.e_obj = self.e.obj
AttributeError: 'Ga' object has no attribute 'e'

Well, actually I do not quite understand the advanced properties of GA. But I find GA is very useful to deal with a lot of stuffs that can not be handled by linear algebra, say oblique coordinates in crystallography, rotation and reflection of rigid body, analytic geometry in dimension bigger than 3, definition of volume of subspace. Moreover, use it to deduce formula in electrodynamics and hydrodynamics(geometric derivative operator). Now, I am still learning field on manifold, it maybe can help me to define correct quantum potential in phase space.

@brombo commented on Mar 11, 2016

Fixed problem with vector manifold input and pushed to github. Try the
following code -

import ga,sympy
coords = u,v =sympy.symbols('u,v',real=True)
#x,y,z=sympy.symbols('x,y,z',Function=True)

x = sympy.Function('x')(_coords)
y = sympy.Function('y')(_coords)
z = sympy.Function('z')(*coords)

#surface=ga.Ga('e1 e2',coords=(u,v),X=[x(u,v),y(u,v),z(u,v)])
surface=ga.Ga('e1 e2',coords=(u,v),X=[x,y,z])
print surface.g
eu,ev = surface.mv()
eur,evr = surface.mvr()
print (eu|eur).simplify()
print (eu|evr).simplify()
print (ev|eur).simplify()
print (ev|evr).simplify()

I could not get you sympy function definition to work for me.
Note that code took awhile to run on my machine (10 sec)

@chaowenGUO closed this on May 27, 2016


From http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/5

Use sympy.core.compatibility for Py 2/3 issues

When first converting GAlgebra from Python 2 to 3, I was not aware of sympy.core.compatibility and didn't wish to add a dependency like six so some compatibility issues are handled in utils.py which should actually be named compat or something but kept utils as its name so it may also used to put other utility functions.

So it's preferred to use sympy.core.compatibility to handle such issues in the future but the entry point could still be kept in utils if appropriate.

I do not worry that sympy.core.compatibility might go away one day, even this happens it will be after SymPy also drops support for Python 2.7 when past its EOL( https://pythonclock.org/ ), we can deal with the situation by cleaning up the remnants of python 2 support in a new release.

The background of this is that @abrombo 's new work on GAlgebra is no longer considering Python 2 support and I intend to keep the support for 2.7 for a while longer to consolidate its ground for the still-fresh Python 3 support.

Formatting Examples With New Printer Module

I am working through all the examples with the new python 3 printer module. When I finish I will send them to you. I see the collect problem you mentioned in several examples (I am using sympy 1.4). Here is the custom collect I wrote to solve the problem -

def Collect(A, exp_lst):
    (coefs,bases) = linear_expand(A)
    C = S(0)
    for x in exp_lst:
        if x in bases:
            i = bases.index(x)
            C += coefs[i]*x
    return C

I placed it in metric.py just after linear_expand. I have replaced the collect call in ga.py but not in mv.py yet. Are there examples where calling collect is a problem in mv.py that I can use to test. I am only using your galgebra for coding now. Would the best thing for me to do is just put a link to your github site in my github site and tell everone that your is the supported version of galgebra.

sympy.simplify(mv) blows up with Recursion

>>> ga, e1, e2, e3, ep, en = galgebra.ga.Ga.build('e_1 e_2 e_3 e_{+} e_{-}',g=[1,1,1, 1, -1])
>>> sympy.simplify(e1)
RecursionError: maximum recursion depth exceeded while calling a Python object
>>> list(e1)
RecursionError: maximum recursion depth exceeded while calling a Python object

This is because:

  • sympy.simplify and list calls iter(e1)
  • Mv.__iter__ is not defined, so it defaults to:
    def __iter__(self):
        i = 0
        while True:
            try:
                yield self[i]
            except IndexError:
                break
            i += 1
    ```
    
  • Mv.__getitem__ will return 0 forever, as it implies grade selection

Possible fixes:

  • Have Mv.__iter__ raise TypeError
  • Have Mv.__iter__ iterate only up to the highest grade present

Christoffel symbols of the first kind ill calculated - Calculation of the Christoffel symbols of the second kind returns an error

Dear All,

Galgebra does not seem to obtain the correct Christoffel symbols of the first kind; at least the values printed out indicate a skew symmetry, which is strange.

Starting with the metric tensor relating to a two dimensional manifold, the unit sphere, viz.,
image
galgebra yields the following components for the Christoffel symbols of the first kind,
image
when, in fact, the correct values are
image
As is well known, these symbols are symmetrical in the indices alpha and beta.

As for the Christoffel symbols of the second kind they are not calculated, an error is returned instead:

C:\Users\Freddy\Desktop\Issues\Christoffel>C:\Anaconda3\python "Christoffel_symbols_checking.py"
Traceback (most recent call last):
File "Christoffel_symbols_checking.py", line 47, in
Cf2 = sp2.Christoffel_symbols(mode=2)
File "C:\Anaconda3\lib\site-packages\galgebra\metric.py", line 490, in Christoffel_symbols
Gamma_ijk += Gijl * self.g(l,)
TypeError: 'MutableDenseMatrix' object is not callable

C:\Users\Freddy\Desktop\Issues\Christoffel>pause
Press any key to continue . . .

It is not at all clear how the differential operators can be properly computed (see zip file enclosed)
when it is explicitly stated in Section 2.3.1 of Galgebra: a Geometric Algebra Module for Sympy (October 8, 2016) that the Christoffel symbols of the first kind are made use of to perform a number of calculations, notably to obtain the derivatives of the basis vectors (footnote on page 17). Unless the Christoffel symbols are not actually used at all! This would explain that, but I can be totally wrong on this.

Look forward to receiving any views on all this.
Kind regards,
FB
[email protected]
Christoffel.zip

Bump pip version

We should put out a python3 compatible release and bump the version in pypi to give people access to the nnice work of @utensil

Merge features from abrombo's branch

This is currently tracked by #62 and #39 .

Mirroring a slack discussion:

To name a few changes I noticed:

  1. The new printer (do you wish to stop supporting Python 2.7?)
  2. Odot (Have you noticed the discussion and my proposal of design which is less invasive?)
  3. xtex (Have you noticed the xpdf function I modified to support not running pdflatex only generating .tex?)
  4. convert strings to raw strings to avoid escaping (it’s preferable to be on a separate commit)
  5. replace operators like I < > in print manually with their LaTeX correspondence (do you wish to stop support the automatic replacement?)
  6. Lots of space or tab changes
  7. new examples/ipython/tutorial_algebra.ipynb
  8. new examples/ipython/tutorial_calculus.ipynb
  9. your new colllect adapter to solve the SymPy 1.4 compatibility issue
  10. LaTeX changes such as align* to aligned

Regressions I noticed:

  1. Installation instructions;
  2. files that should be ignored using .gitignore;
  3. you seem to be using an old version of Jupyter so some fields in .ipynb are obsolete
  4. setgapth.py is back, it’s already replaced by pip install
  5. tests are failing miserably
  6. Circular dependencies are back

@abrombo replied:

  1. I don't see any point in supporting 2.7 since sympy will not.
  2. Odot is on the back burner for now. Needs much more discussion before doing anything
  3. The default for xtex is what you have xpdf doing now.
  4. I try to always use r'\something' instead of '\something'.
  5. Please explain this better.
  6. Do you mean in the source code?
  7. & 8. I need to go through all the examples
  8. What is the question.
  9. Did I miss some?

Regressions

  1. My bad.
  2. Not familiar with .gitignore.
  3. Will update.
  4. Should not have included it. I use it so my changes to code locally (not in sitepackages) take effect for any executable code py or ipynb.
  5. How do you run tests. I will not push in future until code passes.
  6. My bad again.

Some tests are broken for SymPy 1.4

SymPy 1.4 has just released and some tests are broken for SymPy 1.4, see build https://circleci.com/workflow-run/dcbd3c98-45c3-4c89-abd6-2ea97fa07b2c .

Freeze SymPy version to 1.3 to keep CI green for now.

Tasks:

  • Fix broken collect() calls ---- fixed by #48
  • The fix for order change issue also needs to be delayed until the explicitly change to use SymPy 1.4 in CI after the collect() issue is addressed ---- fixed by #164
  • adding a CI build for SymPy master so these issues can be detected sooner tracked by #94

References to older history of galgebra

When blaming the source of galgebra, most lines ends up at a commit fab9012 on 13 Nov 2015
, before that, it's lost to us.

But somehow the history is preserved at the following places:

Set up proper release version system

As discussed here: #9 (comment) , there should be a way to maintain the version number without redundancies.

Also we need to decide a release cycle, a few milestones and decide when can we send PRs to change sympy to point to pygae/galgebra as discussed here: https://github.com/brombo/galgebra/pull/42#issuecomment-464703367 as well as to change the wiki url: https://en.wikipedia.org/wiki/Geometric_algebra#Actively_developed_open_source_projects

P.S. I'm starting this issue to combine some potential lost discussions and to remove the TODO item from README.md to make it more user-friendly.

Galgebra not able to print some products and inverses of multivectors

Dear all,

Galgebra does not seem to be able to print out quantities such as the following:
Products (inner, left contraction, right contraction or geometric) of a (multi)vector with itself, e.g., a * a. It should be noted that the product of a vector with a different one is OK, e.g., a * b is printed out correctly.
By the same token, no inverse of an invertible multi(vector) is printed out.
It looks as if squares of the components of (multi)vectors were the culprits, as these appear in the above calculations.

Python (3.4 and 3.7):
The computer hangs. Here’s a print screen

C:\Users\Freddy\Desktop\Python\programs>C:\Python34-37\python "spacetimePython3.py"
latex file = spacetimePython3.tex
pdflatex path = C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe

Here’s the message returned to the console after exiting with a ctrl-C:

Traceback (most recent call last):
File "spacetimePython3.py", line 65, in
xpdf(paper=(8,9),crop=True)
File "C:\Python34-37\lib\site-packages\galgebra\printer.py", line 1165, in xpdf
os.system(latex_str + ' ' + filename[:-4] + sys_cmd['null'])
KeyboardInterrupt
Terminate batch job (Y/N)?

I tried IPython (notebook), i.e. Jupyter (with both browsers, viz., Firefox and Chrome).
In this case, the unevaluated latex code is returned and the computer does not hang.

Is there any workaround available?

Kind regards,
Freddy Baudine

Fix and close lingering issues in brombo/galgebra

  • Python 3 support: brombo/galgebra#37 (#119), brombo/galgebra#35 (#117), , brombo/galgebra#33 (lost to time)
  • non-root installation: brombo/galgebra#36 (#118)
  • pip installation: brombo/galgebra#39 (#119)
  • self import: brombo/galgebra#27 (lost to time)
  • no .pyc: brombo/galgebra#2 (fixed)
  • properties: brombo/galgebra#23 (#132)
  • my own (review and close, most likely merged by #2): brombo/galgebra#19 (#119), brombo/galgebra#20 (#110)
  • Visualization: brombo/galgebra#4 (#125)
  • N-dim arrays: brombo/galgebra#3 (#102)

Misc bugs that need some time to fix:

  • brombo/galgebra#38 (#127)
  • brombo/galgebra#34 (#126)
  • brombo/galgebra#32 (#116) ( @arsenovic 's )
  • brombo/galgebra#31 (#115) (quite some discussion)
  • brombo/galgebra#29 (#114, @arsenovic 's )
  • brombo/galgebra#28 (#113, @arsenovic 's )
  • brombo/galgebra#18 (#108)
  • brombo/galgebra#10 (#105)
  • brombo/galgebra#9 (#104) (seems fixed)
  • brombo/galgebra#1 (#101) (seems fixed)

'module' object has no attribute 'Ga' (brombo/galgebra#12)

@utensil commented on May 1, 2016

Enviroment

  • MacBook Pro (Retina, 13-inch, Mid 2014)
  • OSX 10.11.2
  • Python 2.7.11
  • numpy 1.9.2
  • sympy 1.0

Steps

git clone https://github.com/brombo/galgebra.git
cd galgebra
python setup.py install
python setup.py test
import galgebra
galgebra.Ga

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Ga'

If I import ga instead, got

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ga

I looked into examples and tests, and can't figure out what went wrong.

@brombo commented on May 1, 2016

"python setup.py test" not implemented (I don't really know hot to write
a setup.py file). You would need to run tests and examples manually
(one at a time). Also "test_test.py" uses old GA format and was not
converted when I left sympy distribution. There is no more module MV to
import. Will fix
test_test.py when I get time. In examples Terminal/terminal_check.py
and LaTeX/latex_check.py run same tests and more without asserts
(answers printed out).

@utensil commented on May 1, 2016 •
edited

Oh it's not about the tests. I saw 0 tests were run.
Just that I can't use any classes in "ga" or "galgebra" after importing either of them in REPL.

@utensil commented on May 1, 2016

Let's use exact code from "Terminal/terminal_check.py":

$ python
Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:57:58) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from ga import Ga, one, zero
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ga
>>> from galgebra import Ga, one, zero
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name Ga

@brombo commented on May 1, 2016

To install use the instructions starting on page 5 of galgebra.pdf in
the doc directory (specifically section 1.3 in the doc) not setup.py.
Note that the Ipython notebook install section is dated.

@utensil commented on May 2, 2016

I followed the instructions in galgebra.pdf, still no luck:

galgebra $ pwd
/Users/utensil/experiments/galgebra/galgebra
galgebra $ ls
__init__.py __init__.pyc    ga.py       lt.py       metric.py   mv.py       printer.py  setgapth.py
galgebra $ python setgapth.py
Traceback (most recent call last):
  File "setgapth.py", line 28, in <module>
    pth_file = open(pth_name,'w')
IOError: [Errno 2] No such file or directory: '/Users/utensil/miniconda2/lib/site-python/Ga.pth'
galgebra $ ls /Users/utensil/miniconda2/lib/site-python/
ls: /Users/utensil/miniconda2/lib/site-python/: No such file or directory
galgebra $ ls /Users/utensil/miniconda2/lib/
Tk.icns                 libQtScript.4.dylib         libmkl_avx2.dylib
Tk.tiff                 libQtScript.dylib           libmkl_avx512.dylib
engines                 libQtScript.la              libmkl_core.dylib
libQtCLucene.4.8.7.dylib        libQtScript.prl             libmkl_intel.dylib

@utensil commented on May 2, 2016

After manually created the directory:

mkdir '/Users/utensil/miniconda2/lib/site-python'
galgebra $ python setgapth.py
os name: posix
site-packages directory: /Users/utensil/miniconda2/lib/site-python/Ga.pth
Ga.pth:
#Path of Ga module
/Users/utensil/experiments/galgebra/galgebra
0

Python pth file Ga.pth for all modules of galgebra has been created and
placed in directory appropriate for Linux, Windows, or OSX. Note that
if Ga.pth already exists the old version will be deleted.

>>> import ga
>>> ga.Ga
<class 'ga.Ga'>

Succeed.

@utensil commented on May 2, 2016

I'll send a PR to correct instructions in INSTALL .

@brombo commented on May 2, 2016

Thanks for your feedback. I think on OSX the directory where the python
path files reside is not created when python is installed. Are you
using the default python that come with OSX or are your using another
distribution, if so what distribution?

@utensil commented on May 2, 2016

I'm using MiniConda which is a minimal distribution of Anaconda which is widely used.

@utensil commented on May 2, 2016

PR sent.

@utensil commented on May 2, 2016 •
edited

Though not related to this issue, I did notice something wrong in terminal_check.py:

print '-I*(grad^A) =', -o3d.E() * (grad ^ A)

It should be .I() if I'm understanding it correctly.

@utensil commented on May 7, 2016

"python setup.py test" not implemented (I don't really know hot to write
a setup.py file). You would need to run tests and examples manually
(one at a time). Also "test_test.py" uses old GA format and was not
converted when I left sympy distribution. There is no more module MV to
import. Will fix
test_test.py when I get time.

I'm interested in writing a setup.py for galgebra, and add other essential parts to get galgebra into PyPI so it can be installed with pip install galgebra. Also I do have some time to fix the issues you mentioned above. Would you like it to be done? Because I think galgebra is a great library.

@brombo commented on May 7, 2016

I would greatly appreciate you doing such a thing. Thank you very much.

@utensil commented on May 8, 2016

Great, then I would get started.

@brombo closed this in brombo/galgebra#13 on May 11, 2016


From http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/12

Cherry-pick from forks of brombo/galgebra

Use sphinx-math-dollar for Math formula in API documentation

Just found sphinx-math-dollar from this post: https://www.asmeurer.com/blog/posts/quansight-labs-work-update-for-september-2019/ .

Currently, the API documentation of GAlgebra splits into two scattered pieces:

  1. The old doc on the API converted from @abrombo 's original doc in LaTeX, it's great but it's somehow outdated (@abrombo has some updates on the doc and yet to be merged )
  2. The API document automatically generated from docstrings in code but it's mostly ill-formated.

1 is at https://galgebra.readthedocs.io/en/latest/galgebra_guide.html#Module-Components
2 is at https://galgebra.readthedocs.io/en/latest/api.html .

The scenario causes maintenance burden and one of the reasons why @abrombo preferred to work on a separate repo is that it's difficult to maintain LaTeX doc and Sphinx doc (but there wasn't such an automatic API doc back then) at the same time.

By ill-formatted, I mean:

image

It's still parseable but cumbersome. I was aware of this situation but I felt unwilling to rewrite them in the verbose syntax of reStructuredText so I left them there and treated them like plain text.

Now, with the help of sphinx-math-dollar which SymPy is also using, the situation can be fixed. So I opened this issue to add this work to the backlog.

However, this does not solve the maintenance burden issue which I only mentioned it as a context and comments and suggestions are welcome @abrombo @hugohadfield @eric-wieser .

Make `galgebra` pip-installable (brombo/galgebra#14)

@utensil commented on May 8, 2016 •
edited

  • write a setup.py so it can be installed by python setup.py install
  • add .gitignore and remove .pyc files
  • add option --noconflict to use galgebra as namespace
  • fix tests
  • register galgebra on PyPI

This issue is opened to track the work discussed in #12 (comment)

The work would be done according to the instructions in the following documents:

@utensil commented on May 8, 2016

Work would begin at https://github.com/utensil-contrib/galgebra/tree/14-pip . A PR would be created when 1-3 tasks have been completed.

@utensil commented on May 8, 2016 •
edited

A minimal setup.py is written as in commit utensil-contrib@2d6606e .

But it introduced a problem, these module names would be exposed in the global(just the same as the old Ga.pth approach). Should we put them into the namespace galgebra? Then we would use import galgebra.ga instead of import ga. Less global namespace pollution.

@brombo commented on May 8, 2016

You are afraid that there is some other python library that could expose
the same module names globally? The only one I would be worried about
is "printer." Could we have an user option to do it either way since
everyone now using galgebra is doing it with ga.pth?

@utensil commented on May 8, 2016 •
edited

Could we have an user option to do it either way since
everyone now using galgebra is doing it with ga.pth?

Yes, we could. After I implemented it, users can use python setup.py install --noconflict.

And in the setup.py, we could just use this option to choose from package_dir={'galgebra':'galgebra'}, and package_dir={'':'galgebra'}.

@brombo commented on May 8, 2016

Let's do it that way then.

@utensil commented on May 8, 2016

Implemented in utensil-contrib@7ec591e

@brombo commented on May 8, 2016

I see you are at Texas Tech. I tracked gcwenken to Texas Tech and
Chaowen Guo is that who you are? I live in Silver Spring Maryland. If
you ever wish to talk in real time my phone number is 301-625-5951. My
main interest in GA is for physics. If you want the GA notes I wrote
(based on Doran and Lasenby's book) I will put them on Google drive. We
have a study group of physicists, mathematician, and astronomers (most
are retired) that meets on most Friday evenings at the Montgomery
College planetarium. We also have two participants that attend remotely
via Teamviewer. We are currently covering Lagrangian field theory. If
you are interested let me know.

@utensil commented on May 9, 2016

Oh, I'm not at Texas Tech. I'm a senior software engineer at Tencent in China, mainly focused on back-end server development for online payment, using C++/Java/Python/Node.js. So my work is not related to GA in any way, Physics and GA are my personal interest.

I'm a reader of "Geometric Algebra for Physicists", and came across your work when looking for previous efforts on combining symbolic programming and GA. My main interest in GA is also for physics. To me, GA is a brand new way to look at the math we used in Physics, with the power of simplicity, the ability to connect/unite different areas or aspects, and the potential to further reveal the nature of physics.

Personally, I'm using spare time to digest what I've learned from the book and related materials, and planning to implement a GA library in Julia(a very expressive and effective language) as a better way to learn it.

Sorry, due to time zone reason, I might not be able to attend the study group meetings, but I'll really benefit from and appreciate your notes. And I'm also reading your book. It's really very nice of you to share all these.

I haven't been able to find too much progress of GA, especially the applications in Physics. It seems that computer graphics did show some interest in GA, for a possibly more effective way to do rotations than quaternions, and there are some papers to introduce GA to their specific areas in Physics, but not much fruit yet. Do you have a better list of papers regarding this? In other words, do you have a clear roadmap of the latest development of GA? It looks like that, GA is still at a stage to reinterpret established Physics, am I missing something?

@utensil closed this on May 9, 2016

@utensil reopened this on May 9, 2016

@utensil commented on May 9, 2016 •
edited

The last paragraph of my last comment may seem a little doubtful about GA. Actually, I was trying to neutralize my more enthusiastic and radical view: The current math used in physics is not only inefficient but also wrong. By "wrong", I mean that the inefficiency of the current math leads to misleading puzzles. The learning curve of GA is smooth, the time-consuming part is mapping them back to old-fashion math and explain the differences or even seemingly contradictions. I do understand the importance to review all "established" physics, the meaning can be explained by a quote from An Introduction to Geometric Algebra with some Preliminary Thoughts on the Geometric Meaning of Quantum Mechanics :

  • Geometric Algebra provides a unified language for the whole of physics that is conceptually and
    computationally superior to alternative mathematical systems in every application domain
  • Reforming the mathematical language of physics is the single most essential step toward
    simplifying physics education at all levels from high school to graduate school

But what I was looking for, was the breadcrumb of serious adoption of GA in edge theoretical physics research and their findings.

@brombo commented on May 9, 2016

The version of BookGA.pdf on Google drive is the latest version. As the
Cliffhangers cover material on Friday evenings corrections and additions
are suggested that I perform during the following week.

@utensil commented on May 10, 2016

The version of BookGA.pdf on Google drive is the latest version.

Sorry, I can't find your Google Drive.

As the
Cliffhangers cover material on Friday evenings corrections and additions
are suggested that I perform during the following week.

I can't quite follow you on this.

@utensil commented on May 15, 2016

Progress update: I'll start to work on fixing the tests in the coming week.

@utensil commented on May 15, 2016

I'm currently converting test cases one by one. The assertions are usually valid, but there're edge cases with slight differences, correcting the assertions with my own eyes.

There's one problematic:

# FIXME failed with value: (a.b)*c - (b.c)*a - ((a.b)*c - (b.c)*a)
assert str((a|(b^c))+(c|(a^b))+(b|(c^a))) == '0'

It's obvious the output is 0, but not simplified to 0. @brombo , do you know what caused this? This seems to be a problem of the implmentation, not the assertion.

@utensil commented on May 15, 2016 •
edited

An extra .simplify() turn it into 0, see utensil-contrib@7b9425e

Is this intentional?

@brombo commented on May 15, 2016

Simplify can be costly in time so it is not automatically applied after
each operation. It is always a good idea to simplify if testing an
expression to be zero.

@utensil commented on May 15, 2016

Yeah, I also thought that the reason would be for performance.

@micahscopes commented on Apr 24, 2017 •
edited

I have a glsl generator that relies on sage's Clifford Algebra tools to generate high dimensional rotation functions. (I used to rely on sympy.galgebra, until it got spun off into this project). Anyhow, I really would love to be able to switch back to this library so I can publish my project, but I'm using setup.py/pip for dependency management... And pip has removed support for external dependencies.

So I'm kinda at a loss! I don't want to use requirements.txt, cause I want to publish my library.

So I'm wondering about what's holding up this ticket and if there anything I can do to help? Maybe you are waiting to do a stable release?

@utensil commented on Apr 29, 2017

@micahscopes

My plan was add some code to make the project pip-compatible, improve the unit tests and assist in the registering process. The first part is completed, the second part(almost completed) lead me to find a few bugs and I fixed them in my way and presented the codes to be reviewed in #20 . Then, my work on it has stopped after some frustrating communication experience and @brombo kept working on the project and the PR became obsolete. After that, my life took a dramatic turn so I haven't been using or concerning this project ever since.

Personally I can update #20 to match the status of the master branch, but the final part relies heavily on @brombo 's own willing and efforts, along with an open communication channel. The work has paused due to the lack of both.

Hope the information helps. I'm always willing to continue the work on this issue.

@utensil commented on Sep 21, 2018

I'll close this issue as pygae#2 is now merged.

@utensil closed this on Sep 21, 2018


Found at http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/14

Mv(coeffs, 'odd') is nonsensical

I believe the intent of 'odd' is for usage like:

>>> g, *a = Ga.build('e*1|2|3|4')
>>> g.mv('A', 'odd')
A__1*e_1 + A__2*e_2 + A__3*e_3 + A__4*e_4 + A__5*e_5 + A__123*e_1^e_2^e_3 + A__124*e_1^e_2^e_4 + A__125*e_1^e_2^e_5 + A__134*e_1^e_3^e_4 + A__135*e_1^e_3^e_5 + A__145*e_1^e_4^e_5 + A__234*e_2^e_3^e_4 + A__235*e_2^e_3^e_5 + A__245*e_2^e_4^e_5 + A__345*e_3^e_4^e_5 + A__12345*e_1^e_2^e_3^e_4^e_5

However, it can be also use as

>>> g, *a = Ga.build('e*1|2|3|4')
>>> g.mv([2], 'odd')
2*e_1 + 2*e_1^e_2^e_3 + 2*e_1^e_2^e_3^e_4^e_5
>>> g.mv([2, 3], 'odd')
ValueError: Too many coefficients

This doesn't seem remotely useful - I'd propose we deprecate or outright remove it. 'even' already forbids this usage.

Add rule-based rewrite capacity in a coordinate-free way

Continuing from discussions on Slack with @abrombo and @hugohadfield :

Alan Bromborsky:

I think the biggest deficiency of galgebra is that it can only reduce multivector expressions in one direction. All results are in terms of the multivector basis. It would be useful to be able to go in the other direction and rewrite multivector expressions in terms of other multivector expressions.

utensil:

I have the same feeling. Actually I think as a symbolic library, GAlgebra should be able to manipulate GA expression without concerning the basis and simplify GA expressions using predefined rewrite rules. For that, I studied the internal of a few rule-based symbolic rewrite library and wish to be able to implement as such.
As for the rewrite rule list, I find Eric Chisolm's https://arxiv.org/pdf/1205.5935.pdf is pretty good at listing the identities in GA exhaustively in Appendix A Summary of definitions and formulas. I also have verified many of them with GAlgebra.jl (for syntax sugar) at https://github.com/pygae/GAlgebra.jl/blob/master/test/runtests.jl#L67 .

Some of the rule-based symbolic rewrite library/code that I've noticed:

Conversion of Printing to Python 3

Thank you for picking up the torch with regard to galgebra. I just did not have enough time to work on it as required. I have a question about your conversion to python 3. I am trying to use your version and it looks like the python 3 print function is not overloaded. That is if A is a multivector or other object in galgebra the statement "print(A)" does not work. Is this correct?

galgebra doesn't fully support using LaTeX as symbol name

If use something like

symbols(r'{\color{airforceblue}\theta} {\color{applegreen}\phi}', real = True)

will produce invalid LaTeX output caused by double escaping:

! Missing } inserted.
<inserted text>
                }
l.61 ...\ 0 & {\sin{\left ({\color{airforceblue}\\
                                                  theta } \right )}}^{2}  \e...

If use something like

symbols(r'{\color{airforceblue}theta} {\color{applegreen}phi}', real = True)

to avoid double escaping, then the result is partially theta/phi and partially \theta/\phi:

image

The expected result is:

image

References to GAlgebra in literature and other Web resources

This issue is to track references to GAlgebra in literature and other Web resources. The goal is:

  • ensure that pygae/galgebra is consistent with descriptions accompanying the references
  • update the corresponding references to pygae/galgebra

Here are these references:

  • SymPy: https://github.com/sympy/sympy/blob/master/sympy/galgebra.py
  • Linear and Geometric Algebra and Vector and Geometric Calculus by Alan Macdonald:
    • GAlgebra is written in Python 2. One of its components (Sympy), will stop supporting Python 2, probably by the end of 2019. Alan Bromborsky is converting GAlgebra to Python 3.
    • GAlgebraPrimer.pdf contains instructions for installing and using GAlgebra. The primer also downloads with GAlgebra. Updated 1/24/18.
  • LAGA Intro by Alan Macdonald:
    • I have removed the old Appendix B, Software, which documented Alan Bromborsky’s Python module GAlgebra. The documentation there became out of date as the module improved. It is now in the file GAlgebraPrimer.pdf.
    • The current versions of GAlgebraPrimer.pdf and cm3.ipynb are available at the book’s website and are bundled with the GAlgebra distribution.
  • GAlgebraPrimer.pdf (included in GAlgebra):
    • I made several "get started" notebook files, one for each geometric algebra in
      Algebras.py (See Section 2.2). For example, g3.ipynb imports SymPy and GAlgebra and sets up the geometric algebra g3.
    • Algebras.py. This fi le is distributed with GAlgebra. It contains code to create many different geometric algebras, including g3 and all others used in this document, as well as others not covered here: homogeneous, spacetime, and conformal algebras.
  • GEOMETRIC ALGEBRA SOFTWARE on Geometric Algebra Explorer

GAlgebra is an implementation of a geometric algebra module in python that utilizes the sympy symbolic algebra library. The python module GA has been developed for coordinate free calculations using the operations (geometric, outer, and inner products etc.) of geometric algebra. The operations can be defined using a completely arbitrary metric defined by the inner products of a set of arbitrary vectors or the metric can be restricted to enforce orthogonality and signature constraints on the set of vectors. In addition the module includes the geometric, outer (curl) and inner (div) derivatives and the ability to define a curvilinear coordinate system. The module requires the numpy and the sympy modules.

My original plan for 0.4.5

This issue is a placeholder for my original plan for 0.4.5, which will be postponed to later versions, but useful as a reference for forming a roadmap.

Moved from #17 (comment):

I think I'll be working on the following features in 0.4.5:

  1. Performance: GAlgebra is extremely slow for certain coordinates and metrics, primarily caused by eagerness in the calculus stuff and simplification, so the main idea is laziness, so higher dimensions can be supported
  2. Better support for FGA and CGA: it's already partially supported but I need to extensively verify them and some complications are expected
  3. SymPy 1.4 support: I need to reimplement collect in SymPy for non-commutative symbols, that's quite some work, see #31
  4. Doc improvements: I want to write a true tutorial, weaving the examples together; also the docstring in Python code are mostly ill formated;
  5. Examples fixing: examples in doc/python are not verified; some of them have serious correctness issues yet to be fixed.

Lt.matrix() does not produce desired answer in sympy1.0 (brombo/galgebra#9)

@chaowenGUO commented on Mar 14, 2016

example:
import ga,sympy
base=ga.Ga('e0 e1',g=[1,1],coords=sympy.symbols('x,y',real=True))
M=[[1,2],[3,4]]
A=base.lt(M)
print A
print A.matrix()

and the ouput is:
Lt(e0) = e0 + 2_e1
Lt(e1) = 3_e0 + 4*e1
Matrix([
[3, 4],
[1, 2]])

According to the definition in page 62 of galgebra.pdf
Lt.matrix()
Returns the matrix representation (sympy Matrix) of the linear transformation, L defined by L (e i ) = L ij e j where L ij is the matrix representation.

the answer of A.matrix() should be
Matrix([
[1, 2],
[3, 4]])
However, the answer is correct in sympy0.7.6.1

@brombo commented on Mar 17, 2016

Fixed Lt Matrix function problem and pushed to github -

import ga,sympy
coords=sympy.symbols('x,y,z',real=True)
base=ga.Ga('e0 e1 e2',g=[1,1,1],coords=coords)
M=[[1,2,3],[4,5,6],[7,8,9]]
A=base.lt(M)
print A
print A.lt_dict
print A.matrix()
v = base.mv('v','vector')
print v
print A(v)

Lt(e0) = e0 + 2_e1 + 3_e2
Lt(e1) = 4_e0 + 5_e1 + 6_e2
Lt(e2) = 7_e0 + 8_e1 + 9_e2
{e2: 7_e0 + 8_e1 + 9_e2, e1: 4_e0 + 5_e1 + 6_e2, e0: e0 + 2_e1 + 3_e2}
Matrix([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
v__x_e0 + v__y_e1 + v__z_e2
(v__x + 4_v__y + 7_v__z)_e0 + (2_v__x + 5_v__y + 8_v__z)_e1 + (3_v__x +
6_v__y + 9_v__z)_e2


From http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/9

TypeError: unicode argument expected, got 'str'

As reported by @FreddyBaudine here and discussed here, it seems that the usages of StringIO should be replaced by BytesIO.

The work needs to be done:

  • Reproduce by tests: possibly a test_py2_compat.py since most tests are written in Python 3 flavor
  • Identify the root cause and best practice
  • Fix it and pass tests

grade(A), or A.grade() is not working (brombo/galgebra#1)

@rbeaster commented on Jan 30, 2016

I am trying to get the grade of blade A as

A.grade()

or

grade(A)

but neither is working. They both return zero. I think this used to work, but then I upgraded the GAlgebra module to get the >> commutator and << anticommutator. I did not try to use grade() in a long time. Does anyone else have this problem with grade(A)==0 ?

@brombo commented on Jan 30, 2016

Both A.grade(r=0) and grade(A,r=0) are grade projection operators. Both
A.grade(r) and grade(A,r) returns the r^{th} grade of the multivector
A. If you want to determine the whether a mulitvector is a pure grade
and what that grade is use the multivector member data A.i_grade (this
is not a function) If A is not a pure grade multivector A.i_grade is
"None" otherwise it is the grade of the multivector. Give me a day or
two and I will add a member function called pure_grade() (usage
A.pure_grade()) so you do not have to use member data (I will make the
interface consistent).

@rbeaster commented on Jan 31, 2016

Thanks for the quick response :)

As you say, A.grade(r)=grade(A,r) returns the grade r part of A. Yet, A.grade() with no grade number given did not return any error and just gives the grade 0 part A.grade(0)=grade(A,0). It seems to replace null with zero, like A.grade(null)=grade(A,null)=A.grade(0)=grade(A,0). I was expecting the function signature "A.grade()" to mean the grade number, and the signature "A.grade(r)" to be the grade r part. In other programming languages, as I understand, functions with different parameter count or types (signature) are different functions. So, I was thinking it would often be possible to define A.grade()=grade(A) to return the grade number, and A.grade(r)=grade(A,r) to return the grade-r part. The member functions of A always implicitly take A as the first param, I guess, and then differ by names and the other params.

Anyhow, I don't understand python well, and I'll like A.pure_grade() if that is how it should be done. :)

I'm using GAlgebra a lot to study some stuff, so I really appreciate this software. It works well for what I am playing around with. If python could run on multiple cores / threads, it might run faster. As I study some stuff, I'm writing a research paper/monograph that seems interesting. I will eventually post it on vixra.org. I cite you and your GAlgebra module with a bibtex I made, and give a url to this github site. I plan to have a large section of the monograph give GAlgebra code listings and some example computations that I can figure out clearly without taking too long.

@rbeaster commented on Jan 31, 2016

I was also thinking... a multivector A is a sum of k-blades that can be of different grades k. The highest grade term (blade) of the multivector is grade r>=k (for all terms) and r is what I'd call the grade of the multivector. If the multivector A is pure grade r as an r-vector or an r-blade, then the grade of A is simply r. But if A is not pure grade, not an r-vector or r-blade, then the highest grade r in A can be returned as the negative -r to indicate that r is the impure highest grade in A. The negative grade is like a flag that says the multivector A is not pure grade, but +r is the largest grade in A.

This is a quick, rough idea. There could be issues I have not thought of. This is probably discussed in some paper or book because this sounds like something I came across before somewhere.

@brombo commented on Jan 31, 2016

When the member function grade(r=0) of multivector is defined r=0
defines the default value of r. Thus A.grade() returns the scalar part
of the multivector A. Actually A.grade() returns a scalar multivector
(as opposed to a sympy scalar which is not a multivector) equal to the
scalar part of A.

@brombo commented on Feb 3, 2016

New function "pure_grade(self)" added to git-hub distribution. If A is
pure grade multivector A.pure_grade() returns the grade value of the
multivector. If A is not pure grade A.pure_grade() returns the negative
of the grade value of the highest non-zero grade of the multivector.

@rbeaster commented on Feb 16, 2016

Thanks for the pure_grade function. I used it for something I was testing and got it to work good.
Using your GAlgebra module again, I studied and tested another geometric algebra and wrote a paper on it. The paper cites your software.
The paper includes code listings of how I used the GAlgebra module in a simple way to test the algebra. The paper is a first draft v1 and has some mistakes, but it is not that bad and is here:
http://vixra.org/abs/1602.0114
Thanks again.


Restored from http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/1

impossible to use Lt.matrix() when using a list of vectors in ga.Ga.lt() (brombo/galgebra#10)

@chaowenGUO commented on Mar 18, 2016

import ga,sympy
base=ga.Ga('a b',g=[1,1],coords=sympy.symbols('x,y',real=True))
a,b=base.mv()
A=base.lt([a+b,a-b])
print A
print A.matrix()

output is:
Lt(a) = a + b
Lt(b) = a - b
Traceback (most recent call last):
File "test.py", line 6, in
print A.matrix()
File "/home/ken/galgebra-master/galgebra/lt.py", line 476, in matrix
self.mat = Dictionary_to_Matrix(self.lt_dict, self.Ga) * self.Ga.g
File "/home/ken/galgebra-master/galgebra/lt.py", line 102, in Dictionary_to_Matrix
(coefs,bases) = metric.linear_expand(dict_rep[e_row])
File "/home/ken/galgebra-master/galgebra/metric.py", line 62, in linear_expand
if expr.is_commutative:
AttributeError: 'Mv' object has no attribute 'is_commutative'

that means it construct linear transformation correctly, but can not convert to sympy matrix


From http://webcache.googleusercontent.com/search?q=cache:https://github.com/brombo/galgebra/issues/10

ValueError: Attempted relative import in non-package

Hi everybody,

I tried using galgebra in pygae but the following code, viz.,

from sympy import symbols, sin, cos, pi
from ga import Ga
from printer import Forma,
Format(Fmode = True, Dmode = True)
coords = (r, th, phi) = symbols('r, theta, phi', real =  True)
sp3d = Ga('e_r e_th e_ph',g=[1, r**2, r**2*sin(th)**2], coords = coords, norm = True) 

lead to the following error

ValueError
Traceback (most recent call last)
<ipython-input-1-aa02a2b2e6ee> in <module>()
         1 from sympy import symbols, sin, cos, pi
----> 2 from ga import Ga
         3 from printer import Format
         4 Format(Fmode = True, Dmode = True)
         5 
C:\Documents and Settings\freddy baudine\Desktop\CliffordAlgebraPython\galgebra-master\galgebra\ga.py in <module>()
        10 #from sympy.core.compatibility import combinations
        11 from itertools import combinations
---> 12 from . import printer
        13 from . import metric
        14 from . import mv

ValueError: Attempted relative import in non-package

This piece of code did not give any error in the past
Many thanks in advance for any help.
Kind regards,
Freddy Baudine

class MV is now broken

Due to my commit Remove circular dependencies , module mv no longer depends on module ga, but currently MV still lives in mv and calls ga.

So any examples using class MV, particularly the ones in examples/Old Format won't work and that includes some references to class MV in the new README. (My mistake......)

I have no intention to reintroduce circular dependencies or to drop support for class MV, so here's the work needed to be done:

  • Create a new module that depends on ga and mv to put class MV and possibly the widely used com(), could name it legacy or deprecated (related to a179957)
  • Fix any references to class MV in README or doc
  • Fix examples using class MV

Extremely slow Ga initialization in derivatives_in_elliptic_cylindrical_coordinates()

Extremely slow Ga initialization in derivatives_in_elliptic_cylindrical_coordinates()

a = symbols('a', real=True)
    coords = (u,v,z) = symbols('u v z', real=True)
    (elip3d,er,eth,ephi) = Ga.build('e_u e_v e_z',X=[a*cosh(u)*cos(v),a*sinh(u)*sin(v),z],coords=coords,norm=True)
    grad = elip3d.grad

The code above takes 500~600 seconds for the Ga.build call.

After some profiling/debugging I found it spent most of the time in simplify and trigsimp(both take ~50%) and every call to them cost ~16s of 100% CPU and there's approximately 27 calls to them, 27 * 16s = 513s, it explains the total time.

So which step is calling simplify and trigsimp? It turns out to be metric.Simp.apply() in build_reciprocal_basis():

        # Replace reciprocal basis vectors with expansion in terms of
        # basis vectors in derivatives of basis vectors

        if self.connect_flg:
            for x_i in self.n_range:
                for jb in self.n_range:
                    if not self.is_ortho:
                        self.de[x_i][jb] = metric.Simp.apply(self.de[x_i][jb].subs(self.r_basis_dict) / self.e_sq)
                    else:
                        self.de[x_i][jb] = metric.Simp.apply(self.de[x_i][jb].subs(self.r_basis_dict))

and derivatives_of_basis()

        # Christoffel symbols of the first kind, \Gamma_{ijk}

        for i in n_range:
            de_row = []
            for j in n_range:
                Gamma = []
                for k in n_range:
                    gamma = half * (dg[j][k][i] + dg[i][k][j] - dg[i][j][k])
                    Gamma.append(Simp.apply(gamma))
                de_row.append(sum([gamma * base for (gamma, base) in zip(Gamma, self.r_symbols)]))
            de.append(de_row)

Mostly the former.

Replace dangerous and unexpected behaviors in printer.xpdf() with safer and more natural equivalents

First discussed in #19 (comment) .

  • Not to stop and ask for input between .tex generation and .pdf generation
  • Remove eval() usage
  • Use safe and cross-platform methods to remove files generated during pdf generation
  • Provide an option for generating only .tex
  • Provide an option for keeping .tex after .pdf generation
  • Provide an option object for specifying options for xpdf() so ther won't be too many parameters
  • Remove unsafe system() usage
  • Support other LaTeX to PDF generator such as https://tectonic-typesetting.github.io/en-US/
  • Dont' hang if pdflatex stops and asks for input

Mv.inv is very slow

Hi,

Here's another slow snippet (291s) :

from galgebra.ga import Ga
from sympy import Symbol

GA, e_0, e_1, e_2, e_3 = Ga.build("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1')

e_0_inv = e_0.inv()
p = GA.mv((1, Symbol('p1'), Symbol('p2'), Symbol('p3')), 'vector')
q = GA.mv((0, Symbol('q1'), Symbol('q2'), Symbol('q3')), 'vector')
r = GA.mv((0, Symbol('r1'), Symbol('r2'), Symbol('r3')), 'vector')
A = q ^ r
X = (p ^ A)                                 # A plane
d = (e_0_inv < (e_0 ^ X)) / (e_0_inv < X)   # Support vector from plane

Very slow :
d_inv = d.inv()

d doesn't seem to complex :
(p1*q2**2*r3**2 - 2*p1*q2*q3*r2*r3 + p1*q3**2*r2**2 - p2*q1*q2*r3**2 + p2*q1*q3*r2*r3 + p2*q2*q3*r1*r3 - p2*q3**2*r1*r2 + p3*q1*q2*r2*r3 - p3*q1*q3*r2**2 - p3*q2**2*r1*r3 + p3*q2*q3*r1*r2)*e_1/(q1**2*r2**2 + q1**2*r3**2 - 2*q1*q2*r1*r2 - 2*q1*q3*r1*r3 + q2**2*r1**2 + q2**2*r3**2 - 2*q2*q3*r2*r3 + q3**2*r1**2 + q3**2*r2**2) + (-p1*q1*q2*r3**2 + p1*q1*q3*r2*r3 + p1*q2*q3*r1*r3 - p1*q3**2*r1*r2 + p2*q1**2*r3**2 - 2*p2*q1*q3*r1*r3 + p2*q3**2*r1**2 - p3*q1**2*r2*r3 + p3*q1*q2*r1*r3 + p3*q1*q3*r1*r2 - p3*q2*q3*r1**2)*e_2/(q1**2*r2**2 + q1**2*r3**2 - 2*q1*q2*r1*r2 - 2*q1*q3*r1*r3 + q2**2*r1**2 + q2**2*r3**2 - 2*q2*q3*r2*r3 + q3**2*r1**2 + q3**2*r2**2) + (p1*q1*q2*r2*r3 - p1*q1*q3*r2**2 - p1*q2**2*r1*r3 + p1*q2*q3*r1*r2 - p2*q1**2*r2*r3 + p2*q1*q2*r1*r3 + p2*q1*q3*r1*r2 - p2*q2*q3*r1**2 + p3*q1**2*r2**2 - 2*p3*q1*q2*r1*r2 + p3*q2**2*r1**2)*e_3/(q1**2*r2**2 + q1**2*r3**2 - 2*q1*q2*r1*r2 - 2*q1*q3*r1*r3 + q2**2*r1**2 + q2**2*r3**2 - 2*q2*q3*r2*r3 + q3**2*r1**2 + q3**2*r2**2)

d_inv will be used later for computing the dual of X. I can provide more information if that matters.

Regards

Investigate whether the left and right contraction overloads are safe

galgebra uses a < b to mean left_contract(a, b). I'm worried that this doesn't work properly:

Quoting the python docs about the comparison ops:

There are no swapped-argument versions of these methods (to be used when the left argument does not support the operation but the right argument does); rather, lt()` and gt() are each other’s reflection

If the operands are of different types, and right operand’s type is a direct or indirect subclass of the left operand’s type, the reflected method of the right operand has priority, otherwise the left operand’s method has priority.

What this means is that obj < mv and mv > obj are indistinguishable if obj does not take part in the comparison.

From dorst, the rule for converting a left to right contraction is:

image

So by identity, left_contract(obj, mv) == right_contract(mv.rev(), obj.rev()).rev()

However, the python rules allow the rewrite left_contract(obj, mv) == right_contract(mv, obj).

Can we guarantee this is always true?

Mv.dual is very slow

Hi,

I was trying this version of galgebra and I found Mv.dual method is very slow for low dimension geometric algebras. I hoped the issue was fixed there (This issue is reproducible with brombo version).

A short snippet :

from galgebra.ga import Ga

GA = Ga('e*1|2|3')
a = GA.mv('a', 'vector')
b = GA.mv('b', 'vector')
c = GA.mv('c', 'vector')

def cross(x, y):
    return (x ^ y).dual()

I only profile :
xx = cross(a, cross(b, c))

cProfile reports :

         16807237 function calls (15373382 primitive calls) in 5.316 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        2    0.000    0.000    5.316    2.658 /home/sylvain/Documents/pygae/tests/test_dual.py:41(cross)
63300/1661    0.047    0.000    5.200    0.003 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/cache.py:91(wrapper)
        2    0.000    0.000    5.106    2.553 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:1050(dual)
        2    0.000    0.000    5.039    2.520 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:506(__mul__)
5864/5592    0.037    0.000    4.517    0.001 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/operations.py:28(__new__)
1789/1582    0.001    0.000    3.483    0.002 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/decorators.py:84(__sympifyit_wrapper)
1602/1579    0.001    0.000    3.481    0.002 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/decorators.py:122(binary_op_wrapper)
       62    0.003    0.000    3.371    0.054 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:103(nc_subs)
       22    0.000    0.000    3.136    0.143 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:1137(base_to_blade_rep)
      927    0.001    0.000    3.058    0.003 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/expr.py:117(__add__)
     1045    0.130    0.000    3.054    0.003 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/add.py:78(flatten)
       10    0.000    0.000    2.956    0.296 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:383(blade_rep)
     5787    0.053    0.000    2.443    0.000 {method 'sort' of 'list' objects}
507395/196716    0.766    0.000    2.390    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/basic.py:170(compare)
     1046    0.000    0.000    2.091    0.002 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/add.py:19(_addsort)
       82    0.000    0.000    1.722    0.021 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/function.py:1982(expand)
       33    0.001    0.000    1.721    0.052 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/expr.py:3071(expand)
246474/297    0.329    0.000    1.720    0.006 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/expr.py:3041(_expand_hint)
        6    0.000    0.000    1.464    0.244 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:287(__init__)
        6    0.000    0.000    1.464    0.244 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:124(characterise_Mv)
     8886    0.025    0.000    1.146    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:854(_eval_expand_mul)
4744/4487    0.126    0.000    1.083    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:97(flatten)
   262792    0.194    0.000    1.050    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/symbol.py:250(_hashable_content)
   262792    0.363    0.000    0.633    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/symbol.py:254(assumptions0)
    77094    0.037    0.000    0.621    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/operations.py:68(_new_rawargs)
    84366    0.154    0.000    0.600    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/operations.py:54(_from_args)
        4    0.000    0.000    0.502    0.125 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:66(update_and_substitute)
604605/508233    0.121    0.000    0.444    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/assumptions.py:242(getit)
  662/646    0.001    0.000    0.421    0.001 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/expr.py:137(__mul__)
        2    0.000    0.000    0.418    0.209 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:1170(mul)
    72928    0.117    0.000    0.382    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/logic.py:112(fuzzy_and)
    71594    0.058    0.000    0.374    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:768(as_coeff_Mul)
  211/133    0.000    0.000    0.365    0.003 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:835(_expandsums)
        8    0.001    0.000    0.360    0.045 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/metric.py:42(linear_expand)
     4737    0.002    0.000    0.354    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:32(_mulsort)
17861/654    0.051    0.000    0.342    0.001 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/assumptions.py:254(_ask)
     5796    0.104    0.000    0.303    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/basic.py:1695(_exec_constructor_postprocessors)
       39    0.001    0.000    0.273    0.007 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:850(<listcomp>)
   648176    0.188    0.000    0.269    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/core.py:73(__cmp__)
  2338243    0.261    0.000    0.261    0.000 {built-in method builtins.isinstance}
  1732062    0.251    0.000    0.251    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/symbol.py:256(<genexpr>)
     8886    0.038    0.000    0.250    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/simplify/radsimp.py:930(fraction)
1018718/360300    0.130    0.000    0.238    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/basic.py:121(__hash__)
       28    0.000    0.000    0.231    0.008 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:1145(blade_to_base_rep)
        4    0.000    0.000    0.228    0.057 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:375(base_rep)
   324088    0.081    0.000    0.224    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/core.py:101(__gt__)
     9486    0.073    0.000    0.212    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:380(_gather)
        2    0.000    0.000    0.210    0.105 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:769(__xor__)
   262825    0.205    0.000    0.205    0.000 {built-in method builtins.sorted}
 1052/902    0.001    0.000    0.200    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/mul.py:1160(_eval_is_integer)
   324088    0.073    0.000    0.199    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/core.py:96(__lt__)
   647160    0.105    0.000    0.179    0.000 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/sympy/core/operations.py:64(<genexpr>)
        4    0.000    0.000    0.167    0.042 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/mv.py:922(is_scalar)
        4    0.000    0.000    0.167    0.042 /home/sylvain/Documents/pygae/venv/lib/python3.6/site-packages/galgebra/ga.py:1333(grades)
    15832    0.052    0.000    0.159    0.000 /usr/lib/python3.6/random.py:263(shuffle)

Regards

Drop Python 2.7

Creating a tracking issue for this, not advocating we do it immediately

Since Python 2.7 is EOL on 2020-01-01, we could consider dropping support for python 2.7 on the same date, in line with https://python3statement.org/ (which notably includes SymPy).

Realistically, that would probably make 0.4.5 the last release to support python 2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.