<s>[INST] Pade approximant for the function $\sqrt{1+x}$ I'm doing the followiwng exercise:

The objective is to obtain an approximation for the square root of any given number using the expression
$$\sqrt{1+x}=f(x)\cdot\sqrt{1+g(x)}$$
where g(x) is an infinitesimal. If we choose $f(x)$ as an approximation of $\sqrt{1+x}$, then we can calculate $g(x)$:
$$g(x)=\frac{1+x}{f^2(x)}-1$$
$f(x)$ can be chosen as a rational function $p(x)/q(x)$, such that $p$ and $q$ have the same degree and it's Mclaurin series is equal to the Mclaurin series of the function $\sqrt{1+x}$ until some degree. Find a rational function $f(x):=p(x)/q(x)$, quotient of two linear polynomials, such that the McLaurin series of $p(x)-\sqrt{1+x}\cdot q(x)$ have the three first terms equal to $0$.

How can I do this? Has something to be with the Pade approximant?
Any hint would be really appreciated. Thanks for your time.
 [/INST] Using the idea of continued fractions, observe that
$$
\sqrt{1+x}=1+(\sqrt{1+x}-1)=1+\frac{x}{2+(\sqrt{1+x}-1)}\\=1+\cfrac{x}{2+\cfrac{x}{2+(\sqrt{1+x}-1)}}=…
$$
continuing in an obvious repetitive pattern.
The computation of the (degree-balanced) partial fractions of this can be implemented (in Magma CAS) as
F<x>:=RationalFunctionField(Rationals());
p := 0;
for k in [1..6] do
   p := x/(2+x/(2+p));
   print 1+p;
end for;

with the results (for instance using http://magma.maths.usyd.edu.au/calc/)
(3*x + 4)/(x + 4)
(5*x^2 + 20*x + 16)/(x^2 + 12*x + 16)
(7*x^3 + 56*x^2 + 112*x + 64)/(x^3 + 24*x^2 + 80*x + 64)
(9*x^4 + 120*x^3 + 432*x^2 + 576*x + 256)/(x^4 + 40*x^3 + 240*x^2 + 448*x + 256)
(11*x^5 + 220*x^4 + 1232*x^3 + 2816*x^2 + 2816*x + 1024)/(x^5 + 60*x^4 + 560*x^3 + 1792*x^2 + 2304*x + 1024)
(13*x^6 + 364*x^5 + 2912*x^4 + 9984*x^3 + 16640*x^2 + 13312*x + 4096)/(x^6 + 84*x^5 + 1120*x^4 + 5376*x^3 + 11520*x^2 + 11264*x + 4096)

as the first six balanced Pade approximants.
</s>