Is there a fast method to get the coefficients of a Taylor series expansion of the function $f(x_1,x_2,...,x_d)$ with maximal summed partial derivative up to $n$, where $d,n$ can be relatively large (for example, $d=10,n=10$)?
For example, in mathematica, the series expansion
n = 1; Series[f[x, y], {x, 0, n}, {y, 0, n}]
$\left(f(0,0)+y f^{(0,1)}(0,0)+O\left(y^2\right)\right)+x \left(f^{(1,0)}(0,0)+f^{(1,1)}(0,0) y+O\left(y^2\right)\right)+O\left(x^2\right)$
I need the coefficient list $(1, x, y)$ for function list: ($f(0,0), f^{(1,0)}(0,0), f^{(0,1)}(0,0)$)
The conventional Series function is very slow, for example,
In[655]:=n = 1; Series[f[x1, x2, x3, x4, x5, x6, x7], {x1, 0, n}, {x2, 0, n}, {x3, 0, n}, {x4, 0, n}, {x5, 0, n}, {x6, 0, n}, {x7, 0, n}]; // AbsoluteTiming
Out[655]= {0.000259252, Null}
In[656]:= n = 2; Series[f[x1, x2, x3, x4, x5, x6, x7], {x1, 0, n}, {x2, 0, n}, {x3, 0, n}, {x4, 0, n}, {x5, 0, n}, {x6, 0, n}, {x7, 0, n}]; // AbsoluteTiming
Out[656]= {0.442849, Null}
In[657]:= n = 3; Series[f[x1, x2, x3, x4, x5, x6, x7], {x1, 0, n}, {x2, 0, n}, {x3, 0, n}, {x4, 0, n}, {x5, 0, n}, {x6, 0, n}, {x7, 0, n}]; // AbsoluteTiming
Out[657]= {2.95541, Null}
In[665]:= n = 5; Series[f[x1, x2, x3, x4, x5, x6, x7], {x1, 0, n}, {x2, 0, n}, {x3, 0, n}, {x4, 0, n}, {x5, 0, n}, {x6, 0, n}, {x7, 0, n}]; // AbsoluteTiming
Out[665]= {42.6434, Null}
The series function seems to be inadequate for obtaining the coefficient list and derivative list of function with large $(n,d)$.
I have found a solution in https://arxiv.org/abs/1905.02809
Mathematica code for Taylor series in several variables
Based on the multi-index, the Taylor series expansion of a multi-variable scalar function $ u(x_{1},...,x_{d})$ at $\mathbf {a} =(0,...,0)$ can be written as
$ u(x_{1},...,x_{d})=\sum _{(n_{1},...,n_{d})\in \alpha _{d}^{n}}{\frac {x_{1}^{n_{1}}...x_{d}^{n_{d}}}{n_{1}!...n_{d}!}}u_{,n_{1}...n_{d}}+O(r^{n+1})$ ,
with $ r={\sqrt {x_{1}^{2}+...+x_{d}^{2}}}$ , $ u_{,n_{1}...n_{d}}={\frac {\partial ^{n_{1}+...+n_{d}}u}{\partial x_{1}^{n_{1}}...\partial x_{d}^{n_{d}}}}|_{x_{1}=0,...,x_{d}=0}$ and $ \alpha _{d}^{n}$ is the set of multi-indexes in $d$ dimensions with maximal single index up to $n$ , i.e. $ \mathbf {\alpha } _{d}^{n}=\{(n_{1},...,n_{d})|0\leq \sum _{i=1}^{d}n_{i}\leq n,\,n_{i}\in \mathbb {N} ^{0},1\leq i\leq d\},$
which can be obtained by an efficient Mathematica code as
MultiIndexList[d_,n_]:=Block[{a,b,c},a=Subsets[Range[d+n],{d}];
Do[ c=a[[i]];b=c-1;b[[2;;]]-=c[[1;;-2]];a[[i]]=b,{i,Length[a]}];a];
(*note: d=number of spatial dimensions, n=maximal order of derivative*)
(*
(*Some Performance test*)
MultiIndexList[5, 20] // Length // AbsoluteTiming
MultiIndexList[5, 40] // Length // AbsoluteTiming
MultiIndexList[10, 10] // Length // AbsoluteTiming
MultiIndexList[200, 3] // Length // AbsoluteTiming
MultiIndexList[200, 1] // Length // AbsoluteTiming
(*
{0.5810 seconds,53130 terms}
{9.777 seconds,1221759 terms}
{1.583 seconds,184756 terms}
{89.013 seconds,1373701 terms}
{0.01451 seconds,201 terms}
*)
*)
For each multi-index $ (n_{1},...,n_{d})\in \alpha _{d}^{n}$ , the polynomial and partial derivative are
$ {\frac {x_{1}^{n_{1}}...x_{d}^{n_{d}}}{n_{1}!...n_{d}!}},\,\,u_{,n_{1}...n_{d}},\quad \forall (n_{1},...,n_{d})\in \alpha _{d}^{n}$
When the multi-index is written explicitly, the Taylor series expansion of the multi-variable function is straightforward.
term /. Derivative[nn__][f][xx__] :> Multinomial[nn] Apply[Times, {xx}^{nn}]
? $\endgroup$nn
: i.stack.imgur.com/puvUO.png $\endgroup$With[{n = 5}, Normal[Series[Apply[f, {x1, x2, x3, x4, x5, x6, x7} t], {t, 0, n}]] /. t -> 1]
$\endgroup$MultiIndexList[d_, n_] := Flatten[Table[Permutations[ip] - 1, {k, n}, {ip, IntegerPartitions[k + d, {d}]}], 2]
$\endgroup$