Let $f:\mathbb{R}^d\to \mathbb{R}$ be real analytic. Define $S=\{x\in\mathbb{R}^d, \nabla f (x)=0\} $. Is it true that for any compact set $K\subset \mathbb{R}^d$, $f(S\cap K)$ is a finite set ?



Critical values of analytic functions of several variables
One can assume that $K$ is a cube, by enlarging it. Then $S \cap K$ is a bounded definable set in the $o$-minimal structure $\mathbb{R}^{\mathrm{an}}$ (obtained by adding restricted analytic function, cf [this paper](https://www.jstor.org/stable/2118545?seq=1#page_scan_tab_contents)). 


By the Yomdin-Gromov parametrization lemma, there exists a finite family $(\phi\_i : ]0,1[^{d\_i} \rightarrow S \cap K)\_{i \in I}$ of differentiable functions whose images cover $S \cap K$.


For each $i$, the function $f \circ \phi\_i$ is differentiable with vanishing differential, so that $f \circ \phi\_i = c\_i$ for some constant $c\_i$.
Thus $f(S \cap K) \subseteq \{ c\_i \ | \ i \in I \}$ is a finite set. 


EDIT: I just realized one could avoid the use of the Yomdin-Gromov parametrization lemma. Namely, $f(S \cap K)$ is a definable subset of $\mathbb{R}$ wrt the aforementioned o-minimal structure. It is therefore a finite union of points and intervals. Since it has zero Lebesgue measure by Morse-Sard's theorem, it must consist of finitely many points.


