Let $L$ be the language $L=\{<,=,+,-,\cdot, 0,1\}$, with standard interpretations, and let $\mathcal{A}=\langle\mathbb{R}, <,=,+,-,\cdot,0,1\rangle$. Let $S\subseteq\mathbb{R}^n$. Show that if $S$ is definable, then the topological closure of $S$, given as $$\bar{S}:=\{a\in\mathbb{R}^n:\text{every open ball centered at $a$, contains a point of $S$}\},$$ is also definable.
My attempt at a solution:
Clearly, the set $\bar{S}$ is the set of all points in $S$ as well as the boundary of $S$. So really, what we want is the union between the set $S$, and the set $S'$ which I use to denote the set of all boundary points of $S$. We already have that $S$ is definable by some $L$-formula in the given structure, say $\phi^{\mathcal{A}}$. It remains to show that the boundary $S'$ is also definable.
The boundary is the set of all points $a\in\mathbb{R}^n$, so that the following holds:
- $a\notin S$
- $\forall\epsilon>0\exists s\in S$ such that $d(a,s)<\epsilon$, where $d$ is the distance function between two points
Let's call the set of elements satisfying the latter property $B$. Clearly the set we are seeking is, $$\phi^{\mathcal{A}}\cup(\mathbb{R}^n\setminus\phi^{\mathcal{A}}\cap B).$$ It remains to show that $B$ is definable then. This is where I'm having some trouble. I can't see how to express this in my given language.
As you wrote in the question, the closure $\overline{S}$ is definable by $(\forall \varepsilon > 0) (\exists y\in S)\, d(x,y)<\varepsilon$. Expanding this into a first-order formula, given that $S$ is definable by $\varphi(x_1,\dots,x_n)$, we have:
$$\forall \varepsilon\, ((\varepsilon > 0) \rightarrow \exists y_1\dots \exists y_n\, (\varphi(y_1,\dots,y_n)\land ((x_1-y_1)\cdot (x_1-y_1) + \dots + (x_n-y_n)\cdot (x_n-y_n) < \varepsilon \cdot \varepsilon))).$$
You were on the right track in the comments, but you weren't expressing the bounded quantifiers correctly.