This question already has an answer here:

I am currently trying to expand a sum without evaluating it, e.g. $$\sum_{i=0}^5 i^2 = 1^2+2^2+3^2+4^2+5^2$$ So I am trying to create a function

SumExpansion[expr_, {i_, a_, b_}]

which outputs something like the example on the right hand side, without actually evaluating the sum. I have tried several different approaches but Mathematica always seems to evaluate it.


marked as duplicate by m_goldberg, Sektor, MarcoB, Young, anderstood Apr 27 '18 at 1:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


may be


Mathematica graphics

But this uses a wrapper. I do not think there is a way without using Hold and friends.


What about this? I am assuming that expr will be in terms of i:

SumExpansion[expr_, {a_, b_}] := HoldForm[Sum[expr, {i, a, b}]] == 
Part[Trace@(Plus @@ (Function[u, Defer@expr /. i -> u][#] & /@ 
    Range[a, b])), 3]

SumExpansion[i^2, {4, 8}]

$$\sum _{i=4}^8 i^2=4^2+5^2+6^2+7^2+8^2$$

SumExpansion[i^2 + i + 4/i^3, {1, 5}]

$$\sum _{i=1}^5 \left(\frac{4}{i^3}+i+i^2\right)=\left(\frac{4}{1^3}+1+1^2\right)+\left(\frac{4}{2^3}+ 2+2^2\right)+\left(\frac{4}{3^3}+3+3^2\right)+\left(\frac{4}{4^3}+4+4^2\right)+\left(\frac{4}{5^3}+5+5^2\right)$$


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