github ↗
docs menu

Module Jera.Tol

Tolerances.

A solve accepts a lane when its error estimate e at its value y meets the tolerance: the root mean square, over the lane's float components, of e_i / s_i is at most 1, with s_i = abs + rel * |y_i|. A component with e_i = 0 counts 0; one with s_i = 0 and e_i <> 0 is never accepted, so an answer that may be zero needs abs. Each solve says what its e and y are.

The components add in a fixed order, pairwise over the flattened components, as do the sums and products that steer the searches. Where a solve's work is those and elementwise operations, its decisions depend only on the values of the user's function, bit for bit eagerly and compiled: Root, Minimize.bracket, and Minimize.solve's bfgs, lbfgs and nelder_mead without a box, System.anderson without memory. A solve that calls a Linear solver, factors a matrix (Nx.solve, Nx.qr, Nx.solve_triangular, Nx.inv) or takes a prefix sum (Nx.cumsum) rounds those within Rune's numerics, and compiled may decide differently: System.solve's newton and broyden, Anderson with memory, System.lanes, Minimize.solve's newton and levenberg_marquardt and its steps in a box, and the methods for stiff and implicit equations. Tolerances are OCaml floats: constants of a compiled program.

#type t

The type for tolerances.

#val v : rel:float -> abs:float -> t

v ~rel ~abs is the tolerance abs + rel * |y|.

Raises Invalid_argument if either is negative or not finite, or if both are 0.

#val rel : float -> t

rel r is v ~rel:r ~abs:0..

#val abs : float -> t

abs a is v ~rel:0. ~abs:a.

#val ulps : float -> t

ulps k is rel (k *. eps) with eps the distance from 1 to the next float of the dtype the tolerance meets. It is met only where the problem determines its answer to k units: a zero of f to about f's rounding error over |f'|, a minimum to about the square root of f's rounding over its curvature.

Raises Invalid_argument if k is not finite and positive.

#val pp : Stdlib.Format.formatter -> t -> unit

pp ppf t formats t as "rel 1e-06 abs 1e-10" or "ulps 4", each number as the shortest decimal that reads as it: "abs 1000000".