简体   繁体   English

1 + 1 和给出错误结果的几率是多少?

[英]What are the chances of a 1 + 1 sum giving the wrong result?

I know that, for as much as we want to believe computers to be unerring, transistors are not perfect and 1 + 1 will not always return 2, at a transistor level.我知道,尽管我们希望相信计算机是无误的,但晶体管并不完美,并且 1 + 1 并不总是在晶体管级别返回 2。

I also know that, to protect us from errors, most computers nowadays have redundancy, error detection and correction algorithms.我也知道,为了保护我们免受错误的影响,现在大多数计算机都有冗余、错误检测和纠正算法。

That being said, what are the chances of the following C++ program printing the wrong result, without warning?话虽如此,以下 C++ 程序在没有警告的情况下打印错误结果的可能性有多大? Is there even a chance?还有机会吗?

#include <iostream>
using namespace std;

int main()
{
    int a = 1, b = 1;
    int sum = a + b;

    cout << "Sum = " << sum;

    return 0;
}

Let's assume we are using an average x64 $1000 laptop, as of 2020.假设我们使用的是 2020 年的平均 x64 1000 美元笔记本电脑。

This question has a broader scope.这个问题的范围更广。 We run billions of calculations per second, I want to know how much can go wrong in a complex program, on a theoretical level.我们每秒运行数十亿次计算,我想知道在理论层面上一个复杂的程序会出错多少。

Yes, there is a chance of 1 + 1 yielding something other than 2. The chance of that happening is so close to zero that it cannot be measured.是的,1 + 1 有可能产生 2 以外的结果。这种情况发生的可能性非常接近于零,无法衡量。

This is so for the following reasons:这是出于以下原因:

  1. First of all, the likelihood of things going wrong at the quantum level are infinitesimally low.首先,在量子层面上出现问题的可能性非常低。 The term "glitches" does exist in IT, but in the vast majority of cases it turns out to be due to some hardware malfunction like a network cable not making perfect contact. “故障”一词在 IT 中确实存在,但在绝大多数情况下,事实证明是由于某些硬件故障,例如网线没有完全接触。 In the remaining extremely small percentage of cases where the glitch has been observed in software, it is simply used as just another term for "we are not quite sure why this happened".在软件中观察到故障的剩余极少数情况下,它只是用作“我们不太确定为什么会发生这种情况”的另一个术语。 It is most likely due to a logic bug, or a multithreading issue, or some other non-quantum effect.这很可能是由于逻辑错误、多线程问题或其他一些非量子效应造成的。 Glitches due to quantum uncertainty are not happening at any rate that has given rise to any need to be given any consideration in our profession.由于量子不确定性导致的故障无论如何都不会发生,以至于我们的专业需要考虑。

  2. The computer system on which you are going to run this little test program of yours is constantly running megabytes of code that perform various other functions, all of which rely on 1+1 or any other computation always yielding the correct result.您将在其上运行您的这个小测试程序的计算机系统不断运行数兆字节的代码,这些代码执行各种其他功能,所有这些都依赖于 1+1 或任何其他计算,始终会产生正确的结果。 If the slightest mishap was to ever happen, the computer would crash miserably and spectacularly.如果发生了最轻微的事故,计算机就会惨痛而壮观地崩溃。 So, your puny little program does not even need to run: your computer and hundreds of millions of computers worldwide working flawlessly around the clock is proof that 1+1 is always computed as 2 with an extremely high degree of certainty.因此,您的小程序甚至不需要运行:您的计算机和全球数亿台计算机全天候完美运行,这证明 1+1 始终以极高的确定性计算为 2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM