Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchyEntropy.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.05 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchyEntropy.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchyEntropy.lean
-
curl -L -o ComplexHierarchyEntropy.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/Entropy/ComplexHierarchyEntropy.lean
9.05 kB
| import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexFiniteEntropy | |
| namespace OAI | |
| /-! Finite entropy, rate estimates and ordered asymptotic limits. -/ | |
| namespace MatrixMultiplication.Foundation | |
| open scoped BigOperators | |
| universe u v | |
| noncomputable section | |
| namespace FiniteLaw | |
| theorem map_mass_mul_conditional_map {A B C : Type*} | |
| [Fintype A] [Fintype B] [Fintype C] | |
| (p : FiniteLaw A) (f : A β B) (g : A β C) (b : B) (c : C) : | |
| (p.map f).mass b * ((p.conditional f b).map g).mass c = | |
| (p.map (fun a => (f a, g a))).mass (b, c) := by | |
| classical | |
| rw [map_mass (p.conditional f b) g c, Finset.mul_sum, | |
| map_mass p (fun a => (f a, g a)) (b, c)] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| by_cases hgc : g a = c | |
| Β· rw [ite_eq_left hgc, map_mass_mul_conditional] | |
| simp only [Prod.mk.injEq, hgc, and_true] | |
| Β· rw [ite_eq_right hgc, mul_zero] | |
| have hpair : (f a, g a) β (b, c) := | |
| fun he => hgc (congrArg Prod.snd he) | |
| rw [ite_eq_right hpair] | |
| end FiniteLaw | |
| def LabelRecord (Label : β β Type u) : β β Type u | |
| | 0 => PUnit | |
| | n + 1 => LabelRecord Label n Γ Label n | |
| instance labelRecordFintype (Label : β β Type u) [β n, Fintype (Label n)] : | |
| (n : β) β Fintype (LabelRecord Label n) | |
| | 0 => by | |
| change Fintype PUnit | |
| infer_instance | |
| | n + 1 => by | |
| letI := labelRecordFintype Label n | |
| change Fintype (LabelRecord Label n Γ Label n) | |
| infer_instance | |
| def labelRecordOf {A : Type v} {Label : β β Type u} | |
| (labels : β n, A β Label n) : (n : β) β A β LabelRecord Label n | |
| | 0, _ => PUnit.unit | |
| | n + 1, a => (labelRecordOf labels n a, labels n a) | |
| structure FiniteLabelHierarchy (Label : β β Type u) [β n, Fintype (Label n)] | |
| (depth : β) where | |
| conditional : β n, n < depth β LabelRecord Label n β FiniteLaw (Label n) | |
| namespace FiniteLabelHierarchy | |
| variable {Label : β β Type u} [β n, Fintype (Label n)] {depth : β} | |
| def prefixLaw (h : FiniteLabelHierarchy Label depth) : | |
| (n : β) β n β€ depth β FiniteLaw (LabelRecord Label n) | |
| | 0, _ => | |
| { mass := fun _ => 1 | |
| nonneg := fun _ => zero_le_one | |
| total := by | |
| classical | |
| refine Finset.sum_eq_single_of_mem (PUnit.unit : LabelRecord Label 0) | |
| (Finset.mem_univ _) ?_ | |
| intro r _ hr | |
| cases r | |
| exact (hr rfl).elim } | |
| | n + 1, hn => | |
| (h.prefixLaw n (Nat.le_of_succ_le hn)).joint | |
| (h.conditional n (Nat.lt_of_succ_le hn)) | |
| @[simp] theorem prefixLaw_zero_mass (h : FiniteLabelHierarchy Label depth) | |
| (hn : 0 β€ depth) (r : LabelRecord Label 0) : | |
| (h.prefixLaw 0 hn).mass r = 1 := rfl | |
| @[simp] theorem prefixLaw_succ (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n + 1 β€ depth) : | |
| h.prefixLaw (n + 1) hn = | |
| (h.prefixLaw n (Nat.le_of_succ_le hn)).joint | |
| (h.conditional n (Nat.lt_of_succ_le hn)) := rfl | |
| @[simp] theorem prefixLaw_succ_mass (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n + 1 β€ depth) (r : LabelRecord Label n) (s : Label n) : | |
| (h.prefixLaw (n + 1) hn).mass (r, s) = | |
| (h.prefixLaw n (Nat.le_of_succ_le hn)).mass r * | |
| (h.conditional n (Nat.lt_of_succ_le hn) r).mass s := rfl | |
| def refinementEntropy (h : FiniteLabelHierarchy Label depth) (n : β) : β := | |
| if hn : n < depth then | |
| β r, (h.prefixLaw n (Nat.le_of_lt hn)).mass r * | |
| finiteEntropy (h.conditional n hn r).mass | |
| else 0 | |
| theorem refinementEntropy_eq (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n < depth) : | |
| h.refinementEntropy n = | |
| β r, (h.prefixLaw n (Nat.le_of_lt hn)).mass r * | |
| finiteEntropy (h.conditional n hn r).mass := by | |
| simp only [refinementEntropy, dite_eq_left hn] | |
| @[simp] theorem refinementEntropy_eq_zero_of_le | |
| (h : FiniteLabelHierarchy Label depth) {n : β} (hn : depth β€ n) : | |
| h.refinementEntropy n = 0 := by | |
| simp only [refinementEntropy, dite_eq_right (Nat.not_lt.mpr hn)] | |
| theorem zero_prefix_contribution (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n < depth) (r : LabelRecord Label n) | |
| (hr : (h.prefixLaw n (Nat.le_of_lt hn)).mass r = 0) : | |
| (h.prefixLaw n (Nat.le_of_lt hn)).mass r * | |
| finiteEntropy (h.conditional n hn r).mass = 0 := by | |
| rw [hr, zero_mul] | |
| theorem prefixLaw_entropy_succ (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n + 1 β€ depth) : | |
| finiteEntropy (h.prefixLaw (n + 1) hn).mass = | |
| finiteEntropy (h.prefixLaw n (Nat.le_of_succ_le hn)).mass + | |
| h.refinementEntropy n := by | |
| rw [refinementEntropy_eq h n (Nat.lt_of_succ_le hn)] | |
| exact FiniteLaw.joint_entropy (h.prefixLaw n (Nat.le_of_succ_le hn)) | |
| (h.conditional n (Nat.lt_of_succ_le hn)) | |
| theorem prefixLaw_entropy (h : FiniteLabelHierarchy Label depth) | |
| (n : β) (hn : n β€ depth) : | |
| finiteEntropy (h.prefixLaw n hn).mass = | |
| β j β Finset.range n, h.refinementEntropy j := by | |
| induction n with | |
| | zero => | |
| simp [prefixLaw, finiteEntropy, entropyTerm, LabelRecord] | |
| | succ n ih => | |
| rw [prefixLaw_entropy_succ h n hn, | |
| ih (Nat.le_of_succ_le hn), Finset.sum_range_succ] | |
| def recordLaw (h : FiniteLabelHierarchy Label depth) : | |
| FiniteLaw (LabelRecord Label depth) := h.prefixLaw depth le_rfl | |
| theorem recordLaw_entropy (h : FiniteLabelHierarchy Label depth) : | |
| finiteEntropy h.recordLaw.mass = | |
| β j β Finset.range depth, h.refinementEntropy j := | |
| h.prefixLaw_entropy depth le_rfl | |
| theorem refinementEntropy_sum_of_injective_record | |
| {A : Type v} [Fintype A] (h : FiniteLabelHierarchy Label depth) | |
| (p : FiniteLaw A) (record : A β LabelRecord Label depth) | |
| (hinjective : Function.Injective record) | |
| (hmass : h.recordLaw.mass = (p.map record).mass) : | |
| (β j β Finset.range depth, h.refinementEntropy j) = finiteEntropy p.mass := by | |
| calc | |
| (β j β Finset.range depth, h.refinementEntropy j) = | |
| finiteEntropy h.recordLaw.mass := h.recordLaw_entropy.symm | |
| _ = finiteEntropy (p.map record).mass := congrArg finiteEntropy hmass | |
| _ = finiteEntropy p.mass := p.map_entropy_of_injective record hinjective | |
| def ofLawLabels {A : Type v} [Fintype A] (p : FiniteLaw A) | |
| (labels : β n, A β Label n) (depth : β) : FiniteLabelHierarchy Label depth where | |
| conditional n _ r := (p.conditional (labelRecordOf labels n) r).map (labels n) | |
| theorem ofLawLabels_prefixLaw_mass {A : Type v} [Fintype A] | |
| (p : FiniteLaw A) (labels : β n, A β Label n) | |
| (depth n : β) (hn : n β€ depth) : | |
| ((ofLawLabels p labels depth).prefixLaw n hn).mass = | |
| (p.map (labelRecordOf labels n)).mass := by | |
| classical | |
| induction n with | |
| | zero => | |
| funext r | |
| rw [prefixLaw_zero_mass, FiniteLaw.map_mass] | |
| refine p.total.symm.trans ?_ | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [ite_eq_left (show labelRecordOf labels 0 a = r by cases r; rfl)] | |
| | succ n ih => | |
| funext rs | |
| rcases rs with β¨r, sβ© | |
| rw [prefixLaw_succ_mass] | |
| change ((ofLawLabels p labels depth).prefixLaw n | |
| (Nat.le_of_succ_le hn)).mass r * | |
| ((p.conditional (labelRecordOf labels n) r).map (labels n)).mass s = | |
| (p.map (labelRecordOf labels (n + 1))).mass (r, s) | |
| rw [ih (Nat.le_of_succ_le hn)] | |
| exact p.map_mass_mul_conditional_map | |
| (labelRecordOf labels n) (labels n) r s | |
| theorem ofLawLabels_refinementEntropy_eq {A : Type v} [Fintype A] | |
| (p : FiniteLaw A) (labels : β n, A β Label n) | |
| (depth n : β) (hn : n < depth) : | |
| (ofLawLabels p labels depth).refinementEntropy n = | |
| β r : LabelRecord Label n, (p.map (labelRecordOf labels n)).mass r * | |
| finiteEntropy ((p.conditional (labelRecordOf labels n) r).map (labels n)).mass := by | |
| rw [refinementEntropy_eq _ n hn, | |
| ofLawLabels_prefixLaw_mass p labels depth n (Nat.le_of_lt hn)] | |
| rfl | |
| theorem ofLawLabels_refinementEntropy_sum {A : Type v} [Fintype A] | |
| (p : FiniteLaw A) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| (β j β Finset.range depth, | |
| (ofLawLabels p labels depth).refinementEntropy j) = finiteEntropy p.mass := by | |
| apply (ofLawLabels p labels depth).refinementEntropy_sum_of_injective_record | |
| p (labelRecordOf labels depth) hinjective | |
| exact ofLawLabels_prefixLaw_mass p labels depth depth le_rfl | |
| theorem entropy_eq_sum_conditional_labels {A : Type v} [Fintype A] | |
| (p : FiniteLaw A) (labels : β n, A β Label n) (depth : β) | |
| (hinjective : Function.Injective (labelRecordOf labels depth)) : | |
| finiteEntropy p.mass = | |
| β j β Finset.range depth, β r : LabelRecord Label j, | |
| (p.map (labelRecordOf labels j)).mass r * | |
| finiteEntropy ((p.conditional (labelRecordOf labels j) r).map (labels j)).mass := by | |
| rw [β ofLawLabels_refinementEntropy_sum p labels depth hinjective] | |
| apply Finset.sum_congr rfl | |
| intro j hj | |
| exact ofLawLabels_refinementEntropy_eq p labels depth j (Finset.mem_range.mp hj) | |
| end FiniteLabelHierarchy | |
| end | |
| end MatrixMultiplication.Foundation | |
| end OAI | |