Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix simplification of Eq(pi/L, 0) to None from False with L positive #16027

Closed
wants to merge 4 commits into from

Conversation

divyanshu132
Copy link
Member

@divyanshu132 divyanshu132 commented Feb 19, 2019

References to other Issues or PRs

Fixes #12690

Brief description of what is fixed or changed

previously:

>>> x=symbols('x', positive=True)
>>> Eq(pi/x, 0)
False

After the fix:

>>> x=symbols('x', positive=True)
>>> Eq(pi/x, 0)
Eq(pi/x, 0) 

>>> Eq(pi/x, 0).subs(x, oo)
True

Other comments

Release Notes

  • core
    • Improve finiteness simplification of equation

@sympy-bot
Copy link

sympy-bot commented Feb 19, 2019

Hi, I am the SymPy bot (v137). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.4.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
Fixes #12690
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed

previously:

```
>>> x=symbols('x', positive=True)
>>> Eq(pi/x, 0)
False

```
After the fix:

```
>>> x=symbols('x', positive=True)
>>> Eq(pi/x, 0)
Eq(pi/x, 0) 

>>> Eq(pi/x, 0).subs(x, oo)
True
```

#### Other comments

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
*  core
   *  Improve finiteness simplification of equation 
<!-- END RELEASE NOTES -->

@divyanshu132
Copy link
Member Author

@asmeurer please review.

@divyanshu132
Copy link
Member Author

divyanshu132 commented Feb 19, 2019

Some of the tests will fail because I was not sure whether we should return None or Eq(pi/x, 0) for the test case Eq(pi/x, 0) where x is finite but as mentioned in the issue I have returned None, previously for Eq(pi/x, 1/x) as I've mentioned above it was returning Eq(pi/x, 1/x) which was of no use and the tests will fail because some of them are using .subs to check the equality of the above type equations which will not be possible now to perform .subs on None. I have not changed those tests for now, waiting for your suggestion @asmeurer.

@asmeurer
Copy link
Member

Eq should not return None. It should either reduce to True or False, or remain unevaluated.

@divyanshu132
Copy link
Member Author

@asmeurer please review.

@sylee957 sylee957 added the core label Feb 20, 2019
@@ -17,7 +17,7 @@ def test_rel_ne():

# issue 6116
p = Symbol('p', positive=True)
assert Ne(p, 0) is S.true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be kept. We still want that behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the current master:

>>> from sympy import *
>>> from sympy.core.relational import Ne
>>> p=symbols('p')
>>> assert Ne(p, 0) is S.true
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> 

But, I don't know how its clearing the tests. Can you please check it once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p must be positive.

from sympy import Ne, Symbol, S
p = Symbol('p', positive=True)

gives:

In [8]: Ne(p, 0) == S.true
Out[8]: True

In [9]: Ne(p, 0) is S.true
Out[9]: True

The thing is that if you change the tests you must be sure that the new behavior is the behavior you want.

@@ -92,7 +92,7 @@ def test_Eq():

# issue 6116
p = Symbol('p', positive=True)
assert Eq(p, 0) is S.false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too. The new test doesn't really test the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar behaviour here as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my current master:

In [1]: from sympy import Eq, Symbol, S

In [2]: p = Symbol('p', positive=True)

In [3]: Eq(p, 0) is S.false
Out[3]: True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh thanks, I was missing the positive.

@oscargus
Copy link
Contributor

You must keep all the old tests. I only commented explicitly on a few. The whole idea is to be able to simplify in certain cases. While you are correct in that the simplification you point out should not be simplified, it cannot lead to that other which should are not simplified (unless there are some really good arguments for that).

@Abdullahjavednesar Abdullahjavednesar added the PR: author's turn The PR has been reviewed and the author needs to submit more changes. label Feb 21, 2019
@divyanshu132
Copy link
Member Author

@oscargus please review. I've modified the tests only for fin = symbols('inf', finite=True) which involves finite=True.

@@ -693,19 +694,19 @@ def test_issue_10401():

assert Eq(1/(1/x + 1), 1).func is Eq
assert Eq(1/(1/x + 1), 1).subs(x, S.ComplexInfinity) is S.true
assert Eq(1/(1/fin + 1), 1) is S.false
assert Eq(1/(1/fin + 1), 1).subs(fin, 1) is S.false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with using subs here is that you change the test from testing if the method can determine that this is false just based on the properties of fin to testing if 1/2 is equal to 1. Which is not the same thing.

Same holds for all other tests where subs is added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, should we use func??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you've changed these tests at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try to avoid changing tests unless you know for sure that it is wanted, not only to make the test pass, but because the test was wrong/the behavior changed. So just leave all tests as is and possibly add new tests for #12690

@divyanshu132 divyanshu132 deleted the fix-Equation branch May 29, 2019 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core PR: author's turn The PR has been reviewed and the author needs to submit more changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eq(pi/L, 0) simplifies to False with L positive
7 participants