How this calculation works
Rational canonical form replaces a matrix by companion blocks without requiring its eigenvalues to belong to the rational numbers. The blocks are determined by a divisibility chain of monic invariant polynomials. This solver obtains determinantal divisors from polynomial minors of xI−A, divides successive divisors to recover the invariant factors, and constructs the associated companion matrix. It then solves the exact intertwining equations AP=PF and searches their solution space for an invertible P. The final similarity identity is checked with rational arithmetic.
d₁|d₂|…|dᵣ; F=diag(C(d₁),…,C(dᵣ)); AP=PF with P invertible over Q.A worked example
For A=((0,−1),(1,0)), the characteristic and minimal polynomials are both x²+1. There is one invariant factor, x²+1, whose companion matrix under the subdiagonal-one convention is exactly A. Thus F=A and P=I are valid. Its eigenvalues are not rational, but that creates no obstacle to a rational canonical form. By comparison, 2I has two invariant factors x−2 rather than a single degree-two companion block, because its minimal polynomial has degree one.
Good to know
Square rational matrices of order one through five. Polynomial determinant and gcd operations have exact fraction-growth bounds. The similarity-basis search uses at most 4,096 deterministic candidates from the intertwiner space; exhaustion raises a resource error. Companion convention is explicitly subdiagonal ones and negated coefficients in the final column. The invariant-factor chain is canonical; P and the displayed successful search candidate are not unique.
Reference: SymPy — polynomial Smith normal forms (opens in a new tab) ↗
Determinantal divisors recover more than the minimal polynomial
The kth determinantal divisor is the monic gcd of every k×k minor of xI−A; the zeroth is one. Consecutive quotients are the Smith invariant factors. Constant factors contribute no companion block. The nonconstant factors divide their successors, their degrees sum to the matrix order, their product is the characteristic polynomial, and the last one is the minimal polynomial. These relationships provide useful consistency checks on the complete block structure.
Two matrices can have the same characteristic polynomial but different invariant factors. The minimal polynomial alone can also fail to describe how the smaller blocks are distributed in larger dimensions. Reporting the full chain distinguishes these cases. Polynomial gcds are taken over Q[x], so nonzero rational scalars are units; making every factor monic removes sign differences caused by determinant orientation or another system’s Smith normalization.
Similarity changes coordinates; it does not diagonalize every matrix
A companion block encodes multiplication by x on residue classes modulo its polynomial. With basis 1,x,…,x^(d−1), the last column is the negative coefficient list and lower adjacent entries are one. A transposed companion convention is mathematically related but uses another basis. Compare both the convention and the identity AP=PF before treating an alternate display as a disagreement.
The exact intertwiner equations alone include singular matrices such as P=0, so solving them is insufficient. This calculator explicitly requires a nonzero determinant and checks the resulting product identity. The Matrix minimal polynomial calculator returns an important single polynomial, while this page reconstructs the full Frobenius block form and its basis. The Jordan normal form calculator provides a different decomposition when the supported eigenvalues split into rational linear factors.
A few questions, answered
Can the input have complex eigenvalues?
Yes. A rational matrix can have irreducible rational invariant polynomials such as x²+1. No complex eigenvalue approximation is needed.
Are invariant factors the diagonal entries of A?
No. They are polynomials derived from xI−A and are invariant under rational similarity. The displayed companion blocks are constructed from their coefficients.