Program Synthesis for Computer-aided Education Sumit Gulwani sumitg@microsoft.com Microsoft Research, Redmond August 2013 Marktoberdorf Summer School Lectures: Part 3 Potential Users of Synthesis Technology Algorithm Designers Software Developers Most Useful Target Most Transformational Target End-Users Students and Teachers • Vision for End-users: Enable people to have (automated) personal assistants. • Vision for Education: Enable interactive & personalized Education. 1 Connections between End-User Programming & Computer-aided Education • End-User teaches Computer & Computer uses that knowledge to automate repetitive tasks. Teacher teachers Computer & Computer uses that knowledge to teach Students. • Interactivity between End-User & Computer to resolve ambiguities. Interactivity between Student & Computer to resolve student’s confusions. Implications: • End-User Programming research can fuel Computer-aided Education research. • And vice-versa! 2 Computer-aided Education Various tasks • Problem Synthesis • Solution Synthesis • Feedback Synthesis • Content Authoring Various subject-domains • Arithmetic, Algebra, Geometry • Programming, Automata, Logic • Board Games, Language Learning • ... Reference: Example Based Learning in Computer-aided STEM Education MSR-TR-2013-50, Gulwani. 3 Content Classification • Procedural – Mathematical Procedures • Addition, Long division, GCD/LCM, Gaussian Elimination – Algorithmic Procedures • Students asked to show understanding of classical algorithms on specific inputs. – BFS, insertion sort, shortest path – translating regular expression into an automaton. • Conceptual – Proofs • Algebraic theorems, Natural deduction, Non-regularity – Constructions • Geometric ruler/compass based constructions, Automata constructions, Algorithms 4 Problem Synthesis Problem Synthesis Motivation • Problems similar to a given problem. – Avoid copyright issues – Prevent cheating in MOOCs (Unsynchronized instruction) • Problems of a given difficulty level and concept usage. – Generate progressions – Generate personalized workflows Key Ideas ο Procedural Content: Test input generation techniques 6 Problem Synthesis: Addition Procedure Concept Single digit addition Multiple digit w/o carry Single carry Two single carries Double carry Triple carry Extra digit in i/p & new digit in o/p Reference: A Trace-based Framework for Analyzing and Synthesizing Educational Progressions; CHI 2013; Andersen, Gulwani, Popovic. 7 Problem Synthesis: Addition Procedure Concept Trace Characteristic Single digit addition L Multiple digit w/o carry LL+ Single carry L* (LC) L* Two single carries L* (LC) L+ (LC) L* Double carry L* (LCLC) L* Triple carry L* (LCLCLCLC) L* Extra digit in i/p & new digit in o/p L* CLDCE Reference: A Trace-based Framework for Analyzing and Synthesizing Educational Progressions; CHI 2013; Andersen, Gulwani, Popovic. 8 Problem Synthesis: Addition Procedure Concept Trace Characteristic Sample Input Single digit addition L 3+2 Multiple digit w/o carry LL+ 1234 +8765 Single carry L* (LC) L* 1234 + 8757 Two single carries L* (LC) L+ (LC) L* 1234 + 8857 Double carry L* (LCLC) L* 1234 + 8667 Triple carry L* (LCLCLCLC) L* 1234 + 8767 Extra digit in i/p & new digit in o/p L* CLDCE 9234 + 900 Reference: A Trace-based Framework for Analyzing and Synthesizing Educational Progressions; CHI 2013; Andersen, Gulwani, Popovic. 9 Comparing Progressions: Integer Comparison Green Progression: Jump Math Blue Progression: Skill Sharpeners Green Progression moves (quickly) into involved problems that involve comparing more digits. But it ignore an entire class of levels (H and L)! 10 Problem Synthesis Motivation • Problems similar to a given problem. – Avoid copyright issues – Prevent cheating in MOOCs (Unsynchronized instruction) • Problems of a given difficulty level and concept usage. – Generate progressions – Generate personalized workflows Key Ideas • Procedural Content: Test input generation techniques • Conceptual Content ο Template based generalization 11 Trigonometry Problem Example Problem: sec π₯ + cos π₯ Query: π1 π₯ ± π2 (π₯) π1 ≠ π5 sec π₯ − cos π₯ = tan2 π₯ + sin2 π₯ π3 π₯ ± π4 π₯ = π52 π₯ ± π62 (π₯) New problems generated: csc π₯ + cos π₯ csc π₯ − cos π₯ = cot 2 π₯ + sin2 π₯ (csc π₯ − sin π₯)(csc π₯ + sin π₯) = cot 2 π₯ + cos 2 π₯ (sec π₯ + sin π₯)(sec π₯ − sin π₯) = tan2 π₯ + cos 2 π₯ : (tan π₯ + sin π₯)(tan π₯ − sin π₯) = tan2 π₯ − sin2 π₯ (csc π₯ + cos π₯)(csc π₯ − cos π₯) = csc 2 π₯ − cos 2 π₯ : Reference: Automatically generating algebra problems; AAAI 2012; Rohit Singh, Sumit Gulwani, Sriram Rajamani. 12 Trigonometry Problem Example Problem: sec π₯ + cos π₯ Query: π1 π₯ ± π2 (π₯) π1 ≠ π5 sec π₯ − cos π₯ = tan2 π₯ + sin2 π₯ π3 π₯ ± π4 π₯ = π52 π₯ ± π62 (π₯) New problems generated: csc π₯ + cos π₯ csc π₯ − cos π₯ = cot 2 π₯ + sin2 π₯ (csc π₯ − sin π₯)(csc π₯ + sin π₯) = cot 2 π₯ + cos 2 π₯ (sec π₯ + sin π₯)(sec π₯ − sin π₯) = tan2 π₯ + cos 2 π₯ : (tan π₯ + sin π₯)(tan π₯ − sin π₯) = tan2 π₯ − sin2 π₯ (csc π₯ + cos π₯)(csc π₯ − cos π₯) = csc 2 π₯ − cos 2 π₯ : Reference: Automatically generating algebra problems; AAAI 2012; Rohit Singh, Sumit Gulwani, Sriram Rajamani. 13 Limits/Series Problem π Example Problem: π Query: lim π→∞ π=0 lim π→∞ π=0 2π 2 + π + 1 5 = π 2 5 πΆ0 π 2 + πΆ1 π + πΆ2 πΆ3 π πΆ4 = πΆ5 C0 ≠ 0 ∧ gcd πΆ0 , πΆ1 , πΆ2 = gcd πΆ4 , πΆ5 = 1 New problems generated: π lim π→∞ π=0 π lim π→∞ π=0 π 2 3π + 2π + 1 7 = π 3 7 lim π→∞ π 2 π 3 = π 2 3 π=0 lim π→∞ π=0 3π 2 + 3π + 1 =4 π 4 5π 2 + 3π + 3 =6 π 6 14 Integration Problem Example Problem: Query: (csc π₯) (csc π₯ − cot π₯) ππ₯ = csc π₯ − cot π₯ π0 π₯ π1 π₯ ± π2 π₯ ππ₯ = π4 π₯ ± π5 (π₯) π1 ≠ π2 ∧ π4 ≠ π5 New problems generated: (tan π₯) (cos π₯ + sec π₯) ππ₯ = sec π₯ − cos π₯ (sec π₯) (tan π₯ + sec π₯) ππ₯ = sec π₯ + cot π₯ (cot π₯) (sin π₯ + csc π₯) ππ₯ = sin π₯ − csc π₯ 15 Determinant Problem Ex. Problem π₯+π¦ π§π₯ π¦π§ 2 π§π₯ π¦+π§ π₯π¦ πΉ0 (π₯, π¦, π§) πΉ1 (π₯, π¦, π§) Query πΉ3 (π₯, π¦, π§) πΉ4 (π₯, π¦, π§) πΉ6 (π₯, π¦, π§) πΉ7 (π₯, π¦, π§) 2 π§π¦ π₯π¦ π§+π₯ = 2π₯π¦π§ π₯ + π¦ + π§ 3 2 πΉ2 (π₯, π¦, π§) πΉ5 (π₯, π¦, π§) πΉ8 (π₯, π¦, π§) = πΆ10 πΉ9 (π₯, π¦, π§) πΉπ β πΉπ π₯ → π¦; π¦ → π§; π§ → π₯ π€βπππ π, π ∈ { 4,0 , 8,4 , 5,1 , … } New problems generated: π¦2 π§+π¦ π§2 2 π¦π§ + π¦ 2 π¦π§ π§π₯ π₯2 π§2 π₯+π§ π₯π¦ π§π₯ + π§ 2 π§π₯ 2 π¦+π₯ π¦2 π₯2 π₯π¦ π¦π§ π₯π¦ + π₯ 2 2 = 2 π₯π¦ + π¦π§ + π§π₯ 3 = 4π₯ 2 π¦ 2 π§ 2 16 Randomized Polynomial Identity Testing • 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. Proof: • by induction over number of polynomial variables. • Base case: If P1 ≡ P2, then P1-P2 has at most d zeros where d = max(degree(P1), degree(P2)). 17 Randomized Identity Testing of Analytic Functions Let π π , π(π) be non-identical real-valued analytic fns over π π . Let π ∈ π π be selected uniformly at random. Then, with high probability over this selection, π π ≠ π π . Proof: • Analytic fns have isolated zeroes, i.e., for every zero point of an analytic fn, there exists a neighborhood in which the fn is non-zero. • Hence, # of non-zero points of the non-zero analytic fn π π − π(π) dominates # of zero points. 18 Problem Synthesis Motivation • Problems similar to a given problem. – Avoid copyright issues – Prevent cheating in MOOCs (Unsynchronized instruction) • Problems of a given difficulty level and concept usage. – Generate progressions – Generate personalized workflows Key Ideas • Procedural Content: Test input generation techniques • Conceptual Content ο Template based generalization 19 Problem Synthesis: Sentence Completion 1. The principal characterized his pupils as _________ they were pampered and spoiled by their indulgent parents. becaus 2. The commentator characterized the electorate as _________ becaus was unpredictable and given to constantly shifting moods. (a) cosseted (b) disingenuous (c) corrosive (d) laconic (e) mercurial One of the problems is a real problem from SAT (standardized US exam), while the other one was automatically generated! From problem 1, we generate template T1: *1 characterized *2 as *3 because *4 We specialize T1 to template T2: *1 characterized *2 as mercurial because *4 Problem 2 is an instance of T2. Problem Synthesis Motivation • Problems similar to a given problem. – Avoid copyright issues – Prevent cheating in MOOCs (Unsynchronized instruction) • Problems of a given difficulty level and concept usage. – Generate progressions – Generate personalized workflows Key Ideas • Procedural Content: Test input generation techniques • Conceptual Content – Template based generalization ο Symbolic methods (solution generation in reverse) 21 Natural Deduction Prove that: π₯1 ∨ π₯2 ∧ π₯3 and π₯1 → π₯4 and π₯4 → π₯5 implies π₯2 ∨ π₯5 Inference Rule Premises Conclusion Modus Ponens (MP) π → π, π π Hypothetical Syllogism (HS) π → π, π → π π→π Disjunctive Syllogism (DS) π ∨ π, ¬π π Simplification (Simp) π∧π π Replacement Rule Proposition Equiv. Proposition Distribution π ∨ (π ∧ π) Double Negation 𠬬π Implication π→π ¬π ∨ π Equivalence π≡π π ∨ π ∧ (π ∨ π) π → π ∧ (π → π) Reference: Automatically Generating Problems and Solutions for Natural Deduction 22 IJCAI 2013; Umair Ahmed, Sumit Gulwani, Amey Karkare Similar Problem Synthesis: Natural Deduction Similar Problems = those that have a minimal proof with the same sequence of inference rules as used by a minimal proof of given problem. Premise 1 Premise 2 Premise 3 Conclusion π₯1 ∨ (π₯2 ∧ π₯3 ) π₯1 → π₯4 π₯4 → π₯5 π₯2 ∨ π₯5 Similar Problems Premise 1 Premise 2 Premise 3 Conclusion π₯1 ≡ π₯2 π₯3 → ¬π₯2 (π₯4 → π₯5 ) → π₯3 π₯1 → (π₯π¦ ∧ ¬π₯5 ) π₯1 ∧ (π₯2 → π₯3 ) π₯1 ∨ π₯4 → ¬π₯5 π₯2 ∨ π₯5 (π₯1 ∨ π₯2 ) → π₯3 π₯3 → π₯1 ∧ π₯4 (π₯1 → π₯2 ) → π₯3 π₯3 → ¬π₯4 π₯1 → π₯2 ∧ π₯3 π₯4 → ¬π₯2 π₯1 ∧ π₯4 → π₯5 π₯1 ∨ π₯5 ∨ π₯4 π₯3 ≡ π₯5 → π₯4 π₯1 ∨ π₯4 ∧ ¬π₯5 π₯1 → π₯5 π₯5 ∨ π₯2 → π₯1 π₯1 → π₯3 ≡ ¬π₯5 23 Parameterized Problem Synthesis: Natural Deduction Parameters: # of premises = 3, Size of propositions ≤ 4 # of variables = 3, # of inference steps = 2 Inference rules = { DS, HS } Parameterized Problems Premise 1 Premise 2 Premise 3 Conclusion (π₯1 → π₯3 ) → π₯2 π₯2 → π₯3 ¬π₯3 π₯1 ∧ ¬π₯3 π₯3 ≡ π₯1 → π₯2 ¬π₯2 π₯1 ∧ ¬π₯3 π₯3 → π₯1 π₯1 ≡ π₯3 ∨ π₯1 ≡ π₯2 (π₯1 ≡ π₯2 ) → π₯3 ¬π₯3 π₯1 ≡ π₯3 π₯1 ≡ ¬π₯3 π₯2 ∨ π₯1 π₯3 → ¬π₯2 π₯1 ∧ ¬π₯3 π₯3 → π₯1 π₯1 → π₯2 ∧ π₯3 π₯3 → ¬π₯2 ¬π₯3 24 Problem Synthesis Motivation • Problems similar to a given problem. – Avoid copyright issues – Prevent cheating in MOOCs (Unsynchronized instruction) • Problems of a given difficulty level and concept usage. – Generate progressions – Generate personalized workflows Key Ideas • Procedural Content: Test input generation techniques • Conceptual Content – Template based generalization ο Symbolic methods (solution generation in reverse) 25 Problem Generation: Board Games Game Rules • allows variants of classic games. Tic-Tac-Toe 4*4 Row/Column only Expertise level of player/opponent • allows leveling the playing field. Reference: Automatic Generation of Starting Positions in Board Games; Technical Report; Umair Ahmed, Krishnendu Chatterjee, Sumit Gulwani. Solution Synthesis Solution Synthesis Motivation • Synthesize sample solutions to new problems. • Synthesize customized solutions or complete unfinished ones. • Inform solution characteristics during problem generation. Key Ideas ο Procedural Content: Programming by Demonstration 28 Solution Synthesis: GCF Computation Time-stamped sequence of (location, value) pairs Programming by Demonstration Spreadsheet Program Can also be used to synthesize incorrect procedures from buggy traces! Reference: Programming by Demonstration framework applied to procedural math 29 problems; Technical Report; Andersen, Gulwani, Popovic. Solution Synthesis Motivation • Synthesize sample solutions to new problems. • Synthesize customized solutions or complete unfinished ones. • Inform solution characteristics during problem generation. Key Ideas • Procedural Content: Programming by Demonstration ο Conceptual Content – Perform reasoning over models (vs. abstract symbolic reasoning). – Reduce solution space to solutions with small length. 30 Ruler/Compass based Geometry Constructions Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. C L1 L2 N Z X Reference: Synthesizing Geometry Constructions PLDI 2011; Gulwani, Korthikanti, Tiwari Y 31 Other Examples of Geometry Constructions • 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. 32 Significance • 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. 33 Programming Language for Geometry Constructions 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. 34 Example: Geometry Program Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 1. C1 = Compass(X,Y); 2. C2 = Compass(Y,X); 3. <P1,P2> = Intersect(C1,C2); 4. L1 = Ruler(P1,P2); 5. D1 = Compass(Z,X); 6. D2 = Compass(X,Z); 7. <R1,R2> = Intersect(D1,D2); 8. L2 = Ruler(R1,R2); 9. N = Intersect(L1,L2); 10. C = Compass(N,X); C L1 N C1 D1 R1 Z R2 P1 X D2 L2 C2 Y P2 35 Specification Language for Geometry Programs Conjunction of predicates over arithmetic expressions Predicates p := e1 = e2 | e1 οΉ e2 | e1 · e2 Arithmetic Expressions e := | | | Distance(Point, Point) Slope(Point, Point) e 1 § e2 c 36 Example: Precondition/Postcondition 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) 37 Verification/Synthesis Problem for Geometry Programs • 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. 38 Approaches to Verification Problem Pre(I), P, Post(I,O) a) Symbolic decision procedures are complex. 39 Approaches to Verification Problem Pre(I), P, Post(I,O) a) Symbolic decision procedures are complex. b) 1. 2. 3. New efficient approach: Random Testing! Choose I’ randomly from the set { I | Pre(I) }. Compute O’ := P(I’). 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 ! 40 Idea 1 (from Theory): Symbolic Reasoning -> Concrete 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(O1,O2) | Oi 2 S, M 2 Methods } 6. Output construction steps for O’. 41 Error Probability of the algorithm is extremely low. Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. C L1 … L1 = Ruler(P1,P2); N … L2 = Ruler(R1,R2); N = Intersect(L1,L2); Z C = Compass(N,X); X L2 Y • For an equilateral 4XYZ, incenter coincides with circumcenter N. • But what are the chances of choosing a random 4XYZ to be an equilateral one? 42 Idea 2 (from PL): High-level Abstractions 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(O1,O2) | Oi 2 S, M 2 Methods } S := S [ { M(O1,O2) | Oi 2 S, M 2 LibMethods } • Two key advantages: – Search space: large depth -> small depth – Easier to explain solutions to students. 43 Use of high-level abstractions reduces program size Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. 1. C1 = Compass(X,Y); 2. C2 = Compass(Y,X); 3. <P1,P2> = Intersect(C1,C2); 4. L1 = Ruler(P1,P2); 5. D1 = Compass(Z,X); 6. D2 = Compass(X,Z); 7. <R1,R2> = Intersect(D1,D2); 8. L2 = Ruler(R1,R2); 9. N = Intersect(L1,L2); 10. C = Compass(N,X); 1. 2. 3. 4. L1 = PBisector(X,Y); L2 = PBisector(X,Z); N = Intersect(L1,L2); C = Compass(N,X); 44 Idea 3 (from AI): Goal Directed Search 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(O1,O2) | Oi 2 S, M 2 LibMethods } S := S [ {M(O1,O2) | Oi2S, M2LibMethods, IsGood(M(O1,O2)) } • Example: If a method constructs a line L that passes through a desired output point, then L is “good” (i.e., worth constructing). 45 Effectiveness of Goal-directed search Given a triangle XYZ, construct circle C such that C passes through X, Y, and Z. C L1 L2 N Z X Y • 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. 46 Experimental Results 25 benchmark problems. • Performance: 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. 47 Search space Exploration: With/without goal-directness 48 Solution Synthesis Motivation • Synthesize sample solutions to new problems. • Synthesize customized solutions or complete unfinished ones. • Inform solution characteristics during problem generation. Key Ideas • Procedural Content: Programming by Demonstration ο Conceptual Content – Perform reasoning over models (vs. abstract symbolic reasoning). – Reduce solution space to solutions with small length. 49 Natural Deduction Prove that: π₯1 ∨ π₯2 ∧ π₯3 and π₯1 → π₯4 and π₯4 → π₯5 implies π₯2 ∨ π₯5 Inference Rule Premises Conclusion Modus Ponens (MP) π → π, π π Hypothetical Syllogism (HS) π → π, π → π π→π Disjunctive Syllogism (DS) π ∨ π, ¬π π Simplification (Simp) π∧π π Replacement Rule Proposition Equiv. Proposition Distribution π ∨ (π ∧ π) Double Negation 𠬬π Implication π→π ¬π ∨ π Equivalence π≡π π ∨ π ∧ (π ∨ π) π → π ∧ (π → π) Reference: Automatically Generating Problems and Solutions for Natural Deduction 50 IJCAI 2013; Umair Ahmed, Sumit Gulwani, Amey Karkare Key Ideas • Represent propositions using (bitvector based) truth table representation. – avoids expensive symbolic reasoning and reduces inference rule applications to simple bitvector operations. • Two-step proof search – Abstract proof (involving only inference rules) over truthtables. – Concretize proof (by adding replacement rules) in between any two neighboring inference rule application. 51 Solution Synthesis: Natural Deduction Prove that: π₯1 ∨ π₯2 ∧ π₯3 and π₯1 → π₯4 and π₯4 → π₯5 Step Proposition Reason P1 π₯1 ∨ π₯2 ∧ π₯3 Premise implies: π₯2 ∨ π₯5 P2 π₯1 → π₯4 Premise P3 π₯4 → π₯5 Premise 1 (π₯1 ∨ π₯2 ) ∧ (π₯1 ∨ π₯3 ) P1, Distr. 2 π₯1 ∨ π₯2 1, Simp. 3 π₯1 → π₯5 P2, P3, HS 4 π₯2 ∨ π₯1 2, Comm. Step Truth Table Reason P1 1048575 Premise P2 4294914867 Premise 5 ¬¬π₯2 ∨ π₯1 4. Double Neg. P3 3722304989 Premise 6 ¬π₯2 → π₯1 5, Implication 1 16777215 P1,Simp. 7 6,3, HS. 2 4294923605 P2,P3,HS ¬π₯2 → π₯5 8 ¬¬π₯2 ∨ π₯5 7, Implication Concl 1442797055 1,2,HS Abstract Proof Concl π₯2 ∨ π₯5 Concrete Proof 8, Double Neg. 52 Key Challenge How to apply inference rules over truth-tables? • Apply inference rules over propositions and project them to truth-tables. • Compute & store this information offline (in a datastructure that we call Universal Proof Graph). – Space and time requirements? • We leverage the fact that real-world problems employ small-sized propositions. 53 # of propositions/truth-tables over n variables & size s Number of propositions over n variables and having size at most s. Size of proposition = number of binary operators. Number of truth-tables over n variables and having size at most s. Size of truth-table = minimum size of any corresponding proposition. 54 Universal Proof Graph (UPG) Size of the UPG for various values of n and size at most 4 & Time taken to compute the UPG. 55 Feedback Synthesis 56 Feedback Synthesis Motivation • Makes teachers more effective. – Saves them time. – Provides immediate insights on where students are struggling. • Can enable rich interactive experience for students. – Generation of hints. – Pointer to simpler problems depending on kind of mistake. Key Ideas: ο Procedural Content: Use PBE techniques to learn buggy procedures in a student’s mind. 57 Feedback Synthesis for Procedural Problems • Ashlock identified buggy computational patterns for various procedures. Following are some bugs for addition. – Add each column and write the sum below each column, even if it is greater than nine. – Add each column, from left to right. If the sum > 9, write the tens digit beneath the column and the ones digit above the column to the right. • Van Lehn identified >100 bugs in subtraction alone. Key Idea: Use Programming by Demonstration technology (also used for solution synthesis for procedural problems) for synthesizing such buggy procedures. 58 Feedback Synthesis Motivation • Makes teachers more effective. – Saves them time. – Provides immediate insights on where students are struggling. • Can enable rich interactive experience for students. – Generation of hints. – Pointer to simpler problems depending on kind of mistake. Key Ideas: • Procedural Content: Use PBE techniques to learn buggy procedures in a student’s mind. • Conceptual Content: Various feedback metrics ο Counterexamples: Inputs on which the solution is not correct 59 Counterexample based Feedback: PexForFun 60 Buggy Program for Array Reverse using System; 6:28::50 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} 61 Buggy Program for Array Reverse using System; 6:32::01 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length-1; i < a.Length-1; i--) { b[count] = a[i]; count++; } return b; }} 62 Buggy Program for Array Reverse using System; 6:32::32 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length-1; i < a.Length-1; i--) { b[count] = a[i]; count++; } return b; }} No change! Sign of Frustation? 63 Buggy Program for Array Reverse using System; 6:33::19 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i <= a.Length; i--) { b[count] = a[i]; count++; } return b; }} 64 Buggy Program for Array Reverse using System; 6:33::55 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { Console.Writeline(i); b[count] = a[i]; count++; } return b; }} Same as initial attempt except Console.Writeline! 65 Buggy Program for Array Reverse using System; 6:34::06 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { Console.Writeline(i); b[count] = a[i]; count++; } return b; }} No change! Sign of Frustation? 66 Buggy Program for Array Reverse using System; 6:34::56 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i <= a.Length; i--) { Console.Writeline(i); b[count] = a[i]; count++; } return b; }} The student has tried this before! 67 Buggy Program for Array Reverse using System; 6:36::24 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} Same as initial attempt! 68 Buggy Program for Array Reverse using System; 6:37::39 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length-1; i < a.Length-1; i--) { b[count] = a[i]; count++; } return b; }} The student has tried this before! 69 Buggy Program for Array Reverse using System; 6:38::11 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i > 0; i--) { b[count] = a[i]; count++; } return b; }} Almost correct! (a[i-1] instead of a[i] in loop body) 70 Buggy Program for Array Reverse using System; 6:38::44 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i >= 0; i--) { b[count] = a[i]; count++; } return b; }} Student going in wrong direction! 71 Buggy Program for Array Reverse using System; 6:39::33 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} Back to bigger error! 72 Buggy Program for Array Reverse using System; 6:39::45 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} No change! Frustation! 73 Buggy Program for Array Reverse using System; 6:40::27 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} No change! More Frustation!! 74 Buggy Program for Array Reverse using System; 6:40::57 AM public class Program { public static int[] Puzzle(int[] a) { int[] b = new int[a.Length]; int count = 0; for(int i=a.Length; i < a.Length; i--) { b[count] = a[i]; count++; } return b; }} No change! Too Frustated now!!! Gives up. 75 Counterexamples are not sufficient! "Not only did it take 1-2 weeks to grade problem, but the comments were entirely unhelpful in actually helping us fix our errors. …. Apparently they don't read the code -- they just ran their tests and docked points mercilessly. What if I just had a simple typo, but my algorithm was fine? ....“ - Student Feedback from MIT 6.00 course, 2013. 76 Feedback Synthesis Motivation • Makes teachers more effective. – Saves them time. – Provides immediate insights on where students are struggling. • Can enable rich interactive experience for students. – Generation of hints. – Pointer to simpler problems depending on kind of mistake. Key Ideas: • Procedural Content: Use PBE techniques to learn buggy procedures in a student’s mind. • Conceptual Content: Various feedback metrics – Counterexamples: Inputs on which the solution is not correct. ο Edit distance to a nearest correct solution. 77 Correction Model for Programming Assignments Array Index: v[a] -> v[{a+1, a-1}] Increment: v++ -> { ++v, v--, --v } Conditional: a op b -> a ops b where ops = { <, >, <=, >=, ==, != } Initialization: v=n -> v={n+1, n-1, 0} Return Value: return v -> return ?v Key Idea: Finding minimal set of such changes that convert a buggy solution into a correct one is phrased as a sketch problem. Reference: Automated Feedback Generation for Introductory Programming Assignments; PLDI 2013; Singh, Gulwani, Solar-Lezama 78 Array Reverse i = 1 front <= back i <= a.Length --back Experimental Results 13,365 incorrect attempts for 13 Python problems. (obtained from Introductory Programming course at MIT and its MOOC version on the EdX platform) • Average time for feedback = 10 seconds • Feedback generated for 64% of those attempts. • Reasons for failure to generate feedback – Completely incorrect solutions – Big conceptual errors – Timeout (4 min) Tool accessible at: http://sketch1.csail.mit.edu/python-autofeedback/ 80 Feedback Synthesis Motivation • Makes teachers more effective. – Saves them time. – Provides immediate insights on where students are struggling. • Can enable rich interactive experience for students. – Generation of hints. – Pointer to simpler problems depending on kind of mistake. Key Ideas: • Procedural Content: Use PBE techniques to learn buggy procedures in a student’s mind. • Conceptual Content: Various feedback metrics – Counterexamples: Inputs on which the solution is not correct. – Edit distance to a nearest correct solution. ο Edit distance to the problem description (of a nearest corresponding problem description). 81 Finite State Automata Draw a DFA that accepts: { s | ‘ab’ appears in s exactly 2 times } Grade: 9/10 Feedback: One more state should be made final Attempt 1 Based on Edit-distance to a correct solution Grade: 6/10 Feedback: The DFA is incorrect on the string ‘ababb’ Attempt 2 Based on counterexamples Grade: 5/10 Feedback: The DFA accepts {s | ‘ab’ appears in s at least 2 times} Attempt 3 Based on Edit-distance to the problem description Reference: Automated Grading of DFA Constructions, IJCAI 2013; Alur, d’Antoni, Gulwani, Kini, Viswanathan 82 Feedback Synthesis Algorithm Problems described in MOSEL (syntactically enriched MSO). – Can be automatically generated from natural language. • Counterexample – Grade: Fn of density of counterexamples (weighted by size). • Edit distance to nearest solution – Grade: Fn of number & kinds of edits required to transform the student’s automaton to a correct one. • Edit distance to the problem description P – Synthesize a problem description P’ matching student’s automaton. • Brute-force search to enumerate MOSEL formulas (in size order). • Similar to synthesis of graph algorithms (OOPSLA 2010)! – Grade: Fn of number & kinds of edits to transform P to P’. 83 Experimental Results 800+ attempts to 6 automata problems (obtained from automata course at UIUC) graded by tool and 2 instructors. • 95% problems graded in <6 seconds each • Out of 131 attempts (108 distinct) for one of those problems: – 6 attempts: instructors were incorrect (gave full marks to an incorrect attempt) – 20 attempts: instructors were inconsistent (gave different marks to syntactically equivalent attempts) – 34 attempts: >= 3 point discrepancy between instructor and tool; in 20 of those, instructor agreed that tool was more fair. • More agreement between instructor/tool than instructors. • Instructors concluded that tool should be preferred over humans for consistency & scalability. Tool accessible at: http://www.automatatutor.com/ 84 Content Authoring 85 Content Authoring Motivation: Make it easy to create and edit ο Equations • Drawings Key Ideas • Allow multi-modal NUIs such as ink, speech, touch. • Error correction. • Prediction. 86 Challenges in creating Equations Text editors like Latex • Unreadable text in prefix notation WYSIWIG editors like Microsoft Word • Change of cursor positions multiple times. • Back and forth switching between mouse & keyboard Our solution: An intelligent predictive editor. • Mathematical text has low entropy and hence amenable to prediction! Joint work with Alex Polozov and Sriram Rajamani. 87 Structure Prediction We can predict likely structures from a flattened representation. This can enable math-by-speech and auto-parenthesis-error-fix. 1+cos π΄ 1−cos π΄ 1 + cos A / 1 − cos A ((1 + cos A ) / (1 − cos A )) Term Prediction (Syntactic Intellisense) tan 3π₯ tan 2π₯ tan π₯ = tan 3π₯ − tan 2π₯ − tan π₯ π¦π§ − π₯ 2 π§π₯ − π¦ 2 π₯π¦ − π§ 2 π΄1 sin3 πΌ π΄2 sin πΌ π§π₯ − π¦ 2 π₯π¦ − π§ 2 π¦π§ − π₯ 2 π΅1 sin3 π½ π΅2 sin π½ π₯π¦ − π§ 2 π¦π§ − π₯ 2 π§π₯ − π¦ 2 πΆ1 sin3 πΎ πΆ2 sin πΎ Our tool can infer colored text. 89 Term Prediction (Semantic Intellisense) Prove (csc π₯ − sin π₯)(sec π₯ − cos π₯)(tan π₯ + cot π₯) = 1 L.H.S. = 1 − sin π₯ sin π₯ = 1 − sin2 π₯ sin π₯ = cos 2 π₯ sin π₯ 1 − cos π₯ cos π₯ 1 − cos2 π₯ cos π₯ sin2 π₯ cos π₯ sin π₯ cos π₯ + cos π₯ sin π₯ sin2 π₯ + cos 2 π₯ cos π₯ sin π₯ 1 cos π₯ sin π₯ =1 90 Content Authoring Motivation: Make it easy to create and edit • Equations ο Drawings Key Ideas • Allow multi-modal NUIs such as ink, speech, touch. • Error correction. • Prediction. 91 Challenges in creating drawings Sometimes require extreme precision. • Our solution: allow pen-based sketching and use constraint solving to beautify. Can be tedious to draw sometimes. Copy-Paste doesn’t address positioning of copied objects & transformations on copied objects! • Our Solution: use synthesis to predict repetitive features. Reference: QuickDraw: Improving Drawing Experience for Geometric Diagrams; CHI 2012: Cheema, Gulwani, LaViola. 92 (Ink) Sketching meets Synthesis Beautification Beautification Prediction Prediction Architecture (Partial) Sketch/Ink Strokes Sketch Recognition Engine [HCI] Circle/Line Objects Constraint Inference Engine [Machine Learning] Constraints between Objects Model Synthesis/Beautification Engine [Constraint Solving] (Partial) Drawing Pattern Synthesis Engine [Program Synthesis] Suggestions for Drawing Completion 94 Computer Aided Education: Conclusion • Technical Perspective – Aspects: Problem/Solution/Feedback Synthesis, Content Authoring – Domains: Math, Programming, Logic, Language Learning, ... • Inter-disciplinary research area – – – – Synthesis/Search techniques HCI Natural language processing (for word problems) Machine learning (for analytics) • Value Proposition: – Short term: Improve Education (personalized + interactive) – Long Term: Ultra-intelligent computer, Model of human mind, Inter-stellar travel ο 95 Outline • Part 1: From verification to synthesis – – – – – Bitvector algorithms (PLDI 2011, ICSE 2012) General loopy programs (POPL 2010) SIMD algorithms (PPoPP 2013) Program inverses (PLDI 2011) Graph algorithms (OOPSLA 2010) • Part 2: End-user Programming (Examples & Natural Language) – – – – Syntactic string transformations: Flash Fill (POPL 2011) Semantic string transformations (VLDB 2012) Table layout transformations (PLDI 2011) Smartphone scripts (MobiSys 2013) • Part 3: Computer-aided Education – – – – Problem Synthesis (AAAI 2012, CHI 2013) Solution Synthesis (PLDI 2011, IJCAI 2013) Feedback Synthesis (PLDI 2013, IJCAI 2013) Content Authoring (CHI 2012) 96 References • Program Synthesis webpage – http://research.microsoft.com/en-us/um/people/sumitg/pubs/synthesis.html • Dimensions in Program Synthesis – PPDP 2010 Keynote paper • Programming by Example – CACM 2012 Research highlights paper • Programming by Natural Language – Mobisys 2013 paper • Education – Example based learning in Computer-aided STEM Education; MSR Technical Report; http://research.microsoft.com/en-us/um/people/sumitg/pubs/education13.pdf 97 Some More Resources on Synthesis • Bret Victor’s talks – https://vimeo.com/71278954 – http://www.youtube.com/watch?v=PUv66718DII • Program Sketching (Solar-Lezama and Bodik) – http://people.csail.mit.edu/asolar/sketch2012/ • Implicit Programming (Kuncak) – http://lara.epfl.ch/w/impro • Eran Yahav’s Synthesis projects – http://www.cs.technion.ac.il/~yahave/ • Synthesis Competitions – ICFP Programming Competition: http://icfpc2013.cloudapp.net/ – CAV 2014: http://www.syntcomp.org/synthesis-competitions-at-cav-2014/ 98 Dimensions & Applications Synthesis is a hard problem that can be tamed with proper choices for the various dimensions. • domain-specific language: design proper abstractions incl. operators, control-flow templates. • intent specification: allow interactivity & under-specifications • search techniques There are applications where you can show impact/relevance with creative algorithms that need not scale to large instances. • Especially in End-User Programming and Education. 99 Search Techniques Leverage existing paradigms/technologies • Build over verification methodology, SMT solvers Two alternate approaches • Construct programs as composition of smaller programs that solve sub-problems (Local Analysis) – PBE, SIMD, Graph • Program = Components + Relations (Global Analysis) – PBNL, Bitvector, Inverses Leverage Web, Big data & offline computation in appropriate instances. • for code/data search, natural language understanding, intelligent tutoring 100 Some Interesting/Challenging Problems • New Programming Environments structured around synthesis – direct manipulation of data – allow under-specifications including examples and NL – How would a debugging environment be for such a system? • End-User Programming of Robots • Design an Ultra-intelligent tutoring system for a subject domain of your choice 101