Hi Simon, On Sun, Jan 29, 2012 at 10:37:22PM -0800, Simon King wrote: > That's to say: You don't simply want a function, but you want a > morphism of modules over the base ring, isn't it? Yes, this is what I wanted to say. And it should fulfill the Leibniz rule on elements of the ring (the module is a ring in fact).
> Since you want an element of a homset in the category of modules over > QQ, let's see first how to create the homset: > > sage: H = P.Hom(P, category=Modules(QQ)) > sage: H > Set of Morphisms from Univariate Polynomial Ring in x over Rational > Field to Univariate Polynomial Ring in x over Rational Field in > Category of vector spaces over Rational Field > > As you can see, P.Hom(...) (in contrast to P.hom) accepts an optional > argument that allows for considering a super category. > > Do you know how to obtain the documentation? If not: Simply type > P.Hom? and hit return. If you want to see the source code, type > P.Hom?? and hit return. Yes, I saw this. But I did not really know how to make use of it. > I think a method P.der(images_of_generators) returning a derivation > given by the images of generators would be useful. Of course, such > method needs to return a derivation, which is a morphism. So, I am > showing you how to define a morphism: > > sage: from sage.categories.morphism import Morphism > sage: Morphism.__call__? > Apply this map to ``x``. > > IMPLEMENTATION: > > - To implement the call method in a subclass of Map, > implement > :meth:`_call_` and possibly also :meth:`_call_with_args` > and > :meth:`pushforward`. > ... > > So, that is an important information: Do NOT override __call__ (double > underscore), but provide a single underscore _call_! > > Here is a toy implementation, namely for univariate polynomial rings > only, and without the possibility to map the generator to anything but > 1. > > sage: class Derivative(Morphism): > ....: def __init__(self, P, gen_images): > ....: if len(gen_images)!=1: > ....: raise ValueError > ....: B = P.base_ring() > ....: if P not in Modules(B): > ....: raise ValueError > ....: if gen_images[0]!=B.one_element(): > ....: raise NotImplementedError > ....: Morphism.__init__(self,P.Hom(P, category=Modules(B))) > ....: # here, add stuff for > ....: # general derivations. > ....: # Store the generator images, e.g. > ....: def _call_(self, p): > ....: # this is just a toy example, > ....: # implement more fancy stuff here > ....: return derivative(p) > ....: def _repr_type(self): > ....: # This is to make the derivative print like a derivative > ....: return "Derivative" > ....: > sage: f = Derivative(P,[1]) > sage: f > Derivative endomorphism of Univariate Polynomial Ring in x over > Rational Field > # you may think of a nicer string representation - look at the source > code > # of other morphisms Thank you for this example. This looks like what I was searching for, at least like a first approximation. I have a problem. After defining the class Derivation, I get an error using it (a ValueError). The problem seems to be the following: sage: P.<x> = QQ[] sage: B = P.base_ring() sage: P in Modules(B) False sage: Modules(B) Category of vector spaces over Rational Field sage: P Univariate Polynomial Ring in x over Rational Field I do not understand why "Univariate Polynomial Ring in x over Rational Field" is not in "Category of vector spaces over Rational Field". It should be. Is not it? Is there a way to visualize the inclusions of categories in sage? I think I saw once a graph visualizing the inclusions. But I do not know how to generate it or where to find it. Best regards, Oliver -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org