Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
0f103b9
Shallow embedding: a starting point on Std.Do
kondylidou Oct 9, 2026
4c50465
Shallow embedding: Core-to-Lean translator (shallow_embed) with tests
calciiium Oct 13, 2026
7be2dc4
Merge origin/main into feat/shallow-embedding
kondylidou Oct 15, 2026
0feee21
Merge origin/main into feat/shallow-embedding
kondylidou Oct 17, 2026
dd5fa1a
Improve Emitter design for while loop
calciiium Oct 17, 2026
8f49506
Shallow embedding: prototype of the generic datatype model
kondylidou Oct 21, 2026
ee813a9
Merge remote-tracking branch 'upstream/feat/shallow-embedding' into f…
calciiium Oct 25, 2026
ffe7e69
Ignore .DS_Store
calciiium Oct 25, 2026
cb7a91e
Shallow embedding: interpreter prototype (WIP)
calciiium Oct 26, 2026
df23539
Shallow embedding: interpreter fails instead of going vacuous; reflec…
calciiium Oct 27, 2026
bc3f786
Shallow embedding: write the plan down as ordered steps
kondylidou Oct 27, 2026
d3c185b
Shallow embedding: leave the datatype and nat model for after steps 1…
kondylidou Oct 27, 2026
d1c9b89
Shallow embedding: state the interpreter and adequacy precisely
kondylidou Oct 27, 2026
6e77eec
Shallow embedding: shorten the design doc
kondylidou Oct 27, 2026
ca376cf
Shallow embedding: shorten the design doc and spell out the path
kondylidou Oct 27, 2026
c9fa9fc
Merge branch 'bump/lean-4.34' into feat/shallow-embedding
kondylidou Oct 28, 2026
951cd5c
Shallow embedding: build on Lean 4.34
kondylidou Oct 28, 2026
d34a10c
Merge remote-tracking branch 'origin/main' into feat/shallow-embedding
kondylidou Oct 28, 2026
e88f689
Lean path: build on Core's Hoare logic
kondylidou Oct 28, 2026
218e608
Lean path doc: remove repeated points
kondylidou Oct 28, 2026
60020eb
Lean path doc: record what the Hoare logic's authors intend for it
kondylidou Oct 29, 2026
1c2bc05
Lean path doc: correct rule names, counts, issue state and what lives…
kondylidou Oct 29, 2026
b5c88d6
Lean path doc: executable Core evaluator, step 5 conditional, risks, …
kondylidou Oct 29, 2026
294b0c3
Lean path doc: record the datatype decision shared with the SMT denot…
kondylidou Oct 29, 2026
ea78528
Lean path doc: remove repeated points
kondylidou Oct 29, 2026
8d08f06
Lean path doc: Boole semantics is a goal, after Core
kondylidou Oct 29, 2026
92bfd6b
Lean path doc: Velvet's monad as a candidate for the Boole interpreter
kondylidou Oct 29, 2026
51423d2
Merge remote-tracking branch 'upstream/feat/shallow-embedding' into f…
calciiium Oct 29, 2026
6a7ba1b
Hoare-logic route: name the doc and the datatype test for what they are
abdoo8080 Oct 30, 2026
9dd95b4
Merge remote-tracking branch 'upstream/feat/hoare-logic' into feat/sh…
calciiium Nov 2, 2026
47ea58d
Hoare-logic doc: record the evaluator vacuity on Map and Sequence sta…
kondylidou Nov 8, 2026
0745191
Hoare-logic doc: Map and Sequence are outside the logic until Strata …
kondylidou Nov 8, 2026
852f518
Hoare-logic doc: what the dalek benchmark needs from the route, step …
kondylidou Nov 8, 2026
a6d6e98
Hoare-logic route: max2 proved against Core's triple, with the liftin…
kondylidou Nov 8, 2026
1a395e1
Pin Strata to the fork's integration/lean-route branch
kondylidou Nov 8, 2026
4a1c867
Merge branch 'feat/hoare-logic' into feat/shallow-translator
calciiium Nov 9, 2026
726ee8d
Move the Lean route onto Strata's denotational semantics
kondylidou Nov 10, 2026
58d1bf6
fix
kondylidou Nov 10, 2026
e36a937
fix
kondylidou Nov 10, 2026
225c548
Pin Strata to the integration head with the Hoare rules for the base …
kondylidou Nov 11, 2026
69b78e0
Pin Strata with the Hoare rules for the base commands; track the Stra…
kondylidou Nov 11, 2026
ce9e4c9
sum
kondylidou Nov 11, 2026
73e2e99
Hoare-logic route: tactic, lifting and boole_prove under HoareLogic/
calciiium Nov 12, 2026
0a1fef9
Record the merged Hoare rules and the datatype decision in the doc
kondylidou Nov 14, 2026
c74feec
Mark the merged denote lemmas and the closed datatype draft in the doc
kondylidou Nov 14, 2026
fbdf57b
Bump Strata to main with the open PRs; port to source locations on Co…
kondylidou Nov 14, 2026
c4df538
Merge branch 'feat/hoare-logic' into feat/hoare-route
calciiium Nov 16, 2026
f3ae840
Bring the dalek sum_of_slice benchmark to this branch, solver path only
kondylidou Nov 16, 2026
5ea2977
Remove the Std.Do prototype and its test; the Hoare route does not bu…
kondylidou Nov 17, 2026
d80bde4
Bump Strata to main with the merged contract-triple axioms
kondylidou Nov 18, 2026
2187eba
Give the trusted callee of sum_of_slice a body that assumes its contract
kondylidou Nov 18, 2026
5b6a3fc
Record the call-site lemma pull request in the Hoare document
kondylidou Nov 18, 2026
126c4b4
Decide termination as a separate proof in the Hoare document
kondylidou Nov 19, 2026
82a2a6f
Record the datatype factory pull request in the Hoare document
kondylidou Nov 19, 2026
a3982d0
Merge branch 'main' into feat/hoare-logic
kondylidou Nov 19, 2026
f198ed1
more
kondylidou Nov 24, 2026
ebba716
Pin Strata main with the open Lean-route pull requests, on Lean 4.35
kondylidou Nov 26, 2026
90f41d9
Merge branch 'main' into feat/hoare-logic
kondylidou Nov 26, 2026
984db33
Pin Strata main with the evaluation lemmas; use them in place of loca…
kondylidou Nov 27, 2026
40d7628
Lift a quantified clause by hand, as the recipe for the lifting tactic
kondylidou Nov 27, 2026
aae4c3a
Merge branch 'main' into feat/hoare-logic
kondylidou Nov 27, 2026
d03750d
Merge remote-tracking branch 'origin/main' into feat/hoare-logic
kondylidou Nov 30, 2026
08502b5
Hoare route: follow the denotational Core semantics; boole_reflect an…
calciiium Nov 30, 2026
e0e242c
Merge upstream feat/hoare-logic into feat/hoare-route
calciiium Nov 30, 2026
f724523
Port the Hoare route to Lean 4.35 and Strata 53a3ff3c
calciiium Nov 30, 2026
2898b5e
Entry over any visible factory; outputs typed at the entry
calciiium Nov 30, 2026
fd0206b
`exit`
calciiium Nov 30, 2026
a5df977
Call of a procedure without a body
calciiium Nov 30, 2026
66c8523
Values of any sort; operators read in the model
calciiium Nov 30, 2026
7ea9640
Axioms as hypotheses; `bv` literals; guarded division
calciiium Nov 30, 2026
cd764d3
Function definitions and sequence lengths as hypotheses; `sum_of_slic…
calciiium Nov 30, 2026
08d7037
Lower a Boole procedure without a body to an abstract procedure
calciiium Nov 30, 2026
8cbff95
`hoare_contract` on an abstract procedure; calls from Boole; the dale…
calciiium Nov 30, 2026
c3ae2f9
Goals without the model; `smt` on the dalek goals; faster lifting
calciiium Nov 30, 2026
fb5a166
The goals a call leaves keep the path to the call
calciiium Nov 30, 2026
8f2c7b8
Drop lemmas Strata proves, two rules without a caller, a stale docstring
calciiium Nov 30, 2026
6e7fc52
Name a clause without a label without its source offset
calciiium Nov 30, 2026
3aa5591
docs: status of the Hoare route
calciiium Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.lake

# macOS Finder metadata
.DS_Store
23 changes: 23 additions & 0 deletions StrataBoole.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module

public import StrataBoole.Boole
public import StrataBoole.Verify
public import StrataBoole.HoareLogic.HoareLift

/-! ## Strata Boole Public Interface

Expand All @@ -29,6 +30,28 @@ dialect of Strata.
`Strata.BooleNat.prepend`. The implementation is `natCorePreamble` in
`StrataBoole/Verify.lean`; nothing imports this module. `lake build StrataBoole.Nat`.

### `import StrataBoole.HoareLogic.Pipeline`

`boole_prove pgm proc` proves in Lean the contract of the procedure `proc` of the Boole program
`pgm`: it binds the program's Core AST (`boole_reflect`), then states and proves
`proc_contract : Core.Logic.Hoare.Procedure.contractTriple pgm_ast params "proc"`, closing each
verification condition with `omega`, then `grind`. `… with tac` closes the conditions with `tac`.

### `import StrataBoole.HoareLogic.Hoare.Tactic`

The Hoare-logic route of `docs/HoareLogic.md`, on Strata's `Core.Logic.Hoare`:
weakest-precondition rules proved from Strata's (`Hoare/Rules.lean`, `Proj.lean`, `WP.lean`,
`Contract.lean`), lifting lemmas for the evaluator and the denotation (`Hoare/Lift/`), and the
tactics `hoare_contract`, `hoare_vcs` and `hoare_lift`, which turn `Procedure.contractTriple`
into verification conditions over `Int` and `Bool`, named after the program's clauses.

### `import StrataBoole.HoareLogic.Reflect.Boole`

`boole_reflect p` binds the type-checked Core program of the Boole program `p` to
`<p>_ast : Core.Program` and each of its procedures to `<name>_ast : Core.Procedure`, as terms
the kernel can reduce. `core_reflect` (`StrataBoole.HoareLogic.Reflect.Core`) does the same
for a program written in Core syntax.

### `import StrataBoole.MetaVerifier`

The `gen_smt_vcs_boole` tactic and `Strata.smtVCsCorrectBoole` are available
Expand Down
623 changes: 623 additions & 0 deletions StrataBoole/HoareLogic/Delab.lean

Large diffs are not rendered by default.

403 changes: 403 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Call.lean

Large diffs are not rendered by default.

356 changes: 356 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Contract.lean

Large diffs are not rendered by default.

1,083 changes: 1,083 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Lift/Denote.lean

Large diffs are not rendered by default.

594 changes: 594 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Lift/Eval.lean

Large diffs are not rendered by default.

446 changes: 446 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Proj.lean

Large diffs are not rendered by default.

267 changes: 267 additions & 0 deletions StrataBoole/HoareLogic/Hoare/Rules.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/-
Copyright Strata Contributors

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

public import Strata.Languages.Core.Logic.Hoare
public import Strata.Languages.Core.Logic.LangDefProps
public import StrataBoole.HoareLogic.Hoare.Proj

/-! # Core Hoare rules beyond `Core.Logic.Hoare`

`Procedure.contractTriple` states a contract as a `Core.Logic.Hoare.Triple`, the judgement the
rules of `Core.Logic.Hoare` are about, so those rules apply to a contract as they are. This file
adds the rules they do not cover, for the same judgement:

* `nil`, the empty statement list;
* `block_proj` and `ite_proj`, the block rules of `StrataBoole/HoareLogic/Hoare/Proj.lean` that
carry the store projection in the postcondition instead of asking for `PostWF`;
* `ite_nondet_proj` and `while_nondet`, for a nondeterministic guard. -/

public section

namespace Strata.Hoare

open Core.Logic
open Core.Logic.Hoare (Triple)

variable (π : String → Option Core.Procedure) (params : Core.Logic.InitEnvWFParams)
variable {factory : Lambda.Factory Core.CoreLParams}

/-! ## Structural rules -/

/-- The empty statement list leaves the environment alone. -/
theorem nil (Pre : Imperative.Env Core.Expression → Prop) :
Triple π params Pre [] Pre (factory := factory) :=
Imperative.Logic.Hoare.skip_block (Core.EvalCommandE π) Core.Logic.BlockInitEnvWF params Pre

/-- `block` with the projection in the body's postcondition: `Post` is checked at the environment
with the body's declarations dropped, which is the one leaving the block. -/
theorem block_proj {ss : Core.Statements} {l : String} {md : Imperative.MetaData Core.Expression}
{Pre Post : Imperative.Env Core.Expression → Prop}
(h : Triple π params Pre ss
(Proj.projected (Imperative.Block.definedVars (P := Core.Expression) (C := Core.Command) ss true)
Post) (factory := factory)) :
Triple π params Pre [.block l ss md] Post (factory := factory) :=
Imperative.Logic.Hoare.singleton (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun _ hb => blockInitEnvWF_singleton hb)
(Proj.block_proj (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun he hn hnd => Core.evalCommandE_preserves_none_of_not_def π he hn hnd)
(fun _ hb => blockInitEnvWF_of_block hb)
(fun _ hb => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_block hb))
h)

/-- `ite` with the projection in each branch's postcondition. -/
theorem ite_proj {cond : Core.Expression.Expr} {tss ess : Core.Statements}
{md : Imperative.MetaData Core.Expression}
{Pre Post : Imperative.Env Core.Expression → Prop}
(ht : Triple π params
(fun ρ => Pre ρ ∧
Core.Expression.eval ρ.factory ρ.store cond = some (Imperative.HasBool.ttVal ρ.factory))
tss (Proj.projected
(Imperative.Block.definedVars (P := Core.Expression) (C := Core.Command) tss true) Post)
(factory := factory))
(he : Triple π params
(fun ρ => Pre ρ ∧
Core.Expression.eval ρ.factory ρ.store cond = some (Imperative.HasBool.ffVal ρ.factory))
ess (Proj.projected
(Imperative.Block.definedVars (P := Core.Expression) (C := Core.Command) ess true) Post)
(factory := factory)) :
Triple π params Pre [.ite (.det cond) tss ess md] Post (factory := factory) :=
Imperative.Logic.Hoare.singleton (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun _ hb => blockInitEnvWF_singleton hb)
(Proj.ite_proj (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun he hn hnd => Core.evalCommandE_preserves_none_of_not_def π he hn hnd)
(fun _ hb => blockInitEnvWF_of_ite_then hb)
(fun _ hb => blockInitEnvWF_of_ite_else hb)
(fun _ hb => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_ite_then hb))
(fun _ hb => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_ite_else hb))
ht he)

/-! ## Nondeterministic branches and loops

The well-formedness lemmas of `Core.Logic` are stated for a deterministic guard. A
nondeterministic guard puts no variable and no operator into the def-use check, so the same
proofs go through at `.nondet`. -/

theorem blockInitEnvWF_of_ite_then_nondet {params : InitEnvWFParams}
{tss ess : Core.Statements} {md : Imperative.MetaData Core.Expression}
{ρ : Imperative.Env Core.Expression}
(h : InitEnvWF params (.ite .nondet tss ess md) ρ) : BlockInitEnvWF params tss ρ := by
have hdu := h.defUseOk
have hdefs := h.defsUndefined
have hdnr := h.definedVarsNotReserved
simp only [Imperative.Stmt.defUseWellFormed, Bool.and_eq_true] at hdu
simp only [Imperative.Stmt.definedVars, Bool.false_eq_true, ite_false] at hdefs hdnr
exact BlockInitEnvWF.of_defUseOk h.toWellFormedSemanticEval h.storeWellDefined
(fun n hn => hdefs n (List.mem_append.mpr (Or.inl hn)))
(fun n hn => hdnr n (List.mem_append.mpr (Or.inl hn)))
h.reservedFresh
(fun l hl => h.exitsNotReserved l
(by rw [Imperative.Stmt.labels]; exact List.mem_append.mpr (Or.inl hl)))
hdu.1.2 h.factoryDeclared h.runtimeFactoryDeclared
(fun ty hty => h.initTypesInhabited ty
(by simp only [Imperative.Stmt.initTypes]; exact List.mem_append.mpr (Or.inl hty)))
(by
obtain ⟨Γ, hσ, hw⟩ := h.fvarTypesOk
simp only [Imperative.Stmt.fvarTypesWellAnnotated] at hw
exact ⟨Γ, hσ, hw.2.1⟩)
(fun m hm => h.measuresTyped m
(by simp only [Imperative.Stmt.measures]; exact List.mem_append.mpr (Or.inl hm)))

theorem blockInitEnvWF_of_ite_else_nondet {params : InitEnvWFParams}
{tss ess : Core.Statements} {md : Imperative.MetaData Core.Expression}
{ρ : Imperative.Env Core.Expression}
(h : InitEnvWF params (.ite .nondet tss ess md) ρ) : BlockInitEnvWF params ess ρ := by
have hdu := h.defUseOk
have hdefs := h.defsUndefined
have hdnr := h.definedVarsNotReserved
simp only [Imperative.Stmt.defUseWellFormed, Bool.and_eq_true] at hdu
simp only [Imperative.Stmt.definedVars, Bool.false_eq_true, ite_false] at hdefs hdnr
exact BlockInitEnvWF.of_defUseOk h.toWellFormedSemanticEval h.storeWellDefined
(fun n hn => hdefs n (List.mem_append.mpr (Or.inr hn)))
(fun n hn => hdnr n (List.mem_append.mpr (Or.inr hn)))
h.reservedFresh
(fun l hl => h.exitsNotReserved l
(by rw [Imperative.Stmt.labels]; exact List.mem_append.mpr (Or.inr hl)))
hdu.2 h.factoryDeclared h.runtimeFactoryDeclared
(fun ty hty => h.initTypesInhabited ty
(by simp only [Imperative.Stmt.initTypes]; exact List.mem_append.mpr (Or.inr hty)))
(by
obtain ⟨Γ, hσ, hw⟩ := h.fvarTypesOk
simp only [Imperative.Stmt.fvarTypesWellAnnotated] at hw
exact ⟨Γ, hσ, hw.2.2⟩)
(fun m hm => h.measuresTyped m
(by simp only [Imperative.Stmt.measures]; exact List.mem_append.mpr (Or.inr hm)))

theorem blockInitEnvWF_of_loop_body_nondet {params : InitEnvWFParams}
{m : Option Core.Expression.Expr} {inv : List (String × Core.Expression.Expr)}
{body : Core.Statements} {md : Imperative.MetaData Core.Expression}
{ρ : Imperative.Env Core.Expression}
(h : InitEnvWF params (.loop .nondet m inv body md) ρ) : BlockInitEnvWF params body ρ := by
have hdu := h.defUseOk
have hdefs := h.defsUndefined
have hdnr := h.definedVarsNotReserved
simp only [Imperative.Stmt.defUseWellFormed, Bool.and_eq_true] at hdu
simp only [Imperative.Stmt.definedVars, Bool.false_eq_true, ite_false] at hdefs hdnr
exact BlockInitEnvWF.of_defUseOk h.toWellFormedSemanticEval h.storeWellDefined hdefs hdnr
h.reservedFresh
(fun l hl => h.exitsNotReserved l (by rw [Imperative.Stmt.labels]; exact hl))
hdu.2 h.factoryDeclared h.runtimeFactoryDeclared
(fun ty hty => h.initTypesInhabited ty (by simp only [Imperative.Stmt.initTypes]; exact hty))
(by
obtain ⟨Γ, hσ, hw⟩ := h.fvarTypesOk
simp only [Imperative.Stmt.fvarTypesWellAnnotated] at hw
exact ⟨Γ, hσ, hw.2.2.2⟩)
(fun m' hm => h.measuresTyped m'
(by simp only [Imperative.Stmt.measures]; exact List.mem_append.mpr (Or.inr hm)))

theorem initEnvWF_loop_iterateE_nondet {params : InitEnvWFParams}
{m : Option Core.Expression.Expr} {inv : List (String × Core.Expression.Expr)}
{body : Core.Statements} {md : Imperative.MetaData Core.Expression}
{ρ ρ_inner : Imperative.Env Core.Expression} {tr : Imperative.Trace Core.Expression}
(h : InitEnvWF params (.loop .nondet m inv body md) ρ)
(hrun : Imperative.StepStmtStarE Core.Expression (Core.EvalCommandE π)
(.stmts body ρ) tr (.terminal ρ_inner)) :
InitEnvWF params (.loop .nondet m inv body md)
{ ρ_inner with store := Imperative.projectStore ρ.store ρ_inner.store } := by
have hstore : ∀ n, ((Imperative.projectStore ρ.store ρ_inner.store) n).isSome
= (ρ.store n).isSome := by
intro n
by_cases hn : (ρ.store n).isSome = Bool.true
· simp only [Imperative.projectStore, hn, ite_true]
exact Core.core_stmts_preserves_isSomeE π hrun hn
· have hnone : ρ.store n = none := by
cases hq : ρ.store n with
| none => rfl
| some v => rw [hq] at hn; simp at hn
simp [Imperative.projectStore, hnone]
have hfun : (fun n => ((Imperative.projectStore ρ.store ρ_inner.store) n).isSome)
= (fun n => (ρ.store n).isSome) := funext hstore
have hfac : ρ.factory = ρ_inner.factory := Imperative.starE_preserves_factory hrun
have hproj : Imperative.WellFormedStore (Imperative.projectStore ρ.store ρ_inner.store)
ρ_inner.factory := by
have hpres : ∀ {f : Core.Expression.Factory} {σ σ' : Core.CoreStore} {c : Core.Command}
{emitted : Imperative.Trace Core.Expression},
Core.EvalCommandE π f σ c σ' emitted →
Imperative.WellFormedStore σ f → Imperative.WellFormedStore σ' f :=
fun hc hs => Core.evalCommandE_storeWellDefined π hc hs
have hinner : Imperative.WellFormedStore ρ_inner.store ρ_inner.factory :=
Imperative.Config.storeWellDefined_star_ofE (EvalCmd := Core.EvalCommandE π) hpres
hrun h.storeWellDefined
intro x w hx
simp only [Imperative.projectStore] at hx
split at hx
· exact hinner x w hx
· exact absurd hx (by simp)
refine InitEnvWF.of_defUseOk (hfac ▸ h.toWellFormedSemanticEval) hproj (fun n hn => ?_)
h.definedVarsNotReserved (fun n hn => ?_) h.exitsNotReserved ?_ h.factoryDeclared
(hfac ▸ h.runtimeFactoryDeclared) (hfac ▸ h.initTypesInhabited) ?_ h.measuresTyped
· have hdef := h.defsUndefined n hn
show (Imperative.projectStore ρ.store ρ_inner.store n).isNone
rw [Option.isNone_iff_eq_none] at hdef ⊢
simp [Imperative.projectStore, hdef]
· exact h.reservedFresh n (by rw [← hstore n]; exact hn)
· show Imperative.Stmt.defUseWellFormed
(fun n => ((Imperative.projectStore ρ.store ρ_inner.store) n).isSome) params.declaredFuncs _
= Bool.true
rw [hfun]; exact h.defUseOk
· obtain ⟨Γ, hσ, hw⟩ := h.fvarTypesOk
refine ⟨Γ, fun y ty hy => ?_, hw⟩
have hsome : (ρ.store y).isSome = Bool.true := by
obtain ⟨w, hw', _⟩ := hσ y ty hy
simp [hw']
obtain ⟨v, hv, hvt⟩ := Core.core_stmts_preserves_typedAtE π hrun (hσ y ty hy)
exact ⟨v, by simp [Imperative.projectStore, hsome, hv], hvt⟩

/-- `if (*)` with the projection in each branch's postcondition. -/
theorem ite_nondet_proj {tss ess : Core.Statements} {md : Imperative.MetaData Core.Expression}
{Pre Post : Imperative.Env Core.Expression → Prop}
(ht : Triple π params Pre tss (Proj.projected
(Imperative.Block.definedVars (P := Core.Expression) (C := Core.Command) tss true) Post)
(factory := factory))
(he : Triple π params Pre ess (Proj.projected
(Imperative.Block.definedVars (P := Core.Expression) (C := Core.Command) ess true) Post)
(factory := factory)) :
Triple π params Pre [.ite .nondet tss ess md] Post (factory := factory) :=
Imperative.Logic.Hoare.singleton (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun _ hb => blockInitEnvWF_singleton hb)
(Proj.ite_nondet_proj (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun he hn hnd => Core.evalCommandE_preserves_none_of_not_def π he hn hnd)
(fun _ hb => blockInitEnvWF_of_ite_then_nondet hb)
(fun _ hb => blockInitEnvWF_of_ite_else_nondet hb)
(fun _ hb => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_ite_then_nondet hb))
(fun _ hb => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_ite_else_nondet hb))
ht he)

/-- `while (*)`: the invariant is preserved by the body and is all that is known at the exit. -/
theorem while_nondet {measure : Option Core.Expression.Expr}
{inv : List (String × Core.Expression.Expr)} {body : Core.Statements}
{md : Imperative.MetaData Core.Expression} {Inv : Imperative.Env Core.Expression → Prop}
(hbody : Triple π params Inv body Inv (factory := factory))
(hcov : Imperative.Block.exitsCoveredByBlocks
(P := Core.Expression) (CmdT := Core.Command) [] body)
(hInv_proj : Imperative.Logic.Hoare.PostWF body Inv) :
Triple π params Inv [.loop .nondet measure inv body md] Inv (factory := factory) :=
Imperative.Logic.Hoare.singleton (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun _ hb => blockInitEnvWF_singleton hb)
(Proj.while_nondet (Core.EvalCommandE π)
Core.Logic.InitEnvWF Core.Logic.BlockInitEnvWF params params
(fun he hn hnd => Core.evalCommandE_preserves_none_of_not_def π he hn hnd)
(fun _ hl => blockInitEnvWF_bodyDefsUndefined (blockInitEnvWF_of_loop_body_nondet hl))
(fun _ hl => blockInitEnvWF_of_loop_body_nondet hl)
(fun _ _ _ hl hr => initEnvWF_loop_iterateE_nondet π hl hr)
hbody hcov hInv_proj)

end Strata.Hoare

end -- public section
Loading