# Speeding up Mathematica code involving nontrivial summations

I want to expand the following type of $q$-series
\begin{align} &\mathrm{ELi}_{n_1,...,n_l;m_1,...,m_l;2o_1,...,2o_{l-1}}\left(x_1,...,x_l;y_1,...,y_l;q\right) \\ &= \sum\limits_{j_1=1}^\infty ... \sum\limits_{j_l=1}^\infty \sum\limits_{k_1=1}^\infty ... \sum\limits_{k_l=1}^\infty \;\; \frac{x_1^{j_1}}{j_1^{n_1}} ... \frac{x_l^{j_l}}{j_l^{n_l}} \;\; \frac{y_1^{k_1}}{k_1^{m_1}} ... \frac{y_l^{k_l}}{k_l^{m_l}} \;\; \frac{q^{j_1 k_1 + ... + j_l k_l}}{\prod\limits_{i=1}^{l-1} \left(j_i k_i + ... + j_l k_l \right)^{o_i}} \end{align} to arbitrary but fixed orders in $q$. Whereby the variables $x_i,y_i \in \mathbb{C}$ are fixed numerical values, the variables $n_i,m_i,o_i\in \mathbb{Z}$ are fixed numbers and $q$ remains a symbol.
The function I have written so far is:

(* 2.1 General properties *)
ELiQ[a_] := MatchQ[a, ELi[__]] (* Test if function is ELi-Function *)
ELi2qSeries[z_, upper_] := Map[ELi2qSeries[#, upper] &, z, {2}] /; MatrixQ[z] (* Apply on Matrices *)
ELi2qSeries[a_*b_, upper_] := a ELi2qSeries[b, upper] /;ELiQ[a] == False (* factor out non ELi(B)'s *)
ELi2qSeries[a_ + b_, upper_] := ELi2qSeries[a, upper] + ELi2qSeries[b, upper]; (* Linearity *)
ELi2qSeries[a_, upper_] := a /; ELiQ[a] == False (*ELi2qSeries applied on non-ELi's *)
(* 2.2 actual series-Expansion with upper denoting the order of the expansion *)
ELi2qSeries[ELi[nlist_, mlist_, xlist_, ylist_, var_, olist_], upper_] := Module[{j, k, term, newterm},
(* term <- definition of eli-Function *)
term = Product[
xlist[[i]]^j[i]/j[i]^nlist[[i]] ylist[[i]]^k[i]/
k[i]^mlist[[i]], {i, Length[nlist]}]*(var)^
Sum[j[h]*k[h], {h, Length[nlist]}]*1/
Product[(Sum[j[i] k[i], {i, h, Length[nlist]}])^(olist[[h]]/
2), {h, 1, Length[olist]}];
(* expand by summation over all j[i],k[i] *)
Do[newterm = Sum[Sum[term, {j[l], 1, upper+1-Length[nlist]}], {k[l], 1, upper+1-Lengt[nlist]}];
term = newterm, {l, 1, Length[nlist]}];
(* omit incorrect higher order terms *)
Series[newterm, {var, 0, upper}]]


My main problem is, that the above defined expansion works incredible slow for a sufficiently high chosen order of expansion (upper>20) by a typical length of nlist~3. Since I have to apply it several times during my calculations, it's an major issue.
Therefore any suggestions on how to speed up the whole expansion procedure are much appreciated!
Thanks, Armin

Remark: Code-Example

In[8]:=
(* Example: Our calculations yield expressions like: *)
GTest=3(ELi[{1},{0},{-1},{1},q,{}]-ELi[{1},{0},{r6},{1},q,{}]);
r6=Exp[2 Pi I/6];

(* for numerical evaluations around small q, I need an expansion, wich is currently done by: *)
ELi2qSeries[ExpandAll[GTest],4]
(* Output:  (-3-3 E^((I \[Pi])/3)) q+(-(3/2)-3/2 (2 (-1)^(1/3)+(-1)^(2/3))) q^2+(-4-3 (-(1/3)+E^((I \[Pi])/3))) q^3+(-(3/4)-3/4 (3 (-1)^(1/3)+2 (-1)^(2/3))) q^4+O[q]^5 *)


This expansion (in much higher order) is suitable for numeric evaluation and for comparison with related Taylor series. The interest for these kind of functions is due to this paper.

• Can you give some examples of how your code is used? Aug 26 '16 at 13:28
• @QuantumDot I edited the original post and included an minimal example. Is there anything else I can do to clarify things? Aug 26 '16 at 14:31

Some elaborate trickery can be done to implement your multiple sum:

ELi[n_?VectorQ, m_?VectorQ, o_?VectorQ, x_?VectorQ, y_?VectorQ, q_,
r : (_Integer?Positive | Infinity) : Infinity] /;
Length[n] == Length[m] == Length[o] + 1 == Length[x] == Length[y] :=
Block[{l = Length[n], i, j, k},
Inactive[Sum][Apply[Times, x^Array[j, l]/Array[j, l]^n]
Apply[Times, y^Array[k, l]/Array[k, l]^m]
q^(Array[j, l].Array[k, l])/
Apply[Times, Table[Array[j, l - i + 1, i].Array[k, l - i + 1, i],
{i, l - 1}]^(o/2)],
Evaluate[Sequence @@ Join[Table[{j[i], 1, r}, {i, l}],
Table[{k[i], 1, r}, {i, l}]]]]]


(I used Inactive[] so that the sum can be quickly displayed and checked for correctness; for actual computation, replace Inactive[Sum] with Sum.)

An optional parameter r can be specified so that you can either see the actual infinite sum or just a partial sum.

An example:

ELi[{1, 3, 5}, {2, 4, 6}, {14, 16}, Array[x, 3], Array[y, 3], q]


• Thanks a lot. I learned some useful things by understanding your code! Oct 4 '16 at 19:48