Ask Your Question
0

Differential forms best package

asked 2017-12-29 00:17:57 +0100

danielvolinski gravatar image

I understand there are two different ways to use differential forms in SageMath:

1) in the reference document "manifold.pdf"

sage: M = Manifold(4, 'M')

sage: a = M.one_form('A') or F = M.diff_form(2, 'F')

2) in the reference document "tensors.pdf"

sage: x, y, z = var('x, y, z')

sage: U = CoordinatePatch((x, y, z))

sage: F = DifferentialForms(U)

sage: form1 = DifferentialForm(F, 0, sin(x*y)); form1

Which is the best? Are they compatible? Can I mix and match from both packages? What are their pros and cons?

Thanks.

edit retag flag offensive close merge delete

Comments

To display inline code, like f, use backticks.

To display blocks of code or error messages, separate them by a blank line from the rest of the text, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select code lines and click the "code" button (the icon with '101 010')
  • select code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y):
        return (x, y)

then `f(2, 3)` returns `(2, 3)` but `f(2)` gives:

    TypeError: f() takes exactly 2 arguments (1 given)

produces:

If we define f by

def f(x, y):
    return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)

Please edit your question to do that.

slelievre gravatar imageslelievre ( 2017-12-29 20:22:31 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-12-29 15:46:09 +0100

eric_g gravatar image

updated 2017-12-29 15:56:58 +0100

I would advise to use the manifold version: all the functionalities of the CoordinatePatch version are available in the manifold version, but the latter is more recent and provides more functionalities, like

  • changing the coordinates
  • evaluating the Lie derivative with respect to a vector field
  • performing the interior product with a p-vector
  • evaluating the Hodge dual with respect to a metric

It is also more flexible:

  • the indices may be chosen to start from 1 instead of 0
  • one may use index notation with summation on repeated indices.

The two versions cannot be mixed and most probably the CoordinatePatch version should be deprecated.

1. Illustration of similarities and differences

Let us declare a differential form of degree 2 with the CoordinatePatch version:

sage: x, y, z = var('x, y, z')
sage: U = CoordinatePatch((x, y, z))
sage: F = DifferentialForms(U)
sage: f = DifferentialForm(F, 2)
sage: f[0,1] = x*sin(z)
sage: f[1,2] = y*z
sage: f
x*sin(z)*dx/\dy + y*z*dy/\dz

To perform the same thing with the manifold version, one should write (using a different Sage session to avoid any confusion):

sage: U = Manifold(3, 'U')
sage: X.<x,y,z> = U.chart()
sage: f = U.diff_form(2, 'f')
sage: f[0,1] = x*sin(z)
sage: f[1,2] = y*z
sage: f
2-form f on the 3-dimensional differentiable manifold U
sage: f.display()
f = x*sin(z) dx/\dy + y*z dy/\dz

Let us introduce another differential form, as a 1-form; in the CoordinatePatch version:

sage: g = DifferentialForm(F, 1)
sage: g[0], g[1], g[2] = (y^2, -z, 2*x-y)
sage: g
(2*x - y)*dz + y^2*dx + -z*dy

In the manifold version, one may use the shortcut notation g[:] to set the components of g:

sage: g = U.diff_form(1, 'g')
sage: g[:] = (y^2, -z, 2*x-y)
sage: g.display()
g = y^2 dx - z dy + (2*x - y) dz

The wedge product of f by g is obtained in the same way in both methods: for CoordinatePatch:

sage: f.wedge(g)
(y^3*z + (2*x - y)*x*sin(z))*dx/\dy/\dz

while for the manifold version:

sage: f.wedge(g)
3-form f/\g on the 3-dimensional differentiable manifold U
sage: f.wedge(g).display()
f/\g = (y^3*z + (2*x^2 - x*y)*sin(z)) dx/\dy/\dz

The exterior derivative is computed via the method diff() in the CoordinatePatch version:

sage: f.diff()
x*cos(z)*dx/\dy/\dz

and via the method exterior_derivative() in the manifold version:

sage: f.exterior_derivative().display()
df = x*cos(z) dx/\dy/\dz

A shortcut is provided by the function xder, to be used as the operator $\mathrm{d}$ to compute $\mathrm{d}f$:

sage: from sage.manifolds.utilities import xder
sage: xder(f) == f.exterior_derivative()
True

A difference regards the parents: in the CoordinatePatch version, the 2-form f and the 1-form g have the same parent, which is the graded algebra $\Omega(U)$ of all differential forms defined on $U$, and declared as F = DifferentialForms(U) at the beginning of the session:

sage: f.parent()
Algebra of differential forms in the variables x, y, z
sage: f.parent() is F
True
sage: g.parent() is F
True

In the manifold case, the parent of f is the set $\Omega^2(U)$ of 2-forms on $U$, which is considered as a free module of rank 3 on the algebra $C^\infty(U)$ of scalar fields on $U$, while the parent of g is the set $\Omega^1(U)$ of 1-forms on $U$, which is considered as another free module of rank 3 on $C^\infty(U)$:

sage: f.parent()
Free module Omega^2(U) of 2-forms on the 3-dimensional differentiable manifold U
sage: f.parent().base_ring()
Algebra of differentiable scalar fields on the 3-dimensional differentiable manifold U
sage: f.parent().rank()
3
sage: g.parent()
Free module Omega^1(U) of 1-forms on the 3-dimensional differentiable manifold U
sage: g.parent().rank()
3

2. Examples of functionalities avalaible only in the manifold version

The capability to access directly to the coordinate basis 1-forms:

sage: X.coframe()
Coordinate coframe (U, (dx,dy,dz))
sage: dx = X.coframe()[0]
sage: dy = X.coframe()[1]
sage: a = sin(z)*dx.wedge(dy)
sage: a.display()
sin(z) dx/\dy

The interior product with a vector field:

sage: v = U.vector_field('v')
sage: v[:] = (-y, z, x^2)
sage: v.interior_product(f)
1-form i_v f on the 3-dimensional differentiable manifold U
sage: v.interior_product(f).display()
i_v f = -x*z*sin(z) dx + (-x^2*y*z - x*y*sin(z)) dy + y*z^2 dz

The Lie derivative with respect to a vector field:

sage: f.lie_derivative(v)
2-form on the 3-dimensional differentiable manifold U
sage: f.lie_derivative(v).display()
(x^3*cos(z) - 2*x*y*z - y*sin(z)) dx/\dy + x*sin(z) dx/\dz + (x^2*y + z^2) dy/\dz

As an illustration, we may check that Cartan's identity $\mathcal{L}_v f = \mathrm{d}(\iota_v f) + \iota_v \mathrm{d} f $ holds:

sage: f.lie_derivative(v) == (v.interior_product(f)).exterior_derivative() + \
....:                        v.interior_product(f.exterior_derivative())
True

Computing the Hodge dual with respect to a given metric:

sage: h = U.metric('h')
sage: h[0,0] = 1+y^2
sage: h[1,1] = 1+z^2
sage: h[2,2] = 1+x^2
sage: h.display()
h = (y^2 + 1) dx*dx + (z^2 + 1) dy*dy + (x^2 + 1) dz*dz
sage: f.hodge_dual(h)
1-form *f on the 3-dimensional differentiable manifold U
sage: f.hodge_dual(h).display()
*f = sqrt(y^2 + 1)*y*z/(sqrt(x^2 + 1)*sqrt(z^2 + 1)) dx + sqrt(x^2 + 1)*x*sin(z)/(sqrt(y^2 + 1)*sqrt(z^2 + 1)) dz

Computing new components under a change of coordinates:

sage: X2.<u,v,w> = U.chart()
sage: X_to_X2 = X.transition_map(X2, [y+z, z+x, x+y])
sage: X_to_X2.inverse()
Change of coordinates from Chart (U, (u, v, w)) to Chart (U, (x, y, z))
sage: g.display()  # the default for g.display(X.frame(), X)
g = y^2 dx - z dy + (2*x - y) dz
sage: g.display(X2.frame(), X2)
g = (-1/8*u^2 + 1/4*(u + 2)*v - 1/8*v^2 - 1/4*(u - v - 2)*w - 1/8*w^2 - u) du + (1/8*u^2 - 1/4*(u - 4)*v + 1/8*v^2 + 1/4*(u - v)*w + 1/8*w^2 - 1/2*u) dv + (1/8*u^2 - 1/4*(u + 4)*v + 1/8*v^2 + 1/4*(u - v)*w + 1/8*w^2 + 1/2*u) dw

Using the function display_comp, which is more convenient for lengthy expressions:

sage: g.display_comp()   # the default for g.display_comp(X.frame(), X)
g_x = y^2 
g_y = -z 
g_z = 2*x - y 
sage: g.display_comp(X2.frame(), X2)
g_u = -1/8*u^2 + 1/4*(u + 2)*v - 1/8*v^2 - 1/4*(u - v - 2)*w - 1/8*w^2 - u 
g_v = 1/8*u^2 - 1/4*(u - 4)*v + 1/8*v^2 + 1/4*(u - v)*w + 1/8*w^2 - 1/2*u 
g_w = 1/8*u^2 - 1/4*(u + 4)*v + 1/8*v^2 + 1/4*(u - v)*w + 1/8*w^2 + 1/2*u
edit flag offensive delete link more

Comments

1

I've opened the ticket #24444 to deprecate the CoordinatePatch way.

eric_g gravatar imageeric_g ( 2017-12-29 17:23:43 +0100 )edit

Eric, thank you very much for a thorough explanation!

However I have an error on the implementation. I used two different sessions for the two packages.

I'm using SageMath version 8.0, Release Date: 2017-07-21 on Windows Native.

In the manifold session, when I get to "v.interior_product(f)" I get a traceback that ends with

AttributeError: 'VectorFieldFreeModule_with_category.element_class' object has no attribute 'interior_product'

What could be the problem?

Thanks again

danielvolinski gravatar imagedanielvolinski ( 2017-12-29 18:29:40 +0100 )edit

@danielvolinski: actually the method interior_product has been introduced in SageMath 8.1. So you have two possibilities: either upgrade to SageMath 8.1 or use the method contract to perform the contraction: v.contract(f) yields the same result as v.interior_product(f); see v.contract? for more details.

eric_g gravatar imageeric_g ( 2017-12-29 21:24:23 +0100 )edit

Eric,

I installed SageMath 8.1 and now it works fine. I get the same as you do.

However I calculated the Hodge dual with respect to a given metric as you do with Maxima and I get something different: in latex:

$\frac{\mathit{dz}\,z\,\sin{(z)}}{2y}+\frac{\mathit{dx}\,x}{2}$

Please advice.

Daniel

danielvolinski gravatar imagedanielvolinski ( 2017-12-31 13:28:52 +0100 )edit

Maybe this depends on the definition. The Hodge dual computed by SageMath is $*f_i = \frac{1}{2} f_{jk} \epsilon^{jk}_{\ \, i}$ (cf. the documentation), where $\epsilon^{jk}_{\ \, i} = h^{jm} h^{kn} \epsilon_{mnk}$, with $\epsilon_{mnk}$ being the Levi-Civita tensor associated with $h$: $\epsilon_{mnk} = \sqrt{\det\, h}\, [m,n,k]$. The square roots in the result arise from $\sqrt{\det\, h}$.

eric_g gravatar imageeric_g ( 2018-01-03 15:38:19 +0100 )edit

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: 2017-12-29 00:17:57 +0100

Seen: 919 times

Last updated: Dec 29 '17