a field-theory motivated approach to computer algebra

Printing expressions in various formats

Basic usage

With basic use of Cadabra, you will typically display your expressions by postfixing them with a semi-colon, as in
ex:=A_{m n} ( B^{n} + 3 C^{n} );
\(\displaystyle{}A_{m n} \left(B^{n}+3C^{n}\right)\)
A_{m n} (B^{n} + 3C^{n})
What happens behind the scenes is that the semi-colon gets translated to a call of display on the last-entered expression. It is therefore equivalent to
\(\displaystyle{}A_{m n} \left(B^{n}+3C^{n}\right)\)
A_{m n} (B^{n} + 3C^{n})
If you do not want to display the expression, post-fix with a colon, as in
ex:=A_{m n} ( B^{n} + 3 C^{n} ):
If you want to display an expression again later, you can just write the name of the expression followed by a semi-colon, or use the display function again,
ex; display(ex)
\(\displaystyle{}A_{m n} \left(B^{n}+3C^{n}\right)\)
A_{m n} (B^{n} + 3C^{n})
\(\displaystyle{}A_{m n} \left(B^{n}+3C^{n}\right)\)
A_{m n} (B^{n} + 3C^{n})
Note that while it may be tempting to use print(ex), the display function is better because it knows about the capabilities of the interface used, and it will automatically select a text output when you use Cadabra from the terminal, or LaTeX output when you use it in the graphical notebook.

Other output formats

Cadabra expressions are standard Python objects, and as such they have a __str__ method which converts them into a printable expression, and a __repr__ method to produce a machine readable form. These are called by the standard str and repr Python functions, as the examples below show.
A_{m n} (B^{n} + 3C^{n})
\prod(A_{m n})(\sum(B^{n})(3C^{n}))
In addition there are some methods to obtain output useful in other software: Mathematica, LaTeX and Sympy:
A[DNm, DNn]*(B[UPn]+3*C[UPn])
A_{m n} \left(B^{n}+3C^{n}\right)
A(DNm, DNn)*(B(UPn)+3*C(UPn))
Copyright © 2001-2021 Kasper Peeters