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

Constructs a monic polynomial over \(\mathrm{GF}(p^m)\) 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 \(\mathrm{GF}(p^m)\) 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 \(\mathrm{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 \(\{r_1, r_2, \dots, r_k\}\) with multiplicities \(\{m_1, m_2, \dots, m_k\}\) is

\[\begin{split}f(x) &= (x - r_1)^{m_1} (x - r_2)^{m_2} \dots (x - r_k)^{m_k} \\ &= a_d x^d + a_{d-1} x^{d-1} + \dots + a_1 x + a_0\end{split}\]

with degree \(d = \sum_{i=1}^{k} m_i\).

Examples

Construct a polynomial over \(\mathrm{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 \(\mathrm{GF}(3^5)\) 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)