sign_vectors.utility¶
Utility functions and other useful functions for working with oriented matroids
Functions
|
Return whether two sign vectors are adjacent over given sign vectors. |
|
Determine whether two components of sign vectors or vectors are parallel. |
|
Compute the classes with same support of given sign vectors. |
|
Compute the parallel classes of given sign vectors or vectors. |
|
Compute the positive parallel classes of given sign vectors or vectors. |
- sign_vectors.utility.adjacent(element1: sign_vectors.sign_vectors.SignVector, element2: sign_vectors.sign_vectors.SignVector, iterable) bool ¶
Return whether two sign vectors are adjacent over given sign vectors.
INPUT:
element1
– a sign vectorelement2
– a sign vectoriterable
– an iterable of sign vectors
OUTPUT: a boolean
Note
define adjacent here TODO
EXAMPLES:
We consider the following cocircuits:
sage: from sign_vectors import * sage: cocircuits = {sign_vector("0+-"), sign_vector("--0"), sign_vector("0-+"), sign_vector("++0"), sign_vector("+0+"), sign_vector("-0-")}
The two sign vectors
X = (++0)
andY = (+0+)
are harmonious:sage: X = sign_vector('++0') sage: X (++0) sage: Y = sign_vector('+0+') sage: Y (+0+) sage: X.is_harmonious_to(Y) True
Furthermore, the only cocircuits lying under the composition of \(X\) and \(Y\), that is, cocircuits \(Z\) satisfying \(Z < (+++) = X \circ Y\), are \(X\) and \(Y\). Hence, those two sign vectors are adjacent:
sage: from sign_vectors.utility import adjacent sage: adjacent(X, Y, cocircuits) True
Conversely, \(Y = (+0+)\) and \(Z = (0+-)\) are not adjacent since \((++0) < (++-) = Y \circ Z\):
sage: Z = sign_vector('0+-') sage: Z (0+-) sage: adjacent(Y, Z, cocircuits) False
- sign_vectors.utility.are_parallel(iterable, component1, component2, return_ratio: bool = False)¶
Determine whether two components of sign vectors or vectors are parallel.
INPUT:
iterable
– a list of sign vectors or vectors of lengthn
component1
– an integer with0 <= component1 < n
component2
– an integer with0 <= component2 < n
return_ratio
– a boolean
OUTPUT:
Returns a boolean. If
return_ratio
is true, a tuple of a boolean and the ratio will be returned instead.Note
The elements
component1
andcomponent2
are parallel if there exists a ratiod
such thatv[component1] = d v[component2]
for eachv
initerable
.EXAMPLES:
sage: from sign_vectors.utility import are_parallel sage: from sign_vectors import sign_vector sage: L = [sign_vector("++0-"), sign_vector("+-0+"), sign_vector("-0+0")] sage: L [(++0-), (+-0+), (-0+0)] sage: are_parallel(L, 0, 1) False sage: are_parallel(L, 1, 2) False sage: are_parallel(L, 1, 3) True
Now, we consider some real vectors:
sage: L = [vector([1, 1, 2, 3, 0, 0]), vector([-2, 1, -4, 3, 3, -17]), vector([0, 1, 0, 1, 0, 0])] sage: L [(1, 1, 2, 3, 0, 0), (-2, 1, -4, 3, 3, -17), (0, 1, 0, 1, 0, 0)] sage: are_parallel(L, 0, 2) True sage: are_parallel(L, 0, 1) False sage: are_parallel(L, 1, 3) False sage: are_parallel(L, 4, 5) True
We can also return the ratio of the two components:
sage: are_parallel(L, 0, 2, return_ratio=True) (True, 1/2) sage: are_parallel(L, 2, 0, return_ratio=True) (True, 2) sage: are_parallel(L, 0, 1, return_ratio=True) (False, None)
Also works for matrices:
sage: M = matrix([[0, 0, 1, -1, 0], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]) sage: are_parallel(M, 0, 4) True sage: are_parallel(M, 0, 1) False
TESTS:
sage: are_parallel([], 0, 1) True sage: are_parallel([], 0, 1, return_ratio=True) (True, 0)
- sign_vectors.utility.classes_same_support(iterable) Iterator[set[sign_vectors.sign_vectors.SignVector]] ¶
Compute the classes with same support of given sign vectors.
INPUT:
iterable
– an iterable of sign vectors
OUTPUT: A generator yielding sets of sign vectors with the same support.
EXAMPLES:
sage: from sign_vectors.utility import classes_same_support sage: from sign_vectors import sign_vector sage: L = [sign_vector("++0-"), sign_vector("+-0+"), sign_vector("-0+0")] sage: list(classes_same_support(L)) [{(++0-), (+-0+)}, {(-0+0)}]
- sign_vectors.utility.parallel_classes(iterable, length: int) list[set[int]] ¶
Compute the parallel classes of given sign vectors or vectors.
INPUT:
iterable
– an iterable of sign vectors or vectors with same lengthlength
– an integern
OUTPUT:
Returns a partition of
[0, ..., n - 1]
into parallel classes.Note
The elements
component1
andcomponent2
are parallel if there exists a ratiod
such thatX[component1] = d X[component2]
for eachX
initerable
.EXAMPLES:
sage: from sign_vectors.utility import parallel_classes sage: from sign_vectors import sign_vector sage: L = [sign_vector("++0-"), sign_vector("+-0+"), sign_vector("-0+0")] sage: L [(++0-), (+-0+), (-0+0)] sage: parallel_classes(L, 4) [{0}, {1, 3}, {2}]
Now, we compute the parallel classes of a list of real vectors:
sage: L = [vector([1, 1, 2, 3, 0, 0]), vector([-2, 1, -4, 3, 3, -17]), vector([0, 1, 0, 1, 0, 0])] sage: L [(1, 1, 2, 3, 0, 0), (-2, 1, -4, 3, 3, -17), (0, 1, 0, 1, 0, 0)] sage: parallel_classes(L, 6) [{0, 2}, {1}, {3}, {4, 5}]
Let us compute the parallel classes of the rows of a matrix:
sage: M = matrix([[0, 0, 1, -2, 0], [1, 0, 0, 0, 1], [1, 1, -3, 6, 1]]) sage: M [ 0 0 1 -2 0] [ 1 0 0 0 1] [ 1 1 -3 6 1] sage: parallel_classes(M, 5) [{0, 4}, {1}, {2, 3}]
TESTS:
sage: parallel_classes([], 5) [{0, 1, 2, 3, 4}]
- sign_vectors.utility.positive_parallel_classes(iterable, length: int) list[set[int]] ¶
Compute the positive parallel classes of given sign vectors or vectors.
See also
EXAMPLES:
sage: from sign_vectors.utility import positive_parallel_classes sage: from sign_vectors import sign_vector sage: L = [sign_vector("++0-"), sign_vector("--0+"), sign_vector("00+0")] sage: L [(++0-), (--0+), (00+0)] sage: positive_parallel_classes(L, 4) [{0, 1}, {2}, {3}]
Now, we compute the positive parallel classes of a list of real vectors:
sage: L = [vector([1, 1, 2, 3, 0, 0]), vector([-2, 1, -4, 3, 3, -17]), vector([0, 1, 0, 1, 0, 0])] sage: L [(1, 1, 2, 3, 0, 0), (-2, 1, -4, 3, 3, -17), (0, 1, 0, 1, 0, 0)] sage: positive_parallel_classes(L, 6) [{0, 2}, {1}, {3}, {4}, {5}]
Let us compute the positive parallel classes of the rows of a matrix:
sage: M = matrix([[0, 0, 1, -2, 0], [1, 0, 0, 0, 1], [1, 1, -3, 6, 1]]) sage: M [ 0 0 1 -2 0] [ 1 0 0 0 1] [ 1 1 -3 6 1] sage: positive_parallel_classes(M, 5) [{0, 4}, {1}, {2}, {3}]
TESTS:
sage: positive_parallel_classes([], 5) [{0, 1, 2, 3, 4}]