Download MES/ref_ellipse_mpmath.py from perrabyte/higher-accuracy-integrals: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/datasets/perrabyte/higher-accuracy-integrals/resolve/main/MES/ref_ellipse_mpmath.py
- Command line
-
hf download hf://datasets/perrabyte/higher-accuracy-integrals/MES/ref_ellipse_mpmath.py
-
curl -L -o ref_ellipse_mpmath.py https://huggingface.co/datasets/perrabyte/higher-accuracy-integrals/resolve/main/MES/ref_ellipse_mpmath.py
670 Bytes
| import mpmath | |
| # 1. Set your arbitrary decimal precision (e.g., 50 digits) | |
| mpmath.mp.dps = 50 | |
| def ellipse_circumference_exact(a, b): | |
| # Convert inputs to mpmath high-precision floats | |
| a = mpmath.mpf(a) | |
| b = mpmath.mpf(b) | |
| # Calculate eccentricity squared: m = 1 - (b^2 / a^2) | |
| m = 1 - (b**2 / a**2) | |
| # Exact Formula: C = 4 * a * E(m) | |
| # Note: mpmath.ellipe takes parameter m (eccentricity squared) | |
| return 4 * a * mpmath.ellipe(m) | |
| # Example usage | |
| a_axis = 5.0 | |
| b_axis = 3.0 | |
| C = ellipse_circumference_exact(a_axis, b_axis) | |
| print(C) | |
| # Outputs exactly 50 decimal places of accuracy: | |
| # 25.526998863398131362241641031331826065576269229712 | |