#!/usr/bin/env python # coding: utf-8 # # Vector calculus with SageMath # # ## 5. Advanced aspects: Euclidean spaces as Riemannian manifolds # # This worksheet illustrates some functionalities regarding Euclidean spaces in SageMath, as introduced in Trac ticket [#24623](https://trac.sagemath.org/ticket/24623). # In[1]: version() # In[2]: get_ipython().run_line_magic('display', 'latex') # ## The Euclidean 3-space # # We define the 3-dimensional Euclidean space $\mathbb{E}^3$, with Cartesian coordinates $(x,y,z)$: # In[3]: E. = EuclideanSpace() print(E) E # $\mathbb{E}^3$ is actually a Riemannian manifold, i.e. a smooth real manifold endowed with a positive definite metric tensor: # In[4]: E.category() # In[5]: print(E.category()) # In[6]: E.base_field() is RR # Actually `RR` is used here as a proxy for the real field (this should be replaced in the future, see the discussion at [#24456](https://trac.sagemath.org/ticket/24456)) and the 53 bits of precision play of course no role for the symbolic computations. # Let us introduce spherical and cylindrical coordinates on $\mathbb{E}^3$: # In[7]: spherical. = E.spherical_coordinates() cylindrical. = E.cylindrical_coordinates() # The user atlas of $\mathbb{E}^3$ has then three charts: # In[8]: E.atlas() # while there are five vector frames defined on $\mathbb{E}^3$: # In[9]: E.frames() # Indeed, there are two frames associated with each of the three coordinate systems: the coordinate frame (denoted with partial derivatives above) and an orthonormal frame, but for Cartesian coordinates, both frames coincide. # # We get the orthonormal spherical and cylindrical frames by # In[10]: spherical_frame = E.spherical_frame() spherical_frame # In[11]: cylindrical_frame = E.cylindrical_frame() cylindrical_frame # On the other side, the coordinate frames are returned by the method `frame()` acting on the coordinate charts: # In[12]: spherical.frame() # In[13]: cylindrical.frame() # ## Charts as maps $\mathbb{E}^3 \rightarrow \mathbb{R}^3$ # The chart of Cartesian coordinates has been constructed at the declaration of `E`; let us denote it by `cartesian`: # In[14]: cartesian = E.cartesian_coordinates() cartesian # Let us consider a point $p\in \mathbb{E}^3$, defined by its Cartesian coordinates: # In[15]: p = E((-1, 1,0), chart=cartesian, name='p') print(p) # In[16]: p.parent() is E # The coordinates of $p$ in a given coordinate chart are obtained by letting the corresponding chart act on $p$: # In[17]: cartesian(p) # In[18]: spherical(p) # In[19]: cylindrical(p) # ## Riemannian metric # # The default metric tensor of $\mathbb{E}^3$ is # In[20]: g = E.metric() print(g) # In[21]: g.display() # In[22]: g[:] # The above display in performed in the default frame, which is the Cartesian one. # Of course, we may ask for display with respect to other frames: # In[23]: g.display(spherical_frame) # In[24]: g[spherical_frame,:] # In the above display, $e^r$, $e^\theta$ and $e^\phi$ are the 1-forms defining the coframe dual to the orthonormal spherical frame $(e_r,e_\theta,e_\phi)$: # In[25]: spherical_frame.coframe() # The fact that the above metric components are either 0 or 1 reflect the orthonormality of the vector frame $(e_r,e_\theta,e_\phi)$. On the contrary, in the coordinate frame # $\left(\frac{\partial}{\partial r}, \frac{\partial}{\partial\theta}, \frac{\partial}{\partial \phi}\right)$, which is not orthonormal, the components differ from 0 or 1: # In[26]: g.display(spherical.frame()) # Note that the components are expressed in terms of the default chart, namely the Cartesian one. To have them displayed in terms of the spherical chart, we have to provide the latter as the second argument of the method `display()`: # In[27]: g.display(spherical.frame(), spherical) # In[28]: g[spherical.frame(),:, spherical] # Similarly, for cylindrical coordinates, we have: # In[29]: g.display(cylindrical_frame) # In[30]: g.display(cylindrical.frame(), cylindrical) # In[31]: g[cylindrical.frame(),:,cylindrical] # The metric $g$ is a *flat*: its (Riemann) curvature tensor is zero: # In[32]: print(g.riemann()) # In[33]: g.riemann().display() # The metric $g$ is defining the dot product on $\mathbb{E}^3$: # In[34]: u = E.vector_field(x*y, y*z, z*x) u.display() # In[35]: v = E.vector_field(-y, x, z^2, name='v') v.display() # In[36]: u.dot(v) == g(u,v) # In[37]: norm(u) == sqrt(g(u,u)) # ### The Levi-Civita tensor # # The scalar triple product of $\mathbb{E}^3$ is provided by the Levi-Civita tensor (also called *volume form*) associated with $g$ (and chosen such that $(e_x,e_y,e_z)$ is right-handed): # In[38]: epsilon = E.scalar_triple_product() print(epsilon) # In[39]: epsilon is E.volume_form() # In[40]: epsilon.display() # In[41]: epsilon.display(spherical.frame(), spherical) # In[42]: epsilon.display(cylindrical.frame(), cylindrical) # Checking that all orthonormal frames introduced above are right-handed: # In[43]: ex, ey, ez = E.cartesian_frame()[:] epsilon(ex, ey, ez).display() # In[44]: epsilon(*spherical_frame) # In[45]: epsilon(*spherical_frame).display() # In[46]: epsilon(*cylindrical_frame).display() # ## Vector fields as derivatives # Let $f$ be a scalar field on $\mathbb{E}^3$: # In[47]: f = E.scalar_field(x^2+y^2 - z^2, name='f') f.display() # Vector fields acts as derivative on scalar fields: # In[48]: print(v(f)) # In[49]: v(f).display() # In[50]: v(f) == v.dot(f.gradient()) # In[51]: df = f.differential() print(df) # In[52]: df.display() # In[53]: v(f) == df(v) # ## The algebra of scalar fields # # The set $C^\infty(\mathbb{E}^3)$ of all smooth scalar fields on $\mathbb{E}^3$ forms a commutative algebra over $\mathbb{R}$: # In[54]: CE = E.scalar_field_algebra() CE # In[55]: CE.category() # In[56]: f in CE # In SageMath terminology $C^\infty(\mathbb{E}^3)$ is the parent of scalar fields: # In[57]: f.parent() is CE # ## The free module of vector fields # # The set $\mathfrak{X}(\mathbb{E}^3)$ of all vector fields on $\mathbb{E}^3$ is a free module of rank 3 over the commutative algebra $C^\infty(\mathbb{E}^3)$: # In[58]: XE = v.parent() print(XE) XE # In[59]: print(XE.category()) # In[60]: print(XE.base_ring()) XE.base_ring() # In[61]: XE.base_ring() is CE # In[62]: rank(XE) # The bases of the free module $\mathfrak{X}(\mathbb{E}^3)$ are nothing but the vector frames defined on $\mathbb{E}^3$: # In[63]: XE.bases() # ## Tangent spaces # Vector fields evaluated at a point are vectors in the tangent space at this point: # In[64]: print(p) # In[65]: vp = v.at(p) vp.display() # In[66]: Tp = vp.parent() print(Tp) Tp # In[67]: print(Tp.category()) # In[68]: dim(Tp) # In[69]: isinstance(Tp, FiniteRankFreeModule) # The bases on $T_p\mathbb{E}^3$ are inherited from the vector frames of $\mathbb{E}^3$: # In[70]: Tp.bases() # For instance, we have: # In[71]: spherical_frame.at(p) # In[72]: spherical_frame.at(p) in Tp.bases() # ## Levi-Civita connection # # The Levi-Civita connection associated to the Euclidean metric $g$ is # In[73]: nabla = g.connection() print(nabla) nabla # The corresponding Christoffel symbols with respect to Cartesian coordinates are identically zero: none of them appear in the output of `christoffel_symbols_display`, which by default displays only nonzero Christoffel symbols: # In[74]: g.christoffel_symbols_display(cartesian) # On the contrary, some of the Christoffel symbols with respect to spherical coordinates differ from zero: # In[75]: g.christoffel_symbols_display(spherical) # By default, only nonzero and nonredundant values are displayed (for instance $\Gamma^\phi_{\ \, \phi r}$ is skipped, since it can be deduced from $\Gamma^\phi_{\ \, r \phi}$ by symmetry on the last two indices). # # Similarly, the nonzero Christoffel symbols with respect to cylindrical coordinates are # In[76]: g.christoffel_symbols_display(cylindrical) # The Christoffel symbols are nothing but the connection coefficient in the corresponding coordinate frame: # In[77]: nabla.display(cylindrical.frame(), cylindrical) # The connection coefficients with respect to the orthonormal (non-coordinate) frames are (again only nonzero values are displayed): # In[78]: nabla.display(spherical_frame, spherical) # In[79]: nabla.display(cylindrical_frame, cylindrical) # $\nabla_g$ is the connection involved in differential operators: # In[80]: from sage.manifolds.operators import * # In[81]: grad(f) == nabla(f).up(g) # In[82]: nabla(f) == grad(f).down(g) # In[83]: div(u) == nabla(u).trace() # In[84]: div(v) == nabla(v).trace() # In[85]: laplacian(f) == nabla(nabla(f).up(g)).trace() # In[86]: laplacian(u) == nabla(nabla(u).up(g)).trace(1,2) # In[87]: laplacian(v) == nabla(nabla(v).up(g)).trace(1,2)