Skip to content

Conversation

@mmcky
Copy link
Contributor

@mmcky mmcky commented Jan 15, 2026

Problem

The solow lecture was failing with:

OverflowError: 'mpz' too large to convert to float

This occurred because the sympy symbolic computation used Python float values (A=2.0, alpha=0.3, delta=0.5) which caused overflow when SymPy tried to convert the result.

Solution

Use sympy.Rational for exact symbolic computation:

from sympy import solve, Symbol, Rational

A_sym = Rational(2)
alpha_sym = Rational(3, 10)
delta_sym = Rational(1, 2)

This matches the fix in the production lecture-python-intro repository.

Changes

  • Import Rational from sympy
  • Define symbolic constants using Rational for exact computation
  • Use float(s_star) when printing for display

The sympy code was using float values (A=2.0, alpha=0.3, delta=0.5) which
caused 'OverflowError: mpz too large to convert to float' during symbolic
computation.

This fix:
- Imports Rational from sympy
- Defines A_sym, alpha_sym, delta_sym as Rational values for exact computation
- Uses float() when printing s_star for display

This matches the fix in the production lecture-python-intro repository.
@github-actions
Copy link

@mmcky mmcky merged commit df7dd39 into main Jan 15, 2026
2 checks passed
@mmcky mmcky deleted the fix/solow-sympy-overflow branch January 15, 2026 23:38
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

Successfully merging this pull request may close these issues.

2 participants