This example is kindly contributed by FreddyBaudine for reproducing pygae/galgebra#15 with modifications by utensil.


In [1]:
import sys
from galgebra.printer import  Format, xpdf, Fmt
Format()
from sympy import symbols, Rational, latex
from galgebra.ga import Ga

In [2]:
# st4: Spacetime Algebra I
st4coords = (t,x,y,z) = symbols('t x y z', real=True) 
st4 = Ga('e_t e_x e_y e_z', g=[1,-1,-1,-1], coords=st4coords)
(e_t,e_x,e_y,e_z) = st4.mv()
(e__t,e__x,e__y,e__z) = st4.mvr(norm = False)

In [3]:
Format(Fmode = True, Dmode = True)

In [4]:
(grad,rgrad) = st4.grads()

In [5]:
s = st4.mv('s','scalar',f = True)
a = st4.mv('a','vector',f = True)
b = st4.mv('b','vector',f = True)
B = st4.mv('B','bivector',f = True)
C = st4.mv('C',3)
I = st4.mv('I','pseudo')
S = st4.mv('S','spinor',f = True)
M = st4.mv('M','mv',f = True)

M1inv = M.grade(1).inv()
M3inv = M.grade(3).inv()

In [6]:
a.Fmt(1,r'\mathbf{a}')


Out[6]:
\begin{equation*} \mathbf{a} = a^{t} \boldsymbol{e}_{t} + a^{x} \boldsymbol{e}_{x} + a^{y} \boldsymbol{e}_{y} + a^{z} \boldsymbol{e}_{z} \end{equation*}

In [7]:
(a*a).Fmt(2,r'\mathbf{a} \mathbf{a}')


Out[7]:
\begin{equation*} \mathbf{a} \mathbf{a} = {a^{t} }^{2} - {a^{x} }^{2} - {a^{y} }^{2} - {a^{z} }^{2} \end{equation*}

In [8]:
a.inv().Fmt(3,r'\mathbf{a}^{-1}')


Out[8]:
\begin{align*} \mathbf{a}^{-1} =& \frac{a^{t} }{{a^{t} }^{2} - {a^{x} }^{2} - {a^{y} }^{2} - {a^{z} }^{2}} \boldsymbol{e}_{t} \\ & + \frac{a^{x} }{{a^{t} }^{2} - {a^{x} }^{2} - {a^{y} }^{2} - {a^{z} }^{2}} \boldsymbol{e}_{x} \\ & + \frac{a^{y} }{{a^{t} }^{2} - {a^{x} }^{2} - {a^{y} }^{2} - {a^{z} }^{2}} \boldsymbol{e}_{y} \\ & + \frac{a^{z} }{{a^{t} }^{2} - {a^{x} }^{2} - {a^{y} }^{2} - {a^{z} }^{2}} \boldsymbol{e}_{z} \end{align*}

In [9]:
(M.grade(1) * M.grade(1)).\
 Fmt(1,r'\langle \mathbf{M} \rangle _1 \langle \mathbf{M} \rangle _1')


Out[9]:
\begin{equation*} \langle \mathbf{M} \rangle _1 \langle \mathbf{M} \rangle _1 = {M^{t} }^{2} - {M^{x} }^{2} - {M^{y} }^{2} - {M^{z} }^{2} \end{equation*}

In [10]:
M1inv.Fmt(3,r'\langle \mathbf{M} \rangle _1 ^{-1}')


Out[10]:
\begin{align*} \langle \mathbf{M} \rangle _1 ^{-1} =& \frac{M^{t} }{{M^{t} }^{2} - {M^{x} }^{2} - {M^{y} }^{2} - {M^{z} }^{2}} \boldsymbol{e}_{t} \\ & + \frac{M^{x} }{{M^{t} }^{2} - {M^{x} }^{2} - {M^{y} }^{2} - {M^{z} }^{2}} \boldsymbol{e}_{x} \\ & + \frac{M^{y} }{{M^{t} }^{2} - {M^{x} }^{2} - {M^{y} }^{2} - {M^{z} }^{2}} \boldsymbol{e}_{y} \\ & + \frac{M^{z} }{{M^{t} }^{2} - {M^{x} }^{2} - {M^{y} }^{2} - {M^{z} }^{2}} \boldsymbol{e}_{z} \end{align*}

In [11]:
M.grade(3).Fmt(2,r'\langle \mathbf{M} \rangle _3')


Out[11]:
\begin{equation*} \langle \mathbf{M} \rangle _3 = M^{txy} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y} + M^{txz} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{z} + M^{tyz} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z} + M^{xyz} \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z} \end{equation*}

In [12]:
(M.grade(3) * M.grade(3)).\
 Fmt(1,r'\langle \mathbf{M} \rangle _3 \langle \mathbf{M} \rangle _3')


Out[12]:
\begin{equation*} \langle \mathbf{M} \rangle _3 \langle \mathbf{M} \rangle _3 = - {M^{txy} }^{2} - {M^{txz} }^{2} - {M^{tyz} }^{2} + {M^{xyz} }^{2} \end{equation*}

In [13]:
M3inv.Fmt(3,r'\langle \mathbf{M} \rangle _3^{-1}')


Out[13]:
\begin{align*} \langle \mathbf{M} \rangle _3^{-1} =& - \frac{M^{txy} }{{M^{txy} }^{2} + {M^{txz} }^{2} + {M^{tyz} }^{2} - {M^{xyz} }^{2}} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y} \\ & - \frac{M^{txz} }{{M^{txy} }^{2} + {M^{txz} }^{2} + {M^{tyz} }^{2} - {M^{xyz} }^{2}} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{z} \\ & - \frac{M^{tyz} }{{M^{txy} }^{2} + {M^{txz} }^{2} + {M^{tyz} }^{2} - {M^{xyz} }^{2}} \boldsymbol{e}_{t}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z} \\ & - \frac{M^{xyz} }{{M^{txy} }^{2} + {M^{txz} }^{2} + {M^{tyz} }^{2} - {M^{xyz} }^{2}} \boldsymbol{e}_{x}\wedge \boldsymbol{e}_{y}\wedge \boldsymbol{e}_{z} \end{align*}

In [ ]: