Generalized Fermat's Theorem:
abs(((X^n + Y^n) / Z^n) - 1.0) < eps,
where 0 < X < Y < Z
Code:
with pN(n, lim, eps) as
( select 3, 300, double(1e-6) from sysibm.sysdummy1)
,
ArgX(x, XpN) as
(select int(1), double(1) from sysibm.sysdummy1
union all
select X + 1, power(double(X + 1), N)
from ArgX, pN
where X + 1 <= lim
)
,
ArgY(y, YpN) as
(select * from ArgX )
,
ArgZ(z, ZpN) as
(select int(1), double(1) from sysibm.sysdummy1
union all
select Z + 1, power(double(Z + 1), N)
from ArgZ, pN
where Z + 1 <= lim * power(2, 1. / n) + 1
)
select X argX, Y argY, Z argZ , N "Power", (ZpN - (XpN + YpN)) "Absolute Difference" ,
double(ZpN) / double(XpN + YpN) - 1.0 "Relative Difference"
from ArgX, ArgY, ArgZ, pN
where ZpN between (XpN + YpN) * ( 1. - eps) and (XpN + YpN) * ( 1. + eps)
and X < Y
and Y < Z
and X < Z
and Z <= X + Y
order by abs(ZpN - (XpN + YpN)), X, Y
For eps = 1e-6 we have 17 solutions in this interval....
But for eps = 1e-7 we have only one solution:
Code:
select power(135, 3) + power(235, 3) - power(249, 3)
from sysibm.sysdummy1
We can see 135^3 + 235^3 = 248^3 + 1 (
not bad !).
For eps = 1e-8 we have no solutions in this interval, even for Generalized
Fermat's Theorem.
Maybe that's why Fermat's Theorem doesn't have solutions when n >=3.
Lenny Khiger, ADSPA&VP