I am calculating a second order mixed derivative by the following formula $$\frac{\partial^2 f(x, y)}{\partial x \partial y} \approx \frac{f(x + h, y + h) - f(x - h, y + h) - f(x + h, y - h) + f(x - h, y - h)}{4h^2}$$
I wonder what is the correct way (with respect to error propagation) of performing the division. Should I divide the numerator by $h$ twice or should I compute $h^2$ first and then divide? Why?
My assignment is to check the magnitudes of possible errors related to the computation of this derivative. I have theoretically shown that when $h$ is small, there is a huge roundoff error and when $h$ is large, there is a huge approximation error. Now I have to implement this procedure and I feel that choosing the sequence of actions will make the procedure either more susceptible to roundoff or to approximation error.
If you calculate, say, $\frac{a}{h}$ or $h^2$, the computer will be off by at most $\epsilon_0 \frac{a}{h}$ or $\epsilon h^2$, respectively, where $\epsilon_0$ is a constant called the machine epsilon. That means if you square it first, the computer will give you $$h^2(1+\epsilon_1),\quad -\epsilon_0\leq \epsilon_1\leq \epsilon_0$$ Then, when you divide, you'll get $$\frac{a}{h^2(1+\epsilon_2)}(1+\epsilon_1),\quad -\epsilon_0\leq\epsilon_2\leq\epsilon_0$$ Your answer will be off by $\frac{1+\epsilon_1}{1+\epsilon_2}$. If you do it the other way around, you'll get that the new error is $(1+\epsilon_1)(1+\epsilon_2)$. So when $\epsilon_2>0$, squaring first is better; when it's negative, dividing first is better, and when it's positive, multiplying is better. But since you can't tell (as far as I know), the two ways are equal. So you might actually want to consider doing both ways.