Cadabra
a field-theory motivated approach to computer algebra

cdb.sympy.calculus

Use SymPy calculus functionality on Cadabra expressions.
A lot of functionality in SymPy can be used on Cadabra expressions, but in order to correctly convert from and to the SymPy expression form, we need a bridge. This package contains such bridging fuctions, which will ensure that e.g. tensor indices are handled correctly when fed through SymPy's scalar algebra algorithms.

diff

Differentiate an expression with respect to one or more variables.
This function mimics the SymPy diff function, except that all expressions need to be Cadabra expressions. The function takes an expression and an arbitrary number of variables with respect to which to differentiate it.
A typical example, differentiating with respect to a single variable:
diff($\sin(x) A_{\mu}(x)$, $x$);
\(\displaystyle{}A_{\mu}\left(x\right) \cos{x}+\sin{x} \partial_{x}\left(A_{\mu}\left(x\right)\right)\)
A_{\mu}(x) \cos(x) + \sin(x) \partial_{x}(A_{\mu}(x))
diff($\sin(x)\cos(y)$, $x$, $y$);
\(\displaystyle{}-\sin{y} \cos{x}\)
-\sin(y) \cos(x)

integrate

Integrate a definite or indefinite integral.
This function mimics the SymPy integrate function, except that all mathematical expressions need to be Cadabra expressions. Indefinite integration is done by passing an argument which is just an expression, while definite integration is done by passing a tuple consisting of the integration variable, the starting point and the end point.
The following is an example of a definite integration:
integrate($x**2 y$, ($x$, 0, 3), ($y$, 0, 1) );
\(\displaystyle{}\frac{9}{2}\)
9/2
Here is an indefinite integration:
integrate($x**2$, $x$, $y$);
\(\displaystyle{}\frac{1}{3}{x}^{3} y\)
1/3 (x)**3 y
Mixed versions are also possible:
integrate($x y$, ($x$, 0, 1), $y$);
\(\displaystyle{}\frac{1}{4}{y}^{2}\)
1/4 (y)**2

limit

Take the limit of an expression.
This function mimics the SymPy limit function, except that all mathematical expressions need to be Cadabra expressions.
limit($\sin(x)/x$, $x$, 0);
\(\displaystyle{}1\)
1

series

Construct a Taylor series.
This function mimics the SymPy series function, except that all mathematical expressions need to be Cadabra expressions.
q=series($\sin(x)/x$, $x$, 0, 4);
\(\displaystyle{}1 - \frac{1}{6}{x}^{2}+{\cal O}\left({x}^{4}\right)\)
1 - 1/6 (x)**2 + {\cal O}((x)**4)
substitute(q, $\bigO(A??) ->0$);
\(\displaystyle{}1 - \frac{1}{6}{x}^{2}\)
1 - 1/6 (x)**2
series($\cos(x)$, $x$, $\pi/4$, 2);
\(\displaystyle{}\frac{1}{2}\sqrt{2}-\sqrt{2} \left(\frac{1}{2}x - \frac{1}{8}\pi\right)+{\cal O}\left({\left(x - \frac{1}{4}\pi\right)}^{2} , \left[x, \frac{1}{4}\pi\right]\right)\)
1/2 \sqrt(2)-\sqrt(2) ( 1/2 x - 1/8 \pi) + {\cal O}((x - 1/4 \pi)**2 , {x, 1/4 \pi})

factor

Factorise an expression
This function mimics the SymPy factor function, except that the argument has to be a Cadabra expression.
ex = factor($ x**2 + x $);
\(\displaystyle{}x \left(x+1\right)\)
x (x + 1)
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science