Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Jupyter notebook SM_sphere_S2.ipynb

Views: 148
Kernel: SageMath 7.4

Sphere S2\mathbb{S}^2

This worksheet demonstrates a few capabilities of SageManifolds (version 0.9.1) on the example of the 2-dimensional sphere.

Click here to download the worksheet file (ipynb format). To run it, you must start SageMath with the Jupyter notebook, via the command sage -n jupyter

First we set up the notebook to display mathematical objects using LaTeX formatting:

%display latex

We also define a viewer for 3D plots (use 'jmol' for interactive 3D graphics):

viewer3D = 'tachyon' # must be 'jmol', 'tachyon' or None (default)

S2\mathbb{S}^2 as a 2-dimensional differentiable manifold

We start by declaring S2\mathbb{S}^2 as a differentiable manifold of dimension 2 over R\mathbb{R}:

S2 = Manifold(2, 'S^2', latex_name=r'\mathbb{S}^2', start_index=1)

The first argument, 2, is the dimension of the manifold, while the second argument is the symbol used to label the manifold.

The argument start_index sets the index range to be used on the manifold for labelling components w.r.t. a basis or a frame: start_index=1 corresponds to {1,2}\{1,2\}; the default value is start_index=0 and yields to {0,1}\{0,1\}.

print(S2)
2-dimensional differentiable manifold S^2
S2

The manifold is a Parent object:

isinstance(S2, Parent)

in the category of smooth manifolds over R\mathbb{R}:

S2.category()

Coordinate charts on S2\mathbb{S}^2

The sphere cannot be covered by a single chart. At least two charts are necessary, for instance the charts associated with the stereographic projections from the North pole and the South pole respectively. Let us introduce the open subsets covered by these two charts: U:=S2{N}, U := \mathbb{S}^2\setminus\{N\},   V:=S2{S}, V := \mathbb{S}^2\setminus\{S\}, where NN is a point of S2\mathbb{S}^2, which we shall call the North pole, and SS is the point of UU of stereographic coordinates (0,0)(0,0), which we call the South pole:

U = S2.open_subset('U') ; print(U)
Open subset U of the 2-dimensional differentiable manifold S^2
V = S2.open_subset('V') ; print(V)
Open subset V of the 2-dimensional differentiable manifold S^2

We declare that S2=UV\mathbb{S}^2 = U \cup V:

S2.declare_union(U, V)

Then we declare the stereographic chart on UU, denoting by (x,y)(x,y) the coordinates resulting from the stereographic projection from the North pole:

stereoN.<x,y> = U.chart()
stereoN
y is stereoN[2]

Similarly, we introduce on VV the coordinates (x,y)(x',y') corresponding to the stereographic projection from the South pole:

stereoS.<xp,yp> = V.chart(r"xp:x' yp:y'")
stereoS

At this stage, the user's atlas on the manifold has two charts:

S2.atlas()

We have to specify the transition map between the charts 'stereoN' = (U,(x,y))(U,(x,y)) and 'stereoS' = (V,(x,y))(V,(x',y')); it is given by the standard inversion formulas:

stereoN_to_S = stereoN.transition_map(stereoS, (x/(x^2+y^2), y/(x^2+y^2)), intersection_name='W', restrictions1= x^2+y^2!=0, restrictions2= xp^2+xp^2!=0) stereoN_to_S.display()

In the above declaration, 'W' is the name given to the chart-overlap subset: W:=UVW := U\cap V, the condition x2+y20x^2+y^2 \not=0  defines WW as a subset of UU, and the condition x2+y20x'^2+y'^2\not=0 defines WW as a subset of VV.

The inverse coordinate transformation is computed by means of the method inverse():

stereoS_to_N = stereoN_to_S.inverse() stereoS_to_N.display()

In the present case, the situation is of course perfectly symmetric regarding the coordinates (x,y)(x,y) and (x,y)(x',y').

At this stage, the user's atlas has four charts:

S2.atlas()

Let us store W=UVW = U\cap V into a Python variable for future use:

W = U.intersection(V)

Similarly we store the charts (W,(x,y))(W,(x,y)) (the restriction of  (U,(x,y))(U,(x,y)) to WW) and (W,(x,y))(W,(x',y')) (the restriction of (V,(x,y))(V,(x',y')) to WW) into Python variables:

stereoN_W = stereoN.restrict(W) stereoN_W
stereoS_W = stereoS.restrict(W) stereoS_W

We may plot the chart (W,(x,y))(W, (x',y')) in terms of itself, as a grid:

stereoS_W.plot()
Image in a Jupyter notebook

More interestingly, let us plot the stereographic chart (x,y)(x',y') in terms of the stereographic chart (x,y)(x,y) on the domain WW where both systems overlap (we split the plot in four parts to avoid the singularity at (x,y)=(0,0)(x',y')=(0,0)):

graphSN1 = stereoS_W.plot(stereoN, ranges={xp:[-6,-0.02], yp:[-6,-0.02]}) graphSN2 = stereoS_W.plot(stereoN, ranges={xp:[-6,-0.02], yp:[0.02,6]}) graphSN3 = stereoS_W.plot(stereoN, ranges={xp:[0.02,6], yp:[-6,-0.02]}) graphSN4 = stereoS_W.plot(stereoN, ranges={xp:[0.02,6], yp:[0.02,6]}) show(graphSN1+graphSN2+graphSN3+graphSN4, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5)
Image in a Jupyter notebook

Spherical coordinates

The standard spherical (or polar) coordinates (θ,ϕ)(\theta,\phi) are defined on the open domain AWS2A\subset W \subset \mathbb{S}^2 that is the complement of the "origin meridian"; since the latter is the half-circle defined by y=0y=0 and x0x\geq 0, we declare:

A = W.open_subset('A', coord_def={stereoN_W: (y!=0, x<0), stereoS_W: (yp!=0, xp<0)}) print(A)
Open subset A of the 2-dimensional differentiable manifold S^2

The restriction of the stereographic chart from the North pole to AA is

stereoN_A = stereoN_W.restrict(A) stereoN_A

We then declare the chart (A,(θ,ϕ))(A,(\theta,\phi)) by specifying the intervals (0,π)(0,\pi) and (0,2π)(0,2\pi) spanned by respectively θ\theta and ϕ\phi:

spher.<th,ph> = A.chart(r'th:(0,pi):\theta ph:(0,2*pi):\phi') ; spher

The specification of the spherical coordinates is completed by providing the transition map with the stereographic chart (A,(x,y))(A,(x,y)):

spher_to_stereoN = spher.transition_map(stereoN_A, (sin(th)*cos(ph)/(1-cos(th)), sin(th)*sin(ph)/(1-cos(th))) ) spher_to_stereoN.display()

We also provide the inverse transition map:

spher_to_stereoN.set_inverse(2*atan(1/sqrt(x^2+y^2)), atan2(-y,-x)+pi, check=True)
spher_to_stereoN.inverse().display()

The transition map (A,(θ,ϕ))(A,(x,y))(A,(\theta,\phi))\rightarrow (A,(x',y')) is obtained by combining the transition maps (A,(θ,ϕ))(A,(x,y))(A,(\theta,\phi))\rightarrow (A,(x,y)) and (A,(x,y))(A,(x,y))(A,(x,y))\rightarrow (A,(x',y')):

stereoN_to_S_A = stereoN_to_S.restrict(A) spher_to_stereoS = stereoN_to_S_A * spher_to_stereoN spher_to_stereoS.display()

Similarly, the transition map (A,(x,y))(A,(θ,ϕ))(A,(x',y'))\rightarrow (A,(\theta,\phi)) is obtained by combining the transition maps (A,(x,y))(A,(x,y))(A,(x',y'))\rightarrow (A,(x,y)) and (A,(x,y))(A,(θ,ϕ))(A,(x,y))\rightarrow (A,(\theta,\phi)):

stereoS_to_N_A = stereoN_to_S.inverse().restrict(A) stereoS_to_spher = spher_to_stereoN.inverse() * stereoS_to_N_A stereoS_to_spher.display()

The user atlas of S2\mathbb{S}^2 is now

S2.atlas()

Let us draw the grid of spherical coordinates (θ,ϕ)(\theta,\phi) in terms of stereographic coordinates from the North pole (x,y)(x,y):

spher.plot(stereoN, nb_values=15, ranges={th: (pi/8,pi)})
Image in a Jupyter notebook

Conversly, we may represent the grid of the stereographic coordinates (x,y)(x,y) restricted to AA in terms of the spherical coordinates (θ,ϕ)(\theta,\phi). We limit ourselves to one quarter (cf. the argument ranges):

stereoN_A.plot(spher, ranges={x: (0.01,8), y: (0.01,8)}, nb_values=20, plot_points=200)
Image in a Jupyter notebook

Points on S2\mathbb{S}^2

We declare the North pole (resp. the South pole) as the point of coordinates (0,0)(0,0) in the chart (V,(x,y))(V,(x',y')) (resp. in the chart (U,(x,y))(U,(x,y))):

N = V.point((0,0), chart=stereoS, name='N') ; print(N) S = U.point((0,0), chart=stereoN, name='S') ; print(S)
Point N on the 2-dimensional differentiable manifold S^2 Point S on the 2-dimensional differentiable manifold S^2

Since points are Sage Element's, the corresponding (facade) Parent being the manifold subsets, an equivalent writing of the above declarations is

N = V((0,0), chart=stereoS, name='N') ; print(N) S = U((0,0), chart=stereoN, name='S') ; print(S)
Point N on the 2-dimensional differentiable manifold S^2 Point S on the 2-dimensional differentiable manifold S^2

Moreover, since stereoS in the default chart on VV and stereoN is the default one on UU, their mentions can be omitted, so that the above can be shortened to

N = V((0,0), name='N') ; print(N) S = U((0,0), name='S') ; print(S)
Point N on the 2-dimensional differentiable manifold S^2 Point S on the 2-dimensional differentiable manifold S^2
N.parent()
S.parent()

We have of course

N in V
N in S2
N in U
N in A

Let us introduce some point at the equator:

E = S2((0,1), chart=stereoN, name='E')

The point EE is in the open subset AA:

E in A

We may then ask for its spherical coordinates (θ,ϕ)(\theta,\phi):

E.coord(spher)

which is not possible for the point NN:

try: N.coord(spher) except ValueError as exc: print('Error: ' + str(exc))
Error: the point does not belong to the domain of Chart (A, (th, ph))

Mappings between manifolds: the embedding of S2\mathbb{S}^2 into R3\mathbb{R}^3

Let us first declare R3\mathbb{R}^3 as a 3-dimensional manifold covered by a single chart (the so-called Cartesian coordinates):

R3 = Manifold(3, 'R^3', r'\mathbb{R}^3', start_index=1) cart.<X,Y,Z> = R3.chart() ; cart

The embedding of the sphere is defined as a differential mapping Φ:S2R3\Phi: \mathbb{S}^2 \rightarrow \mathbb{R}^3:

Phi = S2.diff_map(R3, {(stereoN, cart): [2*x/(1+x^2+y^2), 2*y/(1+x^2+y^2), (x^2+y^2-1)/(1+x^2+y^2)], (stereoS, cart): [2*xp/(1+xp^2+yp^2), 2*yp/(1+xp^2+yp^2), (1-xp^2-yp^2)/(1+xp^2+yp^2)]}, name='Phi', latex_name=r'\Phi')
Phi.display()
Phi.parent()
print(Phi.parent())
Set of Morphisms from 2-dimensional differentiable manifold S^2 to 3-dimensional differentiable manifold R^3 in Category of smooth manifolds over Real Field with 53 bits of precision
Phi.parent() is Hom(S2, R3)

Φ\Phi maps points of S2\mathbb{S}^2 to points of R3\mathbb{R}^3:

N1 = Phi(N) ; print(N1) ; N1 ; N1.coord()
Point Phi(N) on the 3-dimensional differentiable manifold R^3
S1 = Phi(S) ; print(S1) ; S1 ; S1.coord()
Point Phi(S) on the 3-dimensional differentiable manifold R^3
E1 = Phi(E) ; print(E1) ; E1 ; E1.coord()
Point Phi(E) on the 3-dimensional differentiable manifold R^3

Φ\Phi has been defined in terms of the stereographic charts (U,(x,y))(U,(x,y)) and (V,(x,y))(V,(x',y')), but we may ask its expression in terms of spherical coordinates. The latter is then computed by means of the transition map (A,(x,y))(A,(θ,ϕ))(A,(x,y))\rightarrow (A,(\theta,\phi)):

Phi.expr(stereoN_A, cart)
Phi.expr(spher, cart)
Phi.display(spher, cart)

Let us use Φ\Phi to draw the grid of spherical coordinates (θ,ϕ)(\theta,\phi) in terms of the Cartesian coordinates (X,Y,Z)(X,Y,Z) of R3\mathbb{R}^3:

graph_spher = spher.plot(chart=cart, mapping=Phi, nb_values=11, color='blue') show(graph_spher, viewer=viewer3D)
Image in a Jupyter notebook

For future use, let us store a version without any label on the axes:

graph_spher = spher.plot(chart=cart, mapping=Phi, nb_values=11, color='blue', label_axes=False)

We may also use the embedding Φ\Phi to display the stereographic coordinate grid in terms of the Cartesian coordinates in R3\mathbb{R}^3. First for the stereographic coordinates from the North pole:

graph_stereoN = stereoN.plot(chart=cart, mapping=Phi, nb_values=25) show(graph_stereoN, viewer=viewer3D)
Image in a Jupyter notebook

and then have a view with the stereographic coordinates from the South pole superposed (in green):

graph_stereoS = stereoS.plot(chart=cart, mapping=Phi, nb_values=25, color='green') show(graph_stereoN + graph_stereoS, viewer=viewer3D)
Image in a Jupyter notebook

We may also add the two poles to the graphic:

pointN = N.plot(chart=cart, mapping=Phi, color='red', label_offset=0.05) pointS = S.plot(chart=cart, mapping=Phi, color='green', label_offset=0.05) show(graph_stereoN + graph_stereoS + pointN + pointS, viewer=viewer3D)
Image in a Jupyter notebook

Tangent spaces

The tangent space to the manifold S2\mathbb{S}^2 at the point NN is

T_N = S2.tangent_space(N) print(T_N) ; T_N
Tangent space at Point N on the 2-dimensional differentiable manifold S^2

TNS2T_N \mathbb{S}^2 is a vector space over R\mathbb{R} (represented here by Sage's symbolic ring SR):

T_N.category()

Its dimension equals the manifold's dimension:

dim(T_N)
dim(T_N) == dim(S2)

TNS2T_N \mathbb{S}^2 is endowed with a basis inherited from the coordinate frame defined around NN, namely the frame associated with the chart (V,(x,y))(V,(x',y')):

T_N.bases()

(V,(x,y))(V,(x',y')) is the only chart defined so far around the point NN. If various charts have been defined around a point, then the tangent space at this point is automatically endowed with the bases inherited from the coordinate frames associated to all these charts. For instance, for the equator point EE:

T_E = S2.tangent_space(E) print(T_E) ; T_E
Tangent space at Point E on the 2-dimensional differentiable manifold S^2
T_E.bases()
T_E.default_basis()

An element of TES2T_E\mathbb{S}^2:

v = T_E((-3, 2), name='v') print(v)
Tangent vector v at Point E on the 2-dimensional differentiable manifold S^2
v in T_E
v.parent()
v.display()
v.display(T_E.bases()[1])
v.display(T_E.bases()[2])

Differential of a smooth mapping

The differential of the mapping Φ\Phi at the point EE is

dPhi_E = Phi.differential(E) print(dPhi_E) ; dPhi_E
Generic morphism: From: Tangent space at Point E on the 2-dimensional differentiable manifold S^2 To: Tangent space at Point Phi(E) on the 3-dimensional differentiable manifold R^3
dPhi_E.domain()
dPhi_E.codomain()
dPhi_E.parent()

The image by dΦE\mathrm{d}\Phi_E of the vector vTES2v\in T_E\mathbb{S}^2 introduced above is

dPhi_E(v)
print(dPhi_E(v))
Tangent vector dPhi_E(v) at Point Phi(E) on the 3-dimensional differentiable manifold R^3
dPhi_E(v) in R3.tangent_space(Phi(E))
dPhi_E(v).display()

Algebra of scalar fields

The set C(S2)C^\infty(\mathbb{S}^2) of all smooth functions S2R\mathbb{S}^2\rightarrow \mathbb{R} has naturally the structure of a commutative algebra over R\mathbb{R}. C(S2)C^\infty(\mathbb{S}^2) is obtained via the method scalar_field_algebra() applied to the manifold S2\mathbb{S}^2:

CS = S2.scalar_field_algebra() ; CS

Since the algebra internal product is the pointwise multiplication, it is clearly commutative, so that C(S2)C^\infty(\mathbb{S}^2) belongs to Sage's category of commutative algebras:

CS.category()

The base ring of the algebra C(S2)C^\infty(\mathbb{S}^2) is the field R\mathbb{R}, which is represented here by Sage's Symbolic Ring (SR):

CS.base_ring()

Elements of C(S2)C^\infty(\mathbb{S}^2) are of course (smooth) scalar fields:

print(CS.an_element())
Scalar field on the 2-dimensional differentiable manifold S^2

This example element is the constant scalar field that takes the value 2:

CS.an_element().display()

A specific element is the zero one:

f = CS.zero() print(f)
Scalar field zero on the 2-dimensional differentiable manifold S^2

Scalar fields map points of S2\mathbb{S}^2 to real numbers:

f(N), f(E), f(S)
f.display()

Another specific element is the algebra unit element, i.e. the constant scalar field 1:

f = CS.one() print(f)
Scalar field 1 on the 2-dimensional differentiable manifold S^2
f(N), f(E), f(S)
f.display()

Let us define a scalar field by its coordinate expression in the two stereographic charts:

f = CS({stereoN: pi - 2*atan(x^2+y^2), stereoS: 2*atan(xp^2+yp^2)}) f.display()

Instead of using CS() (i.e. the Parent __call__ function), we may invoke the scalar_field method on the manifold to create ff; this allows to pass the name of the scalar field:

f = S2.scalar_field({stereoN: pi - 2*atan(x^2+y^2), stereoS: 2*atan(xp^2+yp^2)}, name='f') f.display()
f.parent()

Internally, the various coordinate expressions of the scalar field are stored in the dictionary _express, whose keys are the charts:

f._express

The expression in a specific chart is recovered by passing the chart as the argument of the method display():

f.display(stereoS)

Scalar fields map the manifold's points to real numbers:

f(N)
f(E)
f(S)

We may define the restrictions of ff to the open subsets UU and VV:

fU = f.restrict(U) fU.display()
fV = f.restrict(V) fV.display()
fU(E), fU(S)
fU.parent()
fV.parent()
CU = U.scalar_field_algebra() fU.parent() is CU

A scalar field on S2\mathbb{S}^2 can be coerced to a scalar field on UU, the coercion being simply the restriction:

CU.has_coerce_map_from(CS)
fU == CU(f)

The arithmetic of scalar fields:

g = f*f - 2*f g.display()

Module of vector fields

The set X(S2)\mathcal{X}(\mathbb{S}^2) of all smooth vector fields on S2\mathbb{S}^2 is a module over the algebra (ring) C(S2)C^\infty(\mathbb{S}^2). It is obtained by the method vector_field_module():

XS = S2.vector_field_module() XS
print(XS)
Module X(S^2) of vector fields on the 2-dimensional differentiable manifold S^2
XS.base_ring()
XS.category()

X(S2)\mathcal{X}(\mathbb{S}^2) is not a free module:

isinstance(XS, FiniteRankFreeModule)

because S2\mathbb{S}^2 is not a parallelizable manifold:

S2.is_manifestly_parallelizable()

On the contrary, the set X(U)\mathcal{X}(U) of smooth vector fields on UU is a free module:

XU = U.vector_field_module() isinstance(XU, FiniteRankFreeModule)

because UU is parallelizable:

U.is_manifestly_parallelizable()

Due to the introduction of the stereographic coordinates (x,y)(x,y) on UU, a basis has already been defined on the free module X(U)\mathcal{X}(U), namely the coordinate basis (/x,/y)(\partial/\partial x, \partial/\partial y):

XU.print_bases()
Bases defined on the Free module X(U) of vector fields on the Open subset U of the 2-dimensional differentiable manifold S^2: - (U, (d/dx,d/dy)) (default basis)
XU.default_basis()

Similarly

XV = V.vector_field_module() XV.default_basis()
eU = XU.default_basis() eV = XV.default_basis()

From the point of view of the open set UU, eU is also the default vector frame:

eU is U.default_frame()

It is also the default vector frame on S2\mathbb{S}^2 (although not defined on the whole S2\mathbb{S}^2), for it is the first vector frame defined on an open subset of S2\mathbb{S}^2:

eU is S2.default_frame()
eV is V.default_frame()

Let us introduce a vector field on S2\mathbb{S}^2:

v = S2.vector_field(name='v') v[eU,:] = [1, -2] v.display(eU)
v.parent()
stereoSW = stereoS.restrict(W) eSW = stereoSW.frame() eSW
vW = v.restrict(W) vW.display()
vW.parent()
print(vW.parent())
Free module X(W) of vector fields on the Open subset W of the 2-dimensional differentiable manifold S^2
vW.display(eSW)
vW.display(eSW, stereoSW)

We extend the definition of vv to VV thanks to the above expression:

v.add_comp_by_continuation(eV, W, chart=stereoS)
v.display(eV)

At this stage, the vector field vv is defined on the whole manifold S2\mathbb{S}^2; it has expressions in each of the two frames eU and eV which cover S2\mathbb{S}^2:

print(v) v.display(eU)
Vector field v on the 2-dimensional differentiable manifold S^2
v.display(eV)

According to the hairy ball theorem, vv has to vanish somewhere. This occurs at the North pole:

vN = v.at(N) print(v)
Vector field v on the 2-dimensional differentiable manifold S^2
vN.display()

vNv|_N is the zero vector of the tangent vector space TNS2T_N\mathbb{S}^2:

vN.parent()
vN.parent() is S2.tangent_space(N)
vN == S2.tangent_space(N).zero()

On the contrary, vv is non-zero at the South pole:

vS = v.at(S) print(v)
Vector field v on the 2-dimensional differentiable manifold S^2
vS.display()
vS.parent()
vS.parent() is S2.tangent_space(S)
vS != S2.tangent_space(S).zero()

Let us plot the vector field vv is terms of the stereographic chart (U,(x,y))(U,(x,y)), with the South pole SS superposed:

v.plot(chart=stereoN, chart_domain=stereoN, max_range=4, nb_values=5, scale=0.5, aspect_ratio=1) + \ S.plot(stereoN, size=30, label_offset=0.2)
Image in a Jupyter notebook

The vector field appears homogeneous because its components w.r.t. the frame (x,y)\left(\frac{\partial}{\partial x}, \frac{\partial}{\partial y}\right) are constant:

v.display(stereoN.frame())

On the contrary, once drawn in terms of the stereographic chart (V,(x,y))(V, (x',y')), vv does no longer appears homogeneous:

v.plot(chart=stereoS, chart_domain=stereoS, max_range=4, scale=0.02, aspect_ratio=1) + \ N.plot(chart=stereoS, size=30, label_offset=0.2)
Image in a Jupyter notebook

Finally, a 3D view of the vector field vv is obtained via the embedding Φ\Phi:

graph_v = v.plot(chart=cart, mapping=Phi, chart_domain=spher, nb_values=11, scale=0.2) show(graph_spher + graph_v, viewer=viewer3D)
Image in a Jupyter notebook

Similarly, let us draw the first vector field of the stereographic frame from the North pole, namely x\frac{\partial}{\partial x}:

ex = stereoN.frame()[1] ex
graph_ex = ex.plot(chart=cart, mapping=Phi, chart_domain=spher, nb_values=11, scale=0.4, width=1) show(graph_spher + graph_ex, viewer=viewer3D)
Image in a Jupyter notebook

For the second vector field of the stereographic frame from the North pole, namely y\frac{\partial}{\partial y}, we get

ey = stereoN.frame()[2] ey
graph_ey = ey.plot(chart=cart, mapping=Phi, chart_domain=spher, nb_values=11, scale=0.4, width=1, color='red', label_axes=False) show(graph_spher + graph_ey, viewer=viewer3D)
Image in a Jupyter notebook

We may superpose the two graphs, to get a 3D view of the frame associated with the stereographic coordinates from the North pole:

show(graph_spher + graph_ex + graph_ey + N.plot(cart, mapping=Phi, label_offset=0.05, size=5) + S.plot(cart, mapping=Phi, label_offset=0.05, size=5) + sphere(opacity=0.5), viewer='tachyon', figsize=10)
Image in a Jupyter notebook

Vector fields acting on scalar fields

vv and ff are both fields defined on the whole sphere (respectively a vector field and a scalar field). By the very definition of a vector field, vv acts on ff:

vf = v(f) print(vf) vf.display()
Scalar field v(f) on the 2-dimensional differentiable manifold S^2

Values of v(f)v(f) at the North pole, at the equator point EE and at the South pole:

vf(N)
vf(E)
vf(S)

1-forms

A 1-form on S2\mathbb{S}^2 is a field of linear forms on the tangent spaces. For instance it can the differential of a scalar field:

df = f.differential() ; print(df)
1-form df on the 2-dimensional differentiable manifold S^2
df.display()
print(df.parent())
Module /\^1(S^2) of 1-forms on the 2-dimensional differentiable manifold S^2
df.parent()

The 1-form acting on a vector field:

print(df(v)) ; df(v).display()
Scalar field df(v) on the 2-dimensional differentiable manifold S^2

Let us check the identity df(v)=v(f)\mathrm{d}f(v) = v(f):

df(v) == v(f)

Similarly, we have Lvf=v(f)\mathcal{L}_v f = v(f):

f.lie_der(v) == v(f)

Curves in S2\mathbb{S}^2

In order to define curves in S2\mathbb{S}^2, we first introduce the field of real numbers R\mathbb{R} as a 1-dimensional smooth manifold with a canonical coordinate chart:

R.<t> = RealLine() ; print(R)
Real number line R
R.category()
dim(R)
R.atlas()

Let us define a loxodrome of the sphere in terms of its parametric equation with respect to the chart spher = (A,(θ,ϕ))(A,(\theta,\phi))

c = S2.curve({spher: [2*atan(exp(-t/10)), t]}, (t, -oo, +oo), name='c')

Curves in S2\mathbb{S}^2 are considered as morphisms from the manifold R\mathbb{R} to the manifold S2\mathbb{S}^2:

c.parent()
c.display()

The curve cc can be plotted in terms of stereographic coordinates (x,y)(x,y):

c.plot(chart=stereoN, aspect_ratio=1)
Image in a Jupyter notebook

We recover the well-known fact that the graph of a loxodrome in terms of stereographic coordinates is a logarithmic spiral.

Thanks to the embedding Φ\Phi, we may also plot cc in terms of the Cartesian coordinates of R3\mathbb{R}^3:

graph_c = c.plot(mapping=Phi, max_range=40, plot_points=200, thickness=2) show(graph_spher + graph_c, viewer=viewer3D)
Image in a Jupyter notebook

The tangent vector field (or velocity vector) to the curve cc is

vc = c.tangent_vector_field() vc

cc' is a vector field along R\mathbb{R} taking its values in tangent spaces to S2\mathbb{S}^2:

print(vc)
Vector field c' along the Real number line R with values on the 2-dimensional differentiable manifold S^2

The set of vector fields along R\mathbb{R} taking their values on S2\mathbb{S}^2 via the differential mapping c:RS2c: \mathbb{R} \rightarrow \mathbb{S}^2 is denoted by X(R,c)\mathcal{X}(\mathbb{R},c); it is a module over the algebra C(R)C^\infty(\mathbb{R}):

vc.parent()
vc.parent().category()
vc.parent().base_ring()

A coordinate view of cc':

vc.display()

Let us plot the vector field cc' in terms of the stereographic chart (U,(x,y))(U,(x,y)):

show(vc.plot(chart=stereoN, nb_values=30, scale=0.5, color='red') + c.plot(chart=stereoN), aspect_ratio=1)
Image in a Jupyter notebook

A 3D view of cc' is obtained via the embedding Φ\Phi:

graph_vc = vc.plot(chart=cart, mapping=Phi, ranges={t: (-20, 20)}, nb_values=30, scale=0.5, color='red', label_axes=False) show(graph_spher + graph_c + graph_vc , viewer=viewer3D)
Image in a Jupyter notebook

Riemannian metric on S2\mathbb{S}^2

The standard metric on S2\mathbb{S}^2 is that induced by the Euclidean metric of R3\mathbb{R}^3. Let us start by defining the latter:

h = R3.metric('h') h[1,1], h[2,2], h[3, 3] = 1, 1, 1 h.display()

The metric gg on S2\mathbb{S}^2 is the pullback of hh associated with the embedding Φ\Phi:

g = S2.metric('g') g.set( Phi.pullback(h) ) print(g)
Riemannian metric g on the 2-dimensional differentiable manifold S^2

Note that we could have defined gg intrinsically, i.e. by providing its components in the two frames stereoN and stereoS, as we did for the metric hh on R3\mathbb{R}^3. Instead, we have chosen to get it as the pullback of hh, as an example of pullback associated with some differential map. 

The metric is a symmetric tensor field of type (0,2):

print(g.parent())
Module T^(0,2)(S^2) of type-(0,2) tensors fields on the 2-dimensional differentiable manifold S^2
g.tensor_type()
g.symmetries()
symmetry: (0, 1); no antisymmetry

The expression of the metric in terms of the default frame on S2\mathbb{S}^2 (stereoN):

g.display()

We may factorize the metric components:

g[1,1].factor() ; g[2,2].factor()
g.display()

A matrix view of the components of gg in the manifold's default frame:

g[:]

Display in terms of the vector frame (V,(x,y))(V, (\partial_{x'}, \partial_{y'})):

g.display(stereoS.frame())
g.display(spher.frame(), chart=spher)

The metric acts on vector field pairs, resulting in a scalar field:

print(g(v,v))
Scalar field g(v,v) on the 2-dimensional differentiable manifold S^2
g(v,v).parent()
g(v,v).display()

The Levi-Civitation connection associated with the metric gg:

nab = g.connection() print(nab) nab
Levi-Civita connection nabla_g associated with the Riemannian metric g on the 2-dimensional differentiable manifold S^2

As a test, we verify that g\nabla_g acting on gg results in zero:

nab(g).display()

The nonzero Christoffel symbols of gg (skipping those that can be deduced by symmetry on the last two indices) w.r.t. two charts:

g.christoffel_symbols_display(chart=stereoN)
g.christoffel_symbols_display(chart=spher)

g\nabla_g acting on the vector field vv:

print(nab(v))
Tensor field nabla_g(v) of type (1,1) on the 2-dimensional differentiable manifold S^2
nab(v).display(stereoN.frame())

Curvature

The Riemann tensor associated with the metric gg:

Riem = g.riemann() print(Riem) Riem.display()
Tensor field Riem(g) of type (1,3) on the 2-dimensional differentiable manifold S^2

The components of the Riemann tensor in the default frame on S2\mathbb{S}^2:

Riem.display_comp()

The components in the frame associated with spherical coordinates:

Riem.display_comp(spher.frame(), chart=spher)
print(Riem.parent())
Module T^(1,3)(S^2) of type-(1,3) tensors fields on the 2-dimensional differentiable manifold S^2
Riem.symmetries()
no symmetry; antisymmetry: (2, 3)

The Riemann tensor associated with the Euclidean metric hh on R3\mathbb{R}^3:

h.riemann().display()

The Ricci tensor and the Ricci scalar:

Ric = g.ricci() Ric.display()
R = g.ricci_scalar() R.display()

Hence we recover the fact that (S2,g)(\mathbb{S}^2,g) is a Riemannian manifold of constant positive curvature.

In dimension 2, the Riemann curvature tensor is entirely determined by the Ricci scalar RR according to

R jlki=R2(δ kigjlδ ligjk)R^i_{\ \, jlk} = \frac{R}{2} \left( \delta^i_{\ \, k} g_{jl} - \delta^i_{\ \, l} g_{jk} \right)

Let us check this formula here, under the form R jlki=Rgj[kδ l]iR^i_{\ \, jlk} = -R g_{j[k} \delta^i_{\ \, l]}:

delta = S2.tangent_identity_field() Riem == - R*(g*delta).antisymmetrize(2,3)

Similarly the relation Ric=(R/2)  g\mathrm{Ric} = (R/2)\; g must hold:

Ric == (R/2)*g

The Levi-Civita tensor associated with gg:

eps = g.volume_form() print(eps) eps.display()
2-form eps_g on the 2-dimensional differentiable manifold S^2
eps.display(spher.frame(), chart=spher)

The exterior derivative of the 2-form ϵg\epsilon_g:

print(eps.exterior_derivative())
3-form deps_g on the 2-dimensional differentiable manifold S^2

Of course, since S2\mathbb{S}^2 has dimension 2, all 3-forms vanish identically:

eps.exterior_derivative().display()

Non-holonomic frames

Up to know, all the vector frames introduced on S2\mathbb{S}^2 have been coordinate frames. Let us introduce a non-coordinate frame on the open subset AA. To ease the notations, we change first the default chart and default frame on AA to the spherical coordinate ones:

A.default_chart()
A.default_frame()
A.set_default_chart(spher) A.set_default_frame(spher.frame()) A.default_chart()
A.default_frame()

We define the new frame ee by relating it the coordinate frame (θ,ϕ)\left(\frac{\partial}{\partial\theta}, \frac{\partial}{\partial\phi}\right) via a field of tangent-space automorphisms:

a = A.automorphism_field() a[1,1], a[2,2] = 1, 1/sin(th) a.display()
a[:]
e = spher.frame().new_frame(a, 'e') print(e) ; e
Vector frame (A, (e_1,e_2))
e[1].display()
e[2].display()
A.frames()

The new frame is an orthonormal frame for the metric gg:

g(e[1],e[1]).expr()
g(e[1],e[2]).expr()
g(e[2],e[2]).expr()
g[e,:]
g.display(e)
eps.display(e)

It is non-holonomic: its structure coefficients are not identically zero:

e.structure_coef()[:]
e[2].lie_der(e[1]).display(e)

while we have of course

spher.frame().structure_coef()[:]