% !TeX root = constructions.tex

\chapter{A Compass is Sufficient}\label{c.compass-only}

In 1797 the Italian mathematician Lorenzo Mascheroni proved that any construction carried out with a compass and straightedge can be carried out with the compass alone! Later it came to light that the construction had already been discovered by the Danish mathematician Georg Mohr 1672. The theorem is now called the Mohr-Mascheroni Theorem.

In this chapter I present a proof of the theorem based on the proof in problem 33 of \cite{dorrie1} and reworked by  Michael Woltermann \cite{dorrie2}.\footnote{I would like to thank Woltermann for permission to use his work.} A different  proof can be found in \cite{mm}.

What does it mean to perform a construction with only a compass? The right diagram below shows the construction of an equilateral triangle using a straightedge and compass. How can we construct a triangle without the line segments $\overline{AB}, \overline{AC}, \overline{BC}$? In fact, there is no need to \emph{see} the lines. A line is defined by two points, so it is sufficient to construct the points in order to obtain a construction equivalent to the one with a straightedge (left diagram):
\begin{center}
\begin{tikzpicture}[scale=0.6]
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\path (A) node[below left] {$A$} -- (B) node[below right] {$B$};
\fill (A) circle[radius=3pt];
\fill (B) circle[radius=3pt];
\draw[name path=larc] (A) ++(-10:4cm) arc (-10:80:4cm);
\draw[name path=rarc] (B) ++(-170:4cm) arc (-170:-260:4cm);
\path [name intersections={of=larc and rarc,by={t}}];
\fill (t) node[above right,xshift=-2pt,yshift=3pt] {$C$} circle[radius=3pt];
\begin{scope}[xshift=10cm]
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\draw (A) node[below left] {$A$} -- (B) node[below right] {$B$};
\fill (A) circle[radius=3pt];
\fill (B) circle[radius=3pt];
\draw[name path=larc] (A) ++(-10:4cm) arc (-10:80:4cm);
\draw[name path=rarc] (B) ++(-170:4cm) arc (-170:-260:4cm);
\path [name intersections={of=larc and rarc,by={t}}];
\fill (t) node[above right,xshift=-2pt,yshift=3pt] {$C$} circle[radius=3pt];
\draw (A) -- (t);
\draw (B) -- (t);
\end{scope}
\end{tikzpicture}
\end{center}
In the diagrams we will draw lines, but they are used only to understand the construction and the proof of its correctness. It is important that you convince yourself that the construction itself uses only a compass.

A construction by straightedge and compass is a sequence taken from these three operations:
\begin{itemize}
\item Find the point of intersection of two straight lines.
\item Find the point of intersection of a straight line and a circle.
\item Find the point(s) of intersection of two circles.
\end{itemize}
It is clear that the third operation can be done with only a compass. We need to show that the first two operations can be done with a compass alone.

Notation:
\begin{itemize}
\item $c(O,A)$: the circle with center $O$ through point $A$.
\item $c(O,r)$: the circle with center $O$ and radius $r$.
\item $c(O,AB)$: the circle with center $O$ and radius the length of line segment $\overline{AB}$.
\end{itemize}

First we will solve four preliminary problems (Sections~\ref{s.reflection}--\ref{s.three}). Next, we show the construction for finding the intersection of two lines (Section~\ref{s.two-lines}), and finally the construction of the intersection of a line and a circle (Section~\ref{s.line-circle}).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Reflection of a point}\label{s.reflection}

\textbf{Given a line $\overline{AB}$ and a point $C$ not on $\overline{AB}$, build a point $C'$ which is a reflection of $C$ about $\overline{AB}$.}

$C'$ is a \emph{reflection} about a line segment $\overline{AB}$ if $\overline{AB}$ (or the line containing $\overline{AB}$) is the perpendicular bisector of the line $CC'$.

Construct a circle centered on $A$ passing through $C$ and circle centered on $B$ passing through $C$. The intersection of the two circles is the point $C'$ which is the reflection of $C$.
\begin{center}
\begin{tikzpicture}[scale=.65]
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (2.5,1.5);
\draw[thick,dashed] ($(B)!2!(A)$) -- ($(A)!2!(B)$);
\fill (A) node[above left] {$A$} circle[radius=2pt];
\fill (B) node[above right] {$B$} circle[radius=2pt];
\fill (C) node[above,yshift=4pt] {$C$} circle[radius=2pt];
\node[draw,circle through=(C),name path=ac] at (A) {};
\node[draw,circle through=(C),name path=bc] at (B) {};
\path [name intersections={of=ac and bc,by={x1,Cp}}];
\fill (Cp) node[below,yshift=-4pt] {$C'$} circle[radius=2pt];
\draw (C) -- (Cp);
\draw[thick,dashed] (A) -- (C);
\draw[thick,dashed] (B) -- (C);
\draw[thick,dashed] (A) -- (Cp);
\draw[thick,dashed] (B) -- (Cp);
\end{tikzpicture}
\end{center}
\textbf{Proof:} $\triangle ABC \cong \triangle ABC'$ by side-side-side since $\overline{AC}, \overline{AC'}$ are radii of the same circle as are $\overline{BC}, \overline{BC'}$, and $\overline{AB}$ is a common side. Therefore, $\angle CAB = \angle C'AB$ so $\overline{AB}$ is the angle bisector of $\angle CAC'$. But $\triangle CAC'$ is an isosceles triangle and the angle bisector $\overline{AB}$ is also the perpendicular bisector of the base of $\triangle CAC'$. By definition $C'$ is the reflection of $C$ around $\overline{AB}$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Construct a circle with a given radius}\label{s.circle}

\textbf{Given points $A,B,C$, construct $c(A,BC)$.}

Construct $c(A,B)$ and $c(B,A)$ and let $X$ and $Y$ be their points of intersection.

\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (A) at (0,1.5);
\coordinate (B) at (0,-1.5);
\coordinate (C) at (1.5,-3);
\coordinate (Cp) at (1.5,3);
\fill (A) node[above] {$A$} circle[radius=3pt];
\fill (B) node[below] {$B$} circle[radius=3pt];
\fill (C) node[below] {$C$} circle[radius=3pt];
%\fill (Cp) node[above] {$C'$} circle[radius=3pt];
\node[draw,circle through=(B),name path=ab] at (A) {};
\node[draw,circle through=(A),name path=ba] at (B) {};
\path [name intersections={of=ab and ba,by={Y,X}}];
\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];
\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];
\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);
\end{tikzpicture}
\vspace*{-6pt}
\end{center}

\newpage

Construct $C'$, the reflection of $C$ about line $\overline{XY}$ as described in Section~\ref{s.reflection}.

\begin{center}
\begin{tikzpicture}[scale=.45]
\coordinate (A) at (0,1.5);
\coordinate (B) at (0,-1.5);
\coordinate (C) at (1.5,-3);
\coordinate (Cp) at (1.5,3);
\fill (A) node[right] {$A$} circle[radius=3pt];
\fill (B) node[right] {$B$} circle[radius=3pt];
\fill (C) node[below,yshift=-2pt] {$C$} circle[radius=3pt];
\fill (Cp) node[above,xshift=2pt,yshift=2pt] {$C'$} circle[radius=3pt];
\node[circle through=(B),name path=ab] at (A) {};
\node[circle through=(A),name path=ba] at (B) {};
\path [name intersections={of=ab and ba,by={Y,X}}];
\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];
\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];
\node[draw,circle through=(C)] at (X) {};
\node[draw,circle through=(C)] at (Y) {};
\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);
%\draw (X) -- (Y) -- (C) -- (X) -- (Cp) -- (Y);
\draw[thick,dashed] (C) -- (Cp);
\end{tikzpicture}
\vspace*{-6pt}
\end{center}

$c(A,C')$ is the desired circle.

\begin{center}
\begin{tikzpicture}[scale=.5]
\coordinate (A) at (0,1.5);
\coordinate (B) at (0,-1.5);
\coordinate (C) at (1.5,-3);
\coordinate (Cp) at (1.5,3);
\fill (A) node[above,yshift=2pt] {$A$} circle[radius=3pt];
\fill (B) node[below,yshift=-2pt] {$B$} circle[radius=3pt];
\fill (C) node[below,yshift=-2pt] {$C$} circle[radius=3pt];
\fill (Cp) node[above,yshift=2pt] {$C'$} circle[radius=3pt];
\node[circle through=(B),name path=ab] at (A) {};
\node[circle through=(A),name path=ba] at (B) {};
\path [name intersections={of=ab and ba,by={Y,X}}];
\fill (X) node[above right,xshift=4pt] {$X$} circle[radius=3pt];
\fill (Y) node[above left,xshift=-4pt] {$Y$} circle[radius=3pt];
\node[circle through=(C)] at (X) {};
\node[draw,circle through=(C)] at (Y) {};
\draw[thick,dashed] ($(X)!2.3!(Y)$) -- ($(Y)!2!(X)$);
\path[name path=xy] (X) -- (Y);
\node[draw,thick,circle through=(Cp)] at (A) {};
\draw[very thick] (A) -- (Cp);
\draw[very thick] (B) -- (C);
\draw[very thick,name path=abline] (A) -- (B);
\draw[very thick,name path=ccp] (C) -- (Cp);
\path [name intersections={of=xy and abline,by={D}}];
\path [name intersections={of=xy and ccp,by={E}}];
\fill (D) node[above left] {$D$} circle[radius=3pt];
\fill (E) node[below right] {$E$} circle[radius=3pt];
\draw[thick,dashed] (D) -- (Cp);
\draw[thick,dashed] (D) -- (C);
\draw (D) rectangle +(10pt,10pt);
\draw (E) rectangle +(10pt,10pt);
\end{tikzpicture}
\vspace*{-4pt}
\end{center}

\textbf{Proof:} $A$ is the reflection of $B$ around $\overline{XY}$ (since $\triangle YAX\cong \triangle YBX$) and $C'$ is the reflection of $C$ around the $\overline{XY}$. By definition, $\overline{XY}$ is the perpendicular bisector of $\overline{CC'}$ and $\overline{AB}$, so $\overline{C'E}=\overline{EC}$, $\overline{AD}=\overline{DB}$ and $\angle DEC=\angle DEC'$ are right angles. $\triangle DEC\cong\triangle DEC'$ by side-angle-side, so $\overline{DC}=\overline{DC'}$ and $\angle ADC'=\angle BDC$ (they are complementary to $\angle EDC'$, $\angle EDC$). Therefore, $\triangle ADC'\cong\triangle BDC$ by side-angle-side, so $\overline{AC'}=\overline{BC}$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Addition and subtraction of line segments}\label{s.add-subtract}

\textbf{Given line segment $\overline{PQ}$ of length $a$ and line segment $\overline{RS}$ of length $b$, construct line segments $\overline{QT}, \overline{QU}$ such that $\overline{PUQT}$ is a line segment, where the length of $\overline{PU}$ is $a-b$ and the length of $\overline{PT}$ is $a+b$.}
\begin{center}
\begin{tikzpicture}[scale=.8]
\draw (0,0) -- (5,0);
\fill (0,0) node[above] {$P$} circle[radius=2pt];
\fill (5,0) node[above left] {$Q$} circle[radius=2pt];
\fill (3,0) node[above left] {$U$} circle[radius=2pt];
\fill (7,0) node[above right] {$T$} circle[radius=2pt];
\draw[thick,dashed] (5,0) -- (8,0);
\draw (5,0) circle[radius=2cm];
\draw[thick,dashed] (5,0) -- node[left] {$b$} ++(60:2cm);
\draw (9,-1) node[above] {$R$} -- node[below right] {$b$} ++(20:2cm) node[above] {$S$};
\fill (9,-1) circle[radius=2pt];
\fill (9,-1) ++(20:2cm) circle[radius=2pt];
\draw[<->] (0,-.5) -- node[fill=white] {$a$} (5,-.5);
\draw[<->] (0,-1) -- node[fill=white] {$a-b$} (3,-1);
\draw[<->] (0,-1.5) -- node[fill=white] {$a+b$} (7,-1.5);
\end{tikzpicture}
\end{center}

\newpage

\subsection*{Constructing an isosceles trapezoid}

Let $H$ be any point on $c(Q,b)$. Construct $H'$, its reflection about $\overline{PQ}$. $h$ is the length of $\overline{HH'}$:

\vspace{-1ex}

\begin{center}
\begin{tikzpicture}[scale=.6]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[thick,dashed] ($(Q)!1.3!(P)$) -- node[above,near start] {$a$} ($(P)!2.3!(Q)$);
\fill (Q) node[above left] {$Q$} circle[radius=2pt];
\fill (P) node[above] {$P$} circle[radius=2pt];
\fill (B) circle[radius=2pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={H}}];
\path [name intersections={of=qb and qhp,by={Hp}}];
\fill[below right] (H) node[right,xshift=2pt] {$H$} circle[radius=2pt];
\fill[above right] (Hp) node[right,xshift=2pt] {$H'$} circle[radius=2pt];
\draw[thick,dashed] (H) -- node[below left,yshift=-2pt] {$h$} (Hp);
\end{tikzpicture}
\end{center}

\vspace{-2ex}

Construct the circles $c(H,b)$, $c(Q,h)$. Let $K$ be the intersection of the circles and construct $K'$, the reflection of $K$ about line $\overline{PQ}$:

\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[thick,dashed] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);
\fill (Q) node[above right,xshift=6pt] {$Q$} circle[radius=3pt];
\fill (P) node[above] {$P$} circle[radius=3pt];
\fill (B) circle[radius=3pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={Hp}}];
\path [name intersections={of=qb and qhp,by={H}}];
\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];
\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];
\draw (H) -- node[below left,yshift=-3pt] {$h$} (Hp);

\draw (H|-Q) rectangle +(10pt,10pt);
\fill (H|-Q) circle(3pt) node[above left] {$Q'$};

\draw[thick,name path=circleqh] (Q) let
  \p1 = ($ (H) - (Hp) $),
  \n2 = {veclen(\x1,\y1)}
in
  circle (\n2)
  (Q) edge [dashed] node[below] {$h$} +(140:\n2) ++(140:\n2) coordinate (q);
\fill (q) circle[radius=3pt];
\draw[thick,name path=circlehb] (H) let
  \p1 = ($ (Q) - (B) $),
  \n2 = {veclen(\x1,\y1)}
in
  circle (\n2)
  (H) edge [dashed] node[below,near end] {$b$} +(50:\n2) ++(50:\n2)  coordinate (h);
\fill (h) circle[radius=3pt];
\path [name intersections={of=circleqh and circlehb,by={K}}];
\fill (K) node[above left] {$K$} circle[radius=3pt];
%\draw[thick] (H) -- (K);
\draw let
  \p1 = ($ (K) - (Q) $)
in
  coordinate (Kp) at (\x1,-\y1);
\fill (Kp) node[below left] {$K'$} circle[radius=3pt];
\draw (K) -- (Kp);
\draw (Q) rectangle +(10pt,10pt);
\end{tikzpicture}
\vspace*{-8pt}
\end{center}

$\overline{PQ}$ is the perpendicular bisector of both $\overline{HH'}$ and $\overline{KK'}$, so these line segments are parallel. $\overline{KH}=b$ since it is the radius of the circle centered on $H$. $K',H'$ are reflections of $K,H$ and it is not hard to show that $\overline{K'H'}=\overline{KH}$ ($\triangle QQ'H\cong \triangle QQ'H'$ and then $\triangle KQH\cong \triangle K'QH'$). Therefore, $\overline{KHH'K'}$ is an isosceles trapezoid whose bases are $\overline{HH'}=h$, $\overline{KK'}=2h$. Let $d$ be the length of the diagonals $\overline{K'H}=\overline{KH'}$:

\begin{center}
\vspace*{-8pt}
\begin{tikzpicture}[scale=.6]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[thick,dashed] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);
\fill (Q) node[above left] {$Q$} circle[radius=3pt];
\fill (P) node[above] {$P$} circle[radius=3pt];
%\fill (B) circle[radius=3pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
%\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={Hp}}];
\path [name intersections={of=qb and qhp,by={H}}];
\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];
\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];
\draw (H) -- node[below right,yshift=-2pt] {$h$} (Hp);
\path[name path=circleqh] (Q) let
  \p1 = ($ (H) - (Hp) $)
in
  circle ({veclen(\x1,\y1)});
\path[name path=circlehb] (H) let
  \p1 = ($ (Q) - (B) $)
in
  circle ({veclen(\x1,\y1)});
\path [name intersections={of=circleqh and circlehb,by={K,k2}}];
\fill (K) node[above left] {$K$} circle[radius=3pt];
\draw (Q) -- node[left] {$h$} (K);
\draw (H) -- node[right,xshift=4pt] {$b$} (K);
\draw let
  \p1 = ($ (K) - (Q) $)
in
  coordinate (Kp) at (\x1,-\y1);
\fill (Kp) node[below left] {$K'$} circle[radius=3pt];
\draw (Q) -- node[left] {$h$} (Kp) -- node[right,xshift=2pt,yshift=-2pt] {$b$} (Hp);
\draw (K) -- node[above right] {$d$} (Hp);
\draw (Kp) -- node[left] {$d$} (H);
\end{tikzpicture}
\label{ptolemy}
\vspace*{-8pt}
\end{center}

\subsection*{Circumscribing the trapezoid by a circle}

We want to proof that it is possible to circumscribe $\overline{KHH'K'}$ by a circle. We will prove that: if the opposite angles of a quadrilateral are supplementary, then the trapezoid can be circumscribed by a circle, and that in an isosceles trapezoid the opposite angles are supplementary. Geometry textbooks give the simple proof that the opposite angles of a quadrilateral circumscribed by a circle are supplementary, but it is hard to find a proof of the converse, so I present both proofs here.

\textbf{If a quadrilateral can be circumscribed by a circle then the opposite angles are supplementary:} An inscribed angle equals half the subtended arc, so $\angle DAB$ is half of the arc $\widehat{DCB}$ and $\angle DCB$ is half of the arc $\widehat{DAB}$. The two arcs subtend the entire circumference of the circle, so their sum is $360^\circ$. Therefore, $\angle DAB + \angle DCB = \disfrac{1}{2} \cdot 360^\circ =  180^\circ$, and similarly $\angle ADC + \angle ABC = 180^\circ$

\vspace*{-2ex}

\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (origin) at (0,0);
\coordinate (A) at (1,3);
\node[draw,circle through=(A),name path=circle] at (origin) {};
\fill (A) node[above right] {$A$} circle[radius=3pt];
\path[name path=b] (A) -- (-50:4.5cm);
\path[name path=c] (A) -- (-120:4.5cm);
\path[name path=d] (A) -- (150:4.5cm);
\path [name intersections={of=circle and b,by={b1,B}}];
\fill (B) node[right] {$B$} circle[radius=3pt];
\path [name intersections={of=circle and c,by={c1,C}}];
\fill (C) node[below left] {$C$} circle[radius=3pt];
\path [name intersections={of=circle and d,by={d1,D}}];
\fill (D) node[above left] {$D$} circle[radius=3pt];
\draw (A) -- (B) -- (C) -- (D) -- cycle;
\end{tikzpicture}
\end{center}

\vspace*{-2ex}

\textbf{A quadrilateral whose opposite angles are supplementary can be circumscribed by a circle:} Any triangle can be circumscribed by a circle. Circumscribe $\triangle DAB$ by a circle and suppose that $C'$ is a point such that $\angle DAB + \angle DC'B = 180^\circ$, but $C'$ is \emph{not} on the circumference of the circle. Without loss of generality, let $C'$ be within the circle:

\vspace*{-1ex}

\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (origin) at (0,0);
\coordinate (A) at (1,3);
\node[draw,circle through=(A),name path=circle] at (origin) {};
\fill (A) node[above right] {$A$} circle[radius=3pt];
\path[name path=b] (A) -- (-50:4cm);
\path[name path=c] (A) -- (-120:4cm);
\path[name path=d] (A) -- (150:4cm);
\path [name intersections={of=circle and b,by={b1,B}}];
\fill (B) node[right] {$B$} circle[radius=3pt];
\path [name intersections={of=circle and c,by={c1,C}}];
\fill (C) node[below left] {$C$} circle[radius=3pt];
\path [name intersections={of=circle and d,by={d2,D}}];
\fill (D) node[above left] {$D$} circle[radius=3pt];
\coordinate (Cp) at ($(C)!.2!(D)$);
\draw (A) -- (B) -- (Cp) -- (D) -- cycle;
\fill (Cp) node[left,xshift=1pt,yshift=2pt] {$C'$} circle[radius=3pt];
\draw[thick,dashed] (D) -- (B) -- (C) -- (Cp);
\end{tikzpicture}
\end{center}

\vspace*{-1ex}

Construct a ray that extends $\overline{DC'}$ and let $C$ be its intersection with the circle. $\overline{ABCD}$ is circumscribed by a circle so:
\begin{eqnarray*}
\angle DAB + \angle DCB &=& 180^\circ\\
\angle DAB + \angle DCB &=& \angle DAB + \angle DC'B\\
\angle DCB &=& \angle DC'B\,,
\end{eqnarray*}
which is impossible if $C$ is on the circle and $C'$ is inside the circle.

\newpage

Finally, we show that the opposite angles of an isosceles trapezoid are supplementary.

\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (origin) at (0,0);
\coordinate (A) at (2.5,1.8);
\node[circle through=(A),name path=circle] at (origin) {};
\fill (A) node[above right] {$A$} circle[radius=3pt];
\path[name path=b] (A) -- ++(-80:4cm);
\path[name path=d] (A) -- ++(180:6cm);
\path [name intersections={of=circle and b,by={b1,B}}];
\fill (B) node[below right] {$B$} circle[radius=3pt];
\path [name intersections={of=circle and d,by={d1,D}}];
\fill (D) node[above left] {$D$} circle[radius=3pt];
\path[name path=c] (D) -- ++(-100:4cm);
\path [name intersections={of=circle and c,by={c1,C}}];
\fill (C) node[below left] {$C$} circle[radius=3pt];
\draw (A) -- node[right,xshift=8pt] {$x$} (B);
\draw[name path=bc] (B) -- node[below] {$y$} (C);
\draw (C) -- node[left,xshift=-8pt] {$x$} (D) -- node[above] {$y$} (A);
\path[name path=para] (A) -- ++(-100:4cm);
\path [name intersections={of=para and bc,by={Bp}}];
\fill (Bp) node[below left] {$B'$} circle[radius=3pt];
\draw[thick,dashed] (A) -- node[left,xshift=-2pt] {$x$} (Bp);
\end{tikzpicture}
\end{center}

\vspace{-4ex}

Construct the line $\overline{AB'}$ parallel to $\overline{CD}$. $\overline{AB'CD}$ is a parallelogram and $\triangle ABB'$ is an isosceles triangle, so $\angle C= \angle ABB' = \angle AB'B = \angle B$. Similarly, $\angle A = \angle D$. Since the sum of the internal angles of any quadrilateral is equal to $360^\circ$:
\begin{eqnarray*}
\angle A + \angle B + \angle C + \angle D &=& 360^\circ\\
2\angle A + 2 \angle C &=& 360^\circ\\
\angle A +  \angle C &=& 180^\circ\,.
\end{eqnarray*}
and similarly $\angle B +  \angle D = 180^\circ$.

\subsection*{Ptolemy's theorem}

Ptolemy's theorem relates the lengths of the diagonals and the lengths of the sides of a quadrilateral that is circumscribed by a circle:
\[
ef = ac + bd\,.
\]
\begin{center}
\begin{tikzpicture}[scale=.6]
\coordinate (origin) at (0,0);
\coordinate (A) at (1,3);
\node[draw,circle through=(A),name path=circle] at (origin) {};
\fill (A) node[above right] {$A$} circle[radius=3pt];
\path[name path=b] (A) -- (-50:4cm);
\path[name path=c] (A) -- (-120:4cm);
\path[name path=d] (A) -- (150:4cm);
\path [name intersections={of=circle and b,by={b1,B}}];
\fill (B) node[right] {$B$} circle[radius=3pt];
\path [name intersections={of=circle and c,by={C,c2}}];
\fill (C) node[below left] {$C$} circle[radius=3pt];
\path [name intersections={of=circle and d,by={D,d2}}];
\fill (D) node[above left] {$D$} circle[radius=3pt];
\draw (A) -- node[right] {$a$} (B) -- node[below,yshift=-10pt] {$b$} (C) -- node[left] {$c$} (D) -- node[above,xshift=2pt,yshift=16pt] {$d$}  cycle;
\draw (A) -- node[right,near start] {$e$} (C);
\draw (B) -- node[left,near end,yshift=-6pt] {$f$} (D);
\end{tikzpicture}
\end{center}
There is a geometric proof of the theorem (see Wikipedia), but I will present a simple trigonometric proof. The law of cosines for the four triangles $\triangle ABC$, $\triangle ADC$, $\triangle DAB$, $\triangle DCB$ gives the following equations:
\begin{eqnarray*}
e^2 &=& a^2 + b^2 - 2ab \cos \angle B\\
e^2 &=& c^2 + d^2 - 2cd \cos \angle D\\
f^2 &=& a^2 + d^2 - 2ad \cos \angle A\\
f^2 &=& b^2 + c^2 - 2bc \cos \angle C\,.
\end{eqnarray*}
$\angle C = 180^\circ - \angle A$ and $\angle D = 180^\circ - \angle B$ because they are opposite angles of a quadrilateral circumscribed by a circle, so:
\begin{eqnarray*}
\cos \angle D &=& - \cos \angle B\\
\cos \angle C &=& -\cos \angle A\,.
\end{eqnarray*}
We can eliminate the cosine term from the first two equations and from the last two equations. After some messy arithmetic, we get:
\begin{eqnarray*}
e^2 &=& \frac{(ac+bd)(ad+bc)}{(ab+cd)}\\
f^2 &=& \frac{(ab+cd)(ac+bd)}{(ad+bc)}\,.
\end{eqnarray*}
Multiply the two equations and simplify to get Ptolemy's theorem:
\begin{eqnarray*}
e^2\cdot f^2 &=& (ac+bd)^2\\
ef &=& (ac+bd)\,.
\end{eqnarray*}
\subsection*{Using Ptolemy's theorem}

For the construction on page~\pageref{ptolemy}, the diagonals are of length $d$, the legs are of length $b$, and the bases are of lengths $h$ and $2h$, so Ptolemy's theorem gives $d\cdot d = b\cdot b + h\cdot 2h$ or $d^2=b^2+2h^2$.

Let $X$ be the point on line $\overline{PQ}$ that extends $\overline{PQ}$ by $b$. (We will eventually construct $X$; now we're just imagining it.) Define  $x = \overline{K'X}$. Since $\triangle QK'X$ is a right triangle, $x^2 = b^2 + h^2$:
\begin{center}
\begin{tikzpicture}[scale=.6]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[thick,dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);
\fill (Q) node[above left] {$Q$} circle[radius=3pt];
\fill (P) node[above] {$P$} circle[radius=3pt];
%\fill (B) circle[radius=2pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
%\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={hp}}];
\path [name intersections={of=qb and qhp,by={H}}];
\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];
\fill (hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];
\draw[thick,dashed] (H) -- (hp);
\path[name path=circleqh] (Q) let
  \p1 = ($ (H) - (hp) $)
in
  circle ({veclen(\x1,\y1)});
\path[name path=circlehb] (H) let
  \p1 = ($ (Q) - (B) $)
in
  circle ({veclen(\x1,\y1)});
\path [name intersections={of=circleqh and circlehb,by={K,k2}}];
\fill (K) node[above left] {$K$} circle[radius=3pt];
\draw[thick,dashed] (Q) -- (K);
\draw[thick,dashed] (H) -- (K);
\draw[thick,dashed] let
  \p1 = ($ (K) - (Q) $)
in
  coordinate (kp) at (\x1,-\y1);
\fill (kp) node[below left] {$K'$} circle[radius=3pt];
\draw[thick,dashed] (Q) -- node[left] {$h$} (kp) -- (hp);
\draw[thick,dashed] (K) -- (hp);
\draw[thick,dashed] (kp) -- (H);
\path [name intersections={of=pq and qb,by={X,x2}}];
\fill (X) node[below right] {$X$} circle[radius=3pt];
\draw[thick,dashed] (kp) -- node[left] {$x$} (X);
\draw[very thick] (Q) -- (kp) -- (X) -- node[above,xshift=-8pt] {$b$} cycle;
\end{tikzpicture}
\vspace*{-8pt}
\end{center}
From the computation of Ptolemy's theorem theorem above:
\erh{0pt}
\begin{equationarray*}{rcl}
d^2&=&b^2 + 2h^2\\
&=&(x^2-h^2)+2h^2\\
&=&x^2+h^2\,.
\end{equationarray*}
Don't look for a right triangle in the diagram. We are claiming that \emph{it is possible to construct} a triangle with sides $x,h,d$.

Let us construct the point $S$ as the intersection of the circles
$c(K,d),c(K',d)$:
\begin{center}
\begin{tikzpicture}[scale=.55]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);
\fill (Q) node[above left] {$Q$} circle[radius=3pt];
\fill (P) node[above] {$P$} circle[radius=3pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={Hp}}];
\path [name intersections={of=qb and qhp,by={H}}];
%\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];
%\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];
\path[name path=circleqh] (Q) let
  \p1 = ($ (H) - (Hp) $)
in
  circle ({veclen(\x1,\y1)});
\path[name path=circlehb] (H) let
  \p1 = ($ (Q) - (B) $)
in
  circle ({veclen(\x1,\y1)});
\path [name intersections={of=circleqh and circlehb,by={K,k2}}];
\fill (K) node[above left] {$K$} circle[radius=3pt];
\draw[thick,dashed] let
  \p1 = ($ (K) - (Q) $)
in
  coordinate (Kp) at (\x1,-\y1);
\fill (Kp) node[below left] {$K'$} circle[radius=3pt];
\draw[thick] (Q) -- node[left] {$h$} (Kp);
\draw[thick,name path=khp] (K) let
  \p1 = ($ (H) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (K) ++(-100:\n2) arc (-100:-30:\n2);
\draw[thick,name path=kph] (Kp) let
  \p1 = ($ (H) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (Kp) ++(100:\n2) arc (100:30:\n2);
\path [name intersections={of=kph and khp,by={S}}];
\fill (S) node[above right,xshift=6pt] {$S$} circle[radius=3pt];
\draw[thick] (Kp) -- node[right,near start,yshift=-6pt] {$d$} (S);
\draw[thick] (Q) -- (S);
\path [name intersections={of=pq and qb,by={X,Xp}}];
\fill (X) node[above right] {$X$} circle[radius=3pt];
%\fill (Xp) node[above left] {$X'$} circle[radius=3pt];
%\draw (Kp) -- node[left] {$x$} (X);
%\draw (K) -- node[left] {$x$} (X);
%\fill (B) circle[radius=3pt];
%\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\end{tikzpicture}
\end{center}
We obtain a right triangle $\triangle QSK'$. By Pythagoras' theorem
$\overline{QS}^2 + h^2 = d^2$, so:
\[
\overline{QS}^2 = d^2-h^2=x^2\,,
\]
and $\overline{QS}=x$.

It is possible to construct the point $X$ as the intersection of the circles $c(K,x),c(K',x)$:
\begin{center}
\vspace*{-14pt}
\begin{tikzpicture}[scale=.55]
\coordinate (Q) at (0,0);
\coordinate (P) at (-6.8,0);
\coordinate (B) at (-3,-2);
\draw[dashed,name path=pq] ($(Q)!1.3!(P)$) -- ($(P)!2.3!(Q)$);
\fill (Q) node[above left] {$Q$} circle[radius=3pt];
\fill (P) node[above] {$P$} circle[radius=3pt];
\node[draw,circle through=(B),name path=qb] at (Q) {};
\path[name path=qh] (Q) -- (-40:5cm);
\path[name path=qhp] (Q) -- (40:5cm);
\path [name intersections={of=qb and qh,by={Hp}}];
\path [name intersections={of=qb and qhp,by={H}}];
%\fill (H) node[right,xshift=2pt] {$H$} circle[radius=3pt];
%\fill (Hp) node[right,xshift=2pt] {$H'$} circle[radius=3pt];
\path[name path=circleqh] (Q) let
  \p1 = ($ (H) - (Hp) $)
in
  circle ({veclen(\x1,\y1)});
\path[name path=circlehb] (H) let
  \p1 = ($ (Q) - (B) $)
in
  circle ({veclen(\x1,\y1)});
\path [name intersections={of=circleqh and circlehb,by={K,k2}}];
\fill (K) node[above left] {$K$} circle[radius=3pt];
\path[thick,dashed] let
  \p1 = ($ (K) - (Q) $)
in
  coordinate (Kp) at (\x1,-\y1);
\fill (Kp) node[below left] {$K'$} circle[radius=3pt];
%\draw[thick] (Q) -- node[left] {$h$} (Kp);
\path[name path=khp] (K) let
  \p1 = ($ (H) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (K) ++(-100:\n2) arc (-100:-30:\n2);
\path[name path=kph] (Kp) let
  \p1 = ($ (H) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (Kp) ++(100:\n2) arc (100:30:\n2);
\path [name intersections={of=kph and khp,by={S}}];
\fill (S) node[above right,xshift=6pt] {$S$} circle[radius=3pt];
%\draw[thick] (Kp) -- node[right,near start,yshift=-6pt] {$d$} (S);
%\draw[thick] (Q) -- (S);
\path [name intersections={of=pq and qb,by={X,Xp}}];
\fill (X) node[above right,xshift=8pt] {$X$} circle[radius=3pt];
\fill (Xp) node[above left] {$X'$} circle[radius=3pt];
\draw (Kp) -- node[left] {$x$} (X);
\draw (K) -- node[left] {$x$} (X);
%\fill (B) circle[radius=3pt];
%\draw[thick,dashed] (Q) -- node[left,xshift=-1pt,yshift=2pt] {$b$} (B);
\draw[name path=kx] (K) let
  \p1 = ($ (X) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (K) ++(-100:\n2) arc (-100:-30:\n2);
\draw[name path=kpx] (Kp) let
  \p1 = ($ (X) - (Kp) $),
  \n2 = {veclen(\x1,\y1)}
in
  (Kp) ++(100:\n2) arc (100:30:\n2);
\path (Xp) -- node[below] {$b$} (Q);
\path (Q) -- node[below] {$b$} (X);
\node at (-5,2) {\mbox{\boldmath $\overline{PQ}=a$}};
\draw[thick,dashed] (Q) -- node[left] {$h$} (Kp);
\draw[thick,dashed] (Q) -- (X);
\end{tikzpicture}
\vspace*{-10pt}
\end{center}
Recall that we want to extend $\overline{PQ}$ of length $a$ by a length $b$, or decrease its length by $b$. Since the length of $\overline{QX}$ is $\sqrt{x^2-h^2}=b$, the length of $\overline{PX}$ is $a+b$ and the length of $\overline{PX'}$ is $a-b$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Construct a line segment relative to three other line segments}\label{s.three}

\textbf{Given line segments of length $n,m,s$, construct a line segment of length:}
\[
x = \disfrac{n}{m}s\,.
\]

Construct two concentric circles $c_1 = c(Z,m)$ and $c_2 = c(Z,n)$, and chord $\overline{AB} = s$ on $c_1$. (A chord can be constructed using only a compass as shown in Section~\ref{s.circle}.)

We assume that $m>n$. If not, exchange the notation.
\begin{center}
\begin{tikzpicture}[scale=.4]
\coordinate (Z) at (0,0);
\coordinate (A) at (-130:5cm);
\coordinate (B) at (-80:5cm);
\fill (Z) node[above left] {$Z$} circle[radius=4pt];
\fill (A) node[below left] {$A$} circle[radius=4pt];
\fill (B) node[below] {$B$} circle[radius=4pt];
\draw[name path=c1] (Z) circle[radius=5cm];
\draw[name path=c2] (Z) circle[radius=3cm];
\node at (2,5) {$c_1$};
\node at (2,3) {$c_2$};
\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);
\draw[thick,dashed] (Z) -- node[below] {$m$} ++(10:5cm);
\draw[thick,dashed] (Z) -- node[below] {$n$} ++(-40:3cm);
\fill (Z) ++ (10:5cm) circle[radius=4pt];
\fill (Z) ++ (-40:3cm) circle[radius=4pt];
\begin{scope}[xshift=-14cm,yshift=3cm]
\coordinate (m) at (0,0);
\coordinate (n) at (0,-1.5);
\coordinate (s) at (0,-3);
\coordinate (mp) at (5,0);
\coordinate (np) at (2,-1.5);
\coordinate (sp) at (4,-3);
\fill (m) circle[radius=4pt];
\fill (n) circle[radius=4pt];
\fill (s) circle[radius=4pt];
\fill (mp) circle[radius=4pt];
\fill (np) circle[radius=4pt];
\fill (sp) circle[radius=4pt];
\draw[thick,dashed] (m) -- node[above] {$m$} (mp);
\draw[thick,dashed] (n) -- node[above] {$n$} (np);
\draw[thick,dashed] (s) -- node[above] {$s$} (sp);
\end{scope}
\end{tikzpicture}
\end{center}

\vspace{-2ex}

We also assume that $s$ does not intersect $c_2$. If not, use the construction in Section~\ref{s.add-subtract} to multiply $m,n$ by a number $k$ so that the chord does not intersect the circle. Note that this does not change the value that we are trying to construct since $x=\disfrac{kn}{km}s=\disfrac{n}{m}s$.

Choose any point $H$ on circle $c_2$. Label the length of $\overline{AH}$ by $w$. Construct point $K$ on $c_2$ such that the length of $\overline{BK}$ is $w$.
\begin{center}
\begin{tikzpicture}[scale=.5]
\coordinate (Z) at (0,0);
\coordinate (A) at (-130:5cm);
\coordinate (B) at (-90:5cm);
\fill (Z) node[above left] {$Z$} circle[radius=4pt];
\fill (A) node[below left] {$A$} circle[radius=4pt];
\fill (B) node[below] {$B$} circle[radius=4pt];
\draw[name path=c1] (Z) circle[radius=5cm];
\draw[name path=c2] (Z) circle[radius=2.5cm];
\node at (2,5) {$c_1$};
\node at (2,2.5) {$c_2$};
\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);
\draw[thick] (A) -- node[above,xshift=-4pt,yshift=-2pt] {$w$} +(20:120pt) coordinate (H);
\fill (H) node[above right,xshift=-2pt,yshift=4pt] {$H$} circle[radius=4pt];
\draw[thick] (B) -- node[right] {$w$} +(60:120pt) coordinate (K);
\fill (K) node[right] {$K$} circle[radius=4pt];
\begin{scope}[xshift=-14cm,yshift=3cm]
\coordinate (m) at (0,0);
\coordinate (n) at (0,-1.5);
\coordinate (s) at (0,-3);
\coordinate (w) at (0,-4.5);
\coordinate (mp) at (5,0);
\coordinate (np) at (2,-1.5);
\coordinate (sp) at (4,-3);
\coordinate (wp) at (4.5,-4.5);
\fill (m) circle[radius=4pt];
\fill (n) circle[radius=4pt];
\fill (s) circle[radius=4pt];
\fill (w) circle[radius=4pt];
\fill (mp) circle[radius=4pt];
\fill (np) circle[radius=4pt];
\fill (sp) circle[radius=4pt];
\fill (wp) circle[radius=4pt];
\draw[thick,dashed] (m) -- node[above] {$m$} (mp);
\draw[thick,dashed] (n) -- node[above] {$n$} (np);
\draw[thick,dashed] (s) -- node[above] {$s$} (sp);
\draw[thick,dashed] (w) -- node[above] {$w$} (wp);
\end{scope}
\end{tikzpicture}
\end{center}

$\triangle AHZ\cong\triangle BZK$ by side-side-side: $\overline{ZA}=\overline{ZB}=m$, the radius of $c_1$, $\overline{ZH}=\overline{ZK}=n$, the radius of $c_2$, and $\overline{AH}=\overline{BK}=w$ by construction.

\begin{center}
\begin{tikzpicture}[scale=.5]
\coordinate (Z) at (0,0);
\coordinate (A) at (-130:5cm);
\coordinate (B) at (-90:5cm);
\fill (Z) node[above left] {$Z$} circle[radius=4pt];
\fill (A) node[below left] {$A$} circle[radius=4pt];
\fill (B) node[below] {$B$} circle[radius=4pt];
\draw[name path=c1] (Z) circle[radius=5cm];
\draw[name path=c2] (Z) circle[radius=2.5cm];
\node at (2,5) {$c_1$};
\node at (2,2.5) {$c_2$};
\draw[thick,dashed] (A) -- node[below,yshift=-6pt] {$s$} (B);
\draw[thick] (A) -- node[above] {$w$} +(20:120pt) coordinate (H);
\fill (H) node[above right,xshift=-2pt,yshift=4pt] {$H$} circle[radius=4pt];
\draw[thick] (B) -- node[right] {$w$} +(60:120pt) coordinate (K);
\fill (K) node[right] {$K$} circle[radius=4pt];
\draw[thick] (Z) -- node[left,xshift=-2pt,yshift=-2pt] {$m$} (A);
\draw[thick] (Z) -- (B);
\draw[thick] (Z) -- (H);
\draw[thick] (Z) -- node[above] {$n$} (K);
\draw[thick,dashed] (H) -- (K);
\end{tikzpicture}
\end{center}
From $\triangle AHZ\cong\triangle BZK$, we get $\angle AZB = \angle HZK$. It is difficult to see this equality from the diagram, but the following diagram clarifies the relation among the angles. Define $\alpha = \angle AZH = \angle BZK$ and $\beta = \angle BZH$. It is easy to see that $\angle AZB = \angle HZK = \alpha - \beta$.
\begin{center}
\vspace*{-10pt}
\begin{tikzpicture}[scale=.7]
\coordinate (Z) at (0,0);
\coordinate (A) at (-150:5cm);
\coordinate (B) at (-100:5cm);
\coordinate (H) at (-60:4.5cm);
\coordinate (K) at (-20:4.5cm);
\fill (Z) circle[radius=2pt];
\fill (A) circle[radius=2pt];
\fill (B) circle[radius=2pt];
\fill (H) circle[radius=2pt];
\fill (K) circle[radius=2pt];
\draw (A) node[below left] {$A$} -- (Z) node[above] {$Z$} -- (B) node[below] {$B$};
\draw (H) node[below] {$H$} -- (Z) -- (K) node[below right] {$K$};
\draw (-150:1cm) arc (-150:-60:1);
\draw (-100:2cm) arc (-100:-20:2);
\draw (-100:3cm) arc (-100:-60:3);
\draw[very thick,dashed] (-150:4cm) arc (-150:-100:4);
\draw[very thick,dashed] (-60:4cm) arc (-60:-20:4);
\node at (-115:1.4) {$\alpha$};
\node at (-50:2.4) {$\alpha$};
\node at (-80:3.5) {$\beta$};
\node at (-40:5) {$\alpha - \beta$};
\node at (-125:5) {$\alpha - \beta$};
\end{tikzpicture}
\vspace*{-10pt}
\end{center}

$\triangle ZAB\sim\triangle ZHK$ by side-angle-side, since both are isosceles triangles and we have shown that they have the same vertex angle.

\vspace{-2ex}

\begin{center}
\begin{tikzpicture}[scale=.45]
\coordinate (Z) at (0,0);
\coordinate (A) at (-130:5cm);
\coordinate (B) at (-90:5cm);
\fill (Z) node[above left] {$Z$} circle[radius=4pt];
\fill (A) node[below left] {$A$} circle[radius=3pt];
\fill (B) node[below] {$B$} circle[radius=3pt];
\draw[name path=c1] (Z) circle[radius=5cm];
\draw[name path=c2] (Z) circle[radius=2.5cm];
\node at (2,5) {$c_1$};
\node at (2,2.5) {$c_2$};
\draw[thick] (A) -- node[below,yshift=-6pt] {$s$} (B);
\path[thick,dashed] (A) -- +(20:120pt) coordinate (H);
\fill (H) node[below] {$H$} circle[radius=3pt];
\path[thick,dashed] (B) -- +(60:120pt) coordinate (K);
\fill (K) node[right] {$K$} circle[radius=3pt];
\draw[thick] (Z) -- node[left,xshift=-2pt,yshift=-2pt] {$m$} (A);
\draw[thick] (Z) -- (B);
\draw[thick] (Z) -- (H);
\draw[thick] (Z) -- node[above] {$n$} (K);
\draw[thick] (H) -- node[below right] {$x$} (K);
\draw[thick,dashed] (A) -- (H);
\draw[thick,dashed] (B) -- (K);
\end{tikzpicture}
\end{center}

\vspace{-2ex}

Label $\overline{HK}$ by $x$. Then:

\vspace{-2ex}

\erh{10pt}
\begin{equationarray*}{rcl}
\frac{m}{s} &=& \frac{n}{x}\\
x&=&\frac{n}{m}s\,.
\end{equationarray*}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\vspace{-2ex}

\section{Find the intersection of two lines}\label{s.two-lines}

\textbf{Given two lines containing the line segments $\overline{AB}, \overline{CD}$, it is possible to construct their intersection using only a compass.}

Let $C',D'$ be the reflections of $C,D$ around $\overline{AB}$. $S$, the point of intersection of $\overline{CD}$ and $\overline{C'D'}$, lies on $\overline{AB}$, because $\triangle CZS\cong \triangle C'ZS$ by side-angle-side: $\overline{CZ}=\overline{C'Z}$, $\angle CZS=\angle C'ZS$ are right triangles and $\overline{ZS}$ is a common side. Therefore, $\overline{C'S}=\overline{CS}$ and similarly $\overline{D'S}=\overline{DS}$.

\begin{center}
\begin{tikzpicture}[scale=.8]
\coordinate (A) at (-4,0);
\coordinate (B) at (2,0);
\coordinate (C) at (-3,2);
\coordinate (D) at (1,-1);
\coordinate (Cp) at (-3,-2);
\coordinate (Dp) at (1,1);
\fill (A) node[below] {$A$} circle[radius=2pt];
\fill (B) node[below] {$B$} circle[radius=2pt];
\fill (C) node[above] {$C$} circle[radius=2pt];
\fill (D) node[below] {$D$} circle[radius=2pt];
\fill (Cp) node[below] {$C'$} circle[radius=2pt];
\fill (Dp) node[above] {$D'$} circle[radius=2pt];
\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);
\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);
\path [name intersections={of=ab and cd,by={S}}];
\fill (S) node[above] {$S$} circle[radius=2pt];
\draw (Cp) -- (Dp);
\draw[thick,dashed] (C) -- node[above left] {$c$} (Cp);
\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);
\path (C) -- node[right,xshift=2pt] {$x$} (S);
\path (S) -- node[left,near end,xshift=-2pt] {$e-x$} (D);
\node at (-.5,-2.5) {\mbox{\boldmath $\overline{CD}=\overline{C'D'}=e$}};
\fill (C|-A)  node[below right] {$Z$} circle[radius=2pt];
\draw (C|-A) rectangle +(8pt,8pt);
\end{tikzpicture}
\end{center}

Label $x=\overline{CS}, c=\overline{CC'}, d=\overline{DD'},e=\overline{CD}$. $\triangle CSC'\sim\triangle DSD'$ are similar so $\disfrac{x}{e-x} = \frac{c}{d}$. Solving the equation for $x$ gives $x=\disfrac{c}{c+d}e$.

If $C,D$ are on the same side of $\overline{AB}$:
\begin{center}
\begin{tikzpicture}[scale=.8]
\coordinate (A) at (-4,0);
\coordinate (B) at (2,0);
\coordinate (C) at (-3,2);
\coordinate (D) at (-1,1);
\coordinate (Cp) at (-3,-2);
\coordinate (Dp) at (-1,-1);
\fill (A) node[below] {$A$} circle[radius=2pt];
\fill (B) node[below] {$B$} circle[radius=2pt];
\fill (C) node[above] {$C$} circle[radius=2pt];
\fill (D) node[above] {$D$} circle[radius=2pt];
\fill (Cp) node[below] {$C'$} circle[radius=2pt];
\fill (Dp) node[below] {$D'$} circle[radius=2pt];
\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);
\draw[name path=cd] ($(C)!2.2!(D)$) -- ($(D)!1.1!(C)$);
\path [name intersections={of=ab and cd,by={S}}];
\fill (S) node[above] {$S$} circle[radius=2pt];
\draw (Cp) -- (S);
\draw[thick,dashed] (C) -- node[above left] {$c$} (Cp);
\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);
\path (C) -- node[above] {$e$} (D);
\path (Cp) -- node[below] {$e$} (Dp);
\path (D) -- node[above right,xshift=-4pt] {$x-e$} (S);
\path (Dp) -- node[below right,xshift=-4pt] {$x-e$} (S);
\node at (1,-2.5) {\mbox{\boldmath $\overline{CS}=\overline{C'S}=x$}};
\end{tikzpicture}
\end{center}
$\triangle CSC'\sim\triangle DSD'$ gives $\disfrac{x}{x-e}=\disfrac{c}{d}$. Solving for $x$ gives $x=\disfrac{c}{c-d}e$.

\medskip

Construct the circles $c(C',d), c(D,e)$ and label their intersection by $H$. The sum of the line segments $\overline{CC'}, \overline{C'H}$ is $c + d$. We have to show that $H$ is on the extension of $\overline{CC'}$ so that $\overline{CH}$ is a line segment of length $c+d$. ($\overline{CH} = c - d$ in case $D$ is on the same side of $\overline{AB}$ as $C$.)

\begin{center}
\begin{tikzpicture}[scale=.8]
\coordinate (A) at (-4,0);
\coordinate (B) at (2,0);
\coordinate (C) at (-3,2);
\coordinate (D) at (1,-1);
\coordinate (Cp) at (-3,-2);
\coordinate (Dp) at (1,1);
\fill (A) node[below left] {$A$} circle[radius=2pt];
\fill (B) node[below] {$B$} circle[radius=2pt];
\fill (C) node[above] {$C$} circle[radius=2pt];
\fill (D) node[below] {$D$} circle[radius=2pt];
\fill (Cp) node[left] {$C'$} circle[radius=2pt];
\fill (Dp) node[above] {$D'$} circle[radius=2pt];
\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);
\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);
\path [name intersections={of=ab and cd,by={S}}];
\fill (S) node[above,yshift=4pt] {$S$} circle[radius=2pt];
\draw (Cp) -- node[below right] {$e$} (Dp);
\path (C) -- node[above left] {$c$} (Cp);
\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);
\node at (3,-3) {\mbox{\boldmath $\overline{CD}=\overline{C'D'}=\overline{DH}=e$}};
\draw[name path=circled] (D) let
  \p1 = ($ (D) - (C) $),
  \n2 = {veclen(\x1,\y1)}
in
  ++(130:\n2) arc (130:230:\n2);

\draw[name path=circlecp] (Cp) let
  \p1 = ($ (D) - (Dp) $),
  \n2 = {veclen(\x1,\y1)}
in
  ++(-180:\n2) arc (-180:0:\n2);
\path [name intersections={of=circled and circlecp,by={H}}];
\fill (H) node[below left] {$H$} circle[radius=2pt];
\draw[thick,dashed] ($(C)!1.2!(H)$) -- (C);
\draw (H) -- node[right] {$d$} (Cp);
\draw (D) -- node[right,xshift=14pt,yshift=8pt] {$e$} (H);
\end{tikzpicture}
\end{center}

\vspace{-3ex}

From the definition of $H$ as the intersection of $c(C',d), c(D,e)$, we get $\overline{DH}=e$, $\overline{C'H}=d$, but $\overline{C'D'} = e$, $\overline{D'D}=d$, so the quadrilateral $\overline{C'D'DH}$ is a parallelogram, since the lengths of both pairs of opposite sides are equal. By construction, the line segment $\overline{DD'}$ is parallel to $\overline{CC'}$, so $\overline{C'H}$ is parallel to $\overline{DD'}$ is also parallel to $\overline{CC'}$. Since one of its end points is $C'$, it must be on the line containing $\overline{CC'}$.

The lengths $c,d,e$ are given and we proved in Section~\ref{s.add-subtract} that a line segment of length $c+d$ can be construction and in Section~\ref{s.three} that a line segment of length $x=\disfrac{c}{c+d}e$ can be constructed. $S$, the intersection of $c(C',x)$ and $c(C,x)$, is the intersection of $\overline{AB}, \overline{CD}$ has been constructed.

\begin{center}
\begin{tikzpicture}[scale=.8]
\coordinate (A) at (-4,0);
\coordinate (B) at (2,0);
\coordinate (C) at (-3,2);
\coordinate (D) at (1,-1);
\coordinate (Cp) at (-3,-2);
\coordinate (Dp) at (1,1);
\fill (A) node[below left] {$A$} circle[radius=2pt];
\fill (B) node[below] {$B$} circle[radius=2pt];
\fill (C) node[above] {$C$} circle[radius=2pt];
\fill (D) node[below] {$D$} circle[radius=2pt];
\fill (Cp) node[left] {$C'$} circle[radius=2pt];
\fill (Dp) node[above] {$D'$} circle[radius=2pt];
\draw[name path=ab] ($(A)!1.3!(B)$) -- ($(B)!1.3!(A)$);
\draw[name path=cd] ($(C)!1.2!(D)$) -- ($(D)!1.1!(C)$);
\path [name intersections={of=ab and cd,by={S}}];
\fill (S) node[above,yshift=4pt] {$S$} circle[radius=2pt];
\draw (Cp) -- (Dp);
\path (C) -- node[above,yshift=4pt] {$x$} (S);
\path (Cp) -- node[below,yshift=-4pt] {$x$} (S);
\path (C) -- node[above left] {$c$} (Cp);
\draw[thick,dashed] (D) -- node[above right] {$d$} (Dp);
\node at (2.5,-3) {\mbox{\boldmath $\overline{CD}=\overline{C'D'}=\overline{DH}=e$}};
\draw[name path=circled] (C) let
  \p1 = ($ (S) - (C) $),
  \n2 = {veclen(\x1,\y1)}
in
  ++(-10:\n2) arc (-10:-100:\n2);

\draw[name path=circlecp] (Cp) let
  \p1 = ($ (S) - (C) $),
  \n2 = {veclen(\x1,\y1)}
in
  ++(100:\n2) arc (100:0:\n2);
\draw[thick,dashed] (Cp) -- (C);
\end{tikzpicture}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Finding the intersection of a line and a circle}\label{s.line-circle}

\textbf{Given a circle $k=C(M,r)$ and a line $\overline{AB}$, construct their intersections using only a compass.}

Construct $M'$, be the reflection of $M$ about $\overline{AB}$ and the circle $k'=c(M',r)$. The points of intersection of $k,k'$ are the points of intersection of the line $\overline{AB}$ and the circle $k$.  This can be shown by congruent triangles, as indicated by the dotted lines in the diagram.

\begin{center}
\begin{tikzpicture}[scale=.5]
\coordinate (A) at (-7,0);
\coordinate (B) at (8,0);
\coordinate (M) at (0,-2);
\coordinate (Mp) at (0,2);
\fill (A) node[below] {$A$} circle[radius=3pt];
\fill (B) node[below] {$B$} circle[radius=3pt];
\fill (M) node[below left] {$M$} circle[radius=3pt];
\fill (Mp) node[above left] {$M'$} circle[radius=2pt];
\draw[name path=c1] (M) circle[radius=3cm];
\draw[name path=c2] (Mp) circle[radius=3cm];
\draw[name path=ab] ($(A)!1.2!(B)$) -- ($(B)!1.2!(A)$);
\path [name intersections={of=c1 and c2,by={S1,S2}}];
\fill (S1) circle[radius=3pt];
\fill (S2) circle[radius=3pt];
\path[name path=radius1] (M) -- ++(15:4cm);
\path [name intersections={of=c1 and radius1,by={R1}}];
\draw[thick,dashed] (M) -- node[below] {$r$} (R1);
\path[name path=radius2] (Mp) -- ++(40:4cm);
\path [name intersections={of=c2 and radius2,by={R2}}];
\draw[thick,dashed] (Mp) -- node[above] {$r$} (R2);
\fill (R1) circle[radius=3pt];
\fill (R2) circle[radius=3pt];
\draw[thick, dotted] (Mp) -- (M) -- (S1) -- (Mp) -- (S2) -- (M);
\draw (0,0) rectangle +(12pt,12pt);
\end{tikzpicture}
\end{center}

This construction cannot be done if $M$ is on the line $\overline{AB}$. In that case, extend and shorten $\overline{AM}$ by length $r$ as described in Section~\ref{s.add-subtract}. The end points of the extended and shortened segments are the intersections of $k$ with $\overline{AB}$.

\begin{center}
\begin{tikzpicture}[scale=.5]
\coordinate (A) at (-7,0);
\coordinate (B) at (8,0);
\coordinate (M) at (0,0);
\fill (A) node[below] {$A$} circle[radius=3pt];
\fill (B) node[below] {$B$} circle[radius=3pt];
\fill (M) node[below left] {$M$} circle[radius=3pt];
\draw[name path=c1] (M) circle[radius=3cm];
\draw[name path=ab] ($(A)!1.2!(B)$) -- ($(B)!1.2!(A)$);
\path[name path=radius1] (M) -- ++(-30:4cm);
\path [name intersections={of=c1 and radius1,by={R1}}];
\draw[thick,dashed] (M) -- node[below] {$r$} (R1);
\path [name intersections={of=c1 and ab,by={S1,S2}}];
\fill (S1) node[above right] {$\overline{AM}+r$} circle[radius=3pt];
\fill (S2) node[above left] {$\overline{AM}-r$} circle[radius=3pt];
\fill (R1) circle[radius=3pt];
\end{tikzpicture}
\end{center}


\subsection{System to Higher Order}
Let's say we have the linear system
\begin{equation*}
	\vec{x}' = A\vec{x} + \vec{f}
\end{equation*}
Writing the system using $x_1, \ldots x_n$ as the components of $\vec{x}$, $f_1, \ldots f_n$ as the components of $\vec{f}$, and $a_{ij}$ as the entry in $A$ on the $i^{th}$ row and $j^{th}$ column,
\begin{equation*}
	\begin{cases}
		x_1' = a_{11}x_1 + \ldots a_{1n}x_n + f_1 \\
		\vdots \\
		x_n' = a_{n1}x_1 + \ldots a_{nn}x_n + f_n
	\end{cases}
\end{equation*}
Let's arbitrarily assign $x_1 = y$. This will allow us to find expressions for $x_2, \ldots x_n$ in terms of $y$ and its derivatives. When we find $x_n$ in these terms and equate $x_n'$ with what's given in the system, we'll have an linear $n^{th}$ order equation.

\ifodd\includeLinearSystemsExamples\input{./linearSystems/systemsAndHigherOrder/systemToHigherOrder_example.tex}\fi

\noindent
The auxiliary polynomial of this higher order equation $p(r)$ and the characteristic polynomial $p(\lambda)$ of the linear system will have exactly the same roots.


\subsection{Math Functions}
\texttt{{\large\textbf{ceil}}}\textsf{(real:x):real}\\
 Round to the smallest integral value not less than x.

\hrulefill

\texttt{{\large\textbf{round}}}\textsf{(real:x):real}\\
 Round to the nearest integral value.

\hrulefill

\texttt{{\large\textbf{floor}}}\textsf{(real:x):real}\\
 Round to the largest integral value not greater than x.

\hrulefill

\texttt{{\large\textbf{sqrt}}}\textsf{(real:x):real}\\
 Returns the square root of a number.

\hrulefill

\texttt{{\large\textbf{pow}}}\textsf{(real:x, real:y):real}\\
 Returns a number x raised to the power y.

\hrulefill

\texttt{{\large\textbf{exp}}}\textsf{(real:x):real}\\
 Returns the base-e exponential of x.

\hrulefill

\texttt{{\large\textbf{log}}}\textsf{(real:x):real}\\
 Returns the base-e logarithm of x.

\hrulefill

\texttt{{\large\textbf{log10}}}\textsf{(real:x):real}\\
 Returns the base-10 logarithm of x.

\hrulefill

\texttt{{\large\textbf{pi}}}\textsf{(void):real}\\
 Returns the value of PI.

\hrulefill

\texttt{{\large\textbf{sgn}}}\textsf{(real:x):real}\\
 Returns 1 if the argument is greater than zero, 0 if argument is 0, otherwise -1.

\hrulefill

\texttt{{\large\textbf{abs}}}\textsf{(real:x):real}\\
 Returns the absolute value of a number.

\hrulefill

\texttt{{\large\textbf{sin}}}\textsf{(real:x):real}\\
 Computes the sine of x (radians)

\hrulefill

\texttt{{\large\textbf{cos}}}\textsf{(real:x):real}\\
 Computes the cosine of x (radians)

\hrulefill

\texttt{{\large\textbf{tan}}}\textsf{(real:x):real}\\
 Computes the tangent of x (radians)

\hrulefill

\texttt{{\large\textbf{asin}}}\textsf{(real:x):real}\\
 Computes the arc sine of x, result is in radians, -pi/2 to pi/2.

\hrulefill

\texttt{{\large\textbf{acos}}}\textsf{(real:x):real}\\
 Computes the arc cosine of x, result is in radians, 0 to pi.

\hrulefill

\texttt{{\large\textbf{atan}}}\textsf{(real:x):real}\\
 Computes the arc tangent of x, result is in radians, -pi/2 to pi/2.

\hrulefill

\texttt{{\large\textbf{atan2}}}\textsf{(real:x, real:y):real}\\
 Computes the arc tangent using both x and y to determine the quadrant of the result, result is in radians.

\hrulefill

\texttt{{\large\textbf{sind}}}\textsf{(real:x):real}\\
 Computes the sine of x (degrees)

\hrulefill

\texttt{{\large\textbf{cosd}}}\textsf{(real:x):real}\\
 Computes the cosine of x (degrees)

\hrulefill

\texttt{{\large\textbf{tand}}}\textsf{(real:x):real}\\
 Computes the tangent of x (degrees)

\hrulefill

\texttt{{\large\textbf{asind}}}\textsf{(real:x):real}\\
 Computes the arc sine of x, result is in degrees, -90 to 90.

\hrulefill

\texttt{{\large\textbf{acosd}}}\textsf{(real:x):real}\\
 Computes the arc cosine of x, result is in degrees, 0 to 180.

\hrulefill

\texttt{{\large\textbf{atand}}}\textsf{(real:x):real}\\
 Computes the arc tangent of x, result is in degrees, -90 to 90.

\hrulefill

\texttt{{\large\textbf{atan2d}}}\textsf{(real:x, real:y):real}\\
 Computes the arc tangent using both x and y to determine the quadrant of the result, result is in degrees.

\hrulefill

\texttt{{\large\textbf{nan}}}\textsf{(void):real}\\
 Returns the non-a-number (NAN) value.

\hrulefill

\texttt{{\large\textbf{isnan}}}\textsf{(number):boolean}\\
 Returns true if the argument is NaN.

\hrulefill

\texttt{{\large\textbf{mod}}}\textsf{(integer:x, integer:y):integer}\\
 Returns the remainder after integer division of x by y.

\hrulefill

\texttt{{\large\textbf{sum}}}\textsf{(...):real}\\
 Returns the numeric sum of all values passed to the function. Arguments can be arrays or numbers.

\hrulefill

\texttt{{\large\textbf{min}}}\textsf{(...):real}\\
 Returns the minimum of the numeric arguments.

\texttt{{\large\textbf{min}}}\textsf{(array):real}\\
 Returns the minimum value in an array of numbers

\emph{Notes:} Returns the minimum numeric value.

\hrulefill

\texttt{{\large\textbf{max}}}\textsf{(...):real}\\
 Returns the maximum of the passed numeric arguments.

\texttt{{\large\textbf{max}}}\textsf{(array):real}\\
 Returns the maximum value in an array of numbers

\emph{Notes:} Returns the maximum numeric value.

\hrulefill

\texttt{{\large\textbf{mean}}}\textsf{(...):real}\\
 Returns the mean (average) value all values passed to the function. Arguments can be arrays or numbers.

\hrulefill

\texttt{{\large\textbf{stddev}}}\textsf{(...):real}\\
 Returns the sample standard deviation of all values passed to the function. Uses Bessel's correction (N-1). Arguments can be arrays or numbers.

\hrulefill

\texttt{{\large\textbf{gammaln}}}\textsf{(real):real}\\
 Computes the logarithm of the Gamma function.

\hrulefill

\texttt{{\large\textbf{pearson}}}\textsf{(array:x, array:y):real}\\
 Calculate the Pearson linear rank correlation coefficient of two arrays.

\hrulefill

\texttt{{\large\textbf{besj0}}}\textsf{(real:x):real}\\
 Computes the value of the Bessel function of the first kind, order 0, J0(x)

\hrulefill

\texttt{{\large\textbf{besj1}}}\textsf{(real:x):real}\\
 Computes the value of the Bessel function of the first kind, order 1, J1(x)

\hrulefill

\texttt{{\large\textbf{besy0}}}\textsf{(real:x):real}\\
 Computes the value of the Bessel function of the second kind, order 0, Y0(x)

\hrulefill

\texttt{{\large\textbf{besy1}}}\textsf{(real:x):real}\\
 Computes the value of the Bessel function of the second kind, order 1, Y1(x)

\hrulefill

\texttt{{\large\textbf{besi0}}}\textsf{(real:x):real}\\
 Computes the value of the modified Bessel function of the first kind, order 0, I0(x)

\hrulefill

\texttt{{\large\textbf{besi1}}}\textsf{(real:x):real}\\
 Computes the value of the modified Bessel function of the first kind, order 1, I1(x)

\hrulefill

\texttt{{\large\textbf{besk0}}}\textsf{(real:x):real}\\
 Computes the value of the modified Bessel function of the second kind, order 0, K0(x)

\hrulefill

\texttt{{\large\textbf{besk1}}}\textsf{(real:x):real}\\
 Computes the value of the modified Bessel function of the second kind, order 1, K1(x)

\hrulefill

\texttt{{\large\textbf{erf}}}\textsf{(real):real}\\
 Calculates the value of the error function

\hrulefill

\texttt{{\large\textbf{erfc}}}\textsf{(real):real}\\
 Calculates the value of the complementary error function


\chapter{Collatz conjecture}

Let \(f(n) = n/2\) if \(n\) is even or \(3n+1\) if \(n\) is odd.

\(f(n) = (n \bmod 2) (n/2) + (1 - n \bmod 2) (3n + 1)\).

\(f(n) = (n \bmod 2) (n/2) + (3n + 1) - (n \bmod 2) (3n + 1)\).

\(f(n) = (n \bmod 2) (n/2 - (3n + 1)) + (3n + 1)\).

\(f(n) = (n \bmod 2) (2 - 5n)/2 + (3n + 1)\).

\(2 f(n) = (n \bmod 2) (2 - 5n) + 6n + 2\).

\(f(2n) = n\)

\(f(2n+1) = 3(2n+1)+1 = 6n+4 = 2(3n+2)\)

\(f(2n+2) = n+1\)

\(f(2n+3) = 3(2n+3)+1 = 6n+10 = 2(3n+5)\)

\(f(2n+2k) = n+k\)

\(f(2n+2k+1) = 2(3n+2+3k)\)

\(f(2n+2k+1) = 2(3(n+k)+2)\)

\(f(2(n+k)+1) = 2(3(n+k)+2)\)

\(f(2m+1) = 2(3m+2)\)... back to square 0

Let \(q\) be odd.
\begin{align*}
    f(2^{p+1} q) = 2^p q
    \\
    f(2^0 q) = 3q + 1
    \\
    f(2k+1) = 3(2k+1) + 1 = 6k+4 = 2(3k+2)
    \\
    f(2(2k)+1) = 3(4k+1) + 1 = 12k+4 = 4(3k+1)
    \\
    f(2(2k+1)+1) = 3(4k+3) + 1 = 12k+10 = 2(6k+5)
\end{align*}

\begin{align*}
    f(6n) &= 3n
    \\
    f(6n+1) &= 3(6n+1)+1 = 18n+4
    \\
    f(6n+2) &= 3n+1
    \\
    f(6n+3) &= 3(6n+3) + 1 = 18n+10
    \\
    f(6n+4) &= 3n+2
    \\
    f(6n+5) &= 3(6n+5) + 1 = 18n+16
\end{align*}

Let \(g(n) = f(2n)\) and \(h(n) = f(2n+1)\).

Let \(a(n,0) = n\) and \(a(n,k+1) = f(a(n,k))\).

Corollary: \(a(n,k+1) = a(f(n),k)\).

Corollary: If \(n\) is odd, then \(f(n)\) is even.

\section{Recursion}

Lemma: For every \(n\) and \(d \neq 0\), there exists \(q,d\) such that \(n = qd+m\) and \(0 \le m < d\).

\begin{align*}
    f(2n+0) &= n+0
    \\
    f(2n+1) &= 6n+4 = 2(3n+2)
    \\
    f(4n+0) &= 2n+0
    \\
    f(4n+1) &= 12n+4 = 4(3n+1)
    \\
    f(4n+2) &= 2n+1
    \\
    f(4n+3) &= 12n+10 = 2(6n+5)
    \\
    f(8n+0) &= 4n+0
    \\
    f(8n+1) &= 24n+4 = 4(6n+1)
    \\
    f(8n+2) &= 4n+1
    \\
    f(8n+3) &= 24n+10 = 2(12n+5)
    \\
    f(8n+4) &= 4n+2 = 2(2n+1)
    \\
    f(8n+5) &= 24n+16 = 8(3n+2)
    \\
    f(8n+6) &= 4n+3
    \\
    f(8n+7) &= 24n+22 = 2(12n+11)
    \\
    f(16n+0) &= 8n+0
    \\
    f(16n+1) &= 48n+4 = 4(12n+1)
    \\
    f(16n+2) &= 8n+1
    \\
    f(16n+3) &= 48n+10 = 2(24n+5)
    \\
    f(16n+4) &= 8n+2 = 2(4n+1)
    \\
    f(16n+5) &= 48n+16 = 16(3n+1)
    \\
    f(16n+6) &= 8n+3
    \\
    f(16n+7) &= 48n+22 = 2(24n+11)
    \\
    f(16n+8) &= 8n+4 = 4(2n+1)
    \\
    f(16n+9) &= 48n+28 = 4(12n+7)
    \\
    f(16n+10) &= 8n+5
    \\
    f(16n+11) &= 48n+34 = 2(24n+17)
    \\
    f(16n+12) &= 8n+6 = 2(4n+3)
    \\
    f(16n+13) &= 48n+40 = 8(6n+5)
    \\
    f(16n+14) &= 8n+7
    \\
    f(16n+15) &= 48n+46 = 2(24n+23)
    \\
    f(16n-1) &= 48n-2 = 2(24n-1)
    \\
    f(16n-5) &= 48n-14 = 2(24n-7)
\end{align*}

\begin{align*}
    f^2(4n) &= (gg)(n) = n
    \\
    f^2(4n+1) &= (gh)(n) = 6n+2 = 2(3n+1)
    \\
    f^2(4n+2) &= (hg)(n) = 6n+4 = 2(3n+2)
    \\
    f^2(4n+3) &= (gh)(n) = 6n+5
    \\
    f^3(8n) &= (ggg)(n) = n
    \\
    f^3(8n+1) &= f^2(24n+4) = (ggh)(n) = 6n+1
    \\
    f^3(8n+2) &= f^2(4n+1) = (ghg)(n) = 6n+2 = 2(3n+1)
    \\
    f^3(8n+3) &= f^2(24n+10) = (hgh)(n) = 36n+16 = 4(9n+4)
    \\
    f^3(8n+4) &= f(2n+1) = (ggg)(n) = 6n+4 = 2(3n+2)
    \\
    f^3(8n+5) &= f^2(24n+16) = (ggh)(n) = 6n+4 = 2(3n+2)
    \\
    f^3(8n+6) &= f^2(4n+3) = (hgh)(n) = 6n+5
    \\
    f^3(8n+7) &= f^2(24n+22) = f(12n+11) = (ghg)(n) = 36n+34 = 2(18n+17)
    \\
    f^p(2^p q+0) &= f^{p-1}(2^{p-1} q+0)
    \\
    f^p(2^p q+1) &= f^{p-1}(3 \cdot 2^{p-1} q+4)
\end{align*}

Lemma: \(f^3(8n+4) = f^3(8n+5)\).

Let \(g(n) = n/2\) and \(h(n) = 3n+1\).

\section{Equation}

\(2^p q = 3 n + 1\) where \(q\) is odd.

\(2^{p_0} q_0 = 3 n_0 + 1\) where \(q\) is odd.

\(2^{p_1} q_1 = 3 n_1 + 1\) where \(q\) is odd.

\(n_{k+1} = 2^{p_k} q_k\)

\section{Sequence}

Consider three mutual sequences \(p\), \(q\), and \(n\).

Input: \(q_0\).

Constraint: \(q_k\) odd.

\begin{align*}
    n_0 &= q_0
    \\
    n_{k+1} &= 3 q_k + 1
    \\
    n_k &= 2^{p_k} q_k
\end{align*}

Collatz conjecture: For every odd \(q_0 \in \Nat\), there exists \(k\) such that \(q_k = 1\).

Alternative: For every odd \(a\), there exists \(k\) and odd \(q_0\) such that \(q_k = a\).

Lemma: If \(n\) is even, then \(3n+1\) is odd.

Lemma: If \(n\) is odd, then \(3n+1\) is even.

\section{Composition}

\(u(n) = 1\) where \(u \in (f|g)^*\)

\(3(2n)+1 = 3(2n+1)-2\)

\section{Composition}

\((h \circ g)(n) = 3(n/2) + 1 = (3n+2)/2\)

\((g \circ h)(n) = (3n + 1)/2 = (3n+1)/2\)

\((h \circ g - g \circ h)(n) = 1/2\)

\section{Path}

Let \(P(a,b)\) mean that there is a path from \(a\) to \(b\) in the forward Collatz graph.

(Domain of discourse is \(\Nat\).
All unbound variables are universally quantified.)

Corollary: If \(P(f(a),b)\) then \(P(a,b)\).

Corollary: If \(n\) is odd and \(P(3n+1,a)\) then \(P(n,a)\).

Corollary: \(P(6n+4,a)\) then \(P(2n+1,a)\).

Corollary: If \(P(n,a)\) then \(P(2n,a)\).

Corollary: If \(n \bmod 3 = 1\) and \(P(n,a)\) then \(P(\frac{n-1}{3},a)\).

Lemma: There is no \(n\) such that \(n \bmod 2^p = 1\) for all \(p > 0\).

Lemma: \(P(2^p n, n)\).

Corollary: \(P(2^p,1)\).

Lemma: If \(P(a,2^p)\) then \(P(a,1)\).

Lemma: If \(P(q, 1)\) then \(P(2^p q,1)\).

Conjecture: If \(P(a,1)\) and \(P(b,1)\) then \(P(ab,1)\)?

Conjecture: If \(P(a,1)\) and \(P(b,1)\) then \(P(a+b,1)\)?

Lemma: If \(P(3n+2,1)\) then \(P(2n+1,1)\).

Lemma: If \(P(3n+1,1)\) then \(P(4n+1,1)\).

Lemma: If \(n\) is odd, then \(f(4n+1) = 4f(n)\).

Lemma: If \(p \ge 2\) then \(f(2^p n + 3) = 2(3 \cdot 2^{p-1} + 5)\).

Suppose \(P(n,1)\). Prove \(P(n+1,1)\).

If \(P(k,1)\) then \(P(2k,1)\).

If \(P(6k+4,1)\) then \(P(2k+1,1)\).

\section{Equivalence}

Lemma: Iff every \(6n+4\) has a path to \(2^p\), then the Collatz conjecture is true.

If \(3n+1 < 4\) and \(3n \bmod 2 = 1\) then \(P(n+1,1)\).

If \(3n+1 < 8\) and \(3n \bmod 4 = 1\) then \(P(3n+1,1)\).

If \(3n+1 < 16\) and \(3n \bmod 8 = 1\) then \(P(3n+1,1)\).

If \(3n+1 < 32\) and \(3n \bmod 16 = 1\) then \(P(3n+1,1)\).

\(\{ (p,N) ~|~ n \in N, ~ 3n \bmod 2^p = 1 \} = \{ (1,\{1,3,5,\ldots\}), (2,\{3,7,11,\ldots\}), (3,\{3,11,19,\ldots\}) \}\)

For all \(n,p\): Statement \(S(p)\) is: if \(3n+1 < 2^{p+1}\) and \(3n \bmod 2^p = 1\) then \(P(3n+1,1)\).

An inductive proof of \(S(p)\) is a proof of the Collatz conjecture.

\section{Representation}

In this section, the domain of discourse is \(\Nat\).

Assume \(n > 0\).
Define \(t(n)\) as the largest \(p\) such that \(n = 2^p q\).
Equivalent:
Define \(t(n)\) as the \(p\) such that \(n = 2^p q\) and \(q\) is odd.

Lemma:
For every positive \(n\), there exists \(p\) and odd \(q\) such that \(n = 2^p q\).

Lemma:
For every positive \(n\), there exists \(p\) and \(q < 2^p\) such that \(n = 2^p + q\).

Lemma: If \(b < 2^a\) then \(t(2^a + b) = \min(a,t(b))\).

Lemma: For every \(n\), there exist \(p,q\) such that \(3(2n+1)+1 = 2^p q\).

Corollary: Iff \(n\) is a power of two, then \(q = 1\).

If \(m = 2^a b\) and \(n = 2^c d\) then \(mn = 2^{a+c} (bd)\).

\begin{align*}
    (2^a b + 2^c d) \bmod 2^p = ?
\end{align*}

\(2^p \cdot 1 + 1 = 2^0 (2^p + 1)\).

If \(k\) is even then \(2^0 (2k + 1) + 1 = 2k + 2 = 2^1 (k+1)\).

\(2^0 (2(2k) + 1) + 1 = 4k+2 = 2^0(2k+1)\)

If \(k\) is even then \(2^0 (2(2k) + 3) + 1 = 4k+4 = 2^2(k+1)\)

\(t(1,2,3,4,5,\ldots) = 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,\ldots\)

\(t(2,4,6,8,10,\ldots) = 1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,\ldots\)

\(t(k)\) is the number of trailing zero bits in the binary representation of \(k\)

Lemma: \(t(k) \cdot t(k+1) = 0\)

Lemma: \(t(ab) = t(a) + t(b)\)

If \(t(k) \ge 1\) then \(2^0 (2^p k+1) + 1 = 2^p k + 2 = 2^p (k+1)\)

If \(t(k) \ge 1\) then \(t(2^a k+1) = a\)

\(t(3k) = t(k)\)

Under what circumstances are \(3(2n+1)+1 = 2^p\) (that is \(q=1\))?

\(6n+4 = 2^p\).

\(1 \equiv 2^p \pmod 3\).
Corollary: Iff \(p\) is even then \(2^p+2\) is even and divisible by 3.

Corollary: If \(t(n) > 0\) then \(t(f(n)) = t(n)-1\).

\[
    g(n) =
    \begin{cases}
        \{2n\} & \text{if } n \bmod 3 \in \{0,2\}
        \\
        \{2n, \frac{n-1}{3}\} & \text{if } n \bmod 3 = 1
    \end{cases}
\]

Let \(G(N) = \bigcup_{n \in N} g(n)\).

Let \(H_0 = \{1\}\) and \(H_{k+1} = H_k \cup G(H_k)\).

\(H \sim \{1\}, \{2,1,0\}, \{4,2,1,0\}, \{8,4,2,1,0\}, \{16,8,5,4,2,1,0\}, \{32,16,10,8,5,4,2,1,0\}\)

\(\forall k : H_k \subset H_{k+1}\)

Collatz conjecture: for every \(N \subseteq \Nat - \{1\}\), there exists \(p \in \Nat\) such that \(N \subseteq G^p(\{1\})\).

Conjecture: \(G(\Nat) = \Nat\).

\section{Collatz graph}

Graph \((V,E)\)

\((2n,n) \in E\)

\((2n+1,3(2n+1)+1) \in E\), that is
\((2n+1,6n+4) \in E\)

\((2,1),(4,2),(6,3),(8,4),(10,5),\ldots\)

\((1,4),(3,10),(5,16),(7,22),(9,28),\ldots\)

Prove that there is a path from every positive \(n\) to 1.

Inverse graph

\((n,2n) \in E'\)

\((6n+4,2n+1) \in E'\)

Prove that there is a path from 1 to every positive \(n\).

Can we transform \(f\) into a monotonically increasing function?


\section{Introduction: Proofs and why we want them}
Vaguely speaking, a proof is a kind of logical argument (or a series of it) which establishes a conclusion.
This is not the most rigorous way to define it, but it would be enough for now.
The big question, however, is why we need them.
Why can't we just assume something that looks nice to be correct?
Why can't we declare something to be right if it holds merely for the scope that we can reach?
Of course, there is an answer.
If not, mathematics would not have existed.
\subsection{Why we need proofs}
There are a few reasons why proofs are important and essential.
The obvious one is that we need to be sure about the truthfulness of something.
There are tonnes of example in mathematcis where a theorem holds for a shockingly large selection of numbers but not for all.
We could, of course, give some silly examples like the claim ``all positive integers are less than $N$'' where you can substitute $N$ for some very large integer, but there is a more interesting example:
\begin{example}[Polya's Conjecture]
    For any positive integer $N>2$, at least half of the positive integers less than or equal to $N$ has an odd number of prime factors (counting multiplicity).
\end{example}
\begin{proof}[Disproof]
    The smallest counterexample occurs at $N=906150257$.
\end{proof}
We do have computers now that can test some of our conjectures up to some very large numbers, but for mathematicians, most of those computational powers are useless,
\footnote{There are some proofs that harness the power of computers, like the four-color theorem. But still -- it is the proof we need, not any sort of verification.}
since they can do nothing about how the general picture is like.
\subsection{Why we want proofs}
We can need something that we don't want, like nuclear weapons.
However, this is not the case for proofs.
We need them, yes.
But we still want them, desperately.
Some say that the study of language is proofreading, then the study of mathematics would be proof-reading.
What we really want is not only the however elegant results that we, or someone else, have proven.
We should be more attracted to the (clever) idea behind.
Why? Because if we come through another statement of similar kind, it would be in our advantage to solve them using the same technique.
After all, mathematics is a creative art (of problem-solving).
Quoting theorems won't get you anywhere in maths, what you really need is to empower yourself with the tricks in the proof.
\subsection{Correct and incorrect proofs}
First let us see how a correct proof is done:
\begin{claim}
    For any integer $n$, $n^3-n$ is a multiple of $3$.
\end{claim}
Note that when you state some variable, you need to state as well where its home is at.
The statement would be false if $n$ is not restricted to integers.
Now here comes the proof.
\begin{proof}
    $n^3-n=(n-1)n(n+1)$. Since one of any three consecutive integers is a multiple of $3$, one of $n-1,n,n+1$ is. So $n^3-n$ is a multiple of $3$.
\end{proof}
A proof almost always comes with a smart idea.
The ``smart'' here doesn't necessarily mean that it is really smart, but a very important point that constitutes the basic of (part of) the proof.
In this case, the smart idea is to try and factorize the expression to something that we can easily handle, which makes the problem quite obivous.\\
Now here come a non-proof, or incorrect proof:
\begin{claim}
    Let $n$ be a integer. If $n^2$ is even, so is $n$.
\end{claim}
\begin{proof}[Non-proof]
    If $n$ is even, then $n=2k$ for some integer $k$, so $n^2=4k^2=2(2k^2)$. Therefore $n^2$ is even.
\end{proof}
Is it factually wrong? No.
The logic in the proof itself is impeccable.
So both the statement and the proof logic is correct, what is wrong?
Quite obviously, it has proved the wrong thing.
We want something like $A\implies B$, but what has been proven is $B\implies A$.
So even both the statement and the proof logic are alright, it might still not be a proof.
(Needless to say, if either of these two things is not, it would not be a proof either.)
So back on the track.
\begin{proof}
    If $n^2$ even but $n$ is not, then $n=2k+1$ for some integer $k$, so $n^2=4k^2+4k+1=2(2k^2+2k)+1$ which is odd. This is a contradiction.
\end{proof}
This is a new way of proof. We do not take $A\implies B$ directly, but we use $\lnot B\implies\lnot A$.
The equivalence of these two is called \textit{reducio ad absurdum}, and the trick to use this in the proof is called a \textit{proof by contradiction}.
\subsection{``iff''}
We want to prove the following claim:
\begin{claim}
    The solutions to $x^2-5x+6$ are $x=2$ and $x=3$.
\end{claim}
Note that this claim is actually two claims: that $2,3$ are indeed solutions to the equation, and that the equation does not have any other solutions.
Therefore, to rephrase the question, we want to prove that $x^2-5x+6=0$ \textit{if and only if} $x=2$ or $x=3$.
Here, \textit{if and only if} means, well, what it literally means, that the two statements are equivalent to each other.
They are interchangable and any one of them implies the other.
So our proof must consist of both the forward and backward implication.
Otherwise, it would be incomplete.
One way of doing it is to seperately prove both sides of the claim, but we can also use a chain of "iff"s:
\begin{proof}
    $x^2-5x+6=0\iff (x-2)(x-3)=0\iff (x=2\lor x=3)$
\end{proof}
However, if such a proof is to be used, one must make sure that the adjascent statements are indeed equivalent to each other.
\subsection{Implicit use of assumption}
The final proof error that we state here would be that sometimes we use an inappropriate assumption in the proof which make it invalid.
Consider the following claim:
\begin{claim}
    $1$ is the smallest positive real number.
\end{claim}
\begin{proof}[Nonsense]
    Let $r$ be the smallest positive real number.
    If $r<1$, then $r^2<r$, contradiction.
    If $r>1$, then $\sqrt r<r$, contradiction.
    Therefore $r=1$
\end{proof}
Why is this nonsense a nonsense?
Because the proof (and the claim) both used a wrong assumption that there exists a smallest positive real number.
But there isn't.
Actually, the above proof and the fact that $1/2<1$ provides a proof of this fact.\\
So in proofs, we cannot assume, and need to avoid assuming implicitly, anything that might not be correct.
If you get to assume something, prove it first.\\
Now that we are done with proofs, here comes the genuine stuff.


\section{Elementary operations}

\begin{outcome}
  \begin{enumerate}
  \item Use elementary operations to simplify a system of equations.
  \item Solve some systems of equations by back substitution.
  \item Write a system of equations in augmented matrix form.
  \item Perform elementary row operations on augmented matrices.
  \end{enumerate}
\end{outcome}

Our strategy for solving systems of linear equations is to
successively transform a difficult system of equations into a simpler
equivalent system. Here, by an ``equivalent'' system of equations we
mean one that has the same solutions as the original one. We will
perform the process of simplifying a system of equations by applying
certain basic steps called ``elementary operations''.

\begin{definition}{Equivalent systems}{equivalent-systems}
  Two systems of equations are called
  \textbf{equivalent}%
  \index{system of linear equations!equivalence}%
  \index{equivalence!system of linear equations}
  if they have the same solutions. This means that every solution of
  the first system is also a solution of the second system, and every
  solution of the second system is also a solution of the first system.
\end{definition}

How can we know whether two systems of equations are equivalent? It
turns out that the following basic operations always transform a
system of equations into an equivalent system. In fact, these
operations are the {\em key tool} we use in linear algebra to solve
systems of equations.

\begin{definition}{Elementary operations}{elementary-operations}
  \textbf{Elementary operations}%
  \index{elementary operation} are the
  following operations:

  \begin{enumerate}
  \item Interchange the order in which the equations are listed.

  \item Multiply any equation by a non-zero scalar.

  \item Add a multiple of one equation to another equation.
  \end{enumerate}
\end{definition}

The most important property of the elementary operations is that they
do not change the solutions to the system of equations. Before proving
that this is true in general, we will first verify it in an example.

\begin{example}{Equivalent systems}{equivalent-systems}
  Show that the systems
  \begin{equation*}
    \begin{array}{r@{~}c@{~}l}
      x+2y&=&7 \\
      -2x  &=& -6
    \end{array}
  \end{equation*}
  and
  \begin{equation*}
    \begin{array}{r@{~}c@{~}l}
      x+2y&=&7 \\
      4y &=& 8
    \end{array}
  \end{equation*}
  are equivalent.
\end{example}

\begin{solution}
  We can see that the second system is obtained from the first one by
  applying an elementary operation, namely, adding 2 times the first
  equation to the second equation:
  \begin{equation*}
    -2x + 2(x+2y) = -6 + 2(7)
  \end{equation*}
  By simplifying, we obtain $4y = 8$.

  To verify that the two systems are indeed equivalent, let us first
  solve the first system. From the second equation, we see that
  $x=3$. Substituting $x=3$ into the first equation, the equation
  becomes $3+2y=7$, which we can solve to find $y=2$. Therefore, the
  only solution to the first system of equations is $(x,y) = (3,2)$.

  Now let us solve the second system. From the second equation, we
  find that $y=2$. Substituting $y=2$ into the first equation, we get
  $x+4=7$, which we can solve to find $x=3$. Therefore, the only
  solution to the second system of equations is $(x,y) = (3,2)$.
  Since the two systems have the same solutions, they are equivalent.
\end{solution}

This example illustrates how an elementary operation applied to a
system of two equations in two variables does not affect the set of
solutions. The same is true for any size of system in any number of
variables.  In the following theorem, we use the notation $E_i$ to
represent the left-hand side of an equation, while $b_i$ denotes a
constant term.

\begin{theorem}{Elementary operations and solutions}{elementary-operations-and-solutions}
  Suppose you have a system of two linear equations in any number of variables
  \begin{equation}
    \begin{array}{c}
      E_1=b_1 \\
      E_2=b_2.
    \end{array} \label{system}
  \end{equation}
  Then the following systems are equivalent to \eqref{system}:
  \begin{enumerate}
  \item   \begin{equation}
      \begin{array}{c}
        E_2=b_2 \\
        E_1=b_1.
      \end{array}
      \label{thm-1.9.1}
    \end{equation}
  \item  \begin{equation}
      \begin{array}{c}
        E_1=b_1 \\
        kE_2=kb_2 \\
      \end{array}
      \label{thm-1.9.2}
    \end{equation}
    for any scalar $k$, provided $k\neq0$.
  \item \begin{equation}
      \begin{array}{c}
        E_1=b_1 \\
        E_2+kE_1=b_2+kb_1
      \end{array}
      \label{thm-1.9.3}
    \end{equation}
    for any scalar $k$ (including $k=0$).

  \end{enumerate}
\end{theorem}

\begin{proof}
  \begin{enumerate}
  \item By definition, a solution of \eqref{system} is an assignment of
    scalars to the variables that is a solution to $E_1=b_1$ and to
    $E_2=b_2$. But that is exactly the same thing as a solution of
    \eqref{thm-1.9.1}.

  \item To prove that the systems \eqref{system} and \eqref{thm-1.9.2}
    have the same solution set, let $(x_1,\ldots,x_n)$ be
    any solution of \eqref{system}. Then $E_1=b_1$ and $E_2=b_2$ are
    both true. Multiplying both sides of the last equation by $k$, we
    know that $kE_2=kb_2$ is true, and so
    $(x_1,\ldots,x_n)$ is a solution of
    \eqref{thm-1.9.2}. Conversely, let $(x_1,\ldots,x_n)$
    be any solution of \eqref{thm-1.9.2}.  Then $E_1=b_1$ and $kE_2=kb_2$
    are true. Because $k\neq 0$, we are allowed to divide both sides of
    the last equation by $k$, and therefore $E_2=b_2$ is true. Hence,
    $(x_1,\ldots,x_n)$ is also a solution of
    \eqref{system}. Since we have shown that every solution of
    \eqref{system}  is a solution of \eqref{thm-1.9.2} and vice versa,
    the two systems are equivalent.

  \item To prove that the systems \eqref{system} and \eqref{thm-1.9.3}
    have the same solution set, let $(x_1,\ldots,x_n)$ be
    any solution of \eqref{system}. Then $E_1=b_1$ and $E_2=b_2$ are
    both true. We multiply both sides of the first equation by $k$ to
    obtain $kE_1=kb_1$. Then $kE_1+E_2 = kb_1+b_2$, and hence
    $(x_1,\ldots,x_n)$ is a solution of
    \eqref{thm-1.9.3}. For the converse direction, assume
    $(x_1,\ldots,x_n)$ is a solution of $E_1=b_1$ and
    $kE_1+E_2 = kb_1+b_2$. From the first equation, we have $kE_1=kb_1$,
    and subtracting this from the second equation, we get $E_2=b_2$,
    hence $(x_1,\ldots,x_n)$ is a solution of
    \eqref{system}. Note that unlike in case 2., there was no need to
    divide by $k$, and therefore it was not necessary to require $k\neq 0$.
  \end{enumerate}
\end{proof}

We will now use elementary operations to solve a system of three
equations and three variables.

\begin{example}{Solving a system of equations with elementary operations}{solving-a-system-with-elementary-operations}
  Solve the system of equations
  \begin{equation*}
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&+&3y&+&6z&=&25 \\
      2x&+&7y&+&14z&=&58 \\
       &&2y&+&5z&=&19.
    \end{array}
    \label{solving-a-system1}
  \end{equation*}
\end{example}

\begin{solution}
  By Theorem~\ref{thm:elementary-operations-and-solutions}, we can do
  elementary operations on this system without changing the solution
  set. We will therefore use elementary operations to try to simplify
  the system of equations.  First, we add $(-2)$ times the
  first equation to the second equation. This yields the system
  \begin{equation*}
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&+&3y&+&6z&=&25 \\
       &&y&+&2z&=&8 \\
       &&2y&+&5z&=&19.
    \end{array}
    \label{solving-a-system2}
  \end{equation*}
  Next, we add $(-2)$ times the second equation to the
  third equation. This yields the system
  \begin{equation}\label{solving-a-system3}
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&+&3y&+&6z&=&25 \\
       &&y&+&2z&=&8 \\
       &&&&z&=&3.
    \end{array}
  \end{equation}
  At this point, it is easy to find the solution. The last equation
  tells us that $z=3$. We can substitute this value of $z$ back into
  the second equation to get
  \begin{equation*}
    y+2(3)=8,
  \end{equation*}
  which we can simplify and solve for $y$ to find that $y=2$. Finally,
  we can substitute the values $z=3$ and $y=2$ back into the first
  equation to get
  \begin{equation*}
    x+3(2)+6(3)=25.
  \end{equation*}
  Simplifying and solving for $x$, we find that $x=1$. Hence, the
  solution to the system is $(x,y,z)=(1,2,3)$.

  The process we followed for solving \eqref{solving-a-system3} by
  first computing $z$, then $y$, then $x$ is called \textbf{back
    substitution}%
  \index{back substitution}.  Alternatively, we could have continued
  from \eqref{solving-a-system3} with more elementary operations as
  follows. Add $(-2)$ times the third equation to the second and then
  add $(-6)$ times the third to the first. This yields
  \begin{equation*}
    \allowbreak
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&+&3y&&&=&7 \\
       &&y&&&=&2 \\
       &&&&z&=&3.
    \end{array}
  \end{equation*}
  Now add $(-3)$ times the second to the first. This yields
  \begin{equation*}
    \allowbreak
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&&&&&=&1 \\
       &&y&&&=&2 \\
       &&&&z&=&3,
    \end{array}
  \end{equation*}
  a system which has the same solution set as the original
  system. This second method avoided back substitution and led to the
  same solution set. It is your decision which you prefer to use, as
  both methods lead to the correct solution,
  $(x,y,z) = (1,2,3)$.
\end{solution}

Note how we have written each system of equations so that ``like''
variables line up on columns: one column for $x$, one column for $y$,
and one column for $z$. This makes it easier to perform elementary
operations. It is often useful to simplify the notation further,
writing systems of equations in \textbf{augmented matrix}%
\index{augmented matrix|seealso{matrix}}%
\index{matrix!augmented matrix} notation. Recall the
system of equations from Example~\ref{exa:solving-a-system-with-elementary-operations}:
\begin{equation*}
  \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
    x&+&3y&+&6z&=&25 \\
    2x&+&7y&+&14z&=&58 \\
     &&2y&+&5z&=&19.
  \end{array}
\end{equation*}
This system can be written as an augmented matrix as follows:
\begin{equation*}
  \begin{mymatrix}{rrr|r}
    1 & 3 & 6 & 25 \\
    2 & 7 & 14 & 58 \\
    0 & 2 & 5 & 19
  \end{mymatrix}.
\end{equation*}
A \textbf{matrix}%
\index{matrix} is just a $2$-dimensional array of numbers. An
augmented matrix has two parts separated by a vertical line. Notice
that the augmented matrix notation has exactly the same information as
the original system of equations. All the coefficients are written on
the left side of the vertical line, and all the constant terms are
written on the right side of the vertical line. These two parts of the
augmented matrix are also called the \textbf{coefficient matrix}%
\index{coefficient matrix}%
\index{matrix!coefficient matrix} and the \textbf{constant matrix}%
\index{constant matrix}%
\index{matrix!constant matrix}.  Each row of the augmented matrix
corresponds to one linear equation. For example, the top row
$\begin{mymatrix}{rrrrr} 1 & 3 & 6 & | & 25
\end{mymatrix}$
corresponds to the equation
\begin{equation*}
  x+3y+6z=25.
\end{equation*}
Each column of the coefficient matrix contains the coefficients
for one particular variable. For example, the first column $\begin{mymatrix}{r}
  1 \\
  2 \\
  0
\end{mymatrix}$ contains all of the coefficients for the variable $x$. If a
variable does not appear in an equation, the corresponding coefficient
is $0$. In general, the augmented matrix of a linear system of
equations is defined as follows.

\begin{definition}{Augmented matrix of a system of linear equations}{augmented-matrix}
  The \textbf{augmented matrix}%
  \index{augmented matrix}%
  \index{matrix!augmented matrix} of the system of linear equations
  \begin{equation*}
    \begin{array}{c}
      a_{11}x_1 + \ldots + a_{1n}x_n = b_1 \\
      \vdots \\
      a_{m1}x_1 + \ldots + a_{mn}x_n = b_m
    \end{array}
  \end{equation*}
  is
  \begin{equation*}
    \begin{mymatrix}{ccc|c}
      a_{11} & \cdots & a_{1n} &  b_1 \\
      \vdots &  & \vdots &  \vdots \\
      a_{m1} & \cdots & a_{mn} &  b_m
    \end{mymatrix}.
  \end{equation*}
\end{definition}

We can consider elementary operations in the context of the augmented
matrix. The elementary operations can be used on the rows of an
augmented matrix just as we used them on equations previously. For
example, instead of adding a multiple of one equation to another, we
will now be adding a multiple of one row to another. Note that
Theorem~\ref{thm:elementary-operations-and-solutions} implies that any
elementary row operation used on an augmented matrix will not change
the solutions to the corresponding system of equations. For reference,
here are the three kinds of elementary row operations, along with a
shorthand notation we are going to use for them.

\begin{definition}{Elementary row operations}{row-operations}
  The \textbf{elementary row operations}%
  \index{matrix!row operation}%
  \index{matrix!elementary row operation}%
  \index{row operation}%
  \index{elementary row operation} are the
  following:
  \begin{enumerate}
  \item Switch two rows. (Notation: $R_i\rowswap R_j$ to switch
    rows $i$ and $j$).
  \item Multiply a row by a non-zero number.  (Notation: $R_i\rowop
    kR_i$ to multiply row $i$ by $k$).
  \item Add a multiple of one row to another row. (Notation:
    $R_i\rowop R_i+kR_j$ to add $k$ times row $j$ to row $i$.)
  \end{enumerate}
\end{definition}

We write ``$\roweq$'' to indicate that two augmented matrices are
equivalent, i.e., that the corresponding systems of equations have the
same set of solutions.

\begin{example}{Elementary row operations}{}
  Repeat the calculations of
  Example~\ref{exa:solving-a-system-with-elementary-operations}, using the
  notations we just introduced.
\end{example}

\begin{solution}
  We have:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      1 & 3 & 6 &  25 \\
      2 & 7 & 14 &  58 \\
      0 & 2 & 5 &  19
    \end{mymatrix}
    \stackrel{R_2\rowop R_2-2R_1}{\roweq}
    \begin{mymatrix}{rrr|r}
      1 & 3 & 6 & 25 \\
      0 & 1 & 2 & 8 \\
      0 & 2 & 5 & 19
    \end{mymatrix}
    \stackrel{R_3\rowop R_3-2R_2}{\roweq}
    \begin{mymatrix}{rrr|r}
      1 & 3 & 6 & 25 \\
      0 & 1 & 2 & 8 \\
      0 & 0 & 1 & 3
    \end{mymatrix}.
  \end{equation*}
  The final augmented matrix corresponds to the system
  \begin{equation*}
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      x&+&3y&+&6z&=&25 \\
       &&y&+&2z&=&8 \\
       &&&&z&=&3,
    \end{array}
  \end{equation*}
  which is the same as {\eqref{solving-a-system3}}. We can solve it by back
  substitution to obtain the solution $x=1$, $y=2$, and $z=3$.

  Alternatively, we can continue with additional row operations:
  \begin{equation*}
    \begin{mymatrix}{rrr|r}
      1 & 3 & 6 & 25 \\
      0 & 1 & 2 & 8 \\
      0 & 0 & 1 & 3
    \end{mymatrix}
    \stackrel{R_1\rowop R_1-6R_3}{\stackrel{R_2\rowop R_2-2R_3}{\roweq}}
    \begin{mymatrix}{rrr|r}
      1 & 3 & 0 & 7 \\
      0 & 1 & 0 & 2 \\
      0 & 0 & 1 & 3
    \end{mymatrix}
    \stackrel{R_1\rowop R_1-3R_2}{\roweq}
    \begin{mymatrix}{rrr|r}
      1 & 0 & 0 & 1 \\
      0 & 1 & 0 & 2 \\
      0 & 0 & 1 & 3
    \end{mymatrix}.
  \end{equation*}
  Notice how this notation is much more succinct than what we used in
  Example~\ref{exa:solving-a-system-with-elementary-operations}.
\end{solution}

We end this section with a final word of caution: logically, you can
only perform one elementary row operation at a time. For example, it
would not be correct to simultaneously add $R_1$ to $R_2$ and add
$R_2$ to $R_1$. What is permitted is to first add $R_1$ to $R_2$, then
then add the {\em new} $R_2$ to $R_1$. Although we may sometimes try
to save space by skipping an intermediate step, as in the last example
where we applied the row operations $R_1\rowop R_1-6R_3$ and
$R_2\rowop R_2-2R_3$ in one step, it is important to realize that
logically, each row operation must be performed separately before the
next one can be done. When in doubt, the only safe course of action is
not to skip any steps.