thurston-lean / Thurston /Conditional /MatrixSpectralRadius.lean
system's picture
system HF Staff
Sync Lean + ledger from GitHub (6d6513147f03fcdca5249ee06cbaf74ba025e4b0)
55a3af4 verified
Raw History Blame Contribute Delete
49 kB

If a nonnegative matrix M and a positive vector u satisfy u M ≤ θ u entrywise, then every complex eigenvalue of M has modulus at most θ.

83
theorem norm_le_of_mem_spectrum_of_weighted_bound (M : Matrix n n ℝ) (hM : ∀ α β, 0 ≤ M α β)
    (u : n → ℝ) (hu : ∀ α, 0 < u α) (θ : ℝ) (hθ : ∀ β, ∑ α, u α * M α β ≤ θ * u β) (μ : ℂ)
    (hμ : μ ∈ spectrum ℂ (M.map (algebraMap ℝ ℂ))) : ‖μ‖ ≤ θ := by
proof · 37 lines
  rw [spectrum.mem_iff] at hμ
  have hdet : (algebraMap ℂ (Matrix n n ℂ) μ - M.map (algebraMap ℝ ℂ)).det = 0 := by
    by_contra hne
    exact hμ ((Matrix.isUnit_iff_isUnit_det _).2 (isUnit_iff_ne_zero.2 hne))
  obtain ⟨x, hx0, hx⟩ := Matrix.exists_mulVec_eq_zero_iff.2 hdet
  have heig : ∀ α, μ * x α = ∑ β, (M α β : ℂ) * x β := by
    intro α
    have h := congrFun hx α
    rw [Algebra.algebraMap_eq_smul_one, Matrix.sub_mulVec, Matrix.smul_mulVec,
      Matrix.one_mulVec] at h
    simp only [Pi.sub_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply, Matrix.mulVec,
      dotProduct, Matrix.map_apply, Complex.coe_algebraMap] at h
    exact sub_eq_zero.1 h
  have hrow : ∀ α, ‖μ‖ * ‖x α‖ ≤ ∑ β, M α β * ‖x β‖ := by
    intro α
    rw [← norm_mul, heig α]
    refine (norm_sum_le _ _).trans (le_of_eq ?_)
    refine Finset.sum_congr rfl fun β _ => ?_
    rw [norm_mul, Complex.norm_real, Real.norm_of_nonneg (hM α β)]
  have hN : 0 < ∑ α, u α * ‖x α‖ := by
    obtain ⟨α₀, hα₀⟩ := Function.ne_iff.1 hx0
    exact Finset.sum_pos' (fun α _ => mul_nonneg (hu α).le (norm_nonneg _))
      ⟨α₀, Finset.mem_univ _, mul_pos (hu α₀) (norm_pos_iff.2 hα₀)⟩
  have hmain : ‖μ‖ * ∑ α, u α * ‖x α‖ ≤ θ * ∑ α, u α * ‖x α‖ :=
    calc ‖μ‖ * ∑ α, u α * ‖x α‖ = ∑ α, u α * (‖μ‖ * ‖x α‖) := by
          rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun α _ => by ring
      _ ≤ ∑ α, u α * ∑ β, M α β * ‖x β‖ :=
          Finset.sum_le_sum fun α _ => mul_le_mul_of_nonneg_left (hrow α) (hu α).le
      _ = ∑ β, (∑ α, u α * M α β) * ‖x β‖ := by
          simp_rw [Finset.mul_sum, Finset.sum_mul]
          rw [Finset.sum_comm]
          exact Finset.sum_congr rfl fun β _ => Finset.sum_congr rfl fun α _ => by ring
      _ ≤ ∑ β, θ * u β * ‖x β‖ :=
          Finset.sum_le_sum fun β _ => mul_le_mul_of_nonneg_right (hθ β) (norm_nonneg _)
      _ = θ * ∑ α, u α * ‖x α‖ := by
          rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun α _ => by ring
  exact le_of_mul_le_mul_right hmain hN

The same hypothesis with θ < 1 gives spectral radius below one.

125
theorem spectralRadius_lt_one_of_weighted_bound (M : Matrix n n ℝ) (hM : ∀ α β, 0 ≤ M α β)
    (u : n → ℝ) (hu : ∀ α, 0 < u α) (θ : ℝ) (hθ1 : θ < 1)
    (hθ : ∀ β, ∑ α, u α * M α β ≤ θ * u β) :
    spectralRadius ℂ (M.map (algebraMap ℝ ℂ)) < 1 := by
proof · 6 lines
  refine lt_of_le_of_lt (iSup₂_le fun k hk => ?_) (ENNReal.ofReal_lt_one.2 hθ1)
  rcases mem_quasispectrum_iff.1 hk with rfl | hk'
  · simp
  · rw [← enorm_eq_nnnorm, ← ofReal_norm]
    exact ENNReal.ofReal_le_ofReal
      (norm_le_of_mem_spectrum_of_weighted_bound M hM u hu θ hθ k hk')
136
theorem pow_apply_nonneg (M : Matrix n n ℝ) (hM : ∀ α β, 0 ≤ M α β) (k : ℕ) :
    ∀ α β, 0 ≤ (M ^ k) α β := by
proof · 6 lines
  induction k with
  | zero => intro α β; rw [pow_zero, Matrix.one_apply]; split_ifs <;> norm_num
  | succ k ih =>
    intro α β
    rw [pow_succ, Matrix.mul_apply]
    exact Finset.sum_nonneg fun γ _ => mul_nonneg (ih α γ) (hM γ β)
145
theorem weighted_pow_le (M : Matrix n n ℝ) (hM : ∀ α β, 0 ≤ M α β) (u : n → ℝ) (θ : ℝ)
    (hθ0 : 0 ≤ θ) (hθ : ∀ β, ∑ α, u α * M α β ≤ θ * u β) (k : ℕ) :
    ∀ β, ∑ α, u α * (M ^ k) α β ≤ θ ^ k * u β := by
proof · 14 lines
  induction k with
  | zero => intro β; simp [Matrix.one_apply]
  | succ k ih =>
    intro β
    calc ∑ α, u α * (M ^ (k + 1)) α β = ∑ γ, (∑ α, u α * (M ^ k) α γ) * M γ β := by
          simp_rw [pow_succ, Matrix.mul_apply, Finset.mul_sum, Finset.sum_mul]
          rw [Finset.sum_comm]
          exact Finset.sum_congr rfl fun γ _ => Finset.sum_congr rfl fun α _ => by ring
      _ ≤ ∑ γ, θ ^ k * u γ * M γ β :=
          Finset.sum_le_sum fun γ _ => mul_le_mul_of_nonneg_right (ih γ) (hM γ β)
      _ = θ ^ k * ∑ γ, u γ * M γ β := by
          rw [Finset.mul_sum]; exact Finset.sum_congr rfl fun γ _ => by ring
      _ ≤ θ ^ k * (θ * u β) := mul_le_mul_of_nonneg_left (hθ β) (pow_nonneg hθ0 k)
      _ = θ ^ (k + 1) * u β := by ring

"In finite dimension, spectral radius below one implies that all entries of its powers tend to zero" (lines 857-858), here directly from the weighted bound.

165
theorem tendsto_pow_apply_zero_of_weighted_bound (M : Matrix n n ℝ) (hM : ∀ α β, 0 ≤ M α β)
    (u : n → ℝ) (hu : ∀ α, 0 < u α) (θ : ℝ) (hθ0 : 0 ≤ θ) (hθ1 : θ < 1)
    (hθ : ∀ β, ∑ α, u α * M α β ≤ θ * u β) (α β : n) :
    Filter.Tendsto (fun k : ℕ => (M ^ k) α β) Filter.atTop (nhds 0) := by
proof · 11 lines
  have hle : ∀ k, (M ^ k) α β ≤ θ ^ k * (u β / u α) := by
    intro k
    have h1 := weighted_pow_le M hM u θ hθ0 hθ k β
    have h2 : u α * (M ^ k) α β ≤ ∑ α', u α' * (M ^ k) α' β :=
      Finset.single_le_sum (f := fun α' => u α' * (M ^ k) α' β)
        (fun α' _ => mul_nonneg (hu α').le (pow_apply_nonneg M hM k α' β)) (Finset.mem_univ α)
    rw [← mul_div_assoc, le_div_iff₀ (hu α)]
    linarith
  have hlim : Filter.Tendsto (fun k : ℕ => θ ^ k * (u β / u α)) Filter.atTop (nhds 0) := by
    simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hθ0 hθ1).mul_const (u β / u α)
  exact squeeze_zero (fun k => pow_apply_nonneg M hM k α β) hle hlim

Along card n + 1 steps of the chain β, lam β, lam (lam β), … some point repeats, so the chain runs through a cycle, and the product of the weights is at most 1/2.

191
theorem prod_chain_le_half (lam : n → n) (w : n → ℝ) (hw0 : ∀ β, 0 ≤ w β) (hw1 : ∀ β, w β ≤ 1)
    (hcyc : ∀ γ p, 0 < p → lam^[p] γ = γ → ∃ a < p, w (lam^[a] γ) ≤ 1 / 2) (β : n) :
    ∏ a ∈ range (Fintype.card n + 1), w (lam^[a] β) ≤ 1 / 2 := by
proof · 19 lines
  obtain ⟨i, j, hij, heq⟩ := Fintype.exists_ne_map_eq_of_card_lt
    (fun a : Fin (Fintype.card n + 1) => lam^[a] β) (by simp)
  wlog hlt : (i : ℕ) < j generalizing i j
  · have hne : (i : ℕ) ≠ j := fun h => hij (Fin.ext h)
    exact this j i hij.symm heq.symm (by omega)
  have heq' : lam^[(i : ℕ)] β = lam^[(j : ℕ)] β := heq
  have hper : lam^[(j : ℕ) - i] (lam^[(i : ℕ)] β) = lam^[(i : ℕ)] β := by
    rw [← Function.iterate_add_apply, Nat.sub_add_cancel hlt.le, ← heq']
  obtain ⟨a, ha, hwa⟩ := hcyc _ _ (by omega) hper
  rw [← Function.iterate_add_apply] at hwa
  have hmem : a + i ∈ range (Fintype.card n + 1) := by
    rw [Finset.mem_range]; have := j.2; omega
  calc ∏ b ∈ range (Fintype.card n + 1), w (lam^[b] β)
      = w (lam^[a + i] β) * ∏ b ∈ (range (Fintype.card n + 1)).erase (a + i), w (lam^[b] β) :=
        (Finset.mul_prod_erase _ _ hmem).symm
    _ ≤ 1 / 2 * 1 := mul_le_mul hwa
        (Finset.prod_le_one₀ (fun b _ => hw0 _) (fun b _ => hw1 _))
        (Finset.prod_nonneg fun b _ => hw0 _) (by norm_num)
    _ = 1 / 2 := by norm_num

A map lam with weights w in [0, 1], such that every cycle of lam has a weight at most 1/2, has a vector v ≥ 1 and a number θ < 1 with v (lam β) w β ≤ θ v β for every β.

216
theorem exists_weight_of_no_unit_cycle (lam : n → n) (w : n → ℝ) (hw0 : ∀ β, 0 ≤ w β)
    (hw1 : ∀ β, w β ≤ 1)
    (hcyc : ∀ γ p, 0 < p → lam^[p] γ = γ → ∃ a < p, w (lam^[a] γ) ≤ 1 / 2) :
    ∃ (θ : ℝ) (v : n → ℝ), 0 ≤ θ ∧ θ < 1 ∧ (∀ β, 1 ≤ v β) ∧ ∀ β, v (lam β) * w β ≤ θ * v β := by
proof · 54 lines
  set N := Fintype.card n with hN
  set θ : ℝ := 1 - 1 / (2 * ((N : ℝ) + 1)) with hθ
  have hN0 : (0 : ℝ) ≤ N := Nat.cast_nonneg N
  have hsmall : 1 / (2 * ((N : ℝ) + 1)) ≤ 1 / 2 := by
    rw [div_le_div_iff₀ (by positivity) (by norm_num)]; linarith
  have hsmall0 : 0 < 1 / (2 * ((N : ℝ) + 1)) := by positivity
  have hθ0 : 0 < θ := by linarith
  have hθ1 : θ < 1 := by linarith
  have hbern : 1 / 2 ≤ θ ^ (N + 1) := by
    have h := one_add_mul_le_pow (a := -(1 / (2 * ((N : ℝ) + 1)))) (by linarith) (N + 1)
    have e : 1 + ((N + 1 : ℕ) : ℝ) * -(1 / (2 * ((N : ℝ) + 1))) = 1 / 2 := by
      push_cast; field_simp; ring
    have e2 : 1 + -(1 / (2 * ((N : ℝ) + 1))) = θ := by rw [hθ]; ring
    rw [e, e2] at h
    exact h
  have hinv : θ * θ⁻¹ = 1 := mul_inv_cancel₀ hθ0.ne'
  have hinv0 : 0 < θ⁻¹ := inv_pos.2 hθ0
  let W : ℕ → n → ℝ := fun j β => ∏ a ∈ range j, w (lam^[a] β)
  have hWsucc : ∀ j β, W (j + 1) β = w β * W j (lam β) := by
    intro j β
    show ∏ a ∈ range (j + 1), w (lam^[a] β) = w β * ∏ a ∈ range j, w (lam^[a] (lam β))
    rw [Finset.prod_range_succ', mul_comm]
    rfl
  have hW0 : ∀ β, W 0 β = 1 := fun β => Finset.prod_range_zero _
  have hWnn : ∀ j β, 0 ≤ W j β := fun j β => Finset.prod_nonneg fun a _ => hw0 _
  have hWhalf : ∀ β, W (N + 1) β ≤ 1 / 2 := fun β => prod_chain_le_half lam w hw0 hw1 hcyc β
  refine ⟨θ, fun β => ∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j β, hθ0.le, hθ1, fun β => ?_,
    fun β => ?_⟩
  · show 1 ≤ ∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j β
    rw [Finset.sum_range_succ', pow_zero, hW0, mul_one]
    have h : 0 ≤ ∑ j ∈ range N, θ⁻¹ ^ (j + 1) * W (j + 1) β :=
      Finset.sum_nonneg fun j _ => mul_nonneg (pow_nonneg hinv0.le _) (hWnn _ _)
    linarith
  · have hL : (∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j (lam β)) * w β
        = ∑ j ∈ range (N + 1), θ⁻¹ ^ j * W (j + 1) β := by
      rw [Finset.sum_mul]
      refine Finset.sum_congr rfl fun j _ => ?_
      rw [hWsucc]; ring
    have hR : θ * ∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j β
        = ∑ j ∈ range N, θ⁻¹ ^ j * W (j + 1) β + θ := by
      rw [Finset.sum_range_succ', pow_zero, hW0, mul_one, mul_add, mul_one, Finset.mul_sum]
      congr 1
      refine Finset.sum_congr rfl fun j _ => ?_
      rw [pow_succ]
      linear_combination (θ⁻¹ ^ j * W (j + 1) β) * hinv
    have hlast : θ⁻¹ ^ N * W (N + 1) β ≤ θ :=
      calc θ⁻¹ ^ N * W (N + 1) β ≤ θ⁻¹ ^ N * θ ^ (N + 1) :=
            mul_le_mul_of_nonneg_left ((hWhalf β).trans hbern) (pow_nonneg hinv0.le _)
        _ = θ := by
            rw [pow_succ, ← mul_assoc, ← mul_pow, inv_mul_cancel₀ hθ0.ne', one_pow, one_mul]
    show (∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j (lam β)) * w β
      ≤ θ * ∑ j ∈ range (N + 1), θ⁻¹ ^ j * W j β
    rw [hL, hR, Finset.sum_range_succ]
    linarith

Lifts with weights in [0, 1], and a function Φ that does not decrease along a lift. Suppose that the lifts that keep Φ are given by a map lam with weights w (at most one such lift over each β), and that v and θ < 1 are as in exists_weight_of_no_unit_cycle. Then there is a positive vector u with ∑ u (src l) wt l ≤ (1 + θ)/2 · u β, the sum over the lifts l of β.

288
theorem exists_weighted_bound_of_levels (src tgt : L → Λ) (wt : L → ℝ)
    (hwt1 : ∀ l, wt l ≤ 1) (Φ : Λ → ℕ) (hΦ : ∀ l, Φ (src l) ≤ Φ (tgt l))
    (lam : Λ → Λ) (w : Λ → ℝ) (hw0 : ∀ β, 0 ≤ w β)
    (hlevel : ∀ l, Φ (src l) = Φ (tgt l) → src l = lam (tgt l) ∧ wt l = w (tgt l))
    (huniq : ∀ l l', Φ (src l) = Φ (tgt l) → Φ (src l') = Φ (tgt l') → tgt l = tgt l' → l = l')
    (θ : ℝ) (hθ1 : θ < 1) (v : Λ → ℝ) (hv : ∀ β, 1 ≤ v β)
    (hvw : ∀ β, v (lam β) * w β ≤ θ * v β) :
    ∃ u : Λ → ℝ, (∀ α, 0 < u α) ∧
      ∀ β, ∑ l ∈ univ.filter (fun l => tgt l = β), u (src l) * wt l ≤ (1 + θ) / 2 * u β := by
proof · 82 lines
  set V : ℝ := ∑ β, v β with hV
  have hv0 : ∀ β, 0 ≤ v β := fun β => by linarith [hv β]
  have hvV : ∀ β, v β ≤ V := fun β =>
    Finset.single_le_sum (f := v) (fun γ _ => hv0 γ) (Finset.mem_univ β)
  have hV0 : 0 ≤ V := Finset.sum_nonneg fun γ _ => hv0 γ
  have h1θ : 0 < 1 - θ := by linarith
  have hc0 : (0 : ℝ) ≤ Fintype.card L := Nat.cast_nonneg _
  set R : ℝ := 2 * (Fintype.card L) * V / (1 - θ) + 1 with hR
  have hR1 : 1 ≤ R := by
    have : 0 ≤ 2 * (Fintype.card L : ℝ) * V / (1 - θ) := by positivity
    linarith
  have hR0 : 0 < R := by linarith
  have hRV : (Fintype.card L : ℝ) * V ≤ (1 - θ) / 2 * R := by
    have e : (1 - θ) / 2 * (2 * (Fintype.card L) * V / (1 - θ)) = (Fintype.card L : ℝ) * V := by
      field_simp
    rw [hR, mul_add, e]
    linarith
  refine ⟨fun α => R ^ Φ α * v α, fun α => mul_pos (pow_pos hR0 _) (by linarith [hv α]),
    fun β => ?_⟩
  have hpowβ : 0 < R ^ Φ β := pow_pos hR0 _
  set Lβ : Finset L := univ.filter (fun l => tgt l = β) with hLβ
  rw [← Finset.sum_filter_add_sum_filter_not Lβ (fun l => Φ (src l) = Φ (tgt l))]
  -- The lifts of `β` that keep `Φ`: at most one, and it is the one given by `lam` and `w`.
  have hlev : ∑ l ∈ Lβ.filter (fun l => Φ (src l) = Φ (tgt l)), R ^ Φ (src l) * v (src l) * wt l
      ≤ θ * (R ^ Φ β * v β) := by
    have hterm : ∀ l ∈ Lβ.filter (fun l => Φ (src l) = Φ (tgt l)),
        R ^ Φ (src l) * v (src l) * wt l = R ^ Φ β * (v (lam β) * w β) := by
      intro l hl
      simp only [hLβ, Finset.mem_filter, Finset.mem_univ, true_and] at hl
      obtain ⟨hs, hwl⟩ := hlevel l hl.2
      rw [hl.2, hs, hwl, hl.1]; ring
    rw [Finset.sum_congr rfl hterm, Finset.sum_const, nsmul_eq_mul]
    have hcard : ((Lβ.filter (fun l => Φ (src l) = Φ (tgt l))).card : ℝ) ≤ 1 := by
      have h : (Lβ.filter (fun l => Φ (src l) = Φ (tgt l))).card ≤ 1 := by
        refine Finset.card_le_one.2 fun l hl l' hl' => ?_
        simp only [hLβ, Finset.mem_filter, Finset.mem_univ, true_and] at hl hl'
        exact huniq l l' hl.2 hl'.2 (hl.1.trans hl'.1.symm)
      exact_mod_cast h
    have hnn : 0 ≤ R ^ Φ β * (v (lam β) * w β) :=
      mul_nonneg hpowβ.le (mul_nonneg (hv0 _) (hw0 β))
    have h2 := mul_le_mul_of_nonneg_left (hvw β) hpowβ.le
    nlinarith
  -- The other lifts of `β` come from a lower value of `Φ`.
  have hnon : ∑ l ∈ Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l)),
      R ^ Φ (src l) * v (src l) * wt l ≤ (1 - θ) / 2 * (R ^ Φ β * v β) := by
    have hterm : ∀ l ∈ Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l)),
        R ^ Φ (src l) * v (src l) * wt l ≤ R ^ Φ β / R * V := by
      intro l hl
      simp only [hLβ, Finset.mem_filter, Finset.mem_univ, true_and] at hl
      have hlt : Φ (src l) + 1 ≤ Φ β := by
        have h := hΦ l
        rw [hl.1] at h
        have hne := hl.2
        rw [hl.1] at hne
        omega
      have hpow : R ^ Φ (src l) ≤ R ^ Φ β / R := by
        rw [le_div_iff₀ hR0, ← pow_succ]
        exact pow_le_pow_right₀ hR1 hlt
      have hnn : 0 ≤ R ^ Φ (src l) * v (src l) := mul_nonneg (pow_pos hR0 _).le (hv0 _)
      calc R ^ Φ (src l) * v (src l) * wt l ≤ R ^ Φ (src l) * v (src l) * 1 :=
            mul_le_mul_of_nonneg_left (hwt1 l) hnn
        _ = R ^ Φ (src l) * v (src l) := mul_one _
        _ ≤ R ^ Φ β / R * V :=
            mul_le_mul hpow (hvV _) (hv0 _) (div_nonneg hpowβ.le hR0.le)
    have hcard : ((Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l))).card : ℝ) ≤ Fintype.card L := by
      exact_mod_cast Finset.card_le_univ _
    have hq : 0 ≤ R ^ Φ β / R := div_nonneg hpowβ.le hR0.le
    calc ∑ l ∈ Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l)), R ^ Φ (src l) * v (src l) * wt l
        ≤ ∑ _l ∈ Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l)), R ^ Φ β / R * V :=
          Finset.sum_le_sum hterm
      _ = (Lβ.filter (fun l => ¬ Φ (src l) = Φ (tgt l))).card * (R ^ Φ β / R * V) := by
          rw [Finset.sum_const, nsmul_eq_mul]
      _ ≤ (Fintype.card L : ℝ) * (R ^ Φ β / R * V) :=
          mul_le_mul_of_nonneg_right hcard (mul_nonneg hq hV0)
      _ = R ^ Φ β / R * ((Fintype.card L : ℝ) * V) := by ring
      _ ≤ R ^ Φ β / R * ((1 - θ) / 2 * R) := mul_le_mul_of_nonneg_left hRV hq
      _ = (1 - θ) / 2 * R ^ Φ β := by field_simp
      _ ≤ (1 - θ) / 2 * (R ^ Φ β * v β) := by
          have h := hv β
          have h3 : R ^ Φ β ≤ R ^ Φ β * v β := by nlinarith
          exact mul_le_mul_of_nonneg_left h3 (by linarith)
  linarith

"Since ∞ is marked, the bounded disk of an essential plane circle contains between 2 and s - 1 finite labels" (lines 793-794). D is the set of finite labels in the bounded disk. The unbounded side contains the other finite labels and ∞. Essential means at least two marks on each side.

390
theorem bounded_side_card_of_essential {A : Type*} [Fintype A] [DecidableEq A] (D : Finset A)
    (hin : 2 ≤ D.card) (hout : 2 ≤ Dᶜ.card + 1) :
    2 ≤ D.card ∧ D.card ≤ Fintype.card A - 1 := by
proof · 3 lines
  have h := D.card_compl
  have h' := D.card_le_univ
  omega

"It follows that an essential closed preimage component has essential image" (line 821). D is the set of finite labels in the disk bounded by the closed lift, and Δ is the set of finite labels in the bounded target disk. The three cases of lines 804-820 are the hypotheses:

* hmap: the disk of the lift maps to the target disk, and marks map to marks. This gives "if the target disk contains no finite mark, its proper preimage disks contain none". * hone: "if it contains just one mark […] at most one source mark lies in the disk". * hall: for a transcendental map there is no closed lift when the target disk contains all finite marks.

406
theorem essential_image_of_essential_lift {A : Type*} [Fintype A] (f : A → A)
    (D Δ : Finset A) (hmap : ∀ a ∈ D, f a ∈ Δ) (hone : Δ.card = 1 → D.card ≤ 1)
    (hall : Δ ≠ univ) (hD : 2 ≤ D.card) : 2 ≤ Δ.card ∧ Δ.card ≤ Fintype.card A - 1 := by
proof · 8 lines
  have hne : Δ.card ≠ 0 := by
    obtain ⟨a, ha⟩ := Finset.card_pos.1 (by omega : 0 < D.card)
    exact (Finset.card_pos.2 ⟨f a, hmap a ha⟩).ne'
  have h1 : Δ.card ≠ 1 := fun h => by have := hone h; omega
  have hlt : Δ.card < Fintype.card A := by
    rw [← Finset.card_univ]
    exact Finset.card_lt_card (Finset.ssubset_univ_iff.2 hall)
  omega

"For a fixed target representative the compact preimage disks are disjoint. Each essential one contains at least two finite marks, so the entries are finite sums" (lines 870-871): the set of lifts is finite.

421
theorem finite_lifts {Λ A L : Type*} [Finite Λ] [Finite A] (src tgt : L → Λ)
    (S : Λ → Finset A) (hS : ∀ α, (S α).Nonempty)
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l'))) :
    Finite L := by
proof · 10 lines
  have hinj : Function.Injective fun l : L => (tgt l, S (src l)) := by
    intro l l' h
    by_contra hne
    have h1 : tgt l = tgt l' := congrArg Prod.fst h
    have h2 : S (src l) = S (src l') := congrArg Prod.snd h
    have hd := hdisj l l' hne h1
    rw [h2] at hd
    obtain ⟨a, ha⟩ := hS (src l')
    exact Finset.disjoint_left.1 hd ha ha
  exact Finite.of_injective _ hinj

The hypotheses of essential_image_of_essential_lift can hold together (the example z² - 1 of the paper, with labels 0, 1, 2 for the marks -1, 0, a).

438
example : ∃ (f : Fin 3 → Fin 3) (D Δ : Finset (Fin 3)), (∀ a ∈ D, f a ∈ Δ) ∧
    (Δ.card = 1 → D.card ≤ 1) ∧ Δ ≠ univ ∧ 2 ≤ D.card :=
proof · 1 line
  ⟨![1, 0, 2], {0, 1}, {0, 1}, by decide, by decide, by decide, by decide⟩

The matrix of a single weighted cycle on p classes: the entry (i, i + 1) is w i.

449
def cycleMatrix (p : ℕ) (w : ZMod p → ℝ) : Matrix (ZMod p) (ZMod p) ℝ :=
body · 1 line
  Matrix.of fun i j => if j = i + 1 then w i else 0
452
theorem cycleMatrix_pow_apply (p : ℕ) [NeZero p] (w : ZMod p → ℝ) (k : ℕ) (i j : ZMod p) :
    (cycleMatrix p w ^ k) i j = if j = i + k then ∏ a ∈ range k, w (i + a) else 0 := by
proof · 10 lines
  induction k generalizing j with
  | zero => simp [Matrix.one_apply, eq_comm]
  | succ k ih =>
    rw [pow_succ, Matrix.mul_apply]
    simp only [ih]
    simp only [cycleMatrix, Matrix.of_apply, ite_mul, zero_mul, Finset.sum_ite_eq',
      Finset.mem_univ, ↓reduceIte]
    have e : i + ((k + 1 : ℕ) : ZMod p) = i + (k : ZMod p) + 1 := by push_cast; ring
    rw [e, Finset.prod_range_succ]
    split_ifs <;> simp
465
theorem prod_range_natCast_zmod (p : ℕ) [NeZero p] (g : ZMod p → ℝ) :
    ∏ a ∈ range p, g (a : ZMod p) = ∏ x : ZMod p, g x := by
proof · 8 lines
  refine Finset.prod_bij (fun a _ => (a : ZMod p)) (fun _ _ => Finset.mem_univ _) ?_ ?_
    (fun _ _ => rfl)
  · intro a ha b hb hab
    rw [Finset.mem_range] at ha hb
    have h := (ZMod.natCast_eq_natCast_iff' a b p).1 hab
    rwa [Nat.mod_eq_of_lt ha, Nat.mod_eq_of_lt hb] at h
  · intro x _
    exact ⟨x.val, Finset.mem_range.2 (ZMod.val_lt x), ZMod.natCast_zmod_val x⟩

"The component is a single cycle with weights 1/d_1, …, 1/d_p. The pth power of its matrix is (∏ d_i)⁻¹ times the identity" (lines 887-888). Here w i = 1 / d_i.

478
theorem cycleMatrix_pow_self (p : ℕ) [NeZero p] (w : ZMod p → ℝ) :
    cycleMatrix p w ^ p = (∏ i, w i) • (1 : Matrix (ZMod p) (ZMod p) ℝ) := by
proof · 10 lines
  ext i j
  rw [cycleMatrix_pow_apply, Matrix.smul_apply, Matrix.one_apply, ZMod.natCast_self, add_zero,
    prod_range_natCast_zmod p (fun x => w (i + x)), smul_eq_mul]
  have hshift : ∏ x : ZMod p, w (i + x) = ∏ x : ZMod p, w x :=
    Fintype.prod_equiv (Equiv.addLeft i) _ _ (fun _ => rfl)
  rw [hshift]
  by_cases h : j = i
  · simp [h]
  · have h' : ¬ i = j := fun h'' => h h''.symm
    simp [h, h']

Every complex eigenvalue μ of the cycle matrix has μ^p = ∏ w_i.

492
theorem cycleMatrix_eigenvalue_pow (p : ℕ) [NeZero p] (w : ZMod p → ℝ) (μ : ℂ)
    (hμ : μ ∈ spectrum ℂ ((cycleMatrix p w).map (algebraMap ℝ ℂ))) :
    μ ^ p = ((∏ i, w i : ℝ) : ℂ) := by
proof · 11 lines
  have h1 := spectrum.pow_mem_pow _ p hμ
  have h3 : ((cycleMatrix p w).map (algebraMap ℝ ℂ)) ^ p
      = (cycleMatrix p w ^ p).map (algebraMap ℝ ℂ) := by
    rw [← RingHom.mapMatrix_apply, ← RingHom.mapMatrix_apply, map_pow]
  have h2 : ((cycleMatrix p w).map (algebraMap ℝ ℂ)) ^ p
      = algebraMap ℂ (Matrix (ZMod p) (ZMod p) ℂ) ((∏ i, w i : ℝ) : ℂ) := by
    rw [h3, cycleMatrix_pow_self, Algebra.algebraMap_eq_smul_one]
    ext i j
    by_cases h : i = j <;> simp [h]
  rw [h2, spectrum.scalar_eq] at h1
  exact h1

"so the spectral radius of this block is (∏ d_i)^{-1/p}" (lines 888-890): every complex eigenvalue μ of the cycle matrix with weights w_i = 1 / d_i has |μ|^p = ∏ w_i.

509
theorem cycleMatrix_eigenvalue_norm_pow (p : ℕ) [NeZero p] (w : ZMod p → ℝ)
    (hw : ∀ i, 0 ≤ w i) (μ : ℂ)
    (hμ : μ ∈ spectrum ℂ ((cycleMatrix p w).map (algebraMap ℝ ℂ))) :
    ‖μ‖ ^ p = ∏ i, w i := by
proof · 2 lines
  rw [← norm_pow, cycleMatrix_eigenvalue_pow p w μ hμ, Complex.norm_real,
    Real.norm_of_nonneg (Finset.prod_nonneg fun i _ => hw i)]

The matrix M of the Matrix lemma: "form M_{αβ} by summing reciprocal degrees of components of f⁻¹(β) in class α" (line 867).

533
noncomputable def thurstonMatrix (src tgt : L → Λ) (deg : L → ℕ) : Matrix Λ Λ ℝ :=
body · 1 line
  Matrix.of fun α β => ∑ l ∈ univ.filter (fun l => src l = α ∧ tgt l = β), (1 : ℝ) / deg l

A Levy cycle among the classes of the multicurve: pairwise distinct classes δ_0, …, δ_{p-1} and lifts ℓ_0, …, ℓ_{p-1} of degree one, where ℓ_a is a component of f⁻¹(δ_a) in the class δ_{a+1}, indices modulo p (Section 1, lines 107-111, with the classes numbered in the opposite direction).

540
def HasLevyCycle (src tgt : L → Λ) (deg : L → ℕ) : Prop :=
body · 2 lines
  ∃ (p : ℕ) (δ : ℕ → Λ) (ℓ : ℕ → L), 0 < p ∧ (∀ a < p, ∀ b < p, δ a = δ b → a = b) ∧
    ∀ a < p, tgt (ℓ a) = δ a ∧ src (ℓ a) = δ ((a + 1) % p) ∧ deg (ℓ a) = 1
544
theorem thurstonMatrix_nonneg (α β : Λ) : 0 ≤ thurstonMatrix src tgt deg α β := by
proof · 3 lines
  unfold thurstonMatrix
  rw [Matrix.of_apply]
  exact Finset.sum_nonneg fun l _ => by positivity

A weighted column sum of M is a sum over the lifts of β.

550
theorem sum_mul_thurstonMatrix (u : Λ → ℝ) (β : Λ) :
    ∑ α, u α * thurstonMatrix src tgt deg α β
      = ∑ l ∈ univ.filter (fun l => tgt l = β), u (src l) * (1 / deg l) := by
proof · 6 lines
  simp only [thurstonMatrix, Matrix.of_apply, Finset.mul_sum, Finset.sum_filter]
  rw [Finset.sum_comm]
  refine Finset.sum_congr rfl fun l _ => ?_
  by_cases h : tgt l = β
  · simp [h]
  · simp [h]

Two distinct lifts of the same curve are in different classes: their disks are disjoint, and the disks of two lifts in one class contain the same labels.

562
theorem src_ne_of_ne (hS : ∀ α, (S α).Nonempty)
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    {l l' : L} (hne : l ≠ l') (ht : tgt l = tgt l') : src l ≠ src l' := by
proof · 5 lines
  intro h
  have hd := hdisj l l' hne ht
  rw [h] at hd
  obtain ⟨a, ha⟩ := hS (src l')
  exact Finset.disjoint_left.1 hd ha ha

So each entry of M is a sum with at most one term: it is zero or one reciprocal degree.

572
theorem card_lifts_le_one (hS : ∀ α, (S α).Nonempty)
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (α β : Λ) : (univ.filter (fun l => src l = α ∧ tgt l = β)).card ≤ 1 := by
proof · 4 lines
  refine Finset.card_le_one.2 fun l hl l' hl' => ?_
  simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hl hl'
  by_contra hne
  exact src_ne_of_ne src tgt S hS hdisj hne (hl.2.trans hl'.2.symm) (hl.1.trans hl'.1.symm)

P_α: "the periodic labels among them" (line 875).

582
noncomputable def perLabels (S : Λ → Finset A) (f : A → A) (α : Λ) : Finset A :=
body · 1 line
  (S α).filter fun a => a ∈ periodicPts f
585
theorem mem_perLabels {α : Λ} {a : A} :
    a ∈ perLabels S f α ↔ a ∈ S α ∧ a ∈ periodicPts f := by
proof · 1 line
  simp [perLabels]

"Thus along internal arrows the cardinality of P_α cannot decrease" (line 880). Here this holds along every arrow: f maps P_α into P_β, and f is injective on periodic labels.

591
theorem perLabels_card_le (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l)) (l : L) :
    (perLabels S f (src l)).card ≤ (perLabels S f (tgt l)).card := by
proof · 7 lines
  refine Finset.card_le_card_of_injOn f ?_ ?_
  · intro a ha
    have ha' := (mem_perLabels S f).1 ha
    exact (mem_perLabels S f).2 ⟨hmap l a ha'.1, (bijOn_periodicPts f).mapsTo ha'.2⟩
  · intro a ha b hb hab
    exact (bijOn_periodicPts f).injOn ((mem_perLabels S f).1 ha).2
      ((mem_perLabels S f).1 hb).2 hab

"In particular f(P_α) = P_β along each internal arrow" (line 881): when the two sets have the same number of elements.

603
theorem image_perLabels_eq [DecidableEq A] (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l)) (l : L)
    (hcard : (perLabels S f (src l)).card = (perLabels S f (tgt l)).card) :
    (perLabels S f (src l)).image f = perLabels S f (tgt l) := by
proof · 9 lines
  refine Finset.eq_of_subset_of_card_le ?_ ?_
  · intro b hb
    obtain ⟨a, ha, rfl⟩ := Finset.mem_image.1 hb
    have ha' := (mem_perLabels S f).1 ha
    exact (mem_perLabels S f).2 ⟨hmap l a ha'.1, (bijOn_periodicPts f).mapsTo ha'.2⟩
  · rw [Finset.card_image_of_injOn, hcard]
    intro a ha b hb hab
    exact (bijOn_periodicPts f).injOn ((mem_perLabels S f).1 ha).2
      ((mem_perLabels S f).1 hb).2 hab

Every label is periodic after |A| steps.

617
theorem iterate_card_mem_periodicPts (b : A) : f^[Fintype.card A] b ∈ periodicPts f := by
proof · 15 lines
  obtain ⟨i, j, hij, heq⟩ := Fintype.exists_ne_map_eq_of_card_lt
    (fun a : Fin (Fintype.card A + 1) => f^[a] b) (by simp)
  wlog hlt : (i : ℕ) < j generalizing i j
  · have hne : (i : ℕ) ≠ j := fun h => hij (Fin.ext h)
    exact this j i hij.symm heq.symm (by omega)
  have heq' : f^[(i : ℕ)] b = f^[(j : ℕ)] b := heq
  have hper : IsPeriodicPt f ((j : ℕ) - i) (f^[(i : ℕ)] b) := by
    show f^[(j : ℕ) - i] (f^[(i : ℕ)] b) = f^[(i : ℕ)] b
    rw [← Function.iterate_add_apply, Nat.sub_add_cancel hlt.le, ← heq']
  have hmem : f^[(i : ℕ)] b ∈ periodicPts f := mk_mem_periodicPts (by omega) hper
  have hi : (i : ℕ) ≤ Fintype.card A := by have := j.2; omega
  have hsplit : f^[Fintype.card A] b = f^[Fintype.card A - i] (f^[(i : ℕ)] b) := by
    rw [← Function.iterate_add_apply, Nat.sub_add_cancel hi]
  rw [hsplit]
  exact ((bijOn_periodicPts f).mapsTo.iterate _) hmem

"If a cycle through α has length p, then f^p(S_α) ⊂ S_α. This nonempty finite set contains a periodic label by iterating f^p" (lines 877-879). The proof of matrix_lemma does not use this statement; it uses depth_le in its place.

637
theorem exists_periodic_of_iterate_mapsTo (T : Finset A) (hT : T.Nonempty) (p : ℕ) (hp : 0 < p)
    (h : ∀ a ∈ T, f^[p] a ∈ T) : ∃ a ∈ T, a ∈ periodicPts f := by
proof · 12 lines
  obtain ⟨a, ha⟩ := hT
  have hiter : ∀ k, (f^[p])^[k] a ∈ T := by
    intro k
    induction k with
    | zero => exact ha
    | succ k ih => rw [Function.iterate_succ_apply']; exact h _ ih
  refine ⟨_, hiter (Fintype.card A), ?_⟩
  obtain ⟨n, hn, hx⟩ := mem_periodicPts.1 (iterate_card_mem_periodicPts (f^[p]) a)
  refine mk_mem_periodicPts (Nat.mul_pos hp hn) ?_
  show f^[p * n] _ = _
  rw [Function.iterate_mul]
  exact hx

S α contains a label of the form f^j(b).

653
def MeetsImage (S : Λ → Finset A) (f : A → A) (α : Λ) (j : ℕ) : Prop :=
body · 1 line
  ∃ a ∈ S α, ∃ b, f^[j] b = a

The largest j ≤ |A| such that S α contains a label of the form f^j(b). It equals |A| exactly when S α contains a periodic label.

659
noncomputable def depth (S : Λ → Finset A) (f : A → A) (α : Λ) : ℕ :=
body · 1 line
  Nat.findGreatest (MeetsImage S f α) (Fintype.card A)

The potential: it does not decrease along an arrow (potential_le).

663
noncomputable def potential (S : Λ → Finset A) (f : A → A) (α : Λ) : ℕ :=
body · 1 line
  depth S f α + (perLabels S f α).card
666
theorem meetsImage_depth (hS : ∀ α, (S α).Nonempty) (α : Λ) :
    MeetsImage S f α (depth S f α) := by
proof · 4 lines
  classical
  unfold depth
  obtain ⟨a, ha⟩ := hS α
  exact Nat.findGreatest_spec (P := MeetsImage S f α) (Nat.zero_le _) ⟨a, ha, a, rfl⟩
673
theorem depth_le_card (α : Λ) : depth S f α ≤ Fintype.card A := by
proof · 3 lines
  classical
  unfold depth
  exact Nat.findGreatest_le _
678
theorem le_depth {α : Λ} {j : ℕ} (hj : j ≤ Fintype.card A) (h : MeetsImage S f α j) :
    j ≤ depth S f α := by
proof · 3 lines
  classical
  unfold depth
  exact Nat.le_findGreatest hj h

Along an arrow the depth does not decrease. If it stays the same, the source class contains a periodic label.

686
theorem depth_le (hS : ∀ α, (S α).Nonempty) (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (l : L) : depth S f (src l) ≤ depth S f (tgt l) ∧
      (depth S f (src l) = depth S f (tgt l) → (perLabels S f (src l)).Nonempty) := by
proof · 16 lines
  have hspec := meetsImage_depth S f hS (src l)
  have hle := depth_le_card S f (src l)
  have hnext : MeetsImage S f (tgt l) (depth S f (src l) + 1) := by
    obtain ⟨a, ha, b, rfl⟩ := hspec
    exact ⟨f (f^[depth S f (src l)] b), hmap l _ ha, b, Function.iterate_succ_apply' f _ b⟩
  rcases Nat.lt_or_ge (depth S f (src l)) (Fintype.card A) with hlt | hge
  · have h1 : depth S f (src l) + 1 ≤ depth S f (tgt l) := le_depth S f hlt hnext
    exact ⟨by omega, fun h => by omega⟩
  · have hK : depth S f (src l) = Fintype.card A := le_antisymm hle hge
    have hprev : MeetsImage S f (tgt l) (depth S f (src l)) := by
      obtain ⟨a, ha, b, hb⟩ := hnext
      exact ⟨a, ha, f b, by rw [← hb, Function.iterate_succ_apply]⟩
    refine ⟨le_depth S f hle hprev, fun _ => ?_⟩
    rw [hK] at hspec
    obtain ⟨a, ha, b, rfl⟩ := hspec
    exact ⟨_, (mem_perLabels S f).2 ⟨ha, iterate_card_mem_periodicPts f b⟩⟩
706
theorem potential_le (hS : ∀ α, (S α).Nonempty) (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (l : L) : potential S f (src l) ≤ potential S f (tgt l) := by
proof · 4 lines
  have h1 := (depth_le src tgt S f hS hmap l).1
  have h2 := perLabels_card_le src tgt S f hmap l
  unfold potential
  omega

A lift that keeps the potential: P_α is not empty and f(P_α) = P_β. In the paper these are the internal arrows of a recurrent component (lines 877-881).

715
theorem level_facts [DecidableEq A] (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l)) (l : L)
    (hl : potential S f (src l) = potential S f (tgt l)) :
    (perLabels S f (src l)).Nonempty ∧
      (perLabels S f (src l)).image f = perLabels S f (tgt l) := by
proof · 4 lines
  have h1 := depth_le src tgt S f hS hmap l
  have h2 := perLabels_card_le src tgt S f hmap l
  unfold potential at hl
  exact ⟨h1.2 (by omega), image_perLabels_eq src tgt S f hmap l (by omega)⟩

"For one fixed target representative β, every internal predecessor disk must contain the entire set (f|𝒫)⁻¹(P_β) […]. Disjointness therefore allows just one, even counting multiple lifts in the same class" (lines 882-885).

728
theorem level_lift_unique (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (l l' : L) (hl : potential S f (src l) = potential S f (tgt l))
    (hl' : potential S f (src l') = potential S f (tgt l')) (ht : tgt l = tgt l') : l = l' := by
proof · 13 lines
  classical
  by_contra hne
  obtain ⟨⟨a, ha⟩, him⟩ := level_facts src tgt S f hS hmap l hl
  obtain ⟨-, him'⟩ := level_facts src tgt S f hS hmap l' hl'
  have hfa : f a ∈ perLabels S f (tgt l') := by
    rw [← ht, ← him]; exact Finset.mem_image_of_mem f ha
  rw [← him'] at hfa
  obtain ⟨a', ha', haa'⟩ := Finset.mem_image.1 hfa
  have heq : a' = a := (bijOn_periodicPts f).injOn ((mem_perLabels S f).1 ha').2
    ((mem_perLabels S f).1 ha).2 haa'
  subst heq
  exact Finset.disjoint_left.1 (hdisj l l' hne ht) ((mem_perLabels S f).1 ha).1
    ((mem_perLabels S f).1 ha').1

The lift over β that keeps the potential, as a map lam on classes with a weight w. Where there is no such lift, w β = 0.

749
theorem exists_level_map (hdeg : ∀ l, 1 ≤ deg l) (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l'))) :
    ∃ (lam : Λ → Λ) (w : Λ → ℝ), (∀ β, 0 ≤ w β) ∧ (∀ β, w β ≤ 1) ∧
      (∀ l, potential S f (src l) = potential S f (tgt l) →
        src l = lam (tgt l) ∧ (1 : ℝ) / deg l = w (tgt l)) ∧
      ∀ β, w β ≠ 0 → ∃ l, tgt l = β ∧ src l = lam β ∧ w β = 1 / deg l := by
proof · 28 lines
  classical
  have hdeg1 : ∀ l, (1 : ℝ) / deg l ≤ 1 := fun l => by
    have h : (1 : ℝ) ≤ deg l := by exact_mod_cast hdeg l
    rw [div_le_one (by linarith)]; exact h
  refine ⟨fun β => if h : ∃ l, tgt l = β ∧ potential S f (src l) = potential S f β
      then src h.choose else β,
    fun β => if h : ∃ l, tgt l = β ∧ potential S f (src l) = potential S f β
      then 1 / (deg h.choose : ℝ) else 0, fun β => ?_, fun β => ?_, fun l hl => ?_, fun β hβ => ?_⟩
  · dsimp only
    split_ifs
    · positivity
    · exact le_rfl
  · dsimp only
    split_ifs
    · exact hdeg1 _
    · norm_num
  · have h : ∃ l', tgt l' = tgt l ∧ potential S f (src l') = potential S f (tgt l) := ⟨l, rfl, hl⟩
    have hc : h.choose = l := by
      obtain ⟨h1, h2⟩ := h.choose_spec
      exact level_lift_unique src tgt S f hS hmap hdisj _ _ (by rw [h1]; exact h2) hl h1
    dsimp only
    split_ifs
    rw [hc]
    exact ⟨rfl, rfl⟩
  · dsimp only at hβ ⊢
    split_ifs at hβ ⊢ with h
    · exact ⟨h.choose, h.choose_spec.1, rfl, rfl⟩
    · exact absurd rfl hβ

The key bound: without a Levy cycle there are a positive vector u and a number θ < 1 with u M ≤ θ u.

787
theorem exists_weighted_bound (hdeg : ∀ l, 1 ≤ deg l) (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (hLevy : ¬ HasLevyCycle src tgt deg) :
    ∃ (u : Λ → ℝ) (θ : ℝ), (∀ α, 0 < u α) ∧ 0 ≤ θ ∧ θ < 1 ∧
      ∀ β, ∑ α, u α * thurstonMatrix src tgt deg α β ≤ θ * u β := by
proof · 44 lines
  obtain ⟨lam, w, hw0, hw1, hlevel, hwne⟩ := exists_level_map src tgt deg S f hdeg hS hmap hdisj
  -- A cycle of `lam` with all weights above `1/2` would be a Levy cycle.
  have hcyc : ∀ γ p, 0 < p → lam^[p] γ = γ → ∃ a < p, w (lam^[a] γ) ≤ 1 / 2 := by
    intro γ p hp hper
    by_contra hcon
    push Not at hcon
    have hlift : ∀ a, a < p → ∃ l, tgt l = lam^[a] γ ∧ src l = lam^[a + 1] γ ∧ deg l = 1 := by
      intro a ha
      have hwa := hcon a ha
      obtain ⟨l, hl1, hl2, hl3⟩ := hwne (lam^[a] γ) (by linarith)
      refine ⟨l, hl1, by rw [hl2, Function.iterate_succ_apply'], ?_⟩
      rw [hl3] at hwa
      have hd : (1 : ℝ) ≤ deg l := by exact_mod_cast hdeg l
      have hd2 : (deg l : ℝ) < 2 := by
        rw [lt_div_iff₀ (by linarith)] at hwa; linarith
      have hd3 : deg l < 2 := by exact_mod_cast hd2
      have := hdeg l
      omega
    obtain ⟨l₀, -⟩ := hlift 0 hp
    have hlift' : ∀ a, ∃ l, a < p → tgt l = lam^[a] γ ∧ src l = lam^[a + 1] γ ∧ deg l = 1 := by
      intro a
      by_cases ha : a < p
      · obtain ⟨l, hl⟩ := hlift a ha
        exact ⟨l, fun _ => hl⟩
      · exact ⟨l₀, fun h => absurd h ha⟩
    choose ℓ hℓ using hlift'
    have hperpt : IsPeriodicPt lam p γ := hper
    have hmin_pos : 0 < minimalPeriod lam γ := hperpt.minimalPeriod_pos hp
    have hmin_le : minimalPeriod lam γ ≤ p := hperpt.minimalPeriod_le hp
    refine hLevy ⟨minimalPeriod lam γ, fun a => lam^[a] γ, ℓ, hmin_pos, fun a ha b hb hab => ?_,
      fun a ha => ?_⟩
    · exact iterate_injOn_Iio_minimalPeriod (Set.mem_Iio.2 ha) (Set.mem_Iio.2 hb) hab
    · obtain ⟨h1, h2, h3⟩ := hℓ a (by omega)
      exact ⟨h1, by rw [h2]; exact (iterate_mod_minimalPeriod_eq (f := lam) (x := γ)).symm, h3⟩
  obtain ⟨θ, v, hθ0, hθ1, hv, hvw⟩ := exists_weight_of_no_unit_cycle lam w hw0 hw1 hcyc
  have hdeg1 : ∀ l, (1 : ℝ) / deg l ≤ 1 := fun l => by
    have h : (1 : ℝ) ≤ deg l := by exact_mod_cast hdeg l
    rw [div_le_one (by linarith)]; exact h
  obtain ⟨u, hu, hbound⟩ := exists_weighted_bound_of_levels src tgt (fun l => (1 : ℝ) / deg l)
    hdeg1 (potential S f) (potential_le src tgt S f hS hmap) lam w hw0 hlevel
    (level_lift_unique src tgt S f hS hmap hdisj) θ hθ1 v hv hvw
  refine ⟨u, (1 + θ) / 2, hu, by linarith, by linarith, fun β => ?_⟩
  rw [sum_mul_thurstonMatrix]
  exact hbound β

Matrix lemma (lines 867-868): "For a finite multicurve Λ, form M_{αβ} by summing reciprocal degrees of components of f⁻¹(β) in class α. If f has no Levy cycle, then ρ(M) < 1." The header of this file says how the hypotheses match the paper.

841
theorem matrix_lemma (hdeg : ∀ l, 1 ≤ deg l) (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (hLevy : ¬ HasLevyCycle src tgt deg) :
    spectralRadius ℂ ((thurstonMatrix src tgt deg).map (algebraMap ℝ ℂ)) < 1 := by
proof · 3 lines
  obtain ⟨u, θ, hu, -, hθ1, hθ⟩ := exists_weighted_bound src tgt deg S f hdeg hS hmap hdisj hLevy
  exact spectralRadius_lt_one_of_weighted_bound _ (thurstonMatrix_nonneg src tgt deg) u hu θ
    hθ1 hθ

The Matrix lemma for single eigenvalues: every complex eigenvalue of M has modulus below one.

852
theorem matrix_lemma_eigenvalue (hdeg : ∀ l, 1 ≤ deg l) (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (hLevy : ¬ HasLevyCycle src tgt deg) (μ : ℂ)
    (hμ : μ ∈ spectrum ℂ ((thurstonMatrix src tgt deg).map (algebraMap ℝ ℂ))) : ‖μ‖ < 1 := by
proof · 3 lines
  obtain ⟨u, θ, hu, -, hθ1, hθ⟩ := exists_weighted_bound src tgt deg S f hdeg hS hmap hdisj hLevy
  exact lt_of_le_of_lt (norm_le_of_mem_spectrum_of_weighted_bound _
    (thurstonMatrix_nonneg src tgt deg) u hu θ hθ μ hμ) hθ1

The form in which the Matrix lemma is used (Figure 1, (M_Λ^k)_{γγ} → 0): every entry of M^k tends to zero as k → ∞.

863
theorem matrix_lemma_tendsto (hdeg : ∀ l, 1 ≤ deg l) (hS : ∀ α, (S α).Nonempty)
    (hmap : ∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l))
    (hdisj : ∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l')))
    (hLevy : ¬ HasLevyCycle src tgt deg) (α β : Λ) :
    Filter.Tendsto (fun k : ℕ => (thurstonMatrix src tgt deg ^ k) α β) Filter.atTop (nhds 0) := by
proof · 4 lines
  obtain ⟨u, θ, hu, hθ0, hθ1, hθ⟩ :=
    exists_weighted_bound src tgt deg S f hdeg hS hmap hdisj hLevy
  exact tendsto_pow_apply_zero_of_weighted_bound _ (thurstonMatrix_nonneg src tgt deg) u hu θ
    hθ0 hθ1 hθ α β

The hypotheses of matrix_lemma can hold together: the paper's example z² - 1 (lines 853-855). The labels 0, 1, 2 stand for the marks -1, 0, a; the map exchanges -1 and 0 and fixes a. There is one curve, with -1 and 0 on its bounded side, and one lift, of degree two. The matrix is [1/2].

877
example : ∃ (src tgt : Unit → Unit) (deg : Unit → ℕ) (S : Unit → Finset (Fin 3))
    (f : Fin 3 → Fin 3), (∀ l, 1 ≤ deg l) ∧ (∀ α, (S α).Nonempty) ∧
    (∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l)) ∧
    (∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l'))) ∧
    ¬ HasLevyCycle src tgt deg ∧ thurstonMatrix src tgt deg () () = 1 / 2 := by
proof · 6 lines
  refine ⟨id, id, fun _ => 2, fun _ => {0, 1}, ![1, 0, 2], fun _ => by norm_num,
    fun _ => ⟨0, by simp⟩, by decide, fun l l' h => absurd (Subsingleton.elim l l') h, ?_, ?_⟩
  · rintro ⟨p, δ, ℓ, hp, -, h⟩
    have h1 := (h 0 hp).2.2
    norm_num at h1
  · simp [thurstonMatrix]

The hypothesis hLevy of matrix_lemma cannot be dropped. In the same model with a lift of degree one, the other hypotheses hold and the matrix is [1], with spectral radius one.

891
example : ∃ (src tgt : Unit → Unit) (deg : Unit → ℕ) (S : Unit → Finset (Fin 3))
    (f : Fin 3 → Fin 3), (∀ l, 1 ≤ deg l) ∧ (∀ α, (S α).Nonempty) ∧
    (∀ l, ∀ a ∈ S (src l), f a ∈ S (tgt l)) ∧
    (∀ l l', l ≠ l' → tgt l = tgt l' → Disjoint (S (src l)) (S (src l'))) ∧
    thurstonMatrix src tgt deg () () = 1 := by
proof · 3 lines
  refine ⟨id, id, fun _ => 1, fun _ => {0, 1}, ![1, 0, 2], fun _ => le_rfl,
    fun _ => ⟨0, by simp⟩, by decide, fun l l' h => absurd (Subsingleton.elim l l') h, ?_⟩
  simp [thurstonMatrix]