-
Notifications
You must be signed in to change notification settings - Fork 408
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
fix: discrepancy in the elaborators for theorem
, def
, and example
#4482
Conversation
Mathlib CI status (docs):
|
This would be great. I'll take a look at Mathlib. There are problems in Mathlib, but they are mostly things that deserve to be fixed. Unfortunately the error messages are terrible, and it's completely unclear that the proofs are being rejected because they specialize the universe variables in the statement. |
When the type of an `example` is a proposition, we should elaborate on them as we elaborate on theorems. This is particularly important for examples that are often used in educational material. Recall that when elaborating theorem headers, we convert unassigned universe metavariables into universe parameters. The motivation is that the proof of a theorem should not influence its statement. However, before this commit, this was not the case for examples when their type was a proposition. This discrepancy often confused users. Additionally, we considered extending the above behavior to definitions when 1- When their type is a proposition. However, it still caused disruption in Mathlib. 2- When their type is provided. That is, we would keep the current behavior only if `: <type>` was omitted. This would make the elaborator for `def` much closer to the one for `theorem`, but it proved to be too restrictive. For example, the following instance in `Core.lean` would fail: ``` instance {α : Sort u} [Setoid α] : HasEquiv α := ⟨Setoid.r⟩ ``` and we would have to write instead: ``` instance {α : Sort u} [Setoid α] : HasEquiv.{u, 0} α := ⟨Setoid.r⟩ ``` There are other failures like this in the core, and we assume many more in Mathlib. closes #4398 closes #4482 Remark: PR #4482 implements option 1 above. We may consider it again in the future.
A typical example of an unhelpful error message is:
which fails with
giving no clue that the fix is:
|
It turns out that that class of inscrutable error was actually very rare in Mathlib. Instead I found many instances where authors had implicitly constrained universes via the RHS of the |
…ture. (#14069) In many places in Mathlib universes in the type signature are invisibly constrained by the RHS of the `def`. This PR makes all these explicit in the type signature. Likely we will change the Lean behaviour to disallow this in leanprover/lean4#4482 (i.e. this is the backport to `master` of the fixes required for that).
…ture. (#14069) In many places in Mathlib universes in the type signature are invisibly constrained by the RHS of the `def`. This PR makes all these explicit in the type signature. Likely we will change the Lean behaviour to disallow this in leanprover/lean4#4482 (i.e. this is the backport to `master` of the fixes required for that).
When the type of a definition or example is a proposition, we should elaborate on them as we elaborate on theorems. This is particularly important for examples that are often used in educational material. Recall that when elaborating theorem headers, we convert unassigned universe metavariables into universe parameters. The motivation is that the proof of a theorem should not influence its statement. However, before this commit, this was not the case for definitions and examples when their type was a proposition. This discrepancy often confused users. Additionally, we considered extending the above behavior whenever the type of a definition is provided. That is, we would keep the current behavior only if `: <type>` was omitted in a definition. However, this proved to be too restrictive. For example, the following instance in `Core.lean` would fail: ``` instance {α : Sort u} [Setoid α] : HasEquiv α := ⟨Setoid.r⟩ ``` and we would have to write instead: ``` instance {α : Sort u} [Setoid α] : HasEquiv.{u, 0} α := ⟨Setoid.r⟩ ``` There are other failures like this in the core, and we assume many more in Mathlib. closes #4398
…ture. (#14069) In many places in Mathlib universes in the type signature are invisibly constrained by the RHS of the `def`. This PR makes all these explicit in the type signature. Likely we will change the Lean behaviour to disallow this in leanprover/lean4#4482 (i.e. this is the backport to `master` of the fixes required for that).
When the type of a definition or example is a proposition,
we should elaborate on them as we elaborate on theorems.
This is particularly important for examples that are often
used in educational material.
Recall that when elaborating theorem headers, we convert unassigned
universe metavariables into universe parameters. The motivation is
that the proof of a theorem should not influence its statement.
However, before this commit, this was not the case for definitions and
examples when their type was a proposition. This discrepancy often confused users.
Additionally, we considered extending the above behavior whenever
the type of a definition is provided. That is, we would keep the
current behavior only if
: <type>
was omitted in a definition.However, this proved to be too restrictive.
For example, the following instance in
Core.lean
would fail:and we would have to write instead:
There are other failures like this in the core, and we assume many more in Mathlib.
closes #4398
@semorrison @jcommelin: what do you think?