I'm wondering how to speed up the following code so it actually computes for $n=2$:
f[n_] := Expand[Sum[FunctionExpand[QBinomial[n, j, q]]*q^(j^2), {j, 0, n}]]
lhs[n_] := Sum[(-1)^j*q^(j(5j + 1)/2), {j, -n, n}]
rhs3[a_, b_, c_, d_, e_, g_, h_] :=
Expand[q^a - f[1]*q^b*Product[1 - q^i, {i, c, d}] + f[2]*q^e*Product[1 - q^i, {i, g, h}]]
B[n_] :=
Do[
If[CoefficientList[lhs[n], q] == CoefficientList[rhs3[a_, b_, c_, d_, e_, g_, h_], q],
Print[{a,b,c,d,e,g,h}]],
{a, 0, 15}, {b, 0, 15}, {c, 1, 5}, {d, 1, 5}, {e, 0,15}, {g, 1, 5}, {h, 1, 5}]
A Do loop with this many iterators may be too much computing, but there must be some built-in constructs which allow for an effective implementation.
Sample input would be B[2]
. Sample output would be {11,1,1,1,1,2,3}
(which is actually one possible solution. However, the point is to print all possible solutions, so the actual output would be a number of such lists.)
Edit:
I want to emphasize that I would like to see an approach that will work for more complicated functions for rhs3[a_, ...] that involve a few more iterator variables. To be specific, I would like to execute the comparison at least somewhat quickly for the following RHS with $n=3$ (and I'll label it as rhs3):
rhs3[a_, b_, c_, d_, e_, g_, h_, j_, k_, l_, x_, r_, y_] :=
Expand[-f[3*x + y]*q^a + f[3*x + r + y]*q^b*Product[1 - q^i, {i, c, d}]
- f[3*x + 2*r + y]*q^e*Product[1 - q^i, {i, g, h}]]
+ f[3*x + 3*r + y]*q^j*Product[1 - q^i, {i, k, l}]]
with the following variable ranges: {a, 0, 30}, {b, 0, 25}, {c, 1, 7}, {d, c, 7}, {e, 0, 20}, {g, 1, 7}, {h, g, 7}, {j, 0, 15}, {k, 1, 7}, {l, k, 7}, {x, 0, 5}, {r, -5, 5}, {y, -5, 5}
. This is of course asking for a lot, but I want to state the nature of the problem in full generality for future visitors.
lhs
. $\endgroup$ – m_goldberg Jun 17 '14 at 17:3716^3 5^4 == 2560000
iterations. Calculating and comparing the coefficient lists takes an average of 0.001110 sec. each (the average over the first five seconds worth) on my MacBook Pro. That gives an estimate of over 2800 seconds of running time to do all the comparisons. To be faster than that, it seems you would have to speed up the calculation of the coefficient lists, which I don't know how to do. $\endgroup$ – Michael E2 Jun 17 '14 at 18:27Do
iterators can depend on those to the left, ie.Do[ ... {g,1,5},{h,g,5} ]
to get onlyh>=g
$\endgroup$ – george2079 Jun 17 '14 at 18:41