Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
    def test_3_2_2(self):
        """
        Computing the contraction explicitly.
        """

        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)]
        C_blades = [R.mv('C', i, 'grade') for i in range(R.n + 1)]

        # scalar and blades of various grades
        A = A_blades[0]
        for B in B_blades:
            self.assertEquals(A < B, A * B)

        A = A_blades[0]
        for B in B_blades:
            self.assertEquals(B < A, 0 if B.pure_grade() > 0 else A * B)

        # vectors
        A = A_blades[1]
        B = B_blades[1]
        self.assertEquals(A < B, A | B)

        # vector and the outer product of 2 blades of various grades (scalars, vectors, 2-vectors...)
        A = A_blades[1]
        for B, C in product(B_blades, C_blades):
            self.assertEquals(A < (B ^ C), ((A < B) ^ C) + (-1)**B.pure_grade() * (B ^ (A < C)))

        # vector and the outer product of 2 blades of various grades (scalars, vectors, 2-vectors...)
        for A, B, C in product(A_blades, B_blades, C_blades):
            self.assertEquals((A ^ B) < C, A < (B < C))

        # distributive properties
        for A, B, C in product(A_blades, B_blades, C_blades):
            self.assertEquals((A + B) < C, (A < C) + (B < C))

        for A, B, C in product(A_blades, B_blades, C_blades):
            self.assertEquals(A < (B + C), (A < B) + (A < C))

        alpha = Symbol("alpha")
        for A, B in product(A_blades, B_blades):
            self.assertEquals((alpha * A) < B, alpha * (A < B))
            self.assertEquals((alpha * A) < B, A < (alpha * B))

        a = R.mv('a', 1, 'grade')
        for A_minus1, B in product(A_blades[:-1], B_blades):
            A = A_minus1 ^ a
            self.assertEquals(A < B, (A_minus1 ^ a) < B)
            self.assertEquals(A < B, A_minus1 < (a < B))
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
    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))
Exemple #10
0
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
Exemple #11
0
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
Exemple #12
0
    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())
Exemple #13
0
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
Exemple #14
0
    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())
Exemple #15
0
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
Exemple #16
0
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
Exemple #17
0
    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)
Exemple #18
0
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
Exemple #19
0
def making_a_circle():
    Print_Function()
    global n, nbar
    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()
    e = n + nbar

    A=make_vector(e1/2,ga=c3d)
    B=make_vector(2*e1,ga=c3d)
    C=make_vector((4.0/5)*e1 + (3.0/5)*e2,ga=c3d)

    A=8*A
    B=2*B
    C=10*C

    print 'F(a) = ',A
    print 'F(b) = ',B
    print 'F(c) = ',C
    print '#Circle through a,b,c'

    print 'A^B = ',(A^B)/3
    print '#Circle triveector:'
    print '(A^B)^C = ',A^B^C
    print 'B^C = ', (B^C)/3
    print '#The same circle trivector as before, different computation order and scaled: '
    print 'A^(B^C) = ',(A^B^C)/18
    print '#Haven\'t figured out how to format the coefficients nicely'
    print '# Are A,B,C all on the line? Let\'s check one:'
    print 'A^B^C^D =',A^B^C^C

    return
Exemple #20
0
def noneuclidian_distance_calculation():
    Print_Function()
    from sympy import solve,sqrt

    g = '0 # #,# 0 #,# # 1'
    nel = Ga('X Y e',g=g)
    (X,Y,e) = nel.mv()

    print 'g_{ij} =',nel.g

    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) = symbols('s c (1/B) M S C alpha')

    XdotY = nel.g[0,1]
    Xdote = nel.g[0,2]
    Ydote = nel.g[1,2]

    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(1/Binv,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
Exemple #21
0
def norm(X):
    Y = sqrt((X * X).scalar())
    return Y


Get_Program(True)
Eprint()

g = '1 0 0 0, \
   0 1 0 0, \
   0 0 0 2, \
   0 0 2 0'

c2d = Ga('e_1 e_2 n \\bar{n}', g=g)
(e1, e2, n, nbar) = c2d.mv()

global n, nbar, I


def F(x):
    global n, nbar
    Fx = ((x * x) * n + 2 * x - nbar) / 2
    return (Fx)


e = (n + nbar) / 2
ebar = n - e
I = e1 * e2 * e * ebar

Exemple #22
0
print('B =', B2d)
print('A + B =', A2d + B2d)
print('AB =', A2d * B2d)
print('A - B =', A2d - B2d)

a = g2d.mv('a', 'vector')
b = g2d.mv('b', 'vector')

print(r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =',
      ((a | A2d.adj()(b)) - (b | A2d(a))).simplify())

m4d = Ga('e_t e_x e_y e_z',
         g=[1, -1, -1, -1],
         coords=symbols('t,x,y,z', real=True))

T = m4d.lt('T')

print('#$T$ is a linear transformation in Minkowski space')
print(r'\underline{T} =', T)
print(r'\overline{T} =', T.adj())
print(r'\f{\mbox{tr}}{\underline{T}} =', T.tr())

a = m4d.mv('a', 'vector')
b = m4d.mv('b', 'vector')

print(r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =',
      ((a | T.adj()(b)) - (b | T(a))).simplify())

xpdf(paper='landscape', crop=True)
Exemple #23
0
def noneuclidian_distance_calculation():
    from sympy import solve,sqrt
    Print_Function()

    g = '0 # #,# 0 #,# # 1'
    necl = Ga('X Y e',g=g)
    (X,Y,e) = necl.mv()

    print('g_{ij} =',necl.g)

    print('(X^Y)**2 =',(X^Y)*(X^Y))

    L = X^Y^e
    B = (L*e).expand().blade_rep() # D&L 10.152
    print('B =',B)
    Bsq = B*B
    print('B**2 =',Bsq.obj)
    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) = symbols('s c (1/B) M S C alpha')

    XdotY = necl.g[0,1]
    Xdote = necl.g[0,2]
    Ydote = necl.g[1,2]

    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])
    print(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)
    print('Wd =', Wd)
    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
Exemple #24
0
def basic_multivector_operations():
    Print_Function()
    g3d = Ga('e*x|y|z')
    (ex, ey, ez) = g3d.mv()

    A = g3d.mv('A', 'mv')

    print(A.Fmt(1, 'A'))
    print(A.Fmt(2, 'A'))
    print(A.Fmt(3, 'A'))

    X = g3d.mv('X', 'vector')
    Y = g3d.mv('Y', 'vector')

    print('g_{ij} =\n', g3d.g)

    print(X.Fmt(1, 'X'))
    print(Y.Fmt(1, 'Y'))

    print((X * Y).Fmt(2, 'X*Y'))
    print((X ^ Y).Fmt(2, 'X^Y'))
    print((X | Y).Fmt(2, 'X|Y'))

    g2d = Ga('e*x|y')

    (ex, ey) = g2d.mv()

    print('g_{ij} =\n', 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'))

    o2d = Ga('e*x|y', g=[1, 1])

    (ex, ey) = o2d.mv()

    print('g_{ii} =\n', 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 main():
    Format()
    (g3d, ex, ey, ez) = Ga.build('e*x|y|z')
    A = g3d.mv('A', 'mv')
    print r'\bm{A} =', A
    A.Fmt(2, r'\bm{A}')
    A.Fmt(3, r'\bm{A}')

    X = (x, y, z) = symbols('x y z', real=True)
    o3d = Ga('e_x e_y e_z', g=[1, 1, 1], coords=X)
    (ex, ey, ez) = o3d.mv()

    f = o3d.mv('f', 'scalar', f=True)
    A = o3d.mv('A', 'vector', f=True)
    B = o3d.mv('B', 'bivector', f=True)

    print r'\bm{A} =', A
    print r'\bm{B} =', B

    print 'grad*f =', o3d.grad * f
    print r'grad|\bm{A} =', o3d.grad | A
    print r'grad*\bm{A} =', o3d.grad * A

    print r'-I*(grad^\bm{A}) =', -o3d.i * (o3d.grad ^ A)
    print r'grad*\bm{B} =', o3d.grad * B
    print r'grad^\bm{B} =', o3d.grad ^ B
    print r'grad|\bm{B} =', o3d.grad | B

    g4d = Ga('a b c d')

    (a, b, c, d) = g4d.mv()

    print 'g_{ij} =', g4d.g

    print '\\bm{a|(b*c)} =', a | (b * c)
    print '\\bm{a|(b^c)} =', a | (b ^ c)
    print '\\bm{a|(b^c^d)} =', a | (b ^ c ^ d)
    print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =', (a |
                                              (b ^ c)) + (c |
                                                          (a ^ b)) + (b |
                                                                      (c ^ a))
    print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =', a * (b ^ c) - b * (a ^ c) + c * (
        a ^ b)
    print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =', a * (
        b ^ c ^ d) - b * (a ^ c ^ d) + c * (a ^ b ^ d) - d * (a ^ b ^ c)
    print '\\bm{(a^b)|(c^d)} =', (a ^ b) | (c ^ d)
    print '\\bm{((a^b)|c)|d} =', ((a ^ b) | c) | d
    print '\\bm{(a^b)\\times (c^d)} =', com(a ^ b, c ^ d)

    g = '1 # #,'+ \
         '# 1 #,'+ \
         '# # 1'

    ng3d = Ga('e1 e2 e3', g=g)
    (e1, e2, e3) = ng3d.mv()

    E = e1 ^ e2 ^ e3
    Esq = (E * E).scalar()
    print 'E =', E
    print '%E^{2} =', Esq
    Esq_inv = 1 / Esq

    E1 = (e2 ^ e3) * E
    E2 = (-1) * (e1 ^ e3) * E
    E3 = (e1 ^ e2) * E

    print 'E1 = (e2^e3)*E =', E1
    print 'E2 =-(e1^e3)*E =', E2
    print 'E3 = (e1^e2)*E =', E3

    print 'E1|e2 =', (E1 | e2).expand()
    print 'E1|e3 =', (E1 | e3).expand()
    print 'E2|e1 =', (E2 | e1).expand()
    print 'E2|e3 =', (E2 | e3).expand()
    print 'E3|e1 =', (E3 | e1).expand()
    print 'E3|e2 =', (E3 | e2).expand()
    w = ((E1 | e1).expand()).scalar()
    Esq = expand(Esq)
    print '%(E1\\cdot e1)/E^{2} =', simplify(w / Esq)
    w = ((E2 | e2).expand()).scalar()
    print '%(E2\\cdot e2)/E^{2} =', simplify(w / Esq)
    w = ((E3 | e3).expand()).scalar()
    print '%(E3\\cdot e3)/E^{2} =', simplify(w / Esq)

    X = (r, th, phi) = symbols('r theta phi')
    s3d = Ga('e_r e_theta e_phi',
             g=[1, r**2, r**2 * sin(th)**2],
             coords=X,
             norm=True)
    (er, eth, ephi) = s3d.mv()

    f = s3d.mv('f', 'scalar', f=True)
    A = s3d.mv('A', 'vector', f=True)
    B = s3d.mv('B', 'bivector', f=True)

    print 'A =', A
    print 'B =', B

    print 'grad*f =', s3d.grad * f
    print 'grad|A =', s3d.grad | A
    print '-I*(grad^A) =', -s3d.i * (s3d.grad ^ A)
    print 'grad^B =', s3d.grad ^ B

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z', g=[1, -1, -1, -1], coords=coords)
    (g0, g1, g2, g3) = m4d.mv()
    I = m4d.i

    B = m4d.mv('B', 'vector', f=True)
    E = m4d.mv('E', 'vector', f=True)
    B.set_coef(1, 0, 0)
    E.set_coef(1, 0, 0)
    B *= g0
    E *= g0
    J = m4d.mv('J', 'vector', f=True)
    F = E + I * B

    print 'B = \\bm{B\\gamma_{t}} =', B
    print 'E = \\bm{E\\gamma_{t}} =', E
    print 'F = E+IB =', F
    print 'J =', J
    gradF = m4d.grad * F
    gradF.Fmt(3, 'grad*F')

    print 'grad*F = J'
    (gradF.get_grade(1) - J).Fmt(3, '%\\grade{\\nabla F}_{1} -J = 0')
    (gradF.get_grade(3)).Fmt(3, '%\\grade{\\nabla F}_{3} = 0')

    (alpha, beta, gamma) = symbols('alpha beta gamma')

    (x, t, xp, tp) = symbols("x t x' t'")
    m2d = Ga('gamma*t|x', g=[1, -1])
    (g0, g1) = m2d.mv()

    R = cosh(alpha / 2) + sinh(alpha / 2) * (g0 ^ g1)
    X = t * g0 + x * g1
    Xp = tp * g0 + xp * g1
    print 'R =', R

    print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}"

    Xpp = R * Xp * R.rev()
    Xpp = Xpp.collect()
    Xpp = Xpp.trigsimp()
    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp
    Xpp = Xpp.subs({sinh(alpha): gamma * beta, cosh(alpha): gamma})

    print r'%\f{\sinh}{\alpha} = \gamma\beta'
    print r'%\f{\cosh}{\alpha} = \gamma'

    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =", Xpp.collect()

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z', g=[1, -1, -1, -1], coords=coords)
    (g0, g1, g2, g3) = m4d.mv()
    I = m4d.i
    (m, e) = symbols('m e')

    psi = m4d.mv('psi', 'spinor', f=True)
    A = m4d.mv('A', 'vector', f=True)
    sig_z = g3 * g0
    print '\\bm{A} =', A
    print '\\bm{\\psi} =', psi

    dirac_eq = (m4d.grad * psi) * I * sig_z - e * A * psi - m * psi * g0
    dirac_eq.simplify()

    dirac_eq.Fmt(
        3,
        r'\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0'
    )

    xpdf()
    return
Exemple #26
0
def main():
    Print_Function()

    (x, y, z) = xyz = symbols('x,y,z',real=True)
    (o3d, ex, ey, ez) = Ga.build('e_x e_y e_z', g=[1, 1, 1], coords=xyz)
    grad = o3d.grad

    (u, v) = uv = symbols('u,v',real=True)
    (g2d, eu, ev) = Ga.build('e_u e_v', coords=uv)
    grad_uv = g2d.grad

    v_xyz = o3d.mv('v','vector')
    A_xyz = o3d.mv('A','vector',f=True)
    A_uv = g2d.mv('A','vector',f=True)

    print '#3d orthogonal ($A$ is vector function)'
    print 'A =', A_xyz
    print '%A^{2} =', A_xyz * A_xyz
    print 'grad|A =', grad | A_xyz
    print 'grad*A =', grad * A_xyz

    print 'v|(grad*A) =',v_xyz|(grad*A_xyz)

    print '#2d general ($A$ is vector function)'
    print 'A =', A_uv
    print '%A^{2} =', A_uv * A_uv
    print 'grad|A =', grad_uv | A_uv
    print 'grad*A =', grad_uv * A_uv

    A = o3d.lt('A')

    print '#3d orthogonal ($A,\\;B$ are linear transformations)'
    print 'A =', A
    print r'\f{mat}{A} =', A.matrix()
    print '\\f{\\det}{A} =', A.det()
    print '\\overline{A} =', A.adj()
    print '\\f{\\Tr}{A} =', A.tr()
    print '\\f{A}{e_x^e_y} =', A(ex^ey)
    print '\\f{A}{e_x}^\\f{A}{e_y} =', A(ex)^A(ey)

    B = o3d.lt('B')

    print 'g =', o3d.g
    print '%g^{-1} =', o3d.g_inv


    print 'A + B =', A + B
    print 'AB =', A * B
    print 'A - B =', A - B

    print 'General Symmetric Linear Transformation'
    Asym = o3d.lt('A',mode='s')
    print 'A =', Asym
    print 'General Antisymmetric Linear Transformation'
    Aasym = o3d.lt('A',mode='a')
    print 'A =', Aasym

    print '#2d general ($A,\\;B$ are linear transformations)'

    A2d = g2d.lt('A')

    print 'g =', g2d.g
    print '%g^{-1} =', g2d.g_inv
    print '%gg^{-1} =', simplify(g2d.g * g2d.g_inv)

    print 'A =', A2d
    print r'\f{mat}{A} =', A2d.matrix()
    print '\\f{\\det}{A} =', A2d.det()
    A2d_adj = A2d.adj()
    print '\\overline{A} =', A2d_adj
    print '\\f{mat}{\\overline{A}} =', simplify(A2d_adj.matrix())
    print '\\f{\\Tr}{A} =', A2d.tr()
    print '\\f{A}{e_u^e_v} =', A2d(eu^ev)
    print '\\f{A}{e_u}^\\f{A}{e_v} =', A2d(eu)^A2d(ev)

    B2d = g2d.lt('B')



    print 'B =', B2d
    print 'A + B =', A2d + B2d
    print 'AB =', A2d * B2d
    print 'A - B =', A2d - B2d

    a = g2d.mv('a','vector')
    b = g2d.mv('b','vector')

    print r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =',((a|A2d.adj()(b))-(b|A2d(a))).simplify()

    m4d = Ga('e_t e_x e_y e_z', g=[1, -1, -1, -1],coords=symbols('t,x,y,z',real=True))

    T = m4d.lt('T')

    print 'g =', m4d.g

    print r'\underline{T} =',T
    print r'\overline{T} =',T.adj()

    print r'\f{\det}{\underline{T}} =',T.det()
    print r'\f{\mbox{tr}}{\underline{T}} =',T.tr()

    a = m4d.mv('a','vector')
    b = m4d.mv('b','vector')

    print r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =',((a|T.adj()(b))-(b|T(a))).simplify()

    coords = (r, th, phi) = symbols('r,theta,phi', real=True)

    (sp3d, er, eth, ephi) = Ga.build('e_r e_th e_ph', g=[1, r**2, r**2*sin(th)**2], coords=coords)
    grad = sp3d.grad

    sm_coords = (u, v) = symbols('u,v', real=True)

    smap = [1, u, v]  # Coordinate map for sphere of r = 1

    sph2d = sp3d.sm(smap,sm_coords,norm=True)
    (eu, ev) = sph2d.mv()
    grad_uv = sph2d.grad

    F = sph2d.mv('F','vector',f=True)
    f = sph2d.mv('f','scalar',f=True)

    print 'f =',f
    print 'grad*f =',grad_uv * f

    print 'F =',F
    print 'grad*F =',grad_uv * F

    tp = (th,phi) = symbols('theta,phi',real=True)

    smap = [sin(th)*cos(phi),sin(th)*sin(phi),cos(th)]

    sph2dr = o3d.sm(smap,tp,norm=True)
    (eth, ephi) = sph2dr.mv()
    grad_tp = sph2dr.grad

    F = sph2dr.mv('F','vector',f=True)
    f = sph2dr.mv('f','scalar',f=True)

    print 'f =',f
    print 'grad*f =',grad_tp * f

    print 'F =',F
    print 'grad*F =',grad_tp * F

    return
Exemple #27
0
def main():
    Print_Function()

    (x, y, z) = xyz = symbols('x,y,z', real=True)
    (o3d, ex, ey, ez) = Ga.build('e_x e_y e_z', g=[1, 1, 1], coords=xyz)
    grad = o3d.grad

    (u, v) = uv = symbols('u,v', real=True)
    (g2d, eu, ev) = Ga.build('e_u e_v', coords=uv)
    grad_uv = g2d.grad

    v_xyz = o3d.mv('v', 'vector')
    A_xyz = o3d.mv('A', 'vector', f=True)
    A_uv = g2d.mv('A', 'vector', f=True)

    print('#3d orthogonal ($A$ is vector function)')
    print('A =', A_xyz)
    print('%A^{2} =', A_xyz * A_xyz)
    print('grad|A =', grad | A_xyz)
    print('grad*A =', grad * A_xyz)

    print('v|(grad*A) =', v_xyz | (grad * A_xyz))

    print('#2d general ($A$ is vector function)')
    print('A =', A_uv)
    print('%A^{2} =', A_uv * A_uv)
    print('grad|A =', grad_uv | A_uv)
    print('grad*A =', grad_uv * A_uv)

    A = o3d.lt('A')

    print('#3d orthogonal ($A,\\;B$ are linear transformations)')
    print('A =', A)
    print(r'\f{mat}{A} =', A.matrix())
    print('\\f{\\det}{A} =', A.det())
    print('\\overline{A} =', A.adj())
    print('\\f{\\Tr}{A} =', A.tr())
    print('\\f{A}{e_x^e_y} =', A(ex ^ ey))
    print('\\f{A}{e_x}^\\f{A}{e_y} =', A(ex) ^ A(ey))

    B = o3d.lt('B')

    print('g =', o3d.g)
    print('%g^{-1} =', o3d.g_inv)

    print('A + B =', A + B)
    print('AB =', A * B)
    print('A - B =', A - B)

    print('General Symmetric Linear Transformation')
    Asym = o3d.lt('A', mode='s')
    print('A =', Asym)
    print('General Antisymmetric Linear Transformation')
    Aasym = o3d.lt('A', mode='a')
    print('A =', Aasym)

    print('#2d general ($A,\\;B$ are linear transformations)')

    A2d = g2d.lt('A')

    print('g =', g2d.g)
    print('%g^{-1} =', g2d.g_inv)
    print('%gg^{-1} =', simplify(g2d.g * g2d.g_inv))

    print('A =', A2d)
    print(r'\f{mat}{A} =', A2d.matrix())
    print('\\f{\\det}{A} =', A2d.det())
    A2d_adj = A2d.adj()
    print('\\overline{A} =', A2d_adj)
    print('\\f{mat}{\\overline{A}} =', simplify(A2d_adj.matrix()))
    print('\\f{\\Tr}{A} =', A2d.tr())
    print('\\f{A}{e_u^e_v} =', A2d(eu ^ ev))
    print('\\f{A}{e_u}^\\f{A}{e_v} =', A2d(eu) ^ A2d(ev))

    B2d = g2d.lt('B')

    print('B =', B2d)
    print('A + B =', A2d + B2d)
    print('AB =', A2d * B2d)
    print('A - B =', A2d - B2d)

    a = g2d.mv('a', 'vector')
    b = g2d.mv('b', 'vector')

    print(r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =',
          ((a | A2d.adj()(b)) - (b | A2d(a))).simplify())

    m4d = Ga('e_t e_x e_y e_z',
             g=[1, -1, -1, -1],
             coords=symbols('t,x,y,z', real=True))

    T = m4d.lt('T')

    print('g =', m4d.g)

    print(r'\underline{T} =', T)
    print(r'\overline{T} =', T.adj())

    print(r'\f{\det}{\underline{T}} =', T.det())
    print(r'\f{\mbox{tr}}{\underline{T}} =', T.tr())

    a = m4d.mv('a', 'vector')
    b = m4d.mv('b', 'vector')

    print(r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =',
          ((a | T.adj()(b)) - (b | T(a))).simplify())

    coords = (r, th, phi) = symbols('r,theta,phi', real=True)

    (sp3d, er, eth, ephi) = Ga.build('e_r e_th e_ph',
                                     g=[1, r**2, r**2 * sin(th)**2],
                                     coords=coords)
    grad = sp3d.grad

    sm_coords = (u, v) = symbols('u,v', real=True)

    smap = [1, u, v]  # Coordinate map for sphere of r = 1

    sph2d = sp3d.sm(smap, sm_coords, norm=True)
    (eu, ev) = sph2d.mv()
    grad_uv = sph2d.grad

    F = sph2d.mv('F', 'vector', f=True)
    f = sph2d.mv('f', 'scalar', f=True)

    print('f =', f)
    print('grad*f =', grad_uv * f)

    print('F =', F)
    print('grad*F =', grad_uv * F)

    tp = (th, phi) = symbols('theta,phi', real=True)

    smap = [sin(th) * cos(phi), sin(th) * sin(phi), cos(th)]

    sph2dr = o3d.sm(smap, tp, norm=True)
    (eth, ephi) = sph2dr.mv()
    grad_tp = sph2dr.grad

    F = sph2dr.mv('F', 'vector', f=True)
    f = sph2dr.mv('f', 'scalar', f=True)

    print('f =', f)
    print('grad*f =', grad_tp * f)

    print('F =', F)
    print('grad*F =', grad_tp * F)

    return
Exemple #28
0
def noneuclidian_distance_calculation():
    Print_Function()
    from sympy import solve,sqrt
    Fmt(1)

    g = '0 # #,# 0 #,# # 1'
    nel = Ga('X Y e',g=g)
    (X,Y,e) = nel.mv()

    print 'g_{ij} =',nel.g

    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) = symbols('s c (1/B) M S C alpha')

    XdotY = nel.g[0,1]
    Xdote = nel.g[0,2]
    Ydote = nel.g[1,2]

    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(1/Binv,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
Exemple #29
0
def reciprocal_frame_test():
    Print_Function()
    Fmt(1)
    g = '1 # #,'+ \
        '# 1 #,'+ \
        '# # 1'

    ng3d = Ga('e1 e2 e3',g=g)
    (e1,e2,e3) = ng3d.mv()

    print 'g_{ij} =',ng3d.g

    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
Exemple #30
0
from printer import Format, xpdf
from ga import Ga
from mv import Com

Format()
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)
xpdf(paper='letter', prog=True)
Exemple #31
0
def main():
    Format()
    (g3d,ex,ey,ez) = Ga.build('e*x|y|z')
    A = g3d.mv('A','mv')
    print r'\bm{A} =',A
    A.Fmt(2,r'\bm{A}')
    A.Fmt(3,r'\bm{A}')

    X = (x,y,z) = symbols('x y z',real=True)
    o3d = Ga('e_x e_y e_z',g=[1,1,1],coords=X)
    (ex,ey,ez) = o3d.mv()

    f = o3d.mv('f','scalar',f=True)
    A = o3d.mv('A','vector',f=True)
    B = o3d.mv('B','bivector',f=True)

    print r'\bm{A} =',A
    print r'\bm{B} =',B

    print 'grad*f =',o3d.grad*f
    print r'grad|\bm{A} =',o3d.grad|A
    print r'grad*\bm{A} =',o3d.grad*A

    print r'-I*(grad^\bm{A}) =',-o3d.i*(o3d.grad^A)
    print r'grad*\bm{B} =',o3d.grad*B
    print r'grad^\bm{B} =',o3d.grad^B
    print r'grad|\bm{B} =',o3d.grad|B

    g4d = Ga('a b c d')

    (a,b,c,d) = g4d.mv()

    print 'g_{ij} =',g4d.g

    print '\\bm{a|(b*c)} =',a|(b*c)
    print '\\bm{a|(b^c)} =',a|(b^c)
    print '\\bm{a|(b^c^d)} =',a|(b^c^d)
    print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',(a|(b^c))+(c|(a^b))+(b|(c^a))
    print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',a*(b^c)-b*(a^c)+c*(a^b)
    print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)
    print '\\bm{(a^b)|(c^d)} =',(a^b)|(c^d)
    print '\\bm{((a^b)|c)|d} =',((a^b)|c)|d
    print '\\bm{(a^b)\\times (c^d)} =',Com(a^b,c^d)

    g = '1 # #,'+ \
         '# 1 #,'+ \
         '# # 1'

    ng3d = Ga('e1 e2 e3',g=g)
    (e1,e2,e3) = ng3d.mv()

    E = e1^e2^e3
    Esq = (E*E).scalar()
    print 'E =',E
    print '%E^{2} =',Esq
    Esq_inv = 1/Esq

    E1 = (e2^e3)*E
    E2 = (-1)*(e1^e3)*E
    E3 = (e1^e2)*E

    print 'E1 = (e2^e3)*E =',E1
    print 'E2 =-(e1^e3)*E =',E2
    print 'E3 = (e1^e2)*E =',E3

    print 'E1|e2 =',(E1|e2).expand()
    print 'E1|e3 =',(E1|e3).expand()
    print 'E2|e1 =',(E2|e1).expand()
    print 'E2|e3 =',(E2|e3).expand()
    print 'E3|e1 =',(E3|e1).expand()
    print 'E3|e2 =',(E3|e2).expand()
    w = ((E1|e1).expand()).scalar()
    Esq = expand(Esq)
    print '%(E1\\cdot e1)/E^{2} =',simplify(w/Esq)
    w = ((E2|e2).expand()).scalar()
    print '%(E2\\cdot e2)/E^{2} =',simplify(w/Esq)
    w = ((E3|e3).expand()).scalar()
    print '%(E3\\cdot e3)/E^{2} =',simplify(w/Esq)

    X = (r,th,phi) = symbols('r theta phi')
    s3d = Ga('e_r e_theta e_phi',g=[1,r**2,r**2*sin(th)**2],coords=X,norm=True)
    (er,eth,ephi) = s3d.mv()

    f = s3d.mv('f','scalar',f=True)
    A = s3d.mv('A','vector',f=True)
    B = s3d.mv('B','bivector',f=True)

    print 'A =',A
    print 'B =',B

    print 'grad*f =',s3d.grad*f
    print 'grad|A =',s3d.grad|A
    print '-I*(grad^A) =',-s3d.i*(s3d.grad^A)
    print 'grad^B =',s3d.grad^B

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords)
    (g0,g1,g2,g3) = m4d.mv()
    I = m4d.i

    B = m4d.mv('B','vector',f=True)
    E = m4d.mv('E','vector',f=True)
    B.set_coef(1,0,0)
    E.set_coef(1,0,0)
    B *= g0
    E *= g0
    J = m4d.mv('J','vector',f=True)
    F = E+I*B

    print 'B = \\bm{B\\gamma_{t}} =',B
    print 'E = \\bm{E\\gamma_{t}} =',E
    print 'F = E+IB =',F
    print 'J =',J
    gradF = m4d.grad*F
    gradF.Fmt(3,'grad*F')

    print 'grad*F = J'
    (gradF.get_grade(1)-J).Fmt(3,'%\\grade{\\nabla F}_{1} -J = 0')
    (gradF.get_grade(3)).Fmt(3,'%\\grade{\\nabla F}_{3} = 0')

    (alpha,beta,gamma) = symbols('alpha beta gamma')

    (x,t,xp,tp) = symbols("x t x' t'")
    m2d = Ga('gamma*t|x',g=[1,-1])
    (g0,g1) = m2d.mv()

    R = cosh(alpha/2)+sinh(alpha/2)*(g0^g1)
    X = t*g0+x*g1
    Xp = tp*g0+xp*g1
    print 'R =',R

    print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}"

    Xpp = R*Xp*R.rev()
    Xpp = Xpp.collect()
    Xpp = Xpp.trigsimp()
    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp
    Xpp = Xpp.subs({sinh(alpha):gamma*beta,cosh(alpha):gamma})

    print r'%\f{\sinh}{\alpha} = \gamma\beta'
    print r'%\f{\cosh}{\alpha} = \gamma'

    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp.collect()

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords)
    (g0,g1,g2,g3) = m4d.mv()
    I = m4d.i
    (m,e) = symbols('m e')

    psi = m4d.mv('psi','spinor',f=True)
    A = m4d.mv('A','vector',f=True)
    sig_z = g3*g0
    print '\\bm{A} =',A
    print '\\bm{\\psi} =',psi

    dirac_eq = (m4d.grad*psi)*I*sig_z-e*A*psi-m*psi*g0
    dirac_eq.simplify()

    dirac_eq.Fmt(3,r'\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0')

    xpdf()
    return
Exemple #32
0
    return [a1,a2]

def norm(X):
    Y=sqrt((X*X).scalar())
    return Y

Get_Program(True)
Eprint()

g='1 0 0 0, \
   0 1 0 0, \
   0 0 0 2, \
   0 0 2 0'

c2d = Ga('e_1 e_2 n \\bar{n}',g=g)
(e1,e2,n,nbar) = c2d.mv()

global n,nbar,I

def F(x):
    global n,nbar
    Fx = ((x*x)*n+2*x-nbar) / 2
    return(Fx)

e = (n+nbar)/2
ebar = n - e
I=e1*e2*e*ebar

def intersect_lines(L1,L2):
    global I
    '''
Exemple #33
0
from sympy import expand, simplify
from printer import Format, xpdf
from ga import Ga

g = '1 # #,'+ \
    '# 1 #,'+ \
    '# # 1'

Format()

ng3d = Ga('e1 e2 e3', g=g)
(e1, e2, e3) = ng3d.mv()
print('g_{ij} =', ng3d.g)
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)
Exemple #34
0
import sys
from sympy import symbols, sin, latex, diff, Function, expand
from ga import Ga
from lt import Mlt
from printer import Eprint, Format, xpdf

Format()

#Define spherical coordinate system in 3-d

coords = (r, th, phi) = symbols('r,theta,phi', real=True)

sp3d = Ga('e_r,e_th,e_ph', g=[1, r**2, r**2*sin(th)**2], coords=coords)
(er, eth, ephi) = sp3d.mv()

#Define coordinates for 2-d (u,v) and 1-d (s) manifolds

u,v,s,alpha = symbols('u v s alpha',real=True)

sub_coords = (u,v)

smap = [1, u, v]  # Coordinate map for sphere of r = 1 in 3-d

print r'(u,v)\rightarrow (r,\theta,\phi) = ',smap

#Define unit sphere manifold

sph2d = sp3d.sm(smap,sub_coords)

print '#Unit Sphere Manifold:'
Exemple #35
0
from sympy import symbols, sin
from printer import Format, xpdf
from ga import Ga

Format()

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

xpdf(crop=True, png=True)
Exemple #36
0
def reciprocal_frame_test():
    Print_Function()
    g = '1 # #,'+ \
        '# 1 #,'+ \
        '# # 1'

    ng3d = Ga('e1 e2 e3',g=g)
    (e1,e2,e3) = ng3d.mv()

    print 'g_{ij} =',ng3d.g

    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
Exemple #37
0
from printer import Format, xpdf
from ga import Ga
from sympy import symbols

Format()
X = (x,y,z) = symbols('x y z')
o3d = Ga('e_x e_y e_z',g=[1,1,1],coords=X)

f = o3d.mv('f','scalar',f=True)
A = o3d.mv('A','vector',f=True)
B = o3d.mv('B','bivector',f=True)

print r'\bm{A} =',A
print r'\bm{B} =',B

print 'grad*f =',o3d.grad*f
print r'grad|\bm{A} =',o3d.grad|A
(o3d.grad*A).Fmt(2,r'grad*\bm{A}')

print r'-I*(grad^\bm{A}) =',-o3d.mv_I*(o3d.grad^A)
(o3d.grad*B).Fmt(2,r'grad*\bm{B}')
print r'grad^\bm{B} =',o3d.grad^B
print r'grad|\bm{B} =',o3d.grad|B

xpdf(crop=True,png=True)
Exemple #38
0
def reciprocal_frame_test():
    Print_Function()

    g = '1 # #,'+ \
        '# 1 #,'+ \
        '# # 1'

    g3dn = Ga('e1 e2 e3',g=g)

    (e1,e2,e3) = g3dn.mv()

    print('g_{ij} =\n',g3dn.g)

    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
Exemple #39
0
from sympy import expand,simplify
from printer import Format,xpdf
from ga import Ga

g = '1 # #,'+ \
    '# 1 #,'+ \
    '# # 1'

Format()

ng3d = Ga('e1 e2 e3',g=g)
(e1,e2,e3) = ng3d.mv()
print 'g_{ij} =',ng3d.g
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)
Exemple #40
0
print '#2d general ($A,\\;B$ are linear transformations)'
A2d = g2d.lt('A')
print 'A =', A2d
print '\\f{\\det}{A} =', A2d.det()
#A2d.adj().Fmt(4,'\\overline{A}')
print '\\f{\\Tr}{A} =', A2d.tr()
print '\\f{A}{e_u^e_v} =', A2d(eu^ev)
print '\\f{A}{e_u}^\\f{A}{e_v} =', A2d(eu)^A2d(ev)
B2d = g2d.lt('B')
print 'B =', B2d
print 'A + B =', A2d + B2d
print 'AB =', A2d * B2d
print 'A - B =', A2d - B2d
a = g2d.mv('a','vector')
b = g2d.mv('b','vector')
print r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =',((a|A2d.adj()(b))-(b|A2d(a))).simplify()

print '#4d Minkowski spaqce (Space Time)'
m4d = Ga('e_t e_x e_y e_z', g=[1, -1, -1, -1],coords=symbols('t,x,y,z',real=True))
T = m4d.lt('T')
print 'g =', m4d.g
print r'\underline{T} =',T
print r'\overline{T} =',T.adj()
#m4d.mv(T.det()).Fmt(4,r'\f{\det}{\underline{T}}')
print r'\f{\mbox{tr}}{\underline{T}} =',T.tr()
a = m4d.mv('a','vector')
b = m4d.mv('b','vector')
print r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =',((a|T.adj()(b))-(b|T(a))).simplify()
xpdf(paper='landscape')
Exemple #41
0
from printer import Format, xpdf
from ga import Ga
Format()
g3d = Ga('e*x|y|z')
A = g3d.mv('A','mv')
print r'\bm{A} =',A
A.Fmt(2,r'\bm{A}')
A.Fmt(3,r'\bm{A}')
xpdf(paper='letter')
Exemple #42
0
import sys
from sympy import symbols, sin, latex, diff, Function, expand
from ga import Ga
from lt import Mlt
from printer import Eprint, Format, xpdf

Format()

#Define spherical coordinate system in 3-d

coords = (r, th, phi) = symbols('r,theta,phi', real=True)

sp3d = Ga('e_r,e_th,e_ph', g=[1, r**2, r**2*sin(th)**2], coords=coords)
(er, eth, ephi) = sp3d.mv()

#Define coordinates for 2-d (u,v) and 1-d (s) manifolds

u,v,s,alpha = symbols('u v s alpha',real=True)

sub_coords = (u,v)

smap = [1, u, v]  # Coordinate map for sphere of r = 1 in 3-d

print r'(u,v)\rightarrow (r,\theta,\phi) = ',smap

#Define unit sphere manifold

sph2d = sp3d.sm(smap,sub_coords)

print '#Unit Sphere Manifold:'
Exemple #43
0
import sys
from sympy import symbols, sin
from printer import Format, xpdf
from ga import Ga

Format()
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)
print(r'%\nabla\cdot\lp\nabla f\rp =', s3d.grad | (s3d.grad * f))
xpdf(paper='letter', prog=True)