math / data /lean /OAI /Computability /PerfectCompleteness /Sampling /SamplerCompositionLaws.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
7.02 kB
import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerReplayTransportLemmas
import OAI.Computability.PerfectCompleteness.Sampling.SamplerComposition
namespace OAI
section
namespace PerfectCompleteness.SamplerComposition
open PointwiseSpaces RecursiveSpaces DescendantSpaces RecursiveSampler
open UniqueGamesTheorem.Foundations.Games
noncomputable section
universe u w
variable {branch : Nat β†’ Nat} {n m k : Nat}
variable (π•œ : Type w) [Field π•œ]
instance expansionSpaceNonempty (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) (j : DrawIndex repeats p) :
Nonempty (ExpansionSpace π•œ repeats p q A j) :=
⟨zeroFactor π•œ repeats p q A j⟩
instance expandedTapeNonempty (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) :
Nonempty (ExpandedTape π•œ repeats p q A) :=
⟨zeroExpandedTape π•œ repeats p q A⟩
variable [Finite π•œ]
theorem expansionSpace_finite (repeats : Nat β†’ Nat) (p : Path branch n m) :
βˆ€ (q : Path branch m k) (A : Slots branch n β†’ Type u),
(βˆ€ s, Finite (A s)) β†’ βˆ€ j : DrawIndex repeats p,
Finite (ExpansionSpace π•œ repeats p q A j) := by
induction p with
| refl n =>
intro q A hA j
let : βˆ€ s, Finite (A s) := hA
let : βˆ€ d : DrawIndex repeats q, Fintype (DrawSpace π•œ repeats q A d) :=
fun d => drawSpaceFintype π•œ repeats q A d
change Finite (RecursiveSampler.Tape π•œ repeats q A)
infer_instance
| @step n m i p ih =>
intro q A hA j
cases j with
| inl j =>
let : βˆ€ s, Finite (childFamily A j.val s) := fun s => hA (j.val, s)
change Finite (squareSpace (space π•œ branch n (childFamily A j.val)))
infer_instance
| inr j =>
exact ih q (childFamily A i) (fun s => hA (i, s)) j.2
instance expansionSpaceFinite (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)]
(j : DrawIndex repeats p) : Finite (ExpansionSpace π•œ repeats p q A j) :=
expansionSpace_finite π•œ repeats p q A (fun _ => inferInstance) j
instance expansionSpaceFintype (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)]
(j : DrawIndex repeats p) : Fintype (ExpansionSpace π•œ repeats p q A j) :=
Fintype.ofFinite _
instance expandedTapeFintype (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
Fintype (ExpandedTape π•œ repeats p q A) :=
@Pi.instFintype (DrawIndex repeats p) (ExpansionSpace π•œ repeats p q A)
(drawIndexDecidableEq repeats p) (drawIndexFintype repeats p)
(fun j => expansionSpaceFintype π•œ repeats p q A j)
def expandedTapeLaw (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
FiniteDistribution (ExpandedTape π•œ repeats p q A) := by
letI : βˆ€ j : DrawIndex repeats p, Fintype (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceFintype π•œ repeats p q A j
letI : βˆ€ j : DrawIndex repeats p, Nonempty (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceNonempty π•œ repeats p q A j
exact FiniteProduct.law (fun j => FiniteDistribution.uniform (ExpansionSpace π•œ repeats p q A j))
theorem expandedTapeLaw_eq_uniform (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
expandedTapeLaw π•œ repeats p q A = FiniteDistribution.uniform (ExpandedTape π•œ repeats p q A) := by
let : βˆ€ j : DrawIndex repeats p, Fintype (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceFintype π•œ repeats p q A j
let : βˆ€ j : DrawIndex repeats p, Nonempty (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceNonempty π•œ repeats p q A j
exact UniformLinearImage.law_uniform
theorem expand_tapeLaw (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
(tapeLaw π•œ repeats (p.append q) A).pushforward (expandEquiv π•œ repeats p q A) =
expandedTapeLaw π•œ repeats p q A := by
rw [tapeLaw_eq_uniform, expandedTapeLaw_eq_uniform,
← FiniteDistribution.transport_eq_pushforward]
exact UniformConditioning.uniform_transport (expandEquiv π•œ repeats p q A)
def factorLaw (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)]
(j : DrawIndex repeats p) : FiniteDistribution (DrawSpace π•œ repeats p A j) :=
(FiniteDistribution.uniform (ExpansionSpace π•œ repeats p q A j)).pushforward
(collapseFactor π•œ repeats p q A j)
theorem collapseExpanded_expandedTapeLaw (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
(expandedTapeLaw π•œ repeats p q A).pushforward (collapseExpanded π•œ repeats p q A) =
FiniteProduct.law (factorLaw π•œ repeats p q A) := by
let : βˆ€ j : DrawIndex repeats p, Fintype (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceFintype π•œ repeats p q A j
let : βˆ€ j : DrawIndex repeats p, Nonempty (ExpansionSpace π•œ repeats p q A j) :=
fun j => expansionSpaceNonempty π•œ repeats p q A j
exact FiniteProduct.pushforward_map _ (collapseFactor π•œ repeats p q A)
theorem collapseSuffix_tapeLaw (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)] :
(tapeLaw π•œ repeats (p.append q) A).pushforward (collapseSuffix π•œ repeats p q A) =
FiniteProduct.law (factorLaw π•œ repeats p q A) := by
calc
_ = ((tapeLaw π•œ repeats (p.append q) A).pushforward
(expandEquiv π•œ repeats p q A)).pushforward (collapseExpanded π•œ repeats p q A) :=
(FiniteDistribution.pushforward_comp _ _ _).symm
_ = _ := by rw [expand_tapeLaw, collapseExpanded_expandedTapeLaw]
theorem law_append (repeats : Nat β†’ Nat) (p : Path branch n m)
(q : Path branch m k) (A : Slots branch n β†’ Type u) [βˆ€ s, Finite (A s)]
[Fintype (space π•œ branch n A)] :
RecursiveSampler.law π•œ repeats (p.append q) A =
(FiniteProduct.law (factorLaw π•œ repeats p q A)).pushforward
(RecursiveSampler.evaluate π•œ repeats p A) := by
calc
_ = ((tapeLaw π•œ repeats (p.append q) A).pushforward
(collapseSuffix π•œ repeats p q A)).pushforward
(RecursiveSampler.evaluate π•œ repeats p A) := by
rw [FiniteDistribution.pushforward_comp]
unfold RecursiveSampler.law
congr 1
funext t
exact (evaluate_collapseSuffix π•œ repeats p q A t).symm
_ = _ := by rw [collapseSuffix_tapeLaw]
end
end PerfectCompleteness.SamplerComposition
end
end OAI