-
galois.Poly.__call__(at: ElementLike | ArrayLike, field: type[Array] | None =
None
, elementwise: bool =True
) Array - galois.Poly.__call__(at: Poly) Poly
Evaluates the polynomial \(f(x)\) at \(x_0\) or the polynomial composition \(f(g(x))\).
- Parameters:¶
- at: ElementLike | ArrayLike¶
- at: Poly
A finite field scalar or array \(x_0\) to evaluate the polynomial at or the polynomial \(g(x)\) to evaluate the polynomial composition \(f(g(x))\).
- field: type[Array] | None =
None
¶ The Galois field to evaluate the polynomial over. The default is
None
which represents the polynomial’s current field, i.e.field
.- elementwise: bool =
True
¶ Indicates whether to evaluate \(x_0\) element-wise. The default is
True
. IfFalse
(only valid for square matrices), the polynomial indeterminate \(x\) is exponentiated using matrix powers (repeated matrix multiplication).
- Returns:¶
The result of the polynomial evaluation \(f(x_0)\). The resulting array has the same shape as \(x_0\). Or the polynomial composition \(f(g(x))\).
Examples¶
Create a polynomial over \(\mathrm{GF}(3^5)\).
In [1]: GF = galois.GF(3**5) In [2]: f = galois.Poly([37, 123, 0, 201], field=GF); f Out[2]: Poly(37x^3 + 123x^2 + 201, GF(3^5))
Evaluate the polynomial element-wise at \(x_0\).
In [3]: x0 = GF([185, 218, 84, 163]) In [4]: f(x0) Out[4]: GF([ 33, 163, 146, 96], order=3^5) # The equivalent calculation In [5]: GF(37)*x0**3 + GF(123)*x0**2 + GF(201) Out[5]: GF([ 33, 163, 146, 96], order=3^5)
Evaluate the polynomial at the square matrix \(X_0\).
In [6]: X0 = GF([[185, 218], [84, 163]]) # This is performed element-wise. Notice the values are equal to the vector x0. In [7]: f(X0) Out[7]: GF([[ 33, 163], [146, 96]], order=3^5) In [8]: f(X0, elementwise=False) Out[8]: GF([[103, 192], [156, 10]], order=3^5) # The equivalent calculation In [9]: GF(37)*np.linalg.matrix_power(X0, 3) + GF(123)*np.linalg.matrix_power(X0, 2) + GF(201)*GF.Identity(2) Out[9]: GF([[103, 192], [156, 10]], order=3^5)
Evaluate the polynomial \(f(x)\) at the polynomial \(g(x)\).
In [10]: g = galois.Poly([55, 0, 1], field=GF); g Out[10]: Poly(55x^2 + 1, GF(3^5)) In [11]: f(g) Out[11]: Poly(77x^6 + 5x^4 + 104x^2 + 1, GF(3^5)) # The equivalent calculation In [12]: GF(37)*g**3 + GF(123)*g**2 + GF(201) Out[12]: Poly(77x^6 + 5x^4 + 104x^2 + 1, GF(3^5))