-
Notifications
You must be signed in to change notification settings - Fork 28
feat: irevert tactic #74
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
Open
oliversoeser
wants to merge
8
commits into
leanprover-community:master
Choose a base branch
from
oliversoeser:irevert
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b1a98c2
feat: irevert tactic
oliversoeser 2c32779
use Qq for irevert
oliversoeser 8e38f97
irevert tests
oliversoeser abee8fd
explicitly bind x
oliversoeser 8c014f7
fix whitespace anomaly
oliversoeser ce592db
descriptive error message
oliversoeser 302b1f6
Merge branch 'leanprover-community:master' into irevert
oliversoeser 2ad360f
simplify
oliversoeser 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /- | ||
| Copyright (c) 2025 Oliver Soeser. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Oliver Soeser | ||
| -/ | ||
| import Iris.ProofMode.Tactics.Cases | ||
|
|
||
| namespace Iris.ProofMode | ||
| open Lean Elab Tactic Meta Qq BI Std | ||
|
|
||
| theorem wand_revert [BI PROP] {P Q A1 A2 : PROP} | ||
| (h1 : P ⊣⊢ A1 ∗ A2) (h2 : A1 ⊢ A2 -∗ Q) : P ⊢ Q := | ||
| h1.mp.trans (wand_elim h2) | ||
|
|
||
| theorem forall_revert [BI PROP] {P : PROP} {Ψ : α → PROP} | ||
| (h : P ⊢ ∀ x, Ψ x) : ∀ x, P ⊢ Ψ x := | ||
| λ x => h.trans (forall_elim x) | ||
|
|
||
| theorem pure_revert [BI PROP] {P Q : PROP} {φ : Prop} | ||
| (h : P ⊢ ⌜φ⌝ -∗ Q) : φ → P ⊢ Q := | ||
| λ hp => (sep_emp.mpr.trans (sep_mono .rfl (pure_intro hp))).trans (wand_elim h) | ||
|
|
||
| elab "irevert" colGt hyp:ident : tactic => do | ||
| let (mvar, { u, prop, bi, e, hyps, goal, .. }) ← istart (← getMainGoal) | ||
|
|
||
| mvar.withContext do | ||
| let uniq? ← try? do pure (← hyps.findWithInfo hyp) | ||
| if let some uniq := uniq? then | ||
| let ⟨e', hyps', out, _, _, _, h⟩ := hyps.remove true uniq | ||
| let m : Q($e' ⊢ $out -∗ $goal) ← mkFreshExprSyntheticOpaqueMVar <| | ||
| IrisGoal.toExpr { hyps := hyps', goal := q(wand $out $goal), .. } | ||
|
|
||
| mvar.assign q(wand_revert $h $m) | ||
| replaceMainGoal [m.mvarId!] | ||
| else | ||
| let f ← getFVarId hyp | ||
| let some ldecl := (← getLCtx).find? f | throwError "irevert: {hyp.getId} not in scope" | ||
|
|
||
| let bibase : Q(BIBase $prop) := q(@BI.toBIBase $prop $bi) | ||
|
|
||
| let v : Level ← Meta.getLevel ldecl.type | ||
| have α : Q(Sort v) := ldecl.type | ||
|
|
||
| let (_, mvarId) ← mvar.revert #[f] | ||
| mvarId.withContext do | ||
| if ← Meta.isProp α then | ||
| have φ : Q(Prop) := α | ||
| let p : Q($prop) := q(@BI.pure $prop $bibase $φ) | ||
|
|
||
| let m : Q($e ⊢ $p -∗ $goal) ← mkFreshExprSyntheticOpaqueMVar <| | ||
| IrisGoal.toExpr { u, prop, bi, hyps, goal := q(wand $p $goal), .. } | ||
|
|
||
| let pf : Q($φ → ($e ⊢ $goal)) := q(pure_revert $m) | ||
|
|
||
| mvarId.assign pf | ||
| replaceMainGoal [m.mvarId!] | ||
| else | ||
| let Φ : Q($α → $prop) ← mapForallTelescope' (λ t _ => do | ||
| let (some ig) := parseIrisGoal? t | throwError "irevert: not in proof mode" | ||
| return ig.goal | ||
| ) (Expr.mvar mvarId) | ||
| let m : Q($e ⊢ ∀ x, $Φ x) ← mkFreshExprSyntheticOpaqueMVar <| | ||
| IrisGoal.toExpr { u, prop, bi, hyps, goal := q(BI.forall $Φ), ..} | ||
|
|
||
| let pf : Q(∀ (x : $α), $e ⊢ $Φ x) := q(forall_revert $m) | ||
|
|
||
| mvarId.assign pf | ||
| replaceMainGoal [m.mvarId!] | ||
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,7 +1,7 @@ | ||
| /- | ||
| Copyright (c) 2022 Lars König. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Lars König | ||
| Authors: Lars König, Oliver Soeser | ||
| -/ | ||
| import Iris.BI | ||
| import Iris.ProofMode | ||
|
|
@@ -115,6 +115,43 @@ theorem multiple_patterns [BI PROP] (Q : PROP) : ⊢ □ (P1 ∧ P2) -∗ Q ∨ | |
|
|
||
| end intro | ||
|
|
||
| -- revert | ||
| namespace revert | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also be good to have tests for the failing cases:
For the second point: When I try the following test, theorem fail [BI PROP] (Φ : Bool → PROP) : ⊢ ∀ x, <affine> ⌜x = true⌝ -∗ Φ x -∗ Φ x := by
iintro x %_ H
irevert xsomething very weird happens: Goals (1)
PROP : Type u_1
inst : BI PROP
Φ : Bool → PROP
⊢
∗H : Φ _fvar.2200
⊢ «forall» fun x x_1 => Φ x |
||
|
|
||
| theorem spatial [BI PROP] (P Q : PROP) (H : ⊢ P -∗ Q) : P ⊢ Q := by | ||
| iintro HP | ||
| irevert HP | ||
| exact H | ||
|
|
||
| theorem intuitionistic [BI PROP] (P : PROP) (H : ⊢ □ P -∗ P) : □ P ⊢ P := by | ||
| iintro □HP | ||
| irevert HP | ||
| exact H | ||
|
|
||
| theorem pure [BI PROP] (P : PROP) (Hφ : φ) : ⊢ (⌜φ⌝ -∗ P) -∗ P := by | ||
| iintro H | ||
| irevert Hφ | ||
| iexact H | ||
|
|
||
| theorem «forall» [BI PROP] (x : α) (Φ : α → PROP) : ⊢ (∀ x, Φ x) → Φ x := by | ||
| iintro H | ||
| irevert x | ||
| iexact H | ||
|
|
||
| theorem multiple_spatial [BI PROP] (P Q : PROP) : | ||
| ⊢ (P -∗ P) -∗ P -∗ <affine> Q -∗ P := by | ||
| iintro H HP HQ | ||
| irevert HP | ||
| iexact H | ||
|
|
||
| theorem multiple_intuitionistic [BI PROP] (P Q : PROP) : | ||
| ⊢ (□ P -∗ P) -∗ □ P -∗ <affine> Q -∗ P := by | ||
| iintro H □HP HQ | ||
| irevert HP | ||
| iexact H | ||
|
|
||
| end revert | ||
|
|
||
| -- exists | ||
| namespace «exists» | ||
|
|
||
|
|
||
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
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.
This should use the
MakeAffinely ⌜ φ ⌝ Pto add the<affine>modality in front of⌜ φ ⌝for logics that require it. Otherwise,irevertcan make the goal unprovable. Seehttps://gitlab.mpi-sws.org/iris/iris/-/blob/306d8d024f9d6522c0e733fd7eb27b0af676d4ca/iris/proofmode/coq_tactics.v