Metric Spaces#

class sage.categories.metric_spaces.MetricSpaces(category, *args)[source]#

Bases: MetricSpacesCategory

The category of metric spaces.

A metric on a set \(S\) is a function \(d : S \times S \to \RR\) such that:

  • \(d(a, b) \geq 0\),

  • \(d(a, b) = 0\) if and only if \(a = b\).

A metric space is a set \(S\) with a distinguished metric.

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 additive groups and move the generic distance \(d(a, b) = |a - b|\) there.

  • Incorporate 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()
>>> from sage.all import *
>>> from sage.categories.metric_spaces import MetricSpaces
>>> C = MetricSpaces()
>>> C
Category of metric spaces
>>> TestSuite(C).run()
class CartesianProducts(category, *args)[source]#

Bases: CartesianProductsCategory

class ParentMethods[source]#

Bases: object

dist(a, b)[source]#

Return the distance between a and b in self.

It is defined as the maximum of the distances within the Cartesian factors.

EXAMPLES:

sage: from sage.categories.metric_spaces import MetricSpaces
sage: Q2 = QQ.cartesian_product(QQ)
sage: Q2.category()
Join of
Category of Cartesian products of commutative rings and
Category of Cartesian products of metric spaces
sage: Q2 in MetricSpaces()
True
sage: Q2.dist((0, 0), (2, 3))
3
>>> from sage.all import *
>>> from sage.categories.metric_spaces import MetricSpaces
>>> Q2 = QQ.cartesian_product(QQ)
>>> Q2.category()
Join of
Category of Cartesian products of commutative rings and
Category of Cartesian products of metric spaces
>>> Q2 in MetricSpaces()
True
>>> Q2.dist((Integer(0), Integer(0)), (Integer(2), Integer(3)))
3
extra_super_categories()[source]#

Implement the fact that a (finite) Cartesian product of metric spaces is a metric space.

EXAMPLES:

sage: from sage.categories.metric_spaces import MetricSpaces
sage: C = MetricSpaces().CartesianProducts()
sage: C.extra_super_categories()
[Category of metric spaces]
sage: C.super_categories()
[Category of Cartesian products of topological spaces,
 Category of metric spaces]
sage: C.axioms()
frozenset()
>>> from sage.all import *
>>> from sage.categories.metric_spaces import MetricSpaces
>>> C = MetricSpaces().CartesianProducts()
>>> C.extra_super_categories()
[Category of metric spaces]
>>> C.super_categories()
[Category of Cartesian products of topological spaces,
 Category of metric spaces]
>>> C.axioms()
frozenset()
class Complete(base_category)[source]#

Bases: CategoryWithAxiom

The category of complete metric spaces.

class CartesianProducts(category, *args)[source]#

Bases: CartesianProductsCategory

extra_super_categories()[source]#

Implement the fact that a (finite) Cartesian product of complete metric spaces is a complete metric space.

EXAMPLES:

sage: from sage.categories.metric_spaces import MetricSpaces
sage: C = MetricSpaces().Complete().CartesianProducts()
sage: C.extra_super_categories()
[Category of complete metric spaces]
sage: C.super_categories()
[Category of Cartesian products of metric spaces,
 Category of complete metric spaces]
sage: C.axioms()
frozenset({'Complete'})

sage: R2 = RR.cartesian_product(RR)
sage: R2 in MetricSpaces()
True
sage: R2 in MetricSpaces().Complete()
True

sage: QR = QQ.cartesian_product(RR)
sage: QR in MetricSpaces()
True
sage: QR in MetricSpaces().Complete()
False
>>> from sage.all import *
>>> from sage.categories.metric_spaces import MetricSpaces
>>> C = MetricSpaces().Complete().CartesianProducts()
>>> C.extra_super_categories()
[Category of complete metric spaces]
>>> C.super_categories()
[Category of Cartesian products of metric spaces,
 Category of complete metric spaces]
>>> C.axioms()
frozenset({'Complete'})

>>> R2 = RR.cartesian_product(RR)
>>> R2 in MetricSpaces()
True
>>> R2 in MetricSpaces().Complete()
True

>>> QR = QQ.cartesian_product(RR)
>>> QR in MetricSpaces()
True
>>> QR in MetricSpaces().Complete()
False
class ElementMethods[source]#

Bases: object

abs()[source]#

Return the absolute value of self.

EXAMPLES:

sage: CC(I).abs()                                                       # needs sage.rings.real_mpfr sage.symbolic
1.00000000000000
>>> from sage.all import *
>>> CC(I).abs()                                                       # needs sage.rings.real_mpfr sage.symbolic
1.00000000000000
dist(b)[source]#

Return the distance between self and other.

EXAMPLES:

sage: # needs sage.symbolic
sage: UHP = HyperbolicPlane().UHP()
sage: p1 = UHP.get_point(5 + 7*I)
sage: p2 = UHP.get_point(1 + I)
sage: p1.dist(p2)
arccosh(33/7)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> UHP = HyperbolicPlane().UHP()
>>> p1 = UHP.get_point(Integer(5) + Integer(7)*I)
>>> p2 = UHP.get_point(Integer(1) + I)
>>> p1.dist(p2)
arccosh(33/7)
class Homsets(category, *args)[source]#

Bases: HomsetsCategory

The category of homsets of metric spaces

It consists of the metric maps, that is, the Lipschitz functions with Lipschitz constant 1.

class ElementMethods[source]#

Bases: object

class ParentMethods[source]#

Bases: object

dist(a, b)[source]#

Return the distance between a and b in self.

EXAMPLES:

sage: # needs sage.symbolic
sage: UHP = HyperbolicPlane().UHP()
sage: p1 = UHP.get_point(5 + 7*I)
sage: p2 = UHP.get_point(1.0 + I)
sage: UHP.dist(p1, p2)
2.23230104635820

sage: PD = HyperbolicPlane().PD()                                       # needs sage.symbolic
sage: PD.dist(PD.get_point(0), PD.get_point(I/2))                       # needs sage.symbolic
arccosh(5/3)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> UHP = HyperbolicPlane().UHP()
>>> p1 = UHP.get_point(Integer(5) + Integer(7)*I)
>>> p2 = UHP.get_point(RealNumber('1.0') + I)
>>> UHP.dist(p1, p2)
2.23230104635820

>>> PD = HyperbolicPlane().PD()                                       # needs sage.symbolic
>>> PD.dist(PD.get_point(Integer(0)), PD.get_point(I/Integer(2)))                       # needs sage.symbolic
arccosh(5/3)
metric(*args, **kwds)[source]#

Deprecated: Use metric_function() instead. See Issue #30062 for details.

metric_function()[source]#

Return the metric function of self.

EXAMPLES:

sage: # needs sage.symbolic
sage: UHP = HyperbolicPlane().UHP()
sage: m = UHP.metric_function()
sage: p1 = UHP.get_point(5 + 7*I)
sage: p2 = UHP.get_point(1.0 + I)
sage: m(p1, p2)
2.23230104635820
>>> from sage.all import *
>>> # needs sage.symbolic
>>> UHP = HyperbolicPlane().UHP()
>>> m = UHP.metric_function()
>>> p1 = UHP.get_point(Integer(5) + Integer(7)*I)
>>> p2 = UHP.get_point(RealNumber('1.0') + I)
>>> m(p1, p2)
2.23230104635820
class SubcategoryMethods[source]#

Bases: object

Complete()[source]#

Return the full subcategory of the complete objects of self.

EXAMPLES:

sage: Sets().Metric().Complete()
Category of complete metric spaces
>>> from sage.all import *
>>> Sets().Metric().Complete()
Category of complete metric spaces
class WithRealizations(category, *args)[source]#

Bases: WithRealizationsCategory

class ParentMethods[source]#

Bases: object

dist(a, b)[source]#

Return the distance between a and b by converting them to a realization of self and doing the computation.

EXAMPLES:

sage: # needs sage.symbolic
sage: H = HyperbolicPlane()
sage: PD = H.PD()
sage: p1 = PD.get_point(0)
sage: p2 = PD.get_point(I/2)
sage: H.dist(p1, p2)
arccosh(5/3)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> H = HyperbolicPlane()
>>> PD = H.PD()
>>> p1 = PD.get_point(Integer(0))
>>> p2 = PD.get_point(I/Integer(2))
>>> H.dist(p1, p2)
arccosh(5/3)
class sage.categories.metric_spaces.MetricSpacesCategory(category, *args)[source]#

Bases: RegressiveCovariantConstructionCategory

classmethod default_super_categories(category)[source]#

Return the default super categories of category.Metric().

Mathematical meaning: if \(A\) is a metric space in the category \(C\), then \(A\) is also a topological space.

INPUT:

  • cls – the class MetricSpaces

  • category – a category \(Cat\)

OUTPUT:

A (join) category

In practice, this returns category.Metric(), joined together with the result of the method RegressiveCovariantConstructionCategory.default_super_categories() (that is the join of category and cat.Metric() for each cat in the super categories of category).

EXAMPLES:

Consider category=Groups(). Then, a group \(G\) with a metric is simultaneously a topological group by itself, and a metric space:

sage: Groups().Metric().super_categories()
[Category of topological groups, Category of metric spaces]
>>> from sage.all import *
>>> Groups().Metric().super_categories()
[Category of topological groups, Category of metric spaces]

This resulted from the following call:

sage: sage.categories.metric_spaces.MetricSpacesCategory.default_super_categories(Groups())
Join of Category of topological groups and Category of metric spaces
>>> from sage.all import *
>>> sage.categories.metric_spaces.MetricSpacesCategory.default_super_categories(Groups())
Join of Category of topological groups and Category of metric spaces