Repository: sympy/sympy

Issue:
TypeError:  Incompatible use of binary symbol `A` as a real variable in `A >= oo`
I'm trying to solve a differential equation.  Code as follows:

```
from sympy import Function, dsolve, Eq, Derivative, symbols
from sympy.abc import t, sigma

A, B, C, D = symbols('A,B,C,D')
f = Function('f')(t)
expr = Eq(Derivative(f, t) + 2 * (A/(B+t)) * f, sigma**2/2*(A/(B+t))**2)

dsolve(expr)
```

The program failed while I have checked with Wolfram Alpha that this equation is solvable.  Error as follows:
```
Traceback (most recent call last):
  File "C:\Users\Ping\PycharmProjects\pythonProject\spline.py", line 8, in <module>
    dsolve(expr)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\ode\ode.py", line 640, in dsolve
    return _helper_simplify(eq, hint, hints, simplify, ics=ics)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\ode\ode.py", line 690, in _helper_simplify
    rv = _remove_redundant_solutions(eq, rv, order, func.args[0])
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\ode\ode.py", line 2627, in _remove_redundant_solutions
    if is_special_case_of(soln1, soln2):
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\ode\ode.py", line 2622, in is_special_case_of
    return _is_special_case_of(soln1, soln2, eq, order, var)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\ode\ode.py", line 2693, in _is_special_case_of
    constant_solns = solve(eqns, constants2)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\solvers\solvers.py", line 924, in solve
    fi = fi.rewrite(Add, evaluate=False)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1894, in rewrite
    return self._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in _rewrite
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in <listcomp>
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in _rewrite
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in <listcomp>
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in _rewrite
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in <listcomp>
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in _rewrite
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in <listcomp>
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in _rewrite
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1899, in <listcomp>
    args = [a._rewrite(pattern, rule, method, **hints)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\basic.py", line 1913, in _rewrite
    return self.func(*args)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\core\operations.py", line 512, in __new__
    _args = frozenset(cls._new_args_filter(args))
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\logic\boolalg.py", line 766, in _new_args_filter
    args = BooleanFunction.binary_check_and_simplify(*args)
  File "C:\Users\Ping\mambaforge\lib\site-packages\sympy\logic\boolalg.py", line 507, in binary_check_and_simplify
    raise TypeError(filldedent('''
TypeError: 
Incompatible use of binary symbol `A` as a real variable in `A <= -oo`
```



Discussion:

Patch:
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 9c0d2dfd24..fb501e07ec 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -271,7 +271,7 @@ def checksol(f, symbol, sol=None, **flags):
             if not f.is_Boolean:
                 return
         else:
-            f = f.rewrite(Add, evaluate=False)
+            f = f.rewrite(Add, evaluate=False, deep=False)
 
     if isinstance(f, BooleanAtom):
         return bool(f)
@@ -945,7 +945,7 @@ def _sympified_list(w):
                             is True or False.
                         '''))
                 else:
-                    fi = fi.rewrite(Add, evaluate=False)
+                    fi = fi.rewrite(Add, evaluate=False, deep=False)
             f[i] = fi
 
         # *** dispatch and handle as a system of relationals


Test patch:
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 235277380c..ccf1aa3074 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -376,6 +376,14 @@ def test_issue_21004():
     assert solve(f_diff, x) == []
 
 
+def test_issue_24650():
+    x = symbols('x')
+    r = solve(Eq(Piecewise((x, Eq(x, 0) | (x > 1))), 0))
+    assert r == [0]
+    r = checksol(Eq(Piecewise((x, Eq(x, 0) | (x > 1))), 0), x, sol=0)
+    assert r is True
+
+
 def test_linear_system():
     x, y, z, t, n = symbols('x, y, z, t, n')