Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add a bit of typing to manifolds
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Jun 1, 2020
1 parent 860e4dc commit e620d05
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/sage/manifolds/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None,
from sage.plot.graphics import Graphics
from sage.plot.line import line
from sage.manifolds.continuous_map import ContinuousMap
from .utilities import set_axes_labels
from sage.manifolds.utilities import set_axes_labels

# Extract the kwds options
max_range = kwds['max_range']
Expand Down
3 changes: 2 additions & 1 deletion src/sage/manifolds/differentiable/degenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from sage.rings.infinity import infinity
from sage.manifolds.structure import DegenerateStructure
from sage.manifolds.differentiable.manifold import DifferentiableManifold
from sage.manifolds.differentiable.metric import DegenerateMetric

###############################################################################

Expand Down Expand Up @@ -141,7 +142,7 @@ def __init__(self, n, name, metric_name='g', signature=None, base_manifold=None,
self._metric_latex_name = metric_latex_name

def metric(self, name=None, signature=None, latex_name=None,
dest_map=None):
dest_map=None) -> DegenerateMetric:
r"""
Return the metric giving the null manifold structure to the
manifold, or define a new metric tensor on the manifold.
Expand Down
6 changes: 3 additions & 3 deletions src/sage/manifolds/differentiable/degenerate_submanifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
TangentTensor)
from sage.manifolds.differentiable.differentiable_submanifold import \
DifferentiableSubmanifold
from sage.manifolds.differentiable.metric import DegenerateMetric
from sage.manifolds.differentiable.vectorfield_module import VectorFieldModule
from sage.rings.infinity import infinity
from sage.matrix.constructor import matrix
Expand Down Expand Up @@ -596,14 +597,13 @@ def screen(self, name, screen, rad, latex_name=None):
self._default_screen = self._screens[name]
return self._screens[name]

def induced_metric(self):
def induced_metric(self) -> DegenerateMetric:
r"""
Return the pullback of the ambient metric.
OUTPUT:
- induced mettric, as an instance of
:class:`~sage.manifolds.differentiable.metric.DegenerateMetric`
- induced mettric
EXAMPLES:
Expand Down
58 changes: 51 additions & 7 deletions src/sage/manifolds/differentiable/manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,17 @@

from sage.categories.manifolds import Manifolds
from sage.categories.homset import Hom
from sage.manifolds.continuous_map import ContinuousMap
from sage.manifolds.differentiable.diff_map import DiffMap
from sage.rings.all import CC
from sage.rings.real_mpfr import RR
from sage.rings.infinity import infinity, minus_infinity
from sage.rings.integer import Integer
from sage.manifolds.manifold import TopologicalManifold
from sage.manifolds.differentiable.mixed_form_algebra import MixedFormAlgebra
from sage.manifolds.differentiable.vectorfield_module import VectorFieldModule
from sage.manifolds.differentiable.metric import PseudoRiemannianMetric
from sage.misc.cachefunc import cached_method

###############################################################################

Expand Down Expand Up @@ -1200,24 +1205,23 @@ def tensor_bundle(self, k, l, dest_map=None):
dest_map=dest_map)
return self._tensor_bundles[dest_map][(k, l)]

def vector_field_module(self, dest_map=None, force_free=False):
def vector_field_module(self, dest_map: DiffMap=None, force_free=False) -> VectorFieldModule:
r"""
Return the set of vector fields defined on ``self``, possibly
with values in another differentiable manifold, as a module over the
algebra of scalar fields defined on the manifold.
That is, returns `\Gamma^\infty(\Phi^* TN)` where `\Phi:\ M \to N` is a smooth map.
See :class:`~sage.manifolds.differentiable.vectorfield_module.VectorFieldModule`
for a complete documentation.
INPUT:
- ``dest_map`` -- (default: ``None``) destination map, i.e. a
differentiable map `\Phi:\ M \rightarrow N`, where `M` is the
differentiable map `\Phi:\ M \to N`, where `M` is the
current manifold and `N` a differentiable manifold;
if ``None``, it is assumed that `N = M` and that `\Phi` is the
identity map (case of vector fields *on* `M`), otherwise
``dest_map`` must be a
:class:`~sage.manifolds.differentiable.diff_map.DiffMap`
identity map (case of vector fields *on* `M`)
- ``force_free`` -- (default: ``False``) if set to ``True``, force
the construction of a *free* module (this implies that `N` is
parallelizable)
Expand Down Expand Up @@ -1350,7 +1354,7 @@ def vector_field_module(self, dest_map=None, force_free=False):
VectorFieldModule, VectorFieldFreeModule
if dest_map is None:
dest_map = self.identity_map()
codomain = dest_map._codomain
codomain = dest_map.codomain()
if dest_map not in self._vector_field_modules:
if codomain.is_manifestly_parallelizable() or force_free:
self._vector_field_modules[dest_map] = \
Expand Down Expand Up @@ -3703,7 +3707,7 @@ def affine_connection(self, name, latex_name=None):
AffineConnection
return AffineConnection(self, name, latex_name)

def metric(self, name, signature=None, latex_name=None, dest_map=None):
def metric(self, name, signature=None, latex_name=None, dest_map=None) -> PseudoRiemannianMetric:
r"""
Define a pseudo-Riemannian metric on the manifold.
Expand Down Expand Up @@ -3936,3 +3940,43 @@ class :class:`~sage.manifolds.differentiable.diff_map.DiffMap`
else:
signat = 2 - dim
return vmodule.metric(name, signature=signat, latex_name=latex_name)

@cached_method
def identity_map(self) -> DiffMap:
r"""
Identity map of ``self``.
The identity map of a differentiable manifold `M` is the trivial
diffeomorphism:
.. MATH::
\begin{array}{cccc}
\mathrm{Id}_M: & M & \longrightarrow & M \\
& p & \longmapsto & p
\end{array}
OUTPUT:
- the identity map
EXAMPLES:
Identity map of a differentiable manifold::
sage: M = Manifold(2, 'M', structure='differentiable')
sage: id = M.identity_map(); id
Identity map Id_M of the 2-dimensional differentiable manifold M
sage: id.display()
Id_M: M --> M
sage: isinstance(id, DiffMap)
True
Identity map of a topological manifold is not smooth::
sage: M = Manifold(2, 'M', structure='topological')
sage: isinstance(M.identity_map(), DiffMap)
False
"""
return Hom(self, self).one()
15 changes: 11 additions & 4 deletions src/sage/manifolds/differentiable/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# *****************************************************************************
from typing import overload, TYPE_CHECKING

from sage.rings.integer import Integer
from sage.manifolds.differentiable.tensorfield import TensorField
from sage.manifolds.differentiable.tensorfield_paral import TensorFieldParal
if TYPE_CHECKING:
from sage.manifolds.differentiable.diff_form import DiffForm


class PseudoRiemannianMetric(TensorField):
Expand Down Expand Up @@ -788,8 +791,7 @@ def connection(self, name=None, latex_name=None, init_coef=True):
True
"""
from sage.manifolds.differentiable.levi_civita_connection import \
LeviCivitaConnection
from sage.manifolds.differentiable.levi_civita_connection import LeviCivitaConnection
if self._connection is None:
if latex_name is None:
if name is None:
Expand Down Expand Up @@ -1616,6 +1618,12 @@ def sqrt_abs_det(self, frame=None):
self._sqrt_abs_dets[frame] = resu
return self._sqrt_abs_dets[frame]

@overload
def volume_form(self) -> 'DiffForm':
pass
@overload
def volume_form(self, contra: int) -> TensorField:
pass
def volume_form(self, contra=0):
r"""
Volume form (Levi-Civita tensor) `\epsilon` associated with the metric.
Expand Down Expand Up @@ -1907,8 +1915,7 @@ def hodge_star(self, pform):
"""
from sage.functions.other import factorial
from sage.tensor.modules.format_utilities import format_unop_txt, \
format_unop_latex
from sage.tensor.modules.format_utilities import format_unop_txt, format_unop_latex
p = pform.tensor_type()[1]
eps = self.volume_form(p)
if p == 0:
Expand Down
33 changes: 15 additions & 18 deletions src/sage/manifolds/differentiable/vectorfield_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
# http://www.gnu.org/licenses/
#******************************************************************************

from sage.manifolds.differentiable.diff_map import DiffMap
from sage.manifolds.differentiable.manifold import DifferentiableManifold
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.categories.modules import Modules
Expand All @@ -59,7 +61,7 @@ class VectorFieldModule(UniqueRepresentation, Parent):
\Phi:\ U \longrightarrow M,
the *vector field module* `\mathfrak{X}(U,\Phi)` is the set of
the *vector field module* `\mathfrak{X}(U,\Phi) = \Gamma(\Phi^* TM)` is the set of
all vector fields of the type
.. MATH::
Expand All @@ -73,6 +75,7 @@ class VectorFieldModule(UniqueRepresentation, Parent):
\forall p \in U,\ v(p) \in T_{\Phi(p)}M,
where `T_{\Phi(p)}M` is the tangent space to `M` at the point `\Phi(p)`.
Thus elements of `\mathfrak{X}(U,\Phi)` are vector fields along `\Phi`.
The set `\mathfrak{X}(U,\Phi)` is a module over `C^k(U)`, the ring
(algebra) of differentiable scalar fields on `U` (see
Expand Down Expand Up @@ -103,9 +106,8 @@ class VectorFieldModule(UniqueRepresentation, Parent):
- ``domain`` -- differentiable manifold `U` along which the
vector fields are defined
- ``dest_map`` -- (default: ``None``) destination map
- ``dest_map`` -- (default: ``None``) smooth destination map
`\Phi:\ U \rightarrow M`
(type: :class:`~sage.manifolds.differentiable.diff_map.DiffMap`);
if ``None``, it is assumed that `U = M` and `\Phi` is the identity
map of `M` (case of vector fields *on* `M`)
Expand Down Expand Up @@ -181,7 +183,7 @@ class VectorFieldModule(UniqueRepresentation, Parent):
"""
Element = VectorField

def __init__(self, domain, dest_map=None):
def __init__(self, domain: DifferentiableManifold, dest_map: DiffMap=None):
r"""
Construct the module of vector fields taking values on a (a priori)
non-parallelizable differentiable manifold.
Expand Down Expand Up @@ -227,7 +229,7 @@ def __init__(self, domain, dest_map=None):
latex_name += "," + dm_latex_name
self._name = name + ")"
self._latex_name = latex_name + r"\right)"
self._ambient_domain = self._dest_map._codomain
self._ambient_domain = self._dest_map.codomain()
# The member self._ring is created for efficiency (to avoid
# calls to self.base_ring()):
self._ring = domain.scalar_field_algebra()
Expand Down Expand Up @@ -1539,7 +1541,7 @@ def _repr_(self):
" mapped into the {}".format(self._ambient_domain)
return description

def domain(self):
def domain(self) -> DifferentiableManifold:
r"""
Return the domain of the vector fields in ``self``.
Expand All @@ -1548,10 +1550,8 @@ def domain(self):
OUTPUT:
- a
:class:`~sage.manifolds.differentiable.manifold.DifferentiableManifold`
representing the domain of the vector fields that belong to this
module
- a differentiable manifold representing the domain of the vector fields
that belong to this module
EXAMPLES::
Expand All @@ -1570,7 +1570,7 @@ def domain(self):
"""
return self._domain

def ambient_domain(self):
def ambient_domain(self) -> DifferentiableManifold:
r"""
Return the manifold in which the vector fields of ``self``
take their values.
Expand All @@ -1580,10 +1580,8 @@ def ambient_domain(self):
OUTPUT:
- a
:class:`~sage.manifolds.differentiable.manifold.DifferentiableManifold`
representing the manifold in which the vector fields of ``self``
take their values
- a differentiable manifold representing the manifold in which the
vector fields of ``self`` take their values
EXAMPLES::
Expand All @@ -1602,7 +1600,7 @@ def ambient_domain(self):
"""
return self._ambient_domain

def destination_map(self):
def destination_map(self) -> DiffMap:
r"""
Return the differential map associated to ``self``.
Expand Down Expand Up @@ -1630,8 +1628,7 @@ def destination_map(self):
OUTPUT:
- a :class:`~sage.manifolds.differentiable.diff_map.DiffMap`
representing the differential map `\Phi`
- the differentiable map `\Phi`
EXAMPLES::
Expand Down
10 changes: 7 additions & 3 deletions src/sage/manifolds/manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@
from sage.manifolds.structure import(
TopologicalStructure, RealTopologicalStructure,
DifferentialStructure, RealDifferentialStructure)
from typing import Union, TYPE_CHECKING, Optional
if TYPE_CHECKING:
from sage.manifolds.differentiable.manifold import DifferentiableManifold
from sage.manifolds.continuous_map import ContinuousMap


#############################################################################
Expand Down Expand Up @@ -2143,7 +2147,7 @@ def homeomorphism(self, codomain, coord_functions=None, chart1=None,
is_isomorphism=True)

@cached_method
def identity_map(self):
def identity_map(self) -> 'ContinuousMap':
r"""
Identity map of ``self``.
Expand Down Expand Up @@ -2399,8 +2403,8 @@ def set_simplify_function(self, simplifying_func, method=None):

_manifold_id = Integer(0)

def Manifold(dim, name, latex_name=None, field='real', structure='smooth',
start_index=0, **extra_kwds):
def Manifold(dim:int, name:Optional[str], latex_name:Optional[str]=None, field='real', structure='smooth',
start_index=0, **extra_kwds) -> Union[TopologicalManifold, 'DifferentiableManifold']:
r"""
Construct a manifold of a given type over a topological field.
Expand Down
Loading

0 comments on commit e620d05

Please sign in to comment.