galois.Poly¶
-
class
galois.
Poly
(coeffs, field=None, order='desc')[source]¶ Bases:
object
A polynomial class with coefficients in any Galois field.
- Parameters
coeffs (array_like) – List of polynomial coefficients of type Galois field array, np.ndarray, list, or tuple. The first element is the highest-degree element if order=”desc” or the first element is the 0-th degree element if order=”asc”.
field (galois.GFBase, optional) – Optionally specify the field to which the coefficients belong. The default field is galois.GF2. If coeffs is a Galois field array, then that field is used and the field parameter is ignored.
order (str, optional) – The interpretation of the coefficient degrees, either “desc” (default) or “asc”. For “desc”, the first element of coeffs is the highest degree coefficient (x^(N-1)) and the last element is the 0-th degree element (x^0).
Examples
Create polynomials over GF(2)
# Construct a polynominal over GF(2) In [13]: a = galois.Poly([1,0,1,1]); a Out[13]: Poly(x^3 + x + 1, GF2) # Construct the same polynomial by only specifying its non-zero coefficients In [14]: b = galois.Poly.NonZero([1,1,1], [3,1,0]); b Out[14]: Poly(x^3 + x + 1, GF2)
Create polynomials over GF(7)
# Construct the GF(7) field In [15]: GF = galois.GF_factory(7, 1) # Construct a polynominal over GF(7) In [16]: a = galois.Poly([4,0,3,0,0,2], field=GF); a Out[16]: Poly(4x^5 + 3x^3 + 2, GF7) # Construct the same polynomial by only specifying its non-zero coefficients In [17]: b = galois.Poly.NonZero([4,3,2], [5,3,0], field=GF); b Out[17]: Poly(4x^5 + 3x^3 + 2, GF7)
Polynomial arithmetic
In [18]: a = galois.Poly([1,0,6,3], field=GF); a Out[18]: Poly(x^3 + 6x + 3, GF7) In [19]: b = galois.Poly([2,0,2], field=GF); b Out[19]: Poly(2x^2 + 2, GF7) In [20]: a + b Out[20]: Poly(x^3 + 2x^2 + 6x + 5, GF7) In [21]: a - b Out[21]: Poly(x^3 + 5x^2 + 6x + 1, GF7) # Compute the quotient of the polynomial division In [22]: a / b Out[22]: Poly(4x, GF7) # True division and floor division are equivalent In [23]: a / b == a // b Out[23]: True # Compute the remainder of the polynomial division In [24]: a % b Out[24]: Poly(5x + 3, GF7)
-
__init__
(coeffs, field=None, order='desc')[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
Decimal
(decimal[, field, order])NonZero
(coeffs, degrees[, field])Examples
__init__
(coeffs[, field, order])Initialize self.
divmod
(dividend, divisor)Attributes
The polynomial coefficients as a Galois field array, in descending order if order=”desc” or ascending order if order=”asc”.
The polynomial coefficients as a Galois field array in exponent-ascending order, i.e. the first element corresponds to x^0 and the last element corresponds to x^N-1.
The polynomial coefficients as a Galois field array in exponent-descending order, i.e. the first element corresponds to x^N-1 and the last element corresponds to x^0.
The degree of the polynomial, i.e. the highest degree with non-zero coefficient.
The finite field to which the coefficients belong.
The interpretation of the ordering of the polynomial coefficients.
-
classmethod
NonZero
(coeffs, degrees, field=<class 'galois.gf2.GF2'>)[source]¶ Examples
# Construct a polynomial over GF2 only specifying the non-zero terms In [25]: a = galois.Poly.NonZero([1,1,1], [3,1,0]); a Out[25]: Poly(x^3 + x + 1, GF2)
-
property
coeffs
¶ The polynomial coefficients as a Galois field array, in descending order if order=”desc” or ascending order if order=”asc”.
- Type
-
property
coeffs_asc
¶ The polynomial coefficients as a Galois field array in exponent-ascending order, i.e. the first element corresponds to x^0 and the last element corresponds to x^N-1.
- Type
-
property
coeffs_desc
¶ The polynomial coefficients as a Galois field array in exponent-descending order, i.e. the first element corresponds to x^N-1 and the last element corresponds to x^0.
- Type
-
property
decimal
¶
-
property
degree
¶ The degree of the polynomial, i.e. the highest degree with non-zero coefficient.
- Type
int
-
property
field
¶ The finite field to which the coefficients belong.
- Type
galois.GF2Base or galois.GFpBase
-
property
order
¶ The interpretation of the ordering of the polynomial coefficients. coeffs are in exponent-descending order if order=”desc” and in exponent-ascending order if order=”asc”.
- Type
str
-
property
str
¶