Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- 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(-oo, oo) (-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: invalid syntax
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)
Relations containing symbols and numeric values or constants::
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)
Note that multiple arguments are combined as union::
sage: RealSet(x >= 0, x < 1) (-oo, +oo) sage: RealSet(x >= 0, x > 1) [0, +oo) sage: RealSet(x >= 0, x > -1) (-1, +oo)
AUTHORS:
- Laurent Claessens (2010-12-10): Interval and ContinuousSet, posted to sage-devel at http://www.mail-archive.com/sage-support@googlegroups.com/msg21326.html.
- Ares Ribo (2011-10-24): Extended the previous work defining the class RealSet.
- Jordi Saludes (2011-12-10): Documentation and file reorganization.
- Volker Braun (2013-06-22): Rewrite """
#***************************************************************************** # Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
""" A real interval.
You are not supposed to create :class:`RealInterval` objects yourself. Always use :class:`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 """ """ Initialize ``self``.
EXAMPLES::
sage: RealSet([0, oo]) Traceback (most recent call last): ... ValueError: interval cannot be closed at +oo """ raise ValueError('lower bound must be in RLF or minus infinity') raise ValueError('upper bound must be in RLF or plus infinity') raise ValueError('lower_closed must be boolean') raise ValueError('upper_closed must be boolean') # comparison of infinity with RLF is broken raise ValueError('lower/upper bounds are not sorted')
""" Return whether the interval is empty
The normalized form of :class:`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 """
""" Return whether the interval consists of a single point
OUTPUT:
Boolean.
EXAMPLES::
sage: I = RealSet(0, 1)[0] sage: I.is_point() False """
""" 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 """ else:
""" 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 """ else:
""" 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 """
""" 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 """
""" 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 """
""" 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 """
""" Intervals are sorted by lower bound, then upper bound
OUTPUT:
`-1`, `0`, or `+1` depending on how the intervals compare.
EXAMPLES::
sage: I1 = RealSet.open_closed(1, 3)[0]; I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5)[0]; I2 (0, 5] sage: I1 > I2 True sage: sorted([I1, I2]) [(0, 5], (1, 3]]
TESTS:
Check if a bug in sorting is fixed (:trac:`17714`)::
sage: RealSet((0, 1),[1, 1],(1, 2)) (0, 2) """
""" Return a string representation
OUTPUT:
String.
EXAMPLES::
sage: RealSet.open_closed(0, 1) (0, 1] sage: RealSet.point(0) {0} """ else: else:
""" Return the closure
OUTPUT:
The closure as a new :class:`RealInterval`
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) """
""" Return the interior
OUTPUT:
The interior as a new :class:`RealInterval`
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) """
""" 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 """ # self is separated and below other return False # self is adjacent and below other # self is separated and above other return False # self is adjacent and above other # They are not separated
""" Return the convex hull of the two intervals
OUTPUT:
The convex hull as a new :class:`RealInterval`.
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] """ else: else:
""" Return the intersection of the two intervals
INPUT:
- ``other`` -- a :class:`RealInterval`
OUTPUT:
The intersection as a new :class:`RealInterval`
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) """ else: else:
""" 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 """
r""" Scale an interval by a scalar on the left or right.
If scaled with a negative number, the interval is flipped.
EXAMPLES::
sage: i = RealSet.open_closed(0,2)[0]; i (0, 2] sage: 2 * i (0, 4] sage: 0 * i {0} sage: (-2) * i [-4, 0) sage: i * (-3) [-6, 0) sage: i * 0 {0} sage: i * 1 (0, 2]
TESTS::
sage: from sage.sets.real_set import InternalRealInterval sage: i = InternalRealInterval(RLF(0), False, RLF(0), False) sage: (0 * i).is_empty() True """ elif not isinstance(left, InternalRealInterval): left = RLF(left) if right.is_empty(): return right lower = left * right._lower lower_closed = right._lower_closed upper = left * right._upper upper_closed = right._upper_closed scalar = left else: return NotImplemented upper, upper_closed)
r""" Scale an interval by a scalar on the left.
If scaled with a negative number, the interval is flipped.
EXAMPLES::
sage: i = RealSet.open_closed(0,2)[0]; i (0, 2] sage: 2 * i (0, 4] sage: 0 * i {0} sage: (-2) * i [-4, 0) """
def __classcall__(cls, *args): """ Normalize the input.
INPUT:
See :class:`RealSet`.
OUTPUT:
A :class:`RealSet`.
EXAMPLES::
sage: R = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3)); R (0, 1] + [2, 3)
::
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) sage: RealSet(x >= -1) [-1, +oo) sage: RealSet(x > oo) {} sage: RealSet(x >= oo) {} sage: RealSet(x <= -oo) {} sage: RealSet(x < oo) (-oo, +oo) sage: RealSet(x > -oo) (-oo, +oo) sage: RealSet(x != oo) (-oo, +oo) sage: RealSet(x <= oo) Traceback (most recent call last): ... ValueError: interval cannot be closed at +oo sage: RealSet(x == oo) Traceback (most recent call last): ... ValueError: interval cannot be closed at +oo sage: RealSet(x >= -oo) Traceback (most recent call last): ... ValueError: interval cannot be closed at -oo
TESTS::
sage: TestSuite(R).run() """ # allow RealSet(0,1) interval constructor """ Internal helper function. """ except AttributeError: pass InternalRealInterval(val, False, oo, False)] else:
and (arg.rhs().is_numeric() or arg.rhs().is_constant()) and arg.rhs().is_real()): and (arg.lhs().is_numeric() or arg.lhs().is_constant()) and arg.lhs().is_real()): op = lt elif op == ge: op = le else: raise ValueError(str(arg) + ' does not determine real interval') else: raise ValueError(str(arg) + ' does not determine real interval')
""" A subset of the real line
INPUT:
Arguments defining a real set. Possibilities are either two real numbers to construct an open set or a list/tuple/iterable of intervals. The individual intervals can be specified by either a :class:`RealInterval`, a tuple of two real numbers (constructing an open interval), or a list of two number (constructing a closed interval).
EXAMPLES::
sage: RealSet(0,1) # open set from two numbers (0, 1) sage: i = RealSet(0,1)[0] sage: RealSet(i) # interval (0, 1) sage: RealSet(i, (3,4)) # tuple of two numbers = open set (0, 1) + (3, 4) sage: RealSet(i, [3,4]) # list of two numbers = closed set (0, 1) + [3, 4] """
""" Intervals are sorted by lower bound, then upper bound
OUTPUT:
`-1`, `0`, or `+1` depending on how the intervals compare.
EXAMPLES::
sage: I1 = RealSet.open_closed(1, 3); I1 (1, 3] sage: I2 = RealSet.open_closed(0, 5); I2 (0, 5] sage: I1 > I2 True sage: sorted([I1, I2]) [(0, 5], (1, 3]] sage: I1 == I1 True """ # note that the interval representation is normalized into a # unique form
""" Iterate over the component intervals is ascending order
OUTPUT:
An iterator over the intervals.
EXAMPLES::
sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3)) sage: i = iter(s) sage: next(i) (0, 1] sage: next(i) [2, 3) """
""" Return the number of connected components
See also :meth:`get_interval`
EXAMPLES::
sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3)) sage: s.n_components() 2 """
""" 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 """ else:
""" Return whether the set is empty
EXAMPLES::
sage: RealSet(0, 1).is_empty() False sage: RealSet(0, 0).is_empty() True """
""" Return the ``i``-th connected component.
Note that the intervals representing the real set are always normalized, see :meth:`normalize`.
INPUT:
- ``i`` -- integer.
OUTPUT:
The $i$-th connected component as a :class:`RealInterval`.
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 """
def normalize(intervals): """ Bring a collection of intervals into canonical form
INPUT:
- ``intervals`` -- a 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),)
sage: RealSet((0, 1), [1, 2], (2, 3)) (0, 3) sage: RealSet((0, 1), (1, 2), (2, 3)) (0, 1) + (1, 2) + (2, 3) sage: RealSet([0, 1], [2, 3]) [0, 1] + [2, 3] sage: RealSet((0, 2), (1, 3)) (0, 3) sage: RealSet(0,0) {} """ # sort by lower bound curr._upper == next._lower and (curr._upper_closed or next._lower_closed)): else:
""" Return a string representation
OUTPUT:
A string representation.
EXAMPLES::
sage: RealSet(0, 1)._repr_() '(0, 1)' """ else: # Switch to u'\u222A' (cup sign) with Python 3
""" Helper to prepare the lower and upper bound
EXAMPLES::
sage: RealSet._prep(1, 0) (0, 1) sage: RealSet._prep(oo) +Infinity """ else: upper = minus_infinity else: return upper, lower else:
def open(lower, upper): """ Construct an open interval
INPUT:
- ``lower``, ``upper`` -- two real numbers or infinity. They will be sorted if necessary.
OUTPUT:
A new :class:`RealSet`.
EXAMPLES::
sage: RealSet.open(1, 0) (0, 1) """
def closed(lower, upper): """ Construct a closed interval
INPUT:
- ``lower``, ``upper`` -- two real numbers or infinity. They will be sorted if necessary.
OUTPUT:
A new :class:`RealSet`.
EXAMPLES::
sage: RealSet.closed(1, 0) [0, 1] """
def point(p): """ Construct an interval containing a single point
INPUT:
- ``p`` -- a real number.
OUTPUT:
A new :class:`RealSet`.
EXAMPLES::
sage: RealSet.open(1, 0) (0, 1) """
def open_closed(lower, upper): """ Construct a half-open interval
INPUT:
- ``lower``, ``upper`` -- two real numbers or infinity. They will be sorted if necessary.
OUTPUT:
A new :class:`RealSet` that is open at the lower bound and closed at the upper bound.
EXAMPLES::
sage: RealSet.open_closed(1, 0) (0, 1] """
def closed_open(lower, upper): """ Construct an half-open interval
INPUT:
- ``lower``, ``upper`` -- two real numbers or infinity. They will be sorted if necessary.
OUTPUT:
A new :class:`RealSet` that is closed at the lower bound and open an the upper bound.
EXAMPLES::
sage: RealSet.closed_open(1, 0) [0, 1) """
def unbounded_below_closed(bound): """ Construct a semi-infinite interval
INPUT:
- ``bound`` -- a real number.
OUTPUT:
A new :class:`RealSet` from minus infinity to the bound (including).
EXAMPLES::
sage: RealSet.unbounded_below_closed(1) (-oo, 1] """
def unbounded_below_open(bound): """ Construct a semi-infinite interval
INPUT:
- ``bound`` -- a real number.
OUTPUT:
A new :class:`RealSet` from minus infinity to the bound (excluding).
EXAMPLES::
sage: RealSet.unbounded_below_open(1) (-oo, 1) """
def unbounded_above_closed(bound): """ Construct a semi-infinite interval
INPUT:
- ``bound`` -- a real number.
OUTPUT:
A new :class:`RealSet` from the bound (including) to plus infinity.
EXAMPLES::
sage: RealSet.unbounded_above_closed(1) [1, +oo) """
def unbounded_above_open(bound): """ Construct a semi-infinite interval
INPUT:
- ``bound`` -- a real number.
OUTPUT:
A new :class:`RealSet` from the bound (excluding) to plus infinity.
EXAMPLES::
sage: RealSet.unbounded_above_open(1) (1, +oo) """
""" Return the union of the two sets
INPUT:
- ``other`` -- a :class:`RealSet` or data that defines one.
OUTPUT:
The set-theoretic union as a new :class:`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) """
""" Return the intersection of the two sets
INPUT:
- ``other`` -- a :class:`RealSet` or data that defines one.
OUTPUT:
The set-theoretic intersection as a new :class:`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: s1 = RealSet((0, 1), (2, 3)); s1 (0, 1) + (2, 3) sage: s2 = RealSet([0, 1], [2, 3]); s2 [0, 1] + [2, 3] sage: s3 = RealSet([1, 2]); s3 [1, 2] sage: s1.intersection(s2) (0, 1) + (2, 3) sage: s1.intersection(s3) {} sage: s2.intersection(s3) {1} + {2} """ # TODO: this can be done in linear time since the intervals are already sorted
""" 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 """ return infinity
""" 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 """ return minus_infinity
""" Return the complement
OUTPUT:
The set-theoretic complement as a new :class:`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) """ return RealSet(minus_infinity, infinity) first._lower, first.lower_open())) RLF(infinity), False)) next._lower, next.lower_open())
""" Return ``self`` with ``other`` subtracted
INPUT:
- ``other`` -- a :class:`RealSet` or data that defines one.
OUTPUT:
The set-theoretic difference of ``self`` with ``other`` removed as a new :class:`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) """
""" 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: 10 in s # syntactic sugar True """
r""" Tests interval inclusion
INPUT:
- ``*args`` -- a :class:`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_included_in(J) True sage: J.is_included_in(K) False """
""" Return a point of the set
OUTPUT:
A real number. ``ValueError`` if the set is empty.
EXAMPLES::
sage: RealSet.open_closed(0, 1).an_element() 1 sage: RealSet(0, 1).an_element() 1/2 sage: RealSet(-oo,+oo).an_element() 0 sage: RealSet(-oo,7).an_element() 6 sage: RealSet(7,+oo).an_element() 8 """ raise ValueError('set is empty') else: return i.lower()
""" Test whether the two sets are disjoint
INPUT:
- ``other`` -- a :class:`RealSet` or data defining one.
OUTPUT:
Boolean.
EXAMPLES::
sage: s1 = RealSet((0, 1), (2, 3)); s1 (0, 1) + (2, 3) sage: s2 = RealSet([1, 2]); s2 [1, 2] sage: s1.is_disjoint_from(s2) True sage: s1.is_disjoint_from([1, 2]) True """
def are_pairwise_disjoint(*real_set_collection): """ Test whether sets are pairwise disjoint
INPUT:
- ``*real_set_collection`` -- a list/tuple/iterable of :class:`RealSet`.
OUTPUT:
Boolean.
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 """
""" Produce an expression which will reproduce this value when evaluated.
TESTS::
sage: sage_input(RealSet()) RealSet() sage: sage_input(RealSet.open(-oo, +oo)) RealSet(-oo, oo) sage: sage_input(RealSet.point(77)) RealSet.point(77) sage: sage_input(RealSet.closed_open(0, +oo)) RealSet.closed_open(0, oo) sage: sage_input(RealSet.open_closed(-oo, 0)) RealSet.open_closed(-oo, 0) sage: sage_input(RealSet.open_closed(-1, 0)) RealSet.open_closed(-1, 0) sage: sage_input(RealSet.closed_open(-1, 0)) RealSet.closed_open(-1, 0) sage: sage_input(RealSet.closed(0, 1)) RealSet.closed(0, 1) sage: sage_input(RealSet.open(0, 1)) RealSet.open(0, 1) sage: sage_input(RealSet.open(0, 1) + RealSet.open(1, 2)) RealSet.open(0, 1) + RealSet.open(1, 2) """
else: else: else: else:
else:
r""" Scale a real set by a scalar on the left or right.
EXAMPLES::
sage: A = RealSet([0, 1/2], (2, infinity)); A [0, 1/2] + (2, +oo) sage: 2 * A [0, 1] + (4, +oo) sage: A * 100 [0, 50] + (200, +oo) sage: 1.5 * A [0.000000000000000, 0.750000000000000] + (3.00000000000000, +oo) sage: (-2) * A (-oo, -4) + [-1, 0] """ elif not isinstance(left, RealSet): return RealSet(*[left*e for e in right]) else: return NotImplemented
r""" Scale a real set by a scalar on the left.
TESTS::
sage: A = RealSet([0, 1/2], RealSet.unbounded_above_closed(2)); A [0, 1/2] + [2, +oo) sage: pi * A [0, 1/2*pi] + [2*pi, +oo) """ |