classmethod galois.Poly.Roots(roots: ArrayLike, multiplicities: Sequence[int] | ndarray | None = None, field: type[Array] | None = None) Self

Constructs a monic polynomial over GF(pm) from its roots.

Parameters:
roots: ArrayLike

The roots of the desired polynomial.

multiplicities: Sequence[int] | ndarray | None = None

The corresponding root multiplicities. The default is None which corresponds to all ones.

field: type[Array] | None = None

The Galois field GF(pm) the polynomial is over.

  • None (default): If the roots are an Array, they won’t be modified. If the roots are not explicitly in a Galois field, they are assumed to be from GF(2) and are converted using galois.GF2(roots).

  • Array subclass: The roots are explicitly converted to this Galois field using field(roots).

Returns:

The polynomial f(x).

Notes

The polynomial f(x) with k roots {r1,r2,,rk} with multiplicities {m1,m2,,mk} is

f(x)=(xr1)m1(xr2)m2(xrk)mk=adxd+ad1xd1++a1x+a0

with degree d=i=1kmi.

Examples

Construct a polynomial over GF(2) from a list of its roots.

In [1]: roots = [0, 0, 1]

In [2]: f = galois.Poly.Roots(roots); f
Out[2]: Poly(x^3 + x^2, GF(2))

# Evaluate the polynomial at its roots
In [3]: f(roots)
Out[3]: GF([0, 0, 0], order=2)

Construct a polynomial over GF(35) from a list of its roots with specific multiplicities.

In [4]: GF = galois.GF(3**5)

In [5]: roots = [121, 198, 225]

In [6]: f = galois.Poly.Roots(roots, multiplicities=[1, 2, 1], field=GF); f
Out[6]: Poly(x^4 + 215x^3 + 90x^2 + 183x + 119, GF(3^5))

# Evaluate the polynomial at its roots
In [7]: f(roots)
Out[7]: GF([0, 0, 0], order=3^5)