Skip to content

induct_unfolding fails to unfold some match expressions #8195

@Rob23oba

Description

@Rob23oba

Prerequisites

Please put an X between the brackets as you perform the following steps:

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_unfolding

The 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions