Skip to main content

Machine

Struct Machine 

Source
pub struct Machine<D: Discretization> { /* private fields */ }
Expand description

Interval evaluation machine with persistent state and discretization.

A machine is compiled from a list of real-number expressions via MachineBuilder::build, and can then be evaluated at specific input points using Machine::apply. Returns an opaque machine that can be passed to Machine::apply to evaluate the compiled real expression on a specific point.

Internally, a machine converts expressions into a simple register machine. Compilation is fairly slow, so the ideal use case is to compile a function once and then apply it to multiple points.

If more than one expression is provided, common subexpressions will be identified and eliminated during compilation. This makes Rival ideal for evaluating large families of related expressions, a feature that is heavily used in Herbie. Note that each expression can use a different discretization.

Implementations§

Source§

impl<D: Discretization> Machine<D>

Source

pub fn instruction_count(&self) -> usize

Return the total number of instructions in the compiled machine.

Source

pub fn argument_count(&self) -> usize

Return the number of input arguments expected by this machine.

Source

pub fn target_precision(&self) -> u32

Return the discretization’s target precision in bits.

Source

pub fn min_precision(&self) -> u32

Return the minimum working precision in bits.

Source

pub fn max_precision(&self) -> u32

Return the maximum working precision in bits.

Source

pub fn argument_precision(&self) -> u32

Return the precision used for input arguments.

Source

pub fn set_max_precision(&mut self, bits: u32)

Set the maximum working precision in bits.

Source

pub fn iterations(&self) -> usize

Return the number of iterations needed for the most recent call to Machine::apply.

Source

pub fn bumps(&self) -> usize

Return the number of bumps detected during the most recent call to Machine::apply.

Source

pub fn set_profiling_enabled(&mut self, enabled: bool)

Enable or disable per-instruction profiling.

Source

pub fn profiling_enabled(&self) -> bool

Returns whether per-instruction profiling is enabled.

Source

pub fn execution_records(&self) -> &[Execution]

Return a slice of recorded Execution records from the profiling buffer.

Source

pub fn clear_executions(&mut self)

Reset the profiling buffer, discarding all recorded executions.

Source

pub fn instruction_names(&self) -> Vec<&'static str>

Return the operation name for each instruction in the machine.

Source

pub fn configure_baseline(&mut self)

Reconfigure the machine to use the baseline strategy.

The baseline strategy uses a single global precision for all instructions, doubling it each iteration. This is simpler but less efficient than the default adaptive precision tuning.

Source

pub fn take_executions(&mut self) -> Vec<Execution>

Return a snapshot of recorded Execution records and reset the internal buffer pointer.

Source§

impl<D: Discretization> Machine<D>

Source

pub fn apply( &mut self, args: &[Ival], hint: Option<&[Hint]>, max_iterations: usize, ) -> Result<Vec<Ival>, RivalError>

Evaluate the compiled real expressions on an input point represented as a slice of intervals.

args must be the same length as the vars passed to MachineBuilder::build. The output is a vector of output values of the same length as the exprs passed to MachineBuilder::build.

hint can be provided from a previous call to Machine::analyze_with_hints to speed up evaluation. Pass None for default behavior.

max_iterations sets the maximum number of re-evaluation iterations before giving up.

§Errors

Returns RivalError::InvalidInput if the point is an invalid input to at least one of the compiled expressions. Returns RivalError::Unsamplable if Rival is unable to evaluate at least one expression.

Note that apply will only return Ok if it can prove that it has correctly-rounded the output. It will only return InvalidInput if it can prove that at least one output expression in the machine throws on the given input.

Source

pub fn apply_baseline( &mut self, args: &[Ival], hint: Option<&[Hint]>, ) -> Result<Vec<Ival>, RivalError>

Evaluate the machine using the baseline strategy.

The baseline strategy uses a single global precision for all instructions, doubling it each iteration. This is simpler but less efficient than Machine::apply, which uses adaptive per-instruction precision tuning.

Call Machine::configure_baseline before using this method to set up the machine for baseline evaluation.

Source

pub fn analyze_baseline_with_hints( &mut self, rect: &[Ival], hint: Option<&[Hint]>, ) -> (Ival, Vec<Hint>, bool)

Analyze an input rectangle using the baseline strategy, returning status, next hints, and a convergence flag.

See Machine::analyze_with_hints for details on the return values.

Source

pub fn analyze_baseline(&mut self, rect: &[Ival]) -> Ival

Analyze a hyper-rectangle using the baseline strategy and return only the boolean interval status.

See Machine::analyze for details on the return value.

Source

pub fn analyze_with_hints( &mut self, rect: &[Ival], hint: Option<&[Hint]>, ) -> (Ival, Vec<Hint>, bool)

Analyze an input rectangle using adaptive precision tuning.

Returns a (status, hints, converged) tuple:

  • status is a boolean interval indicating whether a call to Machine::apply with inputs in the supplied rect is guaranteed to raise an error. If false is returned, there is no point calling apply with any point in the input range. If uncertain, some points may raise errors while others may not, though nothing is guaranteed. If true is returned, InvalidInput will not be raised for any point in the range; however, Unsamplable may still be raised.

  • hints is a vector of Hints that can be passed to subsequent calls to Machine::apply to skip unnecessary computation.

  • converged indicates whether the analysis has converged.

Source

pub fn analyze(&mut self, rect: &[Ival]) -> Ival

Analyze a hyper-rectangle and return only the boolean interval status.

Returns a boolean interval which indicates whether a call to Machine::apply, with inputs in the supplied rect, is guaranteed to raise an error.

In other words, if false is returned, there is no point calling apply with any point in the input range. If uncertain, some points in the range may raise errors, while others may not, though nothing is guaranteed. If true is returned, RivalError::InvalidInput will not be raised for any point in the range. However, RivalError::Unsamplable may still be raised.

The advantage of analyze over apply is that it applies to whole ranges of input points and is much faster.

Auto Trait Implementations§

§

impl<D> Freeze for Machine<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for Machine<D>
where D: RefUnwindSafe,

§

impl<D> Send for Machine<D>
where D: Send,

§

impl<D> Sync for Machine<D>
where D: Sync,

§

impl<D> Unpin for Machine<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Machine<D>
where D: UnsafeUnpin,

§

impl<D> UnwindSafe for Machine<D>
where D: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.