Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Double-exponential integrator (#895) #178

wants to merge 14 commits into


None yet
3 participants

pv commented Mar 10, 2012

Resurrecting an old contribution from Thouis Ray Jones, a double-exponential quadrature.

It integrates analytical functions optimally, and unlike quad(), supports vectorized functions. The tests seem to indicate that everything works as it should. The only question is probably about the pre-generated coefficients -- I'm not 100% sure the full mpmath accuracy is needed here, so it might also be OK to generate them on the fly.

@rgommers rgommers commented on an outdated diff Mar 10, 2012

+def quad_de(func, a, b, args=(), tol=1e-10, vec_func=True, max_level=None):
+ """
+ Integrate a function over an interval using double exponential
+ quadrature.
+ This method is well-suited to integrating analytic functions,
+ and tolerant for singularities at one or both endpoints.
+ It should not be used with functions with discontinuities.
+ If quad_de() encounters a singularity (+/-infinity or NaN) within
+ the integration limits, it will raise a ValueError.
+ Parameters
+ ----------
+ func : function

rgommers Mar 10, 2012


function --> callable (I suppose).

args is missing in the list of parameters.


rgommers commented Mar 10, 2012

Looks good.

Cross-referencing this from the quad docstring, with a recommendation to use this function for analytic functions (?) instead of quad, would be good.

An example is needed I think. The integration routines need this more than most other functions (also looking at you, dblquad and tplquad ...).

Would it also make sense to add dblquad_de and tplquad_de?

Do you know what the performance relative to quad is (speed and accuracy)?


pv commented Mar 10, 2012

Performance-wise, quad_de overall seems to not be significantly better than quad.

Its accuracy seems to depend quite a lot on the function considered. This can be better or worse than quad. Very strongly oscillating functions in infinite ranges, or a strong singularity at one endpoint seem to be problematic at least (however, any problems are indicated in the error estimate, which does seem to be accurate). quad also has some problems in these cases, but you can tell it to increase the allowed numbers of subdivisions, which cannot be done with quad_de. quad wins for very smooth funtions in the integration range. This is probably because quad_de tends to sample the function a lot around the boundaries of the range.

Speed-wise, it can be slower or faster by quad; this depends on the function in question. The speed difference seems to be within a factor of 10 to either direction, except for functions that vary very little in the range --- for those quad can win by a bigger margin.


rgommers commented Mar 10, 2012

Example looks good.

Thanks for the performance explanation. You could consider putting that explanation in the Notes section.

+1 from me.


pv commented May 28, 2012

There's one holdoff: I'm still not really happy with the precomputed knots, as it may be possible to improve the performance by being more intelligent. mpmath also has a tanh-sinh quadrature implementation, so I'll take a look at that.


thouis commented Jun 4, 2012

Sorry, I missed this conversation when it started back up a few months ago. I'll try to resurrect my notes about the knot computation. I may have just taken it from another source (probably John Cook's implementation).


pv commented Jun 4, 2012

mpmath actually is less fancy here. It doesn't use the DE transforms for the infinite intervals, rather, it maps first to [-1,1] using a standard transform, and then uses the DE defined there.

Actually, the bigger question is whether there is some change in the code that could be made, to make the procedure more competitive against quad. It works OK as it is now, though, and could be merged, but seems to lose to quad in many cases.


pv commented Sep 10, 2013

Ok, closing this.

Rationale for rejection: not competitive against quad, so there are no clear gains in adding this.

@pv pv closed this Sep 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment