1import Mathlib.Tactic
2import Mathlib.Analysis.SpecificLimits.Basic
3import Mathlib.Data.Fintype.Option
4import Mathlib.Algebra.BigOperators.Ring.Finset
5
6/-!
7# Naive reuse is a running maximum (multigen note, Proposition 1; signal note L5)
8
9Source: `paper/evaluation_feedback_multigen.md`, draft 0.5, §1–§2; code
10`src/spiral_ln/evaluation_feedback_multigen.py` (`transition_kernel`, `naive_closed_form`,
11`ceiling_mass_closed_form`).
12
13**The chain (§1).** The state is the incumbent's realized count `c` on a reused set of `n` items.
14Each generation draws `K` candidates; `M` is the best candidate count. The policy accepts iff
15`M > c + t(c)` for a threshold rule `t : ℕ → ℕ`; on acceptance the state becomes `M`. The naive rule
16is `t ≡ 0`.
17
18**Proposition 1.** With `t ≡ 0`, `c_G = max(c_0, M_1, …, M_G)`, the maximum of the `G K + 1` draws
19(the initial incumbent is one draw). Consequences: (i) `ρ_G` is non-decreasing in `G`; (ii) the
20increments `a_{m+1} - a_m` of `a_m = E[max of m draws]` are non-increasing; (iii)
21`P(c_G = n) = 1 - (1 - p^n)^{G K + 1}`, so for `0 < p` the gap `ρ_G` increases to `1 - p`.
22
23What is formalized here:
24* `chain_naive`, `naive_reported_eq_max`: the deterministic statement about the update rule.
25* `prob_reported_le`, `expect_reported`: the distributional consequence for `G K + 1` i.i.d. draws
26 from an arbitrary law `w` on `{0, …, n}` (in particular `Bin(n, p)`): the reported count has CDF
27 `F(j)^{G K + 1}` and mean `∑_{j<n} (1 - F(j)^{G K + 1})`, which is the mean of the maximum of
28 `G K + 1` i.i.d. draws (`expect_max`).
29* Consequences (i)–(iii): `aSeq_mono`, `aSeq_increment_antitone`, `expect_reported_mono`,
30 `expect_reported_increment_antitone`, `prob_reported_eq_top`, `binomial_prob_reported_eq_top`,
31 `tendsto_gap`.
32* Proposition 4 (gate dominance under the null, coupling form): `chain_le_chain_naive`.
33
34Probabilities are finite sums over draw configurations `D : ι → Fin (n + 1)` weighted by
35`∏ i, w (D i)`, i.e. expectations under the product law of i.i.d. draws.
36-/
37
38namespace FeedbackChannel.MultigenRunningMax
39
40open Finset Filter Topology
41
42/-! ## The update rule -/
43
44/-- One generation of the threshold policy: from incumbent count `c`, with `M` the best candidate
45count of the generation, accept iff `M > c + t c`; the next state is `M` on acceptance and `c`
46otherwise. -/
47def step (t : ℕ → ℕ) (c M : ℕ) : ℕ := if c + t c < M then M else c
48
49/-- The incumbent count after `g` generations from initial count `c0`, where `best g` is the best
50candidate count of the `(g + 1)`-th generation. -/
51def chain (t : ℕ → ℕ) (c0 : ℕ) (best : ℕ → ℕ) : ℕ → ℕ
52 | 0 => c0
53 | g + 1 => step t (chain t c0 best g) (best g)
54
55/-- The naive rule `t ≡ 0`: accept whenever the best candidate beats the incumbent. -/
56def naive : ℕ → ℕ := fun _ => 0
57
58theorem step_naive (c M : ℕ) : step naive c M = max c M := by
59 unfold step naive
60 split_ifs with h
61 · exact (max_eq_right (by omega)).symm
62 · exact (max_eq_left (by omega)).symm
63
64/-- **Proposition 1, deterministic form.** Under the naive rule the incumbent after `G` generations
65is the running maximum `max(c_0, M_1, …, M_G)`. -/
66theorem chain_naive (c0 : ℕ) (best : ℕ → ℕ) (G : ℕ) :
67 chain naive c0 best G = max c0 ((range G).sup best) := by
68 induction G with
69 | zero => simp [chain]
70 | succ G ih =>
71 rw [chain, ih, step_naive, range_add_one, sup_insert]
72 rw [max_assoc, max_comm ((range G).sup best) (best G)]
73
74/-- **Proposition 4 (null, coupling form).** On the same draws, the chain under any threshold rule
75stays below the naive chain: `c^t_G ≤ c^0_G` pointwise. -/
76theorem chain_le_chain_naive (t : ℕ → ℕ) (c0 : ℕ) (best : ℕ → ℕ) (G : ℕ) :
77 chain t c0 best G ≤ chain naive c0 best G := by
78 induction G with
79 | zero => simp [chain]
80 | succ G ih =>
81 rw [chain, chain, step_naive]
82 unfold step
83 split_ifs
84 · exact le_max_right _ _
85 · exact le_trans ih (le_max_left _ _)
86
87/-! ## `K` candidates per generation: the `G K + 1` draws -/
88
89/-- Index set of the draws of `G` generations of `K` candidates: `none` is the initial incumbent
90(scored on the reused set like every candidate), `some (g, k)` is candidate `k` of generation `g`. -/
91abbrev Draw (G K : ℕ) := Option (Fin G × Fin K)
92
93theorem card_draw (G K : ℕ) : Fintype.card (Draw G K) = G * K + 1 := by
94 simp
95
96/-- The best candidate count of generation `g` (zero for `g ≥ G`, never used). -/
97def bestOf {G K : ℕ} (D : Draw G K → ℕ) (g : ℕ) : ℕ :=
98 if h : g < G then univ.sup fun k : Fin K => D (some (⟨g, h⟩, k)) else 0
99
100/-- **Proposition 1.** With `t ≡ 0` and `K` candidates per generation, the reported count after `G`
101generations is the maximum of all `G K + 1` draws (initial incumbent and every candidate). -/
102theorem naive_reported_eq_max {G K : ℕ} (D : Draw G K → ℕ) :
103 chain naive (D none) (bestOf D) G = univ.sup D := by
104 rw [chain_naive]
105 apply le_antisymm
106 · apply max_le
107 · exact le_sup (f := D) (mem_univ none)
108 · apply Finset.sup_le
109 intro g hg
110 rw [mem_range] at hg
111 simp only [bestOf, dite_eq_left hg]
112 apply Finset.sup_le
113 intro k _
114 exact le_sup (f := D) (mem_univ _)
115 · apply Finset.sup_le
116 rintro (_ | ⟨g, k⟩) _
117 · exact le_max_left _ _
118 · apply le_max_of_le_right
119 calc D (some (g, k)) ≤ bestOf D g := by
120 simp only [bestOf, dite_eq_left g.isLt]
121 exact le_sup (f := fun k : Fin K => D (some (⟨g.val, g.isLt⟩, k))) (mem_univ k)
122 _ ≤ (range G).sup (bestOf D) := le_sup (mem_range.mpr g.isLt)
123
124/-! ## The law of the reported count -/
125
126section Law
127
128variable {n : ℕ} (w : Fin (n + 1) → ℝ)
129
130/-- CDF `F(j) = P(X ≤ j)` of one draw with law `w` on counts `{0, …, n}`. -/
131def cdf (j : ℕ) : ℝ := ∑ x : Fin (n + 1), if x.val ≤ j then w x else 0
132
133/-- Probability of an event of i.i.d. draws `D : ι → Fin (n + 1)`, each with law `w`. -/
134def prob {ι : Type*} [Fintype ι] [DecidableEq ι] (E : (ι → Fin (n + 1)) → Prop)
135 [DecidablePred E] : ℝ :=
136 ∑ D : ι → Fin (n + 1), (∏ i, w (D i)) * if E D then 1 else 0
137
138/-- Expectation of `f` under i.i.d. draws `D : ι → Fin (n + 1)`, each with law `w`. -/
139def expect {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → Fin (n + 1)) → ℝ) : ℝ :=
140 ∑ D : ι → Fin (n + 1), (∏ i, w (D i)) * f D
141
142/-- The maximum count among the draws. -/
143def maxDraw {ι : Type*} [Fintype ι] (D : ι → Fin (n + 1)) : ℕ := univ.sup fun i => (D i).val
144
145theorem maxDraw_le {ι : Type*} [Fintype ι] (D : ι → Fin (n + 1)) : maxDraw D ≤ n :=
146 Finset.sup_le fun i _ => Nat.lt_succ_iff.mp (D i).isLt
147
148theorem maxDraw_le_iff {ι : Type*} [Fintype ι] (D : ι → Fin (n + 1)) (j : ℕ) :
149 maxDraw D ≤ j ↔ ∀ i, (D i).val ≤ j := by
150 simp [maxDraw, Finset.sup_le_iff]
151
152theorem total_mass {ι : Type*} [Fintype ι] [DecidableEq ι] (hw : ∑ x, w x = 1) :
153 ∑ D : ι → Fin (n + 1), ∏ i, w (D i) = 1 := by
154 have h := Finset.prod_univ_sum (fun _ : ι => (univ : Finset (Fin (n + 1)))) (fun _ x => w x)
155 rw [Fintype.piFinset_univ] at h
156 rw [← h]
157 simp [hw]
158
159/-- The maximum of i.i.d. draws: `P(max ≤ j) = F(j)^{|ι|}`. -/
160theorem prob_all_le {ι : Type*} [Fintype ι] [DecidableEq ι] (j : ℕ) :
161 prob w (fun D : ι → Fin (n + 1) => ∀ i, (D i).val ≤ j) = cdf w j ^ Fintype.card ι := by
162 unfold prob cdf
163 rw [← Finset.card_univ, ← Finset.prod_const, Finset.prod_univ_sum, Fintype.piFinset_univ]
164 apply Finset.sum_congr rfl
165 intro D _
166 by_cases h : ∀ i, (D i).val ≤ j
167 · rw [ite_eq_left h, mul_one]
168 exact Finset.prod_congr rfl fun i _ => (ite_eq_left (h i)).symm
169 · rw [ite_eq_right h, mul_zero]
170 obtain ⟨i, hi⟩ := not_forall.mp h
171 exact (Finset.prod_eq_zero (mem_univ i) (ite_eq_right hi)).symm
172
173theorem prob_not {ι : Type*} [Fintype ι] [DecidableEq ι] (hw : ∑ x, w x = 1)
174 (E : (ι → Fin (n + 1)) → Prop) [DecidablePred E] :
175 prob w (fun D => ¬ E D) = 1 - prob w E := by
176 unfold prob
177 have ht := total_mass w hw (ι := ι)
178 rw [eq_sub_iff_add_eq, ← Finset.sum_add_distrib]
179 conv_rhs => rw [← ht]
180 apply Finset.sum_congr rfl
181 intro D _
182 by_cases h : E D <;> simp [h]
183
184theorem tail_sum (x n : ℕ) (hx : x ≤ n) :
185 (∑ j ∈ range n, if x ≤ j then (0 : ℝ) else 1) = x := by
186 rw [← Finset.sum_range_add_sum_Ico _ hx]
187 have h1 : (∑ j ∈ range x, if x ≤ j then (0 : ℝ) else 1) = ∑ j ∈ range x, (1 : ℝ) :=
188 Finset.sum_congr rfl fun j hj => ite_eq_right (by rw [mem_range] at hj; omega)
189 have h2 : (∑ j ∈ Ico x n, if x ≤ j then (0 : ℝ) else 1) = ∑ j ∈ Ico x n, (0 : ℝ) :=
190 Finset.sum_congr rfl fun j hj => ite_eq_left (mem_Ico.mp hj).1
191 rw [h1, h2]
192 simp
193
194/-- `a_m`: the tail-sum form of the mean of the maximum of `m` i.i.d. draws. -/
195def aSeq (m : ℕ) : ℝ := ∑ j ∈ range n, (1 - cdf w j ^ m)
196
197/-- The mean of the maximum of i.i.d. draws indexed by `ι` is `a_{|ι|}`. -/
198theorem expect_max {ι : Type*} [Fintype ι] [DecidableEq ι] (hw : ∑ x, w x = 1) :
199 expect w (fun D : ι → Fin (n + 1) => (maxDraw D : ℝ)) = aSeq w (Fintype.card ι) := by
200 unfold expect aSeq
201 have key : ∀ D : ι → Fin (n + 1), (maxDraw D : ℝ) =
202 ∑ j ∈ range n, if (∀ i, (D i).val ≤ j) then (0 : ℝ) else 1 := by
203 intro D
204 rw [← tail_sum (maxDraw D) n (maxDraw_le D)]
205 apply Finset.sum_congr rfl
206 intro j _
207 simp only [maxDraw_le_iff]
208 simp_rw [key, Finset.mul_sum]
209 rw [Finset.sum_comm]
210 apply Finset.sum_congr rfl
211 intro j _
212 rw [← prob_all_le w j (ι := ι), ← prob_not w hw]
213 unfold prob
214 apply Finset.sum_congr rfl
215 intro D _
216 by_cases h : ∀ i, (D i).val ≤ j <;> simp [h]
217
218/-- The reported count under naive reuse, as a function of the `G K + 1` draws. -/
219def reported {G K : ℕ} (D : Draw G K → Fin (n + 1)) : ℕ :=
220 chain naive (D none).val (bestOf fun i => (D i).val) G
221
222theorem reported_eq_maxDraw {G K : ℕ} (D : Draw G K → Fin (n + 1)) :
223 reported D = maxDraw D :=
224 naive_reported_eq_max (fun i => (D i).val)
225
226/-- **Proposition 1, law.** Under naive reuse with i.i.d. draws of law `w`, the reported count after
227`G` generations of `K` candidates has CDF `F(j)^{G K + 1}`: it is distributed as the maximum of
228`G K + 1` i.i.d. draws. -/
229theorem prob_reported_le (G K j : ℕ) :
230 prob w (fun D : Draw G K → Fin (n + 1) => reported D ≤ j) = cdf w j ^ (G * K + 1) := by
231 rw [← card_draw G K, ← prob_all_le w j]
232 unfold prob
233 apply Finset.sum_congr rfl
234 intro D _
235 simp only [reported_eq_maxDraw, maxDraw_le_iff]
236
237/-- **Proposition 1, mean.** `E[c_G] = a_{G K + 1}`, the mean of the maximum of `G K + 1` i.i.d.
238draws (`expect_max` with `ι = Fin (G K + 1)`); so `ρ_G = E[c_G]/n - p` is the one-generation
239selection gap with `K` replaced by `G K + 1`. -/
240theorem expect_reported (hw : ∑ x, w x = 1) (G K : ℕ) :
241 expect w (fun D : Draw G K → Fin (n + 1) => (reported D : ℝ)) = aSeq w (G * K + 1) := by
242 rw [← card_draw G K, ← expect_max w hw]
243 unfold expect
244 apply Finset.sum_congr rfl
245 intro D _
246 simp only [reported_eq_maxDraw]
247
248theorem expect_reported_eq_expect_max (hw : ∑ x, w x = 1) (G K : ℕ) :
249 expect w (fun D : Draw G K → Fin (n + 1) => (reported D : ℝ)) =
250 expect w (fun D : Fin (G * K + 1) → Fin (n + 1) => (maxDraw D : ℝ)) := by
251 rw [expect_reported w hw, expect_max w hw, Fintype.card_fin]
252
253/-! ### Consequences (i)–(ii) -/
254
255variable {w}
256
257theorem cdf_nonneg (hw0 : ∀ x, 0 ≤ w x) (j : ℕ) : 0 ≤ cdf w j :=
258 Finset.sum_nonneg fun x _ => by split_ifs <;> simp [hw0 x]
259
260theorem cdf_le_one (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (j : ℕ) : cdf w j ≤ 1 := by
261 rw [← hw]
262 exact Finset.sum_le_sum fun x _ => by split_ifs <;> simp [hw0 x]
263
264/-- (ii) The increment of `a_m` is `∑_j F(j)^m (1 - F(j)) = E[(X - M_m)^+]` in tail-sum form. -/
265theorem aSeq_succ_sub (m : ℕ) :
266 aSeq w (m + 1) - aSeq w m = ∑ j ∈ range n, cdf w j ^ m * (1 - cdf w j) := by
267 unfold aSeq
268 rw [← Finset.sum_sub_distrib]
269 apply Finset.sum_congr rfl
270 intro j _
271 ring
272
273/-- (i) `a_m` is non-decreasing in the number of draws. -/
274theorem aSeq_mono (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (m : ℕ) :
275 aSeq w m ≤ aSeq w (m + 1) := by
276 have := aSeq_succ_sub (w := w) m
277 have h : 0 ≤ ∑ j ∈ range n, cdf w j ^ m * (1 - cdf w j) :=
278 Finset.sum_nonneg fun j _ =>
279 mul_nonneg (pow_nonneg (cdf_nonneg hw0 j) _) (by linarith [cdf_le_one hw0 hw j])
280 linarith
281
282/-- (ii) The increments of `a_m` are non-increasing. -/
283theorem aSeq_increment_antitone (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (m : ℕ) :
284 aSeq w (m + 2) - aSeq w (m + 1) ≤ aSeq w (m + 1) - aSeq w m := by
285 rw [aSeq_succ_sub, aSeq_succ_sub]
286 apply Finset.sum_le_sum
287 intro j _
288 have h0 := cdf_nonneg hw0 j
289 have h1 := cdf_le_one hw0 hw j
290 apply mul_le_mul_of_nonneg_right _ (by linarith)
291 exact pow_le_pow_of_le_one h0 h1 (Nat.le_succ m)
292
293theorem aSeq_mono' (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) {m m' : ℕ} (h : m ≤ m') :
294 aSeq w m ≤ aSeq w m' := by
295 induction h with
296 | refl => exact le_rfl
297 | step _ ih => exact ih.trans (aSeq_mono hw0 hw _)
298
299/-- Concavity of `a` transfers to blocks of `K` draws. -/
300theorem aSeq_block_antitone (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (m K : ℕ) :
301 aSeq w (m + 2 * K) - aSeq w (m + K) ≤ aSeq w (m + K) - aSeq w m := by
302 have tele : ∀ a : ℕ, aSeq w (a + K) - aSeq w a =
303 ∑ r ∈ range K, (aSeq w (a + (r + 1)) - aSeq w (a + r)) := by
304 intro a
305 rw [Finset.sum_range_sub (fun r => aSeq w (a + r))]
306 simp
307 have anti : ∀ a b : ℕ, a ≤ b →
308 aSeq w (b + 1) - aSeq w b ≤ aSeq w (a + 1) - aSeq w a := by
309 intro a b hab
310 induction hab with
311 | refl => exact le_rfl
312 | step _ ih =>
313 exact (aSeq_increment_antitone hw0 hw _).trans ih
314 rw [show m + 2 * K = (m + K) + K by ring, tele (m + K), tele m]
315 apply Finset.sum_le_sum
316 intro r _
317 have := anti (m + r) (m + K + r) (by omega)
318 simpa [add_assoc, add_comm, add_left_comm] using this
319
320/-- (i) for the chain: `E[c_G]` (hence `ρ_G = E[c_G]/n - p`) is non-decreasing in `G`. -/
321theorem expect_reported_mono (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (G K : ℕ) :
322 expect w (fun D : Draw G K → Fin (n + 1) => (reported D : ℝ)) ≤
323 expect w (fun D : Draw (G + 1) K → Fin (n + 1) => (reported D : ℝ)) := by
324 rw [expect_reported w hw, expect_reported w hw]
325 exact aSeq_mono' hw0 hw (by nlinarith)
326
327/-- (ii) for the chain: the per-generation increments of `E[c_G]` are non-increasing in `G`. -/
328theorem expect_reported_increment_antitone (hw0 : ∀ x, 0 ≤ w x) (hw : ∑ x, w x = 1) (G K : ℕ) :
329 expect w (fun D : Draw (G + 2) K → Fin (n + 1) => (reported D : ℝ)) -
330 expect w (fun D : Draw (G + 1) K → Fin (n + 1) => (reported D : ℝ)) ≤
331 expect w (fun D : Draw (G + 1) K → Fin (n + 1) => (reported D : ℝ)) -
332 expect w (fun D : Draw G K → Fin (n + 1) => (reported D : ℝ)) := by
333 rw [expect_reported w hw, expect_reported w hw, expect_reported w hw]
334 have := aSeq_block_antitone hw0 hw (G * K + 1) K
335 rw [show (G + 2) * K + 1 = G * K + 1 + 2 * K by ring,
336 show (G + 1) * K + 1 = G * K + 1 + K by ring]
337 exact this
338
339/-! ### Consequence (iii): the ceiling and the limit -/
340
341variable (w) in
342/-- (iii) `P(c_G = n) = 1 - F(n-1)^{G K + 1}`. -/
343theorem prob_reported_eq_top (hw : ∑ x, w x = 1) (hn : 1 ≤ n) (G K : ℕ) :
344 prob w (fun D : Draw G K → Fin (n + 1) => reported D = n) =
345 1 - cdf w (n - 1) ^ (G * K + 1) := by
346 rw [← prob_reported_le w G K (n - 1), ← prob_not w hw]
347 unfold prob
348 apply Finset.sum_congr rfl
349 intro D _
350 have := maxDraw_le D
351 rw [← reported_eq_maxDraw] at this
352 by_cases h : reported D = n
353 · rw [ite_eq_left h, ite_eq_left (by omega)]
354 · rw [ite_eq_right h, ite_eq_right (by omega)]
355
356/-- The binomial law `Bin(n, p)` on `{0, …, n}`. -/
357noncomputable def binomial (n : ℕ) (p : ℝ) (x : Fin (n + 1)) : ℝ :=
358 (n.choose x.val : ℝ) * p ^ x.val * (1 - p) ^ (n - x.val)
359
360theorem binomial_nonneg (n : ℕ) {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (x : Fin (n + 1)) :
361 0 ≤ binomial n p x := by
362 unfold binomial
363 have : 0 ≤ 1 - p := by linarith
364 positivity
365
366theorem binomial_sum (n : ℕ) (p : ℝ) : ∑ x, binomial n p x = 1 := by
367 unfold binomial
368 rw [Fin.sum_univ_eq_sum_range (fun x => (n.choose x : ℝ) * p ^ x * (1 - p) ^ (n - x)) (n + 1)]
369 have h := add_pow p (1 - p) n
370 rw [show p + (1 - p) = 1 by ring, one_pow] at h
371 exact (Finset.sum_congr rfl (fun x _ => by ring)).trans h.symm
372
373theorem binomial_cdf_pred (n : ℕ) (hn : 1 ≤ n) (p : ℝ) :
374 cdf (binomial n p) (n - 1) = 1 - p ^ n := by
375 unfold cdf
376 rw [← binomial_sum n p, Fin.sum_univ_castSucc, Fin.sum_univ_castSucc (fun x => binomial n p x)]
377 have h1 : ∀ x : Fin n, (if (Fin.castSucc x).val ≤ n - 1 then binomial n p (Fin.castSucc x)
378 else 0) = binomial n p (Fin.castSucc x) := fun x => ite_eq_left (by simp; omega)
379 have h2 : (if (Fin.last n).val ≤ n - 1 then binomial n p (Fin.last n) else 0) = 0 :=
380 ite_eq_right (by simp; omega)
381 simp only [h1, h2]
382 simp [binomial]
383
384/-- (iii) for the binomial null: `P(c_G = n) = 1 - (1 - p^n)^{G K + 1}`. -/
385theorem binomial_prob_reported_eq_top (hn : 1 ≤ n) (p : ℝ) (G K : ℕ) :
386 prob (binomial n p) (fun D : Draw G K → Fin (n + 1) => reported D = n) =
387 1 - (1 - p ^ n) ^ (G * K + 1) := by
388 rw [prob_reported_eq_top _ (binomial_sum n p) hn, binomial_cdf_pred n hn]
389
390/-- (iii) For fixed `n ≥ 1`, `K ≥ 1` and `0 < p ≤ 1`, the naive readout gap
391`ρ_G = E[c_G]/n - p` tends to `1 - p` as `G → ∞` (and is non-decreasing, `expect_reported_mono`):
392bounded by the lattice, never stationary. -/
393theorem tendsto_gap (hn : 1 ≤ n) {p : ℝ} (hp0 : 0 < p) (hp1 : p ≤ 1) {K : ℕ} (hK : 1 ≤ K) :
394 Tendsto (fun G : ℕ =>
395 expect (binomial n p) (fun D : Draw G K → Fin (n + 1) => (reported D : ℝ)) / n - p)
396 atTop (𝓝 (1 - p)) := by
397 have hw0 := binomial_nonneg n hp0.le hp1
398 have hw := binomial_sum n p
399 simp_rw [expect_reported _ hw]
400 have hlim : Tendsto (fun G : ℕ => aSeq (binomial n p) (G * K + 1)) atTop (𝓝 (n : ℝ)) := by
401 unfold aSeq
402 have : (n : ℝ) = ∑ j ∈ range n, (1 - 0) := by simp
403 rw [this]
404 apply tendsto_finsetSum
405 intro j hj
406 rw [mem_range] at hj
407 apply Tendsto.const_sub
408 have hF0 := cdf_nonneg hw0 j
409 have hF1 : cdf (binomial n p) j < 1 := by
410 have hmono : cdf (binomial n p) j ≤ cdf (binomial n p) (n - 1) := by
411 unfold cdf
412 apply Finset.sum_le_sum
413 intro x _
414 by_cases hx : x.val ≤ j
415 · rw [ite_eq_left hx, ite_eq_left (by omega)]
416 · rw [ite_eq_right hx]; split_ifs <;> simp [hw0 x]
417 rw [binomial_cdf_pred n hn] at hmono
418 have : 0 < p ^ n := pow_pos hp0 n
419 linarith
420 have hpow := tendsto_pow_atTop_nhds_zero_of_lt_one hF0 hF1
421 have hidx : Tendsto (fun G : ℕ => G * K + 1) atTop atTop := by
422 apply tendsto_atTop_mono (f := fun G : ℕ => G)
423 · intro G; nlinarith
424 · exact tendsto_id
425 exact hpow.comp hidx
426 have hn' : (n : ℝ) ≠ 0 := by positivity
427 have := (hlim.div_const (n : ℝ)).sub_const p
428 rwa [div_self hn'] at this
429
430end Law
431
432end FeedbackChannel.MultigenRunningMax