def Dirac_Equation_in_Geometric_Calculus(): Print_Function() vars = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars) I = MV.I (m, e) = symbols('m e') psi = MV('psi', 'spinor', fct=True) A = MV('A', 'vector', fct=True) sig_z = g3 * g0 print('\\text{4-Vector Potential\\;\\;}\\bm{A} =', A) print('\\text{8-component real spinor\\;\\;}\\bm{\\psi} =', psi) dirac_eq = (grad * psi) * I * sig_z - e * A * psi - m * psi * g0 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_rectangular_coordinates(): Print_Function() X = (x, y, z) = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=X) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) C = MV('C', 'mv', fct=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) =', -MV.I * (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 Maxwells_Equations_in_Geometric_Calculus(): Print_Function() X = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=X) I = MV.I B = MV('B', 'vector', fct=True) E = MV('E', 'vector', fct=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 J = MV('J', 'vector', fct=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 = grad * F print('#Geometric 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.grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0') print('#Curl $E$ and Div $B$ equations') (gradF.grade(3)).Fmt(3, '%\\grade{\\nabla F}_{3} = 0') return
def main(): enhance_print() X = (x, y, z) = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=(x, y, z)) A = x*(ey ^ ez) + y*(ez ^ ex) + z*(ex ^ ey) print('A =', A) print('grad^A =', (grad ^ A).simplify()) print() f = MV('f', 'scalar', fct=True) f = (x**2 + y**2 + z**2)**(-1.5) print('f =', f) print('grad*f =', (grad*f).expand()) print() B = f*A print('B =', B) print() Curl_B = grad ^ B print('grad^B =', Curl_B.simplify()) def Symplify(A): return(factor_terms(simplify(A))) print(Curl_B.func(Symplify)) return
def basic_multivector_operations(): Print_Function() (ex, ey, ez) = MV.setup('e*x|y|z') A = MV('A', 'mv') A.Fmt(1, 'A') A.Fmt(2, 'A') A.Fmt(3, 'A') X = MV('X', 'vector') Y = MV('Y', 'vector') print('g_{ij} =\n', MV.metric) 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') (ex, ey) = MV.setup('e*x|y') print('g_{ij} =\n', MV.metric) X = MV('X', 'vector') A = 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') (ex, ey) = MV.setup('e*x|y', metric='[1,1]') print('g_{ii} =\n', MV.metric) X = MV('X', 'vector') A = 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(): Print_Function() (ex, ey, ez) = MV.setup("e*x|y|z") A = MV("A", "mv") A.Fmt(1, "A") A.Fmt(2, "A") A.Fmt(3, "A") X = MV("X", "vector") Y = MV("Y", "vector") print("g_{ij} =\n", MV.metric) 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") (ex, ey) = MV.setup("e*x|y") print("g_{ij} =\n", MV.metric) X = MV("X", "vector") A = 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") (ex, ey) = MV.setup("e*x|y", metric="[1,1]") print("g_{ii} =\n", MV.metric) X = MV("X", "vector") A = 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 Test_Reciprocal_Frame(): Print_Function() Format() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') eu = ex + ey ev = ex - ey (eu_r, ev_r) = ReciprocalFrame([eu, ev]) oprint('\\mbox{Frame}', (eu, ev), '\\mbox{Reciprocal Frame}', (eu_r, ev_r)) print(r'%\bm{e}_{u}\cdot\bm{e}^{u} =', (eu | eu_r)) print(r'%\bm{e}_{u}\cdot\bm{e}^{v} =', eu | ev_r) print(r'%\bm{e}_{v}\cdot\bm{e}^{u} =', ev | eu_r) print(r'%\bm{e}_{v}\cdot\bm{e}^{v} =', ev | ev_r) eu = ex + ey + ez ev = ex - ey (eu_r, ev_r) = ReciprocalFrame([eu, ev]) oprint('\\mbox{Frame}', (eu, ev), '\\mbox{Reciprocal Frame}', (eu_r, ev_r)) print(r'%\bm{e}_{u}\cdot\bm{e}^{u} =', eu | eu_r) print(r'%\bm{e}_{u}\cdot\bm{e}^{v} =', eu | ev_r) print(r'%\bm{e}_{v}\cdot\bm{e}^{u} =', ev | eu_r) print(r'%\bm{e}_{v}\cdot\bm{e}^{v} =', ev | ev_r) return
def Simple_manifold_with_scalar_function_derivative(): Print_Function() coords = (x, y, z) = symbols('x y z') basis = (e1, e2, e3, grad) = MV.setup('e_1 e_2 e_3', metric='[1,1,1]', coords=coords) # Define surface mfvar = (u, v) = symbols('u v') X = u * e1 + v * e2 + (u**2 + v**2) * e3 print('\\f{X}{u,v} =', X) MF = Manifold(X, mfvar) (eu, ev) = MF.Basis() # Define field on the surface. g = (v + 1) * log(u) print('\\f{g}{u,v} =', g) # Method 1: Using old Manifold routines. VectorDerivative = (MF.rbasis[0] / MF.E_sq) * diff( g, u) + (MF.rbasis[1] / MF.E_sq) * diff(g, v) print('\\eval{\\nabla g}{u=1,v=0} =', VectorDerivative.subs({u: 1, v: 0})) # Method 2: Using new Manifold routines. dg = MF.Grad(g) print('\\eval{\\f{Grad}{g}}{u=1,v=0} =', dg.subs({u: 1, v: 0})) dg = MF.grad * g print('\\eval{\\nabla g}{u=1,v=0} =', dg.subs({u: 1, v: 0})) return
def Distorted_manifold_with_scalar_function(): Print_Function() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') X = 2 * u * ex + 2 * v * ey + (u**3 + v**3 / 2) * ez MF = Manifold(X, mfvar, I=MV.I) (eu, ev) = MF.Basis() g = (v + 1) * log(u) dg = MF.Grad(g) print('g =', g) print('dg =', dg) print('\\eval{dg}{u=1,v=0} =', dg.subs({u: 1, v: 0})) G = u * eu + v * ev dG = MF.Grad(G) print('G =', G) print('P(G) =', MF.Proj(G)) print('dG =', dG) print('P(dG) =', MF.Proj(dG)) PS = u * v * eu ^ ev print('P(S) =', PS) print('dP(S) =', MF.Grad(PS)) print('P(dP(S)) =', MF.Proj(MF.Grad(PS))) return
def Simple_manifold_with_vector_function_derivative(): Print_Function() coords = (x, y, z) = symbols('x y z') basis = (ex, ey, ez, grad) = \ MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) # Define surface mfvar = (u, v) = symbols('u v') X = u * ex + v * ey + (u**2 + v**2) * ez print('\\f{X}{u,v} =', X) MF = Manifold(X, mfvar) (eu, ev) = MF.Basis() # Define field on the surface. g = (v + 1) * log(u) print('\\mbox{Scalar Function: } g =', g) dg = MF.grad * g dg.Fmt(3, '\\mbox{Scalar Function Derivative: } \\nabla g') print('\\eval{\\nabla g}{(1,0)} =', dg.subs({u: 1, v: 0})) # Define vector field on the surface G = v**2 * eu + u**2 * ev print('\\mbox{Vector Function: } G =', G) dG = MF.grad * G dG.Fmt(3, '\\mbox{Vector Function Derivative: } \\nabla G') print('\\eval{\\nabla G}{(1,0)} =', dG.subs({u: 1, v: 0})) return
def properties_of_geometric_objects(): Print_Function() metric = '# # # 0 0,' + \ '# # # 0 0,' + \ '# # # 0 0,' + \ '0 0 0 0 2,' + \ '0 0 0 2 0' (p1, p2, p3, n, nbar) = MV.setup('p1 p2 p3 n \\bar{n}', metric) print('g_{ij} =', MV.metric) 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 extracting_vectors_from_conformal_2_blade(): Print_Function() print(r'B = P1\W P2') metric = ' 0 -1 #,' + \ '-1 0 #,' + \ ' # # #,' (P1, P2, a) = MV.setup('P1 P2 a', metric) print('g_{ij} =', MV.metric) 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 Simple_manifold_with_vector_function_derivative(): Print_Function() coords = (x, y, z) = symbols('x y z') basis = (ex, ey, ez, grad) = \ MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) # Define surface mfvar = (u, v) = symbols('u v') X = u*ex + v*ey + (u**2 + v**2)*ez print('\\f{X}{u,v} =', X) MF = Manifold(X, mfvar) (eu, ev) = MF.Basis() # Define field on the surface. g = (v + 1)*log(u) print('\\mbox{Scalar Function: } g =', g) dg = MF.grad*g dg.Fmt(3, '\\mbox{Scalar Function Derivative: } \\nabla g') print('\\eval{\\nabla g}{(1,0)} =', dg.subs({u: 1, v: 0})) # Define vector field on the surface G = v**2*eu + u**2*ev print('\\mbox{Vector Function: } G =', G) dG = MF.grad*G dG.Fmt(3, '\\mbox{Vector Function Derivative: } \\nabla G') print('\\eval{\\nabla G}{(1,0)} =', dG.subs({u: 1, v: 0})) return
def Lorentz_Tranformation_in_Geometric_Algebra(): Print_Function() (alpha, beta, gamma) = symbols('alpha beta gamma') (x, t, xp, tp) = symbols("x t x' t'") (g0, g1) = MV.setup('gamma*t|x', metric='[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([xp, tp]) Xpp = Xpp.subs({ 2 * sinh(alpha / 2) * cosh(alpha / 2): sinh(alpha), sinh(alpha / 2)**2 + cosh(alpha / 2)**2: cosh(alpha) }) 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(gamma)) return
def extracting_vectors_from_conformal_2_blade(): Print_Function() metric = " 0 -1 #," + "-1 0 #," + " # # #," (P1, P2, a) = MV.setup("P1 P2 a", metric) print("g_{ij} =\n", MV.metric) 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 properties_of_geometric_objects(): Print_Function() metric = '# # # 0 0,' + \ '# # # 0 0,' + \ '# # # 0 0,' + \ '0 0 0 0 2,' + \ '0 0 0 2 0' (p1, p2, p3, n, nbar) = MV.setup('p1 p2 p3 n nbar', metric) print('g_{ij} =\n', MV.metric) P1 = F(p1) P2 = F(p2) P3 = F(p3) print('Extracting direction of line from L = P1^P2^n') L = P1 ^ P2 ^ n delta = (L | n) | nbar print('(L|n)|nbar =', delta) print('Extracting plane of circle from C = P1^P2^P3') C = P1 ^ P2 ^ P3 delta = ((C ^ n) | n) | nbar print('((C^n)|n)|nbar =', delta) print('(p2-p1)^(p3-p1) =', (p2 - p1) ^ (p3 - p1))
def Distorted_manifold_with_scalar_function(): Print_Function() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') X = 2*u*ex + 2*v*ey + (u**3 + v**3/2)*ez MF = Manifold(X, mfvar, I=MV.I) (eu, ev) = MF.Basis() g = (v + 1)*log(u) dg = MF.Grad(g) print('g =', g) print('dg =', dg) print('\\eval{dg}{u=1,v=0} =', dg.subs({u: 1, v: 0})) G = u*eu + v*ev dG = MF.Grad(G) print('G =', G) print('P(G) =', MF.Proj(G)) print('dG =', dG) print('P(dG) =', MF.Proj(dG)) PS = u*v*eu ^ ev print('P(S) =', PS) print('dP(S) =', MF.Grad(PS)) print('P(dP(S)) =', MF.Proj(MF.Grad(PS))) return
def check_generalized_BAC_CAB_formulas(): Print_Function() (a, b, c, d, e) = MV.setup('a b c d e') print('g_{ij} =\n', MV.metric) 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 derivatives_in_rectangular_coordinates(): Print_Function() X = (x, y, z) = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=X) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) C = MV('C', 'mv', fct=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) =', -MV.I*(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 derivatives_in_spherical_coordinates(): Print_Function() X = (r, th, phi) = symbols('r theta phi') curv = [[r * cos(phi) * sin(th), r * sin(phi) * sin(th), r * cos(th)], [1, r, r * sin(th)]] (er, eth, ephi, grad) = MV.setup('e_r e_theta e_phi', metric='[1,1,1]', coords=X, curv=curv) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad*f) print('grad|A =', grad | A) print('-I*(grad^A) =', -MV.I*(grad ^ A)) print('grad^B =', grad ^ B) return
def Lorentz_Tranformation_in_Geometric_Algebra(): Print_Function() (alpha, beta, gamma) = symbols('alpha beta gamma') (x, t, xp, tp) = symbols("x t x' t'") (g0, g1) = MV.setup('gamma*t|x', metric='[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([xp, tp]) Xpp = Xpp.subs({2*sinh(alpha/2)*cosh(alpha/2): sinh(alpha), sinh(alpha/2)**2 + cosh(alpha/2)**2: cosh(alpha)}) 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(gamma)) return
def reciprocal_frame_test(): Print_Function() metric = "1 # #," + "# 1 #," + "# # 1," (e1, e2, e3) = MV.setup("e1 e2 e3", metric) print("g_{ij} =\n", MV.metric) 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) w = E1 | e2 w = w.expand() print("E1|e2 =", w) w = E1 | e3 w = w.expand() print("E1|e3 =", w) w = E2 | e1 w = w.expand() print("E2|e1 =", w) w = E2 | e3 w = w.expand() print("E2|e3 =", w) w = E3 | e1 w = w.expand() print("E3|e1 =", w) w = E3 | e2 w = w.expand() print("E3|e2 =", w) w = E1 | e1 w = (w.expand()).scalar() Esq = expand(Esq) print("(E1|e1)/E**2 =", simplify(w / Esq)) w = E2 | e2 w = (w.expand()).scalar() print("(E2|e2)/E**2 =", simplify(w / Esq)) w = E3 | e3 w = (w.expand()).scalar() print("(E3|e3)/E**2 =", simplify(w / Esq)) return
def extracting_vectors_from_conformal_2_blade(): Print_Function() metric = ' 0 -1 #,' + \ '-1 0 #,' + \ ' # # #,' (P1, P2, a) = MV.setup('P1 P2 a', metric) print('g_{ij} =\n', MV.metric) 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 properties_of_geometric_objects(): Print_Function() metric = "# # # 0 0," + "# # # 0 0," + "# # # 0 0," + "0 0 0 0 2," + "0 0 0 2 0" (p1, p2, p3, n, nbar) = MV.setup("p1 p2 p3 n nbar", metric) print("g_{ij} =\n", MV.metric) P1 = F(p1) P2 = F(p2) P3 = F(p3) print("Extracting direction of line from L = P1^P2^n") L = P1 ^ P2 ^ n delta = (L | n) | nbar print("(L|n)|nbar =", delta) print("Extracting plane of circle from C = P1^P2^P3") C = P1 ^ P2 ^ P3 delta = ((C ^ n) | n) | nbar print("((C^n)|n)|nbar =", delta) print("(p2-p1)^(p3-p1) =", (p2 - p1) ^ (p3 - p1))
def Simple_manifold_with_scalar_function_derivative(): Print_Function() coords = (x, y, z) = symbols('x y z') basis = (e1, e2, e3, grad) = MV.setup('e_1 e_2 e_3', metric='[1,1,1]', coords=coords) # Define surface mfvar = (u, v) = symbols('u v') X = u*e1 + v*e2 + (u**2 + v**2)*e3 print('\\f{X}{u,v} =', X) MF = Manifold(X, mfvar) (eu, ev) = MF.Basis() # Define field on the surface. g = (v + 1)*log(u) print('\\f{g}{u,v} =', g) # Method 1: Using old Manifold routines. VectorDerivative = (MF.rbasis[0]/MF.E_sq)*diff(g, u) + (MF.rbasis[1]/MF.E_sq)*diff(g, v) print('\\eval{\\nabla g}{u=1,v=0} =', VectorDerivative.subs({u: 1, v: 0})) # Method 2: Using new Manifold routines. dg = MF.Grad(g) print('\\eval{\\f{Grad}{g}}{u=1,v=0} =', dg.subs({u: 1, v: 0})) dg = MF.grad*g print('\\eval{\\nabla g}{u=1,v=0} =', dg.subs({u: 1, v: 0})) return
def derivatives_in_rectangular_coordinates(): Print_Function() X = (x, y, z) = symbols("x y z") (ex, ey, ez, grad) = MV.setup("e_x e_y e_z", metric="[1,1,1]", coords=X) f = MV("f", "scalar", fct=True) A = MV("A", "vector", fct=True) B = MV("B", "grade2", fct=True) C = MV("C", "mv", fct=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) =", -MV.I * (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 Maxwells_Equations_in_Geometric_Calculus(): Print_Function() X = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=X) I = MV.I B = MV('B', 'vector', fct=True) E = MV('E', 'vector', fct=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 J = MV('J', 'vector', fct=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 = grad*F print('#Geometric 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.grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0') print('#Curl $E$ and Div $B$ equations') (gradF.grade(3)).Fmt(3, '%\\grade{\\nabla F}_{3} = 0') return
def main(): enhance_print() (ex, ey, ez) = MV.setup('e*x|y|z', metric='[1,1,1]') u = MV('u', 'vector') v = MV('v', 'vector') w = MV('w', 'vector') print(u) print(v) uv = u ^ v print(uv) print(uv.is_blade()) exp_uv = uv.exp() exp_uv.Fmt(2, 'exp(uv)') return
def Plot_Mobius_Strip_Manifold(): Print_Function() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') X = (cos(u) + v*cos(u/2)*cos(u))*ex + (sin(u) + v*cos(u/2)*sin(u))*ey + v*sin(u/2)*ez MF = Manifold(X, mfvar, True, I=MV.I) MF.Plot2DSurface([0.0, 6.28, 48], [-0.3, 0.3, 12], surf=False, skip=[4, 4], tan=0.15) return
def make_vector(a, n=3): if isinstance(a, str): sym_str = '' for i in range(n): sym_str += a + str(i + 1) + ' ' sym_lst = list(symbols(sym_str)) sym_lst.append(S.Zero) sym_lst.append(S.Zero) a = MV(sym_lst, 'vector') return (F(a))
def derivatives_in_spherical_coordinates(): Print_Function() X = (r, th, phi) = symbols('r theta phi') curv = [[r*cos(phi)*sin(th), r*sin(phi)*sin(th), r*cos(th)], [1, r, r*sin(th)]] (er, eth, ephi, grad) = MV.setup('e_r e_theta e_phi', metric='[1,1,1]', coords=X, curv=curv) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) print('f =', f) print('A =', A) print('B =', B) print('grad*f =', grad*f) print('grad|A =', grad | A) print('-I*(grad^A) =', -MV.I*(grad ^ A)) print('grad^B =', grad ^ B) return
def rounding_numerical_components(): Print_Function() (ex, ey, ez) = MV.setup('e_x e_y e_z', metric='[1,1,1]') 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 rounding_numerical_components(): Print_Function() (ex, ey, ez) = MV.setup('e_x e_y e_z', metric='[1,1,1]') 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 MV_setup_options(): Print_Function() (e1, e2, e3) = MV.setup('e_1 e_2 e_3', '[1,1,1]') v = MV('v', 'vector') print(v) (e1, e2, e3) = MV.setup('e*1|2|3', '[1,1,1]') v = MV('v', 'vector') print(v) (e1, e2, e3) = MV.setup('e*x|y|z', '[1,1,1]') v = MV('v', 'vector') print(v) coords = symbols('x y z') (e1, e2, e3, grad) = MV.setup('e', '[1,1,1]', coords=coords) v = MV('v', 'vector') print(v) return
def basic_multivector_operations_3D(): Print_Function() (ex, ey, ez) = MV.setup('e*x|y|z') A = 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 = MV('X', 'vector') Y = MV('Y', 'vector') print('g_{ij} = ', MV.metric) 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 rounding_numerical_components(): Print_Function() (ex, ey, ez) = MV.setup("e_x e_y e_z", metric="[1,1,1]") 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 Plot_Mobius_Strip_Manifold(): Print_Function() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') X = (cos(u) + v * cos(u / 2) * cos(u)) * ex + ( sin(u) + v * cos(u / 2) * sin(u)) * ey + v * sin(u / 2) * ez MF = Manifold(X, mfvar, True, I=MV.I) MF.Plot2DSurface([0.0, 6.28, 48], [-0.3, 0.3, 12], surf=False, skip=[4, 4], tan=0.15) return
def check_generalized_BAC_CAB_formulas(): Print_Function() (a, b, c, d) = MV.setup('a b c d') print('g_{ij} =', MV.metric) 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() (ex, ey) = MV.setup('e*x|y') print('g_{ij} =', MV.metric) X = MV('X', 'vector') A = 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() (a, b, c, d, e) = MV.setup('a b c d e') print('g_{ij} =\n', MV.metric) 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 derivatives_in_spherical_coordinates(): Print_Function() X = (r, th, phi) = symbols("r theta phi") curv = [[r * cos(phi) * sin(th), r * sin(phi) * sin(th), r * cos(th)], [1, r, r * sin(th)]] (er, eth, ephi, grad) = MV.setup("e_r e_theta e_phi", metric="[1,1,1]", coords=X, curv=curv) f = MV("f", "scalar", fct=True) A = MV("A", "vector", fct=True) B = MV("B", "grade2", fct=True) print("f =", f) print("A =", A) print("B =", B) print("grad*f =", grad * f) print("grad|A =", grad | A) print("-I*(grad^A) =", -MV.I * (grad ^ A)) print("grad^B =", grad ^ B) return
def check_generalized_BAC_CAB_formulas(): Print_Function() (a, b, c, d) = MV.setup('a b c d') print('g_{ij} =', MV.metric) 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 Dirac_Equation_in_Geometric_Calculus(): Print_Function() vars = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars) I = MV.I (m, e) = symbols('m e') psi = MV('psi', 'spinor', fct=True) A = MV('A', 'vector', fct=True) sig_z = g3*g0 print('\\text{4-Vector Potential\\;\\;}\\bm{A} =', A) print('\\text{8-component real spinor\\;\\;}\\bm{\\psi} =', psi) dirac_eq = (grad*psi)*I*sig_z - e*A*psi - m*psi*g0 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 conformal_representations_of_circles_lines_spheres_and_planes(): global n, nbar Print_Function() metric = '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' (e1, e2, e3, n, nbar) = MV.setup('e_1 e_2 e_3 n nbar', metric) print('g_{ij} =\n', MV.metric) e = n + nbar # conformal representation of points A = make_vector(e1) # point a = (1,0,0) A = F(a) B = make_vector(e2) # point b = (0,1,0) B = F(b) C = make_vector(-e1) # point c = (-1,0,0) C = F(c) D = make_vector(e3) # point d = (0,0,1) D = F(d) X = make_vector('x', 3) 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 conformal_representations_of_circles_lines_spheres_and_planes(): global n, nbar Print_Function() metric = '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' (e1, e2, e3, n, nbar) = MV.setup('e_1 e_2 e_3 n nbar', metric) print('g_{ij} =\n', MV.metric) e = n + nbar #conformal representation of points A = make_vector(e1) # point a = (1,0,0) A = F(a) B = make_vector(e2) # point b = (0,1,0) B = F(b) C = make_vector(-e1) # point c = (-1,0,0) C = F(c) D = make_vector(e3) # point d = (0,0,1) D = F(d) X = make_vector('x', 3) 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 main(): enhance_print() coords = symbols('x y z') (ex, ey, ez, grad) = MV.setup('ex ey ez', metric='[1,1,1]', coords=coords) mfvar = (u, v) = symbols('u v') eu = ex + ey ev = ex - ey (eu_r, ev_r) = 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) = 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) define_precedence(locals()) print(GAeval('eu^ev|ex', True)) print(GAeval('eu^ev|ex*eu', True)) return
def conformal_representations_of_circles_lines_spheres_and_planes(): global n, nbar Print_Function() metric = "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" (e1, e2, e3, n, nbar) = MV.setup("e_1 e_2 e_3 n nbar", metric) print("g_{ij} =\n", MV.metric) e = n + nbar # conformal representation of points A = make_vector(e1) # point a = (1,0,0) A = F(a) B = make_vector(e2) # point b = (0,1,0) B = F(b) C = make_vector(-e1) # point c = (-1,0,0) C = F(c) D = make_vector(e3) # point d = (0,0,1) D = F(d) X = make_vector("x", 3) 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 basic_multivector_operations_2D_orthogonal(): Print_Function() (ex, ey) = MV.setup('e*x|y', metric='[1,1]') print('g_{ii} =', MV.metric) X = MV('X', 'vector') A = 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 main(): Format() (ex, ey, ez) = MV.setup('e*x|y|z') A = 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') (ex, ey, ez, grad) = MV.setup('e_x e_y e_z', metric='[1,1,1]', coords=X) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) print(r'\bm{A} =', A) print(r'\bm{B} =', B) print('grad*f =', grad * f) print(r'grad|\bm{A} =', grad | A) print(r'grad*\bm{A} =', grad * A) print(r'-I*(grad^\bm{A}) =', -MV.I * (grad ^ A)) print(r'grad*\bm{B} =', grad * B) print(r'grad^\bm{B} =', grad ^ B) print(r'grad|\bm{B} =', grad | B) (a, b, c, d) = MV.setup('a b c d') print('g_{ij} =', MV.metric) 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)) metric = '1 # #,' + \ '# 1 #,' + \ '# # 1,' (e1, e2, e3) = MV.setup('e1 e2 e3', metric) 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') curv = [[r * cos(phi) * sin(th), r * sin(phi) * sin(th), r * cos(th)], [1, r, r * sin(th)]] (er, eth, ephi, grad) = MV.setup('e_r e_theta e_phi', metric='[1,1,1]', coords=X, curv=curv) f = MV('f', 'scalar', fct=True) A = MV('A', 'vector', fct=True) B = MV('B', 'grade2', fct=True) print('A =', A) print('B =', B) print('grad*f =', grad * f) print('grad|A =', grad | A) print('-I*(grad^A) =', -MV.I * (grad ^ A)) print('grad^B =', grad ^ B) vars = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars) I = MV.I B = MV('B', 'vector', fct=True) E = MV('E', 'vector', fct=True) B.set_coef(1, 0, 0) E.set_coef(1, 0, 0) B *= g0 E *= g0 J = MV('J', 'vector', fct=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 = grad * F gradF.Fmt(3, 'grad*F') print('grad*F = J') (gradF.grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0') (gradF.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'") (g0, g1) = MV.setup('gamma*t|x', metric='[1,-1]') 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([xp, tp]) Xpp = Xpp.subs({ 2 * sinh(alpha / 2) * cosh(alpha / 2): sinh(alpha), sinh(alpha / 2)**2 + cosh(alpha / 2)**2: cosh(alpha) }) 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(gamma)) vars = symbols('t x y z') (g0, g1, g2, g3, grad) = MV.setup('gamma*t|x|y|z', metric='[1,-1,-1,-1]', coords=vars) I = MV.I (m, e) = symbols('m e') psi = MV('psi', 'spinor', fct=True) A = MV('A', 'vector', fct=True) sig_z = g3 * g0 print('\\bm{A} =', A) print('\\bm{\\psi} =', psi) dirac_eq = (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' ) xdvi() return
def reciprocal_frame_test(): Print_Function() metric = '1 # #,' + \ '# 1 #,' + \ '# # 1,' (e1, e2, e3) = MV.setup('e1 e2 e3', metric) print('g_{ij} =\n', MV.metric) 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) w = (E1 | e2) w = w.expand() print('E1|e2 =', w) w = (E1 | e3) w = w.expand() print('E1|e3 =', w) w = (E2 | e1) w = w.expand() print('E2|e1 =', w) w = (E2 | e3) w = w.expand() print('E2|e3 =', w) w = (E3 | e1) w = w.expand() print('E3|e1 =', w) w = (E3 | e2) w = w.expand() print('E3|e2 =', w) w = (E1 | e1) w = (w.expand()).scalar() Esq = expand(Esq) print('(E1|e1)/E**2 =', simplify(w / Esq)) w = (E2 | e2) w = (w.expand()).scalar() print('(E2|e2)/E**2 =', simplify(w / Esq)) w = (E3 | e3) w = (w.expand()).scalar() print('(E3|e3)/E**2 =', simplify(w / Esq)) return
def noneuclidian_distance_calculation(): Print_Function() from sympy import solve, sqrt metric = '0 # #,# 0 #,# # 1' (X, Y, e) = MV.setup('X Y e', metric) print('g_{ij} =', MV.metric) print('%(X\\W Y)^{2} =', (X ^ Y) * (X ^ Y)) L = X ^ Y ^ e B = L * e # D&L 10.152 Bsq = (B * B).scalar() print('#%L = X\\W Y\\W e \\text{ is a non-euclidian line}') print('B = L*e =', B) BeBr = B * e * B.rev() print('%BeB^{\\dagger} =', BeBr) print('%B^{2} =', B * B) print('%L^{2} =', L * L) # D&L 10.153 (s, c, Binv, M, BigS, BigC, alpha, XdotY, Xdote, Ydote) = symbols('s c (1/B) M S C alpha (X.Y) (X.e) (Y.e)') Bhat = Binv * B # D&L 10.154 R = c + s * Bhat # Rotor R = exp(alpha*Bhat/2) print( '#%s = \\f{\\sinh}{\\alpha/2} \\text{ and } c = \\f{\\cosh}{\\alpha/2}' ) print('%e^{\\alpha B/{2\\abs{B}}} =', R) Z = R * X * R.rev() # D&L 10.155 Z.obj = expand(Z.obj) Z.obj = Z.obj.collect([Binv, s, c, XdotY]) Z.Fmt(3, '%RXR^{\\dagger}') W = Z | Y # Extract scalar part of multivector # From this point forward all calculations are with sympy scalars # print '#Objective is to determine value of C = cosh(alpha) such that W = 0' W = W.scalar() print('%W = Z\\cdot Y =', W) W = expand(W) W = simplify(W) W = W.collect([s * Binv]) M = 1 / Bsq W = W.subs(Binv**2, M) W = simplify(W) Bmag = sqrt(XdotY**2 - 2 * XdotY * Xdote * Ydote) W = W.collect([Binv * c * s, XdotY]) # Double angle substitutions W = W.subs(2 * XdotY**2 - 4 * XdotY * Xdote * Ydote, 2 / (Binv**2)) W = W.subs(2 * c * s, BigS) W = W.subs(c**2, (BigC + 1) / 2) W = W.subs(s**2, (BigC - 1) / 2) W = simplify(W) W = W.subs(1 / Binv, Bmag) W = expand(W) print('#%S = \\f{\\sinh}{\\alpha} \\text{ and } C = \\f{\\cosh}{\\alpha}') print('W =', W) Wd = collect(W, [BigC, BigS], exact=True, evaluate=False) Wd_1 = Wd[S.One] Wd_C = Wd[BigC] Wd_S = Wd[BigS] print('%\\text{Scalar Coefficient} =', Wd_1) print('%\\text{Cosh Coefficient} =', Wd_C) print('%\\text{Sinh Coefficient} =', Wd_S) print('%\\abs{B} =', Bmag) Wd_1 = Wd_1.subs(Bmag, 1 / Binv) Wd_C = Wd_C.subs(Bmag, 1 / Binv) Wd_S = Wd_S.subs(Bmag, 1 / Binv) lhs = Wd_1 + Wd_C * BigC rhs = -Wd_S * BigS lhs = lhs**2 rhs = rhs**2 W = expand(lhs - rhs) W = expand(W.subs(1 / Binv**2, Bmag**2)) W = expand(W.subs(BigS**2, BigC**2 - 1)) W = W.collect([BigC, BigC**2], evaluate=False) a = simplify(W[BigC**2]) b = simplify(W[BigC]) c = simplify(W[S.One]) print('#%\\text{Require } aC^{2}+bC+c = 0') print('a =', a) print('b =', b) print('c =', c) x = Symbol('x') C = solve(a * x**2 + b * x + c, x)[0] print('%b^{2}-4ac =', simplify(b**2 - 4 * a * c)) print('%\\f{\\cosh}{\\alpha} = C = -b/(2a) =', expand(simplify(expand(C)))) return
def noneuclidian_distance_calculation(): from sympy import solve, sqrt Print_Function() metric = '0 # #,# 0 #,# # 1' (X, Y, e) = MV.setup('X Y e', metric) print('g_{ij} =', MV.metric) print('(X^Y)**2 =', (X ^ Y) * (X ^ Y)) L = X ^ Y ^ e B = L * e # D&L 10.152 print('B =', B) Bsq = B * B print('B**2 =', Bsq) Bsq = Bsq.scalar() print('#L = X^Y^e is a non-euclidian line') print('B = L*e =', B) BeBr = B * e * B.rev() print('B*e*B.rev() =', BeBr) print('B**2 =', B * B) print('L**2 =', L * L) # D&L 10.153 (s, c, Binv, M, BigS, BigC, alpha, XdotY, Xdote, Ydote) = symbols('s c (1/B) M S C alpha (X.Y) (X.e) (Y.e)') Bhat = Binv * B # D&L 10.154 R = c + s * Bhat # Rotor R = exp(alpha*Bhat/2) print('s = sinh(alpha/2) and c = cosh(alpha/2)') print('exp(alpha*B/(2*|B|)) =', R) Z = R * X * R.rev() # D&L 10.155 Z.obj = expand(Z.obj) Z.obj = Z.obj.collect([Binv, s, c, XdotY]) Z.Fmt(3, 'R*X*R.rev()') W = Z | Y # Extract scalar part of multivector # From this point forward all calculations are with sympy scalars print('Objective is to determine value of C = cosh(alpha) such that W = 0') W = W.scalar() print('Z|Y =', W) W = expand(W) W = simplify(W) W = W.collect([s * Binv]) M = 1 / Bsq W = W.subs(Binv**2, M) W = simplify(W) Bmag = sqrt(XdotY**2 - 2 * XdotY * Xdote * Ydote) W = W.collect([Binv * c * s, XdotY]) #Double angle substitutions W = W.subs(2 * XdotY**2 - 4 * XdotY * Xdote * Ydote, 2 / (Binv**2)) W = W.subs(2 * c * s, BigS) W = W.subs(c**2, (BigC + 1) / 2) W = W.subs(s**2, (BigC - 1) / 2) W = simplify(W) W = W.subs(1 / Binv, Bmag) W = expand(W) print('S = sinh(alpha) and C = cosh(alpha)') print('W =', W) Wd = collect(W, [BigC, BigS], exact=True, evaluate=False) Wd_1 = Wd[S.One] Wd_C = Wd[BigC] Wd_S = Wd[BigS] print('Scalar Coefficient =', Wd_1) print('Cosh Coefficient =', Wd_C) print('Sinh Coefficient =', Wd_S) print('|B| =', Bmag) Wd_1 = Wd_1.subs(Bmag, 1 / Binv) Wd_C = Wd_C.subs(Bmag, 1 / Binv) Wd_S = Wd_S.subs(Bmag, 1 / Binv) lhs = Wd_1 + Wd_C * BigC rhs = -Wd_S * BigS lhs = lhs**2 rhs = rhs**2 W = expand(lhs - rhs) W = expand(W.subs(1 / Binv**2, Bmag**2)) W = expand(W.subs(BigS**2, BigC**2 - 1)) W = W.collect([BigC, BigC**2], evaluate=False) a = simplify(W[BigC**2]) b = simplify(W[BigC]) c = simplify(W[S.One]) print('Require a*C**2+b*C+c = 0') print('a =', a) print('b =', b) print('c =', c) x = Symbol('x') C = solve(a * x**2 + b * x + c, x)[0] print('cosh(alpha) = C = -b/(2*a) =', expand(simplify(expand(C)))) return
def basic_multivector_operations(): Print_Function() (ex, ey, ez) = MV.setup('e*x|y|z') A = MV('A', 'mv') A.Fmt(1, 'A') A.Fmt(2, 'A') A.Fmt(3, 'A') X = MV('X', 'vector') Y = MV('Y', 'vector') print('g_{ij} =\n', MV.metric) 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') (ex, ey) = MV.setup('e*x|y') print('g_{ij} =\n', MV.metric) X = MV('X', 'vector') A = 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') (ex, ey) = MV.setup('e*x|y', metric='[1,1]') print('g_{ii} =\n', MV.metric) X = MV('X', 'vector') A = 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 main(): Format() coords = (x, y, z) = symbols('x y z') (ex, ey, ez, grad) = MV.setup('e*x|y|z', '[1,1,1]', coords=coords) s = MV('s', 'scalar') v = MV('v', 'vector') b = 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]) 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 = MV('s', 'scalar', fct=True) fv = MV('v', 'vector', fct=True) fb = MV('b', 'bivector', fct=True) print('#Multivector Functions:') print('s(X) =', fs) print('v(X) =', fv) print('b(X) =', fb) print('#Products:') fX = ((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]) 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]) (ex, ey, grad) = MV.setup('e', coords=(x, y)) print(r'#General 2D Metric\newline') print('#Multivector Functions:') s = MV('s', 'scalar', fct=True) v = MV('v', 'vector', fct=True) b = MV('v', 'bivector', fct=True) print('s(X) =', s) print('v(X) =', v) print('b(X) =', b) X = ((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]) 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]) xdvi(paper='letter') return
def basic_multivector_operations_3D(): Print_Function() (ex, ey, ez) = MV.setup('e*x|y|z') print('g_{ij} =', MV.metric) A = 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 = MV('X', 'vector') Y = 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