Complete Program Synthesis for Linear Arithmetics

Slides:



Advertisements
Similar presentations
Logical Abstract Interpretation Sumit Gulwani Microsoft Research, Redmond.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
College of Information Technology & Design
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
Introduction to Computer Science 2 Lecture 7: Extended binary trees
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
Appendix B Solving Recurrence Equations : With Applications to Analysis of Recursive Algorithms.
Class Presentation on Binary Moment Diagrams by Krishna Chillara Base Paper: “Verification of Arithmetic Circuits using Binary Moment Diagrams” by.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
Decision Procedures for Presburger Arithmetic Presented by Constantinos Bartzis.
1 8. Safe Query Languages Safe program – its semantics can be at least partially computed on any valid database input. Safety is tied to program verification,
ECE Synthesis & Verification1 ECE 667 Spring 2011 Synthesis and Verification of Digital Systems Verification Introduction.
Synthesis of Interface Specifications for Java Classes Rajeev Alur University of Pennsylvania Joint work with P. Cerny, G. Gupta, P. Madhusudan, W. Nam,
1 A propositional world Ofer Strichman School of Computer Science, Carnegie Mellon University.
Vocabulary Chapter 6.
Decision Procedures for Presburger Arithmetic Presented by Constantinos Bartzis.
From Program Verification to Program Synthesis Saurabh Srivastava * Sumit Gulwani ♯ Jeffrey S. Foster * * University of Maryland, College Park ♯ Microsoft.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
Synthesis using Variable Elimination Viktor Kuncak EPF Lausanne
Synthesis, Analysis, and Verification Lecture 01c Lectures: Viktor Kuncak Exercises and Labs: Eva Darulová Giuliano Losa About Synthesis General Background.
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Ruzica Piskac Max Planck Institute for Software Systems, Germany.
Integrating high-level constructs into programming languages Language extensions to make programming more productive Underspecified programs –give assertions,
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
Examples and Sets. Synthesize each of These choose((x,y) =>10 x + 14 y == a) choose((x,y) =>10 x + 14 y == a&& x < y) choose((x,y) =>10 x + 14 y == a.
Do Now (3x + y) – (2x + y) 4(2x + 3y) – (8x – y)
Deriving Pre-Condition for ABCE1 Deriving Preconditions for Array Bound Check Elimination Dana N. XU Joint work with W.N. CHIN and S.C. KHOO Dept of Computer.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
E v a f i c o u g r á v i d a e, a o d a r à l u z u m m e n i n o, d i s s e : " O S e n h o r m e d e u u m f i l h o h o m e m ". E l a d e u à c.
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
Simultaneous Equations 1
Automatic Test Generation
Integer Programming An integer linear program (ILP) is defined exactly as a linear program except that values of variables in a feasible solution have.
On the Size of Pairing-based Non-interactive Arguments
Context-Free Grammars: an overview
Data Structures and Algorithms
MPC and Verifiable Computation on Committed Data
Multiplying Monomials.
Synthesis using Variable Elimination
Solving Linear Arithmetic with SAT-based MC
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Forming Perfect Squares
Estimation Interval Estimates Industrial Engineering
Proving Properties of Recursive Functions and Data Structures
Arithmetic Constraints and Automata
Factor Theorem.
12 Systems of Linear Equations and Inequalities.
LPSAT: A Unified Approach to RTL Satisfiability
Objective of This Course
RS – Reed Solomon List Decoding.
Programming Fundamentals (750113) Ch1. Problem Solving
CHAPTER 2 Context-Free Languages
Competitive Networks.
Solve Linear Equations by Elimination
Linear Algebra Lecture 3.
DESCRIBE how you would solve this system algebraically: y = 3x + 5
Competitive Networks.
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
Instructor: Aaron Roth
Remainder Theorem.
Solving recurrence equations
Recurrences.
Algorithms and Data Structures
Presentation transcript:

Complete Program Synthesis for Linear Arithmetics Mikaël Mayer Monday, January 25, 2009 LARA Supervisors: Viktor Kuncak Ruzica Piskac

Program Verification Our goal is to verify functional programs. Verification in the usual sense: given some specifications, you either prove that the program conforms to them, or find a bug (in the form of a counterexample)

Program Synthesis Our goal is to verify functional programs. Verification in the usual sense: given some specifications, you either prove that the program conforms to them, or find a bug (in the form of a counterexample)

Program Synthesis Challenges Define high-level language input. Reuse existing knowledge Guarantee quality of synthesized programs Human « Give me a program to generate pictures representing complex functions using this formalism(… )» But not: If not: For each program in possible programs: If program meets specifications: Return program Non efficient Undecidable Program Verification Efficiency Correctness-by-construction

Outline Examples Linear Integer Arithmetic synthesis algorithm Parametrized LIA synthesis algorithm Future of program synthesis Contribution : Decision procedure extension. Contribution: Synthesis extension.

Linear Integer Arithmetic Synthesis > 0 = B < y 5x-13y+5z 3x+4y-2A 3x+1 A,B   provided at run-time Find x, y, z  

Examples 27 9 Weights 3 1 T

Examples 27 9 3 1 Weights 19

Examples Weights 3 27 19 9 1

Examples 3 27 T 9 1  , 1 3 9 27 Î £ - = + w T Weights =0 Right Left Outside 

Complicated OK Examples  , 1 3 9 27 Î £ - = + w T Weights T =19 40+T >= 0 && 40-T >= 0 def getWeights(T : Int):(Int, Int, Int, Int) = { val ya = Math.min(1, ((13+T) - (27 + (13+T)%27)%27)/27) val yc = Math.min(1, ((4+T-27*ya) - (9 + (4+T-27*ya)%9)%9)/9) val yb = Math.min(1, ((1+T-27*ya-9*yc) - (3 + (1+T-27*ya-9*yc)%3)%3)/3) val w9 = yc val w3 = yb val w27 = ya val w1 = T-27*ya-3*yb-9*yc (w1, w27, w3, w9) } Complicated T =19 ya = 1 yc = -1 yb = 0 w9 = -1 // On the right w3 = 0 // Not taken w27 = 1 // On the left w1 = 1 // On the left OK 

Linear Integer Arithmetic Synthesis Two steps Equalities Inequalities

Linear Integer Arithmetic Synthesis Equalities – Process 20 30 12 ) 3 .( , = + $ z y x b a 10 15 6 . , = + $ z y x c ) , ( 3 6 var 2 5 ... / z y x v u c b a - + = 2 ) 20 , 3 (1 gcd = Bézout’s Theorem b a 3 2 + Condition Program fragment

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions? Find one solution Find all homogenous solutions ( ) c z y x ÷ ø ö ç è æ - = + 1 var 10 15 6 ÷ ø ö ç è æ = + v u z y x ? var 10 15 6 Extended Euclidian algorithm gcd(15,10)=5 Replace x by 5.

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions? Find all homogenous solutions ÷ ø ö ç è æ = + v u z y x ? 5 var 10 15 30 Simplify Find a witness for y and z

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions? Find all homogenous solutions ÷ ø ö ç è æ - = + v u z y x ? 6 5 var 2 3 Solve homogeneous

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions? Find all homogenous solutions ÷ ø ö ç è æ - = + v u z y x ? 6 5 var 2 3 Solve homogeneous

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions? Find all homogenous solutions ÷ ø ö ç è æ - = + v u c z y x 3 6 1 2 5 var 10 15 ÷ ø ö ç è æ - = + v u z y x 3 2 6 5 var 2 variables Complete solution Result

Linear Integer Arithmetic Synthesis Equalities – Describe all solutions ) , gcd( var ... .. 1 2 3 n i k g u x L M O = ÷ ø ö ç è æ + - Lower triangular Find a witness General solution

Linear Integer Arithmetic Synthesis 6 )% 3 12 ( 2 4 a b y - + £ Linear Integer Arithmetic Synthesis Inequalities Removed a variable x. Added a new variable u. Added an equality. a b y x 3 12 6 2 4 . , - + £ $ b y a x + £ - $ 4 2 3 . , Elimination of x ú û ê ë - + £ ù é 6 3 12 2 4 a b y { } ë û ) , ( 6 / 3 12 var ... ] 5 [ for y x a b k - + = Î a b y - + £ 5 8 6 )% 3 12 ( Program fragment k u a b y + = - £ Ù Î $ 6 3 12 5 8 ]. , [ New equality, new variable u Condition

Linear Integer Arithmetic Synthesis Complexity E = Equalities N = Inequalities V = Output variables ÷ ø ö ç è æ + = - ) , min( 2 Ops( 1 E V N O

Parametrized Linear Integer Synthesis > 0 = B < y 5x-13y+(C-A)z 3x+(AB)y-2A Cx+1 A,B,C   provided at run-time Find x, y, z   V. Weispfenning 1997 : Uniform Presburger Arithmetic

Example y j x i + × - = ) 1 ( j i ³ j y x i < £ + × = i j + × = j i Quotient computation in 1990 by Z. Manna, R. Waldinger y j x i + × - = ) 1 ( j i ³ j y x i < £ + × = i j + × = j i < def quotientRemainder(i : Int, j: Int):(Int, Int) = { if(i >= j) { val (x, y) = quotientRemainder(i-j, j) (x+1, y) } else { (0, i) } Can we do better ?

Example < j False 1 ) ( - £ × i j x j y x i < £ + × = j x i < Quotient computation in 2010 by M. Mayer < j False 1 ) ( - £ × i j x j y x i < £ + × = j x i < × - £ = j False i £ + 1 > j i j x £ × + - 1 ë û ) , ( var / y x j i × - = > j Condition Program fragment

Example ë û ) , ( var / y x j i × - = Quotient computation in 2010 by M. Mayer Comparison def quotientRemainder(i : Int, j: Int):(Int, Int) = { if(i >= j) { val (x, y) = quotientRemainder(i-j, j) (x+1, y) } else { (0, i) } ë û ) , ( var / y x j i × - = Condition Recursive Comfusy

Parametrized Linear Integer Synthesis Inequalities: Test each coefficient sign >0, =0, <0 Generate if-then-elses if needed. Add the coefficient sign to the precondition.

Test if all coefficients are zero Parametrized Linear Integer Synthesis Equalities ) ( . , = + × $ dz cy bx f e a z y x { } ï þ ý ü î í ì + - = × v k u z y x g d c b f e a ij 22 21 20 12 11 10 02 01 var ... ) , Bézout( ( gcd( else & if( 2 ) 20 , 3 (1 gcd = Test if all coefficients are zero Bézout’s Theorem b a 3 2 + ) , gcd( ( = + × Ù ¹ Ú f e a d c b Condition Program fragment

Future of Synthesis Program optimization Other types Recursive Abstract data types Strings … Efficient high-order specification languages

Thank you

Related work A deductive approach to program synthesis, Z. Manna and R. Waldinger, 1980. Complexity and uniformity of elimination in presburger airthmetic, V. Weispfenning, 1997. Combinatorial sketching for finite programs, A. Solar-Lezama & al., 2006. From Program Verification to Synthesis, S. Sivastava & al., 2010. A practical algorithm for extract array dependence analysis, W. Pugh, 1992. Partial Evaluation and Automatic Program Generation, 1993. This presentation is based on the following publications: On Complete Functional Synthesis. (Mayer, Suter, Piskac, Kuncak 2009) Complete Program Synthesis for Linear Arithmetics (Mayer 2010)

Extra Happy New Year 2010

Extra Happy New Year 2010 Quatrains Until the end

Extra Happy New Year 2010 Constraints

Extra Happy New Year 2010 Constraints

Extra Happy New Year 2010 Expected output

Extra Happy New Year 2010 Expected output

Extra Happy New Year 2010 Specifications

Extra Happy New Year 2010 Result

Extra Happy New Year 2010 Result