Repository: sympy/sympy

Issue:
inequalities involving zoo should raise TypeError
Since `I > 0` raises a TypeError, `zoo > 0` should probably do the same. Actually, anything even *containing* `zoo` should probably be disallowed since such an expression will become `zoo` (e.g. `zoo*1`) or `NaN` (e.g. `zoo*0`).  See #7834 for an example of how to make the changes.

Discussion:
smichr: Maybe `if me.is_complex and me.is_real is False:` could just be changed to `if me.is_complex and me.is_real is False or me is S.ComplexInfinity:`.
aktech: Yes, that would be better.
Thanks.
aktech: This Example is failing:
in [sympy/integrals/transforms.py](https://github.com/sympy/sympy/blob/master/sympy/integrals/transforms.py#L881)
```python
>>> from sympy.integrals.transforms import _simplifyconds as simp
>>> from sympy.abc import x
>>> from sympy import sympify as S
>>> simp(abs(x**2) < 1, x, 0)
Abs(x**2) < 1
```
I am not sure about the cause.
smichr: > I am not sure about the cause.

```
File "sympy\integrals\transforms.py", line 919, in bigger
  return bigger(1/ex2, 1/ex1)
```

When ex* is 0 this test is going to fail because a zoo will be generated.
aktech: @smichr  Thanks, for reply.
I should probably Except that error, using try - except.
smichr: The following passes tests, too. What do you think about this:

```diff
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index f3a733f..42c9960 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -235,7 +235,8 @@ def __ge__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s >= %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -252,7 +253,8 @@ def __le__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s <= %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -269,7 +271,8 @@ def __gt__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s > %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -286,7 +289,8 @@ def __lt__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s < %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
```
aktech: > The following passes tests, too.

Have you tried `./bin/doctest integrals` ?
(The Failed case is in Example docs). It Fails on my system.

```
__________________ sympy.integrals.transforms._simplifyconds ___________________
File "sympy/integrals/transforms.py", line 881, in sympy.integrals.transforms._simplifyconds
Failed example:
    simp(abs(x**2) < 1, x, 0)
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest sympy.integrals.transforms._simplifyconds[5]>", line 1, in <module>
        simp(abs(x**2) < 1, x, 0)
      File "sympy/integrals/transforms.py", line 948, in _simplifyconds
        expr = repl(expr, StrictLessThan, replie)
      File "sympy/integrals/transforms.py", line 947, in repl
        return ex.replace(*args)
      File "sympy/core/basic.py", line 1351, in replace
        rv = bottom_up(self, rec_replace, atoms=True)
      File "sympy/simplify/simplify.py", line 4083, in bottom_up
        rv = F(rv)
      File "sympy/core/basic.py", line 1336, in rec_replace
        new = _value(expr, result)
      File "sympy/core/basic.py", line 1280, in <lambda>
        _value = lambda expr, result: value(*expr.args)
      File "sympy/integrals/transforms.py", line 933, in replie
        r = bigger(x, y)
      File "sympy/integrals/transforms.py", line 919, in bigger
        return bigger(1/ex2, 1/ex1)
      File "sympy/integrals/transforms.py", line 925, in bigger
        if n < 0 and (abs(ex1) >= abs(a)**n) == True:
      File "sympy/core/numbers.py", line 1806, in __ge__
        return Rational.__ge__(self, other)
      File "sympy/core/numbers.py", line 1457, in __ge__
        return Expr.__ge__(expr, other)
      File "sympy/core/expr.py", line 240, in __ge__
        raise TypeError("Invalid comparison of complex %s" % me)
    TypeError: Invalid comparison of complex zoo
```

Probably you have tried `sympy/integrals/tests/test_transforms.py` .

smichr: > Have you tried

the diff I gave was on top of your current branch so the catching of the TypeError was not shown in the diff

Patch:
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index f3a733fa63..42c9960175 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -235,7 +235,8 @@ def __ge__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s >= %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -252,7 +253,8 @@ def __le__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s <= %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -269,7 +271,8 @@ def __gt__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s > %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
@@ -286,7 +289,8 @@ def __lt__(self, other):
         except SympifyError:
             raise TypeError("Invalid comparison %s < %s" % (self, other))
         for me in (self, other):
-            if me.is_complex and me.is_real is False:
+            if (me.is_complex and me.is_real is False) or \
+                    me.has(S.ComplexInfinity):
                 raise TypeError("Invalid comparison of complex %s" % me)
             if me is S.NaN:
                 raise TypeError("Invalid NaN comparison")
diff --git a/sympy/integrals/transforms.py b/sympy/integrals/transforms.py
index 9a949884c6..188d13d2b9 100644
--- a/sympy/integrals/transforms.py
+++ b/sympy/integrals/transforms.py
@@ -916,7 +916,10 @@ def bigger(ex1, ex2):
         if ex2.func is Abs:
             ex2 = ex2.args[0]
         if ex1.has(s):
-            return bigger(1/ex2, 1/ex1)
+            try:
+                return bigger(1/ex2, 1/ex1)
+            except TypeError:
+                return None
         n = power(ex2)
         if n is None:
             return None
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index a8c905c383..e72a25676e 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -89,7 +89,7 @@
     # Brackets
     'norm': lambda s: r'\left\lVert{'+s+r'}\right\rVert',
     'avg': lambda s: r'\left\langle{'+s+r'}\right\rangle',
-    'abs': lambda s: r'\left|{'+s+r'}\right|',
+    'abs': lambda s: r'\left\|{'+s+r'}\right\|',
     'mag': lambda s: r'\left\lvert{'+s+r'}\right\rvert',
 }
 
@@ -753,7 +753,7 @@ def _print_ceiling(self, expr, exp=None):
             return tex
 
     def _print_Abs(self, expr, exp=None):
-        tex = r"\left|{%s}\right|" % self._print(expr.args[0])
+        tex = r"\left\|{%s}\right\|" % self._print(expr.args[0])
 
         if exp is not None:
             return r"%s^{%s}" % (tex, exp)


Test patch:
diff --git a/sympy/core/tests/test_relational.py b/sympy/core/tests/test_relational.py
index 21fc0ef58c..f7024122a0 100644
--- a/sympy/core/tests/test_relational.py
+++ b/sympy/core/tests/test_relational.py
@@ -455,10 +455,17 @@ def test_nan_inequality_raise_errors():
 def test_nan_complex_inequalities():
     # Comparisons of NaN with non-real raise errors, we're not too
     # fussy whether its the NaN error or complex error.
-    for r in (I, Symbol('z', imaginary=True)):
+    for r in (I, zoo, Symbol('z', imaginary=True)):
         assert_all_ineq_raise_TypeError(r, nan)
 
 
+def test_complex_infinity_inequalities():
+    raises(TypeError, lambda: zoo > 0)
+    raises(TypeError, lambda: zoo >= 0)
+    raises(TypeError, lambda: zoo < 0)
+    raises(TypeError, lambda: zoo <= 0)
+
+
 def test_inequalities_symbol_name_same():
     """Using the operator and functional forms should give same results."""
     # We test all combinations from a set
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index b1b031df5a..081d9de92e 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -231,7 +231,7 @@ def test_latex_functions():
     assert latex(Min(x, y)**2) == r"\min\left(x, y\right)^{2}"
     assert latex(Max(x, 2, x**3)) == r"\max\left(2, x, x^{3}\right)"
     assert latex(Max(x, y)**2) == r"\max\left(x, y\right)^{2}"
-    assert latex(Abs(x)) == r"\left|{x}\right|"
+    assert latex(Abs(x)) == r"\left\|{x}\right\|"
     assert latex(re(x)) == r"\Re{x}"
     assert latex(re(x + y)) == r"\Re{x} + \Re{y}"
     assert latex(im(x)) == r"\Im{x}"
@@ -1177,7 +1177,7 @@ def test_modifiers():
     assert latex(symbols("xDot")) == r"\dot{x}"
     assert latex(symbols("xBar")) == r"\bar{x}"
     assert latex(symbols("xVec")) == r"\vec{x}"
-    assert latex(symbols("xAbs")) == r"\left|{x}\right|"
+    assert latex(symbols("xAbs")) == r"\left\|{x}\right\|"
     assert latex(symbols("xMag")) == r"\left\lvert{x}\right\rvert"
     assert latex(symbols("xPrM")) == r"{x}'"
     assert latex(symbols("xBM")) == r"\boldsymbol{x}"
@@ -1207,7 +1207,7 @@ def test_modifiers():
     assert latex(symbols("xDotVec")) == r"\vec{\dot{x}}"
     assert latex(symbols("xHATNorm")) == r"\left\lVert{\hat{x}}\right\rVert"
     # Check a couple big, ugly combinations
-    assert latex(symbols('xMathringBm_yCheckPRM__zbreveAbs')) == r"\boldsymbol{\mathring{x}}^{\left|{\breve{z}}\right|}_{{\check{y}}'}"
+    assert latex(symbols('xMathringBm_yCheckPRM__zbreveAbs')) == r"\boldsymbol{\mathring{x}}^{\left\|{\breve{z}}\right\|}_{{\check{y}}'}"
     assert latex(symbols('alphadothat_nVECDOT__tTildePrime')) == r"\hat{\dot{\alpha}}^{{\tilde{t}}'}_{\dot{\vec{n}}}"