4. (1990 National High School League Question) Find the maximum value of the function $f(x)=\sqrt{x^{4}-3 x^{2}-6 x+13}-\sqrt{x^{4}-x^{2}+1}$.
4. The original function can be transformed into
$$
f(x)=\sqrt{\left(x^{2}-2\right)^{2}+(x-3)^{2}}-\sqrt{\left(x^{2}-1\right)^{2}+x^{2}} \text {. }
$$

Let $a=\left(x^{2}-2, x-3\right) ; b=\left(x^{2}-1, x\right)$, then
$f(x)=|a|-|b|$, and $a-b=(-1,-3)$.

Since $||a|-| b|| \leqslant|a-b|=\sqrt{10}$,
thus, $f(x) \leqslant \sqrt{10}$, with equality holding if and only if $a$ and $b$ are in the same direction, i.e., $a=\lambda b(\lambda>0)$.

From $\frac{x^{2}-2}{x^{2}-1}=\frac{x-3}{x}=\lambda$, we get $x=\frac{1-\sqrt{37}}{6}, \lambda=\frac{\sqrt{37}+18}{\sqrt{37}-1}$.
Therefore, when $x=\frac{1-\sqrt{37}}{6}$, $f(x)_{\text {max }}=\sqrt{10}$.