Cadabra

Basic calculus

Because Cadabra started as a tool for tensor manipulations, it has its own logic to manipulate mathematical expressions that contain tensors. However, it can use SymPy algorithms to manipulate the scalar parts of these expressions, and you can therefore combine the power of both in the same unified LaTeX notation.
Let's see this at the level of some simple computations. First, a Taylor series expansion done using SymPy, fed into Cadabra plotting functionality. We start from $\sin(x)$,
ex:=\sin(x);
\(\displaystyle{}\sin{x}\)
SymPy's calculus functionality is imported using a Cadabra package,
from cdb.sympy.calculus import *
You can now call SymPy functions on Cadabra ex expressions; here is a series expansion to 10th and 20th order:
s10 = series(ex, $x$, 0, 10);
\(\displaystyle{}x - \frac{1}{6}\,{x}^{3\,} +\frac{1}{120}\,{x}^{5\,} - \frac{1}{5040}\,{x}^{7\,} +\frac{1}{362880}\,{x}^{9\,} +{\cal O}\left({x}^{10\,}\right)\)
s20=series(ex, $x$, 0, 20);
\(\displaystyle{}x - \frac{1}{6}\,{x}^{3\,} +\frac{1}{120}\,{x}^{5\,} - \frac{1}{5040}\,{x}^{7\,} +\frac{1}{362880}\,{x}^{9\,} - \frac{1}{39916800}\,{x}^{11\,} +\frac{1}{6227020800}\,{x}^{13\,} - \frac{1}{1307674368000}\,{x}^{15\,} +\frac{1}{355687428096000}\,{x}^{17\,} - \frac{1}{121645100408832000}\,{x}^{19\,} +{\cal O}\left({x}^{20\,}\right)\)
Cadabra's plotting functionality resides in another package, from which we import plot, which we then use to plot the function and its two approximations,
from cdb.graphics.plot import *
plot([ex, s10, s20], ($x$,0,10), yrange=(-4,4), legend=["sin(x)", "O(10)", "O(20)"]);
You can differentiate just like in SymPy:
diff($sin(x)$, $y$);
\(\displaystyle{}0\,\)
diff($10 + 3*x + 4*y + 10*x**2 + x**9$, $x$);
\(\displaystyle{}9\,{x}^{8\,} +20\,x +3\,\)
diff($exp(-1/2 x**2 )$, $x$);
\(\displaystyle{}-\,\exp\left( - \frac{1}{2}\,{x}^{2\,}\right) x\)
or integrate
ex:=\int{\log{x}**2}{x};
\(\displaystyle{}\int {\log\left(x\right)}^{2\,}\,\,{\rm d}x\)
integrate($\log{x}**2$, $x$);
\(\displaystyle{}x {\log\left(x\right)}^{2\,} -2\,x \log\left(x\right) +2\,x\)