When does function iteration converge to a fixed point? After watching a Youtube video by blackpenredpen (only 54 seconds long) showing how to write 5 as an infinite nested square root it got me thinking.
This is what he showed in the video:

$
\begin{align}
x  &= 5
\\x-5& = 0
\\(x-5)(x+4)&=0
\\x^2-x-20&=0
\\x^2&=20+x
\\x&=\sqrt{20+x}
\\x&=\sqrt{20+\sqrt{20+x}}
\\x&=\sqrt{20+\sqrt{20+\sqrt{20+\sqrt{20+\sqrt{20+x}}}}}
\end{align}
$
$x$ converges to 5 with the above infinite square root. Nothing weird about that, I tried multiplying by other equations instead of $(x+4)$ and got other fun infinite square roots. $x=\sqrt{10+3\sqrt{10+3x...}}$ and $x = \sqrt{30-\sqrt{30-\sqrt{30-x...}}}$. Both converge to 5 too, all good.
However I wanted to see if it would work without using square roots everywhere. So this is what I tried:

$
\begin{align}
x^2&=20+x
\\x&=x^2-20
\\x&=(x^2-20)^2-20
\end{align}
$
Both $x=x^2-20$ and $x=(x^2-20)^2-20$ diverge (tested by iterating with code), and I have no clue why and I want to know why. My guess would be that it has something to do with the derivative. The derivative at the interesting point, $x=5$, is $\frac{d}{dx}(x^2-20)=2x=10$. And it does not converge. The derivative of one that does converge is $\frac{d}{dx}\sqrt{20+x}=\frac{1}{2\sqrt{20+x}}=0.1$, that is two orders of magnitude smaller than the diverging one. Am I onto the right track? Is there some kind of theorem that states that the derivative has to be less than 1?
I know about Newton's method, a proven technique for finding the zeros to functions. I am curious about why using equations on the form ($x=\sqrt{x}$) converges and why using $x=x^2$ diverges.

You are exactly right. There is a simple rule coming from chaos theory that tells you whether certain fixed points are sinks or sources for a function being iterated. Basically, suppose $f$ is some continuously differentiable function such that $f(x_0)=x_0$. If $|f'(x_0)|>1$ then $x_0$ is a source. If $|f'(x_0)|<1$ then $x_0$ is a sink. If $|f'(x_0)|=1$ then it can go either way.
