Partial correctness and loop invariants for PDL
PDL
DefinitionPartial-correctness Hoare triple for PDL programs#✓fully proved
Every execution of a from P ends in Q, without a termination
requirement.
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
structure Model (World : Type u) (Atom : Type v) (Label : Type w) where
/-- One accessibility relation per atomic program label. -/
rel : Label → World → World → Prop
/-- The atoms true at each world. -/
valuation : World → Atom → Prop
CSLibExt/Logics/PDL/Basic.lean:44
inductive Program (Atom : Type v) (Label : Type w) where
| atomic (a : Label) : Program Atom Label
| seq (α β : Program Atom Label) : Program Atom Label
| choice (α β : Program Atom Label) : Program Atom Label
| star (α : Program Atom Label) : Program Atom Label
| test (φ : Formula Atom Label) : Program Atom Label
CSLibExt/Logics/PDL/Basic.lean:59
def ProgRel {World Atom Label : Type*} (M : Model World Atom Label) :
Program Atom Label → World → World → Prop
| .atomic a, w, v => M.rel a w v
| .seq α β, w, v => ∃ u, ProgRel M α w u ∧ ProgRel M β u v
| .choice α β, w, v => ProgRel M α w v ∨ ProgRel M β w v
| .star α, w, v => Relation.ReflTransGen (ProgRel M α) w v
| .test φ, w, v => w = v ∧ Sat M φ w
CSLibExt/Logics/PDL/Basic.lean:76
Uses 3 · Used by 14
TheoremPartial correctness as inclusion in the relational core#✓fully proved
Partial correctness agrees with the canonical relation's core.
theorem hoare_iff_subset_core :
Hoare M P a Q ↔ P ⊆ SetRel.core (a.toRelation M) Q
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
Uses 5 · Used by 2
TheoremHoare triples as KAT test inequalities#✓fully proved
Hoare verification is equivalent to the KAT test inequality.
theorem hoare_iff_test_le :
Hoare M P a Q ↔ testSet P * a.toRelation M ≤
a.toRelation M * testSet Q
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def testSet (P : Set World) : SquareRelations World :=
{(s, t) | s = t ∧ s ∈ P}
CSLibExt/Foundations/RelationAlgebra/Tests.lean:33
TheoremHoare triples as KAT absorption equations#✓fully proved
The equivalent KAT absorption equation for verification.
theorem hoare_iff_test_eq :
Hoare M P a Q ↔ testSet P * a.toRelation M =
testSet P * a.toRelation M * testSet Q
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def testSet (P : Set World) : SquareRelations World :=
{(s, t) | s = t ∧ s ∈ P}
CSLibExt/Foundations/RelationAlgebra/Tests.lean:33
Uses 7 · Used by 2
TheoremHoare triples with formula assertions as box validity#✓fully proved
Formula assertions connect Hoare verification to global PDL validity, not just an atomic-action modality.
theorem hoare_iff_box (φ ψ : Formula Atom Label) :
Hoare M {s | Sat M φ s} a {s | Sat M ψ s} ↔
∀ s, Sat M (.imp φ (.box a ψ)) s
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
Uses 6
Hoare
TheoremHoare rule of consequence#✓fully proved
Strengthen the precondition and weaken the postcondition.
theorem consequence {P' Q' : Set World} (h : Hoare M P a Q)
(hP : P' ⊆ P) (hQ : Q ⊆ Q') : Hoare M P' a Q'
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
Uses 4 · Used by 1
TheoremHoare rule for sequential composition#✓fully proved
Sequential verification uses the first postcondition as the second precondition.
theorem seq (ha : Hoare M P a I) (hb : Hoare M I b Q) :
Hoare M P (.seq a b) Q
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
Uses 4
TheoremHoare rule for nondeterministic choice#✓fully proved
Nondeterministic choice is safe exactly when both branches are.
theorem choice_iff :
Hoare M P (.choice a b) Q ↔ Hoare M P a Q ∧ Hoare M P b Q
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
Uses 4
TheoremHoare rule for formula tests#✓fully proved
A formula test requires the postcondition only where the test passes.
theorem test_iff (φ : Formula Atom Label) :
Hoare M P (.test φ) Q ↔ P ∩ {s | Sat M φ s} ⊆ Q
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
Uses 6
TheoremHoare invariant rule for iteration#✓fully proved
A one-step invariant holds after every finite number of iterations, including zero, via CSLib's canonical closure-preservation theorem.
theorem star (h : Hoare M I a I) : Hoare M I (.star a) I
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
Uses 4 · Used by 2
PDL
DefinitionGuarded while loop in PDL#✓fully proved
A guarded loop in the existing PDL syntax: iterate guarded body steps, then test that the guard is false.
def Program.whileDo (guard : Formula Atom Label)
(body : Program Atom Label) : Program Atom Label :=
.seq (.star (.seq (.test guard) body)) (.test (.imp guard .bot))
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
inductive Program (Atom : Type v) (Label : Type w) where
| atomic (a : Label) : Program Atom Label
| seq (α β : Program Atom Label) : Program Atom Label
| choice (α β : Program Atom Label) : Program Atom Label
| star (α : Program Atom Label) : Program Atom Label
| test (φ : Formula Atom Label) : Program Atom Label
CSLibExt/Logics/PDL/Basic.lean:59
Hoare
TheoremHoare invariant rule for guarded while loops#✓fully proved
The guarded-loop invariant rule is partial correctness, including zero-step exits; it does not guarantee termination.
theorem whileDo (guard : Formula Atom Label)
(h : Hoare M (I ∩ {s | Sat M guard s}) a I) :
Hoare M I (Program.whileDo guard a) (I ∩ {s | ¬ Sat M guard s})
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
def Program.whileDo (guard : Formula Atom Label)
(body : Program Atom Label) : Program Atom Label :=
.seq (.star (.seq (.test guard) body)) (.test (.imp guard .bot))
CSLibExt/Logics/PDL/Hoare.lean:123
Uses 8 · Used by 2
TheoremWhile-loop rule with initialization and exit implication#✓fully proved
Verify a guarded loop using initialization, invariant preservation, and the exit implication to the desired postcondition.
theorem whileDo_consequence (guard : Formula Atom Label)
(hinit : P ⊆ I) (hbody : Hoare M (I ∩ {s | Sat M guard s}) a I)
(hexit : I ∩ {s | ¬ Sat M guard s} ⊆ Q) :
Hoare M P (Program.whileDo guard a) Q
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
def Program.whileDo (guard : Formula Atom Label)
(body : Program Atom Label) : Program Atom Label :=
.seq (.star (.seq (.test guard) body)) (.test (.imp guard .bot))
CSLibExt/Logics/PDL/Hoare.lean:123
Uses 8 · Used by 1
TheoremSemantic completeness of the while-loop invariant rule#✓fully proved
The guarded-loop rule is semantically complete for arbitrary set
assertions. The witness is guarded-body reachability from P, independent
of Q; this is not a completeness claim for a syntactic assertion language.
theorem whileDo_iff_exists_invariant (guard : Formula Atom Label) :
Hoare M P (Program.whileDo guard a) Q ↔
∃ I : Set World, P ⊆ I ∧
Hoare M (I ∩ {s | Sat M guard s}) a I ∧
I ∩ {s | ¬ Sat M guard s} ⊆ Q
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Hoare (M : Model World Atom Label) (P : Set World)
(a : Program Atom Label) (Q : Set World) : Prop :=
∀ ⦃s t⦄, s ∈ P → ProgRel M a s t → t ∈ Q
CSLibExt/Logics/PDL/Hoare.lean:39
def Program.whileDo (guard : Formula Atom Label)
(body : Program Atom Label) : Program Atom Label :=
.seq (.star (.seq (.test guard) body)) (.test (.imp guard .bot))
CSLibExt/Logics/PDL/Hoare.lean:123
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
Uses 9
PDL
TheoremPDL induction restricted to reachable states#✓fully proved
PDL induction restricted to states reachable from the initial world.
This proves [a*](φ → [a]φ) → (φ → [a*]φ) without assuming preservation
on unreachable states.
theorem sat_box_star_induction {φ : Formula Atom Label} {s : World}
(hstep : Sat M (.box (.star a) (.imp φ (.box a φ))) s)
(hinit : Sat M φ s) : Sat M (.box (.star a) φ) s
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
Uses 5
TheoremTest absorption lifts through iteration#✓fully proved
Concrete relational test absorption lifts through PDL iteration, connecting the algebraic verification equation to closure invariance.
theorem test_mul_star_absorption
(h : testSet I * a.toRelation M =
testSet I * a.toRelation M * testSet I) :
testSet I * a.star.toRelation M =
testSet I * a.star.toRelation M * testSet I
def testSet (P : Set World) : SquareRelations World :=
{(s, t) | s = t ∧ s ∈ P}
CSLibExt/Foundations/RelationAlgebra/Tests.lean:33
TheoremLoop exit absorption from a guarded-body absorption equation#✓fully proved
A guarded-body verification equation implies the loop's exit verification equation over the same canonical relational carrier.
theorem test_mul_whileDo_absorption (guard : Formula Atom Label)
(h : testSet (I ∩ {s | Sat M guard s}) * a.toRelation M =
testSet (I ∩ {s | Sat M guard s}) * a.toRelation M * testSet I) :
testSet I * (Program.whileDo guard a).toRelation M =
testSet I * (Program.whileDo guard a).toRelation M *
testSet (I ∩ {s | ¬ Sat M guard s})
inductive Formula (Atom : Type v) (Label : Type w) where
| atom (a : Atom) : Formula Atom Label
| bot : Formula Atom Label
| imp (φ ψ : Formula Atom Label) : Formula Atom Label
| box (α : Program Atom Label) (φ : Formula Atom Label) : Formula Atom Label
CSLibExt/Logics/PDL/Basic.lean:52
def testSet (P : Set World) : SquareRelations World :=
{(s, t) | s = t ∧ s ∈ P}
CSLibExt/Foundations/RelationAlgebra/Tests.lean:33
def Sat {World Atom Label : Type*} (M : Model World Atom Label) :
Formula Atom Label → World → Prop
| .atom a, w => M.valuation w a
| .bot, _ => False
| .imp φ ψ, w => Sat M φ w → Sat M ψ w
| .box α φ, w => ∀ v, ProgRel M α w v → Sat M φ v
CSLibExt/Logics/PDL/Basic.lean:85
def Program.whileDo (guard : Formula Atom Label)
(body : Program Atom Label) : Program Atom Label :=
.seq (.star (.seq (.test guard) body)) (.test (.imp guard .bot))
CSLibExt/Logics/PDL/Hoare.lean:123
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.