150 likes | 243 Views
Synthesis with the Sketch System. Day 2. Armando Solar- Lezama. 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?.
E N D
Synthesis with the Sketch System Day 2 Armando Solar-Lezama
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?
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
Insight where E = {x1, x2, …, xk} Sketches 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 !
CEGIS Synthesize Check Insert your favorite checker here
CEGIS • Constraints for each follow from semantics • Loops handled through simple unrolling Synthesize Check Insert your favorite checker here
CEGIS in Detail a b c d + + + + + + + + + + + + A A A A Synthesize Check
CEGIS in Detail a b c d + + + + + + + + + + + + A A A A Synthesize Check Bits 5 4 3 2
User defined generators • Mechanism to define sets of code fragments • They look like functions • But with a few caveats
Key features of generators • Different dynamic invocations • different code • Recursive generators = grammar of expressions generator bit[W] gen(bit[W] x, intbnd){ assertbnd > 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) implementsisolate0 { returngen(x, 3); }
Gens + Closures = Extensible Language • Redefining Repeat bit[W] reverseSketch(bit[W] in) implementsreverse { bit[W] t = in; ints = 1; repeat(??){ bit[W] tmp1 = (t << s); bit[W] tmp2 = (t >> s); t = tmp1 {|} tmp2; s = s*??; } returnt; }
Gens + Closures = Extensible Language generator voidrep(intn, funf){ if(n>0){ f(); rep(n-1, f); } } • Redefining Repeat bit[W] reverseSketch(bit[W] in) implementsreverse { bit[W] t = in; ints = 1; generatorvoidtmp(){ bit[W] tmp1 = (t << s); bit[W] tmp2 = (t >> s); t = tmp1 {|} tmp2; s = s*??; } rep(??, tmp); returnt; }
Karatsuba Multiplication • Recursive grade-school multiplication
Karatsuba Multiplication • Smarter Karatsuba Multiplication