math / data /lean /OAI /LinearAlgebra /MatrixFields /Extraction /JointPairClassWindows.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
21.2 kB
import Mathlib
import OAI.LinearAlgebra.MatrixFields.Entropy.ZeroLeafRateFormula
namespace OAI
namespace MatrixAllFields
open scoped BigOperators Topology Polynomial
section
namespace MatrixMultiplication.Foundation
open scoped BigOperators
variable {A I J : Type*} [Fintype A] [DecidableEq A] [Fintype I] [Fintype J]
[DecidableEq I]
def wordPopulation (w : I β†’ A) (a : A) : β„• := Fintype.card {i // w i = a}
omit [DecidableEq I] in
theorem wordPopulation_sum (w : I β†’ A) :
βˆ‘ a, wordPopulation w a = Fintype.card I := by
simpa [wordPopulation] using Fintype.card_congr (Equiv.sigmaFiberEquiv w)
omit [Fintype A] [DecidableEq I] in
theorem wordPopulation_reindex (w : I β†’ A) (e : J ≃ I) (a : A) :
wordPopulation (w ∘ e) a = wordPopulation w a :=
Fintype.card_congr (Equiv.subtypeEquiv e fun _ => Iff.rfl)
abbrev ExactWords (counts : A β†’ β„•) :=
{w : Fin (βˆ‘ a, counts a) β†’ A // βˆ€ a, wordPopulation w a = counts a}
theorem wordPopulation_sigma_fst (counts : A β†’ β„•) (a : A) :
wordPopulation (fun i : Ξ£ b, Fin (counts b) => i.1) a = counts a := by
let e : {i : Ξ£ b, Fin (counts b) // i.1 = a} ≃ Fin (counts a) :=
{ toFun := fun i => i.property β–Έ i.val.2
invFun := fun i => ⟨⟨a, i⟩, rfl⟩
left_inv := by
rintro ⟨⟨b, i⟩, h⟩
cases h
rfl
right_inv := by intro i; rfl }
exact (Fintype.card_congr e).trans (Fintype.card_fin _)
theorem exactWords_nonempty (counts : A β†’ β„•) : Nonempty (ExactWords counts) := by
classical
let e : Fin (βˆ‘ a, counts a) ≃ (Ξ£ a, Fin (counts a)) :=
Fintype.equivOfCardEq (by simp)
refine ⟨⟨(fun i : Σ a, Fin (counts a) => i.1) ∘ e, ?_⟩⟩
intro a
rw [wordPopulation_reindex, wordPopulation_sigma_fst]
omit [Fintype A] [DecidableEq I] in
theorem samePopulation_iff_permutation (w v : I β†’ A) :
(βˆ€ a, wordPopulation v a = wordPopulation w a) ↔
βˆƒ e : Equiv.Perm I, w ∘ e = v := by
classical
constructor
Β· intro h
let es : βˆ€ a, {i // v i = a} ≃ {i // w i = a} :=
fun a => Fintype.equivOfCardEq (h a)
refine ⟨Equiv.ofFiberEquiv es, ?_⟩
funext i
exact Equiv.ofFiberEquiv_map es i
· rintro ⟨e, rfl⟩ a
exact wordPopulation_reindex w e a
theorem samePopulation_card_mul (w : I β†’ A) :
Fintype.card {v : I β†’ A // βˆ€ a, wordPopulation v a = wordPopulation w a} *
(∏ a, (wordPopulation w a).factorial) = (Fintype.card I).factorial := by
classical
let G := DomMulAct (Equiv.Perm I)
let : Fintype G := Fintype.ofEquiv (Equiv.Perm I) DomMulAct.mk
let eOrbit : {v : I β†’ A // βˆ€ a, wordPopulation v a = wordPopulation w a} ≃
MulAction.orbit G w :=
Equiv.subtypeEquivRight fun v => by
rw [samePopulation_iff_permutation, MulAction.mem_orbit_iff]
constructor
· rintro ⟨e, he⟩
exact ⟨DomMulAct.mk e, he⟩
· rintro ⟨g, hg⟩
exact ⟨DomMulAct.mk.symm g, hg⟩
let eStab : MulAction.stabilizer G w ≃
{e : Equiv.Perm I // w ∘ e = w} :=
Equiv.subtypeEquiv DomMulAct.mk.symm fun _ => DomMulAct.mem_stabilizer_iff
have hstab : Fintype.card (MulAction.stabilizer G w) =
∏ a, (wordPopulation w a).factorial := by
rw [Fintype.card_congr eStab]
exact DomMulAct.stabilizer_card w
have hgroup : Fintype.card G = (Fintype.card I).factorial :=
(Fintype.card_congr DomMulAct.mk.symm).trans Fintype.card_perm
have h := MulAction.card_orbit_mul_card_stabilizer_eq_card_group G w
rw [← Fintype.card_congr eOrbit, hstab, hgroup] at h
exact h
theorem exactWords_card (counts : A β†’ β„•) :
Fintype.card (ExactWords counts) = Nat.multinomial Finset.univ counts := by
classical
obtain ⟨w⟩ := exactWords_nonempty counts
let e : ExactWords counts ≃
{v : Fin (βˆ‘ a, counts a) β†’ A // βˆ€ a,
wordPopulation v a = wordPopulation w.val a} :=
Equiv.subtypeEquivRight fun v => by simp only [w.property]
have h := samePopulation_card_mul w.val
rw [← Fintype.card_congr e] at h
simp only [w.property, Fintype.card_fin] at h
exact Nat.eq_div_of_mul_eq_left
(ne_of_gt (Nat.prod_factorial_pos Finset.univ counts)) h
theorem exactWords_card_pos (counts : A β†’ β„•) : 0 < Fintype.card (ExactWords counts) := by
rw [exactWords_card]
exact Nat.multinomial_pos Finset.univ counts
theorem exactWords_card_le (counts : A β†’ β„•) :
Fintype.card (ExactWords counts) ≀ (Fintype.card A) ^ (βˆ‘ a, counts a) := by
classical
calc
Fintype.card (ExactWords counts) ≀
Fintype.card (Fin (βˆ‘ a, counts a) β†’ A) :=
Fintype.card_le_of_injective Subtype.val Subtype.val_injective
_ = _ := by simp
end MatrixMultiplication.Foundation
namespace MatrixMultiplication.Foundation
open scoped BigOperators
variable {A B I : Type*} [Fintype A] [DecidableEq A]
[Fintype B] [DecidableEq B] [Fintype I] [DecidableEq I]
abbrev PopulationWords (I : Type*) [Fintype I] (counts : A β†’ β„•) :=
{w : I β†’ A // βˆ€ a, wordPopulation w a = counts a}
noncomputable def populationWordsEquiv (counts : A β†’ β„•)
(h : Fintype.card I = βˆ‘ a, counts a) : PopulationWords I counts ≃ ExactWords counts := by
let e : I ≃ Fin (βˆ‘ a, counts a) := Fintype.equivFinOfCardEq h
exact
{ toFun := fun w =>
⟨w.val ∘ e.symm, fun a => (wordPopulation_reindex w.val e.symm a).trans (w.property a)⟩
invFun := fun w =>
⟨w.val ∘ e, fun a => (wordPopulation_reindex w.val e a).trans (w.property a)⟩
left_inv := by
intro w
apply Subtype.ext
funext i
simp
right_inv := by
intro w
apply Subtype.ext
funext i
simp }
theorem populationWords_card (counts : A β†’ β„•)
(h : Fintype.card I = βˆ‘ a, counts a) :
Fintype.card (PopulationWords I counts) = Nat.multinomial Finset.univ counts := by
rw [Fintype.card_congr (populationWordsEquiv counts h), exactWords_card]
abbrev ConditionalWords (w : I β†’ A) (counts : A β†’ B β†’ β„•) :=
{r : I β†’ B // βˆ€ a b, Fintype.card {i // w i = a ∧ r i = b} = counts a b}
def fiberWordEquiv (w : I β†’ A) : (I β†’ B) ≃ (βˆ€ a, {i // w i = a} β†’ B) where
toFun r _ i := r i.val
invFun r i := r (w i) ⟨i, rfl⟩
left_inv _ := rfl
right_inv := by
intro r
funext a i
rcases i with ⟨i, hi⟩
cases hi
rfl
omit [Fintype A] [Fintype B] [DecidableEq I] in
theorem wordPopulation_fiber (w : I β†’ A) (r : I β†’ B) (a : A) (b : B) :
wordPopulation (fun i : {i // w i = a} => r i.val) b =
Fintype.card {i // w i = a ∧ r i = b} :=
Fintype.card_congr
(Equiv.subtypeSubtypeEquivSubtypeInter (fun i => w i = a) (fun i => r i = b))
def conditionalWordsEquiv (w : I β†’ A) (counts : A β†’ B β†’ β„•) :
ConditionalWords w counts ≃ βˆ€ a, PopulationWords {i // w i = a} (counts a) := by
let e : ConditionalWords w counts ≃
{r : βˆ€ a, {i // w i = a} β†’ B // βˆ€ a b, wordPopulation (r a) b = counts a b} :=
Equiv.subtypeEquiv (fiberWordEquiv w) fun r => by
change (βˆ€ a b, Fintype.card {i // w i = a ∧ r i = b} = counts a b) ↔
βˆ€ a b, wordPopulation (fun i : {i // w i = a} => r i.val) b = counts a b
simp only [wordPopulation_fiber]
exact e.trans (Equiv.subtypePiEquivPi
(Ξ² := fun a : A => {i // w i = a} β†’ B)
(p := fun a r => βˆ€ b, wordPopulation r b = counts a b))
theorem conditionalWords_card (w : I β†’ A) (counts : A β†’ B β†’ β„•)
(h : βˆ€ a, wordPopulation w a = βˆ‘ b, counts a b) :
Fintype.card (ConditionalWords w counts) =
∏ a, Nat.multinomial Finset.univ (counts a) := by
rw [Fintype.card_congr (conditionalWordsEquiv w counts), Fintype.card_pi]
exact Finset.prod_congr rfl fun a _ => populationWords_card (counts a) (h a)
theorem conditionalWords_card_pos (w : I β†’ A) (counts : A β†’ B β†’ β„•)
(h : βˆ€ a, wordPopulation w a = βˆ‘ b, counts a b) :
0 < Fintype.card (ConditionalWords w counts) := by
rw [conditionalWords_card w counts h]
exact Finset.prod_pos fun a _ => Nat.multinomial_pos Finset.univ (counts a)
theorem conditionalWords_nonempty (w : I β†’ A) (counts : A β†’ B β†’ β„•)
(h : βˆ€ a, wordPopulation w a = βˆ‘ b, counts a b) :
Nonempty (ConditionalWords w counts) :=
Fintype.card_pos_iff.mp (conditionalWords_card_pos w counts h)
theorem conditionalWords_nonempty_iff (w : I β†’ A) (counts : A β†’ B β†’ β„•) :
Nonempty (ConditionalWords w counts) ↔
βˆ€ a, wordPopulation w a = βˆ‘ b, counts a b := by
constructor
· rintro ⟨r⟩ a
calc
wordPopulation w a =
βˆ‘ b, wordPopulation (fun i : {i // w i = a} => r.val i.val) b :=
(wordPopulation_sum _).symm
_ = βˆ‘ b, counts a b := by
apply Finset.sum_congr rfl
intro b _
rw [wordPopulation_fiber, r.property]
Β· exact conditionalWords_nonempty w counts
omit [DecidableEq A] [DecidableEq B] in
theorem multinomial_prod_counts (counts : A Γ— B β†’ β„•) :
Nat.multinomial Finset.univ counts =
Nat.multinomial Finset.univ (fun a => βˆ‘ b, counts (a, b)) *
∏ a, Nat.multinomial Finset.univ (fun b => counts (a, b)) := by
apply Nat.mul_left_cancel (Nat.prod_factorial_pos Finset.univ counts)
rw [Nat.multinomial_spec]
symm
calc
(∏ ab, (counts ab).factorial) *
(Nat.multinomial Finset.univ (fun a => βˆ‘ b, counts (a, b)) *
∏ a, Nat.multinomial Finset.univ (fun b => counts (a, b))) =
((∏ a, ∏ b, (counts (a, b)).factorial) *
∏ a, Nat.multinomial Finset.univ (fun b => counts (a, b))) *
Nat.multinomial Finset.univ (fun a => βˆ‘ b, counts (a, b)) := by
rw [Fintype.prod_prod_type]
ac_rfl
_ = (∏ a, ((∏ b, (counts (a, b)).factorial) *
Nat.multinomial Finset.univ (fun b => counts (a, b)))) *
Nat.multinomial Finset.univ (fun a => βˆ‘ b, counts (a, b)) := by
rw [Finset.prod_mul_distrib]
_ = (∏ a, (βˆ‘ b, counts (a, b)).factorial) *
Nat.multinomial Finset.univ (fun a => βˆ‘ b, counts (a, b)) := by
congr 1
apply Finset.prod_congr rfl
intro a _
exact Nat.multinomial_spec Finset.univ (fun b => counts (a, b))
_ = (βˆ‘ a, βˆ‘ b, counts (a, b)).factorial :=
Nat.multinomial_spec Finset.univ (fun a => βˆ‘ b, counts (a, b))
_ = (βˆ‘ ab, counts ab).factorial := by rw [Fintype.sum_prod_type]
theorem exactWords_card_prod_counts (counts : A Γ— B β†’ β„•) :
Fintype.card (ExactWords counts) =
Fintype.card (ExactWords (fun a => βˆ‘ b, counts (a, b))) *
∏ a, Fintype.card (ExactWords (fun b => counts (a, b))) := by
simpa only [exactWords_card] using multinomial_prod_counts counts
theorem exactWords_card_eq_coarse_mul_conditional (counts : A Γ— B β†’ β„•)
(w : ExactWords (fun a => βˆ‘ b, counts (a, b))) :
Fintype.card (ExactWords counts) =
Fintype.card (ExactWords (fun a => βˆ‘ b, counts (a, b))) *
Fintype.card (ConditionalWords w.val (fun a b => counts (a, b))) := by
rw [conditionalWords_card w.val (fun a b => counts (a, b)) w.property]
simpa only [exactWords_card] using multinomial_prod_counts counts
end MatrixMultiplication.Foundation
noncomputable section
namespace MatrixMultiplication.Foundation
open scoped BigOperators
universe u v
def pushforwardCounts {A B : Type*} [Fintype A]
(counts : A β†’ β„•) (label : A β†’ B) (b : B) : β„• := by
classical
exact βˆ‘ a, if label a = b then counts a else 0
theorem pushforwardCounts_sum {A B : Type*} [Fintype A] [Fintype B]
(counts : A β†’ β„•) (label : A β†’ B) :
(βˆ‘ b, pushforwardCounts counts label b) = βˆ‘ a, counts a := by
classical
unfold pushforwardCounts
rw [Finset.sum_comm]
simp
theorem pushforwardCounts_apply {A B : Type*} [Fintype A]
(counts : A β†’ β„•) (label : A β†’ B) (hinjective : Function.Injective label)
(a : A) : pushforwardCounts counts label (label a) = counts a := by
classical
simp [pushforwardCounts, hinjective.eq_iff]
theorem pushforwardCounts_sum_pair {A B C : Type*}
[Fintype A] [Fintype C] (counts : A β†’ β„•)
(coarse : A β†’ B) (fine : A β†’ C) (b : B) :
(βˆ‘ c, pushforwardCounts counts (fun a => (coarse a, fine a)) (b, c)) =
pushforwardCounts counts coarse b := by
classical
unfold pushforwardCounts
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro a _
by_cases hab : coarse a = b
Β· simp [Prod.mk.injEq, hab]
Β· simp [Prod.mk.injEq, hab]
theorem pushforwardCounts_factorial_prod_of_injective {A B : Type*}
[Fintype A] [Fintype B] (counts : A β†’ β„•) (label : A β†’ B)
(hinjective : Function.Injective label) :
(∏ b, (pushforwardCounts counts label b).factorial) =
∏ a, (counts a).factorial := by
classical
have hfactor (b : B) : (pushforwardCounts counts label b).factorial =
∏ a, if label a = b then (counts a).factorial else 1 := by
by_cases hb : βˆƒ a, label a = b
· obtain ⟨a, rfl⟩ := hb
rw [pushforwardCounts_apply counts label hinjective]
simp [hinjective.eq_iff]
Β· simp [pushforwardCounts, not_exists.mp hb]
simp_rw [hfactor]
rw [Finset.prod_comm]
simp
theorem multinomial_pushforwardCounts_of_injective {A B : Type*}
[Fintype A] [Fintype B] (counts : A β†’ β„•) (label : A β†’ B)
(hinjective : Function.Injective label) :
Nat.multinomial Finset.univ (pushforwardCounts counts label) =
Nat.multinomial Finset.univ counts := by
simp only [Nat.multinomial, pushforwardCounts_sum,
pushforwardCounts_factorial_prod_of_injective counts label hinjective]
namespace LabelHierarchyCounts
variable {Label : β„• β†’ Type u} [βˆ€ n, Fintype (Label n)]
def refinementCount (counts : βˆ€ n, LabelRecord Label n β†’ β„•) (n : β„•) : β„• :=
∏ r : LabelRecord Label n,
Nat.multinomial Finset.univ (fun s : Label n => counts (n + 1) (r, s))
theorem multinomial_succ (counts : βˆ€ n, LabelRecord Label n β†’ β„•) (n : β„•)
(compatible : βˆ€ r, counts n r = βˆ‘ s : Label n, counts (n + 1) (r, s)) :
Nat.multinomial Finset.univ (counts (n + 1)) =
Nat.multinomial Finset.univ (counts n) * refinementCount counts n := by
classical
erw [multinomial_prod_counts]
have hrows : (fun r => βˆ‘ s : Label n, counts (n + 1) (r, s)) = counts n :=
funext fun r => (compatible r).symm
rw [hrows]
rfl
theorem pool_multinomial_eq_one_of_zero
(counts : βˆ€ n, LabelRecord Label n β†’ β„•) (n : β„•)
(compatible : βˆ€ r, counts n r = βˆ‘ s : Label n, counts (n + 1) (r, s))
(r : LabelRecord Label n) (hzero : counts n r = 0) :
Nat.multinomial Finset.univ (fun s : Label n => counts (n + 1) (r, s)) = 1 := by
have hchild (s : Label n) : counts (n + 1) (r, s) = 0 := by
apply Nat.eq_zero_of_le_zero
calc
counts (n + 1) (r, s) ≀ βˆ‘ t : Label n, counts (n + 1) (r, t) :=
Finset.single_le_sum (f := fun t : Label n => counts (n + 1) (r, t))
(fun t _ => Nat.zero_le _) (Finset.mem_univ s)
_ = 0 := (compatible r).symm.trans hzero
simp [Nat.multinomial, hchild]
theorem multinomial_eq_refinementCount_product
(counts : βˆ€ n, LabelRecord Label n β†’ β„•) (depth : β„•)
(compatible : βˆ€ n < depth, βˆ€ r,
counts n r = βˆ‘ s : Label n, counts (n + 1) (r, s)) :
Nat.multinomial Finset.univ (counts depth) =
∏ n ∈ Finset.range depth, refinementCount counts n := by
classical
induction depth with
| zero =>
have hroot : (Finset.univ : Finset (LabelRecord Label 0)) = {PUnit.unit} := rfl
erw [hroot, Nat.multinomial_singleton]
simp
| succ depth ih =>
rw [multinomial_succ counts depth (compatible depth (Nat.lt_succ_self depth))]
rw [ih (fun n hn => compatible n (Nat.lt_trans hn (Nat.lt_succ_self depth))),
Finset.prod_range_succ]
def sourcePrefixCounts {A : Type v} [Fintype A] (counts : A β†’ β„•)
(labels : βˆ€ n, A β†’ Label n) (n : β„•) : LabelRecord Label n β†’ β„• :=
pushforwardCounts counts (labelRecordOf labels n)
theorem sourcePrefixCounts_compatible {A : Type v} [Fintype A]
(counts : A β†’ β„•) (labels : βˆ€ n, A β†’ Label n) (n : β„•)
(r : LabelRecord Label n) :
sourcePrefixCounts counts labels n r =
βˆ‘ s : Label n, sourcePrefixCounts counts labels (n + 1) (r, s) :=
(pushforwardCounts_sum_pair counts (labelRecordOf labels n) (labels n) r).symm
theorem source_refinementCount_product {A : Type v} [Fintype A]
(counts : A β†’ β„•) (labels : βˆ€ n, A β†’ Label n) (depth : β„•)
(hinjective : Function.Injective (labelRecordOf labels depth)) :
(∏ n ∈ Finset.range depth, refinementCount (sourcePrefixCounts counts labels) n) =
Nat.multinomial Finset.univ counts := by
calc
(∏ n ∈ Finset.range depth, refinementCount (sourcePrefixCounts counts labels) n) =
Nat.multinomial Finset.univ (sourcePrefixCounts counts labels depth) :=
(multinomial_eq_refinementCount_product (sourcePrefixCounts counts labels) depth
(fun n _ r => sourcePrefixCounts_compatible counts labels n r)).symm
_ = Nat.multinomial Finset.univ counts :=
multinomial_pushforwardCounts_of_injective counts
(labelRecordOf labels depth) hinjective
theorem source_refinementCount_product_eq_exactWords_card
{A : Type v} [Fintype A] [DecidableEq A]
(counts : A β†’ β„•) (labels : βˆ€ n, A β†’ Label n) (depth : β„•)
(hinjective : Function.Injective (labelRecordOf labels depth)) :
(∏ n ∈ Finset.range depth, refinementCount (sourcePrefixCounts counts labels) n) =
Fintype.card (ExactWords counts) := by
rw [source_refinementCount_product counts labels depth hinjective, exactWords_card]
end LabelHierarchyCounts
end MatrixMultiplication.Foundation
namespace MatrixMultiplication.JointPairClassWindows
open MatrixMultiplication.Foundation
attribute [local instance] Classical.propDecidable
variable {I A C : Type*} [Fintype I] [Fintype A] [Fintype C]
[DecidableEq I] [DecidableEq A] [DecidableEq C]
abbrev Fiber (k : I β†’ C) (c : C) := {i : I // k i = c}
def fiberWord (z : I β†’ A) (k : I β†’ C) (c : C) : Fiber k c β†’ A :=
fun i => z i.val
omit [Fintype A] [Fintype C] [DecidableEq I] in
theorem fiber_population (z : I β†’ A) (k : I β†’ C) (f : A β†’ C)
(hf : βˆ€ i, f (z i) = k i) (c : C) (a : A) :
wordPopulation (fiberWord z k c) a =
if f a = c then wordPopulation z a else 0 := by
classical
by_cases ha : f a = c
Β· rw [ite_eq_left ha]
unfold wordPopulation
apply Fintype.card_congr
exact
{ toFun := fun i => ⟨i.val.val, i.property⟩
invFun := fun i => ⟨⟨i.val, by rw [← hf i.val, i.property, ha]⟩, i.property⟩
left_inv := fun ⟨⟨i, hi⟩, hia⟩ => rfl
right_inv := fun ⟨i, hia⟩ => rfl }
Β· rw [ite_eq_right ha]
let : IsEmpty {i : Fiber k c // fiberWord z k c i = a} :=
⟨fun i => ha (calc
f a = f (z i.val.val) := congrArg f i.property.symm
_ = k i.val.val := hf _
_ = c := i.val.property)⟩
exact Fintype.card_eq_zero
omit [Fintype C] [DecidableEq I] in
theorem fiber_card (k : I β†’ C) (c : C) :
Fintype.card (Fiber k c) = wordPopulation k c := rfl
def conditionalCenter (f : A β†’ C) (c : C) (q : A β†’ ℝ) (mass : ℝ) : A β†’ ℝ :=
fun a => if f a = c then q a / mass else 0
omit [Fintype A] [Fintype C] [DecidableEq I] in
theorem fiber_window (z : I β†’ A) (k : I β†’ C) (f : A β†’ C)
(hf : βˆ€ i, f (z i) = k i) (c : C) (q : A β†’ ℝ) (mass Ξ· : ℝ)
(hmass : 0 < mass) (hΞ· : 0 ≀ Ξ·)
(hclass : (Fintype.card (Fiber k c) : ℝ) = (Fintype.card I : ℝ) * mass)
(hwindow : βˆ€ a, |(wordPopulation z a : ℝ) / Fintype.card I - q a| ≀ Ξ·) :
βˆ€ a, |(wordPopulation (fiberWord z k c) a : ℝ) / Fintype.card (Fiber k c) -
conditionalCenter f c q mass a| ≀ Ξ· / mass := by
intro a
rw [fiber_population z k f hf c a]
by_cases ha : f a = c
Β· simp only [ha, ite_true, conditionalCenter]
rw [hclass]
have hid : (wordPopulation z a : ℝ) / ((Fintype.card I : ℝ) * mass) - q a / mass =
((wordPopulation z a : ℝ) / Fintype.card I - q a) / mass := by
rw [sub_div, div_div]
rw [hid, abs_div, abs_of_pos hmass]
exact div_le_div_of_nonneg_right (hwindow a) hmass.le
Β· simp only [ha, ite_false, Nat.cast_zero, zero_div, conditionalCenter, sub_zero, abs_zero]
exact div_nonneg hΞ· hmass.le
omit [Fintype A] [Fintype C] [DecidableEq I] in
theorem fiber_count_window (z : I β†’ A) (k : I β†’ C) (f : A β†’ C)
(hf : βˆ€ i, f (z i) = k i) (c : C) (q : A β†’ ℝ) (Ξ· : ℝ) (hΞ· : 0 ≀ Ξ·)
(hwindow : βˆ€ a,
|(wordPopulation z a : ℝ) - (Fintype.card I : ℝ) * q a| ≀ (Fintype.card I : ℝ) * Ξ·) :
βˆ€ a, |(wordPopulation (fiberWord z k c) a : ℝ) -
(Fintype.card I : ℝ) * (if f a = c then q a else 0)| ≀ (Fintype.card I : ℝ) * Ξ· := by
intro a
rw [fiber_population z k f hf c a]
by_cases ha : f a = c
Β· simpa only [ha, ite_true] using hwindow a
Β· simp only [ha, ite_false, Nat.cast_zero, mul_zero, sub_zero, abs_zero]
exact mul_nonneg (Nat.cast_nonneg _) hΞ·
end MatrixMultiplication.JointPairClassWindows
end
end
end MatrixAllFields
end OAI