Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Formal methods, theorem proving, and model checking for CS research
.claude/skills/brycewang-stanford-formal-verification-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-09 | ✗→✓ | ▲ Improved | 85% | 0% |
| case-21 | ✗→✓ | ▲ Improved | 179% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 149% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 159% | 0% |
| case-14 | ✓→✓ | = Same ✓ | 622% | 0% |
A skill for applying formal methods to verify software and hardware correctness. Covers model checking, interactive theorem proving, specification languages, and practical verification workflows used in systems and programming language research.
| Approach | Technique | Strengths | Limitations | |----------|-----------|-----------|-------------| | Model checking | Exhaustive state exploration | Fully automatic, produces counterexamples | State space explosion | | Theorem proving | Interactive proof construction | Handles infinite state | Requires expert effort | | Abstract interpretation | Sound static analysis | Automatic, scales well | May report false positives | | SMT solving | Constraint satisfiability | Powerful automation | Limited to decidable theories | | Runtime verification | Execution monitoring | Low barrier, practical | Only checks observed runs |
TLA+ is the standard specification language for distributed systems:
tla--------------------------- MODULE TwoPhaseCommit ------------------------- EXTENDS Integers, Sequences, FiniteSets CONSTANTS RM \* Set of resource managers VARIABLES rmState, \* rmState[r] is the state of resource manager r tmState, \* State of the transaction manager tmPrepared, \* Set of RMs that have sent "Prepared" msgs \* Set of messages sent vars == <<rmState, tmState, tmPrepared, msgs>> Init == /\ rmState = [r \in RM |-> "working"] /\ tmState = "init" /\ tmPrepared = {} /\ msgs = {} \* RM r prepares to commit RMPrepare(r) == /\ rmState[r] = "working" /\ rmState' = [rmState EXCEPT ![r] = "prepared"] /\ msgs' = msgs \union {[type |-> "Prepared", rm |-> r]} /\ UNCHANGED <<tmState, tmPrepared>> \* TM receives a Prepared message from RM r TMRcvPrepared(r) == /\ tmState = "init" /\ [type |-> "Prepared", rm |-> r] \in msgs /\ tmPrepared' = tmPrepared \union {r} /\ UNCHANGED <<rmState, tmState, msgs>> \* TM commits (all RMs have prepared) TMCommit == /\ tmState = "init" /\ tmPrepared = RM /\ tmState' = "committed" /\ msgs' = msgs \union {[type |-> "Commit"]} /\ UNCHANGED <<rmState, tmPrepared>> \* Safety property: No RM commits unless TM has committed Consistency == \A r \in RM : rmState[r] = "committed" => tmState = "committed" ========================================================================
bash# Install TLA+ Toolbox or use command-line TLC # Define model with specific constants # RM = {"rm1", "rm2", "rm3"} java -jar tla2tools.jar -config TwoPhaseCommit.cfg TwoPhaseCommit.tla # TLC will explore all reachable states and verify: # - No deadlocks (unless specified) # - Safety properties (invariants) # - Liveness properties (temporal formulas)
coq(* Example: Proving properties of a simple functional program *) (* Define natural number addition *) Fixpoint add (n m : nat) : nat := match n with | O => m | S n' => S (add n' m) end. (* Prove: 0 + n = n (left identity) *) Theorem add_0_l : forall n : nat, add 0 n = n. Proof. intro n. simpl. (* simplification reduces add 0 n to n *) reflexivity. Qed. (* Prove: n + 0 = n (right identity, requires induction) *) Theorem add_0_r : forall n : nat, add n 0 = n. Proof. intro n. induction n as [| n' IHn']. - (* Base case: n = 0 *) simpl. reflexivity. - (* Inductive step: n = S n' *) simpl. (* add (S n') 0 = S (add n' 0) *) rewrite IHn'. (* apply induction hypothesis *) reflexivity. Qed. (* Prove associativity of addition *) Theorem add_assoc : forall a b c : nat, add a (add b c) = add (add a b) c. Proof. intros a b c. induction a as [| a' IHa']. - simpl. reflexivity. - simpl. rewrite IHa'. reflexivity. Qed.
isabelletheory SimpleVerification imports Main begin (* Define a recursive function *) fun fib :: "nat => nat" where "fib 0 = 0" | "fib (Suc 0) = 1" | "fib (Suc (Suc n)) = fib (Suc n) + fib n" (* Prove a property *) lemma fib_positive: "0 < fib (Suc n)" by (induction n rule: fib.induct) auto (* Verify a sorting algorithm *) fun insert :: "nat => nat list => nat list" where "insert x [] = [x]" | "insert x (y # ys) = (if x <= y then x # y # ys else y # insert x ys)" fun isort :: "nat list => nat list" where "isort [] = []" | "isort (x # xs) = insert x (isort xs)" (* Prove the output is sorted *) lemma sorted_insert: "sorted (insert x xs) = sorted xs" sorry (* full proof requires additional lemmas *) end
pythonfrom z3 import Solver, Int, Bool, And, Or, Not, Implies, ForAll, sat, unsat def verify_array_bounds(): """ Verify that an array access is always within bounds. Model a loop: for i = 0 to n-1, access a[i]. """ s = Solver() n = Int("n") i = Int("i") # Precondition: n > 0 s.add(n > 0) # Loop invariant: 0 <= i < n at each access s.add(i >= 0) s.add(i < n) # Verify: the access a[i] is within bounds [0, n) s.add(Not(And(i >= 0, i < n))) # try to find a violation result = s.check() if result == unsat: return "VERIFIED: array access is always within bounds" else: return f"COUNTEREXAMPLE: {s.model()}" def verify_integer_overflow(): """ Check if integer addition can overflow for given constraints. """ from z3 import BitVec, BitVecVal s = Solver() # 32-bit signed integers x = BitVec("x", 32) y = BitVec("y", 32) # Preconditions: both positive s.add(x > 0) s.add(y > 0) # Check: can x + y wrap around to negative? s.add(x + y < 0) if s.check() == sat: m = s.model() return { "overflow_possible": True, "x": m[x].as_long(), "y": m[y].as_long(), } return {"overflow_possible": False}
promela/* Mutual exclusion with Peterson's algorithm */ bool flag[2] = false; byte turn = 0; byte critical = 0; /* count of processes in critical section */ active [2] proctype process() { byte me = _pid; byte other = 1 - _pid; do :: /* Entry protocol */ flag[me] = true; turn = other; (flag[other] == false || turn == me); /* Critical section */ critical++; assert(critical == 1); /* mutual exclusion */ critical--; /* Exit protocol */ flag[me] = false; od } /* LTL property: mutual exclusion always holds */ ltl mutex { [] (critical <= 1) }
| Property Type | Example | Specification Pattern | |--------------|---------|----------------------| | Safety | "No two processes in critical section" | [] (count <= 1) | | Liveness | "Every request is eventually served" | [] (request -> <> response) | | Deadlock freedom | "System always has an enabled transition" | [] <> enabled | | Termination | "Program always halts" | Well-founded ordering |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 47,706 | 70,064 | +47% | 1 | 1 | 0% | 7,377 | 8,050 | +9% | 0 | 0 | — |
case-02 | fail→fail | 18,036 | 53,457 | +196% | 1 | 1 | 0% | 3,695 | 6,068 | +64% | 0 | 0 | — |
case-03 | pass→pass | 10,390 | 13,347 | +28% | 1 | 1 | 0% | 1,740 | 4,324 | +149% | 0 | 0 | — |
case-04 | pass→pass | 37,637 | 5,006 | -87% | 1 | 1 | 0% | 1,264 | 3,272 | +159% | 0 | 0 | — |
case-14 | pass→pass | 2,496 | 2,425 | -3% | 1 | 1 | 0% | 369 | 2,664 | +622% | 0 | 0 | — |
case-05 | fail→fail | 8,298 | 8,142 | -2% | 1 | 1 | 0% | 1,495 | 3,816 | +155% | 0 | 0 | — |
case-06 | pass→pass | 12,665 | 9,921 | -22% | 1 | 1 | 0% | 2,088 | 4,321 | +107% | 0 | 0 | — |
case-07 | pass→pass | 9,341 | 7,395 | -21% | 1 | 1 | 0% | 1,963 | 4,033 | +105% | 0 | 0 | — |
case-08 | pass→pass | 7,707 | 8,822 | +14% | 1 | 1 | 0% | 1,503 | 4,036 | +169% | 0 | 0 | — |
case-09 | fail→pass | 13,753 | 16,795 | +22% | 1 | 1 | 0% | 2,674 | 4,940 | +85% | 0 | 0 | — |
case-10 | pass→pass | 6,454 | 6,124 | -5% | 1 | 1 | 0% | 1,113 | 3,512 | +216% | 0 | 0 | — |
case-11 | pass→pass | 10,821 | 13,641 | +26% | 1 | 1 | 0% | 1,552 | 3,206 | +107% | 0 | 0 | — |
case-12 | pass→pass | 9,256 | 8,105 | -12% | 1 | 1 | 0% | 1,371 | 3,675 | +168% | 0 | 0 | — |
case-13 | pass→pass | 5,743 | 6,287 | +9% | 1 | 1 | 0% | 1,092 | 3,409 | +212% | 0 | 0 | — |
case-15 | pass→pass | 10,317 | 10,248 | -1% | 1 | 1 | 0% | 1,873 | 4,282 | +129% | 0 | 0 | — |
case-16 | pass→pass | 6,192 | 4,917 | -21% | 1 | 1 | 0% | 1,035 | 3,198 | +209% | 0 | 0 | — |
case-17 | pass→pass | 5,071 | 4,513 | -11% | 1 | 1 | 0% | 830 | 3,010 | +263% | 0 | 0 | — |
case-18 | pass→pass | 6,919 | 5,519 | -20% | 1 | 1 | 0% | 1,124 | 3,351 | +198% | 0 | 0 | — |
case-19 | pass→pass | 13,891 | 13,255 | -5% | 1 | 1 | 0% | 2,339 | 4,617 | +97% | 0 | 0 | — |
case-20 | pass→pass | 10,852 | 10,994 | +1% | 1 | 1 | 0% | 1,931 | 4,118 | +113% | 0 | 0 | — |
case-21 | fail→pass | 7,513 | 5,631 | -25% | 1 | 1 | 0% | 1,158 | 3,234 | +179% | 0 | 0 | — |
case-22 | pass→pass | 14,059 | 13,438 | -4% | 1 | 1 | 0% | 2,217 | 4,439 | +100% | 0 | 0 | — |
case-23 | pass→pass | 14,188 | 20,738 | +46% | 1 | 1 | 0% | 3,028 | 5,790 | +91% | 0 | 0 | — |
case-24 | pass→pass | 22,044 | 19,355 | -12% | 1 | 1 | 0% | 3,270 | 5,374 | +64% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 24 cases were attempted. The headline lift of +8 percentage points is the difference between those two pass rates over the 24 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.