Formal specifications
What Are Formal Specifications?
Formal specifications are precise mathematical descriptions of the intended behavior of a software or hardware system, written in a notation with a well-defined syntax and semantics. Unlike informal requirements documents, a formal specification can be analyzed by automated tools to detect internal inconsistencies, checked against an implementation to confirm conformance, and used as the starting point for deriving test cases or proofs of correctness. The practice draws on mathematical logic, set theory, and type theory, and the principal specification languages include Z notation, the Vienna Development Method (VDM), B, Alloy, and various temporal logics. Formal specifications have achieved the deepest industrial penetration in safety-critical domains where the cost of undetected behavioral errors is high.
The distinction between a formal specification and a formal verification is that the specification describes what a system should do, while verification establishes whether an implementation or design satisfies that description. The two activities are complementary and typically appear together in a formal methods development process.
Model-Based Specification Methods
Model-based specification methods describe a system by defining a mathematical model of its state and the operations that modify it. Z notation represents the system state as a set of typed variables and specifies operations as schemas that constrain the relationship between before-state and after-state values. VDM uses a similar approach with an explicit distinction between the abstract model and a concrete implementation, supporting a refinement discipline in which the specification is incrementally transformed into executable code while preserving behavioral properties. B and its successor Event-B extend this approach with proof obligations that must be discharged to demonstrate that each refinement step is correct. Research on invariants, frames, and postconditions comparing VDM and B notations published in IEEE Transactions on Software Engineering analyzes the differences in expressiveness and tooling support between these two widely used model-based formalisms.
Behavioral Specification Languages
Behavioral specification languages focus on the dynamic properties of systems, describing how they respond to sequences of events over time rather than just their state at a single moment. Temporal logics including Linear Temporal Logic (LTL) and Computation Tree Logic (CTL) express properties such as safety (something bad never happens), liveness (something good eventually happens), and fairness constraints over sequences of states. Process algebras including CSP and CCS specify concurrent systems by composing communicating processes, allowing deadlock and livelock conditions to be detected by model checking. Alloy uses a relational logic and provides an automatic analyzer that finds counterexamples to stated assertions within bounded scopes, making it accessible for early-stage design analysis. An ACM Computing Surveys paper on using formal specifications to support testing surveys how behavioral specifications in LTL, Z, and algebraic formalisms are automatically translated into test suites.
Specification and Verification Integration
The integration of formal specification with formal verification connects the description of intended behavior to automated proof of its satisfaction. Refinement-based approaches allow a high-level specification to be progressively lowered to an implementation while discharging proof obligations at each step, as practiced in the development of the seL4 microkernel and the CompCert verified C compiler. Service-oriented systems engineering applies formal specifications to the interface contracts of distributed services, ensuring that composed services satisfy end-to-end behavioral requirements that no single service specifies alone. IEEE standards such as those governing the specification and design of safety-critical software mandate formal or semi-formal notation for requirements at the highest integrity levels. An IEEE Xplore paper on deriving formal specifications using Z notation illustrates the workflow from natural-language requirements to a verifiable Z specification in an industrial engineering context.
Applications
Formal specifications have applications in a wide range of disciplines, including:
- Safety-critical aerospace and avionics software certification
- Medical device firmware development under regulatory quality requirements
- Service-oriented systems engineering and distributed API contract definition
- Cryptographic protocol design and security property verification
- Hardware IP block specification and automated RTL verification