GithubHelp home page GithubHelp logo

Comments (3)

oscarbenjamin avatar oscarbenjamin commented on June 23, 2024

The call to cancel here fails:

f, x, U = P/Q, P.gen, []
u = Function('u')(x)
a = Dummy('a')
partial = []
for d, n in Q.sqf_list_include(all=True):
b = d.as_expr()
U += [ u.diff(x, n - 1) ]
h = cancel(f*b**n) / u**n

It is assumed that since f = P/Q and b**n is a factor of Q then cancel(f*b**n) will cancel the factor of b**n out of the denominator of f. This fails with floats though since b**n might not exactly divide Q.

We know that it is supposed to divide Q so we can just compute the quotient and discard the remainder:

diff --git a/sympy/polys/partfrac.py b/sympy/polys/partfrac.py
index 000c5d7354..b9a5d32609 100644
--- a/sympy/polys/partfrac.py
+++ b/sympy/polys/partfrac.py
@@ -379,7 +379,7 @@ def apart_list_full_decomposition(P, Q, dummygen):
         b = d.as_expr()
         U += [ u.diff(x, n - 1) ]
 
-        h = cancel(f*b**n) / u**n
+        h = cancel(P/Q.quo(d**n)) / u**n
 
         H, subs = [h], []

That gives the correct answer albeit with some nontrivial rounding error:

In [1]: e = (6.43369157032015e-9*x**3 + 1.35203404799555e-5*x**2 + 0.00357538393743079*x + 0.085)/(4.
   ...: 74334912634438e-11*x**4 + 4.09576274286244e-6*x**3 + 0.00334241812250921*x**2 + 0.15406018058
   ...: 983*x + 1.0)

In [2]: apart(nsimplify(e), full=True).evalf()
Out[2]: 
  133.599202650992      1.07757928431867      0.395006955518971      0.564264854137341  
──────────────────── + ─────────────────── + ──────────────────── + ────────────────────
x + 85524.0054884464   x + 774.88576677949   x + 40.7977016133126   x + 7.79746609204661

In [3]: apart(e, full=True).evalf()
Out[3]: 
  133.594113472755      1.07757928431773      0.395006955518863      0.564264854137269  
──────────────────── + ─────────────────── + ──────────────────── + ────────────────────
x + 85524.0054884464   x + 774.88576677949   x + 40.7977016133126   x + 7.79746609204661

from sympy.

oscarbenjamin avatar oscarbenjamin commented on June 23, 2024

A little more is needed:

diff --git a/sympy/polys/partfrac.py b/sympy/polys/partfrac.py
index 000c5d7354..1ee1f653e0 100644
--- a/sympy/polys/partfrac.py
+++ b/sympy/polys/partfrac.py
@@ -368,6 +368,8 @@ def apart_list_full_decomposition(P, Q, dummygen):
     .. [1] [Bronstein93]_
 
     """
+    P_orig, Q_orig = P, Q
+
     f, x, U = P/Q, P.gen, []
 
     u = Function('u')(x)
@@ -379,7 +381,7 @@ def apart_list_full_decomposition(P, Q, dummygen):
         b = d.as_expr()
         U += [ u.diff(x, n - 1) ]
 
-        h = cancel(f*b**n) / u**n
+        h = cancel(P_orig/Q_orig.quo(d**n)) / u**n
 
         H, subs = [h], []

from sympy.

oscarbenjamin avatar oscarbenjamin commented on June 23, 2024

I've opened gh-26649 with a fix.

from sympy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.