-
classmethod galois.Poly.Str(string: str, field: type[Array] | None =
None) Self Constructs a polynomial over \(\mathrm{GF}(p^m)\) from its string representation.
Notes¶
Str()and__str__()are inverse operations.The string parsing rules include:
Either
^or**may be used for indicating the polynomial degrees. For example,"13x^3 + 117"or"13x**3 + 117".Multiplication operators
*may be used between coefficients and the polynomial indeterminatex, but are not required. For example,"13x^3 + 117"or"13*x^3 + 117".Polynomial coefficients of 1 may be specified or omitted. For example,
"x^3 + 117"or"1*x^3 + 117".The polynomial indeterminate can be any single character, but must be consistent. For example,
"13x^3 + 117"or"13y^3 + 117".Spaces are not required between terms. For example,
"13x^3 + 117"or"13x^3+117".Any combination of the above rules is acceptable.
Examples¶
Construct a polynomial over \(\mathrm{GF}(2)\) from its string representation.
In [1]: f = galois.Poly.Str("x^2 + 1"); f Out[1]: Poly(x^2 + 1, GF(2)) In [2]: str(f) Out[2]: 'x^2 + 1'Construct a polynomial over \(\mathrm{GF}(3^5)\) from its string representation.
In [3]: GF = galois.GF(3**5) In [4]: f = galois.Poly.Str("13x^3 + 117", field=GF); f Out[4]: Poly(13x^3 + 117, GF(3^5)) In [5]: str(f) Out[5]: '13x^3 + 117'