[SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5 to 30 places?

Fernando Perez fperez.net at gmail.com
Sat Jan 13 15:21:29 CST 2007


On 1/13/07, Dick Moores <rdmoores at gmail.com> wrote:
> On 1/13/07, A. M. Archibald <peridot.faceted at gmail.com> wrote:
> >
> > It sounds like what you want is arbitrary-precision arithmetic, which
> > is not what scipy is for (see instead packages like clnum or dmath).
>
> OK, I tracked down clnum and installed it in Python 2.5. But it
> doesn't look as if I can use it for logarithms or non-integer
> exponents. Or can I? The only manual I could find is
> <http://calcrpnpy.sourceforge.net/clnumManual.html>. I was able to
> execute all the examples and got the same results, but...

MPFR is better than clnum for certain things (at least as of Feb'06,
when the SAGE guys did some detailed comparisons) but it's certainly a
very usable library, which I like a lot.  Using it, your computation
can be easily done (here I requested 50 digits, clnum gives a few more
probably because the inputs are exact integers):

In [16]: import clnum as n

In [17]: n.set_default_precision(50)

In [18]: n.log(640320**3 + 744)/n.sqrt(163)
Out[18]: mpf('3.141592653589793238462643383279726619347549880883522422293',55)


Below is Mathematica's value for reference:

tlon[~]> math
Mathematica 5.2 for Linux
Copyright 1988-2005 Wolfram Research, Inc.
 -- Motif graphics initialized --

In[1]:= N[Log[640320^3+744]/Sqrt[163],58]

Out[1]= 3.141592653589793238462643383279726619347549880883522422293
[clnum:]3.141592653589793238462643383279726619347549880883522422293


That looks pretty good to me.

Here's a comparison of the approximate formula with Pi itself:

In[2]:= N[Pi,50]

Out[2]= 3.1415926535897932384626433832795028841971693993751
[approx]3.141592653589793238462643383279726619347549880883522422293

Indeed, they match on the first 30 digits.


Cheers,

f


More information about the SciPy-user mailing list