<p>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.</p>

<p>The very first sentence of the blog post says "<a href="http://blog.regehr.org/archives/140" rel="nofollow">Obviously I’m not serious</a>".  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 <a href="http://blog.regehr.org/archives/161" rel="nofollow">follow-up blog post</a> that explains stuff in more detail... also posted before your question.</p>

<p>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.</p>

CC BY-SA 3.0
2014-05-13T17:13:39.793Z
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).
Kaveh
CC BY-SA 3.0
2014-05-13T17:23:11.037Z
@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.
D.W.
CC BY-SA 3.0
2014-05-12T23:58:28.067Z
2014-05-12T23:58:28.067Z
D.W.
<p>The following blog:</p>

<p><a href="http://blog.regehr.org/archives/140" rel="nofollow">http://blog.regehr.org/archives/140</a></p>

<p>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$. </p>

<p>The check code is given by:</p>

<pre><code>#include &lt;stdio.h&gt;

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&gt;MAX) {
            a=1;
            b++;
        }
        if (b&gt;MAX) {
            b=1;
            c++;
        }
        if (c&gt;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;
}
</code></pre>

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

<p>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.</p>

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

<pre><code>while (1) {
if((a*a)==(b*b)+(c*c)) return 1;
    a++;
    if (a&gt;MAX) {
        a=1;
        b++;
    }
    if (b&gt;MAX) {
        b=1;
        c++;
    }
    if (c&gt;MAX) {
        c=1;
    }
}
</code></pre>

<p>which returns: Fermat's Last Theorem has been disproved as well...</p>

<p>Would this confirm that there is effectively a bug in LLVM?</p>

CC BY-SA 3.0
2014-05-12T02:22:39.420Z
Thus is not a theoretical computer science question.
Jeffε
CC BY-SA 3.0
2014-05-12T10:54:29.023Z
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.
Neel Krishnaswami
<compilers>
Fermat's last theorem and the LLVM compiler
mathersjj1
# Fermat's last theorem and the LLVM compiler

(Asked by: username_0 on 2014-05-11)

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 

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?

**Tags:** compilers
> **Comments:**
> **username_1**: Thus is not a theoretical computer science question.  
> **username_2**: 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.  

---

## 1 answers

### Answer by username_3 on 2014-05-12. Score: 4

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](http://blog.regehr.org/archives/140)". 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](http://blog.regehr.org/archives/161) 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.

> **Comments:**
> **username_4**: 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).  
> **username_3**: @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.  

---

