Updates:
        Status: Started

Comment #2 on issue 2606 by asmeurer: Add degree_offset argument to heurisch()
http://code.google.com/p/sympy/issues/detail?id=2606

Here's a trivial implementation:

diff --git a/sympy/integrals/heurisch.py b/sympy/integrals/heurisch.py
index e51a070..65915c0 100644
--- a/sympy/integrals/heurisch.py
+++ b/sympy/integrals/heurisch.py
@@ -157,6 +157,7 @@ def heurisch(f, x, **kwargs):
     }

     rewrite = kwargs.pop('rewrite', False)
+    degree_offset = kwargs.pop('degree_offset', 0)

     if rewrite:
         for candidates, rule in rewritables.iteritems():
@@ -336,9 +337,9 @@ def exponent(g):
     A, B = exponent(f), a + max(b, c)

     if A > 1 and B > 1:
-        monoms = monomials(V, A + B - 1)
+        monoms = monomials(V, A + B - 1 + degree_offset)
     else:
-        monoms = monomials(V, A + B)
+        monoms = monomials(V, A + B + degree_offset)

     poly_coeffs = _symbols('A', len(monoms))

I already noticed that one of the simplest integrals that heurisch() cannot do, log(x)/x, can be done if you increase the degree by one:

In [1]: from sympy.integrals.heurisch import heurisch

In [2]: heurisch(log(x)/x, x, degree_offset=0)

In [3]: heurisch(log(x)/x, x, degree_offset=1)
Out[3]:
   2
log (x)
───────
   2

On the other hand, the very rapid increase in the number of monomials of a degree means that even this small change can slow down the function by quite a bit in the general case.

In [16]: heurisch(diff(log(x)**2*exp(x), x), x)
Out[16]:
 x    2
ℯ ⋅log (x)

In [18]: %timeit heurisch(diff(log(x)**2*exp(x), x), x)
1 loops, best of 3: 1.72 s per loop

In [19]: %timeit heurisch(diff(log(x)**2*exp(x), x), x, degree_offset=1)
1 loops, best of 3: 3.67 s per loop


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to