@@ -5,7 +5,6 @@ Authors: Rémy Degenne
55-/
66module
77
8- public import LeanMachineLearning.SequentialLearning.Algorithms.AuxSums
98public import LeanMachineLearning.SequentialLearning.Deterministic
109public import LeanMachineLearning.SequentialLearning.FiniteActions
1110public import LeanMachineLearning.SequentialLearning.StationaryEnv
@@ -27,7 +26,48 @@ he action `n % K`.
2726open MeasureTheory ProbabilityTheory Finset Learning
2827open scoped ENNReal NNReal
2928
30- namespace Bandits
29+ section Aux
30+
31+ lemma sum_mod_range {K : ℕ} (hK : 0 < K) (a : Fin K) :
32+ (∑ s ∈ range K, if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) = 1 := by
33+ have h_iff (s : ℕ) (hs : s < K) : ⟨s % K, Nat.mod_lt _ hK⟩ = a ↔ s = a := by
34+ simp only [Nat.mod_eq_of_lt hs, Fin.ext_iff]
35+ calc (∑ s ∈ range K, if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 )
36+ _ = ∑ s ∈ range K, if s = a then 1 else 0 := sum_congr rfl fun s hs ↦ by grind
37+ _ = _ := by
38+ rw [sum_ite_eq']
39+ simp
40+
41+ lemma sum_mod_range_mul {K : ℕ} (hK : 0 < K) (m : ℕ) (a : Fin K) :
42+ (∑ s ∈ range (K * m), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) = m := by
43+ induction m with
44+ | zero => simp
45+ | succ n hn =>
46+ calc (∑ s ∈ range (K * (n + 1 )), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 )
47+ _ = (∑ s ∈ range (K * n + K), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) := by ring_nf
48+ _ = (∑ s ∈ range (K * n), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 )
49+ + (∑ s ∈ Ico (K * n) (K * n + K), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) := by
50+ rw [sum_range_add_sum_Ico]
51+ grind
52+ _ = n + (∑ s ∈ Ico (K * n) (K * n + K), if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) := by
53+ rw [hn]
54+ _ = n + (∑ s ∈ range K, if ⟨(s + K * n) % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) := by
55+ congr 1
56+ let e : ℕ ↪ ℕ := ⟨fun i : ℕ ↦ i + K * n, fun i j hij ↦ by grind⟩
57+ have : Finset.map e (range K) = Ico (K * n) (K * n + K) := by
58+ ext x
59+ simp only [mem_map, mem_range, Function.Embedding.coeFn_mk, mem_Ico, e]
60+ refine ⟨fun h ↦ by grind, fun h ↦ ?_⟩
61+ use x - K * n
62+ grind
63+ rw [← this, Finset.sum_map]
64+ congr
65+ _ = n + (∑ s ∈ range K, if ⟨s % K, Nat.mod_lt _ hK⟩ = a then 1 else 0 ) := by simp
66+ _ = n + 1 := by rw [sum_mod_range hK]
67+
68+ end Aux
69+
70+ namespace Learning
3171
3272variable {K : ℕ}
3373
@@ -123,4 +163,4 @@ lemma pullCount_pos_of_pullCount_gt_one [Nonempty (Fin K)]
123163
124164end RoundRobin
125165
126- end Bandits
166+ end Learning
0 commit comments