视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
verified-spec-code-mapper【文档与办公】Establish explicit traceability between formal specifications (preconditions, postconditions, invariants) and verified code components with their correctness proofs. Produce structured Markdown mapping reports showing verification coverage and proof evidence. Use when auditing formal verification, documenting verified systems, establishing traceabili…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Establish explicit, evidence-based traceability between formal specifications and verified code components. Generate structured reports that map each specification to its implementation and correctness proofs, supporting verification auditing, documentation, and reproducibility.
Locate all formal specifications in the codebase:
Preconditions:
forall ... -> P -> ... (hypothesis before conclusion)requires clausesassumes clausesPostconditions:
... -> Q (conclusion of theorem)ensures clausesshows clausesLoop Invariants:
invariant clauses in loopsClass/Type Invariants:
predicate Valid() methodsFunctional Correctness:
For each specification, identify corresponding code:
Direct mapping:
Lemma factorial_positive : forall n, factorial n >= 1
→ Maps to factorial functionContextual mapping:
sort_correct → sort)Structural mapping:
Record locations:
For each specification-code mapping, find proof evidence:
Complete proofs:
Qeddone or qedIncomplete proofs:
AdmittedsorryAssumed axioms:
Axiom declarationsaxiomatizationExternal verification:
Record evidence:
Determine verification completeness:
Specification coverage:
Coverage = (Verified Specs / Total Specs) × 100%
Code coverage:
Coverage = (Verified Functions / Total Functions) × 100%
Proof completeness:
Completeness = (Complete Proofs / Total Proofs) × 100%
Categorize status:
Identify gaps:
Produce structured Markdown report:
Choose report type:
Include required sections:
Use clear status indicators:
Provide traceability:
For detailed patterns and templates, see mapping_patterns.md.
| Specification Type | Typical Location | Verification Evidence |
|---|---|---|
| Precondition | requires, hypothesis | Checked by verifier or proved |
| Postcondition | ensures, conclusion | Theorem proving property |
| Loop Invariant | invariant, lemma | Induction proof |
| Class Invariant | predicate Valid() | Maintained by all methods |
| Functional Correctness | Theorem statement | Complete proof |
Input Code:
Definition divide (n m : nat) : option nat :=
if m =? 0 then None else Some (n / m).
Lemma divide_safe : forall n m : nat,
m <> 0 -> exists q, divide n m = Some q.
Proof.
intros n m Hm.
unfold divide.
destruct (m =? 0) eqn:E.
- apply Nat.eqb_eq in E. contradiction.
- exists (n / m). reflexivity.
Qed.
Generated Report:
# Verification Report: divide
## Function Signature
```coq
Definition divide (n m : nat) : option nat
m <> 0exists q, divide n m = Some qforall n m, m <> 0 -> exists q, divide n m = Some qm =? 0
### Example 2: Class with Invariants (Dafny)
**Input Code:**
```dafny
class BankAccount {
var balance: int
predicate Valid()
reads this
{
balance >= 0
}
constructor(initial: int)
requires initial >= 0
ensures Valid()
ensures balance == initial
{
balance := initial;
}
method Deposit(amount: int)
requires Valid()
requires amount >= 0
modifies this
ensures Valid()
ensures balance == old(balance) + amount
{
balance := balance + amount;
}
}
Generated Report:
# Verification Report: BankAccount
## Class Invariant
### Invariant: Non-negative Balance
- **Specification:** `balance >= 0`
- **Location:** BankAccount.dfy:5 (Valid predicate)
- **Status:** ✓ Fully Verified
## Method: constructor
### Specifications
1. **Precondition: Non-negative Initial**
- Specification: `requires initial >= 0`
- Location: BankAccount.dfy:10
- Status: ✓ Verified by Dafny
2. **Postcondition: Establishes Invariant**
- Specification: `ensures Valid()`
- Location: BankAccount.dfy:11
- Status: ✓ Verified by Dafny
3. **Postcondition: Correct Balance**
- Specification: `ensures balance == initial`
- Location: BankAccount.dfy:12
- Status: ✓ Verified by Dafny
## Method: Deposit
### Specifications
1. **Precondition: Valid State**
- Specification: `requires Valid()`
- Location: BankAccount.dfy:18
- Status: ✓ Verified by Dafny
2. **Precondition: Non-negative Amount**
- Specification: `requires amount >= 0`
- Location: BankAccount.dfy:19
- Status: ✓ Verified by Dafny
3. **Postcondition: Maintains Invariant**
- Specification: `ensures Valid()`
- Location: BankAccount.dfy:21
- Status: ✓ Verified by Dafny
4. **Postcondition: Correct Balance Update**
- Specification: `ensures balance == old(balance) + amount`
- Location: BankAccount.dfy:22
- Status: ✓ Verified by Dafny
## Coverage Summary
- Total Specifications: 7
- Fully Verified: 7 (100%)
- Status: ✓ Fully Verified
- Verification Method: Dafny automatic verifier
Input Code:
Require Import FunctionalExtensionality.
Definition compose {A B C : Type} (g : B -> C) (f : A -> B) : A -> C :=
fun x => g (f x).
Lemma compose_assoc : forall (A B C D : Type)
(f : A -> B) (g : B -> C) (h : C -> D),
compose h (compose g f) = compose (compose h g) f.
Proof.
intros.
apply functional_extensionality.
intro x. reflexivity.
Qed.
Generated Report:
# Verification Report: compose
## Function Signature
```coq
Definition compose {A B C : Type} (g : B -> C) (f : A -> B) : A -> C
compose h (compose g f) = compose (compose h g) ffunctional_extensionality (assumed)forall (A B : Type) (f g : A -> B), (forall x, f x = g x) -> f = g
### Example 4: Traceability Matrix
**Generated Report:**
```markdown
# Verification Traceability Matrix: Sorting Module
| Spec ID | Specification | Code Component | Proof/Theorem | Status |
|---------|---------------|----------------|---------------|--------|
| SORT-001 | Permutation preservation | `sort` (sort.v:15) | `sort_permutes` (sort.v:45) | ✓ |
| SORT-002 | Output is sorted | `sort` (sort.v:15) | `sort_sorted` (sort.v:62) | ✓ |
| SORT-003 | Combined correctness | `sort` (sort.v:15) | `sort_correct` (sort.v:78) | ✓ |
| SORT-004 | Stability (equal elements) | `sort` (sort.v:15) | - | ✗ |
| SORT-005 | Time complexity O(n log n) | `sort` (sort.v:15) | - | ✗ |
## Summary
- Total Specifications: 5
- Fully Verified: 3 (60%)
- Unverified: 2 (40%)
## Verification Gaps
### SORT-004: Stability
- **Status:** ✗ Unverified
- **Reason:** Stability not formally specified or proved
- **Impact:** Cannot guarantee order of equal elements
- **Priority:** Medium
### SORT-005: Time Complexity
- **Status:** ✗ Unverified
- **Reason:** Complexity analysis not formalized
- **Impact:** Performance guarantees not verified
- **Priority:** Low (functional correctness verified)
Evidence-based mapping:
Preserve specification integrity:
Honest status reporting:
Clear distinction:
Do not infer:
Do not merge:
Do not weaken:
filename.extfilename.ext:linefilename.ext:start-end