Skip to content

Commit d3fece4

Browse files
[DRAFT] Fix: WHIR/STIR (#85)
1 parent 14ea17c commit d3fece4

53 files changed

Lines changed: 1163 additions & 953 deletions

Some content is hidden

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

ArkLib.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
156156
import ArkLib.ProofSystem.Whir
157157
import ArkLib.ProofSystem.Whir.BlockRelDistance
158158
import ArkLib.ProofSystem.Whir.Folding
159-
import ArkLib.ProofSystem.Whir.GenMutualCorrAgreement
160-
import ArkLib.ProofSystem.Whir.MainThm
159+
import ArkLib.ProofSystem.Whir.MutualCorrAgreement
161160
import ArkLib.ProofSystem.Whir.OutofDomainSmpl
162-
import ArkLib.ProofSystem.Whir.ProximityGap
163161
import ArkLib.ProofSystem.Whir.ProximityGen
162+
import ArkLib.ProofSystem.Whir.RBRSoundness
164163
import ArkLib.ToMathlib.BigOperators.Fin
165164
import ArkLib.ToMathlib.Data.IndexedBinaryTree.Basic
166165
import ArkLib.ToMathlib.Data.IndexedBinaryTree.Equiv

ArkLib/Data/Classes/DCast.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Quang Dao
55
-/
66

77
import Mathlib.Data.Fin.Basic
8-
import SEq.Tactic.DepRewrite
8+
import Mathlib.Tactic.DepRewrite
99

1010
/-! # Dependent casts
1111

ArkLib/Data/Classes/Zeroize.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Quang Dao
55
-/
66

7-
import Mathlib.Algebra.Notation.Pi
7+
-- Note: Zero.Zero seems to come from Init.Prelude so we could maybe do without the Mathlib import here?
8+
import Mathlib.Algebra.Notation.Pi.Basic
89

910
/-!
1011
# `Zeroize` class

ArkLib/Data/CodingTheory/Basic.lean

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ theorem dist'_eq_dist : ‖C‖₀'.toNat = ‖C‖₀ := by
199199
section
200200

201201
/-
202-
- TODO: We currently do not use `(E)Dist` as it forces the distance(s) into `ℝ`.
203-
Instead, we take some explicit notion of distance `δf`.
204-
Let us give this some thought.
202+
- TODO: We currently do not use `(E)Dist` as it forces the distance(s) into `ℝ`.
203+
Instead, we take some explicit notion of distance `δf`.
204+
Let us give this some thought.
205205
-/
206206

207207
variable {α : Type*}
@@ -426,7 +426,7 @@ end
426426

427427
noncomputable section
428428

429-
variable {F : Type*}[DecidableEq F]
429+
variable {F : Type*} [DecidableEq F]
430430
{ι : Type*} [Fintype ι]
431431

432432

@@ -456,7 +456,7 @@ def projection (S : Finset n) (w : n → R) : S → R :=
456456

457457
omit [Finite R] in theorem projection_injective
458458
(C : Set (n → R))
459-
(nontriv: ‖C‖₀ ≥ 1)
459+
(nontriv : ‖C‖₀ ≥ 1)
460460
(S : Finset n)
461461
(hS : card S = card n - (‖C‖₀ - 1))
462462
(u v : n → R)
@@ -585,10 +585,10 @@ section
585585

586586
variable {F : Type*}
587587
{ι : Type*} [Fintype ι]
588-
: Type*} [Fintype κ]
588+
{κ : Type*} [Fintype κ]
589589

590590
/--
591-
Linear code defined by left multiplication by its generator matrix.
591+
Linear code defined by left multiplication by its generator matrix.
592592
-/
593593
noncomputable def fromRowGenMat [Semiring F] (G : Matrix κ ι F) : LinearCode ι F :=
594594
LinearMap.range G.vecMulLinear
@@ -653,7 +653,7 @@ end
653653

654654
section
655655

656-
variable {F : Type*}[DecidableEq F]
656+
variable {F : Type*} [DecidableEq F]
657657
{ι : Type*} [Fintype ι]
658658

659659
/-- The minimum taken over the weight of codewords in a linear code.
@@ -666,9 +666,9 @@ The Hamming distance between codewords equals to the weight of their difference.
666666
-/
667667
lemma hammingDist_eq_wt_sub [CommRing F] {u v : ι → F} : hammingDist u v = Code.wt (u - v) := by
668668
aesop (add simp [hammingDist, Code.wt, sub_eq_zero])
669-
669+
670670
/--
671-
The min distance of a linear code equals the minimum of the weights of non-zero codewords.
671+
The min distance of a linear code equals the minimum of the weights of non-zero codewords.
672672
-/
673673
lemma dist_eq_minWtCodewords [CommRing F] {LC : LinearCode ι F} :
674674
Code.minDist (LC : Set (ι → F)) = minWtCodewords LC := by
@@ -727,7 +727,7 @@ lemma poly_eq_zero_of_dist_lt {n k : ℕ} {F : Type*} [DecidableEq F] [CommRing
727727
{p : Polynomial F} {ωs : Fin n → F}
728728
(h_deg : p.natDegree < k)
729729
(hn : k ≤ n)
730-
(h_inj: Function.Injective ωs)
730+
(h_inj : Function.Injective ωs)
731731
(h_dist : Δ₀(p.eval ∘ ωs, 0) < n - k + 1)
732732
: p = 0 := by
733733
by_cases hk : k = 0

ArkLib/Data/CodingTheory/BerlekampWelch/Condition.lean

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Mathlib.Algebra.Polynomial.Degree.Definitions
1010
import Mathlib.Algebra.Polynomial.FieldDivision
1111
import Mathlib.Data.Finset.Insert
1212
import Mathlib.Data.Fintype.Card
13-
import Mathlib.Data.Matrix.Mul
13+
import Mathlib.Data.Matrix.Mul
1414
import Mathlib.Data.Matrix.Reflection
1515

1616
import ArkLib.Data.CodingTheory.Basic
@@ -26,23 +26,23 @@ variable {α : Type} {F : Type} [Field F]
2626
{j : Fin (2 * e + k)}
2727
{ωs f : Fin n → F}
2828
{v : Fin (2 * e + k) → F}
29-
{E Q : Polynomial F}
29+
{E Q : Polynomial F}
3030
{p : Polynomial F}
3131

32-
structure BerlekampWelchCondition (e k : ℕ) (ωs f : Fin n → F) (E Q : Polynomial F): Prop where
33-
cond: ∀ i : Fin n, Q.eval (ωs i) = (f i) * E.eval (ωs i)
32+
structure BerlekampWelchCondition (e k : ℕ) (ωs f : Fin n → F) (E Q : Polynomial F) : Prop where
33+
cond: ∀ i : Fin n, Q.eval (ωs i) = (f i) * E.eval (ωs i)
3434
E_natDegree : E.natDegree = e
35-
E_leadingCoeff : E.coeff e = 1
35+
E_leadingCoeff : E.coeff e = 1
3636
Q_natDegree : Q.natDegree ≤ e + k - 1
3737

38-
def Rhs (e : ℕ) (ωs f : Fin n → F) (i : Fin n) : F :=
38+
def Rhs (e : ℕ) (ωs f : Fin n → F) (i : Fin n) : F :=
3939
let αᵢ := ωs i
4040
(-(f i) * αᵢ^e)
4141

4242
def BerlekampWelchMatrix
43-
(e k : ℕ)
44-
(ωs f : Fin n → F) : Matrix (Fin n) (Fin (2 * e + k)) F :=
45-
Matrix.of fun i j =>
43+
(e k : ℕ)
44+
(ωs f : Fin n → F) : Matrix (Fin n) (Fin (2 * e + k)) F :=
45+
Matrix.of fun i j =>
4646
let αᵢ := ωs i
4747
if ↑j < e then -Rhs j.1 ωs f i else -αᵢ^(j - e)
4848

@@ -61,14 +61,14 @@ lemma Rhs_zero_eq_neg : Rhs 0 ωs f i = -f i := by simp [Rhs]
6161
lemma Rhs_zero_eq_neg' : Rhs 0 ωs f = -f := by ext; simp [Rhs]
6262

6363
def IsBerlekampWelchSolution
64-
(e k : ℕ)
64+
(e k : ℕ)
6565
(ωs f : Fin n → F)
6666
(v : Fin (2 * e + k) → F)
67-
: Prop
67+
: Prop
6868
:= Matrix.mulVec (BerlekampWelchMatrix e k ωs f) v = Rhs e ωs f
6969

7070
lemma IsBerlekampWelchSolution_def
71-
: IsBerlekampWelchSolution e k ωs f v
71+
: IsBerlekampWelchSolution e k ωs f v
7272
↔ Matrix.mulVec (BerlekampWelchMatrix e k ωs f) v = (Rhs e ωs f) := by rfl
7373

7474
lemma linsolve_is_berlekamp_welch_solution
@@ -77,7 +77,7 @@ lemma linsolve_is_berlekamp_welch_solution
7777
simp [IsBerlekampWelchSolution, linsolve_some h_linsolve]
7878

7979
lemma is_berlekamp_welch_solution_ext
80-
(h : ∀ i, (Matrix.mulVec (BerlekampWelchMatrix e k ωs f) v) i = -(f i) * (ωs i)^e)
80+
(h : ∀ i, (Matrix.mulVec (BerlekampWelchMatrix e k ωs f) v) i = -(f i) * (ωs i) ^ e)
8181
: IsBerlekampWelchSolution e k ωs f v := by
8282
aesop (add simp [IsBerlekampWelchSolution, Rhs])
8383

@@ -91,10 +91,10 @@ noncomputable def E_and_Q_to_a_solution (e : ℕ) (E Q : Polynomial F) (i : Fin
9191
if i < e then E.toFinsupp i else Q.toFinsupp (i - e)
9292

9393
@[simp]
94-
lemma E_and_Q_to_a_solution_coeff
94+
lemma E_and_Q_to_a_solution_coeff
9595
: E_and_Q_to_a_solution e E Q i = if i < e then E.coeff i else Q.coeff (i - e) := rfl
9696

97-
def truncate (p : Polynomial F) (n : ℕ) : Polynomial F
97+
def truncate (p : Polynomial F) (n : ℕ) : Polynomial F
9898
:= ⟨⟨p.1.1 ∩ Finset.range n, fun i ↦ if i < n then p.1.2 i else 0, by aesop⟩⟩
9999

100100
@[simp]
@@ -116,7 +116,7 @@ lemma mulVec_BerlekampWelchMatrix_eq :
116116
simp [BerlekampWelchMatrix, Matrix.mulVec, dotProduct, Rhs]
117117
ring_nf
118118

119-
section
119+
section
120120

121121
open Polynomial Finset in
122122
private lemma BerlekampWelchCondition_to_Solution [NeZero n]
@@ -203,7 +203,7 @@ lemma eval_solutionToE {x : F} :
203203
all_goals aesop
204204
rw [Finset.sum_bij (i := fun x h ↦ ⟨x, Finset.mem_range.1 h⟩)
205205
(g := fun y : Fin e ↦ v ⟨y.1, by omega⟩ * x ^ y.1)] <;>
206-
aesop (add simp liftF) (add safe (by omega))
206+
aesop (add simp liftF) (add safe (by omega))
207207

208208
@[simp]
209209
lemma coeff_solutionToE :
@@ -224,17 +224,17 @@ lemma solutionToE_zero_eq_C {v : Fin (2 * 0 + k) → F} :
224224

225225
@[simp]
226226
lemma solutionToE_ne_zero : (solutionToE e k v) ≠ 0 := by
227-
by_cases he : e = 0
227+
by_cases he : e = 0
228228
· subst he
229229
simp
230-
· have h_deg : 0 < (solutionToE e k v).natDegree := by
230+
· have h_deg : 0 < (solutionToE e k v).natDegree := by
231231
aesop (add safe (by omega))
232232
intro contr
233233
simp_all
234234

235235
def solutionToQ (e k : ℕ) (v : Fin (2 * e + k) → F) : Polynomial F :=
236236
237-
(Finset.range (e + k)).filter (fun x => liftF v (e + x) ≠ 0),
237+
(Finset.range (e + k)).filter (fun x => liftF v (e + x) ≠ 0),
238238
fun i => if i < e + k then liftF v (e + i) else 0,
239239
by aesop (add safe (by omega))
240240
@@ -248,7 +248,7 @@ lemma natDegree_solutionToQ :
248248
(solutionToQ e k v).natDegree ≤ e + k - 1 := by
249249
simp [solutionToQ, Polynomial.natDegree, Polynomial.degree]
250250
rw [WithBot.unbotD_le_iff] <;>
251-
aesop (add safe (by omega))
251+
aesop (add safe (by omega))
252252

253253
private lemma eval_solutionToQ_aux {i : Fin ((solutionToQ e k v).natDegree + 1)} [NeZero e]
254254
: e + i < 2 * e + k := by
@@ -271,7 +271,7 @@ lemma eval_solutionToQ {x : F} :
271271
rcases e with _ | e
272272
· simp [eval_solutionToQ_cast]
273273
· rw [Polynomial.eval_eq_sum_range'
274-
(n := (e + 1) + k)
274+
(n := (e + 1) + k)
275275
(Nat.lt_of_le_of_lt natDegree_solutionToQ (by omega))]
276276
refine Finset.sum_congr rfl fun x hx ↦ by simp at *; rw [liftF_eq_of_lt (by omega)]; omega
277277

@@ -280,7 +280,7 @@ lemma eval_solutionToQ_zero {x : F} {v} : eval x (solutionToQ 0 k v) =
280280
∑ a ∈ Finset.range k, liftF v a * x ^ a := by
281281
simp [eval_eq_sum, sum_def, solutionToQ, Finset.sum_filter]
282282
refine Finset.sum_congr rfl (by aesop)
283-
283+
284284
@[simp]
285285
lemma solutionToE_and_Q_E_and_Q_to_a_solution :
286286
E_and_Q_to_a_solution e (solutionToE e k v) (solutionToQ e k v) = v := by
@@ -314,8 +314,8 @@ lemma isBerlekampWelchSolution_zero_zero [NeZero n] {v : Fin (2 * 0 + 0) → F}
314314
IsBerlekampWelchSolution 0 0 ωs f v ↔ f = 0 := by
315315
simp [IsBerlekampWelchSolution]
316316

317-
private lemma solution_to_BerlekampWelch_condition {e k : ℕ}
318-
[NeZero n]
317+
private lemma solution_to_BerlekampWelch_condition {e k : ℕ}
318+
[NeZero n]
319319
{ωs f : Fin n → F}
320320
{v : Fin (2 * e + k) → F}
321321
(h_sol : IsBerlekampWelchSolution e k ωs f v)
@@ -347,19 +347,19 @@ private lemma solution_to_BerlekampWelch_condition {e k : ℕ}
347347
case h => intros; left; ring_nf
348348

349349
theorem BerlekampWelchCondition_iff_Solution {e k : ℕ} [NeZero n]
350-
{ωs f : Fin n → F} {v : Fin (2 * e + k) → F}
350+
{ωs f : Fin n → F} {v : Fin (2 * e + k) → F}
351351
:
352352
IsBerlekampWelchSolution e k ωs f v
353-
353+
354354
(BerlekampWelchCondition e k ωs f (solutionToE e k v) (solutionToQ e k v)) :=
355355
⟨solution_to_BerlekampWelch_condition, BerlekampWelchCondition_to_Solution'⟩
356356

357-
lemma linsolve_to_BerlekampWelch_condition {e k : ℕ}
358-
[NeZero n]
357+
lemma linsolve_to_BerlekampWelch_condition {e k : ℕ}
358+
[NeZero n]
359359
{ωs f : Fin n → F}
360360
{v : Fin (2 * e + k) → F}
361361
(h_sol : linsolve (BerlekampWelchMatrix e k ωs f) (Rhs e ωs f) = some v)
362-
: BerlekampWelchCondition e k ωs f (solutionToE e k v) (solutionToQ e k v) :=
362+
: BerlekampWelchCondition e k ωs f (solutionToE e k v) (solutionToQ e k v) :=
363363
solution_to_BerlekampWelch_condition (linsolve_is_berlekamp_welch_solution h_sol)
364364

365365
end
@@ -372,50 +372,50 @@ lemma BerlekampWelch_E_ne_zero {e k : ℕ}
372372
have h_deg := h_cond.E_natDegree
373373
have h_leadCoeff := h_cond.E_leadingCoeff
374374
aesop
375-
376-
section
377375

378-
open Polynomial
376+
section
377+
378+
open Polynomial
379379

380380
variable [DecidableEq F]
381381

382-
lemma BerlekampWelch_Q_ne_zero {e k : ℕ}
383-
[NeZero n]
382+
lemma BerlekampWelch_Q_ne_zero {e k : ℕ}
383+
[NeZero n]
384384
{ωs f : Fin n → F}
385-
{E Q : Polynomial F}
386-
(h_bw : BerlekampWelchCondition e k ωs f E Q)
385+
{E Q : Polynomial F}
386+
(h_bw : BerlekampWelchCondition e k ωs f E Q)
387387
(h_dist : e < Δ₀(f, 0))
388388
(h_inj : Function.Injective ωs)
389389
: Q ≠ 0 := fun contr ↦
390390
have h_cond := h_bw.cond
391391
let S : Finset (Fin n) := {i | ¬f i = 0}
392392
by replace h_dist : e < S.card := by simpa [hammingDist]
393393
simp [contr] at h_cond
394-
have h_card := Polynomial.card_le_degree_of_subset_roots
394+
have h_card := Polynomial.card_le_degree_of_subset_roots
395395
(Z := Finset.image ωs S) (p := E)
396396
(fun _ hx ↦ by
397397
obtain ⟨i, _⟩ := by simpa using hx
398398
specialize (h_cond i); aesop (add simp (BerlekampWelch_E_ne_zero h_bw)))
399399
rw [Finset.card_image_of_injective _ h_inj, h_bw.E_natDegree] at h_card
400400
omega
401401

402-
lemma solutionToQ_ne_zero {e k : ℕ}
403-
[NeZero n]
402+
lemma solutionToQ_ne_zero {e k : ℕ}
403+
[NeZero n]
404404
{ωs f : Fin n → F}
405405
{v : Fin (2 * e + k) → F}
406406
(h_dist : e < Δ₀(f, 0))
407407
(h_sol : IsBerlekampWelchSolution e k ωs f v)
408408
(h_inj : Function.Injective ωs)
409-
: solutionToQ e k v ≠ 0 :=
410-
BerlekampWelch_Q_ne_zero
411-
(solution_to_BerlekampWelch_condition h_sol)
409+
: solutionToQ e k v ≠ 0 :=
410+
BerlekampWelch_Q_ne_zero
411+
(solution_to_BerlekampWelch_condition h_sol)
412412
h_dist
413413
h_inj
414414

415-
lemma E_and_Q_unique
415+
lemma E_and_Q_unique
416416
[NeZero n]
417-
{e k : ℕ}
418-
{E Q E' Q' : Polynomial F}
417+
{e k : ℕ}
418+
{E Q E' Q' : Polynomial F}
419419
{ωs f : Fin n → F}
420420
(he : 2 * e < n - k + 1)
421421
(hk_n : k ≤ n)
@@ -430,16 +430,16 @@ lemma E_and_Q_unique
430430
simp [R]
431431
apply Nat.le_trans (natDegree_add_le _ _)
432432
simp [
433-
natDegree_mul
434-
(BerlekampWelch_E_ne_zero h_bw₁)
433+
natDegree_mul
434+
(BerlekampWelch_E_ne_zero h_bw₁)
435435
h_Q',
436436
natDegree_neg,
437-
natDegree_mul
437+
natDegree_mul
438438
(BerlekampWelch_E_ne_zero h_bw₂)
439439
h_Q
440440
]
441441
aesop (add safe cases BerlekampWelchCondition) (add safe (by omega))
442-
by_cases hr : R = 0
442+
by_cases hr : R = 0
443443
· rw [←add_zero (E' * Q), ←hr]; ring
444444
· let roots := Multiset.ofList <| (List.finRange n).map ωs
445445
have hsub : (⟨roots, by simp [roots]; rw [List.nodup_map_iff h_inj]

ArkLib/Data/CodingTheory/BerlekampWelch/ElocPoly.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ open Fin
160160
lemma elocPolyF_deg {ωs f : Fin n → F} : (ElocPolyF ωs f p).natDegree = Δ₀(f, p.eval ∘ ωs) := by
161161
rw [elocPolyF_eq_elocPoly']
162162
induction' n with n ih
163-
· simp only [elocPoly_zero, map_one, natDegree_one, hamming_zero_eq_dist]
163+
· simp only [elocPoly_zero, natDegree_one, hamming_zero_eq_dist]
164164
exact funext_iff.2 (Fin.elim0 ·)
165165
· rw [
166166
elocPoly_succ,

0 commit comments

Comments
 (0)