feat: defeqParam gadget for delayed assignment metavariables#12854
Draft
feat: defeqParam gadget for delayed assignment metavariables#12854
Conversation
This PR adds a gadget to support recording dependence of `let` variables in the MetavarContext system. The effect is that `Meta.check` can now detect when the values in delayed substitutions that are meant to be used for `let` variables are no longer definitionally equal to what they are supposed to be. For example, after elaborating `(let v := n + 1; ?m : Nat)`, we get a metavariable `?d` and the expression `let v := n + 1; ?d v`, with a delayed assignment `?m := ?d v`. Before, the type of `?d` was `?d : Nat -> Nat`, but now it is `?d : defeqParam (n + 1) -> Nat`. This `defeqParam (n + 1)` gadget is definitionally equal to `Nat`, but the `Meta.check` checker will ensure the argument to `?d` is definitionally equal to `n + 1`. With this gadge, zeta reduction yields `?d (n + 1)`, which satisfies `Meta.check`. Trying to rewrite with `Nat.add_comm` will fail, since the motive needs to be `?d a` for an astract `a : Nat`, which is not definitionally equal to `n + 1`. **Note:** This gadget is ***not*** meant to be used by users. It is only for the implementation of delayed assignments. It is *not* part of Lean's type theory. Closes #8488
Collaborator
|
Reference manual CI status:
|
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Mar 9, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Mar 9, 2026
|
Mathlib CI status (docs):
|
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Mar 10, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Mar 10, 2026
|
Mathlib CI status (docs):
|
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 fixes an issue in the elaborator where delayed substitutions involving dependent
letbindings could create type-incorrect terms. To address this, we encode theletvalue into the type of the metavariable involved in the delayed substitution, which is then checkable byMeta.checkor rewriting tactics.Implementation: it adds a
defeqParamparameter gadget that is only meant to be used for metavariables created by the MetavarContext system when a metavariable depends on a dependentletthat is being abstracted. InMeta.check, there is an additional check for applications that if the domain has@defeqParam t vthen the argument is definitionally equal tov. This immediately fixes any tactic (likerworclear_value) that usesMeta.checkin its operation.For example, after elaborating
(let v := n + 1; ?m : Nat), we get a metavariable?dand the expressionlet v := n + 1; ?d v, with a delayed assignment?m := ?d v. Before this PR, the type of?dwas?d : Nat -> Nat, but now it is?d : defeqParam (n + 1) -> Nat. ThisdefeqParam (n + 1)gadget is definitionally equal toNat, butMeta.checkwill ensure the argument to?dis definitionally equal ton + 1. If we were to zeta reduce the expression, we'd get?d (n + 1), which is still type correct according toMeta.check. Trying to rewrite withNat.add_commwill fail, since the motive needs to be?d afor an abstracta : Nat, which is not definitionally equal ton + 1.Note: This gadget is not meant to be used by users. It is only for the implementation of delayed assignments. It is also not part of Lean's type theory, since it is merely a hint used by the elaborator.
Closes #8488