Skip to content

User bases in direct sums #34285

Open
Open
@sagrawalx

Description

It is possible to specify custom bases for free modules in Sage with functions such as submodule_with_basis or span_of_basis. For example,

V = (QQ^3).span_of_basis([[1,2,0], [0,1,0]]); V

outputs the following:

Vector space of degree 3 and dimension 2 over Rational Field
User basis matrix:
[1 2 0]
[0 1 0]

However, this custom basis is lost when the vector space is direct summed with another. For example, running

V.direct_sum(QQ^2)

results in the following, where the custom basis of V has been forgotten and only the echelonized basis is remembered:

Vector space of degree 5 and dimension 4 over Rational Field
Basis matrix:
[1 0 0 0 0]
[0 1 0 0 0]
[0 0 0 1 0]
[0 0 0 0 1]

I propose some minor edits to the direct_sum method so that the output is instead as follows:

Vector space of degree 5 and dimension 4 over Rational Field
User basis matrix:
[1 2 0 0 0]
[0 1 0 0 0]
[0 0 0 1 0]
[0 0 0 0 1]

This is accomplished by the following redefinition of direct_sum:

def direct_sum(self, other):
    if not is_FreeModule(other):
        raise TypeError("other must be a free module")
    if other.base_ring() != self.base_ring():
        raise TypeError("base rings of self and other must be the same")
    M = FreeModule(self.base_ring(), self.degree() + other.degree())
    A = self.basis_matrix().block_sum(other.basis_matrix())
    if self.has_user_basis() or other.has_user_basis():
        return M.span_of_basis(A)
    else:
        return M.span(A)

Component: linear algebra

Author: Shishir Agrawal

Branch/Commit: u/gh-sagrawalx/direct-sum-user-basis @ 10c005b

Issue created by migration from https://trac.sagemath.org/ticket/34285

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions