Puneet Varma (Editor)

Machin like formula

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Machin-like formula

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:

Contents

π 4 = 4 arctan 1 5 arctan 1 239

which he used to compute π to 100 decimal places.

Machin-like formulas have the form

where a n and b n are positive integers such that a n < b n , c n is a signed non-zero integer, and c 0 is a positive integer.

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

Derivation

The following equations were derived in Angle addition formula:

sin ( α + β ) = sin α cos β + cos α sin β cos ( α + β ) = cos α cos β sin α sin β

Algebraic manipulation of these equations yields the following:

if

π 2 < arctan a 1 b 1 + arctan a 2 b 2 < π 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:

2 arctan 1 5 4 arctan 1 5 4 arctan 1 5 π 4 π 4 = 4 arctan 1 5 arctan 1 239

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

( b 1 + a 1 i ) ( b 2 + a 2 i ) = b 1 b 2 + a 2 b 1 i + a 1 b 2 i a 1 a 2

The angle associated with a complex number ( b n + a n i ) is given by:

arctan a n b n

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

arctan 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:

c n arctan a n b n

is the angle associated with:

( b n + a n i ) c n

Equation 1 can be re-written as:

k ( 1 + i ) c 0 = n = 1 N ( b n + a n i ) c n

Here 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 ( a + b i ) is given by arctan b a and, when one multiplies complex numbers, one adds their angles. If a=b then arctan b a is 45 degrees or π 4 radians. This means that if the real part and complex part are equal then the arctangent will equal π 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 ( 2 + i ) and ( 3 + i ) . If we multiply these out we will get ( 5 + 5 i ) . Therefore arctan 1 2 + arctan 1 3 = π 4 .

If you want to use complex numbers to show that π 4 = 4 arctan 1 5 arctan 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 ( 5 + i ) 4 ( 239 + i ) = 2 2 ( 13 4 ) ( 1 + i ) and since the real part and imaginary part are equal then, 4 arctan 1 5 arctan 1 239 = π 4

Two-term formulas

In the special case where a n = 1 , there are exactly four solutions having only two terms. These are Euler's:

π 4 = arctan 1 2 + arctan 1 3

Hermann's:

π 4 = 2 arctan 1 2 arctan 1 7

Hutton's (or Vega's):

π 4 = 2 arctan 1 3 + arctan 1 7

and Machin's:

π 4 = 4 arctan 1 5 arctan 1 239

In the general case, where the value of a n is not restricted, there are infinitely many other solutions. For example:

Example

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

a r e a ( P O N ) = a r e a ( M O F ) = π × M O F 2 π = M E F = arctan 1 2 a r e a ( P O M ) = a r e a ( N O F ) = arctan 1 3 a r e a ( P O F ) = π 4 = arctan 1 2 + arctan 1 3 a r e a ( M O N ) = arctan 1 7 arctan 1 2 = arctan 1 3 + arctan 1 7

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:

π 4 = 12 arctan 1 49 + 32 arctan 1 57 5 arctan 1 239 + 12 arctan 1 110443 Kikuo Takano (1982). π 4 = 44 arctan 1 57 + 7 arctan 1 239 12 arctan 1 682 + 24 arctan 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:

π 4 = 36462 arctan 1 390112 + 135908 arctan 1 485298 + 274509 arctan 1 683982 39581 arctan 1 1984933 + 178477 arctan 1 2478328 114569 arctan 1 3449051 146571 arctan 1 18975991 + 61914 arctan 1 22709274 69044 arctan 1 24208144 89431 arctan 1 201229582 43938 arctan 1 2189376182 π 4 = 36462 arctan 1 51387 + 26522 arctan 1 485298 + 19275 arctan 1 683982 3119 arctan 1 1984933 3833 arctan 1 2478328 5183 arctan 1 3449051 37185 arctan 1 18975991 11010 arctan 1 22709274 + 3880 arctan 1 24208144 16507 arctan 1 201229582 7476 arctan 1 2189376182

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

π 4 = 183 arctan 1 239 + 32 arctan 1 1023 68 arctan 1 5832 + 12 arctan 1 110443 12 arctan 1 4841182 100 arctan 1 6826318 黃見利 (Hwang Chien-Lih) (1997). π 4 = 183 arctan 1 239 + 32 arctan 1 1023 68 arctan 1 5832 + 12 arctan 1 113021 100 arctan 1 6826318 12 arctan 1 33366019650 + 12 arctan 1 43599522992503626068 黃見利 (Hwang Chien-Lih) (2003). π 4 = 83 arctan 1 107 + 17 arctan 1 1710 22 arctan 1 103697 24 arctan 1 2513489 44 arctan 1 18280007883 + 12 arctan 1 7939642926390344818 + 22 arctan 1 3054211727257704725384731479018 (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 N d be the number of digits to which π is to be calculated.

Let N t be the number of terms in the Taylor series (see equation 4).

Let u n be the amount of time spent on each digit (for each term in the Taylor series).

The Taylor series will converge when:

( ( b n a n ) 2 ) N t = 10 N d

Thus:

N t = N d ln 10 2 ln b n a n

For the first term in the Taylor series, all 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:

N d N t 2

The run time is given by:

t i m e = u n N d N t 2

Combining equations, the run time is given by:

t i m e = u n N d 2 ln 10 4 ln b n a n = k u n ln b n a n

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

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

t i m e = n = 1 N u n ln b n a n

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:

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. u n is defined to be four.

Note, however, that if a n is equal to one, then step one can be skipped. The loop only takes three units of time. u n is defined to be three.

As an example, consider the equation:

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

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:

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 a n and 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

Machin-like formula Wikipedia