Synthesis with the Sketch System D AY 1 Armando Solar-Lezama.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
PLDI’2005Page 1June 2005 Example (C code) int double(int x) { return 2 * x; } void test_me(int x, int y) { int z = double(x); if (z==y) { if (y == x+10)
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Constraint Based Synthesis for Beginners PSY 2012 Armando Solar-Lezama.
Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
Software Engineering & Automated Deduction Willem Visser Stellenbosch University With Nikolaj Bjorner (Microsoft Research, Redmond) Natarajan Shankar (SRI.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
The Sketching Approach to Program Synthesis
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Compiler Construction
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
Classes, methods, and conditional statements We’re past the basics. These are the roots.
More on FunctionsCS-2301 B-term More on Functions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming Language,
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
1 Lecture 11 – Partial Programs, Program Repair, and Sketching Eran Yahav.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Fundamentals of Python: From First Programs Through Data Structures
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
High-Level Programming Languages: C++
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Generative Programming Meets Constraint Based Synthesis Armando Solar-Lezama.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Enabling Refinement with Synthesis Armando Solar-Lezama with work by Zhilei Xu and many others*
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
Integrating high-level constructs into programming languages Language extensions to make programming more productive Underspecified programs –give assertions,
Storyboard Programming Rishabh Singh and Armando Solar-Lezama.
CS703: PROJECT GUIDELINES 1. Logistics: Project Most important part of the course Teams of 1 or 2 people Expectations commensurate with size of team Deliverables.
Synthesis with the Sketch System D AY 2 Armando Solar-Lezama.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
Generating Heap- bounded Programs Walid Taha, Stephan Ellner (Rice University) Hongwei Xi (Boston University)
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Recursion. Problem decomposition Problem decomposition is a common technique for problem solving in programming – to reduce a large problem to smaller.
Templates of slides for P2 1. A very brief refresher of your problem Describe in English -what artifacts (programs, etc) you wish to synthesize, -from.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
The PLA Model: On the Combination of Product-Line Analyses 강태준.
Certifying and Synthesizing Membership Equational Proofs Patrick Lincoln (SRI) joint work with Steven Eker (SRI), Jose Meseguer (Urbana) and Grigore Rosu.
Constraint Based Synthesis F ROM S KETCHES TO S TORYBOARDS Rishabh Singh and Armando Solar-Lezama.
Control Flow Testing Handouts
A Simple Syntax-Directed Translator
Class 11: Two-argument recursion
Introduction to Sketching
New applications of program synthesis
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Introduction to Sketching
Lecture 7 Constraint-based Search
Functions Inputs Output
Making synthesis practical Are we there yet?
Lecture 8 Functional synthesis
Mini Language Interpreter Programming Languages (CS 550)
Lecture 5 Floyd-Hoare Style Verification
Distributed System Gang Wu Spring,2018.
Templates of slides for P4 Experiments with your synthesizer
This Lecture Substitution model
Presentation transcript:

Synthesis with the Sketch System D AY 1 Armando Solar-Lezama

The Challenge Computer should help make programming easier Problem  Programming requires insight and experience  Computers are not that smart Interaction between programmers and tools is key

The sketching approach Let the programmer control the implementation strategy Focus the synthesizer on the low-level details Key design principle:  Exploit familiar programming concepts

Framing the synthesis problem Automate challenging programming steps Leverage programmer knowledge VisualBasic Python Fortran? MundaneScience Fiction ( )

Fundamental question How to combine human insight and machine power Synergy between human and machine is key

Lessons from verification Embrace partial specifications  Because there will never be a spec for PowerPoint Speak to programmers in their own language  Test harnesses good, high order logic bad Don’t be afraid of exhaustive exploration  But do it intelligently  deductive reasoning is a double-edged sword You don’t have to do everything statically  For most problems it is too hard

Example You want to partition N elements over P procs  How many elements should a processor get? Obvious answer is N/P Obvious answer is wrong! N = 18 P = 5

void partition(int p, int P, int N, ref int ibeg, ref int iend){ if(p< {$ p, P, N, N/P, N%P : *, + $} ){ iend = {$ p, P, N, N/P, N%P : *, + $}; ibeg = {$ p, P, N, N/P, N%P : *, + $}; }else{ iend = {$ p, P, N, N/P, N%P : *, + $}; ibeg = {$ p, P, N, N/P, N%P : *, + $}; } Synthesizing a partition function What do we know?  The interface to the function we want  Not all processors will get the same # of elements  The kind of expressions we expect p P N N/P N%P * +

harness void testPartition(int p, int N, int P){ if(p>=P || P < 1){ return; } int ibeg, iend; partition(p, P, N, ibeg, iend); assert iend - ibeg < (N/P) + 2; if(p+1 < P){ int ibeg2, iend2; partition(p+1, P, N, ibeg2, iend2); assert iend == ibeg2; } if(p==0){ assert ibeg == 0; } if(p==P-1){ assert iend == N; } } Synthesizing a partition function How does the system know what a partition is? Partitions should be balanced Adjacent partitions should match First and last partition should go all the way to the ends

DEMO

Solution void partition(int p, int P, int N, ref int ibeg, ref int iend){ if(p < (N % P)){ iend = ((N / P) + 1) * (1 + p); ibeg = p + ((N / P) * p); }else{ iend = ((N / P) * p) + ((N / P) + (N % P)); ibeg = (N % P) + ((N / P) * p); }

THE SKETCH LANGUAGE

Sketch language basics Sketches are programs with holes  write what you know  use holes for the rest

Specifications Idea: Use unit tests as specification  Programmers know how to write those Two mechanisms  assertions  function equivalence blockedMatMul(Mat a, Mat b) implements matMul assert x > y;

Holes Holes are placeholders for the synthesizer  synthesizer replaces hole with concrete code fragment  fragment must come from a set defined by the user Defining sets of code fragments is the key to Sketching effectively

Language Design Strategy Extend base language with one construct Constant hole: ?? Synthesizer replaces ?? with a constant High-level constructs defined in terms of ?? int bar (int x) { int t = x * ??; assert t == x + x; return t; } int bar (int x) { int t = x * 2; assert t == x + x; return t; }

Integer Holes  Sets of Expressions Expressions with ?? == sets of expressions  linear expressions x*?? + y*??  polynomials x*x*?? + x*?? + ??  sets of variables ?? ? x : y

Integer Holes  Sets of Expressions Example: Least Significant Zero Bit   Trick:  Adding 1 to a string of ones turns the next zero to a 1  i.e = int W = 32; bit[W] isolate0 (bit[W] x) { // W: word size bit[W] ret = 0; for (int i = 0; i < W; i++) if (!x[i]) { ret[i] = 1; return ret; } } !(x + ??) & (x + ??) !(x + 1) & (x + 0) !(x + 0) & (x + 1) !(x + 1) & (x + 0xFFFF) !(x + 0xFFFF) & (x + 1) 

Integer Holes  Sets of Expressions Example: Least Significant Zero Bit   int W = 32; bit[W] isolate0 (bit[W] x) { // W: word size bit[W] ret = 0; for (int i = 0; i < W; i++) if (!x[i]) { ret[i] = 1; return ret; } } bit[W] isolateSk (bit[W] x) implements isolate0 { return !(x + ??) & (x + ??) ; }

Integer Holes  Sets of Expressions Expressions with ?? == sets of expressions  linear expressions x*?? + y*??  polynomials x*x*?? + x*?? + ??  sets of variables ?? ? x : y Semantically powerful but syntactically clunky  Regular Expressions are a more convenient

Regular Expression Generators {| RegExp |} RegExp supports choice ‘|’ and optional ‘?’  can be used arbitrarily within an expression - to select operands {| (x | y | z) + 1 |} - to select operators {| x (+ | -) y |} - to select fields {| n(.prev |.next)? |} - to select arguments {| foo( x | y, z) |} Set must respect the type system  all expressions in the set must type-check  all must be of the same type

Sets of statements Statements with holes = sets of statements Higher level constructs for Statements too  repeat bit[W] tmp=0; repeat(3){ {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |}; } return tmp;

repeat Avoid copying and pasting  repeat(n){ s}  s;s;…s;  each of the n copies may resolve to a distinct stmt  n can be a hole too. n bit[W] tmp=0; repeat(??){ {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |}; } return tmp;

GENERATORS

User defined generators Mechanism to define sets of code fragments They look like functions  But with a few caveats

Key features of generators Different dynamic invocations  different code Recursive generators = grammar of expressions generator bit[W] gen(bit[W] x, int bnd){ assert bnd > 0; if(??) return x; if(??) return ??; if(??) return ~gen(x, bnd-1); if(??){ return {| gen(x, bnd-1) (+ | & | ^) gen(x, bnd-1) |}; } bit[W] isolate0sk (bit[W] x) implements isolate0 { return gen(x, 3); }

CONSTRAINT BASED SYNTHESIS PRIMER

Synthesis problem at the high level Game theoretic view of synthesis For every move of the environment Synthesized program makes a counter move

The challenge of synthesis

Quantifying over programs

31 Insight Sketches are not arbitrary constraint systems  They express the high level structure of a program A small number of inputs can be enough  focus on corner cases This is an inductive synthesis problem ! where E = {x 1, x 2, …, x k }

Insert your favorite checker here CEGIS SynthesizeCheck

Insert your favorite checker here CEGIS SynthesizeCheck