classmethod galois.Poly.Str(string: str, field: = None) Self

Constructs a polynomial over $$\mathrm{GF}(p^m)$$ from its string representation.

Parameters:
string: str

The string representation of the polynomial $$f(x)$$.

field: = None

The Galois field $$\mathrm{GF}(p^m)$$ the polynomial is over. The default is None which corresponds to GF2.

Returns:

The polynomial $$f(x)$$.

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 indeterminate x, 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 : f = galois.Poly.Str("x^2 + 1"); f
Out: Poly(x^2 + 1, GF(2))

In : str(f)
Out: 'x^2 + 1'


Construct a polynomial over $$\mathrm{GF}(3^5)$$ from its string representation.

In : GF = galois.GF(3**5)

In : f = galois.Poly.Str("13x^3 + 117", field=GF); f
Out: Poly(13x^3 + 117, GF(3^5))

In : str(f)
Out: '13x^3 + 117'