How to formalize "show that $[a,b]$ is closed in $\mathbb{R}$"? I'm trying to learn how to write proofs as I go in studying math (for fun) and I'm even stuck at something as simple as this:
"Show that $[a,b]$ is closed in $\mathbb{R}$".
I understand that closed sets are closed if their complements are open; it makes sense that $(-\infty, a)$ and $(b, \infty)$ are open in $\mathbb{R}$, as all of their points are enclosed within the intervals (given any point belonging to either of the two intervals, there will be a ball which of a radius $r$ which would still be a part of that interval).
Any hints on how to formalize this/write a proper proof?
 A: It's more or less formally chaining together what you've already said here.

To show $[a,b]$ is closed, we will show $[a,b]^c = (-\infty,a) \cup (b,\infty)$ is open. Let $x \in (-\infty,a) \cup (b,\infty)$. Then two cases arise:

*

*Case $1$: Suppose $x \in (-\infty,a)$. Then $\exists r > 0$ such that $(x-r,x+r) \subseteq (-\infty,a)$. Since the former is an open ball, this works fine.

*Case $2$: Suppose $x \in (b,\infty)$. [...]

Hence, we have shown that, given $x \in (-\infty,a) \cup (b,\infty)$, there is an open ball which contains $x$ and which is completely contained in $(-\infty,a) \cup (b,\infty)$, making this set open, and hence its complement closed.

Some details I left to you to think about as you fill in the proof, some minor, some not:

*

*Why do we have the casework described? (That is, where do the cases come from, and is it enough to consider these cases?)

*How might we justify the claim about the existence of $r$? (Hint: It would be simplest to just pick a specific $r$ you know can work; say, half the distance between $x$ and $a$.)

*How might we justify the set inclusion? It might seem obvious, but is it? Is it enough to only have it contained in only one of the two unioned sets?

*Fill in the parallel logic for case $2$.


Digression: You might also see that you can generalize the idea very easily to: the union of finitely many open intervals in $\mathbb{R}$ is also open. An even stronger fact is true about arbitrary unions (and of open sets, not just intervals), be they countable or uncountable unions, which becomes particularly important in the study of topology. It also makes this proof significantly simpler if you realize that each of $(-\infty,a)$ and $(b,\infty)$ are open and can use it as a given.

