File size: 8,603 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
import OAI.Computability.PerfectCompleteness.Machines.MetadataFreeTapeLemmas
import OAI.Computability.PerfectCompleteness.Sampling.SamplerCardinalityLemmas

namespace OAI

section

namespace PerfectCompleteness.MetadataFreeLaw

open RecursiveSpaces DescendantSpaces TreeSourceSpaces
open MetadataFreeSampler MetadataFreeTape
open UniqueGamesTheorem.Foundations.Games
open scoped BigOperators Classical

noncomputable section

variable {branch : Nat → Nat} {n d t v m : Nat}

theorem tape_weight_eq (clauses : Fin m → SourceClause.NormalizedClause v)
    (rows repeats : Nat → Nat) (p : Path branch n d) :
    ∀ (q : PreliminarySampler.Questions branch n t m)
      (ω : WholeArraySampler.Tape rows repeats p (sourceSlots clauses q)),
      (WholeArraySampler.tapeLaw rows repeats p (sourceSlots clauses q)).weight ω =
        (WholeArraySampler.tapeLaw rows repeats p (dummyTreeSlots (sourceSigns clauses q))).weight
          (tapeEquiv clauses rows repeats p q ω) := by
  induction p with
  | refl n =>
      intro q ω
      rfl
  | @step n d i p ih =>
      intro q ω
      change (∏ k : WholeArraySampler.StepIndex i,
        (WholeArraySampler.componentLaw rows repeats i p (sourceSlots clauses q) k).weight (ω k)) =
        ∏ k : WholeArraySampler.StepIndex i,
          (WholeArraySampler.componentLaw rows repeats i p
            (dummyTreeSlots (sourceSigns clauses q)) k).weight
              (tapeEquiv clauses rows repeats (.step i p) q ω k)
      apply Finset.prod_congr rfl
      intro k _
      rcases k with u | (u | j)
      · rfl
      · cases u
        exact ih (fun leaf k => q (i, leaf) k) (ω (.inr (.inl ())))
      · rfl

theorem tapeLaw_transport (clauses : Fin m → SourceClause.NormalizedClause v)
    (rows repeats : Nat → Nat) (p : Path branch n d)
    (q : PreliminarySampler.Questions branch n t m) :
    (WholeArraySampler.tapeLaw rows repeats p (sourceSlots clauses q)).transport
        (tapeEquiv clauses rows repeats p q) =
      WholeArraySampler.tapeLaw rows repeats p (dummyTreeSlots (sourceSigns clauses q)) := by
  apply FiniteDistribution.eq_of_weight_eq
  intro ω
  change (WholeArraySampler.tapeLaw rows repeats p (sourceSlots clauses q)).weight
      ((tapeEquiv clauses rows repeats p q).symm ω) = _
  simpa only [Equiv.apply_symm_apply] using
    tape_weight_eq clauses rows repeats p q ((tapeEquiv clauses rows repeats p q).symm ω)

abbrev SignedOutcome (signs : SignTuple branch n t) (rows repeats : Nat → Nat) :=
  Σ leaf : Slots branch n,
    WholeArraySampler.Tape rows repeats (GeometricPath.leafPath leaf) (dummyTreeSlots signs) ×
      PreliminarySampler.Choice rows leaf

def signedLaw (signs : SignTuple branch n t) (rows repeats : Nat → Nat)
    (hn : 0 < n) (hbranch : ∀ k < n, 0 < branch k)
    (hrows : ∀ k, 0 < rows (k + 1)) : FiniteDistribution (SignedOutcome signs rows repeats) :=
  CompletionSoundness.sigmaLaw (GeometricPath.law n hbranch) fun leaf =>
    (WholeArraySampler.tapeLaw rows repeats (GeometricPath.leafPath leaf) (dummyTreeSlots signs)).product
      (PreliminarySampler.choiceLaw leaf hn hrows)

def signedRationalLaw (signs : SignTuple branch n t) (rows repeats : Nat → Nat)
    (hn : 0 < n) (hbranch : ∀ k < n, 0 < branch k) (hrows : ∀ k, 0 < rows (k + 1)) :
    RationalFiniteLaw.RationalLaw (signedLaw signs rows repeats hn hbranch hrows) :=
  RationalFiniteLaw.sigma (SamplerRationality.pathLaw hbranch) fun leaf =>
    RationalFiniteLaw.product
      (SamplerRationality.wholeArrayTapeLaw rows repeats (GeometricPath.leafPath leaf)
        (dummyTreeSlots signs))
      (SamplerRationality.choiceLaw leaf hn hrows)

theorem signedLaw_positive (signs : SignTuple branch n t) (rows repeats : Nat → Nat)
    (hn : 0 < n) (hbranch : ∀ k < n, 0 < branch k) (hrows : ∀ k, 0 < rows (k + 1))
    (e : SignedOutcome signs rows repeats) :
    0 < (signedLaw signs rows repeats hn hbranch hrows).weight e :=
  RationalFiniteLaw.real_positive (signedRationalLaw signs rows repeats hn hbranch hrows) e

def encodeOutcome (clauses : Fin m → SourceClause.NormalizedClause v) (rows repeats : Nat → Nat)
    (e : PreliminarySampler.Raw clauses branch n t rows repeats) :
    SignedOutcome (sourceSigns clauses e.1.1) rows repeats :=
  ⟨e.1.2, tapeEquiv clauses rows repeats (GeometricPath.leafPath e.1.2) e.1.1 e.2.1, e.2.2⟩

theorem raw_weight_eq [NeZero m] (clauses : Fin m → SourceClause.NormalizedClause v)
    (rows repeats : Nat → Nat) (hn : 0 < n)
    (hbranch : ∀ k < n, 0 < branch k) (hrows : ∀ k, 0 < rows (k + 1))
    (e : PreliminarySampler.Raw clauses branch n t rows repeats) :
    (PreliminarySampler.law clauses rows repeats hn hbranch hrows).weight e =
      (1 / (Fintype.card (PreliminarySampler.Questions branch n t m) : ℝ)) *
        (signedLaw (sourceSigns clauses e.1.1) rows repeats hn hbranch hrows).weight
          (encodeOutcome clauses rows repeats e) := by
  change ((1 / (Fintype.card (PreliminarySampler.Questions branch n t m) : ℝ)) *
      (GeometricPath.law n hbranch).weight e.1.2) *
      ((WholeArraySampler.tapeLaw rows repeats (GeometricPath.leafPath e.1.2)
        (sourceSlots clauses e.1.1)).weight e.2.1 *
        (PreliminarySampler.choiceLaw e.1.2 hn hrows).weight e.2.2) =
    (1 / (Fintype.card (PreliminarySampler.Questions branch n t m) : ℝ)) *
      ((GeometricPath.law n hbranch).weight e.1.2 *
        ((WholeArraySampler.tapeLaw rows repeats (GeometricPath.leafPath e.1.2)
          (dummyTreeSlots (sourceSigns clauses e.1.1))).weight
            (tapeEquiv clauses rows repeats (GeometricPath.leafPath e.1.2) e.1.1 e.2.1) *
          (PreliminarySampler.choiceLaw e.1.2 hn hrows).weight e.2.2))
  rw [tape_weight_eq clauses rows repeats (GeometricPath.leafPath e.1.2) e.1.1 e.2.1]
  exact mul_assoc _ _ _

theorem raw_weight_rational [NeZero m] (clauses : Fin m → SourceClause.NormalizedClause v)
    (rows repeats : Nat → Nat) (hn : 0 < n)
    (hbranch : ∀ k < n, 0 < branch k) (hrows : ∀ k, 0 < rows (k + 1))
    (e : PreliminarySampler.Raw clauses branch n t rows repeats) :
    (PreliminarySampler.law clauses rows repeats hn hbranch hrows).weight e =
      (1 / (Fintype.card (PreliminarySampler.Questions branch n t m) : ℝ)) *
        ((signedRationalLaw (sourceSigns clauses e.1.1) rows repeats hn hbranch hrows).weights
          (encodeOutcome clauses rows repeats e) : ℝ) := by
  rw [raw_weight_eq, (signedRationalLaw (sourceSigns clauses e.1.1)
    rows repeats hn hbranch hrows).cast_weight]

def rawEquiv (clauses : Fin m → SourceClause.NormalizedClause v) (rows repeats : Nat → Nat) :
    PreliminarySampler.Raw clauses branch n t rows repeats ≃
      (Σ q : PreliminarySampler.Questions branch n t m,
        SignedOutcome (sourceSigns clauses q) rows repeats) where
  toFun e := ⟨e.1.1, encodeOutcome clauses rows repeats e⟩
  invFun y := ⟨(y.1, y.2.1),
    (tapeEquiv clauses rows repeats (GeometricPath.leafPath y.2.1) y.1).symm y.2.2.1,
    y.2.2.2⟩
  left_inv := by
    rintro ⟨⟨q, leaf⟩, ω, choice⟩
    simp only [encodeOutcome]
    exact congrArg
      (fun tape : WholeArraySampler.Tape rows repeats (GeometricPath.leafPath leaf)
          (sourceSlots clauses q) =>
        (⟨(q, leaf), tape, choice⟩ : PreliminarySampler.Raw clauses branch n t rows repeats))
      ((tapeEquiv clauses rows repeats (GeometricPath.leafPath leaf) q).symm_apply_apply ω)
  right_inv := by
    rintro ⟨q, leaf, ω, choice⟩
    simp only [encodeOutcome, Equiv.apply_symm_apply]

theorem rawLaw_transport [NeZero m] (clauses : Fin m → SourceClause.NormalizedClause v)
    (rows repeats : Nat → Nat) (hn : 0 < n)
    (hbranch : ∀ k < n, 0 < branch k) (hrows : ∀ k, 0 < rows (k + 1)) :
    (PreliminarySampler.law (t := t) clauses rows repeats hn hbranch hrows).transport
        (rawEquiv clauses rows repeats) =
      CompletionSoundness.sigmaLaw PreliminarySampler.questionsLaw
        (fun q => signedLaw (sourceSigns clauses q) rows repeats hn hbranch hrows) := by
  apply FiniteDistribution.eq_of_weight_eq
  rintro ⟨q, leaf, ω, choice⟩
  change (PreliminarySampler.law clauses rows repeats hn hbranch hrows).weight
      ⟨(q, leaf), (tapeEquiv clauses rows repeats (GeometricPath.leafPath leaf) q).symm ω,
        choice⟩ =
    (1 / (Fintype.card (PreliminarySampler.Questions branch n t m) : ℝ)) *
      (signedLaw (sourceSigns clauses q) rows repeats hn hbranch hrows).weight ⟨leaf, ω, choice⟩
  rw [raw_weight_eq]
  simp only [encodeOutcome, Equiv.apply_symm_apply]

end
end PerfectCompleteness.MetadataFreeLaw

end

end OAI