Repository: sympy/sympy (python)

Issue:
Regression in ask from sympy 1.13.3 to 1.14.0

```python
import sympy

sympy.ask(sympy.Q.real(sympy.sqrt(sympy.Symbol("x"))), sympy.Q.real(sympy.Symbol("x")))
```

used to return the correct `None` in sympy 1.13.3, but in sympy 1.14.0 it returns the incorrect `True`.

(We are asking if `sqrt(x)` is real given that `x` is real, which should be unknown as `x` could be negative.)


Patch:
diff --git a/sympy/assumptions/handlers/sets.py b/sympy/assumptions/handlers/sets.py
index beb6afd64c44..031986b77a83 100644
--- a/sympy/assumptions/handlers/sets.py
+++ b/sympy/assumptions/handlers/sets.py
@@ -7,7 +7,7 @@
 from sympy.core.numbers import (AlgebraicNumber, ComplexInfinity, Exp1, Float,
     GoldenRatio, ImaginaryUnit, Infinity, Integer, NaN, NegativeInfinity,
     Number, NumberSymbol, Pi, pi, Rational, TribonacciConstant, E)
-from sympy.core.logic import fuzzy_bool, fuzzy_not
+from sympy.core.logic import fuzzy_bool, fuzzy_not, fuzzy_and
 from sympy.functions import (Abs, acos, acot, asin, atan, cos, cot, exp, im,
     log, re, sin, tan)
 from sympy.core.numbers import I
@@ -339,15 +339,16 @@ def _(expr, assumptions):
 
     if ask(Q.real(expr.base), assumptions):
         if ask(Q.real(expr.exp), assumptions):
-            if ask(Q.zero(expr.base), assumptions) is not False:
-                if ask(Q.positive(expr.exp), assumptions):
-                    return True
-                return
-            if expr.exp.is_Rational and \
-                    ask(Q.even(expr.exp.q), assumptions):
-                return ask(Q.positive(expr.base), assumptions)
-            elif ask(Q.integer(expr.exp), assumptions):
-                return True
+            if (expr.exp.is_Rational and
+                    ask(Q.even(expr.exp.q), assumptions)):
+                return ask(Q.nonnegative(expr.base), assumptions)
+            base_is_zero = ask(Q.zero(expr.base), assumptions)
+            if base_is_zero or ask(Q.integer(expr.exp), assumptions):
+                # Division by zero : If the base is 0 and the exponent
+                # is negative, ``expr`` evaluates to complex infinity.
+                expr_is_complex_infinity = fuzzy_and([base_is_zero,
+                                ask(Q.negative(expr.exp), assumptions)])
+                return fuzzy_not(expr_is_complex_infinity)
             elif ask(Q.positive(expr.base), assumptions):
                 return True
 


Test patch:
diff --git a/sympy/assumptions/tests/test_query.py b/sympy/assumptions/tests/test_query.py
index 31ea38c6ef42..c4d9aa03feaf 100644
--- a/sympy/assumptions/tests/test_query.py
+++ b/sympy/assumptions/tests/test_query.py
@@ -9,6 +9,7 @@
 from sympy.assumptions.ask_generated import (get_all_known_facts,
     get_known_facts_dict)
 from sympy.core.add import Add
+from sympy.core.mul import Mul
 from sympy.core.numbers import (I, Integer, Rational, oo, zoo, pi)
 from sympy.core.singleton import S
 from sympy.core.power import Pow
@@ -2059,6 +2060,19 @@ def test_real_pow():
     assert ask(Q.real(x**y), Q.zero(x) & Q.real(y)) is None
     assert ask(Q.real(x**y), Q.zero(x) & Q.positive(y)) is True
 
+    # https://github.com/sympy/sympy/issues/28142
+    assert ask(Q.real(sqrt(x)), Q.real(x)) is None
+    one_half = Mul(S.Half, 1, evaluate=False)
+    assert ask(Q.real(x ** one_half), Q.real(x)) is None
+    assert ask(Q.real(Pow(x, 1, evaluate=False)), Q.zero(x)) is True
+    assert ask(Q.real(x**x), Q.zero(x)) is True
+    assert ask(Q.real(Pow(x, -1, evaluate=False)), Q.zero(x)) is False
+    two_thirds = Rational(2, 3)
+    assert ask(Q.real(x**two_thirds), Q.zero(x)) is True
+    assert ask(Q.real(x**pi), Q.zero(x)) is True
+    assert ask(Q.real(x**sqrt(2)), Q.zero(x)) is True
+    assert ask(Q.real(x**Rational(1/2)), Q.zero(x)) is True
+
 
 @_both_exp_pow
 def test_real_functions():