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 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') 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(-MV.I) print('-I*(grad^A) =',-MV.I*(grad^A)) print('grad*B =',grad*B) print('grad^B =',grad^B) print('grad|B =',grad|B) 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 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 extracting_vectors_from_conformal_2_blade(): global n,nbar 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(): global n,nbar 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 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() 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()) return
def properties_of_geometric_objects(): global n,nbar 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 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 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)).simplify()) print('grad^B =',grad^B)
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(ZERO) sym_lst.append(ZERO) a = MV(sym_lst,'vector') return(F(a))
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 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) print(w) uv = u ^ v print(uv) print(uv.is_blade()) uvw = u ^ v ^ w print(uvw) print(uvw.is_blade()) print(simplify((uv * uv).scalar())) 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)} =',Ga.com(a^b,c^d)) return
def basic_multivector_operations_2D(): (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 MV_setup_options(): (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 check_generalized_BAC_CAB_formulas(): (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) =',Ga.com(a^b,c^d)) print('(a|(b^c))|(d^e) =',(a|(b^c))|(d^e)) 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) def_prec(locals()) print(GAeval('eu^ev|ex', True)) print(GAeval('eu^ev|ex*eu', True)) 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 reciprocal_frame_test(): Print_Function() metric = '1 # #,'+ \ '# 1 #,'+ \ '# # 1' (e1,e2,e3) = MV.setup('e1 e2 e3',metric) print('g_{ij} =',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\\cdot e1)/E^{2} =',simplify(w/Esq)) w = (E2|e2) w = (w.expand()).scalar() print('%(E2\\cdot e2)/E^{2} =',simplify(w/Esq)) w = (E3|e3) w = (w.expand()).scalar() print('%(E3\\cdot e3)/E^{2} =',simplify(w/Esq)) 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]) 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 = 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]) 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]) (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]) 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]) #xdvi(paper='letter') 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,S,C,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,S) W = W.subs(c**2,(C+1)/2) W = W.subs(s**2,(C-1)/2) W = simplify(W) W = W.subs(Binv,1/Bmag) W = expand(W) print('#%S = \\f{\\sinh}{\\alpha} \\text{ and } C = \\f{\\cosh}{\\alpha}') print('W =',W) Wd = collect(W,[C,S],exact=True,evaluate=False) Wd_1 = Wd[ONE] Wd_C = Wd[C] Wd_S = Wd[S] 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*C rhs = -Wd_S*S lhs = lhs**2 rhs = rhs**2 W = expand(lhs-rhs) W = expand(W.subs(1/Binv**2,Bmag**2)) W = expand(W.subs(S**2,C**2-1)) W = W.collect([C,C**2],evaluate=False) a = simplify(W[C**2]) b = simplify(W[C]) c = simplify(W[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
from __future__ import print_function from sympy import S from galgebra.printer import xdvi, Get_Program, Print_Function, Format from galgebra.deprecated import MV (ex, ey, ez) = MV.setup('e_x e_y e_z', metric='[1,1,1]') v = S(3) * ex + S(4) * ey print(v) print(v.norm()) print(v.norm2()) print(v / v.norm()) print(v / (v.norm()**2)) print(v * (v / v.norm2())) print(v.inv())
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, S, C, 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, S) W = W.subs(c**2, (C + 1) / 2) W = W.subs(s**2, (C - 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, [C, S], exact=True, evaluate=False) Wd_1 = Wd[ONE] Wd_C = Wd[C] Wd_S = Wd[S] 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 * C rhs = -Wd_S * S lhs = lhs**2 rhs = rhs**2 W = expand(lhs - rhs) W = expand(W.subs(1 / Binv**2, Bmag**2)) W = expand(W.subs(S**2, C**2 - 1)) W = W.collect([C, C**2], evaluate=False) a = simplify(W[C**2]) b = simplify(W[C]) c = simplify(W[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
from __future__ import print_function from sympy import * from galgebra.ga import Ga from galgebra.deprecated import MV from galgebra.printer import Format, xpdf, Fmt Format() ew, ex, ey, ez = MV.setup('e_w e_x e_y e_z', metric=[1, 1, 1, 1]) a = MV('a', 'vector') a.set_coef(1, 0, 0) b = ex + ey + ez c = MV('c', 'vector') print('a =', a) print('b =', b) print('c =', c) print(a.reflect_in_blade(ex ^ ey).Fmt(1, 'a\\mbox{ reflect in }xy')) print(a.reflect_in_blade(ey ^ ez).Fmt(1, 'a\\mbox{ reflect in }yz')) print(a.reflect_in_blade(ez ^ ex).Fmt(1, 'a\\mbox{ reflect in }zx')) print( a.reflect_in_blade(ez ^ (ex + ey)).Fmt(1, 'a\\mbox{ reflect in plane }(x=y)')) print( b.reflect_in_blade((ez - ey) ^ (ex - ey)).Fmt( 1, 'b\\mbox{ reflect in plane }(x+y+z=0)')) print(a.reflect_in_blade(ex).Fmt(1, '\\mbox{Reflect in }\\bm{e}_{x}')) print(a.reflect_in_blade(ey).Fmt(1, '\\mbox{Reflect in }\\bm{e}_{y}')) print(a.reflect_in_blade(ez).Fmt(1, '\\mbox{Reflect in }\\bm{e}_{z}'))
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_3D(): (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
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)} =', Ga.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() 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()) 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' ) # xpdf() xpdf(pdfprog=None) return