Sage: Ticket #27856: Tangent vectors should act as derivations on scalar fields
https://trac.sagemath.org/ticket/27856
<p>
In Sage 8.7, we have
</p>
<pre class="wiki">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 2-dimensional 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
</pre><p>
Note that this works for vector <em>fields</em>:
</p>
<pre class="wiki">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 2-dimensional differentiable manifold M
sage: w(f).display()
w(f): M --> R
(x, y) |--> 2*x^2*y - y^3
</pre><p>
This issue has been reported in this <a class="ext-link" href="https://ask.sagemath.org/question/46593/tangent-space-vector-mapping/"><span class="icon"></span>ask.sagemath question</a>.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/27856
Trac 1.1.6egourgoulhonSun, 26 May 2019 16:58:40 GMTcommit, branch set
https://trac.sagemath.org/ticket/27856#comment:1
https://trac.sagemath.org/ticket/27856#comment:1
<ul>
<li><strong>commit</strong>
set to <em>50bc6da98b97fe2104f670c0cc7412211f87be7f</em>
</li>
<li><strong>branch</strong>
set to <em>public/manifolds/vector_derivation-27856</em>
</li>
</ul>
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit?id=50bc6da98b97fe2104f670c0cc7412211f87be7f"><span class="icon"></span>50bc6da</a></td><td><code>Add action of tangent vectors on scalar fields</code>
</td></tr></table>
TicketegourgoulhonSun, 26 May 2019 16:59:45 GMTstatus changed; cc set
https://trac.sagemath.org/ticket/27856#comment:2
https://trac.sagemath.org/ticket/27856#comment:2
<ul>
<li><strong>cc</strong>
<em>tscrim</em> added
</li>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
TickettscrimSun, 26 May 2019 23:42:49 GMT
https://trac.sagemath.org/ticket/27856#comment:3
https://trac.sagemath.org/ticket/27856#comment:3
<p>
A good general rule that you should follow is to not overwrite <code>__call__</code>. Instead, the typical thing to do is implement an <code>_act_on_</code> (or <code>_acted_upon_</code>), and let the coercion framework handle the dispatching.
</p>
TicketegourgoulhonMon, 27 May 2019 15:48:45 GMT
https://trac.sagemath.org/ticket/27856#comment:4
https://trac.sagemath.org/ticket/27856#comment:4
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/27856#comment:3" title="Comment 3">tscrim</a>:
</p>
<blockquote class="citation">
<p>
A good general rule that you should follow is to not overwrite <code>__call__</code>. Instead, the typical thing to do is implement an <code>_act_on_</code> (or <code>_acted_upon_</code>), and let the coercion framework handle the dispatching.
</p>
</blockquote>
<p>
I am a little bit puzzled by this: looking at lines 1154-1184 of <code>src/sage/structure/coerce.pyx</code>, I have the impression that <code>_act_on_</code> is used for actions denoted by <code>__mul__</code>, not by <code>__call__</code>. This seems confirmed from the doctest examples one can get from <code>grep -r "def _act_on_" src/sage</code>. Now, in the current setting, we do want to write <code>v(f)</code> for the action of a tangent vector <code>v</code> on a scalar function <code>f</code>, not <code>v*f</code>. For instance, we can form the derivation law that looks very much the textbook formula (<code>p</code> being the point at which <code>v</code> is defined):
</p>
<pre class="wiki">v(f*g) == v(f)*g(p) + f(p)*v(g)
</pre><p>
There is no redefinition of <code>__call__</code> in <code>src/sage/structure/element.pyx</code>, contrary to <code>__add__</code>, <code>__mul__</code>, etc., which leads one to think that <code>__call__</code> is not delt via the coercion framework. Supporting this, we can note that overwriting <code>__call__</code> is much used in Sage library: <code>grep -r "def __call__" src/sage | wc -l</code> returns 496 instances (on the contrary, <code>grep -r "def _act_on_" src/sage | wc -l</code> returns only 16 instances). Am I missing something?
</p>
TickettscrimTue, 28 May 2019 13:19:46 GMT
https://trac.sagemath.org/ticket/27856#comment:5
https://trac.sagemath.org/ticket/27856#comment:5
<p>
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 <code>__call__</code> that starts the dispatch to the coercion framework, not something that is dealt out from it.)
</p>
<p>
Only other thing you need to address is changing <code>EXAMPLES::</code> -> <code>EXAMPLES:</code> to get a positive review.
</p>
TicketgitTue, 28 May 2019 13:35:07 GMTcommit changed
https://trac.sagemath.org/ticket/27856#comment:6
https://trac.sagemath.org/ticket/27856#comment:6
<ul>
<li><strong>commit</strong>
changed from <em>50bc6da98b97fe2104f670c0cc7412211f87be7f</em> to <em>4c0abd75065fae7820988a6eb8c2a0ebcb3091f9</em>
</li>
</ul>
<p>
Branch pushed to git repo; I updated commit sha1. New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit/?id=4c0abd75065fae7820988a6eb8c2a0ebcb3091f9"><span class="icon"></span>4c0abd7</a></td><td><code>Correct EXAMPLES statement in tangent_vector</code>
</td></tr></table>
TicketegourgoulhonTue, 28 May 2019 13:44:24 GMT
https://trac.sagemath.org/ticket/27856#comment:7
https://trac.sagemath.org/ticket/27856#comment:7
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/27856#comment:5" title="Comment 5">tscrim</a>:
</p>
<blockquote class="citation">
<p>
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.
</p>
</blockquote>
<p>
No problem. Actually I should have used "behave" instead of "act" to avoid any confusion (there is indeed no group action here).
</p>
<blockquote class="citation">
<p>
I guess this is fine since it is done on an element and not a parent.
</p>
</blockquote>
<blockquote class="citation">
<p>
(As a side note, it is actually <code>__call__</code> that starts the dispatch to the coercion framework, not >something that is dealt out from it.)
</p>
</blockquote>
<p>
For my own instruction, can you tell by which magic this is done (given that <code>__call__</code> is not redefined in the base class <code>Element</code>)?
</p>
<blockquote class="citation">
<p>
Only other thing you need to address is changing <code>EXAMPLES::</code> -> <code>EXAMPLES:</code> to get a positive review.
</p>
</blockquote>
<p>
Done in the above commit.
</p>
TickettscrimTue, 28 May 2019 14:06:52 GMTreviewer, author set
https://trac.sagemath.org/ticket/27856#comment:8
https://trac.sagemath.org/ticket/27856#comment:8
<ul>
<li><strong>reviewer</strong>
set to <em>Travis Scrimshaw</em>
</li>
<li><strong>author</strong>
set to <em>Eric Gourgoulhon</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/27856#comment:7" title="Comment 7">egourgoulhon</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/27856#comment:5" title="Comment 5">tscrim</a>:
</p>
<blockquote class="citation">
<p>
I guess this is fine since it is done on an element and not a parent.
</p>
</blockquote>
<blockquote class="citation">
<p>
(As a side note, it is actually <code>__call__</code> that starts the dispatch to the coercion framework, not >something that is dealt out from it.)
</p>
</blockquote>
<p>
For my own instruction, can you tell by which magic this is done (given that <code>__call__</code> is not redefined in the base class <code>Element</code>)?
</p>
</blockquote>
<p>
It is <code>Parent.__call__</code> that starts the process off. However, you can explicit invoke the coercion framework by importing the <code>coercion_model</code> within your own class. There are also things like <code>@coerce_binop</code> as helpers too.
</p>
<blockquote class="citation">
<blockquote class="citation">
<p>
Only other thing you need to address is changing <code>EXAMPLES::</code> -> <code>EXAMPLES:</code> to get a positive review.
</p>
</blockquote>
<p>
Done in the above commit.
</p>
</blockquote>
<p>
Thanks, LGTM.
</p>
TickettscrimTue, 28 May 2019 14:07:01 GMTstatus changed
https://trac.sagemath.org/ticket/27856#comment:9
https://trac.sagemath.org/ticket/27856#comment:9
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
TicketegourgoulhonTue, 28 May 2019 14:34:07 GMT
https://trac.sagemath.org/ticket/27856#comment:10
https://trac.sagemath.org/ticket/27856#comment:10
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/27856#comment:8" title="Comment 8">tscrim</a>:
</p>
<blockquote class="citation">
<p>
It is <code>Parent.__call__</code> that starts the process off. However, you can explicit invoke the coercion framework by importing the <code>coercion_model</code> within your own class. There are also things like <code>@coerce_binop</code> as helpers too.
</p>
</blockquote>
<p>
Thanks for these explanations and thanks for the review!
</p>
TicketvbraunSun, 02 Jun 2019 22:04:31 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/27856#comment:11
https://trac.sagemath.org/ticket/27856#comment:11
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>public/manifolds/vector_derivation-27856</em> to <em>4c0abd75065fae7820988a6eb8c2a0ebcb3091f9</em>
</li>
</ul>
Ticket