← RoseCode

ROSECODE 449

Machin Like Formulae

Philippe_57721 · Programming ·

One of the most famous formulae for computing π is
π4=4.arctan(15)arctan(1239) due to John Machin (1706) who used it to compute 100 decimal places.

We can rewrite it as:
arctan(1/239)=arctan(1/1)+4.arctan(1/5)

It turns out that many integers like 239 have an inverse which can be decomposed as a linear combination of Arctan of inverses.

A few examples:
arctan(13)=arctan(1)arctan(12)
arctan(17)=arctan(1)+2.arctan(12)
arctan(18)=arctan(1)arctan(12)arctan(1/5)
arctan(113)=arctan(1)arctan(12)arctan(1/4)
arctan(117)=arctan(1)+2.arctan(12)arctan(1/12)
arctan(118)=arctan(1)2.arctan(12)+arctan(1/5)
arctan(121)=arctan(1/4)arctan(1/5)
arctan(130)=arctan(1)arctan(12)arctan(1/4)arctan(1/23)
arctan(131)=arctan(1/5)arctan(1/6)
arctan(132)=arctan(1)+2.arctan(12)arctan(1/9)

The irreductible numbers, those which cannot be decomposed this way are called Störmer numbers.
Thus, the inverse of every number which is not a Störmer number can be expressed as a linear combinaison of Arctan of inverse of smaller irreductible integers.

What makes John Machin's formula particularily efficient is the fact that it contains few terms and the numbers involved are not too small: the convergence of the Arctan serie is then quite fast.

Let's define the cost of a formula as the sum of the inverse of the distinct integers without 1.
C(32)=12+19+132=0.642361

Numbers like 21 or 31 are not suitable for a computation of π as they do not include the number 1 in their decomposition, their cost will be infinity.

What are the 10 most efficient numbers less than 20000?

Answer format: Comma separated list in ascending order of cost.

Example: 41,46,75,17,32,7,68,93,43,57 (for numbers less than 100)

C(41)=0.6077235772arctan(141)=arctan(1)2.arctan(12)+2.arctan(112)
C(46)=0.6421095008arctan(146)=arctan(1)+2.arctan(12)arctan(112)arctan(127)
C(75)=0.6421212121arctan(175)=arctan(1)+2.arctan(12)arctan(112)arctan(122)
C(17)=0.6421568627arctan(117)=arctan(1)+2.arctan(12)arctan(112)
C(32)=0.6423611111arctan(132)=arctan(1)+2.arctan(12)arctan(19)
C(7)=0.6428571429arctan(17)=arctan(1)+2.arctan(12)
C(68)=0.6813725490arctan(168)=2.arctan(1)3.arctan(12)arctan(16)
C(93)=0.6899193548arctan(193)=arctan(1)2.arctan(12)+arctan(16)arctan(180)
C(43)=0.6899224806arctan(143)=arctan(1)2.arctan(12)+arctan(16) C(57)=0.7175438596arctan(157)=2.arctan(1)+3.arctan(12)+arctan(15)

[My timing : < 10 sec]