What is a formal specification?

Definition

A formal specification translates requirements into a language with defined mathematical meaning. It can describe permitted states, function behavior, invariants, preconditions and postconditions so verification tools can reason about them without relying on ambiguous prose.

Writing the specification is a critical human responsibility because every later proof depends on it. A perfectly verified implementation can still solve the wrong problem when the specification is incomplete, so teams should review and test the specification against real intent.

ELI5

A formal specification describes required system behavior with precise mathematical rules. It defines allowed inputs, outputs, states and conditions without relying on ambiguous ordinary language.

For example, a payment specification can state that a balance never decreases unless an authorized transaction succeeds. People must review the specification carefully because a proof can be perfectly correct while proving the wrong requirement.

Can a formal specification be written from natural language?

A tool can help translate natural language into a formal statement, but people must review the result because subtle changes can alter the property being proved.

What does a formal specification contain?

It can contain definitions, input assumptions, required outputs, invariants, allowed state transitions and conditions that must hold before and after an operation.

  1. Varun Pant beside the words Prove the Code
Definition card for formal specification: What is a formal specification?

A formal specification is a precise mathematical description of a system's required behavior, inputs, outputs and constraints.