# how to define morphism of free modules without matrices

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 close merge delete

Sort by » oldest newest most voted 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()])

more

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

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