Ticket #9648: trac_9648_modulemorphism_codomain_extension.patch

File trac_9648_modulemorphism_codomain_extension.patch, 3.8 KB (added by stumpc5, 11 years ago)
  • sage/categories/modules_with_basis.py

    # HG changeset patch
    # User Christian Stump <christian.stump@univie.ac.at>
    # Date 1280514062 14400
    # Node ID 76441d22e8cb279d306245aea44fd972783aa9a4
    # Parent  cb1ad1ee5bd452850fde04d47f9618dec4c3e997
    Trac 9648: extension of the codomain of module morphisms
    
    diff -r cb1ad1ee5bd4 -r 76441d22e8cb sage/categories/modules_with_basis.py
    a b  
    44AUTHORS:
    55- Nicolas Thiery (2008): initial revision
    66- Jason Bandlow & Florent Hivert (2010): Triangular Morphisms
     7- Christian Stump (2010): minor changes in ModuleMorphismByLinearity.__init__, .__call__ and updated examples in ModulesWithBasis.ParentMethods.module_morphism
    78
    89"""
    910#*****************************************************************************
     
    227228                sage: phi(x[1] + x[3])
    228229                B[1] + 2*B[2] + B[3] + 2*B[4]
    229230
     231                sage: X = CombinatorialFreeModule(QQ,[1,-1])
     232                sage: phi = X.module_morphism( on_basis=lambda i: i, codomain=QQ )
     233                sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) )
     234                -1
     235
     236                sage: phi = X.module_morphism(on_basis= lambda i: i, codomain=RR )
     237                sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) )
     238                -1.00000000000000
     239
     240                sage: phi = X.module_morphism(on_basis= lambda i: i, codomain=ZZ)
     241                ...
     242                AssertionError:
     243               
     244                ''as codomain.base_ring().has_coerce_map_from( domain.base_ring() ) is False''
     245
     246                sage: R2 = CombinatorialFreeModule(RR,['x','y'])
     247                sage: C  = CombinatorialFreeModule(CC,['z'])
     248                sage: x  = X.monomial('x')
     249                sage: y  = X.monomial('y')
     250                sage: z  = Y.monomial('z')
     251                sage: def on_basis( a ):
     252                    if a == 'x':
     253                        return CC(1) * z
     254                    elif a == 'y':
     255                        return CC(I) * z
     256                ....:
     257                sage: phi = R2.module_morphism( on_basis=on_basis, codomain=C )
     258                sage: v = 3 * x + 2 * y
     259                3.00000000000000*B['x'] + 2.00000000000000*B['y']
     260                sage: phi(v)
     261                (3.00000000000000+2.00000000000000*I)*B['z']
     262
     263
    230264            With the ``diagonal`` argument, this returns the module morphism `g` such that:
    231265
    232266                `g(x_i) = d(i) y_i`
     
    10571091                zero = codomain.zero()
    10581092            else:
    10591093                zero = 0
    1060         assert domain.base_ring()    == codomain.base_ring()
     1094
     1095        assert hasattr( codomain, 'base_ring' ) and codomain.base_ring().has_coerce_map_from( domain.base_ring() )
     1096       
    10611097        if category is None and codomain is not None and codomain.category().is_subcategory(ModulesWithBasis(domain.base_ring())):
    10621098            category = ModulesWithBasis(domain.base_ring())
    10631099        assert codomain is not None
     
    11291165        after = args[self._position+1:len(args)]
    11301166        x = args[self._position]
    11311167        assert(x.parent() is self.domain())
    1132         return sum([self._on_basis(*(before+(index,)+after))._lmul_(coeff) for (index, coeff) in args[self._position]], self._zero)
     1168
     1169        if self.codomain() in ModulesWithBasis( self.codomain().base_ring() ):
     1170            return sum([self._on_basis(*(before+(index,)+after))._lmul_(coeff) for (index, coeff) in args[self._position]], self._zero)
     1171        else:
     1172            return sum([ coeff * self._on_basis(*(before+(index,)+after)) for (index, coeff) in args[self._position]], self._zero)
    11331173
    11341174    # As per the specs of Map, we should in fact implement _call_.
    11351175    # However we currently need to abuse Map.__call__ (which strict