G. Utama: Overview of Geometric Algebra SymPy module GA for Phython


Overview of Geometric Algebra SymPy module GA for Phython
by Ginanjar Utama

Several software packages for numerical geometric algebra calculations are available from the Doran-Lasenby group (GARG, University of Cambridge, UK) and the Dorst group (University of Amsterdam, The Netherlands). Symbolic packages for Clifford algebra using orthogonal bases such as e_{i}e_{j}+e_{j}e_{i} = 2\eta_{ij}, where \eta_{ij} is a numeric array are available in Maple and Mathematica. The symbolic algebra module, GA, developed for python does not depend on an orthogonal basis representation, but rather is generated from a set of n arbitrary symbolic vectors, a_{1},a_{2}, … ,a_{n} and a symbolic metric tensor g_{ij} = a_{i}\cdot a_{j}.

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

To use the GA module we need Python 2.5 or newer and the Python Libraries SymPy and NumPy. SymPy is a symbolic computer algebra library. It also has linear algebra capabilities and pretty print or latex printing capability. GA is just one of sympy modules.

How to install the Python module GA

The not so easy way
download python from http://www.python.org/download/
download sympy from http://code.google.com/p/sympy/wiki/DownloadInstallation?tm=2
download numpy from http://new.scipy.org/download.html
and follow the instructions depending on your operating system

The easy way
If we are using linux and the repositories are right then we can simply type in the console as root:
For debian: apt-get install python python-sympy python-numpy python-numpy-devel
For opensuse: zypper in python python-sympy python-numpy python-numpy-devel

To use latex output the systems must have texlive installed!

How to use the Python module GA

Invoke python shell, by just typing python in the command shell.

# to try sympy

>>> from sympy import *
>>> x = Symbol(‘x’)
>>> limit(sin(pi*x)/x,x,0)
pi
>>> integrate(x+sinh(x),x)
cosh(x) + x**2/2
>>> diff(_ , x)
x + sinh(x)
>>> m = symbols(‘m’)
>>> M = Matrix([[1,m],[3,4]])
>>> M.inv()
[1 + 3*m/(4 – 3*m), -m/(4 – 3*m)]
[     -3/(4 – 3*m),  1/(4 – 3*m)]

# to try the GA module

>>> from sympy.galgebra.GA import *
>>> set_main(sys.modules[__name__])
>>> make_symbols(‘x y z’)
[x, y, z]
>>> x + y
x + y

#Example of basic geometric algebra operations of geometric, outer, and inner products.
#It doesn’t work on the sage and ipython environments, really weird, I don’t know why.

>>> MV.setup(‘a b c d e’)
‘Setup of a b c d e complete!’
>>> a.basis
[[], [[0], [1], [2], [3], [4]], [[0, 1], [0, 2], [1, 2], [0, 3], [1, 3], [2, 3], [0, 4], [1, 4], [2, 4], [3, 4]], [[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3], [0, 1, 4], [0, 2, 4], [1, 2, 4], [0, 3, 4], [1, 3, 4], [2, 3, 4]], [[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4]], [[0, 1, 2, 3, 4]]]
>>> a.basislabel
[‘1’, [‘a’, ‘b’, ‘c’, ‘d’, ‘e’], [‘ab’, ‘ac’, ‘bc’, ‘ad’, ‘bd’, ‘cd’, ‘ae’, ‘be’, ‘ce’, ‘de’], [‘abc’, ‘abd’, ‘acd’, ‘bcd’, ‘abe’, ‘ace’, ‘bce’, ‘ade’, ‘bde’, ‘cde’], [‘abcd’, ‘abce’, ‘abde’, ‘acde’, ‘bcde’], [‘abcde’]]
>>> print ‘e|(a^b) =’,e|(a^b)
e|(a^b) = -(b.e)*a+(a.e)*b
>>> print a|b^c
-(a.c)*b+(a.b)*c
>>> print a|b^c^d
(a.d)*b^c-(a.c)*b^d+(a.b)*c^d
>>> print a|b^c^d^e
-(a.e)*b^c^d+(a.d)*b^c^e-(a.c)*b^d^e+(a.b)*c^d^e
>>> MV.setup(‘a b c’)
‘Setup of a b c complete!’
>>> a.basislabel
[‘1’, [‘a’, ‘b’, ‘c’], [‘ab’, ‘ac’, ‘bc’], [‘abc’]]
>>> a.basis
[[], [[0], [1], [2]], [[0, 1], [0, 2], [1, 2]], [[0, 1, 2]]]
>>> MV.setup(‘a b c d e’)
‘Setup of a b c d e complete!’
>>> print a|(b^c) + b|(c^a) + c|(a^b)  # Jacobi identity/ Cyclic reduction formulas are not working, should be zero
(a**2)*(a.b)*(b.c)-(a.c)*(a.b)**2+(-(a.b)*(b.c)-(a.b)*((a.b)*(c**2)-(a.c)*(b.c)))*a+((a**2)*((a.b)*(c**2)-(a.c)*(b.c))+(a.b)*(a.c))*b+((a.b)*(c**2)-(a.c)*(b.c))*a^b
>>> print ‘e|(a^b) =’,e|(a^b)
e|(a^b) = -(b.e)*a+(a.e)*b
>>> print ‘e|(a^b^c) =’,e|(a^b^c)
e|(a^b^c) = (c.e)*a^b-(b.e)*a^c+(a.e)*b^c
>>> print ‘a*(b^c)-b*(a^c)+c*(a^b) =’,a*(b^c)-b*(a^c)+c*(a^b)
a*(b^c)-b*(a^c)+c*(a^b) = 3*a^b^c
>>> print ‘e|(a^b^c^d) =’,e|(a^b^c^d)
e|(a^b^c^d) = -(d.e)*a^b^c+(c.e)*a^b^d-(b.e)*a^c^d+(a.e)*b^c^d
>>> print -d*(a^b^c)+c*(a^b^d)-b*(a^c^d)+a*(b^c^d)
4*a^b^c^d
>>> print (a^b)|(c^d)  #Basis blade reduction formula
(a.d)*(b.c)-(a.c)*(b.d)

>>>MV.setup(‘a b’)
>>>print a*b – b*a #Expecting a wedge product
-2*(a.b) + 2*ab
#But it can simplify to dot products
>>>print a*b + b*a
2*(a.b)

Other examples can be seen in
http://docs.sympy.org/modules/galgebra/GA/GAsympy.html
and the paper behind the Python GA module can be found in
http://www.montgomerycollege.edu/Departments/planet/planet/Numerical_Relativity/GA-SIG/symbolicGA.pdf
Introduction to Geometric Algebra from the module’s creator Alan Bromborsky is here
http://www.montgomerycollege.edu/Departments/planet/planet/Numerical_Relativity/introGA7-14-2010.pdf
The module is also used and explained in the upcoming book of Prof Alan Macdonald
http://faculty.luther.edu/~macdonal/laga/index.html

 

Source: Email by Ginanjar Utama, 27 October 2010, ginanjar.utama_at_gmail.com

Advertisements

5 Comments

Filed under Software

5 responses to “G. Utama: Overview of Geometric Algebra SymPy module GA for Phython

  1. The formulas seemed to be working in your Jacobi Identity example, but since you didn’t define a metric, terms like a**2 and a.b appeared.
    > metric = ‘1 0 0,0 1 0,0 0 1’
    > MV.setup(‘e1 e2 e3’,metric,True)
    gives:
    > print e1|(e2^e3) + e2|(e3^e1) + e3|(e1^e2)
    0

    > print (e2-e3)*(e2-e3)
    2
    > diff((e1+2*e2)*(e2-a*e3), a)
    -e1**e3 – 2*e2**e3

    However, there are some missing features of GA:
    print (e1+2*e2)/(e2-e3)
    – throws an error.
    print (e1+2*e2)*(e2-e3)/((e2-e3)*(e2-e3))
    – throws an error.

  2. Maya Incaand

    Strange, the blog won’t allow me to use the “tick mark” but reformats it as the curly apostrophe, you know what I mean anyway.

    • Dear Maya,

      I am sorry I don’t know if there are any wordpress blog settings that could enable you to use certain characters. Basically I think everything is displayed in some html code.

      With kind regards,
      Eckhard

      • Maya Incaand

        No problem, if you look at the eg a.basislabel part of the code above, you can see the system response contains elements surrounded by “tick marks”.

        If you use these instead of the “curly quotes” then it will work in Sage (at least on my setup).

  3. Maya Incaand

    If you use the programmers ‘ instead of the ‘, it works fine in Sage (I have Sage 4.2.1 running in Virtual Box on Windows).

    The other errors are still there (a bit different).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s