mixle.engines.affine module¶
Affine arithmetic – tighter error tracing than intervals, and the precision-allocation dial.
An AffineForm represents a quantity as a center plus a linear combination of shared noise
symbols x0 + sum_i x_i * eps_i with eps_i in [-1, 1]. Unlike interval arithmetic, correlated
error cancels: (a + b) - a recovers b exactly because a’s symbols subtract out, where an
interval would double the width. That tightness is what lets a precision-allocation pass avoid
over-spending bits.
The dial: evaluating an operation at dtype d injects a fresh roundoff symbol of radius
u(d) * |result| (u = unit roundoff). The affine radius at the root is the certified error
bound; a subtraction at a cancellation point makes it blow up – the escalation signal, for free. Walk
leaves->root choosing the cheapest dtype whose injected radius keeps the root bound under target.
This is the tighter estimate; the fully IEEE-sound enclosure is mixle.engines.error_tracing
(interval, outward-rounded). The radius here is reported with one outward ULP of slop.
- unit_roundoff(dtype)[source]
Unit roundoff for a dtype name / numpy dtype (
'dd'/'qd'for extended precision).
- class AffineForm(center, terms=None)[source]
Bases:
objectcenter + sum_i coeff_i * eps_iover shared noise symbolseps_i in [-1, 1].- center
- terms
- classmethod uncertain(x, radius=0.0)[source]
An input known only to within +/-
radius– one fresh noise symbol of that radius.
- radius()[source]
Half-width =
sum_i |coeff_i|(one outward ULP of slop for the f64 summation).- Return type:
- allocate_precision(center_magnitude, op_count, target_abs_error)[source]
Cheapest dtype whose accumulated roundoff over
op_countops keeps error under target.Each op injects ~``u(d) * |magnitude|``;
op_countof them accumulate toop_count*u*|mag|. Walk cheapest-first and return the first dtype that fits the budget – spend minimal precision.