Euclidean Spaces¶
An Euclidean space of dimension \(n\) is an affine space \(E\), whose associated vector space is a \(n\)-dimensional vector space over \(\RR\) and is equipped with a positive definite symmetric bilinear form, called the scalar product or dot product [Ber1987]. An Euclidean space of dimension \(n\) can also be viewed as a Riemannian manifold that is diffeomorphic to \(\RR^n\) and that has a flat metric \(g\). The Euclidean scalar product is then that defined by the Riemannian metric \(g\).
The current implementation of Euclidean spaces is based on the second point of
view. This allows for the introduction of various coordinate systems in
addition to the usual the Cartesian systems. Standard curvilinear systems
(planar, spherical and cylindrical coordinates) are predefined for
2-dimensional and 3-dimensional Euclidean spaces, along with the corresponding
transition maps between them. Another benefit of such an implementation is
the direct use of methods for vector calculus already implemented at the
level of Riemannian manifolds (see, e.g., the methods
cross_product()
and
curl()
,
as well as the module operators
).
Euclidean spaces are implemented via the following classes:
EuclideanSpace
for generic values \(n\),EuclideanPlane
for \(n = 2\),Euclidean3dimSpace
for \(n = 3\).
The user interface is provided by EuclideanSpace
.
Example 1: the Euclidean plane
We start by declaring the Euclidean plane E
, with (x, y)
as
Cartesian coordinates:
sage: E.<x,y> = EuclideanSpace()
sage: E
Euclidean plane E^2
sage: dim(E)
2
E
is automatically endowed with the chart of Cartesian coordinates:
sage: E.atlas()
[Chart (E^2, (x, y))]
sage: cartesian = E.default_chart(); cartesian
Chart (E^2, (x, y))
Thanks to the use of <x,y>
when declaring E
, the coordinates \((x,y)\)
have been injected in the global namespace, i.e. the Python variables x
and y
have been created and are available to form symbolic expressions:
sage: y
y
sage: type(y)
<type 'sage.symbolic.expression.Expression'>
sage: assumptions()
[x is real, y is real]
The metric tensor of E
is predefined:
sage: g = E.metric(); g
Riemannian metric g on the Euclidean plane E^2
sage: g.display()
g = dx*dx + dy*dy
sage: g[:]
[1 0]
[0 1]
It is a flat metric, i.e. it has a vanishing Riemann tensor:
sage: g.riemann()
Tensor field Riem(g) of type (1,3) on the Euclidean plane E^2
sage: g.riemann().display()
Riem(g) = 0
Polar coordinates \((r,\phi)\) are introduced by:
sage: polar.<r,ph> = E.polar_coordinates()
sage: polar
Chart (E^2, (r, ph))
E
is now endowed with two coordinate charts:
sage: E.atlas()
[Chart (E^2, (x, y)), Chart (E^2, (r, ph))]
The ranges of the coordinates introduced so far are:
sage: cartesian.coord_range()
x: (-oo, +oo); y: (-oo, +oo)
sage: polar.coord_range()
r: (0, +oo); ph: (0, 2*pi)
The transition map from polar coordinates to Cartesian ones is:
sage: E.coord_change(polar, cartesian).display()
x = r*cos(ph)
y = r*sin(ph)
while the reverse one is:
sage: E.coord_change(cartesian, polar).display()
r = sqrt(x^2 + y^2)
ph = arctan2(y, x)
A point of E
is constructed from its coordinates (by default in the
Cartesian chart):
sage: p = E((-1,1), name='p'); p
Point p on the Euclidean plane E^2
sage: p.parent()
Euclidean plane E^2
The coordinates of a point are obtained by letting the corresponding chart act on it:
sage: cartesian(p)
(-1, 1)
sage: polar(p)
(sqrt(2), 3/4*pi)
At this stage, E
is endowed with three vector frames:
sage: E.frames()
[Coordinate frame (E^2, (e_x,e_y)),
Coordinate frame (E^2, (d/dr,d/dph)),
Vector frame (E^2, (e_r,e_ph))]
The third one is the standard orthonormal frame associated with polar coordinates, as we can check from the metric components in it:
sage: polar_frame = E.polar_frame(); polar_frame
Vector frame (E^2, (e_r,e_ph))
sage: g[polar_frame,:]
[1 0]
[0 1]
The expression of the metric tensor in terms of polar coordinates is:
sage: g.display(polar.frame(), polar)
g = dr*dr + r^2 dph*dph
A vector field on E
:
sage: v = E.vector_field(-y, x, name='v'); v
Vector field v on the Euclidean plane E^2
sage: v.display()
v = -y e_x + x e_y
sage: v[:]
[-y, x]
By default, the components of v
, as returned by display
or the bracket
operator, refer to the Cartesian frame on E
; to get the components with
respect to the orthonormal polar frame, one has to specify it explicitly,
generally along with the polar chart for the coordinate expression of the
components:
sage: v.display(polar_frame, polar)
v = r e_ph
sage: v[polar_frame,:,polar]
[0, r]
Note that the default frame for the display of vector fields can be changed
thanks to the method
set_default_frame()
;
in the same vein, the default coordinates can be changed via the method
set_default_chart()
:
sage: E.set_default_frame(polar_frame)
sage: E.set_default_chart(polar)
sage: v.display()
v = r e_ph
sage: v[:]
[0, r]
sage: E.set_default_frame(E.cartesian_frame()) # revert to Cartesian frame
sage: E.set_default_chart(cartesian) # and chart
The value of v
at point p
:
sage: vp = v.at(p); vp
Vector v at Point p on the Euclidean plane E^2
sage: vp.display()
v = -e_x - e_y
sage: vp.display(polar_frame.at(p))
v = sqrt(2) e_ph
A scalar field on E
:
sage: f = E.scalar_field(x*y, name='f'); f
Scalar field f on the Euclidean plane E^2
sage: f.display()
f: E^2 --> R
(x, y) |--> x*y
(r, ph) |--> r^2*cos(ph)*sin(ph)
The value of f
at point p
:
sage: f(p)
-1
The gradient of f
:
sage: from sage.manifolds.operators import * # to get grad, div, etc.
sage: w = grad(f); w
Vector field grad(f) on the Euclidean plane E^2
sage: w.display()
grad(f) = y e_x + x e_y
sage: w.display(polar_frame, polar)
grad(f) = 2*r*cos(ph)*sin(ph) e_r + (2*cos(ph)^2 - 1)*r e_ph
The dot product of two vector fields:
sage: s = v.dot(w); s
Scalar field v.grad(f) on the Euclidean plane E^2
sage: s.display()
v.grad(f): E^2 --> R
(x, y) |--> x^2 - y^2
(r, ph) |--> (2*cos(ph)^2 - 1)*r^2
sage: s.expr()
x^2 - y^2
The norm is related to the dot product by the standard formula:
sage: norm(v)^2 == v.dot(v)
True
The divergence of the vector field v
:
sage: s = div(v); s
Scalar field div(v) on the Euclidean plane E^2
sage: s.display()
div(v): E^2 --> R
(x, y) |--> 0
(r, ph) |--> 0
Example 2: Vector calculus in the Euclidean 3-space
We start by declaring the 3-dimensional Euclidean space E
, with
(x,y,z)
as Cartesian coordinates:
sage: E.<x,y,z> = EuclideanSpace()
sage: E
Euclidean space E^3
A simple vector field on E
:
sage: v = E.vector_field(-y, x, 0, name='v')
sage: v.display()
v = -y e_x + x e_y
sage: v[:]
[-y, x, 0]
The Euclidean norm of v
:
sage: s = norm(v); s
Scalar field |v| on the Euclidean space E^3
sage: s.display()
|v|: E^3 --> R
(x, y, z) |--> sqrt(x^2 + y^2)
sage: s.expr()
sqrt(x^2 + y^2)
The divergence of v
is zero:
sage: from sage.manifolds.operators import *
sage: div(v)
Scalar field div(v) on the Euclidean space E^3
sage: div(v).display()
div(v): E^3 --> R
(x, y, z) |--> 0
while its curl is a constant vector field along \(e_z\):
sage: w = curl(v); w
Vector field curl(v) on the Euclidean space E^3
sage: w.display()
curl(v) = 2 e_z
The gradient of a scalar field:
sage: f = E.scalar_field(sin(x*y*z), name='f')
sage: u = grad(f); u
Vector field grad(f) on the Euclidean space E^3
sage: u.display()
grad(f) = y*z*cos(x*y*z) e_x + x*z*cos(x*y*z) e_y + x*y*cos(x*y*z) e_z
The curl of a gradient is zero:
sage: curl(u).display()
curl(grad(f)) = 0
The dot product of two vector fields:
sage: s = u.dot(v); s
Scalar field grad(f).v on the Euclidean space E^3
sage: s.expr()
(x^2 - y^2)*z*cos(x*y*z)
The cross product of two vector fields:
sage: a = u.cross(v); a
Vector field grad(f) x v on the Euclidean space E^3
sage: a.display()
grad(f) x v = -x^2*y*cos(x*y*z) e_x - x*y^2*cos(x*y*z) e_y
+ 2*x*y*z*cos(x*y*z) e_z
The scalar triple product of three vector fields:
sage: triple_product = E.scalar_triple_product()
sage: s = triple_product(u, v, w); s
Scalar field epsilon(grad(f),v,curl(v)) on the Euclidean space E^3
sage: s.expr()
4*x*y*z*cos(x*y*z)
Let us check that the scalar triple product of \(u\), \(v\) and \(w\) is \(u\cdot(v\times w)\):
sage: s == u.dot(v.cross(w))
True
AUTHORS:
- Eric Gourgoulhon (2018): initial version
REFERENCES:
- M. Berger: Geometry I [Ber1987]
-
sage.manifolds.differentiable.euclidean.
Euclidean3dimSpace
¶ 3-dimensional Euclidean space.
A 3-dimensional Euclidean space is an affine space \(E\), whose associated vector space is a 3-dimensional vector space over \(\RR\) and is equipped with a positive definite symmetric bilinear form, called the scalar product or dot product.
The class
Euclidean3dimSpace
inherits fromPseudoRiemannianManifold
(viaEuclideanSpace
) since a 3-dimensional Euclidean space can be viewed as a Riemannian manifold that is diffeomorphic to \(\RR^3\) and that has a flat metric \(g\). The Euclidean scalar product is the one defined by the Riemannian metric \(g\).INPUT:
name
– (default:None
) string; name (symbol) given to the Euclidean 3-space; ifNone
, the name will be set to'E^3'
latex_name
– (default:None
) string; LaTeX symbol to denote the Euclidean 3-space; ifNone
, it is set to'\mathbb{E}^{3}'
ifname
isNone
and toname
otherwisecoordinates
– (default:'Cartesian'
) string describing the type of coordinates to be initialized at the Euclidean 3-space creation; allowed values are'Cartesian'
(seecartesian_coordinates()
),'spherical'
(seespherical_coordinates()
) and'cylindrical'
(seecylindrical_coordinates()
)symbols
– (default:None
) string defining the coordinate text symbols and LaTeX symbols, with the same conventions as the argumentcoordinates
inRealDiffChart
, namelysymbols
is a string of coordinate fields separated by a blank space, where each field contains the coordinate’s text symbol and possibly the coordinate’s LaTeX symbol (when the latter is different from the text symbol), both symbols being separated by a colon (:
); ifNone
, the symbols will be automatically generated according to the value ofcoordinates
metric_name
– (default:'g'
) string; name (symbol) given to the Euclidean metric tensormetric_latex_name
– (default:None
) string; LaTeX symbol to denote the Euclidean metric tensor; if none is provided, it is set tometric_name
start_index
– (default: 1) integer; lower value of the range of indices used for “indexed objects” in the Euclidean 3-space, e.g. coordinates of a chartbase_manifold
– (default:None
) if notNone
, must be an Euclidean 3-space; the created object is then an open subset ofbase_manifold
category
– (default:None
) to specify the category; ifNone
,Manifolds(RR).Differentiable()
(orManifolds(RR).Smooth()
ifdiff_degree
=infinity
) is assumed (see the categoryManifolds
)names
– (default:None
) unused argument, except ifsymbols
is not provided; it must then be a tuple containing the coordinate symbols (this is guaranteed if the shortcut operator<,>
is used)init_coord_methods
– (default:None
) dictionary of methods to initialize the various type of coordinates, with each key being a string describing the type of coordinates; to be used by derived classes onlyunique_tag
– (default:None
) tag used to force the construction of a new object when all the other arguments have been used previously (withoutunique_tag
, theUniqueRepresentation
behavior inherited fromPseudoRiemannianManifold
would return the previously constructed object corresponding to these arguments)
EXAMPLES:
A 3-dimensional Euclidean space:
sage: E = EuclideanSpace(3); E Euclidean space E^3 sage: latex(E) \mathbb{E}^{3}
E
belongs to the classEuclidean3dimSpace
(actually to a dynamically generated subclass of it via SageMath’s category framework):sage: type(E) <class 'sage.manifolds.differentiable.euclidean.Euclidean3dimSpace_with_category'>
E
is a real smooth manifold of dimension 3:sage: E.category() Category of smooth manifolds over Real Field with 53 bits of precision sage: dim(E) 3
It is endowed with a default coordinate chart, which is that of Cartesian coordinates \((x,y,z)\):
sage: E.atlas() [Chart (E^3, (x, y, z))] sage: E.default_chart() Chart (E^3, (x, y, z)) sage: cartesian = E.cartesian_coordinates() sage: cartesian is E.default_chart() True
A point of
E
:sage: p = E((3,-2,1)); p Point on the Euclidean space E^3 sage: cartesian(p) (3, -2, 1) sage: p in E True sage: p.parent() is E True
E
is endowed with a default metric tensor, which defines the Euclidean scalar product:sage: g = E.metric(); g Riemannian metric g on the Euclidean space E^3 sage: g.display() g = dx*dx + dy*dy + dz*dz
Curvilinear coordinates can be introduced on
E
: seespherical_coordinates()
andcylindrical_coordinates()
.
-
sage.manifolds.differentiable.euclidean.
EuclideanPlane
¶ Euclidean plane.
An Euclidean plane is an affine space \(E\), whose associated vector space is a 2-dimensional vector space over \(\RR\) and is equipped with a positive definite symmetric bilinear form, called the scalar product or dot product.
The class
EuclideanPlane
inherits fromPseudoRiemannianManifold
(viaEuclideanSpace
) since an Euclidean plane can be viewed as a Riemannian manifold that is diffeomorphic to \(\RR^2\) and that has a flat metric \(g\). The Euclidean scalar product is the one defined by the Riemannian metric \(g\).INPUT:
name
– (default:None
) string; name (symbol) given to the Euclidean plane; ifNone
, the name will be set to'E^2'
latex_name
– (default:None
) string; LaTeX symbol to denote the Euclidean plane; ifNone
, it is set to'\mathbb{E}^{2}'
ifname
isNone
and toname
otherwisecoordinates
– (default:'Cartesian'
) string describing the type of coordinates to be initialized at the Euclidean plane creation; allowed values are'Cartesian'
(seecartesian_coordinates()
) and'polar'
(seepolar_coordinates()
)symbols
– (default:None
) string defining the coordinate text symbols and LaTeX symbols, with the same conventions as the argumentcoordinates
inRealDiffChart
, namelysymbols
is a string of coordinate fields separated by a blank space, where each field contains the coordinate’s text symbol and possibly the coordinate’s LaTeX symbol (when the latter is different from the text symbol), both symbols being separated by a colon (:
); ifNone
, the symbols will be automatically generated according to the value ofcoordinates
metric_name
– (default:'g'
) string; name (symbol) given to the Euclidean metric tensormetric_latex_name
– (default:None
) string; LaTeX symbol to denote the Euclidean metric tensor; if none is provided, it is set tometric_name
start_index
– (default: 1) integer; lower value of the range of indices used for “indexed objects” in the Euclidean plane, e.g. coordinates of a chartbase_manifold
– (default:None
) if notNone
, must be an Euclidean plane; the created object is then an open subset ofbase_manifold
category
– (default:None
) to specify the category; ifNone
,Manifolds(RR).Differentiable()
(orManifolds(RR).Smooth()
ifdiff_degree
=infinity
) is assumed (see the categoryManifolds
)names
– (default:None
) unused argument, except ifsymbols
is not provided; it must then be a tuple containing the coordinate symbols (this is guaranteed if the shortcut operator<,>
is used)init_coord_methods
– (default:None
) dictionary of methods to initialize the various type of coordinates, with each key being a string describing the type of coordinates; to be used by derived classes onlyunique_tag
– (default:None
) tag used to force the construction of a new object when all the other arguments have been used previously (withoutunique_tag
, theUniqueRepresentation
behavior inherited fromPseudoRiemannianManifold
would return the previously constructed object corresponding to these arguments)
EXAMPLES:
One creates an Euclidean plane
E
with:sage: E.<x,y> = EuclideanSpace(); E Euclidean plane E^2
E
is a real smooth manifold of dimension 2:sage: E.category() Category of smooth manifolds over Real Field with 53 bits of precision sage: dim(E) 2
It is endowed with a default coordinate chart, which is that of Cartesian coordinates \((x,y)\):
sage: E.atlas() [Chart (E^2, (x, y))] sage: E.default_chart() Chart (E^2, (x, y)) sage: cartesian = E.cartesian_coordinates() sage: cartesian is E.default_chart() True
A point of
E
:sage: p = E((3,-2)); p Point on the Euclidean plane E^2 sage: cartesian(p) (3, -2) sage: p in E True sage: p.parent() is E True
E
is endowed with a default metric tensor, which defines the Euclidean scalar product:sage: g = E.metric(); g Riemannian metric g on the Euclidean plane E^2 sage: g.display() g = dx*dx + dy*dy
Curvilinear coordinates can be introduced on
E
: seepolar_coordinates()
.See also
-
sage.manifolds.differentiable.euclidean.
EuclideanSpace
¶ Euclidean space.
An Euclidean space of dimension \(n\) is an affine space \(E\), whose associated vector space is a \(n\)-dimensional vector space over \(\RR\) and is equipped with a positive definite symmetric bilinear form, called the scalar product or dot product.
Euclidean space of dimension \(n\) can be viewed as a Riemannian manifold that is diffeomorphic to \(\RR^n\) and that has a flat metric \(g\). The Euclidean scalar product is the one defined by the Riemannian metric \(g\).
INPUT:
n
– positive integer; dimension of the space over the real fieldname
– (default:None
) string; name (symbol) given to the Euclidean space; ifNone
, the name will be set to'E^n'
latex_name
– (default:None
) string; LaTeX symbol to denote the space; ifNone
, it is set to'\mathbb{E}^{n}'
ifname
isNone
and toname
otherwisecoordinates
– (default:'Cartesian'
) string describing the type of coordinates to be initialized at the Euclidean space creation; allowed values are'Cartesian'
(canonical coordinates on \(\RR^n\))'polar'
forn=2
only (seepolar_coordinates()
)'spherical'
forn=3
only (seespherical_coordinates()
)'cylindrical'
forn=3
only (seecylindrical_coordinates()
)
symbols
– (default:None
) string defining the coordinate text symbols and LaTeX symbols, with the same conventions as the argumentcoordinates
inRealDiffChart
, namelysymbols
is a string of coordinate fields separated by a blank space, where each field contains the coordinate’s text symbol and possibly the coordinate’s LaTeX symbol (when the latter is different from the text symbol), both symbols being separated by a colon (:
); ifNone
, the symbols will be automatically generated according to the value ofcoordinates
metric_name
– (default:'g'
) string; name (symbol) given to the Euclidean metric tensormetric_latex_name
– (default:None
) string; LaTeX symbol to denote the Euclidean metric tensor; if none is provided, it is set tometric_name
start_index
– (default: 1) integer; lower value of the range of indices used for “indexed objects” in the Euclidean space, e.g. coordinates of a chartnames
– (default:None
) unused argument, except ifsymbols
is not provided; it must then be a tuple containing the coordinate symbols (this is guaranteed if the shortcut operator<,>
is used)
If
names
is specified, thenn
does not have to be specified.EXAMPLES:
Constructing a 2-dimensional Euclidean space:
sage: E = EuclideanSpace(2); E Euclidean plane E^2
Each call to
EuclideanSpace
creates a different object:sage: E1 = EuclideanSpace(2) sage: E1 is E False sage: E1 == E False
The LaTeX symbol of the Euclidean space is by default \(\mathbb{E}^n\), where \(n\) is the dimension:
sage: latex(E) \mathbb{E}^{2}
But both the name and LaTeX names of the Euclidean space can be customized:
sage: F = EuclideanSpace(2, name='F', latex_name=r'\mathcal{F}'); F Euclidean plane F sage: latex(F) \mathcal{F}
By default, an Euclidean space is created with a single coordinate chart: that of Cartesian coordinates:
sage: E.atlas() [Chart (E^2, (x, y))] sage: E.cartesian_coordinates() Chart (E^2, (x, y)) sage: E.default_chart() is E.cartesian_coordinates() True
The coordinate variables can be initialized, as the Python variables
x
andy
, by:sage: x, y = E.cartesian_coordinates()[:]
However, it is possible to both construct the Euclidean space and initialize the coordinate variables in a single stage, thanks to SageMath operator
<,>
:sage: E.<x,y> = EuclideanSpace()
Note that providing the dimension as an argument of
EuclideanSpace
is not necessary in that case, since it can be deduced from the number of coordinates within<,>
. Besides, the coordinate symbols can be customized:sage: E.<X,Y> = EuclideanSpace() sage: E.cartesian_coordinates() Chart (E^2, (X, Y))
By default, the LaTeX symbols of the coordinates coincide with the text ones:
sage: latex(X+Y) X + Y
However, it is possible to customize them, via the argument
symbols
, which must be a string, usually prefixed byr
(for raw string, in order to allow for the backslash character of LaTeX expressions). This string contains the coordinate fields separated by a blank space; each field contains the coordinate’s text symbol and possibly the coordinate’s LaTeX symbol (when the latter is different from the text symbol), both symbols being separated by a colon (:
):sage: E.<xi,ze> = EuclideanSpace(symbols=r"xi:\xi ze:\zeta") sage: E.cartesian_coordinates() Chart (E^2, (xi, ze)) sage: latex(xi+ze) {\xi} + {\zeta}
Thanks to the argument
coordinates
, an Euclidean space can be constructed with curvilinear coordinates initialized instead of the Cartesian ones:sage: E.<r,ph> = EuclideanSpace(coordinates='polar') sage: E.atlas() # no Cartesian coordinates have been constructed [Chart (E^2, (r, ph))] sage: polar = E.polar_coordinates(); polar Chart (E^2, (r, ph)) sage: E.default_chart() is polar True sage: latex(r+ph) {\phi} + r
The Cartesian coordinates, along with the transition maps to and from the curvilinear coordinates, can be constructed at any time by:
sage: cartesian.<x,y> = E.cartesian_coordinates() sage: E.atlas() # both polar and Cartesian coordinates now exist [Chart (E^2, (r, ph)), Chart (E^2, (x, y))]
The transition maps have been initialized by the command
E.cartesian_coordinates()
:sage: E.coord_change(polar, cartesian).display() x = r*cos(ph) y = r*sin(ph) sage: E.coord_change(cartesian, polar).display() r = sqrt(x^2 + y^2) ph = arctan2(y, x)
The default name of the Euclidean metric tensor is \(g\):
sage: E.metric() Riemannian metric g on the Euclidean plane E^2 sage: latex(_) g
But this can be customized:
sage: E = EuclideanSpace(2, metric_name='h') sage: E.metric() Riemannian metric h on the Euclidean plane E^2 sage: latex(_) h sage: E = EuclideanSpace(2, metric_latex_name=r'\mathbf{g}') sage: E.metric() Riemannian metric g on the Euclidean plane E^2 sage: latex(_) \mathbf{g}
A 4-dimensional Euclidean space:
sage: E = EuclideanSpace(4); E 4-dimensional Euclidean space E^4 sage: latex(E) \mathbb{E}^{4}
E
is a real smooth manifold of dimension \(4\):sage: E.category() Category of smooth manifolds over Real Field with 53 bits of precision sage: dim(E) 4
It is endowed with a default coordinate chart, which is that of Cartesian coordinates \((x_1,x_2,x_3,x_4)\):
sage: E.atlas() [Chart (E^4, (x1, x2, x3, x4))] sage: E.default_chart() Chart (E^4, (x1, x2, x3, x4)) sage: E.default_chart() is E.cartesian_coordinates() True
E
is also endowed with a default metric tensor, which defines the Euclidean scalar product:sage: g = E.metric(); g Riemannian metric g on the 4-dimensional Euclidean space E^4 sage: g.display() g = dx1*dx1 + dx2*dx2 + dx3*dx3 + dx4*dx4