Separation of closed sets with distance $>0$ by function $f \in C_b^k(\mathbb{R}^d)$ I'm interested in the following problem on the separation of closed sets:

Let $A,B \subseteq \mathbb{R}^d$ be closed sets such that $$d(A,B) := \inf\{|x-y|; x \in A, y \in B\}>0.$$ Question: Does there exist a function $f \in C_b^k(\mathbb{R}^d)$ such that $$f^{-1}(\{0\}) = A \quad \text{and} \quad f^{-1}(\{1\})=B \tag{1}$$ ...?

Here, $C_b^k(\mathbb{R}^d)$ denotes the space of functions $f: \mathbb{R}^d \to \mathbb{R}$ with bounded derivatives up to order $k$, and $k \in \mathbb{N}$ is some fixed number.
It is a classical result that there exists a continuous function $f$ satisfying $(1)$. With a bit more effort it can be shown that there exists a smooth function $f \in C^{\infty}(\mathbb{R}^d)$ which satisfies $(1)$; this is e.g. discussed in this question.
I strongly believe that the answer to my question is "yes" but I couldn't find any results concerning the boundedness of the derivates of Urysohn function $f$. The condition $d(A,B)>0$ means intuitively that the function $f$ does not need to be arbitrarily steep, and hence it would be naturally that $f$ can be chosen in such a way that its derivates are bounded.  However, it is not obvious for me how to prove this rigorously; the construction discussed in the question, which I linked above, does not seem to be helpful.
I would be happy about references and/or your thoughts on the question.
 A: I think I managed to prove the assertion; it turns out that it is possible to construct $f \in C_b^{\infty}(\mathbb{R}^d)$ satisfying $(1)$.

As $d(A,B)>0$ we can choose $\epsilon>0$ such that the sets $$A_{\epsilon} := A+\overline{B(0,\epsilon)} \qquad B_{\epsilon} := B+\overline{B(0,\epsilon)}$$ are disjoint. According to this result, there exists $h \in C^{\infty}(\mathbb{R}^d)$, $0 \leq h \leq 1$, such that $$h^{-1}(\{0\}) = A_{\epsilon} \quad \text{and} \quad h^{-1}(\{1\})=B_{\epsilon}.$$Now let $\varphi \in C_c^{\infty}(\mathbb{R}^d)$ be such that $\text{spt} \, \varphi = \overline{B(0,\epsilon)}$, $\int \varphi(y) \, dy=1$ and $\varphi \geq 0$. Define $$f(x) := (h \ast \varphi)(x) = \int_{\mathbb{R}^d} h(y) \varphi(x-y) \, dy, \qquad x \in \mathbb{R}^d.$$ Since $f$ is the convolution of a bounded continuous function with a smooth function with compact support, it is well known that $f$ is smooth and its derivatives are given by
$$\partial_x^{\alpha} f(x) = \int_{\mathbb{R}^d} h(y) \partial_x^{\alpha} \varphi(x-y) \, dy$$
for any multi-index $\alpha \in \mathbb{N}_0^d$. This implies, in particular, $\|\partial^{\alpha} f\|_{\infty} \leq \|\partial^{\alpha} \varphi\|_{L^1}< \infty$, and so $f \in C_b^{\infty}(\mathbb{R}^d)$. Moreover, as $\text{spt} \, \varphi \subseteq \overline{B(0,\epsilon)}$, it is obvious that $f(x)=0$ for any $x \in A$ and $f(x)=1$ for $x \in B$. It remains to check that $0<f(x)<1$ for any $x \in (A \cup B)^c$. To this end, we consider several cases separately:


*

*Case 1: $x \in \mathbb{R}^d \backslash (A_{\epsilon} \cup B_{\epsilon})$. Then $0 < h(x)<1$, and therefore we can choose $r \in (0,\epsilon)$ such that
$$0 < \inf_{|y-x| \leq r} h(y) \leq \sup_{|y-x| \leq r} h(y)<1;$$  this implies $$\begin{align*} f(x) &\leq \int_{\overline{B(x,r)}^c} \varphi(x-y) \, dy + \underbrace{\sup_{|y-x| \leq r} h(y)}_{<1} \int_{\overline{B(x,r)}}\varphi(x-y) \, dy \\ &< \int_{\mathbb{R}^d} \varphi(x-y) \, dy =1; \end{align*}$$ here we have used that $\text{spt} \, \varphi = \overline{B(0,\epsilon)} \supseteq \overline{B(x,r)}$. A very similar estimate shows $f(x)>0$.

*Case 2: $x \in A_{\epsilon} \backslash A$. We have $\overline{B(x,\epsilon)} \cap A^c \neq \emptyset$, and therefore there exist $y \in \mathbb{R}^d$ and $r>0$ such that $$\overline{B(y,r)} \subseteq A^c \cap \overline{B(x,\epsilon)}.$$ In particular $$0 < \inf_{z \in \overline{B(y,r)}} h(z) \leq \sup_{z \in \overline{B(y,r)}} h(z) < 1.$$Since $\text{spt} \, \varphi = \overline{B(0,\epsilon)}$, it follows very similar as in the first case that $0<f(x)<1$.

*Case 3: $x \in B_{\epsilon} \backslash B$. This works as case 2.


Consequently, we have shown that $f$ has all the desired properties.
