Spigot algorithm

Spigot algorithm

A spigot algorithm is an algorithm used to compute the value of a mathematical constant such as π or e. Unlike recursive algorithms, a spigot algorithm yields digits incrementally without using previously computed digits. The Bailey-Borwein-Plouffe formula for the binary digits of π is an example of a spigot algorithm.

Example

This example illustrates the working of a spigot algorithm by calculating the binary digits of the natural logarithm of 2 OEIS|id=A068426 using the identity

:ln(2)=sum_{k=1}^{infty}frac{1}{k2^k}, .

To start calculating binary digits from, say, the 8th place we multiply this identity by 27:

:2^7ln(2) =2^7sum_{k=1}^{infty}frac{1}{k2^k}, .

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^7ln(2) =sum_{k=1}^{7}frac{2^{7-k{k}+sum_{k=8}^{infty}frac{1}{k2^{k-7, .

We are only interested in the fractional part of this value, so we can replace each of the terms in the "head" by

:frac{2^{7-k} mod k}{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^7ln(2)mod{1} approx frac{64}{105}+frac{37}{360}=0.10011100 cdots_{2} + 0.00011010 cdots_{2} = 0.1011 cdots_{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 7 binary digits - indeed, all information about them has been intentionally discarded by using modular arithmetic 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 is used. The precision 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 arithmetic can be used to calculate around 12 binary digits, regardless of the starting position.

External links

*
*


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Spigot (disambiguation) — spigot may refer to:* Spigot, a small wooden plug, a faucet or a Tap (valve) * Tristan A. Farnon, a cartoonist, also known as Spigot * Spigot algorithm, an algorithm used to compute the value of a mathematical constant * AT 4 Spigot, a Russian… …   Wikipedia

  • Bailey–Borwein–Plouffe formula — The Bailey–Borwein–Plouffe formula (BBP formula) provides a spigot algorithm for the computation of the n th binary digit of π. This summation formula was discovered in 1995 by Simon Plouffe. The formula is named after the authors of the paper in …   Wikipedia

  • List of numerical analysis topics — This is a list of numerical analysis topics, by Wikipedia page. Contents 1 General 2 Error 3 Elementary and special functions 4 Numerical linear algebra …   Wikipedia

  • List of mathematics articles (S) — NOTOC S S duality S matrix S plane S transform S unit S.O.S. Mathematics SA subgroup Saccheri quadrilateral Sacks spiral Sacred geometry Saddle node bifurcation Saddle point Saddle surface Sadleirian Professor of Pure Mathematics Safe prime Safe… …   Wikipedia

  • Lattice reduction — In mathematics, the goal of lattice basis reduction is given an integer lattice basis as input, to find a basis with short, nearly orthogonal vectors. This is realized using different algorithms, whose running time is usually at least exponential …   Wikipedia

  • Cinepak — is a video codec developed by Peter Barrett at SuperMac Technologies, and released in 1991 with the Video Spigot, and then in 1992 as part of Apple Computer s QuickTime video suite. It was designed to encode 320x240 resolution video at 1x (150… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”