Is it necessarily a closed subset?

Let
$f:X \rightarrow Y$ be a continuous map and $c \in Y$. Is $\{x \in X | f(x)=c\}$ necessarily a closed subset of $X$?

Attempt:

I was thinking about a contradiction. Can this be a counterexample? $f(x) = \frac{1}{x^2+1}$ is continuous on the whole real line and and the image of the set $[0,\infty)$ is the set $(0,1]$. So we have found a closed set, whose image under a continuos function is not closed(and nor open).

-
The question isn’t about the images of subsets of $X$: it’s about the inverse images of singleton subsets of $Y$. – Brian M. Scott Dec 18 '12 at 12:22
I believe it is not necessarily a closed subset. so what can be a decent counterexample? – John Lennon Dec 18 '12 at 12:25

If $Y$ is a $T_1$-space, so that singleton sets are closed, then $\{x\in X:f(x)=c\}$ is just the inverse image under $f$ of the closed set $\{c\}$ in $Y$, so by continuity of $f$ it is closed in $X$.

If there is a $c\in Y$ such that $\{c\}$ is not closed in $Y$, then $\{x\in X:f(x)=c\}$ need not be closed in $X$. For example, let $Y=\{0,1\}$, and let the open set of $Y$ be $\varnothing, \{1\}$, and $\{0,1\}$. ($Y$ is the Sierpiński space.) Note that $\{0\}$ is not open in $Y$, so $\{1\}$ is not closed. Define $f:\Bbb R\to Y$ by

$$f(x)=\begin{cases}0,&\text{if }x\le 0\\1,&\text{if }x>0\end{cases}\;;$$

it’s easy to check that $f$ is continuous, but $\{x\in\Bbb R:f(x)=1\}$ is not closed in $\Bbb R$.

-

You will not find a counterexample where $Y$ is the real line. This is because points are closed in the real line, and if $f$ is continuous then the inverse images of closed sets are closed. (Note that $\{ x \in X : f(x) = c \} = f^{-1} [ \{ c \} ]$.)

Instead, you should consider topological spaces where points are not closed.

A good example would be $Y = \{ 0 , 1 \}$ with the indiscrete (trivial) topology. Now let $X$ be any space which has a non-closed subset $A$, and consider the mapping $f : X \to Y$ defined by $$f(x) = \begin{cases} 0, &\text{if }x \notin A \\ 1, &\text{if }x \in A.\end{cases}$$ That $Y$ is given the trivial topology means that any function $X \to Y$ is continuous, and taking $c = 1$ we have that $\{ x \in X : f(x) = c \} = A$ is not closed by choice.

-