math / data /lean /OAI /Computability /PerfectCompleteness /Sampling /BucketUniformLemmas.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
22.6 kB
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.SetTheory.Cardinal.Finite
import OAI.Computability.PerfectCompleteness.Algebra.UniformLinearImage
import OAI.Computability.PerfectCompleteness.Sampling.BucketSampler
import OAI.Computability.PerfectCompleteness.Sampling.RationalFiniteLawLemmas
import OAI.Computability.PerfectCompleteness.Sampling.RecordSeedSamplingLemmas
import OAI.Computability.UniqueGames.Games.FinishBoundsLemmas
namespace OAI
namespace PerfectCompleteness.BucketUniform
noncomputable section
open scoped BigOperators Classical
open UniqueGamesTheorem.Foundations.Games
open BucketSampler (F2 Direction)
variable {H : Type*} [AddCommGroup H] [Module F2 H]
def coordinateDirection {β„“ : Nat} (i : Fin β„“) : Direction β„“ :=
⟨Pi.single i (1 : F2), by
intro h
have hi := congrFun h i
simp at hi⟩
def evaluateLinear (β„“ : Nat) : (Direction β„“ β†’ H) β†’β‚—[F2] (Fin β„“ β†’ H) where
toFun := BucketSampler.evaluate β„“ (id : H β†’ H)
map_add' t u := by
funext i
simp only [BucketSampler.evaluate, id_eq, Pi.add_apply, smul_add,
Finset.sum_add_distrib]
map_smul' a t := by
funext i
change (βˆ‘ v : Direction β„“, v.val i β€’ (a β€’ t v)) =
a β€’ βˆ‘ v : Direction β„“, v.val i β€’ t v
rw [Finset.smul_sum]
exact Finset.sum_congr rfl (fun v _ => smul_comm _ _ _)
@[simp] theorem evaluateLinear_apply (β„“ : Nat) (t : Direction β„“ β†’ H) :
evaluateLinear β„“ t = BucketSampler.evaluate β„“ (id : H β†’ H) t := rfl
theorem evaluate_single {β„“ : Nat} (v : Direction β„“) (h : H) :
evaluateLinear β„“ (Pi.single v h) = BucketSampler.rankOne v.val h := by
funext i
change (βˆ‘ w : Direction β„“, w.val i β€’ (Pi.single v h) w) = v.val i β€’ h
rw [Finset.sum_eq_single v]
Β· simp
Β· intro w _ hw
simp [hw]
Β· intro hv
exact (hv (Finset.mem_univ v)).elim
theorem evaluate_coordinate_bucket {β„“ : Nat} (i : Fin β„“) (h : H) :
evaluateLinear β„“ (Pi.single (coordinateDirection i) h) = Pi.single i h := by
rw [evaluate_single]
funext j
by_cases hij : i = j
Β· subst j
simp [BucketSampler.rankOne, coordinateDirection]
Β· simp [BucketSampler.rankOne, coordinateDirection, Ne.symm hij]
def coordinateTape {β„“ : Nat} (rows : Fin β„“ β†’ H) : Direction β„“ β†’ H :=
βˆ‘ i : Fin β„“, Pi.single (coordinateDirection i) (rows i)
theorem evaluate_coordinateTape {β„“ : Nat} (rows : Fin β„“ β†’ H) :
evaluateLinear β„“ (coordinateTape rows) = rows := by
unfold coordinateTape
rw [map_sum]
simp only [evaluate_coordinate_bucket, Finset.univ_sum_single]
theorem evaluateLinear_surjective (β„“ : Nat) :
Function.Surjective (evaluateLinear (H := H) β„“) :=
fun rows => ⟨coordinateTape rows, evaluate_coordinateTape rows⟩
theorem evaluate_surjective (β„“ : Nat) :
Function.Surjective (BucketSampler.evaluate β„“ (id : H β†’ H)) :=
evaluateLinear_surjective β„“
theorem uniform_evaluate_law [Fintype H] (β„“ : Nat) :
(BucketSampler.tapeLaw β„“ (FiniteDistribution.uniform H)).pushforward
(BucketSampler.evaluate β„“ (id : H β†’ H)) =
FiniteDistribution.uniform (Fin β„“ β†’ H) :=
UniformLinearImage.product_uniform_linear_image
(I := Direction β„“) (Ξ© := fun _ => H) (R := F2) (V := Fin β„“ β†’ H)
(evaluateLinear (H := H) β„“) (evaluateLinear_surjective (H := H) β„“)
theorem uniform_array_law [Fintype H] (β„“ : Nat) :
BucketSampler.law β„“ (FiniteDistribution.uniform H) (id : H β†’ H) =
FiniteDistribution.uniform (Fin β„“ β†’ H) :=
uniform_evaluate_law β„“
variable {Ξ© : Type*} (V : Submodule F2 (Ξ© β†’ F2))
def ofRowsLinear (β„“ : Nat) :
(Fin β„“ β†’ V) β†’β‚—[F2] (Module.Dual F2 V β†’β‚—[F2] (Fin β„“ β†’ F2)) where
toFun := EvaluationMatrix.ofRows V
map_add' rows rows' := by
apply LinearMap.ext
intro q
funext i
exact map_add q (rows i) (rows' i)
map_smul' a rows := by
apply LinearMap.ext
intro q
funext i
exact map_smul q a (rows i)
theorem ofRowsLinear_surjective [FiniteDimensional F2 V] (β„“ : Nat) :
Function.Surjective (ofRowsLinear V β„“) :=
fun X => ⟨EvaluationMatrix.rows V X, EvaluationMatrix.ofRows_rows V X⟩
theorem uniform_matrix_law (β„“ : Nat) [Fintype V] [FiniteDimensional F2 V]
[Fintype (Module.Dual F2 V β†’β‚—[F2] (Fin β„“ β†’ F2))] :
(BucketSampler.tapeLaw β„“ (FiniteDistribution.uniform V)).pushforward
(fun t => EvaluationMatrix.ofRows V (BucketSampler.evaluate β„“ (id : V β†’ V) t)) =
FiniteDistribution.uniform (Module.Dual F2 V β†’β‚—[F2] (Fin β„“ β†’ F2)) := by
calc
_ = ((BucketSampler.tapeLaw β„“ (FiniteDistribution.uniform V)).pushforward
(BucketSampler.evaluate β„“ (id : V β†’ V))).pushforward
(EvaluationMatrix.ofRows V) :=
(FiniteDistribution.pushforward_comp _ _ _).symm
_ = (FiniteDistribution.uniform (Fin β„“ β†’ V)).pushforward
(EvaluationMatrix.ofRows V) := by rw [uniform_evaluate_law]
_ = _ := UniformLinearImage.uniform_pushforward_linearMap
(ofRowsLinear V β„“) (ofRowsLinear_surjective V β„“)
end
end PerfectCompleteness.BucketUniform
namespace PerfectCompleteness.RecursiveSamplerBiasAlgebra
open PointwiseSpaces RecursiveSpaces RecursiveSampler
open scoped BigOperators
universe u w
variable (π•œ : Type w) [Field π•œ]
def squareProduct {X : Type u} (H : Submodule π•œ (X β†’ π•œ)) :
H β†’β‚—[π•œ] H β†’β‚—[π•œ] squareSpace H :=
LinearMap.mkβ‚‚ π•œ
(fun g h => ⟨g.val * h.val, mul_mem_squareSpace H g.property h.property⟩)
(fun g g' h => Subtype.ext (add_mul g.val g'.val h.val))
(fun c g h => Subtype.ext (smul_mul_assoc c g.val h.val))
(fun g h h' => Subtype.ext (mul_add g.val h.val h'.val))
(fun c g h => Subtype.ext (mul_smul_comm c g.val h.val))
@[simp] theorem squareProduct_val {X : Type u} (H : Submodule π•œ (X β†’ π•œ))
(g h : H) : (squareProduct π•œ H g h).val = g.val * h.val := rfl
theorem square_functional_eq_zero_of_products {X : Type u}
(H : Submodule π•œ (X β†’ π•œ)) (L : squareSpace H β†’β‚—[π•œ] π•œ)
(hL : βˆ€ g h : H, L (squareProduct π•œ H g h) = 0) : L = 0 := by
apply LinearMap.ext
rintro ⟨x, hx⟩
change L ⟨x, hx⟩ = 0
refine Submodule.span_induction
(p := fun y hy => L ⟨y, hy⟩ = 0) ?_ ?_ ?_ ?_ hx
· rintro y ⟨g, hg, h, hh, rfl⟩
exact hL ⟨g, hg⟩ ⟨h, hh⟩
Β· exact map_zero L
Β· intro y z hy hz hLy hLz
change L ((⟨y, hy⟩ : squareSpace H) + ⟨z, hz⟩) = 0
rw [map_add, hLy, hLz, add_zero]
Β· intro c y hy hLy
change L (c β€’ (⟨y, hy⟩ : squareSpace H)) = 0
rw [map_smul, hLy, smul_zero]
variable {branch : Nat β†’ Nat} {n : Nat}
def childSquareLift (A : Slots branch (n + 1) β†’ Type u) (i : Fin (branch n)) :
squareSpace (space π•œ branch n (childFamily A i)) β†’β‚—[π•œ]
space π•œ branch (n + 1) A where
toFun g := ⟨pullback π•œ (childRestriction A i) g.val,
child_square_le_space A i (Submodule.mem_map_of_mem g.property)⟩
map_add' _ _ := Subtype.ext rfl
map_smul' _ _ := Subtype.ext rfl
@[simp] theorem childSquareLift_val (A : Slots branch (n + 1) β†’ Type u)
(i : Fin (branch n)) (g : squareSpace (space π•œ branch n (childFamily A i))) :
(childSquareLift π•œ A i g).val = pullback π•œ (childRestriction A i) g.val := rfl
def childProduct (A : Slots branch (n + 1) β†’ Type u) (i : Fin (branch n)) :
space π•œ branch n (childFamily A i) β†’β‚—[π•œ]
space π•œ branch n (childFamily A i) β†’β‚—[π•œ] space π•œ branch (n + 1) A :=
(squareProduct π•œ (space π•œ branch n (childFamily A i))).comprβ‚‚
(childSquareLift π•œ A i)
@[simp] theorem childProduct_val (A : Slots branch (n + 1) β†’ Type u)
(i : Fin (branch n)) (g h : space π•œ branch n (childFamily A i)) :
(childProduct π•œ A i g h).val =
pullback π•œ (childRestriction A i) (g.val * h.val) := rfl
def childBilinear (A : Slots branch (n + 1) β†’ Type u) (i : Fin (branch n))
(f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ) :
space π•œ branch n (childFamily A i) β†’β‚—[π•œ]
space π•œ branch n (childFamily A i) β†’β‚—[π•œ] π•œ :=
(childProduct π•œ A i).comprβ‚‚ f
@[simp] theorem childBilinear_apply (A : Slots branch (n + 1) β†’ Type u)
(i : Fin (branch n)) (f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ)
(g h : space π•œ branch n (childFamily A i)) :
childBilinear π•œ A i f g h =
f (childSquareLift π•œ A i
(squareProduct π•œ (space π•œ branch n (childFamily A i)) g h)) := rfl
theorem eq_zero_of_child_restrictions (A : Slots branch (n + 1) β†’ Type u)
(f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ)
(hzero : βˆ€ i : Fin (branch n), f.comp (childSquareLift π•œ A i) = 0) : f = 0 := by
apply LinearMap.ext
rintro ⟨x, hx⟩
change f ⟨x, hx⟩ = 0
refine Submodule.iSup_induction'
(fun i : Fin (branch n) =>
(squareSpace (space π•œ branch n (childFamily A i))).map
(pullback π•œ (childRestriction A i)))
(motive := fun y hy => f ⟨y, hy⟩ = 0) ?_ ?_ ?_ hx
Β· intro i y hy
obtain ⟨g, hg, rfl⟩ := Submodule.mem_map.mp hy
exact LinearMap.congr_fun (hzero i) ⟨g, hg⟩
Β· exact map_zero f
Β· intro y z hy hz hfy hfz
change f ((⟨y, hy⟩ : space π•œ branch (n + 1) A) + ⟨z, hz⟩) = 0
rw [map_add, hfy, hfz, add_zero]
theorem exists_child_restriction_ne_zero (A : Slots branch (n + 1) β†’ Type u)
(f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ) (hf : f β‰  0) :
βˆƒ i : Fin (branch n), f.comp (childSquareLift π•œ A i) β‰  0 := by
classical
by_contra h
apply hf
apply eq_zero_of_child_restrictions π•œ A f
intro i
by_contra hi
exact h ⟨i, hi⟩
theorem childBilinear_ne_zero (A : Slots branch (n + 1) β†’ Type u)
(i : Fin (branch n)) (f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ)
(hchild : f.comp (childSquareLift π•œ A i) β‰  0) :
childBilinear π•œ A i f β‰  0 := by
intro hzero
apply hchild
apply square_functional_eq_zero_of_products π•œ _ _
intro g h
exact LinearMap.congr_funβ‚‚ hzero g h
theorem ordinary_or_bilinear_ne_zero (A : Slots branch (n + 1) β†’ Type u)
(i : Fin (branch n)) (f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ) (hf : f β‰  0) :
(βˆƒ j : OffPath i, f.comp (childSquareLift π•œ A j.val) β‰  0) ∨
childBilinear π•œ A i f β‰  0 := by
classical
obtain ⟨j, hj⟩ := exists_child_restriction_ne_zero π•œ A f hf
by_cases hji : j = i
Β· subst j
exact Or.inr (childBilinear_ne_zero π•œ A i f hj)
· exact Or.inl ⟨⟨j, hji⟩, hj⟩
noncomputable section
theorem combine_eq (A : Slots branch (n + 1) β†’ Type u) (i : Fin (branch n))
(r : Nat)
(ordinary : (j : OffPath i) β†’ squareSpace (space π•œ branch n (childFamily A j.val)))
(left right : Fin r β†’ space π•œ branch n (childFamily A i)) :
combine π•œ A i r ordinary left right =
(βˆ‘ j : OffPath i, childSquareLift π•œ A j.val (ordinary j)) +
βˆ‘ h : Fin r, childProduct π•œ A i (left h) (right h) := by
apply Subtype.ext
change combineFunction π•œ A i r ordinary left right =
(space π•œ branch (n + 1) A).subtype
((βˆ‘ j : OffPath i, childSquareLift π•œ A j.val (ordinary j)) +
βˆ‘ h : Fin r, childProduct π•œ A i (left h) (right h))
rw [map_add, map_sum, map_sum]
rfl
theorem map_combine (A : Slots branch (n + 1) β†’ Type u) (i : Fin (branch n))
(r : Nat) (f : space π•œ branch (n + 1) A β†’β‚—[π•œ] π•œ)
(ordinary : (j : OffPath i) β†’ squareSpace (space π•œ branch n (childFamily A j.val)))
(left right : Fin r β†’ space π•œ branch n (childFamily A i)) :
f (combine π•œ A i r ordinary left right) =
(βˆ‘ j : OffPath i, (f.comp (childSquareLift π•œ A j.val)) (ordinary j)) +
βˆ‘ h : Fin r, childBilinear π•œ A i f (left h) (right h) := by
rw [combine_eq, map_add, map_sum, map_sum]
rfl
end
end PerfectCompleteness.RecursiveSamplerBiasAlgebra
namespace PerfectCompleteness.RecursiveSampler
open PointwiseSpaces RecursiveSpaces DescendantSpaces
open UniqueGamesTheorem.Foundations.Games
open scoped BigOperators
universe u w
variable {branch : Nat β†’ Nat} {n m : Nat}
abbrev CallIndex (repeats : Nat β†’ Nat) (n : Nat) := Fin (repeats (n + 1)) Γ— Bool
variable (π•œ : Type w) [Field π•œ]
abbrev OrdinaryTape (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u) :=
(j : OffPath i) β†’ DrawSpace π•œ repeats (.step i p) A (.inl j)
abbrev CallTapes (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u) :=
CallIndex repeats n β†’ Tape π•œ repeats p (childFamily A i)
def splitTapeEquiv (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u) :
Tape π•œ repeats (.step i p) A ≃
OrdinaryTape π•œ repeats i p A Γ— CallTapes π•œ repeats i p A where
toFun t := (fun j => t (.inl j), fun hb => subTape π•œ repeats i p A t hb.1 hb.2)
invFun z j := match j with
| .inl j => z.1 j
| .inr j => z.2 j.1 j.2
left_inv t := by
funext j
cases j <;> rfl
right_inv z := by
apply Prod.ext
Β· funext j
rfl
Β· funext hb j
rfl
noncomputable def evaluateCalls (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
(calls : CallTapes π•œ repeats i p A) :
CallIndex repeats n β†’ space π•œ branch n (childFamily A i) :=
fun hb => evaluate π•œ repeats p (childFamily A i) (calls hb)
noncomputable def splitEvaluatedTape (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
(t : Tape π•œ repeats (.step i p) A) :
OrdinaryTape π•œ repeats i p A Γ—
(CallIndex repeats n β†’ space π•œ branch n (childFamily A i)) :=
((splitTapeEquiv π•œ repeats i p A t).1,
evaluateCalls π•œ repeats i p A (splitTapeEquiv π•œ repeats i p A t).2)
noncomputable def stepCombine (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
(z : OrdinaryTape π•œ repeats i p A Γ—
(CallIndex repeats n β†’ space π•œ branch n (childFamily A i))) :
space π•œ branch (n + 1) A :=
combine π•œ A i (repeats (n + 1)) z.1
(fun h => z.2 (h, false)) (fun h => z.2 (h, true))
theorem stepCombine_splitEvaluatedTape (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
(t : Tape π•œ repeats (.step i p) A) :
stepCombine π•œ repeats i p A (splitEvaluatedTape π•œ repeats i p A t) =
evaluate π•œ repeats (.step i p) A t := rfl
noncomputable section
variable [Finite π•œ]
instance childFamilyFinite (A : Slots branch (n + 1) β†’ Type u)
[hA : βˆ€ s, Finite (A s)] (i : Fin (branch n)) :
βˆ€ s, Finite (childFamily A i s) := fun s => hA (i, s)
instance childSquareFintype (A : Slots branch (n + 1) β†’ Type u)
[hA : βˆ€ s, Finite (A s)] (i : Fin (branch n)) :
Fintype (squareSpace (space π•œ branch n (childFamily A i))) := by
letI : βˆ€ s, Finite (childFamily A i s) := fun s => hA (i, s)
exact Fintype.ofFinite _
instance ordinaryDrawFintype (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] (j : OffPath i) :
Fintype (DrawSpace π•œ repeats (.step i p) A (.inl j)) :=
drawSpaceFintype π•œ repeats (.step i p) A (.inl j)
instance ordinaryTapeFintype (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] : Fintype (OrdinaryTape π•œ repeats i p A) := by
letI : βˆ€ j : OffPath i, Fintype (DrawSpace π•œ repeats (.step i p) A (.inl j)) :=
fun j => drawSpaceFintype π•œ repeats (.step i p) A (.inl j)
exact Pi.instFintype
instance callTapesFintype (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[hA : βˆ€ s, Finite (A s)] : Fintype (CallTapes π•œ repeats i p A) := by
letI : βˆ€ s, Finite (childFamily A i s) := fun s => hA (i, s)
letI : Fintype (Tape π•œ repeats p (childFamily A i)) :=
@Pi.instFintype (DrawIndex repeats p)
(DrawSpace π•œ repeats p (childFamily A i))
(drawIndexDecidableEq repeats p) (drawIndexFintype repeats p)
(fun j => drawSpaceFintype π•œ repeats p (childFamily A i) j)
exact Pi.instFintype
def ordinaryLaw (π•œ : Type w) [Field π•œ] [Finite π•œ]
(repeats : Nat β†’ Nat) (i : Fin (branch n)) (p : Path branch n m)
(A : Slots branch (n + 1) β†’ Type u) [βˆ€ s, Finite (A s)] :
FiniteDistribution (OrdinaryTape π•œ repeats i p A) := by
letI : βˆ€ j : OffPath i, Fintype (DrawSpace π•œ repeats (.step i p) A (.inl j)) :=
fun j => drawSpaceFintype π•œ repeats (.step i p) A (.inl j)
letI : βˆ€ j : OffPath i, Nonempty (DrawSpace π•œ repeats (.step i p) A (.inl j)) :=
fun j => ⟨zeroDraw π•œ repeats (.step i p) A (.inl j)⟩
exact FiniteProduct.law (fun j : OffPath i =>
FiniteDistribution.uniform (DrawSpace π•œ repeats (.step i p) A (.inl j)))
def callTapeLaw (π•œ : Type w) [Field π•œ] [Finite π•œ]
(repeats : Nat β†’ Nat) (i : Fin (branch n)) (p : Path branch n m)
(A : Slots branch (n + 1) β†’ Type u) [hA : βˆ€ s, Finite (A s)] :
FiniteDistribution (CallTapes π•œ repeats i p A) := by
letI : βˆ€ s, Finite (childFamily A i s) := fun s => hA (i, s)
exact FiniteProduct.law (fun _ : CallIndex repeats n =>
tapeLaw π•œ repeats p (childFamily A i))
theorem splitTape_law (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] :
(tapeLaw π•œ repeats (.step i p) A).pushforward (splitTapeEquiv π•œ repeats i p A) =
(ordinaryLaw π•œ repeats i p A).product (callTapeLaw π•œ repeats i p A) := by
rw [← FiniteDistribution.transport_eq_pushforward]
apply FiniteDistribution.eq_of_weight_eq
intro z
let : βˆ€ j : OffPath i βŠ• (CallIndex repeats n Γ— DrawIndex repeats p),
Fintype (DrawSpace π•œ repeats (.step i p) A j) :=
fun j => drawSpaceFintype π•œ repeats (.step i p) A j
change
(∏ j : OffPath i βŠ• (CallIndex repeats n Γ— DrawIndex repeats p),
1 / (Fintype.card (DrawSpace π•œ repeats (.step i p) A j) : ℝ)) =
(∏ j : OffPath i,
1 / (Fintype.card (DrawSpace π•œ repeats (.step i p) A (.inl j)) : ℝ)) *
∏ _hb : CallIndex repeats n, ∏ j : DrawIndex repeats p,
1 / (Fintype.card (DrawSpace π•œ repeats p (childFamily A i) j) : ℝ)
rw [Fintype.prod_sum_type, Fintype.prod_prod_type]
simp only [Fintype.card_eq_nat_card]
rfl
theorem subTape_tuple_law (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] :
(tapeLaw π•œ repeats (.step i p) A).pushforward
(fun t (hb : CallIndex repeats n) => subTape π•œ repeats i p A t hb.1 hb.2) =
callTapeLaw π•œ repeats i p A := by
calc
_ = ((tapeLaw π•œ repeats (.step i p) A).pushforward
(splitTapeEquiv π•œ repeats i p A)).pushforward Prod.snd :=
(FiniteDistribution.pushforward_comp _ _ Prod.snd).symm
_ = _ := by
rw [splitTape_law, FiniteDistribution.product_pushforward_snd]
def callScalarLaw (π•œ : Type w) [Field π•œ] [Finite π•œ]
(repeats : Nat β†’ Nat) (i : Fin (branch n)) (p : Path branch n m)
(A : Slots branch (n + 1) β†’ Type u) [hA : βˆ€ s, Finite (A s)]
[Fintype (space π•œ branch n (childFamily A i))] :
FiniteDistribution (CallIndex repeats n β†’ space π•œ branch n (childFamily A i)) := by
letI : βˆ€ s, Finite (childFamily A i s) := fun s => hA (i, s)
exact FiniteProduct.law (fun _ : CallIndex repeats n =>
law π•œ repeats p (childFamily A i))
theorem evaluateCalls_law (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] [Fintype (space π•œ branch n (childFamily A i))] :
(callTapeLaw π•œ repeats i p A).pushforward (evaluateCalls π•œ repeats i p A) =
callScalarLaw π•œ repeats i p A :=
FiniteProduct.pushforward_map _ (fun _ => evaluate π•œ repeats p (childFamily A i))
theorem splitEvaluatedTape_law (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] [Fintype (space π•œ branch n (childFamily A i))] :
(tapeLaw π•œ repeats (.step i p) A).pushforward
(splitEvaluatedTape π•œ repeats i p A) =
(ordinaryLaw π•œ repeats i p A).product (callScalarLaw π•œ repeats i p A) := by
calc
_ = ((tapeLaw π•œ repeats (.step i p) A).pushforward
(splitTapeEquiv π•œ repeats i p A)).pushforward
(fun z => (z.1, evaluateCalls π•œ repeats i p A z.2)) :=
(FiniteDistribution.pushforward_comp _ _ _).symm
_ = ((ordinaryLaw π•œ repeats i p A).product
(callTapeLaw π•œ repeats i p A)).pushforward
(fun z => (z.1, evaluateCalls π•œ repeats i p A z.2)) := by
rw [splitTape_law]
_ = (ordinaryLaw π•œ repeats i p A).product
((callTapeLaw π•œ repeats i p A).pushforward
(evaluateCalls π•œ repeats i p A)) := by
simpa only [id_eq, FiniteDistribution.pushforward_id] using
(FiniteDistribution.product_pushforward
(ordinaryLaw π•œ repeats i p A) (callTapeLaw π•œ repeats i p A)
(id : OrdinaryTape π•œ repeats i p A β†’ OrdinaryTape π•œ repeats i p A)
(evaluateCalls π•œ repeats i p A))
_ = _ := by rw [evaluateCalls_law]
theorem law_step (repeats : Nat β†’ Nat) (i : Fin (branch n))
(p : Path branch n m) (A : Slots branch (n + 1) β†’ Type u)
[βˆ€ s, Finite (A s)] [Fintype (space π•œ branch n (childFamily A i))]
[Fintype (space π•œ branch (n + 1) A)] :
law π•œ repeats (.step i p) A =
((ordinaryLaw π•œ repeats i p A).product
(callScalarLaw π•œ repeats i p A)).pushforward
(stepCombine π•œ repeats i p A) := by
calc
_ = ((tapeLaw π•œ repeats (.step i p) A).pushforward
(splitEvaluatedTape π•œ repeats i p A)).pushforward
(stepCombine π•œ repeats i p A) :=
(FiniteDistribution.pushforward_comp _ _ _).symm
_ = _ := by rw [splitEvaluatedTape_law]
end
end PerfectCompleteness.RecursiveSampler
end OAI