File size: 19,253 Bytes
a2ee19a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import OAI.Probability.MatroidSecretary.Transport.GeneralSimulationModel
import OAI.Probability.MatroidProphet.Main
import Mathlib.MeasureTheory.Integral.Prod

namespace OAI

/-! One-sample simulation for an arbitrary measurable complete seed. -/

namespace MatroidProphet.General

open MeasureTheory ProbabilityTheory

variable {n : ℕ} {R : Type*} [MeasurableSpace R]

lemma measurable_mask_membership :
    MeasurableSet {x : Finset (Fin n) × Fin n | x.2 ∈ x.1} :=
  (Set.toFinite _).measurableSet

lemma measurable_observed (A : HiddenRule n R) :
    Measurable (fun x : R × Weights n => observed A x.1 x.2) := by
  classical
  apply Measurable.of_eval
  intro e
  have hm : MeasurableSet {x : R × Weights n | e ∈ A.mask x.1} :=
    (measurableSet_mem_finset e).preimage (A.measurable_mask.comp measurable_fst)
  exact Measurable.ite hm ((measurable_pi_apply e).comp measurable_snd) measurable_const

lemma measurable_simulationHistory (A : HiddenRule n R) (k : Fin n) :
    Measurable (fun x : R × (Weights n × History n k) =>
      simulationHistory A x.1 x.2.1 x.2.2) := by
  classical
  apply Measurable.of_eval
  intro j
  have hh : Measurable (fun x : R × (Weights n × History n k) => x.2.2 j) :=
    (measurable_pi_apply j).comp (measurable_snd.comp measurable_snd)
  have hm : MeasurableSet {x : R × (Weights n × History n k) |
      (x.2.2 j).1 ∈ A.mask x.1} :=
    measurable_mask_membership.preimage
      ((A.measurable_mask.comp measurable_fst).prodMk (measurable_fst.comp hh))
  exact (measurable_fst.comp hh).prodMk (Measurable.ite hm
    (MatroidProphet.measurable_weight_eval.comp
      ((measurable_fst.comp measurable_snd).prodMk (measurable_fst.comp hh)))
    (measurable_snd.comp hh))

lemma measurable_simulationDecision (A : HiddenRule n R) (k : Fin n) :
    Measurable (fun x : R × (Weights n × History n k) =>
      simulationDecision A k x.1 x.2.1 x.2.2) := by
  classical
  have hc : Measurable (fun x : R × (Weights n × History n k) =>
      (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1) :=
    measurable_fst.comp ((measurable_pi_apply
      (⟨k.val, Nat.lt_succ_self _⟩ : Fin (k.val + 1))).comp
        (measurable_snd.comp measurable_snd))
  have hm : MeasurableSet {x : R × (Weights n × History n k) |
      (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask x.1} :=
    measurable_mask_membership.preimage
      ((A.measurable_mask.comp measurable_fst).prodMk hc)
  exact Measurable.ite hm measurable_const
    ((A.core.measurable_decide k).comp (measurable_fst.prodMk
      (((measurable_observed A).comp
        (measurable_fst.prodMk (measurable_fst.comp measurable_snd))).prodMk
          (measurable_simulationHistory A k))))

noncomputable def sampleSimulation (A : HiddenRule n R) : OnlineRule n R where
  decide := simulationDecision A
  measurable_decide := measurable_simulationDecision A

lemma observed_glue (A : HiddenRule n R) (r : R) (s v : Weights n) :
    observed A r (glue (A.mask r) s v) = observed A r s := by
  classical
  funext e
  by_cases he : e ∈ A.mask r <;> simp [observed, glue, he]

lemma simulationHistory_eq (A : HiddenRule n R) (r : R)
    (s v : Weights n) (π : ArrivalOrder n) (k : Fin n) :
    simulationHistory A r s (history v π k) = history (glue (A.mask r) s v) π k := rfl

theorem sampleSimulation_acceptedThrough (A : HiddenRule n R) (r : R)
    (s v : Weights n) (π : ArrivalOrder n) (t : ℕ) :
    acceptedThrough (sampleSimulation A) r s v π t =
      hiddenAcceptedThrough A r (glue (A.mask r) s v) π t := by
  classical
  ext e
  by_cases he : e ∈ A.mask r <;>
    simp [acceptedThrough, hiddenAcceptedThrough, decisionAt, sampleSimulation,
      simulationDecision, history, prefixIndex, simulationHistory_eq, observed_glue, he]

theorem sampleSimulation_reward (A : HiddenRule n R) (r : R)
    (s v : Weights n) (π : ArrivalOrder n) :
    reward (sampleSimulation A) r s v π = hiddenReward A r (glue (A.mask r) s v) π := by
  classical
  unfold reward hiddenReward
  rw [sampleSimulation_acceptedThrough]
  apply Finset.sum_congr rfl
  intro e he
  have he' : e ∉ A.mask r := (Finset.mem_sdiff.mp he).2
  simp [glue, he']

theorem sampleSimulation_feasible (M : Matroid (Fin n)) (A : HiddenRule n R)
    (hA : HiddenFeasible M A) : Feasible M (sampleSimulation A) := by
  intro r s v π t hs hv
  rw [sampleSimulation_acceptedThrough]
  apply hA
  intro e
  classical
  by_cases he : e ∈ A.mask r
  · simpa [glue, he] using hs e
  · simpa [glue, he] using hv e

lemma reward_nonneg (A : OnlineRule n R) (r : R) (s v : Weights n)
    (π : ArrivalOrder n) (hv : ∀ e, 0 ≤ v e) : 0 ≤ reward A r s v π :=
  Finset.sum_nonneg fun e _ => hv e

lemma reward_le_optimum (M : Matroid (Fin n)) (A : OnlineRule n R)
    (hA : Feasible M A) (r : R) (s v : Weights n) (π : ArrivalOrder n)
    (hs : ∀ e, 0 ≤ s e) (hv : ∀ e, 0 ≤ v e) :
    reward A r s v π ≤ optimum M v :=
  sum_le_optimum M v _ (hA r s v π n hs hv)

lemma hiddenWorstReward_le (A : HiddenRule n R) (w : Weights n)
    (r : R) (π : ArrivalOrder n) :
    hiddenWorstReward A w r ≤ hiddenReward A r w π := by
  classical
  exact Finset.inf'_le (hiddenReward A r w) (Finset.mem_univ π)

lemma hiddenWorstReward_nonneg (A : HiddenRule n R) (w : Weights n)
    (hw : ∀ e, 0 ≤ w e) (r : R) : 0 ≤ hiddenWorstReward A w r := by
  classical
  apply Finset.le_inf'
  intro π _
  exact Finset.sum_nonneg fun e _ => hw e

lemma hiddenWorstReward_le_optimum (M : Matroid (Fin n)) (A : HiddenRule n R)
    (hA : HiddenFeasible M A) (w : Weights n) (hw : ∀ e, 0 ≤ w e) (r : R) :
    hiddenWorstReward A w r ≤ optimum M w := by
  apply (hiddenWorstReward_le A w r (Equiv.refl _)).trans
  exact sum_le_optimum M w _ (hA w hw r (Equiv.refl _) n)

lemma measurable_decisionAt {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R)
    (π : ArrivalOrder n) (k : Fin n) :
    Measurable (fun x : R × (Weights n × Weights n) =>
      decisionAt A x.1 x.2.1 x.2.2 π k) :=
  (A.measurable_decide k).comp
    (measurable_fst.prodMk ((measurable_fst.comp measurable_snd).prodMk
      ((measurable_history π k).comp (measurable_snd.comp measurable_snd))))

lemma reward_eq_sum {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) (r : R)
    (s v : Weights n) (π : ArrivalOrder n) :
    reward A r s v π =
      ∑ e : Fin n, if decisionAt A r s v π (π.symm e) = true then v e else 0 := by
  classical
  unfold reward acceptedThrough
  rw [Finset.sum_filter]
  apply Finset.sum_congr rfl
  intro e _
  simp only [(π.symm e).isLt, true_and]

lemma measurable_reward_fixed_order {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R)
    (π : ArrivalOrder n) :
    Measurable (fun x : R × (Weights n × Weights n) =>
      reward A x.1 x.2.1 x.2.2 π) := by
  classical
  simp_rw [reward_eq_sum]
  apply Finset.measurable_sum
  intro e _
  have hd := measurable_decisionAt A π (π.symm e)
  have ht : MeasurableSet {x : R × (Weights n × Weights n) |
      decisionAt A x.1 x.2.1 x.2.2 π (π.symm e) = true} :=
    hd (measurableSet_singleton true)
  exact Measurable.ite ht
    ((measurable_pi_apply e).comp (measurable_snd.comp measurable_snd)) measurable_const

/-- The realized reward remains measurable for arbitrary measurable adversarial permutations. -/
theorem measurable_reward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) :
    Measurable (fun x : ArrivalOrder n × (R × (Weights n × Weights n)) =>
      reward A x.2.1 x.2.2.1 x.2.2.2 x.1) :=
  measurable_from_prod_countable_right (measurable_reward_fixed_order A)

@[simp] lemma glue_self (mask : Finset (Fin n)) (w : Weights n) :
    glue mask w w = w := by
  classical
  funext e
  simp [glue]

lemma measurable_hiddenReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) (π : ArrivalOrder n) :
    Measurable (fun x : R × Weights n => hiddenReward A x.1 x.2 π) := by
  have hm := (measurable_reward_fixed_order (sampleSimulation A) π).comp
    (measurable_fst.prodMk (measurable_snd.prodMk measurable_snd))
  simpa only [Function.comp_def, sampleSimulation_reward, glue_self] using hm

lemma measurable_hiddenWorstReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) :
    Measurable (fun x : R × Weights n => hiddenWorstReward A x.2 x.1) := by
  classical
  have hm : Measurable ((Finset.univ : Finset (ArrivalOrder n)).inf'
      Finset.univ_nonempty (fun π (x : R × Weights n) => hiddenReward A x.1 x.2 π)) :=
    Finset.inf'_induction Finset.univ_nonempty _
      (fun _ hf _ hg => hf.inf hg) (fun π _ => measurable_hiddenReward A π)
  convert hm using 1
  ext x
  simp only [hiddenWorstReward, Finset.inf'_apply]

lemma measurable_glue (mask : Finset (Fin n)) :
    Measurable (fun x : Weights n × Weights n => glue mask x.1 x.2) :=
  MatroidProphet.measurable_glue mask

lemma measurable_glue_seed (mask : R → Finset (Fin n)) (hmask : Measurable mask) :
    Measurable (fun x : R × (Weights n × Weights n) => glue (mask x.1) x.2.1 x.2.2) := by
  have h : Measurable (fun x : Finset (Fin n) × (Weights n × Weights n) =>
      glue x.1 x.2.1 x.2.2) :=
    measurable_from_prod_countable_right measurable_glue
  exact h.comp ((hmask.comp measurable_fst).prodMk measurable_snd)

theorem glue_fixed_law {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)
    (S V : Ω → Weights n) (hS : Measurable S) (hV : Measurable V)
    (hi : iIndepFun (pairedCoordinates S V) μ)
    (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
    (mask : Finset (Fin n)) :
    μ.map (fun ω => glue mask (S ω) (V ω)) = μ.map V :=
  MatroidProphet.glue_fixed_law μ S V hS hV hi hlaw mask

/-- Joint gluing law with an arbitrary measurable complete seed; in particular,
the observation mask may depend on all of that seed. -/
theorem glue_seed_joint_law {Ω : Type*} [MeasurableSpace Ω]
    (μ : Measure Ω) [IsProbabilityMeasure μ]
    (ν : Measure R) [IsProbabilityMeasure ν]
    (S V : Ω → Weights n) (seed : Ω → R)
    (hS : Measurable S) (hV : Measurable V) (hseedM : Measurable seed)
    (hi : iIndepFun (pairedCoordinates S V) μ)
    (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
    (hseed : IndepFun (fun ω => (S ω, V ω)) seed μ)
    (hseedLaw : μ.map seed = ν) (mask : R → Finset (Fin n)) (hmask : Measurable mask) :
    MeasurePreserving (fun ω => (seed ω, glue (mask (seed ω)) (S ω) (V ω)))
      μ (ν.prod (μ.map V)) := by
  have hfiber (r : R) :
      (μ.map (fun ω => (S ω, V ω))).map (fun d => glue (mask r) d.1 d.2) = μ.map V := by
    rw [Measure.map_map (measurable_glue (mask r)) (hS.prodMk hV)]
    exact glue_fixed_law μ S V hS hV hi hlaw (mask r)
  have hstart : MeasurePreserving (fun ω => (seed ω, (S ω, V ω))) μ
      (ν.prod (μ.map (fun ω => (S ω, V ω)))) := by
    refine ⟨hseedM.prodMk (hS.prodMk hV), ?_⟩
    rw [hseed.symm.map_prod_eq_prod_map_map hseedM.aemeasurable
      (hS.prodMk hV).aemeasurable, hseedLaw]
  have hend := (MeasurePreserving.id ν).skew_product
    (g := fun (r : R) (d : Weights n × Weights n) => glue (mask r) d.1 d.2)
    (measurable_glue_seed mask hmask) (ae_of_all _ hfiber)
  exact hend.comp hstart

/-- Nonnegativity of a finite vector is a Borel condition. -/
lemma measurableSet_nonnegative (n : ℕ) :
    MeasurableSet {w : Weights n | ∀ e, 0 ≤ w e} := by
  simp only [Set.ofPred_forall]
  exact MeasurableSet.iInter fun e => measurableSet_le measurable_const (measurable_pi_apply e)

lemma integrable_hidden_product {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ)
    (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (ρ : Measure (Weights n)) [SFinite ρ]
    (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
      ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
        M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
    (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ) :
    Integrable (fun x : Ξ × Weights n => hiddenWorstReward A x.2 x.1)
      (ν.prod ρ) := by
  apply (hopt.comp_snd ν).mono' (measurable_hiddenWorstReward A).aestronglyMeasurable
  filter_upwards [(Measure.quasiMeasurePreserving_snd (μ := ν) (ν := ρ)).ae hNN] with x hx
  rw [Real.norm_eq_abs, abs_of_nonneg (hiddenWorstReward_nonneg A x.2 hx x.1)]
  exact hiddenWorstReward_le_optimum M A hA x.2 hx x.1

lemma hidden_product_integral_bound {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n))
    (A : HiddenRule n Ξ) (ν : Measure (Ξ)) [IsProbabilityMeasure ν]
    (ρ : Measure (Weights n)) [IsProbabilityMeasure ρ] (c : ℝ)
    (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
      ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
        M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
    (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ)
    (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
      c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) :
    c * (∫ w, optimum M w ∂ρ) ≤
      ∫ x : Ξ × Weights n, hiddenWorstReward A x.2 x.1 ∂ν.prod ρ := by
  have hip := integrable_hidden_product M A ν ρ hA hNN hopt
  rw [← integral_const_mul]
  calc
    _ ≤ ∫ w, ∫ r, hiddenWorstReward A w r ∂ν ∂ρ := by
      apply integral_mono_ae (hopt.const_mul c) hip.integral_prod_right
      filter_upwards [hNN] with w hw
      exact hbound w hw
    _ = _ := (integral_prod_symm _ hip).symm

lemma integrable_feasible_reward {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n))
    (A : OnlineRule n Ξ) (hA : Feasible M A)
    {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)
    (S V : Ω → Weights n) (R : Ω → Ξ) (π : Ω → ArrivalOrder n)
    (hS : Measurable S) (hV : Measurable V) (hR : Measurable R) (hπ : Measurable π)
    (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
    (hopt : Integrable (fun ω => optimum M (V ω)) μ) :
    Integrable (fun ω => reward A (R ω) (S ω) (V ω) (π ω)) μ := by
  have hrm := (measurable_reward A).comp (hπ.prodMk (hR.prodMk (hS.prodMk hV)))
  apply hopt.mono' hrm.aestronglyMeasurable
  filter_upwards [hSN, hVN] with ω hs hv
  change ‖reward A (R ω) (S ω) (V ω) (π ω)‖ ≤ optimum M (V ω)
  rw [Real.norm_eq_abs, abs_of_nonneg (reward_nonneg A (R ω) (S ω) (V ω) (π ω) hv)]
  exact reward_le_optimum M A hA (R ω) (S ω) (V ω) (π ω) hs hv

/-- The full one-sample integration step preserves the expected minimum over all orders. -/
theorem oneSample_of_hidden {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ)
    (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (c : ℝ)
    (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
      ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ),
        M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)))
    (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) →
      c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν)
    {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]
    (S V : Ω → Weights n) (R : Ω → Ξ)
    (hS : Measurable S) (hV : Measurable V) (hR : Measurable R)
    (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e)
    (hi : iIndepFun (pairedCoordinates S V) μ)
    (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e))
    (hseed : IndepFun (fun ω => (S ω, V ω)) R μ)
    (hRlaw : μ.map R = ν)
    (hopt : Integrable (fun ω => optimum M (V ω)) μ)
    (π : Ω → ArrivalOrder n) (hπ : Measurable π) :
    Integrable (fun ω => reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω)) μ ∧
      c * (∫ ω, optimum M (V ω) ∂μ) ≤
        ∫ ω, reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω) ∂μ := by
  have hj := glue_seed_joint_law μ ν S V R hS hV hR hi hlaw hseed hRlaw A.mask A.measurable_mask
  have hoptLaw : Integrable (optimum M) (μ.map V) :=
    (integrable_map_measure (measurable_optimum M).aestronglyMeasurable hV.aemeasurable).2 hopt
  have hNNLaw : ∀ᵐ w ∂μ.map V, ∀ e, 0 ≤ w e :=
    (ae_map_iff hV.aemeasurable (measurableSet_nonnegative n)).2 hVN
  have hip := integrable_hidden_product M A ν (μ.map V) hA hNNLaw hoptLaw
  have him := hj.integrable_comp_of_integrable hip
  have hri := integrable_feasible_reward M (sampleSimulation A)
    (sampleSimulation_feasible M A hA) μ S V R π hS hV hR hπ hSN hVN hopt
  have hb := hidden_product_integral_bound M A ν (μ.map V) c hA hNNLaw hoptLaw hbound
  have hoptEq := integral_map_of_stronglyMeasurable (μ := μ) hV
    (measurable_optimum M).stronglyMeasurable
  have hminEq := integral_map_of_stronglyMeasurable (μ := μ) hj.measurable
    (measurable_hiddenWorstReward A).stronglyMeasurable
  rw [hj.map_eq] at hminEq
  rw [hoptEq, hminEq] at hb
  refine ⟨hri, hb.trans (integral_mono_ae him hri (ae_of_all _ ?_))⟩
  intro ω
  change hiddenWorstReward A (glue (A.mask (R ω)) (S ω) (V ω)) (R ω) ≤
    reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω)
  rw [sampleSimulation_reward]
  exact hiddenWorstReward_le A _ (R ω) (π ω)

/-- The manuscript's simulation lemma without any finite-seed restriction. -/
theorem simulation_contract.{u, v} : SimulationContract.{u, v} := by
  intro n R mR M A ν hν c hA hbound
  let := hν
  refine ⟨sampleSimulation A, ?_, sampleSimulation_feasible M A hA,
    sampleSimulation_acceptedThrough A, sampleSimulation_reward A, ?_⟩
  · intro k r s h
    rfl
  · intro Ω mΩ μ hμ S V seed hS hV hseedM hSN hVN hi hlaw hseed hseedLaw hopt π hπ
    exact ⟨glue_seed_joint_law μ ν S V seed hS hV hseedM hi hlaw hseed hseedLaw
      A.mask A.measurable_mask,
      oneSample_of_hidden M A ν c hA hbound μ S V seed hS hV hseedM hSN hVN
        hi hlaw hseed hseedLaw hopt π hπ⟩

/-- The concrete finite-seed information model is a special case, with exactly
the same decisions rather than an unrelated replacement rule. -/
def OnlineRule.ofFinite {bits : ℕ} (A : MatroidProphet.OnlineRule n bits) :
    OnlineRule n (Seed bits) where
  decide := A.decide
  measurable_decide := A.measurable_decide

def HiddenRule.ofFinite {bits : ℕ} (A : MatroidProphet.HiddenRule n bits) :
    HiddenRule n (Seed bits) where
  mask := A.mask
  measurable_mask := measurable_of_countable A.mask
  core := OnlineRule.ofFinite A.core

@[simp] lemma acceptedThrough_ofFinite {bits : ℕ}
    (A : MatroidProphet.OnlineRule n bits) (r : Seed bits) (s v : Weights n)
    (π : ArrivalOrder n) (t : ℕ) :
    acceptedThrough (OnlineRule.ofFinite A) r s v π t =
      MatroidProphet.acceptedThrough A r s v π t := rfl

@[simp] lemma hiddenAcceptedThrough_ofFinite {bits : ℕ}
    (A : MatroidProphet.HiddenRule n bits) (r : Seed bits) (w : Weights n)
    (π : ArrivalOrder n) (t : ℕ) :
    hiddenAcceptedThrough (HiddenRule.ofFinite A) r w π t =
      MatroidProphet.hiddenAcceptedThrough A r w π t := rfl

@[simp] lemma hiddenWorstReward_ofFinite {bits : ℕ}
    (A : MatroidProphet.HiddenRule n bits) (w : Weights n) (r : Seed bits) :
    hiddenWorstReward (HiddenRule.ofFinite A) w r = MatroidProphet.hiddenWorstReward A w r := rfl

end MatroidProphet.General

end OAI