Machin-like formula

From testwiki
Revision as of 22:51, 31 January 2025 by 2a00:1370:81a2:434d:20df:64e7:6027:5229 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description In mathematics, Machin-like formulas are a popular technique for computing [[pi|Template:Pi]] (the ratio of the circumference to the diameter of a circle) to a large number of digits. They are generalizations of John Machin's formula from 1706:

π4=4arctan15arctan1239

which he used to compute Template:Pi to 100 decimal places.[1][2]

Machin-like formulas have the form

Template:NumBlk

where c0 is a positive integer, cn are signed non-zero integers, and an and bn are positive integers such that an<bn.

These formulas are used in conjunction with Gregory's series, the Taylor series expansion for arctangent:

Template:NumBlk

Derivation

The angle addition formula for arctangent asserts that

Template:NumBlk

if π2<arctana1b1+arctana2b2<π2. All of the Machin-like formulas can be derived by repeated application of equation Template:EquationNote. As an example, we show the derivation of Machin's original formula one has: 2arctan15=arctan15+arctan15=arctan15+155511=arctan1024=arctan512, and consequently 4arctan15=2arctan15+2arctan15=arctan512+arctan512=arctan512+512121255=arctan120119. Therefore also 4arctan15π4=4arctan15arctan11=4arctan15+arctan11=arctan120119+arctan11=arctan1201+(1)1191191120(1)=arctan1239, and so finally π4=4arctan15arctan1239.

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

(b1+a1i)(b2+a2i)
=b1b2+a2b1i+a1b2ia1a2

Template:NumBlk

The angle associated with a complex number (bn+ani) is given by:

arctananbn

Thus, in equation Template:EquationNote, the angle associated with the product is:

arctana1b2+a2b1b1b2a1a2

Note that this is the same expression as occurs in equation Template:EquationNote. Thus equation Template:EquationNote can be interpreted as saying that multiplying two complex numbers means adding their associated angles (see multiplication of complex numbers).

The expression:

cnarctananbn

is the angle associated with:

(bn+ani)cn

Equation Template:EquationNote can be re-written as:

k(1+i)c0=n=1N(bn+ani)cn

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.[3] For example, the angle of a complex number (a+bi) is given by arctanba and, when one multiplies complex numbers, one adds their angles. If a=b then arctanba 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+5i). Therefore, arctan12+arctan13=π4.

If you want to use complex numbers to show that π4=4arctan15arctan1239, you first must know that raising a complex number to a real power k implies multiplying its anomaly (angle) by k, and that the anomaly of the product of two complex numbers is equal to the sum of their anomalies. Since it can by shown, by doing the calculation, that (5+i)4(239i)=(1+i)22134, i.e. that the real and imaginary parts of both sides are equal, and since that equality is equivalent to: 4arctan15arctan1239=π4, the latter equality is also demonstrated.

Lehmer's measure

One of the most important parameters that characterize computational efficiency of a Machin-like formula is the Lehmer's measure, defined as[4][5]

λ=n=1N1log10(bn/an).

In order to obtain the Lehmer's measure as small as possible, it is necessary to decrease the ratio of positive integers an/bn in the arctangent arguments and to minimize the number of the terms in the Machin-like formula. Nowadays at an=1 the smallest known Lehmer's measure is λ1.51244 due to H. Chien-Lih (1997),[6] whose Machin-like formula is shown below. It is very common in the Machin-like formulas when all numerators an=1.

Two-term formulas

In the special case where the numerator an=1, there are exactly four solutions having only two terms.[7][8] All four were found by John Machin in 1705–1706, but only one of them became widely known when it was published in William Jones's book Synopsis Palmariorum Matheseos, so the other three are often attributed to other mathematicians. These are

Euler's 1737 (known to Machin 1706):[9][10]

π4=arctan12+arctan13

Hermann's 1706 (known to Machin 1706):[11][10]

π4=2arctan12arctan17

Hutton's or Vega's (known to Machin 1706):[8][10]

π4=2arctan13+arctan17

and Machin's 1706:[1][10]

π4=4arctan15arctan1239 .

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

π4=22arctan128+arctan174450748218032836685456512798646395734210062276153190241239

or Template:NumBlk

Example

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

area(PON)=area(MOF)=π×MOF2π=MEF=arctan12area(POM)=area(NOF)=arctan13area(POF)=π4=area(PON)+area(NOF)=arctan12+arctan13area(MON)=arctan17area(PON)=arctan12=area(POM)+area(MON)=arctan13+arctan17,

a relation which can also be found by means of
the following calculation within the complex numbers

(3+i)(7+i)=211+(3+7)i=10(2+i).

More terms

The 2002 record for digits of Template:Pi, 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=12arctan149+32arctan1575arctan1239+12arctan1110443
Kikuo Takano (1982).
π4=44arctan157+7arctan123912arctan1682+24arctan112943
F. C. M. Størmer (1896).

Two equations are used so that one can check they both give the same result; it is helpful if the equations used to cross-check the result reuse some of the arctangent arguments (note the reuse of 57 and 239 above), so that the process can be simplified by only computing them once, but not all of them, in order to preserve their independence.

Machin-like formulas for Template:Pi can be constructed by finding a set of m integers bn,n=1..m, where all the prime factorisations of Template:Tmath, taken together, use a number of distinct primes m, and then using either linear algebra or the LLL basis-reduction algorithm to construct linear combinations of arctangents of 1bn. For example, in the Størmer formula above, we have

572+1=25313
2392+1=2134
6822+1=53612
129432+1=25413361

so four expressions whose factors are powers of only the four primes 2, 5, 13 and 61.

In 1993 Jörg Uwe Arndt[12] found the 11-term formula:

π4=36462arctan1390112+135908arctan1485298+274509arctan168398239581arctan11984933+178477arctan12478328114569arctan13449051146571arctan118975991+61914arctan12270927469044arctan12420814489431arctan120122958243938arctan12189376182

using the set of 11 primes {2,5,13,17,29,37,53,61,89,97,101}.

Another formula where 10 of the arctan-arguments are the same as above has been discovered by Hwang Chien-Lih (黃見利) (2004), so it is easier to check they both give the same result:

π4=36462arctan151387+26522arctan1485298+19275arctan16839823119arctan119849333833arctan124783285183arctan1344905137185arctan11897599111010arctan122709274+3880arctan12420814416507arctan12012295827476arctan12189376182

You will note that these formulas reuse all the same arctangents after the first one. They are constructed by looking for numbers where Template:Tmath is divisible only by primes less than 102.

Template:AnchorThe most efficient currently known Machin-like formula for computing Template:Pi is:

π4=183arctan1239+32arctan1102368arctan15832+12arctan111044312arctan14841182100arctan16826318
(Hwang Chien-Lih, 1997)

where the set of primes is {2,5,13,229,457,1201}.

A further refinement is to use "Todd's Process", as described in;[5] this leads to results such as

π4=183arctan1239+32arctan1102368arctan15832+12arctan1113021100arctan1682631812arctan133366019650+12arctan143599522992503626068
(Hwang Chien-Lih, 2003)

where the large prime 834312889110521 divides the Template:Tmath of the last two indices.
M. Wetherfield found 2004

π4=83arctan1107+17arctan1171022arctan110369724arctan1251348944arctan118280007883+12arctan17939642926390344818+22arctan13054211727257704725384731479018.

In Pi Day 2024, Matt Parker along with 400 volunteers used the following formula to hand calculate π:

π4=1587arctan12852+295arctan14193+593arctan14246+359arctan139307+481arctan155603+625arctan1211050708arctan1390112

It was the biggest hand calculation of π in a century. [13]

More methods

There are further methods to derive Machin-like formulas for π with reciprocals of integers. One is given by the following formula:[14]

π4=2k1arctan1Ak+m=1Marctan1Bk,m+arctan1Bk,M+1,

where

a0:=0

and recursively

ak:=2+ak1,Ak:=ak2ak1

and

Bk,1:=2(Ak+iAki)2k1ii

and recursively

Bk,m:=1+Bk,m1Bk,m1Bk,m1Bk,m1.

E.g., for k=4 and M=5 we get:

π4=8arctan110arctan184arctan121342arctan1991268848arctan1193018008592515208050arctan1197967899896401851763240424238758988350338arctan1117573868168175352930277752844194126767991915008537018836932014293678271636885792397

This is verified by the following MuPAD code:

z:=(10+I)^8*(84-I)*(21342-I)*(991268848-I)*(193018008592515208050-I)\
  *(197967899896401851763240424238758988350338-I)\
  *(117573868168175352930277752844194126767991915008537018836932014293678271636885792397-I):
Re(z)-Im(z)
0

meaning

z:=(10+i)8(84i)(21342i)(991268848i)(193018008592515208050i)(197967899896401851763240424238758988350338i)(117573868168175352930277752844194126767991915008537018836932014293678271636885792397i)=(1+i)(z).

Efficiency

For large computations of Template:Pi, the binary splitting algorithm can be used to compute the arctangents much, much more quickly than by adding the terms in the Taylor series naively one at a time. In practical implementations such as y-cruncher, there is a relatively large constant overhead per term plus a time proportional to 1/logbn, and a point of diminishing returns appears beyond three or four arctangent terms in the sum; this is why the supercomputer calculation above used only a four-term version.

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 Nd be the number of digits to which Template:Pi is to be calculated.

Let Nt be the number of terms in the Taylor series (see equation Template:EquationNote).

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

The Taylor series will converge when:

((bnan)2)Nt=10Nd

Thus:

Nt=Ndln102lnbnan

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

NdNt2

The run time is given by:

𝚝𝚒𝚖𝚎=unNdNt2

Combining equations, the run time is given by:

𝚝𝚒𝚖𝚎=unNd2ln104lnbnan=kunlnbnan

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

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

𝚝𝚒𝚖𝚎=n=1Nunlnbnan

un 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 Template:EquationNote. The primary loop can be summarized in the following pseudo code:

1: term *= an2
2: term /= bn2
3: tmp = term / (2*n+1)
4: sum += 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. un is defined to be four.

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

As an example, consider the equation:

Template:NumBlk

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

an bn bnan lnbnan un time
Template:Val Template:Val Template:Val Template:Val Template:Val Template:Val
Template:Val Template:Val Template:Val Template:Val Template:Val Template:Val
Template:Val Template:Val Template:Val Template:Val Template:Val Template:Val

The total time is 0.75467 + 0.54780 + 0.60274 = 1.9052

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

an bn bnan lnbnan un time
Template:Val Template:Val Template:Val Template:Val Template:Val Template:Val
Template:Val Template:Val Template:Val Template:Val Template:Val Template:Val

The total time is 1.1191 + 0.8672 = 1.9863

The conclusion, based on this particular model, is that equation Template:EquationNote is slightly faster than equation Template:EquationNote, regardless of the fact that equation Template:EquationNote has more terms. This result is typical of the general trend. The dominant factor is the ratio between an and bn. In order to achieve a high ratio, it is necessary to add additional terms. Often, there is a net savings in time.

References

Template:Reflist