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

Integer comparison #23518

Open
tbennun opened this issue May 19, 2022 · 3 comments · May be fixed by #24198
Open

Integer comparison #23518

tbennun opened this issue May 19, 2022 · 3 comments · May be fixed by #24198

Comments

@tbennun
Copy link

tbennun commented May 19, 2022

Running the following code I expect the result of statement 5 to be True:

In [3]: M = sp.Symbol('M', positive=True, integer=True)

In [4]: N = sp.Symbol('N', positive=True, integer=True)

In [5]: M*N >= N
Out[5]: M*N >= N

This doesn't work as well, but ask is said to be WIP:

In [12]: sp.ask(sp.Q.nonnegative(M*N - N))

Which assumption am I missing on the symbols?

@oscarbenjamin
Copy link
Contributor

This one works:

In [13]: M*(N - 1) >= 0
Out[13]: True

Probably ask should handle things like this but there isn't a general solver for systems of inequalities that it could use.

@tbennun
Copy link
Author

tbennun commented May 19, 2022

That is indeed interesting (I'm guessing because N >= 1 evaluates to True). Strangely enough M*N - N >= 0 evaluates to a Relational. Also interesting:

In [22]: sp.solve((M*N - N) >= 0, M)
Out[22]: True

(N works too)

More tidbits:

In [32]: ((M*N - N) >= 0).simplify()
Out[32]: True

In [33]: (M*N >= N).simplify()
Out[33]: N <= M*N

which of course means that solving M*N >= N works as well.

@u7122029
Copy link

u7122029 commented Oct 26, 2022

So I'm currently working on this issue and I think I have a solution, however, I'm having an issue with making the test function. My test function looks like

# sympy/simplify/tests/test_simplify.py
def test_issue_23518():
    M = Symbol("M", positive=True, integer=True)
    N = Symbol("N", positive=True, integer=True)

    expr = M*N >= N
    expr = expr.simplify() # (X)
    assert expr == True

Unfortunately when I try to run the simplify method on the line marked X, nothing happens. When I try using breakpoints to step into the method, the line just gets skipped like nothing happened.

On the other hand, if I make a testing file on the root directory of the project that looks like:

# testing.py
from sympy import *

M = Symbol("M", positive=True, integer=True)
N = Symbol("N", positive=True, integer=True)

expr = M*N >= N
expr = expr.simplify()
assert expr == True

The code runs fine without any assertion errors. May I please know what is going wrong here and how to remedy the situation?

u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Oct 26, 2022
u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Oct 29, 2022
u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Oct 30, 2022
u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Oct 30, 2022
…omparison(sympy#23518)

� Conflicts:
�	doc/src/guides/solving/index.md
@u7122029 u7122029 linked a pull request Oct 30, 2022 that will close this issue
u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Nov 3, 2022
u7122029 added a commit to u7122029/sympy_2120 that referenced this issue Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants