File size: 5,763 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
import Mathlib.Logic.Equiv.Prod
import OAI.Computability.PerfectCompleteness.Construction.HiddenBucketBias
import OAI.Computability.PerfectCompleteness.Foundations.TerminalCalls
import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerRefinement
import OAI.Computability.UniqueGames.Foundations.SamplingLemmas

namespace OAI

section

namespace PerfectCompleteness.CutTerminalSplit

open PointwiseSpaces RecursiveSpaces DescendantSpaces RecursiveSampler TerminalCalls
open UniqueGamesTheorem.Foundations.Games
open scoped Classical

noncomputable section

universe u w

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

theorem refinedSpace_eq_terminal (𝕜 : Type w) [Field 𝕜]
    (repeats : Nat → Nat) (p : Path branch n m) :
    ∀ (A : Slots branch n → Type u) (terminal : TerminalIndex repeats p),
      CutSamplerRefinement.RefinedSpace 𝕜 repeats p A (drawIndex repeats p terminal) =
        CutSamplerRefinement.RefinedSpace 𝕜 repeats (.refl m) (p.family A) () := by
  induction p with
  | refl n =>
      intro A terminal
      cases terminal
      rfl
  | step i p ih =>
      intro A terminal
      exact ih (childFamily A i) terminal.2

variable (𝕜 : Type w) [Field 𝕜] (repeats : Nat → Nat)
  (p : Path branch n (m + 1)) (A : Slots branch n → Type u)

abbrev TerminalFactor :=
  (i : Fin (branch m)) → squareSpace (space 𝕜 branch m (childFamily (p.family A) i))

abbrev TerminalTape := TerminalIndex repeats p → TerminalFactor 𝕜 p A

abbrev ExteriorIndex := {j : DrawIndex repeats p // ¬ IsTerminal repeats p j}

abbrev ExteriorTape :=
  (j : ExteriorIndex repeats p) → CutSamplerRefinement.RefinedSpace 𝕜 repeats p A j.val

def terminalFactorEquiv (terminal : TerminalIndex repeats p) :
    CutSamplerRefinement.RefinedSpace 𝕜 repeats p A (drawIndex repeats p terminal) ≃
      TerminalFactor 𝕜 p A :=
  Equiv.cast (refinedSpace_eq_terminal 𝕜 repeats p A terminal)

def terminalTapeEquiv :
    ((j : {j : DrawIndex repeats p // IsTerminal repeats p j}) →
      CutSamplerRefinement.RefinedSpace 𝕜 repeats p A j.val) ≃
        TerminalTape 𝕜 repeats p A :=
  ((Equiv.piCongrLeft
    (fun j : {j : DrawIndex repeats p // IsTerminal repeats p j} =>
      CutSamplerRefinement.RefinedSpace 𝕜 repeats p A j.val)
    (terminalSubtypeEquiv repeats p)).symm).trans
      (Equiv.piCongrRight (terminalFactorEquiv 𝕜 repeats p A))

def splitTape :
    CutSamplerRefinement.Tape 𝕜 repeats p A ≃
      TerminalTape 𝕜 repeats p A × ExteriorTape 𝕜 repeats p A :=
  (Equiv.piEquivPiSubtypeProd (IsTerminal repeats p)
    (CutSamplerRefinement.RefinedSpace 𝕜 repeats p A)).trans
      (Equiv.prodCongr (terminalTapeEquiv 𝕜 repeats p A) (Equiv.refl _))

@[simp] theorem splitTape_terminal_apply
    (x : CutSamplerRefinement.Tape 𝕜 repeats p A) (terminal : TerminalIndex repeats p) :
    (splitTape 𝕜 repeats p A x).1 terminal =
      terminalFactorEquiv 𝕜 repeats p A terminal (x (drawIndex repeats p terminal)) := rfl

@[simp] theorem splitTape_exterior_apply
    (x : CutSamplerRefinement.Tape 𝕜 repeats p A) (j : ExteriorIndex repeats p) :
    (splitTape 𝕜 repeats p A x).2 j = x j.val := rfl

variable [Finite 𝕜] [∀ s, Finite (A s)]

instance childSquareFintype (i : Fin (branch m)) :
    Fintype (squareSpace (space 𝕜 branch m (childFamily (p.family A) i))) :=
  Fintype.ofFinite _

def terminalLaw : FiniteDistribution (TerminalTape 𝕜 repeats p A) :=
  FiniteProduct.law (fun _ : TerminalIndex repeats p =>
    FiniteProduct.law (fun i : Fin (branch m) =>
      FiniteDistribution.uniform
        (squareSpace (space 𝕜 branch m (childFamily (p.family A) i)))))

def exteriorLaw : FiniteDistribution (ExteriorTape 𝕜 repeats p A) :=
  FiniteProduct.law (fun j : ExteriorIndex repeats p =>
    FiniteDistribution.uniform (CutSamplerRefinement.RefinedSpace 𝕜 repeats p A j.val))

theorem terminalLaw_uniform :
    terminalLaw 𝕜 repeats p A = FiniteDistribution.uniform (TerminalTape 𝕜 repeats p A) := by
  simp only [terminalLaw, UniformLinearImage.law_uniform]

theorem exteriorLaw_uniform :
    exteriorLaw 𝕜 repeats p A = FiniteDistribution.uniform (ExteriorTape 𝕜 repeats p A) :=
  UniformLinearImage.law_uniform

theorem split_tapeLaw :
    (CutSamplerRefinement.tapeLaw 𝕜 repeats p A).pushforward (splitTape 𝕜 repeats p A) =
      (terminalLaw 𝕜 repeats p A).product (exteriorLaw 𝕜 repeats p A) := by
  unfold CutSamplerRefinement.tapeLaw
  rw [UniformLinearImage.law_uniform, FiniteDistribution.pushforward_equiv,
    terminalLaw_uniform, exteriorLaw_uniform]
  apply FiniteDistribution.eq_of_weight_eq
  intro x
  change 1 / (Fintype.card (CutSamplerRefinement.Tape 𝕜 repeats p A) : ℝ) =
    (1 / (Fintype.card (TerminalTape 𝕜 repeats p A) : ℝ)) *
      (1 / (Fintype.card (ExteriorTape 𝕜 repeats p A) : ℝ))
  rw [Fintype.card_congr (splitTape 𝕜 repeats p A), Fintype.card_prod]
  simp only [Nat.cast_mul, one_div, mul_inv]

theorem terminal_marginal :
    (CutSamplerRefinement.tapeLaw 𝕜 repeats p A).pushforward
        (fun x => (splitTape 𝕜 repeats p A x).1) = terminalLaw 𝕜 repeats p A := by
  rw [← FiniteDistribution.pushforward_comp (CutSamplerRefinement.tapeLaw 𝕜 repeats p A)
    (splitTape 𝕜 repeats p A) Prod.fst, split_tapeLaw]
  exact HiddenBucketBias.product_fst
    (terminalLaw 𝕜 repeats p A) (exteriorLaw 𝕜 repeats p A)

theorem terminal_marginal_uniform :
    (CutSamplerRefinement.tapeLaw 𝕜 repeats p A).pushforward
        (fun x => (splitTape 𝕜 repeats p A x).1) =
      FiniteDistribution.uniform (TerminalTape 𝕜 repeats p A) := by
  rw [terminal_marginal, terminalLaw_uniform]

end
end PerfectCompleteness.CutTerminalSplit

end

end OAI