bpp: Function which calculates pi, or other irrationals, using the...

View source: R/bpp.R

bppR Documentation

Function which calculates pi, or other irrationals, using the BaileyBorweinPlouffe formula ~~

Description

THe BPP algorithm consists of a double summation over specified fractions. Rather than go into the gory details here, please refer to the link in the References section.

Usage

bpp(k,pdat = c(1,16,8,4,0,0,-2,-1,-1,0,0), init = 0, chunk = 1e4,...)

Arguments

k

The number of terms in the series to calculate. Note that zero is a valid entry. If a single value, the terms 0:k are used. If two values are provided (see information for the input parameter init), then the terms k{1}:k[2] are run.

pdat

The parameter P which is used to define the coefficients used in all fractions in each term of the series. In brief, pdat contains the following BPP parameters: pdat(s,b,m,A) where Acomprises all elements of the vector pdat after the first three. There are strict rules about the length of A; see the Details section. The default value will calculate pi.

init

If there's a previous value calculated with bpp for a certain value of k, this term allows the user to continue the calculation. Assign the previous output's bppgmp value to init . Note that one must set up the input k to start at one more than the previous run's maximum "k" value.

chunk

There is a call to sum in the main loop of this function. Use chunk to specify how many terms to pass to the sum call at a time, thus reducing the peak memory requirements of this function. The more RAM available on your machine, the larger this number can be. Set to a value greater than the argument k to run a single "chunk," which is the fastest approach if sufficient memory is available.

...

Optional arguments to pass to .bigq2mpfr .

Details

The BPP algorithm calculates the sumK=0,k, 1/(b^K) * FracSum , where FracSum is defined by the sum(M=1,m, A[M]/(m*K + M)^s) . This means that the number of elements of A must equal m. Zero values are legal and are used to reject fractions not wanted in the inner sum.

The default values for pdat correspond to the coefficients used to generate pi (the sum to infinity is mathematically equal to pi). Other values have been found to calculate a few other irrationals but there is as yet no known procedure to generate the pdat set for any given number.

Value

A list containing bppgmp , the gmp fraction calculated; bppval, the mpfr decimal representation of said fraction; and kvals, echoing the input k.

Author(s)

Carl Witthoft, carl@witthoft.com

References

https://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula and references cited there.

Examples

# Compare the decimal outputs to the first 130 digits of pi, which are:
#  [1] 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4
#  [26] 3 3 8 3 2 7 9 5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5
#  [51] 1 0 5 8 2 0 9 7 4 9 4 4 5 9 2 3 0 7 8 1 6 4 0 6 2
#  [76] 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 1 1 7 0 6
# [101] 7 9 8 2 1 4 8 0 8 6 5 1 3 2 8 2 3 0 6 6 4 7 0 9 3
# [126] 8 4 4 6 0

# Lots of precision, but most of the digits are inaccurate.
(bpp(5))

# extend the series.
(bpp(20))


FunWithNumbers documentation built on Aug. 29, 2023, 1:06 a.m.