梅欽類公式

梅钦类公式（英语：Machin-like formula）是数学中计算圆周率的一个常用技巧，它是梅欽公式的推广，梅钦公式的形式为 π 4 = 4 arctan ⁡ 1 5 − arctan ⁡ 1 239 {\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}} 梅钦依据此公式，把圆周率计算到一百多位小数。 梅钦类公式的形式为： 其中， a n {\displaystyle a_{n}} 和 b n {\displaystyle b_{n}} 为正 整数，且 a n < b n {\displaystyle a_{n}<b_{n}} ， c n {\displaystyle c_{n}} 为非零整数，且 c 0 {\displaystyle c_{0}} 为正整数。 梅钦类公式的应用可结合反正切函数的泰勒级数展开： 根据角的和差公式， sin ⁡ ( α + β ) = sin ⁡ α cos ⁡ β + cos ⁡ α sin ⁡ β {\displaystyle \sin(\alpha +\beta )=\sin \alpha \cos \beta +\cos \alpha \sin \beta } cos ⁡ ( α + β ) = cos ⁡ α cos ⁡ β − sin ⁡ α sin ⁡ β {\displaystyle \cos(\alpha +\beta )=\cos \alpha \cos \beta -\sin \alpha \sin \beta } 若 − π 2 < arctan ⁡ a 1 b 1 + arctan ⁡ a 2 b 2 < π 2 . {\displaystyle -{\frac {\pi }{2}}<\arctan {\frac {a_{1}}{b_{1}}}+\arctan {\frac {a_{2}}{b_{2}}}<{\frac {\pi }{2}}.} 有 反复应用这一方程，可得到所有的梅欽類公式，比如最初的梅欽公式： 2 arctan ⁡ 1 5 {\displaystyle 2\arctan {\frac {1}{5}}} = arctan ⁡ 1 5 + arctan ⁡ 1 5 {\displaystyle =\arctan {\frac {1}{5}}+\arctan {\frac {1}{5}}} = arctan ⁡ 1 × 5 + 1 × 5 5 × 5 − 1 × 1 {\displaystyle =\arctan {\frac {1\times 5+1\times 5}{5\times 5-1\times 1}}} = arctan ⁡ 10 24 {\displaystyle =\arctan {\frac {10}{24}}} = arctan ⁡ 5 12 {\displaystyle =\arctan {\frac {5}{12}}} 4 arctan ⁡ 1 5 {\displaystyle 4\arctan {\frac {1}{5}}} = 2 arctan ⁡ 1 5 + 2 arctan ⁡ 1 5 {\displaystyle =2\arctan {\frac {1}{5}}+2\arctan {\frac {1}{5}}} = arctan ⁡ 5 12 + arctan ⁡ 5 12 {\displaystyle =\arctan {\frac {5}{12}}+\arctan {\frac {5}{12}}} = arctan ⁡ 5 × 12 + 5 × 12 12 × 12 − 5 × 5 {\displaystyle =\arctan {\frac {5\times 12+5\times 12}{12\times 12-5\times 5}}} = arctan ⁡ 120 119 {\displaystyle =\arctan {\frac {120}{119}}} 4 arctan ⁡ 1 5 − π 4 {\displaystyle 4\arctan {\frac {1}{5}}-{\frac {\pi }{4}}} = 4 arctan ⁡ 1 5 − arctan ⁡ 1 1 {\displaystyle =4\arctan {\frac {1}{5}}-\arctan {\frac {1}{1}}} = 4 arctan ⁡ 1 5 + arctan ⁡ − 1 1 {\displaystyle =4\arctan {\frac {1}{5}}+\arctan {\frac {-1}{1}}} = arctan ⁡ 120 119 + arctan ⁡ − 1 1 {\displaystyle =\arctan {\frac {120}{119}}+\arctan {\frac {-1}{1}}} = arctan ⁡ 120 × 1 + ( − 1 ) × 119 119 × 1 − 120 × ( − 1 ) {\displaystyle =\arctan {\frac {120\times 1+(-1)\times 119}{119\times 1-120\times (-1)}}} = arctan ⁡ 1 239 {\displaystyle =\arctan {\frac {1}{239}}} π 4 = 4 arctan ⁡ 1 5 − arctan ⁡ 1 239 {\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}} #include<stdio.h> #include<iostream> using namespace std; int main(void) { //本程序每四位数输出，如果请求计算的位数不是4的整数倍，最后输出可能会少1~3位数 long a[2]={956,80},b[2]={57121,25},i=0,j,k,p,q,r,s=2,t,u,v,N,M=10000; printf("%9cMachin%6cpi=16arctan(1/5)-4arctan(1/239)\nPlease input a number.\n",32,32); cin>>N,N=N/4+3; long *pi=new long[N],*e=new long[N]; while(i<N)pi[i++]=0; while(--s+1) { for(*e=a[k=s],i=N;--i;)e[i]=0; for(q=1;j=i-1,i<N;e[i]?0:++i,q+=2,k=!k) for(r=v=0;++j<N;pi[j]+=k?u:-u)u=(t=v*M+(e[j]=(p=r*M+e[j])/b[s]))/q,r=p%b[s],v=t%q; } while(--i)(pi[i]=(t=pi[i]+s)%M)<0?pi[i]+=M,s=t/M-1:s=t/M; for(cout<<"3.";++i<N-2;)printf("%04ld",pi[i]); delete []pi,delete []e,cin.ignore(),cin.ignore(); return 0; } 埃里克·韦斯坦因. Machin-like formulas. MathWorld.  The constant π （页面存档备份，存于互联网档案馆） Machin's Merit （页面存档备份，存于互联网档案馆） at MathPages Archimedes' constant pi - Machin's formula gives a proof for the John Machin`s formula GUIDORIZZI, Hamilton Luiz. Um Curso de Cálculo, vol. 4. 3ª edição. Rio de Janeiro: Livros Técnicos e Científicos Editora, 1999.