1 / 7

Verification with Array Variables

Verification with Array Variables. Book: Chapter 7.2. The problem. Using array variables can lead to complication: {x[1]=1/x[2]=3} x[x[1]]:=2 {x[x[1]]=2} Why? Because the assignment changes x[1] as well. Now it is also 2, and x[x[1]], which is x[2] is 3 and not 2!. What went wrong?.

nishi
Download Presentation

Verification with Array Variables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Verification with Array Variables Book: Chapter 7.2

  2. The problem Using array variables can lead to complication: {x[1]=1/\x[2]=3} x[x[1]]:=2 {x[x[1]]=2} Why? Because the assignment changes x[1] as well. Now it is also 2, and x[x[1]], which is x[2] is 3 and not 2!

  3. What went wrong? Take the postcondition {x[x[1]]=2} and substitute 2 instead of x[x[1]]. We obtain {2=2} (which is equivalent to {true}). Now, (x[1]=1/\x[2]=3) 2=2. So we may wrongly conclude that the above Hoare triple is correct.

  4. How to fix this? `Backward substitution’ should be done with arrays as complete elements. Define (x; e1: e2): an array like x, with value at the index e1 changed to e2. (x; e1: e2)[e3]=e2 if e1=e3 x[e3] otherwise (x; e1: e2)[e3]=if(e1=e3, e2, x[e3])

  5. Solved the problem? • How to deal with if(φ, e1, e2)? Suppose that formula ψ contains this expression. Replace if(φ, e1, e2) by new variable v in ψ. The original formula ψ is equivalent to: (φ/\ ψ[e1/v])\/(¬φ/\ ψ[e2/v])

  6. Returning to our case • Our postcondition is {x[x[1]]=2}. • The assignment x[x[1]]:=2 causes the substitution in the postcondition ofthe (array) variable x by a new array, which is (x; x[1] : 2), resulting in {x[x[1]]=2} (x; x[1] : 2)[(x; x[1] : 2)[1]] = 2

  7. Are we done? • Not yet. It remains to • Convert the array form into an if form. • Get rid of the if form. • Will not be done in class. • All we say is that we obtain an expression that is not implied by the precondition x[1]=1/\x[2]=3.

More Related