Very Basic Question on Simplify

42 views
Skip to first unread message

Lorenzo Isella

unread,
Feb 1, 2017, 12:51:37 PM2/1/17
to sy...@googlegroups.com
Dear All,
I am making my first baby steps with sympy and I must be
misunderstanding something.
I want to simplify the expression

(N**2/8 -1/8)/((N-1)/2) hence this is what I do in a ipython shell

n [2]: from sympy import *

In [3]: var("N")
Out[3]: N

In [4]: simplify((N**2/8 -1/8)/((N-1)/2))
Out[4]: N**2/(4*(N - 1))

however, the right result is (N+1)/4.

It is not rocket science, so what (obvious) thing am I missing?
Many thanks

Lorenzo

Aaron Meurer

unread,
Feb 1, 2017, 1:49:07 PM2/1/17
to sy...@googlegroups.com
The problem is the 1/8. I Python 2, this evaluates to 0, because of
integer division. I recommend using Python 3, or if you must use
Python 2, use "from __future__ import division". That will cause 1/8
to evaluate to the float 0.125.

For SymPy, it is best to use rational numbers, like Rational(1, 8).

See also http://docs.sympy.org/latest/tutorial/gotchas.html#two-final-notes-and.

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 https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/20170201153814.GA3881%40chicca.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages