File size: 6,137 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
import OAI.Probability.MatroidSecretary.Secretary.MaskModel
import OAI.Probability.MatroidProphet.Main

namespace OAI

/-! Exact branch/sacrificed-mask marginal of the complete source law.

This marginal is taken after integrating all source coins, including test,
parity and unused coins. It is not a product-law assertion conditional on the
entire secretary seed.

Pinned source: `sections/secretary.tex`, lines 41--52 and 68--78,
SHA256 `3554fe0f7296782edf63cc7f1305c377e7a7b9d8f8948b9510ea4ad02a702d63`.
These are supporting obligations of `cor:secretary`, not the complete endpoint.
-/

namespace MatroidProphet.Secretary

open MeasureTheory Finset

lemma branchRate_pos (j : Bool) : 0 < branchRate j := by
  cases j <;> norm_num [branchRate]

lemma branchRate_lt_one (j : Bool) : branchRate j < 1 := by
  cases j <;> norm_num [branchRate]

lemma branchRate_main :
    branchRate true = 1 / 2 + (1 - 1 / 2) * (1 / 4 + (1 - 1 / 4) * thinningRate) := by
  norm_num [branchRate, thinningRate]

lemma sourceMask_eq_completeHiddenRule {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (r : Seed (mainSeedBits n)) :
    sourceMask r = (completeHiddenRule M hE).mask r := by
  rfl

lemma triple_mask_expectation {n : ℕ} (f : Finset (Fin n) → ℝ) :
    bitsExpectation (fun _ : Fin n => (1 / 2 : ℝ)) univ (fun H =>
      bitsExpectation (fun _ : Fin n => (1 / 4 : ℝ)) univ (fun D =>
        bitsExpectation (fun _ : Fin n => thinningRate) univ (fun C => f (H ∪ D ∪ C)))) =
      bitsExpectation (fun _ : Fin n => branchRate true) univ f := by
  have hDC (H : Finset (Fin n)) :
      bitsExpectation (fun _ : Fin n => (1 / 4 : ℝ)) univ (fun D =>
        bitsExpectation (fun _ : Fin n => thinningRate) univ (fun C => f (H ∪ D ∪ C))) =
      bitsExpectation (fun _ : Fin n => 1 / 4 + (1 - 1 / 4) * thinningRate) univ
        (fun S => f (H ∪ S)) := by
    simpa only [Finset.union_assoc] using
      bitsExpectation_union (fun _ : Fin n => (1 / 4 : ℝ))
        (fun _ : Fin n => thinningRate) univ (fun S => f (H ∪ S))
  simp_rw [hDC]
  rw [bitsExpectation_union]
  congr 1
  funext e
  exact branchRate_main.symm

/-- Joint branch/mask law. All unused source coins are integrated, not discarded
from the information available to the adversary. -/
theorem integral_branch_sourceMask {n : ℕ} (j : Bool) (f : Finset (Fin n) → ℝ) :
    (∫ r, (if mainBranch r = j then f (sourceMask r) else 0) ∂sourceSeedLaw n) =
      (1 / 2 : ℝ) * bitsExpectation (fun _ : Fin n => branchRate j) univ f := by
  have h := integral_sourceSeedLaw (fun d b =>
    if b = j then f (if b then d.H ∪ d.D ∪ d.C else d.H) else 0)
  change (∫ r, (if mainBranch r = j then
    f (if mainBranch r then (mainMasks r).H ∪ (mainMasks r).D ∪ (mainMasks r).C
      else (mainMasks r).H) else 0) ∂sourceSeedLaw n) = _
  rw [h]
  cases j
  · simp only [fairParityExpectation, Bool.false_eq_true, Bool.true_eq_false,
      ↓reduceIte, add_zero]
    simp only [bitsExpectation_const]
    simp only [div_eq_mul_inv, bitsExpectation_mul_right, bitsExpectation_add]
    simp only [branchRate, Bool.false_eq_true, ↓reduceIte]
    simp only [div_eq_mul_inv, one_mul]
    ring
  · simp only [fairParityExpectation, Bool.false_eq_true, ↓reduceIte, zero_add]
    simp only [bitsExpectation_const]
    simp only [div_eq_mul_inv, bitsExpectation_mul_right, bitsExpectation_add]
    have ht := triple_mask_expectation f
    simp only [div_eq_mul_inv, one_mul] at ht ⊢
    rw [ht]
    ring

/-- Every branch/mask fiber has its explicit positive Bernoulli product mass. -/
lemma integral_sourceMask_atom {n : ℕ} (j : Bool) (P : Finset (Fin n)) :
    (∫ r, (if mainBranch r = j ∧ sourceMask r = P then (1 : ℝ) else 0)
      ∂sourceSeedLaw n) =
      (1 / 2 : ℝ) * bitsWeight (fun _ : Fin n => branchRate j) univ P := by
  classical
  simpa [bitsExpectation, ite_and] using
    integral_branch_sourceMask j (fun S => if S = P then (1 : ℝ) else 0)

lemma bitsWeight_branchRate_pos {n : ℕ} (j : Bool) (P : Finset (Fin n)) :
    0 < bitsWeight (fun _ : Fin n => branchRate j) univ P := by
  unfold bitsWeight
  apply Finset.prod_pos
  intro e he
  split_ifs
  · exact branchRate_pos j
  · exact sub_pos.mpr (branchRate_lt_one j)

lemma sourceMask_atom_real {n : ℕ} (j : Bool) (P : Finset (Fin n)) :
    (sourceSeedLaw n).real {r | mainBranch r = j ∧ sourceMask r = P} =
      (1 / 2 : ℝ) * bitsWeight (fun _ : Fin n => branchRate j) univ P := by
  classical
  rw [← integral_indicator_one (Set.to_countable _).measurableSet]
  simpa only [Set.indicator_apply, Set.mem_ofPred_eq, Pi.one_apply] using
    integral_sourceMask_atom j P

lemma sourceMask_atom {n : ℕ} (j : Bool) (P : Finset (Fin n)) :
    sourceSeedLaw n {r | mainBranch r = j ∧ sourceMask r = P} =
      ENNReal.ofReal ((1 / 2 : ℝ) * bitsWeight (fun _ : Fin n => branchRate j) univ P) := by
  rw [← sourceMask_atom_real, ofReal_measureReal]

lemma sourceMask_atom_pos {n : ℕ} (j : Bool) (P : Finset (Fin n)) :
    0 < sourceSeedLaw n {r | mainBranch r = j ∧ sourceMask r = P} := by
  rw [sourceMask_atom, ENNReal.ofReal_pos]
  exact mul_pos (by norm_num) (bitsWeight_branchRate_pos j P)

/-- The same atom identity stated directly for the source algorithm's actual
branch-tagged observation; this is the finite conditional-kernel interface. -/
theorem completeHiddenRule_joint_atom {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (j : Bool) (P : Finset (Fin n)) :
    sourceSeedLaw n {r | (mainBranch r, (completeHiddenRule M hE).mask r) = (j, P)} =
      ENNReal.ofReal ((1 / 2 : ℝ) * bitsWeight (fun _ : Fin n => branchRate j) univ P) := by
  simpa only [Prod.mk.injEq, ← sourceMask_eq_completeHiddenRule M hE] using
    sourceMask_atom j P

theorem completeHiddenRule_joint_atom_pos {n : ℕ} (M : Matroid (Fin n))
    (hE : M.E = Set.univ) (j : Bool) (P : Finset (Fin n)) :
    0 < sourceSeedLaw n {r | (mainBranch r, (completeHiddenRule M hE).mask r) = (j, P)} := by
  simpa only [Prod.mk.injEq, ← sourceMask_eq_completeHiddenRule M hE] using
    sourceMask_atom_pos j P

end MatroidProphet.Secretary

end OAI