Where to download a lot of digits of pi?

11

5

Where could I find a large amount of digits of pi? I have already calculated 3.14 billion using PiFast (works well under wine).

I don't care about slow download speeds.

bgw

Posted 2009-07-15T21:05:50.940

Reputation: 299

Question was closed 2015-04-24T05:55:40.890

2Go ahead and try accepting a new answer to your question. The original accepted answer had a single link that no longer exists, so it has been deleted. Go ahead and flag the question if you have any questions for the moderators. – Troggy – 2011-02-10T10:24:41.070

2Do you need it for some even remotely practical purpose, or just for ... ? I can't see the point, so I'm just curious. – Rook – 2009-07-16T03:17:20.660

2@Idigas: Don't you ever make pi? – Nosredna – 2009-07-16T05:04:41.883

Soon's i can find the algorithm for calculating pi, i'll write something up to calculate as many as you want... – RCIX – 2009-07-16T08:32:54.067

Answers

9

I know you say you don't care, but I seriously suspect your cpu can calculate them faster than your network card is capable of downloading them.

Given the last digit and the current state of the calculator used to generate it, the next digit can be found in constant time. It doesn't get progressively harder like finding the next prime does.

Joel Coehoorn

Posted 2009-07-15T21:05:50.940

Reputation: 26 787

5 minutes to calculate 100m decimals on my reasonably new laptop (using pi package on non-virtual Ubuntu), 10 seconds to download the same as a 57MB file. Conclusion: calculating is 30 times slower than downloading. – Nicolas Raoul – 2014-11-18T04:51:18.910

That's simply not true. – Ron Reiter – 2015-04-24T05:31:29.787

Yes, but it is a lot of cpu time to dedicate, and I would rather dedicate some bandwidth rather than all that cpu time. – bgw – 2009-07-15T21:12:00.177

@Joel: by the way, can you show a pointer to an algorithm for that? (Yeah, I know that's more like SO content, but since we're here...) – R. Martinho Fernandes – 2009-07-15T21:16:27.967

The math is beyond me, but read way down in wikipedia and one of the series is said to "deliver 14 digits per term". – Joel Coehoorn – 2009-07-15T21:35:04.320

Sorry, wrong link: http://numbers.computation.free.fr/Constants/PiProgram/algo.html, It was in frames

– bgw – 2009-07-15T21:40:11.793

@Joel That would be the Chudnovsky formula – bgw – 2009-07-15T21:41:20.217

4

Adding on to Joel's comment, SuperPi is one of the most popular tools for this. It's also used for stress testing.

John T

Posted 2009-07-15T21:05:50.940

Reputation: 149 037

PiFast is faster. – bgw – 2009-12-17T21:27:34.237

3

On Ubuntu, you can sudo apt-get install pi

and then:

$ pi 100 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067

It calculates arbitrary precision given the number of digits to calculate.

Janus Troelsen

Posted 2009-07-15T21:05:50.940

Reputation: 1 958

0

If you want to use Python to calculate it, here's an extremely fast method (using Python and the gmpy2 library):

http://www.craig-wood.com/nick/articles/pi-chudnovsky/

Here's the code with a small fix:

"""
Python3 program to calculate Pi using python long integers, binary
splitting and the Chudnovsky algorithm

See: http://www.craig-wood.com/nick/articles/pi-chudnovsky/ for more
info

Nick Craig-Wood <nick@craig-wood.com>
"""

import math
from gmpy2 import mpz
from time import time
import gmpy2

def pi_chudnovsky_bs(digits):
    """
    Compute int(pi * 10**digits)

    This is done using Chudnovsky's series with binary splitting
    """
    C = 640320
    C3_OVER_24 = C**3 // 24
    def bs(a, b):
        """
        Computes the terms for binary splitting the Chudnovsky infinite series

        a(a) = +/- (13591409 + 545140134*a)
        p(a) = (6*a-5)*(2*a-1)*(6*a-1)
        b(a) = 1
        q(a) = a*a*a*C3_OVER_24

        returns P(a,b), Q(a,b) and T(a,b)
        """
        if b - a == 1:
            # Directly compute P(a,a+1), Q(a,a+1) and T(a,a+1)
            if a == 0:
                Pab = Qab = mpz(1)
            else:
                Pab = mpz((6*a-5)*(2*a-1)*(6*a-1))
                Qab = mpz(a*a*a*C3_OVER_24)
            Tab = Pab * (13591409 + 545140134*a) # a(a) * p(a)
            if a & 1:
                Tab = -Tab
        else:
            # Recursively compute P(a,b), Q(a,b) and T(a,b)
            # m is the midpoint of a and b
            m = (a + b) // 2
            # Recursively calculate P(a,m), Q(a,m) and T(a,m)
            Pam, Qam, Tam = bs(a, m)
            # Recursively calculate P(m,b), Q(m,b) and T(m,b)
            Pmb, Qmb, Tmb = bs(m, b)
            # Now combine
            Pab = Pam * Pmb
            Qab = Qam * Qmb
            Tab = Qmb * Tam + Pam * Tmb
        return Pab, Qab, Tab
    # how many terms to compute
    DIGITS_PER_TERM = math.log10(C3_OVER_24/6/2/6)
    N = int(digits/DIGITS_PER_TERM + 1)
    # Calclate P(0,N) and Q(0,N)
    P, Q, T = bs(0, N)
    one_squared = mpz(10)**(2*digits)
    #sqrtC = (10005*one_squared).sqrt()
    sqrtC = gmpy2.isqrt(10005*one_squared)
    return (Q*426880*sqrtC) // T

# The last 5 digits or pi for various numbers of digits
check_digits = {
        100 : 70679,
       1000 :  1989,
      10000 : 75678,
     100000 : 24646,
    1000000 : 58151,
   10000000 : 55897,
}

if __name__ == "__main__":
    digits = 100
    pi = pi_chudnovsky_bs(digits)
    print(pi)
    #raise SystemExit
    for log10_digits in range(1,9):
        digits = 10**log10_digits
        start =time()
        pi = pi_chudnovsky_bs(digits)
        print("chudnovsky_gmpy_mpz_bs: digits",digits,"time",time()-start)
        if digits in check_digits:
            last_five_digits = pi % 100000
            if check_digits[digits] == last_five_digits:
                print("Last 5 digits %05d OK" % last_five_digits)
                open("%s_pi.txt" % log10_digits, "w").write(str(pi))
            else:
                print("Last 5 digits %05d wrong should be %05d" % (last_five_digits, check_digits[digits]))

Ron Reiter

Posted 2009-07-15T21:05:50.940

Reputation: 101