Ask Your Question

Revision history [back]

There are many ways to achieve what you want. For instance, let us consider a differential form $F$ of degree 1 on a 2-dimensional manifold:

sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: X.coframe()
Coordinate coframe (M, (dx,dy))
sage: dx, dy = X.coframe()[:]
sage: F = x*sin(y^2)*dx + (x-y)*dy
sage: F
1-form on the 2-dimensional differentiable manifold M
sage: F.display()
x*sin(y^2) dx + (x - y) dy

To get the coefficient of $dx$, we can use one of the following methods:

1) use F[0]

The easiest way is the square bracket operator, which gives access to components of a tensor field:

sage: F[0]
x*sin(y^2)

Note that F[0] is not a Sage symbolic expression but a higher level object: a ChartFunction:

sage: type(F[0])
<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'>

If you want a Sage symbolic expression, apply expr() on it:

sage: F[0].expr()
x*sin(y^2)
sage: type(F[0].expr())
<type 'sage.symbolic.expression.Expression'>

Actually, chart functions allow for various internal symbolic representations. The default one is Expression, but SymPy representations are also possible:

sage: F[0].expr('sympy')
x*sin(y**2)
sage: type(F[0].expr('sympy'))
<class 'sympy.core.mul.Mul'>

2) use F[[0]]

The double square bracket operator returns a scalar field:

sage: F[[0]]
Scalar field on the 2-dimensional differentiable manifold M
sage: F[[0]].display()
M --> R
(x, y) |--> x*sin(y^2)

Again, if you want a Sage symbolic expression, apply expr():

sage: F[[0]].expr()
x*sin(y^2)

The chart function F[0] is actually the coordinate representation of the scalar field F[[0]] in the chart X:

sage: F[0] is F[[0]].coord_function(X)
True

3) Apply $F$ to $\frac{\partial}{\partial x}$

Being a form, $F$ sends vector fields to scalar fields. Applying it to the vector field $\partial/\partial x$, which is dual to the 1-form $dx$, we get the component of $F$ along $dx$:

sage: e_x = X.frame()[0]  # d/dx
sage: e_x
Vector field d/dx on the 2-dimensional differentiable manifold M
sage: F(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F(e_x).expr()
x*sin(y^2)

4) Apply $\frac{\partial}{\partial x}$ to $F$

By duality, we have

sage: e_x(F)
Scalar field on the 2-dimensional differentiable manifold M
sage: e_x(F).expr()
x*sin(y^2)

5) Take the interior product with $\frac{\partial}{\partial x}$

sage: F.interior_product(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F.interior_product(e_x).expr()
x*sin(y^2)

Equivalently, we may write

sage: e_x.interior_product(F).expr()
x*sin(y^2)

6) Contract with $\frac{\partial}{\partial x}$

As suggested by @FredericC:

sage: F.contract(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F.contract(e_x).expr()
x*sin(y^2)

Equivalently:

sage: e_x.contract(F).expr()
x*sin(y^2)

Note that, instead of contract(), you can use index notations (with LaTeX syntax) to perform the contraction (assuming summation on repeated indices):

sage: F['_a']*e_x['^a']
Scalar field on the 2-dimensional differentiable manifold M
sage: (F['_a']*e_x['^a']).expr()
x*sin(y^2)

There are many ways to achieve what you want. For instance, let us consider a differential form $F$ of degree 1 on a 2-dimensional manifold:

sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: X.coframe()
Coordinate coframe (M, (dx,dy))
sage: dx, dy = X.coframe()[:]
sage: F = x*sin(y^2)*dx + (x-y)*dy
sage: F
1-form on the 2-dimensional differentiable manifold M
sage: F.display()
x*sin(y^2) dx + (x - y) dy

To get the coefficient of $dx$, we can use one of the following methods:

1) use F[0]

The easiest way is the square bracket operator, which gives access to components of a tensor field:

sage: F[0]
x*sin(y^2)

Note that F[0] is not a Sage symbolic expression but a higher level object: a ChartFunction:

sage: type(F[0])
<class 'sage.manifolds.chart_func.ChartFunctionRing_with_category.element_class'>

If you want a Sage symbolic expression, apply expr() on it:

sage: F[0].expr()
x*sin(y^2)
sage: type(F[0].expr())
<type 'sage.symbolic.expression.Expression'>

Actually, chart functions allow for various internal symbolic representations. The default one is Expression, but SymPy representations are also possible:

sage: F[0].expr('sympy')
x*sin(y**2)
sage: type(F[0].expr('sympy'))
<class 'sympy.core.mul.Mul'>

2) use F[[0]]

The double square bracket operator returns a scalar field:

sage: F[[0]]
Scalar field on the 2-dimensional differentiable manifold M
sage: F[[0]].display()
M --> R
(x, y) |--> x*sin(y^2)

Again, if you want a Sage symbolic expression, apply expr():

sage: F[[0]].expr()
x*sin(y^2)

The chart function F[0] is actually the coordinate representation of the scalar field F[[0]] in the chart X:

sage: F[0] is F[[0]].coord_function(X)
True

3) Apply $F$ to $\frac{\partial}{\partial x}$

Being a form, $F$ sends vector fields to scalar fields. Applying it to the vector field $\partial/\partial x$, which is dual to the 1-form $dx$, we get the component of $F$ along $dx$:

sage: e_x = X.frame()[0]  # d/dx
sage: e_x
Vector field d/dx on the 2-dimensional differentiable manifold M
sage: F(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F(e_x).expr()
x*sin(y^2)

4) Apply $\frac{\partial}{\partial x}$ to $F$

By duality, we have

sage: e_x(F)
Scalar field on the 2-dimensional differentiable manifold M
sage: e_x(F).expr()
x*sin(y^2)

5) Take the interior product with $\frac{\partial}{\partial x}$

sage: F.interior_product(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F.interior_product(e_x).expr()
x*sin(y^2)

Equivalently, we may write

sage: e_x.interior_product(F).expr()
x*sin(y^2)

6) Contract with $\frac{\partial}{\partial x}$

As suggested by @FredericC:@FrédéricC:

sage: F.contract(e_x)
Scalar field on the 2-dimensional differentiable manifold M
sage: F.contract(e_x).expr()
x*sin(y^2)

Equivalently:

sage: e_x.contract(F).expr()
x*sin(y^2)

Note that, instead of contract(), you can use index notations (with LaTeX syntax) to perform the contraction (assuming summation on repeated indices):

sage: F['_a']*e_x['^a']
Scalar field on the 2-dimensional differentiable manifold M
sage: (F['_a']*e_x['^a']).expr()
x*sin(y^2)