This is a short and simple Jupyter notebook shows how to use Cadabra functionality from with Jupyter. The first thing to do is to import the cadabra2 module. To save typing, we will import everything into the global namespace.

In :
from cadabra2 import *
from IPython.display import display, Math, Latex


Expressions are declared by typing them as standard LaTeX, and feeding that into the Ex object. The result is a standard Python object.

In :
ex=Ex(r"A_{m n} B^{m n}")


Printing is still a bit messy in IPython/Jupyter, but you can get the nicely typeset form of the expression using the following:

In :
display(Math(str(ex)))

$$A_{m n} B^{m n}$$

Properties get assigned to symbols or patterns by using their Cadabra name,

In :
Symmetric(Ex(r"A_{m n}"))
AntiSymmetric(Ex(r"B_{m n"))

Out:
Property::repr: AntiSymmetric

Cadabra algorithms are ordinary python functions. They always act on the expression that you pass it, and modify it in-place. Here's an example: the contraction of an antisymmetric and a symmetric tensor is zero:

In :
display(Math(str(canonicalise(ex))))

$$C_{m}\,^{p} D_{p n} B^{m n}$$

Let's do another example, with substitution. Note how indices get relabelled automatically.

In :
Indices(Ex(r"{m,n,p,q,r,s,t}"))
ex=Ex(r"A_{m n} B^{m p} C_{p q}")
display(Math(str(substitute(ex, Ex(r"A_{m n} -> D_{m q} D^{q}_{n}")))))

$$D_{m r} D^{r}\,_{n} B^{m p} C_{p q}$$

If you are interested in more of this, get in touch by emailing me at info@cadabra.science !

In [ ]: