-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add weakest precondition #393
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
Merged
Kaptch
merged 79 commits into
leanprover-community:master
from
ayhon:fele/feat/add-weakestpre
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
ff8a1e4
refactor: make SelTarget type an distinct inductive type
ayhon 8c8b59f
refactor: expose `irevert` as a metaprogramming API
ayhon e562c0b
refactor: expose `iintro` as a metaprogramming API
ayhon 7374db7
refactor: expose `iapply` as a metaprogramming API
ayhon 67986f9
feat: add `getDecl?` and `getUsername?` functions for `Hyps`
ayhon 4b5bb60
feat: preliminary `iloeb` tactic implementation
ayhon 65333f5
docs: extend `ihave` docstring on returned `hyps`
ayhon 58da6e3
feat: add iloeb to the tactic prelude
ayhon 018214c
doc: add copyright header comment in iloeb
ayhon 0b22f6a
fix: imports and dangling reference
ayhon 5cb6168
refactor: move `ProofModeM` methods to `ProofModeM.lean`
ayhon e6622e1
feat: add tests
ayhon d8e847e
chore: add TODO justification for opinionated change
ayhon c875bdc
fix: `uniq` is now `ivar`
ayhon 5657c05
refactor: have `iRevertCore` accept a continuation
ayhon ba34106
refactor: have `iIntroCore` accept a continuation
ayhon 8913e35
fix: remove `ProofModeTactic` definition
ayhon 9b9f425
fix: uniq is now ivar
ayhon 1672ec6
feat: simplify `iloeb` using continuations
ayhon b836417
test: warning when generalizing over spatial hypothesis
ayhon 2574cee
docs: add `Hyps` docstring explaining hidden invariants
ayhon d2a7782
fixup! refactor: make SelTarget type an distinct inductive type
ayhon ed9a85c
review: specialize assumption lemma for `iapply`
ayhon e9a9297
review: rename `SelId` constructors (`pm`→`ipm`, `lean`→`pure`)
ayhon 8a70f42
review: BI instance doesn't change between tactics
ayhon b561b94
fixup! review: rename `SelId` constructors (`pm`→`ipm`, `lean`→`pure`)
ayhon 7e6e543
fixup! review: BI instance doesn't always change between tactics
ayhon c7c09ac
review: add persistence information in `SelTarget`
ayhon 4b69bd6
review: remove stale definitions
ayhon 02f35ed
review: add negative test when no BILoeb instance is available using …
ayhon 678a03c
refactor: push `persistent?` in `SelTarget` inside `ìpm`
ayhon a55e95f
fix: warnings
ayhon 1638a59
feat: add WeakestPre notation
ayhon 6f4e724
wip
ayhon 04858f5
feat: preliminary Texan triple syntax
ayhon 393e4bf
fix: move WeakestPre BI definitions under the Iris namespace
ayhon 3f23865
refactor: small opinionated improvements
ayhon 3a2c745
refactor: qol improvements, use `iframe` and `iloeb` in some proofs
ayhon 80a3dbe
feat: add stuckness_to_atomicity
ayhon 49230dc
feat: wp_atomic
ayhon 727abd0
feat: wp_credit_access
ayhon c2c2662
fix: IProp is Leibnitz!
ayhon 5f406b0
fix: non-terminal simps only
ayhon 72c3df2
feat: wp_step_fupdN_strong
ayhon fa016f4
feat: wp_bind
ayhon cd7697d
feat: wp_bind_inv
ayhon 324c252
feat: wp_mono
ayhon 9f0a63e
fix: simplify proofs, using UPred being Leibnitz
ayhon c1433aa
feat: wp_value
ayhon e1f8c77
feat: wp_frame_{l,r}
ayhon be16c9a
feat: wp_step_fupdN
ayhon b4745d7
feat: wp_frame_step_{l,r}
ayhon c76b3bf
feat: wp_wand
ayhon e7efdcf
fix: add Stuckness order theorems
ayhon 8f790c7
feat: add proof mode classes
ayhon b6eee98
refactor: rename `wp_expr` to `wpExpr`
ayhon 000565d
feat: add copyright header
ayhon 17d9196
Merge branch 'master' into fele/feat/add-weakestpre
ayhon d977403
fix: remove infos
ayhon 415d091
chore: clean up file
ayhon 6fb81d3
pass over BI
Kaptch b6ac945
refactor: commute addition so it plays nicer with defeq
ayhon 0d918de
fix: remove left over code from merge
ayhon 3bbfe06
smaller tokens for wp
Kaptch 15b1a20
feat: add `rocq_alias`
ayhon ca7d84c
pass over program logic
Kaptch 0a8e646
Merge remote-tracking branch 'upstream/master' into pr/ayhon/393
Kaptch f059f0b
chore: cleanup updates
markusdemedeiros 8a76076
minor: wp line length
markusdemedeiros f10221a
chore: cleanup in WeakestPre
markusdemedeiros 357244e
Merge branch 'master' into fele/feat/add-weakestpre
ayhon 22fe3e6
fix delab bug, minor nits
Kaptch f54a7c6
todo icombine
Kaptch bddadc5
fix: allow `State` to not be `semiOutParam`
ayhon 6df094f
fix: remove redundant implicit_reducible
ayhon 92bb4bf
porting
Kaptch cea10ed
add test for irevert change
MackieLoeffel 3a8adb1
add missing line
MackieLoeffel a2875b7
rm missed file
Kaptch 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 |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| module | ||
|
|
||
| public import Iris.Std.CoPset | ||
| public import Iris.BI | ||
| public meta import Iris.BI | ||
| public import Iris.BI.BIBase | ||
| public meta import Iris.Std.Rewrite | ||
| public import Std | ||
| meta import Lean | ||
| public import Lean | ||
|
|
||
| public import Iris.BI.BI | ||
| public import Iris.BI.Classes | ||
| public import Iris.BI.DerivedLaws | ||
| public import Iris.BI.DerivedLawsLater | ||
| public import Iris.BI.Extensions | ||
| public import Iris.BI.SIProp | ||
| public meta import Iris.Std.RocqPorting | ||
|
|
||
| public section | ||
|
|
||
| namespace Iris | ||
|
|
||
| open Lean | ||
|
|
||
| inductive Stuckness where | ||
| | NotStuck | ||
| | MaybeStuck | ||
|
|
||
| namespace Stuckness | ||
|
|
||
| @[simp] | ||
| instance instLE: LE Stuckness where | ||
| le x y := ¬ (x = .MaybeStuck ∧ y = .NotStuck) | ||
|
|
||
| instance : Std.IsPreorder Stuckness where | ||
| le_refl := by grind only [Stuckness, LE.le, instLE] | ||
| le_trans := by grind only [Stuckness, LE.le, instLE] | ||
|
|
||
| @[simp] theorem le_MaybeStuck {s : Stuckness} : s ≤ MaybeStuck := by | ||
| cases s <;> grind only [Stuckness, LE.le, instLE] | ||
|
|
||
| @[simp] theorem NotSuck_le {s : Stuckness} : NotStuck ≤ s := by | ||
| cases s <;> grind only [Stuckness, LE.le, instLE] | ||
|
|
||
| end Stuckness | ||
|
|
||
| class Wp (PROP Expr : Type _) (Val : outParam (Type _)) (A : Type _) where | ||
| wp : A → CoPset → Expr → (Val → PROP) → PROP | ||
|
|
||
| class TotalWP (PROP Expr) (Val : outParam (Type _)) (A : Type _) where | ||
| totalWp : A → CoPset → Expr → (Val → PROP) → PROP | ||
|
|
||
| syntax wpExpr := | ||
| term:max (" @ " term:max (" ; " term:max) <|> ((" ? ")? )) <|> (" ? ")? | ||
|
|
||
| declare_syntax_cat wpPostcondInner | ||
| syntax ident ", " term : wpPostcondInner | ||
| syntax term : wpPostcondInner | ||
|
|
||
| declare_syntax_cat wpPostcond | ||
| -- Avoids conflicts with | ||
| -- example {a : PUnit.{i}} : PUnit.{i} := a | ||
| -- ^^ | ||
| -- see: https://github.com/leanprover-community/iris-lean/pull/393 | ||
| syntax " {" "{ " wpPostcondInner " }" "} " : wpPostcond | ||
| syntax " [" "{ " wpPostcondInner " }" "] " : wpPostcond | ||
| syntax " ⦃ " wpPostcondInner " ⦄ " : wpPostcond | ||
| syntax " 〖 " wpPostcondInner " 〗 " : wpPostcond | ||
|
|
||
| syntax (name := wp) "WP " wpExpr wpPostcond : term | ||
|
|
||
| open Lean in | ||
| meta def parseWpExpr : Lean.TSyntax ``wpExpr → Lean.MacroM (TSyntax `term × TSyntax `term × TSyntax `term) := fun | ||
| | `(wpExpr| $e @ $s ; $E) => | ||
| return (e, s, E) | ||
| | `(wpExpr| $e @ $E) => | ||
| return (e, ←`(Stuckness.NotStuck), E) | ||
| | `(wpExpr| $e @ $E ?) => | ||
| return (e, ←`(Stuckness.MaybeStuck), E) | ||
| | `(wpExpr| $e:term) => | ||
| return (e, ←`(Stuckness.NotStuck), ←`(⊤)) | ||
| | `(wpExpr| $e:term ?) => | ||
| return (e, ←`(Stuckness.MaybeStuck), ←`(⊤)) | ||
| | _ => Lean.Macro.throwUnsupported | ||
|
|
||
| open Lean in | ||
| meta def parseWpPostcondInner (stx : TSyntax `wpPostcondInner) : MacroM (TSyntax `term) := do | ||
| match stx with | ||
| | `(wpPostcondInner| $v:ident, $Φ:term) => `(fun $v => iprop($Φ)) | ||
| | `(wpPostcondInner| $Φ:term) => return iprop(Φ) | ||
| | _ => Macro.throwUnsupported | ||
|
|
||
| open Lean in | ||
| meta def parseWpPostcond (stx : TSyntax `wpPostcond) : MacroM (TSyntax `term × Bool) := do | ||
| match stx with | ||
| | `(wpPostcond| {{ $inner:wpPostcondInner }}) | ||
| | `(wpPostcond| ⦃ $inner:wpPostcondInner ⦄) => | ||
| return (←parseWpPostcondInner inner, false) | ||
| | `(wpPostcond| [{ $inner:wpPostcondInner }]) | ||
| | `(wpPostcond| 〖 $inner:wpPostcondInner 〗) => | ||
| return (←parseWpPostcondInner inner, true) | ||
| | _ => Macro.throwUnsupported (α := TSyntax `term × Bool) | ||
|
|
||
| @[macro wp] | ||
| meta def wpMacro : Lean.Macro := fun stx => do | ||
| match stx with | ||
| | `(WP $expr $postcond) => | ||
| let (e, s, E) ← parseWpExpr expr | ||
| let (Φ, useTotal?) ← parseWpPostcond postcond | ||
| if useTotal? then | ||
| `(TotalWP.totalWp $s $E $e $Φ) | ||
| else | ||
| `(Wp.wp $s $E $e $Φ) | ||
| | _ => Lean.Macro.throwUnsupported | ||
|
|
||
| meta def unexpandWpPostcondInner : TSyntax `term → PrettyPrinter.UnexpandM (TSyntax `wpPostcondInner) | ||
| | `(fun $v:ident => iprop($Φ:term)) => `(wpPostcondInner|$v:ident, $Φ:term) | ||
| | `(iprop($Φ:term)) => `(wpPostcondInner| $Φ:term) | ||
| | `(fun $v:ident => $Φ:term) => `(wpPostcondInner|$v:ident, $Φ:term) | ||
| | `($Φ:term) => `(wpPostcondInner| $Φ:term) | ||
|
|
||
| open Lean in | ||
| meta def makeWpExpr (s E e : TSyntax `term) : PrettyPrinter.UnexpandM (TSyntax ``wpExpr) := do | ||
| match s, E with | ||
| | `(Stuckness.NotStuck), `(⊤) => `(wpExpr| $e:term) | ||
| | `(Stuckness.NotStuck), E => `(wpExpr| $e:term @ $E:term) | ||
| | `(Stuckness.MaybeStuck), `(⊤) => `(wpExpr| $e:term ?) | ||
| | `(Stuckness.MaybeStuck), E => `(wpExpr| $e:term @ $E:term ?) | ||
| | s, E => `(wpExpr| $e:term @ $s:term ; $E:term) | ||
|
|
||
| @[app_unexpander Wp.wp] | ||
| meta def unexpanderWp : PrettyPrinter.Unexpander | ||
| | `($_wp $s $E $e $Φ) => do | ||
| let wpExpr ← makeWpExpr s E e | ||
| let wpPostcondInner ← unexpandWpPostcondInner Φ | ||
| `(WP $wpExpr {{ $wpPostcondInner }}) | ||
| | _ => throw () | ||
|
|
||
| @[app_unexpander TotalWP.totalWp] | ||
| meta def unexpanderTotalWp : PrettyPrinter.Unexpander | ||
| | `($_wp $s $E $e $Φ) => do | ||
| let wpExpr ← makeWpExpr s E e | ||
| let wpPostcondInner ← unexpandWpPostcondInner Φ | ||
| `(WP $wpExpr [{ $wpPostcondInner }]) | ||
| | _ => throw () | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.