Repository navigation
feat: no large elim of recursive Prop inductives in the kernel - #13851
Merged
Merged
Conversation
This PR is an experiment that 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 not intended for merging as-is: it is a snapshot to measure the cost (in stdlib churn and in performance) of imposing the restriction, so we can decide whether to pursue it further. `elim_only_at_universe_zero` in `src/kernel/inductive.cpp` now returns true for `is_rec()` inductives. `WellFounded.fix` is redefined in `Init/WF.lean` via a recursive `Prop` `FixGraph` relation plus `Classical.choice` from the prelude (avoiding the import cycle that would arise from `import Init.Classical`). `Init/WFComputable.lean` is restructured: `Acc.recC`/`Acc.ndrec` and their csimp pairs are removed (the recursor signature no longer matches), but compilable csimp rules for `WellFounded.fixF` and `WellFounded.fix` are restored and proved via `FixGraph` uniqueness. `Init/While.lean`'s `whileM.fix` is rewritten on top of `WellFounded.fixF` with an explicit unfolding lemma. 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, `csimpCore.lean` no longer lists `(Acc.rec, Acc.recC)`, and `kernelBacktrack.lean` now sees `Classical.choice` in the axiom dependency list. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…im/no-large-elim # Conflicts: # src/Init/While.lean
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
Adds `Acc.rec'`, `Acc.recOn'`, `Acc.ndrec'` and `Acc.ndrecOn'`, which have the signature `Acc.rec` had before its motive was restricted to `Prop`: any motive in `Sort v`, including one that mentions the accessibility proof. They give code that recurses on an accessibility proof to produce data a mechanical migration path. The motive is closed over the accessibility proof as `C x := (h : Acc r x) → motive x h`, which fits `WellFounded.fixFImpl`'s proof-independent `C` and stays in `Sort v` because `Acc r x` is a proposition; proof irrelevance makes `motive x (Acc.intro x h')` definitionally equal to `motive x h`. So `Acc.rec'` needs only `Prop`-valued elimination of `Acc`, at the cost of depending on `Classical.choice`. `Acc.recC` is restored in `Init/WFComputable.lean` — it never used `Acc.rec`, only well-founded recursion on `Acc.wfRel`, so the restriction does not affect it; what stopped typechecking was the csimp lemma `@Acc.rec = @Acc.recC`, whose two sides no longer had the same type. Stating it for `Acc.rec'` instead restores it, so the new eliminators compile to directly recursive code. What is not recovered is the iota rule. `Acc.rec'_intro` is its propositional counterpart, and `Acc.rec'_eq` unfolds at an arbitrary accessibility proof, which is what proofs that used to close an unfolding equation by `rfl` need. Both equation lemmas pass `motive` explicitly: `Acc.rec'` is `@[elab_as_elim]`, and letting the eliminator elaborator infer the motive in their statements yields one that ignores its `Acc` argument, which no actual `Acc.rec'` application matches. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
nomeata
added a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Aug 20, 2026
`Acc.rec` no longer eliminates into `Sort v`, so the three definitions that recurse on an accessibility proof to produce data go through `Acc.recOn'` / `Acc.rec'` instead. `Acc.rec'` has no iota rule, so the unfolding equations that were closed by `rfl` now go through `Acc.rec'_eq`. `rw` matches on the head symbol, hence the explicit `Acc.recOn'` step before it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Aug 20, 2026
The three kernel soundness regression tests added by #14806 and #14807 build their exploit on `Acc.rec` at a `Bool` motive, which this branch forbids, so they no longer elaborate. `Acc.rec'` cannot stand in: it is backed by `Classical.choice` and has no iota rule, so the definitionally-distinct reducts the tests rely on do not exist. This mirrors the earlier removal of `tests/elab/casesOnAcc.lean`. It does cost coverage for the `is_def_eq` cache and `is_prop` fixes; reinstating it needs an exploit vehicle that does not go through a recursive `Prop` inductive. Co-Authored-By: Claude Opus 5 <[email protected]>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Aug 21, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
Aug 21, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Aug 21, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Aug 21, 2026
`tests/elab/kernel_is_prop_issue.lean` arrived with the latest master merge and builds its gate on `Acc.rec` at a `Bool` motive, so it no longer elaborates on this branch. Same reasoning as the removal of `kernel_is_def_eq_equiv_manager_1/2.lean` and `kernel_is_prop_ensure_sort.lean`. Co-Authored-By: Claude Opus 5 <[email protected]>
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]>
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
…nto joachim/no-large-elim
meefs
pushed a commit
to meefs/lean4
that referenced
this pull request
Oct 14, 2026
leanprover#14892) 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 leanprover#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. --------- Co-authored-by: Claude Opus 5 <[email protected]>
Contributor
|
I believe this PR should also drop the special-casing of |
nomeata
marked this pull request as ready for review
November 20, 2026 15:51
…o-large-elim Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The adaptation PR for this PR is leanprover/downstream-lean4#163. |
`Acc.rec` no longer eliminates into `Type`, so the data-valued major in this test (from #15371) now goes through `Acc.rec'`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hnf` `Acc.ndrec` and `Acc.ndrecOn` are restored as theorems with a `Prop` motive, mirroring `Acc.rec`; data uses go through `Acc.ndrec'` and `Acc.ndrecOn'`. `reduceRec` no longer bumps transparency when reducing the major of `Acc.rec` or `WellFounded.rec`, since well-founded definitions no longer unfold by reducing `Acc.rec`. Also updates the `Acc.rec'` docstring now that `Acc.rec` is restricted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
nomeata
added a commit
to leanprover/downstream-lean4
that referenced
this pull request
Nov 20, 2026
Adapts `Acc.rank` and `SSet.Subcomplex.Pairing.rank'` to leanprover/lean4#13851, which restricts `Acc.rec` to `Prop`; their unfolding lemmas now use `Acc.rec'_eq`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 22, 2026
nomeata
added a commit
that referenced
this pull request
Nov 22, 2026
…cursive Prop inductives (#16671) This PR points the bundled `lean4lean` and `nanoda` checkers at forks that mirror the kernel change from #13851, so that they accept recursors of recursive `Prop` inductives such as `Acc.rec` that only eliminate into `Prop`. The forks are a stop-gap until the Lean Kernel Renovation (#14977) is done and the checkers have caught up upstream. The corresponding changes are proposed upstream as draft PRs digama0/lean4lean#70 and ammkrn/nanoda_lib#86. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
nomeata
added a commit
that referenced
this pull request
Nov 23, 2026
Since #13851, `Acc.rec` no longer eliminates into `Type` and the kernel no longer reduces proofs in major premise position, so the test's `Acc` example no longer applies. Test kernel opacity of theorems directly via `Kernel.whnf`, and use a non-recursive, non-K, indexed Prop inductive for the recursor example. Co-Authored-By: Claude Opus 5.5 <[email protected]>
downstream-lean4 Bot
added a commit
to leanprover/downstream-lean4
that referenced
this pull request
Nov 24, 2026
…el (#163) This is the adaptation PR for leanprover/lean4#13851. --------- 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]>
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 restricts
Acc.recand other recursors for recursivePropinductives to motives inProp, removing large elimination for them while preserving it for non-recursive subsingleton-style products likeEq,And,Iff,Or, andUnit. The motivation is to ensure the kernel never has to look at a proof term of aProp, 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 (#14977).
The library-level work already happened in #14892: defining well-founded recursion without large elimination of
Acc, and addingAcc.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_zeroinsrc/kernel/inductive.cppnow returns true foris_rec()inductives.Acc.ndrecandAcc.ndrecOnare 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.leanis dropped (it tested large elimination ofAcc.casesOnintoNat, which is exactly what the restriction removes),print_cmd.lean's#print Acc.recsnapshot is updated to the restricted signature, andcsimpCore.leanno 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.leanandkernel_is_prop_issue.lean. All four build their exploit onAcc.recat aBoolmotive, so they no longer elaborate, andAcc.rec'cannot stand in for it: beingClassical.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 theis_def_eqcache andis_propfixes, and reinstating it needs an exploit vehicle that does not go through a recursivePropinductive.