-
Notifications
You must be signed in to change notification settings - Fork 717
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
The induct_unfolding and fun_cases_unfolding constructions sometimes splits match cases without unfolding.
Context
This occurred while working on tree maps, in particular trying to use unfolding induction on Std.DTreeMap.Internal.Impl.explore.
Steps to Reproduce
def test (l : List Nat) : Nat :=
match l with
| [] => 0
| x :: l =>
match x == 3 with
| false => test l
| true => test l
#print test.induct_unfoldingThe generated induction looks like this:
test.induct_unfolding (motive : List Nat → Nat → Prop) (case1 : motive [] 0)
(case2 :
∀ (x : Nat) (l : List Nat),
(x == 3) = false →
motive l (test l) →
motive (x :: l)
(match x == 3 with
| false => test l
| true => test l))
(case3 :
∀ (x : Nat) (l : List Nat),
(x == 3) = true →
motive l (test l) →
motive (x :: l)
(match x == 3 with
| false => test l
| true => test l))
(l : List Nat) : motive l (test l)You can see that the match x == 3 has been split into cases 2 and 3, however, the match expression was not reduced. The expected behavior would've been something like:
test.induct_unfolding2 (motive : List Nat → Nat → Prop) (case1 : motive [] 0)
(case2 : ∀ (x : Nat) (l : List Nat), (x == 3) = false → motive l (test l) → motive (x :: l) (test l))
(case3 : ∀ (x : Nat) (l : List Nat), (x == 3) = true → motive l (test l) → motive (x :: l) (test l))
(l : List Nat) : motive l (test l)where the match x == 3 has been reduced into its cases, here test l.
Note: The same problem occurs with fun_cases_unfolding. Writing test using an if-then-else instead causes the issue to disappear.
Versions
Lean 4.20.0-nightly-2025-05-01
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.