-
Notifications
You must be signed in to change notification settings - Fork 717
feat: revert e for arbitrary terms
#8522
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
Draft
kmill
wants to merge
1
commit into
leanprover:master
Choose a base branch
from
kmill:kmill_revert_term
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−7
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,132 @@ | ||
| /-! | ||
| # Tests of the `revert` tactic | ||
| -/ | ||
|
|
||
|
|
||
| theorem tst1 (x y z : Nat) : y = z → x = x → x = y → x = z := | ||
| by { | ||
| /-! | ||
| Simple revert/intro test | ||
| -/ | ||
| /-- | ||
| trace: x y z : Nat | ||
| h1 : y = z | ||
| h3 : x = y | ||
| ⊢ x = x → x = z | ||
| -/ | ||
| #guard_msgs in | ||
| theorem tst1 (x y z : Nat) : y = z → x = x → x = y → x = z := by { | ||
| intros h1 h2 h3; | ||
| revert h2; | ||
| trace_state; | ||
| intro h2; | ||
| exact Eq.trans h3 h1 | ||
| } | ||
|
|
||
| /-! | ||
| Revert reverts dependencies too. | ||
| -/ | ||
| /-- | ||
| trace: x z : Nat | ||
| h2 : x = x | ||
| ⊢ ∀ (y : Nat), y = z → x = y → x = z | ||
| -/ | ||
| #guard_msgs in | ||
| theorem tst2 (x y z : Nat) : y = z → x = x → x = y → x = z := | ||
| by { | ||
| intros h1 h2 h3; | ||
| revert y; | ||
| trace_state; | ||
| intros y hb ha; | ||
| exact Eq.trans ha hb | ||
| } | ||
|
|
||
| /-! | ||
| Can revert a more complex term that evaluates to a hypothesis. | ||
| -/ | ||
| /-- | ||
| trace: x y z : Nat | ||
| a✝¹ : y = z | ||
| a✝ : x = x | ||
| ⊢ x = y → x = z | ||
| -/ | ||
| #guard_msgs in | ||
| theorem tst3 (x y z : Nat) : y = z → x = x → x = y → x = z := by | ||
| intros | ||
| revert ‹x = y› | ||
| trace_state | ||
| intro ha | ||
| exact Eq.trans ha ‹y = z› | ||
|
|
||
| /-! | ||
| Can revert a more complex term that doesn't evaluate to a hypothesis. | ||
| This time, `a✝` itself isn't reverted. | ||
| -/ | ||
| /-- | ||
| trace: x y z : Nat | ||
| a✝² : y = z | ||
| a✝¹ : x = x | ||
| a✝ : x = y | ||
| ⊢ x = y → x = z | ||
| -/ | ||
| #guard_msgs in | ||
| theorem tst4 (x y z : Nat) : y = z → x = x → x = y → x = z := by | ||
| intros | ||
| revert (id ‹x = y›) | ||
| trace_state | ||
| intro ha | ||
| exact Eq.trans ha ‹y = z› | ||
|
|
||
| /-! | ||
| Can revert other expressions. | ||
| -/ | ||
| /-- | ||
| trace: x y : Nat | ||
| h : x = y | ||
| ⊢ x ≤ y → x ≤ y | ||
| -/ | ||
| #guard_msgs in | ||
| theorem tst5 (x y : Nat) : x = y → x ≤ y := by | ||
| intro h | ||
| revert (Nat.le_of_eq h) | ||
| trace_state | ||
| exact id | ||
|
|
||
| /-! | ||
| New metavariables become new goals after the main one. | ||
| -/ | ||
| /-- | ||
| trace: x y : Nat | ||
| h : x = y | ||
| ⊢ x ≤ y → x ≤ y | ||
|
|
||
| case c | ||
| x y : Nat | ||
| h : x = y | ||
| ⊢ x ≤ y | ||
| -/ | ||
| #guard_msgs in | ||
| theorem test6 (x y : Nat) : x = y → x ≤ y := by | ||
| intro h | ||
| revert (?c : x ≤ y) | ||
| trace_state | ||
| case c => exact Nat.le_of_eq h | ||
| exact id | ||
|
|
||
| /-! | ||
| Unsolved natural metavariables are not allowed. | ||
| -/ | ||
| /-- | ||
| error: don't know how to synthesize placeholder | ||
| context: | ||
| x y : Nat | ||
| h : x = y | ||
| ⊢ x ≤ y | ||
| --- | ||
| error: unsolved goals | ||
| x y : Nat | ||
| h : x = y | ||
| ⊢ x ≤ y | ||
| -/ | ||
| #guard_msgs in | ||
| theorem test7 (x y : Nat) : x = y → x ≤ y := by | ||
| intro h | ||
| revert (_ : x ≤ y) | ||
| fail "doesn't get here" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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 bwas pretty much the same asrevert a; revert b.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revertuses local context order, even when there are no dependencies, for exampleends with the state
⊢ ∀ (n m : Nat), True. Same asrevert n m.Given this, if one imagines that
revertis 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 nmanually.There was a problem hiding this comment.
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.