I have this sum

 Sum[-E^(-j (x kx[p] + y ky[q] + z kz[r])) j g w ky[q] Ux[p, q, r],
     {p, -∞, ∞}, {q, -∞, ∞}, {r, -∞, ∞}]

and I would like to pull constants out of the triple sum. I have so many terms that is why I prefer to do it automatic.

Thanks in advance


1 Answer 1


This is kind of ugly, but here goes:

factorFromSum[sum_, vars_] :=
    Inactivate[sum, Sum] /.
      Inactive[Sum][Times[a_, rest_?(Function[{pat}, AllTrue[FreeQ[pat, #] &]@vars])], r___]
      rest Inactive[Sum][a, r]
SetAttributes[factorFromSum, HoldFirst];


factorFromSum[Sum[5 x^2, {x, 1, 10}], {x}]


5 Inactive[Sum][x^2, {x, 1, 10}]

To reenable the sum, finally perform Activate[#, Sum]&.

Your final output is given by

  Sum[-E^(-j (x kx[p] + y ky[q] + z kz[r])) j g w ky[q] Ux[p, q, r],
     {p, -Infinity, Infinity},
     {q, -Infinity, Infinity},
     {r, -Infinity, Infinity}],
  {p, q, r}]
// Activate[#, Sum]&
  • $\begingroup$ It should be: Inactive[Sum][a, r],not Inactive[Sum][a, r]}? $\endgroup$ Mar 13, 2018 at 22:34
  • $\begingroup$ @MariuszIwaniuk Quite right, sorry; a legacy of when I had the rule wrapped in a list. $\endgroup$ Mar 13, 2018 at 23:13
  • $\begingroup$ Many thanks for all. $\endgroup$
    – qahtah
    Mar 14, 2018 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.