From e270655ec552abb098a27cb61f3d78ddd2a1886a Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 21 Jun 2021 09:21:14 +1000 Subject: [PATCH] Fixing issue when the support is smaller than the dimension. --- .../finite_dimensional_modules_with_basis.py | 17 ++++++++++++++++- src/sage/matrix/matrix_space.py | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/sage/categories/finite_dimensional_modules_with_basis.py b/src/sage/categories/finite_dimensional_modules_with_basis.py index c4642d2fbb3..9be638117b7 100644 --- a/src/sage/categories/finite_dimensional_modules_with_basis.py +++ b/src/sage/categories/finite_dimensional_modules_with_basis.py @@ -336,6 +336,17 @@ def echelon_form(self, elements, row_reduced=False, order=None): sage: x = C.basis() sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) [x[0] - x[2], x[1] - x[2]] + + :: + + sage: M = MatrixSpace(QQ, 3, 3) + sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) + sage: M.echelon_form([A, A]) + [ + [0 0 1] + [0 0 0] + [0 0 0] + ] """ if order is not None: order = self._compute_support_order(elements, order) @@ -394,7 +405,11 @@ def _vector_(self, order=None): sage: C.an_element()._vector_() (2, 2, 3) """ - dense_free_module = self.parent()._dense_free_module() + if order is None: + dense_free_module = self.parent()._dense_free_module() + else: + from sage.modules.free_module import FreeModule + dense_free_module = FreeModule(self.parent().base_ring(), len(order)) # We slightly break encapsulation for speed reasons return dense_free_module.element_class(dense_free_module, self.dense_coefficient_list(order), diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 3d9cf880460..8029c6a08b1 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -1586,7 +1586,7 @@ def submodule(self, gens, check=True, already_echelonized=False, If ``already_echelonized`` is ``False``, then the generators are put in reduced echelon form using - :meth:`echelonize`, and reindexed by `0,1,...`. + :meth:`echelonize`, and reindexed by `0, 1, \ldots`. .. WARNING:: @@ -1601,7 +1601,6 @@ def submodule(self, gens, check=True, already_echelonized=False, The basis of the submodule uses the same index set as the generators, and the lifting map sends `y_i` to `gens[i]`. - .. SEEALSO:: :meth:`ModulesWithBasis.ParentMethods.submodule` @@ -1620,6 +1619,21 @@ def submodule(self, gens, check=True, already_echelonized=False, [ 1 0] [0 1] [-3 2], [3 1] ] + + sage: A = matrix([[1, 1], [0, -1]]) + sage: B = matrix([[0, 1], [0, 2]]) + sage: X = M.submodule([A, B]) + sage: Xp = M.submodule([A, B], order=[(0,1), (1,1), (0,0)]) + sage: [X.lift(b) for b in Xp.basis()] + [ + [ 1 0] [0 1] + [ 0 -3], [0 2] + ] + sage: [Xp.lift(b) for b in X.basis()] + [ + [2/3 1] [-1/3 0] + [ 0 0], [ 0 1] + ] """ support_order = self._compute_support_order(gens, support_order) if not already_echelonized: