Video · Lecture notes · Slides

A failed test can supply a concrete counterexample. To establish a property for every allowed execution, we also need to define the initial states, execution rules, and conditions that count as a violation. Even a passing CI run depends on a smaller version of this problem. The tests that ran have to match the tests the project intended to run.
1. Give test policy one executable home
Separate unit, module, and system directories organize the files. A system test that needs a virtual machine may still require edits to documentation, CI, and runner scripts. If these describe the same policy independently, they can drift and leave an entire test outside CI.
A machine-readable registry can record scope, level, runner, arguments, and environment requirements. The runner builds its plan from the registry. CI checks the declared scopes against tests discovered independently in the repository. Checking only the declarations catches missing paths but cannot expose an entirely undeclared test.
2. Use an invariant to explain a loop
The Hoare triple {P} C {Q} gives a program C a precondition P and a postcondition Q. Partial correctness requires a run starting in P to end in Q if it terminates. Total correctness also requires termination. An endless sort can meet a partial correctness claim while never delivering a result.
A loop invariant must hold at entry, survive a body execution when the guard holds, and establish the postcondition together with the exit condition. A quantity that strictly decreases in a well-founded order can supply the separate termination argument.
Boyer–Moore majority voting illustrates how an invariant explains a surprisingly small program. Partition the votes seen so far into pairs for different options and a remainder for the current candidate. A matching vote joins the remainder. A different vote cancels one member of it. When the remainder is empty, the next vote supplies a candidate. Removing a pair of different votes preserves any strict majority. If the input may lack a majority, a second pass has to verify the candidate's actual count.
3. Exhaust the behaviors of a model
Two threads can both load zero, increment a local copy, and store one. Atomic loads and stores allow this interleaving because the full increment spans several operations. A model checker can explore those interleavings and report a trace to the wrong final state. Using an atomic read-modify-write changes the transition rules to be checked.
For a finite model, repeatedly adding successor states yields the reachable set. If the set contains the initial states, is closed under transitions, and excludes bad states, those states are unreachable. Combining components can cause state explosion. Symbolic representations can compress sets of states, while bounded model checking asks a solver for a counterexample within a fixed number of steps. A negative result ordinarily covers that bound.
4. Match the method to the question
A TLA+ model can represent transaction participants and messages, then check whether one participant can commit while another aborts. The guarantee applies to the modeled transitions. Relating deployed software to those transitions is separate work. Symbolic execution follows program paths with constraints on the input. A solver can produce concrete inputs that take a chosen path, subject to the paths explored and the environment modeled.
5. Check the proof and the proposition
Lean tactics help split goals, apply lemmas, and construct proof terms. The kernel checks the resulting terms. Under the Curry–Howard correspondence, proving that P implies Q means constructing a function from proofs of P to proofs of Q. An existential proof pairs a witness with evidence that it has the required property. A model can search for candidate steps and revise them when the checker reports unfinished goals or type errors.
Proof-carrying code applies this division to delivery. The producer supplies a proof for a safety policy and the recipient checks it. The policy still has to express the behavior that matters. A payment system that leaves every account untouched keeps balances nonnegative while omitting transfers. Running useful scenarios against the specification and checking whether it rules out known bad implementations can expose that gap.
