1 Introduction
-
We propose CEGIS(\(\mathcal {T}\)), a program synthesis architecture that facilitates the communication between an inductive synthesizer and a solver for a first-order theory, resulting in an efficient exploration of the search space.
-
We present two exemplars of this architecture, one based on Fourier-Motzkin (FM) variable elimination [7] and one using an off-the-shelf SMT solver.
-
We have implemented CEGIS(\(\mathcal {T}\)) and compared it against state-of-the-art program synthesizers on benchmarks that require intricate constants in the solution.
2 Preliminaries
2.1 The Program Synthesis Problem
2.2 CounterExample Guided Inductive Synthesis
2.3 DPLL(\(\mathcal {T}\))
3 Motivating Example
4 CEGIS(\(\mathcal {T}\))
4.1 Overview
-
The CEGIS architecture (enclosed in a red rectangle) deduces the candidate solution \(P^*\), which is provided to the theory solver.
-
The theory solver (enclosed in a blue rectangle) obtains the skeleton \(P^*[ \textsf {?}]\) of \(P^*\) and generalises it to \(P^*[{\varvec{v}}]\) in the box marked constant removal. Subsequently, Deduction attempts to find a constraint over \({\varvec{v}}\) describing those values for which \(P^*[{\varvec{v}}]\) is a final solution. This constraint is propagated back to CEGIS. Whenever there is no valuation of \({\varvec{v}}\) for which \(P^*[{\varvec{v}}]\) becomes a final solution, the constraint needs to block the current skeleton \(P^*[ \textsf {?}]\).
-
CEGIS synthesis phase: checks the satisfiability of \(\forall {\varvec{x}}_{ inputs }.\, \sigma (P, {\varvec{x}}_{ inputs })\) where \({\varvec{x}}_{ inputs }\) is a subset of all possible \({\varvec{x}}\) and obtains a candidate solution \(P^*\). If this formula is unsatisfiable, then the synthesis problem has no solution.
-
CEGIS verification phase: checks whether there exists a concrete counterexample for the current candidate solution by checking the satisfiability of the formula \(\lnot \sigma (P^*, {\varvec{x}})\). If the result is UNSAT, then \(P^*\) is a final solution to the synthesis problem. If the result is SAT, a concrete counterexample \({\varvec{cex}}\) can be extracted from the satisfying assignment.
-
Theory solver: if \(P^*\) contains constants, then they are eliminated, resulting in the \(P^*[ \textsf {?}]\) skeleton, which is afterwards generalised to \(P^*[{\varvec{v}}]\). The goal of the theory solver is to find \(\mathcal {T}\)-implied literals and communicate them back to the CEGIS part in the form of a constraint, \(C(P, P^*, {\varvec{v}})\). In Algorithm 1, this is done by \( Deduction (\sigma , P^*[{\varvec{v}}])\). The result of \( Deduction (\sigma , P^*[{\varvec{v}}])\) is of the following form: whenever there exists a valuation of \({\varvec{v}}\) for which the current skeleton \(P^*[ \textsf {?}]\) is a final solution, \( res = true \) and \(C(P, P^*, {\varvec{v}})=\bigwedge _{i=1{\cdot }n} v_i=c_i\), where \(c_i\) are constants; otherwise, \( res = false \) and \(C(P, P^*, {\varvec{v}})\) needs to block the current skeleton \(P^*[ \textsf {?}]\), i.e., \(C(P, P^*, {\varvec{v}})=P[ \textsf {?}] \ne P^*[ \textsf {?}]\).
-
CEGIS learning phase: adds new information to the problem specification. If we did not use the theory solver (i.e., the candidate \(P^*\) found by the synthesizer did not contain constants or the problem specification was out of the theory solver’s scope), then the learning would be limited to adding the concrete counterexample \({\varvec{cex}}\) obtained from the verification phase to the set \({\varvec{x}}_{ inputs }\). However, if the theory solver is used and returns \( res = true \), then the second element in the tuple contains valuations for \({\varvec{v}}\) such that \(P^*[{\varvec{v}}]\) is a final solution. If \( res = false \), then the second element blocks the current skeleton and needs to be added to \(\sigma \).
4.2 CEGIS(\(\mathcal {T}\)) with a Theory Solver Based on FM Elimination
4.3 CEGIS(\(\mathcal {T}\)) with an SMT-based Theory Solver
5 Experimental Evaluation
5.1 Implementation
5.2 Benchmarks
5.3 Experimental Setup
-
CEGIS(\(\mathcal {T}\))-FM: CEGIS(\(\mathcal {T}\)) with Fourier Motzkin as the theory solver;
-
CEGIS(\(\mathcal {T}\))-SMT: CEGIS(\(\mathcal {T}\)) with Z3 as the theory solver;
-
CEGIS: basic CEGIS as described in Sect. 2.2;
-
CEGIS-Inc: basic CEGIS with incremental SAT solving.
Configuration |
inv
|
hackers
|
comparisons
|
other
| total | |||||
---|---|---|---|---|---|---|---|---|---|---|
# | s | # | s | # | s | # | s | # | s | |
CEGIS(\(\mathcal {T}\))-SMT | 33 | 33.1 | 4 | 2.5 | 3 | 195.5 | 16 | 14.0 | 56 | 34.1 |
CEGIS(\(\mathcal {T}\))-FM | 16 | 93.1 | 4 | 52.8 | 1 | 0.06 | 12 | 0.7 | 33 | 51.8 |
CEGIS | 16 | 31.3 | 4 | 52.0 | 1 | 0.03 | 14 | 5.3 | 35 | 22.4 |
CEGIS-Inc | 16 | 39.4 | 5 | 167.4 | 1 | 0.03 | 14 | 4.2 | 36 | 42.4 |
Multi-core | 33 | 32.5 | 5 | 92.2 | 3 | 194.7 | 16 | 3.8 | 57 | 38.3 |
CVC4 | 6 | 6.5 | 6 | 0.002 | 7 | 0.006 | 11 | 0.003 | 30 | 1.3 |
# benchmarks | 48 | 6 | 7 | 19 | 80 | |||||
CVC4 with grammar | 4 | 45.8 | 0 | 0 | 6 | 2.4 | 10 | 19.8 | ||
# benchmarks with grammar | 8 | 3 | 7 | 16 | 34 |