sign_vectors.utility

Utility functions and other useful functions for working with oriented matroids

Functions

adjacent(element1, element2, iterable)

Return whether two sign vectors are adjacent over given sign vectors.

classes_same_support(iterable)

Compute the classes with same support of given sign vectors or vectors.

exclude_indices(vectors, indices)

Return a function that returns a sign vector or vector with entries not in given indices.

is_parallel(iterable, component1, component2)

Determine whether two components of sign vectors or vectors are parallel.

loops(iterable)

Compute the loops of sign vectors or vectors.

parallel_classes(iterable[, positive_only])

Compute the parallel classes of given sign vectors or vectors.

positive_parallel_classes(iterable)

Compute the positive parallel classes of given sign vectors or vectors.

sign_vectors.utility.adjacent(element1, element2, iterable) bool

Return whether two sign vectors are adjacent over given sign vectors.

INPUT:

  • element1 – a sign vector

  • element2 – a sign vector

  • iterable – an iterable of sign vectors

OUTPUT: a boolean

Note

define adjacent here TODO

EXAMPLES:

We consider the following matrix:

sage: M = matrix([[1, 2, 0], [0, 1, -1]])
sage: M
[ 1  2  0]
[ 0  1 -1]

By using the function sign_vectors.oriented_matroids.cocircuits_from_matrix(), we can compute the corresponding cocircuits:

sage: from sign_vectors.oriented_matroids import *
sage: cc = cocircuits_from_matrix(M, kernel=False)
sage: cc
{(0-+), (+0+), (--0), (-0-), (0+-), (++0)}

The two sign vectors X = (++0) and Y = (+0+) are harmonious:

sage: X = sign_vector('++0')
sage: X
(++0)
sage: Y = sign_vector('+0+')
sage: Y
(+0+)
sage: X.is_harmonious(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, cc)
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, cc)
False
sign_vectors.utility.classes_same_support(iterable) list

Compute the classes with same support of given sign vectors or vectors.

INPUT:

  • iterable – an iterable of sign vectors or vectors with same length

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: L
[(++0-), (+-0+), (-0+0)]
sage: classes_same_support(L)
[[(++0-), (+-0+)], [(-0+0)]]
sage: classes_same_support([vector([1, 1, 0, 0]), vector([2, -3, 0, 0]), vector([0, 1, 0, 0])])
[[(1, 1, 0, 0), (2, -3, 0, 0)], [(0, 1, 0, 0)]]
sign_vectors.utility.exclude_indices(vectors, indices: list[int])

Return a function that returns a sign vector or vector with entries not in given indices.

INPUT:

  • vectors – a list of sign vectors or vectors

  • indices – a list of indices

EXAMPLES:

sage: from sign_vectors.utility import exclude_indices
sage: from sign_vectors import sign_vector
sage: W = [sign_vector("++0"), sign_vector("-00"), sign_vector("00+")]
sage: W
[(++0), (-00), (00+)]
sage: f = exclude_indices(W, [1])
sage: f(sign_vector("-+0"))
(-0)
sage: l = [vector([0, 0, 1]), vector([0, 2, 1]), vector([-1, 0, 1])]
sage: f = exclude_indices(l, [1])
sage: f(vector([1, 2, 3]))
(1, 3)
sign_vectors.utility.is_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 length n

  • component1 – an integer with 0 <= component1 < n

  • component2 – an integer with 0  <= component2 < n

  • return_ratio – a boolean

OUTPUT:

Returns a boolean. If return_ratio is true, a boolean and the ratio will be returned instead.

Note

The elements component1 and component2 are parallel if there exists a ratio d such that v[component1] = d v[component2] for each v in iterable.

EXAMPLES:

sage: from sign_vectors.utility import is_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: is_parallel(L, 0, 1)
False
sage: is_parallel(L, 1, 2)
False
sage: is_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: is_parallel(L, 0, 2)
True
sage: is_parallel(L, 0, 1)
False
sage: is_parallel(L, 1, 3)
False
sage: is_parallel(L, 4, 5)
True

We can also return the ratio of the two components:

sage: is_parallel(L, 0, 2, return_ratio=True)
(True, 1/2)
sage: is_parallel(L, 2, 0, return_ratio=True)
(True, 2)
sage: is_parallel(L, 0, 1, return_ratio=True)
(False, 0)

Also works for matrices:

sage: M = matrix([[0, 0, 1, -1, 0], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]])
sage: is_parallel(M, 0, 4)
True
sage: is_parallel(M, 0, 1)
False
sign_vectors.utility.loops(iterable) list[int]

Compute the loops of sign vectors or vectors.

Note

A loop is a component where every element is zero.

EXAMPLES:

sage: from sign_vectors.utility import loops
sage: from sign_vectors import sign_vector
sage: loops([sign_vector([0, 1, 0]), sign_vector([-1, 0, 0])])
[2]
sage: loops([sign_vector([1, 0, 0]), sign_vector([-1, 0, 0])])
[1, 2]

Also works for real vectors:

sage: loops([vector([5, 0, 0, 0]), vector([2, 0, -3, 0])])
[1, 3]
sign_vectors.utility.parallel_classes(iterable, positive_only: bool = False) list[list[int]]

Compute the parallel classes of given sign vectors or vectors.

INPUT:

  • iterable – an iterable of sign vectors or vectors with same length

  • positive_only – a boolean (default: False)

OUTPUT:

Returns a partition of [0, ..., n - 1] into parallel classes.

If positive_only is true, returns a partition of [0, ..., n - 1] into positive parallel classes, that is, the ratios of the corresponding classes are nonnegative.

Note

The elements component1 and component2 are parallel if there exists a ratio d such that v[component1] = d v[component2] for each v in iterable.

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)
[[0], [1, 3], [2]]
sage: parallel_classes(L, positive_only=True)
[[0], [1], [2], [3]]

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)
[[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)
[[0, 4], [1], [2, 3]]
sage: parallel_classes(M, positive_only=True)
[[0, 4], [1], [2], [3]]
sign_vectors.utility.positive_parallel_classes(iterable) list[list[int]]

Compute the positive parallel classes of given sign vectors or vectors.

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)
[[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)
[[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)
[[0, 4], [1], [2], [3]]