What am I doing wrong with apart()?

102 views
Skip to first unread message

Francesco Biscani

unread,
Mar 10, 2015, 10:57:11 AM3/10/15
to sympy
Hello list,

I feel a bit embarrassed as probably I am doing something blatantly wrong, but I cannot understand what is going here. Consider this snippet (copy pasted from an Ipython notebook):

"""
import sympy
sympy.init_printing()
from sympy import Symbol,sqrt,cos,sin,solve,Function,atan,apart,S

# Some symbols
h,n,m,M,g,t,xi_s,eta_s = [Symbol(_) for _ in ['h','n','m','M','g','t',r'\xi',r'\eta']]
pxi,peta = [Symbol(_) for _ in [r'p_\xi',r'p_\eta']]

# A rational expression
foo = 32*eta_s**8*g*m/(eta_s**2+xi_s**2)**3-64*eta_s**6*g*m/(eta_s**2+xi_s**2)**2-23*g/2*eta_s**2*m-7*g/2*xi_s**2*m+(320*eta_s**4*g*m**2+peta**2+pxi**2)/(8*m*(eta_s**2+xi_s**2))
"""

Now if I do "foo_apart(xi_s)", it seems like there are two parts of the expression that disappear. (specifically, -23*g/2*eta_s**2*m-7*g/2*xi_s**2*m is not there any more). Indeed, if I do:

"""
foo.apart(xi_s).expand() == foo.expand()
"""

This returns False.

My brain is a bit fried at the moment :) So what am I overlooking here?

Cheers,

  Francesco.

Francesco Biscani

unread,
Mar 10, 2015, 1:28:11 PM3/10/15
to sympy
A much reduced testcase:

x,y = [Symbol(_) for _ in ['x','y']]
foo = 1/(x+y)-Rational(1,2)*x**2
print(foo.apart(x))

This prints:

1/(x + y)

If the Rational has an integral value, everything looks ok:

foo = 1/(x+y)-Rational(6)*x**2
print(foo.apart(x))

Output: -6*x**2 + 1/(x + y)

Aaron Meurer

unread,
Mar 10, 2015, 2:07:30 PM3/10/15
to sy...@googlegroups.com
It looks like a bug. If you do foo.expand() - foo.apart(xi_s).expand()
you get a term which is definitely not equal to zero.

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/CAHExjCsbts1UA_p%3DB6g-%2B6H7ny_MJomiaCjb5YgzSMAgDTs08g%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Smith

unread,
Mar 11, 2015, 2:17:48 PM3/11/15
to sy...@googlegroups.com
Check the version of SymPy that you are using. The development version gives

>>> var('x y')
(x, y)
>>> apart(1/(x+y)-Rational(1,2)*x**2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\utilities\decorator.py", line 35, in threaded_func
    return func(expr, *args, **kwargs)
  File "sympy\polys\partfrac.py", line 123, in apart
    return apart(fc, x=x, full=full, **_options)
  File "sympy\utilities\decorator.py", line 35, in threaded_func
    return func(expr, *args, **kwargs)
  File "sympy\polys\partfrac.py", line 126, in apart
    "multivariate partial fraction decomposition")
NotImplementedError: multivariate partial fraction decomposition

Aaron Meurer

unread,
Mar 11, 2015, 3:05:50 PM3/11/15
to sy...@googlegroups.com
The foo.expand() - foo.apart(xi_s).expand() issue is there for me on
the master version of SymPy.

Aaron Meurer
> https://groups.google.com/d/msgid/sympy/e7daf358-3af7-4c36-b088-9ed11d6c67b4%40googlegroups.com.

Chris Smith

unread,
Mar 11, 2015, 7:26:49 PM3/11/15
to sy...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages