Derivative of $f(x,y)$ with respect to another function of two variables $k(x,y)$

Suppose that we have a function $f(x,y)$ of two variables:

$$f(x,y) = g(x) + h(y) + 5(x-y) = x^2 + y^2 + 5(x-y)$$

where $g(x) = x^2$ and $h(y) = y^2$ are also functions of $x$ and $y$, respectively.

How do I take the partial derivative of $f(x,y)$ with respect to another multivariate function $k(x,y) = x-y$, so that:

$$\frac{{\partial f(x,y)}}{{\partial k(x,y)}} = 5$$

I suppose that this would be a type of directional derivative, or perhaps even a functional derivative. Would the chain rule be applied in this type of situation?

Can this type of calculation be done in a numerical fashion (i.e. using finite difference derivatives) for $f(x,y)$ as a discrete calculated matrix of values, knowing only $f(x,y)$ at each point of the matrix and variables $x$, $y$?


Let $u = x+y$ and $v = x-y$. Let $f'(u,v) = f(x,y)$. See that $x^2 + y^2 = \frac{1}{2}(u^2 + v^2)$ to get

$$f'(u,v) = \frac{1}{2} (u^2 + v^2) + 5v$$

Note that this makes the answer to your problem $\partial f'/\partial v = v + 5$, not just 5.

This is a specific case of a coordinate system transformation.

Edit: here's a general overview of the topic.

Let there be a scalar field $f:\mathbb R^2 \to \mathbb R$ and a vector $p \in \mathbb R^2$. Let $\varphi:\mathbb R^2 \to \mathbb R^2$ be a general coordinate system transformation map, such that $\varphi(p) = p'$. For example, such a transformation could be

$$\varphi(p) = \varphi(x e_1 + y e_2) = u e_1 + ve_2$$

With $x,y$ and $u,v$ as previously described. The logic presented here, however, is entirely general. This could be a transformation from cartesian to polar coordinates or something else. It also need not be in $\mathbb R^2$, but could be in $\mathbb R^n$ instead.

Let there be a cooresponding scalar field $f'$ such that $f'(p') = f(p) = (f' \circ \varphi)(p)$. We can then take derivatives in the usual way. Let $a$ be a vector.

$$a \cdot \nabla f|_p = a \cdot \nabla (f' \circ \varphi) |_p= [a \cdot \nabla \varphi] |_p \cdot \nabla' f' |_{p'}$$

This is a result from the chain rule. $\nabla'$ is given by $e^1 \partial_u + e^2 \partial_v$, and $\nabla = e^1 \partial_x + e^2 \partial_y$. The quantity $a \cdot \nabla \varphi|_p$ is the Jacobian operator at the point $p$. It is sometimes denoted $J_\varphi(a)|_p$ or $d\varphi_p(a)$, but I will call it $\underline \varphi_p(a)$, with transpose $\overline \varphi_p(a)$.

The relationship between derivatives can then be written as

$$a \cdot \nabla f|_p = \underline \varphi_p(a) \cdot \nabla' f'|_{\varphi(p)}$$

$\underline \varphi$ is invertible, and as such, we can write this equivalently as

$$\underline \varphi_p^{-1}(a) \cdot \nabla f|_p = a \cdot \nabla' f|_{p'}$$

This is the form useful for the problem at hand. Pick $a = e_2$ and $a \cdot \nabla' = \partial_v$. What's convenient here is that the left-hand side allows one to evaluate the answer without finding $f'(p')$ at all! Instead, just find the inverse transformation, $\varphi^{-1}(p') = p$. This is encoded in the relations

$$x = \frac{1}{2}(u+v), \quad y = \frac{1}{2} (u - v)$$

Now we can find the inverse Jacobian. In particular,

$$\underline \varphi^{-1}(e_2) = \frac{\partial p}{\partial v} = \frac{1}{2} (e_1 - e_2)$$

We find then that $\partial_v = \underline \varphi^{-1}(e_2) \cdot \nabla = \frac{1}{2}(\partial_x - \partial_y)$.

Knowing that $\partial f/\partial x = 2x+5$ and $\partial f/\partial y = 2y - 5$, the result is

$$\partial_v f' = \frac{1}{2} (\partial_x - \partial_y) f = x - y + 5$$

Using the inverse transformation, of course, gives $\partial f'/\partial v = v + 5$.

This approach is more rigorous, and also suitable when you want to avoid finding $f'$ explicitly (perhaps because it's very, very complicated). This $f'$ in this problem was not, however, so you could be considerably more direct, finding $f'$ explicitly in terms of $u,v$ and just taking the partial derivative as usual.


The above solution seems a bit like a sleight of hand, primarily because it assumes that $u$ and $v$ are independent but that need not be true. In other words, it's entirely possible that $u=x+y$ changes if $v=x-y$ changes. This implies that $\frac{d{u^2}}{dv} \ne 0$, as opposed to what's assumed in the solution. It could be the case that $\frac{d{u^2}}{dv} = 0$ depending the values of $x$ and $y$, but it's not generally true. Anyone see anything wrong with this argument?