<s>[INST] Numerical evaluation of first and second derivative We start with the following function $g: (0,\infty)\rightarrow [0,\infty)$,
$$ g(x)=x+2x^{-\frac{1}{2}}-3.$$ From this function we need a 'smooth' square-root. Thus, we check $g(1)=0$, 
$$g'(x)=1-x^{-\frac{3}{2}},$$ $g'(1)=0$ and 
$$g''(x)=\frac{3}{2}x^{-\frac{5}{2}}\geq 0.$$ 
Therefore, we can define the function $f: (0,\infty)\rightarrow \mathbb{R}$,
$$f(x)=\operatorname{sign}(x-1)\sqrt{g(x)}.$$ 
We can compute the first derivatives as 
$$
f'(x)=\frac{1}{2} \frac{g'(x)}{f(x)}=\frac{1}{2}\frac{1-x^{-\frac{3}{2}}}{\operatorname{sign}(x-1)\sqrt{x+2x^{-\frac{1}{2}}-3}}
$$
and second derivatives as 
$$
f''(x)=\frac{1}{2} \frac{g''(x)f(x)-g'(x)f'(x)}{\bigl(f(x)\bigr)^2}\\
=\frac{1}{2}\frac{g''(x)-\frac{\bigl(g'(x)\bigr)^2}{2g(x)}}{f(x)}\\
=\frac{1}{2}\frac{\frac{3}{2}x^{-\frac{5}{2}}-\frac{\bigl(1-x^{-\frac{3}{2}}\bigr)^2}{2\bigl(x+2x^{-\frac{1}{2}}-3\bigr)}}{\operatorname{sign}(x-1)\sqrt{x+2x^{-\frac{1}{2}}-3}}
$$
where we used $f'(x)$ from above, reduced by $f(x)$ and used $f^2(x)=g(x)$. 
For $x=1$ the first and the second derivatives of $f$ are of the type $\frac{0}{0}$. 
I need a numerical stable evaluation of this derivatives. 
But we have numerical cancellation especially in the nominators. 
A linear Taylor-polynomial at $x=1$ is possible for $f'(x)$ but the computation of $f'''(1)$ by hand is time-consuming. 


*

*Is there a better formulation for $f(x)$?

*Is there an easy way to compute the coefficients of the Taylor-polynomials at $x=1$?

*(Edit 2:) How can I evaluate $f'(x)$ and $f''(x)$ numerically stable for $x\in (0,\infty)$?

Edit 1:
The Taylor-polynomial of degree 1 for $f'(x)$ at $x=1$ is 
$$
f'(x)=\frac{\sqrt{3}}{2} - \frac{5}{4\sqrt{3}}(x-1)+\mathcal{O}\bigl(\lvert x-1\rvert^2\bigr)
$$
 [/INST] For the first question, since $g(x)=\frac{(\sqrt{x}-1)^2(\sqrt{x}+2)}{\sqrt{x}}$, then
$$f(x)=sign(x-1)\sqrt{\frac{(\sqrt{x}-1)^2(\sqrt{x}+2)}{\sqrt{x}}}$$
The $sign(x-1)$ part is necessary for $f$ to be smooth, as $\lim_{x\rightarrow1^-}f'(x)\neq\lim_{x\rightarrow1^+}f'(x)$.
Indeed, if we write
$$f'(x)=\frac{1}{2}\frac{1-\frac{1}{x\sqrt{x}}}{sign(x-1)\sqrt{\frac{(\sqrt{x}-1)^2(\sqrt{x}+2)}{\sqrt{x}}}}=\frac{\sqrt[4]{x}}{2\sqrt{(\sqrt{x}+2)}}\frac{1-\frac{1}{x\sqrt{x}}}{(\sqrt{x}-1)}$$
(ignoring the $sign$ part for manipulation), we see that
$$\lim_{x->1^+}f'(x)=\frac{1}{2\sqrt{3}}\frac{0}{0}$$
The part that gives the $\frac{0}{0}$ indetermination can be solved first by multiplying by the conjugate of the denominator...
$$\lim_{x->1^+}\frac{1-\frac{1}{x\sqrt{x}}}{(\sqrt{x}-1)}=\lim_{x->1^+}\frac{(1-\frac{1}{x\sqrt{x}})(\sqrt{x}+1)}{x-1}=\lim_{x->1^+}\frac{\sqrt{x}+1-\frac{1}{x}-\frac{1}{x\sqrt{x}}}{x-1}=\frac{0}{0}\dots$$
...and applying L'Hôpital's rule:
$$\dots\lim_{x->1^+}\frac{1}{2\sqrt{x}}+\frac{1}{x^2}+\frac{3}{2x^{5/2}}=3$$
Knowing this, we get that
$$\lim_{x->1^+}f'(x)=\frac{3}{2\sqrt{3}}=\frac{\sqrt{3}}{2}$$
Analysing the function $f$ taking now into account the $sign(x-1)$, we obtain that
$$\lim_{x->1^-}f'(x)=-\frac{\sqrt{3}}{2}$$
as can be seen plotting $f(x)$ and $-f(x)$.
</s>