feat: define well-founded recursion without large elimination of Acc - #14892
Draft
nomeata wants to merge 2 commits into
Draft
feat: define well-founded recursion without large elimination of Acc#14892nomeata wants to merge 2 commits into
Acc#14892nomeata wants to merge 2 commits into
Conversation
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 <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
nomeata
marked this pull request as draft
August 22, 2026 10:29
…lean4 into joachim/wf-without-large-elim
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR redefines
WellFounded.fix,WellFounded.fixFandWellFounded.recursionso that they no longer eliminate an accessibility proof into data, and addsAcc.rec',Acc.recOn',Acc.ndrec'andAcc.ndrecOn'for code that needs to do so itself. Fixpoint equations and compiled code are unchanged, andAcc.recis untouched. The one visible change is that well-founded definitions now depend onClassical.choice, which#print axiomsreports.The new definitions are characterised by a
FixGraphrelation — a recursivePropinductive relating an argument to the value obtained by unfoldingFalong the accessibility tree — and are obtained fromClassical.choice.FixGraphis single-valued, which is whatWellFounded.fixF_eqandWellFounded.fix_eqare now proved from.Classical.choiceis taken from the prelude to avoid the import cycle thatimport Init.Classicalwould create.Acc.rec'and friends have the same signatures asAcc.rec,Acc.recOn,Acc.ndrecandAcc.ndrecOn, but are@[irreducible]and go through the same construction, so they carry no iota rule.Acc.rec'_introandAcc.rec'_eqreplace the definitional unfolding;Acc.rec'_eqis the one to reach for whererflused to close an unfolding equation, and sincerwmatches on the head symbol, wrappers likeAcc.recOn'have to be unfolded first, as inrw [myDef, Acc.recOn', Acc.rec'_eq].@[csimp]lemmas continue to rewriteWellFounded.fixF,WellFounded.fixand the wholeAcc.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.rectoPropmotives; it is useful on its own as a migration path, since downstream code can move toAcc.rec'before that lands.