Question: how to emulate this pattern operation in Maple?

Given an expression, I want to do an operation each time the pattern  f(arg1)+f(arg2) is found by replacing it by f(arg1+arg2). Regadless of how many there are. For example

f(A)+f(B) -> f(A+B) and  f(A)+f(B)+f(C) -> f(A+B+C)  and so on. But here is the catch, there could be anything else in the expressions. These will be left unchanged. 

So f(A)+f(B)+x -> f(A+B)+x

I can do it in Maple only when the input is exactly f(A)+f(B)  when the input is f(A)+f(B)+f(C) and so on.

But this is not practical as I need to make new type for each case.

I need a general way that will work for any expression like in the above example.

I am now using evalindets, but I do not know how to tell it the type for the general pattern of  f(n1)+f(n2)+.....+f(nn) to replace these with f(n1+n2+....nn).

For reference, this is code in Mathematica I am trying to translate to maple.

expr = Sin[x] + f[A] + f[B] + 10*Exp[x]/13 + Cos[x] + f[c] + f[10*c];
expr //. f[a_] + f[b_] :> f[a + b]

In the above //. means repeated replacement. So it will keep replacing the same pattern over and over and this works regardless of where f(a)+f(b) show up. They can be anywhere in the sum.

I wish I can the same in Maple using evalindets. I tried patmatch also, and same problem. Which is how to make it general. This is what I tried

expr:=f(A)+f(B);
evalindets(expr,`&+`('specfunc(f)','specfunc(f)'),F->f( op([1,1],F) + op([2,1],F) ) );

Which works

But to detect expr:=f(A)+f(B)+f(C) it would need new code

expr:=f(A)+f(B)+f(C);
evalindets(expr,`&+`('specfunc(f)','specfunc(f)','specfunc(f)'),F->f( op([1,1],F) + op([2,1],F) + op([3,1],F) ) );

Obviously this approach will not work. It will also fail once a new term is added in between. 

But how to extend this to the general case of

expr:=sin(x)+f(A)+f(B)+10*exp(x)/13+cos(x)+f(C)+f(10*C);

Is there a way to tell Maple to apply the pattern over and over like with Mathematica so it works for general case? I need to try to do this using either patmatch or evalindets. Ofcourse I can do it the hard way, by iterating over the expression and collecting all the f() and add their arguments one by one each `+` subtype. But that is now what I looking for.  

There should be something similar to how it is done in Mathematica, but using Maple command. Notice that the Mathematica example will work regadless of where the f(a)+f(b) shows up.

expr = Sin[x] + f[A] + f[B] + 10*Exp[x]/13 + Cos[x] + f[c] + 1/(f[10*c] + x + f[99])
expr //. f[a_] + f[b_] :> f[a + b]

ps. may be I need to use subsindets['nocache'] need to look more into it.

Please Wait...