Skip to content

Commit

Permalink
Trac #30830: Subintervals of OpenInterval and UniqueRepresentation
Browse files Browse the repository at this point in the history
At the moment, we have the following behavior:
{{{
sage: I = OpenInterval(0,2)
sage: J = OpenInterval(0,1, ambient_interval=I, coordinate='t')
sage: I.open_interval(0,1)
Traceback (most recent call last)
...
ValueError: the name '(0, 1)' is already used for another subset of the
Real interval (0, 2)
}}}

Even though the use of `OpenInterval(0,1, ambient_interval=I)` is not
intended, this is still a blind spot.

The reason for this behavior comes from the `UniqueRepresentation` and
how the subintervals are constructed.

I propose a fix using `__classcall_private__`.

URL: https://trac.sagemath.org/30830
Reported by: gh-mjungmath
Ticket author(s): Michael Jung
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Nov 22, 2020
2 parents 1101a45 + 200942c commit bb31b65
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/sage/manifolds/differentiable/examples/real_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,34 @@ class OpenInterval(DifferentiableManifold):
t: (1/2, 1)
"""
@staticmethod
def __classcall_private__(cls, lower, upper, ambient_interval=None,
name=None, latex_name=None, coordinate=None,
names=None, start_index=0):
r"""
Determine the correct interval to return based upon the input.
TESTS:
Check whether :trac:`30830` is fixed::
sage: I = OpenInterval(0,2)
sage: J = OpenInterval(0,1, ambient_interval=I, coordinate='t')
sage: I.open_interval(0,1)
Real interval (0, 1)
"""
if ambient_interval:
# cope the UniqueRepresentation framework for subintervals and
# reset irrelevant information only:
coordinate = None
names = None
start_index = 0
return super(cls, OpenInterval).__classcall__(cls, lower, upper,
ambient_interval=ambient_interval, name=name,
latex_name=latex_name, coordinate=coordinate,
names=names, start_index=start_index)

def __init__(self, lower, upper, ambient_interval=None,
name=None, latex_name=None,
coordinate=None, names=None, start_index=0):
Expand Down Expand Up @@ -830,6 +858,27 @@ class RealLine(OpenInterval):
[Real interval (0, 1), Real number line R]
"""
@staticmethod
def __classcall__(cls, name='R', latex_name=r'\Bold{R}', coordinate=None,
names=None, start_index=0):
r"""
Determine the correct interval to return based upon the input.
TESTS::
sage: R = RealLine(); R
Real number line R
sage: R1 = RealLine('R'); R1
Real number line R
sage: R is R1
True
"""
return super(cls, RealLine).__classcall__(cls, name=name,
latex_name=latex_name,
coordinate=coordinate,
names=names, start_index=start_index)

def __init__(self, name='R', latex_name=r'\Bold{R}', coordinate=None,
names=None, start_index=0):
r"""
Expand Down

0 comments on commit bb31b65

Please sign in to comment.