def legendre(x, y): """ legendre(x, y) -> mpz Return the Legendre symbol (x|y). y is assumed to be an odd prime. """ x = _check_mpz('legendre', 'x', x) y = _check_mpz('legendre', 'y', y) if y <= 0 or not (y % 2): raise ValueError('legendre() expected y to be positive and odd') return gmp.mpz_legendre(x._mpz, y._mpz)
def jacobi(x, y): """ jacobi(x, y) -> mpz Return the Jacobi symbol (x|y). y must be odd and >0. """ x = _check_mpz('jacobi', 'x', x) y = _check_mpz('jacobi', 'y', y) if y <= 0 or not (y % 2): raise ValueError('jacobi() expected y to be positive and odd') return gmp.mpz_legendre(x._mpz, y._mpz)