From 0afa01cfcb1ad3ded5cde7ba2df3dc3231c6a3f8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 21 Jul 2020 10:30:40 -0700 Subject: [PATCH] Modules: Add parent method module_morphism --- src/sage/categories/modules.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/sage/categories/modules.py b/src/sage/categories/modules.py index 9940314265d..11e8b11813e 100644 --- a/src/sage/categories/modules.py +++ b/src/sage/categories/modules.py @@ -15,7 +15,9 @@ from sage.misc.cachefunc import cached_method from sage.misc.lazy_import import LazyImport from sage.categories.category_with_axiom import CategoryWithAxiom_over_base_ring +from sage.categories.morphism import SetMorphism from sage.categories.homsets import HomsetsCategory +from sage.categories.homset import Hom from .category import Category from .category_types import Category_module from sage.categories.tensor import TensorProductsCategory, tensor @@ -538,6 +540,37 @@ def tensor_square(self): """ return tensor([self, self]) + def module_morphism(self, *, function, category=None, codomain, **keywords): + r""" + Construct a module morphism from ``self`` to ``codomain``. + + Let ``self`` be a module `X` over a ring `R`. + This constructs a morphism `f: X \to Y`. + + INPUT: + + - ``self`` -- a parent `X` in ``Modules(R)``. + + - ``function`` -- a function `f` from `X` to `Y` + + - ``codomain`` -- the codomain `Y` of the morphism (default: + ``f.codomain()`` if it's defined; otherwise it must be specified) + + - ``category`` -- a category or ``None`` (default: ``None``) + + EXAMPLES:: + + sage: V = FiniteRankFreeModule(QQ, 2) + sage: e = V.basis('e'); e + Basis (e_0,e_1) on the 2-dimensional vector space over the Rational Field + sage: neg = V.module_morphism(function=operator.neg, codomain=V); neg + Generic endomorphism of 2-dimensional vector space over the Rational Field + sage: neg(e[0]) + Element -e_0 of the 2-dimensional vector space over the Rational Field + + """ + return SetMorphism(Hom(self, codomain, category), function) + class ElementMethods: pass