# Solve a function with sum in Mathematica?

I want to solve an equation with sum in Mathematica, e.g.,

$$\sum _i \frac{a_i}{x}=1$$

But when I input this:

Solve[Sum[Subscript[a, i]/x, i] == 1, x]


Mathematica will tell me:

Solve::nsmet : This system cannot be solved with the methods available to Solve.

If I remove the $x$ from the equation like this:

$$\frac{\sum _i a_i}{x}=1$$

And:

Solve[Sum[Subscript[a, i], i]/x == 1, x]


Then Mathematica can actually solve it. But this seems a bit troublesome and strange to me. So am I using it incorrectly? What should I input in this case, thanks!

• This question is off-topic here. Please see FAQ. Nov 17, 2011 at 20:41
• I think this question is on-topic. Please consider this my vote against closure. Nov 17, 2011 at 21:01
• @OP: What is your desired output? Nov 17, 2011 at 21:54
• @IvanZ.Siu It is not surprising that mathematica cannot handle this, since it is not clear at all what mathematica should do to a sum with unspecified summation range in general. Please consider supporting the proposals for a mathematica stackexchange site: area51.stackexchange.com/proposals/15787/mathematica Nov 17, 2011 at 23:19
• @Phira Thanks. Sure I will. Nov 18, 2011 at 4:56

Mathematica does not have the (user facing) ability to do manipulations of unevaluated sums or integrals. However, simple cases are easily programmed by hand.

I assume that the indefinite sum that you're really interested in is more complicated than the example you provided. Here's some quick code for taking common factors out of sums and expanding sums. You can write similar code to reverse these operations.

factorSum[expr_] := expr /. Sum[x_, i_] :> Module[
{factx = Factor[x], common,
ii = If[Head[i] === List, First[i], i]},
common = If[Head[factx] === Times, Select[factx, FreeQ[#, ii]&], 1];
common Sum[factx/common, i]]
expandSum[expr_] := expr /. Sum[x_, i_] :> Module[
{expandx = Expand[x], ii = If[Head[i] === List, First[i], i]},
Total@Table[Sum[term, i], {term, List @@ expandx}], Sum[x, i]]]


And here it is in action (you can replace the indefinite i with a more definite {i, n1, n2} and it still works):

In[3]:= factorSum[Sum[a[i]*x*y*b^i + y*c[i], i]]
expandSum[%]
factorSum[%]

Out[3]= y*Sum[b^i*x*a[i] + c[i], i]

Out[4]= y*(Sum[b^i*x*a[i], i] + Sum[c[i], i])

Out[5]= y*(x*Sum[b^i*a[i], i] + Sum[c[i], i])


Note that it is a little slow, because every time a new Sum is produced, Mathematica tries to see if it can evaluate it. If you were serious about implementing formal manipulations of sums and integrals, you'd have to define new symbolicSum-type objects or turn off the built in behaviour while your code is running.

In[6]:= Solve[factorSum[Sum[Subscript[a, i]/x, i]] == 1, x]