Cadabra
a field-theory motivated approach to computer algebra

map_sympy

Map Sympy algorithms to Cadabra expressions
Cadabra expressions are typically tensor expressions, which you cannot feed directly into Sympy. With the map_sympy function you can recursively apply Sympy algorithms to the scalar parts of Cadabra expressions. The simplest example is when you have a scalar expression in Cadabra, for instance
ex:= \int{\sin(x)}{x};
\(\displaystyle{}\int \sin{x}\,\,{\rm d}x\)
map_sympy(ex);
\(\displaystyle{}-\cos{x}\)
The inert Cadabra expression gets evaluated by Sympy and then stored again in the `ex` object,
ex;
\(\displaystyle{}-\cos{x}\)
In more complicated cases you may have a tensorial expression which you would like to simplify using Sympy, for instance
ex:= (\sin(x)**2 + \cos(x)**2) A_{m} - A_{m};
\(\displaystyle{}\left({\left(\sin{x}\right)}^{2}+{\left(\cos{x}\right)}^{2}\right) A_{m}-A_{m}\)
map_sympy(ex, "simplify");
\(\displaystyle{}0\)
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science