Opened 2 years ago

Closed 15 months ago

#30334 closed defect (invalid)

MatrixSpace.submodule does not work

Reported by: Matthias Köppe Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: linear algebra Keywords:
Cc: Dima Pasechnik, Travis Scrimshaw, gh-Ivo-Maffei Merged in:
Authors: Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Currently MatrixSpace does not fully implement the category of modules with bases (see (sage.categories.modules_with_basis) that it claims to belong to.

sage: M = MatrixSpace(QQ, 3, 3)
sage: M in ModulesWithBasis(QQ)
True
sage: A = M([[0, 0, 1], [0, 0, 0], [0, 0, 0]])
sage: A
[0 0 1]
[0 0 0]
[0 0 0]
sage: M.submodule([A])
AttributeError: 'MatrixSpace_with_category' object has no attribute 'get_order'

Change History (7)

comment:1 Changed 2 years ago by gh-Ivo-Maffei

I might be wrong, but the issue is not the missing get_order method as the method _compute_support_order assumes that get_order may not exists and simply decide an arbitrary order (it seems order is intended as ordering rather than the order of an element in a group). The only exception not handled is

AttributeError: 'tuple' object has no attribute 'support'

which is caused by sage.categories.finite_dimensional_modules_with_basis.echelon_form because it calls _compute_support_order with the wrong arguments.

I think

  • src/sage/categories/finite_dimensional_modules_with_basis.py

    diff --git a/src/sage/categories/finite_dimensional_modules_with_basis.py b/src/sage/categories/finite_dimensional_modules_with_basis.py
    
    a b class FiniteDimensionalModulesWithBasis(CategoryWithAxiom_over_base_ring): 
    337337                sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]])
    338338                [x[0] - x[2], x[1] - x[2]]
    339339            """
    340340            if order is not None:
    341                 order = self._compute_support_order(order)
     341                order = self._compute_support_order(elements, order)
     342
     343            # order may be an ordering of the support of elements
     344            # hence not an ordering of the whole basis as needed below
     345            # so we extend order to an ordering of the whole basis
     346            orderList = list(order)
     347            for k in self.basis().keys():
     348                if k not in orderList:
     349                    orderList.append(k)
     350
     351            full_order = tuple(orderList)
     352
    342353            from sage.matrix.constructor import matrix
    343             mat = matrix(self.base_ring(), [g._vector_(order=order) for g in elements])
     354            mat = matrix(self.base_ring(), [g._vector_(order=full_order) for g in elements])
    344355            # Echelonizing a matrix over a field returned the rref
    345356            if row_reduced and self.base_ring() not in Fields():
    346357                try:
    347358                    mat = mat.rref().change_ring(self.base_ring())
    348359                except (ValueError, TypeError):
    349360                    raise ValueError("unable to compute the row reduced echelon form")
    350361            else:
    351362                mat.echelonize()
    352             ret = [self.from_vector(vec, order=order) for vec in mat if vec]
     363            ret = [self.from_vector(vec, order=full_order) for vec in mat if vec]

is a needed fix regardless of this ticket.

In addition if we add something silly like

for m in ret:
    try:
        m.__hash__()
    except TypeError:
        m.set_immutable()

then the submodule method returns something (still wrong, though):

sage: MS = MatrixSpace(GF(2),2,2)
sage: A = MS([[1,0],[1,0]])                                                                                                                                                                                                                   
sage: MS.submodule([A])
Free module generated by {0} over Finite Field of size 2
sage: FM = _                                                                                                                                                                                                                                  
sage: FM.gens()                                                                                                                                                                                                                               
(B[0],)
sage: list(FM)
AttributeError: 'SubmoduleWithBasis_with_category' object has no attribute 'list'

comment:2 in reply to:  1 Changed 2 years ago by Matthias Köppe

Replying to gh-Ivo-Maffei:

it seems order is intended as ordering

That's right

comment:3 Changed 2 years ago by Matthias Köppe

Milestone: sage-9.2sage-9.3

comment:4 Changed 20 months ago by Matthias Köppe

Milestone: sage-9.3sage-9.4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

comment:5 Changed 15 months ago by Matthias Köppe

Milestone: sage-9.4sage-duplicate/invalid/wontfix
Status: newneeds_review

dup of #31995

comment:6 Changed 15 months ago by Travis Scrimshaw

Reviewers: Travis Scrimshaw
Status: needs_reviewpositive_review

comment:7 Changed 15 months ago by Matthias Köppe

Resolution: invalid
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.