Skip to main content

Ival

Struct Ival 

Source
pub struct Ival { /* private fields */ }
Expand description

A standard Rival interval containing two arbitrary-precision endpoints.

A standard interval includes both endpoints. Neither endpoint is allowed to be NaN. Intervals can be either real (with rug::Float endpoints) or boolean (with endpoints 0 or 1).

§Boolean intervals

In a boolean interval, false is considered less than true, yielding three boolean interval values:

§Error intervals

Sometimes an interval will contain invalid inputs to some function. For example, sqrt is undefined for negative inputs! In cases like this, Rival’s output interval will only consider valid inputs. Error flags are “sticky”: further computations on an interval will maintain already-set error flags.

§Interval Operations

Rival aims to ensure three properties of all helper functions:

  • Soundness means output intervals contain any output on inputs drawn from the input intervals. IEEE-1788 refers to this as the output interval being valid.

  • Refinement means, moreover, that narrower input intervals lead to narrower output intervals. Rival’s movability flags make this a somewhat more complicated property than typical.

  • Weak completeness means, moreover, that Rival returns the narrowest possible valid interval. IEEE-1788 refers to this as the output interval being tight.

Weak completeness (tightness) is the strongest possible property, while soundness (validity) is the weakest, with refinement somewhere in between.

The typical use case for Rival is to recompute a certain expression at ever higher precision, until the computed interval is narrow enough. However, interval arithmetic is not complete. For example, due to the limitations of the underlying MPFR library, it’s impossible to compute (exp(x) / exp(x)) for large enough values of x.

While it’s impossible to detect this in all cases, Rival provides support for movability flags that can detect many such instances automatically. Movability flags are correctly propagated by all of Rival’s supported operations, and are set by functions such as exp.

Implementations§

Source§

impl Ival

Source

pub fn add_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval sum a + b.

Source

pub fn sub_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval difference a - b.

Source

pub fn mul_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval product a * b.

Source

pub fn div_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval quotient a / b.

Source

pub fn fma_assign(&mut self, a: &Ival, b: &Ival, c: &Ival)

Compute the interval fused multiply-add a * b + c.

Source

pub fn fdim_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval positive difference fdim(x, y) = max(x - y, 0).

Source

pub fn hypot_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval Euclidean distance hypot(x, y) = sqrt(x² + y²).

Source§

impl Ival

Source

pub fn not_assign(&mut self, input: &Ival)

Compute the interval logical NOT of input.

Source

pub fn and_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval logical AND of lhs and rhs.

Source

pub fn or_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval logical OR of lhs and rhs.

Source

pub fn eq_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval equality comparison lhs == rhs.

Source

pub fn ne_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval inequality comparison lhs != rhs.

Source

pub fn lt_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval less-than comparison lhs < rhs.

Source

pub fn le_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval less-than-or-equal comparison lhs <= rhs.

Source

pub fn gt_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval greater-than comparison lhs > rhs.

Source

pub fn ge_assign(&mut self, lhs: &Ival, rhs: &Ival)

Compute the interval greater-than-or-equal comparison lhs >= rhs.

Source

pub fn if_assign(&mut self, cond: &Ival, when_true: &Ival, when_false: &Ival)

Compute an interval conditional: if cond then when_true else when_false.

Here, cond must be a boolean interval, while when_true and when_false should be intervals of the same type, either both real or both boolean. If cond is uncertain, the union of when_true and when_false is returned.

Note that typically, uses of if_assign are incomplete because they are not flow-sensitive. For example, if (x < 0) then (-x) else x is always non-negative, but both branches evaluate to the same interval because the condition does not refine the value of x in either branch.

Source

pub fn error_assign(&mut self, input: &Ival)

Returns a boolean interval indicating whether any inputs were discarded when computing input.

These flags are “sticky”: further computations on input will maintain the already-set error flags.

Source

pub fn assert_assign(&mut self, cond: &Ival)

Returns an illegal interval if cond is false, a legal interval if cond is true, and a partially-legal one if cond’s truth value is unknown. The value of the output interval is always true.

Source§

impl Ival

Source

pub fn set_pi(&mut self)

Set this interval to contain π.

Source

pub fn set_e(&mut self)

Set this interval to contain e.

Source§

impl Ival

Source

pub fn monotonic_assign<F>(&mut self, mpfr_func: &F, a: &Ival)
where F: Fn(&Float, &mut Float, Round) -> bool,

Lift a (weakly) monotonic MPFR function to a function on intervals.

A weakly monotonic function is one where larger inputs produce larger (or equal) outputs. Note that if a non-monotonic function is passed, the results will not be sound.

Source

pub fn comonotonic_assign<F>(&mut self, mpfr_func: &F, a: &Ival)
where F: Fn(&Float, &mut Float, Round) -> bool,

Lift a (weakly) co-monotonic MPFR function to a function on intervals.

A weakly co-monotonic function is one where larger inputs produce smaller (or equal) outputs. Note that if a non-co-monotonic function is passed, the results will not be sound.

Source

pub fn neg_assign(&mut self, a: &Ival)

Compute the interval negation of a.

Source

pub fn fabs_assign(&mut self, x: &Ival)

Compute the interval absolute value of x.

Source

pub fn sqrt_assign(&mut self, a: &Ival)

Compute the interval square root of a.

Source

pub fn cbrt_assign(&mut self, a: &Ival)

Compute the interval cube root of a.

Source

pub fn exp_assign(&mut self, a: &Ival)

Compute the interval exponential of a.

Source

pub fn exp2_assign(&mut self, a: &Ival)

Compute the interval base-2 exponential of a.

Source

pub fn expm1_assign(&mut self, a: &Ival)

Compute the interval exp(a) - 1.

Source

pub fn log_assign(&mut self, a: &Ival)

Compute the interval natural logarithm of a.

Source

pub fn log2_assign(&mut self, a: &Ival)

Compute the interval base-2 logarithm of a.

Source

pub fn log10_assign(&mut self, a: &Ival)

Compute the interval base-10 logarithm of a.

Source

pub fn log1p_assign(&mut self, a: &Ival)

Compute the interval log(1 + a).

Source

pub fn logb_assign(&mut self, a: &Ival)

Compute the interval logb (exponent extraction) of a.

Source

pub fn asin_assign(&mut self, a: &Ival)

Compute the interval arcsine of a.

Source

pub fn acos_assign(&mut self, a: &Ival)

Compute the interval arccosine of a.

Source

pub fn atan_assign(&mut self, a: &Ival)

Compute the interval arctangent of a.

Source

pub fn atan2_assign(&mut self, y: &Ival, x: &Ival)

Compute the interval two-argument arctangent atan2(y, x).

Source

pub fn sinh_assign(&mut self, a: &Ival)

Compute the interval hyperbolic sine of a.

Source

pub fn cosh_assign(&mut self, a: &Ival)

Compute the interval hyperbolic cosine of a.

Source

pub fn tanh_assign(&mut self, a: &Ival)

Compute the interval hyperbolic tangent of a.

Source

pub fn asinh_assign(&mut self, a: &Ival)

Compute the interval inverse hyperbolic sine of a.

Source

pub fn acosh_assign(&mut self, a: &Ival)

Compute the interval inverse hyperbolic cosine of a.

Source

pub fn atanh_assign(&mut self, a: &Ival)

Compute the interval inverse hyperbolic tangent of a.

Source

pub fn erf_assign(&mut self, a: &Ival)

Compute the interval error function of a.

Source

pub fn erfc_assign(&mut self, a: &Ival)

Compute the interval complementary error function of a.

Source

pub fn rint_assign(&mut self, a: &Ival)

Compute the interval round-to-integer of a.

Source

pub fn round_assign(&mut self, a: &Ival)

Compute the interval round-to-integer of a.

Source

pub fn ceil_assign(&mut self, a: &Ival)

Compute the interval ceiling of a.

Source

pub fn floor_assign(&mut self, a: &Ival)

Compute the interval floor of a.

Source

pub fn trunc_assign(&mut self, a: &Ival)

Compute the interval truncation of a.

Source

pub fn fmin_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval minimum of a and b.

Source

pub fn fmax_assign(&mut self, a: &Ival, b: &Ival)

Compute the interval maximum of a and b.

Source

pub fn copysign_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval copysign(x, y).

Source§

impl Ival

Source

pub fn fmod_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval floating-point remainder fmod(x, y).

Source

pub fn remainder_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval remainder remainder(x, y).

Source§

impl Ival

Source

pub fn pow_assign(&mut self, x: &Ival, y: &Ival)

Compute the interval power x^y.

Source

pub fn pow2_assign(&mut self, x: &Ival)

Source§

impl Ival

Source

pub fn cos_assign(&mut self, x: &Ival)

Compute the interval cosine of x.

Source

pub fn sin_assign(&mut self, x: &Ival)

Compute the interval sine of x.

Source

pub fn tan_assign(&mut self, x: &Ival)

Compute the interval tangent of x.

Source§

impl Ival

Source

pub fn lo(&self) -> &Float

Returns the low endpoint of this interval.

Source

pub fn hi(&self) -> &Float

Returns the high endpoint of this interval.

Source

pub fn lo_mut(&mut self) -> &mut Float

Source

pub fn hi_mut(&mut self) -> &mut Float

Source

pub fn lo_immovable(&self) -> bool

Source

pub fn hi_immovable(&self) -> bool

Source

pub fn set_immovable(&mut self, lo: bool, hi: bool)

Source

pub fn error_flags(&self) -> ErrorFlags

Source

pub fn set_error_flags(&mut self, err: ErrorFlags)

Source

pub fn prec(&self) -> u32

Source

pub fn set_prec(&mut self, prec: u32)

Source

pub fn from_lo_hi(lo: Float, hi: Float) -> Self

Construct an interval from two endpoints.

If either endpoint is NaN, or if lo == hi and both are infinite, an illegal interval is returned (with error flags set). The interval is considered movable.

Source

pub fn bool_interval(lo_true: bool, hi_true: bool) -> Self

Construct a boolean interval.

A boolean interval has 2-bit precision endpoints: false is represented as 0 and true as 1. Boolean intervals are always immovable.

Source

pub fn f64_assign(&mut self, value: f64)

Source

pub fn zero(prec: u32) -> Self

Source

pub fn union_assign(&mut self, other: Ival)

Compute the union of this interval with other.

Maintains error flags, and movability flags when possible. If either interval is totally in error, the other is used with its partial error flag set.

Source

pub fn split_at(&self, val: &Float) -> (Ival, Ival)

Split an interval at a point, returning the two halves of that interval on either side of the split point.

Trait Implementations§

Source§

impl Clone for Ival

Source§

fn clone(&self) -> Ival

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ival

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Ival

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Ival

Source§

fn eq(&self, other: &Ival) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Ival

Source§

impl StructuralPartialEq for Ival

Auto Trait Implementations§

§

impl Freeze for Ival

§

impl RefUnwindSafe for Ival

§

impl Send for Ival

§

impl Sync for Ival

§

impl Unpin for Ival

§

impl UnsafeUnpin for Ival

§

impl UnwindSafe for Ival

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.