Skip to content

feat: define well-founded recursion without large elimination of Acc - #14892

Merged
nomeata merged 6 commits into
masterfrom
joachim/wf-without-large-elim
Oct 14, 2026
Merged

nomeata merged 6 commits into
masterfrom
joachim/wf-without-large-elim

Conversation

@nomeata

@nomeata nomeata commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

This PR redefines WellFounded.fix, WellFounded.fixF and WellFounded.recursion so that they no longer eliminate an accessibility proof into data, and adds Acc.rec', Acc.recOn', Acc.ndrec' and Acc.ndrecOn' for code that needs to do so itself. Fixpoint equations and compiled code are unchanged, and Acc.rec is untouched. The one visible change is that well-founded definitions now depend on Classical.choice, which #print axioms reports.

The new definitions are characterised by a FixGraph relation — a recursive Prop inductive relating an argument to the value obtained by unfolding F along the accessibility tree — and are obtained from Classical.choice. FixGraph is single-valued, which is what WellFounded.fixF_eq and WellFounded.fix_eq are now proved from. Classical.choice is taken from the prelude to avoid the import cycle that import Init.Classical would create.

Acc.rec' and friends have the same signatures as Acc.rec, Acc.recOn, Acc.ndrec and Acc.ndrecOn, but are @[irreducible] and go through the same construction, so they carry no iota rule. Acc.rec'_intro and Acc.rec'_eq replace the definitional unfolding; Acc.rec'_eq is the one to reach for where rfl used to close an unfolding equation, and since rw matches on the head symbol, wrappers like Acc.recOn' have to be unfolded first, as in rw [myDef, Acc.recOn', Acc.rec'_eq].

@[csimp] lemmas continue to rewrite WellFounded.fixF, WellFounded.fix and the whole Acc.rec / Acc.rec' family to directly recursive implementations, so nothing becomes noncomputable in practice. The universe parameters of the primed declarations are pinned motive-first to match the unprimed ones, because @[csimp] requires both sides of a replacement theorem to have identical universe parameter lists.

This is a prerequisite for #13851, which restricts Acc.rec to Prop motives; it is useful on its own as a migration path, since downstream code can move to Acc.rec' before that lands.

This PR redefines `WellFounded.fix`, `WellFounded.fixF` and `WellFounded.recursion` so that they no longer eliminate an accessibility proof into data. They are now characterised by a `FixGraph` relation and obtained from `Classical.choice`, which means they depend on `Classical.choice` where they previously did not, and `#print axioms` reports that for anything defined by well-founded recursion. Their fixpoint equations are unchanged, compiled code is unaffected, and `Acc.rec` itself is untouched.

For code that genuinely needs to eliminate an accessibility proof into data, the PR adds `Acc.rec'`, `Acc.recOn'`, `Acc.ndrec'` and `Acc.ndrecOn'`. These have the same signatures as `Acc.rec` and friends, but are `@[irreducible]` and go through the same `Classical.choice` construction, so they carry no iota rule: `Acc.rec'_intro` and `Acc.rec'_eq` replace the definitional unfolding. `Acc.rec'_eq` is the one to reach for where `rfl` used to close an unfolding equation, and since `rw` matches on the head symbol, wrappers like `Acc.recOn'` have to be unfolded first, as in `rw [myDef, Acc.recOn', Acc.rec'_eq]`.

Together these remove the last uses of large elimination of `Acc` from the definition of well-founded recursion, and give downstream code a way to do the same. `@[csimp]` lemmas continue to rewrite `WellFounded.fixF`, `WellFounded.fix` and the whole `Acc.rec` / `Acc.rec'` family to directly recursive implementations. The universe parameters of the primed declarations are pinned motive-first to match the unprimed ones, because `@[csimp]` requires both sides of a replacement theorem to have identical universe parameter lists.

Co-Authored-By: Claude Opus 5 <[email protected]>
@nomeata nomeata added the changelog-library Library label Aug 22, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Aug 22, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • 💥 Mathlib branch lean-pr-testing-14892 build failed against this PR. (2026-08-22 09:36:56) View Log
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-08-21 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-22 09:47:25)
  • 💥 Mathlib branch lean-pr-testing-14892 build failed against this PR. (2026-08-25 12:30:14) View Log

@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 22, 2026
@leanprover-bot

leanprover-bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-21 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-22 09:47:27)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-08-22 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-25 11:39:22)

@nomeata
nomeata marked this pull request as draft August 22, 2026 10:29
@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 25, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Aug 25, 2026
@nomeata nomeata added the downstream Request a downstream-lean4 adaptation PR. label Oct 13, 2026
…k` tests

Well-founded definitions now use `Classical.choice`, so the axiom collection reaches it before `Quot.sound` in these tests' solutions.

🤖 Built with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#162.

`fixF` is now the choice-based definition itself rather than a wrapper around a separate `fixFImpl`, and `recursion` and `Acc.rec'` are defined through it. The lemmas follow the naming conventions: `FixGraph.nonempty`, `FixGraph.unique` and `fixGraph_fixF`.

🤖 Built with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nomeata
nomeata marked this pull request as ready for review October 13, 2026 17:18
@nomeata nomeata removed the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Oct 13, 2026
@nomeata
nomeata enabled auto-merge October 13, 2026 17:18
@nomeata
nomeata added this pull request to the merge queue Oct 13, 2026
nomeata added a commit to leanprover/downstream-lean4 that referenced this pull request Oct 13, 2026
…nto data

The three definitions that recurse on an accessibility proof to produce data go through `Acc.recOn'` / `Acc.rec'` (added in leanprover/lean4#14892), and their unfolding equations, previously closed by `rfl`, go through `Acc.rec'_eq`. This prepares for leanprover/lean4#13851, which restricts `Acc.rec` to `Prop` motives.

Ported from mathlib4-nightly-testing's `lean-pr-testing-13851` (f88713414c).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@nomeata
nomeata removed this pull request from the merge queue due to a manual request Oct 13, 2026
@nomeata
nomeata added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 14, 2026
Declarations outside a `public section` of a `module` are private already; the `redundantVisibility` linter flags the explicit keyword.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7syR5U28E9wRjXxSWb41s
@nomeata
nomeata enabled auto-merge October 14, 2026 21:04
@nomeata
nomeata added this pull request to the merge queue Oct 14, 2026
Merged via the queue into master with commit 684a6ff Oct 14, 2026
17 checks passed
downstream-lean4 Bot added a commit to leanprover/downstream-lean4 that referenced this pull request Oct 15, 2026
…n of `Acc` (#162)

This is the adaptation PR for leanprover/lean4#14892.

---------

Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com>
Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
meefs pushed a commit to meefs/lean4 that referenced this pull request Nov 21, 2026
…rover#13851)

This PR restricts `Acc.rec` and other recursors for recursive `Prop`
inductives to motives in `Prop`, removing large elimination for them
while preserving it for non-recursive subsingleton-style products like
`Eq`, `And`, `Iff`, `Or`, and `Unit`. The motivation is to ensure the
kernel never has to look at a proof term of a `Prop`, which would in
turn enable downstream tooling (e.g. external checkers) to drop proof
subterms after typechecking.

This is part of the Lean Kernel Renovation
(leanprover#14977).

The library-level work already happened in leanprover#14892: defining well-founded
recursion without large elimination of `Acc`, and adding `Acc.rec'` and
friends as the replacement for eliminating an accessibility proof into
data. What is left here is the kernel change itself and the fallout from
it.

`elim_only_at_universe_zero` in `src/kernel/inductive.cpp` now returns
true for `is_rec()` inductives. `Acc.ndrec` and `Acc.ndrecOn` are
removed along with their `@[csimp]` pairs, since their signatures no
longer typecheck; the primed replacements added by the base PR take
over.

Test expectations adjusted: `casesOnAcc.lean` is dropped (it tested
large elimination of `Acc.casesOn` into `Nat`, which is exactly what the
restriction removes), `print_cmd.lean`'s `#print Acc.rec` snapshot is
updated to the restricted signature, and `csimpCore.lean` no longer
lists `(Acc.rec, Acc.recC)`.

Four kernel soundness regression tests are also dropped:
`kernel_is_def_eq_equiv_manager_1.lean`,
`kernel_is_def_eq_equiv_manager_2.lean`,
`kernel_is_prop_ensure_sort.lean` and `kernel_is_prop_issue.lean`. All
four build their exploit on `Acc.rec` at a `Bool` motive, so they no
longer elaborate, and `Acc.rec'` cannot stand in for it: being
`Classical.choice`-backed and without an iota rule, it does not produce
the definitionally-distinct reducts the exploits depend on. This is a
real loss of coverage for the `is_def_eq` cache and `is_prop` fixes, and
reinstating it needs an exploit vehicle that does not go through a
recursive `Prop` inductive.

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library downstream Request a downstream-lean4 adaptation PR. 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