一键导入
hoare-logic-verifier
Verifies programs using Hoare logic. Use when: (1) Proving program correctness, (2) Designing verified software, (3) Verifying loop invariants.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Verifies programs using Hoare logic. Use when: (1) Proving program correctness, (2) Designing verified software, (3) Verifying loop invariants.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement abstract machines for defining and executing operational semantics of programming languages.
Implements alias and points-to analysis for pointer programs. Use for: (1) Optimizing compilers, (2) Verifying memory safety, (3) Program understanding, (4) Parallelization.
Define program meaning through logical assertions and proof rules (Hoare logic).
Transforms closures to explicit environments. Use when: (1) Implementing functional languages, (2) Building compilers, (3) Understanding closures.
Implements common subexpression elimination (CSE). Use when: (1) Building compilers, (2) Optimizing code, (3) Program analysis.
Implements general dataflow analysis framework. Use when: (1) Building compilers, (2) Static analysis tools, (3) Program verification.
| name | hoare-logic-verifier |
| description | Verifies programs using Hoare logic. Use when: (1) Proving program correctness, (2) Designing verified software, (3) Verifying loop invariants. |
| version | 1.0.0 |
| tags | ["verification","hoare-logic","program-proving","correctness"] |
| difficulty | intermediate |
| languages | ["python","coq","why3"] |
| dependencies | ["operational-semantics-definer"] |
Verifies program correctness using Floyd-Hoare logic.
| Concept | Description |
|---|---|
| Precondition | State before execution |
| Postcondition | State after execution |
| Invariant | True before/after each loop iteration |
| Weakest precondition | Minimal condition ensuring postcondition |
| Verification condition | Formula to prove for correctness |
{P} while b do c {Q}
VCs:
1. P ⇒ I (initiation)
2. I ∧ b ⇒ wp(c, I) (preservation)
3. I ∧ ¬b ⇒ Q (usefulness)
{ x = a ∧ y = b }
t := x;
x := y;
y := t;
{ x = b ∧ y = a }
{ ∃i. A[i] = k ∧ 0 ≤ i < n }
i := 0;
while i < n do
if A[i] = k then break;
i := i + 1
{ (i < n ⇒ A[i] = k) ∧ (i = n ⇒ ∀j. 0≤j<n ⇒ A[j] ≠ k) }
separation-logician - Heap verificationinvariant-generator - Automatic invariant inferenceloop-termination-prover - Prove termination| Reference | Why It Matters |
|---|---|
| Hoare, "An Axiomatic Basis for Computer Programming" (CACM 1969) | Original Hoare logic paper (Turing Award) |
| Apt & Olderog, "Verification of Programs" (1981) | Comprehensive survey |
| Floyd, "Assigning Meanings to Programs" (1967) | Predecessor to Hoare logic |
| Nielson & Nielson, "Hoare Logic" (1999) | Formal treatment |
| Gupta et al., "A Practical Guide to Design of C Programs" (1991) | Verifiable C coding |
| Approach | Pros | Cons |
|---|---|---|
| Standard Hoare | Simple, intuitive | Can't handle heap/pointers |
| Separation Logic | Handles pointers, heap | More complex |
| Dynamic Logic | Loops as formulas | Harder to use |
Verification tools based on Hoare logic:
| Tool | Language | What to Learn |
|---|---|---|
| Dafny | C#/Boogie | Verified programs |
| Verifiable C (VST) | Coq | C verification |
| Frama-C | C | Static analysis |
| Why3 | Why3 | Verification platform |
| ESC/Java | Java | Extended Static Checking |
| Spec# | C# | Contract-based verification |
| Pitfall | Real Consequence | Solution |
|---|---|---|
| Wrong invariant | Unsound proof | Verify each VC |
| Missing frames | Incomplete specs | Use separation logic |
| Division by zero | Runtime errors | Add precondition |
| Overflow | Unsoundness | Use bounded integers |
Finding invariants is undecidable:
# What invariant proves this?
i = 0
sum = 0
while i < n:
sum = sum + i
i = i + 1
# Answer: sum = i*(i-1)/2
# Another valid invariant: 0 <= i <= n AND sum >= 0
# But this is too weak to prove final result!
This is why verification requires human insight!