Holevo Additivity Gap in Lean 4

Lean explorer

Exact Lean source

Nonadditivity.Linearization

Download original .lean · View on GitHub · Jump to source

Direct imports

  • Mathlib.Data.Real.Basic dependency
  • Mathlib.Data.Real.Sqrt dependency
  • Mathlib.Algebra.Order.BigOperators.Ring.Finset dependency
  • Mathlib.Analysis.Normed.Operator.Basic dependency
  • Mathlib.Data.Finset.Prod dependency
  • Mathlib.Data.Fintype.Sigma dependency
  • Mathlib.Data.Fin.Rev dependency
  • Mathlib.Data.Matrix.Block dependency
  • Mathlib.Data.Matrix.ColumnRowPartitioned dependency
  • Mathlib.Analysis.Matrix.Order dependency
  • Mathlib.Analysis.CStarAlgebra.Matrix dependency
  • Mathlib.LinearAlgebra.Matrix.Hermitian dependency
  • Mathlib.Tactic.Linarith dependency
  • Mathlib.Tactic.Positivity dependency
  • Mathlib.Tactic.Ring dependency
  • Mathlib.Tactic.NormNum dependency
  • Lean.Elab.Tactic.Omega dependency

Imported by project modules

4 direct reverse imports

Relationships above come from literal import commands. The declarations below link to types and references extracted from Lean’s environment. Source text is complete and unchanged.

Declarations in this module

61 project constants, including generated, internal and private declarations.

61 declarations

Full module

1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56import Mathlib.Data.Real.Basic7import Mathlib.Data.Real.Sqrt8import Mathlib.Algebra.Order.BigOperators.Ring.Finset9import Mathlib.Analysis.Normed.Operator.Basic10import Mathlib.Data.Finset.Prod11import Mathlib.Data.Fintype.Sigma12import Mathlib.Data.Fin.Rev13import Mathlib.Data.Matrix.Block14import Mathlib.Data.Matrix.ColumnRowPartitioned15import Mathlib.Analysis.Matrix.Order16import Mathlib.Analysis.CStarAlgebra.Matrix17import Mathlib.LinearAlgebra.Matrix.Hermitian18import Mathlib.Tactic.Linarith19import Mathlib.Tactic.Positivity20import Mathlib.Tactic.Ring21import Mathlib.Tactic.NormNum22import Lean.Elab.Tactic.Omega2324/-!25# Algebraic and numerical steps in polynomial linearization2627This file proves the finite support bound, Gram factorization identities,28Hermitian dilation identities, the scalar backward-error calculation, and the29geometric word-count calculation used in Sections 3 and Appendix A of30`nonadditivity.tex`.3132The analytic existence of the positive block matrix with the stated operator33norm bound is not assumed globally or declared as an axiom here. The Gram34identities below apply to any supplied square-root factor; the error theorem35states its norm-identity hypotheses explicitly.36-/3738set_option backward.isDefEq.respectTransparency false3940namespace Nonadditivity.Linearization4142open scoped BigOperators4344section Support4546variable {G : Type*} [Group G] [DecidableEq G]4748/-- The finite set `S⁻¹ S`, represented without a pointwise-set convention. -/49def differenceSupport (S : Finset G) : Finset G :=50  (S ×ˢ S).image (fun gh => gh.1⁻¹ * gh.2)5152@[simp] theorem mem_differenceSupport {S : Finset G} {w : G} :53    w ∈ differenceSupport S ↔ ∃ g ∈ S, ∃ h ∈ S, g⁻¹ * h = w := by54  simp only [differenceSupport, Finset.mem_image, Finset.mem_product]55  constructor56  · rintro ⟨⟨g,h⟩, ⟨hg,hh⟩, hw⟩57    exact ⟨g,hg,h,hh,hw⟩58  · rintro ⟨g,hg,h,hh,hw⟩59    exact ⟨(g,h), ⟨hg,hh⟩, hw⟩6061/-- There are at most `B²` differences in a set of `B` elements. -/62theorem card_differenceSupport_le (S : Finset G) :63    (differenceSupport S).card ≤ S.card ^ 2 := by64  calc65    (differenceSupport S).card ≤ (S ×ˢ S).card := Finset.card_image_le66    _ = S.card ^ 2 := by simp [pow_two]6768/-- The adjoint support is covered by the same finite set. -/69theorem inv_mem_differenceSupport {S : Finset G} {w : G}70    (hw : w ∈ differenceSupport S) : w⁻¹ ∈ differenceSupport S := by71  obtain ⟨g,hg,h,hh,rfl⟩ := mem_differenceSupport.mp hw72  apply mem_differenceSupport.mpr73  exact ⟨h,hh,g,hg, by simp⟩7475omit [DecidableEq G] in76/-- Including the identity makes the support size at least one. -/77theorem one_le_card {S : Finset G} (hS : (1 : G) ∈ S) : 1 ≤ S.card :=78  Finset.one_le_card.mpr ⟨1,hS⟩7980/-- A split word `a * b` factors as `(a⁻¹)⁻¹ * b`. -/81theorem split_mem_differenceSupport {S : Finset G} {a b : G}82    (ha : a⁻¹ ∈ S) (hb : b ∈ S) : a * b ∈ differenceSupport S :=83  mem_differenceSupport.mpr ⟨a⁻¹, ha, b, hb, by simp⟩8485end Support8687section Gram8889variable {ι κ ν : Type*} [Fintype ι] [Fintype κ] [Fintype ν]90variable {A : Type*} [NonUnitalSemiring A] [StarRing A]9192omit [Fintype ν] in93/-- Exact Gram identity for the evaluated square-root construction. -/94theorem gram_factorization (R : Matrix ι κ A) (V : Matrix κ ν A) :95    (R * V).conjTranspose * (R * V) =96      V.conjTranspose * (R.conjTranspose * R) * V := by97  rw [Matrix.conjTranspose_mul]98  simp only [Matrix.mul_assoc]99100omit [Fintype ν] in101/-- A square-root factor may be supplied as ordinary data. -/102theorem gram_factorization_of_sqrt (R : Matrix ι κ A) (G : Matrix κ κ A)103    (V : Matrix κ ν A) (hR : R.conjTranspose * R = G) :104    (R * V).conjTranspose * (R * V) = V.conjTranspose * G * V := by105  rw [gram_factorization, hR]106107/-- The finite block evaluation in the manuscript, with noncommuting entries. -/108theorem column_gram_entry (G : Matrix κ κ A) (v : κ → A) :109    let V : Matrix κ Unit A := fun g _ => v g110    (V.conjTranspose * G * V) () () =111      ∑ g, ∑ h, star (v g) * G g h * v h := by112  dsimp113  simp only [Matrix.mul_apply, Matrix.conjTranspose_apply]114  rw [Finset.sum_comm]115  apply Finset.sum_congr rfl116  intro g _117  rw [Finset.sum_mul]118119end Gram120121section PositiveMatrices122123open scoped ComplexOrder MatrixOrder Matrix.Norms.L2Operator124125variable {ι ν : Type*} [Fintype ι] [DecidableEq ι] [Fintype ν]126127/-- Finite-dimensional positivity provides the Gram square root. -/128theorem positive_sqrt_gram (G : Matrix ι ι ℂ) (hG : G.PosSemidef) :129    (CFC.sqrt G).conjTranspose * CFC.sqrt G = G := by130  rw [← Matrix.star_eq_conjTranspose,131    (IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg G)).star_eq]132  exact CFC.sqrt_mul_sqrt_self G hG.nonneg133134omit [Fintype ν] in135/-- Construct the evaluated factor using the positive matrix's actual square root. -/136theorem positive_gram_factorization (G : Matrix ι ι ℂ) (hG : G.PosSemidef)137    (V : Matrix ι ν ℂ) :138    ∃ Q : Matrix ι ν ℂ, Q.conjTranspose * Q = V.conjTranspose * G * V := by139  exact ⟨CFC.sqrt G * V,140    gram_factorization_of_sqrt _ G V (positive_sqrt_gram G hG)⟩141142/-- The positive polar block is a compression of `P` by the column `(U*, I)`. -/143theorem polar_block_posSemidef (P U : Matrix ι ι ℂ) (hP : P.PosSemidef) :144    (Matrix.fromBlocks (U * P * U.conjTranspose) (U * P)145      (P * U.conjTranspose) P).PosSemidef := by146  have h := hP.conjTranspose_mul_mul_same (Matrix.fromCols U.conjTranspose (1 : Matrix ι ι ℂ))147  simpa [Matrix.conjTranspose_fromCols_eq_fromRows_conjTranspose,148    Matrix.fromRows_mul_fromCols, Matrix.mul_assoc] using h149150/-- The appendix polar positivity step with the exact polar identities explicit. -/151theorem polar_block_posSemidef_of_identities (c p d u : Matrix ι ι ℂ)152    (hp : p.PosSemidef) (hc : c = u * p) (hd : d = u * p * u.conjTranspose) :153    (Matrix.fromBlocks d c c.conjTranspose p).PosSemidef := by154  rw [hc, hd, Matrix.conjTranspose_mul, hp.1]155  exact polar_block_posSemidef p u hp156157end PositiveMatrices158159section Dilation160161variable {ι : Type*} [Fintype ι]162variable {A : Type*} [NonUnitalSemiring A] [StarRing A]163164/-- The standard Hermitian dilation, at the matrix-algebra level. -/165def hermitianDilation (P : Matrix ι ι A) : Matrix (Sum ι ι) (Sum ι ι) A :=166  Matrix.fromBlocks 0 P P.conjTranspose 0167168omit [Fintype ι] in169theorem hermitianDilation_isHermitian (P : Matrix ι ι A) :170    (hermitianDilation P).IsHermitian := by171  unfold hermitianDilation Matrix.IsHermitian172  simp [Matrix.fromBlocks_conjTranspose]173174theorem hermitianDilation_sq (P : Matrix ι ι A) :175    hermitianDilation P * hermitianDilation P =176      Matrix.fromBlocks (P * P.conjTranspose) 0 0 (P.conjTranspose * P) := by177  unfold hermitianDilation178  simp [Matrix.fromBlocks_multiply]179180end Dilation181182section ErrorTransfer183184/-- The scalar calculation behind `e_old ≤ 6 B e_new`.185186`rN, rR` are the original two operator norms; `qN, qR` are the187factorized operator norms. All analytic input appears in `hN`, `hR`,188and `hTheta`, rather than as hidden axioms.189-/190theorem backward_error_transfer191    (rN rR qN qR theta B e : ℝ)192    (hqN : 0 ≤ qN) (_hqR : 0 ≤ qR) (hrR : 0 ≤ rR)193    (hTheta0 : 0 ≤ theta) (hB : 1 ≤ B)194    (he0 : 0 ≤ e) (he1 : e ≤ 1)195    (hN : qN ^ 2 = rN + theta) (hR : qR ^ 2 = rR + theta)196    (hTheta : theta ≤ B * rR)197    (hQ : qN ≤ (1 + e) * qR) :198    rN ≤ (1 + 6 * B * e) * rR := by199  have hsq : qN ^ 2 ≤ ((1 + e) * qR) ^ 2 := by200    exact pow_le_pow_left₀ hqN hQ 2201  have heSq : e ^ 2 ≤ e := by nlinarith202  have hError : ((1 + e) ^ 2 - 1) ≤ 3 * e := by nlinarith203  have hSum : 0 ≤ rR + theta := add_nonneg hrR hTheta0204  have hGrowth := mul_le_mul_of_nonneg_right hError hSum205  have hPre : rN ≤ rR + 3 * e * (rR + theta) := by206    nlinarith [hsq, hGrowth]207  have hScale : 0 ≤ 3 * e := by positivity208  have hBound := mul_le_mul_of_nonneg_left hTheta hScale209  have hBScale : 3 * (1 + B) ≤ 6 * B := by linarith210  have hBound' := mul_le_mul_of_nonneg_right hBScale (mul_nonneg he0 hrR)211  nlinarith [hPre, hBound, hBound']212213/-- Initial Gram reduction has additive constant one. -/214theorem initial_backward_error215    (rN rR qN qR e : ℝ)216    (hqN : 0 ≤ qN) (hrR : 0 ≤ rR)217    (he0 : 0 ≤ e) (he1 : e ≤ 1)218    (hN : qN ^ 2 = rN + 1) (hR : qR ^ 2 = rR + 1)219    (hQ : qN ≤ (1 + e) * qR) :220    rN - rR ≤ 3 * e * (1 + rR) := by221  have hsq := pow_le_pow_left₀ hqN hQ 2222  have heSq : e ^ 2 ≤ e := by nlinarith223  have hError : (1 + e) ^ 2 - 1 ≤ 3 * e := by nlinarith224  have hGrowth := mul_le_mul_of_nonneg_right hError (show 0 ≤ 1 + rR by linarith)225  nlinarith [hsq, hGrowth]226227/-- Nonnegative relative excess used for every intermediate polynomial. -/228noncomputable def relativeNormError (a b : ℝ) : ℝ := max 0 (a / b - 1)229230@[simp] theorem relativeNormError_nonneg (a b : ℝ) : 0 ≤ relativeNormError a b :=231  le_max_left _ _232233/-- Convert between a relative-error number and a multiplicative norm bound. -/234theorem relativeNormError_le_iff (a b e : ℝ) (hb : 0 < b) (he : 0 ≤ e) :235    relativeNormError a b ≤ e ↔ a ≤ (1 + e) * b := by236  unfold relativeNormError237  rw [max_le_iff]238  constructor239  · intro h240    have hdiv : a / b ≤ 1 + e := by linarith [h.2]241    have hmul := (div_le_iff₀ hb).mp hdiv242    nlinarith243  · intro h244    refine ⟨he, ?_⟩245    have hdiv : a / b ≤ 1 + e := (div_le_iff₀ hb).mpr (by nlinarith)246    linarith247248/-- The backward-error statement in exactly the `max(0, ratio - 1)` convention. -/249theorem relative_backward_error_transfer250    (rN rR qN qR theta B : ℝ)251    (hqN : 0 ≤ qN) (hqR : 0 ≤ qR) (hrR : 0 < rR)252    (hTheta0 : 0 ≤ theta) (hB : 1 ≤ B)253    (hN : qN ^ 2 = rN + theta) (hR : qR ^ 2 = rR + theta)254    (hTheta : theta ≤ B * rR)255    (hError : relativeNormError qN qR ≤ 1) :256    relativeNormError rN rR ≤ 6 * B * relativeNormError qN qR := by257  have hqRpos : 0 < qR := by nlinarith258  have he0 := relativeNormError_nonneg qN qR259  have hQ := (relativeNormError_le_iff qN qR (relativeNormError qN qR) hqRpos he0).mp le_rfl260  apply (relativeNormError_le_iff rN rR _ hrR (by positivity)).mpr261  exact backward_error_transfer rN rR qN qR theta B _ hqN hqR hrR.le262    hTheta0 hB he0 hError hN hR hTheta hQ263264/-- Compose an arbitrary finite sequence of nonnegative backward-error factors. -/265theorem backward_error_chain (n : ℕ) (F e : ℕ → ℝ)266    (hF : ∀ i < n, 0 ≤ F i) (hStep : ∀ i < n, e i ≤ F i * e (i + 1)) :267    e 0 ≤ (∏ i ∈ Finset.range n, F i) * e n := by268  induction n with269  | zero => simp270  | succ n ih =>271    have hPrefix : e 0 ≤ (∏ i ∈ Finset.range n, F i) * e n :=272      ih (fun i hi => hF i (by omega)) (fun i hi => hStep i (by omega))273    have hProd : 0 ≤ ∏ i ∈ Finset.range n, F i :=274      Finset.prod_nonneg (fun i hi => hF i (by have := Finset.mem_range.mp hi; omega))275    calc276      e 0 ≤ (∏ i ∈ Finset.range n, F i) * e n := hPrefix277      _ ≤ (∏ i ∈ Finset.range n, F i) * (F n * e (n + 1)) :=278        mul_le_mul_of_nonneg_left (hStep n (by omega)) hProd279      _ = (∏ i ∈ Finset.range (n + 1), F i) * e (n + 1) := by280        rw [Finset.prod_range_succ]281        ring282283end ErrorTransfer284285section OperatorCauchySchwarz286287variable {ι : Type*} {E F 𝕜 : Type*}288variable [NontriviallyNormedField 𝕜] [SeminormedAddCommGroup E] [SeminormedAddCommGroup F]289variable [NormedSpace 𝕜 E] [NormedSpace 𝕜 F]290291/-- The vector Cauchy–Schwarz step used to control the additive constant. -/292theorem norm_sum_sq_le_card_sum_sq (s : Finset ι) (v : ι → F) :293    ‖∑ i ∈ s, v i‖ ^ 2 ≤ (s.card : ℝ) * ∑ i ∈ s, ‖v i‖ ^ 2 := by294  calc295    ‖∑ i ∈ s, v i‖ ^ 2 ≤ (∑ i ∈ s, ‖v i‖) ^ 2 :=296      pow_le_pow_left₀ (norm_nonneg _) (norm_sum_le s v) 2297    _ ≤ (∑ i ∈ s, ‖v i‖ ^ 2) * (∑ _i ∈ s, (1 : ℝ) ^ 2) := by298      simpa using Finset.sum_mul_sq_le_sq_mul_sq s (fun i => ‖v i‖) (fun _ => (1 : ℝ))299    _ = (s.card : ℝ) * ∑ i ∈ s, ‖v i‖ ^ 2 := by simp [mul_comm]300301/-- A quadratic energy bound controls the sum's operator norm by `√|S| ρ`. -/302theorem operator_sum_norm_le_sqrt_card (s : Finset ι) (T : ι → E →L[𝕜] F)303    (rho : ℝ) (hrho : 0 ≤ rho)304    (hEnergy : ∀ x : E, ∑ i ∈ s, ‖T i x‖ ^ 2 ≤ rho ^ 2 * ‖x‖ ^ 2) :305    ‖∑ i ∈ s, T i‖ ≤ Real.sqrt (s.card : ℝ) * rho := by306  apply ContinuousLinearMap.opNorm_le_bound _ (mul_nonneg (Real.sqrt_nonneg _) hrho)307  intro x308  have h1 := norm_sum_sq_le_card_sum_sq s (fun i => T i x)309  have h2 := mul_le_mul_of_nonneg_left (hEnergy x) (show 0 ≤ (s.card : ℝ) by positivity)310  have h3 : (Real.sqrt (s.card : ℝ) * rho * ‖x‖) ^ 2 =311      (s.card : ℝ) * rho ^ 2 * ‖x‖ ^ 2 := by312    rw [mul_pow, mul_pow, Real.sq_sqrt (by positivity)]313  have hTarget : 0 ≤ Real.sqrt (s.card : ℝ) * rho * ‖x‖ := by positivity314  simp only [ContinuousLinearMap.sum_apply]315  nlinarith [norm_nonneg (∑ i ∈ s, T i x)]316317/-- The manuscript's `θ ≤ Bρ` follows once the coefficient energy bound318and `|W| ≤ B²` have been supplied. -/319theorem operator_sum_norm_le_support_size (s : Finset ι) (T : ι → E →L[𝕜] F)320    (rho B : ℝ) (hrho : 0 ≤ rho) (hB : 0 ≤ B)321    (hCard : (s.card : ℝ) ≤ B ^ 2)322    (hEnergy : ∀ x : E, ∑ i ∈ s, ‖T i x‖ ^ 2 ≤ rho ^ 2 * ‖x‖ ^ 2) :323    ‖∑ i ∈ s, T i‖ ≤ B * rho := by324  calc325    ‖∑ i ∈ s, T i‖ ≤ Real.sqrt (s.card : ℝ) * rho :=326      operator_sum_norm_le_sqrt_card s T rho hrho hEnergy327    _ ≤ B * rho := mul_le_mul_of_nonneg_right (Real.sqrt_le_iff.mpr ⟨hB,hCard⟩) hrho328329/-- Specialize the coefficient-energy estimate to the actual difference support;330the cardinal bound needed here is proved from `S`, rather than supplied. -/331theorem operator_sum_norm_le_differenceSupport332    {G : Type*} [Group G] [DecidableEq G]333    (S : Finset G) (T : G → E →L[𝕜] F) (rho : ℝ) (hrho : 0 ≤ rho)334    (hEnergy : ∀ x : E, ∑ w ∈ differenceSupport S, ‖T w x‖ ^ 2 ≤ rho ^ 2 * ‖x‖ ^ 2) :335    ‖∑ w ∈ differenceSupport S, T w‖ ≤ (S.card : ℝ) * rho := by336  apply operator_sum_norm_le_support_size _ T rho (S.card : ℝ) hrho (by positivity) ?_ hEnergy337  exact_mod_cast card_differenceSupport_le S338339end OperatorCauchySchwarz340341section HilbertCoefficientEnergy342343variable {ι E F 𝕜 : Type*} [RCLike 𝕜]344variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]345variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F]346347/-- A bound on the coefficient Gram operator gives the precise quadratic energy348estimate used in the appendix's operator Cauchy–Schwarz argument. -/349theorem coefficient_energy_le_of_gram_norm350    (s : Finset ι) (T : ι → E →L[𝕜] F) (rho : ℝ)351    (hGram : ‖∑ i ∈ s, ContinuousLinearMap.adjoint (T i) ∘L T i‖ ≤ rho ^ 2)352    (x : E) :353    ∑ i ∈ s, ‖T i x‖ ^ 2 ≤ rho ^ 2 * ‖x‖ ^ 2 := by354  let G : E →L[𝕜] E := ∑ i ∈ s, ContinuousLinearMap.adjoint (T i) ∘L T i355  have hNorm : ‖G‖ ≤ rho ^ 2 := hGram356  calc357    (∑ i ∈ s, ‖T i x‖ ^ 2) = RCLike.re (inner 𝕜 (G x) x) := by358      simp only [G, ContinuousLinearMap.sum_apply, sum_inner, map_sum]359      apply Finset.sum_congr rfl360      intro i _361      exact ContinuousLinearMap.apply_norm_sq_eq_inner_adjoint_left (T i) x362    _ ≤ ‖G x‖ * ‖x‖ := re_inner_le_norm _ _363    _ ≤ (‖G‖ * ‖x‖) * ‖x‖ :=364      mul_le_mul_of_nonneg_right (G.le_opNorm x) (norm_nonneg _)365    _ ≤ rho ^ 2 * ‖x‖ ^ 2 := by366      have h := mul_le_mul_of_nonneg_right hNorm (sq_nonneg ‖x‖)367      nlinarith368369/-- Operator Cauchy–Schwarz, with a Gram-operator hypothesis rather than a370pointwise energy hypothesis. -/371theorem operator_sum_norm_le_of_gram_norm372    (s : Finset ι) (T : ι → E →L[𝕜] F) (rho : ℝ) (hrho : 0 ≤ rho)373    (hGram : ‖∑ i ∈ s, ContinuousLinearMap.adjoint (T i) ∘L T i‖ ≤ rho ^ 2) :374    ‖∑ i ∈ s, T i‖ ≤ Real.sqrt (s.card : ℝ) * rho :=375  operator_sum_norm_le_sqrt_card s T rho hrho376    (coefficient_energy_le_of_gram_norm s T rho hGram)377378end HilbertCoefficientEnergy379380section Counts381382/-- The four oriented letters of a free group on two generators. -/383abbrev Letter := Fin 4384385/-- `0 ↔ 3` and `1 ↔ 2` form the two inverse pairs. -/386def inverseLetter (a : Letter) : Letter := a.rev387388@[simp] theorem inverseLetter_inverse (a : Letter) :389    inverseLetter (inverseLetter a) = a := by simp [inverseLetter]390391theorem inverseLetter_ne (a : Letter) : inverseLetter a ≠ a := by392  have h : ∀ b : Letter, inverseLetter b ≠ b := by decide393  exact h a394395/-- Legal letters following `a`: all letters except its inverse. -/396abbrev FollowingLetter (a : Letter) := {b : Letter // b ≠ inverseLetter a}397398@[simp] theorem card_followingLetter (a : Letter) :399    Fintype.card (FollowingLetter a) = 3 := by400  simp [FollowingLetter, Fintype.card_subtype_compl]401402/-- A genuine reduced tail; each next letter excludes the previous inverse. -/403def ReducedTail (a : Letter) : ℕ → Type404  | 0 => Unit405  | n + 1 => Σ b : FollowingLetter a, ReducedTail b.val n406407noncomputable instance reducedTailFintype (a : Letter) (n : ℕ) :408    Fintype (ReducedTail a n) := by409  induction n generalizing a with410  | zero => exact inferInstanceAs (Fintype Unit)411  | succ n ih =>412    change Fintype (Σ b : FollowingLetter a, ReducedTail b.val n)413    letI : ∀ b : FollowingLetter a, Fintype (ReducedTail b.val n) := fun b => ih b.val414    infer_instance415416/-- Exactly three choices are available for each subsequent letter. -/417@[simp] theorem card_reducedTail (a : Letter) (n : ℕ) :418    Fintype.card (ReducedTail a n) = 3 ^ n := by419  induction n generalizing a with420  | zero => simp [ReducedTail]421  | succ n ih =>422    change Fintype.card (Σ b : FollowingLetter a, ReducedTail b.val n) = _423    rw [Fintype.card_sigma]424    simp [ih, pow_succ, mul_comm]425426/-- A nonempty reduced word of length `t+1` is its first letter and reduced tail. -/427abbrev ReducedWord (t : ℕ) := Σ a : Letter, ReducedTail a t428429/-- Exact count of reduced words of length `t+1`. -/430theorem card_reducedWord (t : ℕ) : Fintype.card (ReducedWord t) = 4 * 3 ^ t := by431  simp [ReducedWord, Fintype.card_sigma, mul_comm]432433434/-- Four choices for the first letter and three for each succeeding letter. -/435theorem reduced_word_geometric_sum (r : ℕ) :436    (∑ t ∈ Finset.range r, 4 * 3 ^ t) + 2 = 2 * 3 ^ r := by437  induction r with438  | zero => simp439  | succ r ih =>440    rw [Finset.sum_range_succ, pow_succ]441    omega442443/-- The numerical bound `1 + n ∑ 4·3ᵗ ≤ 2 n 3ʳ`, for `n ≥ 1`. -/444theorem short_word_count_bound (n r : ℕ) (hn : 1 ≤ n) :445    1 + n * (∑ t ∈ Finset.range r, 4 * 3 ^ t) ≤ 2 * n * 3 ^ r := by446  have h := reduced_word_geometric_sum r447  have heq : n * ((∑ t ∈ Finset.range r, 4 * 3 ^ t) + 2) =448      n * (2 * 3 ^ r) := congrArg (n * ·) h449  nlinarith450451end Counts452453end Nonadditivity.Linearization