Created
August 22, 2026 17:15
-
-
Save logiclrd/5f3a55a42029b3d2c30dd464ee9b5a97 to your computer and use it in GitHub Desktop.
Quick Python hack-up of one of Ramanujan's pi formulae
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mpmath import * | |
| mp.dps = 500 | |
| mp.pretty = False | |
| coeff = fdiv(1, fmul(882, sqrt(fadd(fmul(6, sqrt(2)), 1)))) | |
| for i in range(0, 5): | |
| s = 0 | |
| for n in range(0, i): | |
| a = fac(4 * n) / power(fac(n), 4) | |
| b = fadd(fsub(106983, fmul(75037, sqrt(2))), fmul(fmul(40, fsub(11133, fmul(7300, sqrt(2)))), n)) | |
| c = fmul(fmul(fmul(power(12, 4 * n), power(fadd(1, sqrt(2)), 20 * n)), power(fadd(1, fmul(2, sqrt(2))), 4 * n)), power(1 + fmul(6, sqrt(2)), fmul(2, n))) | |
| s = fadd(s, fdiv(fmul(a, b), c)) | |
| result = fmul(coeff, s) | |
| if abs(result) > 1e-40: | |
| print(f"{i}:\t{result} => {fdiv(1, result)}") | |
| else: | |
| print(f"{i}:\t{result} => nan") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment