Digit Extraction Algorithm
   HOME

TheInfoList



OR:

A spigot algorithm is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
for computing the value of a
transcendental number In mathematics, a transcendental number is a real or complex number that is not algebraic: that is, not the root of a non-zero polynomial with integer (or, equivalently, rational) coefficients. The best-known transcendental numbers are and . ...
(such as or ''e'') that generates the digits of the number sequentially from left to right providing increasing precision as the algorithm proceeds. Spigot algorithms also aim to minimize the amount of intermediate storage required. The name comes from the sense of the word "spigot" for a tap or valve controlling the flow of a liquid. Spigot algorithms can be contrasted with algorithms that store and process complete numbers to produce successively more accurate approximations to the desired transcendental. Interest in spigot algorithms was spurred in the early days of computational mathematics by extreme constraints on memory, and such an algorithm for calculating the digits of ''e'' appeared in a paper by Sale in 1968. In 1970, Abdali presented a more general algorithm to compute the sums of series in which the ratios of successive terms can be expressed as quotients of integer functions of term positions. This algorithm is applicable to many familiar series for trigonometric functions, logarithms, and transcendental numbers because these series satisfy the above condition. The name "spigot algorithm" seems to have been coined by Stanley Rabinowitz and
Stan Wagon Stanley Wagon is a Canadian-American mathematician, a professor emeritus of mathematics at Macalester College in Minnesota. He is the author of multiple books on number theory, geometry, and computational mathematics, and is also known for his sn ...
, whose algorithm for calculating the digits of is sometimes referred to as "''the'' spigot algorithm for ". The spigot algorithm of Rabinowitz and Wagon is ''bounded'', in the sense that the number of terms of the infinite series that will be processed must be specified in advance. The term "streaming algorithm" indicates an approach without this restriction. This allows the calculation to run indefinitely varying the amount of intermediate storage as the calculation progresses. A variant of the spigot approach uses an algorithm which can be used to compute a single arbitrary digit of the transcendental without computing the preceding digits: an example is the
Bailey–Borwein–Plouffe formula The Bailey–Borwein–Plouffe formula (BBP formula) is a formula for . It was discovered in 1995 by Simon Plouffe and is named after the authors of the article in which it was published, David H. Bailey, Peter Borwein, and Plouffe. The formula i ...
, a digit extraction algorithm for which produces base 16 digits. The inevitable truncation of the underlying infinite series of the algorithm means that the accuracy of the result may be limited by the number of terms calculated.


Example

This example illustrates the working of a spigot algorithm by calculating the binary digits of the
natural logarithm The natural logarithm of a number is its logarithm to the base of a logarithm, base of the e (mathematical constant), mathematical constant , which is an Irrational number, irrational and Transcendental number, transcendental number approxima ...
of 2 using the identity :\ln(2)=\sum_^\frac\, . To start calculating binary digits from, as an example, the 8th place we multiply this identity by 27 (since 7 = 8 − 1): :2^7\ln(2) =2^7\sum_^\infty \frac\, . We then divide the infinite sum into a "head", in which the exponents of 2 are greater than or equal to zero, and a "tail", in which the exponents of 2 are negative: :2^7\ln(2) =\sum_^\frac+\sum_^\frac\, . We are only interested in the fractional part of this value, so we can replace each of the summands in the "head" by :\frac k \bmod 1 = \frac k \, . Calculating each of these terms and adding them to a running total where we again only keep the fractional part, we have: : We add a few terms in the "tail", noting that the error introduced by truncating the sum is less than the final term: : Adding the "head" and the first few terms of the "tail" together we get: :2^7\ln(2)\bmod1 \approx \frac+\frac=0.10011100 \ldots_2 + 0.00011010 \ldots_2 = 0.1011 \ldots_2 \, , so the 8th to 11th binary digits in the binary expansion of ln(2) are 1, 0, 1, 1. Note that we have not calculated the values of the first seven binary digits – indeed, all information about them has been intentionally discarded by using
modular arithmetic In mathematics, modular arithmetic is a system of arithmetic operations for integers, other than the usual ones from elementary arithmetic, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to mo ...
in the "head" sum. The same approach can be used to calculate digits of the binary expansion of ln(2) starting from an arbitrary ''n''th position. The number of terms in the "head" sum increases linearly with ''n'', but the complexity of each term only increases with the logarithm of ''n'' if an efficient method of
modular exponentiation Modular exponentiation is exponentiation performed over a modulus. It is useful in computer science, especially in the field of public-key cryptography, where it is used in both Diffie–Hellman key exchange and RSA public/private keys. Modula ...
is used. The
precision Precision, precise or precisely may refer to: Arts and media * ''Precision'' (march), the official marching music of the Royal Military College of Canada * "Precision" (song), by Big Sean * ''Precisely'' (sketch), a dramatic sketch by the Eng ...
of calculations and intermediate results and the number of terms taken from the "tail" sum are all independent of ''n'', and only depend on the number of binary digits that are being calculated –
single precision Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point. A floa ...
arithmetic can be used to calculate around 12 binary digits, regardless of the starting position.


References


Further reading

* Arndt, Jorg; Haenel, Christoph, '' unleashed'', Springer Verlag, 2000. * {{MathWorld, urlname=SpigotAlgorithm, title=Spigot algorithm Computer arithmetic algorithms