Repository: sympy/sympy

Issue:
Some wrong results in the new assumptions
Copy paste from the mailing list:

Looking through my notes (https://github.com/sympy/sympy/wiki/assumptions_handlers, pardon the formatting; it looks better in emacs), I see that most of the wrong results I saw were not in the "core" facts, like positive or real (other than the ones you probably already knew about with infinities https://github.com/sympy/sympy/issues/5976). It looks like most of the blatant wrong results that I found were in ntheory (and yes, I am guilty of not ever opening issues for these things)

``` py
In [2]: ask(Q.prime(x*y), Q.integer(x)&Q.integer(y))
Out[2]: False

In [3]: ask(Q.prime(x**y), Q.integer(x)&Q.integer(y))
Out[3]: False

In [6]: ask(Q.integer(abs(x)), ~Q.integer(x))
Out[6]: False
```

I leave it as an exercise to the reader why each of the above is incorrect.

But more to the point, as I noted in at the bottom of that wiki page, the new assumptions handlers code is very fragile. If you accidentally use the wrong kind of Python logic instead of fuzzy logic, you can return False instead of None. In the best case, you just end up not implementing as much as you thought you were, but in the worst case, you get a wrong result.

There are subtle issues that can come up (similar to the https://github.com/sympy/sympy/issues/5976 one) with the new assumptions not being consistant in how it defines assumptions. It doesn't help that it quite often calls out to some external routine to calculate something, which may or may not use the same definition of the assumption that it does. It also uses evalf on most assumptions relating to numbers, which can have its own issues.


Discussion:

Fix (patch):
diff --git a/sympy/assumptions/handlers/sets.py b/sympy/assumptions/handlers/sets.py
index bf0754b6d1..ebb7c18dfa 100644
--- a/sympy/assumptions/handlers/sets.py
+++ b/sympy/assumptions/handlers/sets.py
@@ -94,7 +94,8 @@ def _(expr, assumptions):
 
 @IntegerPredicate.register(Abs)
 def _(expr, assumptions):
-    return ask(Q.integer(expr.args[0]), assumptions)
+    if ask(Q.integer(expr.args[0]), assumptions):
+        return True
 
 @IntegerPredicate.register_many(Determinant, MatrixElement, Trace)
 def _(expr, assumptions):
diff --git a/sympy/polys/rootisolation.py b/sympy/polys/rootisolation.py
index b2f8fd115e..3846244fbe 100644
--- a/sympy/polys/rootisolation.py
+++ b/sympy/polys/rootisolation.py
@@ -629,7 +629,7 @@ def dup_isolate_real_roots(f, K, eps=None, inf=None, sup=None, basis=False, fast
     return sorted(I_neg + I_zero + I_pos)
 
 def dup_isolate_real_roots_list(polys, K, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False):
-    """Isolate real roots of a list of polynomial using Vincent-Akritas-Strzebonski (VAS) CF approach.
+    """Isolate real roots of a list of square-free polynomial using Vincent-Akritas-Strzebonski (VAS) CF approach.
 
        References
        ==========
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index 8b315cc20c..20cbe19669 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -264,7 +264,7 @@ def posify(eq):
     [2]
     """
     eq = sympify(eq)
-    if not isinstance(eq, Basic) and iterable(eq):
+    if iterable(eq):
         f = type(eq)
         eq = list(eq)
         syms = set()


Test changes:
diff --git a/sympy/assumptions/tests/test_query.py b/sympy/assumptions/tests/test_query.py
index 5e0eeb50a0..6ba0fbae82 100644
--- a/sympy/assumptions/tests/test_query.py
+++ b/sympy/assumptions/tests/test_query.py
@@ -1642,6 +1642,13 @@ def test_integer():
     assert ask(Q.integer(x/3), Q.odd(x)) is None
     assert ask(Q.integer(x/3), Q.even(x)) is None
 
+    # https://github.com/sympy/sympy/issues/7286
+    assert ask(Q.integer(Abs(x)),Q.integer(x)) is True
+    assert ask(Q.integer(Abs(-x)),Q.integer(x)) is True
+    assert ask(Q.integer(Abs(x)), ~Q.integer(x)) is None
+    assert ask(Q.integer(Abs(x)),Q.complex(x)) is None
+    assert ask(Q.integer(Abs(x+I*y)),Q.real(x) & Q.real(y)) is None
+
 
 def test_negative():
     assert ask(Q.negative(x), Q.negative(x)) is True
diff --git a/sympy/simplify/tests/test_simplify.py b/sympy/simplify/tests/test_simplify.py
index a5bf469f68..926b0380cc 100644
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -548,10 +548,6 @@ def test_posify():
     assert str(Sum(posify(1/x**n)[0], (n,1,3)).expand()) == \
         'Sum(_x**(-n), (n, 1, 3))'
 
-    A = Matrix([[1, 2, 3], [4, 5, 6 * Abs(x)]])
-    Ap, rep = posify(A)
-    assert Ap == A.subs(*reversed(rep.popitem()))
-
     # issue 16438
     k = Symbol('k', finite=True)
     eq, rep = posify(k)