On 11/3/12 9:33 AM, Volker Braun wrote:
On Saturday, November 3, 2012 1:53:24 PM UTC, jason wrote:

    sage: h = linear_transformation(RR^2, RR^2, matrix(RR, [[0, 1], [2,
    3]]))
    sage: h*3 #works fine


This does not involve coercion. h.__mul__(3) figures out that 3 is
scalar multiplication and handles it.

Right.  Sure.



    sage: 3*h #doesn't work


This requires coercion, as 3.__mul__(h) can't possibly know about h
being a vector space morphism. Hence you need the coercion
infrastructure, and in particular _an_element_(). Just implement that.

I guess my confusion comes from 3*phi working when phi is a free module morphism. Indeed, it appears there is a difference:

sage: phi = (ZZ^2).hom(matrix(ZZ,2,[1..4]))
sage: h = (RR^2).hom(matrix(RR, 2, [1..4]))
sage: type(phi.parent())
sage.modules.free_module_homspace.FreeModuleHomspace_with_category
sage: type(h.parent())
sage.modules.vector_space_homspace.VectorSpaceHomspace_with_category

Looking at the code, h.parent() is a direct subclass of phi.parent().


sage: phi.parent()._an_element_()
Free module morphism defined by the matrix
[2 0]
[0 2]
Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring
sage: h.parent()._an_element_()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-90-7eb7649cd8cb> in <module>()
----> 1 h.parent()._an_element_()

/Users/grout/sage-trees/sage-5.4.rc1/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent._an_element_ (sage/structure/parent.c:18100)()

NotImplementedError: please implement _an_element_ for Set of Morphisms (Linear Transformations) from Vector space of dimension 2 over Real Field with 53 bits of precision to Vector space of dimension 2 over Real Field with 53 bits of precision
sage:


How come the _an_element_ method didn't get inherited from from the FreeModuleHomspace? Also, I don't see an _an_element_ method in the FreeModuleHomspace code. Did it inherit its _an_element_ method from its superclass?

Thanks,

Jason


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to sage-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-devel+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to