473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3442
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

107150860718626 732094842504906 000181056140481 170553360744375 038837035105112 493612249319837 881569585812759 467291755314682 518714528569231 404359845775746 985748039345677 748242309854210 746050623711418 779541821530464 749835819412673 987675591655439 460770629145711 964776865421676 604298316526243 868372056680693 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

107150860718626 732094842504906 000181056140481 170553360744375 038837035105112 493612249319837 881569585812759 467291755314682 518714528569231 404359845775746 985748039345677 748242309854210 746050623711418 779541821530464 749835819412673 987675591655439 460770629145711 964776865421676 604298316526243 868372056680693 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.3333333333333 333333333333333 33333333333
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.3333333333333 333333333333333 33333333333

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.3333333333333 333333333333333 33333333333


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_SOURC E" 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.3333333333333 333333333333333 33333333333

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
1708
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 program operates as it should, which I guess is why it's a warning. Is there some reason why I shouldn't use gmpy numbers with relational operators? Is...
11
1752
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 check it at all). I can't reach sourceforge at the moment, so I have meanwhile put the exe file up at: ...
3
2421
by: mensanator | last post by:
Since the following discussion took place (unresolved), <http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3bd08ef3e4c478a/2b54deb522c9b9d9?lnk=st&q=divm()+memory+leak+group:comp.lang.python+author:mensanator&rnum=1&hl=en#2b54deb522c9b9d9> I've kept it in the back of my mind as I've been learning to use the base gmp library...
22
1941
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 version (one thing I must still look at is divm's behavior when its args are not mutually prime). It currently compiles w/o warnings, and passes...
0
1207
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 previously installed (I'm told the one that comes with fink works; I installed my own from sources, from the GMP's site at swox.com), and they're...
3
1883
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 laborious, e.g. by explicitly going through string-forms). I'm thinking about possible ways to fix this, in whole or in part, but, before I...
3
2216
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 ## ## ## 0 0 0 0 0 0 0 0 0 0 ## 0 1 2 3 1 5 6 7 2 9
3
3738
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 following error in conversion from float() to gmpy.mpf() or how to avoid it: import gmpy
7
1403
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 more information. 1 Traceback (most recent call last):
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.