13

Please have a look at the function: $$f(x) = \left(x + \frac{1}{x^x}\right)^x - x^x$$

You may see the plot on Wolfram Alpha.

Why does it have such a weird behaviour from $x = 13$? It starts swinging up and down so weirdly!

soshial
  • 233
  • 11
    My guess is floating point error. When using floating point numbers, significant digits start to become a big factor. $x^{-x}$ vs $x^x$ would be a source of concern. My guess is it is bouncing between large positive and negative numbers because it is having trouble manipulating these numbers on these growing disparate scales – cnick Jun 10 '14 at 17:00
  • Closer inspection suggest things start to squiggle in an unstable fashion between $x=7$ and $8$ – cnick Jun 10 '14 at 17:04
  • 3
    The machine epsilon for number in IEEE double precision is about $2.2\times 10^{-16}$ (i.e 53 bit of precision). At $x = 13$, the relative error between the two terms $x$ and $x + \frac{1}{x^x}$ is $1/(13^{14}) \sim 2.539\times 10^{-16}$. That's why the number start to become really crazy at $x \sim 13$. – achille hui Jun 10 '14 at 17:22
  • Why does this function start swinging up and down so weirdly? - Because it's a ninja function ! :-) Or maybe a ninja disguised as a function ! – Lucian Jun 10 '14 at 17:57
  • @achille-hui, but why does it start squiggling in an unstable fashion on x ∈ (7, 8)? Why is the bouncing doesn't start abruptly, but increases so mildly? – soshial Jun 10 '14 at 17:59
  • @soshial I have no idea. In any event, whenever I see something start to squiggle, I will redo my calculation with higher precision to make sure I get the qualitative feature right. – achille hui Jun 10 '14 at 18:07
  • @soshial If one solve the equation $(x^{-(x+1)})^2 = 2.2\times 10^{-16}$, one find $x \sim 7.784$, this is approximately where the squiggling start. It looks like in the middle of the calculation, some quadratic small term hit the machine epsilon and trigger the behavior you saw there. – achille hui Jun 10 '14 at 18:30
  • With enough digits of precision the oscillations disappear. In Mathematica, the command Plot[(x + 1/x^x)^x - x^x, {x, 1, 20}, WorkingPrecision -> 100, PlotRange -> All, Axes -> False, Frame -> True] produces this plot: http://i.stack.imgur.com/7lUmq.png – Antonio Vargas Jun 11 '14 at 02:50

3 Answers3

7

Using the binomial theorem, we get $$ \begin{align} \left(x+\frac1{x^x}\right)^x-x^x &=x^x\left[\left(1+\frac1{x^{x+1}}\right)^x-1\right]\\ &=x^x\left[\frac1{x^x}+\frac{x-1}2\frac1{x^{2x+1}}+O\left(\frac1{x^{3x}}\right)\right]\\ &=1+\frac1{2x^x}+O\left(\frac1{x^{x+1}}\right) \end{align} $$ If you are getting wild oscillations or quantized output, it is probably due to truncation error.

The bottleneck actually seems to be in the computation of $x+\frac1{x^x}$ since IEEE double precision arithmetic only has a $53$ bit mantissa. $13$ has $4$ bits and $13^{-13}$ has $48$ zeros after the binary point before the first non-zero bit. So there is just barely enough precision to note that there is a difference between $x+\frac1{x^x}$ and $x$. Any imprecision in the computation would completely overwhelm this difference and cause extreme problems in the final computation.

robjohn
  • 345,667
  • Interesting. In $[12,13]$ GeoGebra goes crazy, and returns $0$ after $x=14$. – Pedro Jun 11 '14 at 00:57
  • Actually, at $x \sim 13.037$, $1/x^x$ is already about $2.22\times 10^{-16} \times x$, the IEEE 754 double precision numbers no longer have enough bits to distinguish between $x + \frac{1}{x^x}$ and $x$. – achille hui Jun 11 '14 at 01:08
4

As others have said this is a floating point error. If I plot it in mathematica I find:

enter image description here

Which clearly resembles the output by WolframAlpha (although they are not the same). If I increase the precision of the calculations and replot the same equation I find the following:

enter image description here

Note the change in scale.

Even with this increased precision you will still find erroneous weird behavior after some time and you will have to increase the working precision again (ad infinitum).

Brad
  • 5,156
  • 2
  • 19
  • 50
3

Yes, almost certainly floating point error.

$$f(x)= x^x\left(\left(1+\frac{1}{x^{x+1}}\right)^x-1\right)$$

For $x$ large, $\left(1+\frac{1}{x^{x+1}}\right)^x = 1+\frac{1}{x^x}+O(x^{-2x})$

So $f(x)=1+ O(x^{-x})$.

Thomas Andrews
  • 177,126