Dimension of a semialgebraic set equals the dimension of its closure. I am trying to prove that if $X \subset \mathbb{R}^{n}$ is semialgebraic, then $\operatorname{dim}X = \operatorname{dim}\overline{X}$, where the dimension of a semialgebraic set is the supremum of the dimensions of the elements of a finite semi-algebraic stratification of $X$. The reference is the book from Benedetti and Risler, Semialgebraic and Real Algebraic Sets.
For context, an stratification of a set $X$ is a partition of $X$ into locally closed analytic submanifolds of $\mathbb{R}^{n}$ s.t. $A_{i} \cap \overline{A_{j}} \neq \emptyset$, then $A_{i} \subset \overline{A_{j}}$ and $\operatorname{dim} A_{i} < \operatorname{dim} A_{j}$.
The stratification theorem says that given any finite family $\{P_{1},...,P_{k}\} \subset \mathbb{R}[X_{1},...,X_{n}]$, we can extend it to a family $\{P_{1},...,P_{R}\}$ s.t. the sets of the type $\displaystyle \bigcap_{j=1}^{R} \{x \in \mathbb{R}^{n}: P_{j}(x) s_{j} 0\}$ (called elementary sets) are connected, where $s_{j}$ is $<,=$ or $>$, and the closure of every such set is obtained by relaxing the inequalities. Also, elementary sets form a stratification of $\mathbb{R}^{n}$. By the first structure theorem for semialgebraic sets (where we can decompose it as graphs of maps and bands determined by these graphs), any semialgebraic set admits an stratification.
The book says that the proposition follows from the property about the closure of elementary sets, but I don't understand how.
I tried to analyse what happens with a stratification of $X$ when we take the closure of $X$, but the result is not a stratification of $\overline{X}$. I appreciate any help.
 A: Let us prove the following lemma:

Lemma: let $X_1, \ldots, X_n$ be semialgebraic subsets of $\mathbb{R}^n$. Then $$ \mathrm{dim}\, \bigcup_{i=1}^n X_i = \max_{i=1..n} \mathrm{dim}\, X_i. $$
Proof: using Theorem 2.4.4, we can produce a stratification $\mathcal{S}$ of $\mathbb{R}^n$ by elementary sets which is compatible with each $X_i$. In other words, each $X_i$ is a union of strata of $\mathcal{S}$. Let $\mathcal{S}_i$ denote the set of strata of $\mathcal{S}$ lying in $X_i$ and $\mathcal{S}'$ the set of strata in $\bigcup_{i=1}^n X_i$. Then by definition of the dimension, we have
$$ \mathrm{dim}\, X_i = \max_{S \in \mathcal{S}_i} \mathrm{dim}\, S\ \mbox{ and }\ \mathrm{dim}\, \bigcup_{i=1}^n X_i = \max_{S \in \mathcal{S}'} S. $$
But it is clear that $\mathcal{S}' = \bigcup_{i=1}^n \mathcal{S}_i$.

Now consider $X$ a semialgebraic subset of $\mathbb{R}^n$ and $\mathcal{S}$ a stratification of $\mathbb{R}^n$ compatible with $X$. By Theorem 2.4.4, we can assume that the strata of $\mathcal{S}$ are elementary sets satisfying a kind of Thom's Lemma, that is the closure of the strata are obtained by relaxing the inequalities. Now,
$$ X = \bigcup_{S \in \mathcal{S}'} S\ \mbox{ and }\ \overline{X} = \bigcup_{S \in \mathcal{S}'} \overline{S},$$
for some subset $\mathcal{S}'$ of $\mathcal{S}$. Since we can obtain each stratum $S$ by relaxing inequalities, we have $\mathrm{dim}\, S = \mathrm{dim}\, \overline{S}$. We can conclude by the above lemma.
A: The other answer is good (I've upvoted it), and I think a slightly more explicit approach could be useful too.
Suppose $\{P_1,\cdots,P_R\}$ is a stratifying family and let $X$ be an elementary set given by $\{x\in\Bbb R^n\mid P_i(x)\ s_i\ 0\}$. Then $\overline{X}$, the closure of $X$, is given by $\{x\in\Bbb R^n\mid P_i(x)\ s_i'\ 0\}$, where $s_i'$ is $\geq,=,\leq$ depending on whether $s_i$ is $>,=,<$ respectively. This can be written as a union of strata in the following way: for each $i$ such that $s_i'$ is $\geq$ (respectively $\leq$), replace it with $>$ or $=$ (respectively $<$ or $=$). All possible choices here are strata by definition, and their union is $\overline{X}$ from the fact that $\overline{X}$ is obtained by relaxing inequalities.
Now apply the first property of a stratification: if $A,B$ are two elements of a stratification and $A\cap \overline{B}\neq\emptyset$, then $A\subset \overline{B}$ and $\dim A< \dim B$. Therefore all the extra pieces we picked up by taking the closure have smaller dimension than $X$, and so $\dim \overline{X}=\dim X$ by the definition of the dimension of a semi-algebraic set as the maximum dimension of a piece of the stratification.

Let's do an example to see how this works. Consider $\Bbb R^2$ where our family is $\{x,y\}$. Then we have $3^2=9$ pieces of the stratification: the four open quadrants like $x>0,y>0$, the four axis rays like $x=0,y>0$, and the origin $x=y=0$. If we want to compute the closure of the first quadrant $\{x>0,y>0\}$, we get $\{x\geq0,y\geq 0\}$ which splits in to a union of the following strata: $\{x>0,y>0\}$, $\{x=0,y>0\}$, $\{x>0,y=0\}$, $\{x=y=0\}$. These are locally closed submanifolds of dimension $2$, $1$, $1$, $0$, respectively, verifying our claim.
