1
$\begingroup$

When I try to solve an equation with a constant under the summation sign, Mathematica does not factor the constant out of the summation and fails to solve a simple equation.

How do I make Mathematica handle the problem that arises below as it handles the second case that follows it:

z[t_] = Sum[2 a[0] + m[t], {t, 0, M}]; 
Solve[z[t] == 0, a[0]]

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

Solve[Sum[2*a[0] + m[t], {t, 0, M}] == 0, a[0]]
z[t_] = a[0] Sum[2, {t, 0, M}] + Sum[m[t], {t, 0, M}];
Solve[z[t] == 0, a[0]]
{{a[0] -> -(Sum[m[t], {t, 0, M}]/(2 (1 + M)))}}
$\endgroup$
  • $\begingroup$ Maybe: z[t_] = Sum[#, {t, 0, M}] & /@ (2*a[0] + m[t]); Solve[z[t] == 0, a[0]]? $\endgroup$ – Mariusz Iwaniuk May 11 at 19:44
2
$\begingroup$

One idea is to create a function that expands out sums:

expandSums[expr_] := expr /. s_Sum :> RuleCondition[expandSum[s]]

expandSum @ Sum[a_, i__] := factorSum[Expand[a], i]

factorSum[a_Plus, i__] := Thread[Unevaluated @ factorSum[a, i], Plus]
factorSum[a_Times, i__List] := With[{iter = Alternatives[i][[All, 1]]},
    Times[
        DeleteCases[a, _?(Not @* FreeQ[iter])],
        Sum[DeleteCases[a, _?(FreeQ[iter])], i]
    ]
]
factorSum[a_, i__] := Sum[a, i]

Then you can apply this function to your Sum:

expanded = expandSums[Sum[2 a[0] + m[t], {t, 0, M}]];
expanded //TeXForm

$2 a(0) \sum _{t=0}^M 1+\sum _{t=0}^M m(t)$

and then use Solve:

Solve[expanded == 0, a[0]] //TeXForm

$\left\{\left\{a(0)\to -\frac{\sum _{t=0}^M m(t)}{2 \sum _{t=0}^M 1}\right\}\right\}$

$\endgroup$
  • 1
    $\begingroup$ I do not understand this code yet, but this is robust. I could find p[0] after the change: expanded = expandSums[ Sum[2 (p[0] m[t] + 2 v[t] p[0] p[1] + p[1] m[t])^2, {t, 0, M}]]; $\endgroup$ – glynn May 12 at 0:30
  • $\begingroup$ Thanks for your kind response @CarlWoll. After simplification, the sum of "one's", ∑1 from 0 to M, in your response evaluates to equal (1+M). This simplification does not occur when expecting ∑∑m[t] to equal (1+M)* ∑m[t]. Any thoughts? $\endgroup$ – glynn May 16 at 23:32
0
$\begingroup$

Mathematica works this way. Notice that the summation with explicit numeric bounds:

Sum[2 + x[n], {n, 3}] == 6 + x[1] + x[2] + x[3]

returns result True. The summation with no explicit numeric bounds:

Sum[2 + x[n], {n, k}] 

returns the unevaluated result. There are good reasons why it works this way. However, there are always more than one way to get the results you want and you have used one of them yourself. Unless I am very mistaken, there is no easy way here working only within Sum[].

Another way is to treat summation as a linear operator with the help of Map[]. The following code attempt:

Map[Sum[#, {t, 0, N}] &, (2 a[0] + m[t])]

does just that. The idea is that Map[] works on the top level of the sum 2 a[0] + m[t] and distributes the Sum[] over the top level Plus[]. Of course, this is risky code because it will blindly do similar things if you apply it to 2 a[0] * m[t] and, of course, Sum[] doesn't distribute over Times[].

An improved and safer version of it is this code:

(2 a[0]+m[t]) /. x : __Plus :> Map[Sum[#, {t, 0, N}] &, x]

which only distributes over a sum of terms because of the explicit Rule[]. It probably does what you want.

$\endgroup$

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.