Changes between Initial Version and Version 1 of Ticket #27856, comment 4


Ignore:
Timestamp:
05/27/19 19:16:43 (2 years ago)
Author:
egourgoulhon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27856, comment 4

    initial v1  
    11Replying to [comment:3 tscrim]:
    22> A good general rule that you should follow is to not overwrite `__call__`. Instead, the typical thing to do is implement an `_act_on_` (or `_acted_upon_`), and let the coercion framework handle the dispatching.
    3 I am a little bit puzzled by this: looking at lines 1154-1184 of `src/sage/structure/coerce.pyx`, I have the impression that `_act_on_` is used for actions denoted by `__mul__`, not by `__call__`. This seems confirmed from the doctest examples one can get from `grep -r "def _act_on_" src/sage`. Now, in the current setting, we do want to write `v(f)` for the action of a tangent vector `v` on a scalar function `f`, not `v*f`. Besides, it seems overwriting `__call__` is much used in Sage library: `grep -r "def __call__" src/sage | wc -l` returns 496 instances, while `grep -r "def _act_on_" src/sage | wc -l` returns only 16 instances.
     3I am a little bit puzzled by this: looking at lines 1154-1184 of `src/sage/structure/coerce.pyx`, I have the impression that `_act_on_` is used for actions denoted by `__mul__`, not by `__call__`. This seems confirmed from the doctest examples one can get from `grep -r "def _act_on_" src/sage`. Now, in the current setting, we do want to write `v(f)` for the action of a tangent vector `v` on a scalar function `f`, not `v*f`. For instance, we can form the derivation law that looks very much the textbook formula (`p` being the point at which `v` is defined):
     4{{{
     5v(f*g) == v(f)*g(p) + f(p)*v(g)
     6}}}
     7There is no redefinition of `__call__` in `src/sage/structure/element.pyx`, contrary to `__add__`, `__mul__`, etc., which leads one to think that `__call__` is not delt via the coercion framework. Supporting this, we can note that overwriting `__call__` is much used in Sage library: `grep -r "def __call__" src/sage | wc -l` returns 496 instances (on the contrary, `grep -r "def _act_on_" src/sage | wc -l` returns only 16 instances). Am I missing something?