5^5^5^5
doesn't require so many operations after all. For example, at each power step, say a^b
, you can compute exp(log(a)*b)
, which gives the same result.
I'm not saying this is necessarily how Matlab does it, and there may be numerical precision issues. But this illustrates that a multiple-power operation is not so hard as its direct computation would suggest.
As for numerical precision:
>> format long
>> 5^5^5^5
ans =
2.350988701644576e+087
>> exp(log(exp(log(exp(log(5)*5))*5))*5)
ans =
2.350988701644561e+087
The relative error is
>> 1 - (5^5^5^5 / exp(log(exp(log(exp(log(5)*5))*5))*5))
ans =
-6.661338147750939e-015
which is not very far from eps
.