File size: 20,148 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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import OAI.Computability.PerfectCompleteness.Decoding.CleanDecoderSeedLawLemmas
import OAI.Computability.PerfectCompleteness.Decoding.CleanRecordProjection
import OAI.Computability.PerfectCompleteness.Foundations.WholeReplaySubtreeLemmas
import OAI.Computability.PerfectCompleteness.Machines.WholeArrayInteriorOwnInputLaw
import OAI.Computability.PerfectCompleteness.Repetition.CleanNativeReplay

namespace OAI

section

namespace PerfectCompleteness.CleanPhysicalDecoderLaw

noncomputable section

open scoped Classical
open RecursiveSpaces DescendantSpaces TreeSourceSpaces HierarchicalArrays
open UniqueGamesTheorem.Foundations.Games

abbrev F2 := ZMod 2

attribute [local instance] RightDecoder.scalarFintype

local instance nativeLeftFintype {branch : Nat → Nat} {n t : Nat}
    (slots : Slots branch n → Fin t → MixedSupport.Slot) (upper : Nodes branch n) :
    Fintype (Module.Dual F2 (NodeEmbedding.RowSpace slots upper)) :=
  LeftDecoder.dualFintype (V := NodeEmbedding.RowSpace slots upper)

section NativeData

variable {branch rows repeats : Nat → Nat} {n t : Nat}

def inputOfArrays (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (upper lower : Nodes branch n) (W : Submodule F2 (Block rows upper))
    (a : Block rows lower)
    (known : HiddenBucketBias.VisibleDirection W → H (nodeSlots slots upper))
    (arrays : Arrays slots rows) : OwnInputReference.Input slots rows upper lower W a where
  knownBuckets := known
  otherArrays node := arrays node.val
  lowerQuotient x := DirectionQuotient.proj a (fun row => (arrays lower row).val x)

private theorem inputOfArrays_heq
    (slots target : Slots branch n → Fin t → MixedSupport.Slot) (hs : slots = target)
    (upper lower : Nodes branch n) (W : Submodule F2 (Block rows upper))
    (a : Block rows lower)
    (known : HiddenBucketBias.VisibleDirection W → H (nodeSlots slots upper))
    (otherKnown : HiddenBucketBias.VisibleDirection W → H (nodeSlots target upper))
    (hk : HEq known otherKnown) (arrays : Arrays slots rows) (other : Arrays target rows)
    (ha : HEq arrays other) :
    HEq (inputOfArrays slots upper lower W a known arrays)
      (inputOfArrays target upper lower W a otherKnown other) := by
  cases hs
  cases eq_of_heq hk
  cases eq_of_heq ha
  rfl

private theorem replayKnown_heq {h : Nat}
    (slots target : Slots branch n → Fin t → MixedSupport.Slot) (hs : slots = target)
    (upper : Nodes branch n) (p : Path branch (Nodes.height upper) (h + 1))
    (hp : h + 1 < Nodes.height upper) (clean : Fin (branch h) → Prop)
    (W : Submodule F2 (Block rows upper))
    (tape : WholeCutReplay.Tape rows repeats ((Nodes.path upper).append p) slots clean)
    (other : WholeCutReplay.Tape rows repeats ((Nodes.path upper).append p) target clean)
    (ht : HEq tape other) :
    HEq (WholeReplaySubtree.knownBucketsAtNode rows repeats slots upper p hp clean W tape)
      (WholeReplaySubtree.knownBucketsAtNode rows repeats target upper p hp clean W other) := by
  cases hs
  cases eq_of_heq ht
  rfl

def uncastTape (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (upper lower : Nodes branch n) (cut : OwnInputReference.Cut upper lower)
    {k : Nat} (hk : Nodes.height lower = k)
    (tape : WholeArraySampler.Tape rows repeats
      ((Nodes.path upper).append (hk ▸ cut.path)) slots) :
    WholeArraySampler.Tape rows repeats ((Nodes.path upper).append cut.path) slots := by
  cases hk
  exact tape

def inputFromTape (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (upper lower : Nodes branch n) (cut : OwnInputReference.Cut upper lower)
    {k : Nat} (hk : Nodes.height lower = k)
    (W : Submodule F2 (Block rows upper)) (a : Block rows lower)
    (tape : WholeArraySampler.Tape rows repeats
      ((Nodes.path upper).append (hk ▸ cut.path)) slots) :
    OwnInputReference.Input slots rows upper lower W a :=
  inputOfArrays slots upper lower W a
    (fun v => RecursiveSampler.evaluate F2 repeats (hk ▸ cut.path)
      (LeafDomain (nodeSlots slots upper))
      ((WholeArrayPositiveSplit.split rows repeats (Nodes.path upper) (hk ▸ cut.path)
        (by simpa only [hk] using cut.proper) slots W tape).2.1 v))
    (WholeArraySampler.evaluate rows repeats ((Nodes.path upper).append (hk ▸ cut.path)) slots tape)

theorem inputFromTape_eq_ownInput
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (upper lower : Nodes branch n) (cut : OwnInputReference.Cut upper lower)
    {k : Nat} (hk : Nodes.height lower = k)
    (W : Submodule F2 (Block rows upper)) (a : Block rows lower)
    (tape : WholeArraySampler.Tape rows repeats
      ((Nodes.path upper).append (hk ▸ cut.path)) slots) :
    inputFromTape slots upper lower cut hk W a tape =
      WholeArrayInteriorOwnInputLaw.ownInput rows repeats slots upper lower cut W a
        (uncastTape slots upper lower cut hk tape) := by
  cases hk
  rfl

variable {Sample : OriginalDecoderMark.SlotFamily branch n t → Type*}
  [∀ slots, Fintype (Sample slots)]
  (F : OriginalDecoderMark.Family branch rows n t Sample)

def adviceLaw (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (upper : Nodes branch n) (level : Nat) (κ : ℝ)
    (arrays : Arrays slots rows)
    (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))
    (r : Nat) (ρ : ℝ) (A : ManyGoodRows.RowMap (Block rows upper) r) :
    FiniteDistribution (Module.Dual F2 (NodeEmbedding.RowSpace slots upper)) :=
  HierarchicalLeftDecoder.adviceLaw slots upper level
    (HierarchicalMatrixTable.backgroundOf slots upper arrays) σ
    (OriginalDecoderMark.mark F upper level κ slots
      (HierarchicalMatrixTable.backgroundOf slots upper arrays)) r ρ A
    (A.comp (MatrixRowQuotient.projectMatrix
      (HierarchicalFrozenTables.knownRows slots upper level
        (HierarchicalMatrixTable.backgroundOf slots upper arrays))
      (NodeEmbedding.matrix arrays upper)))

private theorem adviceLaw_heq
    (slots target : Slots branch n → Fin t → MixedSupport.Slot) (hs : slots = target)
    (upper : Nodes branch n) (level : Nat) (κ : ℝ)
    (arrays : Arrays slots rows) (other : Arrays target rows) (ha : HEq arrays other)
    (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))
    (r : Nat) (ρ : ℝ) (A : ManyGoodRows.RowMap (Block rows upper) r) :
    HEq (adviceLaw F slots upper level κ arrays σ r ρ A)
      (adviceLaw F target upper level κ other σ r ρ A) := by
  cases hs
  cases eq_of_heq ha
  rfl

private theorem rightLaw_heq
    (slots target : Slots branch n → Fin t → MixedSupport.Slot) (hs : slots = target)
    (upper lower : Nodes branch n) (W : Submodule F2 (Block rows upper))
    (a : Block rows lower) (cut : OwnInputReference.Cut upper lower)
    (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))
    (input : OwnInputReference.Input slots rows upper lower W a)
    (other : OwnInputReference.Input target rows upper lower W a) (hi : HEq input other)
    (threshold : ℝ) :
    HEq (RightDecoder.law slots rows upper lower W a repeats cut σ input threshold)
      (RightDecoder.law target rows upper lower W a repeats cut σ other threshold) := by
  cases hs
  cases eq_of_heq hi
  rfl

abbrev Answers (slots projected : Slots branch n → Fin t → MixedSupport.Slot)
    (upper : Nodes branch n) :=
  Module.Dual F2 (NodeEmbedding.RowSpace slots upper) ×
    Module.Dual F2 (OwnInputReference.UpperSpace projected upper)

instance answersFintype (slots projected : Slots branch n → Fin t → MixedSupport.Slot)
    (upper : Nodes branch n) : Fintype (Answers slots projected upper) := by
  letI := LeftDecoder.dualFintype (V := NodeEmbedding.RowSpace slots upper)
  letI := RightDecoder.scalarFintype projected upper
  exact inferInstanceAs (Fintype
    (Module.Dual F2 (NodeEmbedding.RowSpace slots upper) ×
      Module.Dual F2 (OwnInputReference.UpperSpace projected upper)))

def answerEquiv (slots projected target other : Slots branch n → Fin t → MixedSupport.Slot)
    (hs : slots = target) (hp : projected = other) (upper : Nodes branch n) :
    Answers slots projected upper ≃ Answers target other upper := by
  cases hs
  cases hp
  exact Equiv.refl _

private theorem product_heq
    (slots projected target other : Slots branch n → Fin t → MixedSupport.Slot)
    (hs : slots = target) (hp : projected = other) (upper : Nodes branch n)
    (μ : FiniteDistribution (Module.Dual F2 (NodeEmbedding.RowSpace slots upper)))
    (μ' : FiniteDistribution (Module.Dual F2 (NodeEmbedding.RowSpace target upper)))
    (ν : FiniteDistribution (Module.Dual F2 (OwnInputReference.UpperSpace projected upper)))
    (ν' : FiniteDistribution (Module.Dual F2 (OwnInputReference.UpperSpace other upper)))
    (hμ : HEq μ μ') (hν : HEq ν ν') : HEq (μ.product ν) (μ'.product ν') := by
  cases hs
  cases hp
  cases eq_of_heq hμ
  cases eq_of_heq hν
  rfl

private theorem pushforward_answerEquiv
    (slots projected target other : Slots branch n → Fin t → MixedSupport.Slot)
    (hs : slots = target) (hp : projected = other) (upper : Nodes branch n)
    (μ : FiniteDistribution (Answers slots projected upper))
    (ν : FiniteDistribution (Answers target other upper)) (hμ : HEq μ ν) :
    μ.pushforward (answerEquiv slots projected target other hs hp upper) = ν := by
  cases hs
  cases hp
  cases eq_of_heq hμ
  exact FiniteDistribution.pushforward_id μ

private theorem meeting_answerEquiv
    (slots projected target other : Slots branch n → Fin t → MixedSupport.Slot)
    (hs : slots = target) (hp : projected = other) (upper : Nodes branch n)
    (q : ∀ s k, MixedSupport.Projection (slots s k) (projected s k))
    (q' : ∀ s k, MixedSupport.Projection (target s k) (other s k))
    (hq : ∀ s k, HEq (q s k) (q' s k)) (answer : Answers slots projected upper) :
    decide ((answerEquiv slots projected target other hs hp upper answer).2 =
      DecoderSourcePullback.upperTarget q' upper
        (answerEquiv slots projected target other hs hp upper answer).1) =
      decide (answer.2 = DecoderSourcePullback.upperTarget q upper answer.1) := by
  cases hs
  cases hp
  have hqq : q = q' := funext (fun s => funext (fun k => eq_of_heq (hq s k)))
  cases hqq
  rfl

end NativeData

variable {branch rows repeats : Nat → Nat} {n h t v m : Nat} [NeZero m]
  {upper : Nodes branch n} {d : HierarchicalFrozenTables.LowerNodes upper (h + 1)}
  (S : CleanDecoderRate.Setup branch rows repeats n h t v m upper d)

abbrev lower (_S : CleanDecoderRate.Setup branch rows repeats n h t v m upper d) :=
  HierarchicalLeftDecoder.LowerNode upper (h + 1) d

abbrev leftArrays (x : CleanDecoderRate.Sample S) :=
  WholeCutSampler.evaluate rows repeats (CleanDecoderRate.path S)
    (CleanNativeReplay.leftSlots S x) (CleanNativeReplay.leftTape S x)

abbrev rightArrays (x : CleanDecoderRate.Sample S) :=
  WholeCutSampler.evaluate rows repeats (CleanDecoderRate.path S)
    (CleanNativeReplay.rightSlots S x) (CleanNativeReplay.rightTape S x)

abbrev rightWholeTape (x : CleanDecoderRate.Sample S) :=
  WholeCutSampler.collapse rows repeats (CleanDecoderRate.path S)
    (CleanNativeReplay.rightSlots S x) (CleanNativeReplay.rightTape S x)

def rightInput (W : Submodule F2 (Block rows upper)) (a : Block rows (lower S))
    (x : CleanDecoderRate.Sample S) :
    OwnInputReference.Input (CleanNativeReplay.rightSlots S x) rows upper (lower S) W a :=
  inputFromTape (CleanNativeReplay.rightSlots S x) upper (lower S) S.cut
    (CleanDecoderContext.lowerHeight upper d) W a (rightWholeTape S x)

theorem rightInput_eq_ownInput (W : Submodule F2 (Block rows upper))
    (a : Block rows (lower S)) (x : CleanDecoderRate.Sample S) :
    rightInput S W a x =
      WholeArrayInteriorOwnInputLaw.ownInput rows repeats (CleanNativeReplay.rightSlots S x)
        upper (lower S) S.cut W a
        (uncastTape (CleanNativeReplay.rightSlots S x) upper (lower S) S.cut
          (CleanDecoderContext.lowerHeight upper d) (rightWholeTape S x)) :=
  inputFromTape_eq_ownInput _ _ _ _ _ _ _ _

variable {Sample : OriginalDecoderMark.SlotFamily branch n t → Type*}
  [∀ slots, Fintype (Sample slots)]
  (F : OriginalDecoderMark.Family branch rows n t Sample) (κ : ℝ)

def useful (record : CleanDecoderRate.Record S) :=
  OriginalDecoderMark.useful F upper (h + 1) κ
    (CleanDecoderContext.leftExposed (CleanDecoderRate.context S record))

variable (σ : KeyStrategy.Strategy (TreeCanonical.locationCount branch n t))
  (r : Nat) (ρ : ℝ) (A : ManyGoodRows.RowMap (Block rows upper) r)
  (W : Submodule F2 (Block rows upper)) (a : Block rows (lower S))
  (threshold : ℝ)

def leftLaw (x : CleanDecoderRate.Sample S) :=
  adviceLaw F (CleanNativeReplay.leftSlots S x) upper (h + 1) κ (leftArrays S x) σ r ρ A

def rightLaw (x : CleanDecoderRate.Sample S) :=
  RightDecoder.law (CleanNativeReplay.rightSlots S x) rows upper (lower S) W a
    repeats S.cut σ (rightInput S W a x) threshold

def pairKernel (x : CleanDecoderRate.Sample S) :=
  (leftLaw S F κ σ r ρ A x).product (rightLaw S σ W a threshold x)

variable (cube : Nat) (hcube : 0 < cube)

theorem leftKernel_heq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    HEq (CleanDecoderSeedLaw.leftKernel (CleanDecoderPairLaw.context S x) σ
      (useful S F κ (CleanDecoderRate.observations S x)) r ρ A (CleanDecoderPairLaw.leftOwn S x))
      (leftLaw S F κ σ r ρ A x) :=
  adviceLaw_heq F _ _ (CleanNativeReplay.leftSlots_eq S x) upper (h + 1) κ
    _ _ (CleanNativeReplay.leftArrays_heq S cube hcube x hx) σ r ρ A

theorem rightKnownBuckets_heq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    HEq (CleanRightDecoder.knownBuckets
      (CleanDecoderPairLaw.context S x).clauses (CleanDecoderPairLaw.context S x).designated
      (CleanDecoderPairLaw.context S x).clean (CleanDecoderPairLaw.context S x).visible
      (CleanDecoderPairLaw.context S x).projected upper (lower S) S.cut
      (CleanDecoderContext.lowerHeight upper d) S.outside rows repeats
      (CleanDecoderPairLaw.context S x).rightTape W (CleanDecoderPairLaw.rightOwn S x))
      (rightInput S W a x).knownBuckets := by
  let suffix := CleanRightDecoder.suffix upper (lower S) S.cut
    (CleanDecoderContext.lowerHeight upper d)
  have hp : h + 1 < Nodes.height upper :=
    CleanRightDecoder.suffix_proper upper (lower S) S.cut (CleanDecoderContext.lowerHeight upper d)
  have hzero := (WholeCutZero.grouped_iff rows repeats (CleanDecoderRate.path S)
    (CleanNativeReplay.rightSlots S x) (CleanDecoderPairLaw.context S x).clean
    (CleanNativeReplay.rightTape S x)).mp (CleanNativeReplay.right_grouped_zero S cube hcube x hx)
  have h := replayKnown_heq _ _ (CleanNativeReplay.rightSlots_eq S x) upper suffix hp
    (CleanDecoderPairLaw.context S x).clean W _ _ (CleanNativeReplay.rightReplay_heq S x)
  have he := WholeCutSubtree.knownBucketsAtNode_erase rows repeats
    (CleanNativeReplay.rightSlots S x) upper suffix hp (CleanDecoderPairLaw.context S x).clean
    W (CleanNativeReplay.rightTape S x) hzero
  have ho := WholeCutSubtree.knownBuckets_eq_original rows repeats (Nodes.path upper) suffix hp
    (CleanNativeReplay.rightSlots S x) W (CleanNativeReplay.rightTape S x)
  exact h.trans ((heq_of_eq he).trans (heq_of_eq ho))

theorem rightInput_heq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    HEq (CleanRightDecoder.input
      (CleanDecoderPairLaw.context S x).clauses (CleanDecoderPairLaw.context S x).designated
      (CleanDecoderPairLaw.context S x).clean (CleanDecoderPairLaw.context S x).visible
      (CleanDecoderPairLaw.context S x).projected upper (lower S) S.cut
      (CleanDecoderContext.lowerHeight upper d) S.outside rows repeats
      (CleanDecoderPairLaw.context S x).rightTape W a (CleanDecoderPairLaw.rightOwn S x))
      (rightInput S W a x) :=
  inputOfArrays_heq _ _ (CleanNativeReplay.rightSlots_eq S x) upper (lower S) W a
    _ _ (rightKnownBuckets_heq S W a cube hcube x hx)
    _ _ (CleanNativeReplay.rightArrays_heq S cube hcube x hx)

theorem rightKernel_heq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    HEq (CleanDecoderSeedLaw.rightKernel (CleanDecoderPairLaw.context S x) σ W a threshold
      (CleanDecoderPairLaw.rightOwn S x)) (rightLaw S σ W a threshold x) :=
  rightLaw_heq _ _ (CleanNativeReplay.rightSlots_eq S x) upper (lower S) W a S.cut σ
    _ _ (rightInput_heq S W a cube hcube x hx) threshold

theorem pairKernel_heq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    HEq (CleanDecoderPairLaw.pairKernel S σ (useful S F κ) r ρ A W a threshold x)
      (pairKernel S F κ σ r ρ A W a threshold x) :=
  product_heq _ _ _ _ (CleanNativeReplay.leftSlots_eq S x)
    (CleanNativeReplay.rightSlots_eq S x) upper _ _ _ _
    (leftKernel_heq S F κ σ r ρ A cube hcube x hx)
    (rightKernel_heq S σ W a threshold cube hcube x hx)

def physicalAnswerEquiv (x : CleanDecoderRate.Sample S) :
    CleanDecoderPairLaw.Pair S x ≃
      Answers (CleanNativeReplay.leftSlots S x) (CleanNativeReplay.rightSlots S x) upper :=
  answerEquiv _ _ _ _ (CleanNativeReplay.leftSlots_eq S x)
    (CleanNativeReplay.rightSlots_eq S x) upper

theorem pairKernel_pushforward (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    (CleanDecoderPairLaw.pairKernel S σ (useful S F κ) r ρ A W a threshold x).pushforward
        (physicalAnswerEquiv S x) = pairKernel S F κ σ r ρ A W a threshold x :=
  pushforward_answerEquiv _ _ _ _ (CleanNativeReplay.leftSlots_eq S x)
    (CleanNativeReplay.rightSlots_eq S x) upper _ _
    (pairKernel_heq S F κ σ r ρ A W a threshold cube hcube x hx)

theorem probability_pairKernel (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0)
    (event : Answers (CleanNativeReplay.leftSlots S x) (CleanNativeReplay.rightSlots S x) upper → Bool) :
    (pairKernel S F κ σ r ρ A W a threshold x).probability event =
      (CleanDecoderPairLaw.pairKernel S σ (useful S F κ) r ρ A W a threshold x).probability
        (fun answer => event (physicalAnswerEquiv S x answer)) := by
  rw [← pairKernel_pushforward S F κ σ r ρ A W a threshold cube hcube x hx]
  exact FiniteDistribution.probability_pushforward _ _ _

abbrev physicalProjection (x : CleanDecoderRate.Sample S) :=
  CleanPhysicalCanonicalQuery.projection rows repeats (CleanDecoderRate.path S)
    S.outside S.clauses S.designated x

theorem projection_heq (x : CleanDecoderRate.Sample S) (leaf : Slots branch n) (k : Fin t) :
    HEq (CleanDecoderOddLists.fullProjection (CleanDecoderPairLaw.context S x)
      (CleanDecoderPairLaw.occurrences S x) leaf k) (physicalProjection S x leaf k) :=
  CleanRecordProjection.decoderProjection_heq rows S.clauses S.designated repeats upper d S.cut
    S.outside S.placeholder (CleanDecoderRate.observations S x) S.exterior x
    (CleanRecordDecoderInput.event_observe rows repeats upper d S.cut S.clauses S.designated x) leaf k

theorem meeting_probability_eq (x : CleanDecoderRate.Sample S)
    (hx : (CleanDecoderRate.rawLaw S cube hcube).weight x ≠ 0) :
    (pairKernel S F κ σ r ρ A W a threshold x).probability
      (fun answer => decide (answer.2 = DecoderSourcePullback.upperTarget
        (physicalProjection S x) upper answer.1)) =
      (CleanDecoderPairLaw.pairKernel S σ (useful S F κ) r ρ A W a threshold x).probability
        (fun answer => decide (answer.2 = DecoderSourcePullback.upperTarget
          (CleanDecoderOddLists.fullProjection (CleanDecoderPairLaw.context S x)
            (CleanDecoderPairLaw.occurrences S x)) upper answer.1)) := by
  rw [probability_pairKernel S F κ σ r ρ A W a threshold cube hcube x hx]
  congr 1
  funext answer
  exact meeting_answerEquiv _ _ _ _ (CleanNativeReplay.leftSlots_eq S x)
    (CleanNativeReplay.rightSlots_eq S x) upper _ _ (projection_heq S x) answer

end
end PerfectCompleteness.CleanPhysicalDecoderLaw

end

end OAI