Question: Collect using pattern?

is it possible to collect using pattern? For example, given 

How to tell Maple to collect on  r^power terms to produce

This came up in another forum here  and using that other software, it is possible to ask collect to collect on pattern r^_

Is there a way in Maple to collect on all powers of r in the above? Here is worksheet

A:=r^(2*a)+r^2*(1+a+r^(2*a)) + r + a*r;
B:=(1+a)*r+(1+a)*r^2+r^(2*a)+r^(2+2*a);

r^(2*a)+r^2*(1+a+r^(2*a))+r+a*r

(1+a)*r+(1+a)*r^2+r^(2*a)+r^(2+2*a)

simplify(A-B)

0

collect(A,r)

r^2*(1+a+r^(2*a))+(1+a)*r+r^(2*a)

collect(A,r,'distributed')

r^2*(1+a+r^(2*a))+(1+a)*r+r^(2*a)

collect(A,r,'recursive')

r^2*(1+a+r^(2*a))+(1+a)*r+r^(2*a)

collect(A,r,expand)

(1+a+(r^a)^2)*r^2+(1+a)*r+(r^a)^2

collect(A,r^(n::anything))

Error, (in collect) cannot collect r^n::anything

 


 

Download collect_using_pattern.mw

Using that other software:

 

Please Wait...