0% found this document useful (0 votes)
11 views31 pages

Lecture01 Overview

The document provides an overview of an introduction to program synthesis course. It discusses the instructor, logistics, objectives, evaluation, papers reviews, projects, and gives a brief introduction to program synthesis.

Uploaded by

qwerty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views31 pages

Lecture01 Overview

The document provides an overview of an introduction to program synthesis course. It discusses the instructor, logistics, objectives, evaluation, papers reviews, projects, and gives a brief introduction to program synthesis.

Uploaded by

qwerty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

#1: Course Overview

Sankha Narayan Guria


EECS 700: Introduction to Program Synthesis

1
Instructor
Sankha Narayan Guria

• Assistant Professor starting this Fall


• Previously: PhD @ University of
Maryland
• Research Areas: Program synthesis and
program analysis

2
Logistics
• Lectures:
• Mon Wed Fri: 3:00 - 3:50pm LEEP2 G411 But you already knew that!

• Office Hours:
• Wed: 4:00 - 5:00pm Eaton 2034

• Course Website:
• https://sankhs.com/eecs700/
• Communications through Canvas and Discord

3
Objectives
1. Understand what program • Lectures
synthesis can do and how • Read and discuss research papers

2. Use existing synthesis


tools

3. Contribute to synthesis • Project


techniques and tools
towards a publication in an
academic conference

4
Evaluation
• Class Participation
• Ask/answer questions in class
• Participate in discussions on Discord
• Paper Reviews
• 9 papers, 5% each
• Final Project
• Team formed by deadline: 5%
• 1 page project proposal: 15%
• Project presentation: 15%
• Final report: 15%

5
Paper Reviews
• Due on Thursday, by end of day
• First review is due next week!
• Will be posted on website a week before due date
• Reviews submitted via Canvas
• Link on website
• Website has details of review guidelines
• Discussion:
• Before review is due: discuss on Discord
• After review is due: discuss in class (Friday)

6
Project
• Kinds of projects:
• Re-implement techniques from a paper
• Apply existing synthesis framework to a new domain
• Extend/improve existing synthesis algorithm or tool
• Develop a new synthesis algorithm or tool
• …
• Judged in terms of
• Quality of execution
• Originality
• Scope

7
Project
Team forming • Teams of 2-3
• Pick a project:
• List of suggested projects coming soon on
website
• Please talk to me!
• One page: explain what you plan to do
Proposal and give some evidence that you’ve
started to work on it
• Presentations in last few classes
Presentation • ~10-15 min per project
• 3-8 pages, structured like a research
Report paper
8
Now to the good stuff …

9
The goal: automate programming
What is program synthesis?
append:
push ebp
mov ebp, esp
push eax
push ebx
push len
“Any
call malloc
s ufficie
mov ebx, [ebp + 12]
ntly a
d
mov [eax + info], ebx
mov dword [eax + next], 0 vance
from d compiler
mov ebx, [ebp + 8]
cmp dword [ebx], 0

a synt
hesize is indisting
je null_pointer void insert(node *xs, int x) {
mov ebx, [ebx] node *new;
node *temp;
r” ui s ha
b
next_element:
le
node *prev;
cmp dword [ebx + next], 0
je found_last new = (node *)malloc(sizeof(node));
mov ebx, [ebx + next] if(new == NULL) {
jmp next_element printf("Insufficient memory.");
return;
found_last: }
push eax new->val = x;
push addMes new->next = NULL;
call puts if (xs == NULL) {
add esp, 4 xs = new;
pop eax } else if(x < xs->val) {
mov [ebx + next], eax new->next = xs;
xs = new;
go_out: } else {
pop ebx prev = xs;
pop eax temp = xs->next;
mov esp, ebp while(temp != NULL && x > temp->val) {
pop ebp prev = temp;
ret 8 temp = temp->next;
}
null_pointer: if(temp == NULL) {

?
push eax prev->next = new;
push nullMes } else {
call puts new->next = temp;
add esp, 4 prev->next = new; insert x [] = [x]
pop eax } insert x (y:ys)
mov [ebx], eax } | x ≤ y = x:y:ys
jmp go_out } | otherwise = y:(insert x ys)

Assembly C Haskell modern program


synthesis
Modern program synthesis: FlashFill

[Gulwani 2011]
FlashFill: a feature of Excel 2013
FlashFill: a feature of Excel 2013
Modern program synthesis: Sketch
• Problem: isolate the least significant zero bit in a word
• example: 0010 0101 à 0000 0010
• Easy to implement with a loop
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; }
}

• Can this be done more efficiently with bit manipulation?


• Trick: adding 1 to a string of ones turns the next zero to a 1
• i.e. 000111 + 1 = 001000

[Solar-Lezama 2013]
Sketch: space of possible
implementations
/**
* Generate the set of all bit-vector expressions
* involving +, &, xor and bitwise negation (~).
*/

generator bit[W] gen(bit[W] x){


if(??) return x;
if(??) return ??;
if(??) return ~gen(x);
if(??){
return {| gen(x) (+ | & | ^) gen(x) |};
}
}
Sketch: synthesis goal
generator bit[W] gen(bit[W] x, int depth){
assert depth > 0;
if(??) return x;
if(??) return ??;
if(??) return ~gen(x, depth-1);
if(??){
return {| gen(x, depth-1) (+ | & | ^) gen(x, depth-1) |};
}
}

bit[W] isolate0fast (bit[W] x) implements isolate0 {


return gen(x, 3);
}
Sketch: output

bit[W] isolate0fast (bit[W] x) {


return (~x) & (x + 1);
}
~0010 0101 0010 0101 + 1
= 1101 1010 = 0010 0110

&
0000 0010
Modern program synthesis: Synquid
• Problem: intersection of sets represented as strictly sorted
lists
• example: intersect [4, 8, 15, 16, 23, 42] [8, 16, 32, 64] à [8, 16]
• Also: we want a guarantee that it’s correct on all inputs!

[Polikarpova et al. 2016]


Synquid: synthesis goal and
components
• Step 1: define synthesis goal as a type sorted
list

intersect
intersect ::
:: xs:List
xs:SLista a→ ys:List a
→ ys:SList a
v:SList
→→ {List a a | elems v = elems xs ∩ elems ys}
the set of
elements

• Step 2: define a set of components


• Which primitive operations is our function likely to use?
• Here: {Nil, Cons, <}
Synquid: output
xs ys result
intersection = \xs . \ys .
match xs with [4, 8, 15, 16, 23, 42] [8, 16, 32, 64]
Nil -> xs [8, 15, 16, 23, 42] [8, 16, 32, 64] [8]
Cons x xt ->
match ys with [15, 16, 23, 42] [16, 32, 64]
Nil -> ys [16, 23, 42] [16, 32, 64] [8, 16]
Cons y yt ->
if x < y [23, 42] [32, 64]
then intersection xt ys
[42] [32, 64]
else
if y < x [42] [64]
then intersection xs yt
[] [64]
else Cons x (intersection xt yt)
Modern program synthesis: GitHub
Copilot
// find all images
// and add a green border around them input
// and add class “githubCopilot” to them
function go() {

• var images = document.getElementByTagName(‘img’);


• for (var i = 0; i < images.length; i++) {
• if (images[i].className.indexOf(‘githubCopilot’) == -1) { output
• images[i].className += ‘ githubCopilot’;
• images[i].style.border = ‘1px solid green’;
• }
• }

What is program synthesis?

specification search program

program
space

24
Dimensions in program synthesis
Behavioral spec:
what should the program should do?

Search strategy:
How does the system find Structural spec:
the program you want? what is the space of programs to
explore?

[Gulwani 2010]
Behavioral spec
• How do you tell the system what the program
should do?
• What is the input language / format?
• What is the interaction model?
• What happens when the intent is ambiguous?

• Q: What did the behavioral spec look like in


FlashFill / Sketch / Synquid / Copilot?
Behavioral spec: examples
• Input/output examples
• Reference implementation
• Formal specifications (pre/post
conditions, types, ...)
• Natural language
• Context
Structural spec
• What is the space of programs to explore?
• Large enough to contain interesting programs, yet
small enough to exclude garbage and enable
efficient search
• Built-in or user defined?
• Can we extract domain knowledge from existing
code?

• Q: What did the structural spec look like in


FlashFill / Sketch / Synquid / Copilot?
Structural spec: examples
• Built-in DSL
• User-defined DSL (grammar)
• User-provided components
• Languages with synthesis constructs
• e.g. generators in Sketch
• Learned language model
Search strategies
• Synthesis is search:
• Find a program in the space defined by structural
constraints that satisfies behavioral constraints
• Challenge: the space is astronomically large
• The search algorithm is the heart of a synthesis
technique
• How does the system find the program you want?
• How does it know it’s the program you want?
• How can it leverage structural constraints to guide the
search?
• How can it leverage behavioral constraints to guide the
search?
Search strategies: examples
• Enumerative (explicit) search
• exhaustively enumerate all programs in the language in
the order of increasing size
• Stochastic search
• random exploration of the search space guided by a
fitness function
• Representation-based search
• use a data structure to represent a large set of
programs
• Constraint-based search
• translate to constraints and use a solver

You might also like