File size: 5,387 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
import OAI.Computability.DepthThree.AlgebraBits
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Algebra.Polynomial.Div

namespace OAI

noncomputable section

open scoped BigOperators
open Polynomial

namespace DepthThreeLowerBound.BinaryAlgebra

def pack {r : ℕ} (v : Fin r → ZMod 2) : Polynomial (ZMod 2) :=
  ∑ i : Fin r, Polynomial.monomial i.val (v i)

theorem degree_pack_lt {r : ℕ} (v : Fin r → ZMod 2) :
    (pack v).degree < (r : WithBot ℕ) := by
  simpa only [pack, Polynomial.C_mul_X_pow_eq_monomial] using
    (Polynomial.degree_sum_fin_lt v)

@[simp] theorem coeff_pack {r : ℕ} (v : Fin r → ZMod 2) (i : Fin r) :
    (pack v).coeff i.val = v i := by
  classical
  simp only [pack, Polynomial.finsetSum_coeff, Polynomial.coeff_monomial,
    Fin.val_eq_val, Finset.sum_ite_eq', ite_eq_left (Finset.mem_univ i)]

theorem coeff_pack_of_le {r : ℕ} (v : Fin r → ZMod 2) {j : ℕ} (hj : r ≤ j) :
    (pack v).coeff j = 0 :=
  Polynomial.coeff_eq_zero_of_degree_lt
    ((degree_pack_lt v).trans_le (WithBot.coe_le_coe.mpr hj))

theorem coeff_pack_nat {r : ℕ} (v : Fin r → ZMod 2) (j : ℕ) :
    (pack v).coeff j = if h : j < r then v ⟨j, h⟩ else 0 := by
  by_cases hj : j < r
  · rw [dite_eq_left hj]
    exact coeff_pack v ⟨j, hj⟩
  · rw [dite_eq_right hj]
    exact coeff_pack_of_le v (Nat.le_of_not_lt hj)

theorem pack_injective {r : ℕ} :
    Function.Injective (pack : (Fin r → ZMod 2) → Polynomial (ZMod 2)) := by
  intro v w h
  funext i
  simpa only [coeff_pack] using congrArg (fun f : Polynomial (ZMod 2) => f.coeff i.val) h

@[simp] theorem pack_zero {r : ℕ} : pack (0 : Fin r → ZMod 2) = 0 := by
  simp [pack]

@[simp] theorem pack_add {r : ℕ} (v w : Fin r → ZMod 2) :
    pack (v + w) = pack v + pack w := by
  simp only [pack, Pi.add_apply, map_add, Finset.sum_add_distrib]

@[simp] theorem pack_smul {r : ℕ} (c : ZMod 2) (v : Fin r → ZMod 2) :
    pack (c • v) = c • pack v := by
  simp only [pack, Pi.smul_apply, map_smul, Finset.smul_sum]

theorem pack_coeff_of_degree_lt {r : ℕ} (f : Polynomial (ZMod 2))
    (hf : f.degree < (r : WithBot ℕ)) :
    pack (fun i : Fin r => f.coeff i.val) = f := by
  unfold pack
  calc
    (∑ i : Fin r, Polynomial.monomial i.val (f.coeff i.val)) =
        f.sum (fun i c => Polynomial.monomial i c) :=
      Polynomial.sum_fin (fun i c => Polynomial.monomial i c)
        (fun i => Polynomial.monomial_zero_right i) hf
    _ = f := Polynomial.sum_monomial_eq f

def inputPolynomial {r : ℕ} (v : Fin r → ZMod 2) : Polynomial (ZMod 2) :=
  Polynomial.X ^ r + pack v

theorem inputPolynomial_monic {r : ℕ} (v : Fin r → ZMod 2) :
    (inputPolynomial v).Monic :=
  Polynomial.monic_X_pow_add (degree_pack_lt v)

@[simp] theorem inputPolynomial_degree {r : ℕ} (v : Fin r → ZMod 2) :
    (inputPolynomial v).degree = (r : WithBot ℕ) := by
  have h : (pack v).degree < (Polynomial.X ^ r : Polynomial (ZMod 2)).degree := by
    simpa only [Polynomial.degree_X_pow] using degree_pack_lt v
  simpa only [inputPolynomial, Polynomial.degree_X_pow] using
    Polynomial.degree_add_eq_left_of_degree_lt h

@[simp] theorem inputPolynomial_natDegree {r : ℕ} (v : Fin r → ZMod 2) :
    (inputPolynomial v).natDegree = r := by
  have h : (pack v).degree < (Polynomial.X ^ r : Polynomial (ZMod 2)).degree := by
    simpa only [Polynomial.degree_X_pow] using degree_pack_lt v
  simpa only [inputPolynomial, Polynomial.natDegree_X_pow] using
    Polynomial.natDegree_add_eq_left_of_degree_lt h

theorem inputPolynomial_ne_zero {r : ℕ} (v : Fin r → ZMod 2) :
    inputPolynomial v ≠ 0 :=
  (inputPolynomial_monic v).ne_zero

@[simp] theorem inputPolynomial_coeff_lt {r : ℕ} (v : Fin r → ZMod 2) (i : Fin r) :
    (inputPolynomial v).coeff i.val = v i := by
  rw [inputPolynomial, Polynomial.coeff_add, Polynomial.coeff_X_pow,
    ite_eq_right (Nat.ne_of_lt i.is_lt), zero_add, coeff_pack]

@[simp] theorem inputPolynomial_coeff_leading {r : ℕ} (v : Fin r → ZMod 2) :
    (inputPolynomial v).coeff r = 1 := by
  rw [inputPolynomial, Polynomial.coeff_add, Polynomial.coeff_X_pow_self,
    coeff_pack_of_le v (Nat.le_refl r), add_zero]

theorem inputPolynomial_coeff_of_gt {r : ℕ} (v : Fin r → ZMod 2)
    {j : ℕ} (hj : r < j) : (inputPolynomial v).coeff j = 0 := by
  apply Polynomial.coeff_eq_zero_of_degree_lt
  rw [inputPolynomial_degree]
  exact WithBot.coe_lt_coe.mpr hj

def inputPolynomialBits {r : ℕ} (p : Fin r → Bool) : Polynomial (ZMod 2) :=
  inputPolynomial (fun i => bitValue (p i))

theorem inputPolynomialBits_monic {r : ℕ} (p : Fin r → Bool) :
    (inputPolynomialBits p).Monic :=
  inputPolynomial_monic _

@[simp] theorem inputPolynomialBits_degree {r : ℕ} (p : Fin r → Bool) :
    (inputPolynomialBits p).degree = (r : WithBot ℕ) :=
  inputPolynomial_degree _

@[simp] theorem inputPolynomialBits_natDegree {r : ℕ} (p : Fin r → Bool) :
    (inputPolynomialBits p).natDegree = r :=
  inputPolynomial_natDegree _

@[simp] theorem inputPolynomialBits_coeff_lt {r : ℕ} (p : Fin r → Bool) (i : Fin r) :
    (inputPolynomialBits p).coeff i.val = bitValue (p i) :=
  inputPolynomial_coeff_lt _ _

@[simp] theorem inputPolynomialBits_coeff_leading {r : ℕ} (p : Fin r → Bool) :
    (inputPolynomialBits p).coeff r = 1 :=
  inputPolynomial_coeff_leading _

end DepthThreeLowerBound.BinaryAlgebra

end

end OAI