Cadabra
a field-theory motivated approach to computer algebra

Differential forms

Cadabra can handle the calculus of differential forms. Differential forms are declared by attaching the property DifferentialForm to an object, as in the example below, where we declare four forms, with degree 0 to 3, and one form with symbolic degree $p$.
A0::LaTeXForm("A^{(0)}"). A1::LaTeXForm("A^{(1)}"). A2::LaTeXForm("A^{(2)}"). A3::LaTeXForm("A^{(3)}"). Bp::LaTeXForm("B^{(p)}"). A0::DifferentialForm(degree=0); A1::DifferentialForm(degree=1); A2::DifferentialForm(degree=2); A3::DifferentialForm(degree=3); Bp::DifferentialForm(degree=p);
\(\displaystyle{}\text{Attached property DifferentialForm to }A^{(0)}.\)
\(\displaystyle{}\text{Attached property DifferentialForm to }A^{(1)}.\)
\(\displaystyle{}\text{Attached property DifferentialForm to }A^{(2)}.\)
\(\displaystyle{}\text{Attached property DifferentialForm to }A^{(3)}.\)
\(\displaystyle{}\text{Attached property DifferentialForm to }B^{(p)}.\)
The exterior product (or wedge product) of forms is denoted with a ^ symbol (make sure to put a space before and after this symbol to avoid confusion with a superscript).
ex:=A1 ^ A2 + A2 ^ A1;
\(\displaystyle{}A^{(1)}\wedge A^{(2)}+A^{(2)}\wedge A^{(1)}\)
\wedge(A1 , A2) + \wedge(A2 , A1)
sort_product(_);
\(\displaystyle{}2A^{(1)}\wedge A^{(2)}\)
2\wedge(A1 , A2)
ex:=A1 ^ A2 ^ A1; sort_product(_);
\(\displaystyle{}A^{(1)}\wedge A^{(2)}\wedge A^{(1)}\)
\wedge(A1 , A2 , A1)
\(\displaystyle{}0\)
0
ex:= A3 ^ A2 ^ A1 ^ A2; sort_product(_);
\(\displaystyle{}A^{(3)}\wedge A^{(2)}\wedge A^{(1)}\wedge A^{(2)}\)
\wedge(A3 , A2 , A1 , A2)
\(\displaystyle{}-A^{(1)}\wedge A^{(2)}\wedge A^{(2)}\wedge A^{(3)}\)
-\wedge(A1 , A2 , A2 , A3)
An exterior derivative can be declared by using the ExteriorDerivative property. Applying an exterior derivative twice produces zero, and it obeys the product rule taking into account the degree of differential forms.
d{#}::ExteriorDerivative; d{#}::LaTeXForm("{\rm d}").
\(\displaystyle{}\text{Attached property ExteriorDerivative to }d{\#}.\)
ex2:= d{ @(ex) };
\(\displaystyle{}2{\rm d}\left(A^{(1)}\wedge A^{(2)}\right)\)
product_rule(_);
\(\displaystyle{}2{\rm d}{A^{(1)}}\wedge A^{(2)}-2A^{(1)}\wedge {\rm d}{A^{(2)}}\)
ex:= d{ A1 ^ A2 ^ d{ A3 } };
\(\displaystyle{}{\rm d}\left(A^{(1)}\wedge A^{(2)}\wedge {\rm d}{A^{(3)}}\right)\)
product_rule(_);
\(\displaystyle{}{\rm d}{A^{(1)}}\wedge A^{(2)}\wedge {\rm d}{A^{(3)}}-A^{(1)}\wedge {\rm d}{A^{(2)}}\wedge {\rm d}{A^{(3)}}\)
sort_product(_);
\(\displaystyle{}A^{(2)}\wedge {\rm d}{A^{(1)}}\wedge {\rm d}{A^{(3)}}-A^{(1)}\wedge {\rm d}{A^{(2)}}\wedge {\rm d}{A^{(3)}}\)
Two forms in a product can only be swapped around if one of their degrees is zero:
ex4:= A2 A0 + A0 A2; sort_product(_);
\(\displaystyle{}A^{(2)} A^{(0)}+A^{(0)} A^{(2)}\)
\(\displaystyle{}2A^{(0)} A^{(2)}\)
In a wedge product, forms can be swapped around taking into account their degree:
ex5:= A3 ^ A1 - A1 ^ A3 + A2 ^ A2 ^ A0; sort_product(_);
\(\displaystyle{}A^{(3)}\wedge A^{(1)}-A^{(1)}\wedge A^{(3)}+A^{(2)}\wedge A^{(2)}\wedge A^{(0)}\)
\(\displaystyle{}-2A^{(1)}\wedge A^{(3)}+A^{(0)}\wedge A^{(2)}\wedge A^{(2)}\)
Differential forms can have tensor indices, e.g. for vielbeine or spin connections:
{a,b,c}::Indices; e^{a}::DifferentialForm(degree=1); \omega^{a}_{b}::DifferentialForm(degree=2);
\(\displaystyle{}\text{Attached property Indices(position=free) to }\left[a, b, c\right].\)
\(\displaystyle{}\text{Attached property DifferentialForm to }e^{a}.\)
\(\displaystyle{}\text{Attached property DifferentialForm to }\omega^{a}\,_{b}.\)
ex:=d{e^{a}} = - \omega^{a}_{b} ^ e^{b};
\(\displaystyle{}{\rm d}{e^{a}} = -\omega^{a}\,_{b}\wedge e^{b}\)
cv:= d{ @(ex) };
\(\displaystyle{}0 = -{\rm d}\left(\omega^{a}\,_{b}\wedge e^{b}\right)\)
distribute(cv); product_rule(cv);
\(\displaystyle{}0 = -{\rm d}\left(\omega^{a}\,_{b}\wedge e^{b}\right)\)
\(\displaystyle{}0 = -{\rm d}{\omega^{a}\,_{b}}\wedge e^{b}-\omega^{a}\,_{b}\wedge {\rm d}{e^{b}}\)
substitute(cv, ex);
\(\displaystyle{}0 = -{\rm d}{\omega^{a}\,_{b}}\wedge e^{b}+\omega^{a}\,_{b}\wedge \omega^{b}\,_{c}\wedge e^{c}\)
Some more random assorted ramblings below, not finished yet!!!
ex4:= d{ @(ex5) };
\(\displaystyle{}{\rm d}\left(-2A^{(1)}\wedge A^{(3)}+A^{(0)}\wedge A^{(2)}\wedge A^{(2)}\right)\)
distribute(_);
\(\displaystyle{}-2{\rm d}\left(A^{(1)}\wedge A^{(3)}\right)+{\rm d}\left(A^{(0)}\wedge A^{(2)}\wedge A^{(2)}\right)\)
product_rule(_);
\(\displaystyle{}-2{\rm d}{A^{(1)}}\wedge A^{(3)}+2A^{(1)}\wedge {\rm d}{A^{(3)}}+{\rm d}{A^{(0)}}\wedge A^{(2)}\wedge A^{(2)}+A^{(0)}\wedge {\rm d}{A^{(2)}}\wedge A^{(2)}+A^{(0)}\wedge A^{(2)}\wedge {\rm d}{A^{(2)}}\)
sort_product(_);
\(\displaystyle{}-2A^{(3)}\wedge {\rm d}{A^{(1)}}+2A^{(1)}\wedge {\rm d}{A^{(3)}}+A^{(2)}\wedge A^{(2)}\wedge {\rm d}{A^{(0)}}+2A^{(0)}\wedge A^{(2)}\wedge {\rm d}{A^{(2)}}\)
{i,j,k,l}::Indices(values={1,2,3}); {i,j,k,l}::Integer(1..3); \epsilon^{i j k}::EpsilonTensor; d{#}::ExteriorDerivative; d{#}::LaTeXForm("{\rm d}").
\(\displaystyle{}\text{Attached property Indices(position=free) to }\left\{i, \mmlToken{mo}[linebreak="goodbreak"]{} j, \mmlToken{mo}[linebreak="goodbreak"]{} k, \mmlToken{mo}[linebreak="goodbreak"]{} l\right\}.\)
\(\displaystyle{}\text{Attached property Integer to }\left\{i, \mmlToken{mo}[linebreak="goodbreak"]{} j, \mmlToken{mo}[linebreak="goodbreak"]{} k, \mmlToken{mo}[linebreak="goodbreak"]{} l\right\}.\)
\(\displaystyle{}\text{Attached property EpsilonTensor to }\epsilon^{i j k}.\)
\(\displaystyle{}\text{Attached property ExteriorDerivative to }{\rm d}{\#}.\)
ex:=\epsilon^{i j k};
\(\displaystyle{}\epsilon^{i j k}\)
evaluate(_, $$);
rl:= { \Sigma^{1} = \cos{\psi} d{\theta} + \sin{\psi} \sin{\theta} d{\phi}, \Sigma^{2} = -\sin{\psi} d{\theta} + \cos{\psi} \sin{\theta} d{\phi}, \Sigma^{3} = \cos{\theta} d{\phi} + d{\psi} };
\(\displaystyle{}\left\{\Sigma^{1} = \cos{\psi} {\rm d}{\theta}+\sin{\psi} \sin{\theta} {\rm d}{\phi}, \mmlToken{mo}[linebreak="goodbreak"]{} \Sigma^{2} = -\sin{\psi} {\rm d}{\theta}+\cos{\psi} \sin{\theta} {\rm d}{\phi}, \mmlToken{mo}[linebreak="goodbreak"]{} \Sigma^{3} = \cos{\theta} {\rm d}{\phi}+{\rm d}{\psi}\right\}\)
tst:= -1/2 \epsilon^{i j k} \Sigma^{j} ^ \Sigma^{k};
\(\displaystyle{} - \frac{1}{2}\epsilon^{i j k} \Sigma^{j}\wedge \Sigma^{k}\)
evaluate(tst, rl);
\(\displaystyle{}0\)
Copyright © 2001-2018 Kasper Peeters
Questions? info@cadabra.science