ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 04 Aug 2013 21:46:20 +0200How to get sage to NOT calculatehttps://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/I would like to be able to give some variables a value and have sage show it to me in a pritty format.
For example if i have;
a = 2
b = 3
and then I input a+b and sage returns 2+3
Is there a command that let me do this? Sat, 08 Jun 2013 14:37:56 +0200https://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/Answer by Pavel Yartsev for <p>I would like to be able to give some variables a value and have sage show it to me in a pritty format. </p>
<p>For example if i have;
a = 2
b = 3
and then I input a+b and sage returns 2+3</p>
<p>Is there a command that let me do this? </p>
https://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/?answer=15311#post-id-15311You can just use strings. Nothing fancy just printing out exactly what you want.
sage: a = 2
sage: b = 3
sage: print str(a)+"+"+str(b)
"2+3"Sun, 04 Aug 2013 21:46:20 +0200https://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/?answer=15311#post-id-15311Answer by tmonteil for <p>I would like to be able to give some variables a value and have sage show it to me in a pritty format. </p>
<p>For example if i have;
a = 2
b = 3
and then I input a+b and sage returns 2+3</p>
<p>Is there a command that let me do this? </p>
https://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/?answer=15046#post-id-15046Some methods for symbolic expressions have a `hold` argument, this allows to prevent simplification of expressions. For example:
sage: a = sqrt(2)
sage: a.parent()
Symbolic Ring
sage: a^2
2
sage: a.power(2)
2
sage: a.power(2, hold=True)
sqrt(2)^2
sage: pi.cos(hold=True)
cos(pi)
It also works for addition in certain cases:
sage: x.parent()
Symbolic Ring
sage: x.add(x, hold=True)
x + x
Unfortunately, it seems not to work for elements of the `Symbolic Ring` that represent integers:
sage: a = SR(2)
sage: a.parent()
Symbolic Ring
sage: a
2
sage: a.add(SR(3), hold=True)
5
Sat, 08 Jun 2013 17:04:51 +0200https://ask.sagemath.org/question/10207/how-to-get-sage-to-not-calculate/?answer=15046#post-id-15046