neco-expr
neco-expr stores exact values in expression graphs and resolves them, per consumer, into certified floating-point values. A resolved result carries a finite f64, a dyadic enclosure at the requested precision, and an exact absolute error bound. The descent to floating point happens only at that final step, and every intermediate value stays exact.
Usage
This example stores the exact value one as an atom and resolves it at 20 bits of absolute precision:
use ;
use Monomial;
let mut graph = new;
let expression = graph
.push
.expect;
let mut atoms = new;
let atom_value = Monomial;
atoms
.insert
.expect;
let consumer = new;
let mut requirements = new;
requirements
.insert
.expect;
let mut assignments = new;
assignments
.insert
.expect;
let = new
.resolve_all
.expect;
let certified = resolved
.get
.expect
.as_ref
.expect;
assert_eq!;
Expressions and exact values
ExactValue has three ordered layers:
Monomial: a normalized monomialFormSum: a normalized formal sumAlgebraic: a real algebraic number identified by a minimal polynomial and root index
The graph is built from two types:
ExprGraph: an insertion-ordered arenaExprNode: atoms, negation, arithmetic operations, and reduced rational powers
Operation nodes may reference only previously inserted nodes, so every graph is acyclic.
For example, the golden ratio is built from a square-root atom and exact constants. The addition produces a layer-2 formal sum. Resolution returns an enclosure within the requested width and a finite floating-point value selected from it:
phi = (1 + 5^(1/2)) / 2
The operation and input layers determine the result layer:
| Operation | Inputs | Result |
|---|---|---|
| Negation | Any layer | Input layer |
| Addition, subtraction | Layers 1 and 2 | FormSum |
| Addition, subtraction | Includes layer 3 | Algebraic |
| Multiplication, division | Two Monomial values |
Monomial |
| Multiplication, division | Up to layer 2 | FormSum |
| Multiplication, division | Includes layer 3 | Algebraic |
| Integer power | Any layer | Input layer |
| Proper rational power | Monomial |
Monomial |
| Proper rational power | FormSum |
Algebraic |
| Proper rational power | Algebraic |
Algebraic |
Declarations and resolution
Resolution takes four independent inputs:
ExprGraph: expression nodesAtomStore: atom IDs and exact valuesPrecisionRequirements: consumer IDs and absolute precisionAssignments: consumer IDs and expression IDs
Resolution is a single call:
Resolver::resolve_all: resolves every consumer in ID order
The call returns three values:
EvaluationCache: exact values or evaluation failures for reached expression IDsIsolationCache: algebraic isolating intervals reusable for the same expression ID and precisionResolvedValues: aCertifiedF64or resolution failure for every requested consumer
When one consumer fails, its failure is stored in the result map and resolution continues with the remaining consumers. The outer result reports failure only when a cache or the result map itself cannot be stored.
Certified floating-point values
CertifiedF64 contains three values:
value(): a finitef64selected with ties-to-even roundingenclosure(): a dyadic interval containing the exact valueabsolute_error(): the greater distance from the selected value to either enclosure endpoint
Absolute precision uses this input:
AbsoluteBits(bits): limits the enclosure width
upper - lower <= 2^(-bits)
Every u32 value, including zero, is a valid precision. Floating-point selection is independent of the requested precision, and it compares exact values across all finite bit patterns, including subnormals, positive zero, and the maximum finite value.
An exact value beyond the finite f64 range produces this failure:
ResolveError::FloatOutOfRange: the exact value exceeds the finite range
Public failures
Failures are separated by operation stage:
GraphError: exhausted IDs, references to nodes yet to be inserted, node cloning, and graph storageInsertError: duplicate IDs, atom-value cloning, and input-map storageEvalError: division by zero, zero powers, even roots, and lower-crate failuresResolveError: missing declarations, unknown IDs, finite range, evaluation, enclosure, and result storageStorageError: capacity overflow and allocation refusal with the required total element count
Lower failures and checked copying use these APIs:
std::error::Error::source: references the stored lower failuretry_clone: checks allocation while copying owned sequences
try_clone is the single copying path for types that own sequences.
Configuration and dependencies
Runtime dependencies are the four lower crates:
neco-bigintneco-monomialneco-formsumneco-algnum
The default std feature enables standard error integration and the same feature in the dependencies. Disabling default features selects the core + alloc configuration:
License
MIT License.