# How to re-index a series?

I'm trying to implement Frobenius method of solving ODEs in Mathematica, namely make a general routine to get recurrence relations from a given equation. Currently I'm stuck at re-indexing a series (to make same powers under single summation sign).

Consider for example the following series:

Sum[r^(2 + k)*c[k], {k, 0, Infinity}]


I'm trying to change k index to m-n (in this example n=2) it so that it looked like this:

Sum[r^m*c[m-2], {m, 2, Infinity}]


Here's my incomplete attempt:

Sum[r^(2 + k)*c[k], {k, 0, Infinity}] //.
{Sum[(a_)*r^(k + (n_)), {k, 0, Infinity}] :> Sum[a*r^(k + n), {k, 0, Infinity}] /.
k -> m - n}


For some reason it doesn't appear to change the expression at all...

So my question is: how do I implement re-indexing of a series correctly?

• I would recommend using a fake Head like sum instead of Sum, to keep from long, fruitless evaluations where Mathematica tries to perform the sum. You can always do sum -> Sum later on. The big problem is that /. k -> m - n is tacked on afterwars. I think you want this: sum[r^(2 + k)*c[k], {k, 0, Infinity}] //. {sum[(a_)*r^(k + (n_Integer)), {k, 0, Infinity}] :> (sum[a*r^(k + n), {k, 0, Infinity}] /. k -> m - n)}. – march Feb 10 '17 at 21:52

Your problems are that the Sum in the Rule evaluates, and even if it didn't evaluate, the pattern in the rule is too specific. I would use something like:

Sum[r^(2+k)*c[k],{k,0,Infinity}] /.
Verbatim[Sum][a_, {k_, k0_, Infinity}] :>
Sum[a /. k->k-n, {k, k0+n, Infinity}] //TeXForm


$\sum _{k=n}^{\infty } c(k-n) r^{k-n+2}$

You may reindex by first principles.

1. Change of variables in the term.

2. Solve for new bounds.

reindexSum[sum_Sum, change_Rule, var_Symbol] :=
Module[{term = First@sum, bounds},
term = term /. change;
bounds =
var /.
First@Solve[Equal @@ change, var] /.
Partition[MapThread[Rule, {List @@ change[[{1, 1}]], sum[[2, 2 ;;]]}], 1];
Sum[term, {var, Sequence @@ bounds}]
]


Then

reindexSum[
Sum[r^(2 + k)*c[k], {k, 0, Infinity}],
k -> m - 2,
m
]

Sum[r^m*c[-2 + m], {m, 2, Infinity}]


Hope this helps.

Along the lines suggested by @march in a comment:

expr = Sum[r^(2 + k)*c[k], {k, 0, Infinity}];

expr /. {Sum -> foo, {k, b_, e_, i___} :> {m, 2 + b, 2 + e, i}, k -> m - 2} /. foo -> Sum 