symbolic computation and theorem proving in program
play

Symbolic Computation and Theorem Proving in Program Analysis Laura - PowerPoint PPT Presentation

Symbolic Computation and Theorem Proving in Program Analysis Laura Kov acs Chalmers Outline Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS08, LPAR10) Part 3:


  1. Symbolic Computation and Theorem Proving in Program Analysis Laura Kov´ acs Chalmers

  2. Outline Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS’08, LPAR’10) Part 3: Quantified Invariant Generation (FASE’09, MICAI’11) Part 4: Invariants, Interpolants and Symbol Elimination (CADE’09, POPL ’12, APLAS’12)

  3. Part 1: Program Analysis and Verification Preliminaries Weakest Precondition (WP) and Loop Invariants Examples of Verification by WP

  4. Preliminaries Program Verification: program satisfies its requirements (specification) Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  5. Preliminaries Program Verification: program satisfies its requirements (specification) Example. Given two natural numbers x and y , with y being non zero, compute the quotient ( quo ) and the remainder ( rem ) of the integer division of x by y . Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  6. Preliminaries Program Verification: program satisfies its requirements (specification) Example. Given two natural numbers x and y , with y being non zero, compute the quotient ( quo ) and the remainder ( rem ) of the integer division of x by y . Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  7. Preliminaries Program Verification: program satisfies its requirements (specification) Example. Given two natural numbers x and y , with y being non zero, compute the quotient ( quo ) and the remainder ( rem ) of the integer division of x by y . Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  8. Preliminaries Program Verification: program satisfies its requirements (specification) Example. Given two natural numbers x and y , with y being non zero, compute the quotient ( quo ) and the remainder ( rem ) of the integer division of x by y . Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  9. Preliminaries Program Verification: program satisfies its requirements (specification P , Q ) � �� � program correctness Example. Given two natural numbers x and y , with y being non zero, compute the quotient ( quo ) and the remainder ( rem ) of the integer division of x by y . Precondition P : ( x ≥ 0 ) ∧ ( y > 0 ) initial states Postcondition Q : ( quo ∗ y + rem = x ) ∧ ( 0 ≤ rem < y ) final states Program (code) S : quo := 0 ; rem := x ; while y ≤ rem do How rem := rem − y ; quo := quo + 1 end while Hoare triple (correctness formula) : { P } S { Q }

  10. Considerations Program statements: ◮ Assignments: x := expression ◮ Sequencing: s 1 ; s 2 ◮ Conditionals: if ( cond ) then s 1 else s 2 ◮ Loops: while ( cond ) do s end while Program: S = s 1 ; s 2 ; . . . ; s n − 1 ; s n Partial correctness of { P } S { Q } : Every computation of S that: ◮ starts in a state satisfying P and ◮ is terminating, ends in a state satisfying Q .

  11. Considerations Program statements: ◮ Assignments: x := expression ◮ Sequencing: s 1 ; s 2 ◮ Conditionals: if ( cond ) then s 1 else s 2 ◮ Loops: while ( cond ) do s end while Program: S = s 1 ; s 2 ; . . . ; s n − 1 ; s n Partial correctness of { P } S { Q } : Every computation of S that: ◮ starts in a state satisfying P and ◮ is terminating, ends in a state satisfying Q .

  12. Considerations Program statements: ◮ Assignments: x := expression ◮ Sequencing: s 1 ; s 2 ◮ Conditionals: if ( cond ) then s 1 else s 2 ◮ Loops: while ( cond ) do s end while Program: S = s 1 ; s 2 ; . . . ; s n − 1 ; s n Partial correctness of { P } S { Q } : Every computation of S that: ◮ starts in a state satisfying P and ◮ is terminating, ends in a state satisfying Q .

  13. Specification Program Weakest Precondition Verification Conditions Proving

  14. Specification Program Weakest Precondition Verification Conditions Proving

  15. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : S = s 1 ; . . . ; s n − 1 ; s n 1. Compute wp ( S , Q ) ; 2. Prove P = ⇒ wp ( S , Q )

  16. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : S = s 1 ; . . . ; s n − 1 ; s n 1. Compute wp ( S , Q ) ; 2. Prove P = ⇒ wp ( S , Q )

  17. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : { P } ← wp ( s 1 , wp ( . . . , wp ( s n , Q ))) S = s 1 ; . . . ; s n − 1 ; s n � �� � s 1 ; wp ( S , Q ) . 1. Compute wp ( S , Q ) ; . . 2. Prove P = ⇒ wp ( S , Q ) ← wp ( s n − 1 , wp ( s n , Q )) s n − 1 ; ← wp ( s n , Q ) s n { Q }

  18. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : { P } ← wp ( s 1 , wp ( . . . , wp ( s n , Q ))) S = s 1 ; . . . ; s n − 1 ; s n � �� � s 1 ; wp ( S , Q ) . 1. Compute wp ( S , Q ) ; . . 2. Prove P = ⇒ wp ( S , Q ) ← wp ( s n − 1 , wp ( s n , Q )) s n − 1 ; ← wp ( s n , Q ) s n { Q }

  19. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : { P } ← wp ( s 1 , wp ( . . . , wp ( s n , Q ))) S = s 1 ; . . . ; s n − 1 ; s n � �� � s 1 ; wp ( S , Q ) . 1. Compute wp ( S , Q ) ; . . 2. Prove P = ⇒ wp ( S , Q ) ← wp ( s n − 1 , wp ( s n , Q )) s n − 1 ; ← wp ( s n , Q ) s n { Q }

  20. Weakest Precondition Strategy P is weaker than R iff R = ⇒ P . Weakest Precondition wp ( S , Q ) for S with Q: for any { R } S { Q } we have R = ⇒ wp ( S , Q ) . Note: { wp ( S , Q ) } S { Q } . Verification of { P } S { Q } : { P } ← wp ( s 1 , wp ( . . . , wp ( s n , Q ))) S = s 1 ; . . . ; s n − 1 ; s n � �� � s 1 ; wp ( S , Q ) . 1. Compute wp ( S , Q ) ; . . 2. Prove P = ⇒ wp ( S , Q ) ← wp ( s n − 1 , wp ( s n , Q )) s n − 1 ; ← wp ( s n , Q ) s n { Q }

  21. WP Inference Rules ◮ Assignments: wp ( x := expression , Q ) = Q x ← expression wp ( x := 5 , x + y = 6 ) = 5 + y = 6 wp ( x := x + 1 , x + y = 6 ) = x + 1 + y = 6 ◮ Sequencing: wp ( s 1 ; s 2 , Q ) = wp ( s 1 , wp ( s 2 , Q )) wp ( x := x + 1 ; y := y + x , 2 ∗ y > 10 ) = wp ( x := x + 1 , wp ( y := y + x , 2 ∗ y > 10 )) = wp ( x := x + 1 , 2 ∗ ( y + x ) > 10 ) = 2 ∗ ( y + x + 1 ) > 10 )

  22. WP Inference Rules ◮ Assignments: wp ( x := expression , Q ) = Q x ← expression wp ( x := 5 , x + y = 6 ) = 5 + y = 6 wp ( x := x + 1 , x + y = 6 ) = x + 1 + y = 6 ◮ Sequencing: wp ( s 1 ; s 2 , Q ) = wp ( s 1 , wp ( s 2 , Q )) wp ( x := x + 1 ; y := y + x , 2 ∗ y > 10 ) = wp ( x := x + 1 , wp ( y := y + x , 2 ∗ y > 10 )) = wp ( x := x + 1 , 2 ∗ ( y + x ) > 10 ) = 2 ∗ ( y + x + 1 ) > 10 )

  23. WP Inference Rules ◮ Assignments: wp ( x := expression , Q ) = Q x ← expression wp ( x := 5 , x + y = 6 ) = 5 + y = 6 wp ( x := x + 1 , x + y = 6 ) = x + 1 + y = 6 ◮ Sequencing: wp ( s 1 ; s 2 , Q ) = wp ( s 1 , wp ( s 2 , Q )) wp ( x := x + 1 ; y := y + x , 2 ∗ y > 10 ) = wp ( x := x + 1 , wp ( y := y + x , 2 ∗ y > 10 )) = wp ( x := x + 1 , 2 ∗ ( y + x ) > 10 ) = 2 ∗ ( y + x + 1 ) > 10 )

  24. WP Inference Rules ◮ Assignments: wp ( x := expression , Q ) = Q x ← expression wp ( x := 5 , x + y = 6 ) = 5 + y = 6 wp ( x := x + 1 , x + y = 6 ) = x + 1 + y = 6 ◮ Sequencing: wp ( s 1 ; s 2 , Q ) = wp ( s 1 , wp ( s 2 , Q )) wp ( x := x + 1 ; y := y + x , 2 ∗ y > 10 ) = wp ( x := x + 1 , wp ( y := y + x , 2 ∗ y > 10 )) = wp ( x := x + 1 , 2 ∗ ( y + x ) > 10 ) = 2 ∗ ( y + x + 1 ) > 10 )

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