vectors_in_intervals.linear_inequality_systems

Linear inequality systems

EXAMPLES:

sage: from vectors_in_intervals import *
sage: A = matrix([[1, 2], [0, 1]])
sage: B = matrix([[2, 3]])
sage: C = matrix([[-1, 0]])
sage: S = HomogeneousSystem(A, B, C)
sage: S.intervals
[(0, +oo), (0, +oo), [0, +oo), {0}]
sage: S.solve()
(0, 1)
sage: S.certify_existence()
(2, 1, 3, 0)
sage: S.certify_nonexistence()
Traceback (most recent call last):
...
ValueError: A solution exists!
sage: S.certify()
(True, (2, 1, 3, 0))
sage: S.certify(reverse=True)
(True, (2, 1, 3, 0))
sage: S.certify_parallel()
(True, (2, 1, 3, 0))
sage: S.certify_parallel(reverse=True)
(True, (2, 1, 3, 0))
sage: S.certify_parallel(random=True)
(True, (2, 1, 3, 0))

We consider another system:

sage: M = matrix([[1, 0], [0, 1], [1, 1], [0, 1]])
sage: lower_bounds = [2, 5, 0, -oo]
sage: upper_bounds = [5, oo, 8, 5]
sage: lower_bounds_closed = [True, True, False, False]
sage: upper_bounds_closed = [False, False, False, True]
sage: I = Intervals.from_bounds(lower_bounds, upper_bounds, lower_bounds_closed, upper_bounds_closed)
sage: S = LinearInequalitySystem(M, I)
sage: S.solve()
(5/2, 5)
sage: S.certify_existence()
(5, 15, 1, 2, 1, 0, 0)
sage: S.certify()
(True, (5, 15, 1, 2, 1, 0, 0))
sage: S.certify(reverse=True)
(True, (3, 7, 1, 1, 0, 0, 0))
sage: # S.certify_parallel() # TODO SignalError: Segmentation Fault
(True, (3, 7, 1, 1, 0, 0, 0))

We consider yet another system:

sage: A = matrix([[1, 0], [1, 1]])
sage: B = matrix([[-1, -1]])
sage: b = vector([1, 0])
sage: c = vector([0])
sage: S = InhomogeneousSystem(A, B, b, c)
sage: S.certify()
(False, (0, 1, 1))
sage: S.certify_parallel()
(False, (0, 1, 1))
sage: S.certify_parallel(random=True)
(False, (0, 1, 1))

In the case of homogeneous systems, we can use cocircuits to certify:

sage: A = matrix([[1, 2], [0, 1]])
sage: B = matrix([[2, 3]])
sage: C = matrix([[-1, 0]])
sage: S = HomogeneousSystemCocircuits(A, B, C) # TODO: not implemented
sage: S.solve() # TODO: not implemented
Traceback (most recent call last):
...
ValueError: Can't solve using cocircuits!
sage: S.certify_existence() # TODO: not implemented
(+++0)
sage: # S.certify() # TODO

Now, we consider the example:

sage: A = matrix([[1, 0], [0, 1]])
sage: B = matrix([[2, -3]])
sage: C = matrix([[-1, -1]])
sage: S = HomogeneousSystemCocircuits(A, B, C) # TODO: not implemented
sage: S.certify_nonexistence() # TODO: not implemented
(++0+)

Functions

homogeneous_from_general(system)

Convert a general system to a homogeneous system.

homogeneous_from_inhomogeneous(system)

Convert an inhomogeneous system to a homogeneous system.

inhomogeneous_from_general(system)

Translate a general system into an inhomogeneous system.

Classes

HomogeneousSystem(A, B, C[, result])

A class for homogeneous linear inequality systems

InhomogeneousSystem(A, B, b, c[, result])

A class for inhomogeneous linear inequality systems

LinearInequalitySystem(matrix[, intervals, ...])

A class for linear inequality systems given by a matrix and intervals

class vectors_in_intervals.linear_inequality_systems.HomogeneousSystem(A: sage.matrix.constructor.matrix, B: sage.matrix.constructor.matrix, C: sage.matrix.constructor.matrix, result: Optional[bool] = None)

A class for homogeneous linear inequality systems

A x > 0, B x >= 0, C x = 0

TESTS:

sage: from vectors_in_intervals import *
sage: A = matrix([[0, 1], [0, 1], [0, 1]])
sage: B = zero_matrix(0, 2)
sage: C = matrix([[1, 1], [0, 0]])
sage: S = HomogeneousSystem(A, B, C)
sage: S.certify_existence()
(1, 1, 1, 0, 0)
candidate_generator(dual: bool = True, reverse: bool = False, random: bool = False) collections.abc.Generator

Return a generator of elementary vectors.

category(self)

File: sage/structure/sage_object.pyx (starting at line 484)

certify(reverse: bool = False) tuple

Return a boolean and a certificate for solvability.

certify_existence(reverse: bool = False, random: bool = False)

Certify existence of a solution if one exists.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_nonexistence(reverse: bool = False, random: bool = False)

Certify nonexistence of solutions.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_parallel(reverse: bool = False, random: bool = False) tuple

Return a boolean and a certificate for solvability.

Attempts to find a solution and certify nonexistence in parallel.

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 string s, which can later be reconstituted as self using loads(s).

There is an optional boolean argument compress which defaults to True.

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
exists_orthogonal_vector(v) bool

Check if an orthogonal vector exists in the intervals.

property intervals: vectors_in_intervals.intervals.Intervals

Return the corresponding intervals.

property matrix: sage.matrix.constructor.matrix

Return the corresponding matrix.

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
solve(reverse: bool = False, random: bool = False)

Compute a solution if existent.

This approach sums up positive elementary vectors in the row space. It doesn’t use division.

Note

If no solution exists, and random is true, this method will never finish.

to_homogeneous() vectors_in_intervals.linear_inequality_systems.HomogeneousSystem

Return the equivalent homogeneous system.

class vectors_in_intervals.linear_inequality_systems.InhomogeneousSystem(A: sage.matrix.constructor.matrix, B: sage.matrix.constructor.matrix, b: sage.modules.free_module_element.vector, c: sage.modules.free_module_element.vector, result: Optional[bool] = None)

A class for inhomogeneous linear inequality systems

A x <= b, B x <= c

candidate_generator(dual: bool = True, reverse: bool = False, random: bool = False) collections.abc.Generator

Return a generator of elementary vectors.

category(self)

File: sage/structure/sage_object.pyx (starting at line 484)

certify(reverse: bool = False) tuple

Return a boolean and a certificate for solvability.

certify_existence(reverse: bool = False, random: bool = False)

Certify existence of a solution if one exists.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_nonexistence(reverse: bool = False, random: bool = False)

Certify nonexistence of solutions.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_parallel(reverse: bool = False, random: bool = False) tuple

Return a boolean and a certificate for solvability.

Attempts to find a solution and certify nonexistence in parallel.

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 string s, which can later be reconstituted as self using loads(s).

There is an optional boolean argument compress which defaults to True.

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
exists_orthogonal_vector(v) bool

Check if an orthogonal vector exists in the intervals.

property intervals: vectors_in_intervals.intervals.Intervals

Return the corresponding intervals.

property matrix: sage.matrix.constructor.matrix

Return the corresponding matrix.

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
solve(reverse: bool = False, random: bool = False)

Compute a solution for this linear inequality system.

If no solution exists, a ValueError is raised.

to_homogeneous() vectors_in_intervals.linear_inequality_systems.HomogeneousSystem

Return the equivalent homogeneous system.

class vectors_in_intervals.linear_inequality_systems.LinearInequalitySystem(matrix: sage.matrix.constructor.matrix, intervals: Optional[vectors_in_intervals.intervals.Intervals] = None, result: Optional[bool] = None)

A class for linear inequality systems given by a matrix and intervals

candidate_generator(dual: bool = True, reverse: bool = False, random: bool = False) collections.abc.Generator

Return a generator of elementary vectors.

category(self)

File: sage/structure/sage_object.pyx (starting at line 484)

certify(reverse: bool = False) tuple

Return a boolean and a certificate for solvability.

certify_existence(reverse: bool = False, random: bool = False)

Certify existence of a solution if one exists.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_nonexistence(reverse: bool = False, random: bool = False)

Certify nonexistence of solutions.

Otherwise, a ValueError is raised.

Note

If a solution exists and random is set to true, this method will never finish.

certify_parallel(reverse: bool = False, random: bool = False) tuple

Return a boolean and a certificate for solvability.

Attempts to find a solution and certify nonexistence in parallel.

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 string s, which can later be reconstituted as self using loads(s).

There is an optional boolean argument compress which defaults to True.

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
exists_orthogonal_vector(v) bool

Check if an orthogonal vector exists in the intervals.

property intervals: vectors_in_intervals.intervals.Intervals

Return the corresponding intervals.

property matrix: sage.matrix.constructor.matrix

Return the corresponding matrix.

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
solve(reverse: bool = False, random: bool = False)

Compute a solution for this linear inequality system.

If no solution exists, a ValueError is raised.

to_homogeneous() vectors_in_intervals.linear_inequality_systems.HomogeneousSystem

Return the equivalent homogeneous system.

vectors_in_intervals.linear_inequality_systems.homogeneous_from_general(system: vectors_in_intervals.linear_inequality_systems.LinearInequalitySystem) vectors_in_intervals.linear_inequality_systems.HomogeneousSystem

Convert a general system to a homogeneous system.

EXAMPLE:

sage: from vectors_in_intervals import *
sage: M = matrix([[1, 0], [0, 1], [1, 1]])
sage: lower_bounds = [2, 5, 0]
sage: upper_bounds = [5, oo, 0]
sage: lower_bounds_closed = [True, True, True]
sage: upper_bounds_closed = [False, False, True]
sage: I = Intervals.from_bounds(lower_bounds, upper_bounds, lower_bounds_closed, upper_bounds_closed)
sage: S = LinearInequalitySystem(M, I)
sage: homogeneous_from_general(S)
[ 1  0 -5]
[ 0  0 -1]
[--------]
[-1  0  2]
[ 0 -1  5]
[--------]
[ 1  1  0] x in [(0, +oo), (0, +oo), [0, +oo), [0, +oo), {0}]
vectors_in_intervals.linear_inequality_systems.homogeneous_from_inhomogeneous(system: vectors_in_intervals.linear_inequality_systems.InhomogeneousSystem) vectors_in_intervals.linear_inequality_systems.HomogeneousSystem

Convert an inhomogeneous system to a homogeneous system.

vectors_in_intervals.linear_inequality_systems.inhomogeneous_from_general(system: vectors_in_intervals.linear_inequality_systems.LinearInequalitySystem) vectors_in_intervals.linear_inequality_systems.InhomogeneousSystem

Translate a general system into an inhomogeneous system.