# Infinite Recursion And It's Limits

Posted by Bedaywi, Mark on December 24, 2019

After playing with tetration, I started to wonder how we can solve equations of the form:
${x}^{x}=b\phantom{\rule{1em/}{0ex}}$

To approach this problem we can look to the properties of infinite recursion. Generally, we can represent a function being applied with itself as so:
$\underset{n\to \infty }{lim}{f}^{n}\left(x\right)=\mathrm{f\left(f\left(f\left(f\left(f\left(f\left(f\left(f\left(...}=k\phantom{\rule{1em/}{0ex}}$

We can take both sides as input to $f$. Notice how the left side stays the same, since one added to infinity is still infinity. Since both $f\left(k\right)$ and $k$ can be represented using infinite recursion $f\left(k\right)$ and $k$ must be equal.
$\mathrm{f\left(f\left(f\left(f\left(f\left(f\left(f\left(f\left(...}=k\phantom{\rule{0ex}{0ex}}\mathrm{f\left(f\left(f\left(f\left(f\left(f\left(f\left(f\left(...}=f\left(k\right)\phantom{\rule{0ex}{0ex}}f\left(k\right)=k$

This means we can solve any equation of the form $f\left(x\right)=x$ by computing the value of ${f}^{n}\left(x\right)$ for some large $n$. Note the choice of $x$ is important in some cases. Trivially, if $x=k$ then the identity always applies. Most of the time the choice of $x$ is arbitrary and infinite recursion eventually reaches a limit. In cases where a solution doesn't exist the function cannot ever approach a value for any choice of $x$. Lastly, some functions have unstable solutions, where only a specific set of starting $x$ values result in the recursion reaching a limit. We can demonstate this with these two simple functions:
$f\left(x\right)=\frac{x+1}{3}\phantom{\rule{0ex}{0ex}}g\left(x\right)=\frac{{x}^{2}+1}{3}$
We can see that starting at any value for $x$ would always lead to $f\left(x\right)$ approaching 0.5, but for $g\left(x\right)$ $x$ has to be between -1 and 1 to approach one of the solutions 0.38196, to find the second solution $x$ must be equal to $\frac{3+\sqrt{5}}{2}$ exactly for it to approach it. The second function is more unstable and the second solution is the most unstable.

We can apply this technique to more interesting functions like $f\left(x\right)=cos\left(x\right)$. Finding $cos\left(cos\left(cos\left(cos\left(cos\left(\text{...}$ for some arbitrary starting point leads us to the solution $x=0.73908$.

Going back to the original question consider the function:
$f\left(x\right)={log}_{\frac{1}{b}}x\phantom{\rule{1em/}{0ex}}$
Doing some rearranging we can turn this into our original problem:
${log}_{\frac{1}{b}}x=x\phantom{\rule{0ex}{0ex}}{\frac{1}{b}}^{x}=x\phantom{\rule{0ex}{0ex}}\frac{1}{b}={x}^{\frac{1}{x}}\phantom{\rule{0ex}{0ex}}b={\frac{1}{x}}^{\frac{1}{x}}$

This means that the limit $\underset{n\to \infty }{lim}{f}^{n}\left(x\right)$ gives us the reciprocal of the solution to ${x}^{x}=b$ for the $b$ in the function. In practice we need to take the absolute value of $x$ to ensure that $x$ remains in the functions domain, this is when we only care about real solutions. This is a much better way to find the solution compared to Newton's method as only one logarithm function is needed. Furthermore, I've found that the values converge to the solution faster when starting at the same values.

Using this knowledge, we can write some code that solves equations like this for us:

def solve(b, time=500, accuracy=100):
#Solves x^x=b
from math import log
import decimal

decimal.getcontext().prec = accuracy
x = decimal.Decimal(2) #this value is arbitrary

for _ in range(time):
x = decimal.Decimal(log(abs(x), 1/b))
return 1/x

As a result of this we can now not only solve some tetration equations faster but also we have a new tool to calculate numerical solutions to equations and a new way of thinking of functions. Nice!