Why do engineers use derivatives in discontinuous functions? Is it correct? I am a Software Engineering student and this year I learned about how CPUs work, it turns out that electronic engineers and I also see it a lot in my field, we do use derivatives with discontinuous functions. For instance in order to calculate the optimal amount of ripple adders so as to minimise the execution time of the addition process:
$$\text{ExecutionTime}(n, k) = \Delta(4k+\frac{2n}{k}-4)$$
$$\frac{d\,\text{ExecutionTime}(n, k)}{dk}=4\Delta-\frac{2n\Delta}{k^2}=0$$
$$k= \sqrt{\frac{n}{2}}$$
where $n$ is the number of bits in the numbers to add, $k$ is the amount of adders in ripple and $\Delta$ is the &quot;delta gate&quot; (the time that takes to a gate to operate).
Clearly you can see that the execution time function is not continuous at all because $k$ is a natural number and so is $n$.
This is driving me crazy because on the one hand I understand that I can analyse the function as a continuous one and get results in that way, and indeed I think that's what we do (&quot;I think&quot;, that's why I am asking), but my intuition and knowledge about mathematical analysis tells me that this is completely wrong, because the truth is that the function is not continuous and will never be and because of that, the derivative with respect to $k$ or $n$ does not exist because there is no rate of change.
If someone could explain me if my first guess is correct or not and why, I'd appreciate it a lot, thanks for reading and helping!
In general, computing the extrema of a continuous function and rounding them to integers does not yield the extrema of the restriction of that function to the integers. It is not hard to construct examples.
However, your particular function is convex on the domain $k&gt;0$. In this case the  extremum is at one or both of the two integers nearest to the unique extremum of the continuous function.
It would have been nice to explicitly state this fact when determining the minimum by this method, as it is really not obvious, but unfortunately such subtleties are often forgotten (or never known in the first place) in such applied fields. So I commend you for noticing the problem and asking!
If you consider that k and n are continuous variables, you obtain a continuous function that may be derivated and is entangled to the initial discontinuous function. The real problem is if the extreme point of this function can approximate the extreme point of the discontinuous one. The error may be evaluated with the Cauchy reminder formula for Newton or Lagrange interpolation which has a k! in the denominator and may be tolerable if k is enough big.