synthesis with the sketch system

15
Synthesis with the Sketch System DAY 2 Armando Solar-Lezama

Upload: abram

Post on 24-Feb-2016

27 views

Category:

Documents


0 download

DESCRIPTION

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?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Synthesis with the Sketch System

Synthesis with the Sketch System

DAY 2

Armando Solar-Lezama

Page 2: Synthesis with the Sketch System

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

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

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

Insert your favorite checker here

CEGIS

{𝒊𝒏𝒊}

∃𝒄 𝒔 .𝒕 .𝑪𝒐𝒓𝒓𝒆𝒄𝒕 (𝑷 𝒄 , 𝒊𝒏𝒊) ∃ 𝒊𝒏𝒔 .𝒕 .¬𝑪𝒐𝒓𝒓𝒆𝒄𝒕 (𝑷𝒄 , 𝒊𝒏𝒊)

Synthesize Check𝒄

𝒊𝒏

Page 6: Synthesis with the Sketch System

•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

CEGIS in Detail

𝑸 (𝒄 ,𝒊𝒏)+

++

b

+

+

++

a c d

A

+

+

+ ++

A A A

{𝒊𝒏𝒊}

Synthesize Check𝒄

𝒊𝒏

Page 8: Synthesis with the Sketch System

CEGIS in Detail𝑸𝟎(𝒄 , 𝒊𝒏)

𝑸𝟎 (𝒄 , 𝒊𝒏 )⇒𝑸𝟏(𝒄 , 𝒊𝒏)𝑸𝟏(𝒄 , 𝒊𝒏)𝑸𝟏 (𝒄 , 𝒊𝒏)⇒𝑸𝟐(𝒄 , 𝒊𝒏)𝑸𝟐(𝒄 , 𝒊𝒏)

++

+

b

+

+

++

a c d

A

+

+

+ ++

A A A

{𝒊𝒏𝒊}

Synthesize Check𝒄

𝒊𝒏

Bits

2345

Page 9: Synthesis with the Sketch System

GENERATORS

Page 10: Synthesis with the Sketch System

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

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

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

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

Karatsuba Multiplication•Recursive grade-school multiplication

𝑥=𝑥2∗𝑝𝑛2+𝑥1 𝑦=𝑦2∗𝑝

𝑛2 +𝑦1

𝑥∗ 𝑦=𝑎+𝑏∗𝑝𝑛2+𝑐 ∗𝑝

𝑛2+𝑑∗𝑝𝑛

Page 15: Synthesis with the Sketch System

Karatsuba Multiplication•Smarter Karatsuba Multiplication

𝑥=𝑥1∗𝑝𝑛2+𝑥2 𝑦=𝑦1∗𝑝

𝑛2+𝑦2

𝑥∗ 𝑦=…