Hi Oliver,

On 30 Jan., 01:04, Oliver Block <oliver_blo...@web.de> wrote:
> Hello,
>
> I would like to define a function d from polynomial ring to itself (in
> the easiest case) that is linear over the base ring

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?

> How can this be achieved?
>
> What I found is the "hom" method of the Polynomial ring, but using this
> method, ring homomorphisms are created.

Let
  sage: P.<x> = QQ[]

Indeed, the method P.hom(P) is not what you want, since it creates
ring homomorphisms.

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.

> Is there already such a functionality in SAGE? If not, my idea would be
> to create a method "der", similar to "hom", but with multiplication
> defined differently. Would this be a good approach? If so, could someone
> give me some hints where to look for in the source?

I am not aware of general derivations in Sage, but I could be
mistaken. So, let's do a search:
  sage: search_src("derivation")
  schemes/elliptic_curves/heegner.py:6911:    #    period lattice.
See the following paper for a derivation:
  symbolic/function_factory.py:150:    - ``derivative_func`` - method
to be used for (partial) derivation
  symbolic/function_factory.py:224:    Defining custom methods for
automatic or numeric evaluation, derivation,
  symbolic/pynac.pyx:87:    Used to pass return values of custom
python evaluation, derivation
  symbolic/units.py:883:unit_derivations = {'acceleration':'length/
time^2',
  symbolic/units.py:938:def unit_derivations_expr(v):
  symbolic/units.py:954:        sage:
sage.symbolic.units.unit_derivations_expr('volume')
  symbolic/units.py:956:        sage:
sage.symbolic.units.unit_derivations_expr('electric_potential')
  symbolic/units.py:961:        sage:
sage.symbolic.units.unit_derivations_expr('invalid')
  symbolic/units.py:967:    Z = unit_derivations[v]
  symbolic/units.py:972:        unit_derivations[v] = Z
  symbolic/units.py:1354:        if unit_derivations.has_key(str(v)):
  symbolic/units.py:1355:            base = unit_derivations_expr(v)
  tensor/differential_form_element.py:807:        The exterior
differential operator is a derivation of degree one
  categories/coxeter_groups.py:1116:            ``self`` as subword.
See Stembridge, A short derivation of

So, it doesn't look like what you want.

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

# f is not a morphism of rings, but of modules:
sage: f.category_for()
Category of vector spaces over Rational Field

# and it maps polynomials as we wanted it:
sage: p = P.random_element()
sage: p
-x^2 + 7/4
sage: f(p)
-2*x

Best regards,
Simon

> PS: There was a similar question on this list posed by Scott on Feb. 7, 2011,
> but there is no answer until now.

Sorry, I missed that.

-- 
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

Reply via email to