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

Floats not always desired? #28

Open
phcreery opened this issue Aug 3, 2021 · 2 comments
Open

Floats not always desired? #28

phcreery opened this issue Aug 3, 2021 · 2 comments

Comments

@phcreery
Copy link
Collaborator

phcreery commented Aug 3, 2021

Example:

>>> _HI = sympy.symbols('a')
>>> sympy.expand(sympy.Pow(sympy.Add(_HI,sympy.Float(1)),sympy.Float(2)))
(a + 1.0)**2.0
>>> sympy.expand(sympy.Pow(sympy.Add(_HI,sympy.Float(1)),sympy.Integer(2)))
a**2 + 2.0*a + 1.0
>>>
@phcreery
Copy link
Collaborator Author

phcreery commented Aug 3, 2021

Here is a little fix I came up with. Line 133 of phcreery@0984fe9 I don't see this hurting anything. Let me know what you think.

@phcreery phcreery changed the title Floats are not always desired Floats not always desired? Aug 3, 2021
@phcreery phcreery closed this as completed Aug 4, 2021
@stefnotch stefnotch reopened this Aug 5, 2021
@stefnotch
Copy link
Owner

Sorry for the late response. I took a look at this and yes, it does seem like the current default behavior is not ideal.
https://docs.sympy.org/latest/gotchas.html#evaluating-expressions-with-floats-and-rationals

Instead, we should almost always use the Integer and Rational data types. I think the conversions in Sympy should always work out the right way.

One minor gotcha of that approach is that the Integer and Rational data types can become arbitrarily large. That means if someone types 99999999**9999999, Sympy will painstakingly try to compute the entire result, regardless of how long it takes. To "fix" that, we have to interrupt the execution after a few seconds.

@stefnotch stefnotch mentioned this issue Aug 8, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants