mixle.engines.spectrum module¶
The precision spectrum’s front door: route a computation to the lowest-cost accurate backend.
Ties the spectrum together – native float64, double-double (mixle.engines.extended), and the MPFR
tail (mixle.engines.highprec) – behind one call that reads the certified error bound
(mixle.engines.error_tracing) and escalates only as far as the accuracy budget demands. This is
‘use logic to preserve numerical accuracy with minimal compute’ as an actual API: a well-conditioned sum
stays in fast float64, a cancelling one steps up to vectorized double-double, and only a catastrophically
ill-conditioned one pays for arbitrary precision.
- class SumResult(value, backend, rel_error_bound, target_rel_error, status='ok')[source]
Bases:
objectResult of
accurate_sum(): the summed value plus a certificate of the accuracy actually achieved – so a caller can verify the target was met rather than trust the call implicitly.statusis one of:"ok":rel_error_boundis a certified bound<= target_rel_error–backendactually met the caller’s target."insufficient": no backend available in this process could certify the target – double-double was proven insufficient and either arbitrary precision is unavailable at all, or even_MAX_MPFR_BITSis not enough.value/backendstill carry the best effort found (the highest-precision backend actually tried), for diagnostics only – callers that require the accuracy guarantee must treat this as a failure and not usevalue."overflow": the exact/high-precision result cannot be represented by this API’s float64valuefield. No relative-error claim is issued.
- Parameters:
- value
the computed sum (best-effort, not certified, when
status == "insufficient").- Type:
- backend
which representation computed
value–"float64","dd", or"mpfr<bits>".- Type:
- rel_error_bound
certified upper bound on
value’s relative error (an analytic bound – the same quantitysum_certificate()reports for the plain float64 sum, not a measurement).- Type:
- target_rel_error
the caller’s requested target, echoed back for convenience.
- Type:
- status
see above.
- Type:
- property met_target: bool
Trueonly whenrel_error_boundis certified to meettarget_rel_error.
- accurate_sum(x, target_rel_error=1e-12)[source]
Sum
xtotarget_rel_errorrelative accuracy using the lowest-cost sufficient backend.Returns a
SumResultcertifying the accuracy actually achieved. Escalates from float64 to double-double to arbitrary precision only when the certified error bound says the lower-cost backend cannot meet the budget – so the common well-conditioned case never leaves vectorized float64 – and fails closed (status="insufficient") rather than silently returning a value that does not meettarget_rel_errorwhen no backend available in this process can certify it.Raises
ValueErroriftarget_rel_erroris not a positive, finite number.
- sum_certificate(x)[source]
Report the certified float64 summation error and the condition number, without choosing a backend.
- cast(x, precision)[source]
Cast
xonto the spectrum: a native dtype name,"dd"/"fp<bits>", or an integer bit width."dd","fp128", and the integer128are the same request (DoubleDouble);"fp96"and the integer96are likewise the same request (both resolve to 96 total bits via_precision_bits()) and route to the identical representation via_cast_by_bits(), regardless of which spelling the caller used. A nonpositive bit width (e.g."fp0",-5) raisesValueErrorrather than reaching format construction. Anything else (e.g."float64",np.float32) is handed straight tonumpy.dtype().Returns a numpy array (native / simulated low-bit), a
DoubleDouble, or an MPFR object array – see_cast_by_bits()for the exact tiering.