Skip to content

feat: improve #print recursor rules - #14960

Merged
kmill merged 1 commit into
masterfrom
kmill_print_rec_improve
Aug 29, 2026
Merged

feat: improve #print recursor rules#14960
kmill merged 1 commit into
masterfrom
kmill_print_rec_improve

Conversation

@kmill

@kmill kmill commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

This PR improves the way #print describes recursors. For example, #print Nat.rec now gives the following:

recursor Nat.rec.{u} {motive : Nat → Sort u} (zero : motive Nat.zero) (succ : (n : Nat) → motive n → motive n.succ)
  (t : Nat) : motive t
number of parameters: 0
number of motives: 1 (position 1)
number of minor premises: 2 (positions 2–3)
number of indices: 0
major premise position: 4
rules:
  Nat.rec zero succ Nat.zero
    ==> zero
  Nat.rec zero succ n.succ
    ==> succ n (Nat.rec zero succ n)

For reference, the Nat.rec rules were formerly printed as

rules:
for Nat.zero (0 fields): fun motive zero succ => zero
for Nat.succ (1 fields): fun motive zero succ n => succ n (Nat.rec zero succ n)

These are the raw lambda expressions that the kernel uses to evaluate the reductions. For the new output, we construct the logical reduction rules instead. This is especially helpful in understanding the reduction rules of auxiliary recursors for nested inductive types (i.e. T.rec_1, T.rec_2, ...).

The recursor's type signature is also now pretty printed using named binders like #check, given the importance of the binder names.

This builds on #10543.

With @berberman

This PR improves the way `#print` describes recursors. For example, `#print Nat.rec` now gives the following:
```
recursor Nat.rec.{u} {motive : Nat → Sort u} (zero : motive Nat.zero) (succ : (n : Nat) → motive n → motive n.succ)
  (t : Nat) : motive t
number of parameters: 0
number of motives: 1 (position 1)
number of minor premises: 2 (positions 2–3)
number of indices: 0
major premise position: 4
rules:
  Nat.rec zero succ Nat.zero
    ==> zero
  Nat.rec zero succ n.succ
    ==> succ n (Nat.rec zero succ n)
```

This builds on #10543.

With @berberman
@kmill kmill added the changelog-language Language features and metaprograms label Aug 28, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Aug 28, 2026
@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-25 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-08-28 20:34:20)

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Aug 28, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Aug 28, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

@kmill
kmill added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit 1584f13 Aug 29, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants