473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Gmpy

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
Jul 18 '05 #1
8 3434
On Thursday 07 August 2003 07:30 am, Jean-Pierre Andreaux wrote:
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


Python has (arbitrarily) long integer support built right in. For instance:
((2**10)**10)**10

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

Jul 18 '05 #2
Gary Herron wrote:
...
Python has (arbitrarily) long integer support built right in. For
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...:
instance:
((2**10)**10)**10

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

Jul 18 '05 #3
Jean-Pierre Andreaux wrote:
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.

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."
Jul 18 '05 #4
Carl Banks wrote:
Jean-Pierre Andreaux wrote:
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.

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.


gmpy also wraps the floating-point functionality of GMP:
print gmpy.mpf(7,99)/3

2.333333333333333333333333333333333333333
Alex

Jul 18 '05 #5
Alex Martelli wrote:
Carl Banks wrote:
Jean-Pierre Andreaux wrote:
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.

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.


gmpy also wraps the floating-point functionality of GMP:
print gmpy.mpf(7,99)/3

2.333333333333333333333333333333333333333

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."
Jul 18 '05 #6
Alex Martelli <al***@aleax.it> wrote in message news:<v8*********************@news1.tin.it>...
Carl Banks wrote:
Jean-Pierre Andreaux wrote:
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.

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.


gmpy also wraps the floating-point functionality of GMP:
print gmpy.mpf(7,99)/3

2.333333333333333333333333333333333333333


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
Jul 18 '05 #7
Ernie wrote:
...
the gmpy for comparison. However, trying to install
gmpy-sources-09a21.zip, results in an error: ... gmpy.c: In function `Pygmpy_rand':
gmpy.c:5053: structure has no member named `seed'
error: command 'gcc' failed with exit status 1


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

Jul 18 '05 #8
Carl Banks wrote:
...
I couldn't use gmpy because I needed floating point, and mxNumber also
wraps the floating point functionality. It seemed to work ok.


gmpy also wraps the floating-point functionality of GMP:
> print gmpy.mpf(7,99)/3

2.333333333333333333333333333333333333333

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.


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

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mensanator | last post by:
In the program that follows, I get the following warning message: collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1 while b>1: In this case, b is a gmpy.mpz number. The...
11
by: Alex Martelli | last post by:
Thanks to David Bolen, who did the build, I have been able to make available a win32 packaging for gmpy 1.0 on python 2.4 alpha 2 (should work on any later Python 2.4 as well, but I have no way to...
3
by: mensanator | last post by:
Since the following discussion took place (unresolved), ...
22
by: Alex Martelli | last post by:
I have fixed almost all of the outstanding bugreports and feature request for gmpy: divm doesn't leak memory any more, truediv and floordiv are implemented for all types, etc -- in the current CVS...
0
by: Alex Martelli | last post by:
I've added to gmpy.sf.net two binary packages of gmpy for Mac OS X 10.4, one for the Python 2.3.5 that comes with the system and one for Bob Ippolito's build of 2.4.1. They still need GMP to be...
3
by: Alex Martelli | last post by:
As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor vice versa (the conversions are all possible, but a bit...
3
by: mensanator | last post by:
## Holy Mother of Pearl! ## ## >>> for i in range(10): ## for j in range(10): ## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)), ## print ## ## ## ...
3
by: zakad | last post by:
python 2.5.2 ubuntu 8.04 LTS (1) I find that python/gmpy is about 3 times slower than c++/gmp. Is this the general experience, or am I doing something wrong? (2) I am unable to understand the...
7
by: | last post by:
Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) on linux2 Type "help", "copyright", "credits" or "license" for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.