# Simplifications of trigonometric sums

I have to compute series expansions of ratio of theta-functions, and the program gets incredibly slow because it does not know how to simplify simple sums of complex exponentials.

So my input is

Normal[FullSimplify[Series[Series[Z[q, y], {q, 0, 3}], {y, 0, 3}]]]


where Z is a rational function in q and y with complex coefficients.

After a long, long time I get messages like

Series::ztest: Unable to decide whether numeric quantities {-1+ E^(-((I π)/3))- E^(-((2 I π)/3)),.......} are equal to zero. Assuming they are. >>

Is there a way to improve things? Currently it take hours to expand to third/fourth order.

thanks

PS : Here is a full example

First the basic functions

eta[q_] := q^(1/24) (1 - q) (1 - q^2) (1 - q^3) (1 - q^4)

theta[q_, y_] := -I q^(1/8) y^(1/2) (1 - q) (1 - q^2) (1 - q^3) (1 - q^4) (1 - q^5) (1 - q^6) (1 - y q) (1 - y q^2) (1 - y q^3) (1 - y q^4) (1 - y^-1) (1 - y^-1 q) (1 - y^-1 q^2) (1 - y^-1 q^3) (1 - y^-1 q^4)


Then the quantity of interest

Z[q_, y_] :=
(1/6)*Sum[((theta[q, y^(1/6 - 1)*q^(l/6)*E^((2*I*Pi*k)/6)]/
theta[q, y^(1/6)*q^(l/6)*E^((2*I*Pi*k)/6)])^3*
(theta[q, y^(1/2 - 1)*q^(l/2)*E^(I*Pi*k)]/
theta[q, y^(1/2)*q^(l/2)*E^(I*Pi*k)]))/
y^l, {k, 0, 3}, {l, 0, 3}]


$$\frac{1}{6} \sum _{k=0}^3 \sum _{l=0}^3 \frac{y^{-l} \left(\frac{\theta \left(q,y^{\frac{1}{6}-1} q^{l/6} e^{\frac{2 i \pi k}{6}}\right)}{\theta \left(q,\sqrt[6]{y} q^{l/6} e^{\frac{2 i \pi k}{6}}\right)}\right)^3 \theta \left(q,y^{\frac{1}{2}-1} q^{l/2} e^{i \pi k}\right)}{\theta \left(q,\sqrt{y} q^{l/2} e^{i \pi k}\right)}$$

and then

Normal[FullSimplify[Series[Series[Z[q, y], {q, 0, 3}], {y, 0, 3}]]]

• Please provide a sample Z. – bbgodfrey Nov 24 '16 at 21:34

First, I did not find any function eta[q]in your code. So, it may contain errors. Second, in your first line of the code you expand a function Z[q, y], while in the second you introduce a function Zell[q,y]. I will further assume that this is the same function, though you should be attentive to such things. We do not know, what do you mean.

Essential: the long time of operating a simplification may take place for several reasons. Among them may be:

First: the use of parameters with the unspecified properties (positive/negative, complex/reals and so on). Mma will divide the space of parameters into parts and solve for each part separately to account for all possibilities, such multiplying the calculation time several fold. So, specify, if possible.

Second, do not use FullSimplify without a direct necessity, that is, if you have no special functions involved. Use Simplifyinstead.

Third, I am not sure, but it seems better to first make the expression normal, and only then to simplify it.

After all this, and given your definitions of theta and Zell here is the way to try. I specify y>0, q>0 and k belonging to Reals. If it is not the case, specify otherwise. If there is no limitations for these parameters, my approach is of no help:

 expr1 = Simplify[Series[Zell[q, y], {q, 0, 3}] // Normal, {q > 0, y > 0,
k \[Element] Reals}] // AbsoluteTiming


returns 76 seconds of calculation and a lengthily result, which I do not show because it takes lots of place. Now, this:

expr2 = Simplify[Series[expr1[[2]], {y, 0, 3}] // Normal, {q > 0, y > 0,
k \[Element] Reals}] // AbsoluteTiming


takes 1.3 seconds and returns the answer:

(*
(1/(6 y^(19/6)))(4 y^(13/6) + 3 I Sqrt[3] y^(7/3) + 6 y^(5/2) +
15 y^(17/6) - 18 I Sqrt[3] y^3 + 80 y^(19/6) +
18 I Sqrt[3] y^(10/3) + 3 I Sqrt[3] q^(1/6) (-1 + y) y^(10/3) +
15 y^(7/2) + 6 y^(23/6) - 3 I Sqrt[3] y^4 + 8 y^(25/6) -
3 I Sqrt[3] (q^7 y)^(1/3) -
6 I Sqrt[3] q^(5/6) (-1 + y)^2 y^2 (-1 + 3 y) +
3 I Sqrt[3] Sqrt[q] y^(7/3) (-1 - y^(2/3) + y + y^(5/3)) +
3 q^(1/3) y^(5/2) (1 + y^(1/3) - 3 y - y^(4/3) + 2 y^2) +
3 q^(2/3) (-1 + y) y^(
11/6) (1 - I Sqrt[3] y^(1/6) - 5 y + 2 I Sqrt[3] y^(7/6) + y^(
5/3) + 5 y^2) -
3 I Sqrt[3] q^(11/6) (-1 + y)^2 y (3 - 25 y + 29 y^2 + y^3) +
3 q^(5/3) (-1 + y)^2 y^(
5/6) (1 - I Sqrt[3] y^(1/6) + 2 y^(2/3) - 14 y +
11 I Sqrt[3] y^(7/6) + 22 y^2 - 10 I Sqrt[3] y^(13/6) -
3 y^(8/3) + 2 y^3) +
6 I Sqrt[3] q^(7/6) y^(7/3) (-1 + 4 y - 6 y^2 + 3 y^3) -
3 I Sqrt[3] q^(3/2) y^(
4/3) (-3 - 6 y^(2/3) + 13 y + 16 y^(5/3) - 16 y^2 - 13 y^(8/3) +
6 y^3 + 3 y^(11/3)) +
3 q^(4/3) y^(
3/2) (-1 - 3 y^(1/3) - 6 I Sqrt[3] y^(5/6) + 6 y + 13 y^(4/3) +
8 I Sqrt[3] y^(11/6) - 5 y^2 - 16 y^(7/3) -
2 I Sqrt[3] y^(17/6) - 5 y^3 + 6 y^(10/3) - I Sqrt[3] y^(23/6) +
5 y^4) -
3 q^(7/3) (-1 + y) y^(
5/6) (2 + 16 I Sqrt[3] Sqrt[y] - y^(2/3) - 26 y -
37 I Sqrt[3] y^(3/2) - 3 y^(5/3) + 57 y^2 +
35 I Sqrt[3] y^(5/2) + 20 y^(8/3) - 41 y^3 -
8 I Sqrt[3] y^(7/2) - 18 y^(11/3) + 10 y^4) +
3 I Sqrt[3] q^(
17/6) (-1 + y)^2 (1 - 31 y + 125 y^2 - 119 y^3 + 12 y^4) +
3 I Sqrt[3] q^(13/6) y^(4/3) (8 - 43 y + 87 y^2 - 79 y^3 + 27 y^4) +
q^2 (-1 + y) y^(
5/6) (-15 + 30 I Sqrt[3] y^(1/6) - 360 y^(1/3) -
24 I Sqrt[3] Sqrt[y] - 24 y^(2/3) + 165 y -
216 I Sqrt[3] y^(7/6) + 2088 y^(4/3) + 213 I Sqrt[3] y^(3/2) +
174 y^(5/3) - 174 y^2 + 213 I Sqrt[3] y^(13/6) - 2440 y^(7/3) -
216 I Sqrt[3] y^(5/2) - 165 y^(8/3) + 24 y^3 -
24 I Sqrt[3] y^(19/6) + 728 y^(10/3) + 30 I Sqrt[3] y^(7/2) +
15 y^(11/3) + 8 y^(13/3)) +
3 q^(8/3) Sqrt[
y] (-3 + 13 y^(1/3) - 16 I Sqrt[3] Sqrt[y] + 21 y - 98 y^(4/3) +
97 I Sqrt[3] y^(3/2) - 40 y^2 + 238 y^(7/3) -
201 I Sqrt[3] y^(5/2) + 27 y^3 - 240 y^(10/3) +
188 I Sqrt[3] y^(7/2) - 2 y^4 + 92 y^(13/3) -
82 I Sqrt[3] y^(9/2) - 5 y^5 - 5 y^(16/3) +
14 I Sqrt[3] y^(11/2)) +
3 I Sqrt[3] q^(5/2) y^(
1/3) (-2 - 8 y^(2/3) + 33 y + 53 y^(5/3) - 97 y^2 - 111 y^(8/3) +
111 y^3 + 97 y^(11/3) - 53 y^4 - 33 y^(14/3) + 8 y^5 +
2 y^(17/3)) +
q^3 (6 I Sqrt[3] - 152 y^(1/6) - 6 I Sqrt[3] y^(1/3) - 30 Sqrt[y] +
150 y^(5/6) - 246 I Sqrt[3] y + 3300 y^(7/6) +
261 I Sqrt[3] y^(4/3) + 318 y^(3/2) - 840 y^(11/6) +
1125 I Sqrt[3] y^2 - 13524 y^(13/6) - 1155 I Sqrt[3] y^(7/3) -
1092 y^(5/2) + 1494 y^(17/6) - 1785 I Sqrt[3] y^3 +
21976 y^(19/6) + 1785 I Sqrt[3] y^(10/3) + 1494 y^(7/2) -
1092 y^(23/6) + 1155 I Sqrt[3] y^4 - 16260 y^(25/6) -
1125 I Sqrt[3] y^(13/3) - 840 y^(9/2) + 318 y^(29/6) -
261 I Sqrt[3] y^5 + 5100 y^(31/6) + 246 I Sqrt[3] y^(16/3) +
150 y^(11/2) - 30 y^(35/6) + 6 I Sqrt[3] y^6 - 440 y^(37/6)) +
q y (4 y^(1/6) - 3 I Sqrt[3] y^(1/3) - 6 Sqrt[y] - 30 y^(5/6) +
42 I Sqrt[3] y - 292 y^(7/6) - 36 I Sqrt[3] y^(4/3) -
24 y^(3/2) + 60 y^(11/6) - 81 I Sqrt[3] y^2 + 648 y^(13/6) +
81 I Sqrt[3] y^(7/3) + 60 y^(5/2) - 24 y^(17/6) +
36 I Sqrt[3] y^3 - 436 y^(19/6) - 42 I Sqrt[3] y^(10/3) -
30 y^(7/2) - 6 y^(23/6) + 3 I Sqrt[3] y^4 + 76 y^(25/6) +
3 I Sqrt[3] (q y)^(1/3)))
*)


which is still so long that I doubt it to be useful. It is not all, you may still try to expand, or collect some terms and so on, depending on your ultimate needs. I hope this helps.

Have fun!

A slightly shorter expression (LeafCount of 1782 vs. 1799) can be obtained in about 1/4 the time with

Simplify@Collect[Series[Z[q, y], {q, 0, 3}, {y, 0, 3}] // Normal, {y, q}, Simplify]


Interestingly,

Simplify[Collect[Series[Z[q, y], {q, 0, 3}, {y, 0, 3}] // Normal, {y, q}, Simplify],
{q > 0, y > 0, k ∈ Reals}]


increases the LeafCount back to 1799, although with the same shorter run-time.

Often, Using Collect to break a lengthy expression into pieces before applying Simplify reduces run-time significantly.