\documentclass{article}

\def\ifsoln{\iftrue}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{comment}
\usepackage{booktabs}
\usetikzlibrary{decorations.markings}

\newtheorem{theorem}{Theorem}
\theoremstyle{definition}
\newtheorem{question}{Question}
\newtheorem{definition}{Definition}

\def\afterelse#1\else#2\fi{\fi#1}

\ifsoln\afterelse
\newenvironment{answer}{}{}
\else
\excludecomment{answer}
\fi

\begin{document}

\date{\today}
\author{Your name}
\title{Latex tutorial}
\maketitle

\begin{question}
	Use summation notation ($\sum_{i = 1}^n$) to rewrite the following expression without ellipses:
\begin{equation*}
1 + \frac{1}{4} + \frac{1}{9} + \frac{1}{16} + \cdots = 
\end{equation*}
\end{question}

\begin{question}
Below is a piece of the topograph for $L(x,y) = 16x + 31y$.  Extend it until you get the gcd.
\begin{center}
\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]
\node[draw,circle,fill] (A) at (-1,0) {};
\node[draw,circle,fill] (B) at (1,0) {};
\node (C) at (-2,1) {};
\node (D) at (-2,-1) {};
\node (E) at (2,-1) {};
\node (F) at (2,1) {};
\draw (A) -- (B);
\draw (A) -- (C);
\draw (A) -- (D);
\draw (B) -- (E);
\draw (B) -- (F);
\node[draw=none] at (0,.8) {$\pm 16$};
\node[draw=none] at (0,.4) {\scriptsize $\pm (1,0)$};
\node[draw=none] at (0,-.4) {$\pm 31$};
\node[draw=none] at (0,-.8) {\scriptsize $\pm (0,1)$};
\end{tikzpicture}
\end{center}
\end{question}

\begin{definition}
An integer $n$ is called \emph{irreducible} if it is not a unit and it cannot be factored as a product $xy$ unless $x$ or $y$ is a unit.
\end{definition}

\begin{question}
Write the definition of a prime integer.
\end{question}

\begin{theorem}
Every prime integer is irreducible.
\end{theorem}
\begin{proof}
Suppose that $p$ is a prime integer.  Then $p$ is not a unit by definition.  Suppose that $p = xy$ for some integers $x$ and $y$.  We want to show $x$ or $y$ is a unit.  Since $p = xy$, we know that $p$ divides $xy$, so by definition of primality, $p$ must divide $x$ or $p$ must divide $y$.  Without loss of generality, we may suppose that $p$ divides $x$.  Then $p$ divides $x$ and $x$ divides $p$, so $|p| \leq |x| \leq |p|$, which implies $|p| = |x|$.  Thus $x = \pm p$, which implies that $y = \pm 1$.  Thus $y$ is a unit.  This shows that in any factorization of $p$ into $xy$, either $x$ or $y$ must be a unit.
\end{proof}

\begin{question}
State and prove a theorem to the effect that irreducible integers are prime.
\end{question}

\begin{question}
The matrices below show a sequence of column operations to solve the linear equation $6x + 10y = 2$:
\begin{gather*}
\begin{pmatrix} 10 & \multicolumn{1}{c|}{6} & 2 \\ \cmidrule(lr){1-2} 1 & 0 \\ 0 & 1 \end{pmatrix} \qquad
\begin{pmatrix} 4 & \multicolumn{1}{c|}{6} & 2 \\ \cmidrule(lr){1-2} 1 & 0 \\ -1 & 1 \end{pmatrix} \qquad
\begin{pmatrix} 4 & \multicolumn{1}{c|}{2} & 2 \\ \cmidrule(lr){1-2} 1 & -1 \\ -1 & 2 \end{pmatrix} \\
\begin{pmatrix} 2 & \multicolumn{1}{c|}{2} & 2 \\ \cmidrule(lr){1-2} 2 & -1 \\ -3 & 2 \end{pmatrix} \qquad
\begin{pmatrix} 0 & \multicolumn{1}{c|}{2} & 2 \\ \cmidrule(lr){1-2} 3 & - 1 \\ -5 & 2 \end{pmatrix} 
\end{gather*}
From this we read off that the solutions are $(-1,2) + k (3,-5)$, where $k$ is allowed to be any integer.  Find all solutions to the following system of equations:
\begin{align*}
10x + 18y + 15z & = 1  \\
9x + 12y + 14z  & = 3
\end{align*}
\end{question}

\begin{question}
	Suppose we started at a position in the topograph that looks like this:
	\begin{center}
\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]
\node[draw,circle,fill] (A) at (-1,0) {};
\node[draw,circle,fill] (B) at (1,0) {};
\node (C) at (-2,1) {};
\node (D) at (-2,-1) {};
\node (E) at (2,-1) {};
\node (F) at (2,1) {};
\draw (A) -- (B);
\draw (A) -- (C);
\draw (A) -- (D);
\draw (B) -- (E);
\draw (B) -- (F);
%\node[draw=none] at (0,.8) {$\pm 16$};
\node[draw=none] at (0,.5) {$\pm (a,b)$};
%\node[draw=none] at (0,-.4) {$\pm 31$};
\node[draw=none] at (0,-.5) {$\pm (c,d)$};
\end{tikzpicture}
\end{center}
Let $L(x,y) = -bx + ay$.  At each position in the topograph labelled by the vector $(x,y)$ place the number $|L(x,y)|$ and label the edges with arrows in the direction of increase of $|L(x,y)|$.  Here's a picture of an arrow to get you started:
	\begin{center}
	\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}, arrow/.style={decoration={markings, mark=at position .5 with {\arrow{>}}},postaction={decorate}}]
\node (A) at (-1,0) {};
\node (B) at (1,0) {};
\draw[arrow] (A) -- (B);
\end{tikzpicture}
\end{center}
\end{question}

\end{document}
