Subsets of the Real Line

This module contains subsets of the real line that can be constructed as the union of a finite set of open and closed intervals.

EXAMPLES:

sage: RealSet(0,1)
(0, 1)
sage: RealSet((0,1), [2,3])
(0, 1) ∪ [2, 3]
sage: RealSet((1,3), (0,2))
(0, 3)
sage: RealSet(-oo, oo)
(-oo, +oo)
>>> from sage.all import *
>>> RealSet(Integer(0),Integer(1))
(0, 1)
>>> RealSet((Integer(0),Integer(1)), [Integer(2),Integer(3)])
(0, 1) ∪ [2, 3]
>>> RealSet((Integer(1),Integer(3)), (Integer(0),Integer(2)))
(0, 3)
>>> RealSet(-oo, oo)
(-oo, +oo)
RealSet(0,1)
RealSet((0,1), [2,3])
RealSet((1,3), (0,2))
RealSet(-oo, oo)

Brackets must be balanced in Python, so the naive notation for half-open intervals does not work:

sage: RealSet([0,1))
Traceback (most recent call last):
...
SyntaxError: ...
>>> from sage.all import *
>>> RealSet([Integer(0),Integer(1)))
Traceback (most recent call last):
...
SyntaxError: ...
RealSet([0,1))

Instead, you can use the following construction functions:

sage: RealSet.open_closed(0,1)
(0, 1]
sage: RealSet.closed_open(0,1)
[0, 1)
sage: RealSet.point(1/2)
{1/2}
sage: RealSet.unbounded_below_open(0)
(-oo, 0)
sage: RealSet.unbounded_below_closed(0)
(-oo, 0]
sage: RealSet.unbounded_above_open(1)
(1, +oo)
sage: RealSet.unbounded_above_closed(1)
[1, +oo)
>>> from sage.all import *
>>> RealSet.open_closed(Integer(0),Integer(1))
(0, 1]
>>> RealSet.closed_open(Integer(0),Integer(1))
[0, 1)
>>> RealSet.point(Integer(1)/Integer(2))
{1/2}
>>> RealSet.unbounded_below_open(Integer(0))
(-oo, 0)
>>> RealSet.unbounded_below_closed(Integer(0))
(-oo, 0]
>>> RealSet.unbounded_above_open(Integer(1))
(1, +oo)
>>> RealSet.unbounded_above_closed(Integer(1))
[1, +oo)
RealSet.open_closed(0,1)
RealSet.closed_open(0,1)
RealSet.point(1/2)
RealSet.unbounded_below_open(0)
RealSet.unbounded_below_closed(0)
RealSet.unbounded_above_open(1)
RealSet.unbounded_above_closed(1)

The lower and upper endpoints will be sorted if necessary:

sage: RealSet.interval(1, 0, lower_closed=True, upper_closed=False)
[0, 1)
>>> from sage.all import *
>>> RealSet.interval(Integer(1), Integer(0), lower_closed=True, upper_closed=False)
[0, 1)
RealSet.interval(1, 0, lower_closed=True, upper_closed=False)

Relations containing symbols and numeric values or constants:

sage: # needs sage.symbolic
sage: RealSet(x != 0)
(-oo, 0) ∪ (0, +oo)
sage: RealSet(x == pi)
{pi}
sage: RealSet(x < 1/2)
(-oo, 1/2)
sage: RealSet(1/2 < x)
(1/2, +oo)
sage: RealSet(1.5 <= x)
[1.50000000000000, +oo)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> RealSet(x != Integer(0))
(-oo, 0) ∪ (0, +oo)
>>> RealSet(x == pi)
{pi}
>>> RealSet(x < Integer(1)/Integer(2))
(-oo, 1/2)
>>> RealSet(Integer(1)/Integer(2) < x)
(1/2, +oo)
>>> RealSet(RealNumber('1.5') <= x)
[1.50000000000000, +oo)
# needs sage.symbolic
RealSet(x != 0)
RealSet(x == pi)
RealSet(x < 1/2)
RealSet(1/2 < x)
RealSet(1.5 <= x)

Note that multiple arguments are combined as union:

sage: RealSet(x >= 0, x < 1)                                                        # needs sage.symbolic
(-oo, +oo)
sage: RealSet(x >= 0, x > 1)                                                        # needs sage.symbolic
[0, +oo)
sage: RealSet(x >= 0, x > -1)                                                       # needs sage.symbolic
(-1, +oo)
>>> from sage.all import *
>>> RealSet(x >= Integer(0), x < Integer(1))                                                        # needs sage.symbolic
(-oo, +oo)
>>> RealSet(x >= Integer(0), x > Integer(1))                                                        # needs sage.symbolic
[0, +oo)
>>> RealSet(x >= Integer(0), x > -Integer(1))                                                       # needs sage.symbolic
(-1, +oo)
RealSet(x >= 0, x < 1)                                                        # needs sage.symbolic
RealSet(x >= 0, x > 1)                                                        # needs sage.symbolic
RealSet(x >= 0, x > -1)                                                       # needs sage.symbolic

AUTHORS:

class sage.sets.real_set.InternalRealInterval(lower, lower_closed, upper, upper_closed, check=True)[source]

Bases: UniqueRepresentation, Parent

A real interval.

You are not supposed to create InternalRealInterval objects yourself. Always use RealSet instead.

INPUT:

  • lower – real or minus infinity; the lower bound of the interval

  • lower_closed – boolean; whether the interval is closed at the lower bound

  • upper – real or (plus) infinity; the upper bound of the interval

  • upper_closed – boolean; whether the interval is closed at the upper bound

  • check – boolean; whether to check the other arguments for validity

boundary_points()[source]

Generate the boundary points of self.

EXAMPLES:

sage: list(RealSet.open_closed(-oo, 1)[0].boundary_points())
[1]
sage: list(RealSet.open(1, 2)[0].boundary_points())
[1, 2]
>>> from sage.all import *
>>> list(RealSet.open_closed(-oo, Integer(1))[Integer(0)].boundary_points())
[1]
>>> list(RealSet.open(Integer(1), Integer(2))[Integer(0)].boundary_points())
[1, 2]
list(RealSet.open_closed(-oo, 1)[0].boundary_points())
list(RealSet.open(1, 2)[0].boundary_points())
closure()[source]

Return the closure.

OUTPUT: the closure as a new InternalRealInterval

EXAMPLES:

sage: RealSet.open(0,1)[0].closure()
[0, 1]
sage: RealSet.open(-oo,1)[0].closure()
(-oo, 1]
sage: RealSet.open(0, oo)[0].closure()
[0, +oo)
>>> from sage.all import *
>>> RealSet.open(Integer(0),Integer(1))[Integer(0)].closure()
[0, 1]
>>> RealSet.open(-oo,Integer(1))[Integer(0)].closure()
(-oo, 1]
>>> RealSet.open(Integer(0), oo)[Integer(0)].closure()
[0, +oo)
RealSet.open(0,1)[0].closure()
RealSet.open(-oo,1)[0].closure()
RealSet.open(0, oo)[0].closure()
contains(x)[source]

Return whether \(x\) is contained in the interval.

INPUT:

  • x – a real number

OUTPUT: boolean

EXAMPLES:

sage: i = RealSet.open_closed(0,2)[0]; i
(0, 2]
sage: i.contains(0)
False
sage: i.contains(1)
True
sage: i.contains(2)
True
>>> from sage.all import *
>>> i = RealSet.open_closed(Integer(0),Integer(2))[Integer(0)]; i
(0, 2]
>>> i.contains(Integer(0))
False
>>> i.contains(Integer(1))
True
>>> i.contains(Integer(2))
True
i = RealSet.open_closed(0,2)[0]; i
i.contains(0)
i.contains(1)
i.contains(2)
convex_hull(other)[source]

Return the convex hull of the two intervals.

OUTPUT: the convex hull as a new InternalRealInterval

EXAMPLES:

sage: I1 = RealSet.open(0, 1)[0];  I1
(0, 1)
sage: I2 = RealSet.closed(1, 2)[0];  I2
[1, 2]
sage: I1.convex_hull(I2)
(0, 2]
sage: I2.convex_hull(I1)
(0, 2]
sage: I1.convex_hull(I2.interior())
(0, 2)
sage: I1.closure().convex_hull(I2.interior())
[0, 2)
sage: I1.closure().convex_hull(I2)
[0, 2]
sage: I3 = RealSet.closed(1/2, 3/2)[0]; I3
[1/2, 3/2]
sage: I1.convex_hull(I3)
(0, 3/2]
>>> from sage.all import *
>>> I1 = RealSet.open(Integer(0), Integer(1))[Integer(0)];  I1
(0, 1)
>>> I2 = RealSet.closed(Integer(1), Integer(2))[Integer(0)];  I2
[1, 2]
>>> I1.convex_hull(I2)
(0, 2]
>>> I2.convex_hull(I1)
(0, 2]
>>> I1.convex_hull(I2.interior())
(0, 2)
>>> I1.closure().convex_hull(I2.interior())
[0, 2)
>>> I1.closure().convex_hull(I2)
[0, 2]
>>> I3 = RealSet.closed(Integer(1)/Integer(2), Integer(3)/Integer(2))[Integer(0)]; I3
[1/2, 3/2]
>>> I1.convex_hull(I3)
(0, 3/2]
I1 = RealSet.open(0, 1)[0];  I1
I2 = RealSet.closed(1, 2)[0];  I2
I1.convex_hull(I2)
I2.convex_hull(I1)
I1.convex_hull(I2.interior())
I1.closure().convex_hull(I2.interior())
I1.closure().convex_hull(I2)
I3 = RealSet.closed(1/2, 3/2)[0]; I3
I1.convex_hull(I3)
element_class[source]

alias of LazyFieldElement

interior()[source]

Return the interior.

OUTPUT: the interior as a new InternalRealInterval

EXAMPLES:

sage: RealSet.closed(0, 1)[0].interior()
(0, 1)
sage: RealSet.open_closed(-oo, 1)[0].interior()
(-oo, 1)
sage: RealSet.closed_open(0, oo)[0].interior()
(0, +oo)
>>> from sage.all import *
>>> RealSet.closed(Integer(0), Integer(1))[Integer(0)].interior()
(0, 1)
>>> RealSet.open_closed(-oo, Integer(1))[Integer(0)].interior()
(-oo, 1)
>>> RealSet.closed_open(Integer(0), oo)[Integer(0)].interior()
(0, +oo)
RealSet.closed(0, 1)[0].interior()
RealSet.open_closed(-oo, 1)[0].interior()
RealSet.closed_open(0, oo)[0].interior()
intersection(other)[source]

Return the intersection of the two intervals.

INPUT:

OUTPUT: the intersection as a new InternalRealInterval

EXAMPLES:

sage: I1 = RealSet.open(0, 2)[0];  I1
(0, 2)
sage: I2 = RealSet.closed(1, 3)[0];  I2
[1, 3]
sage: I1.intersection(I2)
[1, 2)
sage: I2.intersection(I1)
[1, 2)
sage: I1.closure().intersection(I2.interior())
(1, 2]
sage: I2.interior().intersection(I1.closure())
(1, 2]

sage: I3 = RealSet.closed(10, 11)[0];  I3
[10, 11]
sage: I1.intersection(I3)
(0, 0)
sage: I3.intersection(I1)
(0, 0)
>>> from sage.all import *
>>> I1 = RealSet.open(Integer(0), Integer(2))[Integer(0)];  I1
(0, 2)
>>> I2 = RealSet.closed(Integer(1), Integer(3))[Integer(0)];  I2
[1, 3]
>>> I1.intersection(I2)
[1, 2)
>>> I2.intersection(I1)
[1, 2)
>>> I1.closure().intersection(I2.interior())
(1, 2]
>>> I2.interior().intersection(I1.closure())
(1, 2]

>>> I3 = RealSet.closed(Integer(10), Integer(11))[Integer(0)];  I3
[10, 11]
>>> I1.intersection(I3)
(0, 0)
>>> I3.intersection(I1)
(0, 0)
I1 = RealSet.open(0, 2)[0];  I1
I2 = RealSet.closed(1, 3)[0];  I2
I1.intersection(I2)
I2.intersection(I1)
I1.closure().intersection(I2.interior())
I2.interior().intersection(I1.closure())
I3 = RealSet.closed(10, 11)[0];  I3
I1.intersection(I3)
I3.intersection(I1)
is_connected(other)[source]

Test whether two intervals are connected.

OUTPUT:

boolean; whether the set-theoretic union of the two intervals has a single connected component.

EXAMPLES:

sage: I1 = RealSet.open(0, 1)[0];  I1
(0, 1)
sage: I2 = RealSet.closed(1, 2)[0];  I2
[1, 2]
sage: I1.is_connected(I2)
True
sage: I1.is_connected(I2.interior())
False
sage: I1.closure().is_connected(I2.interior())
True
sage: I2.is_connected(I1)
True
sage: I2.interior().is_connected(I1)
False
sage: I2.closure().is_connected(I1.interior())
True
sage: I3 = RealSet.closed(1/2, 3/2)[0]; I3
[1/2, 3/2]
sage: I1.is_connected(I3)
True
sage: I3.is_connected(I1)
True
>>> from sage.all import *
>>> I1 = RealSet.open(Integer(0), Integer(1))[Integer(0)];  I1
(0, 1)
>>> I2 = RealSet.closed(Integer(1), Integer(2))[Integer(0)];  I2
[1, 2]
>>> I1.is_connected(I2)
True
>>> I1.is_connected(I2.interior())
False
>>> I1.closure().is_connected(I2.interior())
True
>>> I2.is_connected(I1)
True
>>> I2.interior().is_connected(I1)
False
>>> I2.closure().is_connected(I1.interior())
True
>>> I3 = RealSet.closed(Integer(1)/Integer(2), Integer(3)/Integer(2))[Integer(0)]; I3
[1/2, 3/2]
>>> I1.is_connected(I3)
True
>>> I3.is_connected(I1)
True
I1 = RealSet.open(0, 1)[0];  I1
I2 = RealSet.closed(1, 2)[0];  I2
I1.is_connected(I2)
I1.is_connected(I2.interior())
I1.closure().is_connected(I2.interior())
I2.is_connected(I1)
I2.interior().is_connected(I1)
I2.closure().is_connected(I1.interior())
I3 = RealSet.closed(1/2, 3/2)[0]; I3
I1.is_connected(I3)
I3.is_connected(I1)
is_empty()[source]

Return whether the interval is empty.

The normalized form of RealSet has all intervals non-empty, so this method usually returns False.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet(0, 1)[0]
sage: I.is_empty()
False
>>> from sage.all import *
>>> I = RealSet(Integer(0), Integer(1))[Integer(0)]
>>> I.is_empty()
False
I = RealSet(0, 1)[0]
I.is_empty()
is_point()[source]

Return whether the interval consists of a single point.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet(0, 1)[0]
sage: I.is_point()
False
>>> from sage.all import *
>>> I = RealSet(Integer(0), Integer(1))[Integer(0)]
>>> I.is_point()
False
I = RealSet(0, 1)[0]
I.is_point()
lower()[source]

Return the lower bound.

OUTPUT: the lower bound as it was originally specified

EXAMPLES:

sage: I = RealSet(0, 1)[0]
sage: I.lower()
0
sage: I.upper()
1
>>> from sage.all import *
>>> I = RealSet(Integer(0), Integer(1))[Integer(0)]
>>> I.lower()
0
>>> I.upper()
1
I = RealSet(0, 1)[0]
I.lower()
I.upper()
lower_closed()[source]

Return whether the interval is open at the lower bound.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet.open_closed(0, 1)[0];  I
(0, 1]
sage: I.lower_closed()
False
sage: I.lower_open()
True
sage: I.upper_closed()
True
sage: I.upper_open()
False
>>> from sage.all import *
>>> I = RealSet.open_closed(Integer(0), Integer(1))[Integer(0)];  I
(0, 1]
>>> I.lower_closed()
False
>>> I.lower_open()
True
>>> I.upper_closed()
True
>>> I.upper_open()
False
I = RealSet.open_closed(0, 1)[0];  I
I.lower_closed()
I.lower_open()
I.upper_closed()
I.upper_open()
lower_open()[source]

Return whether the interval is closed at the upper bound.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet.open_closed(0, 1)[0];  I
(0, 1]
sage: I.lower_closed()
False
sage: I.lower_open()
True
sage: I.upper_closed()
True
sage: I.upper_open()
False
>>> from sage.all import *
>>> I = RealSet.open_closed(Integer(0), Integer(1))[Integer(0)];  I
(0, 1]
>>> I.lower_closed()
False
>>> I.lower_open()
True
>>> I.upper_closed()
True
>>> I.upper_open()
False
I = RealSet.open_closed(0, 1)[0];  I
I.lower_closed()
I.lower_open()
I.upper_closed()
I.upper_open()
upper()[source]

Return the upper bound.

OUTPUT: the upper bound as it was originally specified

EXAMPLES:

sage: I = RealSet(0, 1)[0]
sage: I.lower()
0
sage: I.upper()
1
>>> from sage.all import *
>>> I = RealSet(Integer(0), Integer(1))[Integer(0)]
>>> I.lower()
0
>>> I.upper()
1
I = RealSet(0, 1)[0]
I.lower()
I.upper()
upper_closed()[source]

Return whether the interval is closed at the lower bound.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet.open_closed(0, 1)[0];  I
(0, 1]
sage: I.lower_closed()
False
sage: I.lower_open()
True
sage: I.upper_closed()
True
sage: I.upper_open()
False
>>> from sage.all import *
>>> I = RealSet.open_closed(Integer(0), Integer(1))[Integer(0)];  I
(0, 1]
>>> I.lower_closed()
False
>>> I.lower_open()
True
>>> I.upper_closed()
True
>>> I.upper_open()
False
I = RealSet.open_closed(0, 1)[0];  I
I.lower_closed()
I.lower_open()
I.upper_closed()
I.upper_open()
upper_open()[source]

Return whether the interval is closed at the upper bound.

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet.open_closed(0, 1)[0];  I
(0, 1]
sage: I.lower_closed()
False
sage: I.lower_open()
True
sage: I.upper_closed()
True
sage: I.upper_open()
False
>>> from sage.all import *
>>> I = RealSet.open_closed(Integer(0), Integer(1))[Integer(0)];  I
(0, 1]
>>> I.lower_closed()
False
>>> I.lower_open()
True
>>> I.upper_closed()
True
>>> I.upper_open()
False
I = RealSet.open_closed(0, 1)[0];  I
I.lower_closed()
I.lower_open()
I.upper_closed()
I.upper_open()
class sage.sets.real_set.RealSet(*intervals, normalized=True)[source]

Bases: UniqueRepresentation, Parent, Set_base, Set_boolean_operators, Set_add_sub_operators

A subset of the real line, a finite union of intervals.

INPUT:

  • *args – arguments defining a real set. Possibilities are either:

    • two extended real numbers a, b, to construct the open interval \((a, b)\), or

    • a list/tuple/iterable of (not necessarily disjoint) intervals or real sets, whose union is taken. The individual intervals can be specified by either

      • a tuple (a, b) of two extended real numbers (constructing an open interval),

      • a list [a, b] of two real numbers (constructing a closed interval),

      • an InternalRealInterval,

      • an OpenInterval.

  • structure – (default: None) if None, construct the real set as an instance of RealSet; if 'differentiable', construct it as a subset of an instance of RealLine, representing the differentiable manifold \(\RR\).

  • ambient – (default: None) an instance of RealLine; construct a subset of it. Using this keyword implies structure='differentiable'.

  • names or coordinate – coordinate symbol for the canonical chart; see RealLine. Using these keywords implies structure='differentiable'.

  • name, latex_name, start_index – see RealLine

  • normalized – (default: None) if True, the input is already normalized, i.e., *args are the connected components (type InternalRealInterval) of the real set in ascending order; no other keyword is provided.

There are also specialized constructors for various types of intervals:

Constructor

Interval

RealSet.open()

\((a, b)\)

RealSet.closed()

\([a, b]\)

RealSet.point()

\(\{a\}\)

RealSet.open_closed()

\((a, b]\)

RealSet.closed_open()

\([a, b)\)

RealSet.unbounded_below_closed()

\((-\infty, b]\)

RealSet.unbounded_below_open()

\((-\infty, b)\)

RealSet.unbounded_above_closed()

\([a, +\infty)\)

RealSet.unbounded_above_open()

\((a, +\infty)\)

RealSet.real_line()

\((-\infty, +\infty)\)

RealSet.interval()

any

EXAMPLES:

sage: RealSet(0, 1)    # open set from two numbers
(0, 1)
sage: RealSet(1, 0)    # the two numbers will be sorted
(0, 1)
sage: s1 = RealSet((1,2)); s1    # tuple of two numbers = open set
(1, 2)
sage: s2 = RealSet([3,4]); s2    # list of two numbers = closed set
[3, 4]
sage: i1, i2 = s1[0], s2[0]
sage: RealSet(i2, i1)            # union of intervals
(1, 2) ∪ [3, 4]
sage: RealSet((-oo, 0), x > 6, i1, RealSet.point(5),                            # needs sage.symbolic
....:         RealSet.closed_open(4, 3))
(-oo, 0) ∪ (1, 2) ∪ [3, 4) ∪ {5} ∪ (6, +oo)
>>> from sage.all import *
>>> RealSet(Integer(0), Integer(1))    # open set from two numbers
(0, 1)
>>> RealSet(Integer(1), Integer(0))    # the two numbers will be sorted
(0, 1)
>>> s1 = RealSet((Integer(1),Integer(2))); s1    # tuple of two numbers = open set
(1, 2)
>>> s2 = RealSet([Integer(3),Integer(4)]); s2    # list of two numbers = closed set
[3, 4]
>>> i1, i2 = s1[Integer(0)], s2[Integer(0)]
>>> RealSet(i2, i1)            # union of intervals
(1, 2) ∪ [3, 4]
>>> RealSet((-oo, Integer(0)), x > Integer(6), i1, RealSet.point(Integer(5)),                            # needs sage.symbolic
...         RealSet.closed_open(Integer(4), Integer(3)))
(-oo, 0) ∪ (1, 2) ∪ [3, 4) ∪ {5} ∪ (6, +oo)
RealSet(0, 1)    # open set from two numbers
RealSet(1, 0)    # the two numbers will be sorted
s1 = RealSet((1,2)); s1    # tuple of two numbers = open set
s2 = RealSet([3,4]); s2    # list of two numbers = closed set
i1, i2 = s1[0], s2[0]
RealSet(i2, i1)            # union of intervals
RealSet((-oo, 0), x > 6, i1, RealSet.point(5),                            # needs sage.symbolic
        RealSet.closed_open(4, 3))

Initialization from manifold objects:

sage: # needs sage.symbolic
sage: R = manifolds.RealLine(); R
Real number line ℝ
sage: RealSet(R)
(-oo, +oo)
sage: I02 = manifolds.OpenInterval(0, 2); I
I
sage: RealSet(I02)
(0, 2)
sage: I01_of_R = manifolds.OpenInterval(0, 1, ambient_interval=R); I01_of_R
Real interval (0, 1)
sage: RealSet(I01_of_R)
(0, 1)
sage: RealSet(I01_of_R.closure())
[0, 1]
sage: I01_of_I02 = manifolds.OpenInterval(0, 1,
....:                                     ambient_interval=I02); I01_of_I02
Real interval (0, 1)
sage: RealSet(I01_of_I02)
(0, 1)
sage: RealSet(I01_of_I02.closure())
(0, 1]
>>> from sage.all import *
>>> # needs sage.symbolic
>>> R = manifolds.RealLine(); R
Real number line ℝ
>>> RealSet(R)
(-oo, +oo)
>>> I02 = manifolds.OpenInterval(Integer(0), Integer(2)); I
I
>>> RealSet(I02)
(0, 2)
>>> I01_of_R = manifolds.OpenInterval(Integer(0), Integer(1), ambient_interval=R); I01_of_R
Real interval (0, 1)
>>> RealSet(I01_of_R)
(0, 1)
>>> RealSet(I01_of_R.closure())
[0, 1]
>>> I01_of_I02 = manifolds.OpenInterval(Integer(0), Integer(1),
...                                     ambient_interval=I02); I01_of_I02
Real interval (0, 1)
>>> RealSet(I01_of_I02)
(0, 1)
>>> RealSet(I01_of_I02.closure())
(0, 1]
# needs sage.symbolic
R = manifolds.RealLine(); R
RealSet(R)
I02 = manifolds.OpenInterval(0, 2); I
RealSet(I02)
I01_of_R = manifolds.OpenInterval(0, 1, ambient_interval=R); I01_of_R
RealSet(I01_of_R)
RealSet(I01_of_R.closure())
I01_of_I02 = manifolds.OpenInterval(0, 1,
                                    ambient_interval=I02); I01_of_I02
RealSet(I01_of_I02)
RealSet(I01_of_I02.closure())

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
>>> from sage.all import *
>>> RealSet().category()
Join of
 Category of finite sets and
 Category of subobjects of sets and
 Category of connected topological spaces
>>> RealSet.point(Integer(1)).category()
Join of
 Category of finite sets and
 Category of subobjects of sets and
 Category of connected topological spaces
>>> RealSet([Integer(1), Integer(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
>>> RealSet((Integer(1), Integer(2)), (Integer(3), Integer(4))).category()
Join of
 Category of infinite sets and
 Category of subobjects of sets and
 Category of topological spaces
RealSet().category()
RealSet.point(1).category()
RealSet([1, 2]).category()
RealSet((1, 2), (3, 4)).category()

Constructing real sets as manifolds or manifold subsets by passing structure='differentiable':

sage: # needs sage.symbolic
sage: RealSet(-oo, oo, structure='differentiable')
Real number line ℝ
sage: RealSet([0, 1], structure='differentiable')
Subset [0, 1] of the Real number line ℝ
sage: _.category()
Category of subobjects of sets
sage: RealSet.open_closed(0, 5, structure='differentiable')
Subset (0, 5] of the Real number line ℝ
>>> from sage.all import *
>>> # needs sage.symbolic
>>> RealSet(-oo, oo, structure='differentiable')
Real number line ℝ
>>> RealSet([Integer(0), Integer(1)], structure='differentiable')
Subset [0, 1] of the Real number line ℝ
>>> _.category()
Category of subobjects of sets
>>> RealSet.open_closed(Integer(0), Integer(5), structure='differentiable')
Subset (0, 5] of the Real number line ℝ
# needs sage.symbolic
RealSet(-oo, oo, structure='differentiable')
RealSet([0, 1], structure='differentiable')
_.category()
RealSet.open_closed(0, 5, structure='differentiable')

This is implied when a coordinate name is given using the keywords coordinate or names:

sage: RealSet(0, 1, coordinate='λ')                                             # needs sage.symbolic
Open subset (0, 1) of the Real number line ℝ
sage: _.category()                                                              # needs sage.symbolic
Join of
 Category of smooth manifolds over Real Field with 53 bits of precision and
 Category of connected manifolds over Real Field with 53 bits of precision and
 Category of subobjects of sets
>>> from sage.all import *
>>> RealSet(Integer(0), Integer(1), coordinate='λ')                                             # needs sage.symbolic
Open subset (0, 1) of the Real number line ℝ
>>> _.category()                                                              # needs sage.symbolic
Join of
 Category of smooth manifolds over Real Field with 53 bits of precision and
 Category of connected manifolds over Real Field with 53 bits of precision and
 Category of subobjects of sets
RealSet(0, 1, coordinate='λ')                                             # needs sage.symbolic
_.category()                                                              # needs sage.symbolic

It is also implied by assigning a coordinate name using generator notation:

sage: R_xi.<ξ> = RealSet.real_line(); R_xi                                      # needs sage.symbolic
Real number line ℝ
sage: R_xi.canonical_chart()                                                    # needs sage.symbolic
Chart (ℝ, (ξ,))
>>> from sage.all import *
>>> R_xi = RealSet.real_line(names=('ξ',)); (ξ,) = R_xi._first_ngens(1); R_xi                                      # needs sage.symbolic
Real number line ℝ
>>> R_xi.canonical_chart()                                                    # needs sage.symbolic
Chart (ℝ, (ξ,))
R_xi.<ξ> = RealSet.real_line(); R_xi                                      # needs sage.symbolic
R_xi.canonical_chart()                                                    # needs sage.symbolic

With the keyword ambient, we can construct a subset of a previously constructed manifold:

sage: # needs sage.symbolic
sage: P_xi = RealSet(0, oo, ambient=R_xi); P_xi
Open subset (0, +oo) of the Real number line ℝ
sage: P_xi.default_chart()
Chart ((0, +oo), (ξ,))
sage: B_xi = RealSet(0, 1, ambient=P_xi); B_xi
Open subset (0, 1) of the Real number line ℝ
sage: B_xi.default_chart()
Chart ((0, 1), (ξ,))
sage: R_xi.subset_family()
Set {(0, +oo), (0, 1), ℝ} of open subsets of the Real number line ℝ
sage: F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F
{0} ∪ {1} ∪ {2}
sage: F_tau = RealSet(F, names='τ'); F_tau
Subset {0} ∪ {1} ∪ {2} of the Real number line ℝ
sage: F_tau.manifold().canonical_chart()
Chart (ℝ, (τ,))
>>> from sage.all import *
>>> # needs sage.symbolic
>>> P_xi = RealSet(Integer(0), oo, ambient=R_xi); P_xi
Open subset (0, +oo) of the Real number line ℝ
>>> P_xi.default_chart()
Chart ((0, +oo), (ξ,))
>>> B_xi = RealSet(Integer(0), Integer(1), ambient=P_xi); B_xi
Open subset (0, 1) of the Real number line ℝ
>>> B_xi.default_chart()
Chart ((0, 1), (ξ,))
>>> R_xi.subset_family()
Set {(0, +oo), (0, 1), ℝ} of open subsets of the Real number line ℝ
>>> F = RealSet.point(Integer(0)).union(RealSet.point(Integer(1))).union(RealSet.point(Integer(2))); F
{0} ∪ {1} ∪ {2}
>>> F_tau = RealSet(F, names='τ'); F_tau
Subset {0} ∪ {1} ∪ {2} of the Real number line ℝ
>>> F_tau.manifold().canonical_chart()
Chart (ℝ, (τ,))
# needs sage.symbolic
P_xi = RealSet(0, oo, ambient=R_xi); P_xi
P_xi.default_chart()
B_xi = RealSet(0, 1, ambient=P_xi); B_xi
B_xi.default_chart()
R_xi.subset_family()
F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F
F_tau = RealSet(F, names='τ'); F_tau
F_tau.manifold().canonical_chart()
ambient()[source]

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)
>>> from sage.all import *
>>> s = RealSet(RealSet.open_closed(Integer(0),Integer(1)), RealSet.closed_open(Integer(2),Integer(3)))
>>> s.ambient()
(-oo, +oo)
s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
s.ambient()
static are_pairwise_disjoint(*real_set_collection)[source]

Test whether the real sets are pairwise disjoint.

INPUT:

  • *real_set_collection – list/tuple/iterable of RealSet or data that defines one

OUTPUT: boolean

See also

is_disjoint()

EXAMPLES:

sage: s1 = RealSet((0, 1), (2, 3))
sage: s2 = RealSet((1, 2))
sage: s3 = RealSet.point(3)
sage: RealSet.are_pairwise_disjoint(s1, s2, s3)
True
sage: RealSet.are_pairwise_disjoint(s1, s2, s3, [10,10])
True
sage: RealSet.are_pairwise_disjoint(s1, s2, s3, [-1, 1/2])
False
>>> from sage.all import *
>>> s1 = RealSet((Integer(0), Integer(1)), (Integer(2), Integer(3)))
>>> s2 = RealSet((Integer(1), Integer(2)))
>>> s3 = RealSet.point(Integer(3))
>>> RealSet.are_pairwise_disjoint(s1, s2, s3)
True
>>> RealSet.are_pairwise_disjoint(s1, s2, s3, [Integer(10),Integer(10)])
True
>>> RealSet.are_pairwise_disjoint(s1, s2, s3, [-Integer(1), Integer(1)/Integer(2)])
False
s1 = RealSet((0, 1), (2, 3))
s2 = RealSet((1, 2))
s3 = RealSet.point(3)
RealSet.are_pairwise_disjoint(s1, s2, s3)
RealSet.are_pairwise_disjoint(s1, s2, s3, [10,10])
RealSet.are_pairwise_disjoint(s1, s2, s3, [-1, 1/2])
boundary()[source]

Return the topological boundary of self as a new RealSet.

EXAMPLES:

sage: RealSet(-oo, oo).boundary()
{}
sage: RealSet().boundary()
{}
sage: RealSet.point(2).boundary()
{2}
sage: RealSet([1, 2], (3, 4)).boundary()
{1} ∪ {2} ∪ {3} ∪ {4}
sage: RealSet((1, 2), (2, 3)).boundary()
{1} ∪ {2} ∪ {3}
>>> from sage.all import *
>>> RealSet(-oo, oo).boundary()
{}
>>> RealSet().boundary()
{}
>>> RealSet.point(Integer(2)).boundary()
{2}
>>> RealSet([Integer(1), Integer(2)], (Integer(3), Integer(4))).boundary()
{1} ∪ {2} ∪ {3} ∪ {4}
>>> RealSet((Integer(1), Integer(2)), (Integer(2), Integer(3))).boundary()
{1} ∪ {2} ∪ {3}
RealSet(-oo, oo).boundary()
RealSet().boundary()
RealSet.point(2).boundary()
RealSet([1, 2], (3, 4)).boundary()
RealSet((1, 2), (2, 3)).boundary()
cardinality()[source]

Return the cardinality of the subset of the real line.

OUTPUT:

Integer or infinity; the size of a discrete set is the number of points; the size of a real interval is Infinity.

EXAMPLES:

sage: RealSet([0, 0], [1, 1], [3, 3]).cardinality()
3
sage: RealSet(0,3).cardinality()
+Infinity
>>> from sage.all import *
>>> RealSet([Integer(0), Integer(0)], [Integer(1), Integer(1)], [Integer(3), Integer(3)]).cardinality()
3
>>> RealSet(Integer(0),Integer(3)).cardinality()
+Infinity
RealSet([0, 0], [1, 1], [3, 3]).cardinality()
RealSet(0,3).cardinality()
static closed(lower, upper, **kwds)[source]

Construct a closed interval.

INPUT:

  • lower, upper – two real numbers or infinity; they will be sorted if necessary

  • **kwds – see RealSet

OUTPUT: a new RealSet

EXAMPLES:

sage: RealSet.closed(1, 0)
[0, 1]
>>> from sage.all import *
>>> RealSet.closed(Integer(1), Integer(0))
[0, 1]
RealSet.closed(1, 0)
static closed_open(lower, upper, **kwds)[source]

Construct a half-open interval.

INPUT:

  • lower, upper – two real numbers or infinity; they will be sorted if necessary

  • **kwds – see RealSet

OUTPUT:

A new RealSet that is closed at the lower bound and open at the upper bound.

EXAMPLES:

sage: RealSet.closed_open(1, 0)
[0, 1)
>>> from sage.all import *
>>> RealSet.closed_open(Integer(1), Integer(0))
[0, 1)
RealSet.closed_open(1, 0)
closure()[source]

Return the topological closure of self as a new RealSet.

EXAMPLES:

sage: RealSet(-oo, oo).closure()
(-oo, +oo)
sage: RealSet((1, 2), (2, 3)).closure()
[1, 3]
sage: RealSet().closure()
{}
>>> from sage.all import *
>>> RealSet(-oo, oo).closure()
(-oo, +oo)
>>> RealSet((Integer(1), Integer(2)), (Integer(2), Integer(3))).closure()
[1, 3]
>>> RealSet().closure()
{}
RealSet(-oo, oo).closure()
RealSet((1, 2), (2, 3)).closure()
RealSet().closure()
complement()[source]

Return the complement.

OUTPUT: the set-theoretic complement as a new RealSet

EXAMPLES:

sage: RealSet(0,1).complement()
(-oo, 0] ∪ [1, +oo)

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
(0, 2) ∪ [10, +oo)
sage: s1.complement()
(-oo, 0] ∪ [2, 10)

sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s2.complement()
(-10, 1] ∪ [3, +oo)
>>> from sage.all import *
>>> RealSet(Integer(0),Integer(1)).complement()
(-oo, 0] ∪ [1, +oo)

>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1
(0, 2) ∪ [10, +oo)
>>> s1.complement()
(-oo, 0] ∪ [2, 10)

>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s2.complement()
(-10, 1] ∪ [3, +oo)
RealSet(0,1).complement()
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
s1.complement()
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s2.complement()
contains(x)[source]

Return whether \(x\) is contained in the set.

INPUT:

  • x – a real number

OUTPUT: boolean

EXAMPLES:

sage: s = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s
(0, 2) ∪ [10, +oo)
sage: s.contains(1)
True
sage: s.contains(0)
False
sage: s.contains(10.0)
True
sage: 10 in s    # syntactic sugar
True
sage: s.contains(+oo)
False
sage: RealSet().contains(1)
False
>>> from sage.all import *
>>> s = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s
(0, 2) ∪ [10, +oo)
>>> s.contains(Integer(1))
True
>>> s.contains(Integer(0))
False
>>> s.contains(RealNumber('10.0'))
True
>>> Integer(10) in s    # syntactic sugar
True
>>> s.contains(+oo)
False
>>> RealSet().contains(Integer(1))
False
s = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s
s.contains(1)
s.contains(0)
s.contains(10.0)
10 in s    # syntactic sugar
s.contains(+oo)
RealSet().contains(1)
static convex_hull(*real_set_collection)[source]

Return the convex hull of real sets.

INPUT:

  • *real_set_collection – list/tuple/iterable of RealSet or data that defines one

OUTPUT: the convex hull as a new RealSet

EXAMPLES:

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1 # unbounded set
(0, 2) ∪ [10, +oo)
sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s3 = RealSet((0,2), RealSet.point(8)); s3
(0, 2) ∪ {8}
sage: s4 = RealSet(); s4  # empty set
{}
sage: RealSet.convex_hull(s1)
(0, +oo)
sage: RealSet.convex_hull(s2)
(-oo, 3)
sage: RealSet.convex_hull(s3)
(0, 8]
sage: RealSet.convex_hull(s4)
{}
sage: RealSet.convex_hull(s1, s2)
(-oo, +oo)
sage: RealSet.convex_hull(s2, s3)
(-oo, 8]
sage: RealSet.convex_hull(s2, s3, s4)
(-oo, 8]
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1 # unbounded set
(0, 2) ∪ [10, +oo)
>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s3 = RealSet((Integer(0),Integer(2)), RealSet.point(Integer(8))); s3
(0, 2) ∪ {8}
>>> s4 = RealSet(); s4  # empty set
{}
>>> RealSet.convex_hull(s1)
(0, +oo)
>>> RealSet.convex_hull(s2)
(-oo, 3)
>>> RealSet.convex_hull(s3)
(0, 8]
>>> RealSet.convex_hull(s4)
{}
>>> RealSet.convex_hull(s1, s2)
(-oo, +oo)
>>> RealSet.convex_hull(s2, s3)
(-oo, 8]
>>> RealSet.convex_hull(s2, s3, s4)
(-oo, 8]
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1 # unbounded set
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s3 = RealSet((0,2), RealSet.point(8)); s3
s4 = RealSet(); s4  # empty set
RealSet.convex_hull(s1)
RealSet.convex_hull(s2)
RealSet.convex_hull(s3)
RealSet.convex_hull(s4)
RealSet.convex_hull(s1, s2)
RealSet.convex_hull(s2, s3)
RealSet.convex_hull(s2, s3, s4)
difference(*other)[source]

Return self with other subtracted.

INPUT:

  • other – a RealSet or data that defines one

OUTPUT:

The set-theoretic difference of self with other removed as a new RealSet.

EXAMPLES:

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
(0, 2) ∪ [10, +oo)
sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s1.difference(s2)
(0, 1] ∪ [10, +oo)
sage: s1 - s2    # syntactic sugar
(0, 1] ∪ [10, +oo)
sage: s2.difference(s1)
(-oo, -10] ∪ [2, 3)
sage: s2 - s1    # syntactic sugar
(-oo, -10] ∪ [2, 3)
sage: s1.difference(1,11)
(0, 1] ∪ [11, +oo)
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1
(0, 2) ∪ [10, +oo)
>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s1.difference(s2)
(0, 1] ∪ [10, +oo)
>>> s1 - s2    # syntactic sugar
(0, 1] ∪ [10, +oo)
>>> s2.difference(s1)
(-oo, -10] ∪ [2, 3)
>>> s2 - s1    # syntactic sugar
(-oo, -10] ∪ [2, 3)
>>> s1.difference(Integer(1),Integer(11))
(0, 1] ∪ [11, +oo)
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s1.difference(s2)
s1 - s2    # syntactic sugar
s2.difference(s1)
s2 - s1    # syntactic sugar
s1.difference(1,11)
get_interval(i)[source]

Return the i-th connected component.

Note that the intervals representing the real set are always normalized, i.e., they are sorted, disjoint and not connected.

INPUT:

  • i – integer

OUTPUT: the \(i\)-th connected component as a InternalRealInterval

EXAMPLES:

sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
sage: s.get_interval(0)
(0, 1]
sage: s[0]    # shorthand
(0, 1]
sage: s.get_interval(1)
[2, 3)
sage: s[0] == s.get_interval(0)
True
>>> from sage.all import *
>>> s = RealSet(RealSet.open_closed(Integer(0),Integer(1)), RealSet.closed_open(Integer(2),Integer(3)))
>>> s.get_interval(Integer(0))
(0, 1]
>>> s[Integer(0)]    # shorthand
(0, 1]
>>> s.get_interval(Integer(1))
[2, 3)
>>> s[Integer(0)] == s.get_interval(Integer(0))
True
s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
s.get_interval(0)
s[0]    # shorthand
s.get_interval(1)
s[0] == s.get_interval(0)
inf()[source]

Return the infimum.

OUTPUT: a real number or infinity

EXAMPLES:

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
(0, 2) ∪ [10, +oo)
sage: s1.inf()
0

sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s2.inf()
-Infinity
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1
(0, 2) ∪ [10, +oo)
>>> s1.inf()
0

>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s2.inf()
-Infinity
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
s1.inf()
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s2.inf()
interior()[source]

Return the topological interior of self as a new RealSet.

EXAMPLES:

sage: RealSet(-oo, oo).interior()
(-oo, +oo)
sage: RealSet().interior()
{}
sage: RealSet.point(2).interior()
{}
sage: RealSet([1, 2], (3, 4)).interior()
(1, 2) ∪ (3, 4)
>>> from sage.all import *
>>> RealSet(-oo, oo).interior()
(-oo, +oo)
>>> RealSet().interior()
{}
>>> RealSet.point(Integer(2)).interior()
{}
>>> RealSet([Integer(1), Integer(2)], (Integer(3), Integer(4))).interior()
(1, 2) ∪ (3, 4)
RealSet(-oo, oo).interior()
RealSet().interior()
RealSet.point(2).interior()
RealSet([1, 2], (3, 4)).interior()
intersection(*real_set_collection)[source]

Return the intersection of real sets.

INPUT:

  • *real_set_collection – list/tuple/iterable of RealSet or data that defines one

OUTPUT: the set-theoretic intersection as a new RealSet

EXAMPLES:

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
(0, 2) ∪ [10, +oo)
sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s1.intersection(s2)
(1, 2)
sage: s1 & s2    # syntactic sugar
(1, 2)
sage: s3 = RealSet((0, 1), (2, 3));  s3
(0, 1) ∪ (2, 3)
sage: s4 = RealSet([0, 1], [2, 3]);  s4
[0, 1] ∪ [2, 3]
sage: s3.intersection(s4)
(0, 1) ∪ (2, 3)
sage: s3.intersection([1, 2])
{}
sage: s4.intersection([1, 2])
{1} ∪ {2}
sage: s4.intersection(1, 2)
{}
sage: s5 = RealSet.closed_open(1, 10);  s5
[1, 10)
sage: s5.intersection(-oo, +oo)
[1, 10)
sage: s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0])             # needs sage.symbolic
[1, 2) ∪ (2, 3)
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1
(0, 2) ∪ [10, +oo)
>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s1.intersection(s2)
(1, 2)
>>> s1 & s2    # syntactic sugar
(1, 2)
>>> s3 = RealSet((Integer(0), Integer(1)), (Integer(2), Integer(3)));  s3
(0, 1) ∪ (2, 3)
>>> s4 = RealSet([Integer(0), Integer(1)], [Integer(2), Integer(3)]);  s4
[0, 1] ∪ [2, 3]
>>> s3.intersection(s4)
(0, 1) ∪ (2, 3)
>>> s3.intersection([Integer(1), Integer(2)])
{}
>>> s4.intersection([Integer(1), Integer(2)])
{1} ∪ {2}
>>> s4.intersection(Integer(1), Integer(2))
{}
>>> s5 = RealSet.closed_open(Integer(1), Integer(10));  s5
[1, 10)
>>> s5.intersection(-oo, +oo)
[1, 10)
>>> s5.intersection(x != Integer(2), (-oo, Integer(3)), RealSet.real_line()[Integer(0)])             # needs sage.symbolic
[1, 2) ∪ (2, 3)
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s1.intersection(s2)
s1 & s2    # syntactic sugar
s3 = RealSet((0, 1), (2, 3));  s3
s4 = RealSet([0, 1], [2, 3]);  s4
s3.intersection(s4)
s3.intersection([1, 2])
s4.intersection([1, 2])
s4.intersection(1, 2)
s5 = RealSet.closed_open(1, 10);  s5
s5.intersection(-oo, +oo)
s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0])             # needs sage.symbolic
static interval(lower, upper, lower_closed, upper_closed, **kwds)[source]

Construct an interval.

INPUT:

  • lower, upper – two real numbers or infinity; they will be sorted if necessary

  • lower_closed, upper_closed – boolean; whether the interval is closed at the lower and upper bound of the interval, respectively

  • **kwds – see RealSet

OUTPUT: a new RealSet

EXAMPLES:

sage: RealSet.interval(1, 0, lower_closed=True, upper_closed=False)
[0, 1)
>>> from sage.all import *
>>> RealSet.interval(Integer(1), Integer(0), lower_closed=True, upper_closed=False)
[0, 1)
RealSet.interval(1, 0, lower_closed=True, upper_closed=False)
is_closed()[source]

Return whether self is a closed set.

EXAMPLES:

sage: RealSet().is_closed()
True
sage: RealSet.point(1).is_closed()
True
sage: RealSet([1, 2]).is_closed()
True
sage: RealSet([1, 2], (3, 4)).is_closed()
False
sage: RealSet(-oo, +oo).is_closed()
True
>>> from sage.all import *
>>> RealSet().is_closed()
True
>>> RealSet.point(Integer(1)).is_closed()
True
>>> RealSet([Integer(1), Integer(2)]).is_closed()
True
>>> RealSet([Integer(1), Integer(2)], (Integer(3), Integer(4))).is_closed()
False
>>> RealSet(-oo, +oo).is_closed()
True
RealSet().is_closed()
RealSet.point(1).is_closed()
RealSet([1, 2]).is_closed()
RealSet([1, 2], (3, 4)).is_closed()
RealSet(-oo, +oo).is_closed()
is_connected()[source]

Return whether self is a connected set.

OUTPUT: boolean

EXAMPLES:

sage: s1 = RealSet((1, 2), (2, 4));  s1
(1, 2) ∪ (2, 4)
sage: s1.is_connected()
False
sage: s2 = RealSet((1, 2), (2, 4), RealSet.point(2));  s2
(1, 4)
sage: s2.is_connected()
True
sage: s3 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s3
(-oo, -10] ∪ (1, 3)
sage: s3.is_connected()
False
sage: RealSet(x != 0).is_connected()                                        # needs sage.symbolic
False
sage: RealSet(-oo, oo).is_connected()
True
sage: RealSet().is_connected()
False
>>> from sage.all import *
>>> s1 = RealSet((Integer(1), Integer(2)), (Integer(2), Integer(4)));  s1
(1, 2) ∪ (2, 4)
>>> s1.is_connected()
False
>>> s2 = RealSet((Integer(1), Integer(2)), (Integer(2), Integer(4)), RealSet.point(Integer(2)));  s2
(1, 4)
>>> s2.is_connected()
True
>>> s3 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s3
(-oo, -10] ∪ (1, 3)
>>> s3.is_connected()
False
>>> RealSet(x != Integer(0)).is_connected()                                        # needs sage.symbolic
False
>>> RealSet(-oo, oo).is_connected()
True
>>> RealSet().is_connected()
False
s1 = RealSet((1, 2), (2, 4));  s1
s1.is_connected()
s2 = RealSet((1, 2), (2, 4), RealSet.point(2));  s2
s2.is_connected()
s3 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s3
s3.is_connected()
RealSet(x != 0).is_connected()                                        # needs sage.symbolic
RealSet(-oo, oo).is_connected()
RealSet().is_connected()
is_disjoint(*other)[source]

Test whether the two sets are disjoint.

INPUT:

  • other – a RealSet or data defining one

OUTPUT: boolean

EXAMPLES:

sage: s = RealSet((0, 1), (2, 3));  s
(0, 1) ∪ (2, 3)
sage: s.is_disjoint(RealSet([1, 2]))
True
sage: s.is_disjoint([3/2, 5/2])
False
sage: s.is_disjoint(RealSet())
True
sage: s.is_disjoint(RealSet().real_line())
False
>>> from sage.all import *
>>> s = RealSet((Integer(0), Integer(1)), (Integer(2), Integer(3)));  s
(0, 1) ∪ (2, 3)
>>> s.is_disjoint(RealSet([Integer(1), Integer(2)]))
True
>>> s.is_disjoint([Integer(3)/Integer(2), Integer(5)/Integer(2)])
False
>>> s.is_disjoint(RealSet())
True
>>> s.is_disjoint(RealSet().real_line())
False
s = RealSet((0, 1), (2, 3));  s
s.is_disjoint(RealSet([1, 2]))
s.is_disjoint([3/2, 5/2])
s.is_disjoint(RealSet())
s.is_disjoint(RealSet().real_line())
is_empty()[source]

Return whether the set is empty.

EXAMPLES:

sage: RealSet(0, 1).is_empty()
False
sage: RealSet(0, 0).is_empty()
True
sage: RealSet.interval(1, 1, lower_closed=False, upper_closed=True).is_empty()
True
sage: RealSet.interval(1, -1, lower_closed=False, upper_closed=True).is_empty()
False
>>> from sage.all import *
>>> RealSet(Integer(0), Integer(1)).is_empty()
False
>>> RealSet(Integer(0), Integer(0)).is_empty()
True
>>> RealSet.interval(Integer(1), Integer(1), lower_closed=False, upper_closed=True).is_empty()
True
>>> RealSet.interval(Integer(1), -Integer(1), lower_closed=False, upper_closed=True).is_empty()
False
RealSet(0, 1).is_empty()
RealSet(0, 0).is_empty()
RealSet.interval(1, 1, lower_closed=False, upper_closed=True).is_empty()
RealSet.interval(1, -1, lower_closed=False, upper_closed=True).is_empty()
is_open()[source]

Return whether self is an open set.

EXAMPLES:

sage: RealSet().is_open()
True
sage: RealSet.point(1).is_open()
False
sage: RealSet((1, 2)).is_open()
True
sage: RealSet([1, 2], (3, 4)).is_open()
False
sage: RealSet(-oo, +oo).is_open()
True
>>> from sage.all import *
>>> RealSet().is_open()
True
>>> RealSet.point(Integer(1)).is_open()
False
>>> RealSet((Integer(1), Integer(2))).is_open()
True
>>> RealSet([Integer(1), Integer(2)], (Integer(3), Integer(4))).is_open()
False
>>> RealSet(-oo, +oo).is_open()
True
RealSet().is_open()
RealSet.point(1).is_open()
RealSet((1, 2)).is_open()
RealSet([1, 2], (3, 4)).is_open()
RealSet(-oo, +oo).is_open()
is_subset(*other)[source]

Return whether self is a subset of other.

INPUT:

  • *other – a RealSet or something that defines one

OUTPUT: boolean

EXAMPLES:

sage: I = RealSet((1,2))
sage: J = RealSet((1,3))
sage: K = RealSet((2,3))
sage: I.is_subset(J)
True
sage: J.is_subset(K)
False
>>> from sage.all import *
>>> I = RealSet((Integer(1),Integer(2)))
>>> J = RealSet((Integer(1),Integer(3)))
>>> K = RealSet((Integer(2),Integer(3)))
>>> I.is_subset(J)
True
>>> J.is_subset(K)
False
I = RealSet((1,2))
J = RealSet((1,3))
K = RealSet((2,3))
I.is_subset(J)
J.is_subset(K)
is_universe()[source]

Return whether the set is the ambient space (the real line).

EXAMPLES:

sage: RealSet().ambient().is_universe()
True
>>> from sage.all import *
>>> RealSet().ambient().is_universe()
True
RealSet().ambient().is_universe()
lift(x)[source]

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
>>> from sage.all import *
>>> s = RealSet(Integer(0), Integer(2)); s
(0, 2)
>>> s.lift(Integer(1))
1
s = RealSet(0, 2); s
s.lift(1)
n_components()[source]

Return the number of connected components.

See also get_interval().

EXAMPLES:

sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
sage: s.n_components()
2
>>> from sage.all import *
>>> s = RealSet(RealSet.open_closed(Integer(0),Integer(1)), RealSet.closed_open(Integer(2),Integer(3)))
>>> s.n_components()
2
s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
s.n_components()
normalize(intervals)[source]

Bring a collection of intervals into canonical form.

INPUT:

  • intervals – list/tuple/iterable of intervals

OUTPUT: a tuple of intervals such that

  • they are sorted in ascending order (by lower bound)

  • there is a gap between each interval

  • all intervals are non-empty

EXAMPLES:

sage: i1 = RealSet((0, 1))[0]
sage: i2 = RealSet([1, 2])[0]
sage: i3 = RealSet((2, 3))[0]
sage: RealSet.normalize([i1, i2, i3])
((0, 3),)
>>> from sage.all import *
>>> i1 = RealSet((Integer(0), Integer(1)))[Integer(0)]
>>> i2 = RealSet([Integer(1), Integer(2)])[Integer(0)]
>>> i3 = RealSet((Integer(2), Integer(3)))[Integer(0)]
>>> RealSet.normalize([i1, i2, i3])
((0, 3),)
i1 = RealSet((0, 1))[0]
i2 = RealSet([1, 2])[0]
i3 = RealSet((2, 3))[0]
RealSet.normalize([i1, i2, i3])
static open(lower, upper, **kwds)[source]

Construct an open interval.

INPUT:

  • lower, upper – two real numbers or infinity; they will be sorted if necessary

  • **kwds – see RealSet

OUTPUT: a new RealSet

EXAMPLES:

sage: RealSet.open(1, 0)
(0, 1)
>>> from sage.all import *
>>> RealSet.open(Integer(1), Integer(0))
(0, 1)
RealSet.open(1, 0)
static open_closed(lower, upper, **kwds)[source]

Construct a half-open interval.

INPUT:

  • lower, upper – two real numbers or infinity; they will be sorted if necessary

  • **kwds – see RealSet

OUTPUT:

A new RealSet that is open at the lower bound and closed at the upper bound.

EXAMPLES:

sage: RealSet.open_closed(1, 0)
(0, 1]
>>> from sage.all import *
>>> RealSet.open_closed(Integer(1), Integer(0))
(0, 1]
RealSet.open_closed(1, 0)
static point(p, **kwds)[source]

Construct an interval containing a single point.

INPUT:

  • p – a real number

  • **kwds – see RealSet

OUTPUT: a new RealSet

EXAMPLES:

sage: RealSet.open(1, 0)
(0, 1)
>>> from sage.all import *
>>> RealSet.open(Integer(1), Integer(0))
(0, 1)
RealSet.open(1, 0)
static real_line(**kwds)[source]

Construct the real line.

INPUT:

EXAMPLES:

sage: RealSet.real_line()
(-oo, +oo)
>>> from sage.all import *
>>> RealSet.real_line()
(-oo, +oo)
RealSet.real_line()
retract(x)[source]

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)
>>> from sage.all import *
>>> s = RealSet(Integer(0), Integer(2)); s
(0, 2)
>>> s.retract(Integer(1))
1
>>> s.retract(Integer(2))
Traceback (most recent call last):
...
ValueError: 2 is not an element of (0, 2)
s = RealSet(0, 2); s
s.retract(1)
s.retract(2)
simplest_rational()[source]

Return the simplest rational in this interval. Given rationals \(a / b\) and \(c / d\) (both in lowest terms), the former is simpler if \(b<d\) or if \(b = d\) and \(|a| < |c|\).

OUTPUT: Rational

EXAMPLES:

sage: s = RealSet((1, 2));  s
(1, 2)
sage: s.simplest_rational()
3/2
sage: s = RealSet.point(1/2);  s
{1/2}
sage: s.simplest_rational()
1/2
sage: s = RealSet(1.5 <= x);  s                                             # needs sage.symbolic
[1.50000000000000, +oo)
sage: s.simplest_rational()                                                 # needs sage.symbolic
2
sage: s = RealSet.real_line();  s
(-oo, +oo)
sage: s.simplest_rational()
0
sage: s = RealSet.point(1/2) + RealSet.point(-1/2);  s
{-1/2} ∪ {1/2}
sage: s.simplest_rational()
1/2
sage: s = RealSet(x == pi);  s                                              # needs sage.symbolic
{pi}
sage: s.simplest_rational()                                                 # needs sage.symbolic
Traceback (most recent call last):
...
NotImplementedError...
sage: s = RealSet((0, 1));  s
(0, 1)
sage: s.simplest_rational()
Traceback (most recent call last):
...
NotImplementedError...
sage: s = RealSet();  s
{}
sage: s.simplest_rational()
Traceback (most recent call last):
...
EmptySetError...
>>> from sage.all import *
>>> s = RealSet((Integer(1), Integer(2)));  s
(1, 2)
>>> s.simplest_rational()
3/2
>>> s = RealSet.point(Integer(1)/Integer(2));  s
{1/2}
>>> s.simplest_rational()
1/2
>>> s = RealSet(RealNumber('1.5') <= x);  s                                             # needs sage.symbolic
[1.50000000000000, +oo)
>>> s.simplest_rational()                                                 # needs sage.symbolic
2
>>> s = RealSet.real_line();  s
(-oo, +oo)
>>> s.simplest_rational()
0
>>> s = RealSet.point(Integer(1)/Integer(2)) + RealSet.point(-Integer(1)/Integer(2));  s
{-1/2} ∪ {1/2}
>>> s.simplest_rational()
1/2
>>> s = RealSet(x == pi);  s                                              # needs sage.symbolic
{pi}
>>> s.simplest_rational()                                                 # needs sage.symbolic
Traceback (most recent call last):
...
NotImplementedError...
>>> s = RealSet((Integer(0), Integer(1)));  s
(0, 1)
>>> s.simplest_rational()
Traceback (most recent call last):
...
NotImplementedError...
>>> s = RealSet();  s
{}
>>> s.simplest_rational()
Traceback (most recent call last):
...
EmptySetError...
s = RealSet((1, 2));  s
s.simplest_rational()
s = RealSet.point(1/2);  s
s.simplest_rational()
s = RealSet(1.5 <= x);  s                                             # needs sage.symbolic
s.simplest_rational()                                                 # needs sage.symbolic
s = RealSet.real_line();  s
s.simplest_rational()
s = RealSet.point(1/2) + RealSet.point(-1/2);  s
s.simplest_rational()
s = RealSet(x == pi);  s                                              # needs sage.symbolic
s.simplest_rational()                                                 # needs sage.symbolic
s = RealSet((0, 1));  s
s.simplest_rational()
s = RealSet();  s
s.simplest_rational()
sup()[source]

Return the supremum.

OUTPUT: a real number or infinity

EXAMPLES:

sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
(0, 2) ∪ [10, +oo)
sage: s1.sup()
+Infinity

sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
(-oo, -10] ∪ (1, 3)
sage: s2.sup()
3
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)) + RealSet.unbounded_above_closed(Integer(10));  s1
(0, 2) ∪ [10, +oo)
>>> s1.sup()
+Infinity

>>> s2 = RealSet(Integer(1),Integer(3)) + RealSet.unbounded_below_closed(-Integer(10));  s2
(-oo, -10] ∪ (1, 3)
>>> s2.sup()
3
s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
s1.sup()
s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
s2.sup()
symmetric_difference(*other)[source]

Return the symmetric difference of self and other.

INPUT:

  • other – a RealSet or data that defines one

OUTPUT:

The set-theoretic symmetric difference of self and other as a new RealSet.

EXAMPLES:

sage: s1 = RealSet(0,2); s1
(0, 2)
sage: s2 = RealSet.unbounded_above_open(1); s2
(1, +oo)
sage: s1.symmetric_difference(s2)
(0, 1] ∪ [2, +oo)
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2)); s1
(0, 2)
>>> s2 = RealSet.unbounded_above_open(Integer(1)); s2
(1, +oo)
>>> s1.symmetric_difference(s2)
(0, 1] ∪ [2, +oo)
s1 = RealSet(0,2); s1
s2 = RealSet.unbounded_above_open(1); s2
s1.symmetric_difference(s2)
static unbounded_above_closed(bound, **kwds)[source]

Construct a semi-infinite interval.

INPUT:

  • bound – a real number

  • **kwds – see RealSet

OUTPUT:

A new RealSet from the bound (including) to plus infinity.

EXAMPLES:

sage: RealSet.unbounded_above_closed(1)
[1, +oo)
>>> from sage.all import *
>>> RealSet.unbounded_above_closed(Integer(1))
[1, +oo)
RealSet.unbounded_above_closed(1)
static unbounded_above_open(bound, **kwds)[source]

Construct a semi-infinite interval.

INPUT:

  • bound – a real number

  • **kwds – see RealSet

OUTPUT:

A new RealSet from the bound (excluding) to plus infinity.

EXAMPLES:

sage: RealSet.unbounded_above_open(1)
(1, +oo)
>>> from sage.all import *
>>> RealSet.unbounded_above_open(Integer(1))
(1, +oo)
RealSet.unbounded_above_open(1)
static unbounded_below_closed(bound, **kwds)[source]

Construct a semi-infinite interval.

INPUT:

  • bound – a real number

OUTPUT:

A new RealSet from minus infinity to the bound (including).

EXAMPLES:

sage: RealSet.unbounded_below_closed(1)
(-oo, 1]
>>> from sage.all import *
>>> RealSet.unbounded_below_closed(Integer(1))
(-oo, 1]
RealSet.unbounded_below_closed(1)
static unbounded_below_open(bound, **kwds)[source]

Construct a semi-infinite interval.

INPUT:

  • bound – a real number

OUTPUT:

A new RealSet from minus infinity to the bound (excluding).

EXAMPLES:

sage: RealSet.unbounded_below_open(1)
(-oo, 1)
>>> from sage.all import *
>>> RealSet.unbounded_below_open(Integer(1))
(-oo, 1)
RealSet.unbounded_below_open(1)
union(*real_set_collection)[source]

Return the union of real sets.

INPUT:

  • *real_set_collection – list/tuple/iterable of RealSet or data that defines one

OUTPUT: the set-theoretic union as a new RealSet

EXAMPLES:

sage: s1 = RealSet(0,2)
sage: s2 = RealSet(1,3)
sage: s1.union(s2)
(0, 3)
sage: s1.union(1,3)
(0, 3)
sage: s1 | s2    # syntactic sugar
(0, 3)
sage: s1 + s2    # syntactic sugar
(0, 3)
sage: RealSet().union(RealSet.real_line())
(-oo, +oo)
sage: s = RealSet().union([1, 2], (2, 3)); s
[1, 3)
sage: RealSet().union((-oo, 0), x > 6, s[0],                                # needs sage.symbolic
....:                 RealSet.point(5.0), RealSet.closed_open(2, 4))
(-oo, 0) ∪ [1, 4) ∪ {5} ∪ (6, +oo)
>>> from sage.all import *
>>> s1 = RealSet(Integer(0),Integer(2))
>>> s2 = RealSet(Integer(1),Integer(3))
>>> s1.union(s2)
(0, 3)
>>> s1.union(Integer(1),Integer(3))
(0, 3)
>>> s1 | s2    # syntactic sugar
(0, 3)
>>> s1 + s2    # syntactic sugar
(0, 3)
>>> RealSet().union(RealSet.real_line())
(-oo, +oo)
>>> s = RealSet().union([Integer(1), Integer(2)], (Integer(2), Integer(3))); s
[1, 3)
>>> RealSet().union((-oo, Integer(0)), x > Integer(6), s[Integer(0)],                                # needs sage.symbolic
...                 RealSet.point(RealNumber('5.0')), RealSet.closed_open(Integer(2), Integer(4)))
(-oo, 0) ∪ [1, 4) ∪ {5} ∪ (6, +oo)
s1 = RealSet(0,2)
s2 = RealSet(1,3)
s1.union(s2)
s1.union(1,3)
s1 | s2    # syntactic sugar
s1 + s2    # syntactic sugar
RealSet().union(RealSet.real_line())
s = RealSet().union([1, 2], (2, 3)); s
RealSet().union((-oo, 0), x > 6, s[0],                                # needs sage.symbolic
                RealSet.point(5.0), RealSet.closed_open(2, 4))