#!/usr/bin/env python # coding: utf-8 # # Sphere $\mathbb{S}^2$ # # This worksheet demonstrates a few capabilities of # [SageManifolds](http://sagemanifolds.obspm.fr) (version 1.0, as included in SageMath 7.5) # on the example of the 2-dimensional sphere. # # Click [here](https://raw.githubusercontent.com/sagemanifolds/SageManifolds/master/Worksheets/v1.0/SM_sphere_S2.ipynb) to download the worksheet file (ipynb format). To run it, you must start SageMath with the Jupyter notebook, via the command `sage -n jupyter` # *NB:* a version of SageMath at least equal to 7.5 is required to run this worksheet: # In[1]: version() # First we set up the notebook to display mathematical objects using LaTeX formatting: # In[2]: get_ipython().run_line_magic('display', 'latex') # We also define a viewer for 3D plots (use `'threejs'` or `'jmol'` for interactive 3D graphics): # In[3]: viewer3D = 'threejs' # must be 'threejs', jmol', 'tachyon' or None (default) # ## $\mathbb{S}^2$ as a 2-dimensional differentiable manifold # # We start by declaring $\mathbb{S}^2$ as a differentiable manifold of dimension 2 over $\mathbb{R}$: # In[4]: 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\}$; the default value is start_index=0 and yields to $\{0,1\}$.

# In[5]: print(S2) # In[6]: S2 # The manifold is a `Parent` object: # In[7]: isinstance(S2, Parent) #

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

# In[8]: S2.category() # ### Coordinate charts on $\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 := \mathbb{S}^2\setminus\{N\}, $$  # $$ V := \mathbb{S}^2\setminus\{S\}, $$ # where $N$ is a point of $\mathbb{S}^2$, which we shall call the North pole, and $S$ is the point of $U$ of stereographic coordinates $(0,0)$, which we call the South pole: # In[9]: U = S2.open_subset('U') ; print(U) # In[10]: V = S2.open_subset('V') ; print(V) #

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

# In[11]: S2.declare_union(U, V) #

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

# In[12]: stereoN. = U.chart() # The expression `.` in the left-hand side means that the Python variables `x` and `y` are set to the two coordinates of the chart. This allows one to refer subsequently to the coordinates by their names. In the present case, the function `chart()` has no argument, which implies that the coordinate symbols will be `x` and `y` (i.e. exactly the characters appearing in the `<...>` operator) and that each coordinate range is $(-\infty,+\infty)$. As we will see below, for other cases, an argument must be passed to `chart()` to specify each coordinate symbol and range, as well as some specific LaTeX symbol. # In[13]: stereoN # The coordinates can be accessed individually, either by means of their indices in the chart ( following the convention `start_index=1` set in the manifold's definition) or by their names as Python variables: # In[14]: stereoN[1] # In[15]: y is stereoN[2] #

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

# In[16]: stereoS. = V.chart("xp:x' yp:y'") # In this case, the string argument passed to `chart` stipulates that the text-only names of the coordinates are xp and yp (same as the Python variables names defined within the `<...>` operator in the left-hand side), while their LaTeX names are $x'$ and $y'$. # In[17]: stereoS #

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

# In[18]: S2.atlas() #

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

# In[19]: 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 := U\cap V$, the condition $x^2+y^2 \not=0$  defines $W$ as a subset of $U$, and the condition $x'^2+y'^2\not=0$ defines $W$ as a subset of $V$. # # The inverse coordinate transformation is computed by means of the method `inverse()`: # In[20]: 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)$ and $(x',y')$.

#

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

# In[21]: S2.atlas() #

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

# In[22]: W = U.intersection(V) #

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

# In[23]: stereoN_W = stereoN.restrict(W) stereoN_W # In[24]: stereoS_W = stereoS.restrict(W) stereoS_W #

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

# In[25]: stereoS_W.plot() #

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

# In[26]: 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) #

Spherical coordinates

#

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

# In[27]: A = W.open_subset('A', coord_def={stereoN_W: (y!=0, x<0), stereoS_W: (yp!=0, xp<0)}) print(A) #

The restriction of the stereographic chart from the North pole to $A$ is

# In[28]: stereoN_A = stereoN_W.restrict(A) stereoN_A #

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

# In[29]: spher. = 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))$:

# In[30]: 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, asking to check that the provided formulas are indeed correct (argument `verbose=True`): # In[31]: spher_to_stereoN.set_inverse(2*atan(1/sqrt(x^2+y^2)), atan2(-y,-x)+pi, verbose=True) # The check is passed, modulo some lack of trigonometric simplifications in the first two lines. # In[32]: spher_to_stereoN.inverse().display() # The transition map $(A,(\theta,\phi))\rightarrow (A,(x',y'))$ is obtained by combining the transition maps $(A,(\theta,\phi))\rightarrow (A,(x,y))$ and $(A,(x,y))\rightarrow (A,(x',y'))$: # In[33]: 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'))\rightarrow (A,(\theta,\phi))$ is obtained by combining the transition maps $(A,(x',y'))\rightarrow (A,(x,y))$ and $(A,(x,y))\rightarrow (A,(\theta,\phi))$: # In[34]: 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 $\mathbb{S}^2$ is now

# In[35]: S2.atlas() #

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

# In[36]: spher.plot(stereoN, number_values=15, ranges={th: (pi/8,pi)}) #

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

# In[37]: stereoN_A.plot(spher, ranges={x: (0.01,8), y: (0.01,8)}, number_values=20, plot_points=200) #

Points on $\mathbb{S}^2$

#

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

# In[38]: N = V.point((0,0), chart=stereoS, name='N') ; print(N) S = U.point((0,0), chart=stereoN, name='S') ; print(S) #

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

# In[39]: N = V((0,0), chart=stereoS, name='N') ; print(N) S = U((0,0), chart=stereoN, name='S') ; print(S) #

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

# In[40]: N = V((0,0), name='N') ; print(N) S = U((0,0), name='S') ; print(S) # In[41]: N.parent() # In[42]: S.parent() #

We have of course

# In[43]: N in V # In[44]: N in S2 # In[45]: N in U # In[46]: N in A #

Let us introduce some point at the equator:

# In[47]: E = S2((0,1), chart=stereoN, name='E') #

The point $E$ is in the open subset $A$:

# In[48]: E in A #

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

# In[49]: E.coord(spher) #

which is not possible for the point $N$:

# In[50]: try: N.coord(spher) except ValueError as exc: print('Error: ' + str(exc)) #

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

#

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

# In[51]: R3 = Manifold(3, 'R^3', r'\mathbb{R}^3', start_index=1) cart. = R3.chart() ; cart #

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

# In[52]: 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') # In[53]: Phi.display() # In[54]: Phi.parent() # In[55]: print(Phi.parent()) # In[56]: Phi.parent() is Hom(S2, R3) #

$\Phi$ maps points of $\mathbb{S}^2$ to points of $\mathbb{R}^3$:

# In[57]: N1 = Phi(N) ; print(N1) ; N1 ; N1.coord() # In[58]: S1 = Phi(S) ; print(S1) ; S1 ; S1.coord() # In[59]: E1 = Phi(E) ; print(E1) ; E1 ; E1.coord() #

$\Phi$ has been defined in terms of the stereographic charts $(U,(x,y))$ and $(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))\rightarrow (A,(\theta,\phi))$:

# In[60]: Phi.expr(stereoN_A, cart) # In[61]: Phi.expr(spher, cart) # In[62]: 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)$ of $\mathbb{R}^3$:

# In[63]: graph_spher = spher.plot(chart=cart, mapping=Phi, number_values=11, color='blue', label_axes=False) show(graph_spher, viewer=viewer3D) #

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

# In[64]: graph_stereoN = stereoN.plot(chart=cart, mapping=Phi, number_values=25, label_axes=False) show(graph_stereoN, viewer=viewer3D) #

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

# In[65]: graph_stereoS = stereoS.plot(chart=cart, mapping=Phi, number_values=25, color='green', label_axes=False) show(graph_stereoN + graph_stereoS, viewer=viewer3D) #

We may also add the two poles to the graphic:

# In[66]: 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) #

Tangent spaces

#

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

# In[67]: T_N = S2.tangent_space(N) print(T_N) ; T_N #

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

# In[68]: print(T_N.category()) #

Its dimension equals the manifold's dimension:

# In[69]: dim(T_N) # In[70]: dim(T_N) == dim(S2) #

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

# In[71]: T_N.bases() #

$(V,(x',y'))$ is the only chart defined so far around the point $N$. 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 $E$:

# In[72]: T_E = S2.tangent_space(E) print(T_E) ; T_E # In[73]: T_E.bases() # In[74]: T_E.default_basis() #

An element of $T_E\mathbb{S}^2$:

# In[75]: v = T_E((-3, 2), name='v') print(v) # In[76]: v in T_E # In[77]: v.parent() # In[78]: v.display() # In[79]: v.display(T_E.bases()[1]) # In[80]: v.display(T_E.bases()[2]) #

Differential of a smooth mapping

#

The differential of the mapping $\Phi$ at the point $E$ is

# In[81]: dPhi_E = Phi.differential(E) print(dPhi_E) ; dPhi_E # In[82]: dPhi_E.domain() # In[83]: dPhi_E.codomain() # In[84]: dPhi_E.parent() #

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

# In[85]: dPhi_E(v) # In[86]: print(dPhi_E(v)) # In[87]: dPhi_E(v) in R3.tangent_space(Phi(E)) # In[88]: dPhi_E(v).display() #

Algebra of scalar fields

#

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

# In[89]: CS = S2.scalar_field_algebra() ; CS #

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

# In[90]: CS.category() #

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

# In[91]: CS.base_ring() #

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

# In[92]: print(CS.an_element()) #

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

# In[93]: CS.an_element().display() #

A specific element is the zero one:

# In[94]: f = CS.zero() print(f) #

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

# In[95]: f(N), f(E), f(S) # In[96]: f.display() #

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

# In[97]: f = CS.one() print(f) # In[98]: f(N), f(E), f(S) # In[99]: f.display() #

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

# In[100]: 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 $f$; this allows to pass the name of the scalar field:

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

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

# In[103]: f._express #

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

# In[104]: f.display(stereoS) #

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

# In[105]: f(N) # In[106]: f(E) # In[107]: f(S) #

We may define the restrictions of $f$ to the open subsets $U$ and $V$:

# In[108]: fU = f.restrict(U) fU.display() # In[109]: fV = f.restrict(V) fV.display() # In[110]: fU(E), fU(S) # In[111]: fU.parent() # In[112]: fV.parent() # In[113]: CU = U.scalar_field_algebra() fU.parent() is CU #

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

# In[114]: CU.has_coerce_map_from(CS) # In[115]: fU == CU(f) #

The arithmetic of scalar fields:

# In[116]: g = f*f - 2*f g.display() #

Module of vector fields

#

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

# In[117]: XS = S2.vector_field_module() XS # In[118]: print(XS) # In[119]: XS.base_ring() # In[120]: XS.category() #

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

# In[121]: isinstance(XS, FiniteRankFreeModule) #

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

# In[122]: S2.is_manifestly_parallelizable() #

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

# In[123]: XU = U.vector_field_module() isinstance(XU, FiniteRankFreeModule) #

because $U$ is parallelizable:

# In[124]: U.is_manifestly_parallelizable() #

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

# In[125]: XU.print_bases() # In[126]: XU.default_basis() #

Similarly

# In[127]: XV = V.vector_field_module() XV.default_basis() # In[128]: eU = XU.default_basis() eV = XV.default_basis() #

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

# In[129]: eU is U.default_frame() #

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

# In[130]: eU is S2.default_frame() # In[131]: eV is V.default_frame() #

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

# In[132]: v = S2.vector_field(name='v') v[eU,:] = [1, -2] v.display(eU) # In[133]: v.parent() # In[134]: stereoSW = stereoS.restrict(W) eSW = stereoSW.frame() eSW # In[135]: vW = v.restrict(W) vW.display() # In[136]: vW.parent() # In[137]: print(vW.parent()) # In[138]: vW.display(eSW) # In[139]: vW.display(eSW, stereoSW) #

We extend the definition of $v$ to $V$ thanks to the above expression:

# In[140]: v.add_comp_by_continuation(eV, W, chart=stereoS) # In[141]: v.display(eV) #

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

# In[142]: print(v) v.display(eU) # In[143]: v.display(eV) #

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

# In[144]: vN = v.at(N) print(v) # In[145]: vN.display() #

$v|_N$ is the zero vector of the tangent vector space $T_N\mathbb{S}^2$:

# In[146]: vN.parent() # In[147]: vN.parent() is S2.tangent_space(N) # In[148]: vN == S2.tangent_space(N).zero() #

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

# In[149]: vS = v.at(S) print(v) # In[150]: vS.display() # In[151]: vS.parent() # In[152]: vS.parent() is S2.tangent_space(S) # In[153]: vS != S2.tangent_space(S).zero() #

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

# In[154]: v.plot(chart=stereoN, chart_domain=stereoN, max_range=4, number_values=5, scale=0.5, aspect_ratio=1) + \ S.plot(stereoN, size=30, label_offset=0.2) #

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

# In[155]: v.display(stereoN.frame()) #

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

# In[156]: 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) #

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

# In[157]: graph_v = v.plot(chart=cart, mapping=Phi, chart_domain=spher, number_values=11, scale=0.2) show(graph_spher + graph_v, viewer=viewer3D) #

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

# In[158]: ex = stereoN.frame()[1] ex # In[159]: graph_ex = ex.plot(chart=cart, mapping=Phi, chart_domain=spher, number_values=11, scale=0.4, width=1, label_axes=False) show(graph_spher + graph_ex, viewer=viewer3D) #

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

# In[160]: ey = stereoN.frame()[2] ey # In[161]: graph_ey = ey.plot(chart=cart, mapping=Phi, chart_domain=spher, number_values=11, scale=0.4, width=1, color='red', label_axes=False) show(graph_spher + graph_ey, viewer=viewer3D) # We may superpose the two graphs, to get a 3D view of the vector frame associated with the stereographic coordinates from the North pole: # In[162]: graph_frame = 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) show(graph_frame + sphere(color='lightgrey', opacity=0.4), viewer=viewer3D) # The same scene rendered with Tachyon: # In[163]: show(graph_frame + sphere(opacity=0.5), viewer='tachyon', figsize=10) #

Vector fields acting on scalar fields

#

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

# In[164]: vf = v(f) print(vf) vf.display() #

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

# In[165]: vf(N) # In[166]: vf(E) # In[167]: vf(S) #

1-forms

#

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

# In[168]: df = f.differential() ; print(df) # In[169]: df.display() # In[170]: print(df.parent()) # In[171]: df.parent() #

The 1-form acting on a vector field:

# In[172]: print(df(v)) ; df(v).display() #

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

# In[173]: df(v) == v(f) #

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

# In[174]: f.lie_derivative(v) == v(f) #

Curves in $\mathbb{S}^2$

#

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

# In[175]: R. = RealLine() ; print(R) # In[176]: R.category() # In[177]: dim(R) # In[178]: R.atlas() #

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

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

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

# In[180]: c.parent() # In[181]: c.display() #

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

# In[182]: c.plot(chart=stereoN, aspect_ratio=1) #

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 $c$ in terms of the Cartesian coordinates of $\mathbb{R}^3$:

# In[183]: graph_c = c.plot(mapping=Phi, max_range=40, plot_points=200, thickness=2, label_axes=False) show(graph_spher + graph_c, viewer=viewer3D) #

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

# In[184]: vc = c.tangent_vector_field() vc #

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

# In[185]: print(vc) #

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

# In[186]: vc.parent() # In[187]: vc.parent().category() # In[188]: vc.parent().base_ring() #

A coordinate view of $c'$:

# In[189]: vc.display() #

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

# In[190]: show(vc.plot(chart=stereoN, number_values=30, scale=0.5, color='red') + c.plot(chart=stereoN), aspect_ratio=1) #

A 3D view of $c'$ is obtained via the embedding $\Phi$:

# In[191]: graph_vc = vc.plot(chart=cart, mapping=Phi, ranges={t: (-20, 20)}, number_values=30, scale=0.5, color='red', label_axes=False) show(graph_spher + graph_c + graph_vc , viewer=viewer3D) #

Riemannian metric on $\mathbb{S}^2$

#

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

# In[192]: h = R3.metric('h') h[1,1], h[2,2], h[3, 3] = 1, 1, 1 h.display() #

The metric $g$ on $\mathbb{S}^2$ is the pullback of $h$ associated with the embedding $\Phi$:

# In[193]: g = S2.metric('g') g.set( Phi.pullback(h) ) print(g) #

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

#

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

# In[194]: print(g.parent()) # In[195]: g.tensor_type() # In[196]: g.symmetries() #

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

# In[197]: g.display() #

We may factorize the metric components:

# In[198]: g[1,1].factor() ; g[2,2].factor() # In[199]: g.display() #

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

# In[200]: g[:] #

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

# In[201]: g.display(stereoS.frame()) # In[202]: g.display(spher.frame(), chart=spher) #

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

# In[203]: print(g(v,v)) # In[204]: g(v,v).parent() # In[205]: g(v,v).display() #

The Levi-Civitation connection associated with the metric $g$:

# In[206]: nab = g.connection() print(nab) nab #

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

# In[207]: nab(g).display() #

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

# In[208]: g.christoffel_symbols_display(chart=stereoN) # In[209]: g.christoffel_symbols_display(chart=spher) #

$\nabla_g$ acting on the vector field $v$:

# In[210]: print(nab(v)) # In[211]: nab(v).display(stereoN.frame()) #

Curvature

#

The Riemann tensor associated with the metric $g$:

# In[212]: Riem = g.riemann() print(Riem) Riem.display() #

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

# In[213]: Riem.display_comp() #

The components in the frame associated with spherical coordinates:

# In[214]: Riem.display_comp(spher.frame(), chart=spher) # In[215]: print(Riem.parent()) # In[216]: Riem.symmetries() #

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

# In[217]: h.riemann().display() #

The Ricci tensor and the Ricci scalar:

# In[218]: Ric = g.ricci() Ric.display() # In[219]: R = g.ricci_scalar() R.display() #

Hence we recover the fact that $(\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 $R$ according to

#

$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^i_{\ \, jlk} = -R g_{j[k} \delta^i_{\ \, l]}$:

# In[220]: delta = S2.tangent_identity_field() Riem == - R*(g*delta).antisymmetrize(2,3) #

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

# In[221]: Ric == (R/2)*g #

The Levi-Civita tensor associated with $g$:

# In[222]: eps = g.volume_form() print(eps) eps.display() # In[223]: eps.display(spher.frame(), chart=spher) #

The exterior derivative of the 2-form $\epsilon_g$:

# In[224]: print(eps.exterior_derivative()) #

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

# In[225]: eps.exterior_derivative().display() #

Non-holonomic frames

#

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

# In[226]: A.default_chart() # In[227]: A.default_frame() # In[228]: A.set_default_chart(spher) A.set_default_frame(spher.frame()) A.default_chart() # In[229]: A.default_frame() #

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

# In[230]: a = A.automorphism_field() a[1,1], a[2,2] = 1, 1/sin(th) a.display() # In[231]: a[:] # In[232]: e = spher.frame().new_frame(a, 'e') print(e) ; e # In[233]: e[1].display() # In[234]: e[2].display() # In[235]: A.frames() #

The new frame is an orthonormal frame for the metric $g$:

# In[236]: g(e[1],e[1]).expr() # In[237]: g(e[1],e[2]).expr() # In[238]: g(e[2],e[2]).expr() # In[239]: g[e,:] # In[240]: g.display(e) # In[241]: eps.display(e) #

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

# In[242]: e.structure_coeff()[:] # In[243]: e[2].lie_derivative(e[1]).display(e) #

while we have of course

# In[244]: spher.frame().structure_coeff()[:]