<s>[INST] What is $\lim_{x\to0} \frac{(\cos x + \cos 2x + \dots+ \cos nx - n)}{\sin x^2}$? What is the limit of $$\lim_{x\to0} \frac{\cos x + \cos 2x + \dots+ \cos nx - n}{\sin x^2}$$
 [/INST] We have
$$\sum_{k=1}^n \cos(kx) = \dfrac{\sin(nx/2) \cos((n+1)x/2)}{\sin(x/2)}$$
Hence, we have
$$\dfrac{\dfrac{\sin(nx/2) \cos((n+1)x/2)}{\sin(x/2)} - n}{\sin(x^2)} = \dfrac{\sin(nx/2) \cos((n+1)x/2) - n\sin(x/2)}{\sin(x^2)\sin(x/2)}$$
Expanding around $0$ gives us
$$\dfrac{\left(nx/2 - \dfrac{(nx/2)^3}{3!} + \mathcal{O}(x^5)\right) \left(1-\dfrac{(n+1)^2x^2/4}{2!} + \mathcal{O}(x^4)\right)-n\left(x/2 - \dfrac{(x/2)^3}{3!} + \mathcal{O}(x^5) \right)}{x^3/2 + \mathcal{O}(x^4)}$$
Now cancel off the terms and conclude the limit.
</s>