Skip to content
LeanLearn
Level 4~35 minLean 4

Specifications: programs you can trust

Tests check some inputs; a proof covers all of them. Write what a program must do as a theorem, then prove that the code meets it.

You will be able to
  • Explain the difference between testing a program and proving it correct.
  • Write a specification as a theorem about an implementation.
  • Judge whether a specification is strong enough to pin down the intended behaviour.

Recommended first: Recursion and termination, Proving with ∀ and ∃. You can start anyway. Nothing is locked.

EncounterActivity 1 of 8

Encounter

A lift controller, a bank transfer, a sorting routine: we want them to be right, not just right on the inputs we happened to try.

  • A test runs the program on one input and compares the answer: maxOf 3 7 = 7.
  • A specification says what must hold for every input: "the result is at least both arguments, and is one of them".
  • A proof shows the implementation meets the specification, for all inputs at once.

In Lean all three live in the same file, and the kernel checks the proof.