how to prove loops to be correct
play

How to Prove Loops to be Correct? Thomas Baar / Mathias Krebs EPFL, - PowerPoint PPT Presentation

How to Prove Loops to be Correct? Thomas Baar / Mathias Krebs EPFL, Lausanne, Switzerland 4 th KeY-Workshop, June 8-10, 2005, Lkeberg near Gothenburg, Sweden Proving Loops in KeY Induction Rule generates BaseCase StepCase


  1. How to Prove Loops to be Correct? Thomas Baar / Mathias Krebs EPFL, Lausanne, Switzerland 4 th KeY-Workshop, June 8-10, 2005, Lökeberg near Gothenburg, Sweden

  2. Proving Loops in KeY � Induction Rule generates � BaseCase � StepCase � UseCase � User has to provide � induction formula � induction variable/term

  3. Demo Simple example : il >= 0 -> {i:=il}<while(i>0){i--;}>i=0

  4. Basic Steps � Find appropriate induction term/variable � unwinding the loop body decreases ind-term by 1 � Find appropriate induction formula � normally, this is the same as proof goal � Prove the POs of induction rule � base case and use case are normally trivial � step case can by tricky Methodology: How can we assist the user in finding successful induction variables and formula?

  5. Variants of DecrByOne � Mismatch between BaseCase and Loop Termination il>=5 -> {i:=il}<while(i>5){i--;}>i=5 � BaseCase comes for free (0>=5 -> …) � StepCase has form (il>= 5 -> {i:=il}…) -> (succ(il)>=5) -> {i:=succ(il)… Interesting case : succ(il)=5

  6. Variants of DecrByOne � Fml is valid but not ‘inductive’ il >= 5 -> {i:=il}<while(i>0){i--;}>i=0 If the original proof goal is not ‘inductive’ it must be made stronger.

  7. Decrease Induction not only by One il>=0 -> {i:=il}<while(i>0) {i--;i--;}>(i=0¦i=-1) Step Case: (il >= 0 -> {i:=il}<{while(…)}>) -> (succ(il)>=0 -> {i:=succ(il)}<{while(i>0){i--;i--;}} > After unwinding: (il >= 0 -> {i:=il}<{while(…) }> ) -> (succ(il)>=0 -> {i:=il-1}<{while(…) }> Induction term decreased by more than one: -> use strong induction

  8. Example: Russian Multiplication ( geq(al, 0) -> {a:=al} {b:=bl} {z:=0} <{ while ( a!=0 ) { if (a/2*2!=a) { z=z+b; induction term is al } a=a/2; induction term is strictly b=b*2; decreased, possibly by more } than one }> z = al * bl) -> strong induction proof goal is not inductive } -> strengthening of ind-fml

  9. Multiple Induction Terms � Requires nested induction � exponential number of POs (2 Ind-terms-> 9 POs) {i:=il}{j:=jl} <{ while ( i>0|j>0 ) { if (i>j) { i--; } else { j--; } } }> (i = 0 & j = 0))

  10. Multiple Induction Terms {i:=il} {j:=jl} <{ while ( i>0|j>0 ) { if (j==0) { i--; j=9; } else { j--; } } }> (i = 0 & j = 0)) � Sometimes, more than one loop-unwind must be symbolically executed to make ind-terms smaller

  11. Further Problems � Induction Var is increased instead decreased � requires technical trick for induction formula � Would be nice to have prestate-projection rule POST1' ¦ POST2' < p > POST2 POST' is POST with fresh prog-var < p > POST1¦ � Accumulator variables can destroy update

  12. Is There a Better Way? Yes! Just use another tool � BLAST B erkeley L azy A bstraction S oftware V erification T ool

  13. BLAST � Verification tool for C programs � Based on model checking � Can only prove partial correctness (safety properties) Many great ideas that can be applied in KeY as well! Find more information on BLAST: Dirk Beyer, Thomas A. Henzinger, Renjit Jhala, and Rupak Majumdar: Checking Memory Safety with Blast . FASE 2005. LNCS 3442.

  14. Ways to Express Safety true true PRE if(PRE) if(PRE) Prog Prog Prog if (not POST){ ?unreachable ?POST ?POST } Every partial correctness property for a program (box modality) can be easily reformulated in terms of reachability of a certain statement.

  15. An Unsafe Example Control Flow Automaton (CFA) Program - nodes = control points - edges = decisions/statements 1 x=x+1, x=x+1 if (y > 0){ 2 y>0 x=x+1; !y>0 3 if (x=3){ x=x+1 printf(“error”) 4 x!=3 } x=3 } 5 *

  16. An Unsafe Example Is Trace-Formula satisfiable? ART Trace-Formula CFA YES -- genuine counterexample (Abstract NO -- spurious counterexample Reachability Tree) 1 1 x=x+1 x1=x+1 x=x+1 2 2 y>0 y>0 y>0 !y>0 3 3 x=x+1 x2=x1+1 x=x+1 4 4 x!=3 x=3 x=3 x2=3 5 5 *

  17. A Safe Example Program CFA 1 x=x+1; x=x+1 if (y>0){ 2 y>0 x=y; while (x > 0){ !y>0 3 x=x-1; x=y x=x-1; 4 x>0 !x>0 } if (x!=0 and x!=-1){ 7 5 x=x-1 !(…) printf(“error”); x!=0 and } x!=-1 8 } x=x-1 6 * 9

  18. Craig-Interpolation CFA Trace-Fml ART 1 1 x1=x+1 x=x+1 x=x+1 2 2 y>0 y>0 y>0 !y>0 3 3 x=y x=y x2=y 4 x>0 4 !x>0 !x>0 !x2 > 0 7 5 x=x-1 5 !(…) x!=0 and x!=0 and x2!=0 and x2!=-1 x!=-1 x!=-1 8 x=x-1 6 6 * 9

  19. Craig-Interpolation If trace fml is not satisfiable we ‘refine the abstraction’. Trace-Fml ART For each control point: Craig - split trace fml into before/after - find cp-fml such that 1 - BEF implies CP x1=x+1 x=x+1 - CP and AFT implies false true - vocabulary is intersection 2 y>0 y>0 y>0 3 x=y x2=y x2>0 4 Craig formulas are attached !x>0 !x2 > 0 to corresponding trace node: false 5 -they ‘overapproximate’ properties x!=0 and of trace state x2!=0 and x2!=-1 x!=-1 -nodes with ‘false’ are never reachable 6

  20. Refining the ART Refined ART ART CFA 1 x=x+1 1 2 y>0 1 x=x+1 x=x+1 3 2 true y>0 x=y 2 y>0 4 3 !x>0 y>0 x>0 !y>0 3 x=y x=y x>-1 5 7 4 x>0 x>0 !x>0 7’ 4 x-- x>0 !x>0 7 4’ 8 5 !(…) x!=0 and x-- 5 !x>0 false x-- x!=-1 8 5’ x!=0 and 9 x!=-1 x-- 6 6’ * 9 x>-2

  21. Closing the ART � An ART is closed iff � all possible alternatives are explored � each leaf node is � exit node � annotated with false � there is another node with same label and weaker annotation

  22. Summary SW-Model Checking � Fully automatically � Closed ART is formal proof for safety property � Proof is found by analyzing (spurious) counterexamples � Scalable approach (Craig-Interpolation) � Concrete counterexample for incorrect props � Open Problem: TERMINATION � Room for combining BLAST/KEY � Key-Proof: Look out for Ind-Term which is made strictly smaller in loop body

  23. KeY vs. BLAST � KeY � BLAST � requires interaction � push-button user can give hints � � no support yet for easy � easily finds bugs bug detection � does not prove � total correctness termination � does not support multiplication

  24. Other Activities � OCL workshop at MODELS’05 � conference in Montego Bay, Jamaica ☺ � focus on tool support for OCL � Paper Thomas Baar: Non-deterministic Constructs in OCL – What does any() Mean , SDL’05, Grimstad, Norway.

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