def Maxwells_Equations_in_Geom_Calculus(): Print_Function() X = symbols("t x y z", real=True) (st4d, g0, g1, g2, g3) = Ga.build("gamma*t|x|y|z", g=[1, -1, -1, -1], coords=X) I = st4d.i B = st4d.mv("B", "vector", f=True) E = st4d.mv("E", "vector", f=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 J = st4d.mv("J", "vector", f=True) F = E + I * B print r"\text{Pseudo Scalar\;\;}I =", I print "\\text{Magnetic Field Bi-Vector\\;\\;} B = \\bm{B\\gamma_{t}} =", B print "\\text{Electric Field Bi-Vector\\;\\;} E = \\bm{E\\gamma_{t}} =", E print "\\text{Electromagnetic Field Bi-Vector\\;\\;} F = E+IB =", F print "%\\text{Four Current Density\\;\\;} J =", J gradF = st4d.grad * F print "#Geom Derivative of Electomagnetic Field Bi-Vector" gradF.Fmt(3, "grad*F") print "#Maxwell Equations" print "grad*F = J" print "#Div $E$ and Curl $H$ Equations" print (gradF.get_grade(1) - J).Fmt(3, "%\\grade{\\nabla F}_{1} -J = 0") print "#Curl $E$ and Div $B$ equations" print (gradF.get_grade(3)).Fmt(3, "%\\grade{\\nabla F}_{3} = 0") return
def basic_multivector_operations_3D(): Print_Function() (g3d,ex,ey,ez) = Ga.build('e*x|y|z') print('g_{ij} =',g3d.g) A = g3d.mv('A','mv') print(A.Fmt(1,'A')) print(A.Fmt(2,'A')) print(A.Fmt(3,'A')) print(A.even().Fmt(1,'%A_{+}')) print(A.odd().Fmt(1,'%A_{-}')) X = g3d.mv('X','vector') Y = g3d.mv('Y','vector') print(X.Fmt(1,'X')) print(Y.Fmt(1,'Y')) print((X*Y).Fmt(2,'X*Y')) print((X^Y).Fmt(2,'X^Y')) print((X|Y).Fmt(2,'X|Y')) return
def Maxwells_Equations_in_Geom_Calculus(): Print_Function() X = symbols('t x y z', real=True) (st4d, g0, g1, g2, g3) = Ga.build('gamma*t|x|y|z', g=[1, -1, -1, -1], coords=X) I = st4d.i B = st4d.mv('B', 'vector', f=True) E = st4d.mv('E', 'vector', f=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 J = st4d.mv('J', 'vector', f=True) F = E + I * B print r'\text{Pseudo Scalar\;\;}I =', I print '\\text{Magnetic Field Bi-Vector\\;\\;} B = \\bm{B\\gamma_{t}} =', B print '\\text{Electric Field Bi-Vector\\;\\;} E = \\bm{E\\gamma_{t}} =', E print '\\text{Electromagnetic Field Bi-Vector\\;\\;} F = E+IB =', F print '%\\text{Four Current Density\\;\\;} J =', J gradF = st4d.grad * F print '#Geom Derivative of Electomagnetic Field Bi-Vector' gradF.Fmt(3, 'grad*F') print '#Maxwell Equations' print 'grad*F = J' print '#Div $E$ and Curl $H$ Equations' print(gradF.get_grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0') print '#Curl $E$ and Div $B$ equations' print(gradF.get_grade(3)).Fmt(3, '%\\grade{\\nabla F}_{3} = 0') return
def Lorentz_Tranformation_in_Geog_Algebra(): Print_Function() (alpha,beta,gamma) = symbols('alpha beta gamma') (x,t,xp,tp) = symbols("x t x' t'",real=True) (st2d,g0,g1) = Ga.build('gamma*t|x',g=[1,-1]) from sympy import sinh,cosh R = cosh(alpha/2)+sinh(alpha/2)*(g0^g1) X = t*g0+x*g1 Xp = tp*g0+xp*g1 print 'R =',R print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}" Xpp = R*Xp*R.rev() Xpp = Xpp.collect() Xpp = Xpp.trigsimp() print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp Xpp = Xpp.subs({sinh(alpha):gamma*beta,cosh(alpha):gamma}) print r'%\f{\sinh}{\alpha} = \gamma\beta' print r'%\f{\cosh}{\alpha} = \gamma' print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp.collect() return
def derivatives_in_spherical_coordinates(): #Print_Function() coords = (r,th,phi) = symbols('r theta phi', real=True) (sp3d,er,eth,ephi) = Ga.build('e_r e_theta e_phi',g=[1,r**2,r**2*sin(th)**2],coords=coords) grad = sp3d.grad f = sp3d.mv('f','scalar',f=True) A = sp3d.mv('A','vector',f=True) B = sp3d.mv('B','bivector',f=True) print 'f =',f print 'A =',A print 'B =',B print 'grad*f =',grad*f print 'grad|A =',grad|A print 'grad\\times A = -I*(grad^A) =',-sp3d.i*(grad^A) print '%\\nabla^{2}f =',grad|(grad*f) print 'grad^B =',grad^B """ print '( \\nabla\\W\\nabla )\\bm{e}_{r} =',((grad^grad)*er).trigsimp() print '( \\nabla\\W\\nabla )\\bm{e}_{\\theta} =',((grad^grad)*eth).trigsimp() print '( \\nabla\\W\\nabla )\\bm{e}_{\\phi} =',((grad^grad)*ephi).trigsimp() """ return
def main(): Eprint() X = (x, y, z) = symbols('x y z', real=True) (o3d, ex, ey, ez) = Ga.build('e_x e_y e_z', g=[1, 1, 1], coords=(x, y, z)) A = x * (ey ^ ez) + y * (ez ^ ex) + z * (ex ^ ey) print 'A =', A print 'grad^A =', (o3d.grad ^ A).simplify() print f = o3d.mv(1 / sqrt(x**2 + y**2 + z**2)) print 'f =', f print 'grad*f =', (o3d.grad * f).simplify() print B = f * A print 'B =', B print Curl_B = o3d.grad ^ B print 'grad^B =', Curl_B.simplify() return
def test_blade_coefs(self): """ Various tests on several multivectors. """ (_g3d, e_1, e_2, e_3) = Ga.build('e*1|2|3') m0 = 2 * e_1 + e_2 - e_3 + 3 * (e_1 ^ e_3) + (e_1 ^ e_3) + (e_2 ^ (3 * e_3)) self.assertTrue(m0.blade_coefs([e_1]) == [2]) self.assertTrue(m0.blade_coefs([e_2]) == [1]) self.assertTrue(m0.blade_coefs([e_1, e_2]) == [2, 1]) self.assertTrue(m0.blade_coefs([e_1 ^ e_3]) == [4]) self.assertTrue(m0.blade_coefs([e_1 ^ e_3, e_2 ^ e_3]) == [4, 3]) self.assertTrue(m0.blade_coefs([e_2 ^ e_3, e_1 ^ e_3]) == [3, 4]) self.assertTrue(m0.blade_coefs([e_1, e_2 ^ e_3]) == [2, 3]) a = Symbol('a') b = Symbol('b') m1 = a * e_1 + e_2 - e_3 + b * (e_1 ^ e_2) self.assertTrue(m1.blade_coefs([e_1]) == [a]) self.assertTrue(m1.blade_coefs([e_2]) == [1]) self.assertTrue(m1.blade_coefs([e_3]) == [-1]) self.assertTrue(m1.blade_coefs([e_1 ^ e_2]) == [b]) self.assertTrue(m1.blade_coefs([e_2 ^ e_3]) == [0]) self.assertTrue(m1.blade_coefs([e_1 ^ e_3]) == [0]) self.assertTrue(m1.blade_coefs([e_1 ^ e_2 ^ e_3]) == [0]) # Invalid parameters self.assertRaises(ValueError, lambda: m1.blade_coefs([e_1 + e_2])) self.assertRaises(ValueError, lambda: m1.blade_coefs([e_2 ^ e_1])) self.assertRaises(ValueError, lambda: m1.blade_coefs([e_1, e_2 ^ e_1])) self.assertRaises(ValueError, lambda: m1.blade_coefs([a * e_1])) self.assertRaises(ValueError, lambda: m1.blade_coefs([3 * e_3]))
def Maxwells_Equations_in_Geom_Calculus(): Print_Function() X = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=X) I = st4d.i B = st4d.mv('B','vector',f=True) E = st4d.mv('E','vector',f=True) B.set_coef(1,0,0) E.set_coef(1,0,0) B *= g0 E *= g0 J = st4d.mv('J','vector',f=True) F = E+I*B print r'\text{Pseudo Scalar\;\;}I =',I print '\\text{Magnetic Field Bi-Vector\\;\\;} B = \\bm{B\\gamma_{t}} =',B print '\\text{Electric Field Bi-Vector\\;\\;} E = \\bm{E\\gamma_{t}} =',E print '\\text{Electromagnetic Field Bi-Vector\\;\\;} F = E+IB =',F print '%\\text{Four Current Density\\;\\;} J =',J gradF = st4d.grad*F print '#Geom Derivative of Electomagnetic Field Bi-Vector' gradF.Fmt(3,'grad*F') print '#Maxwell Equations' print 'grad*F = J' print '#Div $E$ and Curl $H$ Equations' (gradF.get_grade(1)-J).Fmt(3,'%\\grade{\\nabla F}_{1} -J = 0') print '#Curl $E$ and Div $B$ equations' (gradF.get_grade(3)).Fmt(3,'%\\grade{\\nabla F}_{3} = 0') return
def main(): Print_Function() (a, b, c) = abc = symbols('a,b,c', real=True) (o3d, ea, eb, ec) = Ga.build('e_a e_b e_c', g=[1, 1, 1], coords=abc) grad = o3d.grad x = symbols('x', real=True) A = o3d.lt([[x*a*c**2,x**2*a*b*c,x**2*a**3*b**5],\ [x**3*a**2*b*c,x**4*a*b**2*c**5,5*x**4*a*b**2*c],\ [x**4*a*b**2*c**4,4*x**4*a*b**2*c**2,4*x**4*a**5*b**2*c]]) print('A =', A) v = a * ea + b * eb + c * ec print('v =', v) f = v | A(v) print(r'%f = v\cdot \f{A}{v} =', f) (grad * f).Fmt(3, r'%\nabla f') Av = A(v) print(r'%\f{A}{v} =', Av) (grad * Av).Fmt(3, r'%\nabla \f{A}{v}') return
def derivatives_in_prolate_spheroidal_coordinates(): #Print_Function() a = symbols('a', real=True) coords = (xi, eta, phi) = symbols('xi eta phi', real=True) (ps3d, er, eth, ephi) = Ga.build('e_xi e_eta e_phi', X=[ a * sinh(xi) * sin(eta) * cos(phi), a * sinh(xi) * sin(eta) * sin(phi), a * cosh(xi) * cos(eta) ], coords=coords, norm=True) grad = ps3d.grad f = ps3d.mv('f', 'scalar', f=True) A = ps3d.mv('A', 'vector', f=True) B = ps3d.mv('B', 'bivector', f=True) print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad * f) print('grad|A =', grad | A) (-ps3d.i * (grad ^ A)).Fmt(3, '-I*(grad^A)') (grad ^ B).Fmt(3, 'grad^B') return
def Lorentz_Tranformation_in_Geog_Algebra(): Print_Function() (alpha, beta, gamma) = symbols('alpha beta gamma') (x, t, xp, tp) = symbols("x t x' t'", real=True) (st2d, g0, g1) = Ga.build('gamma*t|x', g=[1, -1]) from sympy import sinh, cosh R = cosh(alpha / 2) + sinh(alpha / 2) * (g0 ^ g1) X = t * g0 + x * g1 Xp = tp * g0 + xp * g1 print 'R =', R print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}" Xpp = R * Xp * R.rev() Xpp = Xpp.collect() Xpp = Xpp.trigsimp() print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp Xpp = Xpp.subs({sinh(alpha): gamma * beta, cosh(alpha): gamma}) print r'%\f{\sinh}{\alpha} = \gamma\beta' print r'%\f{\cosh}{\alpha} = \gamma' print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp.collect() return
def main(): Print_Function() (a, b, c) = abc = symbols("a,b,c", real=True) (o3d, ea, eb, ec) = Ga.build("e_a e_b e_c", g=[1, 1, 1], coords=abc) grad = o3d.grad x = symbols("x", real=True) A = o3d.lt( [ [x * a * c ** 2, x ** 2 * a * b * c, x ** 2 * a ** 3 * b ** 5], [x ** 3 * a ** 2 * b * c, x ** 4 * a * b ** 2 * c ** 5, 5 * x ** 4 * a * b ** 2 * c], [x ** 4 * a * b ** 2 * c ** 4, 4 * x ** 4 * a * b ** 2 * c ** 2, 4 * x ** 4 * a ** 5 * b ** 2 * c], ] ) print "A =", A v = a * ea + b * eb + c * ec print "v =", v f = v | A(v) print r"%f = v\cdot \f{A}{v} =", f (grad * f).Fmt(3, r"%\nabla f") Av = A(v) print r"%\f{A}{v} =", Av (grad * Av).Fmt(3, r"%\nabla \f{A}{v}") return
def derivatives_in_spherical_coordinates(): #Print_Function() coords = (r, th, phi) = symbols('r theta phi', real=True) (sp3d, er, eth, ephi) = Ga.build('e_r e_theta e_phi', g=[1, r**2, r**2 * sin(th)**2], coords=coords) grad = sp3d.grad f = sp3d.mv('f', 'scalar', f=True) A = sp3d.mv('A', 'vector', f=True) B = sp3d.mv('B', 'bivector', f=True) print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad * f) print('grad|A =', grad | A) print('grad\\times A = -I*(grad^A) =', -sp3d.i * (grad ^ A)) print('%\\nabla^{2}f =', grad | (grad * f)) print('grad^B =', grad ^ B) """ print '( \\nabla\\W\\nabla )\\bm{e}_{r} =',((grad^grad)*er).trigsimp() print '( \\nabla\\W\\nabla )\\bm{e}_{\\theta} =',((grad^grad)*eth).trigsimp() print '( \\nabla\\W\\nabla )\\bm{e}_{\\phi} =',((grad^grad)*ephi).trigsimp() """ return
def derivatives_in_paraboloidal_coordinates(): #Print_Function() coords = (u, v, phi) = symbols('u v phi', real=True) (par3d, er, eth, ephi) = Ga.build( 'e_u e_v e_phi', X=[u * v * cos(phi), u * v * sin(phi), (u**2 - v**2) / 2], coords=coords, norm=True) grad = par3d.grad f = par3d.mv('f', 'scalar', f=True) A = par3d.mv('A', 'vector', f=True) B = par3d.mv('B', 'bivector', f=True) print('#Derivatives in Paraboloidal Coordinates') print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad * f) print('grad|A =', grad | A) (-par3d.i * (grad ^ A)).Fmt(3, 'grad\\times A = -I*(grad^A)') print('grad^B =', grad ^ B) return
def main(): Eprint() X = (x,y,z) = symbols('x y z',real=True) (o3d,ex,ey,ez) = Ga.build('e_x e_y e_z',g=[1,1,1],coords=(x,y,z)) A = x*(ey^ez) + y*(ez^ex) + z*(ex^ey) print 'A =', A print 'grad^A =',(o3d.grad^A).simplify() print f = o3d.mv(1/sqrt(x**2 + y**2 + z**2)) print 'f =', f print 'grad*f =',(o3d.grad*f).simplify() print B = f*A print 'B =', B print Curl_B = o3d.grad^B print 'grad^B =', Curl_B.simplify() return
def basic_multivector_operations_3D(): #Print_Function() (g3d,ex,ey,ez) = Ga.build('e*x|y|z') print 'g_{ij} =',g3d.g A = g3d.mv('A','mv') A.Fmt(1,'A') A.Fmt(2,'A') A.Fmt(3,'A') A.even().Fmt(1,'%A_{+}') A.odd().Fmt(1,'%A_{-}') X = g3d.mv('X','vector') Y = g3d.mv('Y','vector') X.Fmt(1,'X') Y.Fmt(1,'Y') (X*Y).Fmt(2,'X*Y') (X^Y).Fmt(2,'X^Y') (X|Y).Fmt(2,'X|Y') return
def test2_12_2_1(self): """ In R2 with Euclidean metric, choose an orthonormal basis {e_1, e_2} in the plane of a and b such that e1 is parallel to a. Write x = a * e_1 and y = b * (cos(t) * e_1 + sin(t) * e_2), whete t is the angle from a to b. Evaluate the outer product. What is the geometrical interpretation ? """ (_g2d, e_1, e_2) = Ga.build('e*1|2', g='1 0, 0 1') # TODO: use alpha, beta and theta instead of a, b and t (it crashes sympy) a = Symbol('a') b = Symbol('b') t = Symbol('t') x = a * e_1 y = b * (cos(t) * e_1 + sin(t) * e_2) B = x ^ y self.assertTrue(B == (a * b * sin(t) * (e_1 ^ e_2))) # Retrieve the parallelogram area from the 2-vector area = B.norm() self.assertTrue(area == (a * b * sin(t))) # Compute the parallelogram area using the determinant x = [a, 0] y = [b * cos(t), b * sin(t)] area = Matrix([x, y]).det() self.assertTrue(area == (a * b * sin(t)))
def Dirac_Equation_in_Geom_Calculus(): Print_Function() coords = symbols('t x y z', real=True) (st4d, g0, g1, g2, g3) = Ga.build('gamma*t|x|y|z', g=[1, -1, -1, -1], coords=coords) I = st4d.i (m, e) = symbols('m e') psi = st4d.mv('psi', 'spinor', f=True) A = st4d.mv('A', 'vector', f=True) sig_z = g3 * g0 print '\\text{4-Vector Potential\\;\\;}\\bm{A} =', A print '\\text{8-component real spinor\\;\\;}\\bm{\\psi} =', psi dirac_eq = (st4d.grad * psi) * I * sig_z - e * A * psi - m * psi * g0 dirac_eq = dirac_eq.simplify() print dirac_eq.Fmt( 3, r'%\text{Dirac Equation\;\;}\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0' ) return
def General_Lorentz_Tranformation(): Print_Function() (alpha, beta, gamma) = symbols('alpha beta gamma') (x, y, z, t) = symbols("x y z t", real=True) (st4d, g0, g1, g2, g3) = Ga.build('gamma*t|x|y|z', g=[1, -1, -1, -1]) B = (x * g1 + y * g2 + z * g3) ^ (t * g0) print B print B.exp(hint='+') print B.exp(hint='-')
def General_Lorentz_Tranformation(): Print_Function() (alpha, beta, gamma) = symbols("alpha beta gamma") (x, y, z, t) = symbols("x y z t", real=True) (st4d, g0, g1, g2, g3) = Ga.build("gamma*t|x|y|z", g=[1, -1, -1, -1]) B = (x * g1 + y * g2 + z * g3) ^ (t * g0) print B print B.exp(hint="+") print B.exp(hint="-")
def test2_12_1_3(self): """ What is the area of the parallelogram spanned by the vectors a = e_1 + 2*e_2 and b = -e_1 - e_2 (relative to the area of e_1 ^ e_2) ? """ (_g3d, e_1, e_2, _e_3) = Ga.build('e*1|2|3') a = e_1 + 2*e_2 b = -e_1 - e_2 B = a ^ b self.assertTrue(B == 1 * (e_1 ^ e_2))
def test2_12_1_2(self): """ Given the 2-blade B = e_1 ^ (e_2 - e_3) that represents a plane, determine if each of the following vectors lies in that plane. """ (_g3d, e_1, e_2, e_3) = Ga.build('e*1|2|3') B = e_1 ^ (e_2 - e_3) self.assertTrue(e_1 ^ B == 0) self.assertFalse((e_1 + e_2) ^ B == 0) self.assertFalse((e_1 + e_2 + e_3) ^ B == 0) self.assertTrue((2*e_1 - e_2 + e_3) ^ B == 0)
def Mv_setup_options(): Print_Function() (o3d, e1, e2, e3) = Ga.build('e_1 e_2 e_3', g=[1, 1, 1]) v = o3d.mv('v', 'vector') print v (o3d, e1, e2, e3) = Ga.build('e*1|2|3', g=[1, 1, 1]) v = o3d.mv('v', 'vector') print v (o3d, e1, e2, e3) = Ga.build('e*x|y|z', g=[1, 1, 1]) v = o3d.mv('v', 'vector') print v coords = symbols('x y z', real=True) (o3d, e1, e2, e3) = Ga.build('e', g=[1, 1, 1], coords=coords) v = o3d.mv('v', 'vector') print v return
def Mv_setup_options(): Print_Function() (o3d,e1,e2,e3) = Ga.build('e_1 e_2 e_3',g=[1,1,1]) v = o3d.mv('v', 'vector') print v (o3d,e1,e2,e3) = Ga.build('e*1|2|3',g=[1,1,1]) v = o3d.mv('v', 'vector') print v (o3d,e1,e2,e3) = Ga.build('e*x|y|z',g=[1,1,1]) v = o3d.mv('v', 'vector') print v coords = symbols('x y z',real=True) (o3d,e1,e2,e3) = Ga.build('e',g=[1,1,1],coords=coords) v = o3d.mv('v', 'vector') print v return
def test_2_12_1_1(self): """ Compute the outer products of the following 3-space expressions, giving the result relative to the basis {1, e_1, e_2, e_3, e_1^e_2, e_1^e_3, e_2^e_3, e_1^e_2^e_3}. """ (_g3d, e_1, e_2, e_3) = Ga.build('e*1|2|3') self.assertTrue((e_1 + e_2) ^ (e_1 + e_3) == (-e_1 ^ e_2) + (e_1 ^ e_3) + (e_2 ^ e_3)) self.assertTrue((e_1 + e_2 + e_3) ^ (2*e_1) == -2*(e_1 ^ e_2) - 2*(e_1 ^ e_3)) self.assertTrue((e_1 - e_2) ^ (e_1 - e_3) == (e_1 ^ e_2) - (e_1 ^ e_3) + (e_2 ^ e_3)) self.assertTrue((e_1 + e_2) ^ (0.5*e_1 + 2*e_2 + 3*e_3) == 1.5*(e_1 ^ e_2) + 3*(e_1 ^ e_3) + 3*(e_2 ^ e_3)) self.assertTrue((e_1 ^ e_2) ^ (e_1 + e_3) == (e_1 ^ e_2 ^ e_3)) self.assertTrue((e_1 + e_2) ^ ((e_1 ^ e_2) + (e_2 ^ e_3)) == (e_1 ^ e_2 ^ e_3))
def coefs_test(): Print_Function() (o3d, e1, e2, e3) = Ga.build('e_1 e_2 e_3', g=[1, 1, 1]) print(o3d.blades_lst) print(o3d.mv_blades_lst) v = o3d.mv('v', 'vector') print(v) print(v.blade_coefs([e3, e1])) A = o3d.mv('A', 'mv') print(A) print(A.blade_coefs([e1 ^ e3, e3, e1 ^ e2, e1 ^ e2 ^ e3])) print(A.blade_coefs()) return
def coefs_test(): Print_Function() (o3d, e1, e2, e3) = Ga.build("e_1 e_2 e_3", g=[1, 1, 1]) print o3d.blades_lst print o3d.mv_blades_lst v = o3d.mv("v", "vector") print v print v.blade_coefs([e3, e1]) A = o3d.mv("A", "mv") print A print A.blade_coefs([e1 ^ e3, e3, e1 ^ e2, e1 ^ e2 ^ e3]) print A.blade_coefs() return
def Lie_Group(): Print_Function() coords = symbols("t x y z", real=True) (st4d, g0, g1, g2, g3) = Ga.build("gamma*t|x|y|z", g=[1, -1, -1, -1], coords=coords) I = st4d.i a = st4d.mv("a", "vector") B = st4d.mv("B", "bivector") print "a =", a print "B =", B print "a|B =", a | B print ((a | B) | B).simplify().Fmt(3, "(a|B)|B") print (((a | B) | B) | B).simplify().Fmt(3, "((a|B)|B)|B") return
def Lie_Group(): Print_Function() coords = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) I = st4d.i a = st4d.mv('a','vector') B = st4d.mv('B','bivector') print 'a =',a print 'B =',B print 'a|B =', a|B print ((a|B)|B).simplify().Fmt(3,'(a|B)|B') print (((a|B)|B)|B).simplify().Fmt(3,'((a|B)|B)|B') return
def Lie_Group(): Print_Function() coords = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) I = st4d.i a = st4d.mv('a','vector') B = st4d.mv('B','bivector') print('a =',a) print('B =',B) print('a|B =', a|B) print(((a|B)|B).simplify().Fmt(3,'(a|B)|B')) print((((a|B)|B)|B).simplify().Fmt(3,'((a|B)|B)|B')) return
def Mv_setup_options(): Print_Function() (o3d, e1, e2, e3) = Ga.build("e_1 e_2 e_3", g=[1, 1, 1]) v = o3d.mv("v", "vector") print v (o3d, e1, e2, e3) = Ga.build("e*1|2|3", g=[1, 1, 1]) v = o3d.mv("v", "vector") print v (o3d, e1, e2, e3) = Ga.build("e*x|y|z", g=[1, 1, 1]) v = o3d.mv("v", "vector") print v coords = symbols("x y z", real=True) (o3d, e1, e2, e3) = Ga.build("e", g=[1, 1, 1], coords=coords) v = o3d.mv("v", "vector") print v print v.grade(2) print v.i_grade return
def basic_multivector_operations_2D(): #Print_Function() (g2d,ex,ey) = Ga.build('e*x|y') print 'g_{ij} =',g2d.g X = g2d.mv('X','vector') A = g2d.mv('A','spinor') X.Fmt(1,'X') A.Fmt(1,'A') (X|A).Fmt(2,'X|A') (X<A).Fmt(2,'X<A') (A>X).Fmt(2,'A>X') return
def basic_multivector_operations_2D(): Print_Function() (g2d,ex,ey) = Ga.build('e*x|y') print('g_{ij} =',g2d.g) X = g2d.mv('X','vector') A = g2d.mv('A','spinor') print(X.Fmt(1,'X')) print(A.Fmt(1,'A')) print((X|A).Fmt(2,'X|A')) print((X<A).Fmt(2,'X<A')) print((A>X).Fmt(2,'A>X')) return
def test2_12_2_2(self): """ Consider R4 with basis {e_1, e_2, e_3, e_4}. Show that the 2-vector B = (e_1 ^ e_2) + (e_3 ^ e_4) is not a 2-blade (i.e., it cannot be written as the outer product of two vectors). """ (_g4d, e_1, e_2, e_3, e_4) = Ga.build('e*1|2|3|4') # B B = (e_1 ^ e_2) + (e_3 ^ e_4) # C is the product of a and b vectors a_1 = Symbol('a_1') a_2 = Symbol('a_2') a_3 = Symbol('a_3') a_4 = Symbol('a_4') a = a_1 * e_1 + a_2 * e_2 + a_3 * e_3 + a_4 * e_4 b_1 = Symbol('b_1') b_2 = Symbol('b_2') b_3 = Symbol('b_3') b_4 = Symbol('b_4') b = b_1 * e_1 + b_2 * e_2 + b_3 * e_3 + b_4 * e_4 C = a ^ b # other coefficients are null blades = [ e_1 ^ e_2, e_1 ^ e_3, e_1 ^ e_4, e_2 ^ e_3, e_2 ^ e_4, e_3 ^ e_4, ] C_coefs = C.blade_coefs(blades) B_coefs = B.blade_coefs(blades) # try to solve the system and show there is no solution system = [ (C_coef) - (B_coef) for C_coef, B_coef in zip(C_coefs, B_coefs) ] unknowns = [ a_1, a_2, a_3, a_4, b_1, b_2, b_3, b_4 ] # TODO: use solve if sympy fix it result = solve_poly_system(system, unknowns) self.assertTrue(result is None)
def main(): Eprint() (o3d, ex, ey, ez) = Ga.build('e*x|y|z', g=[1, 1, 1]) u = o3d.mv('u', 'vector') v = o3d.mv('v', 'vector') w = o3d.mv('w', 'vector') print u print v uv = u ^ v print uv print uv.is_blade() exp_uv = uv.exp() print 'exp(uv) =', exp_uv return
def main(): Eprint() (o3d,ex,ey,ez) = Ga.build('e*x|y|z',g=[1,1,1]) u = o3d.mv('u','vector') v = o3d.mv('v','vector') w = o3d.mv('w','vector') print u print v uv = u^v print uv print uv.is_blade() exp_uv = uv.exp() print 'exp(uv) =', exp_uv return
def EM_Waves_in_Geom_Calculus_Complex(): #Print_Function() X = (t, x, y, z) = symbols('t x y z', real=True) g = '1 # # 0,# 1 # 0,# # 1 0,0 0 0 -1' coords = (xE, xB, xk, t) = symbols('x_E x_B x_k t', real=True) (EBkst, eE, eB, ek, et) = Ga.build('e_E e_B e_k e_t', g=g, coords=coords) i = EBkst.i E, B, k, w = symbols('E B k omega', real=True) F = E * eE * et + i * B * eB * et K = k * ek + w * et X = xE * eE + xB * eB + xk * ek + t * et KX = (K | X).scalar() F = F * exp(I * KX) g = EBkst.g print('g =', g) print('X =', X) print('K =', K) print('K|X =', KX) print('F =', F) gradF = EBkst.grad * F gradF = gradF.simplify() (gradF).Fmt(3, 'grad*F = 0') gradF = gradF.subs({g[0, 1]: 0, g[0, 2]: 0, g[1, 2]: 0}) KX = KX.subs({g[0, 1]: 0, g[0, 2]: 0, g[1, 2]: 0}) print( r'%\mbox{Substituting }e_{E}\cdot e_{B} = e_{E}\cdot e_{k} = e_{B}\cdot e_{k} = 0' ) (gradF / (I * exp(I * KX))).Fmt( 3, r'%\lp\bm{\nabla}F\rp/\lp ie^{iK\cdot X}\rp = 0') return
def derivatives_in_elliptic_cylindrical_coordinates(): #Print_Function() 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 f = elip3d.mv('f','scalar',f=True) A = elip3d.mv('A','vector',f=True) B = elip3d.mv('B','bivector',f=True) print 'f =',f print 'A =',A print 'B =',B print 'grad*f =',grad*f print 'grad|A =',grad|A print '-I*(grad^A) =',-elip3d.i*(grad^A) print 'grad^B =',grad^B return
def test_is_base(self): """ Various tests on several multivectors. """ (_g3d, e_1, e_2, e_3) = Ga.build('e*1|2|3') self.assertTrue((e_1).is_base()) self.assertTrue((e_2).is_base()) self.assertTrue((e_3).is_base()) self.assertTrue((e_1 ^ e_2).is_base()) self.assertTrue((e_2 ^ e_3).is_base()) self.assertTrue((e_1 ^ e_3).is_base()) self.assertTrue((e_1 ^ e_2 ^ e_3).is_base()) self.assertFalse((2*e_1).is_base()) self.assertFalse((e_1 + e_2).is_base()) self.assertFalse((e_3 * 4).is_base()) self.assertFalse(((3 * e_1) ^ e_2).is_base()) self.assertFalse((2 * (e_2 ^ e_3)).is_base()) self.assertFalse((e_3 ^ e_1).is_base()) self.assertFalse((e_2 ^ e_1 ^ e_3).is_base())
def test_is_base(self): """ Various tests on several multivectors. """ (_g3d, e_1, e_2, e_3) = Ga.build('e*1|2|3') self.assertTrue((e_1).is_base()) self.assertTrue((e_2).is_base()) self.assertTrue((e_3).is_base()) self.assertTrue((e_1 ^ e_2).is_base()) self.assertTrue((e_2 ^ e_3).is_base()) self.assertTrue((e_1 ^ e_3).is_base()) self.assertTrue((e_1 ^ e_2 ^ e_3).is_base()) self.assertFalse((2 * e_1).is_base()) self.assertFalse((e_1 + e_2).is_base()) self.assertFalse((e_3 * 4).is_base()) self.assertFalse(((3 * e_1) ^ e_2).is_base()) self.assertFalse((2 * (e_2 ^ e_3)).is_base()) self.assertFalse((e_3 ^ e_1).is_base()) self.assertFalse((e_2 ^ e_1 ^ e_3).is_base())
def Dirac_Equation_in_Geog_Calculus(): Print_Function() coords = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) I = st4d.i (m,e) = symbols('m e') psi = st4d.mv('psi','spinor',f=True) A = st4d.mv('A','vector',f=True) sig_z = g3*g0 print '\\text{4-Vector Potential\\;\\;}\\bm{A} =',A print '\\text{8-component real spinor\\;\\;}\\bm{\\psi} =',psi dirac_eq = (st4d.grad*psi)*I*sig_z-e*A*psi-m*psi*g0 dirac_eq = dirac_eq.simplify() dirac_eq.Fmt(3,r'%\text{Dirac Equation\;\;}\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0') return
def derivatives_in_prolate_spheroidal_coordinates(): #Print_Function() a = symbols('a', real=True) coords = (xi,eta,phi) = symbols('xi eta phi', real=True) (ps3d,er,eth,ephi) = Ga.build('e_xi e_eta e_phi',X=[a*sinh(xi)*sin(eta)*cos(phi),a*sinh(xi)*sin(eta)*sin(phi), a*cosh(xi)*cos(eta)],coords=coords,norm=True) grad = ps3d.grad f = ps3d.mv('f','scalar',f=True) A = ps3d.mv('A','vector',f=True) B = ps3d.mv('B','bivector',f=True) print 'f =',f print 'A =',A print 'B =',B print 'grad*f =',grad*f print 'grad|A =',grad|A (-ps3d.i*(grad^A)).Fmt(3,'-I*(grad^A)') (grad^B).Fmt(3,'grad^B') return
def main(): Eprint() coords = symbols('x y z') (o3d,ex,ey,ez) = Ga.build('ex ey ez',g=[1,1,1],coords=coords) mfvar = (u,v) = symbols('u v') eu = ex+ey ev = ex-ey (eu_r,ev_r) = o3d.ReciprocalFrame([eu,ev]) oprint('Frame',(eu,ev),'Reciprocal Frame',(eu_r,ev_r)) print 'eu.eu_r =',eu|eu_r print 'eu.ev_r =',eu|ev_r print 'ev.eu_r =',ev|eu_r print 'ev.ev_r =',ev|ev_r eu = ex+ey+ez ev = ex-ey (eu_r,ev_r) = o3d.ReciprocalFrame([eu,ev]) oprint('Frame',(eu,ev),'Reciprocal Frame',(eu_r,ev_r)) print 'eu.eu_r =',eu|eu_r print 'eu.ev_r =',eu|ev_r print 'ev.eu_r =',ev|eu_r print 'ev.ev_r =',ev|ev_r print 'eu =',eu print 'ev =',ev def_prec(locals()) print GAeval('eu^ev|ex',True) print GAeval('eu^ev|ex*eu',True) return
def EM_Waves_in_Geom_Calculus_Complex(): #Print_Function() X = (t,x,y,z) = symbols('t x y z',real=True) g = '1 # # 0,# 1 # 0,# # 1 0,0 0 0 -1' coords = (xE,xB,xk,t) = symbols('x_E x_B x_k t',real=True) (EBkst,eE,eB,ek,et) = Ga.build('e_E e_B e_k e_t',g=g,coords=coords) i = EBkst.i E,B,k,w = symbols('E B k omega',real=True) F = E*eE*et+i*B*eB*et K = k*ek+w*et X = xE*eE+xB*eB+xk*ek+t*et KX = (K|X).scalar() F = F*exp(I*KX) g = EBkst.g print 'g =', g print 'X =', X print 'K =', K print 'K|X =', KX print 'F =', F gradF = EBkst.grad*F gradF = gradF.simplify() (gradF).Fmt(3,'grad*F = 0') gradF = gradF.subs({g[0,1]:0,g[0,2]:0,g[1,2]:0}) KX = KX.subs({g[0,1]:0,g[0,2]:0,g[1,2]:0}) print r'%\mbox{Substituting }e_{E}\cdot e_{B} = e_{E}\cdot e_{k} = e_{B}\cdot e_{k} = 0' (gradF / (I*exp(I*KX))).Fmt(3,r'%\lp\bm{\nabla}F\rp/\lp ie^{iK\cdot X}\rp = 0') return
def derivatives_in_paraboloidal_coordinates(): #Print_Function() coords = (u,v,phi) = symbols('u v phi', real=True) (par3d,er,eth,ephi) = Ga.build('e_u e_v e_phi',X=[u*v*cos(phi),u*v*sin(phi),(u**2-v**2)/2],coords=coords,norm=True) grad = par3d.grad f = par3d.mv('f','scalar',f=True) A = par3d.mv('A','vector',f=True) B = par3d.mv('B','bivector',f=True) print '#Derivatives in Paraboloidal Coordinates' print 'f =',f print 'A =',A print 'B =',B print 'grad*f =',grad*f print 'grad|A =',grad|A (-par3d.i*(grad^A)).Fmt(3,'grad\\times A = -I*(grad^A)') print 'grad^B =',grad^B return
def Dirac_Equation_in_Geom_Calculus(): Print_Function() coords = symbols("t x y z", real=True) (st4d, g0, g1, g2, g3) = Ga.build("gamma*t|x|y|z", g=[1, -1, -1, -1], coords=coords) I = st4d.i (m, e) = symbols("m e") psi = st4d.mv("psi", "spinor", f=True) A = st4d.mv("A", "vector", f=True) sig_z = g3 * g0 print "\\text{4-Vector Potential\\;\\;}\\bm{A} =", A print "\\text{8-component real spinor\\;\\;}\\bm{\\psi} =", psi dirac_eq = (st4d.grad * psi) * I * sig_z - e * A * psi - m * psi * g0 dirac_eq = dirac_eq.simplify() print dirac_eq.Fmt( 3, r"%\text{Dirac Equation\;\;}\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0" ) return
def test2_12_1_4(self): """ Compute the intersection of the non-homogeneous line L with position vector e_1 and direction vector e_2, and the line M with position vector e_2 and direction vector (e_1 + e_2), using 2-blades. """ (_g2d, e_1, e_2) = Ga.build('e*1|2') # x is defined in the basis {e_1, e_2} a = Symbol('a') b = Symbol('b') x = a * e_1 + b * e_2 # x lies on L and M (eq. L == 0 and M == 0) L = (x ^ e_2) - (e_1 ^ e_2) M = (x ^ (e_1 + e_2)) - (e_2 ^ (e_1 + e_2)) # Solve the linear system R = solve([L, M], a, b) # Replace symbols x = x.subs(R) self.assertTrue(x == e_1 + 2*e_2)
def derivatives_in_elliptic_cylindrical_coordinates(): #Print_Function() 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 f = elip3d.mv('f', 'scalar', f=True) A = elip3d.mv('A', 'vector', f=True) B = elip3d.mv('B', 'bivector', f=True) print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad * f) print('grad|A =', grad | A) print('-I*(grad^A) =', -elip3d.i * (grad ^ A)) print('grad^B =', grad ^ B) return
import sys from sympy import symbols,exp,I,Matrix,solve,simplify from printer import Format,xpdf,Get_Program,Print_Function from ga import Ga from metric import linear_expand Format() X = (t,x,y,z) = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=X) i = st4d.i B = st4d.mv('B','vector') E = st4d.mv('E','vector') B.set_coef(1,0,0) E.set_coef(1,0,0) B *= g0 E *= g0 F = E+i*B kx, ky, kz, w = symbols('k_x k_y k_z omega',real=True) kv = kx*g1+ky*g2+kz*g3 xv = x*g1+y*g2+z*g3 KX = ((w*g0+kv)|(t*g0+xv)).scalar() Ixyz = g1*g2*g3 F = F*exp(I*KX) print r'\text{Pseudo Scalar\;\;}I =',i print r'%I_{xyz} =',Ixyz
def main(): Format() coords = (x,y,z) = symbols('x y z',real=True) (o3d,ex,ey,ez) = Ga.build('e*x|y|z',g=[1,1,1],coords=coords) s = o3d.mv('s','scalar') v = o3d.mv('v','vector') b = o3d.mv('b','bivector') print(r'#3D Orthogonal Metric\newline') print('#Multvectors:') print('s =',s) print('v =',v) print('b =',b) print('#Products:') X = ((s,'s'),(v,'v'),(b,'b')) for xi in X: print('') for yi in X: print(xi[1]+' * '+yi[1]+' =',xi[0]*yi[0]) print(xi[1]+' ^ '+yi[1]+' =',xi[0]^yi[0]) if xi[1] != 's' and yi[1] != 's': print(xi[1]+' | '+yi[1]+' =',xi[0]|yi[0]) print(xi[1]+' < '+yi[1]+' =',xi[0]<yi[0]) print(xi[1]+' > '+yi[1]+' =',xi[0]>yi[0]) fs = o3d.mv('s','scalar',f=True) fv = o3d.mv('v','vector',f=True) fb = o3d.mv('b','bivector',f=True) print('#Multivector Functions:') print('s(X) =',fs) print('v(X) =',fv) print('b(X) =',fb) print('#Products:') fX = ((o3d.grad,'grad'),(fs,'s'),(fv,'v'),(fb,'b')) for xi in fX: print('') for yi in fX: if xi[1] == 'grad' and yi[1] == 'grad': pass else: print(xi[1]+' * '+yi[1]+' =',xi[0]*yi[0]) print(xi[1]+' ^ '+yi[1]+' =',xi[0]^yi[0]) if xi[1] != 's' and yi[1] != 's': print(xi[1]+' | '+yi[1]+' =',xi[0]|yi[0]) print(xi[1]+' < '+yi[1]+' =' ,xi[0]<yi[0]) print(xi[1]+' > '+yi[1]+' =' ,xi[0]>yi[0]) (g2d,ex,ey) = Ga.build('e',coords=(x,y)) print(r'#General 2D Metric\newline') print('#Multivector Functions:') s = g2d.mv('s','scalar',f=True) v = g2d.mv('v','vector',f=True) b = g2d.mv('v','bivector',f=True) print('s(X) =',s) print('v(X) =',v) print('b(X) =',b) X = ((g2d.grad,'grad'),(s,'s'),(v,'v')) print('#Products:') for xi in X: print('') for yi in X: if xi[1] == 'grad' and yi[1] == 'grad': pass else: print(xi[1]+' * '+yi[1]+' =',xi[0]*yi[0]) print(xi[1]+' ^ '+yi[1]+' =',xi[0]^yi[0]) if xi[1] != 's' and yi[1] != 's': print(xi[1]+' | '+yi[1]+' =',xi[0]|yi[0]) else: print(xi[1]+' | '+yi[1]+' = Not Allowed') print(xi[1]+' < '+yi[1]+' =',xi[0]<yi[0]) print(xi[1]+' > '+yi[1]+' =' ,xi[0]>yi[0]) xpdf(paper='letter') return
def main(): Format() (g3d,ex,ey,ez) = Ga.build('e*x|y|z') A = g3d.mv('A','mv') print r'\bm{A} =',A A.Fmt(2,r'\bm{A}') A.Fmt(3,r'\bm{A}') X = (x,y,z) = symbols('x y z',real=True) o3d = Ga('e_x e_y e_z',g=[1,1,1],coords=X) (ex,ey,ez) = o3d.mv() f = o3d.mv('f','scalar',f=True) A = o3d.mv('A','vector',f=True) B = o3d.mv('B','bivector',f=True) print r'\bm{A} =',A print r'\bm{B} =',B print 'grad*f =',o3d.grad*f print r'grad|\bm{A} =',o3d.grad|A print r'grad*\bm{A} =',o3d.grad*A print r'-I*(grad^\bm{A}) =',-o3d.i*(o3d.grad^A) print r'grad*\bm{B} =',o3d.grad*B print r'grad^\bm{B} =',o3d.grad^B print r'grad|\bm{B} =',o3d.grad|B g4d = Ga('a b c d') (a,b,c,d) = g4d.mv() print 'g_{ij} =',g4d.g print '\\bm{a|(b*c)} =',a|(b*c) print '\\bm{a|(b^c)} =',a|(b^c) print '\\bm{a|(b^c^d)} =',a|(b^c^d) print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',(a|(b^c))+(c|(a^b))+(b|(c^a)) print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',a*(b^c)-b*(a^c)+c*(a^b) print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c) print '\\bm{(a^b)|(c^d)} =',(a^b)|(c^d) print '\\bm{((a^b)|c)|d} =',((a^b)|c)|d print '\\bm{(a^b)\\times (c^d)} =',Com(a^b,c^d) g = '1 # #,'+ \ '# 1 #,'+ \ '# # 1' ng3d = Ga('e1 e2 e3',g=g) (e1,e2,e3) = ng3d.mv() E = e1^e2^e3 Esq = (E*E).scalar() print 'E =',E print '%E^{2} =',Esq Esq_inv = 1/Esq E1 = (e2^e3)*E E2 = (-1)*(e1^e3)*E E3 = (e1^e2)*E print 'E1 = (e2^e3)*E =',E1 print 'E2 =-(e1^e3)*E =',E2 print 'E3 = (e1^e2)*E =',E3 print 'E1|e2 =',(E1|e2).expand() print 'E1|e3 =',(E1|e3).expand() print 'E2|e1 =',(E2|e1).expand() print 'E2|e3 =',(E2|e3).expand() print 'E3|e1 =',(E3|e1).expand() print 'E3|e2 =',(E3|e2).expand() w = ((E1|e1).expand()).scalar() Esq = expand(Esq) print '%(E1\\cdot e1)/E^{2} =',simplify(w/Esq) w = ((E2|e2).expand()).scalar() print '%(E2\\cdot e2)/E^{2} =',simplify(w/Esq) w = ((E3|e3).expand()).scalar() print '%(E3\\cdot e3)/E^{2} =',simplify(w/Esq) X = (r,th,phi) = symbols('r theta phi') s3d = Ga('e_r e_theta e_phi',g=[1,r**2,r**2*sin(th)**2],coords=X,norm=True) (er,eth,ephi) = s3d.mv() f = s3d.mv('f','scalar',f=True) A = s3d.mv('A','vector',f=True) B = s3d.mv('B','bivector',f=True) print 'A =',A print 'B =',B print 'grad*f =',s3d.grad*f print 'grad|A =',s3d.grad|A print '-I*(grad^A) =',-s3d.i*(s3d.grad^A) print 'grad^B =',s3d.grad^B coords = symbols('t x y z') m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) (g0,g1,g2,g3) = m4d.mv() I = m4d.i B = m4d.mv('B','vector',f=True) E = m4d.mv('E','vector',f=True) B.set_coef(1,0,0) E.set_coef(1,0,0) B *= g0 E *= g0 J = m4d.mv('J','vector',f=True) F = E+I*B print 'B = \\bm{B\\gamma_{t}} =',B print 'E = \\bm{E\\gamma_{t}} =',E print 'F = E+IB =',F print 'J =',J gradF = m4d.grad*F gradF.Fmt(3,'grad*F') print 'grad*F = J' (gradF.get_grade(1)-J).Fmt(3,'%\\grade{\\nabla F}_{1} -J = 0') (gradF.get_grade(3)).Fmt(3,'%\\grade{\\nabla F}_{3} = 0') (alpha,beta,gamma) = symbols('alpha beta gamma') (x,t,xp,tp) = symbols("x t x' t'") m2d = Ga('gamma*t|x',g=[1,-1]) (g0,g1) = m2d.mv() R = cosh(alpha/2)+sinh(alpha/2)*(g0^g1) X = t*g0+x*g1 Xp = tp*g0+xp*g1 print 'R =',R print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}" Xpp = R*Xp*R.rev() Xpp = Xpp.collect() Xpp = Xpp.trigsimp() print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp Xpp = Xpp.subs({sinh(alpha):gamma*beta,cosh(alpha):gamma}) print r'%\f{\sinh}{\alpha} = \gamma\beta' print r'%\f{\cosh}{\alpha} = \gamma' print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp.collect() coords = symbols('t x y z') m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) (g0,g1,g2,g3) = m4d.mv() I = m4d.i (m,e) = symbols('m e') psi = m4d.mv('psi','spinor',f=True) A = m4d.mv('A','vector',f=True) sig_z = g3*g0 print '\\bm{A} =',A print '\\bm{\\psi} =',psi dirac_eq = (m4d.grad*psi)*I*sig_z-e*A*psi-m*psi*g0 dirac_eq.simplify() dirac_eq.Fmt(3,r'\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0') xpdf() return
from sympy import symbols, sin from printer import Format, xpdf, Fmt from ga import Ga Format() g = '# 0 #, 0 # 0, # 0 #' (g3d, ea, eab, eb) = Ga.build('e_a e_ab e_b', g=g) print(g3d.g) v = g3d.mv('v', 'vector') B = g3d.mv('B', 'bivector') print(v) print(B) xpdf()
def main(): Eprint() (o3d, ex, ey, ez) = Ga.build('e*x|y|z', g=[1, 1, 1]) (r, th, phi, alpha, beta, gamma) = symbols('r theta phi alpha beta gamma', real=True) (x_a, y_a, z_a, x_b, y_b, z_b, ab_mag, th_ab) = symbols('x_a y_a z_a x_b y_b z_b ab_mag theta_ab', real=True) I = ex ^ ey ^ ez a = o3d.mv('a', 'vector') b = o3d.mv('b', 'vector') c = o3d.mv('c', 'vector') ab = a - b print('a =', a) print('b =', b) print('c =', c) print('ab =', ab) ab_norm = ab / ab_mag print('ab/|ab| =', ab_norm) R_ab = cos(th_ab / 2) + I * ab_norm * cos(th_ab / 2) R_ab_rev = R_ab.rev() print('R_ab =', R_ab) print('R_ab_rev =', R_ab_rev) e__ab_x = R_ab * ex * R_ab_rev e__ab_y = R_ab * ey * R_ab_rev e__ab_z = R_ab * ez * R_ab_rev print('e_ab_x =', e__ab_x) print('e_ab_y =', e__ab_y) print('e_ab_z =', e__ab_z) R_phi = cos(phi / 2) - (ex ^ ey) * sin(phi / 2) R_phi_rev = R_phi.rev() print(R_phi) print(R_phi_rev) e_phi = (R_phi * ey * R_phi.rev()) print(e_phi) R_th = cos(th / 2) + I * e_phi * sin(th / 2) R_th_rev = R_th.rev() print(R_th) print(R_th_rev) e_r = (R_th * R_phi * ex * R_phi_rev * R_th_rev).trigsimp() e_th = (R_th * R_phi * ez * R_phi_rev * R_th_rev).trigsimp() e_phi = e_phi.trigsimp() print('e_r =', e_r) print('e_th =', e_th) print('e_phi =', e_phi) return
import sys from sympy import symbols,sin,cos from printer import Format,xpdf,Get_Program,Print_Function from ga import Ga from lt import Mlt coords = symbols('t x y z',real=True) (st4d,g0,g1,g2,g3) = Ga.build('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords) A = st4d.mv('T','bivector') def TA(a1,a2): global A return A | (a1 ^ a2) T = Mlt(TA,st4d) # Define multi-linear function
from sympy import symbols, sin, cos from ga import Ga from printer import Format, xpdf Format() (u, v) = uv = symbols('u,v', real=True) (g2d, eu, ev) = Ga.build('e_u e_v', coords=uv) print('#$A$ is a general 2D linear transformation') A2d = g2d.lt('A') print('A =', A2d) print('\\f{\\det}{A} =', A2d.det()) print('\\f{\\Tr}{A} =', A2d.tr()) B2d = g2d.lt('B') print('B =', B2d) print('A + B =', A2d + B2d) print('AB =', A2d * B2d) print('A - B =', A2d - B2d) a = g2d.mv('a', 'vector') b = g2d.mv('b', 'vector') print(r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =', ((a | A2d.adj()(b)) - (b | A2d(a))).simplify()) m4d = Ga('e_t e_x e_y e_z',
def main(): Print_Function() (x, y, z) = xyz = symbols('x,y,z', real=True) (o3d, ex, ey, ez) = Ga.build('e_x e_y e_z', g=[1, 1, 1], coords=xyz) grad = o3d.grad (u, v) = uv = symbols('u,v', real=True) (g2d, eu, ev) = Ga.build('e_u e_v', coords=uv) grad_uv = g2d.grad v_xyz = o3d.mv('v', 'vector') A_xyz = o3d.mv('A', 'vector', f=True) A_uv = g2d.mv('A', 'vector', f=True) print('#3d orthogonal ($A$ is vector function)') print('A =', A_xyz) print('%A^{2} =', A_xyz * A_xyz) print('grad|A =', grad | A_xyz) print('grad*A =', grad * A_xyz) print('v|(grad*A) =', v_xyz | (grad * A_xyz)) print('#2d general ($A$ is vector function)') print('A =', A_uv) print('%A^{2} =', A_uv * A_uv) print('grad|A =', grad_uv | A_uv) print('grad*A =', grad_uv * A_uv) A = o3d.lt('A') print('#3d orthogonal ($A,\\;B$ are linear transformations)') print('A =', A) print(r'\f{mat}{A} =', A.matrix()) print('\\f{\\det}{A} =', A.det()) print('\\overline{A} =', A.adj()) print('\\f{\\Tr}{A} =', A.tr()) print('\\f{A}{e_x^e_y} =', A(ex ^ ey)) print('\\f{A}{e_x}^\\f{A}{e_y} =', A(ex) ^ A(ey)) B = o3d.lt('B') print('g =', o3d.g) print('%g^{-1} =', o3d.g_inv) print('A + B =', A + B) print('AB =', A * B) print('A - B =', A - B) print('General Symmetric Linear Transformation') Asym = o3d.lt('A', mode='s') print('A =', Asym) print('General Antisymmetric Linear Transformation') Aasym = o3d.lt('A', mode='a') print('A =', Aasym) print('#2d general ($A,\\;B$ are linear transformations)') A2d = g2d.lt('A') print('g =', g2d.g) print('%g^{-1} =', g2d.g_inv) print('%gg^{-1} =', simplify(g2d.g * g2d.g_inv)) print('A =', A2d) print(r'\f{mat}{A} =', A2d.matrix()) print('\\f{\\det}{A} =', A2d.det()) A2d_adj = A2d.adj() print('\\overline{A} =', A2d_adj) print('\\f{mat}{\\overline{A}} =', simplify(A2d_adj.matrix())) print('\\f{\\Tr}{A} =', A2d.tr()) print('\\f{A}{e_u^e_v} =', A2d(eu ^ ev)) print('\\f{A}{e_u}^\\f{A}{e_v} =', A2d(eu) ^ A2d(ev)) B2d = g2d.lt('B') print('B =', B2d) print('A + B =', A2d + B2d) print('AB =', A2d * B2d) print('A - B =', A2d - B2d) a = g2d.mv('a', 'vector') b = g2d.mv('b', 'vector') print(r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =', ((a | A2d.adj()(b)) - (b | A2d(a))).simplify()) m4d = Ga('e_t e_x e_y e_z', g=[1, -1, -1, -1], coords=symbols('t,x,y,z', real=True)) T = m4d.lt('T') print('g =', m4d.g) print(r'\underline{T} =', T) print(r'\overline{T} =', T.adj()) print(r'\f{\det}{\underline{T}} =', T.det()) print(r'\f{\mbox{tr}}{\underline{T}} =', T.tr()) a = m4d.mv('a', 'vector') b = m4d.mv('b', 'vector') print(r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =', ((a | T.adj()(b)) - (b | T(a))).simplify()) coords = (r, th, phi) = symbols('r,theta,phi', real=True) (sp3d, er, eth, ephi) = Ga.build('e_r e_th e_ph', g=[1, r**2, r**2 * sin(th)**2], coords=coords) grad = sp3d.grad sm_coords = (u, v) = symbols('u,v', real=True) smap = [1, u, v] # Coordinate map for sphere of r = 1 sph2d = sp3d.sm(smap, sm_coords, norm=True) (eu, ev) = sph2d.mv() grad_uv = sph2d.grad F = sph2d.mv('F', 'vector', f=True) f = sph2d.mv('f', 'scalar', f=True) print('f =', f) print('grad*f =', grad_uv * f) print('F =', F) print('grad*F =', grad_uv * F) tp = (th, phi) = symbols('theta,phi', real=True) smap = [sin(th) * cos(phi), sin(th) * sin(phi), cos(th)] sph2dr = o3d.sm(smap, tp, norm=True) (eth, ephi) = sph2dr.mv() grad_tp = sph2dr.grad F = sph2dr.mv('F', 'vector', f=True) f = sph2dr.mv('f', 'scalar', f=True) print('f =', f) print('grad*f =', grad_tp * f) print('F =', F) print('grad*F =', grad_tp * F) return
def EM_Waves_in_Geom_Calculus(): #Print_Function() X = (t, x, y, z) = symbols('t x y z', real=True) (st4d, g0, g1, g2, g3) = Ga.build('gamma*t|x|y|z', g=[1, -1, -1, -1], coords=X) i = st4d.I() B = st4d.mv('B', 'vector') E = st4d.mv('E', 'vector') B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 F = E + i * B kx, ky, kz, w = symbols('k_x k_y k_z omega', real=True) kv = kx * g1 + ky * g2 + kz * g3 xv = x * g1 + y * g2 + z * g3 KX = ((w * g0 + kv) | (t * g0 + xv)).scalar() Ixyz = g1 * g2 * g3 F = F * exp(I * KX) print(r'\text{Pseudo Scalar\;\;}I =', i) print(r'%I_{xyz} =', Ixyz) print(F.Fmt(3, '\\text{Electromagnetic Field Bi-Vector\\;\\;} F')) gradF = st4d.grad * F print('#Geom Derivative of Electomagnetic Field Bi-Vector') print(gradF.Fmt(3, 'grad*F = 0')) gradF = gradF / (I * exp(I * KX)) print(gradF.Fmt(3, r'%\lp\bm{\nabla}F\rp /\lp i e^{iK\cdot X}\rp = 0')) g = '-1 # 0 0,# -1 0 0,0 0 -1 0,0 0 0 1' X = (xE, xB, xk, t) = symbols('x_E x_B x_k t', real=True) # The correct signature sig=p for signature (p,q) is needed # since the correct value of I**2 is needed to compute exp(I) (EBkst, eE, eB, ek, et) = Ga.build('e_E e_B e_k t', g=g, coords=X, sig=1) i = EBkst.I() E, B, k, w = symbols('E B k omega', real=True) F = E * eE * et + i * B * eB * et kv = k * ek + w * et xv = xE * eE + xB * eB + xk * ek + t * et KX = (kv | xv).scalar() F = F * exp(I * KX) print(r'%\mbox{set } e_{E}\cdot e_{k} = e_{B}\cdot e_{k} = 0'+\ r'\mbox{ and } e_{E}\cdot e_{E} = e_{B}\cdot e_{B} = e_{k}\cdot e_{k} = -e_{t}\cdot e_{t} = 1') print('g =', EBkst.g) print('K|X =', KX) print('F =', F) (EBkst.grad * F).Fmt(3, 'grad*F = 0') gradF_reduced = (EBkst.grad * F) / (I * exp(I * KX)) print( gradF_reduced.Fmt(3, r'%\lp\bm{\nabla}F\rp/\lp ie^{iK\cdot X} \rp = 0')) print( r'%\mbox{Previous equation requires that: }e_{E}\cdot e_{B} = 0\mbox{ if }B\ne 0\mbox{ and }k\ne 0' ) gradF_reduced = gradF_reduced.subs({EBkst.g[0, 1]: 0}).expand() print( gradF_reduced.Fmt(3, r'%\lp\bm{\nabla}F\rp/\lp ie^{iK\cdot X} \rp = 0')) (coefs, bases) = linear_expand(gradF_reduced.obj) eq1 = coefs[0] eq2 = coefs[1] print(r'0 =', eq1) print(r'0 =', eq2) B1 = solve(eq1, B)[0] B2 = solve(eq2, B)[0] eq3 = B1 - B2 print(r'\mbox{eq3 = eq1-eq2: }0 =', eq3) eq3 = simplify(eq3 / E) print(r'\mbox{eq3 = (eq1-eq2)/E: }0 =', eq3) print('k =', Matrix(solve(eq3, k))) print('B =', Matrix([B1.subs(w, k), B1.subs(-w, k)])) return
from sympy import symbols, sin from printer import Format, xpdf, Fmt from ga import Ga import sys Format() xyz_coords = (x, y, z) = symbols('x y z', real=True) (o3d, ex, ey, ez) = Ga.build('e', g=[1, 1, 1], coords=xyz_coords, norm=True) f = o3d.mv('f', 'scalar', f=True) F = o3d.mv('F', 'vector', f=True) B = o3d.mv('B', 'bivector', f=True) l = [f, F, B] print(Fmt(l)) print(Fmt(l, 1)) print(F.Fmt(3)) print(B.Fmt(3)) lap = o3d.grad * o3d.grad print(r'%\nabla^{2} = \nabla\cdot\nabla =', lap) dop = lap + o3d.grad print(dop.Fmt(fmt=3, dop_fmt=3)) xpdf(paper=(6, 7))
from sympy import symbols, sin from printer import Format, xpdf, Fmt from ga import Ga import sys Format() xyz_coords = (x, y, z) = symbols('x y z', real=True) (o3d, ex, ey, ez) = Ga.build('e', g=[1, 1, 1], coords=xyz_coords, norm=True) f = o3d.mv('f', 'scalar', f=True) lap = o3d.grad * o3d.grad print r'%\nabla^{2} = \nabla\cdot\nabla =', lap print r'%\lp\nabla^{2}\rp f =', lap * f print r'%\nabla\cdot\lp\nabla f\rp =', o3d.grad | (o3d.grad * f) sph_coords = (r, th, phi) = symbols('r theta phi', real=True) (sp3d, er, eth, ephi) = Ga.build('e', g=[1, r**2, r**2 * sin(th)**2], coords=sph_coords, norm=True) f = sp3d.mv('f', 'scalar', f=True) lap = sp3d.grad * sp3d.grad print r'%\nabla^{2} = \nabla\cdot\nabla =', lap print r'%\lp\nabla^{2}\rp f =', lap * f print r'%\nabla\cdot\lp\nabla f\rp =', sp3d.grad | (sp3d.grad * f) print Fmt([o3d.grad, o3d.grad]) F = sp3d.mv('F', 'vector', f=True) print F.title print F F.fmt = 3 print F.title print F