Iteration of the function $d(n)=a-n$ I start by defining the function $f$
$$f(0)=0,~~~~~f(n+1)=d(f(n))=a-f(n)$$
So:
$$f(n)=d^{\circ n}(0)$$
$f(1)=a-0=a$
$f(2)=a-(a-0)=0$
$f(3)=a-(a-(a-0))=a$
How can I find the solution of $f(x), x\in\mathbb R$?
I notice that:
$$f(n)=\underbrace{a+(-a)+a+(-a)+...}_n$$
So maybe I think $f(n)=\sum_{i=1}^n a(-1)^{i+1}$ $n\in\mathbb N$ is right, but I can't understand how this result would help me find a value for $f(x), x\in\mathbb R$  And given the summation, how can I find a closed form using known functions?
 A: Bear in mind that extensions of integer recurrence relations are not unique; a recurrence like $ f(x+h) = g(f(x)) $ is unique only up to some term with period h. 
In this case, we have that $ f(x) = a\cdot[1 + ({-1^{x-1})}] $.
So the obvious extension from $ \mathbb N $ to $ \mathbb R $ is just to use the substitution of $ -1^n = e^{n{\pi}i} $, giving $ f(x)=a\cdot(1+e^{(x-1){\pi}i})$, which is equivalent to $ f(x) =a\cdot[1 + cos({\pi}x-\pi) + isin({\pi}x - \pi)]$, which is unfortunately complex-valued.
Hoever, we can now exploit the fact already mentioned above, that we can simply add or subtract any function with the proper period, and subtract out the imaginary term. In general, you can always just shortcut $ (-1)^n $ to $ cos(n{\pi}) $ without trouble. Hence, a solution is that $ f(x) = a\cdot(1 +  cos({\pi}x-\pi)) $. Again, this is not unique; there are other valid extensions from your original recurrence relation to the real numbers. However, it does correspond to the original recurrence at every point where that recurrence is defined.
