Skip to content

Program Synthesis

Generate a program from a specification.

Deductive synthesis

The spec is complete and formal, like a pre and post condition. You derive the program from it with proof rules, so the program is correct by construction.

Manna and Waldinger (1980) treat synthesis as proving \(\forall x.\ \exists y.\ \text{post}(x, y)\) constructively, and the program is read off the proof. This is the Curry-Howard idea, a proof of \(\exists y\) contains a way to compute \(y\).

Inductive synthesis

The spec is incomplete, usually input-output examples. You search for a program that agrees with all of them, and hope it generalises.

FlashFill (Gulwani, 2011) in Excel learns string transformations from a few examples you type in.

Programming by example

Programming by example (PBE) is inductive synthesis where the spec is just input-output pairs.

Input Output
John Smith J. Smith
Ada Lovelace A. Lovelace

Many programs fit a few examples, so PBE needs two things.

  • A small DSL, like FlashFill's string operations, so the search space is manageable.
  • A ranking, usually preferring the simplest program, to pick the one you probably meant.

PROSE (Polozov and Gulwani, 2015) is Microsoft's framework for building PBE tools for a given DSL. Programming by demonstration is the variant where you show the steps, not just the input and output.

CEGIS

Counterexample-Guided Inductive Synthesis combines the two. The spec is formal, but you search like inductive synthesis, using a verifier to supply new examples.

  1. Synthesise. Find a program that works on the current examples.
  2. Verify. Check it against the full spec. If it passes, stop.
  3. Learn. Otherwise, add the counterexample input to the examples, and go back to 1.

It's the same loop as CEGAR, but the candidate is a program instead of an abstraction. Sketch (Solar-Lezama, 2006) introduced it, where you write a program with holes and CEGIS fills them in.

Note

SyGuS (Alur et al., 2013) standardises the problem, a logical spec plus a grammar the program has to come from.