1

I currently am struggling to figure out, how to show that a program, which includes a loop, is correct. I am working on the basis of wp, vc and pc.

The loops in question are:

wp(while(i<n) i = i+1; | i >= n)

wp(while(true) x=4; |x=4)

where everything befeore the ";" is the program and everything after the "|" is the postcondition.

I heard in my lectures that you have to find the invariants as well as the terminating function of the program, but i currently do not really know how to do this intuitively. I heard, that you need to train this, but i did not see a example on this yet, mostly just theory. If someone could help me explain the verification of loops, that would be really kind.

I appreciate every bit of help.

alias
  • 28,120
  • 2
  • 23
  • 40
Mark Lauer
  • 51
  • 1
  • 4
  • 1
    Wikipedia has quite a good introduction: https://en.wikipedia.org/wiki/Predicate_transformer_semantics This is a well-established research area, with lots of online resources. Here's one with some examples that can get you started: https://cecs.wright.edu/~pmateti/Courses/FormalMethods/Lectures/Assertions/wp.html#sec-4 – alias Aug 10 '20 at 01:16
  • `wp` is a function, and the result is an expression. It's not a matter of showing that something is correct here. (You don't have a Hoare triple.) Both `wp` expressions evaluate to `true`, because in both cases the post-condition is satisfied, regardless of the initial state. – aioobe Dec 22 '20 at 06:22

0 Answers0