Connecting Tech Pros Worldwide Forums | Help | Site Map

Gmpy

Jean-Pierre Andreaux
Guest
 
Posts: n/a
#1: Jul 18 '05
Gmpy module was a wrapper of the GNU MP library. It seems that no
evolution is done on this module since 2001. Indeed, Gmpy is not
supported in Python 2.2 nor 2.3.

My question is the following: what is the better replacement solution
for manipulating long numbers. I want to do long numbers
exponentiations. Thanks in advance for your answers.

JP

Gary Herron
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Gmpy


On Thursday 07 August 2003 07:30 am, Jean-Pierre Andreaux wrote:[color=blue]
> Gmpy module was a wrapper of the GNU MP library. It seems that no
> evolution is done on this module since 2001. Indeed, Gmpy is not
> supported in Python 2.2 nor 2.3.
>
> My question is the following: what is the better replacement solution
> for manipulating long numbers. I want to do long numbers
> exponentiations. Thanks in advance for your answers.
>
> JP[/color]

Python has (arbitrarily) long integer support built right in. For instance:
[color=blue][color=green][color=darkred]
>>> ((2**10)**10)**10[/color][/color][/color]
10715086071862673209484250490600018105614048117055 33607443750388370351051124936122493198378815695858 12759467291755314682518714528569231404359845775746 98574803934567774824230985421074605062371141877954 18215304647498358194126739876755916554394607706291 45711964776865421676604298316526243868372056680693 76L

Notice the 'L' on the end of the result implies the value is a "long'
integer, not a 32-bit integer.

In recent versions of Python, arithmetic on normal integers will
convert to long integers when an overflow occurs.

Is this what you wanted?

Gary Herron





Alex Martelli
Guest
 
Posts: n/a
#3: Jul 18 '05

re: Gmpy


Gary Herron wrote:
...[color=blue]
> Python has (arbitrarily) long integer support built right in. For[/color]

Oh yes (it's the one bit that initially most attracted me, because
I needed to do some combinatorial-arithmetic computations...), and it's
become even better (faster) in 2.3, with Karatsuba's algorithm for
multiplication. However...:
[color=blue]
> instance:
>[color=green][color=darkred]
>>>> ((2**10)**10)**10[/color][/color]
>[/color]
10715086071862673209484250490600018105614048117055 33607443750388370351051124936122493198378815695858 12759467291755314682518714528569231404359845775746 98574803934567774824230985421074605062371141877954 18215304647498358194126739876755916554394607706291 45711964776865421676604298316526243868372056680693 76L

[alex@lancelot Lib]$ python timeit.py '((2**10)**10)**10'
10000 loops, best of 3: 98.5 usec per loop

[alex@lancelot Lib]$ python timeit.py -s'import gmpy'
'((gmpy.mpz(2)**10)**10)**10'
100000 loops, best of 3: 6.47 usec per loop

....gmpy's still way faster (at least on my Athlon machine -- I did
originally choose AMD over Intel essentially by benchmarking the
two possibilities on some heavy computations with GMP...), for this
kind of computation. This kind of speed improvement, one of more
than an order of magnitude, sometimes makes the difference between
a project being feasible or unfeasible, if computations of this kind
are right on a program's bottleneck. So, gmpy still has a place, IMHO.


Alex

Carl Banks
Guest
 
Posts: n/a
#4: Jul 18 '05

re: Gmpy


Jean-Pierre Andreaux wrote:[color=blue]
> Gmpy module was a wrapper of the GNU MP library. It seems that no
> evolution is done on this module since 2001. Indeed, Gmpy is not
> supported in Python 2.2 nor 2.3.
>
> My question is the following: what is the better replacement solution
> for manipulating long numbers. I want to do long numbers
> exponentiations. Thanks in advance for your answers.[/color]


An alternative is egenix mxNumber package, still in beta stage.

http://www.egenix.com/files/python/mxNumber.html

I couldn't use gmpy because I needed floating point, and mxNumber also
wraps the floating point functionality. It seemed to work ok.


--
CARL BANKS
"You don't run Microsoft Windows. Microsoft Windows runs you."
Alex Martelli
Guest
 
Posts: n/a
#5: Jul 18 '05

re: Gmpy


Carl Banks wrote:
[color=blue]
> Jean-Pierre Andreaux wrote:[color=green]
>> Gmpy module was a wrapper of the GNU MP library. It seems that no
>> evolution is done on this module since 2001. Indeed, Gmpy is not
>> supported in Python 2.2 nor 2.3.
>>
>> My question is the following: what is the better replacement solution
>> for manipulating long numbers. I want to do long numbers
>> exponentiations. Thanks in advance for your answers.[/color]
>
>
> An alternative is egenix mxNumber package, still in beta stage.
>
> http://www.egenix.com/files/python/mxNumber.html
>
> I couldn't use gmpy because I needed floating point, and mxNumber also
> wraps the floating point functionality. It seemed to work ok.[/color]

gmpy also wraps the floating-point functionality of GMP:
[color=blue][color=green][color=darkred]
>>> print gmpy.mpf(7,99)/3[/color][/color][/color]
2.333333333333333333333333333333333333333


Alex

Carl Banks
Guest
 
Posts: n/a
#6: Jul 18 '05

re: Gmpy


Alex Martelli wrote:[color=blue]
> Carl Banks wrote:
>[color=green]
>> Jean-Pierre Andreaux wrote:[color=darkred]
>>> Gmpy module was a wrapper of the GNU MP library. It seems that no
>>> evolution is done on this module since 2001. Indeed, Gmpy is not
>>> supported in Python 2.2 nor 2.3.
>>>
>>> My question is the following: what is the better replacement solution
>>> for manipulating long numbers. I want to do long numbers
>>> exponentiations. Thanks in advance for your answers.[/color]
>>
>>
>> An alternative is egenix mxNumber package, still in beta stage.
>>
>> http://www.egenix.com/files/python/mxNumber.html
>>
>> I couldn't use gmpy because I needed floating point, and mxNumber also
>> wraps the floating point functionality. It seemed to work ok.[/color]
>
> gmpy also wraps the floating-point functionality of GMP:
>[color=green][color=darkred]
>>>> print gmpy.mpf(7,99)/3[/color][/color]
> 2.333333333333333333333333333333333333333[/color]


I'm sorry--I was thinking of the mpz module. I remember looking at
gmpy but passed on it for some reason--probably something silly. In
any case, mxNumber worked well enough so I stuck with it.


--
CARL BANKS
"You don't run Microsoft Windows. Microsoft Windows runs you."
Ernie
Guest
 
Posts: n/a
#7: Jul 18 '05

re: Gmpy


Alex Martelli <aleax@aleax.it> wrote in message news:<v8AYa.29893$an6.1046141@news1.tin.it>...[color=blue]
> Carl Banks wrote:
>[color=green]
> > Jean-Pierre Andreaux wrote:[color=darkred]
> >> Gmpy module was a wrapper of the GNU MP library. It seems that no
> >> evolution is done on this module since 2001. Indeed, Gmpy is not
> >> supported in Python 2.2 nor 2.3.
> >>
> >> My question is the following: what is the better replacement solution
> >> for manipulating long numbers. I want to do long numbers
> >> exponentiations. Thanks in advance for your answers.[/color]
> >
> >
> > An alternative is egenix mxNumber package, still in beta stage.
> >
> > http://www.egenix.com/files/python/mxNumber.html
> >
> > I couldn't use gmpy because I needed floating point, and mxNumber also
> > wraps the floating point functionality. It seemed to work ok.[/color]
>
> gmpy also wraps the floating-point functionality of GMP:
>[color=green][color=darkred]
> >>> print gmpy.mpf(7,99)/3[/color][/color]
> 2.333333333333333333333333333333333333333[/color]

I am using the XR package from
http://more.btexact.com/people/briggsk2/XR-2.0.tgz and want to try out
the gmpy for comparison. However, trying to install
gmpy-sources-09a21.zip, results in an error:

running install
running build
running build_ext
building 'gmpy' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.3 -c gmpy.c -o
build/temp.linux-i686-2.3/gmpy.o
In file included from /usr/local/include/python2.3/Python.h:8,
from gmpy.c:101:
/usr/local/include/python2.3/pyconfig.h:844:1: warning:
"_POSIX_C_SOURCE" redefined
In file included from /usr/include/assert.h:36,
from gmpy.c:96:
/usr/include/features.h:171:1: warning: this is the location of the
previous definition
gmpy.c: In function `Pygmpy_rand':
gmpy.c:5053: structure has no member named `seed'
error: command 'gcc' failed with exit status 1

Ernie
Alex Martelli
Guest
 
Posts: n/a
#8: Jul 18 '05

re: Gmpy


Ernie wrote:
...[color=blue]
> the gmpy for comparison. However, trying to install
> gmpy-sources-09a21.zip, results in an error:[/color]
...[color=blue]
> gmpy.c: In function `Pygmpy_rand':
> gmpy.c:5053: structure has no member named `seed'
> error: command 'gcc' failed with exit status 1[/color]

Right -- I could SWEAR I've fixed this a zillion times
after the GMP library made an incompatible change in one
of its header files, but apparently the fix didn't
make it to a release. Could you try a CVS snapshot?
Meanwhile I hope to make time to put a fixed release
together in the weekend...


Thanks,

Alex

Alex Martelli
Guest
 
Posts: n/a
#9: Jul 18 '05

re: Gmpy


Carl Banks wrote:
...[color=blue][color=green][color=darkred]
>>> I couldn't use gmpy because I needed floating point, and mxNumber also
>>> wraps the floating point functionality. It seemed to work ok.[/color]
>>
>> gmpy also wraps the floating-point functionality of GMP:
>>[color=darkred]
>>>>> print gmpy.mpf(7,99)/3[/color]
>> 2.333333333333333333333333333333333333333[/color]
>
>
> I'm sorry--I was thinking of the mpz module. I remember looking at
> gmpy but passed on it for some reason--probably something silly. In
> any case, mxNumber worked well enough so I stuck with it.[/color]

I'm sure mxNumber works just fine, but for some users installing all
of mx-base first, then all of mx-experimental, might be a bit much,
perhaps, if all they need is the use of GMP (also, I don't think the
egenix stuff supports Python 2.3 yet? no doubt just temporarily).

So, anyway, I've just updated gmpy with a few outstanding issues (all
already solved in CVS, except one case of misdiagnosis when wrong
numbers of arguments were passed to some functions, kindly reported
by Paul Rubin -- but I hadn't done a "file release" to pick up the
CVS enhancements in quite a long while!) and released it as 1.0 alpha.
The released Windows binaries, by the way, now require Python 2.3.


Alex

Closed Thread