Synthesis with the Sketch System
description
Transcript of Synthesis with the Sketch System
![Page 1: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/1.jpg)
Synthesis with the Sketch System
DAY 2
Armando Solar-Lezama
![Page 2: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/2.jpg)
The challenge of synthesis•For functions, the environment controls the inputs
i.e. whatever we synthesize must work for all inputs
•Modeled with a doubly quantified constraint
What does it mean to quantify over programs?
![Page 3: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/3.jpg)
Quantifying over programs•Synthesis as curve fitting
we want a function that satisfies some properties
•It’s hard to do curve fitting with arbitrary curves Instead, people use parameterized families of curves Quantify over parameters instead of over functions
•A sketch is just a way of describing these families
![Page 4: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/4.jpg)
4
InsightSketches are not arbitrary constraint systems
They express the high level structure of a program
A small number of inputs can be enough focus on corner cases
This is an inductive synthesis problem !
∃𝑐 ∀ 𝑖𝑛∈𝐸𝑄(𝑖𝑛 ,𝑐 )where E = {x1, x2, …, xk}
![Page 5: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/5.jpg)
Insert your favorite checker here
CEGIS
{𝒊𝒏𝒊}
∃𝒄 𝒔 .𝒕 .𝑪𝒐𝒓𝒓𝒆𝒄𝒕 (𝑷 𝒄 , 𝒊𝒏𝒊) ∃ 𝒊𝒏𝒔 .𝒕 .¬𝑪𝒐𝒓𝒓𝒆𝒄𝒕 (𝑷𝒄 , 𝒊𝒏𝒊)
Synthesize Check𝒄
𝒊𝒏
![Page 6: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/6.jpg)
•Constraints for each follow from semantics
Loops handled through simple unrolling
Insert your favorite checker here
CEGIS
{𝒊𝒏𝒊}
∃𝒄 𝒔 .𝒕 .𝑪𝒐𝒓𝒓𝒆𝒄𝒕 (𝑷 𝒄 , 𝒊𝒏𝒊)
Synthesize Check𝒄
𝒊𝒏
![Page 7: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/7.jpg)
CEGIS in Detail
𝑸 (𝒄 ,𝒊𝒏)+
++
b
+
+
++
a c d
A
+
+
+ ++
A A A
{𝒊𝒏𝒊}
Synthesize Check𝒄
𝒊𝒏
![Page 8: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/8.jpg)
CEGIS in Detail𝑸𝟎(𝒄 , 𝒊𝒏)
𝑸𝟎 (𝒄 , 𝒊𝒏 )⇒𝑸𝟏(𝒄 , 𝒊𝒏)𝑸𝟏(𝒄 , 𝒊𝒏)𝑸𝟏 (𝒄 , 𝒊𝒏)⇒𝑸𝟐(𝒄 , 𝒊𝒏)𝑸𝟐(𝒄 , 𝒊𝒏)
++
+
b
+
+
++
a c d
A
+
+
+ ++
A A A
{𝒊𝒏𝒊}
Synthesize Check𝒄
𝒊𝒏
Bits
2345
![Page 9: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/9.jpg)
GENERATORS
![Page 10: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/10.jpg)
User defined generators•Mechanism to define sets of code fragments
•They look like functions But with a few caveats
![Page 11: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/11.jpg)
Key features of generators•Different dynamic invocations • different code
•Recursive generators = grammar of expressionsgenerator bit[W] gen(bit[W] x, int bnd){ assert bnd > 0; if(??) return x; if(??) return ??; if(??) return ~gen(x, bnd-1); if(??){ return {| gen(x, bnd-1) (+ | & | ^) gen(x, bnd-1) |}; }}
bit[W] isolate0sk (bit[W] x) implements isolate0 { return gen(x, 3);}
![Page 12: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/12.jpg)
bit[W] reverseSketch(bit[W] in) implements reverse {
bit[W] t = in; int s = 1; repeat(??){ bit[W] tmp1 = (t << s); bit[W] tmp2 = (t >> s); t = tmp1 {|} tmp2; s = s*??; } return t;}
Gens + Closures = Extensible Language•Redefining Repeat
![Page 13: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/13.jpg)
Gens + Closures = Extensible Language•Redefining Repeat generator void rep(int n, fun f){
if(n>0){ f(); rep(n-1, f); } }
bit[W] reverseSketch(bit[W] in) implements reverse {
bit[W] t = in; int s = 1; generator void tmp(){ bit[W] tmp1 = (t << s); bit[W] tmp2 = (t >> s); t = tmp1 {|} tmp2; s = s*??; } rep(??, tmp); return t;}
![Page 14: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/14.jpg)
Karatsuba Multiplication•Recursive grade-school multiplication
𝑥=𝑥2∗𝑝𝑛2+𝑥1 𝑦=𝑦2∗𝑝
𝑛2 +𝑦1
𝑥∗ 𝑦=𝑎+𝑏∗𝑝𝑛2+𝑐 ∗𝑝
𝑛2+𝑑∗𝑝𝑛
![Page 15: Synthesis with the Sketch System](https://reader035.fdocuments.in/reader035/viewer/2022062218/568165bc550346895dd8b987/html5/thumbnails/15.jpg)
Karatsuba Multiplication•Smarter Karatsuba Multiplication
𝑥=𝑥1∗𝑝𝑛2+𝑥2 𝑦=𝑦1∗𝑝
𝑛2+𝑦2
𝑥∗ 𝑦=…