4

Simply: How do I solve this equation for a given $n \in \mathbb Z$?

$x^x = n$

I mean, of course $2^2=4$ and $3^3=27$ and so on. But I don't understand how to calculate the reverse of this, to get from a given $n$ to $x$.

2 Answers2

3

See this wikipedia article: Lambert W function

If $x^x=n,$ then $$x=\dfrac{\ln n}{W(\ln n)},$$ Where $W$ is the Lambert W function.

Bumblebee
  • 18,220
  • 5
  • 47
  • 87
  • Hey out of curiosity , could you show your steps how you got to x= ? – bigfocalchord Mar 29 '16 at 07:13
  • It may required a little knowledge about Lambert W function. You can find this from the given link. – Bumblebee Mar 29 '16 at 07:17
  • That requires more than a little knowledge, and I've never heard of the Lambert W function before... I would need to find a way to code this in Python, but I can't use the scipy package where this function would be built in... :-/ – Byte Commander Mar 29 '16 at 07:26
  • @ByteCommander Basically, you're not going to find a solution in terms of elementary functions. You either have to use a numerical approximation algorithm (as noted in marty cohen's answer), or a special function such as this (Lambert W function). – Eff Mar 29 '16 at 07:28
  • 1
    @ByteCommander If you wish to calculate the Lambert W function, there are some easy methods you may find in the Lambert W tag. – Simply Beautiful Art Apr 02 '16 at 13:02
1

Simpler:

If $x^x = n$, then $x\ln(x) = \ln(n) =y$.

Let $f(x) = x\ln(x)-y $. $f'(x) =\ln(x)+1 $.

Applying Newton's iteration, starting with $x = \frac{y}{\ln y}$, $x_{new} =x-\frac{f(x)}{f'(x)} =x-\frac{x\ln(x)-y}{\ln(x)+1} =\frac{x\ln(x)+x-x\ln(x)+y}{\ln(x)+1} =\frac{x+y}{\ln(x)+1} $.

Iterate until cooked.

marty cohen
  • 107,799
  • Thanks for your explanation. But maybe the formula would be more clear if you don't substitute $y = ln(n)$... – Byte Commander Mar 29 '16 at 07:34
  • And I just noticed that your value for $y$ must be manually set to $1$ or something similar if $n<1$. Else we get a problem because it would evaluate to $ln(0)$. – Byte Commander Mar 29 '16 at 07:48
  • @ByteCommander Yes, of course, it is recommended that you choose $y$ so that you can avoid such troubles. Interestingly, if you choose different $y$ values, you may experience different complex or real results... (try Google calculator for complex logarithm) – Simply Beautiful Art Apr 02 '16 at 13:01