Ask Your Question

Printing _sage_var_x instead of x

asked 2018-09-07 18:53:59 -0500

anonymous user


Following the section "symbolic maths" in the quickstar of sagemath's web page I put

sage: f=1-sin(x)^2

If I write Print(f) it works fine, but when I do the "pretty printing" :

sage: print(maxima(f))

I get


instead of $$1-sin²(x)$$

which the quickstart says I should get. Why I am printing "_sage_var_x" and how can I replace it by just $x$?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2018-09-08 11:39:33 -0500

nbruin gravatar image

This is because in sage the following is legal (but probably ill-advised): sin(SR.symbol('sin')). With the _SAGE_VAR_ prefix, this translates into an expression in maxima that roughly captures the same meaning. Without it, you get a maxima expression that means something else.

You can create expressions like sin(maxima('x')), but if you want expressions to go back and forth between maxima and sage, it's better to stick with the prefixes that sage uses.

edit flag offensive delete link more

answered 2018-09-09 05:08:52 -0500

eric_g gravatar image

updated 2018-09-09 07:39:13 -0500

Thanks for reporting this! Indeed the documentation at is obsolete and should be fixed (I've opened issue #151 for it). As for the reason why you get _SAGE_VAR_x now, see the explanation in @nbruin 's answer. To get the pretty printing in console mode, simply use the magic command %display ascii_art:

sage: %display ascii_art
sage: f = 1 - sin(x)^2
sage: f
- sin (x) + 1

Note that you can use LaTeX typeset display by %display latex:

sage: %display latex
sage: f
\newcommand{\Bold}[1]{\mathbf{#1}}-\sin\left(x\right)^{2} + 1

However, this display mode is more adapted to the Jupyter notebook: there you really get the typeset display (see e.g. here for some example), not the raw LaTeX code.

NB: for an up-to-date quick start guide, see the Chapter First Steps of the recent free book Computational Mathematics with SageMath.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-09-07 18:53:34 -0500

Seen: 51 times

Last updated: Sep 09