Question:Better way to change all indexed variables in an expression with head Sum?

Question:Better way to change all indexed variables in an expression with head Sum?

Maple 2023

I have expressions with head Sum that are all either one single Sum or sum of these Sum's. So my expression is either

Sum(.....)+Sum(....)+Sum(...)   or Sum()

Inside each Sum, I have indexed a[n] and also possibly nonindexed For an example

Sum( a[n]*x + a, n=1..10)

And I want to change all the indexed a[n] to b[n]

Hence the example above it will becomes  Sum( b[n]*x + a, n=1..10)

I can't just use eval(expr,a=b) as that will also change the non-indexed a to b which I want to leave as is. There will be only one single indexed variable in the sum. In this example it is `a`

Below is a general example and my solution. I'd like to find if there is a more canonical way or shorter more direct way to do this in Maple.

```restart;
expr:=Sum(x^(n+r)*a[n]*(n+r)*(n+r-1)+a[n-1]+3*a*x^10,n = 0 .. infinity)+Sum(4*a*x^(n+r)*a[n],n = 0 .. infinity)+Sum(4*a[n-1]*x^(n+r)+a[n]*x+a*x,n = 1 .. infinity) = 0;

evalindets(expr,specfunc( anything, 'Sum' ),f->Sum(evalindets(op(1,f),'indexed',ff->b[op(ff)]),op(2,f)))

```

I used evalindets twice. Once to look for Sum, and then to look for 'indexed' within each sum. It seems to work. Here is screen shot of the output

If you asking why I have indexed a and non indexed a in the same expression? Well, it is because the non-indexed happend to be a coefficient of the ode that the user used. So it is part of the input, which I have no control over. But the indexed is a local variable I am using inside the function being called to process the input.

On the screen they look the same. But they are actually not the same. The indexed is local to the function and the non-indexed is input via argument. So it is global symbol.

﻿