ostk.mathematics.object.RealInterval¶
- class RealInterval(
- self: ostk.mathematics.object.RealInterval,
- lower_bound: ostk.core.type.Real,
- upper_bound: ostk.core.type.Real,
- type: ostk::mathematics::object::IntervalBase::Type,
- lower_bound: ostk.core.type.Real,
Bases:
pybind11_object
Create an interval with specified bounds and type.
- Parameters:
lower_bound (float) -- The lower bound of the interval.
upper_bound (float) -- The upper bound of the interval.
type (RealInterval.Type) -- The type of interval (Closed, Open, HalfOpenLeft, HalfOpenRight).
Example
>>> interval = RealInterval(0.0, 1.0, RealInterval.Type.Closed) # [0, 1] >>> interval = RealInterval(0.0, 1.0, RealInterval.Type.Open) # (0, 1)
Methods
Clip a list of intervals with a clipping interval.
Create a closed interval [a, b].
Overloaded function.
Find gaps between intervals in a list.
Get the intersection of this interval with another interval.
Get the lower bound of the interval.
Get the union of this interval with another interval.
Get the upper bound of the interval.
Create a half-open interval (a, b].
Create a half-open interval [a, b).
Check if this interval intersects with another interval.
Check if the interval is defined.
Check if the interval is degenerate (single point).
Perform logical AND operation on two lists of intervals.
Perform logical OR operation on two lists of intervals.
Merge overlapping intervals in a list.
Create an open interval (a, b).
Sort a list of intervals.
Convert the interval to a string representation.
Create an undefined interval.
- class Type(self: ostk.mathematics.object.RealInterval.Type, value: int)¶
Bases:
pybind11_object
Members:
Undefined
Closed
Open
HalfOpenLeft
HalfOpenRight
- property name¶
- static clip(
- intervals: list[ostk.mathematics.object.RealInterval],
- clipping_interval: ostk.mathematics.object.RealInterval,
Clip a list of intervals with a clipping interval.
- Parameters:
intervals (list) -- List of intervals to clip.
clipping_interval (RealInterval) -- The interval to clip with.
- Returns:
List of clipped intervals.
- Return type:
Example
>>> intervals = [RealInterval.closed(0.0, 2.0), RealInterval.closed(3.0, 5.0)] >>> clipping = RealInterval.closed(1.0, 4.0) >>> clipped = RealInterval.clip(intervals, clipping)
- static closed(
- lower_bound: ostk.core.type.Real,
- upper_bound: ostk.core.type.Real,
Create a closed interval [a, b].
- Parameters:
- Returns:
A closed interval.
- Return type:
Example
>>> interval = RealInterval.closed(0.0, 1.0) # [0, 1] >>> interval.contains(0.0) # True >>> interval.contains(1.0) # True
- contains(*args, **kwargs)¶
Overloaded function.
contains(self: ostk.mathematics.object.RealInterval, real: ostk.core.type.Real) -> bool
Check if the interval contains a real number.
- Args:
real (float): The real number to check.
- Returns:
bool: True if the interval contains the number, False otherwise.
- Example:
>>> interval = RealInterval.closed(0.0, 1.0) >>> interval.contains(0.5) # True >>> interval.contains(1.5) # False
contains(self: ostk.mathematics.object.RealInterval, interval: ostk.mathematics.object.RealInterval) -> bool
Check if this interval contains another interval.
- Args:
interval (RealInterval): The interval to check containment for.
- Returns:
bool: True if this interval contains the other interval, False otherwise.
- Example:
>>> interval1 = RealInterval.closed(0.0, 2.0) >>> interval2 = RealInterval.closed(0.5, 1.5) >>> interval1.contains(interval2) # True
- static get_gaps(
- intervals: list[ostk.mathematics.object.RealInterval],
- bound: ostk.mathematics.object.RealInterval = RealInterval.undefined(),
Find gaps between intervals in a list.
- Parameters:
intervals (list) -- List of intervals to find gaps between.
bound (RealInterval, optional) -- Bounding interval to consider gaps within. Defaults to undefined.
- Returns:
List of intervals representing gaps.
- Return type:
Example
>>> intervals = [RealInterval.closed(0.0, 1.0), RealInterval.closed(2.0, 3.0)] >>> gaps = RealInterval.get_gaps(intervals) # Gap from 1.0 to 2.0
- get_intersection_with(
- self: ostk.mathematics.object.RealInterval,
- interval: ostk.mathematics.object.RealInterval,
Get the intersection of this interval with another interval.
- Parameters:
interval (RealInterval) -- The interval to intersect with.
- Returns:
The intersection interval, or undefined if no intersection.
- Return type:
Example
>>> interval1 = RealInterval.closed(0.0, 2.0) >>> interval2 = RealInterval.closed(1.0, 3.0) >>> intersection = interval1.get_intersection_with(interval2) >>> # intersection represents [1.0, 2.0]
- get_lower_bound( ) ostk.core.type.Real ¶
Get the lower bound of the interval.
- Returns:
The lower bound value.
- Return type:
Example
>>> interval = RealInterval.closed(0.0, 1.0) >>> interval.get_lower_bound() # 0.0
- get_union_with(
- self: ostk.mathematics.object.RealInterval,
- interval: ostk.mathematics.object.RealInterval,
Get the union of this interval with another interval.
- Parameters:
interval (RealInterval) -- The interval to union with.
- Returns:
The union interval.
- Return type:
Example
>>> interval1 = RealInterval.closed(0.0, 1.0) >>> interval2 = RealInterval.closed(0.5, 2.0) >>> union = interval1.get_union_with(interval2) >>> # union represents [0.0, 2.0]
- get_upper_bound( ) ostk.core.type.Real ¶
Get the upper bound of the interval.
- Returns:
The upper bound value.
- Return type:
Example
>>> interval = RealInterval.closed(0.0, 1.0) >>> interval.get_upper_bound() # 1.0
- static half_open_left(
- lower_bound: ostk.core.type.Real,
- upper_bound: ostk.core.type.Real,
Create a half-open interval (a, b].
- Parameters:
- Returns:
A half-open left interval.
- Return type:
Example
>>> interval = RealInterval.half_open_left(0.0, 1.0) # (0, 1] >>> interval.contains(0.0) # False >>> interval.contains(1.0) # True
- static half_open_right(
- lower_bound: ostk.core.type.Real,
- upper_bound: ostk.core.type.Real,
Create a half-open interval [a, b).
- Parameters:
- Returns:
A half-open right interval.
- Return type:
Example
>>> interval = RealInterval.half_open_right(0.0, 1.0) # [0, 1) >>> interval.contains(0.0) # True >>> interval.contains(1.0) # False
- intersects(
- self: ostk.mathematics.object.RealInterval,
- interval: ostk.mathematics.object.RealInterval,
Check if this interval intersects with another interval.
- Parameters:
interval (RealInterval) -- The interval to check intersection with.
- Returns:
True if intervals intersect, False otherwise.
- Return type:
Example
>>> interval1 = RealInterval.closed(0.0, 2.0) >>> interval2 = RealInterval.closed(1.0, 3.0) >>> interval1.intersects(interval2) # True
- is_defined(self: ostk.mathematics.object.RealInterval) bool ¶
Check if the interval is defined.
- Returns:
True if the interval is defined, False otherwise.
- Return type:
Example
>>> interval = RealInterval.closed(0.0, 1.0) >>> interval.is_defined() # True
- is_degenerate(self: ostk.mathematics.object.RealInterval) bool ¶
Check if the interval is degenerate (single point).
- Returns:
True if the interval represents a single point, False otherwise.
- Return type:
Example
>>> interval = RealInterval.closed(1.0, 1.0) >>> interval.is_degenerate() # True
- static logical_and(
- intervals_1: list[ostk.mathematics.object.RealInterval],
- intervals_2: list[ostk.mathematics.object.RealInterval],
Perform logical AND operation on two lists of intervals.
- Parameters:
- Returns:
List of intervals representing the intersection of both lists.
- Return type:
Example
>>> intervals1 = [RealInterval.closed(0.0, 2.0)] >>> intervals2 = [RealInterval.closed(1.0, 3.0)] >>> result = RealInterval.logical_and(intervals1, intervals2) # [1.0, 2.0]
- static logical_or(
- intervals_1: list[ostk.mathematics.object.RealInterval],
- intervals_2: list[ostk.mathematics.object.RealInterval],
Perform logical OR operation on two lists of intervals.
- Parameters:
- Returns:
List of intervals representing the union of both lists.
- Return type:
Example
>>> intervals1 = [RealInterval.closed(0.0, 1.0)] >>> intervals2 = [RealInterval.closed(2.0, 3.0)] >>> result = RealInterval.logical_or(intervals1, intervals2)
- static merge(
- intervals: list[ostk.mathematics.object.RealInterval],
Merge overlapping intervals in a list.
- Parameters:
intervals (list) -- List of intervals to merge.
- Returns:
List of merged intervals with no overlaps.
- Return type:
Example
>>> intervals = [RealInterval.closed(0.0, 2.0), RealInterval.closed(1.0, 3.0)] >>> merged = RealInterval.merge(intervals) # [RealInterval.closed(0.0, 3.0)]
- static open(
- lower_bound: ostk.core.type.Real,
- upper_bound: ostk.core.type.Real,
Create an open interval (a, b).
- Parameters:
- Returns:
An open interval.
- Return type:
Example
>>> interval = RealInterval.open(0.0, 1.0) # (0, 1) >>> interval.contains(0.0) # False >>> interval.contains(1.0) # False >>> interval.contains(0.5) # True
- static sort(
- intervals: list[ostk.mathematics.object.RealInterval],
- by_lower_bound: bool = True,
- ascending: bool = True,
- by_lower_bound: bool = True,
Sort a list of intervals.
- Parameters:
- Returns:
Sorted list of intervals.
- Return type:
Example
>>> intervals = [RealInterval.closed(2.0, 3.0), RealInterval.closed(0.0, 1.0)] >>> sorted_intervals = RealInterval.sort(intervals)
- to_string( ) ostk.core.type.String ¶
Convert the interval to a string representation.
- Returns:
String representation of the interval.
- Return type:
Example
>>> interval = RealInterval.closed(0.0, 1.0) >>> interval.to_string() # "[0, 1]"
- static undefined() ostk.mathematics.object.RealInterval ¶
Create an undefined interval.
- Returns:
An undefined interval.
- Return type:
Example
>>> undefined_interval = RealInterval.undefined() >>> undefined_interval.is_defined() # False