Advanced handouts
Add missing file Co-authored-by: Mark <mark@betalupi.com> Co-committed-by: Mark <mark@betalupi.com>
31
src/Advanced/Compression/main.tex
Executable file
@ -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}
|
6
src/Advanced/Compression/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Compression"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
38
src/Advanced/Compression/parts/0 intro.tex
Normal file
@ -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{}<naivelen>
|
||||
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
|
190
src/Advanced/Compression/parts/1 runlength.tex
Normal file
@ -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{}<runlenone>
|
||||
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{<space>} 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{}<firstlz>
|
||||
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
|
174
src/Advanced/Compression/parts/2 lzss.tex
Normal file
@ -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{<pos, len>}, 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{<pos, len>}, 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
|
424
src/Advanced/Compression/parts/3 huffman.tex
Normal file
@ -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{}<treedecode>
|
||||
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{}<hufptone>
|
||||
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{}<hufpttwo>
|
||||
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
|
40
src/Advanced/Compression/parts/4 bonus.tex
Normal file
@ -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
|
BIN
src/Advanced/Compression/parts/qoi-specification.pdf
Normal file
68
src/Advanced/Compression/tikzset.tex
Normal file
@ -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
|
||||
}
|
||||
}
|
29
src/Advanced/Continued Fractions/main.tex
Executable file
@ -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}
|
6
src/Advanced/Continued Fractions/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Continued Fractions"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
65
src/Advanced/Continued Fractions/parts/00 euclidean.tex
Executable file
@ -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}<divalgo>
|
||||
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{}<gcd_abc>
|
||||
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
|
194
src/Advanced/Continued Fractions/parts/01 part A.tex
Normal file
@ -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{}<num2cf>
|
||||
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{}<euclid>
|
||||
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{}<irrational>
|
||||
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
|
262
src/Advanced/Continued Fractions/parts/02 part B.tex
Normal file
@ -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{}<sqrt5>
|
||||
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}<rec>
|
||||
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{}<form1>
|
||||
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{}<diff>
|
||||
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}<farey>
|
||||
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
|
32
src/Advanced/Cryptography/main.tex
Executable file
@ -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}
|
6
src/Advanced/Cryptography/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Cryptography"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
139
src/Advanced/Cryptography/parts/0 euclidean.tex
Executable file
@ -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}<divalgo>
|
||||
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{}<gcd_abc>
|
||||
For any integers $a, b, c$, \par
|
||||
$\gcd(ac + b, a) = \gcd(a, b)$
|
||||
|
||||
\problem{The Euclidean Algorithm}<euclid>
|
||||
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{}<extendedeuclid>
|
||||
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
|
||||
|
91
src/Advanced/Cryptography/parts/1 mod.tex
Executable file
@ -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{}<mod_has_inverse>
|
||||
$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{}<general_inverse>
|
||||
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
|
||||
|
99
src/Advanced/Cryptography/parts/2 groups.tex
Executable file
@ -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
|
42
src/Advanced/Cryptography/parts/3 DLP.tex
Executable file
@ -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
|
||||
|
||||
|
129
src/Advanced/Cryptography/parts/4 DiffieHellman.tex
Executable file
@ -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
|
||||
|
||||
|
128
src/Advanced/Cryptography/parts/5 Elgamal.tex
Executable file
@ -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
|
||||
|
||||
|
187
src/Advanced/Cryptography/parts/challenge.tex
Executable file
@ -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{}<eua_runtime>
|
||||
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{}<flt_prereq>
|
||||
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
|
24
src/Advanced/DFAs/main.tex
Executable file
@ -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}
|
6
src/Advanced/DFAs/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Finite Automata"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
649
src/Advanced/DFAs/parts/0 DFA.tex
Normal file
@ -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{}<SameStartAndEnd>
|
||||
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{}<fibonacci>
|
||||
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{}<divsix>
|
||||
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
|
186
src/Advanced/DFAs/parts/1 regular.tex
Normal file
@ -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
|
79
src/Advanced/DFAs/tikzset.tex
Normal file
@ -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
|
||||
}
|
||||
}
|
30
src/Advanced/De Bruijn/main.tex
Executable file
@ -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}
|
6
src/Advanced/De Bruijn/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "De Bruijn"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
56
src/Advanced/De Bruijn/parts/0 intro.tex
Normal file
@ -0,0 +1,56 @@
|
||||
\section{Introduction}
|
||||
|
||||
\example{}<lockproblem>
|
||||
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
|
225
src/Advanced/De Bruijn/parts/1 words.tex
Normal file
@ -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{}<sbounds>
|
||||
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{}<cword>
|
||||
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
|
||||
|
||||
|
392
src/Advanced/De Bruijn/parts/2 bruijn.tex
Normal file
@ -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{}<eulerexists>
|
||||
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{}<dbbounds>
|
||||
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{}<dbpath>
|
||||
Show that $G_4$ always contains an Eulerian path. \par
|
||||
\hint{\ref{eulerexists}}
|
||||
|
||||
\vfill
|
||||
|
||||
\theorem{}<dbeuler>
|
||||
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{}<dblength>
|
||||
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{}<dbsubset>
|
||||
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
|
110
src/Advanced/De Bruijn/parts/3 line.tex
Normal file
@ -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
|
434
src/Advanced/De Bruijn/parts/4 sturmian.tex
Normal file
@ -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{}<trysturmian>
|
||||
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{}<sturmanthm>
|
||||
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{}<sturmianfour>
|
||||
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
|
65
src/Advanced/De Bruijn/tikzset.tex
Normal file
@ -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
|
||||
}
|
||||
}
|
29
src/Advanced/Definable Sets/main.tex
Executable file
@ -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}
|
6
src/Advanced/Definable Sets/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Definable Sets"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
173
src/Advanced/Definable Sets/parts/0 logic.tex
Normal file
@ -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
|
202
src/Advanced/Definable Sets/parts/1 structures.tex
Normal file
@ -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
|
139
src/Advanced/Definable Sets/parts/2 quantifiers.tex
Normal file
@ -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
|
213
src/Advanced/Definable Sets/parts/3 sets.tex
Normal file
@ -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<y<x) ~\bigr]$ \tab \note{\say{$x$ is positive and isn't 0 or 1}} \par
|
||||
$\varphi(x) \coloneqq \bigl[~ (x<0) \land \lnot \exists ab ~ (\psi(a) \land \psi(b) \land a \times b = x) \bigr]$
|
||||
\end{solution}
|
||||
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
\problem{}
|
||||
Define $\mathbb{R}^+_0$ in $\Bigl( \mathbb{R} ~\big|~ \{\times\} \Bigr)$ \par
|
||||
|
||||
\begin{solution}
|
||||
$\varphi(x) \coloneqq \bigl[ \exists y ~ y \times y = x \bigr]$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Let $\bigtriangleup$ be a relational symbol. $a \bigtriangleup b$ is only true if $a$ divides $b$. \par
|
||||
Define the set of prime numbers in $\Bigl( \mathbb{Z}^+ ~\big|~ \{ \bigtriangleup \} \Bigr)$ \par
|
||||
|
||||
\begin{solution}
|
||||
$
|
||||
\varphi(x) \coloneqq
|
||||
\bigl[~ \lnot \exists abc ~ \bigl(
|
||||
(a \bigtriangleup x) \land
|
||||
(b \bigtriangleup x) \land
|
||||
(c \bigtriangleup x) \land
|
||||
\lnot (a = b) \land
|
||||
\lnot (a = c) \land
|
||||
\lnot (b = c)
|
||||
\bigr) ~\bigr]
|
||||
$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
|
||||
|
||||
\theorem{Lagrange's Four Square Theorem}
|
||||
Every natural number may be written as a sum of four integer squares.
|
||||
|
||||
\problem{}
|
||||
Define $\mathbb{Z}^+_0$ in $\Bigl( \mathbb{Z} ~\big|~ \{\times, +\} \Bigr)$
|
||||
|
||||
\begin{solution}
|
||||
$\varphi(x) \coloneqq \bigl[~ \exists abcd ~ (a^2 + b^2 + c^2 + d^2 = x) ~\bigr]$,
|
||||
where $a^2 \coloneqq a \times a$.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
|
||||
|
||||
|
||||
\problem{}
|
||||
Define $<$ in $\Bigl( \mathbb{Z} ~\big|~ \{\times, +\} \Bigr)$ \par
|
||||
\hint{We can't formally define a relation yet. Don't worry about that for now. \\
|
||||
You can repharase this question as \say{given $x,y \in \mathbb{Z}$, write a formula $\varphi(x, y)$ that is only true if $x < y$}}
|
||||
|
||||
\begin{solution}
|
||||
Let $\psi(x)$ be the formula from the previous problem.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
$\varphi(x, y) \coloneqq \bigl[~ \lnot (x=y) \land \exists d ~ \bigl(\psi(d) \land (x + d = y)\bigr) ~\bigr]$
|
||||
\end{solution}
|
||||
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
\problem{}
|
||||
Consider the structure $S = ( \mathbb{R} ~|~ \{0, \diamond \} )$ \par
|
||||
The relation $a \diamond b$ holds if $| a - b | = 1$
|
||||
|
||||
\problempart{}
|
||||
Define $\{-1, 1\}$ in $S$.
|
||||
|
||||
\begin{solution}
|
||||
$\varphi(x) \coloneqq \bigl[ 0 \diamond x \bigr]$
|
||||
\end{solution}
|
||||
|
||||
\problempart{}
|
||||
Define $\{-2, 2\}$ in $S$.
|
||||
|
||||
\begin{solution}
|
||||
$\varphi(x) \coloneqq \bigl[~ \forall a ~ (0 \diamond x \rightarrow a \diamond x) \land \lnot (x = 0) ~\bigr]$
|
||||
\end{solution}
|
||||
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Let $\mathcal{P}$ be the set of all subsets of $\mathbb{Z}^+_0$. This is called the \textit{power set} of $\mathbb{Z}^+_0$. \par
|
||||
Let $S$ be the structure $( \mathcal{P} ~|~ \{\subseteq\})$ \par
|
||||
|
||||
\problempart{}
|
||||
Show that the empty set is definable in $S$. \par
|
||||
\hint{Defining $\{\}$ with $\{x ~|~ \lnot x = x\}$ is \textbf{not} what we need here. \\
|
||||
We need $\varnothing \in \mathcal{P}$, the \say{empty set} element in the power set of $\mathbb{Z}^+_0$.}
|
||||
|
||||
\begin{solution}
|
||||
$\varphi(x) \coloneqq \bigl[~ \forall y ~ x \subseteq y ~\bigr]$ \par
|
||||
Note that we can use the same property to define 0 in $( \mathbb{Z} ~|~ \{\leq\})$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problempart{}
|
||||
Let $x \Bumpeq y$ be a relation on $\mathcal{P}$. $x \Bumpeq y$ holds if $x \cap y \neq \{\}$. \par
|
||||
Show that $\Bumpeq$ is definable in $S$.
|
||||
|
||||
\begin{solution}
|
||||
Let $\psi(x)$ be the formula from the previous problem.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
$\varphi(x, y) \coloneqq \bigl[~ \exists x ~ (a \subseteq x) \land (a \subseteq y) \land \lnot \psi(a) ~\bigr]$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problempart{}
|
||||
Let $f$ be the function on $\mathcal{P}$ defined by $f(x) = \mathbb{Z}^+_0 - x$. This is called the \textit{complement} of $x$. \par
|
||||
Show that $f$ is definable in $S$. \par
|
||||
\hint{You can define a function by writing a formula $\varphi(x, y)$ that is only true when $y = f(x)$.}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
57
src/Advanced/Definable Sets/parts/4 equivalence.tex
Normal file
@ -0,0 +1,57 @@
|
||||
\section{Equivalence}
|
||||
|
||||
\generic{Notation:}
|
||||
Let $S$ be a structure and $\varphi$ a formula. \par
|
||||
If $\varphi$ is true in $S$, we write $S \models \varphi$. \par
|
||||
This is read \say{$S$ satisfies $\varphi$}
|
||||
|
||||
\definition{}
|
||||
Let $S$ and $T$ be structures. \par
|
||||
We say $S$ and $T$ are \textit{equivalent} (and write $S \equiv T$) if for any formula $\varphi$, $S \models \varphi \Longleftrightarrow T \models \varphi$. \par
|
||||
If $S$ and $T$ are not equivalent, we write $S \not\equiv T$.
|
||||
|
||||
\problem{}
|
||||
Show that $
|
||||
\Bigl(\mathbb{Z} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
\not\equiv
|
||||
\Bigl(\mathbb{R} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
$
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Show that $
|
||||
\Bigl(\mathbb{Z} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
\not\equiv
|
||||
\Bigl(\mathbb{N} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
$
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Show that $
|
||||
\Bigl(\mathbb{R} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
\not\equiv
|
||||
\Bigl(\mathbb{N} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
$
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Show that $
|
||||
\Bigl(\mathbb{R} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
\not\equiv
|
||||
\Bigl(\mathbb{Z}^2 ~\big|~ \{ +, 0 \}\Bigr)
|
||||
$
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Show that $
|
||||
\Bigl(\mathbb{Z} ~\big|~ \{ +, 0 \}\Bigr)
|
||||
\not\equiv
|
||||
\Bigl(\mathbb{Z}^2 ~\big|~ \{ +, 0 \}\Bigr)
|
||||
$
|
||||
|
||||
\begin{solution}
|
||||
All of the above are easy, but the last one can take a while. \par
|
||||
The trick is to notice that $\mathbb{Z}$ has two equivalence classes mod 2, while $\mathbb{Z}^2$ has four.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
26
src/Advanced/Error-Correcting Codes/main.tex
Executable file
@ -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{hyperref}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{patterns}
|
||||
|
||||
\uptitlel{Advanced 2}
|
||||
\uptitler{\smallurl{}}
|
||||
\title{Error-Correcting Codes}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\input{parts/00 detection}
|
||||
\input{parts/01 correction}
|
||||
\input{parts/02 hamming}
|
||||
\end{document}
|
6
src/Advanced/Error-Correcting Codes/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Error-Correcting Codes"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
140
src/Advanced/Error-Correcting Codes/parts/00 detection.tex
Executable file
@ -0,0 +1,140 @@
|
||||
\section{Error Detection}
|
||||
|
||||
An ISBN\footnote{International Standard Book Number} is a unique numeric book identifier. It comes in two forms: ISBN-10 and ISBN-13. Naturally, ISBN-10s have ten digits, and ISBN-13s have thirteen. The final digit in both versions is a \textit{check digit}.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Say we have a sequence of nine digits, forming a partial ISBN-10: $n_1 n_2 ... n_9$. \par
|
||||
The final digit, $n_{10}$, is chosen from $\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\}$ so that:
|
||||
|
||||
$$
|
||||
\sum_{i = 1}^{10} (11 - i)n_i \equiv 0 \text{ mod } 11
|
||||
$$
|
||||
|
||||
If $n_{10}$ is equal to 10, it is written as \texttt{X}.
|
||||
|
||||
|
||||
\problem{}
|
||||
Only one of the following ISBNs is valid. Which one is it?
|
||||
|
||||
\begin{itemize}
|
||||
\item \texttt{0-134-54896-2}
|
||||
\item \texttt{0-895-77258-2}
|
||||
\end{itemize}
|
||||
|
||||
\begin{solution}
|
||||
The first has an inconsistent check digit.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-10 and change one digit. Is it possible that you get another valid ISBN-10? \par
|
||||
Provide a proof.
|
||||
|
||||
\begin{solution}
|
||||
Let $S$ be the sum $10n_1 + 9n_2 + ... + 2n_9 + n_{10}$, before any digits are changed.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
If you change one digit of the ISBN, $S$ changes by $km$, where $k \in \{1,2,...,10\}$ and $|m| \leq 10$. \par
|
||||
$k$ and $m$ cannot be divisible by 11, thus $km$ cannot be divisible by 11.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
We know that $S \equiv 0 \text{ (mod 11)}$. \par
|
||||
After the change, the checksum is $S + km \equiv km \not\equiv 0 \text{ (mod 11)}$.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-10 and swap two adjacent digits. When will the result be a valid ISBN-10? \par
|
||||
This is called a \textit{transposition error}.
|
||||
|
||||
|
||||
\begin{solution}
|
||||
Let $n_1n_2...n_{10}$ be a valid ISBN-10. \par
|
||||
When we swap $n_i$ and $n_{i+1}$, we subtract $n_i$ and add $n_{i+1}$ to the checksum.
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
If the new ISBN is to be valid, we must have that $n_{i+1} - n_i \equiv 0 \text{ (mod 11)}$. \par
|
||||
This is impossible unless $n_i = n_{i+1}$. Figure out why yourself.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
ISBN-13 error checking is slightly different. Given a partial ISBN-13 $n_1 n_2 n_3 ... n_{12}$, the final digit is given by
|
||||
|
||||
$$
|
||||
n_{13} = \Biggr[ \sum_{i=1}^{12} n_i \times (2 + (-1)^i) \Biggl] \text{ mod } 10
|
||||
$$
|
||||
|
||||
What is the last digit of the following ISBN-13? \par
|
||||
\texttt{978-0-380-97726-?}
|
||||
|
||||
\begin{solution}
|
||||
The final digit is 0.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-13 and change one digit. Is it possible that you get another valid ISBN-13? \par
|
||||
If you can, provide an example; if you can't, provide a proof.
|
||||
|
||||
\begin{solution}
|
||||
Let $n_1n_2...n_{13}$ be a valid ISBN-13. Choose some $n_i$ and change it to $m_i$. \par
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Since $n_i$, $m_i$ $\in \{0, 1, 2, ..., 9\}$, $-9 \leq n_i - m_i \leq 9$. \par
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 0: $i$ is 13 \par
|
||||
This is trivial.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 1: $i$ is odd \par
|
||||
For the new ISBN to be valid, we need $n_i - m_i \equiv 0 \text{ (mod 10)}$. \par
|
||||
This cannot happen if $n_i \neq m_i$.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Case 2: $i$ is even \par
|
||||
For the new ISBN to be valid, we need $3(n_i - m_i) \equiv 0 \text{ (mod 10)}$ \par
|
||||
This cannot happen, 10 and 3 are coprime.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Take a valid ISBN-13 and swap two adjacent digits. When will the result be a valid ISBN-13? \par
|
||||
\hint{The answer here is more interesting than it was last time.}
|
||||
|
||||
\begin{solution}
|
||||
Say we swap $n_i$ and $n_{i+1}$, where $i \in \{1, 2, ..., 11\}$. \par
|
||||
The checksum changes by $2(n_{i+1} - n_i)$, and will \par
|
||||
remain the same if this value is $\equiv 0 \text{ (mod 10)}$.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}<isbn-nocorrect>
|
||||
\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
|
134
src/Advanced/Error-Correcting Codes/parts/01 correction.tex
Normal file
@ -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{}<number-repeat>
|
||||
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{}<k-efficiency>
|
||||
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
|
577
src/Advanced/Error-Correcting Codes/parts/02 hamming.tex
Normal file
@ -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{}<generalize-hamming>
|
||||
Can you generalize this system for messages of 4, 64, or 256 bits?
|
||||
|
||||
\vfill
|
||||
|
||||
\pagebreak
|
BIN
src/Advanced/Error-Correcting Codes/qr.png
Normal file
After Width: | Height: | Size: 89 KiB |
52
src/Advanced/Esoteric Languages/main.tex
Executable file
@ -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}
|
6
src/Advanced/Esoteric Languages/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Esoteric Languages"
|
||||
|
||||
[publish]
|
||||
handout = false
|
||||
solutions = false
|
159
src/Advanced/Esoteric Languages/parts/00 turing.tex
Executable file
@ -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{}<bfadd>
|
||||
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
|
127
src/Advanced/Esoteric Languages/parts/01 befunge.tex
Executable file
@ -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
|
236
src/Advanced/Estimathon/main.tex
Executable file
@ -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}
|
6
src/Advanced/Estimathon/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Estimathon"
|
||||
|
||||
[publish]
|
||||
handout = false
|
||||
solutions = true
|
22
src/Advanced/Generating Functions/main.tex
Executable file
@ -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}
|
6
src/Advanced/Generating Functions/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Generating Functions"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
107
src/Advanced/Generating Functions/parts/00 introduction.tex
Executable file
@ -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{}<xminusone>
|
||||
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
|
168
src/Advanced/Generating Functions/parts/01 fibonacci.tex
Executable file
@ -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{}<fibo>
|
||||
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<fibo> 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{}<pfd>
|
||||
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
|
102
src/Advanced/Generating Functions/parts/02 dice.tex
Executable file
@ -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
|
102
src/Advanced/Generating Functions/parts/03 coins.tex
Executable file
@ -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{}<pcoins>
|
||||
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
|
251
src/Advanced/Geometric Optimization/main.tex
Executable file
@ -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{}<simtri>
|
||||
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{}<equi>
|
||||
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{}<equi2>
|
||||
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}
|
6
src/Advanced/Geometric Optimization/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Geometric Optimization"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = false
|
BIN
src/Advanced/Geometry of Masses/img/arc.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
src/Advanced/Geometry of Masses/img/pappus_1.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
src/Advanced/Geometry of Masses/img/right_isos.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
src/Advanced/Geometry of Masses/img/seahorse.jpg
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
src/Advanced/Geometry of Masses/img/soda.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
src/Advanced/Geometry of Masses/img/soda_filled.png
Normal file
After Width: | Height: | Size: 11 KiB |
34
src/Advanced/Geometry of Masses/main.tex
Executable file
@ -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}
|
6
src/Advanced/Geometry of Masses/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Geometry of Masses"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = false
|
200
src/Advanced/Geometry of Masses/parts/0 balance 1d.tex
Normal file
@ -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{}<fakeunits>
|
||||
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{}<massline>
|
||||
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
|
155
src/Advanced/Geometry of Masses/parts/1 balance 2d.tex
Normal file
@ -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
|
136
src/Advanced/Geometry of Masses/parts/1 continuous.tex
Normal file
@ -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{}<rightiso>
|
||||
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
|
95
src/Advanced/Geometry of Masses/parts/2 pappus.tex
Normal file
@ -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{}<sector>
|
||||
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.
|
||||
|
28
src/Advanced/Graph Algorithms/main.tex
Executable file
@ -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}
|
6
src/Advanced/Graph Algorithms/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Graph Algorithms"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
58
src/Advanced/Graph Algorithms/parts/00 review.tex
Executable file
@ -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
|
351
src/Advanced/Graph Algorithms/parts/01 flow.tex
Executable file
@ -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
|
211
src/Advanced/Graph Algorithms/parts/02 residual.tex
Executable file
@ -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{}<FindResidual>
|
||||
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
|
123
src/Advanced/Graph Algorithms/parts/03 fulkerson.tex
Executable file
@ -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
|
188
src/Advanced/Graph Algorithms/parts/04 applications.tex
Executable file
@ -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
|
123
src/Advanced/Graph Algorithms/parts/05 reductions.tex
Executable file
@ -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{}<IndepCover>
|
||||
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
|
131
src/Advanced/Graph Algorithms/parts/06 bonus.tex
Normal file
@ -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
|
57
src/Advanced/Graph Algorithms/tikxset.tex
Normal file
@ -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
|
||||
}
|
||||
}
|
339
src/Advanced/Intro to Proofs/main.tex
Executable file
@ -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}<divalgo>
|
||||
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}
|
6
src/Advanced/Intro to Proofs/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Intro to Proofs"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = false
|
38
src/Advanced/Introduction to Quantum/Tectonic.toml
Normal file
@ -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"
|
||||
]
|
29
src/Advanced/Introduction to Quantum/main.tex
Executable file
@ -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}
|
6
src/Advanced/Introduction to Quantum/meta.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[metadata]
|
||||
title = "Quantum Computing"
|
||||
|
||||
[publish]
|
||||
handout = true
|
||||
solutions = true
|
54
src/Advanced/Introduction to Quantum/src/main.tex
Executable file
@ -0,0 +1,54 @@
|
||||
% Copyright (C) 2023 <Mark (mark@betalupi.com)>
|
||||
%
|
||||
% 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 <https://www.gnu.org/licenses/>.
|
||||
%
|
||||
%
|
||||
%
|
||||
% 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}
|
565
src/Advanced/Introduction to Quantum/src/parts/01 bits.tex
Normal file
@ -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{}<firstcompoundstate>
|
||||
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{}<basistp>
|
||||
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{}<fivequant>
|
||||
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{}<linearextension>
|
||||
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
|
347
src/Advanced/Introduction to Quantum/src/parts/02 qubit.tex
Normal file
@ -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
|
145
src/Advanced/Introduction to Quantum/src/parts/03 two qubits.tex
Normal file
@ -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}<measureii>
|
||||
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
|
@ -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{}<notgatex>
|
||||
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
|
@ -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{}<cnot>
|
||||
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{}<applycnot>
|
||||
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{}<cnotflipped>
|
||||
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
|
421
src/Advanced/Introduction to Quantum/src/parts/06 hxh.tex
Normal file
@ -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
|
195
src/Advanced/Introduction to Quantum/src/parts/07 superdense.tex
Normal file
@ -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{}<bellmeasure>
|
||||
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
|
||||
|
179
src/Advanced/Introduction to Quantum/src/parts/08 teleport.tex
Normal file
@ -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
|
||||
|
79
src/Advanced/Introduction to Quantum/src/tikzset.tex
Normal file
@ -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};
|
||||
}
|