leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.52k stars 397 forks source link

"bad" simp lemmas can lead to `acyclic` tactic failure with `simp` recursion limit #3907

Open fpfu opened 5 months ago

fpfu commented 5 months ago

Prerequisites

Description

I assume acyclic should now use omega instead of simp_arith

Context

Steps to Reproduce

import Mathlib.Algebra.Order.Monoid.Lemmas
import Mathlib.Data.Nat.Basic

@[simp] theorem succ_le_iff_lt: n + 1 ≤ k ↔ n < k := sorry

inductive Foo 
| mk (x y: Foo)

set_option trace.Meta.Tactic.acyclic true in
example {x y: Foo} (h: x = Foo.mk y x): False := nomatch h

Expected behavior: acyclic can handle such a goal

Actual behavior: acyclic tactic produces an error message:

[Meta.Tactic.acyclic] failed with
    tactic 'simp' failed, nested error:
    maximum recursion depth has been reached (use `set_option maxRecDepth <num>` to increase limit) 

Versions

4.7.0-rc2

Additional Information

Impact

Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.

leodemoura commented 5 months ago

Remark: acyclic relies on the sizeOf automatically generated simp theorems. Thus, omega by itself cannot close the goals created by acyclic.

Possible solution: add new sizeOf simp set which contains only the sizeOf simp equational theorems.

Possible solution: new acyclic implementation that does not rely on sizeOf. This is the TODO list anyway since the current approach cannot handle functional fields. Example:

inductive Foo 
  | mk (x : Nat → Foo) 
  | bla : Foo

example {x : Foo} (h: x = Foo.mk fun _ => x) : False := 
  nomatch h -- currently fails

Remark: theorem succ_le_iff_lt is problematic independently of acyclic. Example:

example : n + 1 ≤ k := by
  simp_arith -- maximum recursion depth has been reached