import Mathlib namespace OAI namespace CubeShuffle.DimensionEstimates open scoped BigOperators lemma log_factorial_upper_binary (n : ℕ) (hn : 0 norm_num | succ n hn ih => have hn0 : (0:ℝ) norm_num | succ n hn ih => have hn0 : (0:ℝ) norm_num | succ n hn ih => have hn0 : (0:ℝ) congrArg u x.property) _ = _ := by simp [fiberWeight] lemma sum_fiberWeight (f : X → I) : ∑ i, fiberWeight f i=Fintype.card X := by have h := fiber_sum f (fun _ => 1) simpa using h.symm /-- Entropy subadditivity for a finite simple bipartite incidence set. -/ theorem incidence_entropy (f : X → I) (g : X → J) (hinj : Function.Injective (fun x => (f x,g x))) : (∑ i, fiberWeight f i*Real.log (fiberWeight f i))+ (∑ j, fiberWeight g j*Real.log (fiberWeight g j)) ≤ (Fintype.card X:ℝ)*Real.log (Fintype.card X) := by by_cases hX : Nonempty X · let : Nonempty X := hX have hN : (0:ℝ) (f x,g x)), fiberWeight f p.1*fiberWeight g p.2 := by rw [Finset.sum_image (fun x _ y _ h => hinj h)] _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun p _ _ => mul_nonneg (fiberWeight_nonneg f p.1) (fiberWeight_nonneg g p.2)) _ = _ := by rw [Fintype.sum_prod_type] simp_rw [←Finset.mul_sum] rw [←Finset.sum_mul,sum_fiberWeight,sum_fiberWeight,pow_two] have hdiv : (∑ x, fiberWeight f (f x)*fiberWeight g (g x))/(Fintype.card X:ℝ) ≤ Fintype.card X := by apply (div_le_iff₀ hN).mpr simpa only [pow_two] using hprod have hl (x : X) := Real.log_le_sub_one_of_pos (show 0 hl x) simp_rw [Real.log_div (mul_pos (fiberWeight_pos f _) (fiberWeight_pos g _)).ne' hN.ne', Real.log_mul (fiberWeight_pos f _).ne' (fiberWeight_pos g _).ne'] at hs rw [Finset.sum_sub_distrib,Finset.sum_add_distrib, fiber_sum f (fun i => Real.log (fiberWeight f i)), fiber_sum g (fun j => Real.log (fiberWeight g j)), Finset.sum_sub_distrib,←Finset.sum_div] at hs simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hs linarith · let : IsEmpty X := not_nonempty_iff.mp hX have hf (i : I) : fiberWeight f i=0 := by simp [fiberWeight] have hg (j : J) : fiberWeight g j=0 := by simp [fiberWeight] simp [hf,hg] end Bipartite end CubeShuffle.DimensionEstimates namespace CubeShuffle.DimensionEstimates open scoped BigOperators Classical lemma log_factorial_upper_binary_all (n : ℕ) : Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by by_cases hn : n=0 · subst n simpa using (Real.log_nonneg (by norm_num : (1:ℝ)≤2)) · exact log_factorial_upper_binary n (Nat.pos_of_ne_zero hn) lemma log_fiber_factorials {X I : Type*} [Fintype X] [Fintype I] (f : X → I) : Real.log ((∏ i, (Fintype.card {x // f x=i}).factorial : ℕ):ℝ) ≤ ∑ i, fiberWeight f i*Real.log (fiberWeight f i) - Real.log 2*((Fintype.card X:ℝ)-Fintype.card I) := by rw [Nat.cast_prod,Real.log_prod (fun _ _ => by positivity)] have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => log_factorial_upper_binary_all (Fintype.card {x // f x=i})) change ∑ i, Real.log ((Fintype.card {x // f x=i}).factorial:ℝ) ≤ ∑ i, (fiberWeight f i*Real.log (fiberWeight f i)-Real.log 2*(fiberWeight f i-1)) at h rw [Finset.sum_sub_distrib,←Finset.mul_sum,Finset.sum_sub_distrib,sum_fiberWeight] at h simpa using h /-- A dimension lower bound using only the actual row and column subgroup orders, incidence injectivity, and elementary factorial estimates. -/ theorem dimension_log_from_incidence {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] [Nonempty X] (f : X → I) (g : X → J) (hinj : Function.Injective (fun x => (f x,g x))) (D : ℕ) (hD : (Fintype.card X).factorial ≤ D * (∏ i, (Fintype.card {x // f x=i}).factorial) * (∏ j, (Fintype.card {x // g x=j}).factorial)) : ((2*Real.log 2-1)*(Fintype.card X:ℝ)- Real.log 2*((Fintype.card I:ℝ)+Fintype.card J)+1) ≤ Real.log D := by have hd : 0 Real.log (n:ℝ)) (Nat.choose_mul_factorial_mul_factorial hjN.le) simp only [Nat.cast_mul] at hfac rw [Real.log_mul (mul_pos hchoose (by positivity)).ne' (by positivity), Real.log_mul hchoose.ne' (by positivity)] at hfac have hlo := log_factorial_lower N hN have hji := log_factorial_upper j hj have hti := log_factorial_upper (N-j) ht have hjlog := Real.log_le_log hj0 hjN0.le have htlog := Real.log_le_log (by exact_mod_cast ht : (0:ℝ)<(N-j:ℕ)) (by exact_mod_cast Nat.sub_le N j : ((N-j:ℕ):ℝ)≤N) rw [Nat.cast_sub hjN.le] at hti htlog rw [scaled_binEntropy N j hN0 hj0 hjN0] linarith lemma binEntropy_three_quarters : Real.binEntropy (3/4:ℝ)=2*Real.log 2-(3/4:ℝ)*Real.log 3 := by have h4 : Real.log (4:ℝ)=2*Real.log 2 := by rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num unfold Real.binEntropy norm_num only [show (1-(3/4:ℝ))=1/4 by norm_num] rw [Real.log_div (by norm_num) (by norm_num),h4] ring noncomputable def entropyGap : ℝ := Real.log (32/27:ℝ)/3 lemma entropyGap_pos : 0 norm_num) (show (3/4:ℝ)∈Set.Icc 0 1 by constructor <;> norm_num) (show 0≤1-4*q/3 by linarith) (show 0≤4*q/3 by positivity) (show (1-4*q/3)+(4*q/3)=1 by ring) simp only [Real.binEntropy_zero,binEntropy_three_quarters,smul_eq_mul,mul_zero,zero_add] at hc have he : 4*q/3*(3/4:ℝ)=q := by ring rw [he] at hc rw [entropyGap_eq] linarith lemma log_dimension_from_binomial (N j D : ℕ) (hj : 0.1 have he : (j:ℝ)*x=N := by dsimp [x]; field_simp have hk := (chosenTuple_bounds N j hj hx hhalf).2.2 change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower at hk have hratio : (chosenTuple N j:ℝ)/N≤2*x^(nearPower-1) := by rw [Real.rpow_sub hxp,Real.rpow_one] apply (div_le_iff₀ hNp).mpr rw [←he] have : 2*(x^nearPower/x)*((j:ℝ)*x)=2*(j:ℝ)*x^nearPower := by field_simp rw [this] exact hk have hpow := Real.rpow_le_rpow (by positivity : (0:ℝ)≤(chosenTuple N j:ℝ)/N) hratio (by norm_num : (0:ℝ)≤1/512) have hmain := mul_le_mul hk hpow (by positivity) (by positivity) have hrpow : (2*x^(nearPower-1))^(1/512:ℝ)= (2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)) := by rw [Real.mul_rpow (by norm_num) (by positivity),←Real.rpow_mul hxp.le] rw [hrpow] at hmain have heq : 2*(j:ℝ)*x^nearPower*((2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)))= (2:ℝ)^(1+(1/512:ℝ))*(j:ℝ)*x^(-tailPower) := by rw [Real.rpow_add (by norm_num : (0:ℝ)<2),Real.rpow_one] have hp : nearPower+(nearPower-1)*(1/512) = -tailPower := by norm_num [nearPower,tailPower] rw [←hp,Real.rpow_add hxp] ring rw [heq] at hmain have h := mul_le_mul_of_nonneg_left hmain hC simpa only [mul_assoc] using h /-- All cutoffs are absolute. In particular the near-row density cost can be made smaller than the genuine footprint logarithm, uniformly over that range. -/ lemma near_conditions_eventually (C : ℝ) : ∀ᶠ x : ℝ in atTop, 2≤x ∧ 2≤x^nearPower ∧ x^(nearPower-1)≤1/2 ∧ 8*Real.log 2/nearPower≤Real.log x ∧ 4*Real.log 2+2≤Real.log x ∧ C*2^(1+(1/512:ℝ))*x^(-tailPower) ≤ nearFraction/4000 := by have hpow := (tendsto_rpow_atTop (by norm_num [nearPower] : 0 C*2^(1+(1/512:ℝ))*x^(-tailPower)) atTop (nhds 0) := by simpa only [mul_zero] using (tendsto_const_nhds.mul (tendsto_rpow_neg_atTop (by norm_num [tailPower] : 0 x) Finset.univ simpa only [Finset.prod_const,Finset.card_univ,Finset.powerset_univ] using h.symm lemma small_sets_count {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : (∑ E : Finset ι, if (E.card:ℝ)<ε*Fintype.card ι then (1:ℝ) else 0) ≤ Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by have hpow (E : Finset ι) : (Real.exp (-t))^E.card=Real.exp (-t*(E.card:ℝ)) := by rw [←Real.exp_nat_mul] congr 1 ring calc _ ≤ ∑ E : Finset ι, Real.exp (t*ε*Fintype.card ι)*(Real.exp (-t))^E.card := by apply Finset.sum_le_sum intro E _ split_ifs with hE · rw [hpow,←Real.exp_add,←Real.exp_zero] apply Real.exp_le_exp.mpr nlinarith [mul_le_mul_of_nonneg_left hE.le ht] · positivity _ = Real.exp (t*ε*Fintype.card ι)*(1+Real.exp (-t))^Fintype.card ι := by rw [←Finset.mul_sum,finset_power_sum] _ = _ := by have he : (1+Real.exp (-t))^Fintype.card ι= Real.exp (Real.log (1+Real.exp (-t))*(Fintype.card ι:ℝ)) := by rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)] rw [he,←Real.exp_add] congr 1 ring lemma small_sets_ceil_bound {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : (∑ E : Finset ι, if E.card<⌈ε*Fintype.card ι⌉₊ then (1:ℝ) else 0) ≤ Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by have he (E : Finset ι) : E.card<⌈ε*Fintype.card ι⌉₊ ↔ (E.card:ℝ)<ε*Fintype.card ι := Nat.lt_ceil simp only [he] exact small_sets_count ε t ht /-- The exceptional-subset entropy rate can be made arbitrarily small by shrinking its positive fraction, after every other absolute parameter is fixed. -/ lemma exists_small_set_rate (κ ε₀ : ℝ) (hκ : 0<κ) (hε₀ : 0<ε₀) : ∃ ε : ℝ, 0<ε ∧ ε≤ε₀ ∧ ε<1/2 ∧ ∃ t : ℝ, 0≤t ∧ t*ε+Real.log (1+Real.exp (-t))≤κ := by have ht : Tendsto (fun t : ℝ => Real.log (1+Real.exp (-t))) atTop (nhds 0) := by have he : Tendsto (fun t : ℝ => Real.exp (-t)) atTop (nhds 0) := Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot have hl := (tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0) simpa only [add_zero,Real.log_one] using hl obtain ⟨t,ht,hlog⟩ := ((eventually_ge_atTop (1:ℝ)).and (ht.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists let ε := min ε₀ (min (1/4) (κ/(2*t))) have htp : 0 rw [←Real.exp_log hθ,←Real.exp_nat_mul] apply Real.exp_le_exp.mpr have hg := mul_le_mul_of_nonpos_left (Nat.le_ceil (ε*M)) (Real.log_nonpos hθ.le hθ1.le) nlinarith end CubeShuffle.DimensionEstimates namespace CubeShuffle.DimensionEstimates open Filter lemma twopow_tendsto : Tendsto (fun d : ℕ => (2:ℝ)^d) atTop atTop := tendsto_pow_atTop_atTop_of_one_lt (by norm_num) lemma twopow_nat_tendsto : Tendsto (fun d : ℕ => (2:ℕ)^d) atTop atTop := tendsto_pow_atTop_atTop_of_one_lt (by norm_num) lemma twopow_mul_eventually (c : ℝ) (hc : 0.trans_eq (mul_comm _ _) lemma exp_two_absorb (β n : ℝ) (hx : Real.log 2≤β*n/2) : Real.exp (-β*n)+Real.exp (-β*n)≤Real.exp (-β*n/2) := by calc _ = Real.exp (Real.log 2-β*n) := by rw [Real.exp_sub,Real.exp_log (by norm_num)]; rw [neg_mul,Real.exp_neg]; ring _ ≤ _ := Real.exp_le_exp.mpr (by linarith) end CubeShuffle.DimensionEstimates end OAI