Skip to content

Instantly share code, notes, and snippets.

@hugle
hugle / sumexpand.nb
Last active Apr 17, 2022
Expand summation expression and apply the distribution law
View sumexpand.nb
SumExpand[exp_] :=
exp /. Sum[c_, {i_, a_, b_}] :>
Distribute[Sum[ExpandAll[c], {i, a, b}]];
rule = Sum[Times[Longest[u___], x___], {y_, z___}] :>
Times[u] Sum[Times[x], {y, z}] /; (FreeQ[{u}, y]);
SumSimplify[exp_] := SumExpand[exp] /. rule