Programming by Sketching Ras Bodik. 2 The Problem Problem: k-line algorithm translates to 10-100k lines of code. 30-year-old idea: Can we synthesize the.

Slides:



Advertisements
Similar presentations
Chapter 4 Computation Bjarne Stroustrup
Advertisements

IS 2610: Data Structures Sorting Feb 16, Sorting Algorithms: Bubble sort Bubble sort  Move through the elements exchanging adjacent pairs if the.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
MS 101: Algorithms Instructor Neelima Gupta
Background for “KISS: Keep It Simple and Sequential” cs264 Ras Bodik spring 2005.
Coding Practices. Why do we care? Good code is more than just functionality Other people will read your code You will forget what you code does Debugging.
Q-1 University of Washington Computer Programming I Lecture 16: Sorting © 2000 UW CSE.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Heap Management.
Internal Sorting A brief review and some new ideas CS 400/600 – Data Structures.
CS203 Programming with Data Structures Sorting California State University, Los Angeles.
MergeSort (Example) - 1. MergeSort (Example) - 2.
The Future of Correct Software George Necula. 2 Software Correctness is Important ► Where there is software, there are bugs ► It is estimated that software.
2420 Review Questions Chapter 6.
CS 280 Data Structures Professor John Peterson. Example: log(N) This is where things get hairy! How would you compute Log 10 (N) in a very approximate.
Two techniques for programming by sketching (Stanford, November 2004) Rastislav Bodik, David Mandelin, Armando Solar-Lezama, Lin Xu UC Berkeley Rodric.
VS 3 : Verification and Synthesis using SMT Solvers SMT Solvers for Program Verification Saurabh Srivastava * Sumit Gulwani ** Jeffrey S. Foster * * University.
Sorting Algorithms Insertion and Radix Sort. Insertion Sort One by one, each as yet unsorted array element is inserted into its proper place with respect.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Chapter 7 (Part 2) Sorting Algorithms Merge Sort.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Mining Jungloids to Cure Programmer Headaches Dave Mandelin, Ras BodikUC Berkeley Doug KimelmanIBM.
Simple Sort Algorithms Selection Sort Bubble Sort Insertion Sort.
Macho: Programming With Man Pages Anthony Cozzie, Murph Finnicum, Sam King University of Illinois at Urbana-Champaign.
Abstract Data Types (ADTs) Data Structures The Java Collections API
Templates of slides for P3 1. A brief update on your problem (important) Describe in English -what artifacts (programs, etc) will you synthesize, -what.
Programming by Sketching Armando Solar-Lezama, Liviu Tancau, Gilad Arnold, Rastislav Bodik, Sanjit Seshia UC Berkeley, Rodric Rabbah MIT, Kemal Ebcioglu,
{ Graphite Grigory Arashkovich, Anuj Khanna, Anirban Gangopadhyay, Michael D’Egidio, Laura Willson.
Sorting Algorithms. Sorting Sorting is a process that organizes a collection of data into either ascending or descending order. public interface ISort.
Enabling Refinement with Synthesis Armando Solar-Lezama with work by Zhilei Xu and many others*
Searching. The process used to find the location of a target among a list of objects Searching an array finds the index of first element in an array containing.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Synthesis with the Sketch System D AY 1 Armando Solar-Lezama.
Pointers OVERVIEW.
Introduction to: Programming CS105 Lecture: Yang Mu.
Day 2 – Logic and Algorithms REACHING WIDER SUMMER SCHOOL.
Storyboard Programming Rishabh Singh and Armando Solar-Lezama.
Some comments on lab4. Hi Philippe! Can you tell me if my code works? Thanks! I’ll show you what works…
Data Structure and Algorithms. Algorithms: efficiency and complexity Recursion Reading Algorithms.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Synthesis with the Sketch System D AY 2 Armando Solar-Lezama.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
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.
Complexity Analysis. 2 Complexity The complexity of an algorithm quantifies the resources needed as a function of the amount of input data size. The resource.
Q-1 University of Washington Computer Programming I Lecture 16: Sorting © 2000 UW CSE.
Merge Sort. In plain English: if the size of the array > 1, split the array into two halves, and recursively sort both halves; when the sorts return,
1 Sorting. 2 Sorting Data Items Consider a set of data items  Each item may have more than one field Example: a student record with name, roll no, CGPA,…
Sorting Ordering data. Design and Analysis of Sorting Assumptions –sorting will be internal (in memory) –sorting will be done on an array of elements.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Sorting Algorithms. Sorting Sorting is a process that organizes a collection of data into either ascending or descending order. public interface ISort.
Searching and Sorting Searching algorithms with simple arrays
Entry Ticket: Algorithms and Program Construction
Topics Section 9.2 Complexity of algorithms Efficiency of algorithms
6/16/2010 Parallel Performance Parallel Performance.
New applications of program synthesis
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Merge Sort Merge sort is a recursive algorithm for sorting that decomposes the large problem.
Lecture 8 Functional synthesis
Animation of Bubble Sort
CSC215 Lecture Algorithms.
CSE 373 Data Structures and Algorithms
Programming by Sketching
Sorting.
CSE 332: Data Abstractions Sorting I
Templates of slides for P4 Experiments with your synthesizer
Recursion Chapter 11.
_Synthesis__________________ __Of_______________________ ___First-Order_____Dynamic___ _____________Programming___ _______________Algorithms___ Yewen (Evan)
Don’t just listen to music; listen to people
Sorting Algorithms.
Presentation transcript:

Programming by Sketching Ras Bodik

2 The Problem Problem: k-line algorithm translates to k lines of code. 30-year-old idea: Can we synthesize the code? No. Search space too large. Our observation: Some code fragments are harder than others. Our idea: Can we synthesize just the hard fragments?

3 int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n ); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( a[j] < b[k] ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; } Merge Sort looks simple to code, but there is a bug

4 Correct Merge Sort int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( j<n/2 && ( !(k<n-n/2) || a[j] < b[k]) ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; }

5 The sketching experience sketch implementation Movie Script: “Big hairy monster listens patiently to his green friend.” specification + sketch of Merge Sort sketch of Merge Sort completed Merge Sort completed Merge Sort Bubble Sort +

6 Sketched Merge Sort int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( j<n/2 && ( !(k<n-n/2) || a[j] < b[k]) ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; } hole

7 Benefits and Plans Division of labor –programmer writes the strategy/algorithm –synthesizer writes low-level details Immediate plans: –parallel programming! –especially gaming kernels on parallel processors, such as PS3

8 Prospector: another sketching project Sketching is promising for performance code: Abstraction gap between spec and implementation. But what about API client code? Even short code is surprisingly hard-to-write. But such code has no concise specification! public void parseJavaFile (IFile file) { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode node = AST.parseCompilationUnit(cu, false); } public void parseJavaFile (IFile file) { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode node = AST.parseCompilationUnit(cu, false); }

9 Prospector: a very different synthesizer sketch multiple implementations, user chooses one specification hard to write, hence omitted + but the same “sketching formula”

10 Sketching in API client code How do we present jungloid synthesis to programmers? hole objects we have object we want

11 You are invited to the PS Lunch Live demos by people who did the work... and many other presentations 380 Soda, noon-2pm