# Splitting a general rational polynomial ansatz into powers

EDIT This question is completely wrong and useless. It is mathematically incorrect. I think something like Series is sufficient if you're trying to do something similar.

Given a general polynomial ansatz constructed using methods described in this SE post, which looks something like

 expr=(Ca1 + Ca1 x + Ca1 x^2)/(1 + Da1 x +
Da1 x^2)


or perhaps easier to read, I can state my input as

$$\dfrac{c_1 + c_2x+c_3x^2}{1+d_1x+d_2x^2} .$$

I am attempting to use this ansatz and attempt to solve for the various coefficients in my problem, by using Collect. For the case where my ansatz was simply a polynomial, this was trivial to use.

I think it might be useful to instead attempt to separate this out into a polynomial in powers of x immediately. In particular, for one free variable x and only up to order two in the polynomial, I am expecting to find the result (in more legible notation).

$$c_1 + c_2x+c_3x^2 + \\ \dfrac{c_1}{d_1} \dfrac{1}{x} + \dfrac{c_2}{d_1} + \dfrac{c_3}{d_1}x + \\ \dfrac{c_1}{d_2} x^2 + \dfrac{c_2}{d_2}x + \dfrac{c_3}{d_2}$$.

Importantly, I then want to collect into relevant powers of x and solve for the coefficients, probably using Collect to collate the corresponding powers. Below I have stated my desired output.

$$(c_1 + \dfrac{c_2}{d_1} + \dfrac{c_3}{d_2}) + (c_2 + \dfrac{c_3}{d_1}+ \dfrac{c_2}{d_2})x + (c_3 + \dfrac{c_1}{d_2})x^2 + \dfrac{c_1}{d_1} x^{-1} + \dfrac{c_1}{d_2} x^{-2}$$

I attempted to do this using replacement rules, like

expr//.{a__/(b_+c_):>a/b+a/c,(a_+b_)/c_:>a/c+b/c}


and then collect appropriately, but it ended up giving me a very weird form which wasn't useful to me. Any suggestions would be appreciated. As a summary, I am hoping to take a rational function of polynomials, and simplify the out to look more like a power series in orders of x, as described above.

If you really want to get your desired output (with typos corrected) use

s = (c1 + c2 x + c3 x^2)/{1, d1 x, d2 x^2} // Total;
d = (c1 + c2/d1 + c3/d2) + (c2 + c3/d1) x + c3 x^2 + (c1/d1 + c2/d2)/x + c1/d2 x^(-2);


and s == d // Simplify will confirm that they are the same.

However this desired output is not equivalent to the rational function because division does not distribute.

• Much more compact: PadeApproximant[1 + 2 x + 3 x^2 + 4 x^3 + 4 x^4, {x, 0, 2}] Mar 15, 2019 at 13:48
• Hi Somos; thank you for your answer. It doesn't quite run correctly on my system, and I get an error which I'm not expecting. If I change a few things (like putting a zero instead of O?), then I can get a solution, but it's still not the result which you state. Either way, I don't quite see how this solves my problem I'm afraid.
• As in, I get an error about SeriesData, and either way, Solve would only find an expression for d1. I copied and pasted your code into a new session with a fresh kernel. In terms of the problem I posed, I was more looking for a method to rewrite a rational function in terms of orders of the variable x. I will edit my question and try and clarify.
• @Brad Sorry about my typo. In version 10 O[x^5] worked but it should have been O[x]^5 and newer versions of Mathematica are more strict. Mar 15, 2019 at 14:14