-
Notifications
You must be signed in to change notification settings - Fork 55
feat: port bi/lib/counterexamples.v (+ fix IntoWand instances)
#540
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
alvinylt
wants to merge
24
commits into
leanprover-community:master
Choose a base branch
from
ISTA-PLV:Counterexamples
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.
+625
−10
Open
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
572fe29
Start porting `bi/lib/counterexamples.v`
alvinylt 101d1e8
Port `LoebEM` section, `IntoWand` bug found (to be fixed)
alvinylt fc7567f
Towards fixing the `IntoWand` instances, some proofs not done yet
alvinylt 898fff7
Port `persistent_impl_wand_affinely`
alvinylt 5eb2fe9
Proof simplification
alvinylt 33ef431
Rename `impl_wand` as `impl_wand_1` for consistency, towards proving …
alvinylt c82d239
Finish proof for `intoWand_impl_true_false` and `intoWand_impl_false_…
alvinylt e80dc73
Bug fix
alvinylt 8c49e24
Merge remote-tracking branch 'upstream/master' into Counterexamples
alvinylt 30d87d8
Port `SavedProp` section
alvinylt e42cf20
Minor formatting
alvinylt 53aab58
Port `Linear` section
alvinylt 7c9e7b3
Minor formatting
alvinylt b9287ac
Port `LaterCreditsPlain` section
alvinylt d5255e9
Port `Inv` section, excluding `Inv1` and `Inv2`
alvinylt 189bc07
Port section `Inv1`
alvinylt 25fb29d
Fix `rocq_alias` annotations
alvinylt 9feb2b1
Port section `Inv2`
alvinylt b670238
Merge remote-tracking branch 'upstream/master' into Counterexamples
alvinylt 4ad8d13
Remove stale `rocq_alias` entry
alvinylt 0d4eada
Code style improvements and formatting
alvinylt 3e8f730
Simplify imports
alvinylt 57a563c
Merge remote-tracking branch 'upstream/master' into Counterexamples
alvinylt d043ed3
Update `BI/Lib.lean`
alvinylt 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,264 @@ | ||
| /- | ||
| Copyright (c) 2026 Alvin Tang. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Alvin Tang | ||
| -/ | ||
| module | ||
|
|
||
| public import Iris.BI | ||
| public import Iris.BI.Extensions | ||
| public import Iris.BI.Sbi | ||
| public import Iris.ProofMode | ||
| public import Iris.ProofMode.Classes | ||
| public meta import Iris.Std.RocqPorting | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Iris | ||
|
|
||
| open Iris.Std BI ProofMode | ||
|
|
||
| namespace AffineEM | ||
|
|
||
| variable {PROP : Type _} [BI PROP] | ||
| variable (em : ∀ P : PROP, ⊢ P ∨ ¬P) | ||
| variable (P Q : PROP) | ||
| include em | ||
|
|
||
| @[rocq_alias affine_em.sep_dup] | ||
| theorem sep_dup [Affine P] : P ⊢ P ∗ P := by | ||
| iintro HP | ||
| icases (em P) with (HP' | HnotP) | ||
| · iframe HP HP' | ||
| · iexfalso | ||
| iapply HnotP $$ HP | ||
|
|
||
| @[rocq_alias affine_em.and_sep] | ||
| theorem and_sep [BIAffine PROP] : P ∧ Q ⊢ P ∗ Q := by | ||
| iintro HPQ | ||
| icases sep_dup $$ HPQ with ⟨HPQ, HPQ'⟩ | ||
| · assumption | ||
| · isplitl [HPQ] | ||
| · icases HPQ with ⟨HP, -⟩ | ||
| iassumption | ||
| · icases HPQ' with ⟨-, HQ⟩ | ||
| iassumption | ||
|
|
||
| end AffineEM | ||
|
|
||
| namespace LoebEM | ||
|
|
||
| @[rocq_alias löb_em.later_anything] | ||
| theorem later_anything [BI PROP] (em : ∀ P : PROP, ⊢ P ∨ ¬P) [BILoeb PROP] : | ||
| ⊢@{PROP} ▷ P := by | ||
| icases (em iprop(▷ False)) with #(HP | HnotP) | ||
| · inext | ||
| iexfalso | ||
| iassumption | ||
| · iexfalso | ||
| iloeb as IH | ||
| ispecialize HnotP $$ IH | ||
| iassumption | ||
|
|
||
| @[rocq_alias löb_em.later_inconsistent] | ||
| theorem later_inconsistent [Sbi PROP] (em : ∀ P : PROP, ⊢ P ∨ ¬P) : ⊢@{PROP} False := by | ||
| apply later_soundness (PROP := PROP) (P := iprop(False)) | ||
| apply later_anything | ||
| assumption | ||
|
|
||
| end LoebEM | ||
|
|
||
| namespace SavedProp | ||
|
|
||
| variable [BI PROP] [instAffine : BIAffine PROP] {P Q : PROP} | ||
| variable (bupd : PROP → PROP) | ||
| variable (ident : Type _) (saved : ident → PROP → PROP) | ||
| variable [instPers : ∀ (i : ident) (P : PROP), Persistent (saved i P)] | ||
|
|
||
| variable (bupd_intro : ∀ {P : PROP}, P ⊢ bupd P) | ||
| variable (bupd_mono : ∀ {P Q : PROP}, (P ⊢ Q) → bupd P ⊢ bupd Q) | ||
| variable (bupd_trans : ∀ {P : PROP}, bupd (bupd P) ⊢ bupd P) | ||
| variable (bupd_frame_right : ∀ {P R : PROP}, bupd P ∗ R ⊢ bupd iprop(P ∗ R)) | ||
| variable (sprop_alloc_dep : ∀ {P : ident → PROP}, ⊢ bupd (∃ i, saved i (P i))) | ||
| variable (sprop_agree : ∀ (i : ident) (P Q : PROP), saved i P ∧ saved i Q ⊢ □ (P ↔ Q)) | ||
| variable (consistency : ¬(⊢ bupd iprop(False))) | ||
|
|
||
| include bupd_mono in | ||
| omit instAffine in | ||
| @[rw_mono_rule, rocq_alias savedprop.bupd_mono'] | ||
| theorem bupd_mono' (h : P ⊢ Q) : bupd P ⊢ bupd Q := bupd_mono h | ||
|
|
||
| include bupd_frame_right bupd_trans bupd_mono in | ||
| omit instAffine in | ||
| @[rocq_alias savedprop.elim_modal_bupd] | ||
| theorem elim_modal_bupd (p : Bool) : ElimModal True p io false (bupd P) P (bupd Q) (bupd Q) where | ||
| elim_modal _ := calc | ||
| _ ⊢ bupd P ∗ (P -∗ bupd Q) := sep_mono_left intuitionisticallyIf_elim | ||
| _ ⊢ bupd iprop(P ∗ (P -∗ bupd Q)) := bupd_frame_right | ||
| _ ⊢ bupd (bupd Q) := bupd_mono wand_elim_right | ||
| _ ⊢ bupd Q := bupd_trans | ||
|
|
||
| @[reducible, rocq_alias savedprop.A] | ||
| def A (i : ident) : PROP := iprop(∃ P, □ (¬P ∗ saved i P)) | ||
|
|
||
| include sprop_alloc_dep in | ||
| omit instAffine instPers in | ||
| @[rocq_alias savedprop.A_alloc] | ||
| theorem A_alloc : ⊢ bupd (∃ i, saved i (A ident saved i)) := sprop_alloc_dep | ||
|
|
||
| include sprop_agree in | ||
| @[rocq_alias savedprop.saved_NA] | ||
| theorem saved_NA (i : ident) : saved i (A ident saved i) ⊢ ¬A ident saved i := by | ||
| iintro #Hs #HA | ||
| ihave ⟨%P, HNP, HsP⟩ := HA | ||
| iapply HNP | ||
| icases sprop_agree i P (A ident saved i) $$ [] with #⟨_, HP⟩ | ||
| · isplit <;> iassumption | ||
| · iapply HP; iassumption | ||
|
|
||
| include sprop_agree in | ||
| @[rocq_alias savedprop.saved_A] | ||
| theorem saved_A (i : ident) : saved i (A ident saved i) ⊢ A ident saved i := by | ||
| iintro #Hs | ||
| iexists A ident saved i | ||
| iframe Hs | ||
| iintro !> | ||
| iapply saved_NA | ||
| · exact sprop_agree | ||
| · iassumption | ||
|
|
||
| include consistency bupd_frame_right bupd_intro bupd_trans bupd_mono sprop_alloc_dep sprop_agree in | ||
| @[rocq_alias savedprop.contradiction] | ||
| theorem contradiction : False := by | ||
| haveI {p : Bool} {P Q : PROP} : ElimModal True p .out false (bupd P) P (bupd Q) (bupd Q) := | ||
| elim_modal_bupd (io := .out) bupd bupd_mono bupd_trans bupd_frame_right p | ||
| apply consistency | ||
| imod A_alloc bupd ident saved sprop_alloc_dep with ⟨%i, #H⟩ | ||
| iapply bupd_intro | ||
| iapply saved_NA _ $$ H | ||
| · exact sprop_agree | ||
| · iapply saved_A | ||
| · exact sprop_agree | ||
| · iassumption | ||
|
|
||
| end SavedProp | ||
|
|
||
| namespace Linear | ||
|
|
||
| @[rocq_alias linear.mask] | ||
| inductive Mask where | M0 | M1 deriving DecidableEq, Inhabited | ||
|
|
||
| variable {PROP : Type _} [BI PROP] | ||
| variable {P Q : PROP} | ||
| variable (fupd : Mask → Mask → PROP → PROP) | ||
| variable (gname : Type _) (cinv : gname → PROP → PROP) (cinv_own : gname → PROP) | ||
|
|
||
| variable (fupd_intro : ∀ {E : Mask} {P : PROP}, P ⊢ fupd E E P) | ||
| variable (fupd_mono : ∀ {E1 E2 : Mask} {P Q : PROP}, (P ⊢ Q) → fupd E1 E2 P ⊢ fupd E1 E2 Q) | ||
| variable (fupd_fupd : | ||
| ∀ {E1 E2 E3 : Mask} {P : PROP}, fupd E1 E2 (fupd E2 E3 P) ⊢ fupd E1 E3 P) | ||
| variable (fupd_frame_left : | ||
| ∀ {E1 E2 : Mask} {P Q : PROP}, P ∗ fupd E1 E2 Q ⊢ fupd E1 E2 iprop(P ∗ Q)) | ||
| variable (cinv_alloc : ∀ {E : Mask} (P : PROP), ▷ P ⊢ fupd E E iprop(∃ γ, cinv γ P ∗ cinv_own γ)) | ||
| variable (cinv_acc : | ||
| ∀ (P : PROP) (γ : gname), cinv γ P -∗ cinv_own γ -∗ | ||
| fupd M1 M0 iprop(▷ P ∗ cinv_own γ ∗ (▷ P -∗ fupd M0 M1 (emp : PROP)))) | ||
|
|
||
| include fupd_mono in | ||
| @[rw_mono_rule, rocq_alias linear.fupd_mono'] | ||
| theorem fupd_mono' {E1 E2 : Mask} (h : P ⊢ Q) : fupd E1 E2 P ⊢ fupd E1 E2 Q := fupd_mono h | ||
|
|
||
| include fupd_mono in | ||
| @[rocq_alias linear.fupd_proper] | ||
| theorem fupd_proper {E1 E2 : Mask} (h : P ⊣⊢ Q) : fupd E1 E2 P ⊣⊢ fupd E1 E2 Q := by | ||
| constructor | ||
| · apply fupd_mono h.mp | ||
| · apply fupd_mono h.mpr | ||
|
|
||
| include fupd_frame_left fupd_mono in | ||
| @[rocq_alias linear.fupd_frame_r] | ||
| theorem fupd_frame_right {E1 E2 : Mask} : fupd E1 E2 P ∗ Q ⊢ fupd E1 E2 iprop(P ∗ Q) := | ||
| sep_comm.mp.trans <| fupd_frame_left.trans <| fupd_mono sep_comm.mp | ||
|
|
||
| include fupd_frame_left fupd_mono fupd_fupd in | ||
| @[rocq_alias linear.elim_fupd_fupd] | ||
| theorem elim_fupd_fupd {p : Bool} {E1 E2 E3 : Mask} : | ||
| ElimModal True p io false (fupd E1 E2 P) P (fupd E1 E3 Q) (fupd E2 E3 Q) where | ||
| elim_modal _ := calc | ||
| _ ⊢ fupd E1 E2 P ∗ (P -∗ fupd E2 E3 Q) := sep_mono_left intuitionisticallyIf_elim | ||
| _ ⊢ fupd E1 E2 iprop(P ∗ (P -∗ fupd E2 E3 Q)) := fupd_frame_right fupd fupd_mono fupd_frame_left | ||
| _ ⊢ fupd E1 E2 (fupd E2 E3 Q) := fupd_mono wand_elim_right | ||
| _ ⊢ fupd E1 E3 Q := fupd_fupd | ||
|
|
||
| include cinv_alloc cinv_acc fupd_mono fupd_fupd fupd_frame_left in | ||
| @[rocq_alias linear.leak] | ||
| theorem leak : P ⊢ fupd M1 M1 (emp : PROP) := by | ||
| haveI {p : Bool} {E1 E2 E3 : Mask} {P Q : PROP} : | ||
| ElimModal True p .out false (fupd E1 E2 P) P (fupd E1 E3 Q) (fupd E2 E3 Q) := | ||
| elim_fupd_fupd (io := .out) fupd fupd_mono fupd_fupd fupd_frame_left | ||
| iintro HP | ||
| imod cinv_alloc iprop(True) $$ [//] with ⟨%γ, Hinv, Htok⟩ | ||
| imod cinv_acc $$ Hinv Htok with ⟨Htrue, Htok, Hclose⟩ | ||
| iapply Hclose | ||
| iassumption | ||
|
|
||
| end Linear | ||
|
|
||
| namespace LaterCreditsPlain | ||
|
|
||
| variable [instSbi : Sbi PROP] [instBFupd : BIFUpdate PROP] | ||
| variable {lc : PROP} | ||
|
|
||
| variable (lc_fupd_elim_later : ∀ E P, lc ∗ ▷ P ⊢ |={E}=> P) | ||
| variable (lc_soundness : ∀ P [Plain P] E, (lc ⊢ |={E}=> P) → ⊢ P) | ||
|
|
||
| variable (fupd_keep_si_pure' : ∀ {E : CoPset} (E' : CoPset) (Pi : SiProp) (R : PROP), | ||
| (|={E,E'}=> <si_pure> Pi) ∧ (<si_pure> Pi ={E}=∗ R) ⊢ |={E}=> R) | ||
|
|
||
| include lc_fupd_elim_later fupd_keep_si_pure' in | ||
| @[rocq_alias later_credits_plain.lc_fupd_elim_later_keep] | ||
| theorem lc_fupd_elim_later_keep {E : CoPset} {P : PROP} [inst1 : Plain P] [inst2 : Absorbing P] : | ||
| ⊢ lc -∗ ▷ P ={E}=∗ lc ∗ P := by | ||
| iintro Hlc HP | ||
| iapply (fupd_keep_si_pure' E iprop(<si_emp_valid> P)) | ||
| isplit | ||
| · iapply lc_fupd_elim_later | ||
| iframe Hlc | ||
| inext | ||
| exact Plain.plain | ||
| · iintro HP' !> | ||
| iframe Hlc | ||
| iclear HP | ||
| apply siPure_siEmpValid_elim | ||
|
|
||
| omit instBFupd in | ||
| @[rocq_alias later_credits_plain.laterN_False] | ||
| theorem laterN_False [BILoeb PROP] : ⊢@{PROP} ∃ n, ▷^[n] False := by | ||
| iloeb as IH | ||
| icases IH with ⟨%n, Hn⟩ | ||
| iexists n + 1 | ||
| dsimp [BIBase.laterN, Nat.repeat] | ||
| iassumption | ||
|
|
||
| include lc_fupd_elim_later lc_soundness fupd_keep_si_pure' in | ||
| @[rocq_alias later_credits_plain.contradiction] | ||
| theorem contradiction [BILoeb PROP] : False := by | ||
| apply pure_soundness (PROP := PROP) | ||
| apply lc_soundness _ ⊤ | ||
| iintro Hlc | ||
| icases laterN_False with ⟨%n, ∗Hfalse⟩ | ||
| icases affinely_elim $$ Hfalse with Hfalse | ||
| iinduction n with | ||
| | zero => | ||
| dsimp [BIBase.laterN, Nat.repeat] | ||
| iexfalso; iexact Hfalse | ||
| | succ n IH => | ||
| ihave Hfalse := Hfalse | ||
| /- Necessary to unfold `▷^[n + 1]` as `▷ ▷^[n]`, or else we get | ||
| `∗Hfalse : ▷^[n + 1] False` after `imod`. -/ | ||
| icases (later_laterN n).mp $$ Hfalse with Hfalse | ||
| imod lc_fupd_elim_later_keep | ||
| lc_fupd_elim_later fupd_keep_si_pure' $$ Hlc Hfalse with ⟨Hlc, Hfalse⟩ | ||
| iapply IH $$ Hlc Hfalse | ||
|
|
||
| end LaterCreditsPlain | ||
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
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.
We have to unfold
laterNmanually in order forimodto produce the correct hypothesis.Might be interesting to investigate the cause.