vectors_in_intervals.utility¶
Utility functions
Functions
|
Find a solution for |
|
Solve a linear system of equations without division. |
Classes
|
Combinatorial object of all combinations that include given elements |
- class vectors_in_intervals.utility.CombinationsIncluding(mset, k, elements=None)¶
Combinatorial object of all combinations that include given elements
EXAMPLES:
We generate all subsets of
range(4)
with2
elements that include the element2
:sage: from vectors_in_intervals.utility import CombinationsIncluding sage: C = CombinationsIncluding(4, 2, [2]) sage: list(C) [[0, 2], [1, 2], [2, 3]] sage: list(reversed(C)) [[2, 3], [1, 2], [0, 2]]
- 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
- 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'>
- 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
- vectors_in_intervals.utility.solve_left_for_roots(A, b)¶
Find a solution for
x*A = b
that works for matrices whose entries are roots.INPUT:
A
– a matrixb
– a vector
NOTE:
The built in method ``solve_left`` for matrices fails occasionally.
- vectors_in_intervals.utility.solve_without_division(A, b)¶
Solve a linear system of equations without division.
The system is
A x = c b
wherec
is a positive constant. Uses an elementary vector.EXAMPLES:
sage: from vectors_in_intervals.utility import solve_without_division sage: A = matrix([[1, 2], [0, 1], [1, -1]]) sage: b = vector([1, 0, 1]) sage: solve_without_division(A, b) (1, 0) sage: A = matrix([[1, 4], [0, 2], [1, -2]]) sage: b = vector([6, 2, 0]) sage: solve_without_division(A, b) (4, 2) sage: A.solve_right(b) (2, 1) sage: A = matrix([[1, 1, 1], [0, 1, 2]]) sage: b = vector([2, 3]) sage: solve_without_division(A, b) (0, 1, 1)