Introduction to Sketching

Slides:



Advertisements
Similar presentations
Constraint Based Synthesis for Beginners PSY 2012 Armando Solar-Lezama.
Advertisements

Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
The Sketching Approach to Program Synthesis
C. FlanaganSAS’04: Type Inference Against Races1 Type Inference Against Races Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College.
1 Lecture 11 – Partial Programs, Program Repair, and Sketching Eran Yahav.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Generative Programming Meets Constraint Based Synthesis Armando Solar-Lezama.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
Synthesis with the Sketch System D AY 1 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.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Chapter 8: Understanding Collections Textbook: Chapter 4.
Definition of the Programming Language CPRL
Introduction to Optimization
CMPT 120 Topic: Python’s building blocks -> More Statements
Programming what is C++
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Testing Tutorial 7.
Chapter 7: User-Defined Functions II
Chapter 6 CS 3370 – C++ Functions.
A Simple Syntax-Directed Translator
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.4
Java Primer 1: Types, Classes and Operators
Arrays An array in PHP is an ordered map
Variables, Environments and Closures
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
13 Enhancing the Wage Calculator App
New applications of program synthesis
Chapter 7: Introduction to CLIPS
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Introduction to Sketching
Predicates Predicate: A Boolean (yes-no) function. Example:
Chapter 4: Making Decisions.
Emily Leland (Not Nick) Spring 2017
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Lecture 7 Constraint-based Search
Functions Inputs Output
Higher-Order Procedures
Section 1.2 Linear Equations and Rational Equations
Introduction to Optimization
Lecture 5 Floyd-Hoare Style Verification
Preparing for MUPL! Justin Harjanto
MSIS 655 Advanced Business Applications Programming
CS 240 – Lecture 9 Bit Shift Operations, Assignment Expressions, Modulo Operator, Converting Numeric Types to Strings.
Discrete Event Simulation - 4
CSE 341 Section 7 Winter 2018 Adapted from slides by Eric Mullen, Nicholas Shahan, Dan Grossman, and Tam Dang.
Coding Concepts (Basics)
Section 1.2 Linear Equations and Rational Equations
Functional interface.
Adapted from slides by Nicholas Shahan and Dan Grossman
Control Structures Part 3
Programming by Sketching
Introduction to Optimization
Assignment Operators Topics Increment and Decrement Operators
Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang
Templates of slides for P4 Experiments with your synthesizer
Nicholas Shahan Spring 2016
Peter Seibel Practical Common Lisp Peter Seibel
Introduction to Computer Science
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Introduction to the Lab
Introduction to Computing Lecture 08: Functions (Part I)
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
5.8 Analyzing Graphs of Polynomials
Assignment Operators Topics Increment and Decrement Operators
Presentation transcript:

Introduction to Sketching IAP 2008 Armando Solar-Lezama

What is sketching? A program synthesis system A programming aid generates small fragments of code checks their validity against a specification A programming aid help you write tricky programs cleverness and insight come from you sorry, no programming robots computer helps with low-level reasoning

The sketching experience implementation (completed sketch) sketch

Sketch language basics Sketches are programs with holes write what you know use holes for the rest 2 semantic issues specifications How does SKETCH know what program you actually want? holes Constrain the set of solutions the synthesizer may consider

Specifications Is this enough? Specifications constrain program behavior assertions function equivalence Is this enough? assert x > y; blockedMatMul(Mat a, Mat b) implements matMul

Defining sets of code fragments is the key to Sketching effectively 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

Defining sets of code fragments Sets are defined hierarchically a sketch is just a set of possible programs the synthesizer will chose a correct program from the set Sketch Sets of Procedures Sets of Statements Sets of Expressions Sets of Integer Constants

Integer hole Define sets of integer constants Example: Hello World of Sketching spec: int foo (int x) { return x + x; } sketch: int bar (int x) implements foo { return x * ??; } Integer Hole

Integer Holes  Sets of Expressions Example: Least Significant Zero Bit 0010 0101  0000 0010 Trick: Adding 1 to a string of ones turns the next zero to a 1 i.e. 000111 + 1 = 001000 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 + 1) & (x + 0) !(x + 1) & (x + 0xFFFF) !(x + ??) & (x + ??)  !(x + 0) & (x + 1) !(x + 0xFFFF) & (x + 1)

Integer Holes  Sets of Expressions Example: Least Significant Zero Bit 0010 0101  0000 0010 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 Least Significant One Bit 0010 0100  0000 0100 Will the same trick work? try it out 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; } }

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 way of defining sets

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

Least Significant One revisited How did I know the solution would take the form !(x + ??) & (x + ??) . What if all you know is that the solution involves x, +, & and !. bit[W] tmp=0; {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |}; return tmp; This is now a set of statements (and a really big one too)

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 Keep in mind: repeat(n){ s}  s;s;…s; each of the n copies may resolve to a distinct stmt n can be a hole too. Keep in mind: the synthesizer won’t try to minimize n use --unrollamnt to set the maximum value of n n bit[W] tmp=0; repeat(??){ {| x | tmp |} = {| (!)?((x | tmp) (& | +) (x | tmp | ??)) |}; } return tmp;

Example: logcount int pop (bit[W] x) { int count = 0; for (int i = 0; i < W; i++) { if (x[i]) count++; } return count; 1 01 10 0010 0011 00000101 1 1 1 1 01 10 0010 0011 00000101 01 10 0010 0011 00000101

Procedures and Sets of Procedures 2 types of procedures standard procedures represents a single procedure all call sites resolve to the same procedure identified by the keyword static generators represents a set of procedures each call site resolves to a different procedure in the set default in the current implementation

Example: int rec(int x, int y, int z){ int t = ??; if(t == 0){return x;} if(t == 1){return y;} if(t == 2){return z;} if(t == 3){return rec(x,y,z) * rec(x,y,z);} if(t == 4){return rec(x,y,z) + rec(x,y,z);} if(t == 5){return rec(x,y,z) - rec(x,y,z);} } int sketch( int x, int y, int z ) implements spec{ return rec(x,y, z); int spec( int x, int y, int z ){ return (x + x) * (y - z); }

Closing Remarks Problems will be posted on the website at the end of class. Tomorrow: how sketching works advanced use of the synthesizer debugging your sketches