In [1]:
from IPython.display import Math, display
def displayWithTitle(multivector, title):
    display(Math(title + '=' + multivector._repr_latex_()))
def CheckProperties(i,j,k):
    ilabel = i.texLabel
    jlabel = j.texLabel
    klabel = k.texLabel
    displayWithTitle(i, title=ilabel)
    displayWithTitle(j, title=jlabel)
    displayWithTitle(k, title=klabel)
    displayWithTitle((i*i), title=ilabel+'^2')
    displayWithTitle((j*j), title=jlabel+'^2')
    displayWithTitle((k*k), title=klabel+'^2')
    displayWithTitle((i*j), title=ilabel + jlabel)
    displayWithTitle((j*i), title=jlabel + ilabel)
    displayWithTitle((j*k), title=jlabel + klabel)
    displayWithTitle((k*j), title=klabel + jlabel)
    displayWithTitle((k*i), title=klabel + ilabel)
    displayWithTitle((i*k), title=ilabel + klabel)
    displayWithTitle((i*j*k), title=ilabel + jlabel + klabel)

In [2]:
from sympy.matrices import *
from galgebra.ga import Ga
from galgebra.printer import *

ALGEBRA & DEFINITIONS

Clifford algebra is $$Cl_{4,0}(\mathbb{R})$$

Flat space, no metric, just signature

All constants are equal to 1


In [3]:
from sympy import *
variables = (x, y, z, w) = symbols('x y z w', real=True)
print(variables)


(x, y, z, w)

In [4]:
metric=[ 1
        ,1
        ,1
        ,1]

myBasis='e_1 e_2 e_3 e_4'

sp4d = Ga(myBasis, g=metric, coords=variables,norm=True)
(e_1, e_2, e_3, e_4) = sp4d.mv()

In [5]:
sigma_1w=e_2*e_3
sigma_2w=e_3*e_1
sigma_3w=-e_1*e_2
sigma_1w.texLabel='\\sigma_{1w}'
sigma_2w.texLabel='\\sigma_{2w}'
sigma_3w.texLabel='\\sigma_{3w}'

display(Math('(1,'+sigma_1w.texLabel+','+sigma_2w.texLabel+','+sigma_3w.texLabel+')'))
CheckProperties(sigma_1w,sigma_2w,sigma_3w)


$\displaystyle (1,\sigma_{1w},\sigma_{2w},\sigma_{3w})$
$\displaystyle \sigma_{1w}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{2w}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3w}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{1w}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{2w}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{3w}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{1w}\sigma_{2w}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{2w}\sigma_{1w}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{2w}\sigma_{3w}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3w}\sigma_{2w}=\begin{equation*} - \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3w}\sigma_{1w}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{1w}\sigma_{3w}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{1w}\sigma_{2w}\sigma_{3w}=\begin{equation*} -1 \end{equation*}$

In [6]:
sigma_1x=e_2*e_3
sigma_2x=e_3*e_4
sigma_3x=-e_4*e_2
sigma_1x.texLabel='\\sigma_{1x}'
sigma_2x.texLabel='\\sigma_{2x}'
sigma_3x.texLabel='\\sigma_{3x}'

display(Math('(1,'+sigma_1x.texLabel+','+sigma_2x.texLabel+','+sigma_3x.texLabel+')'))
CheckProperties(sigma_1x,sigma_2x,sigma_3x)


$\displaystyle (1,\sigma_{1x},\sigma_{2x},\sigma_{3x})$
$\displaystyle \sigma_{1x}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{2x}=\begin{equation*} \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{3x}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1x}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{2x}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{3x}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{1x}\sigma_{2x}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2x}\sigma_{1x}=\begin{equation*} - \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2x}\sigma_{3x}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3x}\sigma_{2x}=\begin{equation*} - \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3x}\sigma_{1x}=\begin{equation*} \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1x}\sigma_{3x}=\begin{equation*} - \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1x}\sigma_{2x}\sigma_{3x}=\begin{equation*} -1 \end{equation*}$

In [7]:
sigma_1y=e_1*e_3
sigma_2y=e_3*e_4
sigma_3y=-e_4*e_1
sigma_1y.texLabel='\\sigma_{1y}'
sigma_2y.texLabel='\\sigma_{2y}'
sigma_3y.texLabel='\\sigma_{3y}'

display(Math('(1,'+sigma_1y.texLabel+','+sigma_2y.texLabel+','+sigma_3y.texLabel+')'))
CheckProperties(sigma_1y,sigma_2y,sigma_3y)


$\displaystyle (1,\sigma_{1y},\sigma_{2y},\sigma_{3y})$
$\displaystyle \sigma_{1y}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{2y}=\begin{equation*} \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{3y}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1y}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{2y}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{3y}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{1y}\sigma_{2y}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2y}\sigma_{1y}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2y}\sigma_{3y}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3y}\sigma_{2y}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \sigma_{3y}\sigma_{1y}=\begin{equation*} \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1y}\sigma_{3y}=\begin{equation*} - \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1y}\sigma_{2y}\sigma_{3y}=\begin{equation*} -1 \end{equation*}$

In [8]:
sigma_1z=e_1*e_2
sigma_2z=e_2*e_4
sigma_3z=-e_4*e_1
sigma_1z.texLabel='\\sigma_{1z}'
sigma_2z.texLabel='\\sigma_{2z}'
sigma_3z.texLabel='\\sigma_{3z}'

display(Math('(1,'+sigma_1z.texLabel+','+sigma_2z.texLabel+','+sigma_3z.texLabel+')'))
CheckProperties(sigma_1z,sigma_2z,sigma_3z)


$\displaystyle (1,\sigma_{1z},\sigma_{2z},\sigma_{3z})$
$\displaystyle \sigma_{1z}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{2z}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{3z}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1z}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{2z}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{3z}^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \sigma_{1z}\sigma_{2z}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2z}\sigma_{1z}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{2z}\sigma_{3z}=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{3z}\sigma_{2z}=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} \end{equation*}$
$\displaystyle \sigma_{3z}\sigma_{1z}=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1z}\sigma_{3z}=\begin{equation*} - \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \sigma_{1z}\sigma_{2z}\sigma_{3z}=\begin{equation*} -1 \end{equation*}$

In [9]:
gamma_4=e_1*e_2*e_3
gamma_1=e_4*e_2*e_3
gamma_2=e_1*e_4*e_3
gamma_3=e_1*e_2*e_4
displayWithTitle(gamma_4,title='\\gamma_4')
displayWithTitle(gamma_4*gamma_4,title='\\gamma_4^2')

displayWithTitle(gamma_1,title='\\gamma_1')
displayWithTitle(gamma_1*gamma_1,title='\\gamma_1^2')

displayWithTitle(gamma_2,title='\\gamma_2')
displayWithTitle(gamma_2*gamma_2,title='\\gamma_2^2')

displayWithTitle(gamma_3,title='\\gamma_3')
displayWithTitle(gamma_3*gamma_3,title='\\gamma_3^2')


$\displaystyle \gamma_4=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \gamma_4^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \gamma_1=\begin{equation*} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \gamma_1^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \gamma_2=\begin{equation*} - \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \gamma_2^2=\begin{equation*} -1 \end{equation*}$
$\displaystyle \gamma_3=\begin{equation*} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle \gamma_3^2=\begin{equation*} -1 \end{equation*}$

PHYSICS

The following symbols are defined :

Charge $$q \in \mathbb{R}$$

Mass $$m \in \mathbb{R}$$


In [10]:
m, q = symbols('m q', real=True)
rquat = [sigma_1w, sigma_2w, sigma_3w]

In [11]:
B_x, B_y, B_z = symbols('B_x B_y B_z', real=True)
Bv =[B_x, B_y, B_z]
B = S(0)
for (dim, var) in zip(Bv, rquat):
    B += var * dim
B.texLabel='\\mathbf{B}'

display(Latex('Magnetic field $'+B.texLabel+'$ is defined with $B_x, B_y, B_z \\in \\mathbb{R}$'))
display(Math(B.texLabel+'=B_x'+sigma_1w.texLabel+'+B_y'+sigma_2w.texLabel+'+B_z'+sigma_3w.texLabel))
displayWithTitle(B, title=B.texLabel)


Magnetic field $\mathbf{B}$ is defined with $B_x, B_y, B_z \in \mathbb{R}$
$\displaystyle \mathbf{B}=B_x\sigma_{1w}+B_y\sigma_{2w}+B_z\sigma_{3w}$
$\displaystyle \mathbf{B}=\begin{equation*} - B_{z} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} - B_{y} \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} + B_{x} \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$

In [12]:
a, b, c, d = symbols('a b c d', real=True)

psiv =[b, c, d]
psi = S(a)
for (dim, var) in zip(psiv, rquat):
    psi += var * dim
psi.texLabel='\\psi'

display(Latex('Pauli spinor $'+psi.texLabel+'$ is defined with $a, b, c, d\\in \\mathbb{R}$'))
display(Math(psi.texLabel+'=a+b'+sigma_1w.texLabel+'+c'+sigma_2w.texLabel+'+d'+sigma_3w.texLabel))
displayWithTitle(psi, title=psi.texLabel)

psiv_dagger =[-b, -c, -d]
psi_dagger = S(a)
for (dim, var) in zip(psiv_dagger, rquat):
    psi_dagger += var * dim
psi_dagger.texLabel='\\psi^\\dagger'
display(Math(psi_dagger.texLabel+'=a-b'+sigma_1w.texLabel+'-c'+sigma_2w.texLabel+'-d'+sigma_3w.texLabel))
displayWithTitle(psi_dagger, title=psi_dagger.texLabel)


Pauli spinor $\psi$ is defined with $a, b, c, d\in \mathbb{R}$
$\displaystyle \psi=a+b\sigma_{1w}+c\sigma_{2w}+d\sigma_{3w}$
$\displaystyle \psi=\begin{equation*} a - d \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} - c \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} + b \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \psi^\dagger=a-b\sigma_{1w}-c\sigma_{2w}-d\sigma_{3w}$
$\displaystyle \psi^\dagger=\begin{equation*} a + d \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} + c \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} - b \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$

In [13]:
rho=psi*psi_dagger
rho.texLabel = '\\rho'
display(Math(rho.texLabel+'='+psi.texLabel+psi_dagger.texLabel))
displayWithTitle(rho, title=rho.texLabel)

spin_vector_w = psi*sigma_3w*psi_dagger
spin_vector_w.texLabel = '\\boldsymbol{s}_w'
display(Math(spin_vector_w.texLabel+'='+psi.texLabel+sigma_3w.texLabel+psi_dagger.texLabel))
displayWithTitle(spin_vector_w, title=spin_vector_w.texLabel)


$\displaystyle \rho=\psi\psi^\dagger$
$\displaystyle \rho=\begin{equation*} a^{2} + b^{2} + c^{2} + d^{2} \end{equation*}$
$\displaystyle \boldsymbol{s}_w=\psi\sigma_{3w}\psi^\dagger$
$\displaystyle \boldsymbol{s}_w=\begin{equation*} \left ( - a^{2} + b^{2} + c^{2} - d^{2}\right ) \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2} + \left ( 2 a b - 2 c d\right ) \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{3} + \left ( 2 a c + 2 b d\right ) \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3} \end{equation*}$

In [14]:
up=1/2*(1+e_3)
up.texLabel='\\uparrow'
displayWithTitle(up, title=up.texLabel)
displayWithTitle(up*up, title=up.texLabel+'^2')

down=1/2*(1-e_3)
down.texLabel='\\downarrow'
displayWithTitle(down, title=down.texLabel)
displayWithTitle(down*down, title=down.texLabel+'^2')


$\displaystyle \uparrow=\begin{equation*} 0.5 + 0.5 \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \uparrow^2=\begin{equation*} 0.5 + 0.5 \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \downarrow=\begin{equation*} 0.5 -0.5 \boldsymbol{e}_{3} \end{equation*}$
$\displaystyle \downarrow^2=\begin{equation*} 0.5 -0.5 \boldsymbol{e}_{3} \end{equation*}$

In [15]:
gamma_5 = e_1*e_2*e_3*e_4
gamma_5.texLabel = '\\gamma_5'

left=1/2*(1-gamma_5)
left.texLabel='['
displayWithTitle(left, title=left.texLabel)
displayWithTitle(left*left, title=left.texLabel+'^2')

right=1/2*(1+gamma_5)
right.texLabel=']'
displayWithTitle(right, title=right.texLabel)
displayWithTitle(right*right, title=right.texLabel+'^2')


$\displaystyle [=\begin{equation*} 0.5 -0.5 \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle [^2=\begin{equation*} 0.5 -0.5 \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle ]=\begin{equation*} 0.5 + 0.5 \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$
$\displaystyle ]^2=\begin{equation*} 0.5 + 0.5 \boldsymbol{e}_{1}\wedge \boldsymbol{e}_{2}\wedge \boldsymbol{e}_{3}\wedge \boldsymbol{e}_{4} \end{equation*}$

In [ ]: