Last active
March 6, 2025 17:26
-
-
Save corehello/20eae6b80c4b18600df9125daf9861c9 to your computer and use it in GitHub Desktop.
continued fraction of e
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
# %% | |
# continued fraction of e | |
# https://mathworld.wolfram.com/eContinuedFraction.html | |
# e = 1+1+1/(1+1/(2+2/(3+3/(4+4/(5+5/(...)))))) | |
def eContinuedFraction(n: int) -> float: | |
ret = 1 | |
for i in range(n, 0, -1): | |
ret = i+i/ret | |
return 1+1+1/ret |
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
# %% | |
# continued fraction of pi | |
https://mathworld.wolfram.com/PiContinuedFraction.html | |
def piContinuedFraction(n: int): | |
ret = 1 | |
for i in range(n, 0, -1): | |
ret = 1-(1 if i==1 else (2*i-3)*(2*i-2))/(3-(2*i*(2*i+1))/ret) | |
return 2*ret |
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
# %% | |
# continued fraction of pi | |
https://mathworld.wolfram.com/PiContinuedFraction.html | |
def piContinuedFraction(n: int): | |
ret = 1 | |
for i in range(n, -1, -1): | |
ret = 2+((2*i+1)**2)/ret | |
return 4/(ret - 1) |
Author
corehello
commented
Mar 6, 2025
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment