%
% homework.tex:  A LaTeX 2e source file that demonstrates the formatting
%                of CSc 245 homework answers.
%
% Author:  L. McCann (2017/08/09)
%
% To produce a PDF from this file, first make sure that the plot2.png file
% is in the same directory as this file (homework.tex).  Use pdflatex from
% the lectura command line to produce a formatted PDF file from it:
%
%    pdflatex homework.tex
%
% You should find the resulting PDF file homework.pdf in the same directory.
% Use a PDF document viewer (acroread, evince, etc.) to read it.
%
% I have set up this file to produce (for the most part) a typical
% PDF with CSc 245 homework solutions.  I chose sample problems from the
% Rosen text (7th edition) whose solutions demonstrate useful LaTeX
% commands and techniques.  When I first used a command, I added a 
% comment to help explain it.  The exceptions are tables and math
% expressions; those are too complicated to explain completely with comments.
% For those, I refer you to some of the reference materials I've listed
% in the LaTeX web page linked to our class web page.  Much of the time,
% you can figure out what's going on by comparing this file to the PDF
% that pdflatex produces from it.
%
% Last thought:  Like compiler error messages, LaTeX's error messages
% can be cryptic and misleading.  Two pieces of advice:
%
% (1) Just as with programming, add a little at a time:  Write a little bit
% of LaTeX source material, run it through pdflatex, fix errors if necessary,
% and repeat.
%
% (2) If the cause of a LaTeX error isn't obvious, comment out lines and
% re-run pdflatex until you've commented out the line that offends LaTeX.
% That's the easiest way to locate a difficult problem.  Then, all you have
% to do is figure out how to fix it! :-)

% ====================================================================

% LaTeX documents have two sections:  The preamble and the body.
% The preamble gives LaTeX the basic formatting parameters for the
% document.  The body is the document's content, including specific
% formatting commands.
%
% The preamble starts with the \documentclass command and stops when the
% body begins.  The body starts with the \begin{document} command and ends
% with the \end{document} command.


% -------------- The Preamble --------------

% There are many things that can be added to the preamble.  This is a 
% basic set, adequate for formatting basic homework answers for this class.


\documentclass[12pt]{article}   % others are available, like book

\usepackage{amssymb}            % adds more math symbols to LaTeX's basic set
\usepackage{graphicx}           % for importing/adjusting images

    % Below:  Set wider margins to give more text per page.

\setlength{\topmargin}{-0.50in}     % in == inches (others:  cm, mm, pt, ...)
\setlength{\textheight}{9.25in}     % what's left-over is the bottom margin
\setlength{\textwidth}{6.625in}
\setlength{\oddsidemargin}{0.0in}   % right-side pages in a magazine
\setlength{\evensidemargin}{0.0in}  % left-side

\setlength{\parindent}{0.0cm}	    % don't indent first lines of paragraphs
\setlength{\parskip}{0.4cm}         % distance between paragraphs


% -------------- The Body --------------

\begin{document}

\pagestyle{plain}               % 'plain' = add page #s; 'empty' = no page #s
\thispagestyle{empty}           % suppress the page number on this (1st) page

\hfill \fbox{\large Keinezufallemehr, Jack}
% hfill means "horizontal fill", a way to right-justify some text
% fbox created a framed box around the text
% large boosts the point size a little bit

\hfill Homework \#84            % You need to escape the pound sign

\hfill CSc 245 Section Z

\hfill SL:  Glaeken Trismegestus


\begin{enumerate}               % Start a numbered list of items

\item \underline{Section 1.1 \#27(a)}:    % first item

\item[] Converse:  If I ski tomorrow, it snowed today.
% "\item[]" tells LaTeX not to label the item with an item number
\item[] Contrapositive:  If I do not ski tomorrow, it did not snow today.
\item[] Inverse:  If it does not snow today, I will not ski tomorrow.


\item \underline{Section 1.1 \#31(c)}:

\item[]       % Without text, just leaves a bit of a vertical gap

% Tables in LaTeX require a lot of explaining, so I refer you to a LaTeX
% manual for the details.  (I have linked to a few in the LaTeX page that you
% can find linked to the class web page.)
% In brief, the following table has five columns
% with a vertical line between the second and third ("cc|ccc"), and each
% row's content is divided into columns by the ampersands.  Don't forget the
% double backslashes at the end of each row!  (You can skip it after the
% last row, though.)

\begin{tabular}{cc|ccc}
$p$ & $q$ & $\neg q$ & $p \lor \neg q$ & $(p \lor \neg q) \to q$ \\
% Math expressions start and stop with dollar signs
\hline
% hline produces a horizontal line between two rows of the table
 T  &  T  &    F     &      T          &                   T \\
 T  &  F  &    T     &      T          &                   F \\
 F  &  T  &    F     &      F          &                   T \\
 F  &  F  &    T     &      T          &                   F 
\end{tabular}


\item \underline{Section 1.3 \#19}: Answering two ways, neither by truth table:

  \begin{enumerate}    % A list within a list; no problem!

  \item By a sequence of logical equivalances:

  \item[] \begin{tabular}{r@{$\quad \equiv \quad$}ll}
  $\neg p \leftrightarrow q$
    & $(\neg p \to q) \land (q \to \neg p)$                      & [\textit{Def. of Biimplication}] \\
    & $(\neg q \to \neg \neg p) \land (\neg \neg p \to \neg q)$  & [\textit{Contrapositive ($\times$ 2)}] \\
    & $(\neg q \to p) \land (p \to \neg q)$                      & [\textit{Double Negation ($\times$ 2)}] \\
    & $(p \to \neg q) \land (\neg q \to p)$                      & [\textit{Commutativity ($\times$ 2)}] \\
    & $p \leftrightarrow \neg q$                                 & [\textit{Def. of Biimplication}] \\
  \end{tabular}
% textit formats the text in italics

  \item By reasoning:  We know that $p \leftrightarrow q$ is equivalent
        to $(p \to q) \land (q \to p)$, and that $p \leftrightarrow q$
        is true only when $p$ and $q$ are equal (that is, either both true
        or both false).

  % When typing a paragraph, I like to indent within the item.  It's not
  % required by LaTeX, but it makes the file's content easier to read.

  \item[] When we negate $p$, the cases in which $p$ and $q$ were equal
          are now cases in which they differ, and vice versa.
          This makes $\neg p \leftrightarrow q$ the negation of
          $p \leftrightarrow q$.

  \item[] Negating $q$ forces the same swapping of cases, and so has exactly
          the same result.  Thus,
          $\neg p \leftrightarrow q \equiv p \leftrightarrow \neg q$.

  \end{enumerate}


\item \underline{Section 1.4 \#9}:

\item[]

  \begin{itemize}
  \item[(b)] $\exists x (P(x) \land \neg Q(x)), x \in \textrm{UA Students}$
  % item[text] is how you replace LaTeX's normal item labeling
  \item[(c)] $\forall x (P(x) \lor Q(x)), x \in \textrm{UA Students}$
  \end{itemize}


\newpage    % Forces a page break


\item \underline{Section 1.7 \#1}:

\item[] Conjecture:  The sum of two odd integers is even.

\item[] \underline{Proof (Direct)}: Assume that
        $a, b \in \mathbb{Z}^{\textrm{\footnotesize odd}}$.

\item[] Any odd integer is one more than some even integer.
        Let $a = 2k+1$ and $b = 2j+1$, where $k,j \in \mathbb{Z}$.
        It follows that $a + b = (2k+1) + (2j+1) = 2k + 2j + 2 = 2(k+j+1)$.
        This result shows that $a+b$ is twice some integer,
        which is the definition of an even number.

\item[] Therefore, the sum of two odd integers is even.


\item \underline{Section 2.2 \#5}:

\item[] Conjecture:  $\overline{\overline{A}} = A$.

\item[] \underline{Proof (Direct)}:

  \begin{itemize}
  \item[] Case 1:  Show that $\overline{\overline{A}} \subseteq A$ is true.

  \vspace*{0.25cm}  % In lists, LaTeX leaves very little vertical separation
                    % ahead of tables, so I often add a little.

% In this table, to be different, I split up the rows across multiple lines.
% If you like terminal windows wider than 80 columns, this isn't necessary.
% For more narrow windows, this technique can improve readability, but it
% can take some getting used to.

  \item[] \hspace*{1.0cm} \begin{tabular}{r@{$\quad \equiv \quad$}ll}
  $\overline{\overline{A}} \subseteq A$
      & $\forall z \, (z \in \overline{\overline{A}} \to z \in A)$ 
          & [\textit{Def. of $\subseteq$}] \\
      & $\forall z \, (\overline{z \in \overline{A}} \to z \in A)$ 
          & [\textit{Def. of $\overline{X}$}] \\
      & $\forall z \, (\overline{\overline{z \in A}} \to z \in A)$ 
          & [\textit{"}] \\
      & $\forall z \, (z \in A \to z \in A)$ 
          & [\textit{Double Negation}] \\
      & $\forall z \, (\textbf{T})$ 
          & [\textit{Self-Implication}] \\
      & $\textbf{T}$
          & [\textit{Tautology}] \\
  \end{tabular}

  \item[] Case 2:  Show that $A \subseteq \overline{\overline{A}}$ is true.

  \item[] \hspace*{1.0cm}
          (\textit{This half is very similar to the above, and so is not
          provided here.})
  \end{itemize}

\item[] Therefore, $\overline{\overline{A}} = A$.


\item \underline{Section 2.2 \#13}:

\item[] Conjecture:  $A \cap (A \cup B) = A$.

\item[] \underline{Proof (Direct)}:

\item[]

\hspace*{0.5cm} \begin{tabular}{r@{$\quad = \quad$}ll}
$A \cap (A \cup B)$
  & $(A \cup \emptyset) \cap (A \cup B))$ & [\textit{Identity}] \\
  & $A \cup (\emptyset \cap B)$           & [\textit{Distribution}] \\
  & $A \cup \emptyset$                    & [\textit{Domination}] \\
  & $A$                                   & [\textit{Identity}] \\
\end{tabular}

\item[] Therefore, $A \cap (A \cup B) = A$.


\newpage


\item \underline{Section 2.6 \#3(a)}:

\item[] $AB = \left[ \begin{array}{rr}
                     2 & 1 \\
                     3 & 2 \\
                     \end{array} \right]
              \cdot
              \left[ \begin{array}{rr}
                     0 & 4 \\
                     1 & 3 \\
                     \end{array} \right]
            = \left[ \begin{array}{rr}
                     1 & 11 \\
                     2 & 18 \\
                     \end{array} \right]$
% Arrays in math expressions are just like tables ("tabular") in normal text
% "\left[" and "\right]" produce the giant matrix brackets


\item \underline{Section 5.1 \#9}:

\item[]

  \begin{enumerate}
  \item[(a)] $1, 2, \ldots, n$ is an arithmetic sequence.
             The sequence of sums of the terms
             ($s_{1}=1, s_{2}=3, s_{3}=6, s_{4}=10, s_{5}=15$, \ldots)
             is an arithmetic series.
             % ldots produces elipses in both normal text and in math exprs.

  \item[] There are multiple ways of figuring this out.  If we look at the
          values in the series
          and use some imagination to try to express $s_{n}$ in terms of $n$,
          we (eventually) discover that $s_{n}$ is half of the product $n(n+1)$.

  \item[] Here's another way:
          In general, the sum of the $n$ terms of an arithmetic sequence $a$
          is $s_{n} = \frac{n(a_{1}+a_{n})}{2}$.
          In this problem, $a_{1} = 1$ and $a_{n} = n$.  Substituting,
          our sum's formula is $s_{n} = \frac{n(n+1)}{2}$.  Again, that's
          half of the product $n(n+1)$.

  \item[(b)] Conjecture:  $\sum\limits_{i=1}^{n} i = \frac{n(n+1)}{2}$.

  \item[]

  \item[] \underline{Proof (by Weak Induction)}:

  \item[] \hspace*{0.5cm} \textbf{Basis Step}:
  % textbf boldfaces text

  \item[] \hspace*{1.5cm} Let $n=1$.  $\sum\limits_{i=1}^{1} i = 1 = \frac{1(1+1)}{2}$.
OK!

  \vspace*{0.5cm}

  \item[] \hspace*{0.5cm} \textbf{Inductive Step}:

  \item[] \hspace*{1.5cm} If $\sum\limits_{i=1}^{n} i \; = \; \frac{n(n+1)}{2}$, then
$\sum\limits_{i=1}^{n+1} i \; = \; \frac{(n+1)(n+2)}{2}$.

% Some explanation about the vertical spacing of the following table:
% When including math expressions with summations or fractions, the
% table rows can appear close together, making the expressions harder to
% read than they need to be.  Adding something like "[0.15cm]" after a
% row is usually enough to get LaTeX to add that much vertical space between
% that row and the next row.  In this case, that didn't add space between
% the first and second rows, so I added a blank row (the "\multicolumn" line)
% and some negative space to reduce the gap.  Kludgy, but it works! 
% There are more 'official' ways of tweaking the gaps between rows, but
% I've found that manual adjustments are less hassle and more flexible.

  \item[] \hspace*{2.5cm} \begin{tabular}{r@{$\quad = \quad$}lp{5.0cm}}
  $\sum\limits_{i=1}^{n+1} i$ & $\sum\limits_{i=1}^{n} i + (n+1)$ & [\textit{Expose the I.H.'s sum}] \\ 
  \multicolumn{3}{c}{} \\ [-0.25cm]
                              & $\frac{n(n+1)}{2} + (n+1)$        & [\textit{By the I.H.}] \\ [0.35cm]
                              & $\frac{n^2+n+2n+2}{2}$            & [\textit{Algebra}] \\ [0.35cm]
                              & $\frac{(n+1)(n+2)}{2}$            & [\textit{"}] \\
  \end{tabular}


  \item[] \hspace*{1.5cm} Thus, $\sum\limits_{i=1}^{n+1} i = \frac{(n+1)(n+2)}{2}$.

  \vspace*{0.25cm}

  \item[] Therefore, $\sum\limits_{i=1}^{n} i \; = \; \frac{n(n+1)}{2}$.
  \end{enumerate}

\end{enumerate}


\newpage


\underline{Some Additional Examples}:

\begin{itemize}
\item Formatting a Piecewise Function:

\item[] \hspace*{1.0cm}
  $
  \textrm{f(n)} = \left\{   % This is the big left parenthesis 
    \begin{array}{ll}
    \frac{n}{2}       & \textrm{when} \; n \, \equiv \, 0 \, (\textrm{mod} \; 2) \\ [0.15cm]
    3n+1              & \textrm{otherwise}
    \end{array}
  \right.  % This tells LaTeX that there's no corresponding right parenthesis.
  $

\item Importing an Image

\item[] Say that a homework answer requires a diagram to be produced.
        In a more perfect world, you'd use a diagramming tool to 
        make a crisp, impressive picture.  In a world with weekly homework
        due dates, you might decide to save time by drawing it by hand.
        Either way, how do you import the picture into your \LaTeX\ file?
% "\LaTeX" generates the official LaTeX symbol.  The "\ " at the end is
% necessary to add a space after it so that it looks nice in a sentence.

\item[] \LaTeX\ users have created a large number of add-ons.  One of the
        more commonly-used packages is \texttt{graphicx}.
        When used with \texttt{pdflatex}, you can import \texttt{JPG}
        and \texttt{PNG} images easily.  For example:

\vspace*{0.25cm}

\begin{center}
\includegraphics[scale=1.0]{plot2.png}
% includegraphics:  The main command of the graphicx package
% scale:  1.0 = original size; 2.0 is double in both x and y directions,
%         0.5 is half
\end{center}

\item[] Many image processing programs (e.g., GIMP) can convert images
        into \texttt{JPG} or \texttt{PNG} formats.  Strong suggestion:
        Reduce the resolution of the image while you're at it.  Your cell
        phone might capture 12 megapixel pictures, but importing one of those
        will make your \texttt{PDF} file enormous.  The \texttt{PNG}
        image above is just 500 by 500 pixels in size (a mere 0.25 megapixels
        and just 325K bytes -- less than a tenth of the size of the original),
        and is plenty large and entirely legible.
\end{itemize}

\end{document}   % And the document source is complete!  Anything after this
                 % command will be ignored.  This is handy, as you can put
                 % currently unused blocks of LaTeX statements here for future
                 % reference.
