# Machin-like formula

(Redirected from Machin-like formulas)

In mathematics, Machin-like formulae are a popular technique for computing π to a large number of digits. They are generalizations of John Machin's formula from 1706:

${\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}}$

which he used to compute π to 100 decimal places.[1]

Machin-like formulas have the form

${\displaystyle c_{0}{\frac {\pi }{4}}=\sum _{n=1}^{N}c_{n}\arctan {\frac {a_{n}}{b_{n}}}}$

(1)

where ${\displaystyle a_{n}}$ and ${\displaystyle b_{n}}$ are positive integers such that ${\displaystyle a_{n}, ${\displaystyle c_{n}}$ is a signed non-zero integer, and ${\displaystyle c_{0}}$ is a positive integer.

These formulae are used in conjunction with the Taylor series expansion for arctangent:

${\displaystyle \arctan x=\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{2n+1}}x^{2n+1}=x-{\frac {x^{3}}{3}}+{\frac {x^{5}}{5}}-{\frac {x^{7}}{7}}+...}$

(4)

## Derivation

The following equations were derived in Angle addition formula:

${\displaystyle \sin(\alpha +\beta )=\sin \alpha \cos \beta +\cos \alpha \sin \beta }$
${\displaystyle \cos(\alpha +\beta )=\cos \alpha \cos \beta -\sin \alpha \sin \beta }$

Algebraic manipulation of these equations yields the following:

${\displaystyle \arctan {\frac {a_{1}}{b_{1}}}+\arctan {\frac {a_{2}}{b_{2}}}=\arctan {\frac {a_{1}b_{2}+a_{2}b_{1}}{b_{1}b_{2}-a_{1}a_{2}}},}$

(2)

if

${\displaystyle -{\frac {\pi }{2}}<\arctan {\frac {a_{1}}{b_{1}}}+\arctan {\frac {a_{2}}{b_{2}}}<{\frac {\pi }{2}}.}$

All of the Machin-like formulae can be derived by repeated application of equation 2. As an example, we show the derivation of Machin's original formula:

${\displaystyle 2\arctan {\frac {1}{5}}}$
${\displaystyle =\arctan {\frac {1}{5}}+\arctan {\frac {1}{5}}}$
${\displaystyle =\arctan {\frac {1*5+1*5}{5*5-1*1}}}$
${\displaystyle =\arctan {\frac {10}{24}}}$
${\displaystyle =\arctan {\frac {5}{12}}}$
${\displaystyle 4\arctan {\frac {1}{5}}}$
${\displaystyle =2\arctan {\frac {1}{5}}+2\arctan {\frac {1}{5}}}$
${\displaystyle =\arctan {\frac {5}{12}}+\arctan {\frac {5}{12}}}$
${\displaystyle =\arctan {\frac {5*12+5*12}{12*12-5*5}}}$
${\displaystyle =\arctan {\frac {120}{119}}}$
${\displaystyle 4\arctan {\frac {1}{5}}-{\frac {\pi }{4}}}$
${\displaystyle =4\arctan {\frac {1}{5}}-\arctan {\frac {1}{1}}}$
${\displaystyle =4\arctan {\frac {1}{5}}+\arctan {\frac {-1}{1}}}$
${\displaystyle =\arctan {\frac {120}{119}}+\arctan {\frac {-1}{1}}}$
${\displaystyle =\arctan {\frac {120*1+(-1)*119}{119*1-120*(-1)}}}$
${\displaystyle =\arctan {\frac {1}{239}}}$
${\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}}$

An insightful way to visualize equation 2 is to picture what happens when two complex numbers are multiplied together:

${\displaystyle (b_{1}+a_{1}i)*(b_{2}+a_{2}i)}$
${\displaystyle =b_{1}b_{2}+a_{2}b_{1}i+a_{1}b_{2}i-a_{1}a_{2}}$

${\displaystyle =(b_{1}b_{2}-a_{1}a_{2})+(a_{1}b_{2}+a_{2}b_{1})*i}$

(3)

The angle associated with a complex number ${\displaystyle (b_{n}+a_{n}i)}$ is given by:

${\displaystyle \arctan {\frac {a_{n}}{b_{n}}}}$

Thus, in equation 3, the angle associated with the product is:

${\displaystyle \arctan {\frac {a_{1}b_{2}+a_{2}b_{1}}{b_{1}b_{2}-a_{1}a_{2}}}}$

Note that this is the same expression as occurs in equation 2. Thus equation 2 can be interpreted as saying that the act of multiplying two complex numbers is equivalent to adding their associated angles (see multiplication of complex numbers).

The expression:

${\displaystyle c_{n}\arctan {\frac {a_{n}}{b_{n}}}}$

is the angle associated with:

${\displaystyle (b_{n}+a_{n}i)^{c_{n}}}$

Equation 1 can be re-written as:

${\displaystyle k*(1+i)^{c_{0}}=\prod _{n=1}^{N}(b_{n}+a_{n}i)^{c_{n}}}$

Here ${\displaystyle k}$ is an arbitrary constant that accounts for the difference in magnitude between the vectors on the two sides of the equation. The magnitudes can be ignored, only the angles are significant.

### Using complex numbers

Other formulas may be generated using complex numbers. For example the angle of a complex number ${\displaystyle (a+bi)}$ is given by ${\displaystyle \arctan {\frac {b}{a}}}$ and, when one multiplies complex numbers, one adds their angles. If a=b then ${\displaystyle \arctan {\frac {b}{a}}}$ is 45 degrees or ${\displaystyle {\frac {\pi }{4}}}$ radians. This means that if the real part and complex part are equal then the arctangent will equal ${\displaystyle {\frac {\pi }{4}}}$. Since the arctangent of one has a very slow convergence rate if we find two complex numbers that when multiplied will result in the same real and imaginary part we will have a Machin-like formula. An example is ${\displaystyle (2+i)}$ and ${\displaystyle (3+i)}$. If we multiply these out we will get ${\displaystyle (5+5i)}$. Therefore ${\displaystyle \arctan {\frac {1}{2}}+\arctan {\frac {1}{3}}={\frac {\pi }{4}}}$.

If you want to use complex numbers to show that ${\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}}$ you first must know that when multiplying angles you put the complex number to the power of the number that you are multiplying by. So ${\displaystyle (5+i)^{4}(-239+i)=-2^{2}(13^{4})(1+i)}$ and since the real part and imaginary part are equal then, ${\displaystyle 4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}={\frac {\pi }{4}}}$

## Two-term formulas

In the special case where ${\displaystyle a_{n}}$ is one, there are exactly four solutions having only two terms.[2] These are Euler's:

${\displaystyle {\frac {\pi }{4}}=\arctan {\frac {1}{2}}+\arctan {\frac {1}{3}}}$

Hermann's:

${\displaystyle {\frac {\pi }{4}}=2\arctan {\frac {1}{2}}-\arctan {\frac {1}{7}}}$

Hutton's (or Vega's[2]):

${\displaystyle {\frac {\pi }{4}}=2\arctan {\frac {1}{3}}+\arctan {\frac {1}{7}}}$

and Machin's:

${\displaystyle {\frac {\pi }{4}}=4\arctan {\frac {1}{5}}-\arctan {\frac {1}{239}}}$

In the general case, where the value of ${\displaystyle a_{n}}$ is not restricted, there are infinitely many other solutions. For example:

${\displaystyle {\frac {\pi }{4}}=22\arctan {\frac {24478}{873121}}+17\arctan {\frac {685601}{69049993}}}$

(5)

### Example

The adjacent diagram demonstrates the relationship between the arctangents and their areas. From the diagram, we have the following:

{\displaystyle {\begin{aligned}{\rm {area}}(PON)&={\rm {area}}(MOF)=\pi \times {\frac {\angle MOF}{2\pi }}=\angle MEF=\arctan {1 \over 2}\\{\rm {area}}(POM)&={\rm {area}}(NOF)=\arctan {1 \over 3}\\{\rm {area}}(POF)&={\pi \over 4}=\arctan {1 \over 2}+\arctan {1 \over 3}\\{\rm {area}}(MON)&=\arctan {1 \over 7}\\\arctan {1 \over 2}&=\arctan {1 \over 3}+\arctan {1 \over 7}\end{aligned}}}

## More terms

The 2002 record for digits of π, 1,241,100,000,000, was obtained by Yasumasa Kanada of Tokyo University. The calculation was performed on a 64-node Hitachi supercomputer with 1 terabyte of main memory, performing 2 trillion operations per second. The following two equations were both used:

${\displaystyle {\frac {\pi }{4}}=12\arctan {\frac {1}{49}}+32\arctan {\frac {1}{57}}-5\arctan {\frac {1}{239}}+12\arctan {\frac {1}{110443}}}$
Kikuo Takano (1982).
${\displaystyle {\frac {\pi }{4}}=44\arctan {\frac {1}{57}}+7\arctan {\frac {1}{239}}-12\arctan {\frac {1}{682}}+24\arctan {\frac {1}{12943}}}$
F. C. M. Störmer (1896).

The most efficient currently known Machin-like formula pair discovered by 黃見利 (Hwang Chien-Lih) (2004) for computing π are:

{\displaystyle {\begin{aligned}{\frac {\pi }{4}}=&36462\arctan {\frac {1}{390112}}+135908\arctan {\frac {1}{485298}}+274509\arctan {\frac {1}{683982}}\\&-39581\arctan {\frac {1}{1984933}}+178477\arctan {\frac {1}{2478328}}-114569\arctan {\frac {1}{3449051}}\\&-146571\arctan {\frac {1}{18975991}}+61914\arctan {\frac {1}{22709274}}-69044\arctan {\frac {1}{24208144}}\\&-89431\arctan {\frac {1}{201229582}}-43938\arctan {\frac {1}{2189376182}}\\\end{aligned}}}
{\displaystyle {\begin{aligned}{\frac {\pi }{4}}=&36462\arctan {\frac {1}{51387}}+26522\arctan {\frac {1}{485298}}+19275\arctan {\frac {1}{683982}}\\&-3119\arctan {\frac {1}{1984933}}-3833\arctan {\frac {1}{2478328}}-5183\arctan {\frac {1}{3449051}}\\&-37185\arctan {\frac {1}{18975991}}-11010\arctan {\frac {1}{22709274}}+3880\arctan {\frac {1}{24208144}}\\&-16507\arctan {\frac {1}{201229582}}-7476\arctan {\frac {1}{2189376182}}\\\end{aligned}}}

The most efficient currently known Machin-like formulas for computing π are:

{\displaystyle {\begin{aligned}{\frac {\pi }{4}}=&183\arctan {\frac {1}{239}}+32\arctan {\frac {1}{1023}}-68\arctan {\frac {1}{5832}}\\&+12\arctan {\frac {1}{110443}}-12\arctan {\frac {1}{4841182}}-100\arctan {\frac {1}{6826318}}\\\end{aligned}}}

{\displaystyle {\begin{aligned}{\frac {\pi }{4}}=&183\arctan {\frac {1}{239}}+32\arctan {\frac {1}{1023}}-68\arctan {\frac {1}{5832}}\\&+12\arctan {\frac {1}{113021}}-100\arctan {\frac {1}{6826318}}\\&-12\arctan {\frac {1}{33366019650}}+12\arctan {\frac {1}{43599522992503626068}}\\\end{aligned}}}

{\displaystyle {\begin{aligned}{\frac {\pi }{4}}=&83\arctan {\frac {1}{107}}+17\arctan {\frac {1}{1710}}-22\arctan {\frac {1}{103697}}\\&-24\arctan {\frac {1}{2513489}}-44\arctan {\frac {1}{18280007883}}\\&+12\arctan {\frac {1}{7939642926390344818}}\\&+22\arctan {\frac {1}{3054211727257704725384731479018}}\\\end{aligned}}}
(M.Wetherfield) (2004).

## Efficiency

It is not the goal of this section to estimate the actual run time of any given algorithm. Instead, the intention is merely to devise a relative metric by which two algorithms can be compared against each other.

Let ${\displaystyle N_{d}}$ be the number of digits to which ${\displaystyle \pi }$ is to be calculated.

Let ${\displaystyle N_{t}}$ be the number of terms in the Taylor series (see equation 4).

Let ${\displaystyle u_{n}}$ be the amount of time spent on each digit (for each term in the Taylor series).

The Taylor series will converge when:

${\displaystyle \left(\left({\frac {b_{n}}{a_{n}}}\right)^{2}\right)^{N_{t}}=10^{N_{d}}}$

Thus:

${\displaystyle N_{t}=N_{d}\quad {\frac {\ln 10}{2\ln {\frac {b_{n}}{a_{n}}}}}}$

For the first term in the Taylor series, all ${\displaystyle N_{d}}$ digits must be processed. In the last term of the Taylor series, however, there's only one digit remaining to be processed. In all of the intervening terms, the number of digits to be processed can be approximated by linear interpolation. Thus the total is given by:

${\displaystyle {\frac {N_{d}N_{t}}{2}}}$

The run time is given by:

${\displaystyle time={\frac {u_{n}N_{d}N_{t}}{2}}}$

Combining equations, the run time is given by:

${\displaystyle time={\frac {u_{n}{N_{d}}^{2}\ln 10}{4\ln {\frac {b_{n}}{a_{n}}}}}={\frac {ku_{n}}{\ln {\frac {b_{n}}{a_{n}}}}}}$

Where ${\displaystyle k}$ is a constant that combines all of the other constants. Since this is a relative metric, the value of ${\displaystyle k}$ can be ignored.

The total time, across all the terms of equation 1, is given by:

${\displaystyle time=\sum _{n=1}^{N}{\frac {u_{n}}{\ln {\frac {b_{n}}{a_{n}}}}}}$

${\displaystyle u_{n}}$ cannot be modelled accurately without detailed knowledge of the specific software. Regardless, we present one possible model.

The software spends most of its time evaluating the Taylor series from equation 4. The primary loop can be summarized in the following pseudo code:

${\displaystyle 1:\quad term\quad *=\quad {a_{n}}^{2}}$
${\displaystyle 2:\quad term\quad /=\quad -{b_{n}}^{2}}$
${\displaystyle 3:\quad tmp\quad =\quad term\quad /\quad (2*n+1)}$
${\displaystyle 4:\quad sum\quad +=\quad tmp}$

In this particular model, it is assumed that each of these steps takes approximately the same amount of time. Depending on the software used, this may be a very good approximation or it may be a poor one.

The unit of time is defined such that one step of the pseudo code corresponds to one unit. To execute the loop, in its entirety, requires four units of time. ${\displaystyle u_{n}}$ is defined to be four.

Note, however, that if ${\displaystyle a_{n}}$ is equal to one, then step one can be skipped. The loop only takes three units of time. ${\displaystyle u_{n}}$ is defined to be three.

As an example, consider the equation:

${\displaystyle {\frac {\pi }{4}}=44\arctan {\frac {74684}{14967113}}+139\arctan {\frac {1}{239}}-12\arctan {\frac {20138}{15351991}}}$

(6)

The following table shows the estimated time for each of the terms:

${\displaystyle a_{n}}$ ${\displaystyle b_{n}}$ ${\displaystyle {\frac {b_{n}}{a_{n}}}}$ ${\displaystyle \ln {\frac {b_{n}}{a_{n}}}}$ ${\displaystyle u_{n}}$ ${\displaystyle time}$
74684 14967113 200.41 5.3003 4 0.75467
1 239 239.00 5.4765 3 0.54780
20138 15351991 762.34 6.6364 4 0.60274

The total time is 0.75467 + 0.54780 + 0.60274 = 1.9052

Compare this with equation 5. The following table shows the estimated time for each of the terms:

${\displaystyle a_{n}}$ ${\displaystyle b_{n}}$ ${\displaystyle {\frac {b_{n}}{a_{n}}}}$ ${\displaystyle \ln {\frac {b_{n}}{a_{n}}}}$ ${\displaystyle u_{n}}$ ${\displaystyle time}$
24478 873121 35.670 3.5743 4 1.1191
685601 69049993 100.71 4.6123 4 0.8672

The total time is 1.1191 + 0.8672 = 1.9863

The conclusion, based on this particular model, is that equation 6 is slightly faster than equation 5, regardless of the fact that equation 6 has more terms. This result is typical of the general trend. The dominant factor is the ratio between ${\displaystyle a_{n}}$ and ${\displaystyle b_{n}}$. In order to achieve a high ratio, it is necessary to add additional terms. Often, there is a net savings in time.

## References

1. ^ Beckmann, Petr (1971). A History Of Pi. USA: The Golem Press. p. 102. ISBN 0-88029-418-3.
2. ^ a b Carl Størmer (1899). "Solution complète en nombres entiers de l'équation ${\displaystyle m\arctan {\frac {1}{x}}+n\arctan {\frac {1}{y}}=k{\frac {\pi }{4}}}$" (PDF). Bulletin de la S.M.F. (in French). 27: 160–170.