Skip to content

Conversation

@mmcky
Copy link
Contributor

@mmcky mmcky commented Dec 23, 2025

Problem

The weekly cache build is failing with:

OverflowError: 'mpz' too large to convert to float

This occurs in the solow.md lecture when calling solve(c.diff()) with SymPy. The issue is that Python float values (0.3, 0.5, 2.0) create irrational exponents like 1/(1-0.3) which leads to very large mpz intermediate values in SymPy's factorint() function.

Solution

Use sympy.Rational for exact symbolic arithmetic:

  • A = 2.0A_sym = Rational(2)
  • alpha = 0.3alpha_sym = Rational(3, 10)
  • delta = 0.5delta_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:

s_star = 0.3
SUCCESS!

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().
@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit 8d86de1
🔍 Latest deploy log https://app.netlify.com/projects/taupe-gaufre-c4e660/deploys/694a64bb25010a0008b8890d
😎 Deploy Preview https://deploy-preview-687--taupe-gaufre-c4e660.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mmcky
Copy link
Contributor Author

mmcky commented Dec 23, 2025

@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 cache is currently failing, but I won't make any publish tags until this is fixed.

Another option is to pin SymPy to the previous version, but that is suboptimal.

Copy link

Copilot AI left a 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.Rational for 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.

@github-actions
Copy link

github-actions bot commented Dec 23, 2025

@github-actions github-actions bot temporarily deployed to pull request December 23, 2025 05:47 Inactive
@github-actions github-actions bot temporarily deployed to pull request December 23, 2025 05:47 Inactive
@HumphreyYang
Copy link
Member

Many thanks @mmcky! I just came out from a meeting. I will look into this PR and other PRs tonight!

@HumphreyYang
Copy link
Member

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.

@github-actions github-actions bot temporarily deployed to pull request December 23, 2025 09:53 Inactive
@mmcky
Copy link
Contributor Author

mmcky commented Dec 23, 2025

thanks so much @HumphreyYang

@mmcky mmcky merged commit 059e0f4 into main Dec 23, 2025
7 checks passed
@mmcky mmcky deleted the fix/sympy-solow-overflow branch December 23, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants