lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


but a basic asymptotic approcimation cannot work for any number x that sastisfies x^x > 15.5 (which can be very large).
So let's see where x^x does not return  positive infinite (starting at 2^1024).
We need the mathematic solution for x^x = 2^1024.

But let's start by how we can compute the base-2 exponent (which will be betwen 3 and 1024 for this problem) to get a rough estimate of the order of magnitude
log_2(x^x) =x*log_2(x) = 1024
so x= 1024/log_2(x). and then x must be below 

The problem states that x^x>15.5, so x >15.5/log_2(x) (this will be used for tuning the value of the mantissa and correct the effect of the approximate base-2 exponent.

There's not a lot of values of x that can qualify, it is in a small range in the open range (3.3, 395)
If x is to be restricted to be an integer, this x is in the integer range 4..394 (because 395^395>2^1024 and gives a positive infinite value for 64-bit IEEE doubles)

But in that case a table lookup is not possible (the integer range 4..394 would contain 390 double values in a static table)

So what is to approximate if the base-2 integer exponent of x^x and then we can correct the mantissa; and this requires amultiplication from the correct mantissa, by the approximation of the base-2 exponent.

This will still produce large errors compared to the recursive method using the derivative function of (x => x^x), which is (x => (ln(x) + 1) * x^x).

The recursive function will then loop by dividing the current approximation of x^x, by (log(x)+1), to form the new approximation by taking the average (it will have a fast convergence, but now you need a way to compute ln(x) or you can use math.ln(x).





Le jeu. 27 juin 2019 à 09:14, Dirk Laurie <dirk.laurie@gmail.com> a écrit :
Op Wo. 26 Jun. 2019 om 22:47 het Egor Skriptunoff
<egor.skriptunoff@gmail.com> geskryf:
>
> Global variable "C" contains numeric value > 15.5
> The solution of math equation x^x=C must be printed
> Your code must fit into 36 bytes
> Dirty tricks are allowed

That constant 15.5 sticks out like a sore thumb.

The solution to the problem is likely to be non-iterative: some
truncated asymptotic expansion, accurate enough for C>15.5. The dirty
trick may be the replacement of some annoying number by a simpler one,
e.g. 839/5040 by 1/6. Rather like Henrici's program for calculating
the gamma function on the HP 25 pocket calculator.

But right now I don't have the energy to pursue the idea.