Skip to content

Commit b86f532

Browse files
committed
fix aesop_reconcile, now does not need arguments
1 parent 1fc8d7f commit b86f532

1 file changed

Lines changed: 44 additions & 73 deletions

File tree

ArkLib/ProofSystem/Fri/Domain.lean

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ omit [Finite F] in
2727
private lemma op_der_eq : Monoid.toMulAction Fˣ = Units.mulAction' := by ext; rfl
2828

2929
open Lean Elab in
30+
/--
31+
A variation on `rw [op_der_eq] at *`.
32+
33+
Ensures that once `Fˣ` is fixed, we use `Monoid.toMulAction Fˣ`, not `Units.mulAction'`.
34+
-/
3035
private def reconcile (goal : MVarId) : MetaM (Option MVarId) := goal.withContext do
3136
let mut goal ← go goal
3237
for const in ←getLCtx do
@@ -43,46 +48,30 @@ private def reconcile (goal : MVarId) : MetaM (Option MVarId) := goal.withContex
4348
return goal'
4449

4550
open Lean Elab Tactic in
46-
private def reconcile_tac : TacticM Unit := liftMetaTactic1 reconcile
51+
/--
52+
Reconciles `Monoid.toMulAction Fˣ = Units.mulAction'` across the goal.
53+
-/
54+
scoped elab "reconcile" : tactic => liftMetaTactic1 reconcile
4755

4856
/--
4957
`reconcile`-aware `aesop` that deals with coset membership.
5058
51-
- Optionally takes either side of `mem_leftCoset_iff` as a hint.
59+
Can be trivially extended to recognise more than just `mem_leftCoset_iff`.
5260
-/
53-
scoped syntax (name := reconcileStx) withPosition("aesop_reconcile" (colGt ident)?) : tactic
61+
scoped syntax (name := reconcileStx) "aesop_reconcile" : tactic
5462

55-
open Lean Elab Tactic in
63+
set_option hygiene false in
64+
open Lean Elab Tactic PrettyPrinter Delaborator in
5665
@[tactic reconcileStx, inherit_doc reconcileStx]
57-
private def elabReconcileStx : Tactic := fun stx => do
66+
private def elabReconcileStx : Tactic := fun stx => withMainContext do
5867
match stx with
59-
| `(tactic|aesop_reconcile $[$h]?) =>
60-
let tac : TacticM _ :=
61-
match h with
62-
| .none => `(tactic|(try apply (mem_leftCoset_iff _).1
63-
aesop (add safe tactic reconcile_tac)))
64-
| .some h => `(tactic| (try have := (mem_leftCoset_iff _).2 $h
65-
try apply (mem_leftCoset_iff _).1
66-
aesop (add safe tactic reconcile_tac)))
67-
evalTactic (←tac)
68+
| `(tactic|aesop_reconcile) =>
69+
evalTactic (←
70+
`(tactic|(have := fun X₁ X₂ X₃ ↦ @mem_leftCoset_iff Fˣ _ X₁ X₂ X₃
71+
reconcile
72+
aesop)))
6873
| _ => throwError "Unsupported syntax."
6974

70-
/--
71-
Reconciles `Monoid.toMulAction Fˣ = Units.mulAction'` across the goal.
72-
-/
73-
scoped elab "reconcile" : tactic => reconcile_tac
74-
75-
-- open Lean Elab Tactic in
76-
-- scoped elab "reconcile" h:(ident)? : tactic => do
77-
-- let tac : TacticM _ :=
78-
-- match h with
79-
-- | .none => `(tactic|(try apply (mem_leftCoset_iff _).1
80-
-- aesop (add safe tactic (reconcile_tac))))
81-
-- | .some h => `(tactic| (try have := (mem_leftCoset_iff _).2 $h
82-
-- try apply (mem_leftCoset_iff _).1
83-
-- aesop (add safe tactic (reconcile_tac))))
84-
-- evalTactic (←tac)
85-
8675
namespace Domain
8776

8877
/-- Constructs the subgroups of `Fˣ` which we will use to construct
@@ -194,8 +183,10 @@ def domainEmb {i : ℕ} : evalDomain D i ↪ F :=
194183

195184
/- Proof the first subgroup is `D`, the cyclic group generated by `DIsCyclicC.gen : Fˣ` -/
196185
omit [Finite F] in
197-
lemma D_def : D = evalDomain D 0 := by
186+
@[simp]
187+
lemma D_def : evalDomain D 0 = D := by
198188
unfold evalDomain
189+
symm
199190
ext x
200191
rw [Subgroup.mem_zpowers_iff]
201192
simp only [pow_zero, pow_one]
@@ -360,8 +351,6 @@ namespace CosetDomain
360351

361352
open Pointwise
362353

363-
364-
365354
/- Element of `Fˣ` we will use to define our coset -/
366355
variable (x : Fˣ)
367356

@@ -373,21 +362,12 @@ def evalDomain (i : ℕ) : Set Fˣ :=
373362
abbrev evalDomainSigma (s : Fin (n + 1) → ℕ+) (i : ℕ) :=
374363
evalDomain D x (∑ j' ∈ finRangeTo i, s j')
375364

376-
-- set_option pp.all true in
377365
/- Enumeration of the elements of the `i`th coset. -/
378366
def domain (n : ℕ) (i : ℕ) : Fin (2 ^ (n - i)) → evalDomain D x i :=
379367
fun j =>
380368
381369
x ^ 2 ^ i * (DIsCyclicC.gen ^ (2 ^ i)) ^ j.1,
382-
by
383-
simp
384-
rw [←Domain.evalDomain]
385-
have h :
386-
(x ^ 2 ^ i)⁻¹ * (x ^ 2 ^ i * (DIsCyclicC.gen.1 ^ 2 ^ i) ^ j.1) ∈
387-
Domain.evalDomain D i := by
388-
rw [←mul_assoc]
389-
simp
390-
aesop_reconcile h
370+
by aesop_reconcile
391371
392372

393373
lemma domain_injective {i : ℕ} : i ≤ n → Function.Injective (domain D x n i) := by
@@ -422,9 +402,7 @@ noncomputable def domainToFin {i : Fin (n + 1)} : evalDomain D x i → Fin (2 ^
422402
g.1.1 = x.1 ^ (2 ^ i.1) * ((DIsCyclicC.gen.1 ^ (2 ^ i.1)) ^ ind.1) := by
423403
have h := g.2
424404
unfold evalDomain at h
425-
have h' : (x ^ 2 ^ i.1)⁻¹ * ↑g ∈ ↑(Domain.evalDomain D ↑i) := by
426-
apply (@mem_leftCoset_iff Fˣ _ (Domain.evalDomain D ↑i) g.1 (x ^ (2 ^ i.1))).mp
427-
aesop_reconcile
405+
have h' : (x ^ 2 ^ i.1)⁻¹ * ↑g ∈ ↑(Domain.evalDomain D ↑i) := by aesop_reconcile
428406
unfold Domain.evalDomain at h'
429407
rw [Subgroup.mem_zpowers_iff] at h'
430408
rcases h' with ⟨ind, h'⟩
@@ -480,7 +458,11 @@ def injectF {F : Type} [NonBinaryField F] {D : Subgroup Fˣ} [DIsCyclicC : IsCyc
480458
/- Helper lemmas for constructing operations on/lifting between domains. -/
481459

482460
omit [Finite F] in
483-
lemma D_def : evalDomain D x 0 = x • D := by simp [Domain.D_def D]
461+
@[simp]
462+
lemma D_def : evalDomain D x 0 = x • D := by
463+
unfold evalDomain
464+
rw [Domain.D_def]
465+
simp
484466

485467
lemma pow_2_pow_i_mem_Di_of_mem_D {F : Type} [NonBinaryField F] [Finite F] {D : Subgroup Fˣ}
486468
[DIsCyclicC : IsCyclicWithGen ↥D] {x : Fˣ} :
@@ -489,19 +471,17 @@ lemma pow_2_pow_i_mem_Di_of_mem_D {F : Type} [NonBinaryField F] [Finite F] {D :
489471
unfold evalDomain
490472
intros a i h
491473
have h : x⁻¹ * a ∈ Domain.evalDomain D 0 := by aesop_reconcile
492-
rw [←Domain.D_def] at h
493474
have : (x⁻¹ * a) ^ 2 ^ i = (x ^ (2 ^ i))⁻¹ * (a ^ (2 ^ i)) := by field_simp
494-
have h := this ▸ Domain.pow_2_pow_i_mem_Di_of_mem_D D (i := i) h
495-
aesop_reconcile h
475+
simp only [Domain.D_def] at h
476+
have := Domain.pow_2_pow_i_mem_Di_of_mem_D D (i := i) h
477+
aesop_reconcile
496478

497479
omit [Finite F] in
498480
lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
499481
a ∈ evalDomain D x i → a ^ 2 ∈ evalDomain D x (i + 1) := by
500482
unfold evalDomain
501483
intros a i h
502-
have h : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
503-
apply (mem_leftCoset_iff _).mp
504-
aesop
484+
have h : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by aesop_reconcile
505485
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = (x ^ 2 ^ (i + 1))⁻¹ * (a ^ 2) := by
506486
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = ((x ^ 2 ^ i) ^ 2)⁻¹ * (a ^ 2) := by field_simp
507487
rw [this]
@@ -510,8 +490,8 @@ lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
510490
congr 1
511491
grind
512492
rw [this]
513-
have h := this ▸ Domain.sqr_mem_D_succ_i_of_mem_D_i D h
514-
aesop_reconcile h
493+
have h := Domain.sqr_mem_D_succ_i_of_mem_D_i D h
494+
aesop_reconcile
515495

516496
omit [Finite F] in
517497
lemma pow_lift : ∀ {a : Fˣ} {i : ℕ} (s : ℕ),
@@ -533,17 +513,17 @@ lemma neg_mem_dom_of_mem_dom : ∀ {a : Fˣ} (i : Fin n),
533513
unfold evalDomain
534514
rintro a ⟨i, i_prop⟩ h
535515
have mem : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
536-
aesop_reconcile h
516+
aesop_reconcile
537517
have : (x ^ 2 ^ i)⁻¹ * -a ∈ ↑(Domain.evalDomain D i) := by
538518
have : (x ^ 2 ^ i)⁻¹ * -a = ((x ^ 2 ^ i)⁻¹ * a) * (- 1) := by field_simp
539519
rw [this]
540520
exact
541521
(
542522
Subgroup.mul_mem_cancel_right
543-
(Domain.evalDomain D i)
523+
_
544524
(Domain.minus_one_in_doms D i_prop)
545525
).mpr mem
546-
aesop_reconcile this
526+
aesop_reconcile
547527

548528
omit [Finite F] in
549529
lemma mul_root_of_unity {x : Fˣ} :
@@ -553,21 +533,19 @@ lemma mul_root_of_unity {x : Fˣ} :
553533
intros a b i j i_le_j a_in b_in
554534
unfold evalDomain Domain.evalDomain at *
555535
have : (x ^ 2 ^ i)⁻¹ * a ∈ (Subgroup.zpowers (DIsCyclicC.gen.1 ^ 2 ^ i)) := by
556-
apply (mem_leftCoset_iff _).mp
557-
convert a_in
558-
exact op_der_eq
536+
aesop_reconcile
559537
have : (x ^ 2 ^ i)⁻¹ * (a * b) ∈ (Subgroup.zpowers (DIsCyclicC.gen.1 ^ 2 ^ i)) := by
560538
rw [Subgroup.mem_zpowers_iff] at b_in this
561539
rcases this with ⟨ka, a_in⟩
562540
rcases b_in with ⟨kb, b_in⟩
563541
apply Subgroup.mem_zpowers_iff.mpr
564542
exists (ka + (2 ^ (j - i)) * kb)
565543
rw [
566-
←@mul_assoc _ _ a b, ←a_in, ←b_in, zpow_add,
567-
Eq.symm (pow_mul_pow_sub 2 i_le_j), pow_mul, zpow_mul
544+
←@mul_assoc _ _ _ a b, ←a_in, ←b_in, zpow_add,
545+
(pow_mul_pow_sub 2 i_le_j).symm, pow_mul, zpow_mul
568546
]
569547
norm_cast
570-
aesop_reconcile this
548+
aesop_reconcile
571549

572550
omit [Finite F] in
573551
lemma dom_n_eq_triv : evalDomain D x n = {x ^ (2 ^ n)} := by
@@ -577,15 +555,8 @@ lemma dom_n_eq_triv : evalDomain D x n = {x ^ (2 ^ n)} := by
577555

578556
noncomputable local instance : Fintype F := Fintype.ofFinite _
579557

580-
noncomputable instance : Nonempty ↑(CosetDomain.evalDomain D x 0) := by
581-
apply Nonempty.intro
582-
exact
583-
⟨x,
584-
by
585-
simp
586-
have := (@mem_leftCoset_iff Fˣ _ (Subgroup.zpowers DIsCyclicC.gen.1) x x).mpr (by simp)
587-
aesop
588-
558+
noncomputable instance : Nonempty ↑(CosetDomain.evalDomain D x 0) :=
559+
⟨x, by aesop_reconcile⟩
589560

590561
noncomputable instance : Fintype ↑(CosetDomain.evalDomain D x 0) := inferInstance
591562

0 commit comments

Comments
 (0)