Skip to content

lean: add match equation binders for termination measures - #1673

Open
nek0las wants to merge 2 commits into
rems-project:sail2from
nek0las:lean4termpatch
Open

nek0las wants to merge 2 commits into
rems-project:sail2from
nek0las:lean4termpatch

Conversation

@nek0las

@nek0las nek0las commented May 5, 2026

Copy link
Copy Markdown

This aims to solve issue #1659, where Lean 4 cannot automatically find the equality between variables. We add a hypothesis to the match expression so the termination checker can use it.

For example, the generated Lean code now includes h_match in the match expression:

  /-- Type quantifiers: arg1 : Int, arg0 : Int -/
  def test (arg0 : Int) (arg1 : Int) : Bool :=
    let merge_var := (arg0, arg1)
    match h_match : merge_var with
    | (0, g__0) => false
    | (1, x) => (x >b 5)
    | (x, y) =>
      (if ((x ≤b 0) : Bool)
      then false
      else (test (x -i 1) (x +i y)))
  termination_by (let merge_var := (arg0, arg1)
  let (x, _) := merge_var
  x).toNat

@nek0las nek0las changed the title Lean4termpatch lean: add match equation binders for termination measures May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant