math / data /lean /OAI /Computability /PerfectCompleteness /Construction /OriginalChildBlocks.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
11.9 kB
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