TITLE: Given a pair of continuous functions from a topological space to an ordered set, how to prove that this set is closed?
QUESTION [5 upvotes]: Given that $X$ is an arbitrary topological space, $Y$ is a totally ordered set in the order topology, and $f$, $g \colon X \to Y$ are continuous functions, how to show that the subset $A$ of $X$ given by 
$$ A \colon= \left\{ \ x \in X \  \colon \  f(x) \leq g(x) \ \right\} $$ 
is closed in $X$? 
Edit based on the answer by Hagen von Eitzen: 
Let $U \colon= \{ u \times v \in Y \times Y \ \colon \ u < v \ \}$. We show that $U$ is open in $Y \times Y$. 
Let $u \times v \in U$. Then $u < v$. 
Case I. If there is some $y \in Y$ such that $u < y < v$, then $u \times v \in (-\infty, y) \times (y, +\infty) \subset U$. 
Case 2. If $(u,v)$ is empty, then $u \in (-\infty, v)$ and $v \in (u, +\infty)$, and so $u \times v \in (-\infty, v) \times (u, +\infty)$. 
Moreover, if $a \times b \in (-\infty, v) \times (u, +\infty)$, then we must have $a < v$ and $b> u$. So $a \leq u < v \leq b$, which implies that $a < b$ and so $a \times b \in U$. 
Thus, $u \times v \in (-\infty, v) \times (u, +\infty) \subset U$. 
So $U$ is open in $Y \times Y$. 
Similarly, we can show that the set 
$$V \colon= \left\{ \ u \times v \in Y \times Y \ \colon \ u > v \ \right\}$$ is open in $Y \times Y$. 
Thus, it follows that the set $A \colon= \{ \ u \times v \in Y \times Y \ \colon \ u \leq v \ \}$ is closed in $Y \times Y$. 
Now since the maps $f \colon X \to Y$ and $g \colon X \to Y$ are continuous, so is the map $f \times g \colon X \to Y \times Y$ defined as
$$(f \times g)(x) \colon= f(x) \times g(x) \ \mbox{ for all } \ x \in X.$$
Thus, the inverse image under $f \times g$ of the set $A$ is closed in $X$. 
But 
$$ 
\begin{align} 
(f \times g)^{-1} (A) &= \left\{ \ x \in X \ \colon \ (f \times g)(x) \in A \ \right\} \\
&= \left\{ \ x \in X \ \colon \ f(x) \times g(x) \in A \ \right\} \\
&=  \left\{ \ x \in X \ \colon \ f(x) \leq g(x) \ \right\}.
\end{align} 
$$

REPLY [11 votes]: You can prove it directly from the definitions. Let $U=X\setminus A=\{x\in X:f(x)>g(x)\}$; we need only prove that $U$ is open. Let $x\in U$ be arbitrary; we’ll find an open nbhd of $x$ contained in $U$. Since $x\in U$, we know that $g(x)<f(x)$. There are now two cases.

There is some $a\in Y$ such that $g(x)<a<f(x)$. Let $$V=g^{-1}\big[(\leftarrow,a)\big]\quad\text{and}\quad W=f^{-1}\big[(a,\to)\big]\;.$$ Then $V\cap W$ is an open nbhd of $x$ (why?), and for each $y\in V\cap W$ we have $g(y)<a<f(y)$, so $V\cap W\subseteq U$.
The interval $\big(g(x),f(x)\big)$ in $Y$ is empty. Then let $$V=g^{-1}\big[(\leftarrow,f(x))\big]\quad\text{and}\quad W=f^{-1}\big[(g(x),\to)\big]$$ and argue almost exactly as in the first case.