mpyc.gmpy
index
github.com/lschoe/mpyc/blob/v0.11/mpyc/gmpy.py

This module collects all gmpy2 functions used by MPyC.
 
Stubs only using Python built-ins are provided in case the gmpy2 package is not available.
Efficient functions for factoring prime powers and rational reconstruction are also provided.

 
Modules
       
logging
math
os

 
Functions
       
factor_prime_power(x)
Return p and d for a prime power x = p**d.
gcdext(...)
gcdext(a, b, /) -> tuple[mpz, mpz, mpz]
 
Return a 3-element tuple (g,s,t) such that g == gcd(a,b)
and g == a*s + b*t.
invert(...)
invert(x, m, /) -> mpz
 
Return y such that x*y == 1 modulo m. Raises `ZeroDivisionError` if no
inverse exists.
iroot(...)
iroot(x,n,/) -> tuple[mpz, bool]
 
Return the integer n-th root of x and boolean value that is `True`
iff the root is exact. x >= 0. n > 0.
is_prime(...)
is_prime(x, n=25, /) -> bool
 
Return `True` if x is *probably* prime, else `False` if x is
definitely composite. x is checked for small divisors and up
to n Miller-Rabin tests are performed.
is_square(object, /)
is_square(x, /) -> bool
 
Returns `True` if x is a perfect square, else return `False`.
isqrt(object, /)
isqrt(x, /) -> mpz
 
Return the integer square root of a non-negative integer x.
jacobi(...)
jacobi(x, y, /) -> mpz
 
Return the Jacobi symbol (x|y). y must be odd and >0.
kronecker(...)
kronecker(x, y, /) -> mpz
 
Return the Kronecker-Jacobi symbol (x|y).
legendre(...)
legendre(x, y, /) -> mpz
 
Return the Legendre symbol (x|y). y is assumed to be an odd prime.
next_prime(object, /)
next_prime(x, /) -> mpz
 
Return the next *probable* prime number > x.
powmod(...)
powmod(x, y, m, /) -> mpz
 
Return (x**y) mod m. Same as the three argument version of Python's
built-in `pow`, but converts all three arguments to `mpz`.
prev_prime(object, /)
prev_prime(x, /) -> mpz
 
Return the previous *probable* prime number < x.
Only present when compiled with GMP 6.3.0 or later.
ratrec(x, y, N=None, D=None)
Return rational reconstruction (n, d) of x modulo y.
That is,  n/d = x (mod y) with -N <= n <= N and 0 < d <= D,
provided 2*N*D < y.
 
Default N=D=None will set both N and D to sqrt(y/2) approximately.
version()
version() -> str
 
Return string giving current GMPY2 version.