Questions tagged [gmpy]

GMPY and GMPY2 are C-coded Python extension modules that support fast multiple-precision arithmetic. GMPY only supports the GMP library and provides fast multiple-precision integer and rational arithmetic. GMPY2 adds support for fast, correctly rounded multiple-precision real and complex arithmetic.

About

GMPY is a legacy Python module that provides access to the GNU Multiple Precision (GMP) libary. GMP provides very fast and highly optimized routines for working with arbitrary precision integers (MPZ), rationals (MPQ), and (very limited) floating point numbers (MPF).

GMPY2 is the actively maintained replacement for GMPY. The limited floating point support from the GMP library has been replaced with correctly-rounded real arithmetic from the MPFR library. Correctly-rounded complex arithmetic from the MPC library is also available.

Links

73 questions
9
votes
3 answers

Does GMPY2 (or GMP) have a pow() function?

GMPY2 (or GMP) has a powmod function but I can't find anything for regular exponentiation aside from python's native pow. Does a function like this exist for mpz integers?
qwr
  • 9,525
  • 5
  • 58
  • 102
6
votes
4 answers

GMPY2 Not installing, mpir.h not found

I am trying to install gmpy2 on my Anaconda Python 3.5 distribution using pip. I was able to install other modules such as primefac perfectly. When I try to install gmpy2 this is what I get: (C:\Program Files\Anaconda3) C:\WINDOWS\system32>pip…
Hadi Khan
  • 577
  • 2
  • 8
  • 30
5
votes
4 answers

(the first 10-digit prime in e).com python google challenge 2004

I just come up to one of challenges that claimed to be used by google 2004 (the first 10-digit prime in e).com independent from that, I wanted to take the challenge and solve it with python >>> '%0.52f' %…
Elteroooo
  • 2,913
  • 3
  • 33
  • 40
3
votes
1 answer

gmpy2 mpfr values are limited to 301,033 digits of which the 301,032 digits are correct

I am writing a Python3 (64-bit) program to calculate pi to at least a million digits using the gmpy2 module on 64-bit Windows 10. I'm using the Chudnovsky algorithm. The series arithmetic is genius, easy to follow and straightforward to implement.…
stanely
  • 342
  • 1
  • 8
3
votes
2 answers

How to tackle calculating then verifying 10^8 solutions to find the one true answer?

I have a number which is 615 digits in length. Throughout the number, there 8 fixed places where a digit is missing. I have to find what those missing digits are. So there are 10^8 possibilities. After computing them I have to raise a ciphetext to…
trev
  • 33
  • 2
3
votes
1 answer

In python, how to call a function with an argument on a click event

I created the code below, but when I click on the click me button I get the following error message: TypeError: 'mpfr' object is not callable Would someone know what is wrong with the code? import gmpy2 as g from ipywidgets import widgets from…
Olivier
  • 607
  • 1
  • 6
  • 21
3
votes
2 answers

How do I know if mpmath is using gmpy or gmpy2?

I know of import mpmath as mp print mp.libmp.BACKEND but if I'm not mistaken it won't say if I'm using gmpy or gmpy2. Also, I that every time you use a newer version of something you don't get the version number next to it but since I can import…
evan54
  • 3,585
  • 5
  • 34
  • 61
3
votes
2 answers

Python unable to locate gmpy library

I want to use a python script which imports gmpy. However, python always tells me: ImportError: No module named 'gmpy' I am on Ubuntu 14.04 i686 and I tried to install gmpy over various ways: sudo pip install gmpy sudo pip install gmpy2 sudo…
Richard Laurant
  • 647
  • 1
  • 8
  • 21
3
votes
1 answer

How do numpy and GMPY2 compare with GMP in terms of speed?

I understand that GMPY2 supports the GMP library and numpy has fast numerical libraries. I want to know how the speed compares to actually writing C (or C++) code with GMP. Since Python is a scripting language, I don't think it will ever be as fast…
qwr
  • 9,525
  • 5
  • 58
  • 102
3
votes
2 answers

Most efficient way to find all factors with GMPY2 (or GMP)?

I know there's already a question similar to this, but I want to speed it up using GMPY2 (or something similar with GMP). Here is my current code, it's decent but can it be better? Edit: new code, checks divisors 2 and 3 def factors(n): result =…
qwr
  • 9,525
  • 5
  • 58
  • 102
2
votes
1 answer

Why is gmpy2 so slow at complex exponentiation?

I was using complex numbers in gmpy2 and noticed that it was slow. I narrowed it down the exponentiation operator. At first I thought it was just because it was complex. But then I compared it to mpmath which uses gmpy2 and it was so much faster: #…
Status
  • 912
  • 1
  • 12
  • 23
2
votes
1 answer

Is there a c++ gmp library function that does the same as the python gmpy2 library divm(...) function?

Just as the title says I am trying to find a function in the C++ gmp library that does the same thing as the gmpy2 python library's divm(...) function. I can't imagine that gmpy2 has this method and the gmp C++ library has nothing that can do this…
jamlx
  • 23
  • 2
2
votes
1 answer

Python 3.7: Unable to install gmpy2 in a venv in Windows 10

I'm trying to install gmpy2 in a virtual environment in Windows 10. Initially, I was getting the following error. Collecting gmpy2 Using cached…
Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
2
votes
1 answer

Python: "pip install gmpy" on Windows 10 returns "cl.exe' failed with exit status 2"

I've installed Pyhton 3.7 on Windows10 and when I run pip install gmpy the console return me this error: Collecting gmpy Using cached…
Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113
2
votes
1 answer

Python Numpy Exponential Value from Array of BigFloats

I'm trying to compute the natural log of the exponential plus the median of an array but precision of the floating point numbers has to be at 2000 or the answer will always be 0. Here is what I have so far: import bigfloat x =…
Kenneth Orton
  • 399
  • 1
  • 11
1
2 3 4 5