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(60, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + 2x^3 + x^2 + x + 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(2α^4 + 2α^3 + α + 2, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + x^3 + 2x^2 + 2x + 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(α^136, order=3^5)

In : poly = a.characteristic_poly(); poly
Out: Poly(x^5 + x^4 + x^3 + 2x^2 + x + 2, 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([[114, 242,  24],
[184,  12, 203],
[ 40,  16,  37]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + 200x^2 + 165x + 115, 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([[            2α^3 + α + 2,      2α^3 + 2α^2 + α + 2,
α^4 + α + 2],
[     2α^4 + α^2 + 2α + 1,                    α + 1,
α^4 + 2α^3 + α^2 + α + 1],
[                       1,             2α^4 + α + 1,
α^2 + 2α]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + (α^3 + 2α^2 + 2α)x^2 + (2α^2 + 2α + 2)x + (α^4 + α^2 + 1), 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([[ α^47, α^200, α^195],
[  α^3,  α^46, α^203],
[α^213, α^162, α^191]], order=3^5)

In : poly = A.characteristic_poly(); poly
Out: Poly(x^3 + (α^86)x^2 + (α^180)x + α^145, 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)