Formal Reasoning in Practice
-
Making a Claim About Program State
A state claim describes values allowed at a particular point. Specifying that point matters because operations can change whether the claim holds.
-
Reading an Assignment as a State Transition
A simple assignment evaluates its right-hand expression using the prior state, then updates the destination indicated by the assignment.
-
Proving a Postcondition for One Increment
A proof for a simple assignment can relate its post-update value to the input. Use the target property to identify adequate initial states.
-
An Intermediate Assertion Between Assignments
An intermediate assertion can connect the promised result of one step to the starting requirement of the next.
-
Proving a Conditional by Splitting on Its Test
Each branch can be proved under the conditions allowing it to run. Together the cases support a claim for the whole conditional.
-
Checking a Loop Invariant Before the First Step
Initialization establishes that a loop invariant holds even when the body has run zero times.
-
Checking That One Loop Step Preserves an Invariant
Preservation assumes an invariant before an allowed iteration and proves it remains true afterward.
-
Using a Loop Invariant at Exit
An invariant describes maintained facts. The loop's exit condition says which facts about remaining work hold when it finishes.
-
An Inductive Invariant for a Reservation Counter
An inductive state invariant is true initially and maintained by every allowed transition. A counter rule can be checked at each operation.
-
Proving Termination with Remaining Work
A decreasing measure into the natural numbers can show that an operation eventually reaches a base case or stops looping.
-
Partial and Total Correctness
Partial correctness establishes a promised result whenever an operation terminates normally from allowed state. Total correctness also supplies termination under those conditions.
-
A Counterexample as a State Trace
A reachable sequence of steps can refute a claim by showing a first state where the promised property fails.
-
Checking a Small State Graph Explicitly
For a finite model, systematic reachability can inspect every state accessible from the specified initial conditions.
-
What a Bounded State Check Covers
A bounded check explores execution only within a stated horizon. Failure within that horizon can give a concrete trace.
-
A Safety Property for a Queue Limit
A safety invariant can rule out a state with too many queued items. A finite bad prefix can demonstrate a violation.
-
A Liveness Property for Eventual Work
A liveness claim can say that an accepted request will eventually reach a specified outcome under stated assumptions.
-
Using an Implication with a Preconditions Check
A precondition can establish facts useful for later reasoning. Its direction matters when using it to justify an operation.
-
Equivalent Results for Two Pure Rules
Two pure implementations can be compared by checking whether their output agrees for every input in the stated domain.
-
Representing Allowed States with Types
A data type can encode distinct alternatives and require each to carry the fields meaningful for that state.
-
Checking Exhaustiveness After Adding a Variant
An exhaustive match handles every currently allowed form. Adding a new variant can reveal callers needing a decision about that case.
-
What Changes When Two Quantifiers Swap
Changing the order of existential and universal quantifiers can change whether one shared witness suffices or each item can have its own.
-
A Countermodel with Two Boolean Flags
A countermodel for entailment is a valuation where the premises hold and the claimed conclusion fails.
-
Two Constraints Can Describe an Empty Range
Constraints on the same quantity can be individually satisfiable while no value satisfies them together.
-
An Abstraction Can Lose a Relationship Between Variables
Summarizing variables separately can preserve individual ranges while forgetting which combinations are possible together.
-
A Worklist Check on a Small Dependency Graph
When checking reachability or propagating facts, a worklist retains pending nodes. Processing can add later work depending on what changed.
-
What a Property Test Establishes
A property test checks a specified relation on selected instances. A general proof establishes a claim over every input covered by its assumptions.
-
Representing Two Workers by Interleavable Steps
A model of concurrent work should specify which steps are atomic and which can be ordered differently between workers.
-
Choosing Assertions from a Useful Interface Contract
Assertions used in a proof or analysis should capture the observable requirements and the facts needed to establish them.
-
Reviewing a State Model with an Example Trace
A small ordinary trace can show whether a model has the same transitions and observable distinctions as the intended workflow.
-
Stating Assumptions Alongside a Correctness Claim
A correctness result depends on the assumed input set, execution model, and required observations. State them near the claimed property.