File size: 15,261 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 286 287 288 289 290 291 292 293 294 295 296 297 | import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.GroupedEntropyPartition
import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.PairConditionalEntropy
import OAI.LinearAlgebra.MatrixMultiplication.FieldConstruction.ComplementSums
import Mathlib.Data.List.NodupEquivFin
namespace OAI
/-! Tensor extraction over arbitrary fields and its asymptotic rate. -/
noncomputable section
namespace MatrixMultiplication.AllFieldNativeGroupedRates
open MatrixMultiplication.Foundation AllFieldParameters AllFieldHistory
open JointNativeGroupedEntropy JointGroupedEntropyPartition
open AllFieldNativeCapacity AllFieldPairConditionalEntropy
open scoped BigOperators
attribute [local instance] Classical.propDecidable Classical.decEq
section Reindex
variable {U K A : Type*} [Fintype U] [Fintype K] [Fintype A]
omit [Fintype U] [Fintype K] in
theorem singletonResidualGroup_transport (e : U ≃ U) (c : K ≃ K)
(d : U → Prop) (weight : U → K)
(hw : ∀ u, c (weight u) = weight (e u)) :
(Equiv.sumCongr e c) ∘ singletonResidualGroup (d ∘ e) weight =
singletonResidualGroup d weight ∘ e := by
funext u
by_cases hu : d (e u) <;>
simp [singletonResidualGroup, Function.comp_apply, hu, hw]
theorem singletonResidual_groupedEntropy_reindex (e : U ≃ U) (c : K ≃ K)
(p : U → ℝ) (d : U → Prop) (weight : U → K) (q : U → A → ℝ)
(hp : ∀ u, p (e u) = p u) (hw : ∀ u, c (weight u) = weight (e u)) :
JointCompatibilityIncidence.groupedEntropy p
(singletonResidualGroup (d ∘ e) weight) (q ∘ e) =
JointCompatibilityIncidence.groupedEntropy p (singletonResidualGroup d weight) q := by
calc
_ = JointCompatibilityIncidence.groupedEntropy p
((Equiv.sumCongr e c) ∘ singletonResidualGroup (d ∘ e) weight) (q ∘ e) :=
(JointCompatibilityIncidence.groupedEntropy_relabel (Equiv.sumCongr e c) p _ _).symm
_ = JointCompatibilityIncidence.groupedEntropy p
(singletonResidualGroup d weight ∘ e) (q ∘ e) := by
rw [singletonResidualGroup_transport e c d weight hw]
_ = _ := JointCompatibilityIncidence.groupedEntropy_reindex e p _ q hp
theorem right_conditional_sum_eq (e : U ≃ U) (c : K ≃ K)
(p : FiniteLaw U) (d : U → Prop) (weight : U → K) (q : U → A → ℝ)
(hp : ∀ u, p.mass (e u) = p.mass u)
(hw : ∀ u, c (weight u) = weight (e u)) (hq : ∀ u, ∑ a, q u a = 1) :
(∑ k, (p.map weight).mass k *
JointCompatibilityIncidence.groupedEntropy (p.conditional weight k).mass
(JointCompatibilityIncidence.designatedGroup (d ∘ e)) (q ∘ e)) =
JointCompatibilityIncidence.groupedEntropy p.mass (singletonResidualGroup d weight) q := by
rw [← groupedEntropy_conditional_partition p (d ∘ e) weight (q ∘ e)
(fun u => hq (e u))]
exact singletonResidual_groupedEntropy_reindex e c p.mass d weight q hp hw
end Reindex
def supportSubtypeEquiv {α : Type*} (xs : List α) (f : α → α)
(hm : ∀ x ∈ xs, f x ∈ xs) (hi : ∀ x ∈ xs, f (f x) = x) :
Equiv.Perm {x // x ∈ xs} where
toFun x := ⟨f x.val, hm x.val x.property⟩
invFun x := ⟨f x.val, hm x.val x.property⟩
left_inv x := Subtype.ext (hi x.val x.property)
right_inv x := Subtype.ext (hi x.val x.property)
def supportIndexEquiv {α : Type*} [DecidableEq α] (xs : List α) (hn : xs.Nodup)
(f : α → α) (hm : ∀ x ∈ xs, f x ∈ xs) (hi : ∀ x ∈ xs, f (f x) = x) :
Equiv.Perm (Fin xs.length) :=
((hn.getEquiv xs).trans (supportSubtypeEquiv xs f hm hi)).trans (hn.getEquiv xs).symm
theorem supportIndexEquiv_get {α : Type*} [DecidableEq α] (xs : List α)
(hn : xs.Nodup) (f : α → α) (hm : ∀ x ∈ xs, f x ∈ xs)
(hi : ∀ x ∈ xs, f (f x) = x) (i : Fin xs.length) :
xs.get (supportIndexEquiv xs hn f hm hi i) = f (xs.get i) := by
exact congrArg Subtype.val ((hn.getEquiv xs).apply_symm_apply
((supportSubtypeEquiv xs f hm hi) ((hn.getEquiv xs) i)))
def boundedComplement (s : ℕ) (hs : s < 17) (k : Fin 17) : Fin 17 :=
⟨if k.val ≤ s then s - k.val else k.val, by
split_ifs
· exact lt_of_le_of_lt (Nat.sub_le _ _) hs
· exact k.isLt⟩
theorem boundedComplement_involutive (s : ℕ) (hs : s < 17) :
Function.Involutive (boundedComplement s hs) := by
intro k
apply Fin.ext
dsimp only [boundedComplement]
split_ifs <;> omega
def boundedComplementEquiv (s : ℕ) (hs : s < 17) : Equiv.Perm (Fin 17) where
toFun := boundedComplement s hs
invFun := boundedComplement s hs
left_inv := boundedComplement_involutive s hs
right_inv := boundedComplement_involutive s hs
section NativeSupport
variable {A : Type*} [Fintype A]
theorem native_right_conditional_sum_eq (support : List Shape) (s : Shape)
(p : Shape → ℝ) (priority : Placement) (position : Fin 3) (q : Shape → A → ℝ)
(hn : support.Nodup) (hm : ∀ u ∈ support, complement s u ∈ support)
(hsupp : ∀ u ∈ support, ∀ side, u side ≤ s side)
(hs : s (priority position) < 17)
(hbound : ∀ i : SupportIndex support, support[i.val] (priority position) < 17)
(law : FiniteLaw (SupportIndex support))
(hlaw : ∀ i : SupportIndex support, law.mass i = p support[i.val])
(hp : ∀ u ∈ support, p (complement s u) = p u)
(hq : ∀ i : SupportIndex support, ∑ a, q support[i.val] a = 1) :
(∑ k : Fin 17, (law.map (ownWeight support priority position hbound)).mass k *
JointCompatibilityIncidence.groupedEntropy
(law.conditional (ownWeight support priority position hbound) k).mass
(JointCompatibilityIncidence.designatedGroup (fun i =>
AllFieldNativeCapacity.designated priority position (complement s support[i.val])))
(fun i => q (complement s support[i.val]))) =
AllFieldNativeCapacity.groupedEntropy support p priority position q := by
let hi : ∀ u ∈ support, complement s (complement s u) = u :=
fun u hu => complement_involution_of_le s u (hsupp u hu)
let e := supportIndexEquiv support hn (complement s) hm hi
let c := boundedComplementEquiv (s (priority position)) hs
let weight := ownWeight support priority position hbound
let d : SupportIndex support → Prop :=
fun i => AllFieldNativeCapacity.designated priority position support[i.val]
let q₀ : SupportIndex support → A → ℝ := fun i => q support[i.val]
have he (i : SupportIndex support) :
support[(e i).val] = complement s support[i.val] := by
simpa only [List.get_eq_getElem] using
supportIndexEquiv_get support hn (complement s) hm hi i
have hmass (i : SupportIndex support) : law.mass (e i) = law.mass i := by
simp only [hlaw, he]
exact hp _ (List.getElem_mem i.isLt)
have hw (i : SupportIndex support) : c (weight i) = weight (e i) := by
apply Fin.ext
change (if support[i.val] (priority position) ≤ s (priority position)
then s (priority position) - support[i.val] (priority position)
else support[i.val] (priority position)) = support[(e i).val] (priority position)
rw [ite_eq_left (hsupp _ (List.getElem_mem i.isLt) _), he]
rfl
have hright := right_conditional_sum_eq e c law d weight q₀ hmass hw hq
have hd : d ∘ e = fun i =>
AllFieldNativeCapacity.designated priority position (complement s support[i.val]) := by
funext i
dsimp only [d, Function.comp_apply]
rw [he]
have hqr : q₀ ∘ e = fun i => q (complement s support[i.val]) := by
funext i
dsimp only [q₀, Function.comp_apply]
rw [he]
rw [hd, hqr] at hright
have hnonneg (i : SupportIndex support) : 0 ≤ p support[i.val] := by
rw [← hlaw i]
exact law.nonneg i
have hmassfun : law.mass = fun i : SupportIndex support => p support[i.val] := funext hlaw
calc
_ = JointCompatibilityIncidence.groupedEntropy law.mass
(nativeGroup support priority position hbound) (fun i => q support[i.val]) := by
simpa only [d, q₀, weight, nativeGroup] using hright
_ = _ := by
rw [hmassfun]
exact groupedEntropy_eq_native support p priority position q hbound hnonneg hq
theorem native_two_conditional_sums_eq (support : List Shape) (s : Shape)
(p : Shape → ℝ) (priority : Placement) (position : Fin 3) (q : Shape → A → ℝ)
(hn : support.Nodup) (hm : ∀ u ∈ support, complement s u ∈ support)
(hsupp : ∀ u ∈ support, ∀ side, u side ≤ s side)
(hs : s (priority position) < 17)
(hbound : ∀ i : SupportIndex support, support[i.val] (priority position) < 17)
(law : FiniteLaw (SupportIndex support))
(hlaw : ∀ i : SupportIndex support, law.mass i = p support[i.val])
(hp : ∀ u ∈ support, p (complement s u) = p u)
(hq : ∀ i : SupportIndex support, ∑ a, q support[i.val] a = 1) :
(∑ k : Fin 17, (law.map (ownWeight support priority position hbound)).mass k *
(JointCompatibilityIncidence.groupedEntropy
(law.conditional (ownWeight support priority position hbound) k).mass
(JointCompatibilityIncidence.designatedGroup (fun i =>
AllFieldNativeCapacity.designated priority position support[i.val]))
(fun i => q support[i.val]) +
JointCompatibilityIncidence.groupedEntropy
(law.conditional (ownWeight support priority position hbound) k).mass
(JointCompatibilityIncidence.designatedGroup (fun i =>
AllFieldNativeCapacity.designated priority position (complement s support[i.val])))
(fun i => q (complement s support[i.val])))) =
2 * AllFieldNativeCapacity.groupedEntropy support p priority position q := by
simp only [mul_add, Finset.sum_add_distrib]
rw [← native_groupedEntropy_eq_sum_conditional support p priority position q hbound law hlaw hq,
native_right_conditional_sum_eq support s p priority position q hn hm hsupp hs
hbound law hlaw hp hq]
ring
end NativeSupport
def twoHalfConditionalCost {A : Type*} [Fintype A]
(support : List Shape) (s : Shape) (priority : Placement) (position : Fin 3)
(q : Shape → A → ℝ) (law : FiniteLaw (SupportIndex support))
(weight : SupportIndex support → Fin 17) : ℝ :=
∑ k : Fin 17, (law.map weight).mass k *
(JointCompatibilityIncidence.groupedEntropy (law.conditional weight k).mass
(JointCompatibilityIncidence.designatedGroup (fun i =>
AllFieldNativeCapacity.designated priority position support[i.val]))
(fun i => q support[i.val]) +
JointCompatibilityIncidence.groupedEntropy (law.conditional weight k).mass
(JointCompatibilityIncidence.designatedGroup (fun i =>
AllFieldNativeCapacity.designated priority position (complement s support[i.val])))
(fun i => q (complement s support[i.val])))
theorem stageA_twoHalfConditionalCost_eq (g : Shape) (hg : g ∈ positiveInitial)
(priority : Placement) (position : Fin 3) :
twoHalfConditionalCost (below g) g priority position
(fun u a => (halfLaw u (priority position) a : ℝ)) (stageASplitLaw g hg)
(stageASplitWeight g hg (priority position)) =
2 * AllFieldNativeCapacity.groupedEntropy (below g)
(fun u => (stageALaw g u : ℝ)) priority position
(fun u a => (halfLaw u (priority position) a : ℝ)) := by
have hs : g (priority position) < 17 :=
Nat.lt_succ_of_le ((positiveInitial_shape_spec g hg).1 (priority position))
let hb : ∀ i : SupportIndex (below g), (below g)[i.val] (priority position) < 17 :=
fun i => lt_of_le_of_lt (below_le (List.getElem_mem i.isLt) _) hs
have hq (i : SupportIndex (below g)) :
∑ a, (halfLaw (below g)[i.val] (priority position) a : ℝ) = 1 :=
(halfFiniteLaw _ (stageA_children_size g hg _ (List.getElem_mem i.isLt))
(priority position)).total
have hh := native_two_conditional_sums_eq (below g) g
(fun u => (stageALaw g u : ℝ)) priority position
(fun u a => (halfLaw u (priority position) a : ℝ))
(stageA_below_nodup g hg) (fun u hu => (stageA_support_complement g hg u hu).1)
(fun _ hu => below_le hu) hs hb (stageASplitLaw g hg) (fun _ => rfl)
(fun u hu => by rw [stageALaw_complement g u hg hu]) hq
have hw : ownWeight (below g) priority position hb =
stageASplitWeight g hg (priority position) := by
funext i
apply Fin.ext
simp only [ownWeight, stageASplitWeight, List.get_eq_getElem]
rw [hw] at hh
simpa only [twoHalfConditionalCost] using hh
theorem stageB_twoHalfConditionalCost_eq (t : Shape) (ht : t ∈ positiveSecond)
(priority : Placement) (position : Fin 3) :
twoHalfConditionalCost (below t) t priority position
(fun u a => (littleLaw t u (priority position) a : ℝ)) (stageBSplitLaw t ht)
(stageBSplitWeight t ht (priority position)) =
2 * AllFieldNativeCapacity.groupedEntropy (below t)
(fun u => (stageBLaw t u : ℝ)) priority position
(fun u a => (littleLaw t u (priority position) a : ℝ)) := by
have hs : t (priority position) < 17 :=
Nat.lt_succ_of_le ((positiveSecond_shape_spec t ht).1 (priority position))
let hb : ∀ i : SupportIndex (below t), (below t)[i.val] (priority position) < 17 :=
fun i => lt_of_le_of_lt (below_le (List.getElem_mem i.isLt) _) hs
have hq (i : SupportIndex (below t)) :
∑ a, (littleLaw t (below t)[i.val] (priority position) a : ℝ) = 1 :=
(littleFiniteLaw t _ (priority position)).total
have hh := native_two_conditional_sums_eq (below t) t
(fun u => (stageBLaw t u : ℝ)) priority position
(fun u a => (littleLaw t u (priority position) a : ℝ))
(stageB_below_nodup t ht) (fun u hu => (stageB_support_complement t ht u hu).1)
(fun _ hu => below_le hu) hs hb (stageBSplitLaw t ht) (fun _ => rfl)
(fun u hu => by rw [stageBLaw_complement t u ht hu]) hq
have hw : ownWeight (below t) priority position hb =
stageBSplitWeight t ht (priority position) := by
funext i
apply Fin.ext
simp only [ownWeight, stageBSplitWeight, List.get_eq_getElem]
rw [hw] at hh
simpa only [twoHalfConditionalCost] using hh
theorem stageA_twoHalfConditionalCost_eq_entropy_sub_capacity
(g : Shape) (hg : g ∈ positiveInitial) (side : Fin 3) (hside : side ≠ 0) :
twoHalfConditionalCost (below g) g (Equiv.refl (Fin 3)) side
(fun u a => (halfLaw u side a : ℝ)) (stageASplitLaw g hg)
(stageASplitWeight g hg side) =
finiteEntropy (stageAPairLaw g hg side).mass - stageACapacity g side := by
rw [stageACapacity_sharing g hg side hside]
have hh := stageA_twoHalfConditionalCost_eq g hg (Equiv.refl (Fin 3)) side
simpa only [Equiv.refl_apply, sub_sub_cancel] using hh
theorem stageB_twoHalfConditionalCost_eq_entropy_sub_capacity
(t : Shape) (ht : t ∈ positiveSecond) (side : Fin 3) (hside : side ≠ 0) :
twoHalfConditionalCost (below t) t (stageBPriority t) side
(fun u a => (littleLaw t u (stageBPriority t side) a : ℝ)) (stageBSplitLaw t ht)
(stageBSplitWeight t ht (stageBPriority t side)) =
finiteEntropy (stageBPairLaw t ht (stageBPriority t side)).mass -
stageBCapacity t side := by
rw [stageBCapacity_sharing t ht side hside]
have hh := stageB_twoHalfConditionalCost_eq t ht (stageBPriority t) side
simpa only [sub_sub_cancel] using hh
end MatrixMultiplication.AllFieldNativeGroupedRates
end
end OAI
|