Program Synthesis

Program synthesis searches a defined language for an implementation that meets a specification. Counterexamples gradually turn universal correctness into constraints on the search.

Source
Anbloq
Language
English
Created
Updated
Chapters
3
Reading time
2 min
In this article3 chapters
  1. Grammar and semantics jointly specify a task
  2. Counterexamples remove entire classes of guesses
  3. Termination and verification have distinct premises

Grammar and semantics jointly specify a task

A syntax-guided instance supplies a grammar \(G\) for candidate programs and a semantic relation \(\varphi\). The desired result satisfies

\[ \exists f\in G\quad\forall x\quad \varphi(f,x). \]

The grammar can exclude a mathematically valid but unwanted answer. It can also make a specification unrealizable in the chosen language. A program sketch fixes some structure and leaves selected expressions or constants as holes. Both forms make the search space part of the problem definition.

An invariant template gives a small candidate space in which a failure can rule out a proposed solution. Verification conditions state the obligations independently of how a candidate was generated.

Counterexamples remove entire classes of guesses

For a function that clamps negative integers to zero, first trying the identity satisfies all nonnegative examples. A negative input refutes it. The constant zero then handles that counterexample but fails on a positive input. A grammar with an order test and a conditional can express the intended behavior. In CEGIS the synthesis phase finds a candidate on the current finite sample. The verification phase asks whether the negation of the specification has any input for that candidate. Such an input enlarges the sample and excludes every candidate that would fail on the same case.

Termination and verification have distinct premises

With a finite candidate space and exact subsolvers, each new counterexample removes at least one candidate. With an unbounded grammar, the search can keep increasing expression size. A finite sample alone proves correctness only when the verification query is discharged. Quantifier structure, theory fragments and arithmetic bit widths can determine whether that query is feasible. The verifier uses ideas from deductive program verification and SMT solving. The candidate language and cost make the approach closely related to superoptimization.[1][2]

References

  1. Rajeev Alur et al., Syntax-Guided Synthesis ↩
  2. Armando Solar-Lezama et al., Combinatorial Sketching for Finite Programs ↩