The full text of Fermat's statement, written in Latin, reads "*Cubum autem in duos cubos, aut quadrato-quadratum in duos quadrato-quadratos, et generaliter nullam in infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet.*"

The English translation is: "It is impossible for a cube to be the sum of two cubes, a fourth power to be the sum of two fourth powers, or in general for any number that is a power greater than the second to be the sum of two like powers. I have discovered a truly marvelous demonstration of this proposition that this margin is too narrow to contain."

Here at SAS, we don’t take challenges lightly. After a short but intensive brainstorming, we came up with a creative and powerful SAS code that effectively proves this long-standing theorem. And it is so simple and short that not only can it be written on the margins of this blog, it can be tweeted!

Drum roll, please!

Here is the SAS code:

data _null_; do n=3 by 1; do a=1 by 1; do b=1 by 1; do c=1 by 1; e = a**n + b**n = c**n; if e then stop; end; end; end; end; run; |

Or written compactly, without unnecessary spaces:

data _null_;do n=3 by 1;do a=1 by 1;do b=1 by 1;do c=1 by 1;e=a**n+b**n=c**n;if e then stop;end;end;end;end;run; |

which is exactly 112 character long – well below the Twitter 140-character threshold.

Don’t be fooled by the utter simplicity and seeming unfeasibility of this code. For the naysayers, let me clarify that we run this code in a distributed multithreaded environment where each do-loop runs as a separate thread.

We also use some creative coding techniques:

1. Do-loop with just two options, **count=** and **by=**, but without the **to=** option (e.g. do c=1 by 1;). It is a valid syntax in SAS and serves the purpose of creating infinite loops when they are necessary (like in this case). You can easily test it by running the following SAS code snippet:

data _null_; start = datetime(); do i=1 by 1; if intck('sec',start,datetime()) ge 20 then leave; end; run; |

The if-statement here is added solely for the purpose of specifying a wait time (e.g. **20**) sufficient for persuading you in the loop’s infiniteness. Skeptics may increase this number to their comfort level or even remove (or comment out) the if-statement and enjoy the unconstrained eternity.

2. Expression with two “=” signs in it (e.g. e = a**n + b**n = c**n;) Again, this is a perfectly valid expression in SAS and serves the purpose of assigning a variable the value of 0 or 1 resulting from a logical comparison operation. This expression can be rewritten as

e = a**n + b**n eq c**n;

or even more explicitly as

e = (a**n + b**n eq c**n);

As long as the code runs, the theorem is considered proven. If it stops, then the theorem is false.

You can try running this code on your hardware, at your own risk, of course.

We have a dedicated 128-processor UNIX server powered by an on-campus solar farm that has been autonomously running the above code for 40 years now, and there was not a single instance when it stopped running. Except pausing for the scheduled maintenance and equipment replacements.

During the course of this historic experience, we have accumulated an unprecedented amount of big data (all in-memory), converted it into event stream processing, and become a leader in data mining and business analytics.

This leads us to the following scientific conclusion: whether you are a pure mathematician or an empiricist, you can rest assured that Fermat's Last Theorem has been proven with a probability asymptotic to 1 beyond a reasonable doubt.

Have a happy 91-st day of the year 2017!

## 24 Comments

Leonid,

OMG; this is as tremendous an achievement as it is a hilarious achievement!

Well written!

----MMMMIIIIKKKKEEEEE

Thank you, Mike. I am not surprised you are the first to appreciate it.

I'm awestruck with the 128 processor!

You have to really invest in R&D to stay ahead of the game...

And you have to invest in infrastructure, like the solar farm to power up that monster 😉

That is true, Vince. But investing is not wasting. Forward thinking, you don't have to pay those pesky electric bills.

But will it work on the 32-bit versions of SAS/Studio??

Andrew, as you know SAS software works on any platform. I have not tested this code specifically on the 32-bit versions of SAS/Studio, but I am guessing it will work, however with significantly diminished persuasion power. If you dare to run it in your environment please feel free to share your results with us.

A few observations regarding the code: firstly - the 'c' loop will be infinite, so the 'a' and 'b' loops will never advance off '1'; secondly - since SAS uses 8-byte floating point for numerics the loop will eventually reach a value where it can't tell the difference between c and c+1, and therefore cease advancing the iterator; thirdly, - is there anyway to disable the session time limits? I couldn't find any.

Fortunately, I give marks for effort . Try again next year.

G'Day, Mr. Birch!

Thank you so bloody much for making me fortunate to receive your marks for effort. Once a year, we can afford to have a few kangaroos loose in the top paddock. Your first argument that the 'a' and 'b' loops will never advance off '1' can be attributed to a too fast a reading and therefore missing the point. It is London to a brick that all the loops will run as described in this post: “For the naysayers, let me clarify that we run this code in a distributed multithreaded environment where each do-loop runs as a separate thread.” Secondly, when program will be approaching “a value where it can't tell the difference between c and c+1”, what would stop us from doubling numerics’ length to 16 bytes and let it run almost forever! Your third blue is not even an argument, it’s a question. And the answer to it is presented by the if-statement of the coding technique 1.

Give it away, the date of this publication is reserved for going off.

This proves it for the positive integer values in the real plane from 1 to as high as you have gone. Has this been tested on a continuum? What about with negative or complex values?

Thank you, Brad, for your endorsement of the proof. Fermat's Last Theorem actually states that no three

positive integersa, b, and c satisfy the equation a**n + b**n = c**n for anyinteger value of ngreater than 2. Therefore continuum, negative and complex values are not covered by Fermat's Last Theorem. If you can formulate a new theorem for negative and complex values, we will make our best efforts to title our next year April 1st post "SAS code to prove Morantz's Last Theorem".Great story! Since in the real world there are few programs that are supposed to run forever it is good to know that there exists a STOP statement.

Thank you, Erik, for your kind feedback. One cannot overestimate the value of the STOP statement.

The story is nice indeed. But would a mathematician consider this a proof? Waiting for infinity is not a human's option..

How frustrating, if the day after passing away the infinite iteration stops being infinite to find its first counterexample.

Thank you, Tomás, for your comment. Mathematicians are also humans. They love, they laugh, they err, and they are mortal. They live by delusional rules of logic which sometimes lead them to a dead end. In the real world of relativity, what once considered to be a "settled science" some day may become a prejudice. It is not frustrating when one's beliefs get dispelled

the daypassing away, it would have been frustrating when it happenedafterthe day...beforeThat, by far, is the most elegant SAS code I've seen. Simple to read, compact, and powerful. If it stops at some point, I won't be around to see it. 🙂

Thank you, Ed. So far, yours is the most elegant comment to this blog post.

Nice job, Lenny! Love posts like these with seriousness and humor.

Thank you, Matt! You must know then how hard it is to keep a straight face while doing it.

So that server that's been running for 40 years... I take it that started as a less than 128-core machine? Is it still running? Have there been any issues with numerical value ranges?

You are correct, Paul. It started as a less than 128-core machine. But my imagination settled on 128. It is still running as a condition of the theorem to be true. Happy belated April's Fools Day!

Stipulating that the code runs on a "distributed multithreaded environment where each do-loop runs as a separate thread", the number of cores will always be MUCH less than infinity, so how can this (empirically) prove Fermat's Last Theorem? The concept of limit might apply... I do not have access to SAS on such a system, but I would be interested what values of N, A, and B the processes might generate. It appears to me, naively, that only C will iterate.

Kevin, it's all about timing, timing of this publication that is. I am sorry that you discovered it 5 months and 17 days after it was published.