math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /Entropy /ComplexHierarchySeparationRates.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchySeparationRates.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchySeparationRates.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchySeparationRates.lean
-
curl -L -o ComplexHierarchySeparationRates.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchySeparationRates.lean
15.4 kB
| import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexTypeEntropy | |
| import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexHierarchyTypeCounting | |
| import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexSeparationAsymptotics | |
| import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexLabelHierarchySeparation | |
| namespace OAI | |
| /-! Finite entropy, rate estimates and ordered asymptotic limits. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.Foundation | |
| open Filter | |
| open scoped BigOperators Topology | |
| namespace LabelHierarchySeparation | |
| theorem poolAuxiliaryCost_pos (k : β) : 0 < poolAuxiliaryCost k := by | |
| unfold poolAuxiliaryCost | |
| split_ifs | |
| Β· exact Nat.zero_lt_one | |
| Β· exact Separation.gridGroupOrder_pos k | |
| theorem population_le_poolAuxiliaryCost (k : β) : k β€ poolAuxiliaryCost k := by | |
| unfold poolAuxiliaryCost | |
| split_ifs with hk | |
| Β· simp [hk] | |
| Β· exact Separation.population_le_gridGroupOrder k | |
| theorem poolAuxiliaryCost_le_gridGroupOrder (k : β) : | |
| poolAuxiliaryCost k β€ Separation.gridGroupOrder k := by | |
| unfold poolAuxiliaryCost | |
| split_ifs with hk | |
| Β· simpa only [hk] using Separation.population_le_gridGroupOrder k | |
| Β· exact le_rfl | |
| theorem tendsto_log_poolAuxiliaryCost_div_nat {K : β β β} {H : β} | |
| (hK : β n, 0 < K n) (hH : 0 β€ H) | |
| (hpop : Tendsto (fun n => Real.log (K n : β) / (n : β)) atTop (π H)) : | |
| Tendsto (fun n => Real.log (poolAuxiliaryCost (K n) : β) / (n : β)) | |
| atTop (π H) := by | |
| refine tendsto_of_tendsto_of_tendsto_of_le_of_le hpop | |
| (Separation.tendsto_log_gridGroupOrder_div_nat hK hH hpop) ?_ ?_ | |
| Β· intro n | |
| apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) | |
| exact Real.log_le_log (Nat.cast_pos.mpr (hK n)) | |
| (by exact_mod_cast population_le_poolAuxiliaryCost (K n)) | |
| Β· intro n | |
| apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) | |
| exact Real.log_le_log (Nat.cast_pos.mpr (poolAuxiliaryCost_pos (K n))) | |
| (by exact_mod_cast poolAuxiliaryCost_le_gridGroupOrder (K n)) | |
| end LabelHierarchySeparation | |
| namespace HierarchySeparationRates | |
| universe u v w | |
| def populationEntropyRate {B : Type*} [Fintype B] (counts : B β β) : β := | |
| (β b, counts b : β) * | |
| finiteEntropy (fun b => (counts b : β) / (β b, counts b : β)) | |
| theorem tendsto_log_multinomial_mul_div_repetition {B : Type*} [Fintype B] | |
| (counts : B β β) : | |
| Tendsto | |
| (fun t : β => | |
| Real.log (Nat.multinomial Finset.univ (fun b => t * counts b) : β) / (t : β)) | |
| atTop (π (populationEntropyRate counts)) := by | |
| by_cases hD : 0 < β b, counts b | |
| Β· have hD' : ((β b, counts b : β) : β) β 0 := | |
| Nat.cast_ne_zero.mpr (Nat.ne_of_gt hD) | |
| have h := (tendsto_log_multinomial_mul counts hD).const_mul | |
| ((β b, counts b : β) : β) | |
| apply h.congr | |
| intro t | |
| by_cases ht : t = 0 | |
| Β· simp [ht] | |
| have ht' : (t : β) β 0 := Nat.cast_ne_zero.mpr ht | |
| change ((β b, counts b : β) : β) * | |
| (Real.log (Nat.multinomial Finset.univ (fun b => t * counts b) : β) / | |
| ((t : β) * (β b, counts b : β))) = _ | |
| field_simp [hD', ht'] | |
| Β· have hz : (β b, counts b) = 0 := Nat.eq_zero_of_not_pos hD | |
| have hc (b : B) : counts b = 0 := by | |
| apply Nat.eq_zero_of_le_zero | |
| calc | |
| counts b β€ β c, counts c := | |
| Finset.single_le_sum (fun c _ => Nat.zero_le _) (Finset.mem_univ b) | |
| _ = 0 := hz | |
| simp only [populationEntropyRate, hz, Nat.cast_zero, zero_mul] | |
| simp [Nat.multinomial, hc] | |
| theorem populationEntropyRate_nonneg {B : Type*} [Fintype B] (counts : B β β) : | |
| 0 β€ populationEntropyRate counts := by | |
| apply ge_of_tendsto' (tendsto_log_multinomial_mul_div_repetition counts) | |
| intro t | |
| apply div_nonneg _ (Nat.cast_nonneg t) | |
| apply Real.log_nonneg | |
| exact_mod_cast Nat.one_le_iff_ne_zero.mpr | |
| (Nat.ne_of_gt (Nat.multinomial_pos Finset.univ (fun b => t * counts b))) | |
| section FinitePools | |
| variable {I : Type u} [Fintype I] {Alphabet : I β Type v} | |
| [β i, Fintype (Alphabet i)] | |
| def poolTypeCount (counts : β i, Alphabet i β β) (i : I) (t : β) : β := | |
| Nat.multinomial Finset.univ (fun b => t * counts i b) | |
| def poolEntropyTotal (counts : β i, Alphabet i β β) : β := | |
| β i, populationEntropyRate (counts i) | |
| def pairingProduct (counts : β i, Alphabet i β β) (t : β) : β := | |
| β i, poolTypeCount counts i t | |
| def gridProduct (counts : β i, Alphabet i β β) (t : β) : β := | |
| β i, Separation.gridGroupOrder (poolTypeCount counts i t) | |
| def auxiliaryProduct (counts : β i, Alphabet i β β) (t : β) : β := | |
| β i, LabelHierarchySeparation.poolAuxiliaryCost (poolTypeCount counts i t) | |
| omit [Fintype I] in | |
| theorem poolTypeCount_pos (counts : β i, Alphabet i β β) (i : I) (t : β) : | |
| 0 < poolTypeCount counts i t := Nat.multinomial_pos _ _ | |
| theorem pairingProduct_le_auxiliaryProduct (counts : β i, Alphabet i β β) (t : β) : | |
| pairingProduct counts t β€ auxiliaryProduct counts t := by | |
| exact Finset.prod_le_prod (fun i _ => | |
| LabelHierarchySeparation.population_le_poolAuxiliaryCost (poolTypeCount counts i t)) | |
| theorem auxiliaryProduct_le_gridProduct (counts : β i, Alphabet i β β) (t : β) : | |
| auxiliaryProduct counts t β€ gridProduct counts t := by | |
| exact Finset.prod_le_prod (fun i _ => | |
| LabelHierarchySeparation.poolAuxiliaryCost_le_gridGroupOrder (poolTypeCount counts i t)) | |
| omit [Fintype I] in | |
| theorem tendsto_log_poolTypeCount_div (counts : β i, Alphabet i β β) (i : I) : | |
| Tendsto (fun t : β => Real.log (poolTypeCount counts i t : β) / (t : β)) | |
| atTop (π (populationEntropyRate (counts i))) := | |
| tendsto_log_multinomial_mul_div_repetition (counts i) | |
| theorem tendsto_log_pairingProduct_div (counts : β i, Alphabet i β β) : | |
| Tendsto (fun t : β => Real.log (pairingProduct counts t : β) / (t : β)) | |
| atTop (π (poolEntropyTotal counts)) := by | |
| exact Separation.tendsto_log_nat_prod_div_nat Finset.univ | |
| (fun i _ t => poolTypeCount_pos counts i t) | |
| (fun i _ => tendsto_log_poolTypeCount_div counts i) | |
| theorem tendsto_log_gridProduct_div (counts : β i, Alphabet i β β) : | |
| Tendsto (fun t : β => Real.log (gridProduct counts t : β) / (t : β)) | |
| atTop (π (poolEntropyTotal counts)) := by | |
| exact Separation.tendsto_log_gridGroupOrder_prod_div_nat Finset.univ | |
| (fun i _ t => poolTypeCount_pos counts i t) | |
| (fun i _ => populationEntropyRate_nonneg (counts i)) | |
| (fun i _ => tendsto_log_poolTypeCount_div counts i) | |
| theorem tendsto_log_auxiliaryProduct_div (counts : β i, Alphabet i β β) : | |
| Tendsto (fun t : β => Real.log (auxiliaryProduct counts t : β) / (t : β)) | |
| atTop (π (poolEntropyTotal counts)) := by | |
| exact Separation.tendsto_log_nat_prod_div_nat Finset.univ | |
| (fun i _ t => LabelHierarchySeparation.poolAuxiliaryCost_pos (poolTypeCount counts i t)) | |
| (fun i _ => LabelHierarchySeparation.tendsto_log_poolAuxiliaryCost_div_nat | |
| (poolTypeCount_pos counts i) (populationEntropyRate_nonneg (counts i)) | |
| (tendsto_log_poolTypeCount_div counts i)) | |
| end FinitePools | |
| section SourceHierarchy | |
| variable {A : Type u} [Fintype A] {Label : β β Type v} | |
| [β n, Fintype (Label n)] | |
| theorem pushforwardCounts_mul {B : Type*} (counts : A β β) (label : A β B) | |
| (t : β) (b : B) : | |
| pushforwardCounts (fun a => t * counts a) label b = | |
| t * pushforwardCounts counts label b := by | |
| classical | |
| unfold pushforwardCounts | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| by_cases h : label a = b <;> simp [h] | |
| omit [β n, Fintype (Label n)] in | |
| theorem sourcePrefixCounts_mul (counts : A β β) (labels : β n, A β Label n) | |
| (t n : β) (r : LabelRecord Label n) : | |
| LabelHierarchyCounts.sourcePrefixCounts (fun a => t * counts a) labels n r = | |
| t * LabelHierarchyCounts.sourcePrefixCounts counts labels n r := | |
| pushforwardCounts_mul counts (labelRecordOf labels n) t r | |
| abbrev PrefixPool (Label : β β Type v) (depth : β) := | |
| Ξ£ n : Fin depth, LabelRecord Label n.val | |
| def sourcePoolCounts (counts : A β β) (labels : β n, A β Label n) (depth : β) | |
| (j : PrefixPool Label depth) (s : Label j.1.val) : β := | |
| LabelHierarchyCounts.sourcePrefixCounts counts labels (j.1.val + 1) (j.2, s) | |
| theorem pairingProduct_source_eq (counts : A β β) (labels : β n, A β Label n) | |
| (depth : β) (hinjective : Function.Injective (labelRecordOf labels depth)) (t : β) : | |
| pairingProduct (sourcePoolCounts counts labels depth) t = | |
| Nat.multinomial Finset.univ (fun a => t * counts a) := by | |
| classical | |
| unfold pairingProduct | |
| rw [Fintype.prod_sigma] | |
| have hpool (n : Fin depth) : | |
| (β r : LabelRecord Label n.val, | |
| poolTypeCount (sourcePoolCounts counts labels depth) β¨n, rβ© t) = | |
| LabelHierarchyCounts.refinementCount | |
| (LabelHierarchyCounts.sourcePrefixCounts (fun a => t * counts a) labels) n.val := by | |
| apply Finset.prod_congr rfl | |
| intro r _ | |
| change Nat.multinomial Finset.univ | |
| (fun s : Label n.val => t * | |
| LabelHierarchyCounts.sourcePrefixCounts counts labels (n.val + 1) (r, s)) = | |
| Nat.multinomial Finset.univ | |
| (fun s : Label n.val => | |
| LabelHierarchyCounts.sourcePrefixCounts (fun a => t * counts a) | |
| labels (n.val + 1) (r, s)) | |
| apply Nat.multinomial_congr | |
| intro s _ | |
| exact (sourcePrefixCounts_mul counts labels t (n.val + 1) (r, s)).symm | |
| simp_rw [hpool] | |
| rw [Fin.prod_univ_eq_prod_range] | |
| exact LabelHierarchyCounts.source_refinementCount_product | |
| (fun a => t * counts a) labels depth hinjective | |
| theorem pairingProduct_source_eq_exactWords_card [DecidableEq A] | |
| (counts : A β β) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) (t : β) : | |
| pairingProduct (sourcePoolCounts counts labels depth) t = | |
| Fintype.card (ExactWords (fun a => t * counts a)) := by | |
| rw [pairingProduct_source_eq counts labels depth hinjective, exactWords_card] | |
| theorem source_poolEntropyTotal_eq (counts : A β β) (labels : β n, A β Label n) | |
| (depth : β) (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| poolEntropyTotal (sourcePoolCounts counts labels depth) = populationEntropyRate counts := by | |
| have hsource : Tendsto | |
| (fun t : β => Real.log (pairingProduct (sourcePoolCounts counts labels depth) t : β) / | |
| (t : β)) atTop (π (populationEntropyRate counts)) := by | |
| simpa only [pairingProduct_source_eq counts labels depth hinjective] using | |
| tendsto_log_multinomial_mul_div_repetition counts | |
| exact tendsto_nhds_unique | |
| (tendsto_log_pairingProduct_div (sourcePoolCounts counts labels depth)) hsource | |
| private theorem normalized_of_per_repetition (counts : A β β) | |
| (hD : 0 < β a, counts a) (K : β β β) | |
| (h : Tendsto (fun t : β => Real.log (K t : β) / (t : β)) | |
| atTop (π (populationEntropyRate counts))) : | |
| Tendsto (fun t : β => Real.log (K t : β) / ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy (fun a => (counts a : β) / (β a, counts a : β)))) := by | |
| have hD' : ((β a, counts a : β) : β) β 0 := | |
| Nat.cast_ne_zero.mpr (Nat.ne_of_gt hD) | |
| have hmain : populationEntropyRate counts / (β a, counts a : β) = | |
| finiteEntropy (fun a => (counts a : β) / (β a, counts a : β)) := by | |
| unfold populationEntropyRate | |
| exact mul_div_cancel_leftβ _ hD' | |
| simpa only [div_div, hmain] using h.div_const ((β a, counts a : β) : β) | |
| theorem tendsto_log_source_pairingProduct (counts : A β β) | |
| (hD : 0 < β a, counts a) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| Tendsto | |
| (fun t : β => Real.log (pairingProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy (fun a => (counts a : β) / (β a, counts a : β)))) := by | |
| simpa only [pairingProduct_source_eq counts labels depth hinjective] using | |
| tendsto_log_multinomial_mul counts hD | |
| theorem tendsto_log_source_gridProduct (counts : A β β) | |
| (hD : 0 < β a, counts a) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| Tendsto | |
| (fun t : β => Real.log (gridProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy (fun a => (counts a : β) / (β a, counts a : β)))) := by | |
| apply normalized_of_per_repetition counts hD | |
| simpa only [source_poolEntropyTotal_eq counts labels depth hinjective] using | |
| tendsto_log_gridProduct_div (sourcePoolCounts counts labels depth) | |
| theorem tendsto_log_source_auxiliaryProduct (counts : A β β) | |
| (hD : 0 < β a, counts a) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| Tendsto | |
| (fun t : β => Real.log (auxiliaryProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy (fun a => (counts a : β) / (β a, counts a : β)))) := by | |
| apply normalized_of_per_repetition counts hD | |
| simpa only [source_poolEntropyTotal_eq counts labels depth hinjective] using | |
| tendsto_log_auxiliaryProduct_div (sourcePoolCounts counts labels depth) | |
| theorem rationalLaw_exists_source_rates [DecidableEq A] (p : RationalLaw A) | |
| (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| β counts : A β β, 0 < β a, counts a β§ | |
| (β a, (counts a : β) / (β a, counts a : β) = p.toFiniteLaw.mass a) β§ | |
| Tendsto | |
| (fun t : β => Real.log (Fintype.card (ExactWords (fun a => t * counts a)) : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy p.toFiniteLaw.mass)) β§ | |
| Tendsto | |
| (fun t : β => Real.log (pairingProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy p.toFiniteLaw.mass)) β§ | |
| Tendsto | |
| (fun t : β => Real.log (gridProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy p.toFiniteLaw.mass)) β§ | |
| Tendsto | |
| (fun t : β => Real.log (auxiliaryProduct (sourcePoolCounts counts labels depth) t : β) / | |
| ((t : β) * (β a, counts a : β))) | |
| atTop (π (finiteEntropy p.toFiniteLaw.mass)) := by | |
| obtain β¨counts, hD, hmassβ© := p.exists_type_representation | |
| have hfun : (fun a => (counts a : β) / (β a, counts a : β)) = | |
| p.toFiniteLaw.mass := funext hmass | |
| refine β¨counts, hD, hmass, ?_, ?_, ?_, ?_β© | |
| Β· simpa only [hfun] using tendsto_log_exactWords_card_mul counts hD | |
| Β· simpa only [hfun] using tendsto_log_source_pairingProduct counts hD labels depth hinjective | |
| Β· simpa only [hfun] using tendsto_log_source_gridProduct counts hD labels depth hinjective | |
| Β· simpa only [hfun] using tendsto_log_source_auxiliaryProduct counts hD labels depth hinjective | |
| end SourceHierarchy | |
| end HierarchySeparationRates | |
| end MatrixMultiplication.Foundation | |
| end | |
| end OAI | |