sign_crn.utility¶
Utility functions
Functions
|
Return whether all component products with nonzero first component are positive (or negative). |
|
Return a list of lists such that the corresponding kernel matrix has equal entries. |
|
Generate all sign vectors that correspond to a vector with components in given intervals. |
Compute all nonnegative circuits. |
|
Compute nonnegative cocircuits. |
|
Compute all nonnegative covectors from a set of cocircuits. |
|
Compute all nonnegative covectors. |
|
|
Compute all nonnegative covectors from a matrix. |
|
Remove duplicates from a list of iterables. |
|
Return the sign of an expression if defined. |
Return intervals that correspond to a sign vector. |
|
|
Find a vector in the row space of a matrix that has given signs. |
- sign_crn.utility.closure_minors_utility(pairs, positive_only: bool = False, negative_only: bool = False) list¶
Return whether all component products with nonzero first component are positive (or negative).
INPUT:
pairs– an iterable of pairs consisting of a minor and a productpositive_only– a boolean, considers only positive products if truenegative_only– a boolean, considers only negative products if true
OUTPUT: Returns either a boolean or sets of conditions on variables occurring in the input. If the conditions of one of these sets are satisfied, then for all nonzero elements of the first list, the product with the corresponding element of the second list is positive. (Or all products are negative.)
TESTS:
sage: from sign_crn.utility import closure_minors_utility sage: var("a, b, c") (a, b, c) sage: closure_minors_utility(zip([0, a], [0, a]), positive_only=True) [{a == 0}, {a > 0}] sage: len(_) 2 sage: closure_minors_utility(zip([c, -1, c], [c, -b, -a * c])) # random [{-b > 0, c == 0}, {-b < 0, c == 0}, {-b > 0, c > 0, -a*c > 0}, {-b < 0, c < 0, -a*c < 0}] sage: len(_) 4 sage: closure_minors_utility(zip([c, -1, a], [c, -b, -a * c])) # random [{-b > 0, a == 0, c == 0}, {-b < 0, a == 0, c == 0}, {-b > 0, a == 0, c > 0}, {-b < 0, a == 0, c < 0}, {-b > 0, a != 0, c > 0, -a*c > 0}, {-b < 0, a != 0, c < 0, -a*c < 0}, {-a*c > 0, c > 0, -b > 0}, {-a*c < 0, c < 0, -b < 0}]] sage: len(_) 8
sage: closure_minors_utility(zip([-1, -1], [-1, -1])) True sage: closure_minors_utility(zip([-1, 1], [-1, 1])) False sage: closure_minors_utility(zip([0, 1], [0, 1])) True sage: closure_minors_utility([(1, 0)]) False
- sign_crn.utility.equal_entries_lists(length: int, indices: list[int]) list[list[int]]¶
Return a list of lists such that the corresponding kernel matrix has equal entries.
EXAMPLES:
sage: from sign_crn.utility import equal_entries_lists sage: equal_entries_lists(5, [1, 2, 3]) [[0, 1, -1, 0, 0], [0, 1, 0, -1, 0]] sage: equal_entries_lists(3, [0]) [] sage: equal_entries_lists(3, [0, 1]) [[1, -1, 0]]
- sign_crn.utility.intervals_to_sign_vectors(intervals: Intervals) Iterator[SignVector]¶
Generate all sign vectors that correspond to a vector with components in given intervals.
INPUT:
intervals– an Intervals object
EXAMPLES:
sage: from certlin import * sage: from sign_crn.utility import intervals_to_sign_vectors sage: intervals = Intervals.from_bounds([-1, 1], [0, 1]) sage: list(intervals_to_sign_vectors(intervals)) [(0+), (-+)] sage: intervals = Intervals.from_bounds([-1, -2], [0, 1]) sage: list(intervals_to_sign_vectors(intervals)) [(00), (0+), (0-), (-0), (-+), (--)] sage: intervals = Intervals.from_bounds([-1, -1, 0], [0, 5, 0]) sage: list(intervals_to_sign_vectors(intervals)) [(000), (0+0), (0-0), (-00), (-+0), (--0)] sage: intervals = Intervals.from_bounds([-1, -1, -1], [0, 1, 0], False, False) sage: list(intervals_to_sign_vectors(intervals)) [(-0-), (-+-), (---)]
TESTS:
sage: intervals = Intervals.from_bounds([-1, 0], [1, 0], False, False) sage: list(intervals_to_sign_vectors(intervals)) [] sage: intervals = Intervals.from_bounds([], []) sage: list(intervals_to_sign_vectors(intervals)) []
- sign_crn.utility.non_negative_circuits_from_matrix(matrix: matrix) set[SignVector]¶
Compute all nonnegative circuits.
OUTPUT:
Return a set of nonnegative circuits determined by the kernel of
matrix.EXAMPLES:
sage: from sign_vectors import * sage: from sign_crn.utility import non_negative_circuits_from_matrix sage: M = matrix([[2, -1, -1, 0]]) sage: OrientedMatroid(M).circuits() {(0+-0), (--00), (000+), (++00), (0-+0), (+0+0), (-0-0), (000-)} sage: non_negative_circuits_from_matrix(M) {(+0+0), (000+), (++00)}
- sign_crn.utility.non_negative_cocircuits_from_matrix(matrix: matrix) set[SignVector]¶
Compute nonnegative cocircuits.
OUTPUT:
Return a set of nonnegative cocircuits determined by the kernel of
matrix.EXAMPLES:
sage: from sign_vectors import * sage: from sign_crn.utility import non_negative_cocircuits_from_matrix sage: M = matrix([[1, 0, 2, 0], [0, 1, -1, 0], [0, 0, 0, 1]]) sage: OrientedMatroid(M).cocircuits() {(0+-0), (--00), (0-+0), (000+), (++00), (+0+0), (-0-0), (000-)} sage: non_negative_cocircuits_from_matrix(M) {(+0+0), (000+), (++00)}
- sign_crn.utility.non_negative_covectors_from_cocircuits(cocircuits: set[SignVector], length: int) set[SignVector]¶
Compute all nonnegative covectors from a set of cocircuits.
- sign_crn.utility.non_negative_covectors_from_matrix(matrix: matrix) set[SignVector]¶
Compute all nonnegative covectors.
OUTPUT:
Return a set of nonnegative covectors determined by the kernel of
matrix.EXAMPLES:
sage: from sign_vectors.oriented_matroids import OrientedMatroid sage: from sign_crn.utility import non_negative_covectors_from_matrix sage: M = matrix([[1, 0, 2, 0], [0, 1, -1, 0], [0, 0, 0, 1]]) sage: OrientedMatroid(M).covectors() {(0000), (++-0), (--+0), (000+), (--0+), (+-+-), (-0-0), (+-++), (000-), (-+-0), (--0-), (0-+0), (++00), (--++), (+0+0), (++--), (--00), (--+-), (-0-+), (++-+), (---0), (0+-0), (-+-+), (-0--), (+++0), (-+--), (0-++), (+-+0), (0-+-), (++0-), (++0+), (---+), (+0+-), (0+-+), (+0++), (++++), (----), (0+--), (+++-)} sage: non_negative_covectors_from_matrix(M) {(0000), (++00), (++0+), (+0+0), (+++0), (000+), (+0++), (++++)}
- sign_crn.utility.non_negative_vectors_from_matrix(matrix: matrix) set[SignVector]¶
Compute all nonnegative covectors from a matrix.
OUTPUT:
Return a set of nonnegative covectors determined by the kernel of
matrix.EXAMPLES:
sage: from sign_vectors.oriented_matroids import OrientedMatroid sage: from sign_crn.utility import non_negative_vectors_from_matrix sage: M = matrix([[2, -1, -1, 0]]) sage: OrientedMatroid(M).vectors() {(0000), (++-0), (--+0), (000+), (--0+), (+-+-), (-0-0), (+-++), (000-), (-+-0), (--0-), (0-+0), (++00), (--++), (+0+0), (++--), (--00), (--+-), (-0-+), (++-+), (---0), (0+-0), (-+-+), (-0--), (+++0), (-+--), (0-++), (+-+0), (0-+-), (++0-), (++0+), (0+-+), (---+), (+0+-), (+0++), (++++), (----), (0+--), (+++-)} sage: non_negative_vectors_from_matrix(M) {(0000), (++00), (++0+), (+0+0), (+++0), (000+), (+0++), (++++)}
- sign_crn.utility.remove_duplicates(iterable)¶
Remove duplicates from a list of iterables.
- sign_crn.utility.sign_or_symbolic(expression)¶
Return the sign of an expression if defined.
- sign_crn.utility.sign_vector_to_intervals(sv: SignVector) Intervals¶
Return intervals that correspond to a sign vector.
EXAMPLES:
sage: from sign_vectors import * sage: from sign_crn.utility import sign_vector_to_intervals sage: sv = sign_vector("+0-") sage: sign_vector_to_intervals(sv) (0, +oo) x {0} x (-oo, 0)
- sign_crn.utility.vector_from_sign_vector(data, sv: SignVector) vector¶
Find a vector in the row space of a matrix that has given signs.
INPUT:
data– either a real matrix withncolumns or a list of circuits of lengthnsv– a sign vector of lengthn
OUTPUT: Return a conformal sum of circuits that lies in the given subspace.
If
datais a matrix, the circuits of this matrix are used for the result. Ifdatais a list of circuits, those are used.Note
A
ValueErroris raised if no solution exists.EXAMPLES:
sage: from sign_crn.utility import vector_from_sign_vector sage: from elementary_vectors import * sage: from sign_vectors import * sage: M = matrix([[1, 0, 2, 0], [0, 1, 1, 0], [0, 0, 0, 1]]) sage: vector_from_sign_vector(M, zero_sign_vector(4)) (0, 0, 0, 0) sage: vector_from_sign_vector(M, sign_vector("+-+0")) (2, -2, 2, 0) sage: vector_from_sign_vector(M, sign_vector("+0+0")) (1, 0, 2, 0) sage: vector_from_sign_vector(M, sign_vector("+-0+")) (1, -2, 0, 1) sage: vector_from_sign_vector(cocircuits(M), sign_vector("+-0+")) (1, -2, 0, 1) sage: vector_from_sign_vector(M, sign_vector("+0-0")) Traceback (most recent call last): ... ValueError: Cannot find vector corresponding to given sign vector. sage: vector_from_sign_vector([], zero_sign_vector(4)) (0, 0, 0, 0)