Skip to content

feat: port Batteries.WF for executable well-founded fixpoints - #11620

Merged
nomeata merged 6 commits into
leanprover:masterfrom
joehendrix:jhx/fixc
Dec 12, 2025
Merged

nomeata merged 6 commits into
leanprover:masterfrom
joehendrix:jhx/fixc

Conversation

@joehendrix

@joehendrix joehendrix commented Dec 11, 2025 •

Copy link
Copy Markdown
Contributor

This PR ports Batteries.WF to Init.WFC for executable well-founded fixpoints. It introduces csimp theorems to replace the recursors and non-executable definitions with executable definitions.

This ocassionally comes up on Zulip as it prevents admiting definitions generated from well-founded induction. (e.g., #lean4 > Computable WellFounded.fix and #mathlib4 > Why Nat.find is computable, when Wellfounded.fix isn't?).

This was motivated by running into poor elaboration performance with recursive definitions involving complex inductive types generated by a custom elaborator. It would be helpful to explore bypassing the elaborator and generating elaborated terms directly, but this requires an executable fixpoint (such as WellFounded.fixC introduced in batteries).

@joehendrix joehendrix changed the title feat: Port Batteries.WF for executable well-founded fixpoints. feat: Port Batteries.WF for executable well-founded fixpoints Dec 11, 2025
@joehendrix joehendrix changed the title feat: Port Batteries.WF for executable well-founded fixpoints feat: port Batteries.WF for executable well-founded fixpoints Dec 11, 2025
@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 Dec 11, 2025
@ghost

ghost commented Dec 11, 2025 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c4477939d07116df842258bf8f9267deea51c466 --onto 19e1fe55f33a8aadc4243da32828b70a4b4677cc. You can force Mathlib CI using the force-mathlib-ci label. (2025-12-11 20:14:27)
  • 💥 Mathlib branch lean-pr-testing-11620 build failed against this PR. (2025-12-12 10:18:34) View Log
  • 💥 Mathlib branch lean-pr-testing-11620 build failed against this PR. (2025-12-12 23:00:48) View Log

@leanprover-bot

leanprover-bot commented Dec 11, 2025 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c4477939d07116df842258bf8f9267deea51c466 --onto eee58f4506d28a14c9a171165f999445a0663d93. You can force reference manual CI using the force-manual-ci label. (2025-12-11 20:14:29)
  • ✅ Reference manual branch lean-pr-testing-11620 has successfully built against this PR. (2025-12-12 10:19:03) View Log
  • 🟡 Reference manual branch lean-pr-testing-11620 build against this PR didn't complete normally. (2025-12-12 10:19:42) View Log

@nomeata

nomeata commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

This was motivated by running into poor elaboration performance with recursive definitions involving complex inductive types generated by a custom elaborator

Do we have an issue tracking this?

But assuming the compiled code you get from using this here is reasonable, I'm happy to have this in core.

We should make wrap public, it's useful generally.

Comment thread src/Init/WFC.lean Resolved
Comment thread src/Init/WFC.lean Resolved
Comment thread src/Init/WFC.lean Resolved
Comment thread src/Init.lean Resolved
Comment thread tests/lean/run/wfcomputable.lean Resolved
@nomeata nomeata added the changelog-language Language features and metaprograms label Dec 11, 2025
Comment thread src/Init/WFComputable.lean Resolved
@joehendrix

Copy link
Copy Markdown
Contributor Author

No issue tracking -- happy to add one if that is helpful.

For performance, I did a little bit of testing with a function defined using this and another defined relying on the elaborator introducing well-founded induction; profiling results in #eval were similar.

I'd naively expect the compiler may do better with the elaborator generated code, since I assume that generates better code, but I haven't really tested it.

@nomeata

nomeata commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

Happy to merge without an issue once CI is happy.

ghost pushed a commit to leanprover-community/batteries that referenced this pull request Dec 12, 2025
@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 Dec 12, 2025
ghost pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 12, 2025
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Dec 12, 2025
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Dec 12, 2025
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Dec 12, 2025
@joehendrix

Copy link
Copy Markdown
Contributor Author

CI checks seem to be working.

I looked into the Batteries failure, and it is the expected name failures. I think that's a trivial fix, but I don't have permission to push to batteries.

Comment thread src/Init/WFComputable.lean Resolved
Comment thread src/Init/WFComputable.lean Resolved
Comment thread src/Init/WFComputable.lean Resolved
@nomeata
nomeata added this pull request to the merge queue Dec 12, 2025
Merged via the queue into leanprover:master with commit ac7b95d Dec 12, 2025
kim-em added a commit to leanprover-community/batteries that referenced this pull request Dec 12, 2025
kim-em added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Dec 12, 2025
kim-em added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 26, 2026
* deprecation in lakefile

* chore: bump to nightly-2025-12-10

* Update lean-toolchain for testing leanprover/lean4#11581

* Update lean-toolchain for testing leanprover/lean4#11587

* chore: adaptations for nightly-2025-12-10

* fix

* fix for leanprover/lean4#11581

* deprecation

* remove unused argument

* feat: register mathlib tactics with try? (#136)

This PR adds `register_try?_tactic` calls for all finishing tactics currently registered with `register_hint`, which are not already covered by `grind` modules (i.e. I have not registered `linarith` or `ring`), using identical priority values:

**Common tactics** (Common.lean):
- tauto (priority 500)
- aesop (priority 80)
- fun_prop (priority 200)

**Domain-specific tactics**:
- norm_num (1000), noncomm_ring (1000)
- field (850), bound (70)
- finiteness (1000), compute_degree (1000), positivity (1000), field_simp (1000)


🤖 Prepared with Claude Code

* chore: adaptations for nightly-2025-12-10 (#141)



Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>

* fix deprecation in mk_all

* chore: adaptations for nightly-2025-12-10

* chore: bump to nightly-2025-12-11

* Kick CI

* lake update

* fix deps

* remove upstreamed

* workaround

* fix

* chore: bump to nightly-2025-12-12

* Update lean-toolchain for testing leanprover/lean4#11620

* more fix

* fix the fix

* lake update

* adding a prime to NameMapExtension

* adaptations for leanprover/lean4#11620

* revert spurious change

* warning

* Merge master into nightly-testing

* fixes

* fix

* deprecations

* chore: bump to nightly-2025-12-13

* lake update

* lake update

* fix merge

* revert a lia back to omega

* remove upstreamed

* deprecation

* fixes

* fix archive

* lint

* lake update aesop

* chore: adaptations for nightly-2025-12-13

* remove aliases for upstreamed lemmas

* deprecation

* revert a lia back to omega

* lake update

* cutsat to lia

* hm

* note

* adaptation notes

* chore: bump to nightly-2025-12-14

* remove @[grind =] from even_sign_iff

* chore: adaptations for nightly-2025-12-13 (#142)

* lake update

* chore: adaptations for nightly-2025-12-14 (#143)

* chore: adaptations for nightly-2025-12-14

* chore: update lean-toolchain to leanprover/lean4:nightly-2025-12-14

* chore: bump to nightly-2025-12-15

* chore: adaptations for nightly-2025-12-15 (#144)

* chore: bump to nightly-2025-12-16

* Update batteries

* Adapt to leanprover/lean4#11608

* Pull in aesop fixes (from my fork, sorry for that)

* chore: adaptations for nightly-2025-12-16

* fixes

* chore: bump to nightly-2025-12-17

* chore: adaptations for nightly-2025-12-17

* chore: adaptations for nightly-2025-12-16 (#145)

* chore: adaptations for nightly-2025-12-17 (#146)

* chore: adaptations for nightly-2025-12-17

* chore: bump to nightly-2025-12-18

* lake update

* chore: adaptations for nightly-2025-12-18

* chore: bump to nightly-2025-12-19

* remove upstreamed

* remove upstreamed

* fixes

* chore: bump to nightly-2025-12-20

* mk_all

* chore: adaptations for nightly-2025-12-20

* chore: adaptations for nightly-2025-12-20 (#148)



Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>

* chore: adaptations for nightly-2025-12-20

* chore: bump to nightly-2025-12-21

* chore: adaptations for nightly-2025-12-21

* chore: adaptations for nightly-2025-12-21 (#149)

* chore: adaptations for nightly-2025-12-21

* chore: bump to nightly-2025-12-22

* chore: adaptations for nightly-2025-12-22

* chore: bump to nightly-2025-12-23

* chore: bump to nightly-2025-12-24

* chore: adaptations for nightly-2025-12-24

* chore: bump to nightly-2025-12-25

* chore: adaptations for nightly-2025-12-25

* chore: bump to nightly-2025-12-26

* chore: adaptations for nightly-2025-12-26

* chore: bump to nightly-2025-12-27

* chore: bump to nightly-2025-12-28

* chore: bump to nightly-2025-12-29

* chore: bump to nightly-2025-12-30

* chore: bump to nightly-2025-12-31

* chore: bump to nightly-2026-01-01

* chore: bump to nightly-2026-01-02

* lake update

* chore: bump to nightly-2026-01-03

* chore: bump to nightly-2026-01-04

* merge lean-pr-testing-10059

* lake update

* deprecations

* Revert "merge lean-pr-testing-10387"

This reverts commit e166d33, reversing
changes made to cf6049c.

* fix

* Revert incorrectly merged lean-pr-testing branches

Reverts the following branches that were incorrectly merged due to a bug
in discover-lean-pr-testing.yml where an empty prs.txt caused grep to
match ALL lean-pr-testing branches:

- lean-pr-testing-2714 (from Oct 2023!)
- lean-pr-testing-11455
- lean-pr-testing-11163
- lean-pr-testing-10231
- lean-pr-testing-10178
- lean-pr-testing-10059

These PRs are not in nightly-2026-01-04, so their adaptations should not
be merged.

The bug fix is in: #33546

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* deprecations

* Update lean-toolchain for testing leanprover/lean4#11893

* fix

* chore: bump to nightly-2026-01-05

* remove upstreamed

* lake update

* fix

* chore: adaptations for nightly-2026-01-05

* chore: bump to nightly-2026-01-06

* chore: adaptations for nightly-2026-01-06

* chore: adaptations for nightly-2026-01-06

* chore: bump to nightly-2026-01-07

* chore: adaptations for nightly-2026-01-07

* chore: adaptations for nightly-2026-01-09 (#159)

* replace aesop proof

* chore: adaptations for nightly-2026-01-07

* chore: bump to nightly-2026-01-08

* chore: adaptations for nightly-2026-01-08

* chore: bump to nightly-2026-01-09

---------

Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: mathlib4-bot <[email protected]>

* chore: adaptations for nightly-2026-01-23 (#160)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: adaptations for nightly-2026-01-24 (#161)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: adaptations for nightly-2026-01-25 (#162)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: bump toolchain to v4.28.0-rc1

* fix: use main/master instead of nightly-testing for dependencies

---------

Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Ruben Van de Velde <[email protected]>
Co-authored-by: leanprover-community-bot-assistant <97194829+leanprover-community-bot-assistant@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Kevin Buzzard <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>
YellPika pushed a commit to YellPika/mathlib4 that referenced this pull request Feb 3, 2026
* deprecation in lakefile

* chore: bump to nightly-2025-12-10

* Update lean-toolchain for testing leanprover/lean4#11581

* Update lean-toolchain for testing leanprover/lean4#11587

* chore: adaptations for nightly-2025-12-10

* fix

* fix for leanprover/lean4#11581

* deprecation

* remove unused argument

* feat: register mathlib tactics with try? (leanprover-community#136)

This PR adds `register_try?_tactic` calls for all finishing tactics currently registered with `register_hint`, which are not already covered by `grind` modules (i.e. I have not registered `linarith` or `ring`), using identical priority values:

**Common tactics** (Common.lean):
- tauto (priority 500)
- aesop (priority 80)
- fun_prop (priority 200)

**Domain-specific tactics**:
- norm_num (1000), noncomm_ring (1000)
- field (850), bound (70)
- finiteness (1000), compute_degree (1000), positivity (1000), field_simp (1000)


🤖 Prepared with Claude Code

* chore: adaptations for nightly-2025-12-10 (leanprover-community#141)



Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>

* fix deprecation in mk_all

* chore: adaptations for nightly-2025-12-10

* chore: bump to nightly-2025-12-11

* Kick CI

* lake update

* fix deps

* remove upstreamed

* workaround

* fix

* chore: bump to nightly-2025-12-12

* Update lean-toolchain for testing leanprover/lean4#11620

* more fix

* fix the fix

* lake update

* adding a prime to NameMapExtension

* adaptations for leanprover/lean4#11620

* revert spurious change

* warning

* Merge master into nightly-testing

* fixes

* fix

* deprecations

* chore: bump to nightly-2025-12-13

* lake update

* lake update

* fix merge

* revert a lia back to omega

* remove upstreamed

* deprecation

* fixes

* fix archive

* lint

* lake update aesop

* chore: adaptations for nightly-2025-12-13

* remove aliases for upstreamed lemmas

* deprecation

* revert a lia back to omega

* lake update

* cutsat to lia

* hm

* note

* adaptation notes

* chore: bump to nightly-2025-12-14

* remove @[grind =] from even_sign_iff

* chore: adaptations for nightly-2025-12-13 (leanprover-community#142)

* lake update

* chore: adaptations for nightly-2025-12-14 (leanprover-community#143)

* chore: adaptations for nightly-2025-12-14

* chore: update lean-toolchain to leanprover/lean4:nightly-2025-12-14

* chore: bump to nightly-2025-12-15

* chore: adaptations for nightly-2025-12-15 (leanprover-community#144)

* chore: bump to nightly-2025-12-16

* Update batteries

* Adapt to leanprover/lean4#11608

* Pull in aesop fixes (from my fork, sorry for that)

* chore: adaptations for nightly-2025-12-16

* fixes

* chore: bump to nightly-2025-12-17

* chore: adaptations for nightly-2025-12-17

* chore: adaptations for nightly-2025-12-16 (leanprover-community#145)

* chore: adaptations for nightly-2025-12-17 (leanprover-community#146)

* chore: adaptations for nightly-2025-12-17

* chore: bump to nightly-2025-12-18

* lake update

* chore: adaptations for nightly-2025-12-18

* chore: bump to nightly-2025-12-19

* remove upstreamed

* remove upstreamed

* fixes

* chore: bump to nightly-2025-12-20

* mk_all

* chore: adaptations for nightly-2025-12-20

* chore: adaptations for nightly-2025-12-20 (leanprover-community#148)



Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>

* chore: adaptations for nightly-2025-12-20

* chore: bump to nightly-2025-12-21

* chore: adaptations for nightly-2025-12-21

* chore: adaptations for nightly-2025-12-21 (leanprover-community#149)

* chore: adaptations for nightly-2025-12-21

* chore: bump to nightly-2025-12-22

* chore: adaptations for nightly-2025-12-22

* chore: bump to nightly-2025-12-23

* chore: bump to nightly-2025-12-24

* chore: adaptations for nightly-2025-12-24

* chore: bump to nightly-2025-12-25

* chore: adaptations for nightly-2025-12-25

* chore: bump to nightly-2025-12-26

* chore: adaptations for nightly-2025-12-26

* chore: bump to nightly-2025-12-27

* chore: bump to nightly-2025-12-28

* chore: bump to nightly-2025-12-29

* chore: bump to nightly-2025-12-30

* chore: bump to nightly-2025-12-31

* chore: bump to nightly-2026-01-01

* chore: bump to nightly-2026-01-02

* lake update

* chore: bump to nightly-2026-01-03

* chore: bump to nightly-2026-01-04

* merge lean-pr-testing-10059

* lake update

* deprecations

* Revert "merge lean-pr-testing-10387"

This reverts commit e166d33, reversing
changes made to cf6049c.

* fix

* Revert incorrectly merged lean-pr-testing branches

Reverts the following branches that were incorrectly merged due to a bug
in discover-lean-pr-testing.yml where an empty prs.txt caused grep to
match ALL lean-pr-testing branches:

- lean-pr-testing-2714 (from Oct 2023!)
- lean-pr-testing-11455
- lean-pr-testing-11163
- lean-pr-testing-10231
- lean-pr-testing-10178
- lean-pr-testing-10059

These PRs are not in nightly-2026-01-04, so their adaptations should not
be merged.

The bug fix is in: leanprover-community#33546

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* deprecations

* Update lean-toolchain for testing leanprover/lean4#11893

* fix

* chore: bump to nightly-2026-01-05

* remove upstreamed

* lake update

* fix

* chore: adaptations for nightly-2026-01-05

* chore: bump to nightly-2026-01-06

* chore: adaptations for nightly-2026-01-06

* chore: adaptations for nightly-2026-01-06

* chore: bump to nightly-2026-01-07

* chore: adaptations for nightly-2026-01-07

* chore: adaptations for nightly-2026-01-09 (leanprover-community#159)

* replace aesop proof

* chore: adaptations for nightly-2026-01-07

* chore: bump to nightly-2026-01-08

* chore: adaptations for nightly-2026-01-08

* chore: bump to nightly-2026-01-09

---------

Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: mathlib4-bot <[email protected]>

* chore: adaptations for nightly-2026-01-23 (leanprover-community#160)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: adaptations for nightly-2026-01-24 (leanprover-community#161)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: adaptations for nightly-2026-01-25 (leanprover-community#162)



Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>

* chore: bump toolchain to v4.28.0-rc1

* fix: use main/master instead of nightly-testing for dependencies

---------

Co-authored-by: leanprover-community-mathlib4-bot <[email protected]>
Co-authored-by: mathlib4-bot <[email protected]>
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Joachim Breitner <[email protected]>
Co-authored-by: Sebastian Ullrich <[email protected]>
Co-authored-by: Ruben Van de Velde <[email protected]>
Co-authored-by: leanprover-community-bot-assistant <97194829+leanprover-community-bot-assistant@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Kevin Buzzard <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Rob23oba <[email protected]>
Co-authored-by: Markus Himmel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan builds-manual CI has verified that the Lean Language Reference 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.

4 participants