Abstract
In this work, we consider the properties of the two-term Machin-like formula and develop an algorithm for computing digits of by using its rational approximation. In this approximation, both terms are constructed by using a representation of in the binary form. This approach provides the squared convergence in computing digits of without any trigonometric functions and surd numbers. The Mathematica codes showing some examples are presented.
1. Preliminaries
In 1876, English astronomer and mathematician John Machin demonstrated an efficient method to compute the digits of by using his famous discovery [1,2,3,4]
In particular, due to the relatively rapid convergence of this formula, he was the first to compute more than 100 digits of . Nowadays, the equations of the kind
where and are either integers or rational numbers, are named after him as the Machin-like formulas for [1,2,3,4].
Theorem 1 below shows the arctangent Formula (2) for . We can use this equation as a starting point to generate the two-term Machin-like formula for of the kind
where and . Further, we will show the significance of the multiplier in this formula.
Theorem 1.
There is a formula for π at any integer [5]:
where and are nested radicals.
Proof of Theorem 1.
Since
from the identity
it follows, by induction, that
Therefore, using
we obtain
and Equation (2) follows. □
Lemma 1.
There is a limit such that [6]
Proof of Lemma 1.
Let
Then, we can write
or
or
Solving this quadratic equation leads to two solutions and . Since cannot be negative, we came to the conclusion that
Consequently, this gives
Lemma 2 and its proof below show how Equation (2) can be transformed into the two-term Machin-like formula for [7].
Lemma 2.
In the following equation
the value is always a rational number.
Proof of Lemma 2.
It is convenient to define
It is not difficult to see by substitution that the following formula [7]
is a solution of Equation (6). Since k is a positive integer greater than or equal to 1, we can see that the real and imaginary parts of the expression
cannot be an irrational number if is an integer. This means that the real and imaginary parts of the value must be both rational. Since the first arctangent term of Equation (4) is a real number, the second arctangent term is also a real number. Therefore, we conclude that the imaginary part of the value is equal to zero. This completes the proof. □
This is not the only method to generate the two-term Machin-like formulas for of kind (4). Recently, Gasull et al. proposed a different method to derive the same equation (see Table 2 in [8]). Lemma 3 and its proof below shows how Equation (4) can be represented in a trigonometric form [7].
Lemma 3.
Equation (4) can be expressed as
Proof of Lemma 3.
Define
and
such that
in accordance with Equation (7). Then, using de Moivre’s formula, we can write the complex number in polar form as
Thus, substituting this equation into Equation (9), we obtain
Using the relation
we can write
It should be noted that computation of the constant by using Equation (7) is not optimal. Specifically, at lager values of the integer k, its application slows down the computation. The application of Equation (12) for the computation of the constant is also not desirable due to the presence of the trigonometric functions. Theorem 2 and its proof show how this problem can be effectively resolved [7].
Theorem 2.
The rational number is given by
where the coefficients and can be found by a two-step iteration
with initial values
and
Proof of Theorem 2.
We notice that the following power reduction
where the numbers and can be found by two-step iteration (14), leads to
according to Equation (7).
From the Lemma 2, it follows that the imaginary part of the value is equal to zero. Consequently, the equation above can be simplified as
However, since
it follows that
There is an interesting relation between and nested radicals and . Specifically, comparing Equation (4) with Equation (18) from Lemma 4 below, one can see that
where
denotes the fractional part.
Lemma 4.
Proof of Lemma 4.
It is not difficult to see that using a change in the variable
in the trigonometric identity
leads to
Solving the equation
we obtain
Therefore, we have
As the fractional part
while
we conclude that
□
Lemma 5 and its proof below show how to obtain a single-term rational approximation (34) for by truncating Equation (19).
Lemma 5.
Proof of Lemma 5.
From the Lemma 4, it immediately follows that
According to Lemma 1
and
Therefore, we can infer that
or
Motivated by recent publications [8,9,10,11,12,13] in connection to our works [5,7,14], we propose a methodology for determination of the coefficients without computing nested square roots of 2 (see Equation (5)) and develop an algorithm providing the squared convergence per iteration in computing the digits of . To the best of our knowledge, this approach is new and has never been reported.
2. Methodologies
2.1. Arctangent Function
There are different efficient methods to compute the arctangent function in the Machin-like formulas. We will consider a few of them.
In our previous publication [15], we showed how the two-term Machin-like formula for represented in form (8) is used to derive an iterative formula
where the initial value can be taken as
such that
This iterative formula provides a squared convergence in computing the digits of (see the Mathematica code in [15]).
Taking the change in the variable in Equation (21) yields a more convenient form
Consequently, the limit (22) can be rearranged now as
Comparing this limit with Equation (2), we can see that this iteration procedure results in
and is used de facto for the determination of the arctangent function. The detailed procedure showing how to implement the computation with a high convergence rate is given in our recent publication [16].
Alternatively, we can transform the two-term into multi-term Machin-like formulas for consisting of only the integer reciprocals. In order to do this, we can use the following equation [14]
where
with an initial value
For example, by taking in Equation (24), we can construct
This equation is commonly known as the Hermann’s formula for [17,18].
The case requires more calculations to obtain the multi-term formula for consisting of only integer reciprocals. In particular, at , we obtain
Repeating this procedure over and over again, at , we end up with a 7-term Machin-like formula for consisting of only integer reciprocals
where
is the largest integer (see the Mathematica code in [16] that validates this seven-term Machin-like formula for ).
As we can see, Hermann’s (25), Machin’s (1) and the derived (26) formulas for belong to the same generic group, as all of them can be constructed from the same equation-template (24).
This expanded variation of Equation (26) together with iterative formula (23) can also be used for computing the digits of (see Section 5 in [16] for more details).
Our empirical results show that two arctangent series expansions can be used for computation with rapid convergence. The first equation is Euler’s expansion series given by [19]
The second equation is [7,20]
where
and
with initial values
and
2.2. Tangent Function
Generally, transformation of the two-terms to multi-terms formulas for with integer reciprocals is not required. In particular, we can use the Newton–Raphson iteration method. For example, both arctangent terms in the two-term Machin-like formula (4) for can be computed directly by using the following iterative formulas
and
with initial values
and
such that
and
Since the convergence of the Newton–Raphson iteration is quadratic [21], with proper implementation of the tangent function, we may achieve an efficient computation.
The tangent function can be expanded as
where are the Bernoulli numbers that can be defined by the exponential generating function
However, application of Equation (29) is not desirable since the computation of the Bernoulli numbers itself is a big challenge [22,23,24,25].
In order to resolve this problem, we propose the following limit [16]:
where
such that
with initial values
Specifically, it has been shown that at , in the two-term Machin-like formula (4) for , the application of Equation (30) results in more than 17 digits of per increment n (see the Mathematica codes in [16]).
Since the multiplier in Equation (30) increases exponentially with increasing integer n, the iteration process rapidly reduces the number of digits in the mantissa when the tangent function with some fixed accuracy is computed. Decreasing the number of digits in the mantissa may be advantageous as the computation requires less memory usage.
3. Algorithmic Implementation
In our recent publication, we showed that [15]
Consequently, in accordance with Equation (4), we obtain the following approximation:
At sufficiently large k, the value . Therefore, according to Lemma 5, in this equation, we can replace the first arctangent term by a rational number . This gives
Unfortunately, we cannot compute efficiently the tangent function in this approximation since its argument is not a small number as it tends to with increasing k. However, again by taking into consideration that from which it follows that
we can write
Now we can take advantage of the fact that the multiplier is continuously divisible by 2. Therefore, we can use the trigonometric identity
times over and over again. Thus, this leads to the following iterative formula:
with an initial value
such that
Since the left side of the equation above provides an exact value without (tangent and arctangent) trigonometric functions, we can regard this equation
as a rational approximation. This rational approximation of the two-term Machin-like formula for can be used in an algorithm providing a quadratic convergence. This can be achieved with help of Theorem 3.
Theorem 3.
There is a conversion formula
such that
Proof.
The proof is related to the parity of the integer . According to Lemma 5, we can write
or
Consequently, if the integer is even, then
However, if the integer is odd, then
This means that contributes a binary digit to the previous value if and only if is odd. This completes the proof. □
Consider an example. There are four consecutive values , and and . Since the first three values are even, we have
However, since is odd, we obtain
Consider how the number of digits of can be doubled without computing square roots for the nested radicals . We can take, for example, . This yields
However, it is not reasonable to compute the square roots of 2 so many times to obtain this number. Instead, we can simplify computation considerably by using the value in the binary form according to Theorem 3. Thus, ignoring the first two initial zeros in the binary output of Equation (33), we have a corresponding sequence
This sequence can be obtained by using the built-in Mathematica directly using . For example, the following code:
RealDigits[
ImportString[ToString[BaseForm[N[1/\[Pi],20],2]],
"Table"][[1]][[1]]][[1]][[1;;20]]
returns the first 20 digits from the sequence (36):
{1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0}
From this sequence, we choose the sub-sequence (say, up to seventh element)
and apply it accordingly as
Explicitly, defining , this step-by-step procedure results in
Thus, we can see how a very simple procedure can be used to determine the value of the rational number without using a sophisticated Equation (35) consisting of 14 nested square roots of 2.
At , the corresponding Machin-like formula is
where the constant
can be computed either by using Equation (7) or, more efficiently, by using Equation (13) based on two-step iteration (14).
The following Mathematica code:
(∗ String for long number \[Beta]_7 ∗)
strBeta7=
ToString[StringJoin[
"21549475820057881611210311984288158234143531212163819254",
"1568712000964806160594022446140062110943660584298183679/",
"459948920218008069525744651226752553899687099736076594466",
"78719072620659988130828378620624183170066256006981324801"
]];
(∗ Verification ∗)
Print[\[Pi]/4==64∗ArcTan[1/81]-ArcTan[ToExpression[strBeta7]]];
validates Equation (37) by returning True.
Suppose that we do not know the sequence other than . However, with the help of Equation (32), we can find other digits of in the iterative process. In particular, using Equation (31), we have
Substituting this value into Equation (32), we can find a significantly better approximation of .
The following is the Mathematica code:
Print["Equation (34) at k = 7: ",
MantissaExponent[N[\[Pi]-4∗(64/81),20]][[2]] // Abs,
" digits of \[Pi]"];
Print["Equation (32) at k = 7: ",
MantissaExponent[
N[\[Pi]-4∗(64/81+1/2∗(1-1.00941448647564092749)),
20]][[2]]//Abs," digits of \[Pi]"];
which produces the following output:
Equation (34) at k = 7: 1 digits of π
Equation (32) at k = 7: 4 digits of π
The initial sequence helped us to find the value . Now, due to the higher accuracy of Equation (32), we can generate the sequence in which its upper index is doubled
and with the help of this sequence, we can find the corresponding value = 10,430.
Unfortunately, doubling the upper index k does not always work. For example, if we attempt to double the upper index by using the initial sequence , then we obtain = 41,722 instead of the correct value = 41,721. Therefore, the upper index of the sequence should be slightly less than two.
The two-term approximation (32) doubles the number of digits of as compared to the single-term approximation (34). This means that using the sequence , we can obtain all sequences , , , etc., up to , where is an integer slightly smaller than . Our numerical results show that doubling the value of k does not always provide the correct sequence, as a few binary digits at the end of the sequence occasionally may not be correct. However, when we use the empirical equation
then the corresponding sequence is a sub-sequence of the infinite sequence (36) and, therefore, it is appeared to be correct. It is interesting to note that the number 32 in this equation is the largest integer that we found on the basis of our numerical results.
The following is a Mathematica code that shows number of digits of at given iteration number n and integer k:
Clear[str,sps,k,\[Gamma],\[Alpha],lst,\[Eta]]
(∗ String for conversion of 1/\[Pi] to sequence ∗)
str="ImportString[ToString[BaseForm[N[1/piAppr,k0],2]],
\"Table\"][[1]][[1]]";
(∗ String for space separation ∗)
sps[n_]:=Module[{m=1,sps=" "},
While[m<n,sps=StringJoin[sps," "];m++];If[m==n,sps]];
(∗ Converting number to string with length q ∗)
cnv2str[p_,q_]:=Module[{},StringTake[StringJoin[ToString[p],sps[q]],q]]
(∗ Defining \[Eta]-function ∗)
\[Eta][n_,x_,k_]:=Module[{K=k/1.5,y=x},y=N[(2∗y)/(1-y^2),K];cntr = 1;
While[cntr<n,y=(2∗y)/(1-y^2);cntr++];y];
(∗ Define \[Alpha]_1, \[Alpha]_2 and \[Alpha]_3] ∗)
\[Alpha][1]=1;
\[Alpha][2]=2;
\[Alpha][3]=5;
(∗ Input values ∗)
k=3;\[Gamma]=\[Alpha][3];
(∗ Heading ∗)
Print["-------------------------------"];
Print["Iteration | k", sps[5], "| Digits of \[Pi]"];
Print["-------------------------------"];
n=1;
While[n<=12,
intR=1/\[Gamma];
k0=\[LeftFloor](2-1/32)∗k\[RightFloor];
piAppr=4∗(2^(k-1)∗intR+1/2∗(1-\[Eta][k-1,intR,k0]));
(∗ Extracting the sequence {1,0,1,0,0,0,1...} ∗)
lst=RealDigits[ToExpression[str]][[1]][[1;;k0]];
(∗ Main computation ∗)
K=k+1;
While[K<=k0,\[Gamma]=
2∗\[Gamma]+lst[[K]];\[Alpha][K]=\[Gamma];K++];k=k0;
(∗ Aligned output" ∗)
Print[cnv2str[n,5],sps[4]," | ",cnv2str[k,5]," | ",
MantissaExponent[N[\[Pi]-piAppr,k0]][[2]]//Abs];
n++];
This code generates the output:
---------------------------------------
Iteration | k | Digits of π
---------------------------------------
1 | 5 | 1
2 | 9 | 2
3 | 17 | 4
4 | 33 | 9
5 | 64 | 20
6 | 126 | 38
7 | 248 | 75
8 | 488 | 149
9 | 960 | 293
10 | 1890 | 577
11 | 3720 | 1137
12 | 7323 | 2240
As we can see from the third column, the number of digits of doubles at each iteration.
It should be noted that the tangent function can also be computed by combining together Equations (30) and (31). In particular, taking , we can apply the identity
The following is the Mathematica code where the identity (38) is implemented by using Equations (30) and (31) at and :
Clear[tanF]
(∗ Computing tangent ∗)
tanF[n_,x_,k_]:=Module[{p=0,q=0,m=1,x0=N[x,k]},xSq=x0^2;
While[m<=n,
r=(-1)^(m-1)/(2∗m-1)!∗x0;
p=p+r;
q=q+2^(2∗m-1)∗r;
m++;x0=x0∗xSq];
(2∗p^2)/q];
(∗ Case k = k0 = 7323 ∗)
n=1;
\[Sigma]=100;
While[n<=10,numb=tanF[n,2^(k0-1-\[Sigma])/\[Alpha][k0],k0];
Print["n = ",n,": ",MantissaExponent[\[Pi]-
4∗(2^(k0-1)/\[Alpha][k0]+
1/2∗(1-\[Eta][\[Sigma],numb,k0]))][[2]]//Abs,
" digits of \[Pi]"];n++];
This code returns the following output:
n = 1: 60 digits of π
n = 2: 121 digits of π
n = 3: 182 digits of π
n = 4: 244 digits of π
n = 5: 306 digits of π
n = 6: 368 digits of π
n = 7: 430 digits of π
n = 8: 492 digits of π
n = 9: 554 digits of π
n = 10: 617 digits of π
This output shows a high convergence rate. Specifically, we can see that each increment n in Equation (30) contributes more than 60 digits of . Generally, this convergence rate has no upper limitation. However, in order to increase in Equation (38), we have to increase the value of the integer k.
Although this convergence rate is significantly higher than those in some modern algorithms for computing digits of [4], even without nested square roots of 2, the proposed method at large values k still requires a powerful computer to compute the coefficients by using the binary form of .
The presence of the multiplier in Equation (38) is continuously divisible by 2. Therefore, its application may be advantageous for more rapid computation since each multiplication by 2 implies just a binary shift of the mantissa.
The Mathematica code below shows the values of at given k:
(∗Heading∗)
Print["-----------------"];
Print["k",sps[5],"| \[Alpha][k]"];
Print["-----------------"];
k=2;
While[k<=25,
(∗Aligned output" ∗)
Print[cnv2str[k,5], " | ", \[Alpha][k]];
k++];
This code returns the following output:
------------------------
k | αk
------------------------
2 | 2
3 | 5
4 | 10
5 | 20
6 | 40
7 | 81
8 | 162
9 | 325
10 | 651
11 | 1303
12 | 2607
13 | 5215
14 | 10430
15 | 20860
16 | 41721
17 | 83443
18 | 166886
19 | 333772
20 | 667544
21 | 1335088
22 | 2670176
23 | 5340353
24 | 10680707
25 | 21361414
As we can see, all numbers are the same as those reported in [9].
Since the constants have been computed already, we can use them to validate the formula (33) for in the binary form. The Mathematica code below:
f[K_]:=N[Sum[(1/10^(k+1))∗Mod[\[Alpha][k],2],{k,1,K}],K];
Print["-------------------------------------------------------------"]
Print["k",sps[2]," | Binary output"];
Print["-------------------------------------------------------------"]
k := 1;
While[k<=5,Print[10∗k,sps[2],"| ",Subscript[f[10∗k],2]];k++]
Print["-------------------------------------------------------------"]
Print["Built-in Mathematica:"]
Print["1/\[Pi]=",
Subscript[StringJoin["[",
StringSplit[ToString[BaseForm[N[1/Pi,15],2]]][[1]], "...]"],
2]];
returns the output:
------------------------------------------------------
k | Binary output
------------------------------------------------------
10 | 0.010100010112
20 | 0.0101000101111100110002
30 | 0.01010001011111001100000110110112
40 | 0.010100010111110011000001101101110010011102
50 | 0.0101000101111100110000011011011100100111001000100002
————————————————————-
Built-in Mathematica:
= [0.010100010111110011000001101101110010011100100010000...]2
according to Equation (33). The original binary representation of the number generated by the built-in Mathematica is also shown for comparison (see also [26] for binary sequence for ).
4. Conclusions
We consider the properties of the two-term Machin-like formula for and propose its two-term rational approximation (32). Using this approach, we develop an efficient algorithm for computing digits of with squared convergence. The constants in this approximation are computed without nested square roots of 2.
Author Contributions
S.M.A. developed the methodology, wrote the codes and prepared a draft version of the manuscript. R.S., R.K.J. and B.M.Q. verified, reviewed and edited the manuscript. All authors have read and agreed to the published version of the manuscript.
Funding
This research received no external funding.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
Data are contained within the article.
Acknowledgments
This work was supported by National Research Council Canada, Thoth Technology Inc., York University and Epic College of Technology. The authors wish to thank the Reviewers for their constructive comments and recommendations.
Conflicts of Interest
The authors declare no conflicts of interest.
References
- Beckmann, P. A History of Pi; Golem Press: New York, NY, USA, 1971. [Google Scholar]
- Berggren, L.; Borwein, J.; Borwein, P. Pi: A Source Book, 3rd ed.; Springer-Verlag: New York, NY, USA, 2004. [Google Scholar]
- Borwein, J.; Bailey, D. Mathematics by Experiment—Plausible Reasoning in the 21st Century, 2nd ed.; Taylor & Francis Group: Abingdon, UK, 2008. [Google Scholar]
- Agarwal, R.P.; Agarwal, H.; Sen, S.K. Birth, growth and computation of pi to ten trillion digits. Adv. Differ. Equ. 2013, 2023, 100. [Google Scholar] [CrossRef]
- Abrarov, S.M.; Quine, B.M. A formula for pi involving nested radicals. Ramanujan J. 2018, 46, 657–665. [Google Scholar] [CrossRef]
- Servi, L.D. Nested square roots of 2. Am. Math. Mon. 2003, 110, 326–330. [Google Scholar] [CrossRef]
- Abrarov, S.M.; Quine, B.M. An iteration procedure for a two-term Machin-like formula for pi with small Lehmer’s measure. arXiv 2017, arXiv:1706.08835. [Google Scholar]
- Gasull, A.; Luca, F.; Varona, J.L. Three essays on Machin’s type formulas. Indag. Math. 2023, 34, 1373–1396. [Google Scholar] [CrossRef]
- Wolfram Cloud. A Wolfram Notebook Playing with Machin-like Formulas. Available online: https://www.wolframcloud.com/obj/exploration/MachinLike.nb (accessed on 5 June 2024).
- Campbell, J. Nested radicals obtained via the Wilf–Zeilberger method and related results. Maple Trans. 2023, 3, 16011. [Google Scholar] [CrossRef]
- Maritz, M.F. Extracting pi from chaos. Coll. Math. J. 2024, 55, 86–99. [Google Scholar] [CrossRef]
- Spíchal, L. Using the golden section to approximate π. Math. Mag. 2022, 97, 315–320. [Google Scholar] [CrossRef]
- Alferov, O. A rapidly converging Machin-like formula for π. arXiv 2023, arXiv:arxiv:2403.09654. [Google Scholar]
- Abrarov, S.M.; Jagpal, R.K.; Siddiqui, R.; Quine, B.M. A new form of the Machin-like formula for π by iteration with increasing integers. J. Integer Seq. 2022, 25, 22.4.5. [Google Scholar]
- Abrarov, S.M.; Jagpal, R.K.; Siddiqui, R.; Quine, B.M. Algorithmic determination of a large integer in the two-term Machin-like formula for pi. Mathematics 2021, 9, 2162. [Google Scholar] [CrossRef]
- Abrarov, S.M.; Jagpal, R.K.; Siddiqui, R.; Quine, B.M. An iterative method for computing π by argument reduction of the tangent function. Math. Comput. Appl. 2024, 29, 17. [Google Scholar] [CrossRef]
- Borwein, J.M.; Borwein, P.B. Pi and the AGM—A Study in Analytic Number Theory and Computational Complexity; Wiley & Sons Inc.: Hoboken, NJ, USA, 1987. [Google Scholar]
- Chien-Lih, H. More Machin-type identities. Math. Gaz. 1997, 81, 120–121. [Google Scholar] [CrossRef]
- Chien-Lih, H. An elementary derivation of Euler’s series for the arctangent function. Math. Gaz. 2005, 89, 469–470. [Google Scholar] [CrossRef]
- Abrarov, S.M.; Siddiqui, R.; Jagpal, R.K.; Quine, B.M. A generalized series expansion of the arctangent function based on the enhanced midpoint integration. AppliedMath 2023, 3, 395–405. [Google Scholar] [CrossRef]
- Ypma, T.J. Historical development of the Newton—Raphson method. SIAM Rev. 1995, 37, 531–551. [Google Scholar] [CrossRef]
- Knuth, D.E.; Buckholtz, T.J. Computation of tangent, Euler, and Bernoulli numbers. Math. Comp. 1967, 21, 663–688. [Google Scholar] [CrossRef]
- Harvey, D. A multimodular algorithm for computing Bernoulli numbers. Math. Comput. 2010, 79, 2361–2370. [Google Scholar] [CrossRef]
- Bailey, D.H.; Bauschke, H.H.; Borwein, P.; Garvan, F.; Vanderwerff, M.T.J.D.; Wolkowicz, H. Computational and Analytical Mathematics; Springer: New York, NY, USA, 2013. [Google Scholar]
- Beebe, N.H.F. The Mathematical Function Computation Handbook; Springer International Publishing AG: New York, NY, USA, 2017. [Google Scholar]
- The Online Encyclopedia of Integer Sequences. Expansion of 1/Pi in Base 2. OEIS: A127266. Available online: https://oeis.org/A127266 (accessed on 5 June 2024).
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).