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

Incorrect result of simplify #23086

Open
proy87 opened this issue Feb 16, 2022 · 6 comments
Open

Incorrect result of simplify #23086

proy87 opened this issue Feb 16, 2022 · 6 comments

Comments

@proy87
Copy link

proy87 commented Feb 16, 2022

simplify(180*acos(S.One*7823207/7823209)/pi) returns 0, but the value of the expression is approximately 0.04

@oscarbenjamin
Copy link
Contributor

I don't get zero:

In [1]: simplify(180 * acos(S.One * 7823207 / 7823209) / pi)
Out[1]: 
        ⎛7823207180acos⎜───────⎟
        ⎝7823209⎠
─────────────────
        π 

@oscarbenjamin
Copy link
Contributor

I see, it only happens sometimes:

$ cat t.py
from sympy import *

print(simplify(180 * acos(S.One * 7823207 / 7823209) / pi))
$ python t.py 
0
$ python t.py 
0
$ python t.py 
0
$ python t.py 
0
$ python t.py 
0
$ python t.py 
180*acos(7823207/7823209)/pi
$ python t.py 
0
$ python t.py 
180*acos(7823207/7823209)/pi
$ python t.py 
180*acos(7823207/7823209)/pi

@oscarbenjamin
Copy link
Contributor

It's a problem with assumptions. This sometimes gives True and sometimes False:

from sympy import *

expr = 180 * acos(S.One * 7823207 / 7823209) / pi

print(expr.is_zero)

@oscarbenjamin
Copy link
Contributor

The bug is in evalf:

In [2]: expr = acos(S(7823207) / 7823209)

In [3]: expr.evalf(2)
Out[3]: 0

In [4]: expr.evalf(20)
Out[4]: 0.00071505185649204996777

@oscarbenjamin
Copy link
Contributor

Here the rational number is evalfed to 1 when it is not quite equal to 1:

# Convert all args to mpf or mpc
# Convert the arguments to *higher* precision than requested for the
# final result.
# XXX + 5 is a guess, it is similar to what is used in evalf.py. Should
# we be more intelligent about it?
try:
args = [arg._to_mpmath(prec + 5) for arg in args]

@proy87
Copy link
Author

proy87 commented Feb 16, 2022

Also from time to time sin(acos(S(7823207)/7823209)) gives 0.

skirpichev added a commit to skirpichev/diofant that referenced this issue Feb 17, 2022
skirpichev added a commit to skirpichev/diofant that referenced this issue Feb 24, 2022
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