{ "cells" : [ { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\section*{Printing expressions in various formats}\n\\subsection*{Basic usage}\n\nWith basic use of Cadabra, you will typically display your expressions by postfixing them with a semi-colon,\nas in" } ], "hidden" : true, "source" : "\\section*{Printing expressions in various formats}\n\\subsection*{Basic usage}\n\nWith basic use of Cadabra, you will typically display your expressions by postfixing them with a semi-colon,\nas in" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_origin" : "server", "cell_type" : "input_form", "source" : "A_{m n} (B^{n} + 3C^{n})" } ], "source" : "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source" : "ex:=A_{m n} ( B^{n} + 3 C^{n} );" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "What happens behind the scenes is that the semi-colon gets translated to a call of \\verb|display| on the \nlast-entered expression. It is therefore equivalent to " } ], "hidden" : true, "source" : "What happens behind the scenes is that the semi-colon gets translated to a call of \\verb|display| on the \nlast-entered expression. It is therefore equivalent to " }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_origin" : "server", "cell_type" : "input_form", "source" : "A_{m n} (B^{n} + 3C^{n})" } ], "source" : "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source" : "display(ex)" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "If you do not want to display the expression, post-fix with a colon, as in" } ], "hidden" : true, "source" : "If you do not want to display the expression, post-fix with a colon, as in" }, { "cell_origin" : "client", "cell_type" : "input", "source" : "ex:=A_{m n} ( B^{n} + 3 C^{n} ):" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "If you want to display an expression again later, you can just write the name of the expression followed\nby a semi-colon, or use the \\verb|display| function again," } ], "hidden" : true, "source" : "If you want to display an expression again later, you can just write the name of the expression followed\nby a semi-colon, or use the \\verb|display| function again," }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_origin" : "server", "cell_type" : "input_form", "source" : "A_{m n} (B^{n} + 3C^{n})" } ], "source" : "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" }, { "cell_origin" : "server", "cell_type" : "latex_view", "cells" : [ { "cell_origin" : "server", "cell_type" : "input_form", "source" : "A_{m n} (B^{n} + 3C^{n})" } ], "source" : "\\begin{dmath*}{}A_{m n} \\left(B^{n}+3C^{n}\\right)\\end{dmath*}" } ], "source" : "ex;\ndisplay(ex)" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "Note that while it may be tempting to use \\verb|print(ex)|, the \\verb|display| function is better because\nit knows about the capabilities of the interface used, and it will automatically select a text output when\nyou use Cadabra from the terminal, or \\LaTeX{} output when you use it in the graphical notebook." } ], "hidden" : true, "source" : "Note that while it may be tempting to use \\verb|print(ex)|, the \\verb|display| function is better because\nit knows about the capabilities of the interface used, and it will automatically select a text output when\nyou use Cadabra from the terminal, or \\LaTeX{} output when you use it in the graphical notebook." }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\subsection*{Other output formats}\n\nCadabra expressions are standard Python objects, and as such they have a \\verb|__str__| method which\nconverts them into a printable expression, and a \\verb|__repr__| method to produce a machine readable form.\nThese are called by the standard \\verb|str| and \\verb|repr| Python functions, as the examples below show." } ], "hidden" : true, "source" : "\\subsection*{Other output formats}\n\nCadabra expressions are standard Python objects, and as such they have a \\verb|__str__| method which\nconverts them into a printable expression, and a \\verb|__repr__| method to produce a machine readable form.\nThese are called by the standard \\verb|str| and \\verb|repr| Python functions, as the examples below show." }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "output", "source" : "\\begin{verbatim}A_{m n} (B^{n} + 3C^{n})\n\\end{verbatim}" } ], "source" : "print(str(ex))" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "output", "source" : "\\begin{verbatim}\\prod(A_{m n})(\\sum(B^{n})(3C^{n}))\n\\end{verbatim}" } ], "source" : "print(repr(ex))" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "In addition there are some methods to obtain output useful in other software: Mathematica, \\LaTeX{} and Sympy:" } ], "hidden" : true, "source" : "In addition there are some methods to obtain output useful in other software: Mathematica, \\LaTeX{} and Sympy:" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "output", "source" : "\\begin{verbatim}A[DNm, DNn]*(B[UPn]+3*C[UPn])\n\\end{verbatim}" } ], "source" : "print(ex.mma_form())" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "output", "source" : "\\begin{verbatim}A_{m n} \\left(B^{n}+3C^{n}\\right)\n\\end{verbatim}" } ], "source" : "print(ex._latex_())" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "output", "source" : "\\begin{verbatim}A(DNm, DNn)*(B(UPn)+3*C(UPn))\n\\end{verbatim}" } ], "source" : "print(ex.sympy_form())" }, { "cell_origin" : "client", "cell_type" : "input", "source" : "" } ], "description" : "Cadabra JSON notebook format", "version" : 1 }