If $f,g: X\to Y$ be two functions continuous on $X$ then show that $\{x:f(x)=g(x)\}$ is closed in $X$ 
Problem. Let $(X,\mathcal{T}_X)$ and $(Y,\mathcal{T}_Y)$ be two topological spaces and $f,g:X\to Y$ such that $f$ and $g$ both are continuous on $X$. Show that the set $E:=\{x:f(x)=g(x)\}$ is closed in $X$.

My Attempt

Let $\mathscr{S}:=\{V:(V\ \text{is closed in}\ Y)\land ((f(x)=g(x))\implies f(x)\in V)\}$. If $\mathscr{S}=\emptyset$ then we have nothing to prove since then $E=\emptyset$ and is indeed closed in $X$. So let $\mathscr{S}\ne \emptyset$. Then observe that,

*

*$\displaystyle\bigcap_{\alpha\in \mathscr{S}}V_\alpha$ is the smallest closed set in $\mathscr{S}$.


*$\displaystyle\bigcap_{\alpha\in \mathscr{S}}V_\alpha\subseteq f(X)$
Now observe that, $$f(x)\in f(E)\implies f(x)=g(x)\implies f(x)\in \displaystyle\bigcap_{\alpha\in \mathscr{S}}V_\alpha$$

At this point I am stuck. I actually wanted to show that $f(E)=\displaystyle\bigcap_{\alpha\in \mathscr{S}}V_\alpha$ but I am unable to do that. So my questions are,

*

*Is there any way to show that $f(E)=\displaystyle\bigcap_{\alpha\in \mathscr{S}}V_\alpha$?


*If not, then can some other way of proving this result be suggested?
 A: Here’s an counterexample when $Y$ is not Hausdorff. As I noted in the comments, there’s a proof of the result here when $Y$ is Hausdorff.
Let $A=\left\{\frac1n:n\in\Bbb Z^+\right\}$. Let $X=\{0\}\cup A$ with the topology that it inherits from $\Bbb R$. Let $p$ and $q$ be distinct points not in $X$, and let $Y=\{p,q\}\cup A$. For $n\in\Bbb Z^+$ let $B_n(p)=\{p\}\cup\left\{\frac1k:k\ge n\right\}$ and $B_n(q)=\{q\}\cup\left\{\frac1k:k\ge n\right\}$. Then
$$\{x:x\in A\}\cup\{B_n(p):n\in\Bbb Z^+\}\cup\{B_n(q):n\in\Bbb Z^+\}$$
is a base for a topology $\tau$ on $Y$. This topology is not Hausdorff: $p$ and $q$ do not have disjoint open nbhds.
Let 
$$f:X\to Y:x\mapsto\begin{cases}
x,&\text{if }x\ne 0\\
p,&\text{if }x=0
\end{cases}$$
and
$$g:X\to Y:x\mapsto\begin{cases}
x,&\text{if }x\ne 0\\
q,&\text{if }x=0\;;
\end{cases}$$
I’ll leave it to you to check that $f$ and $g$ are continuous, but $\{x\in X:f(x)=g(x)\}=A$, which is not closed in $X$.
A: Give $Y$, this statement is true for all $X,f,g$ if and only if $Y$ is Hausdorff.
Let $\Delta =\{(y_1,y_2)\in Y\times Y\mid y_1=y_2\}$ be the diagonal. When is $\Delta$ closed in $Y\times Y$? 
If it is not closed, we can let $X_1=Y\times Y$ and $f,g:X_1\to Y$ by $f(y_1,y_2)=y_1$ and $g(y_1,y_2)=y_2$, and then $\Delta = \{x\in X_1\mid f(x)=g(x)\}$ is not closed, so the above theorem is not true.
If, on the other hand, $\Delta$ is closed, show that $h(x)=(f(x),g(x)):X\to Y\times Y$ is continuous, and that thus $\{x\mid f(x)=g(x)\}=h^{-1}(\Delta)$ is closed.
Now you just need to prove:

$Y$ is Hausdorff if and only if $\Delta$ is closed. 

It's a good usage of point-set topology definitions. Easier to prove that $Y\times Y\setminus\Delta$ is open in $Y\times Y$ if and only if $Y$ is Hausdorff:
Proof:
If $Y$ is Hausdorff, let $(y_1,y_2)\in Y\times Y\setminus\Delta$. Then, since $y_1\neq y_2$, you have open sets $U,V\subset Y$ so that $y_1\in U,y_2\in V$ and $U\cap V=\emptyset$. But that means $U\times V\subseteq Y\times Y\setminus\Delta$. Thus a neighborhood of $(y_1,y_2)$ is in our set, so $Y\times Y\setminus\Delta$ is open.
On the other hand, if $Y\times Y\setminus\Delta$ is open, then, by the definition of the product topology, we can find an expression:
$$Y\times Y\setminus\Delta = \bigcup_{i\in I} U_i\times V_i$$
with the $U_i,V_i$ being pairs of open sets. We can see that $U_i\cap V_i$ must be empty (or $U_i\times V_i$ contains an element of $\Delta$.) 
For $y_1\neq y_2$, then, $(y_1,y_2)\in Y\times Y\setminus\Delta$, and thus there are a pair of disjoint open sets $U_i,V_i$ with $y_1\in U_i$ and $y_2\in V_i$. Hence $Y$ is Hausdorff.

So we've learned:


*

*If $Y$ is Hausdorff, the result is true for any $X,f,g$.

*If $Y$ is not Hausdorff, there exists an $X$ and $f,g$ so that the stated theorem is not true.

A: Another example when $Y$ is not $T_2$:
Suppose let us take $Y=R$ with the topology consist of only $R$ and $\phi$. Let us take $f: Y \rightarrow Y$ such that $f(x)=x$ and $g:Y \rightarrow Y$ such that$g(x)=-x$. Then obviously $f$ and $g$ are continuous as the only nonempty open set of (co-domain)$Y$ is $Y$ itself and whose inverse image is $Y$ in both case. Now the set on which $f$ and $g$ agrees is {0} which is not closed in $Y$.
A: Take $X = \Bbb{R}$ the real line  and $Y =  \{1,2,3\}$ in the indiscrete topology. Then every map from $X$ to $Y$ will be continuous here.   Let $f(x)=1$ be the constant map and g any non constant map where inverse image $g^{-1}(1)=(-2,2)$. Then both $f$ and $g$ are continuous but $E =(-2,2)$, which is not closed.
