Skip to content

Arithmetic on tensor module elements, manifold objects: Always Return a Copy #30302

@mjungmath

Description

@mjungmath

This question arose from ticket #30239, comment:36.

Should FiniteRankFreeModule and manifold objects always return a mutable copy, even for trivial operations? At least, this would be a consistent behavior.

As pointed out by Matthias, this already holds true for FreeModule:

sage: M = FreeModule(QQ, 3)
sage: v = M([1,2,3])
sage: w = v + 0
sage: w == v
True
sage: w is v
False

I feel quite torn about this, but slightly tend to the copy-version.

Addendum:

For FreeModule, we also have the following behavior:

sage: M = FreeModule(QQ, 3)
sage: M(0)
(0, 0, 0)
sage: M.zero()
(0, 0, 0)
sage: M.zero() is M(0)
False

I don't think that a parent should do that, especially when it already has a zero method. Should that be changed?

CC: @egourgoulhon @tscrim @mkoeppe

Component: misc

Branch/Commit: u/gh-mjungmath/return_copy_always_scalarfields @ b7b0b3f

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

Metadata

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