Skip to content

Commit 31cd88d

Browse files
committed
perf: avoid proofs on rhs of simp lemmas (#22160)
Some simp rewrite lemmas create large proof terms, causing significant slowdowns. This fix helps avoid a slowdown in [lean4#6973](leanprover/lean4#6973).
1 parent e73fad1 commit 31cd88d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Mathlib/Logic/Equiv/Basic.lean

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,7 @@ open Subtype
10481048
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
10491049
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.
10501050
For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/
1051+
@[simps apply]
10511052
def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) :
10521053
{ a : α // p a } ≃ { b : β // q b } where
10531054
toFun a := ⟨e a, (h _).mp a.property⟩
@@ -1065,25 +1066,21 @@ theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _
10651066
ext
10661067
rfl
10671068

1069+
-- We use `as_aux_lemma` here to avoid creating large proof terms when using `simp`
10681070
@[simp]
10691071
theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) :
10701072
(e.subtypeEquiv h).symm =
1071-
e.symm.subtypeEquiv fun a => by
1073+
e.symm.subtypeEquiv (by as_aux_lemma =>
1074+
intro a
10721075
convert (h <| e.symm a).symm
1073-
exact (e.apply_symm_apply a).symm :=
1076+
exact (e.apply_symm_apply a).symm) :=
10741077
rfl
10751078

10761079
@[simp]
10771080
theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ)
10781081
(h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) :
10791082
(e.subtypeEquiv h).trans (f.subtypeEquiv h')
1080-
= (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) :=
1081-
rfl
1082-
1083-
@[simp]
1084-
theorem subtypeEquiv_apply {p : α → Prop} {q : β → Prop}
1085-
(e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) (x : { x // p x }) :
1086-
e.subtypeEquiv h x = ⟨e x, (h _).1 x.2⟩ :=
1083+
= (e.trans f).subtypeEquiv (by as_aux_lemma => exact fun a => (h a).trans (h' <| e a)) :=
10871084
rfl
10881085

10891086
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to

0 commit comments

Comments
 (0)