#!/usr/bin/python #Dirac.py import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex import sys if __name__ == '__main__': metric = '1 0 0 0,'+\ '0 -1 0 0,'+\ '0 0 -1 0,'+\ '0 0 0 -1' vars = GA.make_symbols('t x y z') GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars) parms = GA.make_symbols('m e') tex.Format() I = GA.MV(GA.ONE,'pseudo') nvars = len(vars) psi = GA.MV('psi','spinor',fct=True) psi.convert_to_blades() A = GA.MV('A','vector',fct=True) sig_x = gamma_x*gamma_t sig_y = gamma_y*gamma_t sig_z = gamma_z*gamma_t print '$A$ is 4-vector potential' print A print r'$\bm{\psi}$ is 8-component real spinor (even multi-vector)' print psi
metric = '1 0 0,' \ '0 1 0,' \ '0 0 1' gamma_x, gamma_y, gamma_z = GA.MV.setup('gamma_x gamma_y gamma_z', metric, True) tex.Format() coords = r, theta, phi = sympy.symbols('r theta phi') x = r * (sympy.cos(theta) * gamma_z + sympy.sin(theta) * (sympy.cos(phi) * gamma_x + sympy.sin(phi) * gamma_y)) x.set_name('x') GA.MV.rebase(x, coords, 'e', True) psi = GA.MV('psi', 'scalar', fct=True) dpsi = psi.grad() print 'Gradient of Scalar Function $\\psi$' print '\\nabla\\psi =', dpsi A = GA.MV('A', 'vector', fct=True) print 'Div and Curl of Vector Function $A$' print A gradA = A.grad() I = GA.MV(GA.ONE, 'pseudo') divA = A.grad_int() curlA = -I * A.grad_ext() print '\\nabla \\cdot A =', divA
import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex GA.set_main(sys.modules[__name__]) if __name__ == '__main__': tex.Format() GA.make_symbols('xbm alpha_1 delta__nugamma_r') x = alpha_1*xbm/delta__nugamma_r print 'x =',x tex.xdvi()
#EandM.py import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex import sympy,numpy,time if __name__ == '__main__': metric = '1 0 0,'+\ '0 1 0,'+\ '0 0 1' GA.MV.setup('gamma_x gamma_y gamma_z',metric,True) tex.Format() coords = GA.make_symbols('r theta phi') x = r*(sympy.cos(theta)*gamma_z+sympy.sin(theta)*\ (sympy.cos(phi)*gamma_x+sympy.sin(phi)*gamma_y)) x.set_name('x') GA.MV.rebase(x,coords,'e',True) psi = GA.MV('psi','scalar',fct=True) dpsi = psi.grad() print 'Gradient of Scalar Function $\\psi$' print '\\nabla\\psi =',dpsi A = GA.MV('A','vector',fct=True) print 'Div and Curl of Vector Function $A$'
# c.communicate # c.wait() d = sub.Popen(topdf,stdin=PIPE,stdout=PIPE,stderr=STDOUT) d.communicate d.wait() e = sub.Popen(dispdf,stdin=PIPE,stdout=PIPE,stderr=STDOUT) e.communicate else: b = sub.Popen(disdvi,stdin=PIPE,stdout=PIPE,stderr=STDOUT) b.communicate() #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- GA.set_main(sys.modules[__name__]) def generate_output_2(output): """ See sympy's GA module online """ tex.Format() tex.sym_format(1) x = tex.print_LaTeX(output) print x #tex.xdvi(debug=True) #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- #--------------------------------------------------------------------------------- def generate_output_3(output): """ Uses the MathTex summer of code project """
#!/usr/bin/python #Dirac.py import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex import sys GA.set_main(sys.modules[__name__]) if __name__ == '__main__': metric = '1 0 0 0,'+\ '0 -1 0 0,'+\ '0 0 -1 0,'+\ '0 0 0 -1' vars = GA.make_symbols('t x y z') GA.MV.setup('gamma_t gamma_x gamma_y gamma_z', metric, True, vars) parms = GA.make_symbols('m e') tex.Format() I = GA.MV(GA.ONE, 'pseudo') nvars = len(vars) psi = GA.MV('psi', 'spinor', fct=True) psi.convert_to_blades() A = GA.MV('A', 'vector', fct=True) sig_x = gamma_x * gamma_t sig_y = gamma_y * gamma_t sig_z = gamma_z * gamma_t print '$A$ is 4-vector potential' print A
#!/usr/bin/python import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex GA.set_main(sys.modules[__name__]) if __name__ == '__main__': metric = '1 0 0 0,'+\ '0 -1 0 0,'+\ '0 0 -1 0,'+\ '0 0 0 -1' vars = GA.make_symbols('t x y z') GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars) tex.Format() I = GA.MV(1,'pseudo') I.convert_to_blades() print '$I$ Pseudo-Scalar' print 'I =',I B = GA.MV('B','vector',fct=True) E = GA.MV('E','vector',fct=True) B.set_coef(1,0,0) E.set_coef(1,0,0) B *= gamma_t E *= gamma_t B.convert_to_blades() E.convert_to_blades() J = GA.MV('J','vector',fct=True)
#!/usr/bin/python #EandM.py import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex import sympy,numpy,time GA.set_main(sys.modules[__name__]) if __name__ == '__main__': metric = '1 0 0,'+\ '0 1 0,'+\ '0 0 1' GA.MV.setup('gamma_x gamma_y gamma_z',metric,True) tex.Format() coords = GA.make_symbols('r theta phi') x = r*(sympy.cos(theta)*gamma_z+sympy.sin(theta)*\ (sympy.cos(phi)*gamma_x+sympy.sin(phi)*gamma_y)) x.set_name('x') GA.MV.rebase(x,coords,'e',True) psi = GA.MV('psi','scalar',fct=True) dpsi = psi.grad() print 'Gradient of Scalar Function $\\psi$' print '\\nabla\\psi =',dpsi
import sys, sympy if __name__ == '__main__': metric = '1 0 0 0,'+\ '0 -1 0 0,'+\ '0 0 -1 0,'+\ '0 0 0 -1' vars = sympy.symbols('t x y z') gamma_t, gamma_x, gamma_y, gamma_z = GA.MV.setup( 'gamma_t gamma_x gamma_y gamma_z', metric, True, vars) m, e = sympy.symbols('m e') tex.Format() I = GA.MV(GA.ONE, 'pseudo') nvars = len(vars) psi = GA.MV('psi', 'spinor', fct=True) psi.convert_to_blades() A = GA.MV('A', 'vector', fct=True) sig_x = gamma_x * gamma_t sig_y = gamma_y * gamma_t sig_z = gamma_z * gamma_t print '$A$ is 4-vector potential' print A print r'$\bm{\psi}$ is 8-component real spinor (even multi-vector)' print psi dirac_eq = psi.grad() * I * sig_z - e * A * psi - m * psi * gamma_t dirac_eq.simplify() dirac_eq.convert_to_blades() print 'Dirac equation in terms of real geometric algebra/calculus '+\
import sympy import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex if __name__ == '__main__': metric = '1 0 0 0,' \ '0 -1 0 0,' \ '0 0 -1 0,' \ '0 0 0 -1' vars = sympy.symbols('t x y z') gamma_t, gamma_x, gamma_y, gamma_z = GA.MV.setup( 'gamma_t gamma_x gamma_y gamma_z', metric, True, vars) tex.Format() I = GA.MV(1, 'pseudo') I.convert_to_blades() print '$I$ Pseudo-Scalar' print 'I =', I B = GA.MV('B', 'vector', fct=True) E = GA.MV('E', 'vector', fct=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= gamma_t E *= gamma_t B.convert_to_blades() E.convert_to_blades() J = GA.MV('J', 'vector', fct=True) print '$B$ Magnetic Field Bi-Vector' print 'B = Bvec gamma_0 =', B print '$E$ Electric Field Bi-Vector'
#!/usr/local/bin/python # Dirac.py import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex import sys GA.set_main(sys.modules[__name__]) if __name__ == "__main__": metric = "1 0 0 0," + "0 -1 0 0," + "0 0 -1 0," + "0 0 0 -1" vars = GA.make_symbols("t x y z") GA.MV.setup("gamma_t gamma_x gamma_y gamma_z", metric, True, vars) parms = GA.make_symbols("m e") tex.Format() I = GA.MV(GA.ONE, "pseudo") nvars = len(vars) psi = GA.MV("psi", "spinor", fct=True) psi.convert_to_blades() A = GA.MV("A", "vector", fct=True) sig_x = gamma_x * gamma_t sig_y = gamma_y * gamma_t sig_z = gamma_z * gamma_t print "$A$ is 4-vector potential" print A print r"$\bm{\psi}$ is 8-component real spinor (even multi-vector)" print psi dirac_eq = psi.grad() * I * sig_z - e * A * psi - m * psi * gamma_t
import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex if __name__ == '__main__': tex.Format() GA.make_symbols('xbm alpha_1 delta__nugamma_r') x = alpha_1*xbm/delta__nugamma_r print 'x =',x tex.xdvi()
import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex GA.set_main(sys.modules[__name__]) if __name__ == '__main__': tex.Format() GA.make_symbols('xbm alpha_1 delta__nugamma_r') x = alpha_1 * xbm / delta__nugamma_r print 'x =', x tex.xdvi()
#!/usr/bin/python import sys import sympy.galgebra.GA as GA import sympy.galgebra.latex_ex as tex if __name__ == '__main__': metric = '1 0 0 0,'+\ '0 -1 0 0,'+\ '0 0 -1 0,'+\ '0 0 0 -1' vars = GA.make_symbols('t x y z') GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars) tex.Format() I = GA.MV(1,'pseudo') I.convert_to_blades() print '$I$ Pseudo-Scalar' print 'I =',I B = GA.MV('B','vector',fct=True) E = GA.MV('E','vector',fct=True) B.set_coef(1,0,0) E.set_coef(1,0,0) B *= gamma_t E *= gamma_t B.convert_to_blades() E.convert_to_blades() J = GA.MV('J','vector',fct=True) print '$B$ Magnetic Field Bi-Vector' print 'B = Bvec gamma_0 =',B