Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: infer Prop for inductive/structure when defining syntactic subsingletons #5517

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Sep 29, 2024

A Prop-valued inductive type is a syntactic subsingleton if it has at most one constructor and all the arguments to the constructor are in Prop. Such types have large elimination, so they could be defined in Type or Prop without any trouble, though users tend to expect that such types define a Prop and need to learn to insert : Prop.

Currently, the default universe for types is Type. This PR adds a heuristic: if a type is a syntactic subsingleton with exactly one constructor, and the constructor has at least one parameter, then the inductive command will prefer creating a Prop instead of a Type. For structure, we ask for at least one field.

More generally, for mutual inductives, each type needs to be a syntactic subsingleton, at least one type must have one constructor, and at least one constructor must have at least one parameter. The motivation for this restriction is that every inductive type starts with a zero constructors and each constructor starts with zero fields, and stubbed-out types shouldn't be Prop.

Thanks to @arthur-adjedj for the investigation in #2695 and to @digama0 for formulating the heuristic.

Closes #2690

@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 Sep 29, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Sep 29, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Sep 29, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Sep 29, 2024
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Sep 29, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Sep 29, 2024

Mathlib CI status (docs):

  • ❌ Mathlib branch lean-pr-testing-5517 built against this PR, but testing failed. (2024-09-29 07:00:16) View Log
  • ✅ Mathlib branch lean-pr-testing-5517 has successfully built against this PR. (2024-09-29 17:56:08) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fdd5aec172c48f1aac19e90b68775f4cd344d429 --onto 3e75d8f74297bc258352f8d89f71496aacefe7ae. (2024-10-08 22:14:16)

@leanprover-community-bot leanprover-community-bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Sep 29, 2024
@kmill kmill added the awaiting-review Waiting for someone to review the PR label Sep 29, 2024
kmill added 3 commits October 8, 2024 14:29
…c subsingletons

A `Prop`-valued inductive type is a syntactic subsingleton if it has at most one constructor and all the arguments to the constructor are in `Prop`. Such types have large elimination, so they could be defined in `Type` or `Prop` without any trouble, though users tend to expect that such types define a `Prop` and need to learn to insert `: Prop` manually.

Currently, the default universe for types is `Type`. This PR adds a heuristic: if a type is a syntactic subsingleton with exactly one constructor, and the constructor has at least one parameter, then the `inductive` command will prefer creating a `Prop` instead of a `Type`. For `structure`, we ask for at least one field.

More generally, for mutual inductives, each type needs to be a syntactic subsingleton, at least one type must have one constructor, and at least one constructor must have at least one parameter.

Thanks to @arthur-adjedj for the investigation in leanprover#2695.

Closes leanprover#2690
@kmill kmill added this pull request to the merge queue Oct 8, 2024
Merged via the queue into leanprover:master with commit a35e6f4 Oct 8, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR builds-mathlib CI has verified that Mathlib builds against this PR 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.

structure sometimes makes a Type not a Prop.
2 participants