Ask Your Question
0

Derivation of a sagemanifold vector (possible bug)

asked 2016-06-28 17:16:13 +0100

Dox gravatar image

updated 2017-08-01 12:17:43 +0100

FrédéricC gravatar image

I'm using sage v7.1 with sagemanifold v0.9 to calculate Lie derivatives.

The problem

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.

My bypass

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-06-28 17:42:17 +0100

eric_g gravatar image

It'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).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-28 17:16:13 +0100

Seen: 486 times

Last updated: Jun 28 '16