Bound on $\sum\limits_{n=0}^{x}{\sin{\sqrt{n}}}$

Using Desmos and Mathematica, I was able to find a function $g(x)$ that seemingly estimated the function

$$f(x)=\sum_{n=0}^{x}{\sin{\sqrt{n}}}$$

I found that

$${g(x)=2\sqrt{x}*\sin{\left({{\sqrt{4x+{\pi}^2}-\pi}\over{2}}\right)}}\approx f(x)$$

Furthermore, I found that the difference between these two functions, or $|{f(x)-g(x)}|$, never seemed to exceed some constant $C\approx 0.464568$

Is there some way to prove the conjecture below?

$g(x)<f(x)<(g(x)+C)$ for all $x>14$

Or perhaps a weaker version considering I have no good definition for $C$:

$g(x)<f(x)<(g(x)+{1\over2})$ for all $x>14$.

Further questions:

Is there a closed form for $C$?

Is there a closed form for $f(x)$?


(Too long for a comment)


We have

\begin{align*} f(x) = \sum_{k=1}^{n} \int_{0}^{\sqrt{k}} \cos x \, dx = \int_{0}^{\infty} \left( \sum_{k=1}^{n} \mathbf{1}_{\{ x < \sqrt{k}\}} \right) \cos x \, dx. \end{align*}

Notice that $\sum_{k=1}^{n} \mathbf{1}_{\{ x < \sqrt{k}\}} = (n - \lfloor x^2 \rfloor)_+$, where $a_+ = \max\{a, 0\}$ denotes the positive part of $a$. So

\begin{align*} f(x) &= \int_{0}^{\sqrt{n}} (n - \lfloor x^2 \rfloor) \cos x \, dx \\ &= \int_{0}^{\sqrt{n}} \left(n - x^2 + \frac{1}{2} \right) \cos x \, dx + \int_{0}^{\sqrt{n}} \left(x^2 - \lfloor x^2 \rfloor - \frac{1}{2} \right) \cos x \, dx \end{align*}

The first integral is easy to evaluate:

$$ \int_{0}^{\sqrt{n}} \left(n - x^2 + \frac{1}{2} \right) \cos x \, dx = -2\sqrt{n}\cos\sqrt{n} + \frac{5}{2}\sin\sqrt{n}. $$

To evaluate the second integral, we substitute $x^2 \mapsto x$ to write

\begin{align*} \int_{0}^{\sqrt{n}} \left(x^2 - \lfloor x^2 \rfloor - \frac{1}{2} \right) \cos x \, dx &= \sum_{k=0}^{n-1} \int_{0}^{1} \left(x - \frac{1}{2}\right) \frac{\cos\sqrt{x+k}}{2\sqrt{x+k}} \, dx \\ &= \sum_{k=0}^{n-1} \int_{0}^{\frac{1}{2}} x \left( \frac{\cos\sqrt{k+\frac{1}{2}+x}}{2\sqrt{k+\frac{1}{2}+x}} - \frac{\cos\sqrt{k+\frac{1}{2}-x}}{2\sqrt{k+\frac{1}{2}-x}} \right) \, dx \end{align*}

Although I cannot prove at this point, numerical evidence suggests that this integral converge as $n\to\infty$. Assuming this, it follows that

Conjecture. $c = \lim_{n\to\infty} \int_{0}^{\sqrt{n}} \left(x^2 - \lfloor x^2 \rfloor - \frac{1}{2} \right) \cos x \, dx $ converges. Consequently,

$$ f(n) = -2\sqrt{n}\cos\sqrt{n} + \frac{5}{2}\sin\sqrt{n} + c + o(1) $$

Indeed, the following figure is the plot of the difference $f(n) - \left( -2\sqrt{n}\cos\sqrt{n} + \frac{5}{2}\sin\sqrt{n} \right)$ for $n \leq 10^4$.

Graph of the differnce


The Euler-Maclaurin Sum Formula gives $$ \sum_{k=1}^n\sin\left(\sqrt{k}\right) =\frac52\sin\left(\sqrt{n}\right)-2\sqrt{n}\overbrace{\left(1-\frac1{48n}\right)}^{\substack{\text{reduces the error}\\\text{from $O\left(n^{-1/2}\right)$}\\\text{to $O\left(n^{-3/2}\right)$}}}\cos\left(\sqrt{n}\right)+C+O\!\left(\frac1{n^{3/2}}\right) $$ where $C=-0.203568606528057118$.


Examples $$ \begin{array}{r|r|r} n&\text{actual sum}&\text{approximation}\\\hline 10&6.0547478264&6.0547515529\\ 100&15.2143129534&15.2143130664\\ 1000&-61.5861622838&-61.5861622890\\ 10000&-173.9328978672&-173.9328978673\\ 100000&303.9334372399&303.9334372399 \end{array} $$


Comparison to the Guess in the Question

The formula in the question is equivalent to $$ \begin{align} &-2\sqrt{n}\cos\left(\sqrt{n+\pi^2/4}\right)\\ &=-2\sqrt{n}\cos\left(\sqrt{n}+\frac{\pi^2}{8\sqrt{n}}\right)+O\!\left(\frac1n\right)\\ &=-2\sqrt{n}\cos\left(\sqrt{n}\right)\cos\left(\frac{\pi^2}{8\sqrt{n}}\right)+2\sqrt{n}\sin\left(\sqrt{n}\right)\sin\left(\frac{\pi^2}{8\sqrt{n}}\right)+O\!\left(\frac1n\right)\\ &=-2\sqrt{n}\cos\left(\sqrt{n}\right)+\frac{\pi^2}4\sin\left(\sqrt{n}\right)+O\!\left(\frac1{\sqrt{n}}\right) \end{align} $$ $\frac{\pi^2}4\approx\frac52$, so the coefficient of $\sin\left(\sqrt{n}\right)$ is close, and this difference adds no more than an amplitude $\frac1{30}$ oscillation to $C$.

Here is a plot of $\sum\limits_{k=1}^n\sin\left(\sqrt{k}\right)-C+2\sqrt{n}\cos\left(\sqrt{n+\pi^2/4}\right)$ vs $\pm\left(\frac52-\frac{\pi^2}4\right)$ : enter image description here


Comment on Sangchul Lee's Answer

Using $\{x\}=x-\lfloor x\rfloor$, $$ \begin{align} \int_1^{\sqrt{n}}\left(\left\{x^2\right\}-\tfrac12\right)\cos(x)\,\mathrm{d}x &=\int_1^n\left(\left\{x\right\}-\tfrac12\right)\cos\left(\sqrt{x}\right)\frac{\mathrm{d}x}{2\sqrt{x}}\\ &=\int_1^n\frac{\cos\left(\sqrt{x}\right)}{2\sqrt{x}}\,\mathrm{d}\frac{\{x\}^2-\{x\}+\frac16}2\\[12pt] &=\frac{\cos(n)}{24\sqrt{n}}-\frac{\cos(1)}{24}\\ &-\frac1{24}\int_1^n\left(\{x\}^2-\{x\}+\frac16\right)\frac{\cos\left(\sqrt{x}\right)+\sqrt{x}\sin\left(\sqrt{x}\right)}{2x^{3/2}}\,\mathrm{d}x\\[12pt] &=\frac{\cos(n)}{24\sqrt{n}}-\frac{\cos(1)}{24}\\ &-\frac1{24}\int_1^n\left(\{x\}^2-\{x\}+\frac16\right)\frac{\cos\left(\sqrt{x}\right)}{2x^{3/2}}\,\mathrm{d}x\\ &-\frac1{24}\int_1^n\frac{\sin\left(\sqrt{x}\right)}{2x}\,\mathrm{d}\frac{2\{x\}^3-3\{x\}^2+\{x\}}6\\[12pt] &=\frac{\cos(n)}{24\sqrt{n}}-\frac{\cos(1)}{24}\\ &-\frac1{24}\int_1^n\left(\{x\}^2-\{x\}+\frac16\right)\frac{\cos\left(\sqrt{x}\right)}{2x^{3/2}}\,\mathrm{d}x\\ &+\frac1{288}\int_1^n\left(2\{x\}^3-3\{x\}^2+\{x\}\right)\frac{\sqrt{x}\cos\left(\sqrt{x}\right)-2\sin\left(\sqrt{x}\right)}{2x^2}\,\mathrm{d}x\\[12pt] \end{align} $$ Therefore $$ \begin{align} &\int_0^\infty\left(\left\{x^2\right\}-\tfrac12\right)\cos(x)\,\mathrm{d}x\\ &=\int_0^1\left(x^2-\tfrac12\right)\cos(x)\,\mathrm{d}x-\frac{\cos(1)}{24}\\ &-\frac1{48}\int_1^\infty\left(\{x\}^2-\{x\}+\frac16\right)\frac{\cos\left(\sqrt{x}\right)}{x^{3/2}}\,\mathrm{d}x\\ &+\frac1{576}\int_1^\infty\left(2\{x\}^3-3\{x\}^2+\{x\}\right)\frac{\sqrt{x}\cos\left(\sqrt{x}\right)-2\sin\left(\sqrt{x}\right)}{x^2}\,\mathrm{d}x \end{align} $$ where all the integrals on the right are absolutely convergent.


The function $f(x)=\sin\sqrt x$, defined for $x>0$, has the primitive: $$ F(x)=-2\sqrt x\, \cos \sqrt x+2\sin\sqrt x\ . $$ Fix now some "big" integer $n$, for instance $n>14$. Then we can write, Lagrange intermediate value theorem, or Taylor polynomial approximation using an intermediate value: $$ \begin{aligned} F(n+1) - F(n) &= \frac 1{1!}F'(n) + \frac 1{2!}F''(n) + \frac 1{3!}F'''(n+c_n) \\ &= \frac 1{1!}f(n) + \frac 1{2!}f'(n) + \frac 1{3!}f''(n+c_n) \\[2mm] &\qquad\text{so} \\[2mm] F(x+1) - F(n_0) &= \sum_{n_0\le n\le x}f(n) \ +\ \frac 12 \sum_{n_0\le n\le x} f'(n) \ +\ \frac 16 \sum_{n_0\le n\le x} \underbrace{f''(n)}_{ \text{white noise}(n)}\ . \end{aligned} $$ Above, $c_n$ is an intermediate term between $0$ and $1$.

  • Now the above $\displaystyle\sum_{n_0\le n\le x} f(n) = \sum_{n_0\le n\le x} \sin\sqrt n $ is related to the sum in the OP. We only have to find a suitable $n_0$ with a low error. Doable. We may search for special bigger $x$ values, so that the sum over $\sin\sqrt n$ for $n$ from $1$ to $x$ is small. For instance, for $x=118$ the sum is $\approx 0.194481943838007\dots$ and for $x=1086$ the sum is $\approx 0.172694673659704\dots$ (And we compute all the related other quantities numerically.) Take $n_0=1086$ or so.

  • Then the difference from $F(x+1)$ to the given $g(x)$-asymptotic is also controlled by some $O(x^0)=O(1)$ because $$ \begin{aligned} \sin\left(-\left(\frac \pi2-\sqrt{x+\frac{\pi^2}4}\right)\right) &= -\cos\sqrt{x+\frac{\pi^2}4}\ , \\ &\qquad\text{ and } \\ \left| \cos\sqrt{x+\frac{\pi^2}4} -\cos\sqrt{x+1}\right| &\le \|\cos'\|\cdot \left| \sqrt{x+\frac{\pi^2}4} - \sqrt{x+1}\right| \\ &=\text{Constant}\cdot\frac1 {\sqrt{x+\frac{\pi^2}4} + \sqrt{x+1}} \\ &\in O(x^{-1/2}) \ . \end{aligned} $$

  • The sum of the "white noise" terms is controllable, $$ f''(x) = -\frac{\sin\left(\sqrt{x}\right)}{4 \, x} - \frac{\cos\left(\sqrt{x}\right)}{4 \, x^{\frac{3}{2}}}\ . $$ The second term has a sum of the shape $O(x^{-1/2})$, the first one would introduce a logarithmic term. Yes, we do not want it, but to be better, one has maybe to differentiate once more, i.e. use the Taylor expansion with Lagrange remainder with one more term, and do what we do with the part in $f'(n)$ (as in $(*)$ below) also with that $f''(n)$. It is too hard to type, else i would do it here. (I did not check the details.)

  • The last piece to be controlled with a constant is now: $$ (*) \qquad \sum_{n_0\le n\le x} f'(n) = \sum_{n_0\le n\le x} \frac 1{2\sqrt n}\cos\sqrt n \ . $$ We use the same idea as above, when trying to control the $\sum f(n)$ with the primitive $F$. Here we have with the same idea $$ f(n+1)-f(n) = \frac 1{1!}f'(n)+\frac 1{2!}f''(n+d_n)\ , $$ with an intermediate $d_n\in(0,1)$, then pass to the sum and use $f(x)\in O(1)$.


I have to submit, back to work. Errors may be present in detail. At any rate, this is the idea i would follow to get the asymptotical behavior of the sum, Taylor expansions of a needed degree.