Skip to main content

refine

Function refine 

Source
pub fn refine<const N: usize>(
    start: [Scalar; N],
    domain: [(Scalar, Scalar); N],
    step: impl Fn([Scalar; N]) -> Option<[Scalar; N]>,
) -> [Scalar; N]
Expand description

Refine start — a box a subdivision search proved holds a root — by Newton, within domain. step takes an iterate to the next one, unsharpened, or None where Newton cannot go on (a singular Jacobian at a tangential crossing or a pole, an evaluation failing).

Every iterate but the last is sharpened, which is legitimate: it is only a seed for the next step. The final step is left unsharpened, so the returned widths honestly state how well the root is determined (see “Sharpen only where the value is a free choice” in AGENTS.md). Each iterate is clamped into domain — sharpened first, so the clamp’s comparisons are exact — rather than given up on: a foot point can step outside the domain on the way in.

A seed repeating one before it ends the iteration early with the same result (super::iterate::Repeat::Cycle).

The result is intersected with start: both enclose the same root, so their intersection does too, and is tighter than either. Infallible by construction: if Newton stops, or ends disjoint from start (it has wandered out of the box the search proved the root lies in), start is returned unchanged. Refinement can only tighten, never fail.

Plain, unverified Newton: it does not itself certify existence or uniqueness, so callers check that the refined box can still hold what they are looking for.