Skip to content

Instantly share code, notes, and snippets.

@hugle
Last active April 17, 2022 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugle/3cf42b47e71cc0d0e980ab0a3900790f to your computer and use it in GitHub Desktop.
Save hugle/3cf42b47e71cc0d0e980ab0a3900790f to your computer and use it in GitHub Desktop.
Expand summation expression and apply the distribution law
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment