Anyone know why I don't get symbolic results by default?

54 views
Skip to first unread message

Andre Yonadam

unread,
Feb 17, 2015, 12:16:19 PM2/17/15
to sy...@googlegroups.com
I was writing out a Python file by hand and wasn't getting the symbolic results only when using default operators. For example, when dividing 1/3 it would return a decimal answer while if I used the Integral function it would give me the right result.

Ondřej Čertík

unread,
Feb 17, 2015, 12:28:03 PM2/17/15
to sympy
Hi Andre,

Can you post your Python code? In Python 2.x, 1/3 returns 0, while in
Python 3.x, 1/3 returns 0.3333. You can also turn on the Python 3.x
behavior on 2.x with a future import.

Ondrej
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/5ba37888-554a-42fd-b961-f38466a729d1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jason Moore

unread,
Feb 17, 2015, 12:28:04 PM2/17/15
to sy...@googlegroups.com
On Tue, Feb 17, 2015 at 9:16 AM, Andre Yonadam <agy...@gmail.com> wrote:
I was writing out a Python file by hand and wasn't getting the symbolic results only when using default operators. For example, when dividing 1/3 it would return a decimal answer while if I used the Integral function it would give me the right result.

--
Message has been deleted

Aaron Meurer

unread,
Feb 17, 2015, 1:07:18 PM2/17/15
to sy...@googlegroups.com
The SymPy Live shell does some preparsing of the input to prevent 1/3
from being converted to 0.33333333333. In a normal Python shell, this
does not happen. You should use Rational(1, 3) or S(1)/3. The link
Jason gave explains why this is necessary.

Aaron Meurer

On Tue, Feb 17, 2015 at 11:57 AM, Andre Yonadam <agy...@gmail.com> wrote:
> Hi thanks for the reply. I wanted to do a simple division and print it out.
> For example print("%d", 5/6). The problem is it doesn't return the formatted
> result like it would in the shell. Do I have to use the S function?
> https://groups.google.com/d/msgid/sympy/7ba91a47-6809-4aef-a693-db77e3265ce9%40googlegroups.com.

Andre Yonadam

unread,
Feb 17, 2015, 1:15:08 PM2/17/15
to sy...@googlegroups.com
Thanks. So the only way of doing in a normal Python shell is to use the S function. Does the S function have any limitations compared to the SymPy Live shell?

Andre Yonadam

unread,
Feb 17, 2015, 1:15:23 PM2/17/15
to sy...@googlegroups.com
Hi thanks for the reply. I wanted to do a simple division and print it out. For example print("%d", 5/6). The problem is it doesn't return the formatted result like it would in the shell. Do I have to use the S function?

On Tuesday, February 17, 2015 at 12:07:18 PM UTC-6, Aaron Meurer wrote:

Andre Yonadam

unread,
Feb 20, 2015, 8:56:57 PM2/20/15
to sy...@googlegroups.com
I was still wondering if there was anyway to change it so the SymPy handles the default data types or a way for Sympy to handle all the calculations symbolically automatically. For example I can do print(latex((Integer(1)/Integer(3)))) to get the desired output, but without the Integer it wouldn't return it in latex.

Aaron Meurer

unread,
Feb 20, 2015, 10:13:45 PM2/20/15
to sy...@googlegroups.com
If you use isympy, you can use isympy -i or isympy -I.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/160ac3d1-46d0-4f28-83e0-f0df80e803d6%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages