File size: 8,633 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
import Mathlib.LinearAlgebra.Basis.Defs
import OAI.Computability.PerfectCompleteness.Algebra.UniformLinearImage
import OAI.Computability.PerfectCompleteness.Sampling.RationalFiniteLawLemmas
import OAI.Computability.UniqueGames.Analysis.MatrixRestrictions
import OAI.Computability.UniqueGames.Foundations.SamplingLemmas

namespace OAI


namespace PerfectCompleteness.RestrictionRowsLaw

noncomputable section

open UniqueGamesTheorem.Integration.BinaryLinear
open UniqueGamesTheorem.Fourier.MatrixRestrictions
open UniqueGamesTheorem.Foundations.Games
open scoped Classical

variable {E C I : Type*} [AddCommGroup E] [Module F2 E]
  [AddCommGroup C] [Module F2 C] [Fintype I]
  (W : Submodule F2 E) (C' : Submodule F2 C) (b : Module.Basis I F2 C')

def rowsLinear : Parameter W C' →ₗ[F2] (I → Module.Dual F2 (E ⧸ W)) where
  toFun A i := (b.coord i).comp A
  map_add' A B := by
    funext i
    apply LinearMap.ext
    intro x
    exact map_add (b.coord i) (A x) (B x)
  map_smul' a A := by
    funext i
    apply LinearMap.ext
    intro x
    exact map_smul (b.coord i) a (A x)

omit [Fintype I] in
@[simp] theorem rowsLinear_apply (A : Parameter W C') (i : I) :
    rowsLinear W C' b A i = (b.coord i).comp A := rfl

def fromRows (rows : I → Module.Dual F2 (E ⧸ W)) : Parameter W C' :=
  b.equivFun.symm.toLinearMap.comp (LinearMap.pi rows)

@[simp] theorem rowsLinear_fromRows (rows : I → Module.Dual F2 (E ⧸ W)) :
    rowsLinear W C' b (fromRows W C' b rows) = rows := by
  funext i
  apply LinearMap.ext
  intro x
  exact b.coord_equivFun_symm i (fun j => rows j x)

theorem rowsLinear_surjective : Function.Surjective (rowsLinear W C' b) :=
  fun rows => ⟨fromRows W C' b rows, rowsLinear_fromRows W C' b rows⟩

omit [Fintype I] in
theorem rowsLinear_injective : Function.Injective (rowsLinear W C' b) := by
  intro A B h
  apply LinearMap.ext
  intro x
  apply b.repr.injective
  ext i
  exact congrArg (fun rows : I → Module.Dual F2 (E ⧸ W) => rows i x) h

def rowsEquiv : Parameter W C' ≃ₗ[F2] (I → Module.Dual F2 (E ⧸ W)) :=
  LinearEquiv.ofBijective (rowsLinear W C' b)
    ⟨rowsLinear_injective W C' b, rowsLinear_surjective W C' b⟩

section Selection

variable {J : Type*} (sel : J → I)

def selectLinear : (I → Module.Dual F2 (E ⧸ W)) →ₗ[F2]
    (J → Module.Dual F2 (E ⧸ W)) :=
  LinearMap.pi (fun j => LinearMap.proj (sel j))

omit [Fintype I] in
theorem selectLinear_surjective (hsel : Function.Injective sel) :
    Function.Surjective (selectLinear W sel) :=
  hsel.surjective_comp_right

def selectedRowsLinear : Parameter W C' →ₗ[F2] (J → Module.Dual F2 (E ⧸ W)) :=
  (selectLinear W sel).comp (rowsLinear W C' b)

omit [Fintype I] in
@[simp] theorem selectedRowsLinear_apply (A : Parameter W C') (j : J) :
    selectedRowsLinear W C' b sel A j = (b.coord (sel j)).comp A := rfl

theorem selectedRowsLinear_surjective (hsel : Function.Injective sel) :
    Function.Surjective (selectedRowsLinear W C' b sel) :=
  (selectLinear_surjective W sel hsel).comp (rowsLinear_surjective W C' b)

end Selection

section Uniform

variable [Fintype (Parameter W C')] [Fintype (Module.Dual F2 (E ⧸ W))]

theorem uniform_rowsLinear :
    (FiniteDistribution.uniform (Parameter W C')).pushforward (rowsLinear W C' b) =
      FiniteDistribution.uniform (I → Module.Dual F2 (E ⧸ W)) :=
  UniformLinearImage.uniform_pushforward_linearMap
    (rowsLinear W C' b) (rowsLinear_surjective W C' b)

theorem uniform_rows_law [DecidableEq I] :
    (FiniteDistribution.uniform (Parameter W C')).pushforward (rowsLinear W C' b) =
      FiniteProduct.law (fun _ : I => FiniteDistribution.uniform
        (Module.Dual F2 (E ⧸ W))) := by
  rw [UniformLinearImage.law_uniform]
  exact UniformLinearImage.uniform_pushforward_linearMap
    (rowsLinear W C' b) (rowsLinear_surjective W C' b)

private theorem uniform_add_left {V : Type*} [AddGroup V] [Fintype V] (offset : V) :
    (FiniteDistribution.uniform V).pushforward (fun x => offset + x) =
      FiniteDistribution.uniform V := by
  change (FiniteDistribution.uniform V).pushforward (Equiv.addLeft offset) = _
  rw [FiniteDistribution.pushforward_equiv]
  apply FiniteDistribution.eq_of_weight_eq
  intro x
  rfl

theorem uniform_translated_rows (offsets : I → Module.Dual F2 (E ⧸ W)) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (fun A => offsets + rowsLinear W C' b A) =
      FiniteDistribution.uniform (I → Module.Dual F2 (E ⧸ W)) := by
  rw [← FiniteDistribution.pushforward_comp
    (FiniteDistribution.uniform (Parameter W C')) (rowsLinear W C' b)
    (fun rows => offsets + rows), uniform_rowsLinear]
  exact uniform_add_left offsets

variable {J : Type*} [Fintype J] (sel : J → I)

theorem uniform_selectedRowsLinear (hsel : Function.Injective sel) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (selectedRowsLinear W C' b sel) =
      FiniteDistribution.uniform (J → Module.Dual F2 (E ⧸ W)) :=
  UniformLinearImage.uniform_pushforward_linearMap
    (selectedRowsLinear W C' b sel) (selectedRowsLinear_surjective W C' b sel hsel)

theorem uniform_selected_rows_law [DecidableEq J] (hsel : Function.Injective sel) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (selectedRowsLinear W C' b sel) =
      FiniteProduct.law (fun _ : J => FiniteDistribution.uniform
        (Module.Dual F2 (E ⧸ W))) := by
  rw [UniformLinearImage.law_uniform]
  exact UniformLinearImage.uniform_pushforward_linearMap
    (selectedRowsLinear W C' b sel) (selectedRowsLinear_surjective W C' b sel hsel)

end Uniform

def affineRow (offset : Module.Dual F2 E) (row : Module.Dual F2 (E ⧸ W)) :
    Module.Dual F2 E := offset + row.comp W.mkQ

omit [Fintype I] in
theorem coordinate_translate (coordinates : I → Module.Dual F2 C)
    (hcoordinates : ∀ i, (coordinates i).comp C'.subtype = b.coord i)
    (X : E →ₗ[F2] C) (A : Parameter W C') (i : I) :
    (coordinates i).comp (translate W C' X A) =
      affineRow W ((coordinates i).comp X) (rowsLinear W C' b A i) := by
  apply LinearMap.ext
  intro x
  change coordinates i (X x + (A (W.mkQ x) : C)) =
    coordinates i (X x) + b.coord i (A (W.mkQ x))
  rw [map_add]
  congr 1
  exact congrArg (fun f : C' →ₗ[F2] F2 => f (A (W.mkQ x))) (hcoordinates i)


variable [Fintype (Parameter W C')] [Fintype (Module.Dual F2 (E ⧸ W))]
  [Fintype (Module.Dual F2 E)]

def affineRowLaw (offset : Module.Dual F2 E) : FiniteDistribution (Module.Dual F2 E) :=
  (FiniteDistribution.uniform (Module.Dual F2 (E ⧸ W))).pushforward (affineRow W offset)

theorem uniform_affine_rows_law [DecidableEq I] (offsets : I → Module.Dual F2 E) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (fun A i => affineRow W (offsets i) (rowsLinear W C' b A i)) =
      FiniteProduct.law (fun i => affineRowLaw W (offsets i)) := by
  rw [← FiniteDistribution.pushforward_comp
    (FiniteDistribution.uniform (Parameter W C')) (rowsLinear W C' b)
    (fun rows i => affineRow W (offsets i) (rows i)), uniform_rows_law]
  exact FiniteProduct.pushforward_map _ (fun i => affineRow W (offsets i))

theorem uniform_coordinate_translate_law [DecidableEq I]
    (coordinates : I → Module.Dual F2 C)
    (hcoordinates : ∀ i, (coordinates i).comp C'.subtype = b.coord i)
    (X : E →ₗ[F2] C) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (fun A i => (coordinates i).comp (translate W C' X A)) =
      FiniteProduct.law (fun i => affineRowLaw W ((coordinates i).comp X)) := by
  have hrows : (fun A i => (coordinates i).comp (translate W C' X A)) =
      (fun A i => affineRow W ((coordinates i).comp X) (rowsLinear W C' b A i)) := by
    funext A i
    exact coordinate_translate W C' b coordinates hcoordinates X A i
  rw [hrows]
  exact uniform_affine_rows_law W C' b (fun i => (coordinates i).comp X)

variable {J : Type*} [Fintype J] [DecidableEq J]

theorem uniform_selected_affine_rows_law (sel : J → I)
    (hsel : Function.Injective sel) (offsets : J → Module.Dual F2 E) :
    (FiniteDistribution.uniform (Parameter W C')).pushforward
        (fun A j => affineRow W (offsets j) (selectedRowsLinear W C' b sel A j)) =
      FiniteProduct.law (fun j => affineRowLaw W (offsets j)) := by
  rw [← FiniteDistribution.pushforward_comp
    (FiniteDistribution.uniform (Parameter W C')) (selectedRowsLinear W C' b sel)
    (fun rows j => affineRow W (offsets j) (rows j)),
    uniform_selected_rows_law W C' b sel hsel]
  exact FiniteProduct.pushforward_map _ (fun j => affineRow W (offsets j))

end
end PerfectCompleteness.RestrictionRowsLaw

end OAI