Ask Your Question
0

how to define morphism of free modules without matrices

asked 2017-04-06 18:32:02 -0500

I want to use sage to get some complicated mapping between free modules as a matrix. Consider the following code:

test_basis = [((0, 0, 0), (0, 0, 0)), ((0, 0, 1), (0, 0, 0)), ((0, 1, 0), (0, 0, 0)), ((1, 0, 0), (0, 0, 0))]
Domain = CombinatorialFreeModule(QQ, test_basis, prefix='D')
codomain_basis = [((0, 0, 0), (0, 0, 0)), ((0, 0, 1), (0, 0, 0)), ((0, 1, 0), (0, 0, 0)), ((1, 0, 0), (0, 0, 0))]
Codomain = CombinatorialFreeModule(QQ, codomain_basis, prefix='C')
Cb = Codomain.basis()
images = [Cb[((1, 0, 0), (0, 0, 0))]]
h = Domain.hom(images, codomain=Codomain)

I expected to obtain the homohorphism h and then just ask for the matrix, but instead I got this error:

Error in lines 7-7
Traceback (most recent call last):
  File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 982, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "sage/structure/parent.pyx", line 1444, in sage.structure.parent.Parent.hom (/projects/sage/sage-7.5/src/build/cythonized/sage/structure/parent.c:13257)
    return self.Hom(codomain)(im_gens)
  File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/categories/homset.py", line 908, in __call__
    raise TypeError("Unable to coerce x (=%s) to a morphism in %s"%(x,self))
TypeError: Unable to coerce x (=[C[((1, 0, 0), (0, 0, 0))]]) to a morphism in Set of Morphisms from Free module generated by {((0, 0, 0), (0, 0, 0)), ((0, 0, 1), (0, 0, 0)), ((0, 1, 0), (0, 0, 0)), ((1, 0, 0), (0, 0, 0))} over Rational Field to Free module generated by {((0, 0, 0), (0, 0, 0)), ((0, 0, 1), (0, 0, 0)), ((0, 1, 0), (0, 0, 0)), ((1, 0, 0), (0, 0, 0))} over Rational Field in Category of finite dimensional vector spaces with basis over Rational Field

By the way, the documentation of Free Modules is seriously lacking. For example, I have no idea what the prefix is for.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2017-04-07 01:52:57 -0500

FrédéricC gravatar image

Maybe like that

def matrice_morphism(morph):
    """
    Return the matrix of a morphism ``morph``.

    EXAMPLES::

        sage: module = CombinatorialFreeModule(QQ,Partitions(4))
        sage: f = lambda mu:module.monomial(mu.conjugate())
        sage: morphisme = module.module_morphism(f, codomain=module)
        sage: matrice_morphism(morphisme)
        [0 0 0 0 1]
        [0 0 0 1 0]
        [0 0 1 0 0]
        [0 1 0 0 0]
        [1 0 0 0 0]
    """
    return matrix([morph(u).to_vector() for u in morph.domain().basis()])
edit flag offensive delete link more

Comments

Thank you, but the error happens when I try to actually construct the morphism.

vit_tucek gravatar imagevit_tucek ( 2017-04-07 06:40:36 -0500 )edit

Oh. I see. Then look at the doc of Domain.module_morphism? for the possible ways to define a morphism.

FrédéricC gravatar imageFrédéricC ( 2017-04-07 11:11:36 -0500 )edit

But this workaround works. Thanks again.

vit_tucek gravatar imagevit_tucek ( 2017-04-07 16:49:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-04-06 18:32:02 -0500

Seen: 30 times

Last updated: Apr 07