Repository: sympy/sympy

Issue:
Type Error in Union
`s=Union(ImageSet(Lambda(n, -sqrt(n*pi/2 - 1 + pi/2)), Integers), ImageSet(Lambda(n, sqrt(n*pi/2 - 1 + pi/2)), Integers))`

`s + FiniteSet(0)` raises TypeError.

Can anybody tell me what is the problem?

Discussion:

Patch:
diff --git a/doc/src/modules/index.rst b/doc/src/modules/index.rst
index 6e3fdaa521..3c7f410848 100644
--- a/doc/src/modules/index.rst
+++ b/doc/src/modules/index.rst
@@ -3,8 +3,6 @@
 SymPy Modules Reference
 =======================
 
-.. module:: sympy
-
 Because every feature of SymPy must have a test case, when you are not sure how
 to use something, just look into the ``tests/`` directories, find that feature
 and read the tests for it, that will tell you everything you need to know.
diff --git a/doc/src/modules/matrices/immutablematrices.rst b/doc/src/modules/matrices/immutablematrices.rst
index 380f3999d9..b94c6147ad 100644
--- a/doc/src/modules/matrices/immutablematrices.rst
+++ b/doc/src/modules/matrices/immutablematrices.rst
@@ -1,7 +1,7 @@
 Immutable Matrices
 ==================
 
-.. currentmodule:: sympy
+.. module:: sympy
 
 The standard :obj:`~.Matrix` class in SymPy is mutable. This is important for
 performance reasons but means that standard matrices cannot interact well with
diff --git a/sympy/sets/sets.py b/sympy/sets/sets.py
index 1e3c9d292f..9350f656e5 100644
--- a/sympy/sets/sets.py
+++ b/sympy/sets/sets.py
@@ -80,6 +80,7 @@ def _infimum_key(expr):
         try:
             infimum = expr.inf
             assert infimum.is_comparable
+            infimum = infimum.evalf()  # issue #18505
         except (NotImplementedError,
                 AttributeError, AssertionError, ValueError):
             infimum = S.Infinity
diff --git a/sympy/simplify/radsimp.py b/sympy/simplify/radsimp.py
index b013f6b926..9457921008 100644
--- a/sympy/simplify/radsimp.py
+++ b/sympy/simplify/radsimp.py
@@ -178,7 +178,7 @@ def collect(expr, syms, func=None, evaluate=None, exact=False, distribute_order_
         if not isinstance(rv, dict):
             return rv.xreplace(urep)
         else:
-            return {urep.get(k, k): v.xreplace(urep) for k, v in rv.items()}
+            return {urep.get(k, k): v for k, v in rv.items()}
 
     if evaluate is None:
         evaluate = global_parameters.evaluate


Test patch:
diff --git a/sympy/sets/tests/test_sets.py b/sympy/sets/tests/test_sets.py
index 61c058c05e..7f3ea64b62 100644
--- a/sympy/sets/tests/test_sets.py
+++ b/sympy/sets/tests/test_sets.py
@@ -1437,6 +1437,11 @@ def test_issue_11174():
     assert Intersection(FiniteSet(x), S.Reals) == soln
 
 
+def test_issue_18505():
+    assert ImageSet(Lambda(n, sqrt(pi*n/2 - 1 + pi/2)), S.Integers).contains(0) == \
+            Contains(0, ImageSet(Lambda(n, sqrt(pi*n/2 - 1 + pi/2)), S.Integers))
+
+
 def test_finite_set_intersection():
     # The following should not produce recursion errors
     # Note: some of these are not completely correct. See
diff --git a/sympy/simplify/tests/test_radsimp.py b/sympy/simplify/tests/test_radsimp.py
index 769ddcfaff..e56fd14f82 100644
--- a/sympy/simplify/tests/test_radsimp.py
+++ b/sympy/simplify/tests/test_radsimp.py
@@ -223,12 +223,6 @@ def test_collect_5():
                    [x, y]) == 1 + y + x*(1 + 2*y) + x**2 + y**2
 
 
-def test_collect_pr19431():
-    """Unevaluated collect with respect to a product"""
-    a = symbols('a')
-    assert collect(a**2*(a**2 + 1), a**2, evaluate=False)[a**2] == (a**2 + 1)
-
-
 def test_collect_D():
     D = Derivative
     f = Function('f')