Download data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/JointExtractionRates.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 33.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/JointExtractionRates.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/JointExtractionRates.lean
-
curl -L -o JointExtractionRates.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/JointExtractionRates.lean
33.6 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Construction.JointAPFree | |
| import OAI.LinearAlgebra.MatrixFields.Extraction.ComplexFiniteSeparation | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| section | |
| noncomputable section | |
| namespace MatrixMultiplication.Foundation.Separation | |
| open Filter | |
| private theorem scale_exists (K : β) : β n : β, K β€ 2 ^ (n ^ 2) := by | |
| refine β¨K + 1, ?_β© | |
| have hK : K < 2 ^ K := Nat.lt_pow_self (by decide : 1 < 2) | |
| exact hK.le.trans (Nat.pow_le_pow_right (by decide) (by nlinarith)) | |
| noncomputable def gridScale (K : β) : β := Nat.find (scale_exists K) | |
| theorem population_le_scale (K : β) : K β€ 2 ^ ((gridScale K) ^ 2) := | |
| Nat.find_spec (scale_exists K) | |
| theorem previous_scale_lt_population {K : β} (hn : 0 < gridScale K) : | |
| 2 ^ ((gridScale K - 1) ^ 2) < K := by | |
| exact lt_of_not_ge (Nat.find_min (scale_exists K) (Nat.sub_lt hn (by decide))) | |
| theorem scale_pos {K : β} (hK : 1 < K) : 0 < gridScale K := by | |
| have h := population_le_scale K | |
| by_contra hn | |
| have hz : gridScale K = 0 := Nat.eq_zero_of_not_pos hn | |
| simp only [hz, zero_pow (by decide : 2 β 0), pow_zero] at h | |
| exact (not_le_of_gt hK) h | |
| theorem scale_gt_of_population_gt {K n : β} (hK : 2 ^ (n ^ 2) < K) : | |
| n < gridScale K := by | |
| by_contra hn | |
| have hscale : gridScale K β€ n := Nat.le_of_not_gt hn | |
| have hp : 2 ^ ((gridScale K) ^ 2) β€ 2 ^ (n ^ 2) := | |
| Nat.pow_le_pow_right (by decide) (Nat.pow_le_pow_left hscale 2) | |
| exact (not_le_of_gt hK) ((population_le_scale K).trans hp) | |
| theorem gridScale_monotone : Monotone gridScale := by | |
| intro K L hKL | |
| exact Nat.find_min' (scale_exists K) (hKL.trans (population_le_scale L)) | |
| def gridDimension (K : β) : β := gridScale K + 4 | |
| def gridWidth (K : β) : β := 2 ^ (gridScale K + 2) | |
| def gridGroupOrder (K : β) : β := (4 * gridWidth K) ^ gridDimension K | |
| theorem gridDimension_pos (K : β) : 0 < gridDimension K := by | |
| simp [gridDimension] | |
| theorem gridWidth_ge_two (K : β) : 2 β€ gridWidth K := by | |
| simpa only [gridWidth, pow_one] using | |
| (Nat.pow_le_pow_right (by decide : 0 < 2) (by omega : 1 β€ gridScale K + 2)) | |
| private theorem dimension_le_power (n : β) : n + 4 β€ 2 ^ (n + 2) := by | |
| induction n with | |
| | zero => norm_num | |
| | succ n ih => | |
| have hp : 2 ^ (n + 2 + 1) = 2 ^ (n + 2) * 2 := pow_succ _ _ | |
| have he : n + 1 + 2 = n + 2 + 1 := by omega | |
| rw [he, hp] | |
| omega | |
| theorem grid_population_bound (K : β) : | |
| (gridDimension K * gridWidth K ^ 2 + 1) * K β€ | |
| gridWidth K ^ gridDimension K := by | |
| let n := gridScale K | |
| have hd : n + 4 β€ 2 ^ (n + 2) := dimension_le_power n | |
| have hq : 0 < 2 ^ (n + 2) := by positivity | |
| have hcolorpos : 0 < (n + 4) * (2 ^ (n + 2)) ^ 2 := by positivity | |
| have hcolor : (n + 4) * (2 ^ (n + 2)) ^ 2 + 1 β€ 2 ^ (3 * n + 7) := by | |
| calc | |
| (n + 4) * (2 ^ (n + 2)) ^ 2 + 1 β€ | |
| 2 * ((n + 4) * (2 ^ (n + 2)) ^ 2) := by nlinarith | |
| _ β€ 2 * (2 ^ (n + 2) * (2 ^ (n + 2)) ^ 2) := by gcongr | |
| _ = 2 ^ (3 * n + 7) := by | |
| rw [β pow_mul, β pow_add, β pow_succ'] | |
| congr 1 | |
| omega | |
| calc | |
| (gridDimension K * gridWidth K ^ 2 + 1) * K β€ | |
| 2 ^ (3 * n + 7) * 2 ^ (n ^ 2) := | |
| Nat.mul_le_mul hcolor (population_le_scale K) | |
| _ = 2 ^ (3 * n + 7 + n ^ 2) := (pow_add _ _ _).symm | |
| _ β€ 2 ^ ((n + 2) * (n + 4)) := | |
| Nat.pow_le_pow_right (by decide) (by nlinarith) | |
| _ = gridWidth K ^ gridDimension K := by | |
| simp only [gridWidth, gridDimension, n, pow_mul] | |
| theorem gridGroupOrder_eq (K : β) : | |
| gridGroupOrder K = 2 ^ ((gridScale K + 4) ^ 2) := by | |
| unfold gridGroupOrder gridWidth gridDimension | |
| have hb : 4 * 2 ^ (gridScale K + 2) = 2 ^ (gridScale K + 4) := by | |
| calc | |
| 4 * 2 ^ (gridScale K + 2) = 2 ^ 2 * 2 ^ (gridScale K + 2) := by norm_num | |
| _ = 2 ^ (2 + (gridScale K + 2)) := (pow_add _ _ _).symm | |
| _ = 2 ^ (gridScale K + 4) := by congr 1; omega | |
| rw [hb, β pow_mul, pow_two] | |
| theorem gridGroupOrder_pos (K : β) : 0 < gridGroupOrder K := by | |
| rw [gridGroupOrder_eq] | |
| positivity | |
| theorem population_le_gridGroupOrder (K : β) : K β€ gridGroupOrder K := by | |
| rw [gridGroupOrder_eq] | |
| exact (population_le_scale K).trans | |
| (Nat.pow_le_pow_right (by decide) | |
| (Nat.pow_le_pow_left (Nat.le_add_right (gridScale K) 4) 2)) | |
| theorem gridGroupOrder_monotone : Monotone gridGroupOrder := by | |
| intro K L hKL | |
| rw [gridGroupOrder_eq, gridGroupOrder_eq] | |
| exact Nat.pow_le_pow_right (by decide) | |
| (Nat.pow_le_pow_left (Nat.add_le_add_right (gridScale_monotone hKL) 4) 2) | |
| theorem asymptotic_grid_tags_slices (K : β) : | |
| β tags : Finset (Grid (gridDimension K) (gridWidth K)), tags.card = K β§ | |
| (β radius : Fin (gridDimension K * gridWidth K ^ 2 + 1), | |
| β t β tags, normColor t = radius) β§ | |
| β t β tags, β slice : Finset (Grid (gridDimension K) (gridWidth K)), | |
| slice.card = K β§ β level : Fin (gridDimension K * gridWidth K ^ 2 + 1), | |
| β u β slice, dotColor t u = level := | |
| grid_tags_slices (grid_population_bound K) (grid_population_bound K) | |
| theorem log_gridGroupOrder (K : β) : | |
| Real.log (gridGroupOrder K : β) = ((gridScale K : β) + 4) ^ 2 * Real.log 2 := by | |
| rw [gridGroupOrder_eq, Nat.cast_pow, Real.log_pow] | |
| norm_cast | |
| theorem log_population_le_log_gridGroupOrder {K : β} (hK : 0 < K) : | |
| Real.log (K : β) β€ Real.log (gridGroupOrder K : β) := by | |
| exact Real.log_le_log (by exact_mod_cast hK) | |
| (by exact_mod_cast population_le_gridGroupOrder K) | |
| theorem previous_scale_log_lt {K : β} (hK : 1 < K) : | |
| ((gridScale K : β) - 1) ^ 2 * Real.log 2 < Real.log (K : β) := by | |
| have hn : 1 β€ gridScale K := scale_pos hK | |
| have hp : (0 : β) < (2 : β) ^ ((gridScale K - 1) ^ 2) := by positivity | |
| have hc : (2 : β) ^ ((gridScale K - 1) ^ 2) < (K : β) := by | |
| exact_mod_cast previous_scale_lt_population (scale_pos hK) | |
| have h := Real.log_lt_log hp hc | |
| simpa only [Real.log_pow, Nat.cast_pow, Nat.cast_sub hn, Nat.cast_one] using h | |
| theorem log_gridGroupOrder_le_of_scale {K : β} {Ξ΅ : β} | |
| (hK : 1 < K) (hΞ΅ : 0 β€ Ξ΅) | |
| (hscale : 10 * (gridScale K : β) + 15 β€ | |
| Ξ΅ * ((gridScale K : β) - 1) ^ 2) : | |
| Real.log (gridGroupOrder K : β) β€ (1 + Ξ΅) * Real.log (K : β) := by | |
| have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) | |
| have hpoly : ((gridScale K : β) + 4) ^ 2 β€ | |
| (1 + Ξ΅) * ((gridScale K : β) - 1) ^ 2 := by nlinarith | |
| calc | |
| Real.log (gridGroupOrder K : β) = | |
| ((gridScale K : β) + 4) ^ 2 * Real.log 2 := log_gridGroupOrder K | |
| _ β€ ((1 + Ξ΅) * ((gridScale K : β) - 1) ^ 2) * Real.log 2 := | |
| mul_le_mul_of_nonneg_right hpoly hlog2.le | |
| _ = (1 + Ξ΅) * (((gridScale K : β) - 1) ^ 2 * Real.log 2) := by ring | |
| _ β€ (1 + Ξ΅) * Real.log (K : β) := | |
| mul_le_mul_of_nonneg_left (previous_scale_log_lt hK).le (by positivity) | |
| private theorem scale_error_bound {n Ξ΅ : β} (hn : 2 β€ n) (hΞ΅ : 0 β€ Ξ΅) | |
| (hlarge : 72 β€ Ξ΅ * n) : 10 * n + 15 β€ Ξ΅ * (n - 1) ^ 2 := by | |
| have hsq : n ^ 2 β€ 4 * (n - 1) ^ 2 := by nlinarith | |
| have hmul := mul_le_mul_of_nonneg_left hsq hΞ΅ | |
| have hlarge' := mul_le_mul_of_nonneg_right hlarge (by linarith : 0 β€ n) | |
| nlinarith | |
| theorem eventually_log_gridGroupOrder_le {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) : | |
| βαΆ K : β in atTop, | |
| Real.log (gridGroupOrder K : β) β€ (1 + Ξ΅) * Real.log (K : β) := by | |
| obtain β¨m : β, hmβ© := exists_nat_gt (max 2 (72 / Ξ΅)) | |
| refine eventually_atTop.2 β¨2 ^ (m ^ 2) + 1, ?_β© | |
| intro K hK | |
| have hKm : 2 ^ (m ^ 2) < K := by omega | |
| have hn := scale_gt_of_population_gt hKm | |
| have hnR : (m : β) < (gridScale K : β) := by exact_mod_cast hn | |
| have hm2 : 2 < (m : β) := (le_max_left _ _).trans_lt hm | |
| have hmΞ΅ : 72 / Ξ΅ < (m : β) := (le_max_right _ _).trans_lt hm | |
| have hnΞ΅ : 72 β€ Ξ΅ * (gridScale K : β) := by | |
| have hdiv : 72 / Ξ΅ < (gridScale K : β) := hmΞ΅.trans hnR | |
| have hmul := (div_lt_iffβ hΞ΅).1 hdiv | |
| nlinarith | |
| have hKone : 1 < K := by | |
| have hp : 1 β€ 2 ^ (m ^ 2) := Nat.one_le_pow _ _ (by decide) | |
| omega | |
| exact log_gridGroupOrder_le_of_scale hKone hΞ΅.le | |
| (scale_error_bound (by linarith) hΞ΅.le hnΞ΅) | |
| theorem uniform_log_gridGroupOrder_le {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) : | |
| β C : β, 0 β€ C β§ β K : β, | |
| Real.log (gridGroupOrder K : β) β€ (1 + Ξ΅) * Real.log (K : β) + C := by | |
| obtain β¨Kβ, hKββ© := eventually_atTop.1 (eventually_log_gridGroupOrder_le hΞ΅) | |
| refine β¨Real.log (gridGroupOrder Kβ : β), Real.log_natCast_nonneg _, ?_β© | |
| intro K | |
| by_cases hK : Kβ β€ K | |
| Β· exact (hKβ K hK).trans (le_add_of_nonneg_right (Real.log_natCast_nonneg _)) | |
| Β· have horder : gridGroupOrder K β€ gridGroupOrder Kβ := | |
| gridGroupOrder_monotone (Nat.le_of_lt (Nat.lt_of_not_ge hK)) | |
| have hpos : (0 : β) < (gridGroupOrder K : β) := by | |
| rw [gridGroupOrder_eq, Nat.cast_pow] | |
| positivity | |
| have hcast : (gridGroupOrder K : β) β€ (gridGroupOrder Kβ : β) := by | |
| exact_mod_cast horder | |
| have hlog := Real.log_le_log hpos hcast | |
| have hnonneg : 0 β€ (1 + Ξ΅) * Real.log (K : β) := | |
| mul_nonneg (by linarith) (Real.log_natCast_nonneg K) | |
| linarith | |
| theorem tendsto_log_gridGroupOrder_div_log_population : | |
| Tendsto (fun K : β => Real.log (gridGroupOrder K : β) / Real.log (K : β)) | |
| atTop (nhds 1) := by | |
| refine tendsto_order.2 β¨?_, ?_β© | |
| Β· intro a ha | |
| refine eventually_atTop.2 β¨2, ?_β© | |
| intro K hK | |
| have hKone : 1 < K := by omega | |
| have hlog : 0 < Real.log (K : β) := | |
| Real.log_pos (by exact_mod_cast hKone) | |
| have hle := log_population_le_log_gridGroupOrder (by omega : 0 < K) | |
| exact ha.trans_le ((le_div_iffβ hlog).2 (by simpa using hle)) | |
| Β· intro b hb | |
| have he : 0 < (b - 1) / 2 := by linarith | |
| filter_upwards [eventually_log_gridGroupOrder_le he, | |
| (eventually_atTop.2 β¨2, fun K (hK : 2 β€ K) => hKβ©)] with K hcost hK | |
| have hlog : 0 < Real.log (K : β) := | |
| Real.log_pos (by exact_mod_cast (show 1 < K by omega)) | |
| have hratio : Real.log (gridGroupOrder K : β) / Real.log (K : β) β€ | |
| 1 + (b - 1) / 2 := (div_le_iffβ hlog).2 hcost | |
| linarith | |
| theorem tendsto_log_gridGroupOrder_div_nat {K : β β β} {H : β} | |
| (hK : β N, 0 < K N) (hH : 0 β€ H) | |
| (hpop : Tendsto (fun N => Real.log (K N : β) / (N : β)) atTop (nhds H)) : | |
| Tendsto (fun N => Real.log (gridGroupOrder (K N) : β) / (N : β)) | |
| atTop (nhds H) := by | |
| refine tendsto_order.2 β¨?_, ?_β© | |
| Β· intro a ha | |
| filter_upwards [(tendsto_order.1 hpop).1 a ha, | |
| (eventually_atTop.2 β¨1, fun N (hN : 1 β€ N) => hNβ©)] with N haN hN | |
| have hNpos : (0 : β) < (N : β) := by exact_mod_cast hN | |
| exact haN.trans_le (div_le_div_of_nonneg_right | |
| (log_population_le_log_gridGroupOrder (hK N)) hNpos.le) | |
| Β· intro b hb | |
| let Ξ΅ := (b - H) / (2 * (H + 1)) | |
| have hdenom : 0 < 2 * (H + 1) := by linarith | |
| have hΞ΅ : 0 < Ξ΅ := div_pos (by linarith) hdenom | |
| obtain β¨C, hC, hboundβ© := uniform_log_gridGroupOrder_le hΞ΅ | |
| have hΞ΅eq : Ξ΅ * (2 * (H + 1)) = b - H := div_mul_cancelβ _ hdenom.ne' | |
| have hlimitlt : (1 + Ξ΅) * H < b := by nlinarith | |
| have hconstant : Tendsto (fun N : β => C / (N : β)) atTop (nhds 0) := | |
| tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop | |
| have hupper : Tendsto | |
| (fun N : β => (1 + Ξ΅) * (Real.log (K N : β) / (N : β)) + C / (N : β)) | |
| atTop (nhds ((1 + Ξ΅) * H)) := by | |
| simpa using (hpop.const_mul (1 + Ξ΅)).add hconstant | |
| filter_upwards [(tendsto_order.1 hupper).2 b hlimitlt, | |
| (eventually_atTop.2 β¨1, fun N (hN : 1 β€ N) => hNβ©)] with N hbN hN | |
| have hNpos : (0 : β) < (N : β) := by exact_mod_cast hN | |
| have hle := div_le_div_of_nonneg_right (hbound (K N)) hNpos.le | |
| have heq : ((1 + Ξ΅) * Real.log (K N : β) + C) / (N : β) = | |
| (1 + Ξ΅) * (Real.log (K N : β) / (N : β)) + C / (N : β) := by ring | |
| rw [heq] at hle | |
| exact hle.trans_lt hbN | |
| theorem log_nat_prod {I : Type*} (s : Finset I) (a : I β β) | |
| (ha : β i β s, 0 < a i) : | |
| Real.log ((β i β s, a i : β) : β) = β i β s, Real.log (a i : β) := by | |
| rw [Nat.cast_prod] | |
| exact Real.log_prod fun i hi => | |
| Nat.cast_ne_zero.mpr (Nat.ne_of_gt (ha i hi)) | |
| theorem tendsto_log_nat_prod_div_nat {I : Type*} (s : Finset I) | |
| {K : I β β β β} {H : I β β} | |
| (hK : β i β s, β N, 0 < K i N) | |
| (hpop : β i β s, | |
| Tendsto (fun N => Real.log (K i N : β) / (N : β)) atTop (nhds (H i))) : | |
| Tendsto (fun N => Real.log ((β i β s, K i N : β) : β) / (N : β)) | |
| atTop (nhds (β i β s, H i)) := by | |
| have hsum := tendsto_finsetSum s hpop | |
| apply hsum.congr | |
| intro N | |
| rw [log_nat_prod s (fun i => K i N) (fun i hi => hK i hi N)] | |
| simp only [div_eq_mul_inv, Finset.sum_mul] | |
| theorem tendsto_log_gridGroupOrder_prod_div_nat {I : Type*} (s : Finset I) | |
| {K : I β β β β} {H : I β β} | |
| (hK : β i β s, β N, 0 < K i N) (hH : β i β s, 0 β€ H i) | |
| (hpop : β i β s, | |
| Tendsto (fun N => Real.log (K i N : β) / (N : β)) atTop (nhds (H i))) : | |
| Tendsto (fun N => Real.log ((β i β s, gridGroupOrder (K i N) : β) : β) / (N : β)) | |
| atTop (nhds (β i β s, H i)) := by | |
| exact tendsto_log_nat_prod_div_nat s (fun i hi N => gridGroupOrder_pos (K i N)) | |
| (fun i hi => tendsto_log_gridGroupOrder_div_nat (hK i hi) (hH i hi) (hpop i hi)) | |
| theorem tendsto_log_nat_weighted_prod_div_nat {I : Type*} (s : Finset I) (w : I β β) | |
| {K : I β β β β} {H : I β β} | |
| (hK : β i β s, β N, 0 < K i N) | |
| (hpop : β i β s, | |
| Tendsto (fun N => Real.log (K i N : β) / (N : β)) atTop (nhds (H i))) : | |
| Tendsto (fun N => Real.log ((β i β s, (K i N) ^ w i : β) : β) / (N : β)) | |
| atTop (nhds (β i β s, (w i : β) * H i)) := by | |
| apply tendsto_log_nat_prod_div_nat s | |
| Β· intro i hi N | |
| exact pow_pos (hK i hi N) _ | |
| Β· intro i hi | |
| simpa only [Nat.cast_pow, Real.log_pow, mul_div_assoc] using | |
| (hpop i hi).const_mul (w i : β) | |
| theorem tendsto_log_gridGroupOrder_weighted_prod_div_nat {I : Type*} | |
| (s : Finset I) (w : I β β) {K : I β β β β} {H : I β β} | |
| (hK : β i β s, β N, 0 < K i N) (hH : β i β s, 0 β€ H i) | |
| (hpop : β i β s, | |
| Tendsto (fun N => Real.log (K i N : β) / (N : β)) atTop (nhds (H i))) : | |
| Tendsto | |
| (fun N => Real.log ((β i β s, gridGroupOrder (K i N) ^ w i : β) : β) / (N : β)) | |
| atTop (nhds (β i β s, (w i : β) * H i)) := by | |
| exact tendsto_log_nat_weighted_prod_div_nat s w | |
| (fun i hi N => gridGroupOrder_pos (K i N)) | |
| (fun i hi => tendsto_log_gridGroupOrder_div_nat (hK i hi) (hH i hi) (hpop i hi)) | |
| end MatrixMultiplication.Foundation.Separation | |
| namespace MatrixMultiplication.JointExtractionRates | |
| open Filter | |
| open scoped BigOperators Topology | |
| def goodCount {Ξ© E : Type*} [Fintype E] (good : Ξ© β E β Prop) (Ο : Ξ©) : β := by | |
| classical | |
| exact (Finset.univ.filter (good Ο)).card | |
| def goodIncidence {Ξ© E : Type*} [Fintype Ξ©] (good : Ξ© β E β Prop) (e : E) : β := by | |
| classical | |
| exact (Finset.univ.filter (fun Ο => good Ο e)).card | |
| theorem sum_goodCount_eq_sum_goodIncidence {Ξ© E : Type*} [Fintype Ξ©] [Fintype E] | |
| (good : Ξ© β E β Prop) : | |
| (β Ο, goodCount good Ο) = β e, goodIncidence good e := by | |
| classical | |
| simp only [goodCount, goodIncidence, Finset.card_filter] | |
| exact Finset.sum_comm | |
| theorem exists_goodCount_ge {Ξ© E : Type*} [Fintype Ξ©] [Nonempty Ξ©] [Fintype E] | |
| (good : Ξ© β E β Prop) (q : β) | |
| (hinc : β e, q * (Fintype.card Ξ© : β) β€ (goodIncidence good e : β)) : | |
| β Ο, (Fintype.card E : β) * q β€ (goodCount good Ο : β) := by | |
| have hsum := Finset.sum_le_sum (fun e (_ : e β Finset.univ) => hinc e) | |
| have hdouble : (β Ο, (goodCount good Ο : β)) = | |
| β e, (goodIncidence good e : β) := by | |
| exact_mod_cast sum_goodCount_eq_sum_goodIncidence good | |
| have havg : (β _Ο : Ξ©, (Fintype.card E : β) * q) β€ | |
| β Ο, (goodCount good Ο : β) := by | |
| rw [hdouble] | |
| simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_assoc, | |
| mul_comm, mul_left_comm] using hsum | |
| obtain β¨Ο, _, hΟβ© := Finset.exists_le_of_sum_le Finset.univ_nonempty havg | |
| exact β¨Ο, hΟβ© | |
| theorem exists_good_subfamily {Ξ© E : Type*} [Fintype E] | |
| (good : Ξ© β E β Prop) (Ο : Ξ©) (K : β) (hK : K β€ goodCount good Ο) : | |
| β G : Finset E, G.card = K β§ β e β G, good Ο e := by | |
| classical | |
| obtain β¨G, hG, hcardβ© := Finset.exists_subset_card_eq | |
| (s := Finset.univ.filter (good Ο)) (by simpa only [goodCount] using hK) | |
| exact β¨G, hcard, fun e he => (Finset.mem_filter.mp (hG he)).2β© | |
| theorem eventually_exists_good_subfamily {Ξ© E : β β Type*} | |
| [β N, Fintype (E N)] | |
| (good : β N, Ξ© N β E N β Prop) (K : β β β) | |
| (hK : βαΆ N in atTop, β Ο : Ξ© N, K N β€ goodCount (good N) Ο) : | |
| βαΆ N in atTop, β (Ο : Ξ© N) (G : Finset (E N)), | |
| G.card = K N β§ β e β G, good N Ο e := by | |
| filter_upwards [hK] with N hN | |
| obtain β¨Ο, hΟβ© := hN | |
| obtain β¨G, hcard, hgoodβ© := exists_good_subfamily (good N) Ο (K N) hΟ | |
| exact β¨Ο, G, hcard, hgoodβ© | |
| theorem incidence_lower_of_survival_and_loss {Ξ© E : Type*} [Fintype Ξ©] | |
| (survives bad : Ξ© β E β Prop) (e : E) (s Ξ΅ : β) | |
| (hs : s * (Fintype.card Ξ© : β) β€ (goodIncidence survives e : β)) | |
| (hb : (goodIncidence (fun Ο e => survives Ο e β§ bad Ο e) e : β) β€ | |
| s * Ξ΅ * (Fintype.card Ξ© : β)) : | |
| s * (1 - Ξ΅) * (Fintype.card Ξ© : β) β€ | |
| (goodIncidence (fun Ο e => survives Ο e β§ Β¬ bad Ο e) e : β) := by | |
| classical | |
| have hsplit : goodIncidence (fun Ο e => survives Ο e β§ bad Ο e) e + | |
| goodIncidence (fun Ο e => survives Ο e β§ Β¬ bad Ο e) e = | |
| goodIncidence survives e := by | |
| simp only [goodIncidence, Finset.card_filter, β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro Ο _ | |
| by_cases hs : survives Ο e <;> by_cases hb : bad Ο e <;> simp [hs, hb] | |
| have hsplitR : | |
| (goodIncidence (fun Ο e => survives Ο e β§ bad Ο e) e : β) + | |
| (goodIncidence (fun Ο e => survives Ο e β§ Β¬ bad Ο e) e : β) = | |
| (goodIncidence survives e : β) := by | |
| exact_mod_cast hsplit | |
| nlinarith | |
| theorem exists_goodCount_ge_half_survival {Ξ© E : Type*} | |
| [Fintype Ξ©] [Nonempty Ξ©] [Fintype E] | |
| (survives bad : Ξ© β E β Prop) (s Ξ΅ : β) (hsβ : 0 β€ s) (hΞ΅ : Ξ΅ β€ 1 / 2) | |
| (hs : β e, s * (Fintype.card Ξ© : β) β€ (goodIncidence survives e : β)) | |
| (hb : β e, (goodIncidence (fun Ο e => survives Ο e β§ bad Ο e) e : β) β€ | |
| s * Ξ΅ * (Fintype.card Ξ© : β)) : | |
| β Ο, (Fintype.card E : β) * (s / 2) β€ | |
| (goodCount (fun Ο e => survives Ο e β§ Β¬ bad Ο e) Ο : β) := by | |
| apply exists_goodCount_ge | |
| intro e | |
| have h := incidence_lower_of_survival_and_loss survives bad e s Ξ΅ (hs e) (hb e) | |
| have hc : (0 : β) β€ Fintype.card Ξ© := Nat.cast_nonneg _ | |
| have hm := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hΞ΅ hsβ) hc | |
| nlinarith | |
| theorem tendsto_polynomial_mul_exp_neg (d : β) {c : β} (hc : 0 < c) : | |
| Tendsto (fun N : β => ((N : β) + 1) ^ d * Real.exp (-c * (N : β))) | |
| atTop (π 0) := by | |
| have hbase := (Real.summable_pow_mul_exp_neg_nat_mul d hc).tendsto_atTop_zero | |
| have hshift := (hbase.comp (tendsto_add_atTop_nat 1)).mul_const (Real.exp c) | |
| simp only [zero_mul, Function.comp_apply, Nat.cast_add, Nat.cast_one] at hshift | |
| convert hshift using 1 | |
| ext N | |
| rw [mul_assoc, β Real.exp_add] | |
| congr 2 | |
| ring | |
| theorem eventually_error_le_half {error : β β β} (B : β) (d : β) | |
| {c : β} (hc : 0 < c) | |
| (hbound : βαΆ N in atTop, | |
| error N β€ B * (((N : β) + 1) ^ d * Real.exp (-c * (N : β)))) : | |
| βαΆ N in atTop, error N β€ 1 / 2 := by | |
| have hlim := (tendsto_polynomial_mul_exp_neg d hc).const_mul B | |
| have hsmall : βαΆ N : β in atTop, | |
| B * (((N : β) + 1) ^ d * Real.exp (-c * (N : β))) < 1 / 2 := by | |
| simpa only [mul_zero] using (tendsto_order.1 hlim).2 (1 / 2) (by simp) | |
| filter_upwards [hbound, hsmall] with N hb hs | |
| exact hb.trans hs.le | |
| theorem tendsto_log_one_sub_error_div_nat {error : β β β} | |
| (herror : Tendsto error atTop (π 0)) : | |
| Tendsto (fun N => Real.log (1 - error N) / (N : β)) atTop (π 0) := by | |
| have hone : Tendsto (fun N => 1 - error N) atTop (π (1 : β)) := by | |
| simpa using (tendsto_const_nhds : | |
| Tendsto (fun _ : β => (1 : β)) atTop (π 1)).sub herror | |
| exact (hone.log one_ne_zero).div_atTop tendsto_natCast_atTop_atTop | |
| def hashModulus (H : β) (N : β) : β := | |
| 37 ^ (β(N : β) * H / Real.log 37ββ + 1) | |
| theorem hashModulus_ge (H : β) (N : β) : 37 β€ hashModulus H N := by | |
| simpa only [hashModulus, pow_one] using | |
| (Nat.pow_le_pow_right (by norm_num : 0 < 37) | |
| (show 1 β€ β(N : β) * H / Real.log 37ββ + 1 by omega)) | |
| theorem hashModulus_log_bounds {H : β} (hH : 0 β€ H) (N : β) : | |
| (N : β) * H β€ Real.log (hashModulus H N : β) β§ | |
| Real.log (hashModulus H N : β) β€ (N : β) * H + Real.log 37 := by | |
| have hl : 0 < Real.log (37 : β) := Real.log_pos (by norm_num) | |
| have harg : 0 β€ (N : β) * H / Real.log 37 := | |
| div_nonneg (mul_nonneg (Nat.cast_nonneg N) hH) hl.le | |
| have hfloor := mul_le_mul_of_nonneg_right (Nat.floor_le harg) hl.le | |
| have hceil := mul_lt_mul_of_pos_right | |
| (Nat.lt_floor_add_one ((N : β) * H / Real.log 37)) hl | |
| have hcancel : (N : β) * H / Real.log 37 * Real.log 37 = (N : β) * H := | |
| div_mul_cancelβ _ hl.ne' | |
| simp only [hashModulus, Nat.cast_pow, Real.log_pow, Nat.cast_add, Nat.cast_one] | |
| constructor <;> nlinarith | |
| theorem tendsto_log_hashModulus_div_nat {H : β} (hH : 0 β€ H) : | |
| Tendsto (fun N => Real.log (hashModulus H N : β) / (N : β)) | |
| atTop (π H) := by | |
| have hc : Tendsto (fun N : β => Real.log 37 / (N : β)) atTop (π 0) := | |
| tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop | |
| have hu : Tendsto (fun N : β => H + Real.log 37 / (N : β)) atTop (π H) := by | |
| simpa only [add_zero] using hc.const_add H | |
| apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hu | |
| Β· filter_upwards [eventually_ge_atTop (1 : β)] with N hN | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| apply (le_div_iffβ hNr).2 | |
| nlinarith [(hashModulus_log_bounds hH N).1] | |
| Β· filter_upwards [eventually_ge_atTop (1 : β)] with N hN | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| have hb := div_le_div_of_nonneg_right (hashModulus_log_bounds hH N).2 hNr.le | |
| simpa only [add_div, mul_div_cancel_leftβ H hNr.ne'] using hb | |
| theorem eventual_log_upper_of_error {degree : β β β} {error : β β β} {D : β} | |
| (herror : Tendsto (fun N => error N / (N : β)) atTop (π 0)) | |
| (hbound : βαΆ N in atTop, | |
| Real.log (degree N : β) β€ (N : β) * D + error N) | |
| {Ξ· : β} (hΞ· : 0 < Ξ·) : | |
| βαΆ N in atTop, Real.log (degree N : β) / (N : β) β€ D + Ξ· := by | |
| filter_upwards [hbound, (tendsto_order.1 herror).2 Ξ· hΞ·, | |
| eventually_ge_atTop (1 : β)] with N hb he hN | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| have hd := div_le_div_of_nonneg_right hb hNr.le | |
| rw [add_div, mul_div_cancel_leftβ D hNr.ne'] at hd | |
| linarith | |
| theorem eventually_ratio_le_exp_neg_of_log_bounds {degree M : β β β} {D H c : β} | |
| (hdegree : β Ξ· : β, 0 < Ξ· β | |
| βαΆ N in atTop, Real.log (degree N : β) / (N : β) β€ D + Ξ·) | |
| (hpos : βαΆ N in atTop, 0 < M N) | |
| (hM : Tendsto (fun N => Real.log (M N : β) / (N : β)) atTop (π H)) | |
| (hc : c < H - D) : | |
| βαΆ N in atTop, (degree N : β) / (M N : β) β€ Real.exp (-c * (N : β)) := by | |
| let Ξ· : β := (H - D - c) / 3 | |
| have hΞ· : 0 < Ξ· := by dsimp [Ξ·]; linarith | |
| filter_upwards [hdegree Ξ· hΞ·, hpos, | |
| (tendsto_order.1 hM).1 (H - Ξ·) (by linarith), | |
| eventually_ge_atTop (1 : β)] with N hd hp hm hN | |
| by_cases hz : degree N = 0 | |
| Β· simp only [hz, Nat.cast_zero, zero_div] | |
| exact (Real.exp_pos _).le | |
| have hdpos : (0 : β) < degree N := by | |
| exact_mod_cast Nat.pos_of_ne_zero hz | |
| have hmpos : (0 : β) < M N := by exact_mod_cast hp | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| have hdu := (div_le_iffβ hNr).mp hd | |
| have hml := (lt_div_iffβ hNr).mp hm | |
| have hcoefficient : D - H + 2 * Ξ· β€ -c := by dsimp [Ξ·]; linarith | |
| have hscaled := mul_le_mul_of_nonneg_right hcoefficient hNr.le | |
| have hdiff : Real.log (degree N : β) - Real.log (M N : β) β€ | |
| -c * (N : β) := by nlinarith | |
| calc | |
| _ = Real.exp (Real.log (degree N : β) - Real.log (M N : β)) := by | |
| rw [Real.exp_sub, Real.exp_log hdpos, Real.exp_log hmpos] | |
| _ β€ _ := Real.exp_le_exp.mpr hdiff | |
| theorem eventually_degree_div_hashModulus_le_exp {degree : β β β} {D H c : β} | |
| (hH : 0 β€ H) | |
| (hdegree : β Ξ· : β, 0 < Ξ· β | |
| βαΆ N in atTop, Real.log (degree N : β) / (N : β) β€ D + Ξ·) | |
| (hc : c < H - D) : | |
| βαΆ N in atTop, (degree N : β) / (hashModulus H N : β) β€ | |
| Real.exp (-c * (N : β)) := by | |
| apply eventually_ratio_le_exp_neg_of_log_bounds hdegree _ | |
| (tendsto_log_hashModulus_div_nat hH) hc | |
| exact Eventually.of_forall fun N => | |
| lt_of_lt_of_le (by decide : 0 < 37) (hashModulus_ge H N) | |
| theorem tendsto_sqrt_div_nat_of_div_nat {a : β β β} {A : β} | |
| (ha : β N, 0 β€ a N) | |
| (h : Tendsto (fun N => a N / (N : β)) atTop (π A)) : | |
| Tendsto (fun N => Real.sqrt (a N) / (N : β)) atTop (π 0) := by | |
| have hinv : Tendsto (fun N : β => 1 / (N : β)) atTop (π 0) := | |
| tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop | |
| have hp := h.sqrt.mul hinv.sqrt | |
| simp only [Real.sqrt_zero, mul_zero] at hp | |
| convert hp using 1 | |
| ext N | |
| symm | |
| rw [Real.sqrt_div (ha N), Real.sqrt_div (by norm_num : (0 : β) β€ 1), | |
| Real.sqrt_one, div_mul_div_comm, mul_one, Real.mul_self_sqrt (Nat.cast_nonneg N)] | |
| theorem tendsto_log_modularSet_card_div_nat {M : β β β} {H : β} | |
| (hM : βαΆ N in atTop, 2 β€ M N) | |
| (hlog : Tendsto (fun N => Real.log (M N : β) / (N : β)) atTop (π H)) : | |
| Tendsto (fun N => Real.log ((JointAPFree.modularSet (M N)).card : β) / (N : β)) | |
| atTop (π H) := by | |
| have hsqrt := tendsto_sqrt_div_nat_of_div_nat | |
| (fun N => Real.log_natCast_nonneg (M N)) hlog | |
| have hconst : Tendsto (fun N : β => Real.log 3 / (N : β)) atTop (π 0) := | |
| tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop | |
| have hlower : Tendsto (fun N => | |
| (Real.log (M N : β) - Real.log 3 - | |
| 4 * Real.sqrt (Real.log (M N : β))) / (N : β)) | |
| atTop (π H) := by | |
| have h := (hlog.sub hconst).sub (hsqrt.const_mul 4) | |
| simp only [mul_zero, sub_zero] at h | |
| apply h.congr | |
| intro N | |
| ring | |
| apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hlower hlog | |
| Β· filter_upwards [hM] with N hN | |
| exact div_le_div_of_nonneg_right | |
| (JointAPFree.modularSet_log_card_lower_modulus hN) (Nat.cast_nonneg N) | |
| Β· filter_upwards [hM] with N hN | |
| exact div_le_div_of_nonneg_right | |
| (JointAPFree.modularSet_log_card_le_modulus hN) (Nat.cast_nonneg N) | |
| theorem tendsto_log_yield_lower {T U M : β β β} {A B C : β} | |
| (hT : Tendsto (fun N => Real.log (T N : β) / (N : β)) atTop (π A)) | |
| (hU : Tendsto (fun N => Real.log (U N : β) / (N : β)) atTop (π B)) | |
| (hM : Tendsto (fun N => Real.log (M N : β) / (N : β)) atTop (π C)) : | |
| Tendsto (fun N => | |
| (Real.log (T N : β) + Real.log (U N : β) - | |
| 2 * Real.log (M N : β) - Real.log 2) / (N : β)) | |
| atTop (π (A + B - 2 * C)) := by | |
| have hconst : Tendsto (fun N : β => Real.log 2 / (N : β)) atTop (π 0) := | |
| tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop | |
| have h := ((hT.add hU).sub (hM.const_mul 2)).sub hconst | |
| simp only [sub_zero] at h | |
| apply h.congr | |
| intro N | |
| ring | |
| theorem exp_log_yield_lower {T U M : β} (hT : 0 < T) (hU : 0 < U) (hM : 0 < M) : | |
| Real.exp (Real.log (T : β) + Real.log (U : β) - | |
| 2 * Real.log (M : β) - Real.log 2) = | |
| (T : β) * ((U : β) / (M : β) ^ 2 / 2) := by | |
| have hTr : (0 : β) < T := by exact_mod_cast hT | |
| have hUr : (0 : β) < U := by exact_mod_cast hU | |
| have hMr : (0 : β) < M := by exact_mod_cast hM | |
| rw [Real.exp_sub, Real.exp_sub, Real.exp_add, Real.exp_log hTr, | |
| Real.exp_log hUr, Real.exp_log (by norm_num : (0 : β) < 2)] | |
| rw [show 2 * Real.log (M : β) = Real.log ((M : β) ^ 2) by | |
| rw [Real.log_pow]; norm_num, Real.exp_log (pow_pos hMr 2)] | |
| ring | |
| theorem eventually_floor_exp_le_of_log_lower {Y : β β β} {L : β β β} {R : β} | |
| (hL : Tendsto (fun N => L N / (N : β)) atTop (π R)) | |
| (hY : βαΆ N in atTop, Real.exp (L N) β€ (Y N : β)) | |
| {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) : | |
| βαΆ N : β in atTop, βReal.exp ((N : β) * (R - Ξ΅))ββ β€ Y N := by | |
| filter_upwards [(tendsto_order.1 hL).1 (R - Ξ΅) (by linarith), hY, | |
| (eventually_atTop.2 β¨1, fun N (hN : 1 β€ N) => hNβ©)] with N hrate hy hN | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| have hexp : Real.exp ((N : β) * (R - Ξ΅)) β€ (Y N : β) := by | |
| apply le_trans (Real.exp_le_exp.mpr ?_) hy | |
| have hm := (lt_div_iffβ hNr).mp hrate | |
| nlinarith | |
| simpa only [Nat.floor_natCast] using Nat.floor_le_floor hexp | |
| theorem eventually_exists_many_good | |
| {Ξ© E : β β Type*} [β N, Fintype (Ξ© N)] [β N, Nonempty (Ξ© N)] | |
| [β N, Fintype (E N)] | |
| (good : β N, Ξ© N β E N β Prop) (U M : β β β) {A H : β} | |
| (hpos : βαΆ N in atTop, 0 < Fintype.card (E N) β§ 0 < U N β§ 0 < M N) | |
| (hinc : βαΆ N in atTop, β e, | |
| ((U N : β) / (M N : β) ^ 2 / 2) * (Fintype.card (Ξ© N) : β) β€ | |
| (goodIncidence (good N) e : β)) | |
| (hE : Tendsto (fun N => Real.log (Fintype.card (E N) : β) / (N : β)) | |
| atTop (π A)) | |
| (hU : Tendsto (fun N => Real.log (U N : β) / (N : β)) atTop (π H)) | |
| (hM : Tendsto (fun N => Real.log (M N : β) / (N : β)) atTop (π H)) | |
| {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) : | |
| βαΆ N in atTop, β Ο : Ξ© N, | |
| βReal.exp ((N : β) * (A - H - Ξ΅))ββ β€ goodCount (good N) Ο := by | |
| let L : β β β := fun N => Real.log (Fintype.card (E N) : β) + | |
| Real.log (U N : β) - 2 * Real.log (M N : β) - Real.log 2 | |
| have hL : Tendsto (fun N => L N / (N : β)) atTop (π (A - H)) := by | |
| simpa only [L, show A + H - 2 * H = A - H by ring] using | |
| tendsto_log_yield_lower hE hU hM | |
| filter_upwards [hpos, hinc, (tendsto_order.1 hL).1 (A - H - Ξ΅) (by linarith), | |
| (eventually_atTop.2 β¨1, fun N (hN : 1 β€ N) => hNβ©)] with N hp hi hr hN | |
| obtain β¨Ο, hΟβ© := exists_goodCount_ge (good N) _ hi | |
| refine β¨Ο, ?_β© | |
| have heq := exp_log_yield_lower hp.1 hp.2.1 hp.2.2 | |
| have hNr : (0 : β) < N := by exact_mod_cast hN | |
| have he : Real.exp ((N : β) * (A - H - Ξ΅)) β€ | |
| (goodCount (good N) Ο : β) := by | |
| calc | |
| _ β€ Real.exp (L N) := Real.exp_le_exp.mpr (by | |
| have hm := (lt_div_iffβ hNr).mp hr | |
| nlinarith) | |
| _ = _ := heq | |
| _ β€ _ := hΟ | |
| simpa only [Nat.floor_natCast] using Nat.floor_le_floor he | |
| theorem eventually_exists_many_good_explicit | |
| {Ξ© E : β β Type*} [β N, Fintype (Ξ© N)] [β N, Nonempty (Ξ© N)] | |
| [β N, Fintype (E N)] | |
| (good : β N, Ξ© N β E N β Prop) {A H : β} (hH : 0 β€ H) | |
| (hpos : βαΆ N in atTop, 0 < Fintype.card (E N)) | |
| (hinc : βαΆ N in atTop, β e, | |
| (((JointAPFree.modularSet (hashModulus H N)).card : β) / | |
| (hashModulus H N : β) ^ 2 / 2) * (Fintype.card (Ξ© N) : β) β€ | |
| (goodIncidence (good N) e : β)) | |
| (hE : Tendsto (fun N => Real.log (Fintype.card (E N) : β) / (N : β)) | |
| atTop (π A)) | |
| {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) : | |
| βαΆ N in atTop, β Ο : Ξ© N, | |
| βReal.exp ((N : β) * (A - H - Ξ΅))ββ β€ goodCount (good N) Ο := by | |
| have hM : β N, 2 β€ hashModulus H N := fun N => | |
| (by norm_num : 2 β€ 37).trans (hashModulus_ge H N) | |
| have hr := tendsto_log_hashModulus_div_nat hH | |
| apply eventually_exists_many_good good | |
| (fun N => (JointAPFree.modularSet (hashModulus H N)).card) (hashModulus H) | |
| _ hinc hE (tendsto_log_modularSet_card_div_nat (Eventually.of_forall hM) hr) hr hΞ΅ | |
| filter_upwards [hpos] with N hN | |
| exact β¨hN, JointAPFree.modularSet_card_pos (hM N), | |
| lt_of_lt_of_le (by decide : 0 < 2) (hM N)β© | |
| theorem fixed_product_subexponential {I : Type*} (s : Finset I) (R : I β β β β) | |
| (hpos : β i β s, β N, 0 < R i N) | |
| (hR : β i β s, | |
| Tendsto (fun N => Real.log (R i N : β) / (N : β)) atTop (π 0)) : | |
| Tendsto (fun N => Real.log ((β i β s, R i N : β) : β) / (N : β)) | |
| atTop (π 0) := by | |
| simpa only [Finset.sum_const_zero] using | |
| MatrixMultiplication.Foundation.Separation.tendsto_log_nat_prod_div_nat s hpos hR | |
| theorem presence_replications_subexponential (L : β β β) | |
| (hL : Tendsto (fun N => (L N : β) / (N : β)) atTop (π 0)) : | |
| Tendsto (fun N => Real.log ((2 ^ (3 * L N) : β) : β) / (N : β)) | |
| atTop (π 0) := by | |
| have h := hL.const_mul (3 * Real.log 2) | |
| simp only [mul_zero] at h | |
| apply h.congr | |
| intro N | |
| rw [Nat.cast_pow, Real.log_pow] | |
| push_cast | |
| ring | |
| end MatrixMultiplication.JointExtractionRates | |
| end | |
| end | |
| end MatrixAllFields | |
| end OAI | |