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 Program 2
What are your Dreams? Magic Specification Program 3
What are your Dreams? First-order Logic Magic Specification Program 3
What are your Dreams? First-order Logic Magic Specification Program Temporal Logic 3
What are your Dreams? First-order Logic Magic I/O Examples Program Temporal Logic 3
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 • See, e.g., FlashFill for Excel, Smartphone scripts, etc. • Desired programs are usually simple 4
Contribution Escher Recursive I/O Examples Program 5
Contribution User Escher Recursive I/O Examples Program 5
Contribution User Escher Recursive I/O Examples Program Parameterized by a set of building blocks (operations) integers, lists, trees, etc. 5
Contribution User Escher Recursive I/O Examples Program Parameterized by a set of building blocks (operations) integers, lists, trees, etc. Novel search-based synthesis technique 5
Contribution User Escher Recursive I/O Examples Program Parameterized by a set of building blocks (operations) integers, lists, trees, etc. Novel search-based synthesis technique No templates required 5
High Level View Forward Search 6
High Level View Forward Search I 1 I n . . . 6
High Level View Forward Search I 1 I n . . . O 1 . . . O n 6
High Level View Forward Search I 1 I n . . . P 1 P n . . . O 1 . . . O n 6
High Level View Forward Search Conditional Inference I 1 I 1 I 2 I n . . . + P 1 P n P 1 P 2 . . . O 1 O 2 O 1 . . . O n 6
High Level View Forward Search Conditional Inference I 1 I 1 I 2 I n . . . if ( ) C + P 1 P 1 P n = P 1 P 2 . . . else P 2 O 1 O 2 O 1 . . . O n 6
High Level View Forward Search Conditional Inference I 1 I 1 I 2 I n . . . if ( ) C + P 1 P 1 P n = P 1 P 2 . . . else P 2 O 1 O 2 O 1 . . . O n 6
High Level View Forward Search Conditional Inference I 1 I 1 I 2 I n . . . if ( ) C + P 1 P 1 P n = P 1 P 2 . . . else P 2 O 1 O 2 O 1 . . . O n Recursive call synthesis Reuse I/O as recursive call specification or query user 6
Example Synthesize list length from examples: 7
Example Synthesize list length from examples: → � [],[2],[1,2] � Inputs: 7
Example Synthesize list length from examples: → � [],[2],[1,2] � Inputs: � 0,1,2 � Outputs: 7
Ex: Forward Search Components: inc, isEmpty, tail, zero 8
Ex: Forward Search Components: inc, isEmpty, tail, zero Programs of size 1: 8
Ex: Forward Search Components: inc, isEmpty, tail, zero Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � 8
Ex: Forward Search Components: inc, isEmpty, tail, zero Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � 8
Ex: Forward Search Components: inc, isEmpty, tail, zero Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � matches output for first input Recall outputs � 0,1,2 � 8
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 �
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 �
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 � goal Goal Graph (GG): � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � P 2
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 � goal Goal Graph (GG): � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � P 2
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 � goal Goal Graph (GG): � 0,1,2 � AND node P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � P 2
Ex: Conditional Inference → � 1 P 2 = zero → � 0,0,0 � Outputs: � 0,1,2 � goal Goal Graph (GG): � 0,1,2 � “Backward” search AND node P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � P 2
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � 10
Ex: Forward Search 2 Programs of size 1: 1 P 1 = i → � [],[2],[1,2] � → � 1 P 2 = zero → � 0,0,0 � → � � Programs of size 2: P 3 = tail ( P 1 ) → � err ,[],[2] � 2 P 4 = inc ( P 2 ) → � 1,1,1 � P 5 = isEmpty ( P 1 ) → � T,F,F � Satisfies one of our goals 10
Ex: Conditional Inference 2 2 → � � 4 P 5 = isEmpty ( P 1 ) → � T,F,F � goal � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � P 2 11
Ex: Conditional Inference 2 2 → � � 4 P 5 = isEmpty ( P 1 ) → � T,F,F � goal � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � � P 2 P 5 11
Ex: Conditional Inference 2 2 → � � 4 P 5 = isEmpty ( P 1 ) → � T,F,F � goal � 0,1,2 � � if ( ) � � � P 5 P 2 P r else ... cond then else � T,F,F � � 0,?,? � � ?,1,2 � � P 2 P 5 11
Ex: Forward Search 3 Programs of size 2 → � � P 3 = tail ( P 1 ) → � err ,[],[2] � ... 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Use I/O values to simulate recursive call 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Use I/O values to simulate recursive call 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Use I/O values to simulate recursive call 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Use I/O values to simulate recursive call 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � ... → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Use I/O values to simulate recursive call Only allow calls satisfying well-founded relation 12
Ex: Forward Search 3 → � � Programs of size 2 P 3 = tail ( P 1 ) → � err ,[],[2] � But what if there isn’t ... such an I/O pair? → � � Programs of size 3 3 P 6 = length ( P 3 ) → � err ,0,1 � Query the user for new examples! Use I/O values to simulate recursive call (too long for 15 min talk) Only allow calls satisfying well-founded relation 12
Ex: Conditional Inference One iteration later: goal � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � � P 5 P 2 inc(length(tail(i))) P 8 13
Ex: Conditional Inference One iteration later: goal � 0,1,2 � P r cond then else � T,F,F � � 0,?,? � � ?,1,2 � � P 5 P 2 inc(length(tail(i))) P 8 13
Recommend
More recommend