Skip to content

A square matrix has a characteristic polynomial - #1625

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
the-characteristic-polynomial
Sep 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
the-characteristic-polynomial

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Matrix.CharacteristicPolynomial(x) is det(x I - A), the monic one, written as a polynomial in x with each coefficient simplified:

[[1, 2], [3, 4]]      x ^ 2 - 5 * x - 2
[[a, b], [c, d]]      x ^ 2 - (a + d) * x + d * a - b * c

It returns null for a matrix that is not square, and for one in which x already occurs, since then the result would not be a polynomial in x. The convention is the monic one: the leading coefficient is 1, the next is minus the trace, and the constant term is (-1)^n det(A). det(A - x I) is (-1)^n times it. The monic polynomial is the one the Cayley–Hamilton theorem and the minimal polynomial are stated with.

Why it works now and didn't in August. It is the determinant of x I - A. When I tried it then (#381), Determinant used Gaussian elimination. That left the pivots, which are polynomials in x, as divisions, so the characteristic polynomial had no value wherever a pivot vanished, even though it is defined everywhere. Determinant now uses Bareiss's fraction-free elimination or Laplace expansion (#992, #999), and neither leaves a division.

The tests check:

  • the 2×2 trace-and-determinant form;
  • a value at the diagonal entries, where the old pivots vanished;
  • the diagonal of a triangular matrix as its roots, and the constant term (-1)^n det(A);
  • the two refusals.

Terms are subtracted where the coefficient reads more simply negated, so the result reads - 5 * x rather than + (-5) * x.

The API is additive, so there is no BREAKING entry. Targeted tests (CharacteristicPolynomialTest, matrix, determinant, public API): 222 passed. It builds on every target framework.

Closes #381.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Matrix.CharacteristicPolynomial(x) is det(x I - A), the monic one, written
as a polynomial in x with each coefficient simplified: [[1, 2], [3, 4]]
gives x ^ 2 - 5 * x - 2, and [[a, b], [c, d]] gives
x ^ 2 - (a + d) * x + d * a - b * c. It is null for a matrix that is not
square, and where x already occurs in the matrix.

It is the determinant of x I - A, which Bareiss' elimination or Laplace
expansion computes without leaving a division. Gaussian elimination left
its pivots -- polynomials in x -- as divisions, and a polynomial computed
through them had no value where one vanished; that is what stopped this
in August, and the determinant no longer divides.

Closes #381.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet added this to the 2.6.0 milestone Sep 30, 2026
@Rafael-SOWNet
Rafael-SOWNet merged commit c7b18bb into master Sep 30, 2026
31 checks passed
Rafael-SOWNet added a commit that referenced this pull request Oct 22, 2026
A matrix had a characteristic polynomial (#1625) and no eigenvalues.
Matrix.Eigenvalues is the set of its roots in a variable of its own,
solved by the equation solver: radicals up to the fourth degree, and past
it where the polynomial factors. The characteristic polynomial divides by
nothing, so the roots carry no condition an elimination's pivots would
bring: [[0, J], [J, 0]] has sqrt(J^2) and -sqrt(J^2), which hold at J = 0
too. A repeated root is one member of the set; a matrix that is not
square has none.

The MCP server solved the characteristic polynomial itself, waiting for
this; am_eigenvalues now takes the library's, and its README lists the
workarounds that remain.

Fixes #1676.


Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Characteristic polynomial

1 participant