Repository: sympy/sympy (Python)

Issue:
regression: `Ne` simplifies incorrectly
Consider
```
a = Ne(x*(x+y), x**2 + x*y)
```
Before fd63f10ec66c437513bdfd983ce4d62ae7747373, `simplify(a)` gave False.  Now it gives True

I think it should be False because `Eq(a.lhs, a.rhs)` should (and does) simplify to True.  `Ne` is mathematical inequality, not structural inequality.

CC @smichr


Discussion:
I would like to work.
Fortunately, the offending diff is small. My initial assessment is that it is related to the call to canonical. What does `a.canonical` give?
@smichr I have query that what should `simplify(x**2 + x*y)` return. Now it is returning `x*(x + y)` but i think it should return `x**2 + x*y` unless and untill it is known that the given symbols hold ditributivity i.e  it is surely true.
`a.canonical` is `Ne(x*(x + y), x**2 + x*y)`
@jmig5776  you can go through simplify doc for your answer. There is a definition defined for simplify--"Nonetheless, especially for interactive use, or when you don’t know anything about the structure of the expression, simplify() tries to apply intelligent heuristics to make the input expression “simpler”. "


> @smichr I have query that what should `simplify(x**2 + x*y)` return. Now it is returning `x*(x + y)` but i think it should return `x**2 + x*y` unless and untill it is known that the given symbols hold ditributivity i.e it is surely true.


Thanks @RituRajSingh878 
I think the below `_eval_simplify` function of class `Unequality` should `return not eq` because if the equality holds then the function should return that this Unequality does'nt hold true.
```
def _eval_simplify(self, ratio, measure, rational, inverse):
        eq = Equality(*self.args)._eval_simplify(
            ratio, measure, rational, inverse)
        if isinstance(eq, Equality):
            eq = self.func(*eq.args)
        return eq
```
What do you think @smichr ?

> I think the below `_eval_simplify` function of class `Unequality` should `return not eq` because if the equality holds then the function should return that this Unequality does'nt hold true.
> 
> ```
> def _eval_simplify(self, ratio, measure, rational, inverse):
>         eq = Equality(*self.args)._eval_simplify(
>             ratio, measure, rational, inverse)
>         if isinstance(eq, Equality):
>             eq = self.func(*eq.args)
>         return eq
> ```
> 

yup I checked it and I am currently trying to resolve.
Thanks, @jmig5776 


@RituRajSingh878 I had solved it in my dev environment. Is it okk to you if I make pull request? 
I am busy in other issue .But I had also solved, and I am going for pr. So you can go for another issue.
Thanks
There is nothing wrong with more than one person doing a PR for the same issue.  Sometimes that will help everyone find the best solution.  And there is always need for constructive review.



Patch:
diff --git a/sympy/core/relational.py b/sympy/core/relational.py
index 6460dac0dede..3efd2273c374 100644
--- a/sympy/core/relational.py
+++ b/sympy/core/relational.py
@@ -520,11 +520,13 @@ def binary_symbols(self):
         return set()
 
     def _eval_simplify(self, ratio, measure, rational, inverse):
+        # simplify as an equality
         eq = Equality(*self.args)._eval_simplify(
             ratio, measure, rational, inverse)
         if isinstance(eq, Equality):
-            eq = self.func(*eq.args)
-        return eq
+            # send back Ne with the new args
+            return self.func(*eq.args)
+        return ~eq  # result of Ne is ~Eq
 
 Ne = Unequality
 


Test patch:
diff --git a/sympy/core/tests/test_relational.py b/sympy/core/tests/test_relational.py
index 6e8ed5b42be2..9c3d6c08d524 100644
--- a/sympy/core/tests/test_relational.py
+++ b/sympy/core/tests/test_relational.py
@@ -802,3 +802,7 @@ def test_Equality_rewrite_as_Add():
     assert eq.rewrite(Add) == 2*x
     assert eq.rewrite(Add, evaluate=None).args == (x, x, y, -y)
     assert eq.rewrite(Add, evaluate=False).args == (x, y, x, -y)
+
+def test_issue_15847():
+    a = Ne(x*(x+y), x**2 + x*y)
+    assert simplify(a) == False