Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(CategoryTheory): let aesop_cat attempt rfl before aesop #21330

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Mathlib/Algebra/Homology/DifferentialObject.lean
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ def dgoToHomologicalComplex :
-- Porting note: this `rw` used to be part of the `simp`.
have : f.f i ≫ Y.d i = X.d i ≫ f.f _ := (congr_fun f.comm i).symm
rw [reassoc_of% this] }
map_id _ := rfl -- the `aesop_cat` autoparam solves this but it's slow
map_comp _ _ := rfl -- the `aesop_cat` autoparam solves this but it's slow

/-- The functor from homological complexes to differential graded objects.
-/
Expand Down
17 changes: 15 additions & 2 deletions Mathlib/CategoryTheory/Category/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Mathlib.Combinatorics.Quiver.Basic
import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.Common
import Mathlib.Tactic.StacksAttribute
import Mathlib.Tactic.TryThis

/-!
# Categories
Expand Down Expand Up @@ -108,6 +109,18 @@ open Lean Meta Elab.Tactic in
else
throwError "The goal does not contain `sorry`"

/--
`rfl_cat` is a macro for `intros; rfl` which is attempted in `aesop_cat` before
doing the more expensive `aesop` tactic.

Note on `refine id ?_`.
In some cases it is important that the type of the proof matches the expected type exactly.
e.g. if the goal is `2 = 1 + 1`, the `rfl` tactic will give a proof of type `2 = 2`.
starting a proof with `refine id ?_` is a trick to make sure that the proof has exactly
the expected type, in this case `2 = 1 + 1`.
-/
macro (name := rfl_cat) "rfl_cat" : tactic => do `(tactic| (refine id ?_; intros; rfl))

/--
A thin wrapper for `aesop` which adds the `CategoryTheory` rule set and
allows `aesop` to look through semireducible definitions when calling `intros`.
Expand All @@ -116,7 +129,7 @@ use in auto-params.
-/
macro (name := aesop_cat) "aesop_cat" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry |
first | sorry_if_sorry | rfl_cat |
aesop $c* (config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))

Expand All @@ -125,7 +138,7 @@ We also use `aesop_cat?` to pass along a `Try this` suggestion when using `aesop
-/
macro (name := aesop_cat?) "aesop_cat?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry |
first | sorry_if_sorry | try_this rfl_cat |
aesop? $c* (config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
/--
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/CategoryTheory/DiscreteCategory.lean
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ theorem functor_obj {I : Type u₁} (F : I → C) (i : I) :
(Discrete.functor F).obj (Discrete.mk i) = F i :=
rfl

@[simp]
theorem functor_map {I : Type u₁} (F : I → C) {i : Discrete I} (f : i ⟶ i) :
(Discrete.functor F).map f = 𝟙 (F i.as) := by aesop_cat

@[simp]
theorem functor_obj_eq_as {I : Type u₁} (F : I → C) (X : Discrete I) :
(Discrete.functor F).obj X = F X.as :=
Expand Down
2 changes: 0 additions & 2 deletions Mathlib/CategoryTheory/Monoidal/Mod_.lean
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def comap {A B : Mon_ C} (f : A ⟶ B) : Mod_ B ⥤ Mod_ A where
slice_rhs 1 2 => rw [whisker_exchange]
slice_rhs 2 3 => rw [← g.act_hom]
rw [Category.assoc] }
map_id _ := rfl -- the `aesop_cat` autoparam solves this but it's slow
map_comp _ _ := rfl -- the `aesop_cat` autoparam solves this but it's slow

-- Lots more could be said about `comap`, e.g. how it interacts with
-- identities, compositions, and equalities of monoid object morphisms.
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Topology/Sheaves/SheafCondition/OpensLeCover.lean
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ variable {Y : Opens X}
in the sieve. This full subcategory is equivalent to `OpensLeCover U`, the (poset)
category of opens contained in some `U i`. -/
@[simps]
def generateEquivalenceOpensLe_functor' (hY : Y = iSup U) :
def generateEquivalenceOpensLe_functor' :
(FullSubcategory fun f : Over Y => (Sieve.generate (presieveOfCoveringAux U Y)).arrows f.hom) ⥤
OpensLeCover U :=
{ obj := fun f =>
Expand Down Expand Up @@ -150,7 +150,7 @@ def generateEquivalenceOpensLe (hY : Y = iSup U) :
(FullSubcategory fun f : Over Y => (Sieve.generate (presieveOfCoveringAux U Y)).arrows f.hom) ≌
OpensLeCover U where
-- Porting note: split it out to prevent timeout
functor := generateEquivalenceOpensLe_functor' _ hY
functor := generateEquivalenceOpensLe_functor' _
inverse := generateEquivalenceOpensLe_inverse' _ hY
unitIso := eqToIso <| CategoryTheory.Functor.ext
(by rintro ⟨⟨_, _⟩, _⟩; dsimp; congr)
Expand Down