# Vector Calculus Identities

Suppose

$g({\bf x}) = {\bf p}({\bf x})^T {\bf q}({\bf x})$.

That is, $g$ is a scalar function of a vector ${\bf x}$, given by taking the inner product of the two vector valued functions ${\bf p}$ and ${\bf q}$. Now, we would like the gradient of $g$, i.e. $\frac{\partial g}{\partial \bf x}$. What is it?

I frequently need to find such derivatives, and I have never been able to find any reference for rules to calculate them. (Though such rules surely exist somewhere!) Today, Alap and I derived a couple simple rules. The first answers the above question.

Rule 1.

If $g({\bf x}) = {\bf p}({\bf x})^T {\bf q}({\bf x})$, then,

$\frac{\partial g}{\partial \bf x} = J[{\bf p}]^T {\bf q}({\bf x}) + J[{\bf q}]^T{\bf p}({\bf x})$.

Here, $J[{\bf p}]=\frac{\partial {\bf p}}{\partial {\bf x}^T}$ is the Jacobian. i.e. $J_{i,j} = \frac{\partial p_i }{\partial x_j}$

This rule is a generalization of the calculus 101 product rule, where $g(x)=p(x) q(x)$ (everything scalar), and $g'(x) = p'(x) q(x) + q'(x) p(x)$.

A different rule concerning exponentials is

Rule 2.

If ${\bf f}({\bf x}) = \exp({\bf q}({\bf x}))$, then

$J[{\bf f}]= \frac{\partial {\bf f}}{\partial {\bf x}^T} = \exp( {\bf q}({\bf x})) {\bf 1}^T \odot J[{\bf q}]$.

Here, $\odot$ is the element-wise product. The strange product with ${\bf 1}^T$ can be understood as “copying” the first vector. That is, ${\bf x} {\bf 1}^T$ is a matrix where each column consists of $\bf x$. (The number of columns must be understood from context.)

Rule 3.

If ${\bf f}({\bf x}) = {\bf p}({\bf x}) \odot {\bf q}({\bf x})$, then

$J[{\bf f}] ={\bf p}({\bf x}){\bf 1}^T \odot J[{\bf q}] + J[{\bf p}] \odot {\bf q}({\bf x}){\bf 1}^T$

Surely there exists a large set of rules like this somewhere, but I have not been able to find them, despite needing things like this for years now. What I would really like to do is use a computer algebra system, such as Maple, Mathematica or Sage to do this, but that doesn’t seem possible at present. (It is suggested in that thread that Mathematica is up to the job, but I have tested it out found that not to be true.)