Expand description
§Rival 3: Real Computation via Interval Arithmetic
Rival is an advanced interval arithmetic library for arbitrary-precision computation of complex mathematical expressions. Its interval arithmetic is valid and attempts to be tight. Besides the standard intervals, Rival also supports boolean intervals, error intervals, and movability flags, as described in “An Interval Arithmetic for Robust Error Estimation”.
Rival is a part of the Herbie project, and is developed on Github.
§Real Computation
Rival is built to evaluate real-number expressions to
correctly-rounded floating-point outputs. To do so, you first compile
your real-number expression to a Machine via MachineBuilder,
and then apply that machine to specific inputs.
use rival::{Expr, MachineBuilder, Ival};
use rug::Float;
struct Fp64Disc;
impl rival::Discretization for Fp64Disc {
fn target(&self) -> u32 { 53 }
fn convert(&self, _: usize, v: &Float) -> Float { Float::with_val(53, v) }
fn distance(&self, _: usize, lo: &Float, hi: &Float) -> usize { 0 }
}
impl Clone for Fp64Disc { fn clone(&self) -> Self { Fp64Disc } }
let expr = Expr::Sub(
Box::new(Expr::Sin(Box::new(Expr::Var("x".into())))),
Box::new(Expr::Sub(
Box::new(Expr::Var("x".into())),
Box::new(Expr::Div(
Box::new(Expr::Pow(
Box::new(Expr::Var("x".into())),
Box::new(Expr::Literal(Float::with_val(53, 3))),
)),
Box::new(Expr::Literal(Float::with_val(53, 6))),
)),
)),
);
let machine = MachineBuilder::new(Fp64Disc).build(vec![expr], vec!["x".into()]);Rival works by evaluating the expression with high-precision interval arithmetic, repeating the evaluation with ever-higher precision until a narrow-enough output interval is found.
Detailed profiling information can be accessed via Execution.
Rival also exposes the underlying interval-arithmetic library:
use rival::Ival;
let x = Ival::from_lo_hi(
rug::Float::with_val(20, 2),
rug::Float::with_val(20, 3),
);
let mut result = Ival::zero(20);
result.sqrt_assign(&x);Rival is fast, accurate, and sound. We believe it to be a state-of-the-art implementation, competitive with Sollya/MPFI, Calcium/Arb, and Mathematica.
Structs§
- Error
Flags - Flags indicating whether invalid inputs were discarded during computation.
- Execution
- A single recorded execution of a Rival interval operator.
- Ival
- A standard Rival interval containing two arbitrary-precision endpoints.
- Machine
- Interval evaluation machine with persistent state and discretization.
- Machine
Builder - Builder for constructing a
Machinewith custom parameters.
Enums§
- Expr
- High-level expression AST for real-number computation.
- Hint
- Hints guide the execution of individual instructions in the machine.
- Rival
Error - Errors that can occur during
Machine::apply.
Traits§
- Discretization
- A discretization represents some subset of the real numbers
(for example,
f64).