File size: 8,806 Bytes
9dbc64e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Computability.DepthThree.AlgebraPolynomial
import Mathlib.RingTheory.AdjoinRoot

namespace OAI

noncomputable section

open scoped BigOperators
open Polynomial

namespace DepthThreeLowerBound.BinaryAlgebra

def quotientRepresentative {P : Polynomial F2} (hP : P.Monic) :
    AdjoinRoot P →ₗ[F2] Polynomial F2 :=
  AdjoinRoot.modByMonicHom hP

@[simp] theorem quotientRepresentative_mk {P : Polynomial F2} (hP : P.Monic)
    (f : Polynomial F2) :
    quotientRepresentative hP (AdjoinRoot.mk P f) = f %ₘ P :=
  AdjoinRoot.modByMonicHom_mk hP f

theorem mk_quotientRepresentative {P : Polynomial F2} (hP : P.Monic)
    (z : AdjoinRoot P) :
    AdjoinRoot.mk P (quotientRepresentative hP z) = z :=
  AdjoinRoot.mk_leftInverse hP z

theorem degree_quotientRepresentative_lt {P : Polynomial F2} (hP : P.Monic)
    (z : AdjoinRoot P) :
    (quotientRepresentative hP z).degree < P.degree := by
  refine AdjoinRoot.induction_on P z ?_
  intro f
  rw [quotientRepresentative_mk]
  exact Polynomial.degree_modByMonic_lt f hP

theorem quotientRepresentative_one {P : Polynomial F2} (hP : P.Monic)
    (hdeg : 0 < P.natDegree) :
    quotientRepresentative hP (1 : AdjoinRoot P) = 1 := by
  have h : (1 : Polynomial F2).degree < P.degree := by
    rw [Polynomial.degree_one, Polynomial.degree_eq_natDegree hP.ne_zero]
    exact WithBot.coe_lt_coe.mpr hdeg
  calc
    quotientRepresentative hP (1 : AdjoinRoot P) =
        quotientRepresentative hP (AdjoinRoot.mk P 1) := by rw [(AdjoinRoot.mk P).map_one]
    _ = (1 : Polynomial F2) %ₘ P := quotientRepresentative_mk hP 1
    _ = 1 := (Polynomial.modByMonic_eq_self_iff hP).mpr h

abbrev InputQuotient {r : ℕ} (p : Fin r → F2) :=
  AdjoinRoot (inputPolynomial p)

abbrev BitQuotient {r : ℕ} (p : Fin r → Bool) :=
  InputQuotient (fun i => bitValue (p i))

theorem pack_mod_inputPolynomial {r : ℕ} (p a : Fin r → F2) :
    pack a %ₘ inputPolynomial p = pack a := by
  apply (Polynomial.modByMonic_eq_self_iff (inputPolynomial_monic p)).mpr
  rw [inputPolynomial_degree]
  exact degree_pack_lt a

def encode {r : ℕ} (p : Fin r → F2) (a : Fin r → F2) : InputQuotient p :=
  AdjoinRoot.mk (inputPolynomial p) (pack a)

def coordinates {r : ℕ} (p : Fin r → F2) :
    InputQuotient p ≃ₗ[F2] (Fin r → F2) where
  toFun z i := (quotientRepresentative (inputPolynomial_monic p) z).coeff i.val
  invFun := encode p
  map_add' x y := by
    funext i
    simp only [map_add, Polynomial.coeff_add, Pi.add_apply]
  map_smul' c x := by
    funext i
    simp only [map_smul, Polynomial.coeff_smul, Pi.smul_apply, RingHom.id_apply]
  left_inv z := by
    have hd : (quotientRepresentative (inputPolynomial_monic p) z).degree <
        (r : WithBot ℕ) := by
      simpa only [inputPolynomial_degree] using
        degree_quotientRepresentative_lt (inputPolynomial_monic p) z
    change AdjoinRoot.mk (inputPolynomial p)
      (pack (fun i : Fin r =>
        (quotientRepresentative (inputPolynomial_monic p) z).coeff i.val)) = z
    rw [pack_coeff_of_degree_lt _ hd]
    exact mk_quotientRepresentative (inputPolynomial_monic p) z
  right_inv a := by
    funext i
    change (quotientRepresentative (inputPolynomial_monic p)
      (AdjoinRoot.mk (inputPolynomial p) (pack a))).coeff i.val = a i
    rw [quotientRepresentative_mk, pack_mod_inputPolynomial, coeff_pack]

@[simp] theorem coordinates_apply {r : ℕ} (p : Fin r → F2)
    (z : InputQuotient p) (i : Fin r) :
    coordinates p z i =
      (quotientRepresentative (inputPolynomial_monic p) z).coeff i.val := rfl

@[simp] theorem coordinates_symm_apply {r : ℕ} (p a : Fin r → F2) :
    (coordinates p).symm a = encode p a := rfl

@[simp] theorem coordinates_encode {r : ℕ} (p a : Fin r → F2) :
    coordinates p (encode p a) = a :=
  (coordinates p).apply_symm_apply a

@[simp] theorem encode_coordinates {r : ℕ} (p : Fin r → F2) (z : InputQuotient p) :
    encode p (coordinates p z) = z :=
  (coordinates p).symm_apply_apply z

theorem encode_injective {r : ℕ} (p : Fin r → F2) : Function.Injective (encode p) :=
  (coordinates p).symm.injective

theorem encode_surjective {r : ℕ} (p : Fin r → F2) : Function.Surjective (encode p) :=
  (coordinates p).symm.surjective

instance inputQuotientFintype {r : ℕ} (p : Fin r → F2) : Fintype (InputQuotient p) :=
  Fintype.ofEquiv (Fin r → F2) (coordinates p).toEquiv.symm

@[simp] theorem inputQuotient_card {r : ℕ} (p : Fin r → F2) :
    Fintype.card (InputQuotient p) = 2 ^ r := by
  rw [Fintype.card_congr (coordinates p).toEquiv, Fintype.card_fun,
    ZMod.card, Fintype.card_fin]

@[simp] theorem bitQuotient_card {r : ℕ} (p : Fin r → Bool) :
    Fintype.card (BitQuotient p) = 2 ^ r :=
  inputQuotient_card _

@[simp] theorem coordinates_mk {r : ℕ} (p : Fin r → F2)
    (f : Polynomial F2) (i : Fin r) :
    coordinates p (AdjoinRoot.mk (inputPolynomial p) f) i =
      (f %ₘ inputPolynomial p).coeff i.val := by
  rw [coordinates_apply, quotientRepresentative_mk]

@[simp] theorem encode_zero {r : ℕ} (p : Fin r → F2) :
    encode p (0 : Fin r → F2) = 0 := by
  rw [encode, pack_zero, map_zero]

@[simp] theorem encode_add {r : ℕ} (p a b : Fin r → F2) :
    encode p (a + b) = encode p a + encode p b := by
  simp only [encode, pack_add, map_add]

@[simp] theorem encode_smul {r : ℕ} (p : Fin r → F2) (c : F2) (a : Fin r → F2) :
    encode p (c • a) = c • encode p a := by
  change AdjoinRoot.mk (inputPolynomial p) (pack (c • a)) =
    c • AdjoinRoot.mk (inputPolynomial p) (pack a)
  rw [pack_smul, AdjoinRoot.smul_mk]

theorem coordinates_encode_mul {r : ℕ} (p a b : Fin r → F2) (i : Fin r) :
    coordinates p (encode p a * encode p b) i =
      ((pack a * pack b) %ₘ inputPolynomial p).coeff i.val := by
  change coordinates p
    (AdjoinRoot.mk (inputPolynomial p) (pack a) *
      AdjoinRoot.mk (inputPolynomial p) (pack b)) i = _
  rw [← map_mul, coordinates_mk]

theorem encode_mul {r : ℕ} (p a b : Fin r → F2) :
    encode p (fun i => ((pack a * pack b) %ₘ inputPolynomial p).coeff i.val) =
      encode p a * encode p b := by
  apply (coordinates p).injective
  rw [coordinates_encode]
  funext i
  exact (coordinates_encode_mul p a b i).symm

theorem coordinates_mul {r : ℕ} (p : Fin r → F2) (x y : InputQuotient p) (i : Fin r) :
    coordinates p (x * y) i =
      ((pack (coordinates p x) * pack (coordinates p y)) %ₘ inputPolynomial p).coeff i.val := by
  simpa only [encode_coordinates] using
    coordinates_encode_mul p (coordinates p x) (coordinates p y) i

theorem coordinates_one {r : ℕ} (p : Fin r → F2) (hr : 0 < r) (i : Fin r) :
    coordinates p (1 : InputQuotient p) i = if i.val = 0 then 1 else 0 := by
  rw [coordinates_apply, quotientRepresentative_one (inputPolynomial_monic p)
    (by simpa only [inputPolynomial_natDegree] using hr), Polynomial.coeff_one]

def degreeZero {P : Polynomial F2} (hP : P.Monic) : AdjoinRoot P →ₗ[F2] F2 :=
  (Polynomial.lcoeff F2 0).comp (quotientRepresentative hP)

@[simp] theorem degreeZero_apply {P : Polynomial F2} (hP : P.Monic)
    (z : AdjoinRoot P) :
    degreeZero hP z = (quotientRepresentative hP z).coeff 0 := rfl

@[simp] theorem degreeZero_mk {P : Polynomial F2} (hP : P.Monic) (f : Polynomial F2) :
    degreeZero hP (AdjoinRoot.mk P f) = (f %ₘ P).coeff 0 := by
  rw [degreeZero_apply, quotientRepresentative_mk]

theorem degreeZero_one {P : Polynomial F2} (hP : P.Monic) (hdeg : 0 < P.natDegree) :
    degreeZero hP (1 : AdjoinRoot P) = 1 := by
  rw [degreeZero_apply, quotientRepresentative_one hP hdeg, Polynomial.coeff_one_zero]

theorem degreeZero_surjective {P : Polynomial F2} (hP : P.Monic)
    (hdeg : 0 < P.natDegree) : Function.Surjective (degreeZero hP) := by
  intro c
  refine ⟨c • (1 : AdjoinRoot P), ?_⟩
  rw [map_smul, degreeZero_one hP hdeg, smul_eq_mul, mul_one]

theorem degreeZero_encode {r : ℕ} (p : Fin r → F2) (hr : 0 < r) (a : Fin r → F2) :
    degreeZero (inputPolynomial_monic p) (encode p a) = a ⟨0, hr⟩ := by
  rw [encode, degreeZero_mk, pack_mod_inputPolynomial]
  exact coeff_pack a ⟨0, hr⟩

theorem degreeZero_coordinates {r : ℕ} (p : Fin r → F2) (hr : 0 < r)
    (z : InputQuotient p) :
    degreeZero (inputPolynomial_monic p) z = coordinates p z ⟨0, hr⟩ := rfl

theorem degreeZero_sum_encode_pow {r t : ℕ} (p a : Fin r → F2)
    (beta : Fin t → Fin r → F2) :
    degreeZero (inputPolynomial_monic p)
        (∑ j : Fin t, encode p (beta j) * (encode p a) ^ j.val) =
      ((∑ j : Fin t, pack (beta j) * (pack a) ^ j.val) %ₘ inputPolynomial p).coeff 0 := by
  rw [← degreeZero_mk (inputPolynomial_monic p)
    (∑ j : Fin t, pack (beta j) * (pack a) ^ j.val)]
  congr 1
  simp only [encode, map_sum, map_mul, map_pow]

end DepthThreeLowerBound.BinaryAlgebra

end

end OAI