I'm trying to understand an answer to the question: How to do algebra on summations of variable expressions?How to do algebra on summations of variable expressions? The following input:
reindex = s : sum[_, {i_, __}] :> (s /. i -> Unique[ToString[i]]);
unpower = s_sum^p_Integer :> Times @@ Table[s /. reindex, {p}];
test = (5*sum[x[k], {k, 1, kk}])^2;
test /. unpower
Out[4]= 25 sum[x[k3], {k3, 1, kk}] sum[x[k4], {k4, 1, kk}]
produces result, that differs from result produced by expressions ($25\neq625$):
unpowerstep1 = s_sum^p_Integer :> Table[s /. reindex, {p}];
intermediate = test /. unpowerstep1
Times @@ intermediate
Out[6]= {25 sum[x[k5], {k5, 1, kk}], 25 sum[x[k6], {k6, 1, kk}]}
Out[7]= 625 sum[x[k5], {k5, 1, kk}] sum[x[k6], {k6, 1, kk}]
Also, I cannot undestand what s_sum
mean. Does it mean, that s is any expression with head sum?