cse507
play

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:


  1. CSE507 Computer-Aided Reasoning for Software Program Synthesis courses.cs.washington.edu/courses/cse507/14au/ Emina Torlak emina@cs.washington.edu

  2. Today Last lecture • Angelic nondeterminism and execution Today • Program synthesis: computers programming computers Announcements • Please fill out the course evaluation form (Dec 02-08) 2

  3. Computers programming computers? “Information technology has been praised as a labor saver and cursed as a destroyer of obsolete jobs. But the entire edifice of modern Program synthesis aims to computing rests on a fundamental irony: the automate (tedious parts software that makes it all possible is, in a of) programming. 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 3

  4. The program synthesis problem φ may be a formula, a reference implementation, input/output pairs, traces, demonstrations, etc. Synthesis improves Find a program P that . ∀ x. φ (x, P(x)) ∃ P meets the input/output • Productivity (when specification φ . writing φ is easier than writing P). • Correctness (when verifying φ is easier than verifying P). 4

  5. Two kinds of program synthesis . ∀ x. φ (x, P(x)) ∃ P FlashFill SPIRAL Inductive (syntax-guided) Deductive (classic) synthesis synthesis Synthesis as a problem in Synthesis as a problem in Derive the program P from the deductive theorem proving. machine learning. Discover the program P by constructive proof of the searching a restricted space of theorem ∀ x. ∃ y. φ (y, x). candidate programs for one that meets φ on all inputs. 5

  6. Deductive synthesis with axioms and E-graphs 1. Construct an E-graph. Complete specification φ Optimal (lowest cost) of the desired program (a program P that is 2. Use a SAT solver to equivalent to φ on all reference implementation search the E-graph for in an ISA). inputs (values of reg6). a K-cycle program. Denali Superoptimizer [ Joshi, Nelson, s 4addl(reg6, 1) reg6 * 4 + 1 Randall, PLDI’02 ] Two kinds of axioms: ∀ k, n. 2 n = 2**n • Instruction semantics. ∀ k, n. k*2 n = k << n • Algebraic properties of functions ∀ k, n. k*4 + n = s4addl (k, n) and relations used for specifying … instruction semantics. 6

  7. Denali by example s4addl << reg6 * 4 + 1 2 + * 1 ∀ k, n. 2 n = 2**n E-graph matching ∀ k, n. k*2 n = k << n reg6 4 * ∀ k, n. k*4 + n = s4addl (k, n) 2 2 … SAT s 4addl(reg6, 1) 7

  8. Deductive synthesis versus compilation s4addl << Deductive synthesizer 2 + • Non-deterministic. * 1 • Searches all correct rewrite sequences (proofs) reg6 4 * for one that yields an optimal program. 2 2 Compiler • Deterministic. reg6 * 4 + 1 • Lowers a source program into a target program using a fixed sequence of rewrites. reg6 << 2 + 1 8

  9. Deductive synthesis versus inductive synthesis . ∀ x. φ (x, P(x)) ∃ P Deductive synthesis Inductive synthesis • Efficient and provably correct: thanks • Works with multi-modal and partial to the semantics-preserving rules, specifications. only correct programs are explored. • Requires no axioms . • Requires complete specifications to • But often at the cost of lower seed the derivation. efficiency and weaker (bounded) • Requires sufficient axiomatization of guarantees on the correctness/ the domain. optimality of synthesized code. 9

  10. Inductive syntax-guided synthesis . φ (x 1 , P(x 1 )) ∧ … ∧ Solves ∃ P A partial or multimodal A program P from the φ (x n , P(x n )) for representative specification φ of the given space of candidates inputs x 1 , …, x n . that satisfies φ on all desired program (e.g., assertions, i/o pairs). (usually bounded) inputs. CEGIS: Counterexample-Guided Inductive Synthesis s 4addl(reg6, 1) reg6 * 4 + 1 [ Solar-Lezama et al, ASPLOS'06 ] A syntactic sketch (e.g., a grammar) expr := describing the shape of the desired const | reg6 | program P . s4addl( expr , expr ) | … This defines the space of candidate programs to search. Can be fine- tuned for better performance. 10

  11. Overview of CEGIS Any search algorithm: Searches for a program P Searches for an Usually a solver, but ∈ S that satisfies φ on all e.g., a solver, enumerative input x i+i on which P can be a test suite, violates φ . search, stochastic search. end-user, etc. inputs x i seen so far. P ∈ S s.t. ⋀ i φ (x i , P(x i )) Specification φ Synthesizer Verifier Sketch S x i+1 no counterexample Form of active learning (a special case of machine learning). Fail P 11

  12. Inductive synthesis with a solver 0, 1, 2 • Replace each ?? with fresh symbolic constant. (0 << n = 0) ∧ Logical encoding of x * 4 • Translate the resulting the synthesis (1 << n = 4) ∧ problem for the problem to constraints Solver-based synthesis x << ?? n (2 << n = 8) inputs 0, 1, 2. w.r.t. the current inputs. • If SAT, convert the model to a c program P . [ Solar-Lezama et al, ASPLOS'06 ] x << 2 12

  13. Inductive synthesis with enumerative search 0, 1, 2 • Iteratively construct all programs of size K until A candidate K=1: 0, 1, 2, x x * 4 one is consistent with program consistent K=1: 0 K=2: 1 << 2, 2 << 2, the current inputs. Enumeration-based with current inputs. x << 1, x << 2 synthesis • If two programs produce expr := the same output on all 0 | 1 | 2 | x | current inputs, keep just expr << expr one of the two. [ Udupa et al, PLDI'13 ] 13

  14. Inductive synthesis with stochastic search 0, 1, 2 • Use Metropolis-Hastings to sample expressions. A candidate x * 4 program consistent • Mutate the current with current inputs. candidate program and Stochastic synthesis keep the mutation with expr := probability proportional 0 | 1 | 2 | x | to its correctness w.r.t. expr << expr the current inputs. [ Schkufza et al, ASPLOS'13 ] 14

  15. Summary Today • Deductive synthesis with axioms and E-graphs • Inductive synthesis with solvers, enumeration, and stochastic search Next (and final) lecture • Solver-aided languages 15

Recommend


More recommend