Skip to main content

Interval

Struct Interval 

Source
pub struct Interval {
    pub lo: Bound,
    pub hi: Bound,
    pub lo_open: bool,
    pub hi_open: bool,
}
Expand description

An interval [lo, hi] with optional open/closed endpoints. Represents the set of values x such that lo ≤ x ≤ hi (closed) or lo < x < hi (open), depending on the flags.

Fields§

§lo: Bound

Lower bound.

§hi: Bound

Upper bound.

§lo_open: bool

True if lower bound is open (exclusive).

§hi_open: bool

True if upper bound is open (exclusive).

Implementations§

Source§

impl Interval

Source

pub fn empty() -> Self

Create the empty interval.

Source

pub fn reals() -> Self

Create the interval containing all reals (-∞, +∞).

Source

pub fn point(a: BigRational) -> Self

Create a point interval [a, a].

Source

pub fn closed(a: BigRational, b: BigRational) -> Self

Create a closed interval [a, b].

Source

pub fn open(a: BigRational, b: BigRational) -> Self

Create an open interval (a, b).

Source

pub fn half_open_right(a: BigRational, b: BigRational) -> Self

Create a half-open interval [a, b).

Source

pub fn half_open_left(a: BigRational, b: BigRational) -> Self

Create a half-open interval (a, b].

Source

pub fn at_most(b: BigRational) -> Self

Create an interval (-∞, b].

Source

pub fn less_than(b: BigRational) -> Self

Create an interval (-∞, b).

Source

pub fn at_least(a: BigRational) -> Self

Create an interval [a, +∞).

Source

pub fn greater_than(a: BigRational) -> Self

Create an interval (a, +∞).

Source

pub fn is_empty(&self) -> bool

Check if the interval is empty.

Source

pub fn is_point(&self) -> bool

Check if the interval is a single point.

Source

pub fn is_bounded(&self) -> bool

Check if the interval is bounded (both endpoints finite).

Source

pub fn contains(&self, x: &BigRational) -> bool

Check if the interval contains a value.

Source

pub fn contains_zero(&self) -> bool

Check if this interval contains zero.

Source

pub fn is_positive(&self) -> bool

Check if all values in the interval are positive.

Source

pub fn is_negative(&self) -> bool

Check if all values in the interval are negative.

Source

pub fn is_non_negative(&self) -> bool

Check if all values are non-negative.

Source

pub fn is_non_positive(&self) -> bool

Check if all values are non-positive.

Source

pub fn sign(&self) -> Option<i8>

Get the sign of the interval. Returns Some(1) if all positive, Some(-1) if all negative, Some(0) if only zero. Returns None if the interval contains values of different signs.

Source

pub fn negate(&self) -> Interval

Negate the interval.

Source

pub fn add(&self, other: &Interval) -> Interval

Add two intervals.

Source

pub fn sub(&self, other: &Interval) -> Interval

Subtract two intervals.

Source

pub fn mul(&self, other: &Interval) -> Interval

Multiply two intervals.

Source

pub fn div(&self, other: &Interval) -> Option<Interval>

Divide two intervals. Returns None if division by zero occurs (divisor contains zero).

Source

pub fn intersect(&self, other: &Interval) -> Interval

Compute the intersection of two intervals.

Source

pub fn union(&self, other: &Interval) -> Option<Interval>

Compute the union of two intervals (if contiguous). Returns None if the intervals are not contiguous.

Source

pub fn pow(&self, n: u32) -> Interval

Compute the power of an interval.

Source

pub fn midpoint(&self) -> Option<BigRational>

Get the midpoint of the interval (if bounded).

Source

pub fn width(&self) -> Option<BigRational>

Get the width of the interval (if bounded).

Source

pub fn split(&self, at: &BigRational) -> (Interval, Interval)

Split the interval at a point.

Source

pub fn hull(&self, other: &Interval) -> Interval

Convex hull of two intervals (always returns a single interval). This is the smallest interval containing both inputs.

Source

pub fn tighten_lower(&self, new_lo: Bound, new_lo_open: bool) -> Interval

Tighten lower bound to be at least the given value. Returns a new interval with the tightened bound, or empty if inconsistent.

Source

pub fn tighten_upper(&self, new_hi: Bound, new_hi_open: bool) -> Interval

Tighten upper bound to be at most the given value. Returns a new interval with the tightened bound, or empty if inconsistent.

Source

pub fn propagate_add(x: &Interval, result: &Interval) -> Interval

Propagate bounds from constraint: x + y ∈ result_interval. Given x and result, tighten y’s bounds. Returns the tightened interval for y.

Source

pub fn propagate_sub_left(x: &Interval, result: &Interval) -> Interval

Propagate bounds from constraint: x - y ∈ result_interval. Given x and result, tighten y’s bounds. Returns the tightened interval for y.

Source

pub fn propagate_sub_right(y: &Interval, result: &Interval) -> Interval

Propagate bounds from constraint: x - y ∈ result_interval. Given y and result, tighten x’s bounds. Returns the tightened interval for x.

Source

pub fn propagate_mul(x: &Interval, result: &Interval) -> Option<Interval>

Propagate bounds from constraint: x * y ∈ result_interval. Given x and result, tighten y’s bounds (if x doesn’t contain 0). Returns None if x contains 0, otherwise returns the tightened interval for y.

Source

pub fn propagate_div_left(x: &Interval, result: &Interval) -> Option<Interval>

Propagate bounds from constraint: x / y ∈ result_interval. Given x and result, tighten y’s bounds (if result doesn’t contain 0). Returns None if propagation is impossible, otherwise returns the tightened interval for y.

Source

pub fn propagate_div_right(y: &Interval, result: &Interval) -> Interval

Propagate bounds from constraint: x / y ∈ result_interval. Given y and result, tighten x’s bounds. Returns the tightened interval for x.

Source

pub fn is_subset_of(&self, other: &Interval) -> bool

Check if this interval is a subset of another interval.

Source

pub fn overlaps(&self, other: &Interval) -> bool

Check if two intervals overlap (have non-empty intersection).

Source

pub fn widen(&self, amount: &BigRational) -> Interval

Widen the interval by a given amount on each side.

Trait Implementations§

Source§

impl Add<&Interval> for &Interval

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Interval) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Interval

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Interval

Source§

fn clone(&self) -> Interval

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Interval

Source§

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

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

impl Default for Interval

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Interval

Source§

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

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

impl Div<&Interval> for &Interval

Source§

type Output = Option<Interval>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Interval) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Interval

Source§

type Output = Option<Interval>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Mul<&Interval> for &Interval

Source§

type Output = Interval

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Interval) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Interval

Source§

type Output = Interval

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for &Interval

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for Interval

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Interval

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Sub<&Interval> for &Interval

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Interval) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Interval

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Eq for Interval

Source§

impl StructuralPartialEq for Interval

Auto Trait Implementations§

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> 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<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<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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.