from program verification to program synthesis
play

From Program Verification to Program Synthesis Overview Jaak - PowerPoint PPT Presentation

From Program Verification to Program Synthesis Overview Jaak Ristioja March 30, 2010 1 / 91 Reference From Program Verification to Program Synthesis. @ POPL10; January 17-23, 2010 Saurabh Srivastava , University of Maryland, College Park


  1. From Program Verification to Program Synthesis Overview Jaak Ristioja March 30, 2010 1 / 91

  2. Reference From Program Verification to Program Synthesis. @ POPL’10; January 17-23, 2010 Saurabh Srivastava , University of Maryland, College Park Sumit Gulwani , Microsoft Research, Redmond Jeffrey S. Foster University of Maryland, College Park doi:10.1145/1706299.1706337 (including numerous typos and ambiguities) 2 / 91

  3. Reference From Program Verification to Program Synthesis. @ POPL’10; January 17-23, 2010 Saurabh Srivastava , University of Maryland, College Park Sumit Gulwani , Microsoft Research, Redmond Jeffrey S. Foster University of Maryland, College Park doi:10.1145/1706299.1706337 (including numerous typos and ambiguities) 3 / 91

  4. Introduction Automated program synthesis ◮ Correct-by-construction ◮ Eases task of programming ◮ Automated debugging ◮ Programmer only deals with high-level design ◮ New non-trivial algorithms could be discovered ◮ Difficult to implement 4 / 91

  5. Introduction Verification and synthesis Program verification ◮ synthesizes program proofs from programs ◮ for loops it uses ◮ inductive invariants for partial correctness ◮ ranking functions for termination ◮ does verification Synthesis problem → verification problem ◮ encoding guards and statements etc as logical facts ◮ using verification tools for synthesis ◮ by verification we infer statements, guards etc Proof-theoretic synthesis ◮ Proof for the program is synthesized alongside the program 5 / 91

  6. Introduction Verification and synthesis Program verification ◮ synthesizes program proofs from programs ◮ for loops it uses ◮ inductive invariants for partial correctness ◮ ranking functions for termination ◮ does verification Synthesis problem → verification problem ◮ encoding guards and statements etc as logical facts ◮ using verification tools for synthesis ◮ by verification we infer statements, guards etc Proof-theoretic synthesis ◮ Proof for the program is synthesized alongside the program 6 / 91

  7. Introduction Verification and synthesis Program verification ◮ synthesizes program proofs from programs ◮ for loops it uses ◮ inductive invariants for partial correctness ◮ ranking functions for termination ◮ does verification Synthesis problem → verification problem ◮ encoding guards and statements etc as logical facts ◮ using verification tools for synthesis ◮ by verification we infer statements, guards etc Proof-theoretic synthesis ◮ Proof for the program is synthesized alongside the program 7 / 91

  8. Motivating example Bresenham’s line drawing algorithm Pre- and post-condition for a line drawing program: 0 < Y ≤ X τ pre : τ post : ∀ k : 0 ≤ k ≤ X ⇒ 2 | out [ k ] − ( Y / X ) k | ≤ 1 and resource constraints, for example constraints for ◮ control flow, ◮ stack space, ◮ available operations, etc can we synthesize the program? 8 / 91

  9. Motivating example Bresenham’s line drawing algorithm Given the specification for a line drawing program 0 < Y ≤ X τ pre : τ post : ∀ k : 0 ≤ k ≤ X ⇒ 2 | out [ k ] − ( Y / X ) k | ≤ 1 and resource constraints, for example constraints for ◮ control flow, ◮ stack space, ◮ available operations, etc can we synthesize the program? 9 / 91

  10. Motivating example Bresenham’s line drawing algorithm Example Bresenhams ( int X, int Y) v 1 := 2Y − X; y := 0; x := 0; while ( x < = X) | out [ x ] := y ; | i f ( v 1 < 0) | | v 1 := v 1 + 2Y; | else | | v 1 := v 1 + 2(Y − X) ; y++; | x++; out ; return 10 / 91

  11. Motivating example Bresenham’s line drawing algorithm Observations ◮ We can write statements as equality predicates ◮ We can write acyclic program fragments as transition systems Example ◮ x := e becomes an equality predicate x ′ = e where ◮ x ′ is a renaming of x to its output value ◮ e is the expression over the non-primed values ◮ y := x; x := y becomes y ′ = x ∧ x ′ = y ′ ◮ if (x > 0) x := y; else skip ; becomes [] x > 0 → x ′ = y [] x ≤ 0 → true 11 / 91

  12. Motivating example Bresenham’s line drawing algorithm Example 1 = 2 Y − X ∧ y ′ = 0 ∧ x ′ = 0 [] true → v ′ while ( x < = X) [] v 1 < 0 → out ′ = upd( out , x , y ) ∧ | v ′ | 1 = v 1 + 2 Y ∧ y ′ = y ∧ | x ′ = x + 1 | [] v 1 ≥ 0 → out ′ = upd( out , x , y ) ∧ | v ′ | 1 = v 1 + 2( Y − X ) ∧ y ′ = y + 1 ∧ | x ′ = x + 1 | 12 / 91

  13. Motivating example Bresenham’s line drawing algorithm To prove partial correctness, we can write down the inductive loop invariant for the while -loop: τ : 0 < Y ≤ X ∧ v 1 = 2 ( x + 1) Y − (2 y + 1) X ∧ 2 ( Y − X ) ≤ v 1 ≤ 2 Y ∧ ∀ k : 0 ≤ k < x ⇒ 2 | out [ k ] − ( Y / X ) k | ≤ 1 and the verification condition can be written as four implications of four paths in the program: τ pre ∧ s entry ⇒ τ ′ τ ∧ ¬ g loop ⇒ τ post τ ∧ g loop ∧ g body 1 ∧ s body 1 ⇒ τ ′ τ ∧ g loop ∧ g body 2 ∧ s body 2 ⇒ τ ′ where τ ′ is the renamed version of the loop invariant. 13 / 91

  14. Motivating example Bresenham’s line drawing algorithm 1 = 2 Y − X ∧ y ′ = 0 ∧ x ′ = 0 s entry : v ′ g loop : x ≤ X g body 1 : v 1 < 0 s body 1 : out ′ = upd( out , x , y ) ∧ v ′ 1 = v 1 + 2 Y ∧ y ′ = y ∧ x ′ = x + 1 g body 2 : v 1 ≥ 0 s body 2 : out ′ = upd( out , x , y ) ∧ v ′ 1 = v 1 + 2( Y − X ) ∧ y ′ = y + 1 ∧ x ′ = x + 1 14 / 91

  15. Motivating example One can validate that the loop invariant τ satisfies the verification condition. ◮ e.g. by using SMT (Satisfiability Modulo Theory) solvers There are also powerful program verification tools that can prove total correctness by ◮ automatically generating fixed-point solutions for loop invariants, such as τ ◮ inferring ranking functions ( ϕ ) to prove termination So if we can infer the verification condition, perhaps we can also infer ◮ the guards g i ’s and ◮ the statements s i ’s at the same time? 15 / 91

  16. Motivating example One can validate that the loop invariant τ satisfies the verification condition. ◮ e.g. by using SMT (Satisfiability Modulo Theory) solvers There are also powerful program verification tools that can prove total correctness by ◮ automatically generating fixed-point solutions for loop invariants, such as τ ◮ inferring ranking functions ( ϕ ) to prove termination So if we can infer the verification condition, perhaps we can also infer ◮ the guards g i ’s and ◮ the statements s i ’s at the same time? 16 / 91

  17. Motivating example How to infer guards and statements 1. encode programs as transition systems 2. assert appropriate constraints 3. use verification tools to systematically infer solutions for the unknowns in the constraints. The unknowns are ◮ invariants ◮ statements ◮ guards Types of constraints ◮ well-formedness constraints to get solutions corresponding to real-life programs ◮ progress constraints to ensure termination 17 / 91

  18. Motivating example How to infer guards and statements 1. encode programs as transition systems 2. assert appropriate constraints 3. use verification tools to systematically infer solutions for the unknowns in the constraints. The unknowns are ◮ invariants ◮ statements ◮ guards Types of constraints ◮ well-formedness constraints to get solutions corresponding to real-life programs ◮ progress constraints to ensure termination 18 / 91

  19. Specification for proof-theoretic approach For synthesis we first need a specification for the program we want to construct. Synthesis scaffold �F , D , R� ◮ F - functional specification ◮ D - domain constraints ◮ R - resource constraints 19 / 91

  20. Specification for proof-theoretic approach Synthesis scaffold Functional specification F Let � v in and v out be vectors containing the input and output � variables. F = ( F pre ( � v in ) , F post ( � v out )) where F pre ( � v in ) and F post ( � v out ) are formulas that hold at the program entry and exit locations, respectively. 20 / 91

  21. Specification for proof-theoretic approach Synthesis scaffold Domain constraints D D = ( D exp , D grd ) where D exp is the domain of expressions in the program and D grd is the domain of boolean expressions used in program guards. Proof domain D prf ◮ Proof-theoretic synthesis needs to synthesize proof terms from a proof domain D prf . ◮ D prf needs to be at least as expressive as D exp and D grd . ◮ We need a solver capable of handling D prf . 21 / 91

  22. Specification for proof-theoretic approach Synthesis scaffold Domain constraints D D = ( D exp , D grd ) where D exp is the domain of expressions in the program and D grd is the domain of boolean expressions used in program guards. Proof domain D prf ◮ Proof-theoretic synthesis needs to synthesize proof terms from a proof domain D prf . ◮ D prf needs to be at least as expressive as D exp and D grd . ◮ We need a solver capable of handling D prf . 22 / 91

  23. Specification for proof-theoretic approach Synthesis scaffold Resource constraints R R = ( R flow , R stack , R comp ) ◮ R flow is a flowgraph template from the grammar T ::= ◦ | ∗ ( T ) | T ; T ◮ R stack : type → N 1 is a mapping indicating the number of extra temporary variables of each type available to the program. ◮ R comp : op → N 0 is a mapping defining how many operations of each type can be included in the program. R comp = ∅ indicates no constraints. 23 / 91

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend