Expanding an algebraic expression in powers of specific coefficients

I have the following algebraic expression:

(2a^4bc + a^3b^2 + a^3(c^2+2cd)d + a^2b^3d + a^2b(4c^3-c^2d-6cd^2+2d^3) + 2cd^2b^3 -
b^3c^2d + b(2c^5-3c^4d+4c^3d^2+d^5-6cd^4+2c^2d^3) + ab^2(4c^3-c^2d-6cd^2+2d^3) + 2ab^4c +
b(2c^5-3c^4d+4c^3d^2+2c^2d^3-6cd^4+d^5)) / ((a^2+c^2)(b^2+c^2)+2(ab-c^2)d^2+d^4)


The entire expression may not have been relevant, but in any case, I want to arrange the expression in a certain form with terms in powers of (a/b) and/or ((c-d)/d); i.e.,

something*(a/b) + 2ndsomething*(a/b)^2 + 3rdsomething((c-d)/d)


and so on.

I have looked at Collect and excluded forms but haven't been able to work out how to get the result I want. Not sure if it's possible.

• It's a rational function. Do you mean to separately expand numerator and denominator in terms of these given expressions? (Multivariate power series can be tricky beasts and you may not want to work with them directly.) Also is cd meant to be a distinct variable or c*d? Dec 15, 2017 at 23:34

It is not quite clear, what are you after, since your expression contains a denominator. Thus, you task can either be understood as (i) expansion of the whole expression in series in terms of a/b and (c-d)/d, or (ii) as only an expansion of the numerator, while the denominator should stay as it was. I will understand the question in the second sense.

First of all let me note that the expressions such as bc in the first term or cdin the second one Mma interprets as a new variable bc or cd, rather than a product b*c or c*d. You should either put a single space, or a sign *between them. After correction, let us introduce a rule:

rule = {a -> x*b, c -> d*y + d};


and then according to this rule let us replace variables:

expr = (2 a^4 b*c + a^3 b^2 + a^3 (c^2 + 2 c*d) d + a^2 b^3 d +
a^2 b (4 c^3 - c^2 d - 6 c*d^2 + 2 d^3) + 2 c*d^2 b^3 -
b^3 c^2 d +
b (2 c^5 - 3 c^4 d + 4 c^3 d^2 + d^5 - 6 c*d^4 + 2 c^2 d^3) +
a*b^2 (4 c^3 - c^2 d - 6 c*d^2 + 2 d^3) + 2 a*b^4 c +
b (2 c^5 - 3 c^4 d + 4 c^3 d^2 + 2 c^2 d^3 - 6 c*d^4 +
d^5))/((a^2 + c^2) (b^2 + c^2) + 2 (a*b - c^2) d^2 + d^4) /.rule


Now we can take the numerator and apply Collect to it:

expr2=Collect[Expand[Numerator[expr]],
Drop[Table[x^m*y^n, {m, 0, 4}, {n, 0, 5}] // Flatten, 1]]

(*  b^3 d^3 + (2 b^5 d - b^3 d^3) x + (b^5 d - b^3 d^3) x^2 + (b^5 +
3 b^3 d^3) x^3 + 2 b^5 d x^4 +
16 b d^5 y + (2 b^5 d + 4 b^3 d^3) x y + 4 b^3 d^3 x^2 y +
4 b^3 d^3 x^3 y + 2 b^5 d x^4 y + (-b^3 d^3 + 32 b d^5) y^2 +
11 b^3 d^3 x y^2 + 11 b^3 d^3 x^2 y^2 + b^3 d^3 x^3 y^2 +
24 b d^5 y^3 + 4 b^3 d^3 x y^3 + 4 b^3 d^3 x^2 y^3 + 14 b d^5 y^4 +
4 b d^5 y^5    *)


What to do further is to extent the question of a personal taste. It is, therefore, up to you. I would prefer to represent the result as a sum of terms of the numerator, each being divided by the denominator:

expr3=Map[Divide[#, Denominator[expr]] &, expr2] /. {x -> HoldForm[a/b],
y -> HoldForm[(c - d)/d]}


The result looks rather clumsy as a code, and it is much too large to show it here as an image. Therfore, I only show here first few terms of the result as an image:

Altogether there are 19 terms of the expression:

Length[expr3]

(*  19  *)


from which only 4 are shown above. One can separately address to each of them. For example, let us address the 10th term:

expr3[[10]]

As it is, it is good to look at, but I used the HoldForm function above to preserve the view of the terms. Therefore, if you intend to further operate with any of those terms, remove Hold first:

expr3[[10]] // ReleaseHold

(*  (2 a^4 b (c - d))/((a^2 + c^2) (b^2 + c^2) + 2 (a b - c^2) d^2 + d^4)  *)


Have fun!

Later edit: To address your question. If you need to also expand the denominator, you get series, rather than a simple polynomial. Then you may use the function Series, but you need to inicate, up to what order do you need to expand the expression.

I will act as if you need to expand the expression up to cubes both in x and y and use the notations already introduced above. Try this

    Collect[Series[expr, {x, 0, 3}, {y, 0, 3}] // Normal // Expand, {x,
x^2, x^3, y, y^2, y^3, x*y, x^2*y, x*y^2}]


Though you may easily evaluate it, the result is better visible as an image below:

You may no make the reverse replacement (just as I did above) to obtain the finla result.

Have fun!

• Thanks this was very helpful, I did ideally want the entire numerator AND denominator expanded so that each coefficient before an x or y term had it's own numerator and denominator. I'm not sure how possible this is though. Dec 14, 2017 at 3:10
• Please have a look at the edit. Dec 14, 2017 at 9:34