· 8 years ago · Feb 25, 2018, 11:36 AM
1{\footnotesize Note: This is by no means a full and complete introduction
2to \LaTeX{}. Its purpose is to introduce some of the symbols and notation
3used in various courses, and demonstrate how you can accomplish common
4tasks in \LaTeX{}. We encourage you to use this document as a template for
5your solutions.}
6\exercise
7\subexercise
8My solution to this exercise is a bunch of \textbf{logical symbols}:
9\begin{center}
10\begin{tabular}{>{\ttfamily}l c @{\hspace{3em}} >{\ttfamily}l c}
11\toprule
12\textbackslash{}exists & $\exists$ &
13\textbackslash{}forall & $\forall$ \\
14\textbackslash{}vee & $\vee$ &
15\textbackslash{}wedge & $\wedge$ \\
16\textbackslash{}Rightarrow & $\Rightarrow$ &
17\textbackslash{}Leftrightarrow & $\Leftrightarrow$ \\
18\textbackslash{}neg & $\neg$ &
19\textbackslash{}equiv & $\equiv$ \\
20\textbackslash{}not\textbackslash{}equiv & $\not\equiv$ &
21& \\
22\bottomrule
23\end{tabular}
24\end{center}
25Although we usually use them inline: $\frac{x}{2} - y > 4 \Rightarrow x >
262(y + 4)$, or in a block:
27\[
28\frac{x}{2} - y > 4 \Rightarrow x > 2(y + 4).
29\]
30\subexercise
31Can't forget the \emph{set operations} and so forth: $P \cup \emptyset
32\not\subseteq Q$.
33\begin{center}
34\begin{tabular}{>{\ttfamily}l c @{\hspace{3em}} >{\ttfamily}l c}
35\toprule
36\textbackslash{}cap & $\cap$ &
37\textbackslash{}cup & $\cup$ \\
38\textbackslash{}setminus & $\setminus$ &
39\texttt{\{A\}\textasciicircum{}\textbackslash{}text\{c\}} &
40${A}^\text{c}$ \\
41\textbackslash{}mathcal\{P\} & $\mathcal{P}$ &
42\textbackslash{}mathcal\{U\} & $\mathcal{U}$ \\
43\textbackslash{}in & $\in$ &
44\textbackslash{}not\textbackslash{}in & $\not\in$ \\
45\textbackslash{}subseteq & $\subseteq$ &
46\textbackslash{}not\textbackslash{}subseteq & $\not\subseteq$ \\
47\textbackslash{}emptyset & $\emptyset$ & & \\
48\bottomrule
49\end{tabular}
50\end{center}
51\subexercise
52Some basic mathematical notation: normally, one needs to write
53\texttt{\textbackslash{}mathbb\{R\}} to get~$\R$, but we have defined
54shortcuts for you: \texttt{\textbackslash{}R} works!
55\[ \R \quad \N \quad \Z \quad \Q \quad < \quad > \quad \leq \quad \geq
56\quad \neq \quad x^2 \quad \sqrt{y} \]
57\[ 3 \cdot 3 = 3^2 = 9 \]
58\subexercise
59And some \emph{mathematical operators}.
60\begin{center}
61\begin{tabular}{>{\ttfamily}l c @{\hspace{3em}}}
62\toprule
63\textbackslash{}sum\_\{i=1\}\string^\{n\}\{i\string^2\} &
64$\sum_{i=1}^{n}{i^2}$\\
65&\\
66\textbackslash{}prod\_\{i=1\}\string^\{n\}\textbackslash{}left(i\string^2+i \textbackslash{}right) & $\prod_{i=1}^{n}\left(i^2+i\right)$\\
67&\\
68\textbackslash{}left\textbackslash{}lfloor\textbackslash{}frac\{x\}\{2
69\}\textbackslash{}right\textbackslash{}rfloor &
70$\left\lfloor\frac{x}{2}\right\rfloor$\\
71&\\
72\textbackslash{}left\textbackslash{}lceil\textbackslash{}frac\{x\}\{2\}\textbackslash{}right\textbackslash{}rceil &
73$\left\lceil\frac{x}{2}\right\rceil$\\
74\bottomrule
75\end{tabular}
76\end{center}
77\subexercise We can create matrices as follows:
78\[\begin{pmatrix}
790 & 1\\
801. & 1
81\end{pmatrix}\]
82\subexercise Recurrences:
83\[ T(n) = \left\{
84\begin{array}{ll}
852. & \mbox{if $n = 2$,} \\
862T(n/2) + n & \mbox{if $n = 2^k$, for $k > 1$}
87\end{array}
88\right. \]
89\subexercise
90You can align your equations as follows:
91\begin{align*}
92T(n) &= T(n/3)+T(2n/3)+n & \left\{\text{IH on~$n/3$ and
93$2n/3$}\right\}\\
94&\le c \cdot n/3 \log \left(n/3\right) + c \cdot 2n/3 \log
95\left(2n/3\right) + n & \big\{ \log \left(n/3\right) \le \log
96\left(2n/3\right) \text{ and }\\
97& & \text{some other requirement} \big\}\\
98&\le ...\\
99&\le c n\log n
100\end{align*}
101\subexercise
102Finally a basic table:
103\begin{center}
104\begin{tabular}{lcr}
105\toprule
106left & center & right \\
107\midrule
108l & c & r \\
109\bottomrule
110\end{tabular}
111\end{center}
112\exercise
113The basic proof setup is:
114\begin{proof}
115It can easily be seen that this statement is concluded with a
116\texttt{\textbackslash{}qed} symbol.
117\end{proof}
118\exercise
119\subexercise
120
121\begin{algorithm}[H]
122\caption{MyIncredibleAlgorithm($A, v$)}
123\KwIn{an array $A$ of $n$ numbers and a number $v$}
124\KwOut{an index $i$ such that $A[i] = 42$, or \textsc{NotFound} if no
125such index exists}
126$i \leftarrow 1$ \;
127\While{$i \leq n$ \And $A[i] \neq 42$}{
128$A[i].\textit{update()}$ \;
129$i \leftarrow i + v^2$
130}
131\tcc{the following loop runs over all of $A$}
132\For(\tcp*[f]{use a different indicator variable here}){$j \leftarrow 1$
133\To $n$}{
134something useful \tcp*{you can write text if that's more succinct}
135\If{$j$ is even}{
136$A[j].\textit{flip()}$
137}
138}
139\leIf{$i > n$}{
140\Return{\textsc{NotFound}}
141}{
142\Return{$i$}
143}
144\end{algorithm}
145\subexercise For analysis, you may want to know $O, \Theta, \Omega(n \log
146n)$ (not to be confused with $o, \omega$).
147\exercise
148A figure (such as Figure~\ref{fig:squares}) can be inserted, PDF format is
149preferred.
150\begin{figure}[hb] % The letters between square brackets tell LaTeX where
151the figure can be placed:
152% `h` means 'right here';
153% `b` means 'at the bottom of the page';
154% `t` means 'at the top of the page';
155% `p` means 'at a separate page (optionally with other figures if that
156fits).
157% Specifying only `h` will not work, LaTeX will automatically change
158that to `ht`.
159\begin{center}
160\includegraphics{squares}
161\caption{Three axis-aligned squares.}
162\label{fig:squares}
163\end{center}
164\end{figure}
165To insert a figure precisely where you want it to appear, you can leave
166away the \texttt{figure} environment. You will then however not be able to
167add a caption or refer to it.
168\begin{center}
169\includegraphics{squares}
170\end{center}
171The caption of Figure~\ref{fig:squares} can be left away completely, but
172you will not be able to refer to the figure anymore if you do that; the
173\texttt{\textbackslash{}label} only works right after a
174\texttt{\textbackslash{}caption}. Note how \LaTeX{} can automatically fill
175in the figure number for you, making it easy to refer to figures. The same
176approach works for tables, although it is common practice to put the
177caption before the table instead of below it; this can be seen in
178Table~\ref{tab:courses}.
179\begin{table}[bt]
180\caption{Courses taught by members of the Applied Geometric Algorithms
181group.}
182\label{tab:courses}
183\begin{center}
184\begin{tabular}{ll}
185\toprule
186\textbf{Course code} & \textbf{Course name} \\
187\midrule
1882IL50 & Data Structures \\
1892IT80 & Introduction to Discrete Structures \\
190JBI020 & Foundations of Computing \\
191\bottomrule
192\end{tabular}
193\end{center}
194\end{table}
195\subexercise
196As you can see, you can put text before the first subexercise as well, if
197you wish.