Skip to content

Commit 1fc8d7f

Browse files
committed
the first version of reconcile
1 parent 51ec87a commit 1fc8d7f

1 file changed

Lines changed: 68 additions & 26 deletions

File tree

ArkLib/ProofSystem/Fri/Domain.lean

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Mathlib.GroupTheory.Coset.Basic
22
import Mathlib.GroupTheory.GroupAction.Basic
33
import Mathlib.GroupTheory.SpecificGroups.Cyclic
4+
import Mathlib.MeasureTheory.MeasurableSpace.Defs
45

56
import ArkLib.Data.FieldTheory.NonBinaryField.Basic
67
import ArkLib.Data.GroupTheory.Smooth
@@ -25,13 +26,62 @@ omit [Finite F] in
2526
@[simp, grind _=_]
2627
private lemma op_der_eq : Monoid.toMulAction Fˣ = Units.mulAction' := by ext; rfl
2728

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
29+
open Lean Elab in
30+
private def reconcile (goal : MVarId) : MetaM (Option MVarId) := goal.withContext do
31+
let mut goal ← go goal
32+
for const in ←getLCtx do
33+
if const.isImplementationDetail then continue
34+
goal ← go goal (mkIdent const.userName)
35+
pure (.some goal)
36+
where go (goal : MVarId) (loc : Option Ident := .none) : MetaM MVarId := do
37+
let tac : MetaM _ :=
38+
match loc with
39+
| .none => `(tactic|try rewrite [op_der_eq])
40+
| .some loc => `(tactic|try rewrite [op_der_eq] at $loc:ident)
41+
let ([goal'], _) ← runTactic goal (←tac)
42+
| throwError "Failed to reconcile `Monoid.toMulAction` and `Units.mulAction`."
43+
return goal'
44+
45+
open Lean Elab Tactic in
46+
private def reconcile_tac : TacticM Unit := liftMetaTactic1 reconcile
47+
48+
/--
49+
`reconcile`-aware `aesop` that deals with coset membership.
50+
51+
- Optionally takes either side of `mem_leftCoset_iff` as a hint.
52+
-/
53+
scoped syntax (name := reconcileStx) withPosition("aesop_reconcile" (colGt ident)?) : tactic
54+
55+
open Lean Elab Tactic in
56+
@[tactic reconcileStx, inherit_doc reconcileStx]
57+
private def elabReconcileStx : Tactic := fun stx => do
58+
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+
| _ => throwError "Unsupported syntax."
69+
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)
3585

3686
namespace Domain
3787

@@ -337,7 +387,7 @@ def domain (n : ℕ) (i : ℕ) : Fin (2 ^ (n - i)) → evalDomain D x i :=
337387
Domain.evalDomain D i := by
338388
rw [←mul_assoc]
339389
simp
340-
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
390+
aesop_reconcile h
341391
342392

343393
lemma domain_injective {i : ℕ} : i ≤ n → Function.Injective (domain D x n i) := by
@@ -374,7 +424,7 @@ noncomputable def domainToFin {i : Fin (n + 1)} : evalDomain D x i → Fin (2 ^
374424
unfold evalDomain at h
375425
have h' : (x ^ 2 ^ i.1)⁻¹ * ↑g ∈ ↑(Domain.evalDomain D ↑i) := by
376426
apply (@mem_leftCoset_iff Fˣ _ (Domain.evalDomain D ↑i) g.1 (x ^ (2 ^ i.1))).mp
377-
aesop
427+
aesop_reconcile
378428
unfold Domain.evalDomain at h'
379429
rw [Subgroup.mem_zpowers_iff] at h'
380430
rcases h' with ⟨ind, h'⟩
@@ -413,7 +463,7 @@ noncomputable def domainToFin {i : Fin (n + 1)} : evalDomain D x i → Fin (2 ^
413463
rw [h']
414464
simp
415465
rw [h']
416-
norm_cast
466+
rfl
417467
Classical.choose this
418468

419469
def injectF {F : Type} [NonBinaryField F] {D : Subgroup Fˣ} [DIsCyclicC : IsCyclicWithGen ↥D]
@@ -438,15 +488,11 @@ lemma pow_2_pow_i_mem_Di_of_mem_D {F : Type} [NonBinaryField F] [Finite F] {D :
438488
a ∈ evalDomain D x 0 → a ^ (2 ^ i) ∈ evalDomain D x i := by
439489
unfold evalDomain
440490
intros a i h
441-
have h : x⁻¹ * a ∈ Domain.evalDomain D 0 := by
442-
simp only [pow_zero, pow_one] at h
443-
apply (mem_leftCoset_iff _).mp
444-
aesop
491+
have h : x⁻¹ * a ∈ Domain.evalDomain D 0 := by aesop_reconcile
445492
rw [←Domain.D_def] at h
446-
have h := Domain.pow_2_pow_i_mem_Di_of_mem_D D (i := i) h
447493
have : (x⁻¹ * a) ^ 2 ^ i = (x ^ (2 ^ i))⁻¹ * (a ^ (2 ^ i)) := by field_simp
448-
rw [this] at h
449-
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
494+
have h := this ▸ Domain.pow_2_pow_i_mem_Di_of_mem_D D (i := i) h
495+
aesop_reconcile h
450496

451497
omit [Finite F] in
452498
lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
@@ -456,7 +502,6 @@ lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
456502
have h : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
457503
apply (mem_leftCoset_iff _).mp
458504
aesop
459-
have h := Domain.sqr_mem_D_succ_i_of_mem_D_i D h
460505
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = (x ^ 2 ^ (i + 1))⁻¹ * (a ^ 2) := by
461506
have : ((x ^ 2 ^ i)⁻¹ * a) ^ 2 = ((x ^ 2 ^ i) ^ 2)⁻¹ * (a ^ 2) := by field_simp
462507
rw [this]
@@ -465,8 +510,8 @@ lemma sqr_mem_D_succ_i_of_mem_D_i : ∀ {a : Fˣ} {i : ℕ},
465510
congr 1
466511
grind
467512
rw [this]
468-
rw [this] at h
469-
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 h)
513+
have h := this ▸ Domain.sqr_mem_D_succ_i_of_mem_D_i D h
514+
aesop_reconcile h
470515

471516
omit [Finite F] in
472517
lemma pow_lift : ∀ {a : Fˣ} {i : ℕ} (s : ℕ),
@@ -488,9 +533,7 @@ lemma neg_mem_dom_of_mem_dom : ∀ {a : Fˣ} (i : Fin n),
488533
unfold evalDomain
489534
rintro a ⟨i, i_prop⟩ h
490535
have mem : (x ^ 2 ^ i)⁻¹ * a ∈ Domain.evalDomain D i := by
491-
apply (mem_leftCoset_iff _).mp
492-
aesop
493-
536+
aesop_reconcile h
494537
have : (x ^ 2 ^ i)⁻¹ * -a ∈ ↑(Domain.evalDomain D i) := by
495538
have : (x ^ 2 ^ i)⁻¹ * -a = ((x ^ 2 ^ i)⁻¹ * a) * (- 1) := by field_simp
496539
rw [this]
@@ -500,8 +543,7 @@ lemma neg_mem_dom_of_mem_dom : ∀ {a : Fˣ} (i : Fin n),
500543
(Domain.evalDomain D i)
501544
(Domain.minus_one_in_doms D i_prop)
502545
).mpr mem
503-
convert (mem_leftCoset_iff _).mpr this
504-
exact op_der_eq.symm
546+
aesop_reconcile this
505547

506548
omit [Finite F] in
507549
lemma mul_root_of_unity {x : Fˣ} :
@@ -525,7 +567,7 @@ lemma mul_root_of_unity {x : Fˣ} :
525567
Eq.symm (pow_mul_pow_sub 2 i_le_j), pow_mul, zpow_mul
526568
]
527569
norm_cast
528-
exact mem_smul_of_congr_aux ((mem_leftCoset_iff _).2 this)
570+
aesop_reconcile this
529571

530572
omit [Finite F] in
531573
lemma dom_n_eq_triv : evalDomain D x n = {x ^ (2 ^ n)} := by

0 commit comments

Comments
 (0)