lean4-htt/tests/lean/run/790.lean
Joachim Breitner 29298c9f30
feat: linter.loopingSimpArgs (#8865)
This PR allows `simp` to recognize and warn about simp lemmas that are
likely looping in the current simp set. It does so automatically
whenever simplification fails with the dreaded “max recursion depth”
error fails, but it can be made to do it always with `set_option
linter.loopingSimpArgs true`. This check is not on by default because it
is somewhat costly, and can warn about simp calls that still happen to
work.

This closes #5111. In the end, this implemented much simpler logic than
described there (and tried in the abandoned #8688; see that PR
description for more background information), but it didn’t work as well
as I thought. The current logic is:

“Simplify the RHS of the simp theorem, complain if that fails”.

It is a reasonable policy for a Lean project to say that all simp
invocation should be so that this linter does not complain. Often it is
just a matter of explicitly disabling some simp theorems from the
default simp set, to make it clear and robust that in this call, we do
not want them to trigger. But given that often such simp call happen to
work, it’s too pedantic to impose it on everyone.
2025-06-23 07:36:21 +00:00

31 lines
876 B
Text

class Vec (X : Type) extends Add X, Inhabited X
class Vec' (X : Type) extends Vec X
def differential {X Y : Type} [Vec X] [Vec Y] (f : X → Y) (x dx : X) : Y := f dx
@[simp]
theorem differential_of_linear {X Y : Type} [Vec X] [Vec Y] (f : X → Y) (x dx : X)
: differential f x dx = f dx := by simp[differential]
example {X Y : Type} [Vec X] [Vec Y] (f : X → Y) (x dx : X)
: differential f x dx = f dx := by simp
instance : Vec Nat := ⟨⟩
instance : Vec' Nat := ⟨⟩
set_option trace.Meta.Tactic.simp.rewrite true
/--
trace: [Meta.Tactic.simp.rewrite] differential_of_linear:1000:
differential f x dx
==>
f dx
[Meta.Tactic.simp.rewrite] eq_self:1000:
f dx = f dx
==>
True
-/
#guard_msgs in
example {Y : Type} [Vec Y] (f : Nat → Y) (x dx : Nat)
: @differential _ _ Vec'.toVec _ f x dx = f dx :=
by simp