## Compute the Jordan and rational canonical forms of a given matrix over QQ

Let $A = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ -2 & -2 & 0 & 1 \\ -2 & 0 & -1 & -2 \end{bmatrix}$. Compute the Jordan and rational canonical forms of $A$ over $\mathbb{Q}$.

Let $P = \dfrac{1}{4} \begin{bmatrix} 0 & -2 & 0 & 4 \\ -8 & -4 & -4 & -4 \\ 0 & 1 & 0 & 0 \\ -1 & -3 & 0 & 0 \end{bmatrix}$. Evidently, $P^{-1}AP = \begin{bmatrix} -1 & 1 & 0 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$ is in Jordan canonical form. Thus the elementary divisors of $A$ are $(x+1)^2$, $x-1$, and $x-1$, so that the invariant factors of $A$ are $(x+1)^2(x-1)$ and $x-1$. So the rational canonical form of $A$ is $\begin{bmatrix} 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & -1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}$. (Computations carried out by WolframAlpha; see here.)