Skip to content

Commit 93ad6ec

Browse files
committed
perf(Tactic/FieldSimp): exclude simp lemmas that don't apply for fields. (#21326)
This PR excludes simp lemmas like `div_self'` from being used in the `field_simp` tactic. These lemmas have discrimination tree keys that commonly find a match when running `field_simp`, and if they do match then unification needs to fail, because the field is in fact not a `Group`/`CommGroup`/`LeftCancelMonoid`/`RightCancelMonoid`.
1 parent 6b28ba2 commit 93ad6ec

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Mathlib/Tactic/FieldSimp.lean

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ partial def discharge (prop : Expr) : SimpM (Option Expr) :=
8686
@[inherit_doc discharge]
8787
elab "field_simp_discharge" : tactic => wrapSimpDischarger Mathlib.Tactic.FieldSimp.discharge
8888

89+
/-- The list of lemma's that aren't used in `field_simp`.
90+
91+
`one_div`, `mul_eq_zero` and `one_divp` are excluded because we don't want those rewrites.
92+
93+
The remaining constants are excluded for efficiency. These are lemmas consisting of just
94+
`*`, `/` and `=` that are applicable in a typeclass that can't be a field. -/
95+
def fieldSimpExcluded : List Name := [
96+
``one_div, ``mul_eq_zero, ``one_divp,
97+
98+
``div_self', ``div_div_cancel, ``div_div_cancel_left,
99+
``div_mul_cancel, ``div_mul_cancel_left, ``div_mul_cancel_right,
100+
``mul_div_cancel, ``mul_div_cancel_left, ``mul_div_cancel_right,
101+
``div_div_div_cancel_left, ``div_div_div_cancel_right,
102+
``div_mul_div_cancel, ``div_mul_div_cancel', ``div_mul_mul_cancel,
103+
``mul_div_div_cancel, ``mul_mul_div_cancel,
104+
105+
``div_eq_self,
106+
``mul_left_eq_self, ``mul_right_eq_self, ``self_eq_mul_left, ``self_eq_mul_right,
107+
``div_left_inj, ``div_right_inj, ``mul_left_inj, ``mul_right_inj]
108+
89109
/--
90110
The goal of `field_simp` is to reduce an expression in a field to an expression of the form `n / d`
91111
where neither `n` nor `d` contains any division symbol, just using the simplifier (with a carefully
@@ -169,9 +189,7 @@ elab_rules : tactic
169189
simpOnlyBuiltins.foldlM (·.addConst ·) ({} : SimpTheorems)
170190
else do
171191
let thms0 ← getSimpTheorems
172-
let thms0 ← thms0.erase (.decl ``one_div)
173-
let thms0 ← thms0.erase (.decl `mul_eq_zero)
174-
thms0.erase (.decl ``one_divp)
192+
fieldSimpExcluded.foldlM (init := thms0) fun thms0 name => thms0.erase (.decl name)
175193

176194
let some ext ← getSimpExtension? `field_simps | throwError "field_simps not found"
177195
let thms ← ext.getTheorems

0 commit comments

Comments
 (0)