Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a thought about loop variants #30

Open
jensgerlach opened this issue Nov 17, 2019 · 2 comments
Open

a thought about loop variants #30

jensgerlach opened this issue Nov 17, 2019 · 2 comments

Comments

@jensgerlach
Copy link

Here is a simple function that is verified with Frama-C without problems

/*@
  requires 0 < n;
  assigns  \nothing;
*/
int loop(int n)
{
   int a = 0;
   /*@
     loop invariant 0 <= i <= n;
     loop invariant a == i;
     loop assigns i, a;

     // note these two lines
     loop variant n-i;
     //loop invariant n-i;
   */
   for(int i = 0; i < n; ++i) {
      a += 1;
   }

  return a;
}

If, however, the user accidentally types invariant instead of variant,
then Frama-C does not warn about it.
I don't hink this is a bug, although I think the "loop invariant" n-i looks a bit odd (as an aside the loop "invariant" is not verified (at least with alt-ergo)).

My point is, that it might be nice, if there were a way to warn a user that he did not specify a loop variant. Something along the lines -wp-check-termination.

@vprevosto
Copy link
Member

Indeed, the loop invariant is accepted as a short-hand for loop invariant n-i !=0;, which is not true at the end of the last iteration.

My proposal would be to refuse to mix invariant and assigns. This won't help you if don't provide a loop assigns clause;, but this is already a problem in itself.

@jensgerlach
Copy link
Author

Yes, that would help although it would be rather indirect. I think an option as mentioned above would be clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants