I would like to go for search for this given functional equation using either java or python $f(x+1) = f(x)^2-1$

I would like to go for search for this given functional equation using either java or python $$f(x+1) = f(x)^2-1$$ $$f(0) = 1$$ I don't know where to start. I know how to graph in pycharm. I know basics in animation like object collision in java. I don't know how to go for estimation search for functional equations or in other manners any search whatsoever. If some one can give me both the algorithm and the manner for which I can program it, I would be glad.

• When you say you wish to "search for" the functional equation, are you trying to search the internet for information about it, or are you trying to solve it numerically (or something else entirely)? – Theo Bendit May 11 at 13:15
• Actually, $f^2(x)=f(f(x))$ and $f(x)^2=(f(x))^2.$ – Michael Rozenberg May 11 at 13:18
• No solving it numerically. – Alireza Rouhani May 11 at 13:18
• Mostly just graphing it. – Alireza Rouhani May 11 at 13:19
• @MichaelRozenberg Just fix it. Thank you. – Alireza Rouhani May 11 at 13:26

Let's look at some of its algebraic properties on the integers $$\mathbb Z$$.

For negative initial values, this immediately squares to become positive and for absolute values of $$2$$ or above, this will naturally grow exceedingly fast.

For moderate values, the square will instead push it down. If $$f(x)=0$$, then $$f(x+1)=0^2-1=-1$$ and if $$f(x)=\pm 1$$, then $$f(x+1)=(\pm 1)^2-1=0$$. In other words, once you touch the ground, you'll forever bounce down and back again.

So this is akin to $$-r(x,x_0,y_0)\cdot\frac{1}{2}\cdot(1-(-1)^x)$$ for some $$r$$ shirking with $$x$$.

On the reals, you may find some variation of functions with trigonometric relations (alla those of $$\sin(\pi x)-1$$).

I wrote you your python script and for the values I display here all values eventually end up in that pendulum. import matplotlib.pyplot as plt

x0 = -5
xfin = 10
xs = range(x0, xfin)

num_ys = 30
y_max = 1.5
y0s = [y_max * y / num_ys for y in range(-num_ys, num_ys)]

for y0 in y0s:

def f(x):
return y0 if x==x0 else f(x - 1)**2 - 1

ys = map(f, xs)

plt.plot(xs, ys)

plt.show()


If efficiency should be a concern, note that here in this implementation of constructing the ys, I do some unnecessary re-computation.

• Thank you. Is there way to make these graphs smooth?. – Alireza Rouhani May 11 at 14:05
• @AlirezaRouhani Should be doable, but to avoid accidental infinite recursion on $f(x - 1)$, you should use a rational number library or the check $x=x_0$ should be replaced with your own implementation of an approximate equality. Keep in mind that there's few programming languages where $0.1 + 0.2$ is $0.3$, see https://0.30000000000000004.com/. – Nikolaj-K May 11 at 14:13
• Thank you. That was very kind. – Alireza Rouhani May 11 at 14:16
• @AlirezaRouhani, if you find an answer helpful, please mark it as such. – NoChance May 11 at 14:29
• @Nikolaj-K, I ran the program, It is giving me error on plt.plot. I don't know why. – Alireza Rouhani May 11 at 14:41