noncomputabledefcounts {α : Type uα} {β : Type uβ} [Fintype α] [Fintype β] {k : ℕ}
(w : Fin k → β → α) : β → α →Fin (k+1) :=by
body · 3
lines
classical
exact fun j a => ⟨(Finset.univ.filter (fun t => w t j=a)).card,
Nat.lt_succ_of_le ((Finset.card_le_card (Finset.filter_subset _ _)).trans_eq (Fintype.card_fin k))⟩
theoremcounts_expand {α : Type uα} {β : Type uβ} [Fintype α] [Fintype β] {k : ℕ}
(v : β → α →ℝ) (w : Fin k → β → α) :
∑ t, ∑ j, v j (w t j) = ∑ j, ∑ a, ((counts w j a).val : ℝ)*v j a :=by
proof · 14
lines
classical
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro j _
rw [←Finset.sum_fiberwise Finset.univ (funt : Fin k => w t j)]
apply Finset.sum_congr rfl
intro a _
calc∑ t ∈Finset.univ.filter (funt : Fin k => w t j=a), v j (w t j) =
∑ _t ∈Finset.univ.filter (funt : Fin k => w t j=a), v j a :=by
apply Finset.sum_congr rfl
intro t ht
rw [(Finset.mem_filter.mp ht).2]
_ = _ :=by simp [counts]