Determine whether a finite measurement exists
Let \(x\) be the distance from the edge divided by the specimen width. Take the idealised density \(f(x)=x^{-\alpha}\) on the open interval between zero and one. The exponent is a known input in this experiment. Start with \(0<\alpha<1\). If the instrument samples exactly at zero, its readout would be undefined in this model. That does not make the integrated signal infinite. The contribution of the first \(\varepsilon\) of the interval is found by integrating from a positive lower bound and taking that bound to zero.
This sets the physical scale of the numerical task. With \(\alpha=1/2\), the first one ten-thousandth of the spatial window contributes one per cent of the complete signal. For \(\alpha=0.9\), the same strip contributes almost forty per cent. An instrument with finite edge resolution may require a separate sub-resolution material model. In the numerical exercise the stated power law is exact down to arbitrarily small distance. That assumption permits an independent reference answer and lets us attribute a mismatch to the quadrature rather than to unseen edge physics.
A uniform midpoint rule avoids the forbidden endpoint, using \(h\sum_{j=0}^{N-1}f((j+1/2)h)\) with \(h=1/N\). The exact contribution of the first cell is \(h^{1-\alpha}/(1-\alpha)\). Its midpoint approximation is \(2^\alpha h^{1-\alpha}\). The leading error already visible in this cell decays slowly when the exponent is close to one. Since the density is convex, every midpoint panel underestimates its integral. The errors do not cancel the missing first-cell contribution. The usual smooth-function bound in terms of a uniform second derivative cannot be applied here.
Build a transformation that resolves both ends
Map a real parameter \(t\) onto the physical interval. A convenient first choice is a logistic map, which approaches either endpoint exponentially in the parameter. To concentrate the nodes more aggressively near the endpoints, first replace that parameter by \(\pi\sinh t\). Written using a hyperbolic tangent, the resulting map is the usual tanh–sinh transformation. Its derivative becomes small at precisely those points where the original density becomes large.
Apply the change of variables before choosing any quadrature rule. The new integrand is \(g(t)=\pi\cosh(t)x(t)^{1-\alpha}[1-x(t)]\), integrated along the entire real line. To inspect its left tail take \(t=-u\) with \(u\) large. Then \(\sinh u\) and \(\cosh u\) both grow approximately as \(e^u/2\), while \(x(-u)\) behaves as \(\exp[-(\pi/2)e^u]\). Their product decays like a factor proportional to \(e^u\) multiplied by \(\exp[-(1-\alpha)(\pi/2)e^u]\). The second exponential dominates eventually. As \(\alpha\) approaches one its coefficient shrinks and the relevant left tail extends farther out.
At the right end \(x(t)\) approaches one and the factor \(1-x(t)\) supplies the rapid decay. A symmetric truncation in \(t\) therefore covers two generally unequal tail contributions. On a real density that is singular at both ends, repeat the asymptotic argument separately for each endpoint. For a strong interior peak the present transformation has no reason to concentrate near the peak. Splitting the interval at a known interior singularity would give each transformed subproblem a meaningful endpoint.
Distinguish tail loss from the panel approximation
Choose a finite half-window \(T\), then a step \(h_t\) such that a whole number of panels fits on either side of zero. The notebook applies the composite trapezoid with half weights on both boundary nodes of \([-T,T]\). This calculation leaves out the two infinite tails even if the finite interval is integrated perfectly. There is a second error from replacing the finite integral by sampled trapezoids. At fixed window the panel errors can become tiny while an appreciable area is still missing.
In the power-law test the omitted tails can themselves be integrated explicitly. Write \(a=x(-T)\) and \(b=x(T)\). Their sum is \([a^{1-\alpha}+1-b^{1-\alpha}]/(1-\alpha)\). With \(\alpha=0.65,T=3,h_t=0.25\), there are 25 evaluations and the notebook gives about 2.85707045 against the reference 2.85714286. The omitted tail is approximately \(4.70\,10^{-5}\), while the total difference is about \(7.24\,10^{-5}\). The gap between these values belongs to resolution inside the chosen window. Recalculating at smaller \(h_t\) without increasing \(T\) tests only the latter.
Open full-size diagramCompute the weighted integrand before rounding the endpoints
If \(x\) is stored as exactly one, the expression \(1-x\) loses a small positive number. If \(x\) underflows to zero, multiplying \(f(x)=\infty\) by a derivative rounded to zero causes another failure. Both effects are artefacts of evaluation order. Here the product \(f(x(t))x'(t)\) has a simple algebraic form that is finite everywhere at finite \(t\). Working in logarithms keeps the two endpoint distances separately.
Put \(s=\pi\sinh(t)\). A stable evaluation of \(\log x\) is \(-\log(1+e^{-s})\), and that of \(\log(1-x)\) is \(-\log(1+e^s)\). The notebook calls NumPy's log-add-exp operation on zero and the respective exponent to avoid directly forming a very large exponential. The log of the complete integrand is now the sum of \(\log\pi+\log\cosh t\), \((1-\alpha)\log x\) and \(\log(1-x)\). Exponentiating this final quantity may underflow in sufficiently distant tails. There that represents a negligible weighted contribution, rather than the disappearance of the physical interval itself.
In an integral supplied by a black-box material law the algebraic combination may be less accessible. If the law can accept a distance and the logarithm of a distance, the same strategy works. If measurements stop before either endpoint, no quadrature transformation recovers information about the missing function automatically. A defensible result should record where the model was extrapolated as well as how the integration was performed.
Design two distinct convergence experiments
First vary the number of transformed panels at fixed half-window and plot the absolute error. Use absolute error near a zero integral because a relative percentage becomes ill-conditioned as the answer tends to zero. Next increase \(T\) while keeping the transformed step approximately fixed. More points are then added to the previously discarded tails. If changing the half-window matters and halving the step does not, the initial allocation spent too much effort in the centre. Repeat this reasoning before making claims about asymptotic convergence from only two almost identical values.
For this particular reference family there is an even simpler independent calculation: map \(x=u^{1/(1-\alpha)}\) on the unit interval. The diverging density and the vanishing derivative combine into the constant \(1/(1-\alpha)\). A single properly weighted node can integrate a constant exactly. This yields a stringent check of the implementation while illustrating a general design principle. When the singularity exponent is known and the remaining factor is smooth, a tailored substitution may be the easiest route to the required integral. Tanh–sinh is especially attractive when the two endpoints need protection and their detailed local structure is not fully known.
Compare two uses of a fixed sample budget
Take 33 transformed nodes and put 16 panels on either side of the origin. A half-window of two now gives a step of one eighth. Doubling the half-window with the same number of samples doubles the spacing while extending the tails. There is no general reason this second calculation should be more accurate. It trades centre resolution for coverage. Plot the estimates against window length at fixed sample count and identify the interval where both errors are small. Move the exponent closer to one and repeat; the useful window typically shifts because the physical edge carries a larger fraction of the signal.
For a more expensive black-box integrand, retain samples when halving the transformed step at fixed cutoff. All old abscissae lie on the finer grid. The trapezoid at the finer step is the sum of half the old approximation and the new midpoint samples times the finer spacing. This reuse affects computational cost, not the mathematics of the tail correction. It supports two separate reports: how much the estimated integral changed and how many genuinely new evaluations were required to obtain that change.
A local OneSimulation comparison in the notebook uses twenty-four line elements on the retained window. Eight mapped Gaussian points per element sample the transformed density at different locations from the trapezoid. Compare that sum with the analytical finite-window integral. Agreement here isolates the numerical integration on the interval. The previously calculated tails must still be included when reporting the complete physical signal.
Tutorial on endpoint mass and stopping criteria
1. An instrument cannot resolve the first millionth of the width. For \(\alpha=2/3\), what fraction of the total signal would be omitted if this strip were simply discarded?
Work through the solution
The fraction is \(\varepsilon^{1-\alpha}\). Substituting \(10^{-6}\) and \(1/3\) gives \(10^{-2}\), or one per cent. The full integral is three, so the omitted integral is 0.03 in the dimensionless units of the model. This error would persist even for an exact integration over the resolved remainder.
2. With \(\alpha=1/2\), compare the first-panel midpoint contribution to its exact value. What follows for the number of uniform panels needed merely to halve this contribution to the error?
Work through the solution
The exact value is \(2\sqrt h\), and the midpoint gives \(\sqrt{2h}\). Their difference is \((2-\sqrt2)\sqrt h\). To halve it one must quarter \(h\), hence quadruple the number of panels on the fixed overall interval. A second-order rule for a smooth function would suggest a much smaller increase.
3. Two calculations with \(T=2\) agree to ten printed digits. Does this suffice to report ten digits in the full integral? Propose an additional diagnostic for a density without a known antiderivative.
Work through the solution
Agreement supports resolution inside the selected window. Extend both tails at comparable step and record the changes from the new bands separately. Inspect their decay and, if the model supplies an asymptotic bound, integrate that bound beyond the last sampled band. Almost equal numbers at one truncation do not constrain a contribution that neither run sampled.
Further reading · Masatake Mori, discovery and development of the double-exponential transformation
Change parameters · Integrating an infinite endpoint with a finite table of samples
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.