4. The function $f(x)$
$$
\begin{aligned}
= & \sqrt{x^{2}-4 x+7-2 \sqrt{2}}+ \\
& \sqrt{x^{2}-8 x+27-6 \sqrt{2}}(x \in \mathbf{R})
\end{aligned}
$$

The minimum value of the function is $\qquad$
4. $2 \sqrt{2}$.

In the Cartesian coordinate system $x O y$, let
$$
\begin{array}{l}
A(2, \sqrt{2}-1), B(4,3-\sqrt{2}), P(x, 0). \\
\text { Then } f(x)=|P A|+|P B| \\
=\left|P A^{\prime}\right|+|P B| \\
\geqslant\left|A^{\prime} B\right|=2 \sqrt{2},
\end{array}
$$

where $A^{\prime}(2,1-\sqrt{2})$ is the reflection of $A$ over the $x$-axis.
The equality in (1) holds if and only if $A^{\prime}$, $P$, and $B$ are collinear, in which case, $x=\sqrt{2}+1$.