Skip to content

feat: generalize below and brecOn on subsingletons#12718

Open
arthur-adjedj wants to merge 7 commits intoleanprover:masterfrom
arthur-adjedj:below_subsingletons
Open

feat: generalize below and brecOn on subsingletons#12718
arthur-adjedj wants to merge 7 commits intoleanprover:masterfrom
arthur-adjedj:below_subsingletons

Conversation

@arthur-adjedj
Copy link
Contributor

@arthur-adjedj arthur-adjedj commented Feb 26, 2026

This PR makes it so that (recursive) inductive predicate that are subsingletons, namely Acc, have below and brecOn be generated like any other non-predicate inductive type rather than treating them using IndPredBelow. This allows brecOn to eliminate to sorts instead of only Prop.

Closes #12739

@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 Feb 27, 2026
@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-02-23-rev2 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-02-27 00:27:38)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Feb 27, 2026
@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 Feb 27, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Feb 27, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Feb 27, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@arthur-adjedj
Copy link
Contributor Author

!bench

@leanprover-radar
Copy link

leanprover-radar commented Feb 28, 2026

Benchmark results for f03c018 against c595413 are in! @arthur-adjedj

  • 🟥 build//instructions: +2.1G (+0.02%)

Small changes (4🟥)

  • 🟥 build/module/Init.WF//instructions: +17.0M (+0.89%)
  • 🟥 build/module/Lean.Meta.AbstractNestedProofs//instructions: +45.8M (+1.97%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Lean.Meta.Basic//instructions: +111.5M (+0.43%)
  • 🟥 build/module/Lean.Meta.Constructions.BRecOn//instructions: +518.1M (+8.98%) (reduced significance based on *//lines)

@nomeata
Copy link
Collaborator

nomeata commented Feb 28, 2026

BTW, if you need the stage0 update only to get the test suite to pass, but not because of actual bootstrapping issues, you don't need the stage0 update on this branch. It suffices to leave a comment in stage0/src/stdlib_flags.h and the CI will run the test suite with stage2.

@arthur-adjedj arthur-adjedj marked this pull request as ready for review February 28, 2026 16:11
@arthur-adjedj
Copy link
Contributor Author

changelog-language

@github-actions github-actions bot added the changelog-language Language features and metaprograms label Feb 28, 2026
That is, `inductive` type in `Prop` and cannot eliminate to any `Sort u`.
-/
def isInductivePredicateNotSubsingleton? (declName : Name) : MetaM Bool := do
match (← getEnv).find? (declName ++ `rec) with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ++ can do the wrong thing for names with macro scopes, or something. Do we not have a mkRecName function somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. ++ 'rec is already used in a few other places, it might be worth fixing those too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use it here to not make things worse, but leave that cleanup elsewhere for another PR. Fixing inductives in macros maybe a larger task.

Return `some info` if `declName` is an non-subsingleton inductive predicate where `info : InductiveVal`.
That is, `inductive` type in `Prop` and cannot eliminate to any `Sort u`.
-/
def isInductivePredicateNotSubsingleton? (declName : Name) : MetaM Bool := do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different from ”rec eliminates not into Sort”?

Copy link
Contributor Author

@arthur-adjedj arthur-adjedj Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not. Is there an existing function for this ? If not, should this function be named something else ? it definitely should not end with a ?, that's a typo. Since it replaces isInductivePredicate?, I thought I would extend the naming to specifically mention non-singleton predicates, but something better is probably more sensible

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this construction is really based off the recursor, and simply eliminates into whatever the recursor supports, that seems the more natural phrasing. Imagine people generating “recursors” in libraries at some point. Then this construction would still work and only care about the shape of the recursor.

In other places in the Lean code we do this check simply by checking if the recursor has one level parameter more than its inductive, IIRC. Not sure which check is better or it it makes a difference. It would be nice to unify these checks in one place. I'm not expecting you to do that in this PR, but if you feel like it I'll happily review that.

Copy link
Contributor Author

@arthur-adjedj arthur-adjedj Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places in the Lean code we do this check simply by checking if the recursor has one level parameter more than its inductive.

I will adapt this function to do the same then.

It would be nice to unify these checks in one place

Would adding a "does its recursor eliminate to sort" field to RecursorVal be worth anything for this ? Since this is already computed when the recursor is generated initially, the changes would be minimal (similarly to your past numNested refactoring), and with that implemented, fixing #3213 would now be a one-line change .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary of changing RecursorVal, it may break meta code downstream, and things like the export format. Not worth it given that it is easy to recalculate and not on any hot path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test that eq_def and induct_unfolding work properly here?

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 1, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 1, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

@nomeata nomeata added the P-low We are not planning to work on this issue label Mar 2, 2026
@nomeata
Copy link
Collaborator

nomeata commented Mar 2, 2026

As discussed: This change is welcome in principle, but runs into existing issues in abstractNestedProof that are not straight-forward to fix (#12740). Let's revisit this when and if the issue for abstractNestedProof disappears anyways.

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 P-low We are not planning to work on this issue 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.

Structural recursion over Acc fails

5 participants