Skip to content

Commit c5a05f1

Browse files
chore(SplitFold): docstring and attribute hygiene follow-up to #670
Follow-up to #670, which merged as-is because none of these were blocking. No statement, definition or proof changes semantics. Docstrings: - `splitNth_eval_comp_pow` referenced `splitNth_def`, renamed by #670 to `eq_sum_splitNth`. - The module docstring and that docstring advertised `Polynomial.foldNth`, which does not exist in the repo; point at `FoldingPolynomial.polyFold` and `polyFold_eq_sum_of_splitNth` instead. - `eq_sum_splitNth` and `splitNth_degree_le` used `/- -/` not `/-- -/`, so the file's key identity had no docstring (pre-existing). - Note that `splitNth`'s `n = 0` branch is unreachable (`Fin 0` is empty). Attributes and names: - Drop `@[simp]` from `splitNth_degree_le` and pass it explicitly to the one `aesop` call that needs it. It is an inequality, and it was load-bearing invisibly: `folding_polynomial_eq_sum_splitNth` relied on the attribute without naming it. - `splitNthNoncomputable_of_nz` -> `private lemma splitNthNoncomputable_of_neZero`: a `@[simp]` lemma about a `private` definition should not sit in the global simp set; its sibling `splitNthNoncomputable_coeff` was already private. - `splitNthNoncomputable_eq_splitNth` -> `splitNth_eq_splitNthNoncomputable`, matching the statement's direction. Deprecation sweep: - `Polynomial.eval_finset_sum` -> `eval_finsetSum` (4 sites in `Fri/RoundConsistency.lean`). `./scripts/validate.sh` green. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 646fb08 commit c5a05f1

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

ArkLib/Data/Polynomial/SplitFold.lean

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ This file defines n-way splitting and folding operations on polynomials.
1717
* `Polynomial.splitNth f n i`: Splits polynomial `f` into `n` component polynomials,
1818
where `splitNth f n i` extracts coefficients at positions `j ≡ i (mod n)`.
1919
20-
* `Polynomial.foldNth n f α`: Recombines the n-way split of `f` using powers of `α`,
21-
computing `∑ i : Fin n, α^i * splitNth f n i`. This is the core operation in
22-
FRI-style polynomial commitment schemes.
20+
* `FoldingPolynomial.polyFold f n r`: Recombines the n-way split of `f` using powers of `r`,
21+
computing `∑ i : Fin n, r^i * splitNth f n i` (see `polyFold_eq_sum_of_splitNth`). This is
22+
the core operation in FRI-style polynomial commitment schemes.
2323
2424
## Implementation notes
2525
@@ -43,7 +43,7 @@ coefficients are extracted from positions `j ≡ i (mod n)`, reindexed by `j / n
4343
Formally: `splitNth f n i = ∑_{j ≡ i (mod n)} aⱼ X^(j/n)`.
4444
-/
4545
def splitNth (f : 𝔽[X]) (n : ℕ) (i : Fin n) : 𝔽[X] :=
46-
if hn : n = 0 then f else -- contradictory case
46+
if hn : n = 0 then f else -- unreachable: `Fin 0` is uninhabited
4747
Polynomial.ofFinsupp
4848
4949
Finset.filterMap (fun x ↦ if x % n = i.1 then .some (x / n) else .none)
@@ -78,7 +78,7 @@ private noncomputable def splitNthNoncomputable (f : 𝔽[X]) (n : ℕ) (i : Fin
7878
if k % n = i.1 then Polynomial.C (f.coeff k) * Polynomial.X ^ (k / n) else 0
7979

8080
@[simp]
81-
lemma splitNthNoncomputable_of_nz {f : 𝔽[X]} {n : ℕ} [inst : NeZero n] {i : Fin n} :
81+
private lemma splitNthNoncomputable_of_neZero {f : 𝔽[X]} {n : ℕ} [inst : NeZero n] {i : Fin n} :
8282
splitNthNoncomputable f n i =
8383
∑ k ∈ f.support,
8484
if k % n = i.1 then Polynomial.C (f.coeff k) * Polynomial.X ^ (k / n) else 0 := by
@@ -121,19 +121,19 @@ private lemma splitNthNoncomputable_coeff {n : ℕ} {f : 𝔽[X]} (i : Fin n) (m
121121
Polynomial.mem_support_iff])
122122
· aesop (add safe [cases Fin, (by omega)])
123123

124-
private lemma splitNthNoncomputable_eq_splitNth {n : ℕ} {f : 𝔽[X]} :
124+
private lemma splitNth_eq_splitNthNoncomputable {n : ℕ} {f : 𝔽[X]} :
125125
splitNth f n = splitNthNoncomputable f n := by aesop
126126

127-
/- Proof of key identity `splitNth` has to satisfy. -/
127+
/-- The key identity `splitNth` satisfies: `f` is recovered from its `n` components. -/
128128
lemma eq_sum_splitNth (n : ℕ) [inst : NeZero n] (f : 𝔽[X]) :
129129
f =
130130
∑ i : Fin n,
131131
(Polynomial.X ^ i.1) *
132132
Polynomial.eval₂ Polynomial.C (Polynomial.X ^ n) (splitNth f n i) := by
133-
rw [splitNthNoncomputable_eq_splitNth]
133+
rw [splitNth_eq_splitNthNoncomputable]
134134
have hn : 0 < n := Nat.pos_of_ne_zero inst.out
135135
conv_lhs => rw [Polynomial.as_sum_support_C_mul_X_pow f]
136-
simp only [splitNthNoncomputable_of_nz, eval₂_finsetSum, Finset.mul_sum]
136+
simp only [splitNthNoncomputable_of_neZero, eval₂_finsetSum, Finset.mul_sum]
137137
rw [Finset.sum_comm]
138138
apply Finset.sum_congr rfl
139139
intro k hk
@@ -150,8 +150,7 @@ lemma eq_sum_splitNth (n : ℕ) [inst : NeZero n] (f : 𝔽[X]) :
150150
rw [Finset.sum_congr rfl (fun i _ => hstep i),
151151
Finset.sum_eq_single (⟨k % n, Nat.mod_lt k hn⟩ : Fin n)] <;> aesop
152152

153-
/- Lemma bounding degree of each `n`-split polynomial. -/
154-
@[simp]
153+
/-- Lemma bounding degree of each `n`-split polynomial. -/
155154
lemma splitNth_degree_le {n : ℕ} {f : 𝔽[X]} [inst : NeZero n] {i : Fin n} :
156155
(splitNth f n i).natDegree ≤ f.natDegree / n := by
157156
have hn := inst.out
@@ -179,7 +178,7 @@ lemma folding_polynomial_eq_sum_splitNth {𝔽 : Type} [Field 𝔽] {f : Polynom
179178
(add simp [comp])
180179
(add safe (by ac_nf))
181180
· aesop
182-
(add simp [Bivariate.degreeX])
181+
(add simp [Bivariate.degreeX, splitNth_degree_le])
183182
(add safe natDegree_sum_le_of_forall_le)
184183
· simp only [Bivariate.natDegreeY, natDegree_pow, natDegree_X, mul_one]
185184
exact Nat.lt_of_le_pred (by aesop (add unsafe Nat.zero_lt_of_ne_zero)) <| by
@@ -242,8 +241,8 @@ theorem polyFold_sum {𝔽 : Type} [Field 𝔽] {r : 𝔽}
242241
(add safe (by grind))
243242

244243
/--
245-
Lemma bridges the coefficient-level identity `splitNth_def` and
246-
evaluation-level reasoning about `splitNth` and `foldNth`.
244+
Lemma bridges the coefficient-level identity `eq_sum_splitNth` and
245+
evaluation-level reasoning about `splitNth` and `polyFold`.
247246
-/
248247
lemma splitNth_eval_comp_pow {n : ℕ} [NeZero n] (f : 𝔽[X]) (x : 𝔽) (i : Fin n) :
249248
(eval₂ C (X ^ n) (splitNth f n i)).eval x = (splitNth f n i).eval (x ^ n) := by

ArkLib/ProofSystem/Fri/RoundConsistency.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ lemma generalised_round_consistency_completeness
6666
rw [←eval]
6767
simp
6868
simp only [polyFold_eq_sum_of_splitNth, map_pow]
69-
rw [eval_finset_sum]
69+
rw [eval_finsetSum]
7070
conv =>
7171
rhs
7272
rhs
@@ -102,7 +102,7 @@ lemma generalised_round_consistency_completeness
102102
conv =>
103103
lhs
104104
rw [eq_sum_splitNth n f]
105-
rw [eval_finset_sum, eval_finset_sum]
105+
rw [eval_finsetSum, eval_finsetSum]
106106
conv =>
107107
lhs
108108
rhs
@@ -117,7 +117,7 @@ lemma generalised_round_consistency_completeness
117117
simp
118118
rw [←one_mul (s₀ ^ n), ←h i]
119119
rw [mul_pow]
120-
· rw [eval_finset_sum]
120+
· rw [eval_finsetSum]
121121
conv =>
122122
lhs
123123
rhs

0 commit comments

Comments
 (0)