Why can I assume the force to be constant in this particular interval? If I have force, or any function $f(z)$, I was told that I can assume it to be constant only in the interval $dz$.
However, in this case, I had to calculate the work done by the spring force as a function of $y$

Over here, I assumed the spring force, which is a function of its elongation $x$ ($F = -kx$) to be constant in the interval $dy$ and integrated and this gave me the correct answer
I want to know why the error vanished over here. Shouldn't spring force only be constant in the interval $dx$ and not $dy$?
I also want to know, in general, if I have a function, how to decide whether it is constant in some particular interval/in which cases the error will vanish as I take the limit and integrate.
Note:  I do know I can assume a function $f(x)$ to be constant in the interval $[x,x+dx)$ while integrating, but over here I've assumed it to be constant in the interval $dy$. I want to know why I can do that and also if I can assume a force/function to be constant in any infinitesimal interval such as $Rdθ$, $dy\over cosϕ$,$dz$ etc. 
 A: It is, in general, by definition. $dx$ and $dy$ are defined in such a way that the force can be assumed to be constant in such an interval.
That's the general case, the way we use infinitesimals in physical problems mostly. Exceptions to this may occur.
A: You did a coordinate transformation from $x$ to $\theta$ to $y$. You are doing a normal integration. In such, you can assume the function to be constant for the interval $\mathrm dX$ for any $X$, as long as the function $f(X)$ is smoothly differentiable. That means that $f'(X)$ does not have any jumps. One eample of function that do not work would be $f(x) = |x|$ at value $x = 0$.
A function which can be differentiated smoothly infinitely often can be expanded into a Taylor series. This might be a circular definition when looking at analytic functions, but that shall not bother us here. We can find the approximation
$$ f(x - a) = f(a) + f'(a) [x - a] + \frac 12 f''(a) [x-a]^2 + \ldots \,.$$
When we look at the interval $[x, x + \mathrm dx)$, we look at an infinitely small interval. We can call this size $\epsilon$. When you integrate, you sum up slices of the function of size $\epsilon$. Since we do the limit $\epsilon \to 0$, we say that only terms of $\epsilon^1$ are interesting, terms with $\epsilon^2$ or higher powers will tend to zero faster than anything else of interest.
If we integrate in the interval $[x, x + \mathrm dx)$, we can take the value of the function at $x$ and use the Taylor expansion to get the value at $x + \mathrm dx$:
$$ f(x + \mathrm dx) = f(a) + f'(a) \, \mathrm dx + \frac 12 f''(a) [\mathrm dx]^2 + \ldots \,.$$
Then you do the Riemann sums and compute the area of the rectangles, you multiply again with $\mathrm dx$ and sum up those areas:
$$ \int \mathrm dx \, f(x) \simeq \sum_i \mathrm dx \left[ f(x_i) + f'(x_i) \, \mathrm dx + \frac 12 f''(x_i) [\mathrm dx]^2 + \ldots \right] \,.$$
But now we have this additional power of the small number $\mathrm dx$ in there. And $[\mathrm dx]^2$ is already “too small to count”. Therefore the only interesting term within the interval $[x, \mathrm dx)$ is the leading term. So we only need to keep the $f(x_i)$ term in the sum and not the derivatives. That means that the function can be assumed constant in the infinitesimal interval.
