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,
)

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

Clip a list of intervals with a clipping interval.

closed

Create a closed interval [a, b].

contains

Overloaded function.

get_gaps

Find gaps between intervals in a list.

get_intersection_with

Get the intersection of this interval with another interval.

get_lower_bound

Get the lower bound of the interval.

get_union_with

Get the union of this interval with another interval.

get_upper_bound

Get the upper bound of the interval.

half_open_left

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

half_open_right

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

intersects

Check if this interval intersects with another interval.

is_defined

Check if the interval is defined.

is_degenerate

Check if the interval is degenerate (single point).

logical_and

Perform logical AND operation on two lists of intervals.

logical_or

Perform logical OR operation on two lists of intervals.

merge

Merge overlapping intervals in a list.

open

Create an open interval (a, b).

sort

Sort a list of intervals.

to_string

Convert the interval to a string representation.

undefined

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,
) list[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:

list

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,
) ostk.mathematics.object.RealInterval

Create a closed interval [a, b].

Parameters:
  • lower_bound (float) -- The lower bound (inclusive).

  • upper_bound (float) -- The upper bound (inclusive).

Returns:

A closed interval.

Return type:

RealInterval

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.

  1. 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
    
  2. 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(),
) list[ostk.mathematics.object.RealInterval]

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:

list

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,
) 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:

RealInterval

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(
self: ostk.mathematics.object.RealInterval,
) ostk.core.type.Real

Get the lower bound of the interval.

Returns:

The lower bound value.

Return type:

float

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,
) 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:

RealInterval

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(
self: ostk.mathematics.object.RealInterval,
) ostk.core.type.Real

Get the upper bound of the interval.

Returns:

The upper bound value.

Return type:

float

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,
) ostk.mathematics.object.RealInterval

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

Parameters:
  • lower_bound (float) -- The lower bound (exclusive).

  • upper_bound (float) -- The upper bound (inclusive).

Returns:

A half-open left interval.

Return type:

RealInterval

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,
) ostk.mathematics.object.RealInterval

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

Parameters:
  • lower_bound (float) -- The lower bound (inclusive).

  • upper_bound (float) -- The upper bound (exclusive).

Returns:

A half-open right interval.

Return type:

RealInterval

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,
) bool

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:

bool

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:

bool

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:

bool

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],
) list[ostk.mathematics.object.RealInterval]

Perform logical AND operation on two lists of intervals.

Parameters:
  • intervals_1 (list) -- First list of intervals.

  • intervals_2 (list) -- Second list of intervals.

Returns:

List of intervals representing the intersection of both lists.

Return type:

list

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],
) list[ostk.mathematics.object.RealInterval]

Perform logical OR operation on two lists of intervals.

Parameters:
  • intervals_1 (list) -- First list of intervals.

  • intervals_2 (list) -- Second list of intervals.

Returns:

List of intervals representing the union of both lists.

Return type:

list

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],
) 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:

list

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,
) ostk.mathematics.object.RealInterval

Create an open interval (a, b).

Parameters:
  • lower_bound (float) -- The lower bound (exclusive).

  • upper_bound (float) -- The upper bound (exclusive).

Returns:

An open interval.

Return type:

RealInterval

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,
) list[ostk.mathematics.object.RealInterval]

Sort a list of intervals.

Parameters:
  • intervals (list) -- List of intervals to sort.

  • by_lower_bound (bool, optional) -- Sort by lower bound if True, upper bound if False. Defaults to True.

  • ascending (bool, optional) -- Sort in ascending order if True, descending if False. Defaults to True.

Returns:

Sorted list of intervals.

Return type:

list

Example

>>> intervals = [RealInterval.closed(2.0, 3.0), RealInterval.closed(0.0, 1.0)]
>>> sorted_intervals = RealInterval.sort(intervals)
to_string(
self: ostk.mathematics.object.RealInterval,
) ostk.core.type.String

Convert the interval to a string representation.

Returns:

String representation of the interval.

Return type:

str

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:

RealInterval

Example

>>> undefined_interval = RealInterval.undefined()
>>> undefined_interval.is_defined()  # False