TITLE: A curious expression involving the nearest-integer function whose sum appears to be 3
QUESTION [6 upvotes]: Let $ \def\nint#1{\langle #1\rangle}\nint x$ denote the integer closest to $\sqrt x$.  This is ambiguous whenever $\sqrt x$ is a half-integer; fortunately such will not arise in the rest of this question, and we  may simply take $\nint x = \left\lfloor \sqrt x+\frac12\right\rfloor$.
Now consider the sum $$S(k) = \def\nint#1{\langle #1\rangle} \sum_{i=1}^\infty \frac{k^{\nint i} + k^{-\nint i}}{k^i}$$
Computer calculations unequivocally suggest that $$S(k)=\frac{k+1}{k-1}$$ for all $k>1$; in particular $$S(2) = 3.$$  Is this correct, and if so, what is a proof?  I imagine a counting argument that calculates the number $C_n$ of different $i$ at  which the function $\nint i$ takes the value $n$, but I have not worked out the details. I would also be interested to see an argument about the region in which $S$ converges.
[ The $k=2$ case of this question has been asked at least twice 1 2 in the past couple of days, and closed both times, but I think it deserves more attention. ]

REPLY [4 votes]: I think I have an answer for the case $k=2$, and the method can be used for the general case. The question (for $k=2$) has been closed before I can put this answer.
Let $k\geq 1$. For $n\in \mathbb{N}$, there exists $k$ such that $k-\frac{1}{2}\leq \sqrt{n}\leq k+\frac{1}{2}$. We cannot have $\sqrt{n}=k\pm \frac{1}{2}$, and the set of $n$ such that $<n>=k$ is $(k^2-k, k^2+k]$. We sum first over such a set:
$$\sum_{k^2-k<n\leq k^2+k}\frac{2^{<n>}+2^{-<n>}}{2^n}=2\frac{4^{2k}-1}{2^{(k+1)^2}}$$
Hence your sum is
$$S=2\sum_{k\geq 1}\frac{4^{2k}-1}{2^{(k+1)^2}}$$
Put $$f(x)=\sum_{m\geq 1}\frac{x^m}{2^{(m+1)^2}}$$ This is an entire function. We have $S=2(f(4^2)-f(1))$. 
We compute  $$f(4x)=\frac{x}{4}+\frac{x}{2}f(x)$$
and 
$$f(4^2x)=x+\frac{x^2}{2}+x^2f(x)$$
We put $x=1$:
$\displaystyle f(4^2)-f(1)=\frac{3}{2}$ and hence $S=3$.