vectors_in_intervals.intervals¶
Interval classes.
Classes
|
An interval. |
|
A Cartesian product of intervals. |
- class vectors_in_intervals.intervals.Interval(lower, upper, lower_closed: bool = True, upper_closed: bool = True)¶
An interval.
Also supports variables.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(0, 1) [0, 1] sage: Interval(0, 1, False, True) (0, 1] sage: Interval(0, 1, False, False) (0, 1) sage: Interval(0, 1, True, False) [0, 1) sage: Interval(0, 0) {0} sage: Interval(0, 0, False, False) {} sage: Interval(0, 0, True, True) {0} sage: Interval(0, 0, True, False) {} sage: Interval(0, 0, False, True) {} sage: Interval(-oo, 4) (-oo, 4] sage: Interval(-oo, 4, False, False) (-oo, 4) sage: I = Interval(-3, +oo, False, False) sage: I (-3, +oo) sage: 0 in I True sage: -3 in I False sage: Interval.random() # random (-1, 1)
Variables are supported, too:
sage: var("a") a sage: Interval(a, 1) [a, 1] sage: I = Interval(a, 1, False, False) sage: I (a, 1) sage: I.an_element() 1/2*a + 1/2
- an_element()¶
Return an element of the interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(0, 1).an_element() 0 sage: Interval(0, 1, False, True).an_element() 1 sage: Interval(0, 1, False, False).an_element() 1/2 sage: Interval(-oo, 0).an_element() 0 sage: Interval(-oo, +oo).an_element() 0 sage: Interval(5, +oo, False, False).an_element() 6 sage: Interval(0, 0, False, False).an_element() Traceback (most recent call last): ... ValueError: The interval is empty.
- static closed(lower, upper) vectors_in_intervals.intervals.Interval ¶
Return a closed interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval.closed(0, 1) [0, 1]
- static empty() vectors_in_intervals.intervals.Interval ¶
Return the empty interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval.empty() {}
- infimum()¶
Return the infimum of the interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(0, 1).infimum() 0 sage: Interval(-oo, 0).infimum() -Infinity sage: Interval(0, 0, False, False).infimum() +Infinity
- is_bounded() bool ¶
Return whether the interval is bounded.
- is_closed() bool ¶
Return whether the interval is closed.
- is_empty() bool ¶
Return whether the interval is empty.
- is_open() bool ¶
Return whether the interval is open.
- is_pointed() bool ¶
Return whether the interval is a point.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(0, 0).is_pointed() True sage: Interval(0, 1).is_pointed() False
- is_unbounded() bool ¶
Return whether the interval is unbounded.
- static open(lower, upper) vectors_in_intervals.intervals.Interval ¶
Return an open interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval.open(0, 1) (0, 1)
- static random(ring=Rational Field, allow_infinity: bool = True, allow_empty: bool = False) vectors_in_intervals.intervals.Interval ¶
Generate a random interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval.random() # random (-1, 1)
- simplest_element()¶
Return the simplest rational in this interval.
OUTPUT: If possible, an integer with smallest possible absolute value will be returned. Otherwise, a rational number with smallest possible denominator is constructed.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(1/2, +oo, False, False).simplest_element() 1 sage: Interval(-oo, 1/2, False, False).simplest_element() 0 sage: Interval(-19, 0, False, False).simplest_element() -1 sage: Interval(0, 1, False, False).simplest_element() 1/2 sage: Interval(-2/3, 0, False, False).simplest_element() -1/2 sage: Interval(4/3, 3/2, False, False).simplest_element() 7/5 sage: Interval(0, 0).simplest_element() 0 sage: Interval(5, 5).simplest_element() 5 sage: Interval(sqrt(2), pi/2).simplest_element() 3/2 sage: Interval(1/2, 1/2).simplest_element() 1/2
- supremum()¶
Return the supremum of the interval.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Interval(0, 1).supremum() 1 sage: Interval(0, +oo).supremum() +Infinity sage: Interval(0, 0, False, False).supremum() -Infinity
- class vectors_in_intervals.intervals.Intervals(intervals: list)¶
A Cartesian product of intervals.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Intervals([Interval(0, 1), Interval(-5, 2, False, False), Interval(0, 1)]) [0, 1] x (-5, 2) x [0, 1] sage: vector([0, 1]) in Intervals([Interval(0, 1), Interval(-5, 2)]) True sage: Intervals.random(3) # random [0, +oo) x (-5, 2) x (0, 1]
- static from_bounds(lower_bounds: list, upper_bounds: list, lower_bounds_closed: bool = True, upper_bounds_closed: bool = True) vectors_in_intervals.intervals.Intervals ¶
Return intervals that are determined by bounds.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Intervals.from_bounds([0, -5, 0], [1, 2, +oo]) [0, 1] x [-5, 2] x [0, +oo) sage: Intervals.from_bounds([0, -5, 0], [1, 2, +oo], False, False) (0, 1) x (-5, 2) x (0, +oo) sage: Intervals.from_bounds([0, -5, 0], [1, 2, +oo], True, False) [0, 1) x [-5, 2) x [0, +oo) sage: Intervals.from_bounds([0, -5, 0], [1, 2, +oo], [True, False, True], [True, True, False]) [0, 1] x (-5, 2] x [0, +oo)
- static from_sign_vector(sv: sign_vectors.sign_vectors.SignVector) vectors_in_intervals.intervals.Intervals ¶
Return intervals that are determined by a sign vector.
EXAMPLES:
sage: from vectors_in_intervals import * sage: from sign_vectors import * sage: sv = sign_vector("+0-") sage: Intervals.from_sign_vector(sv) (0, +oo) x {0} x (-oo, 0)
- static random(length: int, ring=Rational Field) vectors_in_intervals.intervals.Intervals ¶
Generate a random list of intervals.
EXAMPLES:
sage: from vectors_in_intervals import * sage: Intervals.random(3) # random [0, +oo) x (-5, 2) x (0, 1]
- vectors_in_intervals.intervals.getrandbits(k) x. Generates an int with k random bits. ¶