-
-
Notifications
You must be signed in to change notification settings - Fork 27
Fix SymPy OverflowError in solow.md by using Rational #687
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
Conversation
The SymPy solve() function was failing with 'mpz too large to convert to float' when using Python float values (0.3, 0.5, 2.0) in symbolic expressions with fractional exponents. Using sympy.Rational for exact arithmetic avoids the large intermediate mpz values that caused the overflow in factorint().
✅ Deploy Preview for taupe-gaufre-c4e660 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@HumphreyYang there appears to be an issue with the newer SymPy in this lecture. Would you mind to take a look at this when you get the time. Our Another option is to pin SymPy to the previous version, but that is suboptimal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an OverflowError in the Solow model lecture that occurs when SymPy attempts to solve symbolic equations using float values. The solution replaces float constants with exact rational representations to avoid large intermediate mpz conversions.
Key changes:
- Introduced
sympy.Rationalfor exact symbolic arithmetic instead of float values - Created separate symbolic variables (
A_sym,alpha_sym,delta_sym) to avoid affecting existing numerical code - Updated the print statement to convert the symbolic result to float for display
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Many thanks @mmcky! I just came out from a meeting. I will look into this PR and other PRs tonight! |
|
Many thanks @mmcky, it looks perfect to me! I just noticed that the greek variable names are not in unicode and pushed some edits. Please feel free to merge if the latest commit looks good to you. |
|
thanks so much @HumphreyYang |
Problem
The weekly cache build is failing with:
This occurs in the
solow.mdlecture when callingsolve(c.diff())with SymPy. The issue is that Python float values (0.3, 0.5, 2.0) create irrational exponents like1/(1-0.3)which leads to very largempzintermediate values in SymPy'sfactorint()function.Solution
Use
sympy.Rationalfor exact symbolic arithmetic:A = 2.0→A_sym = Rational(2)alpha = 0.3→alpha_sym = Rational(3, 10)delta = 0.5→delta_sym = Rational(1, 2)This avoids the float-to-mpz conversion issues and produces clean symbolic computation.
Testing
Tested locally with SymPy 1.14.0: