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.
- category(self)¶
File: sage/structure/sage_object.pyx (starting at line 484)
- classmethod 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]
- dump(self, filename, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 445)
Same as self.save(filename, compress)
- dumps(self, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 451)
Dump
self
to a strings
, which can later be reconstituted asself
usingloads(s)
.There is an optional boolean argument
compress
which defaults toTrue
.EXAMPLES:
sage: from sage.misc.persist import comp sage: O = SageObject() sage: p_comp = O.dumps() sage: p_uncomp = O.dumps(compress=False) sage: comp.decompress(p_comp) == p_uncomp True sage: import pickletools sage: pickletools.dis(p_uncomp) 0: \x80 PROTO 2 2: c GLOBAL 'sage.structure.sage_object SageObject' 41: q BINPUT ... 43: ) EMPTY_TUPLE 44: \x81 NEWOBJ 45: q BINPUT ... 47: . STOP highest protocol among opcodes = 2
- classmethod 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.
An interval is pointed if it has the same lower and upper bound, and both are closed.
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.
- classmethod 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)
- parent(self)¶
File: sage/structure/sage_object.pyx (starting at line 518)
Return the type of
self
to support the coercion framework.EXAMPLES:
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods() sage: u.parent() <class 'sage.symbolic.maxima_wrapper.MaximaWrapper'>
- classmethod 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)
- rename(self, x=None)¶
File: sage/structure/sage_object.pyx (starting at line 68)
Change self so it prints as x, where x is a string.
Note
This is only supported for Python classes that derive from SageObject.
EXAMPLES:
sage: x = PolynomialRing(QQ, 'x', sparse=True).gen() sage: g = x^3 + x - 5 sage: g x^3 + x - 5 sage: g.rename('a polynomial') sage: g a polynomial sage: g + x x^3 + 2*x - 5 sage: h = g^100 sage: str(h)[:20] 'x^300 + 100*x^298 - ' sage: h.rename('x^300 + ...') sage: h x^300 + ...
Real numbers are not Python classes, so rename is not supported:
sage: a = 3.14 sage: type(a) <... 'sage.rings.real_mpfr.RealLiteral'> sage: a.rename('pi') Traceback (most recent call last): ... NotImplementedError: object does not support renaming: 3.14000000000000
Note
The reason C-extension types are not supported by default is if they were then every single one would have to carry around an extra attribute, which would be slower and waste a lot of memory.
To support them for a specific class, add a
cdef public __custom_name
attribute.
- reset_name(self)¶
File: sage/structure/sage_object.pyx (starting at line 125)
Remove the custom name of an object.
EXAMPLES:
sage: P.<x> = QQ[] sage: P Univariate Polynomial Ring in x over Rational Field sage: P.rename('A polynomial ring') sage: P A polynomial ring sage: P.reset_name() sage: P Univariate Polynomial Ring in x over Rational Field
- save(self, filename=None, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 420)
Save self to the given filename.
EXAMPLES:
sage: f = x^3 + 5 sage: f.save(os.path.join(SAGE_TMP, 'file')) sage: load(os.path.join(SAGE_TMP, 'file.sobj')) x^3 + 5
- 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[vectors_in_intervals.intervals.Interval])¶
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]
- an_element()¶
Return an element from each interval.
- category(self)¶
File: sage/structure/sage_object.pyx (starting at line 484)
- dump(self, filename, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 445)
Same as self.save(filename, compress)
- dumps(self, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 451)
Dump
self
to a strings
, which can later be reconstituted asself
usingloads(s)
.There is an optional boolean argument
compress
which defaults toTrue
.EXAMPLES:
sage: from sage.misc.persist import comp sage: O = SageObject() sage: p_comp = O.dumps() sage: p_uncomp = O.dumps(compress=False) sage: comp.decompress(p_comp) == p_uncomp True sage: import pickletools sage: pickletools.dis(p_uncomp) 0: \x80 PROTO 2 2: c GLOBAL 'sage.structure.sage_object SageObject' 41: q BINPUT ... 43: ) EMPTY_TUPLE 44: \x81 NEWOBJ 45: q BINPUT ... 47: . STOP highest protocol among opcodes = 2
- classmethod 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)
- classmethod 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)
- is_bounded() bool ¶
Return whether all intervals are bounded.
- is_closed() bool ¶
Return whether all intervals are closed.
- is_empty() bool ¶
Return whether the intervals are empty.
- is_open() bool ¶
Return whether all intervals are open.
- is_pointed() bool ¶
Return whether all intervals are pointed.
- is_unbounded() bool ¶
Return whether any interval is unbounded.
- parent(self)¶
File: sage/structure/sage_object.pyx (starting at line 518)
Return the type of
self
to support the coercion framework.EXAMPLES:
sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods() sage: u.parent() <class 'sage.symbolic.maxima_wrapper.MaximaWrapper'>
- classmethod 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]
- rename(self, x=None)¶
File: sage/structure/sage_object.pyx (starting at line 68)
Change self so it prints as x, where x is a string.
Note
This is only supported for Python classes that derive from SageObject.
EXAMPLES:
sage: x = PolynomialRing(QQ, 'x', sparse=True).gen() sage: g = x^3 + x - 5 sage: g x^3 + x - 5 sage: g.rename('a polynomial') sage: g a polynomial sage: g + x x^3 + 2*x - 5 sage: h = g^100 sage: str(h)[:20] 'x^300 + 100*x^298 - ' sage: h.rename('x^300 + ...') sage: h x^300 + ...
Real numbers are not Python classes, so rename is not supported:
sage: a = 3.14 sage: type(a) <... 'sage.rings.real_mpfr.RealLiteral'> sage: a.rename('pi') Traceback (most recent call last): ... NotImplementedError: object does not support renaming: 3.14000000000000
Note
The reason C-extension types are not supported by default is if they were then every single one would have to carry around an extra attribute, which would be slower and waste a lot of memory.
To support them for a specific class, add a
cdef public __custom_name
attribute.
- reset_name(self)¶
File: sage/structure/sage_object.pyx (starting at line 125)
Remove the custom name of an object.
EXAMPLES:
sage: P.<x> = QQ[] sage: P Univariate Polynomial Ring in x over Rational Field sage: P.rename('A polynomial ring') sage: P A polynomial ring sage: P.reset_name() sage: P Univariate Polynomial Ring in x over Rational Field
- save(self, filename=None, compress=True)¶
File: sage/structure/sage_object.pyx (starting at line 420)
Save self to the given filename.
EXAMPLES:
sage: f = x^3 + 5 sage: f.save(os.path.join(SAGE_TMP, 'file')) sage: load(os.path.join(SAGE_TMP, 'file.sobj')) x^3 + 5
- sign_vectors(generator: bool = False) Union[list[sign_vectors.sign_vectors.SignVector], Iterator[sign_vectors.sign_vectors.SignVector]] ¶
Compute all sign vectors that correspond to a vector with components in given intervals.
INPUT:
intervals
– a list of intervalsgenerator
– a boolean (default:False
)
EXAMPLES:
sage: from vectors_in_intervals import * sage: intervals = Intervals.from_bounds([-1, 1], [0, 1]) sage: intervals.sign_vectors() [(0+), (-+)] sage: intervals = Intervals.from_bounds([-1, -2], [0, 1]) sage: intervals.sign_vectors() [(00), (0+), (0-), (-0), (-+), (--)] sage: intervals = Intervals.from_bounds([-1, -1, 0], [0, 5, 0]) sage: intervals.sign_vectors() [(000), (0+0), (0-0), (-00), (-+0), (--0)] sage: intervals = Intervals.from_bounds([-1, -1, -1], [0, 1, 0], False, False) sage: intervals.sign_vectors() [(-0-), (-+-), (---)]
TESTS:
sage: intervals = Intervals.from_bounds([-1, 0], [1, 0], False, False) sage: intervals.sign_vectors() [] sage: intervals = Intervals.from_bounds([], []) sage: intervals.sign_vectors() []
- simplest_element()¶
Return the simplest element from each interval.
- vectors_in_intervals.intervals.getrandbits(k) x. Generates an int with k random bits. ¶