# Linear functions with rounding

If I convert 47°F to Celsius, rounding to the nearest integer, I get 8°C. If I then convert back to Fahrenheit, again rounding, I get 46°F. Back to Celsius, 8°C. Now of course if I continue this process it will remain stable, going back and forth between 8°C and 46°F. Will it always stabilize, for any given starting value?

More generally, suppose I have an arbitrary linear function, $f(x) = ax + b$, with inverse $f^{-1}(x) = \frac {x - b} a$. Using the rounding function $r(x) = \lfloor x + \frac 1 2 \rfloor$, define the round-trip function $g = r \circ f^{-1} \circ r \circ f$. Then the question is, does $g = g \circ g$? If not, is there always some $n$ for which $g^n = g^{n+1}$?

Empirically, it seems that $g$ is idempotent, but the proof has defied my meagre abilities.

Also, are there any more general things we can say? For instance if $f$ isn't necessarily linear, but strictly monotone, does the process of repeatedly applying, rounding, inverting, and rounding again always converge?

PS: Please feel free to add meaningful tags to this... I'm not sure what would be appropriate for this question.

### Edit

Vlad has found a counterexample, so let me amend the definition of rounding to be that if the fractional part is exactly .5, it yields the adjacent even number...

-

Consider the case of $f(x) = x + \frac12$.
You get $$n\mathrel{\mathop{\longmapsto}^f} \left(n+\frac12\right)\mathrel{\mathop{\longmapsto}^{rounding}}(n+1)\mathrel{\mathop{\longmapsto}^{f^{-1}}}\left(n+\frac12\right)\mathrel{\mathop{\longmapsto}^{rounding}} (n+1)$$ for $n\in\mathbb Z$. So for this $f$ the sequence wouldn't stabilize, because $g(n) = n + 1$.
@pelotom You will have the same problem potentially with $f(x)=x+1/4$ – Olivier Bégassat Aug 18 '11 at 9:38