Graph of a non-continuous function is closed 
Exercise. Let $\ f\colon\mathbf R\to\mathbf R$ be defined by
  $$f(x)=\begin{cases}\frac{1}{x},\ x>0\\0,\ x\leq 0\end{cases}$$
  Prove that the graph $\Gamma_f:=\{(a,f(a)):a\in\mathbf R\}$ of $f$ is  a closed subset of $(\mathbf R^2,d)$.

I'm not sure about the following. I'd appreciate if you would check if it's right. 
Lemma. If $f$ is continuous, the graph $\Gamma_f$ is closed.
Proof. Let $\gamma_n:=(a_n,f(a_n))\subset\Gamma_f$ a sequence of $\Gamma_f$ that converges to $\gamma:=(a,b)$. It suffices to show that $\gamma\in\Gamma_f$ to conclude that $\Gamma_f$ is closed (this is one of the characterizations of a closed set).
We know that $\gamma_n\to\gamma$ as $n\to\infty$ iff $a_n\to a$ and $f(a_n)\to b$ as $n\to\infty$. Since $a\in X$, and since $f$ is continuous, we have that $b=\lim_n f(a_n)=f(\lim_n a_n)=f(a)$. Thus, $\gamma=(a,f(a))\in\Gamma_f$.$\quad\quad\ \quad\blacksquare$ 
Proof of the exercise. We have that
$$\Gamma_f:=\{(a,f(a)):a\in\mathbf R\}=\underbrace{\{(a,f(a)):a>0\}}_{\Gamma_{f|_{X_1}}}\cup\underbrace{\{(a,f(a)):a\leq 0\}}_{\Gamma_{f|_{X_2}}}$$
Since $f$ is continuous in both sets $X_1=\{x:x>0\}$ and $X_2=\{x:x\leq 0\}$, by the Lemma $\Gamma_{f|_{X_1}}$ and $\Gamma_{f|_{X_2}}$ are closed, where $f|_X$ denote the restriction of $f$ to $X$. Hence, since "the union of a finite collection of closed sets is closed", the result holds. $\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\blacksquare$
If you show me other possible way to solve it it would be great. Thanks! 
 A: That's a very nice little argument! Alas it's totally wrong, but it's still very nice; in various contexts I'd love to have students give me wrong arguments like that.
First, it really is wrong. Proof that it's wrong: Define $g:\mathbb R\to\mathbb R$ by $g(x)=1$ for $x>0$, $g(x)=0$ for $x\le0$. The graph of $g$ is certainly not closed, but your argument applies to $g$ just as well as to the given function $f$. Arguments that suffice to prove falsehoods are bad.
The problem is that saying "$E$ is closed" is actually meaningless. What one should actually say is "$E$ is a closed subset of $Y$" for some $Y$; whether this is true or not depends on $Y$ as well as on $E$. Yes, people say "$E$ is closed" all the time, but only in contexts where what $Y$ is meant is clear. Here it matters, because $Y$ is shifting.
A correct statement of your lemma would then be "If $f:X\to Y$ is continuous then the graph of $f$ is a closed subset of $X\times Y$". That's true, and the proof you give is fine.
The problem is later when you say the union of two closed subsets is closed. It's true that the union of two closed subsets of $Y$ is a closed subset of $Y$. But that doesn't apply here:
If you use the more carefully phrased version of the lemma you see you've written the graph of $f$ as the union of a closed subset of $(-\infty,0]\times\mathbb R$ and a closed subset of $(0,\infty)\times\mathbb R$. True, but irrelevant; you want to show the graph of $f$ is a closed subset of $\mathbb R\times\mathbb R$. You haven't shown that either set is a closed subset of $\mathbb R\times\mathbb R$.
The union of a closed subset of this and a closed subset of that is nothing in particular.
