\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx,wrapfig,lipsum}
\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Test\ \#2}
\newcommand{\hmwkDueDate}{Due on 2nd November, 2018}
\newcommand{\hmwkClass}{Fluid Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\begin{homeworkProblem}[1]
	\begin{align*}
		\includegraphics[scale=0.1,angle=90]{q1.jpg}
	\end{align*}
	For the topspin, there will be a corresponding downward force $ \va{L} $ on the ball (assumed to be a cylinder) given by,
	\begin{equation*}
	\va{L} = - \rho V \Gamma \vu{y}
	\end{equation*}
	where $ \rho $ is the density of air and $ \Gamma $ is the circulation strength.

	The maximum velocity that can be imparted to the ball is $ V $, and hence the maximum angular velocity imparted is $\frac{V}{R}$, where $ R $ is the radius. So one can find the maximum value of circulation (and consequently maximum lift) from,
	\begin{equation*}
	\dfrac{V}{R} = \dfrac{\Gamma}{2 \pi R^2} \implies \Gamma = {2 \pi R V} \implies \va{L} = -2 \pi \rho R V^2 \vu{y}
	\end{equation*}

	We have assumed here that velocity of the player's hand is completely imparted to the ball.

	The total force $ \va{F} $ and acceleration $ \va{a} $ acting on the ball is (neglecting air drag),
	\begin{equation*}
	\va{F} = -(mg + 2 \pi \rho R V^2)\vu{y} \implies \va{a} =  -\qty(g + \dfrac{2 \pi \rho R V^2}{m})\vu{y}
	\end{equation*}

	The problem now becomes that of projective motion. If the table is assumed to be at $ y=0 $, and the initial position of the ball is $ (0,H) $, the coordinates $ x $ and $ y $ are given by,
	\begin{equation*}
	x = Vt \qq{,} y = H - \dfrac{1}{2}\qty(g + \dfrac{2 \pi \rho R V^2}{m})t^2
	\end{equation*}
	Note that these formulae for $ x $ and $ y $ are valid only till the time $T$ that the ball first hits the table,
	\begin{equation*}
	 H - \dfrac{1}{2}\qty(g + \dfrac{2 \pi \rho R V^2}{m})T^2 = 0 \implies T = \sqrt{\dfrac{2Hm}{mg + 2 \pi \rho R V^2}}
	\end{equation*}
	The angle that the ball makes with the vertical at the time of collision is,
	\begin{equation*}
	\theta_1 = \tan^{-1}\qty(\dfrac{V}{U}) \qq{;} U=\sqrt{2\qty(g + \dfrac{2 \pi \rho R V^2}{m})H}
	\end{equation*}

	On hitting the table, the ball exerts a leftward force on the table, to which there is an equal and rightward reaction force (impulse) acting on the ball. This will increase the net rightward velocity of the ball, and the angle $ \theta_2 $ that the ball makes with the vertical will be greater than $ \theta_1 $
\end{homeworkProblem}

\begin{homeworkProblem}[2]
	We assume homogenous, isotropic turbulence. These assumptions tell us that the second-order structure function $ S_2 $ calculated between two spatial points should depend \textit{only} on the distance between the two points. More mathematically,
	\begin{equation*}
	\expval{\qty(\va{u}(\va{r} + \va{l}) - \va{u}(\va{r}))^2} = S_2 \qty(\abs{\va{l}}) = S_2(l)
	\end{equation*}

	Further, we define the \textit{energy spectrum} $ E(k) $ such that $ E(k)dk $ gives the mean kinetic energy contained within $ k $ and $ k + dk $. It follows from the definition that,
	\begin{equation}
	\int_{0}^{\infty} E(k) dk = \dfrac{1}{2}\expval{u^2}
	\label{ekkin}
	\end{equation}
	The \textit{Wiener-Khinchin} theorem tells us that energy spectrum is the Fourier Transform of the spatial autocorrelation function,
	\begin{equation}
	S_2(l) \sim  \int_{-\infty}^{\infty} e^{i \va{k} \vdot \va{l}} E(k) d^3 \va{k}
	\label{wkt}
	\end{equation}

	Now we try to guess the scaling form of $ E(k) $ as $E(k) \sim k^{-n}$. Substituting this ansatz into (\ref{ekkin}),
	\begin{align*}
	\int_{0}^{\infty} E(k) dk &\sim \int_{0}^{\infty} k^{-n} dk \\
	&\sim \eval{\dfrac{k^{1-n}}{1-n}}_{\infty}
	\end{align*}
	As the RHS of (\ref{ekkin}) is finite, it follows from above that $ n > 1 $. We now substitute our ansatz into (\ref{wkt}),
	\begin{align*}
	S_2 (l) &\sim \int_{-\infty}^{\infty} e^{i \va{k} \vdot \va{l}} k^{-n} d^3 \va{k}\\
	&\sim \int_{0}^{\infty}  e^{i kl} k^{-n} dk\int_{0}^{\pi} d(\cos\theta) \int_{0}^{2\pi} d\phi\\
	&\sim \int_{0}^{\infty}  e^{i kl} k^{-n} dk\\
	&\sim \int_{0}^{\infty}  e^{i x} x^{-n} l^n \dfrac{dx}{l} \impliedby \qq{substituting} kl =x \\
	S_2 (l) &\sim \qty[\int_{0}^{\infty} e^{i x} (x)^{-n} dx] l^{n-1}
	\end{align*}

	This tells us that $ E(k) \sim k^{-n} \iff S_2(l) \sim l^{n-1}$. In class it was discussed that $ S_2(l) \sim l^{2/3}$ which from the above analysis implies $E(k) \sim k^{-5/3}$. The latter was the expression of the energy spectrum discussed in class.

\end{homeworkProblem}

\begin{homeworkProblem}[3]
	As the depth and the width for all three streams is the same and constant, we expect that at the source on top of the mountain, the volume flow rate $ Q $ gets divided equally between the three streams. Writing unsteady Bernoulli between the topmost point and a point at height $ h $ above the bottom for a given stream $ i $,
	\begin{equation}
	\int \rho \pdv{v_i}{t} ds + \qty(P_{atm} + \dfrac{\rho Q^2}{18 A^2} + \rho g H) - \qty(P_{atm} + \dfrac{\rho v_i^2}{2} + \rho g h)
	\label{uparneeche}
	\end{equation}
	where the integral is along a streamline. The path of the water can be given as,
	\begin{equation*}
	ds = \sqrt{dx_i^2 + dy_i^2} = dh\sqrt{\dot{x}_i^2 + \dot{y}_i^2} \qq{where} \dot{x}_i= \dv{x_i}{h} \qq{and} \dot{y}_i = \dv{y_i}{h}
	\end{equation*}
	We denote the distance that the water has travelled by $ L_i(h) $,
	\begin{equation*}
	L_i(h) = \abs{\int_H^{h} dh \sqrt{\dot{x}_i^2 + \dot{y}_i^2}}
	\end{equation*}
	So we can then rewrite (\ref{uparneeche}) as,
	\begin{equation*}
	\pdv{v_i}{t} L_i(h) = -\qty(\dfrac{v_i^2}{2} - \dfrac{Q^2}{18A^2} - \rho g (H-h)) \implies \pdv{v_i}{t} = -\dfrac{9A^2 v_i^2 - Q^2 - 18g(H-h)A^2}{18A^2L_i(h)}
	\end{equation*}
	Using $\alpha(h)^2 = \dfrac{Q^2 + 18g(H-h)A^2}{9A^2}$
	\begin{equation*}
	\ln \dfrac{v_i- \alpha}{v_i + \alpha} = - \dfrac{\alpha(h) t}{L_i(h)} \implies v_i(t,h) = \alpha(h) \tanh\dfrac{\alpha(h) t}{2L_i(h)}
	\end{equation*}
\end{homeworkProblem}

\end{document}


%% Copyright (C) 2019-2021 Alessandro Clerici Lorenzini
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Alessandro Clerici Lorenzini
%
% This work consists of the files listed in work.txt

\documentclass[a4paper,twoside]{report}
% \documentclass[a4paper,oneside]{report}
\usepackage{mdc-impostazioni}

% TODO: sistemare numero di righe bianche prima di chapter/section/sub
% TODO: sistemare virgolette
% TODO: (ri)fare i grafici con tikz
% TODO: sostituire \[\] con ambiente equation*
\begin{document}

\title{Matematica del Continuo\\
	\normalsize v. $0.1.1$ }
\author{Alessandro Clerici Lorenzini}
\date{Anno accademico 2019/2020}
\maketitle
\tableofcontents

\begin{dedication}
	Al professor Massimo Tarallo,\\
	che in poche settimane mi ha insegnato a innamorarmi del Sapere.
\end{dedication}

\chapter{Algebra e Complessi}
\input{tex/1_1-depresse.tex}
\input{tex/1_2-complessi.tex}
\input{tex/1_3-scomposizioni.tex}

\chapter{Reali, razionali e interi}
\input{tex/2_1-insiemistica.tex}
\input{tex/2_2-logica.tex}

\chapter{Limiti di successioni}
\input{tex/3_1-definizioni}
\input{tex/3_2-limiti}

\chapter{Simboli di Landau}
\input{tex/4_1-opiccolo}
\input{tex/4_2-asintotico}
\input{tex/4_3-grandi}

\chapter{Continuità e limiti di funzioni}
\input{tex/5_1-limite}
\input{tex/5_2-continuita}
\input{tex/5_3-operazioni}
\input{tex/5_4-rlandau}
\input{tex/5_5-teoremi}

\chapter{Calcolo differenziale}
\input{tex/6_1-laderivata}
\input{tex/6_2-calcolodiderivate}
\input{tex/6_3-teoremiderivate}
\input{tex/6_4-sviluppitaylor}

\chapter{Calcolo integrale}
\input{tex/7_1-int_definito}
\input{tex/7_2-int_indefinito}
\input{tex/7_3-int_improprio}

\chapter{Somme e serie}
\input{tex/8_1-sommefinite}
\input{tex/8_2-serie}
\input{tex/8_3-potenze}

\chapter{Ricorsione}
\input{tex/9_1-ricorsione}
% TODO: da completare

\end{document}


\documentclass{article}
    % General document formatting
    \usepackage[margin=0.7in]{geometry}
    \usepackage[parfill]{parskip}
    \usepackage[utf8]{inputenc}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{tikz}
    \usepackage{fancyhdr}
    \usepackage{listings}

\pagestyle{fancy}
\fancyhf{}
\rhead{Edgar Jacob Rivera Rios - A01184125}

\begin{document}
\begin{titlepage}

    \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here

    \center % Center everything on the page

    %----------------------------------------------------------------------------------------
    %	HEADING SECTIONS
    %----------------------------------------------------------------------------------------

    \textsc{\LARGE Tecnológico de Monterrey}\\[1.5cm] % Name of your university/college
    \textsc{\Large Fundamentos de computación}\\[0.5cm] % Major heading such as course name
    %\textsc{\large Minor Heading}\\[0.5cm] % Minor heading such as course title

    %----------------------------------------------------------------------------------------
    %	TITLE SECTION
    %----------------------------------------------------------------------------------------

    \HRule \\[0.4cm]
    { \huge \bfseries Homework 3}\\[0.4cm] % Title of your document
    \HRule \\[1.5cm]

    %----------------------------------------------------------------------------------------
    %	AUTHOR SECTION
    %----------------------------------------------------------------------------------------

    \begin{minipage}{0.4\textwidth}
    \begin{flushleft} \large
    \emph{Student:}\\
    Jacob \textsc{Rivera} % Your name
    \end{flushleft}
    \end{minipage}
    ~
    \begin{minipage}{0.4\textwidth}
    \begin{flushright} \large
    \emph{Professor:} \\
    Dr. Hugo \textsc{Terashima} % Supervisor's Name
    \end{flushright}
    \end{minipage}\\[2cm]

    % If you don't want a supervisor, uncomment the two lines below and remove the section above
    %\Large \emph{Author:}\\
    %John \textsc{Smith}\\[3cm] % Your name

    %----------------------------------------------------------------------------------------
    %	DATE SECTION
    %----------------------------------------------------------------------------------------

    {\large \today}\\[2cm] % Date, change the \today to a set date if you want to be precise

    %----------------------------------------------------------------------------------------
    %	LOGO SECTION
    %----------------------------------------------------------------------------------------

    \includegraphics[width=0.4\textwidth,height=\textheight,keepaspectratio]{logo-tec-negro.png} % Include a department/university logo - this will require the graphicx package

    %----------------------------------------------------------------------------------------

    \vfill % Fill the rest of the page with whitespace

\end{titlepage}

\section{Problems}
Solve the following problems:
\begin{enumerate}
    \item  Find an optimal parenthesization of a matrix-chain product whose sequence of dimensions are $p_0= 10$, $p_1= 19$, $p_2= 29$, $p_3= 33$, $p_4= 9$ and $p_5= 17$. Show and explain each step in the procedure.

    \begin{align*}
        A_1 &= 10\times19\\
        A_2 &= 19\times29\\
        A_3 &= 29\times33\\
        A_4 &= 33\times9\\
        A_5 &= 9\times17\\
    \end{align*}
    \begin{center}
        \begin{tabular}{c|c|c|c|c|c|}
             & 1 & 2 & 3 & 4 & 5 \\
            \hline
            1& 0 & & & & \\
            \hline
            2& 5510 & 0 & & & \\
            \hline
            3& 15080 & 18183 & 0 & & \\
            \hline
            4& 15282 & 13572 & 8613 & 0 & \\
            \hline
            5& 16812 & 16479 & 13050 & 5049 & 0 \\
            \hline
        \end{tabular}

        \begin{tabular}{c|c|c|c|c|}
             & 1 & 2 & 3 & 4\\
            \hline
            2& 1 & & &  \\
            \hline
            3& 2 & 2 & &  \\
            \hline
            4& 1 & 2 & 3 &  \\
            \hline
            5& 4 & 4 & 4 & 4 \\
            \hline
        \end{tabular}
    \end{center}

    \item  Show that a full parenthesization of an $n$ element expression has exactly $n-1$ pairs of parentheses

    We can see that a parenthesization of one element is none and of two elements is trivial, as the only possibility is $(A_1A_2)$, but when we add a third element, we have the possibilities of $((A_1A_2)A_3)$ and $(A_1(A_2A_3))$, so, by in induction we can see that the number of pairs parentheses is dependent of the number of terms, as $n -1$
    \pagebreak
    \item Solve problem 15-4 from Cormen et al. Book.

    Consider the problem of neatly printing a paragraph with a monospaced font (all characters having the same width) on a printer. The input text is a sequence of $n$ words of lengths $l_1, l_2, ... , l_n$, measured in characters. We want to print this paragraph neatly on a number of lines that hold a maximum of $M$ characters each. Our criterion of “neatness” is as follows. If a given line contains words $i$ through $j$, where $i \leq j$, and we leave exactly one space between words, the number of extra space characters at the end of the line is $M - j + i - \sum_{k=i}^{j}l_k$, which must be non negative so that the words fit on the line. We wish to minimize the sum, over all lines except the last, of the cubes of the numbers of extra space characters at the ends of lines. Give a dynamic-programming algorithm to print a paragraph of $n$ words neatly on a printer. Analyze the running time and space requirements of your algorithm.
    \begin{lstlisting}
    PRINT-NEATLY(l[], n, M)
        spaces_at_the_end = new [n][n]
        line_cost = new [n][n]
        c = new [n]
        for i = 1 to n
            spaces_at_the_end[i][i] = M - l[i]
            for j = i + 1 to n
                spaces_at_the_end[i, j] = spaces_at_the_end[i][j - 1] - l[j] - 1
        for i = 1 to n
            for j = i to n
                if spaces_at_the_end[i][j] < 0
                    line_cost[i][j] = inf
                else if j == n and spaces_at_the_end[i][j] >= 0
                    line_cost[i][j] = 0
                else line_cost[i][j] = spaces_at_the_end[i][j]^3
        c[0] = 0
        p = new [n]
        for j = 1 to n
            c[j] = inf
            for i = 1 to j
                if c[i - 1] + line_cost[i][j] < c[j]
                    c[j] = c[i - 1] + line_cost[i][j]
                    p[j] = i
        return c and p
    \end{lstlisting}

    We can see that the complexity is simply $O(n^2)$

    \item Provide a comparative study on an investigation over algorithm-design strategies: Divide and Conquer, Dynamic Programming and Greedy Algorithms. State their definition, characteristics, advantages, disadvantages, examples of problems where each strategy is best applied, and a description to characterize problems within each technique. Add references to your work.

\end{enumerate}
\end{document}


\section{Conclusions and Future Work}
\label{sec:reusable-correct-transformations:conclusions}
To address research question~\RQ{4}, we defined a formal framework for reasoning about the correctness of the endogenous model transformations related to \SLCO, which is illustrated in this chapter.
Using this framework, we can assess whether sequences of transformations are well-composed, and whether individual transformations are provably correct.
By designing sequences of transformations that are as fine-grained as possible, we improved the reusability of these transformations, both between sequences of transformations and within such sequences.
Furthermore, this design decision increased the number of transformations with straightforward correctness proofs and reduced the number of proof obligations for the proofs of the larger transformation steps.

Given the large number of straightforward proofs, we consider investigating the application of automated theorem proving to be a promising direction for future research.
Furthermore, the work presented in this chapter does not take successful termination and time into account.
These problems also provide opportunities for future research.
Finally, we want to investigate the generalization of the approach to other DSMLs.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% writeLaTeX Example: A quick guide to LaTeX
%
% Source: Dave Richeson (divisbyzero.com), Dickinson College
%
% A one-size-fits-all LaTeX cheat sheet. Kept to two pages, so it
% can be printed (double-sided) on one piece of paper
%
% Feel free to distribute this example, but please keep the referral
% to divisbyzero.com
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% How to use writeLaTeX:
%
% You edit the source code here on the left, and the preview on the
% right shows you the result within a few seconds.
%
% Bookmark this page and share the URL with your co-authors. They can
% edit at the same time!
%
% You can upload figures, bibliographies, custom classes and
% styles using the files menu.
%
% If you're new to LaTeX, the wikibook is a great place to start:
% http://en.wikibooks.org/wiki/LaTeX
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[10pt,landscape]{article}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{multicol,multirow}
\usepackage{calc}
\usepackage{ifthen}
\usepackage[landscape]{geometry}
\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref}

\ifthenelse{\lengthtest { \paperwidth = 11in}}
    { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
	{\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
		{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
		{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
	}
\pagestyle{empty}
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%x
                                {\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
                                {-1explus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%
                                {\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {1ex plus .2ex}%
                                {\normalfont\small\bfseries}}
\makeatother
\setcounter{secnumdepth}{0}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}
% -----------------------------------------------------------------------

\title{Quick Guide to LaTeX}

\begin{document}

\raggedright
\footnotesize

\begin{center}
     \Large{\textbf{A quick guide to \LaTeX}} \\
\end{center}
\begin{multicols}{3}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{2pt}

\section{What is \LaTeX?}
\LaTeX (usually pronounced ``LAY teck,'' sometimes ``LAH teck,'' and never ``LAY tex'') is a mathematics typesetting program that is the standard for most professional mathematics writing. It is based on the typesetting program \TeX\ created by Donald Knuth of Stanford University (his first version appeared in 1978). Leslie Lamport was responsible for creating \LaTeX\, a more user friendly version of \TeX. A team of \LaTeX\ programmers created the current version,  \LaTeX\ 2$\varepsilon$.

\section{Math vs. text vs. functions}
In properly typeset mathematics  variables appear in italics (e.g., $f(x)=x^{2}+2x-3$). The exception to this rule is predefined functions (e.g., $\sin (x)$). Thus it is important to \textbf{always} treat text, variables, and functions correctly. See the difference between $x$ and x, -1 and $-1$, and $sin(x)$ and $\sin(x)$.

There are two ways to present a mathematical expression--- \emph{inline} or as an \emph{equation}.

\subsection{Inline mathematical expressions}
Inline expressions occur in the middle of a sentence.  To produce an inline expression, place the math expression between dollar signs (\verb!$!).  For example, typing \verb!$90^{\circ}$ is the same as $\frac{\pi}{2}$ radians!  yields $90^{\circ}$ is the same as $\frac{\pi}{2}$ radians.

\subsection{Equations}
Equations are mathematical expressions that are given their own line and are centered on the page.  These are usually used for important equations that deserve to be showcased on their own line or for large equations that cannot fit inline. To produce an inline expression, place the mathematical expression  between the symbols  \verb!\[! and \verb!\]!. Typing \verb!\[x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}\]! yields \[x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}.\]

\subsection{Displaystyle}
To get full-sized inline mathematical expressions  use  \verb!\displaystyle!. Use this sparingly. Typing \verb!I want this $\displaystyle \sum_{n=1}^{\infty}! \verb!\frac{1}{n}$, not this $\sum_{n=1}^{\infty}! \verb!\frac{1}{n}$.! yields\\ I want  this $\displaystyle \sum_{n=1}^{\infty}\frac{1}{n}$, not this $\sum_{n=1}^{\infty}\frac{1}{n}.$

\section{Images}

You can put images (pdf, png, jpg, or gif) in your document. They need to be in the same location as your .tex file when you compile the document. Omit   \verb![width=.5in]! if you want the image to be full-sized.

\verb!\begin{figure}[ht]!\\
\verb!\includegraphics[width=.5in]{imagename.jpg}!\\
\verb!\caption{The (optional) caption goes here.}!\\
\verb!\end{figure}!

\subsection{Text decorations}

Your text can be \textit{italics} (\verb!\textit{italics}!), \textbf{boldface} (\verb!\textbf{boldface}!), or \underline{underlined} (\verb!\underline{underlined}!).

Your math can contain boldface, $\mathbf{R}$ (\verb!\mathbf{R}!), or blackboard bold, $\mathbb{R}$ (\verb!\mathbb{R}!). You may want to used these to express the sets of real numbers ($\mathbb{R}$ or $\mathbf{R}$), integers ($\mathbb{Z}$ or $\mathbf{Z}$), rational numbers ($\mathbb{Q}$ or $\mathbf{Q}$), and natural numbers ($\mathbb{N}$ or $\mathbf{N}$).

To have text appear in a math expression use \verb!\text!. \verb!(0,1]=\{x\in\mathbb{R}:x>0\text{ and }x\le 1\}! yields $(0,1]=\{x\in\mathbb{R}:x>0\text{ and }x\le 1\}$. (Without the \verb!\text! command it treats ``and'' as three variables: $(0,1]=\{x\in\mathbb{R}:x>0 and x\le 1\}$.)

\section{Spaces and new lines}

\LaTeX\ ignores extra spaces and new lines. For example,

\verb!This   sentence will       look!

\verb!fine after      it is     compiled.!

This   sentence will       look
fine after      it is     compiled.

Leave one full empty line between two paragraphs. Place \verb!\\! at the end of a line to create a new line (but not create a new paragraph).

\verb!This!

\verb!compiles!

~

\verb!like\\!

\verb!this.!

This
compiles

like\\
this.

Use  \verb!\noindent! to prevent a paragraph from indenting.

\section{Comments}

Use \verb!%! to create a comment. Nothing on the line after the \verb!%! will be typeset. \verb!$f(x)=\sin(x)$ %this is the sine function! yields $f(x)=\sin(x)$%this is the sine function

\section{Delimiters}

\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
parentheses &\verb!(x)! & (x)\\
brackets &\verb![x]! & [x]\\
curly braces& \verb!\{x\}! & \{x\}\\
\end{tabular}

To make your delimiters large enough to fit the content, use them together with \verb!\right! and \verb!\left!. For example, \verb!\left\{\sin\left(\frac{1}{n}\right)\right\}_{n}^! \verb!{\infty}! produces\\ $\displaystyle \left\{\sin\left(\frac{1}{n}\right)\right\}_{n}^{\infty}$.

Curly braces are non-printing characters that are used to gather text that has more than one character. Observe the differences between the four expressions \verb!x^2!, \verb!x^{2}!, \verb!x^2t!, \verb!x^{2t}! when typeset: $x^2$, $x^{2}$, $x^2t$, $x^{2t}$.

\section{Lists}

You can produce ordered and unordered lists.

\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
unordered list&
\begin{tabular}{l}
\verb!\begin{itemize}!\\
\verb!  \item!\\
\verb!  Thing 1!\\
\verb!  \item!\\
\verb!  Thing 2!\\
\verb!\end{itemize}!
\end{tabular}&
\begin{tabular}{l}
$\bullet$ Thing 1\\
$\bullet$ Thing 2
\end{tabular}\\
~\\
ordered list&
\begin{tabular}{l}
\verb!\begin{enumerate}!\\
\verb!  \item!\\
\verb!  Thing 1!\\
\verb!  \item!\\
\verb!  Thing 2!\\
\verb!\end{enumerate}!
\end{tabular}&
\begin{tabular}{l}
1.~Thing 1\\
2.~Thing 2
\end{tabular}
\end{tabular}

\section{Symbols (in \emph{math} mode)}

\subsection{The basics}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
addition & \verb!+! & $+$\\
subtraction & \verb!-! & $-$\\
plus or minus & \verb!\pm! & $\pm$\\
multiplication (times) & \verb!\times! & $\times$\\
multiplication (dot) & \verb!\cdot! & $\cdot$\\
division symbol & \verb!\div! & $\div$\\
division (slash) & \verb!/! & $/$\\
circle plus & \verb!\oplus! & $\oplus$\\
circle times & \verb!\otimes! & $\otimes$\\
equal & \verb!=! & $=$\\
not equal & \verb!\ne! & $\ne$\\
less than & \verb!<! & $<$\\
greater than & \verb!>! & $>$\\
less than or equal to & \verb!\le! & $\le$\\
greater than or equal to & \verb!\ge! & $\ge$\\
approximately equal to & \verb!\approx! & $\approx$\\
infinity & \verb!\infty! & $\infty$\\
dots & \verb!1,2,3,\ldots! & $1,2,3,\ldots$\\
dots & \verb!1+2+3+\cdots! & $1+2+3+\cdots$\\
fraction & \verb!\frac{a}{b}! & $\frac{a}{b}$\\
square root & \verb!\sqrt{x}! & $\sqrt{x}$\\
$n$th root & \verb!\sqrt[n]{x}! & $\sqrt[n]{x}$\\
exponentiation & \verb!a^b! & $a^{b}$\\
subscript & \verb!a_b! & $a_{b}$\\
absolute value & \verb!|x|! & $|x|$\\
natural log  & \verb!\ln(x)! & $\ln(x)$\\
logarithms & \verb!\log_{a}b! & $\log_{a}b$\\
exponential function & \verb!e^x=\exp(x)! & $e^{x}=\exp(x)$\\
degree & \verb!\deg(f)! & $\deg(f)$\\
\end{tabular}
\newpage

\subsection{Functions}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
maps to & \verb!\to! & $\to$\\
composition& \verb!\circ! & $\circ$\\
piecewise& \verb!|x|=! & \multirow{5}{*}{$\displaystyle |x|=\begin{cases}x&x\ge 0\\-x&x<0\end{cases}$}\\
function&\verb!\begin{cases}!&\\
&\verb!x & x\ge 0\\!&\\
&\verb!-x & x<0!&\\
&\verb!\end{cases}!&
\end{tabular}

\subsection{Greek and Hebrew letters}
\begin{tabular}{llll}
\emph{command} & \emph{output}&\emph{command} & \emph{output}\\
\verb!\alpha! & $\alpha$&\verb!\tau! & $\tau$\\
\verb!\beta! & $\beta$&\verb!\theta! & $\theta$\\
\verb!\chi! & $\chi$&\verb!\upsilon! & $\upsilon$\\
\verb!\delta! & $\delta$&\verb!\xi! & $\xi$\\
\verb!\epsilon! & $\epsilon$&\verb!\zeta! & $\zeta$\\
\verb!\varepsilon! & $\varepsilon$&\verb!\Delta! & $\Delta$\\
\verb!\eta! & $\eta$&\verb!\Gamma! & $\Gamma$\\
\verb!\gamma! & $\gamma$&\verb!\Lambda! & $\Lambda$\\
\verb!\iota! & $\iota$&\verb!\Omega! & $\Omega$\\
\verb!\kappa! & $\kappa$&\verb!\Phi! & $\Phi$\\
\verb!\lambda! & $\lambda$&\verb!\Pi! & $\Pi$\\
\verb!\mu! & $\mu$&\verb!\Psi! & $\Psi$\\
\verb!\nu! & $\nu$&\verb!\Sigma! & $\Sigma$\\
\verb!\omega! & $\omega$&\verb!\Theta! & $\Theta$\\
\verb!\phi! & $\phi$&\verb!\Upsilon! & $\Upsilon$\\
\verb!\varphi! & $\varphi$&\verb!\Xi! & $\Xi$\\
\verb!\pi! & $\pi$&\verb!\aleph! & $\aleph$\\
\verb!\psi! & $\psi$&\verb!\beth! & $\beth$\\
\verb!\rho! & $\rho$&\verb!\daleth! & $\daleth$\\
\verb!\sigma! & $\sigma$&\verb!\gimel! & $\gimel$
\end{tabular}

\subsection{Set theory}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
set brackets & \verb!\{1,2,3\}! & $\{1,2,3\}$\\
element of & \verb!\in! & $\in$\\
not an element of & \verb!\not\in! & $\not\in$\\
subset of & \verb!\subset! & $\subset$\\
subset of & \verb!\subseteq! & $\subseteq$\\
not a subset of & \verb!\not\subset! & $\not\subset$\\
contains & \verb!\supset! & $\supset$\\
contains & \verb!\supseteq! & $\supseteq$\\
union & \verb!\cup! & $\cup$\\
intersection & \verb!\cap! & $\cap$\\
big union &
\verb!\bigcup_{n=1}^{10}A_n! &
$\displaystyle \bigcup_{n=1}^{10}A_{n}$\\
big intersection & \verb!\bigcap_{n=1}^{10}A_n! &$\displaystyle \bigcap_{n=1}^{10}A_{n}$\\
empty set & \verb!\emptyset! & $\emptyset$\\
power set & \verb!\mathcal{P}! & $\mathcal{P}$\\
minimum & \verb!\min! & $\min$\\
maximum & \verb!\max! & $\max$\\
supremum & \verb!\sup! & $\sup$\\
infimum & \verb!\inf! & $\inf$\\
limit superior & \verb!\limsup! & $\limsup$\\
limit inferior & \verb!\liminf! & $\liminf$\\
closure & \verb!\overline{A}! & $\overline{A}$
\end{tabular}

\subsection{Calculus}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
derivative & \verb!\frac{df}{dx}! & $\displaystyle \frac{df}{dx}$\\
derivative & \verb!\f'! & $f'$\\
partial derivative &
\begin{tabular}{l}
\verb!\frac{\partial f}!\\ \verb!{\partial x}!
\end{tabular}& $\displaystyle \frac{\partial f}{\partial x}$\\
integral & \verb!\int! & $\displaystyle\int$\\
double integral & \verb!\iint! & $\displaystyle\iint$\\
triple integral & \verb!\iiint! & $\displaystyle\iiint$\\
limits & \verb!\lim_{x\to \infty}! & $\displaystyle \lim_{x\to \infty}$\\
summation  &
\verb!\sum_{n=1}^{\infty}a_n! &
$\displaystyle \sum_{n=1}^{\infty}a_n$\\
product  &
\verb!\prod_{n=1}^{\infty}a_n! &
$\displaystyle \prod_{n=1}^{\infty}a_n$
\end{tabular}

\subsection{Logic}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
not & \verb!\sim! & $\sim$\\
and & \verb!\land! & $\land$\\
or & \verb!\lor! & $\lor$\\
if...then & \verb!\to! & $\to$\\
if and only if & \verb!\leftrightarrow! & $\leftrightarrow$\\
logical equivalence & \verb!\equiv! & $\equiv$\\
therefore & \verb!\therefore! & $\therefore$\\
there exists  & \verb!\exists! & $\exists$\\
for all & \verb!\forall! & $\forall$\\
implies & \verb!\Rightarrow! & $\Rightarrow$\\
equivalent & \verb!\Leftrightarrow! & $\Leftrightarrow$
\end{tabular}

\subsection{Linear algebra}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
vector & \verb!\vec{v}! & $\vec{v}$\\
vector & \verb!\mathbf{v}! & $\mathbf{v}$\\
norm & \verb!||\vec{v}||! & $||\vec{v}||$\\
matrix&
\begin{tabular}{l}
\verb!\left[!\\
\verb!\begin{array}{ccc}!\\
\verb!1 & 2 & 3 \\!\\
\verb!4 & 5 & 6\\!\\
\verb!7 & 8 & 0!\\
\verb!\end{array}!\\
\verb!\right]!\end{tabular}&
$\displaystyle \left[\begin{array}{ccc}1 & 2 & 3 \\4 & 5 & 6 \\7 & 8 & 0\end{array}\right]$\\
\\determinant&
\begin{tabular}{l}
\verb!\left|!\\
\verb!\begin{array}{ccc}!\\
\verb!1 & 2 & 3 \\!\\
\verb!4 & 5 & 6 \\!\\
\verb!7 & 8 & 0!\\
\verb!\end{array}!\\
\verb!\right|!
\end{tabular}&
$\displaystyle \left|\begin{array}{ccc}1 & 2 & 3 \\4 & 5 & 6 \\7 & 8 & 0\end{array}\right|$\\
determinant & \verb!\det(A)! & $ \det(A)$\\
trace & \verb!\operatorname{tr}(A)! & $\operatorname{tr}(A)$\\
dimension & \verb!\dim(V)! & $\dim(V)$\\
\end{tabular}

\subsection{Number theory}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
divides & \verb!|! & $|$\\
does not divide & \verb!\not |! & $\not |$\\
div & \verb!\operatorname{div}! & $\operatorname{div}$\\
mod & \verb!\mod! & $\operatorname{mod}$\\
greatest common divisor & \verb!\gcd! & $\gcd$\\
ceiling & \verb!\lceil x \rceil! & $\lceil x\rceil$\\
floor & \verb!\lfloor x \rfloor! & $\lfloor x \rfloor$\\
\end{tabular}

\subsection{Geometry and trigonometry}
\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
angle& \verb!\angle ABC! & $\angle ABC$\\
degree& \verb!90^{\circ}! & $90^{\circ}$\\
triangle& \verb!\triangle ABC! & $\triangle ABC$\\
segment& \verb!\overline{AB}! & $\overline{AB}$\\
sine& \verb!\sin! & $\sin$\\
cosine& \verb!\cos! & $\cos$\\
tangent& \verb!\tan! & $\tan$\\
cotangent& \verb!\cot! & $\cot$\\
secant& \verb!\sec! & $\sec$\\
cosecant& \verb!\csc! & $\csc$\\
inverse sine& \verb!\arcsin! & $\arcsin$\\
inverse cosine& \verb!\arccos! & $\arccos$\\
inverse tangent& \verb!\arctan! & $\arctan$\\
\end{tabular}

\section{Symbols (in \emph{text} mode)}

The followign symbols do \textbf{not} have to be surrounded by dollar signs.

\begin{tabular}{lll}
\emph{description} & \emph{command} & \emph{output}\\
dollar sign & \verb!\$! & \$ \\
percent & \verb!\%! & \% \\
ampersand & \verb!\&! & \& \\
pound & \verb!\#! & \# \\
backslash & \verb!\textbackslash! & \textbackslash \\
left quote marks & \verb!``! & `` \\
right quote marks & \verb!''! & '' \\
single left quote  & \verb!`! & ` \\
single right quote  & \verb!'! & ' \\
hyphen & \verb!X-ray! & X-ray\\
en-dash & \verb!pp. 5--15! & pp. 5--15 \\
em-dash & \verb!Yes---or no?! & Yes---or no?
\end{tabular}

\section{Resources}
Great symbol look-up site: \href{http://detexify.kirelabs.org/}{Detexify}\\
\href{http://amath.colorado.edu/documentation/LaTeX/Symbols.pdf}{\LaTeX\ Mathematical Symbols}\\
\href{ftp://tug.ctan.org/pub/tex-archive/info/symbols/comprehensive/symbols-letter.pdf}{The Comprehensive \LaTeX\ Symbol List}\\
\href{http://mirrors.med.harvard.edu/ctan/info/lshort/english/lshort.pdf}{The Not So Short Introduction to \LaTeX\ 2$\varepsilon$}\\
\href{http://www.tug.org/}{TUG: The \TeX\ Users Group}\\
\href{http://www.ctan.org/}{CTAN: The Comprehensive \TeX\ Archive Network}\\
~\\
\LaTeX\ for the Mac: \href{http://www.tug.org/mactex/}{Mac\TeX}\\
\LaTeX\ for the PC: \href{http://www.texniccenter.org/}{{\TeX}nicCenter} and \href{http://miktex.org/}{MiK\TeX}\\
\LaTeX\ online: \href{http://www.writelatex.com/}{WriteLaTeX}.
\vfill
\hrule
~\\
Dave Richeson, Dickinson College, \href{http://divisbyzero.com/}{http://divisbyzero.com/}
\end{multicols}

\end{document}


%
% @author   Shmish  "shmish90@gmail.com"
% @legal    MIT     "(c) Christopher Schmitt"
%

\documentclass{article}

%
% Document Imports
%

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{color}

%
% Document Configuation
%

\newcommand{\hwAuthor}{Christopher Schmitt}
\newcommand{\hwSubject}{Math 218}
\newcommand{\hwSection}{Section 81}
\newcommand{\hwSemester}{Summer 2019}
\newcommand{\hwAssignment}{Assignment 2}

%
% Document Enviornments
%

\setlength{\headheight}{65pt}
\pagestyle{fancy}
\lhead{\hwAuthor}
\rhead{
  \hwSubject \\
  \hwSection \\
  \hwSemester \\
  \hwAssignment
}

\newenvironment{problem}[1]{
  \nobreak\section*{Problem #1}
}{}

%
% Document Start
%

\begin{document}
  \begin{problem}{1}
    Let $x$ be a fixed positive real number. Prove that there exists a unique positive real number $y$ such that $xy = 3$.
    \begin{proof} Let $x$ be a fixed positive real.
      \begin{equation*}
        \begin{split}
          xy & = 3\\
          \frac{xy}{x} & = \frac{3}{x}\\
          y & = \frac{3}{x}\text{, which is a positive real.}
        \end{split}
      \end{equation*}
      Suppose $x(y_1) = 3$\\
      Suppose $x(y_2) = 3$
      \begin{equation*}
        \begin{split}
          x(y_1) & = x(y_2)\\
          \frac{x(y_1)}{x} & = \frac{x(y_2)}{x}\\
          y_1 & = y_2\text{, thus any two solution are the same.}
        \end{split}
      \end{equation*}
    \end{proof}
  \end{problem}

  \begin{problem}{2}
    Write the negation of the following statement in English. Do not simply add the words “not” or “it is not the case that” or similar before the existing statement.
    \begin{center}
      “Every dog likes some flavor of Brand XYZ dog food.”
    \end{center}
    \textbf{Solution}
    \begin{center}
      “Some dog does not like any flavor of Brand XYZ dog food.”
    \end{center}
  \end{problem}

  \begin{problem}{3}
    Consider the following compound statements:
    \begin{center}
      $(p \implies q) \wedge (\neg r \implies q)$ and $(p \vee \neg r) \implies q$
    \end{center}
    are logically equivalent by constructing truth tables.
    \begin{center}
    \begin{tabular}{@{ }c@{ }@{ }c@{ }@{ }c | c@{ }@{}c@{}@{ }c@{ }@{ }c@{ }@{ }c@{ }@{}c@{}@{ }c@{ }@{}c@{}@{ }c@{ }@{ }c@{ }@{ }c@{ }@{ }c@{ }@{}c@{}@{ }c}
      p & q & r &  & ( & p & $\rightarrow$ & q & ) & $\&$ & ( & $\sim$ & r & $\rightarrow$ & q & ) & \\
      \hline
      T & T & T &  &  & T & T & T &  & \textcolor{red}{T} &  & F & T & T & T &  & \\
      T & T & F &  &  & T & T & T &  & \textcolor{red}{T} &  & T & F & T & T &  & \\
      T & F & T &  &  & T & F & F &  & \textcolor{red}{F} &  & F & T & T & F &  & \\
      T & F & F &  &  & T & F & F &  & \textcolor{red}{F} &  & T & F & F & F &  & \\
      F & T & T &  &  & F & T & T &  & \textcolor{red}{T} &  & F & T & T & T &  & \\
      F & T & F &  &  & F & T & T &  & \textcolor{red}{T} &  & T & F & T & T &  & \\
      F & F & T &  &  & F & T & F &  & \textcolor{red}{T} &  & F & T & T & F &  & \\
      F & F & F &  &  & F & T & F &  & \textcolor{red}{F} &  & T & F & F & F &  & \\
    \end{tabular}
    \end{center}
    \begin{center}
      \begin{tabular}{@{ }c@{ }@{ }c@{ }@{ }c | c@{ }@{}c@{}@{ }c@{ }@{ }c@{ }@{ }c@{ }@{ }c@{ }@{}c@{}@{ }c@{ }@{ }c@{ }@{ }c}
        p & q & r &  & ( & p & $\lor$ & $\sim$ & r & ) & $\rightarrow$ & q & \\
        \hline
        T & T & T &  &  & T & T & F & T &  & \textcolor{red}{T} & T & \\
        T & T & F &  &  & T & T & T & F &  & \textcolor{red}{T} & T & \\
        T & F & T &  &  & T & T & F & T &  & \textcolor{red}{F} & F & \\
        T & F & F &  &  & T & T & T & F &  & \textcolor{red}{F} & F & \\
        F & T & T &  &  & F & F & F & T &  & \textcolor{red}{T} & T & \\
        F & T & F &  &  & F & T & T & F &  & \textcolor{red}{T} & T & \\
        F & F & T &  &  & F & F & F & T &  & \textcolor{red}{T} & F & \\
        F & F & F &  &  & F & T & T & F &  & \textcolor{red}{F} & F & \\
        \end{tabular}
    \end{center}
  \end{problem}

  \begin{problem}{4}
    Prove that the compound statements in Problem 3 are logically equivalent by using the basic logical equivalences. At each step, state which basic logical equivalence you are using.
    \begin{enumerate}
      \item $(p \implies q) \wedge (\neg r \implies q)$
    \end{enumerate}
    Since $(p \implies q) \wedge (r \implies q) \equiv (p \vee r) \implies q$, we can skip right to:
    \begin{enumerate}
      \item[2.] $(p \vee \neg r) \implies q$
    \end{enumerate}
  \end{problem}

  \begin{problem}{5}
    Write the compound statements in Problem 3 in disjunctive normal form. (Since they are logically equivalent, they have the same disjunctive normal form, so you only need to give one answer.
    \begin{center}
      $(p \wedge q \wedge r) \vee (p \wedge q \wedge \neg r) \vee (\neg p \wedge q \wedge r) \vee (\neg p \wedge q \wedge \neg r) \vee (\neg p \wedge \neg q \wedge r)$
    \end{center}
  \end{problem}

  \begin{problem}{6}
    Consider the premises:
    \begin{enumerate}
      \item It is not snowing today and it is windy;
      \item School will be canceled only if it is snowing today;
      \item If school is not canceled today, then our study group will meet;
      \item If I did not get A on the exam, then our study group did not meet.
    \end{enumerate}
    Do these premises imply the conclusion “I will get A or B on the exam”? If so, explain why by using the rules of inference. If not, explain why not.
    \begin{enumerate}
      \item $\neg S \wedge W$
      \item $C \iff S$
      \item $\neg C \implies G$
      \item $\neg A \implies \neg G$
    \end{enumerate}
    \textbf{Steps}
    \begin{enumerate}
      \item Contrapositive of 4: $G \implies A$
      \item School is not canceled because $C \iff S$ and $\neg S \wedge W$
      \item School is not canceled, so the group meets because $\neg C \implies G$
      \item And $G \implies A$ as seen earlier. So $A \vee B$ is true because $G$ is true.
    \end{enumerate}
  \end{problem}
\end{document}


\documentclass[11pt,pdftex,a4paper, twocolumn]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{float}
\usepackage[pdftex]{graphicx}
\usepackage{listings}
%\usepackage[pdftex]{graphicx}
\include{sort}
\addto\captionsenglish{\renewcommand{\figurename}{Fig.}}
\setlength{\abovecaptionskip}{-5mm}
\setlength{\belowcaptionskip}{-2mm}
\setlength{\dblfloatsep}{0mm}
\begin{document}
\title{Projekt-INF:\\
Implementation of in-place merge sort algorithms}
\author{Patrick Spaney, Kai Ziegler, Jonas Kittelberger, \\ Raphael Brösamle}
\date{Institut für Formale Methoden der Informatik \\ Universität Stuttgart\\
\normalsize Betreuer: Dr. Armin Weiß\\
Prüfer: Prof. Dr. Volker Diekert}
\maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Introduction}
Traditionally, the problem of sorting a given array by the key values of its elements is a common problem in computer science and thus has been subject to extensive research throughout the evolution of the field. \\
Merge sort is a sorting algorithm that is of special interest due to its $O(n \cdot \log(n))$ worst case time bound. Therefore, when a guaranteed worst-case runtime matters, merge sort is chosen over e.g. standard implementations of quicksort, which are usually very fast but have an upper bound of $O(n^{2})$. At the same time, other worst-case efficient sorting algorithms like heapsort are often considerably slower, giving merge sort the edge in many situations. \\
It employs the \textit{“divide and conquer”} paradigm by dividing the given list into smaller sublists, either to a size of one that can always be considered sorted, or until some lower bound is reached, at which point another sorting algorithm is used. Those sorted sublists are then consecutively merged, creating one sorted list from two smaller ones at a time. \\
This allows very simple recursive top-down implementations whose functionality is largely affected by the choice of merging strategies. \\
As one can see, standard versions of merge sort can also be easily parallelised, but this property does not hold for the implementations we will present here because they rely on using not yet sorted parts of the list as extra space to speed up the sorting process. \\
Despite its desirable properties, one big downside of naive merge sort implementations is the required linear extra space, making in-place algorithms like quicksort or heapsort a more suitable choice if memory usage is essential. \\
Therefore, many in-place variants of merge-sorts have been suggested by several authors, ranging from implementations for in-place merges that can then be easily integrated in a naive merge-sort algorithm by replacing the previous merging procedure to entirely modified sorting schemes. \\
In this paper we will discuss a full in-place merge sort by Reinhardt\cite{Reinhardt92} and two in-place merging algorithms, one by Chen\cite{Chen06} and another by Huang and Langston\cite{huang1988practical}. We used the latter ones to implement simple top-down in-place merge sorts. \\
We will describe our implementations giving special attention to parts where our implementation differs from the original algorithms, which applies especially to some versions of Reinhardt’s algorithm. \\
Afterwards, we will give an overview on the various tests we ran, comparing our implementations both against one another and against existing in-place merge sort implementations. We focuse on measuring the performance in means of time, comparisons and assignments. The latter ones are well established measures of complexity for sorting algorithms as they are independent of the machine the algorithm is running on.

\section*{Literature research on in-place merge sort algorithms}
Different authors have proposed algorithms and strategies for in-place merging and merge sorting. Chen’s algorithm for example is itself a simplification of an in-place merging algorithm presented by Geffert et al.\cite{geffert2000asymptotically}. \\
An early approach to in-place merging is the algorithm of Mannila and Ukkonen\cite{mannila1984simple} that makes use of partitioning the given lists into blocks, that are then rearranged to provide for easier merging. \\
Huang and Langston later provided a much simpler approach also relying on the rearrangement of blocks and using one block as internal buffer. Similar techniques have been employed in many in-place merging algorithms. \\
In the paper from Katajainen, Pasanen and Teuhola\cite{katajainen1996practical} another in-place merge sort algorithm was pointed out. The algorithm works broadly similar to Reinhardt (see next section) by merging a part of the unsorted list into the already sorted part in one iteration. In contrast to Reinhardt, only half (and not two thirds!) of the unsorted elements are sorted in one iteration by using the other half as gap. Afterwards, the gap is located between the recently and the previously sorted list. The now following merge is obviously very simple because it can be realised without any collision of the lists. This holds because the recently sorted list is not larger than the gap. Therefore, this concept leads to an in-place merge sort algorithm which is easier to implement but needs more comparisons than Reinhardt.  \\
A more recent algorithm is presented by Dalkilic, Acar and Tokatli\cite{dalkilic2011simple}, relying on an efficient in-place algorithm for shuffling two lists and the corresponding inverse operation. In this context, shuffling means to interleave the elements of both lists while keeping their order among elements originating from the same list. The shuffled lists can be efficiently sorted by consecutively inverse-shuffling parts that will afterwards be in correct order.

\section*{Description of implementations}
\subsection*{Test environment and standard mergesort}
We started by implementing some versions of the standard merge sort with extra storage matching the size of the given list. In the files \textit{rec\_mergesort\_reference.cpp} and \textit{rec\_mergesort\_iter.cpp}, we implemented the recursive standard merge sort on a reference to a vector and on begin-/end-iterators. They work according to the known principle of pairwise merging two lists to one bigger list. Thereby we merge between the extra storage and the original list alternating each iteration. We implemented insertion sort and a small sort which can be used for small sizes in the last recursion step. The last step can be performed within the original list or between the lists so that a final copy of the whole list can be avoided in any case. \\
We also implemented an iterative merge sort (\textit{iterative\_mergesort.cpp}) which similarly needs additional storage the same size of the original list. \\
A disadvantage of the recursive variant is the logarithmic space for the internal stack. But on the other side, it is a simple and elegant way to split a long list into parts of equal length throughout all recursion levels. Thus it is important to remark that true in-place sort algorithms may also use extra space for recursive execution (even though they just work on the original list per definition). \\
For test cases we implemented different test environments. We used the main function in the \textit{“TestAndEvaluation”}-project for obtaining our test results. The user can choose between different types to sort, the list sizes and a lot of other options (\textit{main.h}). The user can start the test by executing the main procedure (\textit{main.cpp}) and the results (average time, comparisons and assignments per size of the list) are written to CSV-Files. We implemented a general BigType (\textit{structs.h}) and a general PointerType to weigh assignments and/or comparisons differently. Sorting the BigType makes the assignments more expensive and the user can choose whether the computation of the comparisons should also be expensive. To get expensive comparisons and cheap assignments, the user can choose the PointerType on the BigType with expensive comparisons.

\subsection*{Reinhardt}
Reinhardt‘s in-place mergesort algorithm consists of two main procedures: \\
In the first step, $\frac{2}{3}$ of the unsorted elements are sorted by using the other $\frac{1}{3}$ of the unsorted elements as gap \textit{(reinhardt\_gapsort)}. \\
In the second step, the sorted elements of the first step (called “short” list) are merged with the previous sorted elements (called “long” list) \textit{(reinhardt\_merge)}. \\
Therefore, we can merge $\frac{2}{3}$ of the unsorted elements into the sorted list in a single iteration. Despite this being a full description of an $O(n \cdot \log(n))$ in-place-mergesort, we need a lot of time to swap all elements after one iteration as well as in the asymmetric merge in step two. \\
Therefore, we implemented some improvements, most of them also described in the paper: \\
In the whole algorithm we regard our elements as a ring list to skip the moves after one iteration \textit{(*\_ring)}. For this we “overloaded” the dereference operator so that every iterator points on the shifted element. But because of the worse results and the incompatibility with the following improvements, we just continued without the ring list and leave a more detailed explanation. \\
We also implemented two other procedures that can be executed instead of the “usual” step \textit{(quick\_steps)}. They perform a quickselect- or quicksort-step on the unsorted elements and then merge them with a part of the long list. After this step, the merged elements are on their correct position and do not need to be considered any more. \\
In the following, we give a more detailed description of the stated procedures. \\
$ $ \\
\textbf{In-place mergesort basic routine \textit{(inplace\_mergesort\_[qsel / qsort])}} \\
Firstly, we sort $\frac{4}{5}$ elements of the whole list by using $\frac{1}{5}$ as gap. This is possible in the first iteration because we do not need to consider the gap for step two. After that, we call the recursive procedure which executes the two steps mentioned above. We implemented an integer-flag where the user can choose the frequency of quicksort or quickselect iteration compared to the usual iteration. A quicksort step can leave the new gap on the right side, therefore we needed to implement an analogous second procedure for this case. As soon as the gap size undercuts a short number, we execute one parallel insertion sort step for the left block by use of binary search for efficiency reasons. \\
$ $ \\
$ $ \\
\textbf{Step one \textit{(reinhardt\_gapsort)}} \\
We sort the elements between the passed iterators by using $\frac{size}{4}$ elements as a gap on the left or on the right side. For this we firstly sort four quarters of the list with the usual recursive mergesort \textit{(rec\_mergesort\_iter)} and the gap as “extra storage”. Therefore, we permanently have to swap the gap elements instead of just assigning them to the extra memory. \\
Afterwards we merge the four quarters in a way quite similar to the symmetric merge procedure described below (step two). \\
Step one can also be used as a full sorting algorithm with $\frac{size}{4}$ extra space \textit{(reinhardt\_extrasort)}. The number of assignments is obviously bigger for the in-place mergesort due to swapping instead of moving. But $\frac{size}{4}$ extra space is only just enough to avoid any additional costs for swapping or shifting. \\
$ $ \\
\textbf{Step two \textit{(reinhardt\_merge)}} \\
The merge procedure expects the longer list being between the gap and the shorter list and a minimal gap size of half of the shorter list. The merge direction changes after a “collision” with the longer list, exactly as described by Reinhardt\cite{Reinhardt92} (chapter two). \\
To reduce the number of comparisions, we also implemented an asymmetric merge variant. For this we compare the first element of the shorter list with the $2^n$’th element of the longer list whereas $n$ is chosen depending on the relation of the list sizes. Afterwards, the whole block of the longer list can be moved or a binary search in the block is needed. The case $2^n = 1$ is equal to the usual symmetric merge. \\
$ $ \\
\textbf{Quickselect and Quicksort iteration \textit{(quick\_steps)}} \\
The quickselect iteration extracts the $\frac{2}{3}$-smallest element of the gap and partitions the gap elements around. Note that this step should not exceed $O(n \cdot \log(n))$ in worst case to retain $O(n \cdot \log(n))$ as worst case runtime for the whole sort. Afterwards, the small-elements partition is sorted with step one by using the big-elements partition as gap. Now we determine the fitting small-elements list of the long list by binary search and then the two small-elements lists are merged (after a possibly necessary swap of the lists). \\
Although there is a non-negligible overhead for the quickselect procedure, all the merged elements are on their correct position and the gap size is reduced by the same amount as in the usual step. \\
$ $ \\
The quicksort iteration as described in chapter five does not guarantee a specific reduction of the gap size, but it moves half of the long list to the correct position. Therefore, the size of the remaining “long” list could get very small and in this case we just continue to execute the usual iteration in the basic routine for efficiency reasons. \\
The quicksort step works as follows: \\
After quicksort on the unsorted elements with the middle element of the long list as pivot, we sort the partition of the bigger or the smaller elements depending on the size of the partitions. Before the following merge with the bigger or the smaller half of the long list, we possibly need some swaps to get the lists to be merged in the right order. After the merge, the remaining gap may have changed on the other side and in this case the other recursive basic routine is called.

\subsection*{Chen}
Chen describes a linear time in-place merging procedure that we used to implement a merge sort algorithm. \\
The merge requires two adjacent sorted lists and a block size k as input. Both sublists are divided into a series of blocks, each of size k (with the possible exception of an undersized leftmost block of length f). The two rightmost blocks of the first sublist will initially be used as internal buffers. During the execution of the merge, the order of the left list's blocks may be altered but the elements within each block, again excluding the buffer blocks, remain sorted. The elements are inserted into a hole, which is created by moving one element to some temporary memory. As the algorithm progresses, the hole is always at the position where the next element will be inserted. While the position of the hole and the second list’s smallest element are only incremented by 1 each time they are updated, the buffers and the first list’s current block, containing its smallest elements, require more attention. We will explain this in the following description of the corresponding procedures. \\
We do not provide a detailed description of all the procedures, as our implementation does not differ from the pseudo-code given by Chen in most parts, but we will provide a short overview. \\
Some notations: $n$ denotes the size of the list. As in the original paper we will use X to denote the first and Y to denote the second sublist. \\
$ $ \\
\textbf{\textit{mergesort\_chen}}: \\
Divides the given list into two sublists of equal size. The first sublist is always sorted with another merge sort algorithm, using the second one as extra space, while the second sublist is handled by a recursive call to \textit{“mergesort\_chen”}. The recursion stops when the list contains 50 or less elements and the remaining list is sorted by insertion sort.  Both sublists are then merged using the “merge”-procedure with block size $k=\sqrt{n}$. \\
$ $ \\
\textbf{\textit{merge}}: \\
This is the main procedure of Chen’s merging algorithm. Firstly, there is some preparatory work, mostly initialising variables, like the size $f$ of a possible undersized leftmost block and the position of the $b1$ and $b2$ buffer (specificly the iterators to the respective first element). The buffers initially consist of the two rightmost X-blocks. Also the hole must be created and the corresponding element must be stored in temporary memory. Afterwards, we begin to merge both sublists in a while-loop until there is no more room for the buffers in the remainder of X, i.e. all but 2k X-elements are in their final position. First we check whether the current X- or Y-element is smaller or the second sublist is exhausted, in which case we always pick the X-element. In either case the following moves will be executed: \\
hole $\leftarrow$ smaller $\leftarrow$ buffer element $\leftarrow$ element currently in next hole. \\
While the hole position $z$ and the current Y-element position $y$ are only incremented by one in each iteration, it is a bit trickier to keep $b1$, $b2$ and the current X-element position $x$ updated. The latter one is updated each time it hits a block boundary by the \textit{“findNextXBlock”} procedure. If the hole is not currently positioned in the block just left by $x$, then $b2$ is set to $x-k$ before $x$ is updated because the block does now consist solely of buffer elements. The same buffer-update will be applied if $y$ reaches a block boundary, but we do not need to check for the position of $z$ in this case. Furthermore, $b2$ must be invalidated if the hole enters the current $b2$ block, which is done by setting $b2$ to the end-iterator of the current list. In each iteration we need to increment $b1$ and when it hits a block boundary, we set it to $b2$ if a $b2$ buffer is available. Otherwise the $b1$ buffer can be reused and we set it to $b1-k$. After the while-loop terminates, we can put the element we used to create the initial hole back in the current hole, which is the first position of the remaining buffer. \\
This process leaves us with a sorted output block where every element is already in its final position, two unsorted buffer blocks and possibly a sorted remainder of Y. \\
As suggested by Chen, we handled the remaining list by first sorting the buffer, merging the sorted buffer and the remaining Y-elements with block size $\sqrt{k}$ and then using \textit{“mergeBandY”} in the recursive invocation of \textit{“merge”}. The proposed heapsort for sorting the buffer is replaced by our \textit{“mergesort\_chen”} procedure, as our goal is to compare different in-place merge sort algorithms without using other sorting algorithms for greater parts of the lists. Moreover, due to the $O(k^{2}+|remainder of Y|)$ time complexity of \textit{“mergeBandY”}, we do the recursive step two times instead of one before using \textit{“mergeBandY”} because the list can still be quite large in the first recursion step. \\
$ $ \\
\textbf{\textit{mergeBandY}}: \\
Merges an unsorted block B with a sorted Block Y until B or Y is exhausted. \\
If B is exhausted first, the merge is finished, otherwise the remaining B-elements need to be sorted differently. Again, we chose \textit{“mergesort\_chen”} over heapsort for this task. \\
This procedure is not very efficient because in each step we determine the smallest remaining B-element and compare it with the current Y-element. \\
$ $ \\
\textbf{\textit{findNextXBlock}}: \\
As the X-blocks are not always in their correct order during the merging process, we use this function to determine the next block after we hit a block boundary. \\
This is accomplished by comparing all X-blocks, excluding buffer blocks, by their respective first and last element and choosing the X-block with the smallest elements.

\subsection*{Huang and Langston}
Like Chen, Huang and Langston describe a linear time in-place merging procedure that can then be used to implement a full merge sort algorithm. \\
The merge is accomplished by moving the $\sqrt{n}$ largest elements of the list to the front and using them as internal buffer.
The remainder of each sublist is then divided into blocks of size $\sqrt{n}$. In case this is not possible without at least one undersized block we must do some preparatory work first. \\
We omit the details here and assume the list is ready for the main algorithm to commence. \\
First, the blocks need to be sorted by their rightmost elements. \\
Selection sort is a good choice for this as it is very easy to implement and performs only $O(n)$ swaps. \\
Afterwards we need to determine the next two series of elements to be merged. \\
The first series consists of the first block after the buffer and all following blocks until one block’s rightmost element is larger than the next block’s leftmost element. The second series consists only of the latter block. These two series are merged, beginning at the leftmost buffer position and breaking ties in favour of the first series until the first series is exhausted. Therefore, the second series will still contain at least one element and the buffer elements will be back in one piece, adjacent to the left of the second series’ remainder.
This process, starting with finding the two series, is now repeated with the first “block” of the new first series being the remainder of the last second series until there is no second series to be found. \\
Then we just need to perform a cyclic shift of the remaining elements and the buffer, leaving the list sorted except for its $\sqrt{n}$ rightmost elements, consisting only of the buffer elements. Since these are the largest elements of the list, we just need to sort them in order to finish sorting the whole list. \\
The paper of Huang and Langston does not provide a specific suggestion as to how the buffer should be sorted. For the purpose of using solely the algorithm in the paper, we sort the buffer by a recursive call to our merge sort implemented with the described merge of Huang and Langston. \\
$ $ \\
We will give a quick outline of our implementation’s basic procedures. \\
Note that $n$ is always referring to the size of the list \textit{“merge”} is initially called with. \\
$ $ \\
\textbf{\textit{mergesort}}: \\
Divides the given list into two sublists of equal size. The first sublist is always sorted with another merge sort algorithm, using the second one as extra space, while the second sublist is handled by a recursive call to \textit{“mergesort”}. The recursion stops when the list contains 50 or less elements and the remaining list is sorted by insertion sort.  Both sublists are then merged using the \textit{“merge”}-procedure. \\
$ $ \\
\textbf{\textit{merge}}: \\
Determines the $\sqrt{n}$ largest elements that will constitute the buffer and whether the remaining sublists meet the size requirements (integral multiples of $\sqrt{n}$). If the requirements are met, the basic merge procedure, as described above, can commence. The buffer will then be extracted using two cyclic shifts and \textit{“basic\_inplace\_merge”} is called. Otherwise some undersized blocks must be extracted alongside the buffer, so we can again use \textit{“basic\_inplace\_merge”} on the remaining list (and merge one of the undersized blocks afterwards). \\
$ $ \\
\textbf{\textit{basic\_inplace\_merge}}: \\
This is where the actual merging begins. As explained above, we now regard our list, excluding the buffer, as a list of blocks, each of size $\sqrt{n}$. The blocks need first be sorted by their rightmost element. This is done by \textit{“sort\_blocks”}, which is essentially an implementation of selection sort. The following process of finding new series and merging them is accomplished by alternating calls to \textit{“merge\_with\_buffer”} and \textit{“find\_series”}, the first one obviously performing the merge and returning the start of the new first series. The latter one simply returns the start of the new second series or, if no such series can be found, the end-iterator that serves as condition to terminate the loop. Afterwards, the buffer is shifted to its final place and is sorted. This is done by using \textit{“mergesort”}, for the purpose of testing only the merge of Huang and Langston. \\
$ $ \\
\textbf{\textit{merge\_with\_buffer}}: \\
Merges the first and second series, with the resulting list beginning at the first buffer position, until the first series’ elements are exhausted. Ties are broken in favour of the first series. As a result, the buffer will be in one place after the procedure, adjacent to the right of the sorted list and followed by at least one unmerged element of the second series.

\section*{Test results}
In the following we will describe and analyse the results of the tests. Although it is not possible to compare all versions of the in-place merge sorts with all possible test conditions, we try to cover a broad range to show the main results. The raw data and further results are given in the \textit{“Test\_Diagramme”} file. \\
For all the tests given here, we sorted equally distributed integer values or big types, consisting of an integer array of length 30, in multiple runs (of course more runs for smaller lists) on the server. \newpage We start by comparing our in-place merge sort implementations with each other. \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/ints-time.JPG} \\
\caption{ $ \frac{Time(ns)}{n \cdot \log(n)} $ for different integer list sizes $ n $ } \label{fig:ints-time}
\end{figure}
Integers do not need much time to be assigned. Therefore the time in this test is mainly influenced by other statements like index computations. This can also be seen by a comparison with the following result. \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/big-beidesTeuer.JPG} \\
\caption{ $ \frac{Time(ns)}{n \cdot \log(n)} $ for different Bigtype list sizes } \label{fig:big-beides-Teuer}
\end{figure}
The result from Fig.\ref{fig:big-beides-Teuer} is mainly influenced by the number of comparisons and assignments (see Fig.\ref{fig:ints-comp} / Fig.\ref{fig:ints-assign}). As one can see, the used algorithm or version of algorithm should be chosen depending on the type for better performance. For a universal measure, independent of type, compiler and operating system, the number of comparisons and assignments can be evaluated. \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/ints-comparisons.JPG} \\
\caption{ $ \frac{Comparisons}{n \cdot \log(n)} $ for different list sizes $ n $ } \label{fig:ints-comp}
\end{figure}
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/ints-assignments.JPG} \\
\caption{ $ \frac{Assignments}{n \cdot \log(n)} $ for different list sizes $ n $ } \label{fig:ints-assign}
\end{figure}
The standard merge sort does roughly one assignment after one comparison and has only a small additional number of assignments (see \textit{“Test\_Diagramme”}). One can see that all our in-place versions need roughly just two assignments per comparison. \\
In most diagrams, we show the results divided by $ n \cdot \log(n) $. Therefore, time, comparisons and assignments should be nearly constant throughout different list sizes for all mergesort implementations. To conclude to other specific implications, another scale may be used. E.g. the following diagram can be used as proof that the number of comparisons does not exceed $ n \cdot \log(n) + O(n) $. If this number is not exceeded then the values do not increase for an increasing list size. \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/ints-time-otherNormalization.JPG} \\
\caption{Comparisons with another normalisation ( $ \frac{Comparisons - n \cdot \log(n)}{n} $)} \label{fig:ints-time-otherNormalization}
\end{figure}
In the test from Fig. \ref{fig:ints-time-otherNormalization} we did not use the usual insertion sort for small sublists as its usage leads to a varying number of additional comparisons depending on how the list is partitioned. \\
For a clearer comparison of Huang and Chen it is possible to just compare the merges because they can be substituted in the algorithm. But here it is important to mention that Reinhardt’s merge works completely different because it merges to another range and although the std-inplace-merge merges to the same range, it needs additional memory to only use $ n-1 $ comparisons. \\
The runtime of the merges reflects the bad result of Chen in the first test more clearly. But it is important to remind that the runtime also depends on compiler and device. For results of the server see \textit{“Test\_Diagramme”}. \\
$ $ \\
For a usual laptop and another compiler we got the following time average for multiple runs of the merges with 10 Mio. elements: \\
\scriptsize
\begin{tabular}{|c|c|c|c|} \hline
Chen & Reinhardt & Huang & StdInpl-merge \\ \hline
148 418 ns & 88 717 ns & 99 766 ns & 147 056 ns \\ \hline
\end{tabular}
\normalsize \\
$ $ \\
And if we make comparisons/assignments more relevant by use of lists with 1 million bigtypes, we get an entirely different relation of results for multiple runs on the laptop: \\
\scriptsize
\begin{tabular}{|c|c|c|c|} \hline
Chen & Reinhardt & Huang & StdInpl-merge \\ \hline
317 783 ns & 309 832 ns & 485 642 ns & 247 364 ns \\ \hline
\end{tabular}
\normalsize \\
In the above tests (except Fig.\ref{fig:ints-time-otherNormalization}), we ran the in-place algorithm of Reinhardt by using insertion sort in \textit{"reinhardt\_gapsort"} for small cases and the asymmetric merge in \textit{"reinhardt\_merge"}. Furthermore we utilised the quickselect step in every iteration. \\
But if we make specific demands to the sort, e.g. a small number of comparisons, we can switch to a more suitable mode. In the following, we will compare the different Reinhardt modes between each other. In all runs, we use integer as type to be sorted. \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/diff-iterations-time.JPG} \\
\caption{ $ \frac{Time(ns)}{n \cdot \log(n)} $ different Reinhardt iterations } \label{fig:diff-iterations-time}
\end{figure}
We can see that Reinhardt’s algorithm is fastest for integers if we just execute quickselect or quicksort iterations. Though these iterations need some more comparisons for the execution of quicksort or quickselect, the number of assignments is smaller. This can also be seen clearly in the following diagrams. \\
$ $ \\
\includegraphics[width=\linewidth]{Diagramm-Bilder/diff-iterationsAndMerges-comparisons.JPG}
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/diff-iterationsAndMerges-assignments.JPG} \\
\caption{Comparisons and Assignments for different Reinhardt merges} \label{fig:diff-iterationsAndMerges-assignAndComp}
\end{figure}
Merging asymmetric is a big improvement for time and number of comparisons (obviously not for number of assignments) of the usual iteration because in the usual iteration, the short list is always merged with all other sorted elements. For the time of the quickselect iteration, the asymmetric merge is, especially for the runtime, no improvement in this test case. \\
For a further reduction of comparisons and thus for sorting comparison-expensive types, it is also a good idea to replace insertion sort in the sort of the gap for small cases (here all along 50 elements) by aborting the recursive procedure later (3-smallsort).
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/comparisons-diff-iter-and-smallsorts.JPG} \\
\caption{Comparisons for different Reinhardt smallsorts} \label{fig:comparisons-diff-iter-and-smallsorts}
\end{figure}
The result is not surprising because merge sort needs less comparisons than insertion sort. But on the other side, insertion sort is used many times as sort for small cases because it is often executed faster for integers: \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/time-diff-iter-and-smallsorts.JPG} \\
\caption{ $ \frac{Time(ns)}{n \cdot \log(n)} $ for Reinhardt smallsorts} \label{fig:time-diff-iter-and-smallsorts}
\end{figure}
$ $ \\
We also compared our implementations with some existing in-place merge sorts: \\
\begin{figure}[H]
\includegraphics[width=\linewidth]{Diagramm-Bilder/time-other-inplace.JPG} \\
\caption{Time comparison with other in-place merge sorts} \label{fig:time-other-inplace}
\end{figure}
$ $ \\
In terms of comparisons and moves they are able to compete with the other algorithms. It must be said that some more sophisticated and specialized implementations can slightly outperform our implementations when it comes to the measured time.

\newpage
\nocite{wegener1993bottom}
\nocite{edelkamp2019worst}
\bibliographystyle{amsplain}
\bibliography{sort}

\end{document}