Double Exponential Integration

While the AdaptiveIntegrator works well in most cases, it is not perfect. It sometimes has problems with some singularities on the boundaries of the integration interval. In such cases, the DoubleExponentialIntegrator may be a better option.

This integrator works by implicitly transforming the integration interval using tanh and sinh functions. Convergence is very fast in most cases. For smooth integrands, more traditional methods often win out.

An example of a difficult integral that is computed successfully with double exponential integration is:

$$\int_0^\inf \sqrt{frac{x}{1-x^2}}\,dx$$

The code below shows the difference in effectiveness. The standard adaptive integrator fails completely while the double exponential integrator requires just 51 function evaluations to get a result within the desired tolerance.

C#
Func<double, double> fn = x => Math.Sqrt(x / (1 - x * x));
const double knownResult = 1.198140234735592;
var adaptive = new AdaptiveIntegrator();
var exponential = new DoubleExponentialIntegrator();
var result1 = adaptive.Integrate(fn, 0, 1);
Console.WriteLine($"Adaptive: {adaptive.Status}");
var result2 = exponential.Integrate(fn, 0, 1);
Console.WriteLine($"Double exponential: {exponential.Status}");
Console.WriteLine($"  Result: {result2}");
Console.WriteLine($"  Estimated error: {exponential.EstimatedError}");
Console.WriteLine($"  Actual error: {result2 - knownResult}");
Console.WriteLine($"  Function evaluations: {exponential.EvaluationsNeeded}");

References

Hidetosi Takahasi and Masatake Mori, Double Exponential Formulas for Numerical Integration, Publications of the Research Institute for Mathematical Sciences, 9 (3): 721–741