JML:如何指定具有新月形元素的数组的要求?

发布于 2024-09-28 08:54:51 字数 219 浏览 1 评论 0原文

我想在 JML 中做到这一点:

//@ requires (\forall int i : array[i] < array[i+1])
void calculatesDistances(int[] array){
 ..
}

我无法让它工作,在 JML 规范中看到了很多示例,但找不到如何做到这一点的方法。

那么,我怎样才能做到呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2024-10-05 08:54:51

一种方法是使用蕴涵来“防范”无意义的数组值:

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

使用 \forall 的新语法,我相信您还可以编写:

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

where (i >= 0 && i < array.length-1) 是范围表达式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文