Holevo Additivity Gap in Lean 4

Lean explorer

Exact Lean source

Nonadditivity.StructuredCostBounds

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

Direct imports

Imported by project modules

2 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

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

54 declarations

Full module

1/-2Copyright (c) 2026 the Nonadditivity project contributors.3All rights reserved. See COPYRIGHT.md for licensing and attribution.4-/56import Nonadditivity.Quantitative7import Mathlib.Analysis.SpecialFunctions.Log.Base8import Mathlib.Algebra.Order.Floor.Div910/-! Exact products of the structured tensor and word support budgets. -/1112namespace Nonadditivity.StructuredCostBounds1314noncomputable section1516open scoped BigOperators1718set_option maxHeartbeats 8000001920def dyadicCeil (m j : ℕ) : ℕ := ⌈(m : ℝ) / 2 ^ j⌉₊21def tensorSteps (n : ℕ) : ℕ := Nat.clog 2 n22def wordLength (K : ℕ) : ℕ := 2 * Nat.log2 (K - 1) + 123def wordSteps (K : ℕ) : ℕ := Nat.clog 2 (wordLength K)24def tensorSupportBound (K n j : ℕ) : ℕ := 1 + 2 ^ (j + 1) * K ^ dyadicCeil n j25def wordSupportBound (K n i : ℕ) : ℕ := 2 * n * 3 ^ dyadicCeil (wordLength K) i2627theorem dyadicCeil_le (m j : ℕ) :28    (dyadicCeil m j : ℝ) ≤ (m : ℝ) / 2 ^ j + 1 := by29  exact (Nat.ceil_lt_add_one (by positivity : 0 ≤ (m : ℝ) / 2 ^ j)).le3031theorem geometric_sum_le (m q : ℕ) :32    ∑ j ∈ Finset.range q, (m : ℝ) / 2 ^ (j + 1) ≤ m := by33  have h : ∑ j ∈ Finset.range q, (m : ℝ) / 2 ^ (j + 1) =34      m - (m : ℝ) / 2 ^ q := by35    induction q with36    | zero => simp37    | succ q ih =>38      rw [Finset.sum_range_succ, ih, pow_succ]39      field_simp40      ring41  rw [h]42  exact sub_le_self _ (by positivity)4344theorem sum_dyadicCeil_le (m q : ℕ) :45    ∑ j ∈ Finset.range q, (dyadicCeil m (j + 1) : ℝ) ≤ (m : ℝ) + (q : ℝ) := by46  calc47    _ ≤ ∑ j ∈ Finset.range q, ((m : ℝ) / 2 ^ (j + 1) + 1) :=48      Finset.sum_le_sum fun j _ => dyadicCeil_le m (j + 1)49    _ = (∑ j ∈ Finset.range q, (m : ℝ) / 2 ^ (j + 1)) + (q : ℝ) := by simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one]50    _ ≤ (m : ℝ) + (q : ℝ) := by linarith [geometric_sum_le m q]5152theorem clog_le_log (m : ℕ) :53    (Nat.clog 2 m : ℝ) ≤ 1 + Real.log (m : ℝ) / Real.log 2 := by54  rw [← Real.natCeil_logb_natCast]55  have hnonneg : 0 ≤ Real.logb 2 (m : ℝ) := by56    by_cases hm : m = 057    · simp [hm]58    · exact Real.logb_nonneg (by norm_num) (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hm)59  simpa [Real.logb, add_comm] using (Nat.ceil_lt_add_one hnonneg).le6061theorem wordLength_le {K : ℕ} (hK : 2 ≤ K) :62    (wordLength K : ℝ) ≤ 3 * (1 + Real.log (K : ℝ)) := by63  have hKr : (2 : ℝ) ≤ K := by exact_mod_cast hK64  have hKm : (0 : ℝ) < (K : ℝ) - 1 := by linarith65  have hcast : ((K - 1 : ℕ) : ℝ) = (K : ℝ) - 1 := by rw [Nat.cast_sub (by omega : 1 ≤ K)]; norm_num66  have hm := Real.log2_le_logb (K - 1)67  rw [Real.logb, hcast] at hm68  have hl := Real.log_le_log hKm (show (K : ℝ) - 1 ≤ K by linarith)69  have h2 : 0 < Real.log 2 := by linarith [Real.log_two_gt_d9]70  have hh0 : 0 ≤ Real.log (K : ℝ) := Real.log_nonneg (by exact_mod_cast (by omega : 1 ≤ K))71  have hd : Real.log (K : ℝ) / Real.log 2 ≤ 3 / 2 * Real.log (K : ℝ) := by72    apply (div_le_iff₀ h2).273    nlinarith [mul_nonneg hh0 (show 0 ≤ Real.log 2 - 2 / 3 by linarith [Real.log_two_gt_d9])]74  have hm' := hm.trans ((div_le_div_iff_of_pos_right h2).2 hl)75  dsimp [wordLength]76  push_cast77  linarith7879theorem log_three_lt : Real.log 3 < (4 : ℝ) / 3 := by80  apply (Real.log_lt_iff_lt_exp (by norm_num)).281  have h := Real.sum_le_exp_of_nonneg (by norm_num : (0 : ℝ) ≤ 4 / 3) 382  norm_num [Finset.sum_range_succ] at h83  linarith8485theorem log_six_lt : Real.log 6 < (2 : ℝ) := by86  apply (Real.log_lt_iff_lt_exp (by norm_num)).287  have h := Real.sum_le_exp_of_nonneg (by norm_num : (0 : ℝ) ≤ 2) 488  norm_num [Finset.sum_range_succ] at h89  linarith9091theorem step_bounds {K n : ℕ} (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :92    (tensorSteps n : ℝ) ≤ 3 / 2 * (1 + Real.log K + Real.log n) ∧93    (wordSteps K : ℝ) ≤ 1 + Real.log K + Real.log n ∧94    Real.log (2 * (n : ℝ)) ≤ 1 + Real.log K + Real.log n := by95  obtain ⟨hh, hn64, hu, _⟩ := Quantitative.threshold_consequences hK hn96  have hn0 : (0 : ℝ) < n := by linarith97  have hv : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by linarith)98  have h2 : 0 < Real.log 2 := by linarith [Real.log_two_gt_d9]99  have h2lower : (2 : ℝ) / 3 ≤ Real.log 2 := by linarith [Real.log_two_gt_d9]100  have h2upper : Real.log 2 ≤ (7 : ℝ) / 10 := by linarith [Real.log_two_lt_d9]101  have hlogK : (2 : ℝ) / 3 ≤ Real.log (K : ℝ) := by102    have hk := Real.log_le_log (by norm_num : (0 : ℝ) < 2) (show (2 : ℝ) ≤ (K : ℝ) by exact_mod_cast hK)103    linarith104  have hq := clog_le_log n105  have hd : Real.log (n : ℝ) / Real.log 2 ≤ 3 / 2 * Real.log n := by106    apply (div_le_iff₀ h2).2107    nlinarith [mul_nonneg hv (sub_nonneg.mpr h2lower)]108  refine ⟨by dsimp [tensorSteps]; linarith, ?_, ?_⟩109  · have hy : 0 < 1 + Real.log (K : ℝ) := by linarith110    have hlpos : (0 : ℝ) < wordLength K := by dsimp [wordLength]; positivity111    have hle := Real.log_le_log hlpos (wordLength_le hK)112    rw [Real.log_mul (by norm_num) hy.ne'] at hle113    have hylog := Real.log_le_sub_one_of_pos (div_pos hy (by norm_num : (0 : ℝ) < 2))114    rw [Real.log_div hy.ne' (by norm_num)] at hylog115    have hlogl : 0 ≤ Real.log (wordLength K : ℝ) :=116      Real.log_nonneg (by dsimp [wordLength]; push_cast; linarith [(Nat.cast_nonneg (Nat.log2 (K - 1)) : (0 : ℝ) ≤ (Nat.log2 (K - 1) : ℝ))])117    have hld : Real.log (wordLength K : ℝ) / Real.log 2 ≤118        3 / 2 * Real.log (wordLength K : ℝ) := by119      apply (div_le_iff₀ h2).2120      nlinarith [mul_nonneg hlogl (sub_nonneg.mpr h2lower)]121    have hs := clog_le_log (wordLength K)122    have hv6 : 6 ≤ Real.log (n : ℝ) := by123      have hbase : 256 * (1 + Real.log (K : ℝ)) ^ 2 ≤ (n : ℝ) :=124        (Nat.le_ceil _).trans (by exact_mod_cast hn)125      have hn512 : (512 : ℝ) ≤ n := by nlinarith [sq_nonneg (1 + Real.log (K : ℝ) - 5 / 3)]126      have hl := Real.log_le_log (by norm_num : (0 : ℝ) < 512) hn512127      have he : Real.log (512 : ℝ) = 9 * Real.log 2 := by128        rw [show (512 : ℝ) = 2 ^ (9 : ℕ) by norm_num, Real.log_pow]; norm_num129      rw [he] at hl130      linarith131    dsimp [wordSteps]132    linarith [log_three_lt]133  · rw [Real.log_mul (by norm_num) hn0.ne']134    linarith135136theorem dyadicCeil_eq_div (m j : ℕ) :137    dyadicCeil m j = (m + 2 ^ j - 1) / 2 ^ j := by138  change dyadicCeil m j = m ⌈/⌉ (2 ^ j)139  apply eq_of_forall_ge_iff140  intro a141  rw [ceilDiv_le_iff_le_mul (by positivity : 0 < (2 : ℕ) ^ j)]142  dsimp [dyadicCeil]143  rw [Nat.ceil_le, div_le_iff₀ (by positivity : (0 : ℝ) < 2 ^ j)]144  norm_cast145  rw [Nat.mul_comm]146147theorem tensorSupportBound_pos (K n j : ℕ) : 0 < tensorSupportBound K n j := by148  dsimp [tensorSupportBound]; positivity149150theorem wordSupportBound_pos {n : ℕ} (hn : 0 < n) (K i : ℕ) :151    0 < wordSupportBound K n i := by152  dsimp [wordSupportBound]; positivity153154theorem log_tensorSupportBound_le {K : ℕ} (hK : 1 ≤ K) (n j : ℕ) :155    Real.log (tensorSupportBound K n j : ℝ) ≤156      (j + 2 : ℕ) * Real.log 2 + (dyadicCeil n j : ℝ) * Real.log K := by157  have hK0 : (0 : ℝ) < K := by exact_mod_cast (by omega : 0 < K)158  have hpow : (1 : ℝ) ≤ (K : ℝ) ^ dyadicCeil n j :=159    one_le_pow₀ (by exact_mod_cast hK)160  have htwo : (1 : ℝ) ≤ (2 : ℝ) ^ (j + 1) := one_le_pow₀ (by norm_num)161  have hprod : (1 : ℝ) ≤ 2 ^ (j + 1) * (K : ℝ) ^ dyadicCeil n j :=162    one_le_mul_of_one_le_of_one_le htwo hpow163  have hb : (tensorSupportBound K n j : ℝ) ≤164      2 ^ (j + 2) * (K : ℝ) ^ dyadicCeil n j := by165    dsimp [tensorSupportBound]166    push_cast167    simp only [show j + 2 = (j + 1) + 1 by omega, pow_succ] at hprod ⊢168    nlinarith169  have hl := Real.log_le_log (by exact_mod_cast tensorSupportBound_pos K n j) hb170  rw [Real.log_mul (by positivity) (by positivity), Real.log_pow, Real.log_pow] at hl171  exact hl172173theorem sum_linear_indices (q : ℕ) :174    ∑ j ∈ Finset.range q, ((j : ℝ) + 3) = (q : ℝ) * (q + 5) / 2 := by175  induction q with176  | zero => simp177  | succ q ih =>178    rw [Finset.sum_range_succ, ih]179    push_cast180    ring181182theorem tensor_sum_log_coarse {K : ℕ} (hK : 2 ≤ K) (n q : ℕ) :183    (∑ j ∈ Finset.range q, Real.log (tensorSupportBound K n (j + 1) : ℝ)) ≤184      (n : ℝ) * Real.log K + q * Real.log K +185        (q : ℝ) * (q + 5) / 2 * Real.log 2 := by186  have hh : 0 ≤ Real.log (K : ℝ) := Real.log_nonneg (by exact_mod_cast (by omega : 1 ≤ K))187  calc188    _ ≤ ∑ j ∈ Finset.range q,189        (((j : ℝ) + 3) * Real.log 2 + (dyadicCeil n (j + 1) : ℝ) * Real.log K) := by190      apply Finset.sum_le_sum191      intro j _192      simpa only [Nat.cast_add, Nat.cast_one, Nat.cast_ofNat, add_assoc, show (1 : ℝ) + 2 = 3 by norm_num] using193        log_tensorSupportBound_le (by omega : 1 ≤ K) n (j + 1)194    _ = ((q : ℝ) * (q + 5) / 2) * Real.log 2 +195        (∑ j ∈ Finset.range q, (dyadicCeil n (j + 1) : ℝ)) * Real.log K := by196      rw [Finset.sum_add_distrib, ← Finset.sum_mul, ← Finset.sum_mul, sum_linear_indices]197    _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_right (sum_dyadicCeil_le n q) hh]198199theorem tensor_sum_log_bound {K n : ℕ} (hK : 2 ≤ K) :200    (∑ j ∈ Finset.range (tensorSteps n),201      Real.log (tensorSupportBound K n (j + 1) : ℝ)) ≤202    (n : ℝ) * Real.log K + 3 / 4 * (1 + Real.log K + Real.log n) ^ 2 +203      2 * (1 + Real.log K + Real.log n) := by204  have hh : 0 ≤ Real.log (K : ℝ) := Real.log_nonneg (by exact_mod_cast (by omega : 1 ≤ K))205  have hv : 0 ≤ Real.log (n : ℝ) := by206    by_cases hn : n = 0207    · simp [hn]208    · exact Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hn)209  have h2 : 0 < Real.log 2 := by linarith [Real.log_two_gt_d9]210  have h2lo : (2 : ℝ) / 3 ≤ Real.log 2 := by linarith [Real.log_two_gt_d9]211  have h2hi : Real.log 2 ≤ (7 : ℝ) / 10 := by linarith [Real.log_two_lt_d9]212  have hq := clog_le_log n213  change (tensorSteps n : ℝ) ≤ 1 + Real.log (n : ℝ) / Real.log 2 at hq214  have hqd : (tensorSteps n : ℝ) * Real.log 2 ≤ Real.log 2 + Real.log n := by215    have h := (le_div_iff₀ h2).1 (show (tensorSteps n : ℝ) - 1 ≤ Real.log n / Real.log 2 by linarith)216    nlinarith217  have hq0 : (0 : ℝ) ≤ tensorSteps n := by positivity218  have hqlo : (tensorSteps n : ℝ) ≤ 1 + 3 / 2 * Real.log n := by219    nlinarith [mul_nonneg hq0 (sub_nonneg.mpr h2lo)]220  have hqh := mul_le_mul_of_nonneg_right hqlo hh221  have hqv := mul_le_mul_of_nonneg_right hqlo hv222  have hqq := mul_le_mul_of_nonneg_left hqd hq0223  have hq2 : (tensorSteps n : ℝ) ^ 2 * Real.log 2 ≤224      3 / 2 * Real.log (n : ℝ) ^ 2 + 2 * Real.log n + Real.log 2 := by225    nlinarith226  have hcoarse := tensor_sum_log_coarse hK n (tensorSteps n)227  have hhsq := sq_nonneg (Real.log (K : ℝ) - 1)228  nlinarith229230theorem word_sum_log_bound {K n : ℕ} (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :231    (∑ i ∈ Finset.range (wordSteps K),232      Real.log (wordSupportBound K n (i + 1) : ℝ)) ≤233    (1 + Real.log K + Real.log n) ^ 2 + 6 * (1 + Real.log K + Real.log n) := by234  obtain ⟨hh, hn64, hu, _⟩ := Quantitative.threshold_consequences hK hn235  obtain ⟨_, hs, hlog2n⟩ := step_bounds hK hn236  have hn0 : (0 : ℝ) < n := by linarith237  have hlog3 : 0 ≤ Real.log 3 := Real.log_nonneg (by norm_num)238  have hlog2n0 : 0 ≤ Real.log (2 * (n : ℝ)) := Real.log_nonneg (by linarith)239  have hs0 : (0 : ℝ) ≤ wordSteps K := by positivity240  have hu0 : 0 ≤ 1 + Real.log (K : ℝ) + Real.log n := by linarith241  have heq : (∑ i ∈ Finset.range (wordSteps K),242      Real.log (wordSupportBound K n (i + 1) : ℝ)) =243      (wordSteps K : ℝ) * Real.log (2 * (n : ℝ)) +244      (∑ i ∈ Finset.range (wordSteps K), (dyadicCeil (wordLength K) (i + 1) : ℝ)) * Real.log 3 := by245    simp only [wordSupportBound, Nat.cast_mul, Nat.cast_ofNat, Nat.cast_pow,246      Real.log_mul (by positivity : (2 : ℝ) * n ≠ 0) (by positivity : (3 : ℝ) ^ _ ≠ 0),247      Real.log_pow, Finset.sum_add_distrib, Finset.sum_const, Finset.card_range,248      nsmul_eq_mul, Finset.sum_mul]249  rw [heq]250  have hsum := mul_le_mul_of_nonneg_right (sum_dyadicCeil_le (wordLength K) (wordSteps K)) hlog3251  have hsmul := mul_le_mul hs hlog2n hlog2n0 hu0252  have hl := wordLength_le hK253  have hv : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by linarith)254  have hsumfactor : (wordLength K : ℝ) + wordSteps K ≤255      4 * (1 + Real.log K + Real.log n) := by linarith256  have hsumfactor0 : (0 : ℝ) ≤ (wordLength K : ℝ) + wordSteps K := by positivity257  have hb := mul_le_mul hsumfactor (show Real.log 3 ≤ (3 : ℝ) / 2 by linarith [log_three_lt])258    hlog3 (by linarith : 0 ≤ 4 * (1 + Real.log (K : ℝ) + Real.log n))259  nlinarith260261/-- Product of all tensor and word support budgets, including each stage's262multiplicative overhead.  Use `a=6` for errors and `a=2` for dimensions. -/263def supportProduct (K n : ℕ) (a : ℝ) : ℝ :=264  (∏ j ∈ Finset.range (tensorSteps n), a * (tensorSupportBound K n (j + 1) : ℝ)) *265  (∏ i ∈ Finset.range (wordSteps K), a * (wordSupportBound K n (i + 1) : ℝ))266267theorem supportProduct_pos {K n : ℕ} {a : ℝ} (hn : 0 < n) (ha : 0 < a) :268    0 < supportProduct K n a := by269  apply mul_pos270  · exact Finset.prod_pos fun j _ => mul_pos ha (by exact_mod_cast tensorSupportBound_pos K n (j + 1))271  · exact Finset.prod_pos fun i _ => mul_pos ha (by exact_mod_cast wordSupportBound_pos hn K (i + 1))272273theorem log_supportProduct {K n : ℕ} {a : ℝ} (hn : 0 < n) (ha : 0 < a) :274    Real.log (supportProduct K n a) =275      ((tensorSteps n : ℝ) + wordSteps K) * Real.log a +276      (∑ j ∈ Finset.range (tensorSteps n), Real.log (tensorSupportBound K n (j + 1) : ℝ)) +277      (∑ i ∈ Finset.range (wordSteps K), Real.log (wordSupportBound K n (i + 1) : ℝ)) := by278  have ht : ∀ j, (tensorSupportBound K n (j + 1) : ℝ) ≠ 0 := fun j => by279    exact_mod_cast (tensorSupportBound_pos K n (j + 1)).ne'280  have hw : ∀ i, (wordSupportBound K n (i + 1) : ℝ) ≠ 0 := fun i => by281    exact_mod_cast (wordSupportBound_pos hn K (i + 1)).ne'282  dsimp [supportProduct]283  rw [Real.log_mul (Finset.prod_ne_zero_iff.mpr fun j _ => mul_ne_zero ha.ne' (ht j))284    (Finset.prod_ne_zero_iff.mpr fun i _ => mul_ne_zero ha.ne' (hw i))]285  rw [Real.log_prod (fun j _ => mul_ne_zero ha.ne' (ht j)),286    Real.log_prod (fun i _ => mul_ne_zero ha.ne' (hw i))]287  simp_rw [Real.log_mul ha.ne' (ht _), Real.log_mul ha.ne' (hw _)]288  simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul]289  ring290291theorem supportProduct_dimension_log_bound {K n : ℕ}292    (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :293    Real.log (supportProduct K n 2) < (n : ℝ) * Real.log K + n / 3 := by294  obtain ⟨_, hn64, hu, hthreshold⟩ := Quantitative.threshold_consequences hK hn295  have hn0 : 0 < n := by exact_mod_cast (show (0 : ℝ) < n by linarith)296  obtain ⟨hq, hs, _⟩ := step_bounds hK hn297  have hsteps : (0 : ℝ) ≤ (tensorSteps n : ℝ) + wordSteps K := by positivity298  have hov : ((tensorSteps n : ℝ) + wordSteps K) * Real.log 2 ≤299      5 / 2 * (1 + Real.log K + Real.log n) := by300    have hm := mul_le_mul_of_nonneg_left (show Real.log 2 ≤ 1 by linarith [Real.log_two_lt_d9]) hsteps301    nlinarith302  rw [log_supportProduct hn0 (by norm_num)]303  exact Quantitative.reduction_coefficient_log_bound hu hthreshold hov304    (tensor_sum_log_bound hK) (word_sum_log_bound hK hn)305306/-- Upper bound for the initial shifted-dilation error factor from the307prescribed witness's lower norm. -/308def initialFactor (K n : ℕ) : ℝ :=309  3 * (1 + Real.exp (((n : ℝ) + 1) * Real.log K / 2) / Real.sqrt 2)310311theorem initialFactor_pos (K n : ℕ) : 0 < initialFactor K n := by312  dsimp [initialFactor]; positivity313314theorem initialFactor_log_bound {K n : ℕ}315    (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :316    Real.log (initialFactor K n) ≤317      (n : ℝ) * Real.log K / 2 + (1 + Real.log K + Real.log n) := by318  obtain ⟨hh, hn64, _, _⟩ := Quantitative.threshold_consequences hK hn319  have hn0 : (0 : ℝ) < n := by linarith320  have hx0 : 0 ≤ ((n : ℝ) + 1) * Real.log K / 2 := by positivity321  have he : 1 ≤ Real.exp (((n : ℝ) + 1) * Real.log K / 2) := Real.one_le_exp_iff.mpr hx0322  have hs : (1 : ℝ) ≤ Real.sqrt 2 := (Real.le_sqrt (by norm_num) (by norm_num)).2 (by norm_num)323  have hd : Real.exp (((n : ℝ) + 1) * Real.log K / 2) / Real.sqrt 2 ≤324      Real.exp (((n : ℝ) + 1) * Real.log K / 2) := div_le_self (by positivity) hs325  have hi : initialFactor K n ≤ 6 * Real.exp (((n : ℝ) + 1) * Real.log K / 2) := by326    dsimp [initialFactor]; linarith327  have hl := Real.log_le_log (initialFactor_pos K n) hi328  rw [Real.log_mul (by norm_num) (by positivity), Real.log_exp] at hl329  have hv : 1 ≤ Real.log (n : ℝ) := by330    apply (Real.le_log_iff_exp_le hn0).2331    linarith [Real.exp_one_lt_three]332  linarith [log_six_lt]333334/-- The full relative-error amplification budget, as an actual product. -/335def errorProduct (K n : ℕ) : ℝ := initialFactor K n * supportProduct K n 6336337theorem errorProduct_bound {K n : ℕ} (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :338    errorProduct K n ≤ Real.exp (Quantitative.gamma (Real.log K) * n) := by339  obtain ⟨_, hn64, hu, hthreshold⟩ := Quantitative.threshold_consequences hK hn340  have hn0 : 0 < n := by exact_mod_cast (show (0 : ℝ) < n by linarith)341  obtain ⟨hq, hs, _⟩ := step_bounds hK hn342  have hsteps : (0 : ℝ) ≤ (tensorSteps n : ℝ) + wordSteps K := by positivity343  have hov : ((tensorSteps n : ℝ) + wordSteps K) * Real.log 6 ≤344      5 * (1 + Real.log K + Real.log n) := by345    have hm := mul_le_mul_of_nonneg_left log_six_lt.le hsteps346    nlinarith347  have hb := Quantitative.reduction_error_log_bound hu hthreshold348    (initialFactor_log_bound hK hn) hov (tensor_sum_log_bound hK) (word_sum_log_bound hK hn)349  have hepos : 0 < errorProduct K n := mul_pos (initialFactor_pos K n)350    (supportProduct_pos hn0 (by norm_num))351  apply (Real.log_le_iff_le_exp hepos).mp352  dsimp [errorProduct]353  rw [Real.log_mul (initialFactor_pos K n).ne' (supportProduct_pos hn0 (by norm_num)).ne',354    log_supportProduct hn0 (by norm_num)]355  linarith356357/-- Largest permitted test net size in the traceless Hermitian sphere. -/358def netCardBound (K n : ℕ) : ℕ := (1 + 2 * n) ^ (K ^ (2 * n) - 1)359360/-- The actual coefficient budget including the initial `2 J K^n` and all361subsequent structured support factors. -/362def coefficientBound (K n : ℕ) : ℝ :=363  2 * netCardBound K n * (K : ℝ) ^ n * supportProduct K n 2364365theorem netCardBound_pos (K n : ℕ) : 0 < netCardBound K n := by366  dsimp [netCardBound]; positivity367368theorem coefficientBound_log {K n : ℕ} (hK : 2 ≤ K) (hn : 0 < n) :369    Real.log (2 * coefficientBound K n) =370      Real.log 4 + (K ^ (2 * n) - 1 : ℝ) * Real.log (1 + 2 * (n : ℝ)) +371      (n : ℝ) * Real.log K + Real.log (supportProduct K n 2) := by372  have hKpos : 0 < K := by omega373  have hKreal : (0 : ℝ) < K := by exact_mod_cast hKpos374  have hj : (0 : ℝ) < netCardBound K n := by exact_mod_cast netCardBound_pos K n375  have he : 2 * coefficientBound K n =376      4 * (netCardBound K n : ℝ) * (K : ℝ) ^ n * supportProduct K n 2 := by377    dsimp [coefficientBound]; ring378  rw [he, Real.log_mul (by positivity) (supportProduct_pos hn (by norm_num)).ne',379    Real.log_mul (by positivity) (by positivity), Real.log_mul (by norm_num) hj.ne', Real.log_pow]380  have hjlog : Real.log (netCardBound K n : ℝ) =381      ((K : ℝ) ^ (2 * n) - 1) * Real.log (1 + 2 * (n : ℝ)) := by382    dsimp [netCardBound]383    rw [Nat.cast_pow, Real.log_pow]384    congr 1385    · rw [Nat.cast_sub (by exact Nat.one_le_iff_ne_zero.mpr (pow_ne_zero _ (by omega))), Nat.cast_pow, Nat.cast_one]386    · push_cast; rfl387  rw [hjlog]388389theorem coefficientBound_log_bound {K n : ℕ}390    (hK : 2 ≤ K) (hn : Quantitative.n₀ K ≤ n) :391    Real.log (2 * coefficientBound K n) ≤392      2 * (K : ℝ) ^ (2 * n) * Real.log (1 + 2 * (n : ℝ)) := by393  obtain ⟨_, hn64, _, _⟩ := Quantitative.threshold_consequences hK hn394  have hn0 : 0 < n := by exact_mod_cast (show (0 : ℝ) < n by linarith)395  have hKr : (2 : ℝ) ≤ K := by exact_mod_cast hK396  have hKr0 : (0 : ℝ) < K := by linarith397  have hh : (2 : ℝ) / 3 ≤ Real.log (K : ℝ) := by398    have h := Real.log_le_log (by norm_num : (0 : ℝ) < 2) hKr399    linarith [Real.log_two_gt_d9]400  have hexp : Real.exp (2 * (n : ℝ) * Real.log K) = (K : ℝ) ^ (2 * n) := by401    rw [show 2 * (n : ℝ) * Real.log K = (2 * n : ℕ) * Real.log K by push_cast; ring,402      Real.exp_nat_mul, Real.exp_log hKr0]403  rw [coefficientBound_log hK hn0]404  have h := Quantitative.final_coefficient_size hh (show (2 : ℝ) ≤ n by linarith)405    (J := ((K : ℝ) ^ (2 * n) - 1) * Real.log (1 + 2 * (n : ℝ)))406    (by rw [hexp]) (supportProduct_dimension_log_bound hK hn).le (le_refl _)407  simpa only [hexp] using h408409end410end Nonadditivity.StructuredCostBounds