geometric algebra (basics)

142 days ago by cjfsyntropy

Load sympy's GA Module
from sympy.galgebra.GA import * 
       
The documentation at http://docs.sympy.org/modules/galgebra/GA/GAsympy.html says you need to do this to get access to GA variables for operations.
set_main(sys.modules[__name__]);dir(sympy.galgebra.GA) 
       
['HALF', 'LaTeX_lst', 'MAIN_PROGRAM', 'MV', 'NUMPAT', 'ONE', 'TWO',
'TrigSimp', 'ZERO', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', 'abs_type', 'add_type', 'build_base',
'collect', 'collect_common_factors', 'comb', 'copy', 'cp', 'diagpq',
'dualsort', 'expand', 'function_lst', 'is_quasi_unit_numpy_array',
'isint', 'israt', 'magnitude', 'make_null_array', 'make_scalars',
'make_symbols', 'mul_type', 'normalize', 'numeric', 'numpy', 'os',
'plist', 'pow_type', 'print_lst', 'reciprocal_frame', 'reduce_base',
'regrep', 'set_main', 'set_names', 'sqrfree', 'sqrt', 'string',
'sub_base', 'sym_type', 'symbol', 'sympy', 'sys', 'test_int_flgs',
'types', 'unabs', 'vector_fct']
MV.setup('a b c d e') 
       
'Setup of a b c d e complete!'
type(a) 
       
<class 'sympy.galgebra.GA.MV'>
MV.set_str_format(1) 
       
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
e=a*(b^c)-b*(a^c)+c*(a^b) 
       
       
<sympy.galgebra.GA.MV object at 0x5cdea90>
print e 
       
(3)a^b^c
dir(e) 
       
['I', 'Name', '__add__', '__add_ab__', '__call__', '__class__',
'__delattr__', '__dict__', '__div__', '__div_ab__', '__doc__',
'__eq__', '__format__', '__getattribute__', '__hash__', '__init__',
'__module__', '__mul__', '__neg__', '__new__', '__or__', '__pos__',
'__pow__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__',
'__rmul__', '__ror__', '__rsub__', '__rxor__', '__setattr__',
'__sizeof__', '__str__', '__sub__', '__sub_ab__',
'__subclasshook__', '__weakref__', '__xor__', 'add_in_place',
'addition', 'basis', 'basis_map', 'basislabel', 'basislabel_lst',
'basisroot', 'blade_table', 'bladeflg', 'bladelabel', 'bladeprint',
'btable', 'bvec', 'cancel', 'collect', 'combine_common_factors',
'compact', 'construct_index', 'contract', 'convert',
'convert_from_blades', 'convert_to_blades', 'coord', 'coords',
'copy', 'cse', 'curvilinear_flg', 'ddt', 'debug', 'define_basis',
'define_metric', 'define_reciprocal_frame', 'diff', 'div', 'even',
'expand', 'flatten', 'g', 'gabasis', 'geometric_product', 'grad',
'grad_ext', 'grad_int', 'ibtable', 'index', 'inner_product',
'inverse_blade_table', 'is_pure', 'is_setup', 'mag2', 'max_grade',
'metric', 'metric_str', 'mtable', 'multiplication_table', 'mv', 'n',
'n1', 'n1rg', 'name', 'named', 'nbasis', 'npow', 'nrg', 'odd',
'outer_product', 'pad_zeros', 'print_bases', 'print_blades',
'printmv', 'printnm', 'project', 'puregrade', 'rebase',
'reduce_basis', 'reduce_basis_loop', 'rev', 'scalar_fct',
'scalar_mul', 'scalar_mul_inplace', 'scalar_to_symbol', 'set_coef',
'set_coords', 'set_name', 'set_str_format', 'set_value', 'setup',
'simplify', 'sqrfree', 'str_mode', 'str_rep', 'sub_in_place',
'sub_mv', 'sub_scalar', 'subs', 'substitute_base', 'subtraction',
'tables_flg', 'trigsimp', 'trim', 'vbasis', 'vdiff', 'vector_fct',
'vsyms', 'wedge', 'x']
x=a+b 
       
print(x) 
       
a
+b
The "|" is used for inner product. In the output, it seems to be displayed as ((a.b))1 perhaps to show that it is a 1-vector.
y=a|b 
       
print y 
       
((a.b))1
The wedge (or outer) product producing a bivector.
w=a^b 
       
print w 
       
a^b
The geometric product of a and b works as expected!
v=a*b 
       
print v 
       
((a.b))1
+a^b
c=(a+b)*(a+b) 
       
print c 
       
((a**2) + (b**2) + 2*(a.b))1
print c**2 
       
(2*(a**2) + 2*(b**2) + 4*(a.b))1