Consider, I have a function $\phi: R^N \to R$, denote its i'th argument with $x_i$. Consider also a vector in $R^N$: $W$. Denote a multiindex $\alpha = (\alpha_1, \dots, \alpha_n)$ (for each $\alpha_n$ integer). Then denote

$$ W^\alpha = W_1^{\alpha_1} \cdot W_2^{\alpha_2} \cdots W_n ^{\alpha_n}, $$

$$ \alpha ! = \alpha_1 ! \cdot \alpha_2 ! \cdots \alpha_N ! , $$

$$ \lvert \alpha \rvert = \alpha_1 + \alpha_2 + \cdots + \alpha _N $$

and (assuming everyhing exists and is well-behaved)

$$ D^{ \alpha} = \frac{\partial^{\alpha_1} }{\partial x_1^{\alpha_1}} \cdot \frac{\partial^{\alpha_2} }{\partial x_2^{\alpha_2}} \cdots \frac{\partial^{\alpha_n} }{\partial x_n^{\alpha_n}} \, \phi $$

(i.e. differentiate $\alpha_n$ times with respect to $x_n$ then $\alpha_{n-1}$ times wrt. $x_{n-1}$ etc).

Then I seek to calculate (symbolically!)

$$ \sum_{\lvert \alpha \rvert =k} D^{\alpha} \phi \cdot W^{\alpha} \, \frac{k!}{\alpha !} $$

Can anyone help? I am aware of this question: Other Question but honestly I'm having a hard time deciphering the answers. Mathematica isn't my best language, but it seems like it would be very convenient at this particular problem (especially since the symbolic math is so strong).

Oh, and readability is more important to me than speed (to me, in this particular situation).

  • $\begingroup$ @MMM Thanks for the help! (Maybe you can kill the note? - I'm still not allowed to it appears). $\endgroup$
    – htd
    Mar 2, 2017 at 13:43
  • $\begingroup$ Are you seeking a completely general result independent of phi, or do you have a function phi in mind? Do you have a way of generating the alpha indices? Are you sure that this is even a Mathematica question, and not still a math question? We can help with implementation, but this seems to require more than that. $\endgroup$
    – MarcoB
    Mar 2, 2017 at 15:14
  • $\begingroup$ @MarcoB Thank you for your interest! I was hoping a general function. Generating the alpha indices is adressed very nicely in the question I is referring to, I just don't understand the implementation. So what I am basically asking is how to get "Derivative" and "Power" to work in the proper way and insert into the place of "b" in that question. $\endgroup$
    – htd
    Mar 2, 2017 at 15:33
  • $\begingroup$ I see you've used $n$ and $N$ interchangeably. You have also not set restrictions for the values of $\alpha_i$. Are they >=0 or >0? If the former, the set of $|\alpha| = k$ is quickly rather huge. $\endgroup$
    – LLlAMnYP
    Mar 8, 2017 at 14:39
  • $\begingroup$ By the way, I'm quite convinced, that your desired expression is quite simply the sum of all k-th order terms of the Taylor expansion of $\phi$ in the vicinity of $\vec{0}$ at $W$ $\endgroup$
    – LLlAMnYP
    Mar 8, 2017 at 14:45

1 Answer 1


As I commented, these are the k'th-order terms of the multivariable Taylor expansion. After some redefinitions of Derivative I came up with a solution:

kOrderTerms[f_[args__], k_] :=                                   (* 1 *)
 Block[{d, expr}, d[x___][d[y___][g_]] := (d @@ ({x} + {y}))[g]; (* 2 *)
    Block[{Derivative = d},                                      (* 3 *)
     expr = Series @@ ({f[args]}~Join~Thread[{{args}, 0, k}]);   (* 4 *)
     d[x___ /; Plus[x] != k][g_] = 0 &;                          (* 5 *)
     expr = expr];                                               (* 6 *)
    d = Derivative;                                              (* 7 *)
    expr = expr] // Normal // Expand                             (* 8 *)
  1. Usage: $\mathrm{kOrderTerms}[\phi[W_1, W_2, ..., W_n], k]$
  2. Get a variable d to emulate the behavior of chained derivative, e.g. d[0, 1, 2][d[3, 0, 1][f]] -> d[3, 1, 3][f], just like Derivative would behave in place of d.
  3. Tell Mathematica to use d in place of Derivative.
  4. Calculate the series expansion of the given function up to the desired order k in each variable. At this step the chained derivatives properly fold.
  5. Introduce a new rule: if the total order of our "derivative" is not equal to k, that summand will be zero.
  6. Update the expression, given the new rule.
  7. Forget about all the rules for d, instead just switch it back to the proper Derivative.
  8. Update the expression once more, remove all big-O terms, expand into a sum.

enter image description here

Note that Series caches its results. While coding, I, e.g., ran into a bug that kOrderTerms[f[x, y, z], 3] retained f[0,0,0] in the returned expression. This was fixed by ClearSystemCache[].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.