Skip to content

Commit ff7e2ff

Browse files
dhsorensquangvdao
andauthored
feat: bump lean version to 4.29.0 (#176)
* feat: bump lean version * fix: linter * Generalize CMvPolynomial coefficient universes (#178) * refactor(multivariate): generalize coefficient universes * refactor(multivariate): restore ExtTreeMap lemmas dependency * style(multivariate): clean review nits * fix(multivariate): adapt universe branch to Lean 4.29 * feat: bump to 4.29.0 - sorry out problem lemmas * feat: fix broken proofs for 4.29.0 bump * fix: compiler warnings * fix: linting errors * fix(bivariate): keep ofPoly computable * test(univariate): use implicit reducibility * fix(multivariate): restore computable degrees * fix(lean): address remaining review nits * fix(additive-ntt): restore computable BTF3 fintype --------- Co-authored-by: Quang Dao <qvd@andrew.cmu.edu> Co-authored-by: Quang Dao <quang.dao@layerzerolabs.org>
1 parent 6c3c131 commit ff7e2ff

46 files changed

Lines changed: 383 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CompPoly/Bivariate/ToPoly.lean

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ noncomputable def toPoly {R : Type*} [BEq R] [LawfulBEq R] [Semiring R]
5050
`toImpl` and trimming, then builds the canonical bivariate sum.
5151
-/
5252
def ofPoly {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R]
53-
[DecidableEq R] (p : R[X][Y]) : CBivariate R :=
53+
[DecidableEq R] [Semiring (Polynomial R)] (p : R[X][Y]) : CBivariate R :=
5454
(p.support).sum (fun j ↦
5555
let cj := p.coeff j
5656
CPolynomial.monomial j ⟨cj.toImpl, CPolynomial.Raw.isCanonical_toImpl cj⟩)
@@ -171,9 +171,10 @@ lemma ofPoly_add {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R]
171171
(show q.support ⊆ p.support ∪ q.support from Finset.subset_union_right) ]
172172
· rw [ ← Finset.sum_add_distrib ]
173173
refine' Finset.sum_congr rfl fun x hx ↦ _
174-
rw [ ← CPolynomial.monomial_add ]
175-
congr
176-
exact Eq.symm (toImpl_add (p.coeff x) (q.coeff x))
174+
erw [ ← CPolynomial.monomial_add ]
175+
congr 1
176+
apply Subtype.ext
177+
exact (toImpl_add (p.coeff x) (q.coeff x)).symm
177178
· aesop
178179
· aesop
179180
· aesop
@@ -195,7 +196,8 @@ theorem ofPoly_coeff {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring
195196
unfold CBivariate.ofPoly
196197
induction' p.support using Finset.induction with j s hj ih
197198
· exact CPolynomial.eq_iff_coeff.mpr (congrFun rfl)
198-
· rw [ Finset.sum_insert hj, CPolynomial.coeff_add, ih, Finset.sum_insert hj ]
199+
· rw [Finset.sum_insert hj]
200+
erw [CPolynomial.coeff_add, ih, Finset.sum_insert hj]
199201
rw [ h_coeff_sum, Finset.sum_eq_single n ]
200202
· rw [ CPolynomial.coeff_monomial ]
201203
simp +decide [ CPolynomial.toPoly ]
@@ -237,7 +239,8 @@ theorem toPoly_mul {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R]
237239
toPoly (p * q) = toPoly p * toPoly q := by
238240
have h_mul : (p * q).toPoly =
239241
(CPolynomial.toPoly (p * q)).map (CPolynomial.ringEquiv (R := R)) := toPoly_eq_map (p * q)
240-
rw [ h_mul, CPolynomial.toPoly_mul ]
242+
rw [ h_mul ]
243+
erw [CPolynomial.toPoly_mul]
241244
rw [ Polynomial.map_mul, ← toPoly_eq_map, ← toPoly_eq_map ]
242245

243246
end ToPolyCore
@@ -310,6 +313,8 @@ lemma ofPoly_zero {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R]
310313
ofPoly (0 : R[X][Y]) = 0 := by
311314
unfold CBivariate.ofPoly
312315
simp +decide [ Polynomial.support ]
316+
erw [Finsupp.support_zero]
317+
exact Finset.sum_empty
313318

314319
/-- Ring hom from computable bivariates to Mathlib bivariates. -/
315320
noncomputable def toPolyRingHom
@@ -743,7 +748,7 @@ theorem swap_toPoly_coeff {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semi
743748
CPolynomial.coeff (swap (R := R) f) j =
744749
∑ x ∈ f.supportY, CPolynomial.monomial x ((f.val.coeff x).coeff j) := by
745750
unfold CBivariate.swap CBivariate.supportY
746-
rw [hCoeffSumOuter]
751+
erw [hCoeffSumOuter]
747752
exact Finset.sum_congr rfl (fun x hx => hInner x)
748753
change CPolynomial.coeff (CPolynomial.coeff (swap (R := R) f) j) i =
749754
CPolynomial.coeff (CPolynomial.coeff f i) j

CompPoly/Data/Fin/BigOperators.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ theorem div_two_pow_lt_two_pow (x i j : ℕ) (h_x_lt_2_pow_i : x < 2 ^ (i + j)):
4242
· simp only [h_i_eq_0, zero_add, pow_zero, Nat.lt_one_iff, Nat.div_eq_zero_iff, Nat.pow_eq_zero,
4343
OfNat.ofNat_ne_zero, ne_eq, false_and, false_or] at *;
4444
omega
45-
· push_neg at h_i_eq_0
45+
· push Not at h_i_eq_0
4646
apply Nat.div_lt_of_lt_mul (m:=x) (n:=2^j) (k:=2^i) (by
4747
have h_rhs_eq : 2^(i+j) = 2^j * 2^i := by
4848
rw [pow_add (a:=2) (m:=i) (n:=j), mul_comm]
@@ -151,7 +151,7 @@ This is useful for definitions that process elements in reverse order, like `fol
151151
have h := Fin.lt_last_iff_ne_last (n:=r - 1) (a:=⟨i, by omega⟩)
152152
simp only [Fin.last, mk_lt_mk, ne_eq, mk.injEq] at h
153153
have h_i_val_ne_eq: (i.val ≠ r - 1) := by
154-
push_neg at h_i_eq_last
154+
push Not at h_i_eq_last
155155
exact Fin.val_ne_of_ne h_i_eq_last
156156
apply Fin.mk_lt_of_lt_val
157157
apply h.mpr

CompPoly/Data/Nat/Bitwise.lean

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ lemma ENat.le_floor_NNReal_iff (x : ENat) (y : ℝ≥0) (hx_ne_top : x ≠ ⊤)
3535
(x : ENat) ≤ ((Nat.floor y) : ENat) ↔ x.toNat ≤ Nat.floor y := by
3636
lift x to ℕ using hx_ne_top
3737
-- y : ℝ≥0, x : ℕ, ⊢ ↑x ≤ ↑⌊y⌋₊ ↔ (↑x).toNat ≤ ⌊y⌋₊
38-
simp only [Nat.cast_le, toNat_coe]
38+
simp only [ENat.coe_le_coe, toNat_coe]
3939

4040
section ENNReal
4141
open ENNReal
@@ -49,29 +49,11 @@ variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
4949
-- lemma ENNReal.div_lt_div_right (hc₀ : c ≠ 0) (hc : c ≠ ∞) (hab : a < b) : a / c < b / c :=
5050
-- (ENNReal.div_lt_div_iff_left hc₀ hc).2 hab
5151

52-
theorem ENNReal.mul_inv_rev_ENNReal {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
53-
((a : ENNReal)⁻¹ * (b : ENNReal)⁻¹) = ((a : ENNReal) * (b : ENNReal))⁻¹ := by
54-
-- Let x = ↑a and y = ↑b for readability
55-
let x : ENNReal := a
56-
let y : ENNReal := b
57-
-- Prove x and y are non-zero and finite (needed for inv_cancel)
58-
have hx_ne_zero : x ≠ 0 := by exact Nat.cast_ne_zero.mpr ha
59-
have hy_ne_zero : y ≠ 0 := by exact Nat.cast_ne_zero.mpr hb
60-
have hx_ne_top : x ≠ ∞ := by exact ENNReal.natCast_ne_top a
61-
have hy_ne_top : y ≠ ∞ := by exact ENNReal.natCast_ne_top b
62-
have ha_NNReal_ne0 : (a : ℝ≥0) ≠ 0 := by exact Nat.cast_ne_zero.mpr ha
63-
have hb_NNReal_ne0 : (b : ℝ≥0) ≠ 0 := by exact Nat.cast_ne_zero.mpr hb
64-
-- (a * b)⁻¹ = b⁻¹ * a⁻¹
65-
have hlhs : ((a : ENNReal)⁻¹ * (b : ENNReal)⁻¹) = ((a : ℝ≥0)⁻¹ * (b : ℝ≥0)⁻¹) := by
66-
rw [coe_inv (hr := by exact ha_NNReal_ne0)]
67-
rw [coe_inv (hr := by exact hb_NNReal_ne0)]
68-
rw [ENNReal.coe_natCast, ENNReal.coe_natCast]
69-
have hrhs : ((a : ENNReal) * (b : ENNReal))⁻¹ = ((a : ℝ≥0) * (b : ℝ≥0))⁻¹ := by
70-
rw [coe_inv (hr := (mul_ne_zero_iff_right hb_NNReal_ne0).mpr (ha_NNReal_ne0))]
71-
simp only [coe_mul, coe_natCast]
72-
rw [hlhs, hrhs]
73-
rw [mul_inv_rev (a := (a : ℝ≥0)) (b := (b : ℝ≥0))]
74-
rw [coe_mul, mul_comm]
52+
theorem ENNReal.mul_inv_rev_ENNReal {a b : ℕ} (ha : a ≠ 0) :
53+
((a : ENNReal)⁻¹ * (b : ENNReal)⁻¹) = ((a : ENNReal) * (b : ENNReal))⁻¹ :=
54+
(ENNReal.mul_inv
55+
(Or.inl (Nat.cast_ne_zero.mpr ha))
56+
(Or.inl (ENNReal.natCast_ne_top a))).symm
7557

7658
lemma ENNReal.coe_le_of_NNRat {a b : ℚ≥0} : ((a : ENNReal)) ≤ (b) ↔ a ≤ b := by
7759
exact ENNReal.coe_le_coe.trans (by norm_cast)
@@ -367,7 +349,7 @@ lemma getBit_two_pow {i k : ℕ} : (getBit k (2^i) = if i == k then 1 else 0) :=
367349
simp only [Nat.and_one_is_mod, BEq.rfl, ↓reduceIte]
368350
rw [Nat.shiftLeft_shiftRight]
369351
else
370-
push_neg at h_i_eq_k
352+
push Not at h_i_eq_k
371353
simp only [beq_iff_eq, h_i_eq_k, ↓reduceIte]
372354
if h_k_lt_i: i < k then
373355
have h_res : (1 <<< i >>> k &&& 1) = 0 := by
@@ -390,7 +372,7 @@ lemma getBit_two_pow {i k : ℕ} : (getBit k (2^i) = if i == k then 1 else 0) :=
390372
rw [h_one_div_2_pow_k_sub_i, Nat.zero_and]
391373
rw [h_res]
392374
else
393-
push_neg at h_k_lt_i
375+
push Not at h_k_lt_i
394376
have h_res : (1 <<< i >>> k &&& 1) = 0 := by
395377
set i_sub_k := i - k with h_i_sub_k
396378
have h_i_sub_k_le_1: i_sub_k ≥ 1 := by omega
@@ -419,7 +401,7 @@ lemma and_two_pow_eq_zero_of_getBit_0 {n i : ℕ} (h_getBit : getBit i n = 0) :
419401
rw [getBit, h_k.symm] at h_getBit
420402
rw [getBit, h_getBit, Nat.zero_and]
421403
else
422-
push_neg at h_k
404+
push Not at h_k
423405
simp only [beq_iff_eq, h_k.symm, ↓reduceIte] at h_getBit_two_pow
424406
rw [getBit] at h_getBit_two_pow
425407
rw [getBit, getBit, h_getBit_two_pow]
@@ -448,7 +430,7 @@ lemma and_two_pow_eq_two_pow_of_getBit_eq_one {n i : ℕ} (h_getBit: getBit i n
448430
rw [Nat.shiftRight_and_distrib, Nat.and_assoc, Nat.and_comm (2^k >>> k) 1, ←Nat.and_assoc]
449431
rw [h_getBit, ←one_mul (2^k), ←Nat.shiftLeft_eq, Nat.shiftLeft_shiftRight, Nat.and_self]
450432
else
451-
push_neg at h_k
433+
push Not at h_k
452434
simp only [beq_iff_eq, h_k.symm, ↓reduceIte] at h_getBit_two_pow
453435
rw [getBit] at h_getBit_two_pow
454436
rw [h_getBit_two_pow, Nat.shiftRight_and_distrib, Nat.and_assoc, h_getBit_two_pow]
@@ -465,9 +447,7 @@ lemma eq_zero_or_eq_one_of_lt_two {n : ℕ} (h_lt : n < 2) : n = 0 ∨ n = 1 :=
465447

466448
lemma div_2_form {nD2 b : ℕ} (h_b : b < 2) :
467449
(nD2 * 2 + b) / 2 = nD2 := by
468-
rw [←add_comm, ←mul_comm]
469-
rw [Nat.add_mul_div_left (x := b) (y := 2) (z := nD2) (H := by norm_num)]
470-
norm_num; exact h_b;
450+
omega
471451

472452
lemma and_by_split_lowBits {n m n1 m1 bn bm : ℕ} (h_bn : bn < 2) (h_bm : bm < 2)
473453
(h_n : n = n1 * 2 + bn) (h_m : m = m1 * 2 + bm) :
@@ -656,7 +636,7 @@ lemma sum_eq_xor_plus_twice_and (n : Nat) : ∀ m : ℕ, n + m = (n ^^^ m) + 2 *
656636
rw [h_and_getBits, mul_comm (a := (n2 &&& m2)) (b := 2)];
657637
_ = 2 * (nVal &&& mVal) := by rw [h_and];
658638
rw [h_right]
659-
· push_neg at h_and_getBitN_getBitM_eq_1;
639+
· push Not at h_and_getBitN_getBitM_eq_1;
660640
have h_and_getBitN_getBitM_eq_0 : (getBitN &&& getBitM) = 0 := by
661641
interval_cases (getBitN &&& getBitM)
662642
· rfl
@@ -895,7 +875,7 @@ lemma getBit_of_sub_two_pow_of_bit_1 {n i j: ℕ} (h_getBit_eq_1: getBit i n = 1
895875
rw [Nat.getBit_two_pow]
896876
simp only [beq_iff_eq]
897877
simp only [h_j_eq_i, ↓reduceIte]
898-
push_neg at h_j_eq_i
878+
push Not at h_j_eq_i
899879
simp only [if_neg h_j_eq_i.symm, xor_zero]
900880

901881
lemma getBit_of_lowBits {n: ℕ} (numLowBits : ℕ) : ∀ k, getBit k (getLowBits numLowBits n) =
@@ -915,7 +895,7 @@ lemma getBit_of_lowBits {n: ℕ} (numLowBits : ℕ) : ∀ k, getBit k (getLowBit
915895
· simp only [Nat.and_one_is_mod]
916896
· simp only [Nat.and_one_is_mod]
917897
else
918-
push_neg at h_k
898+
push Not at h_k
919899
have getBit_k_mask : getBit k (1 <<< numLowBits - 1) = 0:= by
920900
rw [Nat.shiftLeft_eq, one_mul]
921901
rw [getBit_of_two_pow_sub_one (i := numLowBits) (k := k)]
@@ -964,7 +944,7 @@ theorem getBit_repr {ℓ : Nat} :
964944
interval_cases j
965945
· simp only [getBit, Nat.shiftRight_zero, Nat.and_one_is_mod, Nat.zero_mod]
966946
· simp only [getBit, Nat.shiftRight_zero, Nat.and_one_is_mod]
967-
· push_neg at h_ℓ₁
947+
· push Not at h_ℓ₁
968948
set ℓ := ℓ₁ + 1
969949
have h_ℓ_eq : ℓ = ℓ₁ + 1 := by rfl
970950
intro j h_j
@@ -991,7 +971,7 @@ theorem getBit_repr {ℓ : Nat} :
991971
_ = b + 2 * m := by omega;
992972
have h_m : m < 2^ℓ₁ := by
993973
by_contra h_m_ge_2_pow_ℓ
994-
push_neg at h_m_ge_2_pow_ℓ
974+
push Not at h_m_ge_2_pow_ℓ
995975
have h_j_ge : j ≥ 2^ℓ := by
996976
calc _ = 2 * m + b := by rw [h_j_eq]; omega
997977
_ ≥ 2 * (2^ℓ₁) + b := by omega
@@ -1261,7 +1241,7 @@ lemma getBit_of_lt_two_pow {n: ℕ} (a: Fin (2^n)) (k: ℕ) :
12611241
lemma exist_bit_diff_if_diff {n: ℕ} (a: Fin (2^n)) (b: Fin (2^n)) (h_a_ne_b: a ≠ b) :
12621242
∃ k: Fin n, getBit k a ≠ getBit k b := by
12631243
by_contra h_no_diff
1264-
push_neg at h_no_diff
1244+
push Not at h_no_diff
12651245
have h_a_eq_b: a = b := by
12661246
apply Fin.eq_of_val_eq
12671247
apply eq_iff_eq_all_getBits.mpr
@@ -1371,7 +1351,7 @@ lemma getBit_of_binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary: ∀ j
13711351
if h_k_lt_n: k < n then
13721352
have h_k_lt_n_add_1: k < n + 1 := by omega
13731353
simp only [h_k_lt_n_add_1, ↓reduceDIte]
1374-
push_neg at h_k_eq
1354+
push Not at h_k_eq
13751355
simp only [h_k_lt_n, ↓reduceDIte]
13761356
unfold msbTerm
13771357
interval_cases h_m_last_val: m ⟨n, by omega⟩

CompPoly/Data/Polynomial/Frobenius.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ theorem degree_dvd_of_irreducible_dvd_X_pow_card_pow_sub_X
486486
have h_exponent_dvd : Monoid.exponent Kˣ ∣ q ^ n - 1 :=
487487
Monoid.exponent_dvd_of_forall_pow_eq_one h_units_pow_eq_one
488488
have h_order_K : Fintype.card Kˣ = q ^ d - 1 := by
489-
rw [Fintype.card_units, h_card_K]
489+
erw [Fintype.card_units, h_card_K]
490490
have h_exp_eq_order : Monoid.exponent Kˣ = Fintype.card Kˣ := by
491491
rw [IsCyclic.exponent_eq_card, Nat.card_eq_fintype_card]
492492
rw [h_exp_eq_order, h_order_K] at h_exponent_dvd

CompPoly/Data/RingTheory/AlgebraTower.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ variable {ι : Type*} [Preorder ι]
4242
{C : ι → Type*} [∀ i, CommSemiring (C i)] [AlgebraTower C]
4343

4444
@[simp]
45-
def AlgebraTower.toAlgebra {i j : ι} (h : i ≤ j) : Algebra (A i) (A j) :=
45+
abbrev AlgebraTower.toAlgebra {i j : ι} (h : i ≤ j) : Algebra (A i) (A j) :=
4646
(AlgebraTower.algebraMap (i:=i) (j:=j) (h:=h)).toAlgebra
4747

4848
@[simp]
@@ -102,11 +102,11 @@ def AlgebraTowerEquiv.algebraMapLeftUp (e : AlgebraTowerEquiv A B) (i j : ι)
102102
have hjRingEquiv: RingEquiv (B i) (A i) := (e.toRingEquiv i).symm
103103
exact hAij.comp hjRingEquiv.toRingHom
104104

105-
def AlgebraTowerEquiv.toAlgebraOverLeft (e : AlgebraTowerEquiv A B) (i j : ι)
105+
abbrev AlgebraTowerEquiv.toAlgebraOverLeft (e : AlgebraTowerEquiv A B) (i j : ι)
106106
(h : i ≤ j) : Algebra (A i) (B j) := by
107107
exact (e.algebraMapRightUp i j h).toAlgebra
108108

109-
def AlgebraTowerEquiv.toAlgebraOverRight (e : AlgebraTowerEquiv A B) (i j : ι)
109+
abbrev AlgebraTowerEquiv.toAlgebraOverRight (e : AlgebraTowerEquiv A B) (i j : ι)
110110
(h : i ≤ j) : Algebra (B i) (A j) := by
111111
exact (e.algebraMapLeftUp i j h).toAlgebra
112112

CompPoly/Data/Vector/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ lemma cons_empty_tail_eq_nil {α} (hd : α) (tl : Vector α 0) :
8989
theorem tail_cons {α} {n : ℕ} (hd : α) (tl : Vector α n) : (cons hd tl).tail = tl := by
9090
rw [cons, Vector.insertIdx]
9191
simp only [Nat.add_one_sub_one, Array.insertIdx_zero, tail_eq_cast_extract, extract_mk,
92-
Array.extract_append, List.extract_toArray, List.extract_eq_drop_take, add_tsub_cancel_right,
92+
Array.extract_append, List.extract_toArray, List.extract_eq_take_drop, add_tsub_cancel_right,
9393
List.drop_succ_cons, List.drop_nil, List.take_nil, List.size_toArray, List.length_cons,
9494
List.length_nil, tsub_self, Array.take_eq_extract, Array.empty_append, cast_mk, mk_eq,
9595
Array.extract_eq_self_iff, size_toArray, le_refl, and_self, or_true]

CompPoly/Fields/Binary/AdditiveNTT/Algorithm.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ lemma evaluationPointω_eq_twiddleFactor_of_div_2 (i : Fin ℓ) (x : Fin (2 ^ (
100100
simp only [Nat.getBit, Nat.shiftRight_zero, Nat.and_one_is_mod]
101101
by_cases h_lsb_of_x_eq_0 : x.val % 2 = 0
102102
· simp only [h_lsb_of_x_eq_0, zero_ne_one, ↓reduceIte, Nat.cast_zero, zero_mul]
103-
· push_neg at h_lsb_of_x_eq_0
103+
· push Not at h_lsb_of_x_eq_0
104104
simp only [ne_eq, Nat.mod_two_not_eq_zero] at h_lsb_of_x_eq_0
105105
simp only [h_lsb_of_x_eq_0, ↓reduceIte, Nat.cast_one, one_mul]
106106

@@ -159,7 +159,7 @@ lemma eval_point_ω_eq_next_twiddleFactor_comp_qmap
159159
conv_rhs => rw [h_0_is_algebra_map]
160160
have h_res := qMap_eval_𝔽q_eq_0 𝔽q β (i := ⟨i, by omega⟩) (c := 0)
161161
rw [h_res]
162-
· push_neg at h_bit_of_x_eq_0
162+
· push Not at h_bit_of_x_eq_0
163163
have h_bit_lt_2 := Nat.getBit_lt_2 (k := x1) (n := x)
164164
have bit_eq_1 : Nat.getBit x1 x = 1 := by
165165
interval_cases Nat.getBit x1 x

CompPoly/Fields/Binary/AdditiveNTT/Correctness.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ lemma NTTStage_correctness (i : Fin (ℓ))
277277
rw [h_x0_eq_cur_evaluation_point]
278278
simp only [eval_comp, eval_add, eval_mul, eval_X]
279279
· simp only [h_b_bit_eq_0, ↓reduceDIte]
280-
push_neg at h_b_bit_eq_0
280+
push Not at h_b_bit_eq_0
281281
have bit_i_j_eq_1 : Nat.getBit i.val j.val = 1 := by omega
282282
simp only [ne_eq, Nat.mod_two_not_eq_zero] at h_b_bit_eq_0
283283
set x1 := twiddleFactor 𝔽q β h_ℓ_add_R_rate i
@@ -501,12 +501,13 @@ theorem additiveNTT_correctness (h_ℓ : ℓ ≤ r)
501501
have res := output_foldl_correctness j
502502
unfold output_foldl at res
503503
simp only [Fin.zero_eta, Nat.sub_zero, pow_zero, Nat.div_one, Fin.eta,
504-
Nat.pow_zero, Nat.getLowBits_zero_eq_zero (n := j.val), Fin.isValue, base_coeffsBySuffix] at res
504+
Nat.pow_zero, Nat.getLowBits_zero_eq_zero (n := j.val), Fin.isValue] at res
505505
simp only [←
506506
intermediate_poly_P_base 𝔽q β h_ℓ_add_R_rate
507507
h_ℓ original_coeffs,
508508
Fin.zero_eta]
509-
rw [← res]
509+
erw [base_coeffsBySuffix] at res
510+
erw [← res]
510511
simp_rw [Nat.sub_right_comm]
511512

512513
end AlgorithmCorrectness

CompPoly/Fields/Binary/AdditiveNTT/Impl.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Chung Thai Nguyen, Quang Dao
66

77
import CompPoly.Fields.Binary.AdditiveNTT.Algorithm
88
import CompPoly.Fields.Binary.Tower.Concrete.Basis
9+
import Mathlib.Data.BitVec
910

1011
/-!
1112
# Additive NTT Implementation
@@ -399,7 +400,8 @@ abbrev BTF₃ := ConcreteBTField 3 -- 8 bits
399400
instance : NeZero (2^3) := ⟨by norm_num⟩
400401
instance : Field BTF₃ := instFieldConcrete
401402
instance : DecidableEq BTF₃ := (inferInstance : DecidableEq (ConcreteBTField 3))
402-
instance : Fintype BTF₃ := (inferInstance : Fintype (ConcreteBTField 3))
403+
instance : Fintype BTF₃ :=
404+
Fintype.ofEquiv (Fin (2 ^ (2 ^ 3))) (BitVec.equivFin (m := 2 ^ 3)).symm.toEquiv
403405

404406
/-- Test of the computable additive NTT over BTF₃ (an 8-bit binary tower field `BTF₃`).
405407
**Input polynomial:** p(x) = x (novel coefficients [7, 1, 0, 0]) of size `2^ℓ` in `BTF₃`

CompPoly/Fields/Binary/AdditiveNTT/Intermediate.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ lemma getSDomainBasisCoeff_of_iteratedQuotientMap
380380
simp only [zero_add]
381381
omega⟩)
382382
simp only [Fin.zero_eta, Fin.coe_ofNat_eq_mod, Nat.sub_zero] at h_interW_comp
383-
rw [h_interW_comp]
383+
erw [h_interW_comp]
384384
have h_index : 0 + i.val = i.val := by omega
385385
rw! (castMode := .all) [h_index]
386386
rfl
@@ -480,7 +480,7 @@ theorem base_intermediateNovelBasisX (j : Fin (2 ^ ℓ)) :
480480
simp only [Fin.mk_zero'] at h_res
481481
conv_lhs =>
482482
enter [2, x, 1]
483-
rw [h_res ⟨x, by omega⟩]
483+
erw [h_res ⟨x, by omega⟩]
484484
congr
485485

486486
omit [DecidableEq L] [DecidableEq 𝔽q] h_Fq_char_prime hF₂ hβ_lin_indep h_β₀_eq_1 in

0 commit comments

Comments
 (0)