\section{Continuity}

\news[Definitions and basic properties]
The most general sort of function that we might be interested in is a
function from one metric space, say $(M_0,d_0)$, to another, say
$(M_1,d_1)$.  Let $f$ be such a function.  If $x_i\in M_i$, then the
expression 
$$\lim_{x\to x_0}f(x)=x_1$$
has the obvious meaning.  If $M_1$ is one of the spaces $\R^k$, then
we have theorems about limits of sums and scalar multiples of
functions, theorems corresponding to the theorems about sequences.

We shall say that $f:M_0\to M_1$ is \defn{continuous at $x_0$} if
$$\lim_{x\to x_0}f(x)=f(x_0).$$
If $A\included M_0$, then $f$ is \defn{continuous on $A$} if it is
  continuous at every point of $A$.  Finally, $f$ is
  \defn{continuous}, simply, if it is continuous on $M_0$.

The following is proved like the earlier theorem about limits of
functions and sequences.

\begin{lemma*}
 A function $f:M_0\to M_1$ is continuous if and only if
$\lim_{n\to\infty}f(x_n)$ exists, and is 
$$f(\lim_{n\to\infty}x_n),$$
 whenever $(x_n:n\in\N)$ is a convergent sequence in $M_0$.
\end{lemma*}

\begin{theorem*}
  Continuity is preserved under composition.
\end{theorem*}

\begin{proof}
  Let $(M_i,d_i)$ be metric spaces ($i<3$), let $f:M_0\to M_1$ be
  continuous at $a$, and let
  $g:M_1\to M_2$ be continuous at $f(a)$.  We shall show that $g\circ
  f$ is continuous at $a$.  Let $U$ be a neighborhood of $g(f(a))$.
  Then $f(a)$ has a neighborhood $V$ such that
$$x\in V\implies f(x)\in U.$$
Then also $a$ has a neighborhood $W$ such that
$$y\in W\implies f(y)\in V\implies g(f(y))\in U,$$
which means $g\circ f$ is continuous at $a$.
\end{proof}

\news[Functions into Euclidean spaces]

If $i<k$, then there is a \defn{coordinate map},
$$\tuple a\longmapsto a_i:\R^k\to \R,$$
which we may denote $\pi_i$.  (If $k=1$, then $\pi_0$ is just the
identity-function on $\R$.)

\begin{theorem*}
  The projection-maps $\pi_i$ are continuous.
\end{theorem*}
\begin{proof}
  If $\tuple a\in \R^k$, and $\tuple x\in (\tuple a;\epsilon)$, then
  $\abs{a_i,x_i}<\epsilon$. 
\end{proof}

\begin{theorem*}
  A function $f$ into $\R^k$ is continuous if and only if the
  compositions $\pi_i\circ f$ are continuous.
\end{theorem*}

\begin{proof}
  The `only-if' part follows from the last two theorems.  For the `if'
  part, if $x$ is in the domain of $f$, and $\epsilon>0$, then for
  each $i$ less than $k$, there is a neighborhood $U_i$ of $x$ such
  that 
$$y\in U_i\implies \abs{\pi_i\circ f(y)-\pi_i\circ
    f(x)}<\epsilon/\radix k.$$
Let $U$ be the intersection of the $U_i$.  Then $U$ is a neighborhood
    of $x$, and
$$y\in U\implies f(y)\in B(f(x);\epsilon).$$
This completes the proof.
\end{proof}

\begin{theorem*}
  Let $f$ and $g$ be continuous functions into $\R^k$, and $h$ be a
  continous function into $\R$, all defined on the same metric space.
  Then $f+g$ and $h\cdot f$ are continuous; so is $1/h$ wherever $h$
  is not $0$.
\end{theorem*}

\begin{exercise}
  Prove the theorem.
\end{exercise}

\news[Topology]

A function $f:A\to B$ induces the functions
\begin{align*}
  X\mapsto \{f(x):x\in X\}&:\pow A\to\pow B,\\
 Y\mapsto \{x\in A:f(x)\in Y\}&:\pow B\to \pow A.
\end{align*}
These are denoted $f$ and $f\inv$ respectively.
Here $f(X)$ is the \defn{image} of $X$, and $f\inv Y$ is the
\defn{inverse image} of $Y$, under $f$. 

\begin{lemma*}
  If $f:A\to B$ is a function, then $f(f\inv(Y))\included Y$ for all subsets
  $Y$ of $B$; also, $f\inv(Y\comp)=(f\inv(Y))\comp$.
\end{lemma*}

\begin{theorem*}
The following are equivalent statements about a function between
metric spaces: 
\begin{enumerate}
    \item\label{cond:cont}
 The function is continuous.
\item\label{cond:open}
Under the function, inverse images of open sets are open.
\item\label{cond:closed}
Under the function, inverse images of closed sets are closed.
\end{enumerate}
\end{theorem*}

\begin{proof}
  Say $f:M_0\to M_1$ is a function of metric spaces.

\pref{cond:cont}$\implies$\pref{cond:open}.
Suppose $f$ is continuous.  Let $Y$ be an open subset of
$M_1$.  If $x\in f\inv(Y)$, then $f(x)\in Y$, so $x$ has a
neighborhood $U$ such that 
$$y\in U\implies f(y)\in Y.$$
Therefore $U\included f\inv(Y)$, so $f\inv(Y)$ is a neighborhood of
$x$.  Thus $f\inv(Y)$ is a neighborhood of all of its points, so it is
open.   

\pref{cond:open}$\implies$\pref{cond:cont}.
Suppose $f\inv$ takes
  open sets to open sets.  If $x\in M_0$, and $U$ is an open
  neighborhood of $f(x)$, then 
$$y\in f\inv(U)\implies f(y)\in U$$
by the last lemma.
But $f\inv(U)$ is a neighborhood of $x$ (since it contains $x$ and is
open).  Thus $f$ is continuous at $x$.

\pref{cond:open}$\iff$\pref{cond:closed}.  Clear by the lemma.
\end{proof}

\news[Continuous functions on compact sets]

\begin{theorem*}
  Under a continuous function, the image of a compact set is compact.
\end{theorem*}

\begin{exercise}
  Prove the theorem.
\end{exercise}

\begin{theorem*}
  If $f:M\to\R$ is continuous, and $M$ is compact, then $f$ attains a
  minimum and a maximum value.
\end{theorem*}

\begin{proof}
  $f(M)$ is compact, hence closed and bounded; so $f(M)$ contains its
  extrema. 
\end{proof}

\news[Additional exercises]

\begin{enumerate}
  \item
If $x\in\R$, does $\displaystyle\lim_{n\to\infty}\displaystyle\frac{x^n}{n!}$ exist?
\item
What about $\displaystyle\lim_{n\to\infty}(\sqrt{n^2+1}-n)$?
\item
Define sequences $(a_n)$ and $(b_n)$ by:
\begin{itemize}
  \item
$a_0=3$ and $b_0=2$.
\item
$a_n,b_n\in\Z$.
\item
$a_{n+1}+b_{n+1}\radix 2=(a_n+b_n\radix 2)^2$.
\end{itemize}
Prove that $a_n^2-2b_n^2=1$, and then that
$\displaystyle\lim_{n\to\infty}\displaystyle\frac{a_n}{b_n}=\radix 2$. 
\item
Prove that every sequence in a compact space has a convergent
subsequence. 
\item
Prove that complete subspaces of metric spaces are closed, and that
closed subsets of complete spaces are complete.
\item
If $f:\R^2\to \R$, and $\lim_{(0,0)}f$ exists, and
$\lim_{y\to 0}f(x,y)$ 
exists for each $x$, then $\displaystyle\lim_{x\to 0}(\displaystyle\lim_{y\to
  0}f(x,y))=\displaystyle\lim_{(0,0)}f$. 
\item
Define $f(x,y)=
\begin{cases}
  \displaystyle\frac{x^2-y^2}{x^2+y^2},&\text{ if
  }(x,y)\neq(0,0);\\
0,&\text{ if }(x,y)=(0,0).
\end{cases}
$
Find $\displaystyle\lim_{y\to 0}f(x,y)$.  What can you conclude about
$\displaystyle\lim_{(0,0)}$? 
\item
If $f:\R^k\to\R$ is continuous at $\tuple a$, show that each function
$$x\mapsto f(a_0,\dots,a_{n-1},x,a_{n+1},\dots,a_{n-1}):\R\to \R$$ 
is continuous at $a_i$.  Is the converse true?
\item
If $f:\R^k\to\R$ is continuous, show that $\{\tuple a\in\R^k:f(\tuple
a)=0\}$ is closed.
\item
If $f:\R\to\R$ is continuous at $1$, and $f(1)=1$, and
$f(x+y)=f(x)+f(y)$ for all $x$ and $y$ in $\R$, show that $f(x)=x$ for
all $x$ in $\R$.
\item
Discuss the continuity of the following functions:
\begin{enumerate}
  \item
$f(x)=
    \begin{cases}
      0,&\text{ if }x\text{ is irrational};\\
1,&\text{ if }x\text{ is rational}.\\
    \end{cases}
$
\item
$x\mapsto xf(x)$.
\item
$g(x)=
    \begin{cases}
      0,&\text{ if }x\text{ is irrational};\\
\displaystyle\frac 1n,&\text{ if }x=\displaystyle\frac mn,\text{ where
}\gcd(m,n)=1\text{ and }n>0.\\
    \end{cases}
$
\item
$h(x)=
    \begin{cases}
      0,&\text{ if }x=0;\\
\sin\displaystyle\frac 1x,&\text{ if }x\neq0.\\
    \end{cases}
$
\item
$x\mapsto xh(x)$.
\end{enumerate}
\item
If $f\circ f$ is continuous, must $f$ be continuous?
\item
Suppose $f:[0,1]\to\R$ is continous, and 
$$g(x)=
    \begin{cases}
      f(x),&\text{ if }x=0;\\
\displaystyle\max_{[0,x]}f,&\text{ if }x\in(0,1].\\
    \end{cases}
$$
Show that $g$ is continous.
\end{enumerate}

\news[Connectedness]

\begin{lemma*}
  If $f:\R\to\R$ is function continuous at $a$, and $f(a)>0$, then there is
  a positive $\delta$ such that 
$$\abs{a-x}<\delta\implies f(x)>0$$
for all $x$ in $\R$. 
\end{lemma*}

\begin{theorem*}[Bolzano]
  If $f:[a,b]\to\R$ is continuous, and $f(a)f(b)<0$, then $f(x)=0$ for
  some $x$ in $(a,b)$.
\end{theorem*}

\begin{corollary*}[Intermediate Value]
  If  $f:[a,b]\to\R$ is continuous, and $c$ is between $f(a)$ and
  $f(b)$, then $f(x)=c$ for some $x$ in $(a,b)$.
\end{corollary*}

\begin{exercise}
  Prove the lemma, theorem and corollary.
\end{exercise}

In fact the Intermediate Value Theorem will follow also from the
following considerations.

\begin{lemma*}
  Every open subset of $\R$ is a disjoint union of open intervals.
\end{lemma*}

\begin{proof}
  Say $U$ is an open subset of $\R$.  If $x\in U$, let $U_x=(a,b)$,
  where
  \begin{align*}
    a&= \inf\{y\in U:[y,x]\included U\};\\
    b&= \sup\{z\in U:[x,z]\included U\}.\\
  \end{align*}
Note that $a$ and $b$ are well-defined elements of $\R\setminus U$,
and $U_x\included U$ (why?).
Also, if $y\in U$, and $U_x\cap U_y\neq\emptyset$, then $U_x=U_y$
(why?).  Hence $U=\bigcup\{U_x:x\in U\}$, and the union is disjoint
(in the sense that two elements of $\{U_x:x\in U\}$ are either
disjoint or equal).
\end{proof}

\begin{exercise}
  Supply the details of the proof.
\end{exercise}

A union of two or more disjoint \emph{open} intervals should be called
\tech{disconnected}; but a disjoint union like $(0,1]\cup (1,2)$ is
  the \tech{connected} set $(0,2)$.  A precise definition agreeing
  with these ideas is the following.

  \begin{definition*}
    A subset $X$ of a metric space is \defn{connected} if, whenever
    $A_0$ and $A_1$ are disjoint open sets, and $X\included A_0\cup
    A_1$, then $X\included A_i$ for some $i$.  A set that is not
    connected is \defn{disconnected}.
  \end{definition*}

  \begin{lemma*}
    Open intervals of $\R$ are connected.  If $X$ is a connected subset of
    $\R$, and $a<b$, and $a,b\in X$, then $[a,b]\included X$.
  \end{lemma*}

  \begin{exercise}
    Prove the lemma.
  \end{exercise}

  \begin{theorem*}
    The continuous image of a connected set is connected.
  \end{theorem*}

  \begin{proof}
    Suppose $f$ is a continuous function, and $f(X)$ is disconnected.
    Then $X\included A\cup B$, where $A$ and $B$ are disjoint open
    sets, and $X\cap A$ and $X\cap B$ are non-empty.  Then $X$ is a
    subset of the disjoint union $f\inv(A)\cup f\inv(B)$, but $X$ is
    not a subset of $f\inv (A)$ or of $f\inv (B)$; so $X$ is
    disconnected. 
  \end{proof}

  \begin{corollary*}[I.V.T. for continuous real-valued functions]
Suppose $f$ is a continuous real-valued function on a connected set
$X$.  If $a<b$, and $a,b\in f(X)$, then $[a,b]\included f(X)$.
  \end{corollary*}

  \begin{exercise}
    Prove the corollary.
  \end{exercise}

An alternative approach to connectedness is the following.  

A function is called \defn{two-valued} if its image is a set of size
$2$ or less.  One may then suppose that the image is a subset of
$\{0,1\}$.  Every metric on this set determines the same open sets;
indeed, every subset of $\{0,1\}$ will be open.  So it makes sense to
speak of a \defn{continous} two-valued function.

\begin{theorem*}
  A subset $X$ of a metric space is connected if and only if every
  continuous two-valued function on $X$ is constant.
\end{theorem*}

\begin{proof}
  If $X$ is connected, and $f:X\to\{0,1\}$ is continuous, then $f(X)$
  is connected, so $f(X)$ has at most one element.  If $X$ is not
  connected, so that  $X\included A\cup B$, where $A$ and $B$ are
  disjoint open sets, each having non-empty intersection with $X$,
  then the function $f:X\to\{0,1\}$ given by
$$f(x)=
  \begin{cases}
    0,&\text{ if }x\in X\cap A;\\
    1,&\text{ if }x\in X\cap B
  \end{cases}
$$
is continuous (why?), and its range is (all of) $\{0,1\}$.
\end{proof}

\begin{exercise}
  Supply the missing detail in the proof.
\end{exercise}

\begin{exercise}
  Prove that a metric space $(M,d)$ is connected if and only if the
  only subsets of $M$ that are \defn{clopen} (closed and open) are
  $\emptyset$ and $M$.  Explain why $[0,1]\cup[2,3]$ is disconnected,
  even though it has \emph{no} subsets that are both open and closed. 
\end{exercise}

\news[Uniform continuity and convergence]

To say that a function $f:M_0\to M_1$ is continuous means,
symbolically, 
$$(\forall x\in M_0)(\forall\epsilon>0)(\exists\delta>0)(\forall y\in
M_0)(y\in 
B(x;\delta)\to f(y)\in B(f(x);\epsilon)).$$
\emph{One} adjustment of the quantifiers makes no logical difference:
$$(\forall\epsilon>0)(\forall x\in M_0)(\exists\delta>0)(\forall y\in
M_0)(y\in
B(x;\delta)\to f(y)\in B(f(x);\epsilon)).$$
A further adjustment makes a logical change, and gives us a new
definition. 

\begin{definition*}
  A function  $f:M_0\to M_1$ is \defn{uniformly continuous} if
$$(\forall\epsilon>0)(\exists\delta>0)(\forall x\in M_0)(\forall y\in
  M_0)(y\in B(x;\delta)\to f(y)\in B(f(x);\epsilon)).$$
\end{definition*}
(The implication could also be written $d_0(x,y)<\delta\to
d_1(f(x),f(y))<\epsilon$. )
For continuous functions in general, the delta depends on $x$.  In
\emph{uniformly} continuous functions, one delta works for all $x$
(though delta still depends on epsilon).  It should be clear that
uniformly continuous functions are indeed continuous.

\begin{examples}
  \begin{enumerate}
    \item  Let $f:(0,1]\to\R$ be $x\mapsto 1/x$.  If $\delta>0$, let
  $x=\delta$.  Then $B(x,\delta)=(0,2\delta)$, so
  $f(B(x,\delta))=(1/\delta,\infty)$; in particular, no ball includes
  this image.  So $f$ is not uniformly continuous.
\item
Let $g:\R\to\R$ be $x\mapsto x^2$.  If $\delta>0$, let $x=1/\delta$.
Then $x+\delta/2\in B(x;\delta)$, but $g(x+\delta/2)-g(x)>1$, so
$g(x+\delta/2)\notin B(g(x);1)$.  So $g$ is not uniformly continuous.
  \end{enumerate}
\end{examples}

\begin{theorem*}
  Continuous functions on compact sets are uniformly continuous.
\end{theorem*}

\begin{proof}
  Suppose $f:M_0\to M_1$ is continuous, and $M_0$ is compact.  Say
  $\epsilon>0$.  (We have to find $\delta$.)  For each $x$ in $M_0$
  there is $\delta_x$ such that
$$y\in B(x;2\delta_x)\implies f(y)\in B(f(x);\epsilon/2).$$
By compactness, $M_0$ is covered by some collection
$\{B(x(i);\delta_{x(i)}): i\in I\}$, where $I$ is finite.  Let
$\delta$ be the least of the $\delta_{x(i)}$.  Say $x\in M_0$, and
$y\in B(x,\delta)$.  But $x\in B(x(i);\delta)$ for some $i$ in $I$; so
$y\in B(x(i),2\delta)$ by the triangle inequality.  Hence
$f(x),f(y)\in B(f(x(i)),\epsilon/2)$, so $f(y)\in B(f(x),\epsilon)$,
again by the triangle inequality.
\end{proof}

\news[Uniform convergence]

Suppose $f$ and $f_n$ are functions from $M_0$ to $M_1$ such that
$$f(x)=\lim_{n\to\infty}f_n(x)$$
for each $x$ in $M_0$.  Suppose the $f_n$ are continuous.  Then $f$ is
continuous if and only if
$$\lim_{y\to x}\lim_{n\to \infty}f_n(y)= \lim_{n\to \infty}\lim_{y\to
  x}f_n(y).$$
\begin{example*}
  Let $f_n$ be $x\mapsto x^n/(1+x^n):[0,\infty]\to\R$.  Then
$$\lim_{n\to\infty}f_n(x)=
  \begin{cases}
    0,&\text{ if }0\leq x<1;\\
1/2, &\text{ if }x=1;\\
1,&\text{ if }1<x.
  \end{cases}
$$
The $f_n$ are continuous; their limit is not.
\end{example*}

That a sequence of functions $f_n:M_0\to M_1$ \defn{converges} to $f$
(that is, $f_n\to f$) means
$$(\forall\epsilon>0)(\forall x\in M_0)(\exists N)(\forall m\in\N)
(m\geq N\to f_n(x)\in B(f(x);\epsilon)).$$
We say that the sequence \defn{converges uniformly} to $f$ if
$$(\forall\epsilon>0)(\exists N)(\forall x\in M_0)(\forall m\in\N)
(m\geq N\to f_n(x)\in B(f(x);\epsilon)).$$
\begin{theorem*}
  Continuity is preserved under uniform convergence.
\end{theorem*}

\begin{proof}
  Say functions $f_n:M_0\to M_1$ are continuous and converge uniformly
  to $f$.  Let $a\in M$ and $\epsilon>0$.  We have to find a positive
  $\delta$ such that
$$x\in B(a;\delta)\implies f(x)\in B(f(a);\epsilon).$$
Now, 
$$d_1(f(x),f(a))\leq d_1(f(x),f_m(x))+ d_1(f_m(x),f_m(a))
+d_1(f_m(a),f(a)).$$ 
By uniform convergence, there is $m$ large enough that for all $z$ in
$M_0$ we have $d_1(f(z),f_m(z))<\epsilon/3$.  By continuity of $f_m$
at $a$, there is a positive $\delta$ such that
$$x\in B(a;\delta)\implies f_m(x)\in B(f_m(a);\epsilon/3.$$
This $\delta$ is as desired.
\end{proof}

Say $f_n\to f$, and all functions are continuous.  The convergence
need not be uniform.

\begin{example*}
  $f_n(x)=
  \begin{cases}
    nx,&\text{ if }0\leq x\leq 1/n;\\
2-nx,&\text{ if }1/n<x\leq 2/n;\\
0,&\text{ if }2/n<x.
  \end{cases}
$
\end{example*}

\begin{theorem*}
  If a sequence of continuous real-valued functions $f_n$ on a compact
  space $M$ converges to a continuous limit $f$, and $f_{n+1}(x)\leq
  f_n(x)$ for all $x$ in $M$, then the convergence is uniform. 
\end{theorem*}

\begin{exercise}
  Prove the theorem.  Why is compactness needed?
\end{exercise}

\news[Contractions and fixed points]

Let $f$ be a function from a metric space $(M,d)$ to itself.  A point
$P$ in $M$ is a \defn{fixed point} of $f$ if $f(P)=P$.  The function
$f$ is a \defn{contraction} if there is some $\alpha$ (called the
\defn{contraction constant} in $[0,1)$ such that
$$d(f(x),f(y)\leq\alpha d(x,y)$$
for all $x$ and $y$ in $M$.

\begin{exercise}
  Prove that contractions are uniformly continuous.
\end{exercise}

\begin{theorem*}
  Contractions on complete spaces have unique fixed points.
\end{theorem*}

\begin{proof}
  Say $f:M\to M$ is a contraction with constant $\alpha$.  Let $a\in
  M$.  Define a sequence of points $a_n$ by $a_0=a$ and
  $a_{n+1}=f(a_n)$.  Then 
$$d(a_{n+2},a_{n+1})\leq \alpha d(a_{n+1},a_n)$$
so the sequence is Cauchy 
(why?); hence it has a limit, $b$.  This is a
  fixed point (why?), and is the only possible fixed point (why?).
\end{proof}

\begin{exercise}
  Supply the details of the proof.
\end{exercise}









