This PR extracts the functional (lambda) passed to `brecOn` in structural recursion into a named `_f` helper definition (e.g. `foo._f`), similar to how well-founded recursion uses `._unary`. This way the functional shows up with a helpful name in kernel diagnostics rather than as an anonymous lambda. The `_f` definition is added with `.abbrev` kernel reducibility hints and the `@[reducible]` elaborator attribute, so the kernel unfolds it eagerly after `brecOn` iota-reduces. For inductive predicates, the previous inline lambda behavior is kept. To ensure that parent definitions still get the correct reducibility height (since `getMaxHeight` ignores `.abbrev` definitions), each `_f`'s body height is registered via a new `defHeightOverrideExt` environment extension. `getMaxHeight` checks this extension for all definitions, making the height computation transparent to the extraction. This change improves code size (a bit). It may regress kernel reduction times, especially if a function defined by structural recursion is used in kernel reduction proofs on the hot path. Functions defined by structural recursion are not particularly fast to reduce anyways (due to the `.brecOn` construction), so already now it may be worth writing a kernel-reduction-friendly function manually (using the recursor directly, avoiding overloaded operations). This change will guide you in knowing which function to optimize. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
24 lines
1.1 KiB
Text
24 lines
1.1 KiB
Text
@[reducible] def myAdd._f : (x : Nat) → Nat.below x → Nat → Nat :=
|
||
fun x f x_1 =>
|
||
(match x, x_1 with
|
||
| 0, m => fun x => m
|
||
| n.succ, m => fun x => (x.1 m).succ)
|
||
f
|
||
@[reducible] def myAdd._f : (x : Nat) → Nat.below (motive := fun x => Nat → Nat) x → Nat → Nat :=
|
||
fun x f x_1 =>
|
||
(match (motive := (x : Nat) → Nat → Nat.below (motive := fun x => Nat → Nat) x → Nat) x, x_1 with
|
||
| 0, m => fun x => m
|
||
| n.succ, m => fun x => (x.1 m).succ)
|
||
f
|
||
theorem ex.{u} : ∀ {α β : Sort u} (h : α = β) (a : α), cast h a ≍ a :=
|
||
fun x x_1 x_2 x_3 =>
|
||
match x, x_1, x_2, x_3 with
|
||
| α, .(α), Eq.refl α, a => HEq.refl a
|
||
theorem ex.{u} : ∀ {α β : Sort u} (h : α = β) (a : α), cast h a ≍ a :=
|
||
fun x x_1 x_2 x_3 =>
|
||
match (motive := ∀ (x x_4 : Sort u) (x_5 : x = x_4) (x_6 : x), cast x_5 x_6 ≍ x_6) x, x_1, x_2, x_3 with
|
||
| α, .(α), Eq.refl α, a => HEq.refl a
|
||
def fact : Nat → Nat :=
|
||
fun n => Nat.recOn n 1 fun n acc => (n + 1) * acc
|
||
def fact : Nat → Nat :=
|
||
fun n => Nat.recOn (motive := fun x => Nat) n 1 fun n acc => (n + 1) * acc
|