-4
$\begingroup$

The following blog:

http://blog.regehr.org/archives/140

discusses how the LLVM compiler seems to prove that Fermat's last theorem is false by showing that the compiler optimizes the $while(1)$ "check" code to the opcode $ret$.

The check code is given by:

#include <stdio.h>

int fermat (void) {
    const int MAX = 1000;
    int a=1,b=1,c=1;
    while (1) {
        if (((a*a*a) == ((b*b*b)+(c*c*c)))) return 1;
        a++;
        if (a>MAX) {
            a=1;
            b++;
        }
        if (b>MAX) {
            b=1;
            c++;
        }
        if (c>MAX) {
            c=1;
        }
    }
    return 0;
}
int main (void) {
    if (fermat()) {
        printf ("Fermat's Last Theorem has been disproved.\n");
    } else {
        printf ("Fermat's Last Theorem has not been disproved.\n");
    }
    return 0;
}

and returns: Fermat's Last Theorem has been disproved in LLVM GCC 4.2.

Many are questioning if LLVM truly disproved Fermat's last theorem by eliminating the $while(1)$ loop in its compile process or if it is because of a bug in LLVM.

So I replaced the while loop with something that I know should return theorem proved (the $a^2=b^2+c^2$ case):

while (1) {
if((a*a)==(b*b)+(c*c)) return 1;
    a++;
    if (a>MAX) {
        a=1;
        b++;
    }
    if (b>MAX) {
        b=1;
        c++;
    }
    if (c>MAX) {
        c=1;
    }
}

which returns: Fermat's Last Theorem has been disproved as well...

Would this confirm that there is effectively a bug in LLVM?

$\endgroup$
  • 4
    $\begingroup$ Thus is not a theoretical computer science question. $\endgroup$ – Jeffε May 12 '14 at 2:22
  • 7
    $\begingroup$ It's not a bug in LLVM. It's the result of some utter lunacy in the C++ standard, which says that compilers may assume all loops (which do not do I/O) terminate. $\endgroup$ – Neel Krishnaswami May 12 '14 at 10:54
4
$\begingroup$

Read the post you are linking to. It's explained there in quite some detail. It's a consequence of the C++ spec, as Neel Krishnaswami explains.

The very first sentence of the blog post says "Obviously I’m not serious". That should have been a tip-off right there. The post then goes on to say "What is really going on here..." and explains what's going on. The blog post also has a number of updates added (all posted before your question here) that also elaborate even further. For instance, the FAQ at the bottom contains the question "Didn’t you know Fermat’s Last Theorem was proved in 1995?" and answers "I did know that. [...] I was making a weak joke [...]". It also links at the very top to a follow-up blog post that explains stuff in more detail... also posted before your question.

So, no, your claim that "Many are questioning if LLVM truly disproved Fermat's last theorem..." does not seem accurate or helpful to me. You might want to re-read those blog posts to re-assess your premises, then see if you have a more specific question.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ I think it would be better if this was posted as a comment (closed questions with negative total votes without a positively voted answer get automatically deleted after sometime). $\endgroup$ – Kaveh May 13 '14 at 17:13
  • $\begingroup$ @Kaveh, thanks for the suggestion. Either way, people with enough rep can certainly vote to delete the question, and I think that would be appropriate for this question. If I could, I would vote to delete the question, but I don't have enough rep to vote to delete. $\endgroup$ – D.W. May 13 '14 at 17:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.