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

How to install gmpy2 on Google Colab?

I am trying to install "gmpy2" on Google Colab via the command: !pip3 install gmpy2 I get the error: Collecting gmpy2 Downloading gmpy2-2.0.8.zip (280 kB) |████████████████████████████████| 280 kB 5.0 MB/s Building wheels for collected…
Dew Debra
  • 47
  • 5
0
votes
1 answer

PyCharm won't install gmpy2 - Tried all versions

I am trying to install the package called gmpy2, but PyCharm just won't. Tried googling and can't find anything that helps me (or I might just not be doing it right). I'm using Python 3.9 with PyCharm. Here's a picture of what PyCharm gives me as a…
0
votes
1 answer

Python: inverse a matrix with high precision floats

I am following a tutorial on how to work on multiple-precision arithmetic in Python. In the end I would like to have a numpy array with floats of arbitrary high precision and I need to inverse that matrix. Therefore we have: import sys import numpy…
maciek
  • 1,807
  • 2
  • 18
  • 30
0
votes
1 answer

How to compare various multiplication algorithms over a range of numbers

While going through a MIT lecture in MITOpencourseware (6.006 lecture 12), I came across the mention of 4 multiplication algorithms (to multiply two n-digit numbers) - Ordinary naive approach with O(n^2) complexity Karatsuba algorithm -…
Anirban Chakraborty
  • 539
  • 1
  • 5
  • 15
0
votes
0 answers

How to use gmpy2 in Heroku?

I'm trying to use gmpy2 as part of my Python packages in Heroku but I'm having issues with the building process. I'm using two different buildpacks: the standard Python buildpack and APT (heroku-buildpack-apt) so I can install the dependencies…
Rafa0809
  • 1,733
  • 21
  • 24
0
votes
1 answer

Cython same classes with different types

I have two cdef classes B and C whose methods are exactly the same. The only difference between them is the type of their attributes: one has mpz attributes, the other one int attributes. My first guess was to use an abstract class A which would be…
Tristan Nemoz
  • 1,844
  • 1
  • 6
  • 19
0
votes
1 answer

issues with .series() and conversion from mpmath

I came across the following seemingly bizarre behavior (this is a test case showing the basic issue). from sympy import * dz = symbols('dz') f = 1/(dz - (1.0+I)) f1.series(dz,0,1) this gives an error like "TypeError: gmpy.mpq() expects numeric or…
woody
  • 3
  • 2
0
votes
2 answers

Is it possible to loop through 10^8 possibilities to determine the correct answer?

I have a number which is 615 digits long. Throughout it, there are 8 places where digits are missing. I have to find out what the digits are. There are 10^8 possibilities. It is for an RSA problem. The number in question is the private key, and I…
jeary
  • 3
  • 2
0
votes
1 answer

gmpy2 qdiv() returns mpq where mpz would be possible

I wonder if I don't get something here... Why does qdiv(8,2) return an mpq instead of an mpz? See here: Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more…
cxxl
  • 4,939
  • 3
  • 31
  • 52
0
votes
1 answer

PyCharm can't locate gmpy2 (unresolved reference)

I'm using Ubuntu 16.04 and just need a downloaded simple encryption script in python to run. I installed pyCharm to run the scripts but its giving unresolved reference errors at gmpy2 The script is using gmpy2 which I installed using the command:…
StuckInPhDNoMore
  • 2,507
  • 4
  • 41
  • 73
0
votes
1 answer

How could I implement a xor operation of big integers with gmpy?

I want to xor two big integers. Just installed the gmpy2 library, but no mpz_xor operation anywhere. Am I missing something?
framontb
  • 1,817
  • 1
  • 15
  • 33
0
votes
1 answer

GMPY2 - How to avoid gmpy2.floor() returning mpfr instead of mpz?

After using gmpy2.floor() on an mpz variable: x = mpz(5) x = gmpy2.floor(x/256) x has the type mpfr and not mpz anymore, even though to my understanding, floor always returns integers. How can I avoid that? I'm afraid using x =…
netik
  • 1,736
  • 4
  • 22
  • 45
0
votes
2 answers

gmpy2 installs but can't find libmpc.so.3

I want to use gmpy2 with python 2.7 but when I try to import it I get: >>> import gmpy2 Traceback (most recent call last): File "", line 1, in ImportError: libmpc.so.3: cannot open shared object file: No such file or directory I…
R.Mckemey
  • 335
  • 1
  • 3
  • 14
0
votes
3 answers

Python - How to avoid discrepancy of base y**log base y of x, in gmpy2

The Following code examples my problem which does not occur between 10 power 10 and 10 power 11, but does for the example given in code and above it. I can't see where in my code I am not properly handling the retrieval of the original value. May…
ocopa
  • 75
  • 8
0
votes
1 answer

sharing gmpy2 multi-precision integer between processes without copying

Is it possible to share gmpy2 multiprecision integers (https://pypi.python.org/pypi/gmpy2) between processes (created by multiprocessing) without creating copies in memory? Each integer has about 750,000 bits. The integers are not modified by the…
rxu
  • 1,369
  • 1
  • 11
  • 29