mixle.engines.error_tracing module

Sound error tracing via interval arithmetic.

An Interval carries [lo, hi] enclosing a true value. Every operation rounds the bounds outward (one ULP via numpy.nextafter()), so the enclosure provably contains the exact result despite float64 round-off – the interval certifies the numerical error rather than hoping it is small. The width is a guaranteed error bound; a precision-allocation pass reads it to pick the lowest-cost format that keeps the width under a target (pair with mixle.engines.formats.min_float_mantissa_bits()).

Interval arithmetic is sound but pessimistic because it ignores correlations between operands. Affine arithmetic can tighten the bound when that extra complexity is justified. This module provides the vectorized, dependency-free core.

class Interval(lo, hi)[source]

Bases: object

A guaranteed enclosure [lo, hi] of a value (scalar or numpy array), outward-rounded.

Parameters:
  • lo (Any)

  • hi (Any)

classmethod exact(x)[source]

A degenerate interval [x, x] for an exactly-represented value.

Parameters:

x (Any)

Return type:

Interval

classmethod from_quantized(original, fmt)[source]

Enclose original using the quantized format’s error bound.

Parameters:
Return type:

Interval

width()[source]

The guaranteed error bound: hi - lo (outward-rounded).

Return type:

ndarray

max_width()[source]

Return the largest interval width.

Return type:

float

midpoint()[source]

Return interval midpoints.

Return type:

ndarray

contains(value)[source]

Return a boolean mask for values inside the interval.

Parameters:

value (Any)

Return type:

ndarray

sum_error_bound(x)[source]

Return a certified bound on the float64 error of sum(x).

The standard a-priori bound |fl(sum) - sum| <= gamma_{n-1} * sum|x_i| with gamma_k = k*u / (1 - k*u) and u = 2**-53. It is sound for any summation order. A bound that is large relative to |sum x| means the sum is ill-conditioned (cancellation) and warrants the double-double mixle.engines.extended.dd_sum(); a tight one means float64 already suffices and no extra compute is justified.

Parameters:

x (Any)

Return type:

float

sum_enclosure(x)[source]

Return an outward-rounded interval enclosing the true sum(x).

Parameters:

x (Any)

Return type:

Interval

float64_sum_is_accurate(x, target_rel_error=1e-12)[source]

Return whether float64 summation is accurate to target_rel_error.

Reads the certified bound relative to the magnitude of the result – precision allocation in one call.

Parameters:
Return type:

bool