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

solve does not take positive=True into account #25627

Open
retsyo opened this issue Sep 4, 2023 · 3 comments
Open

solve does not take positive=True into account #25627

retsyo opened this issue Sep 4, 2023 · 3 comments

Comments

@retsyo
Copy link

retsyo commented Sep 4, 2023

I am using sympy 1.12 with python-3.10.9.amd64 on windows 10 64bits

Given $s=\LARGE \frac {50} {r+1}$, if $r \geq 0$ then we know that if $r<49$, in a all, $0 \leq r<49$, then $s>1$.

I try to solve it by

import sys
from sympy import *

r = Symbol('r', positive=True)

s = 50/(r+1)

x0 = solve(f'{s}>1')
print(f'{x0}')

which says

(-1 < r) & (r < 49)

in other words, solve does not find that r is a positive number to give an corrected answer as (0 <= r) & (r < 49)

@oscarbenjamin
Copy link
Contributor

It is a mistake that solve pretends to check assumptions when it cannot do it properly. Also solve should be changed to not "solve" inequalities like this as it is incompatible with what solve otherwise does. There should be a separate function for "solving" inequalities (actually there are several but none of them really works very well for a system of inequalities).

@oscarbenjamin
Copy link
Contributor

The function that should be used here is reduce_inequalities but it needs improvement:

In [23]: reduce_inequalities([(50/(x+1) > 1), (x > 0)])
Out[23]: -1 < x0 < xx < 49x <

skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 4, 2023
@retsyo
Copy link
Author

retsyo commented Sep 5, 2023

>>> from sympy import *
>>> __version__
'1.12'
>>> x = Symbol('x')
>>> reduce_inequalities([(50/(x+1) > 1), (x > 0)])
(-1 < x) & (0 < x) & (x < 49) & (x < oo)
>>> reduce_inequalities([(50/(x+1) > 1)])
(-1 < x) & (x < 49)

but if we tell that the symbol is positive

>>> y = Symbol('y', positive=True)
>>> reduce_inequalities([(50/(y+1) > 1), (y > 0)])
y < 49
>>> reduce_inequalities([(50/(y+1) > 1)])
y < 49

which I think the answer shoule be

(0<y) & (y < 49)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants