給一個具體的軟件,你們看看會不會crash?
假設用GNU的大整數library,所有int變量都可以是任意大的自然數。其中用print的那一行有可能造成0除以0,在C裏麵整數0除以0程序要crash的。請問這個程序會crash嗎?如果你知道會不會,你就知道了哥猜想對不對。
存在類似的程序,它不需要任何外界輸入,運行過程是決定地而且唯一的,但是連數學家都不可能知道它會不會crash。有意思吧?
int is_prime(int x) {
for (int i = 2; i*i
if (mod(x, i) == 0) { // i divides x, not a prime
return 0;
}
}
return 1;
}
void test_goldbach() {
for (int n = 6; ; n = n + 2) { // Iterate over even numbers n.
for (int x = 2; x
if (!is_prime(x)) {
continue;
}
for (int y = 2; y
if (!is_prime(y)) {
continue;
}
// Now we have x and y prime numbers.
// If x + y == n, we test the next n.
if (x + y == n) {
goto next_n;
}
}
}
next_n:;
// By construction of the loops, if n invalides Goldbach,
// then x == y == n, and (n - x) / (n - y) will crash
// with a division by 0 error.
// Otherwise, the code can go on.
print((n - x) / (n - y));
}
}