Ask Your Question

How to get sage to NOT calculate

asked 2013-06-08 14:37:56 +0100

anonymous user


updated 2013-06-09 05:52:30 +0100

tmonteil gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-06-08 17:04:51 +0100

tmonteil gravatar image

updated 2013-06-08 17:11:27 +0100

Some 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
sage: a.power(2)
sage: a.power(2, hold=True)
sage: pi.cos(hold=True)

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
sage: a.add(SR(3), hold=True)
edit flag offensive delete link more

answered 2013-08-04 21:46:20 +0100

Pavel Yartsev gravatar image

You 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)
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


Asked: 2013-06-08 14:37:56 +0100

Seen: 555 times

Last updated: Aug 04 '13