Repository: sympy/sympy

Issue:
maximum recursion depth exceeded from solve(log(y) - log(0.1222*x**0.8628), x)
```
In [1]: solve(log(y) - log(0.1222*x**0.8628), x)
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-1-61b053bc3d22> in <module>()
----> 1 solve(log(y) - log(0.1222*x**0.8628), x)

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/solvers/solvers.py in solve(f, *symbols, **flags)
   1033             if fi.has(Float):
   1034                 floats = True
-> 1035                 f[i] = nsimplify(fi, rational=True)
   1036
   1037     # Any embedded piecewise functions need to be brought out to the

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/simplify/simplify.py in nsimplify(expr, constants, tolerance, full, rational)
   1130     """
   1131     try:
-> 1132         return sympify(as_int(expr))
   1133     except (TypeError, ValueError):
   1134         pass

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/compatibility.py in as_int(n)
    400     """
    401     try:
--> 402         result = int(n)
    403         if result != n:
    404             raise TypeError

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/expr.py in __int__(self)
    193         # places) we need to test whether we are off by one.
    194         from sympy import Dummy
--> 195         r = self.round(2)
    196         if not r.is_Number:
    197             raise TypeError("can't convert complex to int")

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/expr.py in round(self, p)
   3149         if not x.is_real:
   3150             i, r = x.as_real_imag()
-> 3151             return i.round(p) + S.ImaginaryUnit*r.round(p)
   3152         if not x:
   3153             return x

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/expr.py in round(self, p)
   3149         if not x.is_real:
   3150             i, r = x.as_real_imag()
-> 3151             return i.round(p) + S.ImaginaryUnit*r.round(p)
   3152         if not x:
   3153             return x

... last 2 frames repeated, from the frame below ...

/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/expr.py in round(self, p)
   3149         if not x.is_real:
   3150             i, r = x.as_real_imag()
-> 3151             return i.round(p) + S.ImaginaryUnit*r.round(p)
   3152         if not x:
   3153             return x

RecursionError: maximum recursion depth exceeded
```

It used to work in 0.7.6:

```
In [1]: solve(log(y) - log(0.1222*x**0.8628), x)
Out[1]:
⎡                  2500⎤
⎢                  ────⎥
⎢                  2157⎥
⎣11.4314187062073⋅y    ⎦
```

I bisected it to commit 26f77778e1e93388b1d092038bcb6ccd056bd7b4
Author: Chris Smith <smichr@gmail.com>
Date:   Tue Dec 29 20:39:39 2015 -0600

    check that round arg evaluates to a literal number

@smichr 

Discussion:

Patch:
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index eab55068b8..3c81fb4ed1 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -192,6 +192,8 @@ def __int__(self):
         # (regardless of how much extra work we do to calculate extra decimal
         # places) we need to test whether we are off by one.
         from sympy import Dummy
+        if not self.is_number:
+            raise TypeError("can't convert symbols to int")
         r = self.round(2)
         if not r.is_Number:
             raise TypeError("can't convert complex to int")
@@ -3139,7 +3141,9 @@ def round(self, p=0):
         """
         from sympy import Float
         x = self
-        if x.is_number and not x.is_Atom:
+        if not x.is_number:
+            raise TypeError("can't round symbolic expression")
+        if not x.is_Atom:
             xn = x.n(2)
             if not pure_complex(xn, or_real=True):
                 raise TypeError('Expected a number but got %s:' %
diff --git a/sympy/functions/combinatorial/numbers.py b/sympy/functions/combinatorial/numbers.py
index e9f130005d..75a2ae6bca 100644
--- a/sympy/functions/combinatorial/numbers.py
+++ b/sympy/functions/combinatorial/numbers.py
@@ -20,7 +20,6 @@
 from sympy.functions.elementary.integers import floor
 from sympy.functions.elementary.trigonometric import sin, cos, cot
 from sympy.functions.elementary.miscellaneous import sqrt
-from sympy.utilities.memoization import recurrence_memo
 
 from mpmath import bernfrac, workprec
 from mpmath.libmp import ifib as _ifib
@@ -32,6 +31,7 @@ def _product(a, b):
         p *= k
     return p
 
+from sympy.utilities.memoization import recurrence_memo
 
 
 # Dummy symbol used for computing polynomial sequences
diff --git a/sympy/matrices/matrices.py b/sympy/matrices/matrices.py
index 95e44ee1fc..00ab86f2e3 100644
--- a/sympy/matrices/matrices.py
+++ b/sympy/matrices/matrices.py
@@ -3220,8 +3220,7 @@ def condition_number(self):
 
         singular_values
         """
-        if not self:
-            return S.Zero
+
         singularvalues = self.singular_values()
         return Max(*singularvalues) / Min(*singularvalues)
 


Test patch:
diff --git a/sympy/core/tests/test_expr.py b/sympy/core/tests/test_expr.py
index 541e454167..117d75d8c6 100644
--- a/sympy/core/tests/test_expr.py
+++ b/sympy/core/tests/test_expr.py
@@ -442,6 +442,7 @@ def test_is_algebraic_expr():
     assert (cos(y)/sqrt(x)).is_algebraic_expr(y) is False
     assert (cos(y)/sqrt(x)).is_algebraic_expr(x, y) is False
 
+
 def test_SAGE1():
     #see https://github.com/sympy/sympy/issues/3346
     class MyInt:
@@ -1426,10 +1427,12 @@ def test_issue_4199():
     assert a._eval_interval(x, -oo, oo) == -y
     assert a._eval_interval(x, oo, -oo) == y
 
+
 def test_eval_interval_zoo():
     # Test that limit is used when zoo is returned
     assert Si(1/x)._eval_interval(x, 0, 1) == -pi/2 + Si(1)
 
+
 def test_primitive():
     assert (3*(x + 1)**2).primitive() == (3, (x + 1)**2)
     assert (6*x + 2).primitive() == (2, 3*x + 1)
@@ -1657,6 +1660,7 @@ def test_round():
     assert S.NegativeInfinity.round() == S.NegativeInfinity
     assert S.ComplexInfinity.round() == S.ComplexInfinity
 
+
 def test_round_exception_nostr():
     # Don't use the string form of the expression in the round exception, as
     # it's too slow
@@ -1669,6 +1673,7 @@ def test_round_exception_nostr():
         # Did not raise
         raise AssertionError("Did not raise")
 
+
 def test_extract_branch_factor():
     assert exp_polar(2.0*I*pi).extract_branch_factor() == (1, 1)
 
@@ -1706,3 +1711,9 @@ def test_issue_7426():
 def test_issue_10161():
     x = symbols('x', real=True)
     assert x*abs(x)*abs(x) == x**3
+
+
+def test_issue_10755():
+    x = symbols('x')
+    raises(TypeError, lambda: int(log(x)))
+    raises(TypeError, lambda: log(x).round(2))
diff --git a/sympy/matrices/tests/test_matrices.py b/sympy/matrices/tests/test_matrices.py
index 3f741dd050..60dae527a7 100644
--- a/sympy/matrices/tests/test_matrices.py
+++ b/sympy/matrices/tests/test_matrices.py
@@ -2047,9 +2047,6 @@ def test_condition_number():
     assert all(Float(1.).epsilon_eq(Mc.subs(x, val).evalf()) for val in
         [Rational(1, 5), Rational(1, 2), Rational(1, 10), pi/2, pi, 7*pi/4 ])
 
-    #issue 10782
-    assert Matrix([]).condition_number() == 0
-
 
 def test_equality():
     A = Matrix(((1, 2, 3), (4, 5, 6), (7, 8, 9)))