Skip to content

Instantly share code, notes, and snippets.

@dmishin
Created June 28, 2023 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmishin/e6eef6600e63790d5d41df74c00283a0 to your computer and use it in GitHub Desktop.
Save dmishin/e6eef6600e63790d5d41df74c00283a0 to your computer and use it in GitHub Desktop.
Calculating and plotting smooth fractional iterates of 1-sqrt(1-x^2)
"""Calculate smooth iterates of the function
f:[0,1]->[0,1]
f(x) = 1-sqrt(1-x^2)
https://mathoverflow.net/questions/449748/what-are-the-iterates-of-x-mapsto-1-sqrt1-x2
https://twitter.com/gro_tsen/status/1674132770203881477
Generally, f(x) <= x
What is asymptotic behavior of the iterates?
For small x, f(x) = 1-sqrt(1-x^2) ~~ x^2/2
Then, for small x, its iterates are:
0 x
1 (1/2)^1*x^2
2 (1/2)^3*x^4
3 (1/2)^7*x^8
...
n (1/2)^(2^n-1)*x^(2^n) = 2*(x/2)^(2^n)
Smooth t'th iterate for small x is: f[t](x) = 2*(x/2)^(2^t)
Then approximate smooth t'th iterate can be calculated as:
f[t] ~~ f^-1 . f^-1 ... f^-1 . g[t] . f . f ... f
Where number of functions is the same before and after.
The idea: first apply x->f(x) n times, to make value small, then appply approximate smooth iterate for small x, then reverse.
Observation:
f = (1-x) . (sqrt(x)) . (1-x) . (x^2)
where (.) is function composition.
Inverse function:
f^(-1) = (sqrt(x)) . (1-x) . (x^2) . (1-x)
This way, it is eqsy to see why for integer iterates
(1-x) . f^(n) = f^(-1) . (1-x)
"""
import numpy as np
from math import sqrt
def f(x):
"""The function"""
return 1.0 - np.sqrt(1.0-x**2)
def f_inv(x):
"""Inverse function"""
return np.sqrt(2.0*x - x**2)
def f0t(x,t):
"""Smooth t'th iterate for small x"""
return 2.0*(0.5*x)**(2.0**t)
@np.vectorize
def ft(x, t, eps = 1e-3):
"""Approximate smooth t'th iterate, for all x"""
if x == 0: return 0.0
if x == 1: return 1.0
count = 0
while x > eps:
x = f(x)
count += 1
x = f0t(x,t)
for _ in range(count):
x = f_inv(x)
return x
if __name__=="__main__":
#Plot the smooth iterates
from matplotlib import pyplot as plt
xx = np.linspace(0.0, 1.0, 500)
for t in np.linspace(-2.0, 2.0, 21):
plt.plot(xx, ft(xx, t=t),label = f"$f^{{{t:0.2}}}(x)$")
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment