lean4-htt/tests/lean/run/structuralEqns2.lean
Joachim Breitner 8655f7706f
refactor: structural recursion: prove .eq_def directly (#10606)
This PR changes how Lean proves the equational theorems for structural
recursion. The core idea is to let-bind the `f` argument to `brecOn` and
rewriting `.brecOn` with an unfolding theorem. This means no extra case
split for the `.rec` in `.brecOn` is needed, and `simp` doesn't change
the `f` argument which can break the definitional equality with the
defined function. With this, we can prove the unfolding theorem first,
and derive the equational theorems from that, like for all other ways of
defining recursive functions.

Backs out the changes from #10415, the old strategy works well with the
new goals.

Fixes #5667
Fixes #10431
Fixes #10195
Fixes #2962
2025-10-07 12:53:09 +00:00

33 lines
569 B
Text

import Lean
open Lean
open Lean.Meta
def tst (declName : Name) : MetaM Unit := do
IO.println (← getUnfoldEqnFor? declName)
def g (i j : Nat) : Nat :=
if i < 5 then 0 else
match j with
| Nat.zero => 1
| Nat.succ j => g i j
/-- info: (some g.eq_def) -/
#guard_msgs(pass trace, all) in
#eval tst ``g
#check g.eq_1
#check g.eq_2
#check g.eq_def
def h (i j : Nat) : Nat :=
let z :=
match j with
| Nat.zero => 1
| Nat.succ j => h i j
z + z
/-- info: (some h.eq_def) -/
#guard_msgs in
#eval tst ``h
#check h.eq_1
#check h.eq_2
#check h.eq_def