File size: 12,472 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
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
import OAI.Computability.PerfectCompleteness.Decoding.HierarchicalLeftDecoder
import OAI.Computability.PerfectCompleteness.Foundations.MultiplicationFormInjectiveLemmas
import OAI.Computability.PerfectCompleteness.Repetition.CleanConditioning

namespace OAI

section

namespace PerfectCompleteness.HierarchicalDecoderTables

noncomputable section

open scoped Classical
open TreeSourceSpaces HierarchicalArrays PointwiseSpaces
open UniqueGamesTheorem.Foundations.Games

attribute [local instance] UniqueGamesTheorem.Appendix.RankLevelFilter.linearMapFintype

section ConstantValidity

variable {Q A Ω : Type*} [Fintype Q] [DecidableEq Q] [Fintype A] [Fintype Ω]

omit [Fintype Q] [DecidableEq Q] in
private theorem constant_row_event_eq (valid : A → Prop) (q : Q) :
    (fun answer : Option A => decide
      (DecoderTableAdmissibility.RowValid (fun (_ : Q) => valid) q answer)) =
      (fun answer : Option A => decide (∀ z, answer = some z → valid z)) := by
  funext answer
  exact (@decide_eq_decide
    (DecoderTableAdmissibility.RowValid (fun (_ : Q) => valid) q answer)
    (∀ z, answer = some z → valid z) _ _).mpr Iff.rfl

private theorem table_admissible_of_constant_probability_one
    (responses : Q → FiniteDistribution (Option A)) (valid : A → Prop)
    (hvalid : ∀ q, (responses q).probability
      (fun answer => decide (∀ z, answer = some z → valid z)) = 1)
    (table : Q → Option A)
    (hsupport : (FiniteDistribution.table responses).weight table ≠ 0) :
    DecoderTableAdmissibility.Admissible (fun (_ : Q) => valid) table := by
  apply DecoderTableAdmissibility.table_admissible_of_probability_one
    responses (fun (_ : Q) => valid) _ table hsupport
  intro q
  exact (congrArg (responses q).probability (constant_row_event_eq valid q)).trans (hvalid q)

private theorem hit_square_le_of_constant_probability_one
    (responses : Q → FiniteDistribution (Option A))
    (ν : FiniteDistribution Ω) (ownInput : Ω → Q) (right : A)
    (valid : A → Prop)
    (hvalid : ∀ q, (responses q).probability
      (fun answer => decide (∀ z, answer = some z → valid z)) = 1)
    (bound : ℝ)
    (hbound : ∀ table : Q → Option A,
      DecoderTableAdmissibility.Admissible (fun (_ : Q) => valid) table →
      StochasticSingleResponse.tableCollision ν ownInput table ≤ bound) :
    StochasticSingleResponse.hit responses ν ownInput right ^ 2 ≤ bound := by
  apply StochasticSingleResponse.hit_square_le_of_probability_one
    responses ν ownInput right (fun (_ : Q) => valid) _ bound hbound
  intro q
  exact (congrArg (responses q).probability (constant_row_event_eq valid q)).trans (hvalid q)

end ConstantValidity

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

local instance rowSpaceFintype (node : Nodes branch n) :
    Fintype (NodeEmbedding.RowSpace slots node) := Fintype.ofFinite _

local instance nodeSpaceFintype (node : Nodes branch n) :
    Fintype (NodeEmbedding.NodeH slots node) := Fintype.ofFinite _

local instance upperDualFintype :
    Fintype (Module.Dual F2 (NodeEmbedding.RowSpace slots upper)) :=
  LeftDecoder.dualFintype (V := NodeEmbedding.RowSpace slots upper)

abbrev Advice (r : Nat) :=
  ManyGoodRows.RowMap (Block rows upper) r ×
    (Module.Dual F2 (NodeEmbedding.RowSpace slots upper ⧸
      HierarchicalFrozenTables.knownRows slots upper lowerLevel background) →ₗ[F2]
      (Fin r → F2))

local instance adviceFintype (r : Nat) :
    Fintype (Advice slots upper lowerLevel background r) := by
  letI : Fintype (Module.Dual F2 (NodeEmbedding.RowSpace slots upper ⧸
      HierarchicalFrozenTables.knownRows slots upper lowerLevel background)) :=
    LeftDecoder.dualFintype
  infer_instance

variable (hbranch : ∀ k < n, 0 < branch k)
  (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))
  (useful : HierarchicalFrozenTables.QuotientMatrix slots upper lowerLevel background → Prop)

abbrev LowerH (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) :=
  NodeEmbedding.NodeH slots (HierarchicalLeftDecoder.LowerNode upper lowerLevel d)

abbrev Answer (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) :=
  Module.Dual F2 (squareSpace (LowerH slots upper lowerLevel d))

local instance answerFintype (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) :
    Fintype (Answer slots upper lowerLevel d) :=
  LeftDecoder.dualFintype (V := squareSpace (LowerH slots upper lowerLevel d))

def fullRank (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel)
    (z : Answer slots upper lowerLevel d) : Nat :=
  OddListExtraction.formRank (LowerH slots upper lowerLevel d)
    (OddListExtraction.multiplicationForm (LowerH slots upper lowerLevel d) z)

def decode (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (q : Module.Dual F2 (NodeEmbedding.RowSpace slots upper)) :
    Option (Answer slots upper lowerLevel d) :=
  let z := HierarchicalLeftDecoder.output slots upper lowerLevel hbranch d q
  if fullRank slots upper lowerLevel d z ≤ s then none else some z

def responseLaw (r : Nat) (ρ : ℝ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (advice : Advice slots upper lowerLevel background r) :
    FiniteDistribution (Option (Answer slots upper lowerLevel d)) :=
  (HierarchicalLeftDecoder.adviceLaw slots upper lowerLevel background σ useful r ρ
    advice.1 advice.2).pushforward (decode slots upper lowerLevel hbranch d s)

def Valid (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (z : Answer slots upper lowerLevel d) : Prop :=
  z (HierarchicalLeftDecoder.lowerOne slots upper lowerLevel hbranch d) = 1 ∧
    (LowerAffineSliceRank.testedGram
      (FunctionSpaceLowerRank.matrixForm (LowerH slots upper lowerLevel d)
        (OddListExtraction.multiplicationForm (LowerH slots upper lowerLevel d) z))
      (HierarchicalLeftDecoder.testedMatrix slots upper lowerLevel background d)).rank ≤ 1 ∧
    s < fullRank slots upper lowerLevel d z

theorem decode_valid
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (q : Module.Dual F2 (NodeEmbedding.RowSpace slots upper))
    (hq : HierarchicalLeftDecoder.Valid slots upper lowerLevel hbranch background q)
    (z : Answer slots upper lowerLevel d)
    (hz : decode slots upper lowerLevel hbranch d s q = some z) :
    Valid slots upper lowerLevel background hbranch d s z := by
  change (if fullRank slots upper lowerLevel d
      (HierarchicalLeftDecoder.output slots upper lowerLevel hbranch d q) ≤ s then none
    else some (HierarchicalLeftDecoder.output slots upper lowerLevel hbranch d q)) = some z at hz
  split at hz
  · cases hz
  · rename_i hrank
    have heq := Option.some.inj hz
    subst z
    exact ⟨(hq d).1, (hq d).2, Nat.lt_of_not_ge hrank⟩

theorem responseLaw_valid (r : Nat) (ρ : ℝ) (hρ : 0 < ρ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (advice : Advice slots upper lowerLevel background r) :
    (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s advice).probability
      (fun answer => decide (∀ z, answer = some z →
        Valid slots upper lowerLevel background hbranch d s z)) = 1 := by
  rw [responseLaw, FiniteDistribution.probability_pushforward]
  apply le_antisymm (FiniteDistribution.probability_le_one _ _)
  rw [← HierarchicalLeftDecoder.adviceLaw_valid slots upper lowerLevel hbranch background
    σ useful r ρ hρ advice.1 advice.2]
  apply FiniteDistribution.probability_mono
  intro q hq
  apply decide_eq_true
  intro z hz
  exact decode_valid slots upper lowerLevel background hbranch d s q
    (of_decide_eq_true hq) z hz

def tableLaw (r : Nat) (ρ : ℝ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat) :
    FiniteDistribution (Advice slots upper lowerLevel background r →
      Option (Answer slots upper lowerLevel d)) :=
  FiniteDistribution.table
    (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s)

def upperTableLaw (r : Nat) (ρ : ℝ) :
    FiniteDistribution (Advice slots upper lowerLevel background r →
      Module.Dual F2 (NodeEmbedding.RowSpace slots upper)) :=
  FiniteDistribution.table (fun advice : Advice slots upper lowerLevel background r =>
    HierarchicalLeftDecoder.adviceLaw slots upper lowerLevel background σ useful
      r ρ advice.1 advice.2)

theorem upperTableLaw_pushforward (r : Nat) (ρ : ℝ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat) :
    (upperTableLaw slots upper lowerLevel background σ useful r ρ).pushforward
      (fun table advice => decode slots upper lowerLevel hbranch d s (table advice)) =
        tableLaw slots upper lowerLevel background hbranch σ useful r ρ d s := by
  exact CleanConditioning.pushforward_law
    (fun advice : Advice slots upper lowerLevel background r =>
      HierarchicalLeftDecoder.adviceLaw slots upper lowerLevel background σ useful
        r ρ advice.1 advice.2)
    (fun _ => decode slots upper lowerLevel hbranch d s)

theorem supported_table_valid (r : Nat) (ρ : ℝ) (hρ : 0 < ρ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (table : Advice slots upper lowerLevel background r → Option (Answer slots upper lowerLevel d))
    (hsupport : (tableLaw slots upper lowerLevel background hbranch σ useful r ρ d s).weight table ≠ 0) :
    DecoderTableAdmissibility.Admissible
      (Q := Advice slots upper lowerLevel background r)
      (A := Answer slots upper lowerLevel d)
      (fun (_ : Advice slots upper lowerLevel background r)
        (z : Answer slots upper lowerLevel d) =>
        Valid slots upper lowerLevel background hbranch d s z) table := by
  apply table_admissible_of_constant_probability_one
    (Q := Advice slots upper lowerLevel background r)
    (A := Answer slots upper lowerLevel d)
    (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s)
    (Valid slots upper lowerLevel background hbranch d s)
    _ table hsupport
  intro advice
  rw [← responseLaw_valid slots upper lowerLevel background hbranch σ useful r ρ hρ d s advice]
  apply congrArg (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s
    advice).probability
  funext answer
  exact (@decide_eq_decide _ _ _ _).mpr Iff.rfl

theorem hit_square_le {Ω : Type*} [Fintype Ω]
    (r : Nat) (ρ : ℝ) (hρ : 0 < ρ)
    (d : HierarchicalFrozenTables.LowerNodes upper lowerLevel) (s : Nat)
    (ν : FiniteDistribution Ω) (ownInput : Ω → Advice slots upper lowerLevel background r)
    (right : Answer slots upper lowerLevel d) (bound : ℝ)
    (hbound : ∀ table : Advice slots upper lowerLevel background r →
        Option (Answer slots upper lowerLevel d),
      DecoderTableAdmissibility.Admissible
        (Q := Advice slots upper lowerLevel background r)
        (A := Answer slots upper lowerLevel d)
        (fun (_ : Advice slots upper lowerLevel background r)
          (z : Answer slots upper lowerLevel d) =>
          Valid slots upper lowerLevel background hbranch d s z) table →
      StochasticSingleResponse.tableCollision
        (Q := Advice slots upper lowerLevel background r)
        (A := Answer slots upper lowerLevel d) (Ω := Ω) ν ownInput table ≤ bound) :
    StochasticSingleResponse.hit
      (Q := Advice slots upper lowerLevel background r)
      (A := Answer slots upper lowerLevel d) (Ω := Ω)
      (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s)
      ν ownInput right ^ 2 ≤ bound := by
  apply hit_square_le_of_constant_probability_one
    (Q := Advice slots upper lowerLevel background r)
    (A := Answer slots upper lowerLevel d) (Ω := Ω)
    (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s)
    ν ownInput right (Valid slots upper lowerLevel background hbranch d s)
    _ bound hbound
  intro advice
  rw [← responseLaw_valid slots upper lowerLevel background hbranch σ useful r ρ hρ d s advice]
  apply congrArg (responseLaw slots upper lowerLevel background hbranch σ useful r ρ d s
    advice).probability
  funext answer
  exact (@decide_eq_decide _ _ _ _).mpr Iff.rfl

end
end PerfectCompleteness.HierarchicalDecoderTables

end

end OAI