-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Implicitly converting floats to Rational in SymPy APIs #15844
Comments
What about having a method (maybe that method is Very relevant question though! Also, I think that it can be OK to convert 0.1 to 1/10 given that there is a way to get and use the "exact" floating-point representation. Despite being a minority of users, there are some that would like that to happen. Despite being a generally evil idea, can one have two global modes? One where it is OK to convert things like that, maybe default, one where it isn't? |
There is already some code that does this (yes, from nsimplify), but it is bad IMO. It leads to a lot of problems. See #12045. Also see #12534 and the dozens of linked issues if you want to get a better handle on this stuff. There is no way for SymPy to distinguish between On the other hand, treating floats as equal to things that they are only approximately equal to can lead to a lot of issues (#11707). |
0.3*sqrt(3) is left unevaluated only because it could be too expensive in general to evaluate the rest of the expression in a Mul. Imagine it was Function calls like |
This can be handled at instantiation with |
Does SymPy have any policy on implicit conversion of
float
toRational
at API entry points?It seems to me like there are many functions that work a lot better if you pass in Rationals even for simple numbers like 0.1. I would consider that important advice to users: pass in exact inputs where possible.
On the other hand there are lots of users who really want to be able to write
0.1
instead ofS(1)/10
etc and have SymPy treat it the same. I see this come up often in issues/questions so I think the current behaviour breaks common user expectations.OTOH I might prefer
0.1
to be treated as exactlyS('0.1000000000000000055511151231257827021181583404541015625')
but I suspect I would be in the minority among users.I'm asking this because
Point
auto-converts float to Rational (inexactly usingnsimplify
).Circle
passes some arguments toPoint
but keeps the radius itself soThe fix proposed in #15816 is to convert the radius as well but actually I wonder if the mistake is the fact that
Point
does auto-conversion.This then leads on to questions like what should
is_tangent
do in the presence of floats. Normally a floating point routine for a question like that would be based on some tolerancereturn abs(dist) < tol
. Maybe the answer should be put back to users: don't use floats or don't use functions like is_tangent with floats etc.See also #11484.
The text was updated successfully, but these errors were encountered: