import Mathlib /-! # Lemma 4.1 (`lem:iterate`): Matrices of Iterates Formalization of Lemma 4.1 from S. van Strien, *The Thurston algorithm for meromorphic and rational maps* (version 22, 3 December 2026): Let `Λ` be an `f`-stable multicurve with Thurston pullback matrix `M`, defined from the finite 1-step essential covering lifts `l : L` (with source class `src l`, target class `tgt l`, and covering degree `deg l`) by `M δ γ = ∑_{src l = δ, tgt l = γ} 1 / deg l`. 1. **Concrete lift chains** (`pow_thurstonMatrix_eq_sum_chains`): For all `m : ℕ` and `δ, γ : Λ`, `(M ^ m) δ γ = ∑ c : LiftChain src tgt m δ γ, 1 / chainDeg c`. 2. **Abstract covering-component theorem** (`iterate_matrix_eq_sum_lifts`): Following Lemma 4.1's proof verbatim, given any finite family `Comp m γ` of essential `m`-step closed lifts over `γ` satisfying the base identification (`m = 1`) and inductive factorization `Comp (m + 1) γ ≃ Σ β : Comp m γ, { l : L // tgt l = cls β }` with multiplicative degrees, `(M ^ m) δ γ = ∑_{α ∈ Comp m γ, cls α = δ} 1 / compDeg α` for all `m ≥ 1`. -/ open Finset Matrix namespace Thurston.Core section ThurstonMatrix variable {Λ L : Type*} [Fintype L] [DecidableEq Λ] /-- The Thurston pullback matrix of a finite 1-step covering-lift system: `(thurstonMatrix src tgt deg) δ γ = ∑_{src l = δ, tgt l = γ} 1 / deg l`. -/ noncomputable def thurstonMatrix (src tgt : L → Λ) (deg : L → ℕ) : Matrix Λ Λ ℝ := fun δ γ => ∑ l ∈ Finset.univ.filter (fun l : L => src l = δ ∧ tgt l = γ), (1 : ℝ) / (deg l : ℝ) @[simp] lemma thurstonMatrix_apply (src tgt : L → Λ) (deg : L → ℕ) (δ γ : Λ) : thurstonMatrix src tgt deg δ γ = ∑ l ∈ Finset.univ.filter (fun l : L => src l = δ ∧ tgt l = γ), (1 : ℝ) / (deg l : ℝ) := rfl /-- Every entry of the Thurston pullback matrix is nonnegative. -/ lemma thurstonMatrix_nonneg (src tgt : L → Λ) (deg : L → ℕ) (δ γ : Λ) : 0 ≤ thurstonMatrix src tgt deg δ γ := Finset.sum_nonneg fun _ _ => by positivity private lemma sum_subtype_tgt_eq_thurstonMatrix (src tgt : L → Λ) (deg : L → ℕ) (δ κ : Λ) : (∑ l : { l : L // tgt l = κ }, if src l.1 = δ then (1 : ℝ) / (deg l.1 : ℝ) else 0) = thurstonMatrix src tgt deg δ κ := by rw [← Finset.sum_filter, thurstonMatrix_apply] refine Finset.sum_bij (fun l _ => l.1) (fun l hl => ?_) (fun _ _ _ _ h => Subtype.ext h) (fun l hl => ?_) (fun _ _ => rfl) · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl ⊢ exact ⟨hl, l.2⟩ · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl exact ⟨⟨l, hl.2⟩, by simp [hl.1], rfl⟩ end ThurstonMatrix section LiftChains universe u variable {Λ : Type*} {L : Type u} /-- A composable chain of `m` 1-step lifts starting at `δ` and ending at `γ`. For `m = 0`, it is a lifted proof that `δ = γ`; for `m + 1`, it consists of a first lift `l` with `src l = δ` followed by an `m`-step chain from `tgt l` to `γ`. -/ def LiftChain (src tgt : L → Λ) : ℕ → Λ → Λ → Type u | 0, δ, γ => ULift.{u} (PLift (δ = γ)) | m + 1, δ, γ => Σ l : { l : L // src l = δ }, LiftChain src tgt m (tgt l.1) γ /-- Total covering degree of a lift chain: the product of the degrees of its steps. -/ def chainDeg {src tgt : L → Λ} (deg : L → ℕ) : {m : ℕ} → {δ γ : Λ} → LiftChain src tgt m δ γ → ℕ | 0, _, _, _ => 1 | _ + 1, _, _, ⟨l, c⟩ => deg l.1 * chainDeg deg c instance instFintypeLiftChain [Fintype L] [DecidableEq Λ] (src tgt : L → Λ) : ∀ (m : ℕ) (δ γ : Λ), Fintype (LiftChain src tgt m δ γ) | 0, δ, γ => by dsimp [LiftChain]; infer_instance | m + 1, δ, γ => by dsimp [LiftChain] letI := instFintypeLiftChain src tgt m infer_instance /-- **Concrete `m`-step lift-chain formula**: for every `m : ℕ` and `δ, γ : Λ`, `(M ^ m) δ γ` equals the sum of `1 / chainDeg c` over all composable `m`-step lift chains `c` from `δ` to `γ`. -/ theorem pow_thurstonMatrix_eq_sum_chains [Fintype Λ] [Fintype L] [DecidableEq Λ] (src tgt : L → Λ) (deg : L → ℕ) : ∀ (m : ℕ) (δ γ : Λ), (thurstonMatrix src tgt deg ^ m) δ γ = ∑ c : LiftChain src tgt m δ γ, (1 : ℝ) / (chainDeg deg c : ℝ) | 0, δ, γ => by simp only [pow_zero, Matrix.one_apply, LiftChain, chainDeg, Nat.cast_one, div_one] by_cases h : δ = γ · subst h have : Unique (ULift.{u} (PLift (δ = δ))) := ⟨⟨⟨⟨rfl⟩⟩⟩, fun ⟨⟨_⟩⟩ => rfl⟩ simp · have : IsEmpty (ULift.{u} (PLift (δ = γ))) := ⟨fun ⟨⟨heq⟩⟩ => h heq⟩ simp [h] | m + 1, δ, γ => by have ih := pow_thurstonMatrix_eq_sum_chains src tgt deg m have hrhs : (∑ c : LiftChain src tgt (m + 1) δ γ, (1 : ℝ) / (chainDeg deg c : ℝ)) = ∑ l : { l : L // src l = δ }, ((1 : ℝ) / (deg l.1 : ℝ)) * (thurstonMatrix src tgt deg ^ m) (tgt l.1) γ := by change (∑ p : Σ l : { l : L // src l = δ }, LiftChain src tgt m (tgt l.1) γ, (1 : ℝ) / ((deg p.1.1 * chainDeg deg p.2 : ℕ) : ℝ)) = _ rw [Fintype.sum_sigma] refine Finset.sum_congr rfl fun l _ => ?_ rw [ih (tgt l.1) γ, Finset.mul_sum] refine Finset.sum_congr rfl fun c _ => by push_cast; rw [one_div_mul_one_div] rw [hrhs, pow_succ', Matrix.mul_apply] symm rw [← Finset.sum_fiberwise_of_maps_to (t := Finset.univ) (g := fun l : { l : L // src l = δ } => tgt l.1) (fun _ _ => Finset.mem_univ _)] refine Finset.sum_congr rfl fun κ _ => ?_ have hinner : (∑ l ∈ Finset.univ.filter (fun l : { l : L // src l = δ } => tgt l.1 = κ), ((1 : ℝ) / (deg l.1 : ℝ)) * (thurstonMatrix src tgt deg ^ m) (tgt l.1) γ) = (∑ l ∈ Finset.univ.filter (fun l : { l : L // src l = δ } => tgt l.1 = κ), (1 : ℝ) / (deg l.1 : ℝ)) * (thurstonMatrix src tgt deg ^ m) κ γ := by rw [Finset.sum_mul] refine Finset.sum_congr rfl fun l hl => by simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl; rw [hl] rw [hinner, thurstonMatrix_apply] congr 1 refine Finset.sum_bij (fun l _ => l.1) (fun l hl => ?_) (fun _ _ _ _ h => Subtype.ext h) (fun l hl => ?_) (fun _ _ => rfl) · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl ⊢ exact ⟨l.2, hl⟩ · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl exact ⟨⟨l, hl.1⟩, by simp [hl.2], rfl⟩ end LiftChains section AbstractCoveringLifts variable {Λ L : Type*} [Fintype Λ] [Fintype L] [DecidableEq Λ] /-- **Lemma 4.1 (`lem:iterate`, Matrices of iterates)**: Given a finite family `Comp m γ` of essential `m`-step closed lifts over `γ ∈ Λ` with homotopy class `cls` and covering degree `compDeg`, satisfying: - base correspondence `Comp 1 γ ≃ { l : L // tgt l = γ }` preserving class and degree; - inductive factorization `Comp (m + 1) γ ≃ Σ β : Comp m γ, { l : L // tgt l = cls β }` (stability + isotopy lifting) with multiplicative covering degrees; we have for every `m ≥ 1` and `δ, γ : Λ`: `(thurstonMatrix src tgt deg ^ m) δ γ = ∑_{α ∈ Comp m γ, cls α = δ} 1 / compDeg α`. -/ theorem iterate_matrix_eq_sum_lifts (src tgt : L → Λ) (deg : L → ℕ) (Comp : ℕ → Λ → Type*) [∀ m γ, Fintype (Comp m γ)] (cls : ∀ {m γ}, Comp m γ → Λ) (compDeg : ∀ {m γ}, Comp m γ → ℕ) (e_one : ∀ γ, Comp 1 γ ≃ { l : L // tgt l = γ }) (hcls_one : ∀ {γ} (α : Comp 1 γ), cls α = src (e_one γ α).1) (hdeg_one : ∀ {γ} (α : Comp 1 γ), compDeg α = deg (e_one γ α).1) (e_succ : ∀ m, 1 ≤ m → ∀ γ, Comp (m + 1) γ ≃ Σ β : Comp m γ, { l : L // tgt l = cls β }) (hcls_succ : ∀ m (hm : 1 ≤ m) γ (β : Comp m γ) (l : { l : L // tgt l = cls β }), cls ((e_succ m hm γ).symm ⟨β, l⟩) = src l.1) (hdeg_succ : ∀ m (hm : 1 ≤ m) γ (β : Comp m γ) (l : { l : L // tgt l = cls β }), compDeg ((e_succ m hm γ).symm ⟨β, l⟩) = deg l.1 * compDeg β) : ∀ m : ℕ, 1 ≤ m → ∀ δ γ : Λ, (thurstonMatrix src tgt deg ^ m) δ γ = ∑ α ∈ Finset.univ.filter (fun α : Comp m γ => cls α = δ), (1 : ℝ) / (compDeg α : ℝ) := by intro m hm induction m, hm using Nat.le_induction with | base => intro δ γ rw [pow_one, thurstonMatrix_apply] symm refine Finset.sum_bij (fun α _ => (e_one γ α).1) (fun α hα => ?_) (fun _ _ _ _ h => (e_one γ).injective (Subtype.ext h)) (fun l hl => ?_) (fun α _ => by rw [hdeg_one α]) · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hα ⊢ exact ⟨(hcls_one α).symm.trans hα, (e_one γ α).2⟩ · simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl exact ⟨(e_one γ).symm ⟨l, hl.2⟩, by simp [hcls_one, hl.1], by simp⟩ | succ m hm ih => intro δ γ symm rw [Finset.sum_filter, ← Equiv.sum_comp (e_succ m hm γ).symm, Fintype.sum_sigma] have hinner : (∑ β : Comp m γ, ∑ l : { l : L // tgt l = cls β }, if cls ((e_succ m hm γ).symm ⟨β, l⟩) = δ then (1 : ℝ) / (compDeg ((e_succ m hm γ).symm ⟨β, l⟩) : ℝ) else 0) = ∑ β : Comp m γ, thurstonMatrix src tgt deg δ (cls β) * ((1 : ℝ) / (compDeg β : ℝ)) := by refine Finset.sum_congr rfl fun β _ => ?_ rw [← sum_subtype_tgt_eq_thurstonMatrix, Finset.sum_mul] refine Finset.sum_congr rfl fun l _ => ?_ rw [hcls_succ m hm γ β l, hdeg_succ m hm γ β l] split_ifs · push_cast; rw [one_div_mul_one_div] · simp rw [hinner, ← Finset.sum_fiberwise_of_maps_to (t := Finset.univ) (g := fun β : Comp m γ => cls β) (fun _ _ => Finset.mem_univ _), pow_succ', Matrix.mul_apply] refine Finset.sum_congr rfl fun κ _ => ?_ rw [ih κ γ, Finset.mul_sum] refine Finset.sum_congr rfl fun β hβ => by simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hβ; rw [hβ] end AbstractCoveringLifts section SanityExample /-! ### Sanity check: a 2-class, 3-lift covering system `Λ = Fin 2`, `L = Fin 3` with lifts `0 : 0 → 0` (deg `2`), `1 : 0 → 1` (deg `1`), `2 : 1 → 0` (deg `2`), giving `M = [[1/2, 1], [1/2, 0]]` and `(M ^ 2) 0 0 = 1/4 + 1/2 = 3/4`. -/ private def exSrc : Fin 3 → Fin 2 | 0 => 0 | 1 => 0 | 2 => 1 private def exTgt : Fin 3 → Fin 2 | 0 => 0 | 1 => 1 | 2 => 0 private def exDeg : Fin 3 → ℕ | 0 => 2 | 1 => 1 | 2 => 2 private abbrev ExComp (m : ℕ) (γ : Fin 2) : Type := Σ δ : Fin 2, LiftChain exSrc exTgt m δ γ private def exEquivOne (γ : Fin 2) : ExComp 1 γ ≃ { l : Fin 3 // exTgt l = γ } where toFun p := ⟨p.2.1.1, p.2.2.down.down⟩ invFun l := ⟨exSrc l.1, ⟨⟨l.1, rfl⟩, ⟨⟨l.2⟩⟩⟩⟩ left_inv := by rintro ⟨δ, ⟨⟨l, rfl⟩, ⟨⟨rfl⟩⟩⟩⟩; rfl right_inv := by rintro ⟨l, rfl⟩; rfl private def exEquivSucc (m : ℕ) (γ : Fin 2) : ExComp (m + 1) γ ≃ Σ β : ExComp m γ, { l : Fin 3 // exTgt l = β.1 } where toFun p := ⟨⟨exTgt p.2.1.1, p.2.2⟩, ⟨p.2.1.1, rfl⟩⟩ invFun := fun ⟨⟨_, c⟩, ⟨l, htgt⟩⟩ => ⟨exSrc l, ⟨⟨l, rfl⟩, htgt ▸ c⟩⟩ left_inv := by rintro ⟨δ, ⟨⟨l, rfl⟩, c⟩⟩; rfl right_inv := by rintro ⟨⟨κ, c⟩, ⟨l, htgt⟩⟩; dsimp only at htgt; subst htgt; rfl example : (thurstonMatrix exSrc exTgt exDeg ^ 2) 0 0 = ∑ α ∈ Finset.univ.filter (fun α : ExComp 2 0 => α.1 = 0), (1 : ℝ) / (chainDeg exDeg α.2 : ℝ) ∧ (thurstonMatrix exSrc exTgt exDeg ^ 2) 0 0 = ∑ c : LiftChain exSrc exTgt 2 0 0, (1 : ℝ) / (chainDeg exDeg c : ℝ) ∧ (thurstonMatrix exSrc exTgt exDeg ^ 2) 0 0 = (3 : ℝ) / 4 := by have h1 := iterate_matrix_eq_sum_lifts exSrc exTgt exDeg ExComp (fun p => p.1) (fun p => chainDeg exDeg p.2) exEquivOne (fun p => p.2.1.2.symm) (fun ⟨_, ⟨_, _⟩⟩ => mul_one _) (fun m _ γ => exEquivSucc m γ) (fun _ _ _ _ _ => rfl) (fun _ _ _ β l => by rcases β with ⟨κ, c⟩; rcases l with ⟨l, htgt⟩; dsimp only at htgt; subst htgt; rfl) 2 (by norm_num) 0 0 have h2 := pow_thurstonMatrix_eq_sum_chains exSrc exTgt exDeg 2 0 0 refine ⟨h1, h2, ?_⟩ rw [pow_two, Matrix.mul_apply, Fin.sum_univ_two] simp_rw [thurstonMatrix_apply, Finset.sum_filter, Fin.sum_univ_three] norm_num [exSrc, exTgt, exDeg] end SanityExample end Thurston.Core