\documentclass[11pt]{article}
\usepackage{amsmath,amsfonts,tikz}

\title{Solutions to Homework 2}
\author{}
\date{}

\newcommand \Q {\mathbb Q}
\newcommand \R {\mathbb R}

\begin{document}
\maketitle

\begin{enumerate}


\item[1.5.]
Let $(X,d)$ be a metric space.  Prove the \emph{reverse triangle inequality}:
\[ |d(p,q) - d(p,r)| \le d(q,r). \]
Include an appropriate picture.

{\bf Solution:} The triangle inequality gives
\[ d(p,q) \le d(p,r) + d(q,r), \]
so
\begin{equation} \label{first_way}
d(p,q) - d(p,r) \le d(q,r).
\end{equation}
The triangle inequality also gives
\[ d(p,r) \le d(p,q) + d(q,r), \]
so
\begin{equation} \label{second_way}
d(p,r) - d(p,q) \le d(p,r).
\end{equation}
The left-hand side of \eqref{second_way} is the opposite of the left-hand side of \eqref{first_way}, so taken together they imply that
\[ |d(p,q) - d(p,r)| \le d(p,r). \]
Here are two pictures:
\begin{center}
\begin{tikzpicture}
% edited from ChatGPT
    % Define the points
    \coordinate (p1) at (0, 0);
    \coordinate (q1) at (4, 1);
    \coordinate (r1) at (3, 0);

    \coordinate (p2) at (5, 0);
    \coordinate (q2) at (8, 1);
    \coordinate (r2) at (9,0);

    % Draw the triangle
    \draw[thick] (p1) -- (q1) -- (r1) -- cycle;
    \draw[thick] (p2) -- (q2) -- (r2) -- cycle;

    % Mark the points
    \fill (p1) circle (2pt) node[below left] {$p$};
    \fill (q1) circle (2pt) node[above right] {$q$};
    \fill (r1) circle (2pt) node[below right] {$r$};
    \fill (p2) circle (2pt) node[below left] {$p$};
    \fill (q2) circle (2pt) node[above] {$q$};
    \fill (r2) circle (2pt) node[below right] {$r$};
\end{tikzpicture}
\end{center}
In the first we see that $d(p,q) - d(p,r)$ is shorter than $d(q,r)$.  In the second we see that $d(p,q) - d(p,r)$ is negative, but its absolute value is again shorter than $d(q,r)$.


\item[1.6.] Let $(X,d_X)$ and $(Y,d_Y)$ and $(Z,d_Z)$ be metric spaces.  Let $f\colon X \to Y$ be continuous at a point $p \in X$, and let $g\colon Y \to Z$ be continuous at $f(p)$.  Prove that $g \circ f$ is continuous at $p$.

{\bf Solution:} Let $\epsilon > 0$ be given.  Because $g$ is continuous at $f(p)$, there is an $\eta > 0$ such that $d_Y(f(p), r) < \eta$ implies $d_Z(g(f(p)), g(r)) < \epsilon$ for all $r \in Y$, and in particular for all $r$ of the form $g(q)$ for some $q \in X$.  Because $f$ is continuous at $p$, there is a $\delta > 0$ such that $d_X(p,q) < \delta$ implies $d_Y(f(p),f(q)) < \eta$ for all $q \in X$.  Thus $d_X(p,q) < \delta$ implies $d_Z(g(f(p)), g(f(q))) < \epsilon$ for all $q \in X$.


\item[1.8] Let $X$ be any set, and let $d_X$ be the \emph{discrete metric}
\[ d_X(p,q) = \begin{cases}
0 & \text{if $p = q$, or} \\
1 & \text{if $p \ne q$.}
\end{cases} \]
\begin{enumerate}
\item Prove that $d_X$ is a metric.

{\bf Solution:} Clearly $d$ is symmetric, $d(p,p) = 0$, and $d(p,q) > 0$ if $p \ne q$.  It remains to check the triangle inequality:
\[ d(p,r) \le d(p,q) + d(q,r) \]
for all $p,q,r \in X$.  We could analyze a series of cases ($p=q=r$, or $p=q \ne r$, etc.) and see that the triangle inequality holds in each case.  Or we could ask, how could the triangle inequality fail, knowing that all the distances that appear in it are either 0 or 1?  Only if the left-hand side is 1 and the right-hand side is 0.  But if the right-hand side is 0 then $d(p,q) = d(q,r) = 0$, so $p = q$ and $q = r$, so $p = r$, so the left-hand side is 0, not 1.

\item Let $(Y,d_Y)$ be another metric space (not necessarily discrete).  Prove that every map $f\colon X \to Y$ is continuous.

{\bf Solution:} Let $p \in X$ and $\epsilon > 0$ be given, and let $\delta = \frac12$.  If $d_X(p,q) < \delta = \frac12$ then $d_X(p,q) = 0$, so $p = q$, so $d_Y(f(p),f(q)) = 0 < \epsilon$.

\item Prove that a sequence $p_1, p_2, p_3, \dotsc \in X$ converges in the discrete metric if and only if it is eventually constant.

{\bf Solution:} Let $\ell \in X$ be the limit.  Apply the definition of convergence with $\epsilon = \frac12$, so there is an integer $N$ such that if $n \ge N$ then $d(p_n, \ell) < \epsilon = \frac12$, so $d(p_n, \ell) = 0$, so $p_n = \ell$.
\pagebreak


\item[2.1] Let $X = \R^2$ with the Euclidean metric.  Sketch the subset
\[ A = \{ (x,y) \in \R^2 : x \ne 0 \text{ or } y = 0 \}. \]
Prove that $A$ is neither open nor closed.
{\bf Solution:}
\begin{center}
\includegraphics[height=1.5in]{hw2_sol_5a.png}
\end{center}

To see that $A$ is not open, observe that the origin $(0,0) \in A$, but any ball around the origin, say $B_r(0,0)$, contains a point $(0,\,r/2)$ that is not in $A$.
\begin{center}
\includegraphics[height=1.5in]{hw2_sol_5b.png}
\end{center}

To see that $A$ is not closed, consider the sequence of points $p_n = (\frac{1}{n},1)$, which stays in $A$ but converges to $(0,1)$ which is not in $A$.
\begin{center}
\includegraphics[height=1.5in]{hw2_sol_5c.png}
\end{center}

\end{enumerate}
\pagebreak


\item Let $X=\Q$ with the metric induced from the usual one on $\R$.
\begin{enumerate}
\item
Prove that the subset
\[ \{ x \in \Q : x^2 < 1 \} \]
is open but not closed.

{\bf Solution:} Call the subset $A$, and notice that we can also describe it as
\[ A = \{ x \in \Q : |x| < 1 \}. \]
To see that $A$ is open, let $x \in A$, and take $r = 1-|x| > 0$.  Then $B_r(x) \subset A$: for all $y \in \Q$ with $|y-x| < r$, we have
\[ |y| \le |y-x| + |x| < r + |x| = 1, \]
so $y \in A$.

To see that $A$ is not closed, consider the sequence $\frac12, \frac23, \frac34, \dotsc \in A$ which converges to $1 \notin A$.
\bigskip

\item
Prove that the subset 
\[ \{ x \in \Q : x^2 < 2 \} \]
is both open and closed.

{\bf Solution:} Call the subset $B$, and notice that we can also describe it as
\[ B = \{ x \in \Q : x^2 \le 2 \}, \]
because there is no $x \in \Q$ with $x^2 = 2$.  Thus we can describe it either as
\[ B = \{ x \in \Q : |x| < \sqrt 2 \}, \]
or as
\[ B = \{ x \in \Q : |x| \le \sqrt 2 \}. \]
To see that $B$ is open, let $x \in B$, take $r = \sqrt 2 - |x|$, and argue that $B_r(x) \subset B$ as before.

To see that $B$ is closed, let $x_n$ be a sequence of rational numbers with $|x_n| \le \sqrt{2}$, converging to a limit $\ell$.  We have
\[ |\ell| \le |\ell - x_n| + |x_n| \le |\ell - x_n| + \sqrt 2 \]
for all $n$.  For every $\epsilon > 0$ there is an $n$ such that $|\ell-x_n| < \epsilon$, so the right-hand side is less that $\sqrt 2 + \epsilon$: that is, $|\ell| < \sqrt 2 + \epsilon$ for all $\epsilon > 0$, so $|\ell| \le \sqrt 2$.

\end{enumerate}


\item[2.3] (Optional.)
Let $U \subset C^1([0,1])$ be the set of functions with simple roots -- that is, those for which $f'(x) \ne 0$ whenever $f(x) = 0$.  Prove that $U$ is open in the $C^1$ metric
\[ d(f,g) = \sup|f-g| + \sup|f'-g'|. \]

Hint: For a given $f \in U$, take the ball of radius
\[ r = \inf\left(|f| + |f'|\right). \]

{\bf Solution:} Observe that $f \in U$ if and only if $|f(x)| + |f'(x)| > 0$ for all $x \in [0,1]$, because that says that $f(x) \ne 0$ or $f'(x) \ne 0$ or both.

Let $f \in U$ be given, and take $r$ as in the hint.  First let us argue that $r > 0$.  Because $f$ and $f'$ are continuous, $|f| + |f'|$ is continuous, so it achieves its sup and inf: that is, there is an $x \in [0,1]$ such that $|f(x)| + |f'(x)| = r$.  But this is positive because $f \in U$.

Now  let us argue that if $d(f,g) < r$ then $g \in U$.  By the reverse triangle inequality, we have
\[ |g(x)| \ge |f(x)| - |f(x)-g(x)| \quad\text{and}\quad |g'(x)| \ge |f'(x)| - |f'(x)-g'(x)| \]
for all $x \in [0,1]$.  Adding the two inequalities, we get
\[ |g(x)| + |g'(x)| \ge |f(x)| + |f'(x)| - |f(x)-g(x)| - |f'(x)-g'(x)|. \]
For the first two terms on the right-hand side, we have
\[ |f(x)| + |f'(x)| \ge \inf\left(|f| + |f'|\right) = r \]
and for the last two terms,
\[ |f(x)-g(x)| + |f'(x)-g'(x)| \le \sup |f-g| + \sup |f'-g'| = d(f,g) < r, \]
so
\[ |g(x)| + |g'(x))| > r-r = 0. \]
Thus $g \in U$, as desired.

\end{enumerate}

\end{document}
