What is Tanh-Sinh Quadrature?
Tanh-Sinh quadrature, also known as the Double Exponential (DE) rule, is a numerical integration method that excels at evaluating definite integrals on a finite interval [a, b]—especially when the integrand has singularities at the endpoints. It works by applying the change of variable \(u = \tanh\!\left(\tfrac{\pi}{2}\sinh(t)\right)\), which maps the endpoints to \(t = \pm\infty\). Near those endpoints the integrand's contribution decays double-exponentially, so even functions that blow up at \(a\) or \(b\) (like \(\tfrac{1}{\sqrt{1-x^2}}\)) can be integrated accurately. This tool is universal mathematics and applies everywhere.
How to use it
Enter your function f(x) using standard notation (operators + - * / ^, parentheses, and functions such as sin, cos, exp, log, sqrt, abs, plus the constants pi and e). Provide the lower limit \(a\), the upper limit \(b\), and the number of subdivisions \(n\) that controls node density. Larger \(n\) improves accuracy at higher computational cost; 50–400 is a typical practical range. The integrand must be analytic on the open interval (endpoint singularities are fine) and must not be periodic.
The formula explained
The interval is first normalized to [-1, 1] with \(x = \tfrac{b-a}{2}u + \tfrac{a+b}{2}\) and \(dx = \tfrac{b-a}{2}\,du\). The DE rule then uses nodes \(t_k = k h\), abscissa \(u_k = \tanh\!\left(\tfrac{\pi}{2}\sinh(t_k)\right)\) and weights \(w_k = \dfrac{\tfrac{\pi}{2}\cosh(t_k)}{\cosh^{2}\!\left(\tfrac{\pi}{2}\sinh(t_k)\right)}\). The integral is approximated by $$\int_{a}^{b} f(x)\,dx \approx \frac{b-a}{2}\, h \sum_{k=-N}^{N} w_k\, f\!\left(\frac{a+b}{2} + \frac{b-a}{2}\,x_k\right)$$ Nodes whose weight underflows to zero (the saturated endpoints) are skipped, avoiding evaluation at the possibly singular boundaries.
Worked example
Integrate \(f(x) = \exp(-x^2)\) over [0, 1]. The exact value is $$\frac{\sqrt{\pi}}{2}\cdot\operatorname{erf}(1) \approx 0.7468241.$$ With a coarse step (\(h = 0.5\), \(N = 4\)) the rule already returns about 0.7467; with the default \(n = 100\) it agrees to roughly twelve digits.
FAQ
Can I integrate functions with endpoint singularities? Yes—that is the method's main strength. Integrable singularities at \(a\) or \(b\) are handled gracefully.
Why does periodicity matter? The double-exponential rule is tuned for non-periodic integrands; for periodic functions the trapezoidal rule converges faster and DE may be inaccurate.
What if a equals b? The integral is zero. If \(a > b\) the result is correctly negated because the \(\tfrac{b-a}{2}\) factor carries the sign.