elementary_vectors.reductions

Reducing and simplifying lists of vectors

Functions

reduce_factor(iterable)

Cancel a common factor of each entry.

reduce_vector(element[, equalities, ...])

Reduce this vector by canceling common factors and applying equalities to variables.

reduce_vector_using_equalities(iterable, ...)

Use a list of equalities equalities to simplify expressions in a vector iterable.

reduce_vectors(vectors[, equalities, ...])

Reduces this list of vectors.

reduce_vectors_support(vectors[, generator])

Return a ist of vectors where each element has distinct support.

remove_zero_vectors(vectors)

Remove all zero vectors from this list.

simplify_using_equalities(value, equalities)

Simplifies an expression using a list of equalities.

elementary_vectors.reductions.reduce_factor(iterable)

Cancel a common factor of each entry.

INPUT:

  • iterable – a vector or a list

EXAMPLES:

sage: from elementary_vectors.reductions import reduce_factor
sage: var('a')
a
sage: v = vector([5*a, 10*a])
sage: reduce_factor(v)
(1, 2)
sage: w = vector([4, 6])
sage: reduce_factor(w)
(2, 3)

When we cancel a common factor, we expect to have an integer vector again:

sage: type(reduce_factor(w))
<class 'sage.modules.vector_integer_dense.Vector_integer_dense'>

We can also cancel common factors from lists:

sage: reduce_factor([4, 6])
[2, 3]
sage: reduce_factor([-4, -6])
[-2, -3]

The function also cancels denominators:

sage: v = vector([1/10, 0, 1/3, 1/4])
sage: v
(1/10, 0, 1/3, 1/4)
sage: reduce_factor(v)
(6, 0, 20, 15)

TESTS:

sage: from elementary_vectors.reductions import reduce_factor
sage: v = vector([2, 4])
sage: w = reduce_factor(v)
sage: w
(1, 2)
sage: w.base_ring()
Integer Ring
sage: v = [2, 4]
sage: w = reduce_factor(v)
sage: w
[1, 2]
sage: w[0].base_ring()
Integer Ring
elementary_vectors.reductions.reduce_vector(element, equalities: Optional[list] = None, cancel_factor: bool = True)

Reduce this vector by canceling common factors and applying equalities to variables.

INPUT:

  • element – a vector

  • equalities – a list of equalities (default: None)

  • cancel_factor – a boolean (default: True). If true, cancels a common factor.

EXAMPLES:

sage: from elementary_vectors.reductions import reduce_vector
sage: var('a')
a
sage: assume(a == 0)
sage: v = vector([5*a, 10*a])
sage: reduce_vector(v, equalities=assumptions())
(0, 0)
sage: reduce_vector(v)
(1, 2)
sage: reduce_vector(v, equalities=[a == 0], cancel_factor=False)
(0, 0)
sage: reduce_vector(v, cancel_factor=False)
(5*a, 10*a)
elementary_vectors.reductions.reduce_vector_using_equalities(iterable, equalities: list)

Use a list of equalities equalities to simplify expressions in a vector iterable.

elementary_vectors.reductions.reduce_vectors(vectors, equalities: Optional[list] = None, cancel_factors: bool = False, reduce_support: bool = True, remove_zeros: bool = True) list

Reduces this list of vectors.

INPUT:

  • vectors – a list of vectors

  • equalities – a list of equalities (default: None)

  • cancel_factors – a boolean (default: False). If true, cancels common factors of each vector.

  • reduce_support – a boolean (default: True). Keeps only the first vector for each different support.

  • remove_zeros – a boolean (default: True). If true, removes all zero vectors.

EXAMPLES:

sage: from elementary_vectors.reductions import reduce_vectors
sage: var('a')
a
sage: assume(a == 0)
sage: l = [vector([5*a, 10*a, 0]), vector([5*a, 2*a, a]), vector([4, 6, 0])]
sage: reduce_vectors(l, equalities=assumptions(), cancel_factors=True)
[(2, 3, 0)]
sage: reduce_vectors(l, cancel_factors=True)
[(1, 2, 0), (5, 2, 1)]
sage: reduce_vectors(l, equalities=[a == 0], cancel_factors=False)
[(4, 6, 0)]
sage: reduce_vectors(l, equalities=assumptions(), reduce_support=True, cancel_factors=True)
[(2, 3, 0)]
sage: reduce_vectors(l, equalities=assumptions(), reduce_support=False, remove_zeros=False, cancel_factors=True)
[(0, 0, 0), (0, 0, 0), (2, 3, 0)]
elementary_vectors.reductions.reduce_vectors_support(vectors, generator: bool = False)

Return a ist of vectors where each element has distinct support.

INPUT:

  • vectors – an iterable of vectors

  • generator – an optional boolean

OUTPUT:

Only the first element with a specific support is kept. Return a generator if generator is true.

EXAMPLES:

sage: from elementary_vectors.reductions import reduce_vectors_support
sage: l = [vector([1, 3, 2]), vector([0, 0, 1]), vector([2, 2, 0]), vector([0, 0, -5])]
sage: reduce_vectors_support(l)
[(1, 3, 2), (0, 0, 1), (2, 2, 0)]
sage: reduce_vectors_support([zero_vector(5)])
[(0, 0, 0, 0, 0)]
elementary_vectors.reductions.remove_zero_vectors(vectors) list

Remove all zero vectors from this list.

EXAMPLES:

sage: from elementary_vectors.reductions import remove_zero_vectors
sage: var('a')
a
sage: remove_zero_vectors([vector([5, 2, 3]), zero_vector(3), vector([a*0, 0, 0])])
[(5, 2, 3)]
elementary_vectors.reductions.simplify_using_equalities(value, equalities: list)

Simplifies an expression using a list of equalities.

Note

Only equalities are considered. Other expressions (e.g. inequalities) are ignored.

EXAMPLES:

sage: from elementary_vectors.reductions import simplify_using_equalities
sage: var('a')
a
sage: expr = a + 1
sage: simplify_using_equalities(expr, [a == 0])
1
sage: simplify_using_equalities(expr, [])
a + 1

Now, we consider a polynomial expression:

sage: R = PolynomialRing(ZZ, 'x')
sage: x = R.gen()
sage: assume(SR(x) == 0)
sage: simplify_using_equalities(x + 1, assumptions())
1