File size: 10,947 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
import OAI.Computability.PerfectCompleteness.Construction.CutBucketTransportLemmas
import OAI.Computability.PerfectCompleteness.Sampling.OriginalCutPairLaw

namespace OAI

section

namespace PerfectCompleteness.OriginalUsefulPairLaw

open RecursiveSpaces DescendantSpaces TreeSourceSpaces HierarchicalArrays
open OriginalWholeCutTape WholeArrayInteriorExterior
open UniqueGamesTheorem.Foundations.Games
open UniqueGamesTheorem.Appendix.RankLevelFilter (linearMapFintype)
open scoped BigOperators Classical

noncomputable section

attribute [local instance] linearMapFintype

private theorem product_mixture_pushforward {E A B Γ : Type*}
    [Fintype E] [Fintype A] [Fintype B] [Fintype Γ]
    (μ : FiniteDistribution A) (κ : FiniteDistribution E)
    (ν : E → FiniteDistribution B) (f : A × B → Γ) :
    (μ.product (κ.mixture ν)).pushforward f =
      κ.mixture (fun e => (μ.product (ν e)).pushforward f) := by
  have hp : μ.product (κ.mixture ν) = κ.mixture (fun e => μ.product (ν e)) := by
    apply FiniteDistribution.eq_of_weight_eq
    intro x
    simp only [FiniteDistribution.product, FiniteDistribution.mixture, Finset.mul_sum]
    apply Finset.sum_congr rfl
    intro e _
    exact mul_left_comm _ _ _
  rw [hp, FiniteDistribution.pushforward_mixture]

private theorem nested_sigma_product_pushforward {Tag Bg Buck Γ : Type*}
    [Fintype Tag] [Fintype Bg] [Fintype Buck] [Fintype Γ]
    (μ : FiniteDistribution Tag) (β : Tag → FiniteDistribution Bg)
    (γ : Tag → FiniteDistribution Buck) (f : Bg × Buck → Γ) :
    (CompletionSoundness.sigmaLaw (CompletionSoundness.sigmaLaw μ β)
      (fun d : Σ _ : Tag, Bg => γ d.1)).pushforward
        (fun z => f (z.1.2, z.2)) =
      μ.mixture (fun tag => ((β tag).product (γ tag)).pushforward f) := by
  apply FiniteDistribution.eq_of_weight_eq
  intro x
  simp only [FiniteDistribution.pushforward, CompletionSoundness.sigmaLaw,
    FiniteDistribution.mixture, FiniteDistribution.product, Fintype.sum_sigma,
    Fintype.sum_prod_type, Finset.mul_sum, mul_ite, mul_zero, mul_assoc]

variable {branch : Nat → Nat} {n m k t : Nat}

local instance backgroundFintype (rows : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    Fintype (HierarchicalMatrixTable.Background (rows := rows) slots (upperNode p)) :=
  Fintype.ofFinite _

local instance rowSpaceFintype (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) :
    Fintype (NodeEmbedding.RowSpace slots (upperNode p)) := Fintype.ofFinite _

attribute [local instance 2000] OriginalWholeCutLaw.valuesBelowFintype

private theorem transportPair_law (rows : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (μ : FiniteDistribution (HierarchicalMatrixTable.Background (rows := rows) slots (upperNode p)))
    (ν : FiniteDistribution (BucketSampler.Direction (rows (m + 1)) ×
      (BucketSampler.Tape (rows (m + 1)) (H (cutSlots p slots)) × H (cutSlots p slots)))) :
    (μ.product ν).pushforward (OriginalCutPairLaw.transportPair rows p slots) =
      ((μ.product ν).pushforward
        (fun z : OriginalCutBucketLaw.NativeSample rows p slots =>
          (z.1, CutNodeRows.bucketSampleEquiv rows p slots z.2))).pushforward
        (HierarchicalAgreementMean.pairRecord slots (upperNode p)) := by
  exact (FiniteDistribution.pushforward_comp (μ.product ν)
    (fun z : OriginalCutBucketLaw.NativeSample rows p slots =>
      (z.1, CutNodeRows.bucketSampleEquiv rows p slots z.2))
    (HierarchicalAgreementMean.pairRecord slots (upperNode p))).symm

theorem record_fresh_pair_law (rows repeats : Nat → Nat)
    (p : Path branch n (m + 1)) (chosen : Fin (branch m)) (q : Path branch m k)
    (slots : Slots branch n → Fin t → MixedSupport.Slot) (hrows : 0 < rows (m + 1)) :
    ((OriginalCutPairLaw.directionsLaw rows m hrows).product
      (((OriginalWholeCutLaw.recordLaw rows repeats p chosen q slots).pushforward
        (OriginalWholeCutBridge.numberRecord rows repeats p slots)).product
          (RecursiveSampler.law F2 repeats (.step chosen q) (LeafDomain (cutSlots p slots))))).pushforward
      (OriginalCutCollision.pairRecord rows repeats p slots) =
      ((OriginalOwnBucketSplit.actualBackgroundLaw rows repeats p chosen q slots).product
        (HierarchicalUsefulCollision.bucketLaw slots (upperNode p)
          ((RecursiveSampler.law F2 repeats (.step chosen q) (LeafDomain (cutSlots p slots))).pushforward
            (CutNodeRows.cutRowEquiv p slots))
          (by simpa only [upperNode_height] using hrows))).pushforward
            (HierarchicalAgreementMean.pairRecord slots (upperNode p)) := by
  let μ := OriginalOwnBucketSplit.actualBackgroundLaw rows repeats p chosen q slots
  let scalar := RecursiveSampler.law F2 repeats (.step chosen q) (LeafDomain (cutSlots p slots))
  let records := ((OriginalWholeCutLaw.recordLaw rows repeats p chosen q slots).pushforward
    (OriginalWholeCutBridge.numberRecord rows repeats p slots)).product scalar
  let directions := OriginalCutPairLaw.directionsLaw rows m hrows
  have hread := OriginalCutBucketLaw.record_fresh_read_law rows repeats p chosen q slots directions
  have hnative :
      (directions.product records).pushforward (OriginalCutBucketLaw.read rows repeats p slots) =
        μ.product (CutBucketTransportActual.nativeLaw rows p slots scalar hrows) := by
    simpa only [μ, scalar, records, directions, CutBucketTransportActual.nativeLaw,
      OriginalCutPairLaw.directionsLaw] using hread
  have htransport := FiniteDistribution.product_pushforward μ
    (CutBucketTransportActual.nativeLaw rows p slots scalar hrows) id
    (CutNodeRows.bucketSampleEquiv rows p slots)
  simp only [id_eq, FiniteDistribution.pushforward_id] at htransport
  calc
    _ = ((directions.product records).pushforward
        (OriginalCutBucketLaw.read rows repeats p slots)).pushforward
          (OriginalCutPairLaw.transportPair rows p slots) := by
      rw [FiniteDistribution.pushforward_comp]
      congr 1
      funext sample
      exact OriginalCutPairLaw.pairRecord_eq rows repeats p slots sample
    _ = (μ.product (CutBucketTransportActual.nativeLaw rows p slots scalar hrows)).pushforward
        (OriginalCutPairLaw.transportPair rows p slots) := by rw [hnative]
    _ = ((μ.product (CutBucketTransportActual.nativeLaw rows p slots scalar hrows)).pushforward
        (fun z => (z.1, CutNodeRows.bucketSampleEquiv rows p slots z.2))).pushforward
          (HierarchicalAgreementMean.pairRecord slots (upperNode p)) :=
      transportPair_law rows p slots μ (CutBucketTransportActual.nativeLaw rows p slots scalar hrows)
    _ = _ := by
      rw [htransport, CutBucketTransportActual.nativeLaw_pushforward]

abbrev Descriptor (rows : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) (K : Type*) :=
  Σ _ : Fin (branch m) × K,
    HierarchicalMatrixTable.Background (rows := rows) slots (upperNode p)

variable {K : Type*} [Fintype K]

def externalLaw (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (ν : FiniteDistribution K) (q : K → Path branch m k) (hbranch : 0 < branch m) :
    FiniteDistribution (Descriptor rows p slots K) :=
  CompletionSoundness.sigmaLaw (OriginalPrefixContinuation.tagLaw ν hbranch)
    (fun tag => OriginalOwnBucketSplit.actualBackgroundLaw rows repeats p tag.1 (q tag.2) slots)

def background (rows : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (descriptor : Descriptor rows p slots K) :
    HierarchicalMatrixTable.Background (rows := rows) slots (upperNode p) := descriptor.2

def scalarLaw (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot) (q : K → Path branch m k)
    (descriptor : Descriptor rows p slots K) :
    FiniteDistribution (NodeEmbedding.RowSpace slots (upperNode p)) :=
  (RecursiveSampler.law F2 repeats (.step descriptor.1.1 (q descriptor.1.2))
    (LeafDomain (cutSlots p slots))).pushforward (CutNodeRows.cutRowEquiv p slots)

theorem useful_pairLaw_eq_mixture (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (ν : FiniteDistribution K) (q : K → Path branch m k) (hbranch : 0 < branch m)
    (hrows : 0 < rows (m + 1)) :
    HierarchicalUsefulCollision.pairLaw slots (upperNode p)
        (externalLaw rows repeats p slots ν q hbranch) (background rows p slots)
        (scalarLaw rows repeats p slots q)
        (by simpa only [upperNode_height] using hrows) =
      (OriginalPrefixContinuation.tagLaw ν hbranch).mixture (fun tag =>
        ((OriginalOwnBucketSplit.actualBackgroundLaw rows repeats p tag.1 (q tag.2) slots).product
          (HierarchicalUsefulCollision.bucketLaw slots (upperNode p)
            ((RecursiveSampler.law F2 repeats (.step tag.1 (q tag.2))
              (LeafDomain (cutSlots p slots))).pushforward (CutNodeRows.cutRowEquiv p slots))
            (by simpa only [upperNode_height] using hrows))).pushforward
              (HierarchicalAgreementMean.pairRecord slots (upperNode p))) := by
  exact nested_sigma_product_pushforward
    (OriginalPrefixContinuation.tagLaw ν hbranch)
    (fun tag => OriginalOwnBucketSplit.actualBackgroundLaw rows repeats p tag.1 (q tag.2) slots)
    (fun tag => HierarchicalUsefulCollision.bucketLaw slots (upperNode p)
      ((RecursiveSampler.law F2 repeats (.step tag.1 (q tag.2))
        (LeafDomain (cutSlots p slots))).pushforward (CutNodeRows.cutRowEquiv p slots))
      (by simpa only [upperNode_height] using hrows))
    (HierarchicalAgreementMean.pairRecord slots (upperNode p))

theorem actual_pair_law (rows repeats : Nat → Nat) (p : Path branch n (m + 1))
    (slots : Slots branch n → Fin t → MixedSupport.Slot)
    (ν : FiniteDistribution K) (q : K → Path branch m k) (hbranch : 0 < branch m)
    (hrows : 0 < rows (m + 1)) :
    ((OriginalCutPairLaw.directionsLaw rows m hrows).product
      (OriginalExtraCutComparison.actualLaw rows repeats p slots ν q hbranch)).pushforward
        (OriginalCutCollision.pairRecord rows repeats p slots) =
      HierarchicalUsefulCollision.pairLaw slots (upperNode p)
        (externalLaw rows repeats p slots ν q hbranch) (background rows p slots)
        (scalarLaw rows repeats p slots q)
        (by simpa only [upperNode_height] using hrows) := by
  rw [OriginalExtraCutComparison.actualLaw_eq_mixture, product_mixture_pushforward,
    useful_pairLaw_eq_mixture rows repeats p slots ν q hbranch hrows]
  apply congrArg ((OriginalPrefixContinuation.tagLaw ν hbranch).mixture)
  funext tag
  exact record_fresh_pair_law rows repeats p tag.1 (q tag.2) slots hrows

end
end PerfectCompleteness.OriginalUsefulPairLaw

end

end OAI