Download data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/InitialLeafRates.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/InitialLeafRates.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/InitialLeafRates.lean
-
curl -L -o InitialLeafRates.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Entropy/InitialLeafRates.lean
15.1 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Histories.HistorySums | |
| import OAI.LinearAlgebra.MatrixFields.Tensors.CWWordDimensionParameters | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| namespace MatrixMultiplication.AllFieldParameters | |
| open MatrixMultiplication.Foundation | |
| open scoped BigOperators | |
| noncomputable section | |
| theorem entropy_two_points {A : Type*} [Fintype A] [DecidableEq A] | |
| (a b : A) (hab : a β b) (p q : β) : | |
| finiteEntropy (fun i => if i = a then p else if i = b then q else 0) = | |
| entropyTerm p + entropyTerm q := by | |
| unfold finiteEntropy | |
| calc | |
| _ = β i : A, ((if i = a then entropyTerm p else 0) + | |
| (if i = b then entropyTerm q else 0)) := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| by_cases hi : i = a | |
| Β· subst i | |
| simp [hab] | |
| Β· by_cases hj : i = b | |
| Β· subst i | |
| simp [hab.symm] | |
| Β· simp [hi, hj] | |
| _ = _ := by simp [Finset.sum_add_distrib] | |
| theorem weighted_two_points {A : Type*} [Fintype A] [DecidableEq A] | |
| (a b : A) (hab : a β b) (p q : β) (f : A β β) : | |
| (β i : A, (if i = a then p else if i = b then q else 0) * f i) = | |
| p * f a + q * f b := by | |
| calc | |
| _ = β i : A, ((if i = a then p * f a else 0) + | |
| (if i = b then q * f b else 0)) := by | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| by_cases hi : i = a | |
| Β· subst i | |
| simp [hab] | |
| Β· by_cases hj : i = b | |
| Β· subst i | |
| simp [hi] | |
| Β· simp [hi, hj] | |
| _ = _ := by simp [Finset.sum_add_distrib] | |
| def statisticRate (d : β) (k : Fin 5) : β := | |
| finiteEntropy (fun i : Fin 6 => (statisticLaw d k i : β)) + | |
| β i : Fin 6, (statisticLaw d k i : β) * Real.log (multiplicity i : β) | |
| def binaryEntropyRate (d : β) : β := | |
| entropyTerm (1 - (d : β)) + entropyTerm (d : β) + (d : β) * Real.log 2 | |
| theorem statisticLaw_two_real (d : β) (i : Fin 6) : | |
| (statisticLaw d 2 i : β) = | |
| if i = 2 then 1 - (d : β) else if i = 3 then (d : β) else 0 := by | |
| by_cases hi : i = 2 | |
| Β· simp [statisticLaw, hi] | |
| Β· by_cases hj : i = 3 <;> simp [statisticLaw, hi, hj] | |
| theorem statisticRate_two (d : β) : | |
| statisticRate d 2 = binaryEntropyRate d + 2 * (1 - (d : β)) * Real.log 5 := by | |
| unfold statisticRate | |
| simp_rw [statisticLaw_two_real] | |
| rw [entropy_two_points (2 : Fin 6) 3 (by decide), | |
| weighted_two_points (2 : Fin 6) 3 (by decide)] | |
| have h25 : Real.log (25 : β) = 2 * Real.log 5 := by | |
| have hp : (5 : β) ^ 2 = 25 := by norm_num | |
| rw [β hp, Real.log_pow] | |
| norm_num | |
| change entropyTerm (1 - (d : β)) + entropyTerm (d : β) + | |
| ((1 - (d : β)) * Real.log 25 + (d : β) * Real.log 2) = _ | |
| rw [h25] | |
| unfold binaryEntropyRate | |
| ring | |
| theorem statisticRate_deterministic (d : β) (k : Fin 5) (hk : k.val β 2) : | |
| statisticRate d k = Real.log (multiplicity (singletonSlot k.val) : β) := by | |
| have hmass (i : Fin 6) : (statisticLaw d k i : β) = | |
| if i = singletonSlot k.val then 1 else 0 := by | |
| by_cases hi : i = singletonSlot k.val <;> simp [statisticLaw, hk, hi] | |
| unfold statisticRate finiteEntropy | |
| simp_rw [hmass] | |
| simp [entropyTerm, apply_ite] | |
| theorem statisticRate_zero (d : β) : statisticRate d 0 = 0 := by | |
| rw [statisticRate_deterministic d 0 (by decide)] | |
| norm_num [singletonSlot, multiplicity] | |
| theorem statisticRate_one (d : β) : statisticRate d 1 = Real.log 10 := by | |
| rw [statisticRate_deterministic d 1 (by decide)] | |
| norm_num [singletonSlot, multiplicity] | |
| theorem statisticRate_three (d : β) : statisticRate d 3 = Real.log 10 := by | |
| rw [statisticRate_deterministic d 3 (by decide)] | |
| change Real.log (10 : β) = Real.log 10 | |
| rfl | |
| theorem statisticRate_four (d : β) : statisticRate d 4 = 0 := by | |
| rw [statisticRate_deterministic d 4 (by decide)] | |
| have hv : multiplicity (singletonSlot (4 : Fin 5).val) = 1 := by decide +kernel | |
| rw [hv] | |
| norm_num | |
| end | |
| end MatrixMultiplication.AllFieldParameters | |
| noncomputable section | |
| namespace MatrixMultiplication.AllFieldTerminalRates | |
| open AllFieldParameters AllFieldHistory | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable Classical.decEq | |
| def initialRate (g : Shape) : β := | |
| Real.log (Contractions.coefficients[shapeMax g]?.getD 0 : β) | |
| def S0 : β := | |
| ((sortedInitial.filter (fun g => !positive g)).map | |
| (fun g => (initialLaw g : β) * initialRate g)).sum | |
| def S1 : β := | |
| (zeroSecond.map (fun t => (secondMass t : β) * AllFieldZeroLeafRates.fourRate t)).sum | |
| def secondLeafRate (t u : Shape) : β := | |
| if shapeMax u = 4 then 0 | |
| else if shapeMax u = 3 then Real.log 10 | |
| else if !positive u then | |
| binaryEntropyRate (binaryParameter t u) + | |
| 2 * (1 - (binaryParameter t u : β)) * Real.log 5 | |
| else (2 - (binaryParameter t u : β)) * Real.log 5 | |
| def S2 : β := | |
| (positiveSecond.map (fun t => | |
| ((below t).map (fun u => (littleMass t u : β) * secondLeafRate t u)).sum)).sum | |
| def S : β := (S0 + S1) + S2 | |
| private theorem four_shape_max_lt_five : β u β shapes 4, shapeMax u < 5 := by | |
| decide +kernel | |
| private theorem four_zero_max : β u β shapes 4, positive u = false β | |
| shapeMax u = 2 β¨ shapeMax u = 3 β¨ shapeMax u = 4 := by | |
| decide +kernel | |
| private theorem four_positive_max : β u β shapes 4, positive u = true β | |
| shapeMax u = 2 := by | |
| decide +kernel | |
| theorem second_shapeMax_lt_five (t : Shape) (ht : t β positiveSecond) | |
| (u : Shape) (hu : u β below t) : shapeMax u < 5 := | |
| four_shape_max_lt_five u (stageB_children_size t ht u hu) | |
| theorem secondLeafRate_zero (t : Shape) (ht : t β positiveSecond) | |
| (u : Shape) (hu : u β below t) (hz : positive u = false) : | |
| secondLeafRate t u = statisticRate (binaryParameter t u) | |
| β¨shapeMax u, second_shapeMax_lt_five t ht u huβ© := by | |
| rcases four_zero_max u (stageB_children_size t ht u hu) hz with h2 | h3 | h4 | |
| Β· have hk : (β¨shapeMax u, second_shapeMax_lt_five t ht u huβ© : Fin 5) = 2 := | |
| Fin.ext h2 | |
| rw [hk, statisticRate_two] | |
| simp [secondLeafRate, h2, hz] | |
| Β· have hk : (β¨shapeMax u, second_shapeMax_lt_five t ht u huβ© : Fin 5) = 3 := | |
| Fin.ext h3 | |
| rw [hk, statisticRate_three] | |
| simp [secondLeafRate, h3] | |
| Β· have hk : (β¨shapeMax u, second_shapeMax_lt_five t ht u huβ© : Fin 5) = 4 := | |
| Fin.ext h4 | |
| rw [hk, statisticRate_four] | |
| simp [secondLeafRate, h4] | |
| theorem secondLeafRate_positive (t : Shape) (ht : t β positiveSecond) | |
| (u : Shape) (hu : u β below t) (hp : positive u = true) : | |
| secondLeafRate t u = (2 - (binaryParameter t u : β)) * Real.log 5 := by | |
| have hm := four_positive_max u (stageB_children_size t ht u hu) hp | |
| simp [secondLeafRate, hm, hp] | |
| theorem secondLeafRate_builder_expression (t u : Shape) : | |
| secondLeafRate t u = | |
| if shapeMax u = 4 then 0 | |
| else if shapeMax u = 3 then Real.log 10 | |
| else if !positive u then | |
| (MatrixMultiplication.Foundation.entropyTerm (1 - (binaryParameter t u : β)) + | |
| MatrixMultiplication.Foundation.entropyTerm (binaryParameter t u : β) + | |
| (binaryParameter t u : β) * Real.log 2) + | |
| ((1 - (binaryParameter t u : β)) * 2) * Real.log 5 | |
| else (2 - (binaryParameter t u : β)) * Real.log 5 := by | |
| unfold secondLeafRate | |
| split_ifs <;> try rfl | |
| unfold binaryEntropyRate | |
| ring | |
| private theorem list_filter_sum_inline_MatrixMultiplication_AllFieldTerminalRateFormulas {A : Type*} (xs : List A) (p : A β Bool) | |
| (f : A β β) : | |
| ((xs.filter p).map f).sum = (xs.map (fun a => if p a then f a else 0)).sum := by | |
| induction xs with | |
| | nil => simp | |
| | cons a xs ih => cases hp : p a <;> simp [hp, ih] | |
| theorem initial_zero_history_rate (K : β) : | |
| (β h : {h : Initial K // initialShape h β positiveInitial}, | |
| (initialAmount h.val : β) * initialRate (initialShape h.val)) = (K : β) * S0 := by | |
| calc | |
| _ = β h : Initial K, if initialShape h β positiveInitial then | |
| (initialAmount h : β) * initialRate (initialShape h) else 0 := by | |
| rw [β Finset.sum_filter] | |
| exact (Finset.sum_subtype | |
| (p := fun h : Initial K => initialShape h β positiveInitial) | |
| (Finset.univ.filter (fun h : Initial K => initialShape h β positiveInitial)) | |
| (by simp) | |
| (fun h : Initial K => (initialAmount h : β) * initialRate (initialShape h))).symm | |
| _ = β h : Initial K, (initialAmount h : β) * | |
| (if initialShape h β positiveInitial then initialRate (initialShape h) else 0) := by | |
| apply Finset.sum_congr rfl | |
| intro h _ | |
| split_ifs <;> simp | |
| _ = _ := by | |
| rw [initial_history_sum K | |
| (fun g => if g β positiveInitial then initialRate g else 0), S0, list_filter_sum_inline_MatrixMultiplication_AllFieldTerminalRateFormulas] | |
| apply congrArg (fun x : β => (K : β) * x) | |
| apply congrArg List.sum | |
| apply List.map_congr_left | |
| intro g hg | |
| cases hp : positive g <;> simp [positiveInitial, hg, hp] | |
| end MatrixMultiplication.AllFieldTerminalRates | |
| namespace MatrixMultiplication.AllFieldInitialLeafRates | |
| open AllFieldHistory AllFieldParameters AllFieldTerminalRates | |
| open CWWindowedLeaves Filter | |
| open scoped BigOperators Topology | |
| attribute [local instance] Classical.propDecidable Classical.decEq | |
| abbrev InitialZero (K : β) := | |
| {h : Initial K // initialShape h β positiveInitial} | |
| abbrev PopulationHistory (K : β) := InitialZero K Γ Placement | |
| theorem shapeMax_lt {K : β} (h : InitialZero K) : | |
| shapeMax (initialShape h.val) < 17 := by | |
| have hb := (root_shape_spec _ (initialShape_mem h.val)).1 | |
| exact Nat.lt_succ_of_le (max_le (hb 0) (max_le (hb 1) (hb 2))) | |
| def shapeIndex {K : β} (h : InitialZero K) : Fin 17 := | |
| β¨shapeMax (initialShape h.val), shapeMax_lt hβ© | |
| theorem card_alphabet {K : β} (h : InitialZero K) : | |
| Fintype.card (Alphabet 8 (shapeMax (initialShape h.val))) = | |
| Contractions.coefficients[shapeMax (initialShape h.val)]?.getD 0 := by | |
| have hc := CWWordDimensionParameters.table_eq_card (shapeIndex h) | |
| rw [Fintype.card_eq_nat_card] at hc β’ | |
| exact hc.symm | |
| theorem card_alphabet_pos {K : β} (h : InitialZero K) : | |
| 0 < Fintype.card (Alphabet 8 (shapeMax (initialShape h.val))) := by | |
| have hc := CWWordDimensionParameters.word_card_positive (shapeIndex h) | |
| rw [Fintype.card_eq_nat_card] at hc β’ | |
| exact hc | |
| abbrev Words {K : β} (allocation : Allocation) (dilation : β) | |
| (h : PopulationHistory K) := | |
| Fin (population allocation dilation (.initial h.1.val, h.2)) β | |
| Alphabet 8 (shapeMax (initialShape h.1.val)) | |
| theorem card_words {K : β} (allocation : Allocation) (dilation : β) | |
| (h : PopulationHistory K) : | |
| Fintype.card (Words allocation dilation h) = | |
| (Contractions.coefficients[shapeMax (initialShape h.1.val)]?.getD 0) ^ | |
| population allocation dilation (.initial h.1.val, h.2) := by | |
| simp only [Words, Fintype.card_fun, Fintype.card_fin, card_alphabet] | |
| theorem card_words_pos {K : β} (allocation : Allocation) (dilation : β) | |
| (h : PopulationHistory K) : | |
| 0 < Fintype.card (Words allocation dilation h) := by | |
| simp only [Words, Fintype.card_fun, Fintype.card_fin] | |
| exact pow_pos (card_alphabet_pos h.1) _ | |
| theorem log_card_words {K : β} (allocation : Allocation) (dilation : β) | |
| (h : PopulationHistory K) : | |
| Real.log (Fintype.card (Words allocation dilation h) : β) = | |
| (population allocation dilation (.initial h.1.val, h.2) : β) * | |
| initialRate (initialShape h.1.val) := by | |
| simp only [card_words, Nat.cast_pow, Real.log_pow, initialRate] | |
| abbrev ProductWords {K : β} (allocation : Allocation) (dilation : β) := | |
| β h : PopulationHistory K, Words allocation dilation h | |
| def volume {K : β} (allocation : Allocation) (dilation : β) : β := | |
| Fintype.card (ProductWords (K := K) allocation dilation) | |
| theorem volume_eq_prod {K : β} (allocation : Allocation) (dilation : β) : | |
| volume (K := K) allocation dilation = | |
| β h : PopulationHistory K, Fintype.card (Words allocation dilation h) := by | |
| rw [volume, Fintype.card_pi] | |
| theorem volume_pos {K : β} (allocation : Allocation) (dilation : β) : | |
| 0 < volume (K := K) allocation dilation := by | |
| rw [volume_eq_prod] | |
| exact Finset.prod_pos (fun h _ => card_words_pos allocation dilation h) | |
| theorem log_volume {K : β} (allocation : Allocation) (dilation : β) : | |
| Real.log (volume (K := K) allocation dilation : β) = | |
| (populationLength (K := K) allocation dilation : β) * | |
| β h : PopulationHistory K, | |
| (amount allocation (.initial h.1.val, h.2) : β) * | |
| initialRate (initialShape h.1.val) := by | |
| rw [volume_eq_prod, Nat.cast_prod, Real.log_prod | |
| (fun h _ => Nat.cast_ne_zero.mpr | |
| (Nat.ne_of_gt (card_words_pos allocation dilation h)))] | |
| simp only [log_card_words] | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro h _ | |
| have hc : (population allocation dilation (.initial h.1.val, h.2) : β) = | |
| (populationLength (K := K) allocation dilation : β) * | |
| (amount allocation (.initial h.1.val, h.2) : β) := by | |
| exact_mod_cast population_cast allocation dilation (.initial h.1.val, h.2) | |
| rw [hc, mul_assoc] | |
| theorem sum_populationHistory_rate {K : β} (allocation : Allocation) : | |
| (β h : PopulationHistory K, | |
| (amount allocation (.initial h.1.val, h.2) : β) * | |
| initialRate (initialShape h.1.val)) = | |
| β h : InitialZero K, | |
| (initialAmount h.val : β) * initialRate (initialShape h.val) := by | |
| rw [Fintype.sum_prod_type] | |
| apply Finset.sum_congr rfl | |
| intro h _ | |
| dsimp only | |
| rw [β Finset.sum_mul] | |
| have hm : (β phi : Placement, (amount allocation (.initial h.val, phi) : β)) = | |
| (initialAmount h.val : β) := by | |
| exact_mod_cast sum_placement_amount allocation (.initial h.val) | |
| rw [hm] | |
| theorem log_volume_eq_S0 {K : β} (allocation : Allocation) (dilation : β) : | |
| Real.log (volume (K := K) allocation dilation : β) = | |
| (populationLength (K := K) allocation dilation : β) * ((K : β) * S0) := by | |
| rw [log_volume, sum_populationHistory_rate, initial_zero_history_rate] | |
| theorem normalized_log_volume_eq_S0 {K : β} (allocation : Allocation) | |
| (dilation : β) (hd : 0 < dilation) : | |
| Real.log (volume (K := K) allocation dilation : β) / | |
| populationLength (K := K) allocation dilation = (K : β) * S0 := by | |
| rw [log_volume_eq_S0] | |
| have hn : (populationLength (K := K) allocation dilation : β) β 0 := | |
| Nat.cast_ne_zero.mpr | |
| (Nat.ne_of_gt (AllFieldPopulationCounts.blockLength_pos _ hd)) | |
| exact mul_div_cancel_leftβ _ hn | |
| theorem tendsto_normalized_log_volume {K : β} (allocation : Allocation) : | |
| Tendsto (fun dilation : β => | |
| Real.log (volume (K := K) allocation dilation : β) / | |
| populationLength (K := K) allocation dilation) atTop (π ((K : β) * S0)) := by | |
| apply tendsto_const_nhds.congr' | |
| filter_upwards [eventually_gt_atTop (0 : β)] with dilation hd | |
| exact (normalized_log_volume_eq_S0 allocation dilation hd).symm | |
| end MatrixMultiplication.AllFieldInitialLeafRates | |
| end | |
| end MatrixAllFields | |
| end OAI | |