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

Commit

Permalink
Merge #31877
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jun 11, 2021
2 parents f535127 + 46eed0e commit 32cdd5c
Showing 1 changed file with 83 additions and 2 deletions.
85 changes: 83 additions & 2 deletions src/sage/sets/real_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RealSet.
from sage.structure.richcmp import richcmp, richcmp_method
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.categories.sets_cat import Sets
from sage.categories.topological_spaces import TopologicalSpaces
from sage.rings.all import ZZ
from sage.rings.real_lazy import LazyFieldElement, RLF
from sage.rings.infinity import infinity, minus_infinity
Expand Down Expand Up @@ -909,8 +909,37 @@ def __init__(self, *intervals):
(0, 1) + (3, 4)
sage: RealSet(i, [3,4]) # list of two numbers = closed set
(0, 1) + [3, 4]
Real sets belong to a subcategory of topological spaces::
sage: RealSet().category()
Join of Category of finite sets and Category of subobjects of sets and Category of connected topological spaces
sage: RealSet.point(1).category()
Join of Category of finite sets and Category of subobjects of sets and Category of connected topological spaces
sage: RealSet([1, 2]).category()
Join of Category of infinite sets and Category of compact topological spaces and Category of subobjects of sets and Category of connected topological spaces
sage: RealSet((1, 2), (3, 4)).category()
Join of Category of infinite sets and Category of subobjects of sets and Category of topological spaces
"""
Parent.__init__(self, category = Sets())
category = TopologicalSpaces()
if len(intervals) <= 1:
category = category.Connected()
if all(i.is_point() for i in intervals):
category = category.Subobjects().Finite()
else:
# Have at least one non-degenerate interval
category = category.Infinite()
inf = intervals[0].lower()
sup = intervals[-1].upper()
if not (len(intervals) == 1 and inf is minus_infinity and sup is infinity):
category = category.Subobjects() # subobject of real line
if inf is not minus_infinity and sup is not infinity:
# Bounded
if all(i.lower_closed() and i.upper_closed()
for i in intervals):
category = category.Compact()
Parent.__init__(self, category=category)
self._intervals = intervals

def __richcmp__(self, other, op):
Expand Down Expand Up @@ -1052,6 +1081,58 @@ def get_interval(self, i):

__getitem__ = get_interval

# ParentMethods of Subobjects

def ambient(self):
"""
Return the ambient space (the real line).
EXAMPLES::
sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
sage: s.ambient()
(-oo, +oo)
"""
return RealSet(minus_infinity, infinity)

def lift(self, x):
"""
Lift ``x`` to the ambient space for ``self``.
This version of the method just returns ``x``.
EXAMPLES::
sage: s = RealSet(0, 2); s
(0, 2)
sage: s.lift(1)
1
"""
return x

def retract(self, x):
"""
Retract ``x`` to ``self``.
It raises an error if ``x`` does not lie in the set ``self``.
EXAMPLES::
sage: s = RealSet(0, 2); s
(0, 2)
sage: s.retract(1)
1
sage: s.retract(2)
Traceback (most recent call last):
...
ValueError: 2 is not an element of (0, 2)
"""
if x not in self:
raise ValueError(f'{x} is not an element of {self}')
return x

#

@staticmethod
def normalize(intervals):
"""
Expand Down

0 comments on commit 32cdd5c

Please sign in to comment.