summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Gourgoulhon <eric.gourgoulhon@obspm.fr>2015-12-16 17:27:33 +0100
committerEric Gourgoulhon <eric.gourgoulhon@obspm.fr>2015-12-16 17:27:33 +0100
commitcb534171ae64a7f61a4ea53f41982de0e9eecbd2 (patch)
tree0dd93d4ec6168d0e0a9c51525c78535902929af8
parentSome class renaming; add more examples and doctests (full coverage) (diff)
Add argument full_name to AbstractNamedObject; remove _repr_() from all parent classes; improve documentation
-rw-r--r--src/sage/manifolds/abstract.py67
-rw-r--r--src/sage/manifolds/manifold.py95
-rw-r--r--src/sage/manifolds/subset.py52
3 files changed, 109 insertions, 105 deletions
diff --git a/src/sage/manifolds/abstract.py b/src/sage/manifolds/abstract.py
index f38c128..d7d6c0c 100644
--- a/src/sage/manifolds/abstract.py
+++ b/src/sage/manifolds/abstract.py
@@ -30,11 +30,43 @@ from sage.manifolds.point import ManifoldPoint
class AbstractNamedObject(object):
"""
- An abstract object.
+ An abstract named object.
+
+ This abstract class handles the outputs (text and LaTeX) of named objects
+ (e.g. parent objects in manifold classes).
+
+ INPUT:
+
+ - ``name`` -- (short) string; name (symbol) given to the object
+ - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
+ denote the object; if ``None``, the LaTeX symbol is set to ``name``
+ - ``full_name`` -- (default: ``None``) string; short description of the
+ object; if ``None``, the description is set to ``name``.
+
+ EXAMPLES::
+
+ sage: from sage.manifolds.abstract import AbstractNamedObject
+ sage: a = AbstractNamedObject('A', latex_name=r'\mathcal{A}',
+ ....: full_name='Object A')
+ sage: a._repr_()
+ 'Object A'
+ sage: a._latex_()
+ '\\mathcal{A}'
+ sage: latex(a)
+ \mathcal{A}
+
+ Using default values::
+
+ sage: a = AbstractNamedObject('A')
+ sage: a._repr_()
+ 'A'
+ sage: a._latex_()
+ 'A'
+ sage: latex(a)
+ A
- An abstract object is a variable name and LaTeX name.
"""
- def __init__(self, name, latex_name=None):
+ def __init__(self, name, latex_name=None, full_name=None):
"""
Initialize ``self``.
@@ -49,13 +81,18 @@ class AbstractNamedObject(object):
if not isinstance(name, str):
raise TypeError("{} is not a string".format(name))
self._name = name
-
if latex_name is None:
self._latex_name = self._name
else:
if not isinstance(latex_name, str):
raise TypeError("{} is not a string".format(latex_name))
self._latex_name = latex_name
+ if full_name is None:
+ self.__custom_name = self._name
+ else:
+ if not isinstance(full_name, str):
+ raise TypeError("{} is not a string".format(full_name))
+ self.__custom_name = full_name
def _repr_(self):
"""
@@ -69,7 +106,7 @@ class AbstractNamedObject(object):
'a'
"""
- return self._name
+ return self.__custom_name
def _latex_(self):
r"""
@@ -103,12 +140,25 @@ class AbstractNamedObject(object):
class AbstractSet(AbstractNamedObject, UniqueRepresentation, Parent):
"""
- An abstract set.
+ An abstract set on a topological manifold.
An abstract set is an :class:`AbstractNamedObject` along with its known
subsets, supersets, intersections, unions, and open covers.
+
+ INPUT:
+
+ - ``name`` -- (short) string; name (symbol) given to the object
+ - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
+ denote the object; if ``None``, the LaTeX symbol is set to ``name``
+ - ``full_name`` -- (default: ``None``) string; short description of the
+ object; if ``None``, the description is set to ``name``.
+ - ``base`` -- (default: ``None``) base for the
+ :class:`~sage.structure.parent.Parent` constructor
+ - ``category`` -- (default: ``None``) category of the object
+
"""
- def __init__(self, name, latex_name, base=None, category=None):
+ def __init__(self, name, latex_name=None, full_name=None, base=None,
+ category=None):
r"""
Initialize ``self``
@@ -119,7 +169,8 @@ class AbstractSet(AbstractNamedObject, UniqueRepresentation, Parent):
sage: A = M.subset('A'); A
Subset A of the 2-dimensional topological manifold M
"""
- AbstractNamedObject.__init__(self, name, latex_name)
+ AbstractNamedObject.__init__(self, name, latex_name=latex_name,
+ full_name=full_name)
category = Sets().or_subcategory(category)
Parent.__init__(self, base=base, category=category)
diff --git a/src/sage/manifolds/manifold.py b/src/sage/manifolds/manifold.py
index 7123e21..ea5a699 100644
--- a/src/sage/manifolds/manifold.py
+++ b/src/sage/manifolds/manifold.py
@@ -293,10 +293,11 @@ from sage.rings.complex_field import ComplexField_class
from sage.misc.prandom import getrandbits
from sage.rings.integer import Integer
from sage.manifolds.abstract import AbstractSet
-from sage.manifolds.structure import TopologicalStructure, RealTopologicalStructure
+from sage.manifolds.structure import TopologicalStructure, \
+ RealTopologicalStructure
-#####################################################################
-## Classes
+#############################################################################
+## Class
class TopologicalManifold(AbstractSet):
r"""
@@ -317,9 +318,7 @@ class TopologicalManifold(AbstractSet):
- ``n`` -- positive integer; dimension of the manifold
- ``name`` -- string; name (symbol) given to the manifold
- - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
- denote the manifold; if none is provided, it is set to ``name``
- - ``field`` -- (default: ``'real'``) field `K` on which the manifold is
+ - ``field`` -- field `K` on which the manifold is
defined; allowed values are
- ``'real'`` or an object of type ``RealField`` (e.g., ``RR``) for
@@ -331,15 +330,18 @@ class TopologicalManifold(AbstractSet):
:class:`~sage.categories.topological_spaces.TopologicalSpaces`)
for other types of manifolds
+ - ``structure`` -- manifold structure
+ - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
+ denote the manifold; if none is provided, it is set to ``name``
+ - ``full_name`` -- (default: ``None``) string; short description of the
+ manifold; if none is provided, it is formed from the field, dimension
+ and structure
- ``start_index`` -- (default: 0) integer; lower value of the range of
indices used for "indexed objects" on the manifold, e.g., coordinates
in a chart
- ``category`` -- (default: ``None``) to specify the category; if ``None``,
``Manifolds(field)`` is assumed (see the category
:class:`~sage.categories.manifolds.Manifolds`)
- - ``ambient_manifold`` -- (default: ``None``) if not ``None``, the created
- object is considered as an open subset of the topological manifold
- ``ambient_manifold``
- ``unique_tag`` -- (default: ``None``) tag used to force the construction
of a new object when all the other arguments have been used previously
(without ``unique_tag``, the
@@ -449,8 +451,9 @@ class TopologicalManifold(AbstractSet):
sage: TestSuite(M).run()
"""
- def __init__(self, n, name, latex_name, field, structure,
- start_index, category=None, unique_tag=None):
+ def __init__(self, n, name, field, structure, latex_name=None,
+ full_name=None, start_index=0, category=None,
+ unique_tag=None):
r"""
Construct a topological manifold.
@@ -468,7 +471,7 @@ class TopologicalManifold(AbstractSet):
sage: TestSuite(M).run()
"""
- # Initialization of the attributes _dim, _field and _start_index:
+ # Initialization of the attributes _dim, _field, _field_type:
self._dim = n
if field == 'real':
self._field = RR
@@ -486,12 +489,28 @@ class TopologicalManifold(AbstractSet):
self._field_type = 'complex'
else:
self._field_type = 'neither_real_nor_complex'
-
+ # Structure and category:
self._structure = structure
category = Manifolds(self._field).or_subcategory(category)
category = self._structure.subcategory(category)
-
- AbstractSet.__init__(self, name, latex_name, self._field, category)
+ # Full name:
+ if full_name is None:
+ if self._field_type == 'real':
+ full_name = "{}-dimensional {} manifold {}".format(n,
+ self._structure.name,
+ name)
+ elif self._field_type == 'complex':
+ full_name = "Complex {}-dimensional {} manifold {}".format(n,
+ self._structure.name,
+ name)
+ else:
+ full_name = "{}-dimensional {} manifold {} over the {}".format(n,
+ self._structure.name,
+ name, self._field)
+ # Initialization as a manifold set:
+ AbstractSet.__init__(self, name, latex_name=latex_name,
+ full_name=full_name, base=self._field,
+ category=category)
if not isinstance(start_index, (int, Integer)):
raise TypeError("the starting index must be an integer")
@@ -509,48 +528,8 @@ class TopologicalManifold(AbstractSet):
# List of charts that individually cover self, i.e. whose
# domains are self (if non-empty, self is a coordinate domain):
self._covering_charts = []
-
self._open_covers.append([self]) # list of open covers of self
- def _repr_(self):
- r"""
- Return a string representation of the manifold.
-
- TESTS::
-
- sage: M = Manifold(3, 'M', structure='topological')
- sage: M._repr_()
- '3-dimensional topological manifold M'
- sage: repr(M) # indirect doctest
- '3-dimensional topological manifold M'
- sage: M # indirect doctest
- 3-dimensional topological manifold M
- sage: M = Manifold(3, 'M', structure='topological', field='complex')
- sage: M._repr_()
- 'Complex 3-dimensional topological manifold M'
- sage: M = Manifold(3, 'M', structure='topological', field=QQ)
- sage: M._repr_()
- '3-dimensional topological manifold M over the Rational Field'
-
- If the manifold is actually an open subset of a larger manifold, the
- string representation is different::
-
- sage: U = M.open_subset('U')
- sage: U._repr_()
- 'Open subset U of the 3-dimensional topological manifold M over the Rational Field'
-
- """
- if self._field_type == 'real':
- return "{}-dimensional {} manifold {}".format(self._dim,
- self._structure.name,
- self._name)
- elif self._field_type == 'complex':
- return "Complex {}-dimensional {} manifold {}".format(self._dim,
- self._structure.name,
- self._name)
- return "{}-dimensional {} manifold {} over the {}".format(self._dim,
- self._structure.name, self._name, self._field)
-
def _an_element_(self):
r"""
Construct some point on the manifold.
@@ -1558,7 +1537,7 @@ class TopologicalManifold(AbstractSet):
"""
return self
-#####################################################################
+##############################################################################
## Constructor function
def Manifold(dim, name, latex_name=None, field='real', structure='smooth',
@@ -1713,6 +1692,6 @@ def Manifold(dim, name, latex_name=None, field='real', structure='smooth',
else:
raise NotImplementedError("manifolds of type {} are not ".format(structure) +
"implemented")
-
- return TopologicalManifold(dim, name, latex_name, field, structure, start_index,
+ return TopologicalManifold(dim, name, field, structure,
+ latex_name=latex_name, start_index=start_index,
unique_tag=getrandbits(128)*time())
diff --git a/src/sage/manifolds/subset.py b/src/sage/manifolds/subset.py
index 6f6c297..a165425 100644
--- a/src/sage/manifolds/subset.py
+++ b/src/sage/manifolds/subset.py
@@ -95,7 +95,7 @@ class ManifoldSubset(AbstractSet):
- ``manifold`` -- topological manifold on which the subset is defined
- ``name`` -- string; name (symbol) given to the subset
- - ``latex_name`` -- (default: ``None``) string: LaTeX symbol to denote the
+ - ``latex_name`` -- (default: ``None``) string; LaTeX symbol to denote the
subset; if none is provided, it is set to ``name``
EXAMPLES:
@@ -163,33 +163,18 @@ class ManifoldSubset(AbstractSet):
coordinate definition of the subset.
"""
- category = Sets().Subobjects()
- AbstractSet.__init__(self, name=name, latex_name=latex_name,
- category=category)
- self._manifold = manifold
for dom in manifold._subsets:
if name == dom._name:
raise ValueError("the name '" + name +
"' is already used for another " +
"subset of the {}".format(manifold))
+ full_name = "Subset {} of the {}".format(name, manifold)
+ category = Sets().Subobjects()
+ AbstractSet.__init__(self, name=name, latex_name=latex_name,
+ full_name=full_name, category=category)
+ self._manifold = manifold
manifold._subsets.add(self)
- def _repr_(self):
- r"""
- String representation of the object.
-
- TESTS::
-
- sage: M = Manifold(2, 'M', structure='topological')
- sage: A = M.subset('A')
- sage: A._repr_()
- 'Subset A of the 2-dimensional topological manifold M'
- sage: repr(A) # indirect doctest
- 'Subset A of the 2-dimensional topological manifold M'
-
- """
- return "Subset {} of the {}".format(self._name, self._manifold)
-
def manifold(self):
r"""
Return the manifold of which the current object is a subset.
@@ -583,7 +568,7 @@ class OpenTopologicalSubmanifold(ManifoldSubset, TopologicalManifold):
if not isinstance(ambient, TopologicalManifold):
raise TypeError("the argument 'ambient' must be " +
"a topological manifold")
-
+ full_name = "Open subset {} of the {}".format(name, ambient)
# This is copied from ManifoldSubset to avoid twice
# initializing AbstractSet
self._manifold = ambient
@@ -595,24 +580,13 @@ class OpenTopologicalSubmanifold(ManifoldSubset, TopologicalManifold):
ambient._subsets.add(self)
category = ambient.category().Subobjects()
- TopologicalManifold.__init__(self, ambient.dim(), name, latex_name,
- ambient._field, ambient._structure,
- ambient._sindex, category)
-
- def _repr_(self):
- """
- Return a string representation of ``self``.
-
- TEST::
-
- sage: M = Manifold(3, 'M', structure='topological')
- sage: A = M.open_subset('A')
- sage: A._repr_()
- 'Open subset A of the 3-dimensional topological manifold M'
-
- """
- return "Open subset {} of the {}".format(self._name, self._manifold)
+ TopologicalManifold.__init__(self, ambient.dim(), name, ambient._field,
+ ambient._structure, latex_name=latex_name,
+ full_name=full_name,
+ start_index=ambient._sindex,
+ category=category,
+ unique_tag=ambient)
def superset(self, name, latex_name=None, is_open=False):
r"""