Prime number module

Alex Martelli aleax at aleax.it
Wed Oct 1 08:54:16 EDT 2003


Lulu of the Lotus-Eaters wrote:

> |Lulu of the Lotus-Eaters wrote:
> |> Along those lines, what's the quickest way to count bits in Python?
> 
> Alex Martelli <aleax at aleax.it> wrote previously:
> |Probably gmpy's popcount function.
> 
> What about fast AND portable?
> 
> (I'm sure gmpy can be installed lots of places, but not necessarily by
> receivers of Python code).

Why not?  gmpy's downloads include a self-contained .pyd for Windows
users (the ones who typically lack easy access to a C compiler) -- don't
most users of Linux, MacOs and other BSD's, etc, typically have gcc
available to install extensions if they want...?  Or are you worrying
about the operations' availability to users of Jython...?

I see you guys are having a great time concocting pure-Python ways to
count bits, etc -- but GMP, the library underying gmpy, has carefully
tuned machine-code accelerations for many important operations and
platforms... if one really needs to perform advanced multi-precision
arithmetic, as opposed to just playing with it, GMP is just too
precious a resource to ignore it.  Given how widespread Java is, I would
not be surprised if libraries of similar quality were available there
(with native-methods and all) -- I just don't know of any because I
never needed them, so didn't research the issue.

I do acknowlegde the usefulness of pure Python (AND readable, NOT
distorted for fun & optimization-profit:-) code in *teaching* even 
the lowest-level concepts of multi-precision arithmetic & bit-fiddling.
And Python is ideal for playing with higher-level architectures, such
as you guys have been doing about various potential ways to store
compressed pre-computed representations of primes.  Finally, one day,
if and when pypy triumphs, one will no doubt need to start with pure
Python code (most likely SIMPLE, NON-TRICKY pure Python code) in
order to obtain maximum speed.

But from a pragmatic point of view, I'll keep using gmpy for the
foreseeable future, thanks;-).


Alex






More information about the Python-list mailing list