Consider the following recursive function $f()$
def f(x,n=0):
if x<2:
return n
return f(math.sqrt(x),n+1)
$f(x)$ calculates the number of square-root operations that need to be taken such that the result is less than 2
Is there a way to calculate that analytically with a formula ?
The square root of $x$ is $x^{1/2}$. If you take the square root $n$ times, you get $((x^{1/2})^{\dots})^{1/2} = x^{1/(2^n)}$. We want the minimum integer value of $n$ such that $x^{1/(2^n)} < 2$.
Taking the logarithm (base $2$) of both sides, we want $\frac{1}{2^n}\log_2(x)< 1$, which is equivalent to $2^n > \log_2(x)$, and (taking another logarithm) $n>\log_2(\log_2(x))$. So the minimum integer value of $n$ satisfying this inequality is $\lceil \log_2(\log_2(x))\rceil$.