Prove2Me
Navigate
MissionsFormalpediaUsersMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Matrix similarity, Jordan blocks, and Jordan matrices

Definition
HefferonLinAlg_jordan

by tianyipeng · Aug 7, 2026 · Mathlib c5ea003 (Lean v4.30.0)

jordan-formlinear-algebramatricessimilarity

The vocabulary of Hefferon's Chapter Five, Section IV.2, stated over an arbitrary commutative ring and an arbitrary finite index type so that later work can reuse it: only the theorems need C\mathbb{C}C. Similarity is factored out as its own definition (B=P−1APB = P^{-1}APB=P−1AP for some PPP of unit determinant), so statements about similarity alone can be phrased against it. A Jordan block of size mmm with eigenvalue λ\lambdaλ is the m×mm \times mm×m matrix carrying λ\lambdaλ down the diagonal and 111 on the subdiagonal; Hefferon places the ones below the diagonal, matching his convention that a nilpotent map carries each string basis vector to the next. A Jordan matrix is assembled from finitely many such blocks: given a block count kkk, sizes sz:Fin k→Nsz : \mathrm{Fin}\,k \to \mathbb{N}sz:Fink→N and eigenvalues λ:Fin k→C\lambda : \mathrm{Fin}\,k \to \mathbb{C}λ:Fink→C, it is indexed by Σ i, Fin(sz i)\Sigma\, i,\ \mathrm{Fin}(sz\,i)Σi, Fin(szi) and is the block diagonal of those blocks. The block data is a Jordan form of AAA when every block is nonempty and, after a reindexing of the coordinates, some change of basis carries AAA to that Jordan matrix; AAA has a Jordan form when such data exists. Nonemptiness is what makes the data an invariant -- without it one could pad any Jordan form with empty blocks carrying arbitrary eigenvalues. Finally jordanBlocks is the multiset of (size,eigenvalue)(\text{size}, \text{eigenvalue})(size,eigenvalue) pairs, which is what discards the ordering of the blocks.

Definition code
import Mathlib.Data.Matrix.Basic
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Complex.Basic
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse

namespace HefferonLinAlg

open Matrix

variable {R : Type*}

/-- Two square matrices are **similar** when a change of basis carries one to the
other: `B = P⁻¹ A P` for some `P` with unit determinant.  Kept separate from the
Jordan-form vocabulary below so that any statement about matrix similarity — that
it is an equivalence relation, that it preserves the determinant, trace, rank or
characteristic polynomial — can be phrased against it. -/
def IsSimilar [CommRing R] {ι : Type*} [Fintype ι] [DecidableEq ι]
    (A B : Matrix ι ι R) : Prop :=
  ∃ P : Matrix ι ι R, IsUnit P.det ∧ P⁻¹ * A * P = B

/-- The `m × m` **Jordan block** with eigenvalue `lam`: `lam` down the diagonal and
`1` on the subdiagonal.  Hefferon puts the ones *below* the diagonal (Five.IV.2),
matching the book's convention that a nilpotent map carries each string basis
vector to the next one.  Stated over an arbitrary scalar type so that the same
block is available for real, rational or general-field Jordan theory. -/
def jordanBlock [Zero R] [One R] (m : ℕ) (lam : R) : Matrix (Fin m) (Fin m) R :=
  Matrix.of fun i j => if i = j then lam else if (i : ℕ) = (j : ℕ) + 1 then 1 else 0

@[simp] theorem jordanBlock_apply [Zero R] [One R] {m : ℕ} (lam : R) (i j : Fin m) :
    jordanBlock m lam i j =
      if i = j then lam else if (i : ℕ) = (j : ℕ) + 1 then 1 else 0 :=
  rfl

/-- The index type of a Jordan matrix with `k` blocks of sizes `sz`. -/
abbrev jordanIndex {k : ℕ} (sz : Fin k → ℕ) : Type := Σ i : Fin k, Fin (sz i)

/-- The block-diagonal **Jordan matrix** with `k` blocks, the `i`-th of size `sz i`
and eigenvalue `lam i`. -/
def jordanMatrix [Zero R] [One R] {k : ℕ} (sz : Fin k → ℕ) (lam : Fin k → R) :
    Matrix (jordanIndex sz) (jordanIndex sz) R :=
  Matrix.blockDiagonal' fun i => jordanBlock (sz i) (lam i)

@[simp] theorem jordanMatrix_apply_same [Zero R] [One R] {k : ℕ}
    (sz : Fin k → ℕ) (lam : Fin k → R) (i : Fin k) (a b : Fin (sz i)) :
    jordanMatrix sz lam ⟨i, a⟩ ⟨i, b⟩ = jordanBlock (sz i) (lam i) a b := by
  simp [jordanMatrix, Matrix.blockDiagonal'_apply_eq]

@[simp] theorem jordanMatrix_apply_ne [Zero R] [One R] {k : ℕ}
    (sz : Fin k → ℕ) (lam : Fin k → R) {i j : Fin k}
    (a : Fin (sz i)) (b : Fin (sz j)) (h : i ≠ j) :
    jordanMatrix sz lam ⟨i, a⟩ ⟨j, b⟩ = 0 := by
  simp [jordanMatrix, Matrix.blockDiagonal'_apply_ne _ _ _ h]

/-- The block data `(sz, lam)` **is a Jordan form of** `A`: every block is nonempty,
and after reindexing the coordinates by `e`, `A` is similar to the corresponding
block-diagonal Jordan matrix.

Nonemptiness (`0 < sz i`) is what makes the block data an invariant: without it one
could pad any Jordan form with empty blocks carrying arbitrary eigenvalues, and no
uniqueness statement could hold. -/
def IsJordanFormOf [CommRing R] {ι : Type*} [Fintype ι] [DecidableEq ι] {k : ℕ}
    (A : Matrix ι ι R) (sz : Fin k → ℕ) (lam : Fin k → R) : Prop :=
  (∀ i, 0 < sz i) ∧
    ∃ e : ι ≃ jordanIndex sz,
      IsSimilar A (Matrix.reindex e.symm e.symm (jordanMatrix sz lam))

/-- `A` **has a Jordan form**: it is similar to a block-diagonal Jordan matrix.
Note this says `A` is *similar to* a Jordan matrix, not that `A` is one. -/
def HasJordanForm [CommRing R] {ι : Type*} [Fintype ι] [DecidableEq ι]
    (A : Matrix ι ι R) : Prop :=
  ∃ (k : ℕ) (sz : Fin k → ℕ) (lam : Fin k → R), IsJordanFormOf A sz lam

/-- The multiset of `(block size, eigenvalue)` pairs of a Jordan form. Passing to a
multiset is exactly what discards the ordering of the blocks, which is the sense in
which Jordan form is unique (Hefferon, Five.IV.2, Remark 2.9). -/
def jordanBlocks {k : ℕ} (sz : Fin k → ℕ) (lam : Fin k → R) : Multiset (ℕ × R) :=
  (Finset.univ : Finset (Fin k)).val.map fun i => (sz i, lam i)

/-- The dimension of the kernel of `(A - lam)^r`.  As `r` grows these dimensions
determine how many Jordan blocks of each size carry the eigenvalue `lam`, so they
are the invariant behind uniqueness of the Jordan form; they are also the standard
way to read block structure off a matrix in practice. -/
noncomputable def kerDim {K : Type*} [Field K] {n : ℕ}
    (A : Matrix (Fin n) (Fin n) K) (lam : K) (r : ℕ) : ℕ :=
  Module.finrank K (LinearMap.ker (Matrix.toLin' ((A - lam • 1) ^ r)))

end HefferonLinAlg
Source
Jim Hefferon, *Linear Algebra*, Saint Michael's College, 2020 printing, Chapter Five, Section IV.2, printed pp. 448-463 (PDF pp. 458-473)
Read-back

What the Lean code literally says, in plain math · claude-opus-5

Read-back — HefferonLinAlg_jordan.lean

All declarations live in a namespace HefferonLinAlg. Throughout, RRR is an arbitrary type (an implicit parameter of every declaration below except kerDim), and the typeclass assumptions carried by each declaration are stated individually; they differ from declaration to declaration and are not uniform across the bundle.


1. IsSimilar (definition)

Assumptions: RRR is a commutative ring; ι\iotaι is an arbitrary type that is a finite type and has decidable equality; A,BA, BA,B are ι×ι\iota \times \iotaι×ι matrices over RRR.

This defines a proposition, "AAA is similar to BBB", to mean:

∃ P∈Matι×ι(R):det⁡(P) is a unit of R  ∧  P−1AP=B.\exists\, P \in \mathrm{Mat}_{\iota\times\iota}(R):\quad \det(P) \text{ is a unit of } R \ \ \wedge\ \ P^{-1} A P = B.∃P∈Matι×ι​(R):det(P) is a unit of R  ∧  P−1AP=B.

Three points of literal content. First, the condition on PPP is that det⁡P\det PdetP is an invertible element of the ring RRR (i.e. there is u∈Ru \in Ru∈R with u⋅det⁡P=1u \cdot \det P = 1u⋅detP=1), not that det⁡P=1\det P = 1detP=1 and not merely that det⁡P≠0\det P \neq 0detP=0. Second, P−1P^{-1}P−1 denotes the total "nonsingular inverse" operation on matrices (adjugate divided by determinant), which returns a junk value — the zero matrix — when the determinant is not invertible; here that junk branch is excluded by the hypothesis, so P−1P^{-1}P−1 is a genuine two-sided inverse of PPP. Third, the equation is written in the specific order P−1AP=BP^{-1} A P = BP−1AP=B (the conjugating matrix on the right, its inverse on the left); no symmetry, reflexivity, transitivity, or any other property of this relation is asserted anywhere in this file. Degenerate case: if ι\iotaι is empty, there is exactly one matrix and det⁡\detdet of it is 111, so the relation holds trivially for the unique A=BA = BA=B.


2. jordanBlock (definition)

Assumptions: RRR carries only a distinguished element 000 and a distinguished element 111 — no ring, group, or even additive structure is assumed. Inputs: a natural number mmm and a scalar λ∈R\lambda \in Rλ∈R.

This defines the m×mm \times mm×m matrix Jm(λ)J_m(\lambda)Jm​(λ) indexed by {0,1,…,m−1}\{0,1,\dots,m-1\}{0,1,…,m−1} in both coordinates, whose (i,j)(i,j)(i,j) entry is

(Jm(λ))i,j  =  {λ,i=j,1,i=j+1,0,otherwise,\bigl(J_m(\lambda)\bigr)_{i,j} \;=\; \begin{cases} \lambda, & i = j,\\ 1, & i = j + 1,\\ 0, & \text{otherwise,} \end{cases}(Jm​(λ))i,j​=⎩⎨⎧​λ,1,0,​i=j,i=j+1,otherwise,​

where i=j+1i = j+1i=j+1 is an equation between the underlying natural-number values of the indices. So λ\lambdaλ sits on the diagonal and 111 sits on the subdiagonal (the entries immediately below the diagonal); the superdiagonal entries are 000. The two cases are tested in that order, but they are mutually exclusive as stated, since i=ji = ji=j and i=j+1i = j+1i=j+1 cannot both hold in N\mathbb{N}N. Nothing is assumed relating 000 and 111 in RRR; in particular RRR may be trivial (0=10 = 10=1). Degenerate cases: m=0m = 0m=0 yields the empty matrix; m=1m = 1m=1 yields the 1×11 \times 11×1 matrix (λ)(\lambda)(λ) with no subdiagonal.


3. jordanBlock_apply (theorem, tagged as a simplification lemma)

Assumptions: RRR has a 000 and a 111; mmm is a natural number (implicit); λ∈R\lambda \in Rλ∈R; i,ji, ji,j are indices in {0,…,m−1}\{0,\dots,m-1\}{0,…,m−1}.

The claim is that the (i,j)(i,j)(i,j) entry of the matrix Jm(λ)J_m(\lambda)Jm​(λ) of §2 equals λ\lambdaλ if i=ji = ji=j, else 111 if the natural number iii equals the natural number j+1j+1j+1, else 000. This restates the defining formula of §2 verbatim and is proved by definitional unfolding; it asserts no new mathematical content.


4. jordanIndex (abbreviation)

Assumptions: none beyond a natural number kkk (implicit) and a function sz:{0,…,k−1}→Nsz : \{0,\dots,k-1\} \to \mathbb{N}sz:{0,…,k−1}→N.

This names the index type

I(sz)  =  ∐i=0k−1{0,1,…,sz(i)−1},\mathcal{I}(sz) \;=\; \coprod_{i=0}^{k-1} \{0,1,\dots,sz(i)-1\},I(sz)=i=0∐k−1​{0,1,…,sz(i)−1},

the disjoint union (dependent pair type) whose elements are pairs (i,a)(i, a)(i,a) with iii a block label in {0,…,k−1}\{0,\dots,k-1\}{0,…,k−1} and aaa an index in {0,…,sz(i)−1}\{0,\dots,sz(i)-1\}{0,…,sz(i)−1}. Its cardinality is ∑isz(i)\sum_{i} sz(i)∑i​sz(i). Degenerate cases: if k=0k = 0k=0, or if every sz(i)=0sz(i) = 0sz(i)=0, this type is empty; blocks with sz(i)=0sz(i) = 0sz(i)=0 contribute no indices.


5. jordanMatrix (definition)

Assumptions: RRR has a 000 and a 111; kkk is a natural number (implicit); szszsz assigns a natural-number size to each of the kkk block labels, and λ\lambdaλ assigns an element of RRR to each block label.

This defines the block-diagonal matrix indexed by I(sz)×I(sz)\mathcal{I}(sz) \times \mathcal{I}(sz)I(sz)×I(sz) (§4) whose iii-th diagonal block is the sz(i)×sz(i)sz(i) \times sz(i)sz(i)×sz(i) matrix Jsz(i)(λ(i))J_{sz(i)}(\lambda(i))Jsz(i)​(λ(i)) of §2 and whose off-diagonal blocks are zero:

J(sz,λ)  =  diag⁡(Jsz(0)(λ(0)),  …,  Jsz(k−1)(λ(k−1))).J(sz,\lambda) \;=\; \operatorname{diag}\bigl(J_{sz(0)}(\lambda(0)),\; \dots,\; J_{sz(k-1)}(\lambda(k-1))\bigr).J(sz,λ)=diag(Jsz(0)​(λ(0)),…,Jsz(k−1)​(λ(k−1))).

The eigenvalue function λ\lambdaλ is arbitrary: distinct blocks may carry the same scalar, and no relation among the λ(i)\lambda(i)λ(i) is imposed. Sizes are arbitrary naturals, including 000.


6. jordanMatrix_apply_same (theorem, tagged as a simplification lemma)

Assumptions: RRR has a 000 and a 111; kkk (implicit), szszsz, λ\lambdaλ as above; iii a block label; a,ba, ba,b indices in {0,…,sz(i)−1}\{0,\dots,sz(i)-1\}{0,…,sz(i)−1}.

The claim: the entry of J(sz,λ)J(sz,\lambda)J(sz,λ) at row (i,a)(i,a)(i,a) and column (i,b)(i,b)(i,b) — i.e. two indices lying in the same block iii — equals the (a,b)(a,b)(a,b) entry of the single Jordan block Jsz(i)(λ(i))J_{sz(i)}(\lambda(i))Jsz(i)​(λ(i)).


7. jordanMatrix_apply_ne (theorem, tagged as a simplification lemma)

Assumptions: RRR has a 000 and a 111; kkk (implicit), szszsz, λ\lambdaλ as above; block labels i,ji, ji,j (implicit); aaa an index in {0,…,sz(i)−1}\{0,\dots,sz(i)-1\}{0,…,sz(i)−1}, bbb an index in {0,…,sz(j)−1}\{0,\dots,sz(j)-1\}{0,…,sz(j)−1}; and the explicit hypothesis i≠ji \neq ji=j.

The claim: whenever the row's block label differs from the column's block label, the entry of J(sz,λ)J(sz,\lambda)J(sz,λ) at row (i,a)(i,a)(i,a), column (j,b)(j,b)(j,b) is 000.


8. IsJordanFormOf (definition)

Assumptions: RRR is a commutative ring; ι\iotaι is a finite type with decidable equality; kkk is a natural number (implicit); AAA is an ι×ι\iota \times \iotaι×ι matrix over RRR; sz:{0,…,k−1}→Nsz : \{0,\dots,k-1\} \to \mathbb{N}sz:{0,…,k−1}→N and λ:{0,…,k−1}→R\lambda : \{0,\dots,k-1\} \to Rλ:{0,…,k−1}→R.

This defines the proposition "the block data (sz,λ)(sz,\lambda)(sz,λ) is a Jordan form of AAA" as the conjunction of:

  1. Every block is nonempty: sz(i)>0sz(i) > 0sz(i)>0 for all i∈{0,…,k−1}i \in \{0,\dots,k-1\}i∈{0,…,k−1}; and
  2. There exists a bijection e:ι→ ∼ I(sz)e : \iota \xrightarrow{\ \sim\ } \mathcal{I}(sz)e:ι ∼ ​I(sz) between the index type of AAA and the disjoint union of block index sets, such that AAA is similar (in the exact sense of §1: there exists PPP over ι\iotaι with det⁡P\det PdetP a unit and P−1APP^{-1} A PP−1AP equal to the target) to the matrix obtained by transporting J(sz,λ)J(sz,\lambda)J(sz,λ) along eee, namely the ι×ι\iota \times \iotaι×ι matrix whose (x,y)(x,y)(x,y) entry is J(sz,λ)e(x), e(y)J(sz,\lambda)_{e(x),\,e(y)}J(sz,λ)e(x),e(y)​.

Several literal points. The bijection is existentially quantified, so no particular ordering of ι\iotaι is fixed; but its mere existence forces ∣ι∣=∑isz(i)|\iota| = \sum_i sz(i)∣ι∣=∑i​sz(i), so the proposition is unsatisfiable for any block data whose sizes do not sum to the size of AAA. The similarity is stated in the direction "AAA is similar to the reindexed Jordan matrix", with the conjugator PPP ranging over ι\iotaι-indexed matrices with unit determinant. Nothing asserts that the λ(i)\lambda(i)λ(i) are eigenvalues, roots of the characteristic polynomial, or otherwise related to AAA except through this similarity; nothing asserts uniqueness of (sz,λ)(sz,\lambda)(sz,λ); and no ordering, grouping, or distinctness condition on the blocks is imposed. Degenerate cases: k=0k = 0k=0 (no blocks) satisfies condition 1 vacuously and is possible exactly when ι\iotaι is empty; conversely condition 1 rules out any block of size 000, so padding with empty blocks is excluded.


9. HasJordanForm (definition)

Assumptions: RRR is a commutative ring; ι\iotaι is a finite type with decidable equality; AAA is an ι×ι\iota \times \iotaι×ι matrix over RRR.

This defines the proposition "AAA has a Jordan form" as: there exist a natural number kkk, a size function sz:{0,…,k−1}→Nsz : \{0,\dots,k-1\} \to \mathbb{N}sz:{0,…,k−1}→N, and a scalar function λ:{0,…,k−1}→R\lambda : \{0,\dots,k-1\} \to Rλ:{0,…,k−1}→R such that (sz,λ)(sz,\lambda)(sz,λ) is a Jordan form of AAA in the sense of §8 — i.e. all sz(i)>0sz(i) > 0sz(i)>0, and for some bijection e:ι≃I(sz)e : \iota \simeq \mathcal{I}(sz)e:ι≃I(sz) and some matrix PPP over ι\iotaι with det⁡P\det PdetP a unit of RRR, P−1APP^{-1} A PP−1AP equals the matrix with entries J(sz,λ)e(x),e(y)J(sz,\lambda)_{e(x),e(y)}J(sz,λ)e(x),e(y)​. This is a definition only; no theorem in this file asserts that any matrix has this property, and in particular no existence theorem over C\mathbb{C}C or any algebraically closed field is stated.


10. jordanBlocks (definition)

Assumptions: none at all on RRR — no ring, no zero, no one; RRR is a bare type. Inputs: kkk (implicit), sz:{0,…,k−1}→Nsz : \{0,\dots,k-1\} \to \mathbb{N}sz:{0,…,k−1}→N, λ:{0,…,k−1}→R\lambda : \{0,\dots,k-1\} \to Rλ:{0,…,k−1}→R.

This defines the multiset (unordered collection with multiplicities) of pairs

{ ⁣ ⁣{ (sz(0),λ(0)), (sz(1),λ(1)), …, (sz(k−1),λ(k−1)) } ⁣ ⁣} ∈ Multiset(N×R),\bigl\{\!\!\bigl\{\,(sz(0),\lambda(0)),\ (sz(1),\lambda(1)),\ \dots,\ (sz(k-1),\lambda(k-1))\,\bigr\}\!\!\bigr\} \ \in\ \text{Multiset}(\mathbb{N}\times R),{{(sz(0),λ(0)), (sz(1),λ(1)), …, (sz(k−1),λ(k−1))}} ∈ Multiset(N×R),

obtained by mapping i↦(sz(i),λ(i)i \mapsto (sz(i), \lambda(i)i↦(sz(i),λ(i)) over all kkk block labels. It has exactly kkk elements counted with multiplicity; repeated pairs are kept as repetitions and only the ordering of the blocks is forgotten. This is a construction on arbitrary block data; it is attached to no matrix, and no theorem in this file relates it to IsJordanFormOf, HasJordanForm, or any uniqueness claim.


11. kerDim (definition, noncomputable)

Assumptions: KKK is a field (a fresh type variable, not the RRR used above); nnn is a natural number (implicit); AAA is an n×nn \times nn×n matrix over KKK indexed by {0,…,n−1}\{0,\dots,n-1\}{0,…,n−1}; λ∈K\lambda \in Kλ∈K; r∈Nr \in \mathbb{N}r∈N.

This defines the natural number

dim⁡Kker⁡( x↦(A−λI)rx ),\dim_K \ker\Bigl(\, x \mapsto (A - \lambda I)^{r} x \,\Bigr),dimK​ker(x↦(A−λI)rx),

that is: form the matrix A−λ⋅IA - \lambda \cdot IA−λ⋅I (the scalar λ\lambdaλ acting on the identity matrix, i.e. the diagonal matrix with λ\lambdaλ in every diagonal position), raise it to the rrr-th power as a matrix product, view the result as the KKK-linear endomorphism of the coordinate space KnK^{n}Kn given by multiplication on the standard basis, and take the KKK-dimension of its kernel as a submodule of KnK^nKn.

Literal points: matrix power is the ordinary product, so r=0r = 0r=0 gives the identity matrix, whose kernel is {0}\{0\}{0} and hence kerDim(A,λ,0)=0\mathrm{kerDim}(A,\lambda,0) = 0kerDim(A,λ,0)=0; n=0n = 0n=0 gives the zero space and dimension 000 for every rrr. The value is the rank/dimension function that returns a natural number (returning 000 in the degenerate convention for non-finite-dimensional modules, which does not arise here since KnK^nKn is finite-dimensional). No theorem in this file states any property of this quantity — no monotonicity in rrr, no stabilization, no relation to block sizes or to any of the Jordan definitions above.


Scope note

The file contains three theorems (§3, §6, §7); each is an entry-value computation for the matrices defined in §2 and §5, and each is proved by unfolding definitions. Everything else (§1, §2, §4, §5, §8, §9, §10, §11) is a definition or abbreviation. No statement in the file asserts existence, uniqueness, or invariance of Jordan forms, and no statement connects kerDim or jordanBlocks to IsJordanFormOf or HasJordanForm.

Human review
  • Endorsed by Shuze Chen · Aug 7, 2026

  • Endorsed by tianyipeng · Aug 7, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeLaunch a missionPropose a formalization projectFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions.

How Prove2Me works
SKILL.mdTourFAQContactJoin Slack© 2026 Prove2Me