Repository: sympy/sympy

Issue:
Infinte recursion error  when using maximum 
```
>>> sympy.__version__
'1.8.dev'
````

```
>>> from sympy import *
>>> from sympy.abc import x,y
>>> f = x/sqrt(x**2+1)
>>> maximum(f,x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\calculus\util.py", line 795, in maximum
    return function_range(f, symbol, domain).sup
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\calculus\util.py", line 194, in function_range
    solution = solveset(f.diff(symbol), symbol, interval)
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 2117, in solveset
    rv = solveset(f.xreplace({symbol: x}), x, domain)
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 2141, in solveset
    return _solveset(f, symbol, domain, _check=True)
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 1083, in _solveset
    result += _solve_radical(equation,
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 858, in _solve_radical
    result = solveset_solver(eq, symbol) - \
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 1013, in <lambda>
    solver = lambda f, x, domain=domain: _solveset(f, x, domain)
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 1083, in _solveset
    result += _solve_radical(equation,
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 858, in _solve_radical
    result = solveset_solver(eq, symbol) - \
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 1013, in <lambda>
    solver = lambda f, x, domain=domain: _solveset(f, x, domain)
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 1083, in _solveset
    result += _solve_radical(equation,
  File "C:\Users\2acha\Desktop\NewFinal\sympy\sympy\solvers\solveset.py", line 858, in _solve_radical
    result = solveset_solver(eq, symbol) - \
```


EDIT: I have found this to more of a solveset issue than an issue pertaining to the calculus module. 
The reason why this function goes into infintire recursion  is because of this equation: 
```
eq = x/sqrt(x**2+1)
dif = eq.diff(x)
solveset(dif,x) # solveset cannot solve this. It  calls unrad, which returns none, 

```

This expression keeps on going in loops between solveset  ->unrad -> solveset and so forth.

Discussion:

Patch:
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 65e1ef0d2e..06d30cbdea 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -3296,7 +3296,7 @@ def _take(d, take_int_pow):
 
     eq = _mexpand(eq, recursive=True)
     if eq.is_number:
-        return
+        return eq, []
 
     syms = set(syms) or eq.free_symbols
     poly = eq.as_poly()


Test patch:
diff --git a/sympy/calculus/tests/test_util.py b/sympy/calculus/tests/test_util.py
index fdb261dea0..510fb12741 100644
--- a/sympy/calculus/tests/test_util.py
+++ b/sympy/calculus/tests/test_util.py
@@ -42,6 +42,7 @@ def test_function_range():
     assert function_range(cos(x), x, Interval(-oo, -4)
         ) == Interval(-1, 1)
     assert function_range(cos(x), x, S.EmptySet) == S.EmptySet
+    assert function_range(x/sqrt(x**2+1), x, S.Reals) == Interval.open(-1,1)
     raises(NotImplementedError, lambda : function_range(
         exp(x)*(sin(x) - cos(x))/2 - x, x, S.Reals))
     raises(NotImplementedError, lambda : function_range(
@@ -258,6 +259,7 @@ def test_maximum():
     assert maximum(abs(a**3 + a), a, Interval(0, 2)) == 10
     assert maximum(abs(60*a**3 + 24*a), a, Interval(0, 2)) == 528
     assert maximum(abs(12*a*(5*a**2 + 2)), a, Interval(0, 2)) == 528
+    assert maximum(x/sqrt(x**2+1), x, S.Reals) == 1
 
     raises(ValueError, lambda : maximum(sin(x), x, S.EmptySet))
     raises(ValueError, lambda : maximum(log(cos(x)), x, S.EmptySet))
@@ -286,6 +288,7 @@ def test_minimum():
         ) is S.NegativeOne
     assert minimum(cos(x)-sin(x), x, S.Reals) == -sqrt(2)
     assert minimum(y, x, S.Reals) == y
+    assert minimum(x/sqrt(x**2+1), x, S.Reals) == -1
 
     raises(ValueError, lambda : minimum(sin(x), x, S.EmptySet))
     raises(ValueError, lambda : minimum(log(cos(x)), x, S.EmptySet))
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 7545daffcc..6fb2588eb9 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -315,6 +315,13 @@ def test_issue_7190():
     assert solve(log(x-3) + log(x+3), x) == [sqrt(10)]
 
 
+def test_issue_21004():
+    x = symbols('x')
+    f = x/sqrt(x**2+1)
+    f_diff = f.diff(x)
+    assert solve(f_diff, x) == []
+
+
 def test_linear_system():
     x, y, z, t, n = symbols('x, y, z, t, n')