Пример #1
0
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
Пример #2
0
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
Пример #3
0
def extracting_vectors_from_conformal_2_blade():
    global n,nbar
    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
Пример #4
0
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 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)
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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
Пример #10
0
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
Пример #11
0
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
Пример #12
0
def test_extracting_vectors_from_conformal_2_blade():
    metric = ' 0 -1 #,'+ \
             '-1  0 #,'+ \
             ' #  # #,'

    (P1, P2, a) = MV.setup('P1 P2 a', metric)

    B = P1 ^ P2
    Bsq = B * B
    assert str(Bsq) == '1'
    ap = a - (a ^ B) * B
    assert str(ap) == '-(P2.a)*P1 - (P1.a)*P2'

    Ap = ap + ap * B
    Am = ap - ap * B

    assert str(Ap) == '-2*(P2.a)*P1'
    assert str(Am) == '-2*(P1.a)*P2'

    assert str(Ap * Ap) == '0'
    assert str(Am * Am) == '0'

    aB = a | B
    assert str(aB) == '-(P2.a)*P1 + (P1.a)*P2'
    return
Пример #13
0
def test_derivatives_in_spherical_coordinates():
    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)

    assert str(f) == 'f'
    assert str(A) == 'A__r*e_r + A__theta*e_theta + A__phi*e_phi'
    assert str(
        B
    ) == 'B__rtheta*e_r^e_theta + B__rphi*e_r^e_phi + B__thetaphi*e_theta^e_phi'

    assert str(
        grad *
        f) == 'D{r}f*e_r + D{theta}f/r*e_theta + D{phi}f/(r*sin(theta))*e_phi'
    assert str(
        grad | A
    ) == 'D{r}A__r + 2*A__r/r + A__theta*cos(theta)/(r*sin(theta)) + D{theta}A__theta/r + D{phi}A__phi/(r*sin(theta))'
    assert str(
        -MV.I * (grad ^ A)
    ) == '((A__phi*cos(theta)/sin(theta) + D{theta}A__phi - D{phi}A__theta/sin(theta))/r)*e_r + (-D{r}A__phi - A__phi/r + D{phi}A__r/(r*sin(theta)))*e_theta + (D{r}A__theta + A__theta/r - D{theta}A__r/r)*e_phi'
    assert str(
        grad ^ B
    ) == '(D{r}B__thetaphi - B__rphi*cos(theta)/(r*sin(theta)) + 2*B__thetaphi/r - D{theta}B__rphi/r + D{phi}B__rtheta/(r*sin(theta)))*e_r^e_theta^e_phi'
    return
Пример #14
0
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
Пример #15
0
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
Пример #16
0
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
Пример #17
0
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
Пример #18
0
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
Пример #19
0
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
Пример #20
0
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
Пример #21
0
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
Пример #22
0
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
Пример #23
0
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
Пример #24
0
def test_rounding_numerical_components():
    (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

    #assert str(X) == '1.20000000000000*e_x + 2.34000000000000*e_y + 0.555000000000000*e_z'
    assert str(Nga(X, 2)) == '1.2*e_x + 2.3*e_y + 0.55*e_z'
    #assert str(X*Y) == '12.7011000000000 + 4.02078000000000*e_x^e_y + 6.17518500000000*e_x^e_z + 10.1820000000000*e_y^e_z'
    assert str(Nga(X * Y,
                   2)) == '13. + 4.0*e_x^e_y + 6.2*e_x^e_z + 10.*e_y^e_z'
    return
Пример #25
0
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
Пример #26
0
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
Пример #27
0
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
Пример #28
0
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
Пример #29
0
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
Пример #30
0
def test_derivatives_in_rectangular_coordinates():
    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)

    assert str(f) == 'f'
    assert str(A) == 'A__x*e_x + A__y*e_y + A__z*e_z'
    assert str(B) == 'B__xy*e_x^e_y + B__xz*e_x^e_z + B__yz*e_y^e_z'
    assert str(
        C
    ) == 'C + C__x*e_x + C__y*e_y + C__z*e_z + C__xy*e_x^e_y + C__xz*e_x^e_z + C__yz*e_y^e_z + C__xyz*e_x^e_y^e_z'

    assert str(grad * f) == 'D{x}f*e_x + D{y}f*e_y + D{z}f*e_z'
    assert str(grad | A) == 'D{x}A__x + D{y}A__y + D{z}A__z'
    assert str(
        grad * A
    ) == 'D{x}A__x + D{y}A__y + D{z}A__z + (-D{y}A__x + D{x}A__y)*e_x^e_y + (-D{z}A__x + D{x}A__z)*e_x^e_z + (-D{z}A__y + D{y}A__z)*e_y^e_z'

    assert str(
        -MV.I * (grad ^ A)
    ) == '(-D{z}A__y + D{y}A__z)*e_x + (D{z}A__x - D{x}A__z)*e_y + (-D{y}A__x + D{x}A__y)*e_z'

    assert str(
        grad * B
    ) == '(-D{y}B__xy - D{z}B__xz)*e_x + (D{x}B__xy - D{z}B__yz)*e_y + (D{x}B__xz + D{y}B__yz)*e_z + (D{z}B__xy - D{y}B__xz + D{x}B__yz)*e_x^e_y^e_z'
    assert str(grad ^ B) == '(D{z}B__xy - D{y}B__xz + D{x}B__yz)*e_x^e_y^e_z'
    assert str(
        grad | B
    ) == '(-D{y}B__xy - D{z}B__xz)*e_x + (D{x}B__xy - D{z}B__yz)*e_y + (D{x}B__xz + D{y}B__yz)*e_z'

    assert str(grad < A) == 'D{x}A__x + D{y}A__y + D{z}A__z'
    assert str(grad > A) == 'D{x}A__x + D{y}A__y + D{z}A__z'
    assert str(
        grad < B
    ) == '(-D{y}B__xy - D{z}B__xz)*e_x + (D{x}B__xy - D{z}B__yz)*e_y + (D{x}B__xz + D{y}B__yz)*e_z'
    assert str(grad > B) == '0'
    assert str(
        grad < C
    ) == 'D{x}C__x + D{y}C__y + D{z}C__z + (-D{y}C__xy - D{z}C__xz)*e_x + (D{x}C__xy - D{z}C__yz)*e_y + (D{x}C__xz + D{y}C__yz)*e_z + D{z}C__xyz*e_x^e_y - D{y}C__xyz*e_x^e_z + D{x}C__xyz*e_y^e_z'
    assert str(
        grad > C
    ) == 'D{x}C__x + D{y}C__y + D{z}C__z + D{x}C*e_x + D{y}C*e_y + D{z}C*e_z'
    return
Пример #31
0
def test_check_generalized_BAC_CAB_formulas():
    (a, b, c, d, e) = MV.setup('a b c d e')

    assert str(a | (b * c)) == '-(a.c)*b + (a.b)*c'
    assert str(a | (b ^ c)) == '-(a.c)*b + (a.b)*c'
    assert str(a | (b ^ c ^ d)) == '(a.d)*b^c - (a.c)*b^d + (a.b)*c^d'
    #assert str( (a|(b^c))+(c|(a^b))+(b|(c^a)) ) == '0'
    assert str(a * (b ^ c) - b * (a ^ c) + c * (a ^ b)) == '3*a^b^c'
    assert str(a * (b ^ c ^ d) - b * (a ^ c ^ d) + c * (a ^ b ^ d) - d *
               (a ^ b ^ c)) == '4*a^b^c^d'
    assert str((a ^ b) | (c ^ d)) == '-(a.c)*(b.d) + (a.d)*(b.c)'
    assert str(((a ^ b) | c) | d) == '-(a.c)*(b.d) + (a.d)*(b.c)'
    assert str(Ga.com(a ^ b, c
                      ^ d)) == '-(b.d)*a^c + (b.c)*a^d + (a.d)*b^c - (a.c)*b^d'
    assert str(
        (a | (b ^ c)) | (d ^ e)
    ) == '(-(a.b)*(c.e) + (a.c)*(b.e))*d + ((a.b)*(c.d) - (a.c)*(b.d))*e'
    return
Пример #32
0
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
Пример #33
0
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
Пример #34
0
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
Пример #35
0
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
Пример #36
0
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
Пример #37
0
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
Пример #38
0
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
Пример #39
0
def test_conformal_representations_of_circles_lines_spheres_and_planes():
    global n, nbar

    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)

    e = n + nbar
    #conformal representation of points

    A = make_vector(e1)
    B = make_vector(e2)
    C = make_vector(-e1)
    D = make_vector(e3)
    X = make_vector('x', 3)

    assert str(A) == 'e_1 + 1/2*n - 1/2*nbar'
    assert str(B) == 'e_2 + 1/2*n - 1/2*nbar'
    assert str(C) == '-e_1 + 1/2*n - 1/2*nbar'
    assert str(D) == 'e_3 + 1/2*n - 1/2*nbar'
    assert str(
        X
    ) == 'x1*e_1 + x2*e_2 + x3*e_3 + ((x1**2 + x2**2 + x3**2)/2)*n - 1/2*nbar'

    assert str(
        (A ^ B ^ C ^ X)
    ) == '-x3*e_1^e_2^e_3^n + x3*e_1^e_2^e_3^nbar + ((x1**2 + x2**2 + x3**2 - 1)/2)*e_1^e_2^n^nbar'
    assert str(
        (A ^ B ^ n ^ X)
    ) == '-x3*e_1^e_2^e_3^n + ((x1 + x2 - 1)/2)*e_1^e_2^n^nbar + x3/2*e_1^e_3^n^nbar - x3/2*e_2^e_3^n^nbar'
    assert str((((A ^ B) ^ C) ^ D)
               ^ X) == '((-x1**2 - x2**2 - x3**2 + 1)/2)*e_1^e_2^e_3^n^nbar'
    assert str(
        (A ^ B ^ n ^ D ^ X)) == '((-x1 - x2 - x3 + 1)/2)*e_1^e_2^e_3^n^nbar'

    L = (A ^ B ^ e) ^ X

    assert str(
        L
    ) == '-x3*e_1^e_2^e_3^n - x3*e_1^e_2^e_3^nbar + (-x1**2/2 + x1 - x2**2/2 + x2 - x3**2/2 - 1/2)*e_1^e_2^n^nbar + x3*e_1^e_3^n^nbar - x3*e_2^e_3^n^nbar'
    return
Пример #40
0
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
Пример #41
0
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
Пример #42
0
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
Пример #43
0
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
Пример #44
0
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
Пример #45
0
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
Пример #46
0
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
Пример #47
0
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
Пример #48
0
def test_properties_of_geometric_objects():
    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)

    P1 = F(p1)
    P2 = F(p2)
    P3 = F(p3)

    L = P1 ^ P2 ^ n
    delta = (L | n) | nbar
    assert str(delta) == '2*p1 - 2*p2'

    C = P1 ^ P2 ^ P3
    delta = ((C ^ n) | n) | nbar
    assert str(delta) == '2*p1^p2 - 2*p1^p3 + 2*p2^p3'
    assert str((p2 - p1) ^ (p3 - p1)) == 'p1^p2 - p1^p3 + p2^p3'
    return
Пример #49
0
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
Пример #50
0
from sympy import *
from ga import Ga
from mv import MV
from 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}')

print c.reflect_in_blade(ex^ey).Fmt(1,'c\\mbox{ reflect in }xy')
print c.reflect_in_blade(ex^ey^ez).Fmt(1,'c\\mbox{ reflect in }xyz')
print (ew^ex).reflect_in_blade(ey^ez).Fmt(1,'wx\\mbox{ reflect in }yz')
print (ew^ex).reflect_in_blade(ex^ey).Fmt(1,'wx\\mbox{ reflect in }xy')
Пример #51
0
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(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
Пример #52
0
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
Пример #53
0
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
Пример #54
0
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
Пример #55
0
from sympy import S
from printer import xdvi,Get_Program,Print_Function,Format
from mv 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()
Пример #56
0
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()
    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')

    xdvi()
    return