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{Property DifferentialForm attached to }A^{(0)}.\)
\(\displaystyle{}\text{Property DifferentialForm attached to }A^{(1)}.\)
\(\displaystyle{}\text{Property DifferentialForm attached to }A^{(2)}.\)
\(\displaystyle{}\text{Property DifferentialForm attached to }A^{(3)}.\)
\(\displaystyle{}\text{Property DifferentialForm attached 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)}\)
sort_product(_);
\(\displaystyle{}2\,A^{(1)}\wedge A^{(2)}\)
ex:=A1 ^ A2 ^ A1; sort_product(_);
\(\displaystyle{}A^{(1)}\wedge A^{(2)}\wedge A^{(1)}\)
\(\displaystyle{}0\,\)
ex:= A3 ^ A2 ^ A1 ^ A2; sort_product(_);
\(\displaystyle{}A^{(3)}\wedge A^{(2)}\wedge A^{(1)}\wedge A^{(2)}\)
\(\displaystyle{}-\,A^{(1)}\wedge A^{(2)}\wedge A^{(2)}\wedge A^{(3)}\)
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{Property ExteriorDerivative attached to }d{\#}.\)
ex2:= d{ @(ex) };
\(\displaystyle{}-\,{\rm d}\left(A^{(1)}\wedge A^{(2)}\wedge A^{(2)}\wedge A^{(3)}\right)\)
product_rule(_);
\(\displaystyle{}-\,{\rm d}{A^{(1)}}\wedge A^{(2)}\wedge A^{(2)}\wedge A^{(3)} +A^{(1)}\wedge {\rm d}{A^{(2)}}\wedge A^{(2)}\wedge A^{(3)} +A^{(1)}\wedge A^{(2)}\wedge {\rm d}{A^{(2)}}\wedge A^{(3)} +A^{(1)}\wedge A^{(2)}\wedge A^{(2)}\wedge {\rm d}{A^{(3)}}\)
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{}2\,A^{(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{}-2\,A^{(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. In the example below the spin connection is a one-form:
{a,b,c}::Indices; {e^{a}, \omega^{a}_{b}}::DifferentialForm(degree=1);
\(\displaystyle{}\text{Property Indices(position=free) attached to }\left[a, b, c\right].\)
\(\displaystyle{}\text{Property DifferentialForm attached to }\left[e^{a}, \omega^{a}\,_\!{b}\right].\)
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}\)
rename_dummies(cv);
\(\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(-2\,A^{(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)} +2\,A^{(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{}-2\,A^{(3)}\wedge {\rm d}{A^{(1)}} +2\,A^{(1)}\wedge {\rm d}{A^{(3)}} +A^{(2)}\wedge A^{(2)}\wedge {\rm d}{A^{(0)}} +2\,A^{(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{Property Indices(position=free, values=\{{1} , {1} 2 , {1} 3 \}) attached to }\left[i, j, k, l\right].\)
\(\displaystyle{}\text{Property Integer attached to }\left[i, j, k, l\right].\)
\(\displaystyle{}\text{Property EpsilonTensor attached to }\epsilon^{i j k}.\)
\(\displaystyle{}\text{Property ExteriorDerivative attached to }{\rm d}{\#}.\)
ex:=\epsilon^{i j k};
\(\displaystyle{}\epsilon^{i j k}\)
evaluate(_);
\(\displaystyle{}\square{}^{i}{}^{j}{}^{k}\left\{\begin{aligned}\square{}^{1}{}^{2\,}{}^{3\,}& = 1\\[-.5ex] \square{}^{1}{}^{3\,}{}^{2\,}& = -\,1\\[-.5ex] \square{}^{2\,}{}^{1}{}^{3\,}& = -\,1\\[-.5ex] \square{}^{2\,}{}^{3\,}{}^{1}& = 1\\[-.5ex] \square{}^{3\,}{}^{1}{}^{2\,}& = 1\\[-.5ex] \square{}^{3\,}{}^{2\,}{}^{1}& = -\,1\\[-.5ex] \end{aligned}\right. \)
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}, \Sigma^{2} = -\sin{\psi} {\rm d}{\theta}+\cos{\psi} \sin{\theta} {\rm d}{\phi}, \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-2025 Kasper Peeters
Questions? info@cadabra.science