Compute pi to base 12 using Python?

mensanator at aol.com mensanator at aol.com
Mon Apr 18 18:55:16 EDT 2005


Nick Craig-Wood wrote:
> mensanator at aol.com <mensanator at aol.com> wrote:
> >  Nick Craig-Wood wrote:
> > > mensanator at aol.com <mensanator at aol.com> wrote:
> > > >  I'm using GMPY (see code).
> > > [snip]
> > >
> > > If you are using gmpy you might as well do it like this.....
> > >
> > > gmpy.pi() uses the Brent-Salamin Arithmetic-Geometric Mean
formula
> > > for
> > > pi IIRC.  This converges quadratically, and it will calculate you
a
> > > million places without breaking a sweat.
> >
> >  It would be nice if that were documented. What do I have to do, go
get
> >  the documentation for the original GMP to find out what else is in
GMPY
> >  that they didn't include in the doc file?
>
> "pydoc gmpy" works for me.  Not sure how you use pydoc on windows,
but
> you can do this...
>
> >>> import gmpy
> >>> help(gmpy)
> Help on module gmpy:
>
> NAME
>     gmpy
>
> FILE
>     /usr/lib/python2.3/site-packages/gmpy.so
> [snip]
> Help on built-in function pi:
>
> pi(...)
>     pi(n): returns pi with n bits of precision in an mpf object
> [snip]

Thanks, didn't know you could do that. And I'm glad you didn't reply
until today, because I learned how to do it the hard way:

>>> import gmpy
>>> f = dir(gmpy)
>>> def print_docs(f):
            for q in f:
                    if q[:2]=='__':
                             pass
                    else:
                             d = 'gmpy.' + q + '.__doc__'
                             e = eval(compile(d,'<string>','eval')
                             print e
                             print
>>> print_docs(f)


That's 3 new functions I learned, dir(), compile() and eval().
And now that I know help(), I'll probably never need them, but
hopefully will remember them.

Even better, I realize the inadequecy of the doc strings of a
program I wrote. Now that I know how to use them interactively,
I can make them more useful.

>
> The original gmp documentation is sensible also, since gmpy is really
> just a thin wrapper to it.

I already looked. Utterly useless.

> There is also the gmp source code too.

That helped, as there's a list of the function names in the source
code, but help() makes it unnecessary.

You still have to wonder, though, with as easy as this is, how the
gmpy documention ended up incomplete. I'm always reminded of something
I read in the National Lampoon:

"You know what a fuck-up you are at work, how would anything get
done if everyone was like you? Well, the sad fact is everyone _is_
just like you...including the air traffic controller who's supposed
to be tracking your flight but has just looked away because he
dropped a cigarette ash and burned a hole in his trousers..."

So I suppose I shouldn't complain, after all, I got something
positive out of it.

>
> --
> Nick Craig-Wood <nick at craig-wood.com> --
http://www.craig-wood.com/nick




More information about the Python-list mailing list