File size: 11,884 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 | import OAI.Computability.PerfectCompleteness.Construction.CutChildGrouping
import OAI.Computability.PerfectCompleteness.Construction.OriginalChildScalarAssemblyLemmas
import OAI.Computability.PerfectCompleteness.Construction.OriginalChildScalars
import OAI.Computability.PerfectCompleteness.Foundations.OriginalBelowCut
import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerReplayTransportLemmas
namespace OAI
section
namespace PerfectCompleteness.OriginalChildBlocks
open PointwiseSpaces RecursiveSpaces DescendantSpaces TreeSourceSpaces HierarchicalArrays
open OriginalChildScalars
open UniqueGamesTheorem.Foundations.Games
open scoped BigOperators Classical
noncomputable section
private theorem uniform_product {A B : Type*} [Fintype A] [Fintype B]
[Nonempty A] [Nonempty B] :
(FiniteDistribution.uniform A).product (FiniteDistribution.uniform B) =
FiniteDistribution.uniform (A × B) := by
apply FiniteDistribution.eq_of_weight_eq
intro x
simp only [FiniteDistribution.product, FiniteDistribution.uniform,
Fintype.card_prod, Nat.cast_mul, one_div_mul_one_div]
variable {branch : Nat → Nat} {n m t : Nat}
def rawEquiv (calls : Nat) (rows : Nat → Nat)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) (child : Fin (branch n)) :
((Fin calls → Square slots child) × Arrays (childSlots slots child) rows) ≃
ChildBlockCardinality.Raw calls rows (childSlots slots child) := Equiv.refl _
def arrayComponent (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :
(child : Fin (branch n)) → FiniteDistribution (Arrays (childSlots slots child) rows) :=
ChildBlockMixture.component
(fun child => WholeArraySampler.law rows repeats q (childSlots slots child)) chosen
def specialLaw (calls : Nat) (rows repeats : Nat → Nat) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) (child : Fin (branch n)) :
FiniteDistribution (ChildBlockCardinality.Raw calls rows (childSlots slots child)) :=
@FiniteDistribution.transport
((Fin calls → Square slots child) × Arrays (childSlots slots child) rows)
(ChildBlockCardinality.Raw calls rows (childSlots slots child))
(instFintypeProd _ _) (ChildBlockCardinality.rawFintype calls rows (childSlots slots child))
((FiniteProduct.law (fun _ : Fin calls => specialSquareLaw repeats q slots child)).product
(WholeArraySampler.law rows repeats q (childSlots slots child)))
(rawEquiv calls rows slots child)
def componentLaw (calls : Nat) (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(child : Fin (branch n)) :
FiniteDistribution (ChildBlockCardinality.Raw calls rows (childSlots slots child)) :=
@FiniteDistribution.transport
((Fin calls → Square slots child) × Arrays (childSlots slots child) rows)
(ChildBlockCardinality.Raw calls rows (childSlots slots child))
(instFintypeProd _ _) (ChildBlockCardinality.rawFintype calls rows (childSlots slots child))
((callComponent calls repeats chosen q slots child).product
(arrayComponent rows repeats chosen q slots child)) (rawEquiv calls rows slots child)
theorem callComponent_uniform (calls : Nat) (repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(child : Fin (branch n)) (hne : child ≠ chosen) :
callComponent calls repeats chosen q slots child =
FiniteDistribution.uniform (Fin calls → Square slots child) := by
have h := squareComponent_other repeats q slots chosen ⟨child, hne⟩
unfold callComponent
rw [h]
exact UniformLinearImage.law_uniform
theorem componentLaw_eq (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) (child : Fin (branch n)) :
componentLaw calls rows repeats chosen q slots child =
ChildBlockMixture.component (specialLaw calls rows repeats q slots) chosen child := by
by_cases h : child = chosen
· subst child
simp only [componentLaw, callComponent, squareComponent_self, arrayComponent,
ChildBlockMixture.component, dite_eq_left rfl, dite_true, specialLaw]
· have harray : arrayComponent rows repeats chosen q slots child =
FiniteDistribution.uniform (Arrays (childSlots slots child) rows) :=
dite_eq_right (Ne.symm h)
rw [componentLaw, callComponent_uniform calls repeats chosen q slots child h, harray]
rw [uniform_product]
have huniform := @UniformConditioning.uniform_transport
((Fin calls → Square slots child) × Arrays (childSlots slots child) rows)
(ChildBlockCardinality.Raw calls rows (childSlots slots child))
(instFintypeProd _ _) (ChildBlockCardinality.rawFintype calls rows (childSlots slots child))
inferInstance inferInstance (rawEquiv calls rows slots child)
have hcomponent :
ChildBlockMixture.component (specialLaw calls rows repeats q slots) chosen child =
FiniteDistribution.uniform
(ChildBlockCardinality.Raw calls rows (childSlots slots child)) := by
simp only [ChildBlockMixture.component, dite_eq_right (Ne.symm h)]
exact huniform.trans hcomponent.symm
abbrev SourceTape (calls : Nat) (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :=
(Fin calls → ScalarTape repeats chosen q slots) ×
WholeArraySampler.Tape rows repeats (.step chosen q) slots
def sourceLaw (calls : Nat) (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :
FiniteDistribution (SourceTape calls rows repeats chosen q slots) :=
(callsLaw calls repeats chosen q slots).product
(WholeArraySampler.tapeLaw rows repeats (.step chosen q) slots)
def rawMap (calls : Nat) (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(ω : SourceTape calls rows repeats chosen q slots) :
(child : Fin (branch n)) → ChildBlockCardinality.Raw calls rows (childSlots slots child) :=
fun child => rawEquiv calls rows slots child
(callContributions calls repeats chosen q slots ω.1 child,
OriginalBelowCut.below rows repeats chosen q slots ω.2 child)
@[simp] theorem rawMap_call (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(ω : SourceTape calls rows repeats chosen q slots) (child : Fin (branch n)) (call : Fin calls) :
(rawMap calls rows repeats chosen q slots ω child).1 call =
stepSquareMap repeats chosen q slots (ω.1 call) child := rfl
@[simp] theorem rawMap_array (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(ω : SourceTape calls rows repeats chosen q slots) (child : Fin (branch n))
(node : Nodes branch n) :
(rawMap calls rows repeats chosen q slots ω child).2 node =
WholeArraySampler.evaluate rows repeats (.step chosen q) slots ω.2 (.inr (child, node)) := rfl
theorem rawMap_product_law (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :
(sourceLaw calls rows repeats chosen q slots).pushforward
(rawMap calls rows repeats chosen q slots) =
FiniteProduct.law (componentLaw calls rows repeats chosen q slots) := by
calc
_ = ((sourceLaw calls rows repeats chosen q slots).pushforward
(fun ω => (callContributions calls repeats chosen q slots ω.1,
OriginalBelowCut.below rows repeats chosen q slots ω.2))).pushforward
(fun z child => rawEquiv calls rows slots child (z.1 child, z.2 child)) :=
(FiniteDistribution.pushforward_comp _ _ _).symm
_ = ((FiniteProduct.law (callComponent calls repeats chosen q slots)).product
(FiniteProduct.law (arrayComponent rows repeats chosen q slots))).pushforward
(fun z child => rawEquiv calls rows slots child (z.1 child, z.2 child)) := by
rw [sourceLaw, FiniteDistribution.product_pushforward,
callContributions_law, OriginalBelowCut.below_pushforward, arrayComponent]
_ = _ := by
have hpair := OriginalChildBlockProducts.pair_transport_law
(Ω := fun child : Fin (branch n) => Fin calls → ↥(Square slots child))
(Γ := fun child => Arrays (childSlots slots child) rows)
(Δ := fun child => ChildBlockCardinality.Raw calls rows (childSlots slots child))
(rawEquiv calls rows slots) (callComponent calls repeats chosen q slots)
(arrayComponent rows repeats chosen q slots)
apply FiniteDistribution.eq_of_weight_eq
intro x
have hw := congrFun (congrArg FiniteDistribution.weight hpair) x
simpa only [componentLaw, FiniteProduct.law, FiniteDistribution.transport] using hw
theorem rawMap_law (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :
(sourceLaw calls rows repeats chosen q slots).pushforward
(rawMap calls rows repeats chosen q slots) =
ChildBlockMixture.special (specialLaw calls rows repeats q slots) chosen := by
rw [rawMap_product_law]
apply congrArg (fun laws : (child : Fin (branch n)) →
FiniteDistribution (ChildBlockCardinality.Raw calls rows (childSlots slots child)) =>
FiniteProduct.law laws)
funext child
exact componentLaw_eq calls rows repeats chosen q slots child
def observed (calls : Nat) (rows repeats : Nat → Nat) (chosen : Fin (branch n))
(q : Path branch n m) (slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(ω : SourceTape calls rows repeats chosen q slots) :
CutChildGrouping.Assembled (C := Fin calls) slots rows :=
(fun call => RecursiveSampler.evaluate F2 repeats (.step chosen q) (LeafDomain slots) (ω.1 call),
OriginalBelowCut.below rows repeats chosen q slots ω.2)
theorem assemble_rawMap (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot)
(ω : SourceTape calls rows repeats chosen q slots) :
CutChildGrouping.assemble slots rows (rawMap calls rows repeats chosen q slots ω) =
observed calls rows repeats chosen q slots ω := by
apply Prod.ext
· funext call
exact OriginalChildScalarAssembly.recursiveSum_callContributions
calls repeats chosen q slots ω.1 call
· rfl
theorem observed_law (calls : Nat) (rows repeats : Nat → Nat)
(chosen : Fin (branch n)) (q : Path branch n m)
(slots : Slots branch (n + 1) → Fin t → MixedSupport.Slot) :
(sourceLaw calls rows repeats chosen q slots).pushforward
(observed calls rows repeats chosen q slots) =
(ChildBlockMixture.special (specialLaw calls rows repeats q slots) chosen).pushforward
(CutChildGrouping.assemble slots rows) := by
calc
_ = ((sourceLaw calls rows repeats chosen q slots).pushforward
(rawMap calls rows repeats chosen q slots)).pushforward
(CutChildGrouping.assemble slots rows) := by
rw [FiniteDistribution.pushforward_comp]
congr 1
funext ω
exact (assemble_rawMap calls rows repeats chosen q slots ω).symm
_ = _ := by rw [rawMap_law]
end
end PerfectCompleteness.OriginalChildBlocks
end
end OAI
|