Repository: sympy/sympy

Issue:
(Integration) regressions?
Hello, I am trying to integrate the following expressions (`f`) which work under SymPy v1.4 but fail on both the master version and 1.7.1.

Behavior in v1.4 is:

```
>>> from sympy import *
>>> x = Symbol('x', real=True, nonzero=True)

>>> f1 = x*(-x**4/asin(5)**4 - x*sinh(x + log(asin(5))) + 5)
>>> integrate(f1, x)
-x**6/(6*asin(5)**4) - x**2*cosh(x + log(asin(5))) + 5*x**2/2 + 2*x*sinh(x + log(asin(5))) - 2*cosh(x + log(asin(5)))

>>> f2 = (x + cosh(cos(4)))/(x*(x + 1/(12*x)))
>>> integrate(f2, x)
log(x**2 + 1/12)/2 + 2*sqrt(3)*cosh(cos(4))*atan(2*sqrt(3)*x)
```

For `f1`: v1.7.1 and master raise the following error: `RecursionError: maximum recursion depth exceeded`
For `f2`: v1.7.1 raises CoercionFailed error (issue possibly related to #21024), while master fails with `RecursionError: maximum recursion depth exceeded`

Discussion:

Patch:
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index 38c423a70f..1c7ef70b6a 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -3767,7 +3767,7 @@ def round(self, n=None):
                     'Expected a number but got %s:' % func_name(x))
         elif x in (S.NaN, S.Infinity, S.NegativeInfinity, S.ComplexInfinity):
             return x
-        if not x.is_extended_real:
+        if x.is_extended_real is False:
             r, i = x.as_real_imag()
             return r.round(n) + S.ImaginaryUnit*i.round(n)
         if not x:


Test patch:
diff --git a/sympy/core/tests/test_arit.py b/sympy/core/tests/test_arit.py
index 51d19548ff..2dc6589f8c 100644
--- a/sympy/core/tests/test_arit.py
+++ b/sympy/core/tests/test_arit.py
@@ -8,6 +8,7 @@
 from sympy.utilities.iterables import cartes
 from sympy.testing.pytest import XFAIL, raises, warns_deprecated_sympy
 from sympy.testing.randtest import verify_numerically
+from sympy.functions.elementary.trigonometric import asin
 
 
 a, c, x, y, z = symbols('a,c,x,y,z')
@@ -2321,3 +2322,8 @@ def test_issue_18507():
 def test_issue_17130():
     e = Add(b, -b, I, -I, evaluate=False)
     assert e.is_zero is None # ideally this would be True
+
+
+def test_issue_21034():
+    e = -I*log((re(asin(5)) + I*im(asin(5)))/sqrt(re(asin(5))**2 + im(asin(5))**2))/pi
+    assert e.round(2)
diff --git a/sympy/integrals/tests/test_integrals.py b/sympy/integrals/tests/test_integrals.py
index d58adb12fc..3de1d543f3 100644
--- a/sympy/integrals/tests/test_integrals.py
+++ b/sympy/integrals/tests/test_integrals.py
@@ -1704,3 +1704,10 @@ def test_issue_4231():
 def test_issue_17841():
     f = diff(1/(x**2+x+I), x)
     assert integrate(f, x) == 1/(x**2 + x + I)
+
+
+def test_issue_21034():
+    x = Symbol('x', real=True, nonzero=True)
+    f = x*(-x**4/asin(5)**4 - x*sinh(x + log(asin(5))) + 5)
+    assert integrate(f, x) == \
+        -x**6/(6*asin(5)**4) - x**2*cosh(x + log(asin(5))) + 5*x**2/2 + 2*x*sinh(x + log(asin(5))) - 2*cosh(x + log(asin(5)))