File size: 11,358 Bytes
2f887db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Computability.PerfectCompleteness.Decoding.BucketUsefulCollision
import OAI.Computability.PerfectCompleteness.Foundations.HierarchicalAgreementMean
import OAI.Computability.PerfectCompleteness.Reduction.CompletionSoundness

namespace OAI

section

namespace PerfectCompleteness.HierarchicalUsefulCollision

noncomputable section

open scoped BigOperators Classical
open TreeSourceSpaces HierarchicalArrays
open UniqueGamesTheorem.Foundations.Games
open UniqueGamesTheorem.Appendix.RankLevelFilter (linearMapFintype)

attribute [local instance] linearMapFintype

private theorem probability_product {A B : Type*} [Fintype A] [Fintype B]
    (μ : FiniteDistribution A) (ν : FiniteDistribution B) (event : A × B → Bool) :
    (μ.product ν).probability event =
      μ.expectation (fun a => ν.probability (fun b => event (a, b))) := by
  simp only [FiniteDistribution.probability, FiniteDistribution.expectation,
    FiniteDistribution.product, Fintype.sum_prod_type, Finset.mul_sum, mul_ite, mul_zero]

private theorem probability_product_first {A B : Type*} [Fintype A] [Fintype B]
    (μ : FiniteDistribution A) (ν : FiniteDistribution B) (event : A → Bool) :
    (μ.product ν).probability (fun x => event x.1) = μ.probability event := by
  unfold FiniteDistribution.probability
  rw [Fintype.sum_prod_type]
  apply Finset.sum_congr rfl
  intro a _
  cases he : event a <;>
    simp [FiniteDistribution.product, he, ← Finset.mul_sum, ν.normalized]

variable {branch rows : Nat → Nat} {n t : Nat}
  (slots : RecursiveSpaces.Slots branch n → Fin t → MixedSupport.Slot)
  (upper : Nodes branch n)

abbrev Background := HierarchicalAgreementMean.Background (rows := rows) slots upper
abbrev Matrix := HierarchicalAgreementMean.Matrix (rows := rows) slots upper
abbrev Direction := BucketSampler.Direction (rows (Nodes.height upper))
abbrev Tape := BucketSampler.Tape (rows (Nodes.height upper)) (NodeEmbedding.RowSpace slots upper)

local instance backgroundFintype : Fintype (Background (rows := rows) slots upper) :=
  Fintype.ofFinite _

local instance rowSpaceFintype : Fintype (NodeEmbedding.RowSpace slots upper) :=
  Fintype.ofFinite _

local instance valueFintype :
    Fintype (Block rows upper × HierarchicalMatrixTable.SideOutput (rows := rows) upper) :=
  Fintype.ofFinite _

def directionLaw (hrows : 0 < rows (Nodes.height upper)) :
    FiniteDistribution (Direction (rows := rows) upper) := by
  letI : Nonempty (Direction (rows := rows) upper) :=
    ⟨BucketUniform.coordinateDirection ⟨0, hrows⟩⟩
  exact FiniteDistribution.uniform _

def bucketLaw (ν : FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    FiniteDistribution (HierarchicalAgreementMean.BucketSample (rows := rows) slots upper) :=
  (directionLaw upper hrows).product
    ((BucketSampler.tapeLaw (rows (Nodes.height upper)) ν).product ν)

variable {P : Type*} [Fintype P]

abbrev Sample := (_ : P) × HierarchicalAgreementMean.BucketSample (rows := rows) slots upper

def law (externalLaw : FiniteDistribution P)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    FiniteDistribution (Sample (P := P) (rows := rows) slots upper) :=
  CompletionSoundness.sigmaLaw externalLaw (fun p => bucketLaw slots upper (scalarLaw p) hrows)

def pairRecord (background : P → Background (rows := rows) slots upper)
    (sample : Sample (P := P) (rows := rows) slots upper) :
    HierarchicalAgreementMean.PairRecord (rows := rows) slots upper :=
  HierarchicalAgreementMean.pairRecord slots upper (background sample.1, sample.2)

def pairLaw (externalLaw : FiniteDistribution P)
    (background : P → Background (rows := rows) slots upper)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    FiniteDistribution (HierarchicalAgreementMean.PairRecord (rows := rows) slots upper) :=
  (law slots upper externalLaw scalarLaw hrows).pushforward (pairRecord slots upper background)

variable (lowerLevel : Nat) {Ω : Type*} [Fintype Ω]
  (original : FiniteDistribution Ω) (arrays : Ω → Arrays slots rows)
  (lower : Ω → Bool) (κ : ℝ)
  (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))

def usefulAccepted (background : Background (rows := rows) slots upper)
    (a : Direction (rows := rows) upper) (tape : Tape (rows := rows) slots upper) : Bool :=
  decide (CanonicalMatrixTable.Accepts (TreeCanonical.numberedSlots slots)
    (NodeEmbedding.RowSpace slots upper) (HierarchicalMatrixTable.other slots upper background)
    σ a.val (BucketMatrixResampling.assembledMatrix (NodeEmbedding.RowSpace slots upper)
      (rows (Nodes.height upper)) tape)) &&
    (HierarchicalUsefulness.table slots upper lowerLevel original arrays lower κ σ background
      (MatrixRowQuotient.projectMatrix
        (HierarchicalFrozenTables.knownRows slots upper lowerLevel background)
        (BucketMatrixResampling.assembledMatrix (NodeEmbedding.RowSpace slots upper)
          (rows (Nodes.height upper)) tape))).isSome

def usefulEvent (background : P → Background (rows := rows) slots upper)
    (sample : Sample (P := P) (rows := rows) slots upper) : Bool :=
  usefulAccepted slots upper lowerLevel original arrays lower κ σ
    (background sample.1) sample.2.1 sample.2.2.1

theorem direction_collision_lower_bound
    (background : Background (rows := rows) slots upper)
    (ν : FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (a : Direction (rows := rows) upper) :
    (BucketSampler.tapeLaw (rows (Nodes.height upper)) ν).probability
        (usefulAccepted slots upper lowerLevel original arrays lower κ σ background a) ^ 2 / 2 ≤
      ((BucketSampler.tapeLaw (rows (Nodes.height upper)) ν).product ν).probability
        (fun z => HierarchicalAgreementMean.collision slots upper lowerLevel
          original arrays lower κ σ
          (HierarchicalAgreementMean.pairRecord slots upper (background, (a, z)))) := by
  exact BucketUsefulCollision.collision_probability_lower_bound
    (TreeCanonical.numberedSlots slots) (NodeEmbedding.RowSpace slots upper)
    (HierarchicalMatrixTable.other slots upper background) σ
    (HierarchicalFrozenTables.knownRows slots upper lowerLevel background)
    (HierarchicalFrozenTables.sectionMap slots upper lowerLevel background)
    (HierarchicalFrozenTables.sectionMap_spec slots upper lowerLevel background)
    (HierarchicalFrozenTables.determined slots upper lowerLevel background) ν
    (fun X => HierarchicalUsefulness.mark slots upper lowerLevel original arrays lower κ
      ⟨background, X⟩ = true) a

theorem useful_probability_eq
    (externalLaw : FiniteDistribution P)
    (background : P → Background (rows := rows) slots upper)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    (law slots upper externalLaw scalarLaw hrows).probability
        (usefulEvent slots upper lowerLevel original arrays lower κ σ background) =
      externalLaw.expectation (fun p => (directionLaw upper hrows).expectation (fun a =>
        (BucketSampler.tapeLaw (rows (Nodes.height upper)) (scalarLaw p)).probability
          (usefulAccepted slots upper lowerLevel original arrays lower κ σ (background p) a))) := by
  rw [law, CompletionSoundness.sigmaLaw_probability]
  apply FiniteDistribution.expectation_congr
  intro p
  rw [bucketLaw, probability_product]
  apply FiniteDistribution.expectation_congr
  intro a
  exact probability_product_first
    (BucketSampler.tapeLaw (rows (Nodes.height upper)) (scalarLaw p)) (scalarLaw p)
    (usefulAccepted slots upper lowerLevel original arrays lower κ σ (background p) a)

theorem collision_probability_eq
    (externalLaw : FiniteDistribution P)
    (background : P → Background (rows := rows) slots upper)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    (pairLaw slots upper externalLaw background scalarLaw hrows).probability
        (HierarchicalAgreementMean.collision slots upper lowerLevel original arrays lower κ σ) =
      externalLaw.expectation (fun p => (directionLaw upper hrows).expectation (fun a =>
        ((BucketSampler.tapeLaw (rows (Nodes.height upper)) (scalarLaw p)).product
          (scalarLaw p)).probability (fun z =>
            HierarchicalAgreementMean.collision slots upper lowerLevel original arrays lower κ σ
              (HierarchicalAgreementMean.pairRecord slots upper (background p, (a, z)))))) := by
  rw [pairLaw, FiniteDistribution.probability_pushforward, law,
    CompletionSoundness.sigmaLaw_probability]
  apply FiniteDistribution.expectation_congr
  intro p
  exact probability_product (directionLaw upper hrows)
    ((BucketSampler.tapeLaw (rows (Nodes.height upper)) (scalarLaw p)).product (scalarLaw p))
    (fun z => HierarchicalAgreementMean.collision slots upper lowerLevel original arrays lower κ σ
      (HierarchicalAgreementMean.pairRecord slots upper (background p, z)))

theorem collision_probability_lower_bound
    (externalLaw : FiniteDistribution P)
    (background : P → Background (rows := rows) slots upper)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) :
    (law slots upper externalLaw scalarLaw hrows).probability
        (usefulEvent slots upper lowerLevel original arrays lower κ σ background) ^ 2 / 2 ≤
      (pairLaw slots upper externalLaw background scalarLaw hrows).probability
        (HierarchicalAgreementMean.collision slots upper lowerLevel original arrays lower κ σ) := by
  rw [useful_probability_eq, collision_probability_eq]
  apply CollisionAveraging.average_square_bound
  intro p
  apply CollisionAveraging.average_square_bound
  intro a
  exact direction_collision_lower_bound slots upper lowerLevel original arrays lower κ σ
    (background p) (scalarLaw p) a

theorem collision_probability_ge_eighth
    (externalLaw : FiniteDistribution P)
    (background : P → Background (rows := rows) slots upper)
    (scalarLaw : P → FiniteDistribution (NodeEmbedding.RowSpace slots upper))
    (hrows : 0 < rows (Nodes.height upper)) (c : ℝ) (hc : 0 ≤ c)
    (hmass : c / 2 ≤ (law slots upper externalLaw scalarLaw hrows).probability
      (usefulEvent slots upper lowerLevel original arrays lower κ σ background)) :
    c ^ 2 / 8 ≤
      (pairLaw slots upper externalLaw background scalarLaw hrows).probability
        (HierarchicalAgreementMean.collision slots upper lowerLevel original arrays lower κ σ) := by
  have h := collision_probability_lower_bound slots upper lowerLevel original arrays lower κ σ
    externalLaw background scalarLaw hrows
  have hprod : 0 ≤
      ((law slots upper externalLaw scalarLaw hrows).probability
        (usefulEvent slots upper lowerLevel original arrays lower κ σ background) - c / 2) *
      ((law slots upper externalLaw scalarLaw hrows).probability
        (usefulEvent slots upper lowerLevel original arrays lower κ σ background) + c / 2) :=
    mul_nonneg (sub_nonneg.mpr hmass) (by linarith)
  nlinarith

end
end PerfectCompleteness.HierarchicalUsefulCollision

end

end OAI