FunctorialAcademySign in

Functorial Academy · Advanced

Specification Engineering

Say what a C function and its RISC-V binary must do, in Lean 4, tightly enough to hand the proof to an AI.

You write the specification. An AI writes the proof, or finds the counterexample. Lean checks both. This course is about the part that stays yours: saying what correct means, tightly enough that a wrong program cannot satisfy it. You specify functions on machine words, C functions with undefined behavior, loops, and the RISC-V words a real compiler emitted, and every specification is tested against buggy variants of the program. By the end you hand compiled loops to the AI with one-line statements, and you know what the checked proof does and does not tell you.

Start freeEnter your email and we send you a six-digit code. No password. A new address gets a new account.
  • 8 units
  • 90 exercises
  • Checked by real Lean 4
  • Free

The path

For people who have finished an introductory course here: you can read Lean and write small definitions and tactic proofs. You know C and have seen assembly. No formal methods background is assumed.

  1. What a specification is. A specification is a proposition about a program. A good one is satisfied by the right program and by no wrong one.
  2. Machine integers. A C unsigned is not a natural number. Specifications about programs are written over 32-bit words, where arithmetic wraps and the same bits can be read as signed or unsigned.
  3. MiniC and undefined behavior. A C function can do something worse than return the wrong value: it can leave the language. A specification has to say that it doesn't.
  4. Loops, fuel and termination. A loop can run forever, and a definition in Lean cannot. Fuel is how the model squares the two, and it changes what a specification of a loop has to say.
  5. RISC-V: the machine. The C compiler is not the end of the line. What runs is machine code, and Lean can hold a model of the machine as easily as a model of C.
  6. Specifying binaries. The specifications you wrote for functions on words apply unchanged to compiled code. The mutants are now single instruction words.
  7. One specification, two targets. The same statement can be asked of the source and of the binary. And once a function writes to memory, the statement has to say what it leaves alone.
  8. The handoff. You write the statement. The AI writes the proof or the counterexample. Lean checks what comes back. This unit is about what that arrangement does and does not give you.
Start freeEnter your email and we send you a six-digit code. No password. A new address gets a new account.