开发者

JML: How to specify a requirement of an array with crescent elements?

开发者 https://www.devze.com 2023-01-20 00:38 出处:网络
I want to do that in JML: //@ requires (\\forall int i : array[i] < array[i+1开发者_开发技巧])

I want to do that in JML:

//@ requires (\forall int i : array[i] < array[i+1开发者_开发技巧])
void calculatesDistances(int[] array){
 ..
}

I couldn't make it work, saw a lot of examples in JML specs, but couldn't find a way how to do it.

So, how can i make it?


One way is to "guard" against nonsense array values using implication:

  (\forall int i; (i >= 0 && i < array.length-1) ==> (array[i] < array[i+1]))

With the newer syntax for \forall, I believe you could also write:

  (\forall int i; (i >= 0 && i < array.length-1) ; (array[i] < array[i+1]))

where (i >= 0 && i < array.length-1) is the range expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号