Opened 13 months ago
Closed 12 months ago
#27856 closed defect (fixed)
Tangent vectors should act as derivations on scalar fields
Reported by:  egourgoulhon  Owned by:  

Priority:  major  Milestone:  sage8.8 
Component:  geometry  Keywords:  vector, derivation 
Cc:  tscrim  Merged in:  
Authors:  Eric Gourgoulhon  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  4c0abd7 (Commits)  Commit:  4c0abd75065fae7820988a6eb8c2a0ebcb3091f9 
Dependencies:  Stopgaps: 
Description
In Sage 8.7, we have
sage: M = Manifold(2, 'M') sage: X.<x,y> = M.chart() sage: p = M((2,1), name='p') sage: TpM = M.tangent_space(p) sage: v = TpM((2, 3), name='v'); v Tangent vector v at Point p on the 2dimensional differentiable manifold M sage: f = M.scalar_field(x*y^2, name='f') sage: v(f) Traceback (most recent call last): ... TypeError: the argument no. 1 must be a linear form
Note that this works for vector fields:
sage: w = M.vector_field(name='w') sage: w[:] = y, x sage: w.display() w = y d/dx + x d/dy sage: w(f) Scalar field w(f) on the 2dimensional differentiable manifold M sage: w(f).display() w(f): M > R (x, y) > 2*x^2*y  y^3
This issue has been reported in this ask.sagemath question.
Change History (11)
comment:1 Changed 12 months ago by
 Branch set to public/manifolds/vector_derivation27856
 Commit set to 50bc6da98b97fe2104f670c0cc7412211f87be7f
comment:2 Changed 12 months ago by
 Cc tscrim added
 Status changed from new to needs_review
comment:3 followup: ↓ 4 Changed 12 months ago by
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.
comment:4 in reply to: ↑ 3 Changed 12 months ago by
Replying to tscrim:
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.
I am a little bit puzzled by this: looking at lines 11541184 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):
v(f*g) == v(f)*g(p) + f(p)*v(g)
There 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?
comment:5 followup: ↓ 7 Changed 12 months ago by
Ah, I see. I saw act in the ticket and was thinking it should behave like a normal action (and be written with a binary operation such as multiplication). So sorry about that noise there. I guess this is fine since it is done on an element and not a parent. (As a side note, it is actually __call__
that starts the dispatch to the coercion framework, not something that is dealt out from it.)
Only other thing you need to address is changing EXAMPLES::
> EXAMPLES:
to get a positive review.
comment:6 Changed 12 months ago by
 Commit changed from 50bc6da98b97fe2104f670c0cc7412211f87be7f to 4c0abd75065fae7820988a6eb8c2a0ebcb3091f9
Branch pushed to git repo; I updated commit sha1. New commits:
4c0abd7  Correct EXAMPLES statement in tangent_vector

comment:7 in reply to: ↑ 5 ; followup: ↓ 8 Changed 12 months ago by
Replying to tscrim:
Ah, I see. I saw act in the ticket and was thinking it should behave like a normal action (and be written with a binary operation such as multiplication). So sorry about that noise there.
No problem. Actually I should have used "behave" instead of "act" to avoid any confusion (there is indeed no group action here).
I guess this is fine since it is done on an element and not a parent.
(As a side note, it is actually
__call__
that starts the dispatch to the coercion framework, not >something that is dealt out from it.)
For my own instruction, can you tell by which magic this is done (given that __call__
is not redefined in the base class Element
)?
Only other thing you need to address is changing
EXAMPLES::
>EXAMPLES:
to get a positive review.
Done in the above commit.
comment:8 in reply to: ↑ 7 ; followup: ↓ 10 Changed 12 months ago by
 Reviewers set to Travis Scrimshaw
Replying to egourgoulhon:
Replying to tscrim:
I guess this is fine since it is done on an element and not a parent.
(As a side note, it is actually
__call__
that starts the dispatch to the coercion framework, not >something that is dealt out from it.)For my own instruction, can you tell by which magic this is done (given that
__call__
is not redefined in the base classElement
)?
It is Parent.__call__
that starts the process off. However, you can explicit invoke the coercion framework by importing the coercion_model
within your own class. There are also things like @coerce_binop
as helpers too.
Only other thing you need to address is changing
EXAMPLES::
>EXAMPLES:
to get a positive review.Done in the above commit.
Thanks, LGTM.
comment:9 Changed 12 months ago by
 Status changed from needs_review to positive_review
comment:10 in reply to: ↑ 8 Changed 12 months ago by
Replying to tscrim:
It is
Parent.__call__
that starts the process off. However, you can explicit invoke the coercion framework by importing thecoercion_model
within your own class. There are also things like@coerce_binop
as helpers too.
Thanks for these explanations and thanks for the review!
comment:11 Changed 12 months ago by
 Branch changed from public/manifolds/vector_derivation27856 to 4c0abd75065fae7820988a6eb8c2a0ebcb3091f9
 Resolution set to fixed
 Status changed from positive_review to closed
New commits:
Add action of tangent vectors on scalar fields