Fermat's Last Theorem states that no three positive integers $x$, $y$ and $z$ can satisfy the equation $x^n + y^n - z^n = 0$ for any integer $n>2$. Explain this apparent counter-example to the theorem:
In [x]: 844487.**5 + 1288439.**5 - 1318202.**5
Out[x]: 0.0
The problem, of course, is that the expression has been written using double-precision floating point numbers and the difference between the sum of the first two terms and the third is smaller than the precision of this representation. Using the exact representation in integer arithmetic,
In [x]: 844487**5 + 1288439**5
Out[x]: 3980245235185639013055619497406
In [x]: 1288439**5
Out[x]: 3980245235185639013290924656032
giving a difference of
In [x]: 844487**5 + 1288439**5 - 1318202**5
Out[x]: -235305158626
The finite precision of the floating point representation used, however truncates the decimal places before this difference is apparent:
In [x]: 844487.**5 + 1288439.**5
Out[x]: 3.980245235185639e+30
In [x]: 1318202.**5
Out[x]: 3.980245235185639e+30
This is an example of catastrophic cancellation.