Given a positive integer n and a number a, the n-th tetration of a is defined as a^(a^(a^(...^a))), where ^ denotes exponentiation (or power) and the expression contains the number a exactly n times.
In other words, tetration is right-associative iterated exponentiation. For n=4 and a=1.6 the tetration is 1.6^(1.6^(1.6^1.6)) ≈ 3.5743.
The inverse function of tetration with respect to n is the super-logarithm. In the previous example, 4 is the super-logarithm of 3.5743 with "super-base" 1.6.
Given a positive integer n, find x such that n is the super-logarithm of itself in super-base x. That is, find x such that x^(x^(x^(...^x))) (with x appearing n times) equals n.
Program or function allowed.
Input and output formats are flexible as usual.
The algorithm should theoretically work for all positive integers. In practice, input may be limited to a maximum value owing to memory, time or data-type restrictions. However, the code must work for inputs up to
100 at least in less than a minute.
The algorithm should theoretically give the result with
0.001 precision. In practice, the output precision may be worse because of accumulated errors in numerical computations. However, the output must be accurate up to
0.001 for the indicated test cases.
Shortest code wins.
1 -> 1 3 -> 1.635078 6 -> 1.568644 10 -> 1.508498 25 -> 1.458582 50 -> 1.448504 100 -> 1.445673
Here's a reference implementation in Matlab / Octave (try it at Ideone).
N = 10; % input t = .0001:.0001:2; % range of possible values: [.0001 .0002 ... 2] r = t; for k = 2:N r = t.^r; % repeated exponentiation, element-wise end [~, ind] = min(abs(r-N)); % index of entry of r that is closest to N result = t(ind); disp(result)
N = 10 this gives
result = 1.5085.
The following code is a check of the output precision, using variable-precision arithmetic:
N = 10; x = 1.5085; % result to be tested for that N. Add or subtract 1e-3 to see that % the obtained y is farther from N s = num2str(x); % string representation se = s; for n = 2:N; se = [s '^(' se ')']; % build string that evaluates to iterated exponentiation end y = vpa(se, 1000) % evaluate with variable-precision arithmetic
x = 1.5085:
y = 10.00173...
x = 1.5085 + .001:
y = 10.9075
x = 1.5085 - .001it gives
y = 9.23248.
1.5085 is a valid solution with