diff --git a/src/Advanced/Compression/main.tex b/src/Advanced/Compression/main.tex new file mode 100755 index 0000000..d3d8bd9 --- /dev/null +++ b/src/Advanced/Compression/main.tex @@ -0,0 +1,31 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\input{tikzset.tex} +\usepackage{units} +\usepackage{pdfpages} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Compression} +\subtitle{Prepared by Mark on \today{}} + +% TODO: add a section on info theory, +% shannon entropy. etc. + +\begin{document} + + \maketitle + + \input{parts/0 intro.tex} + \input{parts/1 runlength.tex} + \input{parts/2 lzss.tex} + \input{parts/3 huffman.tex} + \input{parts/4 bonus.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Compression/meta.toml b/src/Advanced/Compression/meta.toml new file mode 100644 index 0000000..ff6f333 --- /dev/null +++ b/src/Advanced/Compression/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Compression" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Compression/parts/0 intro.tex b/src/Advanced/Compression/parts/0 intro.tex new file mode 100644 index 0000000..d4135ac --- /dev/null +++ b/src/Advanced/Compression/parts/0 intro.tex @@ -0,0 +1,38 @@ +\section{Introduction} + +\definition{} +An \textit{alphabet} is a set of symbols. Two examples are +$\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$ and $\{\texttt{0}, \texttt{1}\}$. + +\definition{} +A \textit{string} is a sequence of symbols from an alphabet. \par +For example, \texttt{CBCAADDD} is a string over the alphabet $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$. + +\problem{} +Say we want to store a length-$n$ string over the alphabet $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$ as a binary sequence. \par +How many bits will we need? \par +\hint{ + Our alphabet has four symbols, so we can encode each symbol using two bits, \par + mapping $\texttt{A} \rightarrow \texttt{00}$, + $\texttt{B} \rightarrow \texttt{01}$, + $\texttt{C} \rightarrow \texttt{10}$, and + $\texttt{D} \rightarrow \texttt{11}$. +} + +\begin{solution} + $2n$ bits. +\end{solution} + +\vfill + + +\problem{} +Similarly, we can encode an $n$-symbol string over an alphabet of size $k$ \par +using $n \times \lceil \log_2k \rceil$ bits. Show that this is true. \par +\note[Note]{We'll call this the \textit{na\"ive coding scheme}.} + + +\vfill +As you might expect, this isn't ideal: we can do much better than $n \times \lceil \log_2k \rceil$. +We will spend the rest of this handout exploring more efficient ways of encoding such sequences of symbols. +\pagebreak diff --git a/src/Advanced/Compression/parts/1 runlength.tex b/src/Advanced/Compression/parts/1 runlength.tex new file mode 100644 index 0000000..e8c6e8f --- /dev/null +++ b/src/Advanced/Compression/parts/1 runlength.tex @@ -0,0 +1,190 @@ +% TODO: +% Basic run-length +% LZ77 + +\section{Run-length Coding} + + +%\definition{} +%\textit{Entropy} is a measure of information in a certain sequence. \par +%A sequence with high entropy contains a lot of information, and a sequence with low entropy contains relatively little. +%For example, consider the following two ten-symbol ASCII\footnotemark{} strings: +%\begin{itemize} +% \item \texttt{AAAAAAAAAA} +% \item \texttt{pDa3:7?j;F} +%\end{itemize} +%The first string clearly contains less information than the second. +%It's much harder to describe \texttt{pDa3:7?j;F} than it is \texttt{AAAAAAAAAA}. +%Thus, we say that the first has low entropy, and the second has fairly high entropy. +% +%\vspace{2mm} +% +%The definition above is intentionally hand-wavy. \par +%Formal definitions of entropy exist, but we won't need them today---we just need +%an intuitive understanding of the \say{density} of information in a given string. + +% +%\footnotetext{ +% American Standard Code for Information Exchange, an early character encoding for computers. \par +% It contains 128 symbols, including numbers, letters, and +% \texttt{!"\#\$\%\&`()*+,-./:;<=>?@[\textbackslash]\^\_\{|\}\textasciitilde} +%} + + +%\vspace{5mm} + + +\problem{} +Using the na\"ive coding scheme, encode \texttt{AAAA$\cdot$AAAA$\cdot$BCD$\cdot$AAAA$\cdot$AAAA} in binary. \par +\note[Note]{ + We're still using the four-symbol alphabet $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$. \par + Dots ($\cdot$) in the string are drawn for readability. Ignore them. +} + +\begin{solution} + There are eight \texttt{A}s on each end of that string. Mapping symbols as before, \par + we get \texttt{[00 00 00 00 00 00 00 00 01 10 11 00 00 00 00 00 00 00 00]} + + \begin{instructornote} + In this handout, all encoded binary is written in square brackets. \par + Spaces, dashes, dots, and etc are added for readability, and should be ignored. + \end{instructornote} +\end{solution} + + +\vfill +In \ref{runlenone}---and often, in the real world---the strings we want to encode have fairly low \textit{entropy}. \par +That is, they have predictable patterns, sequences of symbols that don't contain a lot of information. \par +\note{ + For example, consider the text in this document. \par + The symbols \texttt{e}, \texttt{t}, and \texttt{} are much more common than any others. \par + Also, certain subsequences are repeated: \texttt{th}, \texttt{and}, \texttt{encode}, and so on. +} +We can exploit this fact to develop encoding schemes that need relatively few bits per letter. + +\example{} +A simple example of such a coding scheme is \textit{run-length encoding}. Instead of simply listing letters of a string +in their binary form, we'll add a \textit{count} to each letter, shortening repeated instances of the same symbol. + +\vspace{2mm} + +We'll encode our string into a sequence of 6-bit blocks, interpreted as follows: + +\begin{center} + \begin{tikzpicture} + \node[anchor=west,color=gray] at (-2.3, 0) {Bits}; + \node[anchor=west,color=gray] at (-2.3, -0.5) {Meaning}; + \draw[color=gray] (-2.3, -0.25) -- (5.5, -0.25); + \draw[color=gray] (-2.3, 0.15) -- (-2.3, -0.65); + + \node at (0, 0) {\texttt{0}}; + \node at (1, 0) {\texttt{0}}; + \node at (2, 0) {\texttt{1}}; + \node at (3, 0) {\texttt{1}}; + \node at (4, 0) {\texttt{0}}; + \node at (5, 0) {\texttt{1}}; + + \draw (-0.5, 0.25) -- (5.5, 0.25); + \draw (-0.5, -0.25) -- (5.5, -0.25); + \draw (-0.5, -0.75) -- (5.5, -0.75); + + \draw (-0.5, 0.25) -- (-0.5, -0.75); + \draw (3.5, 0.25) -- (3.5, -0.75); + \draw (5.5, 0.25) -- (5.5, -0.75); + + \node at (1.5, -0.5) {number of copies}; + \node at (4.5, -0.5) {symbol}; + \end{tikzpicture} +\end{center} +So, the sequence \texttt{BBB} will be encoded as \texttt{[0011-01]}. \par +\note[Notation]{ + Just like dots, dashes and spaces are added for readability. Pretend they don't exist. \par + Encoded binary sequences will always be written in square brackets. \texttt{[]}. +} + +\problem{} +Decode \texttt{[010000001111]} using this scheme. + +\begin{solution} + \texttt{AAAADDD} +\end{solution} +\vfill + +\problem{} +Encode \texttt{AAAA$\cdot$AAAA$\cdot$BCD$\cdot$AAAA$\cdot$AAAA} using this scheme. \par +Is this more or less efficient than \ref{runlenone}? + +\begin{solution} + \texttt{[1000-00 0001-01 0001-10 0001-11 1000-00]} \par + This requires 30 bits, as compared to 38 in \ref{runlenone}. +\end{solution} + +\vfill +\pagebreak + + + + + + +\problem{} +Give an example of a message on $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$ +that uses $n$ bits when encoded with a na\"ive scheme, and \textit{fewer} than $\nicefrac{n}{2}$ bits +when encoded using the scheme described on the previous page. + + +\vfill + +\problem{} +Give an example of a message on $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}\}$ +that uses $n$ bits when encoded with a na\"ive scheme, and \textit{more} than $2n$ bits +when encoded using the scheme described on the previous page. + + +\vfill + + +\problem{} +Is run-length coding always more efficient than na\"ive coding? \par +When does it work well, and when does it fail? + +\vfill + + +\problem{} +Our coding scheme wastes a lot of space when our string has few runs of the same symbol. \par +Fix this problem: modify the scheme so that single occurrences of symbols do not waste space. \par +\hint{We don't need a run length for every symbol. We only need one for \textit{repeated} symbols.} + +\begin{solution} + One idea is as follows: \par + \begin{itemize} + \item Encode single symbols na\"ively: \texttt{ABCD} becomes \texttt{[00 01 10 11]} + \item Signal runs using two copies of the same symbol: \texttt{AAAAAA} becomes \texttt{[00 00 0110]}. \par + When our decoder sees two copies of the same symbol, it will interpret the next four bits as + a run length. + \end{itemize} + \texttt{BDC$\cdot$DDDDD$\cdot$AADBDC} will be encoded as \texttt{[01 11 10 11-11-0101 01-01-0010 11 01 11 10]}. +\end{solution} + +\vfill + +\problem{} +Consider the following string: \texttt{ABCD$\cdot$ABCD$\cdot$BABABA$\cdot$ABCD$\cdot$ABCD}. \par +\begin{itemize} + \item How many bits do we need to encode this na\"ively? \par + \item How about with the (unmodified) run-length scheme described on the previous page? +\end{itemize} +\hint{You don't need to encode this string---just find the length of its encoded form.} + +\begin{solution} + Na\"ively: \tab 22 bits \par + Run-length: \tab $6 \times 21 = 126$ bits. Watch out for the two repeated \texttt{A}s! +\end{solution} + + +\vfill + +Neither solution to \ref{firstlz} is ideal. Run-length is very wasteful due to the lack of runs, and na\"ive coding +does not take advantage of repetition in the string. We'll need a better coding scheme. +\pagebreak diff --git a/src/Advanced/Compression/parts/2 lzss.tex b/src/Advanced/Compression/parts/2 lzss.tex new file mode 100644 index 0000000..8ecae87 --- /dev/null +++ b/src/Advanced/Compression/parts/2 lzss.tex @@ -0,0 +1,174 @@ +\section{LZ Codes} + +The LZ-family\footnotemark{} of codes (LZ77, LZ78, LZSS, LZMA, and others) take advantage of repeated subsequences +in a string. They are the basis of most modern compression algorithms, including DEFLATE, which is used in the ZIP, PNG, +and GZIP formats. + +\footnotetext{ + Named after Abraham Lempel and Jacob Ziv, the original inventors. \par + LZ77 is the algorithm described in their first paper on the topic, which was published in 1977. \par + LZ78, LZSS, and LZMA are minor variations on the same general idea. +} + +\vspace{2mm} + +The idea behind LZ is to represent repeated substrings as \textit{pointers} to previous parts of the string. \par +Pointers take the form \texttt{}, where \texttt{pos} is the position of the string to repeat and +\texttt{len} is the number of symbols to copy. + +\vspace{2mm} + +For example, we can encode the string \texttt{ABRACADABRA} as \texttt{[ABRACAD<7, 4>]}. \par +The pointer \texttt{<7, 4>} tells us to look back 7 positions (to the first \texttt{A}), and copy the next 4 symbols. \par +Note that pointers refer to the partially decoded output---\textit{not} to the encoded string. \par +This allows pointers to reference other pointers, and ensures that codes like \texttt{A<1,9>} are valid. \par +\note{For example, \texttt{[B<1,2>]} decodes to \texttt{BBB}.} + +\problem{} +Encode \texttt{ABCD$\cdot$ABCD$\cdot$BABABA$\cdot$ABCD$\cdot$ABCD} using this scheme. \par +Then, decode the following: +\begin{itemize} + \item \texttt{[ABCD<4,4>]} + \item \texttt{[A<1,9>]} + \item \texttt{[DAC<3,5>]} +\end{itemize} + +\begin{solution} + + % spell:off + \texttt{ABCD$\cdot$ABCD$\cdot$BABABA$\cdot$ABCD$\cdot$ABCD} becomes \texttt{[ABCD<4, 4> BA<2,4> ABCD<4,4>]}. + % spell:on + + \linehack{} + + In parts two and three, remember that we're reading the \textit{output string.} \par + The ten \texttt{A}s in part two are produced one by one, \par + with the decoder's \say{read head} following its \say{write head.} + + \begin{itemize} + \item \texttt{ABCD$\cdot$ABCD} + \item \texttt{AAAAA$\cdot$AAAAA} + \item \texttt{DACDACDA} + \end{itemize} +\end{solution} + +\vfill + +\problem{} +Convince yourself that LZ is a generalization of the run-length code we discussed in the previous section. +\hint{\texttt{[A<1,9>]} and \texttt{[00-1001]} are the same thing!} + +\remark{} +Note that we left a few things out of this section: we didn't discuss the algorithm that converts a string to an LZ-encoded blob, +nor did we discuss how we should represent strings encoded with LZ in binary. We skipped these details because they are +problems of implementation---they're the engineer's headache, not the mathematician's. \par + +\pagebreak + +%\begin{instructornote} +% A simple LZ-scheme can work as follows. We encode our string into a sequence of +% nine-bit blocks, drawn below. The first bit of each block tells us whether or not +% this block is a pointer, and the next eight bits contain either a \texttt{pos, len} pair +% (using, say, for bits for each number) or a plain eight-bit symbol code. +% \begin{center} +% \begin{tikzpicture} +% \node[anchor=west,color=gray] at (-2.3, 0) {Bits}; +% \node[anchor=west,color=gray] at (-2.3, -0.5) {Meaning}; +% \draw[color=gray] (-2.3, -0.25) -- (5.5, -0.25); +% \draw[color=gray] (-2.3, 0.15) -- (-2.3, -0.65); +% +% \node at (0, 0) {\texttt{0}}; +% \node at (1, 0) {\texttt{0}}; +% \node at (2, 0) {\texttt{1}}; +% \node at (3, 0) {\texttt{0}}; +% \node at (4, 0) {\texttt{1}}; +% \node at (5, 0) {\texttt{1}}; +% \node at (6, 0) {\texttt{0}}; +% \node at (7, 0) {\texttt{0}}; +% \node at (8, 0) {\texttt{1}}; +% +% \draw (-0.5, 0.25) -- (8.5, 0.25); +% \draw (-0.5, -0.25) -- (8.5, -0.25); +% \draw (-0.5, -0.75) -- (8.5, -0.75); +% +% \draw (-0.5, 0.25) -- (-0.5, -0.75); +% \draw (0.5, 0.25) -- (0.5, -0.75); +% \draw (8.5, 0.25) -- (8.5, -0.75); +% +% \node at (0, -0.5) {flag}; +% \node at (4.5, -0.5) {if flag \texttt{}, else eight-bit symbol}; +% \end{tikzpicture} +% \end{center} +% +% To encode a string, we read it using a \say{window}, shown below. This window consists of +% a search buffer and a lookahead buffer, both of which have a fixed (but configurable) size. +% This window passes over the string one character at a time, inserting a pointer if it finds +% the lookahead buffer inside its search buffer, and a plain character otherwise. +% +% +% \begin{center} +% \begin{tikzpicture} +% % Text tape +% \node[color=gray] at (-0.75, 0) {\texttt{...}}; +% \node[color=gray] at (0.0, 0) {\texttt{D}}; +% \node at (0.5, 0) {\texttt{A}}; +% \node at (1.0, 0) {\texttt{B}}; +% \node at (1.5, 0) {\texttt{C}}; +% \node at (2.0, 0) {\texttt{D}}; +% \node at (2.5, 0) {\texttt{A}}; +% \node at (3.0, 0) {\texttt{B}}; +% \node at (3.5, 0) {\texttt{C}}; +% \node at (4.0, 0) {\texttt{D}}; +% \node[color=gray] at (4.5, 0) {\texttt{B}}; +% \node[color=gray] at (5.0, 0) {\texttt{D}}; +% \node[color=gray] at (5.5, 0) {\texttt{A}}; +% \node[color=gray] at (6.0, 0) {\texttt{C}}; +% \node[color=gray] at (6.75, 0) {\texttt{...}}; +% +% \draw (-1.75, 0.25) -- (7.25, 0.25); +% \draw (-1.75, -0.25) -- (7.25, -0.25); +% +% +% \draw[line width = 0.7mm, color=oblue, dotted] (2.25, 0.5) -- (2.25, -0.5); +% \draw[line width = 0.7mm, color=oblue] +% (-1.25, 0.5) +% -- (4.25, 0.5) +% -- (4.25, -0.5) +% -- (-1.25, -0.5) +% -- cycle +% ; +% +% \draw +% (4.2, -0.625) +% -- (4.2, -0.75) +% to node[anchor=north, midway] {lookahead} (2.3, -0.75) +% -- (2.3, -0.625) +% ; +% +% \draw +% (2.2, -0.625) +% -- (2.2, -0.75) +% to node[anchor=north, midway] {search buffer} (-1.1, -0.75) +% -- (-1.1, -0.625) +% ; +% +% \draw[color=gray] +% (2.2, 0.625) +% -- (2.2, 0.75) +% to node[anchor=south, midway] {match!} (0.3, 0.75) +% -- (0.3, 0.625) +% ; +% +% %\draw[->, color=gray] (2.5, 0.3) -- (2.5, 0.8) to[out=90,in=90] (0.5, 0.8); +% \node at (7.0, -0.75) {Result: \texttt{[$\cdot\cdot\cdot$DABCD<4,4>$\cdot\cdot\cdot$]}}; +% \end{tikzpicture} +% \end{center} +% +% This is not the exact process used in practice---but it's close enough. \par +% This process may be tweaked in any number of ways. +%\end{instructornote} +% +%\makeatletter\if@solutions +% \vfill +% \pagebreak +%\fi\makeatother \ No newline at end of file diff --git a/src/Advanced/Compression/parts/3 huffman.tex b/src/Advanced/Compression/parts/3 huffman.tex new file mode 100644 index 0000000..3fab653 --- /dev/null +++ b/src/Advanced/Compression/parts/3 huffman.tex @@ -0,0 +1,424 @@ +\section{Huffman Codes} + + +\example{} +Now consider the alphabet $\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}, \texttt{E}\}$. \par +With the na\"ive coding scheme, we can encode a length $n$ string with $3n$ bits, by mapping... +\begin{itemize} + \item $\texttt{A}$ to $\texttt{000}$ + \item $\texttt{B}$ to $\texttt{001}$ + \item $\texttt{C}$ to $\texttt{010}$ + \item $\texttt{D}$ to $\texttt{011}$ + \item $\texttt{E}$ to $\texttt{100}$ +\end{itemize} +For example, this encodes \texttt{ADEBCE} as \texttt{[000 011 100 001 010 100]}. \par +It is easy to see that this scheme uses an average of three bits per symbol. + +\vspace{2mm} + +However, one could argue that this coding scheme is wasteful: \par +we're not using three of the eight possible three-bit sequences! + +\example{} +There is, of course, a better way. \par +Consider the following mapping: + +\begin{itemize} + \item $\texttt{A}$ to $\texttt{00}$ + \item $\texttt{B}$ to $\texttt{01}$ + \item $\texttt{C}$ to $\texttt{10}$ + \item $\texttt{D}$ to $\texttt{110}$ + \item $\texttt{E}$ to $\texttt{111}$ +\end{itemize} + +\problem{} +\begin{itemize} + \item Using the above code, encode \texttt{ADEBCE}. + \item Then, decode \texttt{[110011001111]}. +\end{itemize} + +\begin{solution} + \texttt{ADEBCE} becomes \texttt{[00 110 111 01 10 111]}, \par + and \texttt{[110 01 10 01 111]} is \texttt{DBCBE}. +\end{solution} + +\vfill + +\problem{} +How many bits does this code need per symbol, on average? + +\begin{solution} + \begin{equation*} + \frac{2 + 2 + 2 + 3 + 3}{5} = \frac{12}{5} = 2.4 + \end{equation*} +\end{solution} + +\vfill + +\problem{} +Consider the code below. How is it different from the one on the previous page? \par +Is this a good way to encode five-letter strings? +\begin{itemize} + \item $\texttt{A}$ to $\texttt{00}$ + \item $\texttt{B}$ to $\texttt{01}$ + \item $\texttt{C}$ to $\texttt{10}$ + \item $\texttt{D}$ to $\texttt{110}$ + \item $\texttt{E}$ to $\texttt{11}$ +\end{itemize} + +\begin{solution} + No. The code for \texttt{E} occurs inside the code for \texttt{D}, + and we thus can't decode sequences uniquely. For example, we could + decode the fragment \texttt{[11001$\cdot\cdot\cdot$]} as \texttt{EA} + or as \texttt{DB}. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + +\remark{} +The code from the previous page can be visualized as a full binary tree: \par +\note{Every node in a \textit{full binary tree} has either zero or two children.} + +\vspace{-5mm} +\null\hfill +\begin{minipage}[t]{0.48\textwidth} + \vspace{0pt} + + \begin{itemize} + \item $\texttt{A}$ encodes as $\texttt{00}$ + \item $\texttt{B}$ encodes as $\texttt{01}$ + \item $\texttt{C}$ encodes as $\texttt{10}$ + \item $\texttt{D}$ encodes as $\texttt{110}$ + \item $\texttt{E}$ encodes as $\texttt{111}$ + \end{itemize} +\end{minipage} +\hfill +\begin{minipage}[t]{0.48\textwidth} + \vspace{0pt} + + \begin{center} + \begin{tikzpicture}[scale=1.0] + \begin{scope}[layer = nodes] + \node[int] (x) at (0, 0) {}; + \node[int] (0) at (-0.75, -1) {}; + \node[int] (1) at (0.75, -1) {}; + \node[end] (00) at (-1.25, -2) {\texttt{A}}; + \node[end] (01) at (-0.25, -2) {\texttt{B}}; + \node[end] (10) at (0.25, -2) {\texttt{C}}; + \node[int] (11) at (1.25, -2) {}; + \node[end] (110) at (0.75, -3) {\texttt{D}}; + \node[end] (111) at (1.75, -3) {\texttt{E}}; + \end{scope} + + \draw[-] + (x) to node[edg] {\texttt{0}} (0) + (x) to node[edg] {\texttt{1}} (1) + (0) to node[edg] {\texttt{0}} (00) + (0) to node[edg] {\texttt{1}} (01) + (1) to node[edg] {\texttt{0}} (10) + (1) to node[edg] {\texttt{1}} (11) + (11) to node[edg] {\texttt{0}} (110) + (11) to node[edg] {\texttt{1}} (111) + ; + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill\null +You can think of each symbol's code as it's \say{address} in this tree. +When decoding a string, we start at the topmost node. Reading the binary sequence +bit by bit, we move down the tree, taking a left edge if we see a \texttt{0} +and a right edge if we see a \texttt{1}. +Once we reach a letter, we return to the top node and repeat the process. + + + +\definition{} +We say a coding scheme is \textit{prefix-free} if no whole code word is a prefix of another code word. \par + +\problem{} +Convince yourself that trees like the one above always produce a prefix-free code. + +\problem{} +Decode \texttt{[110111001001110110]} using the tree above. + +\begin{solution} + This is \texttt{[110$\cdot$111$\cdot$00$\cdot$10$\cdot$01$\cdot$110$\cdot$110]}, which is \texttt{DEACBDD} +\end{solution} + +\vfill + +\problem{} +Encode \texttt{ABDECBE} using this tree. \par +How many bits do we save over a na\"ive scheme? + +\begin{solution} + This is \texttt{[00 01 110 111 10 01 111]}, and saves four bits. +\end{solution} + + +\vfill +\pagebreak + +\problem{} +In \ref{treedecode}, we needed 18 bits to encode \texttt{DEACBDD}. \par +\note{Note that we'd need $3 \times 7 = 21$ bits to encode this string na\"ively.} + +\vspace{2mm} +Draw a tree that encodes this string more efficiently. \par + +\begin{solution} + Two possible solutions are below. \par + \begin{itemize} + \item The left tree encodes \texttt{DEACBDD} as \texttt{[00$\cdot$111$\cdot$110$\cdot$10$\cdot$01$\cdot$00$\cdot$00]}, using 16 bits. + \item The right tree encodes \texttt{DEACBDD} as \texttt{[0$\cdot$111$\cdot$101$\cdot$110$\cdot$100$\cdot$0$\cdot$0]}, using 15 bits. + \end{itemize} + + \null\hfill + \begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=1.0] + \begin{scope}[layer = nodes] + \node[int] (x) at (0, 0) {}; + \node[int] (0) at (-0.75, -1) {}; + \node[int] (1) at (0.75, -1) {}; + \node[end] (00) at (-1.25, -2) {\texttt{D}}; + \node[end] (01) at (-0.25, -2) {\texttt{B}}; + \node[end] (10) at (0.25, -2) {\texttt{C}}; + \node[int] (11) at (1.25, -2) {}; + \node[end] (110) at (0.75, -3) {\texttt{A}}; + \node[end] (111) at (1.75, -3) {\texttt{E}}; + \end{scope} + + \draw[-] + (x) to node[edg] {\texttt{0}} (0) + (x) to node[edg] {\texttt{1}} (1) + (0) to node[edg] {\texttt{0}} (00) + (0) to node[edg] {\texttt{1}} (01) + (1) to node[edg] {\texttt{0}} (10) + (1) to node[edg] {\texttt{1}} (11) + (11) to node[edg] {\texttt{0}} (110) + (11) to node[edg] {\texttt{1}} (111) + ; + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill + \begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=1.0] + \begin{scope}[layer = nodes] + \node[int] (x) at (0, 0) {}; + \node[int] (0) at (-0.75, -1) {\texttt{D}}; + \node[int] (1) at (0.75, -1) {}; + \node[end] (10) at (0.25, -2) {}; + \node[int] (11) at (1.25, -2) {}; + \node[end] (100) at (-0.15, -3) {\texttt{A}}; + \node[end] (101) at (0.6, -3) {\texttt{B}}; + \node[end] (110) at (0.9, -3) {\texttt{C}}; + \node[end] (111) at (1.6, -3) {\texttt{E}}; + \end{scope} + + \draw[-] + (x) to node[edg] {\texttt{0}} (0) + (x) to node[edg] {\texttt{1}} (1) + (1) to node[edg] {\texttt{0}} (10) + (1) to node[edg] {\texttt{1}} (11) + (10) to node[edg] {\texttt{0}} (101) + (10) to node[edg] {\texttt{1}} (100) + (11) to node[edg] {\texttt{0}} (110) + (11) to node[edg] {\texttt{1}} (111) + ; + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill\null +\end{solution} + +\vfill + +\problem{} +Now, do the opposite: draw a tree that encodes \texttt{DEACBDD} \textit{less} efficiently than before. + +\begin{solution} + Bury \texttt{D} as deep as possible in the tree, so that we need four bits to encode it. +\end{solution} + +\vfill + +\remark{} +As we just saw, constructing a prefix-free code is fairly easy. \par +Constructing the \textit{most efficient} prefix-free code for a +given message is a bit more difficult. \par +\pagebreak + + + + + + + + + + +\remark{} +Let's restate our problem. \par +Given an alphabet $A$ and a frequency function $f$, we want to construct a binary tree $T$ that minimizes + +\begin{equation*} + \mathcal{B}_f(T) = \sum_{a \in A} f(a) \times d_T(a) +\end{equation*} + +Where... +\begin{itemize}[itemsep=1mm] + \item $a$ is a symbol in $A$ + + \item $d_T(a)$ is the \say{depth} of $a$ in our tree. \par + \note{In other words, $d_T(a)$ is the number of bits we need to encode $a$} + + \item $f(a)$ is a frequency function that maps each symbol in $A$ to a value in $[0, 1]$. \par + You can think of this as the distribution of symbols in messages we expect to encode. \par + For example, consider the alphabet $\{\texttt{A}, \texttt{B}, \texttt{C}\}$: + \begin{itemize} + \item In $\texttt{AAA}$, $f(\texttt{A}) = 1$ and $f(\texttt{B}) = f(\texttt{C}) = 0$. + \item In $\texttt{ABC}$, $f(\texttt{A}) = f(\texttt{B}) = f(\texttt{C}) = \nicefrac{1}{3}$. + \end{itemize} + \note{Note that $f(a) \geq 0$ and $\sum f(a) = 1$.} +\end{itemize} + +\vspace{2mm} + +Also notice that $\mathcal{B}_f(T)$ is the \say{average bits per symbol} metric we saw in previous problems. + + +\problem{} +Let $f$ be fixed frequency function over an alphabet $A$. \par +Let $T$ be an arbitrary tree for $A$, and let $a, b$ be two symbols in $A$. \par +Construct $T'$ by swapping $a$ and $b$ in $T$. Show that \par +\begin{equation*} + \mathcal{B}_f(T) - \mathcal{B}_f(T') = \Bigl(f(b) - f(a)\Bigr) \times \Bigl(d_T(a) - d_T(b)\Bigr) +\end{equation*} + +\begin{solution} + $\mathcal{B}_f(T)$ and $\mathcal{B}_f(T')$ are nearly identical, and differ only at $d_T(a)$ and $d_T(b)$. + So, we get... + + \begin{align*} + \mathcal{B}_f(T) - \mathcal{B}_f(T') + &= f(a)d_T(a) + f(b)d_T(b) - f(a)d_T(b) - f(b)d_T(a) \\ + &= f(a)\bigl(d_T(a) - d_T(b)\bigr) + f(b)\bigl(d_T(b) - d_T(a)\bigr) \\ + &= \Bigl(f(b) - f(a)\Bigr) \times \Bigl(d_T(a) - d_T(b)\Bigr) + \end{align*} +\end{solution} + +\vfill +\pagebreak + +\problem{} +Show that there is an optimal tree in which the two symbols with the lowest frequencies have the same parent. +\hint{You may assume that an optimal tree exists. There are a few cases.} + +\begin{solution} + Let $T$ be an optimal tree, and let $a, b$ be the two symbols with the lowest frequency. \par + If there is a tie among three or more symbols, pick $a, b$ to be those with the greatest depth. \par + Label $a$ and $b$ so that that $d_T(a) \geq d_T(a)$. + + \vspace{1mm} + + If $a$ and $b$ share a parent, we're done. + If $a$ and $b$ do not share a parent, we have three cases: + \begin{itemize}[itemsep=1mm] + \item There is a node $x$ with $d_T(x) > d_T(a)$. \par + Create $T'$ by swapping $a$ and $x$. By definition, $f(a) < f(x)$, and thus + by \ref{hufptone} $\mathcal{B}_f(T) > \mathcal{B}_f(T')$. This is a contradiction, + since we chose $T$ as an optimal tree---so this case is impossible. + + \item $a$ is an only child. Create $T'$ by removing $a$'s parent and replacing it with $a$. \par + Then $\mathcal{B}_f(T) > \mathcal{B}_f(T')$, same contradiction as above. \par + \note{If we assume $T$ is a full binary tree, this case doesn't exist.} + + \item $a$ has a sibling $x$, and $x$ isn't $b$. \par + Let $T'$ be the tree created by swapping $x$ and $b$ (thus making $a$ and $b$ siblings). \par + By \ref{hufptone}, $\mathcal{B}_f(T) \geq \mathcal{B}_f(T')$. $T$ is optimal, so there cannot + be a tree with a better average length---thus $\mathcal{B}_f(T) = \mathcal{B}_f(T')$ and $T'$ + is also optimal. + \end{itemize} +\end{solution} + +\vfill +\pagebreak + +\problem{} +Devise an algorithm that builds an optimal tree given an alphabet $A$ and a frequency function $f$. \par +Then, use the previous two problems to show that your algorithm indeed produces an ideal tree. \par +\hint{ + First, make an algorithm that makes sense intuitively. \par + Once you have something that looks good, start your proof. +} \par +\hint{Build from the bottom.} + +\begin{solution} + \textbf{The Algorithm:} \par + Given an alphabet $A$ and a frequency function $f$... + \begin{itemize} + \item If $|A| = 1$, return a single node. + \item Let $a, b$ be two symbols with the smallest frequency. + \item Let $A' = A - \{a, b\} + \{x\}$ \tab \note{(Where $x$ is a new \say{placeholder} symbol)} + \item Let $f'(x) = f(a) + f(b)$, and $f'(s) = f(s)$ for all other symbols $s$. + \item Compute $T'$ by repeating this algorithm on $A'$ and $f'$ + \item Create $T$ from $T'$ by adding $a$ and $b$ as children of $x$. + \end{itemize} + + \vspace{2mm} + In plain english: pick the two nodes with the smallest frequency, combine them, + and replace them with a \say{compound symbol}. Repeat until you're done. + + + \linehack{} + \textbf{The Proof:} \par + We'll proceed by induction on $|A|$. \par + Let $f$ be an arbitrary frequency function. + + \vspace{4mm} + + \textbf{Base case:} $|A| = 1$. We only have one vertex, and we thus only have one tree. \par + The algorithm above produces this tree. Done. + + \vspace{4mm} + + \textbf{Induction:} Assume that for all $A$ with $|A| = n - 1$, the algorithm above produces an ideal tree. + First, we'll show that $\mathcal{B}_f(T) = \mathcal{B}_{f'}(T') + f(a) + f(b)$: + \begin{align*} + \mathcal{B}_f(T) + &= \sum_{x \in A - \{a, b\}} \Bigl(f(x)d_T(x)\Bigr) + f(a)d_T(a) + f(b)d_T(b) \\ + &= \sum_{x \in A - \{a, b\}} \Bigl(f(x)d_T(x)\Bigr) + \Bigl(f(a)+f(b)\Bigr)\Bigl(d_{T'}(x) + 1\Bigr) \\ + &= \sum_{x \in A - \{a, b\}} \Bigl(f(x)d_T(x)\Bigr) + f'(z)d_{T'}(z) + f(a) + f(b) \\ + &= \sum_{x \in A'} \Bigl(f'(x)d_{T'}(x)\Bigr) + f(a) + f(b) \\ + &= \mathcal{B}_{f'}(T') + f(a) + f(b) + \end{align*} + + Now, assume that $T$ is not optimal. There then exists an optimal tree $U$ with $a$ and $b$ as siblings (by \ref{hufpttwo}). + Let $U'$ be the tree created by removing $a, b$ from $U$. $U'$ is a tree for $A'$ and $f'$, so we can repeat the calculation + above to find that $\mathcal{B}_f(U) = \mathcal{B}_{f'}(U') + f(a) + f(b)$. + + \vspace{2mm} + + So, $ + \mathcal{B}_{f'}(T') + ~=~ \mathcal{B}_f(T) - f(a) - f(b) + ~>~ \mathcal{B}_f(U) - f(a) - f(b) + ~=~ \mathcal{B}_{f'}(U') + $. \par + Since $T'$ is optimal for $A'$ and $f'$, this is a contradition. $T$ must therefore be optimal. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Compression/parts/4 bonus.tex b/src/Advanced/Compression/parts/4 bonus.tex new file mode 100644 index 0000000..415fd7c --- /dev/null +++ b/src/Advanced/Compression/parts/4 bonus.tex @@ -0,0 +1,40 @@ +\section{Bonus problems} + + +\problem{} +Make sense of the document on the next page. \par +What does it describe, and how does it work? + + +\problem{} +Given a table with a marked point, $O$, and with $2013$ properly working watches put down on the table, prove that there exists a moment in time when the sum of the distances from $O$ to the watches' centers is less than the sum of the distances from $O$ to the tips of the watches' minute hands. + +\vfill + + +\problem{A Minor Inconvenience} +A group of eight friends goes out to dinner. Each drives his own car, checking it in with valet upon arrival. +Unfortunately, the valet attendant forgot to tag the friends' keys. Thus, when the group leaves the restaurant, +each friend is handed a random key. +\begin{itemize} + \item What is the probability that everyone gets the correct set of keys? + \item What is the probability that each friend gets the wrong set? +\end{itemize} + +\vfill + + +\problem{Bimmer Parking} +A parking lot has a row of 16 spaces, of which a random 12 are taken. \par +Ivan drives a BMW, and thus needs two adjacent spaces to park. \par +What is the probability he'll find a spot? + +\vfill +\pagebreak + +\includepdf[ + pages=1, + fitpaper=true +]{parts/qoi-specification.pdf} + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Compression/parts/qoi-specification.pdf b/src/Advanced/Compression/parts/qoi-specification.pdf new file mode 100644 index 0000000..3ffa4bd Binary files /dev/null and b/src/Advanced/Compression/parts/qoi-specification.pdf differ diff --git a/src/Advanced/Compression/tikzset.tex b/src/Advanced/Compression/tikzset.tex new file mode 100644 index 0000000..b2aa528 --- /dev/null +++ b/src/Advanced/Compression/tikzset.tex @@ -0,0 +1,68 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweak + >={Latex[ width=2mm, length=2mm ]}, + % + % Labels inside edges + label/.style = { + rectangle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none, + rounded corners = 0mm + }, + % + % Nodes + edg/.style = { + midway, + fill = \ORMCbgcolor, + text = gray + }, + int/.style = {}, + end/.style = { + anchor=north + }, + % + % Loop tweaks + loop above/.style = { + min distance = 2mm, + looseness = 8, + out = 45, + in = 135 + }, + loop below/.style = { + min distance = 5mm, + looseness = 10, + out = 315, + in = 225 + }, + loop right/.style = { + min distance = 5mm, + looseness = 10, + out = 45, + in = 315 + }, + loop left/.style = { + min distance = 5mm, + looseness = 10, + out = 135, + in = 215 + } +} \ No newline at end of file diff --git a/src/Advanced/Continued Fractions/main.tex b/src/Advanced/Continued Fractions/main.tex new file mode 100755 index 0000000..2002cd1 --- /dev/null +++ b/src/Advanced/Continued Fractions/main.tex @@ -0,0 +1,29 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + shortwarning, + singlenumbering, + unfinished +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{multicol} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Continued Fractions} +\subtitle{ + Prepared by Mark on \today \\ + Based on a handout by Matthew Gherman and Adam Lott +} + +\begin{document} + + \maketitle + + \input{parts/00 euclidean} + \input{parts/01 part A} + \input{parts/02 part B} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Continued Fractions/meta.toml b/src/Advanced/Continued Fractions/meta.toml new file mode 100644 index 0000000..e6960ee --- /dev/null +++ b/src/Advanced/Continued Fractions/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Continued Fractions" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Continued Fractions/parts/00 euclidean.tex b/src/Advanced/Continued Fractions/parts/00 euclidean.tex new file mode 100755 index 0000000..da044f8 --- /dev/null +++ b/src/Advanced/Continued Fractions/parts/00 euclidean.tex @@ -0,0 +1,65 @@ +\section{The Euclidean Algorithm} + +\definition{} +The \textit{greatest common divisor} of $a$ and $b$ is the greatest integer that divides both $a$ and $b$. \par +We denote this number with $\gcd(a, b)$. For example, $\gcd(45, 60) = 15$. + +\problem{} +Find $\gcd(20, 14)$ by hand. + +\begin{solution} + $\gcd(20, 14) = 2$ +\end{solution} + +\vfill + +\theorem{The Division Algorithm} +Given two integers $a, b$, we can find two integers $q, r$, where $0 \leq r < b$ and $a = qb + r$. \par +In other words, we can divide $a$ by $b$ to get $q$ remainder $r$. + +\vspace{2mm} + +For example, take $14 \div 3$. We can re-write this as $3 \times 4 + 2$. \par +Here, $a$ and $b$ are $14$ and $3$, $q = 4$ and $r = 2$. + +\theorem{} +For any integers $a, b, c$, \par +$\gcd(ac + b, a) = \gcd(a, b)$ + + +\problem{} +Compute $\gcd(668, 6)$. \hint{$668 = 111 \times 6 + 2$} +Then, compute $\gcd(3 \times 668 + 6, 668)$. + +\vfill + +\problem{The Euclidean Algorithm} +Using the two theorems above, detail an algorithm for finding $\gcd(a, b)$. \par +Then, compute $\gcd(1610, 207)$ by hand. \par + +\begin{solution} + Using \ref{gcd_abc} and the division algorithm, + + % Minipage prevents column breaks inside body + \begin{multicols}{2} + \begin{minipage}{\columnwidth} + $\gcd(1610, 207)$ \par + $= \gcd(207, 161)$ \par + $= \gcd(161, 46)$ \par + $= \gcd(46, 23)$ \par + $= \gcd(23, 0) = 23$ \par + \end{minipage} + + \columnbreak + + \begin{minipage}{\columnwidth} + $1610 = 207 \times 7 + 161$ \par + $207 = 161 \times 1 + 46$ \par + $161 = 46 \times 3 + 23$ \par + $46 = 23 \times 2 + 0$ \par + \end{minipage} + \end{multicols} +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Continued Fractions/parts/01 part A.tex b/src/Advanced/Continued Fractions/parts/01 part A.tex new file mode 100644 index 0000000..9843452 --- /dev/null +++ b/src/Advanced/Continued Fractions/parts/01 part A.tex @@ -0,0 +1,194 @@ +\section{} + + + +\definition{} +A \textit{finite continued fraction} is an expression of the form +\[ +a_0 + \cfrac{1}{a_1+\cfrac{1}{a_2 + \cfrac{1}{a_3 + ... + \cfrac{1}{a_{k-1} + \cfrac{1}{a_k}}}}} +\] +where $a_0, a_1, ..., a_k$ are all in $\mathbb{Z}^+_0$. +We'll denote this as $[a_0, a_1, ..., a_k]$. + + + + + +\problem{} +Write each of the following as a continued fraction. \par +\hint{Solve for one $a_n$ at a time.} +\begin{itemize} + \item $5/12$ + \item $5/3$ + \item $33/23$ + \item $37/31$ +\end{itemize} + + +\vfill + + +\problem{} +Write each of the following continued fractions as a regular fraction in lowest terms: \par +\begin{itemize} + \item $[2,3,2]$ + \item $[1,4,6,4]$ + \item $[2,3,2,3]$ + \item $[9,12,21,2]$ +\end{itemize} + + +\vfill +\pagebreak + +\problem{} +Let $\frac{p}{q}$ be a positive rational number in lowest terms. +Perform the Euclidean algorithm to obtain the following sequence: +\begin{align*} + p \ &= \ q_0 q + r_1 \\ + q \ &= \ q_1 r_1 + r_2 \\ + r_1 \ &= \ q_2 r_2 + r_3 \\ + &\vdots \\ + r_{k-1} \ &= \ q_k r_k + 1 \\ + r_k \ &= \ q_{k+1} +\end{align*} +We know that we will eventually get $1$ as the remainder because $p$ and $q$ are relatively prime. \par +Show that $p/q = [q_0, q_1, ..., q_{k+1}]$. + + +\vfill + + +\problem{} +Repeat \ref{num2cf} using the method outlined in \ref{euclid}. + + +\vfill +\pagebreak + + + + + + + +\definition{} +An \textit{infinite continued fraction} is an expression of the form +\[ +a_0 + \cfrac{1}{a_1+\cfrac{1}{a_2 + \cfrac{1}{a_3 + \cfrac{1}{a_4 + ...}}}} +\] +where $a_0, a_1, a_2, ...$ are in $\mathbb{Z}^+_0$. +To prove that this expression actually makes sense and equals a finite number +is beyond the scope of this worksheet, so we assume it for now. +This is denoted $[a_0, a_1, a_2, ...]$. + + + + + + +\problem{} +Using a calculator, compute the first five terms of the +continued fraction expansion of the following numbers. +Do you see any patterns? + +\begin{itemize} + \item $\sqrt{2}$ + \item $\pi \approx 3.14159...$ + \item $\sqrt{5}$ + \item $e \approx 2.71828...$ +\end{itemize} + + +\vfill + + + + +\problem{} +Show that an $\alpha \in \mathbb{R}^+$ can be written as a finite +continued fraction if and only if $\alpha$ is rational. \par +\hint{For one of the directions, use \ref{euclid}} + + + +\vfill +\pagebreak + + +\definition{} +The continued fraction $[a_0, a_1, a_2, ...]$ is \textit{periodic} if it ends in a repeating sequence of digits. \par +A few examples are below. We denote the repeating sequence with a line. +\begin{itemize} + \item $[1,2,2,2,...] = [1, \overline{2}]$ is periodic. + \item $[1,2,3,4,5,...]$ is not periodic. + \item $[1,3,7,6,4,3,4,3,4,3,...] = [1,3,7,6,\overline{4,3}]$ is periodic. + \item $[1,2,4,8,16, ...]$ is not periodic. +\end{itemize} + + + + + +\problem{} +\begin{itemize} + \item Show that $\sqrt{2} = [1, \overline{2}]$. + \item Show that $\sqrt{5} = [1, \overline{4}]$. +\end{itemize} +\hint{use the same strategy as \ref{irrational} but without a calculator.} + + +\vfill + + + +\problem{Challenge I} +Express the following continued fractions in the form $\frac{a+\sqrt{b}}{c}$ where $a$, $b$, and $c$ are integers: \par +\begin{itemize} + \item $[~\overline{1}~]$ + \item $[~\overline{2,5}~]$ + \item $[~1, 3, \overline{2,3}~]$ +\end{itemize} + + + +\vfill + + + + +\problem{Challenge II} +Let $\alpha = [~a_0,~ ...,~ a_r,~ \overline{a_{r+1},~ ...,~ a_{r+p}}~]$ be any periodic continued fraction. \par +Prove that $\alpha$ is of the form $\frac{a+\sqrt{b}}{c}$ for some integers $a,b,c$ where $b$ is not a perfect square. + + + +\vfill + + + +\problem{Challenge III} +Prove that any number of the form $\frac{a+\sqrt{b}}{c}$ where $a,b,c$ are integers +and $b$ is not a perfect square can be written as a periodic continued fraction. + + + +%\begin{rmk} +%Numbers of the form $\frac{a+\sqrt{b}}{c}$ where $a,b,c$ are integers and $b$ is not a perfect square are the ``simplest'' irrational numbers in the following sense. A number is rational if and only if it is the solution to a degree $1$ polynomial equation, $ax+b = 0$. Similarly, a number is of the form $\frac{a+\sqrt{b}}{c}$ if it is the solution to a degree $2$ polynomial equation, $ax^2 + bx + c = 0$ (Bonus exercise: prove this). Such numbers are called \textit{quadratic} irrational numbers or \textit{degree 2} irrational numbers. +%\end{rmk} + + + + + +%\begin{rmk} +%Notice that the results of this worksheet provide a very clean characterization of continued fraction expansions: +%\begin{itemize} +%\item $\alpha$ is a rational number if and only if it has a finite continued fraction expansion. +%\item $\alpha$ is a degree $2$ irrational number if and only if it has an infinite periodic continued fraction expansion. +%\end{itemize} +%\end{rmk} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Continued Fractions/parts/02 part B.tex b/src/Advanced/Continued Fractions/parts/02 part B.tex new file mode 100644 index 0000000..f492086 --- /dev/null +++ b/src/Advanced/Continued Fractions/parts/02 part B.tex @@ -0,0 +1,262 @@ +\section{Convergents} + + +\definition{} +Let $\alpha = [a_0, a_1, a_2, ...]$ be an infinite continued fraction (aka an irrational number). \par +The \emph{$n$th convergent to $\alpha$} is the rational number $[a_0, a_1, ..., a_n]$ and is denoted $C_n(\alpha)$. + +\problem{} +Calculate the following convergents and write them in lowest terms: \\ +\begin{itemize} + \item $C_3([~ 1,2,3,4, ... ~])$ + \item $C_4([~ 0,\overline{2,3} ~])$ + \item $C_5([~ \overline{1,5} ~])$ +\end{itemize} + +\vfill + + + + + + +\problem{} +Recall from last week that $\sqrt{5} = [2,\overline{4}]$. +Calculate the first five convergents to $\sqrt{5}$ and write them in lowest terms. +Do you notice any patterns? \par +\hint{Look at the numbers $\sqrt{5}-C_j(\sqrt{5})$ for $1 \leq j \leq 5$} + + +\vfill + + + + + + +\generic{Properties of Convergents} +In this section, we want to show that the $n$th convergent to a real number +$\alpha$ is the best approximation of $\alpha$ with the given denominator. +Let $\alpha = [a_0, a_1, ...]$ be fixed, and we will write $C_n$ instead of +$C_n(\alpha)$ for short. Let $p_n / q_n$ be the expression of $C_n$ as a rational number +in lowest terms. We will eventually prove that $|\alpha-C_n|<\frac{1}{q_n^2}$, +and there is no better rational estimate of $\alpha$ with denominator less than or equal to $q_n$. + +First we want the recursive formulas $p_n=a_np_{n-1}+p_{n-2}$ and $q_n=a_nq_{n-1}+q_{n-2}$ given $p_{-1}=1$, $p_0=a_0$, $q_{-1}=0$, and $q_0=1$. + + +\pagebreak + + + + +\problem{} +Verify the recursive formula for $1\leq j\leq 3$ for the convergents $C_j$ of: \par +\begin{itemize} + \item $[~ 1,2,3,4, ... ~]$ + \item $[~ 0,\overline{2,3} ~]$ + \item $[~ \overline{1,5} ~]$ +\end{itemize} + + +\vfill + + + + +\problem{Challenge IV} +Prove that $p_n = a_np_{n-1} + p_{n-2}$ and $q_n = a_nq_{n-1} + q_{n-2}$ by induction. +\begin{itemize} + \item As the base case, verify the recursive formulas for $n=1$ and $n=2$. + \item Assume the recursive formulas hold for $n\leq m$ and show the formulas hold for $m+1$. +\end{itemize} + + + +\vfill + + + + + +\problem{} +Using the recursive formula from \ref{rec}, +we will show that $p_n q_{n-1} - p_{n-1}q_n = (-1)^{n-1}$. +\begin{itemize} + \item What is $p_1q_0-p_0q_1$? + \item Substitute $a_np_{n-1}+p_{n-2}$ for $p_n$ and $a_nq_{n-1}+q_{n-2}$ for $q_n$ in $p_n q_{n-1}-p_{n-1}q_n$. Simplify the expression. + \item What happens when $n=2$? Explain why $p_n q_{n-1}-p_{n-1}q_n = (-1)^{n-1}$. +\end{itemize} + + +\vfill + + + + + + + +\problem{Challenge VI} +Similarly derive the formula $p_nq_{n-2}-p_{n-2}q_n = (-1)^{n-2}a_n$. + + + +\vfill +\pagebreak + + + + + + + + +\problem{} +Recall $C_n=p_n/q_n$. +Show that $C_n-C_{n-1}=\frac{(-1)^{n-1}}{q_{n-1}q_n}$ +and $C_n-C_{n-2}=\frac{(-1)^{n-2}a_n}{q_{n-2}q_n}$. \par +\hint{Use \ref{form1} and $p_nq_{n-2}-p_{n-2}q_n = (-1)^{n-2}a_n$ respectively} + +In \ref{sqrt5}, the value $\alpha-C_n$ alternated between negative and positive +and $|\alpha-C_n|$ got smaller each step. Using the relations in \ref{diff}, +we can prove that this is always the case. +Specifically, $\alpha$ is always between $C_n$ and $C_{n+1}$. + + + +\vfill + + + +\problem{} +Let's figure out how well the $n$th convergents estimate $\alpha$. +We will show that $|\alpha-C_n|<\frac{1}{q_n^2}$. +\begin{itemize} + \item Note that $|C_{n+1}-C_n|=\frac{1}{q_nq_{n+1}}$. + \item Why is $|\alpha-C_n|\leq|C_{n+1}-C_n|$? + \item Conclude that $|\alpha-C_n|<\frac{1}{q_n^2}$. +\end{itemize} + +We are now ready to prove a fundamental result in the theory of rational approximation. +\problem{Dirichlet's approximation theorem} +Let $\alpha$ be any irrational number. +Prove that there are infinitely many rational numbers $\frac{p}{q}$ such that $|\alpha - \frac{p}{q}| < \frac{1}{q^2}$. + + + + +\vfill +\pagebreak + + + + + + +\problem{Challenge VII} +Prove that if $\alpha$ is \emph{rational}, then there are only \emph{finitely} many rational numbers $\frac{p}{q}$ +satisfying $|\alpha - \frac{p}{q} | < \frac{1}{q^2}$. + + +The above result shows that the $n$th convergents estimate $\alpha$ extremely well. +Are there better estimates for $\alpha$ if we want small denominators? +In order to answer this question, we introduce the Farey sequence. + + + +\vfill + + + + + + +\definition{} +The \emph{Farey sequence} of order $n$ is the set of rational numbers between +0 and 1 whose denominators (in lowest terms) are $\leq n$, arranged in increasing order. + + +\problem{} +List the Farey sequence of order 4. Now figure out the Farey sequence of order 5 by including the relevant rational numbers in the Farey sequence of order 4. + +\vfill + + + + +\problem{} +Let $\frac{a}{b}$ and $\frac{c}{d}$ be consecutive elements of the Farey sequence of order 5. What does $bc-ad$ equal? + + +\vfill + + + + + +\problem{Challenge VIII} +Prove that $bc-ad=1$ for $\frac{a}{b}$ and $\frac{c}{d}$ consecutive rational numbers in Farey sequence of order $n$. + +\begin{itemize}[itemsep=2mm] + \item In the plane, draw the triangle with vertices (0,0), $(b,a)$, $(d,c)$. + Show that the area $A$ of this triangle is $\frac{1}{2}$ using Pick's Theorem. + Recall that Pick's Theorem states $A=\frac{B}{2}+I-1$ where $B$ is the number of + lattice points on the boundary and $I$ is the number of points in the interior. \par + \hint{B=3 and I=0} + + \item Show that the area of the triangle is also given by $\frac{1}{2}|ad-bc|$. + + \item Why is $bc>ad$? + + \item Conclude that $bc-ad=1$. +\end{itemize} + + + + + + +\vfill +\pagebreak + + + +\problem{} +Use the result of \ref{farey} to show that there is no rational number between +$C_{n-1}$ and $C_n$ with denominator less than or equal to $q_n$. +Conclude that if $a/b$ is any rational number with $b \leq q_n$, then +$|\alpha - \frac ab| \geq |\alpha - \frac{p_n}{q_n}|$ + +%What the above exercise shows is that relative to the size of the denominator, the convergents of the continued fraction expansion of $\a$ are the absolute best rational approximations to $\a$. + + +\vfill + + + + + +\problem{Challenge X} +Prove the following strengthening of Dirichlet's approximation theorem. +If $\alpha$ is irrational, then there are infinitely many rational numbers +$\frac{p}{q}$ satisfying $|\alpha - \frac pq| < \frac{1}{2q^2}$. + +\begin{itemize}[itemsep = 2mm] + + \item Prove that $(x+y)^2 \geq 4xy$ for any real $x,y$. + \item Let $p_n/q_n$ be the $n$th convergent to $\alpha$. Prove that + \[ + \biggl|\frac{p_n}{q_n} - \frac{p_{n+1}}{q_{n+1}}\biggr|^2 \ \geq \ 4 \biggl| \frac{p_n}{q_n} - \alpha \biggr| \biggl| \frac{p_{n+1}}{q_{n+1}} - \alpha \biggr| + \] + \hint{$\alpha$ lies in between $\frac{p_n}{q_n}$ and $\frac{p_{n+1}}{q_{n+1}}$} + + + \item Prove that either $\frac{p_n}{q_n}$ or $\frac{p_{n+1}}{q_{n+1}}$ satisfies the desired inequality (Hint: proof by contradiction). + + \item Conclude that there are infinitely many rational numbers $\frac{p}{q}$ satisfying $|\alpha - \frac pq| < \frac{1}{2q^2}$. +\end{itemize} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Cryptography/main.tex b/src/Advanced/Cryptography/main.tex new file mode 100755 index 0000000..3a59153 --- /dev/null +++ b/src/Advanced/Cryptography/main.tex @@ -0,0 +1,32 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering, + shortwarning +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{multicol} +\usepackage{mathtools} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Intro to Cryptography} +\subtitle{Prepared by Mark on \today{}} + + +\begin{document} + + \maketitle + + \input{parts/0 euclidean} + \input{parts/1 mod} + \input{parts/2 groups} + \input{parts/3 DLP} + \input{parts/4 DiffieHellman} + \input{parts/5 Elgamal} + + \input{parts/challenge} + +\end{document} diff --git a/src/Advanced/Cryptography/meta.toml b/src/Advanced/Cryptography/meta.toml new file mode 100644 index 0000000..659ab7e --- /dev/null +++ b/src/Advanced/Cryptography/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Cryptography" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Cryptography/parts/0 euclidean.tex b/src/Advanced/Cryptography/parts/0 euclidean.tex new file mode 100755 index 0000000..83c3553 --- /dev/null +++ b/src/Advanced/Cryptography/parts/0 euclidean.tex @@ -0,0 +1,139 @@ +\section{The Euclidean Algorithm} + +\definition{} +The \textit{greatest common divisor} of $a$ and $b$ is the greatest integer that divides both $a$ and $b$. \par +We denote this number with $\gcd(a, b)$. For example, $\gcd(45, 60) = 15$. + +\problem{} +Find $\gcd(20, 14)$ by hand. + +\begin{solution} + $\gcd(20, 14) = 2$ +\end{solution} + +\vfill + +\theorem{The Division Algorithm} +Given two integers $a, b$, we can find two integers $q, r$, where $0 \leq r < b$ and $a = qb + r$. \par +In other words, we can divide $a$ by $b$ to get $q$ remainder $r$. + +\theorem{} +For any integers $a, b, c$, \par +$\gcd(ac + b, a) = \gcd(a, b)$ + +\problem{The Euclidean Algorithm} +Using the two theorems above, detail an algorithm for finding $\gcd(a, b)$. \par +Then, compute $\gcd(1610, 207)$ by hand. \par + +\begin{solution} + Using \ref{gcd_abc} and the division algorithm, + + % Minipage prevents column breaks inside body + \begin{multicols}{2} + \begin{minipage}{\columnwidth} + $\gcd(1610, 207)$ \par + $= \gcd(207, 161)$ \par + $= \gcd(161, 46)$ \par + $= \gcd(46, 23)$ \par + $= \gcd(23, 0) = 23$ \par + \end{minipage} + + \columnbreak + + \begin{minipage}{\columnwidth} + $1610 = 207 \times 7 + 161$ \par + $207 = 161 \times 1 + 46$ \par + $161 = 46 \times 3 + 23$ \par + $46 = 23 \times 2 + 0$ \par + \end{minipage} + \end{multicols} +\end{solution} + +\vfill +\pagebreak + + + + +\problem{} +Using the output of the Euclidean algorithm, + +\begin{itemize} + \item[-] find a pair $(u, v)$ that satisfies $20u + 14v = \gcd(20, 14)$ + \item[-] find a pair $(u, v)$ that satisfies $541u + 34v = \gcd(541, 34)$ + % gcd = 1 + % u = 11; v = -175 +\end{itemize} +This is called the \textit{extended Euclidean algorithm}. \par +\hint{ + You don't need to fully solve the last part of this question. \\ + Understand how you \textit{would} do it, then move on. + Don't spend too much time on arithmetic. +} + +%For which numbers $c$ can we find a $(u, v)$ so that $541u + 34v = c$? \\ +%For every such $c$, what are $u$ and $v$? + +\vspace{2mm} + +\textbf{Hint:} + +After running the Euclidean algorithm, you have a table similar to the one shown below. \par +You can use a bit of algebra to rearrange these statements to get what you need. \par + +\vspace{5mm} + +\newdimen\mywidth +\setbox0=\hbox{Using the Euclidean Algorithm to find that $\gcd(20, 14) = 2$:} +\mywidth=\wd0 +\begin{minipage}{\mywidth} + \begin{center} + Using the Euclidean Algorithm to find that $\gcd(20, 14) = 2$: \par + $20 = 14 \times 1 + 6$ \par + $14 = 6 \times 2 + 2$ \par + $6 = 2 \times 3 + 0$ \par + \end{center} +\end{minipage}\par +\vspace{2mm} +We now want to write the 2 in the last equation in terms of 20 and 14. + + + +\begin{solution} + Using the output of the Euclidean Algorithm, we can use substitution and a bit of algebra to solve such problems. Consider the following example: + + \begin{multicols}{2} + \begin{minipage}{\columnwidth} + \textit{Euclidean Algorithm:} \par + $20 = 14 \times 1 + 6$ \par + $14 = 6 \times 2 + 2$ \par + $6 = 2 \times 3 + 0$ \par + \end{minipage} + + \columnbreak + + \begin{minipage}{\columnwidth} + \textit{Rearranged:} \par + $6 = 20 - 14 \times 1$ \par + $2 = 14 - 6 \times 2 = \gcd(20, 14)$ \par + \end{minipage} + \end{multicols} + + Using the right table, we can replace $6$ in $2 = 14 - 6 \times 2$ to get + $2 = 14 - (20 - 14) \times 2$, \par + which gives us $2 = \gcd(20, 14) = (3)14 + (-2)20$. \par + + \linehack{} + + $\gcd(20, 14) = 20(-2) + 14(3)$ \par + $\gcd(541, 34) = 541(11) + 34(-175)$ +\end{solution} + +\begin{solution} + \huge + This problem is too hard. Break it into many. +\end{solution} + +\vfill +\pagebreak + diff --git a/src/Advanced/Cryptography/parts/1 mod.tex b/src/Advanced/Cryptography/parts/1 mod.tex new file mode 100755 index 0000000..b06b662 --- /dev/null +++ b/src/Advanced/Cryptography/parts/1 mod.tex @@ -0,0 +1,91 @@ +\section{Modular Arithmetic} + +\definition{} +$\mathbb{Z}_n$ is the set of integers mod $n$. For example, $\mathbb{Z}_5 = \{0, 1, 2, 3, 4\}$. \par + +\vspace{2mm} + +Multiplication in $\mathbb{Z}_n$ works much like multiplication in $\mathbb{Z}$: \par +If $a, b$ are elements of $\mathbb{Z}_n$, $a \times b$ is the remainder of $a \times b$ when divided by $n$. \par +\note{For example, $2 \times 2 = 4$ and $3 \times 4 = 12 = 2$ in $\mathbb{Z}_5$} + +\problem{} +Create a multiplication table for $\mathbb{Z}_4$: + +\begin{center} +\begin{tabular}{c | c c c c} + $\times$ & 0 & 1 & 2 & 3 \\ + \hline + 0 & ? & ? & ? & ? \\ + 1 & ? & ? & ? & ? \\ + 2 & ? & ? & ? & ? \\ + 3 & ? & ? & ? & ? \\ +\end{tabular} +\end{center} + + + + + +\definition{} +Let $a, b$ be elements of %\mathbb{Z}_n$. \par +If $a \times b = 1$, we say that $b$ is the \textit{inverse} of $a$ in $\mathbb{Z}_n$. + +\vspace{2mm} + +We usually write \say{$a$ inverse} as $a^{-1}$. \par +Inverses are \textbf{not} guaranteed to exist. + +\theorem{} +$a$ has an inverse in $\mathbb{Z}_n$ if and only if $\gcd(a, n) = 1$ \par + +\problem{} +Find the inverse of $3$ in $\mathbb{Z}_4$, if one exists. \par +Find the inverse of $20$ in $\mathbb{Z}_{14}$, if one exists. \par +Find the inverse of $4$ in $\mathbb{Z}_7$, if one exists. + +\begin{solution} + \begin{itemize} + \item $3^{-1}$ in $\mathbb{Z}_{4}$ is $3$ + \item $20^{-1}$ in $\mathbb{Z}_{14}$ doesn't exist. + \item $4^{-1}$ in $\mathbb{Z}_{7}$ is $2$ + \end{itemize} +\end{solution} + +\vfill + + +\problem{} +Show that if $n$ is prime, every element of $\mathbb{Z}_n$ (except 0) has an inverse. +\vfill + +\problem{} +Show that if $n$ is not prime, $\mathbb{Z}_n$ has at least one element with no inverse. +\vfill + +\pagebreak + +\problem{} +In general, how can we find the inverse of $a$ in $\mathbb{Z}_n$? Assume $a$ and $n$ are coprime.\par +\hint{You can find that $34^{-1}$ is $-175$ in $\mathbb{Z}_{541}$ by looking at a previous problem.} + +\begin{solution} + We need an $a^{-1}$ so that $a \times a^{-1} = 1$. \par + This means that $aa^{-1} - mk = 1$. \par + Since $a$ and $m$ are coprime, $\gcd(a, m) = 1$ and $aa^{-1} - mk = \gcd(a, m)$ \par + Now use the extended Euclidean algorithm from \ref{extendedeuclid} to find $a^\star$. +\end{solution} + +\vfill + +\definition{} +Elements in $\mathbb{Z}_n$ that have an inverse are called \textit{units}. \par +The set of units in $\mathbb{Z}_n$ is called $\mathbb{Z}_n^\times$, which is read \say{$\mathbb{Z}$ mod $n$ cross}. + +\problem{} +What is $\mathbb{Z}_5^\times$? \par +What is $\mathbb{Z}_{12}^\times$? \par + +\vfill +\pagebreak + diff --git a/src/Advanced/Cryptography/parts/2 groups.tex b/src/Advanced/Cryptography/parts/2 groups.tex new file mode 100755 index 0000000..32f3c78 --- /dev/null +++ b/src/Advanced/Cryptography/parts/2 groups.tex @@ -0,0 +1,99 @@ +\section{Groups} + +Group theory gives us a set tools for understanding complex structures. +We can use groups to solve the Rubik's cube, +to solve problems in physics and chemistry, +and to understand complex geometric symmetries. +It's also worth noting that much of modern cryptography +is built using results from group theory. + +\definition{} +A \textit{group} $(G, \ast)$ consists of a set $G$ and an operator $\ast$. \par +Groups always have the following properties: + +\begin{enumerate} + \item $G$ is closed under $\ast$. In other words, $a, b \in G \implies a \ast b \in G$. + \item $\ast$ is associative: $(a \ast b) \ast c = a \ast (b \ast c)$ for all $a,b,c \in G$ + \item There is an \textit{identity} $e \in G$, so that $a \ast e = a \ast e = a$ for all $a \in G$. + \item For any $a \in G$, there exists a $b \in G$ so that $a \ast b = b \ast a = e$. $b$ is called the \textit{inverse} of $a$. \par + This element is written as $-a$ if our operator is addition and $a^{-1}$ otherwise. +\end{enumerate} + +Any pair $(G, \ast)$ that satisfies these properties is a group. + +\problem{} +Is $(\mathbb{Z}_5, +)$ a group? \par +Is $(\mathbb{Z}_5, -)$ a group? \par +\hint{$+$ and $-$ refer to the usual operations in modular arithmetic.} +\vfill + + +\problem{} +Show that $(\mathbb{R}, \times)$ is not a group, +then find a subset $S$ of $\mathbb{R}$ so that $(S, \times)$ is a group. + +\begin{solution} + $(\mathbb{R}, \times)$ is not a group because $0$ has no inverse. \par + The solution is simple: remove the problem. + + \vspace{3mm} + + $(\mathbb{R} - \{0\}, \times)$ is a group. +\end{solution} +\vfill + + +\problem{} +What is the smallest group we can create? + +\begin{solution} + Let $(G, \circledcirc)$ be our group, where $G = \{\star\}$ and $\circledcirc$ is defined by the identity $\star \circledcirc \star = \star$ + + Verifying that the trivial group is a group is trivial. +\end{solution} + + +\vfill +\pagebreak + + +\problem{} +Let $(G, \ast)$ be a group with finitely many elements, and let $a \in G$. \par +Show that there exists an $n$ in $\mathbb{Z}^+$ so that $a^n = e$ \par +\hint{$a^n \coloneqq a \ast a \ast ... \ast a$, with $a$ repeated $n$ times.} + +\vspace{2mm} + +The smallest such $n$ defines the \textit{order} of $g$. + +\vfill + +\problem{} +What is the order of 5 in $(\mathbb{Z}_{25}, +)$? \par +What is the order of 2 in $(\mathbb{Z}_{17}^\times, \times)$? \par + +\vfill + + +\theorem{} +Let $p$ be a prime number. \par +In any group $(\mathbb{Z}_p^\times, \ast)$ there exists a $g \in \mathbb{Z}_p^\times$ where... + +\begin{itemize}[itemsep=1mm] + \item The order of $g$ is $p - 1$, and + \item $\{a^0,~ a^1,~ ...,~ a^{p - 2}\} = \mathbb{Z}_n^\times$ +\end{itemize} +We call such a $g$ a \textit{generator}, since its powers generate every other element in the group. + +\begin{instructornote} + $\mathbb{Z}_p^\times$ has $p-1$ elements. \par + The set $\{a^0,~ a^1,~ ...,~ a^{p - 2}\}$ also has $p-1$ elements, since we start counting from zero. + + \vspace{2mm} + + The fact that the last power here is $p-2$ can be a bit confusing, but it's just the result of counting from zero. + We could also write this set as $\{a^1,~ a^2,~ ...,~ a^{p - 1}\}$, since $a^0 = a^{p - 1}$. +\end{instructornote} + +\vfill +\pagebreak diff --git a/src/Advanced/Cryptography/parts/3 DLP.tex b/src/Advanced/Cryptography/parts/3 DLP.tex new file mode 100755 index 0000000..2f980e1 --- /dev/null +++ b/src/Advanced/Cryptography/parts/3 DLP.tex @@ -0,0 +1,42 @@ +\section{The Discrete Log Problem} + +\definition{} +Let $g$ be a generator in $(\mathbb{Z}_p^\times, \ast)$ \par +Let $n$ be a positive integer. + +\vspace{1mm} + +We now want a function \say{log} from $\mathbb{Z}_p^\times$ to $\mathbb{Z}^+$ so that $\log_g(g^n) = n$. \par +In other words, we want an inverse of the \say{exponent} function. + +\vspace{1mm} + +This is the \textit{discrete logarithm problem}, often abbreviated \textit{DLP}. + +\problem{} +Does the discrete log function even exist? \par +Show that $\exp$ is a bijection, which will guarantee the existence of $\log$. \par +\note[Note]{Why does this guarantee the existence of log? Recall our lesson on functions.} + +\vfill + +\problem{} +Find a simple (but perhaps inefficient) way to calculate $\log_g(a)$ + +\vfill + +\problem{} +Find an efficient way to solve the discrete log problem. \par +Then learn \LaTeX, write a paper, and enjoy free admission to the graduate program at any university. \par + +\vfill + +The discrete logarithm can be quickly computed in a few special cases, but there is no known way to efficiently compute it in general. Interestingly enough, we haven't been able to prove that an efficient solution \textit{doesn't} exist. The best we can offer is a \say{proof by effort:} many smart people have been trying for long time and haven't solved it yet. It probably doesn't exist. + +\vspace{2mm} + +In the next few pages, we'll see how the assumption \say{DLP is hard} can be used to construct various tools used to secure communications. + +\pagebreak + + diff --git a/src/Advanced/Cryptography/parts/4 DiffieHellman.tex b/src/Advanced/Cryptography/parts/4 DiffieHellman.tex new file mode 100755 index 0000000..4044bf4 --- /dev/null +++ b/src/Advanced/Cryptography/parts/4 DiffieHellman.tex @@ -0,0 +1,129 @@ +\section{Diffie-Hellman Key Exchange} + +One problem we encounter in computer science is \textit{secure key exchange}: How can two parties (usually called Alice and Bob) agree on a \say{key} without revealing anything to an eavesdropper (Eve)? + +\begin{center} +\begin{tikzpicture} + \node (A) at (0, 0) {Alice}; + \node (B) at (4, 0) {Bob}; + \node (E) at (2, -1) {Eve}; + + \draw[-] + (A) edge (B) + (E) edge (2, 0) + ; +\end{tikzpicture} +\end{center} + + +A simple mathematical solution to the key exchange problem is the \textit{Diffie-Hellman key exchange algorithm}, detailed below. + +\vspace{1mm} + +Values that are \textit{public} are known to everyone. Values that are sent are also known to everyone: we assume that everyone can see what Alice and Bob send to each other. + +Eve can read all public values, but she cannot change them in any way. + +\begin{center} +\begin{tikzpicture}[scale = 0.5] + + \def\bx{18} + \def\ex{13} + + \node[anchor = center] at (\ex, 7.5) {\textbf{Setup}}; + \draw[-] (\ex-4.5, 7) -- (\ex+4.5, 7); + + \node[anchor = west] at (\ex-4, 6) {Let $p$ be a prime number}; + \node[anchor = west] at (\ex-4, 5) {Let $g$ be a generator in $\mathbb{Z}_p^\times$}; + \node[anchor = west] at (\ex-4, 4) {Both $g$ and $p$ are public.}; + + + + + + \node[anchor = center] at (4, 1.5) {\textbf{Alice}}; + \draw[-] (-0.5, 1) -- (8.5, 1); + + \node[anchor = west] at (0, 0) {Pick a random $a \in \mathbb{Z}_p^\times$}; + \node[anchor = west] at (0, -1) {Set $A = g^a$}; + + \node[anchor = west] at (0, -3) {Publish $A$}; + \draw[->] (6, -3) -- (\ex - 1, -3); + + \node[anchor = west] at (0, -5) {\color{gray} Compute ...}; + + + + + \node[anchor = center] at (\bx+4, 1.5) {\textbf{Bob}}; + \draw[-] (\bx-0.5, 1) -- (\bx+8.5, 1); + + \node[anchor = west] at (\bx, 0) {Pick a random $b \in \mathbb{Z}_p^\times$}; + \node[anchor = west] at (\bx, -1) {Set $B = g^b$}; + + + \node[anchor = west] at (\bx, -4) {Publish $B$}; + \draw[->] (\bx - 1, -4) -- (\ex+1, -4); + + \node[anchor = west] at (\bx, -5) {\color{gray} Compute ...}; + + + + + \node[anchor = center] at (\ex, 1.5) {\textbf{Public}}; + \draw[-] (\ex-2, 1) -- (\ex+2, 1); + + \node[anchor = center] at (\ex, 0) {$p, g$}; + + \node[fill=white, anchor = center] at (\ex, -3) {$A$}; + \node[fill=white, anchor = center] at (\ex, -4) {$B$}; + + + + +\end{tikzpicture} +\end{center} + +\problem{} +Complete the algorithm. What should Alice and Bob compute? \par +\hint{ + The goal of this process is to arrive at a \textit{shared secret} \par + That is, Alice and Bob should arrive at the same value without exposing it to Eve. +} + +\vfill + + +\problem{} +Let $p = 11$, $g = 2$, $a = 9$, and $b = 4$. \par +Run the algorithm. What is the resulting shared secret? + +\begin{solution} + $g^b = 5$\par + $g^a = 6$\par + $g^{ab} = g^{ba} = 9$ % spell:disable-line +\end{solution} + + +\vfill +\pagebreak + +\problem{} +Is the Diffie-Hellman key exchange algorithm secure? What information does Eve have? \par +What does Eve need to do to find the value Alice and Bob agreed on? + +\vfill + + +\problem{} +Now, say Eve can change information in transit. \par +That is, she can pretend to be Alice to send information to Bob. \par +How can she break this system? \par +\note[Note]{This is called a \textit{man-in-the-middle} attack.} + +\vfill + + +\pagebreak + + diff --git a/src/Advanced/Cryptography/parts/5 Elgamal.tex b/src/Advanced/Cryptography/parts/5 Elgamal.tex new file mode 100755 index 0000000..c5bb38c --- /dev/null +++ b/src/Advanced/Cryptography/parts/5 Elgamal.tex @@ -0,0 +1,128 @@ +\section{Elgamal Asymmetric Encryption} + +Another cryptographic tool we often use is the \textit{public key cryptosystem}. +In such a system, one has two keys: a \textit{public key} that can only encrypt data, and a \textit{private key} that can decrypt it. +The following problem provides a simple example. + + +\problem{} +Alice wants to send a secret letter to Bob. Eve, the postman, would like to see what is inside. \par + +\vspace{2mm} + +Alice has a box, a lock, and a key. Bob does not own a lock. \par +Eve will open the box if she can, but she will not try to break any locks. \par +Also, she will always deliver the box without modifying its contents. + +\vspace{2mm} + +How can Alice send her letter without letting Eve read it? + + +\vfill + +Elgamal encryption allows Alice to publish a public key ($A$ in the diagram below), +which Bob can use to encrypt a message. Alice then uses here private key ($a$) to decrypt it. + + +\begin{center} +\begin{tikzpicture}[scale = 0.5] + + \def\bx{18} + \def\ex{13} + + \node[anchor = center] at (\ex, 7.5) {\textbf{Setup}}; + \draw[-] (\ex-4.5, 7) -- (\ex+4.5, 7); + + \node[anchor = west] at (\ex-4, 6) {Let $p$ be a prime number}; + \node[anchor = west] at (\ex-4, 5) {Let $g$ be a generator in $\mathbb{Z}_p^\times$}; + \node[anchor = west] at (\ex-4, 4) {Both $g$ and $p$ are public.}; + + + + + + \node[anchor = center] at (4, 1.5) {\textbf{Alice}}; + \draw[-] (-0.5, 1) -- (8.5, 1); + + \node[anchor = west] at (0, 0) {Pick a random $a \in \mathbb{Z}_p^\times$}; + \node[anchor = west] at (0, -1) {Set $A = g^a$}; + \node[anchor = west] at (0, -2) {Publish $A$}; + \draw[->] (6, -2) -- (\ex - 1, -2); + \draw[->] (\ex+1, -2) -- (\bx - 1, -2); + + + \node[anchor = west] at (0, -6) {Compute $c_2 \times c_1^{-a}$}; + \node[anchor = west] at (0, -7) {$= (mA^k)(g^{-ak})$}; + \node[anchor = west] at (0, -8) {$= (m)(g^{ak}g^{-ak})$}; + \node[anchor = west] at (0, -9) {$= m$}; + + + + + \node[anchor = center] at (\bx+4, 1.5) {\textbf{Bob}}; + \draw[-] (\bx-0.5, 1) -- (\bx+8.5, 1); + + \node[anchor = west] at (\bx, 0) {Bob has a message $m \in \mathbb{Z}_p^\times$}; + \node[anchor = west] at (\bx, -1) {Pick a random $k \in \mathbb{Z}_p^\times$}; + \node[anchor = west] at (\bx, -3) {Set $c_1 = g^k$}; + \node[anchor = west] at (\bx, -4) {Set $c_2 = mA^k$}; + + + \node[anchor = west] at (\bx, -5) {Publish $(c_1, c_2)$}; + \draw[->] (\bx-1, -5) -- (\ex+1.5, -5); + \draw[->] (\ex-1.5, -5) -- (6, -5); + + + + + \node[anchor = center] at (\ex, 1.5) {\textbf{Public}}; + \draw[-] (\ex-2, 1) -- (\ex+2, 1); + + \node[anchor = center] at (\ex, 0) {$p, g$}; + + \node[fill=white, anchor = center] at (\ex, -2) {$A$}; + \node[fill=white, anchor = center] at (\ex, -5) {$(c_1, c_2)$}; +\end{tikzpicture} +\end{center} + +\problem{} +Let $p = 17$, $g = 2$, $a = 7$, $k = 10$, and $m = 3$ \par +Run this algorithm and make sure it works. + +\begin{solution} + $A = 2^7 = 9$\par + $c_1 = 2^10 = 4$\par + $c_2 = 3(9^{10}) = 5$ + + \vspace{2mm} + + $c_1^a = 13$, so $c_1^{-a} = 4$\par + $c_2 \times c_1^a = 5 \times 4 = 3 = m$ +\end{solution} + +\vfill +\pagebreak + + +\problem{} +What information does Eve have? \par +What does Eve need to do to find $m$? +\vfill + +\problem{} +Say Bob re-uses the same $k$ twice.\par +Let $(c_1, c_2)$ and $(d_1, d_2)$ be two ciphertexts generated with this key, encrypting messages $m_1$ and $m_2$. \par +Also, say Eve knows the value of $m_1 - m_2$. How can Eve find $m_1$ and $m_2$?\par +\note[Note]{If Bob doesn't change his key, Eve will also be able to decrypt future messages.} + +\begin{solution} + $c_2 - d_2 = (m_1 - m_2)A^k$ \par + So, $(c_2 - d_2)(m_1 - m_2)^{-1} = A^k$\par + Now that we have $A^k$, we can compute $m_1 = c_2 \times A^{-k}$ +\end{solution} + +\vfill +\pagebreak + + diff --git a/src/Advanced/Cryptography/parts/challenge.tex b/src/Advanced/Cryptography/parts/challenge.tex new file mode 100755 index 0000000..9a84946 --- /dev/null +++ b/src/Advanced/Cryptography/parts/challenge.tex @@ -0,0 +1,187 @@ +\section{Bonus Problems} + + +\problem{} +Show that a group has exactly one identity element. +\vfill + +\problem{} +Show that each element in a group has exactly one inverse. +\vfill + +\problem{} +Let $(G, \ast)$ be a group and $a, b, c \in G$. Show that... +\begin{itemize} + \item $a \ast b = a \ast c \implies b = c$ + \item $b \ast a = c \ast a \implies b = c$ +\end{itemize} + +This means that we can \say{cancel} operations in groups, much like we do in algebra. + +\vfill +\pagebreak + + + + +\problem{} +Let $G$ be the set of all bijections $A \to A$. \par +Let $\circ$ be the usual composition operator. \par +Is $(G, \circ)$ a group? +\vfill + +\definition{} +Note that our definition of a group does \textbf{not} state that $a \ast b = b \ast a$. \par +Many interesting groups do not have this property. +Those that do are called \textit{abelian} groups. \par + +\vspace{2mm} + +One example of a non-abelian group is the set of invertible 2x2 matrices under matrix multiplication. + +\problem{} +Show that if $G$ has four elements, $(G, \ast)$ is abelian. + +\vfill +\pagebreak + +\problem{} +Prove \ref{mod_has_inverse}: \par +$a$ has an inverse mod $m$ iff $\gcd(a, m) = 1$ \par + + +\begin{solution} + Assume $a^\star$ is the inverse of $a \pmod{m}$. \par + Then $a^\star \times a \equiv 1 \pmod{m}$ \par + + Therefore, $aa^\star - 1 = km$, and $aa^\star - km = 1$ \par + We know that $\gcd(a, m)$ divides $a$ and $m$, therefore $\gcd(a, m)$ must divide $1$. \par + $\gcd(a, m) = 1$ \par + + Now, assume $\gcd(a, m) = 1$. \par + By the Extended Euclidean Algorithm, we can find $(u, v)$ that satisfy $au+mv=1$ \par + So, $au-1 = mv$. \par + $m$ divides $au-1$, so $au \equiv 1 \pmod{m}$ \par + $u$ is $a^\star$. +\end{solution} + + +\vfill + + +\problem{} +The Euclidean Algorithm (From \ref{euclid}) can be written as follows: \par + +\begin{itemize} + \item Assume $a > b$. + \item Set $e_0 = a$ and $e_1 = b$. \par + \item Let $e_{n+1} = \text{remainder}(r_{n-1} \div r_{n})$ \par + \item Stop when $e_{k} = 0$. + \item Then, $\gcd(a, b) = e_{k-1}$. \par +\end{itemize} + + +Let $F_n$ be the $n^{\text{th}}$ Fibonacci number. ($F_0 = 0$; $F_1 = 1$; $F_2 = 1$; $\dots$) \par + +\vspace{2mm} + +Show that if the Euclidean algorithm requires $n$ steps for an input $(a, b)$, then $a \geq F_{n+2}$ and $b \geq F_{n+1}$. +In other words, show that the longest-running input of a given size is a Fibonacci pair. + +\begin{solution} + The easiest way to go about this is induction on $n$: \par + + \textcolor{gray}{\textit{Base Case:}} + + If $n = 1$, $b$ divides $a$ with no remainder, and the smallest possible $a, b$ for which this is true is $(2, 1) = (F_3, F_2)$. + + \linehack{} + + \textcolor{gray}{\textit{Induction:}} + + Assume that for $n$ steps, $a \geq F_{n+2}$ and $b \geq F_{n+1}$. + + Now, say the algorithm takes $n+1 = m$ steps. \par + + The first step gives us $a = q_0b + r_0$ \par + Therefore, the pair $(b, r_0)$ must take $m-1$ steps. \par + We thus know that $b \geq F_{m+1}$ and $r_0 \geq F_m$ \hfill \textcolor{gray}{by our induction hypothesis} \par + Therefore, $a = q_0b + r_0 \geq b + r_0$ \par + But $b + r_0 = F_{m+1} + F_{m} = F_{m+2}$, \par + so $a \geq F_{m+2}$. +\end{solution} + +\vfill +\pagebreak + +\problem{Chinese Remainder Theorem} +There are certain things whose number is unknown. If we count them by threes, we have two left over; by fives, we have three left over; and by sevens, two are left over. How many things are there? + +\begin{solution} + $x \equiv 2 \pmod{3}$ \par + $x \equiv 3 \pmod{5}$ \par + $x \equiv 2 \pmod{7}$ \par + + $x = 23 + 105k\ \forall k \in \mathbb{Z}$ +\end{solution} + +\vfill + +\problem{} +Show that if $p$ is prime, $\binom{p}{i} \equiv 0 \pmod{p}$ +for $0 < i < p$. + +\begin{solution} + $\binom{p}{i} = \frac{p!}{i!(p-i)!}$ tells us that $i!(p-i)!$ divides $p! = p(p-1)!$. \\ + However, $i!(p-i)!$ and $p$ are coprime, since all factors of $i!(p-i)!$ are smaller than $p$. \\ + Therefore, $i!(p-i)!$ must divide $(p-1)!$ \par + + So, $\binom{p}{i} = p \times \frac{(p-1)!}{i!(p-i)!}$, and $\binom{p}{i} \equiv 0 \pmod{p}$. +\end{solution} + +\vfill +\pagebreak + +\problem{Fermat's Little Theorem} +Show that if $p$ is prime and $a \not\equiv 0 \pmod{p}$, then $a^{p-1} \equiv 1 \pmod{p}$. \\ +You may want to use \ref{flt_prereq}. \par +\hint{It may be easier to show that $a^p \equiv a \pmod{p}$} + + +\begin{solution} + Use induction: + + $1 \equiv 1 \pmod{p}$ \par + + Using \ref{flt_prereq} and the binomial theorem, we have + + $2^p = (1 + 1)^p = 1 + \binom{p}{1} + \binom{p}{2} + \dots + \binom{p}{p-1} + 1 \equiv 1 + 0 + ... + 0 + 1 \equiv 2 \pmod{p}$ \par + + Then, + + $3^p = (1 + 2)^p = 1 + \binom{p}{1}2 + \binom{p}{2}2^2 + \dots + \binom{p}{p-1}2^{p-1} + 2^p \equiv 1 + 0 + ... + 0 + 2 \equiv 3 \pmod{p}$ \par + + We can repeat this for all $a$. This proof can be presented more formally with a bit of induction. + +\end{solution} + +\vfill + + +\problem{} +Show that for any three integers $a, b, c$, \par +$\gcd(ac + b, a) = \gcd(a, b)$ \par + +%\begin{solution} +% This problem is hard, \\ +% I'll write a solution eventually. +%\end{solution} + +\vfill + +[Note on \ref{eua_runtime}] This proof can be used to show that the Euclidean +algorithm finishes in logarithmic time, and it is the first practical application +of the Fibonacci numbers. If you have finished all challenge problems, +finish the proof: find how many steps the Euclidean algorithm needs to arrive at +a solution for a given $a$ and $b$. +\pagebreak \ No newline at end of file diff --git a/src/Advanced/DFAs/main.tex b/src/Advanced/DFAs/main.tex new file mode 100755 index 0000000..8a75b06 --- /dev/null +++ b/src/Advanced/DFAs/main.tex @@ -0,0 +1,24 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\input{tikzset.tex} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Finite Automata} +\subtitle{Prepared by Mark and Nikita on \today{}} + + +\begin{document} + + \maketitle + + \input{parts/0 DFA.tex} + \input{parts/1 regular.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/DFAs/meta.toml b/src/Advanced/DFAs/meta.toml new file mode 100644 index 0000000..cbe951b --- /dev/null +++ b/src/Advanced/DFAs/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Finite Automata" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/DFAs/parts/0 DFA.tex b/src/Advanced/DFAs/parts/0 DFA.tex new file mode 100644 index 0000000..53744d5 --- /dev/null +++ b/src/Advanced/DFAs/parts/0 DFA.tex @@ -0,0 +1,649 @@ +\section{DFAs} + +This week, we will study computational devices called \textit{deterministic finite automata}. \par +A DFA has a simple job: it will either \say{accept} or \say{reject} a string of letters. + +\vspace{2mm} + +Consider the automaton $A$ shown below: + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[accept] (b) at (2, 0) {$b$}; + \node[main] (c) at (5, 0) {$c$}; + \node[start] (s) at (-2, 0) {\texttt{start}}; + \end{scope} + + \draw[->] + (s) edge (a) + (a) edge node[label] {$1$} (b) + (a) edge[loop above] node[label] {$0$} (a) + (b) edge[bend left] node[label] {$0$} (c) + (b) edge[loop above] node[label] {$1$} (b) + (c) edge[bend left] node[label] {$0,1$} (b) + ; +\end{tikzpicture} +\end{center} + +$A$ takes strings of letters in the alphabet $\{0, 1\}$ and reads them left to right, one letter at a time. \par +Starting in the state $a$, the automaton $A$ will move between states along the edge marked by each letter. \par + +\vspace{2mm} + +Note that node $b$ has a \say{double edge} in the diagram above. This means that the state $b$ is \textit{accepting}. Any string that makes $A$ end in state $b$ is \textit{accepted}. Similarly, strings that end in states $a$ or $c$ are \textit{rejected}. \par + +\vspace{2mm} + +For example, consider the string \texttt{1011}. \par +$A$ will go through the states $a - b - c - b - b$ while processing this string. \par + + +\problem{} +Which of the following strings are accepted by $A$? \par +\begin{itemize} + \item \texttt{1} + \item \texttt{1010} + \item \texttt{1110010} + \item \texttt{1000100} +\end{itemize} + +\vfill + + + +\problem{} +Describe the general form of a string accepted by $A$. \par +\hint{Work backwards from the accepting state, and decide what all the strings must look like at the end in order to be accepted.} + +\begin{solution} + $A$ will accept strings that contain at least one $1$ and end with an even (possibly 0) number of zeroes. +\end{solution} + +\vfill +\pagebreak + + + +Now consider the automaton $B$, which uses the alphabet $\{a, b\}$. \par +It starts in the state $s$ and has two accepting states $a_1$ and $b_1$. + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (s) at (0, 0) {$s$}; + \node[accept] (a1) at (-2, -0.5) {$a_1$}; + \node[main] (a2) at (-2, -2.5) {$a_2$}; + \node[accept] (b1) at (2, -0.5) {$b_1$}; + \node[main] (b2) at (2, -2.5) {$b_2$}; + \node[start] (start) at (0, 1) {\texttt{start}}; + \end{scope} + + \clip (-4, -3.5) rectangle (4, 1); + + \draw[->] + (start) edge (s) + (s) edge node[label] {\texttt{a}} (a1) + (a1) edge[loop left] node[label] {\texttt{a}} (a1) + (a1) edge[bend left] node[label] {\texttt{b}} (a2) + (a2) edge[bend left] node[label] {\texttt{a}} (a1) + (a2) edge[loop left] node[label] {\texttt{b}} (a2) + (s) edge node[label] {\texttt{b}} (b1) + (b1) edge[loop right] node[label] {\texttt{b}} (b1) + (b1) edge[bend left] node[label] {\texttt{a}} (b2) + (b2) edge[bend left] node[label] {\texttt{b}} (b1) + (b2) edge[loop right] node[label] {\texttt{a}} (b2) + ; +\end{tikzpicture} +\end{center} + +\problem{} +Which of the following strings are accepted by $B$? +\begin{itemize} + \item \texttt{aa} + \item \texttt{abba} + \item \texttt{abbba} + \item \texttt{baabab} +\end{itemize} + +\vfill + + + +\problem{} +Describe the strings accepted by $B$. + +\begin{solution} + $B$ accepts strings that start and end with the same letter. +\end{solution} + +\vfill +\pagebreak + +Before we continue, let's properly define all the words we've been using in the problems above. + +\definition{} +An \textit{alphabet} is a finite set of symbols. \par + +\definition{} +A \textit{string} over an alphabet $Q$ is a finite sequence of symbols from $Q$. \par +We'll denote the empty string $\varepsilon$. \par + + +\definition{} +$Q^*$ is the set of all possible strings over $Q$. \par +For example, $\{\texttt{0}, \texttt{1}\}^*$ is the set $\{\varepsilon, \texttt{0}, \texttt{1}, \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}, \texttt{000},... \}$ \par +Note that this set contains the empty string. + +\definition{} +A \textit{language} over an alphabet $Q$ is a subset of $Q^*$. \par +For example, the language \say{strings of length 2} over $\{\texttt{0}, \texttt{1}\}$ is $\{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$ + +\definition{} +The language \textit{recognized} by a DFA is the set of strings that the DFA accepts. + +\vspace{5mm} + +\problem{} +How many strings of length $n$ are accepted by the automaton below? \par +\hint{Induction.} + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (0) at (0, 0) {$0$}; + \node[accept] (1) at (3, 0) {$1$}; + \node[main] (2) at (5, 0) {$2$}; + \node[start] (s) at (-2, 0) {\texttt{start}}; + \end{scope} + + \draw[->] + (s) edge (0) + (0) edge[loop above] node[label] {\texttt{b}} (0) + (0) edge[bend left] node[label] {\texttt{a}} (1) + (1) edge[bend left] node[label] {\texttt{b}} (0) + (1) edge node[label] {\texttt{a}} (2) + (2) edge[loop above] node[label] {\texttt{a,b}} (2) + ; +\end{tikzpicture} +\end{center} + +\begin{solution} + If $A_n$ is the number of accepted strings of length $n$, then $A_n = A_{n-1}+A_{n-2}$. \par + Computing initial conditions, we see that $A_n$ is an $n+2$-th Fibonacci number. +\end{solution} + +\vfill + +\vfill +\pagebreak + +\problem{} +Draw DFAs that recognize the following languages. In all parts, the alphabet is $\{0, 1\}$: +\begin{itemize} + \item $\{w~ | ~w~ \text{begins with a \texttt{1} and ends with a \texttt{0}}\}$ + \item $\{w~ | ~w~ \text{contains at least three \texttt{1}s}\}$ + \item $\{w~ | ~w~ \text{contains the substring \texttt{0101} (i.e, $w = x\texttt{0101}y$ for some $x$ and $y$)}\}$ + \item $\{w~ | ~w~ \text{has length at least three and its third symbol is a \texttt{0}}\}$ + \item $\{w~ | ~w~ \text{starts with \texttt{0} and has odd length, or starts with \texttt{1} and has even length}\}$ + \item $\{w~ | ~w~ \text{doesn't contain the substring \texttt{110}}\}$ +\end{itemize} + +\begin{solution} + $\{w~ | ~w~ \text{begins with a \texttt{1} and ends with a \texttt{0}}\}$ + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[accept] (0) at (0, 2) {$\phantom{0}$}; + \node[main] (1) at (3, 2) {$\phantom{0}$}; + \node[main] (2) at (0, 0) {$\phantom{0}$}; + \node[main] (3) at (3, 0) {$\phantom{0}$}; + \node[start] (s) at (-2, 0) {\texttt{start}}; + \end{scope} + + \clip (-2, -1) rectangle (4.5, 3); + + \draw[->] + (s) edge (2) + (0) edge[loop left] node[label] {\texttt{1}} (0) + (0) edge[bend left] node[label] {\texttt{1}} (1) + (1) edge[loop right] node[label] {\texttt{1}} (1) + (1) edge[bend left] node[label] {\texttt{0}} (0) + (2) edge[out=90, in=270] node[label] {\texttt{1}} (1) + (2) edge node[label] {\texttt{0}} (3) + (3) edge[loop right] node[label] {\texttt{1,0}} (3) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + $\{w~ | ~w~ \text{contains at least three \texttt{1}s}\}$ + + \begin{center} + + + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (s) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[main] (1) at (2, 0) {$\phantom{0}$}; + \node[main] (2) at (4, 0) {$\phantom{0}$}; + \node[accept] (3) at (6, 0) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (s) edge (0) + (0) edge[loop above] node[label] {\texttt{0}} (0) + (1) edge[loop above] node[label] {\texttt{0}} (1) + (2) edge[loop above] node[label] {\texttt{0}} (2) + (3) edge[loop above] node[label] {\texttt{0,1}} (3) + (0) edge node[label] {\texttt{1}} (1) + (1) edge node[label] {\texttt{1}} (2) + (2) edge node[label] {\texttt{1}} (3) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + $\{w~ | ~w~ \text{contains the substring \texttt{0101}}\}$ + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (s) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[main] (1) at (2, 1) {$\phantom{0}$}; + \node[main] (2) at (4, 1) {$\phantom{0}$}; + \node[main] (3) at (0, 3) {$\phantom{0}$}; + \node[accept] (4) at (2, 3) {$\phantom{0}$}; + \end{scope} + + % Tikz includes invisible handles in picture size. + % This crops the image to fix sizing. + \clip (-2, -1.75) rectangle (5, 5.25); + + \draw[->] + (s) edge (0) + (0) edge[loop above] node[label] {\texttt{1}} (0) + (0) edge[bend right] node[label] {\texttt{0}} (1) + (1) edge[loop above] node[label] {\texttt{0}} (1) + (1) edge node[label] {\texttt{1}} (2) + (3) edge[bend right] node[label] {\texttt{0}} (1) + (3) edge node[label] {\texttt{1}} (4) + (4) edge[loop above] node[label] {\texttt{0,1}} (4) + ; + + \draw[->, rounded corners = 10mm] + (2) to (4, 5) to node[label] {\texttt{0}} (0, 5) to (3) + ; + + \draw[->, rounded corners = 10mm] + (2) to (4, -1.5) to node[label] {\texttt{1}} (0, -1.5) to (0) + ; + + \end{tikzpicture} + \end{center} + + Notice that after getting two 0's in a row we don't reset to the initial state. + + \pagebreak + $\{w~ | ~w~ \text{has length at least three and its third symbol is a \texttt{0}}\}$ + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (s) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[main] (1) at (2, 0) {$\phantom{0}$}; + \node[main] (2) at (4, 0) {$\phantom{0}$}; + \node[accept] (3) at (6, 1) {$\phantom{0}$}; + \node[accept] (4) at (6, -1) {$\phantom{0}$}; + \end{scope} + + \clip (-2, -2.5) rectangle (7, 2.5); + + \draw[->] + (s) edge (0) + (0) edge node[label] {\texttt{0,1}} (1) + (1) edge node[label] {\texttt{0,1}} (2) + (2) edge node[label] {\texttt{0}} (3) + (2) edge node[label] {\texttt{1}} (4) + (3) edge[loop above] node[label] {\texttt{0,1}} (3) + (4) edge[loop below] node[label] {\texttt{0,1}} (4) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + $\{w~ | ~w~ \text{starts with \texttt{0} and has odd length, or starts with \texttt{1} and has even length}\}$ + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (s) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (2, 1) {$\phantom{0}$}; + \node[main] (2) at (4, 1) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (s) edge (0) + (0) edge node[label] {\texttt{0}} (1) + (1) edge[bend left] node[label] {\texttt{0,1}} (2) + (2) edge[bend left] node[label] {\texttt{0,1}} (1) + ; + + \draw[->, rounded corners = 5mm] + (0) to node[label] {\texttt{1}} (4, 0) to (2) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + $\{w~ | ~w~ \text{doesn't contain the substring \texttt{110}}\}$ + + \begin{center} + + + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (s) at (-2, 0){\texttt{start}}; + \node[accept] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (2, 0) {$\phantom{0}$}; + \node[accept] (2) at (4, 0) {$\phantom{0}$}; + \node[main] (3) at (6, 0) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (s) edge (0) + (0) edge[loop above] node[label] {\texttt{0}} (0) + (2) edge[loop above] node[label] {\texttt{1}} (2) + (3) edge[loop above] node[label] {\texttt{0,1}} (3) + (0) edge[bend left] node[label] {\texttt{1}} (1) + (1) edge[bend left] node[label] {\texttt{0}} (0) + (1) edge node[label] {\texttt{1}} (2) + (2) edge node[label] {\texttt{0}} (3) + ; + \end{tikzpicture} + \end{center} + + Notice that after getting three 1's in a row we don't reset to the initial state. +\end{solution} + +\vfill +\pagebreak + +\problem{} +Draw a DFA over an alphabet $\{\texttt{a}, \texttt{b}, \texttt{@}, \texttt{.}\}$ recognizing the language of strings of the form \texttt{user@website.domain}, where \texttt{user}, \texttt{website} and \texttt{domain} are nonempty strings over $\{\texttt{a}, \texttt{b}\}$ and \texttt{domain} has length 2 or 3. + +\begin{solution} + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (start) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[main] (1) at (0, 2) {$\phantom{0}$}; + \node[main] (2) at (0, 4) {$\phantom{0}$}; + \node[main] (3) at (0, 6) {$\phantom{0}$}; + \node[main] (4) at (0, 8) {$\phantom{0}$}; + \node[main] (5) at (0, 10) {$\phantom{0}$}; + \node[accept] (6) at (0, 12) {$\phantom{0}$}; + \node[accept] (7) at (0, 14) {$\phantom{0}$}; + + \node[main] (8) at (5, 7) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (start) edge (0) + (0) edge node[label] {\texttt{a,b}} (1) + (1) edge node[label] {\texttt{@}} (2) + (2) edge node[label] {\texttt{a,b}} (3) + (3) edge node[label] {\texttt{.}} (4) + (4) edge node[label] {\texttt{a,b}} (5) + (5) edge node[label] {\texttt{a,b}} (6) + (6) edge node[label] {\texttt{a,b}} (7) + + (1) edge[loop left] node[label] {\texttt{a,b}} (1) + (3) edge[loop left] node[label] {\texttt{a,b}} (3) + + (0) edge[out=0, in=270] node[label] {\texttt{@,.}} (8) + (1) edge[out=0, in=245] node[label] {\texttt{.}} (8) + (2) edge[out=0, in=220] node[label] {\texttt{@,.}} (8) + (3) edge[out=0, in=195] node[label] {\texttt{@}} (8) + (4) edge[out=0, in=170] node[label] {\texttt{@,.}} (8) + (5) edge[out=0, in=145] node[label] {\texttt{@,.}} (8) + (6) edge[out=0, in=120] node[label] {\texttt{@,.}} (8) + (7) edge[out=0, in=95] node[label] {\texttt{a,b,@,.}} (8) + ; + + \draw[->, rounded corners = 5mm] + (8) to +(1.5, 1) to node[label] {\texttt{a,b,@,.}} +(1.5, -1) to (8) + ; + \end{tikzpicture} + \end{center} + +\end{solution} + +\vfill + +%\problem{} +%Construct a DFA that accepts a binary integer iff it is divisible by two. +%\vfill + + +\vfill +\pagebreak + +\problem{} +Draw a state diagram for a DFA over an alphabet of your choice that accepts exactly $f(n)$ strings of length $n$ if \par +\begin{itemize} + \item $f(n) = n$ + \item $f(n) = n+1$ + \item $f(n) = 3^n$ + \item $f(n) = n^2$ + \item $f(n)$ is a Tribonacci number. \par + Tribonacci numbers are defined by the sequence $f(0) = 0$, $f(1) = 1$, $f(2) = 1$, + and $f(n) = f(n-1)+f(n-2)+f(n-3)$ for $n \ge 3$ \par + \hint{Fibonacci numbers are given by the automaton prohibiting two letters \say{\texttt{a}} in a row.} +\end{itemize} + + +\begin{solution} + + \textbf{Part 4:} $f(n) = n^2$ \par + Consider the language of words over $\{0, 1, 2\}$ that have the sum of their digits equal to $2$. \par + Such words must contain two ones or one two: + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (start) at (-2, 0) {\texttt{start}}; + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (2, 0) {$\phantom{0}$}; + \node[main] (2) at (0, -2) {$\phantom{0}$}; + \node[main] (3) at (2, -2) {$\phantom{0}$}; + \end{scope} + + \clip (-2, 1.5) rectangle (4, -2.75); + + \draw[->] + (start) edge (0) + + (0) edge[loop above] node[label] {\texttt{0}} (0) + (1) edge[loop above] node[label] {\texttt{0}} (1) + (2) edge[loop left] node[label] {\texttt{0}} (2) + (3) edge[loop right] node[label] {\texttt{0,1,2}} (3) + + (0) edge node[label] {\texttt{2}} (1) + (0) edge node[label] {\texttt{1}} (2) + (1) edge node[label] {\texttt{1,2}} (3) + (2) edge node[label] {\texttt{1}} (1) + (2) edge node[label] {\texttt{2}} (3) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + + + \textbf{Part 5:} Tribonacci numbers \par + Using the hint, we get the following automaton. \par + It rejects all strings with three \texttt{a}s in a row. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (start) at (-2, 0) {\texttt{start}}; + \node[accept] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (0, 2) {$\phantom{0}$}; + \node[accept] (2) at (2, 0) {$\phantom{0}$}; + \node[main] (3) at (4, 0) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (start) edge (0) + (0) edge[loop below] node[label] {\texttt{b}} (0) + (3) edge[loop above] node[label] {\texttt{a,b}} (3) + (0) edge[bend left] node[label] {\texttt{a}} (1) + (1) edge[bend left] node[label] {\texttt{b}} (0) + (1) edge[bend left] node[label] {\texttt{a}} (2) + (2) edge node[label] {\texttt{a}} (3) + (2) edge node[label] {\texttt{b}} (0) + ; + \end{tikzpicture} + \end{center} + + This automaton rejects all strings with three \texttt{a}s in a row. If we count accepted strings, we get the Tribonacci numbers with an offset: $f(0) = 1$, $f(1) = 2$, $f(2)=4$, ... \par + + \pagebreak + + We can fix this by adding a node and changing the start state: + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (start) at (1, -2) {\texttt{start}}; + \node[accept] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (0, 2) {$\phantom{0}$}; + \node[accept] (2) at (2, 0) {$\phantom{0}$}; + \node[main] (3) at (4, 0) {$\phantom{0}$}; + \node[main] (4) at (3, -2) {$\phantom{0}$}; + \end{scope} + + \draw[->] + (start) edge (4) + (2) edge node[label] {\texttt{b}} (0) + (4) edge node[label] {\texttt{b}} (2) + (4) edge node[label] {\texttt{a}} (3) + + (0) edge[loop below] node[label] {\texttt{b}} (0) + (3) edge[loop above] node[label] {\texttt{a,b}} (3) + (0) edge[bend left] node[label] {\texttt{a}} (1) + (1) edge[bend left] node[label] {\texttt{b}} (0) + (1) edge[bend left] node[label] {\texttt{a}} (2) + (2) edge node[label] {\texttt{a}} (3) + (2) edge node[label] {\texttt{b}} (0) + ; + \end{tikzpicture} + \end{center} +\end{solution} + +\vfill +\pagebreak + +% \problem{} +% Draw a DFA over an alphabet $\{a, b, c\}$, accepting all the suffixes of the string $abbc$ (including $\varepsilon$) and only them. + + +\problem{} + Draw a DFA recognizing the language of strings over $\{\texttt{0}, \texttt{1}\}$ in which \texttt{0} is the third digit from the end. \par + Prove that any such DFA must have at least 8 states. + +\begin{solution} + + \textbf{Part 1:} \par + Index the states by three-letter suffixes \texttt{000}, \texttt{001}, ..., \texttt{111}. All strings that end with letters $d_1d_2d_3$ will end up in the state $d_1d_2d_3$. We accept all states that start with a \texttt{0}. \par + Note that we can start at any node if we ignore strings with fewer than three letters. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[start] (start) at (-2, 0) {\texttt{start}}; + \node[main] (7) at (0, 0) {\texttt{111}}; + \node[accept] (3) at (0, -2) {\texttt{011}}; + \node[main] (6) at (2, -2) {\texttt{110}}; + \node[main] (4) at (4, -2) {\texttt{100}}; + \node[accept] (1) at (-4, -4) {\texttt{001}}; + \node[main] (5) at (0, -4) {\texttt{101}}; + \node[accept] (2) at (-2, -4) {\texttt{010}}; + \node[accept] (0) at (-2, -6) {\texttt{000}}; + \end{scope} + + \draw[->] + (0) edge[loop left, looseness = 7] node[label] {\texttt{0}} (0) + (7) edge[loop above, looseness = 7] node[label] {\texttt{1}} (7) + + (start) edge (7) + + (0) edge[out=90,in=-90] node[label] {\texttt{1}} (1) + (1) edge node[label] {\texttt{0}} (2) + (1) edge[out=45,in=-135] node[label] {\texttt{1}} (3) + (2) edge[bend left] node[label] {\texttt{1}} (5) + (3) edge node[label] {\texttt{0}} (6) + (3) edge node[label] {\texttt{1}} (7) + (5) edge[bend left] node[label] {\texttt{0}} (2) + (5) edge node[label] {\texttt{1}} (3) + (6) edge[bend left] node[label] {\texttt{0}} (4) + (6) edge[out=-90,in=0] node[label] {\texttt{1}} (5) + (7) edge[out=0,in=90] node[label] {\texttt{0}} (6) + ; + + \draw[->, rounded corners = 10mm] + (4) to (4, 2) to node[label] {\texttt{1}} (-4, 2) to (1) + ; + + \draw[->, rounded corners = 10mm] + (4) to (4, -6) to node[label] {\texttt{0}} (0) + ; + + \draw[->, rounded corners = 5mm] + (2) to (-2, -5) to node[label] {\texttt{0}} (3, -5) to (3, -2) to (4) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + + \textbf{Part 2:} \par + Strings \texttt{000}, \texttt{001}, ..., \texttt{111} must lead to pairwise different states. \par + + \vspace{2mm} + + Assume \texttt{101} and \texttt{010} lead to the same state. Append a \texttt{1} to the end of the string. \par + \texttt{101} will become \texttt{011}, and \texttt{010} will become \texttt{101}. These must be different states, since we accept \texttt{011} and reject \texttt{101}. We now have a contradiction: one edge cannot lead to two states! + + \vspace{2mm} + + \texttt{101} and \texttt{010} must thus correspond to distinct states. \par + We can repeat this argument for any other pair of strings. \par + +\end{solution} + +\vfill +\pagebreak + +\problem{} +Construct a DFA that accepts an binary integer if and only if it is divisible by six. \par +Strings are read from most to least significant digit. +(that is, 18 will be read as 1,0,0,1,0) + +\vfill + +\problem{} +Construct a DFA that satisfies \ref{divsix}, but reads digits in the opposite order. + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/DFAs/parts/1 regular.tex b/src/Advanced/DFAs/parts/1 regular.tex new file mode 100644 index 0000000..11b9978 --- /dev/null +++ b/src/Advanced/DFAs/parts/1 regular.tex @@ -0,0 +1,186 @@ +\section{Regular languages} + +\definition{} +We say a language is \textit{regular} if it is recognized by some $DFA$. + +\problem{} +Draw a DFA over $\{A, B\}$ that accepts strings which do not start and end with the same letter. \par +\hint{Modify the DFA in \ref{SameStartAndEnd}.} + +\vfill + +\problem{} +Let $L$ be a regular language over an alphabet $Q$. \par +Show that $Q^* - L$ is also regular. \par +\hint{$Q^* - L$ is the set of objects in $Q^*$ but not in $L$. This is often called the \textit{complement} of $L$.} + +\begin{solution} + Invert accepting and rejecting states. +\end{solution} + +\vfill +\pagebreak + + + + +\problem{} +Draw a DFA over the alphabet $\{A, B\}$ that accepts strings which have even length and do not start and end with the same letter. \par + + +\vfill + +\problem{} +Let $L_1$, $L_2$ be two regular languages over an alphabet $Q$. \par +Show that their union and intersection are also regular. + +\begin{solution} + Consider a product of automatons where each state is a pair of states in the first and second automaton and every transition works if it was applied to both elements in pair. + + \vspace{2mm} + + For union, we call the state $(s_1, s_2)$ accepting if $s_1$ OR $s_2$ is accepting in their respective automaton. + + \vspace{2mm} + + For intersection, we call it accepting if $s_1$ AND $s_2$ are accepting in their respective automaton. +\end{solution} + + +\vfill +\pagebreak + + +\theorem{Pumping Lemma} +Let $A$ be a regular language. \par +There then exists a number $p$, called the \textit{pumping length}, so that any string $s \in A$ of length at least $p$ may be divided into three pieces $s = xyz$ satisfying the following: + +\begin{itemize} + \item $|y| > 0$ \tab~\tab \hint{In other words, the segment $y$ is not the empty string.} + \item $|xy| \leq p$. \tab~\tab \hint{$|s|$ is the length of a string.} + \item $\forall i > 0$, $x y^i z \in A$ \tab \hint{$y^i$ means that $y$ is repeated $i$ times. $y^0$ is the empty string.} +\end{itemize} + +When $s$ is divided into $xyz$, either $x$ or $z$ may be the empty string, but $y$ must not be empty. \par +Notice that without the first condition, this theorem is trivially true. + +\vspace{2mm} + +In english, the pumping lemma states that in any regular language, any string of sufficient length contains a substring that can be \say{pumped} (or repeated) to generate more strings in that language. + + +\problem{} +Check that the pumping lemma holds with $p = 3$ for the following DFA. \par +\hint{This is the same DFA as in \ref{fibonacci}. What kind of strings does it accept?} + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (0) at (0, 0) {$\phantom{0}$}; + \node[accept] (1) at (3, 0) {$\phantom{0}$}; + \node[main] (2) at (5, 0) {$\phantom{0}$}; + \node[start] (s) at (-2, 0) {\texttt{start}}; + \end{scope} + + \draw[->] + (s) edge (0) + (0) edge[loop above] node[label] {\texttt{b}} (0) + (0) edge[bend left] node[label] {\texttt{a}} (1) + (1) edge[bend left] node[label] {\texttt{b}} (0) + (1) edge node[label] {\texttt{a}} (2) + (2) edge[loop above] node[label] {\texttt{a,b}} (2) + ; +\end{tikzpicture} +\end{center} + + +\vfill + +\problem{} +How can we use the pumping lemma to show that a language is \textbf{not} regular? +\vfill + +%\part{b} Suppose that there is a regular language $L$ in the alphabet $\{a\}$. $L$ contains all strings of $a$'s whose length is some set $S$. Derive from the pumping lemma that if $S$ is infinite then it contains some arithmetic progression. + +% \part{c} Prove directly that if $S$ is infinite, than it contains some arithmetic progression. \textit{Hint: look at the first cycle in the DFA you get while reading $aaa\dots$.} + +\problem{} +Prove the pumping lemma. \par +\hint{Look at the first cycle in the DFA you get while reading $s$.} + +\begin{solution} + Look at the first place where we come to an already visited state while reading the word. Say the first time we came to this state after reading $x$ and the second time after reading $xy$. Then $y$ doesn't move us from this state and we can omit it or repeat any number of times we want. +\end{solution} + +\vfill +\pagebreak + +\problem{} +Show that the following languages are not regular: \par + +\begin{enumerate}[itemsep=2mm] + % \item $\{a^{n^2}\}$, the language of all strings over the alphabet $\{a\}$ which have a square length. \par + % $\{a^{n^2}\} = \{ \varepsilon, \texttt{a}, \texttt{aaaa}, \texttt{aaaaaaaaa}, ... \}$ + + \item $\{0^n1^n ~|~ n \in \mathbb{Z}^+_0\}$ over $\{0, 1\}$, which is the shorthand for the set $\{\varepsilon, 01, 0011, \dots\}$ + + \item The language ADD over the alphabet $\Sigma = \{0, 1, +, =\}$ where \par + $\text{ADD} = \{ ~ \text{\say{x=y+z}} ~|~ x, y, z ~ \text{are binary integers, and $x$ is the sum of $y$ and $z$}\}$ + + \item The language of all palindromes over the english alphabet + +\end{enumerate} + + +\begin{solution} + % \textbf{Part A:} \par + % Follows from parts b-c of the previous problem; + % \vspace{2mm} + + \textbf{Part A:} \par + Assume this language is regular. Let $p$ be the pumping length. The string $0^p1^p$ must then be accepted, implying that the string $0^{p-|y|}1^p$ (or $0^{p+|y|}1^p$) is also accepted. + + \vspace{2mm} + + \textbf{Part B:} \par + By pumping $10^{p+1}=10^p+10^p$ + + \vspace{2mm} + + \textbf{Part C:} \par + By pumping $a^pba^p$ + + +\end{solution} + + +\vfill +\pagebreak + +\definition{} +Let $w$ be a string over an alphabet $A$. \par +If $a \in A$, $|w|_a$ is the number of times the letter $a$ occurs in $w$. + +\vspace{2mm} + +For the following problems, we will use the alphabet $\{a, b\}$. + +\problem{} +Show that the language $L_p = \Bigl\{w ~\Bigl|~ \text{$p$ divides } |w|_a - |w|_b \Bigr\}$ is regular for any prime $p$. + +\vfill + +\problem{} +Show that $L = \Bigl\{ w ~\Big|~ |w|_a - |w|_b = \pm 1 \Bigr\}$ is not regular. + +\vfill + +\problem{} +Prove that there are infinitely many primes. + +\begin{solution} + \texttt{https://www.jstor.org/stable/48661886} +\end{solution} + +\vfill +\pagebreak diff --git a/src/Advanced/DFAs/tikzset.tex b/src/Advanced/DFAs/tikzset.tex new file mode 100644 index 0000000..911338c --- /dev/null +++ b/src/Advanced/DFAs/tikzset.tex @@ -0,0 +1,79 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweak + >={Latex[ width=2mm, length=2mm ]}, + % + % Labels inside edges + label/.style = { + rectangle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none, + rounded corners = 0mm + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white, + line width = 0.35mm + }, + accept/.style = { + draw, + circle, + fill = white, + double, + double distance = 0.5mm, + line width = 0.35mm + }, + start/.style = { + draw, + rectangle, + fill = white, + line width = 0.35mm + }, + % + % Loop tweaks + loop above/.style = { + min distance = 2mm, + looseness = 8, + out = 45, + in = 135 + }, + loop below/.style = { + min distance = 5mm, + looseness = 10, + out = 315, + in = 225 + }, + loop right/.style = { + min distance = 5mm, + looseness = 10, + out = 45, + in = 315 + }, + loop left/.style = { + min distance = 5mm, + looseness = 10, + out = 135, + in = 215 + } +} \ No newline at end of file diff --git a/src/Advanced/De Bruijn/main.tex b/src/Advanced/De Bruijn/main.tex new file mode 100755 index 0000000..4dff0e9 --- /dev/null +++ b/src/Advanced/De Bruijn/main.tex @@ -0,0 +1,30 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\input{tikzset.tex} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{De Bruijn Sequences} +\subtitle{ + Prepared by Mark on \today{} \par + Based on a handout by Glenn Sun +} + + +\begin{document} + + \maketitle + + \input{parts/0 intro} + \input{parts/1 words} + \input{parts/2 bruijn} + \input{parts/3 line} + \input{parts/4 sturmian} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/De Bruijn/meta.toml b/src/Advanced/De Bruijn/meta.toml new file mode 100644 index 0000000..e86e40b --- /dev/null +++ b/src/Advanced/De Bruijn/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "De Bruijn" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/De Bruijn/parts/0 intro.tex b/src/Advanced/De Bruijn/parts/0 intro.tex new file mode 100644 index 0000000..10ed2c7 --- /dev/null +++ b/src/Advanced/De Bruijn/parts/0 intro.tex @@ -0,0 +1,56 @@ +\section{Introduction} + +\example{} +A certain electronic lock has two buttons: \texttt{0} and \texttt{1}. +It opens as soon as the correct two-digit code is entered, completely ignoring +previous inputs. For example, if the correct code is \text{10}, the lock will open +once the sequence \texttt{010} is entered. + +\vspace{2mm} + +Naturally, there are $2^2 = 4$ possible combinations that open this lock. \par +If we don't know the lock's combination, we could try to guess it by trying all four combinations. \par +This would require eight key presses: \texttt{0001101100}. + +\problem{} +There is, of course, a better way. \par +Unlock this lock with only 5 keypresses. + +\begin{solution} + The sequence \texttt{00110} is guaranteed to unlock this lock. +\end{solution} +\vfill + +Now, consider the same lock, now set with a three-digit binary code. +\problem{} +How many codes are possible? +\vfill + +\problem{} +Show that there is no solution with fewer than three keypresses +\vfill + +\problem{} +What is the shortest sequence that is guaranteed to unlock the lock? \par +\hint{You'll need 10 digits.} + +\begin{solution} + \texttt{0001110100} will do. +\end{solution} + + +%\problem{} +%How about a four-digit code? How many digits do we need? \par +% +%\begin{instructornote} +% Don't spend too much time here. +% Provide a solution at the board once everyone has had a few +% minutes to think about this problem. +%\end{instructornote} +% +%\begin{solution} +% One example is \texttt{0000 1111 0110 0101 000} +%\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/De Bruijn/parts/1 words.tex b/src/Advanced/De Bruijn/parts/1 words.tex new file mode 100644 index 0000000..527cd10 --- /dev/null +++ b/src/Advanced/De Bruijn/parts/1 words.tex @@ -0,0 +1,225 @@ +\section{Words} + +\definition{} +An \textit{alphabet} is a set of symbols. \par +For example, $\{\texttt{0}, \texttt{1}\}$ is an alphabet of two symbols, +and $\{\texttt{a}, \texttt{b}, \texttt{c}\}$ is an alphabet of three. + +\definition{} +A \textit{word} over an alphabet $A$ is a sequence of symbols in that alphabet. \par +For example, $\texttt{00110}$ is a word over the alphabet $\{\texttt{0}, \texttt{1}\}$. \par +We'll let $\varnothing$ denote the empty word, which is a valid word over any alphabet. + +\definition{} +Let $v$ and $w$ be words over the same alphabet. \par +We say $v$ is a \textit{subword} of $w$ if $v$ is contained in $w$. \par +\note{ + In other words, $v$ is a subword of $w$ if we can construct $v$ \par + by removing a few characters from the start and end of $w$. +} +For example, \texttt{11} is a subword of \texttt{011}, but \texttt{00} is not. + +\definition{} +Recall \ref{lockproblem}. Let's generalize this to the \textit{$n$-subword problem}: \par +Given an alphabet $A$ and a positive integer $n$, +we want a word over $A$ that contains all possible length-$n$ subwords. +The shortest word that solves a given $n$-subword problem is called the \textit{optimal solution}. + + + +\problem{} +List all subwords of \texttt{110}. \par +\hint{There are six.} + +\begin{solution} + They are $\varnothing$, \texttt{0}, \texttt{1}, \texttt{10}, \texttt{11}, and \texttt{110}. +\end{solution} + +\vfill + + +\definition{} +Let $\mathcal{S}_n(w)$ be the number of subwords of length $n$ in a word $w$. + +\problem{} +Find the following: +\begin{itemize} + \item $\mathcal{S}_n(\texttt{101001})$ for $n \in \{0, 1, ..., 6\}$ + \item $\mathcal{S}_n(\texttt{abccac})$ for $n \in \{0, 1, ..., 6\}$ +\end{itemize} + +\begin{solution} + In order from $\mathcal{S}_0$ to $\mathcal{S}_6$: + \begin{itemize} + \item 1, 2, 3, 4, 3, 2, 1 + \item 1, 3, 5, 4, 3, 2, 1 + \end{itemize} +\end{solution} + +\vfill +\pagebreak + + + + + + + +\problem{} +Let $w$ be a word over an alphabet of size $k$. \par +Prove the following: +\begin{itemize} + \item $\mathcal{S}_n(w) \leq k^n$ + \item $\mathcal{S}_n(w) \geq \mathcal{S}_{n-1}(w) - 1$ + \item $\mathcal{S}_n(w) \leq k \times \mathcal{S}_{n-1}(w)$ +\end{itemize} + +\begin{solution} + \begin{itemize} + \item There are $k$ choices for each of $n$ letters in the subword. + So, there are $k^n$ possible words of length $n$, and $\mathcal{S}_n(w) \leq k^n$. + + \item For almost every distinct subword counted by $\mathcal{S}_{n-1}$, + concatenating the next letter creates a distinct length $n$ subword. + The only exception is the last subword with length $n-1$, so + $\mathcal{S}_n(w) \geq \mathcal{S}_{n-1}(w) - 1$ + + \item For each subword counted by $\mathcal{S}_{n-1}$, there are $k$ possibilities + for the letter that follows in $w$. Each element in the count $\mathcal{S}_n$ comes from + one of $k$ different length $n$ words starting with an element counted by $\mathcal{S}_{n-1}$. + Thus, $\mathcal{S}_n(w) \leq k \times \mathcal{S}_{n-1}(w)$ + \end{itemize} +\end{solution} + + +\vfill +\pagebreak + + + + + + + +\definition{} +Let $v$ and $w$ be words over the same alphabet. \par +The word $vw$ is the word formed by writing $v$ after $w$. \par +For example, if $v = \texttt{1001}$ and $w = \texttt{10}$, $vw$ is $\texttt{100110}$. + +\problem{} +Let $F_k$ denote the word over the alphabet $\{\texttt{0}, \texttt{1}\}$ obtained from the following relation: +\begin{equation*} + F_0 = \texttt{0}; ~~ F_1 = \texttt{1}; ~~ F_k = F_{k-1}F_{k-2} +\end{equation*} +We'll call this the \textit{Fibonacci word} of order $k$. +\begin{itemize} + \item What are $F_3$, $F_4$, and $F_5$? + \item Compute $\mathcal{S}_0$ through $\mathcal{S}_5$ for $F_5$. + \item Show that the length of $F_k$ is the $(k + 2)^\text{th}$ Fibonacci number. \par + \hint{Induction.} +\end{itemize} + +\begin{solution} + \begin{itemize} + \item $F_3 = \texttt{101}$ + \item $F_4 = \texttt{10110}$ + \item $F_5 = \texttt{10110101}$ + \end{itemize} + + \linehack{} + + \begin{itemize} + \item $\mathcal{S}_0 = 1$ + \item $\mathcal{S}_1 = 2$ + \item $\mathcal{S}_2 = 3$ + \item $\mathcal{S}_3 = 4$ + \item $\mathcal{S}_4 = 5$ + \item $\mathcal{S}_5 = 4$ + \end{itemize} + + \linehack + + As stated, use induction. The base case is trivial. \par + Let $N_k$ represent the Fibonacci numbers, with $N_0 = 0$, $N_1 = 1$, and $N_{k} = N_{k-1} + N_{k-2}$ + + \vspace{2mm} + + Assume that $F_k$ has length $N_{k+2}$ for all $k \leq n$. + We want to show that $F_{k+1}$ has length $N_{k+3}$. \par + Since $F_{k} = F_{k-1}F_{k-2}$, it has the length $|F_{k-1}| + |F_{k-2}|$. \par + By our assumption, $|F_{k-1}| = N_{k+1}$ and $|F_{k-2}| = N_{k}$. \par + So, $|F_{k}| = |F_{k-1}| + |F_{k-2}| = N_{k+1} + N_{k} = N_{k + 2}$. + +\end{solution} + +\vfill +\pagebreak + + + + + + + + + +% C_k is called the "Champernowne word" of order k. +\problem{} +Let $C_k$ denote the word over the alphabet $\{\texttt{0}, \texttt{1}\}$ obtained by \par +concatenating the binary representations of the integers $0,~...,~2^k -1$. \par +For example, $C_1 = \texttt{01}$, $C_2 = \texttt{011011}$, and $C_3 = \texttt{011011100101110111}$. +\begin{itemize} + % Good bonus problem, hard to find a closed-form solution + % \item How many symbols does the word $C_k$ contain? + \item Compute $\mathcal{S}_0$, $\mathcal{S}_1$, $\mathcal{S}_2$, and $\mathcal{S}_3$ for $C_3$. + \item Show that $\mathcal{S}_k(C_k) = 2^k - 1$. + \item Show that $\mathcal{S}_n(C_k) = 2^n$ for $n < k$. +\end{itemize} +\hint{ + If $v$ is a subword of $w$ and $w$ is a subword of $u$, $v$ must be a subword of $u$. \par + In other words, the \say{subword} relation is transitive. +} + +\begin{solution} + $\mathcal{S}_0 = 1$, $\mathcal{S}_1 = 2$, $\mathcal{S}_2 = 4$, and $\mathcal{S}_3 = 7$. + + \linehack{} + + First, we show that $\mathcal{S}_k(C_k) = 2^k - 1$. \par + Consider an arbitrary word $w$ of length $k$. We'll consider three cases: + + \begin{itemize} + \item If $w$ consists only of zeros, $w$ does not appear in $C_k$. + + \item If $w$ starts with a \texttt{1}, $w$ must appear in $C_k$ by construction. + + \item If $w$ does starts with a \texttt{0} and contains a \texttt{1}, $w$ has the form + $\texttt{0}^x\texttt{1}\overline{\texttt{y}}$ \par + \note{ + That is, $x$ copies of \texttt{0} followed by a \texttt{1}, followed by \par + an arbitrary sequence $\overline{\texttt{y}}$ with length $(k-x-1)$. + } \par + Now consider the word $\texttt{1}\overline{\texttt{y}}\texttt{0}^x\texttt{1}\overline{\texttt{y}}\texttt{0}^{(x-1)}\texttt{1}$. \par + This is the concatenation of two consecutive binary numbers with $k$ digits, and thus appears in $C_k$. + $w$ is a subword of this word, and therefore also appears in $C_k$. + \end{itemize} + + \linehack{} + + We can use the above result to conclude that $\mathcal{S}_n(C_k) = 2^n$ for $n < k$: \par + If we take any word of length $n < k$ and repeatedly append \texttt{1} to create a word of length $k$, \par + we end up with a subword of $C_k$ by the reasoning above. \par + Thus, any word of length $n$ is a subword of $w$, of which there are $2^n$. +\end{solution} + + +\vfill + +\problem{} +Convince yourself that $C_{n+1}$ provides a solution to the $n$-subword problem over $\{\texttt{0}, \texttt{1}\}$. \par +\note[Note]{$C_{n+1}$ may or may not be an \textit{optimal} solution---but it is a \textit{valid} solution} \par +Which part of \ref{cword} shows that this is true? + +\pagebreak + + diff --git a/src/Advanced/De Bruijn/parts/2 bruijn.tex b/src/Advanced/De Bruijn/parts/2 bruijn.tex new file mode 100644 index 0000000..c585343 --- /dev/null +++ b/src/Advanced/De Bruijn/parts/2 bruijn.tex @@ -0,0 +1,392 @@ +\section{De Bruijn Words} + +Before we continue, we'll need to review some basic +graph theory. + +\definition{} +A \textit{directed graph} consists of nodes and directed edges. \par +An example is shown below. It consists of three vertices (labeled $a, b, c$), \par +and five edges (labeled $0, ... , 4$). + +\begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (2, 0) {$b$}; + \node[main] (c) at (4, 0) {$c$}; + \end{scope} + + \draw[->] + (a) edge node[label] {$0$} (b) + (a) edge[loop above] node[label] {$1$} (a) + (b) edge[bend left] node[label] {$2$} (c) + (b) edge[loop above] node[label] {$3$} (b) + (c) edge[bend left] node[label] {$4$} (b) + ; + \end{tikzpicture} +\end{center} + +\definition{} +A \textit{path} in a graph is a sequence of adjacent edges, \par +In a directed graph, edges $a$ and $b$ are adjacent if $a$ ends at the node which $b$ starts at. \par +\vspace{2mm} +For example, consider the graph above. \par +The edges $1$ and $0$ are adjacent, since you can take edge $0$ after taking edge $1$. \par +$0$ starts where $1$ ends. \par +$0$ and $1$, however, are not: $1$ does not start at the edge at which $0$ ends. + + +\definition{} +An \textit{Eulerian path} is a path that visits each edge of a graph exactly once. \par +An \textit{Eulerian cycle} is an Eulerian path that starts and ends on the same node. + +\problem{} +Find the single unique Eulerian cycle in the graph below. +\begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (2, 0) {$b$}; + \node[main] (c) at (4, 0) {$c$}; + \end{scope} + + \draw[->] + (a) edge[bend left] node[label] {$0$} (b) + (b) edge[bend left] node[label] {$1$} (a) + (b) edge[bend left] node[label] {$2$} (c) + (c) edge[bend left] node[label] {$3$} (b) + (c) edge[loop right] node[label] {$4$} (c) + ; + \end{tikzpicture} +\end{center} + +\begin{solution} + $24310$ is one way to write this cycle. \par + There are other options, but they're all the same. +\end{solution} + +\vfill + +\theorem{} +A directed graph contains an Eulerian cycle iff... +\begin{itemize} + \item There is a path between every pair of nodes, and + \item every node has as many \say{in} edges as it has \say{out} edges. +\end{itemize} + +If the a graph contains an Eulerian cycle, it must contain an Eulerian path. \note{(why?)} \par +Some graphs contain an Eulerian path, but not a cycle. In this case, both conditions above must +still hold, but the following exceptions are allowed: +\begin{itemize} + \item There may be at most one node where $(\text{number in} - \text{number out}) = 1$ + \item There may be at most one node where $(\text{number in} - \text{number out}) = -1$ +\end{itemize} +\note[Note]{Either both exceptions occur, or neither occurs. Bonus problem: why?} +We won't provide a proof of this theorem today. However, you should convince yourself that it is true: +if any of these conditions are violated, why do we know that an Eulerian cycle (or path) cannot exist? + +\pagebreak + + + + + + +\definition{} +Now, consider the $n$-subword problem over $\{\texttt{0}, \texttt{1}\}$. \par +We'll call the optimal solution to this problem a \textit{De Bruijn\footnotemark{} word} of order $n$. \par + +\footnotetext{Dutch. Rhymes with \say{De Grown.}} + + +\problem{} +Let $w$ be the an order-$n$ De Bruijn word, and denote its length with $|w|$. \par +Show that the following bounds always hold: +\begin{itemize} + \item $|w| \leq n2^n$ + \item $|w| \geq 2^n + n - 1$ +\end{itemize} + +\begin{solution} + \begin{itemize} + \item There are $2^n$ binary words with length $n$. \par + Concatenate these to get a word with length $n2^n$. + \item A word must have at least $2^n + n - 1$ letters to have $2^n$ subwords with length $n$. + \end{itemize} +\end{solution} + + +\remark{} +Now, we'd like to show that the length of a De Bruijn word is always $2^n + n - 1$ \par +That is, that the optimal solution to the subword problem always has $2^n + n - 1$ letters. \par +We'll do this by construction: for a given $n$, we want to build a word with length $2^n + n - 1$ +that solves the binary $n$-subword problem. + + + +\definition{} +Consider a $n$-length word $w$. \par +The \textit{prefix} of $w$ is the word formed by the first $n-1$ letters of $w$. \par +The \textit{suffix} of $w$ is the word formed by the last $n-1$ letters of $w$. \par +For example, the prefix of the word \texttt{1101} is \texttt{110}, and its suffix is \texttt{101}. +The prefix and suffix of any one-letter word are both $\varnothing$. + +\definition{} +A \textit{De Bruijn graph} of order $n$, denoted $G_n$, is constructed as follows: +\begin{itemize} + \item Nodes are created for each word of length $n - 1$. + \item A directed edge is drawn from $a$ to $b$ if the suffix of + $a$ matches the prefix of $b$. \par + Note that a node may have an edge to itself. + \item We label each edge with the last letter of $b$. +\end{itemize} +$G_2$ and $G_3$ are shown below. + +\null\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + $G_2$ + + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (0) at (0, 0) {\texttt{0}}; + \node[main] (1) at (2, 0) {\texttt{1}}; + \end{scope} + + \draw[->] + (0) edge[loop left] node[label] {$0$} (0) + (1) edge[loop right] node[label] {$1$} (1) + (1) edge[bend left] node[label] {$0$} (0) + (0) edge[bend left] node[label] {$1$} (1) + ; + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + $G_3$ + + \begin{tikzpicture}[scale = 0.9] + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[loop left] node[label] {$0$} (00) + (11) edge[loop right] node[label] {$1$} (11) + (00) edge[bend left] node[label] {$1$} (01) + (01) edge[bend left] node[label] {$0$} (10) + (10) edge[bend left] node[label] {$1$} (01) + (10) edge[bend left] node[label] {$0$} (00) + (01) edge[bend left] node[label] {$1$} (11) + (11) edge[bend left] node[label] {$0$} (10) + ; + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill\null + +\vfill +\pagebreak + + + + + + + + + + + +\problem{} +Draw $G_4$. + +\begin{solution} + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (7) at (0, 0) {\texttt{111}}; + \node[main] (3) at (0, -2) {\texttt{011}}; + \node[main] (6) at (2, -2) {\texttt{110}}; + \node[main] (4) at (4, -2) {\texttt{100}}; + \node[main] (1) at (-4, -4) {\texttt{001}}; + \node[main] (5) at (0, -4) {\texttt{101}}; + \node[main] (2) at (-2, -4) {\texttt{010}}; + \node[main] (0) at (-2, -6) {\texttt{000}}; + \end{scope} + + \draw[->] + (0) edge[loop left, looseness = 7] node[label] {\texttt{0}} (0) + (7) edge[loop above, looseness = 7] node[label] {\texttt{1}} (7) + + (0) edge[out=90,in=-90] node[label] {\texttt{1}} (1) + (1) edge node[label] {\texttt{0}} (2) + (1) edge[out=45,in=-135] node[label] {\texttt{1}} (3) + (2) edge[bend left] node[label] {\texttt{1}} (5) + (3) edge node[label] {\texttt{0}} (6) + (3) edge node[label] {\texttt{1}} (7) + (5) edge[bend left] node[label] {\texttt{0}} (2) + (5) edge node[label] {\texttt{1}} (3) + (6) edge[bend left] node[label] {\texttt{0}} (4) + (6) edge[out=-90,in=0] node[label] {\texttt{1}} (5) + (7) edge[out=0,in=90] node[label] {\texttt{0}} (6) + ; + + \draw[->, rounded corners = 10mm] + (4) to (4, 2) to node[label] {\texttt{1}} (-4, 2) to (1) + ; + + \draw[->, rounded corners = 10mm] + (4) to (4, -6) to node[label] {\texttt{0}} (0) + ; + + \draw[->, rounded corners = 5mm] + (2) to (-2, -5) to node[label] {\texttt{0}} (3, -5) to (3, -2) to (4) + ; + \end{tikzpicture} + \end{center} + + \begin{instructornote} + This graph also appears as a solution to a different + problem in the DFA handout. + \end{instructornote} +\end{solution} + +\vfill +\pagebreak + +\problem{} +\begin{itemize} + \item Show that $G_n$ has $2^{n-1}$ nodes and $2^n$ edges; + \item that each node has two outgoing edges; + \item and that there are as many edges labeled $0$ as are labeled $1$. +\end{itemize} + +\begin{solution} + \begin{itemize} + \item There $2^{n-1}$ binary words of length $n-1$. + \item The suffix of a given word is the prefix of two other words, \par + so there are two edges leaving each node. + \item One of those words will end with one, and the other will end with zero. + \item Our $2^{n-1}$ nodes each have $2$ outgoing edges---we thus have $2^n$ edges in total. + \end{itemize} +\end{solution} + +\vfill + +\problem{} +Show that $G_4$ always contains an Eulerian path. \par +\hint{\ref{eulerexists}} + +\vfill + +\theorem{} +We can now easily construct De Bruijn words for a given $n$: \par +\begin{itemize} + \item Construct $G_n$, + \item find an Eulerian cycle in $G_n$, + \item then, construct a De Bruijn word by writing the label of our starting vertex, + then appending the label of every edge we travel. +\end{itemize} + +\problem{} +Find De Bruijn words of orders $2$, $3$, and $4$. + +\begin{solution} + \begin{itemize} + \item + One Eulerian cycle in $G_2$ starts at node \texttt{0}, and takes the edges labeled $[1, 1, 0, 0]$. \par + We thus have the word \texttt{01100}. + + \item + In $G_3$, we have an Eulerian cycle that visits nodes in the following order: \par + $ + \texttt{00} + \rightarrow \texttt{01} + \rightarrow \texttt{11} + \rightarrow \texttt{11} + \rightarrow \texttt{10} + \rightarrow \texttt{01} + \rightarrow \texttt{10} + \rightarrow \texttt{00} + \rightarrow \texttt{00} + $\par + This gives us the word \texttt{0011101000} + + \item Similarly, we $G_4$ gives us the word \texttt{0001 0011 0101 1110 000}. \par + \note{Spaces have been added for convenience.} + \end{itemize} +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + +Let's quickly show that the process described in \ref{dbeuler} +indeed produces a valid De Bruijn word. + +\problem{} +How long will a word generated by the above process be? + +\begin{solution} + A De Bruijn graph has $2^n$ edges, each of which is traversed exactly once. + The starting node consists of $n - 1$ letters. + + \vspace{2mm} + + Thus, the resulting word contains $2^n + n - 1$ symbols. +\end{solution} + +\vfill + +\problem{} +Show that a word generated by the process in \ref{dbeuler} +contains every possible length-$n$ subword. \par +In other words, show that $\mathcal{S}_n(w) = 2^n$ for a generated word $w$. + +\begin{solution} + Any length-$n$ subword of $w$ is the concatenation of a vertex label and an edge label. + By construction, the next length-$n$ subword is the concatenation of the next vertex and edge + in the Eulerian cycle. + + \vspace{2mm} + + This cycle traverses each edge exactly once, so each length-$n$ subword is distinct. \par + Since $w$ has length $2^n + n - 1$, there are $2^n$ total subwords. \par + These are all different, so $\mathcal{S}_n \geq 2^n$. \par + However, $\mathcal{S}_n \leq 2^n$ by \ref{sbounds}, so $\mathcal{S}_n = 2^n$. + +\end{solution} + +\vfill + +\remark{} +\begin{itemize} + \item We found that \ref{dbeuler} generates a word with length $2^n + n - 1$ in \ref{dblength}, \par + \item and we showed that this word always solves the $n$-subword problem in \ref{dbsubset}. + + \item From \ref{dbbounds}, we know that any solution to the binary $n$-subword problem \par + must have at least $2^n + n - 1$ letters. + + \item Finally, \ref{dbpath} guarantees that it is possible to generate such a word in any $G_n$. +\end{itemize} + +Thus, we have shown that the process in \ref{dbeuler} generates ideal solutions +to the $n$-subword problem, and that such solutions always exist. +We can now conclude that for any $n$, the binary $n$-subword problem may be solved with a word of length $2^n + n - 1$. + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/De Bruijn/parts/3 line.tex b/src/Advanced/De Bruijn/parts/3 line.tex new file mode 100644 index 0000000..0454474 --- /dev/null +++ b/src/Advanced/De Bruijn/parts/3 line.tex @@ -0,0 +1,110 @@ +\section{Line Graphs} + +\problem{} +Given a graph $G$, we can construct a graph called the \par +\textit{line graph} of $G$ (\hspace{0.3ex}denoted $\mathcal{L}(G)$\hspace{0.3ex}) by doing the following: \par +\begin{itemize} + \item Creating a node in $\mathcal{L}(G)$ for each edge in $G$ + \item Drawing a directed edge between every pair of nodes $a, b$ in $\mathcal{L}(G)$ \par + if the corresponding edges in $G$ are adjacent. \par + \note{That is, if edge $b$ in $G$ starts at the node at which $a$ ends.} +\end{itemize} + +\problem{} +Draw the line graph for the graph below. \par +Have an instructor check your solution. + +\begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (a) at (0, 0) {$a$}; + \node[main] (b) at (2, 0) {$b$}; + \node[main] (c) at (4, 0) {$c$}; + \end{scope} + + \draw[->] + (a) edge[bend left] node[label] {$0$} (b) + (b) edge[bend left] node[label] {$1$} (a) + (b) edge[bend left] node[label] {$2$} (c) + (c) edge[bend left] node[label] {$3$} (b) + (c) edge[loop right] node[label] {$4$} (c) + ; + \end{tikzpicture} +\end{center} + +\begin{solution} + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (1) at (0, 0) {$1$}; + \node[main] (4) at (3.5, 1) {$4$}; + \node[main] (3) at (2, 0) {$3$}; + \node[main] (2) at (2, 2) {$2$}; + \node[main] (0) at (0, 2) {$0$}; + \end{scope} + + \draw[->] + (0) edge[bend left] (1) + (1) edge[bend left] (0) + (0) edge (2) + (2) edge (3) + (2) edge[bend left] (4) + (4) edge[bend left] (2) + (3) edge (1) + (4) edge (3) + (4) edge[loop right] (4) + ; + \end{tikzpicture} + \end{center} +\end{solution} + + +\vfill + +\definition{} +We say a graph $G$ is \textit{connected} if there is a path +between any two vertices of $G$. + +\problem{} +Show that if $G$ is connected, $\mathcal{L}(G)$ is connected. + +\begin{solution} + Let $a, b$ and $x, y$ be nodes in a connected graph $G$ so that an edges $a \rightarrow b$ and + and $x \rightarrow y$ exist. Since $G$ is connected, we can find a path from $b$ to $x$. + The path $a$ to $y$ corresponds to a path in $\mathcal{L}(G)$ between $a \rightarrow b$ and $x \rightarrow y$. +\end{solution} + +\vfill +\pagebreak + + +\definition{} +Consider $\mathcal{L}(G_n)$, where $G_n$ is the $n^\text{th}$ order De Bruijn graph. \par + +\vspace{2mm} + +We'll need to label the vertices of $\mathcal{L}(G_n)$. To do this, do the following: +\begin{itemize} + \item Let $a$ and $b$ be nodes in $G_n$ + \item Let \texttt{x} be the first letter of $a$ + \item Let \texttt{y}, the last letter of $b$ + \item Let $\overline{\texttt{p}}$ be the prefix/suffix that $a$ and $b$ share. \par + Note that $a = \texttt{x}\overline{\texttt{p}}$ and $b = \overline{\texttt{p}}\texttt{y}$, +\end{itemize} +Now, relabel the edge from $a$ to $b$ as $\texttt{x}\overline{\texttt{p}}\texttt{y}$. \par +Use these new labels to name nodes in $\mathcal{L}(G_n)$. + +\problem{} +Construct $\mathcal{L}(G_2)$ and $\mathcal{L}(G_3)$. What do you notice? \par +\hint{ + What are $\mathcal{L}(G_2)$ and $\mathcal{L}(G_3)$? We've seen them before! \par + You may need to re-label a few edges. +} + +\begin{solution} + After fixing edge labels, we find that + $\mathcal{L}(G_2) \cong G_3$ and $\mathcal{L}(G_3) \cong G_4$ +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/De Bruijn/parts/4 sturmian.tex b/src/Advanced/De Bruijn/parts/4 sturmian.tex new file mode 100644 index 0000000..97b87f0 --- /dev/null +++ b/src/Advanced/De Bruijn/parts/4 sturmian.tex @@ -0,0 +1,434 @@ +\section{Sturmian Words} + +A De Bruijn word is the shortest word that contains all subwords +of a given length. \par +Let's now solve a similar problem: given an alphabet, we want to +construct a word that contains exactly $m$ distinct subwords of +length $n$. + +\vspace{2mm} + +% TODO: better, intuitive description + +In general, this is a difficult problem. We'll restrict ourselves +to a special case: \par +We'd like to find a word that contains exactly $m + 1$ distinct subwords +of length $m$ for all $m < n$. + + +\definition{} +We say a word $w$ is a \textit{Sturmian word} of order $n$ +if $\mathcal{S}_m(w) = m + 1$ for all $m \leq n$. \par +We say $w$ is a \textit{minimal} Sturmian word if there is no shorter +Sturmian word of that order. + +\problem{} +Show that the length of a Sturmian word of order $n$ is at least $2n$. + +\begin{solution} + In order to have $n + 1$ subwords of length $n$, a word must have at + least $(n+1) + (n-1) = 2n$ letters. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + + + + + + + +\problem{} +Construct $R_3$ by removing four edges from $G_3$. \par +Show that each of the following is possible: +\begin{itemize}[itemsep=2mm ] + \item $R_3$ does not contain an Eulerian path. + \item $R_3$ contains an Eulerian path, and this path \par + constructs a word $w$ with $\mathcal{S}_3(w) = 4$ + and $\mathcal{S}_2(w) = 4$. + \item $R_3$ contains an Eulerian path, and this path \par + constructs a word $w$ that is a minimal Sturmian word + of order 3. +\end{itemize} + +\begin{solution} + Remove the edges $\texttt{00} \rightarrow \texttt{01}$, + $\texttt{01} \rightarrow \texttt{10}$, + $\texttt{10} \rightarrow \texttt{00}$, and + $\texttt{11} \rightarrow \texttt{11}$: + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[loop left] node[label] {$0$} (00) + (10) edge[bend left] node[label] {$1$} (01) + (01) edge[bend left] node[label] {$1$} (11) + (11) edge[bend left] node[label] {$0$} (10) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + + Remove the edges $\texttt{00} \rightarrow \texttt{00}$, + $\texttt{01} \rightarrow \texttt{10}$, + $\texttt{10} \rightarrow \texttt{01}$, and + $\texttt{11} \rightarrow \texttt{11}$. \par + The Eulerian path starting at \texttt{00} produces \texttt{001100}, + where $\mathcal{S}_2 = \mathcal{S}_3 = 4$. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[bend left] node[label] {$1$} (01) + (10) edge[bend left] node[label] {$0$} (00) + (01) edge[bend left] node[label] {$1$} (11) + (11) edge[bend left] node[label] {$0$} (10) + ; + \end{tikzpicture} + \end{center} + + \linehack{} + + Remove the edges $\texttt{01} \rightarrow \texttt{11}$, + $\texttt{10} \rightarrow \texttt{00}$, + $\texttt{11} \rightarrow \texttt{10}$, and + $\texttt{11} \rightarrow \texttt{11}$. \par + The Eulerian path starting at \texttt{00} produces \texttt{000101}, + where $\mathcal{S}_0 = 1$, $\mathcal{S}_1 = 2$, $\mathcal{S}_2 = 3$, + and $\mathcal{S}_3 = 4$. \par + + \texttt{000101} has length $2 \times 3 = 6$, and is thus minimal. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[loop left] node[label] {$0$} (00) + (00) edge[bend left] node[label] {$1$} (01) + (01) edge[bend left] node[label] {$0$} (10) + (10) edge[bend left] node[label] {$1$} (01) + ; + \end{tikzpicture} + \end{center} + + Note that this graph contains an Eulerian path even though + \texttt{11} is disconnected. \par + An Eulerian path needs to visit all \textit{edges}, not all \textit{nodes}! +\end{solution} + + +\vfill +\pagebreak + + + + + + + + + + + + + + + + + + + +\problem{} +Construct $R_2$ by removing one edge from $G_2$, then construct $\mathcal{L}(R_2)$. \par +\begin{itemize} + \item If this line graph has four edges, set $R_3 = \mathcal{L}(R_2)$. \par + \item If not, remove one edge from $\mathcal{L}(R_2)$ so that an Eulerian path still exists + and set $R_3$ to the resulting graph. +\end{itemize} +Label each edge in $R_3$ with the last letter of its target node. \par +Let $w$ be the word generated by an Eulerian path in this graph, as before. + +\vspace{2mm} + +Attempt the above construction a few times. Is $w$ a minimal Sturmian word? + +\begin{solution} + If $R_2$ is constructed by removing the edge $\texttt{0} \rightarrow \texttt{1}$, + $\mathcal{L}(R_2)$ is the graph shown below. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[loop left] node[label] {$0$} (00) + (10) edge[bend left] node[label] {$0$} (00) + (11) edge[bend left] node[label] {$0$} (10) + (11) edge[loop right] node[label] {$1$} (11) + ; + \end{tikzpicture} + \end{center} + + We obtain the Sturmian word \texttt{111000} via the Eulerian path through the nodes + $\texttt{11} \rightarrow \texttt{11} \rightarrow \texttt{10} + \rightarrow \texttt{00} \rightarrow \texttt{00}$. + + \linehack{} + + If $R_2$ is constructed by removing the edge $\texttt{0} \rightarrow \texttt{0}$, + $\mathcal{L}(R_2)$ is the graph pictured below. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (01) edge[bend left] node[label] {$0$} (10) + (10) edge[bend left] node[label] {$1$} (01) + (11) edge[bend left] node[label] {$0$} (10) + (01) edge[bend left] node[label] {$1$} (11) + (11) edge[loop right] node[label] {$1$} (11) + ; + \end{tikzpicture} + \end{center} + + This graph contains five edges, we need to remove one. \par + To keep an Eulerian path, we can remove any of the following: + \begin{itemize} + \item $\texttt{10} \rightarrow \texttt{01}$ to produce \texttt{011101} + \item $\texttt{01} \rightarrow \texttt{11}$ to produce \texttt{111010} + \item $\texttt{11} \rightarrow \texttt{10}$ to produce \texttt{010111} + \item $\texttt{11} \rightarrow \texttt{11}$ to produce \texttt{011010} + \end{itemize} + Each of these is a minimal Sturmian word. + + \linehack{} + + The case in which we remove $\texttt{1} \rightarrow \texttt{0}$ in $G_2$ should + produce a minimal Sturmian word where \texttt{0} and \texttt{1} are interchanged + in the word produced by removing $\texttt{0} \rightarrow \texttt{1}$. + + \vspace{2mm} + + If we remove $\texttt{1} \rightarrow \texttt{1}$ will produce minimal + Sturmian words where \texttt{0} and \texttt{1} are interchanged from the words + produced by removing $\texttt{0} \rightarrow \texttt{0}$. + +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + +\theorem{} +We can construct a minimal Sturmian word of order $n \geq 3$ as follows: +\begin{itemize} + \item Start with $G_2$, create $R_2$ by removing one edge. + \item Construct $\mathcal{L}(G_2)$, remove an edge if necessary. \par + The resulting graph must have an 4 edges and an Eulerian path. Call this $R_3$. + \item Repeat the previous step to construct a sequence of graphs $R_n$. \par + $R_{n-1}$ is used to create $R_n$, which has $n + 1$ edges and an Eulerian path. \par + Label edges with the last letter of their target vertex. + \item Construct a word $w$ using the Eulerian path, as before. \par + This is a minimal Sturmian word. +\end{itemize} +For now, assume this theorem holds. We'll prove it in the next few problems. + +\problem{} +Construct a minimal Sturmain word of order 4. + +\begin{solution} + Let $R_3$ be the graph below (see \ref{trysturmian}). + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (00) at (0, 0) {\texttt{00}}; + \node[main] (01) at (2, 1) {\texttt{01}}; + \node[main] (10) at (2, -1) {\texttt{10}}; + \node[main] (11) at (4, 0) {\texttt{11}}; + \end{scope} + + \draw[->] + (00) edge[loop left] node[label] {$0$} (00) + (10) edge[bend left] node[label] {$0$} (00) + (11) edge[bend left] node[label] {$0$} (10) + (11) edge[loop right] node[label] {$1$} (11) + ; + \end{tikzpicture} + \end{center} + + $R_4 = \mathcal{L}(R_3)$ is then as shown below, producing the + order $4$ minimal Sturman word \texttt{11110000}. Disconnected + nodes are omitted. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (000) at (0, 0) {\texttt{000}}; + \node[main] (100) at (2, 1) {\texttt{100}}; + \node[main] (110) at (2, -1) {\texttt{110}}; + \node[main] (111) at (4, 0) {\texttt{111}}; + \end{scope} + + \draw[->] + (000) edge[loop left] node[label] {$0$} (000) + (100) edge[bend right] node[label] {$0$} (000) + (110) edge[bend left] node[label] {$0$} (100) + (111) edge[bend left] node[label] {$0$} (110) + (11) edge[loop right] node[label] {$1$} (11) + ; + \end{tikzpicture} + \end{center} +\end{solution} + +\vfill +\pagebreak + +\problem{} +Construct a minimal Sturmain word of order 5. + +\begin{solution} + Use $R_4$ from \ref{sturmianfour} to construct $R_5$, shown below. \par + Disconnected nodes are omitted. + + \begin{center} + \begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (0000) at (0, 0) {\texttt{0000}}; + \node[main] (1000) at (2, 0) {\texttt{1000}}; + \node[main] (1100) at (4, 0) {\texttt{1100}}; + \node[main] (1110) at (6, 0) {\texttt{1110}}; + \node[main] (1111) at (8, 0) {\texttt{1111}}; + \end{scope} + + \draw[->] + (1111) edge[loop right] node[label] {$1$} (1111) + (1111) edge[bend right] node[label] {$0$} (1110) + (1110) edge[bend left] node[label] {$0$} (1100) + (1100) edge[bend right] node[label] {$0$} (1000) + (1000) edge[bend left] node[label] {$0$} (0000) + (0000) edge[loop left] node[label] {$0$} (0000) + ; + \end{tikzpicture} + \end{center} + This graph generates the minimal Sturmian word \texttt{1111100000} +\end{solution} + +\vfill +\pagebreak + + +\problem{} +Argue that the words we get by \ref{sturmanthm} are minimal Sturmain words. \par +That is, the word $w$ has length $2n$ and $\mathcal{S}_m(w) = m + 1$ for all $m \leq n$. + +\begin{solution} + We proceed by induction. \par + First, show that we can produce a minimal order 3 Sturmian word: \par + + \vspace{2mm} + + + $R_3$ is guaranteed to have four edges with length-$2$ node labels, + the length of $w$ is $2 \times 3 = 6$. \par + Trivially, we also have $\mathcal{S}_0 = 1$ and $\mathcal{S}_1 = 2$. \par + + \vspace{2mm} + + There are three vertices of $R_3$ given by the three remaining nodes of $R_2$. + Each length-2 subword of $w$ will be represented by the label of one of these + three nodes. Thus, $\mathcal{S}_2(w) \leq 3$. The line graph of a connected graph + is connected, so an Eulerian path on $R_3$ reaches every node. We thus have that + $\mathcal{S}_2(w) = 3$. + + \vspace{2mm} + + By construction, the length 3 subwords of $w$ are all distinct, so $\mathcal{S}_3(w) = 4$. + We thus conclude that $w$ is a minimal order 3 Sturmain word. + + \linehack{} + + Now, we prove our inductive step: \par + Assume that the process above produces an order $n-1$ minimal Sturmain word $w_{n-1}$. \par + We want to show that $w_n$ is also a minimal Sturmain word. \par + + \vspace{2mm} + + By construction, $R_n$ has node labels of length $n-1$ and $n+1$ edges. \par + Thus, $w_n$ has length $2n$. + + \vspace{2mm} + + The only possilble length-$m$ subwords of $w_n$ are those of $w_{n-1}$ for $m < n$. \par + The line graph of a connected graph is connected, so an Eulerian path on $R_3$ reaches each node. + Thus, all length-$m$ subwords of $w_{n-1}$ appear in $w_n$. + + \vspace{2mm} + + By our inductive hypothesis, $\mathcal{S}_m(w_n) = m + 1$ for $m < n$. \par + The length-$n$ subwords of $w_n$ are distinct by construction, and there are + $n+1$ such subwords. + + \vspace{2mm} + + Thus, $\mathcal{S}_n(w_n) = n + 1$. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/De Bruijn/tikzset.tex b/src/Advanced/De Bruijn/tikzset.tex new file mode 100644 index 0000000..d83fa32 --- /dev/null +++ b/src/Advanced/De Bruijn/tikzset.tex @@ -0,0 +1,65 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweak + >={Latex[ width=2mm, length=2mm ]}, + % + % Labels inside edges + label/.style = { + rectangle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none, + rounded corners = 0mm + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white, + line width = 0.35mm + }, + % + % Loop tweaks + loop above/.style = { + min distance = 2mm, + looseness = 8, + out = 45, + in = 135 + }, + loop below/.style = { + min distance = 5mm, + looseness = 10, + out = 315, + in = 225 + }, + loop right/.style = { + min distance = 5mm, + looseness = 10, + out = 45, + in = 315 + }, + loop left/.style = { + min distance = 5mm, + looseness = 10, + out = 135, + in = 215 + } +} \ No newline at end of file diff --git a/src/Advanced/Definable Sets/main.tex b/src/Advanced/Definable Sets/main.tex new file mode 100755 index 0000000..7ba8c33 --- /dev/null +++ b/src/Advanced/Definable Sets/main.tex @@ -0,0 +1,29 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +% for \coloneqq, a centered := +\usepackage{mathtools} +\usepackage{units} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Definable Sets} +\subtitle{Prepared by Mark on \today{}} + +\begin{document} + + \maketitle + + \input{parts/0 logic.tex} + \input{parts/1 structures.tex} + \input{parts/2 quantifiers.tex} + \input{parts/3 sets.tex} + \input{parts/4 equivalence.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Definable Sets/meta.toml b/src/Advanced/Definable Sets/meta.toml new file mode 100644 index 0000000..c071ab7 --- /dev/null +++ b/src/Advanced/Definable Sets/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Definable Sets" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Definable Sets/parts/0 logic.tex b/src/Advanced/Definable Sets/parts/0 logic.tex new file mode 100644 index 0000000..fb82d01 --- /dev/null +++ b/src/Advanced/Definable Sets/parts/0 logic.tex @@ -0,0 +1,173 @@ +\section{Logical Algebra} + +\definition{} +\textit{Logical operators} operate on the values $\{\texttt{true}, \texttt{false}\}$, \par +just like algebraic operators operate on numbers. \par +In this handout, we'll use the following operators: +\begin{itemize} + \item $\lnot$: not + \item $\land$: and + \item $\lor$: or + \item $\rightarrow$: implies + \item $()$: parenthesis. +\end{itemize} + +The function of these is defined by \textit{truth tables}: +\begin{center} +\begin{tabular}{ c | c | c } + \multicolumn{3}{ c }{and} \\ + \hline + $A$ & $B$ & $A \land B$ \\ + \hline + \texttt{F} & \texttt{F} & \texttt{F} \\ + \texttt{F} & \texttt{T} & \texttt{F} \\ + \texttt{T} & \texttt{F} & \texttt{F} \\ + \texttt{T}& \texttt{T} & \texttt{T} +\end{tabular} +\hfill +\begin{tabular}{ c | c | c } + \multicolumn{3}{ c }{or} \\ + \hline + $A$ & $B$ & $A \lor B$ \\ + \hline + \texttt{F} & \texttt{F} & \texttt{F} \\ + \texttt{F} & \texttt{T} & \texttt{T} \\ + \texttt{T} & \texttt{F} & \texttt{T} \\ + \texttt{T} & \texttt{T} & \texttt{T} +\end{tabular} +\hfill +\begin{tabular}{ c | c | c } + \multicolumn{3}{ c }{implies} \\ + \hline + $A$ & $B$ & $A \rightarrow B$ \\ + \hline + \texttt{F} & \texttt{F} & \texttt{T} \\ + \texttt{F} & \texttt{T} & \texttt{T} \\ + \texttt{T} & \texttt{F} & \texttt{F} \\ + \texttt{T} & \texttt{T} & \texttt{T} +\end{tabular} +\hfill +\begin{tabular}{ c | c } + \multicolumn{2}{ c }{not} \\ + \hline + $A$ & $\lnot A$ \\ + \hline + \texttt{T} & \texttt{F} \\ + \texttt{F} & \texttt{T} \\ + ~ & ~ \\ + ~ & ~ \\ +\end{tabular} +\end{center} + +\vspace{2mm} + +$A \land B$ is \texttt{true} only if both $A$ and $B$ are \texttt{true}. $A \lor B$ is \texttt{true} if $A$ or $B$ (or both) are \texttt{true}. \par +$\lnot A$ is the opposite of $A$, which is why it looks like a \say{negative} sign. \par + +\vspace{2mm} + +$A \rightarrow B$ is a bit harder to understand. Read aloud, this is \say{$A$ implies $B$.} \par +The only time $\rightarrow$ produces \texttt{false} is when $\texttt{true} \rightarrow \texttt{false}$. +This fact may seem counterintuitive, but will make more sense as we progress through this handout. \par +\hint{ + Think about it---if event $\alpha$ implies $\beta$, it is impossible for $\alpha$ to occur without $\beta$. \par + This is the only impossibility. All other variants are valid. +} + +\problem{} +Evaluate the following. +\begin{itemize} + \item $\lnot \texttt{T}$ + \item $\texttt{F} \lor \texttt{T}$ + \item $\texttt{T} \land \texttt{T}$ + \item $(\texttt{T} \land \texttt{F}) \lor \texttt{T}$ + \item $(\lnot (\texttt{F} \lor \lnot \texttt{T}) ) \rightarrow \lnot \texttt{T}$ + \item $(\texttt{F} \rightarrow \texttt{T}) \rightarrow (\lnot \texttt{F} \lor \lnot \texttt{T})$ +\end{itemize} + +\begin{solution} + \texttt{F} + \texttt{T} + \texttt{T} + \texttt{T} + \texttt{F} + \texttt{T} +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + +\begin{instructornote} + We can also think of $[x \geq 0] \rightarrow b$ as follows: + if $x$ isn't the kind of object we care about, we evaluate true and + check the next one. If $x$ \textit{is} the kind of object we care about + and $b$ is false, we have a counterexample to $[x \geq 0] \rightarrow b$, + and thus $\texttt{T} \rightarrow \texttt{F}$ must be false. + + + \vspace{2mm} + + Say we have the sentence $\forall x ~ (a \rightarrow b)$. \par + For example, take $\varphi = \forall x ~ ([x \geq 0] \rightarrow [\exists y ~ y^2 = x])$. \par + $\varphi$ holds whenever any positive $x$ has a square root. + + \vspace{2mm} + + If $(\text{F} \rightarrow *)$ returned false, statements like the above would be hard to write. \par + If $x$ is negative, $\varphi$ doesn't care whether or not it has a root. In this case, $\text{F} \rightarrow *$ must be true to avoid making whole $\forall$ false. +\end{instructornote} + + +\problem{} +Evaluate the following. +\begin{itemize} + \item $A \rightarrow \texttt{T}$ for any $A$ + \item $(\lnot (A \rightarrow B)) \rightarrow A$ for any $A, B$ + \item $(A \rightarrow B) \rightarrow (\lnot B \rightarrow \lnot A)$ for any $A, B$ +\end{itemize} + +\begin{instructornote} + Note that the last formula is the contrapositive of $A \rightarrow B$. +\end{instructornote} + +\begin{solution} + All are true. +\end{solution} + +\vfill + +% Show that A -> B ^ B -> A = T iff A = B + +\problem{} +Show that $\lnot (A \rightarrow \lnot B)$ is equivalent to $A \land B$. \par +That is, show that these expressions always evaluate to the same value given +the same $A$ and $B$. \par +\hint{Use a truth table} + +\vfill + +\problem{} +Write an expression equivalent to $A \lor B$ using only $\lnot$, $\rightarrow$, and $()$? + +\begin{solution} + $((\lnot A) \rightarrow B)$ +\end{solution} + +\vfill + +Note that both $\land$ and $\lor$ can be defined using the other logical symbols. \par +The only logical symbols we \textit{need} are $\lnot$, $\rightarrow$, and $()$. \par +We include $\land$ and $\lor$ to simplify our expressions. + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Definable Sets/parts/1 structures.tex b/src/Advanced/Definable Sets/parts/1 structures.tex new file mode 100644 index 0000000..8929f15 --- /dev/null +++ b/src/Advanced/Definable Sets/parts/1 structures.tex @@ -0,0 +1,202 @@ +\section{Structures} + +\definition{} +A \textit{universe} is a set of meaningless objects. Here are a few examples: +\begin{itemize} + \item $\{a, b, ..., z\}$ + \item $\{0, 1\}$ + \item $\mathbb{Z}$, $\mathbb{R}$, etc. +\end{itemize} + +\definition{} +A \textit{structure} consists of a universe and a set of \textit{symbols}. \par +A structure's symbols give meaning to the objects in its universe. + +\vspace{2mm} + +Symbols come in three types: +\begin{itemize} + \item \textit{Constant symbols}, which let us specify specific elements of our universe. \par + Examples: $0, 1, \frac{1}{2}, \pi$ + \vspace{2mm} + + \item \textit{Function symbols}, which let us navigate between elements of our universe. \par + Examples: $+, \times, \sin{x}, \sqrt{x}$ \par + \note{Note that symbols we usually call \say{operators} are functions under this definition. \par + The only difference between $a + b$ and $+(a, b)$ is notation.} + \vspace{2mm} + + \item \textit{Relation symbols}, which let us compare elements of our universe. \par + Examples: $<, >, \leq, \geq$ \par + \vspace{2mm} +\end{itemize} + +The equality check $=$ is \textit{not} a relation symbol. It is included in every structure by default. \par +By definition, $a = b$ is true if and only if $a$ and $b$ are the same element of our universe. + + +\vspace{3mm} + + +\example{} +The first structure we'll look at is the following: +$$ + \Bigl( \mathbb{Z} ~\big|~ \{0, 1, +, -, <\} \Bigr) +$$ + +\vspace{2mm} + +This is a structure over the universe $\mathbb{Z}$ that provides the following symbols: +\begin{itemize} + \item Constants: \tab $\{0, 1\}$ + \item Functions: \tab $\{+, -\}$ + \item Relations: \tab $\{<\}$ +\end{itemize} + +\vspace{2mm} + +If we look at our set of constant symbols, we see that the only integers +we can directly refer to in this structure are 0 and 1. If we want any +others, we must define them using the tools this structure offers. + +\vspace{2mm} + +% NOTE: this is a great example for typesetting. +% The line breaks here are ugly without a centered sentence. +To \say{define} an element of a set, we need to write a sentence that is only true for that element. \par +If we want to define 2 in the structure above, +we could use the following sentence: +\begin{center} + \say{$2$ is the $x$ that satisfies $[1 + 1 = x]$.} \par +\end{center} +This is a valid definition because $2$ is the \textit{only} element of $\mathbb{Z}$ for which $[1 + 1 = x]$ +evaluates to \texttt{true}. + + +\problem{} +Define $-1$ in $\Bigl( \mathbb{Z} ~\big|~ \{0, 1, +, -, <\} \Bigr)$. + +\begin{solution} + The sentences \say{$x$ where $[x + 1 = 0]$} and \say{$x$ where $[0 - 1 = x]$} both work. +\end{solution} + +\vfill +\pagebreak + + + + + + + +Let us formalize what we found in the previous two problems. \par + +\definition{Formulas} +A \textit{formula} in a structure $S$ is a well-formed string +of constants, functions, relations, \par and logical operators. + +\vspace{2mm} + +You already know what a \say{well-formed string} is: $1 + 1$ is fine, $\sqrt{+}$ is nonsense. \par +For the sake of time, I will not provide a formal definition --- it isn't particularly interesting. + +\vspace{2mm} + +As a quick example, the formula $\psi \coloneqq [\lnot (1 = 1)]$ is always false, \par +and $\varphi(x) \coloneqq [1 + 1 = x]$ evaluates to \texttt{true} only when $x$ is 2. + + + + + +\definition{Free Variables} +A formula can contain one or more \textit{free variables.} These are denoted $\varphi{(a, b, ...)}$. \par +Formulas with free variables let us define \say{properties} that certain objects have. + +\vspace{2mm} + +For example, consider the two formulas from the previous definition, $\psi$ and $\varphi$: +\begin{itemize} + \item $\psi \coloneqq [\lnot (1 = 1)]$ \par + There are no free variables in this formula. \par + In any structure, $\psi$ is always either \texttt{true} or \texttt{false}. + + \vspace{2mm} + + \item $\varphi(x) \coloneqq [1 + 1 = x]$ \par + This formula has one free variable, labeled $x$. \par + The value of $\varphi(x)$ depends on the $x$ we're talking about: \par + $\varphi(72)$ is false, and $\varphi(2)$ is true. +\end{itemize} + +\vspace{2mm} + +\note{ + This \say{free variable} notation is very similar to the function notation we are used to: \par + The values of both $\varphi(x) \coloneqq [x > 0]$ and $f(x) = x + 1$ depend on $x$. +} + + + + +\definition{Definable Elements} +Let $S$ be a structure over a universe $U$. \par +We say an element $x \in U$ is \textit{definable in $S$} if we can write a formula $\varphi(x)$ that only $x$ satisfies. + + +\problem{} +Define 2 in the structure $\Bigl( \mathbb{Z^+} ~\big|~ \{4, \times \} \Bigr)$. \par +\hint{$\mathbb{Z}^+ = \{1, 2, 3, ...\}$. Also, $2 \times 2 = 4$.} + +\begin{solution} + $2$ is the only element in $\mathbb{Z}^+$ that satisfies $\varphi(x) \coloneqq [x \times x = 4]$. +\end{solution} + + +\vfill +\pagebreak + + + + + + +\problem{} +Try to define 2 in the structure $\Bigl( \mathbb{Z} ~\big|~ \{4, \times \} \Bigr)$. \par +Why can't you do it? + +\begin{solution} + We could try $\varphi(x) \coloneqq [x \times x = 4]$, but this is satisfied by both $2$ and $-2$. \par + We have no way to distinguish between negative and positive numbers. \par + + \note{This problem is intentionally hand-wavy. We don't have the tools to write a proper proof.} + + \begin{instructornote} + Actually, it is. Bonus problem: how? \par + Do this after understanding quantifiers. + \end{instructornote} +\end{solution} + +\vfill + + +\problem{} +Consider the structure $\Bigl( \mathbb{R}^+_0 ~\big|~ \{1, 2, \div \} \Bigr)$ + +\begin{itemize} + \item Define $2^2$ + \item Define $2^n$ for all positive integers $n$ + \item Define $2^{-n}$ for all positive integers $n$ + + \item What other numbers can we define in this structure? \par + \hint{There is at least one more \say{class} of numbers we can define.} +\end{itemize} + + +\begin{solution} + As far as I've seen, we can define any $2^{\nicefrac{a}{b}}$ for $a, b \in \mathbb{Z}$. \par + For example, $\phi(x) \coloneqq [2 = x \div (1 \div x)]$ defines $\sqrt{2}$. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Definable Sets/parts/2 quantifiers.tex b/src/Advanced/Definable Sets/parts/2 quantifiers.tex new file mode 100644 index 0000000..8d0362d --- /dev/null +++ b/src/Advanced/Definable Sets/parts/2 quantifiers.tex @@ -0,0 +1,139 @@ +\section{Quantifiers} + +Recall the logical symbols we introduced earlier: $(), \land, \lor, \lnot, \rightarrow$ \par +We will now add two more: $\forall$ (for all) and $\exists$ (exists). + +\definition{} +$\forall$ and $\exists$ are \textit{quantifiers}. They allow us to make statements about arbitrary symbols. \par +\note{Quantifiers are aptly named: they tell us \textit{how many} symbols satisfy a certain sentence.} + + +\vspace{2mm} + +Let's look at $\forall$ first. If $\varphi(x)$ is a formula, \par +the formula $\forall x ~ \varphi(x)$ is true only if $\varphi$ is true for all $x$ in our universe. + +\vspace{1mm} + +For example, take the formula $\forall x ~ (0 < x)$. \par +In English, this means \say{For any $x$, $x$ is bigger than zero,} or simply \say{Any $x$ is positive.} + +\vspace{3mm} + +$\exists$ is very similar: the formula $\exists x ~ \varphi(x)$ is true if there is at least one $x$ for which $\varphi(x)$ is true. \par +For example, $\exists ~ (0 < x)$ means \say{there is a positive number in our set.} + +\vspace{4mm} + +\problem{} +Which of the following are true in $\mathbb{Z}$? Which are true in $\mathbb{R}^+_0$? \par +\note{$\mathbb{R}^+_0$ is the set of positive real numbers and zero.} + +\begin{itemize}[itemsep = 1mm] + \item $\forall x ~ (x \geq 0)$ + \item $\lnot (\exists x ~ (x = 0))$ + \item $\forall x ~ [\exists y ~ (y \times y = x)]$ + \item $\forall xy ~ \exists z ~ (x < z < y)$ \tab + \note{This is a compact way to write $\forall x ~ (\forall y ~ (\exists z ~ (x < z < y)))$} + \item $\lnot \exists x ~ ( \forall y ~ (x < y) )$ +\end{itemize} + +\begin{solution} + \begin{itemize} + \item \say{all $x$ are positive} \tab $\mathbb{R}^+_0$ + \item \say{zero doesn't exist} \tab neither + \item \say{square roots exist} \tab $\mathbb{R}^+_0$ + \item \say{this set is dense} \tab\null\tab $\mathbb{R}^+_0$ + \item \say{there is no minimum} \tab $\mathbb{Z}$ + \end{itemize} +\end{solution} + +%\begin{examplesolution} +% Here is a solution to the last part: $\lnot \exists x ~ ( \forall y ~ (x < y) )$ \par +% +% \vspace{4mm} +% +% Reading this term-by-term, we get \tab \say{not exists $x$ where (for all $y$ ($x$ smaller than $y$))} \par +% If we add some grammar, we get \tab \say{There isn't an $x$ where all $y$ are bigger than $x$} \par +% which we can rephrase as \tab~\tab \say{There isn't a minimum value} \par +% +% \vspace{4mm} +% +% Which is true in $\mathbb{Z}$ and false in $\mathbb{R}^+_0$ +%\end{examplesolution} + + +\vfill +\pagebreak + + + + + + + + + + +\problem{} +Does the order of $\forall$ and $\exists$ in a formula matter? \par +What's the difference between $\exists x ~ \forall y ~ (x \leq y)$ and $\forall y ~ \exists x ~ (x \leq y)$? \par +\hint{ + Consider $\mathbb{R}^+$\hspace{-1.3ex},\hspace{0.8ex} the set of positive reals. Zero is not positive. \par + Which of the above formulas is true in $\mathbb{R}^+$\hspace{-1.3ex},\hspace{0.8ex} and which is false? +} + +\begin{solution} + If $\exists x$ is inside $\forall y$, $x$ depends on $y$. We may pick a different value of $x$ for every $y$. \par + If $\exists x$ is outside, $x$ is fixed \textit{before} we check all $y$. +\end{solution} + + +\vfill + +\problem{} +Define 0 in $\Bigl( \mathbb{Z} ~\big|~ \{\times\} \Bigr)$ + +\begin{solution} + $\varphi(x) \coloneqq \bigl[~ \forall y ~ x \times y = x ~\bigr]$ +\end{solution} + +\vfill + + +\problem{} +Define 1 in $\Bigl( \mathbb{Z} ~\big|~ \{\times\} \Bigr)$ + +\begin{solution} + $\varphi(x) \coloneqq \bigl[~ \forall y ~ x \times y = y ~\bigr]$ +\end{solution} + + +\vfill +\pagebreak + + +\problem{} +Define $-1$ in $\Bigl( \mathbb{Z} ~\big|~ \{0, <\} \Bigr)$ + +\begin{solution} + $\varphi(x) \coloneqq \bigl[~ (x<0) \land \lnot \exists y ~ (x < y < 0) ~\bigr]$ +\end{solution} + +\vfill + +%\problem{} +%Define $2$ in $\Bigl( \mathbb{Z} ~\big|~ \{0, <\} \Bigr)$ + +%\vfill + +\problem{} +Let $\varphi(x)$ be a formula. \par +Write a formula equivalent to $\forall x ~ \varphi(x)$ using only logical symbols and $\exists$. + +\begin{solution} + $\forall x ~ \varphi(x)$ is true if and only if $\lnot \exists x ~ \lnot \varphi(x)$ is true. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Definable Sets/parts/3 sets.tex b/src/Advanced/Definable Sets/parts/3 sets.tex new file mode 100644 index 0000000..09af3d4 --- /dev/null +++ b/src/Advanced/Definable Sets/parts/3 sets.tex @@ -0,0 +1,213 @@ +\section{Definable Sets} + +Armed with $(), \land, \lor, \lnot, \rightarrow, \forall,$ and $\exists$, we have the tools to define sets. + +\definition{Set-Builder Notation} +Say we have a sentence $\varphi(x)$. \par +The set of all elements that satisfy that sentence may be written as follows: +\begin{equation*} + \{ x ~|~ \varphi(x) \} +\end{equation*} +This is read \say{The set of $x$ where $\varphi$ is true} or \say{The set of $x$ that satisfy $\varphi$.} + +\vspace{2mm} + +For example, take the formula $\varphi(x) = \exists y ~ (y + y = x)$. \par +The set of all even integers can then be written as +$$ + \{ x ~|~ \exists y ~ (y + y = x) \} +$$ + +\definition{Definable Sets} +Let $S$ be a structure with a universe $U$. \par +We say a subset $M$ of $U$ is \textit{definable} if we can write a formula \par +that is true for some $x$ if and only if $M$ contains $x$. + +\vspace{4mm} + +For example, consider the structure $\bigl( \mathbb{Z} ~\big|~ \{+\} \bigr)$. \par +Only even numbers satisfy the formula $\varphi(x) \coloneqq \bigl[\exists y ~ (y + y = x)\bigr]$, \par +so we can define \say{the set of even numbers} as $\{ x ~|~ \exists y ~ (y + y = x) \}$. \par +Remember---we can only use symbols that are available in our structure! + +\problem{} +The empty set is definable in any structure. How? +\begin{solution} + Always: $\{ x ~|~ \lnot (x = x) \}$ +\end{solution} + +\vfill + + +\problem{} +Define $\{0, 1\}$ in $\Bigl( \mathbb{Z}^+_0 ~\big|~ \{<\} \Bigr)$ +\hint{Define 0 and 1 as elements first, and remember that we can use logical symbols.} + +\begin{solution} + $\varphi_0(x) \coloneqq \bigl[~ \lnot \exists y ~ y < x ~\bigr]$ \par + $\varphi_1(x) \coloneqq \bigl[~ (0 < x) ~\land~ \lnot \exists y ~ (x < y < 0) ~\bigr]$ + + \vspace{2mm} + + Our final solution is $\{ x ~|~ \varphi_0(x) \lor \varphi_1(x) \}$. + + \note{A finite set of definable elements is always definable. \par + An infinite set of definable elements might not be definable.} +\end{solution} + + +\vfill + +\problem{} +Define the set of prime numbers in $\Bigl( \mathbb{Z} ~\big|~ \{\times, \div, <\} \Bigr)$. \par +\hint{A prime number is an integer that is positive and is only divisible by 1 and itself.} + +\begin{solution} + $\psi(x) \coloneqq \bigl[~ \exists y ~ (0 +\texttt{978-0-08-2066-46-6} was a valid ISBN until I changed a single digit. \par +Can you find the digit I changed? Can you recover the original ISBN? + +\begin{solution} + Nope, unless you look at the meaning of each digit in the spec. \par + If you're unlucky, maybe not even then. +\end{solution} + + +\vfill +\pagebreak diff --git a/src/Advanced/Error-Correcting Codes/parts/01 correction.tex b/src/Advanced/Error-Correcting Codes/parts/01 correction.tex new file mode 100644 index 0000000..72d183b --- /dev/null +++ b/src/Advanced/Error-Correcting Codes/parts/01 correction.tex @@ -0,0 +1,134 @@ +\section{Error Correction} + +As we saw in \ref{isbn-nocorrect}, the ISBN check-digit scheme does not allow us to correct errors. \par +QR codes feature a system that does. \par + +\vspace{1mm} + +Odds are, you've seen a QR code with an image in the center. Such codes aren't \say{special}---they're simply missing their central pixels. The error-correcting algorithm in the QR specification allows us to read the code despite this damage. +\begin{figure}[h] + \centering + \href{https://youtube.com/watch?v=dQw4w9WgXcQ}{\includegraphics[width = 3cm]{qr}} +\end{figure} + +\definition{Repeating codes} +The simplest possible error-correcting code is a \textit{repeating code}. It works just as you'd expect: \par +Instead of sending data once, it sends multiple copies of each bit. \par +If a few bits are damaged, they can be both detected and repaired. \par + +For example, consider the following three-repeat code encoding the binary string $101$: + +$$ + 111~000~111 +$$ + +If we flip any one bit, we can easily find and fix the error. + +\problem{} +How many repeated digits do you need to... +\begin{itemize} + \item[-] detect a transposition error? + \item[-] correct a transposition error? +\end{itemize} + +\vfill + + +\definition{Code Efficiency} +The efficiency of an error-correcting code is calculated as follows: +$$ +\frac{\text{number of data bits}}{\text{total bits sent}} +$$ + +For example, the efficiency of the three-repeat code above is $\frac{3}{9} = \frac{1}{3} \approx 0.33$ + +\problem{} +What is the efficiency of a $k$-repeat code? + +\vfill + +As you just saw, repeat codes are not a good solution. You need many extra bits for even a small amount of redundancy. We need a better system. + +\pagebreak + +%\definition{Hamming's Square Code} +%We will now analyze a more efficient coding scheme: \par +% +%\vspace{1mm} +% +%Take a four-bit message and arrange it in a $2 \times 2$ square. \par +%Compute the pairity of each row and write it at the right. \par +%Compute the pairity of each column and write it at the bottom. \par +%Finally, compute the pairity of the entire message write it in the lower right corner. +%This ensures that the total number of ones in the message is even. +% +%\vspace{2mm} +% +%Reading the result row by row to get the encoded message. \par +%For example, the message 1011 generates the sequence 101110011: +% +%$$ +%1011 +%\longrightarrow +%\begin{array}{cc|} +% 1 & 0 \\ +% 1 & 1 \\ +% \hline +%\end{array} +%\longrightarrow +%\begin{array}{cc|c} +% 1 & 0 & 1 \\ +% 1 & 1 & 0 \\ \hline +% 0 & 1 & +%\end{array} +%\longrightarrow +%\begin{array}{cc|c} +% 1 & 0 & 1 \\ +% 1 & 1 & 0 \\ \hline +% 0 & 1 & 1 +%\end{array} +%\longrightarrow +%101110011 +%$$ +% +%\problem{} +%The following messages are encoded using the method above. +%Find and correct any single-digit or transposition errors. +%\begin{enumerate} +% \item \texttt{110 110 011} %101110011 +% \item \texttt{100 101 011} %110101011 +% \item \texttt{001 010 110} %000110110 +%\end{enumerate} +% +%\begin{solution} +% \begin{enumerate} +% \item \texttt{101 110 011} or \texttt{110 101 011} +% \item \texttt{110 101 011} +% \item \texttt{000 110 110} +% \end{enumerate} +%\end{solution} +% +%\vfill +% +%\problem{} +%What is the efficiency of this coding scheme? +% +%\vfill +% +%\problem{} +%Can we correct a single-digit error in the encoded message? \par +%Can we correct a transposition error in the encoded message? +% +%\vfill +% +%\problem{} +%Let's generalize this coding scheme to a non-square table: \par +%Given a message of length $ab$, construct a rectangle with dimensions $a \times b$ as described above. +%\begin{itemize} +% \item What is the efficiency of a $a \times b$ rectangle code? +% \item Can the $a \times b$ rectangle code detect and fix single-bit errors? +% \item Can the $a \times b$ rectangle code detect and fix two-bit errors? +%\end{itemize} +% +%\vfill +%\pagebreak diff --git a/src/Advanced/Error-Correcting Codes/parts/02 hamming.tex b/src/Advanced/Error-Correcting Codes/parts/02 hamming.tex new file mode 100644 index 0000000..89b29b7 --- /dev/null +++ b/src/Advanced/Error-Correcting Codes/parts/02 hamming.tex @@ -0,0 +1,577 @@ +\section{Hamming Codes} + +Say we have a 16-bit message, for example \texttt{1011 0101 1101 1001}. \par +We will number its bits in binary, from left to right: + + +\begin{center} +\begin{tikzpicture} + + \node[anchor=west] at (-1.75, 0) {Bit}; + \node[anchor=west] at (-1.75, -0.5) {Index}; + + \node at (0, 0) {\texttt{1}}; + \node at (1, 0) {\texttt{0}}; + \node at (2, 0) {\texttt{1}}; + \node at (3, 0) {\texttt{1}}; + \node at (4, 0) {\texttt{0}}; + \node at (5, 0) {\texttt{1}}; + \node at (6, 0) {\texttt{0}}; + \node at (7, 0) {\texttt{1}}; + + \draw (-1.75, 0.25) -- (6.9, 0.25); + \draw (-1.75, -0.25) -- (6.9, -0.25); + \draw (-1.75, -0.75) -- (6.9, -0.75); + + \foreach \x in {-1.75,-0.5,0.5,...,6.5} { + \draw (\x, 0.25) -- (\x, -0.75); + } + + \node[color=gray] at (0, -0.5) {\texttt{0000}}; + \node[color=gray] at (1, -0.5) {\texttt{0001}}; + \node[color=gray] at (2, -0.5) {\texttt{0010}}; + \node[color=gray] at (3, -0.5) {\texttt{0011}}; + \node[color=gray] at (4, -0.5) {\texttt{0100}}; + \node[color=gray] at (5, -0.5) {\texttt{0101}}; + \node[color=gray] at (6, -0.5) {\texttt{0110}}; + \node[color=gray] at (7, -0.5) {\texttt{0111}}; + + + \draw[fill = white, draw = none] + (6.9, 0.25) + -- (7.1, 0) + -- (6.9, -0.25) + -- (7.1, -0.5) + -- (6.9, -0.75) + -- (7.5, -0.75) + -- (7.5, 0.25) + ; + + \draw (6.9, 0.25) + -- (7.1, 0) + -- (6.9, -0.25) + -- (7.1, -0.5) + -- (6.9, -0.75) + ; + + + \node[anchor=west,color=gray] at (7.2, -0.25) { and so on...}; + +\end{tikzpicture} +\end{center} + + +\problem{} +In this 16-bit message, how many message bits have an index with a one as the last digit? \par +(i.e, an index that looks like \texttt{***1}) + +\vspace{2cm} + +\problem{} +Say we number the bits in a 32-bit message as above. \par +How many message bits have an index with a one as the $n^\text{th}$ digit? \par + +\vspace{2cm} + + + + +We now want a way to detect errors in our 16-bit message. To do this, we'll replace a few data bits with parity bits. This will reduce the amount of information we can send, but will also improve our error-detection capabilities. + +\vspace{1mm} + +Let's arrange our message in a grid. We'll make the first bit (currently empty, marked \texttt{X}) a parity bit. Its value will depend on the content of the message: if our message has an even number of ones, it will be zero; if our message has an odd number of ones, it will be one. \par +This first bit ensures that there is an even number of ones in the whole message. + +\begin{center} +\hfill +\begin{tikzpicture}[scale = 1.25] + \node at (0.75, 0.5) {Bit Numbering}; + + \node at (0.0, 0) {\texttt{0}}; + \node at (0.5, 0) {\texttt{1}}; + \node at (1.0, 0) {\texttt{2}}; + \node at (1.5, 0) {\texttt{3}}; + + \node at (0.0, -0.5) {\texttt{4}}; + \node at (0.5, -0.5) {\texttt{5}}; + \node at (1.0, -0.5) {\texttt{6}}; + \node at (1.5, -0.5) {\texttt{7}}; + + \node at (0.0, -1) {\texttt{8}}; + \node at (0.5, -1) {\texttt{9}}; + \node at (1.0, -1) {\texttt{10}}; + \node at (1.5, -1) {\texttt{11}}; + + \node at (0.0, -1.5) {\texttt{12}}; + \node at (0.5, -1.5) {\texttt{13}}; + \node at (1.0, -1.5) {\texttt{14}}; + \node at (1.5, -1.5) {\texttt{15}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale = 1.25] + \node at (0.75, 0.5) {Sample Message}; + + \node at (0.0, 0) {\texttt{X}}; + \node at (0.5, 0) {\texttt{0}}; + \node at (1.0, 0) {\texttt{1}}; + \node at (1.5, 0) {\texttt{1}}; + + \node at (0.0, -0.5) {\texttt{0}}; + \node at (0.5, -0.5) {\texttt{1}}; + \node at (1.0, -0.5) {\texttt{0}}; + \node at (1.5, -0.5) {\texttt{1}}; + + \node at (0.0, -1) {\texttt{1}}; + \node at (0.5, -1) {\texttt{1}}; + \node at (1.0, -1) {\texttt{0}}; + \node at (1.5, -1) {\texttt{1}}; + + \node at (0.0, -1.5) {\texttt{1}}; + \node at (0.5, -1.5) {\texttt{0}}; + \node at (1.0, -1.5) {\texttt{0}}; + \node at (1.5, -1.5) {\texttt{1}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw (-0.2,-0.2) -- (0.2, -0.2) -- (0.2, 0.2) -- (-0.2, 0.2) -- (-0.2,-0.2); +\end{tikzpicture} +\hfill~ +\end{center} + +\problem{} +What is the value of the parity bit in the message above? + +\vfill + +\problem{} +Can this coding scheme detect a transposition error? \par +Can this coding scheme detect two single-bit errors? \par +Can this coding scheme correct a single-bit error? + +\vfill +\pagebreak + +We'll now add four more parity bits, in positions \texttt{0001}, \texttt{0010}, \texttt{0100}, and \texttt{1000}: + +\begin{center} +\begin{tikzpicture}[scale = 1.25] + \node at (0.0, 0) {\texttt{X}}; + \node at (0.5, 0) {\texttt{X}}; + \node at (1.0, 0) {\texttt{X}}; + \node at (1.5, 0) {\texttt{1}}; + + \node at (0.0, -0.5) {\texttt{X}}; + \node at (0.5, -0.5) {\texttt{1}}; + \node at (1.0, -0.5) {\texttt{0}}; + \node at (1.5, -0.5) {\texttt{1}}; + + \node at (0.0, -1) {\texttt{X}}; + \node at (0.5, -1) {\texttt{1}}; + \node at (1.0, -1) {\texttt{0}}; + \node at (1.5, -1) {\texttt{1}}; + + \node at (0.0, -1.5) {\texttt{1}}; + \node at (0.5, -1.5) {\texttt{0}}; + \node at (1.0, -1.5) {\texttt{0}}; + \node at (1.5, -1.5) {\texttt{1}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw (0 - 0.2, 0 - 0.2) + -- (0 + 0.2, 0 - 0.2) + -- (0 + 0.2, 0 + 0.2) + -- (0 - 0.2, 0 + 0.2) + -- (0 - 0.2, 0 - 0.2); + \draw (0.5 - 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 - 0.2); + \draw (1 - 0.2, 0 - 0.2) + -- (1 + 0.2, 0 - 0.2) + -- (1 + 0.2, 0 + 0.2) + -- (1 - 0.2, 0 + 0.2) + -- (1 - 0.2, 0 - 0.2); + \draw (0 - 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 - 0.2); + \draw (0 - 0.2, -1 - 0.2) + -- (0 + 0.2, -1 - 0.2) + -- (0 + 0.2, -1 + 0.2) + -- (0 - 0.2, -1 + 0.2) + -- (0 - 0.2, -1 - 0.2); +\end{tikzpicture} +\end{center} + + +Bit \texttt{0001} will count the parity of all bits with a one in the first digit of their index. \par +Bit \texttt{0010} will count the parity of all bits with a one in the second digit of their index. \par +Bits \texttt{0100} and \texttt{1000} work in the same way. \par +\hint{In \texttt{0001}, \texttt{1} is the first digit. In \texttt{0010}, \texttt{1} is the second digit. \\ +When counting bits in binary numbers, go from right to left.} + +\problem{} +Which message bits does each parity bit cover? \par +In other words, which message bits affect the value of each parity bit? \par + +\vspace{1mm} + +Four diagrams are shown below. In each grid, fill in the bits that affect the shaded parity bit. + +\begin{center} + \hfill + \begin{tikzpicture}[scale = 1.25] + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw[pattern=north east lines] (0.5 - 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 - 0.2); + \end{tikzpicture} + \hfill + \begin{tikzpicture}[scale = 1.25] + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + + \draw[pattern=north east lines] (1 - 0.2, 0 - 0.2) + -- (1 + 0.2, 0 - 0.2) + -- (1 + 0.2, 0 + 0.2) + -- (1 - 0.2, 0 + 0.2) + -- (1 - 0.2, 0 - 0.2); + \end{tikzpicture} + \hfill + \begin{tikzpicture}[scale = 1.25] + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw[pattern=north east lines] (0 - 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 - 0.2); + \end{tikzpicture} + \hfill + \begin{tikzpicture}[scale = 1.25] + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw[pattern=north east lines] (0 - 0.2, -1 - 0.2) + -- (0 + 0.2, -1 - 0.2) + -- (0 + 0.2, -1 + 0.2) + -- (0 - 0.2, -1 + 0.2) + -- (0 - 0.2, -1 - 0.2); + \end{tikzpicture} + \hfill +\end{center} + + + +\problem{} +Compute all parity bits in the message above. + +\vfill +\pagebreak + + +\problem{} +Analyze this coding scheme. +\begin{itemize} + \item Can we detect one single-bit errors? + \item Can we detect two single-bit errors? + \item What errors can we correct? +\end{itemize} + +\vfill + +\problem{} +Each of the following messages has either 0, 1, or two errors. \par +Find the errors and correct them if possible. \par +\hint{Bit \texttt{0000} should tell you how many errors you have.} + +\begin{center} +\hfill +\begin{tikzpicture}[scale = 1.25] + \node at (0.0, 0) {\texttt{0}}; + \node at (0.5, 0) {\texttt{1}}; + \node at (1.0, 0) {\texttt{1}}; + \node at (1.5, 0) {\texttt{1}}; + + \node at (0.0, -0.5) {\texttt{0}}; + \node at (0.5, -0.5) {\texttt{1}}; + \node at (1.0, -0.5) {\texttt{1}}; + \node at (1.5, -0.5) {\texttt{1}}; + + \node at (0.0, -1) {\texttt{0}}; + \node at (0.5, -1) {\texttt{0}}; + \node at (1.0, -1) {\texttt{1}}; + \node at (1.5, -1) {\texttt{1}}; + + \node at (0.0, -1.5) {\texttt{1}}; + \node at (0.5, -1.5) {\texttt{1}}; + \node at (1.0, -1.5) {\texttt{1}}; + \node at (1.5, -1.5) {\texttt{0}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw (0 - 0.2, 0 - 0.2) + -- (0 + 0.2, 0 - 0.2) + -- (0 + 0.2, 0 + 0.2) + -- (0 - 0.2, 0 + 0.2) + -- (0 - 0.2, 0 - 0.2); + \draw (0.5 - 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 - 0.2); + \draw (1 - 0.2, 0 - 0.2) + -- (1 + 0.2, 0 - 0.2) + -- (1 + 0.2, 0 + 0.2) + -- (1 - 0.2, 0 + 0.2) + -- (1 - 0.2, 0 - 0.2); + \draw (0 - 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 - 0.2); + \draw (0 - 0.2, -1 - 0.2) + -- (0 + 0.2, -1 - 0.2) + -- (0 + 0.2, -1 + 0.2) + -- (0 - 0.2, -1 + 0.2) + -- (0 - 0.2, -1 - 0.2); +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale = 1.25] + \node at (0.0, 0) {\texttt{1}}; + \node at (0.5, 0) {\texttt{1}}; + \node at (1.0, 0) {\texttt{0}}; + \node at (1.5, 0) {\texttt{1}}; + + \node at (0.0, -0.5) {\texttt{1}}; + \node at (0.5, -0.5) {\texttt{0}}; + \node at (1.0, -0.5) {\texttt{1}}; + \node at (1.5, -0.5) {\texttt{0}}; + + \node at (0.0, -1) {\texttt{0}}; + \node at (0.5, -1) {\texttt{1}}; + \node at (1.0, -1) {\texttt{1}}; + \node at (1.5, -1) {\texttt{0}}; + + \node at (0.0, -1.5) {\texttt{1}}; + \node at (0.5, -1.5) {\texttt{1}}; + \node at (1.0, -1.5) {\texttt{0}}; + \node at (1.5, -1.5) {\texttt{1}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw (0 - 0.2, 0 - 0.2) + -- (0 + 0.2, 0 - 0.2) + -- (0 + 0.2, 0 + 0.2) + -- (0 - 0.2, 0 + 0.2) + -- (0 - 0.2, 0 - 0.2); + \draw (0.5 - 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 - 0.2); + \draw (1 - 0.2, 0 - 0.2) + -- (1 + 0.2, 0 - 0.2) + -- (1 + 0.2, 0 + 0.2) + -- (1 - 0.2, 0 + 0.2) + -- (1 - 0.2, 0 - 0.2); + \draw (0 - 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 - 0.2); + \draw (0 - 0.2, -1 - 0.2) + -- (0 + 0.2, -1 - 0.2) + -- (0 + 0.2, -1 + 0.2) + -- (0 - 0.2, -1 + 0.2) + -- (0 - 0.2, -1 - 0.2); +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale = 1.25] + \node at (0.0, 0) {\texttt{0}}; + \node at (0.5, 0) {\texttt{1}}; + \node at (1.0, 0) {\texttt{1}}; + \node at (1.5, 0) {\texttt{1}}; + + \node at (0.0, -0.5) {\texttt{1}}; + \node at (0.5, -0.5) {\texttt{0}}; + \node at (1.0, -0.5) {\texttt{1}}; + \node at (1.5, -0.5) {\texttt{1}}; + + \node at (0.0, -1) {\texttt{1}}; + \node at (0.5, -1) {\texttt{0}}; + \node at (1.0, -1) {\texttt{1}}; + \node at (1.5, -1) {\texttt{1}}; + + \node at (0.0, -1.5) {\texttt{1}}; + \node at (0.5, -1.5) {\texttt{0}}; + \node at (1.0, -1.5) {\texttt{0}}; + \node at (1.5, -1.5) {\texttt{0}}; + + \draw (-0.25, 0.25) -- (1.75, 0.25); + \draw (-0.25, -0.25) -- (1.75, -0.25); + \draw (-0.25, -0.75) -- (1.75, -0.75); + \draw (-0.25, -1.25) -- (1.75, -1.25); + \draw (-0.25, -1.75) -- (1.75, -1.75); + + \draw (-0.25, 0.25) -- (-0.25, -1.75); + \draw (0.25, 0.25) -- (0.25, -1.75); + \draw (0.75, 0.25) -- (0.75, -1.75); + \draw (1.25, 0.25) -- (1.25, -1.75); + \draw (1.75, 0.25) -- (1.75, -1.75); + + \draw (0 - 0.2, 0 - 0.2) + -- (0 + 0.2, 0 - 0.2) + -- (0 + 0.2, 0 + 0.2) + -- (0 - 0.2, 0 + 0.2) + -- (0 - 0.2, 0 - 0.2); + \draw (0.5 - 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 - 0.2) + -- (0.5 + 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 + 0.2) + -- (0.5 - 0.2, 0 - 0.2); + \draw (1 - 0.2, 0 - 0.2) + -- (1 + 0.2, 0 - 0.2) + -- (1 + 0.2, 0 + 0.2) + -- (1 - 0.2, 0 + 0.2) + -- (1 - 0.2, 0 - 0.2); + \draw (0 - 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 - 0.2) + -- (0 + 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 + 0.2) + -- (0 - 0.2, -0.5 - 0.2); + \draw (0 - 0.2, -1 - 0.2) + -- (0 + 0.2, -1 - 0.2) + -- (0 + 0.2, -1 + 0.2) + -- (0 - 0.2, -1 + 0.2) + -- (0 - 0.2, -1 - 0.2); +\end{tikzpicture} +\hfill +\end{center} + +\begin{solution} + \textbf{1:} Single error at position \texttt{1010} \par + \textbf{2:} Double error \par + \textbf{3:} No error \par +\end{solution} + + +\vfill +\pagebreak + + +\problem{} +How many parity bits does each message bit affect? \par +Does this correlate with that message bit's index? +\vfill + + +\problem{} +Say we have a message with exactly one single-bit error. \par +If we know which parity bits are inconsistent, how can we find where the error is? + +\vfill + +\problem{} +Can you generalize this system for messages of 4, 64, or 256 bits? + +\vfill + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Error-Correcting Codes/qr.png b/src/Advanced/Error-Correcting Codes/qr.png new file mode 100644 index 0000000..195d3e3 Binary files /dev/null and b/src/Advanced/Error-Correcting Codes/qr.png differ diff --git a/src/Advanced/Esoteric Languages/main.tex b/src/Advanced/Esoteric Languages/main.tex new file mode 100755 index 0000000..0fa8748 --- /dev/null +++ b/src/Advanced/Esoteric Languages/main.tex @@ -0,0 +1,52 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + nosolutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +% Factorial (print x! from x=0 onwards) +% >++++++++++>>>+>+[>>>+[-[<<<<<[+<<<<<]>>[[-]>[<<+>+>-]<[>+<-]<[>+<-[>+<-[> +% +<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>>>>+>+<<<<<<-[>+<-]]]]]]]]]]]>[<+>- +% ]+>>>>>]<<<<<[<<<<<]>>>>>>>[>>>>>]++[-<<<<<]>>>>>>-]+>>>>>]<[>++<-]<<<<[<[ +% >+<-]<<<<]>>[->[-]++++++[<++++++++>-]>>>>]<<<<<[<[>+>+<<-]>.<<<<<]>.>>>>] +% +% Same, fibonacci: +% >++++++++++>+>+[ +% [+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[ +% [-]<[>+<-]>>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- +% [>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]]]]]]+>>> +% ]<<< +% ] +% https://brainfuck.org/fib_explained.b +% +% Useful: +% https://brainfuck.org/ +% +% +% +++[[<+>>++<-]>] +% This sets up the tape in the format 3*n^2, which looks like +% 3 6 12 24 48 96 192 128 0 0 +% Why is this so important? +% Let's go down the list: +% - 3 and 6 are boring +% - 12: Close to 10 (newline) or 13 (carriage return). Can also be used for the counter for 0-9 +% - 24: Close to 26, the number of letters in the alphabet +% - 48: ASCII for 0 +% - 96: Close to 97, ASCII for a +% - 196 and 128: 196-128=64, close to 65, the ASCII for A. + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Esoteric Programming} +\subtitle{Prepared by Mark on \today} + +\begin{document} + \maketitle + + \input{parts/00 turing.tex} + \input{parts/01 befunge.tex} +\end{document} \ No newline at end of file diff --git a/src/Advanced/Esoteric Languages/meta.toml b/src/Advanced/Esoteric Languages/meta.toml new file mode 100644 index 0000000..f9d26e9 --- /dev/null +++ b/src/Advanced/Esoteric Languages/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Esoteric Languages" + +[publish] +handout = false +solutions = false diff --git a/src/Advanced/Esoteric Languages/parts/00 turing.tex b/src/Advanced/Esoteric Languages/parts/00 turing.tex new file mode 100755 index 0000000..0035db9 --- /dev/null +++ b/src/Advanced/Esoteric Languages/parts/00 turing.tex @@ -0,0 +1,159 @@ +\section{Turing} + +\definition{} +An \textit{esoteric programming language} is a programming language made for fun. \par +We'll work with two such languages today: \textit{Turing} and \textit{Befunge}. + +\definition{} +\textit{Turing} is one of the most famous esoteric languages, and is extremely minimalist. \par +It consists only of eight symbols, a data pointer, and an instruction pointer. + +Turing's eight symbols are as follows: +\begin{itemize}[itemsep=2mm] + \item \texttt{>} : move the instruction pointer right + \item \texttt{<} : move the instruction pointer left + \item \texttt{+} : increment the current memory cell + \item \texttt{-} : decrement the current memory cell + \item \texttt{.} : output the value of the current cell as a character + \item \texttt{,} : consume one character from input and store it at the current cell + \item \texttt{[} : Jump to the matching \texttt{]} if the current cell is zero. \par + otherwise, execute the next instruction. + \item \texttt{]} : Jump back to the matching \texttt{[} if the current cell is not zero. \par + otherwise, execute the next instruction. + \item All other characters are ignored. +\end{itemize} + +\problem{} +Go to \href{https://langs.betalupi.com/}{\texttt{langs.betalupi.com}} and open the Turing editor. \par +Clear the pre-set program in the left side of the screen and replace it with the following: +\begin{center} + \texttt{>+>++>+++>++++>+++++[[-]<]} +\end{center} + +\begin{itemize} + \item What does this program do? + \item What does the snippet \texttt{[-]} do? + \item Why is the first cell left as \texttt{0}? +\end{itemize} + +\vfill +\pagebreak + +\remark{} +Run the program \texttt{+[+]}. Notice that the cell's value \textit{wraps} +from \texttt{127} to \texttt{-128}! \par + +\vspace{2mm} + +Note that \texttt{[+]} has the same effect as \texttt{[-]}. + + +\vfill + +\problem{} +Write a program that moves the value of the current cell three cells to the right. + +\problem{} +Write a program that \textbf{copies} the value of the current cell into the next cell. + +\begin{solution} + Use a third \say{scratch} cell. +\end{solution} + +\problem{} +Write a program that adds the value of the first cell and the second cell, +leaving the result in the second cell. + +\problem{} +Solve \ref{bfadd} again, but multiply the two cells instead of adding. + +\problem{} +Write a program that computes the square of the current cell. + + +\vfill +\pagebreak + + +\definition{} +Turing uses ASCII to map numbers to characters. \par +You may use +\href{https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html}{\texttt{cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html}} +for reference. + +\vspace{5mm} + + +\problem{} +Write a program that prints the letter \texttt{a}. + +\problem{} +Write a program that prints the alphabet as shown below: \par +\begin{center} + \texttt{abcdefghijklmnopqrstuvwxyz} +\end{center} + +\problem{} +Modify your program so that it prints the alphabet with alternating case: +\begin{center} + \texttt{aBcDeFgHiJkLmNoPqRsTuVwXyZ} +\end{center} + +\problem{} +Write a program that repeats the user's input exactly as it is entered. +\begin{solution} + \texttt{,[.,]} +\end{solution} + +\problem{} +Write a program that repeats the user's input in reverse \par +\hint{You may use as many memory cells as you need---the editor will add more as you use them.} + + +\vfill +\pagebreak + + + +\problem{} +Write a program that prints \say{Hello World} + +\problem{} +Write a program that finds the first memory cell that is non-zero. + +\problem{} +Write a program that initializes the tape with the following sequence: +\begin{center} + \texttt{3 6 12 24 48 96 192 128 0} +\end{center} + +\problem{} +Write a program that decodes run-length encoding. +That is, it turns input like +\begin{center} + \texttt{a3j4k2d5} +\end{center} +into the decoded output +\begin{center} + \texttt{aaajjjjkkddddd} +\end{center} + + +\vfill + +\problem{Bonus} +Write a program that prints a Turing program that prints the original program's input. + +\problem{Bonus} +Write a program that outputs all squares between 0 and 400 %10,000 + +\problem{Bonus} +Write a program that prints the Fibonacci numbers + +\begin{solution} + \href{https://brainfuck.org/fib\_explained.b}{\texttt{https://brainfuck.org/fib\_explained.b}} +\end{solution} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Esoteric Languages/parts/01 befunge.tex b/src/Advanced/Esoteric Languages/parts/01 befunge.tex new file mode 100755 index 0000000..ecae011 --- /dev/null +++ b/src/Advanced/Esoteric Languages/parts/01 befunge.tex @@ -0,0 +1,127 @@ +\section{Befunge} + +\definition{} +\textit{Befunge} is another esoteric programming language, designed to be very difficult to compile. \par +It consists of a \say{field} of instructions, a two-dimensional program counter, and a stack of values. \par + +\vspace{2mm} + +The program counter starts in the top-left corner of the field, moving right. \par +It executes any instruction it encounters. +The instructions \texttt{>}, \texttt{<}, \texttt{\^}, and \texttt{v} can be used to direct the program counter, +and \texttt{\_} and \texttt{|} are used for control flow. + + + +\vfill + +An instruction reference is below: +\begin{itemize}[itemsep=2mm] + \item \texttt{+} Addition: Pop two values $a$ and $b$, then push the result of $a+b$ + \item \texttt{-} Subtraction: Pop two values $a$ and $b$, then push the result of $b-a$ + \item \texttt{*} Multiplication: Pop two values $a$ and $b$, then push the result of $a \times b$ + \item \texttt{/} Integer division: Pop two values $a$ and $b$, then push the result of $b \div a$, rounded down. + \item \texttt{\%} Modulo: Pop two values $a$ and $b$, then push the remainder of the integer division of $b \div a$. + \item \texttt{!} Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero. + \item \texttt{ \`} Greater than: Pop two values $a$ and $b$, then push 1 if $b>a$, otherwise zero. + \item \texttt{>} Program counter direction right + \item \texttt{<} Program counter direction left + \item \texttt{\textasciicircum} Program counter direction up + \item \texttt{v} Program counter direction down + \item \texttt{?} Random program counter direction + \item \texttt{\_} Horizontal \texttt{if}: pop a value; set direction to right if value=0, set to left otherwise + \item \texttt{|} Vertical \texttt{if}: pop a value; set direction to down if value=0, set to up otherwise + \item \texttt{"} Toggle string mode (push each character's ASCII value all the way up to the next ") + \item \texttt{:} Duplicate top stack value + \item \texttt{\textbackslash} Swap top stack values + \item \texttt{\$} Pop top of stack and discard + \item \texttt{.} Pop top of stack and output as integer + \item \texttt{,} Pop top of stack and output as ASCII character + \item \texttt{\#} Bridge: jump over next command in the current direction of the current PC + \item \texttt{g} A "get" call (a way to retrieve data in storage). Pop two values y and x, then push the ASCII value of the character at that position in the program. If (x,y) is out of bounds, push 0 + \item \texttt{p} A "put" call (a way to store a value for later use). Pop three values y, x and v, then change the character at the position (x,y) in the program to the character with ASCII value v + \item \texttt{\&} Get integer from user and push it + \item \texttt{\~{}} Get character from user and push it + \item \texttt{@} End program + \item \texttt{0}-\texttt{9} Push corresponding number onto the stack +\end{itemize} + +\vspace{2mm} + +Note that the \texttt{p} instruction allows us to write self-modifying code. + +\vfill +\pagebreak + +\problem{} +Write a program that prints \say{\texttt{Hello World}}. + +\problem{} +Write a program that prints the alphabet + +\problem{} +Write a program that generates a random sequence of numbers (\texttt{0}-\texttt{9}). + +\vfill + + + +\problem{} +Write a program that does not contain the string \say{\texttt{Hello World}}, \par +but writes that string somewhere inside its source. + +\problem{} +Replace the \texttt{x}s in the following program +so that the loop runs forever. \par +Do not use any control-flow instructions +(\texttt{>}, \texttt{<}, \texttt{\textasciicircum{}}, \texttt{v}, \texttt{\_}, \texttt{|}, \texttt{\#}, or \texttt{?}) \par +\hint{ + Start by replacing all the \texttt{x}s with spaces. \par + You may not need all the \texttt{x}s, feel free to use a smaller rectangle. +} + +\vspace{2mm} + +\begin{center} + \texttt{>xxxxxxxxv \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + x ~ ~ ~ ~x \\ + \textasciicircum{}xxxxxxxx@ +} +\end{center} + +\begin{solution} + The intended solution is self-modifying code: + + \begin{center} + \texttt{>69*6+97pv\\ + p ~ ~ ~ ~8\\ + 7 ~ ~ ~ ~8\\ + 9 ~ ~ ~ ~*\\ + * ~ ~ ~ ~0\\ + 8 ~ ~ ~ ~0\\ + 8 ~ ~ ~ ~p\\ + \textasciicircum{}p00-2*88@ + } + \end{center} + +\end{solution} + + +\vfill + + +\problem{Bonus} +Write a quine. (i.e, write a program that outputs itself) + +\begin{solution} + \texttt{01->1\# +\# :\# 0\# g\# ,\# :\# 5\# 8\# *\# 4\# +\# -\# \_@} +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Estimathon/main.tex b/src/Advanced/Estimathon/main.tex new file mode 100755 index 0000000..a8682c7 --- /dev/null +++ b/src/Advanced/Estimathon/main.tex @@ -0,0 +1,236 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering, + nopagenumber +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Estimathon} +\subtitle{Prepared by Mark on \today{}} + + +\begin{document} + + + \maketitle + + \section{Rules} + + Your team will have 45 minutes to work on 16 estimation problems. + The answer to each problem is a positive real number. Your team will + submit intervals for each problem, which (ideally) contain the specified quantity. + + + \vspace{2mm} + + An interval is \say{good} if it contains the true value. After the end of the game, + your team's score will be calculated as follows: + + \begin{equation*} + \Biggl(10 +\sum_\text{good intervals}\biggl\lfloor\frac{\text{max}}{\text{min}}\biggr\rfloor\Biggr) + \times 2^{16 ~-~ \text{number of good intervals}} + \end{equation*} + + + For every problem you miss or leave blank, your score doubles. \par + Your job is to \textbf{minimize} your score. + + + \vspace{8mm} + + Every team will get 20 answer sheets. You may use one of these sheets to submit an interval at any time. + Make sure you write your team name, problem number, and interval (min and max) every time you submit. + + \vspace{2mm} + + There are 16 problems, but you are given 20 answer sheets. You may re-submit your solution to any problem + (as long as you have sheets remaining). Your latest answer will be kept. + + \vspace{2mm} + + Your interval may not use any mathematical operations except for scientific notation \par + (for example, $[2 \times 10^2, 3 \times 10^2]$) + + + + \vfill + \pagebreak + + \section{Problems} + + \problem{} + What is the highest posted speed limit in the United States? + + \begin{solution} + $85$ mi/hr + \end{solution} + + \problem{} + How many words are in Isaac Asimov's \textit{Foundation} trilogy? + + \begin{solution} + About 250,000 + \end{solution} + + + \problem{} + How much horsepower can the average horse produce, disregarding fatigue? + + \begin{solution} + About 15HP, as measured in 1925. + \end{solution} + + \problem{} + What is $\sqrt[100]{2} - 1$? + + \begin{solution} + $0.06956$ + \end{solution} + + + %\problem{} + %What is the approximate speed of the magnetic north pole's drift? (in km/year) + %\begin{solution} + % 60km/yr + %\end{solution} + + \problem{} + What was the stock price of Apple on $2023-01-10$? + \begin{solution} + $\$186.19$ + \end{solution} + + \problem{} + How many distinct (non-isomorphic) groups are there on $60$ elements? + + \begin{solution} + 13 + \end{solution} + + + \problem{} + How many undergraduates were enrolled at UCLA in the Fall of 2021? + + \begin{solution} + 32,121 + \end{solution} + + +\makeatletter +\if@solutions + \vfill + \pagebreak +\fi +\makeatother + + + %\problem{} + %How many different creatures are there in \textit{Dwarf Fortress}? + + %\begin{solution} + % 500 (estimate, no way I'm counting them all) + %\end{solution} + + \problem{} + Find the smallest $k > 10$ where + $ + \sqrt{ + \frac{k!(k+1)!}{2} + } + $ + is an integer + + \begin{solution} + $\frac{k!(k+1!)}{2} = (k!)^2 \times \frac{k+1}{2}$, so $\frac{k+1}{2}$ must be a perfect square. \par + If $k > 10$, $\frac{k+1}{2} > \frac{11}{2} > 4$. 9 is the next smallest perfect square, so $\frac{k+1}{2} = 9$ and $k =17$. + \end{solution} + + + \problem{} + How many hours of podcasts has Mark listened to in 3.5 years of driving to UCLA? + + \begin{solution} + 831.4 hours + \end{solution} + + + \problem{} + For how many positive integers $n$ less than $10,000$ is $2^n - n^2$ divisible by $7$? + + \begin{solution} + 2858 + \end{solution} + + %\problem{} + %How many Serbian dinars can you exchange for $\$32.53$? + %\begin{solution} + % 3,473.02 + %\end{solution} + + \problem{} + How many lines of code were in the Linux repository in 2022? + + \begin{solution} + About 27.8 million + \end{solution} + + + \problem{} + Suppose you drop 16 needles of length 5 on ruled paper with distance 8. \par + What is the probability that three, four, or five needles cross a line? + + \begin{solution} + 0.316 + \end{solution} + + + \problem{} + How many officially-recognized time zones are there? + + \begin{solution} + Oddly enough, 38 + \end{solution} + + + \problem{} + What is the smallest number ending in 34, divisible by 34, with a sum of digits equal to 34? + \begin{solution} + 198934 + \end{solution} + + +\makeatletter +\if@solutions + \vfill + \pagebreak +\fi +\makeatother + + + \problem{} + How many distinct typewriter models have been produced by \textit{Smith Corona} since 1886? + + \begin{solution} + 106 + \end{solution} + + %\problem{} + %How many people live on Antarctica during the winter? + + %\begin{solution} + % About 1100; rises to about 5000 in Summer. + %\end{solution} + + + \problem{} + What is the standard deviation of the above solutions? + + \begin{solution} + $7.421 \times 10^6$ + \end{solution} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Estimathon/meta.toml b/src/Advanced/Estimathon/meta.toml new file mode 100644 index 0000000..3bb5423 --- /dev/null +++ b/src/Advanced/Estimathon/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Estimathon" + +[publish] +handout = false +solutions = true diff --git a/src/Advanced/Generating Functions/main.tex b/src/Advanced/Generating Functions/main.tex new file mode 100755 index 0000000..49a940d --- /dev/null +++ b/src/Advanced/Generating Functions/main.tex @@ -0,0 +1,22 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Generating Functions} +\subtitle{Prepared by Mark on \today \\ Based on a handout by Aaron Anderson} + +\begin{document} + \maketitle + + \input{parts/00 introduction.tex} + \input{parts/01 fibonacci.tex} + \input{parts/02 dice.tex} + \input{parts/03 coins.tex} +\end{document} \ No newline at end of file diff --git a/src/Advanced/Generating Functions/meta.toml b/src/Advanced/Generating Functions/meta.toml new file mode 100644 index 0000000..08749ca --- /dev/null +++ b/src/Advanced/Generating Functions/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Generating Functions" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Generating Functions/parts/00 introduction.tex b/src/Advanced/Generating Functions/parts/00 introduction.tex new file mode 100755 index 0000000..adf9871 --- /dev/null +++ b/src/Advanced/Generating Functions/parts/00 introduction.tex @@ -0,0 +1,107 @@ +\section{Introduction} + +\definition{} +Say we have a sequence $a_0, a_1, a_2, ...$. \par +The \textit{generating function} of this sequence is defined as follows: +\begin{equation*} + A(x) = \sum_{n=0}^\infty a_nx^n = a_0 + a_1x + a_2x^2 + a_3x^3 + ... +\end{equation*} + +Under some circumstances, this sum does not converge, and thus $A(x)$ is undefined. \par +However, we can still manipulate this infinite sum to get useful results even if $A(x)$ +diverges. + +\problem{} +Let $A(x)$ be the generating function of the sequence $a_n$, \par +and let $B(x)$ be the generating function of the sequence $b_n$. \par +Find the sequences that correspond to the following generating functions: +\begin{itemize}[itemsep=2mm] + \item $cA(x)$ + \item $xA(x)$ + \item $A(x) + B(x)$ + \item $A(x)B(x)$ +\end{itemize} + +\begin{solution} + \begin{itemize}[itemsep=2mm] + \item $cA(x)$ corresponds to $ca_n$ + \item $xA(x)$ corresponds to $0, a_0, a_1, ...$ + \item $A(x) + B(x)$ corresponds to $a_n+b_n$ + \item $A(x)B(x)$ is $a_0b_0 + (a_0b_1 + a_1b_0)x + (a_0b_2 + a_1b_1 + a_2b_0)x^2 + ...$ \par + Which corresponds to $c_n = \sum_{k=0}^n a_kb_{n-k}$ + \end{itemize} +\end{solution} + + +\vfill +\pagebreak + + + + +\problem{} +Assuming $|x| < 1$, show that +\begin{equation*} + \frac{1}{1-x} = 1 + x + x^2 + x^3 + ... +\end{equation*} +\hint{use some clever algebra. What is $x \times (1 + x + x^2 + ...)$? } + +\begin{solution} + Let $S = 1 + x + x^2 + ...$ \par + Then, $xS = x + x^2 + x^3 + ...$ \par + + \vspace{2mm} + + So, $xS = S - 1$ \par + and $1 = S - xS = S(1 - x)$ \par + and $S = \frac{1}{1-x}$. +\end{solution} + + +\vfill + + + + +\problem{} +Let $A(x)$ be the generating function of the sequence $a_n$. \par +Find the sequence that corresponds to the generating function $\frac{A(x)}{1-x}$ + +\begin{solution} + \begin{align*} + \frac{A(x)}{1-x} + &=~ A(x)(1 + x + x^2 + ...) \\ + &=~ (a_0 + a_1x + a_2x^2 + ...)(1 + x + x^2 + ...)\\ + &=~ a_0 + (a_0 + a_1)x + (a_0 + a_1 + a_2)x^2 + ... + \end{align*} + + Which corresponds to the sequence $c_n = \sum_{k=0}^n a_k$ +\end{solution} + +\vfill + +\problem{} +Find short expressions for the generating functions for the following sequences: +\begin{itemize} + \item $1, 0, 1, 0, ...$ + \item $1, 2, 4, 8, 16, ...$ + \item $1, 2, 3, 4, 5, ...$ +\end{itemize} + +\begin{solution} + \begin{itemize}[itemsep=2mm] + \item $1, 0, 1, 0, ...$ corresponds to $1 + x^2 + x^4 + ...$. \par + By \ref{xminusone}, this is $\frac{1}{1-x^2}$. + + \item $1, 2, 4, 8, 16, ...$ corresponds to $1 + 2x + (2x)^2 + ...$. \par + By \ref{xminusone}, this is $\frac{1}{1-2x}$. + + \item $1, 2, 3, 4, 5, ...$ corresponds to $1 + 2x + 3x^2 + 4x^3 + ...$.\par + This is equal to $(1 + x + x^2 + ...)^2$, and thus is $\left(\frac{1}{1-x}\right)^2$ + \end{itemize} +\end{solution} + + +\vfill + +\pagebreak diff --git a/src/Advanced/Generating Functions/parts/01 fibonacci.tex b/src/Advanced/Generating Functions/parts/01 fibonacci.tex new file mode 100755 index 0000000..3c99478 --- /dev/null +++ b/src/Advanced/Generating Functions/parts/01 fibonacci.tex @@ -0,0 +1,168 @@ +\section{Fibonacci} + +\definition{} +The \textit{Fibonacci numbers} are defined by the following recurrence relation: +\begin{itemize} + \item $f_0 = 0$ + \item $f_1 = 1$ + \item $f_n = f_{n-1} + f_{n-2}$ +\end{itemize} + +\problem{} +Let $F(x)$ be the generating function that corresponds to the Fibonacci numbers. \par +Find the generating function of $0, f_0, f_1, ...$ in terms of $F(x)$. \par +Call this $G(x)$. + +\begin{solution} + \begin{equation*} + G(x) = xF(x) + \end{equation*} +\end{solution} + +\vfill + +\problem{} +Find the generating function of $0, 0, f_0, f_1, ...$ in terms of $F(x)$. +Call this $H(x)$. + +\begin{solution} + \begin{equation*} + H(x) = x^2F(x) + \end{equation*} +\end{solution} + +\vfill + +\problem{} +Calculate $F(x) - G(x) - H(x)$ using the recurrence relation that +we used to define the Fibonacci numbers. + +\begin{solution} + \begin{align*} + F(x) - G(x) - H(x) + &=~ f_0 + (f_1 - f_0)x + (f_2 - f_1 - f_0)x^2 + (f_3 - f_2 - f_1)x^3 + ... \\ + &=~ f_0 + (f_1 - f_0)x \\ + &=~ x + \end{align*} +\end{solution} + +\vfill +\pagebreak + + +\problem{} +Using the problems on the previous page, find $F(x)$ in terms of $x$. + +\begin{solution} + \begin{align*} + x + &=~ F(x) - G(x) - H(x) \\ + &=~ F(x) - xF(x) - x^2F(x) \\ + &=~ F(x)(1-x-x^2) + \end{align*} + + So, + \begin{equation*} + F(x) = \frac{x}{1-x-x^2} + \end{equation*} +\end{solution} + +\vfill + + + + +\definition{} +A \textit{rational function} $f$ is a function that can be written as a quotient of polynomials. \par +That is, $f(x) = \frac{p(x)}{q(x)}$ where $p$ and $q$ are polynomials. + +\problem{} +Solve the equation from \ref for $F(x)$, expressing it as a rational function. + +\begin{solution} + \begin{align*} + F(x) + &=~ \frac{-x}{x^2+x-1} = \frac{-x}{(x-a)(x-b)} \\ + &=~ \frac{1 - \sqrt{5}}{2\sqrt{5}}\frac{1}{x-a} + \frac{-1 - \sqrt{5}}{2\sqrt{5}}\frac{1}{x-b} + \end{align*} + + where + + \begin{equation*} + a = \frac{-1 + \sqrt{5}}{2} ;~~ + b = \frac{-1 - \sqrt{5}}{2} + \end{equation*} +\end{solution} + +\vfill +\pagebreak + + +\definition{} +\textit{Partial fraction decomposition} is an algebreic technique that works as follows: \par +If $p(x)$ is a polynomial and $a$ and $b$ are constants, +we can rewrite the rational function $\frac{p(x)}{(x-a)(x-b)}$ as follows: +\begin{equation*} + \frac{p(x)}{(x-a)(x-b)} = \frac{c}{x-a} + \frac{d}{x-b} +\end{equation*} +where $c$ and $d$ are constants. + + +\problem{} +Now that we have a rational function for $F(x)$, \par +find a closed-form expression for its coefficients using partial fraction decomposition. + +\begin{solution} + \begin{align*} + F(x) + &=~ + \left(\frac{1 - \sqrt{5}}{2\sqrt{5}}\right)\left(\frac{-1}{a}\right)\left(\frac{1}{1-\frac{x}{a}}\right) + + \left(\frac{-1 - \sqrt{5}}{2\sqrt{5}}\right)\left(\frac{-1}{b}\right)\left(\frac{1}{1-\frac{x}{b}}\right) \\ + &=~ + \left(\frac{1}{\sqrt{5}}\right)\left(\frac{1}{1-\frac{x}{a}}\right) + + \left(\frac{-1}{\sqrt{5}}\right)\left(\frac{1}{1-\frac{x}{b}}\right) \\ + &=~ + \frac{1}{\sqrt{5}}\left(1 + \frac{x}{a} + \left(\frac{x}{a}\right)^2 + ...\right) + - \frac{1}{\sqrt{5}}\left(1 + \frac{x}{b} + \left(\frac{x}{b}\right)^2 + ...\right) + \end{align*} +\end{solution} + +\vfill + +\problem{} +Using problems from the introduction and \ref{pfd}, find an expression +for the coefficients of $F(x)$ (and this, for the Fibonacci numbers). + + +\begin{solution} + \begin{align*} + f_0 &= \frac{1}{\sqrt{5}} - \frac{1}{\sqrt{5}} = 0 \\ + f_1 &= \frac{1}{a\sqrt{5}} - \frac{1}{b\sqrt{5}} = 1 \\ + f_n &= \frac{1}{\sqrt{5}}\left(\frac{1}{a^n} - \frac{1}{b^n}\right) + = \frac{1}{\sqrt{5}}\left( + \left(\frac{1 + \sqrt{5}}{2}\right)^n + - \left(\frac{1-\sqrt{5}}{2}\right)^n + \right) + \end{align*} +\end{solution} + +\vfill +\pagebreak + +\problem{Bonus} +Repeat the method of recurrence, generating function, +partial fraction decomposition, and geometric series +to find a closed form for the following sequence: +\begin{equation*} + a_0 = 1 ;~~ a_{n+1} = 2a_n + n +\end{equation*} + +\hint{ + When doing partial fraction decomposition with a + denominator of the form $(x-a)^2(x-b)$, + you may need to express your expression as a sum of three fractions: + $\frac{c}{(x-a)^2} + \frac{d}{x-a} + \frac{e}{x-b}$.`' +} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Generating Functions/parts/02 dice.tex b/src/Advanced/Generating Functions/parts/02 dice.tex new file mode 100755 index 0000000..f893350 --- /dev/null +++ b/src/Advanced/Generating Functions/parts/02 dice.tex @@ -0,0 +1,102 @@ +\section{Dice} + +\definition{} +A \textit{die} is a device that randomly selects a positive integer from +a finite list of options. For example, the standard 6-sided die selects a value from +$[1,2,3,4,5,6]$. We may have many sides with the same value, as in $[1, 1, 2, 3]$. + +To describe a die with a generating function, let $a_k$ be the number of times +$k$ appears as a side of the die and consider $a_0 + a_1x + x_2x^2 + ... $. \par +A die has a finite number of sides, so this will be a regular polynomial. + +\problem{} +What is the generating function of the standard 6-sided die? + +\begin{solution} + $x + x^2 + x^3 + x^4 + x^5 + x^6$ +\end{solution} + +\vfill + +\problem{} +What is the generating function of the die with sides $[1, 2, 3, 5]$? + +\begin{solution} + $2x + x^2 + x^3 + x^5$ +\end{solution} + +\vfill + +\problem{} +Let $A(x)$ and $B(x)$ be the generating functions of two dice. \par +What is the significance of $A(1)$? +\begin{solution} + $A(1) = $ the number of sides on the die +\end{solution} + +\vfill + +\problem{} +Using formulas we found earlier, show that the $k^\text{th}$ coefficient +of $A(x)B(x)$ is the number of ways to roll $k$ as the sum of the two dice. +\begin{solution} + The $k^\text{th}$ coefficient of $A(x)B(x)$ is... + + \begin{align*} + a_0b_k + a_1b_{k+1} + ... + a_kb_0 \\ + &=~ \text{count}(A = 0; B = k) + ... + \text{count}(A = k; B = 0) \\ + &=~ \text{number of ways} A + B = k + \end{align*} +\end{solution} + + +\vfill +\pagebreak + +\problem{} +Find a generating function for the sequence $c_0, c_1, ...$, where $c_k$ is +the probability that the sum of the two dice is $k$. +\begin{solution} + + \begin{equation*} + c_k + = \frac{\text{number of ways sum} = k}{\text{number of total outcomes}} + = \frac{\text{number of ways sum} = k}{A(1)B(1)} + \end{equation*} + + So, + + \begin{equation*} + c_0 + c_1x + c_2x^2 = + \frac{A(x)B(x)}{A(1)B(1)} + \end{equation*} +\end{solution} + +\vfill + +\problem{} +Using generating functions, find two six-sided dice whose sum has the same +distribution as the sum of two standard six-sided dice? \par + +That is, for any integer $k$, the number if ways that the sum of the two +nonstandard dice rolls as $k$ is equal to the number of ways the sum of +two standard dice rolls as $k$. +\hint{factor polynomials.} +\begin{solution} + We need a different factorization of + + \begin{equation*} + (x + x^2 + x^3 + x^4 + x^5 + x^6)^2 = A(x)B(x) + \end{equation*} + + We can use + + \begin{equation*} + (x + 2x^2 + 2x^3 + x^4) + (x + x^3 + x^4 + x^5 + x^6 + x^8) + \end{equation*} +\end{solution} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Generating Functions/parts/03 coins.tex b/src/Advanced/Generating Functions/parts/03 coins.tex new file mode 100755 index 0000000..6ab2e22 --- /dev/null +++ b/src/Advanced/Generating Functions/parts/03 coins.tex @@ -0,0 +1,102 @@ +\section{Coins} + + +Consider the following problem: + +\say{How many different ways can you make change for \$0.50 \par +using pennies, nickels, dimes, quarters and half-dollars?} + +\vspace{2mm} + +Most ways of solving this involve awkward brute-force +approache that don't reveal anything interesting about the problem: +how can we change our answer if we want to make change for +\$0.51, or \$1.05, or some other quantity? + +\vspace{2mm} + +We can use generating functions to solve this problem in a general way. + +\definition{} +Let $p_0, p_1, p_2, ...$ be such that $p_k$ is the number +of ways to make change for $k$ cents with only pennies. + +Similarly, let... +\begin{itemize} + \item $n_k$ be the number of ways to make change for $k$ cents with only nickels; + \item $d_k$ be the number of ways using only dimes; + \item $q_k$ be the number of ways using only quarters; + \item and $h_k$ be the number of ways using only half-dollars. +\end{itemize} + +\problem{} +Let $p(x)$ be the generating function that corresponds to $p_n$. \par +Express $p(x)$ as a rational function. + +\vfill + +\problem{} +Modify \ref{pcoins} to find expressions for $n(x)$, $d(x)$, $q(x)$, and $h(x)$. + +\vfill +\pagebreak + +\definition{} +Now, let $N(x)$ be the generating function for the sequence +$n_0, n_1, ...$, where $n_k$ is the number of ways to make +change for $k$ cents using pennies and nickels. + +Similarly, let... +\begin{itemize} + \item let $D(x)$ be the generating function for the sequence using pennies, nickels, and dimes; + \item let $Q(x)$ use pennies, nickels, dimes, and quarters; + \item and let $H(x)$ use all coins. +\end{itemize} + +\problem{} +Express $N(x)$ as a rational function. + +\vfill + +\problem{} +Using the previous problem, write $D(x)$, then $Q(x)$, then $H(x)$ +as rational functions. + + +\vfill + +\problem{} +Using these generating functions, find recurrence relations for +the sequences $N_k$, $D_k$, $Q_k$, and $H_k$. + +\hint{ + Your recurrence relation for $N_k$ should refer to the + previous values of itself and some values of $p_k$. + Your recurrence for $D_k$ should refer to itself and $N_k$; + the one for $Q_k$ should refer to itself $D_k$; + and the one for $H_k$ should refer to itself and $Q_k$. +} + +\vfill + + +\problem{} +Using these recurrence relations, fill following table +and solve the original problem. + +\begin{center} + \begin{tabular}{ c|cccc|cccc|ccc } + $n$ & 0 & 5 & 10 & 15 & 20 & 25 & 30 & 35 & 40 & 45 & 50 \\ + \hline + $p_k$ &&&&&&&&&& \\ + $N_k$ &&&&&&&&&& \\ + \hline + $D_k$ &&&&&&&&&& \\ + \hline + $Q_k$ &&&&&&&&&& \\ + $H_k$ &&&&&&&&&& + \end{tabular} +\end{center} + +\vspace{1cm} +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Geometric Optimization/main.tex b/src/Advanced/Geometric Optimization/main.tex new file mode 100755 index 0000000..8876c3c --- /dev/null +++ b/src/Advanced/Geometric Optimization/main.tex @@ -0,0 +1,251 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Geometric Optimization} +\subtitle{ + Prepared by Mark on \today \par + Based on a handout by Nakul \& Andreas +} + +\begin{document} + + \maketitle + + \section{Optimization} + + \problem{} + Let $A$ and $B$ be two points on the same side of a given line $\ell$. \par + Find a point $C$ on $\ell$ so that $|AC| + |BC|$ is minimized. + + + \begin{center} + \begin{tikzpicture}[scale = 2] + \draw[-] (-2,0) -- (3,0); + + \fill[fill=black] (-0.6, 1) circle (0.03) node[below] {$A$}; + \fill[fill=black] (1.6, 0.75) circle (0.03) node[below] {$B$}; + \fill[fill=black] (0.5, 0) circle (0.03) node[below] {$C$}; + + \draw[-] (-0.6, 1) -- (0.5, 0) -- (1.6, 0.75); + \end{tikzpicture} + \end{center} + + \vfill + \pagebreak + + + \definition{} + An \textit{ellipse} with foci $A$, $B$ and radius $r$ is the set of all points $C$ where $|AB| + |BC| = r$. + + \problem{} + Consider a reflective ellipse with foci $A$ and $B$. \par + Find all points $X$ on the ellipse where $A$ can aim a laser at so that the beam reaches $B$. \par + \hint{use \ref{simtri}} + + \begin{center} + \begin{tikzpicture}[ + dot/.style={draw, fill, circle, inner sep=1.2}, + scale = 0.75 + ] + \def\a{5} % large half axis + \def\b{3} % small half axis + + \draw (0,0) ellipse ({\a} and {\b}); + + % Foci + \node[dot,label={above right:$A$}] (A) at ({-sqrt(\a*\a-\b*\b)},0) {}; + \node[dot,label={above:$B$}] (B) at ({+sqrt(\a*\a-\b*\b)},0) {}; + + % Node on ellipse + \def\angle{150} + \node[dot,label={\angle:$X$}] (X) at (\angle:{\a} and {\b}) {}; + \draw (A) -- (X) -- (B); + \end{tikzpicture} + \end{center} + + \vfill + \pagebreak + + + + + \problem{} + Let $C$ be a point in the interior of a given angle. Find points A and B on the sides + of the angle such that the perimeter of the triangle ABC is a minimum. + \vfill + + \problem{} + In a convex quadrilateral ABCD, find the point T for which the sum of the distances to + the vertices is minimal. + \vfill + \pagebreak + + + \problem{} + A road needs to be constructed from town A to town B, crossing a river, over which a + perpendicular bridge is to be constructed. + Where should the bridge be placed to minimize $|AR_1| + |R_1R_2| + |R_2B|$? + + \begin{center} + \begin{tikzpicture}[scale = 1.5] + \draw[-] (-5, 0.5) -- (5, 0.5); + \draw[-] (-5, -0.5) -- (5, -0.5); + + \fill[fill=black] (-3, -3) circle (0.06) node[below] {$A$}; + \fill[fill=black] (0.5, -0.5) circle (0.06) node[below] {$R_1$}; + \fill[fill=black] (0.5, 0.5) circle (0.06) node[below right] {$R_2$}; + \fill[fill=black] (3, 1) circle (0.06) node[below] {$B$}; + + \draw[-] (-3, -3) -- (0.5, -0.5) -- (0.5, 0.5) -- (3,1); + \end{tikzpicture} + \end{center} + + \pagebreak + + + + + + \problem{} + Consider an equilateral triangle triangle with vertices labeled $A$, $B$, and $C$. \par + Let P be a point inside this triangle. Place $D$, $E$, and $F$ so that $PD$, $PE$, and $PF$ + are the perpendiculars from $P$ to the sides of the triangle. \par + + Find all points $P$ where $|PD| + |PE| + |PF|$ is minimized. + + \begin{center} + \begin{tikzpicture}[scale = 4] + \draw[-] + (-1, 0) + -- (1, 0) + -- (0, 1.47) + -- cycle + ; + + \fill[fill=black] (0, 1.47) circle (0.03) node[above] (A) {$A$}; + \fill[fill=black] (1, 0) circle (0.03) node[below right] {$B$}; + \fill[fill=black] (-1, 0) circle (0.03) node[below left] {$C$}; + + \fill[fill=black] (0.39, 0.9) circle (0.03) node[above right] {$D$}; + \fill[fill=black] (-0.3, 0) circle (0.03) node[below right] {$E$}; + \fill[fill=black] (-0.555, 0.65) circle (0.03) node[above left] {$F$}; + + \fill[fill=black] (-0.3, 0.5) circle (0.03) node[below right] {$P$}; + + + \draw[-] (-0.3, 0.5) -- (0.39, 0.9); + \draw[-] (-0.3, 0.5) -- (-0.3, 0); + \draw[-] (-0.3, 0.5) -- (-0.555, 0.65); + + \draw[-] (-0.2, 0) -- (-0.2, 0.1) -- (-0.3, 0.1); + + + \end{tikzpicture} + \end{center} + + \vfill + \pagebreak + + + + + \problem{} + With the same setup as \ref{equi}, find all points $P$ where $|PA| + |PB| + |PC|$ is minimized. + \vfill + + + \problem{} + Solve \ref{equi2} for a triangle that isn't equilateral. + \vfill + \pagebreak + + + + \problem{} + Draw a circle, then draw two distinct tangents $\ell_1$ and $\ell_2$ that intersect at point $A$. \par + Let $P$ be a point on the circle between the tangents, and $BC$ be the tangent at that point. + Describe how $P$ should be selected in order to minimize the perimeter of triangle $ABC$. + + \begin{center} + \begin{tikzpicture}[scale = 2] + \draw (0, 0) circle (1); + + \fill[fill=black] (-4, -1) circle (0.04) node[below] (A) {$A$}; + \draw[-] (-4, -1) -- (2, -1); + \draw[-] (-4, -1) -- (1.2, 1.78); + \draw[-] (-1, -1) -- (-1, 0.6); + + \fill[fill=black] (-1, 0.6) circle (0.04) node[above left] {$B$}; + \fill[fill=black] (-1, 0) circle (0.04) node[right] {$P$}; + \fill[fill=black] (-1, -1) circle (0.04) node[below] {$C$}; + \end{tikzpicture} + \end{center} + + \vspace{2cm} + + + \problem{} + Now, assume that $\ell_1$ and $\ell_2$ intersect at $A$, and pick a point $P$ between them. \par + Find $BC$ through $P$ so that the perimeter of $ABC$ is minimized. + + \vfill + \pagebreak + + + \section{Bonus Problems} + + \problem{} + Given a cube $A_1B_1C_1D_1A_2B_2C_2D_2$ with side length $l$, \par + find the angle and distance between lines $A_1B_2$ and $A_2C_1$. + + \begin{solution} + Triangle $A_1B_2D_2$ is equilateral. \par + Also, point $A_2$ is equidistant from each of this triangle's vertices. \par + Therefore, its projection onto the plane formed by $A_1$, $B_2$, and $D_2$ is the center of the triangle. \par + + \vspace{2mm} + + Similarly, $C_1$ is mapped to the center of $A_1B_2D_2$. \par + Therefore, lines $A_1B_2$ and $A_2C_1$ are perpendicular and the distance between them is + equal to the distance from the center of triangle $A_1B_2D_2$ to its side. + + \vspace{2mm} + + Since all the sides of this triangle have length $l\sqrt{2}$, the distance in question is $\frac{a}{\sqrt{6}}$. + + \end{solution} + + \vfill + + \problem{} + Consider a cube $A_1B_1C_1D_1A_2B_2C_2D_2$, and let $K$, $L$, \par + and $M$ be midpoints of the edges $A_2D_2$, $A_1B_1$, and $C_1C_2$. \par + Show that the triangle formed by $KLM$ is equilateral, and that its center is the center of the cube. + + \begin{solution} + Let $O$ be the center of the cube. Then, $|OK| = |C_1D_2|$, $|2OL| = |D_2A_1|$, and $2|OM| = |A_1C_1|$. \par + Since triangle $C_1D_2A_1$is equilateral, triangle $KLM$ is equilateral and has $O$ as its center. + \end{solution} + + \vfill + + \pagebreak + + + \problem{} + Consider all $n$-gons with a certain perimeter. + Show that the $n$-gon with maximal area has equal sides + \vfill + + \problem{} + Consider all $n$-gons with a certain perimeter. + Show that the $n$-gon with maximal area has equal angles + \vfill + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Geometric Optimization/meta.toml b/src/Advanced/Geometric Optimization/meta.toml new file mode 100644 index 0000000..f3533c2 --- /dev/null +++ b/src/Advanced/Geometric Optimization/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Geometric Optimization" + +[publish] +handout = true +solutions = false diff --git a/src/Advanced/Geometry of Masses/img/arc.png b/src/Advanced/Geometry of Masses/img/arc.png new file mode 100644 index 0000000..a732cbb Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/arc.png differ diff --git a/src/Advanced/Geometry of Masses/img/pappus_1.png b/src/Advanced/Geometry of Masses/img/pappus_1.png new file mode 100644 index 0000000..1b67411 Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/pappus_1.png differ diff --git a/src/Advanced/Geometry of Masses/img/right_isos.png b/src/Advanced/Geometry of Masses/img/right_isos.png new file mode 100644 index 0000000..185392c Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/right_isos.png differ diff --git a/src/Advanced/Geometry of Masses/img/seahorse.jpg b/src/Advanced/Geometry of Masses/img/seahorse.jpg new file mode 100644 index 0000000..4be3bba Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/seahorse.jpg differ diff --git a/src/Advanced/Geometry of Masses/img/soda.png b/src/Advanced/Geometry of Masses/img/soda.png new file mode 100644 index 0000000..b45546d Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/soda.png differ diff --git a/src/Advanced/Geometry of Masses/img/soda_filled.png b/src/Advanced/Geometry of Masses/img/soda_filled.png new file mode 100644 index 0000000..4c695ec Binary files /dev/null and b/src/Advanced/Geometry of Masses/img/soda_filled.png differ diff --git a/src/Advanced/Geometry of Masses/main.tex b/src/Advanced/Geometry of Masses/main.tex new file mode 100755 index 0000000..5971604 --- /dev/null +++ b/src/Advanced/Geometry of Masses/main.tex @@ -0,0 +1,34 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering, + shortwarning +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{tikz} +\usetikzlibrary{patterns} +\usetikzlibrary{shapes.geometric} + +\usepackage{graphicx} + + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Geometry of Masses I} +\subtitle{Prepared by Sunny \& Mark on \today{}} + + + + +\begin{document} + \maketitle + + \input{parts/0 balance 1d.tex} + \input{parts/1 balance 2d.tex} + \input{parts/1 continuous} + \input{parts/2 pappus} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Geometry of Masses/meta.toml b/src/Advanced/Geometry of Masses/meta.toml new file mode 100644 index 0000000..6b3a40d --- /dev/null +++ b/src/Advanced/Geometry of Masses/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Geometry of Masses" + +[publish] +handout = true +solutions = false diff --git a/src/Advanced/Geometry of Masses/parts/0 balance 1d.tex b/src/Advanced/Geometry of Masses/parts/0 balance 1d.tex new file mode 100644 index 0000000..75ffa3c --- /dev/null +++ b/src/Advanced/Geometry of Masses/parts/0 balance 1d.tex @@ -0,0 +1,200 @@ +\section{Balancing a line} + +\example{} +Consider a mass $m_1$ on top of a pin. \par +Due to gravity, the mass exerts a force on the pin at the point of contact. \par +For simplicity, we'll say that the magnitude of this force is equal the mass of the object--- +that is, $m_1$. + +\begin{center} + \begin{tikzpicture}[scale=2] + \fill[color = black] (0, 0.1) circle[radius=0.1]; + \node[above] at (0, 0.20) {$m_1$}; + + \draw[line width = 0.25mm, pattern=north west lines] (0, 0) -- (-0.15, -0.3) -- (0.15, -0.3) -- cycle; + + \draw[color = black, opacity = 0.5] (1, 0.1) circle[radius=0.1]; + + \draw[line width = 0.25mm, pattern=north west lines, opacity = 0.5] + (1, 0) -- (0.85, -0.3) -- (1.15, -0.3) -- cycle; + + \draw[->, line width = 0.5mm] (1, 0) -- (1, -0.5) node[below] {$m_1$}; + %\draw[->, line width = 0.5mm, dashed] (1, 0) -- (1, 0.5) node[above] {$-m_1$}; + + \fill[color = red] (1, 0) circle[radius=0.025]; + \end{tikzpicture} +\end{center} +The pin exerts an opposing force on the mass at the same point, and the system thus stays still. + + +\remark{} +Forces, distances, and torques in this handout will be provided in arbitrary (though consistent) units. \par +We have no need for physical units in this handout. + +\example{} +Now attach this mass to a massless rod and try to balance the resulting system. \par +As you might expect, it is not stable: the rod pivots and falls down. +\begin{center} + \begin{tikzpicture}[scale=2] + \fill[color = black] (-0.3, 0.0) circle[radius=0.1]; + \node[above] at (-0.3, 0.1) {$m_1$}; + \draw[-, line width = 0.5mm] (-0.8, 0) -- (0.5, 0); + + \draw[line width = 0.25mm, pattern=north west lines] (0, 0) -- (-0.15, -0.3) -- (0.15, -0.3) -- cycle; + + + \draw[color = black, opacity = 0.5] (1.2, 0.0) circle[radius=0.1]; + \draw[-, line width = 0.5mm, opacity = 0.5] (0.7, 0) -- (1.9, 0); + + \draw[line width = 0.25mm, pattern=north west lines, opacity = 0.5] + (1.5, 0) -- (1.35, -0.3) -- (1.65, -0.3) -- cycle; + + \draw[->, line width = 0.5mm] (1.2, 0) -- (1.2, -0.5) node[below] {$m_1$}; + %\draw[->, line width = 0.5mm, dashed] (1.5, 0) -- (1.5, 0.5) node[above] {$f_p$}; + \end{tikzpicture} +\end{center} +This is because the force $m_1$ is offset from the pivot (i.e, the tip of the pin). \par +It therefore exerts a \textit{torque} on the mass-rod system, causing it to rotate and fall. + +\pagebreak + + + +\definition{Torque} +Consider a rod on a single pivot point. +If a force with magnitude $m_1$ is applied at an offset $d$ from the pivot point, +the system experiences a \textit{torque} with magnitude $m_1 \times d$. +\begin{center} + \begin{tikzpicture}[scale=2] + \draw[-, line width = 0.5mm] (-1.2, 0) -- (0.5, 0); + \draw[line width = 0.25mm, pattern=north west lines] (0, 0) -- (-0.15, -0.3) -- (0.15, -0.3) -- cycle; + + \draw[->, line width = 0.5mm, dashed] (-0.8, 0) -- (-0.8, -0.5) node[below] {$m_1$}; + \fill[color = red] (-0.8, 0.0) circle[radius=0.05]; + + + \draw[-, line width = 0.3mm, double] (-0.8, 0.1) -- (-0.8, 0.2) -- (0, 0.2) node [midway, above] {$d$} -- (0, 0.1); + \end{tikzpicture} +\end{center} + +We'll say that a \textit{positive torque} results in \textit{clockwise} rotation, +and a \textit{negative torque} results in a \textit{counterclockwise rotation}. +As stated in \ref{fakeunits}, torque is given in arbitrary \say{torque units} +consistent with our units of distance and force. + +\vspace{2mm} + +% I believe the convention used in physics is opposite ours, but that's fine. +% Positive = clockwise is more intuitive given our setup, +% and we only use torque to define CoM anyway. +Look at the diagram above and convince yourself that this convention makes sense: +\begin{itemize} + \item $m_1$ is positive \note{(masses are usually positive)} + \item $d$ is negative \note{($m_1$ is \textit{behind} the pivot)} + \item therefore, $m_1 \times d$ is negative. +\end{itemize} + + +\definition{Center of mass} +The \textit{center of mass} of a physical system is the point at which one can place a pivot \par +so that the total torque the system experiences is 0. \par +\note{In other words, it is the point at which the system may be balanced on a pin.} + + +\problem{} +Consider the following physical system: +we have a massless rod of length $1$, with a mass of size 3 at position $0$ +and a mass of size $1$ at position $1$. +Find the position of this system's center of mass. \par + +\begin{center} + \begin{tikzpicture}[scale=2] + \draw[line width = 0.25mm, pattern=north west lines] (0, 0) -- (-0.15, -0.3) -- (0.15, -0.3) -- cycle; + + \draw[-, line width = 0.5mm] (-0.5, 0) -- (1.5, 0); + + \fill[color = black] (-0.5, 0) circle[radius=0.1]; + \node[above] at (-0.5, 0.2) {$3$}; + + \fill[color = black] (1.5, 0) circle[radius=0.08]; + \node[above] at (1.5, 0.2) {$1$}; + \end{tikzpicture} +\end{center} + +\vfill + +\problem{} +Do the same for the following system, where $m_1$ and $m_2$ are arbitrary masses. + +\begin{center} + \begin{tikzpicture}[scale=2] + \draw[line width = 0.25mm, pattern=north west lines] (0.7, 0) -- (0.55, -0.3) -- (0.85, -0.3) -- cycle; + + \draw[-, line width = 0.5mm] (-0.5, 0) -- (1.5, 0); + + + \fill[color = black] (-0.5, 0) circle[radius=0.1]; + \node[above] at (-0.5, 0.2) {$m_1$}; + + \fill[color = black] (1.5, 0) circle[radius=0.08]; + \node[above] at (1.5, 0.2) {$m_2$}; + \end{tikzpicture} +\end{center} + +\begin{solution} + The CoM will be such that the rod is split into $d_1+d_2=1$ + according to the relation $m_1 d_1 = m_2 d_2$. + This is sufficient, but if you want to solve for one of the $d$, + you get $d_1 = \frac{m_2}{m_1+m_2}$. + + \vspace{2mm} + + This should be intuitive; the distance of each mass from the CoM + is proportional to the other mass's share of the total mass. +\end{solution} + +\vfill +\pagebreak + + + + +\definition{} +Consider a massless, horizontal rod of infinite length. \par +Affix a finite number of point masses to this rod. \par +We will call the resulting object a \textit{one-dimensional system of masses}: +\begin{center} + \begin{tikzpicture}[scale=1] + \draw[<->, line width = 0.5mm] (-4, 0) -- (4, 0); + \node[left] at (-4, 0) {$...$}; + \node[right] at (4, 0) {$...$}; + + + \fill[color = black] (-2.5, 0) circle[radius=0.12]; + \node[above] at (-2.5, 0.15) {$m_1$}; + + \fill[color = black] (-0.5, 0) circle[radius=0.1]; + \node[above] at (-0.5, 0.15) {$m_2$}; + + \fill[color = black] (1.5, 0) circle[radius=0.15]; + \node[above] at (1.5, 0.15) {$m_3$}; + \end{tikzpicture} +\end{center} +\vspace{5mm} + + + +\problem{} +Consider a one-dimensional system of masses consisting of $n$ masses $m_1, m_2, ..., m_n$, \par +with each $m_i$ positioned at $x_i$. Show that the resulting system always has a unique center of mass. \par +\hint{Prove this by construction: find the point!} + +\begin{solution} + \begin{equation*} + x_0 = \frac{1}{M}\sum_{i=1}^n m_i x_i + \end{equation*} + where $M = \sum_{i=1}^n m_i$ +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Geometry of Masses/parts/1 balance 2d.tex b/src/Advanced/Geometry of Masses/parts/1 balance 2d.tex new file mode 100644 index 0000000..cefe7b8 --- /dev/null +++ b/src/Advanced/Geometry of Masses/parts/1 balance 2d.tex @@ -0,0 +1,155 @@ +\section{Balancing a plane} + +\definition{} +Consider a massless two-dimensional plane. \par +Affix a finite number of point masses to this plane. \par +We will call the resulting object a \textit{two-dimensional system of masses:} + + +\begin{center} + \begin{tikzpicture}[scale = 0.5] + + %\draw[ + % line width = 0mm, + % pattern = north west lines, + % pattern color = blue, + %] + % (1, 0) + % -- (0.5, 0.866) + % -- (-0.5, 0.866) + % -- (-1, 0) + % -- (-0.5, -0.866) + % -- (0.5, -0.866) + % -- cycle; + %\draw[ + % line width = 0.5mm, + % blue + %] + % (1, 0) + % -- (0.5, 0.866) + % -- (-0.5, 0.866) + % -- (-1, 0) + % -- (-0.5, -0.866) + % -- (0.5, -0.866) + % -- cycle; + %\fill[color = blue] (0, 0) circle[radius=0.3]; + + + \fill[color = black] + (-3, 3) circle[radius = 0.5] + node[above] at (-3, 3.5) {$m_1$ at $(x_1, y_1)$}; + + \fill[color = black] + (-5, -1.5) circle[radius = 0.4] + node[above] at (-5, -1.0) {$m_2$ at $(x_2, y_2)$}; + + \fill[color = black] + (3, -3) circle[radius = 0.35] + node[above] at (3, -2.5) {$m_3$ at $(x_3, y_3)$}; + + \draw[line width = 0.5mm] + (-7.5, -4.2) + -- (6, -4.2) + -- (6, 5) + -- (-7.5, 5) + -- cycle; + + \end{tikzpicture} +\end{center} +\vspace{5mm} + + + +\problem{} +Show that any two-dimensional system of masses has a unique center of mass. \par +\hint{ + If a plane balances on a pin, it does not tilt in the $x$ or $y$ direction. \par + See the diagram below. +} +\begin{center} + \begin{tikzpicture}[scale = 0.5] + + % Horizontal + \draw[line width = 0.5mm, dotted, gray] (-3, 3) -- (-3, -5); + \draw[line width = 0.5mm, dotted, gray] (-5, -1.5) -- (-5, -5); + \draw[line width = 0.5mm, dotted, gray] (3, -3) -- (3, -5); + \draw[line width = 0.5mm, dotted, gray] (0, 0) -- (0, -5); + \draw[line width = 0.5mm] (-7, -5) -- (6.5, -5); + + \fill[color = gray] (-3, -5) circle[radius = 0.3]; + \fill[color = gray] (-5, -5) circle[radius = 0.3]; + \fill[color = gray] (3, -5) circle[radius = 0.3]; + + \draw[line width = 0.25mm, pattern=north west lines] + (0, -5) -- (-0.6, -6) -- (0.6, -6) -- cycle; + + + % Vertical + + \draw[line width = 0.5mm, dotted, gray] (-3, 3) -- (8, 3); + \draw[line width = 0.5mm, dotted, gray] (-5, -1.5) -- (8, -1.5); + \draw[line width = 0.5mm, dotted, gray] (3, -3) -- (8, -3); + \draw[line width = 0.5mm, dotted, gray] (0, 0) -- (8, 0); + \draw[line width = 0.5mm] (8, 4) -- (8, -4); + + \fill[color = gray] (8, 3) circle[radius = 0.3]; + \fill[color = gray] (8, -1.5) circle[radius = 0.3]; + \fill[color = gray] (8, -3) circle[radius = 0.3]; + + \draw[line width = 0.25mm, pattern=north west lines] + (8, 0) -- (9, -0.6) -- (9, 0.6) -- cycle; + + + \draw[ + line width = 0mm, + pattern = north west lines, + pattern color = blue, + ] + (1, 0) + -- (0.5, 0.866) + -- (-0.5, 0.866) + -- (-1, 0) + -- (-0.5, -0.866) + -- (0.5, -0.866) + -- cycle; + \draw[ + line width = 0.5mm, + blue + ] + (1, 0) + -- (0.5, 0.866) + -- (-0.5, 0.866) + -- (-1, 0) + -- (-0.5, -0.866) + -- (0.5, -0.866) + -- cycle; + \fill[color = blue] (0, 0) circle[radius=0.3] + node[above] at (0, 1) {Pivot}; + + \fill[color = black] + (-3, 3) circle[radius = 0.5] + node[above] at (-3, 3.5) {$m_1$ at $(x_1, y_1)$}; + + \fill[color = black] + (-5, -1.5) circle[radius = 0.4] + node[above] at (-5.5, -1.0) {$m_2$ at $(x_2, y_2)$}; + + \fill[color = black] + (3, -3) circle[radius = 0.35] + node[above] at (3, -2.8) {$m_3$ at $(x_3, y_3)$}; + \end{tikzpicture} +\end{center} + +\begin{solution} + \begin{equation*} + x_0 = \frac{\sum_{i=1}^n m_i x_i}{\sum_{i=1}^n m_i} + \qquad + y_0 = \frac{\sum_{i=1}^n m_i y_i}{\sum_{i=1}^n m_i} + \end{equation*} +\end{solution} + +\vfill +\pagebreak + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Geometry of Masses/parts/1 continuous.tex b/src/Advanced/Geometry of Masses/parts/1 continuous.tex new file mode 100644 index 0000000..b2b3dbf --- /dev/null +++ b/src/Advanced/Geometry of Masses/parts/1 continuous.tex @@ -0,0 +1,136 @@ +\section{Continuous mass} + +Now let's extend this idea to a \textit{continuous distribution} of masses rather than discrete point masses. This isn't so different; a continuous distribution of mass is really just a lot of point-masses, only that there are so many of them so close together that you can't even count them\footnote{For example, your pencil might seem like a continuous distribution of mass, but it's really just a whole lot of atoms.}. In general, finding the CoM requires integral calculus, but not always...\footnote{Many of the following problems can be solved with integration even though you're meant to solve them without it. But remember, in math, whenever you accomplish the same task two different ways, that really means that they're somehow the same thing.} + +\begin{figure}[htp] + \centering + \includegraphics[width=0.3\linewidth]{img/seahorse.jpg} + \label{seahorse} +\end{figure} + +\problem{} +You are given a cardboard cutout of a seahorse and some office supplies. \par +How might you determine its center of mass? Does your strategy also work in 3D? + +\begin{solution} + Many correct answers. One example: + \begin{enumerate}[label={(\arabic*)}] + \item Stick a thumb tack into the horse and let it come to equilibrium + \item Use a ruler or string to draw a straight line through that point along the direction of gravity + \item Repeat (1) and (2) at a different point + \item The intersection of the two lines marks the CoM + \end{enumerate} +\end{solution} + +\vfill + +\definition{Centroid} +Centroids are closely related to, and often synonymous with, centers of mass. +A centroid is the geometric center of an object, regardless of the mass distribution. +Thus, the centroid and center of mass are the same when the mass is uniformly distributed. + +\problem{} +Where is the center of a right isosceles triangle? What about any isosceles triangle? + +\begin{solution} + There are probably some other clever ways of doing this without calculus but here's one way: + \begin{center} + \includegraphics[width=0.3\linewidth]{img/right_isos.png} + \end{center} + Clearly, the centroid $O$ must be somewhere along $SC$. + Now we just need to find $s$ in terms of $x$, that is, the balancing point along either of the shorter sides. + To do this, we split the triangle into three regions: $\triangle{AVT}$ on the left, + the rectangle $TUCV$ on the right, and $\triangle{TUB}$ also on the right. + + Each region exerts a torque proportional to its area times the horizontal distance from $VT$ of that region's + centroid. Note that, even though we don't know what $x$ is yet, we can use it to find itself. + By similar triangles, the centroids of $\triangle{AVT}$ and $\triangle{TUB}$ are both located $x(1-x)$ away from $VT$. + The centroid of $TUVC$ is trivially $\frac{1-x}{2}$. So we get the following equation: + \begin{align*} + \frac{1}{2}x^2 \cdot x(1-x) &= x(1-x) \cdot \frac{1-x}{2} + \frac{1}{2}(1-x)^2 \cdot x(1-x) \quad . + \end{align*} + We easily find that $x=\frac{1}{3}$. Remarkably, the ratio $\frac{SO}{SC}$ is also $\frac{1}{3}$. + + Any right triangle is just an isosceles right triangle that's been scaled along some axis, so the centroid scales with it and this one-third rule still applies. + + Any isosceles triangle is just two right triangles, so \textit{its} centroid will be in between its two "sub-centroids" from each right triangle, that is, one-third the altitude. +\end{solution} + +\vfill + +\problem{} +How can you easily find the center of mass of any triangle? Why does this work? + + +\begin{solution} + It turns out that all three medians of a triangle always intersect at a single point. That point is the centroid. You could feasibly guess this by taking what you learned from Problem 13 and applying Cavalieri's Theorem. Otherwise, I'm interested to see what students come up with. +\end{solution} + +\vfill + +\pagebreak + + +\problem{} +Consider Figure \ref{soda} depicting a simplified soda can. +If you leave just the right amount, +you can get it to balance on the beveled edge, as seen in Figure +\ref{soda filled}. + +\begin{figure}[htp] +\centering +\begin{minipage}{0.5\textwidth} + \centering + \includegraphics[width=0.6\linewidth]{img/soda.png} + \caption{} + \label{soda} +\end{minipage}\hfill +\begin{minipage}{0.5\textwidth} + \centering + \includegraphics[width=0.6 \linewidth]{img/soda_filled.png} + \caption{} + \label{soda filled} +\end{minipage} +\end{figure} + +\problem{} +See Figure \ref{soda filled}. +Let's take the can to be massless and initially empty. +Let's also assume that we live in two dimensions. +We start slowly filling it up with soda to a vertical height $h$. +What is $h$ just before the can tips over? + +\begin{solution} + Similar to our solution to \ref{rightiso}, we draw a vertical line from the + desired balancing point and split the regions into triangles and rectangles. + Using symmetry and simple trigonometry, we find that: + $h = \sqrt{\sqrt{2}+\frac{8}{9}} + 3\sqrt{2}$ +\end{solution} + +\vfill + +\problem{}<3D soda> +Think about how you might approach this problem in 3D. Does $h$ become larger or smaller? + +\begin{solution} + This is a pretty open-ended question and is meant simply to make students think about + how the problem would change in 3D. I believe that $h$ gets smaller. +\end{solution} + + +\vfill + +\pagebreak + +So far we've made the assumption our shapes have mass that is \textit{uniformly distributed}. But that doesn't have to be the case. + +\begin{solution} + This problem is really just \ref{rightiso} again in disguise. + So, the balancing point is at $1/3$ the length of the staff measured from the dense-end. +\end{solution} + +\problem{} +A mathemagical wizard will give you his staff if you can balance it horizontally on your finger. The strange magical staff has unit length and it's mass is distributed in a very special way. It's density decreases linearly from $\lambda_0$ at one end to $0$ at the other. Where is the staff's balancing point? + +\vfill +\pagebreak diff --git a/src/Advanced/Geometry of Masses/parts/2 pappus.tex b/src/Advanced/Geometry of Masses/parts/2 pappus.tex new file mode 100644 index 0000000..ec4a4b3 --- /dev/null +++ b/src/Advanced/Geometry of Masses/parts/2 pappus.tex @@ -0,0 +1,95 @@ +\section{Pappus's Centroid Theorem} + +\begin{figure}[htp] + \centering + \includegraphics[width=0.6\linewidth]{img/pappus_1.png} + \caption{} + \label{pappus1} +\end{figure} + +\remark{} +\textit{Centroids} are closely related to, and often synonymous with, centres of mass. A centroid is the geometric centre of an object, regardless of the mass distribution. Thus, the centroid and centre of mass coincide when the mass is uniformly distributed. + +\remark{} +Figure \ref{pappus1} depicts three different surfaces constructed by revolving a line segment (in red) about a central axis. These are often called \textit{surfaces of revolution}. + +\problem{} +\textit{Pappus's First Centroid Theorem} allows you to determine the area of a surface of revolution using information about the line segment and the axis of rotation. +Can you intuitively come up with Pappus's First Centroid Theorem for yourself? Figure \ref{pappus1} is very helpful. It may also help to draw from surface area formulae you already know. What limitations are there on the theorem? + +\begin{solution} + \url{https://en.wikipedia.org/wiki/Pappus%27s_centroid_theorem} + \url{https://mathworld.wolfram.com/PappussCentroidTheorem.html} +\end{solution} + +\vfill +\pagebreak + +\problem{} +\textit{Pappus's Second Centroid Theorem} simply extends this concept to \textit{solids of revolution}, which are exactly what you think they are. + + +\problem{} +Now that you've done the first theorem, what do you think Pappus's Second Centroid Theorem states? + +\vfill + + +\problem{} +The centroid of a semi-circular line segment is already given in Figure \ref{pappus1}, but what about the centroid of a filled semi-circle? (Hint: For a sphere of radius $r$, $V=\frac{4}{3}\pi r^3$) + +\begin{figure}[htp] + \centering + \includegraphics[width=0.4\linewidth]{img/arc.png} + \caption{} + \label{arc} +\end{figure} + +\problem{} +Given arc $AB$ with radius $r$ and subtended by $2\alpha$, determine $OG$, the distance from the centre of the circle to the centroid of the arc. + +\begin{solution} + \url{https://mathspanda.com/A2FM/Lessons/Centres_of_mass_of_standard_shapes_LESSON.pdf} +\end{solution} + +\vfill + +\pagebreak + +\problem{} +Where is the centroid of the \textit{sector} of the circle in Figure \ref{arc}? +\hint{cut it up.} + + +\vfill + +\problem{} +Seeing your success with his linear staff, the wizard challenges you with another magical staff to balance. +It looks identical to the first one, but you're told that the density decreases from $\lambda_0$ to $0$ +according to the function $\lambda(x) = \lambda_0\sqrt{1-x^2}$. + +\begin{solution} + This is equivalent to finding the x-coordinate of the centroid of a quarter-circle. See \ref{sector}. +\end{solution} + +\vfill +\problem{} +Infinitely many masses $m_i$ are placed at $x_i$ along the positive $x$-axis, starting with $m_0 = 1$ placed at $x_0 = 1$. Each successive mass is placed twice as far from the origin compared to the previous one. But also, each successive mass has a quarter the weight of the previous one. Find the CoM if it exists. + +\begin{solution} + We have $m_i = 1/4^i$ and $x_i = 2^i$ so + \begin{align*} + \sum_{i=0}^\infty m_i x_i &= \sum \frac{2^i}{4^i} \\ + &= \sum \frac{1}{2^i} \\ + &= \frac{1}{1-1/2} = 2 \qquad \text{as this is just a geometric series} \\ + \end{align*} + \[ M = \sum m_i = \frac{1}{1-1/4} = 4/3 \] + Then + \[ x_{CM} = \frac{\sum m_i x_i}{M} = 3/2 \] +\end{solution} + +\vfill + +\problem{Bonus} +Try to actually find $h$ from Problem \ref{3D soda}. Good luck. + diff --git a/src/Advanced/Graph Algorithms/main.tex b/src/Advanced/Graph Algorithms/main.tex new file mode 100755 index 0000000..8c80ccb --- /dev/null +++ b/src/Advanced/Graph Algorithms/main.tex @@ -0,0 +1,28 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\input{tikxset} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Algorithms on Graphs: Flow} +\subtitle{Prepared by Mark on \today} + + +\begin{document} + + \maketitle + + \input{parts/00 review} + \input{parts/01 flow} + \input{parts/02 residual} + \input{parts/03 fulkerson} + \input{parts/04 applications} + \input{parts/05 reductions} + \input{parts/06 bonus} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/meta.toml b/src/Advanced/Graph Algorithms/meta.toml new file mode 100644 index 0000000..466ede4 --- /dev/null +++ b/src/Advanced/Graph Algorithms/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Graph Algorithms" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Graph Algorithms/parts/00 review.tex b/src/Advanced/Graph Algorithms/parts/00 review.tex new file mode 100755 index 0000000..db4e0f4 --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/00 review.tex @@ -0,0 +1,58 @@ +\section{Review} + +\definition{} +A \textit{graph} consists of a set of \textit{nodes} $\{A, B, ...\}$ and a set of edges $\{ (A,B), (A,C), ...\}$ connecting them. +A \textit{directed graph} is a graph where edges have direction. In such a graph, edges $(A, B)$ and $(B, A)$ are distinct. +A \textit{weighted graph} is a graph that features weights on its edges. \\ +A weighted directed graph is shown below. + +\begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope} + \node[main] (A) {$A$}; + \node[main] (B) [below right of = A] {$B$}; + \node[main] (C) [below left of = A] {$C$}; + \end{scope} + + % Edges + \draw[->] + (A) edge[bend right] node[label] {$4$} (B) + (B) edge node[label] {$2$} (C) + (C) edge node[label] {$2$} (A) + (B) edge[bend right] node[label] {$1$} (A) + ; + \end{tikzpicture} +\end{center} + +\vfill + +\definition{} +We say a graph is \textit{bipartite} if its nodes can be split into two groups $L$ and $R$, where no two nodes in the same group are connected by an edge: \\ + +\begin{center} + \begin{tikzpicture} + % Nodes + \begin{scope} + \node[main] (A) at (0mm, 0mm) {$A$}; + \node[main] (B) at (0mm, -10mm) {$B$}; + \node[main] (C) at (0mm, -20mm) {$C$}; + + \node[main, hatch] (D) at (20mm, 0mm) {$D$}; + \node[main, hatch] (E) at (20mm, -10mm) {$E$}; + \node[main, hatch] (F) at (20mm, -20mm) {$F$}; + \end{scope} + + % Edges + \draw + (A) edge (D) + (A) edge (E) + (B) edge (F) + (C) edge (E) + (C) edge (D) + ; + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/parts/01 flow.tex b/src/Advanced/Graph Algorithms/parts/01 flow.tex new file mode 100755 index 0000000..8acdab2 --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/01 flow.tex @@ -0,0 +1,351 @@ +\section{Network Flow} + +\generic{Networks} +Say have a network: a sequence of pipes, a set of cities and highways, an electrical circuit, etc. + +\vspace{1ex} + +We can draw this network as a directed weighted graph. If we take a transportation network, for example, edges will represent highways and nodes will be cities. There are a few conditions for a valid network graph: + +\begin{itemize} + \item The weight of each edge represents its capacity, e.g, the number of lanes in the highway. + \item Edge capacities are always positive integers.\hspace{-0.5ex}\footnotemark{} + \item Node $S$ is a \textit{source}: it produces flow. + \item Node $T$ is a \textit{sink}: it consumes flow. + \item All other nodes \textit{conserve} flow. The sum of flow coming in must equal the sum of flow going out. +\end{itemize} + +\footnotetext{An edge with capacity zero is equivalent to an edge that does not exist; An edge with negative capacity is equivalent to an edge in the opposite direction.} + +Here is an example of such a graph: +\begin{center} + \begin{tikzpicture} + + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$4$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} +\end{center} + +\hrule{} + +\generic{Flow} +In our city example, traffic represents \textit{flow}. Let's send one unit of traffic along the topmost highway: + +\vspace{2ex} + +\begin{minipage}{0.33\textwidth} +\begin{center} + \begin{tikzpicture} + + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$4$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + + % Flow + \draw[path] + (S) -- node[above left, flow] {$(1)$} (A) + -- node[above right, flow] {$(1)$} (T) + ; + \end{tikzpicture} +\end{center} +\end{minipage} +\begin{minipage}{0.65\textwidth} + There are a few things to notice here: + \begin{itemize} + \item Highlighted edges carry flow. + \item Numbers in parentheses tell us how much flow each edge carries. + \item The flow along an edge is always positive or zero. + \item Flow comes from $S$ and goes towards $T$. + \item Flow is conserved: all flow produced by $S$ enters $T$. + \end{itemize} +\end{minipage} + +\vspace{1ex} + +The \textit{magnitude} of a flow is the number of \say{flow-units} that go from $S$ to $T$. \\ + +We are interested in the \textit{maximum flow} through this network: what is the greatest amount of flow we can get from $S$ to $T$? + +\problem{} +What is the magnitude of the flow above? + +\vfill +\pagebreak + +\problem{} +Find a flow with magnitude 2 on the graph below. + +\begin{center} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$4$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} +\end{center} + +\vfill + +\problem{} +Find a maximal flow on the graph below. \\ +\hint{The total capacity coming out of $S$ is 3, so any flow must have magnitude $\leq 3$.} + +\begin{center} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$4$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak + +\section{Combining Flows} +It is fairly easy to combine two flows on a graph. All we need to do is add the flows along each edge. \\ +Consider the following flows: + +\vspace{2ex} + +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + \begin{tikzpicture} + + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$2$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + + % Flow + \draw[path] + (S) -- node[above left, flow] {$(1)$} (A) + -- node[above right, flow] {$(1)$} (T) + ; + \end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + \begin{tikzpicture} + + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$2$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + + % Flow + \draw[path] + (S) + -- node[below left, flow] {$(1)$} (B) + -- node[left, flow] {$(1)$} (A) + -- node[above right, flow] {$(1)$} (T) + ; + \end{tikzpicture} +\end{center} +\end{minipage} + +\vspace{1cm} + +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + Combining these, we get the following: + \vspace{2ex} + + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (+00mm, +00mm) {$S$}; + \node[main] (A) at (+15mm, +15mm) {$A$}; + \node[main] (B) at (+15mm, -15mm) {$B$}; + \node[main] (T) at (+30mm, +00mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$2$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + + % Flow + \draw[path] + (S) + -- node[below left, flow] {$(1)$} (B) + -- node[left, flow] {$(1)$} (A) + -- node[above right, flow] {$(2) = (1) + (1)$} (T) + (S) + -- node[above left, flow] {$(1)$} (A) + ; + \end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}[t]{0.48\textwidth} + \raggedright + When adding flows, we must respect edge capacities. + + \vspace{1ex} + + For example, we could not add these graphs if the magnitude of flow in the right graph above was 2, since the capacity of the top-right edge is 2, and $2 + 1 > 2$. +\end{minipage} + +\vspace{2ex} +\hrule +\vspace{2ex} + +\problem{} +Combine the flows below, ensuring that the flow along each edge remains within capacity. + +\vspace{2ex} + +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (C) [right of = A] {$C$}; + \node[main] (D) [right of = B] {$D$}; + \node[main] (T) [above right of = D] {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$5$} (A) + (A) edge node[label] {$3$} (C) + (C) edge node[label] {$2$} (T) + (A) edge node[label] {$4$} (D) + (S) edge node[label] {$4$} (B) + (B) edge node[label] {$1$} (D) + (D) edge node[label] {$2$} (T) + ; + + % Flow + \draw[path] + (S) + -- node[above left, flow] {$(2)$} (A) + -- node[above, flow] {$(2)$} (C) + -- node[above right, flow] {$(2)$} (T) + ; + \end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (C) [right of = A] {$C$}; + \node[main] (D) [right of = B] {$D$}; + \node[main] (T) [above right of = D] {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$5$} (A) + (A) edge node[label] {$3$} (C) + (C) edge node[label] {$2$} (T) + (A) edge node[label] {$4$} (D) + (S) edge node[label] {$4$} (B) + (B) edge node[label] {$1$} (D) + (D) edge node[label] {$2$} (T) + ; + + % Flow + \draw[path] + (S) + -- node[above left, flow] {$(2)$} (A) + -- node[above right, flow] {$(2)$} (D) + -- node[below right, flow] {$(2)$} (T) + ; + \end{tikzpicture} +\end{center} +\end{minipage} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/parts/02 residual.tex b/src/Advanced/Graph Algorithms/parts/02 residual.tex new file mode 100755 index 0000000..a33611a --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/02 residual.tex @@ -0,0 +1,211 @@ +\section{Residual Graphs} +It is hard to find a maximum flow for a large network by hand. \\ +We need to create an algorithm to accomplish this task. + +\vspace{1ex} + +The first thing we'll need is the notion of a \textit{residual graph}. + +\vspace{2ex} +\hrule + +\begin{center} + \begin{minipage}[t]{0.48\textwidth} + We'll start with the following network and flow: + \begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$1$} (A) + (A) edge node[label] {$3$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + + % Flow + \draw[path] + (S) -- node[above left, flow] {$(1)$} (A) + -- node[above right, flow] {$(1)$} (T) + ; + + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill + \begin{minipage}[t]{0.48\textwidth} + First, we'll copy all nodes and \say{unused} edges: + \begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} + \end{center} + \end{minipage} +\end{center} + +\hrule + +\begin{center} + \begin{minipage}[t]{0.48\textwidth} + Then, we'll add the unused capacity of \say{used} edges: (Note that $3 - 1 = 2$) + \begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (A) edge node[label] {$2$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill + \begin{minipage}[t]{0.48\textwidth} + Finally, we'll add \say{used} capacity as edges in the opposite direction: + \begin{center} + \begin{tikzpicture}[node distance = 20mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (A) edge node[label] {$1$} (S) + (T) edge [bend right] node[label] {$1$} (A) + (A) edge [bend right] node[label] {$2$} (T) + (B) edge node[label] {$2$} (A) + (S) edge node[label] {$2$} (B) + (B) edge node[label] {$1$} (T) + ; + \end{tikzpicture} + \end{center} + This graph is the residual of the original flow. +\end{minipage} +\end{center} + +\hrule +\vspace{3ex} + +You can think of the residual graph as a \say{list of possible changes} to the original flow. \\ +There are two ways we can change a flow: +\begin{itemize} + \item We can add flow along a path + \item We can remove flow along another path +\end{itemize} + +\vspace{1ex} + +A residual graph captures both of these actions, showing us where we can add flow (forward edges) and where we can remove it (reverse edges). Note that \say{removing} flow along an edge is equivalent to adding flow in the opposite direction. + + +\vfill +\pagebreak + +\problem{} +Construct the residual of this flow. + +\begin{center} + \begin{tikzpicture}[node distance = 25mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$2$} (A) + (A) edge node[label] {$1$} (T) + (A) edge node[label] {$3$} (B) + (S) edge node[label] {$1$} (B) + (B) edge node[label] {$2$} (T) + ; + + % Flow + \draw[path] + (S) + -- node[above left, flow] {$(2)$} (A) + -- node[left, flow] {$(2)$} (B) + -- node[below right, flow] {$(2)$} (T) + ; + \end{tikzpicture} +\end{center} + +\begin{solution} + \begin{center} + \begin{tikzpicture}[node distance = 25mm] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) {$S$}; + \node[main] (A) [above right of = S] {$A$}; + \node[main] (B) [below right of = S] {$B$}; + \node[main] (T) [above right of = B] {$T$}; + \end{scope} + + % Edges + \draw[->] + (A) edge node[label] {$2$} (S) + (A) edge node[label] {$1$} (T) + (A) edge[out=295,in=65] node[label] {$1$} (B) + (B) edge[out=115,in=245] node[label] {$2$} (A) + (S) edge node[label] {$1$} (B) + (T) edge node[label] {$2$} (B) + ; + \end{tikzpicture} + \end{center} +\end{solution} + +\vfill +\problem{} +Is the flow in \ref{FindResidual} maximal? \\ +If it isn't, find a maximal flow. \\ +\hint{Look at the residual graph. Can we add flow along another path?} + +\vfill +\pagebreak + +\problem{} +Show that... +\begin{enumerate} + \item A maximal flow exists in every network with integral edge weights. + \item Every edge in this flow carries an integral amount of flow +\end{enumerate} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/parts/03 fulkerson.tex b/src/Advanced/Graph Algorithms/parts/03 fulkerson.tex new file mode 100755 index 0000000..cf837bc --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/03 fulkerson.tex @@ -0,0 +1,123 @@ + +\section{The Ford-Fulkerson Algorithm} +We now have all the tools we need to construct an algorithm that finds a maximal flow. \\ +It works as follows: +\begin{enumerate} + \item[\texttt{00}] Take a weighted directed graph $G$. + \item[\texttt{01}] Find any flow $F$ in $G$ + \item[\texttt{02}] Calculate $R$, the residual of $F$. + \item[\texttt{03}] ~~~~If $S$ and $T$ are not connected in $R$, $F$ is a maximal flow. \texttt{HALT}. + \item[\texttt{04}] Otherwise, find another flow $F_0$ in $R$. + \item[\texttt{05}] Add $F_0$ to $F$ + \item[\texttt{06}] \texttt{GOTO 02} +\end{enumerate} + +\problem{} +Run the Ford-Fulkerson algorithm on the following graph. \\ +There is extra space on the next page. + +\begin{center} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (-5mm, 0mm) {$S$}; + \node[main] (A) at (20mm, 20mm) {$A$}; + \node[main] (B) at (20mm, 0mm) {$B$}; + \node[main] (C) at (20mm, -20mm) {$C$}; + \node[main] (D) at (50mm, 20mm) {$D$}; + \node[main] (E) at (50mm, 0mm) {$E$}; + \node[main] (F) at (50mm, -20mm) {$F$}; + \node[main] (T) at (75mm, 0mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$8$} (A) + (S) edge node[label] {$7$} (B) + (S) edge node[label] {$4$} (C) + + (A) edge node[label] {$2$} (B) + (B) edge node[label] {$5$} (C) + + (A) edge node[label] {$3$} (D) + (A) edge node[label] {$9$} (E) + (B) edge node[label] {$6$} (E) + (C) edge node[label] {$7$} (E) + (C) edge node[label] {$2$} (F) + + (E) edge node[label] {$3$} (D) + (E) edge node[label] {$4$} (F) + + (D) edge node[label] {$9$} (T) + (E) edge node[label] {$5$} (T) + (F) edge node[label] {$8$} (T) + ; + + \end{tikzpicture} +\end{center} + +\begin{solution} + The maximum flow is $17$. +\end{solution} + +\vspace{5mm} + +\pagebreak + +\begin{center} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S) at (-5mm, 0mm) {$S$}; + \node[main] (A) at (20mm, 20mm) {$A$}; + \node[main] (B) at (20mm, 0mm) {$B$}; + \node[main] (C) at (20mm, -20mm) {$C$}; + \node[main] (D) at (50mm, 20mm) {$D$}; + \node[main] (E) at (50mm, 0mm) {$E$}; + \node[main] (F) at (50mm, -20mm) {$F$}; + \node[main] (T) at (75mm, 0mm) {$T$}; + \end{scope} + + % Edges + \draw[->] + (S) edge node[label] {$8$} (A) + (S) edge node[label] {$7$} (B) + (S) edge node[label] {$4$} (C) + + (A) edge node[label] {$2$} (B) + (B) edge node[label] {$5$} (C) + + (A) edge node[label] {$3$} (D) + (A) edge node[label] {$9$} (E) + (B) edge node[label] {$6$} (E) + (C) edge node[label] {$7$} (E) + (C) edge node[label] {$2$} (F) + + (E) edge node[label] {$3$} (D) + (E) edge node[label] {$4$} (F) + + (D) edge node[label] {$9$} (T) + (E) edge node[label] {$5$} (T) + (F) edge node[label] {$8$} (T) + ; + + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak + +\problem{} +You are given a large network. How can you quickly find an upper bound for the number of iterations the Ford-Fulkerson algorithm will need to find a maximum flow? + +\begin{solution} + Each iteration adds at least one unit of flow. So, we will find a maximum flow in at most $\min(\text{flow out of } S,~\text{flow into } T)$ iterations. + + \vspace{2ex} + + A simpler answer could only count the flow on $S$. + +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/parts/04 applications.tex b/src/Advanced/Graph Algorithms/parts/04 applications.tex new file mode 100755 index 0000000..e648a24 --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/04 applications.tex @@ -0,0 +1,188 @@ + +\section{Applications} + + +\problem{Maximum Cardinality Matching} + +A \textit{matching} is a subset of edges in a bipartite graph. Nodes in a matching must not have more than one edge connected to them. \\ +A matching is \textit{maximal} if it has more edges than any other matching. + +\vspace{5mm} + +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + Initial Graph \\ + \vspace{2mm} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (A1) at (0mm, 24mm) {}; + \node[main] (A2) at (0mm, 18mm) {}; + \node[main] (A3) at (0mm, 12mm) {}; + \node[main] (A4) at (0mm, 6mm) {}; + \node[main] (A5) at (0mm, 0mm) {}; + \node[main] (B1) at (20mm, 24mm) {}; + \node[main] (B2) at (20mm, 18mm) {}; + \node[main] (B3) at (20mm, 12mm) {}; + \node[main] (B4) at (20mm, 6mm) {}; + \node[main] (B5) at (20mm, 0mm) {}; + \end{scope} + + % Edges + \draw + (A1) edge (B2) + (A1) edge (B3) + (A2) edge (B1) + (A2) edge (B4) + (A4) edge (B3) + (A2) edge (B3) + (A5) edge (B3) + (A5) edge (B4) + ; + + \end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}[t]{0.48\textwidth} +\begin{center} + Maximal Matching \\ + \vspace{2mm} + \begin{tikzpicture} + % Nodes + \begin{scope}[layer = nodes] + \node[main] (A1) at (0mm, 24mm) {}; + \node[main] (A2) at (0mm, 18mm) {}; + \node[main] (A3) at (0mm, 12mm) {}; + \node[main] (A4) at (0mm, 6mm) {}; + \node[main] (A5) at (0mm, 0mm) {}; + \node[main] (B1) at (20mm, 24mm) {}; + \node[main] (B2) at (20mm, 18mm) {}; + \node[main] (B3) at (20mm, 12mm) {}; + \node[main] (B4) at (20mm, 6mm) {}; + \node[main] (B5) at (20mm, 0mm) {}; + \end{scope} + + % Edges + \draw[opacity = 0.4] + (A1) edge (B2) + (A1) edge (B3) + (A2) edge (B1) + (A2) edge (B4) + (A4) edge (B3) + (A4) edge (B3) + (A5) edge (B3) + (A5) edge (B4) + ; + \draw + (A1) edge (B2) + (A2) edge (B1) + (A4) edge (B3) + (A5) edge (B4) + ; + \end{tikzpicture} +\end{center} +\end{minipage} + +\vspace{5mm} + +Create an algorithm that finds a maximal matching in any bipartite graph. \\ +Find an upper bound for its runtime. \\ +\hint{Can you modify an algorithm we already know?} + +\begin{solution} + Turn this into a maximum flow problem and use FF. \\ + Connect a node $S$ to all nodes in the left group and a node $T$ to all nodes in the right group. All edges have capacity 1. + + \vspace{2ex} + + Just like FF, this algorithm will take at most $\min(\# \text{ left nodes}, \# \text{ right nodes})$ iterations. +\end{solution} + +\vfill +\pagebreak + +\problem{Supply and Demand} + +Say we have a network of cities and power stations. Stations produce power; cities consume it. + +Each station produces a limited amount of power, and each city has limited demand. + +\vspace{2ex} + +We can represent this power grid as a graph, with cities and stations as nodes and transmission lines as edges. + +\vspace{2ex} + +A simple example is below. There are two cities ($2$ and $4$) and two stations (both $-3$). + +We'll represent station capacity with a negative number, since they \textit{consume} a negative amount of energy. + +\begin{center} + \begin{tikzpicture}[ + node distance = 25mm, + main/.style = { + draw, + circle, + fill = white, + minimum size = 8mm + }, + ] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (S1) {$-3$}; + \node[main] (S2) [below left of = S1] {$-3$}; + \node[main] (C1) [below right of = S1] {$2$}; + \node[main] (C2) [below right of = S2] {$4$}; + \end{scope} + + % Edges + \draw[->] + (S1) edge node[label] {$3$} (S2) + (S1) edge node[label] {$3$} (C1) + (S2) edge node[label] {$2$} (C1) + (S2) edge node[label] {$2$} (C2) + (C1) edge node[label] {$2$} (C2) + ; + \end{tikzpicture} +\end{center} + +We'd like to know if there exists a \textit{feasible circulation} in this network---that is, can we supply our cities with the energy they need without exceeding the capacity of our power plants and transmission lines? + +\vspace{2ex} + +\textbf{Your job:} Devise an algorithm that solve this problem. + +\vspace{2ex} + +\note{\textbf{Bonus:} Say certain edges have a lower bound on their capacity, meaning that we must send \textit{at least} that much flow down the edge. Modify your algorithm to account for these additional constraints.} + + +\begin{solution} + Create a source node $S$, and connect it to each station with an edge. Set the capacity of that edge to the capacity of the station. \\ + + Create a sink node $T$ and do the same for cities. + + \vspace{2ex} + + This is now a maximum-flow problem with one source and one sink. Apply FF. + + \linehack{} + + To solve the bonus problem, we'll modify the network before running the algorithm above. + + \vspace{2ex} + + Say an edge from $A$ to $B$ has minimum capacity $l$ and maximum capacity $u \geq l$. Apply the following transformations: + \begin{itemize} + \item Add $l$ to the capacity of $A$ + \item Subtract $l$ from the capacity of $B$ + \item Subtract $l$ from the total capacity of the edge. + \end{itemize} + + Do this for every edge that has a lower bound then apply the algorithm above. + +\end{solution} + +\vfill +\pagebreak diff --git a/src/Advanced/Graph Algorithms/parts/05 reductions.tex b/src/Advanced/Graph Algorithms/parts/05 reductions.tex new file mode 100755 index 0000000..0ad1859 --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/05 reductions.tex @@ -0,0 +1,123 @@ +\section{Reductions} + +\definition{Independent Sets} +An \textit{independent set} is a set of vertices\footnotemark{} in which no two are connected. $\{B, C, D, E\}$ form an independent set in the following graph: + +\footnotetext{\say{Node} and \say{Vertex} are synonyms in graph theory.} + + +\begin{center} + \begin{tikzpicture}[ + node distance = 12mm + ] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (A) {$A$}; + + + % Patterns are transparent. + % Fill nodes first so paths don't show through + \node[main, draw = white] (B1) [above left of = A] {$\phantom{B}$}; + \node[main, draw = white] (C1) [below left of = A] {$\phantom{C}$}; + \node[main, draw = white] (D1) [below right of = A] {$\phantom{D}$}; + \node[main, draw = white] (E1) [above right of = A] {$\phantom{E}$}; + + \node[main, hatch] (B) [above left of = A] {$B$}; + \node[main, hatch] (C) [below left of = A] {$C$}; + \node[main, hatch] (D) [below right of = A] {$D$}; + \node[main, hatch] (E) [above right of = A] {$E$}; + \end{scope} + + % Edges + \draw + (A) edge (B) + (A) edge (C) + (A) edge (D) + (A) edge (E) + ; + \end{tikzpicture} +\end{center} + + +\definition{Vertex Covers} +A \textit{vertex cover} is a set of vertices that includes at least one endpoint of each edge. $B$ and $D$ form a vertex cover of the following graph: + +\begin{center} + \begin{tikzpicture}[ + node distance = 12mm + ] + % Nodes + \begin{scope}[layer = nodes] + \node[main] (A) {$A$}; + + % Patterns are transparent. + % Fill nodes first so paths don't show through + \node[main, draw = white] (B1) [right of = A] {$\phantom{B}$}; + \node[main, hatch] (B) [right of = A] {$B$}; + \node[main, draw = white] (D1) [below of = B] {$\phantom{D}$}; + \node[main, hatch] (D) [below of = B] {$D$}; + + \node[main] (C) [right of = B] {$C$}; + \node[main] (E) [right of = D] {$E$}; + \end{scope} + + % Edges + \draw + (A) edge (B) + (B) edge (C) + (B) edge (D) + (D) edge (E) + ; + + % Flow + \draw[path] + (B) -- (A) + (B) -- (C) + (B) -- (D) + (D) -- (E) + ; + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak + +\problem{} +Let $G$ be a graph with a set of vertices $V$. \\ + +Show that $S \subset V$ is an independent set iff $(V - S)$ is a vertex cover. \\ + +\hint{$(V - S)$ is the set of elements in $V$ that are not in $S$.} + +\begin{solution} + Suppose $S$ is an independent set. + \begin{itemize} + \item [$\implies$] All edges are in $(V - S)$ or connect $(V - S)$ and $S$. + \item [$\implies$] $(V - S)$ is a vertex cover. + \end{itemize} + + \linehack{} + + Suppose $S$ is a vertex cover. + \begin{itemize} + \item [$\implies$] There are no edges with both endpoints in $(V - S)$. + \item [$\implies$] $(V - S)$ is an independent set. + \end{itemize} +\end{solution} + +\vfill + +\problem{} +Consider the following two problems: +\begin{itemize} + \item Given a graph $G$, determine if it has an independent set of size $\geq k$. + \item Given a graph $G$, determine if it has a vertex cover of size $\leq k$. +\end{itemize} +Show that these are equivalent. In other words, show that an algorithm that solves one can be used to solve the other. + +\begin{solution} + This is a direct consequence of \ref{IndepCover}. You'll need to show that the size constraints are satisfied, but that's fairly easy to do. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Graph Algorithms/parts/06 bonus.tex b/src/Advanced/Graph Algorithms/parts/06 bonus.tex new file mode 100644 index 0000000..3c0790f --- /dev/null +++ b/src/Advanced/Graph Algorithms/parts/06 bonus.tex @@ -0,0 +1,131 @@ +\section{Crosses} + +You are given an $n \times n$ grid. Some of its squares are white, some are gray. Your goal is to place $n$ crosses on white cells so that each row and each column contains exactly one cross. + +\vspace{2ex} + +Here is an example of such a grid, including a possible solution. + +\newcommand{\bx}[2]{ + \draw[ + line width = 1.5mm + ] + (#1 + 0.3, #2 + 0.3) -- (#1 + 0.7, #2 + 0.7) + (#1 + 0.7, #2 + 0.3) -- (#1 + 0.3, #2 + 0.7); +} + +\newcommand{\dk}[2]{ + \draw[ + line width = 0mm, + fill = gray + ] + (#1, #2) -- + (#1 + 1, #2) -- + (#1 + 1, #2 + 1) -- + (#1, #2 + 1); +} + +\begin{center} +\begin{tikzpicture}[ + scale = 0.8 +] + + % Dark squares + \dk{0}{2} + \dk{1}{0} + \dk{1}{1} + \dk{1}{2} + \dk{1}{4} + \dk{2}{2} + \dk{2}{4} + \dk{3}{0} + \dk{3}{1} + \dk{3}{3} + \dk{3}{4} + \dk{4}{3} + \dk{4}{1} + + + % Base grid + \foreach \x in {0,...,5} { + \draw[line width = 0.4mm] + (0, \x) -- (5, \x) + (\x, 0) -- (\x, 5); + } + + % X marks + \bx{0}{4} + \bx{1}{3} + \bx{2}{1} + \bx{3}{2} + \bx{4}{0} +\end{tikzpicture} +\end{center} + +\problem{} +Find a solution for the following grid. + +\begin{center} +\begin{tikzpicture}[ + scale = 1 +] + % Dark squares + \dk{0}{2} + \dk{0}{3} + \dk{0}{6} + \dk{0}{7} + \dk{1}{0} + \dk{1}{1} + \dk{1}{4} + \dk{1}{5} + \dk{1}{6} + \dk{1}{7} + \dk{2}{0} + \dk{2}{1} + \dk{2}{3} + \dk{2}{4} + \dk{2}{5} + \dk{2}{6} + \dk{2}{7} + \dk{3}{1} + \dk{3}{2} + \dk{3}{3} + \dk{3}{4} + \dk{3}{5} + \dk{3}{6} + \dk{4}{0} + \dk{4}{1} + \dk{4}{2} + \dk{4}{3} + \dk{4}{6} + \dk{5}{1} + \dk{5}{4} + \dk{5}{5} + \dk{5}{6} + \dk{6}{0} + \dk{6}{1} + \dk{6}{2} + \dk{6}{3} + \dk{6}{4} + \dk{6}{5} + \dk{7}{0} + \dk{7}{4} + \dk{7}{6} + \dk{7}{7} + + % Base grid + \foreach \x in {0,...,8} { + \draw[line width = 0.4mm] + (0, \x) -- (8, \x) + (\x, 0) -- (\x, 8); + } +\end{tikzpicture} +\end{center} + +\pagebreak + +\problem{} +Turn this into a network flow problem that can be solved with the Ford-Fulkerson algorithm. + +\vfill +\pagebreak diff --git a/src/Advanced/Graph Algorithms/tikxset.tex b/src/Advanced/Graph Algorithms/tikxset.tex new file mode 100644 index 0000000..4991f1d --- /dev/null +++ b/src/Advanced/Graph Algorithms/tikxset.tex @@ -0,0 +1,57 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweaks + >={Latex[ width=2mm, length=2mm ]}, + label/.style = { + circle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white + }, + % + % Flow annotations + flow/.style = { + opacity = 1, + thin, + inner xsep = 2.5mm, + inner ysep = 2.5mm + }, + % + % Paths + path/.style = { + line width = 4mm, + draw = black, + % Lengthen paths so they're + % completely under nodes. + line cap = rect, + opacity = 0.3 + }, + hatch/.style = { + pattern=north west lines, + pattern color=gray + } +} \ No newline at end of file diff --git a/src/Advanced/Intro to Proofs/main.tex b/src/Advanced/Intro to Proofs/main.tex new file mode 100755 index 0000000..0519d7f --- /dev/null +++ b/src/Advanced/Intro to Proofs/main.tex @@ -0,0 +1,339 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + nosolutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Intro to Proofs} +\subtitle{Prepared by Mark on \today{}} + + +\begin{document} + + \maketitle + + + \section{} + + \problem{} + We say an integer $x$ is \textit{even} if $x = 2k$ for some $k \in \mathbb{Z}$. + We say $x$ is \textit{odd} if $x = 2k + 1$ for some $k \in \mathbb{Z}$. \par + Assume that every integer is even or odd, and never both. + + \vspace{2mm} + \begin{itemize}[itemsep=4mm] + \item + Show that the product of two odd integers is odd. + + \item + Let $a, b \in \mathbb{Z}, a \neq 0$. + We say $a$ \textit{divides} $b$ and write $a~|~b$ if there is a $k \in \mathbb{Z}$ so that $ak = b$. + + Show that $a~|~b \implies a~|~2b$ + + \item + Show that $5n^2 + 3n + 7$ is odd for any $n \in \mathbb{Z}$. + + \item + Let $a, b, c$ be integers so that $a^2 + b^2 = c^2$. \par + Show that one of $a, b$ is even. + + \item + Show that every odd integer is the difference of two squares. + + \item + Prove the assumption in the statement of this problem. + \end{itemize} + + + \vfill + \pagebreak + + + + + + + \problem{} + Let $r \in \mathbb{R}$. We say $r$ is \textit{rational} if there exist $p, q \in \mathbb{Z}, q \neq 0$ so that $r = \frac{a}{b}$ + + \vspace{2mm} + \begin{itemize}[itemsep=4mm] + \item Show that $\sqrt{2}$ is irrational. + \item Show that the product of two rational numbers must be rational, while the product of + irrational numbers may be rational or irrational. If you claim a number is irrational, provide + a proof. + \end{itemize} + + \vfill + \pagebreak + + + + + + \problem{} + Let $X = \{x \in \mathbb{Z} ~\bigl|~ x \geq 2 \}$. For $k \geq 2$, define $X_k = \{kx ~\bigl|~ x \in X \}$. \par + What is $X - (X_2 \cup X_3 \cup X_4 \cup ...)$? Prove your claim. + + \vfill + \pagebreak + + + + + + + + \problem{} + Show that there are infinitely may primes. \par + You may use the fact that every integer has a prime factorization. + + + \vfill + \pagebreak + + + + + + \problem{} + For a set $X$, define its \textit{diagonal} as $\text{D}(X) = \{ (x, x) \in X \times X ~\bigl|~ x \in X \}$. + + \vspace{2mm} + + An \textit{undirected graph} $G$ is an ordered pair $(V, E)$, where $V$ is a set, and $E \subset V \times V$ + satisfies $(a, b) \in E \iff (b, a) \in E$ and $E \cap \text{D}(X) = \varnothing$. + + The elements of $V$ are called \textit{vertices}; the elements of $E$ are called \textit{edges}. + + \vspace{2mm} + \begin{itemize}[itemsep=4mm] + + \item Make sense of the conditions on $E$. + + \item The \textit{degree} of a vertex $a$ is the number of edges connected to that vertex. \par + We'll denote this as $d(a)$. Write a formal definition of this function using set-builder notation and the definitions above. + Recall that $|X|$ denotes the size of a set $X$. + + \item There are 9 people at a party. Show that they cannot each have 3 friends. \par + Friendship is always mutual. + \end{itemize} + + \vfill + \pagebreak + + + + + + + \problem{} + Let $f$ be a function from a set $X$ to a set $Y$. We say $f$ is \textit{injective} if $f(x) = f(y) \implies x = y$. \par + We say $f$ is \textit{surjective} if for all $y \in Y$ there exists an $x \in X$ so that $f(x) = y$. \par + Let $A, B, C$ be sets, and let $f: A \to B$, $g: B \to C$ be functions. Let $h = g \circ f$. + + \vspace{2mm} + \begin{itemize} + \item Show that if $h$ is injective, $f$ must be injective and $g$ may not be injective. + \item Show that if $h$ is surjective, $g$ must be surjective and $f$ may not be surjective. + \end{itemize} + + \vfill + \pagebreak + + + + + + + \problem{} + Let $X = \{1, 2, ..., n\}$ for some $n \geq 2$. Let $k \in \mathbb{Z}$ so that $1 \leq k \leq n - 1$. \par + Let $E = \{Y \subset X ~\bigl|~ |Y| = k\}$, $E_1 = \{Y \in E ~\bigl|~ 1 \in Y\}$, and $E_2 = \{Y \in E ~\bigl|~ 1 \notin Y\}$ + + \vspace{2mm} + \begin{itemize}[itemsep=4mm] + \item Show that $\{E_1, E_2\}$ is a partition of $E$. \par + In other words, show that $\varnothing \neq E_1$, $\varnothing \neq E_2$, $E_1 \cup E_2 = E$, and $E_1 \cap E_2 = \varnothing$. \par + \hint{What does this mean in English?} + + \item Compute $|E_1|$, $|E_2|$, and $|E|$. \par + Recall that a set of size $n$ has $\binom{n}{k}$ subsets of size $k$. + + \item Conclude that for any $n$ and $k$ satisfying the conditions above, + $$ + \binom{n-1}{k} + \binom{n-1}{k-1} = \binom{n}{k} + $$ + + \item For $t \in \mathbb{N}$, show that $\binom{2t}{t}$ is even. + + \end{itemize} + + + \vfill + \pagebreak + + + + + + \theorem{The Division Algorithm} + Given two integers $a, b$, we can find two integers $q, r$, where $0 \leq r < b$ and $a = qb + r$. \par + In other words, we can divide $a$ by $b$ to get $q$ remainder $r$. + + \problem{} + Let $x, y \in \mathbb{N}$ be natural numbers. + Consider the set $S = \{ax + by ~\bigl|~ a, b \in \mathbb{Z}, ax + by > 0\}$. \par + The well-ordering principle states that every nonempty subset of the natural numbers has a least element. + + \vspace{4mm} + \begin{itemize}[itemsep=4mm] + \item Show that $S$ has a least element. Call it $d$. + \item Let $z = \text{gcd}(x, y)$. Show that $z$ divides $d$. + \item Show that $d$ divides $x$ and $d$ divides $y$. + \item Prove or disprove $\text{gcd}(x, y) \in S$. + \end{itemize} + + \vfill + \pagebreak + + + + + + \problem{} + + \begin{itemize}[itemsep=4mm] + \item Let $f: X \to Y$ be an injective function. Show that for any two functions $g: Z \to X$ and $h: Z \to X$, + if $f \circ g = f \circ h$ from $Z$ to $Y$ then $g = h$ from $Z$ to $X$. \par + By definition, functions are equal if they agree on every input in their domain. \par + \hint{This is a one-line proof.} + + + \item Let $f: X \to Y$ be a surjective function. + Show that for any two functions $g: Y \to W$ and $h: Y \to W$, if + $g \circ f = h \circ f \implies g = h$. + + \item[$\star$] Let $f: X \to Y$ be a function where for any set $Z$ and functions $g: Z \to X$ and $h: Z \to X$, + $f \circ g = f \circ h \implies g = h$. Show that $f$ is injective. + + \item[$\star$] Let $f: X \to Y$ be a function where for any set $W$ and functions $g: Y \to W$ and $h: Y \to W$, + $g \circ f = h \circ f \implies g = h$. Show f is surjective. + \end{itemize} + + \vfill + \pagebreak + + + + + + + \problem{} + In this problem we prove the binomial theorem: + for $a, b \in \mathbb{R}$ and $n \in \mathbb{Z}^+$\hspace{-0.5ex}, we have + $$ + (a + b)^n = \sum_{k=0}^n \binom{n}{k}a^kb^{N-k} + $$ + In the proof below, we let $a$ and $b$ be arbitrary numbers. + + \vspace{4mm} + \begin{itemize} + \item Check that this formula works for $n = 0$. Also, check a few small $n$ + to get a sense of what's going on. + + \item Let $N \in \mathbb{N}$. Suppose we know that for a specific value of $N$, + $$ + (a + b)^N = \sum_{k=0}^N \binom{N}{k}a^kb^{N-k} + $$ + Now, show that this formula also works for $N + 1$. + + \item Conclude that this formula works for all $a, b \in \mathbb{R}$ and $n \in \mathbb{Z}^+$\hspace{-0.5ex}. + \end{itemize} + + \vfill + \pagebreak + + + + + + \problem{} + A \textit{relation} on a set $X$ is an $R \subset X \times X$. \par + \begin{itemize} + \item We say $R$ is \textit{reflexive} if $(x,x) \in R$ for all $x \in X$. + \item We say $R$ is \textit{symmetric} if $(x, y) \in R \implies (y, x) \in R$. + \item We say $R$ is \textit{transitive} if $(x, y) \in R$ and $(y, z) \in R$ imply $(x, z) \in R$. + \item We say $R$ is an \textit{equivalence relation} if it is reflexive, symmetric, and transitive. + \end{itemize} + Say we have a set $X$ and an equivalence relation $R$. \par + The \textit{equivalence class} of an element $x \in X$ is the set $\{y \in X ~\bigl|~ (x, y) \in R\}$. + + + \vspace{4mm} + + Let $R$ be an equivalence relation on a set $X$. \par + Show that the set of equivalence classes is a partition of $X$. + + \vfill + \pagebreak + + \problem{} + Show that there exist two positive irrational numbers $a$ and $b$ so that $a^b$ is rational. + + % Solution: a = b = root 2, check all cases + % if irrational,a=rt, s = rt^rt, which is rational + + \vfill + + \problem{} + Show that the following holds for any planar graph: + $$ + \text{vertices} - \text{edges} + \text{faces} = 2 + $$ + \hint{If you don't know what these words mean, ask an instructor.} + + + \vfill + \pagebreak + + \problem{} + Consider a rectangular chocolate bar of arbitrary size. \par + What is the minimum number of breaks you need to make to + separate all its pieces? + + \begin{solution} + number of squares minus one, simple proof by induction. + \end{solution} + + \vfill + + \problem{} + Four travellers are on a plane, each moving along a straight line at an arbitrary constant speed. \par + No two of their paths are parallel, and no three intersect at the same point. \par + We know that traveller A has met traveler B, C, and D, and that B has met C and D (and A). \par + Show that C and D must also have met. + + \begin{solution} + When a body travels at a constant speed, its graph with respect to time is a straight line. \par + So, we add time axis in the third dimension, perpendicular to our plane. \par + Naturally, the projection of each of these onto the plane corresponds to a road. + + Now, note that two intersecting lines define a plane and use the conditions in the problem to show that no two lines are parallel. + \end{solution} + + + \vfill + + + \problem{} + Say we have an $n$-gon with non-intersecting edges. \par + What is the size of the smallet set of vertices that can \say{see} every point inside the polygon? + \vfill + \pagebreak +\end{document} \ No newline at end of file diff --git a/src/Advanced/Intro to Proofs/meta.toml b/src/Advanced/Intro to Proofs/meta.toml new file mode 100644 index 0000000..8e885f4 --- /dev/null +++ b/src/Advanced/Intro to Proofs/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Intro to Proofs" + +[publish] +handout = true +solutions = false diff --git a/src/Advanced/Introduction to Quantum/Tectonic.toml b/src/Advanced/Introduction to Quantum/Tectonic.toml new file mode 100644 index 0000000..f83cea0 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/Tectonic.toml @@ -0,0 +1,38 @@ +[doc] +name = "Definable Sets" +bundle = "https://data1.fullyjustified.net/tlextras-2022.0r0.tar" + +extra_paths = [ + "../../resources" +] + +[doc.metadata] +publish = true +show_solutions = true +title = "Definable Sets" +description = "" +favorite = false + + +[[output]] +shell_escape = false +tex_format = "latex" +type = "pdf" + +name = "handout" +inputs = [ + { inline = "\\def\\argNoSolutions{1}" }, + "week 1.tex" +] + + +[[output]] +shell_escape = false +tex_format = "latex" +type = "pdf" + +name = "solutions" +inputs = [ + { inline = "\\def\\argYesSolutions{1}" }, + "week 1.tex" +] diff --git a/src/Advanced/Introduction to Quantum/main.tex b/src/Advanced/Introduction to Quantum/main.tex new file mode 100755 index 0000000..34a3cd3 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/main.tex @@ -0,0 +1,29 @@ +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} +\usepackage{units} +\input{src/tikzset} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Intro to Quantum Computing} +\subtitle{Prepared by Mark on \today{}} + +\def\ket#1{\left|#1\right\rangle} +\def\bra#1{\left\langle#1\right|} + +\begin{document} + + \maketitle + + \input{src/parts/01 bits} + \input{src/parts/02 qubit} + \input{src/parts/03 two qubits} + \input{src/parts/04 logic gates} + \input{src/parts/05 quantum gates} + \input{src/parts/06 hxh} + \input{src/parts/07 superdense} + \input{src/parts/08 teleport} +\end{document} \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/meta.toml b/src/Advanced/Introduction to Quantum/meta.toml new file mode 100644 index 0000000..27d5132 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Quantum Computing" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Introduction to Quantum/src/main.tex b/src/Advanced/Introduction to Quantum/src/main.tex new file mode 100755 index 0000000..4708319 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/main.tex @@ -0,0 +1,54 @@ +% Copyright (C) 2023 +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% You may have received a copy of the GNU General Public License +% along with this program. If not, see . +% +% +% +% If you edit this, please give credit! +% Quality handouts take time to make. + +% use the [nosolutions] flag to hide solutions, +% use the [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../../lib/tex/ormc_handout} +\usepackage{../../../../lib/tex/macros} +\usepackage{units} +\input{tikzset} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Intro to Quantum Computing} +\subtitle{Prepared by Mark on \today{}} + +\def\ket#1{\left|#1\right\rangle} +\def\bra#1{\left\langle#1\right|} + + +% TODO: spend more time on probabalastic bits. +% This could even be its own handout, especially +% for younger classes! + +% Why are qubits amplitudes instead of probabilities? +% (Asher question) + +\begin{document} + + \maketitle + + \input{parts/01 bits} + \input{parts/02 qubit} + \input{parts/03 two qubits} + \input{parts/04 logic gates} + \input{parts/05 quantum gates} + \input{parts/06 hxh} + \input{parts/07 superdense} + \input{parts/08 teleport} +\end{document} \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/src/parts/01 bits.tex b/src/Advanced/Introduction to Quantum/src/parts/01 bits.tex new file mode 100644 index 0000000..6a98c52 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/01 bits.tex @@ -0,0 +1,565 @@ +\section{Probabilistic Bits} + + +\definition{} + +As we already know, a \textit{classical bit} may take the values \texttt{0} and \texttt{1}. \par +We can model this with a two-sided coin, one face of which is labeled \texttt{0}, and the other, \texttt{1}. \par + +\vspace{2mm} + +Of course, if we toss such a \say{bit-coin,} we'll get either \texttt{0} or \texttt{1}. \par +We'll denote the probability of getting \texttt{0} as $p_0$, and the probability of getting \texttt{1} as $p_1$. \par +As with all probabilities, $p_0 + p_1$ must be equal to 1. + + +\vfill + + +\definition{} + +Say we toss a \say{bit-coin} and don't observe the result. We now have a \textit{probabilistic bit}, with a probability $p_0$ +of being \texttt{0}, and a probability $p_1$ of being \texttt{1}. + +\vspace{2mm} + +We'll represent this probabilistic bit's \textit{state} as a vector: +$\left[\begin{smallmatrix} + p_0 \\ p_1 +\end{smallmatrix}\right]$ \par +We do \textbf{not} assume this coin is fair, and thus $p_0$ might not equal $p_1$. + +\note{ + This may seem a bit redundant: since $p_0 + p_1$, we can always calculate one probability given the other. \\ + We'll still include both probabilities in the state vector, since this provides a clearer analogy to quantum bits. +} + + +\vfill + + +\definition{} + +The simplest probabilistic bit states are of course $[0]$ and $[1]$, defined as follows: +\begin{itemize} + \item $[0] = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right]$ + \item $[1] = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right]$ +\end{itemize} +That is, $[0]$ represents a bit that we known to be \texttt{0}, \par +and $[1]$ represents a bit we know to be \texttt{1}. + +\vfill + + +\definition{} +$[0]$ and $[1]$ form a \textit{basis} for all possible probabilistic bit states: \par +Every other probabilistic bit can be written as a \textit{linear combination} of $[0]$ and $[1]$: + +\begin{equation*} + \begin{bmatrix} p_0 \\ p_1 \end{bmatrix} + = + p_0 \begin{bmatrix} 1 \\ 0 \end{bmatrix} + + p_1 \begin{bmatrix} 0 \\ 1 \end{bmatrix} + = + p_0 [0] + p_1 [1] +\end{equation*} + + +\vfill +\pagebreak + +\problem{} +Every possible state of a probabilistic bit is a two-dimensional vector. \par +Draw all possible states on the axis below. + + +\begin{center} + \begin{tikzpicture}[scale = 2.0] + \fill[color = black] (0, 0) circle[radius=0.05]; + \node[below left] at (0, 0) {$\left[\begin{smallmatrix} 0 \\ 0 \end{smallmatrix}\right]$}; + + \draw[->] (0, 0) -- (1.2, 0); + \node[right] at (1.2, 0) {$p_0$}; + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below] at (1, 0) {$[0]$}; + + \draw[->] (0, 0) -- (0, 1.2); + \node[above] at (0, 1.2) {$p_1$}; + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[left] at (0, 1) {$[1]$}; + \end{tikzpicture} +\end{center} + +\begin{solution} + \begin{center} + \begin{tikzpicture}[scale = 2.0] + \fill[color = black] (0, 0) circle[radius=0.05]; + \node[below left] at (0, 0) {$\left[\begin{smallmatrix} 0 \\ 0 \end{smallmatrix}\right]$}; + + \draw[ored, -, line width = 2] (0, 1) -- (1, 0); + + + \draw[->] (0, 0) -- (1.2, 0); + \node[right] at (1.2, 0) {$p_0$}; + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below] at (1, 0) {$[0]$}; + + \draw[->] (0, 0) -- (0, 1.2); + \node[above] at (0, 1.2) {$p_1$}; + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[left] at (0, 1) {$[1]$}; + \end{tikzpicture} + \end{center} +\end{solution} + + +\vfill +\pagebreak + + + + + +\section{Measuring Probabilistic Bits} + + +\definition{} +As we noted before, a probabilistic bit represents a coin we've tossed but haven't looked at. \par +We do not know whether the bit is \texttt{0} or \texttt{1}, but we do know the probability of both of these outcomes. \par + +\vspace{2mm} + +If we \textit{measure} (or \textit{observe}) a probabilistic bit, we see either \texttt{0} or \texttt{1}---and thus our +knowledge of its state is updated to either $[0]$ or $[1]$, since we now certainly know what face the coin landed on. + +\vspace{2mm} + +Since measurement changes what we know about a probabilistic bit, it changes the probabilistic bit's state. +When we measure a bit, it's state \textit{collapses} to either $[0]$ or $[1]$, and the original state of the +bit vanishes. We \textit{cannot} recover the state $[x_0, x_1]$ from a measured probabilistic bit. + + +\definition{Multiple bits} +Say we have two probabilistic bits, $x$ and $y$, \par +with states +$[x]=[ x_0, x_1]$ +and +$[y]=[y_0, y_1]$ + +\vspace{2mm} + +The \textit{compound state} of $[x]$ and $[y]$ is exactly what it sounds like: \par +It is the probabilistic two-bit state $\ket{xy}$, where the probabilities of the first bit are +determined by $[x]$, and the probabilities of the second are determined by $[y]$. + + + + +\problem{} +Say $[x] = [\nicefrac{2}{3}, \nicefrac{1}{3}]$ and $[y] = [\nicefrac{3}{4}, \nicefrac{1}{4}]$. \par +\begin{itemize}[itemsep = 1mm] + \item If we measure $x$ and $y$ simultaneously, \par + what is the probability of getting each of \texttt{00}, \texttt{01}, \texttt{10}, and \texttt{11}? + + + \item If we measure $y$ first and observe \texttt{1}, \par + what is the probability of getting each of \texttt{00}, \texttt{01}, \texttt{10}, and \texttt{11}? +\end{itemize} +\note[Note]{$[x]$ and $[y]$ are column vectors, but I've written them horizontally to save space.} + + +\vfill + + + + + +\problem{} +Say $[x] = [\nicefrac{2}{3}, \nicefrac{1}{3}]$ and $[y] = [\nicefrac{3}{4}, \nicefrac{1}{4}]$. \par +What is the probability that $x$ and $y$ produce different outcomes? + +\vfill +\pagebreak + + + + + + + + + + + +\section{Tensor Products} + +\definition{Tensor Products} +The \textit{tensor product} of two vectors is defined as follows: +\begin{equation*} + \begin{bmatrix} + x_1 \\ x_2 + \end{bmatrix} + \otimes + \begin{bmatrix} + y_1 \\ y_2 + \end{bmatrix} += + \begin{bmatrix} + x_1 + \begin{bmatrix} + y_1 \\ y_2 + \end{bmatrix} + + \\[4mm] + + x_2 + \begin{bmatrix} + y_1 \\ y_2 + \end{bmatrix} + \end{bmatrix} += + \begin{bmatrix} + x_1y_1 \\[1mm] + x_1y_2 \\[1mm] + x_2y_1 \\[1mm] + x_2y_2 \\[0.5mm] + \end{bmatrix} +\end{equation*} + + +That is, we take our first vector, multiply the second +vector by each of its components, and stack the result. +You could think of this as a generalization of scalar +mulitiplication, where scalar mulitiplication is a +tensor product with a vector in $\mathbb{R}^1$: +\begin{equation*} + a + \begin{bmatrix} + x_1 \\ x_2 + \end{bmatrix} += + \begin{bmatrix} + a_1 + \end{bmatrix} + \otimes + \begin{bmatrix} + y_1 \\ y_2 + \end{bmatrix} += + \begin{bmatrix} + a_1 + \begin{bmatrix} + y_1 \\ y_2 + \end{bmatrix} + \end{bmatrix} += + \begin{bmatrix} + a_1y_1 \\[1mm] + a_1y_2 + \end{bmatrix} +\end{equation*} + +\problem{} +Say $x \in \mathbb{R}^n$ and $y \in \mathbb{R}^m$. \par +What is the dimension of $x \otimes y$? + +\vfill + +\problem{} +What is the pairwise tensor product +$ +\Bigl\{ + \left[ + \begin{smallmatrix} + 1 \\ 0 \\ 0 + \end{smallmatrix} + \right], + \left[ + \begin{smallmatrix} + 0 \\ 1 \\ 0 + \end{smallmatrix} + \right], + \left[ + \begin{smallmatrix} + 0 \\ 0 \\ 1 + \end{smallmatrix} + \right] +\Bigr\} +\otimes +\Bigl\{ + \left[ + \begin{smallmatrix} + 1 \\ 0 + \end{smallmatrix} + \right], + \left[ + \begin{smallmatrix} + 0 \\ 1 + \end{smallmatrix} + \right] +\Bigr\} +$? + +\note{in other words, distribute the tensor product between every pair of vectors.} + +\vfill + + + + + + + + + + +\problem{} +What is the \textit{span} of the vectors we found in \ref{basistp}? \par +In other words, what is the set of vectors that can be written as linear combinations of the vectors above? + +\vfill + +% This is wrong, but there's something here. +% maybe fix later? +% +%Look through the above problems and convince yourself of the following fact: \par +%If $a$ is a basis of $A$ and $b$ is a basis of $B$, $a \otimes b$ is a basis of $A \times B$. \par +%\note{If you don't understand what this says, ask an instructor. \\ This is the reason we did the last few problems!} +% +%\begin{instructornote} +% \textbf{The idea here is as follows:} +% +% If $a$ is in $\{\texttt{0}, \texttt{1}\}$ and $b$ is in $\{\texttt{0}, \texttt{1}\}$, +% the values $ab$ can take are +% $\{\texttt{0}, \texttt{1}\} \times \{\texttt{0}, \texttt{1}\} = \{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$. +% +% \vspace{2mm} +% +% The same is true of any other state set: if $a$ takes values in $A$ and $b$ takes values in $B$, \par +% the compound state $(a,b)$ takes values in $A \times B$. +% +% \vspace{2mm} +% +% We would like to do the same with probabilistic bits. \par +% Given bits $\ket{a}$ and $\ket{b}$, how should we represent the state of $\ket{ab}$? +%\end{instructornote} + +\pagebreak + + + + + + +\problem{} +Say $[x] = [\nicefrac{2}{3}, \nicefrac{1}{3}]$ and $[y] = [\nicefrac{3}{4}, \nicefrac{1}{4}]$. \par +What is $[x] \otimes [y]$? How does this relate to \ref{firstcompoundstate}? + +\vfill + + + +\problem{} +The compound state of two vector-form bits is their tensor product. \par +Compute the following. Is the result what we'd expect? +\begin{itemize} + \item $[0] \otimes [0]$ + \item $[0] \otimes [1]$ + \item $[1] \otimes [0]$ + \item $[1] \otimes [1]$ +\end{itemize} +\hint{ + Remember that + $[0] = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right]$ + and + $[1] = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right]$. +} + + +\vfill + + + + + + + + + +\problem{} +Of course, writing $[0] \otimes [1]$ is a bit excessive. We'll shorten this notation to $[01]$. \par + +\vspace{2mm} + +In fact, we could go further: if we wanted to write the set of bits $[1] \otimes [1] \otimes [0] \otimes [1]$, \par +we could write $[1101]$---but a shorter alternative is $[13]$, since $13$ is \texttt{1101} in binary. + +\vspace{2mm} + +Write $[5]$ as three-bit probabilistic state. \par + +\begin{solution} + $[5] = [101] = [1] \otimes [0] \otimes [1] = [0,0,0,0,0,1,0,0]^T$ \par + Notice how we're counting from the top, with $[000] = [1,0,...,0]$ and $[111] = [0, ..., 0, 1]$. +\end{solution} + +\vfill + + + + + + +\problem{} +Write the three-bit states $[0]$ through $[7]$ as column vectors. \par +\hint{You do not need to compute every tensor product. Do a few and find the pattern.} + + + + + + +\vfill +\pagebreak + + + + + + + + + + + + + + + + + +\section{Operations on Probabilistic Bits} + +Now that we can write probabilistic bits as vectors, we can represent operations on these bits +with linear transformations---in other words, as matrices. + +\definition{} +Consider the NOT gate, which operates as follows: \par +\begin{itemize} + \item $\text{NOT}[0] = [1]$ + \item $\text{NOT}[1] = [0]$ +\end{itemize} +What should NOT do to a probabilistic bit $[x_0, x_1]$? \par +If we return to our coin analogy, we can think of the NOT operation as +flipping a coin we have already tossed, without looking at its state. +Thus, +\begin{equation*} + \text{NOT} \begin{bmatrix} + x_0 \\ x_1 + \end{bmatrix} = \begin{bmatrix} + x_1 \\ x_0 + \end{bmatrix} +\end{equation*} + + +\begin{ORMCbox}{Review: Multiplying Vectors by Matrices}{black!10!white}{black!65!white} + \begin{equation*} + Av = + \begin{bmatrix} + 1 & 2 \\ + 3 & 4 \\ + \end{bmatrix} + \begin{bmatrix} + v_0 \\ v_1 + \end{bmatrix} + = + \begin{bmatrix} + 1v_0 + 2v_1 \\ + 3v_0 + 4v_1 + \end{bmatrix} + \end{equation*} + + Note that each element of $Av$ is the dot product of a row in $A$ and a column in $v$. +\end{ORMCbox} + +\problem{} +Compute the following product: +\begin{equation*} + \begin{bmatrix} + 1 & 0.5 \\ 0 & 1 + \end{bmatrix} + \begin{bmatrix} + 3 \\ 2 + \end{bmatrix} +\end{equation*} + + +\vfill + +\generic{Remark:} +Also, recall that every matrix is linear map, and that every linear map may be written as a matrix. \par +We often use the terms \textit{matrix}, \textit{transformation}, and \textit{linear map} interchangeably. + +\pagebreak + + +\problem{} +Find the matrix that represents the NOT operation on one probabilistic bit. + +\begin{solution} + \begin{equation*} + \begin{bmatrix} + 0 & 1 \\ 1 & 0 + \end{bmatrix} + \end{equation*} +\end{solution} + +\vfill + + +\problem{Extension by linearity} +Say we have an arbitrary operation $M$. \par +If we know how $M$ acts on $[1]$ and $[0]$, can we compute $M[x]$ for an arbitrary state $[x]$? \par +Say $[x] = [x_0, x_1]$. +\begin{itemize} + \item What is the probability we observe $0$ when we measure $x$? + \item What is the probability that we observe $M[0]$ when we measure $Mx$? +\end{itemize} + +\vfill + +\problem{} +Write $M[x_0, x_1]$ in terms of $M[0]$, $M[1]$, $x_0$, and $x_1$. + + +\begin{solution} + \begin{equation*} + M \begin{bmatrix} + x_0 \\ x_1 + \end{bmatrix} + = + x_0 M \begin{bmatrix} + 1 \\ 0 + \end{bmatrix} + + + x_1 M \begin{bmatrix} + 0 \\ 1 + \end{bmatrix} + = + x_0 M [0] + + x_1 M [1] + \end{equation*} +\end{solution} + + + +\vfill + +\generic{Remark:} +Every matrix represents a \textit{linear} map, so the following is always true: +\begin{equation*} + A \times (px + qy) = pAx + qAy +\end{equation*} +\ref{linearextension} is just a special case of this fact. + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/src/parts/02 qubit.tex b/src/Advanced/Introduction to Quantum/src/parts/02 qubit.tex new file mode 100644 index 0000000..f302e19 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/02 qubit.tex @@ -0,0 +1,347 @@ +\section{One Qubit} + +Quantum bits (or \textit{qubits}) are very similar to probabilistic bits, but have one major difference: \par +probabilities are replaced with \textit{amplitudes}. + +\vspace{2mm} +Of course, a qubit can take the values \texttt{0} and \texttt{1}, which are denoted $\ket{0}$ and $\ket{1}$. \par +Like probabilistic bits, a quantum bit is written as a linear combination of $\ket{0}$ and $\ket{1}$: +\begin{equation*} + \ket{\psi} = \psi_0\ket{0} + \psi_1\ket{1} +\end{equation*} +Such linear combinations are called \textit{superpositions}. + +\vspace{2mm} + +The $\ket{~}$ you see in the expressions above is called a \say{ket,} and denotes a column vector. \par +$\ket{0}$ is pronounced \say{ket zero,} and $\ket{1}$ is pronounced \say{ket one.} This is called bra-ket notation. \par +\note[Note]{$\bra{0}$ is called a \say{bra,} but we won't worry about that for now.} + +\vspace{2mm} +This is very similar to the \say{box} $[~]$ notation we used for probabilistic bits. \par +As before, we will write $\ket{0} = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right]$ +and $\ket{1} = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right]$. + + +\vspace{8mm} + +Recall that probabilistic bits are subject to the restriction that $p_0 + p_1 = 1$. \par +Quantum bits have a similar condition: $\psi_0^2 + \psi_1^2 = 1$. \par +Note that this implies that $\psi_0$ and $\psi_1$ are both in $[-1, 1]$. \par +Quantum amplitudes may be negative, but probabilistic bit probabilities cannot. + +\vspace{2mm} + +If we plot the set of valid quantum states on our plane, we get a unit circle centered at the origin: + +\begin{center} + \begin{tikzpicture}[scale=1.5] + \draw[dashed] (0,0) circle(1); + + \fill[color = black] (0, 0) circle[radius=0.05]; + + \draw[->] (0, 0) -- (1.2, 0); + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below right] at (1, 0) {$\ket{0}$}; + + \draw[->] (0, 0) -- (0, 1.2); + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[above left] at (0, 1) {$\ket{1}$}; + + \fill[color = ored] (0.87, 0.5) circle[radius=0.05]; + \node[above right] at (0.87, 0.5) {$\ket{\psi}$}; + \end{tikzpicture} +\end{center} + + + +Recall that the set of probabilistic bits forms a line instead: + + +\begin{center} + \begin{tikzpicture}[scale = 1.5] + \fill[color = black] (0, 0) circle[radius=0.05]; + \node[below left] at (0, 0) {$\left[\begin{smallmatrix} 0 \\ 0 \end{smallmatrix}\right]$}; + + \draw[ored, -, line width = 2] (0, 1) -- (1, 0); + + + \draw[->] (0, 0) -- (1.2, 0); + \node[right] at (1.2, 0) {$p_0$}; + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below] at (1, 0) {$[0]$}; + + \draw[->] (0, 0) -- (0, 1.2); + \node[above] at (0, 1.2) {$p_1$}; + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[left] at (0, 1) {$[1]$}; + \end{tikzpicture} +\end{center} + + +\problem{} +In the above unit circle, the counterclockwise angle from $\ket{0}$ to $\ket{\psi}$ is $30^\circ$\hspace{-1ex}. \par +Write $\ket{\psi}$ as a linear combination of $\ket{0}$ and $\ket{1}$. + + +\vfill +\pagebreak + + +\definition{Measurement I} +Just like a probabilistic bit, we must observed $\ket{0}$ or $\ket{1}$ when we measure a qubit. \par +If we were to measure $\ket{\psi} = \psi_0\ket{0} + \psi_1\ket{1}$, we'd observe either $\ket{0}$ or $\ket{1}$, \par +with the following probabilities: +\begin{itemize}[itemsep = 2mm, topsep = 2mm] + \item $\mathcal{P}(\ket{1}) = \psi_1^2$ + \item $\mathcal{P}(\ket{0}) = \psi_0^2$ +\end{itemize} +\note{Note that $\mathcal{P}(\ket{0}) + \mathcal{P}(\ket{1}) = 1$.} + + +\vspace{2mm} + +As before, $\ket{\psi}$ \textit{collapses} when it is measured: its state becomes that which we observed in our measurement, +leaving no trace of the previous superposition. \par + + + + + + + + + + + + +\problem{} +\begin{itemize} + \item What is the probability we observe $\ket{0}$ when we measure $\ket{\psi}$? \par + \item What can we observe if we measure $\ket{\psi}$ a second time? \par + \item What are these probabilities for $\ket{\varphi}$? +\end{itemize} + + + +\begin{center} + \begin{tikzpicture}[scale=1.5] + \draw[dashed] (0,0) circle(1); + + \fill[color = black] (0, 0) circle[radius=0.05]; + + \draw[->] (0, 0) -- (1.2, 0); + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below right] at (1, 0) {$\ket{0}$}; + + \draw[->] (0, 0) -- (0, 1.2); + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[above left] at (0, 1) {$\ket{1}$}; + + \draw[dotted] (0, 0) -- (0.87, 0.5); + \draw[color=gray,->] (0.5, 0.0) arc (0:30:0.5); + \node[right, color=gray] at (0.47, 0.12) {$30^\circ$}; + \fill[color = ored] (0.87, 0.5) circle[radius=0.05]; + \node[above right] at (0.87, 0.5) {$\ket{\psi}$}; + + + \draw[dotted] (0, 0) -- (-0.707, -0.707); + \draw[color=gray,->] (0.25, 0.0) arc (0:-135:0.25); + \node[below, color=gray] at (0.2, -0.2) {$135^\circ$}; + \fill[color = ored] (-0.707, -0.707) circle[radius=0.05]; + \node[below left] at (-0.707, -0.707) {$\ket{\varphi}$}; + \end{tikzpicture} +\end{center} + + + +\vfill + +As you may have noticed, we don't need two coordinates to fully define a quibit's state. \par +We can get by with one coordinate just as well. + +Instead of referring to each state using its cartesian coordinates $\psi_0$ and $\psi_1$, \par +we can address it using its \textit{polar angle} $\theta$, measured from $\ket{0}$ counterclockwise: + +\begin{center} + \begin{tikzpicture}[scale=1.5] + \draw[dashed] (0,0) circle(1); + \fill[color = black] (0, 0) circle[radius=0.05]; + + \draw[dotted] (0, 0) -- (0.707, 0.707); + \draw[color=gray,->] (0.5, 0.0) arc (0:45:0.5); + \node[above right, color=gray] at (0.5, 0) {$\theta$}; + + \draw[->] (0, 0) -- (1.2, 0); + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below right] at (1, 0) {$\ket{0}$}; + + \draw[->] (0, 0) -- (0, 1.2); + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[above left] at (0, 1) {$\ket{1}$}; + + \fill[color = ored] (0.707, 0.707) circle[radius=0.05]; + \node[above right] at (0.707, 0.707) {$\ket{\psi}$}; + \end{tikzpicture} +\end{center} + + +\problem{} +Find $\psi_0$ and $\psi_1$ in terms of $\theta$ for an arbitrary qubit $\psi$. + + +\vfill +\pagebreak + + +\problem{} +Consider the following qubit states: + +\null\hfill\begin{minipage}{0.48\textwidth} + \begin{equation*} + \ket{+} = \frac{\ket{0} + \ket{1}}{\sqrt{2}} + \end{equation*} +\end{minipage}\hfill\begin{minipage}{0.48\textwidth} + \begin{equation*} + \ket{-} = \frac{\ket{0} - \ket{1}}{\sqrt{2}} + \end{equation*} +\end{minipage}\hfill\null + +\begin{itemize} + \item Where are these on the unit circle? + \item What are their polar angles? + \item What are the probabilities of observing $\ket{0}$ and $\ket{1}$ when measuring $\ket{+}$ and $\ket{-}$? +\end{itemize} + +\vfill + +\begin{center} + \begin{tikzpicture}[scale = 2.5] + \draw[dashed] (0,0) circle(1); + \fill[color = black] (0, 0) circle[radius=0.05]; + + \draw[->] (0, 0) -- (1.2, 0); + \fill[color = oblue] (1, 0) circle[radius=0.05]; + \node[below right] at (1, 0) {$\ket{0}$}; + + \draw[->] (0, 0) -- (0, 1.2); + \fill[color = oblue] (0, 1) circle[radius=0.05]; + \node[above left] at (0, 1) {$\ket{1}$}; + \end{tikzpicture} +\end{center} + +\vfill +\vfill +\pagebreak + + +\section{Operations on One Qubit} + +We may apply transformations to qubits just as we apply transformations to probabilistic bits. +Again, we'll represent transformations as $2 \times 2$ matrices, since we want to map +one qubit state to another. \par +\note{In other words, we want to map elements of $\mathbb{R}^2$ to elements of $\mathbb{R}^2$.} \par +We will call such maps \textit{quantum gates,} since they are the quantum equivalent of classical logic gates. + + +\vspace{2mm} + +There are two conditions a valid quantum gate $G$ must satisfy: +\begin{itemize}[itemsep = 1mm] + \item For any valid state $\ket{\psi}$, $G\ket{\psi}$ is a valid state. \par + Namely, $G$ must preserve the length of any vector it is applied to. \par + Recall that the set of valid quantum states is the set of unit vectors in $\mathbb{R}^2$ + + \item Any quantum gate must be \textit{invertible}. \par + We'll skip this condition for now, and return to it later. +\end{itemize} +In short, a quantum gate is a linear map that maps the unit circle to itself. \par +There are only two kinds of linear maps that do this: reflections and rotations. + +\problem{} +The $X$ gate is the quantum analog of the \texttt{not} gate, defined by the following table: +\begin{itemize} + \item $X\ket{0} = \ket{1}$ + \item $X\ket{1} = \ket{0}$ +\end{itemize} +Find the matrix $X$. + +\begin{solution} + \begin{equation*} + \begin{bmatrix} + 0 & 1 \\ 1 & 0 + \end{bmatrix} + \end{equation*} +\end{solution} + +\vfill + +\problem{} +What is $X\ket{+}$ and $X\ket{-}$? \par +\hint{Remember that all matrices are linear maps. What does this mean?} + +\begin{solution} + $X\ket{+} = \ket{+}$ and $X\ket{-} = -\ket{-}$ (that is, negative ket-minus). \par + Most notably, remember that $G(a\ket{0} + b\ket{1}) = aG\ket{0} + bG\ket{1}$ +\end{solution} + +\vfill + + +\problem{} +In terms of geometric transformations, what does $X$ do to the unit circle? + +\begin{solution} + It is a reflection about the $45^\circ$ axis. +\end{solution} + +\vfill +\pagebreak + + +\problem{} +Let $Z$ be a quantum gate defined by the following table: \par +\begin{itemize} + \item $Z\ket{0} = \ket{0}$, + \item $Z\ket{1} = -\ket{1}$. +\end{itemize} +What is the matrix $Z$? What are $Z\ket{+}$ and $Z\ket{-}$? \par +What is $Z$ as a geometric transformation? + +\vfill + +\problem{} +Is the map $B$ defined by the table below a valid quantum gate? +\begin{itemize} + \item $B\ket{0} = \ket{0}$ + \item $B\ket{1} = \ket{+}$ +\end{itemize} +\hint{Find a $\ket{\psi}$ so that $B\ket{\psi}$ is not a valid qubit state} + +\begin{solution} + $B\ket{+} = \frac{1 + \sqrt{2}}{2}\ket{0} + \frac{1}{2}\ket{1}$, which has a non-unit length of $\frac{\sqrt{2} + 1}{\sqrt{2}}$. +\end{solution} + +\vfill + + + +\problem{Rotation} +As we noted earlier, any rotation about the center is a valid quantum gate. \par +Let's derive all transformations of this form. +\begin{itemize}[itemsep = 1mm] + \item Let $U_\phi$ be the matrix that represents a counterclockwise rotation of $\phi$ degrees. \par + What is $U\ket{0}$ and $U\ket{1}$? + + \item Find the matrix $U_\phi$ for an arbitrary $\phi$. +\end{itemize} + +\vfill + + +\problem{} +Say we have a qubit that is either $\ket{+}$ or $\ket{-}$. We do not know which of the two states it is in. \par +Using one operation and one measurement, how can we find out, for certain, which qubit we received? \par + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/src/parts/03 two qubits.tex b/src/Advanced/Introduction to Quantum/src/parts/03 two qubits.tex new file mode 100644 index 0000000..d62b60f --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/03 two qubits.tex @@ -0,0 +1,145 @@ +\section{Two Qubits} + + +\definition{} +Just as before, we'll represent multi-qubit states as linear combinations of multi-qubit basis states. \par +For example, a two-qubit state $\ket{ab}$ is the four-dimensional unit vector +\begin{equation} + \begin{bmatrix} + a \\ b \\ c \\ d + \end{bmatrix} + = a \ket{00} + b\ket{01} + c\ket{10} + d\ket{11} +\end{equation} + +As always, multi-qubit states are unit vectors. \par +Thus, $a^2 + b^2 + c^2 + d^2 = 1$ in the two-bit case above. + + +\problem{} +Say we have two qubits $\ket{\psi}$ and $\ket{\varphi}$. \par +Show that $\ket{\psi} \otimes \ket{\varphi}$ is always a unit vector (and is thus a valid quantum state). + +\vfill + + +\definition{Measurement II} +Measurement of a two-qubit state works just like measurement of a one-qubit state: \par +If we measure $a\ket{00} + b\ket{01} + c\ket{10} + d\ket{11}$, \par +we get one of the four basis states with the following probabilities: + +\begin{itemize} + \item $\mathcal{P}(\ket{00}) = a^2$ + \item $\mathcal{P}(\ket{01}) = b^2$ + \item $\mathcal{P}(\ket{10}) = c^2$ + \item $\mathcal{P}(\ket{11}) = d^2$ +\end{itemize} +As before, the sum of all the above probabilities is $1$. + + +\problem{} +Consider the two-qubit state +$\ket{\psi} = \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{2} \ket{01} + \frac{\sqrt{3}}{4} \ket{10} + \frac{1}{4} \ket{11}$ + +\begin{itemize}[itemsep=2mm] + \item If we measure both bits of $\ket{\psi}$ simultaneously, \par + what is the probability of getting each of $\ket{00}$, $\ket{01}$, $\ket{10}$, and $\ket{11}$? + + \item If we measure the ONLY the first qubit, what is the probability we get $\ket{0}$? How about $\ket{1}$? \par + \hint{There are two basis states in which the first qubit is $\ket{0}$.} + + \item Say we measured the second bit and read $\ket{1}$. \par + If we now measure the first bit, what is the probability of getting $\ket{0}$? +\end{itemize} + + + +\vfill +\pagebreak + +\problem{} +Again, consider the two-qubit state +$\ket{\psi} = \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{2} \ket{01} + \frac{\sqrt{3}}{4} \ket{10} + \frac{1}{4} \ket{11}$ \par +If we measure the first qubit of $\ket{\psi}$ and get $\ket{0}$, what is the resulting state of $\ket{\psi}$? \par +What would the state be if we'd measured $\ket{1}$ instead? + +\vfill + +\problem{} +Consider the three-qubit state $\ket{\psi} = c_0\ket{000} + c_1\ket{001} + ... + c_7 \ket{111}$. \par +Say we measure the first two qubits and get $\ket{00}$. What is the resulting state of $\ket{\psi}$? + +\begin{solution} + We measure $\ket{00}$ with probability $c_0^2 + c_1^2$, and $\ket{\psi}$ collapses to + \begin{equation*} + \frac{c_0\ket{000} + c_1\ket{001}}{\sqrt{c_0^2 + c_1^2}} + \end{equation*} +\end{solution} + + + + + +\vfill +\pagebreak + + + +\definition{Entanglement} +Some product states can be factored into a tensor product of individual qubit states. For example, +\begin{equation*} + \frac{1}{2} \bigl(\ket{00} + \ket{01} + \ket{10} + \ket{11}\bigr) + = \frac{1}{\sqrt{2}}\bigl( \ket{0} + \ket{1} \bigr) \otimes + \frac{1}{\sqrt{2}}\bigl( \ket{0} + \ket{1} \bigr) +\end{equation*} +Such states are called \textit{product states.} States that aren't product states are called \textit{entangled} states. + +\problem{} +Factor the following product state: +\begin{equation*} + \frac{1}{2\sqrt{2}} \bigl(\sqrt{3}\ket{00} - \sqrt{3}\ket{01} + \ket{10} - \ket{11}\bigr) +\end{equation*} + +\begin{solution} + \begin{equation*} + \frac{1}{2\sqrt{2}} \biggl(\sqrt{3}\ket{00} - \sqrt{3}\ket{01} + \ket{10} - \ket{11}\biggr) + = \biggl( \frac{\sqrt{3}}{2}\ket{0} + \frac{1}{2}\ket{1} \biggr) \otimes + \biggl(\frac{1}{\sqrt{2}}\ket{0} - \frac{1}{\sqrt{2}}\ket{1} \biggr) + \end{equation*} +\end{solution} + + +\vfill + +\problem{} +Show that the following is an entangled state. +\begin{equation*} + \frac{1}{\sqrt{2}}\ket{00} + \frac{1}{\sqrt{2}}\ket{11} +\end{equation*} + +\begin{solution} + $ + \left[ + \begin{smallmatrix} + a_0 \\ a_1 + \end{smallmatrix} + \right] + \otimes + \left[ + \begin{smallmatrix} + b_0 \\ b_1 + \end{smallmatrix} + \right] + = + a_0b_0\ket{00} + a_0b_1\ket{01} + a_1b_0\ket{10} + a_1b_1\ket{11} + $ + + \vspace{2mm} + + So, we have that $a_1b_1 = a_0b_0 = \sqrt{2}^{-1}$ \par + But $a_0b_1 = a_1b_0 = 0$, so one of $a_0$ and $b_1$ must be zero. \par + We thus have a contradiction. +\end{solution} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/src/parts/04 logic gates.tex b/src/Advanced/Introduction to Quantum/src/parts/04 logic gates.tex new file mode 100644 index 0000000..53f927a --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/04 logic gates.tex @@ -0,0 +1,312 @@ +\section{Logic Gates} + +\definition{Matrices} +Throughout this handout, we've been using matrices. Again, recall that every linear map may be written as a matrix, +and that every matrix represents a linear map. For example, if $f: \mathbb{R}^2 \to \mathbb{R}^2$ is a linear +map, we can write it as follows: +\begin{equation*} + f\left( + \ket{x} + \right) + = + \begin{bmatrix} + m_1 & m_2 \\ + m_3 & m_4 + \end{bmatrix} + \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + = + \left[ + \begin{matrix} + m_1x_1 + m_2x_2 \\ + m_3x_1 + m_4x_2 + \end{matrix} + \right] +\end{equation*} + + +\definition{} +Before we discussing multi-qubit quantum gates, we need to review to classical logic. \par +Of course, a classical logic gate is a linear map from $\{0,1\}^m$ to $\{0,1\}^n$ + + +\problem{} +The \texttt{not} gate is a map defined by the following table: \par + +\begin{itemize} + \item $X\ket{0} = \ket{1}$ + \item $X\ket{1} = \ket{0}$ +\end{itemize} + +Write the \texttt{not} gate as a matrix that operates on single-bit vector states. \par +That is, find a matrix $X$ so that +$ + X\left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right] + = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right] +$ +and +$ + X\left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right] + = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right] +$ \par + +\begin{solution} + \begin{equation*} + X = \begin{bmatrix} + 0 & 1 \\ 1 & 0 + \end{bmatrix} + \end{equation*} +\end{solution} + + +\vfill + + +\problem{} +The \texttt{and} gate is a map $\mathbb{B}^2 \to \mathbb{B}$ defined by the following table: +\begin{center} + \begin{tabular}{ c | c | c } + \hline + \texttt{a} & \texttt{b} & \texttt{a} and \texttt{b} \\ + \hline + 0 & 0 & 0 \\ + 0 & 1 & 0 \\ + 1 & 0 & 0 \\ + 1 & 1 & 1 + \end{tabular} +\end{center} + +Find a matrix $A$ so that $A\ket{\texttt{ab}}$ works as expected. \par +\hint{Remember, we write bits as vectors.} + + +\begin{solution} + \begin{equation*} + A = \begin{bmatrix} + 1 & 1 & 1 & 0 \\ + 0 & 0 & 0 & 1 \\ + \end{bmatrix} + \end{equation*} + + \begin{instructornote} + Because of the way we represent bits here, we also have the following property: \par + The columns of $A$ correspond to the output for each input---i.e, $A$ is just a table of outputs. \par + + \vspace{2mm} + For example, if we look at the first column of $A$ (which is $[1, 0]$), we see: \par + $A\ket{00} = A[1,0,0,0] = [1,0] = \ket{0}$ + + \vspace{2mm} + Also with the last column (which is $[0,1]$): \par + $A\ket{00} = A[0,0,0,1] = [0,1] = \ket{1}$ + \end{instructornote} +\end{solution} + + +\vfill +\pagebreak + +\generic{Remark:} +The way a quantum circuit handles information is a bit different than the way a classical circuit does. +We usually think of logic gates as \textit{functions}: they consume one set of bits, and return another: + + +\begin{center} +\begin{tikzpicture}[circuit logic US, scale=2] + \node[and gate] (and) at (0,-0.8) {\tiny\texttt{and}}; + \draw[->] ([shift={(-0.5, 0)}] and.input 1) node[left] {\texttt{input A}} -- ([shift={(-0.25, 0)}]and.input 1); + \draw[->] ([shift={(-0.5, 0)}] and.input 2) node[left] {\texttt{input B}} -- ([shift={(-0.25, 0)}]and.input 2); + \draw ([shift={(-0.25, 0)}] and.input 1) -- (and.input 1); + \draw ([shift={(-0.25, 0)}] and.input 2) -- (and.input 2); + \draw[->] (and.output) -- ([shift={(0.5, 0)}] and.output) node[right] {\texttt{output}}; +\end{tikzpicture} +\end{center} + + +This model, however, won't work for quantum logic. If we want to understand quantum gates, we need to see them +not as \textit{functions}, but as \textit{transformations}. This distinction is subtle, but significant: +\begin{itemize} + \item functions \textit{consume} a set of inputs and \textit{produce} a set of outputs + \item transformations \textit{change} a set of objects, without adding or removing any elements +\end{itemize} + +\vspace{2mm} + +Our usual logic circuit notation models logic gates as functions---we thus can't use it. \par +We'll need a different diagram to draw quantum circuits. \par + +\vfill + + +First, we'll need a set of bits. For this example, we'll use two, drawn in a vertical array. \par +We'll also add a horizontal time axis, moving from left to right: + +\begin{center} +\begin{tikzpicture}[scale=1] + \node[qubit] (a) at (0, 0) {\texttt{0}}; + \node[qubit] (b) at (0, -1) {\texttt{1}}; + + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {\texttt{0}}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {\texttt{1}}; + + \draw[ + color = oblue, + ->>, + line width = 0.5mm + ] (-1,-1.5) -- (5, -1.5); + + \node[fill=white, text=oblue] at (2, -1.5) {\texttt{time axis}}; + + + \node[left, gray] at (-1, -0.5) {State of each bit at start}; + \node[right, gray] at (5, -0.5) {State of each bit at end}; + + \draw[ + ->, + color = gray, + line width = 0.2mm, + rounded corners = 2mm + ] + (-1, -0.5) -- (-0.8, -0.5) -- (-0.8, 0) --(a) + ; + \draw[ + ->, + color = gray, + line width = 0.2mm, + rounded corners = 2mm + ] + (-1, -0.5) -- (-0.8, -0.5) -- (-0.8, -1) -- (b) + ; + + \draw[ + <-, + color = gray, + line width = 0.2mm, + rounded corners = 2mm + ] + (4.2, 0) -- (4.8, 0) -- (4.8, -0.5) -- (5, -0.5) + ; + \draw[ + <-, + color = gray, + line width = 0.2mm, + rounded corners = 2mm + ] + (4.2, -1) -- (4.8, -1) -- (4.8, -0.5) -- (5, -0.5) + ; + + \end{tikzpicture} +\end{center} + +In the diagram above, we didn't change our bits---so the labels at the start match those at the end. + +\vfill + +Thus, our circuit forms a grid, with bits ordered vertically and time horizontally. \par +If we want to change our state, we draw transformations as vertical boxes. \par +Every column represents a single transformation on the entire state: + +\begin{center} +\begin{tikzpicture}[scale=1] + \node[qubit] (a) at (0, 0) {\texttt{1}}; + \node[qubit] (b) at (0, -1) {\texttt{0}}; + + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {\texttt{0}}; + \draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {\texttt{1}}; + + \ghostqubox{a}{1}{b}{2}{$T_1$} + \ghostqubox{a}{2}{b}{3}{$T_2$} + \ghostqubox{a}{3}{b}{4}{$T_3$} + +\end{tikzpicture} +\end{center} + +Note that the transformations above span the whole state. This is important: \par +we cannot apply transformations to individual bits---we always transform the \textit{entire} state. + + +\vfill +\pagebreak + +\generic{Setup:} +Say we want to invert the first bit of a two-bit state. That is, we want a transformation $T$ so that \par + +\begin{center} +\begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {\texttt{a}}; + \node[qubit] (b) at (0, -1) {\texttt{b}}; + + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {\texttt{not a}}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {\texttt{b}}; + + \qubox{a}{1.5}{b}{2.5}{$T$} +\end{tikzpicture} +\end{center} + +In other words, we want a matrix $T$ satisfying the following equalities: +\begin{itemize} + \item $T\ket{00} = \ket{10}$ + \item $T\ket{01} = \ket{11}$ + \item $T\ket{10} = \ket{00}$ + \item $T\ket{11} = \ket{01}$ +\end{itemize} + + + +\problem{} +Find the matrix that corresponds to the above transformation. \par +\hint{ + Remember that + $\ket{0} = \left[\begin{smallmatrix} 1 \\ 0 \end{smallmatrix}\right]$ and + $\ket{1} = \left[\begin{smallmatrix} 0 \\ 1 \end{smallmatrix}\right]$ \\ + Also, we found earlier that $X = \left[\begin{smallmatrix} 0 && 1 \\ 1 && 0 \end{smallmatrix}\right]$, + and of course $I = \left[\begin{smallmatrix} 1 && 0 \\ 0 && 1 \end{smallmatrix}\right]$. +} + +\begin{solution} + \begin{equation*} + T = \begin{bmatrix} + 0 & 0 & 1 & 0 \\ + 0 & 0 & 0 & 1 \\ + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + \end{bmatrix} + \end{equation*} +\end{solution} + +\vfill + +\generic{Remark:} +We could draw the above transformation as a combination $X$ and $I$ (identity) gate: +\begin{center} +\begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{0}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{1}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$}; + + \qubox{a}{1}{a}{2}{$X$} + \qubox{b}{1}{b}{2}{$I$} +\end{tikzpicture} +\end{center} + +We can even omit the $I$ gate, since we now know that transformations affect the whole state: \par +\begin{center} +\begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{0}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{1}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$}; + + \qubox{a}{1}{a}{2}{$X$} +\end{tikzpicture} +\end{center} +We're now done: this is how we draw quantum circuits. +Don't forget that transformations \textit{always} affect the whole state---even if our diagram doesn't explicitly state this. + +\pagebreak + +% TODO: +% distributive property of tensor product +% quantum gate algebra \ No newline at end of file diff --git a/src/Advanced/Introduction to Quantum/src/parts/05 quantum gates.tex b/src/Advanced/Introduction to Quantum/src/parts/05 quantum gates.tex new file mode 100644 index 0000000..ba68291 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/05 quantum gates.tex @@ -0,0 +1,217 @@ +\section{Quantum Gates} + + +In the previous section, we stated that a quantum gate is a linear map. \par +Let's complete that definition. + +\definition{} +A quantum gate is a \textit{orthonormal matrix}, which means any gate $G$ +satisfies $GG^\text{T} = I$. \par +This implies the following: \par + +\begin{itemize} + \item $G$ is square. In other words, it has as many rows as it has columns. \par + \note{ + If we think of $G$ as a map, this means that $G$ has as many inputs as it has outputs. \\ + This is to be expected: we stated earlier that quantum gates do not destroy or create qubits. + } + + \item $G$ preserves lengths; i.e $|x| = |Gx|$. \par + \note{This ensures that $G\ket{\psi}$ is always a valid state.} +\end{itemize} + +(You will prove all these properties in any introductory linear algebra course. \\ +This isn't a lesson on linear algebra, so you may take them as given today.) + +\generic{Remark:} +Let $G$ be a quantum gate. \par +Since quantum gates are, by definition, \textit{linear} maps, +the following holds: \par + +\begin{equation*} + G\bigl(a_0 \ket{0} + a_1\ket{1}\bigr) = a_0G\ket{0} + a_1G\ket{1} +\end{equation*} + +\problem{} +Consider the \textit{controlled not} (or \textit{cnot}) gate, defined by the following table: \par +\begin{itemize} + \item $\text{X}_\text{c}\ket{00} = \ket{00}$ + \item $\text{X}_\text{c}\ket{01} = \ket{01}$ + \item $\text{X}_\text{c}\ket{10} = \ket{11}$ + \item $\text{X}_\text{c}\ket{11} = \ket{10}$ +\end{itemize} +In other words, the cnot gate inverts its second bit if its first bit is $\ket{1}$. \par +Find the matrix that applies the cnot gate. + +\begin{solution} + \begin{equation*} + \text{X}_\text{c} = \left[\begin{smallmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 0 & 1 \\ + 0 & 0 & 1 & 0 \\ + \end{smallmatrix}\right] + \end{equation*} + + \vspace{4mm} + + If $\ket{a}$ is $\ket{0}$, $\ket{a} \otimes \ket{b}$ is + $ + \left[ + \begin{smallmatrix} + \left[ + \begin{smallmatrix} + b_1 \\ b_2 + \end{smallmatrix} + \right] + \\ 0 \\ 0 + \end{smallmatrix} + \right] + $, and the \say{not} portion of the matrix is ignored. + + + \vspace{4mm} + + If $\ket{a}$ is $\ket{1}$, $\ket{a} \otimes \ket{b}$ is + $ + \left[ + \begin{smallmatrix} + 0 \\ 0 \\ + \left[ + \begin{smallmatrix} + b_1 \\ b_2 + \end{smallmatrix} + \right] + \end{smallmatrix} + \right] + $, and the \say{identity} portion of the matrix is ignored. + + + The state of $\ket{a}$ is always preserved, since it's determined by the position of + $\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ in the tensor product. + If $\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ is on top, $\ket{a}$ is $\ket{0}$, + and if $\left[\begin{smallmatrix}b_1 \\ b_2\end{smallmatrix}\right]$ is on the bottom, $\ket{a}$ is $\ket{1}$. +\end{solution} + + + + +\vfill +\pagebreak + + + +\problem{} +Evaluate the following: +\begin{equation*} + \text{X}_\text{C} + \Bigl( + \frac{1}{2}\ket{00} + + \frac{1}{2}\ket{01} - + \frac{1}{2}\ket{10} - + \frac{1}{2}\ket{11} + \Bigr) +\end{equation*} + + +\vfill + +\problem{} +If we measure the result of \ref{applycnot}, what are the probabilities of getting each state? + +\vfill + +\problem{} +Finally, modify the original cnot gate so that the roles of its bits are reversed: \par +$\text{X}_\text{c, flipped} \ket{ab}$ should invert $\ket{a}$ iff $\ket{b}$ is $\ket{1}$. + + +\begin{solution} + \begin{equation*} + \text{X}_\text{c, flipped} = \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 1 \\ + 0 & 0 & 1 & 0 \\ + 0 & 1 & 0 & 0 \\ + \end{bmatrix} + \end{equation*} +\end{solution} + +\vfill +\pagebreak + + + + + +\definition{} +The \textit{Hadamard Gate} is given by the following matrix: \par +\begin{equation*} + H = \frac{1}{\sqrt{2}}\begin{bmatrix} + 1 & 1 \\ + 1 & -1 + \end{bmatrix} +\end{equation*} +\note{Note that we divide by $\sqrt{2}$, since $H$ must be orthonormal.} + +\begin{ORMCbox}{Review: Matrix Multiplication}{black!10!white}{black!65!white} + Matrix multiplication works as follows: + + \begin{equation*} + AB = + \begin{bmatrix} + 1 & 2 \\ + 3 & 4 \\ + \end{bmatrix} + \begin{bmatrix} + a_0 & b_0 \\ + a_1 & b_1 \\ + \end{bmatrix} + = + \begin{bmatrix} + 1a_0 + 2a_1 & 1b_0 + 2b_1 \\ + 3a_0 + 4a_1 & 3b_0 + 4b_1 \\ + \end{bmatrix} + \end{equation*} + + + Note that this is very similar to multiplying each column of $B$ by $A$. \par + The product $AB$ is simply $Ac$ for every column $c$ in $B$: + + \begin{equation*} + Ac_0 = + \begin{bmatrix} + 1 & 2 \\ + 3 & 4 \\ + \end{bmatrix} + \begin{bmatrix} + a_0 \\ a_1 + \end{bmatrix} + = + \begin{bmatrix} + 1a_0 + 2a_1 \\ + 3a_0 + 4a_1 + \end{bmatrix} + \end{equation*} + + This is exactly the first column of the matrix product. \par + Also, note that each element of $Ac_0$ is the dot product of a row in $A$ and a column in $c_0$. +\end{ORMCbox} + + +\problem{} +What is $HH$? \par +Using this result, find $H^{-1}$. + +\begin{solution} + $HH = I$, so $H^{-1} = H$ +\end{solution} + +\vfill + +\problem{} +What geometric transformation does $H$ apply to the unit circle? \par +\hint{Rotation or reflection? How much, or about which axis?} + +\vfill +\pagebreak diff --git a/src/Advanced/Introduction to Quantum/src/parts/06 hxh.tex b/src/Advanced/Introduction to Quantum/src/parts/06 hxh.tex new file mode 100644 index 0000000..ee3b0f9 --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/06 hxh.tex @@ -0,0 +1,421 @@ +\section{HXH} + +Let's return to the quantum circuit diagrams we discussed a few pages ago. \par +Keep in mind that we're working with quantum gates and proper half-qubits---not classical bits, as we were before. + +\definition{Controlled Inputs} +A \textit{control input} or \textit{inverted control input} may be attached to any gate. \par +These are drawn as filled and empty circles in our circuit diagrams: + +\null\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{0}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{0}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + + \node[gray] at ($([shift={(0,-0.75)}] dot)$) {Non-inverted control input}; + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{0}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{1}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{0}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wireijoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + + \node[gray] at ($([shift={(0,-0.75)}] dot)$) {Inverted control input}; + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill\null +\vspace{2mm} + +An $X$ gate with a (non-inverted) control input behaves like an $X$ gate if \textit{all} its control inputs are $\ket{1}$, +and like $I$ otherwise. An $X$ gate with an inverted control inputs does the opposite, behaving like $I$ if its input is $\ket{1}$ +and like $X$ otherwise. The two circuits above illustrate this fact---take a look at their inputs and outputs. + +\vspace{2mm} +Of course, we can give a gate multiple controls. \par +An $X$ gate with multiple controls behaves like an $X$ gate if... +\begin{itemize} + \item all non-inverted controls are $\ket{1}$, and + \item all inverted controls are $\ket{0}$ +\end{itemize} +...and like $I$ otherwise. + +\problem{} +What are the final states of the qubits in the diagram below? + +\begin{center} + \begin{tikzpicture}[scale = 1.0] + \node[qubit] (a) at (0, 0) {$\ket{1}$}; + \node[qubit] (b) at (0, -1) {$\ket{0}$}; + \node[qubit] (c) at (0, -2) {$\ket{1}$}; + \node[qubit] (d) at (0, -3) {$\ket{0}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {?}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {?}; + \draw[wire] (c) -- ([shift={(3, 0)}] c.center) node[qubit] {?}; + \draw[wire] (d) -- ([shift={(3, 0)}] d.center) node[qubit] {?}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] d)!0.5!([shift={(2,0)}] d)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) + circle[radius=0.1] coordinate(dot) + ; + \draw[wireijoin] + ($([shift={(1,0)}] c)!0.5!([shift={(2,0)}] c)$) + circle[radius=0.1] coordinate(dot) + ; + \draw[wirejoin] + ($([shift={(1,0)}] d)!0.5!([shift={(2,0)}] d)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{b}{1}{b}{2}{$X$} + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak + +\problem{} +Consider the diagram below, with one controlled $X$ gate: \par +\note[Note]{The CNOT gate from \ref{cnot} is a controlled $X$ gate.} + +\begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{a}$}; + \node[qubit] (b) at (0, -1) {$\ket{b}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} +\end{center} + +Find a matrix $\text{X}_\text{c}$ that represents this gate, so that $\text{X}_\text{c}\ket{ab}$ works as expected. + +\begin{solution} + \begin{equation*} + \text{X}_\text{c} = \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 1 \\ + 0 & 0 & 1 & 0 \\ + 0 & 1 & 0 & 0 + \end{bmatrix} + \end{equation*} + Note that this is also the solution to \ref{cnotflipped}. +\end{solution} + +\vfill + +\problem{} +Now, evaluate the following. Remember that +$\ket{+} = \frac{1}{\sqrt{2}}\Bigl(\ket{0} + \ket{1}\Bigr)$ and +$\ket{-} = \frac{1}{\sqrt{2}}\Bigl(\ket{0} - \ket{1}\Bigr)$ + +\null\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{1}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{+}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill\null + +\vspace{5mm} + +\null\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{-}$}; + \node[qubit] (b) at (0, -1) {$\ket{1}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{+}$}; + \node[qubit] (b) at (0, -1) {$\ket{-}$}; + + \draw[wire] (a) -- ([shift={(3, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(3, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} + \end{center} +\end{minipage} +\hfill\null + +\hint{ + Note that some of these states are entangled. The circuit diagrams are a bit misleading: + we can't write an entangled state as two distinct qubits! + + \vspace{2mm} + + So, don't try to find $\ket{a}$ and $\ket{b}$. \par + Instead find $\ket{ab} = \psi_0\ket{00} + \psi_1\ket{01} + \psi_2\ket{10} + \psi_3\ket{11}$, and factor it into $\ket{a} \otimes \ket{b}$ if you can. +} + +\begin{solution} + In all the below equations, let $\tau = \frac{1}{\sqrt{2}}$. + \begin{itemize}[itemsep = 1mm] + \item $ + \text{X}_\text{c}\ket{01} + = \ket{11} + $ + + \item $ + \text{X}_\text{c}\ket{0+} + = \tau\ket{00} + \tau\ket{11} + $ \note[Note]{This state is entangled!} + + \item $ + \text{X}_\text{c}\ket{-1} + = -\tau\ket{10} + \tau\ket{11} + = (-\ket{-}) \otimes \ket{1} + $ + + \item $ + \text{X}_\text{c}\ket{+-} + = \frac{1}{2}(\ket{00} - \ket{01} + \ket{10} - \ket{11}) + = \ket{+-} + $ + \end{itemize} +\end{solution} + +\vfill +\pagebreak + +\generic{Remark:} +Now, consider the following circuit: + +\begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{1}$}; + + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \qubox{b}{1}{b}{2}{$H$} + \qubox{b}{3}{b}{4}{$H$} + + \draw[wire] + ($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) -- + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{2}{a}{3}{$X$} + + \end{tikzpicture} +\end{center} + +We already know that $H$ is its own inverse: $HH = I$. \par +Applying $H$ to a qubit twice does not change its state. + +\note{ + Recall that $H = \frac{1}{\sqrt{2}}\left[\begin{smallmatrix} 1 & 1 \\ 1 & -1 \end{smallmatrix}\right]$ +} + + +\vspace{2mm} + +So, we might expect that the two circuits below are equivalent: \par +After all, we $H$ the second bit, use it to control an $X$ gate, and then $H$ it back to its previous state. + +\null\hfill +\begin{minipage}{0.48\textwidth}\begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{1}$}; + + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{a}$}; + \draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{b}$}; + + \qubox{b}{1}{b}{2}{$H$} + \qubox{b}{3}{b}{4}{$H$} + + \draw[wire] + ($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) -- + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{2}{a}{3}{$X$} + + \end{tikzpicture} +\end{center}\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth}\begin{center} + \begin{tikzpicture}[scale=0.8] + \node[qubit] (a) at (0, 0) {$\ket{0}$}; + \node[qubit] (b) at (0, -1) {$\ket{1}$}; + + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {$\ket{c}$}; + \draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {$\ket{d}$}; + + \draw[wire] + ($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) -- + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(2,0)}] b)!0.5!([shift={(3,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{a}{2}{a}{3}{$X$} + + \end{tikzpicture} +\end{center}\end{minipage} +\hfill\null + +\vspace{2mm} + +This, however, isn't the case: \par +If we compute the state $\ket{ab}$ in the left circuit, we get $[0.5, ~0.5, -0.5, ~0.5]$ (which is entangled), \par +but the state $\ket{cd}$ on the right is $\ket{11} = [0,0,0,1]$. \par +\note{This is easy to verify with a few matrix multiplications.} + + +\vspace{4mm} + +How does this make sense? \par +Remember that a two-bit quantum state is \textit{not} equivalent to a pair of one-qubit quantum states. +We must treat a multi-qubit state as a single unit. + +Recall that a two-bit state $\ket{ab}$ comes with four probabilities: +$\mathcal{P}(\texttt{00})$, $\mathcal{P}(\texttt{01})$, $\mathcal{P}(\texttt{10})$, and $\mathcal{P}(\texttt{11})$. +If we change the probabilities of only $\ket{a}$, \textit{all four of these change!} + + +\vfill + +Because of this fact, \say{controlled gates} may not work as you expect. They may seem +to \say{read} their controlling qubit without affecting its state, but remember---a +controlled gate still affects the \textit{entire} state. As we noted before, it is +not possible to apply a transformation to one bit of a quantum state. + + +\begin{center} + \begin{tikzpicture}[scale=1] + \node[qubit] (a) at (0, 0) {\texttt{1}}; + \node[qubit] (b) at (0, -1) {\texttt{0}}; + + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {\texttt{0}}; + \draw[wire] (b) -- ([shift={(5, 0)}] b.center) node[qubit] {\texttt{1}}; + + \ghostqubox{a}{1}{b}{2}{$T_1$} + \ghostqubox{a}{2}{b}{3}{$T_2$} + \ghostqubox{a}{3}{b}{4}{$T_3$} + + \end{tikzpicture} +\end{center} + +\vfill +\pagebreak diff --git a/src/Advanced/Introduction to Quantum/src/parts/07 superdense.tex b/src/Advanced/Introduction to Quantum/src/parts/07 superdense.tex new file mode 100644 index 0000000..cf60ded --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/07 superdense.tex @@ -0,0 +1,195 @@ +\section{Superdense Coding} + +Consider the following entangled two-qubit states, called the \textit{bell states}: +\begin{itemize} + \item $\ket{\Phi^+} = \frac{1}{\sqrt{2}}\ket{00} + \frac{1}{\sqrt{2}}\ket{11}$ + \item $\ket{\Phi^-} = \frac{1}{\sqrt{2}}\ket{00} - \frac{1}{\sqrt{2}}\ket{11}$ + \item $\ket{\Psi^+} = \frac{1}{\sqrt{2}}\ket{01} + \frac{1}{\sqrt{2}}\ket{10}$ + \item $\ket{\Psi^-} = \frac{1}{\sqrt{2}}\ket{01} - \frac{1}{\sqrt{2}}\ket{10}$ +\end{itemize} + +\problem{} +The probabilistic bits we get when measuring any of the above may be called \textit{anticorrelated bits}. \par +If we measure the first bit of any of these states and observe $1$, what is the resulting compound state? \par +What if we observe $0$ instead? \par +Do you see why we can call these bits anticorrelated? + +\vfill + +\problem{} +Show that the bell states are orthogonal \par +\hint{Dot product} + +\vfill + +\problem{} +Say we have a pair of qubits in one of the four bell states. \par +How can we find out which of the four states we have, with certainty? \par +\hint{$H\ket{+} = \ket{0}$, and $H\ket{-} = \ket{1}$} + +\begin{solution} + $X_\text{c}\ket{\Phi^+} = \ket{+0}$ and $(H \otimes I)\ket{+0} = \ket{00}$ \par + $X_\text{c}\ket{\Psi^+} = \ket{+1}$ and $(H \otimes I)\ket{+1} = \ket{01}$ \par + $X_\text{c}\ket{\Phi^-} = \ket{-0}$ and $(H \otimes I)\ket{-0} = \ket{10}$ \par + $X_\text{c}\ket{\Psi^-} = \ket{-1}$ and $(H \otimes I)\ket{-1} = \ket{11}$ \par +\end{solution} + + +\vfill +\pagebreak + +\definition{} +The $Z$ gate is defined as follows: \par +\begin{equation*} + Z\begin{bmatrix} + \psi_0 \\ \psi_1 + \end{bmatrix} + = + \begin{bmatrix} + \psi_0 \\ -\psi_1 + \end{bmatrix} +\end{equation*} + +\problem{} +Suppose that Alice and Bob are each in possession of one qubit. \par +These two qubits are entangled, and have the compound state $\ket{\Phi^+}$. \par +\note[Note]{We could say that they each have \say{half} of $\ket{\Phi^+}$.} +How can Alice send a two-bit classical state +(i.e, one of the four values \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}) \par +to Bob by only sending one qubit? + +\begin{solution} + Alice can turn any bell state into any other by applying operations to her qubit. \par + Once she does so, Bob may use the procedure in \ref{bellmeasure} to read one of four states. + + \null\hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, 0) {}; + \node[qubit] (b) at (0, -1) {}; + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {}; + \node[right] at (0, -0.5) {$\ket{\Phi^+}$}; + \node[left] at (4, -0.5) {$\ket{\Phi^-}$}; + + \qubox{a}{1.5}{a}{2.5}{$Z$} + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, 0) {}; + \node[qubit] (b) at (0, -1) {}; + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {}; + \node[right] at (0, -0.5) {$\ket{\Phi^+}$}; + \node[left] at (4, -0.5) {$\ket{\Psi^+}$}; + + \qubox{a}{1.5}{a}{2.5}{$X$} + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, 0) {}; + \node[qubit] (b) at (0, -1) {}; + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {}; + \node[right] at (0, -0.5) {$\ket{\Phi^+}$}; + \node[left] at (4, -0.5) {$\ket{\Psi^-}$}; + + \qubox{a}{1}{a}{2}{$X$} + \qubox{a}{2}{a}{3}{$Z$} + \end{tikzpicture} + \end{center} + \end{minipage} + \hfill\null + + \vspace{4mm} + \linehack{} + + The complete circuit is shown below. Double lines indicate classical bits. + + + \begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, 0) {$a$}; + \node[qubit] (b) at (0, -1) {$b$}; + \node[qubit] (c) at (0, -2) {$\ket{\Phi^+_\text{A}}$}; + \node[qubit] (d) at (0, -3) {$\ket{\Phi^+_\text{B}}$}; + \draw[wire, double] (a) -- ([shift={(9, 0)}] a.center) node[qubit] {}; + \draw[wire, double] (b) -- ([shift={(9, 0)}] b.center) node[qubit] {}; + \draw[wire] (c) -- ([shift={(7, 0)}] c.center) node[qubit] {}; + \draw[wire] (d) -- ([shift={(7, 0)}] d.center) node[qubit] {}; + + \draw[wire, double] + ([shift={(7, 0)}] c.center) + -- ([shift={(9, 0)}] c.center) + node[qubit] {$a$} + ; + + \draw[wire, double] + ([shift={(7, 0)}] d.center) + -- ([shift={(9, 0)}] d.center) + node[qubit] {$b$} + ; + + + \draw[wire, double] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) -- + ($([shift={(1,0)}] c)!0.5!([shift={(2,0)}] c)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{c}{1}{c}{2}{$X$} + + \draw[wire, double] + ($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) -- + ($([shift={(2,0)}] c)!0.5!([shift={(3,0)}] c)$) + ; + \draw[wirejoin] + ($([shift={(2,0)}] a)!0.5!([shift={(3,0)}] a)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{c}{2}{c}{3}{$Z$} + + + + \draw[wire] + ($([shift={(4,0)}] c)!0.5!([shift={(5,0)}] c)$) -- + ($([shift={(4,0)}] d)!0.5!([shift={(5,0)}] d)$) + ; + \draw[wirejoin] + ($([shift={(4,0)}] c)!0.5!([shift={(5,0)}] c)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{d}{4}{d}{5}{$X$} + \qubox{c}{5}{c}{6}{$H$} + + + + \qubox{c}{6.3}{c}{8}{measure} + \qubox{d}{6.3}{d}{8}{measure} + \end{tikzpicture} + \end{center} +\end{solution} + + +\vfill + +\generic{Remark:} +Superdense coding consumes a pre-shared entangled pair to transmit two bits of information. +This entanglement may \textit{not} be re-used---it is destroyed when Bob measures the final qubit states. + +\pagebreak + diff --git a/src/Advanced/Introduction to Quantum/src/parts/08 teleport.tex b/src/Advanced/Introduction to Quantum/src/parts/08 teleport.tex new file mode 100644 index 0000000..cc0082c --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/parts/08 teleport.tex @@ -0,0 +1,179 @@ +\section{Quantum Teleportation} + +Superdense coding lets us convert quantum bandwidth into classical bandwidth. \par +Quantum teleportation does the opposite, using two classical bits and an entangled pair +to transmit a quantum state. + +\generic{Setup:} +Again, suppose Alice and Bob each have half of a $\ket{\Phi^+}$ state. \par +We'll call the state Alice wants to teleport $\ket{\psi} = \psi_0\ket{0} + \psi_1\ket{1}$. \par + +\problem{} +What is the three-qubit state $\ket{\psi}\ket{\Phi^+}$ in terms of $\psi_0$ and $\psi_1$? + +\vfill + +\problem{} +To teleport $\ket{\psi}$, Alice applies the following circuit to her two qubits, where $\ket{\Phi^+_\text{A}}$ is her half of $\ket{\Phi^+}$. \par +She then measures both qubits and sends the result to Bob. + +\begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, 0) {$\ket{\Phi^+_\text{A}}$}; + \node[qubit] (b) at (0, -1) {$\ket{\psi}$}; + \draw[wire] (a) -- ([shift={(4, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(4, 0)}] b.center) node[qubit] {}; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] b)!0.5!([shift={(2,0)}] b)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{b}{2}{b}{3}{$H$} + \qubox{a}{1}{a}{2}{$X$} + \end{tikzpicture} +\end{center} +What should Bob do so that $\ket{\Phi^+_B}$ takes the state $\ket{\psi}$ had initially? + +\begin{solution} + \begin{itemize} + \item + If Bob receives \texttt{00}, he does nothing. + + \item + If Bob receives \texttt{01}, he applies an $X$ gate to his qubit. + + \item + If Bob receives \texttt{01}, he applies a $Z$ gate to his qubit. + + \item + If Bob receives \texttt{11}, he applies $ZX$ to his qubit. + \end{itemize} + + \linehack{} + + The complete circuit is shown below. Double lines indicate classical bits. + + + \begin{center} + \begin{tikzpicture}[scale = 1] + \node[qubit] (a) at (0, -1) {$\ket{\Phi^+_\text{A}}$}; + \node[qubit] (b) at (0, -2) {$\ket{\Phi^+_\text{B}}$}; + \node[qubit] (c) at (0, 0) {$\ket{\psi}$}; + \draw[wire] (a) -- ([shift={(5, 0)}] a.center) node[qubit] {}; + \draw[wire] (b) -- ([shift={(9, 0)}] b.center) node[qubit] {$\ket{\psi}$}; + \draw[wire] (c) -- ([shift={(5, 0)}] c.center) node[qubit] {}; + + \draw[wire, double] + ([shift={(5, 0)}] a.center) + -- ([shift={(9, 0)}] a.center) + node[qubit] {} + ; + + \draw[wire, double] + ([shift={(5, 0)}] c.center) + -- ([shift={(9, 0)}] c.center) + node[qubit] {} + ; + + \draw[wire] + ($([shift={(1,0)}] a)!0.5!([shift={(2,0)}] a)$) -- + ($([shift={(1,0)}] c)!0.5!([shift={(2,0)}] c)$) + ; + \draw[wirejoin] + ($([shift={(1,0)}] c)!0.5!([shift={(2,0)}] c)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{c}{2}{c}{3}{$H$} + \qubox{a}{1}{a}{2}{$X$} + + \qubox{a}{3.8}{a}{5.5}{measure} + \qubox{c}{3.8}{c}{5.5}{measure} + + + \draw[wire, double] + ($([shift={(6,0)}] a)!0.5!([shift={(7,0)}] a)$) -- + ($([shift={(6,0)}] b)!0.5!([shift={(7,0)}] b)$) + ; + \draw[wirejoin] + ($([shift={(6,0)}] a)!0.5!([shift={(7,0)}] a)$) + circle[radius=0.1] coordinate(dot) + ; + + \qubox{b}{6}{b}{7}{$X$} + + + \draw[wire, double] + ($([shift={(7,0)}] b)!0.5!([shift={(8,0)}] b)$) -- + ($([shift={(7,0)}] c)!0.5!([shift={(8,0)}] c)$) + ; + \draw[wirejoin] + ($([shift={(7,0)}] c)!0.5!([shift={(8,0)}] c)$) + circle[radius=0.1] coordinate(dot) + ; + \qubox{b}{7}{b}{8}{$Z$} + + \end{tikzpicture} + \end{center} + + Note how similar this is to the superdense coding circuit. +\end{solution} + +\vfill +\pagebreak + +\problem{} +With an informal proof, show that it is not possible to use superdense coding to send +more than two classical bits through an entangled two-qubit quantum state. + +\begin{solution} + If superdense coding was any more efficient, we could repeatedly apply superdense coding and quantum teleportation, + to compress an arbitrary number of bits into two \say{seed} bits. + + \linehack{} + + \textbf{Even worse, this would allow faster-than-light communication:} \par + + Because the seed message is only 4 bits, Alice has decent odds of just + guessing it. She'll guess wrong and trash the message the majority of the + time but, by using an error correcting code, she can tell whether or not + the guess was correct or she trashed the message. And by repeating the protocol + enough times, we can increase the odds of the message being received arbitrarily + close to certainty. + + \note[Note]{ + I'm implicitly assuming that if Alice uses the wrong seed, she gets a totally random message---or + at least a message that isn't guaranteed to follow the error correction scheme better than chance would. + The alternative, where Alice receives noise that's uncorrelated with the message and yet somehow satisfies + arbitrary error correction schemes, is waaay too magical for me to even consider. + } + + \vspace{2mm} + + Suppose Alice and Bob perform the iterated-ultradense-encode-and-guess process 100 times. + That gives a failure rate of $(\nicefrac{15}{16})^{100} \approx 0.5\%$. + Sure it's a hundred times more work than just sending the 4 bits, and less likely to succeed to boot, + but the new protocol \textit{doesn't require any bits to be physically transmitted}. + There's no signalling delay! + + \vspace{2mm} + + In fact, Alice could even perform the decoding process \textit{before} Bob did the encoding. + But we're already so far into \say{everything is clearly broken} territory that creating time travel paradoxes is overkill. + + + \vspace{5mm} + + + From \url{https://algassert.com/2016/05/29/ultra-dense-coding-allows-ftl.html} +\end{solution} + + +\vfill +\pagebreak + diff --git a/src/Advanced/Introduction to Quantum/src/tikzset.tex b/src/Advanced/Introduction to Quantum/src/tikzset.tex new file mode 100644 index 0000000..23a052c --- /dev/null +++ b/src/Advanced/Introduction to Quantum/src/tikzset.tex @@ -0,0 +1,79 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{calc} +\usetikzlibrary{circuits.logic.US} +\usetikzlibrary{plotmarks} + + +\tikzset{ + gate/.style = { + draw, + rectangle, + fill = white, + line width = 0.35mm + }, + qubit/.style = { + fill = \ORMCbgcolor, + line width = 0.35mm + }, + wire/.style = { + line width = 1 + }, + wirejoin/.style = { + fill = oblue, + draw = oblue, + line width = 1.5 + }, + wireijoin/.style = { + fill = white, + draw = oblue, + line width = 1.5 + }, +} + +% Macros + + +% Do NOT put a semicolon after qubox, +% it gives a "character ; not found" error. +% LaTeX is odd. +\def\qubox#1#2#3#4#5{ + % 1: point ne + % 2: point ne x offset + % 3: point sw + % 4: point sw x offset + % 5: label text + \draw[ + line width = 1, + fill = white, + draw = black + ] + ([shift={(#2 + 0.1, 0.4)}] #1.center) + -- ([shift={(#2 + 0.1, -0.4)}] #1.center |- #3.center) + -- ([shift={(#4 - 0.1, -0.4)}] #3.center) + -- ([shift={(#4 - 0.1, 0.4)}] #1.center -| #3.center) + -- cycle + ; + \node at ($([shift={(#2,0)}] #1)!0.5!([shift={(#4,0)}] #3)$) {#5}; +} + +\def\ghostqubox#1#2#3#4#5{ + % 1: point ne + % 2: point ne x offset + % 3: point sw + % 4: point sw x offset + % 5: label text + \draw[ + line width = 1, + fill = white, + draw = gray, + dashed + ] + ([shift={(#2 + 0.1, 0.4)}] #1.center) + -- ([shift={(#2 + 0.1, -0.4)}] #1.center |- #3.center) + -- ([shift={(#4 - 0.1, -0.4)}] #3.center) + -- ([shift={(#4 - 0.1, 0.4)}] #1.center -| #3.center) + -- cycle + ; + \node[gray] at ($([shift={(#2,0)}] #1)!0.5!([shift={(#4,0)}] #3)$) {#5}; +} \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/main.tex b/src/Advanced/Lambda Calculus/main.tex new file mode 100755 index 0000000..6703558 --- /dev/null +++ b/src/Advanced/Lambda Calculus/main.tex @@ -0,0 +1,110 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +\usepackage{mathtools} % for \coloneqq + +% An invisible marker, used to +% draw arrows in equations. +\newcommand{\tzmr}[1]{ + \tikz[ + overlay, + remember picture, + right = 0.25ex + ] \node (#1) {}; +} +\newcommand{\tzm}[1]{ + \tikz[ + overlay, + remember picture + ] \node (#1) {}; +} + +\newcommand{\lm}{\lambda} + + + +% TODO: +% Lazy evaluation (alternate Y) +% Add a few theorems +% Better ending -> applications? +% - nix, comparison to imperative + + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Lambda Calculus} +\subtitle{Prepared by Mark on \today{}} + +\begin{document} + + \maketitle + + \hfill + \begin{minipage}{8cm} + Beware of the Turing tar pit, in which everything is possible but nothing of interest is easy. + + \vspace{2ex} + + Alan Perlis, \textit{Epigrams of Programming}, \#54 + \end{minipage} + \hfill\null + + \vspace{4mm} + + \makeatletter + \if@solutions + \begin{instructornote} + \textbf{Context \& Computability:} (or, why do we need lambda calculus?)\par + \note{From Peter Selinger's \textit{Lecture Notes on Lambda Calculus}} + + \vspace{2mm} + + In the 1930s, several people were interested in the question: what does it mean for + a function $f : \mathbb{N} \mapsto \mathbb{N}$ to be computable? An informal definition of computability + is that there should be a pencil-and-paper method allowing a trained person to + calculate $f(n)$, for any given $n$. The concept of a pencil-and-paper method is not + so easy to formalize. Three different researchers attempted to do so, resulting in + the following definitions of computability: + + \begin{itemize} + \item Turing defined an idealized computer we now call a Turing machine, and + postulated that a function is \say{computable} if and only + if it can be computed by such a machine. + + \item G\"odel defined the class of general recursive functions as the smallest set of + functions containing all the constant functions, the successor function, and + closed under certain operations (such as compositions and recursion). He + postulated that a function is \say{computable} if and only + if it is general recursive. + + \item Church defined an idealized programming language called the lambda calculus, + and postulated that a function is \say{computable} if and only if it can be written as a lambda term. + \end{itemize} + + It was proved by Church, Kleene, Rosser, and Turing that all three computational + models were equivalent to each other --- each model defines the same class + of computable functions. Whether or not they are equivalent to the \say{intuitive} + notion of computability is a question that cannot be answered, because there is no + formal definition of \say{intuitive computability.} The assertion that they are in fact + equivalent to intuitive computility is known as the Church-Turing thesis. + \end{instructornote} + \vfill + \pagebreak + \fi + \makeatother + + \input{parts/00 intro} + \input{parts/01 combinators} + \input{parts/02 boolean} + \input{parts/03 numbers} + \input{parts/04 recursion} + \input{parts/05 challenges} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/meta.toml b/src/Advanced/Lambda Calculus/meta.toml new file mode 100644 index 0000000..8f8932c --- /dev/null +++ b/src/Advanced/Lambda Calculus/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Lambda Calculus" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Lambda Calculus/parts/00 intro.tex b/src/Advanced/Lambda Calculus/parts/00 intro.tex new file mode 100755 index 0000000..5d785b2 --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/00 intro.tex @@ -0,0 +1,461 @@ +\section{Introduction} +\textit{Lambda calculus} is a model of computation, much like the Turing machine. +As we're about to see, it works in a fundamentally different way, which has a few +practical applications we'll discuss at the end of class. + +\vspace{2mm} + + +A lambda function starts with a lambda ($\lm$), followed by the names of any inputs used in the expression, +followed by the function's output. + +For example, $\lm x . x + 3$ is the function $f(x) = x + 3$ written in lambda notation. + +\vspace{4mm} +Let's disect $\lm x . x + 3$ piece by piece: + +\begin{itemize}[itemsep=3mm] + \item \say{$\lm$} tells us that this is the beginning of an expression. \par + $\lm$ here doesn't have a special value or definition; \par + it's just a symbol that tells us \say{this is the start of a function.} + + + \item \say{$\lm x$} says that the variable $x$ is \say{bound} to the function (i.e, it is used for input).\par + Whenever we see $x$ in the function's output, we'll replace it with the input of the same name. + + \vspace{1mm} + + This is a lot like normal function notation: In $f(x) = x + 3$, $(x)$ is \say{bound} + to $f$, and we replace every $x$ we see with our input when evaluating. + + + + \item The dot tells us that what follows is the output of this expression. \par + This is much like $=$ in our usual function notation: \par + The symbols after $=$ in $f(x) = x + 3$ tell us how to compute the output of this function. +\end{itemize} + +\problem{} +Rewrite the following functions using this notation: +\begin{itemize} + \item $f(x) = 7x + 4$ + \item $f(x) = x^2 + 2x + 1$ +\end{itemize} + +\vfill +\pagebreak + + + + + + + + + + + + + + + + + +To evaluate $\lm x . x + 3$, we need to input a value: +$$ + (\lm x . x + 3)~5 +$$ +This is very similar to the usual way we call functions: we usually write $f(5)$. \par +Above, we define our function $f$ \say{in-line} using lambda notation, \par +and we omit the parentheses around 5 for the sake of simpler notation. + + +\vspace{2mm} + + +We evaluate this by removing the \say{$\lm$} prefix and substituting $3$ for $x$ wheverever it appears: +$$ +(\lm x . \tzm{b}x + 3)~\tzmr{a}5 = +5 + 3 = 8 +\begin{tikzpicture}[ + overlay, + remember picture, + out=225, + in=315, + distance=0.5cm +] + \draw[->,gray,shorten >=5pt,shorten <=3pt] + (a.center) to (b.center); +\end{tikzpicture} +$$ + +\problem{} +Evaluate the following: +\begin{itemize}[itemsep = 2mm] + \item $(\lm x. 2x + 1)~4$ + \item $(\lm x. x^2 + 2x + 1)~3$ + \item $(\lm x. (\lm y. 9y) x + 3)~2$ \par + \hint{ + This function has a function inside, but the evaluation process doesn't change. \\ + Replace all $x$ with 2 and evaluate again. + } +\end{itemize} + + +\vfill + +As we saw above, we denote function application by simply putting functions next to their inputs. \par +If we want to apply $f$ to $5$, we write \say{$f~5$}, without any parentheses around the function's argument. + +\vspace{4mm} + +You may have noticed that we've been using arithmetic in the last few problems. +This isn't fully correct: addition is not defined in lambda calculus. In fact, nothing is defined: +not even numbers! + +In lambda calculus, we have only one kind of object: the function. +The only action we have is function application, which works by just like the examples above. + +\vspace{2mm} + +Don't worry if this sounds confusing, we'll see a few examples soon. + +\pagebreak + + + + + + + + + + + + + + + + + + + + +\definition{} +The first \say{pure} functions we'll define are $I$ and $M$: +\begin{itemize} + \item $I = \lm x . x$ + \item $M = \lm x . x x$ +\end{itemize} +Both $I$ and $M$ take one function ($x$) as an input. \par +$I$ does nothing, it just returns $x$. \par +$M$ is a bit more interesting: it applies the function $x$ on a copy of itself. + +\vspace{4mm} + +Also, note that $I$ and $M$ don't have a meaning on their own. They are not formal functions. \par +Rather, they are abbreviations that say \say{write $\lm x.x$ whenever you see $I$.} + + + + +\problem{} +Reduce the following expressions. \par +\hint{ + Of course, your final result will be a function. \\ + Functions are the only objects we have! +} + +\begin{itemize}[itemsep=2mm] + \item $I~I$ + \item $M~I$ + \item $(I~I)~I$ + \item $\Bigl(~ \lm a .(a~(a~a)) ~\Bigr) ~ I$ + \item $\Bigl(~(\lm a . (\lm b . a)) ~ M~\Bigr) ~ I$ +\end{itemize} + +\begin{examplesolution} + \textbf{Solution for $(I~I)$:}\par + Recall that $I = \lm x.x$. First, we rewrite the left $I$ to get $(\lm x . x )~I$. \par + Applying this function by replacing $x$ with $I$, we get $I$: + $$ + I ~ I = + (\lm x . \tzm{b}x )~\tzm{a}I = + I + \begin{tikzpicture}[ + overlay, + remember picture, + out=-90, + in=-90, + distance=0.5cm + ] + \draw[->,gray,shorten >=5pt,shorten <=3pt] + (a.center) to (b.east); + \end{tikzpicture} + $$\null +\end{examplesolution} + + +\vfill + +In lambda calculus, functions are left-associative: \par +$(f~g~h)$ means $((f~g)~h)$, not $(f~(g~h))$ + +As usual, we use parentheses to group terms if we want to override this order: $(f~(g~h)) \neq ((f~g)~h)$ \par +In this handout, all types of parentheses ( $(), [~],$ etc ) are equivalent. + +\problem{} +Rewrite the following expressions with as few parentheses as possible, without changing their meaning or structure. +Remember that lambda calculus is left-associative. +\vspace{2mm} +\begin{itemize}[itemsep=2mm] + \item $(\lm x. (\lm y. \lm z. ((xz)(yz))))$ + \item $((ab)(cd))((ef)(gh))$ + \item $(\lm x. ((\lm y.(yx))(\lm v.v)z)u) (\lm w.w)$ +\end{itemize} + +\begin{solution} + $(\lm x. ((\lm y.(yx))(\lm v.v)z)u) (\lm w.w) \implies (\lm x. (\lm y.yx) (\lm v.v)~z~u) \lm w.w$ + + \vspace{2mm} + + It's important that a function's output (everything after the dot) will continue until we hit a close-paren. + This is why we need the parentheses in the above example. +\end{solution} + + +\vfill +\pagebreak + + + + + + + + + + + + + + +\definition{Equivalence} +We say two functions are \textit{equivalent} if they differ only by the names of their variables: +$I = \lm a.a = \lm b.b = \lm \heartsuit . \heartsuit = ...$ \par + +\begin{instructornote} + + The idea behind this is very similar to the idea behind \say{equivalent groups} in group theory: \par + we do not care which symbols a certain group or function uses, we care about their \textit{structure}. \par + + \vspace{2mm} + + If we have two groups with different elements with the same multiplication table, we look at them as identical groups. + The same is true of lambda functions: two lambda functions with different variable names that behave in the same way are identical. + +\end{instructornote} + + + +\definition{} +Let $K = \lm a. (\lm b . a)$. We'll call $K$ the \say{constant function function.} + +\problem{} +That's not a typo. Why does this name make sense? \par +\hint{What is $K~x$?} + +\begin{solution} + $K x = \lm a . x$, which is a constant function that always outputs $x$. \par + Given an argument, $K$ returns a constant function with that value. +\end{solution} + +\vfill + +\problem{} +Show that associativity matters by evaluating $\bigl((M~K)~I\bigr)$ and $\bigl(M~(K~I)\bigr)$. \par +What would $M~K~I$ reduce to? + +\begin{solution} + $\bigl((M~K)~I\bigr) = (K~K)~I = (\lm a.K)~I = K$ \par + $\bigl(M~(K~I)\bigr) = M~(\lm a.I) = (\lm a.I)(\lm a.I) = I$ +\end{solution} + + +\vfill +\pagebreak + + + + + + + + + + + + + + + + + + + +\generic{Currying:} + +In lambda calculus, functions are only allowed to take one argument. \par +If we want multivariable functions, we'll have to emulate them through \textit{currying}\footnotemark{}\hspace{-1ex}. + +\footnotetext{After Haskell Brooks Curry\footnotemark{}\hspace{-1ex}, a logician that contributed to the theory of functional computation.} +\footnotetext{ + There are three programming languages named after him: Haskell, Brook, and Curry. \par + Two of these are functional, and one is an oddball GPU language last released in 2007. +} + +\vspace{1ex} + +The idea behind currying is fairly simple: we make functions that return functions. \par +We've already seen this on the previous page: $K$ takes an input $x$ and uses it to construct a constant function. +You can think of $K$ as a \say{factory} that constructs functions using the input we provide. + +\problem{} +\vspace{1mm} % Slight gap for big paren +Let $C = \lm f. \Bigl[\lm g. \Bigl( \lm x. [~ f(g(x)) ~] \Bigr)\Bigr]$. For now, we'll call it the \say{composer.} \par +\note[Note]{We could also call $C$ the \say{right-associator.} Why?} + +\vspace{3mm} + +$C$ has three \say{layers} of curry: it makes a function ($\lm g$) that makes another function ($\lm x$). \par +If we look closely, we'll find that $C$ pretends to take three arguments. + +\vspace{1mm} + +What does $C$ do? Evaluate $(C~a~b~x)$ for arbitrary expressions $a, b,$ and $x$. \par +\hint{Evaluate $(C~a)$ first. Remember, function application is left-associative.} + +\vfill + +\problem{} +Using the definition of $C$ above, evaluate $C~M~I~\star$ \par +Then, evaluate $C~I~M~I$ \par +\note[Note]{$\star$ represents an arbitrary expression. Treat it like an unknown variable.} + +\vfill + +As we saw above, currying allows us to create multivariable functions by nesting single-variable functions. +You may have notice that curried expressions can get very long. We'll use a bit of shorthand to make them more palatable: +If we have an expression with repeated function definitions, we'll combine their arguments under one $\lm$. + +\vspace{1ex} + +For example, $A = \lm f .[ \lm a . f(f(a))]$ will become $A = \lm fa . f(f(a))$ + +\problem{} +Rewrite $C = \lm f.\lm g.\lm x. (g(f(x)))$ from \ref{firstcardinal} using this shorthand. + +\vspace{25mm} + +Remember that this is only notation. \textbf{Curried functions are not multivariable functions, they are simply shorthand!} +Any function presented with this notation must still be evaluated one variable at a time, just like an un-curried function. +Substituting all curried variables at once will cause errors. + +\pagebreak + + + + + + + + + + + + + + + + + + + + + + +%\iftrue +\iffalse + \generic{$\alpha$-Conversion:} + There is one more operation we need to discuss. Those of you that have worked with any programming language may + find that this section sounds like something you've seen before. + + \vspace{2mm} + + Variables inside functions are \say{scoped.} We must take care to keep separate variables separate. + + For example, take the functions \par + $A = \lm a b . a$ \par + $B = \lm b . b$ + + \vspace{2ex} + + We could say that $(A~B) = \lm b . (\lm b . b)$, and therefore + $$ + ((A~B)~I) + = (~ (\lm \tzm{b}b . (\lm b . b))~\tzmr{a}I ~) + = \lm I . I + \begin{tikzpicture}[ + overlay, + remember picture, + out=225, + in=315, + distance=0.5cm + ] + \draw[->,gray,shorten >=5pt,shorten <=3pt] + (a.center) to (b.center); + \end{tikzpicture} + $$ + + Which is, of course, incorrect. $\lm I . I$ is not a valid function. + This problem arises because both $A$ and $B$ use the input $b$. + However, each $b$ is \say{bound} to a different function: + One $b$ is bound to $A$, and the other to $B$. They are therefore distinct. + + \vspace{2ex} + + Let's rewrite $B$ as $\lm b_1 . b_1$ and try again: $(A~B) = \lm b . ( \lm b_1 . b_1) = \lm bb_1 . b_1$ \par + Now, we correctly find that $(A~B~I) = (\lm bc . c)~I = \lm c . c = B = I$. +\fi + +\problem{} +Let $Q = \lm abc.b$. Reduce $(Q~a~c~b)$. \par +\hint{ + You may want to rename a few variables. \\ + The $a,b,c$ in $Q$ are different than the $a,b,c$ in the expression! +} + +\begin{solution} + I'll rewrite $(Q~a~c~b)$ as $(Q~a_1~c_1~b_1)$: + \begin{align*} + Q = (\lm abc.b) &= (\lm a.\lm b.\lm c.b) \\ + (\lm a.\lm b.\lm c.b)~a_1 &= (\lm b.\lm c.b) \\ + (\lm b.\lm c.b)~c_1 &= (\lm c.c_1) \\ + (\lm c.c_1)~b_1 &= c_1 + \end{align*} +\end{solution} + +\vfill + +\problem{} +Reduce $((\lm a.a)~\lm bc.b)~d~\lm eg.g$ + +\begin{solution} + $((\lm a.a)~\lm bc.b)~d~\lm eg.g$ \\ + $= (\lm bc.b)~d~\lm eg.g$ \\ + $= (\lm c.d)~\lm eg.g$ \\ + $= d$ +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/parts/01 combinators.tex b/src/Advanced/Lambda Calculus/parts/01 combinators.tex new file mode 100755 index 0000000..fd39f7d --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/01 combinators.tex @@ -0,0 +1,42 @@ +\section{Combinators} + +\definition{} +A \textit{free variable} in a $\lm$-expression is a variable that isn't bound to any input. \par +For example, $b$ is a free variable in $(\lm a.a)~b$. + +\definition{Combinators} +A \textit{combinator} is a lambda expression with no free variables. + +\vspace{1mm} + +Notable combinators are often named after birds.\hspace{-0.5ex}\footnotemark{} We've already met a few: \par +The \textit{Idiot}, $I = \lm a.a$ \par +The \textit{Mockingbird}, $M = \lm f.ff$ \par +The \textit{Cardinal}, $C = \lm fgx.(~ f(g(x)) ~)$ +The \textit{Kestrel}, $K = \lm ab . a$ + + + +\problem{} +If we give the Kestrel two arguments, it does something interesting: \par +It selects the first and rejects the second. \par +Convince yourself of this fact by evaluating $(K~\heartsuit~\star)$. + +\vfill + +\problem{} +Modify the Kestrel so that it selects its \textbf{second} argument and rejects the first. \par + +\begin{solution} + $\lm ab . b$. +\end{solution} + +\vfill + +\problem{} +We'll call the combinator from \ref{kitedef} the \textit{Kite}, $KI$. \par +Show that we can also obtain the kite by evaluating $(K~I)$. + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/parts/02 boolean.tex b/src/Advanced/Lambda Calculus/parts/02 boolean.tex new file mode 100755 index 0000000..b4b051b --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/02 boolean.tex @@ -0,0 +1,77 @@ +\section{Boolean Algebra} + +The Kestrel selects its first argument, and the Kite selects its second. \par +Maybe we can somehow put this \say{choosing} behavior to work... + +\vspace{1ex} + +Let $T = K\phantom{I} = \lm ab . a$ \par +Let $F = KI = \lm ab . b$ + +\problem{} +Write a function $\text{NOT}$ so that $(\text{NOT} ~ T) = F$ and $(\text{NOT}~F) = T$. \par +\hint{What is $(T~\heartsuit~\star)$? How about $(F~\heartsuit~\star)$?} + + +\begin{solution} + $\text{NOT} = \lm a . (a~F~T)$ +\end{solution} + +\vfill + +\problem{} +How would \say{if} statements work in this model of boolean logic? \par +Say we have a boolean $B$ and two expressions $E_T$ and $E_F$. +Can we write a function that evaluates to $E_T$ if $B$ is true, and to $E_F$ otherwise? + +\vfill +\pagebreak + +\problem{} +Write functions $\text{AND}$, $\text{OR}$, and $\text{XOR}$ that satisfy the following table. + +\begin{center} +\begin{tabular}{|| c c || c | c | c ||} + \hline + $A$ & $B$ & $(\text{AND}~A~B)$ & $(\text{OR}~A~B)$ & $(\text{XOR}~A~B)$ \\ + \hline\hline + F & F & F & F & F \\ + \hline + F & T & F & T & T \\ + \hline + T & F & F & T & T \\ + \hline + T & T & T & T & F \\ + \hline +\end{tabular} +\end{center} + +\begin{solution} + There's more than one way to do this, of course. + \begin{align*} + \text{AND} &= \lm ab . (a~b~F) = \lm ab . aba \\ + \text{OR} &= \lm ab . (a~T~b) = \lm ab . aab \\ + \text{XOR} &= \lm ab . (a~ (\text{NOT}~b) ~b) + \end{align*} + + Another clever solution is $\text{OR} = \lm ab.(M~a~b)$ +\end{solution} + +\vfill + +\problem{} +To complete our boolean algebra, construct the boolean equality check EQ. \par +What inputs should it take? What outputs should it produce? + +\begin{solution} + $\text{EQ} = \lm ab . [a~(bTF)~(bFT)] = \lm ab . [a~b~(\text{NOT}~b)]$ + + \vspace{1ex} + + $\text{EQ} = \lm ab . [\text{NOT}~(\text{XOR}~a~b)]$ +\end{solution} + + +\vfill + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/parts/03 numbers.tex b/src/Advanced/Lambda Calculus/parts/03 numbers.tex new file mode 100755 index 0000000..9afed5d --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/03 numbers.tex @@ -0,0 +1,175 @@ +\section{Numbers} + +Since the only objects we have in $\lm$ calculus are functions, it's natural to think of quantities as \textit{adverbs} (once, twice, thrice,...) rather than \textit{nouns} (one, two, three ...) + +\vspace{1ex} + +We'll start with zero. If our numbers are \textit{once,} \textit{twice,} and \textit{twice}, it may make sense to make zero \textit{don't}. \par +Here's our \textit{don't} function: given a function and an input, don't apply the function to the input. +$$ + 0 = \lm fa.a +$$ +If you look closely, you'll find that $0$ is equivalent to the false function $F$. + +\problem{} +Write $1$, $2$, and $3$. We will call these \textit{Church numerals}.\hspace{-0.5ex}\footnotemark{} \\ +\note{\textit{Note:} This problem read aloud is \say{Define \textit{once}, \textit{twice}, and \textit{thrice}.}} + +\footnotetext{after Alonzo Church, the inventor of lambda calculus and these numerals. He was Alan Turing's thesis advisor.} + +\begin{solution} + $1$ calls a function once on its argument: \par + $1 = \lm fa . (f~a)$. + + \vspace{1ex} + + Naturally, \par + $2 = \lm fa . [~f~(f~a)~]$ \par + $3 = \lm fa . [~f~(f~(f~a))~]$ + + \vspace{1ex} + + The round parentheses are \textit{essential}. Our lambda calculus is left-associative! \par + Also, note that zero is false and one is the (two-variable) identity. +\end{solution} + +\vfill + +\problem{} +What is $(4~I)~\star$? + +\vfill + +\problem{} +What is $(3~NOT~T)$? \par +How about $(8~NOT~F)$? + +\vfill + +\pagebreak + +\problem{} +Peano's axioms state that we only need a zero element and a \say{successor} operation to +build the natural numbers. We've already defined zero. +Now, create a successor operation so that $1 \coloneqq S(0)$, $2 \coloneqq S(1)$, and so on. \par +\hint{A good signature for this function is $\lm nfa$, or more clearly $\lm n.\lm fa$. Do you see why?} + +\begin{solution} + $S = \lm n. [\lm fa . f~(n~f~a)] = \lm nfa . [f~(n~f~a)]$ + + \vspace{1ex} + + Do $f$ $n$ times, then do $f$ one more time. +\end{solution} + +\vfill + +\problem{} +Verify that $S(0) = 1$ and $S(1) = 2$. + +\vfill +\pagebreak + + +Assume that only Church numerals will be passed to the functions in the following problems. \par +We make no promises about their output if they're given anything else. + +\problem{} +Define a function ADD that adds two Church numerals. + +\begin{solution} + $\text{ADD} = \lm mn . (m~S~n) = \lm mn . (n~S~m)$ +\end{solution} + +\begin{instructornote} + Defining \say{equivalence} is a bit tricky. The solution above illustrates the problem pretty well. + + \note{Note: The notions of \say{extensional} and \say{intentional} equivalence may be interesting in this context. Do some reading on your own. + } + + \vspace{4ex} + + These two definitions of ADD are equivalent if we apply them to Church numerals. If we were to apply these two versions of ADD to functions that behave in a different way, we'll most likely get two different results! \\ + As a simple example, try applying both versions of ADD to the Kestrel and the Kite. + + \vspace{1ex} + + To compare functions that aren't $\alpha$-equivalent, we'll need to restrict our domain to functions of a certain form, saying that two functions are equivalent over a certain domain. \\ +\end{instructornote} +\vfill + +\problem{} +Design a function MULT that multiplies two numbers. \par +\hint{The easy solution uses ADD, the elegant one doesn't. Find both!} + +\begin{solution} + $\text{MULT} = \lm mn . [m~(\text{ADD}~n)~m]$ + + $\text{MULT} = \lm mnf . [m~(n~f)]$ +\end{solution} + +\vfill +\pagebreak + + +\problem{} +Define the functions $Z$ and $NZ$. $Z$ should reduce to $T$ if its input was zero, and $F$ if it wasn't. \par +$NZ$ does the opposite. $Z$ and $NZ$ should look fairly similar. + +\vspace{1ex} + +\begin{solution} + $Z\phantom{N} = \lm n .[n~(\lm a.F)~T]$ \par + $NZ = \lm n .[n~(\lm a.T)~F]$ +\end{solution} + +\vfill + +\problem{} +Design an expression PAIR that constructs two-value tuples. \par +For example, say $A = \text{PAIR}~1~2$. Then, \par +$(A~T)$ should reduce to $1$ and $(A~F)$ should reduce to $2$. + +\begin{solution} + $\text{PAIR} = \lm ab . \lm i . (i~a~b) = \lm abi.iab$ +\end{solution} + +\vfill +From now on, I'll write (PAIR $A$ $B$) as $\langle A,B \rangle$. \par +Like currying, this is only notation. The underlying logic remains the same. + +\pagebreak + +\problem{} +Write a function $H$, which we'll call \say{shift and add.} \par +It does exactly what it says on the tin: + +\vspace{1ex} + +Given an input pair, it should shift its second argument left, then add one. \par +$H~\langle 0, 1 \rangle$ should reduce to $\langle 1, 2\rangle$ \par +$H~\langle 1, 2 \rangle$ should reduce to $\langle 2, 3\rangle$ \par +$H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$ + +\begin{solution} + $H = \lm p . \Bigl\langle~(p~F)~,~S(p~F)~\Bigr\rangle$ + + \vspace{1ex} + + Note that $H~\langle 0, 0 \rangle$ reduces to $\langle 0, 1 \rangle$ +\end{solution} + + +\vfill + +\problem{} +Design a function $D$ that un-does $S$. That means \par +$D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \par +\hint{$H$ will help you make an elegant solution.} + +\begin{solution} + $D = \lm n . \Bigl[(~n~H~\langle 0, 0 \rangle~)~T\Bigr]$ +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/parts/04 recursion.tex b/src/Advanced/Lambda Calculus/parts/04 recursion.tex new file mode 100755 index 0000000..d7a1bf4 --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/04 recursion.tex @@ -0,0 +1,162 @@ +\section{Recursion} + + +%\iftrue +\iffalse + + You now have a choice. Choose wisely --- there's no going back. + + \begin{tcolorbox}[ + breakable, + colback=white, + colframe=gray, + arc=0pt, outer arc=0pt + ] + \raggedright + \textbf{Take the red pill:} You stay on this page and try to solve \ref{thechallenge}. \par + This will take a while, and it's very unlikely you'll finish before class ends. + + + \vspace{4mm} + + I strongly prefer this option. It's not easy, but you'll be very happy if you solve it yourself. + This is a chance to build your own solution to a fundamental problem in this field, just as + Curry, Church, and Turing did when first developing the theory of lambda calculus. + + - Mark + \end{tcolorbox} + + \begin{tcolorbox}[ + breakable, + colback=white, + colframe=gray, + arc=0pt, outer arc=0pt + ] + \textbf{Take the blue pill:} You skip this problem and turn the page. + Half of the answer to \ref{thechallenge} will be free, and the rest will be + broken into smaller steps. This is how we usually learn out about interesting + mathematics, both in high school and in university. + + \vspace{2mm} + + This path isn't as rewarding as the one above, but it is well-paved + and easier to traverse. + \end{tcolorbox} + + \problem{} + Can you find a way to recursively call functions in lambda calculus? \par + Find a way to define a recursive factorial function. \par + + \note{$A = (\lm a. A~a)$ doesn't count. You can't use a macro inside itself.} + + \vfill + \pagebreak +\fi + + + + + + + + + + + + + + + + + + + + + +Say we want a function that computes the factorial of a positive integer. Here's one way we could define it: +$$ + x! = \begin{cases} + x \times (x-1)! & x \neq 0 \\ + 1 & x = 0 + \end{cases} +$$ + +We cannot re-create this in lambda calculus, since we aren't given a way to recursively call functions. + +\vspace{2mm} + +One could think that $A = \lm a. A~a$ is a recursive function. In fact, it is not. \par +Remember that such \say{definitions} aren't formal structures in lambda calculus. \par +They're just shorthand that simplifies notation. + +\begin{instructornote} + We're talking about recursion, and \textit{computability} isn't far away. At one point or another, it may be good to give the class a precise definition of \say{computable by lambda calculus:} + + \vspace{4ex} + + Say we have a device that reduces a $\lm$ expression to $\beta$-normal form. We give it an expression, and the machine simplifies it as much as it can and spits out the result. + + \vspace{1ex} + + An algorithm is \say{computable by lambda calculus} if we can encode its input in an expression that resolves to the algorithm's output. +\end{instructornote} + +\problem{} +Write an expression that resolves to itself. \par +\hint{Your answer should be quite short.} + +\vspace{1ex} + +This expression is often called $\Omega$, after the last letter of the Greek alphabet. \par +$\Omega$ useless on its own, but it gives us a starting point for recursion. \par + +\begin{solution} + $\Omega = M~M = (\lm x . xx) (\lm x . xx)$ + + \vspace{1mm} + + An uninspired mathematician might call the Mockingbird $\omega$, \say{little omega}. +\end{solution} + +\vfill +\pagebreak + + + + + +\definition{} +This is the \textit{Y-combinator}. You may notice that it's just $\Omega$ put to work. +$$ + Y = \lm f . (\lm x . f(x~x))(\lm x . f(x~x)) +$$ + +\problem{} +What does this thing do? \par +Evaluate $Y f$. + + + +%\vfill + +%\definition{} +%We say $x$ is a \textit{fixed point} of a function $f$ if $f(x) = x$. + +%\problem{} +%Show that $Y F$ is a fixed point of $F$. + +%\vfill + +%\problem{} +%Let $b = (\lm xy . y(xxy))$ and $B = b ~ b$. \par +%Let $N = B F$ for an arbitrary lambda expression $F$. \par + +%Show that $F N = N$. + +%\vfill + +%\problem{Bonus} +%Find a fixed-point combinator that isn't $Y$ or $\Theta$. + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lambda Calculus/parts/05 challenges.tex b/src/Advanced/Lambda Calculus/parts/05 challenges.tex new file mode 100755 index 0000000..e1a3497 --- /dev/null +++ b/src/Advanced/Lambda Calculus/parts/05 challenges.tex @@ -0,0 +1,130 @@ +\section{Challenges} + +Do \ref{Yfac} first, then finish the rest in any order. + +\problem{} +Design a recursive factorial function using $Y$. + +\begin{solution} + $\text{FAC} = \lm yn.[Z~n][1][\text{MULT}~n~(y~(\text{D}~n))]$ + + To compute the factorial of 5, evaluate $(\text{Y}~\text{FAC}~5)$. +\end{solution} + +\vfill + +\problem{} +Design a non-recursive factorial function. \par +\note{This one is easier than \ref{Yfac}, but I don't think it will help you solve it.} + +\begin{solution} + $\text{FAC}_0 = \lm p . + \Bigl\langle~~ + \Bigl[D~(p~t)\Bigr] + ~,~ + \Bigl[\text{MULT}~(p~T)~(p~F)\Bigr] + ~~\Bigr\rangle + $ + + \vspace{2ex} + + $ + \text{FAC} = \lm n . + \bigl( n~\text{FAC}_0~\langle n, 1 \rangle \bigr) + $ +\end{solution} + +\vfill + + + +\problem{} +Solve \ref{decrement} without using $H$. \par +In \ref{decrement}, we created the \say{decrement} function. + +\begin{solution} + One solution is below. Can you figure out how it works? \par + + \vspace{1ex} + + $ + D_0 = + \lm p . \Bigl[p~T\Bigr] + \Bigl\langle + F ~,~ p~F + \Bigr\rangle + \Bigl\langle + F + ~,~ + \bigl\langle + p~F~T ~,~ ( (p~F~T)~(P~F~F) ) + \bigr\rangle + \Bigr\rangle + $ + + \vspace{1ex} + + $ + D = \lm nfa . + \Bigl( + n D_0 \Bigl\langle T, \langle f, a \rangle \Bigr\rangle + \Bigr)~F~F + $ +\end{solution} + +\vfill + + + +\problem{} +Using pairs, make a \say{list} data structure. Define a GET function, so that $\text{GET}~L~n$ reduces to the nth item in the list. +$\text{GET}~L~0$ should give the first item in the list, and $\text{GET}~L~1$, the \textit{second}. \par +Lists have a defined length, so you should be able to tell when you're on the last element. + +\begin{solution} + One possible implementation is + $\Bigl\langle + \langle \text{is last} ~,~ \text{item} \rangle + ~,~ + \text{next}... + \Bigr\rangle$, where: + + \vspace{1ex} + + \say{is last} is a boolean, true iff this is the last item in the list. \par + \say{item} is the thing you're storing \par + \say{next...} is another one of these list fragments. + + It doesn't matter what \say{next} is in the last list fragment. A dedicated \say{is last} slot allows us to store arbitrary functions in this list. + + \vspace{1ex} + + Here, $\text{GET} = \lm nL.[(n~L~F)~T~F$] + + This will break if $n$ is out of range. +\end{solution} + +\vfill +\pagebreak + +\problem{} +Write a lambda expression that represents the Fibonacci function: \par +$f(0) = 1$, $f(1) = 1$, $f(n + 2) = f(n + 1) + f(n)$. + +\vfill + +\problem{} +Write a lambda expression that evaluates to $T$ if a number $n$ is prime, and to $F$ otherwise. + +\vfill + +\problem{} +Write a function MOD so that $(\text{MOD}~a~b)$ reduces to the remainder of $a \div b$. + +\vfill + +\problem{Bonus} +Play with \textit{Lamb}, an automatic lambda expression evaluator. \par +\url{https://git.betalupi.com/Mark/lamb} + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lattices/main.tex b/src/Advanced/Lattices/main.tex new file mode 100755 index 0000000..c8d93e4 --- /dev/null +++ b/src/Advanced/Lattices/main.tex @@ -0,0 +1,27 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{ifthen} +%\usepackage{lua-visual-debug} + +\renewcommand{\arraystretch}{1.2} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Lattices} +\subtitle{Prepared by Mark on \today} + +\begin{document} + + \maketitle + + \input{parts/0 intro.tex} + \input{parts/1 minkowski.tex} + \input{parts/2 orchard.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Lattices/meta.toml b/src/Advanced/Lattices/meta.toml new file mode 100644 index 0000000..782e271 --- /dev/null +++ b/src/Advanced/Lattices/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Lattices" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Lattices/parts/0 intro.tex b/src/Advanced/Lattices/parts/0 intro.tex new file mode 100644 index 0000000..fc03417 --- /dev/null +++ b/src/Advanced/Lattices/parts/0 intro.tex @@ -0,0 +1,53 @@ +\definition{} +The \textit{integer lattice} $\mathbb{Z}^n \subset \mathbb{R}^n$ is the set of points with integer coordinates. + +\problem{} +Draw $\mathbb{Z}^2$. + +\vfill + + +\definition{} +We say a set of vectors $\{v_1, v_2, ..., v_k\}$ \textit{generates} $\mathbb{Z}^n$ if every lattice point can be written uniquely as +$$ + a_1v_1 + a_2v_2 + ... + a_kv_k +$$ +for integer coefficients $a_i$. \par +It is fairly easy to show that $k$ must be at least $n$. + +\problem{} +Which of the following generate $\mathbb{Z}^2$? +\begin{itemize} + \item $\{ (1,2), (2,1) \}$ + \item $\{ (1,0), (0,2) \}$ + \item $\{ (1,1), (1,0), (0,1) \}$ +\end{itemize} + +\begin{solution} + Only the last. +\end{solution} + +\vfill + +\problem{} +Find a set of two vectors that generates $\mathbb{Z}^2$. \\ +Don't say $\{ (0, 1), (1, 0) \}$, that's too easy. + +\vfill + +\problem{} +Find a set of vectors that generates $\mathbb{Z}^n$. + + + +\vfill +\pagebreak + +\definition{} +A \textit{fundamental region} of a lattice is the parallelepiped spanned by a generating set. The exact shape of this region depends on the generating set we use. + +\problem{} +Draw two fundamental regions of $\mathbb{Z}^2$ using two different generating sets. Verify that their volumes are the same. + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lattices/parts/1 minkowski.tex b/src/Advanced/Lattices/parts/1 minkowski.tex new file mode 100644 index 0000000..3c196e6 --- /dev/null +++ b/src/Advanced/Lattices/parts/1 minkowski.tex @@ -0,0 +1,115 @@ +\section{Minkowski's Theorem} + +\theorem{Blichfeldt's Theorem} +Let $X$ be a finite connected region. If the volume of $X$ is greater than $1$, $X$ must contain two distinct points that differ by an element of $\mathbb{Z}^n$. In other words, there exist distinct $x, y \in X$ so that $x - y \in \mathbb{Z}^n$. + +\vspace{2mm} + +Intuitively, this means that you can translate $X$ to cover two lattice points at the same time. + + +\problem{} +Draw a region in $\mathbb{R}^2$ with volume greater than 1 that contains no lattice points. Find two points in that region which differ by an integer vector. +\hint{Area is two-dimensional volume.} + +\vfill + + +\problem{} +The following picture gives an idea for the proof of Blichfeldt's theorem in $\mathbb{Z}^2$. Explain the picture and complete the proof. + +\begin{center} + \includegraphics[angle=90,width=0.5\linewidth]{proof.png} +\end{center} + +\begin{solution} + The fundamental region of $\mathbb{Z}^2$ tiles the plane. Translate these tiles by lattice vectors to stack them on the fundamental region. Then since the union of the intersections of X with these tiles has area greater 1 and they are stacked on a region of area 1, there must be an overlap by a generalization of the pigeonhole principle (if there were no overlap then the sum of the areas would be less than or equal to 1). Take points $x, y$ in the overlap. Then $x - y$ is a lattice point corresponding to the difference in translates, which were lattice points. Hence, $x - y \in \mathbb{Z}^2$. +\end{solution} + +\vfill +\pagebreak + + +%\problem{} +%Does your proof of Blichfeldt's theorem in $\mathbb{Z}^2$ extend to a proof of Blichfeldt's theorem in $\mathbb{Z}^n$? +%\vfill + + +\problem{} +Let $X$ be a region $\in \mathbb{R}^2$ of volume $k$. How many integral points must $X$ contain after a translation? + +\begin{solution} + $\lceil k \rceil$ +\end{solution} + +\vfill + +\definition{} +A region $X$ is \textit{convex} if the line segment connecting any two points in $X$ lies entirely in $X$. + +\problem{} +\begin{itemize} + \item Draw a convex region in the plane. + \item Draw a region that is not convex. +\end{itemize} + +\vfill +\pagebreak + + + +\definition{} +We say a region $X$ is \textit{symmetric} if for all points $x \in X$, $-x$ is also in $X$. + +\problem{} +\begin{itemize} + \item Draw a symmetric region. + \item Draw an asymmetric region. +\end{itemize} + +\vfill + +\theorem{Minkowski's Theorem} +Every convex set in $\mathbb{R}^n$ that is symmetric with respect to the origin and which has a volume greater than $2^n$ contains an integral point that isn't zero. + + +\problem{} +Draw a few sets that satisfy \ref{mink} in $\mathbb{R}^2$. \par +What is the simplest region that has the properties listed above? + +\vfill + + +\problem{} +Let $K$ be a region in $\mathbb{R}^2$ satisfying \ref{mink}. \par +Let $K'$ be this region scaled by $\frac{1}{2}$. + +\begin{itemize} + \item How does the volume of $K'$ compare to $K$? + \item Show that the sum of any two points in $K'$ lies in $K$ \hint{Use convexity.} + \item Apply Blichfeldt's theorem to $K'$ to prove Minkowski's theorem in $\mathbb{R}^2$. +\end{itemize} + +\vfill + +\problem{} +Let $K$ be a region in $\mathbb{R}^n$ satisfying \ref{mink}. Scale this region by $\frac{1}{2}$, called $K' = \frac{1}{2}K$. + +\begin{itemize} + \item How does the volume of $K'$ compare to $K$? + \item Show that the sum of any two points in $K'$ lies in $K$ + \item Apply Blichfeldt's theorem to $K'$ to prove Minkowski's theorem. +\end{itemize} + +\begin{solution} + \begin{itemize} + \item The volume of $K'$ is $\frac{1}{2^n}$ the volume of $K$. + \item Take $x, y \in K'$. It follows that $2x, 2y \in K$. Since $K$ is convex, we have that the midpoint of the line segment between $2x$ and $2y$ is in $K$, and so $\frac{2x + 2y}{2} = x + y \in K$. + \item Since the volume of $K$ is greater than $2^n$, we have the volume of $K'$ is greater than one. + Applying Blichfeldt's theorem, we can find two distinct points $x, y \in K'$ such that $x - y \in \mathbb{Z}^n$. Since $K'$ is symmetric with respect to the origin, we have that $-y \in K'$. Therefore, $x + (-y) \in K$ by the previous part. $x \neq y, x - y \neq 0$, so we have found a nontrivial integer point in $K$. + + \end{itemize} +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Lattices/parts/2 orchard.tex b/src/Advanced/Lattices/parts/2 orchard.tex new file mode 100644 index 0000000..08b2cff --- /dev/null +++ b/src/Advanced/Lattices/parts/2 orchard.tex @@ -0,0 +1,137 @@ +\section{Polya's Orchard Problem} + +You are standing in the center of a circular orchard of integer radius $R$. +A tree of radius $r$ has been planted at every integer point in the circle. +If $r$ is small, you will have a clear line of sight through the orchard. +If $r$ is large, there will be no clear line of sight through in any direction: + +\begin{center} + \hfill + \begin{tikzpicture}[scale=0.4] + \draw[color=black, very thick] (0,0) circle (5); + + \draw[fill=black] (0,0) circle (0.2); + \draw [->, very thick](0,0) -- (0.7, 0.7); + \draw [->, very thick](0,0) -- (-0.7, 0.7); + + \foreach \x in {-4, ..., 4} { + \foreach \y in {-4, ..., 4} { + \ifthenelse{ + % Remove center + \( \x=0 \AND \y=0 \) \OR + % + % Remove corners + \( \x=4 \AND \y=-4 \) \OR + \( \x=4 \AND \y=4 \) \OR + \( \x=-4 \AND \y=4 \) \OR + \( \x=-4 \AND \y=-4 \) \OR + % + % Remove corner corners + \( \x=4 \AND \y=-3 \) \OR + \( \x=4 \AND \y=3 \) \OR + \( \x=-4 \AND \y=3 \) \OR + \( \x=-4 \AND \y=-3 \) \OR + \( \x=3 \AND \y=-4 \) \OR + \( \x=3 \AND \y=4 \) \OR + \( \x=-3 \AND \y=4 \) \OR + \( \x=-3 \AND \y=-4 \) + }{}{ + \draw[fill=teal] (\x,\y) circle (0.4); + }}} + + \draw[fill=teal] (0, 5) circle (0.4); + \draw[fill=teal] (5, 0) circle (0.4); + \draw[fill=teal] (0, -5) circle (0.4); + \draw[fill=teal] (-5, 0) circle (0.4); + \end{tikzpicture} + \hfill + \begin{tikzpicture}[scale=0.4] + \draw[color=black, very thick] (0,0) circle (5); + + \draw[fill=black] (0,0) circle (0.2); + + \draw [->, very thick](0,0) -- (-5,3.7); + \draw [->, very thick](0,0) -- (5, 3.7); + + \foreach \x in {-4, ..., 4} { + \foreach \y in {-4, ..., 4} { + \ifthenelse{ + % Remove center + \( \x=0 \AND \y=0 \) \OR + % + % Remove corners + \( \x=4 \AND \y=-4 \) \OR + \( \x=4 \AND \y=4 \) \OR + \( \x=-4 \AND \y=4 \) \OR + \( \x=-4 \AND \y=-4 \) \OR + % + % Remove corner corners + \( \x=4 \AND \y=-3 \) \OR + \( \x=4 \AND \y=3 \) \OR + \( \x=-4 \AND \y=3 \) \OR + \( \x=-4 \AND \y=-3 \) \OR + \( \x=3 \AND \y=-4 \) \OR + \( \x=3 \AND \y=4 \) \OR + \( \x=-3 \AND \y=4 \) \OR + \( \x=-3 \AND \y=-4 \) + }{}{ + \draw[fill=teal] (\x,\y) circle (0.2); + }}} + + \draw[fill=teal] (0, 5) circle (0.2); + \draw[fill=teal] (5, 0) circle (0.2); + \draw[fill=teal] (0, -5) circle (0.2); + \draw[fill=teal] (-5, 0) circle (0.2); + \end{tikzpicture} + \hfill ~ +\end{center} + +\problem{} +Show that you will have at least one clear line of sight if $r < \frac{1}{\sqrt{R^2 + 1}}$. \par +\hint{Consider the line segment from $(0, 0)$ to $(R, 1)$. Calculate the distance from the closest integer points to the ray.} + +\begin{solution} + Consider the ray from the origin to the point $(R, 1)$. + + The two lattice points closest to this ray are $(1, 0)$ and $(R - 1, 1)$. Say the distance from each of these points to the ray is $\delta$. \par + + Now, consider the triangle with vertices $(0, 0)$, $(1, 0)$, and $(R, 1)$. The area of this triangle is $\frac{1}{2}$. + + The area of this triangle is also equal to $\frac{1}{2} \delta \sqrt{R^2 + 1}$. By algebra, $\delta = \frac{1}{\sqrt{R^2+1}}$. \par + + Therefore, if $r < \frac{1}{\sqrt{R^2+1}}$, we will have a clear line of sight given by this ray. +\end{solution} + + +\vfill +\pagebreak + +\problem{} +Show that there is no line of sight through the orchard if $r > \frac{1}{R}$. You may want to use the following steps: +\begin{itemize} + \item Show that there is no line of sight if $r \geq 1$. + \item Suppose $r < 1$ and $r > \frac{1}{R}$. Then, $R \geq 2$. Choose a potential line of sight passing through an arbitrary point $P$ on the circle. Thicken this line of sight equally on both sides into a rectangle of width $2r$ tangent to $P$ and $-P$. From here, use Minkowski's theorem to get a contradiction. Don't forget + to rule out any lattice points that sit outside the orchard but inside the rectangle. +\end{itemize} + +% Any interest in counting the number of trees in the orchard? If so, google the Gauss circle problem. If orchards are not your slice of fruit, maybe rational approximations are your cup of tea + +\begin{solution} + Suppose $r < 1$ and let $L$ be a potential line of sight. Consider the rectangle of width $2r$ tangent to $P$ and $-P$. Then this is convex and symmetric with respect to the origin. Its area is $(2R)(2r) > 4 \frac{R}{R} = 4$. By Minkowski, we have a nonzero integral point in this rectangle. Suppose first that the integer point is within the orchard. Then this means that there is a tree whose distance to the line is at most $r$. Therefore, this tree blocks the line of sight. Now notice that there is a part of this rectangle that sits outside the orchard. Can the integer point be in this region? This would mean its distance to the origin, $D$, would satisfy $D > R$. Now since this point is within a distance of $r$ of our line $L$, we have that $D < \sqrt{R^2 + r^2} < \sqrt{R^2 + 1}$. So we have that $R < D < \sqrt{R^2 + 1}$. Then $R^2 < D^2 < R^2 + 1$, but $D^2$ is an integer so this is impossible. +\end{solution} + +\vfill + +\problem{Challenge} +Prove that there exists a rational approximation of $\sqrt{3}$ within $10^{-3}$ with denominator at most $501$. Come up with an upper bound for the smallest denominator of a $\epsilon$-close rational approximation of any irrational number $\alpha > 0$. Your bound can have some dependence on $\alpha$ and should get smaller as $\alpha$ gets larger. \\ +\hint{Use the orchard.} + +\begin{solution} + Take the line through the origin of slope $\sqrt{3}$. We would like an orchard for which $r = 10^{-3}$ gives no line of sight, since this will guarantee an integer point within a distance of $10^{-3}$. Then by our previous problem, we can take $10^{-3} > \frac{1}{R}$, so take $R > 1000$. Now since this line intersects the boundary of the orchard at $( \frac{R}{2}, \frac{\sqrt{3R}}{2} )$, we have that the $x$-coordinate is at most $\frac{R}{2} = 501$. Then we have that our lattice point $(x, y)$ satisfies $\sqrt{3x} - 10^{-3} < y < \sqrt{3x} + 10^{-3}$, so $\sqrt{3} - 10^{-3} < \frac{x}{y} < \sqrt{3} + \frac{10^{-3}}{x}$. Therefore, $\frac{y}{x}$ is a rational approximation that is $10^{-3}$-close to $\sqrt{3}$ and has denominator at most $501$. Notice that we got closer than we need to. + + Repeating this same process, our upper bound for the denominator of an $\epsilon$-close approximation of $\alpha$ is $\frac{\text{cos}({\text{atan}({\alpha})})}{\epsilon} = \frac{1}{\sqrt{\alpha^2 + 1 \epsilon}}$. +\end{solution} + +\vfill +\pagebreak + diff --git a/src/Advanced/Lattices/proof.png b/src/Advanced/Lattices/proof.png new file mode 100755 index 0000000..2ed93af Binary files /dev/null and b/src/Advanced/Lattices/proof.png differ diff --git a/src/Advanced/Mock a Mockingbird/main.tex b/src/Advanced/Mock a Mockingbird/main.tex new file mode 100755 index 0000000..f772d2a --- /dev/null +++ b/src/Advanced/Mock a Mockingbird/main.tex @@ -0,0 +1,85 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + +\usepackage{mathtools} % for \coloneqq + +%\usepackage{lua-visual-debug} + +\usepackage{censor} +\usepackage{alltt} + + +\newenvironment{helpbox}[1][0.5]{ + \begin{center} + \begin{tcolorbox}[ + colback=white!90!black, + colframe=white!90!black, + coltitle=black, + center title, + width = #1\textwidth, + leftrule = 0mm, + rightrule = 0mm, + toprule = 0mm, + bottomrule = 0mm, + left = 1mm, + right = 1mm, + top = 1mm, + bottom = 1mm, + toptitle = 1mm, + lefttitle = 1mm, + titlerule = 1pt, + title={\textbf{Things you will need:}} + ] +}{ + \end{tcolorbox} + \end{center} +} + +% Logic block comment +\newcommand{\cmnt}[1]{\textcolor{gray}{\# #1}} + +\newcounter{allttLineCounter} +\setcounter{allttLineCounter}{0} + +\newcommand{\linenoref}[1]{\colorbox{gray!30!white}{#1}} +\newcommand{\lineno}{ + \stepcounter{allttLineCounter}% + \linenoref{\ifnum\value{allttLineCounter}<10 0\fi\arabic{allttLineCounter}}% +} + +% Redefine alltt so it automatically +% resets allttLineCounter +\let\oldalltt\alltt +\renewenvironment{alltt} + {\setcounter{allttLineCounter}{0}\begin{oldalltt}} + {\end{oldalltt}} + + +\newcommand{\thus}{\(\Rightarrow\)} +\newcommand{\qed}{\(\blacksquare\)} + + + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{To Mock a Mockingbird} +\subtitle{ + Prepared by Mark on \today \\ + Based on a book of the same name. +} + +\begin{document} + + \maketitle + + \input{parts/00 intro} + \input{parts/01 tmam} + \input{parts/02 kestrel} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Mock a Mockingbird/meta.toml b/src/Advanced/Mock a Mockingbird/meta.toml new file mode 100644 index 0000000..891ab9c --- /dev/null +++ b/src/Advanced/Mock a Mockingbird/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Mock a Mockingbird" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Mock a Mockingbird/parts/00 intro.tex b/src/Advanced/Mock a Mockingbird/parts/00 intro.tex new file mode 100644 index 0000000..8e13a24 --- /dev/null +++ b/src/Advanced/Mock a Mockingbird/parts/00 intro.tex @@ -0,0 +1,46 @@ +\section{Introduction} + +A certain enchanted forest is inhabited by talking birds. Each of these birds has a name, and will respond whenever it hears the name of another. Suppose you are exploring this forest and come across the bird $A$. You call the name of bird $B$. $A$ hears you and responds with the name of some other bird, which we will designate $AB$. + +Bird $AB$ is, by definition, $A$'s response to $B$. + +\vspace{2mm} + +As you wander around this forest, you quickly discover two interesting facts: +\begin{enumerate}[itemsep = 1mm] + \item $A$'s response to $B$ mustn't be the same as $B$'s response to $A$. + \item Given three birds $A$, $B$, and $C$, $(AB)C$ and $A(BC)$ are not necessarily the same bird. \\ + Bird $A(BC)$ is $A$'s response to bird $BC$, while $(AB)C$ is $AB$'s response to $C$. \\ + Thus, $ABC$ is ambiguous. Parenthesis are mandatory. +\end{enumerate} + +\vspace{2mm} + +You also find that this forest has two laws: +\begin{enumerate}[itemsep = 1mm] + \item \textit{The Law of Composition}: \\ + For any two birds $A$ and $B$, there must be a bird $C$ so that $Cx = A(Bx)$ + \item \textit{The Law of the Mockingbird}: \\ + The forest must contain the Mockingbird $M$, which always satisfies $Mx = xx$. \\ + In other words, the Mockingbird's response to any bird $x$ is the same as $x$'s response to itself. +\end{enumerate} + +\vfill + +\definition{} +We say a bird $A$ is fond of a bird $B$ if $A$ responds to $B$ with $B$. \\ +In other words, $A$ is fond of $B$ if $AB = B$. + +\vfill + +\definition{} +We say a bird $C$ \textit{composes} $A$ with $B$ if for any bird $x$, +$$ + Cx = A(Bx) +$$ +In other words, this means that $C$'s response to $x$ is the same as $A$'s response to $B$'s response to $x$. \\ +Note that $C$ is exactly the kind of bird $L_1$ guarantees. + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Mock a Mockingbird/parts/01 tmam.tex b/src/Advanced/Mock a Mockingbird/parts/01 tmam.tex new file mode 100644 index 0000000..55a8af1 --- /dev/null +++ b/src/Advanced/Mock a Mockingbird/parts/01 tmam.tex @@ -0,0 +1,175 @@ +\section{To Mock a Mockingbird} + +\problem{} +Mark tells you that any bird $A$ is fond of at least one other bird. \\ +Complete his proof. +\begin{alltt} + let A \cmnt{Let A be any any bird.} + let Cx = A(Mx) \cmnt{Define C as the composition of A and M} + + \cmnt{The rest is up to you.} + CC = ?? +\end{alltt} + + +\begin{helpbox} + \texttt{Law:} There exists a Mockingbird, $Mx := xx$ \\ + \texttt{Def:} $A$ is fond of $B$ if $AB = B$ +\end{helpbox} + + +\begin{solution} + \begin{alltt} + \lineno{} let A \cmnt{Let A be any any bird.} + \lineno{} let Cx = A(Mx) \cmnt{Define C as the composition of A and M} + \lineno{} CC = A(MC) + \lineno{} = A(CC) \qed{} + \end{alltt} +\end{solution} + +\vfill +\problem{} +We say a bird $A$ is \textit{egocentric} if it is fond of itself. \\ +Show that the laws of the forest guarantee that at least one bird is egocentric. + + +\begin{helpbox} + \texttt{Law:} There exists a Mockingbird, $Mx := xx$ \\ + \texttt{Def:} $A$ is fond of $B$ if $AB = B$ \\ + \texttt{Lem:} Any bird is fond of at least one bird. +\end{helpbox} + +\begin{solution} + \begin{alltt} + \lineno{} \cmnt{We know M is fond of at least one bird.} + \lineno{} let E so that ME = E + \lineno{} + \lineno{} ME = E \cmnt{By definition of fondness} + \lineno{} ME = EE \cmnt{By definition of M} + \lineno{} \thus{} EE = E \qed{} + \end{alltt} +\end{solution} + +\vfill +\pagebreak + + +\definition{} +We say a bird $A$ is \textit{agreeable} if for all birds $B$, there is at least one bird $x$ on which $A$ and $B$ agree. \\ +In other words, $A$ is agreeable if given any $B$, we can find a bird $x$ satisfying $Ax = Bx$. + +\problem{} +Is the Mockingbird agreeable? + +\begin{solution} + We know that $Mx = xx$. \\ + + From this definition, we see that $M$ agrees with any $x$ on $x$ itself. +\end{solution} + +\vfill + +\problem{} +Take two birds $A$ and $B$. Let $C$ be their composition. \\ +Show that if $C$ is agreeable, $A$ is agreeable. +\begin{alltt} + \cmnt{Given information} + let A, B + let Cx = A(Bx) + + let D \cmnt{Arbitrary bird} + let Ex = D(Bx) \cmnt{Define E as the composition of D and B} + Cy = ?? +\end{alltt} + +\begin{helpbox}[0.65] + \texttt{Def:} $A$ is agreeable if $Ax = Bx$ for all $B$ with some $x$. \\ + \texttt{Law:} For any $A, B$, there is C defined by Cx = A(Bx) +\end{helpbox} + + +\begin{solution} + \begin{alltt} + \lineno{} \cmnt{Given information} + \lineno{} let A, B + \lineno{} let Cx = A(Bx) + \lineno{} + \lineno{} let D \cmnt{Arbitrary bird} + \lineno{} let Ex = D(Bx) \cmnt{Define E as the composition of D and B} + \lineno{} let y so that Cy = Ey \cmnt{Such a y must exist because C is agreeable} + \lineno{} + \lineno{} A(By) = Ey + \lineno{} = D(By) \qed{} + \end{alltt} +\end{solution} + +\vfill +\pagebreak + +\problem{} +Given three arbitrary birds $A$, $B$, and $C$, show that there exists a bird $D$ satisfying $Dx = A(B(Cx))$ + +\begin{solution} + \begin{alltt} + \lineno{} let A, B, C + \lineno{} + \lineno{} \cmnt{Invoke the Law of Composition:} + \lineno{} let Qx = B(Cx) + \lineno{} let Dx = A(Qx) + \lineno{} + \lineno{} Dx = A(Qx) + \lineno{} = A(B(Cx)) \qed{} + \end{alltt} +\end{solution} + +\vfill + + +\definition{} +We say two birds $A$ and $B$ are \textit{compatible} if there are birds $x$ and $y$ so that $Ax = y$ and $By = x$. \\ +Note that $x$ and $y$ may be the same bird. \\ + +\problem{} +Show that any two birds in this forest are compatible. \\ +\begin{alltt} + let A, B + let Cx = A(Bx) +\end{alltt} + +\begin{helpbox} + \texttt{Law:} Law of composition \\ + \texttt{Lem:} Any bird is fond of at least one bird. +\end{helpbox} + +\begin{solution} + \begin{alltt} + \lineno{} let A, B + \lineno{} + \lineno{} let Cx = A(Bx) \cmnt{Composition} + \lineno{} let y = Cy \cmnt{Let C be fond of y} + \lineno{} + \lineno{} Cy = y + \lineno{} = A(By) + \lineno{} + \lineno{} let x = By \cmnt{Rename By to x} + \lineno{} Ax = y \qed{} + \end{alltt} +\end{solution} + +\vfill + +\problem{} +Show that any bird that is fond of at least one bird is compatible with itself. + +\begin{solution} + \begin{alltt} + \lineno{} let A + \lineno{} let x so that Ax = x \cmnt{A is fond of at least one other bird} + \lineno{} Ax = x \qed{} + \end{alltt} + + That's it. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Mock a Mockingbird/parts/02 kestrel.tex b/src/Advanced/Mock a Mockingbird/parts/02 kestrel.tex new file mode 100644 index 0000000..293b508 --- /dev/null +++ b/src/Advanced/Mock a Mockingbird/parts/02 kestrel.tex @@ -0,0 +1,136 @@ +\section{The Curious Kestrel} + +\definition{} +Recall that a bird is \textit{egocentric} if it is fond of itself. \\ +A bird is \textit{hopelessly egocentric} if $Bx = B$ for all birds $x$. + +\definition{} +More generally, we say that a bird $A$ is \textit{fixated} on a bird $B$ if $Ax = B$ for all $x$. \\ +Convince yourself that a hopelessly egocentric bird is fixated on itself. + + + +\problem{} +Say $A$ is fixated on $B$. Is $A$ fond of $B$? + +\begin{solution} + Yes! See the following proof. + \begin{alltt} + \lineno{} let A + \lineno{} let B so that Ax = B + \lineno{} \thus{} AB = B \qed{} + \end{alltt} +\end{solution} +\vfill + + + +\definition{} +The \textit{Kestrel} $K$ is defined by the following relationship: +$$ + (Kx)y = x~~~\forall x, y +$$ +In other words, this means that for every bird $x$, the bird $Kx$ is fixated on $x$. + +\problem{} +Show that an egocentric Kestrel is hopelessly egocentric. + +\begin{solution} + \begin{alltt} + \lineno{} KK = K + \lineno{} \thus{} (KK)y = K \cmnt{By definition of the Kestrel} + \lineno{} \thus{} Ky = K \qed{} \cmnt{By 01} + \end{alltt} +\end{solution} + +\vfill +\pagebreak + + +\problem{} +Assume the forest contains a Kestrel. \\ +Given the Law of Composition and the Law of the Mockingbird, show that at least one bird is hopelessly egocentric. + +\begin{helpbox}[0.75] + \texttt{Def:} $K$ is defined by $(Kx)y = x$ \\ + \texttt{Def:} $A$ is fond of $B$ if $AB = B$ \\ + \texttt{???:} You'll need one more result from the previous section. Good luck! +\end{helpbox} + +\begin{solution} + The final piece is a lemma we proved earlier: \\ + Any bird is fond of at least one bird + + \begin{alltt} + \lineno{} let A so that KA = A \cmnt{Any bird is fond of at least one bird} + \lineno{} (KA)y = y \cmnt{By definition of the kestrel} + \lineno{} \thus{} Ay = A \qed{} \cmnt{By 01} + \end{alltt} +\end{solution} + +\vfill + +\problem{Kestrel Left-Cancellation} +In general, $Ax = Ay$ does not imply $x = y$. However, this is true if $A$ is $K$. \\ +Show that $Kx = Ky \implies x = y$. + +\begin{alltt} + \cmnt{This is a hint.} + let x, y so that Kx = Ky +\end{alltt} + +\begin{solution} + \begin{alltt} + \lineno{} let x, y so that Kx = Ky + \lineno{} let z + \lineno{} + \lineno{} (Kx)z = (Ky)z \cmnt{By 01} + \lineno{} + \lineno{} \cmnt{By the definition of K} + \lineno{} (Kx)z = x + \lineno{} (Ky)z = y + \lineno{} + \lineno{} \thus{} x = (Kx)z = (Ky)z = y \qed{} + \end{alltt} +\end{solution} + +\vfill +\pagebreak + +\problem{} +Show that if $K$ is fond of $Kx$, $K$ is fond of $x$. + +\begin{solution} + \begin{alltt} + \lineno{} let x so that K(Kx) = Kx + \lineno{} (K(Kx))y = (Kx)y + \lineno{} = Kx \cmnt{By definition of K} + \lineno{} x = Kx \cmnt{By 03 and definition of K} + \end{alltt} +\end{solution} + +\vfill + +\problem{} +An egocentric Kestrel must be extremely lonely. Why is this? + +\begin{solution} + If a Kestrel is egocentric, it must be the only bird in the forest! + + \begin{alltt} + \lineno{} \cmnt{Given} + \lineno{} Kx = K for some x + \lineno{} \cmnt{We have shown that an egocentric kestrel is hopelessly egocentric} + \lineno{} Kx = K for all x + \lineno{} + \lineno{} let x, y + \lineno{} Kx = K + \lineno{} Ky = K + \lineno{} Kx = Ky + \lineno{} x = y for all x, y \cmnt{By \ref{leftcancel}} + \lineno{} x = y = K \qed{} \cmnt{By 10, and since K exists} + \end{alltt} +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Nonstandard Analysis/main.tex b/src/Advanced/Nonstandard Analysis/main.tex new file mode 100755 index 0000000..c0cc0e9 --- /dev/null +++ b/src/Advanced/Nonstandard Analysis/main.tex @@ -0,0 +1,49 @@ +% Copyright (C) 2023 +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% You may have received a copy of the GNU General Public License +% along with this program. If not, see . +% +% +% +% If you edit this, please give credit! +% Quality handouts take time to make. + + +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + nosolutions, + singlenumbering, +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} +\usepackage{units} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Nonstandard Analysis} +\subtitle{ + Prepared by Mark on \today{} \\ + Based on handouts by Nikita and Stepan +} + + +% This handout is pretty difficult. Make sure you can all solve all the problems yourself, +% and remember that each SECTION was a two-hour lesson with a smart class. +% From experience, the following holds: +% supremum is a better lesson than dual numbers, which is better than extensions. + + +\begin{document} + + \maketitle + + \input{parts/supremum} + \input{parts/dual} + \input{parts/extensions} + +\end{document} diff --git a/src/Advanced/Nonstandard Analysis/meta.toml b/src/Advanced/Nonstandard Analysis/meta.toml new file mode 100644 index 0000000..e79cf0a --- /dev/null +++ b/src/Advanced/Nonstandard Analysis/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Nonstandard Analysis" + +[publish] +handout = false +solutions = false diff --git a/src/Advanced/Nonstandard Analysis/parts/dual.tex b/src/Advanced/Nonstandard Analysis/parts/dual.tex new file mode 100644 index 0000000..b7eb55a --- /dev/null +++ b/src/Advanced/Nonstandard Analysis/parts/dual.tex @@ -0,0 +1,103 @@ +% Copyright (C) 2023 +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% You may have received a copy of the GNU General Public License +% along with this program. If not, see . +% +% +% +% If you edit this, please give credit! +% Quality handouts take time to make. + + +\section{Dual Numbers} + +\definition{} +In the problems below, let $\varepsilon$ a positive infinitesimal so that $\varepsilon^2 = 0$. \par +\note{Note that $\varepsilon \neq 0$.} + +\definition{} +The set of \textit{dual numbers} consists of elements of the form $a + b\varepsilon$, where $a, b \in \mathbb{R}$. + +\problem{} +Compute $(a + b\varepsilon) \times (c + d\varepsilon)$. + +\vfill + + + +\definition{} +Let $f(x)$ be an algebraic function $\mathbb{R} \to \mathbb{R}$. \par +(that is, a function we can write using the operators $+-\times\div$ and integer powers) \par + +\vspace{2mm} + +the \textit{derivative} of such an $f$ is a function $f'$ that satisfies the following: +\begin{equation*} + f(x + \varepsilon) = f(x) + f'(x)\varepsilon +\end{equation*} +If $f(x + \varepsilon)$ is not defined, we will say that $f$ is not \textit{differentiable} at $x$. + +\problem{} +What is the derivative of $f(x) = x^2$? + +\vfill + +\problem{} +What is the derivative of $f(x) = x^n$? + +\vfill + +\problem{} +Assume that the derivatives of $f$ and $g$ are known. \par +Find the derivatives of $h(x) = f(x) + g(x)$ and $k(x) = f(x) \times g(x)$. + +\vfill +\pagebreak + + + + +\problem{} +When can you divide dual numbers? \par +That is, for what numbers $(a + b\varepsilon)$ is there a $(x + y\varepsilon)$ such that $(a +b\varepsilon)(x+y\varepsilon) = 1$? + +\vfill + +\problem{} +Find an explicit formula for the inverse of a dual number $(a + b\varepsilon)$, assuming one exists. \par +Then, use this find the derivative of $f(x) = \frac{1}{x}$. + +\vfill + +\problem{} +Which dual numbers have a square root? \par +That is, for which dual numbers $(a + b\varepsilon)$ is there a dual number +$(x + y\varepsilon)$ such that $(x + y\varepsilon)^2 = a + b\varepsilon$? + +\vfill + +\problem{} +Find an explicit formula for the square root and use it to find the derivative of $f(x) = \sqrt{x}$ + +\vfill + +\problem{} +Find the derivative of the following functions: +\begin{itemize} + \item $f(x) = \frac{x}{1 + x^2}$ + \item $g(x) = \sqrt{1 - x^2}$ +\end{itemize} + +\vfill + +\problem{} +Assume that the derivatives of $f$ and $g$ are known. \par +What is the derivative of $f(g(x))$? + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Nonstandard Analysis/parts/extensions.tex b/src/Advanced/Nonstandard Analysis/parts/extensions.tex new file mode 100644 index 0000000..e0cb5d7 --- /dev/null +++ b/src/Advanced/Nonstandard Analysis/parts/extensions.tex @@ -0,0 +1,213 @@ +% Copyright (C) 2023 +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% You may have received a copy of the GNU General Public License +% along with this program. If not, see . +% +% +% +% If you edit this, please give credit! +% Quality handouts take time to make. + +\section{Extensions of $\mathbb{R}$} + +\definition{} +An \textit{ordered field} consists of a set $S$, the operations $+$ and $\times$, and the relation $<$. \par +An ordered field must satisfy the following properties: + +\begin{itemize} + \item \textbf{Properties of $+$:} + \begin{itemize} + \item Commutativity: $a + b = b + a$ + \item Associativity: $a + (b + c) = (a + b) + c$ + \item Identity: there exists an element $0$ so that $a + 0 = a$ for all $a \in S$ + \item Inverse: for every $a$, there exists a $-a$ so that $a + (-a) = 0$ + \end{itemize} + + \item \textbf{Properties of $\times$:} + \begin{itemize} + \item Commutativity + \item Associativity + \item Identity (which we label $1$) + \item For every $a \neq 0$, there exists an inverse $a^{-1}$ so that $aa^{-1} = 1$ + \item Distributivity: $a(b + c) = ab + ac$ + \end{itemize} + + \item \textbf{Properties of $<$:} + \begin{itemize} + \item Non-reflexive: $x < x$ is always false + \item Transitive: $x < y$ and $y < z$ imply $x < z$ + \item Connected: for all $x, y \in S$, either $x < y$, $x > y$, or $x = y$. + \item If $x < y$ then $x + z < y + z$ + \item If $x < y$ and $z > 0$, then $xz < yz$ + \item $0 < 1$ + \end{itemize} +\end{itemize} + +\definition{} +An ordered field that contains $\mathbb{R}$ is called an \textit{extension} of $\mathbb{R}$. + +\definition{} +The \textit{Archimedean property} states the following: \par +For all positive $x, y$, there exists an $n$ so that $nx \geq y$. + +\theorem{} +All extensions of $\mathbb{R}$ are nonarchemedian. \par +Proving this is difficult. + + +\vfill +\pagebreak + + +\problem{} +Which of the following are ordered fields? +\begin{itemize}[itemsep=2mm] + \item $\mathbb{R}$ with the usual definitions of $+$, $\times$, $<$ + \item $\mathbb{R}$ with the usual definitions of $+$, $\times$, $\leq$ \par + \note{Note that our relation here is $\leq$, not $<$} + \item $\mathbb{Z}$ with the usual definitions of $+$, $\times$, $<$ + \item $\mathbb{Q}$ with the usual definitions of $+$, $\times$, $<$ + \item $\mathbb{C}$ with the usual definitions of $+$, $\times$, \par + and with $(a + bi) < (c + di)$ iff $a < c$. +\end{itemize} + +\vfill + + +\problem{} +Show that each of the following is true in any ordered field. \par +The list of field axioms is provided below, for convenience. +\begin{enumerate} + \item if $x \neq 0$ then $(x^{-1})^{-1} = x$ + \item $0 \times x = 0$ + \item $(-x)(-y) = xy$ + \item if $0 < x < y$, then $x^{-1} > y^{-1}$ +\end{enumerate} + + +%\begin{solution} +% \textbf{Part A:} +% We know that $x^{-1} \times (x^{-1})^{-1} = 1$ \par +% Thus $x \times (x^{-1} \times (x^{-1})^{-1}) = x \times 1 = x$ \par +% We can rewrite this as $(x \times x^{-1}) \times (x^{-1})^{-1} = x$ \par +% When then becomes $1 \times (x^{-1})^{-1} = x$ \par +% And thus $(x^{-1})^{-1} = x$ +%\end{solution} + +\vfill + +\begin{itemize} + \item \textbf{Properties of $+$:} + \begin{itemize} + \item Commutativity: $a + b = b + a$ + \item Associativity: $a + (b + c) = (a + b) + c$ + \item Identity: there exists an element $0$ so that $a + 0 = a$ for all $a \in S$ + \item Inverse: for every $a$, there exists a $-a$ so that $a + (-a) = 0$ + \end{itemize} + + \item \textbf{Properties of $\times$:} + \begin{itemize} + \item Commutativity + \item Associativity + \item Identity (which we label $1$) + \item For every $a \neq 0$, there exists an inverse $a^{-1}$ so that $aa^{-1} = 1$ + \item Distributivity: $a(b + c) = ab + ac$ + \end{itemize} + + \item \textbf{Properties of $<$:} + \begin{itemize} + \item Non-reflexive: $x < x$ is always false + \item Transitive: $x < y$ and $y < z$ imply $x < z$ + \item Connected: for all $x, y \in S$, either $x < y$, $x > y$, or $x = y$. + \item If $x < y$ then $x + z < y + z$ + \item If $x < y$ and $z > 0$, then $xz < yz$ + \item $0 < 1$ + \end{itemize} +\end{itemize} +\pagebreak + + + + + + + + +\definition{} +In an ordered field, the \textit{magnitude} of a number x is defined as follows: \par +\begin{equation*} + |x| = + \begin{cases} + x & \text{\tab} x \geq 0 \\ + -x & \text{\tab otherwise} + \end{cases} +\end{equation*} + +\definition{} +We say an element $\delta$ of an ordered field is \textit{infinitesimal} if +$|nd| < 1$ % spell:disable-line +for all $n \in \mathbb{Z^+}$. \par +\note{Note that $\mathbb{Z}^+$ is a subset of any nonarchimedian extension of $\mathbb{R}$.} \par + +\vspace{2mm} + +Likewise, we say $x$ is \textit{limited} if $|x| < n$ for some $n \in \mathbb{Z}^+$. \par +Elements that are not limited are \textit{unlimited}. + +\definition{} +We say an element $x$ of a field is \textit{positive} if $x > 0$. \par +We say $x$ is \textit{negative} if $x < 0$. \par + + +\problem{} +Show that a positive $\delta$ is infinitesimal if and only if $\delta < x$ for all $x \in \mathbb{R}^+$. \par +Then, show that a negative $\delta$ is infinitesimal if and only if $\delta > x$ for every $x \in \mathbb{R}^-$. + +\vfill + + +\problem{} +Prove the following statements: \par +\begin{itemize} + \item If $\delta$ and $\varepsilon$ are infinitesimal, then $\delta + \varepsilon$ is infinitesimal. + \item If $\delta$ is infinitesimal and $x$ is limited, then $x\delta$ is infinitesimal. + \item If $x$ and $y$ are limited, $xy$ and $x+y$ are too. + \item A nonzero $\delta$ is infinitesimal iff $\delta^{-1}$ is unlimited. +\end{itemize} + +\vfill +\pagebreak + + +\problem{} +Let $\delta$ be a positive infinitesimal. Which is greater? +\begin{itemize} + \item $\delta$ or $\delta^2$ + \item $(1 - \delta)$ or $(1 + \delta^2)^{-1}$ + \item $\frac{1 + \delta}{1 + \delta^2}$ or $\frac{2 + \delta^2}{2 + \delta^3}$ \par + \note[Note]{we define $\frac{1}{x}$ as $x^{-1}$, and thus $\frac{a}{b} = a \times b^{-1}$} +\end{itemize} + +\vfill + + +\definition{} +We say two elements of an ordered field are \textit{infinitely close} if $x - y$ is infinitesimal. \par +We say that $x_0 \in \mathbb{R}$ is the \textit{standard part} of $x$ if it is infinitely close to $x$. \par + +We will denote the standard part of $x$ as $\text{st}(x)$. \par +You may assume that $\text{st}(x)$ exists and is unique for limited $x$. \par + +%\problem{} +%Let $H$ be positive unlimited. Determine which of the following are limited. \par + +\problem{} +Show that $\text{st}(x + y) = \text{st}(x) + \text{st}(y)$ and $\text{st}(xy) = \text{st}(x) \text{st}(y)$. \par + +\vfill +\pagebreak diff --git a/src/Advanced/Nonstandard Analysis/parts/supremum.tex b/src/Advanced/Nonstandard Analysis/parts/supremum.tex new file mode 100644 index 0000000..bd0dbf7 --- /dev/null +++ b/src/Advanced/Nonstandard Analysis/parts/supremum.tex @@ -0,0 +1,152 @@ +% Copyright (C) 2023 +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% You may have received a copy of the GNU General Public License +% along with this program. If not, see . +% +% +% +% If you edit this, please give credit! +% Quality handouts take time to make. + + +\section*{The supremum \& the infimum} + +\definition{} +In this section, we'll define a \say{real number} as a decimal, infinite or finite. + +\problem{} +Write $2.317171717...$ as a simple fraction. + +\vfill + +\problem{} +Write $\nicefrac{2}{11}$ as an infinite decimal and prove that your answer is correct. + +\vfill + +\problem{} +Show that $0.999... = 1$ + +\note[Note]{ + There is no real number $0.0...1$ with a digit $1$ \say{at infinity.} \\ + Some numbers have two decimal representations, some have only one. +} + + +\vfill + + +\problem{} +Concatenate all the natural numbers in order to form $0.12345678910111213...$. \par +Show that the resulting decimal is irrational. + +\vfill + +\problem{} +Show that a rational number exists between any two real numbers. + +\vfill +\pagebreak + +\definition{} +Let $M$ be a subset of $\mathbb{R}$.\par +We say $c \in \mathbb{R}$ is an \textit{upper bound} of $M$ if $c \geq m$ for all $m \in M$. \par +The smallest such $c$ is called the \textit{supremum} of $M$, and is denoted $\text{sup}(M)$. \par + +\vspace{2mm} + +Similarly, $x \in \mathbb{R}$ is a \textit{lower bound} of $M$ if $x \leq m$ for all $m \in M$. \par +The largest upper bound of $M$ is called the \textit{infimum} of $M$, denoted $\text{inf}(M)$. + +\problem{} +Show that $x$ is the supremum of $M$ if and only if... +\begin{itemize} + \item for all $m \in M$, $m \leq x$, and + \item for any $x_0 < x$, there exists an $m \in M$ so that $m > x_0$ +\end{itemize} + +\vfill + + + +\problem{} +Show that any subset of $\mathbb{R}$ has at most one supremum and at most one infimum. + +\vfill + + + +\problem{} +Find the supremum and infimum of the following sets: +\begin{itemize} + \item $\bigl\{ a^2 + 2a \bigl| -5 < a < 5\bigr\}$ + \item $\bigl\{\pm \frac{n}{2n + 1} \bigl| n \in \mathbb{N}\bigr\}$ +\end{itemize} + +\vfill + + +\problem{} +Let $A$ and $B$ be subsets of $\mathbb{R}$, and let $\text{sup}(A)$ and $\text{sup}(B)$ be known. \par +Compute the following in terms of $\text{sup}(A)$ and $\text{sup}(B)$. +\begin{itemize} + \item $\text{sup}(A \cup B)$ + \item $\text{sup}(A + B)$, where $A + B = {a + b \forall (a, b) \in A \times B}$, + \item $\text{inf}(A \cdot B)$, where $A \cdot B = {ab \forall (a, b) \in A \times B}$ +\end{itemize} + + +\vfill + +\problem{} +Prove the assumptions in \ref{stpart}: \par +Show that $\text{st}(x)$ is exists and is unique for limited $x$. + +\vfill +\pagebreak + + +\theorem{Completeness Axiom} +Every non-empty subset of $\mathbb{R}$ that is bounded above has a least upper bound. + +\problem{} +Show that $a < \text{sup}(A)$ if and only if there is a $c$ in $A$ where $a < c$ + +\vfill + +\problem{} +Use the definitions in this handout to prove \ref{completeness}. \par +\hint{Build the supremum one digit at a time.} + +\vfill + +\problem{} +Let $[a_1, b_1] \supseteq [a_2, b_3] \supseteq [a_3, b_3] \supseteq ...$ be an infinite sequence of closed line intervals. +\par Show that there exists a $c \in \mathbb{R}$ that lies in all of them. Is this true of open intervals? + + +\vfill +\pagebreak + +\problem{Bonus} +Show that every real number in $[0, 1]$ can be written as a sum of 9 numbers \par +Whose decimal representations only contain 0 and 8. \par + +\vfill + +\problem{Bonus} +Two genies take an infinite amount of turns and write the digits of an infinite +decimal. The first genie, on every turn, writes any finite amount of digits to the tail of the decimal. +The second genie writes one digit to the end. If the resulting decimal after an infinite amount +of turns is periodic, the first genie wins; otherwise, the second genie wins. Who has a winning +strategy? \par + + +\vfill +\pagebreak + diff --git a/src/Advanced/Origami/images/72.png b/src/Advanced/Origami/images/72.png new file mode 100644 index 0000000..9e4d04f Binary files /dev/null and b/src/Advanced/Origami/images/72.png differ diff --git a/src/Advanced/Origami/images/O5Compass.png b/src/Advanced/Origami/images/O5Compass.png new file mode 100644 index 0000000..bb69953 Binary files /dev/null and b/src/Advanced/Origami/images/O5Compass.png differ diff --git a/src/Advanced/Origami/images/Segment_division.png b/src/Advanced/Origami/images/Segment_division.png new file mode 100644 index 0000000..747e441 Binary files /dev/null and b/src/Advanced/Origami/images/Segment_division.png differ diff --git a/src/Advanced/Origami/images/axioms/01.png b/src/Advanced/Origami/images/axioms/01.png new file mode 100644 index 0000000..7aa057c Binary files /dev/null and b/src/Advanced/Origami/images/axioms/01.png differ diff --git a/src/Advanced/Origami/images/axioms/02.png b/src/Advanced/Origami/images/axioms/02.png new file mode 100644 index 0000000..f9ae309 Binary files /dev/null and b/src/Advanced/Origami/images/axioms/02.png differ diff --git a/src/Advanced/Origami/images/axioms/03.png b/src/Advanced/Origami/images/axioms/03.png new file mode 100644 index 0000000..28bf506 Binary files /dev/null and b/src/Advanced/Origami/images/axioms/03.png differ diff --git a/src/Advanced/Origami/images/axioms/04.png b/src/Advanced/Origami/images/axioms/04.png new file mode 100644 index 0000000..a5bbbb4 Binary files /dev/null and b/src/Advanced/Origami/images/axioms/04.png differ diff --git a/src/Advanced/Origami/images/axioms/05.png b/src/Advanced/Origami/images/axioms/05.png new file mode 100644 index 0000000..7cde5b5 Binary files /dev/null and b/src/Advanced/Origami/images/axioms/05.png differ diff --git a/src/Advanced/Origami/images/axioms/06.png b/src/Advanced/Origami/images/axioms/06.png new file mode 100644 index 0000000..365bae6 Binary files /dev/null and b/src/Advanced/Origami/images/axioms/06.png differ diff --git a/src/Advanced/Origami/images/axioms/07.png b/src/Advanced/Origami/images/axioms/07.png new file mode 100644 index 0000000..a22714d Binary files /dev/null and b/src/Advanced/Origami/images/axioms/07.png differ diff --git a/src/Advanced/Origami/images/exo51.png b/src/Advanced/Origami/images/exo51.png new file mode 100644 index 0000000..2bc7706 Binary files /dev/null and b/src/Advanced/Origami/images/exo51.png differ diff --git a/src/Advanced/Origami/images/exo53.png b/src/Advanced/Origami/images/exo53.png new file mode 100644 index 0000000..d22d98e Binary files /dev/null and b/src/Advanced/Origami/images/exo53.png differ diff --git a/src/Advanced/Origami/images/prob9.png b/src/Advanced/Origami/images/prob9.png new file mode 100644 index 0000000..e1d142e Binary files /dev/null and b/src/Advanced/Origami/images/prob9.png differ diff --git a/src/Advanced/Origami/images/prob9s.png b/src/Advanced/Origami/images/prob9s.png new file mode 100644 index 0000000..b5f7339 Binary files /dev/null and b/src/Advanced/Origami/images/prob9s.png differ diff --git a/src/Advanced/Origami/main.tex b/src/Advanced/Origami/main.tex new file mode 100755 index 0000000..40d925b --- /dev/null +++ b/src/Advanced/Origami/main.tex @@ -0,0 +1,397 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + %shortwarning +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\graphicspath{ {./images/} } + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Origami} +\subtitle{Prepared by everyone on \today} + +\begin{document} + + \maketitle + + \section{Axioms of Origami} + + \vspace{1cm} + + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 1:} \par + \includegraphics[height=2.5cm]{axioms/01.png} + \end{center} + Given two points, we can fold a line between them. + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 2:} \par + \includegraphics[height=3cm]{axioms/02.png} + \end{center} + Given two points, we can make a fold that places one atop the other. + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 3:} \par + \includegraphics[height=3cm]{axioms/03.png} + \end{center} + Given two lines, we can make a fold that places one atop the other + \end{minipage} + \hfill~ + + \vfill + + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 4:} \par + \includegraphics[height=3cm]{axioms/04.png} + \end{center} + Given a point and a line, we can make a fold through the point and perpendicular to the line. + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 5:} \par + \includegraphics[height=3cm]{axioms/05.png} + \end{center} + Given two points and a line, we can make a fold through one point that places the second on the line. + \end{minipage} + \hfill + \begin{minipage}{0.3\textwidth} + \begin{center} + \textbf{Axiom 6:} \par + \includegraphics[height=3cm]{axioms/06.png} + \end{center} + Given two points and two lines, we can make a fold that places each point on a line. + \end{minipage} + \hfill~ + + \vfill + + % Subcase of 6 + %\begin{minipage}{0.3\textwidth} + % \begin{center} + % \textbf{Axiom 7:} \\ + % \includegraphics[height=3cm]{axioms/07.png} + % \end{center} + % Given a point $P$ and two lines $l, m$, we can make fold perpendicular to $l$ that places $P$ on $m$. + %\end{minipage} + + \vfill + \pagebreak + + \problem{} + \note{Proposed by Nikita} + + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Take a piece of paper. Let the bottom edge be $l_1$ and take $p_1$ to be a point in the middle and close to $l_1$. + Then choose $p_2$ to be anywhere on the left or right edge of the square and perform Axiom 5. + Then choose a different $p_2$. Repeat this 8 or 9 times keeping the same $p_1$ and choosing different $p_2$'s. + What do you see? \par + + \begin{center} + \includegraphics[height=4cm]{exo51.png} + \end{center} + + + \item Then, take another piece of paper. + Draw two random intersecting lines $l_1$ and $l_2$ and points $p_1$ and $p_2$ about an inch close to their intersection. + Perform a Beloch fold for them. + \end{enumerate} + + + \begin{solution} + \textbf{A:} The repeated use of Axiom 5 in this exercise will result in the appearance of a parabola on the paper. Really! \par + + \begin{center} + \includegraphics[height=3cm]{exo53.png} + \end{center} + + To see why, imagine making one of the folds in this exercise. Before you unfold the flap, take a heavy black pen and draw a line from the point $p_1$ + to the folded edge, making it perpendicular to the "folded-up" segment of $l_1$ (as in the left picture above). + If our pen is heavy enough, this line will bleed through the paper and mark the underneath side as well, so when we unfold + this flap we'll see two lines (as in the right picture above). Note that these two lines have the same length and one is + perpendicular to the original line $l_1$. This shows that exactly one point on the crease line we just made is equidistant + to the point $p_1$ and the line $l_1$. In other words, the crease line is tangent to the parabola with focus $p_1$ and + directrix $l_1$. + This should seem amazing - origami actually allows us to do simple calculus! Just one fold computes a tangent line of a parabola. + + But there's a more important thing to observe here. Parabolas are given by second-degree equations. + Thus Axiom 5 finds a point for us on some second-degree equation. In other words, + Axiom 5 solves second-degree equations for us! It may seem strange to think of an origami fold as solving an equation, + but mathematically this is exactly what is going on. + + \vspace{2mm} + + \textbf{B:} If you look closely, Axiom 6 is just like Axiom 5 but times two: In Axiom 5 $p_1$ is the focus and $l_1$ is the directrix of a parabola. In Axiom 6 we have this again, but also p2 is the focus and $l_2$ is the directrix of another parabola! + Thus Axiom 6 solves the following problem: Given two parabolas drawn in the plane, find a line that is tangent to both of them. + + Exercise: Show that doing this is equivalent to solving a 3rd-degree equation. + \end{solution} + + \vfill + \pagebreak + + + % James + \problem{} + \note{Proposed by James} + + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Given a circle, its center, and a point $p$ on the circle, use origami to construct a tangent line to the circle that passes through $p$. + \item Given a circle, its center, and a point $p$ on the circle, use origami to construct an equilateral triangle inscribed in the circle that passes through $p$. + \item Given a triangle, use origami to construct the center of the circle inscribed in it and its tangent points. + \end{enumerate} + + \begin{solution} + \textbf{A:} Take the fold through the center of the circle and the point $p$, and take the perpendicular fold passing through $p$. + + \vspace{2mm} + + \textbf{B:} Fold $p$ to the center of the circle to produce two points on the circle, do the same for the two points. + The equilateral triangle doesn't pass through $p$. But by repeating the process for some of the vertices produced on + the circle, one can produce an equilateral triangle that passes through $p$. + + \vspace{2mm} + + \textbf{C:} Fold one side to another side to produce the three angle bisectors. + They intersect at a point, which is the incenter. Then use Axiom 4 for each of the three sides. + \end{solution} + + \vfill + + \problem{} + \note{Proposed by Nikita} + Use origami to find the other three notable points in the given triangle: circumcenter, centroid and orthocenter. + + \begin{solution} + Use Axiom 2 for pairs of vertices to get the circumcenter. + + The creases from the perpendicular bisectors leave marks at the centers of sides which we use (in Axiom 1) to + build the medians and the centroid. Use Axiom 4 for vertices and opposite sides to get the orthocenter. + \end{solution} + + \vfill + \pagebreak + + \problem{} + \note{Proposed by Nikita} + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Emulate Axiom 5 with a compass and straightedge. + \item In your emulation, probably, there is a choice of which of the two intersections of a + circle and a line to take. Does it mean that there are two ways to perform the fold? + \end{enumerate} + + \begin{solution} + There are two ways to do it: + + \begin{center} + \includegraphics[height=5cm]{O5Compass.png} + \end{center} + \end{solution} + + \vfill + + \problem{} + \note{Proposed by Nikita} + Prove that $\sqrt[3]{2} \ne \frac{a}{b}$ for any $a, b \in \mathbb{N}$. + + \begin{solution} + Suppose that $\sqrt[3]{2} = \frac{a}{b}$. Take the smallest such pair $(a, b)$. + Then $2b^3=a^3$. So $a$ is even. Let $a=2c$. Then $2b^3=8c^3 \implies b^3=4c^3$. + So $b$ is also even, which contradicts the minimality assumption. + \end{solution} + + \vfill + \pagebreak + + + \problem{} + \note{Proposed by Nikita} + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Construct a regular hexagon using a ruler and compass. + + \item Cut the triangle with angles $72^\circ$, $72^\circ$, $36^\circ$ into 2 isosceles triangles. + + \item Using triangle similarity, prove that the ratio of the sides in this triangle + is equal to the golden ratio $\varphi = \frac{1+\sqrt{5}}{2}$. + + \item Find a way to construct a regular pentagon using only a ruler and compass. + \end{enumerate} + + \begin{solution} + \textbf{A:} Obvious + + \vspace{2mm} + + \textbf{B:} \par + \begin{center} + \includegraphics[height=4cm]{72.png} + \end{center} + + \vspace{2mm} + + \textbf{C:} Let $|BC|=1$. Then $|AC|=x$, the ratio we seek. From equilateral triangles we get $|AD|=|BD|=|BC|=1$. + From similar triangles we get $|CD|=\frac{|CD|}{|BD|} = \frac{1}{x}$. + So $|AC|=|AD|+|DC|$ means $x=1+\frac{1}{x}$ or $x^2-x-1=0$. + Solving for $x$ we get $x=\frac{1 \pm \sqrt{5}}{2}$. We take the positive root. + + \vspace{2mm} + + \textbf{D:} Draw any segment $BC$ and call its length the unit length. + Then construct the right triangle with sides $1$ and $2$. This will give a segment of length $\sqrt{5}$. + Using it we construct a segment of length $\varphi = \frac{1+\sqrt{5}}{2}$ and can find the vertex $A$ of + a regular pentagon since it should be distance $\varphi$ apart from $B$ and $C$. It's easy to find two other vertices. + \end{solution} + + \vfill + \pagebreak + + \problem{} + \note{Proposed by Nikita} + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Use origami to divide a given segment into $3$ equal parts. + \item Use origami to divide a given segment into $n$ equal parts. + \end{enumerate} + + \begin{solution} + \textbf{A:} Build a square on this segment and then use the construction from the origami paper (or see the next part). + + \vspace{2mm} + + \textbf{B:} The same construction works inductively. + + \begin{center} + \includegraphics[height=3cm]{Segment_division.png} + \end{center} + + If in unit square $ABCD$ the length $|BE| = \frac{1}{n}$, then for $H = AE \cap BD$ the distance to + $BC$ is $\frac{1}{n+1}$, since $\triangle ADH \sim \triangle EBH$. + \end{solution} + + \vfill + + \problem{} + \note{Proposed by ?} + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item In the lecture, you saw that Axioms 1--5 are all able to be simulated by compass and straightedge constructions. + Is the following claim a correct \emph{deduction} from the above? (In other words, does simulating Axioms 1--5 \emph{prove} the claim?) + + Claim: \say{In all cases, origami constructions are at least as powerful as compass and straightedge constructions.} + + \item Is the claim true? Argue \emph{both} sides with yourself (or with a classmate). + + + \item (Hard) Prove the sense in which the claim is true. + (Hint: recall from the lecture that all constructible lengths with straightedge and compass are rational, + or of the form $a + b\sqrt{c}$ with $a, b, c$ rational, or of the form $d + e\sqrt{f}$ with $d, e, f$ of the form + $a + b \sqrt{c}$ with $a, b, c$ rational, etc.) + \end{enumerate} + + \begin{solution} + \textbf{A:} No, this argument leaves open the possibility that something can be constructed with a compass and straightedge, but cannot be with origami. + + \vspace{2mm} + + \textbf{B:} Argument for false: With a compass, one can draw circles, and origami can never draw curves that are not straight (in a finite number of steps.) + + Argument for true: Although the pictures look different, it is possible (and actually true) that the constructible + \emph{lengths} with straightedge and compass form a strict subset of lengths with origami. + + \vspace{2mm} + + \textbf{C:} It suffices to construct such numbers with origami, i.e. that rationals, square roots, addition, + and multiplication are all constructible. + + \vspace{2mm} + + These actually require a bit of critical thinking. See Lemma 4.3.3 (page 38/pdf 47) of + ORIGAMI-CONSTRUCTIBLE NUMBERS by HWA YOUNG LEE (\texttt{https://getd.libs.uga.edu/pdfs/lee\_hwa-young\_201712\_ma.pdf}) + for the details. + \end{solution} + + \vfill + \pagebreak + + + \problem{} + \note{Proposed by Mark} + Do each of the following with a compass and ruler. \par + Do not use folds. + + \begin{enumerate}[label = \textbf{\alph{enumi}:}] + \item Divide a circle into five parts of equal area. + \item Divide a circle into seven parts of equal area. + \item Divide a circle into $n$ parts of equal area. + \end{enumerate} + + \begin{solution} + \textbf{a:} Trivial \par + \textbf{b:} Hard, since we can't make a 7-gon using a compass and a ruler. Use \textbf{c}. \par + \textbf{c:} Draw a diameter $AB$. Split that diameter into $n$ equal segments. In the top half of the original circle, draw a half-circle from each point to $A$. In the bottom, do the same for B. + + + \begin{center} + \begin{tikzpicture}[scale = 0.5] + \draw (3.5, 0) circle (3.5cm); + \draw (0,0) -- (7, 0); + \filldraw (0, 0) circle (1mm); + + \foreach \i in {1,...,7} { + \filldraw (\i, 0) circle (1mm); + \draw (\i, 0) arc [ + start angle = 0, + end angle = 180, + radius = \i cm / 2 + ]; + \draw (7 - \i, 0) arc [ + start angle = -180, + end angle = 0, + radius = \i cm / 2 + ]; + } + \end{tikzpicture} + \end{center} + \end{solution} + + \vfill + \pagebreak + + + \problem{} + \note{Proposed by Sunny} + Using a compass and ruler, find two circles tangent to a point D and lines AB and AC. (Problem of Appolonius, PLL case) \par + \hint{ + All circles tangent to $AB$ and $AC$ are homothetic with centre at $A$. What does this mean? \\ + Also, the angle bisector may help. + } + + \begin{center} + \includegraphics[width=0.5\linewidth]{prob9.png} + \end{center} + + \begin{solution} + See diagram and instructions below. + \begin{enumerate} + \item Draw angle bisector $AE$ and line $AD$. + \item Draw circle tangent to $AB$ and $AC$ centered at $E$. + \item Draw $EG$ and $EH$ from $E$ to line $AD$. + \item Draw $DI$ and $DK$ parallel to $EH$ and $EG$ respectively (they are necessarily parallel by homothety). The desired circles are centered at $I$ and $K$. + \end{enumerate} + + \begin{center} + \includegraphics[height=6cm]{prob9s.png} + \end{center} + \end{solution} + + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Origami/meta.toml b/src/Advanced/Origami/meta.toml new file mode 100644 index 0000000..9de3074 --- /dev/null +++ b/src/Advanced/Origami/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Origami" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Pidgeonhole Problems/main.tex b/src/Advanced/Pidgeonhole Problems/main.tex new file mode 100755 index 0000000..a7069d1 --- /dev/null +++ b/src/Advanced/Pidgeonhole Problems/main.tex @@ -0,0 +1,407 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{tikz} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Pidgeonhole Problems} +\subtitle{Prepared by Mark on \today} + +\begin{document} + + \maketitle + + + \problem{} + Is it possible to cover an equilateral triangle with two smaller equilateral triangles? Why or why not? + + + \begin{solution} + In order to completely cover an equilateral triangle, the two smaller triangles must cover all three vertices. Since the longest length of an equilateral triangle is one of its sides, a smaller triangle cannot cover more than one vertex. Therefore, we cannot completely cover the triangle with two smaller copies. \par + + \textcolor{gray}{\textit{Bonus question:}} Can you cover a square with three smaller squares? + \end{solution} + + \vfill + + + + + \problem{} + You are given $n + 1$ distinct integers. \par + Prove that at least two of them have a difference divisible by $n$. + + \begin{solution} + $n~|~(a-b) \iff a \equiv b \pmod{n}$ \par + + Let $i_0 ... i_{n+1}$ be our set of integers. If we pick $i_0 ... i_{n+1}$ so that no two have a difference divisible by $n$, we must have $i_0 \not\equiv i_k \pmod{n}$ for all $1 \leq k \leq n+1$. There are $n$ such $i_k$, and there are $n$ equivalence classes mod $n$. \par + + Therefore, either, $i_1 ... i_{n+1}$ must cover all equivalence classes mod $n$ (implying that $i_0 \equiv i_k \pmod{n}$ for some k), or there exist two elements in $i_1 ... i_{n+1}$ that are equivalent mod $n$. \par + + In either case, we can find $a, b$ so that $a \equiv b \pmod{n}$, which implies that $n$ divides $a-b$. + \end{solution} + + \vfill + \pagebreak + + + + + \problem{} + You have an $8 \times 8$ chess board with two opposing corner squares cut off. You also have a set of dominoes, each of which is the size of two squares. Is it possible to completely cover the board with dominos, so that none overlap nor stick out? + + \begin{solution} + A domino covers two adjacent squares. Adjacent squares have different colors. \par + + If you remove two opposing corners of a chessboard, you remove two squares of the same color, and you're left with $32$ of one and $30$ of the other. \par + + Since each domino must cover two colors, you cannot cover the modified board. + \end{solution} + + \vfill + + + + \problem{} + The ocean covers more than a half of the Earth's surface. Prove that the ocean has at least one pair of antipodal points. + + \begin{solution} + Let $W$ be the set of wet points, and $W^c$ the set of points antipodal to those in $W$. $W$ and $W^c$ each contain more than half of the points on the earth. The set of dry points, $D$, contains less than half of the points on the earth. Therefore, $W^c \not\subseteq D$. \par + + \textcolor{gray}{\textit{Note:}} This solution isn't very convincing. However, it is unlikely that the students know enough to provide a fully rigorous proof. + \end{solution} + + \vfill + + + + \problem{} + There are $n > 1$ people at a party. Prove that among them there are at least two people who have the same number of acquaintances at the gathering. (We assume that if A knows B, then B also knows A) + + \begin{solution} + Assume that every attendee knows a different number of people. There is only one way this may happen: the most popular person knows $n-1$ people (that is, everyone but himself), the second-most popular knows $n-2$, etc. The least-popular person must then know $0$ people. \par + + This is impossible, since we know that someone must know $n-1$. \par + (Remember, ``knowing'' must be mutual.) + \end{solution} + + \vfill + \pagebreak + + + + \problem{} + Pick five points in $\mathbb{R}^2$ with integral coordinates. Show that two of these form a line segment that has an integral midpoint. + + \begin{solution} + Let $e, o$ represent even and odd integers. \par + There are four possible classes of points: $(e, e)$, $(o, o)$, $(e, o)$, $(o, e)$. \par + + $\text{midpoint}(a, b) = (\frac{a_x + b_x}{2}, \frac{a_y + b_y}{2})$. If $a_x + b_x$ and $a_y + b_y$ are both even, the midpoint of points $a$ and $b$ will have integer coordinates. \par + + Since we pick five points from four classes, at least two must come from the same class. \par + $e + e = e$ and $o + o = e$, so the midpoint between two points of the same class must have integral coordinates. \par + + \end{solution} + + \vfill + + + + + \problem{} + Every point on a line is painted black or white. Show that there exist three points of the same color where one is the midpoint of the line segment formed by the other two. + + \begin{solution} + This is a proof by contradiction. We will try to construct a set of points where three points have such an arrangement. \par + + We know that some two points on the line will have the same color: + + \begin{center} + \begin{tikzpicture} + % Axis + \draw[latex-latex] (-3,0) -- (4,0); + + % Ticks + \foreach \x in {-2,-1,0,1,2,3} + \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt); + + % Points + \path [draw=black, fill=black] (1,0) circle (2pt); + \path [draw=black, fill=black] (0,0) circle (2pt); + \end{tikzpicture} + \end{center} + + This implies that the points one unit left and right of them must also be white---if they are not, they will form a line of equidistant black points. + + \begin{center} + \begin{tikzpicture} + % Axis + \draw[latex-latex] (-3,0) -- (4,0); + + % Ticks + \foreach \x in {-2,-1,0,1,2,3} + \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt); + + % Points + \path [draw=black, fill=black] (1,0) circle (2pt); + \path [draw=black, fill=black] (0,0) circle (2pt); + \path [draw=black, fill=white] (2,0) circle (2pt); + \path [draw=black, fill=white] (-1,0) circle (2pt); + \end{tikzpicture} + \end{center} + + Our original assumption also implies that the center point is white. \par + This, however, creates a line of equidistant white points: + + \begin{center} + \begin{tikzpicture} + % Axis + \draw[latex-latex] (-3,0) -- (4,0); + + % Ticks + \foreach \x in {-2,-1,0,1,2,3} + \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt); + + % Points + \path [draw=black, fill=black] (1,0) circle (2pt); + \path [draw=black, fill=black] (0,0) circle (2pt); + \path [draw=black, fill=white] (0.5,0) circle (2pt); + \path [draw=black, fill=white] (2,0) circle (2pt); + \path [draw=black, fill=white] (-1,0) circle (2pt); + \end{tikzpicture} + \end{center} + + It is thus impossible to create a set of points that does not have the property stated in the problem. + \end{solution} + + + \vfill + + + + \problem{} + Every point on a plane is painted black or white. Show that there exist two points in the plane that have the same color and are located exactly one foot away from each other. + + \begin{solution} + Pick three points that form an equilateral triangle with side length 1. + \end{solution} + + \vfill + \pagebreak + + + + \problem{} + Let n be an integer not divisible by $2$ and $5$. Show that n has a multiple consisting entirely of ones. + + \begin{solution} + Let $a_1 = 1, a_2 = 11, a_3 = 111$, and so on. + + \vspace{2mm} + + Consider the sequence $a_1, ..., a_{n+1}$. \par + By \ref{divisibledifference}, there exist $a_i$ and $a_j$ in this list so that $a_i - a_j \equiv 0 \pmod{n}$. \par + + \vspace{2mm} + + Since $a_i$ and $a_j$ are both made of ones, $a_i - a_j = 11...111 \times 10^j$. \par + $n$ must be a factor of either $11...111$ or $10^j$. \par + Since $n$ isn't divisible by $2$ or $5$, $10^j$ cannot be divisible by $n$, so $11...111$ must be a factor of $n$. + \end{solution} + + + \vfill + + + + + \problem{} + Prove that for any $n > 1$, there exists an integer made of only sevens and zeros that is divisible by $n$. + + + \begin{solution} + If $n$ is not divisible by $2$ or $5$, the solution to this problem is the same as \ref{multipleofones}: \par + just multiply the number of all ones by $7$. + + \vspace{2mm} + + If $n$ is divisible by $2$ or $5$, set $p$ to the largest power of $2$ or $5$ in $n$. \par + Multiply the above number by $10^p$ to get a number that satisfies the conditions above. + \end{solution} + + + \vfill + + + + \problem{} + Choose $n + 1$ integers between $1$ and $2n$. Show that at least two of these are co-prime. + + \vfill + + + + \problem{} + Choose $n + 1$ integers between $1$ and $2n$. Show that you must select two numbers $a$ and $b$ such that $a$ divides $b$. + + \begin{solution} + Split the set $\{1, ..., 2n\}$ into classes defined by each integer's greatest odd divisor. There will be $n$ classes since there are $\frac{k}{2}$ odd numbers between $1$ and $n$. Because we pick $n + 1$ numbers, at least two will come from the same class---they will be divisible. \par + + For example, if $n = 5$, our classes are + \begin{itemize} + \item[1:] $\{1, 2, 4, 8\}$ + \item[3:] $\{3, 6\}$ + \item[5:] $\{5, 10\}$ + \item[7:] $\{7\}$ + \item[9:] $\{9\}$ + \end{itemize} + \end{solution} + + \vfill + \pagebreak + + + + \problem{} + Show that it is always possible to choose a subset of the set of integers $\{a_1, a_2, ... , a_n\}$ so that the sum of the numbers in the subset is divisible by $n$. + + \begin{solution} + Let $\{a_1^\prime, a_2^\prime, ..., a_n^\prime\}$ be this set mod $n$. \par + If any $a_i^\prime$ is zero, we're done: $\{a_i^\prime\}$ satisfies the problem. + + \vspace{2mm} + + If none are zero, consider the set $\{a_1^\prime,~ a_1^\prime + a_2^\prime,~ ...,~ a_1^\prime + a_2^\prime + ... + a_n^\prime\}$. \par + If any element of this set is zero, we're done. + + \vspace{2mm} + + If zero is not in this set, we have $n$ numbers with $n-1$ possible remainders. Therefore, at least two elements in this set must be equivalent mod $n$. If we subtract these two elements, we get a sum divisible by $n$. + \end{solution} + + \vfill + + + + + \problem{} + Show that there exists a positive integer divisible by $2013$ that has $2014$ as its last four digits. + + \begin{solution} + Let $n$ be this number. \par + First, note that $n - 2013$ has $0001$ as its last four digits. \par + + \vspace{2mm} + + So, we see that $n - 2013 = 2013k \equiv 1 \pmod{1000}$. \par + Of course, $k$ = $2013^{-1} \pmod{1000}$, which exists because 2013 and 1000 are coprime. \par + And finally, we see that $n = 2013 \times (k + 1)$. + \end{solution} + + \vfill + + + + + \problem{} + Let $n$ be an odd number. Let $a_1, a_2, ... , a_n$ be a permutation of the numbers $1, 2, ... , n$. \par + Show that $(a_1 - 1) \times (a_2 - 2) \times ... \times (a_n - n)$ is even. + + \begin{solution} + If $n$ is odd, there will be $m$ even and $m + 1$ odd numbers between $1$ and $n$. \par + Therefore, if we match each $a_n$ with an integer in $[1, ..., n]$, we will have to match at least one odd number with an odd number. \par + + The difference of two odd numbers is even, so the product above will have at least one factor of two. + \end{solution} + + \vfill + \pagebreak + + + + + \problem{} + A stressed-out student consumes at least one espresso every day of a particular year, drinking $500$ overall. Show the student drinks exactly $100$ espressos on some consecutive sequence of days. + + \begin{solution} + Rearrange the problem. Don't think about days, think about espressos. Consider the following picture: + + \begin{center} + \begin{tikzpicture} + % Axis + \draw[-] (1,0) -- (12,0); + + % Ticks + \foreach \x in {1, 2, 3, 4} + \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt); + + % Legend + \node[above] at (-0.5, 3pt) {Day consumed}; + \node[below] at (-0.5,-3pt) {Espresso \#}; + + % Bottom numbers + \foreach \x in {1, 2, ..., 7} + \draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt, -3pt) node[below] {$\x$}; + \draw[shift={(9,0)},color=black] (0pt,0pt) -- (0pt, -3pt) node[below] {$...$}; + \draw[shift={(11,0)},color=black] (0pt,0pt) -- (0pt, -3pt) node[below] {$499$}; + \draw[shift={(12,0)},color=black] (0pt,0pt) -- (0pt, -3pt) node[below] {$500$}; + + % Top numbers + \draw[shift={(1,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$1$}; + \draw[shift={(2,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$1$}; + \draw[shift={(3,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$2$}; + \draw[shift={(4,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$2$}; + \draw[shift={(5,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$3$}; + \draw[shift={(6,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$3$}; + \draw[shift={(7,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$3$}; + \draw[shift={(9,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$...$}; + \draw[shift={(11,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$365$}; + \draw[shift={(12,0)},color=black] (0pt,0pt) -- (0pt,3pt) node[above] {$365$}; + + \draw[shift={(3, -1)}, color=orange, thick] (0pt,0pt) -- (0pt,3pt) + node[below, color=gray, shift={(0, -3pt)}] {$3$}; + \draw[color=orange, thick] (3, -1) -- (8.5, -1) node[below, midway] {100 espressos}; + \draw[shift={(8.5, -1)}, color=orange, thick] (0pt,0pt) -- (0pt,3pt) + node[below, color=gray, shift={(0, -3pt)}] {$102$}; + \end{tikzpicture} + \end{center} + + If there exists a sequence of days where the student drinks exactly 100 espressos, we must have at least one ``block'' (in orange, above) of 100 espressos that both begins and ends on a ``clean break'' between days. \par + + There are $499$ ``breaks'' between $500$ espressos. \par + In a year, there are $364$ clean breaks. This leaves $499 - 364 = 135$ ``dirty'' breaks. \par + We therefore have $135$ places to start a block on a dirty break, and $135$ places to end a block on a dirty break. This gives us a maximum of $270$ dirty blocks. \par + + % spell:off + However, there are $401$ possible blocks, + since we can start one at the $1^{\text{st}},2^{\text{nd}}, ..., 401^{\text{st}}$ espresso. \par + % spell:on + + Out of $401$ blocks, a maximum of $270$ can be dirty. We are therefore guaranteed at least $131$ clean blocks. This completes the problem---each clean block represents a set of consecutive, whole days during which exactly 100 espressos were consumed. + + \end{solution} + + + \vfill + + + \problem{} + Show that there are either three mutual acquaintances or four mutual strangers at a party with ten or more people. + + \vfill + + + + \problem{} + Given a table with a marked point, $O$, and with $2013$ properly working watches put down on the table, prove that there exists a moment in time when the sum of the distances from $O$ to the watches' centers is less than the sum of the distances from $O$ to the tips of the watches' minute hands. + + \vfill +\end{document} diff --git a/src/Advanced/Pidgeonhole Problems/meta.toml b/src/Advanced/Pidgeonhole Problems/meta.toml new file mode 100644 index 0000000..c610312 --- /dev/null +++ b/src/Advanced/Pidgeonhole Problems/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Pidgeonhole Problems" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Random Walks/main.tex b/src/Advanced/Random Walks/main.tex new file mode 100755 index 0000000..1c03ca6 --- /dev/null +++ b/src/Advanced/Random Walks/main.tex @@ -0,0 +1,33 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\input{tikxset.tex} + +% For \nicefrac +\usepackage{units} +\usepackage{circuitikz} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Random Walks and Resistance} +\subtitle{ + Prepared by Mark on \today{} \\ + Based on a handout by Aaron Anderson +} + + +\begin{document} + + \maketitle + + \input{parts/0 random.tex} + \input{parts/1 circuits.tex} + \input{parts/2 equivalence.tex} + \input{parts/3 effective.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Random Walks/meta.toml b/src/Advanced/Random Walks/meta.toml new file mode 100644 index 0000000..2be363f --- /dev/null +++ b/src/Advanced/Random Walks/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Random Walks" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Random Walks/parts/0 random.tex b/src/Advanced/Random Walks/parts/0 random.tex new file mode 100644 index 0000000..10c2e70 --- /dev/null +++ b/src/Advanced/Random Walks/parts/0 random.tex @@ -0,0 +1,330 @@ +\section{Random Walks} + +Consider the graph below. A particle sits on some node $n$. Every second, this particle moves left or +right with equal probability. Once it reaches node $A$ or $B$, it stops. \par +We would like to compute the probability of our particle stopping at node $A$. \par + +\vspace{2mm} + +In other words, we want a function $P: \text{Nodes} \to [0, 1]$ that maps each node of the graph +to the probability that our particle stops at $A$. + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[accept] (a) at (0, 0) {$A$}; + \node[main] (x) at (2, 0) {$x$}; + \node[main] (y) at (4, 0) {$y$}; + \node[reject] (b) at (6, 0) {$B$}; + \end{scope} + + \draw[-] + (a) edge (x) + (x) edge (y) + (y) edge (b) + ; +\end{tikzpicture} +\end{center} + + + + +\problem{} +What are $P(A)$ and $P(B)$ in the graph above? \par +\note{Note that these values hold for all graphs.} + +\begin{solution} + $P(A) = 1$ and $P(B) = 0$ +\end{solution} + +\vfill + + + + +\problem{} +Find an expression for $P(x)$ in terms of $P(y)$ and $P(A)$. \par +Find an expression for $P(y)$ in terms of $P(x)$ and $P(B)$. \par + +\begin{solution} + $P(x) = \frac{P(A) + P(y)}{2}$ + + \vspace{2mm} + + $P(y) = \frac{P(B) + P(x)}{2}$ +\end{solution} + +\vfill + + + + +\problem{} +Use the previous problems to find $P(x)$ and $P(y)$. + +\begin{solution} + $P(x) = \nicefrac{2}{3}$ + + \vspace{2mm} + + $P(y) = \nicefrac{1}{3}$ +\end{solution} + +\vfill +\pagebreak + + + + +\problem{} +Say we have a graph $G$ and a particle on node $x$ with neighbors $v_1, v_2, ..., v_n$. \par +Assume that our particle is equally likely to travel to each neighbor. \par +Find $P(x)$ in terms of $P(v_1), P(v_2), ..., P(v_n)$. + +\begin{solution} + We have + $$ + P(x) = \frac{P(v_1) + P(v_2) + ... + P(v_n)}{n} + $$ +\end{solution} + +\vfill + + +\problem{} +In general, how do we find $P(n)$ for any node $n$? + +\begin{solution} + If we write an equation for each node other than $A$ and $B$, we have a system of $|N| - 2$ + linear equations in $|N| - 2$ variables. + + \vspace{2mm} + + We still need to show that this system is nonsingular, but + that's outside the scope of this handout. This could + be offered as a bonus problem. +\end{solution} + +\vfill +\pagebreak + + + + + +\problem{} +Find $P(n)$ for all nodes in the graph below. + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[accept] (a) at (0, 0) {$A$}; + \node[main] (x) at (2, 0) {$x$}; + \node[main] (y) at (0, -2) {$y$}; + \node[reject] (b) at (2, -2) {$B$}; + \end{scope} + + \draw[-] + (a) edge (x) + (x) edge (b) + (b) edge (y) + (y) edge (a) + ; +\end{tikzpicture} +\end{center} + +\begin{solution} + $P(x) = \nicefrac{1}{2}$ for both $x$ and $y$. +\end{solution} + +\vfill + + + + + +\problem{} +Find $P(n)$ for all nodes in the graph below. \par +\note{Note that this is the graph of a cube with $A$ and $B$ on opposing vertices.} + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[main] (q) at (0, 0) {$q$}; + \node[main] (r) at (2, 0) {$r$}; + \node[main] (s) at (0, -2) {$s$}; + \node[reject] (b) at (2, -2) {$B$}; + + \node[accept] (a) at (-1, 1) {$A$}; + \node[main] (z) at (3, 1) {$z$}; + \node[main] (x) at (-1, -3) {$x$}; + \node[main] (y) at (3, -3) {$y$}; + \end{scope} + + \draw[-] + (a) edge (z) + (z) edge (y) + (y) edge (x) + (x) edge (a) + + (q) edge (r) + (r) edge (b) + (b) edge (s) + (s) edge (q) + + (a) edge (q) + (z) edge (r) + (y) edge (b) + (x) edge (s) + ; +\end{tikzpicture} +\end{center} + + +\begin{solution} + $P(z,q, \text{ and } x) = \nicefrac{3}{5}$ \par + $P(s,r, \text{ and } y) = \nicefrac{2}{5}$ +\end{solution} + +\vfill +\pagebreak + + + + + + +\definition{} +Let us now take a look at weighted graphs. The problem remains the same: we want to compute the probability that +our particle stops at node $A$, but our graphs will now feature weighted edges. The probability of our particle +taking a certain edge is proportional to that edge's weight. + +\vspace{2mm} + +For example, if our particle is on node $y$ of the graph below, it has a $\frac{3}{8}$ probability of moving +to $x$ and a $\frac{1}{8}$ probability of moving to $z$. \par +\note{Note that $3 + 3 + 1 + 1 = 8$.} + + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[reject] (b) at (0, 0) {$B$}; + \node[main] (x) at (0, 2) {$x$}; + \node[main] (y) at (2, 0) {$y$}; + \node[main] (z) at (4, 0) {$z$}; + \node[accept] (a) at (3, -2) {$A$}; + \end{scope} + + \draw[-] + (a) edge node[label] {$3$} (y) + (y) edge node[label] {$1$} (z) + + (b) edge node[label] {$2$} (x) + (x) edge[bend left] node[label] {$3$} (y) + (a) edge[bend right] node[label] {$2$} (z) + (y) edge node[label] {$1$} (b) + ; +\end{tikzpicture} +\end{center} + + + + + +\problem{} +Say a particle on node $x$ has neighbors $v_1, v_2, ..., v_n$ with weights $w_1, w_2, ..., w_n$. \par +The edge $(x, v_1)$ has weight $w_1$. Find $P(x)$ in terms of $P(v_1), P(v_2), ..., P(v_n)$. + + +\begin{solution} + $$ + P(x) = \frac{w_1 P(v_1) + w_2 P(v_2) + ... + w_n P(v_n)}{w_1 + w_2 + ... + w_n} + $$ +\end{solution} + +\vfill +\pagebreak + + + + + + + +\problem{} +Consider the following graph. Find $P(x)$, $P(y)$, and $P(z)$. + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[reject] (b) at (3, 2) {$B$}; + \node[main] (x) at (0, 0) {$x$}; + \node[main] (y) at (2, 0) {$y$}; + \node[main] (z) at (1, 2) {$z$}; + \node[accept] (a) at (-2, 0) {$A$}; + \end{scope} + + \draw[-] + (x) edge node[label] {$1$} (y) + (y) edge node[label] {$1$} (z) + (x) edge[bend left] node[label] {$2$} (z) + (a) edge node[label] {$1$} (x) + (z) edge node[label] {$1$} (b) + ; +\end{tikzpicture} +\end{center} + +\begin{solution} + $P(x) = \nicefrac{7}{12}$ \par + $P(y) = \nicefrac{6}{12}$ \par + $P(z) = \nicefrac{5}{12}$ +\end{solution} + +\vfill + + + + + + + +\problem{} +Consider the following graph. \par +What expressions can you find for $P(w)$, $P(x)$, $P(y)$, and $P(z)$? + +\begin{center} +\begin{tikzpicture} + \begin{scope}[layer = nodes] + \node[accept] (a) at (0, 0) {$A$}; + \node[main] (w) at (2, 1) {$w$}; + \node[main] (x) at (4, 1) {$x$}; + \node[main] (y) at (2, -1) {$y$}; + \node[main] (z) at (4, -1) {$z$}; + \node[accept] (b) at (6, 0) {$B$}; + \end{scope} + + \draw[-] + (a) edge node[label] {$2$} (w) + (a) edge node[label] {$1$} (y) + (w) edge node[label] {$2$} (x) + (y) edge node[label] {$2$} (z) + (x) edge node[label] {$1$} (y) + (x) edge node[label] {$1$} (b) + (z) edge node[label] {$2$} (b) + ; +\end{tikzpicture} +\end{center} + +Solve this system of equations. \par +\hint{Use symmetry. $P(w) = 1 - P(z)$ and $P(x) = 1 - P(y)$. Why?} + +\begin{solution} + $P(w) = \nicefrac{3}{4}$ \par + $P(x) = \nicefrac{2}{4}$ \par + $P(y) = \nicefrac{2}{4}$ \par + $P(z) = \nicefrac{1}{4}$ +\end{solution} + +\vfill +\pagebreak diff --git a/src/Advanced/Random Walks/parts/1 circuits.tex b/src/Advanced/Random Walks/parts/1 circuits.tex new file mode 100644 index 0000000..9837e23 --- /dev/null +++ b/src/Advanced/Random Walks/parts/1 circuits.tex @@ -0,0 +1,162 @@ +\section{Circuits} + +An \textit{electrical circuit} is a graph with a few extra properties, +called \textit{current}, \textit{voltage}, and \textit{resistance}. \par +In the definitions below, let $X$ be the set of nodes in a circuit. + + +\begin{itemize}[itemsep=3mm] + \item \textbf{Voltage} is a function $V: X \to \mathbb{R}$ that assigns a number to each node of our graph. \par + In any circuit, we pick a \say{ground} node, and define the voltage\footnotemark{} there as 0. \par + We also select a \say{source} node, and define its voltage as 1. \par + + \vspace{1mm} + + Intuitively, you could say we're connecting the ends of a 1-volt battery to our source and ground nodes. + + \footnotetext{ + In the real world, voltage is always measured \textit{between two points} on a circuit. + Voltage is defined as the \textit{difference} in electrical charge between two points. + Hence, voltage is a function of two nodes. + + \vspace{2mm} + + Note that this is different than current and resistance, which aren't functions + of two arbitrary nodes --- rather, they are functions of \textit{edges} + (i.e, two adjacent nodes). + } + + + \item \textbf{Current} is a function $I: X^2 \to \mathbb{R}$ that assigns a number to each + \textit{oriented edge} in our graph. An \say{oriented edge} is just an ordered pair of nodes $(n_1, n_2)$. \par + + \vspace{1mm} + + Current through an edge $(a, b)$ is a measure of the flow of charge from $a$ to $b$. \par + Naturally, $I(a, b) = -I(b, a)$. + + + \item \textbf{Resistance} is a function $R: X^2 \to \mathbb{R}^+_0$ that represents a certain edge's + resistance to the flow of current through it. \par + Resistance is a property of each \textit{link} between nodes, so order doesn't matter: $R(a, b) = R(b, a)$. +\end{itemize} + +\vspace{2mm} + +It is often convenient to compare electrical circuits to systems of pipes. Say we have a pipe from point $A$ to point $B$. +The size of this pipe represents resistance (smaller pipe $\implies$ more resistance), the pressure between $A$ and $B$ +is voltage, and the speed water flows through it is to current. + + +\definition{Ohm's law} +With this \say{pipe} analogy in mind, you may expect that voltage, current, and resistance are related: +if we make our pipe bigger (and change no other parameters), we'd expect to see more current. This is indeed +the case! Any circuit obeys \textit{Ohm's law}, stated below: +$$ + V(a, b) = I(a,b) \times R(a,b) +$$ + +This handout uses two notations for voltage: two-variable $V(a, b)$ and one-variable $V(a)$. \par +The first represents the voltage between points $a$ and $b$, better reflecting reality (see the footnote below). +The second measures the voltage between $a$ and ground, and is more convenient to use in equations. +\textbf{Try to use the single-variable notation in your equations.} +Convince yourself that $V(a, b) = V(a) - V(b)$. + +\vfill + + +\definition{Kirchoff's law} +The second axiom of electrical circuits is also fairly simple. \textit{Kirchoff's law} states that the sum of all currents connected to +a given edge is zero. You can think of this as \say{conservation of mass}: nodes in our circuit do not create or +destroy electrons, they simply pass them around to other nodes.\par +Formally, we can state this as follows: + +\vspace{2mm} + +Let $x$ be a node in our circuit and $N_x$ the set of its neighbors. We than have +$$ + \sum_{b \in N_x} I(x, b) = 0 +$$ +which must hold at every node \textbf{except the source and ground vertices.} \par +\hint{Keep this exception in mind, it is used in a few problems later on.} + +\vfill +\pagebreak + + + +\begin{instructornote} + Be aware that some students may not be comfortable with these concepts from physics, + nor with the circuit notation on the next page. + + \vspace{2mm} + + It may be a good idea to give the class a quick lecture on this topic, + explaining the basics of electronic circuits and circuit diagrams. + + \vspace{2mm} + + Things to cover: + \begin{itemize} + \item All the definitions on the previous page, in detail. + \item What's an Ohm, an Amp, a Volt? + \item Measuring voltage. Why is $V(a, b) = V(a) - V(b)$? + \item What does the $\Omega$ in the picture below mean? + \item Circuit symbols in the diagram below. + \end{itemize} + + \vspace{2mm} + + You could also draw connections to the graph flow handout, + if the class covered it before. +\end{instructornote} + + +Consider the circuit below. \textbf{This the graph from \ref{firstgraph}}, turned into a circuit by: +\begin{itemize} + \item Replacing all edges with $1\Omega$ resistors + \item Attaching a 1 volt battery between $A$ and $B$ +\end{itemize} +\vspace{2mm} +Note that the battery between $A$ and $B$ isn't really an edge. +It exists only to create a potential difference between the two nodes. + +\begin{center} +\begin{circuitikz}[american voltages] + \draw + (0,0) node[above left] {$A$ (source)} + to[R, l=$1\Omega$, *-*] (2,0) node[above] {$x$} + to[R, l=$1\Omega$, *-*] (4,0) node[above] {$y$} + to[R, l=$1\Omega$, *-*] (6,0) node[above right] {$B$ (ground)} + to[short] (6, -1) node[below] {$-$} + to[battery,invert,l={1 Volt}] (0, -1) node[below] {$+$} + to[short] (0, 0) + ; +\end{circuitikz} +\end{center} + +\problem{} +From the circuit diagram above, we immediately know that $V(A) = 1$ and $V(B) = 0$. \par +What equations related to the currents out of $x$ and $y$ does Kirchoff's law give us? \par +\hint{Current into $x$ = current out of $x$} + +\vfill + + + + +\problem{} +Use Ohm's law to turn the equations from \ref{onecurrents} into equations about voltage and resistance. \par +Find an expression for $V(x)$ and $V(y)$ in terms of other voltages, then solve the resulting system of equations. +Does your result look familiar? + +\begin{solution} + \setlength{\abovedisplayskip}{0pt} % Fix spacing on top + \begin{flalign*} + V(x) &= \frac{V(A) - V(y)}{2} &&\\ + V(y) &= \frac{V(x) - V(B)}{2} && + \end{flalign*} +\end{solution} + +\vfill +\pagebreak diff --git a/src/Advanced/Random Walks/parts/2 equivalence.tex b/src/Advanced/Random Walks/parts/2 equivalence.tex new file mode 100644 index 0000000..9162825 --- /dev/null +++ b/src/Advanced/Random Walks/parts/2 equivalence.tex @@ -0,0 +1,122 @@ +\section{The Equivalence} +In the last problem, we found that the equations for $V(x)$ were the same as the equations for $P(x)$ on the same graph. +It turns out that this is true in general: problems about voltage in circuits directly correspond to problems about probability +in graphs. We'll spend the next section proving this fact. + +\definition{} +For the following problems, \textit{conductance} will be more convenient than resistance. \par +The definition of conductance is quite simple: +$$ + C(a, b) = \frac{1}{R(a,b)} +$$ +\note[Aside]{ + Resistance is usually measured in Ohms, denoted $\Omega$. \\ + A few good-natured physicists came up with the \say{mho} (denoted \reflectbox{\rotatebox[origin=c]{180}{$\Omega$}}) + as a unit of conductance, which is equivalent to an inverse Ohm. + Unfortunately, NIST discourages the use of Mhos in favor of the equivalent (and less amusing) \say{Siemens.} +} + + + + + +\problem{} +Let $x$ be a node in a graph. \par +Let $N_x$ be the set of $x$'s neighbors, $w(x, y)$ the weight of the edge between nodes $x$ and $y$, and $W_x$ +the sum of the weights of all edges connected to $x$. + +We saw earlier that the probability function $P$ satisfies the following sum: +$$ + P(x) = \sum_{b \in N_x} \biggl( P(b) \times \frac{w(x, b)}{W_x} \biggr) +$$ + +\note{This was never explicitly stated, but is noted in \ref{weightedgraph}.} + +\vspace{4mm} + +Use Ohm's and Kirchoff's laws to show that the voltage function $V$ satisfies a similar sum: +$$ + V(x) = \sum_{b \in N_x} \biggl( V(b) \times \frac{C(x, b)}{C_x} \biggr) +$$ +where $C(x, b)$ is the conductance of edge $(x, b)$ and $C_x$ is the sum of the conductances of all edges connected to $x$. + + +\begin{solution} + First, we know that + $$ + \sum_{b \in N_x} I(x, b) = 0 + $$ + for all nodes $x$. Now, substitute $I(x, b) = \frac{V(x) - V(b)}{R(x, y)}$ and pull out $V(x)$ terms to get + $$ + V(x) \sum_{b \in N_x} \frac{1}{R(x, b)} - \sum_{b \in N_x} \frac{V(b)}{R(x, b)} = 0 + $$ + + Rearranging and replacing $R(x, b)^{-1}$ with $C(x, b)$ and $\sum C(x, b)$ with $C_x$ gives us + $$ + V(x) = \sum_{b \in N_x} V(b) \frac{C(x, b)}{C_x} + $$ +\end{solution} + + +\vfill + +\pagebreak + +Thus, if $w(a, b) = C(a, b)$, $P$ and $V$ satisfy the same system of linear equations. To finish proving that +$P = V$, we now need to show that there can only be one solution to this system. We will do this in the next +two problems. + + + +\problem{} +Let $q$ be a solution to the following equations, where $x \neq a, b$. +$$ + q(x) = \sum_{b \in N_x} \biggl( q(b) \times \frac{w(x, b)}{W_x} \biggr) +$$ +Show that the maximum and minimum of $q$ are $q(a)$ and $q(b)$ (not necessarily in this order). + +\begin{solution} + The domain of $q$ is finite, so a maximum and minimum must exist. + + \vspace{2mm} + + Since $q(x)$ is a weighted average of all $q(b), ~b \in N_x$, there exist $y, z \in N_x$ satisfying + $q(y) \leq q(x) \leq q(z)$. Therefore, none of these can be an extreme point. + + \vspace{2mm} + + $A$ and $B$ are the only vertices for which this may not be true, so they must be the minimum and maximum. +\end{solution} + +\vfill + + + +\problem{} +Let $p$ and $q$ be functions that solve our linear system \par +and satisfy $p(A) = q(A) = 1$ and $p(B) = q(B) = 0$. \par + +\vspace{1mm} + +Show that the function $p - q$ satisfies the equations in \ref{generaleq}, \par +and that $p(x) - q(x) = 0$ for every $x$. \note{Note that $p(x) - q(x) = 0 ~ \forall x \implies p = q$} + +\begin{solution} + The equations in \ref{generaleq} for $p$ and $q$ directly imply that + $$ + [p - q](x) = \sum_{b \in N_x} \biggl( [p - q](b) \times \frac{w(x, b)}{W_x} \biggr) + $$ + Which are the equations from \ref{generaleq} for $(p - q)$. + + \vspace{2mm} + + Hence, the minimum and maximum values of $p - q$ are $[p - q](a) = 1 - 1 = 0$ + and $[p - q](b) = 1 - 1 = 0$. + + \vspace{2mm} + + Therefore $p(x) - q(x) = 0$ for all $x$, so $p(x) = q(x)$. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Random Walks/parts/3 effective.tex b/src/Advanced/Random Walks/parts/3 effective.tex new file mode 100644 index 0000000..614edb1 --- /dev/null +++ b/src/Advanced/Random Walks/parts/3 effective.tex @@ -0,0 +1,282 @@ +\section{Effective Resistance} + +As we have seen, calculating the properties of a circuit by creating an equation for each vertex is +a fairly time-consuming ordeal. Fortunately, there is a better strategy we can use. + +\vspace{2mm} + +Consider a graph (or a circuit) with source and ground vertices. All parts of the circuit that aren't these +two vertices are hidden inside a box, as shown below: + + +\begin{center} +\begin{circuitikz}[american voltages] + \draw + (0,0) node[above left] {$A$ (source)} + to[short, *-] (1,0) + (5, 0) to[short, -*] (6,0) node[above right] {$B$ (ground)} + to[short] (6, -2) node[below] {$-$} + to[battery,invert,l={1 Volt}] (0, -2) node[below] {$+$} + to[short] (0, 0) + ; + + \node[ + draw, + minimum width = 4cm, + minimum height = 2cm, + anchor = south west + ] at (1, -1) {Unknown circuit}; + +\end{circuitikz} +\end{center} + + +What do we know about this box? If this was a physical system, we'd expect that the current flowing +out of $A$ is equal to the current flowing into $B$. + + +\problem{} +Using Kirchoff's law, show that the following equality holds. \par +Remember that we assumed Kirchoff's law holds only at nodes other than $A$ and $B$. \par +\note[Note]{As before, $N_x$ is the set of neighbors of $x$.} +$$ + \sum_{b \in N_A} I(A, b) = \sum_{b \in N_B} I(b, B) +$$ + +\begin{solution} + Add Kirchoff's law for all vertices $x \neq A$ to get + $$ + \sum_{\forall x} \biggl( ~ \sum_{b \in N_x } I(x, b) \biggr) = 0 + $$ + This sum counts both $I(x, y)$ and $I(x, y)$ for all edges $x, y$, except $I(x, y)$ when $x$ is + $A$ or $B$. Since $I(a, b) + I(b, a) = 0$, these cancel out, leaving us with + $$ + \sum_{b \in N_A} I(A, b) + \sum_{b \in N_B} I(B, b) = 0 + $$ + + \vspace{2mm} + + Rearrange and use the fact that $I(a, b) = -I(b, a)$ to get the final equation. +\end{solution} + +\vfill + +If we call this current $I_A = \sum_{b \in N_A} I(A, b)$, we can pretend that the box contains only one resistor, +carrying $I_A$ units of current. Using this information and Ohm's law, we can calculate the +\textit{effective resistance} of the box. + +\pagebreak + + +\problem{Resistors in parallel} +Using Ohm's law and Kirchoff's law, calculate the effective resistance $R_\text{eff}$ of the circuit below. + +\begin{center} +\begin{circuitikz}[american voltages] + \draw + (0,0) node[above left] {$A$ (source)} + to[short, *-*] (1, 0) + + (1, 0) to[short] (2, 1) + to[R, l=$R_1$, o-o] (4, 1) + to[short] (5, 0) + + (1, 0) to[short] (2, -1) + to[R, l=$R_n$, o-o] (4, -1) + to[short] (5, 0) + + (1, 0) to[short, -o] (2, 0.5) + (2, 0.5) to (2.3, 0.5) + (4, 0.5) to (3.7, 0.5) + (4, 0.5) to[short, o-] (5, 0) + + (1, 0) to[short, -o] (2, -0.5) + (2, -0.5) to (2.3, -0.5) + (4, -0.5) to (3.7, -0.5) + (4, -0.5) to[short, o-] (5, 0) + + (1, 0) to[short] (1.7, 0) + (4.3, 0) to[short] (5, 0) + + (5, 0) to[short, *-*] (6, 0) node[above right] {$B$ (ground)} + to[short] (6, -2) node[below] {$-$} + to[battery,invert,l={1 Volt}] (0, -2) node[below] {$+$} + to[short] (0, 0) + ; + + \node at (3, 0) {$...$ a few more $...$}; +\end{circuitikz} +\end{center} + +\begin{solution} + Let $I_i$ be the current across resistor $R_i$, from left to right. \par + By Ohm's law, $I_i = \frac{V}{R_i}$ (Note that $V = 1$ in this problem). \par + + \vspace{2mm} + + The source current is then $I_A = \sum_{i=1}^n = \Bigl( V \Bigr) \Bigl( \frac{1}{R_1} + \frac{1}{R_2} + ... + \frac{1}{R_n} \Bigr)$. + Applying Ohm's law again, we find that + $$ + R_\text{eff} = \frac{1}{\frac{1}{R_1} + \frac{1}{R_2} + ... + \frac{1}{R_n}} + $$ +\end{solution} + +\vfill + + +\problem{Resistors in series} +Using Ohm's law and Kirchoff's law, calculate the effective resistance $R_{\text{total}}$ of the circuit below. + +\begin{center} +\begin{circuitikz}[american voltages] + \draw + (0,0) node[above left] {$A$ (source)} + to[R, l=$R_1$, *-*] (2,0) + to[short] (2.5, 0) + + + (5.5, 0) to[short] (6, 0) + to[R, l=$R_n$, *-*] (8,0) node[above right] {$B$ (ground)} + to[short] (8, -1) node[below] {$-$} + to[battery,invert,l={1 Volt}] (0, -1) node[below] {$+$} + to[short] (0, 0) + ; + + \node at (4, 0) {$...$ a few more $...$}; +\end{circuitikz} +\end{center} + +\begin{solution} + This solution uses the same notation as the solution for \ref{parallelresistors}. + + \vspace{2mm} + + By Kirchoff's law, all $I_i$ are equal in this circuit. Let's say $I = I_i$. \par + Let $V_i$ denote the voltage at the node to the left of $R_i$. \par + By Ohm's law, $V_i - V_{i+1} = IR_i$. + + \vspace{2mm} + + The sum of this over all $i$ telescopes, and we get $V(A) - V(B) = I(R_1 + R_2 + ... + R_n)$. \par + Dividing, we find that + $$ + R_\text{eff} = R_1 + R_2 + ... + R_n + $$ +\end{solution} + +\vfill +\pagebreak + +We can now use effective resistance to simplify complicated circuits. Whenever we see the above constructions +(resistors in parallel or in series) in a graph, we can replace them with a single resistor of appropriate value. + + +\problem{} +Consider the following circuits. Show that the triangle has the same effective resistance as the star if +\begin{itemize} + \item $x = R_1R_2 + R_1R_3 + R_2R_3$ + \item $S_1 = \nicefrac{x}R_3$ + \item $S_2 = \nicefrac{x}R_1$ + \item $S_3 = \nicefrac{x}R_2$ +\end{itemize} + +\vspace{2mm} + +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \textbf{The star:}\par + \begin{circuitikz}[american voltages] + \draw + (-1, 1.732) to[R, l=$R_1$, *-*] (0, 0) + (2, 0) to[R, l=$R_2$, *-*] (0, 0) + (-1, -1.732) to[R, l=$R_3$, *-*] (0, 0) + + (-1, 1.732) to[short, *-o] (-1.5, 1.732) + (-1, -1.732) to[short, *-o] (-1.5, -1.732) + (2, 0) to[short, *-o] (2.5, 0) + ; + + \node[above] at (-1, 1.732) {a}; + \node[above] at (2, 0) {b}; + \node[below] at (-1, -1.732) {c}; + \end{circuitikz} + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} + \begin{center} + \textbf{The triangle:}\par + \begin{circuitikz}[american voltages] + \draw + (-1, 1.732) + to[R, l=$S_1$, *-*] (2, 0) + to[R, l=$S_2$, *-*] (-1, -1.732) + to[R, l=$S_3$, *-*] (-1, 1.732) + + (-1, 1.732) to[short, *-o] (-1.5, 1.732) + (-1, -1.732) to[short, *-o] (-1.5, -1.732) + (2, 0) to[short, *-o] (2.5, 0) + ; + + \node[above] at (-1, 1.732) {a}; + \node[above] at (2, 0) {b}; + \node[below] at (-1, -1.732) {c}; + \end{circuitikz} + \end{center} +\end{minipage} +\hfill + + + +\vfill +\pagebreak + +\problem{} +Suppose we construct a circuit by connecting the $2^n$ vertices of an $n$-dimensional cube with $1\Omega$ resistors. +If we place $A$ and $B$ at opposing vertices, what is the effective resistance of this circuit? \par +\textbf{Bonus:} As $n \rightarrow \infty$, what happens to $R_\text{eff}$? \par +\note[Note]{Leave your answer as a sum.} + +\begin{solution} + Think of the vertices of the $n$-dimensional cube as $n$-bit binary strings, with $A$ at \texttt{000...0} + and $B$ at \texttt{111...1}. We can divide our cube into $n+1$ layers based on how many ones are in each + node's binary string, with the $k^\text{th}$ layer having $k$ ones. By symmetry, all the nodes in each layer + have the same voltage. This means we can think of the layers as connected in series, with the resistors + inside each layer connected in parallel. + + \vspace{2mm} + + There are $\binom{n}{k}$ nodes in the $k^\text{th}$ layer. Each node in this layer has $k$ ones, so + there are $n - k$ ways to flip a zero to get to the $(k + 1)^\text{th}$ layer. In total, there are + $\binom{n}{k}(n - k)$ parallel connections from the $k^\text{th}$ layer to the $(k + 1)^\text{th}$ + layer, creating an effective resistance of + $$ + \frac{1}{\binom{n}{k}(n - k)} + $$ + + The total effective resistance is therefore + $$ + \sum_{k = 0}^{n-1} \frac{1}{\binom{n}{k}(n - k)} + $$ + + \linehack{} + + To calculate the limit as $n \rightarrow \infty$, note that + $$ + \binom{n}{k}(n - k) = \frac{n!}{(n - k - 1)! \times k!} = n \binom{n-1}{k} + $$ + So, the sum is + $$ + \frac{1}{n} \sum_{k=0}^{n-1} \frac{1}{\binom{n - 1}{k}} + $$ + + \vspace{8mm} + + Note that for $n \geq 4$, $\binom{n}{k} \geq \binom{n}{2}$ for $2 \leq k \leq n-2$, so + $$ + \sum_{k = 0}^{n} \frac{1}{\binom{n}{k}} \leq 2 + \frac{2}{n} + \frac{n - 3}{\binom{n}{2}} + $$ + which approaches $2$ as $n \rightarrow \infty$. + So, $R_\text{eff} \rightarrow 0$ as $n \rightarrow \infty$. +\end{solution} \ No newline at end of file diff --git a/src/Advanced/Random Walks/tikxset.tex b/src/Advanced/Random Walks/tikxset.tex new file mode 100644 index 0000000..0b504d6 --- /dev/null +++ b/src/Advanced/Random Walks/tikxset.tex @@ -0,0 +1,88 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Arrowhead tweak + >={Latex[ width=2mm, length=2mm ]}, + % + % Labels inside edges + label/.style = { + rectangle, + % For automatic red background in solutions + fill = \ORMCbgcolor, + draw = none, + rounded corners = 0mm + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white, + line width = 0.35mm + }, + accept/.style = { + draw, + circle, + fill = white, + double, + double distance = 0.5mm, + line width = 0.35mm + }, + reject/.style = { + draw, + rectangle, + fill = white, + text = black, + double, + double distance = 0.5mm, + line width = 0.35mm + }, + start/.style = { + draw, + rectangle, + fill = white, + line width = 0.35mm + }, + % + % Loop tweaks + loop above/.style = { + min distance = 2mm, + looseness = 8, + out = 45, + in = 135 + }, + loop below/.style = { + min distance = 5mm, + looseness = 10, + out = 315, + in = 225 + }, + loop right/.style = { + min distance = 5mm, + looseness = 10, + out = 45, + in = 315 + }, + loop left/.style = { + min distance = 5mm, + looseness = 10, + out = 135, + in = 215 + } +} \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/chess-setup.tex b/src/Advanced/Retrograde Analysis/chess-setup.tex new file mode 100644 index 0000000..f2c0a25 --- /dev/null +++ b/src/Advanced/Retrograde Analysis/chess-setup.tex @@ -0,0 +1,36 @@ + +\setchessboard{ + showmover=false, + borderwidth=0.5mm, + label=false, + labelleft=true, + labelbottom=true, + normalboard, + hlabelformat=\arabic{ranklabel}, + vlabelformat=\Alph{filelabel} +} + +\long\def\twoboards#1{ + \chessboard[setpieces = {#1}] + \hfill + \chessboard[setpieces = {#1}] + \par +} + +\makeatletter +\long\def\manyboards#1{ + \if@solutions + \twoboards{#1} + \else + \twoboards{#1} + \twoboards{#1} + \fi +} + +\cbDefineNewPiece{white}{U} +{\raisebox{1.75mm}{\cfss@whitepiececolor +$\odot$}} +{\BlackEmptySquare% +\makebox[0pt][r]{\cfss@whitepiececolor +\raisebox{1.75mm}{\makebox[1em]{$\odot$}}}} +\makeatother \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/main.tex b/src/Advanced/Retrograde Analysis/main.tex new file mode 100755 index 0000000..e01ac25 --- /dev/null +++ b/src/Advanced/Retrograde Analysis/main.tex @@ -0,0 +1,44 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + shortwarning +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{chessfss} +\usepackage{chessboard} +\usepackage{anyfontsize} % Silences some chess warnings +\usepackage{afterpage} +\usepackage[hang]{footmisc} + +\input{chess-setup} + +\def\difficulty#1#2{ + \textbf{Difficulty:} \stars{#1}{#2} \par + \vspace{1mm} +} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Retrograde Analysis} +\subtitle{ + Prepared by Mark on \today{} \\ + Based on books\footnotemark{} by Raymond Smullyan +} + +\begin{document} + + \maketitle + + \footnotetext[1]{ + Most of the easy problems in this handout are from \textit{The Chess Mysteries of Sherlock Holmes}.\\ + The rest are from \textit{The Chess Mysteries of the Arabian Knights}. + } + + \input{parts/01 intro} + + \input{parts/02 easy} + \input{parts/03 medium} + \input{parts/04 hard} +\end{document} \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/meta.toml b/src/Advanced/Retrograde Analysis/meta.toml new file mode 100644 index 0000000..1c4ea7e --- /dev/null +++ b/src/Advanced/Retrograde Analysis/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Retrograde Analysis" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Retrograde Analysis/parts/01 intro.tex b/src/Advanced/Retrograde Analysis/parts/01 intro.tex new file mode 100644 index 0000000..78cd5d6 --- /dev/null +++ b/src/Advanced/Retrograde Analysis/parts/01 intro.tex @@ -0,0 +1,141 @@ +\section{Introduction} + +To solve the problems in this handout, you mustn't be a chess master---you just need to know how the pieces move. +I'd expect that you're all familiar with the basic rules of chess (ask questions if you aren't!). +The odd ones are listed below. + +\generic{Board orientation:} +The bottom-left square of a chessboard is \textit{always} black. + +\generic{Starting pawns \& en passant:} +A pawn may move two squares on its first turn. \par +An opposing pawn may capture this pawn as it completes this move. \par +This is called an \textit{en passant} capture (Which means \say{in passing} in French) + +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=b4, + setpieces = { + pa4,pb3, + Pa1,Pb1 + }, + addpgf={ + \tikz[overlay] + \draw[ocyan,line width=0.1em,->] + (a1)--(a3); + }, + ] + + White moves two squares + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=b4, + setpieces = { + pa4,pb3, + Pa3,Pb1 + }, + addpgf={ + \tikz[overlay] + \draw[ocyan,line width=0.1em,->] + (b3)--(a2); + }, + ] + + Black captures en passant + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=b4, + setpieces = { + pa4,pa2, + Pb1 + }, + ] + + Result + \end{center} +\end{minipage} + +\vfill + +\generic{Promotion:} +When a pawn reaches the last row of the board, it may be promoted to any other piece.\par +(Except a king or a pawn, of course.) + +\generic{Castling:} +A king and rook can \textit{castle} under the following conditions: +\begin{itemize} + \item No pieces are in the way + \item The king has not yet moved + \item The rook has not yet moved + \item The king is not in check + \item The king does not move through check while castling +\end{itemize} + +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=h2, + setpieces = { + Ra1,Ke1,Rh1 + }, + addpgf={ + \tikz[overlay] + \draw[ocyan,line width=0.1em,->] + (e1)--(g1); + \tikz[overlay] + \draw[ocyan,line width=0.1em,->] + (e1)--(c1); + }, + hmarginwidth=0mm + ] + + Possible castle directions + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=h2, + setpieces = { + Rd1,Kc1,Rh1 + }, + hmarginwidth=0mm + ] + + Queenside castle result + \end{center} +\end{minipage} +\hfill +\begin{minipage}{0.3\textwidth} + \begin{center} + \chessboard[ + smallboard, + maxfield=h2, + setpieces = { + Ra1,Kg1,Rf1 + }, + hmarginwidth=0mm, + ] + + Kingside castle result + \end{center} +\end{minipage} +\par + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/parts/02 easy.tex b/src/Advanced/Retrograde Analysis/parts/02 easy.tex new file mode 100644 index 0000000..c51140e --- /dev/null +++ b/src/Advanced/Retrograde Analysis/parts/02 easy.tex @@ -0,0 +1,375 @@ +\section{Simple problems} + + +% Sherlock, A little exercise +\problem{A little exercise} +\difficulty{1}{5} + +Black has just moved in the game below. White started on the south side of the board.\par +What was Black's last move, and what was White's last move? \par +\note[Note]{ + The boards below are identical copies. Scribble to your heart's content.\\ + There a few empty boards at the end of this handout as well. +} + +% spell:off +\manyboards{ + ka8,Kc8, + Ph2, + Bg1 +} +% spell:on + +\begin{solution} + It's pretty clear that Black just moved out of check from A7. + + \vspace{2mm} + + How did White deliver this check? The bishop couldn't have moved to G1, + so this check must have been discovered by another piece. Since there are + no extra pieces on the board, Black must've captured this piece on his last move. + + \vspace{2mm} + + The only piece that could have moved from the white bishop's diagonal to + then be captured on A8 is a knight. + + \vspace{2mm} + + \textbf{Note:} + There are two possible answers if we don't know who started where. + If Black had started on the south side of the board, that bishop could be a promoted pawn. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + +% Sherlock, Which color? +\problem{Which color?} +\difficulty{2}{5} + +In the game below, no pieces have moved from a black square to a white square, or from a white square to a black square. +There is a pawn at G3. What color is it? \par +As before, White started on the bottom of the board. + +% spell:off +\manyboards{ + ke8, + Kb4, + Ug3, + Pd2,Pf2 +} +% spell:on + +\begin{solution} + The white king is the key to this solution. How did it get off of E1? \par + It must have castled kingside---castling queenside would move a rook from black to white. + + \vspace{2mm} + + Now, the white king is on G1. How did it get out of there? \par + It's must have moved through H2 and G3, which would be impossible if the mystery pawn on G3 was white. + Therefore, that pawn must be black. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + +% Arabian Knights 2 +\problem{Invisible, but not invincible} +\difficulty{2}{5} + +The black king has turned himself invisible. Unfortunately, his position is hopeless. \par +Mate the king in one move. \par + +% spell:off +\manyboards{ + Ra8,rb8,Kf8, + Nb7,Pc7, + Pa6,Rc6 +} +% spell:on + +\begin{solution} + Since it is White's move, Black cannot be in check. \par + So, either White is in check or the black king is on C8. \par + If White is in check, Black must have administered this check by moving from C8 to D7. \par + Therefore, the black king must be on C8 or D7. + + \vspace{2mm} + + If we capture the black rook on B8 with the pawn on C7 and promote it to a knight, the black king will be in checkmate + regardless of his position. +\end{solution} + +\vfill +\pagebreak + + + + + + +% Sherlock, a question of survival +\problem{An empty board} +\difficulty{2}{5} + +In the game below, no pieces have moved from a black square to a white square, or from a white square to a black square. +There is one more piece on the board, which isn't shown. What color square does it stand on? \par + +% spell:off +\manyboards{ + ke8, + Pd2,Pf2, + Ke1 +} +% spell:on + +\begin{solution} + + Which piece performed the last capture on a black square? It couldn't have been a white pawn, which haven't moved. + It couldn't have been the white king, which is trapped; or the black king, which is restricted to white squares. + + \vspace{2mm} + + It must have been the piece we can't see, which therefore stands on a black square. + +\end{solution} + +\vfill +\pagebreak + + +% Sherlock, another monochromatic +\problem{The knight's grave} +\difficulty{3}{5} + +In the game below, no pieces have moved from a black square to a white square, or from a white square to a black square. +The white king has made less than fourteen moves. \par +Use this information to show that a pawn was promoted. \par + +% spell:off +\manyboards{ + ke8, + Pb2,Pd2, + Ke1 +} +% spell:on + +\begin{solution} + Knights always move to a different colored square, so all four missing knights must have been captured on their home square. + What pieces captured them? + + \vspace{2mm} + + We can easily account for the white knights and the black knight on G8, but who could've captured the knight from B8? + The only white pieces that can move to black squares are pawns, the Bishop (which is trapped on C1), the rook (which is stuck on column A and row 1), or the king (which would need at least 14 moves to do so). + + \vspace{2mm} + + If this knight was captured by a pawn, that pawn would be immediately promoted. If it was captured by a piece that wasn't a pawn, that piece must be a promoted pawn. +\end{solution} + +\vfill +\pagebreak + + + + + + +% Arabian Knights, intro (given with solution) +\problem{Promotion?} +\difficulty{2}{5} + + +It is White's move. Have there been any promotions this game? \par + +% spell:off +\manyboards{ + Pb2,Pe2,kf2,Pg2,Ph2, + Bc1,Kd1,Rh1 +} +% spell:on + +\begin{solution} + + Since it is White's move, Black has just moved his king. Where did he move it from? + Not E1, E3, F3, or G3, since that implies Black had moved into check before. \par + + \vspace{2mm} + + The only remaining possibilities are F1 and G1. \par + G1 is again impossible: how would the king get there without moving into check? \par + F1, therefore, is the only choice. If we place the king on F1, we see that another piece must prevent check from the white rook. + This must have been a white black-square bishop, which moved to F2 to reveal that check, and was then captured by the black king. + + \vspace{2mm} + + However, there is already a white black-square bishop on the board! We can get a second only by promoting a pawn, so the answer is \say{yes.} + +\end{solution} + +\vfill +\pagebreak + + + +% Sherlock Holmes, two bagatelles (1) +\problem{Whodunit} +\difficulty{2}{5} + +It is Black's move. Can Black castle? \par +\hint{Remember the rules of chess: you may not castle if you've moved your rook.} + +% spell:off +\manyboards{ + ra8,bc8,ke8,rh8, + pa7,pc7,pe7,pg7, + pb6,pf6,ph6, + Pa3, + Pb2,Pc2,Pd2,Pe2,Pf2,Pg2,Ph2, + Bc1,Qd1,Ke1,Bf1 +} +% spell:on + +\begin{solution} + White's last move was with the pawn. \par + Black's last move must have been to capture the white piece which moved before that. + + \vspace{2mm} + + This piece would have to have been a knight, since the white rooks could not have got out onto the board. + It is clear that none of the black pawns captured this knight. + The black rook on A8 couldn't have captured it either, because there is no square that + the knight could have moved from to get to that position. + + \vspace{2mm} + + The black bishop couldn't have captured the knight either, since the only square the + knight could have come from is D6, where it would have been checking the king. + + \vspace{2mm} + + So, the black king or the rook on H8 made this capture. Therefore, Black can't castle. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + +% Sherlock Holmes, two bagatelles (2) +\problem{Castle contradiction} +\difficulty{2}{5} + +Neither Black nor White captured a piece on their last move. \par +It is Black's move. Can he castle? \par +\hint{What was White's last move? Check the cases.} + +\manyboards{ + ke8,rh8, + pc4, + Pf3, + Pc2,Pf2,Pg2, + bd1,Rf1,Kg1 +} + + +\begin{solution} + If White's last move was with the king, then the black rook moved to check him and Black can't castle. + + \vspace{2mm} + + If White's last move wasn't with the king, White must have castled. \par + What was Black's last move? \par + If it was with the king or rook, Black can't castle. + + \vspace{2mm} + + It could not have been with the bishop, since then White would have had no move immediately before that. + Now, suppose Black moved his pawn. Then White's preceding move must have been with the pawn from E2, + capturing a piece on F3. This means that the bishop on D1 is a promoted bishop. The promoting pawn must + have come from D7, passed D2, checked the white king, making it move! + This contradicts our assumption that White has just castled. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + +% Arabian Knights, intro (given with solution) +\problem{A matter of order} +\difficulty{3}{5} + +A black bishop captured a White piece earlier in this game. \par +Which bishop was it, and what did it capture? \par +\hint{Black and White start with 16 pieces each.} + +\manyboards{ + ra8,qd8,ke8, + pa7,pc7,pd7,pf7,ph7, + pb6,nc6,pe6,nf6,ph6, + Bb5,be5, + Pe4,bg4, + Pc3,Nf3, + Pa2,Pb2,Pc2,Qe2,Pf2,Pg2,Ph2, + Kc1,Rd1,Rh1 +} + +\begin{solution} + First, notice that the pawn on C3 came from D2 by capturing a piece. \par + This must have been a black rook, which is the only missing black piece. + + \vspace{2mm} + + This black rook couldn't have moved there before the black pawn on G7 captured a white piece on H6. + This piece couldn't have been the missing white bishop, because that bishop would still be trapped by the pawn on D2. + Therefore, the missing white knight was captured on H6. + + \vspace{2mm} + + The only other missing white piece is the black-square bishop, which must have been captured by the black bishop on E5. + +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/parts/03 medium.tex b/src/Advanced/Retrograde Analysis/parts/03 medium.tex new file mode 100644 index 0000000..7ba70d8 --- /dev/null +++ b/src/Advanced/Retrograde Analysis/parts/03 medium.tex @@ -0,0 +1,273 @@ +\section{Slightly harder problems} + + +% Sherlock, A matter of direction +\problem{A matter of direction} +\difficulty{3}{5} + +The results of a game of chess are shown below. \par +Did White start on the north or south side of the board? \par + +% spell:off +\manyboards{ + ka8,Kc8, + Qe7, + Bc5,Pe5, + Pd4, + Ph3, + Bh1 +} +% spell:on + +\begin{solution} + Let us first find White's last move. It wasn't with the pawns on D4 and E5, since Black wouldn't have a move before that. + (Note the double-check on A7). + + \vspace{2mm} + + How, then, did White put Black in check? There are no pieces that could've uncovered this check, and the bishop on H1 couldn't + have moved from anywhere. We thus see that that bishop must be a promoted pawn, proving that White started on the north side of the board. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + + + + +% Arabian Knights 1 +\problem{Where is the king?} +\difficulty{3}{5} + + +The white king has again become invisible. Find him. \par +\hint{White started on the bottom. En passant.} \par + +% spell:off +\manyboards{ + rb5,bd5, + Ba4, + kd1 +} +% spell:on + + +\begin{solution} + Looking at the board, we see that the white king is on B3 or Black is in check. + + \vspace{2mm} + + First, we show that the latter implies the former: assume the black king is not on B3. \par + How did White deliver this check? + Not by moving the bishop, so this check must have been discovered by the white king moving from B3. + Therefore, if the white king isn't on B3 now, he was there on the previous move. + + \vspace{4mm} + + How did the white king end up on B3? That seems to be an impossible double-check from both the rook and bishop! + Looking at the hint, we place a black pawn on B4 to block check from the rook, and a white pawn on C2 that this black pawn will capture. + The sequence of moves is now as follows: + + \begin{minipage}{0.5\linewidth} + \begin{center} + % spell:off + \chessboard[ + setpieces = { + rb5, + Ba4,pb4,be4, + Kb3, + Pc2, + kd1 + } + ] + % spell:on + \end{center} + \end{minipage} + \hfill + \begin{minipage}{0.48\linewidth} + Black: E4 $\to$ D5 \par + White: C2 $\to$ C4 \par + Black: B4 $\to$ C3 (en passant capture) \par + White: B3 $\to$ C3 \par + So, the white king must be on C3. + \end{minipage} + +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + + +% Arabian Knights, intro (given with solution) +\problem{Double-checks} +\difficulty{3}{5} + + +White to move. Which side of the board did each color start on? \par +\hint{What was Black's last move? } + +% spell:off +\manyboards{ + Re3, + Nc2,Rd2, + Nd1,kf1,Kh1 +} +% spell:on + +\begin{solution} + Black's last move was from F2, where his king was in double-check from both a rook and a knight. + How did this happen? + + \vspace{2mm} + + White started on the north side of the board, and put Black in check by capturing a piece on D1 with + a pawn and then promoting that pawn to a knight. + + \begin{center} + \chessboard[ + smallboard, + setpieces = { + Re3, + Nc2,Rd2,Pe2, + bd1,kf2,Kh1 + } + ] + \end{center} + +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + + + + +% Arabian Knights 4 +\problem{A missing piece} +\difficulty{4}{5} + + +There is a piece at G4, marked with a $\odot$. \par +What is it, and what is its color? \par + +% spell:off +\manyboards{ + ra8,ke8,rh8, + pc7,pd7, + pb6, + pa5, + Ug4, + Pb3,Pg3,Ph3, + ba2,Pb2,Pc2,Pd2,Pf2,qg2,bh2, + Kc1,Rd1,nf1,Bh1 +} +% spell:on + + +\makeatletter +\if@solutions + \vfill + \pagebreak +\fi +\makeatother + + +\begin{solution} + \textbf{Part 1:} + + The black bishop on A2 cannot be original, since the white pawn on B3 would have prevented it from getting there. + That bishop is a promoted bishop. \par + + The black pawn it was promoted from must have come from E7, + captured four pieces to get to A3, then moved to A2, and then made a capture on B1, where it was promoted. \par + + Thus, the pawn from E7 has made five captures. + + \vspace{2mm} + + The white bishop from from C1 never left its home square + (since neither of the pawns on B2 or D2 have moved), and hence was captured on C1. This makes six captures of + white pieces, which tells us that the mystery piece is black. + + + \vspace{2mm} + + \textbf{Part 2:} + + White's last move could not have been with the rook from E1, which would have checked Black, + nor with the king (which could only come from B1, an impossible check), + nor could it have been with any piece other than the rook or king. + Therefore, White just castled, and thus the white king never moved before that. + + + \vspace{2mm} + + \textbf{Part 3:} + + Among the white pieces captured by the black pawn from E7 was the white rook from H1. Since White has just castled, + and the white king never moved before that, how did the rook from H1 get onto the board to be captured? + + The only possible explanation is that the pawns on G3 and H3 cross-captured to let out the rook: + the pawn on G3 really came from H2 and vice-versa. Since the pawn on G3 comes from H2, the black bishop + on H2 has always been confined to G1 and H2. How did the bishop get there? It must have been promoted. + + + \vspace{2mm} + + \textbf{Part 4:} + + The promoted black bishop on H2 must have been promoted on G1. The pawn which was promoted must have come from G7, + since neither of the pawns from F6 or H6 could make a capture to get to the G-file (all six missing white pieces have been accouted for). + The Pawn from E7 has promoted to the bishop on A2. + + What happened was this: the white pawn from G2 made its capture on H3 while the pawn on G3 was still on H2. This allowed the black pawn + to come down and be promoted (after the white rook from H1 got out), and then the pawn on H2 made its capture on G3. + + + \vspace{2mm} + + \textbf{Conclusion:} + + We already know the mystery piece is black. It can't be a pawn, because we've accounted for all missing black pawns. + It can't be a queen or a rook, since there couldn't have been any more promotions by Black. It is therefore a bishop or a knight. + However, White has just castled and moved his king over D1, so the mystery piece cannot be a bishop (the king may not cross through + check while castling). Therefore, the mystery piece must be \textbf{a black knight}. + +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Retrograde Analysis/parts/04 hard.tex b/src/Advanced/Retrograde Analysis/parts/04 hard.tex new file mode 100644 index 0000000..4ca8eb1 --- /dev/null +++ b/src/Advanced/Retrograde Analysis/parts/04 hard.tex @@ -0,0 +1,147 @@ +\section{Very difficult problems} + +% Arabian Knights 5 +\problem{The hidden castle} +\difficulty{7}{7} + +There is a white castle hidden on this board. Where is it? \par +None of the royalty has moved or been under attack. \par + +% spell:off +\manyboards{ + nb8,qd8,ke8,ng8,rh8, + pa7,pb7,pc7,pf7,pg7, + pe6,pf6,ph6, + Pa4,Bc4,Pe4, + Pc3, + Pb2,Pd2,Pf2,Pg2, + Qd1,Ke1 +} +% spell:on + +\begin{solution} + See \say{The Hidden Castle} in \textit{The Chess Mysteries of the Arabian Knights}. +\end{solution} + +\vfill +\pagebreak + + + +% Arabian Knights 6 +\problem{Who moved last?} +\difficulty{7}{7} + +After many moves of chess, the board looks as follows. \par +Who moved last? \par + +% spell:off +\manyboards{ + ka8,Kc8,bf8,rh8, + pb7,pc7,pf7,pg7, + Ba6, + Pe4, + Pa2,Pb2,Pd2,Pg2,Ph2, + Ra1,Nb1,Bc1,Qd1,Rh1 +} +% spell:on + +\begin{solution} + See \say{A Vital Decision} in \textit{The Chess Mysteries of the Arabian Knights}. +\end{solution} + +\vfill +\pagebreak + + + + +% Arabian Knights 3 +\problem{The king in disguise} +\difficulty{7}{7} + +The white king is exploring his kingdom under a disguise. He could look like any piece of any color.\par +Show that he must be on C7. + +% spell:off +\manyboards{ + qa8,nb8,be8,Qg8,kh8, + pa7,Pb7,pc7,Nd7,pe7,Pf7,ph7, + pa6,Pc6,Pg6, + ra5,pb5,Rd5,Ph5, + Pa4,Nc4,Pe4,Bg4 +} +% spell:on + +\begin{solution} + Black is in check, so we know that it is Black's move and White is not in check.\par + Assume the white king is not on C7. Where else could he hide? + First, we exclude the black pawns on A6, A7, and B5, since the white king would be in check in any of those positions. \par + + \vspace{2mm} + + The pawn on A6 came from B7 by capturing one piece, and the pawn on B5 came from D7 by capturing two. + (Note that this may not be true if we don't assume the pawn on C7 is real.) + We've counted three captures, all on white squares, so the white black-square bishop must have been captured separately. + + \vspace{2mm} + + Thus, at least four white pieces have been captured. White has 12 pieces on the board, + so the white king must be disguised as a white piece if he isn't on C7. + If we Exclude a few more pieces in check, we now see that the white king must + be on D5, E4, G4, or H5 if he isn't on C7. + + \linehack{} + + The white queen has to have moved from F8 to capture a piece on G8 to put Black in check. What was Black's move before this? + It couldn't have been the king from G7, since the white queen wouldn't have been able to enter F8. + It couldn't have been any other piece on the board, since they are all trapped. + So, Black's last move must have been with the mystery piece on G8. + + \vspace{2mm} + + Where did it come from? This piece can't be a bishop (how would it get in?), so it must be a queen, rook, or knight. + If it is a queen or rook, it must have come from G7, which is impossible---the white queen wouldn't be able to get in. + The mystery piece must therefore be a knight. It couldn't have come from H6 (again, the queen couldn't have gotten in to deliver a check), + so it must have come from F6. + + \linehack{} + + We now know that the white king is not on D5, E4, G4, or H5, since all those were in check when the black knight was on F6. + However, the white king must be on one of those four squares if he isn't on C7. This is a contradiction --- therefore the king must be hiding on C7. + +\end{solution} + +\vfill +\pagebreak + + + +% Arabian Knights 3 +\problem{The king in disguise once more} +\difficulty{5}{7} + +The white king is again exploring his kingdom, now under a different disguise. Where is he? \par +\hint{\say{different disguise} implies that the white king looks like a different piece!} + +% spell:off +\manyboards{ + nb8,be8,Qg8,kh8, + pa7,Pb7,pc7,Nd7,pe7,Pf7,ph7, + pa6,Pc6,Pg6, + ra5,pb5,Rd5,Ph5, + Pa4,Nc4,Pe4,Bg4 +} +% spell:on + +\begin{solution} + Use the same arguments as before, but now assume that the king isn't a black pawn. + + \vspace{2mm} + + Again, the king is disguised as a white piece, and must be on D5, E4, G4, H5, or B7. \par + For the same reasons as above, he can't be on D5, E4, G4, or H5, so he must be on B7. +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/main.tex b/src/Advanced/Size of Sets/main.tex new file mode 100755 index 0000000..777c212 --- /dev/null +++ b/src/Advanced/Size of Sets/main.tex @@ -0,0 +1,56 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + + + +\uptitlel{Advanced 1} +\uptitler{\smallurl{}} +\title{The Size of Sets} +\subtitle{Prepared by Mark on \today{}} + +\begin{document} + + \maketitle + + \input{parts/0 sets.tex} + \input{parts/1 really big.tex} + \input{parts/2 cartesian.tex} + \input{parts/3 functions.tex} + \input{parts/4 enumeration.tex} + %\input{parts/5 dense.tex} + \input{parts/6 uncountable.tex} + + + %\vfill + %\pagebreak + + %\section{Bonus Problems} + + %\problem{} + %Using only sets, how can we build an ordered pair $(a, b)$? \par + %$(a, b)$ should be equal to $(c, d)$ if and only if $a = b$ and $c = d$. \par + %Of course, $(a, b) \neq (b, a)$. + + %\begin{solution} + % $(a, b) = \{ \{a\}, \{a, b\}\}$ + %\end{solution} + + %\problem{} + %Suppose $f: A \to B$ and $g: B \to C$ are both one-to-one. Must $h(x) = g(f(x))$ be one-to-one? \par + %Provide a proof or a counterexample. + + %\vfill + + %\problem{} + %Suppose $f: A \to B$ and $g: B \to C$ are both onto. Must $h(x) = g(f(x))$ be onto? \par + %Provide a proof or a counterexample. + + %\vfill + %\pagebreak + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Size of Sets/meta.toml b/src/Advanced/Size of Sets/meta.toml new file mode 100644 index 0000000..8ff1deb --- /dev/null +++ b/src/Advanced/Size of Sets/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "The Size of Sets" + +[publish] +handout = true +solutions = false diff --git a/src/Advanced/Size of Sets/parts/0 sets.tex b/src/Advanced/Size of Sets/parts/0 sets.tex new file mode 100644 index 0000000..308fc46 --- /dev/null +++ b/src/Advanced/Size of Sets/parts/0 sets.tex @@ -0,0 +1,113 @@ +\section{Set Basics} + +\definition{} +A \textit{set} is a collection of objects. \par +If $a$ is an element of set $S$, we write $a \in S$. This is pronounced \say{$a$ in $S$.} \par +The position of each element in a set or the number of times it is repeated doesn't matter. \par +All that matters is \textit{which} elements are in the set. + +\vspace{2mm} + +We say two sets $A$ and $B$ are equal if every element of $A$ is in $B$, and every element of $B$ is in $A$. This is known as the \textit{principle of extensionality.} + +\problem{} +Convince yourself that $\{a, b\} = \{b, a\} = \{a, b, a, b, b\}$. + +\definition{} +A set $A$ is a \textit{subset} of a set $B$ if every element of $A$ is in $B$. \par +For example, $\{a, b\}$ is a subset of $\{a, b, c\}$. This is written $\{a, b\} \subseteq \{a, b, c\}$. \par +Note that the \say{subset} symbol resembles the \say{less than or equal to} symbol. + +\vspace{2mm} + +We can also write $\{a, b\} \subset \{a, b, c\}$, which denotes a \textit{strict subset.} \par +The relationship between $\subseteq$ and $\subset$ is the same as the relationship between $\leq$ and $<$. \par +In particular, if $A \subset B$, $A \subseteq B$ and $A \neq B$ \par +For example, $\{a, b, c\} \subseteq \{a, b, c\}$ is true, but $\{a, b, c\} \subset \{a, b, c\}$ is false. + + +\definition{} +The \textit{empty set}, usually written $\varnothing$, is the unique set containing no elements. \par +By definition, the empty set is a subset of every set. \par +\note[Note]{The $\varnothing$ symbol is called \say{varnothing.} If you'd like to know why, ask an instructor.} + +\problem{} +Which of the following are true? +\begin{itemize} + \item $\{1, 3\} = \{3, 3, 1\}$ + \item $\{1, 2\} \subset \{2\}$ + \item $\{1, 2\} \subset \{1, 2\}$ + \item $\{1, 2\} \subseteq \{1, 2\}$ + \item $\{2\} \subseteq \{1, 2\}$ + \item $\varnothing \subseteq \{1, 2\}$ +\end{itemize} + +\vfill +\pagebreak + +\problem{} +Let $A$ and $B$ be sets. Convince yourself that $A \subseteq B$ and $B \subseteq A$ implies $A = B$. + +\vspace{2mm} + +\hint{Whenever you start a proof, you should first look at definitions. \\ +As stated on the previous page, $A = B$ if every element in $A$ is in $B$ and every element of $B$ is in $A$.} + +\vspace{2mm} + +As we saw before, the $\subseteq$ relation behaves a lot like the $\leq$ relation. \par +The statement above is very similar to the statement \say{$x \leq y$ and $y \geq x$ implies $x = y$}. + + +\definition{} +Let $A$ be a set. The \textit{power set} of $A$, written $\mathcal{P}(A)$, is the set of all subsets of $A$. + +\problem{} +What is the power set of $\{1, 2, 3\}$? \par +\hint{It has eight elements.} + +\vfill + +\problem{} +Let $A$ be a set with $n$ elements. \par +How many elements does $\mathcal{P}(A)$ have? \par +\hint{Binary may help.} +\vfill + +\problem{} +Show that the set of all sets that do not contain themselves is not a set. \par + + +\vfill +\pagebreak + + +\definition{Set Operations} +$A \cap B$ is the \textit{intersection} of $A$ and $B$. \par +It is the set of objects that are in both $A$ and $B$. + +\vspace{3mm} + +$A \cup B$ is the \textit{union} of $A$ and $B$. \par +It is the set of objects that are in either $A$ or $B$. + +\vspace{3mm} + +$A - B$ is the \textit{difference} of $A$ and $B$. \par +It is the set of objects that are in $A$ but are not in $B$. + +\problem{} +What is $\{a, b, c\} \cap \{b, c, d\}$? + +\vfill + +\problem{} +What is $\{a, b, c\} \cup \{b, c, d\}$? + +\vfill + +\problem{} +What is $\{a, b, c\} - \{b, c, d\}$? + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/1 really big.tex b/src/Advanced/Size of Sets/parts/1 really big.tex new file mode 100644 index 0000000..ddc74b9 --- /dev/null +++ b/src/Advanced/Size of Sets/parts/1 really big.tex @@ -0,0 +1,65 @@ +\section{Really Big Sets} + +\definition{} +%We say a set $S$ is \textit{finite} if there exists a bijection from $S$ to $\{1, 2, 3, ..., n\}$ for some integer $n$. \par +%In other words +We say set is \textit{finite} if its elements can be consecutively numbered from 1 to some maximum index $n$. \par +Informally, we could say that a set is finite if it \say{ends.} \par +For example, the set $\{\star, \diamond, \heartsuit\}$ is (obviously) finite. We can number its elements 1, 2, and 3. + +\vspace{2mm} + +If a set is not finite, we say it is \textit{infinite}. + +\vspace{2mm} + + + +\problem{} +Which of the following sets are finite? +\begin{itemize} + \item $\{\texttt{A}, \texttt{B}, ..., \texttt{Z}\}$ + \item $\{ \text{all rats in Europe} \}$ + \item $\{ \text{all positive numbers} \}$ + \item $\{ \mathbb{ \text{all rational numbers} } \}$ +\end{itemize} + + +\vfill + +\generic{Remark:} +Note that our definition of \say{infinite-ness} is based on a property of the set. Saying \say{a set is infinite} is much like saying \say{a cat is black} or \say{a number is even}. There are many different kinds of black cats, and there are many different even numbers --- some large, some small. \par + +\vspace{2mm} + +In general, \textbf{$\infty$ is not a well-defined mathematical object\footnotemark{}}. Infinity is not a number. There isn't a single \say{infinity.} Infinity is the the general concept of endlessness, used in many different contexts. + +\vspace{2mm} + +%The Russian language (as well as many others, no doubt) captures this well: \say{infinity} in Russian is \say{бес-конеч-ность}, which can be literally translated as \say{without-end-ness}. + + +\footnotetext{ + In most cases. There are exceptions, but you need not worry about them for now. If you're curious, you may ask an instructor to explain. There's also a chance we'll see a well-defined \say{infinity} in a handout later this quarter. +} + + +\vfill +\pagebreak + +%Say we have two finite sets $A$ and $B$. Comparing the sizes of these is fairly easy: all we need to do is count the elements %in each. It is not difficult to see that $\{1, 2, 3\}$ is bigger than $\{1, 2\}$. +% +%\vspace{2mm} +% +%We could extend this notion of \say{size} to infinite sets. \par +%For example, consider $\mathbb{R}$ and $\mathbb{Z}$. Intuitively, we'd expect $\mathbb{R}$ to be larger, \par +%since there are many elements in $\mathbb{R}$ between every two elements in $\mathbb{Z}$. +% +%\vspace{1mm} +% +%We could also try to compare the sizes of $\mathbb{Q}$ and $\mathbb{Z}$. There are bIntuitively, we'd expect $\mathbb{R}$ to %be larger, \par +%since there are many elements in $\mathbb{R}$ between every two elements in $\mathbb{Z}$. +% +% +%\vfill +%\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/2 cartesian.tex b/src/Advanced/Size of Sets/parts/2 cartesian.tex new file mode 100644 index 0000000..422ed03 --- /dev/null +++ b/src/Advanced/Size of Sets/parts/2 cartesian.tex @@ -0,0 +1,172 @@ +\section{Common Sets and Cartesian Products} + +\definition{} +There are a few sets we use often. They have special names: +\begin{itemize} + \item $\mathbb{N} = \{0, 1, 2, 3, ...\}$ is the set of \textit{natural numbers}. + \item $\mathbb{Z} = \{..., -2, -1, 0, 1, 2, ...\}$ is the set of \textit{integers}. + \item $\mathbb{Q}$ is the set of \textit{rational numbers}. + \item $\mathbb{R}$ is the set of \textit{real numbers}. +\end{itemize} +\note[Note]{$\mathbb{Z}$ is called \say{blackboard zee} or \say{big zee.} Naturally, $\mathbb{N}$, $\mathbb{Q}$, and $\mathbb{R}$ have similar names. \\ This, of course, depends on context. Sometimes \say{zee} is all you need.} + + +\problem{} +Which of the following sets contain 100? \par +\hint{There may be more than one answer in all the problems below.} + +\begin{tcolorbox}[ + colback=white, + colframe=black, + width=0.5\textwidth, + toprule=0.3mm, + bottomrule=0.3mm, + leftrule=0.3mm, + rightrule=0.3mm, +] + \hfill $\mathbb{N}$ \hfill $\mathbb{Z}$ \hfill $\mathbb{Q}$ \hfill $\mathbb{R}$ \hfill\null +\end{tcolorbox} +\vfill + + +\problem{} +Which of the following sets contain {\large $\frac{1}{2}$}? \par + +\begin{tcolorbox}[ + colback=white, + colframe=black, + width=0.5\textwidth, + toprule=0.3mm, + bottomrule=0.3mm, + leftrule=0.3mm, + rightrule=0.3mm, +] + \hfill $\mathbb{N}$ \hfill $\mathbb{Z}$ \hfill $\mathbb{Q}$ \hfill $\mathbb{R}$ \hfill\null +\end{tcolorbox} +\vfill + + + +\problem{} +Which of the following sets contain $\pi$? \par + +\begin{tcolorbox}[ + colback=white, + colframe=black, + width=0.5\textwidth, + toprule=0.3mm, + bottomrule=0.3mm, + leftrule=0.3mm, + rightrule=0.3mm, +] + \hfill $\mathbb{N}$ \hfill $\mathbb{Z}$ \hfill $\mathbb{Q}$ \hfill $\mathbb{R}$ \hfill\null +\end{tcolorbox} +\vfill + + +\problem{} +Which of the following sets contain $\sqrt{-1}$? \par + +\begin{tcolorbox}[ + colback=white, + colframe=black, + width=0.5\textwidth, + toprule=0.3mm, + bottomrule=0.3mm, + leftrule=0.3mm, + rightrule=0.3mm, +] + \hfill $\mathbb{N}$ \hfill $\mathbb{Z}$ \hfill $\mathbb{Q}$ \hfill $\mathbb{R}$ \hfill\null +\end{tcolorbox} + +\vfill +\pagebreak + + +\definition{} +Consider the sets $A$ and $B$. The set $A \times B$ consists of all ordered\footnotemark{} pairs $(a, b)$ where $a \in A$ and $b \in B$. \par +This is called the \textit{cartesian product}, and is usually pronounced \say{$A$ cross $B$}. + +\footnotetext{This means that order matters. $(a, b) \neq (b, a)$.} + +\vspace{2mm} + + +For example, $\{1, 2, 3\} \times \{\heartsuit, \star\} = \{(1,\heartsuit),~ (1, \star),~ (2,\heartsuit),~ (2, \star),~ (3,\heartsuit),~ (3, \star)\}$ \par + + +You can think of this as placing the two sets \say{perpendicular} to one another: + +\begin{center} +\begin{tikzpicture}[ + scale=1, + bullet/.style={circle,inner sep=1.5pt,fill} +] + \draw[->] (-0.2,0) -- (4,0) node[right]{$A$}; + \draw[->] (0,-0.2) -- (0,3) node[above]{$B$}; + + \draw (1,0.1) -- ++ (0,-0.2) node[below]{$1$}; + \draw (2,0.1) -- ++ (0,-0.2) node[below]{$2$}; + \draw (3,0.1) -- ++ (0,-0.2) node[below]{$3$}; + + \draw (0.1, 1) -- ++ (-0.2, 0) node[left]{$\heartsuit$}; + \draw (0.1, 2) -- ++ (-0.2, 0) node[left]{$\star$}; + + \node[bullet] at (1, 1){}; + \node[bullet] at (2, 1) {}; + \node[bullet] at (3, 1) {}; + \node[bullet] at (1, 2) {}; + \node[bullet] at (2, 2) {}; + \node[bullet] at (3, 2) {}; + + + \draw[rounded corners] (0.5, 0.5) rectangle (3.5, 2.5) {}; + \node[above] at (2, 2.5) {$A \times B$}; + +\end{tikzpicture} +\end{center} + +\problem{} +Let $A = \{0, 1\} \times \{0, 1\}$ \par +Let $B = \{ a, b\}$ \par +What is $A \times B$? + +\vfill + +\problem{} +What is $\mathbb{R} \times \mathbb{R}$? \par +\hint{Use the \say{perpendicular} analogy} + +\vfill +\pagebreak + +\definition{} +$\mathbb{R}^n$ is the set of $n$-tuples of real numbers. \par +In English, this means that an element of $\mathbb{R}^n$ is a list of $n$ real numbers: \par + +\vspace{4mm} + +Elements of $\mathbb{R}^2$ look like $(a, b)$, where $a, b \in \mathbb{R}$. \hfill \note{\textit{Note:} $\mathbb{R}^2$ is pronounced \say{arrgh-two.}} +Elements of $\mathbb{R}^5$ look like $(a_1, a_2, a_3, a_4, a_5)$, where $a_n \in \mathbb{R}$. \par + +$\mathbb{R}^1$ and $\mathbb{R}$ are identical. + +\vspace{4mm} + +Intuitively, $\mathbb{R}^2$ forms a two-dimensional plane, and $\mathbb{R}^3$ forms a three-dimensional space. \par +$\mathbb{R}^n$ is hard to visualize when $n \geq 4$, but you are welcome to try. + +\problem{} +Convince yourself that $\mathbb{R} \times \mathbb{R}$ is $\mathbb{R}^2$. \par +What is $\mathbb{R}^2 \times \mathbb{R}$? +\vfill + +\problem{} +What is $\mathbb{N}^2$? +\vfill + +\problem{} +What is $\mathbb{Z}^3$? + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/3 functions.tex b/src/Advanced/Size of Sets/parts/3 functions.tex new file mode 100644 index 0000000..f8c4fb6 --- /dev/null +++ b/src/Advanced/Size of Sets/parts/3 functions.tex @@ -0,0 +1,375 @@ +\section{Functions and Maps} + +\definition{} +A \textit{function} or \textit{map} $f$ from a set $A$ to a set $B$ is a rule that assigns an element of $B$ to each element of $A$. We write this as $f: A \to B$. + +\vspace{1mm} + +Let $L = \{\texttt{a}, \texttt{b}, \texttt{c}, \texttt{d}, ..., \texttt{z}\}$ be the set of lowercase english letters. \par +Let $C = \{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}, ..., \texttt{Z}\}$ be the set of uppercase english letters. \par + +\vspace{1mm} + +Say we have a function $g: L \to C$ that capitalizes english letters. \par +We can think of this function as a \textit{map} from $A$ to $B$, shown below using arrows: + + +\begin{center} + \begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5); + \node at (0, 0) {\texttt{a}}; + \node at (0, -1) {\texttt{b}}; + \node at (0, -2) {\texttt{c}}; + \node at (0, -3) {\texttt{d}}; + \node at (0, -4) {\texttt{...}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -2); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -3); + \node[fill=white, text=gray] at (2, 0) {$g$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5); + \node at (4, 0) {\texttt{A}}; + \node at (4, -1) {\texttt{B}}; + \node at (4, -2) {\texttt{C}}; + \node at (4, -3) {\texttt{D}}; + \node at (4, -4) {\texttt{...}}; + \end{tikzpicture} +\end{center} + + +\definition{} +We say a map $f$ is \textit{one-to-one} if $a = b$ implies $f(a) = f(b)$ for all $a, b \in A$. \par +In other words, this means that no two elements of $A$ are mapped to the same $b$: + +\null\hfill +\begin{minipage}{0.48\textwidth} +\begin{center} +\textbf{A one-to-one function:} \par +\vspace{2mm} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3) {\texttt{d}}; + \node at (4, -4) {\texttt{e}}; +\end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} +\begin{center} +\textbf{NOT a one-to-one function:} \par +\vspace{2mm} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.4, -1.8); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -2.2); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3) {\texttt{d}}; + \node at (4, -4) {\texttt{e}}; + + \draw[line width = 0.4mm, ->] (5.5, -2) -- (4.5, -2); + \node[anchor=west] at (5.5, -2) {!!!}; + +\end{tikzpicture} +\end{center} +\end{minipage} +\hfill\null + +\vfill + + +\definition{} +We say a map $f$ is \textit{onto} if for every $b \in B$, there is an $a \in A$ so that $b = f(a)$. \par +In other words, this means that every element of $B$ has some element of $A$ mapped to it: + +\null\hfill +\begin{minipage}{0.48\textwidth} +\begin{center} +\textbf{An onto function:} \par +\vspace{2mm} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + \node at (0, -4) {\texttt{5}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3.1) {\texttt{d}}; +\end{tikzpicture} +\end{center} +\end{minipage} +\hfill +\begin{minipage}{0.48\textwidth} +\begin{center} +\textbf{NOT an onto function:} \par +\vspace{2mm} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + \node at (0, -4) {\texttt{5}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, -0.8); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1.2); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4); + \node[fill=white, text=gray] at (2, -0.4) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3.1) {\texttt{d}}; + + \draw[line width = 0.4mm, ->] (5.5, 0) -- (4.5, 0); + \node[anchor=west] at (5.5, 0) {!!!}; +\end{tikzpicture} +\end{center} +\end{minipage} +\hfill\null + +\vfill +\pagebreak + +\generic{Remark:} +The words \say{function} and \say{map} are two views of the same mathematical object. We usually think of functions as \say{machines} that take an input, change it, and produce an output. We think of maps as \say{rules} that match each element of a set $A$ to an element of a set $B$. + +\vspace{2mm} + +Again, functions and maps are \textit{identical}. They do the same thing. The only difference between \say{functions} and \say{maps} is how we think about them. + +% one-to-one = injective +% onto = surjective + +\problem{} +Is the \say{capitalize} function in \ref{deffun} one-to-one? Is it onto? + +\vfill + +\problem{} +Consider the function $f: \mathbb{Z} \to \mathbb{Z}$ defined by $f(x) = x^2$. \par +Is this function one-to-one? Is it onto? + +\vfill + +\problem{} +Consider the function $f: \mathbb{Z} \to \mathbb{Z}$ defined below. \par +Is this function one-to-one? Is it onto? + +\[ + f(x) = \begin{cases} + 0 & \text{if } x = 0 \\ + x + 1 & \text{otherwise} + \end{cases} +\] + + +% TODO: +% bijections, same size if exists bijection + +\vfill +\pagebreak + +\definition{Invertible Functions} +A function $g$ is an \textit{inverse} of a function $f$ if $g(f(x)) = x$ for any $x$. \par +In other words, the function $g$ \say{undoes} $f$. Usually, the inverse of a function $f$ is written $f^{-1}$. \par +We say a function is \textit{invertible} if it has an inverse. + +\vspace{2mm} + +Intuitively, we could say that the inverse of $f$ reverses the \say{arrows} of $f$. + +\problem{} +Is the following function invertible? \par +Draw the inverse, or explain why you can't. + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {$A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {$B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3) {\texttt{d}}; +\end{tikzpicture} +\end{center} + +\vfill + +\problem{} +Is the following function invertible? \par +Draw the inverse, or explain why you can't. + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3) {\texttt{d}}; + \node at (4, -4) {\texttt{e}}; +\end{tikzpicture} +\end{center} + +\vfill + + +\problem{} +Is the following function invertible? \par +Draw the inverse, or explain why you can't. + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node[anchor=south] at (0, 1) {Set $A$}; + \draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5); + \node at (0, 0) {\texttt{1}}; + \node at (0, -1) {\texttt{2}}; + \node at (0, -2) {\texttt{3}}; + \node at (0, -3) {\texttt{4}}; + \node at (0, -4) {\texttt{5}}; + + \draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0); + \draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2); + \draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1); + \draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3); + \draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4); + \node[fill=white, text=gray] at (2, 0) {$f$}; + + \node[anchor=south] at (4, 1) {Set $B$}; + \draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4); + \node at (4, 0) {\texttt{a}}; + \node at (4, -1) {\texttt{b}}; + \node at (4, -2) {\texttt{c}}; + \node at (4, -3.1) {\texttt{d}}; +\end{tikzpicture} +\end{center} + +\vfill +\pagebreak + + +\definition{Bijections} +One-to-one maps are also called \textit{injective} maps. \par +Onto maps are also called \textit{surjective} maps. + +\vspace{2mm} + +If a function is both one-to-one and onto, we say it is a \textit{bijection}. + +\vspace{4mm} + +\theorem{} +All bijective functions are invertible. All invertible functions are bijections. \par +You should review the problems on the previous page and convince yourself that this is true. + +\problem{} +We say a set $S$ is \textit{finite} if there exists a bijection from $S$ to $\{1, 2, 3, ..., n\}$ for some integer $n$.\par +Convince yourself that this definition of \say{finite-ness} is the same as the one in \ref{infiniteset}. + +\problem{} +Is there a bijection between the sets $\{1, 2, 3\}$ and $\{\texttt{A}, \texttt{B}, \texttt{C}\}$? \par +If a bijection exists, find one; if one doesn't, prove it. \par +\vfill + +\problem{} +Is there a bijection between the sets $\{1, 2, 3, 4\}$ and $\{\texttt{A}, \texttt{B}, \texttt{C}\}$? \par +If a bijection exists, find one; if one doesn't, prove it. \par +\vfill + + +\problem{} +Let $A$ and $B$ be two sets of different sizes. \par +Show that no bijection between $A$ and $B$ exists. +\vfill + + +\ref{samesize} reveals a very important fact: if we can find a bijection between two sets $A$ and $B$, these sets must have the same number of elements. Similarly, if we know that a bijection doesn't exist, we know that $A$ and $B$ must have a different number of elements. + +\vspace{2mm} + +Intuitively, you can think of a bijection as a \say{matching} between elements of $A$ and $B$. If we were to draw a bijection, we'd see an arrow connecting every element in $A$ to every element in $B$. If a bijection exists, every element of $A$ directly corresponds to an element of $B$, therefore $A$ and $B$ must have the same number of elements. + +\definition{} +We say two sets $A$ and $B$ are \textit{equinumerous} if there exists a bijection $f: A \to B$. + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/4 enumeration.tex b/src/Advanced/Size of Sets/parts/4 enumeration.tex new file mode 100644 index 0000000..f675126 --- /dev/null +++ b/src/Advanced/Size of Sets/parts/4 enumeration.tex @@ -0,0 +1,51 @@ +\section{Enumerations} + +\definition{} +Let $A$ be a set. An \textit{enumeration} is a bijection from $A$ to $\{1, 2, ..., n\}$ or $\mathbb{N}$.\par +An enumeration assigns an element of $\mathbb{N}$ to each element of $A$. + +\definition{} +We say a set is \textit{countable} if it has an enumeration.\par +We consider the empty set trivially countable. + + +\problem{} +Find an enumeration of $\{\texttt{A}, \texttt{B}, ..., \texttt{Z}\}$. +\vfill + +\problem{} +Find an enumeration of $\mathbb{N}$. +\vfill + +\problem{} +Find an enumeration of the set of squares $\{1, 4, 9, 16, ...\}$. + +\problem{} +Let $A$ and $B$ be equinumerous sets. \par +Show that $A$ is countable iff $B$ is countable. + +\vfill +\pagebreak + +\problem{} +Show that $\mathbb{Z}$ is countable. +\vfill + +\problem{} +Show that $\mathbb{N}^2$ is countable. +\vfill + +\problem{} +Show that $\mathbb{Q}$ is countable. +\vfill + +\problem{} +Show that $\mathbb{N}^k$ is countable. +\vfill + +\problem{} +Show that if $A$ and $B$ are countable, $A \cup B$ is also countable.\par +\note{Note that this automatically solves \ref{naturaltwo} and \ref{naturalk}.} +\vfill + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/5 dense.tex b/src/Advanced/Size of Sets/parts/5 dense.tex new file mode 100644 index 0000000..44f33bc --- /dev/null +++ b/src/Advanced/Size of Sets/parts/5 dense.tex @@ -0,0 +1,35 @@ +\section{Dense Orderings} + +\definition{} +An \textit{ordered set} is a set with an \say{order} attached to it. \par +A few examples are below: +\begin{itemize} + \item $\mathbb{Z}$ is an ordered set under $<$. + \item $\{\texttt{A}, \texttt{B}, ..., \texttt{Z}\}$ is an ordered set under $\diamond$,\par + Where $\alpha \diamond \beta$ holds iff the letter $\alpha$ comes before letter $\beta$ in the alphabet. +\end{itemize} + + +\definition{} +We say an ordered set $A$ is \textit{dense} if for any $a, b \in A$ there is a $c \in A$ so that $a < c < b$.\par +Intuitively, this means that there is an element of $A$ between any two elements of $A$. + +\problem{} +Show that the ordered set $(\mathbb{Q}, <)$ is dense.\par +\hint{Elements of $\mathbb{Q}$ are defined as fractions $\frac{p}{q}$, where $p$ and $q$ are integers.} +\vfill + +\problem{} +Show that the ordered set $(\mathbb{R}, <)$ is dense.\par +\hint{We can define a \say{real number} as a decimal, finite or infinite.} +\vfill + +\problem{} +Show that there is a real number between every two rationals. +\vfill + +\problem{} +Show that there is a rational number between every two reals. +\vfill + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Size of Sets/parts/6 uncountable.tex b/src/Advanced/Size of Sets/parts/6 uncountable.tex new file mode 100644 index 0000000..17ff9ec --- /dev/null +++ b/src/Advanced/Size of Sets/parts/6 uncountable.tex @@ -0,0 +1,74 @@ +\section*{Uncountable Sets} + +\problem{} +Let $B$ be the set of infinite binary strings. Show that $B$ is not countable. \par +Here's how you should start: + +\vspace{2mm} + +Assume we have some enumeration $n(b)$ that assigns a natural number to every $b \in B$.\par +Now, arrange the elements of $B$ in a table, in order of increasing index: \par + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node at (0, 0) {$n(b)$}; + \node at (4.5, 0) {digits of $b$}; + + % Vertical lines + \draw (1, 0.5) -- (1, -8); + \draw (-1, 0.5) -- (-1, -8); + + % Horizontal title + \draw (-1, -0.5) -- (8, -0.5); + + \foreach \i/\j in { + 0/1010100110011110, + 1/0101101011010010, + 2/1101011001010101, + 3/0001100101010110, + 4/1101011101000110, + 5/1101100010100111, + 6/1011001101001010% + } { + \node at (0, -\i-1) {$\i$}; + \draw (-1, -1.5 - \i) -- (8, -1.5 - \i); + \node[anchor=west] at (1, -\i-1) {\texttt{\j}...}; + } + + \node at (0, -7-1) {...}; + \node at (4.5, -7-1) {.....}; +\end{tikzpicture} +\end{center} + + +First, convince yourself that if $B$ is countable, this table will contain every element of $B$, \par +then construct a new element of $B$ that is guaranteed to \textit{not} be in this table.\par +\hint{What should the first digit of this new string be? What should its second digit be? \\ +Or, even better, what \textit{shouldn't} they be?} +\vfill + + +\problem{} +Using \ref{binarystrings}, show that $\mathcal{P}(\mathbb{N})$ is uncountable. +\vfill +\pagebreak + +\problem{} +Show that $\mathbb{R}$ is not countable. \par +\hint{Earlier in this handout, we defined a real number as \say{a decimal, finite or infinite.}} +\vfill + +\problem{} +Find a bijection from $(0, 1)$ to $\mathbb{R}$.\par +\hint{$(0, 1)$ is the set of all real numbers between 0 and 1, not including either endpoint.} +\vspace{2mm} +This problem brings us to the surprising conclusion that there are \say{just as many} numbers between 0 and 1 as there are in the entire real line. + +\vfill + +\problem{} +Find a bijection between $(0, 1)$ and $[0, 1]$. \par +\hint{$[0, 1]$ is the set of all real numbers between 0 and 1, including both endpoints.} +\vfill + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Stopping Problems/main.tex b/src/Advanced/Stopping Problems/main.tex new file mode 100755 index 0000000..fdc85c0 --- /dev/null +++ b/src/Advanced/Stopping Problems/main.tex @@ -0,0 +1,26 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} + +\usepackage{units} +\usepackage{mathtools} % for \coloneqq + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Stopping problems} +\subtitle{Prepared by Mark on \today{}} + +\begin{document} + + \maketitle + + \input{parts/0 probability.tex} + \input{parts/1 intro.tex} + \input{parts/2 secretary.tex} + \input{parts/3 orderstat.tex} + +\end{document} \ No newline at end of file diff --git a/src/Advanced/Stopping Problems/meta.toml b/src/Advanced/Stopping Problems/meta.toml new file mode 100644 index 0000000..1566940 --- /dev/null +++ b/src/Advanced/Stopping Problems/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Stopping Problems" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Stopping Problems/parts/0 probability.tex b/src/Advanced/Stopping Problems/parts/0 probability.tex new file mode 100644 index 0000000..b376b4c --- /dev/null +++ b/src/Advanced/Stopping Problems/parts/0 probability.tex @@ -0,0 +1,141 @@ +\section{Probability} + +\definition{} +A \textit{sample space} is a finite set $\Omega$. \par +The elements of this set are called \textit{outcomes}. \par +An \textit{event} is a set of outcomes (i.e, a subset of of $\Omega$). + +\definition{} +A \textit{probability function} over a sample space $\Omega$ is a function $\mathcal{P}: P(\Omega) \to [0, 1]$ \par +that maps events to real numbers between 0 and 1. \par +Any probability function has the following properties: +\begin{itemize} + \item $\mathcal{P}(\varnothing) = 0$ + \item $\mathcal{P}(\Omega) = 1$ + \item For events $A$ and $B$ where $A \cap B = \varnothing$, $\mathcal{P}(A \cup B) = \mathcal{P}(A) + \mathcal{P}(B)$ +\end{itemize} + + +\problem{} +Say we flip a fair coin three times. \par +List all elements of the sample space $\Omega$ this experiment generates. + +\vfill + +\problem{} +Using the same setup as \ref{threecoins}, find the following: +\begin{itemize} + \item $\mathcal{P}(~ \{\omega \in \Omega ~|~ \omega \text{ has at least two \say{heads}}\} ~)$ + \item $\mathcal{P}(~ \{\omega \in \Omega ~|~ \omega \text{ has an odd number of \say{heads}}\} ~)$ + \item $\mathcal{P}(~ \{\omega \in \Omega ~|~ \omega \text{ has at least one \say{tails}}\} ~)$ +\end{itemize} + +\vfill +\pagebreak + +% +% MARK: Page +% + + +\definition{} +Given a sample space $\Omega$ and a probability function $\mathcal{P}$, \par +a \textit{random variable} is a function from $\Omega$ to a specified output set. + +\vspace{2mm} + +For example, given the three-coin-toss sample space +$\Omega = \{ + \texttt{TTT},~ \texttt{TTH},~ \texttt{THT},~ % spell:disable-line + \texttt{THH},~ \texttt{HTT},~ \texttt{HTH},~ % spell:disable-line + \texttt{HHT},~ \texttt{HHH} % spell:disable-line +\}$, +We can define a random variable $\mathcal{H}$ as \say{the number of heads in a throw of three coins}. \par +As a function, $\mathcal{H}$ maps values in $\Omega$ to values in $\mathbb{Z}^+_0$ and is defined as: +\begin{itemize} + \item $\mathcal{H}(\texttt{TTT}) = 0$ % spell:disable-line + \item $\mathcal{H}(\texttt{TTH}) = 1$ % spell:disable-line + \item $\mathcal{H}(\texttt{THT}) = 1$ % spell:disable-line + \item $\mathcal{H}(\texttt{THH}) = 2$ % spell:disable-line + \item ...and so on. +\end{itemize} + +Intuitively, a random variable assigns a \say{value} in $\mathbb{R}$ to every possible outcome. + + +\definition{} +We can compute the probability that a random variable takes a certain value by computing the probability of +the set of outcomes that produce that value. \par + +\vspace{2mm} + +For example, if we wanted to compute $\mathcal{P}(\mathcal{H} = 2)$, we would find +$\mathcal{P}\bigl(\{\texttt{THH}, \texttt{HTH}, \texttt{HHT}\}\bigr)$. % spell:disable-line + + +\problem{} +Say we flip a coin with $\mathcal{P}(\texttt{H}) = \nicefrac{1}{3}$ three times. \par +What is $\mathcal{P}(\mathcal{H} = 1)$, with $\mathcal{H}$ defined as above? \par +What is $\mathcal{P}(\mathcal{H} = 5)$? + +\vfill + + +\problem{} +Say we roll a fair six-sided die twice. \par +Let $\mathcal{X}$ be a random variable measuring the sum of the two results. \par +Find $\mathcal{P}(\mathcal{X} = x)$ for all $x$ in $\mathbb{Z}$. + +\vfill +\pagebreak + + +% +% MARK: Page +% + + +\definition{} +Say we have a random variable $\mathcal{X}$ that produces outputs in $\mathbb{R}$. \par +The \textit{expected value} of $\mathcal{X}$ is then defined as +\begin{equation*} + \mathcal{E}(\mathcal{X}) + ~\coloneqq~ \sum_{x \in \mathbb{R}}\Bigl(x \times \mathcal{P}\bigl(\mathcal{X} = x\bigr)\Bigr) + ~=~ \sum_{\omega \in \Omega}\Bigl(\mathcal{X}(\omega) \times \mathcal{P}(\omega)\Bigr) +\end{equation*} +That is, $\mathcal{E}(\mathcal{X})$ is the average of all possible outputs of $\mathcal{X}$ weighted by their probability. + +\problem{} +Say we flip a coin with $\mathcal{P}(\texttt{H}) = \nicefrac{1}{3}$ two times. \par +Define $\mathcal{H}$ as the number of heads we see. \par +Find $\mathcal{E}(\mathcal{H})$. + +\vfill + +\problem{} +Let $\mathcal{A}$ and $\mathcal{B}$ be two random variables. \par +Show that $\mathcal{E}(\mathcal{A} + \mathcal{B}) = \mathcal{E}(\mathcal{A}) + \mathcal{E}(\mathcal{B})$. + +\begin{solution} + Use the second definition of $\mathcal{E}$, $\sum_{\omega \in \Omega}\Bigl(\mathcal{X}(\omega) \times \mathcal{P}(\omega)\Bigr)$. + + \vspace{2mm} + + Make sure students understand all parts of \ref{defexp}, and are comfortable with the fact that a random variable \say{assigns values} to outcomes. +\end{solution} + +\vfill + +\definition{} +Let $A$ and $B$ be events on a sample space $\Omega$. \par +We say that $A$ and $B$ are \textit{independent} if $\mathcal{P}(A \cap B) = \mathcal{P}(A) \times \mathcal{P}(B)$. \par +Intuitively, events $A$ and $B$ are independent if the outcome of one does not affect the other. + +\definition{} +Let $\mathcal{A}$ and $\mathcal{B}$ be two random variables over $\Omega$. \par +We say that $\mathcal{A}$ and $\mathcal{B}$ are independent if the events $\{\omega \in \Omega ~|~ \mathcal{A}(\omega) = a\}$ +and $\{\omega \in \Omega ~|~ \mathcal{B}(\omega) = b\}$ are independent for all $(a, b)$ that $\mathcal{A}$ and $\mathcal{B}$ can produce. + + + +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Stopping Problems/parts/1 intro.tex b/src/Advanced/Stopping Problems/parts/1 intro.tex new file mode 100644 index 0000000..940bb85 --- /dev/null +++ b/src/Advanced/Stopping Problems/parts/1 intro.tex @@ -0,0 +1,70 @@ +\section{Introduction} + +\generic{Setup:} +Suppose we toss a 6-sided die $n$ times. \par +It is easy to detect the first time we roll a 6. \par +What should we do if we want to detect the \textit{last}? + +\problem{} +Given $l \leq n$, what is the probability that the last $l$ +tosses of this die contain exactly one six? \par +\hint{Start with small $l$.} + +\begin{solution} + $\mathcal{P}(\text{last } l \text{ tosses have exactly one 6}) = (\nicefrac{1}{6})(\nicefrac{5}{6})^{l-1} \times l$ +\end{solution} + +\vfill + +\problem{} +For what value of $l$ is the probability in \ref{lastl} maximal? \par +The following table may help. \par +\note{We only care about integer values of $l$.} + +\begin{center} + \begin{tabular}{|| c | c | c ||} + \hline + \rule{0pt}{3.5mm} % Bonus height for exponent + $l$ & $(\nicefrac{5}{6})^l$ & $(\nicefrac{1}{6})(\nicefrac{5}{6})^{l}$ \\ + \hline\hline + 0 & 1.00 & 0.167 \\ + \hline + 1 & 0.83 & 0.139 \\ + \hline + 2 & 0.69 & 0.116 \\ + \hline + 3 & 0.58 & 0.096 \\ + \hline + 4 & 0.48 & 0.080 \\ + \hline + 5 & 0.40 & 0.067 \\ + \hline + 6 & 0.33 & 0.056 \\ + \hline + 7 & 0.28 & 0.047 \\ + \hline + 8 & 0.23 & 0.039 \\ + \hline + \end{tabular} +\end{center} + +\begin{solution} + $(\nicefrac{1}{6})(\nicefrac{5}{6})^{l-1} \times l$ is maximal at $l = 5.48$, so $l = 5$. \par + $l = 6$ is close enough. +\end{solution} + +\vfill + +\problem{} +Finish your solution: \par +In $n$ rolls of a six-sided die, what strategy maximizes +our chance of detecting the last $6$ that is rolled? \par +What is the probability of our guess being right? + +\begin{solution} + Whether $l = 5$, $5.4$, or $6$, the probability of success rounds to $0.40$. +\end{solution} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Stopping Problems/parts/2 secretary.tex b/src/Advanced/Stopping Problems/parts/2 secretary.tex new file mode 100644 index 0000000..b0b26e7 --- /dev/null +++ b/src/Advanced/Stopping Problems/parts/2 secretary.tex @@ -0,0 +1,277 @@ +\section{The Secretary Problem} + +\definition{The secretary problem} +Say we need to hire a secretary. We have exactly one position to fill, +and we must fill it with one of $n$ applicants. These $n$ applicants, +if put together, can be ranked unambiguously from \say{best} to \say{worst}. + +\vspace{2mm} + +We interview applicants in a random order, one at a time. \par +At the end of each interview, we either reject the applicant (and move on to the next one), \par +or select the applicant (which fills the position and ends the process). + +\vspace{2mm} + +Each applicant is interviewed at most once---we cannot return to an applicant we've rejected. \par +In addition, we cannot reject the final applicant, as doing so will leave us without a secretary. + +\vspace{2mm} + +For a given $n$, we would like to maximize our probability of selecting the best applicant. \par +This is the only metric we care about---we do not try to maximize the rank of our applicant. \par +Hiring the second-best applicant is no better than hiring the worst. + +\problem{} +If $n = 1$, what is the best hiring strategy, and what is the probability that we hire the best applicant? + +\begin{solution} + This is trivial. Hire the first applicant, she's always the best. +\end{solution} + +\vfill + + + + +\problem{} +If $n = 2$, what is the best hiring strategy, and what is the probability that we hire the best applicant? \par +Is this different than the probability of hiring the best applicant at random? + +\begin{solution} + There are two strategies: + \begin{itemize} + \item hire the first + \item hire the second + \end{itemize} + + Both are equivalent to the random strategy. + + \vspace{2mm} + + Intuitively, the fact that a strategy can't help us makes sense: \par + When we're looking at the first applicant, we have no information; \par + when we're looking at the second, we have no agency (i.e, we \textit{must} hire). +\end{solution} + + +\vfill + + +\problem{} +If $n = 3$, what is the probability of hiring the best applicant at random? \par +Come up with a strategy that produces better odds. + +\begin{solution} + Once we have three applicants, we can make progress. + + \vspace{2mm} + + The remark from the previous solution still holds: \par + When we're looking at the first applicant, we have no information; \par + when we're looking at the last, we have no choices. + + \vspace{2mm} + + So, let's make our decision at the second candidate. \par + If we hire only when the second candidate is better than the first, \par + we end up hiring the best candidate exactly half the time. + + \vspace{2mm} + + This can be verified by checking all six cases. +\end{solution} + +\vfill +\pagebreak + +% +% MARK: Page +% + + +\problem{} +Should we ever consider hiring a candidate that \textit{isn't} the best we've seen so far? \par +Why or why not? \hint{Read the problem again.} + +\begin{solution} + No! A candidate that isn't the best yet cannot be the best overall! \par + Remember---this problem is only interested in hiring the \textit{absolute best} candidate. \par + Our reward is zero in all other cases. +\end{solution} + +\vfill + + +\remark{} +\ref{bestyet} implies that we should automatically reject any applicant that isn't +the best we've seen. We can take advantage of this fact to restrict the types of +strategies we consider. + +\remark{} +Let $B_x$ be the event \say{the $x^\text{th}$ applicant is better than all previous applicants,} \par +and recall that we only know the \textit{relative} ranks of our applicants: \par +given two candidates, we know \textit{which} is better, but not \textit{by how much}. + +\vspace{2mm} + +Therefore, the results of past events cannot provide information about future $B_x$. \par +All events $B_x$ are independent. + +\vspace{2mm} + +We can therefore ignore any strategy that depends on the outcomes of individual $B_x$. +Given this realization, we are left with only one kind of strategy: \par +We blindly reject the first $(k - 1)$ applicants, then select the next \say{best-yet} applicant. \par +All we need to do now is pick the optimal $k$. + +\problem{} +Consider the secretary problem with a given $n$. \par +What are the probabilities of each $B_x$? + +\vfill + + + +\problem{} +What is the probability that the $n^\text{th}$ applicant is the overall best applicant? + +\begin{solution} + All positions are equally likely. $\nicefrac{1}{n}$. +\end{solution} + +\vfill +\pagebreak + +% +% MARK: Page +% + + + + +\problem{} +Given that the $x^\textit{th}$ applicant is the overall best, what is the probability of hiring this applicant \par +if we use the \say{look-then-leap} strategy detailed above? \par +\hint{ + Under what conditions would we \textit{not} hire this applicant? \par + This probability depends on $k$ and $x$. +} + +\begin{solution} + Say that the $x^\text{th}$ applicant is the best overall. If we do not hire this applicant, + we must have hired a candidate that came before them. \par + + \vspace{2mm} + + What is the probability of this? We saw $x-1$ applicants before the $x^\text{th}$. \par + If we hired one of them, the best of those initial $x-1$ candidates did \textit{not} fall + into the initial $k-1$ applicants we rejected. + \note{(This is again verified by contradiction: if the best of the first $x-1$ applicants + \textit{was} within the first $k-1$, we would hire the $x^\text{th}$)} + + \vspace{2mm} + + There are $x-1$ positions to place the best of the first $x-1$ candidates, \par + and $k-1$ of these positions are initially rejected. \par + Thus, the probability of the best of the first $x-1$ applicants being rejected is $\frac{k-1}{x-1}$. + + \vspace{2mm} + + Unraveling our previous logic, we find that the probability we are interested in is also $\frac{k-1}{x-1}$. \par + \note{Assuming that $x \geq k$. Of course, this probability is 0 otherwise.} +\end{solution} + +\vfill + +\problem{} +Consider the secretary problem with $n$ applicants. \par +If we reject the first $k$ applicants and hire the first \say{best-yet} applicant we encounter, \par +what is the probability that we select the best candidate? \par +Call this probability $\phi_n(k)$. + +\begin{solution} + Using \ref{seca} and \ref{secb}, this is straightforward: + \[ + \phi_n(k) + = \sum_{x = k}^{n}\left( \frac{1}{n} \times \frac{k-1}{x-1} \right) + \] +\end{solution} + +\vfill + +\problem{} +Find the $k$ that maximizes $\phi_n(k)$ for $n$ in $\{1, 2, 3, 4, 5\}$. + +\begin{solution} + Brute force. We already know that $\phi_1(1) = 1.0$ and $\phi_2(1) = \phi_3(2) = 0.5$. \par + The maximal value of $\phi_4$ is $\phi_4(2) = 0.46$, and of $\phi_5$ is $\phi_5(3) = 0.43$. +\end{solution} + +\vfill +\pagebreak + + +% +% MARK: Page +% + +\problem{} +Let $r = \frac{k-1}{n}$, the fraction of applicants we reject. Show that +\begin{equation*} + \phi_n(k) + = r \sum_{x = k}^{n}\left( \frac{1}{x-1} \right) +\end{equation*} + +\begin{solution} + This is easy. +\end{solution} + +\vfill + +\problem{} +With a bit of fairly unpleasant calculus, we can show that the following is true for large $n$: +\begin{equation*} + \sum_{x=k}^{n}\frac{1}{x-1} + ~\approx~ \text{ln}\Bigl(\frac{n}{k}\Bigr) +\end{equation*} +Use this fact to find an approximation of $\phi_n(k)$ at large $n$ in terms of $r$. \par +\hint{If $n$ is big, $\frac{k-1}{n} \approx \frac{k}{n}$.} + +\begin{solution} + \begin{equation*} + \phi_n(k) + ~=~ r \sum_{x = k}^{n}\left( \frac{1}{x-1} \right) + ~\approx~ r \times \text{ln}\left(\frac{n}{k}\right) + ~=~ -r \times \text{ln}\left(\frac{k}{n}\right) + ~\approx~ -r \times \text{ln}(r) + \end{equation*} +\end{solution} + +\vfill + +\problem{} +Find the $r$ that maximizes $\underset{n \rightarrow \infty}{\text{lim}} \phi_n$. \par +Also, find the value of $\phi_n$ at this point. \par +\note{If you aren't familiar with calculus, ask an instructor for help.} + + +\begin{solution} + Use the usual calculus tricks: + \begin{equation*} + \frac{d}{dr} \bigl( -r \times \text{ln}(r) \bigr) + = -1 - \text{ln}(r) + \end{equation*} + + Which is zero at $r = e^{-1}$. The value of $ -r \times \text{ln}(r)$ at this point is also $\frac{1}{e}$. +\end{solution} + + +\vfill + +Thus, the \say{look-then-leap} strategy with $r = e^{-1}$ should select the best candidate about $e^{-1} = 37\%$ of the time, +\textit{regardless of $n$.} Our probability of success does not change as $n$ gets larger! \par +\note{Recall that the random strategy succeeds with probability $\nicefrac{1}{n}$. \par +That is, it quickly becomes small as $n$ gets large.} + +\pagebreak diff --git a/src/Advanced/Stopping Problems/parts/3 orderstat.tex b/src/Advanced/Stopping Problems/parts/3 orderstat.tex new file mode 100644 index 0000000..82fc4e5 --- /dev/null +++ b/src/Advanced/Stopping Problems/parts/3 orderstat.tex @@ -0,0 +1,203 @@ +\section{Another Secretary Problem} + +As you may have already noticed, the secretary problem we discussed in the previous section +is somewhat disconnected from reality. Under what circumstances would one only be satisfied +with the \textit{absolute best} candidate? It may make more sense to maximize the average rank +of the candidate we hire, rather than the probability of selecting the best. This is the problem +we'll attempt to solve next. + + +\definition{} +The problem we're solving is summarized below. +Note that this is nearly identical to the classical secretary problem in the previous +section---the only thing that has changed is the goal. +\begin{itemize} + \item We have exactly one position to fill, and we must fill it with one of $n$ applicants. + \item These $n$ applicants, if put together, can be ranked unambiguously from \say{best} to \say{worst}. + \item We interview applicants in a random order, one at a time. + \item After each interview, we either reject or select the applicant. + \item We cannot return to an applicant we've rejected. + \item The process ends once we select an applicant. + + \vspace{2mm} + + \item Our goal is to maximize the rank of the applicant we hire. +\end{itemize} + + +\definition{} +Just like before, we need to restate this problem in the language of probability. \par +To do this, we'll say that each candidate has a \textit{quality} rating in $[0, 1]$. \par + +\vspace{2mm} + +Our series of applicants then becomes a series of random variables $\mathcal{X}_1, \mathcal{X}_2, ..., \mathcal{X}_n$, \par +where each $\mathcal{X}_i$ is drawn uniformly from $[0, 1]$. + +\problem{} +The modification in \ref{mod} doesn't fully satisfy the constraints of the secretary problem. \par +Why not? + +\begin{solution} + If we observe $\mathcal{X}_i$ directly, we obtain \textit{absolute} scores. \par + This is more information than the secretary problem allows us to have---we can know which of + two candidates is better, but \textit{not by how much}. +\end{solution} + +\vfill + +Ignore this issue for now. We'll return to it later. + +\problem{} +Let $\mathcal{X}$ be a random variable uniformly distributed over $[0, 1]$. \par +Given a real number $x$, what is the probability that $\mathcal{P}(\mathcal{X} \leq x)$? + + +\begin{solution} + \begin{equation*} + \mathcal{P}(\mathcal{X} \leq x) = + \begin{cases} + 0 & x \leq 0 \\ + x & 0 < x < 1 \\ + 1 & \text{otherwise} + \end{cases} + \end{equation*} + +\end{solution} + +\vfill + +\problem{} +Say we have five random variables $\mathcal{X}_1, \mathcal{X}_2, ..., \mathcal{X}_5$. \par +Given some $y$, what is the probability that all five $\mathcal{X}_i$ are smaller than $y$? + +\begin{solution} + Naturally, this is $\mathcal{P}(\mathcal{X} \leq y)^5$, which is $y^5$. +\end{solution} + +\vfill +\pagebreak + + +% +% MARK: Page +% + + +\definition{} +Say we have a random variable $\mathcal{X}$ which we observe $n$ times. \note{(for example, we repeatedly roll a die)} +We'll arrange these observations in increasing order, labeled $x_1 < x_2 < ... < x_n$. \par +Under this definition, $x_i$ is called the \textit{$i^\text{th}$ order statistic}---the $i^\text{th}$ smallest sample of $\mathcal{X}$. + +\problem{} +Say we have a random variable $\mathcal{X}$ uniformly distributed on $[0, 1]$, of which we take $5$ observations. \par +Given some $y$, what is the probability that $x_5 < y$? How about $x_4 y) + + + \mathcal{P}(\mathcal{X} \leq y)^5 + $, which is $5y^4(1-y) + y^5$. +\end{solution} + +\vfill + +\problem{} +Consider the same setup as \ref{ostatone}, but with $n$ measurements. \par +What is the probability that $x_i < y$ for a given $y$? + +\begin{solution} + \begin{equation*} + \mathcal{P}(x_i < y) + ~=~ + \sum_{j=i}^{n} + \binom{n}{j} \times + y^j + (1-y)^{n-j} + \end{equation*} +\end{solution} + +\vfill + +\remark{} +The expected value of the $i^\text{th}$ order statistic on $n$ samples of the uniform distribution is below. +\begin{equation*} + \mathcal{E}(x_i) = \frac{i}{n+1} +\end{equation*} +We do not have the tools to derive this yet. + +\pagebreak + +% +% MARK: Page +% + + + +\definition{} +Recall \ref{notsatisfy}. We need one more modification. \par +In order to preserve the constraints of the problem, we will not be allowed to observe $\mathcal{X}_i$ directly. \par +Instead, we'll be given an \say{indicator} $\mathcal{I}_i$ for each $\mathcal{X}_i$, which produces values in $\{0, 1\}$. \par +If the value we observe when interviewing $\mathcal{X}_i$ is the best we've seen so far, $\mathcal{I}_i$ will produce $1$. \par +If it isn't, $\mathcal{I}_i$ produces $0$. + +\problem{} +Given a secretary problem with $n$ applicants, what is $\mathcal{E}(\mathcal{I}_i)$? + +\begin{solution} + \begin{equation*} + \mathcal{E}(\mathcal{I}_i) = \frac{1}{i} + \end{equation*} +\end{solution} + +\vfill + + +\problem{} +What is $\mathcal{E}(\mathcal{X}_i ~|~ \mathcal{I}_i = 1)$? \par +In other words, what is the expected value of $\mathcal{X}_i$ given that \par +we know this candidate is the best we've seen so far? + +\begin{solution} + This is simply the expected value of the $i^\text{th}$ order statistic on $i$ samples: + \begin{equation*} + \mathcal{E}(\mathcal{X}_i ~|~ \mathcal{I}_i = 1) = \frac{i}{i+1} + \end{equation*} +\end{solution} + + +\vfill +\pagebreak + + +\problem{} +In the previous section, we found that the optimal strategy for the classical secretary problem is to +reject the first $e^{-1} \times n$ candidates, and select the next \say{best-yet} candidate we see. \par + +\vspace{2mm} + +How effective is this strategy for the ranked secretary problem? \par +Find the expected rank of the applicant we select using this strategy. + + +\vfill + +\problem{} +Assuming we use the same kind of strategy as before (reject $k$, select the next \say{best-yet} candidate), \par +show that $k = \sqrt{n}$ optimizes the expected rank of the candidate we select. + +\begin{solution} + This is a difficult bonus problem. see + \texttt{Neil Bearden, J. (2006). A new secretary problem with rank-based selection and cardinal payoffs.} +\end{solution} + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Symmetric Groups/main.tex b/src/Advanced/Symmetric Groups/main.tex new file mode 100755 index 0000000..d11dcfe --- /dev/null +++ b/src/Advanced/Symmetric Groups/main.tex @@ -0,0 +1,58 @@ +% use [nosolutions] flag to hide solutions. +% use [solutions] flag to show solutions. +\documentclass[ + solutions, + singlenumbering +]{../../../lib/tex/ormc_handout} +\usepackage{../../../lib/tex/macros} +\usetikzlibrary{calc} + +\uptitlel{Advanced 2} +\uptitler{\smallurl{}} +\title{Symmetric Groups} +\subtitle{Prepared by Mark on \today{}} + + + +\def\line#1#2{ + \draw[line width = 0.3mm, ->, ocyan] + (#1) + -- ($(#1) + (0, -1)$) + -- ($(#2) + (0,1)$) + -- (#2); +} + +\begin{document} + + \maketitle + + \input{parts/0 intro} + \input{parts/1 cycle} + \input{parts/2 groups} + \input{parts/3 subgroup} + + + \section{Bonus problems} + + \problem{} + Show that $x \in \mathbb{Z}^+$ has a multiplicative inverse mod $n$ iff $\text{gcd}(x, n) = 1$ + + \vfill + + \problem{} + Let $\sigma = (\sigma_1 \sigma_2 ... \sigma_k)$ be a $k$-cycle in $S_n$, and let $\tau$ be an arbitrary element of $S_n$. \par + Show that $\tau \sigma \tau^{-1}$ = $\bigl(\tau(\sigma_1), \tau(\sigma_2), ..., \tau(\sigma_k)\bigr)$ \par + \hint{As usual, $\tau$ is a permutation. Thus, $\tau(x)$ is the value at position $x$ after applying $\tau$.} + + \vfill + + \problem{} + Show that the set $\Bigl\{ (1, 2),~ (1,2,...,n) \Bigr\}$ generates $S_n$. + \vfill + + % TODO: (a second day?) + % alternating group + % type and sign and conjugation + % isomorphisms & automorphisms + % automorphism groups +\end{document} diff --git a/src/Advanced/Symmetric Groups/meta.toml b/src/Advanced/Symmetric Groups/meta.toml new file mode 100644 index 0000000..c30e90c --- /dev/null +++ b/src/Advanced/Symmetric Groups/meta.toml @@ -0,0 +1,6 @@ +[metadata] +title = "Symmetric Groups" + +[publish] +handout = true +solutions = true diff --git a/src/Advanced/Symmetric Groups/parts/0 intro.tex b/src/Advanced/Symmetric Groups/parts/0 intro.tex new file mode 100644 index 0000000..1949abe --- /dev/null +++ b/src/Advanced/Symmetric Groups/parts/0 intro.tex @@ -0,0 +1,199 @@ +\section{Introduction} + + +\definition{} +Informally, a \textit{permutation} of a collection of $n$ objects is an ordering of these $n$ objects. \par +For example, a few permutations of $\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}$ are $\texttt{ABCD}$, +$\texttt{BCDA}$, and $\texttt{DACB}$. \par + +\vspace{2mm} + +This, however, isn't the definition we'll use today. Instead of defining permutations as \say{ordered lists,} +(as we do above), we'll define them as functions. Our first goal today is to make sense of this definition. + + + +\definition{Permutations} +Let $\Omega$ be an arbitrary set of $n$ objects. \par +A \textit{permutation} on $\Omega$ is a map from $\Omega$ to itself that produces a \textit{unique} output for each input. \par +\note{In other words, if $a$ and $b$ are different, $f(a)$ and $f(b)$ must also be different.} + + +\footnotetext{The words \say{function} and \say{map} are equivalent.} + +\vspace{2mm} + +For example, consider $\{1, 2, 3\}$. \par +One permutation on this set can be defined as follows: \par +\begin{itemize} + \item $f(1) = 3$ + \item $f(2) = 1$ + \item $f(3) = 2$ +\end{itemize} + +If we take the array $123$ and apply + + +\problem{} +List all permutations on three objects. \par +How many permutations of $n$ objects are there? + +\vfill + + +\problem{} +What map corresponds to the permutation $[321]$? + + +\vfill + +\problem{} +What map corresponds to the \say{do-nothing} permutation? \par +Write it as a function and in square-bracket notation. \par +\note[Note]{We usually call this the \textit{trivial permutation}} + + +\vfill +\pagebreak + + +We can visualize permutations with a \textit{string diagram}, shown below. \par +The arrows in this diagram denote the image of $f$ for each possible input. +Two examples are below: + +\vspace{2mm} +\hfill +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {1}; + \node (2a) at (1, 0.5) {2}; + \node (3a) at (2, 0.5) {3}; + \node (4a) at (3, 0.5) {4}; + + \node (1b) at (0, -2) {1}; + \node (3b) at (1, -2) {3}; + \node (4b) at (2, -2) {4}; + \node (2b) at (3, -2) {2}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {1}; + \node (2a) at (1, 0.5) {2}; + \node (3a) at (2, 0.5) {3}; + \node (4a) at (3, 0.5) {4}; + + \node (2b) at (0, -2) {2}; + \node (1b) at (1, -2) {1}; + \node (3b) at (2, -2) {3}; + \node (4b) at (3, -2) {4}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} +\end{tikzpicture} +\hfill\null +\vspace{2mm} + + +Note that in all our examples thus far, the objects in our set have an implicit order. +This is only for convenience. The elements of $\Omega$ are not ordered (it is a \textit{set}, after all), +and we may present them however we wish. + + + + + + + +\vspace{1cm} + +For example, consider the diagrams below. \par +On the left, 1234 are ordered as usual. In the middle, they are ordered alphabetically. \par +The rightmost diagram uses arbitrary, meaningless labels. + +\vspace{2mm} +\hfill +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {1}; + \node (2a) at (1, 0.5) {2}; + \node (3a) at (2, 0.5) {3}; + \node (4a) at (3, 0.5) {4}; + + \node (2b) at (0, -2) {2}; + \node (1b) at (1, -2) {1}; + \node (3b) at (2, -2) {3}; + \node (4b) at (3, -2) {4}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale=0.5] + \node (4a) at (0, 0.5) {4}; + \node (1a) at (1, 0.5) {1}; + \node (3a) at (2, 0.5) {3}; + \node (2a) at (3, 0.5) {2}; + + \node (1b) at (0, -2) {1}; + \node (4b) at (1, -2) {4}; + \node (3b) at (2, -2) {3}; + \node (2b) at (3, -2) {2}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} +\end{tikzpicture} +\hfill +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {$\triangle$}; + \node (2a) at (1, 0.5) {$\divideontimes$}; + \node (3a) at (2, 0.5) {$\circledcirc$}; + \node (4a) at (3, 0.5) {$\boxdot$}; + + \node (2b) at (0, -2) {$\divideontimes$}; + \node (1b) at (1, -2) {$\triangle$}; + \node (3b) at (2, -2) {$\circledcirc$}; + \node (4b) at (3, -2) {$\boxdot$}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} +\end{tikzpicture} +\hfill\null +\vspace{2mm} + + +It shouldn't be hard to see that despite the different \say{output} order (2134 and 1432), \par +the same permutation is depicted in all three diagrams. This example demonstrates two things: +\begin{itemize}[itemsep=2mm] + \item First, the names of the items in our set do not have any meaning. \par + $\Omega$ is just a set of $n$ arbitrary things, which we may label however we like. + + \item Second, permutations are verbs. We do not care about the \say{output} of a certain permutation, + we care about what it \textit{does}. We could, for example, describe the permutation above as + \say{swap the first two of four elements.} +\end{itemize} + +\vspace{2mm} + + +Why, then, do we order our elements when we talk about permutations? As noted before, this is for convenience. +If we assign a natural order to the elements of $\Omega$ (say, 1234), we can identify permutations by simply listing +their output: +Clearly, $[1234]$ represents the trivial permutation, $[2134]$ represents \say{swap first two,} +and $[4123]$ represents \say{cycle right.} + +\problem{} +Draw string diagrams for $[4123]$ and $[2341]$. + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Symmetric Groups/parts/1 cycle.tex b/src/Advanced/Symmetric Groups/parts/1 cycle.tex new file mode 100755 index 0000000..8721b99 --- /dev/null +++ b/src/Advanced/Symmetric Groups/parts/1 cycle.tex @@ -0,0 +1,536 @@ + +\section{Cycle Notation} + +\definition{Order} +The \textit{order} of a permutation $f$ is the \textbf{smallest} positive $n$ so that $f^n(x) = x$ for all $x$. \par +If we repeatedly apply a permutation with order $n$, we will get back to where we started after $n$ steps. \par + +\vspace{2mm} + +For example, consider $[2134]$. This permutation has order $2$, as we clearly see below: + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {1}; + \node (2a) at (1, 0.5) {2}; + \node (3a) at (2, 0.5) {3}; + \node (4a) at (3, 0.5) {4}; + + \node (2b) at (0, -2) {2}; + \node (1b) at (1, -2) {1}; + \node (3b) at (2, -2) {3}; + \node (4b) at (3, -2) {4}; + + \node (1c) at (0, -4.5) {1}; + \node (2c) at (1, -4.5) {2}; + \node (3c) at (2, -4.5) {3}; + \node (4c) at (3, -4.5) {4}; + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + \line{4a}{4b} + \line{1b}{1c} + \line{2b}{2c} + \line{3b}{3c} + \line{4b}{4c} +\end{tikzpicture} +\end{center} +Swapping the first two elements of a list twice changes nothing. \par +Thus, $[2134]$ has an order of two. + + +\problem{} +What is the order of $[2314]$? \par +How about $[4321]$? \par +\note[Note]{You shouldn't need to draw any strings to solve this problem.} + + +\vfill + +\problem{} +Show that all permutations (on a finite set) have a well-defined order. \par +In other words, show that there is always an integer $n$ so that $f^n(x) = x$. + +\vfill + +\definition{Composition} +The \textit{composition} of two permutations $f$ and $g$ is the permutation $h(x) = f(g(x))$. \par +We'll denote this as $fg$---that is, by simply writing the permutations we're composing next to each other. + +\problem{} +Show that function composition is associative. \par +That is, show that $f(gh) = (fg)h$. + +\vfill + +\problem{} +What is $[1324][4321]$? \par +How about $[321][213][231]$? \par + + +\vfill +\pagebreak + + +As you may have noticed, the square-bracket notation we've been using thus far is a bit unwieldy. +Permutations are verbs---but we've been referring to them using a noun (namely, their output when +applied to an ordered sequence of numbers). Our notation fails to capture the meaning of the +underlying object. + +\vspace{2mm} + +Think about it: is the permutation $[1234]$ different than the permutation $[12345]$? \par +Indeed, these permutations operate on different sets---but they are both the identity! \par +What should we do if we want to talk about the identity on $\{1, 2, ..., 10\}$? + +\vspace{2mm} + +We need something better. + + + + +\definition{Cycles} +Any permutation is composed of a number of \textit{cycles}. \par + +For example, consider the permutation $[2134]$, which consists of one two-cycle: $1 \to 2 \to 1$ \par +\note[Note]{$3 \to 3$ and $4 \to 4$ are also cycles, but we'll ignore them. One-cycles aren't aren't interesting.} + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + + \draw[line width = 0.3mm, ->, ocyan] + (1) + -- ($(1) + (0,-1)$) + -- ($(2) + (0,-1)$) + -- (2); + + \draw[line width = 0.3mm, ->, ocyan] + (2) + -- ($(2) + (0, 1)$) + -- ($(1) + (0, 1)$) + -- (1); +\end{tikzpicture} +\end{center} + + +The permutation $[431265]$ is a bit more interesting---it contains two cycles: \par +($1 \to 3 \to 2 \to 4 \to 1$ and $5 \to 6 \to 5$) + + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + \node (5) at (4, 0) {5}; + \node (6) at (5, 0) {6}; + + \draw[line width = 0.3mm, ->, ocyan] + (3) + -- ($(3) + (0,-1)$) + -- ($(2) + (0,-1)$) + -- (2); + + \draw[line width = 0.3mm, ->, ocyan] + (2) + -- ($(2) + (0,1.5)$) + -- ($(4) + (0,1.5)$) + -- (4); + + \draw[line width = 0.3mm, ->, ocyan] + (4) + -- ($(4) + (0,-1.5)$) + -- ($(1) + (0,-1.5)$) + -- (1); + + \draw[line width = 0.3mm, ->, ocyan] + (1) + -- ($(1) + (0,1)$) + -- ($(3) + (0,1)$) + -- (3); + + \draw[line width = 0.3mm, ->, ogreen] + (5) + -- ($(5) + (0,-1)$) + -- ($(6) + (0,-1)$) + -- (6); + + \draw[line width = 0.3mm, ->, ogreen] + (6) + -- ($(6) + (0,1)$) + -- ($(5) + (0,1)$) + -- (5); + +\end{tikzpicture} +\end{center} + + +Another name we'll often use for two-cycles is \textit{transposition}. \par +Any permutation that swaps two adjacent elements is called a transposition. \par + + +\problem{} +Find all cycles in $[5342761]$. + +\begin{solution} + \begin{center} + \begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + \node (5) at (4, 0) {5}; + \node (6) at (5, 0) {6}; + \node (7) at (6, 0) {7}; + + \draw[line width = 0.3mm, ->, ocyan] + (1) + -- ($(1) + (0,2)$) + -- ($(7) + (0,2)$) + -- (7); + + \draw[line width = 0.3mm, ->, ocyan] + (7) + -- ($(7) + (0,-1.5)$) + -- ($(5) + (0,-1.5)$) + -- (5); + + \draw[line width = 0.3mm, ->, ocyan] + (5) + -- ($(5) + (0,1.5)$) + -- ($(1) + (0.5,1.5)$) + -- ($(1) + (0.5,-1)$) + -- ($(1) + (0,-1)$) + -- (1); + + \draw[line width = 0.3mm, ->, ogreen] + (2) + -- ($(2) + (0,-1.5)$) + -- ($(4) + (0,-1.5)$) + -- (4); + + \draw[line width = 0.3mm, ->, ogreen] + (4) + -- ($(4) + (0,1)$) + -- ($(3) + (0,1)$) + -- (3); + + \draw[line width = 0.3mm, ->, ogreen] + (3) + -- ($(3) + (0,-1)$) + -- ($(2) + (0.5,-1)$) + -- ($(2) + (0.5,1)$) + -- ($(2) + (0,1)$) + -- (2); + \end{tikzpicture} + \end{center} +\end{solution} + +\vfill + + +\problem{} +What permutation (on five objects) is formed by the cycles $3 \to 5 \to 3$ and $1 \to 2 \to 4 \to 1$? + + +\begin{solution} + \begin{center} + \begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + \node (5) at (4, 0) {5}; + + \draw[line width = 0.3mm, ->, ocyan] + (3) + -- ($(3) + (0,1)$) + -- ($(5) + (0,1)$) + -- (5); + + \draw[line width = 0.3mm, ->, ocyan] + (5) + -- ($(5) + (0,-1)$) + -- ($(3) + (0,-1)$) + -- (3); + + \draw[line width = 0.3mm, ->, ogreen] + (1) + -- ($(1) + (0,-1)$) + -- ($(2) + (0,-1)$) + -- (2); + + \draw[line width = 0.3mm, ->, ogreen] + (2) + -- ($(2) + (0,1.5)$) + -- ($(4) + (0,1.5)$) + -- (4); + + \draw[line width = 0.3mm, ->, ogreen] + (4) + -- ($(4) + (0,-1.5)$) + -- ($(1) + (0.5,-1.5)$) + -- ($(1) + (0.5,1)$) + -- ($(1) + (0,1)$) + -- (1); + \end{tikzpicture} + + This is $[41523]$ + \end{center} +\end{solution} + + + +\vfill +\pagebreak + +\definition{Cycle Notation} +We now have a solution to our problem of notation. +Instead of referring to permutations using their output, we will refer to them using their \textit{cycles}. + +\vspace{2mm} + +For example, we'll write $[2134]$ as $(12)$, which denotes the cycle $1 \to 2 \to 1$: + + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + + \draw[line width = 0.3mm, ->, ocyan] + (1) + -- ($(1) + (0,-1)$) + -- ($(2) + (0,-1)$) + -- (2); + + \draw[line width = 0.3mm, ->, ocyan] + (2) + -- ($(2) + (0, 1)$) + -- ($(1) + (0, 1)$) + -- (1); +\end{tikzpicture} +\end{center} + + + +As another example, $[431265]$ is $(1324)(56)$ in cycle notation. \par +Note that we write $[431265]$ as a \textit{composition} of two cycles: \par +applying the permutation $[431265]$ is the same as applying $(1324)$, then applying $(56)$. + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1) at (0, 0) {1}; + \node (2) at (1, 0) {2}; + \node (3) at (2, 0) {3}; + \node (4) at (3, 0) {4}; + \node (5) at (4, 0) {5}; + \node (6) at (5, 0) {6}; + + \draw[line width = 0.3mm, ->, ocyan] + (3) + -- ($(3) + (0,-1)$) + -- ($(2) + (0,-1)$) + -- (2); + + \draw[line width = 0.3mm, ->, ocyan] + (2) + -- ($(2) + (0,1.5)$) + -- ($(4) + (0,1.5)$) + -- (4); + + \draw[line width = 0.3mm, ->, ocyan] + (4) + -- ($(4) + (0,-1.5)$) + -- ($(1) + (0,-1.5)$) + -- (1); + + \draw[line width = 0.3mm, ->, ocyan] + (1) + -- ($(1) + (0,1)$) + -- ($(3) + (0,1)$) + -- (3); + + \draw[line width = 0.3mm, ->, ogreen] + (5) + -- ($(5) + (0,-1)$) + -- ($(6) + (0,-1)$) + -- (6); + + \draw[line width = 0.3mm, ->, ogreen] + (6) + -- ($(6) + (0,1)$) + -- ($(5) + (0,1)$) + -- (5); + +\end{tikzpicture} +\end{center} + +Any permutation $\sigma$ may be written as a product (i.e, composition) of disjoint cycles $\sigma_1\sigma_2...\sigma_k$. \par +Make sure you believe this fact. If you don't, ask an instructor. \par +Also, the identity $f(x) = x$ is written as $()$ in cycle notation. + + + +\problem{} +Convince yourself that disjoint cycles commute. \par +That is, that $(1324)(56) = (56)(1324) = [431265]$ since $(1324)$ and $(56)$ do not overlap. \par + + + + +\problem{} +Write the following in square-bracket notation. +\begin{itemize} + \item $(12)$ \tab~\tab on a set of 2 elements + \item $(12)(435)$ \tab on a set of 5 elements + \vspace{2mm} + \item $(321)$ \tab~\tab on a set of 3 elements + \item $(321)$ \tab~\tab on a set of 6 elements + \vspace{2mm} + \item $(1234)$ \tab on a set of 4 elements + \item $(3412)$ \tab on a set of 4 elements +\end{itemize} +\note{ + Note that $(12)$ refers the \say{swap first two} permutation on a set of \textit{any} size. \\ + We can now use the same name for the same permutation on two different sets! \\ +} + +\vfill + + + +\problem{} +Write the following in square-bracket notation. +Be careful. +\begin{itemize} + \item $(13)(243)$ \tab on a set of 4 elements + \item $(243)(13)$ \tab on a set of 4 elements +\end{itemize} + +\vfill + + + +\problem{} +Look at the last two permutations in \ref{insquare}, $(1234)$ and $(3412)$. \par +These are \textit{identical}---they are the same cycle written in two different ways. \par +List all other ways to write this cycle. \hint{There are two more.} \par +\note{Also, note that the last two permutations in \ref{insquare} are the same.} + +\pagebreak + + +\problem{} +What is the inverse of $(12)$? \par +How about $(123)$? And $(4231)$? \par +\note{ + Note that again, we don't need to know how big our set is. \\ + The inverse of $(12)$ is the same in all sets. +} + +\vfill + + +\problem{} +Say $\sigma$ is a permutation composed of disjoint cycles $\sigma_1\sigma_2...\sigma_k$. \par +Say we know the order of all $\sigma_i$. What is the order of $\sigma$? + +\begin{solution} + $\text{lcm}\Bigl(\text{ord}(\sigma_1),~ \text{ord}(\sigma_2),~ ..., ~ \text{ord}(\sigma_k)\Bigr)$ +\end{solution} + + +\vfill + +\problem{} +Show that any cycle $(123...n)$ is equal to the product $(12)(23)...(n-1, n)$. + +\begin{solution} + TODO +\end{solution} + +\vfill + +\problem{} +Write $(7126453)$ as a product of transpositions. \par + +\vfill +\pagebreak + +\problem{} +Show that any permutation is a product of transpositions. + +\begin{solution} + Use \ref{cycletrans}. +\end{solution} + +\vfill + + +\problem{} +Show that any permutation is a product of transpositions of the form $(1, k)$. \par + +\begin{solution} + Use \ref{simpletrans} and rewrite each $(a, b)$ as $(1, a)(1, b)(1, a)$. \par + Showing that $(a, b) = (1, a)(1, b)(1, a)$ is fairly easy. +\end{solution} + +\vfill +\pagebreak + + + +\problem{} +Show that any transposition $(a, b)$ is equal to the product $(a, a+1)(a+1, b)(a, a+1)$. + +\begin{solution} + This is the same as the $(1, a)(1, b)(1, a)$ case above, but we use $a + 1$ + as a \say{working slot} instead of $1$. +\end{solution} + +\vfill + + + +\problem{} +Show that any permutation is a product of adjacent transpositions. \par +(An \textit{adjacent transposition} swaps two adjacent elements, and thus looks like $(n, n+1)$) + +\begin{solution} + As before, we will use \ref{simpletrans} and rewrite the transpositions it produces in a form that fits the problem. + We thus need to show that every transposition $(a, b)$ is a product of adjacent transpositions. + + \vspace{8mm} + + In the proof below, assume that $a < b$ and perform induction on $b - a$. \par + + \textbf{Base Case:}\par + If $b - a = 1$, we clearly see that $(a, b)$ is a product of adjacent. \par + In fact, it \textit{is} an adjacent transposition. + + \vspace{4mm} + + \textbf{Induction:}\par + Now, say $b - a = n + 1$. \par + Assume that all $(a, b)$ where $b - a \leq n$ are products of adjacent transpositions.\par + Note that $(a, b) = (a, a+1)(a+1, b)(a, a+1)$. + + \vspace{2mm} + + $(a, a+1)$ is an adjacent transposition, and $b - (a+1) = n$. \par + Thus, $(a, b)$ is a product of adjacent transpositions. +\end{solution} + + +\vfill +\pagebreak \ No newline at end of file diff --git a/src/Advanced/Symmetric Groups/parts/2 groups.tex b/src/Advanced/Symmetric Groups/parts/2 groups.tex new file mode 100755 index 0000000..abb0ded --- /dev/null +++ b/src/Advanced/Symmetric Groups/parts/2 groups.tex @@ -0,0 +1,165 @@ +\section{Groups (review)} + +\definition{} +Before we continue, we must introduce a bit of notation: +\begin{itemize} + \item $S_n$ is the set of permutations on $n$ objects. + \item $\mathbb{Z}_n$ is the set of integers mod $n$. + + \item $\mathbb{Z}_n^\times$ is the set of integers mod $n$ with multiplicative inverses. \par + In other words, it is the set of integers smaller than $n$ and coprime to $n$.\footnotemark{} \par + For example, $\mathbb{Z}_{12}^\times = \{1, 5, 7, 11\}$. + + \footnotetext{We proved this in another handout, but you may take it as fact here.} +\end{itemize} + +\problem{} +What are the elements of $S_3$? \tab\hint{Use cycle notation}\par +How about $\mathbb{Z}_{17}^\times$? + +\vfill + + +\definition{} +A \textit{group} $(G, \ast)$ consists of a set $G$ and an operator $\ast$. \par +Groups always have the following properties: + +\begin{enumerate} + \item $G$ is closed under $\ast$. In other words, $a, b \in G \implies a \ast b \in G$. + \item $\ast$ is \textit{associative}: $(a \ast b) \ast c = a \ast (b \ast c)$ for all $a,b,c \in G$ + \item There is an \textit{identity} $e \in G$, so that $a \ast e = a \ast e = a$ for all $a \in G$. + \item For any $a \in G$, there exists a $b \in G$ so that $a \ast b = b \ast a = e$. $b$ is called the \textit{inverse} of $a$. \par + This element is written as $-a$ if our operator is addition and $a^{-1}$ otherwise. +\end{enumerate} + +Any pair $(G, \ast)$ that satisfies these properties is a group. + +\problem{} +Is $(\mathbb{Z}_5, +)$ a group? \par +Is $(\mathbb{Z}_5, -)$ a group? \par +\note[Note]{$+$ and $-$ refer to the usual operations in modular arithmetic.} +\vfill + + +\problem{} +What is the group with the fewest elements? + +\begin{solution} + Let $(G, \star)$ be our group, where $G = \{x\}$ and $\star$ is defined by $x \star x = x$ + + Verifying that the trivial group is a group is trivial. +\end{solution} + +\vfill +\pagebreak + + + + + + + + + + + +\problem{} +Show that function composition is associative + +\vfill + + +\problem{} +Show that $S_n$ is a group under composition. + +\vfill + +\problem{} +Let $(G, \ast)$ be a group with finitely many elements, and let $a \in G$. \par +Show that $\exists n \in \mathbb{Z}^+$ so that $a^n = e$ \par +\hint{$a^n = a \ast a \ast ... \ast a$ repeated $n$ times.} + +\vspace{2mm} + +The smallest such $n$ defines the \textit{order} of $g$. + +\begin{examplesolution} + We've already done a special case of this problem! \par + Find it in this handout, then rewrite your proof for an arbitrary (finite) group. +\end{examplesolution} + + +\vfill + +\problem{} +What is the order of 5 in $(\mathbb{Z}_{25}, +)$? \par +What is the order of 2 in $(\mathbb{Z}_{17}^\times, \times)$? \par + +\vfill +\pagebreak + + + + + + + + + + + + + + +\definition{} +Let $G$ be a group, and let $g$ be an element of $G$. \par +We say $g$ is a \textit{generator} if every other element of $G$ may be written as a power of $g$. \par + +\problem{} +Say the size of a group $G$ is $n$. \par +If $g$ is a generator, what is its order? \par +Provide a proof. +\vfill + + + +\problem{} +Find the two generators in $(\mathbb{Z}, +)$ \par +Then, find all generators of $(\mathbb{Z}_5, +)$ +\vfill + + +\problem{} +How many groups have only one generator? + +\begin{solution} + Only one: the trivial group. The inverse of a generator is also a generator! +\end{solution} + +\vfill + + +\definition{} +Let $S$ be a subset of the elements in $G$. \par +We say that $S$ \textit{generates} $G$ if every element of $G$ may be written as a product of elements in $S$. \par +\note{Note that this is an extension of \ref{gendef}.} + +\problem{} +We've already found a few generating sets of $S_n$. What are they? + +\begin{solution} + The following sets generate $S_n$: + \begin{itemize} + \item All transpositions + \item All transpositions of the form $(1, k)$ + \item All adjacent transpositions + \end{itemize} + + \vspace{2mm} + + The smallest generating set of $S_n$ consists of the transposition $(12)$ and the $n$-cycle $(1,2,...,n)$. \par + The proof of this is a bonus problem later in the handout. +\end{solution} + +\vfill +\pagebreak diff --git a/src/Advanced/Symmetric Groups/parts/3 subgroup.tex b/src/Advanced/Symmetric Groups/parts/3 subgroup.tex new file mode 100644 index 0000000..b0f4980 --- /dev/null +++ b/src/Advanced/Symmetric Groups/parts/3 subgroup.tex @@ -0,0 +1,163 @@ +\section{Subgroups} + +\problem{} +What elements do $S_2$ and $S_3$ share? +\vspace{2cm} + + + +Consider the sets $\{1, 2\}$ and $\{1,2,3\}$. Clearly, $\{1, 2\} \subset \{1, 2, 3\}$. \par +Can we say something similar about $S_2$ and $S_3$? + +\vspace{2mm} + +Looking at \ref{s2s3share}, we may want to say that $S_2 \subset S_3$ since every element of $S_2$ is in $S_3$. \par +This however, isn't as interesting as it could be. Remember that $S_2$ and $S_3$ are \textit{groups}, not \textit{sets}: \par +their elements come with structure, which the \say{subset} relation does not capture. + +\vspace{2mm} + +To account for this, we'll define a similar relation: subgroups. + +\definition{} +Let $G$ and $G'$ be groups. We say $G'$ is a \textit{subgroup} of $G$ (and write $G' \subset G$) if the following are true:\par +(Note that $x, y$ are elements of $G$, and $xy$ is multiplication in $G$) +\begin{itemize} + \item the set of elements in $G'$ is a subset of the set of elements in $G$. + \item the identity of $G$ is in $G'$ + \item $x,y \in G' \implies xy \in G'$ + \item $x \in G' \implies x^{-1} \in G'$ +\end{itemize} + +The above definition may look faily scary, but the idea behind a subgroup is simple. \par +Consider $S_3$ and $S_4$, the groups of permutations of $3$ and $4$ elements. \par + +\vspace{2mm} + +Say we have a set of four elements and only look at the first three. \par +$S_3$ fully describes all the ways we can arrange those three elements: + +\begin{center} +\begin{tikzpicture}[scale=0.5] + \node (1a) at (0, 0.5) {1}; + \node (2a) at (1, 0.5) {2}; + \node (3a) at (2, 0.5) {3}; + \node (4a) at (3, 0.5) {4}; + + \node (2b) at (0, -2) {2}; + \node (3b) at (1, -2) {3}; + \node (1b) at (2, -2) {1}; + \node (4b) at (3, -2) {4}; + + \draw[line width = 0.3mm, ->, ogreen] + (4a) + -- ($(4a) + (0, -1)$) + -- ($(4b) + (0,1)$) + -- (4b); + + \line{1a}{1b} + \line{2a}{2b} + \line{3a}{3b} + + \node[fill=white,draw=oblue,line width=0.3mm] at (1, -0.75) {$S_3$}; + +\end{tikzpicture} +\end{center} + + +\problem{} +Show that $S_3$ is a subgroup of $S_4$. + +\vfill +\pagebreak + + + +\definition{} +Let $G$ and $H$ be groups. We say that $G$ and $H$ are \textit{isomorphic} (and write $A \simeq B$) \par +if there is a bijection $f: G \to H$ with the following properties: +\begin{itemize} + \item $f(e_G) = e_H$, where $e_G$ is the identity in $G$ + \item $f(x^{-1}) = f(x)^{-1}$ for all $x$ in $G$ + \item $f(xy) = f(x)f(y)$ for all $x, y$ in $G$ +\end{itemize} + +Intuitively, you can think of isomorphism as a form of equivalence. \par +If two groups are isomorphic, they only differ by the names of their elements. \par +The function $f$ above tells us how to map one set of labels to the other. + + + +\problem{} +Show that $\mathbb{Z}_7^\times$ and $\mathbb{Z}_9^\times$ are isomorphic. +\hint{ + Build a bijection with the above properties. \\ + Remember that a group is fully defined by its multiplication table. +} +\vfill + + +\problem{} +Show that $\mathbb{Z}_{10}^\times$ and $\mathbb{Z}_5^\times$, and $\mathbb{Z}_4$ are isomorphic. +\hint{ + Build a bijection with the above properties. \\ + Remember that a group is fully defined by its multiplication table. +} + + +\vfill + +\problem{} +Show that isomorphism is transitive. \par +That is, if $A \simeq B$ and $B \simeq C$, then $A \simeq C$. + +\vfill +\pagebreak + + +\problem{} +How many subgroups of $S_4$ are isomorphic to $S_3$? \par + +\vfill + + + + +\problem{} +What are the orders of $S_3$ and $S_4$? \par +How is this related to \ref{firstindex}? + +\begin{solution} + $|S_4| = |S_3| \times [S_4 : S_3]$ + + \vspace{2mm} + + This solution is written using index notation, \par + but the class doesn't need to know what it means yet. +\end{solution} + +\vfill + +\problem{} +$S_4$ also has $S_2$ and the trivial group as subgroups. \par +How many instances of each does $S_4$ contain? + +\vfill + + +\problem{} +$(\mathbb{Z}_4, +)$ is also a subgroup of $S_4$. Find it! \par +How many subgroups of $\mathbb{Z}_4$ are isomorphic to $S_4$?. + +\begin{solution} + A good hint is \say{look at generators.} + + \vspace{4mm} + + There are four instances of $\mathbb{Z}_4$ in $S_4$, each of which is generated by a 4-cycle of $S_n$. \par + (i.e, the group generated by $(1234)$ is isomorphic to $\mathbb{Z}_4$) +\end{solution} + + +\vfill +\pagebreak