File size: 11,507 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import OAI.Computability.PerfectCompleteness.Foundations.OddListExtraction
import OAI.Computability.PerfectCompleteness.Foundations.SourceOddListsLemmas
import OAI.Computability.PerfectCompleteness.Repetition.RepetitionRateLemmas

namespace OAI

section

namespace PerfectCompleteness.SourceLocalOddLists

open scoped Classical
open PointwiseSpaces TreeSourceSpaces SourceAnswerEquiv
open UniqueGamesTheorem.Foundations.Games

abbrev F2 := ZMod 2

noncomputable section

variable {branch : Nat → Nat} {h t v m s : Nat}

abbrev Form (slots : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot) :=
  H slots →ₗ[F2] H slots →ₗ[F2] F2

def leafSupport (slots : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot)
    (F : Form slots) (leaf : RecursiveSpaces.Slots branch h) : Finset (LeafDomain slots leaf) :=
  OddLists.support (fun a => F
    (OddListExtraction.atom (H slots) (fun x => x leaf)
      (OddListExtraction.source_leaf_indicator_mem slots leaf) a)
    (OddListExtraction.atom (H slots) (fun x => x leaf)
      (OddListExtraction.source_leaf_indicator_mem slots leaf) a))

def extract (positive : 0 < s)
    (slots : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot)
    (F : Form slots) (leaf : RecursiveSpaces.Slots branch h) (fallback : LeafDomain slots leaf) :
    OddLists.OddList s (LeafDomain slots leaf) :=
  OddLists.OddList.extract positive fallback (leafSupport slots F leaf)

theorem extract_accepts (positive : 0 < s)
    {slots projected : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot}
    (p : ∀ leaf k, MixedSupport.Projection (slots leaf k) (projected leaf k))
    (leaf : RecursiveSpaces.Slots branch h) (F : Form slots) (F' : Form projected)
    (z : Module.Dual F2 (squareSpace (H slots)))
    (hform : F = OddListExtraction.multiplicationForm (H slots) z)
    (hone : (1 : Domain slots → F2) ∈ squareSpace (H slots))
    (hnorm : z ⟨1, hone⟩ = 1) (hrank : OddListExtraction.formRank (H slots) F ≤ s)
    (hagree : ∀ f g, F' f g = OddListExtraction.multiplicationForm (H slots) z
      (HPullback p f) (HPullback p g))
    (leftFallback : LeafDomain slots leaf) (rightFallback : LeafDomain projected leaf) :
    OddLists.OddList.map (MixedSupport.projectionMap (p leaf))
      (extract positive slots F leaf leftFallback) =
      extract positive projected F' leaf rightFallback := by
  have hleft : Odd (leafSupport slots F leaf).card ∧ (leafSupport slots F leaf).card ≤ s := by
    rw [hform] at hrank ⊢
    exact (OddListExtraction.extractedList (H slots) (fun x => x leaf)
      (OddListExtraction.source_leaf_indicator_mem slots leaf) z hone hnorm s hrank).property
  have hsupport : leafSupport projected F' leaf =
      OddLists.parityPushforward (MixedSupport.projectionMap (p leaf)) (leafSupport slots F leaf) := by
    rw [hform]
    exact OddListExtraction.source_projected_support p leaf z F' hagree
  have hright : Odd (leafSupport projected F' leaf).card ∧
      (leafSupport projected F' leaf).card ≤ s := by
    rw [hsupport]
    exact ⟨OddLists.parityPushforward_odd _ _ hleft.1,
      (OddLists.parityPushforward_card_le _ _).trans hleft.2⟩
  apply Subtype.ext
  rw [OddLists.OddList.map_val]
  change OddLists.parityPushforward (MixedSupport.projectionMap (p leaf))
      (OddLists.OddList.extract positive leftFallback (leafSupport slots F leaf)).val =
    (OddLists.OddList.extract positive rightFallback (leafSupport projected F' leaf)).val
  rw [OddLists.OddList.extract_valid positive leftFallback _ hleft,
    OddLists.OddList.extract_valid positive rightFallback _ hright]
  exact hsupport.symm

private theorem map_eq_of_map_eq {A B : Type*} {s : Nat}
    {f₁ f₂ : Fintype B} {d₁ d₂ : DecidableEq B}
    (π : A → B) (L : OddLists.OddList s A) (R : OddLists.OddList s B)
    (accepted : @OddLists.OddList.map A B s f₁ d₁ π L = R) :
    @OddLists.OddList.map A B s f₂ d₂ π L = R := by
  have hf : f₁ = f₂ := Subsingleton.elim _ _
  cases hf
  have hd : d₁ = d₂ := Subsingleton.elim _ _
  cases hd
  exact accepted

variable (clauses : Fin m → SourceClause.NormalizedClause v)

abbrev LeftQuestions := RecursiveSpaces.Slots branch h → Fin t → Fin m
abbrev RightQuestions := RecursiveSpaces.Slots branch h → Fin t → Fin v
abbrev Occurrences := RecursiveSpaces.Slots branch h → SourceOddLists.Occurrences m t

abbrev LeftForms := (q : LeftQuestions (branch := branch) (h := h) (t := t) (m := m)) →
  Form (leftTreeSlots clauses q)

abbrev RightForms := (q : RightQuestions (branch := branch) (h := h) (t := t) (v := v)) →
  Form (rightTreeSlots clauses q)

def leftResponse (positive : 0 < s) (forms : LeftForms (branch := branch) (h := h) (t := t) clauses)
    (q : LeftQuestions (branch := branch) (h := h) (t := t) (m := m))
    (leaf : RecursiveSpaces.Slots branch h) : OddLists.OddList s (SourceOddLists.LeftLabels t) :=
  encodeOddList clauses (q leaf)
    (extract positive (leftTreeSlots clauses q) (forms q) leaf
      ((leftEquiv clauses (q leaf)).symm (fun _ => 0)))

def rightResponse (positive : 0 < s) (forms : RightForms (branch := branch) (h := h) (t := t) clauses)
    (q : RightQuestions (branch := branch) (h := h) (t := t) (v := v))
    (leaf : RecursiveSpaces.Slots branch h) : OddLists.OddList s (SourceOddLists.RightLabels t) :=
  extract positive (rightTreeSlots clauses q) (forms q) leaf (fun _ => false)

def treeProjection (e : Occurrences (branch := branch) (h := h) (m := m) (t := t)) :
    ∀ leaf k, MixedSupport.Projection
      (leftTreeSlots clauses (fun j => SourceOddLists.left (e j)) leaf k)
      (rightTreeSlots clauses (fun j => SourceOddLists.right clauses (e j)) leaf k) :=
  fun leaf => slotProjection clauses (e leaf)

section Clean

variable (clean : RecursiveSpaces.Slots branch h → Prop)

abbrev CleanLeaves := {leaf : RecursiveSpaces.Slots branch h // clean leaf}

def fill {Q : Type*} (background : RecursiveSpaces.Slots branch h → Q)
    (q : CleanLeaves clean → Q) : RecursiveSpaces.Slots branch h → Q :=
  fun leaf => if hc : clean leaf then q ⟨leaf, hc⟩ else background leaf

@[simp] theorem fill_clean {Q : Type*} (background : RecursiveSpaces.Slots branch h → Q)
    (q : CleanLeaves clean → Q) (leaf : CleanLeaves clean) :
    fill clean background q leaf.val = q leaf := by
  simp only [fill, dite_eq_left leaf.property]

theorem fill_comp {Q R : Type*} (background : RecursiveSpaces.Slots branch h → Q)
    (q : CleanLeaves clean → Q) (f : Q → R) :
    fill clean (fun leaf => f (background leaf)) (fun leaf => f (q leaf)) =
      fun leaf => f (fill clean background q leaf) := by
  funext leaf
  by_cases hc : clean leaf
  · simp only [fill, dite_eq_left hc]
  · simp only [fill, dite_eq_right hc]

variable (background : Occurrences (branch := branch) (h := h) (m := m) (t := t))

def strategy (positive : 0 < s) (leftForms : LeftForms (branch := branch) (h := h) (t := t) clauses) (rightForms : RightForms (branch := branch) (h := h) (t := t) clauses) :
    Strategy (CleanLeaves clean → Fin t → Fin m) (CleanLeaves clean → Fin t → Fin v)
      (CleanLeaves clean → OddLists.OddList s (SourceOddLists.LeftLabels t))
      (CleanLeaves clean → OddLists.OddList s (SourceOddLists.RightLabels t)) :=
  (fun q leaf => leftResponse clauses positive leftForms
      (fill clean (fun j => SourceOddLists.left (background j)) q) leaf.val,
   fun q leaf => rightResponse clauses positive rightForms
      (fill clean (fun j => SourceOddLists.right clauses (background j)) q) leaf.val)

theorem strategy_wins [NeZero m] (positive : 0 < s)
    (leftForms : LeftForms (branch := branch) (h := h) (t := t) clauses) (rightForms : RightForms (branch := branch) (h := h) (t := t) clauses)
    (e : CleanLeaves clean → SourceOddLists.Occurrences m t)
    (z : Module.Dual F2 (squareSpace
      (H (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j))))))
    (hform : leftForms (fun j => SourceOddLists.left (fill clean background e j)) =
      OddListExtraction.multiplicationForm
        (H (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j)))) z)
    (hone :
      (1 : Domain (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j))) → F2) ∈
      squareSpace (H (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j)))))
    (hnorm : z ⟨1, hone⟩ = 1)
    (hrank : OddListExtraction.formRank
      (H (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j))))
      (leftForms (fun j => SourceOddLists.left (fill clean background e j))) ≤ s)
    (hagree : ∀ f g,
      rightForms (fun j => SourceOddLists.right clauses (fill clean background e j)) f g =
      OddListExtraction.multiplicationForm
        (H (leftTreeSlots clauses (fun j => SourceOddLists.left (fill clean background e j)))) z
        (HPullback (treeProjection clauses (fill clean background e)) f)
        (HPullback (treeProjection clauses (fill clean background e)) g)) :
    (IndexedRepetition.game (SourceOddLists.game s clauses t) (CleanLeaves clean)).wins
      (strategy clauses clean background positive leftForms rightForms) e = true := by
  simp only [OccurrenceGame.wins, IndexedRepetition.game, SourceOddLists.game,
    OddListGame.game, OccurrenceGame.ofProjection, strategy, decide_eq_true_eq]
  intro leaf
  rw [fill_comp clean background e SourceOddLists.left,
    fill_comp clean background e (SourceOddLists.right clauses)]
  let full : Occurrences (branch := branch) (h := h) (m := m) (t := t) :=
    fill clean background e
  let qL : LeftQuestions (branch := branch) (h := h) (t := t) (m := m) :=
    fun j => SourceOddLists.left (full j)
  let qR : RightQuestions (branch := branch) (h := h) (t := t) (v := v) :=
    fun j => SourceOddLists.right clauses (full j)
  let slotsL : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot :=
    leftTreeSlots (branch := branch) (n := h) clauses qL
  let slotsR : RecursiveSpaces.Slots branch h → Fin t → MixedSupport.Slot :=
    rightTreeSlots (branch := branch) (n := h) clauses qR
  let L : OddLists.OddList s (LeftDomain clauses (SourceOddLists.left (full leaf.val))) :=
    extract (branch := branch) (h := h) (t := t) positive slotsL (leftForms qL) leaf.val
      ((leftEquiv clauses (SourceOddLists.left (full leaf.val))).symm (fun _ => 0))
  let R : OddLists.OddList s (RightDomain clauses (SourceOddLists.right clauses (full leaf.val))) :=
    extract (branch := branch) (h := h) (t := t) positive slotsR (rightForms qR) leaf.val
      (fun _ => false)
  have hraw := extract_accepts (branch := branch) (h := h) (t := t)
      (slots := slotsL) (projected := slotsR) positive
      (treeProjection (branch := branch) (h := h) (t := t) clauses full)
      leaf.val (leftForms qL) (rightForms qR) z hform hone hnorm hrank hagree
      ((leftEquiv clauses (SourceOddLists.left (full leaf.val))).symm (fun _ => 0))
      (fun _ => false)
  have hnative : OddLists.OddList.map (actualProjection clauses (full leaf.val)) L = R :=
    map_eq_of_map_eq _ L R hraw
  have haccept := encodeOddList_accepted clauses (full leaf.val) L R hnative
  rw [← fill_clean clean background e leaf]
  change OddLists.OddList.map (SourceOddLists.projection clauses (full leaf.val))
      (encodeOddList clauses (SourceOddLists.left (full leaf.val)) L) = R
  exact haccept

end Clean

end
end PerfectCompleteness.SourceLocalOddLists

end

end OAI