Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

133958 views
License: OTHER
%auto typeset_mode(True, display=False)

Sphere $\mathbb{S}^2$

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

The whole worksheet file can be downloaded from here.

$\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}$:

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\}$.

print S2
2-dimensional manifold 'S^2'
S2
$\mathbb{S}^2$

The manifold is a Sage Parent object:

isinstance(S2, Parent)
$\mathrm{True}$
S2.category()
$\mathbf{Sets}$

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:

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

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

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:

stereoN.<x,y> = U.chart()
stereoN
$\left(U,(x, y)\right)$
y is stereoN[2]
$\mathrm{True}$

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

stereoS.<xp,yp> = V.chart(r"xp:x' yp:y'")
stereoS
$\left(V,({x'}, {y'})\right)$

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

S2.atlas()
[$\left(U,(x, y)\right)$, $\left(V,({x'}, {y'})\right)$]

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:

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()
$\left\{\begin{array}{lcl} {x'} & = & \frac{x}{x^{2} + y^{2}} \\ {y'} & = & \frac{y}{x^{2} + y^{2}} \end{array}\right.$

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():

stereoS_to_N = stereoN_to_S.inverse() stereoS_to_N.display()
$\left\{\begin{array}{lcl} x & = & \frac{{x'}}{{x'}^{2} + {y'}^{2}} \\ y & = & \frac{{y'}}{{x'}^{2} + {y'}^{2}} \end{array}\right.$

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:

S2.atlas()
[$\left(U,(x, y)\right)$, $\left(V,({x'}, {y'})\right)$, $\left(W,(x, y)\right)$, $\left(W,({x'}, {y'})\right)$]

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

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:

stereoN_W = stereoN.restrict(W) stereoN_W
$\left(W,(x, y)\right)$
stereoS_W = stereoS.restrict(W) stereoS_W
$\left(W,({x'}, {y'})\right)$

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

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)$):

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:

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

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

stereoN_A = stereoN_W.restrict(A) stereoN_A
$\left(A,(x, y)\right)$

We then declare the chart $(A,(\theta,\phi))$ by specifying the intervals $(0,\pi)$ and $(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
$\left(A,({\theta}, {\phi})\right)$

The specification of the spherical coordinates is completed by providing the transition map with the stereographic chart $(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()
$\left\{\begin{array}{lcl} x & = & -\frac{\cos\left({\phi}\right) \sin\left({\theta}\right)}{\cos\left({\theta}\right) - 1} \\ y & = & -\frac{\sin\left({\phi}\right) \sin\left({\theta}\right)}{\cos\left({\theta}\right) - 1} \end{array}\right.$

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 of the inverse coordinate transformation: th == 2*arctan(sqrt(-cos(th) + 1)/sqrt(cos(th) + 1)) ph == pi + arctan2(sin(ph)*sin(th)/(cos(th) - 1), cos(ph)*sin(th)/(cos(th) - 1)) x == x y == y

The check is passed, up to some lack of simplification in the functions atan and atan2.


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

S2.atlas()
[$\left(U,(x, y)\right)$, $\left(V,({x'}, {y'})\right)$, $\left(W,(x, y)\right)$, $\left(W,({x'}, {y'})\right)$, $\left(A,(x, y)\right)$, $\left(A,({\theta}, {\phi})\right)$]

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

spher.plot(stereoN, nb_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):

stereoN_A.plot(spher, ranges={x: (0.01,8), y: (0.01,8)}, nb_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))$):

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 2-dimensional manifold 'S^2' point 'S' on 2-dimensional 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 2-dimensional manifold 'S^2' point 'S' on 2-dimensional manifold 'S^2'

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

N = V((0,0), name='N') ; print N S = U((0,0), name='S') ; print S
point 'N' on 2-dimensional manifold 'S^2' point 'S' on 2-dimensional manifold 'S^2'
N.parent()
$\mathbb{S}^2$
S.parent()
$\mathbb{S}^2$

We have of course

N in V
$\mathrm{True}$
N in S2
$\mathrm{True}$
N in U
$\mathrm{False}$
N in A
$\mathrm{False}$

Let us introduce some point at the equator:

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

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

E in A
$\mathrm{True}$

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

E.coord(spher)
($\frac{1}{2} \, \pi$, $\frac{1}{2} \, \pi$)

which is not possible for the point $N$:

N.coord(spher)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/point.py", line 341, in coord "of " + str(chart)) ValueError: The point does not belong to the domain of chart (A, (th, ph))

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):

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

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

Phi = S2.diff_mapping(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()
$\begin{array}{llcl} \Phi:& \mathbb{S}^2 & \longrightarrow & \mathbb{R}^3 \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & \left(X, Y, Z\right) = \left(\frac{2 \, x}{x^{2} + y^{2} + 1}, \frac{2 \, y}{x^{2} + y^{2} + 1}, \frac{x^{2} + y^{2} - 1}{x^{2} + y^{2} + 1}\right) \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & \left(X, Y, Z\right) = \left(\frac{2 \, {x'}}{{x'}^{2} + {y'}^{2} + 1}, \frac{2 \, {y'}}{{x'}^{2} + {y'}^{2} + 1}, -\frac{{x'}^{2} + {y'}^{2} - 1}{{x'}^{2} + {y'}^{2} + 1}\right) \end{array}$
Phi.parent()
$\mathrm{Hom}\left(\mathbb{S}^2,\mathbb{R}^3\right)$
print Phi.parent()
Set of Morphisms from 2-dimensional manifold 'S^2' to 3-dimensional manifold 'R^3' in Category of sets
Phi.parent() is Hom(S2, R3)
$\mathrm{True}$

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

N1 = Phi(N) ; print N1 ; N1 ; N1.coord()
point 'Phi(N)' on 3-dimensional manifold 'R^3'
$\Phi\left(N\right)$
($0$, $0$, $1$)
S1 = Phi(S) ; print S1 ; S1 ; S1.coord()
point 'Phi(S)' on 3-dimensional manifold 'R^3'
$\Phi\left(S\right)$
($0$, $0$, $-1$)
E1 = Phi(E) ; print E1 ; E1 ; E1.coord()
point 'Phi(E)' on 3-dimensional manifold 'R^3'
$\Phi\left(E\right)$
($0$, $1$, $0$)

$\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))$:

Phi.expr(stereoN_A, cart)
($\frac{2 \, x}{x^{2} + y^{2} + 1}$, $\frac{2 \, y}{x^{2} + y^{2} + 1}$, $\frac{x^{2} + y^{2} - 1}{x^{2} + y^{2} + 1}$)
Phi.expr(spher, cart)
($\cos\left({\phi}\right) \sin\left({\theta}\right)$, $\sin\left({\phi}\right) \sin\left({\theta}\right)$, $\cos\left({\theta}\right)$)
Phi.display(spher, cart)
$\begin{array}{llcl} \Phi:& \mathbb{S}^2 & \longrightarrow & \mathbb{R}^3 \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & \left(X, Y, Z\right) = \left(\cos\left({\phi}\right) \sin\left({\theta}\right), \sin\left({\phi}\right) \sin\left({\theta}\right), \cos\left({\theta}\right)\right) \end{array}$

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$:

graph_spher = spher.plot(chart=cart, mapping=Phi, nb_values=11, color='blue') show(graph_spher)
3D rendering not yet implemented

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 $\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)
3D rendering not yet implemented

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)
3D rendering not yet implemented

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)
3D rendering not yet implemented

Tangent spaces

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

T_N = N.tangent_space() print T_N ; T_N
tangent space at point 'N' on 2-dimensional manifold 'S^2'
$T_{N}\,\mathbb{S}^2$

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

T_N.category()
$\mathbf{VectorSpaces}_{\text{SR}}$

Its dimension equals the manifold's dimension:

dim(T_N)
$2$
dim(T_N) == dim(S2)
$\mathrm{True}$

$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'))$:

T_N.bases()
[$\left(\frac{\partial}{\partial {x'} },\frac{\partial}{\partial {y'} }\right)$]

$(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$:

T_E = E.tangent_space() print T_E ; T_E
tangent space at point 'E' on 2-dimensional manifold 'S^2'
$T_{E}\,\mathbb{S}^2$
T_E.bases()
[$\left(\frac{\partial}{\partial x },\frac{\partial}{\partial y }\right)$, $\left(\frac{\partial}{\partial {x'} },\frac{\partial}{\partial {y'} }\right)$, $\left(\frac{\partial}{\partial {\theta} },\frac{\partial}{\partial {\phi} }\right)$]
T_E.default_basis()
$\left(\frac{\partial}{\partial x },\frac{\partial}{\partial y }\right)$

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

v = T_E((-3, 2), name='v') print v
tangent vector v at point 'E' on 2-dimensional manifold 'S^2'
v in T_E
$\mathrm{True}$
v.parent()
$T_{E}\,\mathbb{S}^2$
v.display()
$v = -3 \frac{\partial}{\partial x } + 2 \frac{\partial}{\partial y }$
v.display(T_E.bases()[1])
$v = -3 \frac{\partial}{\partial {x'} } -2 \frac{\partial}{\partial {y'} }$
v.display(T_E.bases()[2])
$v = -2 \frac{\partial}{\partial {\theta} } + 3 \frac{\partial}{\partial {\phi} }$

Differential of a smooth mapping

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

dPhi_E = Phi.differential(E) print dPhi_E ; dPhi_E
Generic morphism: From: tangent space at point 'E' on 2-dimensional manifold 'S^2' To: tangent space at point 'Phi(E)' on 3-dimensional manifold 'R^3'
$\mathrm{d}\Phi_{E}$
dPhi_E.domain()
$T_{E}\,\mathbb{S}^2$
dPhi_E.codomain()
$T_{\Phi\left(E\right)}\,\mathbb{R}^3$
dPhi_E.parent()
$\mathrm{Hom}\left(T_{E}\,\mathbb{S}^2,T_{\Phi\left(E\right)}\,\mathbb{R}^3\right)$

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

dPhi_E(v)
$\mathrm{d}\Phi_{E}\left(v\right)$
print dPhi_E(v)
tangent vector dPhi_E(v) at point 'Phi(E)' on 3-dimensional manifold 'R^3'
dPhi_E(v) in Phi(E).tangent_space()
$\mathrm{True}$
dPhi_E(v).display()
$\mathrm{d}\Phi_{E}\left(v\right) = -3 \frac{\partial}{\partial X } + 2 \frac{\partial}{\partial Z }$

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$:

CS = S2.scalar_field_algebra() ; CS
$C^\infty(\mathbb{S}^2)$

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:

CS.category()
$\mathbf{CommutativeAlgebras}_{\text{SR}}$

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):

CS.base_ring()
$\text{SR}$

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

print CS.an_element()
scalar field on the 2-dimensional manifold 'S^2'

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

CS.an_element().display()
$\begin{array}{llcl} & \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & 2 \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 2 \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & 2 \end{array}$

A specific element is the zero one:

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

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

f(N), f(E), f(S)
($0$, $0$, $0$)
f.display()
$\begin{array}{llcl} 0:& \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & 0 \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 0 \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & 0 \end{array}$

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

f = CS.one() print f
scalar field on the 2-dimensional manifold 'S^2'
f(N), f(E), f(S)
($1$, $1$, $1$)
f.display()
$\begin{array}{llcl} & \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & 1 \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 1 \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & 1 \end{array}$

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()
$\begin{array}{llcl} & \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & \pi - 2 \, \arctan\left(x^{2} + y^{2}\right) \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & \pi + 2 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right) \end{array}$

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:

f = S2.scalar_field({stereoN: pi - 2*atan(x^2+y^2), stereoS: 2*atan(xp^2+yp^2)}, name='f') f.display()
$\begin{array}{llcl} f:& \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & \pi - 2 \, \arctan\left(x^{2} + y^{2}\right) \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & \pi + 2 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right) \end{array}$
f.parent()
$C^\infty(\mathbb{S}^2)$

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

f._express
$\left\{\left(A,(x, y)\right) : \pi - 2 \, \arctan\left(x^{2} + y^{2}\right), \left(A,({\theta}, {\phi})\right) : \pi + 2 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right), \left(U,(x, y)\right) : \pi - 2 \, \arctan\left(x^{2} + y^{2}\right), \left(V,({x'}, {y'})\right) : 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right)\right\}$

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

f.display(stereoS)
$\begin{array}{llcl} f:& \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \end{array}$

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

f(N)
$0$
f(E)
$\frac{1}{2} \, \pi$
f(S)
$\pi$

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

fU = f.restrict(U) fU.display()
$\begin{array}{llcl} f:& U & \longrightarrow & \mathbb{R} \\ & \left(x, y\right) & \longmapsto & \pi - 2 \, \arctan\left(x^{2} + y^{2}\right) \\ \mbox{on}\ W : & \left({x'}, {y'}\right) & \longmapsto & 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & \pi + 2 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right) \end{array}$
fV = f.restrict(V) fV.display()
$\begin{array}{llcl} f:& V & \longrightarrow & \mathbb{R} \\ & \left({x'}, {y'}\right) & \longmapsto & 2 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \\ \mbox{on}\ W : & \left(x, y\right) & \longmapsto & \pi - 2 \, \arctan\left(x^{2} + y^{2}\right) \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & \pi + 2 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right) \end{array}$
fU(E), fU(S)
($\frac{1}{2} \, \pi$, $\pi$)
fU.parent()
$C^\infty(U)$
fV.parent()
$C^\infty(V)$
CU = U.scalar_field_algebra() fU.parent() is CU
$\mathrm{True}$

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

CU.has_coerce_map_from(CS)
$\mathrm{True}$
fU == CU(f)
$\mathrm{True}$

The arithmetic of scalar fields:

g = f*f - 2*f g.display()
$\begin{array}{llcl} & \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & -2 \, \pi + \pi^{2} - 4 \, {\left(\pi - 1\right)} \arctan\left(x^{2} + y^{2}\right) + 4 \, \arctan\left(x^{2} + y^{2}\right)^{2} \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 4 \, \arctan\left({x'}^{2} + {y'}^{2}\right)^{2} - 4 \, \arctan\left({x'}^{2} + {y'}^{2}\right) \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & -2 \, \pi + \pi^{2} + 4 \, {\left(\pi - 1\right)} \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right) + 4 \, \arctan\left(\frac{\cos\left({\theta}\right) + 1}{\cos\left({\theta}\right) - 1}\right)^{2} \end{array}$

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():

XS = S2.vector_field_module() XS
$\mathcal{X}\left(\mathbb{S}^2\right)$
print XS
module X(S^2) of vector fields on the 2-dimensional manifold 'S^2'
XS.base_ring()
$C^\infty(\mathbb{S}^2)$
XS.category()
$\mathbf{Modules}_{C^\infty(\mathbb{S}^2)}$

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

isinstance(XS, FiniteRankFreeModule)
$\mathrm{False}$

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

S2.is_manifestly_parallelizable()
$\mathrm{False}$

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

XU = U.vector_field_module() isinstance(XU, FiniteRankFreeModule)
$\mathrm{True}$

because $U$ is parallelizable:

U.is_manifestly_parallelizable()
$\mathrm{True}$

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)$:

XU.print_bases()
Bases defined on the free module X(U) of vector fields on the open subset 'U' of the 2-dimensional manifold 'S^2': - (U, (d/dx,d/dy)) (default basis)
XU.default_basis()
$\left(U ,\left(\frac{\partial}{\partial x },\frac{\partial}{\partial y }\right)\right)$

Similarly

XV = V.vector_field_module() XV.default_basis()
$\left(V ,\left(\frac{\partial}{\partial {x'} },\frac{\partial}{\partial {y'} }\right)\right)$
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:

eU is U.default_frame()
$\mathrm{True}$

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$:

eU is S2.default_frame()
$\mathrm{True}$
eV is V.default_frame()
$\mathrm{True}$

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

v = S2.vector_field(name='v') v[eU,:] = [1, -2] v.display(eU)
$v = \frac{\partial}{\partial x } -2 \frac{\partial}{\partial y }$
v.parent()
$\mathcal{X}\left(\mathbb{S}^2\right)$
stereoSW = stereoS.restrict(W) eSW = stereoSW.frame() eSW
$\left(W ,\left(\frac{\partial}{\partial {x'} },\frac{\partial}{\partial {y'} }\right)\right)$
vW = v.restrict(W) vW.display()
$v = \frac{\partial}{\partial x } -2 \frac{\partial}{\partial y }$
vW.parent()
$\mathcal{X}\left(W\right)$
print vW.parent()
free module X(W) of vector fields on the open subset 'W' of the 2-dimensional manifold 'S^2'
vW.display(eSW)
$v = \left( -\frac{x^{2} - 4 \, x y - y^{2}}{x^{4} + 2 \, x^{2} y^{2} + y^{4}} \right) \frac{\partial}{\partial {x'} } + \left( -\frac{2 \, {\left(x^{2} + x y - y^{2}\right)}}{x^{4} + 2 \, x^{2} y^{2} + y^{4}} \right) \frac{\partial}{\partial {y'} }$
vW.display(eSW, stereoSW)
$v = \left( -{x'}^{2} + 4 \, {x'} {y'} + {y'}^{2} \right) \frac{\partial}{\partial {x'} } + \left( -2 \, {x'}^{2} - 2 \, {x'} {y'} + 2 \, {y'}^{2} \right) \frac{\partial}{\partial {y'} }$

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

v.add_comp_by_continuation(eV, W, chart=stereoS)
v.display(eV)
$v = \left( -{x'}^{2} + 4 \, {x'} {y'} + {y'}^{2} \right) \frac{\partial}{\partial {x'} } + \left( -2 \, {x'}^{2} - 2 \, {x'} {y'} + 2 \, {y'}^{2} \right) \frac{\partial}{\partial {y'} }$

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$:

print v v.display(eU)
vector field 'v' on the 2-dimensional manifold 'S^2'
$v = \frac{\partial}{\partial x } -2 \frac{\partial}{\partial y }$
v.display(eV)
$v = \left( -{x'}^{2} + 4 \, {x'} {y'} + {y'}^{2} \right) \frac{\partial}{\partial {x'} } + \left( -2 \, {x'}^{2} - 2 \, {x'} {y'} + 2 \, {y'}^{2} \right) \frac{\partial}{\partial {y'} }$

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

vN = v.at(N) print vN
tangent vector v at point 'N' on 2-dimensional manifold 'S^2'
vN.display()
$v = 0$

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

vN.parent()
$T_{N}\,\mathbb{S}^2$
vN.parent() is N.tangent_space()
$\mathrm{True}$
vN == N.tangent_space().zero()
$\mathrm{True}$

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

vS = v.at(S) print vS
tangent vector v at point 'S' on 2-dimensional manifold 'S^2'
vS.display()
$v = \frac{\partial}{\partial x } -2 \frac{\partial}{\partial y }$
vS.parent()
$T_{S}\,\mathbb{S}^2$
vS.parent() is S.tangent_space()
$\mathrm{True}$
vS != S.tangent_space().zero()
$\mathrm{True}$

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

v.plot(chart=stereoN, chart_domain=stereoN, max_value=4, nb_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:

v.display(stereoN.frame())

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

v.plot(chart=stereoS, chart_domain=stereoS, max_value=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$:

graph_v = v.plot(chart=cart, mapping=Phi, chart_domain=spher, nb_values=11, scale=0.2) show(graph_v + graph_spher, aspect_ratio=1)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/vectorfield.py", line 528, in plot **extra_options) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/tangentspace.py", line 284, in plot eff_vector = mapping.differential(self._point)._call_(self) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/tensor/modules/free_module_morphism.py", line 882, in _call_ "of {} by {}".format(element,self)) ValueError: no common basis found to evaluate the image of tangent vector v at point on 2-dimensional manifold 'S^2' by Generic morphism: From: tangent space at point on 2-dimensional manifold 'S^2' To: tangent space at point on 3-dimensional manifold 'R^3'

Similarly, let us draw the first vector field of the stereographic frame from the North pole, namely $\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_ex + graph_spher, aspect_ratio=1)
Error in lines 1-2 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'ex' is not defined

For the second vector field of the stereographic frame from the North pole, namely $\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_ey + graph_spher, aspect_ratio=1)

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_ex + graph_ey + graph_spher + N.plot(cart, mapping=Phi, label_offset=0.05) + S.plot(cart, mapping=Phi, label_offset=0.05), aspect_ratio=1)
Error in lines 1-4 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 2, in <module> NameError: name 'graph_ex' is not defined

A Tachyon view of the same frame:

show(graph_ex + graph_ey + graph_spher + 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), aspect_ratio=1, 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$:

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:

vf(N)
vf(E)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'vf' is not defined
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:

df = f.differential() ; print df
df.display()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'df' is not defined
print df.parent()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'df' is not defined
df.parent()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'df' is not defined

The 1-form acting on a vector field:

print df(v) ; df(v).display()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'df' is not defined

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

df(v) == v(f)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'df' is not defined

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

f.lie_der(v) == v(f)
$\mathrm{True}$

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:

R.<t> = RealLine() ; print R
field R of real numbers
isinstance(R, Manifold)
$\mathrm{True}$
dim(R)
$1$
R.atlas()
[$\left(\RR,(t)\right)$]

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

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$:

c.parent()
$\mathrm{Hom}\left(\RR,\mathbb{S}^2\right)$
c.display()
$\begin{array}{llcl} c:& \RR & \longrightarrow & \mathbb{S}^2 \\ & t & \longmapsto & \left(x, y\right) = \left(\cos\left(t\right) e^{\left(\frac{1}{10} \, t\right)}, e^{\left(\frac{1}{10} \, t\right)} \sin\left(t\right)\right) \\ & t & \longmapsto & \left({\theta}, {\phi}\right) = \left(2 \, \arctan\left(e^{\left(-\frac{1}{10} \, t\right)}\right), t\right) \end{array}$

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

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$:

graph_c = c.plot(mapping=Phi, max_value=40, plot_points=200, thickness=2) show(graph_spher + graph_c)
3D rendering not yet implemented

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

vc = c.tangent_vector_field() vc
${c'}$

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

print vc
vector field 'c'' along the field R of real numbers with values on the 2-dimensional manifold 'S^2'

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})$:

vc.parent()
$\mathcal{X}\left(\RR,c\right)$
vc.parent().category()
$\mathbf{Modules}_{C^\infty(\RR)}$
vc.parent().base_ring()
$C^\infty(\RR)$

A coordinate view of $c'$:

vc.display()
${c'} = \left( \frac{1}{10} \, \cos\left(t\right) e^{\left(\frac{1}{10} \, t\right)} - e^{\left(\frac{1}{10} \, t\right)} \sin\left(t\right) \right) \frac{\partial}{\partial x } + \left( \cos\left(t\right) e^{\left(\frac{1}{10} \, t\right)} + \frac{1}{10} \, e^{\left(\frac{1}{10} \, t\right)} \sin\left(t\right) \right) \frac{\partial}{\partial y }$

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

show(vc.plot(chart=stereoN, nb_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$:

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_vc + graph_spher + graph_c, aspect_ratio=1)
Error in lines 1-2 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 2, in <module> File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/vectorfield.py", line 528, in plot **extra_options) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/tangentspace.py", line 284, in plot eff_vector = mapping.differential(self._point)._call_(self) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/tensor/modules/free_module_morphism.py", line 882, in _call_ "of {} by {}".format(element,self)) ValueError: no common basis found to evaluate the image of tangent vector c' at point on 2-dimensional manifold 'S^2' by Generic morphism: From: tangent space at point on 2-dimensional manifold 'S^2' To: tangent space at point on 3-dimensional manifold 'R^3' Error in lines 1-2 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 2, in <module> File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/vectorfield.py", line 528, in plot **extra_options) File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/geometry/manifolds/tangentspace.py", line 308, in plot vcomp = eff_vector.comp(basis=basis)[:] File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/tensor/modules/free_module_tensor.py", line 1050, in components "the components in the {}".format(basis)) ValueError: no basis could be found for computing the components in the Basis (d/dX,d/dY,d/dZ) on the tangent space at point on 3-dimensional manifold 'R^3'

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:

h = R3.riemann_metric('h') h[1,1], h[2,2], h[3, 3] = 1, 1, 1 h.display()
$h = \mathrm{d} X\otimes \mathrm{d} X+\mathrm{d} Y\otimes \mathrm{d} Y+\mathrm{d} Z\otimes \mathrm{d} Z$
$h = \mathrm{d} X\otimes \mathrm{d} X+\mathrm{d} Y\otimes \mathrm{d} Y+\mathrm{d} Z\otimes \mathrm{d} Z$

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

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

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):

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

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

g.display()
$g = \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \mathrm{d} x\otimes \mathrm{d} x + \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \mathrm{d} y\otimes \mathrm{d} y$

We may factorize the metric components:

g[1,1].factor() ; g[2,2].factor()
$\frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}}$
$\frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}}$
g.display()
$g = \frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}} \mathrm{d} x\otimes \mathrm{d} x + \frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}} \mathrm{d} y\otimes \mathrm{d} y$

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

g[:]
$\left(\begin{array}{rr} \frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}} & 0 \\ 0 & \frac{4}{{\left(x^{2} + y^{2} + 1\right)}^{2}} \end{array}\right)$

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

g.display(stereoS.frame())
$g = \left( \frac{4}{{x'}^{4} + {y'}^{4} + 2 \, {\left({x'}^{2} + 1\right)} {y'}^{2} + 2 \, {x'}^{2} + 1} \right) \mathrm{d} {x'}\otimes \mathrm{d} {x'} + \left( \frac{4}{{x'}^{4} + {y'}^{4} + 2 \, {\left({x'}^{2} + 1\right)} {y'}^{2} + 2 \, {x'}^{2} + 1} \right) \mathrm{d} {y'}\otimes \mathrm{d} {y'}$
g.display(spher.frame(), chart=spher)
$g = \mathrm{d} {\theta}\otimes \mathrm{d} {\theta} + \sin\left({\theta}\right)^{2} \mathrm{d} {\phi}\otimes \mathrm{d} {\phi}$

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 manifold 'S^2'
g(v,v).parent()
$C^\infty(\mathbb{S}^2)$
g(v,v).display()
$\begin{array}{llcl} g\left(v,v\right):& \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & \frac{20}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & \frac{20 \, {\left({x'}^{4} + 2 \, {x'}^{2} {y'}^{2} + {y'}^{4}\right)}}{{x'}^{4} + {y'}^{4} + 2 \, {\left({x'}^{2} + 1\right)} {y'}^{2} + 2 \, {x'}^{2} + 1} \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & -\frac{5 \, {\left(\cos\left({\theta}\right)^{4} - 4 \, \cos\left({\theta}\right)^{3} + 6 \, \cos\left({\theta}\right)^{2} - 4 \, \cos\left({\theta}\right) + 1\right)}}{\sin\left({\theta}\right)^{2} + 2 \, \cos\left({\theta}\right) - 2} \end{array}$

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

nab = g.connection() print nab nab
Levi-Civita connection 'nabla_g' associated with the Riemannian metric 'g' on the 2-dimensional manifold 'S^2'
$\nabla_{g}$

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

nab(g).display()
$\nabla_{g} g = 0$

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

g.christoffel_symbols_display(chart=stereoN)
$\begin{array}{lcl} \Gamma_{ \phantom{\, x } \, x \, x }^{ \, x \phantom{\, x } \phantom{\, x } } & = & -\frac{2 \, x}{x^{2} + y^{2} + 1} \\ \Gamma_{ \phantom{\, x } \, x \, y }^{ \, x \phantom{\, x } \phantom{\, y } } & = & -\frac{2 \, y}{x^{2} + y^{2} + 1} \\ \Gamma_{ \phantom{\, x } \, y \, y }^{ \, x \phantom{\, y } \phantom{\, y } } & = & \frac{2 \, x}{x^{2} + y^{2} + 1} \\ \Gamma_{ \phantom{\, y } \, x \, x }^{ \, y \phantom{\, x } \phantom{\, x } } & = & \frac{2 \, y}{x^{2} + y^{2} + 1} \\ \Gamma_{ \phantom{\, y } \, x \, y }^{ \, y \phantom{\, x } \phantom{\, y } } & = & -\frac{2 \, x}{x^{2} + y^{2} + 1} \\ \Gamma_{ \phantom{\, y } \, y \, y }^{ \, y \phantom{\, y } \phantom{\, y } } & = & -\frac{2 \, y}{x^{2} + y^{2} + 1} \end{array}$
g.christoffel_symbols_display(chart=spher)
$\begin{array}{lcl} \Gamma_{ \phantom{\, {\theta} } \, {\phi} \, {\phi} }^{ \, {\theta} \phantom{\, {\phi} } \phantom{\, {\phi} } } & = & -\cos\left({\theta}\right) \sin\left({\theta}\right) \\ \Gamma_{ \phantom{\, {\phi} } \, {\theta} \, {\phi} }^{ \, {\phi} \phantom{\, {\theta} } \phantom{\, {\phi} } } & = & \frac{\cos\left({\theta}\right)}{\sin\left({\theta}\right)} \end{array}$

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

print nab(v)
tensor field 'nabla_g v' of type (1,1) on the 2-dimensional manifold 'S^2'
nab(v).display(stereoN.frame())
$\nabla_{g} v = \left( -\frac{2 \, {\left(x - 2 \, y\right)}}{x^{2} + y^{2} + 1} \right) \frac{\partial}{\partial x }\otimes \mathrm{d} x + \left( -\frac{2 \, {\left(2 \, x + y\right)}}{x^{2} + y^{2} + 1} \right) \frac{\partial}{\partial x }\otimes \mathrm{d} y + \left( \frac{2 \, {\left(2 \, x + y\right)}}{x^{2} + y^{2} + 1} \right) \frac{\partial}{\partial y }\otimes \mathrm{d} x + \left( -\frac{2 \, {\left(x - 2 \, y\right)}}{x^{2} + y^{2} + 1} \right) \frac{\partial}{\partial y }\otimes \mathrm{d} y$

Curvature

The Riemann tensor associated with the metric $g$:

Riem = g.riemann() print Riem Riem.display()
tensor field 'Riem(g)' of type (1,3) on the 2-dimensional manifold 'S^2'
$\mathrm{Riem}\left(g\right) = \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \frac{\partial}{\partial x }\otimes \mathrm{d} y\otimes \mathrm{d} x\otimes \mathrm{d} y + \left( -\frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \frac{\partial}{\partial x }\otimes \mathrm{d} y\otimes \mathrm{d} y\otimes \mathrm{d} x + \left( -\frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \frac{\partial}{\partial y }\otimes \mathrm{d} x\otimes \mathrm{d} x\otimes \mathrm{d} y + \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \frac{\partial}{\partial y }\otimes \mathrm{d} x\otimes \mathrm{d} y\otimes \mathrm{d} x$

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

Riem.display_comp()
$\begin{array}{lcl} \mathrm{Riem}\left(g\right)_{ \phantom{\, x } \, y \, x \, y }^{ \, x \phantom{\, y } \phantom{\, x } \phantom{\, y } } & = & \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, x } \, y \, y \, x }^{ \, x \phantom{\, y } \phantom{\, y } \phantom{\, x } } & = & -\frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, y } \, x \, x \, y }^{ \, y \phantom{\, x } \phantom{\, x } \phantom{\, y } } & = & -\frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, y } \, x \, y \, x }^{ \, y \phantom{\, x } \phantom{\, y } \phantom{\, x } } & = & \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \end{array}$

The components in the frame associated with spherical coordinates:

Riem.display_comp(spher.frame(), chart=spher)
$\begin{array}{lcl} \mathrm{Riem}\left(g\right)_{ \phantom{\, {\theta} } \, {\phi} \, {\theta} \, {\phi} }^{ \, {\theta} \phantom{\, {\phi} } \phantom{\, {\theta} } \phantom{\, {\phi} } } & = & \sin\left({\theta}\right)^{2} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, {\theta} } \, {\phi} \, {\phi} \, {\theta} }^{ \, {\theta} \phantom{\, {\phi} } \phantom{\, {\phi} } \phantom{\, {\theta} } } & = & -\sin\left({\theta}\right)^{2} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, {\phi} } \, {\theta} \, {\theta} \, {\phi} }^{ \, {\phi} \phantom{\, {\theta} } \phantom{\, {\theta} } \phantom{\, {\phi} } } & = & \frac{\cos\left({\theta}\right)^{2} - 1}{\sin\left({\theta}\right)^{2}} \\ \mathrm{Riem}\left(g\right)_{ \phantom{\, {\phi} } \, {\theta} \, {\phi} \, {\theta} }^{ \, {\phi} \phantom{\, {\theta} } \phantom{\, {\phi} } \phantom{\, {\theta} } } & = & 1 \end{array}$
print Riem.parent()
module T^(1,3)(S^2) of type-(1,3) tensors fields on the 2-dimensional manifold 'S^2'
Riem.symmetries()
no symmetry; antisymmetry: (2, 3)

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

h.riemann().display()
$\mathrm{Riem}\left(h\right) = 0$

The Ricci tensor and the Ricci scalar:

Ric = g.ricci() Ric.display()
$\mathrm{Ric}\left(g\right) = \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \mathrm{d} x\otimes \mathrm{d} x + \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \mathrm{d} y\otimes \mathrm{d} y$
R = g.ricci_scalar() R.display()
$\begin{array}{llcl} \mathrm{r}\left(g\right):& \mathbb{S}^2 & \longrightarrow & \mathbb{R} \\ \mbox{on}\ U : & \left(x, y\right) & \longmapsto & 2 \\ \mbox{on}\ V : & \left({x'}, {y'}\right) & \longmapsto & 2 \\ \mbox{on}\ A : & \left({\theta}, {\phi}\right) & \longmapsto & 2 \end{array}$

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]}$:

delta = S2.tangent_identity_field() Riem == - R*(g*delta).antisymmetrize(2,3)
$\mathrm{False}$

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

Ric == (R/2)*g
$\mathrm{True}$

The Levi-Civita tensor associated with $g$:

eps = g.volume_form() print eps eps.display()
2-form 'eps_g' on the 2-dimensional manifold 'S^2'
$\epsilon_{g} = \left( \frac{4}{x^{4} + y^{4} + 2 \, {\left(x^{2} + 1\right)} y^{2} + 2 \, x^{2} + 1} \right) \mathrm{d} x\wedge \mathrm{d} y$
eps.display(spher.frame(), chart=spher)
$\epsilon_{g} = \sin\left({\theta}\right) \mathrm{d} {\theta}\wedge \mathrm{d} {\phi}$

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

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

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

eps.exterior_der().display()
$\mathrm{d}\epsilon_{g} = 0$

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:

A.default_chart()
$\left(A,(x, y)\right)$
A.default_frame()
$\left(A ,\left(\frac{\partial}{\partial x },\frac{\partial}{\partial y }\right)\right)$
A.set_default_chart(spher) A.set_default_frame(spher.frame()) A.default_chart()
$\left(A,({\theta}, {\phi})\right)$
A.default_frame()
$\left(A ,\left(\frac{\partial}{\partial {\theta} },\frac{\partial}{\partial {\phi} }\right)\right)$

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:

a = A.automorphism_field() a[1,1], a[2,2] = 1, 1/sin(th) a.display()
$\frac{\partial}{\partial {\theta} }\otimes \mathrm{d} {\theta} + \frac{1}{\sin\left({\theta}\right)} \frac{\partial}{\partial {\phi} }\otimes \mathrm{d} {\phi}$
a[:]
$\left(\begin{array}{rr} 1 & 0 \\ 0 & \frac{1}{\sin\left({\theta}\right)} \end{array}\right)$
e = spher.frame().new_frame(a, 'e') print e ; e
vector frame (A, (e_1,e_2))
$\left(A, \left(e_1,e_2\right)\right)$
e[1].display()
$e_1 = \frac{\partial}{\partial {\theta} }$
e[2].display()
$e_2 = \frac{1}{\sin\left({\theta}\right)} \frac{\partial}{\partial {\phi} }$
A.frames()
[$\left(A ,\left(\frac{\partial}{\partial x },\frac{\partial}{\partial y }\right)\right)$, $\left(A ,\left(\frac{\partial}{\partial {\theta} },\frac{\partial}{\partial {\phi} }\right)\right)$, $\left(A, \left(e_1,e_2\right)\right)$]

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

g(e[1],e[1]).expr()
$1$
g(e[1],e[2]).expr()
$0$
g(e[2],e[2]).expr()
$1$
g[e,:]
$\left(\begin{array}{rr} 1 & 0 \\ 0 & 1 \end{array}\right)$
g.display(e)
$g = e^1\otimes e^1+e^2\otimes e^2$
eps.display(e)
$\epsilon_{g} = e^1\wedge e^2$

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

e.structure_coef()[:]
[[[$0$, $0$], [$0$, $0$]], [[$0$, $-\frac{\cos\left({\theta}\right)}{\sin\left({\theta}\right)}$], [$\frac{\cos\left({\theta}\right)}{\sin\left({\theta}\right)}$, $0$]]]
e[2].lie_der(e[1]).display(e)
$-\frac{\cos\left({\theta}\right)}{\sin\left({\theta}\right)} e_2$

while we have of course

spher.frame().structure_coef()[:]
[[[$0$, $0$], [$0$, $0$]], [[$0$, $0$], [$0$, $0$]]]