Skip to content

feat: add weakest precondition#393

Merged
Kaptch merged 79 commits into
leanprover-community:masterfrom
ayhon:fele/feat/add-weakestpre
May 21, 2026
Merged

feat: add weakest precondition#393
Kaptch merged 79 commits into
leanprover-community:masterfrom
ayhon:fele/feat/add-weakestpre

Conversation

@ayhon
Copy link
Copy Markdown
Contributor

@ayhon ayhon commented May 13, 2026

Description

Porting of the weakest precondition definitions (program_logic/weakestpre.v) and notation (bi/weakestpre.v).

Implements #253.

Checklist

  • My code follows the mathlib naming and code style conventions
  • I have updated PORTING.md as appropriate
  • I have added my name to the authors section of any appropriate files

@ayhon ayhon changed the title Fele/feat/add weakestpre feat: add weakest precondition May 13, 2026
@markusdemedeiros
Copy link
Copy Markdown
Collaborator

A general comment: please do not state theorems as functions unless you have a good reason to. It's better to give names to all hypotheses so it is easier to cleanup later (implicits, named arguments, etc.)

@markusdemedeiros
Copy link
Copy Markdown
Collaborator

Also: no universe names unless you have a really good reason. Type _ avoids the issue where you reuse a letter and put in a hard to track down universe constraint.

Comment thread Iris/Iris/ProgramLogic/WeakestPre.lean Outdated
Comment thread Iris/Iris/ProgramLogic/WeakestPre.lean
@markusdemedeiros
Copy link
Copy Markdown
Collaborator

Awesome, this will be great to have in. I looked over the BI code and it looks good enough to me.

@ayhon ayhon marked this pull request as ready for review May 20, 2026 20:47
Copy link
Copy Markdown
Collaborator

@MackieLoeffel MackieLoeffel left a comment

Choose a reason for hiding this comment

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

This PR looks really great! I had some minor thoughts when looking over it (but none of this should be blocking merging this. (I hope that I will have time to look into the printing problem with iloeb at some point, but not sure when that will exactly be.)

Comment thread Iris/Iris/ProgramLogic/WeakestPre.lean Outdated
Comment thread Iris/Iris/ProgramLogic/WeakestPre.lean Outdated
Comment thread Iris/Iris/Std/GenSets.lean
@Kaptch
Copy link
Copy Markdown
Collaborator

Kaptch commented May 21, 2026

This PR looks really great! I had some minor thoughts when looking over it (but none of this should be blocking merging this. (I hope that I will have time to look into the printing problem with iloeb at some point, but not sure when that will exactly be.)

Hi Michael, thanks for the tip with icases <-, H>, that's exactly what I wanted!

Please take a look at https://github.com/leanprover-community/iris-lean/pull/393/changes#diff-6e68887200b797a6df93c0284434bf155c23f7c61bea9d8f8452950382bfb2fcR72
I think the problem was that irevert was keeping originally implicit binders as implicit, which breaks delaboration for forall. I forced it to be explicit here, but I'm not sure if it's a good solution (alternatively, delab for forall can be extended, but having implicit binders for IPM forall seems a bit odd to me). If you think it's not a good solution, I will revert, and the PR can be merged as it is.

lihaokun added a commit to lihaokun/iris-lean that referenced this pull request May 21, 2026
…kestpre interface

Lean 4 port of `iris/program_logic/adequacy.v`, adapted to the
`IrisGS_gen` / `wp.pre` / `WP _ @ s ; E {{ Φ }}` interface from PR leanprover-community#393.

Proven in this branch (5 lemmas + 2 theorems):
- `wp_step`, `wptp_step`, `wp_not_stuck`
- `wptp_preservation` (refl case)
- `adequate_alt`, `adequate_tp_safe`

Remaining sorries:
- `wptp_preservation` cons (skeleton + ~40 lines of working IPM; blocked
  at `imod Hbody` — goal is step_fupdN, not fupd outermost)
- `wptp_postconditions`, `wptp_progress` (plain sorry, follow same pattern
  as `wptp_preservation`)
- `wp_progress_gen`, `wp_strong_adequacy_gen`, `wp_adequacy_gen`,
  `wp_invariance_gen` (4 meta-level theorems with `_hwp : True` placeholders;
  unblocked once `InvGpreS`-style existential is finalized)

Helper `step_fupdN_compose` proves `(|=...=>^[a] P) ⊢ (P -∗ |=...=>^[b] Q) -∗
|=...=>^[a+b] Q` (`step_fupdN_wand` + `Nat.repeat_add`).
lihaokun added a commit to lihaokun/iris-lean that referenced this pull request May 21, 2026
…kestpre interface

Lean 4 port of `iris/program_logic/adequacy.v`, adapted to the
`IrisGS_gen` / `wp.pre` / `WP _ @ s ; E {{ Φ }}` interface from PR leanprover-community#393.

Proven in this branch (5 lemmas + 2 theorems):
- `wp_step`, `wptp_step`, `wp_not_stuck`
- `wptp_preservation` (refl case)
- `adequate_alt`, `adequate_tp_safe`

Remaining sorries:
- `wptp_preservation` cons (skeleton + ~40 lines of working IPM; blocked
  at `imod Hbody` — goal is step_fupdN, not fupd outermost)
- `wptp_postconditions`, `wptp_progress` (plain sorry, follow same pattern
  as `wptp_preservation`)
- `wp_progress_gen`, `wp_strong_adequacy_gen`, `wp_adequacy_gen`,
  `wp_invariance_gen` (4 meta-level theorems with `_hwp : True` placeholders;
  unblocked once `InvGpreS`-style existential is finalized)

Helper `step_fupdN_compose` proves `(|=...=>^[a] P) ⊢ (P -∗ |=...=>^[b] Q) -∗
|=...=>^[a+b] Q` (`step_fupdN_wand` + `Nat.repeat_add`).
lihaokun added a commit to lihaokun/iris-lean that referenced this pull request May 21, 2026
`wp_invariance_gen`: full structural proof using `adequate_alt` +
`wp_strong_adequacy_gen` (oracle) + `erasedStep_nSteps` + per-element
bigSepL2 handling. Internal sorry at the `bridge` step: our Lean
signature has `iG.stateInterp σ2 0 [] (t2.length - 1)` with literal
`ns = 0`, while `wp_strong_adequacy_gen` yields `ns = n` from the
NSteps count. Coq absorbs this via `(λ σ _ _ _, stateI σ)` in the user-
constructed `irisGS_gen`; the Lean PR leanprover-community#393 interface receives iG
externally, so the `ns` parameter is literal `0` in the user signature.
`stateInterp_mono` only goes `ns → ns+1` (not downward), so we cannot
bridge `n → 0`.

Fix path: change wp_invariance_gen's `_Hwp` signature to take a
`stateI : State → IProp GF` (without ns/obs/nt) and construct
`iG.stateInterp σ _ _ _ = stateI σ` via a custom IrisGS_gen instance.
Deferred.

Other meta proofs (wp_strong_adequacy_gen, wp_progress_gen,
wp_adequacy_gen): agents either still running or hit
fromOptionVal/match-form ispecialize blockers; left as plain `sorry`.
@MackieLoeffel
Copy link
Copy Markdown
Collaborator

I've looked into this and your fix seems like the best option. I added some comments and a test for this behavior.

Comment thread Iris/Iris/NotationTest.lean.ignore Outdated
@Kaptch Kaptch merged commit 23fc7d5 into leanprover-community:master May 21, 2026
5 checks passed
lihaokun added a commit to lihaokun/iris-lean that referenced this pull request May 22, 2026
…kestpre interface

Lean 4 port of `iris/program_logic/adequacy.v`, adapted to the
`IrisGS_gen` / `wp.pre` / `WP _ @ s ; E {{ Φ }}` interface from PR leanprover-community#393.

Proven in this branch (5 lemmas + 2 theorems):
- `wp_step`, `wptp_step`, `wp_not_stuck`
- `wptp_preservation` (refl case)
- `adequate_alt`, `adequate_tp_safe`

Remaining sorries:
- `wptp_preservation` cons (skeleton + ~40 lines of working IPM; blocked
  at `imod Hbody` — goal is step_fupdN, not fupd outermost)
- `wptp_postconditions`, `wptp_progress` (plain sorry, follow same pattern
  as `wptp_preservation`)
- `wp_progress_gen`, `wp_strong_adequacy_gen`, `wp_adequacy_gen`,
  `wp_invariance_gen` (4 meta-level theorems with `_hwp : True` placeholders;
  unblocked once `InvGpreS`-style existential is finalized)

Helper `step_fupdN_compose` proves `(|=...=>^[a] P) ⊢ (P -∗ |=...=>^[b] Q) -∗
|=...=>^[a+b] Q` (`step_fupdN_wand` + `Nat.repeat_add`).
lihaokun added a commit to lihaokun/iris-lean that referenced this pull request May 22, 2026
`wp_invariance_gen`: full structural proof using `adequate_alt` +
`wp_strong_adequacy_gen` (oracle) + `erasedStep_nSteps` + per-element
bigSepL2 handling. Internal sorry at the `bridge` step: our Lean
signature has `iG.stateInterp σ2 0 [] (t2.length - 1)` with literal
`ns = 0`, while `wp_strong_adequacy_gen` yields `ns = n` from the
NSteps count. Coq absorbs this via `(λ σ _ _ _, stateI σ)` in the user-
constructed `irisGS_gen`; the Lean PR leanprover-community#393 interface receives iG
externally, so the `ns` parameter is literal `0` in the user signature.
`stateInterp_mono` only goes `ns → ns+1` (not downward), so we cannot
bridge `n → 0`.

Fix path: change wp_invariance_gen's `_Hwp` signature to take a
`stateI : State → IProp GF` (without ns/obs/nt) and construct
`iG.stateInterp σ _ _ _ = stateI σ` via a custom IrisGS_gen instance.
Deferred.

Other meta proofs (wp_strong_adequacy_gen, wp_progress_gen,
wp_adequacy_gen): agents either still running or hit
fromOptionVal/match-form ispecialize blockers; left as plain `sorry`.
ayhon added a commit to ayhon/iris-lean that referenced this pull request May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants