Runtime exponential in number of copies of unused variables
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
When adding copies of a propositional parameter, which depends on a large proof term of a specific form, to a theorem, the running time of exact sorry seemingly increases exponentially.
Context
See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Performance.20issue
Steps to Reproduce
def help (A : Type) : ([] : List A).length % 1 = 0 → Prop := fun _ ↦ True
set_option profiler true
--the running time of "exact sorry" seems exponential in the number of h1
theorem slow {A : Type} (p : Bool)
(h : ∀ (hp : ([] : List A).length % 1 = 0), help A hp → help A hp)
(h1 : help A (by cases p <;> omega))
(h1 : help A (by cases p <;> omega))
(h1 : help A (by cases p <;> omega))
(h1 : help A (by cases p <;> omega))
(h1 : help A (by cases p <;> omega))
-- (h1 : help A (by cases p <;> omega))
-- (h1 : help A (by cases p <;> omega))
(hp : ([] : List A).length % 1 = 0) : help A hp := by
refine h (by cases p <;> omega) ?_
exact sorry
--the issue disappers after removing some of the "cases p",
--or replacing "omega" by "simp"
--or replacing A by ℕ
--or replacing "exact sorry" by "exact trivial"
A variant crashing the VS Code infoview is
def help (A : Type) : ([] : List A).length % 1 = 0 → Prop := fun _ ↦ True
set_option profiler true
set_option diagnostics true
example (A : Type) (p : Bool) : ([] : List A).length % 1 = 0 := by
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
-- let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
-- let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
-- let h1 : ([] : List A).length % 1 = 0 := by cases p <;> omega
omega
--also, replacing let by have fixes the issue
Expected behavior: The running time is linear or at least polynomial in the number of copies of h1.
Actual behavior: The running time seems exponential in the number of copies of h1.
Versions
4.11.0-rc2
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal slow reproduction in the issue on Lean 4.11.0-rc2, using set_option profiler true and varying the number of repeated h1 parameters. Compare exact sorry with exact trivial, omega with simp, and the let versus have variants; done means the runtime no longer grows exponentially and the VS Code infoview variant does not crash.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100