Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pi upto a Billion Digits

5 views
Skip to first unread message

Raj

unread,
May 7, 2007, 5:45:26 AM5/7/07
to
hi!

Could somebody tell me if they ever tried finding Pi upto a billion
digits using the N function:
N[Pi,10^9] and how long did it take?

Thanks,

Raj


Szabolcs

unread,
May 8, 2007, 6:07:21 AM5/8/07
to

I haven't tried it, but you can estimate how long it takes, like this:

d = Table[Update[]; First@Timing[N[Pi, 2^k 10^5]], {k, 1, 6}]/Second

{1.437, 3.579, 9.14, 23.375, 58.453, 143.391}

(Results are from Mathematica 5.2, 1.7 GHz processor.)

ListPlot[Log@d]

Now we can extrapolate. Find the slope of Log@d

slope = Mean@ListConvolve[{1, -1}, Log@d]

0.920604

10^9 is approximately 2^12 * 10^5, so you can expect

Exp[11*slope + d[[1]] ]

105202.

This is approximately 30 hours. Of course this result may be an order of
magnitude off, but I suspect that the precise result is less than 30
hours, not more. With a little patience you can get a much better estimate.

Or you can leave the calculation running for a day and hope that you
don't run out of memory (memory usage may be a bigger problem than CPU
time). If you do run the calculation, please let us know your findings.

But note that the time to export the result to a file may be comparable
to the time of the calculation (or even much longer -- Mathematica I/O
is pretty slow).

Szabolcs

Peter Pein

unread,
May 8, 2007, 6:16:42 AM5/8/07
to
Raj schrieb:
Hi,

don't know this, but http://www.lacim.uqam.ca/~plouffe/ might be of interest.

Regards,
Peter

Murray Eisenberg

unread,
May 8, 2007, 6:17:44 AM5/8/07
to
Essentially no time at all!

Upon trying to evaluate the cell on my Windows XP machine with 2GB of
RAM, I got an immediate "No more memory available. Mathematica kernel
has shut down." message. (This is with my normal complement of other
programs running: Thunderbird, Firefox, and all sorts of background
utilities including Google Desktop indexing, background degragger, AV,
anti-spyware, and firewall.)

Raj wrote:
> hi!
>
> Could somebody tell me if they ever tried finding Pi upto a billion
> digits using the N function:
> N[Pi,10^9] and how long did it take?
>
> Thanks,
>
> Raj
>
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

dimitris

unread,
May 9, 2007, 4:16:38 AM5/9/07
to
I must admit what you asked is not "my cup of tea".
So I may miss some things.
But...
I don't believe that this is a task for the N function.

In[23]:=
Developer`ClearCache[]

In[24]:=
InputForm[(Timing[N[Pi, 10^#1]; ] & ) /@ Range[7]]

Out[24]//InputForm=
{{0.*Second, Null}, {0.*Second, Null}, {0.*Second, Null},
{0.015999999999999986*Second, Null},
{0.5619999999999999*Second, Null}, {13.453*Second, Null},
{267.17199999999997*Second, Null}}

Look the differences in timings!

Is it an important reason you want Pi with so many decimal digits?
Or you just want to testify Mathematica?

There are many references containg formulas about Pi that you should
consult instead of N[Pi,..] (or evalf(Pi,...) on another CAS) for
obtaining numerical approximations of Pi with millions of digits.

(BTW Pi is computed using the Chudnovsky formula in Mathematica
which as far as I have read they must be (the brothers!) considered
gurus of Pi

http://mathforum.org/library/drmath/view/58285.html

www.mathsci.appstate.edu/~sjg/class/3010/final/andy.pdf )

1) L. Berggren, J. Borwein, P. Borwein. Pi: A Source Book, Springer-
Verlag, New York, 1997.
2) J. Arndt, C. Haenel. =F0 Unleashed, Springer-Verlag, Berlin, 2001.

3) http://mathworld.wolfram.com/PiFormulas.html

I think that the old book Mathematica in Action contain some material
about Pi.

Copy/Paste also the following command on a notebook and then execute
it.

In[28]:=
FrontEndExecute[{HelpBrowserLookup["Demos", "Pi"]}]

(or see here
http://documents.wolfram.com/mathematica/Demos/Notebooks/CalculatingPi.html
)

The following may be interested for you.

Suppose you want to compute the thousandth digit in base 10

In Mathematica 5.2 you could have

In[21]:=
Block[{$MaxExtraPrecision = 10000}, First[RealDigits[Pi, 10, 1,
-1000]]]

Out[21]=
{9}

Indeed

In[52]:=
N[Pi,1001]

Out[52]=
3=2E14159265358979323846264338327950288419716939937510582097494459230781640=
62862\
089986280348253421170679821480865132823066470938446095505822317253594081284=
811\
174502841027019385211055596446229489549303819644288109756659334461284756482=
337\
867831652712019091456485669234603486104543266482133936072602491412737245870=
066\
063155881748815209209628292540917153643678925903600113305305488204665213841=
469\
519415116094330572703657595919530921861173819326117931051185480744623799627=
495\
673518857527248912279381830119491298336733624406566430860213949463952247371=
907\
021798609437027705392171762931767523846748184676694051320005681271452635608=
277\
857713427577896091736371787214684409012249534301465495853710507922796892589=
235\
420199561121290219608640344181598136297747713099605187072113499999983729780=
499\
510597317328160963185950244594553469083026425223082533446850352619311881710=
100\
031378387528865875332083814206171776691473035982534904287554687311595628638=
823\
537875937519577818577805321712268066130019278766111959092164201989

Last but not least!

Did you see the film Pi?
Amazing movie!

Dimitris


=CF/=C7 Raj =DD=E3=F1=E1=F8=E5:

Daniel Lichtblau

unread,
May 9, 2007, 4:50:41 AM5/9/07
to
Szabolcs wrote:
> I haven't tried it, but you can estimate how long it takes, like this:
>
> d = Table[Update[]; First@Timing[N[Pi, 2^k 10^5]], {k, 1, 6}]/Second
>
> {1.437, 3.579, 9.14, 23.375, 58.453, 143.391}
>
> (Results are from Mathematica 5.2, 1.7 GHz processor.)
>
> ListPlot[Log@d]
>
> Now we can extrapolate. Find the slope of Log@d
>
> slope = Mean@ListConvolve[{1, -1}, Log@d]
>
> 0.920604
>
> 10^9 is approximately 2^12 * 10^5, so you can expect
>
> Exp[11*slope + d[[1]] ]
>
> 105202.
>
> This is approximately 30 hours. Of course this result may be an order of
> magnitude off, but I suspect that the precise result is less than 30
> hours, not more. With a little patience you can get a much better estimate.
>
> Or you can leave the calculation running for a day and hope that you
> don't run out of memory (memory usage may be a bigger problem than CPU
> time). If you do run the calculation, please let us know your findings.
>
> But note that the time to export the result to a file may be comparable
> to the time of the calculation (or even much longer -- Mathematica I/O
> is pretty slow).
>
> Szabolcs

I'll comment on that last part. First we rerun the computation. I'm
using version 6 on a Linux machine, around 3 GHz.

In[8]:= d = Table[ClearSystemCache[];
First[Timing[v[k]=N[Pi,2^k*10^5]]], {k,1,7}]
Out[8]= {0.47603, 1.08807, 2.56416, 6.09238, 14.2249, 31.874, 73.5246}

What we see is "soft" linear time, roughly that associated with the
(bit) complexity of multiplication.

Now we convert to strings of digits.

In[12]:= f = Table[First[Timing[s10[k]=RealDigits[v[k]]]], {k,7}]
Out[12]= {0.176011, 0.47603, 1.12407, 2.77217, 6.65242, 15.861, 37.3623}

We see similar complexity. Not surprising, because the conversion from
binary to decimal involves division, which has the same complexity as
multiplication.

If we avoid the b2d conversion it becomes a byte faster.

In[13]:= g = Table[First[Timing[s16[k]=RealDigits[v[k],16]]], {k,7}]
Out[13]= {0.004, 0.008002, 0.012, 0.020002, 0.036002, 0.076004, 0.15201}

Outputting the results e.g. to a file will show similar behavior to
RealDigits; slow if in decimal and relatively fast if in hex. Upshot:
This has little to do with I/O, and more to do with conversion of large
numbers from binary to decimal form.

Daniel Lichtblau
Wolfram Research

DrMajorBob

unread,
May 9, 2007, 4:52:45 AM5/9/07
to
On my machine (WinXP, Athlon 3200+, 2GB RAM, Mathematica 6), I estimate

3.4 hours:

Timing[data =
Table[Update[];
Log@{#, First@Timing[N[Pi, #]]} &[2^k 10^5], {k, 1, 8}]]

{231.921, {{Log[200000], -1.06711}, {Log[400000], -0.226901}, {Log[
800000], 0.669879}, {Log[1600000], 1.50741}, {Log[3200000],
2.37052}, {Log[6400000], 3.21451}, {Log[12800000],
4.05123}, {Log[25600000], 4.87675}}}

(I doubled two steps more than Szabolcs did.)

The log-log data is VERY linear:

Needs["LinearRegression`"]
AdjustedRSquared /. Regress[data, x, x]

0.999901

Clear[a, b, z, logSecs, hours]
model = a + b z;
logSecs[z_] = model /. FindFit[data, model, {a, b}, z]
hours[z_] := Exp[logSecs[Log[z]]]/60^2
hours[10^9]

-16.0424 + 1.22792 z

3.37132

Also note, omitting Update[] has NO effect on the timings:

Timing[data =
Table[Log@{#, First@Timing[N[Pi, #]]} &[2^k 10^5], {k, 1, 8}]]

{231.703, {{Log[200000], -1.07002}, {Log[400000], -0.207024}, {Log[
800000], 0.628609}, {Log[1600000], 1.52126}, {Log[3200000],
2.36471}, {Log[6400000], 3.21133}, {Log[12800000],
4.04989}, {Log[25600000], 4.8771}}}

Bobby

On Tue, 08 May 2007 04:54:55 -0500, Szabolcs <szho...@gmail.com> wrote:=

> I haven't tried it, but you can estimate how long it takes, like this:=

>
> d = Table[Update[]; First@Timing[N[Pi, 2^k 10^5]], {k, 1, 6}]/Second=

>
> {1.437, 3.579, 9.14, 23.375, 58.453, 143.391}
>
> (Results are from Mathematica 5.2, 1.7 GHz processor.)
>
> ListPlot[Log@d]
>
> Now we can extrapolate. Find the slope of Log@d
>
> slope = Mean@ListConvolve[{1, -1}, Log@d]
>
> 0.920604
>
> 10^9 is approximately 2^12 * 10^5, so you can expect
>
> Exp[11*slope + d[[1]] ]
>
> 105202.
>

> This is approximately 30 hours. Of course this result may be an order =


of
> magnitude off, but I suspect that the precise result is less than 30

> hours, not more. With a little patience you can get a much better =

> estimate.
>
> Or you can leave the calculation running for a day and hope that you

> don't run out of memory (memory usage may be a bigger problem than CPU=

> time). If you do run the calculation, please let us know your findings=
.
>
> But note that the time to export the result to a file may be comparabl=
e
> to the time of the calculation (or even much longer -- Mathematica I/O=

> is pretty slow).
>
> Szabolcs
>
>

-- =

DrMaj...@bigfoot.com

Szabolcs Horvát

unread,
May 9, 2007, 4:53:46 AM5/9/07
to
On 08/05/07, DrMajorBob <drmaj...@bigfoot.com> wrote:
> On my machine (WinXP, Athlon 3200+, 2GB RAM, Mathematica 6), I estimate
> 3.4 hours:

Did you run the calculation?

Update[] forces Mathematica to recalculate everything instead of using
cached values. If it has no effect in Mathematica 6 that is very
strange (it would mean that Mathematica 6 doesn't cache results in
this case, and that the performance may be worse than in 5.2). Does it
have an effect when you don't use it in Table[], but evaluate the
expressions separately?

In 5.2 it has a very noticeable effect:

In[178]:=
Update[]

In[179]:=
Timing[N[Pi,4*10^5];]

Out[179]=
{3.25 Second,Null}

In[180]:=
Timing[N[Pi,8*10^5];]

Out[180]=
{5.579 Second,Null}

In[181]:=
Update[]

In[182]:=
Timing[N[Pi,8*10^5];]

Out[182]=
{8.187 Second,Null}

In[183]:=
Update[]

In[184]:=
Table[Timing[N[Pi,k 4*10^5];],{k,2}]

Out[184]=
{{3.156 Second,Null},{5.625 Second,Null}}

In[185]:=
Update[]

In[186]:=
Table[Update[];Timing[N[Pi,k 4*10^5];],{k,2}]

Out[186]=
{{3.11 Second,Null},{8.062 Second,Null}}

Szabolcs

DrMajorBob

unread,
May 9, 2007, 4:57:57 AM5/9/07
to
Version 6 may cache differently than 5.2, in some way that Update[]
doesn't affect.

Whatever the case may be, version 6 is faster than 5.2 at my machine.

Version 5.2 timings:

Update[]
Timing[N[Pi,4*10^5];]
Timing[N[Pi,8*10^5];]
Update[]
Timing[N[Pi,8*10^5];]
Update[]


Table[Timing[N[Pi,k 4*10^5];],{k,2}]

Update[]


Table[Update[];Timing[N[Pi,k 4*10^5];],{k,2}]

{1.515 Second,Null}
{2.922 Second,Null}
{4.047 Second,Null}
{{1.562 Second,Null},{2.907 Second,Null}}
{{1.562 Second,Null},{3.984 Second,Null}}

Update[]
Timing[N[Pi, 4*10^5];]
Timing[N[Pi, 8*10^5];]
Update[]
Timing[N[Pi, 8*10^5];]
Update[]
Table[Timing[N[Pi, k 4*10^5];], {k, 2}]
Update[]
Table[Update[]; Timing[N[Pi, k 4*10^5];], {k, 2}]

{0.796, Null}
{1.954, Null}
{1.875, Null}
{{0.813, Null}, {1.89, Null}}
{{0.812, Null}, {1.907, Null}}

Bobby

On Tue, 08 May 2007 11:29:51 -0500, Szabolcs Horvát <szho...@gmail.com>
wrote:

--
DrMaj...@bigfoot.com

DrMajorBob

unread,
May 9, 2007, 5:06:08 AM5/9/07
to
Calculating N[Pi,2*10^8], I got an abnormal termination from the
C++ library after ten or fifteen minutes.

So... 10^9 is out of the question on my machine.

Raj

unread,
May 10, 2007, 5:40:46 AM5/10/07
to
On May 9, 2:06 am, DrMajorBob <drmajor...@bigfoot.com> wrote:
> Calculating N[Pi,2*10^8], I got an abnormal termination from the
> C++ library after ten or fifteen minutes.
>
> So... 10^9 is out of the question on my machine.
>
> Bobby
>
> On Tue, 08 May 2007 11:29:51 -0500, Szabolcs Horv=E1t <szhor...@gmail.com>
> wrote:
> DrMajor...@bigfoot.com

Thanks for the replies. It seemed to take a long time(> 1 hour) on my
computer...so I was curious if someone already evaluated it.

Thanks,

Raj


0 new messages