Skip to content

Commit 51ec87a

Browse files
committed
cleanup the instance issues, document what's happening
1 parent 74bfbad commit 51ec87a

2 files changed

Lines changed: 66 additions & 75 deletions

File tree

ArkLib/ProofSystem/Fri/Domain.lean

Lines changed: 65 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ variable (D : Subgroup Fˣ) {n : ℕ} [DIsCyclicC : IsCyclicWithGen D] [DSmooth
1111

1212
namespace Fri
1313

14+
section
15+
16+
/-
17+
For `[CommMonoid K], (Monoid.toMulAction _ : MulAction Kˣ Kˣ) = Units.mulAction'` is not defeq.
18+
This leads to some typeclass friction that is ameliorated, albeit not resolved, by some automation.
19+
20+
Viz. the discussion here:
21+
https://leanprover.zulipchat.com/#narrow/channel/217875-Is-there-code-for-X.3F/topic/class.2Flemmas.20for.20smul.20distributing.20over.20smul
22+
-/
23+
24+
omit [Finite F] in
25+
@[simp, grind _=_]
26+
private lemma op_der_eq : Monoid.toMulAction Fˣ = Units.mulAction' := by ext; rfl
27+
28+
omit [Finite F] in
29+
@[grind, aesop safe apply]
30+
private lemma mem_smul_of_congr_aux {a b : Fˣ} {s : Set Fˣ}
31+
(h₅ : a ∈ (@Set.smulSet Fˣ _ (Monoid.toMulAction Fˣ).toSMul).smul b s) :
32+
a ∈ (@Set.smulSet Fˣ _ (Units.mulAction').toSMul).smul b s := by
33+
convert h₅
34+
simp
35+
1436
namespace Domain
1537

1638
/-- Constructs the subgroups of `Fˣ` which we will use to construct
@@ -133,25 +155,17 @@ lemma D_def : D = evalDomain D 0 := by
133155
grind
134156

135157
/- Proof each on of these groups is cyclic (with a computable generator) -/
136-
instance {i : ℕ} : IsCyclicWithGen (evalDomain D i) := by
137-
unfold evalDomain
138-
constructor
139-
swap
140-
· refine ⟨DIsCyclicC.gen.1 ^ 2 ^ i, ?_⟩
141-
simp
142-
· unfold Function.Surjective
143-
rintro ⟨b, h⟩
144-
have : ∃ n : ℤ, b = (DIsCyclicC.gen.1 ^ 2 ^ i) ^ n := by
145-
refine Subgroup.exists_mem_zpowers.mp ?_
146-
exists b
147-
rcases this with ⟨a, h'⟩
148-
exists a
149-
simp only [h']
150-
rfl
158+
instance {i : ℕ} : IsCyclicWithGen (evalDomain D i) :=
159+
160+
⟨DIsCyclicC.gen.1 ^ 2 ^ i, by simp⟩,
161+
by rintro ⟨b, h⟩
162+
have := Subgroup.exists_mem_zpowers.1 ⟨b, ⟨h, rfl⟩⟩
163+
aesop
164+
151165

152166
omit [Finite F] in
153167
lemma pow_2_pow_i_mem_Di_of_mem_D :
154-
∀ {x : Fˣ} (i : ℕ),
168+
∀ {x : Fˣ} {i : ℕ},
155169
x ∈ D → x ^ (2 ^ i) ∈ evalDomain D i := by
156170
intros x i h
157171
simp only [evalDomain]
@@ -236,44 +250,30 @@ lemma minus_one_in_doms {i : ℕ} (h : i < n) :
236250
exists ((2 ^ (n - (i + 1))))
237251
norm_cast
238252
rw [←pow_mul, ←pow_add]
239-
have : (i + (n - (i + 1))) = n - 1 := by
240-
refine Eq.symm ((fun {b a c} h ↦ (Nat.sub_eq_iff_eq_add' h).mp) (Nat.le_sub_one_of_lt h) ?_)
241-
exact Eq.symm (Nat.Simproc.sub_add_eq_comm n i 1)
242-
rw [this]
243-
have : ((DIsCyclicC.gen.1 ^ 2 ^ (n - 1)) ^ 2) = 1 := by
244-
rw [←pow_mul]
245-
have : 2 ^ (n - 1) * 2 = 2 ^ n := by
246-
apply Nat.two_pow_pred_mul_two
247-
linarith
248-
rw [this, ←DSmooth.smooth]
253+
rw [show i + (n - (i + 1)) = n - 1 by omega]
254+
have : (DIsCyclicC.gen.1 ^ 2 ^ (n - 1)) ^ 2 = 1 := by
255+
rw [
256+
←pow_mul,
257+
show 2 ^ (n - 1) * 2 = 2 ^ n by grind [Nat.two_pow_pred_mul_two],
258+
←DSmooth.smooth
259+
]
249260
norm_cast
250261
rw [pow_orderOf_eq_one]
251262
have alg {x : Fˣ} : x^2 = 1 → x = 1 ∨ x = -1 := by
252-
intros h
253-
refine (Units.inv_eq_self_iff x).mp ?_
254-
have {a b : Fˣ} (c : Fˣ) : c * a = c * b → a = b := by
255-
intros h
256-
have : c⁻¹ * (c * a) = c⁻¹ * (c * a) := by rfl
257-
rw (occs := .pos [2]) [h] at this
258-
rw [←mul_assoc, ←mul_assoc, inv_mul_cancel, one_mul, one_mul] at this
259-
exact this
260-
apply this x
261-
simp only [mul_inv_cancel, h.symm, pow_two]
262-
have cast : (DIsCyclicC.gen ^ 2 ^ (n - 1)).1 = (DIsCyclicC.gen.1 ^ 2 ^ (n - 1)) := by rfl
263-
rw [cast]
263+
intros h₁
264+
have := sq_eq_one_iff (a := (x : F))
265+
norm_cast at this
266+
aesop
264267
specialize alg this
265-
rcases alg with alg | alg
266-
· have gen_ord := DSmooth.smooth
267-
rw [orderOf_eq_iff (by simp)] at gen_ord
268-
have gen_ord :=
269-
gen_ord.2
270-
(2 ^ (n - 1))
271-
(by apply Nat.two_pow_pred_lt_two_pow; linarith)
272-
(by simp)
273-
exfalso
274-
apply gen_ord
275-
norm_cast at alg
276-
· assumption
268+
have gen_ord := DSmooth.smooth
269+
rw [orderOf_eq_iff (by simp)] at gen_ord
270+
norm_cast at alg
271+
have gen_ord :=
272+
gen_ord.2
273+
(2 ^ (n - 1))
274+
(by apply Nat.two_pow_pred_lt_two_pow; linarith)
275+
(by simp)
276+
tauto
277277

278278
omit [Finite F] in
279279
lemma dom_n_eq_triv : evalDomain D n = ⊥ := by
@@ -310,9 +310,8 @@ namespace CosetDomain
310310

311311
open Pointwise
312312

313-
omit [Finite F] in
314-
private lemma op_der_eq : Monoid.toMulAction Fˣ = Units.mulAction' := by ext; rfl
315313

314+
316315
/- Element of `Fˣ` we will use to define our coset -/
317316
variable (x : Fˣ)
318317

@@ -324,6 +323,7 @@ def evalDomain (i : ℕ) : Set Fˣ :=
324323
abbrev evalDomainSigma (s : Fin (n + 1) → ℕ+) (i : ℕ) :=
325324
evalDomain D x (∑ j' ∈ finRangeTo i, s j')
326325

326+
-- set_option pp.all true in
327327
/- Enumeration of the elements of the `i`th coset. -/
328328
def domain (n : ℕ) (i : ℕ) : Fin (2 ^ (n - i)) → evalDomain D x i :=
329329
fun j =>
@@ -337,9 +337,7 @@ def domain (n : ℕ) (i : ℕ) : Fin (2 ^ (n - i)) → evalDomain D x i :=
337337
Domain.evalDomain D i := by
338338
rw [←mul_assoc]
339339
simp
340-
convert (mem_leftCoset_iff _).mpr h
341-
expose_names
342-
exact (@op_der_eq F inst).symm
340+
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
343341
344342

345343
lemma domain_injective {i : ℕ} : i ≤ n → Function.Injective (domain D x n i) := by
@@ -376,8 +374,7 @@ noncomputable def domainToFin {i : Fin (n + 1)} : evalDomain D x i → Fin (2 ^
376374
unfold evalDomain at h
377375
have h' : (x ^ 2 ^ i.1)⁻¹ * ↑g ∈ ↑(Domain.evalDomain D ↑i) := by
378376
apply (@mem_leftCoset_iff Fˣ _ (Domain.evalDomain D ↑i) g.1 (x ^ (2 ^ i.1))).mp
379-
convert h
380-
exact op_der_eq
377+
aesop
381378
unfold Domain.evalDomain at h'
382379
rw [Subgroup.mem_zpowers_iff] at h'
383380
rcases h' with ⟨ind, h'⟩
@@ -437,21 +434,19 @@ lemma D_def : evalDomain D x 0 = x • D := by simp [Domain.D_def D]
437434

438435
lemma pow_2_pow_i_mem_Di_of_mem_D {F : Type} [NonBinaryField F] [Finite F] {D : Subgroup Fˣ}
439436
[DIsCyclicC : IsCyclicWithGen ↥D] {x : Fˣ} :
440-
∀ {a : Fˣ} (i : ℕ),
437+
∀ {a : Fˣ} {i : ℕ},
441438
a ∈ evalDomain D x 0 → a ^ (2 ^ i) ∈ evalDomain D x i := by
442439
unfold evalDomain
443440
intros a i h
444441
have h : x⁻¹ * a ∈ Domain.evalDomain D 0 := by
445442
simp only [pow_zero, pow_one] at h
446443
apply (mem_leftCoset_iff _).mp
447-
convert h
448-
exact op_der_eq
444+
aesop
449445
rw [←Domain.D_def] at h
450-
have h := Domain.pow_2_pow_i_mem_Di_of_mem_D D i h
446+
have h := Domain.pow_2_pow_i_mem_Di_of_mem_D D (i := i) h
451447
have : (x⁻¹ * a) ^ 2 ^ i = (x ^ (2 ^ i))⁻¹ * (a ^ (2 ^ i)) := by field_simp
452448
rw [this] at h
453-
convert (mem_leftCoset_iff _).mpr h
454-
exact op_der_eq.symm
449+
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
455450

456451
omit [Finite F] in
457452
lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
@@ -460,8 +455,7 @@ lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
460455
intros a i h
461456
have h : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
462457
apply (mem_leftCoset_iff _).mp
463-
convert h
464-
exact op_der_eq
458+
aesop
465459
have h := Domain.sqr_mem_D_succ_i_of_mem_D_i D h
466460
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = (x ^ 2 ^ (i + 1))⁻¹ * (a ^ 2) := by
467461
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = ((x ^ 2 ^ i) ^ 2)⁻¹ * (a ^ 2) := by field_simp
@@ -472,8 +466,7 @@ lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
472466
grind
473467
rw [this]
474468
rw [this] at h
475-
convert (mem_leftCoset_iff _).mpr h
476-
exact op_der_eq.symm
469+
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
477470

478471
omit [Finite F] in
479472
lemma pow_lift : ∀ {a : Fˣ} {i : ℕ} (s : ℕ),
@@ -496,8 +489,7 @@ lemma neg_mem_dom_of_mem_dom : ∀ {a : Fˣ} (i : Fin n),
496489
rintro a ⟨i, i_prop⟩ h
497490
have mem : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
498491
apply (mem_leftCoset_iff _).mp
499-
convert h
500-
exact op_der_eq
492+
aesop
501493

502494
have : (x ^ 2 ^ i)⁻¹ * -a ∈ ↑(Domain.evalDomain D i) := by
503495
have : (x ^ 2 ^ i)⁻¹ * -a = ((x ^ 2 ^ i)⁻¹ * a) * (- 1) := by field_simp
@@ -533,9 +525,7 @@ lemma mul_root_of_unity {x : Fˣ} :
533525
Eq.symm (pow_mul_pow_sub 2 i_le_j), pow_mul, zpow_mul
534526
]
535527
norm_cast
536-
have := (mem_leftCoset_iff (x ^ 2 ^ i)).mpr this
537-
convert this
538-
exact op_der_eq.symm
528+
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 this)
539529

540530
omit [Finite F] in
541531
lemma dom_n_eq_triv : evalDomain D x n = {x ^ (2 ^ n)} := by
@@ -552,8 +542,7 @@ noncomputable instance : Nonempty ↑(CosetDomain.evalDomain D x 0) := by
552542
by
553543
simp
554544
have := (@mem_leftCoset_iff Fˣ _ (Subgroup.zpowers DIsCyclicC.gen.1) x x).mpr (by simp)
555-
convert this
556-
exact op_der_eq.symm
545+
aesop
557546
558547

559548
noncomputable instance : Fintype ↑(CosetDomain.evalDomain D x 0) := inferInstance
@@ -565,4 +554,6 @@ instance domain_neg_inst {F : Type} [NonBinaryField F] [Finite F] {D : Subgroup
565554

566555
end CosetDomain
567556

557+
end
558+
568559
end Fri

ArkLib/ProofSystem/Fri/Spec/SingleRound.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ noncomputable def queryVerifier (k_le_n : (∑ j', (s j').1) ≤ n) (l : ℕ) [D
727727
let s₀ :
728728
evalDomain D x
729729
(∑ j' ∈ finRangeTo i.1, (s j').1) :=
730-
⟨_, pow_2_pow_i_mem_Di_of_mem_D _ s₀.2
730+
⟨_, pow_2_pow_i_mem_Di_of_mem_D s₀.2
731731
let queries :
732732
List (
733733
evalDomain D x

0 commit comments

Comments
 (0)