File size: 13,255 Bytes
f18e7de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.LinearAlgebra.MatrixMultiplication.Recovery.InheritedMaskConcentration
import OAI.LinearAlgebra.MatrixMultiplication.Recovery.InheritedMasks
import OAI.LinearAlgebra.MatrixMultiplication.Recovery.InheritedStatisticWindows

namespace OAI

/-! Finite orbit symmetries, masks and exact recovery operations. -/

namespace MatrixMultiplication.PermutationMatching

open scoped BigOperators
open MatrixMultiplication.InheritedMasks
open Classical

noncomputable section

section ClassMixtures

variable {C : Type*} [Fintype C] [DecidableEq C] {P : C → Type*}
  [∀ c, Fintype (P c)] [∀ c, DecidableEq (P c)]

def classWeight (P : C → Type*) [∀ c, Fintype (P c)] (c : C) : ℝ :=
  (Fintype.card (P c) : ℝ) / populationSize P

def classDensity (A : ∀ c, Finset (P c)) (c : C) : ℝ :=
  ((A c).card : ℝ) / Fintype.card (P c)

def classProductMixture (P : C → Type*) [∀ c, Fintype (P c)]
    (left right : C → ℝ) : ℝ :=
  ∑ c, classWeight P c * (left c * right c)

omit [DecidableEq C] [∀ c, DecidableEq (P c)] in
theorem classWeight_nonneg (hm : 0 < populationSize P) (c : C) :
    0 ≤ classWeight P c := div_nonneg (Nat.cast_nonneg _) (le_of_lt hm)

omit [DecidableEq C] [∀ c, DecidableEq (P c)] in
theorem sum_classWeight (hm : 0 < populationSize P) :
    ∑ c, classWeight P c = 1 := by
  unfold classWeight
  rw [← Finset.sum_div]
  exact div_self (ne_of_gt hm)

omit [Fintype C] [DecidableEq C] [∀ c, DecidableEq (P c)] in
theorem classDensity_nonneg (A : ∀ c, Finset (P c)) (c : C) :
    0 ≤ classDensity A c := div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)

omit [Fintype C] [DecidableEq C] [∀ c, DecidableEq (P c)] in
theorem classDensity_le_one [∀ c, Nonempty (P c)]
    (A : ∀ c, Finset (P c)) (c : C) : classDensity A c ≤ 1 := by
  have hn : (0 : ℝ) < Fintype.card (P c) := by exact_mod_cast Fintype.card_pos
  apply (div_le_iff₀ hn).2
  simpa using (Nat.cast_le.mpr (Finset.card_le_univ (A c)) :
    ((A c).card : ℝ) ≤ Fintype.card (P c))

omit [DecidableEq C] in
theorem totalMatchingMean_normalized_eq [∀ c, Nonempty (P c)]
    (A B : ∀ c, Finset (P c)) (hm : 0 < populationSize P) :
    totalMatchingMean A B / populationSize P =
      classProductMixture P (classDensity A) (classDensity B) := by
  classical
  rw [totalMatchingMean_eq, Finset.sum_div]
  unfold classProductMixture
  apply Finset.sum_congr rfl
  intro c _
  have hn : (Fintype.card (P c) : ℝ) ≠ 0 := by
    exact_mod_cast (ne_of_gt (Fintype.card_pos (α := P c)))
  dsimp [classWeight, classDensity]
  field_simp [hn, ne_of_gt hm]

omit [DecidableEq C] in
theorem totalMatchingMean_prescribed_error [∀ c, Nonempty (P c)]
    (A B : ∀ c, Finset (P c)) (hm : 0 < populationSize P)
    (left right : C → ℝ) (τ : ℝ)
    (hright0 : ∀ c, 0 ≤ right c) (hright1 : ∀ c, right c ≤ 1)
    (hleft : ∀ c, |classDensity A c - left c| ≤ τ)
    (hright : ∀ c, |classDensity B c - right c| ≤ τ) :
    |totalMatchingMean A B / populationSize P -
      classProductMixture P left right| ≤ 2 * τ := by
  rw [totalMatchingMean_normalized_eq A B hm]
  have h := weighted_window (classWeight P)
    (fun c => classDensity A c * classDensity B c - left c * right c)
    0 (2 * τ) (classWeight_nonneg hm) (sum_classWeight hm) (by
      intro c
      simpa only [sub_zero] using product_coordinate_error
        (classDensity_nonneg A c) (classDensity_le_one A c)
        (hright0 c) (hright1 c) (hleft c) (hright c))
  simpa only [classProductMixture, sub_zero, mul_sub, Finset.sum_sub_distrib] using h

omit [DecidableEq C] in
theorem totalMatchingMean_inherited_margin [∀ c, Nonempty (P c)]
    (A B : ∀ c, Finset (P c)) (hm : 0 < populationSize P)
    (left right : C → ℝ) (η τ α ν : ℝ)
    (hright0 : ∀ c, 0 ≤ right c) (hright1 : ∀ c, right c ≤ 1)
    (hleft : ∀ c, |classDensity A c - left c| ≤ τ)
    (hright : ∀ c, |classDensity B c - right c| ≤ τ)
    (happrox : |classProductMixture P left right - ν| ≤ α)
    (hτ : τ ≤ η / 8) (hα : α ≤ η / 4) :
    |totalMatchingMean A B / populationSize P - ν| ≤ η / 2 := by
  have hchild := totalMatchingMean_prescribed_error A B hm left right τ
    hright0 hright1 hleft hright
  have h := inherited_margin (actual := ν)
    (expected := classProductMixture P left right)
    (prescribed := totalMatchingMean A B / populationSize P)
    (by simpa only [abs_sub_comm] using hchild)
    (by simpa only [abs_sub_comm] using happrox) hτ hα
  simpa only [abs_sub_comm] using h

theorem inheritedMask_rejection_of_windows_le [∀ c, Nonempty (P c)]
    (A B : ∀ c, Finset (P c)) (hn : ∀ c, 2 ≤ Fintype.card (P c))
    (hm : 0 < populationSize P) (left right : C → ℝ) (η τ α ν : ℝ)
    (hη : 0 < η)
    (hright0 : ∀ c, 0 ≤ right c) (hright1 : ∀ c, right c ≤ 1)
    (hleft : ∀ c, |classDensity A c - left c| ≤ τ)
    (hright : ∀ c, |classDensity B c - right c| ≤ τ)
    (happrox : |classProductMixture P left right - ν| ≤ α)
    (hτ : τ ≤ η / 8) (hα : α ≤ η / 4) :
    average (fun p : ClassPermutations P =>
      if η < |totalMatchingCount A B p / populationSize P - ν| then 1 else 0) ≤
        1 / (2 * populationSize P * η ^ 2) := by
  exact inheritedMask_rejection_le A B hn hm η ν hη
    (totalMatchingMean_inherited_margin A B hm left right η τ α ν
      hright0 hright1 hleft hright happrox hτ hα)

theorem twoHalf_inheritedMask_rejection_of_windows_le [∀ c, Nonempty (P c)]
    (A B : ∀ c, Finset (P c)) (hn : ∀ c, 2 ≤ Fintype.card (P c))
    (hm : 0 < populationSize P) (left right : C → ℝ) (η τ α ν : ℝ)
    (hη : 0 < η)
    (hright0 : ∀ c, 0 ≤ right c) (hright1 : ∀ c, right c ≤ 1)
    (hleft : ∀ c, |classDensity A c - left c| ≤ τ)
    (hright : ∀ c, |classDensity B c - right c| ≤ τ)
    (happrox : |classProductMixture P left right - ν| ≤ α)
    (hτ : τ ≤ η / 8) (hα : α ≤ η / 4) :
    average (fun p : ClassPermutations P × ClassPermutations P =>
      if η < |totalTwoHalfCount A B p / populationSize P - ν| then 1 else 0) ≤
        1 / (2 * populationSize P * η ^ 2) := by
  exact twoHalf_inheritedMask_rejection_le A B hn hm η ν hη
    (totalMatchingMean_inherited_margin A B hm left right η τ α ν
      hright0 hright1 hleft hright happrox hτ hα)

theorem selectedTwoHalfMask_rejection_of_windows_le
    (D : Finset C) (A B : ∀ c, Finset (P c))
    (hn : ∀ c ∈ D, 2 ≤ Fintype.card (P c))
    (hm : 0 < populationSize (fun c : D => P c))
    (left right : C → ℝ) (η τ α ν : ℝ) (hη : 0 < η)
    (hright0 : ∀ c ∈ D, 0 ≤ right c) (hright1 : ∀ c ∈ D, right c ≤ 1)
    (hleft : ∀ c ∈ D, |classDensity A c - left c| ≤ τ)
    (hright : ∀ c ∈ D, |classDensity B c - right c| ≤ τ)
    (happrox : |classProductMixture (fun c : D => P c)
      (fun c => left c) (fun c => right c) - ν| ≤ α)
    (hτ : τ ≤ η / 8) (hα : α ≤ η / 4) :
    average (fun p : ClassPermutations P × ClassPermutations P =>
      if η < |selectedTwoHalfCount D A B p /
        populationSize (fun c : D => P c) - ν| then 1 else 0) ≤
      1 / (2 * populationSize (fun c : D => P c) * η ^ 2) := by
  let : ∀ c : D, Nonempty (P c) := fun c =>
    Fintype.card_pos_iff.mp (lt_of_lt_of_le (by decide : 0 < 2) (hn c c.property))
  apply selectedTwoHalfMask_rejection_le D A B hn hm η ν hη
  exact totalMatchingMean_inherited_margin (fun c : D => A c) (fun c : D => B c)
    hm (fun c => left c) (fun c => right c) η τ α ν
    (fun c => hright0 c c.property) (fun c => hright1 c c.property)
    (fun c => hleft c c.property) (fun c => hright c c.property) happrox hτ hα

end ClassMixtures

section CompleteWordStatistics

variable {C : Type*} [Fintype C] [DecidableEq C] {P X Y S T : C → Type*}
  [∀ c, Fintype (P c)] [∀ c, DecidableEq (P c)]
  [∀ c, Fintype (S c)] [∀ c, DecidableEq (S c)]
  [∀ c, Fintype (T c)] [∀ c, DecidableEq (T c)]

omit [Fintype C] [DecidableEq C] [∀ c, DecidableEq (P c)] in
theorem classDensity_statisticPositions (w : ∀ c, P c → X c)
    (statistic : ∀ c, X c → S c) (s : ∀ c, S c) (c : C) :
    classDensity (fun c => statisticPositions (w c) (statistic c) (s c)) c =
      empiricalLaw (statistic c ∘ w c) (s c) := by
  rw [classDensity, statisticPositions_card, empiricalLaw]

omit [DecidableEq C] in
theorem totalMatchingMean_statistic_eq [∀ c, Nonempty (P c)]
    (w : ∀ c, P c → X c) (v : ∀ c, P c → Y c)
    (leftStat : ∀ c, X c → S c) (rightStat : ∀ c, Y c → T c)
    (s : ∀ c, S c) (t : ∀ c, T c) (hm : 0 < populationSize P) :
    totalMatchingMean (fun c => statisticPositions (w c) (leftStat c) (s c))
        (fun c => statisticPositions (v c) (rightStat c) (t c)) / populationSize P =
      classProductMixture P
        (fun c => empiricalLaw (leftStat c ∘ w c) (s c))
        (fun c => empiricalLaw (rightStat c ∘ v c) (t c)) := by
  rw [totalMatchingMean_normalized_eq _ _ hm]
  simp only [classProductMixture, classDensity_statisticPositions]

theorem twoHalf_statistic_rejection_of_typeWindows_le [∀ c, Nonempty (P c)]
    (w : ∀ c, P c → X c) (v : ∀ c, P c → Y c)
    (leftStat : ∀ c, X c → S c) (rightStat : ∀ c, Y c → T c)
    (s : ∀ c, S c) (t : ∀ c, T c)
    (hn : ∀ c, 2 ≤ Fintype.card (P c)) (hm : 0 < populationSize P)
    (leftLaw : ∀ c, S c → ℝ) (rightLaw : ∀ c, T c → ℝ)
    (η τ α ν : ℝ) (hη : 0 < η)
    (hright0 : ∀ c, 0 ≤ rightLaw c (t c))
    (hright1 : ∀ c, rightLaw c (t c) ≤ 1)
    (hleft : ∀ c, typeWindow (leftLaw c) τ (leftStat c ∘ w c))
    (hright : ∀ c, typeWindow (rightLaw c) τ (rightStat c ∘ v c))
    (happrox : |classProductMixture P
      (fun c => leftLaw c (s c)) (fun c => rightLaw c (t c)) - ν| ≤ α)
    (hτ : τ ≤ η / 8) (hα : α ≤ η / 4) :
    average (fun p : ClassPermutations P × ClassPermutations P =>
      if η < |totalTwoHalfCount
          (fun c => statisticPositions (w c) (leftStat c) (s c))
          (fun c => statisticPositions (v c) (rightStat c) (t c)) p /
          populationSize P - ν| then 1 else 0) ≤
        1 / (2 * populationSize P * η ^ 2) := by
  apply twoHalf_inheritedMask_rejection_of_windows_le _ _ hn hm
    (fun c => leftLaw c (s c)) (fun c => rightLaw c (t c)) η τ α ν hη
    hright0 hright1
  · intro c
    simpa only [classDensity_statisticPositions] using hleft c (s c)
  · intro c
    simpa only [classDensity_statisticPositions] using hright c (t c)
  · exact happrox
  · exact hτ
  · exact hα

theorem selectedTwoHalf_statistic_rejection_of_completeWindows_le
    [∀ c, Fintype (X c)] [∀ c, DecidableEq (X c)]
    [∀ c, Fintype (Y c)] [∀ c, DecidableEq (Y c)]
    (D : Finset C) (w : ∀ c, P c → X c) (v : ∀ c, P c → Y c)
    (leftStat : ∀ c, X c → S c) (rightStat : ∀ c, Y c → T c)
    (s : ∀ c, S c) (t : ∀ c, T c)
    (hn : ∀ c ∈ D, 2 ≤ Fintype.card (P c))
    (hm : 0 < populationSize (fun c : D => P c))
    (leftLaw : ∀ c, X c → ℝ) (rightLaw : ∀ c, Y c → ℝ)
    (leftε rightε : C → ℝ) (η α ν : ℝ) (hη : 0 < η)
    (hright0 : ∀ c ∈ D, ∀ y, 0 ≤ rightLaw c y)
    (hrightSum : ∀ c ∈ D, ∑ y, rightLaw c y = 1)
    (hleftε : ∀ c ∈ D, 0 ≤ leftε c) (hrightε : ∀ c ∈ D, 0 ≤ rightε c)
    (hleft : ∀ c ∈ D, typeWindow (leftLaw c) (leftε c) (w c))
    (hright : ∀ c ∈ D, typeWindow (rightLaw c) (rightε c) (v c))
    (hleftFactor : ∀ c ∈ D, (Fintype.card (X c) : ℝ) * leftε c ≤ η / 8)
    (hrightFactor : ∀ c ∈ D, (Fintype.card (Y c) : ℝ) * rightε c ≤ η / 8)
    (happrox : |classProductMixture (fun c : D => P c)
      (fun c => pushforwardLaw (leftStat c) (leftLaw c) (s c))
      (fun c => pushforwardLaw (rightStat c) (rightLaw c) (t c)) - ν| ≤ α)
    (hα : α ≤ η / 4) :
    average (fun p : ClassPermutations P × ClassPermutations P =>
      if η < |selectedTwoHalfCount D
          (fun c => statisticPositions (w c) (leftStat c) (s c))
          (fun c => statisticPositions (v c) (rightStat c) (t c)) p /
          populationSize (fun c : D => P c) - ν| then 1 else 0) ≤
        1 / (2 * populationSize (fun c : D => P c) * η ^ 2) := by
  apply selectedTwoHalfMask_rejection_of_windows_le D _ _ hn hm
    (fun c => pushforwardLaw (leftStat c) (leftLaw c) (s c))
    (fun c => pushforwardLaw (rightStat c) (rightLaw c) (t c))
    η (η / 8) α ν hη
  · intro c hc
    exact pushforwardLaw_nonneg (rightStat c) (rightLaw c) (hright0 c hc) (t c)
  · intro c hc
    exact pushforwardLaw_le_one (rightStat c) (rightLaw c)
      (hright0 c hc) (hrightSum c hc) (t c)
  · intro c hc
    rw [classDensity_statisticPositions]
    exact (typeWindow_statistic (leftLaw c) (leftε c) (w c) (leftStat c)
      (hleftε c hc) (hleft c hc) (s c)).trans (hleftFactor c hc)
  · intro c hc
    rw [classDensity_statisticPositions]
    exact (typeWindow_statistic (rightLaw c) (rightε c) (v c) (rightStat c)
      (hrightε c hc) (hright c hc) (t c)).trans (hrightFactor c hc)
  · exact happrox
  · exact le_rfl
  · exact hα

end CompleteWordStatistics

end

end MatrixMultiplication.PermutationMatching

end OAI