# coding: utf-8 # # Sphere $\mathbb{S}^2$ (SymPy version) # # This worksheet demonstrates a few capabilities of # [SageManifolds](http://sagemanifolds.obspm.fr) (version 1.2, as included in SageMath 8.2) # on the example of the 2-dimensional sphere, using [SymPy](http://www.sympy.org) as symbolic engine, instead of SageMath's default one (Pynac+Maxima). # # Click [here](https://raw.githubusercontent.com/sagemanifolds/SageManifolds/master/Worksheets/v1.2/SM_sphere_S2_sympy.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 8.2 is required to run this worksheet: # In[1]: version() # First we set up the notebook to display mathematical objects using LaTeX rendering: # In[2]: get_ipython().run_line_magic('display', 'latex') from sympy import init_printing init_printing() # 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() # We ask for all symbolic computations to be performed with [SymPy](http://www.sympy.org), instead of SageMath's default symbolic engine (Pynac+Maxima, implemented via SageMath's Symbolic Ring): # In[9]: S2.set_calculus_method('sympy') # ### 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[10]: U = S2.open_subset('U') ; print(U) # In[11]: V = S2.open_subset('V') ; print(V) #

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

# In[12]: 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[13]: 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[14]: 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[15]: stereoN[1] # In[16]: y is stereoN[2] #

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

# In[17]: 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[18]: stereoS #

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

# In[19]: 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[20]: 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[21]: 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[22]: S2.atlas() #

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

# In[23]: 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[24]: stereoN_W = stereoN.restrict(W) stereoN_W # In[25]: stereoS_W = stereoS.restrict(W) stereoS_W #

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

# In[26]: 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[27]: 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[28]: 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[29]: 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[30]: spher. = A.chart(r'theta:(0,pi):\theta phi:(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[31]: 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[32]: 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[33]: 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[34]: 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[35]: 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[36]: S2.atlas() #

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

# In[37]: 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[38]: 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[39]: 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[40]: 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[41]: N = V((0,0), name='N') ; print(N) S = U((0,0), name='S') ; print(S) # In[42]: N.parent() # In[43]: S.parent() #

We have of course

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

Let us introduce some point at the equator:

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

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

# In[49]: E in A #

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

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

which is not possible for the point $N$:

# In[51]: 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[52]: R3 = Manifold(3, 'R^3', r'\mathbb{R}^3', start_index=1) R3.set_calculus_method('sympy') cart. = R3.chart() ; cart #

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

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

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

# In[58]: N1 = Phi(N) ; print(N1) ; N1 ; N1.coord() # In[59]: S1 = Phi(S) ; print(S1) ; S1 ; S1.coord() # In[60]: 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[61]: Phi.expr(stereoN_A, cart) # In[62]: Phi.expr(spher, cart) # In[63]: 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[64]: graph_spher = spher.plot(chart=cart, mapping=Phi, number_values=11, color='blue', label_axes=False) show(graph_spher, viewer=viewer3D, online=True) #

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[65]: graph_stereoN = stereoN.plot(chart=cart, mapping=Phi, number_values=25, label_axes=False) show(graph_stereoN, viewer=viewer3D, online=True) #

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

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

We may also add the two poles to the graphic:

# In[67]: 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, online=True) #

## Tangent spaces

#

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

# In[68]: 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[69]: print(T_N.category()) #

Its dimension equals the manifold's dimension:

# In[70]: dim(T_N) # In[71]: 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[72]: 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[73]: T_E = S2.tangent_space(E) print(T_E) ; T_E # In[74]: T_E.bases() # In[75]: T_E.default_basis() #

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

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

### Differential of a smooth mapping

#

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

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

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

# In[86]: dPhi_E(v) # In[87]: print(dPhi_E(v)) # In[88]: dPhi_E(v) in R3.tangent_space(Phi(E)) # In[89]: 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[90]: 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[91]: 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[92]: CS.base_ring() #

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

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

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

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

A specific element is the zero one:

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

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

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

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

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

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

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

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

# In[104]: f._express #

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

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

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

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

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

# In[109]: fU = f.restrict(U) fU.display() # In[110]: fV = f.restrict(V) fV.display() # In[111]: fU(E), fU(S) # In[112]: fU.parent() # In[113]: fV.parent() # In[114]: 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[115]: CU.has_coerce_map_from(CS) # In[116]: fU == CU(f) #

The arithmetic of scalar fields:

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

## Module of vector fields

#

The set $\mathfrak{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[118]: XS = S2.vector_field_module() XS # In[119]: print(XS) # In[120]: XS.base_ring() # In[121]: XS.category() #

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

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

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

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

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

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

because $U$ is parallelizable:

# In[125]: 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 $\mathfrak{X}(U)$, namely the coordinate basis $(\partial/\partial x, \partial/\partial y)$:

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

Similarly

# In[128]: XV = V.vector_field_module() XV.default_basis() # In[129]: 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[130]: 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[131]: eU is S2.default_frame() # In[132]: eV is V.default_frame() #

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

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

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

# In[141]: v.add_comp_by_continuation(eV, W, chart=stereoS) # In[142]: 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[143]: print(v) v.display(eU) # In[144]: v.display(eV) #

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

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

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

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

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

# In[150]: vS = v.at(S) print(v) # In[151]: vS.display() # In[152]: vS.parent() # In[153]: vS.parent() is S2.tangent_space(S) # In[154]: 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[155]: 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[156]: 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[157]: 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[158]: graph_v = v.plot(chart=cart, mapping=Phi, chart_domain=spher, number_values=11, scale=0.2) show(graph_spher + graph_v, viewer=viewer3D, online=True) # The code in the following cell is a workaround for a bug that has been revealed in Sage 8.2; this will be corrected in Sage 8.3. # In[159]: S2._frames = S2._frames[:-1] U._frames = U._frames[:-1] V._frames = V._frames[:-1] W._frames = W._frames[:-1] A._frames = A._frames[:-1] S2._top_frames = S2._top_frames[:-1] U._top_frames = U._top_frames[:-1] V._top_frames = V._top_frames[:-1] W._top_frames = W._top_frames[:-1] A._top_frames = A._top_frames[:-1] #

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

# In[160]: ex = stereoN.frame()[1] ex # In[161]: 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, online=True) #

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

# In[162]: ey = stereoN.frame()[2] ey # In[163]: 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, online=True) # 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[164]: 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, online=True) # The same scene rendered with Tachyon: # In[165]: 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[166]: 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[167]: vf(N) # In[168]: vf(E) # In[169]: 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[170]: df = f.differential() ; print(df) # In[171]: df.display() # In[172]: print(df.parent()) # In[173]: df.parent() #

The 1-form acting on a vector field:

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

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

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

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

# In[176]: 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[177]: R. = RealLine() ; print(R) # In[178]: R.category() # In[179]: dim(R) # In[180]: R.atlas() # In[181]: R.set_calculus_method('sympy') #

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

# In[182]: 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[183]: c.parent() # In[184]: c.display() #

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

# In[185]: 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[186]: graph_c = c.plot(mapping=Phi, max_range=40, plot_points=200, thickness=2, label_axes=False) show(graph_spher + graph_c, viewer=viewer3D, online=True) #

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

# In[187]: 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[188]: 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 $\mathfrak{X}(\mathbb{R},c)$; it is a module over the algebra $C^\infty(\mathbb{R})$:

# In[189]: vc.parent() # In[190]: vc.parent().category() # In[191]: vc.parent().base_ring() #

A coordinate view of $c'$:

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

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

# In[193]: 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$ (not working yet with SymPy as symbolic engine; should be fixed in Sage 8.3): # In[194]: #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, online=True) #

## 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[195]: 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[196]: 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[197]: print(g.parent()) # In[198]: g.tensor_type() # In[199]: g.symmetries() #

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

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

We may factorize the metric components:

# In[201]: g[1,1].factor() ; g[2,2].factor() # In[202]: g.display() #

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

# In[203]: g[:] #

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

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

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

# In[206]: print(g(v,v)) # In[207]: g(v,v).parent() # In[208]: g(v,v).display() #

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

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

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

# In[210]: 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[211]: g.christoffel_symbols_display(chart=stereoN) # In[212]: g.christoffel_symbols_display(chart=spher) #

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

# In[213]: print(nab(v)) # In[214]: nab(v).display(stereoN.frame()) #

## Curvature

#

The Riemann tensor associated with the metric $g$:

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

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

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

The components in the frame associated with spherical coordinates:

# In[217]: Riem.display_comp(spher.frame(), chart=spher) # In[218]: print(Riem.parent()) # In[219]: Riem.symmetries() #

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

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

The Ricci tensor and the Ricci scalar:

# In[221]: Ric = g.ricci() Ric.display() # In[222]: 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[223]: delta = S2.tangent_identity_field() Riem == - R*(g*delta).antisymmetrize(2,3) #

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

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

The Levi-Civita tensor associated with $g$:

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

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

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

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

# In[228]: 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[229]: A.default_chart() # In[230]: A.default_frame() # In[231]: A.set_default_chart(spher) A.set_default_frame(spher.frame()) A.default_chart() # In[232]: 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[233]: a = A.automorphism_field() a[1,1], a[2,2] = 1, 1/sin(th) a.display() # In[234]: a[:] # In[235]: e = spher.frame().new_frame(a, 'e') print(e) ; e # In[236]: e[1].display() # In[237]: e[2].display() # In[238]: A.frames() #

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

# In[239]: g(e[1],e[1]).expr() # In[240]: g(e[1],e[2]).expr() # In[241]: g(e[2],e[2]).expr() # In[242]: g[e,:] # In[243]: g.display(e) # In[244]: eps.display(e) #

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

# In[245]: e.structure_coeff()[:] # In[246]: e[2].lie_derivative(e[1]).display(e) #

while we have of course

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