|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() Другие алгоритмы. Математика: Быстрое вычисление функций и констант.N-th digit computationСтатья любезно предоставлена: Is it possible to compute directly the n-th digit of p without computing all its first n digits ? At first sight, the problem seems of the same complexity. Recently [1], a formula which permits to find directly the n-th bit of p with very little memory and in quasi-linear time was exhibited. In other words, the question has a positive answer in base 2.
In [1], David Bailey, Peter Borwein and Simon Plouffe give the following formula
and use that to compute the n-th bit of p without computing all its first n bits. More precisely, their method permits to obtain the n-th bit of p in time O(nlog3n) and space O(log(n)).
1.1 Principle of the algorithmFor convenience, we call the k-th bit of a number the k-th bit of its fractional part.
Computation of the N-th bit of a numberWe make use of the notation
The N+n-th bit of a real number a is obtained by computing the n-th bit of the fractional part of 2Na.Proof : This property is obvious since the binary expansion of a
Thus from a sufficiently accurate value of {2N a}, this result permits to know the first term of its binary expansion. We illustrate this simple idea on p. One has
PoweringWe are thus lead to compute a sufficiently accurate value of the fractional part {2Np} of 2N p. Formula (1) entails that {2Np} is the fractional part of the series
The computation of 2n modulo m is obtained thanks to a binary powering method, using only O(log(n)) operations modulo m. It consists in writing n in base 2
Final resultFinally, formula (1) permits to obtain bits of p between position N+1 and N+K by computing the K first bits of the number
1.2 Other BBP formulas for pOther formulas of this type have been found for p. The fastest known is due to Fabrice Bellard and is approximately 43% faster than (1) to compute the n-th bit of p :
In [1], David Bailey, Peter Borwein and Simon Plouffe give similar kind of series to compute directy the n-th bit of the constants log(2), p2 and log2(2). Later [2], D. J. Broadhurst found other similar series for a wider class of constants, like z(3), z(5), the Catalan constant C, p3, p4, log3(2), log4(2), log5(2). Here are a sample of those formulas :
As for the Catalan constant G = еk і 0 (-1)k/(2k+1)2, we have
The direct computation of the n-th bit of the classical constants e, Ц2 and g with a similar complexity remains an open problem.
Unhappily, no formula of the same kind to compute decimal digits of p have been found yet (or more generally, in any base that is not a power of two). In other words, no series of the form
The first progress in this direction is due to Simon Plouffe in 1997, who found an algorithm with time O(n3 log3n) and very little memory to compute the n-th digit of p (see the Plouffe page for a description of the method). Unhappily, the complexity is so high that his technique does not reasonably permit to reach decimal digits at position n higher than several thousands. The Simon Plouffe method has been improved by Fabrice Bellard with a O(n2) algorithm. The Fabrice Bellard page describes the corresponding algorithm, and a C program is also available. The millionth decimal digit can be reached with that technique. Nethertheless, even using parallelization, the complexity remains too high to give a practical alternative to techniques in quasi-linear time which computes all the decimal digits.
References
![]() |