Created
June 22, 2022 20:56
-
-
Save okumurakengo/ca48e4b90bf29628039e89a5ed279e78 to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "47129976", | |
"metadata": {}, | |
"source": [ | |
"# チュドノフスキーの公式\n", | |
"\n", | |
"$$\n", | |
"\\frac{1}{\\pi} = 12\\sum_{n=0}^\\infty \\frac{(-1)^n(6n)!(545140134n + 13591409)}{(3n)!(n!)^3(640320)^{3n+\\frac{3}{2}}}\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 117, | |
"id": "bfe1bde5", | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"この値に近似する 1/π ↓\n", | |
"0.318309886183790671537767526745\n", | |
"\n", | |
"\n", | |
"計算結果ほぼ同じ!\n", | |
"0.318309886183790691216444201928\n" | |
] | |
} | |
], | |
"source": [ | |
"from sympy import *\n", | |
"\n", | |
"init_printing()\n", | |
"\n", | |
"def Chudnovsky(cnt):\n", | |
" sum = 0\n", | |
" for n in range(cnt):\n", | |
" numerator = ((-1)**n) * factorial(6*n) * ((545140134*n) + 13591409)\n", | |
" denominator = factorial(3*n) * (factorial(n)**3) * (640320 ** (3*n + 3/2))\n", | |
" sum += (numerator / denominator)\n", | |
" return 12 * sum\n", | |
"\n", | |
"\n", | |
"print('この値に近似する 1/π ↓')\n", | |
"print((1 / pi).evalf(30))\n", | |
"print('\\n')\n", | |
"print('計算結果ほぼ同じ!')\n", | |
"print(Chudnovsky(10).evalf(30))\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6858469b", | |
"metadata": {}, | |
"source": [ | |
"# ベイリー=ボールウェイン=プラウフの公式\n", | |
"\n", | |
"$$\n", | |
"\\pi = \\sum_{n=0}^\\infty (\\frac{4}{8n+1}-\\frac{2}{8n+4}-\\frac{1}{8n+5}-\\frac{1}{8n+6})(\\frac{1}{16})^n\n", | |
"$$\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 116, | |
"id": "e59b45dd", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"この値に近似する π ↓\n", | |
"3.14159265358979323846264338328\n", | |
"\n", | |
"\n", | |
"計算結果ほぼ同じ!\n", | |
"3.14159265358979133964112406829\n" | |
] | |
} | |
], | |
"source": [ | |
"from sympy import *\n", | |
"\n", | |
"init_printing()\n", | |
"\n", | |
"def BBP(cnt):\n", | |
" return sympify(sum([((4/(8*n+1))-(2/(8*n+4))-(1/(8*n+5))-(1/(8*n+6)))*((1/16)**n) for n in range(cnt)]))\n", | |
"\n", | |
"print('この値に近似する π ↓')\n", | |
"print((pi).evalf(30))\n", | |
"print('\\n')\n", | |
"print('計算結果ほぼ同じ!')\n", | |
"print(BBP(10).evalf(30))\n" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment