# Computing the derivative $D^kf(z)$ in Mathematica

Suppose we have a polynomial function $f:\mathbb{C}^n\to\mathbb{C}$, it can be written as $f(X_1,\ldots\,X_N) = \sum_{j=1}^m c_j X_1^{a_{j_1}}\cdot\ldots\cdot X_n^{a_{j_n}}$. We may want to compute the $k$-th derivative of $f$ in some point $z\in\mathbb{C}^n$, which is a $k$-linear function $D^kf(z):\underbrace{\mathbb{C}^n\times\mathbb{C}^n}_{k \text{ times}}\to\mathbb{C}$.

To be more precise, this function is given by $$D^kf(z)(v_1,\ldots,v_k) = \sum_{i_1,\ldots,i_k=1}^n v_{1,i_1}\cdot\ldots\cdot v_{k,i_k} \frac{\partial^k f(z)}{\partial X_{i_1}\ldots\partial X_{i_k}},$$ where $v_j = (v_{j,1},v_{j,2},\ldots,v_{j,n})$ for $j=1\ldots k$.

Note that we can write $$D^kf(z) = \sum_{i_1,\ldots,i_k=1}^n dx_{i_1}\otimes\ldots\otimes dx_{i_k}\frac{\partial^k f(z)}{\partial X_{i_1}\ldots\partial X_{i_k}},$$ so I suspect Mathematica have a built in function for this, because it works with tensors (although the documentation wasn't very helpful for me in this case).

I have two questions:

1) How can I make Mathematica to compute $D^kf(z)(v_1,\ldots,v_k)$ when I give only the function $f$, the point $z\in\mathbb{C}^n$ and the vectors $v_1,\ldots v_k\in\mathbb{C}^n$ as input?

2) If my first question has a positive answer, I want to make Mathematica to compute $$\|D^kf(z)\| = \max_{v1,\ldots,v_k\in\mathbb{C}^n, \|v_j\|=1} |D^kf(z)|.$$

How can I do this?

Thank you very much for your help.

PS: the fact that $f$ is a polynomial is not so important, what is really important is that $f$ is differentiable $k$ times. Also, the mentioned norms $\|v_j\|$ are the usual norms $\|v_j\|=\sqrt{|v_{j,1}|^2+\ldots+|v_{j,n}|^2}$ (note that each $v_{j,l}$ is a complex number, so it is necessary to compute the absolute value).

• Could you give a simple example of a Mathematica expression you would like to differentiate and the result you would expect? Oct 8 '16 at 6:12
• @mikado For example, consider the function $f(X_1,X_2,X_3) = X_1X_2X_3-2X_1X_2^2$ and the point $z=(1,1,1)$. In this case, for $u=(u_1,u_2,u_3)\in\mathbb{C}^3$, we have $Df(z)u = -u_1-3u_2+u_3$. Similarly, we have $D^2f(z)(u,v) = -4u_2v_2+u_2v_3+u_3v_2-3u_1v_2+u_1v_3-3u_2v_1+u_3v_1$ and $D^3f(u,v,w) = -4u_1v_2w_2+u_1v_2w_3+u_1v_3w_2-4u_2v_1w_2+u_2v_1w_3-4u_2v_2w_1+u_2v_3w_1+u_3v_1w_2+u_3v_2w_1$. Oct 10 '16 at 2:39

Based on your examples, here's a possibility:

dop[f_, {vars_, val_}, vs_?MatrixQ] /;
Length[val] == Length[vars] == Last[Dimensions[vs]] :=
With[{k = Length[vs]}, Fold[Dot, D[f, {vars, k}] /. Thread[vars -> val], vs]]


Examples:

dop[x y z - 2 x y^2, {{x, y, z}, {1, 1, 1}}, {Array[u, 3], Array[v, 3], Array[w, 3]}]
((-4 u[2] + u[3]) v[2] + u[2] v[3]) w[1] +
((-4 u[2] + u[3]) v[1] - 4 u[1] v[2] + u[1] v[3]) w[2] +
(u[2] v[1] + u[1] v[2]) w[3]

dop[SymmetricPolynomial[3, {x, y, z, w}], {{x, y, z, w}, {0, 1, -1, 0}},
{Array[p, 4], Array[q, 4]}]
(-p[2] + p[3]) q[1] + (-p[1] - p[4]) q[2] + (p[1] + p[4]) q[3] + (-p[2] + p[3]) q[4]


Maximizing across multiple complex vectors looks a bit harder to do; I'll leave that for somebody else.

• Thank you for answering, J.M. About the maximizing question, I'm trying to write /.u[1]->ru1 + I*iu1 (and do the same for every variable) and then use the function Maximize with constrains $ru_1^2+iu_1^2+ru_2^2+iu_2^2+ru_3^2+iu_3^2 == 1$ and $rv_1^2+iv_1^2+rv_2^2+iv_2^2+rv_3^2+iv_3^2 == 1$ (note that that the $i$ in $iu_1$ is not the imaginary number, but only a letter standing for imaginary part, just as $ru_1$ is for real part). Do you think this is a good approach? To be honest, it's not working... Oct 10 '16 at 22:27
• Ok. I could make it work with Maximize and MaxValue. It works fine but there is only a problem: if $f$ has a high degree, let's say a degree $k$, I'll need to use $k$ vectors. It's easy for two or three vectors, just name them as $u,v,w$ like you did. I still need a more generic solution, for $k$ vectors $v_1,\ldots, v_k \in\mathbb{C}^n$. After this, creating real and imaginary parts for each vector by hand (in order to compute the norm) is not acceptable. Your solution is great, but is it possible to generalize? Thanks. Oct 11 '16 at 0:01
• At least could you tell me where can I read about the dop and With functions? Can't find anywhere. Thanks! Oct 14 '16 at 14:15