Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complete Program Synthesis for Linear Arithmetics

Similar presentations


Presentation on theme: "Complete Program Synthesis for Linear Arithmetics"— Presentation transcript:

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

2 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)

3 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)

4 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

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

6 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  

7 Examples 27 9 Weights 3 1 T

8 Examples 27 9 3 1 Weights 19

9 Examples Weights 3 27 19 9 1

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

11 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

12 Linear Integer Arithmetic Synthesis
Two steps Equalities Inequalities

13 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

14 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.

15 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

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

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

18 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

19 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

20 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

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

22 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

23 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 ?

24 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

25 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

26 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.

27 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

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

29 Thank you

30 Related work A deductive approach to program synthesis, Z. Manna and R. Waldinger, 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)

31 Extra Happy New Year 2010

32 Extra Happy New Year 2010 Quatrains Until the end

33 Extra Happy New Year 2010 Constraints

34 Extra Happy New Year 2010 Constraints

35 Extra Happy New Year 2010 Expected output

36 Extra Happy New Year 2010 Expected output

37 Extra Happy New Year 2010 Specifications

38 Extra Happy New Year 2010 Result

39 Extra Happy New Year 2010 Result


Download ppt "Complete Program Synthesis for Linear Arithmetics"

Similar presentations


Ads by Google