From applied-pl
Use Hoare logic to verify, derive, and reason about imperative programs. Apply this skill when asked to prove correctness, find loop invariants, verify pre/postconditions, calculate weakest preconditions, or reason about imperative code with assignments, loops, and conditionals. Also use when the user mentions "Hoare triple", "wp", "program verification".
How this skill is triggered — by the user, by Claude, or both
Slash command
/applied-pl:hoare-logicThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
`{P} C {Q}`: if P holds before C, then Q holds after. Derive correctness with
{P} C {Q}: if P holds before C, then Q holds after. Derive correctness with
named inference rules — never by inspection.
Assignment Axiom (backward — substitute in postcondition):
──────────────────────────
{Q[x/E]} x := E {Q}
wp(x := E, Q) = Q[x/E]
Sequencing: wp(C₁; C₂, Q) = wp(C₁, wp(C₂, Q))
Conditional:
{P ∧ B} C₁ {Q} {P ∧ ¬B} C₂ {Q}
───────────────────────────────────────
{P} if B then C₁ else C₂ {Q}
While (partial correctness):
{I ∧ B} C {I}
──────────────────────────────
{I} while B do C {I ∧ ¬B}
Consequence:
P' → P {P} C {Q} Q → Q'
──────────────────────────────────
{P'} C {Q'}
| Command | wp(C, Q) |
|---|---|
skip | Q |
x := E | Q[x/E] |
C₁; C₂ | wp(C₁, wp(C₂, Q)) |
if B then C₁ else C₂ | (B → wp(C₁, Q)) ∧ (¬B → wp(C₂, Q)) |
while B do C | requires invariant |
Three obligations must hold for invariant I, guard B, loop body C:
Strategies:
s = Σ a[0..n) → Invariant: s = Σ a[0..i) ∧ 0 ≤ i ≤ nRequires a variant t (integer, bounded below by 0 when guard holds, strictly decreasing each iteration):
{I ∧ B ∧ t = V} C {I ∧ t < V} I ∧ B → t ≥ 0
──────────────────────────────────────────────────────
[I] while B do C [I ∧ ¬B]
Square brackets [P] C [Q] denote total correctness.
wp(a[i] := E, Q) = Q[a / a⟨i ↦ E⟩]
where a⟨i ↦ E⟩[j] = if j = i then E else a[j].
Common invariant patterns:
∀ k. 0 ≤ k < i → a[k] = f(k)(∀ k < p → a[k] < pivot) ∧ (∀ p ≤ k < i → a[k] ≥ pivot)∀ k. 0 ≤ k < i-1 → a[k] ≤ a[k+1]i = 0
while i < n and a[i] != v:
i = i + 1
return i
Triple: {n ≥ 0} C {(i < n ∧ a[i] = v) ∨ (i = n ∧ v ∉ a[0..n))}
Invariant: I ≡ 0 ≤ i ≤ n ∧ v ∉ a[0..i)
n ≥ 0 → (0 ≤ 0 ≤ n ∧ v ∉ a[0..0)) — empty range. ✓I ∧ B. After i := i+1: bounds hold from i < n;
v ∉ a[0..i+1) from v ∉ a[0..i) and a[i] ≠ v. ✓¬B ≡ i ≥ n ∨ a[i] = v. With I: either
i = n ∧ v ∉ a[0..n) or i < n ∧ a[i] = v. Both match Q. ✓n - i, decreases by 1; i < n → n - i > 0. ✓ ∎I ∧ B, not just I.{P} C {Q} formallynpx claudepluginhub ldbeth/cc-deno-plugins --plugin applied-plGuides completion of development work by verifying tests, detecting environment, and presenting structured options for merge, PR, or cleanup.
Enforces test-driven development: write failing test first, then minimal code to pass. Use when implementing features or bugfixes.
Guides creation and editing of skills using test-driven development with pressure scenarios and subagents to verify agent compliance.