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: BoundLower bound.
hi: BoundUpper bound.
lo_open: boolTrue if lower bound is open (exclusive).
hi_open: boolTrue if upper bound is open (exclusive).
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn point(a: BigRational) -> Self
pub fn point(a: BigRational) -> Self
Create a point interval [a, a].
Sourcepub fn closed(a: BigRational, b: BigRational) -> Self
pub fn closed(a: BigRational, b: BigRational) -> Self
Create a closed interval [a, b].
Sourcepub fn open(a: BigRational, b: BigRational) -> Self
pub fn open(a: BigRational, b: BigRational) -> Self
Create an open interval (a, b).
Sourcepub fn half_open_right(a: BigRational, b: BigRational) -> Self
pub fn half_open_right(a: BigRational, b: BigRational) -> Self
Create a half-open interval [a, b).
Sourcepub fn half_open_left(a: BigRational, b: BigRational) -> Self
pub fn half_open_left(a: BigRational, b: BigRational) -> Self
Create a half-open interval (a, b].
Sourcepub fn at_most(b: BigRational) -> Self
pub fn at_most(b: BigRational) -> Self
Create an interval (-∞, b].
Sourcepub fn less_than(b: BigRational) -> Self
pub fn less_than(b: BigRational) -> Self
Create an interval (-∞, b).
Sourcepub fn at_least(a: BigRational) -> Self
pub fn at_least(a: BigRational) -> Self
Create an interval [a, +∞).
Sourcepub fn greater_than(a: BigRational) -> Self
pub fn greater_than(a: BigRational) -> Self
Create an interval (a, +∞).
Sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
Check if the interval is bounded (both endpoints finite).
Sourcepub fn contains(&self, x: &BigRational) -> bool
pub fn contains(&self, x: &BigRational) -> bool
Check if the interval contains a value.
Sourcepub fn contains_zero(&self) -> bool
pub fn contains_zero(&self) -> bool
Check if this interval contains zero.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if all values in the interval are positive.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if all values in the interval are negative.
Sourcepub fn is_non_negative(&self) -> bool
pub fn is_non_negative(&self) -> bool
Check if all values are non-negative.
Sourcepub fn is_non_positive(&self) -> bool
pub fn is_non_positive(&self) -> bool
Check if all values are non-positive.
Sourcepub fn sign(&self) -> Option<i8>
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.
Sourcepub fn div(&self, other: &Interval) -> Option<Interval>
pub fn div(&self, other: &Interval) -> Option<Interval>
Divide two intervals. Returns None if division by zero occurs (divisor contains zero).
Sourcepub fn intersect(&self, other: &Interval) -> Interval
pub fn intersect(&self, other: &Interval) -> Interval
Compute the intersection of two intervals.
Sourcepub fn union(&self, other: &Interval) -> Option<Interval>
pub fn union(&self, other: &Interval) -> Option<Interval>
Compute the union of two intervals (if contiguous). Returns None if the intervals are not contiguous.
Sourcepub fn midpoint(&self) -> Option<BigRational>
pub fn midpoint(&self) -> Option<BigRational>
Get the midpoint of the interval (if bounded).
Sourcepub fn width(&self) -> Option<BigRational>
pub fn width(&self) -> Option<BigRational>
Get the width of the interval (if bounded).
Sourcepub fn split(&self, at: &BigRational) -> (Interval, Interval)
pub fn split(&self, at: &BigRational) -> (Interval, Interval)
Split the interval at a point.
Sourcepub fn hull(&self, other: &Interval) -> Interval
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.
Sourcepub fn tighten_lower(&self, new_lo: Bound, new_lo_open: bool) -> Interval
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.
Sourcepub fn tighten_upper(&self, new_hi: Bound, new_hi_open: bool) -> Interval
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.
Sourcepub fn propagate_add(x: &Interval, result: &Interval) -> Interval
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.
Sourcepub fn propagate_sub_left(x: &Interval, result: &Interval) -> Interval
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.
Sourcepub fn propagate_sub_right(y: &Interval, result: &Interval) -> Interval
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.
Sourcepub fn propagate_mul(x: &Interval, result: &Interval) -> Option<Interval>
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.
Sourcepub fn propagate_div_left(x: &Interval, result: &Interval) -> Option<Interval>
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.
Sourcepub fn propagate_div_right(y: &Interval, result: &Interval) -> Interval
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.
Sourcepub fn is_subset_of(&self, other: &Interval) -> bool
pub fn is_subset_of(&self, other: &Interval) -> bool
Check if this interval is a subset of another interval.
Sourcepub fn overlaps(&self, other: &Interval) -> bool
pub fn overlaps(&self, other: &Interval) -> bool
Check if two intervals overlap (have non-empty intersection).
Sourcepub fn widen(&self, amount: &BigRational) -> Interval
pub fn widen(&self, amount: &BigRational) -> Interval
Widen the interval by a given amount on each side.