vectors_in_intervals.setup_intervals

Setting up lists of intervals

Functions

intervals_from_bounds(lower_bounds, upper_bounds)

Construct a list of intervals from lists of bounds.

intervals_from_sign_vector(sv)

Return intervals that are determined by a sign vector.

is_vector_in_intervals(v, intervals)

Check if a vector lies in a list of intervals.

random_intervals(length[, ring, ...])

Generate a list of random intervals.

vectors_in_intervals.setup_intervals.intervals_from_bounds(lower_bounds: list, upper_bounds: list, lower_bounds_closed: bool = True, upper_bounds_closed: bool = True) list[sage.sets.real_set.RealSet]

Construct a list of intervals from lists of bounds.

INPUT:

  • lower_bounds – a list of real values and infinity of length n

  • upper_bounds – a list of real values and infinity of length n

  • lower_bounds_closed – a boolean (default: True) or a list of booleans of length n

  • upper_bounds_closed – a boolean (default: True) or a list of booleans of length n

OUTPUT:

A list of RealSet objects of length n.

  • lower_bounds and upper_bounds are the lower and upper interval bounds. If lower_bounds[i] > upper_bounds[i], those elements will be exchanged.

  • lower_bounds_closed and upper_bounds_closed determine the intervals.

  • The lower (or upper) interval bounds of the i-th interval is

    • closed if lower_bounds_closed[i] (or upper_bounds_closed[i]) is True (default).

    • open if lower_bounds_closed[i] (or upper_bounds_closed[i]) is False.

  • If lower_bounds_closed (or upper_bounds_closed) is a boolean, then all lower or upper interval bounds are considered closed if True (default) and open if False.

EXAMPLES:

sage: from vectors_in_intervals import *
sage: lower_bounds = [2, 5, -1]
sage: upper_bounds = [5, 6, 1]

By default, the intervals are closed:

sage: intervals_from_bounds(lower_bounds, upper_bounds)
[[2, 5], [5, 6], [-1, 1]]

We obtain open intervals if both lower_bounds_closed and upper_bounds_closed are false:

sage: intervals_from_bounds(lower_bounds, upper_bounds, False, False)
[(2, 5), (5, 6), (-1, 1)]

Mixed intervals are also possible:

sage: intervals_from_bounds(lower_bounds, upper_bounds, False)
[(2, 5], (5, 6], (-1, 1]]
sage: intervals_from_bounds(lower_bounds, upper_bounds, [False, True, True], [True, True, False])
[(2, 5], [5, 6], [-1, 1)]

We can also specify unbounded intervals. Note that bounds at infinity are always open:

sage: lower_bounds = [-oo, 2, -oo]
sage: upper_bounds = [-5, oo, oo]
sage: intervals_from_bounds(lower_bounds, upper_bounds)
[(-oo, -5], [2, +oo), (-oo, +oo)]

Finite and empty intervals are represented as usual:

sage: lower_bounds = [0, 2]
sage: upper_bounds = [0, 2]
sage: intervals_from_bounds(lower_bounds, upper_bounds, [True, False], True)
[{0}, {}]

If the lower bound is greater than the upper bound, those bounds will be exchanged:

sage: lower_bounds = [1, 4]
sage: upper_bounds = [2, 3]
sage: intervals_from_bounds(lower_bounds, upper_bounds, False)
[(1, 2], (3, 4]]
vectors_in_intervals.setup_intervals.intervals_from_sign_vector(sv) list[sage.sets.real_set.RealSet]

Return intervals that are determined by a sign vector.

EXAMPLES:

sage: from sign_vectors import *
sage: from vectors_in_intervals import *
sage: intervals_from_sign_vector(sign_vector("++0-"))
[(0, +oo), (0, +oo), {0}, (-oo, 0)]
vectors_in_intervals.setup_intervals.is_vector_in_intervals(v, intervals: list[sage.sets.real_set.RealSet]) bool

Check if a vector lies in a list of intervals.

EXAMPLES:

sage: from vectors_in_intervals import *
sage: v = vector([5, 0, -10])
sage: intervals = intervals_from_bounds([0, 0, -oo], [oo, 0, 0])
sage: is_vector_in_intervals(v, intervals)
True
sage: is_vector_in_intervals(-v, intervals)
False
vectors_in_intervals.setup_intervals.random_intervals(length: int, ring=Rational Field, allow_infinity: bool = True, allow_open: bool = True, allow_empty: bool = False) list[sage.sets.real_set.RealSet]

Generate a list of random intervals.

EXAMPLES:

sage: from vectors_in_intervals import *
sage: random_intervals(5) # random
[(-oo, -4), [1, 2], (0, 1], (-oo, 1/2], (0, oo)]