霍尔逻辑:严格递减循环变体本身如何证明终止?

发布于 2024-11-11 14:00:22 字数 409 浏览 8 评论 0原文

参考 完全正确性的 while 规则,WP 似乎告诉我,只需找到一个循环严格减少的变体足以证明终止。我无法接受这一点,要么是因为我遗漏了某些东西,要么是规则是错误的。考虑

int i = 1000;
while(true) i--;

其中变量 i 的值是严格递减循环变体,但循环肯定不会终止。

当然,该规则需要有一个额外的前提条件,例如 i<0 → ØB (其中 B 是公理模式中的循环条件),以便循环条件最终“捕获”循环变体并退出。

或者我错过了什么?

Referring to the while rule for total correctness, WP seems to tell me that just finding a loop variant that strictly decreases is enough to prove termination. I can't accept that, either because I'm missing something or the rule is wrong. Consider

int i = 1000;
while(true) i--;

in which the value of variable i is a strictly decreasing loop variant, but the loop certainly doesn't terminate.

Surely the rule needs to have an additional precondition, something like i<0 → ¬B (where B is the loop condition in the axiom schema) so that the loop condition eventually 'catches' the loop variant and exits.

Or have I missed something?

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

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

发布评论

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

评论(3

深白境迁sunset 2024-11-18 14:00:22

循环变量必须是自然数。自然数不能减少到零以上。使用大词,循环变体是一个相对于有充分基础的关系单调递减的值。这是你的推理中缺少的依据。

The loop-variant must be a natural number. A natural number cannot decrease past zero. Using big words, the loop variant is a value that is monotonically decreasing with respect to a well-founded relation. It's the well-foundedness that's missing from your reasoning.

虐人心 2024-11-18 14:00:22

正如维基百科文章中所述:

[...]条件B必须暗示t
不是其范围的最小元素,
否则本规则的前提
将是错误的。

在本例中,Btruetitrue 没有暗示 i 的最小性,因此不满足规则的前提。

As noted in the Wikipedia article:

[...] the condition B must imply that t is
not a minimal element of its range,
for otherwise the premise of this rule
would be false.

In the case at hand, B is true and t is i. true makes no implication about the minimality of i, so the premise of the rule is not met.

丑疤怪 2024-11-18 14:00:22

通常的排序“<”在自然数上有充分根据,但在整数上则不然。为了使关系有良好的基础,其域的每个非空子集必须具有最小元素。由于可以证明,对于有充分基础的关系而言,不存在无限的下降链,因此具有变体的循环必须终止。

当然,在元素最小的情况下,循环条件必须为假!

然而,变体不必限于自然数。超限序数也是良序的。

The usual ordering "<" is well-founded on the natural numbers, but not on the integers. In order for a relation to be well-founded, every non-empty subset of its domain must have a minimal element. Since it can be shown that there is no infinite descending chain with respect to a well-founded relation, it follows that a loop with a variant must terminate.

Of course the condition of the loop must be false in the case of a minimal element!

A variant need not be restricted to the natural numbers, however. Transfinite ordinals are also well-ordered.

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