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

Solving for symbols with large exponents is slow #15296

Open
Sircular opened this issue Sep 26, 2018 · 4 comments
Open

Solving for symbols with large exponents is slow #15296

Sircular opened this issue Sep 26, 2018 · 4 comments

Comments

@Sircular
Copy link

The following MWE takes 100% of a CPU core and does not find the solution after a full minute:

from sympy import Symbol
from sympy.solvers import solve

r = Symbol('r')
eq = (1+r)**30 - 1.5
solve(eq, r)
@llucifer97
Copy link

erro_sympy
hi @Sircular i ran this code i have shared the result.
it ran without a error.

@warnerjon12
Copy link
Contributor

warnerjon12 commented Oct 4, 2018

SymPy is a tool, and like all tools, it can only be used well if you know the best way to use it. In your example, it is easy to see how SymPy might solve it, but in the general case it is hard to program intuition. As such, it is up to you as the user to determine how best to express your problem so that SymPy will work the fastest. In this case, I can get the exact answers in under 3 seconds using this code:

r = Symbol('r')
eq = r**30 - Number(3) / 2
print([s.subs(r, 1+r) for s in solve(eq, r)])

@smichr
Copy link
Member

smichr commented Oct 6, 2018

Were you wanting all roots or a simple inversion?

>>> [i.subs(y, 30) for i in solve((x+1)**y-1.5,x)]
[0.0136072508934197]

@oscarbenjamin
Copy link
Contributor

Ideally a solution would be found even where there are floats in the input. Perhaps it would be appropriate to return float solutions for float input.

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

5 participants