Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dimensions in Synthesis Sumit Gulwani Microsoft Research, Redmond May 2012.

Similar presentations


Presentation on theme: "Dimensions in Synthesis Sumit Gulwani Microsoft Research, Redmond May 2012."— Presentation transcript:

1 Dimensions in Synthesis Sumit Gulwani sumitg@microsoft.com Microsoft Research, Redmond May 2012

2 Synthesize a program in some underlying language from user intent using some search technique. 1 Program Synthesis Why today? –Variety of (cheap) computational devices and platforms Billions of non-experts have access to these devices! –Enabling technology is now available Better search algorithms Faster machines (good application for multi-cores)

3 Synthesize a program in some underlying language from user intent using some search technique. 2 Program Synthesis Why today? –Variety of (cheap) computational devices and platforms Billions of non-experts have access to these devices! –Enabling technology is now available Better search algorithms Faster machines (good application for multi-cores)

4 Concept Language –Programs Straight-line programs –Automata –Queries –Sequences User Intent –Logic, Natural Language –Examples, Demonstrations/Traces Search Technique –SAT/SMT solvers (Formal Methods) –A*-style goal-directed search (AI) –Version space algebras (Machine Learning) 3 Dimensions in Synthesis PPDP 2010: “Dimensions in Program Synthesis”, Gulwani. (Application) (Ambiguity) (Algorithm)

5 4 Compilers vs. Synthesizers DimensionCompilersSynthesizers Concept Language Executable ProgramVariety of concepts: Program, Automata, Query, Sequence User IntentStructured languageVariety/mixed form of constraints: logic, examples, traces Search Technique Syntax-directed translation (No new algorithmic insights) Uses some kind of search (Discovers new algorithmic insights)

6 Students and Teachers End-Users Algorithm Designers Software Developers Most Transformational Target Potential Users of Synthesis Technology 5 Most Useful Target Vision for End-users: Enable people to have (automated) personal assistants. Vision for Education: Enable every student to have access to free & high-quality education.

7 Lecture 1: Algorithms Synthesis of Straight-line Programs from Logic –Bit-vector Algorithms –Geometry Constructions Lecture 2: Applications Intelligent Tutoring Systems Lecture 3: Ambiguity Synthesis from Examples & Keywords 6 Organization

8 Intelligent Tutoring Systems Technical Goals: Identify a useful task that can be formalized as a synthesis problem. Propose an appropriate user interaction model. Propose an appropriate search technique. 7 Lab

9 Synthesizing Bitvector Algorithms PLDI 2011: Gulwani, Jha, Tiwari, Venkatesan

10 Concept Language –Programs Straight-line programs –Automata –Queries –Sequences User Intent –Logic, Natural Language –Examples, Demonstrations/Traces Search Technique –SAT/SMT solvers (Formal Methods) –A*-style goal-directed search (AI) –Version space algebras (Machine Learning) 9 Dimensions in Synthesis PPDP 2010: “Dimensions in Program Synthesis”, Gulwani.

11 Straight-line programs that use –Arithmetic Operators: +,-,*,/ –Logical Operators: Bitwise and/or/not, Shift left/right 10 Bitvector Algorithms

12 1 0 1 0 1 1 0 0 Turn-off rightmost 1-bit 11 Examples of Bitvector Algorithms 1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0 Z Z & (Z-1) 1 0 1 0 1 0 1 1 Z Z-1 1 0 1 0 1 0 0 0 & Z & (Z-1)

13 12 Examples of Bitvector Algorithms Turn-off rightmost contiguous sequence of 1-bits Z Z & (1 + (Z | (Z-1))) 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0 Ceil of average of two integers without overflowing (Y|Z) – ((Y © Z) >> 1)

14 13 Examples of Bitvector Algorithms Higher order half of product of x and y o1 := and(x,0xFFFF); o2 := shr(x,16); o3 := and(y,0xFFFF); o4 := shr(y,16); o5 := mul(o1,o3); o6 := mul(o2,o3); o7 := mul(o1,o4); o8 := mul(o2,o4); o9 := shr(o5,16); o10 := add(o6,o9); o11 := and(o10,0xFFFF); o12 := shr(o10,16); o13 := add(o7,o11); o14 := shr(o13,16); o15 := add(o14,o12); res := add(o15,o8); Round up to next highest power of 2 o1 := sub(x,1); o2 := shr(o1,1); o3 := or(o1,o2); o4 := shr(o3,2); o5 := or(o3,o4); o6 := shr(o5,4); o7 := or(o5,o6); o8 := shr(o7,8); o9 := or(o7,o8); o10 := shr(o9,16); o11 := or(o9,o10); res := add(o10,1);

15 Given: Specification of desired functionality Specification of library components Synthesize a straight-line program 14 Problem Definition where Each variable in is either or some where k<j is a permutation of 1...n that meets the desired specification. Verification Constraint

16 Specification of desired functionality Specification of library components 15 Problem Definition: Turn-off rightmost 1 bit

17 16 Synthesis Constraint Verification Constraint Synthesis Constraint

18 represents which component goes on which location (line #) and from which location does it gets its input arguments. We encode this by location variables L. 17 Idea # 1: Reduce Second-order Quantification in Synthesis Constraint to First Order

19 18 Example: Possible programs that use 2 components and their Representation using Location Variables

20 Consistency Constraint: Every line in the program should have at most one component. 19 Encoding Well-formedness of Programs Acyclicity Constraint: A variable should be initialized before being used. The following constraint ensures that L assignments correspond to well-formed programs.

21 20 Encoding data-flow The following constraint describes connections between inputs and outputs of various components.

22 21 Idea # 1: Reduce Second-order Quantification in Synthesis Constraint to First Order

23 Synthesis constraint is of the form: 9 L 8 Y F(L,Y) Finite Synthesis Step 9 L F(L,y 1 ) Æ … Æ F(L,y n ) Verification Step Does 8 Y F(S,Y) hold? Or, equivalently 9 Y : F(S,Y) Solution Y = y n+1 return S 22 Choose some values y1,..,yn for y Solution L = S Failure No Solution Idea # 2: Using CEGIS style procedure to solve the Synthesis Constraint

24 Experiments: Comparison with Brute-force Search 23 ProgramBrahmaAHA time Namelinesiterstime P12230.1 P22330.1 P32310.1 P42230.1 P52320.1 P62220.1 P73212 P83211 P93267 P103147610 P1137579 P12396710 ProgramBrahmaAHA time Namelinesiterstime P13446X P144460X P1548119X P164562X P174678109 P186546X P196535X P2076108X P218528X P2288279X P231081668X P24129224X P2516112779X

25 Synthesizing Geometry Constructions PLDI 2011: Gulwani, Korthikanti, Tiwari.

26 Concept Language –Programs Straight-line programs –Automata –Queries –Sequences User Intent –Logic, Natural Language –Examples, Demonstrations/Traces Search Technique –SAT/SMT solvers (Formal Methods) –A*-style goal-directed search (AI) –Version space algebras (Machine Learning) 25 Dimensions in Synthesis PPDP 2010: “Dimensions in Program Synthesis”, Gulwani.

27 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 26 Ruler/Compass based Geometry Constructions X Z Y L1 L2 N C

28 Draw a regular hexagon given a side. Given 3 parallel lines, draw an equilateral triangle whose vertices lie on the parallel lines. Given 4 points, draw a square whose sides contain those points. 27 Other Examples of Geometry Constructions

29 Good platform for teaching logical reasoning. –Visual Nature: Makes it more accessible. Exercises both logical/visual abilities of left/right brain. –Fun Aspect: Ruler/compass restrictions make it fun, as in sports. Application in dynamic geometry or animations. –“Constructive” geometry macros (unlike numerical methods) enable fast re-computation of derived objects from free (moving) objects. 28 Significance

30 Types: Point, Line, Circle Methods: Ruler(Point, Point) -> Line Compass(Point, Point) -> Circle Intersect(Circle, Circle) -> Pair of Points Intersect(Line, Circle) -> Pair of Points Intersect(Line, Line) -> Point Geometry Program: A straight-line composition of the above methods. 29 Programming Language for Geometry Constructions

31 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 30 Example Problem: Program 1.C1 = Compass(X,Y); 2.C2 = Compass(Y,X); 3. = Intersect(C1,C2); 4.L1 = Ruler(P1,P2); 5.D1 = Compass(Z,X); 6.D2 = Compass(X,Z); 7. = Intersect(D1,D2); 8.L2 = Ruler(R1,R2); 9.N = Intersect(L1,L2); 10.C = Compass(N,X); X Z Y C1 C2 P1 P2 L1 D2 D1 R1 R2 L2 N C

32 Conjunction of predicates over arithmetic expressions Predicates p := e 1 = e 2 | e 1  e 2 | e 1 · e 2 Arithmetic Expressions e := Distance(Point, Point) | Slope(Point, Point) | e 1 § e 2 | c 31 Specification Language for Geometry Programs

33 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. Precondition: Slope(X,Y)  Slope(X,Z) Æ Slope(X,Y)  Slope(Z,X) Postcondition: LiesOn(X,C) Æ LiesOn(Y,C) Æ LiesOn(Z,C) Where LiesOn(X,C) ´ Distance(X,Center(C)) = Radius(C) Example Problem: Precondition/Postcondition 32

34 Let P be a geometry program that computes outputs O from inputs I. Verification Problem: Check the validity of the following Hoare triple. Assume Pre(I); P Assert Post(I,O); Synthesis Problem: Given Pre(I), Post(I,O), find P such that the above Hoare triple is valid. 33 Verification/Synthesis Problem for Geometry Programs

35 Pre(I), P, Post(I,O) a)Symbolic decision procedures are complex. 34 Approaches to Verification Problem

36 Problem: Given two polynomials P1 and P2, determine whether they are equivalent. The naïve deterministic algorithm of expanding polynomials to compare them term-wise is exponential. A simple randomized test is probabilistically sufficient: –Choose random values r for polynomial variables x –If P1(r) ≠ P2(r), then P1 is not equivalent to P2. –Otherwise P1 is equivalent to P2 with high probability, 35 Randomized Polynomial Identity Testing

37 Pre(I), P, Post(I,O) a)Symbolic decision procedures are complex. b)New efficient approach: Random Testing! 1.Choose I’ randomly from the set { I | Pre(I) }. 2.Compute O’ := P(I’). 3.If O’ satisfies Post(I’,O’) output “Verified”. Correctness Proof of (b): Objects constructed by P can be described using polynomial ops (+,-,*), square-root & division operator. The randomized polynomial identity testing algorithm lifts to square-root and division operators as well ! 36 Approaches to Verification Problem

38 Synthesis Algorithm: // First obtain a random input-output example. 1.Choose I’ randomly from the set { I | Pre(I) }. 2.Compute O’ s.t. Post(I’,O’) using numerical methods. // Now obtain a construction that can generate O’ from I’ (using exhaustive search). 3.S := I’; 4.While (S does not contain O’) 5. S := S [ { M(O 1,O 2 ) | O i 2 S, M 2 Methods } 6.Output construction steps for O’. 37 Idea 1 (from Theory): Symbolic Reasoning -> Concrete

39 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 38 Error Probability of the algorithm is extremely low. … L1 = Ruler(P1,P2); … L2 = Ruler(R1,R2); N = Intersect(L1,L2); C = Compass(N,X); 38 For an equilateral 4 XYZ, incenter coincides with circumcenter N. But what are the chances of choosing a random 4 XYZ to be an equilateral one? X Z Y L1 L2 N C

40 Synthesis algorithm times out because programs are large. Identify a library of commonly used patterns (pattern = “sequence of geometry methods”) –E.g., perpendicular/angular bisector, midpoint, tangent, etc. S := S [ { M(O 1,O 2 ) | O i 2 S, M 2 Methods } S := S [ { M(O 1,O 2 ) | O i 2 S, M 2 LibMethods } Two key advantages: –Search space: large depth -> small depth –Easier to explain solutions to students. 39 Idea 2 (from PL): High-level Abstractions

41 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 40 Use of high-level abstractions reduces program size 1.C1 = Compass(X,Y); 2.C2 = Compass(Y,X); 3. = Intersect(C1,C2); 4.L1 = Ruler(P1,P2); 5.D1 = Compass(Z,X); 6.D2 = Compass(X,Z); 7. = Intersect(D1,D2); 8.L2 = Ruler(R1,R2); 9.N = Intersect(L1,L2); 10.C = Compass(N,X); 1.L1 = PBisector(X,Y); 2.L2 = PBisector(X,Z); 3.N = Intersect(L1,L2); 4.C = Compass(N,X);

42 Synthesis algorithm is inefficient because the search space is too wide and hence still huge. Prune forward search by using A* style heuristics. S := S [ { M(O 1,O 2 ) | O i 2 S, M 2 LibMethods } S := S [ {M(O 1,O 2 ) | O i 2 S, M 2 LibMethods, IsGood(M(O 1,O 2 )) } Example: If a method constructs a line L that passes through a desired output point, then L is “good” (i.e., worth constructing). 41 Idea 3 (from AI): Goal Directed Search

43 Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 42 Effectiveness of Goal-directed search 42 L1 and L2 are immediately constructed since they pass through output point N. On the other hand, other lines like angular bisectors are not eagerly constructed. X Z Y L1 L2 N C

44 25 benchmark problems. such as: Construct a square whose extended sides pass through 4 given points. 18 problems less than 1 second. 4 problems between 1-3 seconds. 3 problems 13-82 seconds. Idea 2 (high-level abstractions) reduces programs of size 3-45 to 3-13. Idea 3 (goal-directedness) improves performance by factor of 10-1000 times on most problems. 43 Experimental Results

45 44 Search space Exploration: With/without goal-directness

46 Concept Language –Programs Straight-line programs –Automata –Queries –Sequences User Intent –Logic, Natural Language –Examples, Demonstrations/Traces Search Technique –SAT/SMT solvers (Formal Methods) –A*-style goal-directed search (AI) –Version space algebras (Machine Learning) 45 Dimensions in Synthesis PPDP 2010: “Dimensions in Program Synthesis”, Gulwani.

47 Lecture 2 –Section 4 in WAMBSE 2012 keynote paper “Synthesis from Examples”, Gulwani. Lab –Section 4 in WAMBSE 2012 keynote paper. –NCERT Online Book Website. http://ncert.nic.in/NCERTS/textbook/textbook.htm Lecture 3 –Sections 1-3 in WAMBSE 2012 keynote paper 46 Optional Advance Preparation

48 Motivation –Online learning sites: Khan academy, Edx, Udacity, Coursera Increasing class sizes with even less personal attention –New technologies: Tablets/Smartphones, NUI, Cloud Various Aspects –Solution Generation –Problem Generation –Automated Grading –Content Entry Various Domains –K-12: Mathematics, Physics, Chemistry –Undergraduate: Introductory Programming, Automata Theory –Language Learning 47 Intelligent Tutoring Systems


Download ppt "Dimensions in Synthesis Sumit Gulwani Microsoft Research, Redmond May 2012."

Similar presentations


Ads by Google