-
classmethod galois.Poly.Roots(roots: ArrayLike, multiplicities: Sequence[int] | ndarray | None =
None
, field: Type[Array] | None =None
) Poly Constructs a monic polynomial over \(\mathrm{GF}(p^m)\) from its roots.
- Parameters¶
- 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)