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
2
votes
1 answer

Does gmpy2 have "e=2.1718..." constant?

It does have Euler–Mascheroni constant, but I cannot find whether it has exp(1) as well.
user272651
  • 312
  • 2
  • 5
2
votes
1 answer

Is gmpy2 suitable for implementing RSA in python?

More specifically, is the gmpy2.next_prime function good enough to find the large primes needed? Or should I be using one of the other many gmpy2.*_prp functions? For example, is the following code good enough for finding suitable primes for…
Broseph
  • 1,655
  • 1
  • 18
  • 38
2
votes
1 answer

How to boost efficiency for large number modulus multiplications in Python

I am using python3 without any tailored library for some simple arithmetic. The operation that dominates computational efficiency is a multiplication of many 2048 bit values: length=len(array) res=1 for x in range(length): …
curious
  • 1,524
  • 6
  • 21
  • 45
1
vote
2 answers

Preventing overflow of large integers in (GPU) optimized methods such as gmpy2 and numba

I am trying to check whether a large integer is a perfect square using gmpy2 in a JIT-decorated (optimized) routine using numba. The example here is for illustrative purposes only (from a theoretical point of view, such equations or elliptic curves…
Eldar Sultanow
  • 205
  • 2
  • 9
1
vote
3 answers

How to check if a variable is an instance of mpfr in Python 3?

I want to know how to check whether a variable is of type mpfr or not, this might sound trivial but a simple isinstance(v, mpfr) can't do the trick. Example: create a variable that is an instance of mpfr, how to verify said variable is an instance…
Ξένη Γήινος
  • 2,181
  • 1
  • 9
  • 35
1
vote
1 answer

Pylint cannot recognize gmpy2 members

I use pylint and gmpy2 on Kali Linux(WSL2). Pylint makes many complaints about being unable to find gmpy2 members. How can I avoid this? Here is a little example: import gmpy2 print(gmpy2.is_even(6)) And the result of pylint is tst.py:2:6: E1101:…
FantasqueX
  • 56
  • 1
  • 5
1
vote
1 answer

Has anyone encountered the same Error while installing ludwig on colab?

I'm getting the below error while installing ludwig on colab. Tried a few things but not able to resolve this. ERROR: Command "/usr/bin/python3 -u -c 'import setuptools,…
1
vote
1 answer

How to get the gmpy2 module in RPI2 Buildroot

I am unable to get the gmpy2 Python module working in a Buildroot build for Raspberry Pi2. Buildroot does not include the gmpy2 module by default. Buildroot does not include the GCC as well, so I compiled the gmpy2 module from source on Raspbian on…
user0
  • 97
  • 9
1
vote
1 answer

How can I set the precision of a number to have 10 decimal digits using the python module gmpy2

I created the following piece of python code. It should first set the precision of numbers to 10 decimal digits, but printing pi shows 3.156, which only has 3 decimal digits! Would someone please let me know what I'm doing wrong. import gmpy2 as…
Olivier
  • 607
  • 1
  • 6
  • 21
1
vote
1 answer

Storing really huge ints in MySQL

Is it possible to efficiently store big ints in MySQL? Not big as in bigint, more like 1000th Catalan number or so, and there are at least hundreds of them. More likely, thousands. The speed of storing and loading values is a priority. The numbers…
Synedraacus
  • 975
  • 1
  • 8
  • 21
1
vote
1 answer

Installing gmpy2 on windows using pre-compiled binaries

I am trying to install the gmpy2 package as its an requirement for the PHE package. As suggested in "GMPY2 not installing", I have tried to install it via pre-compliled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/. However when I try to…
ARedder
  • 113
  • 1
  • 5
1
vote
1 answer

Define a function based on available modules

I have a function I need to calculate which has to work with fairly large numbers (something like 200^200). I found i can deal with it fairly well using the Decimal package, however the function is quite slow. I therefore installed the GMPY2…
Nicolo Castro
  • 195
  • 1
  • 3
  • 8
1
vote
1 answer

Fastest way to convert gmpy2 mpz to a bigendian byte-array (bytes)?

I tried several different approaches, from def ToByteArray(x): x = int(x) return x.to_bytes((x.bit_length() + 7) // 8, byteorder='big') or diving x by 256 and building a new bytearray in a loop but it just feels slow compared to the…
user66875
  • 2,772
  • 3
  • 29
  • 55
1
vote
1 answer

How to get abs() of an mpz in GMPY2?

I need to get the absolute value of an mpz object in GMPY2 but I cannot find any function like abs(). How can this be done?
netik
  • 1,736
  • 4
  • 22
  • 45
1
vote
1 answer

Installing gmpy with an Anaconda distribution of Python 2 (Windows)

I am trying to use a program called CatMAP that makes heavy use of the gmpy dependency (I think it's gmpy, not gmpy2 based on the installation instructions). I have Python 2.7.12 via Anaconda but am having a lot of trouble installing gmpy. Doing…
Argon
  • 405
  • 1
  • 6
  • 18