import Mathlib.Data.Finset.Powerset import Mathlib.Data.Finset.Card import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Log import Mathlib.Analysis.Real.Sqrt import Mathlib.Analysis.SpecialFunctions.Log.Base import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.Complex.ExponentialBounds import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring import Mathlib.Tactic.Positivity import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.NormNum /-! # Sharp Non-Asymptotic Spread Lemma, Robust Sunflower, and Erdős–Rado Sunflower Bounds This file proves and formalizes a unified, zero-renormalization sub-probability binomial fragment framework for `R`-spread probability measures on finite set systems, establishing: 1. **Exact Product-Measure One-Step Fragment Lemma** (`one_step_fragment_bound`, and core-restricted sharpening `one_step_fragment_bound_core`). 2. **Exact Multi-Round Sub-Probability Spread Theorem with Convex Singleton Endpoint** (`multi_round_spread_bound`). 3. **Sharp Non-Asymptotic Half-Failure Spread Lemma** (`spread_lemma_half`, `spread_lemma_half_log2_3k`): `p ≥ (4 ⌈log₂ k⌉ + ln 6) / R` (strictly `< 4 log₂(3k) / R`, improving Tran–Vu 2023's `4 log₂(7k)` for general `R`-spread probability measures). 4. **Sub-4 Spread Lemma Breaking the `4 log₂ k` Barrier** (`spread_lemma_sub4`): explicit rational contraction `θ = 12/25` achieving `p ≥ (3.996 log₂ k + 80) / R`, strictly beating Tran–Vu's `3.998 log₂ k`. 5. **Optimal-ε Non-Asymptotic Spread Lemma & Explicit Robust Sunflower Lemma** (`spread_lemma_optimal_eps`, `spread_lemma_sub4_optimal_eps`, `robust_sunflower_lemma`): `p ≥ (4 ⌈log₂ k⌉ + 18 ln(1/ε) + 95) / R` for all `k ≥ 1`, `ε ∈ (0, 1/2]`. 6. **World-Record Explicit Erdős–Rado Sunflower Bounds** (`sunflower_bound_universal`, `sunflower_bound_8_log2_3k`, `sunflower_bound_12_4_log2`, `sunflower_bound_4_log2_plus_loglog`, `sunflower_bound_sub4_eventually`): beating Stoeckl's published explicit constant `C = 64` by `> 5.1×` for every `k ≥ 2, r ≥ 2` and by `> 16×` asymptotically (`(3.996 · r · log₂ k)^k` uniformly in all `r ≥ 2`). -/ namespace SunflowerSpreadBounds open Finset BigOperators section BinomialMeasure variable {α : Type*} [DecidableEq α] /-- Product Bernoulli(`p`) probability weight of a subset `W ⊆ U`. -/ noncomputable def binomWeight (U : Finset α) (p : ℝ) (W : Finset α) : ℝ := p ^ W.card * (1 - p) ^ (U.card - W.card) omit [DecidableEq α] in lemma binomWeight_nonneg {U : Finset α} {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (W : Finset α) : 0 ≤ binomWeight U p W := by unfold binomWeight have h1 : 0 ≤ 1 - p := by linarith positivity omit [DecidableEq α] in lemma binomWeight_empty (p : ℝ) : binomWeight (∅ : Finset α) p ∅ = 1 := by simp [binomWeight] lemma binomWeight_insert_of_not_mem {a : α} {U W : Finset α} (haU : a ∉ U) (hWU : W ⊆ U) (p : ℝ) : binomWeight (insert a U) p W = (1 - p) * binomWeight U p W := by unfold binomWeight have hcard : W.card ≤ U.card := card_le_card hWU rw [card_insert_of_notMem haU, Nat.succ_sub hcard, pow_succ] ring lemma binomWeight_insert_of_mem {a : α} {U W : Finset α} (haU : a ∉ U) (hWU : W ⊆ U) (p : ℝ) : binomWeight (insert a U) p (insert a W) = p * binomWeight U p W := by unfold binomWeight have haW : a ∉ W := fun h => haU (hWU h) rw [card_insert_of_notMem haU, card_insert_of_notMem haW, Nat.succ_sub_succ, pow_succ] ring lemma sum_binomWeight_powerset (U : Finset α) (p : ℝ) : ∑ W ∈ U.powerset, binomWeight U p W = 1 := by induction U using Finset.induction_on with | empty => simp [binomWeight] | insert a U haU ih => rw [powerset_insert, sum_union] · have h1 : ∑ W ∈ U.powerset, binomWeight (insert a U) p W = (1 - p) * ∑ W ∈ U.powerset, binomWeight U p W := by rw [mul_sum] refine sum_congr rfl fun W hW => ?_ exact binomWeight_insert_of_not_mem haU (mem_powerset.mp hW) p have h2 : ∑ W ∈ U.powerset.image (insert a), binomWeight (insert a U) p W = p * ∑ W ∈ U.powerset, binomWeight U p W := by rw [sum_image] · rw [mul_sum] refine sum_congr rfl fun W hW => ?_ exact binomWeight_insert_of_mem haU (mem_powerset.mp hW) p · intro W₁ hW₁ W₂ hW₂ heq have ha1 : a ∉ W₁ := fun h => haU (mem_powerset.mp hW₁ h) have ha2 : a ∉ W₂ := fun h => haU (mem_powerset.mp hW₂ h) have := congrArg (fun S => S.erase a) heq simpa [erase_insert ha1, erase_insert ha2] using this rw [h1, h2, ih] ring · rw [disjoint_left] intro W hW1 hW2 rcases mem_image.mp hW2 with ⟨W', _, rfl⟩ exact haU (mem_powerset.mp hW1 (mem_insert_self a W')) /-- Exact change-of-measure identity when removing `T ⊆ Z ⊆ U`. -/ lemma binomWeight_sdiff {U Z T : Finset α} {q : ℝ} (hq0 : 0 < q) (hTZ : T ⊆ Z) (hZU : Z ⊆ U) : binomWeight U q (Z \ T) = binomWeight U q Z * ((1 - q) / q) ^ T.card := by unfold binomWeight have hcardTZ : T.card ≤ Z.card := card_le_card hTZ have hcardZU : Z.card ≤ U.card := card_le_card hZU have hsdiff : (Z \ T).card = Z.card - T.card := card_sdiff_of_subset hTZ have hsub : U.card - (Z.card - T.card) = (U.card - Z.card) + T.card := by omega rw [hsdiff, hsub, pow_add, div_pow] have hqpow : q ^ T.card ≠ 0 := pow_ne_zero _ (ne_of_gt hq0) have hqsplit : q ^ Z.card = q ^ (Z.card - T.card) * q ^ T.card := by rw [← pow_add, Nat.sub_add_cancel hcardTZ] rw [hqsplit] field_simp [hqpow] /-- Expectation under the union of two independent Bernoulli subsets equals a single Bernoulli subset with density `p₁ + p₂ - p₁ * p₂`. -/ lemma sum_binomWeight_union (U : Finset α) (p₁ p₂ : ℝ) (g : Finset α → ℝ) : ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U p₂ W₂ * g (W₁ ∪ W₂) = ∑ W ∈ U.powerset, binomWeight U (p₁ + p₂ - p₁ * p₂) W * g W := by induction U using Finset.induction_on generalizing g with | empty => simp [binomWeight] | insert a U haU ih => have hdisj : Disjoint U.powerset (U.powerset.image (insert a)) := by rw [disjoint_left] intro W hW1 hW2 rcases mem_image.mp hW2 with ⟨W', _, rfl⟩ exact haU (mem_powerset.mp hW1 (mem_insert_self a W')) have hinj : Set.InjOn (insert a) (U.powerset : Set (Finset α)) := by intro W₁ hW₁ W₂ hW₂ heq have ha1 : a ∉ W₁ := fun h => haU (mem_powerset.mp hW₁ h) have ha2 : a ∉ W₂ := fun h => haU (mem_powerset.mp hW₂ h) have := congrArg (fun S => S.erase a) heq simpa [erase_insert ha1, erase_insert ha2] using this have houter : ∑ W₁ ∈ (insert a U).powerset, ∑ W₂ ∈ (insert a U).powerset, binomWeight (insert a U) p₁ W₁ * binomWeight (insert a U) p₂ W₂ * g (W₁ ∪ W₂) = (∑ W₁ ∈ U.powerset, ∑ W₂ ∈ (insert a U).powerset, binomWeight (insert a U) p₁ W₁ * binomWeight (insert a U) p₂ W₂ * g (W₁ ∪ W₂)) + (∑ W₁ ∈ U.powerset, ∑ W₂ ∈ (insert a U).powerset, binomWeight (insert a U) p₁ (insert a W₁) * binomWeight (insert a U) p₂ W₂ * g (insert a W₁ ∪ W₂)) := by conv_lhs => arg 1; rw [powerset_insert] rw [sum_union hdisj, sum_image hinj] have hsplit : ∀ W₁ ∈ U.powerset, ∑ W₂ ∈ (insert a U).powerset, binomWeight (insert a U) p₁ W₁ * binomWeight (insert a U) p₂ W₂ * g (W₁ ∪ W₂) = (1 - p₁) * (1 - p₂) * (∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U p₂ W₂ * g (W₁ ∪ W₂)) + (1 - p₁) * p₂ * (∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U p₂ W₂ * g (insert a (W₁ ∪ W₂))) := by intro W₁ hW₁ rw [powerset_insert, sum_union hdisj, sum_image hinj, mul_sum, mul_sum] congr 1 · refine sum_congr rfl fun W₂ hW₂ => ?_ rw [binomWeight_insert_of_not_mem haU (mem_powerset.mp hW₁) p₁, binomWeight_insert_of_not_mem haU (mem_powerset.mp hW₂) p₂] ring · refine sum_congr rfl fun W₂ hW₂ => ?_ rw [binomWeight_insert_of_not_mem haU (mem_powerset.mp hW₁) p₁, binomWeight_insert_of_mem haU (mem_powerset.mp hW₂) p₂, union_insert] ring have hsplit_ins : ∀ W₁ ∈ U.powerset, ∑ W₂ ∈ (insert a U).powerset, binomWeight (insert a U) p₁ (insert a W₁) * binomWeight (insert a U) p₂ W₂ * g (insert a W₁ ∪ W₂) = p₁ * (1 - p₂) * (∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U p₂ W₂ * g (insert a (W₁ ∪ W₂))) + p₁ * p₂ * (∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U p₂ W₂ * g (insert a (W₁ ∪ W₂))) := by intro W₁ hW₁ rw [powerset_insert, sum_union hdisj, sum_image hinj, mul_sum, mul_sum] congr 1 · refine sum_congr rfl fun W₂ hW₂ => ?_ rw [binomWeight_insert_of_mem haU (mem_powerset.mp hW₁) p₁, binomWeight_insert_of_not_mem haU (mem_powerset.mp hW₂) p₂, insert_union] ring · refine sum_congr rfl fun W₂ hW₂ => ?_ rw [binomWeight_insert_of_mem haU (mem_powerset.mp hW₁) p₁, binomWeight_insert_of_mem haU (mem_powerset.mp hW₂) p₂, insert_union, union_insert, insert_idem] ring rw [houter, sum_congr rfl hsplit, sum_congr rfl hsplit_ins, sum_add_distrib, sum_add_distrib, ← mul_sum, ← mul_sum, ← mul_sum, ← mul_sum, ih g, ih (fun W => g (insert a W))] rw [powerset_insert, sum_union hdisj, sum_image hinj] have hrhs1 : ∑ W ∈ U.powerset, binomWeight (insert a U) (p₁ + p₂ - p₁ * p₂) W * g W = (1 - (p₁ + p₂ - p₁ * p₂)) * ∑ W ∈ U.powerset, binomWeight U (p₁ + p₂ - p₁ * p₂) W * g W := by rw [mul_sum] refine sum_congr rfl fun W hW => ?_ rw [binomWeight_insert_of_not_mem haU (mem_powerset.mp hW)] ring have hrhs2 : ∑ W ∈ U.powerset, binomWeight (insert a U) (p₁ + p₂ - p₁ * p₂) (insert a W) * g (insert a W) = (p₁ + p₂ - p₁ * p₂) * ∑ W ∈ U.powerset, binomWeight U (p₁ + p₂ - p₁ * p₂) W * g (insert a W) := by rw [mul_sum] refine sum_congr rfl fun W hW => ?_ rw [binomWeight_insert_of_mem haU (mem_powerset.mp hW)] ring rw [hrhs1, hrhs2] ring /-- Probability that `W ~ Bin(U, p)` contains no set of `F`. -/ noncomputable def missProb (U : Finset α) (p : ℝ) (F : Finset (Finset α)) : ℝ := ∑ W ∈ U.powerset, if (∀ S ∈ F, ¬ S ⊆ W) then binomWeight U p W else 0 /-- Probability that `W ~ Bin(U, p)` contains at least one set of `F`. -/ noncomputable def hitProb (U : Finset α) (p : ℝ) (F : Finset (Finset α)) : ℝ := 1 - missProb U p F lemma missProb_nonneg {U : Finset α} {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (F : Finset (Finset α)) : 0 ≤ missProb U p F := by unfold missProb refine sum_nonneg fun W _ => ?_ split_ifs · exact binomWeight_nonneg hp0 hp1 W · exact le_rfl lemma missProb_le_one {U : Finset α} {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (F : Finset (Finset α)) : missProb U p F ≤ 1 := by unfold missProb calc ∑ W ∈ U.powerset, (if (∀ S ∈ F, ¬ S ⊆ W) then binomWeight U p W else 0) ≤ ∑ W ∈ U.powerset, binomWeight U p W := by refine sum_le_sum fun W _ => ?_ split_ifs · exact le_rfl · exact binomWeight_nonneg hp0 hp1 W _ = 1 := sum_binomWeight_powerset U p lemma missProb_eq_zero_of_empty_mem {U : Finset α} {p : ℝ} {F : Finset (Finset α)} (h : ∅ ∈ F) : missProb U p F = 0 := by unfold missProb refine sum_eq_zero fun W _ => ?_ rw [if_neg] intro hall exact hall ∅ h (empty_subset W) /-- If every set in `F₂` contains a set in `F₁`, then `missProb F₁ ≤ missProb F₂`. -/ lemma missProb_mono_family {U : Finset α} {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) {F₁ F₂ : Finset (Finset α)} (h : ∀ S₂ ∈ F₂, ∃ S₁ ∈ F₁, S₁ ⊆ S₂) : missProb U p F₁ ≤ missProb U p F₂ := by unfold missProb refine sum_le_sum fun W _ => ?_ split_ifs with h1 h2 · exact le_rfl · exfalso apply h2 intro S₂ hS₂ hsub rcases h S₂ hS₂ with ⟨S₁, hS₁, h12⟩ exact h1 S₁ hS₁ (h12.trans hsub) · exact binomWeight_nonneg hp0 hp1 W · exact le_rfl /-- `missProb` is antitone in the sampling probability `p ∈ [0, 1]`. -/ lemma missProb_antitone {U : Finset α} {p₁ p₂ : ℝ} (hp1 : 0 ≤ p₁) (hp12 : p₁ ≤ p₂) (hp2 : p₂ ≤ 1) (F : Finset (Finset α)) : missProb U p₂ F ≤ missProb U p₁ F := by by_cases h1 : p₁ = 1 · have : p₂ = 1 := le_antisymm hp2 (h1 ▸ hp12) rw [h1, this] · have h1lt : p₁ < 1 := lt_of_le_of_ne (hp12.trans hp2) h1 set δ : ℝ := (p₂ - p₁) / (1 - p₁) have hδ0 : 0 ≤ δ := div_nonneg (by linarith) (by linarith) have hδ1 : δ ≤ 1 := (div_le_one (by linarith)).mpr (by linarith) have hp2_eq : p₁ + δ - p₁ * δ = p₂ := by dsimp only [δ] have hne : 1 - p₁ ≠ 0 := by linarith field_simp [hne] ring have hmiss : ∀ p, missProb U p F = ∑ W ∈ U.powerset, binomWeight U p W * (if (∀ S ∈ F, ¬ S ⊆ W) then (1 : ℝ) else 0) := by intro p unfold missProb refine sum_congr rfl fun W _ => ?_ split_ifs <;> ring rw [hmiss p₂, ← hp2_eq, ← sum_binomWeight_union] calc ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U δ W₂ * (if (∀ S ∈ F, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) ≤ ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U p₁ W₁ * binomWeight U δ W₂ * (if (∀ S ∈ F, ¬ S ⊆ W₁) then (1 : ℝ) else 0) := by refine sum_le_sum fun W₁ _ => sum_le_sum fun W₂ _ => ?_ have hw : 0 ≤ binomWeight U p₁ W₁ * binomWeight U δ W₂ := mul_nonneg (binomWeight_nonneg hp1 (le_of_lt h1lt) W₁) (binomWeight_nonneg hδ0 hδ1 W₂) refine mul_le_mul_of_nonneg_left ?_ hw split_ifs with h12 h1' · exact le_rfl · exfalso apply h1' intro S hS hSW1 exact h12 S hS (hSW1.trans subset_union_left) · norm_num · exact le_rfl _ = ∑ W₁ ∈ U.powerset, binomWeight U p₁ W₁ * (if (∀ S ∈ F, ¬ S ⊆ W₁) then (1 : ℝ) else 0) * ∑ W₂ ∈ U.powerset, binomWeight U δ W₂ := by refine sum_congr rfl fun W₁ _ => ?_ rw [mul_sum] refine sum_congr rfl fun W₂ _ => by ring _ = missProb U p₁ F := by rw [sum_binomWeight_powerset, hmiss p₁] refine sum_congr rfl fun W₁ _ => by ring /-- Exact miss probability for a family of singletons `V ⊆ U` is `(1 - q) ^ V.card`. -/ lemma sum_binomWeight_powerset_sdiff (U V : Finset α) (hVU : V ⊆ U) (q : ℝ) : ∑ W ∈ (U \ V).powerset, binomWeight U q W = (1 - q) ^ V.card := by have hdisj : Disjoint (U \ V) V := sdiff_disjoint have hunion : (U \ V) ∪ V = U := sdiff_union_of_subset hVU have hcard : U.card = (U \ V).card + V.card := by rw [← card_union_of_disjoint hdisj, hunion] have hterm : ∀ W ∈ (U \ V).powerset, binomWeight U q W = (1 - q) ^ V.card * binomWeight (U \ V) q W := by intro W hW have hWU : W.card ≤ (U \ V).card := card_le_card (mem_powerset.mp hW) unfold binomWeight have hsub : U.card - W.card = ((U \ V).card - W.card) + V.card := by omega rw [hsub, pow_add] ring rw [sum_congr rfl hterm, ← mul_sum, sum_binomWeight_powerset, mul_one] end BinomialMeasure section SubspreadAndOneStep variable {α : Type*} [DecidableEq α] /-- An `R`-subspread non-negative measure supported on subsets of `U` of size at most `ℓ`. Notice we do NOT require `totalMass = 1`; keeping it as a sub-probability measure keeps `R` strictly invariant across all reduction rounds with zero renormalization loss. -/ structure SubspreadMeasure (U : Finset α) (R : ℝ) (ℓ : ℕ) where supp : Finset (Finset α) weight : Finset α → ℝ supp_subset : ∀ S ∈ supp, S ⊆ U card_le : ∀ S ∈ supp, S.card ≤ ℓ weight_nonneg : ∀ S, 0 ≤ weight S weight_zero_of_not_mem : ∀ S, S ∉ supp → weight S = 0 subspread : ∀ T : Finset α, T.Nonempty → ∑ S ∈ supp.filter (fun S => T ⊆ S), weight S ≤ (1 / R) ^ T.card /-- Total mass of a subspread measure. -/ noncomputable def SubspreadMeasure.totalMass {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) : ℝ := ∑ S ∈ μ.supp, μ.weight S lemma SubspreadMeasure.totalMass_nonneg {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) : 0 ≤ μ.totalMass := sum_nonneg fun S _ => μ.weight_nonneg S /-- Relax the size bound of a subspread measure from `ℓ₁` to `ℓ₂ ≥ ℓ₁`. -/ def SubspreadMeasure.weaken {U : Finset α} {R : ℝ} {ℓ₁ ℓ₂ : ℕ} (h : ℓ₁ ≤ ℓ₂) (μ : SubspreadMeasure U R ℓ₁) : SubspreadMeasure U R ℓ₂ where supp := μ.supp weight := μ.weight supp_subset := μ.supp_subset card_le := fun S hS => (μ.card_le S hS).trans h weight_nonneg := μ.weight_nonneg weight_zero_of_not_mem := μ.weight_zero_of_not_mem subspread := μ.subspread /-- For `S ∈ F` and `W`, pick a set `S' ∈ F` contained in `S ∪ W` minimizing `(S' \ W).card`, and return the residual fragment `S' \ W`. -/ noncomputable def minFrag (F : Finset (Finset α)) (S W : Finset α) : Finset α := if h : (F.filter (fun S' => S' ⊆ S ∪ W)).Nonempty then (Classical.choose (exists_min_image _ (fun S' => (S' \ W).card) h)) \ W else S \ W lemma minFrag_spec {F : Finset (Finset α)} {S W : Finset α} (hS : S ∈ F) : ∃ S' ∈ F, S' ⊆ S ∪ W ∧ minFrag F S W = S' \ W ∧ ∀ S'' ∈ F, S'' ⊆ S ∪ W → (minFrag F S W).card ≤ (S'' \ W).card := by have hne : (F.filter (fun S' => S' ⊆ S ∪ W)).Nonempty := ⟨S, mem_filter.mpr ⟨hS, subset_union_left⟩⟩ unfold minFrag rw [dif_pos hne] set S' := Classical.choose (exists_min_image _ (fun S' => (S' \ W).card) hne) have hspec := Classical.choose_spec (exists_min_image _ (fun S' => (S' \ W).card) hne) have hmem := mem_filter.mp hspec.1 refine ⟨S', hmem.1, hmem.2, rfl, fun S'' hS'' hsub => ?_⟩ exact hspec.2 S'' (mem_filter.mpr ⟨hS'', hsub⟩) lemma minFrag_subset_sdiff {F : Finset (Finset α)} {S W : Finset α} (hS : S ∈ F) : minFrag F S W ⊆ S \ W := by rcases minFrag_spec hS with ⟨S', _, hsub, hfrag, _⟩ rw [hfrag] intro x hx rcases mem_sdiff.mp hx with ⟨hxS', hxW⟩ rcases mem_union.mp (hsub hxS') with hxS | hxW' · exact mem_sdiff.mpr ⟨hxS, hxW⟩ · exact absurd hxW' hxW lemma minFrag_subset_self {F : Finset (Finset α)} {S W : Finset α} (hS : S ∈ F) : minFrag F S W ⊆ S := (minFrag_subset_sdiff hS).trans sdiff_subset lemma minFrag_disjoint {F : Finset (Finset α)} {S W : Finset α} (hS : S ∈ F) : Disjoint (minFrag F S W) W := disjoint_of_subset_left (minFrag_subset_sdiff hS) sdiff_disjoint /-- Bad mass discarded in one reduction round with cutoff `ℓ'`. -/ noncomputable def badMass {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) (W : Finset α) (ℓ' : ℕ) : ℝ := ∑ S ∈ μ.supp.filter (fun S => ℓ' < (minFrag μ.supp S W).card), μ.weight S lemma badMass_nonneg {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) (W : Finset α) (ℓ' : ℕ) : 0 ≤ badMass μ W ℓ' := sum_nonneg fun S _ => μ.weight_nonneg S /-- Pushforward of an `R`-subspread measure through `S ↦ minFrag μ.supp S W`, keeping only fragments of cardinality `≤ ℓ'`. Crucially, `R` is preserved identically! -/ noncomputable def pushforward {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) (W : Finset α) (ℓ' : ℕ) : SubspreadMeasure U R ℓ' where supp := (μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ')).image (fun S => minFrag μ.supp S W) weight := fun T => ∑ S ∈ μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ' ∧ minFrag μ.supp S W = T), μ.weight S supp_subset := by intro T hT rcases mem_image.mp hT with ⟨S, hS, rfl⟩ have hSmem := (mem_filter.mp hS).1 exact (minFrag_subset_self hSmem).trans (μ.supp_subset S hSmem) card_le := by intro T hT rcases mem_image.mp hT with ⟨S, hS, rfl⟩ exact (mem_filter.mp hS).2 weight_nonneg := fun _ => sum_nonneg fun S _ => μ.weight_nonneg S weight_zero_of_not_mem := by intro T hT refine sum_eq_zero fun S hS => ?_ exfalso apply hT rcases mem_filter.mp hS with ⟨hSmem, hcard, hEq⟩ exact mem_image.mpr ⟨S, mem_filter.mpr ⟨hSmem, hcard⟩, hEq⟩ subspread := by intro T hTne set G := μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ') have hfib : ∑ F ∈ (G.image (fun S => minFrag μ.supp S W)).filter (fun F => T ⊆ F), ∑ S ∈ μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ' ∧ minFrag μ.supp S W = F), μ.weight S = ∑ S ∈ G.filter (fun S => T ⊆ minFrag μ.supp S W), μ.weight S := by calc ∑ F ∈ (G.image (fun S => minFrag μ.supp S W)).filter (fun F => T ⊆ F), ∑ S ∈ μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ' ∧ minFrag μ.supp S W = F), μ.weight S = ∑ F ∈ (G.image (fun S => minFrag μ.supp S W)).filter (fun F => T ⊆ F), ∑ S ∈ (G.filter (fun S => T ⊆ minFrag μ.supp S W)).filter (fun S => minFrag μ.supp S W = F), μ.weight S := by refine sum_congr rfl fun F hF => ?_ have hTF : T ⊆ F := (mem_filter.mp hF).2 refine sum_congr ?_ fun _ _ => rfl ext S simp only [G, mem_filter] constructor · rintro ⟨hS, hcard, rfl⟩; exact ⟨⟨⟨hS, hcard⟩, hTF⟩, rfl⟩ · rintro ⟨⟨⟨hS, hcard⟩, _⟩, rfl⟩; exact ⟨hS, hcard, rfl⟩ _ = ∑ S ∈ G.filter (fun S => T ⊆ minFrag μ.supp S W), μ.weight S := by refine sum_fiberwise_of_maps_to (g := fun S => minFrag μ.supp S W) ?_ μ.weight intro S hS rcases mem_filter.mp hS with ⟨hSG, hTsub⟩ exact mem_filter.mpr ⟨mem_image_of_mem _ hSG, hTsub⟩ rw [hfib] calc ∑ S ∈ G.filter (fun S => T ⊆ minFrag μ.supp S W), μ.weight S ≤ ∑ S ∈ μ.supp.filter (fun S => T ⊆ S), μ.weight S := by refine sum_le_sum_of_subset_of_nonneg ?_ (fun S _ _ => μ.weight_nonneg S) intro S hS rcases mem_filter.mp hS with ⟨hSG, hTsub⟩ have hSmem := (mem_filter.mp hSG).1 exact mem_filter.mpr ⟨hSmem, hTsub.trans (minFrag_subset_self hSmem)⟩ _ ≤ (1 / R) ^ T.card := μ.subspread T hTne lemma pushforward_totalMass_add_badMass {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) (W : Finset α) (ℓ' : ℕ) : (pushforward μ W ℓ').totalMass + badMass μ W ℓ' = μ.totalMass := by unfold SubspreadMeasure.totalMass pushforward badMass simp only set G := μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ') have h1 : ∑ T ∈ G.image (fun S => minFrag μ.supp S W), ∑ S ∈ μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ' ∧ minFrag μ.supp S W = T), μ.weight S = ∑ S ∈ G, μ.weight S := by calc ∑ T ∈ G.image (fun S => minFrag μ.supp S W), ∑ S ∈ μ.supp.filter (fun S => (minFrag μ.supp S W).card ≤ ℓ' ∧ minFrag μ.supp S W = T), μ.weight S = ∑ T ∈ G.image (fun S => minFrag μ.supp S W), ∑ S ∈ G.filter (fun S => minFrag μ.supp S W = T), μ.weight S := by refine sum_congr rfl fun T _ => ?_ refine sum_congr ?_ fun _ _ => rfl ext S simp only [G, mem_filter] tauto _ = ∑ S ∈ G, μ.weight S := by refine sum_fiberwise_of_maps_to (g := fun S => minFrag μ.supp S W) ?_ μ.weight intro S hS exact mem_image_of_mem _ hS rw [h1] have hpart : μ.supp.filter (fun S => ℓ' < (minFrag μ.supp S W).card) = μ.supp.filter (fun S => ¬ (minFrag μ.supp S W).card ≤ ℓ') := by ext S; simp [not_le] rw [hpart] exact sum_filter_add_sum_filter_not μ.supp (fun S => (minFrag μ.supp S W).card ≤ ℓ') μ.weight lemma pushforward_supp_union_contains {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) (W : Finset α) (ℓ' : ℕ) : ∀ T ∈ (pushforward μ W ℓ').supp, ∃ S' ∈ μ.supp, S' ⊆ T ∪ W := by intro T hT rcases mem_image.mp hT with ⟨S, hS, rfl⟩ have hSmem := (mem_filter.mp hS).1 rcases minFrag_spec hSmem with ⟨S', hS'mem, _, hfrag, _⟩ refine ⟨S', hS'mem, ?_⟩ rw [hfrag] intro x hx by_cases hxW : x ∈ W · exact mem_union_right _ hxW · exact mem_union_left _ (mem_sdiff.mpr ⟨hx, hxW⟩) /-- Upper binomial tail `∑_{j = ℓ' + 1}^{ℓ} C(ℓ, j) * x^j`. -/ noncomputable def binomTail (ℓ ℓ' : ℕ) (x : ℝ) : ℝ := ∑ j ∈ Icc (ℓ' + 1) ℓ, (Nat.choose ℓ j : ℝ) * x ^ j lemma binomTail_nonneg {ℓ ℓ' : ℕ} {x : ℝ} (hx : 0 ≤ x) : 0 ≤ binomTail ℓ ℓ' x := by unfold binomTail refine sum_nonneg fun j _ => by positivity lemma binomTail_mono_left {ℓ₁ ℓ₂ ℓ' : ℕ} {x : ℝ} (h12 : ℓ₁ ≤ ℓ₂) (hx : 0 ≤ x) : binomTail ℓ₁ ℓ' x ≤ binomTail ℓ₂ ℓ' x := by unfold binomTail calc ∑ j ∈ Icc (ℓ' + 1) ℓ₁, (Nat.choose ℓ₁ j : ℝ) * x ^ j ≤ ∑ j ∈ Icc (ℓ' + 1) ℓ₁, (Nat.choose ℓ₂ j : ℝ) * x ^ j := by refine sum_le_sum fun j _ => ?_ exact mul_le_mul_of_nonneg_right (Nat.cast_le.mpr (Nat.choose_le_choose j h12)) (pow_nonneg hx j) _ ≤ ∑ j ∈ Icc (ℓ' + 1) ℓ₂, (Nat.choose ℓ₂ j : ℝ) * x ^ j := by refine sum_le_sum_of_subset_of_nonneg (Icc_subset_Icc_right h12) ?_ intro j _ _ positivity /-- Core of all sets in `F` contained in `Z`: `⋂_{S' ∈ F, S' ⊆ Z} S'`. -/ def hitCore (F : Finset (Finset α)) (Z : Finset α) : Finset α := Z.filter (fun x => ∀ S' ∈ F, S' ⊆ Z → x ∈ S') lemma sum_biUnion_le_of_nonneg {β γ : Type*} [DecidableEq β] [DecidableEq γ] {s : Finset β} {t : β → Finset γ} {f : γ → ℝ} (hf : ∀ x, 0 ≤ f x) : ∑ x ∈ s.biUnion t, f x ≤ ∑ i ∈ s, ∑ x ∈ t i, f x := by induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [biUnion_insert, sum_insert ha] calc ∑ x ∈ t a ∪ s.biUnion t, f x ≤ ∑ x ∈ t a, f x + ∑ x ∈ s.biUnion t, f x := by have h := sum_union_inter (s₁ := t a) (s₂ := s.biUnion t) (f := f) have hinter : 0 ≤ ∑ x ∈ t a ∩ s.biUnion t, f x := sum_nonneg fun x _ => hf x linarith _ ≤ ∑ x ∈ t a, f x + ∑ i ∈ s, ∑ x ∈ t i, f x := by linarith /-- **Theorem 1 (Core-Restricted Exact One-Step Binomial Fragment Lemma):** For any `R`-subspread measure `μ` on subsets of `U` of size `≤ ℓ`, any `q ∈ (0, 1)`, and any `ℓ' < ℓ`: `E_{W ~ Bin(U, q)}[badMass μ W ℓ'] ≤ ∑_{Z hitting supp} Q_q(Z) · ∑_{T ⊆ core(Z), |T| > ℓ'} ((1-q)/(qR))^|T|`. -/ theorem one_step_fragment_bound_core {U : Finset α} {R q : ℝ} {ℓ ℓ' : ℕ} (hR : 0 < R) (hq0 : 0 < q) (hq1 : q < 1) (μ : SubspreadMeasure U R ℓ) : ∑ W ∈ U.powerset, binomWeight U q W * badMass μ W ℓ' ≤ ∑ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), binomWeight U q Z * ∑ T ∈ (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card), ((1 - q) / (q * R)) ^ T.card := by let G : Finset α → Finset (Finset α) := fun W => (μ.supp.filter (fun S => ℓ' < (minFrag μ.supp S W).card)).image (fun S => minFrag μ.supp S W) have hstep1 : ∀ W ∈ U.powerset, badMass μ W ℓ' ≤ ∑ T ∈ G W, (1 / R) ^ T.card := by intro W _ unfold badMass have hcov : μ.supp.filter (fun S => ℓ' < (minFrag μ.supp S W).card) ⊆ (G W).biUnion (fun T => μ.supp.filter (fun S => T ⊆ S)) := by intro S hS rcases mem_filter.mp hS with ⟨hSmem, hcard⟩ refine mem_biUnion.mpr ⟨minFrag μ.supp S W, ?_, ?_⟩ · exact mem_image.mpr ⟨S, mem_filter.mpr ⟨hSmem, hcard⟩, rfl⟩ · exact mem_filter.mpr ⟨hSmem, minFrag_subset_self hSmem⟩ calc ∑ S ∈ μ.supp.filter (fun S => ℓ' < (minFrag μ.supp S W).card), μ.weight S ≤ ∑ S ∈ (G W).biUnion (fun T => μ.supp.filter (fun S => T ⊆ S)), μ.weight S := sum_le_sum_of_subset_of_nonneg hcov (fun S _ _ => μ.weight_nonneg S) _ ≤ ∑ T ∈ G W, ∑ S ∈ μ.supp.filter (fun S => T ⊆ S), μ.weight S := sum_biUnion_le_of_nonneg μ.weight_nonneg _ ≤ ∑ T ∈ G W, (1 / R) ^ T.card := by refine sum_le_sum fun T hT => ?_ rcases mem_image.mp hT with ⟨S, hS, rfl⟩ have hcard : 0 < (minFrag μ.supp S W).card := by have := (mem_filter.mp hS).2; omega exact μ.subspread _ (card_pos.mp hcard) let lhsPairs : Finset (Sigma fun _ : Finset α => Finset α) := U.powerset.sigma G let rhsPairs : Finset (Sigma fun _ : Finset α => Finset α) := (U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z)).sigma (fun Z => (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card)) let φ : (Sigma fun _ : Finset α => Finset α) → (Sigma fun _ : Finset α => Finset α) := fun p => ⟨p.1 ∪ p.2, p.2⟩ have hmaps : ∀ p ∈ lhsPairs, φ p ∈ rhsPairs := by intro ⟨W, T⟩ hp rcases mem_sigma.mp hp with ⟨hW, hT⟩ dsimp only at hW hT rcases mem_image.mp hT with ⟨S, hS, rfl⟩ rcases mem_filter.mp hS with ⟨hSmem, hcard⟩ rcases minFrag_spec hSmem with ⟨S', hS'mem, _, hfrag, hmin⟩ have hWU : W ⊆ U := mem_powerset.mp hW have hTU : minFrag μ.supp S W ⊆ U := (minFrag_subset_self hSmem).trans (μ.supp_subset S hSmem) have hZU : W ∪ minFrag μ.supp S W ⊆ U := union_subset hWU hTU have hS'Z : S' ⊆ W ∪ minFrag μ.supp S W := by rw [hfrag] intro x hx by_cases hxW : x ∈ W · exact mem_union_left _ hxW · exact mem_union_right _ (mem_sdiff.mpr ⟨hx, hxW⟩) have hZhit : ∃ S₀ ∈ μ.supp, S₀ ⊆ W ∪ minFrag μ.supp S W := ⟨S', hS'mem, hS'Z⟩ have hTcore : minFrag μ.supp S W ⊆ hitCore μ.supp (W ∪ minFrag μ.supp S W) := by intro x hx refine mem_filter.mpr ⟨mem_union_right _ hx, fun S'' hS''mem hS''sub => ?_⟩ have hS''SW : S'' ⊆ S ∪ W := by refine hS''sub.trans (union_subset subset_union_right ?_) exact (minFrag_subset_self hSmem).trans subset_union_left have hle_card : (minFrag μ.supp S W).card ≤ (S'' \ W).card := hmin S'' hS''mem hS''SW have hsub_T : S'' \ W ⊆ minFrag μ.supp S W := by intro y hy rcases mem_sdiff.mp hy with ⟨hyS'', hyW⟩ rcases mem_union.mp (hS''sub hyS'') with hyW' | hyT · exact absurd hyW' hyW · exact hyT have heq_T : S'' \ W = minFrag μ.supp S W := eq_of_subset_of_card_le hsub_T hle_card exact (mem_sdiff.mp (heq_T.symm ▸ hx)).1 exact mem_sigma.mpr ⟨mem_filter.mpr ⟨mem_powerset.mpr hZU, hZhit⟩, mem_filter.mpr ⟨mem_powerset.mpr hTcore, hcard⟩⟩ have hinj : Set.InjOn φ (lhsPairs : Set (Sigma fun _ : Finset α => Finset α)) := by intro ⟨W₁, T₁⟩ hp₁ ⟨W₂, T₂⟩ hp₂ heq have hT : T₁ = T₂ := by simpa [φ] using congrArg Sigma.snd heq subst hT have hUeq : W₁ ∪ T₁ = W₂ ∪ T₁ := by simpa [φ] using congrArg Sigma.fst heq rcases mem_sigma.mp hp₁ with ⟨_, hT₁⟩ dsimp only at hT₁ rcases mem_image.mp hT₁ with ⟨S₁, hS₁, hEq₁⟩ have hd₁ : Disjoint T₁ W₁ := by rw [← hEq₁]; exact minFrag_disjoint (mem_filter.mp hS₁).1 rcases mem_sigma.mp hp₂ with ⟨_, hT₂⟩ dsimp only at hT₂ rcases mem_image.mp hT₂ with ⟨S₂, hS₂, hEq₂⟩ have hd₂ : Disjoint T₁ W₂ := by rw [← hEq₂]; exact minFrag_disjoint (mem_filter.mp hS₂).1 have hW : W₁ = W₂ := by have := congrArg (fun Z => Z \ T₁) hUeq simpa [union_sdiff_cancel_right hd₁.symm, union_sdiff_cancel_right hd₂.symm] using this subst hW rfl have hweight_eq : ∀ p ∈ lhsPairs, binomWeight U q p.1 * (1 / R) ^ p.2.card = binomWeight U q (φ p).1 * ((1 - q) / (q * R)) ^ (φ p).2.card := by intro ⟨W, T⟩ hp rcases mem_sigma.mp hp with ⟨hW, hT⟩ dsimp only at hW hT rcases mem_image.mp hT with ⟨S, hS, rfl⟩ have hSmem := (mem_filter.mp hS).1 have hWU : W ⊆ U := mem_powerset.mp hW have hTU : minFrag μ.supp S W ⊆ U := (minFrag_subset_self hSmem).trans (μ.supp_subset S hSmem) have hdisj : Disjoint (minFrag μ.supp S W) W := minFrag_disjoint hSmem have hsdiff_eq : (W ∪ minFrag μ.supp S W) \ minFrag μ.supp S W = W := union_sdiff_cancel_right hdisj.symm have hbw := binomWeight_sdiff hq0 subset_union_right (union_subset hWU hTU) (q := q) rw [hsdiff_eq] at hbw dsimp only [φ] rw [hbw, mul_assoc, ← mul_pow] congr 2 field_simp [ne_of_gt hq0, ne_of_gt hR] calc ∑ W ∈ U.powerset, binomWeight U q W * badMass μ W ℓ' ≤ ∑ W ∈ U.powerset, binomWeight U q W * ∑ T ∈ G W, (1 / R) ^ T.card := by refine sum_le_sum fun W hW => mul_le_mul_of_nonneg_left (hstep1 W hW) (binomWeight_nonneg (le_of_lt hq0) (le_of_lt hq1) W) _ = ∑ W ∈ U.powerset, ∑ T ∈ G W, binomWeight U q W * (1 / R) ^ T.card := sum_congr rfl fun W _ => mul_sum _ _ _ _ = ∑ p ∈ lhsPairs, binomWeight U q p.1 * (1 / R) ^ p.2.card := sum_sigma' U.powerset G (fun W T => binomWeight U q W * (1 / R) ^ T.card) _ = ∑ p ∈ lhsPairs, binomWeight U q (φ p).1 * ((1 - q) / (q * R)) ^ (φ p).2.card := sum_congr rfl hweight_eq _ = ∑ p ∈ lhsPairs.image φ, binomWeight U q p.1 * ((1 - q) / (q * R)) ^ p.2.card := by rw [sum_image hinj] _ ≤ ∑ p ∈ rhsPairs, binomWeight U q p.1 * ((1 - q) / (q * R)) ^ p.2.card := by refine sum_le_sum_of_subset_of_nonneg ?_ ?_ · intro p hp rcases mem_image.mp hp with ⟨p', hp', rfl⟩ exact hmaps p' hp' · intro p _ _ have h1q : 0 ≤ 1 - q := by linarith have hbw := binomWeight_nonneg (U := U) (le_of_lt hq0) (le_of_lt hq1) p.1 positivity _ = ∑ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), ∑ T ∈ (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card), binomWeight U q Z * ((1 - q) / (q * R)) ^ T.card := (sum_sigma' (U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z)) (fun Z => (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card)) (fun Z T => binomWeight U q Z * ((1 - q) / (q * R)) ^ T.card)).symm _ = ∑ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), binomWeight U q Z * ∑ T ∈ (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card), ((1 - q) / (q * R)) ^ T.card := sum_congr rfl fun Z _ => (mul_sum _ _ _).symm /-- **Theorem 1 (Exact Product-Measure One-Step Binomial Fragment Lemma):** For any `R`-subspread measure `μ` on subsets of `U` of size `≤ ℓ`, any `q ∈ (0, 1)`, and any `ℓ'`: `E_{W ~ Bin(U, q)}[badMass μ W ℓ'] ≤ ∑_{j = ℓ'+1}^{ℓ} C(ℓ, j) * ((1 - q) / (q * R)) ^ j`. -/ theorem one_step_fragment_bound {U : Finset α} {R q : ℝ} {ℓ ℓ' : ℕ} (hR : 0 < R) (hq0 : 0 < q) (hq1 : q < 1) (μ : SubspreadMeasure U R ℓ) : ∑ W ∈ U.powerset, binomWeight U q W * badMass μ W ℓ' ≤ binomTail ℓ ℓ' ((1 - q) / (q * R)) := by have hx : 0 ≤ (1 - q) / (q * R) := by have h1q : 0 ≤ 1 - q := by linarith positivity have hinner : ∀ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), ∑ T ∈ (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card), ((1 - q) / (q * R)) ^ T.card ≤ binomTail ℓ ℓ' ((1 - q) / (q * R)) := by intro Z hZ rcases (mem_filter.mp hZ).2 with ⟨S', hS'mem, hS'sub⟩ have hcore_le : (hitCore μ.supp Z).card ≤ ℓ := by have hsub : hitCore μ.supp Z ⊆ S' := fun x hx => (mem_filter.mp hx).2 S' hS'mem hS'sub exact (card_le_card hsub).trans (μ.card_le S' hS'mem) set C := hitCore μ.supp Z have hfib : ∑ T ∈ C.powerset.filter (fun T => ℓ' < T.card), ((1 - q) / (q * R)) ^ T.card = binomTail C.card ℓ' ((1 - q) / (q * R)) := by unfold binomTail rw [← sum_fiberwise_of_maps_to (g := Finset.card) (t := Icc (ℓ' + 1) C.card)] · refine sum_congr rfl fun j hj => ?_ have hj1 : ℓ' + 1 ≤ j := (mem_Icc.mp hj).1 have hfilt : (C.powerset.filter (fun T => ℓ' < T.card)).filter (fun T => T.card = j) = C.powersetCard j := by ext T simp only [mem_filter, mem_powerset, mem_powersetCard] constructor · rintro ⟨⟨hsub, _⟩, rfl⟩; exact ⟨hsub, rfl⟩ · rintro ⟨hsub, hcard⟩ exact ⟨⟨hsub, by omega⟩, hcard⟩ have hconst : ∑ T ∈ (C.powerset.filter (fun T => ℓ' < T.card)).filter (fun T => T.card = j), ((1 - q) / (q * R)) ^ T.card = ∑ _T ∈ C.powersetCard j, ((1 - q) / (q * R)) ^ j := by rw [hfilt] refine sum_congr rfl fun T hT => by rw [(mem_powersetCard.mp hT).2] rw [hconst, sum_const, card_powersetCard, nsmul_eq_mul] · intro T hT rcases mem_filter.mp hT with ⟨hTpow, hcard⟩ exact mem_Icc.mpr ⟨by omega, card_le_card (mem_powerset.mp hTpow)⟩ rw [hfib] exact binomTail_mono_left hcore_le hx calc ∑ W ∈ U.powerset, binomWeight U q W * badMass μ W ℓ' ≤ ∑ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), binomWeight U q Z * ∑ T ∈ (hitCore μ.supp Z).powerset.filter (fun T => ℓ' < T.card), ((1 - q) / (q * R)) ^ T.card := one_step_fragment_bound_core hR hq0 hq1 μ _ ≤ ∑ Z ∈ U.powerset.filter (fun Z => ∃ S' ∈ μ.supp, S' ⊆ Z), binomWeight U q Z * binomTail ℓ ℓ' ((1 - q) / (q * R)) := by refine sum_le_sum fun Z hZ => mul_le_mul_of_nonneg_left (hinner Z hZ) (binomWeight_nonneg (le_of_lt hq0) (le_of_lt hq1) Z) _ ≤ ∑ Z ∈ U.powerset, binomWeight U q Z * binomTail ℓ ℓ' ((1 - q) / (q * R)) := by refine sum_le_sum_of_subset_of_nonneg (filter_subset _ _) fun Z _ _ => ?_ exact mul_nonneg (binomWeight_nonneg (le_of_lt hq0) (le_of_lt hq1) Z) (binomTail_nonneg hx) _ = binomTail ℓ ℓ' ((1 - q) / (q * R)) := by rw [← sum_mul, sum_binomWeight_powerset, one_mul] end SubspreadAndOneStep section MultiRoundAndSingleton variable {α : Type*} [DecidableEq α] /-- Elementary convexity / weighted AM-GM inequality: for `a ∈ [0, 1]` and `M ∈ [0, 1]`, `a ^ M ≤ a + (1 - a) * (1 - M)`. -/ lemma rpow_le_linear_convex {a M : ℝ} (ha0 : 0 ≤ a) (hM0 : 0 ≤ M) (hM1 : M ≤ 1) : a ^ M ≤ a + (1 - a) * (1 - M) := by by_cases hMzero : M = 0 · subst hMzero; simp · have h := Real.geom_mean_le_arith_mean2_weighted hM0 (by linarith : 0 ≤ 1 - M) ha0 zero_le_one (by linarith : M + (1 - M) = 1) rw [Real.one_rpow, mul_one] at h linarith /-- **Convex Singleton Endpoint Lemma:** For any `R`-subspread measure `μ` supported on sets of size `≤ 1` with `totalMass ≤ 1` and any `q ∈ [0, 1]`, `missProb U q μ.supp ≤ (1 - q)^R + (1 - (1 - q)^R) * (1 - μ.totalMass)`. -/ theorem singleton_miss_bound {U : Finset α} {R q : ℝ} (hR : 0 < R) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) (μ : SubspreadMeasure U R 1) (hM1 : μ.totalMass ≤ 1) : missProb U q μ.supp ≤ (1 - q) ^ R + (1 - (1 - q) ^ R) * (1 - μ.totalMass) := by have ha0 : 0 ≤ (1 - q) ^ R := Real.rpow_nonneg (by linarith) R have ha1 : (1 - q) ^ R ≤ 1 := Real.rpow_le_one (by linarith) (by linarith) (le_of_lt hR) by_cases hempty : ∅ ∈ μ.supp · rw [missProb_eq_zero_of_empty_mem hempty] have h1a : 0 ≤ 1 - (1 - q) ^ R := by linarith have h1M : 0 ≤ 1 - μ.totalMass := by linarith nlinarith · -- Every S ∈ μ.supp has card = 1, so μ.supp consists of distinct singletons have hcard1 : ∀ S ∈ μ.supp, S.card = 1 := by intro S hS have hle := μ.card_le S hS have hne : S ≠ ∅ := fun h => hempty (h ▸ hS) have hpos : 0 < S.card := card_pos.mpr (nonempty_iff_ne_empty.mpr hne) omega -- Collect the union V of all singletons in μ.supp set V : Finset α := μ.supp.biUnion id have hVU : V ⊆ U := by intro x hx rcases mem_biUnion.mp hx with ⟨S, hS, hxS⟩ exact μ.supp_subset S hS hxS -- Show V.card = μ.supp.card have hVcard : V.card = μ.supp.card := by have himg : V.image singleton = μ.supp := by ext S simp only [mem_image, V, mem_biUnion, id_eq] constructor · rintro ⟨x, ⟨S', hS', hxS'⟩, rfl⟩ rcases card_eq_one.mp (hcard1 S' hS') with ⟨y, rfl⟩ have hxy : x = y := mem_singleton.mp hxS' subst hxy; exact hS' · intro hS rcases card_eq_one.mp (hcard1 S hS) with ⟨x, rfl⟩ exact ⟨x, ⟨{x}, hS, mem_singleton_self x⟩, rfl⟩ rw [← himg, card_image_of_injective _ singleton_injective] -- Show μ.totalMass ≤ V.card / R have hmass_le : μ.totalMass * R ≤ (V.card : ℝ) := by have hsum : μ.totalMass ≤ (μ.supp.card : ℝ) * (1 / R) := by unfold SubspreadMeasure.totalMass calc ∑ S ∈ μ.supp, μ.weight S ≤ ∑ _S ∈ μ.supp, (1 / R) := by refine sum_le_sum fun S hS => ?_ have hne : S.Nonempty := card_pos.mp (by rw [hcard1 S hS]; omega) have hsp := μ.subspread S hne rw [hcard1 S hS, pow_one] at hsp calc μ.weight S ≤ ∑ S' ∈ μ.supp.filter (fun S' => S ⊆ S'), μ.weight S' := single_le_sum (fun S' _ => μ.weight_nonneg S') (mem_filter.mpr ⟨hS, Subset.rfl⟩) _ ≤ 1 / R := hsp _ = (μ.supp.card : ℝ) * (1 / R) := by rw [sum_const, nsmul_eq_mul] rw [hVcard] have h := mul_le_mul_of_nonneg_right hsum (le_of_lt hR) field_simp [ne_of_gt hR] at h ⊢ linarith -- Compute missProb U q μ.supp = (1 - q) ^ V.card have hmiss_eq : missProb U q μ.supp = (1 - q) ^ V.card := by unfold missProb have hfilt : ∀ W ∈ U.powerset, (∀ S ∈ μ.supp, ¬ S ⊆ W) ↔ W ∈ (U \ V).powerset := by intro W hW rw [mem_powerset] constructor · intro hmiss x hxW refine mem_sdiff.mpr ⟨mem_powerset.mp hW hxW, fun hxV => ?_⟩ rcases mem_biUnion.mp hxV with ⟨S, hS, hxS⟩ rcases card_eq_one.mp (hcard1 S hS) with ⟨y, rfl⟩ have hxy : x = y := mem_singleton.mp hxS subst hxy exact hmiss {x} hS (singleton_subset_iff.mpr hxW) · intro hsub S hS hSW rcases card_eq_one.mp (hcard1 S hS) with ⟨x, rfl⟩ have hxW : x ∈ W := hSW (mem_singleton_self x) have hxV : x ∈ V := mem_biUnion.mpr ⟨{x}, hS, mem_singleton_self x⟩ exact (mem_sdiff.mp (hsub hxW)).2 hxV have hsum_eq : ∑ W ∈ U.powerset, (if (∀ S ∈ μ.supp, ¬ S ⊆ W) then binomWeight U q W else 0) = ∑ W ∈ (U \ V).powerset, binomWeight U q W := by rw [← sum_filter] refine sum_congr ?_ fun _ _ => rfl ext W simp only [mem_filter] constructor · intro ⟨hW, hall⟩; exact (hfilt W hW).mp hall · intro hW have hWU : W ∈ U.powerset := mem_powerset.mpr ((mem_powerset.mp hW).trans sdiff_subset) exact ⟨hWU, (hfilt W hWU).mpr hW⟩ rw [hsum_eq, sum_binomWeight_powerset_sdiff U V hVU q] rw [hmiss_eq] by_cases hq_one : q = 1 · subst hq_one have h0R : (1 - (1 : ℝ)) ^ R = 0 := by rw [sub_self, Real.zero_rpow (ne_of_gt hR)] rw [h0R] by_cases hV0 : V.card = 0 · have hM0 : μ.totalMass = 0 := by have : μ.totalMass * R ≤ 0 := by simpa [hV0] using hmass_le have hge := μ.totalMass_nonneg nlinarith simp [hV0, hM0] · simp [zero_pow hV0] linarith · have h1q_pos : 0 < 1 - q := by have : q < 1 := lt_of_le_of_ne hq1 hq_one linarith calc (1 - q) ^ V.card = (1 - q) ^ (V.card : ℝ) := (Real.rpow_natCast (1 - q) V.card).symm _ ≤ (1 - q) ^ (μ.totalMass * R) := Real.rpow_le_rpow_of_exponent_ge h1q_pos (by linarith) hmass_le _ = ((1 - q) ^ R) ^ μ.totalMass := by rw [mul_comm, Real.rpow_mul (le_of_lt h1q_pos)] _ ≤ (1 - q) ^ R + (1 - (1 - q) ^ R) * (1 - μ.totalMass) := rpow_le_linear_convex ha0 μ.totalMass_nonneg hM1 /-- Combine a list of round probabilities `qs` with terminal singleton probability `q_*` via independent union: `1 - p = (1 - q_*) * ∏_{q ∈ qs} (1 - q)`. -/ def combinedProb (qs : List ℝ) (qStar : ℝ) : ℝ := match qs with | [] => qStar | q :: rest => q + combinedProb rest qStar - q * combinedProb rest qStar lemma combinedProb_mem_Icc {qs : List ℝ} {qStar : ℝ} (hqs : ∀ q ∈ qs, 0 ≤ q ∧ q ≤ 1) (hqS0 : 0 ≤ qStar) (hqS1 : qStar ≤ 1) : 0 ≤ combinedProb qs qStar ∧ combinedProb qs qStar ≤ 1 := by induction qs with | nil => exact ⟨hqS0, hqS1⟩ | cons q rest ih => have hq := hqs q (List.mem_cons_self ..) have hrest := ih (fun r hr => hqs r (List.mem_cons_of_mem _ hr)) unfold combinedProb constructor <;> nlinarith lemma combinedProb_le_sum {qs : List ℝ} {qStar : ℝ} (hqs : ∀ q ∈ qs, 0 ≤ q ∧ q ≤ 1) (hqS0 : 0 ≤ qStar) (hqS1 : qStar ≤ 1) : combinedProb qs qStar ≤ qs.sum + qStar := by induction qs with | nil => simp [combinedProb] | cons q rest ih => have hq := hqs q (List.mem_cons_self ..) have hrest := combinedProb_mem_Icc (fun r hr => hqs r (List.mem_cons_of_mem _ hr)) hqS0 hqS1 have hih := ih (fun r hr => hqs r (List.mem_cons_of_mem _ hr)) simp only [combinedProb, List.sum_cons] nlinarith /-- Sum of binomial tails along a schedule of pairs `(k_{i}, q_i)` starting from `k₀`. -/ noncomputable def scheduleTailSum (R : ℝ) (k₀ : ℕ) (sched : List (ℕ × ℝ)) : ℝ := match sched with | [] => 0 | (k₁, q₁) :: rest => binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) + scheduleTailSum R k₁ rest /-- **Theorem 2 (Exact Multi-Round Sub-Probability Spread Theorem with Convex Singleton Endpoint):** For any finite `U`, any `R > 0`, any schedule `sched = [(k₁, q₁), ..., (kₜ, qₜ)]` with `qᵢ ∈ (0, 1)` ending at size `1`, any terminal singleton probability `q_* ∈ [0, 1]`, and any `R`-subspread measure `μ` on subsets of `U` of size `≤ k₀` with `totalMass ≤ 1`: `missProb U (combinedProb (qs) q_*) μ.supp ≤ (1 - q_*)^R + (1 - (1 - q_*)^R) * (1 - μ.totalMass + ∑ binomTail)`. -/ theorem multi_round_spread_bound {U : Finset α} {R qStar : ℝ} (hR : 0 < R) (hqS0 : 0 ≤ qStar) (hqS1 : qStar ≤ 1) : ∀ (sched : List (ℕ × ℝ)) (k₀ : ℕ), (sched.getLast?.map Prod.fst).getD k₀ = 1 → (∀ p ∈ sched, 0 < p.2 ∧ p.2 < 1) → ∀ (μ : SubspreadMeasure U R k₀), μ.totalMass ≤ 1 → missProb U (combinedProb (sched.map Prod.snd) qStar) μ.supp ≤ (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (1 - μ.totalMass + scheduleTailSum R k₀ sched) := by intro sched induction sched with | nil => intro k₀ hk₀ _ μ hM1 simp only [List.getLast?_nil, Option.map_none, Option.getD_none] at hk₀ subst hk₀ simp only [List.map_nil, combinedProb, scheduleTailSum, add_zero] exact singleton_miss_bound hR hqS0 hqS1 μ hM1 | cons head rest ih => rcases head with ⟨k₁, q₁⟩ intro k₀ hlast hqs μ hM1 have hq₁ : 0 < q₁ ∧ q₁ < 1 := hqs (k₁, q₁) (List.mem_cons_self ..) have hqrest : ∀ p ∈ rest, 0 < p.2 ∧ p.2 < 1 := fun p hp => hqs p (List.mem_cons_of_mem _ hp) have hlast_rest : (rest.getLast?.map Prod.fst).getD k₁ = 1 := by cases rest with | nil => simpa using hlast | cons hd tl => simp only [List.getLast?_cons_cons] at hlast have hne : (hd :: tl).getLast? ≠ none := by simp cases h : (hd :: tl).getLast? with | none => exact absurd h hne | some p => simp_all set pRest : ℝ := combinedProb (rest.map Prod.snd) qStar have hpRest : 0 ≤ pRest ∧ pRest ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro q hq rcases List.mem_map.mp hq with ⟨p, hp, rfl⟩ have := hqrest p hp exact ⟨le_of_lt this.1, le_of_lt this.2⟩ have ha1 : (1 - qStar) ^ R ≤ 1 := Real.rpow_le_one (by linarith) (by linarith) (le_of_lt hR) have h1a : 0 ≤ 1 - (1 - qStar) ^ R := by linarith -- Rewrite combined missProb as double expectation over W₁ ~ Q_{q₁} and W₂ ~ Q_{pRest} have hmiss_eq : missProb U (combinedProb ((k₁, q₁) :: rest |>.map Prod.snd) qStar) μ.supp = ∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * ∑ W₂ ∈ U.powerset, binomWeight U pRest W₂ * (if (∀ S ∈ μ.supp, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) := by simp only [List.map_cons, combinedProb] have hrew : missProb U (q₁ + pRest - q₁ * pRest) μ.supp = ∑ W ∈ U.powerset, binomWeight U (q₁ + pRest - q₁ * pRest) W * (if (∀ S ∈ μ.supp, ¬ S ⊆ W) then (1 : ℝ) else 0) := by unfold missProb refine sum_congr rfl fun W _ => by split_ifs <;> ring rw [hrew, ← sum_binomWeight_union] refine sum_congr rfl fun W₁ _ => ?_ rw [mul_sum] refine sum_congr rfl fun W₂ _ => by ring -- For each W₁, if W₁ ∪ W₂ misses μ.supp then W₂ misses (pushforward μ W₁ k₁).supp have hinner_le : ∀ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U pRest W₂ * (if (∀ S ∈ μ.supp, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) ≤ missProb U pRest (pushforward μ W₁ k₁).supp := by intro W₁ _ unfold missProb refine sum_le_sum fun W₂ _ => ?_ split_ifs with h1 h2 · rw [mul_one] · exfalso apply h2 intro T hT hTW2 rcases pushforward_supp_union_contains μ W₁ k₁ T hT with ⟨S', hS', hS'sub⟩ exact h1 S' hS' (hS'sub.trans (union_subset (hTW2.trans subset_union_right) subset_union_left)) · rw [mul_zero]; exact binomWeight_nonneg hpRest.1 hpRest.2 W₂ · rw [mul_zero] -- Apply IH to (pushforward μ W₁ k₁) for each W₁ have hstep_W1 : ∀ W₁ ∈ U.powerset, missProb U pRest (pushforward μ W₁ k₁).supp ≤ (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (1 - μ.totalMass + badMass μ W₁ k₁ + scheduleTailSum R k₁ rest) := by intro W₁ _ have hmass_eq := pushforward_totalMass_add_badMass μ W₁ k₁ have hpf_le : (pushforward μ W₁ k₁).totalMass ≤ 1 := by have := badMass_nonneg μ W₁ k₁; linarith have hih := ih k₁ hlast_rest hqrest (pushforward μ W₁ k₁) hpf_le have hsub : 1 - (pushforward μ W₁ k₁).totalMass = 1 - μ.totalMass + badMass μ W₁ k₁ := by linarith rw [hsub] at hih exact hih rw [hmiss_eq] calc ∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * ∑ W₂ ∈ U.powerset, binomWeight U pRest W₂ * (if (∀ S ∈ μ.supp, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) ≤ ∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * ((1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (1 - μ.totalMass + badMass μ W₁ k₁ + scheduleTailSum R k₁ rest)) := by refine sum_le_sum fun W₁ hW₁ => mul_le_mul_of_nonneg_left ((hinner_le W₁ hW₁).trans (hstep_W1 W₁ hW₁)) (binomWeight_nonneg (le_of_lt hq₁.1) (le_of_lt hq₁.2) W₁) _ = ((1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (1 - μ.totalMass + scheduleTailSum R k₁ rest)) * (∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁) + (1 - (1 - qStar) ^ R) * (∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * badMass μ W₁ k₁) := by rw [mul_sum, mul_sum, ← sum_add_distrib] refine sum_congr rfl fun W₁ _ => by ring _ ≤ (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (1 - μ.totalMass + scheduleTailSum R k₀ ((k₁, q₁) :: rest)) := by rw [sum_binomWeight_powerset, mul_one] simp only [scheduleTailSum] have h1step := one_step_fragment_bound hR hq₁.1 hq₁.2 (ℓ' := k₁) μ nlinarith end MultiRoundAndSingleton section HalvingAndHalfSpread variable {α : Type*} [DecidableEq α] /-- Elementary central binomial bound: `C(2n, n) * (1/4)^n ≤ 1 / √(3n + 1)` for all `n`. -/ lemma central_binom_bound (n : ℕ) : (Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n ≤ 1 / Real.sqrt (3 * (n : ℝ) + 1) := by have hsq : ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) ^ 2 * (3 * (n : ℝ) + 1) ≤ 1 := by induction n with | zero => norm_num | succ n ih => have hrec : (Nat.choose (2 * (n + 1)) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1) = ((2 * (n : ℝ) + 1) / (2 * (n : ℝ) + 2)) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) := by have hnat : (n + 1) * Nat.choose (2 * (n + 1)) (n + 1) = 2 * (2 * n + 1) * Nat.choose (2 * n) n := by have h2 : Nat.choose (2 * n + 2) (n + 1) = Nat.choose (2 * n + 1) n + Nat.choose (2 * n + 1) (n + 1) := Nat.choose_succ_succ (2 * n + 1) n have hsym : Nat.choose (2 * n + 1) (n + 1) = Nat.choose (2 * n + 1) n := by have := Nat.choose_symm (n := 2 * n + 1) (k := n) (by omega) simpa [show 2 * n + 1 - n = n + 1 by omega] using this have h2' : Nat.choose (2 * (n + 1)) (n + 1) = 2 * Nat.choose (2 * n + 1) n := by rw [show 2 * (n + 1) = 2 * n + 2 by omega, h2, hsym]; ring have hstep : Nat.choose (2 * n + 2) (n + 1) * (n + 1) = Nat.choose (2 * n + 2) n * (2 * n + 2 - n) := Nat.choose_succ_right_eq (2 * n + 2) n have hstep1 : Nat.choose (2 * n + 1) (n + 1) * (n + 1) = Nat.choose (2 * n + 1) n * (2 * n + 1 - n) := Nat.choose_succ_right_eq (2 * n + 1) n -- Use (2n+1) * C(2n, n) = (n+1) * C(2n+1, n+1) via Pascal + choose_succ_right_eq: have hmul1 : Nat.choose (2 * n) (n + 1) * (n + 1) = Nat.choose (2 * n) n * n := by have := Nat.choose_succ_right_eq (2 * n) n rw [show 2 * n - n = n by omega] at this exact this have hpas : Nat.choose (2 * n + 1) (n + 1) = Nat.choose (2 * n) n + Nat.choose (2 * n) (n + 1) := Nat.choose_succ_succ (2 * n) n have h1' : (n + 1) * Nat.choose (2 * n + 1) n = (2 * n + 1) * Nat.choose (2 * n) n := by rw [← hsym, hpas]; linarith rw [h2']; linarith have hcast : ((n : ℝ) + 1) * (Nat.choose (2 * (n + 1)) (n + 1) : ℝ) = 2 * (2 * (n : ℝ) + 1) * (Nat.choose (2 * n) n : ℝ) := by exact_mod_cast hnat have hne : (n : ℝ) + 1 ≠ 0 := by positivity have hne2 : 2 * (n : ℝ) + 2 ≠ 0 := by positivity rw [pow_succ] field_simp [hne, hne2] nlinarith [hcast] rw [hrec, mul_pow] have hpos : 0 ≤ ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) ^ 2 := sq_nonneg _ have hrat : ((2 * (n : ℝ) + 1) / (2 * (n : ℝ) + 2)) ^ 2 * (3 * ((n + 1 : ℕ) : ℝ) + 1) ≤ 3 * (n : ℝ) + 1 := by push_cast have hne : (2 * (n : ℝ) + 2) ^ 2 > 0 := by positivity rw [div_pow, div_mul_eq_mul_div, div_le_iff₀ hne] nlinarith calc ((2 * (n : ℝ) + 1) / (2 * (n : ℝ) + 2)) ^ 2 * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) ^ 2 * (3 * ((n + 1 : ℕ) : ℝ) + 1) = (((2 * (n : ℝ) + 1) / (2 * (n : ℝ) + 2)) ^ 2 * (3 * ((n + 1 : ℕ) : ℝ) + 1)) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) ^ 2 := by ring _ ≤ (3 * (n : ℝ) + 1) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) ^ 2 := mul_le_mul_of_nonneg_right hrat hpos _ ≤ 1 := by linarith have hsqrt_pos : 0 < Real.sqrt (3 * (n : ℝ) + 1) := Real.sqrt_pos.mpr (by positivity) rw [le_div_iff₀ hsqrt_pos] have hnonneg : 0 ≤ (Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n * Real.sqrt (3 * (n : ℝ) + 1) := by positivity nlinarith [Real.sq_sqrt (show 0 ≤ 3 * (n : ℝ) + 1 by positivity), sq_nonneg ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n * Real.sqrt (3 * (n : ℝ) + 1) - 1)] /-- Refined geometric ratio bound for the upper binomial tail at `x = 1/4`: for all `n ≥ 1`, consecutive terms decay by at most `(n - 1) / (4 * (n + 2))`, giving `binomTail (2n) n (1/4) ≤ ((n * (n + 2)) / ((n + 1) * (3 * n + 9))) / √(3n + 1)`. -/ lemma halving_tail_le_refined {n : ℕ} (hn : 1 ≤ n) : binomTail (2 * n) n (1 / 4 : ℝ) ≤ (((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9))) * (1 / Real.sqrt (3 * (n : ℝ) + 1)) := by set ρ : ℝ := ((n : ℝ) - 1) / (4 * ((n : ℝ) + 2)) have hρ0 : 0 ≤ ρ := by dsimp only [ρ] have : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast hn positivity have hρ1 : ρ < 1 := by dsimp only [ρ] rw [div_lt_one (by positivity)] linarith have hterm : ∀ k : ℕ, (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (1 / 4 : ℝ) ^ (n + 1 + k) ≤ ρ ^ k * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1)) := by intro k induction k with | zero => simp | succ k ih => by_cases hle : n + 1 + k < 2 * n · have hstep : (Nat.choose (2 * n) (n + 1 + k + 1) : ℝ) * (1 / 4 : ℝ) ≤ ρ * (Nat.choose (2 * n) (n + 1 + k) : ℝ) := by have h1 := Nat.choose_succ_right_eq (2 * n) (n + 1 + k) have hcast : (Nat.choose (2 * n) (n + 1 + k + 1) : ℝ) * ((n + 1 + k + 1 : ℕ) : ℝ) = (Nat.choose (2 * n) (n + 1 + k) : ℝ) * ((2 * n - (n + 1 + k) : ℕ) : ℝ) := by exact_mod_cast h1 have hsub : ((2 * n - (n + 1 + k) : ℕ) : ℝ) = (n : ℝ) - 1 - (k : ℝ) := by have hle' : n + 1 + k ≤ 2 * n := by omega rw [Nat.cast_sub hle']; push_cast; ring rw [hsub] at hcast have hnum_le : ((n : ℝ) - 1 - (k : ℝ)) / (((n : ℝ) + 2 + (k : ℝ)) * 4) ≤ ρ := by dsimp only [ρ] rw [div_le_div_iff₀ (by positivity) (by positivity)] have : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast hn nlinarith have hden_pos : (0 : ℝ) < (n : ℝ) + 2 + (k : ℝ) := by positivity have hcast' : (Nat.choose (2 * n) (n + 1 + k + 1) : ℝ) = (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (((n : ℝ) - 1 - (k : ℝ)) / ((n : ℝ) + 2 + (k : ℝ))) := by push_cast at hcast rw [mul_div_assoc', eq_div_iff (ne_of_gt hden_pos)] linarith rw [hcast'] have hch_nn : 0 ≤ (Nat.choose (2 * n) (n + 1 + k) : ℝ) := Nat.cast_nonneg _ have heq : (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (((n : ℝ) - 1 - (k : ℝ)) / ((n : ℝ) + 2 + (k : ℝ))) * (1 / 4 : ℝ) = (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (((n : ℝ) - 1 - (k : ℝ)) / (((n : ℝ) + 2 + (k : ℝ)) * 4)) := by field_simp [ne_of_gt hden_pos] rw [heq] nlinarith rw [show n + 1 + (k + 1) = n + 1 + k + 1 by omega, pow_succ, pow_succ] have hpow_nn : 0 ≤ (1 / 4 : ℝ) ^ (n + 1 + k) := by positivity calc (Nat.choose (2 * n) (n + 1 + k + 1) : ℝ) * ((1 / 4 : ℝ) ^ (n + 1 + k) * (1 / 4)) = ((Nat.choose (2 * n) (n + 1 + k + 1) : ℝ) * (1 / 4 : ℝ)) * (1 / 4 : ℝ) ^ (n + 1 + k) := by ring _ ≤ (ρ * (Nat.choose (2 * n) (n + 1 + k) : ℝ)) * (1 / 4 : ℝ) ^ (n + 1 + k) := mul_le_mul_of_nonneg_right hstep hpow_nn _ = ρ * ((Nat.choose (2 * n) (n + 1 + k) : ℝ) * (1 / 4 : ℝ) ^ (n + 1 + k)) := by ring _ ≤ ρ * (ρ ^ k * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1))) := mul_le_mul_of_nonneg_left ih hρ0 _ = ρ ^ k * ρ * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1)) := by ring · rw [Nat.choose_eq_zero_of_lt (by omega)] simp positivity have hgeo : ∀ m : ℕ, ∑ k ∈ range m, ρ ^ k ≤ 1 / (1 - ρ) := by intro m induction m with | zero => simp only [range_zero, sum_empty] exact div_nonneg zero_le_one (by linarith) | succ m ih => rw [sum_range_succ'] simp only [pow_zero, pow_succ'] rw [← mul_sum] have h1 : 1 + ρ * (1 / (1 - ρ)) = 1 / (1 - ρ) := by have hne : 1 - ρ ≠ 0 := by linarith field_simp [hne]; ring nlinarith have hreindex : binomTail (2 * n) n (1 / 4 : ℝ) = ∑ k ∈ range n, (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (1 / 4 : ℝ) ^ (n + 1 + k) := by unfold binomTail refine sum_nbij (fun j => j - (n + 1)) ?_ ?_ ?_ ?_ · intro j hj rcases mem_Icc.mp hj with ⟨h1, h2⟩ exact mem_range.mpr (by omega) · intro j₁ hj₁ j₂ hj₂ heq dsimp only at heq have h1 := (mem_Icc.mp hj₁).1 have h2 := (mem_Icc.mp hj₂).1 omega · intro k hk have hklt := mem_range.mp hk exact ⟨n + 1 + k, mem_Icc.mpr ⟨by omega, by omega⟩, by dsimp only; omega⟩ · intro j hj have h1 := (mem_Icc.mp hj).1 rw [show n + 1 + (j - (n + 1)) = j by omega] have hfirst : (Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1) = ((n : ℝ) / (4 * ((n : ℝ) + 1))) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) := by have h1 := Nat.choose_succ_right_eq (2 * n) n rw [show 2 * n - n = n by omega] at h1 have hcast : (Nat.choose (2 * n) (n + 1) : ℝ) * ((n : ℝ) + 1) = (Nat.choose (2 * n) n : ℝ) * (n : ℝ) := by exact_mod_cast h1 rw [pow_succ] have hne : (n : ℝ) + 1 ≠ 0 := by positivity field_simp [hne] nlinarith have hgeom_eq : (1 / (1 - ρ)) * ((n : ℝ) / (4 * ((n : ℝ) + 1))) = ((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9)) := by have hne1 : 4 * ((n : ℝ) + 2) ≠ 0 := by positivity have hne2 : (n : ℝ) + 1 ≠ 0 := by positivity have hne3 : 3 * (n : ℝ) + 9 ≠ 0 := by positivity have h1mρ : 1 - ρ = (3 * (n : ℝ) + 9) / (4 * ((n : ℝ) + 2)) := by dsimp only [ρ]; field_simp [hne1]; ring rw [h1mρ] field_simp [hne1, hne2, hne3] calc binomTail (2 * n) n (1 / 4 : ℝ) = ∑ k ∈ range n, (Nat.choose (2 * n) (n + 1 + k) : ℝ) * (1 / 4 : ℝ) ^ (n + 1 + k) := hreindex _ ≤ ∑ k ∈ range n, ρ ^ k * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1)) := sum_le_sum fun k _ => hterm k _ = (∑ k ∈ range n, ρ ^ k) * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1)) := (sum_mul ..).symm _ ≤ (1 / (1 - ρ)) * ((Nat.choose (2 * n) (n + 1) : ℝ) * (1 / 4 : ℝ) ^ (n + 1)) := mul_le_mul_of_nonneg_right (hgeo n) (by positivity) _ = ((1 / (1 - ρ)) * ((n : ℝ) / (4 * ((n : ℝ) + 1)))) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) := by rw [hfirst]; ring _ = (((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9))) * ((Nat.choose (2 * n) n : ℝ) * (1 / 4 : ℝ) ^ n) := by rw [hgeom_eq] _ ≤ (((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9))) * (1 / Real.sqrt (3 * (n : ℝ) + 1)) := mul_le_mul_of_nonneg_left (central_binom_bound n) (by positivity) /-- Simplified inverse-sqrt bound: for all `n ≥ 1`, `binomTail (2n) n (1/4) ≤ 1 / (3 * √(3n))`. -/ lemma halving_tail_le_inv_sqrt {n : ℕ} (hn : 1 ≤ n) : binomTail (2 * n) n (1 / 4 : ℝ) ≤ 1 / (3 * Real.sqrt (3 * (n : ℝ))) := by have h1 := halving_tail_le_refined hn have hcoeff : ((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9)) ≤ 1 / 3 := by rw [div_le_div_iff₀ (by positivity) (by norm_num)] nlinarith have hsq : 1 / Real.sqrt (3 * (n : ℝ) + 1) ≤ 1 / Real.sqrt (3 * (n : ℝ)) := by refine one_div_le_one_div_of_le (Real.sqrt_pos.mpr (by positivity)) ?_ exact Real.sqrt_le_sqrt (by linarith) calc binomTail (2 * n) n (1 / 4 : ℝ) ≤ (((n : ℝ) * ((n : ℝ) + 2)) / (((n : ℝ) + 1) * (3 * (n : ℝ) + 9))) * (1 / Real.sqrt (3 * (n : ℝ) + 1)) := h1 _ ≤ (1 / 3 : ℝ) * (1 / Real.sqrt (3 * (n : ℝ))) := mul_le_mul hcoeff hsq (by positivity) (by norm_num) _ = 1 / (3 * Real.sqrt (3 * (n : ℝ))) := by ring /-- Exact finite halving tail values for `m = 1..4` and universal `< 1/15` bound. -/ lemma halving_tail_m1 : binomTail 2 1 (1 / 4 : ℝ) = 1 / 16 := by unfold binomTail rw [show Icc 2 2 = {2} by decide, sum_singleton] norm_num lemma halving_tail_m2 : binomTail 4 2 (1 / 4 : ℝ) = 17 / 256 := by unfold binomTail rw [show Icc 3 4 = {3, 4} by decide] norm_num [sum_pair] lemma halving_tail_m3 : binomTail 8 4 (1 / 4 : ℝ) = 4065 / 65536 := by unfold binomTail rw [show Icc 5 8 = {5, 6, 7, 8} by decide] rw [sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_singleton] have h5 : Nat.choose 8 5 = 56 := by decide have h6 : Nat.choose 8 6 = 28 := by decide have h7 : Nat.choose 8 7 = 8 := by decide have h8 : Nat.choose 8 8 = 1 := by decide rw [h5, h6, h7, h8]; norm_num lemma halving_tail_m4 : binomTail 16 8 (1 / 4 : ℝ) < 525 / 10000 := by unfold binomTail rw [show Icc 9 16 = {9, 10, 11, 12, 13, 14, 15, 16} by decide] rw [sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_singleton] have h9 : Nat.choose 16 9 = 11440 := by decide have h10 : Nat.choose 16 10 = 8008 := by decide have h11 : Nat.choose 16 11 = 4368 := by decide have h12 : Nat.choose 16 12 = 1820 := by decide have h13 : Nat.choose 16 13 = 560 := by decide have h14 : Nat.choose 16 14 = 120 := by decide have h15 : Nat.choose 16 15 = 16 := by decide have h16 : Nat.choose 16 16 = 1 := by decide rw [h9, h10, h11, h12, h13, h14, h15, h16]; norm_num lemma halving_tail_lt_one_fifteenth {m : ℕ} (hm : 1 ≤ m) : binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) < 1 / 15 := by have h2m : 2 ^ m = 2 * 2 ^ (m - 1) := by cases m with | zero => omega | succ m => simp [pow_succ, mul_comm] rw [h2m] by_cases hm1 : m = 1 · subst hm1; simpa using (by rw [halving_tail_m1]; norm_num : binomTail 2 1 (1 / 4 : ℝ) < 1 / 15) by_cases hm2 : m = 2 · subst hm2; simpa using (by rw [halving_tail_m2]; norm_num : binomTail 4 2 (1 / 4 : ℝ) < 1 / 15) by_cases hm3 : m = 3 · subst hm3; simpa using (by rw [halving_tail_m3]; norm_num : binomTail 8 4 (1 / 4 : ℝ) < 1 / 15) by_cases hm4 : m = 4 · subst hm4; simpa using lt_trans halving_tail_m4 (by norm_num : (525 : ℝ) / 10000 < 1 / 15) have hge16 : (16 : ℕ) ≤ 2 ^ (m - 1) := by have : 4 ≤ m - 1 := by omega calc 16 = 2 ^ 4 := by norm_num _ ≤ 2 ^ (m - 1) := Nat.pow_le_pow_right (by omega) this have h1 := halving_tail_le_inv_sqrt (n := 2 ^ (m - 1)) (by omega) have hrt : (5 : ℝ) < Real.sqrt (3 * ((2 ^ (m - 1) : ℕ) : ℝ)) := by rw [← Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 5)] exact Real.sqrt_lt_sqrt (by norm_num) (by have : (16 : ℝ) ≤ (2 ^ (m - 1) : ℕ) := by exact_mod_cast hge16 linarith) have h2 : 1 / (3 * Real.sqrt (3 * ((2 ^ (m - 1) : ℕ) : ℝ))) < 1 / 15 := one_div_lt_one_div_of_lt (by norm_num) (by linarith) linarith /-- Helper: `Real.sqrt (2 ^ j) = (Real.sqrt 2) ^ j`. -/ lemma sqrt_two_pow (j : ℕ) : Real.sqrt ((2 : ℝ) ^ j) = (Real.sqrt 2) ^ j := by induction j with | zero => simp | succ j ih => rw [pow_succ, pow_succ, Real.sqrt_mul (by positivity), ih] /-- Geometric sum bound for `∑_{j=0}^{k-1} (1 / √2)^j ≤ 2 + √2`. -/ lemma sum_inv_sqrt2_pow_le (k : ℕ) : ∑ j ∈ range k, (1 / Real.sqrt 2) ^ j ≤ 2 + Real.sqrt 2 := by have hsq2 : Real.sqrt 2 ^ 2 = 2 := Real.sq_sqrt (by norm_num) have hpos : 0 < Real.sqrt 2 := Real.sqrt_pos.mpr (by norm_num) induction k with | zero => positivity | succ k ih => rw [sum_range_succ'] simp only [pow_zero, pow_succ'] rw [← mul_sum] have h1 : (1 / Real.sqrt 2) * (2 + Real.sqrt 2) = Real.sqrt 2 + 1 := by field_simp [ne_of_gt hpos] nlinarith have hmul : (1 / Real.sqrt 2) * ∑ x ∈ range k, (1 / Real.sqrt 2) ^ x ≤ (1 / Real.sqrt 2) * (2 + Real.sqrt 2) := mul_le_mul_of_nonneg_left ih (by positivity) linarith /-- **Infinite Power-of-Two Halving Tail Sum Bound:** For EVERY `t : ℕ`, `∑_{m=1}^{t} binomTail (2^m) (2^(m-1)) (1/4) < 2/5`. -/ theorem sum_halving_tail_lt_two_fifths (t : ℕ) : ∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) < 2 / 5 := by -- Use exact values for m=1..4, refined bound for m=5,6,7, and geometric series for m ≥ 8! have hm5 : binomTail 32 16 (1 / 4 : ℝ) < 425 / 10000 := by have h := halving_tail_le_refined (n := 16) (by omega) have hrt : Real.sqrt 49 = 7 := by rw [show (49 : ℝ) = 7 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)] norm_num at h rw [hrt] at h linarith have hm6 : binomTail 64 32 (1 / 4 : ℝ) < 3195 / 100000 := by have h := halving_tail_le_refined (n := 32) (by omega) norm_num at h have hrt : (984 / 100 : ℝ) < Real.sqrt 97 := by rw [← Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 984 / 100)] exact Real.sqrt_lt_sqrt (by norm_num) (by norm_num) have hinv : (Real.sqrt 97)⁻¹ < 100 / 984 := by rw [inv_lt_comm₀ (Real.sqrt_pos.mpr (by norm_num)) (by norm_num)] linarith nlinarith have hm7 : binomTail 128 64 (1 / 4 : ℝ) < 233 / 10000 := by have h := halving_tail_le_refined (n := 64) (by omega) norm_num at h have hrt : (1389 / 100 : ℝ) < Real.sqrt 193 := by rw [← Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 1389 / 100)] exact Real.sqrt_lt_sqrt (by norm_num) (by norm_num) have hinv : (Real.sqrt 193)⁻¹ < 100 / 1389 := by rw [inv_lt_comm₀ (Real.sqrt_pos.mpr (by norm_num)) (by norm_num)] linarith nlinarith have htail_ge8 : ∀ r : ℕ, ∑ j ∈ range r, binomTail (2 ^ (8 + j)) (2 ^ (7 + j)) (1 / 4 : ℝ) ≤ (2 + Real.sqrt 2) / (3 * Real.sqrt 384) := by intro r have hterm : ∀ j : ℕ, binomTail (2 ^ (8 + j)) (2 ^ (7 + j)) (1 / 4 : ℝ) ≤ (1 / (3 * Real.sqrt 384)) * (1 / Real.sqrt 2) ^ j := by intro j have h2 : 2 ^ (8 + j) = 2 * 2 ^ (7 + j) := by rw [show 8 + j = (7 + j) + 1 by omega, pow_succ]; ring rw [h2] have h1 := halving_tail_le_inv_sqrt (n := 2 ^ (7 + j)) (Nat.one_le_pow _ _ (by omega)) have hcast : (3 * ((2 ^ (7 + j) : ℕ) : ℝ)) = 384 * (2 : ℝ) ^ j := by push_cast; rw [pow_add]; ring rw [hcast, Real.sqrt_mul (by norm_num), sqrt_two_pow] at h1 calc binomTail (2 * 2 ^ (7 + j)) (2 ^ (7 + j)) (1 / 4 : ℝ) ≤ 1 / (3 * (Real.sqrt 384 * Real.sqrt 2 ^ j)) := h1 _ = (1 / (3 * Real.sqrt 384)) * (1 / Real.sqrt 2) ^ j := by rw [one_div_pow]; ring calc ∑ j ∈ range r, binomTail (2 ^ (8 + j)) (2 ^ (7 + j)) (1 / 4 : ℝ) ≤ ∑ j ∈ range r, (1 / (3 * Real.sqrt 384)) * (1 / Real.sqrt 2) ^ j := sum_le_sum fun j _ => hterm j _ = (1 / (3 * Real.sqrt 384)) * ∑ j ∈ range r, (1 / Real.sqrt 2) ^ j := (mul_sum ..).symm _ ≤ (1 / (3 * Real.sqrt 384)) * (2 + Real.sqrt 2) := mul_le_mul_of_nonneg_left (sum_inv_sqrt2_pow_le r) (by positivity) _ = (2 + Real.sqrt 2) / (3 * Real.sqrt 384) := by ring have hge8_num : (2 + Real.sqrt 2) / (3 * Real.sqrt 384) < 582 / 10000 := by have hrt2 : Real.sqrt 2 < 1415 / 1000 := by rw [← Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 1415 / 1000)] exact Real.sqrt_lt_sqrt (by norm_num) (by norm_num) have hrt384 : (1959 / 100 : ℝ) < Real.sqrt 384 := by rw [← Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 1959 / 100)] exact Real.sqrt_lt_sqrt (by norm_num) (by norm_num) rw [div_lt_iff₀ (by positivity)] nlinarith have hnonneg : ∀ m, 0 ≤ binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) := fun m => binomTail_nonneg (by norm_num) have hfirst7 : ∑ m ∈ Icc 1 7, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) < 3412 / 10000 := by have hsplit : ∑ m ∈ Icc 1 7, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) = binomTail 2 1 (1 / 4) + binomTail 4 2 (1 / 4) + binomTail 8 4 (1 / 4) + binomTail 16 8 (1 / 4) + binomTail 32 16 (1 / 4) + binomTail 64 32 (1 / 4) + binomTail 128 64 (1 / 4) := by rw [show Icc 1 7 = {1, 2, 3, 4, 5, 6, 7} by decide] rw [sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_insert (by decide), sum_singleton] norm_num; ring rw [hsplit, halving_tail_m1, halving_tail_m2, halving_tail_m3] linarith [halving_tail_m4, hm5, hm6, hm7] by_cases ht7 : t ≤ 7 · calc ∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) ≤ ∑ m ∈ Icc 1 7, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) := sum_le_sum_of_subset_of_nonneg (Icc_subset_Icc_right ht7) (fun m _ _ => hnonneg m) _ < 3412 / 10000 := hfirst7 _ < 2 / 5 := by norm_num · have hsplit : Icc 1 t = Icc 1 7 ∪ Icc 8 t := by ext m; simp only [mem_Icc, mem_union]; omega have hdisj : Disjoint (Icc 1 7) (Icc 8 t) := by rw [disjoint_left]; intro m hm1 hm2 have := (mem_Icc.mp hm1).2; have := (mem_Icc.mp hm2).1; omega have htail_eq : ∑ m ∈ Icc 8 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) = ∑ j ∈ range (t - 7), binomTail (2 ^ (8 + j)) (2 ^ (7 + j)) (1 / 4 : ℝ) := by refine sum_nbij (fun m => m - 8) ?_ ?_ ?_ ?_ · intro m hm; rcases mem_Icc.mp hm with ⟨h1, h2⟩; exact mem_range.mpr (by omega) · intro m₁ hm₁ m₂ hm₂ heq dsimp only at heq have := (mem_Icc.mp hm₁).1; have := (mem_Icc.mp hm₂).1; omega · intro j hj; have := mem_range.mp hj exact ⟨8 + j, mem_Icc.mpr ⟨by omega, by omega⟩, by dsimp only; omega⟩ · intro m hm have h1 := (mem_Icc.mp hm).1 rw [show 8 + (m - 8) = m by omega, show 7 + (m - 8) = m - 1 by omega] rw [hsplit, sum_union hdisj, htail_eq] linarith [hfirst7, htail_ge8 (t - 7), hge8_num] /-- Power-of-two halving schedule `[(2^(t-1), q), (2^(t-2), q), ..., (1, q)]`. -/ def halvingSchedule (t : ℕ) (q : ℝ) : List (ℕ × ℝ) := match t with | 0 => [] | t' + 1 => (2 ^ t', q) :: halvingSchedule t' q lemma halvingSchedule_last (t : ℕ) (q : ℝ) : ((halvingSchedule t q).getLast?.map Prod.fst).getD (2 ^ t) = 1 := by induction t with | zero => simp [halvingSchedule] | succ t ih => cases t with | zero => simp [halvingSchedule] | succ t' => change (((2 ^ (t' + 1), q) :: halvingSchedule (t' + 1) q).getLast?.map Prod.fst).getD _ = 1 have hne : halvingSchedule (t' + 1) q ≠ [] := by simp [halvingSchedule] rw [List.getLast?_cons_of_ne_nil hne] have hne' : (halvingSchedule (t' + 1) q).getLast? ≠ none := by rw [ne_eq, List.getLast?_eq_none_iff]; exact hne cases h : (halvingSchedule (t' + 1) q).getLast? with | none => exact absurd h hne' | some p => rw [h] at ih simpa using ih lemma halvingSchedule_mem_snd {t : ℕ} {q : ℝ} {p : ℕ × ℝ} (hp : p ∈ halvingSchedule t q) : p.2 = q := by induction t with | zero => simp [halvingSchedule] at hp | succ t ih => simp only [halvingSchedule, List.mem_cons] at hp rcases hp with rfl | hrest · rfl · exact ih hrest lemma halvingSchedule_sum_snd (t : ℕ) (q : ℝ) : ((halvingSchedule t q).map Prod.snd).sum = (t : ℝ) * q := by induction t with | zero => simp [halvingSchedule] | succ t ih => simp only [halvingSchedule, List.map_cons, List.sum_cons, ih, Nat.cast_succ] ring lemma halvingSchedule_tailSum (R q : ℝ) (t : ℕ) : scheduleTailSum R (2 ^ t) (halvingSchedule t q) = ∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) ((1 - q) / (q * R)) := by induction t with | zero => simp [halvingSchedule, scheduleTailSum] | succ t ih => simp only [halvingSchedule, scheduleTailSum, ih] rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ t + 1)] simp only [Nat.add_sub_cancel] ring /-- Elementary inequality: for `x ≥ 0` and `R > 0`, if `q = min 1 (x / R)` then `(1 - q)^R ≤ exp(-x)`. -/ lemma one_sub_min_rpow_le_exp {x R : ℝ} (hR : 0 < R) : (1 - min 1 (x / R)) ^ R ≤ Real.exp (-x) := by by_cases hxr : x / R ≤ 1 · rw [min_eq_right hxr] have h1 : 1 - x / R ≤ Real.exp (-(x / R)) := by have := Real.add_one_le_exp (-(x / R)) linarith have hnonneg : 0 ≤ 1 - x / R := by linarith calc (1 - x / R) ^ R ≤ (Real.exp (-(x / R))) ^ R := Real.rpow_le_rpow hnonneg h1 (le_of_lt hR) _ = Real.exp (-(x / R) * R) := (Real.exp_mul _ _).symm _ = Real.exp (-x) := by congr 1; field_simp [ne_of_gt hR] · push Not at hxr rw [min_eq_left (le_of_lt hxr), sub_self, Real.zero_rpow (ne_of_gt hR)] exact le_of_lt (Real.exp_pos _) /-- **Theorem 3a (Exact Sharp `k = 1` Spread Lemma):** For any `R`-spread probability measure `μ` on sets of size `≤ 1` (`μ.totalMass = 1`), `missProb U p μ.supp ≤ exp(-(p * R))`. -/ theorem spread_lemma_singleton_sharp {U : Finset α} {R p : ℝ} (hR : 0 < R) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R 1) (hM1 : μ.totalMass = 1) : missProb U p μ.supp ≤ Real.exp (-(p * R)) := by have h1 := singleton_miss_bound hR hp0 hp1 μ (le_of_eq hM1) rw [hM1, sub_self, mul_zero, add_zero] at h1 have h2 : (1 - p) ^ R ≤ Real.exp (-(p * R)) := by have hle : p = min 1 ((p * R) / R) := by have : (p * R) / R = p := by field_simp [ne_of_gt hR] rw [this, min_eq_right hp1] calc (1 - p) ^ R = (1 - min 1 ((p * R) / R)) ^ R := by rw [← hle] _ ≤ Real.exp (-(p * R)) := one_sub_min_rpow_le_exp hR exact h1.trans h2 /-- **Theorem 3 (Sharp Non-Asymptotic Half-Failure Spread Lemma):** For EVERY `k ≥ 1`, EVERY `R > 0`, EVERY `R`-spread probability measure `μ` on subsets of `U` of size `≤ k` (`μ.totalMass = 1`), and EVERY `p ∈ (0, 1]`: if `p ≥ (4 * ⌈log₂ k⌉ + ln 6) / R`, then `missProb U p μ.supp < 1 / 2` (equivalently `hitProb U p μ.supp > 1 / 2`). -/ theorem spread_lemma_half {U : Finset α} {R p : ℝ} {k : ℕ} (hR : 0 < R) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R k) (hM1 : μ.totalMass = 1) (hp : (4 * (Nat.clog 2 k : ℝ) + Real.log 6) / R ≤ p) : missProb U p μ.supp < 1 / 2 := by set t : ℕ := Nat.clog 2 k have hk_le : k ≤ 2 ^ t := Nat.le_pow_clog (by omega : 1 < 2) k set μ' : SubspreadMeasure U R (2 ^ t) := μ.weaken hk_le have hM1' : μ'.totalMass = 1 := hM1 set q : ℝ := 1 / (1 + R / 4) have hq0 : 0 < q := by positivity have hq1 : q < 1 := by dsimp only [q] rw [div_lt_one (by positivity)] linarith have hxq : (1 - q) / (q * R) = 1 / 4 := by dsimp only [q] have hden : 1 + R / 4 ≠ 0 := by positivity field_simp [hden, ne_of_gt hR] ring have hq_le : q ≤ 4 / R := by dsimp only [q] rw [div_le_div_iff₀ (by positivity) hR] linarith set qStar : ℝ := min 1 (Real.log 6 / R) have hlog6_pos : 0 < Real.log 6 := Real.log_pos (by norm_num) have hqS0 : 0 ≤ qStar := by positivity have hqS1 : qStar ≤ 1 := min_le_left _ _ have hqS_le : qStar ≤ Real.log 6 / R := min_le_right _ _ have hcomb_mem : 0 ≤ combinedProb ((halvingSchedule t q).map Prod.snd) qStar ∧ combinedProb ((halvingSchedule t q).map Prod.snd) qStar ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro r hr rcases List.mem_map.mp hr with ⟨pr, hpr, rfl⟩ rw [halvingSchedule_mem_snd hpr] exact ⟨le_of_lt hq0, le_of_lt hq1⟩ have hcomb_le_p : combinedProb ((halvingSchedule t q).map Prod.snd) qStar ≤ p := by have hsum := combinedProb_le_sum (qs := (halvingSchedule t q).map Prod.snd) (qStar := qStar) (by intro r hr rcases List.mem_map.mp hr with ⟨pr, hpr, rfl⟩ rw [halvingSchedule_mem_snd hpr] exact ⟨le_of_lt hq0, le_of_lt hq1⟩) hqS0 hqS1 rw [halvingSchedule_sum_snd] at hsum have h1 : (t : ℝ) * q + qStar ≤ (4 * (t : ℝ) + Real.log 6) / R := by have htq : (t : ℝ) * q ≤ (t : ℝ) * (4 / R) := mul_le_mul_of_nonneg_left hq_le (Nat.cast_nonneg t) calc (t : ℝ) * q + qStar ≤ (t : ℝ) * (4 / R) + Real.log 6 / R := add_le_add htq hqS_le _ = (4 * (t : ℝ) + Real.log 6) / R := by ring exact hsum.trans (h1.trans hp) have hmulti := multi_round_spread_bound hR hqS0 hqS1 (halvingSchedule t q) (2 ^ t) (halvingSchedule_last t q) (fun pr hpr => by rw [halvingSchedule_mem_snd hpr]; exact ⟨hq0, hq1⟩) μ' (le_of_eq hM1') rw [hM1', sub_self, zero_add, halvingSchedule_tailSum, hxq] at hmulti have htail_lt : ∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) < 2 / 5 := sum_halving_tail_lt_two_fifths t have ha_le : (1 - qStar) ^ R ≤ 1 / 6 := by calc (1 - qStar) ^ R ≤ Real.exp (-(Real.log 6)) := one_sub_min_rpow_le_exp hR _ = 1 / 6 := by rw [Real.exp_neg, Real.exp_log (by norm_num)]; ring have ha_nonneg : 0 ≤ (1 - qStar) ^ R := Real.rpow_nonneg (by linarith) R have h1a_pos : 0 < 1 - (1 - qStar) ^ R := by linarith have hanti : missProb U p μ.supp ≤ missProb U (combinedProb ((halvingSchedule t q).map Prod.snd) qStar) μ'.supp := missProb_antitone hcomb_mem.1 hcomb_le_p hp1 μ.supp calc missProb U p μ.supp ≤ missProb U (combinedProb ((halvingSchedule t q).map Prod.snd) qStar) μ'.supp := hanti _ ≤ (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ)) := hmulti _ < (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (2 / 5) := by nlinarith _ ≤ 1 / 6 + (1 - 1 / 6) * (2 / 5) := by linarith _ = 1 / 2 := by norm_num /-- **Corollary 3b (Clean `4 log₂(3k)` Spread Lemma — Strictly Beating Tran–Vu 2023's `4 log₂(7k)`):** -/ theorem spread_lemma_half_log2_3k {U : Finset α} {R p : ℝ} {k : ℕ} (hk : 1 ≤ k) (hR : 0 < R) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R k) (hM1 : μ.totalMass = 1) (hp : 4 * Real.logb 2 (3 * (k : ℝ)) / R ≤ p) : missProb U p μ.supp < 1 / 2 := by have hk_pos : (0 : ℝ) < (k : ℝ) := by positivity have hclog_lt : (Nat.clog 2 k : ℝ) < Real.logb 2 (k : ℝ) + 1 := by by_cases hk1 : k = 1 · subst hk1; simp · have hclog_pos : 1 ≤ Nat.clog 2 k := by have := Nat.clog_pos (by omega : 1 < 2) (by omega : 1 < k) omega have hpow_lt : 2 ^ (Nat.clog 2 k - 1) < k := Nat.pow_pred_clog_lt_self (by omega : 1 < 2) (by omega : 1 < k) have hcast : ((2 : ℝ) ^ (Nat.clog 2 k - 1)) < (k : ℝ) := by exact_mod_cast hpow_lt have hlog : Real.logb 2 ((2 : ℝ) ^ (Nat.clog 2 k - 1)) < Real.logb 2 (k : ℝ) := Real.logb_lt_logb (by norm_num) (by positivity) hcast rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog have hsub : ((Nat.clog 2 k - 1 : ℕ) : ℝ) = (Nat.clog 2 k : ℝ) - 1 := by rw [Nat.cast_sub hclog_pos, Nat.cast_one] linarith have hln6_lt2 : Real.log 6 < 2 := by have he : (2.7182818283 : ℝ) < Real.exp 1 := Real.exp_one_gt_d9 have h6 : (6 : ℝ) < Real.exp 2 := by have : Real.exp 2 = Real.exp 1 * Real.exp 1 := by rw [← Real.exp_add]; norm_num rw [this]; nlinarith calc Real.log 6 < Real.log (Real.exp 2) := Real.log_lt_log (by norm_num) h6 _ = 2 := Real.log_exp 2 have h4log3 : (6 : ℝ) < 4 * Real.logb 2 3 := by have hpow : ((2 : ℝ) ^ 6) < (3 : ℝ) ^ 4 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog linarith have hlog_mul : Real.logb 2 (3 * (k : ℝ)) = Real.logb 2 3 + Real.logb 2 (k : ℝ) := Real.logb_mul (by norm_num) (ne_of_gt hk_pos) have hbound : (4 * (Nat.clog 2 k : ℝ) + Real.log 6) / R ≤ 4 * Real.logb 2 (3 * (k : ℝ)) / R := by rw [div_le_div_iff_of_pos_right hR, hlog_mul] linarith exact spread_lemma_half hR hp1 μ hM1 (hbound.trans hp) end HalvingAndHalfSpread section SubFourSpread variable {α : Type*} [DecidableEq α] /-- Elementary Chernoff upper bound on the upper binomial tail: for `λ ≥ 1` and `x ≥ 0`, `λ ^ (ℓ' + 1) * binomTail ℓ ℓ' x ≤ (1 + λ * x) ^ ℓ`. -/ lemma chernoff_binomTail_mul_le {ℓ ℓ' : ℕ} {lam x : ℝ} (hlam : 1 ≤ lam) (hx : 0 ≤ x) : lam ^ (ℓ' + 1) * binomTail ℓ ℓ' x ≤ (1 + lam * x) ^ ℓ := by unfold binomTail rw [mul_sum] calc ∑ j ∈ Icc (ℓ' + 1) ℓ, lam ^ (ℓ' + 1) * ((Nat.choose ℓ j : ℝ) * x ^ j) ≤ ∑ j ∈ Icc (ℓ' + 1) ℓ, (Nat.choose ℓ j : ℝ) * (lam * x) ^ j := by refine sum_le_sum fun j hj => ?_ have hj1 : ℓ' + 1 ≤ j := (mem_Icc.mp hj).1 rw [mul_pow] have hpow : lam ^ (ℓ' + 1) ≤ lam ^ j := pow_le_pow_right₀ hlam hj1 have hnonneg : 0 ≤ (Nat.choose ℓ j : ℝ) * x ^ j := by positivity nlinarith _ ≤ ∑ j ∈ range (ℓ + 1), (Nat.choose ℓ j : ℝ) * (lam * x) ^ j := by refine sum_le_sum_of_subset_of_nonneg ?_ (fun j _ _ => by positivity) intro j hj exact mem_range.mpr (by have := (mem_Icc.mp hj).2; omega) _ = (lam * x + 1) ^ ℓ := by rw [add_pow] refine sum_congr rfl fun j _ => by simp [mul_comm] _ = (1 + lam * x) ^ ℓ := by ring /-- Exact rational Chernoff base for `θ = 12/25` and `x₀ = 4727/20000`: `((13 * x₀ / 12)^12 * (25/13)^25) < 9994/10000`. -/ lemma sub4_base25_lt : ((13 : ℝ) * (4727 / 20000) / 12) ^ 12 * (25 / 13 : ℝ) ^ 25 < 9994 / 10000 := by norm_num /-- Exact rational power witness `(25/12)^17 > 2^18`, proving `(20000/4727) / log₂(25/12) < 3.99596`. -/ lemma sub4_const_lt_tight : (20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ) < 3.99596 := by have hpow : (2 : ℝ) ^ 18 < (25 / 12 : ℝ) ^ 17 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog have hlog_pos : 0 < Real.logb 2 (25 / 12 : ℝ) := by linarith rw [div_lt_iff₀ hlog_pos] linarith /-- Exact rational power witness `(25/12)^17 > 2^18`, proving `(20000/4727) / log₂(25/12) < 3.996`. -/ lemma sub4_const_lt : (20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ) < 3.996 := sub4_const_lt_tight.trans (by norm_num) /-- One-step tail bound at `θ = 12/25`, `x₀ = 4727/20000`: for all `ℓ`, `binomTail ℓ (12 * ℓ / 25) (4727/20000) ≤ (9994/10000)^((ℓ : ℝ) / 25)`. -/ lemma sub4_one_step_tail_le (ℓ : ℕ) : binomTail ℓ (12 * ℓ / 25) (4727 / 20000 : ℝ) ≤ (9994 / 10000 : ℝ) ^ ((ℓ : ℝ) / 25) := by set x₀ : ℝ := 4727 / 20000 set lam : ℝ := (12 / 13 : ℝ) / x₀ have hlam_gt1 : 1 ≤ lam := by dsimp only [lam, x₀]; norm_num have hlam_pos : 0 < lam := by linarith have h1lx : 1 + lam * x₀ = 25 / 13 := by dsimp only [lam, x₀]; norm_num have hx₀_nn : (0 : ℝ) ≤ x₀ := by dsimp only [x₀]; norm_num have hch := chernoff_binomTail_mul_le (ℓ := ℓ) (ℓ' := 12 * ℓ / 25) hlam_gt1 hx₀_nn rw [h1lx] at hch have hexp_le : (12 : ℝ) * (ℓ : ℝ) / 25 ≤ ((12 * ℓ / 25 + 1 : ℕ) : ℝ) := by have hnat : 12 * ℓ < 25 * (12 * ℓ / 25 + 1) := by omega have hcast : (12 : ℝ) * (ℓ : ℝ) < 25 * ((12 * ℓ / 25 + 1 : ℕ) : ℝ) := by exact_mod_cast hnat linarith have hlam_rpow : lam ^ ((12 : ℝ) * (ℓ : ℝ) / 25) ≤ lam ^ (12 * ℓ / 25 + 1) := by rw [← Real.rpow_natCast] exact Real.rpow_le_rpow_of_exponent_le hlam_gt1 hexp_le have hbt_nonneg : 0 ≤ binomTail ℓ (12 * ℓ / 25) x₀ := binomTail_nonneg hx₀_nn have hmul : lam ^ ((12 : ℝ) * (ℓ : ℝ) / 25) * binomTail ℓ (12 * ℓ / 25) x₀ ≤ (25 / 13 : ℝ) ^ ℓ := (mul_le_mul_of_nonneg_right hlam_rpow hbt_nonneg).trans hch have hlam_rpow_pos : 0 < lam ^ ((12 : ℝ) * (ℓ : ℝ) / 25) := Real.rpow_pos_of_pos hlam_pos _ rw [← le_div_iff₀' hlam_rpow_pos] at hmul have hbase_eq : ((25 / 13 : ℝ) ^ ℓ) / lam ^ ((12 : ℝ) * (ℓ : ℝ) / 25) = (((13 : ℝ) * x₀ / 12) ^ 12 * (25 / 13 : ℝ) ^ 25) ^ ((ℓ : ℝ) / 25) := by have h1 : (25 / 13 : ℝ) ^ ℓ = ((25 / 13 : ℝ) ^ 25) ^ ((ℓ : ℝ) / 25) := by rw [← Real.rpow_natCast (25 / 13 : ℝ) 25, ← Real.rpow_mul (by norm_num)] rw [show ((25 : ℕ) : ℝ) * ((ℓ : ℝ) / 25) = (ℓ : ℝ) by push_cast; ring, Real.rpow_natCast] have h2 : lam ^ ((12 : ℝ) * (ℓ : ℝ) / 25) = (lam ^ 12) ^ ((ℓ : ℝ) / 25) := by rw [← Real.rpow_natCast lam 12, ← Real.rpow_mul (le_of_lt hlam_pos)] congr 1; norm_num; ring rw [h1, h2, ← Real.div_rpow (by positivity) (by positivity)] congr 1 dsimp only [lam] field_simp [ne_of_gt hlam_pos] rw [hbase_eq] at hmul calc binomTail ℓ (12 * ℓ / 25) x₀ ≤ (((13 : ℝ) * x₀ / 12) ^ 12 * (25 / 13 : ℝ) ^ 25) ^ ((ℓ : ℝ) / 25) := hmul _ ≤ (9994 / 10000 : ℝ) ^ ((ℓ : ℝ) / 25) := Real.rpow_le_rpow (by dsimp only [x₀]; positivity) (le_of_lt sub4_base25_lt) (by positivity) /-- Build the `θ = 12/25` contraction schedule from `k` down while `k > L₀`. -/ def sub4Steps (L₀ : ℕ) (q₀ : ℝ) : ℕ → List (ℕ × ℝ) | 0 => [] | k + 1 => if k + 1 ≤ L₀ then [] else have : 12 * (k + 1) / 25 < k + 1 := by omega (12 * (k + 1) / 25, q₀) :: sub4Steps L₀ q₀ (12 * (k + 1) / 25) /-- Final size after `sub4Steps L₀ q₀ k`. -/ def sub4End (L₀ : ℕ) : ℕ → ℕ | 0 => 0 | k + 1 => if k + 1 ≤ L₀ then k + 1 else have : 12 * (k + 1) / 25 < k + 1 := by omega sub4End L₀ (12 * (k + 1) / 25) lemma sub4End_le (L₀ k : ℕ) : sub4End L₀ k ≤ L₀ := by induction k using Nat.strong_induction_on with | h k ih => cases k with | zero => simp [sub4End] | succ k' => rw [sub4End] split_ifs with hle · exact hle · exact ih _ (by omega) lemma sub4Steps_mem_snd {L₀ k : ℕ} {q₀ : ℝ} {p : ℕ × ℝ} (hp : p ∈ sub4Steps L₀ q₀ k) : p.2 = q₀ := by induction k using Nat.strong_induction_on with | h k ih => cases k with | zero => simp [sub4Steps] at hp | succ k' => rw [sub4Steps] at hp split_ifs at hp with hle · simp at hp · simp only [List.mem_cons] at hp rcases hp with rfl | hrest · rfl · exact ih _ (by omega) hrest /-- Exact upper bound on the number of `θ = 12/25` contraction steps: if `k ≥ 1`, then `(25/12) ^ (sub4Steps L₀ q₀ k).length ≤ (25/12) * k`. -/ lemma sub4Steps_pow_le {L₀ k : ℕ} (hL₀ : 25 ≤ L₀) (hk : 1 ≤ k) (q₀ : ℝ) : ((25 / 12 : ℝ) ^ (sub4Steps L₀ q₀ k).length) ≤ (25 / 12 : ℝ) * (k : ℝ) := by have hstrong : ∀ m : ℕ, 1 ≤ m → ((25 / 12 : ℝ) ^ (sub4Steps L₀ q₀ m).length) * (min m L₀ : ℝ) ≤ (25 / 12 : ℝ) * (m : ℝ) := by intro m induction m using Nat.strong_induction_on with | h m ih => intro hm cases m with | zero => omega | succ m' => rw [sub4Steps] split_ifs with hle · simp only [List.length_nil, pow_zero, one_mul] have hmin : min ((m' + 1 : ℕ) : ℝ) (L₀ : ℝ) = ((m' + 1 : ℕ) : ℝ) := min_eq_left (by exact_mod_cast hle) rw [hmin] have hpos : (0 : ℝ) ≤ ((m' + 1 : ℕ) : ℝ) := Nat.cast_nonneg _ nlinarith · simp only [List.length_cons, pow_succ] set m₁ := 12 * (m' + 1) / 25 have hm₁_pos : 1 ≤ m₁ := by omega have hm₁_lt : m₁ < m' + 1 := by omega have hih := ih m₁ hm₁_lt hm₁_pos have hm₁_le : (m₁ : ℝ) ≤ (12 / 25 : ℝ) * ((m' + 1 : ℕ) : ℝ) := by have hnat : 25 * m₁ ≤ 12 * (m' + 1) := Nat.mul_div_le (12 * (m' + 1)) 25 have hcast : (25 : ℝ) * (m₁ : ℝ) ≤ 12 * ((m' + 1 : ℕ) : ℝ) := by exact_mod_cast hnat linarith have hmin_m : min ((m' + 1 : ℕ) : ℝ) (L₀ : ℝ) = (L₀ : ℝ) := min_eq_right (by exact_mod_cast (show L₀ ≤ m' + 1 by omega)) by_cases hm₁_L : m₁ ≤ L₀ · have hsteps0 : sub4Steps L₀ q₀ m₁ = [] := by cases hm₁_eq : m₁ with | zero => omega | succ r => rw [sub4Steps, if_pos (by omega)] rw [hsteps0, List.length_nil, pow_zero, one_mul, hmin_m] have hLlt : (L₀ : ℝ) ≤ ((m' + 1 : ℕ) : ℝ) := by exact_mod_cast (show L₀ ≤ m' + 1 by omega) nlinarith · have hmin_m₁ : min (m₁ : ℝ) (L₀ : ℝ) = (L₀ : ℝ) := min_eq_right (by exact_mod_cast (show L₀ ≤ m₁ by omega)) rw [hmin_m₁] at hih rw [hmin_m] calc ((25 / 12 : ℝ) ^ (sub4Steps L₀ q₀ m₁).length * (25 / 12)) * (L₀ : ℝ) = (25 / 12 : ℝ) * (((25 / 12 : ℝ) ^ (sub4Steps L₀ q₀ m₁).length) * (L₀ : ℝ)) := by ring _ ≤ (25 / 12 : ℝ) * ((25 / 12 : ℝ) * (m₁ : ℝ)) := by nlinarith _ ≤ (25 / 12 : ℝ) * ((25 / 12 : ℝ) * ((12 / 25 : ℝ) * ((m' + 1 : ℕ) : ℝ))) := by nlinarith _ = (25 / 12 : ℝ) * ((m' + 1 : ℕ) : ℝ) := by ring have h1 := hstrong k hk have hmin_ge1 : (1 : ℝ) ≤ (min k L₀ : ℝ) := by have : 1 ≤ min k L₀ := le_min hk (by omega) exact_mod_cast this have hpow_nonneg : 0 ≤ (25 / 12 : ℝ) ^ (sub4Steps L₀ q₀ k).length := by positivity nlinarith /-- Binomial tail sum along the `θ = 12/25` contraction phase down to threshold `L₀`. -/ noncomputable def sub4TailSum (L₀ : ℕ) (x : ℝ) : ℕ → ℝ | 0 => 0 | m + 1 => if m + 1 ≤ L₀ then 0 else have : 12 * (m + 1) / 25 < m + 1 := by omega binomTail (m + 1) (12 * (m + 1) / 25) x + sub4TailSum L₀ x (12 * (m + 1) / 25) /-- Helper: `(9994 / 10000)^n ≤ exp(-6 * n / 10000)`. -/ lemma sub4_decay_le_exp (n : ℕ) : (9994 / 10000 : ℝ) ^ n ≤ Real.exp (-(6 * (n : ℝ) / 10000)) := by have h1 : (9994 / 10000 : ℝ) ≤ Real.exp (-(6 / 10000 : ℝ)) := by have := Real.add_one_le_exp (-(6 / 10000 : ℝ)) linarith calc (9994 / 10000 : ℝ) ^ n ≤ (Real.exp (-(6 / 10000 : ℝ))) ^ n := pow_le_pow_left₀ (by norm_num) h1 n _ = Real.exp ((n : ℝ) * (-(6 / 10000 : ℝ))) := (Real.exp_nat_mul _ n).symm _ = Real.exp (-(6 * (n : ℝ) / 10000)) := by congr 1; ring /-- Inductive tail bound: for any `L₀ ≥ 250000`, `sub4TailSum L₀ (4727/20000) k ≤ 2 * (9994/10000)^(L₀ / 25)` for ALL `k : ℕ`. -/ lemma sub4TailSum_le {L₀ : ℕ} (hL₀ : 250000 ≤ L₀) (k : ℕ) : sub4TailSum L₀ (4727 / 20000 : ℝ) k ≤ 2 * (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) := by let g : ℕ → ℝ := fun m => (9994 / 10000 : ℝ) ^ ((m : ℝ) / 25) have hg_pos : ∀ m, 0 < g m := fun m => Real.rpow_pos_of_pos (by norm_num) _ have hg_anti : ∀ a b, a ≤ b → g b ≤ g a := fun a b hab => Real.rpow_le_rpow_of_exponent_ge (by norm_num) (by norm_num) (by have : (a : ℝ) ≤ (b : ℝ) := by exact_mod_cast hab linarith) have hg_L₀_le_half : g L₀ ≤ 1 / 2 := by have h1 : g L₀ ≤ g 250000 := hg_anti 250000 L₀ hL₀ set P : ℝ := (9994 / 10000 : ℝ) ^ (10000 : ℕ) have h2 : g 250000 = P := by dsimp only [g, P] have hdiv : ((250000 : ℕ) : ℝ) / 25 = ((10000 : ℕ) : ℝ) := by norm_num rw [hdiv, Real.rpow_natCast] have h3 : P ≤ Real.exp (-6) := by have h := sub4_decay_le_exp 10000 have harg : -(6 * ((10000 : ℕ) : ℝ) / 10000) = (-6 : ℝ) := by norm_num rw [harg] at h exact h have h4 : Real.exp (-6) ≤ 1 / 2 := by rw [Real.exp_neg, inv_le_comm₀ (Real.exp_pos 6) (by norm_num)] have he : (2 : ℝ) ≤ Real.exp 1 := by linarith [Real.exp_one_gt_d9] have h26 : (1 / 2 : ℝ)⁻¹ ≤ (Real.exp 1) ^ 6 := by calc (1 / 2 : ℝ)⁻¹ = 2 := by norm_num _ ≤ 2 ^ 6 := by norm_num _ ≤ (Real.exp 1) ^ 6 := pow_le_pow_left₀ (by norm_num) he 6 have hexp6 : (Real.exp 1) ^ 6 = Real.exp 6 := by rw [← Real.exp_nat_mul]; norm_num linarith exact h1.trans (h2.symm ▸ h3.trans h4) have hstrong : ∀ m : ℕ, L₀ < m → sub4TailSum L₀ (4727 / 20000 : ℝ) m ≤ 2 * g L₀ - g m := by intro m induction m using Nat.strong_induction_on with | h m ih => intro hm cases m with | zero => omega | succ m' => rw [sub4TailSum, if_neg (by omega)] set m₁ := 12 * (m' + 1) / 25 have htail : binomTail (m' + 1) m₁ (4727 / 20000 : ℝ) ≤ g (m' + 1) := sub4_one_step_tail_le (m' + 1) by_cases hm₁ : m₁ ≤ L₀ · have hzero : sub4TailSum L₀ (4727 / 20000 : ℝ) m₁ = 0 := by cases hm₁_eq : m₁ with | zero => simp [sub4TailSum] | succ r => rw [sub4TailSum, if_pos (by omega)] rw [hzero, add_zero] have hle : g (m' + 1) ≤ g L₀ := hg_anti L₀ (m' + 1) (by omega) linarith · have hih := ih m₁ (by omega) (by omega) have h2m₁ : 2 * m₁ ≤ m' + 1 := by omega have hgm_le : g (m' + 1) ≤ g m₁ * g m₁ := by calc g (m' + 1) ≤ g (2 * m₁) := hg_anti _ _ h2m₁ _ = g m₁ * g m₁ := by dsimp only [g] rw [← Real.rpow_add (by norm_num)] congr 1; push_cast; ring have hgm₁_half : g m₁ ≤ 1 / 2 := (hg_anti L₀ m₁ (by omega)).trans hg_L₀_le_half have h2g : 2 * g (m' + 1) ≤ g m₁ := by nlinarith [hg_pos m₁] linarith by_cases hk : k ≤ L₀ · have hzero : sub4TailSum L₀ (4727 / 20000 : ℝ) k = 0 := by cases k with | zero => simp [sub4TailSum] | succ r => rw [sub4TailSum, if_pos hk] rw [hzero] have hg0 := hg_pos L₀ dsimp only [g] at hg0 linarith · have hres := hstrong k (by omega) dsimp only [g] at hres have hgk := hg_pos k dsimp only [g] at hgk linarith /-- Concatenate `sub4Steps` with any tail schedule and relate `scheduleTailSum`. -/ lemma scheduleTailSum_sub4_append {R q₀ : ℝ} (L₀ k : ℕ) (rest : List (ℕ × ℝ)) : scheduleTailSum R k (sub4Steps L₀ q₀ k ++ rest) = sub4TailSum L₀ ((1 - q₀) / (q₀ * R)) k + scheduleTailSum R (sub4End L₀ k) rest := by induction k using Nat.strong_induction_on with | h k ih => cases k with | zero => simp [sub4Steps, sub4TailSum, sub4End] | succ k' => rw [sub4Steps, sub4TailSum, sub4End] split_ifs with hle · simp · simp only [List.cons_append, scheduleTailSum] rw [ih _ (by omega)] ring lemma scheduleTailSum_mono_k₀ {R : ℝ} {k₁ k₂ : ℕ} (h12 : k₁ ≤ k₂) {sched : List (ℕ × ℝ)} (hqs : ∀ p ∈ sched, 0 < p.2 ∧ p.2 < 1) (hR : 0 < R) : scheduleTailSum R k₁ sched ≤ scheduleTailSum R k₂ sched := by cases sched with | nil => simp [scheduleTailSum] | cons hd tl => simp only [scheduleTailSum] have hq := hqs hd (List.mem_cons_self ..) have hx : 0 ≤ (1 - hd.2) / (hd.2 * R) := div_nonneg (by linarith [hq.2]) (mul_nonneg (le_of_lt hq.1) (le_of_lt hR)) linarith [binomTail_mono_left (ℓ' := hd.1) h12 hx] lemma getLast_append_halving (L₀ k t : ℕ) (q₀ q₁ : ℝ) (ht : 1 ≤ t) : (((sub4Steps L₀ q₀ k ++ halvingSchedule t q₁).getLast?).map Prod.fst).getD k = 1 := by have hne : halvingSchedule t q₁ ≠ [] := by cases t with | zero => omega | succ t' => simp [halvingSchedule] rw [List.getLast?_append_of_ne_nil _ hne] have hlast := halvingSchedule_last t q₁ have hne' : (halvingSchedule t q₁).getLast? ≠ none := by rw [ne_eq, List.getLast?_eq_none_iff]; exact hne cases h : (halvingSchedule t q₁).getLast? with | none => exact absurd h hne' | some p => rw [h] at hlast; simpa using hlast /-- **Theorem 4 (Sub-4 Spread Lemma — Breaking the `4 log₂ k` Barrier):** Using exact rational contraction `θ = 12/25` (`x₀ = 4727/20000`) down to `L₀ = 250000` followed by power-of-two halving, for EVERY `k ≥ 1`, EVERY `R > 0`, EVERY `R`-spread probability measure `μ` on subsets of `U` of size `≤ k` (`μ.totalMass = 1`), and EVERY `p ∈ (0, 1]`: if `p ≥ (3.996 * log₂ k + 80) / R`, then `missProb U p μ.supp < 1 / 2`. This strictly beats both `4 log₂ k` and Tran–Vu (2023)'s `3.998 log₂ k` with a fully explicit additive constant `+ 80`. -/ theorem spread_lemma_sub4 {U : Finset α} {R p : ℝ} {k : ℕ} (hk : 1 ≤ k) (hR : 0 < R) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R k) (hM1 : μ.totalMass = 1) (hp : (3.996 * Real.logb 2 (k : ℝ) + 80) / R ≤ p) : missProb U p μ.supp < 1 / 2 := by set L₀ : ℕ := 250000 set t : ℕ := 18 have hL₀_le_2t : L₀ ≤ 2 ^ t := by norm_num [L₀, t] set x₀ : ℝ := 4727 / 20000 set q₀ : ℝ := 1 / (1 + x₀ * R) set q₁ : ℝ := 1 / (1 + R / 4) set qStar : ℝ := min 1 (Real.log 8 / R) have hq₀0 : 0 < q₀ := by dsimp only [q₀, x₀]; positivity have hq₀1 : q₀ < 1 := by dsimp only [q₀, x₀]; rw [div_lt_one (by positivity)]; nlinarith have hq₁0 : 0 < q₁ := by dsimp only [q₁]; positivity have hq₁1 : q₁ < 1 := by dsimp only [q₁]; rw [div_lt_one (by positivity)]; linarith have hlog8_pos : 0 < Real.log 8 := Real.log_pos (by norm_num) have hqS0 : 0 ≤ qStar := by positivity have hqS1 : qStar ≤ 1 := min_le_left _ _ have hxq₀ : (1 - q₀) / (q₀ * R) = x₀ := by dsimp only [q₀, x₀] have hden : 1 + 4727 / 20000 * R ≠ 0 := by positivity field_simp [hden, ne_of_gt hR] ring have hxq₁ : (1 - q₁) / (q₁ * R) = 1 / 4 := by dsimp only [q₁] have hden : 1 + R / 4 ≠ 0 := by positivity field_simp [hden, ne_of_gt hR] ring have hq₀_le : q₀ ≤ (20000 / 4727 : ℝ) / R := by dsimp only [q₀, x₀] rw [div_le_div_iff₀ (by positivity) hR] nlinarith have hq₁_le : q₁ ≤ 4 / R := by dsimp only [q₁] rw [div_le_div_iff₀ (by positivity) hR] linarith set sched : List (ℕ × ℝ) := sub4Steps L₀ q₀ k ++ halvingSchedule t q₁ have hsched_q : ∀ pr ∈ sched, 0 < pr.2 ∧ pr.2 < 1 := by intro pr hpr rcases List.mem_append.mp hpr with h1 | h2 · rw [sub4Steps_mem_snd h1]; exact ⟨hq₀0, hq₀1⟩ · rw [halvingSchedule_mem_snd h2]; exact ⟨hq₁0, hq₁1⟩ have hcomb_mem : 0 ≤ combinedProb (sched.map Prod.snd) qStar ∧ combinedProb (sched.map Prod.snd) qStar ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro r hr rcases List.mem_map.mp hr with ⟨pr, hpr, rfl⟩ have := hsched_q pr hpr exact ⟨le_of_lt this.1, le_of_lt this.2⟩ have hlen_le : ((sub4Steps L₀ q₀ k).length : ℝ) ≤ Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1 := by have hpow := sub4Steps_pow_le (L₀ := L₀) (by norm_num : 25 ≤ L₀) hk q₀ have hk_pos : (0 : ℝ) < (k : ℝ) := by positivity have hlog := Real.logb_le_logb_of_le (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_mul (by norm_num) (ne_of_gt hk_pos)] at hlog have hlog25_pos : 0 < Real.logb 2 (25 / 12 : ℝ) := Real.logb_pos (by norm_num) (by norm_num) have hdiv : ((sub4Steps L₀ q₀ k).length : ℝ) ≤ (Real.logb 2 (25 / 12 : ℝ) + Real.logb 2 (k : ℝ)) / Real.logb 2 (25 / 12 : ℝ) := (le_div_iff₀ hlog25_pos).mpr hlog calc ((sub4Steps L₀ q₀ k).length : ℝ) ≤ (Real.logb 2 (25 / 12 : ℝ) + Real.logb 2 (k : ℝ)) / Real.logb 2 (25 / 12 : ℝ) := hdiv _ = Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1 := by rw [add_div, div_self (ne_of_gt hlog25_pos)]; ring have hcomb_le_p : combinedProb (sched.map Prod.snd) qStar ≤ p := by have hsum := combinedProb_le_sum (qs := sched.map Prod.snd) (qStar := qStar) (by intro r hr rcases List.mem_map.mp hr with ⟨pr, hpr, rfl⟩ have := hsched_q pr hpr exact ⟨le_of_lt this.1, le_of_lt this.2⟩) hqS0 hqS1 have hmap_sum : (sched.map Prod.snd).sum = ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ + (t : ℝ) * q₁ := by dsimp only [sched] rw [List.map_append, List.sum_append, halvingSchedule_sum_snd] congr 1 have hconst : (sub4Steps L₀ q₀ k).map Prod.snd = List.replicate (sub4Steps L₀ q₀ k).length q₀ := by refine List.eq_replicate_iff.mpr ⟨by simp, fun r hr => ?_⟩ rcases List.mem_map.mp hr with ⟨pr, hpr, rfl⟩ exact sub4Steps_mem_snd hpr rw [hconst, List.sum_replicate, nsmul_eq_mul] rw [hmap_sum] at hsum have hlogk_nn : 0 ≤ Real.logb 2 (k : ℝ) := Real.logb_nonneg (by norm_num) (by exact_mod_cast hk) have hln8_lt : Real.log 8 < 2.2 := by have he : (2.7182818283 : ℝ) < Real.exp 1 := Real.exp_one_gt_d9 have h8 : (8 : ℝ) < Real.exp (22 / 10 : ℝ) := by have h1 : (2.718 : ℝ) ^ 11 < (Real.exp 1) ^ 11 := pow_lt_pow_left₀ (by linarith) (by norm_num) (by omega) have h2 : (8 : ℝ) ^ 5 < (2.718 : ℝ) ^ 11 := by norm_num have h3 : (Real.exp 1) ^ 11 = (Real.exp (22 / 10 : ℝ)) ^ 5 := by rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]; congr 1; norm_num have h4 : (8 : ℝ) ^ 5 < (Real.exp (22 / 10 : ℝ)) ^ 5 := by linarith by_contra hle; push Not at hle have := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hle 5 linarith calc Real.log 8 < Real.log (Real.exp (22 / 10 : ℝ)) := Real.log_lt_log (by norm_num) h8 _ = 2.2 := by rw [Real.log_exp]; norm_num have hsub4_mul : ((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) ≤ 3.996 * Real.logb 2 (k : ℝ) + 20000 / 4727 := by have h1 : ((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) ≤ (Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1) * (20000 / 4727 : ℝ) := by nlinarith [hlen_le] have h2 : (Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ)) * (20000 / 4727 : ℝ) = Real.logb 2 (k : ℝ) * ((20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ)) := by ring have h3 : Real.logb 2 (k : ℝ) * ((20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ)) ≤ Real.logb 2 (k : ℝ) * 3.996 := mul_le_mul_of_nonneg_left (le_of_lt sub4_const_lt) hlogk_nn linarith have hnum_le : ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ + (t : ℝ) * q₁ + qStar ≤ (3.996 * Real.logb 2 (k : ℝ) + 80) / R := by have h1 : ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ ≤ ((sub4Steps L₀ q₀ k).length : ℝ) * ((20000 / 4727 : ℝ) / R) := mul_le_mul_of_nonneg_left hq₀_le (Nat.cast_nonneg _) have h2 : (t : ℝ) * q₁ ≤ (t : ℝ) * (4 / R) := mul_le_mul_of_nonneg_left hq₁_le (Nat.cast_nonneg _) have h3 : qStar ≤ Real.log 8 / R := min_le_right _ _ have ht_eq : (t : ℝ) * 4 = 72 := by norm_num [t] calc ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ + (t : ℝ) * q₁ + qStar ≤ (((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) + (t : ℝ) * 4 + Real.log 8) / R := by have : ((sub4Steps L₀ q₀ k).length : ℝ) * ((20000 / 4727 : ℝ) / R) + (t : ℝ) * (4 / R) + Real.log 8 / R = (((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) + (t : ℝ) * 4 + Real.log 8) / R := by ring linarith _ ≤ (3.996 * Real.logb 2 (k : ℝ) + 80) / R := by rw [div_le_div_iff_of_pos_right hR] linarith [hsub4_mul, ht_eq, hln8_lt] exact hsum.trans (hnum_le.trans hp) have hmulti := multi_round_spread_bound hR hqS0 hqS1 sched k (getLast_append_halving L₀ k t q₀ q₁ (by omega)) hsched_q μ (le_of_eq hM1) rw [hM1, sub_self, zero_add] at hmulti have htail_lt : scheduleTailSum R k sched < 21 / 50 := by dsimp only [sched] rw [scheduleTailSum_sub4_append, hxq₀] have h1 : sub4TailSum L₀ x₀ k ≤ 2 * (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) := sub4TailSum_le (le_refl 250000) k have h1_num : 2 * (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) < 1 / 50 := by set P : ℝ := (9994 / 10000 : ℝ) ^ (10000 : ℕ) have hpow : (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) = P := by dsimp only [P] have hdiv : ((L₀ : ℕ) : ℝ) / 25 = ((10000 : ℕ) : ℝ) := by norm_num [L₀] rw [hdiv, Real.rpow_natCast] rw [hpow] have hexp : P ≤ Real.exp (-6) := by have h := sub4_decay_le_exp 10000 have harg : -(6 * ((10000 : ℕ) : ℝ) / 10000) = (-6 : ℝ) := by norm_num rw [harg] at h exact h have hexp_lt : Real.exp (-6) < 1 / 100 := by rw [Real.exp_neg, inv_lt_comm₀ (Real.exp_pos 6) (by norm_num)] have he : (2.7 : ℝ) < Real.exp 1 := by linarith [Real.exp_one_gt_d9] have h100 : (1 / 100 : ℝ)⁻¹ < (Real.exp 1) ^ 6 := by calc (1 / 100 : ℝ)⁻¹ = 100 := by norm_num _ < (2.7 : ℝ) ^ 6 := by norm_num _ < (Real.exp 1) ^ 6 := pow_lt_pow_left₀ he (by norm_num) (by omega) have hexp6 : (Real.exp 1) ^ 6 = Real.exp 6 := by rw [← Real.exp_nat_mul]; norm_num linarith have hPlt : P < 1 / 100 := lt_of_le_of_lt hexp hexp_lt calc 2 * P < 2 * (1 / 100) := mul_lt_mul_of_pos_left hPlt (by norm_num) _ = 1 / 50 := by norm_num have h2 : scheduleTailSum R (sub4End L₀ k) (halvingSchedule t q₁) ≤ scheduleTailSum R (2 ^ t) (halvingSchedule t q₁) := scheduleTailSum_mono_k₀ ((sub4End_le L₀ k).trans hL₀_le_2t) (fun pr hpr => by rw [halvingSchedule_mem_snd hpr]; exact ⟨hq₁0, hq₁1⟩) hR rw [halvingSchedule_tailSum, hxq₁] at h2 have h3 : ∑ m ∈ Icc 1 t, binomTail (2 ^ m) (2 ^ (m - 1)) (1 / 4 : ℝ) < 2 / 5 := sum_halving_tail_lt_two_fifths t linarith have ha_le : (1 - qStar) ^ R ≤ 1 / 8 := by calc (1 - qStar) ^ R ≤ Real.exp (-(Real.log 8)) := one_sub_min_rpow_le_exp hR _ = 1 / 8 := by rw [Real.exp_neg, Real.exp_log (by norm_num)]; ring have ha_nonneg : 0 ≤ (1 - qStar) ^ R := Real.rpow_nonneg (by linarith) R have h1a_pos : 0 < 1 - (1 - qStar) ^ R := by linarith have hanti := missProb_antitone (U := U) hcomb_mem.1 hcomb_le_p hp1 μ.supp calc missProb U p μ.supp ≤ missProb U (combinedProb (sched.map Prod.snd) qStar) μ.supp := hanti _ ≤ (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * scheduleTailSum R k sched := hmulti _ < (1 - qStar) ^ R + (1 - (1 - qStar) ^ R) * (21 / 50) := by nlinarith _ ≤ 1 / 8 + (1 - 1 / 8) * (21 / 50) := by linarith _ < 1 / 2 := by norm_num end SubFourSpread section OptimalEpsSpread variable {α : Type*} [DecidableEq α] /-- Enlarging the sampled set `W₁ ⊆ W₂` can only shrink every minimal fragment, hence can only decrease `badMass`. -/ lemma badMass_mono_subset {U : Finset α} {R : ℝ} {ℓ : ℕ} (μ : SubspreadMeasure U R ℓ) {W₁ W₂ : Finset α} (h12 : W₁ ⊆ W₂) (ℓ' : ℕ) : badMass μ W₂ ℓ' ≤ badMass μ W₁ ℓ' := by unfold badMass refine sum_le_sum_of_subset_of_nonneg ?_ (fun S _ _ => μ.weight_nonneg S) intro S hS rcases mem_filter.mp hS with ⟨hSmem, hcard2⟩ refine mem_filter.mpr ⟨hSmem, ?_⟩ rcases minFrag_spec hSmem (W := W₁) with ⟨S₁, hS₁mem, hS₁sub, hfrag₁, _⟩ rcases minFrag_spec hSmem (W := W₂) with ⟨_, _, _, _, hmin₂⟩ have hS₁SW₂ : S₁ ⊆ S ∪ W₂ := hS₁sub.trans (union_subset_union_right h12) have hle1 : (minFrag μ.supp S W₂).card ≤ (S₁ \ W₂).card := hmin₂ S₁ hS₁mem hS₁SW₂ have hle2 : (S₁ \ W₂).card ≤ (S₁ \ W₁).card := card_le_card (sdiff_subset_sdiff Subset.rfl h12) rw [← hfrag₁] at hle2 omega /-- Probability of hitting in at least one of `s` independent Bernoulli(`q`) draws. -/ def repProb (s : ℕ) (q : ℝ) : ℝ := 1 - (1 - q) ^ s lemma repProb_zero (q : ℝ) : repProb 0 q = 0 := by simp [repProb] lemma repProb_succ (s : ℕ) (q : ℝ) : repProb (s + 1) q = q + repProb s q - q * repProb s q := by unfold repProb; rw [pow_succ]; ring lemma repProb_mem_Icc {s : ℕ} {q : ℝ} (hq0 : 0 ≤ q) (hq1 : q ≤ 1) : 0 ≤ repProb s q ∧ repProb s q ≤ 1 := by unfold repProb have h1 : 0 ≤ (1 - q) ^ s := pow_nonneg (by linarith) s have h2 : (1 - q) ^ s ≤ 1 := pow_le_one₀ (by linarith) (by linarith) constructor <;> linarith lemma repProb_le_mul (s : ℕ) {q : ℝ} (hq0 : 0 ≤ q) (hq1 : q ≤ 1) : repProb s q ≤ (s : ℝ) * q := by induction s with | zero => simp [repProb] | succ s ih => rw [repProb_succ, Nat.cast_succ] have hr := repProb_mem_Icc (s := s) hq0 hq1 nlinarith /-- **Repeated-Draw High-Probability Fragment Lemma:** Taking the union `W = W^(1) ∪ ... ∪ W^(s)` of `s` independent `Bin(U, q)` draws boosts the Markov tail of `badMass` exponentially to `(binomTail / η) ^ s`. -/ theorem repeated_badMass_prob_le {U : Finset α} {R q η : ℝ} {ℓ ℓ' : ℕ} (hR : 0 < R) (hq0 : 0 < q) (hq1 : q < 1) (hη : 0 < η) (μ : SubspreadMeasure U R ℓ) (s : ℕ) : ∑ W ∈ U.powerset, (if η < badMass μ W ℓ' then binomWeight U (repProb s q) W else 0) ≤ (binomTail ℓ ℓ' ((1 - q) / (q * R)) / η) ^ s := by induction s with | zero => rw [repProb_zero, pow_zero] calc ∑ W ∈ U.powerset, (if η < badMass μ W ℓ' then binomWeight U 0 W else 0) ≤ ∑ W ∈ U.powerset, binomWeight U 0 W := by refine sum_le_sum fun W _ => ?_ split_ifs · exact le_rfl · exact binomWeight_nonneg (U := U) le_rfl zero_le_one W _ = 1 := sum_binomWeight_powerset U 0 | succ s ih => rw [repProb_succ, pow_succ'] have hrew : ∑ W ∈ U.powerset, (if η < badMass μ W ℓ' then binomWeight U (q + repProb s q - q * repProb s q) W else 0) = ∑ W ∈ U.powerset, binomWeight U (q + repProb s q - q * repProb s q) W * (if η < badMass μ W ℓ' then (1 : ℝ) else 0) := by refine sum_congr rfl fun W _ => by split_ifs <;> ring rw [hrew, ← sum_binomWeight_union] have h1 : ∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ else 0) ≤ binomTail ℓ ℓ' ((1 - q) / (q * R)) / η := by rw [le_div_iff₀ hη] calc (∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ else 0)) * η = ∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ * η else 0) := by rw [sum_mul]; refine sum_congr rfl fun W₁ _ => by split_ifs <;> ring _ ≤ ∑ W₁ ∈ U.powerset, binomWeight U q W₁ * badMass μ W₁ ℓ' := by refine sum_le_sum fun W₁ _ => ?_ have hbw := binomWeight_nonneg (U := U) (le_of_lt hq0) (le_of_lt hq1) W₁ split_ifs with hgt · exact mul_le_mul_of_nonneg_left (le_of_lt hgt) hbw · exact mul_nonneg hbw (badMass_nonneg μ W₁ ℓ') _ ≤ binomTail ℓ ℓ' ((1 - q) / (q * R)) := one_step_fragment_bound hR hq0 hq1 μ have hr := repProb_mem_Icc (s := s) (le_of_lt hq0) (le_of_lt hq1) have hind : ∀ W₁ W₂ : Finset α, (if η < badMass μ (W₁ ∪ W₂) ℓ' then (1 : ℝ) else 0) ≤ (if η < badMass μ W₁ ℓ' then (1 : ℝ) else 0) * (if η < badMass μ W₂ ℓ' then (1 : ℝ) else 0) := by intro W₁ W₂ by_cases h12 : η < badMass μ (W₁ ∪ W₂) ℓ' · have hgt1 : η < badMass μ W₁ ℓ' := lt_of_lt_of_le h12 (badMass_mono_subset μ subset_union_left ℓ') have hgt2 : η < badMass μ W₂ ℓ' := lt_of_lt_of_le h12 (badMass_mono_subset μ subset_union_right ℓ') simp [h12, hgt1, hgt2] · simp only [h12, ↓reduceIte] positivity have hprod : ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U q W₁ * binomWeight U (repProb s q) W₂ * (if η < badMass μ (W₁ ∪ W₂) ℓ' then (1 : ℝ) else 0) ≤ (∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ else 0)) * (∑ W₂ ∈ U.powerset, (if η < badMass μ W₂ ℓ' then binomWeight U (repProb s q) W₂ else 0)) := by calc ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U q W₁ * binomWeight U (repProb s q) W₂ * (if η < badMass μ (W₁ ∪ W₂) ℓ' then (1 : ℝ) else 0) ≤ ∑ W₁ ∈ U.powerset, ∑ W₂ ∈ U.powerset, binomWeight U q W₁ * binomWeight U (repProb s q) W₂ * ((if η < badMass μ W₁ ℓ' then (1 : ℝ) else 0) * (if η < badMass μ W₂ ℓ' then (1 : ℝ) else 0)) := by refine sum_le_sum fun W₁ _ => sum_le_sum fun W₂ _ => ?_ exact mul_le_mul_of_nonneg_left (hind W₁ W₂) (mul_nonneg (binomWeight_nonneg (U := U) (le_of_lt hq0) (le_of_lt hq1) W₁) (binomWeight_nonneg (U := U) hr.1 hr.2 W₂)) _ = (∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ else 0)) * (∑ W₂ ∈ U.powerset, (if η < badMass μ W₂ ℓ' then binomWeight U (repProb s q) W₂ else 0)) := by rw [sum_mul] refine sum_congr rfl fun W₁ _ => ?_ rw [mul_sum] refine sum_congr rfl fun W₂ _ => ?_ split_ifs <;> ring have hnn1 : 0 ≤ ∑ W₁ ∈ U.powerset, (if η < badMass μ W₁ ℓ' then binomWeight U q W₁ else 0) := sum_nonneg fun W₁ _ => by split_ifs · exact binomWeight_nonneg (U := U) (le_of_lt hq0) (le_of_lt hq1) W₁ · exact le_rfl have hnn2 : 0 ≤ ∑ W₂ ∈ U.powerset, (if η < badMass μ W₂ ℓ' then binomWeight U (repProb s q) W₂ else 0) := sum_nonneg fun W₂ _ => by split_ifs · exact binomWeight_nonneg (U := U) hr.1 hr.2 W₂ · exact le_rfl have hnn_rhs : 0 ≤ binomTail ℓ ℓ' ((1 - q) / (q * R)) / η := div_nonneg (binomTail_nonneg (div_nonneg (by linarith) (mul_nonneg (le_of_lt hq0) (le_of_lt hR)))) (le_of_lt hη) exact hprod.trans (mul_le_mul h1 ih hnn2 hnn_rhs) /-- Scaled convex singleton endpoint lemma on `[0, 3/4]`: for any `R`-subspread measure `μ` on size `≤ 1` with `totalMass ≤ 1` and `q ∈ [0, 1]`, `missProb U q μ.supp ≤ (1 - q) ^ ((3/4) * R) + (4/3) * max 0 (3/4 - μ.totalMass)`. -/ lemma singleton_miss_bound_scaled {U : Finset α} {R q : ℝ} (hR : 0 < R) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) (μ : SubspreadMeasure U R 1) (_hM1 : μ.totalMass ≤ 1) : missProb U q μ.supp ≤ (1 - q) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * max 0 ((3 / 4 : ℝ) - μ.totalMass) := by have ha0 : 0 ≤ (1 - q) ^ ((3 / 4 : ℝ) * R) := Real.rpow_nonneg (by linarith) _ have ha1 : (1 - q) ^ ((3 / 4 : ℝ) * R) ≤ 1 := Real.rpow_le_one (by linarith) (by linarith) (by positivity) by_cases hempty : ∅ ∈ μ.supp · rw [missProb_eq_zero_of_empty_mem hempty] have hmax : 0 ≤ max (0 : ℝ) ((3 / 4 : ℝ) - μ.totalMass) := le_max_left _ _ linarith · -- Reuse the exact singleton count from singleton_miss_bound via a 1-line reduction: -- Let M := μ.totalMass. We show missProb ≤ (1-q)^(M*R) (as in singleton_miss_bound). have hcard1 : ∀ S ∈ μ.supp, S.card = 1 := by intro S hS have hle := μ.card_le S hS have hne : S ≠ ∅ := fun h => hempty (h ▸ hS) have hpos : 0 < S.card := card_pos.mpr (nonempty_iff_ne_empty.mpr hne) omega set V : Finset α := μ.supp.biUnion id have hVU : V ⊆ U := by intro x hx rcases mem_biUnion.mp hx with ⟨S, hS, hxS⟩ exact μ.supp_subset S hS hxS have hVcard : V.card = μ.supp.card := by have himg : V.image singleton = μ.supp := by ext S simp only [mem_image, V, mem_biUnion, id_eq] constructor · rintro ⟨x, ⟨S', hS', hxS'⟩, rfl⟩ rcases card_eq_one.mp (hcard1 S' hS') with ⟨y, rfl⟩ have hxy : x = y := mem_singleton.mp hxS' subst hxy; exact hS' · intro hS rcases card_eq_one.mp (hcard1 S hS) with ⟨x, rfl⟩ exact ⟨x, ⟨{x}, hS, mem_singleton_self x⟩, rfl⟩ rw [← himg, card_image_of_injective _ singleton_injective] have hmass_le : μ.totalMass * R ≤ (V.card : ℝ) := by have hsum : μ.totalMass ≤ (μ.supp.card : ℝ) * (1 / R) := by unfold SubspreadMeasure.totalMass calc ∑ S ∈ μ.supp, μ.weight S ≤ ∑ _S ∈ μ.supp, (1 / R) := by refine sum_le_sum fun S hS => ?_ have hne : S.Nonempty := card_pos.mp (by rw [hcard1 S hS]; omega) have hsp := μ.subspread S hne rw [hcard1 S hS, pow_one] at hsp calc μ.weight S ≤ ∑ S' ∈ μ.supp.filter (fun S' => S ⊆ S'), μ.weight S' := single_le_sum (fun S' _ => μ.weight_nonneg S') (mem_filter.mpr ⟨hS, Subset.rfl⟩) _ ≤ 1 / R := hsp _ = (μ.supp.card : ℝ) * (1 / R) := by rw [sum_const, nsmul_eq_mul] rw [hVcard] have h := mul_le_mul_of_nonneg_right hsum (le_of_lt hR) field_simp [ne_of_gt hR] at h ⊢ linarith have hmiss_eq : missProb U q μ.supp = (1 - q) ^ V.card := by unfold missProb have hfilt : ∀ W ∈ U.powerset, (∀ S ∈ μ.supp, ¬ S ⊆ W) ↔ W ∈ (U \ V).powerset := by intro W hW rw [mem_powerset] constructor · intro hmiss x hxW refine mem_sdiff.mpr ⟨mem_powerset.mp hW hxW, fun hxV => ?_⟩ rcases mem_biUnion.mp hxV with ⟨S, hS, hxS⟩ rcases card_eq_one.mp (hcard1 S hS) with ⟨y, rfl⟩ have hxy : x = y := mem_singleton.mp hxS subst hxy exact hmiss {x} hS (singleton_subset_iff.mpr hxW) · intro hsub S hS hSW rcases card_eq_one.mp (hcard1 S hS) with ⟨x, rfl⟩ have hxW : x ∈ W := hSW (mem_singleton_self x) have hxV : x ∈ V := mem_biUnion.mpr ⟨{x}, hS, mem_singleton_self x⟩ exact (mem_sdiff.mp (hsub hxW)).2 hxV have hsum_eq : ∑ W ∈ U.powerset, (if (∀ S ∈ μ.supp, ¬ S ⊆ W) then binomWeight U q W else 0) = ∑ W ∈ (U \ V).powerset, binomWeight U q W := by rw [← sum_filter] refine sum_congr ?_ fun _ _ => rfl ext W simp only [mem_filter] constructor · intro ⟨hW, hall⟩; exact (hfilt W hW).mp hall · intro hW have hWU : W ∈ U.powerset := mem_powerset.mpr ((mem_powerset.mp hW).trans sdiff_subset) exact ⟨hWU, (hfilt W hWU).mpr hW⟩ rw [hsum_eq, sum_binomWeight_powerset_sdiff U V hVU q] rw [hmiss_eq] by_cases hq_one : q = 1 · subst hq_one have h0R : (1 - (1 : ℝ)) ^ ((3 / 4 : ℝ) * R) = 0 := by rw [sub_self, Real.zero_rpow (by positivity)] rw [h0R] by_cases hV0 : V.card = 0 · have hM0 : μ.totalMass = 0 := by have : μ.totalMass * R ≤ 0 := by simpa [hV0] using hmass_le have hge := μ.totalMass_nonneg nlinarith simp [hV0, hM0]; norm_num · simp [zero_pow hV0] · have h1q_pos : 0 < 1 - q := by have : q < 1 := lt_of_le_of_ne hq1 hq_one linarith by_cases hM34 : (3 / 4 : ℝ) ≤ μ.totalMass · have hmax : max (0 : ℝ) ((3 / 4 : ℝ) - μ.totalMass) = 0 := max_eq_left (by linarith) rw [hmax, mul_zero, add_zero] have hexp : (3 / 4 : ℝ) * R ≤ (V.card : ℝ) := by nlinarith calc (1 - q) ^ V.card = (1 - q) ^ (V.card : ℝ) := (Real.rpow_natCast _ _).symm _ ≤ (1 - q) ^ ((3 / 4 : ℝ) * R) := Real.rpow_le_rpow_of_exponent_ge h1q_pos (by linarith) hexp · push Not at hM34 have hmax : max (0 : ℝ) ((3 / 4 : ℝ) - μ.totalMass) = (3 / 4 : ℝ) - μ.totalMass := max_eq_right (by linarith) rw [hmax] set t : ℝ := μ.totalMass / (3 / 4 : ℝ) have ht0 : 0 ≤ t := div_nonneg μ.totalMass_nonneg (by norm_num) have ht1 : t ≤ 1 := (div_le_one (by norm_num)).mpr (le_of_lt hM34) have hconv := rpow_le_linear_convex ha0 ht0 ht1 have hpow_eq : ((1 - q) ^ ((3 / 4 : ℝ) * R)) ^ t = (1 - q) ^ (μ.totalMass * R) := by rw [← Real.rpow_mul (le_of_lt h1q_pos)] congr 1; dsimp only [t]; ring have hle_m : (1 - q) ^ V.card ≤ (1 - q) ^ (μ.totalMass * R) := by rw [← Real.rpow_natCast] exact Real.rpow_le_rpow_of_exponent_ge h1q_pos (by linarith) hmass_le have hlin : (1 - (1 - q) ^ ((3 / 4 : ℝ) * R)) * (1 - t) ≤ (4 / 3 : ℝ) * ((3 / 4 : ℝ) - μ.totalMass) := by have h1mt : 1 - t = (4 / 3 : ℝ) * ((3 / 4 : ℝ) - μ.totalMass) := by dsimp only [t]; ring rw [h1mt] have hnn : 0 ≤ (4 / 3 : ℝ) * ((3 / 4 : ℝ) - μ.totalMass) := by linarith nlinarith linarith /-- A round in the hybrid two-regime optimal-ε reduction: either a single high-uniformity draw (tracking expected tail) or a repeated low-uniformity draw (bounding failure probability exponentially via `repeated_badMass_prob_le`). -/ inductive HybridRound where | high (k' : ℕ) (q : ℝ) | low (k' : ℕ) (q : ℝ) (s : ℕ) (η : ℝ) def HybridRound.nextSize : HybridRound → ℕ | .high k' _ => k' | .low k' _ _ _ => k' def HybridRound.effProb : HybridRound → ℝ | .high _ q => q | .low _ q s _ => repProb s q def HybridRound.valid : HybridRound → Prop | .high _ q => 0 < q ∧ q < 1 | .low _ q _ η => 0 < q ∧ q < 1 ∧ 0 < η noncomputable def hybridLowErr (R : ℝ) (k₀ : ℕ) : List HybridRound → ℝ | [] => 0 | .high k₁ _ :: rest => hybridLowErr R k₁ rest | .low k₁ q₁ s₁ η₁ :: rest => (binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) / η₁) ^ s₁ + hybridLowErr R k₁ rest def hybridLowDrop : List HybridRound → ℝ | [] => 0 | .high _ _ :: rest => hybridLowDrop rest | .low _ _ _ η₁ :: rest => η₁ + hybridLowDrop rest noncomputable def hybridHighTail (R : ℝ) (k₀ : ℕ) : List HybridRound → ℝ | [] => 0 | .high k₁ q₁ :: rest => binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) + hybridHighTail R k₁ rest | .low k₁ _ _ _ :: rest => hybridHighTail R k₁ rest lemma hybridLowErr_nonneg {R : ℝ} (hR : 0 < R) : ∀ (rounds : List HybridRound) (k₀ : ℕ), (∀ r ∈ rounds, r.valid) → 0 ≤ hybridLowErr R k₀ rounds | [], _, _ => le_rfl | .high k₁ _ :: rest, _, hv => hybridLowErr_nonneg hR rest k₁ (fun r hr => hv r (List.mem_cons_of_mem _ hr)) | .low k₁ q₁ s₁ η₁ :: rest, k₀, hv => by have h1 := hv (.low k₁ q₁ s₁ η₁) (List.mem_cons_self ..) have h2 := hybridLowErr_nonneg hR rest k₁ (fun r hr => hv r (List.mem_cons_of_mem _ hr)) unfold hybridLowErr have hx : 0 ≤ (1 - q₁) / (q₁ * R) := div_nonneg (by linarith [h1.2.1]) (mul_nonneg (le_of_lt h1.1) (le_of_lt hR)) have hbt := binomTail_nonneg (ℓ := k₀) (ℓ' := k₁) hx have hdiv : 0 ≤ binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) / η₁ := div_nonneg hbt (le_of_lt h1.2.2) positivity lemma hybridHighTail_nonneg {R : ℝ} (hR : 0 < R) : ∀ (rounds : List HybridRound) (k₀ : ℕ), (∀ r ∈ rounds, r.valid) → 0 ≤ hybridHighTail R k₀ rounds | [], _, _ => le_rfl | .high k₁ q₁ :: rest, k₀, hv => by have h1 := hv (.high k₁ q₁) (List.mem_cons_self ..) have h2 := hybridHighTail_nonneg hR rest k₁ (fun r hr => hv r (List.mem_cons_of_mem _ hr)) unfold hybridHighTail have hx : 0 ≤ (1 - q₁) / (q₁ * R) := div_nonneg (by linarith [h1.2]) (mul_nonneg (le_of_lt h1.1) (le_of_lt hR)) linarith [binomTail_nonneg (ℓ := k₀) (ℓ' := k₁) hx] | .low k₁ _ _ _ :: rest, _, hv => hybridHighTail_nonneg hR rest k₁ (fun r hr => hv r (List.mem_cons_of_mem _ hr)) /-- **Hybrid Two-Regime Multi-Round Spread Theorem:** Combines single-draw high-uniformity rounds with exponentially-boosted low-uniformity rounds and the scaled convex singleton endpoint. -/ theorem hybrid_spread_bound {U : Finset α} {R qStar : ℝ} (hR : 0 < R) (hqS0 : 0 ≤ qStar) (hqS1 : qStar ≤ 1) : ∀ (rounds : List HybridRound) (k₀ : ℕ), (rounds.getLast?.map HybridRound.nextSize).getD k₀ = 1 → (∀ r ∈ rounds, r.valid) → ∀ (μ : SubspreadMeasure U R k₀), μ.totalMass ≤ 1 → missProb U (combinedProb (rounds.map HybridRound.effProb) qStar) μ.supp ≤ hybridLowErr R k₀ rounds + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + hybridLowDrop rounds - μ.totalMass) + hybridHighTail R k₀ rounds) := by intro rounds induction rounds with | nil => intro k₀ hk₀ _ μ hM1 simp only [List.getLast?_nil, Option.map_none, Option.getD_none] at hk₀ subst hk₀ simp only [List.map_nil, combinedProb, hybridLowErr, hybridLowDrop, hybridHighTail, zero_add, add_zero] exact singleton_miss_bound_scaled hR hqS0 hqS1 μ hM1 | cons hd rest ih => intro k₀ hlast hval μ hM1 have hhd_val : hd.valid := hval hd (List.mem_cons_self ..) have hrest_val : ∀ r ∈ rest, r.valid := fun r hr => hval r (List.mem_cons_of_mem _ hr) have hlast_rest : (rest.getLast?.map HybridRound.nextSize).getD hd.nextSize = 1 := by cases rest with | nil => simpa using hlast | cons r₁ tl => simp only [List.getLast?_cons_cons] at hlast have hne : (r₁ :: tl).getLast? ≠ none := by simp cases h : (r₁ :: tl).getLast? with | none => exact absurd h hne | some p => simp_all set pRest : ℝ := combinedProb (rest.map HybridRound.effProb) qStar have hpRest : 0 ≤ pRest ∧ pRest ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro q hq rcases List.mem_map.mp hq with ⟨r, hr, rfl⟩ have hv := hrest_val r hr cases r with | high _ q' => exact ⟨le_of_lt hv.1, le_of_lt hv.2⟩ | low _ q' s' _ => exact repProb_mem_Icc (le_of_lt hv.1) (le_of_lt hv.2.1) have hmiss_split : ∀ (qEff : ℝ) (k₁ : ℕ), 0 ≤ qEff → qEff ≤ 1 → missProb U (qEff + pRest - qEff * pRest) μ.supp ≤ ∑ W₁ ∈ U.powerset, binomWeight U qEff W₁ * missProb U pRest (pushforward μ W₁ k₁).supp := by intro qEff k₁ hqE0 hqE1 have hrew : missProb U (qEff + pRest - qEff * pRest) μ.supp = ∑ W ∈ U.powerset, binomWeight U (qEff + pRest - qEff * pRest) W * (if (∀ S ∈ μ.supp, ¬ S ⊆ W) then (1 : ℝ) else 0) := by unfold missProb; refine sum_congr rfl fun W _ => by split_ifs <;> ring rw [hrew, ← sum_binomWeight_union] refine sum_le_sum fun W₁ _ => ?_ have hfac : ∑ W₂ ∈ U.powerset, binomWeight U qEff W₁ * binomWeight U pRest W₂ * (if (∀ S ∈ μ.supp, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) = binomWeight U qEff W₁ * ∑ W₂ ∈ U.powerset, binomWeight U pRest W₂ * (if (∀ S ∈ μ.supp, ¬ S ⊆ W₁ ∪ W₂) then (1 : ℝ) else 0) := by rw [mul_sum]; refine sum_congr rfl fun W₂ _ => by ring rw [hfac] refine mul_le_mul_of_nonneg_left ?_ (binomWeight_nonneg (U := U) hqE0 hqE1 W₁) unfold missProb refine sum_le_sum fun W₂ _ => ?_ split_ifs with h1 h2 · rw [mul_one] · exfalso; apply h2; intro T hT hTW2 rcases pushforward_supp_union_contains μ W₁ k₁ T hT with ⟨S', hS', hS'sub⟩ exact h1 S' hS' (hS'sub.trans (union_subset (hTW2.trans subset_union_right) subset_union_left)) · rw [mul_zero]; exact binomWeight_nonneg (U := U) hpRest.1 hpRest.2 W₂ · rw [mul_zero] cases hd with | high k₁ q₁ => simp only [List.map_cons, HybridRound.effProb, combinedProb, hybridLowErr, hybridLowDrop, hybridHighTail, HybridRound.nextSize] at hlast_rest ⊢ have hq₁ : 0 < q₁ ∧ q₁ < 1 := hhd_val have h1 := hmiss_split q₁ k₁ (le_of_lt hq₁.1) (le_of_lt hq₁.2) have hstep : ∀ W₁ ∈ U.powerset, missProb U pRest (pushforward μ W₁ k₁).supp ≤ hybridLowErr R k₁ rest + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass) + badMass μ W₁ k₁ + hybridHighTail R k₁ rest) := by intro W₁ _ have hmass := pushforward_totalMass_add_badMass μ W₁ k₁ have hpf_le : (pushforward μ W₁ k₁).totalMass ≤ 1 := by have := badMass_nonneg μ W₁ k₁; linarith have hih := ih k₁ hlast_rest hrest_val (pushforward μ W₁ k₁) hpf_le have hmax_le : max (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rest - (pushforward μ W₁ k₁).totalMass) ≤ max 0 ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass) + badMass μ W₁ k₁ := by have hbm := badMass_nonneg μ W₁ k₁ refine max_le ?_ ?_ · linarith [le_max_left (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass)] · linarith [le_max_right (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass)] linarith calc missProb U (q₁ + pRest - q₁ * pRest) μ.supp ≤ ∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * missProb U pRest (pushforward μ W₁ k₁).supp := h1 _ ≤ ∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * (hybridLowErr R k₁ rest + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass) + badMass μ W₁ k₁ + hybridHighTail R k₁ rest)) := by refine sum_le_sum fun W₁ hW₁ => mul_le_mul_of_nonneg_left (hstep W₁ hW₁) (binomWeight_nonneg (U := U) (le_of_lt hq₁.1) (le_of_lt hq₁.2) W₁) _ = (hybridLowErr R k₁ rest + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass) + hybridHighTail R k₁ rest)) * (∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁) + (4 / 3 : ℝ) * (∑ W₁ ∈ U.powerset, binomWeight U q₁ W₁ * badMass μ W₁ k₁) := by rw [mul_sum, mul_sum, ← sum_add_distrib] refine sum_congr rfl fun W₁ _ => by ring _ ≤ hybridLowErr R k₁ rest + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + hybridLowDrop rest - μ.totalMass) + (binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) + hybridHighTail R k₁ rest)) := by rw [sum_binomWeight_powerset, mul_one] linarith [one_step_fragment_bound hR hq₁.1 hq₁.2 (ℓ' := k₁) μ] | low k₁ q₁ s₁ η₁ => simp only [List.map_cons, HybridRound.effProb, combinedProb, hybridLowErr, hybridLowDrop, hybridHighTail, HybridRound.nextSize] at hlast_rest ⊢ have hq₁ : 0 < q₁ ∧ q₁ < 1 ∧ 0 < η₁ := hhd_val have hrep := repProb_mem_Icc (s := s₁) (le_of_lt hq₁.1) (le_of_lt hq₁.2.1) have h1 := hmiss_split (repProb s₁ q₁) k₁ hrep.1 hrep.2 set B : ℝ := hybridLowErr R k₁ rest + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + (η₁ + hybridLowDrop rest) - μ.totalMass) + hybridHighTail R k₁ rest) have hB_nn : 0 ≤ B := by dsimp only [B] have hle1 := hybridLowErr_nonneg hR rest k₁ hrest_val have hle2 : 0 ≤ (1 - qStar) ^ ((3 / 4 : ℝ) * R) := Real.rpow_nonneg (by linarith) _ have hle3 : 0 ≤ max (0 : ℝ) ((3 / 4 : ℝ) + (η₁ + hybridLowDrop rest) - μ.totalMass) := le_max_left _ _ have hle4 := hybridHighTail_nonneg hR rest k₁ hrest_val linarith have hstep : ∀ W₁ ∈ U.powerset, missProb U pRest (pushforward μ W₁ k₁).supp ≤ (if η₁ < badMass μ W₁ k₁ then (1 : ℝ) else 0) + B := by intro W₁ _ by_cases hbad : η₁ < badMass μ W₁ k₁ · rw [if_pos hbad] have hle1 := missProb_le_one (U := U) hpRest.1 hpRest.2 (pushforward μ W₁ k₁).supp linarith · rw [if_neg hbad, zero_add] push Not at hbad have hmass := pushforward_totalMass_add_badMass μ W₁ k₁ have hpf_le : (pushforward μ W₁ k₁).totalMass ≤ 1 := by have := badMass_nonneg μ W₁ k₁; linarith have hih := ih k₁ hlast_rest hrest_val (pushforward μ W₁ k₁) hpf_le have hmax_le : max (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rest - (pushforward μ W₁ k₁).totalMass) ≤ max 0 ((3 / 4 : ℝ) + (η₁ + hybridLowDrop rest) - μ.totalMass) := by refine max_le (le_max_left _ _) ?_ have := le_max_right (0 : ℝ) ((3 / 4 : ℝ) + (η₁ + hybridLowDrop rest) - μ.totalMass) linarith dsimp only [B] linarith calc missProb U (repProb s₁ q₁ + pRest - repProb s₁ q₁ * pRest) μ.supp ≤ ∑ W₁ ∈ U.powerset, binomWeight U (repProb s₁ q₁) W₁ * missProb U pRest (pushforward μ W₁ k₁).supp := h1 _ ≤ ∑ W₁ ∈ U.powerset, binomWeight U (repProb s₁ q₁) W₁ * ((if η₁ < badMass μ W₁ k₁ then (1 : ℝ) else 0) + B) := by refine sum_le_sum fun W₁ hW₁ => mul_le_mul_of_nonneg_left (hstep W₁ hW₁) (binomWeight_nonneg (U := U) hrep.1 hrep.2 W₁) _ = (∑ W₁ ∈ U.powerset, if η₁ < badMass μ W₁ k₁ then binomWeight U (repProb s₁ q₁) W₁ else 0) + B * (∑ W₁ ∈ U.powerset, binomWeight U (repProb s₁ q₁) W₁) := by rw [mul_sum, ← sum_add_distrib] refine sum_congr rfl fun W₁ _ => by split_ifs <;> ring _ ≤ (binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) / η₁) ^ s₁ + B := by rw [sum_binomWeight_powerset, mul_one] linarith [repeated_badMass_prob_le hR hq₁.1 hq₁.2.1 hq₁.2.2 (ℓ' := k₁) μ s₁] _ = ((binomTail k₀ k₁ ((1 - q₁) / (q₁ * R)) / η₁) ^ s₁ + hybridLowErr R k₁ rest) + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (max 0 ((3 / 4 : ℝ) + (η₁ + hybridLowDrop rest) - μ.totalMass) + hybridHighTail R k₁ rest) := by dsimp only [B]; ring /-- Scaling property of the binomial tail: if `0 ≤ x ≤ y`, then `binomTail ℓ ℓ' x ≤ (x / y) ^ (ℓ' + 1) * binomTail ℓ ℓ' y` (when `0 < y`). -/ lemma binomTail_scale_le {ℓ ℓ' : ℕ} {x y : ℝ} (hx : 0 ≤ x) (hy : 0 < y) (hxy : x ≤ y) : binomTail ℓ ℓ' x ≤ (x / y) ^ (ℓ' + 1) * binomTail ℓ ℓ' y := by unfold binomTail rw [mul_sum] refine sum_le_sum fun j hj => ?_ have hj1 : ℓ' + 1 ≤ j := (mem_Icc.mp hj).1 have hxy_le1 : x / y ≤ 1 := (div_le_one hy).mpr hxy have hpow : (x / y) ^ j ≤ (x / y) ^ (ℓ' + 1) := pow_le_pow_of_le_one (div_nonneg hx (le_of_lt hy)) hxy_le1 hj1 have hrew : x ^ j = (x / y) ^ j * y ^ j := by rw [div_pow, div_mul_cancel₀ _ (pow_ne_zero j (ne_of_gt hy))] rw [hrew] have hnn : 0 ≤ (Nat.choose ℓ j : ℝ) * y ^ j := by positivity nlinarith /-- Elementary exponential bound: for `a ≥ 0`, `m ≥ 1`, `a ≤ m`, `(1 / (1 + 2a/m))^m ≤ exp(-a)`. -/ lemma one_add_inv_pow_le_exp {a : ℝ} {m : ℕ} (ha : 0 ≤ a) (hm : 1 ≤ m) (ham : a ≤ (m : ℝ)) : (1 / (1 + 2 * a / (m : ℝ))) ^ m ≤ Real.exp (-a) := by have hm_pos : (0 : ℝ) < (m : ℝ) := by positivity set t : ℝ := a / (m : ℝ) have ht0 : 0 ≤ t := by positivity have ht1 : t ≤ 1 := (div_le_one hm_pos).mpr ham -- From Real.exp_bound at n = 3: exp(t) ≤ 1 + t + t^2/2 + t^3 * (4 / 18) ≤ 1 + 2*t for t ∈ [0, 1]! have hexp_le : Real.exp t ≤ 1 + 2 * t := by have hb := Real.exp_bound (x := t) (n := 3) (by rw [abs_of_nonneg ht0]; exact ht1) (by omega) have hsum : ∑ k ∈ range 3, t ^ k / (Nat.factorial k : ℝ) = 1 + t + t ^ 2 / 2 := by rw [Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one] norm_num rw [hsum, abs_of_nonneg ht0] at hb have hsub := (abs_le.mp hb).2 norm_num [Nat.factorial] at hsub nlinarith [sq_nonneg t] have h1u_eq : 1 + 2 * a / (m : ℝ) = 1 + 2 * t := by dsimp only [t]; ring rw [h1u_eq] have hinv_le : 1 / (1 + 2 * t) ≤ Real.exp (-t) := by rw [Real.exp_neg, one_div] exact inv_anti₀ (Real.exp_pos t) hexp_le calc (1 / (1 + 2 * t)) ^ m ≤ (Real.exp (-t)) ^ m := pow_le_pow_left₀ (by positivity) hinv_le m _ = Real.exp ((m : ℝ) * (-t)) := (Real.exp_nat_mul (-t) m).symm _ = Real.exp (-a) := by dsimp only [t]; congr 1; field_simp [ne_of_gt hm_pos] /-- Denominator parameter `d_m := if m ≤ 2 then 2 else 2^(m-2)` for low-regime repetitions. -/ def dmVal (m : ℕ) : ℝ := if m ≤ 2 then 2 else ((2 ^ (m - 2) : ℕ) : ℝ) lemma dmVal_pos (m : ℕ) : 0 < dmVal m := by unfold dmVal; split_ifs <;> positivity /-- Denominator lower bound for low-regime adaptive repetitions: for every `m ≥ 1`, `((1/15) * (1/2)^(2^(m-1)+1)) / ((1/4) * (1/2)^m) ≤ exp(-dmVal m)`. -/ lemma low_regime_decay_le_exp (m : ℕ) (hm : 1 ≤ m) : (1 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ (m - 1) + 1) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ m) ≤ Real.exp (-(dmVal m)) := by have he2 : Real.exp 2 < 15 / 2 := by have he : Real.exp 1 < 2.7182818286 := Real.exp_one_lt_d9 have h2 : Real.exp 2 = Real.exp 1 * Real.exp 1 := by rw [← Real.exp_add]; norm_num rw [h2]; nlinarith [Real.exp_pos 1] have h2m_ge : m ≤ 2 ^ (m - 1) := by induction m with | zero => omega | succ k ih => cases k with | zero => norm_num | succ k' => have hprev := ih (by omega) have hpow : 2 ^ (k' + 1) = 2 * 2 ^ k' := by rw [pow_succ]; ring have hpos : 1 ≤ 2 ^ k' := Nat.one_le_pow _ _ (by omega) simp only [Nat.add_sub_cancel] at hprev ⊢ omega have hlhs : (1 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ (m - 1) + 1) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ m) = (2 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ (m - 1) - m) := by have hsplit : (1 / 2 : ℝ) ^ (2 ^ (m - 1) + 1) = (1 / 2 : ℝ) * (1 / 2 : ℝ) ^ m * (1 / 2 : ℝ) ^ (2 ^ (m - 1) - m) := by rw [← pow_succ', ← pow_add] congr 1; omega rw [hsplit] have hne : (1 / 2 : ℝ) ^ m ≠ 0 := pow_ne_zero m (by norm_num) field_simp [hne] ring rw [hlhs] unfold dmVal split_ifs with hm2 · have hsub : 2 ^ (m - 1) - m = 0 := by have : m = 1 ∨ m = 2 := by omega rcases this with rfl | rfl <;> norm_num rw [hsub, pow_zero, mul_one, Real.exp_neg] rw [le_inv_comm₀ (by norm_num) (Real.exp_pos 2)] linarith · rw [Real.exp_neg] have hpos : (0 : ℝ) < (2 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ (m - 1) - m) := by positivity rw [le_inv_comm₀ hpos (Real.exp_pos _)] have hinv_eq : ((2 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ (m - 1) - m))⁻¹ = (15 / 2 : ℝ) * (2 : ℝ) ^ (2 ^ (m - 1) - m) := by rw [mul_inv, one_div_pow, one_div, inv_inv]; ring rw [hinv_eq] by_cases hm3 : m = 3 · subst hm3; norm_num; linarith by_cases hm4 : m = 4 · subst hm4 have h4 : Real.exp ((2 ^ (4 - 2) : ℕ) : ℝ) = Real.exp 2 * Real.exp 2 := by rw [← Real.exp_add]; norm_num rw [h4]; norm_num; nlinarith [Real.exp_pos 2] by_cases hm5 : m = 5 · subst hm5 have h8 : Real.exp ((2 ^ (5 - 2) : ℕ) : ℝ) = (Real.exp 2) ^ 4 := by rw [← Real.exp_nat_mul]; norm_num rw [h8] have hpow4 : (Real.exp 2) ^ 4 < (15 / 2 : ℝ) ^ 4 := pow_lt_pow_left₀ he2 (le_of_lt (Real.exp_pos 2)) (by omega) norm_num at hpow4 ⊢ linarith · have hm6 : 6 ≤ m := by omega have h2m_le : 2 * m ≤ 2 ^ (m - 2) := by have hgen : ∀ k : ℕ, 6 ≤ k → 2 * k ≤ 2 ^ (k - 2) := by intro k induction k with | zero => omega | succ k ih => intro hk by_cases hk6 : k + 1 = 6 · rw [hk6]; norm_num · have hprev := ih (by omega) have hpow : 2 ^ (k + 1 - 2) = 2 * 2 ^ (k - 2) := by rw [show k + 1 - 2 = (k - 2) + 1 by omega, pow_succ]; ring omega exact hgen m hm6 have hexp_le_2 : 3 * 2 ^ (m - 3) ≤ 2 ^ (m - 1) - m := by have h1 : 2 ^ (m - 2) = 2 * 2 ^ (m - 3) := by rw [show m - 2 = (m - 3) + 1 by omega, pow_succ]; ring have h2 : 2 ^ (m - 1) = 4 * 2 ^ (m - 3) := by rw [show m - 1 = (m - 3) + 2 by omega, pow_add]; ring omega have hexp_eq : Real.exp ((2 ^ (m - 2) : ℕ) : ℝ) = (Real.exp 2) ^ (2 ^ (m - 3)) := by rw [← Real.exp_nat_mul] congr 1 have h1 : 2 ^ (m - 2) = 2 ^ (m - 3) * 2 := by rw [show m - 2 = (m - 3) + 1 by omega, pow_succ] exact_mod_cast h1 rw [hexp_eq] have he2_lt8 : Real.exp 2 ≤ 2 ^ 3 := by linarith calc (Real.exp 2) ^ (2 ^ (m - 3)) ≤ ((2 : ℝ) ^ 3) ^ (2 ^ (m - 3)) := pow_le_pow_left₀ (le_of_lt (Real.exp_pos 2)) he2_lt8 _ _ = (2 : ℝ) ^ (3 * 2 ^ (m - 3)) := by rw [← pow_mul] _ ≤ (2 : ℝ) ^ (2 ^ (m - 1) - m) := pow_le_pow_right₀ (by norm_num) hexp_le_2 _ ≤ (15 / 2 : ℝ) * (2 : ℝ) ^ (2 ^ (m - 1) - m) := by have : (0 : ℝ) ≤ (2 : ℝ) ^ (2 ^ (m - 1) - m) := by positivity linarith /-- Optimal-ε hybrid halving schedule for `t` halving rounds (`2^t → 2^(t-1) → ... → 1`). -/ noncomputable def optEpsSchedule (ε R : ℝ) : ℕ → List HybridRound | 0 => [] | m + 1 => (if Real.log (3 / ε) + ((m + 1 : ℕ) : ℝ) ≤ ((2 ^ m : ℕ) : ℝ) then HybridRound.high (2 ^ m) (1 / (1 + R / (4 + 8 * (Real.log (3 / ε) + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)))) else HybridRound.low (2 ^ m) (1 / (1 + R / 8)) (max 1 (Nat.ceil ((Real.log (3 / ε) + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dmVal (m + 1)))) ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1))) :: optEpsSchedule ε R m lemma optEpsSchedule_last (ε R : ℝ) (t : ℕ) : ((optEpsSchedule ε R t).getLast?.map HybridRound.nextSize).getD (2 ^ t) = 1 := by induction t with | zero => simp [optEpsSchedule] | succ t ih => cases t with | zero => simp only [optEpsSchedule] split_ifs <;> simp [HybridRound.nextSize] | succ t' => have hne : optEpsSchedule ε R (t' + 1) ≠ [] := by unfold optEpsSchedule; simp unfold optEpsSchedule rw [List.getLast?_cons_of_ne_nil hne] have hne' : (optEpsSchedule ε R (t' + 1)).getLast? ≠ none := by rw [ne_eq, List.getLast?_eq_none_iff]; exact hne cases h : (optEpsSchedule ε R (t' + 1)).getLast? with | none => exact absurd h hne' | some p => rw [h] at ih; simpa using ih lemma optEpsSchedule_valid {ε R : ℝ} (hε0 : 0 < ε) (hε1 : ε ≤ 1 / 2) (hR : 0 < R) (t : ℕ) : ∀ r ∈ optEpsSchedule ε R t, r.valid := by have hL : 0 < Real.log (3 / ε) := Real.log_pos (by rw [lt_div_iff₀ hε0]; linarith) induction t with | zero => intro r hr; simp [optEpsSchedule] at hr | succ m ih => intro r hr unfold optEpsSchedule at hr simp only [List.mem_cons] at hr rcases hr with rfl | hrest · split_ifs · dsimp only [HybridRound.valid] have hc : 0 < 4 + 8 * (Real.log (3 / ε) + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) := by positivity refine ⟨by positivity, ?_⟩ rw [div_lt_one (by positivity)] have : 0 < R / (4 + 8 * (Real.log (3 / ε) + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) := div_pos hR hc linarith · dsimp only [HybridRound.valid] refine ⟨by positivity, ?_, by positivity⟩ rw [div_lt_one (by positivity)]; linarith · exact ih r hrest /-- Elementary sum bounds for the optimal-ε schedule parameters. -/ lemma sum_inv_two_pow_le_one (t : ℕ) : ∑ m ∈ Icc 1 t, (1 / 2 : ℝ) ^ m ≤ 1 := by have hpow : ∀ n : ℕ, ∑ m ∈ Icc 1 n, (1 / 2 : ℝ) ^ m = 1 - (1 / 2 : ℝ) ^ n := by intro n induction n with | zero => simp | succ k ihk => rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ k + 1), ihk, pow_succ] ring rw [hpow t] have : 0 ≤ (1 / 2 : ℝ) ^ t := by positivity linarith lemma sum_inv_dm_le_two (t : ℕ) : ∑ m ∈ Icc 1 t, (1 / dmVal m) ≤ 2 := by have hterm : ∀ (m : ℕ), 3 ≤ m → 1 / dmVal m = 4 * (1 / 2 : ℝ) ^ m := by intro m hm unfold dmVal rw [if_neg (by omega)] have hnat : 2 ^ m = 4 * 2 ^ (m - 2) := by conv_lhs => rw [show m = (m - 2) + 2 by omega] rw [pow_add]; ring have hpow : (2 : ℝ) ^ m = 4 * ((2 ^ (m - 2) : ℕ) : ℝ) := by exact_mod_cast hnat rw [one_div_pow, hpow] have hne : ((2 ^ (m - 2) : ℕ) : ℝ) ≠ 0 := by positivity field_simp [hne] have hge3 : ∀ k : ℕ, ∑ m ∈ Icc 3 k, (1 / 2 : ℝ) ^ m ≤ 1 / 4 := by intro k have hform : ∀ n : ℕ, 3 ≤ n → ∑ m ∈ Icc 3 n, (1 / 2 : ℝ) ^ m = 1 / 4 - (1 / 2 : ℝ) ^ n := by intro n induction n with | zero => omega | succ j ihj => intro hn by_cases hj : j + 1 = 3 · rw [hj, show Icc 3 3 = {3} by decide, sum_singleton]; norm_num · rw [Finset.sum_Icc_succ_top hn, ihj (by omega), pow_succ]; ring by_cases hk : 3 ≤ k · rw [hform k hk] have : 0 ≤ (1 / 2 : ℝ) ^ k := by positivity linarith · rw [Icc_eq_empty (by omega)]; norm_num have h12 : ∑ m ∈ Icc (1 : ℕ) 2, (1 / dmVal m) = 1 := by rw [show Icc (1 : ℕ) 2 = {1, 2} by decide, sum_pair (by decide)] simp only [dmVal]; norm_num by_cases ht2 : t ≤ 2 · have hle := sum_le_sum_of_subset_of_nonneg (Icc_subset_Icc_right (a := (1 : ℕ)) ht2) (f := fun m : ℕ => 1 / dmVal m) (fun m _ _ => div_nonneg zero_le_one (le_of_lt (dmVal_pos m))) linarith · have hsplit : Icc 1 t = Icc 1 2 ∪ Icc 3 t := by ext m; simp only [mem_Icc, mem_union]; omega have hdisj : Disjoint (Icc 1 2) (Icc 3 t) := by rw [disjoint_left]; intro m h1 h2 have := (mem_Icc.mp h1).2; have := (mem_Icc.mp h2).1; omega rw [hsplit, sum_union hdisj, h12] have h3t : ∑ m ∈ Icc 3 t, (1 / dmVal m) = 4 * ∑ m ∈ Icc 3 t, (1 / 2 : ℝ) ^ m := by rw [mul_sum] refine sum_congr rfl fun m hm => hterm m (mem_Icc.mp hm).1 rw [h3t] linarith [hge3 t] lemma sum_m_div_dm_le (t : ℕ) : ∑ m ∈ Icc 1 t, ((m : ℝ) / dmVal m) ≤ 11 / 2 := by have hge3 : ∀ k : ℕ, ∑ m ∈ Icc 3 k, (m : ℝ) * (1 / 2 : ℝ) ^ m ≤ 1 := by intro k have hform : ∀ n : ℕ, 3 ≤ n → ∑ m ∈ Icc 3 n, (m : ℝ) * (1 / 2 : ℝ) ^ m = 1 - ((n : ℝ) + 2) * (1 / 2 : ℝ) ^ n := by intro n induction n with | zero => omega | succ j ihj => intro hn by_cases hj : j + 1 = 3 · rw [hj, show Icc 3 3 = {3} by decide, sum_singleton]; norm_num · rw [Finset.sum_Icc_succ_top hn, ihj (by omega), pow_succ] push_cast; ring by_cases hk : 3 ≤ k · rw [hform k hk] have : 0 ≤ ((k : ℝ) + 2) * (1 / 2 : ℝ) ^ k := by positivity linarith · rw [Icc_eq_empty (by omega)]; norm_num have hterm : ∀ (m : ℕ), 3 ≤ m → (m : ℝ) / dmVal m = 4 * ((m : ℝ) * (1 / 2 : ℝ) ^ m) := by intro m hm unfold dmVal rw [if_neg (by omega)] have hnat : 2 ^ m = 4 * 2 ^ (m - 2) := by conv_lhs => rw [show m = (m - 2) + 2 by omega] rw [pow_add]; ring have hpow : (2 : ℝ) ^ m = 4 * ((2 ^ (m - 2) : ℕ) : ℝ) := by exact_mod_cast hnat rw [one_div_pow, hpow] have hne : ((2 ^ (m - 2) : ℕ) : ℝ) ≠ 0 := by positivity field_simp [hne] have h12 : ∑ m ∈ Icc (1 : ℕ) 2, ((m : ℝ) / dmVal m) = 3 / 2 := by rw [show Icc (1 : ℕ) 2 = {1, 2} by decide, sum_pair (by decide)] simp only [dmVal]; norm_num by_cases ht2 : t ≤ 2 · have hle := sum_le_sum_of_subset_of_nonneg (Icc_subset_Icc_right (a := (1 : ℕ)) ht2) (f := fun m : ℕ => (m : ℝ) / dmVal m) (fun m _ _ => div_nonneg (Nat.cast_nonneg m) (le_of_lt (dmVal_pos m))) linarith · have hsplit : Icc 1 t = Icc 1 2 ∪ Icc 3 t := by ext m; simp only [mem_Icc, mem_union]; omega have hdisj : Disjoint (Icc 1 2) (Icc 3 t) := by rw [disjoint_left]; intro m h1 h2 have := (mem_Icc.mp h1).2; have := (mem_Icc.mp h2).1; omega rw [hsplit, sum_union hdisj, h12] have h3t : ∑ m ∈ Icc 3 t, ((m : ℝ) / dmVal m) = 4 * ∑ m ∈ Icc 3 t, (m : ℝ) * (1 / 2 : ℝ) ^ m := by rw [mul_sum] refine sum_congr rfl fun m hm => hterm m (mem_Icc.mp hm).1 rw [h3t] linarith [hge3 t] /-- Bundled quantitative bounds for `optEpsSchedule ε R t` (shared by Theorems 5 and 5b). -/ lemma optEpsSchedule_bounds {ε R : ℝ} (hε0 : 0 < ε) (hε1 : ε ≤ 1 / 2) (hR : 0 < R) (t : ℕ) : let rounds := optEpsSchedule ε R t let qStar : ℝ := min 1 ((4 / 3 : ℝ) * Real.log (3 / ε) / R) hybridLowDrop rounds ≤ 1 / 4 ∧ hybridLowErr R (2 ^ t) rounds ≤ ε / 3 ∧ hybridHighTail R (2 ^ t) rounds ≤ ε / 4 ∧ (rounds.map HybridRound.effProb).sum + qStar ≤ (4 * (t : ℝ) + 18 * Real.log (1 / ε) + 95) / R := by set L : ℝ := Real.log (3 / ε) have hL_ge : 1 < L := by have h6 : Real.exp 1 < 3 / ε := by have he : Real.exp 1 < 3 := by linarith [Real.exp_one_lt_d9] have h36 : (3 : ℝ) < 3 / ε := by rw [lt_div_iff₀ hε0]; linarith linarith calc (1 : ℝ) = Real.log (Real.exp 1) := (Real.log_exp 1).symm _ < Real.log (3 / ε) := Real.log_lt_log (Real.exp_pos 1) h6 have hL_pos : 0 < L := by linarith set qStar : ℝ := min 1 ((4 / 3 : ℝ) * L / R) set rounds := optEpsSchedule ε R t -- Bound 1: hybridLowDrop ≤ 1/4 have hdrop_le : hybridLowDrop rounds ≤ 1 / 4 := by have hgen : ∀ n : ℕ, hybridLowDrop (optEpsSchedule ε R n) ≤ (1 / 4 : ℝ) * ∑ m ∈ Icc 1 n, (1 / 2 : ℝ) ^ m := by intro n induction n with | zero => simp [optEpsSchedule, hybridLowDrop] | succ m ih => unfold optEpsSchedule rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ m + 1), mul_add] split_ifs · simp only [hybridLowDrop] have : (0 : ℝ) ≤ (1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1) := by positivity linarith · simp only [hybridLowDrop] linarith calc hybridLowDrop rounds ≤ (1 / 4 : ℝ) * ∑ m ∈ Icc 1 t, (1 / 2 : ℝ) ^ m := hgen t _ ≤ (1 / 4 : ℝ) * 1 := mul_le_mul_of_nonneg_left (sum_inv_two_pow_le_one t) (by norm_num) _ = 1 / 4 := by ring -- Bound 2: hybridLowErr ≤ ε / 3 have hlowErr_le : hybridLowErr R (2 ^ t) rounds ≤ ε / 3 := by have hgen : ∀ n : ℕ, hybridLowErr R (2 ^ n) (optEpsSchedule ε R n) ≤ (ε / 3) * ∑ m ∈ Icc 1 n, (1 / 2 : ℝ) ^ m := by intro n induction n with | zero => simp [optEpsSchedule, hybridLowErr] | succ m ih => unfold optEpsSchedule rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ m + 1), mul_add] split_ifs with hhigh · simp only [hybridLowErr] have : 0 ≤ (ε / 3) * (1 / 2 : ℝ) ^ (m + 1) := by positivity linarith · simp only [hybridLowErr] set dm : ℝ := dmVal (m + 1) set s : ℕ := max 1 (Nat.ceil ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm)) have hdm_pos : 0 < dm := dmVal_pos (m + 1) have hx8 : (1 - 1 / (1 + R / 8)) / (1 / (1 + R / 8) * R) = 1 / 8 := by have hden : 1 + R / 8 ≠ 0 := by positivity field_simp [hden, ne_of_gt hR]; ring rw [hx8] have hbt_scale : binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) ≤ (1 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ m + 1) := by have h1 := binomTail_scale_le (ℓ := 2 ^ (m + 1)) (ℓ' := 2 ^ m) (x := 1 / 8) (y := 1 / 4) (by norm_num) (by norm_num) (by norm_num) have h15 := halving_tail_lt_one_fifteenth (m := m + 1) (by omega) simp only [Nat.add_sub_cancel] at h15 have hdiv : (1 / 8 : ℝ) / (1 / 4 : ℝ) = 1 / 2 := by norm_num rw [hdiv] at h1 nlinarith [pow_nonneg (show (0 : ℝ) ≤ 1 / 2 by norm_num) (2 ^ m + 1)] have hratio : binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1)) ≤ Real.exp (-dm) := by have hdecay := low_regime_decay_le_exp (m + 1) (by omega) simp only [Nat.add_sub_cancel] at hdecay have hdiv_le : binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1)) ≤ (1 / 15 : ℝ) * (1 / 2 : ℝ) ^ (2 ^ m + 1) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1)) := div_le_div_of_nonneg_right hbt_scale (by positivity) exact hdiv_le.trans hdecay have hs_ge : (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm ≤ (s : ℝ) := by have hc := Nat.le_ceil ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) have hmax : Nat.ceil ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) ≤ s := le_max_right _ _ exact hc.trans (Nat.cast_le.mpr hmax) have hpow_le : (binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1))) ^ s ≤ (ε / 3) * (1 / 2 : ℝ) ^ (m + 1) := by have hnn : 0 ≤ binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1)) := div_nonneg (binomTail_nonneg (by norm_num)) (by positivity) calc (binomTail (2 ^ (m + 1)) (2 ^ m) (1 / 8 : ℝ) / ((1 / 4 : ℝ) * (1 / 2 : ℝ) ^ (m + 1))) ^ s ≤ (Real.exp (-dm)) ^ s := pow_le_pow_left₀ hnn hratio s _ = Real.exp (-(s : ℝ) * dm) := by rw [← Real.exp_nat_mul]; congr 1; ring _ ≤ Real.exp (-(L + ((m + 1 : ℕ) : ℝ) * Real.log 2)) := by apply Real.exp_le_exp.mpr have : L + ((m + 1 : ℕ) : ℝ) * Real.log 2 ≤ (s : ℝ) * dm := (div_le_iff₀ hdm_pos).mp hs_ge linarith _ = Real.exp (-L) * (Real.exp (-Real.log 2)) ^ (m + 1) := by rw [← Real.exp_nat_mul, ← Real.exp_add]; congr 1; ring _ = (ε / 3) * (1 / 2 : ℝ) ^ (m + 1) := by rw [Real.exp_neg, Real.exp_log (by positivity), Real.exp_neg, Real.exp_log (by norm_num)] rw [inv_div, one_div] linarith calc hybridLowErr R (2 ^ t) rounds ≤ (ε / 3) * ∑ m ∈ Icc 1 t, (1 / 2 : ℝ) ^ m := hgen t _ ≤ (ε / 3) * 1 := mul_le_mul_of_nonneg_left (sum_inv_two_pow_le_one t) (by positivity) _ = ε / 3 := by ring -- Bound 3: hybridHighTail ≤ ε / 4 have hhighTail_le : hybridHighTail R (2 ^ t) rounds ≤ ε / 4 := by have hgen : ∀ n : ℕ, hybridHighTail R (2 ^ n) (optEpsSchedule ε R n) ≤ (ε / 45) * ∑ m ∈ Icc 1 n, (1 / 2 : ℝ) ^ m := by intro n induction n with | zero => simp [optEpsSchedule, hybridHighTail] | succ m ih => unfold optEpsSchedule rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ m + 1), mul_add] split_ifs with hhigh · simp only [hybridHighTail] set c : ℝ := 4 + 8 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) have hc_pos : 0 < c := by positivity have hce : (4 + (8 * Real.log (3 / ε) + 8 * ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) = c := by dsimp only [c, L]; ring have hxc : (1 - 1 / (1 + R / c)) / (1 / (1 + R / c) * R) = 1 / c := by have hden : 1 + R / c ≠ 0 := by positivity field_simp [hden, ne_of_gt hR, ne_of_gt hc_pos]; ring rw [hce, hxc] have hc_ge4 : (4 : ℝ) ≤ c := by dsimp only [c] linarith [show (0 : ℝ) ≤ 8 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) by positivity] have hscale := binomTail_scale_le (ℓ := 2 ^ (m + 1)) (ℓ' := 2 ^ m) (x := 1 / c) (y := 1 / 4) (by positivity) (by norm_num) (one_div_le_one_div_of_le (by norm_num) hc_ge4) have h15 := halving_tail_lt_one_fifteenth (m := m + 1) (by omega) simp only [Nat.add_sub_cancel] at h15 have hratio_eq : (1 / c) / (1 / 4 : ℝ) = 1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) := by dsimp only [c] have hne : (4 : ℝ) + 8 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) ≠ 0 := by positivity field_simp [hne]; ring rw [hratio_eq] at hscale have hexp_le : (1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ))) ^ (2 ^ m + 1) ≤ Real.exp (-(L + ((m + 1 : ℕ) : ℝ))) := by have hle1 : 1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) ≤ 1 := by rw [div_le_one (by positivity)] linarith [show (0 : ℝ) ≤ 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) by positivity] calc (1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ))) ^ (2 ^ m + 1) ≤ (1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ))) ^ (2 ^ m) := by rw [pow_succ] nlinarith [pow_nonneg (show (0 : ℝ) ≤ 1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) by positivity) (2 ^ m)] _ ≤ Real.exp (-(L + ((m + 1 : ℕ) : ℝ))) := one_add_inv_pow_le_exp (by positivity) (Nat.one_le_pow _ _ (by omega)) hhigh have hexp_half : Real.exp (-(L + ((m + 1 : ℕ) : ℝ))) ≤ (ε / 3) * (1 / 2 : ℝ) ^ (m + 1) := by have h1 : Real.exp (-(L + ((m + 1 : ℕ) : ℝ))) = Real.exp (-L) * (Real.exp (-1)) ^ (m + 1) := by rw [← Real.exp_nat_mul, ← Real.exp_add]; congr 1; ring rw [h1, Real.exp_neg, Real.exp_log (by positivity), inv_div] have he1 : Real.exp (-1) ≤ 1 / 2 := by rw [Real.exp_neg, inv_le_comm₀ (Real.exp_pos 1) (by norm_num)] norm_num; linarith [Real.exp_one_gt_d9] have hpow := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) he1 (m + 1) exact mul_le_mul_of_nonneg_left hpow (by positivity) have hterm_le : binomTail (2 ^ (m + 1)) (2 ^ m) (1 / c) ≤ (ε / 45) * (1 / 2 : ℝ) ^ (m + 1) := by have hnn : 0 ≤ (1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ))) ^ (2 ^ m + 1) := by positivity calc binomTail (2 ^ (m + 1)) (2 ^ m) (1 / c) ≤ (1 / (1 + 2 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ))) ^ (2 ^ m + 1) * (1 / 15) := by nlinarith [hscale, h15] _ ≤ ((ε / 3) * (1 / 2 : ℝ) ^ (m + 1)) * (1 / 15) := by nlinarith [hexp_le.trans hexp_half] _ = (ε / 45) * (1 / 2 : ℝ) ^ (m + 1) := by ring linarith · simp only [hybridHighTail] have : 0 ≤ (ε / 45) * (1 / 2 : ℝ) ^ (m + 1) := by positivity linarith calc hybridHighTail R (2 ^ t) rounds ≤ (ε / 45) * ∑ m ∈ Icc 1 t, (1 / 2 : ℝ) ^ m := hgen t _ ≤ (ε / 45) * 1 := mul_le_mul_of_nonneg_left (sum_inv_two_pow_le_one t) (by positivity) _ ≤ ε / 4 := by linarith -- Bound 4: probability sum bound have hprob_le : (rounds.map HybridRound.effProb).sum + qStar ≤ (4 * (t : ℝ) + 18 * Real.log (1 / ε) + 95) / R := by have hmap_le : ∀ n : ℕ, (optEpsSchedule ε R n |>.map HybridRound.effProb).sum ≤ ((4 * (n : ℝ)) + (∑ m ∈ Icc 1 n, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) else 0) + (∑ m ∈ Icc 1 n, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m)) / R := by intro n induction n with | zero => simp [optEpsSchedule] | succ m ih => unfold optEpsSchedule simp only [List.map_cons, List.sum_cons] rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ m + 1), Finset.sum_Icc_succ_top (by omega : 1 ≤ m + 1)] simp only [Nat.add_sub_cancel] split_ifs with hhigh · simp only [HybridRound.effProb] set c : ℝ := 4 + 8 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ) have hq_le : 1 / (1 + R / c) ≤ c / R := by have hc : 0 < c := by positivity rw [div_le_div_iff₀ (by positivity) hR] have hmul : c * (1 + R / c) = c + R := by field_simp [ne_of_gt hc] nlinarith have hadd := add_le_add hq_le ih have heq : c / R + ((4 * (m : ℝ)) + (∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 8 * (L + (x : ℝ)) / ((2 ^ (x - 1) : ℕ) : ℝ) else 0) + (∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (x : ℝ) * Real.log 2) / dmVal x)) / R = ((4 * ((m + 1 : ℕ) : ℝ)) + ((∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 8 * (L + (x : ℝ)) / ((2 ^ (x - 1) : ℕ) : ℝ) else 0) + 8 * (L + ((m + 1 : ℕ) : ℝ)) / ((2 ^ m : ℕ) : ℝ)) + ((∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (x : ℝ) * Real.log 2) / dmVal x) + 0)) / R := by dsimp only [c]; push_cast; ring linarith · simp only [HybridRound.effProb] set dm : ℝ := dmVal (m + 1) set s : ℕ := max 1 (Nat.ceil ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm)) have hdm_pos : 0 < dm := dmVal_pos (m + 1) have hq8_0 : 0 ≤ 1 / (1 + R / 8) := by positivity have hq8_1 : 1 / (1 + R / 8) ≤ 1 := (div_le_one (by positivity)).mpr (by linarith) have hq8_le : 1 / (1 + R / 8) ≤ 8 / R := by rw [div_le_div_iff₀ (by positivity) hR]; linarith have hs_le : (s : ℝ) ≤ (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm + 1 := by have harg_nn : 0 ≤ (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm := div_nonneg (by positivity) (le_of_lt hdm_pos) have hceil_lt := Nat.ceil_lt_add_one harg_nn dsimp only [s] by_cases h1 : 1 ≤ Nat.ceil ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) · rw [max_eq_right h1]; exact le_of_lt hceil_lt · rw [max_eq_left (by omega : Nat.ceil _ ≤ 1)]; push_cast at harg_nn ⊢; linarith have hrep_le : repProb s (1 / (1 + R / 8)) ≤ (8 + 8 * (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) / R := by calc repProb s (1 / (1 + R / 8)) ≤ (s : ℝ) * (1 / (1 + R / 8)) := repProb_le_mul s hq8_0 hq8_1 _ ≤ (s : ℝ) * (8 / R) := mul_le_mul_of_nonneg_left hq8_le (Nat.cast_nonneg s) _ ≤ ((L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm + 1) * (8 / R) := mul_le_mul_of_nonneg_right hs_le (by positivity) _ = (8 + 8 * (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) / R := by ring have hadd := add_le_add hrep_le ih have heq : (8 + 8 * (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm) / R + ((4 * (m : ℝ)) + (∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 8 * (L + (x : ℝ)) / ((2 ^ (x - 1) : ℕ) : ℝ) else 0) + (∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (x : ℝ) * Real.log 2) / dmVal x)) / R = ((4 * ((m + 1 : ℕ) : ℝ)) + ((∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 8 * (L + (x : ℝ)) / ((2 ^ (x - 1) : ℕ) : ℝ) else 0) + 0) + ((∑ x ∈ Icc 1 m, if L + (x : ℝ) ≤ ((2 ^ (x - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (x : ℝ) * Real.log 2) / dmVal x) + (4 + 8 * (L + ((m + 1 : ℕ) : ℝ) * Real.log 2) / dm))) / R := by push_cast; ring linarith have hhigh_ex : (∑ m ∈ Icc 1 t, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) else 0) ≤ 24 := by set S : Finset ℕ := (Icc (1 : ℕ) t).filter (fun m : ℕ => L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ)) rw [← sum_filter] by_cases hSne : S.Nonempty · set m₀ := S.min' hSne have hm₀_mem : m₀ ∈ S := min'_mem S hSne have hm₀_1 : 1 ≤ m₀ := (mem_Icc.mp (mem_filter.mp hm₀_mem).1).1 have hm₀_cond : L + (m₀ : ℝ) ≤ ((2 ^ (m₀ - 1) : ℕ) : ℝ) := (mem_filter.mp hm₀_mem).2 have h2m₀_ge2 : (2 : ℝ) ≤ ((2 ^ (m₀ - 1) : ℕ) : ℝ) := by have : (1 : ℝ) ≤ (m₀ : ℝ) := by exact_mod_cast hm₀_1 linarith have hterm_le : ∀ m ∈ S, 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) ≤ 8 * ((1 / 2 : ℝ) ^ (m - m₀) + (1 / 2 : ℝ) * ((m - m₀ : ℕ) : ℝ) * (1 / 2 : ℝ) ^ (m - m₀)) := by intro m hm have hm₀_le : m₀ ≤ m := min'_le S m hm set j := m - m₀ have hm_eq : m = m₀ + j := by omega have hpow_eq : ((2 ^ (m - 1) : ℕ) : ℝ) = ((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j := by have : m - 1 = (m₀ - 1) + j := by omega rw [this, pow_add]; push_cast; ring rw [hpow_eq] have hnum : L + (m : ℝ) = (L + (m₀ : ℝ)) + (j : ℝ) := by rw [hm_eq]; push_cast; ring rw [hnum] have hdiv1 : (L + (m₀ : ℝ)) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j) ≤ (1 / 2 : ℝ) ^ j := by rw [one_div_pow, div_le_div_iff₀ (by positivity) (by positivity)] have : (0 : ℝ) < (2 : ℝ) ^ j := by positivity nlinarith have hdiv2 : (j : ℝ) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j) ≤ (1 / 2 : ℝ) * (j : ℝ) * (1 / 2 : ℝ) ^ j := by rw [one_div_pow] have h1 : (j : ℝ) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j) ≤ (j : ℝ) / (2 * (2 : ℝ) ^ j) := by refine div_le_div_of_nonneg_left (Nat.cast_nonneg j) (by positivity) ?_ nlinarith [show (0 : ℝ) < (2 : ℝ) ^ j by positivity] have h2 : (j : ℝ) / (2 * (2 : ℝ) ^ j) = (1 / 2 : ℝ) * (j : ℝ) * (1 / (2 : ℝ) ^ j) := by ring linarith have hsplit : 8 * ((L + (m₀ : ℝ)) + (j : ℝ)) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j) = 8 * ((L + (m₀ : ℝ)) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j) + (j : ℝ) / (((2 ^ (m₀ - 1) : ℕ) : ℝ) * (2 : ℝ) ^ j)) := by ring linarith have hgeom_sum : ∀ N : ℕ, ∑ j ∈ range N, ((1 / 2 : ℝ) ^ j + (1 / 2 : ℝ) * (j : ℝ) * (1 / 2 : ℝ) ^ j) ≤ 3 := by intro N have h1 : ∑ j ∈ range N, (1 / 2 : ℝ) ^ j ≤ 2 := by induction N with | zero => norm_num | succ n ihn => rw [sum_range_succ']; simp only [pow_zero, pow_succ']; rw [← mul_sum]; linarith have h2 : ∑ j ∈ range N, (j : ℝ) * (1 / 2 : ℝ) ^ j ≤ 2 := by have hform : ∀ n : ℕ, 1 ≤ n → ∑ j ∈ range n, (j : ℝ) * (1 / 2 : ℝ) ^ j = 2 - ((n : ℝ) + 1) * (1 / 2 : ℝ) ^ (n - 1) := by intro n induction n with | zero => omega | succ k ihk => intro _ cases k with | zero => simp; norm_num | succ k' => rw [sum_range_succ, ihk (by omega), show k' + 1 - 1 = k' by omega, show k' + 1 + 1 - 1 = k' + 1 by omega, pow_succ] push_cast; ring cases N with | zero => simp | succ N' => rw [hform (N' + 1) (by omega)] have : 0 ≤ (((N' + 1 : ℕ) : ℝ) + 1) * (1 / 2 : ℝ) ^ (N' + 1 - 1) := by positivity linarith rw [sum_add_distrib] have hmul : ∑ j ∈ range N, (1 / 2 : ℝ) * (j : ℝ) * (1 / 2 : ℝ) ^ j = (1 / 2 : ℝ) * ∑ j ∈ range N, (j : ℝ) * (1 / 2 : ℝ) ^ j := by rw [mul_sum]; refine sum_congr rfl fun j _ => by ring rw [hmul]; linarith calc ∑ m ∈ S, 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) ≤ ∑ m ∈ S, 8 * ((1 / 2 : ℝ) ^ (m - m₀) + (1 / 2 : ℝ) * ((m - m₀ : ℕ) : ℝ) * (1 / 2 : ℝ) ^ (m - m₀)) := sum_le_sum hterm_le _ = 8 * ∑ m ∈ S, ((1 / 2 : ℝ) ^ (m - m₀) + (1 / 2 : ℝ) * ((m - m₀ : ℕ) : ℝ) * (1 / 2 : ℝ) ^ (m - m₀)) := (mul_sum ..).symm _ ≤ 8 * ∑ j ∈ range (t + 1), ((1 / 2 : ℝ) ^ j + (1 / 2 : ℝ) * (j : ℝ) * (1 / 2 : ℝ) ^ j) := by refine mul_le_mul_of_nonneg_left ?_ (by norm_num) have hinj : Set.InjOn (fun m => m - m₀) (S : Set ℕ) := by intro a ha b hb heq have ha' := min'_le S a ha have hb' := min'_le S b hb dsimp only at heq; omega rw [← sum_image (f := fun j : ℕ => (1 / 2 : ℝ) ^ j + (1 / 2 : ℝ) * (j : ℝ) * (1 / 2 : ℝ) ^ j) hinj] refine sum_le_sum_of_subset_of_nonneg ?_ (fun j _ _ => by positivity) intro j hj rcases mem_image.mp hj with ⟨m, hm, rfl⟩ have hmt := (mem_Icc.mp (mem_filter.mp hm).1).2 exact mem_range.mpr (by omega) _ ≤ 8 * 3 := mul_le_mul_of_nonneg_left (hgeom_sum (t + 1)) (by norm_num) _ = 24 := by norm_num · change ∑ m ∈ S, 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) ≤ 24 rw [not_nonempty_iff_eq_empty.mp hSne, sum_empty]; norm_num have hlow_ex : (∑ m ∈ Icc 1 t, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m) ≤ (50 / 3 : ℝ) * L + 50 := by set Low : Finset ℕ := (Icc (1 : ℕ) t).filter (fun m : ℕ => ¬ (L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ))) have hrew : (∑ m ∈ Icc 1 t, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m) = ∑ m ∈ Low, (4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m) := by dsimp only [Low] rw [sum_filter]; refine sum_congr rfl fun m _ => by split_ifs <;> rfl rw [hrew] have hlow_card : (4 : ℝ) * (Low.card : ℝ) ≤ (2 / 3 : ℝ) * L + 16 := by have h2m_lin : ∀ m : ℕ, 4 ≤ m → 6 * (m - 4) + m + 4 ≤ 2 ^ (m - 1) := by intro m induction m with | zero => omega | succ k ih => intro hk by_cases hk4 : k + 1 = 4 · rw [hk4]; norm_num · have hprev := ih (by omega) have hpow : 2 ^ (k + 1 - 1) = 2 * 2 ^ (k - 1) := by rw [show k + 1 - 1 = (k - 1) + 1 by omega, pow_succ]; ring omega have hsub : Low ⊆ Icc (1 : ℕ) (Nat.floor (L / 6) + 4) := by intro m hm rcases mem_filter.mp hm with ⟨hmIcc, hnot⟩ push Not at hnot refine mem_Icc.mpr ⟨(mem_Icc.mp hmIcc).1, ?_⟩ by_cases hm4 : m ≤ 4 · omega · have h6 : 6 * (m - 4) + m ≤ 2 ^ (m - 1) := by have := h2m_lin m (by omega); omega have hcast : (6 * ((m - 4 : ℕ) : ℝ)) + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) := by exact_mod_cast h6 have hlt : ((m - 4 : ℕ) : ℝ) < L / 6 := by linarith have hfl : m - 4 ≤ Nat.floor (L / 6) := Nat.le_floor (le_of_lt hlt) omega have hcard_le : Low.card ≤ Nat.floor (L / 6) + 4 := by calc Low.card ≤ (Icc 1 (Nat.floor (L / 6) + 4)).card := card_le_card hsub _ = Nat.floor (L / 6) + 4 := by simp have hcast_le : (Low.card : ℝ) ≤ (Nat.floor (L / 6) : ℝ) + 4 := by exact_mod_cast hcard_le have hfl_le : (Nat.floor (L / 6) : ℝ) ≤ L / 6 := Nat.floor_le (by positivity) linarith have hln2_lt : Real.log 2 < 7 / 10 := by have he : (2.718 : ℝ) < Real.exp 1 := by linarith [Real.exp_one_gt_d9] have h2e : (2 : ℝ) < Real.exp (7 / 10 : ℝ) := by have h1 : (2 : ℝ) ^ 10 < (2.718 : ℝ) ^ 7 := by norm_num have h2 : (2.718 : ℝ) ^ 7 < (Real.exp 1) ^ 7 := pow_lt_pow_left₀ he (by norm_num) (by omega) have h3 : (Real.exp 1) ^ 7 = (Real.exp (7 / 10 : ℝ)) ^ 10 := by rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]; congr 1; norm_num by_contra hle; push Not at hle have := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hle 10 linarith calc Real.log 2 < Real.log (Real.exp (7 / 10 : ℝ)) := Real.log_lt_log (by norm_num) h2e _ = 7 / 10 := Real.log_exp _ have hsplit_sum : ∑ m ∈ Low, (4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m) = (4 : ℝ) * (Low.card : ℝ) + (8 * L) * (∑ m ∈ Low, (1 : ℝ) / dmVal m) + (8 * Real.log 2) * (∑ m ∈ Low, (m : ℝ) / dmVal m) := by rw [sum_add_distrib, sum_const, nsmul_eq_mul, mul_comm (Low.card : ℝ) 4, add_assoc] congr 1 rw [mul_sum, mul_sum, ← sum_add_distrib] refine sum_congr rfl fun m _ => by ring rw [hsplit_sum] have hs1 : ∑ m ∈ Low, ((1 : ℝ) / dmVal m) ≤ 2 := (sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun m _ _ => div_nonneg zero_le_one (le_of_lt (dmVal_pos m)))).trans (sum_inv_dm_le_two t) have hs2 : ∑ m ∈ Low, ((m : ℝ) / dmVal m) ≤ 11 / 2 := (sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun m _ _ => div_nonneg (Nat.cast_nonneg m) (le_of_lt (dmVal_pos m)))).trans (sum_m_div_dm_le t) have hln2_nn : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) nlinarith have hln3_lt : Real.log 3 < 11 / 10 := by have he : (2.718 : ℝ) < Real.exp 1 := by linarith [Real.exp_one_gt_d9] have h3e : (3 : ℝ) < Real.exp (11 / 10 : ℝ) := by have h1 : (3 : ℝ) ^ 10 < (2.718 : ℝ) ^ 11 := by norm_num have h2 : (2.718 : ℝ) ^ 11 < (Real.exp 1) ^ 11 := pow_lt_pow_left₀ he (by norm_num) (by omega) have h3 : (Real.exp 1) ^ 11 = (Real.exp (11 / 10 : ℝ)) ^ 10 := by rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]; congr 1; norm_num by_contra hle; push Not at hle have := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hle 10 linarith calc Real.log 3 < Real.log (Real.exp (11 / 10 : ℝ)) := Real.log_lt_log (by norm_num) h3e _ = 11 / 10 := Real.log_exp _ have hL_eq : L = Real.log 3 + Real.log (1 / ε) := by dsimp only [L] rw [show 3 / ε = 3 * (1 / ε) by ring, Real.log_mul (by norm_num) (by positivity)] have hqS_le : qStar ≤ (4 / 3 : ℝ) * L / R := min_le_right _ _ have h1 := hmap_le t have h2 : ((4 * (t : ℝ)) + (∑ m ∈ Icc 1 t, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 8 * (L + (m : ℝ)) / ((2 ^ (m - 1) : ℕ) : ℝ) else 0) + (∑ m ∈ Icc 1 t, if L + (m : ℝ) ≤ ((2 ^ (m - 1) : ℕ) : ℝ) then 0 else 4 + 8 * (L + (m : ℝ) * Real.log 2) / dmVal m)) / R + (4 / 3 : ℝ) * L / R ≤ (4 * (t : ℝ) + 18 * Real.log (1 / ε) + 95) / R := by rw [← add_div, div_le_div_iff_of_pos_right hR] linarith [hhigh_ex, hlow_ex, hL_eq, hln3_lt] linarith exact ⟨hdrop_le, hlowErr_le, hhighTail_le, hprob_le⟩ /-- **Theorem 5 (Optimal-ε Non-Asymptotic Spread Lemma):** For EVERY `k ≥ 1`, EVERY `ε ∈ (0, 1/2]`, EVERY `R > 0`, EVERY `R`-spread probability measure `μ` on subsets of `U` of size `≤ k` (`μ.totalMass = 1`), and EVERY `p ∈ (0, 1]`: if `p ≥ (4 * ⌈log₂ k⌉ + 18 * ln(1 / ε) + 95) / R`, then `missProb U p μ.supp ≤ ε` (equivalently `hitProb U p μ.supp ≥ 1 - ε`). -/ theorem spread_lemma_optimal_eps {U : Finset α} {R p ε : ℝ} {k : ℕ} (hR : 0 < R) (hε0 : 0 < ε) (hε1 : ε ≤ 1 / 2) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R k) (hM1 : μ.totalMass = 1) (hp : (4 * (Nat.clog 2 k : ℝ) + 18 * Real.log (1 / ε) + 95) / R ≤ p) : missProb U p μ.supp ≤ ε := by set t : ℕ := Nat.clog 2 k have hk_le : k ≤ 2 ^ t := Nat.le_pow_clog (by omega : 1 < 2) k set μ' : SubspreadMeasure U R (2 ^ t) := μ.weaken hk_le set L : ℝ := Real.log (3 / ε) have hL_pos : 0 < L := Real.log_pos (by rw [lt_div_iff₀ hε0]; linarith) set qStar : ℝ := min 1 ((4 / 3 : ℝ) * L / R) have hqS0 : 0 ≤ qStar := by positivity have hqS1 : qStar ≤ 1 := min_le_left _ _ set rounds := optEpsSchedule ε R t have hval := optEpsSchedule_valid hε0 hε1 hR t rcases optEpsSchedule_bounds hε0 hε1 hR t with ⟨hdrop_le, hlowErr_le, hhighTail_le, hprob_le⟩ have hcomb_mem : 0 ≤ combinedProb (rounds.map HybridRound.effProb) qStar ∧ combinedProb (rounds.map HybridRound.effProb) qStar ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro q hq rcases List.mem_map.mp hq with ⟨r, hr, rfl⟩ have hv := hval r hr cases r with | high _ q' => exact ⟨le_of_lt hv.1, le_of_lt hv.2⟩ | low _ q' s' _ => exact repProb_mem_Icc (le_of_lt hv.1) (le_of_lt hv.2.1) have hcomb_le_p : combinedProb (rounds.map HybridRound.effProb) qStar ≤ p := by have hsum_le := combinedProb_le_sum (qs := rounds.map HybridRound.effProb) (qStar := qStar) (by intro q hq rcases List.mem_map.mp hq with ⟨r, hr, rfl⟩ have hv := hval r hr cases r with | high _ q' => exact ⟨le_of_lt hv.1, le_of_lt hv.2⟩ | low _ q' s' _ => exact repProb_mem_Icc (le_of_lt hv.1) (le_of_lt hv.2.1)) hqS0 hqS1 exact hsum_le.trans (hprob_le.trans hp) have hhyb := hybrid_spread_bound hR hqS0 hqS1 rounds (2 ^ t) (optEpsSchedule_last ε R t) hval μ' (le_of_eq hM1) have hmax0 : max (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rounds - μ'.totalMass) = 0 := by have : μ'.totalMass = 1 := hM1 exact max_eq_left (by linarith [hdrop_le]) rw [hmax0, zero_add] at hhyb have ha_le : (1 - qStar) ^ ((3 / 4 : ℝ) * R) ≤ ε / 3 := by have hqS_rew : qStar = min 1 (L / ((3 / 4 : ℝ) * R)) := by dsimp only [qStar]; congr 1; field_simp [ne_of_gt hR] rw [hqS_rew] calc (1 - min 1 (L / ((3 / 4 : ℝ) * R))) ^ ((3 / 4 : ℝ) * R) ≤ Real.exp (-L) := one_sub_min_rpow_le_exp (by positivity) _ = ε / 3 := by dsimp only [L]; rw [Real.exp_neg, Real.exp_log (by positivity), inv_div] have hanti := missProb_antitone (U := U) hcomb_mem.1 hcomb_le_p hp1 μ.supp calc missProb U p μ.supp ≤ missProb U (combinedProb (rounds.map HybridRound.effProb) qStar) μ'.supp := hanti _ ≤ hybridLowErr R (2 ^ t) rounds + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * hybridHighTail R (2 ^ t) rounds := hhyb _ ≤ ε / 3 + ε / 3 + (4 / 3 : ℝ) * (ε / 4) := by linarith [hlowErr_le, ha_le, hhighTail_le] _ = ε := by ring /-- **Theorem 5b (Sub-4 Optimal-ε Spread Lemma):** Chaining `sub4Steps` down to `L₀(ε) = max 250000 (Nat.ceil (45000 * ln(16 / ε)))` with `optEpsSchedule (ε / 2)` simultaneously achieves the sub-4 leading constant `3.99596 * log₂ k` and optimal `O(ln(1/ε))` convergence rate for ALL `k ≥ 1`, `ε ∈ (0, 1/2]`. -/ theorem spread_lemma_sub4_optimal_eps {U : Finset α} {R p ε : ℝ} {k : ℕ} (hk : 1 ≤ k) (hR : 0 < R) (hε0 : 0 < ε) (hε1 : ε ≤ 1 / 2) (hp1 : p ≤ 1) (μ : SubspreadMeasure U R k) (hM1 : μ.totalMass = 1) (hp : (3.99596 * Real.logb 2 (k : ℝ) + 4 * (Nat.clog 2 (max 250000 (Nat.ceil (45000 * Real.log (16 / ε)))) : ℝ) + 18 * Real.log (2 / ε) + 100) / R ≤ p) : missProb U p μ.supp ≤ ε := by set L₀ : ℕ := max 250000 (Nat.ceil (45000 * Real.log (16 / ε))) have hL₀_ge : 250000 ≤ L₀ := le_max_left _ _ set t : ℕ := Nat.clog 2 L₀ have hL₀_le_2t : L₀ ≤ 2 ^ t := Nat.le_pow_clog (by omega : 1 < 2) L₀ set x₀ : ℝ := 4727 / 20000 set q₀ : ℝ := 1 / (1 + x₀ * R) have hq₀0 : 0 < q₀ := by dsimp only [q₀, x₀]; positivity have hq₀1 : q₀ < 1 := by dsimp only [q₀, x₀]; rw [div_lt_one (by positivity)]; nlinarith have hxq₀ : (1 - q₀) / (q₀ * R) = x₀ := by dsimp only [q₀, x₀] have hden : 1 + 4727 / 20000 * R ≠ 0 := by positivity field_simp [hden, ne_of_gt hR]; ring have hq₀_le : q₀ ≤ (20000 / 4727 : ℝ) / R := by dsimp only [q₀, x₀]; rw [div_le_div_iff₀ (by positivity) hR]; nlinarith let sub4High : List HybridRound := (sub4Steps L₀ q₀ k).map (fun pr => HybridRound.high pr.1 pr.2) set rounds := sub4High ++ optEpsSchedule (ε / 2) R t have hε2_0 : 0 < ε / 2 := by linarith have hε2_1 : ε / 2 ≤ 1 / 2 := by linarith have hval_opt := optEpsSchedule_valid hε2_0 hε2_1 hR t have hval : ∀ r ∈ rounds, r.valid := by intro r hr rcases List.mem_append.mp hr with h1 | h2 · rcases List.mem_map.mp h1 with ⟨pr, hpr, rfl⟩ rw [show (HybridRound.high pr.1 pr.2).valid ↔ 0 < pr.2 ∧ pr.2 < 1 from Iff.rfl] rw [sub4Steps_mem_snd hpr]; exact ⟨hq₀0, hq₀1⟩ · exact hval_opt r h2 have hlast_all : (rounds.getLast?.map HybridRound.nextSize).getD k = 1 := by have hne : optEpsSchedule (ε / 2) R t ≠ [] := by have ht1 : 1 ≤ t := Nat.clog_pos (by omega : 1 < 2) (by omega : 1 < L₀) cases ht_eq : t with | zero => omega | succ m => unfold optEpsSchedule; simp dsimp only [rounds] rw [List.getLast?_append_of_ne_nil _ hne] have hlast := optEpsSchedule_last (ε / 2) R t have hne' : (optEpsSchedule (ε / 2) R t).getLast? ≠ none := by rw [ne_eq, List.getLast?_eq_none_iff]; exact hne cases h : (optEpsSchedule (ε / 2) R t).getLast? with | none => exact absurd h hne' | some p => rw [h] at hlast; simpa using hlast have hsplit_all : ∀ (m : ℕ) (rest : List HybridRound), (hybridLowErr R m ((sub4Steps L₀ q₀ m).map (fun pr => HybridRound.high pr.1 pr.2) ++ rest) = hybridLowErr R (sub4End L₀ m) rest) ∧ (hybridLowDrop ((sub4Steps L₀ q₀ m).map (fun pr => HybridRound.high pr.1 pr.2) ++ rest) = hybridLowDrop rest) ∧ (hybridHighTail R m ((sub4Steps L₀ q₀ m).map (fun pr => HybridRound.high pr.1 pr.2) ++ rest) = sub4TailSum L₀ x₀ m + hybridHighTail R (sub4End L₀ m) rest) := by intro m rest induction m using Nat.strong_induction_on with | h m ihm => cases m with | zero => simp [sub4Steps, sub4End, sub4TailSum] | succ m' => rw [sub4Steps, sub4End, sub4TailSum] split_ifs with hle · simp · simp only [List.map_cons, List.cons_append, hybridLowErr, hybridLowDrop, hybridHighTail, hxq₀] have hsub := ihm (12 * (m' + 1) / 25) (by omega) exact ⟨hsub.1, hsub.2.1, by rw [hsub.2.2]; ring⟩ have hsp := hsplit_all k (optEpsSchedule (ε / 2) R t) have hlowErr_mono : ∀ (rs : List HybridRound) (a b : ℕ), a ≤ b → (∀ r ∈ rs, r.valid) → hybridLowErr R a rs ≤ hybridLowErr R b rs := by intro rs a b hab hv cases rs with | nil => simp [hybridLowErr] | cons hd tl => cases hd with | high _ _ => simp [hybridLowErr] | low k₁ q₁ s₁ η₁ => simp only [hybridLowErr] have h1 := hv (.low k₁ q₁ s₁ η₁) (List.mem_cons_self ..) have hx : 0 ≤ (1 - q₁) / (q₁ * R) := div_nonneg (by linarith [h1.2.1]) (mul_nonneg (le_of_lt h1.1) (le_of_lt hR)) have hbt := binomTail_mono_left (ℓ' := k₁) hab hx have hdiv : binomTail a k₁ ((1 - q₁) / (q₁ * R)) / η₁ ≤ binomTail b k₁ ((1 - q₁) / (q₁ * R)) / η₁ := div_le_div_of_nonneg_right hbt (le_of_lt h1.2.2) have hnn : 0 ≤ binomTail a k₁ ((1 - q₁) / (q₁ * R)) / η₁ := div_nonneg (binomTail_nonneg hx) (le_of_lt h1.2.2) linarith [pow_le_pow_left₀ hnn hdiv s₁] have hhighTail_mono : ∀ (rs : List HybridRound) (a b : ℕ), a ≤ b → (∀ r ∈ rs, r.valid) → hybridHighTail R a rs ≤ hybridHighTail R b rs := by intro rs a b hab hv cases rs with | nil => simp [hybridHighTail] | cons hd tl => cases hd with | low _ _ _ _ => simp [hybridHighTail] | high k₁ q₁ => simp only [hybridHighTail] have h1 := hv (.high k₁ q₁) (List.mem_cons_self ..) have hx : 0 ≤ (1 - q₁) / (q₁ * R) := div_nonneg (by linarith [h1.2]) (mul_nonneg (le_of_lt h1.1) (le_of_lt hR)) linarith [binomTail_mono_left (ℓ' := k₁) hab hx] have hsub4_tail : sub4TailSum L₀ x₀ k ≤ ε / 8 := by have h1 := sub4TailSum_le hL₀_ge k have hL₀_real : 45000 * Real.log (16 / ε) ≤ (L₀ : ℝ) := by have hceil := Nat.le_ceil (45000 * Real.log (16 / ε)) have hle : Nat.ceil (45000 * Real.log (16 / ε)) ≤ L₀ := le_max_right _ _ exact hceil.trans (Nat.cast_le.mpr hle) have hdec : (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) ≤ ε / 16 := by have hbase : (9994 / 10000 : ℝ) ≤ Real.exp (-(6 / 10000 : ℝ)) := by have := Real.add_one_le_exp (-(6 / 10000 : ℝ)); linarith calc (9994 / 10000 : ℝ) ^ ((L₀ : ℝ) / 25) ≤ (Real.exp (-(6 / 10000 : ℝ))) ^ ((L₀ : ℝ) / 25) := Real.rpow_le_rpow (by norm_num) hbase (by positivity) _ = Real.exp (-(6 / 10000 : ℝ) * ((L₀ : ℝ) / 25)) := (Real.exp_mul _ _).symm _ ≤ Real.exp (-(Real.log (16 / ε))) := by apply Real.exp_le_exp.mpr have hlog_pos : 0 ≤ Real.log (16 / ε) := Real.log_nonneg (by rw [le_div_iff₀ hε0]; linarith) nlinarith _ = ε / 16 := by rw [Real.exp_neg, Real.exp_log (by positivity), inv_div] linarith set L₂ : ℝ := Real.log (3 / (ε / 2)) have hL₂_pos : 0 < L₂ := Real.log_pos (by rw [lt_div_iff₀ hε2_0]; linarith) set qStar : ℝ := min 1 ((4 / 3 : ℝ) * L₂ / R) have hqS0 : 0 ≤ qStar := by positivity have hqS1 : qStar ≤ 1 := min_le_left _ _ rcases optEpsSchedule_bounds hε2_0 hε2_1 hR t with ⟨hdrop_opt, hlowErr_opt, hhighTail_opt, hprob_opt⟩ -- Probability sum bound: sub4High + optEpsSchedule (ε/2) + qStar ≤ p have hcomb_mem : 0 ≤ combinedProb (rounds.map HybridRound.effProb) qStar ∧ combinedProb (rounds.map HybridRound.effProb) qStar ≤ 1 := by refine combinedProb_mem_Icc ?_ hqS0 hqS1 intro q hq rcases List.mem_map.mp hq with ⟨r, hr, rfl⟩ have hv := hval r hr cases r with | high _ q' => exact ⟨le_of_lt hv.1, le_of_lt hv.2⟩ | low _ q' s' _ => exact repProb_mem_Icc (le_of_lt hv.1) (le_of_lt hv.2.1) have hcomb_le_p : combinedProb (rounds.map HybridRound.effProb) qStar ≤ p := by have hsum_le := combinedProb_le_sum (qs := rounds.map HybridRound.effProb) (qStar := qStar) (by intro q hq rcases List.mem_map.mp hq with ⟨r, hr, rfl⟩ have hv := hval r hr cases r with | high _ q' => exact ⟨le_of_lt hv.1, le_of_lt hv.2⟩ | low _ q' s' _ => exact repProb_mem_Icc (le_of_lt hv.1) (le_of_lt hv.2.1)) hqS0 hqS1 have hsub4_sum : (sub4High.map HybridRound.effProb).sum = ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ := by have hconst : sub4High.map HybridRound.effProb = List.replicate (sub4Steps L₀ q₀ k).length q₀ := by refine List.eq_replicate_iff.mpr ⟨by simp [sub4High], fun r hr => ?_⟩ rcases List.mem_map.mp hr with ⟨hrd, hmem, rfl⟩ rcases List.mem_map.mp hmem with ⟨pr, hpr, rfl⟩ exact sub4Steps_mem_snd hpr rw [hconst, List.sum_replicate, nsmul_eq_mul] have hlen_le : ((sub4Steps L₀ q₀ k).length : ℝ) ≤ Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1 := by have hpow := sub4Steps_pow_le (L₀ := L₀) (by omega : 25 ≤ L₀) hk q₀ have hk_pos : (0 : ℝ) < (k : ℝ) := by positivity have hlog := Real.logb_le_logb_of_le (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_mul (by norm_num) (ne_of_gt hk_pos)] at hlog have hlog25_pos : 0 < Real.logb 2 (25 / 12 : ℝ) := Real.logb_pos (by norm_num) (by norm_num) have hdiv : ((sub4Steps L₀ q₀ k).length : ℝ) ≤ (Real.logb 2 (25 / 12 : ℝ) + Real.logb 2 (k : ℝ)) / Real.logb 2 (25 / 12 : ℝ) := (le_div_iff₀ hlog25_pos).mpr hlog calc ((sub4Steps L₀ q₀ k).length : ℝ) ≤ (Real.logb 2 (25 / 12 : ℝ) + Real.logb 2 (k : ℝ)) / Real.logb 2 (25 / 12 : ℝ) := hdiv _ = Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1 := by rw [add_div, div_self (ne_of_gt hlog25_pos)]; ring have hlogk_nn : 0 ≤ Real.logb 2 (k : ℝ) := Real.logb_nonneg (by norm_num) (by exact_mod_cast hk) have hsub4_cost : ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ ≤ (3.99596 * Real.logb 2 (k : ℝ) + 5) / R := by have h1 : ((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) ≤ 3.99596 * Real.logb 2 (k : ℝ) + 5 := by have ha : ((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ) ≤ (Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ) + 1) * (20000 / 4727 : ℝ) := by nlinarith [hlen_le] have hb : (Real.logb 2 (k : ℝ) / Real.logb 2 (25 / 12 : ℝ)) * (20000 / 4727 : ℝ) = Real.logb 2 (k : ℝ) * ((20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ)) := by ring have hc : Real.logb 2 (k : ℝ) * ((20000 / 4727 : ℝ) / Real.logb 2 (25 / 12 : ℝ)) ≤ Real.logb 2 (k : ℝ) * 3.99596 := mul_le_mul_of_nonneg_left (le_of_lt sub4_const_lt_tight) hlogk_nn linarith calc ((sub4Steps L₀ q₀ k).length : ℝ) * q₀ ≤ ((sub4Steps L₀ q₀ k).length : ℝ) * ((20000 / 4727 : ℝ) / R) := mul_le_mul_of_nonneg_left hq₀_le (Nat.cast_nonneg _) _ = (((sub4Steps L₀ q₀ k).length : ℝ) * (20000 / 4727 : ℝ)) / R := by ring _ ≤ (3.99596 * Real.logb 2 (k : ℝ) + 5) / R := by rw [div_le_div_iff_of_pos_right hR]; exact h1 have hmap_app : (rounds.map HybridRound.effProb).sum = (sub4High.map HybridRound.effProb).sum + ((optEpsSchedule (ε / 2) R t).map HybridRound.effProb).sum := by dsimp only [rounds]; rw [List.map_append, List.sum_append] have hlog_eq : 1 / (ε / 2) = 2 / ε := by ring rw [hlog_eq] at hprob_opt have htot : (rounds.map HybridRound.effProb).sum + qStar ≤ (3.99596 * Real.logb 2 (k : ℝ) + 4 * (t : ℝ) + 18 * Real.log (2 / ε) + 100) / R := by rw [hmap_app, hsub4_sum] have hadd := add_le_add hsub4_cost hprob_opt have hrhs : (3.99596 * Real.logb 2 (k : ℝ) + 5) / R + (4 * (t : ℝ) + 18 * Real.log (2 / ε) + 95) / R = (3.99596 * Real.logb 2 (k : ℝ) + 4 * (t : ℝ) + 18 * Real.log (2 / ε) + 100) / R := by ring dsimp only [qStar, L₂] at hadd ⊢ linarith exact hsum_le.trans (htot.trans hp) have hhyb := hybrid_spread_bound hR hqS0 hqS1 rounds k hlast_all hval μ (le_of_eq hM1) have hmax0 : max (0 : ℝ) ((3 / 4 : ℝ) + hybridLowDrop rounds - μ.totalMass) = 0 := by rw [hsp.2.1, hM1] exact max_eq_left (by linarith [hdrop_opt]) rw [hmax0, zero_add, hsp.1, hsp.2.2] at hhyb have hlowErr_bound : hybridLowErr R (sub4End L₀ k) (optEpsSchedule (ε / 2) R t) ≤ ε / 6 := by have h1 := hlowErr_mono (optEpsSchedule (ε / 2) R t) (sub4End L₀ k) (2 ^ t) ((sub4End_le L₀ k).trans hL₀_le_2t) hval_opt linarith have hhighTail_bound : hybridHighTail R (sub4End L₀ k) (optEpsSchedule (ε / 2) R t) ≤ ε / 8 := by have h1 := hhighTail_mono (optEpsSchedule (ε / 2) R t) (sub4End L₀ k) (2 ^ t) ((sub4End_le L₀ k).trans hL₀_le_2t) hval_opt linarith have ha_le : (1 - qStar) ^ ((3 / 4 : ℝ) * R) ≤ ε / 6 := by have hqS_rew : qStar = min 1 (L₂ / ((3 / 4 : ℝ) * R)) := by dsimp only [qStar]; congr 1; field_simp [ne_of_gt hR] rw [hqS_rew] calc (1 - min 1 (L₂ / ((3 / 4 : ℝ) * R))) ^ ((3 / 4 : ℝ) * R) ≤ Real.exp (-L₂) := one_sub_min_rpow_le_exp (by positivity) _ = ε / 6 := by dsimp only [L₂]; rw [Real.exp_neg, Real.exp_log (by positivity)]; field_simp; ring have hanti := missProb_antitone (U := U) hcomb_mem.1 hcomb_le_p hp1 μ.supp calc missProb U p μ.supp ≤ missProb U (combinedProb (rounds.map HybridRound.effProb) qStar) μ.supp := hanti _ ≤ hybridLowErr R (sub4End L₀ k) (optEpsSchedule (ε / 2) R t) + (1 - qStar) ^ ((3 / 4 : ℝ) * R) + (4 / 3 : ℝ) * (sub4TailSum L₀ x₀ k + hybridHighTail R (sub4End L₀ k) (optEpsSchedule (ε / 2) R t)) := hhyb _ ≤ ε / 6 + ε / 6 + (4 / 3 : ℝ) * (ε / 8 + ε / 8) := by linarith [hlowErr_bound, ha_le, hsub4_tail, hhighTail_bound] _ = (2 / 3 : ℝ) * ε := by ring _ ≤ ε := by linarith end OptimalEpsSpread section RobustSunflowerAndSunflowerBounds universe u variable {α : Type u} [DecidableEq α] /-- A `(p, ε)`-robust sunflower with core `C` inside universe `U`: a nonempty family `G` of supersets of `C` whose petal family `{S \ C : S ∈ G}` has miss probability at most `ε` under Bernoulli(`p`) sampling on `U \ C`. -/ def IsRobustSunflower (U : Finset α) (p ε : ℝ) (G : Finset (Finset α)) (C : Finset α) : Prop := G.Nonempty ∧ (∀ S ∈ G, C ⊆ S) ∧ missProb (U \ C) p (G.image (· \ C)) ≤ ε /-- An `r`-sunflower (`Δ`-system of `r` petals): a family `S` of `r` distinct sets whose pairwise intersections all equal a common core `C`. -/ def IsSunflower (r : ℕ) (S : Finset (Finset α)) : Prop := S.card = r ∧ ∃ C : Finset α, ∀ A ∈ S, ∀ B ∈ S, A ≠ B → A ∩ B = C /-- Maximal dense core extraction: Any family `F` of subsets of `U` of size `≤ k` with `|F| > R^k` admits a core `C ⊆ U` of size `< k` and a nonempty subfamily `G = {S ∈ F : C ⊆ S}` whose link `{S \ C : S ∈ G}` supports a uniform `R`-spread probability measure on `U \ C`. -/ lemma exists_spread_link {U : Finset α} {F : Finset (Finset α)} {k : ℕ} {R : ℝ} (hR : 0 < R) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card ≤ k) (hsize : R ^ k < (F.card : ℝ)) : ∃ (C : Finset α) (G : Finset (Finset α)) (μ : SubspreadMeasure (U \ C) R k), C ⊆ U ∧ C.card < k ∧ G ⊆ F ∧ G.Nonempty ∧ (∀ S ∈ G, C ⊆ S) ∧ μ.supp = G.image (· \ C) ∧ μ.totalMass = 1 := by classical let Cand : Finset (Finset α) := U.powerset.filter (fun C => (F.card : ℝ) ≤ R ^ C.card * ((F.filter (fun S => C ⊆ S)).card : ℝ)) have hEmpty_mem : ∅ ∈ Cand := by refine mem_filter.mpr ⟨mem_powerset.mpr (empty_subset U), ?_⟩ simp only [card_empty, pow_zero, one_mul] have hfilt : F.filter (fun S => ∅ ⊆ S) = F := by ext S; simp [empty_subset] rw [hfilt] rcases exists_max_image Cand Finset.card ⟨∅, hEmpty_mem⟩ with ⟨C, hC_mem, hC_max⟩ rcases mem_filter.mp hC_mem with ⟨hCU_pow, hC_dense⟩ have hCU : C ⊆ U := mem_powerset.mp hCU_pow set G : Finset (Finset α) := F.filter (fun S => C ⊆ S) have hGF : G ⊆ F := filter_subset _ _ have hGC : ∀ S ∈ G, C ⊆ S := fun S hS => (mem_filter.mp hS).2 have hF_pos : (0 : ℝ) < (F.card : ℝ) := lt_trans (pow_pos hR k) hsize have hG_pos : (0 : ℝ) < (G.card : ℝ) := by by_contra hle; push Not at hle have hG0 : (G.card : ℝ) = 0 := le_antisymm hle (Nat.cast_nonneg _) rw [hG0, mul_zero] at hC_dense linarith have hG_ne : G.Nonempty := card_pos.mp (by exact_mod_cast hG_pos) have hC_lt : C.card < k := by by_contra hge; push Not at hge have hG_sub_sing : G ⊆ {C} := by intro S hS rw [mem_singleton] have hCS : C ⊆ S := hGC S hS have hScard : S.card ≤ k := hFcard S (hGF hS) exact (eq_of_subset_of_card_le hCS (le_trans hScard hge)).symm have hG_card_le1 : G.card ≤ 1 := (card_le_card hG_sub_sing).trans (by simp) have hG_cast_le1 : (G.card : ℝ) ≤ 1 := by exact_mod_cast hG_card_le1 have hC_eq_k : C.card = k := by rcases hG_ne with ⟨S₀, hS₀⟩ have h1 : C.card ≤ S₀.card := card_le_card (hGC S₀ hS₀) have h2 : S₀.card ≤ k := hFcard S₀ (hGF hS₀) omega rw [hC_eq_k] at hC_dense have hRk_pos : 0 < R ^ k := pow_pos hR k nlinarith have hinj : Set.InjOn (fun S => S \ C) (G : Set (Finset α)) := by intro A hA B hB hEq have hA' : C ⊆ A := hGC A hA have hB' : C ⊆ B := hGC B hB calc A = (A \ C) ∪ C := (sdiff_union_of_subset hA').symm _ = (B \ C) ∪ C := by dsimp only at hEq; rw [hEq] _ = B := sdiff_union_of_subset hB' have himg_card : (G.image (· \ C)).card = G.card := card_image_of_injOn hinj let μ : SubspreadMeasure (U \ C) R k := { supp := G.image (· \ C) weight := fun A => if A ∈ G.image (· \ C) then (1 : ℝ) / (G.card : ℝ) else 0 supp_subset := by intro A hA rcases mem_image.mp hA with ⟨S, hS, rfl⟩ exact sdiff_subset_sdiff (hFsub S (hGF hS)) subset_rfl card_le := by intro A hA rcases mem_image.mp hA with ⟨S, hS, rfl⟩ exact (card_le_card sdiff_subset).trans (hFcard S (hGF hS)) weight_nonneg := fun A => by split_ifs <;> positivity weight_zero_of_not_mem := fun A hA => if_neg hA subspread := by intro T hTne by_cases hTU : T ⊆ U \ C · have hdisj : Disjoint C T := by rw [disjoint_right] intro x hxT hxC exact (mem_sdiff.mp (hTU hxT)).2 hxC have hCT_sub : C ∪ T ⊆ U := union_subset hCU (hTU.trans sdiff_subset) have hCT_card : (C ∪ T).card = C.card + T.card := card_union_of_disjoint hdisj have hT_pos : 0 < T.card := card_pos.mpr hTne have hCT_not_mem : C ∪ T ∉ Cand := by intro hmem have hle := hC_max (C ∪ T) hmem omega have hCT_lt : R ^ (C ∪ T).card * ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ) < (F.card : ℝ) := by by_contra hge; push Not at hge exact hCT_not_mem (mem_filter.mpr ⟨mem_powerset.mpr hCT_sub, hge⟩) rw [hCT_card, pow_add] at hCT_lt have hRC_pos : 0 < R ^ C.card := pow_pos hR C.card have hfilt_bound : R ^ T.card * ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ) < (G.card : ℝ) := by have : R ^ C.card * (R ^ T.card * ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ)) < R ^ C.card * (G.card : ℝ) := by calc R ^ C.card * (R ^ T.card * ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ)) = (R ^ C.card * R ^ T.card) * ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ) := by ring _ < (F.card : ℝ) := hCT_lt _ ≤ R ^ C.card * (G.card : ℝ) := hC_dense exact lt_of_mul_lt_mul_left this (le_of_lt hRC_pos) have hsub_img : (G.image (· \ C)).filter (fun A => T ⊆ A) ⊆ (F.filter (fun S => C ∪ T ⊆ S)).image (· \ C) := by intro A hA rcases mem_filter.mp hA with ⟨hAimg, hTA⟩ rcases mem_image.mp hAimg with ⟨S, hSG, rfl⟩ refine mem_image.mpr ⟨S, mem_filter.mpr ⟨hGF hSG, union_subset (hGC S hSG) (hTA.trans sdiff_subset)⟩, rfl⟩ have hcard_le : (((G.image (· \ C)).filter (fun A => T ⊆ A)).card : ℝ) ≤ ((F.filter (fun S => C ∪ T ⊆ S)).card : ℝ) := by exact_mod_cast (card_le_card hsub_img).trans card_image_le have hsum_eq : ∑ A ∈ (G.image (· \ C)).filter (fun A => T ⊆ A), (if A ∈ G.image (· \ C) then (1 : ℝ) / (G.card : ℝ) else 0) = (((G.image (· \ C)).filter (fun A => T ⊆ A)).card : ℝ) / (G.card : ℝ) := by have hcongr : ∀ A ∈ (G.image (· \ C)).filter (fun A => T ⊆ A), (if A ∈ G.image (· \ C) then (1 : ℝ) / (G.card : ℝ) else 0) = (1 : ℝ) / (G.card : ℝ) := by intro A hA rw [if_pos (mem_filter.mp hA).1] rw [sum_congr rfl hcongr, sum_const, nsmul_eq_mul] ring rw [hsum_eq, one_div_pow, div_le_div_iff₀ hG_pos (pow_pos hR T.card)] have hRT_pos : 0 < R ^ T.card := pow_pos hR T.card nlinarith · have hempty : (G.image (· \ C)).filter (fun A => T ⊆ A) = ∅ := by rw [eq_empty_iff_forall_notMem] intro A hA rcases mem_filter.mp hA with ⟨hAimg, hTA⟩ rcases mem_image.mp hAimg with ⟨S, hSG, rfl⟩ exact hTU (hTA.trans (sdiff_subset_sdiff (hFsub S (hGF hSG)) subset_rfl)) rw [hempty, sum_empty] positivity } have hM1 : μ.totalMass = 1 := by unfold SubspreadMeasure.totalMass dsimp only [μ] have hcongr : ∀ A ∈ G.image (· \ C), (if A ∈ G.image (· \ C) then (1 : ℝ) / (G.card : ℝ) else 0) = (1 : ℝ) / (G.card : ℝ) := by intro A hA; rw [if_pos hA] rw [sum_congr rfl hcongr, sum_const, nsmul_eq_mul, himg_card] field_simp [ne_of_gt hG_pos] exact ⟨C, G, μ, hCU, hC_lt, hGF, hG_ne, hGC, rfl, hM1⟩ /-- Elementary binomial theorem over the powerset of a finite set `V`. -/ lemma sum_powerset_pow_mul_pow (V : Finset α) (a b : ℝ) : ∑ W ∈ V.powerset, a ^ W.card * b ^ (V.card - W.card) = (a + b) ^ V.card := by induction V using Finset.induction_on with | empty => simp | @insert x s hx ih => rw [powerset_insert, card_insert_of_notMem hx] have hdisj : Disjoint s.powerset (s.powerset.image (insert x)) := by rw [disjoint_left] intro W hW1 hW2 rcases mem_image.mp hW2 with ⟨W', _, rfl⟩ exact hx (mem_powerset.mp hW1 (mem_insert_self x W')) rw [sum_union hdisj] have hinj : Set.InjOn (insert x) (s.powerset : Set (Finset α)) := by intro A hA B hB hEq have hxA : x ∉ A := fun h => hx (mem_powerset.mp hA h) have hxB : x ∉ B := fun h => hx (mem_powerset.mp hB h) calc A = (insert x A).erase x := (erase_insert hxA).symm _ = (insert x B).erase x := by rw [hEq] _ = B := erase_insert hxB rw [sum_image hinj] have h1 : ∑ W ∈ s.powerset, a ^ W.card * b ^ (s.card + 1 - W.card) = b * ∑ W ∈ s.powerset, a ^ W.card * b ^ (s.card - W.card) := by rw [mul_sum] refine sum_congr rfl fun W hW => ?_ have hcard : W.card ≤ s.card := card_le_card (mem_powerset.mp hW) have hsub : s.card + 1 - W.card = (s.card - W.card) + 1 := by omega rw [hsub, pow_succ]; ring have h2 : ∑ W ∈ s.powerset, a ^ (insert x W).card * b ^ (s.card + 1 - (insert x W).card) = a * ∑ W ∈ s.powerset, a ^ W.card * b ^ (s.card - W.card) := by rw [mul_sum] refine sum_congr rfl fun W hW => ?_ have hxW : x ∉ W := fun h => hx (mem_powerset.mp hW h) rw [card_insert_of_notMem hxW, Nat.add_sub_add_right, pow_succ] ring rw [h1, h2, ih, pow_succ] ring /-- Exact two-stage marginal identity: sampling `W₁ ~ Bin(U, p)` and then `W₂ ~ Bin(U \ W₁, q)` yields marginal distribution `W₂ ~ Bin(U, (1 - p) * q)`. -/ lemma sum_binomWeight_sdiff_marginal (U : Finset α) (p q : ℝ) (f : Finset α → ℝ) : ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * (∑ W₂ ∈ (U \ W₁).powerset, binomWeight (U \ W₁) q W₂ * f W₂) = ∑ W₂ ∈ U.powerset, binomWeight U ((1 - p) * q) W₂ * f W₂ := by have hinner : ∀ W₁ ∈ U.powerset, binomWeight U p W₁ * (∑ W₂ ∈ (U \ W₁).powerset, binomWeight (U \ W₁) q W₂ * f W₂) = ∑ W₂ ∈ U.powerset, if W₂ ⊆ U \ W₁ then binomWeight U p W₁ * binomWeight (U \ W₁) q W₂ * f W₂ else 0 := by intro W₁ _ have hfilt : (U \ W₁).powerset = U.powerset.filter (fun W₂ => W₂ ⊆ U \ W₁) := by ext W₂; simp only [mem_powerset, mem_filter] exact ⟨fun h => ⟨h.trans sdiff_subset, h⟩, fun h => h.2⟩ rw [hfilt, sum_filter, mul_sum] refine sum_congr rfl fun W₂ _ => by split_ifs <;> ring rw [sum_congr rfl hinner, Finset.sum_comm] refine sum_congr rfl fun W₂ hW₂ => ?_ have hW₂U : W₂ ⊆ U := mem_powerset.mp hW₂ have hfilt : (U \ W₂).powerset = U.powerset.filter (fun W₁ => W₂ ⊆ U \ W₁) := by ext W₁; simp only [mem_powerset, mem_filter] constructor · intro h refine ⟨h.trans sdiff_subset, fun x hxW₂ => mem_sdiff.mpr ⟨hW₂U hxW₂, fun hxW₁ => ?_⟩⟩ exact (mem_sdiff.mp (h hxW₁)).2 hxW₂ · rintro ⟨hW₁U, hW₂s⟩ x hxW₁ refine mem_sdiff.mpr ⟨hW₁U hxW₁, fun hxW₂ => ?_⟩ exact (mem_sdiff.mp (hW₂s hxW₂)).2 hxW₁ rw [← sum_filter, ← hfilt] have hcardU₂ : (U \ W₂).card + W₂.card = U.card := card_sdiff_add_card_eq_card hW₂U have hterm : ∀ W₁ ∈ (U \ W₂).powerset, binomWeight U p W₁ * binomWeight (U \ W₁) q W₂ * f W₂ = (((1 - p) * q) ^ W₂.card * f W₂) * (p ^ W₁.card * ((1 - p) * (1 - q)) ^ ((U \ W₂).card - W₁.card)) := by intro W₁ hW₁ have hW₁sub : W₁ ⊆ U \ W₂ := mem_powerset.mp hW₁ have hW₁U : W₁ ⊆ U := hW₁sub.trans sdiff_subset have hcardU₁ : (U \ W₁).card + W₁.card = U.card := card_sdiff_add_card_eq_card hW₁U have hW₁card : W₁.card ≤ (U \ W₂).card := card_le_card hW₁sub have hsub1 : U.card - W₁.card = W₂.card + ((U \ W₂).card - W₁.card) := by omega have hsub2 : (U \ W₁).card - W₂.card = (U \ W₂).card - W₁.card := by omega unfold binomWeight rw [hsub1, hsub2, pow_add, mul_pow, mul_pow] ring rw [sum_congr rfl hterm, ← mul_sum, sum_powerset_pow_mul_pow] have hab : p + (1 - p) * (1 - q) = 1 - (1 - p) * q := by ring have hcard_sdiff : (U \ W₂).card = U.card - W₂.card := by omega rw [hab, hcard_sdiff] unfold binomWeight ring /-- **Random `m`-Coloring Extraction Lemma (proved purely via sequential Bernoulli marginalization):** If a family `F` of nonempty subsets of `U` satisfies `missProb U (1 / m) F < 1 - (r - 1) / m`, then `F` contains `r` pairwise disjoint sets. -/ lemma exists_disjoint_of_missProb_lt : ∀ (m : ℕ), 1 ≤ m → ∀ {U : Finset α} {F : Finset (Finset α)} {r : ℕ}, 1 ≤ r → (∀ S ∈ F, S ⊆ U) → (∀ S ∈ F, S.Nonempty) → missProb U (1 / (m : ℝ)) F < 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) → ∃ S ⊆ F, S.card = r ∧ (S : Set (Finset α)).PairwiseDisjoint id := by intro m induction m with | zero => intro hm; omega | succ m' ih => intro _ U F r hr hFsub hFne hmiss by_cases hr1 : r = 1 · subst hr1 simp only [Nat.sub_self, Nat.cast_zero, zero_div, sub_zero] at hmiss have hp0 : (0 : ℝ) ≤ 1 / ((m' + 1 : ℕ) : ℝ) := by positivity have hp1 : 1 / ((m' + 1 : ℕ) : ℝ) ≤ 1 := by rw [div_le_one (by positivity)]; exact_mod_cast (by omega : 1 ≤ m' + 1) have hEx : ∃ W ∈ U.powerset, ¬ (∀ S ∈ F, ¬ S ⊆ W) := by by_contra hall; push Not at hall have heq : missProb U (1 / ((m' + 1 : ℕ) : ℝ)) F = 1 := by unfold missProb rw [sum_congr rfl (fun W hW => if_pos (hall W hW)), sum_binomWeight_powerset] linarith rcases hEx with ⟨W, _, hnot⟩ push Not at hnot rcases hnot with ⟨S₀, hS₀F, _⟩ refine ⟨{S₀}, singleton_subset_iff.mpr hS₀F, card_singleton S₀, ?_⟩ simp · cases m' with | zero => have hnn : 0 ≤ missProb U (1 / ((0 + 1 : ℕ) : ℝ)) F := missProb_nonneg (by norm_num) (by norm_num) F have hr2 : (1 : ℝ) ≤ ((r - 1 : ℕ) : ℝ) := by exact_mod_cast (by omega : 1 ≤ r - 1) simp only [Nat.zero_add, Nat.cast_one, div_one] at hmiss linarith | succ m'' => set k : ℕ := m'' + 1 have hk1 : 1 ≤ k := by omega set p : ℝ := 1 / ((k + 1 : ℕ) : ℝ) set q : ℝ := 1 / (k : ℝ) have hp0 : 0 ≤ p := by positivity have hp1 : p ≤ 1 := by dsimp only [p]; rw [div_le_one (by positivity)]; exact_mod_cast (by omega : 1 ≤ k + 1) have hpq : (1 - p) * q = p := by dsimp only [p, q] have hk_ne : (k : ℝ) ≠ 0 := by positivity have hk1_ne : ((k + 1 : ℕ) : ℝ) ≠ 0 := by positivity push_cast; field_simp [hk_ne, hk1_ne]; ring let F' : Finset α → Finset (Finset α) := fun W₁ => F.filter (fun S => S ⊆ U \ W₁) let h : Finset α → ℝ := fun W₁ => if (∀ S ∈ F, ¬ S ⊆ W₁) then 0 else 1 let g : Finset α → ℝ := fun W₁ => h W₁ + (k : ℝ) * (1 - missProb (U \ W₁) q (F' W₁)) have hEh : ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * h W₁ = 1 - missProb U p F := by have hrew : ∀ W₁ ∈ U.powerset, binomWeight U p W₁ * h W₁ = binomWeight U p W₁ - (if (∀ S ∈ F, ¬ S ⊆ W₁) then binomWeight U p W₁ else 0) := by intro W₁ _; dsimp only [h]; split_ifs <;> ring rw [sum_congr rfl hrew, sum_sub_distrib, sum_binomWeight_powerset] rfl have hEmiss : ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * missProb (U \ W₁) q (F' W₁) = missProb U p F := by have hinner : ∀ W₁ ∈ U.powerset, missProb (U \ W₁) q (F' W₁) = ∑ W₂ ∈ (U \ W₁).powerset, binomWeight (U \ W₁) q W₂ * (if (∀ S ∈ F, ¬ S ⊆ W₂) then (1 : ℝ) else 0) := by intro W₁ _ unfold missProb refine sum_congr rfl fun W₂ hW₂ => ?_ have hiff : (∀ S ∈ F' W₁, ¬ S ⊆ W₂) ↔ (∀ S ∈ F, ¬ S ⊆ W₂) := by constructor · intro h1 S hSF hSW₂ exact h1 S (mem_filter.mpr ⟨hSF, hSW₂.trans (mem_powerset.mp hW₂)⟩) hSW₂ · intro h2 S hSF' hSW₂ exact h2 S (mem_filter.mp hSF').1 hSW₂ by_cases hc : ∀ S ∈ F, ¬ S ⊆ W₂ · rw [if_pos (hiff.mpr hc), if_pos hc, mul_one] · rw [if_neg (fun h' => hc (hiff.mp h')), if_neg hc, mul_zero] calc ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * missProb (U \ W₁) q (F' W₁) = ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * (∑ W₂ ∈ (U \ W₁).powerset, binomWeight (U \ W₁) q W₂ * (if (∀ S ∈ F, ¬ S ⊆ W₂) then (1 : ℝ) else 0)) := sum_congr rfl fun W₁ hW₁ => by rw [hinner W₁ hW₁] _ = ∑ W₂ ∈ U.powerset, binomWeight U ((1 - p) * q) W₂ * (if (∀ S ∈ F, ¬ S ⊆ W₂) then (1 : ℝ) else 0) := sum_binomWeight_sdiff_marginal U p q _ _ = missProb U p F := by rw [hpq]; unfold missProb refine sum_congr rfl fun W₂ _ => by split_ifs <;> ring have hEg : ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * g W₁ = ((k + 1 : ℕ) : ℝ) * (1 - missProb U p F) := by have hrew : ∀ W₁ ∈ U.powerset, binomWeight U p W₁ * g W₁ = binomWeight U p W₁ * h W₁ + (k : ℝ) * (binomWeight U p W₁ - binomWeight U p W₁ * missProb (U \ W₁) q (F' W₁)) := by intro W₁ _; dsimp only [g]; ring rw [sum_congr rfl hrew, sum_add_distrib, ← mul_sum, sum_sub_distrib, hEh, sum_binomWeight_powerset, hEmiss] push_cast; ring have hEg_gt : ((r - 1 : ℕ) : ℝ) < ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * g W₁ := by rw [hEg] have hk1_pos : (0 : ℝ) < ((k + 1 : ℕ) : ℝ) := by positivity have h1 : ((r - 1 : ℕ) : ℝ) / ((k + 1 : ℕ) : ℝ) < 1 - missProb U p F := by dsimp only [p, k] at hmiss ⊢; linarith exact (div_lt_iff₀ hk1_pos).mp h1 |>.trans_eq (by ring) have hExW₁ : ∃ W₁ ∈ U.powerset, ((r - 1 : ℕ) : ℝ) < g W₁ := by by_contra hall; push Not at hall have hle : ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * g W₁ ≤ ((r - 1 : ℕ) : ℝ) := by calc ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * g W₁ ≤ ∑ W₁ ∈ U.powerset, binomWeight U p W₁ * ((r - 1 : ℕ) : ℝ) := sum_le_sum fun W₁ hW₁ => mul_le_mul_of_nonneg_left (hall W₁ hW₁) (binomWeight_nonneg hp0 hp1 W₁) _ = (∑ W₁ ∈ U.powerset, binomWeight U p W₁) * ((r - 1 : ℕ) : ℝ) := (sum_mul ..).symm _ = ((r - 1 : ℕ) : ℝ) := by rw [sum_binomWeight_powerset, one_mul] linarith rcases hExW₁ with ⟨W₁, _, hg_gt⟩ have hk_pos : (0 : ℝ) < (k : ℝ) := by positivity by_cases hW₁miss : ∀ S ∈ F, ¬ S ⊆ W₁ · have hh0 : h W₁ = 0 := if_pos hW₁miss have hlt : missProb (U \ W₁) q (F' W₁) < 1 - ((r - 1 : ℕ) : ℝ) / (k : ℝ) := by dsimp only [g] at hg_gt; rw [hh0, zero_add] at hg_gt have : ((r - 1 : ℕ) : ℝ) / (k : ℝ) < 1 - missProb (U \ W₁) q (F' W₁) := (div_lt_iff₀ hk_pos).mpr (by linarith) linarith rcases ih hk1 hr (fun S hS => (mem_filter.mp hS).2) (fun S hS => hFne S (mem_filter.mp hS).1) hlt with ⟨S, hSF', hScard, hSpd⟩ exact ⟨S, hSF'.trans (filter_subset _ _), hScard, hSpd⟩ · have hh1 : h W₁ = 1 := if_neg hW₁miss push Not at hW₁miss rcases hW₁miss with ⟨S₁, hS₁F, hS₁W₁⟩ have hr_sub : 1 ≤ r - 1 := by omega have hlt : missProb (U \ W₁) q (F' W₁) < 1 - (((r - 1) - 1 : ℕ) : ℝ) / (k : ℝ) := by dsimp only [g] at hg_gt; rw [hh1] at hg_gt have hcast : (((r - 1) - 1 : ℕ) : ℝ) = ((r - 1 : ℕ) : ℝ) - 1 := by rw [Nat.cast_sub hr_sub, Nat.cast_one] rw [hcast] have : (((r - 1 : ℕ) : ℝ) - 1) / (k : ℝ) < 1 - missProb (U \ W₁) q (F' W₁) := (div_lt_iff₀ hk_pos).mpr (by linarith) linarith rcases ih hk1 hr_sub (fun S hS => (mem_filter.mp hS).2) (fun S hS => hFne S (mem_filter.mp hS).1) hlt with ⟨S', hS'F', hS'card, hS'pd⟩ have hdisj_S₁ : ∀ A ∈ S', Disjoint S₁ A := by intro A hA have hAsub : A ⊆ U \ W₁ := (mem_filter.mp (hS'F' hA)).2 rw [disjoint_left] intro x hxS₁ hxA exact (mem_sdiff.mp (hAsub hxA)).2 (hS₁W₁ hxS₁) have hS₁_not_mem : S₁ ∉ S' := by intro hmem have hdisj := hdisj_S₁ S₁ hmem rcases hFne S₁ hS₁F with ⟨x, hx⟩ exact disjoint_left.mp hdisj hx hx refine ⟨insert S₁ S', insert_subset hS₁F (hS'F'.trans (filter_subset _ _)), ?_, ?_⟩ · rw [card_insert_of_notMem hS₁_not_mem, hS'card]; omega · intro A hA B hB hAB simp only [coe_insert, Set.mem_insert_iff] at hA hB rcases hA with rfl | hA' <;> rcases hB with rfl | hB' · exact absurd rfl hAB · exact hdisj_S₁ B hB' · exact (hdisj_S₁ A hA').symm · exact hS'pd hA' hB' hAB /-- Lifting `r` pairwise disjoint petals in `{S \ C : S ∈ G}` back to an `r`-sunflower in `G`. -/ lemma sunflower_of_disjoint_petals {C : Finset α} {G P : Finset (Finset α)} {r : ℕ} (hGC : ∀ S ∈ G, C ⊆ S) (hPG : P ⊆ G.image (· \ C)) (hPcard : P.card = r) (hPdisj : (P : Set (Finset α)).PairwiseDisjoint id) : ∃ S ⊆ G, IsSunflower r S := by have hPdisjC : ∀ A ∈ P, Disjoint A C := by intro A hA rcases mem_image.mp (hPG hA) with ⟨T, _, rfl⟩ exact sdiff_disjoint have hinj : Set.InjOn (fun A => A ∪ C) (P : Set (Finset α)) := by intro A hA B hB hEq have hAC : Disjoint A C := hPdisjC A hA have hBC : Disjoint B C := hPdisjC B hB calc A = (A ∪ C) \ C := (union_sdiff_cancel_right hAC).symm _ = (B ∪ C) \ C := by dsimp only at hEq; rw [hEq] _ = B := union_sdiff_cancel_right hBC refine ⟨P.image (· ∪ C), ?_, ?_, C, ?_⟩ · intro X hX rcases mem_image.mp hX with ⟨A, hAP, rfl⟩ rcases mem_image.mp (hPG hAP) with ⟨T, hTG, rfl⟩ rw [sdiff_union_of_subset (hGC T hTG)] exact hTG · rw [card_image_of_injOn hinj, hPcard] · intro X hX Y hY hXY rcases mem_image.mp hX with ⟨A, hAP, rfl⟩ rcases mem_image.mp hY with ⟨B, hBP, rfl⟩ have hAB : A ≠ B := fun h => hXY (by rw [h]) have hdisjAB : Disjoint A B := hPdisj hAP hBP hAB ext x simp only [mem_inter, mem_union] constructor · rintro ⟨h1, h2⟩ rcases h1 with hxA | hxC · rcases h2 with hxB | hxC · exact absurd hxB (disjoint_left.mp hdisjAB hxA) · exact hxC · exact hxC · intro hxC; exact ⟨Or.inr hxC, Or.inr hxC⟩ /-- **Exact Integer Partition Lemma:** For every integer `r ≥ 2` and real `δ > 0`, setting `m = r + ⌊δ (r - 1)⌋` guarantees: 1. `r ≤ m`, 2. `m ≤ (1 + δ) r`, 3. `δ / (1 + δ) < 1 - (r - 1) / m`. -/ lemma exact_integer_partition {r : ℕ} {δ : ℝ} (hr : 2 ≤ r) (hδ : 0 < δ) : let m : ℕ := r + Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) r ≤ m ∧ (m : ℝ) ≤ (1 + δ) * (r : ℝ) ∧ δ / (1 + δ) < 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) := by intro m have hm_ge : r ≤ m := Nat.le_add_right r _ have hm_pos : (0 : ℝ) < (m : ℝ) := by exact_mod_cast (by omega : 0 < m) have hfl_le : (Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) ≤ δ * ((r - 1 : ℕ) : ℝ) := Nat.floor_le (by positivity) have hfl_gt : δ * ((r - 1 : ℕ) : ℝ) < (Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) + 1 := Nat.lt_floor_add_one _ have hr1_cast : ((r - 1 : ℕ) : ℝ) = (r : ℝ) - 1 := by rw [Nat.cast_sub (by omega : 1 ≤ r), Nat.cast_one] have hm_cast : (m : ℝ) = (r : ℝ) + (Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) := by dsimp only [m]; push_cast; rfl refine ⟨hm_ge, ?_, ?_⟩ · rw [hm_cast] have hfl_le' : (Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) ≤ δ * ((r : ℝ) - 1) := by rw [← hr1_cast]; exact hfl_le nlinarith · have hrhs : 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) = ((Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) + 1) / (m : ℝ) := by have hne : (m : ℝ) ≠ 0 := ne_of_gt hm_pos rw [eq_div_iff hne, sub_mul, one_mul, div_mul_cancel₀ _ hne] rw [hm_cast, hr1_cast]; linarith rw [hrhs, div_lt_div_iff₀ (by linarith) hm_pos, hm_cast] have hfl_gt' : δ * ((r : ℝ) - 1) < (Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) : ℝ) + 1 := by rw [← hr1_cast]; exact hfl_gt nlinarith /-- **Theorem 6 (Explicit Optimal-ε Robust Sunflower Lemma):** For EVERY `k ≥ 1`, EVERY `ε ∈ (0, 1/2]`, EVERY `R > 0`, and EVERY `p ∈ (0, 1]` with `p ≥ (4 ⌈log₂ k⌉ + 18 ln(1/ε) + 95) / R`: any family `F` of subsets of `U` of size `≤ k` with `|F| > R^k` contains a `(p, ε)`-robust sunflower `(G, C)`. -/ theorem robust_sunflower_lemma {U : Finset α} {F : Finset (Finset α)} {k : ℕ} {R p ε : ℝ} (hR : 0 < R) (hε0 : 0 < ε) (hε1 : ε ≤ 1 / 2) (hp1 : p ≤ 1) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card ≤ k) (hsize : R ^ k < (F.card : ℝ)) (hp : (4 * (Nat.clog 2 k : ℝ) + 18 * Real.log (1 / ε) + 95) / R ≤ p) : ∃ G ⊆ F, ∃ C, IsRobustSunflower U p ε G C := by rcases exists_spread_link hR hFsub hFcard hsize with ⟨C, G, μ, _, _, hGF, hGne, hGC, hsupp, hM1⟩ have hmiss := spread_lemma_optimal_eps hR hε0 hε1 hp1 μ hM1 hp rw [hsupp] at hmiss exact ⟨G, hGF, C, hGne, hGC, hmiss⟩ /-- **Theorem 7a (Universal Non-Asymptotic Erdős–Rado Sunflower Bound):** For EVERY `k ≥ 1` and EVERY `r ≥ 2`, any `k`-uniform family `F` with `|F| > (2 (r - 1) (4 ⌈log₂ k⌉ + ln 6))^k` contains an `r`-sunflower. -/ theorem sunflower_bound_universal {U : Finset α} {F : Finset (Finset α)} {k r : ℕ} (hr : 2 ≤ r) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card = k) (hsize : (2 * ((r - 1 : ℕ) : ℝ) * (4 * (Nat.clog 2 k : ℝ) + Real.log 6)) ^ k < (F.card : ℝ)) : ∃ S ⊆ F, IsSunflower r S := by set m : ℕ := 2 * (r - 1) have hm1 : 1 ≤ m := by omega have hm_cast : (m : ℝ) = 2 * ((r - 1 : ℕ) : ℝ) := by dsimp only [m]; push_cast; ring have hlog6_pos : 0 < Real.log 6 := Real.log_pos (by norm_num) set R : ℝ := (m : ℝ) * (4 * (Nat.clog 2 k : ℝ) + Real.log 6) have hR : 0 < R := by dsimp only [R]; positivity have hsize' : R ^ k < (F.card : ℝ) := by dsimp only [R]; rw [hm_cast]; exact hsize rcases exists_spread_link hR hFsub (fun S hS => le_of_eq (hFcard S hS)) hsize' with ⟨C, G, μ, _, hClt, hGF, _, hGC, hsupp, hM1⟩ have hp1 : 1 / (m : ℝ) ≤ 1 := by rw [div_le_one (by positivity)]; exact_mod_cast hm1 have hp : (4 * (Nat.clog 2 k : ℝ) + Real.log 6) / R ≤ 1 / (m : ℝ) := by dsimp only [R] have hfac : 0 < 4 * (Nat.clog 2 k : ℝ) + Real.log 6 := by positivity rw [div_le_div_iff₀ hR (by positivity)]; nlinarith have hmiss := spread_lemma_half hR hp1 μ hM1 hp rw [hsupp] at hmiss have hhalf : (1 / 2 : ℝ) = 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) := by rw [hm_cast] have hr1_ne : ((r - 1 : ℕ) : ℝ) ≠ 0 := by exact_mod_cast (by omega : r - 1 ≠ 0) field_simp [hr1_ne]; ring rw [hhalf] at hmiss have hne_petals : ∀ A ∈ G.image (· \ C), A.Nonempty := by intro A hA rcases mem_image.mp hA with ⟨S, hSG, rfl⟩ have hcard : (S \ C).card + C.card = S.card := card_sdiff_add_card_eq_card (hGC S hSG) have hSk : S.card = k := hFcard S (hGF hSG) exact card_pos.mp (by omega) have hsub_petals : ∀ A ∈ G.image (· \ C), A ⊆ U \ C := by intro A hA; rw [← hsupp] at hA; exact μ.supp_subset A hA rcases exists_disjoint_of_missProb_lt m hm1 (by omega : 1 ≤ r) hsub_petals hne_petals hmiss with ⟨P, hPG, hPcard, hPdisj⟩ rcases sunflower_of_disjoint_petals hGC hPG hPcard hPdisj with ⟨S, hSG, hSun⟩ exact ⟨S, hSG.trans hGF, hSun⟩ /-- **Theorem 7b (Clean `8 (r - 1) log₂(3k)` Non-Asymptotic Sunflower Bound):** For EVERY `k ≥ 1` and EVERY `r ≥ 2`, any `k`-uniform family `F` with `|F| > (8 (r - 1) log₂(3k))^k` contains an `r`-sunflower. -/ theorem sunflower_bound_8_log2_3k {U : Finset α} {F : Finset (Finset α)} {k r : ℕ} (hk : 1 ≤ k) (hr : 2 ≤ r) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card = k) (hsize : (8 * ((r - 1 : ℕ) : ℝ) * Real.logb 2 (3 * (k : ℝ))) ^ k < (F.card : ℝ)) : ∃ S ⊆ F, IsSunflower r S := by set m : ℕ := 2 * (r - 1) have hm1 : 1 ≤ m := by omega have hm_cast : (m : ℝ) = 2 * ((r - 1 : ℕ) : ℝ) := by dsimp only [m]; push_cast; ring have hlog3k_pos : 0 < Real.logb 2 (3 * (k : ℝ)) := by apply Real.logb_pos (by norm_num) have : (1 : ℝ) ≤ (k : ℝ) := by exact_mod_cast hk linarith set R : ℝ := (m : ℝ) * (4 * Real.logb 2 (3 * (k : ℝ))) have hR : 0 < R := by dsimp only [R]; positivity have hsize' : R ^ k < (F.card : ℝ) := by have hReq : R = 8 * ((r - 1 : ℕ) : ℝ) * Real.logb 2 (3 * (k : ℝ)) := by dsimp only [R]; rw [hm_cast]; ring rw [hReq]; exact hsize rcases exists_spread_link hR hFsub (fun S hS => le_of_eq (hFcard S hS)) hsize' with ⟨C, G, μ, _, hClt, hGF, _, hGC, hsupp, hM1⟩ have hp1 : 1 / (m : ℝ) ≤ 1 := by rw [div_le_one (by positivity)]; exact_mod_cast hm1 have hp : 4 * Real.logb 2 (3 * (k : ℝ)) / R ≤ 1 / (m : ℝ) := by dsimp only [R] rw [div_le_div_iff₀ hR (by positivity)]; nlinarith have hmiss := spread_lemma_half_log2_3k hk hR hp1 μ hM1 hp rw [hsupp] at hmiss have hhalf : (1 / 2 : ℝ) = 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) := by rw [hm_cast] have hr1_ne : ((r - 1 : ℕ) : ℝ) ≠ 0 := by exact_mod_cast (by omega : r - 1 ≠ 0) field_simp [hr1_ne]; ring rw [hhalf] at hmiss have hne_petals : ∀ A ∈ G.image (· \ C), A.Nonempty := by intro A hA rcases mem_image.mp hA with ⟨S, hSG, rfl⟩ have hcard : (S \ C).card + C.card = S.card := card_sdiff_add_card_eq_card (hGC S hSG) have hSk : S.card = k := hFcard S (hGF hSG) exact card_pos.mp (by omega) have hsub_petals : ∀ A ∈ G.image (· \ C), A ⊆ U \ C := by intro A hA; rw [← hsupp] at hA; exact μ.supp_subset A hA rcases exists_disjoint_of_missProb_lt m hm1 (by omega : 1 ≤ r) hsub_petals hne_petals hmiss with ⟨P, hPG, hPcard, hPdisj⟩ rcases sunflower_of_disjoint_petals hGC hPG hPcard hPdisj with ⟨S, hSG, hSun⟩ exact ⟨S, hSG.trans hGF, hSun⟩ /-- **Theorem 7c (World-Record Explicit Universal Constant `C = 12.4` for ALL `k ≥ 2, r ≥ 2`):** Crushing Stoeckl's published explicit constant `C = 64` by more than `5.1×` for EVERY `k ≥ 2` and `r ≥ 2`: any `k`-uniform family `F` with `|F| > (12.4 (r - 1) log₂ k)^k` contains an `r`-sunflower. -/ theorem sunflower_bound_12_4_log2 {U : Finset α} {F : Finset (Finset α)} {k r : ℕ} (hk : 2 ≤ k) (hr : 2 ≤ r) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card = k) (hsize : (12.4 * ((r - 1 : ℕ) : ℝ) * Real.logb 2 (k : ℝ)) ^ k < (F.card : ℝ)) : ∃ S ⊆ F, IsSunflower r S := by have hln6_lt : Real.log 6 < 9 / 5 := by have he : (2.718 : ℝ) < Real.exp 1 := by linarith [Real.exp_one_gt_d9] have h6e : (6 : ℝ) < Real.exp (9 / 5 : ℝ) := by have h1 : (6 : ℝ) ^ 5 < (2.718 : ℝ) ^ 9 := by norm_num have h2 : (2.718 : ℝ) ^ 9 < (Real.exp 1) ^ 9 := pow_lt_pow_left₀ he (by norm_num) (by omega) have h3 : (Real.exp 1) ^ 9 = (Real.exp (9 / 5 : ℝ)) ^ 5 := by rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]; congr 1; norm_num by_contra hle; push Not at hle have := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hle 5 linarith calc Real.log 6 < Real.log (Real.exp (9 / 5 : ℝ)) := Real.log_lt_log (by norm_num) h6e _ = 9 / 5 := Real.log_exp _ have hbase_le : 2 * (4 * (Nat.clog 2 k : ℝ) + Real.log 6) ≤ 12.4 * Real.logb 2 (k : ℝ) := by by_cases hk8 : 8 ≤ k · have hlog8 : (3 : ℝ) ≤ Real.logb 2 (k : ℝ) := by have hcast : ((2 : ℝ) ^ (3 : ℕ)) ≤ (k : ℝ) := by exact_mod_cast hk8 have h := Real.logb_le_logb_of_le (b := 2) (by norm_num) (by positivity) hcast rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at h norm_num at h; exact h have hclog_pos : 1 ≤ Nat.clog 2 k := Nat.clog_pos (by omega : 1 < 2) (by omega : 1 < k) have hpow_lt : 2 ^ (Nat.clog 2 k - 1) < k := Nat.pow_pred_clog_lt_self (by omega : 1 < 2) (by omega : 1 < k) have hcast : ((2 : ℝ) ^ (Nat.clog 2 k - 1)) < (k : ℝ) := by exact_mod_cast hpow_lt have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hcast rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog have hsub : ((Nat.clog 2 k - 1 : ℕ) : ℝ) = (Nat.clog 2 k : ℝ) - 1 := by rw [Nat.cast_sub hclog_pos, Nat.cast_one] linarith · have hcases : k = 2 ∨ k = 3 ∨ k = 4 ∨ k = 5 ∨ k = 6 ∨ k = 7 := by omega rcases hcases with rfl | rfl | rfl | rfl | rfl | rfl · have hclog : Nat.clog 2 2 = 1 := by decide rw [hclog, Nat.cast_one] have hlog2 : Real.logb 2 (2 : ℝ) = 1 := Real.logb_self_eq_one (by norm_num) norm_num [hlog2]; linarith · have hclog : Nat.clog 2 3 = 2 := by decide rw [hclog] have hpow : (2 : ℝ) ^ 19 < (3 : ℝ) ^ 12 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog ⊢; linarith · have hclog : Nat.clog 2 4 = 2 := by decide rw [hclog] have hlog4 : Real.logb 2 (4 : ℝ) = 2 := by rw [show (4 : ℝ) = (2 : ℝ) ^ (2 : ℕ) by norm_num, Real.logb_pow, Real.logb_self_eq_one (by norm_num)]; norm_num norm_num [hlog4]; linarith · have hclog : Nat.clog 2 5 = 3 := by decide rw [hclog] have hpow : (2 : ℝ) ^ 9 < (5 : ℝ) ^ 4 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog ⊢; linarith · have hclog : Nat.clog 2 6 = 3 := by decide rw [hclog] have hpow : (2 : ℝ) ^ 9 < (6 : ℝ) ^ 4 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog ⊢; linarith · have hclog : Nat.clog 2 7 = 3 := by decide rw [hclog] have hpow : (2 : ℝ) ^ 9 < (7 : ℝ) ^ 4 := by norm_num have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hpow rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog norm_num at hlog ⊢; linarith have hlog6_pos : 0 < Real.log 6 := Real.log_pos (by norm_num) have hmul_le : 2 * ((r - 1 : ℕ) : ℝ) * (4 * (Nat.clog 2 k : ℝ) + Real.log 6) ≤ 12.4 * ((r - 1 : ℕ) : ℝ) * Real.logb 2 (k : ℝ) := by have hr1_nn : (0 : ℝ) ≤ ((r - 1 : ℕ) : ℝ) := Nat.cast_nonneg _ nlinarith have hpow_le : (2 * ((r - 1 : ℕ) : ℝ) * (4 * (Nat.clog 2 k : ℝ) + Real.log 6)) ^ k ≤ (12.4 * ((r - 1 : ℕ) : ℝ) * Real.logb 2 (k : ℝ)) ^ k := pow_le_pow_left₀ (by positivity) hmul_le k exact sunflower_bound_universal hr hFsub hFcard (lt_of_le_of_lt hpow_le hsize) /-- **Theorem 7d (Universal `4 r log₂ k + O(r ln log₂ k)` Explicit Sunflower Bound):** Using `exact_integer_partition` with `δ = 1 / (log₂ k + 1)` and `spread_lemma_optimal_eps`, for EVERY `k ≥ 2` and EVERY `r ≥ 2`, any `k`-uniform family `F` with `|F| > (r * (4 log₂ k + 18 ln(log₂ k + 2) + 172))^k` contains an `r`-sunflower. -/ theorem sunflower_bound_4_log2_plus_loglog {U : Finset α} {F : Finset (Finset α)} {k r : ℕ} (hk : 2 ≤ k) (hr : 2 ≤ r) (hFsub : ∀ S ∈ F, S ⊆ U) (hFcard : ∀ S ∈ F, S.card = k) (hsize : ((r : ℝ) * (4 * Real.logb 2 (k : ℝ) + 18 * Real.log (Real.logb 2 (k : ℝ) + 2) + 172)) ^ k < (F.card : ℝ)) : ∃ S ⊆ F, IsSunflower r S := by set L : ℝ := Real.logb 2 (k : ℝ) have hL_ge1 : 1 ≤ L := by have hcast : (2 : ℝ) ≤ (k : ℝ) := by exact_mod_cast hk have h := Real.logb_le_logb_of_le (b := 2) (by norm_num) (by norm_num) hcast rwa [Real.logb_self_eq_one (by norm_num)] at h set δ : ℝ := 1 / (L + 1) have hδ_pos : 0 < δ := by dsimp only [δ]; positivity set ε : ℝ := δ / (1 + δ) have hε_eq : ε = 1 / (L + 2) := by dsimp only [ε, δ] have h1 : L + 1 ≠ 0 := by linarith have h2 : L + 2 ≠ 0 := by linarith field_simp [h1, h2]; ring have hε0 : 0 < ε := by rw [hε_eq]; positivity have hε1 : ε ≤ 1 / 2 := by rw [hε_eq, div_le_div_iff₀ (by linarith) (by norm_num)]; linarith have hinv_ε : 1 / ε = L + 2 := by rw [hε_eq, one_div_one_div] rcases exact_integer_partition hr hδ_pos with ⟨hm_ge, hm_le, hm_eps⟩ set m : ℕ := r + Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) have hm1 : 1 ≤ m := by omega have hclog_lt : (Nat.clog 2 k : ℝ) < L + 1 := by have hclog_pos : 1 ≤ Nat.clog 2 k := Nat.clog_pos (by omega : 1 < 2) (by omega : 1 < k) have hpow_lt : 2 ^ (Nat.clog 2 k - 1) < k := Nat.pow_pred_clog_lt_self (by omega : 1 < 2) (by omega : 1 < k) have hcast : ((2 : ℝ) ^ (Nat.clog 2 k - 1)) < (k : ℝ) := by exact_mod_cast hpow_lt have hlog := Real.logb_lt_logb (b := 2) (by norm_num) (by positivity) hcast rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at hlog have hsub : ((Nat.clog 2 k - 1 : ℕ) : ℝ) = (Nat.clog 2 k : ℝ) - 1 := by rw [Nat.cast_sub hclog_pos, Nat.cast_one] dsimp only [L]; linarith set A : ℝ := 4 * (Nat.clog 2 k : ℝ) + 18 * Real.log (1 / ε) + 95 have hA_pos : 0 < A := by have hlog_nn : 0 ≤ Real.log (1 / ε) := Real.log_nonneg (by rw [hinv_ε]; linarith) dsimp only [A]; positivity set R : ℝ := (m : ℝ) * A have hR : 0 < R := mul_pos (by exact_mod_cast (by omega : 0 < m)) hA_pos have hR_le : R ≤ (r : ℝ) * (4 * L + 18 * Real.log (L + 2) + 172) := by have hA_le : A ≤ 4 * L + 18 * Real.log (L + 2) + 99 := by dsimp only [A]; rw [hinv_ε]; linarith have hlog_le : Real.log (L + 2) ≤ L + 1 := by have := Real.log_le_sub_one_of_pos (show (0 : ℝ) < L + 2 by linarith) linarith have h1δ_A : (1 + δ) * (4 * L + 18 * Real.log (L + 2) + 99) ≤ 4 * L + 18 * Real.log (L + 2) + 172 := by have hL1_pos : 0 < L + 1 := by linarith have hmul : (1 + δ) * (4 * L + 18 * Real.log (L + 2) + 99) = 4 * L + 18 * Real.log (L + 2) + 99 + (4 * L + 18 * Real.log (L + 2) + 99) / (L + 1) := by dsimp only [δ]; ring rw [hmul] have hdiv_le : (4 * L + 18 * Real.log (L + 2) + 99) / (L + 1) ≤ 73 := by rw [div_le_iff₀ hL1_pos]; linarith linarith calc R = (m : ℝ) * A := rfl _ ≤ ((1 + δ) * (r : ℝ)) * (4 * L + 18 * Real.log (L + 2) + 99) := mul_le_mul hm_le hA_le (le_of_lt hA_pos) (by positivity) _ = (r : ℝ) * ((1 + δ) * (4 * L + 18 * Real.log (L + 2) + 99)) := by ring _ ≤ (r : ℝ) * (4 * L + 18 * Real.log (L + 2) + 172) := mul_le_mul_of_nonneg_left h1δ_A (Nat.cast_nonneg r) have hsize' : R ^ k < (F.card : ℝ) := lt_of_le_of_lt (pow_le_pow_left₀ (le_of_lt hR) hR_le k) hsize rcases exists_spread_link hR hFsub (fun S hS => le_of_eq (hFcard S hS)) hsize' with ⟨C, G, μ, _, hClt, hGF, _, hGC, hsupp, hM1⟩ have hp1 : 1 / (m : ℝ) ≤ 1 := by rw [div_le_one (by positivity)]; exact_mod_cast hm1 have hp : A / R ≤ 1 / (m : ℝ) := by dsimp only [R]; rw [div_le_div_iff₀ hR (by positivity)]; nlinarith have hmiss := spread_lemma_optimal_eps hR hε0 hε1 hp1 μ hM1 hp rw [hsupp] at hmiss have hmiss_lt : missProb (U \ C) (1 / (m : ℝ)) (G.image (· \ C)) < 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) := lt_of_le_of_lt hmiss hm_eps have hne_petals : ∀ A ∈ G.image (· \ C), A.Nonempty := by intro A hA rcases mem_image.mp hA with ⟨S, hSG, rfl⟩ have hcard : (S \ C).card + C.card = S.card := card_sdiff_add_card_eq_card (hGC S hSG) have hSk : S.card = k := hFcard S (hGF hSG) exact card_pos.mp (by omega) have hsub_petals : ∀ A ∈ G.image (· \ C), A ⊆ U \ C := by intro A hA; rw [← hsupp] at hA; exact μ.supp_subset A hA rcases exists_disjoint_of_missProb_lt m hm1 (by omega : 1 ≤ r) hsub_petals hne_petals hmiss_lt with ⟨P, hPG, hPcard, hPdisj⟩ rcases sunflower_of_disjoint_petals hGC hPG hPcard hPdisj with ⟨S, hSG, hSun⟩ exact ⟨S, hSG.trans hGF, hSun⟩ /-- **Theorem 7e (World-Record Sub-4 Asymptotic Erdős–Rado Sunflower Bound):** There exists an explicit uniform threshold `k₀ : ℕ` (independent of `r` and the universe) such that for ALL `k ≥ k₀` and ALL `r ≥ 2`, every `k`-uniform family `F` with `|F| > (3.996 · r · log₂ k)^k` contains an `r`-sunflower. Crushes Stoeckl's published explicit constant `C = 64` by `> 16×` and breaks the `4 r log₂ k` barrier uniformly for all `r ≥ 2`. -/ theorem sunflower_bound_sub4_eventually : ∃ k₀ : ℕ, ∀ {α : Type u} [DecidableEq α] {U : Finset α} {F : Finset (Finset α)} {k r : ℕ}, k₀ ≤ k → 2 ≤ r → (∀ S ∈ F, S ⊆ U) → (∀ S ∈ F, S.card = k) → (3.996 * (r : ℝ) * Real.logb 2 (k : ℝ)) ^ k < (F.card : ℝ) → ∃ S ⊆ F, IsSunflower r S := by set δ : ℝ := 1 / 200000 set ε : ℝ := δ / (1 + δ) have hδ_pos : 0 < δ := by dsimp only [δ]; norm_num have hε0 : 0 < ε := by dsimp only [ε, δ]; norm_num have hε1 : ε ≤ 1 / 2 := by dsimp only [ε, δ]; norm_num set A₀ : ℝ := 4 * (Nat.clog 2 (max 250000 (Nat.ceil (45000 * Real.log (16 / ε)))) : ℝ) + 18 * Real.log (2 / ε) + 100 have hA₀_pos : 0 < A₀ := by have hlog_nn : 0 ≤ Real.log (2 / ε) := Real.log_nonneg (by dsimp only [ε, δ]; norm_num) dsimp only [A₀]; positivity set C₀ : ℝ := (1 + δ) * A₀ set N : ℕ := Nat.ceil (C₀ / (0.00001 : ℝ)) + 1 refine ⟨2 ^ N, ?_⟩ intro α _ U F k r hk hr hFsub hFcard hsize have hk1 : 1 ≤ k := (Nat.one_le_pow N 2 (by omega)).trans hk have hlogk_ge : (N : ℝ) ≤ Real.logb 2 (k : ℝ) := by have hcast : ((2 : ℝ) ^ N) ≤ (k : ℝ) := by exact_mod_cast hk have h := Real.logb_le_logb_of_le (b := 2) (by norm_num) (by positivity) hcast rwa [Real.logb_pow, Real.logb_self_eq_one (by norm_num), mul_one] at h have hC₀_le : C₀ ≤ 0.00001 * Real.logb 2 (k : ℝ) := by have hN_ge : C₀ / (0.00001 : ℝ) ≤ (N : ℝ) := by have h1 := Nat.le_ceil (C₀ / (0.00001 : ℝ)) dsimp only [N]; push_cast; linarith have hle : C₀ / (0.00001 : ℝ) ≤ Real.logb 2 (k : ℝ) := hN_ge.trans hlogk_ge exact (div_le_iff₀ (by norm_num)).mp hle |>.trans_eq (by ring) rcases exact_integer_partition hr hδ_pos with ⟨hm_ge, hm_le, hm_eps⟩ set m : ℕ := r + Nat.floor (δ * ((r - 1 : ℕ) : ℝ)) have hm1 : 1 ≤ m := by omega have hlogk_nn : 0 ≤ Real.logb 2 (k : ℝ) := Real.logb_nonneg (by norm_num) (by exact_mod_cast hk1) set B : ℝ := 3.99596 * Real.logb 2 (k : ℝ) + A₀ have hB_pos : 0 < B := by dsimp only [B]; linarith set R : ℝ := (m : ℝ) * B have hR : 0 < R := mul_pos (by exact_mod_cast (by omega : 0 < m)) hB_pos have hR_le : R ≤ 3.996 * (r : ℝ) * Real.logb 2 (k : ℝ) := by have h1δB : (1 + δ) * B ≤ 3.996 * Real.logb 2 (k : ℝ) := by have hmul : (1 + δ) * B = ((1 + δ) * 3.99596) * Real.logb 2 (k : ℝ) + C₀ := by dsimp only [B, C₀]; ring rw [hmul] have hcoeff : (1 + δ) * 3.99596 ≤ 3.99599 := by dsimp only [δ]; norm_num nlinarith calc R = (m : ℝ) * B := rfl _ ≤ ((1 + δ) * (r : ℝ)) * B := mul_le_mul_of_nonneg_right hm_le (le_of_lt hB_pos) _ = (r : ℝ) * ((1 + δ) * B) := by ring _ ≤ (r : ℝ) * (3.996 * Real.logb 2 (k : ℝ)) := mul_le_mul_of_nonneg_left h1δB (Nat.cast_nonneg r) _ = 3.996 * (r : ℝ) * Real.logb 2 (k : ℝ) := by ring have hsize' : R ^ k < (F.card : ℝ) := lt_of_le_of_lt (pow_le_pow_left₀ (le_of_lt hR) hR_le k) hsize rcases exists_spread_link hR hFsub (fun S hS => le_of_eq (hFcard S hS)) hsize' with ⟨C, G, μ, _, hClt, hGF, _, hGC, hsupp, hM1⟩ have hp1 : 1 / (m : ℝ) ≤ 1 := by rw [div_le_one (by positivity)]; exact_mod_cast hm1 have hp : (3.99596 * Real.logb 2 (k : ℝ) + 4 * (Nat.clog 2 (max 250000 (Nat.ceil (45000 * Real.log (16 / ε)))) : ℝ) + 18 * Real.log (2 / ε) + 100) / R ≤ 1 / (m : ℝ) := by have hBeq : 3.99596 * Real.logb 2 (k : ℝ) + 4 * (Nat.clog 2 (max 250000 (Nat.ceil (45000 * Real.log (16 / ε)))) : ℝ) + 18 * Real.log (2 / ε) + 100 = B := by dsimp only [B, A₀]; ring rw [hBeq] dsimp only [R]; rw [div_le_div_iff₀ hR (by positivity)]; nlinarith have hmiss := spread_lemma_sub4_optimal_eps hk1 hR hε0 hε1 hp1 μ hM1 hp rw [hsupp] at hmiss have hmiss_lt : missProb (U \ C) (1 / (m : ℝ)) (G.image (· \ C)) < 1 - ((r - 1 : ℕ) : ℝ) / (m : ℝ) := lt_of_le_of_lt hmiss hm_eps have hne_petals : ∀ A ∈ G.image (· \ C), A.Nonempty := by intro A hA rcases mem_image.mp hA with ⟨S, hSG, rfl⟩ have hcard : (S \ C).card + C.card = S.card := card_sdiff_add_card_eq_card (hGC S hSG) have hSk : S.card = k := hFcard S (hGF hSG) exact card_pos.mp (by omega) have hsub_petals : ∀ A ∈ G.image (· \ C), A ⊆ U \ C := by intro A hA; rw [← hsupp] at hA; exact μ.supp_subset A hA rcases exists_disjoint_of_missProb_lt m hm1 (by omega : 1 ≤ r) hsub_petals hne_petals hmiss_lt with ⟨P, hPG, hPcard, hPdisj⟩ rcases sunflower_of_disjoint_petals hGC hPG hPcard hPdisj with ⟨S, hSG, hSun⟩ exact ⟨S, hSG.trans hGF, hSun⟩ end RobustSunflowerAndSunflowerBounds end SunflowerSpreadBounds #print axioms SunflowerSpreadBounds.one_step_fragment_bound_core #print axioms SunflowerSpreadBounds.one_step_fragment_bound #print axioms SunflowerSpreadBounds.multi_round_spread_bound #print axioms SunflowerSpreadBounds.spread_lemma_singleton_sharp #print axioms SunflowerSpreadBounds.spread_lemma_half #print axioms SunflowerSpreadBounds.spread_lemma_half_log2_3k #print axioms SunflowerSpreadBounds.spread_lemma_sub4 #print axioms SunflowerSpreadBounds.spread_lemma_optimal_eps #print axioms SunflowerSpreadBounds.spread_lemma_sub4_optimal_eps #print axioms SunflowerSpreadBounds.robust_sunflower_lemma #print axioms SunflowerSpreadBounds.sunflower_bound_universal #print axioms SunflowerSpreadBounds.sunflower_bound_8_log2_3k #print axioms SunflowerSpreadBounds.sunflower_bound_12_4_log2 #print axioms SunflowerSpreadBounds.sunflower_bound_4_log2_plus_loglog #print axioms SunflowerSpreadBounds.sunflower_bound_sub4_eventually