def Fmt_test(): Print_Function() e3d = Ga('e1 e2 e3',g=[1,1,1]) v = e3d.mv('v','vector') B = e3d.mv('B','bivector') M = e3d.mv('M','mv') Fmt(2) print '#Global $Fmt = 2$' print 'v =',v print 'B =',B print 'M =',M print '#Using $.Fmt()$ Function' print 'v.Fmt(3) =',v.Fmt(3) print 'B.Fmt(3) =',B.Fmt(3) print 'M.Fmt(2) =',M.Fmt(2) print 'M.Fmt(1) =',M.Fmt(1) print '#Global $Fmt = 1$' Fmt(1) print 'v =',v print 'B =',B print 'M =',M return
def extracting_vectors_from_conformal_2_blade(): Print_Function() print r'B = P1\W P2' g = '0 -1 #,'+ \ '-1 0 #,'+ \ '# # #' c2b = Ga('P1 P2 a',g=g) (P1,P2,a) = c2b.mv() print 'g_{ij} =',c2b.g B = P1^P2 Bsq = B*B print '%B^{2} =',Bsq ap = a-(a^B)*B print "a' = a-(a^B)*B =",ap Ap = ap+ap*B Am = ap-ap*B print "A+ = a'+a'*B =",Ap print "A- = a'-a'*B =",Am print '%(A+)^{2} =',Ap*Ap print '%(A-)^{2} =',Am*Am aB = a|B print 'a|B =',aB return
def derivatives_in_rectangular_coordinates(): Print_Function() X = (x,y,z) = symbols('x y z') o3d = Ga('e_x e_y e_z',g=[1,1,1],coords=X) (ex,ey,ez) = o3d.mv() grad = o3d.grad f = o3d.mv('f','scalar',f=True) A = o3d.mv('A','vector',f=True) B = o3d.mv('B','bivector',f=True) C = o3d.mv('C','mv') print 'f =',f print 'A =',A print 'B =',B print 'C =',C print 'grad*f =',grad*f print 'grad|A =',grad|A print 'grad*A =',grad*A print '-I*(grad^A) =',-o3d.i*(grad^A) print 'grad*B =',grad*B print 'grad^B =',grad^B print 'grad|B =',grad|B return
def basic_multivector_operations_3D(): Print_Function() g3d = Ga('e*x|y|z') (ex,ey,ez) = g3d.mv() 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') print 'g_{ij} = ',g3d.g 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 properties_of_geometric_objects(): Print_Function() global n, nbar g = '# # # 0 0,'+ \ '# # # 0 0,'+ \ '# # # 0 0,'+ \ '0 0 0 0 2,'+ \ '0 0 0 2 0' c3d = Ga('p1 p2 p3 n \\bar{n}',g=g) (p1,p2,p3,n,nbar) = c3d.mv() print 'g_{ij} =',c3d.g P1 = F(p1) P2 = F(p2) P3 = F(p3) print '\\text{Extracting direction of line from }L = P1\\W P2\\W n' L = P1^P2^n delta = (L|n)|nbar print '(L|n)|\\bar{n} =',delta print '\\text{Extracting plane of circle from }C = P1\\W P2\\W P3' C = P1^P2^P3 delta = ((C^n)|n)|nbar print '((C^n)|n)|\\bar{n}=',delta print '(p2-p1)^(p3-p1)=',(p2-p1)^(p3-p1) return
def test_3_4(self): """ The other contraction. """ Ga.dual_mode("Iinv+") R = Ga('e*1|2|3') A_blades = [R.mv('A', i, 'grade') for i in range(R.n + 1)] B_blades = [R.mv('B', i, 'grade') for i in range(R.n + 1)] for A, B in product(A_blades, B_blades): self.assertEquals(B > A, ((-1) ** (A.pure_grade() * (B.pure_grade() - 1))) * (A < B))
def rounding_numerical_components(): Print_Function() o3d = Ga('e_x e_y e_z',g=[1,1,1]) (ex,ey,ez) = o3d.mv() X = 1.2*ex+2.34*ey+0.555*ez Y = 0.333*ex+4*ey+5.3*ez print 'X =',X print 'Nga(X,2) =',Nga(X,2) print 'X*Y =',X*Y print 'Nga(X*Y,2) =',Nga(X*Y,2) 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 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 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 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 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 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 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 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 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(): 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 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 test_3_5_4(self): """ The duality relationships. """ Ga.dual_mode("Iinv+") R = Ga('e*1|2|3') A_blades = [R.mv('A', i, 'grade') for i in range(R.n + 1)] B_blades = [R.mv('B', i, 'grade') for i in range(R.n + 1)] for A, B in product(A_blades, B_blades): self.assertEquals((A ^ B).dual(), A < B.dual()) for A, B in product(A_blades, B_blades): self.assertEquals((A < B).dual(), A ^ B.dual())
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 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 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 basic_multivector_operations_2D(): Print_Function() g2d = Ga('e*x|y') (ex,ey) = g2d.mv() 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 check_generalized_BAC_CAB_formulas(): Print_Function() 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) return
def basic_multivector_operations_2D(): Print_Function() g2d = Ga('e*x|y') (ex,ey) = g2d.mv() 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 check_generalized_BAC_CAB_formulas(): Print_Function() 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) return
def derivatives_in_rectangular_coordinates(): Print_Function() X = (x, y, z) = symbols('x y z') o3d = Ga('e_x e_y e_z', g=[1, 1, 1], coords=X) (ex, ey, ez) = o3d.mv() grad = o3d.grad f = o3d.mv('f', 'scalar', f=True) A = o3d.mv('A', 'vector', f=True) B = o3d.mv('B', 'bivector', f=True) C = o3d.mv('C', 'mv') print('f =', f) print('A =', A) print('B =', B) print('C =', C) print('grad*f =', grad * f) print('grad|A =', grad | A) print('grad*A =', grad * A) print('-I*(grad^A) =', -o3d.I() * (grad ^ A)) print('grad*B =', grad * B) print('grad^B =', grad ^ B) print('grad|B =', grad | B) return
def derivatives_in_rectangular_coordinates(): Print_Function() X = (x, y, z) = symbols('x y z') o3d = Ga('e_x e_y e_z', g=[1, 1, 1], coords=X) (ex, ey, ez) = o3d.mv() grad = o3d.grad f = o3d.mv('f', 'scalar', f=True) A = o3d.mv('A', 'vector', f=True) B = o3d.mv('B', 'bivector', f=True) C = o3d.mv('C', 'mv', f=True) print 'f =', f print 'A =', A print 'B =', B print 'C =', C print 'grad*f =', grad * f print 'grad|A =', grad | A print 'grad*A =', grad * A print '-I*(grad^A) =', -o3d.E() * (grad ^ A) print 'grad*B =', grad * B print 'grad^B =', grad ^ B print 'grad|B =', grad | B print 'grad<A =', grad < A print 'grad>A =', grad > A print 'grad<B =', grad < B print 'grad>B =', grad > B print 'grad<C =', grad < C print 'grad>C =', grad > C return
def test_3_5_2(self): """ The inverse of a blade. """ Ga.dual_mode("Iinv+") R = Ga('e*1|2|3') A_blades = [R.mv('A', i, 'grade') for i in range(R.n + 1)] for A in A_blades: self.assertEquals(A.inv(), ((-1) ** (A.pure_grade() * (A.pure_grade() - 1) / 2)) * (A / A.norm2())) for A in A_blades: self.assertEquals(A < A.inv(), 1) A = A_blades[1] self.assertEquals(A.inv(), A / A.norm2())
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 derivatives_in_spherical_coordinates(): Print_Function() 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() grad = s3d.grad f = s3d.mv('f','scalar',f=True) A = s3d.mv('A','vector',f=True) B = s3d.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) =',(-s3d.i*(grad^A)).simplify() print 'grad^B =',grad^B
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 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 conformal_representations_of_circles_lines_spheres_and_planes(): global n, nbar Print_Function() g = '1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 2,0 0 0 2 0' cnfml3d = Ga('e_1 e_2 e_3 n nbar', g=g) (e1, e2, e3, n, nbar) = cnfml3d.mv() print 'g_{ij} =\n', cnfml3d.g e = n + nbar #conformal representation of points A = make_vector(e1, ga=cnfml3d) # point a = (1,0,0) A = F(a) B = make_vector(e2, ga=cnfml3d) # point b = (0,1,0) B = F(b) C = make_vector(-e1, ga=cnfml3d) # point c = (-1,0,0) C = F(c) D = make_vector(e3, ga=cnfml3d) # point d = (0,0,1) D = F(d) X = make_vector('x', 3, ga=cnfml3d) print 'F(a) =', A print 'F(b) =', B print 'F(c) =', C print 'F(d) =', D print 'F(x) =', X print 'a = e1, b = e2, c = -e1, and d = e3' print 'A = F(a) = 1/2*(a*a*n+2*a-nbar), etc.' print 'Circle through a, b, and c' print 'Circle: A^B^C^X = 0 =', (A ^ B ^ C ^ X) print 'Line through a and b' print 'Line : A^B^n^X = 0 =', (A ^ B ^ n ^ X) print 'Sphere through a, b, c, and d' print 'Sphere: A^B^C^D^X = 0 =', (((A ^ B) ^ C) ^ D) ^ X print 'Plane through a, b, and d' print 'Plane : A^B^n^D^X = 0 =', (A ^ B ^ n ^ D ^ X) L = (A ^ B ^ e) ^ X print L.Fmt(3, 'Hyperbolic Circle: (A^B^e)^X = 0 =') return
def conformal_representations_of_circles_lines_spheres_and_planes(): global n,nbar Print_Function() g = '1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 2,0 0 0 2 0' cnfml3d = Ga('e_1 e_2 e_3 n nbar',g=g) (e1,e2,e3,n,nbar) = cnfml3d.mv() print 'g_{ij} =\n',cnfml3d.g e = n+nbar #conformal representation of points A = make_vector(e1,ga=cnfml3d) # point a = (1,0,0) A = F(a) B = make_vector(e2,ga=cnfml3d) # point b = (0,1,0) B = F(b) C = make_vector(-e1,ga=cnfml3d) # point c = (-1,0,0) C = F(c) D = make_vector(e3,ga=cnfml3d) # point d = (0,0,1) D = F(d) X = make_vector('x',3,ga=cnfml3d) print 'F(a) =',A print 'F(b) =',B print 'F(c) =',C print 'F(d) =',D print 'F(x) =',X print 'a = e1, b = e2, c = -e1, and d = e3' print 'A = F(a) = 1/2*(a*a*n+2*a-nbar), etc.' print 'Circle through a, b, and c' print 'Circle: A^B^C^X = 0 =',(A^B^C^X) print 'Line through a and b' print 'Line : A^B^n^X = 0 =',(A^B^n^X) print 'Sphere through a, b, c, and d' print 'Sphere: A^B^C^D^X = 0 =',(((A^B)^C)^D)^X print 'Plane through a, b, and d' print 'Plane : A^B^n^D^X = 0 =',(A^B^n^D^X) L = (A^B^e)^X print L.Fmt(3,'Hyperbolic Circle: (A^B^e)^X = 0 =') return
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 conformal_representations_of_circles_lines_spheres_and_planes(): Print_Function() global n, nbar Fmt(1) g = '1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 2,0 0 0 2 0' c3d = Ga('e_1 e_2 e_3 n \\bar{n}', g=g) (e1, e2, e3, n, nbar) = c3d.mv() print('g_{ij} =', c3d.g) e = n + nbar #conformal representation of points A = make_vector(e1, ga=c3d) # point a = (1,0,0) A = F(a) B = make_vector(e2, ga=c3d) # point b = (0,1,0) B = F(b) C = make_vector(-e1, ga=c3d) # point c = (-1,0,0) C = F(c) D = make_vector(e3, ga=c3d) # point d = (0,0,1) D = F(d) X = make_vector('x', 3, ga=c3d) print('F(a) =', A) print('F(b) =', B) print('F(c) =', C) print('F(d) =', D) print('F(x) =', X) print('#a = e1, b = e2, c = -e1, and d = e3') print('#A = F(a) = 1/2*(a*a*n+2*a-nbar), etc.') print('#Circle through a, b, and c') print('Circle: A^B^C^X = 0 =', (A ^ B ^ C ^ X)) print('#Line through a and b') print('Line : A^B^n^X = 0 =', (A ^ B ^ n ^ X)) print('#Sphere through a, b, c, and d') print('Sphere: A^B^C^D^X = 0 =', (((A ^ B) ^ C) ^ D) ^ X) print('#Plane through a, b, and d') print('Plane : A^B^n^D^X = 0 =', (A ^ B ^ n ^ D ^ X)) L = (A ^ B ^ e) ^ X L.Fmt(3, 'Hyperbolic\\;\\; Circle: (A^B^e)^X = 0') 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 check_generalized_BAC_CAB_formulas(): Print_Function() g5d = Ga('a b c d e') (a, b, c, d, e) = g5d.mv() print 'g_{ij} =\n', g5d.g print 'a|(b*c) =', a | (b * c) print 'a|(b^c) =', a | (b ^ c) print 'a|(b^c^d) =', a | (b ^ c ^ d) print 'a|(b^c)+c|(a^b)+b|(c^a) =', (a | ( b ^ c)) + (c | (a ^ b)) + (b | (c ^ a)) print 'a*(b^c)-b*(a^c)+c*(a^b) =',a*(b^c)-b*(a^c)+c*(a^b) print '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 '(a^b)|(c^d) =',(a^b)|(c^d) print '((a^b)|c)|d =',((a^b)|c)|d print '(a^b)x(c^d) =',com(a^b,c^d) print '(a|(b^c))|(d^e) =',(a|(b^c))|(d^e) 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 check_generalized_BAC_CAB_formulas(): Print_Function() g5d = Ga('a b c d e') (a, b, c, d, e) = g5d.mv() print('g_{ij} =\n', g5d.g) print('a|(b*c) =', a | (b * c)) print('a|(b^c) =', a | (b ^ c)) print('a|(b^c^d) =', a | (b ^ c ^ d)) print('a|(b^c)+c|(a^b)+b|(c^a) =', (a | ( b ^ c)) + (c | (a ^ b)) + (b | (c ^ a))) print('a*(b^c)-b*(a^c)+c*(a^b) =',a*(b^c)-b*(a^c)+c*(a^b)) print('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('(a^b)|(c^d) =',(a^b)|(c^d)) print('((a^b)|c)|d =',((a^b)|c)|d) print('(a^b)x(c^d) =',com(a^b,c^d)) print('(a|(b^c))|(d^e) =',(a|(b^c))|(d^e)) 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 derivatives_in_spherical_coordinates(): Print_Function() 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() grad = s3d.grad f = s3d.mv('f', 'scalar', f=True) A = s3d.mv('A', 'vector', f=True) B = s3d.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) =', (-s3d.i * (grad ^ A)).simplify() print 'grad^B =', grad ^ B
def test_3_6(self): """ Orthogonal projection of subspaces. """ Ga.dual_mode("Iinv+") R = Ga('e*1|2|3') X_blades = [R.mv('X', i, 'grade') for i in range(R.n + 1)] B_blades = [R.mv('B', i, 'grade') for i in range(R.n + 1)] # projection of X on B def P(X, B): return (X < B.inv()) < B # a projection should be idempotent for X, B in product(X_blades, B_blades): self.assertEquals(P(X, B), P(P(X, B), B)) # with the contraction for X, B in product(X_blades, B_blades): self.assertEquals(X < B, P(X, B) < B)
def basic_multivector_operations_2D_orthogonal(): Print_Function() o2d = Ga('e*x|y',g=[1,1]) (ex,ey) = o2d.mv() print 'g_{ii} =',o2d.g X = o2d.mv('X','vector') A = o2d.mv('A','spinor') X.Fmt(1,'X') A.Fmt(1,'A') (X*A).Fmt(2,'X*A') (X|A).Fmt(2,'X|A') (X<A).Fmt(2,'X<A') (X>A).Fmt(2,'X>A') (A*X).Fmt(2,'A*X') (A|X).Fmt(2,'A|X') (A<X).Fmt(2,'A<X') (A>X).Fmt(2,'A>X') return
def basic_multivector_operations_2D_orthogonal(): Print_Function() o2d = Ga('e*x|y',g=[1,1]) (ex,ey) = o2d.mv() print 'g_{ii} =',o2d.g X = o2d.mv('X','vector') A = o2d.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 (X<A).Fmt(2,'X<A') print (X>A).Fmt(2,'X>A') print (A*X).Fmt(2,'A*X') print (A|X).Fmt(2,'A|X') print (A<X).Fmt(2,'A<X') print (A>X).Fmt(2,'A>X') 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 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 main(): Format() snr=1 g = '0 0 1 0 ,0 0 0 1 ,1 0 0 0 ,0 1 0 0' sk4coords = (e1,e2,e3,e4) = symbols('e1 e2 e3 e4') sk4 = Ga('e_1 e_2 e_3 e_4', g=g, coords=sk4coords) (e1,e2,e3,e4) = sk4.mv() print 'g_{ii} =',sk4.g v = symbols('v', real=True) x1=(e1+e3)/sqrt(2) x2=(e2+e4)/sqrt(2) print 'x_1<x_1==',x1<x1 print 'x_1<x_2==',x1<x2 print 'x_2<x_1==',x2<x1 print 'x_2<x_2==',x2<x2 print r'#$-\infty < v < \infty$' print '(-v*(x_1^x_2)/2).exp()==',(-v*(x1^x2)/2).exp() v = symbols('v', real=True, positive=True) print r'#$0\le v < \infty$' print '(-v*(x_1^x_2)/2).exp()==',(-v*(x1^x2)/2).exp() xpdf() return
def generateit(): # # 繁衍多代 # 返回,最终编码coding,每次繁衍的编码decodings,每次繁衍的适应度值fitnessvalues,初始编码iniplot,每代的适应度值fitness # inipol = ga.codeit(n, length) decodings = [] fitnessvalues = [] fitness = [] iniplot = np.copy(inipol).tolist() for i in range(g): inipol = multiply(inipol)[0] decodings.append(multiply(inipol)[1]) fitnessvalues.append(multiply(inipol)[2]) fitness.append(np.mean(multiply(inipol)[2])) return inipol, decodings, fitnessvalues, iniplot, fitness
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 test_check_generalized_BAC_CAB_formulas(): (a, b, c, d, e) = MV.setup('a b c d e') assert str(a | (b * c)) == '-(a.c)*b + (a.b)*c' assert str(a | (b ^ c)) == '-(a.c)*b + (a.b)*c' assert str(a | (b ^ c ^ d)) == '(a.d)*b^c - (a.c)*b^d + (a.b)*c^d' #assert str( (a|(b^c))+(c|(a^b))+(b|(c^a)) ) == '0' assert str(a * (b ^ c) - b * (a ^ c) + c * (a ^ b)) == '3*a^b^c' assert str(a * (b ^ c ^ d) - b * (a ^ c ^ d) + c * (a ^ b ^ d) - d * (a ^ b ^ c)) == '4*a^b^c^d' assert str((a ^ b) | (c ^ d)) == '-(a.c)*(b.d) + (a.d)*(b.c)' assert str(((a ^ b) | c) | d) == '-(a.c)*(b.d) + (a.d)*(b.c)' assert str(Ga.com(a ^ b, c ^ d)) == '-(b.d)*a^c + (b.c)*a^d + (a.d)*b^c - (a.c)*b^d' assert str( (a | (b ^ c)) | (d ^ e) ) == '(-(a.b)*(c.e) + (a.c)*(b.e))*d + ((a.b)*(c.d) - (a.c)*(b.d))*e' 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 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())