Arrays¶
- class galois.Array(numpy.ndarray)
An abstract
ndarray
subclass over a Galois field or Galois ring.
- galois.typing.ElementLike
A
Union
representing objects that can be coerced into a Galois field element.
- galois.typing.IterableLike
A
Union
representing iterable objects that can be coerced into a Galois field array.
Galois fields¶
- class galois.FieldArray(galois.Array)
An abstract
ndarray
subclass over .
- class galois.GF2(galois.FieldArray)
A
FieldArray
subclass over .
- galois.Field(order: int, *, ...) type[FieldArray]
- galois.Field(characteristic: int, degree, ...) type[FieldArray]
Alias of
GF()
.
- galois.GF(order: int, *, ...) type[FieldArray]
- galois.GF(characteristic: int, degree: int, ...) type[FieldArray]
Creates a
FieldArray
subclass for .
Primitive elements¶
- galois.primitive_element(irreducible_poly: Poly, ...) Poly
Finds a primitive element
of the Galois field with degree- irreducible polynomial over .
- galois.primitive_elements(irreducible_poly: Poly) list[Poly]
Finds all primitive elements
of the Galois field with degree- irreducible polynomial over .
- galois.is_primitive_element(element: PolyLike, ...) bool
Determines if
is a primitive element of the Galois field with degree- irreducible polynomial over .
Polynomials¶
- class galois.Poly
A univariate polynomial
over .
See also
The Number theory section contains many functions that operate on polynomials.
Irreducible polynomials¶
- galois.irreducible_poly(order: int, degree: int, ...) Poly
Returns a monic irreducible polynomial
over with degree .
- galois.irreducible_polys(order: int, degree, ...) Iterator[Poly]
Iterates through all monic irreducible polynomials
over with degree .
Primitive polynomials¶
- galois.conway_poly(characteristic: int, degree: int, ...) Poly
Returns the Conway polynomial
over with degree .
- galois.matlab_primitive_poly(characteristic: int, degree) Poly
Returns Matlab’s default primitive polynomial
over with degree .
- galois.primitive_poly(order: int, degree: int, ...) Poly
Returns a monic primitive polynomial
over with degree .
- galois.primitive_polys(order: int, degree, ...) Iterator[Poly]
Iterates through all monic primitive polynomials
over with degree .
Interpolating polynomials¶
- galois.lagrange_poly(x: Array, y: Array) Poly
Computes the Lagrange interpolating polynomial
such that .
Forward error correction¶
- class galois.BCH
A general
code over .
- class galois.ReedSolomon
A general
code over .
Linear sequences¶
- class galois.FLFSR
A Fibonacci linear-feedback shift register (LFSR).
- class galois.GLFSR
A Galois linear-feedback shift register (LFSR).
- galois.berlekamp_massey(sequence: FieldArray, ...) Poly
- galois.berlekamp_massey(sequence: FieldArray, output) FLFSR
- galois.berlekamp_massey(sequence: FieldArray, output) GLFSR
Finds the minimal polynomial
that produces the linear recurrent sequence .
Transforms¶
- galois.intt(X: ArrayLike, ...) FieldArray
Computes the Inverse Number-Theoretic Transform (INTT) of
.
-
galois.ntt(x: ArrayLike, size: int | None =
None
, ...) FieldArray Computes the Number-Theoretic Transform (NTT) of
.
Number theory¶
Divisibility¶
- galois.are_coprime(*values: int) bool
- galois.are_coprime(*values: Poly) bool
Determines if the arguments are pairwise coprime.
- galois.egcd(a: int, b: int) tuple[int, int, int]
- galois.egcd(...) tuple[galois._polys._poly.Poly, galois._polys._poly.Poly, galois._polys._poly.Poly]
Finds the multiplicands of
and such that .
- galois.gcd(a: int, b: int) int
- galois.gcd(a: Poly, b: Poly) Poly
Finds the greatest common divisor of
and .
- galois.lcm(*values: int) int
- galois.lcm(*values: Poly) Poly
Computes the least common multiple of the arguments.
- galois.prod(*values: int) int
- galois.prod(*values: Poly) Poly
Computes the product of the arguments.
- galois.totatives(n: int) list[int]
Returns the positive integers (totatives) in
that are coprime to .
Congruences¶
- galois.carmichael_lambda(n: int) int
Finds the smallest positive integer
such that for every integer in that is coprime to .
- galois.crt(remainders: Sequence[int], moduli: Sequence[int]) int
- galois.crt(remainders: Sequence[Poly], moduli) Poly
Solves the simultaneous system of congruences for
.
- galois.kronecker_symbol(a: int, n: int) int
Computes the Kronecker symbol
. The Kronecker symbol extends the Jacobi symbol for all .
Primitive roots¶
-
galois.primitive_roots(n: int, start: int =
1
, ...) Iterator[int] Iterates through all primitive roots modulo
in the range .
Integer arithmetic¶
Factorization¶
Prime factorization¶
- galois.factors(value: int) tuple[list[int], list[int]]
- galois.factors(...) tuple[list[galois._polys._poly.Poly], list[int]]
Computes the prime factors of a positive integer or the irreducible factors of a non-constant, monic polynomial.
Composite factorization¶
-
galois.divisor_sigma(n: int, k: int =
1
) int Returns the sum of
-th powers of the positive divisors of .
Specific factorization algorithms¶
- galois.perfect_power(n: int) tuple[int, int]
Returns the integer base
and exponent of . If is not a perfect power, then and .
-
galois.pollard_p1(n: int, B: int, B2: int | None =
None
) int Attempts to find a non-trivial factor of
if it has a prime factor such that is -smooth.
-
galois.pollard_rho(n: int, c: int =
1
) int Attempts to find a non-trivial factor of
using cycle detection.
Primes¶
Prime number generation¶
-
galois.mersenne_exponents(n: int | None =
None
) list[int] Returns all known Mersenne exponents
for .
- galois.next_prime(n: int) int
Returns the nearest prime
, such that .
- galois.prev_prime(n: int) int
Returns the nearest prime
, such that .
-
galois.random_prime(bits: int, seed: int | None =
None
) int Returns a random prime
with bits, such that .
Primality tests¶
- galois.is_composite(n: int) bool
Determines if
is composite.
- galois.is_perfect_power(n: int) bool
Determines if
is a perfect power with .
- galois.is_prime_power(n: int) bool
Determines if
is a prime power for prime and .
- galois.is_square_free(value: int) bool
- galois.is_square_free(value: Poly) bool
Determines if an integer or polynomial is square-free.
Specific primality tests¶
- galois.fermat_primality_test(n: int, ...) bool
Determines if
is composite using Fermat’s primality test.
-
galois.miller_rabin_primality_test(n: int, a: int =
2
, ...) bool Determines if
is composite using the Miller-Rabin primality test.
Configuration¶
- galois.get_printoptions() dict[str, Any]
Returns the current print options for the package. This function is the
galois
equivalent ofnumpy.get_printoptions()
.
- galois.printoptions(**kwargs) Generator[None, None, None]
A context manager to temporarily modify the print options for the package. This function is the
galois
equivalent ofnumpy.printoptions()
.
-
galois.set_printoptions(coeffs: 'desc' | 'asc' =
'desc'
) Modifies the print options for the package. This function is the
galois
equivalent ofnumpy.set_printoptions()
.