Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 20 · Thu 03/12/2026 · Schedule buffer: applications (program synthesis), finish theory combination, project office hours (Caroline Trippel). Reading: none listed. Basis: No slides are public for this session. Theory combination is covered in Lecture 18. This lecture is written from:
- Solar-Lezama et al. (ASPLOS 2006) and Solar-Lezama’s thesis (2008): sketching and CEGIS;
- Alur et al. (FMCAD 2013): syntax-guided synthesis (SyGuS);
- Udupa et al. (PLDI 2013) and Albarghouthi, Gulwani and Kincaid (CAV 2013): observational equivalence;
- Alur, Radhakrishna and Udupa (TACAS 2017): EUSolver;
- Jha, Gulwani, Seshia and Tiwari (ICSE 2010): synthesis of bit-manipulating programs;
- Reynolds et al. (CAV 2015): synthesis inside an SMT solver;
- Warren’s Hacker’s Delight.
These notes add one module,
synth.py, with:
- grammars, and enumeration with observational equivalence;
- CEGIS with Lecture 16’s bit-vector solver as verifier;
- sketching, and the expansion of ∀;
- certificates for every program.
A closing script runs one problem through every solver the course built. The experiments were designed for these notes and do not reflect what was said in class. Code:
code/lecture20/(3 scripts + 1 module; Python standard library only; about 3 to 7 seconds of CPU time each) Reading time: 2 hours including running the code
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- State program synthesis as an ∃∀ problem, and say why the quantifier alternation makes it hard.
- Write a syntax-guided synthesis problem: a grammar of allowed programs and a specification.
- Run bottom-up enumeration with observational equivalence by hand, and explain why its pruning is safe in a CEGIS loop.
- Explain CEGIS: synthesizer, verifier, counterexamples. Say why it converges quickly in practice, and connect it to Lecture 17’s model-based instantiation.
- Use sketches: holes filled by a solver. Prove that a sketch is impossible.
- Place every solver of the course on one map, and explain what each one’s certificate is.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed elsewhere |
|---|---|---|
| bit-vectors, bit-blasting, DRUP (Lectures 5, 16) | synthesis, grammars, CEGIS, sketches | — |
| quantifier instantiation, MBQI (Lecture 17) | CEGIS as lazy instantiation of ∀ | — |
| counterexample databases, generate-and-verify (Lecture 19) | the verifier as teacher | LLM-based generation (outside this course) |
0.3 Map
§1 synthesis: from checking to inventing
§2 specifications and grammars (SyGuS)
§3 enumeration with observational equivalence ← code 01
§4 CEGIS: the verifier as teacher ← code 01
§5 sketching: the solver fills holes ← code 02
§6 synthesis in practice (overview)
§7 the course in review ← code 03
§8 summary §9 common pitfalls §10 exercises §11 further reading
0.4 Notation
| Symbol | Meaning |
|---|---|
| the synthesis problem: a program meeting spec on every input | |
| a grammar: the programs allowed | |
| the current finite set of example inputs | |
| signature of | the tuple of its outputs on the examples |
| , | logical and arithmetic right shift (8-bit) |
| , | bitwise complement, two’s-complement negation |
0.5 The code of this lecture
One module, synth.py:
- programs:
evaluate,to_bv,show,size; - problems:
Grammar,Spec,equals_reference; - enumeration:
enumerate_programs; - CEGIS:
cegis,verify,exhaustive_check,random_examples_synthesis; - sketching:
Sketch,sketch_cegis,sketch_all_inputs; - benchmarks:
BENCHMARKS.
The verifier is Lecture 16’s bit-blaster with Lecture 5’s CDCL. Its UNSAT answers carry checked DRUP proofs.
1. Synthesis: from checking to inventing
Every earlier lecture asked a solver to check something. Is this formula satisfiable? Is this circuit’s output always correct? Do these two queries agree on every database? Synthesis asks it to invent a program that is correct:
An example. Find such that for all 8-bit unsigned , without the overflow of (Lecture 16). Hacker’s Delight’s answer is : the common bits, plus half the differing ones.
Why it is hard.
- The quantifier alternation. ranges over programs, an infinite space; ranges over all inputs. Lecture 17 showed that is where solvers struggle, and here it sits under an existential over functions.
- Undecidability. In general the problem is undecidable.
- The search space. Even over finite inputs and a bounded program size, the space of programs grows exponentially with size (§3).
A short history.
- Church’s problem (1957). Synthesize a circuit from a logical specification.
- Deductive synthesis (Manna and Waldinger, 1980). Extract the program from a constructive proof of .
- Superoptimization (Massalin, 1987). Enumerate machine-code sequences and test them.
Today’s methods. Today’s methods are inductive: they generalize from examples and use a solver to check and to find counterexamples. Two ideas make this work, and they are the subject of this lecture:
- the syntactic restriction of the program space (SyGuS);
- the counterexample-guided loop (CEGIS).
2. Specifications and grammars (SyGuS)
2.1 The two parts of a problem
A syntax-guided synthesis problem (Alur et al. 2013) has two parts:
- a specification : a formula in a background theory, here bit-vectors;
- a grammar : the programs allowed.
Specifications come in two kinds:
- Reference implementation: , for example . This asks for a different (smaller, faster) program with the same behavior.
- Relational: a property, for example for the maximum . No program is given.
Grammars. The benchmark grammars are:
BITS S -> x | 0 | 1 | S op S, op in {+, -, &, |, ^}, | ~S | -S (one input)
BITS2 S -> x | y | 0 | 1 | S op S, op in {+, -, &, |, ^, >>} | ~S (two inputs)
SHIFTS BITS plus >>, >>s and the constant 7
CHOICE S -> x | y | 0 | 1 | ite(B, S, S); B -> S <s S | S <u S | S = S
The grammar is part of the problem. It keeps the search small and expresses what kind of answer is wanted, for example “branch-free”.
2.2 The benchmarks
| specification | kind | known solution |
|---|---|---|
| turn off the rightmost 1-bit | reference | |
| isolate the rightmost 1-bit | reference | |
| right-propagate the rightmost 1-bit | reference | |
| isolate the rightmost 0-bit | reference | |
| average without overflow | reference, 9-bit sum | |
| absolute value | reference | |
| signed max, signed min | relational | if-then-else |
They come from Hacker’s Delight and from Jha, Gulwani, Seshia and Tiwari’s benchmarks.
3. Enumeration with observational equivalence
3.1 Bottom-up enumeration
Generate programs by size. Start with the leaves (size 1). Then build size from smaller pieces:
- with ;
- with ;
- with .
The first program that satisfies the specification is the smallest.
The space explodes. Script 01, Part 1, uses the one-variable grammar BITS:
| programs up to size | all programs | generated with pruning | kept |
|---|---|---|---|
| 1 | 3 | 3 | 3 |
| 2 | 9 | 9 | 7 |
| 3 | 66 | 62 | 15 |
| 4 | 288 | 150 | 37 |
| 5 | 1,938 | 418 | 84 |
| 6 | 11,286 | 1,100 | 193 |
Without pruning the count grows by a factor of about 4 to 7 per extra node.
3.2 Observational equivalence
The idea. The signature of a program is its tuple of outputs on the current examples. Two programs with the same signature are interchangeable as far as the examples can tell. So the enumerator keeps only the first one, and builds bigger programs only from kept ones.
An example. With examples :
- , , and all have the signature , and only is kept;
- up to size 6, 193 of the 1,100 generated programs survive.
The pruning compounds. Every discarded program would have been combined into countless bigger ones.
Is it sound? For the question “find a program consistent with the examples”, yes. Any program built from a discarded has a twin built from the kept with the same signature.
Is it complete for correctness? No. Two programs may agree on the examples and differ elsewhere:
- (that is, ) and (that is, ) both map to ;
- but at they give 1 and 3.
The enumerator may keep the wrong one. CEGIS repairs exactly this: the verifier’s counterexample becomes an example, and the next enumeration keeps both twins apart.
4. CEGIS: the verifier as teacher
4.1 The loop
The two sides. CEGIS (Solar-Lezama et al. 2006) splits into two quantifier-free questions:
E := {an initial input}
repeat:
SYNTHESIZE: f := the smallest program in G with φ(e, f(e)) for every e in E (∃f, finitely many e)
VERIFY: is ¬φ(x, f(x)) satisfiable? (∃x, f fixed)
UNSAT -> return f (with the DRUP proof that no counterexample exists)
SAT -> the model is a counterexample input c; E := E ∪ {c}
- Synthesizer: enumeration. It never sees a quantifier.
- Verifier: bit-blasting plus CDCL. It never sees an unknown function.
The connection to Lecture 17. This is model-based quantifier instantiation, for functions: the verifier finds the instance of that the current candidate violates.
4.2 Results
Script 01, Part 2:
| specification | program found | size | rounds | programs generated | certificate |
|---|---|---|---|---|---|
| turn off rightmost 1 | x & ~-x | 5 | 4 | 261 | DRUP ok + exhaustive |
| isolate rightmost 1 | x & -x | 4 | 3 | 120 | DRUP ok + exhaustive |
| right-propagate rightmost 1 | x | ~-x | 5 | 4 | 346 | DRUP ok + exhaustive |
| isolate rightmost 0 | ~x & -~x | 6 | 4 | 1,049 | DRUP ok + exhaustive |
| average without overflow | (x & y) + ((x ^ y) >> 1) | 9 | 7 | 253,748 | DRUP ok + exhaustive |
| absolute value | (x >> 7) + (x ^ (x >>s x)) | 9 | 7 | 162,713 | DRUP ok + exhaustive |
| signed max (relational) | (x <s y ? y : x) | 6 | 3 | 47 | DRUP ok + exhaustive |
| signed min (relational) | (x <s y ? x : y) | 6 | 3 | 73 | DRUP ok + exhaustive |
Every answer is checked twice.
- The final verification is UNSAT, with a checked DRUP proof.
- An exhaustive run over all or inputs agrees, using no solver at all.
The smallest program is not always the textbook one.
- is , because in two’s complement (Exercise 2).
- For the absolute value the enumerator found . It shifts by itself, using SMT-LIB’s rule that a shift by fills with the sign bit (Exercise 3). It is correct on all 256 inputs, and nobody would write it.
Specifications define correctness, not readability. To get readable programs, restrict the grammar (no variable shift amounts) or use a sketch (§5).
4.3 One run
Script 01, Part 3, traces the average:
round 1: x -- counterexample x = 0, y = 128
round 2: y >> 1 -- counterexample x = 128, y = 0
round 3: (x + y) >> 1 -- counterexample x = 128, y = 128 (the overflow of Lecture 16)
round 4: (x >> 1) + (y >> 1) -- counterexample x = 223, y = 95 (both odd: a lost carry)
round 5: x + ((y >> 1) - (x >> 1)) -- counterexample x = 241, y = 204
round 6: y + ((x >> 1) - (y >> 1)) -- counterexample x = 204, y = 241
round 7: (x & y) + ((x ^ y) >> 1) -- verified
Each counterexample is chosen by the solver to break the current candidate. Seven examples pin down a function on 65,536 inputs.
4.4 Why it converges quickly in practice
Script 01, Part 4, compares counterexamples with random examples. The table shows, of 5 random example sets of each size, how many led to a correct program:
| specification | 1 | 2 | 4 | 8 | 16 | CEGIS: examples used |
|---|---|---|---|---|---|---|
| turn off rightmost 1 | 3/5 | 3/5 | 4/5 | 5/5 | 5/5 | 4 |
| isolate rightmost 1 | 3/5 | 4/5 | 5/5 | 5/5 | 5/5 | 3 |
| right-propagate rightmost 1 | 3/5 | 3/5 | 4/5 | 5/5 | 5/5 | 4 |
| isolate rightmost 0 | 0/5 | 2/5 | 3/5 | 3/5 | 5/5 | 4 |
| signed max | 0/5 | 4/5 | 5/5 | 5/5 | 5/5 | 3 |
Random examples need luck. They rarely hit the corner cases where small candidates differ: 0, 128, the sign bit, ties. CEGIS needs 3 or 4 examples because each one is targeted.
There is no general bound. A single counterexample can rule out only one candidate, so the worst case is one round per wrong candidate. In practice small programs are separated by few inputs, and the smallest-first order means the true answer is reached early.
Pruning inside CEGIS (Part 5): on the small benchmarks, the unpruned enumeration generates up to about five times more programs per run (1,346 against 261 for the rightmost-bit benchmark).
5. Sketching: the solver fills holes
5.1 Holes as selectors
A sketch (Solar-Lezama) is a program with holes: unknown constants or operator choices. The programmer supplies the shape. For the average:
Holes as selectors. Each hole becomes a small bit-vector selector. An operator hole becomes an if-then-else over its choices. Filling the holes so that the sketch meets the specification on the examples is a quantifier-free formula: one SAT call. So the solver is on both sides of CEGIS (script 02, Part 1):
round 1: OP1 = and, OP2 = and, C = 0 -> (x & y) + ((x & y) >> 0) -- counterexample x = 0, y = 128
round 2: OP1 = and, OP2 = xor, C = 1 -> (x & y) + ((x ^ y) >> 1) -- verified (DRUP ok; exhaustive ok)
The absolute value. The sketch is filled in 4 rounds as , the other textbook branch-free form.
5.2 Proving a sketch impossible
Restrict the average sketch’s operators to and (script 02, Part 2):
round 1: OP1 = and, OP2 = and, C = 0 -> ... -- counterexample x = 0, y = 128
round 2: OP1 = and, OP2 = or, C = 1 -> ... -- counterexample x = 128, y = 254
round 3: no hole values fit the 3 examples -- the sketch cannot do it (UNSAT, DRUP ok)
The UNSAT answer is a proof of impossibility. Every example is an input the specification constrains, so no completion of the sketch can be correct. Enumeration can only report “nothing up to size ”.
5.3 Why loop? Expanding the ∀
Expansion. Over -bit inputs the ranges over a finite set, so it can be expanded: one constraint per input, and a single SAT call. This is Herbrand instantiation over a finite universe (Lecture 17). Script 02, Part 3:
| problem | method | instances of ∀x | clauses | program |
|---|---|---|---|---|
| absolute value (8 bits) | CEGIS | 4 examples | 304 (last check) | (x + (x >>s 7)) ^ (x >>s 7) |
| expand ∀ | 256 constraints | 162,210 | the same | |
| average (4 bits) | CEGIS | 2 examples | 119 (last check) | (x & y) + ((x ^ y) >> 1) |
| expand ∀ | 256 constraints | 4,368 | the same |
The answers agree, but the expansion is exponential in the input bits. It needs 65,536 constraints for the 8-bit average and for two 32-bit inputs. CEGIS instantiates the lazily, only where a candidate fails: Lecture 17’s model-based instantiation, for programs.
5.4 Enumeration or sketching?
| specification | enumeration finds | rounds | search | sketch finds | rounds |
|---|---|---|---|---|---|
| average | (x & y) + ((x ^ y) >> 1) | 7 | 253,748 programs | the same | 2 |
| absolute value | (x >> 7) + (x ^ (x >>s x)) | 7 | 162,713 programs | (x + (x >>s 7)) ^ (x >>s 7) | 4 |
The trade-off.
- Enumeration needs only a grammar, and finds the smallest program. It pays with a search over hundreds of thousands of programs.
- Sketching needs human insight into the shape. It then searches the holes symbolically, with a few small SAT calls.
Both are syntax-guided: the grammar or sketch restricts the space, the specification defines correctness, and the verifier connects them.
6. Synthesis in practice (overview)
- SyGuS solvers. cvc5 and its predecessor CVC4 (Reynolds et al. 2015) solve SyGuS problems inside the SMT solver. They use enumeration with observational equivalence, and also quantifier instantiation on the formula. EUSolver (Alur, Radhakrishna and Udupa 2017) enumerates small terms and conditions separately, then combines them by decision-tree learning (“divide and conquer”). The SyGuS competition compares such tools on a common format.
- Programming by example. FlashFill (Gulwani 2011) synthesizes spreadsheet string transformations from a few input–output examples. Ranking chooses among the many consistent programs.
- Superoptimization. From Massalin’s exhaustive search to STOKE’s stochastic search (Schkufza, Sharma and Aiken 2013): find the shortest or fastest code equivalent to a given one. The verifier is a bit-vector solver, exactly as here.
- Language models as synthesizers. A model proposes code, and a verifier or test harness checks it and returns counterexamples. This is the loop of §4 with a neural generator. Lecture 19’s counterexample databases are one instance: the solver supplies the precise, minimal feedback that makes the loop converge, and the certificate.
7. The course in review
7.1 One problem per solver
Script 03 runs one small problem through every solver the course built, and checks every answer with independent code:
| lecture | module | decides | problem | answer | check |
|---|---|---|---|---|---|
| 1 | logic, semantic_argument | propositional validity | Peirce’s law | VALID | truth table agrees |
| 2 | cnf, resolution | resolution refutations | {1,2} {1,¬2} {¬1,3} {¬1,¬3} | UNSAT | refutation re-checked |
| 3 | proof_systems | proof-system derivations | b ⇒ c, ¬b ⇒ c, ¬c | refutation | every leaf closed |
| 4 | dpll | SAT by DPLL | the slides’ DPLL example | UNSAT | tree-like resolution proof re-checked |
| 5 | cdcl, drup_check | SAT by CDCL | pigeonhole PHP(5) (153 conflicts) | UNSAT | DRUP proof checked |
| 6–7 | fol, fol_semantics | finite models (FOL) | ∀x ∃y q(x, y) ∧ ¬∃x q(x, x) | model with 2 elements | sentences evaluated in the model |
| 7 | unify | unification | Q(a, f(y)) and Q(z, f(b)) | {y ← b, z ← a} | both sides equal under σ |
| 8 | prover | FOL by resolution | Pelletier 18 | PROVED | resolution proof re-checked |
| 9 | mc | safety: BMC, k-induction, IC3 | 4-bit counter x += 2 never reaches 1 | SAFE, invariant ¬x0 | initiation, consecution, safety by SAT |
| 10 | smt | EUF in CDCL(T) | g(a) = c ∧ (f(g(a)) ≠ f(c) ∨ g(a) = d) ∧ c ≠ d | UNSAT | lemmas + DRUP checked |
| 11 | simplex | linear real arithmetic | x + y ≤ 3 ∧ 2x − y ≤ −5 ∧ (x > 0 ∨ y > 4) | SAT | rational model evaluated |
| 12 | lia | linear integer arithmetic | 6a + 9b + 20c = 44 over ℕ | SAT a = 4, b = 0, c = 1 | integer model evaluated |
| 13 | arrays | arrays | read(write(a, i, e), j) ≠ read(a, j) ∧ i ≠ j | UNSAT | refutation ok |
| 13 | strings | strings | x·“ab” = “ba”·y ∧ |x| = 1 | SAT x = y = “b” | model checked on the constraints |
| 14 | (notes only) | symbolic execution | — | — | examples checked with Lectures 12, 16 |
| 15 | kernel | LCF proof kernel | Peirce’s law as a theorem | ⊢ ((p ⇒ q) ⇒ p) ⇒ p | proof replayed by the kernel (62 steps) |
| 16 | bitvec | bit-vectors | x + 1 > x (8 bits); (x ^ y) ^ y = x (32 bits) | counterexample x = 255; valid | model ok; DRUP ok |
| 17 | quantifiers | quantifiers | P(a), ∀x. P(x) ⇒ P(s(x)), ¬P(s³(a)) | UNSAT (3 instances) | instances + lemmas + DRUP checked |
| 18 | combine | theory combination | f(f(x) − f(y)) = a ∧ f(0) > a + 2 ∧ x = y | UNSAT | per-theory lemmas + DRUP checked |
| 19 | sqlcheck | SQL query equivalence | MAX subquery vs ORDER BY … LIMIT 1 | different (2 rows) | counterexample re-run on SQLite |
| 20 | synth | program synthesis | ⌊(x + y)/2⌋ without overflow | (x & y) + ((x ^ y) >> 1) | DRUP ok + all 65,536 inputs run |
All 20 solvers run in about 2 seconds of CPU in total.
7.2 The thread
Unit I: propositional logic and SAT (Lectures 1–5).
- Truth tables are exponential. Proof systems trade search for structure: tableaux, resolution, Hilbert systems.
- DPLL searches smartly, and CDCL learns from its conflicts.
- The SAT solver of Lecture 5 runs underneath almost everything that follows, and its UNSAT answers produce DRUP proofs that a small, separate checker replays.
Unit II: first-order logic (Lectures 6–8).
- Quantifiers, structures and unification.
- Undecidability bounds what any procedure can promise.
- Resolution is refutationally complete, and Herbrand’s theorem reduces FOL to SAT, in principle.
Unit III: model checking (Lecture 9). Systems over time are SAT problems unrolled (BMC) or folded into invariants (k-induction, IC3). An invariant is a certificate checked by three SAT queries.
Unit IV: satisfiability modulo theories (Lectures 10–13).
- CDCL(T) splits work between a SAT solver and theory solvers: congruence closure, the simplex method, branch and bound, arrays, strings.
- Theory lemmas are re-checked by naive procedures, and models are evaluated on the input.
Unit V: programs and proofs (Lectures 14–15).
- Symbolic execution turns programs into solver queries.
- Proof kernels turn untrusted automation into trusted theorems.
Unit VI: more theories and their combination (Lectures 16–18).
- Bit-vectors by bit-blasting.
- Quantifiers by instantiation, which needs heuristics and an honest “unknown”.
- Theories by combination: equalities between shared variables.
Unit VII: applications (Lectures 19–20).
- Text-to-SQL checked by bounded equivalence.
- Programs synthesized by CEGIS.
- The solver acts as the teacher: its counterexamples drive the search.
7.3 What runs through all of it
One habit runs through the whole course. A solver is a search procedure; a certificate is the reason to believe its answer. The certificates of this course are:
- UNSAT: a proof replayed by small code (resolution, DRUP, an LCF kernel), with theory lemmas re-checked by naive procedures;
- SAT: a model evaluated on the original input;
- safety: an inductive invariant checked by SAT;
- differences: a counterexample re-run on an independent engine.
Several lectures found errors this way: in their own code, and in published examples, slides and gold queries. That is the practical case for automated reasoning with certificates.
8. Summary
- Synthesis is . The quantifier alternation and the space of programs make it hard. SyGuS restricts programs by a grammar.
- Bottom-up enumeration finds the smallest program. Observational equivalence keeps one program per signature on the examples: 193 of 1,100 up to size 6, out of 11,286 programs.
- CEGIS alternates a synthesizer on finitely many examples with a verifier for all inputs; counterexamples become examples. All 8 benchmarks are solved in 3–7 rounds, each certified by DRUP and by an exhaustive check.
- Counterexamples are targeted. CEGIS uses 3–4 examples where random examples often mislead with 1 or 2. CEGIS is lazy instantiation of , Lecture 17’s MBQI for programs. Expanding over all inputs works but is exponential in the input bits.
- Sketches put the solver on both sides of CEGIS: holes become selectors, and an UNSAT hole-filling call proves the sketch impossible.
- The course built every solver it used, from truth tables to synthesis, and every answer of every solver can be checked by independent code.
9. Common pitfalls
- Trusting a program that fits the examples. Without a verifier, it is a guess.
- Specifications that say too little. “out ≥ x ∧ out ≥ y” alone admits 127; a relational spec must pin down the answer.
- Grammars that are too big or too small. Too big and enumeration drowns. Too small and the answer is not in it; a sketch makes this provable.
- Expecting readable output. The smallest program in a grammar can be strange (
x >>s x). Restrict the grammar to what you want to read. - Forgetting the verifier’s semantics. Shifts by , overflow, signed vs unsigned. The synthesizer will exploit every corner of the semantics the verifier uses.
10. Exercises
1. (CEGIS by hand) Run CEGIS for “isolate the rightmost 1-bit” () on grammar BITS, starting from . Which candidates and counterexamples do you expect?
Answer
The run. The smallest program consistent with is itself (size 1, enumerated first). The verifier refutes it with some that has more than one bit set; cegis reports .
The next smallest program consistent with is , since on 8 bits. It is refuted by , where .
Then (size 4) is consistent with and verified: three rounds, as cegis reports.
2. (two’s complement) Prove that and on -bit vectors. Deduce that the synthesized and are the textbook programs.
Answer
The identity. In two’s complement (all bits flipped is ).
The two rules.
- .
- .
So and .
3. (a strange absolute value) Explain why computes (two’s complement) on all 8-bit .
Answer
(negative). . The shift amount , so fills with the sign bit: all ones. Then , and .
. The shift fills with the sign bit 0, so , plus 0.
. , because . The result is .
. The result is 0. The exhaustive check confirms all 256 cases.
4. (observational equivalence) With examples , show that and have the same signature but are different functions. What does CEGIS do if the enumerator keeps the wrong one?
Answer
The two functions. , so the first is . The second is .
The same signature. On 3, 12, 200 both give 3, 14, 202: 3 is odd, so and ; 12 and 200 are even, so , plus 1, equals because bit 1 is 0.
Different functions. At they give 1 and 3.
What CEGIS does. If the kept one is wrong, the verifier returns a distinguishing input, for example 1, and the next enumeration separates them.
5. (an impossible sketch) For the average sketch with and , check that every one of the 16 completions fails on one of the inputs or .
Answer
On the average is 64, and , .
- gives : all 8 such completions fail.
- With , the result is . gives 0, which fails for every . gives , which is 64 only for .
The survivor is . On it gives , while the average is 191.
This matches the script’s run, and the final UNSAT call is the solver’s proof of the same fact.
6. (expansion vs CEGIS) How many constraints does expanding need for inputs of bits? For which sizes is expansion still reasonable?
Answer
The count. : 256 for one 8-bit input or two 4-bit inputs, 65,536 for two 8-bit inputs, for two 32-bit inputs.
When it is reasonable. Each constraint copies the sketch’s circuit: 162,210 clauses already for the 8-bit absolute value. Expansion is reasonable up to a few thousand instances. Beyond that only lazy instantiation (CEGIS) works.
7. (specifications) Weaken the maximum’s specification to , dropping . What does CEGIS return with grammar CHOICE, and what if the constant 127 is added to the grammar?
Answer
With CHOICE. The constants are only 0 and 1, and there is no arithmetic, so no constant is every input. CEGIS returns the maximum after 3 rounds: and are refuted first, by and .
With 127 in the grammar. The third round returns the constant 127, which is every 8-bit signed value, and it is verified. The weakened specification was satisfied, but not as intended.
The lesson. A specification that leaves freedom invites the synthesizer to use it. Both runs were made with cegis.
8. (programming) Add max of three with a relational specification to BENCHMARKS (grammar CHOICE). How far does enumeration get? Then write a sketch and compare.
Answer sketch
Enumeration. The smallest max-of-three program has two nested if-then-else levels, 16 nodes. Expect enumeration with observational equivalence to slow down sharply: it must build every distinct condition and branch up to that size.
The sketch. It fixes the nesting and leaves only the comparisons and branches as holes: a few SAT calls. This is the typical case where a human’s shape makes synthesis feasible.
9. (programming) Implement EUSolver’s divide-and-conquer idea for CHOICE. Enumerate small terms until every example is covered by some term that is correct on it. Enumerate small conditions. Combine them into an if-then-else that sends each example to a correct term. Test it on signed max and min.
Answer sketch
What the two enumerations find. Terms and each cover part of the examples. The condition separates the two parts.
The combination. The resulting decision tree is found without enumerating if-then-else terms at all. The verifier then checks it as usual.
11. Further reading
- A. Solar-Lezama, L. Tancau, R. Bodík, S. Seshia, V. Saraswat, “Combinatorial Sketching for Finite Programs”, ASPLOS 2006; A. Solar-Lezama, Program Synthesis by Sketching, PhD thesis, UC Berkeley, 2008.
- R. Alur, R. Bodík, G. Juniwal, M. M. K. Martin, M. Raghothaman, S. A. Seshia, R. Singh, A. Solar-Lezama, E. Torlak, A. Udupa, “Syntax-Guided Synthesis”, FMCAD 2013.
- A. Udupa, A. Raghavan, J. V. Deshmukh, S. Mador-Haim, M. M. K. Martin, R. Alur, “TRANSIT: Specifying Protocols with Concolic Snippets”, PLDI 2013.
- A. Albarghouthi, S. Gulwani, Z. Kincaid, “Recursive Program Synthesis”, CAV 2013.
- R. Alur, A. Radhakrishna, A. Udupa, “Scaling Enumerative Program Synthesis via Divide and Conquer”, TACAS 2017.
- S. Jha, S. Gulwani, S. A. Seshia, A. Tiwari, “Oracle-Guided Component-Based Program Synthesis”, ICSE 2010.
- A. Reynolds, M. Deters, V. Kuncak, C. Tinelli, C. Barrett, “Counterexample-Guided Quantifier Instantiation for Synthesis in SMT”, CAV 2015.
- S. Gulwani, “Automating String Processing in Spreadsheets Using Input-Output Examples”, POPL 2011.
- H. Massalin, “Superoptimizer: A Look at the Smallest Program”, ASPLOS 1987; E. Schkufza, R. Sharma, A. Aiken, “Stochastic Superoptimization”, ASPLOS 2013.
- Z. Manna, R. Waldinger, “A Deductive Approach to Program Synthesis”, ACM TOPLAS 2(1), 1980.
- H. S. Warren, Hacker’s Delight, 2nd ed., 2012.
- S. Gulwani, O. Polozov, R. Singh, “Program Synthesis”, Foundations and Trends in Programming Languages 4(1–2), 2017 (a survey).