Skip to content

Conversation

@kmill
Copy link
Collaborator

@kmill kmill commented May 28, 2025

This PR adds a feature to revert where revert e is like have := e; revert this when e is not a local variable. This is sometimes useful for putting a goal into a particular form for other tactics.

Recall that revert sorts the fvars to revert by local context order when reverting. The implementation of this new feature acts as if each non-local-variable term is added to the local context in order and then added to the list of fvars to revert. The result of this is that they appear at the end of the reverted telescope, in the provided order.

This PR adds a feature to `revert` where `revert e` is like `have := e; revert this` when `e` is not a local variable. This is sometimes useful for putting a goal into a particular form for other tactics.
@kmill kmill requested a review from kim-em as a code owner May 28, 2025 21:54
@kmill kmill added awaiting-review Waiting for someone to review the PR changelog-language Language features and metaprograms labels May 28, 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 May 28, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 28, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 28, 2025
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label May 28, 2025
let mut mvarId ← popMainGoal
for e in toAssertRev do
mvarId ← mvarId.assert (← Term.mkFreshBinderName) (← inferType e) e
mvarId ← Prod.snd <$> mvarId.revert fvarIds
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm that means that they aren't always reverted in the order you specify though, doesn't it? It would probably be better if it revert a b was pretty much the same as revert a; revert b.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

revert uses local context order, even when there are no dependencies, for example

example (n : Nat) (m : Nat) : True := by revert m n

ends with the state ⊢ ∀ (n m : Nat), True. Same as revert n m.

Given this, if one imagines that revert is adding the non-fvars to the local context as a first step, then they would come last when reverted.

If you want to control reversion orders, you always can write revert m; revert n manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I guess then it makes sense.

@kmill kmill removed the awaiting-review Waiting for someone to review the PR label Jun 13, 2025
@kmill kmill marked this pull request as draft June 13, 2025 15:09
@leanprover-bot leanprover-bot added the P-low We are not planning to work on this issue label Jun 14, 2025
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 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.

4 participants