CSE507
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Program Synthesis
CSE507 Computer-Aided Reasoning for Software Program Synthesis - - PowerPoint PPT Presentation
CSE507 Computer-Aided Reasoning for Software Program Synthesis courses.cs.washington.edu/courses/cse507/14au/ Emina Torlak emina@cs.washington.edu Today Last lecture Angelic nondeterminism and execution Today Program synthesis:
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Program Synthesis
Today
2Last lecture
Today
Announcements
Computers programming computers?
3“Information technology has been praised as a labor saver and cursed as a destroyer of
computing rests on a fundamental irony: the software that makes it all possible is, in a very real sense, handmade. Every miraculous thing computers can accomplish begins with a human programmer entering lines of code by hand, character by character.” Interview with Moshe Vardi
Program synthesis aims to automate (tedious parts
The program synthesis problem
4∃ P . ∀ x. φ(x, P(x))
Find a program P that meets the input/output specification φ. φ may be a formula, a reference implementation, input/output pairs, traces, demonstrations, etc. Synthesis improves
writing φ is easier than writing P).
verifying φ is easier than verifying P).
Synthesis as a problem in machine learning. Inductive (syntax-guided) synthesis Discover the program P by searching a restricted space of candidate programs for one that meets φ on all inputs. Synthesis as a problem in deductive theorem proving. Deductive (classic) synthesis Derive the program P from the constructive proof of the theorem ∀ x. ∃ y. φ(y, x).
Two kinds of program synthesis
5∃ P . ∀ x. φ(x, P(x)) FlashFill SPIRAL
∀ k, n. 2n = 2**n ∀ k, n. k*2n = k << n ∀ k, n. k*4 + n = s4addl(k, n) …
Deductive synthesis with axioms and E-graphs
6reg6 * 4 + 1 s4addl(reg6, 1)
Complete specification φ
reference implementation in an ISA). Optimal (lowest cost) program P that is equivalent to φ on all inputs (values of reg6). Denali Superoptimizer [Joshi, Nelson, Randall, PLDI’02] Two kinds of axioms:
and relations used for specifying instruction semantics.
search the E-graph for a K-cycle program.
Denali by example
7∀ k, n. 2n = 2**n ∀ k, n. k*2n = k << n ∀ k, n. k*4 + n = s4addl(k, n) …
reg6 * 4 + 1
E-graph matching SAT
s4addl(reg6, 1) reg6 * 4 + 1 2 * 2 2 << s4addl
Deductive synthesizer
for one that yields an optimal program. Compiler
using a fixed sequence of rewrites.
Deductive synthesis versus compilation
8reg6 * 4 + 1 2 * 2 2 << s4addl reg6 * 4 + 1 reg6 << 2 + 1
Deductive synthesis versus inductive synthesis
9Inductive synthesis
specifications.
efficiency and weaker (bounded) guarantees on the correctness/
Deductive synthesis
to the semantics-preserving rules,
seed the derivation.
the domain.
∃ P . ∀ x. φ(x, P(x))
Inductive syntax-guided synthesis
10CEGIS: Counterexample-Guided Inductive Synthesis [Solar-Lezama et al, ASPLOS'06]
expr := const | reg6 | s4addl(expr, expr) | …
A partial or multimodal specification φ of the desired program (e.g., assertions, i/o pairs).
reg6 * 4 + 1
A syntactic sketch (e.g., a grammar) describing the shape of the desired program P . This defines the space of candidate programs to search. Can be fine- tuned for better performance.
s4addl(reg6, 1)
A program P from the given space of candidates that satisfies φ on all (usually bounded) inputs. Solves ∃ P . φ(x1, P(x1)) ∧ … ∧ φ(xn, P(xn)) for representative inputs x1, …, xn.
Searches for an input xi+i on which P violates φ. Usually a solver, but can be a test suite, end-user, etc.
Overview of CEGIS
11Specification φ Sketch S Synthesizer Verifier Fail P no counterexample P ∈ S s.t. ⋀i φ(xi, P(xi)) Searches for a program P ∈ S that satisfies φ on all inputs xi seen so far. xi+1 Form of active learning (a special case of machine learning). Any search algorithm: e.g., a solver, enumerative search, stochastic search.
Solver-based synthesis
fresh symbolic constant.
problem to constraints w.r.t. the current inputs.
to a c program P .
Inductive synthesis with a solver
12x << ?? x * 4 0, 1, 2
(0 << n = 0) ∧ (1 << n = 4) ∧ (2 << n = 8) n Logical encoding of the synthesis problem for the inputs 0, 1, 2.
x << 2
[Solar-Lezama et al, ASPLOS'06]
Enumeration-based synthesis A candidate program consistent with current inputs.
programs of size K until
the current inputs.
the same output on all current inputs, keep just
Inductive synthesis with enumerative search
13x * 4 0, 1, 2
K=1: 0
expr := 0 | 1 | 2 | x | expr << expr
K=1: 0, 1, 2, x K=2: 1 << 2, 2 << 2, x << 1, x << 2 [Udupa et al, PLDI'13]
Stochastic synthesis
to sample expressions.
candidate program and keep the mutation with probability proportional to its correctness w.r.t. the current inputs.
Inductive synthesis with stochastic search
14A candidate program consistent with current inputs.
x * 4 0, 1, 2 expr := 0 | 1 | 2 | x | expr << expr
[Schkufza et al, ASPLOS'13]
Summary
15Today
and stochastic search Next (and final) lecture