Skip to content

Instantly share code, notes, and snippets.

@juliusgeo
Last active February 2, 2023 23:25
Show Gist options
  • Save juliusgeo/1da759d07af0b447a78d0ccb14162c57 to your computer and use it in GitHub Desktop.
Save juliusgeo/1da759d07af0b447a78d0ccb14162c57 to your computer and use it in GitHub Desktop.
from functools import reduce as red; from math import \
(factorial as fact, comb);import sys;from decimal import \
(getcontext as c,Decimal as dc);(a:=range,
b:=int(sys. argv[1]));c\
().prec=b; ber=lambda\
e,f=[dc(1)]: [f.append(
1-sum(comb(h ,g)*f[g]/(h
- g + 1) for g in a(h)))for
h in a(1, e + 1)] and abs(
f[-1]);print ((2 * fact(b) /
(ber(b)* 2** b * red(dc.__mul__
, [1 - (1/dc (i) ** b) for i in
[2, 3, 5, 7] ]))) ** (1 / dc(b)))
#juliusgeo pi arb. precis.
@juliusgeo
Copy link
Author

juliusgeo commented Feb 2, 2023

Output:

(venv) ➜ python pi_shaped.py 200
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819

It accepts one argument which is the number of digits of precision you want.

@juliusgeo
Copy link
Author

https://gist.github.com/juliusgeo/f4642c3a6835a2ea0676ef82a6fea1ac This is what I did before, it's basically the same implementation, but without all of the stuff to work with the whitespace changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment