galois.FieldArray.characteristic_poly() Poly

Computes the characteristic polynomial of a finite field element $$a$$ or a square matrix $$\mathbf{A}$$.

Returns:

For scalar inputs, the degree-$$m$$ characteristic polynomial $$c_a(x)$$ of $$a$$ over $$\mathrm{GF}(p)$$. For square $$n \times n$$ matrix inputs, the degree-$$n$$ characteristic polynomial $$c_A(x)$$ of $$\mathbf{A}$$ over $$\mathrm{GF}(p^m)$$.

Raises:

ValueError – If the array is not a single finite field element (scalar 0-D array) or a square $$n \times n$$ matrix (2-D array).

An element $$a$$ of $$\mathrm{GF}(p^m)$$ has characteristic polynomial $$c_a(x)$$ over $$\mathrm{GF}(p)$$. The characteristic polynomial when evaluated in $$\mathrm{GF}(p^m)$$ annihilates $$a$$, that is $$c_a(a) = 0$$. In prime fields $$\mathrm{GF}(p)$$, the characteristic polynomial of $$a$$ is simply $$c_a(x) = x - a$$.

An $$n \times n$$ matrix $$\mathbf{A}$$ has characteristic polynomial $$c_A(x) = \textrm{det}(x\mathbf{I} - \mathbf{A})$$ over $$\mathrm{GF}(p^m)$$. The constant coefficient of the characteristic polynomial is $$\textrm{det}(-\mathbf{A})$$. The $$x^{n-1}$$ coefficient of the characteristic polynomial is $$-\textrm{Tr}(\mathbf{A})$$. The characteristic polynomial annihilates $$\mathbf{A}$$, that is $$c_A(\mathbf{A}) = \mathbf{0}$$.

Examples

The characteristic polynomial of the element $$a$$.

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

In : a = GF.Random(); a
Out: GF(160, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + 2x^3 + 2x^2 + 2, GF(3))

# The characteristic polynomial annihilates a
In : poly(a, field=GF)
Out: GF(0, order=3^5)

In : GF = galois.GF(3**5, repr="poly")

In : a = GF.Random(); a
Out: GF(α^3 + α, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + 2x^3 + 2x^2 + x + 1, GF(3))

# The characteristic polynomial annihilates a
In : poly(a, field=GF)
Out: GF(0, order=3^5)

In : GF = galois.GF(3**5, repr="power")

In : a = GF.Random(); a
Out: GF(α^231, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + 2x^4 + 2x^3 + 2x^2 + 1, GF(3))

# The characteristic polynomial annihilates a
In : poly(a, field=GF)
Out: GF(0, order=3^5)


The characteristic polynomial of the square matrix $$\mathbf{A}$$.

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

In : A = GF.Random((3,3)); A
Out:
GF([[ 59, 184,  50],
[224, 150,   0],
[ 98,   6, 165]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + 79x^2 + 2x + 11, GF(3^5))

# The x^0 coefficient is det(-A)
In : poly.coeffs[-1] == np.linalg.det(-A)
Out: True

# The x^n-1 coefficient is -Tr(A)
In : poly.coeffs == -np.trace(A)
Out: True

# The characteristic polynomial annihilates the matrix A
In : poly(A, elementwise=False)
Out:
GF([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]], order=3^5)

In : GF = galois.GF(3**5, repr="poly")

In : A = GF.Random((3,3)); A
Out:
GF([[      α^4 + α^3 + 2α^2 + α,     2α^4 + 2α^3 + 2α^2 + α,
α^4 + 2α^2 + 2α + 1],
[       2α^3 + α^2 + 2α + 1, α^4 + 2α^3 + 2α^2 + 2α + 2,
α^3 + α + 1],
[  α^4 + α^3 + 2α^2 + α + 2,             2α^4 + α^2 + 1,
α^4 + α^3 + 2α^2 + α + 1]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + (2α^3 + 2α)x^2 + (α^2 + 2α + 2)x + (2α^2 + α + 2), GF(3^5))

# The x^0 coefficient is det(-A)
In : poly.coeffs[-1] == np.linalg.det(-A)
Out: True

# The x^n-1 coefficient is -Tr(A)
In : poly.coeffs == -np.trace(A)
Out: True

# The characteristic polynomial annihilates the matrix A
In : poly(A, elementwise=False)
Out:
GF([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]], order=3^5)

In : GF = galois.GF(3**5, repr="power")

In : A = GF.Random((3,3)); A
Out:
GF([[ α^64,  α^53, α^152],
[α^197,  α^80, α^212],
[α^129, α^224,  α^39]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + (α^25)x^2 + (α^161)x + α^229, GF(3^5))

# The x^0 coefficient is det(-A)
In : poly.coeffs[-1] == np.linalg.det(-A)
Out: True

# The x^n-1 coefficient is -Tr(A)
In : poly.coeffs == -np.trace(A)
Out: True

# The characteristic polynomial annihilates the matrix A
In : poly(A, elementwise=False)
Out:
GF([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]], order=3^5)