Repository navigation
A square matrix has a characteristic polynomial - #1625
Merged
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Matrix.CharacteristicPolynomial(x)isdet(x I - A), the monic one, written as a polynomial inxwith each coefficient simplified:It returns
nullfor a matrix that is not square, and for one in whichxalready occurs, since then the result would not be a polynomial inx. The convention is the monic one: the leading coefficient is1, the next is minus the trace, and the constant term is(-1)^n det(A).det(A - x I)is(-1)^ntimes 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),Determinantused Gaussian elimination. That left the pivots, which are polynomials inx, as divisions, so the characteristic polynomial had no value wherever a pivot vanished, even though it is defined everywhere.Determinantnow uses Bareiss's fraction-free elimination or Laplace expansion (#992, #999), and neither leaves a division.The tests check:
(-1)^n det(A);Terms are subtracted where the coefficient reads more simply negated, so the result reads
- 5 * xrather 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