math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /JointExtraction /CompatibilityIncidence.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityIncidence.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 34 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityIncidence.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityIncidence.lean
-
curl -L -o CompatibilityIncidence.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/CompatibilityIncidence.lean
34 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.TypeCounts | |
| import Mathlib.Logic.Equiv.Option | |
| namespace OAI | |
| /-! Joint tensor extraction, compatibility and entropy estimates. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.JointCompatibilityIncidence | |
| open MatrixMultiplication.Foundation JointTypeCounts | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable | |
| section Actions | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos A : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] | |
| abbrev ClassPerm := β c, Equiv.Perm (Pos c) | |
| def permuteFixedWords (counts : β c, A c β β) | |
| (g : ClassPerm Pos) (w : FixedClassWords Pos A counts) : | |
| FixedClassWords Pos A counts := | |
| fun c => β¨(w c).val β ((g c)β»ΒΉ : Equiv.Perm (Pos c)), fun a => | |
| (wordPopulation_reindex (w c).val (g c)β»ΒΉ a).trans ((w c).property a)β© | |
| @[instance_reducible] | |
| def fixedWordsMulAction (counts : β c, A c β β) : | |
| MulAction (ClassPerm Pos) (FixedClassWords Pos A counts) where | |
| smul := permuteFixedWords Pos A counts | |
| one_smul w := by | |
| funext c | |
| apply Subtype.ext | |
| funext i | |
| rfl | |
| mul_smul g h w := by | |
| funext c | |
| apply Subtype.ext | |
| funext i | |
| change (w c).val (((g * h) c)β»ΒΉ i) = | |
| (w c).val ((h c)β»ΒΉ ((g c)β»ΒΉ i)) | |
| simp only [Pi.mul_apply, mul_inv_rev, Equiv.Perm.mul_apply] | |
| attribute [local instance] fixedWordsMulAction | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Pos c)] [β c, Fintype (A c)] in | |
| theorem fixedWordsPretransitive (counts : β c, A c β β) : | |
| MulAction.IsPretransitive (ClassPerm Pos) (FixedClassWords Pos A counts) where | |
| exists_smul_eq w v := by | |
| obtain β¨e, heβ© := fixedClassWords_transitive Pos A counts w v | |
| refine β¨fun c => (e c)β»ΒΉ, ?_β© | |
| funext c | |
| apply Subtype.ext | |
| change (w c).val β (((e c)β»ΒΉ)β»ΒΉ : Equiv.Perm (Pos c)) = (v c).val | |
| simpa only [inv_inv] using he c | |
| attribute [local instance] fixedWordsPretransitive | |
| end Actions | |
| attribute [local instance] fixedWordsMulAction fixedWordsPretransitive | |
| section Counts | |
| variable {P U Z A : Type*} [Fintype P] [DecidableEq U] [DecidableEq A] | |
| def jointCount (w : P β U) (z : P β Z) (part : Z β A) (u : U) (a : A) : β := | |
| Fintype.card {i : P // w i = u β§ part (z i) = a} | |
| theorem jointCount_reindex (w : P β U) (z : P β Z) (part : Z β A) | |
| (e : Equiv.Perm P) (u : U) (a : A) : | |
| jointCount (w β e) (z β e) part u a = jointCount w z part u a := by | |
| exact Fintype.card_congr (Equiv.subtypeEquiv e fun _ => Iff.rfl) | |
| variable [DecidableEq P] [Fintype U] [Fintype A] | |
| omit [DecidableEq P] [Fintype A] in | |
| theorem jointCount_sum_shapes (w : P β U) (z : P β Z) (part : Z β A) (a : A) : | |
| (β u, jointCount w z part u a) = wordPopulation (part β z) a := by | |
| calc | |
| (β u, jointCount w z part u a) = | |
| β u, wordPopulation (fun i : {i : P // part (z i) = a} => w i.val) u := by | |
| apply Finset.sum_congr rfl | |
| intro u _ | |
| rw [wordPopulation_fiber] | |
| exact Fintype.card_congr (Equiv.subtypeEquivRight fun _ => and_comm) | |
| _ = wordPopulation (part β z) a := wordPopulation_sum _ | |
| omit [DecidableEq P] [Fintype A] in | |
| theorem projected_restrict_population (w : P β U) (z : P β Z) (part : Z β A) | |
| (d : U β Prop) (a : A) : | |
| wordPopulation (fun i : {i : P // d (w i)} => part (z i.val)) a = | |
| β u : {u : U // d u}, jointCount w z part u.val a := by | |
| let e : {i : {i : P // d (w i)} // part (z i.val) = a} β | |
| Ξ£ u : {u : U // d u}, {i : P // w i = u.val β§ part (z i) = a} := | |
| { toFun := fun i => β¨β¨w i.val.val, i.val.propertyβ©, | |
| β¨i.val.val, rfl, i.propertyβ©β© | |
| invFun := fun i => β¨β¨i.2.val, by | |
| rw [i.2.property.1] | |
| exact i.1.propertyβ©, i.2.property.2β© | |
| left_inv := by intro i; rfl | |
| right_inv := by | |
| rintro β¨β¨u, huβ©, i, hi, haβ© | |
| cases hi | |
| rfl } | |
| simpa only [wordPopulation, Fintype.card_sigma, jointCount] using Fintype.card_congr e | |
| omit [DecidableEq P] [Fintype A] in | |
| theorem residual_population_add_designated (w : P β U) (z : P β Z) | |
| (part : Z β A) (d : U β Prop) (a : A) : | |
| wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a + | |
| β u : {u : U // d u}, jointCount w z part u.val a = | |
| wordPopulation (part β z) a := by | |
| have hres : | |
| wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a = | |
| β u : {u : U // Β¬d u}, jointCount w z part u.val a := by | |
| convert projected_restrict_population w z part (fun u => Β¬d u) a using 1 <;> congr 1 | |
| Β· exact Subsingleton.elim _ _ | |
| Β· ext u | |
| simp | |
| rw [hres, add_comm] | |
| exact (Fintype.sum_subtype_add_sum_subtype d | |
| (fun u => jointCount w z part u a)).trans (jointCount_sum_shapes w z part a) | |
| omit [DecidableEq P] [Fintype A] in | |
| theorem projected_population_fixed [Fintype Z] [DecidableEq Z] | |
| (z : P β Z) (counts : Z β β) (hz : β s, wordPopulation z s = counts s) | |
| (part : Z β A) (a : A) : | |
| wordPopulation (part β z) a = β s : {s : Z // part s = a}, counts s.val := by | |
| have h := (Fintype.card_congr | |
| (Equiv.sigmaSubtypeFiberEquivSubtype z | |
| (p := fun i => part (z i) = a) (q := fun s => part s = a) | |
| (fun _ => Iff.rfl))).symm | |
| simp only [Fintype.card_sigma] at h | |
| change wordPopulation (part β z) a = | |
| β s : {s : Z // part s = a}, wordPopulation z s.val at h | |
| simpa only [hz] using h | |
| omit [DecidableEq P] [Fintype A] in | |
| theorem residual_projected_window (w : P β U) (z : P β Z) (part : Z β A) | |
| (d : U β Prop) (counts : U β β) (law : U β A β β) | |
| (residualLaw totalTarget : A β β) (Ο Ξ· : β) (a : A) | |
| (hmass : 0 < Fintype.card {i : P // Β¬d (w i)}) | |
| (htotal : |(wordPopulation (part β z) a : β) - totalTarget a| β€ Ξ·) | |
| (hdesignated : β u, d u β | |
| |(jointCount w z part u a : β) - (counts u : β) * law u a| β€ | |
| (counts u : β) * Ο) | |
| (hbalance : (Fintype.card {i : P // Β¬d (w i)} : β) * residualLaw a = | |
| totalTarget a - β u : {u : U // d u}, (counts u.val : β) * law u.val a) : | |
| |(wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a : β) / | |
| Fintype.card {i : P // Β¬d (w i)} - residualLaw a| β€ | |
| (Ξ· + (β u : {u : U // d u}, (counts u.val : β)) * Ο) / | |
| Fintype.card {i : P // Β¬d (w i)} := by | |
| have hm : (0 : β) < Fintype.card {i : P // Β¬d (w i)} := Nat.cast_pos.mpr hmass | |
| have hsplit : | |
| (wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a : β) = | |
| wordPopulation (part β z) a - | |
| β u : {u : U // d u}, (jointCount w z part u.val a : β) := by | |
| have h := residual_population_add_designated w z part d a | |
| have h' : | |
| (wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a : β) + | |
| β u : {u : U // d u}, (jointCount w z part u.val a : β) = | |
| wordPopulation (part β z) a := by exact_mod_cast h | |
| exact eq_sub_of_add_eq h' | |
| have hd : |(β u : {u : U // d u}, (jointCount w z part u.val a : β)) - | |
| β u : {u : U // d u}, (counts u.val : β) * law u.val a| β€ | |
| (β u : {u : U // d u}, (counts u.val : β)) * Ο := by | |
| rw [β Finset.sum_sub_distrib, Finset.sum_mul] | |
| exact (Finset.abs_sum_le_sum_abs _ _).trans | |
| (Finset.sum_le_sum fun u _ => hdesignated u.val u.property) | |
| exact residual_window_error hm (by rwa [mul_div_cancelβ _ hm.ne']) | |
| hbalance htotal hd | |
| end Counts | |
| section Groups | |
| variable {P U Z A : Type*} [Fintype P] [DecidableEq P] | |
| [Fintype U] [DecidableEq U] [Fintype A] [DecidableEq A] | |
| def designatedGroup (d : U β Prop) (u : U) : Option U := | |
| if d u then some u else none | |
| omit [Fintype U] [DecidableEq U] in | |
| theorem designatedGroup_eq_some (d : U β Prop) (u v : U) : | |
| designatedGroup d v = some u β d u β§ v = u := by | |
| constructor | |
| Β· intro h | |
| by_cases hv : d v | |
| Β· have he : v = u := Option.some.inj (by simpa [designatedGroup, hv] using h) | |
| exact β¨he βΈ hv, heβ© | |
| Β· simp [designatedGroup, hv] at h | |
| Β· rintro β¨hu, rflβ© | |
| simp [designatedGroup, hu] | |
| omit [Fintype U] [DecidableEq U] in | |
| theorem designatedGroup_eq_none (d : U β Prop) (v : U) : | |
| designatedGroup d v = none β Β¬d v := by | |
| simp [designatedGroup] | |
| abbrev GroupPos (w : P β U) (d : U β Prop) (k : Option U) := | |
| {i : P // designatedGroup d (w i) = k} | |
| def groupProjection (w : P β U) (d : U β Prop) (k : Option U) | |
| (z : P β Z) (part : Z β A) : GroupPos w d k β A := | |
| fun i => part (z i.val) | |
| omit [DecidableEq P] [Fintype U] in | |
| theorem groupPos_card_some (w : P β U) (d : U β Prop) (u : U) (hu : d u) : | |
| Fintype.card (GroupPos w d (some u)) = wordPopulation w u := by | |
| apply Fintype.card_congr | |
| exact Equiv.subtypeEquivRight fun i => by simp [designatedGroup_eq_some, hu] | |
| omit [DecidableEq P] [Fintype U] [DecidableEq U] in | |
| theorem groupPos_card_none (w : P β U) (d : U β Prop) : | |
| Fintype.card (GroupPos w d none) = Fintype.card {i : P // Β¬d (w i)} := by | |
| apply Fintype.card_congr | |
| exact Equiv.subtypeEquivRight fun i => designatedGroup_eq_none d (w i) | |
| omit [DecidableEq P] in | |
| theorem restrict_card_eq_sum_population (w : P β U) (d : U β Prop) : | |
| Fintype.card {i : P // d (w i)} = | |
| β u : {u : U // d u}, wordPopulation w u.val := by | |
| simpa only [Fintype.card_sigma, wordPopulation] using | |
| (Fintype.card_congr (Equiv.sigmaSubtypeFiberEquivSubtype w | |
| (p := fun i => d (w i)) (q := d) (fun _ => Iff.rfl))).symm | |
| omit [DecidableEq P] [Fintype A] [Fintype U] in | |
| theorem groupProjection_population_some (w : P β U) (d : U β Prop) | |
| (u : U) (hu : d u) (z : P β Z) (part : Z β A) (a : A) : | |
| wordPopulation (groupProjection w d (some u) z part) a = | |
| jointCount w z part u a := by | |
| apply Fintype.card_congr | |
| refine (Equiv.subtypeSubtypeEquivSubtypeInter | |
| (fun i : P => designatedGroup d (w i) = some u) | |
| (fun i : P => part (z i) = a)).trans ?_ | |
| exact Equiv.subtypeEquivRight fun i => by simp [designatedGroup_eq_some, hu] | |
| omit [DecidableEq P] [Fintype A] [Fintype U] [DecidableEq U] in | |
| theorem groupProjection_population_none (w : P β U) (d : U β Prop) | |
| (z : P β Z) (part : Z β A) (a : A) : | |
| wordPopulation (groupProjection w d none z part) a = | |
| wordPopulation (fun i : {i : P // Β¬d (w i)} => part (z i.val)) a := by | |
| apply Fintype.card_congr | |
| exact (Equiv.subtypeEquiv | |
| (Equiv.subtypeEquivRight fun i => designatedGroup_eq_none d (w i)) fun _ => Iff.rfl) | |
| theorem normalized_count_window {x n p Ο : β} (hn : 0 < n) | |
| (h : |x - n * p| β€ n * Ο) : |x / n - p| β€ Ο := by | |
| apply (mul_le_mul_iff_leftβ hn).mp | |
| calc | |
| |x / n - p| * n = |(x / n - p) * n| := by rw [abs_mul, abs_of_pos hn] | |
| _ = |x - n * p| := by rw [sub_mul, div_mul_cancelβ _ hn.ne', mul_comm p n] | |
| _ β€ n * Ο := h | |
| _ = Ο * n := mul_comm _ _ | |
| omit [DecidableEq P] in | |
| theorem group_entropy_of_designated_windows | |
| (w : P β U) (z : P β Z) (part : Z β A) (d : U β Prop) | |
| (counts : U β β) (hcounts : β u, wordPopulation w u = counts u) | |
| (law : U β A β β) (residualLaw totalTarget : A β β) | |
| (Ο Ξ· : β) (H : Option U β β) (hH : β k, 0 β€ H k) | |
| (htotal : β a, |(wordPopulation (part β z) a : β) - totalTarget a| β€ Ξ·) | |
| (hdesignated : β u, d u β β a, | |
| |(jointCount w z part u a : β) - (counts u : β) * law u a| β€ | |
| (counts u : β) * Ο) | |
| (hbalance : β a, (Fintype.card {i : P // Β¬d (w i)} : β) * residualLaw a = | |
| totalTarget a - β u : {u : U // d u}, (counts u.val : β) * law u.val a) | |
| (hcapDesignated : β u, d u β β q : A β β, | |
| (β a, |q a - law u a| β€ Ο) β finiteEntropy q β€ H (some u)) | |
| (hcapResidual : β q : A β β, | |
| (β a, |q a - residualLaw a| β€ | |
| (Ξ· + (β u : {u : U // d u}, (counts u.val : β)) * Ο) / | |
| Fintype.card {i : P // Β¬d (w i)}) β finiteEntropy q β€ H none) | |
| (k : Option U) : | |
| finiteEntropy (fun a => (wordPopulation (groupProjection w d k z part) a : β) / | |
| Fintype.card (GroupPos w d k)) β€ H k := by | |
| by_cases hzero : Fintype.card (GroupPos w d k) = 0 | |
| Β· simpa only [hzero, Nat.cast_zero, div_zero, finiteEntropy, entropyTerm_zero, | |
| Finset.sum_const_zero] using hH k | |
| have hpos : 0 < Fintype.card (GroupPos w d k) := Nat.pos_of_ne_zero hzero | |
| cases k with | |
| | some u => | |
| obtain β¨iβ© := Fintype.card_pos_iff.mp hpos | |
| have hu : d u := ((designatedGroup_eq_some d u (w i.val)).mp i.property).1 | |
| have hm : 0 < counts u := by | |
| simpa only [groupPos_card_some w d u hu, hcounts u] using hpos | |
| apply hcapDesignated u hu | |
| intro a | |
| simp only [groupProjection_population_some w d u hu, | |
| groupPos_card_some w d u hu, hcounts u] | |
| exact normalized_count_window (Nat.cast_pos.mpr hm) (hdesignated u hu a) | |
| | none => | |
| apply hcapResidual | |
| intro a | |
| simp only [groupProjection_population_none, groupPos_card_none] | |
| exact residual_projected_window w z part d counts law residualLaw totalTarget Ο Ξ· a | |
| (by simpa only [groupPos_card_none] using hpos) (htotal a) | |
| (fun u hu => hdesignated u hu a) (hbalance a) | |
| end Groups | |
| section GroupEntropy | |
| variable {U K A : Type*} [Fintype U] [Fintype K] [Fintype A] | |
| def groupMass (p : U β β) (group : U β K) (k : K) : β := | |
| β u, if group u = k then p u else 0 | |
| def groupLaw (p : U β β) (group : U β K) (law : U β A β β) | |
| (k : K) (a : A) : β := | |
| (β u, if group u = k then p u * law u a else 0) / groupMass p group k | |
| def groupedEntropy (p : U β β) (group : U β K) (law : U β A β β) : β := | |
| β k, groupMass p group k * finiteEntropy (groupLaw p group law k) | |
| omit [Fintype K] in | |
| theorem groupMass_relabel {L : Type*} (e : K β L) (p : U β β) | |
| (group : U β K) (k : K) : | |
| groupMass p (e β group) (e k) = groupMass p group k := by | |
| simp only [groupMass, Function.comp_apply, e.injective.eq_iff] | |
| omit [Fintype A] [Fintype K] in | |
| theorem groupLaw_relabel {L : Type*} (e : K β L) (p : U β β) | |
| (group : U β K) (law : U β A β β) (k : K) : | |
| groupLaw p (e β group) law (e k) = groupLaw p group law k := by | |
| funext a | |
| simp only [groupLaw, groupMass_relabel, Function.comp_apply, e.injective.eq_iff] | |
| theorem groupedEntropy_relabel {L : Type*} [Fintype L] (e : K β L) | |
| (p : U β β) (group : U β K) (law : U β A β β) : | |
| groupedEntropy p (e β group) law = groupedEntropy p group law := by | |
| unfold groupedEntropy | |
| calc | |
| (β l, groupMass p (e β group) l * finiteEntropy (groupLaw p (e β group) law l)) = | |
| β k, groupMass p (e β group) (e k) * | |
| finiteEntropy (groupLaw p (e β group) law (e k)) := (e.sum_comp _).symm | |
| _ = β k, groupMass p group k * finiteEntropy (groupLaw p group law k) := by | |
| simp only [groupMass_relabel, groupLaw_relabel] | |
| omit [Fintype K] in | |
| theorem groupMass_reindex (e : U β U) (p : U β β) (group : U β K) | |
| (hp : β u, p (e u) = p u) (k : K) : | |
| groupMass p (group β e) k = groupMass p group k := by | |
| unfold groupMass | |
| calc | |
| (β u, if (group β e) u = k then p u else 0) = | |
| β u, if group (e u) = k then p (e u) else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro u _ | |
| simp only [Function.comp_apply, hp u] | |
| _ = β u, if group u = k then p u else 0 := | |
| e.sum_comp (fun u => if group u = k then p u else 0) | |
| omit [Fintype A] [Fintype K] in | |
| theorem groupLaw_reindex (e : U β U) (p : U β β) (group : U β K) | |
| (law : U β A β β) (hp : β u, p (e u) = p u) (k : K) : | |
| groupLaw p (group β e) (law β e) k = groupLaw p group law k := by | |
| funext a | |
| unfold groupLaw | |
| rw [groupMass_reindex e p group hp] | |
| congr 1 | |
| calc | |
| (β u, if (group β e) u = k then p u * (law β e) u a else 0) = | |
| β u, if group (e u) = k then p (e u) * law (e u) a else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro u _ | |
| simp only [Function.comp_apply, hp u] | |
| _ = β u, if group u = k then p u * law u a else 0 := | |
| e.sum_comp (fun u => if group u = k then p u * law u a else 0) | |
| theorem groupedEntropy_reindex (e : U β U) (p : U β β) (group : U β K) | |
| (law : U β A β β) (hp : β u, p (e u) = p u) : | |
| groupedEntropy p (group β e) (law β e) = groupedEntropy p group law := by | |
| simp only [groupedEntropy, groupMass_reindex e p group hp, | |
| groupLaw_reindex e p group law hp] | |
| theorem groupedEntropy_add_reindex (e : U β U) (p : U β β) (group : U β K) | |
| (law : U β A β β) (hp : β u, p (e u) = p u) : | |
| groupedEntropy p group law + groupedEntropy p (group β e) (law β e) = | |
| 2 * groupedEntropy p group law := by | |
| rw [groupedEntropy_reindex e p group law hp] | |
| ring | |
| omit [Fintype U] in | |
| theorem designatedGroup_transport (e : U β U) (d : U β Prop) : | |
| e.optionCongr β designatedGroup (d β e) = designatedGroup d β e := by | |
| funext u | |
| by_cases h : d (e u) <;> | |
| simp [designatedGroup, Function.comp_apply, Equiv.optionCongr_apply, h] | |
| theorem designated_groupedEntropy_reindex (e : U β U) (p : U β β) | |
| (d : U β Prop) (law : U β A β β) (hp : β u, p (e u) = p u) : | |
| groupedEntropy p (designatedGroup (d β e)) (law β e) = | |
| groupedEntropy p (designatedGroup d) law := by | |
| calc | |
| groupedEntropy p (designatedGroup (d β e)) (law β e) = | |
| groupedEntropy p (e.optionCongr β designatedGroup (d β e)) (law β e) := | |
| (groupedEntropy_relabel e.optionCongr p (designatedGroup (d β e)) (law β e)).symm | |
| _ = groupedEntropy p (designatedGroup d β e) (law β e) := by | |
| rw [designatedGroup_transport] | |
| _ = groupedEntropy p (designatedGroup d) law := | |
| groupedEntropy_reindex e p (designatedGroup d) law hp | |
| end GroupEntropy | |
| section SideControls | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos Shape Pair A : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (Shape c)] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (Pair c)] [β c, DecidableEq (Pair c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] | |
| variable (shapeCounts : β c, Shape c β β) (pairCounts : β c, Pair c β β) | |
| (part : β c, Pair c β A c) (designated : β c, Shape c β Prop) | |
| (law : β c, Shape c β A c β β) (Ο : β) | |
| (H : (Ξ£ c, Option (Shape c)) β β) (w : FixedClassWords Pos Shape shapeCounts) | |
| structure SideEntropyControl where | |
| residualLaw : β c, A c β β | |
| totalTarget : β c, A c β β | |
| totalError : C β β | |
| aggregate_window : β c a, | |
| |((β s : {s : Pair c // part c s = a}, pairCounts c s.val : β) : β) - | |
| totalTarget c a| β€ totalError c | |
| mixture_balance : β c a, | |
| (Fintype.card {i : Pos c // Β¬designated c ((w c).val i)} : β) * residualLaw c a = | |
| totalTarget c a - β u : {u : Shape c // designated c u}, | |
| (shapeCounts c u.val : β) * law c u.val a | |
| nonneg : β g, 0 β€ H g | |
| designated_entropy : β c u, designated c u β β q : A c β β, | |
| (β a, |q a - law c u a| β€ Ο) β finiteEntropy q β€ H β¨c, some uβ© | |
| residual_entropy : β c, β q : A c β β, | |
| (β a, |q a - residualLaw c a| β€ | |
| (totalError c + (β u : {u : Shape c // designated c u}, | |
| (shapeCounts c u.val : β)) * Ο) / | |
| Fintype.card {i : Pos c // Β¬designated c ((w c).val i)}) β | |
| finiteEntropy q β€ H β¨c, noneβ© | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Pos c)] in | |
| theorem SideEntropyControl.group_entropy | |
| (control : SideEntropyControl Pos Shape Pair A shapeCounts pairCounts | |
| part designated law Ο H w) | |
| (z : FixedClassWords Pos Pair pairCounts) | |
| (hdesignated : β c u, designated c u β β a, | |
| |(jointCount (w c).val (z c).val (part c) u a : β) - | |
| (shapeCounts c u : β) * law c u a| β€ (shapeCounts c u : β) * Ο) | |
| (g : Ξ£ c, Option (Shape c)) : | |
| finiteEntropy (fun a => | |
| (wordPopulation (groupProjection (w g.1).val (designated g.1) g.2 | |
| (z g.1).val (part g.1)) a : β) / | |
| Fintype.card (GroupPos (w g.1).val (designated g.1) g.2)) β€ H g := by | |
| apply group_entropy_of_designated_windows (w g.1).val (z g.1).val (part g.1) | |
| (designated g.1) (shapeCounts g.1) (w g.1).property (law g.1) | |
| (control.residualLaw g.1) (control.totalTarget g.1) Ο (control.totalError g.1) | |
| (fun k => H β¨g.1, kβ©) (fun k => control.nonneg β¨g.1, kβ©) | |
| Β· intro a | |
| rw [projected_population_fixed (z g.1).val (pairCounts g.1) (z g.1).property] | |
| exact control.aggregate_window g.1 a | |
| Β· exact hdesignated g.1 | |
| Β· exact control.mixture_balance g.1 | |
| Β· exact control.designated_entropy g.1 | |
| Β· exact control.residual_entropy g.1 | |
| end SideControls | |
| section Compatibility | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| variable (Pos Shape Pair Left Right : C β Type*) | |
| [β c, Fintype (Pos c)] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (Shape c)] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (Pair c)] [β c, DecidableEq (Pair c)] | |
| [β c, Fintype (Left c)] [β c, DecidableEq (Left c)] | |
| [β c, Fintype (Right c)] [β c, DecidableEq (Right c)] | |
| variable (shapeCounts : β c, Shape c β β) (pairCounts : β c, Pair c β β) | |
| (leftPart : β c, Pair c β Left c) (rightPart : β c, Pair c β Right c) | |
| (designatedLeft designatedRight : β c, Shape c β Prop) | |
| (leftLaw : β c, Shape c β Left c β β) | |
| (rightLaw : β c, Shape c β Right c β β) (Ο : β) | |
| def DesignatedCompatibility (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) : Prop := | |
| (β c u, designatedLeft c u β β a, | |
| |(jointCount (w c).val (z c).val (leftPart c) u a : β) - | |
| (shapeCounts c u : β) * leftLaw c u a| β€ (shapeCounts c u : β) * Ο) β§ | |
| (β c u, designatedRight c u β β a, | |
| |(jointCount (w c).val (z c).val (rightPart c) u a : β) - | |
| (shapeCounts c u : β) * rightLaw c u a| β€ (shapeCounts c u : β) * Ο) | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Pos c)] | |
| [β c, Fintype (Shape c)] [β c, Fintype (Pair c)] | |
| [β c, Fintype (Left c)] [β c, Fintype (Right c)] in | |
| theorem designatedCompatibility_permute (g : ClassPerm Pos) | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) : | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο | |
| (permuteFixedWords Pos Shape shapeCounts g w) | |
| (permuteFixedWords Pos Pair pairCounts g z) β | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z := by | |
| simp only [DesignatedCompatibility, permuteFixedWords, jointCount_reindex] | |
| def compatibleStatisticCount (w : FixedClassWords Pos Shape shapeCounts) : β := | |
| Fintype.card {z : FixedClassWords Pos Pair pairCounts // | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z} | |
| def compatibleCandidateCount (z : FixedClassWords Pos Pair pairCounts) : β := | |
| Fintype.card {w : FixedClassWords Pos Shape shapeCounts // | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z} | |
| omit [β c, Fintype (Left c)] [β c, Fintype (Right c)] in | |
| theorem designated_incidence_count | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) : | |
| Fintype.card (FixedClassWords Pos Shape shapeCounts) * | |
| compatibleStatisticCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w = | |
| Fintype.card (FixedClassWords Pos Pair pairCounts) * | |
| compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z := by | |
| exact invariant_incidence_count (G := ClassPerm Pos) | |
| (DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο) | |
| (designatedCompatibility_permute Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο) w z | |
| omit [β c, Fintype (Left c)] [β c, Fintype (Right c)] in | |
| theorem designated_incidence_multinomial | |
| (hshape : β c, Fintype.card (Pos c) = β u, shapeCounts c u) | |
| (hpair : β c, Fintype.card (Pos c) = β a, pairCounts c a) | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) : | |
| (β c, Nat.multinomial Finset.univ (shapeCounts c)) * | |
| compatibleStatisticCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w = | |
| (β c, Nat.multinomial Finset.univ (pairCounts c)) * | |
| compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z := by | |
| simpa only [fixedClassWords_card Pos Shape shapeCounts hshape, | |
| fixedClassWords_card Pos Pair pairCounts hpair] using | |
| designated_incidence_count Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z | |
| omit [β c, Fintype (Left c)] [β c, Fintype (Right c)] in | |
| theorem compatibleCandidateCount_eq | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) : | |
| (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z : β) = | |
| (Fintype.card (FixedClassWords Pos Shape shapeCounts) : β) * | |
| compatibleStatisticCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w / | |
| Fintype.card (FixedClassWords Pos Pair pairCounts) := by | |
| exact invariant_incidence_degree_eq (G := ClassPerm Pos) | |
| (DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο) | |
| (designatedCompatibility_permute Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο) w z | |
| def wordEntropyBound (I A : Type*) [Fintype I] [Fintype A] (H : β) : β := | |
| ((Fintype.card I : β) + 1) ^ Fintype.card A * | |
| Real.exp ((Fintype.card I : β) * H + | |
| ((Fintype.card A : β) + 1) * (1 + Real.log (Fintype.card I + 1 : β))) | |
| theorem compatibleStatisticCount_le_grouped_entropy | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (hpair : β c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s))) | |
| (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (hL : β z : FixedClassWords Pos Pair pairCounts, | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z β | |
| β g : Ξ£ c, Option (Shape c), | |
| finiteEntropy (fun a => | |
| (wordPopulation (groupProjection (w g.1).val (designatedLeft g.1) g.2 | |
| (z g.1).val (leftPart g.1)) a : β) / | |
| Fintype.card (GroupPos (w g.1).val (designatedLeft g.1) g.2)) β€ HL g) | |
| (hR : β z : FixedClassWords Pos Pair pairCounts, | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z β | |
| β g : Ξ£ c, Option (Shape c), | |
| finiteEntropy (fun a => | |
| (wordPopulation (groupProjection (w g.1).val (designatedRight g.1) g.2 | |
| (z g.1).val (rightPart g.1)) a : β) / | |
| Fintype.card (GroupPos (w g.1).val (designatedRight g.1) g.2)) β€ HR g) : | |
| (compatibleStatisticCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w : β) β€ | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedLeft g.1) g.2) (Left g.1) (HL g)) * | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedRight g.1) g.2) (Right g.1) (HR g)) := by | |
| let J := Ξ£ c, Option (Shape c) | |
| let PL : J β Type _ := fun g => GroupPos (w g.1).val (designatedLeft g.1) g.2 | |
| let PR : J β Type _ := fun g => GroupPos (w g.1).val (designatedRight g.1) g.2 | |
| let EL := β g : J, {v : PL g β Left g.1 // | |
| finiteEntropy (fun a => (wordPopulation v a : β) / Fintype.card (PL g)) β€ HL g} | |
| let ER := β g : J, {v : PR g β Right g.1 // | |
| finiteEntropy (fun a => (wordPopulation v a : β) / Fintype.card (PR g)) β€ HR g} | |
| let Row := {z : FixedClassWords Pos Pair pairCounts // | |
| DesignatedCompatibility Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z} | |
| let encode : Row β EL Γ ER := fun z => | |
| (fun g => β¨groupProjection (w g.1).val (designatedLeft g.1) g.2 | |
| (z.val g.1).val (leftPart g.1), hL z.val z.property gβ©, | |
| fun g => β¨groupProjection (w g.1).val (designatedRight g.1) g.2 | |
| (z.val g.1).val (rightPart g.1), hR z.val z.property gβ©) | |
| have hinj : Function.Injective encode := by | |
| intro x y h | |
| apply Subtype.ext | |
| funext c | |
| apply Subtype.ext | |
| funext i | |
| apply hpair c | |
| apply Prod.ext | |
| Β· exact congrArg (fun v : EL Γ ER => | |
| ((v.1 β¨c, designatedGroup (designatedLeft c) ((w c).val i)β©).val β¨i, rflβ©)) h | |
| Β· exact congrArg (fun v : EL Γ ER => | |
| ((v.2 β¨c, designatedGroup (designatedRight c) ((w c).val i)β©).val β¨i, rflβ©)) h | |
| have hleft : (Fintype.card EL : β) β€ | |
| β g : J, wordEntropyBound (PL g) (Left g.1) (HL g) := | |
| card_class_entropy_bounded_words_le PL (fun g => Left g.1) HL | |
| have hright : (Fintype.card ER : β) β€ | |
| β g : J, wordEntropyBound (PR g) (Right g.1) (HR g) := | |
| card_class_entropy_bounded_words_le PR (fun g => Right g.1) HR | |
| have hcard : (Fintype.card Row : β) β€ (Fintype.card EL : β) * Fintype.card ER := by | |
| simpa only [Fintype.card_prod, Nat.cast_mul] using | |
| (Nat.cast_le.mpr (Fintype.card_le_of_injective encode hinj) : | |
| (Fintype.card Row : β) β€ Fintype.card (EL Γ ER)) | |
| exact hcard.trans (mul_le_mul hleft hright (Nat.cast_nonneg _) | |
| ((Nat.cast_nonneg _).trans hleft)) | |
| theorem compatibleStatisticCount_le_of_controls | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (hpair : β c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s))) | |
| (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts | |
| leftPart designatedLeft leftLaw Ο HL w) | |
| (controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts | |
| rightPart designatedRight rightLaw Ο HR w) : | |
| (compatibleStatisticCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w : β) β€ | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedLeft g.1) g.2) (Left g.1) (HL g)) * | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedRight g.1) g.2) (Right g.1) (HR g)) := by | |
| apply compatibleStatisticCount_le_grouped_entropy Pos Shape Pair Left Right | |
| shapeCounts pairCounts leftPart rightPart designatedLeft designatedRight | |
| leftLaw rightLaw Ο w hpair HL HR | |
| Β· intro z hz g | |
| exact SideEntropyControl.group_entropy Pos Shape Pair Left shapeCounts pairCounts | |
| leftPart designatedLeft leftLaw Ο HL w controlLeft z hz.1 g | |
| Β· intro z hz g | |
| exact SideEntropyControl.group_entropy Pos Shape Pair Right shapeCounts pairCounts | |
| rightPart designatedRight rightLaw Ο HR w controlRight z hz.2 g | |
| theorem compatibleCandidateCount_le_of_controls | |
| (w : FixedClassWords Pos Shape shapeCounts) | |
| (z : FixedClassWords Pos Pair pairCounts) | |
| (hpair : β c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s))) | |
| (HL HR : (Ξ£ c, Option (Shape c)) β β) | |
| (controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts | |
| leftPart designatedLeft leftLaw Ο HL w) | |
| (controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts | |
| rightPart designatedRight rightLaw Ο HR w) : | |
| (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο z : β) β€ | |
| (Fintype.card (FixedClassWords Pos Shape shapeCounts) : β) * | |
| ((β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedLeft g.1) g.2) (Left g.1) (HL g)) * | |
| (β g : Ξ£ c, Option (Shape c), wordEntropyBound | |
| (GroupPos (w g.1).val (designatedRight g.1) g.2) (Right g.1) (HR g))) / | |
| Fintype.card (FixedClassWords Pos Pair pairCounts) := by | |
| rw [compatibleCandidateCount_eq Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w z] | |
| apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) | |
| exact mul_le_mul_of_nonneg_left | |
| (compatibleStatisticCount_le_of_controls Pos Shape Pair Left Right shapeCounts pairCounts | |
| leftPart rightPart designatedLeft designatedRight leftLaw rightLaw Ο w hpair HL HR | |
| controlLeft controlRight) (Nat.cast_nonneg _) | |
| end Compatibility | |
| end MatrixMultiplication.JointCompatibilityIncidence | |
| end | |
| end OAI | |