adaptive quadrature
Most integrands are not uniformly hard: a function might be nearly flat over most of its range but spike sharply in one small region. A fixed, uniform grid is wasteful here — it lavishes the same effort on the boring flat parts as on the wild spike. Adaptive quadrature is the smart alternative: it concentrates work WHERE the integrand is hard and coasts where it is easy, automatically.
The mechanism is a self-checking divide-and-conquer. On a panel, estimate the integral two ways — for instance with a coarse rule and a finer one, or a Gauss rule paired with a Kronrod extension that reuses the same points. The difference between the two estimates is a cheap a-posteriori error estimate for that panel. If it is below the local tolerance, accept the panel and move on. If not, SPLIT the panel in half and recurse on each half, with each half allotted a share of the tolerance. The recursion naturally drills many tiny panels into a spike or a region of rapid change, while leaving smooth flat stretches as one big panel — so the final mesh is fine exactly where it needs to be.
Adaptive quadrature is what general-purpose integration routines in scientific libraries (the famous QUADPACK family, MATLAB's integral, SciPy's quad) actually use, because it delivers a requested accuracy without the user having to know in advance where the integrand misbehaves. The honest caveats: the built-in error estimate is a heuristic, not a guarantee, so a sufficiently spiky or oscillatory integrand can fool it into stopping too early (a narrow spike between sample points may go entirely unseen); and a genuine singularity can trigger endless, ineffective subdivision unless the routine recognizes it or you transform it away first.
Integrate f(x) = 1/((x - 0.3)^2 + 0.0001) on [0, 1], which has a tall narrow spike near x = 0.3. A uniform grid either misses the spike or wastes points everywhere; an adaptive routine places a dense cluster of tiny panels around 0.3 and just a few coarse panels elsewhere, reaching the target accuracy with far fewer total evaluations.
Refine only where the integrand is hard; coast where it is smooth.
The error estimate is a heuristic, so adaptive quadrature can be fooled: a spike narrower than the spacing of the initial samples may never be detected, and the routine then returns a confident but wrong answer. For oscillatory or singular integrands, use a method designed for them rather than trusting the default.