expr contain a sum of powers of
x with some coefficients
ci. The exponents of
x can contain variables and/or integers. I would like to define a function
MyCollect in Mathematica which would first collect all powers containing variables and would then collect all powers containing integers within the first collection. For example, such that if:
expr = c0 x^(a+b)+c1 x^(a+b+1)+c2 x^(a+b+2)+c3 x^(a+b+2)+c4 x^(a+b+2)+c5 x^(a)+c6 x^(a+1)+c7 x^(a+1)
the result would be:
x^(a)(c5 + x(c6+c7)) + x^(a+b)(c0 + x c1 + x^2(c2 + c3 + c4))
Is there a convenient way to do this? Thanks for any suggestion!
Here is a second, more complicated example
expr = c0 x^(a+b)+c1 x^(a+b+1)+c2 x^(a+b+2)+c3 x^(2a+b+2)+c4 x^(a+b+2)+c5 x^(a)+c6 x^(a+1)+c7 x^(a+1)+c8 x^(a+c+1)+c9 x^(a+c)
Desired output of
x^(a)(c5 +x(c6+c7)) + x^(a+b)(c0 +x c1+x^2(c2+c4)) + x^(2a+b)(x^2 c3) + x^(a+c)(c9+x c8)
All unique combinations of powers involving variables are collected first, and then the remaining integer powers are collected at a second level, so to say.