Recursive Program Synthesis
Aws Albarghouthi (UToronto), Sumit Gulwani (MSR), and Zachary Kincaid (UToronto) CAV 2013 Saint Petersburg, Russia
Recursive Program Synthesis Aws Albarghouthi (UToronto), Sumit - - PowerPoint PPT Presentation
Recursive Program Synthesis Aws Albarghouthi (UToronto), Sumit Gulwani (MSR), and Zachary Kincaid (UToronto) CAV 2013 Saint Petersburg, Russia Program Synthesis Magic Specification Program 2 Program Synthesis Magic Specification
Aws Albarghouthi (UToronto), Sumit Gulwani (MSR), and Zachary Kincaid (UToronto) CAV 2013 Saint Petersburg, Russia
Program Synthesis
2
Magic
Specification Program
Program Synthesis
2
Magic
Specification Program
What are your Dreams?
3
Magic
Specification Program
What are your Dreams?
3
Magic
Specification Program First-order Logic
What are your Dreams?
3
Magic
Specification Program First-order Logic Temporal Logic
What are your Dreams?
3
Magic
Program First-order Logic Temporal Logic I/O Examples
Why Synthesis from I/O?
I/O examples are easy to specify
4
Why Synthesis from I/O?
I/O examples are easy to specify Non-expert users can specify I/O behaviour
4
Contribution
5
I/O Examples Recursive Program
Contribution
5
I/O Examples Recursive Program User
Contribution
5
I/O Examples Recursive Program Parameterized by a set of building blocks (operations) integers, lists, trees, etc. User
Contribution
5
I/O Examples Recursive Program Parameterized by a set of building blocks (operations) Novel search-based synthesis technique integers, lists, trees, etc. User
Contribution
5
I/O Examples Recursive Program Parameterized by a set of building blocks (operations) Novel search-based synthesis technique integers, lists, trees, etc. User No templates required
High Level View
6
Forward Search
High Level View
6
Forward Search
I1 In . . .
High Level View
6
Forward Search
I1 In . . .
High Level View
6
Forward Search
I1 In . . .
P1 Pn . . .
High Level View
6
Forward Search Conditional Inference
I1 In . . .
P1 Pn . . . I1 O1
+
I2 O2
P1 P2
High Level View
6
Forward Search Conditional Inference
I1 In . . .
P1 Pn . . . I1 O1
+
I2 O2
P1 P2
= if ( ) else
C
P1
P2
High Level View
6
Forward Search Conditional Inference
I1 In . . .
P1 Pn . . . I1 O1
+
I2 O2
P1 P2
= if ( ) else
C
P1
P2
High Level View
6
Forward Search Conditional Inference
I1 In . . .
P1 Pn . . . I1 O1
+
I2 O2
P1 P2
= if ( ) else
C
P1
P2
Recursive call synthesis Reuse I/O as recursive call specification or query user
Example
Synthesize list length from examples:
7
Example
Synthesize list length from examples:
7
Inputs:
Example
Synthesize list length from examples:
7
Inputs:
Outputs:
Ex: Forward Search
8
Components: inc, isEmpty, tail, zero
Ex: Forward Search
8
Components: inc, isEmpty, tail, zero Programs of size 1:
Ex: Forward Search
8
Components: inc, isEmpty, tail, zero Programs of size 1:
1 P1 = i → [],[2],[1,2]
Ex: Forward Search
8
Components: inc, isEmpty, tail, zero Programs of size 1:
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Ex: Forward Search
8
Components: inc, isEmpty, tail, zero Programs of size 1:
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
matches output for first input Recall outputs
0,1,2
Ex: Conditional Inference
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
Ex: Conditional Inference
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
Ex: Conditional Inference
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
Goal Graph (GG):
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
Ex: Conditional Inference
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
Goal Graph (GG):
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
Ex: Conditional Inference
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
AND node Goal Graph (GG):
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
Ex: Conditional Inference
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
AND node Goal Graph (GG):
1 → P2 = zero → 0,0,0 0,1,2
Outputs:
“Backward” search
Ex: Forward Search 2
10
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2:
Ex: Forward Search 2
10
→
P3 = tail(P1) → err,[],[2] P4 = inc(P2) → 1,1,1 P5 = isEmpty(P1) → T,F,F
1 P1 = i → [],[2],[1,2]
1 → P2 = zero → 0,0,0
Programs of size 1: Programs of size 2: Satisfies one of our goals
Ex: Conditional Inference 2
11
4 2 →
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
Ex: Conditional Inference 2
11
4 2 →
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
Ex: Conditional Inference 2
11
4 2 →
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
if ( ) else
...
Ex: Forward Search 3
12
Programs of size 2 →
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
→
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Only allow calls satisfying well-founded relation
Ex: Forward Search 3
12
Programs of size 2 Programs of size 3
→
Use I/O values to simulate recursive call
→
...
Only allow calls satisfying well-founded relation
But what if there isn’t such an I/O pair? Query the user for new examples!
(too long for 15 min talk)
Ex: Conditional Inference
13
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
One iteration later:
inc(length(tail(i))) P8
Ex: Conditional Inference
13
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
One iteration later:
inc(length(tail(i))) P8
Ex: Conditional Inference
13
Pr 0,1,2
T,F,F ?,1,2 0,?,?
cond then else goal
P2
One iteration later:
inc(length(tail(i))) P8
if isEmpty(i) then 0 else inc(length(tail(i)))
P5 P8 P2
Synthesized program:
Escher: Recap
Forward Search
14
Escher: Recap
Forward Search
Conditional Inference
14
Escher: Recap
Forward Search
Conditional Inference
Recursive call synthesis
14
Implementation
Prototype implementation of Escher
Experimented with:
15
Experiments
16
Escher w/o
ObsEquiv w/o GoalGraph
w/o OE+GG
collect_leaves
0.04 0.09 68.9 81.8
count_leaves
0.06 0.2 9.3 12.3
hbal_tree
1.5 MEM TIME MEM
nodes_at_level 10.74 MEM
TIME MEM
(tree manipulating programs) Time in seconds
Experiments
17
(#components sensitivity: mult)
Escher: 0.7s
with all components
Experiments
17
(#components sensitivity: mult)
10 20 30 40 1 2 3 4 5Sketch sensitivty
SAT-based synthesis [ASPLOS’06]
NUMBER OF EXTRA COMPONENTS T I M E ( S )
Escher: 0.7s
with all components
Experiments
17
(#components sensitivity: mult)
10 20 30 40 1 2 3 4 5Sketch sensitivty
SAT-based synthesis [ASPLOS’06]
NUMBER OF EXTRA COMPONENTS T I M E ( S )
Had to supply Sketch with high-level conditional
Escher: 0.7s
with all components
Conclusion
18
I/O Examples Recursive Program User
Conclusion
18
I/O Examples Recursive Program User Interactive
Conclusion
18
I/O Examples Recursive Program User Interactive Highly-customizable
Conclusion
18
I/O Examples Recursive Program User Interactive Highly-customizable Novel synthesis techniques
Questions?
How can we synthesize loops?
19
Questions?
How can we synthesize loops? Integration with SMT
19
Questions?
How can we synthesize loops? Integration with SMT
Applications of Escher in eduction
19
Questions?
How can we synthesize loops? Integration with SMT
Applications of Escher in eduction
Theoretical under-pinnings
19