File size: 12,986 Bytes
cdec422 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | import OAI.LinearAlgebra.MatrixMultiplication.Separation.AuxiliarySeparation
import OAI.LinearAlgebra.MatrixMultiplication.Entropy.ComplexHierarchyEntropy
namespace OAI
/-! Finite entropy, rate estimates and ordered asymptotic limits. -/
noncomputable section
namespace MatrixMultiplication
open MatrixMultiplication.Foundation Filter
open scoped Topology BigOperators Classical
inductive ReaderPair where
| xy | xz | yz
deriving DecidableEq
protected abbrev ReaderPair.enumList : List ReaderPair := [.xy, .xz, .yz]
protected theorem ReaderPair.enumList_getElem?_ctorIdx_eq (x : ReaderPair) :
ReaderPair.enumList[ReaderPair.ctorIdx x]? = some x := by
cases x <;> rfl
protected theorem ReaderPair.enumList_nodup : ReaderPair.enumList.Nodup := by
apply List.Nodup.of_map ReaderPair.ctorIdx
have h : List.map ReaderPair.ctorIdx ReaderPair.enumList = List.range 3 := rfl
exact h ▸ List.nodup_range
instance : Fintype ReaderPair where
elems := Finset.mk ReaderPair.enumList (Multiset.coe_nodup.mpr ReaderPair.enumList_nodup)
complete := by
intro x
rw [Finset.mem_mk, Multiset.mem_coe, List.mem_iff_getElem?]
exact ⟨ReaderPair.ctorIdx x, ReaderPair.enumList_getElem?_ctorIdx_eq x⟩
namespace ConditionalLabels
universe u v
section PairAccounting
variable {I : Type u} [Fintype I]
def pairingSize (population : I → ℕ) (reader : I → ReaderPair)
(pair : ReaderPair) : ℕ :=
∏ i, if reader i = pair then population i else 1
def pairingRate (rate : I → ℝ) (reader : I → ReaderPair)
(pair : ReaderPair) : ℝ :=
∑ i, if reader i = pair then rate i else 0
theorem pairingSize_pos (population : I → ℕ) (reader : I → ReaderPair)
(pair : ReaderPair) (positive : ∀ i, 0 < population i) :
0 < pairingSize population reader pair := by
apply Finset.prod_pos
intro i _
split_ifs
· exact positive i
· exact Nat.zero_lt_one
theorem pairingRate_nonneg (rate : I → ℝ) (reader : I → ReaderPair)
(pair : ReaderPair) (nonneg : ∀ i, 0 ≤ rate i) :
0 ≤ pairingRate rate reader pair := by
apply Finset.sum_nonneg
intro i _
split_ifs
· exact nonneg i
· exact le_rfl
theorem pairingSize_product (population : I → ℕ) (reader : I → ReaderPair) :
pairingSize population reader .xy * pairingSize population reader .xz *
pairingSize population reader .yz = ∏ i, population i := by
simp only [pairingSize, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro i _
cases reader i <;> simp
theorem pairingRate_sum (rate : I → ℝ) (reader : I → ReaderPair) :
pairingRate rate reader .xy + pairingRate rate reader .xz +
pairingRate rate reader .yz = ∑ i, rate i := by
simp only [pairingRate, ← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro i _
cases reader i <;> simp
theorem tendsto_log_pairingSize (population : I → ℕ → ℕ)
(rate : I → ℝ) (reader : I → ReaderPair) (pair : ReaderPair)
(positive : ∀ i n, 0 < population i n)
(growth : ∀ i, Tendsto (fun n => Real.log (population i n : ℝ) / (n : ℝ))
atTop (𝓝 (rate i))) :
Tendsto (fun n => Real.log (pairingSize (fun i => population i n) reader pair : ℝ) /
(n : ℝ)) atTop (𝓝 (pairingRate rate reader pair)) := by
apply Separation.tendsto_log_nat_prod_div_nat Finset.univ
· intro i _ n
split_ifs
· exact positive i n
· exact Nat.zero_lt_one
· intro i _
by_cases h : reader i = pair
· simpa only [h, ite_true] using growth i
· simpa only [h, ite_false, Nat.cast_one, Real.log_one, zero_div] using
(tendsto_const_nhds : Tendsto (fun _ : ℕ => (0 : ℝ)) atTop (𝓝 0))
end PairAccounting
section SourceHierarchy
variable {A : Type u} [Fintype A] {Label : ℕ → Type v}
[∀ n, Fintype (Label n)]
open StageHierarchyResources HierarchySeparationRates
def stagePairingSize (counts : A → ℕ) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair) (pair : ReaderPair) (t : ℕ) : ℕ :=
pairingSize (fun n : Fin depth => stageRefinementCount counts labels n.val t) reader pair
def stagePairingRate (counts : A → ℕ) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair) (pair : ReaderPair) : ℝ :=
pairingRate (fun n : Fin depth => stageEntropyRate counts labels n.val) reader pair
theorem stagePairingSize_product (counts : A → ℕ) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair)
(complete : Function.Injective (labelRecordOf labels depth)) (t : ℕ) :
stagePairingSize counts labels depth reader .xy t *
stagePairingSize counts labels depth reader .xz t *
stagePairingSize counts labels depth reader .yz t =
Fintype.card (ExactWords (fun a => t * counts a)) := by
rw [stagePairingSize, stagePairingSize, stagePairingSize, pairingSize_product]
exact stagePairingProduct_eq_exactWords_card counts labels depth complete t
theorem stagePairingRate_sum (counts : A → ℕ) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair)
(complete : Function.Injective (labelRecordOf labels depth)) :
stagePairingRate counts labels depth reader .xy +
stagePairingRate counts labels depth reader .xz +
stagePairingRate counts labels depth reader .yz = populationEntropyRate counts := by
rw [stagePairingRate, stagePairingRate, stagePairingRate, pairingRate_sum]
exact sum_stageEntropyRate_eq_source counts labels depth complete
theorem tendsto_log_stagePairingSize (counts : A → ℕ) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair) (pair : ReaderPair) :
Tendsto (fun t => Real.log (stagePairingSize counts labels depth reader pair t : ℝ) /
(t : ℝ)) atTop (𝓝 (stagePairingRate counts labels depth reader pair)) := by
exact tendsto_log_pairingSize _ _ reader pair
(fun n => stageRefinementCount_pos counts labels n.val)
(fun n => tendsto_log_stageRefinementCount_div counts labels n.val)
theorem tendsto_log_stagePairingSize_normalized (counts : A → ℕ)
(labels : ∀ n, A → Label n) (depth : ℕ)
(reader : Fin depth → ReaderPair) (pair : ReaderPair) :
Tendsto (fun t => Real.log (stagePairingSize counts labels depth reader pair t : ℝ) /
((t : ℝ) * (∑ a, counts a : ℕ))) atTop
(𝓝 (stagePairingRate counts labels depth reader pair / (∑ a, counts a : ℕ))) := by
simpa only [div_div] using
(tendsto_log_stagePairingSize counts labels depth reader pair).div_const
((∑ a, counts a : ℕ) : ℝ)
theorem auxiliary_overhead_tendsto_zero (counts : A → ℕ) (hD : 0 < ∑ a, counts a)
(labels : ∀ n, A → Label n) (depth : ℕ)
(complete : Function.Injective (labelRecordOf labels depth)) :
Tendsto (fun t =>
(Real.log (stageAuxiliaryBudget counts labels depth t : ℝ) -
Real.log (Fintype.card (ExactWords (fun a => t * counts a)) : ℝ)) /
((t : ℝ) * (∑ a, counts a : ℕ))) atTop (𝓝 0) := by
have h := (tendsto_log_stageAuxiliaryBudget counts hD labels depth complete).sub
(tendsto_log_exactWords_card_mul counts hD)
simpa only [sub_self, sub_div] using h
theorem auxiliary_overhead_nonneg (counts : A → ℕ)
(labels : ∀ n, A → Label n) (depth : ℕ)
(complete : Function.Injective (labelRecordOf labels depth)) (t : ℕ) :
0 ≤ Real.log (stageAuxiliaryBudget counts labels depth t : ℝ) -
Real.log (Fintype.card (ExactWords (fun a => t * counts a)) : ℝ) := by
apply sub_nonneg.mpr
rw [← stagePairingProduct_eq_exactWords_card counts labels depth complete t]
apply Real.log_le_log
· apply Nat.cast_pos.mpr
exact Finset.prod_pos (fun n _ => stageRefinementCount_pos counts labels n.val t)
· exact_mod_cast stagePairingProduct_le_budget counts labels depth t
theorem charged_cost_tendsto (counts : A → ℕ) (hD : 0 < ∑ a, counts a)
(labels : ∀ n, A → Label n) (depth : ℕ)
(complete : Function.Injective (labelRecordOf labels depth)) (C : ℝ) :
Tendsto (fun t => C +
(Real.log (stageAuxiliaryBudget counts labels depth t : ℝ) -
Real.log (Fintype.card (ExactWords (fun a => t * counts a)) : ℝ)) /
((t : ℝ) * (∑ a, counts a : ℕ))) atTop (𝓝 C) := by
simpa only [add_zero] using
(auxiliary_overhead_tendsto_zero counts hD labels depth complete).const_add C
theorem limit_le_source_cost (counts : A → ℕ) (hD : 0 < ∑ a, counts a)
(labels : ∀ n, A → Label n) (depth : ℕ)
(complete : Function.Injective (labelRecordOf labels depth))
{value : ℕ → ℝ} {rate C : ℝ}
(limit : Tendsto value atTop (𝓝 rate))
(finite_bound : ∀ᶠ t in atTop, value t ≤ C +
(Real.log (stageAuxiliaryBudget counts labels depth t : ℝ) -
Real.log (Fintype.card (ExactWords (fun a => t * counts a)) : ℝ)) /
((t : ℝ) * (∑ a, counts a : ℕ))) : rate ≤ C :=
le_of_tendsto_of_tendsto limit
(charged_cost_tendsto counts hD labels depth complete C) finite_bound
def lawPairingRate (p : FiniteLaw A) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair) (pair : ReaderPair) : ℝ :=
pairingRate (fun n : Fin depth =>
(FiniteLabelHierarchy.ofLawLabels p labels depth).refinementEntropy n.val) reader pair
theorem lawPairingRate_sum (p : FiniteLaw A) (labels : ∀ n, A → Label n)
(depth : ℕ) (reader : Fin depth → ReaderPair)
(complete : Function.Injective (labelRecordOf labels depth)) :
lawPairingRate p labels depth reader .xy +
lawPairingRate p labels depth reader .xz +
lawPairingRate p labels depth reader .yz = finiteEntropy p.mass := by
rw [lawPairingRate, lawPairingRate, lawPairingRate, pairingRate_sum,
Fin.sum_univ_eq_sum_range]
exact FiniteLabelHierarchy.ofLawLabels_refinementEntropy_sum p labels depth complete
theorem incident_rate_eq_prefix_entropy (p : FiniteLaw A)
(labels : ∀ n, A → Label n) (depth cut : ℕ) (hcut : cut ≤ depth)
(reader : Fin depth → ReaderPair)
(incident_prefix : ∀ n : Fin depth,
(reader n = .xy ∨ reader n = .xz) ↔ n.val < cut) :
lawPairingRate p labels depth reader .xy +
lawPairingRate p labels depth reader .xz =
finiteEntropy (p.map (labelRecordOf labels cut)).mass := by
let hierarchy := FiniteLabelHierarchy.ofLawLabels p labels depth
have hterms : ∀ n : Fin depth,
(if reader n = .xy then hierarchy.refinementEntropy n.val else 0) +
(if reader n = .xz then hierarchy.refinementEntropy n.val else 0) =
if n.val < cut then hierarchy.refinementEntropy n.val else 0 := by
intro n
cases hr : reader n with
| xy =>
have hn := (incident_prefix n).mp (Or.inl hr)
simp [hn]
| xz =>
have hn := (incident_prefix n).mp (Or.inr hr)
simp [hn]
| yz =>
have hn : ¬n.val < cut := by
intro h
rcases (incident_prefix n).mpr h with h | h <;> simp [hr] at h
simp [hn]
have hfilter : (Finset.range depth).filter (fun n => n < cut) = Finset.range cut := by
ext n
simp only [Finset.mem_filter, Finset.mem_range]
omega
calc
lawPairingRate p labels depth reader .xy +
lawPairingRate p labels depth reader .xz =
∑ n : Fin depth, if n.val < cut then hierarchy.refinementEntropy n.val else 0 := by
simp only [lawPairingRate, pairingRate, ← Finset.sum_add_distrib]
exact Finset.sum_congr rfl (fun n _ => hterms n)
_ = ∑ n ∈ Finset.range cut, hierarchy.refinementEntropy n := by
rw [show (∑ n : Fin depth, if n.val < cut then hierarchy.refinementEntropy n.val else 0) =
∑ n ∈ Finset.range depth, if n < cut then hierarchy.refinementEntropy n else 0 from
Fin.sum_univ_eq_sum_range
(fun n => if n < cut then hierarchy.refinementEntropy n else 0) depth]
rw [← Finset.sum_filter, hfilter]
_ = finiteEntropy (hierarchy.prefixLaw cut hcut).mass :=
(hierarchy.prefixLaw_entropy cut hcut).symm
_ = finiteEntropy (p.map (labelRecordOf labels cut)).mass := by
rw [FiniteLabelHierarchy.ofLawLabels_prefixLaw_mass]
theorem remaining_rate_eq_entropy_sub_prefix (p : FiniteLaw A)
(labels : ∀ n, A → Label n) (depth cut : ℕ) (hcut : cut ≤ depth)
(reader : Fin depth → ReaderPair)
(incident_prefix : ∀ n : Fin depth,
(reader n = .xy ∨ reader n = .xz) ↔ n.val < cut)
(complete : Function.Injective (labelRecordOf labels depth)) :
lawPairingRate p labels depth reader .yz = finiteEntropy p.mass -
finiteEntropy (p.map (labelRecordOf labels cut)).mass := by
have hsum := lawPairingRate_sum p labels depth reader complete
have hprefix := incident_rate_eq_prefix_entropy p labels depth cut hcut reader incident_prefix
linarith
end SourceHierarchy
end ConditionalLabels
end MatrixMultiplication
end
end OAI
|