CounterExample Guided Neural Synthesis

Elizabeth Polgreen, Ralph Abboud, Daniel KroeningarXiv 2020

Introduction

Program synthesis aims to automatically generate code from specifications. Traditionally, this field is split between formal methods and neural networks. Formal methods, such as SMT solvers, provide mathematical guarantees but struggle with scalability and finding specific constants. Neural networks (NNs) excel at pattern recognition and "guessing" code from examples but often produce solutions that fail on edge cases.

The core challenge lies in the "semantic gap": NNs typically require input-output (I/O) examples, whereas many real-world problems are defined by logical specifications. This paper introduces CEGNS, a framework that bridges this gap by using an SMT solver to provide corrective examples to a neural network in an iterative loop.

Methodology

The CEGNS Framework

The authors propose two primary algorithms:

  1. Example Guided Neural Synthesis (EGNS): A one-shot approach where an SMT solver generates initial I/O examples from a logical specification. These are fed to a neural network to predict a candidate program, which is then verified by the SMT solver.
  2. CounterExample Guided Neural Synthesis (CEGNS): An iterative refinement loop. If the SMT verifier finds the candidate program incorrect, it generates a counterexample—an input where the program fails. This counterexample is converted into a new I/O example and added to the training set for the next iteration.
The CEGNS iterative loop between synthesis and verification.

Neural Architecture

The synthesis engine uses a sequence-to-sequence model based on Long Short-Term Memory (LSTM) cells. The architecture consists of an Input Encoder that processes the input arguments of the I/O examples, an Output Encoder for the corresponding output values, and a Synthesis Decoder that generates program tokens (e.g., bvadd, bvgt) based on the encoded examples.

The LSTM-based sequence-to-sequence architecture for program synthesis.

To improve reliability, the system employs Beam Search to generate the top 100 candidate programs, filtering them against current I/O examples before final verification by the SMT solver.

Datasets and Training

Due to the lack of large-scale program synthesis benchmarks, the authors generated a synthetic dataset of 32 million bit-vector programs. After pruning equivalent mutants and trivial programs using SMT solvers, a final training set of ~29.4 million programs was used. Evaluation was conducted on loop invariant problems from the SyGuS (Syntax-Guided Synthesis) competition and safety invariants for C programs.

Key Insights and Results

  • Informative Counterexamples: The iterative CEGNS loop nearly doubled the performance of the one-shot EGNS (21 vs 12 benchmarks solved). Counterexamples act as highly informative "teachers," forcing the model to refine its logic where it previously failed.
  • Competitive Performance: CEGNS performed comparably to standard symbolic CEGIS implementations. While it did not surpass state-of-the-art solvers like CVC4, it solved a distinct subset of problems, suggesting that neural synthesis explores different regions of the search space.
  • Solution Quality: Unlike traditional solvers that often produce complex, bloated formulas, the neural network tended to generate shorter, more human-readable solutions.

Limitations and Future Work

The current implementation is constrained to bit-vector logic and would require retraining for other theories like linear integer arithmetic. Furthermore, the authors suggest that replacing the LSTM architecture with more modern components, such as Transformers or Attention mechanisms, could significantly enhance the model's predictive power. Scaling to full software synthesis remains a major challenge due to the exponential growth of the search space.

Summary updated

BibTeX
@misc{polgreen2020counterexample,
  author = {Elizabeth Polgreen and Ralph Abboud and Daniel Kroening},
  title = {{CounterExample Guided Neural Synthesis}},
  year = {2020},
  eprint = {2001.09245},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2001.09245},
}
Figure