ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Jun 2016 10:42:17 -0500Derivation of a sagemanifold vector (possible bug)http://ask.sagemath.org/question/33951/derivation-of-a-sagemanifold-vector-possible-bug/ I'm using sage v7.1 with sagemanifold v0.9 to calculate Lie derivatives.
<h2>The problem</h2>
I define my manifold, with a chart and the vectors which define the symmetry,
M = Manifold(4, 'M', latex_name=r"\mathcal{M}")
X.<t,r,th,ph> = M.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
Lx = M.vector_field('Lx')
Lx[:] = [ 0, 0, -cos(ph), cot(th)*sin(ph) ]
Ly = M.vector_field('Ly')
Ly[:] = [ 0, 0, sin(ph), cot(th)*cos(ph) ]
Lz = M.vector_field('Lz')
Lz[:] = [ 0, 0, 0, 1]
Lt = M.vector_field('Lt')
Lt[:] = [ 1, 0, 0, 0]
However, if I call the derivative of a component of the vector like
diff( Lx[3], th )
I get a `TypeError`, because
type( Lx[3] )
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
and it seems that the function `diff` only acts on SR expressions.
<h2>My bypass</h2>
Although I was able to bypass the situation, it would be nice if a solution was provided *out of the box*, but in case anyone else needs a solution:
I defined my vectors in a Sage way
xi0 = [ 1, 0, 0, 0]
xi1 = [ 0, 0, -cos(ph), cot(th)*sin(ph) ]
xi2 = [ 0, 0, sin(ph), cot(th)*cos(ph) ]
xi3 = [ 0, 0, 0, 1]
and then assigned them to the SageManifolds vector_field
Lx = M.vector_field('Lx')
Lx[:] = xi1
Ly = M.vector_field('Ly')
Ly[:] = xi2
Lz = M.vector_field('Lz')
Lz[:] = xi3
Lt = M.vector_field('Lt')
Lt[:] = xi0
So, when I need the derivative of a component of the vector, I calculate
diff(xi1[3], th)
Cheers.Tue, 28 Jun 2016 10:16:13 -0500http://ask.sagemath.org/question/33951/derivation-of-a-sagemanifold-vector-possible-bug/Answer by eric_g for <p>I'm using sage v7.1 with sagemanifold v0.9 to calculate Lie derivatives.</p>
<h2>The problem</h2>
<p>I define my manifold, with a chart and the vectors which define the symmetry,</p>
<pre><code>M = Manifold(4, 'M', latex_name=r"\mathcal{M}")
X.<t,r,th,ph> = M.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
Lx = M.vector_field('Lx')
Lx[:] = [ 0, 0, -cos(ph), cot(th)*sin(ph) ]
Ly = M.vector_field('Ly')
Ly[:] = [ 0, 0, sin(ph), cot(th)*cos(ph) ]
Lz = M.vector_field('Lz')
Lz[:] = [ 0, 0, 0, 1]
Lt = M.vector_field('Lt')
Lt[:] = [ 1, 0, 0, 0]
</code></pre>
<p>However, if I call the derivative of a component of the vector like</p>
<pre><code>diff( Lx[3], th )
</code></pre>
<p>I get a <code>TypeError</code>, because</p>
<pre><code>type( Lx[3] )
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
</code></pre>
<p>and it seems that the function <code>diff</code> only acts on SR expressions.</p>
<h2>My bypass</h2>
<p>Although I was able to bypass the situation, it would be nice if a solution was provided <em>out of the box</em>, but in case anyone else needs a solution:</p>
<p>I defined my vectors in a Sage way</p>
<pre><code>xi0 = [ 1, 0, 0, 0]
xi1 = [ 0, 0, -cos(ph), cot(th)*sin(ph) ]
xi2 = [ 0, 0, sin(ph), cot(th)*cos(ph) ]
xi3 = [ 0, 0, 0, 1]
</code></pre>
<p>and then assigned them to the SageManifolds vector_field</p>
<pre><code>Lx = M.vector_field('Lx')
Lx[:] = xi1
Ly = M.vector_field('Ly')
Ly[:] = xi2
Lz = M.vector_field('Lz')
Lz[:] = xi3
Lt = M.vector_field('Lt')
Lt[:] = xi0
</code></pre>
<p>So, when I need the derivative of a component of the vector, I calculate</p>
<pre><code>diff(xi1[3], th)
</code></pre>
<p>Cheers.</p>
http://ask.sagemath.org/question/33951/derivation-of-a-sagemanifold-vector-possible-bug/?answer=33952#post-id-33952It's true that the *global function* `diff` applies only to symbolic expressions, not to coordinate functions as defined in SageManifolds. But you can use the *method* `diff` on them:
sage: Lx[3].diff(th)
-sin(ph)/sin(th)^2
Note that the result is still a coordinate function:
sage: type(Lx[3].diff(th))
<class 'sage.manifolds.coord_func_symb.CoordFunctionSymb'>
To get a symbolic expression, use the method `expr()`:
sage: Lx[3].diff(th).expr()
-sin(ph)/sin(th)^2
sage: type(Lx[3].diff(th).expr())
<type 'sage.symbolic.expression.Expression'>
Another solution is to invoke `expr()` prior to the global function `diff`:
sage: diff(Lx[3].expr(), th)
-cos(th)^2*sin(ph)/sin(th)^2 - sin(ph)
Note that in this case, the result is not automatically simplified (this is one of the differences between symbolic expressions and coordinate functions).Tue, 28 Jun 2016 10:42:17 -0500http://ask.sagemath.org/question/33951/derivation-of-a-sagemanifold-vector-possible-bug/?answer=33952#post-id-33952