# Eq( Mod(x, 2*pi), 0 ) evaluates to False #10024

Closed
opened this Issue Oct 22, 2015 · 5 comments

Projects
None yet
3 participants
Contributor

### drufat commented Oct 22, 2015

 The condition `Eq( Mod(x, 2*pi), 0 )` always evaluates to `False` where `x` is just a regular symbol. Obviously when `x=0, 2*pi, 4*pi` it should be `True`. The correct behavior should be not to reduce the expression to True or False when x is a general symbol. To replicate the bug, try: ``````from sympy import Mod from sympy.abc import x print(Eq( Mod(x, 2*pi), 0 )) ``````
Contributor

### drufat commented Oct 22, 2015

 It appears that when one initializes expr with `expr = Mod(x, 2*pi)` `expr._assumptions['zero']` is set to `True` when it should have been set to `None`.

Merged

Member

### smichr commented Oct 23, 2015

 `_fuzzy_group` should be used instead of `fuzzy_and` in `Mod._eval_is_integer` ``````diff --git a/sympy/core/mod.py b/sympy/core/mod.py index 4d58ebd..4b27152 100644 --- a/sympy/core/mod.py +++ b/sympy/core/mod.py @@ -141,9 +141,9 @@ def doit(p, q): return G*cls(p, q, evaluate=(p, q) != (pwas, qwas)) def _eval_is_integer(self): - from sympy.core.logic import fuzzy_and, fuzzy_not + from sympy.core.logic import _fuzzy_group, fuzzy_not p, q = self.args - return fuzzy_and([p.is_integer, q.is_integer, fuzzy_not(q.is_zero)]) + return _fuzzy_group([p.is_integer, q.is_integer, fuzzy_not(q.is_zero)]) def _eval_is_nonnegative(self): if self.args[1].is_positive: \$ python Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from sympy import *; from sympy.abc import x >>> Mod(x, 2*pi).is_integer >>> ``````
Contributor

### drufat commented Oct 23, 2015

 Isn't it cleaner to have ``````- return fuzzy_and([p.is_integer, q.is_integer, fuzzy_not(q.is_zero)]) + if fuzzy_and([p.is_integer, q.is_integer, fuzzy_not(q.is_zero)]): + return True `````` That's what I did in my pull request.
Member

### smichr commented Oct 23, 2015

 I think so. As I recall, the assumption system's eval routines only have to worry about returning True and the implications will be worked out by the logic engine. If what you propose works then I guess this is true. Also, if p and q were rational and non-zero then we wouldn't want to return False. So I think your proposal is better.
Member

### asmeurer commented Oct 24, 2015

 If the implications are defined in sympy.core.assumptions, then yes, the system will deduce them automatically.

### skirpichev added a commit to skirpichev/diofant that referenced this issue May 21, 2016

``` Fix Mod._eval_is_integer helper ```
```When one cannot determine it is an integer, it should
return None, and not False.  This closes issue sympy/sympy#10024.

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>```
``` 47cfeeb ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue May 22, 2016

``` Fix Mod._eval_is_integer helper ```
```When one cannot determine it is an integer, it should
return None, and not False.  This closes issue sympy/sympy#10024.

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>```
``` dafa72e ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 26, 2016

``` Fix Mod._eval_is_integer helper ```
```When one cannot determine it is an integer, it should
return None, and not False.  This closes issue sympy/sympy#10024.

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>```
``` b1b58d8 ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 16, 2016

``` Fix Mod._eval_is_integer helper ```
```When one cannot determine it is an integer, it should
return None, and not False.  This closes issue sympy/sympy#10024.

Signed-off-by: Sergey B Kirpichev <skirpichev@gmail.com>```
``` 1461dd4 ```