如何证明函数始终不可交换

发布于 2024-10-06 02:14:42 字数 370 浏览 0 评论 0原文

我有以下令人烦恼的问题。 我已经实现了以下功能:

function bool less(nat x, nat y) {
    if (y<>0) then
       if (x<>0) then
           return less(x-1,y-1);
       else
           return true;
       end;
    else
       return false;
    end;
end;

How can I show that for all x,y the following less(x,y) 和 less(y,x) 不可能在 同一时间?

再见

I have the following vexing problem.
I have implemented the following function:

function bool less(nat x, nat y) {
    if (y<>0) then
       if (x<>0) then
           return less(x-1,y-1);
       else
           return true;
       end;
    else
       return false;
    end;
end;

How can I show that for all x,y the following
less(x,y) and less(y,x) are not possible at the
same time?

Bye

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

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

发布评论

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

评论(1

帝王念 2024-10-13 02:14:42

好吧,首先我会要求你考虑 less(-1, -2) 的情况,所以我们必须将函数定义在 n ≥ 0 的范围内。此外,当第一个输入等于第二个输入,对于两个排序都会返回 true,因此我们必须假设 x ≠ y。

我会使用矛盾证明。

假设对于某些 x 和某些 y,其中 x 和 y 都 ≥ 0 且 x≠y,则 less(x,y) 和 less(y,x) 均为 true。

这意味着虽然 x 和 y 都不为零,但您需要将它们减去 n 次,直到其中一个为零,首先检查 x。当第一个操作数达到零时,该函数返回 true;当第二个操作数达到零且第一个操作数非零时,该函数返回 false。

有两种情况:

  1. x 首先达到零。在本例中,n = x,因为 0 = x - n(1)。
  2. y 首先达到零。在本例中 n = y,因为 0 = y - n(1)。

根据我们的假设,less(x,y) 返回 true,这意味着该函数迭代了 x 次,之后 x - x(1) = 0 且 y - x(1) > > 0(因为 y ≠ x,并且该函数事先没有返回 false)。

类似地,less(y,x) 返回 true,这意味着该函数迭代了 y 次,之后 y- y(1) = 0 且 x - y(1) > 。 0(原因与之前相同)。

这给了我们两个有用的关系: y - x > 0 和 x - y > 0 。重新排列: y > xx > y (函数的语义,但我们已经从函数如何工作的定义中实现了这一点,并且我们已将其简化为可以使用某些公理的纯数学)。

y > xx > y,您可以重新排列为 x > x 和 y > y (如果 x 大于 y,则它大于 y 大于的所有事物。y 大于 x,因此 x 大于 x)。

这是一个逻辑矛盾,因此我们的假设(它们都是正确的)是不正确的。

因此,通过矛盾证明,当 x ≠ y,且 x,y ≥ 0 时,函数 less 不能同时对 less(x,y) 和 less(y,x) 返回 true。

(自从我必须做证明以来已经有一段时间了(尽管我将不得不做一些接下来的事情,所以这是一个很好的做法)所以我可能有点生疏。如果有人看到错误,请指出我会尝试修复它)

Well, first of all I would ask you to consider the case of less(-1, -2), so we will have to define the function to be on the bounds of n ≥ 0. Also when the first input is equal to the second it will return true for both orderings, so we will have to assume that x ≠ y.

I would use Proof by Contradiction.

Assume that for some x and some y where x and y are both ≥ 0 and x≠y, that less(x,y) and less(y,x) are both true.

This would imply that while x and y are both nonzero, you subtract one from them n times until one of them is zero, checking x first. The function returns true when the first operand reaches zero, false when the second operand reaches zero while the first is nonzero.

There are two cases for this:

  1. x reaches zero first. In this case n = x, because 0 = x - n(1).
  2. y reaches zero first. In this case n = y, because 0 = y - n(1).

By our assumption, less(x,y) returned true, meaning that the function iterated x times, after which x - x(1) = 0 and y - x(1) > 0 (because y ≠ x, and the function didn't return false before hand).

Similarly, less(y,x) returned true, meaning that the function iterated y times, after which y- y(1) = 0 and x - y(1) > 0 (same reasons as before).

This gives us two useful relations: y - x > 0 and x - y > 0. rearranged: y > x and x > y (the semantic meaning of the function, but we have achieved this from the definition of how the function works and we have reduced it to the pure mathematics which we can work with certain axioms for).

From y > x and x > y, you can rearrange as x > x and y > y (If x is greater than y, then it is greater than all things y is greater than. y is greater than x, therefore x is greater than x).

This is a logical contradiction, and therefore our assumption (that they were both true) is incorrect.

Therefore, by Proof by Contradiction, when x ≠ y, and x,y ≥ 0, the function less cannot return true for both less(x,y) and less(y,x).

(it's been a while since I had to do a proof (though I'm going to have to do some coming up so it is good practice) so I might be a bit rusty. If any one sees an error, please point it out and I will try to fix it)

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