Table of contents
Refines
Formal definition
Refinement is a binary relation on a class of specifications :
The refinement relation is characterized by two conditions:
-
Behavior containment (soundness): every behavior permitted by is a behavior permitted by . A refinement makes a choice among the behaviors allowed by the abstract specification — it does not introduce new behaviors that did not sanction. In terms of sets of behaviors: .
-
Obligation inheritance (completeness): every obligation imposed by is inherited by . A refinement cannot drop requirements — it may only add them. If requires to be established, must establish as well.
Together these conditions define refinement as specialization: is a more specific version of — it does everything does (obligation inheritance) and nothing would prohibit (behavior containment).
The refinement preorder: is a preorder on :
- Reflexivity: (every specification refines itself; the identity refinement adds nothing)
- Transitivity: and implies (refinement composition is valid)
is not in general antisymmetric — two distinct specifications may mutually refine each other while being different representations (e.g., two equivalent programs that are not syntactically identical). The refinement equivalence iff and is the equivalence relation induced by the preorder.
Dijkstra and weakest preconditions
Edsger Dijkstra (A Discipline of Programming, 1976) introduced the weakest precondition transformer — the weakest predicate on the initial state that guarantees postcondition after executing . The weakest precondition transformer gives a complete and compositional characterization of program meaning.
The weakest precondition refinement order: iff for every postcondition :
is a refinement of iff succeeds from at least as many starting states as , for every postcondition. Equivalently: the set of states from which guarantees (its weakest-precondition set) is at least as large as ’s corresponding set. A refinement is more defined: it handles all input states that the abstract specification handles and possibly more, guaranteeing the same or stronger outcomes.
The direction: means ’s weakest-precondition set ’s — establishes in at least as many situations. The abstract specification may succeed only from restricted states; the concrete refinement extends this to all of ’s states and potentially more. The formula is not : that would require to succeed from strictly fewer states than , which is the opposite of refinement.
Monotonicity of composition: if and , then — sequential composition is monotone in refinement. This makes refinement-based development compositional: a system can be refined component by component, and the whole system’s refinement follows from the components'.
The refinement lattice: under Dijkstra’s weakest precondition model:
- Top element (, the “magic” specification): satisfied by everything — for all . The magic specification is never implementable; it forms the top of the refinement order.
- Bottom element (, abort): satisfies no postcondition — for all . Abort never terminates (or always fails); it refines everything.
- Demonic nondeterminism (meet, ): . The nondeterministic choice that is worst for the programmer: the implementation may choose either branch, and the programmer must ensure regardless.
- Angelic nondeterminism (join, ): . The nondeterministic choice that is best for the programmer: there exists a branch satisfying .
Back and von Wright: the refinement calculus
Ralph-Johan Back and Joakim von Wright (Refinement Calculus: A Systematic Introduction, 1998) developed the refinement calculus — a complete formal system for systematically deriving correct programs from abstract specifications by a sequence of refinement steps.
A specification statement specifies a program component by its precondition and postcondition : the component is correct iff, when started in a state satisfying , it terminates in a state satisfying .
The basic refinement law: iff:
(Weaken the precondition — the refinement applies to more starting states; strengthen the postcondition — the refinement guarantees more about the final state.)
Back and von Wright prove an extensive library of refinement laws — lemmas establishing when one program construct refines another. Key laws:
- Strengthen postcondition: when (stronger guarantee)
- Weaken precondition: when (more starting states covered)
- Sequential composition: (introduce a midcondition)
- Conditional introduction: (introduce guard)
A complete derivation in the refinement calculus is a proof that a concrete program refines its abstract specification: a chain .
Abadi and Lamport: specification refinement
Martín Abadi and Leslie Lamport (The Existence of Refinement Mappings, 1991) gave a model-theoretic account of specification refinement for concurrent systems:
A specification is a set of behaviors (infinite sequences of states). refines iff — every behavior of is a behavior of .
Refinement mapping: a function from states of the concrete system to states of the abstract system is a refinement mapping iff it preserves all behaviors — for every concrete behavior , (the behavior obtained by applying to each state) is a behavior of the abstract system.
Abadi and Lamport prove: refines iff there exists a refinement mapping from to (possibly with auxiliary variables — additional state tracking what the concrete system has “committed to” in terms of the abstract spec). The auxiliary-variable requirement is the key technical contribution: pure refinement mappings are not always sufficient for capturing all valid refinements; auxiliary variables track intermediate commitments.
TLA+ refinement: in TLA+ (Temporal Logic of Actions), a specification refines iff — the spec implies spec as a temporal formula. This is the strongest characterization: specification-level implication is refinement.
Hoare, He, and Sanders: data refinement
C.A.R. Hoare, He Jifeng, and J.W. Sanders (Data Refinement Refined, ESOP 1986) generalized the Back-von Wright account to handle data refinement — refinement between implementations that use different state representations:
In standard refinement, the abstract specification and the concrete implementation operate on the same state space. Data refinement relaxes this: the concrete implementation may use an entirely different concrete state space while the abstract specification uses an abstract state space .
A retrieve relation (also called an abstraction relation or coupling invariant) maps concrete states to the abstract states they represent:
Downward simulation (the sufficient condition for data refinement): data-refines via iff:
- Initialization: every initial concrete state is related by to some initial abstract state : if satisfies , there exists satisfying with .
- Correctness step: for every concrete step from to under , and every abstract state with , there exists an abstract state with such that takes to . In terms of weakest preconditions: — the concrete operation’s termination condition (via ) implies the abstract operation terminates.
Upward simulation (via ): the same conditions applied with the retrieve relation reversed. Hoare, He, and Sanders prove that downward and upward simulation together are necessary and sufficient for data refinement.
When is a function (a surjection), the retrieve relation becomes the abstraction function of abstract data types (Hoare 1972, Proof of Correctness of Data Representations, Acta Informatica). The data refinement condition then reduces to: the concrete operation commutes with — applying before or after the concrete operation gives the same abstract result. This is the precise categorical statement: (natural transformation condition on the state-transformer functors).
Data refinement is the bridge between refines and extends: when the concrete state space properly extends the abstract state space (via an inclusion ), the retrieve relation recovers standard refinement. Data refinement generalizes this to arbitrary re-representations — the concrete state can be a more efficient encoding, a lower-level structure, or a completely different representation that happens to implement the same observable behavior.
Open questions
- Whether the refinement preorder is always a partial order (antisymmetric up to observational equivalence) for the behavior-containment formulation, or whether there are specifications with and that are genuinely observationally distinct.
- Whether the refinement calculus of Back and von Wright can be embedded into the topos — whether specification statements are morphisms in the topos, whether refinement is the factorization order on those morphisms, and whether the refinement laws correspond to natural transformations.
- Whether data refinement (Hoare, He, and Sanders 1986) — where the concrete state space differs from the abstract — corresponds to refinement in the coalgebraic setting: a simulation relation between coalgebras over different state spaces, which is what the coalgebraic account of bisimulation already provides.
- Whether the Abadi-Lamport auxiliary variable construction has a canonical categorical form — whether auxiliary variables correspond to enriching the diagram category with extra colimits that track commitments, and whether the refinement mapping theorem is a universal property in this enriched category.