File size: 17,092 Bytes
dd14c26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.MeasureTheory.Constructions.Pi
import OAI.Probability.MatroidSecretary.Secretary.SourcePrefixLaw
import OAI.Probability.MatroidSecretary.Secretary.Precommit
import OAI.Probability.MatroidSecretary.Weights.FiniteWeightLawTheorems
import OAI.Probability.MatroidSecretary.Secretary.ConditionalLaw
import OAI.Probability.MatroidProphet.Main
import OAI.Probability.MatroidSecretary.Secretary.PrefixObservationModel
import OAI.Probability.MatroidSecretary.Secretary.ProbabilityModel

namespace OAI

/-!
# Initial-seed / random-prefix coupling

The complete table is drawn with the initial seed, before the independent
arrival permutation.  Reassociation here is only a proof of the joint law;
the implementation does not defer any table randomness until after the prefix.
-/

namespace MatroidProphet.Secretary

open MeasureTheory

variable {U T S B A : Type*}
variable [MeasurableSpace U] [MeasurableSpace T] [MeasurableSpace S]
variable [MeasurableSpace B] [MeasurableSpace A]

/-- Moving the independent arrival randomness next to the source seed does not
change the product law; the entire precommitted table remains present. -/
theorem initial_seed_reassociate (μ : Measure U) (ν : Measure T) (η : Measure S)
    [SFinite μ] [SFinite ν] [SFinite η] :
    MeasurePreserving (fun z : (U × T) × S => ((z.1.1, z.2), z.1.2))
      ((μ.prod ν).prod η) ((μ.prod η).prod ν) := by
  have h₁ := measurePreserving_prodAssoc μ ν η
  have h₂ := (MeasurePreserving.id μ).prod
    (Measure.measurePreserving_swap (μ := ν) (ν := η))
  have h₃ := (measurePreserving_prodAssoc μ η ν).symm MeasurableEquiv.prodAssoc
  exact h₃.comp (h₂.comp h₁)

/-- Any observation of source seed and independent prefix randomness retains
independence from the complete pre-drawn table. -/
theorem observation_table_joint (μ : Measure U) (ν : Measure T) (η : Measure S)
    (ρ : Measure B) [SFinite μ] [SFinite ν] [SFinite η]
    (index : U × S → B) (hi : Measurable index)
    (hindex : (μ.prod η).map index = ρ) :
    ((μ.prod ν).prod η).map
      (fun z : (U × T) × S => (index (z.1.1, z.2), z.1.2)) = ρ.prod ν := by
  have hm : MeasurePreserving index (μ.prod η) ρ := ⟨hi, hindex⟩
  exact ((hm.prod (MeasurePreserving.id ν)).comp
    (initial_seed_reassociate μ ν η)).map_eq

/-- Decoding the precommitted table after observing the prefix has the same
law as selecting from an independent table at an index with the required
observation law.  No future arrival information is an input to `decode`. -/
theorem reconstructed_seed_law (μ : Measure U) (ν : Measure T) (η : Measure S)
    (ρ : Measure B) (ξ : Measure A) [SFinite μ] [SFinite ν] [SFinite η]
    (index : U × S → B) (hi : Measurable index)
    (hindex : (μ.prod η).map index = ρ)
    (decode : B × T → A) (hd : Measurable decode)
    (hdecode : (ρ.prod ν).map decode = ξ) :
    ((μ.prod ν).prod η).map
      (fun z : (U × T) × S => decode (index (z.1.1, z.2), z.1.2)) = ξ := by
  rw [← hdecode, ← observation_table_joint μ ν η ρ index hi hindex,
    Measure.map_map hd]
  · rfl
  · exact (hi.comp (measurable_fst.fst.prodMk measurable_snd)).prodMk
      measurable_fst.snd

end MatroidProphet.Secretary

namespace MatroidProphet.Secretary

open MeasureTheory

variable {A B : Type*} [Fintype A] [Fintype B]
variable [MeasurableSpace A] [MeasurableSingletonClass A]
variable [MeasurableSpace B] [MeasurableSingletonClass B]
variable [DecidableEq A] [DecidableEq B]

/-- Normalize the actual source measure on each observation fiber. -/
noncomputable def conditionalSourceLaw (μ : Measure A) (obs : A → B)
    (fallback : A) (b : B) : Measure A :=
  FiniteLaw.weightMeasure
    (fiberKernel (fun a => μ.real {a}) obs fallback b)
    (fiberKernel_nonneg _ (fun _ => measureReal_nonneg) obs fallback b)
    (fiberKernel_sum _ obs fallback b)

instance conditionalSourceLaw_probability (μ : Measure A) (obs : A → B)
    (fallback : A) (b : B) : IsProbabilityMeasure (conditionalSourceLaw μ obs fallback b) := by
  unfold conditionalSourceLaw
  infer_instance

omit [Fintype B] [DecidableEq A] in
/-- The graph of the observation keeps the full source realization. -/
theorem observation_graph_atom (μ : Measure A) (obs : A → B) (b : B) (a : A) :
    (μ.map (fun a => (obs a, a))) {(b, a)} =
      if obs a = b then μ {a} else 0 := by
  rw [Measure.map_apply (measurable_of_countable _) (measurableSet_singleton _)]
  have heq : (fun a => (obs a, a)) ⁻¹' {(b, a)} =
      if obs a = b then {a} else ∅ := by
    by_cases hobs : obs a = b
    · rw [ite_eq_left hobs]
      ext source
      simp only [Set.mem_preimage, Set.mem_singleton_iff, Prod.mk.injEq]
      constructor
      · exact And.right
      · rintro rfl
        exact ⟨hobs, rfl⟩
    · rw [ite_eq_right hobs]
      ext source
      simp only [Set.mem_preimage, Set.mem_singleton_iff, Prod.mk.injEq,
        Set.mem_empty_iff_false, iff_false]
      rintro ⟨hvalue, rfl⟩
      exact hobs hvalue
  rw [heq]
  split_ifs <;> simp

omit [Fintype B] in
/-- The true observation marginal times the normalized conditional law is the
exact graph law of the complete source seed, including unused coordinates. -/
theorem conditionalSourceLaw_joint_atom (μ : Measure A) [IsProbabilityMeasure μ]
    (obs : A → B) (fallback : A) (b : B) (a : A) :
    (μ.map obs) {b} * conditionalSourceLaw μ obs fallback b {a} =
      (μ.map (fun a => (obs a, a))) {(b, a)} := by
  have hmap : (μ.map obs) {b} =
      ENNReal.ofReal (fiberMass (fun a => μ.real {a}) obs b) := by
    calc
      _ = ENNReal.ofReal ((μ.map obs).real {b}) :=
        (ENNReal.ofReal_toReal (measure_ne_top (μ.map obs) {b})).symm
      _ = _ := congrArg ENNReal.ofReal (by
        rw [FiniteLaw.map_real_singleton]
        unfold fiberMass
        apply Finset.sum_congr rfl
        intro a _
        by_cases h : obs a = b <;> simp [h])
  rw [hmap, conditionalSourceLaw, FiniteLaw.weightMeasure_singleton,
    ← ENNReal.ofReal_mul (fiberMass_nonneg _ (fun _ => measureReal_nonneg) obs b),
    fiberMass_mul_fiberKernel _ (fun _ => measureReal_nonneg) obs fallback,
    observation_graph_atom]
  split_ifs
  · exact ENNReal.ofReal_toReal (measure_ne_top μ {a})
  · simp

/-- Predrawing every conditional source seed and selecting the observed fiber
reconstructs the complete source joint law exactly. -/
theorem conditional_table_joint (μ : Measure A) [IsProbabilityMeasure μ]
    (obs : A → B) (fallback : A) :
    ((μ.map obs).prod (Measure.pi (conditionalSourceLaw μ obs fallback))).map
      (fun z : B × (B → A) => (z.1, z.2 z.1)) =
      μ.map (fun a => (obs a, a)) := by
  apply SecretaryPrecommit.selected_joint_eq
  intro b a
  exact (conditionalSourceLaw_joint_atom μ obs fallback b a).symm

/-- The actual initial seed is `(source seed, whole conditional table)`,
independent of prefix randomness.  If the prefix observation has the true
observation law, lookup recovers the full joint source law. -/
theorem precommitted_source_joint {S : Type*} [MeasurableSpace S]
    (μ : Measure A) [IsProbabilityMeasure μ] (η : Measure S) [SFinite η]
    (obs : A → B) (fallback : A) (index : A × S → B)
    (hi : Measurable index) (hindex : (μ.prod η).map index = μ.map obs) :
    ((μ.prod (Measure.pi (conditionalSourceLaw μ obs fallback))).prod η).map
      (fun z : (A × (B → A)) × S =>
        (index (z.1.1, z.2), z.1.2 (index (z.1.1, z.2)))) =
      μ.map (fun a => (obs a, a)) := by
  exact reconstructed_seed_law μ (Measure.pi (conditionalSourceLaw μ obs fallback)) η
    (μ.map obs) (μ.map (fun a => (obs a, a))) index hi hindex
    (fun z : B × (B → A) => (z.1, z.2 z.1)) (measurable_of_countable _)
    (conditional_table_joint μ obs fallback)

/-- In particular the reconstructed seed, with all unused coordinates, has
the original source marginal. -/
theorem precommitted_source_marginal {S : Type*} [MeasurableSpace S]
    (μ : Measure A) [IsProbabilityMeasure μ] (η : Measure S) [SFinite η]
    (obs : A → B) (fallback : A) (index : A × S → B)
    (hi : Measurable index) (hindex : (μ.prod η).map index = μ.map obs) :
    ((μ.prod (Measure.pi (conditionalSourceLaw μ obs fallback))).prod η).map
      (fun z : (A × (B → A)) × S => z.1.2 (index (z.1.1, z.2))) = μ := by
  have h := congrArg (fun ν : Measure (B × A) => ν.map Prod.snd)
    (precommitted_source_joint μ η obs fallback index hi hindex)
  have hf : Measurable (fun z : (A × (B → A)) × S =>
      (index (z.1.1, z.2), z.1.2 (index (z.1.1, z.2)))) :=
    (measurable_of_countable (fun z : B × (B → A) => (z.1, z.2 z.1))).comp
      ((hi.comp (measurable_fst.fst.prodMk measurable_snd)).prodMk measurable_fst.snd)
  rw [Measure.map_map measurable_snd hf,
    Measure.map_map measurable_snd (measurable_of_countable _)] at h
  change ((μ.prod (Measure.pi (conditionalSourceLaw μ obs fallback))).prod η).map
    (fun z : (A × (B → A)) × S => z.1.2 (index (z.1.1, z.2))) = μ.map id at h
  simpa only [Measure.map_id] using h

theorem ae_precommitted_source_observation {S : Type*} [MeasurableSpace S]
    (μ : Measure A) [IsProbabilityMeasure μ] (η : Measure S) [SFinite η]
    (obs : A → B) (fallback : A) (index : A × S → B)
    (hi : Measurable index) (hindex : (μ.prod η).map index = μ.map obs) :
    ∀ᵐ z : (A × (B → A)) × S
      ∂(μ.prod (Measure.pi (conditionalSourceLaw μ obs fallback))).prod η,
      obs (z.1.2 (index (z.1.1, z.2))) = index (z.1.1, z.2) := by
  have hgraph : ∀ᵐ x : B × A ∂μ.map (fun a => (obs a, a)), obs x.2 = x.1 := by
    exact (ae_map_iff (measurable_of_countable _).aemeasurable
      (Set.to_countable _).measurableSet).2 (ae_of_all _ fun _ => rfl)
  rw [← precommitted_source_joint μ η obs fallback index hi hindex] at hgraph
  have hf : Measurable (fun z : (A × (B → A)) × S =>
      (index (z.1.1, z.2), z.1.2 (index (z.1.1, z.2)))) :=
    (measurable_of_countable (fun z : B × (B → A) => (z.1, z.2 z.1))).comp
      ((hi.comp (measurable_fst.fst.prodMk measurable_snd)).prodMk
        measurable_fst.snd)
  exact (ae_map_iff hf.aemeasurable (Set.to_countable _).measurableSet).1 hgraph

end MatroidProphet.Secretary

namespace MatroidProphet.Secretary

open MeasureTheory

abbrev SourceObservation (n : ℕ) := Bool × Finset (Fin n)

/-- The full source seed together with every conditional draw, all predrawn. -/
abbrev CouplingSeed (n : ℕ) :=
  Seed (mainSeedBits n) × (SourceObservation n → Seed (mainSeedBits n))

noncomputable def couplingObservation {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (r : Seed (mainSeedBits n)) : SourceObservation n :=
  (mainBranch r, (completeHiddenRule M hE).mask r)

noncomputable def couplingKernel {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (b : SourceObservation n) : Measure (Seed (mainSeedBits n)) :=
  conditionalSourceLaw (sourceSeedLaw n) (couplingObservation M hE) (fun _ => false) b

instance couplingKernel_probability {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (b : SourceObservation n) :
    IsProbabilityMeasure (couplingKernel M hE b) := by
  unfold couplingKernel
  infer_instance

/-- This initial seed law depends on the matroid but not on any weights. -/
noncomputable def couplingSeedLaw {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) : Measure (CouplingSeed n) :=
  (sourceSeedLaw n).prod (Measure.pi (couplingKernel M hE))

instance couplingSeedLaw_probability {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) : IsProbabilityMeasure (couplingSeedLaw M hE) := by
  unfold couplingSeedLaw
  infer_instance

/-- The cutoff is fixed before arrivals using only the first part of the seed. -/
noncomputable def couplingLength {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (q : CouplingSeed n) : Fin (n + 1) :=
  ⟨((completeHiddenRule M hE).mask q.1).card, by
    have h := Finset.card_le_univ ((completeHiddenRule M hE).mask q.1)
    simpa only [Fintype.card_fin, Nat.lt_succ_iff] using h⟩

/-- Lookup needs only the seed and the observed label set, not its weights or
the future suffix order. -/
def couplingDecode {n : ℕ} (q : CouplingSeed n) (P : Finset (Fin n)) :
    Seed (mainSeedBits n) := q.2 (mainBranch q.1, P)

noncomputable def couplingIndex {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (x : Seed (mainSeedBits n) × ArrivalOrder n) :
    SourceObservation n :=
  (mainBranch x.1, orderPrefix x.2 ((completeHiddenRule M hE).mask x.1).card)

/-- The remaining input is the independently proved random-prefix law, not a
hypothesis of the final secretary endpoint. -/
theorem coupling_joint_of_prefix_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ)
    (hprefix : ((sourceSeedLaw n).prod (uniformArrivalLaw n)).map (couplingIndex M hE) =
      (sourceSeedLaw n).map (couplingObservation M hE)) :
    ((couplingSeedLaw M hE).prod (uniformArrivalLaw n)).map
      (fun z : CouplingSeed n × ArrivalOrder n =>
        ((mainBranch z.1.1, orderPrefix z.2 (couplingLength M hE z.1).val),
          couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val))) =
      (sourceSeedLaw n).map (fun r => (couplingObservation M hE r, r)) := by
  exact precommitted_source_joint (sourceSeedLaw n) (uniformArrivalLaw n)
    (couplingObservation M hE) (fun _ => false) (couplingIndex M hE)
    (measurable_of_countable _) hprefix

theorem coupling_marginal_of_prefix_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ)
    (hprefix : ((sourceSeedLaw n).prod (uniformArrivalLaw n)).map (couplingIndex M hE) =
      (sourceSeedLaw n).map (couplingObservation M hE)) :
    ((couplingSeedLaw M hE).prod (uniformArrivalLaw n)).map
      (fun z : CouplingSeed n × ArrivalOrder n =>
        couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val)) =
      sourceSeedLaw n := by
  exact precommitted_source_marginal (sourceSeedLaw n) (uniformArrivalLaw n)
    (couplingObservation M hE) (fun _ => false) (couplingIndex M hE)
    (measurable_of_countable _) hprefix

theorem coupling_mask_ae_of_prefix_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ)
    (hprefix : ((sourceSeedLaw n).prod (uniformArrivalLaw n)).map (couplingIndex M hE) =
      (sourceSeedLaw n).map (couplingObservation M hE)) :
    ∀ᵐ z : CouplingSeed n × ArrivalOrder n
      ∂(couplingSeedLaw M hE).prod (uniformArrivalLaw n),
      (completeHiddenRule M hE).mask
          (couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val)) =
        orderPrefix z.2 (couplingLength M hE z.1).val := by
  filter_upwards [ae_precommitted_source_observation (sourceSeedLaw n) (uniformArrivalLaw n)
    (couplingObservation M hE) (fun _ => false) (couplingIndex M hE)
    (measurable_of_countable _) hprefix] with z hz
  exact congrArg Prod.snd hz

end MatroidProphet.Secretary

namespace MatroidProphet.Secretary

open MeasureTheory

/-- Concrete random-prefix identity, with no transport premise. -/
theorem coupling_source_prefix_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) :
    ((sourceSeedLaw n).prod (uniformArrivalLaw n)).map (couplingIndex M hE) =
      (sourceSeedLaw n).map (couplingObservation M hE) := by
  exact source_random_prefix_joint_law M hE

/-- The complete initial finite seed and independent arrival order reconstruct
exactly the original full source graph law. No assumption is added to an endpoint. -/
theorem coupling_joint_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) :
    ((couplingSeedLaw M hE).prod (uniformArrivalLaw n)).map
      (fun z : CouplingSeed n × ArrivalOrder n =>
        ((mainBranch z.1.1, orderPrefix z.2 (couplingLength M hE z.1).val),
          couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val))) =
      (sourceSeedLaw n).map (fun r => (couplingObservation M hE r, r)) :=
  coupling_joint_of_prefix_law M hE (coupling_source_prefix_law M hE)

/-- The decoded seed retains the law of every source bit, including unused bits. -/
theorem coupling_source_law {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) :
    ((couplingSeedLaw M hE).prod (uniformArrivalLaw n)).map
      (fun z : CouplingSeed n × ArrivalOrder n =>
        couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val)) =
      sourceSeedLaw n :=
  coupling_marginal_of_prefix_law M hE (coupling_source_prefix_law M hE)

/-- Almost-sure mask agreement for the concrete initial-seed experiment.
Every-seed feasibility separately uses the replay's mismatch-rejection guard. -/
theorem coupling_mask_ae {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) :
    ∀ᵐ z : CouplingSeed n × ArrivalOrder n
      ∂(couplingSeedLaw M hE).prod (uniformArrivalLaw n),
      (completeHiddenRule M hE).mask
          (couplingDecode z.1 (orderPrefix z.2 (couplingLength M hE z.1).val)) =
        orderPrefix z.2 (couplingLength M hE z.1).val :=
  coupling_mask_ae_of_prefix_law M hE (coupling_source_prefix_law M hE)

end MatroidProphet.Secretary

end OAI