Skip to content

Commit

Permalink
Merge pull request #1308 from skirpichev/1288-remove-UniversalSet
Browse files Browse the repository at this point in the history
sets: removed S.UniversalSet
  • Loading branch information
skirpichev committed Mar 21, 2023
2 parents d4c7e98 + 2fe5184 commit 1d632ce
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 118 deletions.
13 changes: 2 additions & 11 deletions diofant/logic/boolalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,8 @@ def __hash__(self):
return hash(True)

def as_set(self):
"""
Rewrite logic operators and relationals in terms of real sets.
Examples
========
>>> true.as_set()
UniversalSet()
"""
return S.UniversalSet
"""Rewrite logic operators and relationals in terms of real sets."""
return S.ExtendedReals


class BooleanFalse(BooleanAtom, metaclass=Singleton):
Expand Down
68 changes: 0 additions & 68 deletions diofant/sets/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Set(Basic):
is_Union = False
is_Intersection: bool | None = None
is_EmptySet: bool | None = None
is_UniversalSet: bool | None = None
is_Complement: bool | None = None
is_SymmetricDifference: bool | None = None

Expand Down Expand Up @@ -153,9 +152,6 @@ def complement(self, universe):
>>> Interval(0, 1).complement(S.Reals)
(-oo, 0) U (1, oo)
>>> Interval(0, 1).complement(S.UniversalSet)
UniversalSet() \ [0, 1]
"""
return Complement(universe, self)

Expand Down Expand Up @@ -908,8 +904,6 @@ def _union(self, other):
See Set._union for docstring
"""
if other.is_UniversalSet:
return S.UniversalSet
if other.is_Interval and self._is_comparable(other):
from ..functions import Max, Min

Expand Down Expand Up @@ -1356,10 +1350,6 @@ def flatten(arg):
return sum(map(flatten, arg), [])
raise TypeError('Input must be Sets or iterables of Sets')
args = flatten(args)

if len(args) == 0:
return S.UniversalSet

args = list(ordered(args, Set._infimum_key))

# Reduce sets using known rules
Expand Down Expand Up @@ -1522,11 +1512,6 @@ class EmptySet(Set, metaclass=Singleton):
>>> Interval(1, 2).intersection(S.EmptySet)
EmptySet()
See Also
========
UniversalSet
References
==========
Expand Down Expand Up @@ -1573,59 +1558,6 @@ def _symmetric_difference(self, other):
return other


class UniversalSet(Set, metaclass=Singleton):
"""
Represents the set of all things.
The universal set is available as a singleton as S.UniversalSet
Examples
========
>>> S.UniversalSet
UniversalSet()
>>> Interval(1, 2).intersection(S.UniversalSet)
[1, 2]
See Also
========
EmptySet
References
==========
* https://en.wikipedia.org/wiki/Universal_set
"""

is_UniversalSet = True

def _intersection(self, other):
return other

def _complement(self, other):
return S.EmptySet

def _symmetric_difference(self, other):
return other

@property
def measure(self):
return oo

def _contains(self, other):
return true

def as_relational(self, symbol):
return true

@property
def boundary(self):
return EmptySet()


class FiniteSet(Set, EvalfMixin):
"""
Represents a set that has a finite number of elements.
Expand Down
6 changes: 1 addition & 5 deletions diofant/tests/core/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
from diofant.printing.codeprinter import Assignment
from diofant.sets.fancysets import (ExtendedReals, Integers, Naturals,
Naturals0, Rationals, Reals)
from diofant.sets.sets import EmptySet, UniversalSet
from diofant.sets.sets import EmptySet
from diofant.simplify.hyperexpand import G_Function, Hyper_Function
from diofant.tensor import ImmutableDenseNDimArray, ImmutableSparseNDimArray
from diofant.tensor.tensor import (TensAdd, TensorHead, TensorIndex,
Expand Down Expand Up @@ -441,10 +441,6 @@ def test_diofant__sets__sets__EmptySet():
assert _test_args(EmptySet())


def test_diofant__sets__sets__UniversalSet():
assert _test_args(UniversalSet())


def test_diofant__sets__sets__FiniteSet():
assert _test_args(FiniteSet(x, y, z))

Expand Down
2 changes: 1 addition & 1 deletion diofant/tests/logic/test_boolalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def test_bool_as_set():
assert ((x <= 2) & (x >= -2)).as_set() == Interval(-2, 2)
assert ((x >= 2) | (x <= -2)).as_set() == (Interval(-oo, -2) + Interval(2, oo, False))
assert Not(x > 2, evaluate=False).as_set() == Interval(-oo, 2, True)
assert true.as_set() == S.UniversalSet
assert true.as_set() == S.ExtendedReals
assert false.as_set() == EmptySet()


Expand Down
36 changes: 6 additions & 30 deletions diofant/tests/sets/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def test_Complement():
assert -1 in Complement(S.Reals, S.Naturals, evaluate=False)
assert 1 not in Complement(S.Reals, S.Naturals, evaluate=False)

assert Complement(S.Integers, S.UniversalSet) == EmptySet()
assert S.UniversalSet.complement(S.Integers) == EmptySet()
assert Complement(S.Integers, S.Reals) == EmptySet()
assert S.Reals.complement(S.Integers) == EmptySet()

assert (0 not in S.Reals.intersection(S.Integers - FiniteSet(0)))

Expand All @@ -188,10 +188,8 @@ def test_complement():
assert Interval(0, 1, True, True).complement(S.Reals) == \
Union(Interval(-oo, 0, True, False), Interval(1, oo, False, True))

assert S.UniversalSet.complement(S.EmptySet) == S.EmptySet
assert S.UniversalSet.complement(S.Reals) == S.EmptySet
assert S.UniversalSet.complement(S.UniversalSet) == S.EmptySet

assert S.Reals.complement(S.EmptySet) == S.EmptySet
assert S.Reals.complement(S.Reals) == S.EmptySet
assert S.EmptySet.complement(S.Reals) == S.Reals

assert Union(Interval(0, 1), Interval(2, 3)).complement(S.Reals) == \
Expand Down Expand Up @@ -229,8 +227,6 @@ def test_complement():
def test_intersection():
pytest.raises(TypeError, lambda: Intersection(1))

assert Intersection() == S.UniversalSet

assert Interval(0, 2).intersection(Interval(1, 2)) == Interval(1, 2)
assert Interval(0, 2).intersection(Interval(1, 2, True)) == \
Interval(1, 2, True)
Expand Down Expand Up @@ -589,7 +585,7 @@ def test_Intersection_as_relational():

def test_EmptySet():
assert S.EmptySet.as_relational(x) is false
assert S.EmptySet.intersection(S.UniversalSet) == S.EmptySet
assert S.EmptySet.intersection(S.Reals) == S.EmptySet
assert S.EmptySet.boundary == S.EmptySet
assert Interval(0, 1).symmetric_difference(S.EmptySet) == Interval(0, 1)
assert Interval(1, 2).intersection(S.EmptySet) == S.EmptySet
Expand Down Expand Up @@ -741,19 +737,6 @@ def test_supinf():
assert FiniteSet('Ham', 'Eggs').sup == Max('Ham', 'Eggs')


def test_universalset():
U = S.UniversalSet
assert U.as_relational(x) is true
assert U.union(Interval(2, 4)) == U

assert U.intersection(Interval(2, 4)) == Interval(2, 4)
assert U.measure == oo
assert U.boundary == S.EmptySet
assert U.contains(0) is true
assert Interval(0, 1).symmetric_difference(U) == Interval(0, 1)
assert U.complement(U) == S.EmptySet


def test_Union_of_ProductSets_shares():
line = Interval(0, 2)
points = FiniteSet(0, 1, 2)
Expand Down Expand Up @@ -1013,25 +996,18 @@ def test_sympyissue_9808():
Complement(FiniteSet(1), FiniteSet(y), evaluate=False))


def test_sympyissue_9447():
def test_sympyissue_10305():
a = Interval(0, 1) + Interval(2, 3)
assert (Complement(S.UniversalSet, a) ==
Complement(S.UniversalSet,
Union(Interval(0, 1), Interval(2, 3)), evaluate=False))
# issue sympy/sympy#10305:
assert (Complement(S.Naturals, a) ==
Complement(S.Naturals,
Union(Interval(0, 1), Interval(2, 3)), evaluate=False))


def test_sympyissue_2799():
U = S.UniversalSet
a = Symbol('a', real=True)
inf_interval = Interval(a, oo)
R = S.Reals

assert U + inf_interval == inf_interval + U
assert U + R == R + U
assert R + inf_interval == inf_interval + R


Expand Down
3 changes: 0 additions & 3 deletions docs/modules/sets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ Singleton Sets
.. autoclass:: EmptySet
:members:

.. autoclass:: UniversalSet
:members:

Special Sets
^^^^^^^^^^^^

Expand Down

0 comments on commit 1d632ce

Please sign in to comment.