summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTravis Scrimshaw <tscrimsh at umn.edu>2015-10-17 09:52:52 -0500
committerTravis Scrimshaw <tscrimsh at umn.edu>2015-10-17 09:52:52 -0500
commit041a5d10259ca0ec083a313bd4ad1fe6cfb8d9c0 (patch)
treebbb1f602764fe9b9532da3359c164cfa14ec62c8
parentFixing last remaining doctests. (diff)
Adding p-adics to metric spaces and some cleanup.
-rw-r--r--src/doc/en/reference/categories/index.rst10
-rw-r--r--src/sage/categories/metric_spaces.py53
-rw-r--r--src/sage/rings/complex_double.pyx13
-rw-r--r--src/sage/rings/complex_field.py13
-rw-r--r--src/sage/rings/integer_ring.pyx13
-rw-r--r--src/sage/rings/padics/local_generic.py1
-rw-r--r--src/sage/rings/padics/padic_base_leaves.py12
-rw-r--r--src/sage/rings/padics/padic_generic.py1
-rw-r--r--src/sage/rings/rational_field.py13
-rw-r--r--src/sage/rings/real_double.pyx13
-rw-r--r--src/sage/rings/real_mpfr.pyx13
11 files changed, 69 insertions, 86 deletions
diff --git a/src/doc/en/reference/categories/index.rst b/src/doc/en/reference/categories/index.rst
index 518d9e6..34cf416 100644
--- a/src/doc/en/reference/categories/index.rst
+++ b/src/doc/en/reference/categories/index.rst
@@ -56,6 +56,7 @@ Individual Categories
sage/categories/coxeter_group_algebras
sage/categories/coxeter_groups
sage/categories/crystals
+ sage/categories/cw_complexes
sage/categories/discrete_valuation
sage/categories/distributive_magmas_and_additive_magmas
sage/categories/division_rings
@@ -98,6 +99,7 @@ Individual Categories
sage/categories/graded_hopf_algebras_with_basis
sage/categories/graded_modules
sage/categories/graded_modules_with_basis
+ sage/categories/graphs
sage/categories/group_algebras
sage/categories/groupoid
sage/categories/groups
@@ -109,10 +111,13 @@ Individual Categories
sage/categories/integral_domains
sage/categories/lattice_posets
sage/categories/left_modules
+ sage/categories/lie_groups
sage/categories/magmas
sage/categories/magmas_and_additive_magmas
sage/categories/magmatic_algebras
+ sage/categories/manifolds
sage/categories/matrix_algebras
+ sage/categories/metric_spaces
sage/categories/modular_abelian_varieties
sage/categories/modules
sage/categories/modules_with_basis
@@ -139,6 +144,8 @@ Individual Categories
sage/categories/sets_cat
sage/categories/sets_with_grading
sage/categories/sets_with_partial_maps
+ sage/categories/simplicial_complexes
+ sage/categories/topological_spaces
sage/categories/unique_factorization_domains
sage/categories/unital_algebras
sage/categories/vector_spaces
@@ -187,6 +194,7 @@ Examples of parents using categories
sage/categories/examples/commutative_additive_semigroups
sage/categories/examples/coxeter_groups
sage/categories/examples/crystals
+ sage/categories/examples/cw_complexes
sage/categories/examples/facade_sets
sage/categories/examples/finite_coxeter_groups
sage/categories/examples/finite_dimensional_algebras_with_basis
@@ -196,8 +204,10 @@ Examples of parents using categories
sage/categories/examples/finite_weyl_groups
sage/categories/examples/graded_connected_hopf_algebras_with_basis
sage/categories/examples/graded_modules_with_basis
+ sage/categories/examples/graphs
sage/categories/examples/hopf_algebras_with_basis
sage/categories/examples/infinite_enumerated_sets
+ sage/categories/examples/manifolds
sage/categories/examples/monoids
sage/categories/examples/posets
sage/categories/examples/semigroups_cython
diff --git a/src/sage/categories/metric_spaces.py b/src/sage/categories/metric_spaces.py
index ef2460b..d7147ed 100644
--- a/src/sage/categories/metric_spaces.py
+++ b/src/sage/categories/metric_spaces.py
@@ -81,6 +81,28 @@ class MetricSpaces(MetricSpacesCategory):
- `d(a, b) = 0` if and only if `a = b`.
A metric space is a set `S` with a distinguished metric.
+
+ .. RUBRIC:: Implementation
+
+ Objects in this category must implement either a ``dist`` on the parent
+ or the elements or ``metric`` on the parent; otherwise this will cause
+ an infinite recursion.
+
+ .. TODO::
+
+ - Implement a general geodesics class.
+ - Implement a category for metric unital additive magmas and
+ move the generic distance `d(a, b) = |a - b|` there.
+ - Incorperate the length of a geodesic as part of the default
+ distance cycle.
+
+ EXAMPLES::
+
+ sage: from sage.categories.metric_spaces import MetricSpaces
+ sage: C = MetricSpaces()
+ sage: C
+ Category of metric spaces
+ sage: TestSuite(C).run()
"""
def _repr_object_names(self):
"""
@@ -114,7 +136,7 @@ class MetricSpaces(MetricSpacesCategory):
for a in S:
for b in S:
d = dist(a, b)
- if a is not b:
+ if a != b:
tester.assertGreater(d, 0)
else:
tester.assertEqual(d, 0)
@@ -132,9 +154,8 @@ class MetricSpaces(MetricSpacesCategory):
sage: m(p1, p2)
2.23230104635820
"""
- return lambda a,b: self.dist(a, b)
+ return lambda a,b: a.dist(b)
- @abstract_method
def dist(self, a, b):
"""
Return the distance between ``a`` and ``b`` in ``self``.
@@ -150,9 +171,35 @@ class MetricSpaces(MetricSpacesCategory):
sage: PD = HyperbolicPlane().PD()
sage: PD.dist(PD.get_point(0), PD.get_point(I/2))
arccosh(5/3)
+
+ TESTS::
+
+ sage: RR.dist(-1, pi)
+ 4.14159265358979
+ sage: RDF.dist(1, -1/2)
+ 1.5
+ sage: CC.dist(3, 2)
+ 1.00000000000000
+ sage: CC.dist(-1, I)
+ 1.41421356237310
+ sage: CDF.dist(-1, I)
+ 1.4142135623730951
"""
+ return (self(a) - self(b)).abs()
class ElementMethods:
+ def abs(self):
+ """
+ Return the absolute value of ``self``.
+
+ EXAMPLES::
+
+ sage: CC(I).abs()
+ 1.00000000000000
+ """
+ P = self.parent()
+ return P.metric()(self, P.zero())
+
def dist(self, b):
"""
Return the distance between ``self`` and ``other``.
diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx
index 7101ee8..31c12bd 100644
--- a/src/sage/rings/complex_double.pyx
+++ b/src/sage/rings/complex_double.pyx
@@ -199,19 +199,6 @@ cdef class ComplexDoubleField_class(sage.rings.ring.Field):
return 561162115
#return hash(self.str())
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b``.
-
- EXAMPLES::
-
- sage: CDF.dist(3, 2)
- 1.0
- sage: CDF.dist(-1, I)
- 1.4142135623730951
- """
- return (self(a) - self(b)).abs()
-
def characteristic(self):
"""
Return the characteristic of the complex double field, which is 0.
diff --git a/src/sage/rings/complex_field.py b/src/sage/rings/complex_field.py
index 9f5765a..991635b 100644
--- a/src/sage/rings/complex_field.py
+++ b/src/sage/rings/complex_field.py
@@ -745,16 +745,3 @@ class ComplexField_class(ring.Field):
from sage.structure.factorization import Factorization
return Factorization([(R(g).monic(),e) for g,e in zip(*F)], f.leading_coefficient())
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b``.
-
- EXAMPLES::
-
- sage: CC.dist(3, 2)
- 1.00000000000000
- sage: CC.dist(-1, I)
- 1.41421356237310
- """
- return self(a - b).abs()
-
diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx
index 6fed18f..76adb61 100644
--- a/src/sage/rings/integer_ring.pyx
+++ b/src/sage/rings/integer_ring.pyx
@@ -1250,19 +1250,6 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
else:
raise ValueError("no nth root of unity in integer ring")
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b``.
-
- EXAMPLES::
-
- sage: ZZ.dist(3, 2)
- 1
- sage: ZZ.dist(-1, 1)
- 2
- """
- return self(a - b).abs()
-
def parameter(self):
r"""
Return an integer of degree 1 for the Euclidean property of `\ZZ`,
diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py
index 48bdfb4..8ee98a1 100644
--- a/src/sage/rings/padics/local_generic.py
+++ b/src/sage/rings/padics/local_generic.py
@@ -55,6 +55,7 @@ class LocalGeneric(CommutativeRing):
category = CompleteDiscreteValuationFields()
else:
category = CompleteDiscreteValuationRings()
+ category = category.Metric().Complete()
if default_category is not None:
category = check_default_category(default_category, category)
Parent.__init__(self, base, names=(names,), normalize=False, category=category, element_constructor=element_class)
diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py
index a43eb7ef..55de7f5 100644
--- a/src/sage/rings/padics/padic_base_leaves.py
+++ b/src/sage/rings/padics/padic_base_leaves.py
@@ -231,7 +231,7 @@ class pAdicRingCappedRelative(pAdicRingBaseGeneric, pAdicCappedRelativeRingGener
sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)])
sage: R = ZpCR(3, 2)
- sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)])
+ sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)]) # long time
sage: R = ZpCR(next_prime(10^60))
sage: TestSuite(R).run()
@@ -320,7 +320,7 @@ class pAdicRingCappedAbsolute(pAdicRingBaseGeneric, pAdicCappedAbsoluteRingGener
sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)])
sage: R = ZpCA(3, 2)
- sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)])
+ sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)]) # long time
sage: R = ZpCA(next_prime(10^60))
sage: TestSuite(R).run()
@@ -411,7 +411,7 @@ class pAdicRingFixedMod(pAdicRingBaseGeneric, pAdicFixedModRingGeneric):
sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)])
sage: R = ZpFM(3, 2)
- sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)])
+ sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)]) # long time
sage: R = ZpFM(next_prime(10^60))
sage: TestSuite(R).run()
@@ -525,10 +525,12 @@ class pAdicFieldCappedRelative(pAdicFieldBaseGeneric, pAdicCappedRelativeFieldGe
sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12) # long time
sage: R = Qp(3, 1)
- sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)])
+ sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)]) # long time
sage: R = Qp(3, 2)
- sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^9)])
+ sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^9)],
+ ....: skip="_test_metric") # Skip because too long
+ sage: R._test_metric(elements=[R.random_element() for i in range(3^3)])
sage: R = Qp(next_prime(10^60))
sage: TestSuite(R).run()
diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py
index 1fba883..eed574f 100644
--- a/src/sage/rings/padics/padic_generic.py
+++ b/src/sage/rings/padics/padic_generic.py
@@ -56,6 +56,7 @@ class pAdicGeneric(PrincipalIdealDomain, LocalGeneric):
category = Fields()
else:
category = PrincipalIdealDomains()
+ category = category.Metric().Complete()
LocalGeneric.__init__(self, base, prec, names, element_class, category)
self._printer = pAdicPrinter(self, print_mode)
diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py
index aefba90..4a041a8 100644
--- a/src/sage/rings/rational_field.py
+++ b/src/sage/rings/rational_field.py
@@ -934,19 +934,6 @@ class RationalField(Singleton, number_field_base.NumberField):
from sage.rings.all import QQbar
return QQbar
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b``.
-
- EXAMPLES::
-
- sage: QQ.dist(3, 2)
- 1
- sage: QQ.dist(-1, 1/2)
- 3/2
- """
- return self(a - b).abs()
-
def order(self):
r"""
Return the order of `\QQ` which is `\infty`.
diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx
index 8211108..a0a22c4 100644
--- a/src/sage/rings/real_double.pyx
+++ b/src/sage/rings/real_double.pyx
@@ -236,19 +236,6 @@ cdef class RealDoubleField_class(Field):
return 0
return cmp(type(self), type(x))
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b`` in ``self``.
-
- EXAMPLES::
-
- sage: RDF.dist(5, 1/2)
- 4.5
- sage: RDF.dist(-1, 1/2)
- 1.5
- """
- return (self(a) - self(b)).abs()
-
def construction(self):
r"""
Returns the functorial construction of ``self``, namely, completion of
diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx
index 415e9be..3950c1b 100644
--- a/src/sage/rings/real_mpfr.pyx
+++ b/src/sage/rings/real_mpfr.pyx
@@ -801,19 +801,6 @@ cdef class RealField_class(sage.rings.ring.Field):
"""
return self.complex_field()
- def dist(self, a, b):
- """
- Return the distance between ``a`` and ``b``.
-
- EXAMPLES::
-
- sage: RR.dist(3, 2)
- 1.00000000000000
- sage: RR.dist(-1, pi)
- 4.14159265358979
- """
- return self(a - b).abs()
-
def ngens(self):
"""
Return the number of generators.