\documentclass[11pt,a4wide]{article}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{a4wide}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[dvips]{epsfig}
\usepackage[T1]{fontenc}
\usepackage{cite} % [2,3,4] --> [2--4]
\usepackage{shadow}
\usepackage{hyperref}

\setcounter{tocdepth}{2}

\lstset{language=c++}
\lstset{alsolanguage=[90]Fortran}
\lstset{basicstyle=\small}
\lstset{backgroundcolor=\color{white}}
\lstset{frame=single}
\lstset{stringstyle=\ttfamily}
\lstset{keywordstyle=\color{red}\bfseries}
\lstset{commentstyle=\itshape\color{blue}}
\lstset{showspaces=false}
\lstset{showstringspaces=false}
\lstset{showtabs=false}
\lstset{breaklines}
\begin{document}
\section*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.
\begin{itemize}
\item Give a short description of the nature of the problem and the eventual
numerical methods you have used.
\item Describe the algorithm you have used and/or developed. Here you may find it convenient
to use pseudocoding. In many cases you can describe the algorithm
in the program itself.

\item Include the source code of your program. Comment your program properly.
\item If possible, try to find analytic solutions, or known limits
in order to test your program when developing the code.
\item Include your results either in figure form or in a table. Remember to
       label your results. All tables and figures should have relevant captions
       and labels on the axes.
\item Try to evaluate the reliabilty and numerical stability/precision
of your results. If possible, include a qualitative and/or quantitative
discussion of the numerical stability, eventual loss of precision etc.

\item Try to give an interpretation of you results in your answers to
the problems.
\item Critique: if possible include your comments and reflections about the
exercise, whether you felt you learnt something, ideas for improvements and
other thoughts you've made when solving the exercise.
We wish to keep this course at the interactive level and your comments can help
us improve it.
\item Try to establish a practice where you log your work at the
computerlab. You may find such a logbook very handy at later stages
in your work, especially when you don't properly remember
what a previous test version
of your program did. Here you could also record
the time spent on solving the exercise, various algorithms you may have tested
or other topics which you feel worthy of mentioning.
\end{itemize}

\section*{Format for electronic delivery of report and programs}
%
This project counts 1/3 of the final mark. The feedback will, in addition to our comments contain a final score, where 100 is the maximum. Project 5 counts also 1/3 of the final mark. The final exam stands for the remaining 1/3 of the final mark.
We have set up devilry so that you can use your candidate number only. Please mark your project with the candidate number. If you prefer to not use the candidate number, we will need it anyway in order to correlate with the final written exam.

The preferred format for the report is a PDF file. You can also
use DOC or postscript formats or as an ipython notebook file.
As programming language we prefer that you choose between C/C++, Fortran2008 or Python.
The following prescription should be followed when preparing the report:
\begin{itemize}
\item Use Devilry to hand in your projects, log in  at
\url{ http://devilry.ifi.uio.no} with your normal UiO username and password
and choose either 'fys3150' or 'fys4150'. This time however you should use your candidate number only. You are free to use your name as well, but we need the candidate number for the final mark.
\item You can upload the report file as well as your program files to devilry!  For the source code file(s) you have developed you can also place these at  a github domain, or eventually upload all program files to devilry.
The report file should include all of your discussions and a list of the codes you have developed.
\item You should include tests and/or unit tests of your code(s).
\item Comments  from us on your projects, with final score
will be available under
your Devilry domain and are only visible to you and the teachers of the course.

\end{itemize}

Finally, even though this project counts 1/3 of the final mark,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. You can then hand in a common report.

\section*{Project 4, numerical integration, deadline  Friday November 13}

The project deals with the Ising model in two dimensions, without an external magnetic
field. In its simplest form
the energy is expressed as
\begin{equation}
  E=-J\sum_{<kl>}^{N}s_ks_l
\end{equation}
with  $s_k=\pm 1$, $N$ is the total number of spins and
$J$ is a coupling constant expressing the strength of the interaction
between neighboring spins.
The symbol $<kl>$ indicates that we sum over nearest
neighbors only. We will assume that we have a ferromagnetic ordering, viz $J> 0$.
We will use periodic boundary conditions and the Metropolis algorithm only.
\begin{enumerate}

\item[a)] Assume we have only two spins in each dimension, that is $L=2$.
Find the closed form expression for the partition function and the corresponding
expectations values for
for $E$, $|{\cal M}|$, the specific heat $C_V$ and the susceptibility $\chi$
as functions of  $T$ using periodic boundary conditions.

\item[b)]
Write now a code for the Ising model which computes the mean energy
$E$, mean magnetization
$|{\cal M}|$, the specific heat $C_V$ and the susceptibility $\chi$
as functions of  $T$ using periodic boundary conditions for
$L=2$ in the $x$ and $y$ directions.
Compare your results with the expressions from a)
for  a  temperature $T=1.0$ (in units of $kT/J$).

How many Monte Carlo cycles do you need in order to achieve a good agreeement?

\item[c)]

We choose now a square lattice with $L=20$ spins in the $x$ and $y$ directions.

In [b) we did not study carefully how many Monte Carlo cycles were needed in order to reach the most likely state. Here
we want to perform a study of the time (here it corresponds to the number
of Monte Carlo cycles) one needs before one reaches an equilibrium situation
and can start computing various expectations values. Our
first attempt is a rough and plain graphical
one, where we plot various expectations values as functions of the number of Monte Carlo cycles.

Choose first a temperature of $T=1.0$ (in units of $kT/J$) and study the
mean energy and magnetisation (absolute value) as functions of the number of Monte Carlo cycles.
Use both an ordered (all spins pointing in one direction) and a random
spin orientation as starting configuration.
How many Monte Carlo cycles do you need before you reach an equilibrium situation?
Repeat this analysis for $T=2.4$.

Make also a plot of the total number of accepted configurations
as function of the total number of Monte Carlo cycles. How does the number of
accepted configurations behave as function of temperature $T$?

\item[d)] Compute thereafter the probability
$P(E)$ for the previous system with $L=20$ and the same temperatures.
You compute this probability by simply counting the number of times a
given energy appears in your computation. Start the computation after
the steady state situation has been reached.
Compare your results with the computed variance in energy
$\sigma^2_E$ and discuss the behavior you observe.
\end{enumerate}

Near $T_C$ we can characterize the behavior of many physical quantities
by a power law behavior.
As an example the mean magnetization is given by
\begin{equation}
  \langle {\cal M}(T) \rangle \sim \left(T-T_C\right)^{\beta},
\end{equation}
where $\beta=1/8$ is a so-called critical exponent. A similar relation
applies to the heat capacity
\begin{equation}
  C_V(T) \sim \left|T_C-T\right|^{\alpha},
\end{equation}
and the susceptibility
\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{\gamma},
\end{equation}
with $\alpha = 0$ and $\gamma = 7/4$.
Another important quantity is the correlation length, which is expected
to be of the order of the lattice spacing for $T>> T_C$. Because the spins
become more and more correlated as $T$ approaches $T_C$, the correlation
length increases as we get closer to the critical temperature. The divergent
behavior of $\xi$ near $T_C$
is
\begin{equation}
  \xi(T) \sim \left|T_C-T\right|^{-\nu}.
  \label{eq:xi}
\end{equation}
A second-order phase transition is characterized by a
correlation length which spans the whole system.
Since we are always limited to a finite lattice, $\xi$ will
be proportional with the size of the lattice.
Through so-called finite size scaling relations
it is possible to relate the behavior at finite lattices with the
results for an infinitely large lattice.
The critical temperature scales then as
\begin{equation}
 T_C(L)-T_C(L=\infty) = aL^{-1/\nu},
 \label{eq:tc}
\end{equation}
with  $a$ a constant and  $\nu$ defined in Eq.~(\ref{eq:xi}).
We set $T=T_C$ and obtain a mean magnetisation
\begin{equation}
  \langle {\cal M}(T) \rangle \sim \left(T-T_C\right)^{\beta}
  \rightarrow L^{-\beta/\nu},
  \label{eq:scale1}
\end{equation}
a heat capacity
\begin{equation}
  C_V(T) \sim \left|T_C-T\right|^{-\gamma} \rightarrow L^{\alpha/\nu},
  \label{eq:scale2}
\end{equation}
and susceptibility
\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{-\alpha} \rightarrow L^{\gamma/\nu}.
  \label{eq:scale3}
\end{equation}

\begin{enumerate}
\item [e)]  We wish to study the behavior of the Ising model in two dimensions close to the
critical temperature as a function of the lattice size $L\times L$.
Calculate the expectation values
for $\langle E\rangle$ and $\langle |{\cal M}|\rangle$,
the specific heat $C_V$ and the susceptibility $\chi$
as functions  of $T$ for $L=20$, $L=40$, $L=60$ and $L=80$ for $T\in [2.0,2.4]$
with a step in temperature $\Delta T=0.05$ or smaller.
Plot  $\langle E\rangle$, $\langle 1{\cal M}1\rangle$, $C_V$ and $\chi$
as functions of $T$. Can you see an indication of a phase transition?

Use the absolute value $\langle |{\cal M}|\rangle$ when you evaluate $\chi$.

You should parallelize the code using either OpenMP or MPI.
\item[f)]  Use Eq.~(\ref{eq:tc}) and the exact result
$\nu=1$ in order to estimate $T_C$ in the thermodynamic limit $L\rightarrow \infty$
using your simulations with $L=20$, $L=40$, $L=60$ and $L=80$
The exact result for the critical temperature (after Lars Onsager) is
$kT_C/J=2/ln(1+\sqrt{2})\approx 2.269$ with $\nu=1$.
\end{enumerate}

\section*{Background literature}
If you wish to read more about the Ising model and statistical physics here are two suggestions.
\begin{enumerate}
\item M.~Plischke and B.~Bergersen, Equilibrium Statistical Physics,
Prentice-Hall, see chapters 5 and 6.
\item M.~E.~J.~Newman and T.~Barkema, Monte Carlo methods in statistical physics, Oxford, see chapters 3 and 4.

\end{enumerate}
\end{document}


%!TEX root = forallxsol.tex
%\part{Truth-functional logic}
%\label{ch.TFL}
%\addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}

\stepcounter{chapter} % first steps

\chapter{Connectives}\setcounter{ProbPart}{0}
\problempart Using the symbolization key given, symbolize each English sentence in TFL.\label{pr.monkeysuits}
	\begin{ekey}
		\item[M] Those creatures are men in suits.
		\item[C] Those creatures are chimpanzees.
		\item[G] Those creatures are gorillas.
	\end{ekey}
\begin{earg}
\item Those creatures are not men in suits.
\item[] \myanswer{$\enot M$}
\item Those creatures are men in suits, or they are not.
\item[] \myanswer{$(M \eor \enot M$)}
\item Those creatures are either gorillas or chimpanzees.
\item[] \myanswer{$(G \eor C)$}
\item Those creatures are neither gorillas nor chimpanzees.
\item[] \myanswer{$\enot (C \eor G)$}
\item If those creatures are chimpanzees, then they are neither gorillas nor men in suits.
\item[] \myanswer{$(C \eif \enot(G \eor M))$}
\item Unless those creatures are men in suits, they are either chimpanzees or they are gorillas.
\item[] \myanswer{$(M \eor (C \eor G))$}
\end{earg}

\problempart Using the symbolization key given, symbolize each English sentence in TFL.
\begin{ekey}
\item[A] Mister Ace was murdered.
\item[B] The butler did it.
\item[C] The cook did it.
\item[D] The Duchess is lying.
\item[E] Mister Edge was murdered.
\item[F] The murder weapon was a frying pan.
\end{ekey}
\begin{earg}
\item Either Mister Ace or Mister Edge was murdered.
\item[] \myanswer{$(A \eor E)$}
\item If Mister Ace was murdered, then the cook did it.
\item[] \myanswer{$(A \eif C)$}
\item If Mister Edge was murdered, then the cook did not do it.
\item[] \myanswer{$(E \eif \enot C)$}
\item Either the butler did it, or the Duchess is lying.
\item[] \myanswer{$(B \eor D)$}
\item The cook did it only if the Duchess is lying.
\item[] \myanswer{$(C \eif D)$}
\item If the murder weapon was a frying pan, then the culprit must have been the cook.
\item[] \myanswer{$(F \eif C)$}
\item If the murder weapon was not a frying pan, then the culprit was either the cook or the butler.
\item[] \myanswer{$(\enot F \eif (C \eor B))$}
\item Mister Ace was murdered if and only if Mister Edge was not murdered.
\item[] \myanswer{$(A \eiff \enot E)$}
\item The Duchess is lying, unless it was Mister Edge who was murdered.
\item[] \myanswer{$(D \eor E)$}
\item If Mister Ace was murdered, he was done in with a frying pan.
\item[] \myanswer{$(A \eif F)$}
\item Since the cook did it, the butler did not.
\item[] \myanswer{$(C \eand \enot B)$}
\item Of course the Duchess is lying!
\item[] \myanswer{$D$}
\end{earg}

\solutions

\problempart Using the symbolization key given, symbolize each English sentence in TFL.\label{pr.avacareer}
	\begin{ekey}
		\item[E_1] Ava is an electrician.
		\item[E_2] Harrison is an electrician.
		\item[F_1] Ava is a firefighter.
		\item[F_2] Harrison is a firefighter.
		\item[S_1] Ava is satisfied with her career.
		\item[S_2] Harrison is satisfied with his career.
	\end{ekey}
\begin{earg}
\item Ava and Harrison are both electricians.
\item[] \myanswer{$(E_1 \eand E_2)$}
\item If Ava is a firefighter, then she is satisfied with her career.
\item[] \myanswer{$(F_1 \eif S_1)$}
\item Ava is a firefighter, unless she is an electrician.
\item[] \myanswer{$(F_1 \eor E_1)$}
\item Harrison is an unsatisfied electrician.
\item[] \myanswer{$(E_2 \eand \enot S_2)$}
\item Neither Ava nor Harrison is an electrician.
\item[] \myanswer{$\enot (E_1 \eor E_2)$}
\item Both Ava and Harrison are electricians, but neither of them find it satisfying.
\item[] \myanswer{$((E_1 \eand E_2) \eand \enot (S_1 \eor S_2))$}
\item Harrison is satisfied only if he is a firefighter.
\item[] \myanswer{$(S_2 \eif F_2)$}
\item If Ava is not an electrician, then neither is Harrison, but if she is, then he is too.
\item[] \myanswer{$((\enot E_1 \eif \enot E_2) \eand (E_1 \eif  E_2))$}
\item Ava is satisfied with her career if and only if Harrison is not satisfied with his.
\item[] \myanswer{$(S_1 \eiff \enot S_2)$}
\item If Harrison is both an electrician and a firefighter, then he must be satisfied with his work.
\item[] \myanswer{$((E_2 \eand F_2) \eif S_2)$}
\item It cannot be that Harrison is both an electrician and a firefighter.
\item[] \myanswer{$\enot (E_2 \eand F_2)$}
\item Harrison and Ava are both firefighters if and only if neither of them is an electrician.
\item[] \myanswer{$((F_2 \eand F_1) \eiff \enot(E_2 \eor E_1))$}
\end{earg}

\problempart
Using the symbolization key given, translate each English-language sentence into TFL.
\label{pr.jazzinstruments}
\begin{ekey}
\item[J_1] John Coltrane played tenor sax.
\item[J_2] John Coltrane played soprano sax.
\item[J_3] John Coltrane played tuba
\item[M_1] Miles Davis played trumpet
\item[M_2] Miles Davis played tuba
\end{ekey}

\begin{earg}
\item John Coltrane played tenor and soprano sax.
\item[~] \myanswer{$J_1 \eand J_2$}
\item Neither Miles Davis nor John Coltrane played tuba.
\item[~] \myanswer{$\enot(M_2 \eor J_3)$ or $\enot M_2 \eand \enot J_3$}
\item John Coltrane did not play both tenor sax and tuba.
\item[~] \myanswer{$\enot(J_1 \eand J_3)$ or $\enot J_1 \eor \enot J_3$}
\item John Coltrane did not play tenor sax unless he also played soprano sax.
\item[~] \myanswer{$\enot J_1 \eor J_2$}
\item John Coltrane did not play tuba, but Miles Davis did.
\item[~] \myanswer{$\enot J_3 \eand M_2$}
\item Miles Davis played trumpet only if he also played tuba.
\item[~] \myanswer{$M_1 \eif M_2$}
\item If Miles Davis played trumpet, then John Coltrane played at least one of these three instruments: tenor sax, soprano sax, or tuba.
\item[~] \myanswer{$M_1 \eif (J_1 \eor (J_2 \eor J_3))$}
\item If John Coltrane played tuba then Miles Davis played neither trumpet nor tuba.
\item[~] \myanswer{$J_3 \eif \enot(M_1 \eor M_2)$ or $J_3 \eif (\enot M_1 \eand \enot M_2)$}
\item Miles Davis and John Coltrane both played tuba if and only if Coltrane did not play tenor sax and Miles Davis did not play trumpet.
\item[~] \myanswer{$(J_3 \eand M_2) \eiff (\enot J_1 \wedge \enot M_1)$ or $(J_3 \eand M_2) \eiff \enot (J_1 \eor M_1)$}
\end{earg}

\problempart
\label{pr.spies}
Give a symbolization key and symbolize the following English sentences in TFL.
\myanswer{\begin{ekey}
\item[A] Alice is a spy.
\item[B] Bob is a spy.
\item[C] The code has been broken.
\item[G] The German embassy will be in an uproar.
\end{ekey}}
\begin{earg}
\item Alice and Bob are both spies.
\item[] \myanswer{$(A \eand B)$}
\item If either Alice or Bob is a spy, then the code has been broken.
\item[] \myanswer{$((A \eor B) \eif C)$}
\item If neither Alice nor Bob is a spy, then the code remains unbroken.
\item[] \myanswer{$(\enot (A \eor B) \eif \enot C)$}
\item The German embassy will be in an uproar, unless someone has broken the code.
\item[] \myanswer{$(G \eor C)$}
\item Either the code has been broken or it has not, but the German embassy will be in an uproar regardless.
\item[] \myanswer{$((C \eor \enot C) \eand G)$}
\item Either Alice or Bob is a spy, but not both.
\item[] \myanswer{$((A \eor B) \eand \enot (A \eand B))$}
\end{earg}

\problempart Give a symbolization key and symbolize the following English sentences in TFL.
\myanswer{\begin{ekey}
\item[F] There is food to be found in the pridelands.
\item[R] Rafiki will talk about squashed bananas.
\item[A] Simba is alive.
\item[K] Scar will remain as king.
\end{ekey}}
\begin{earg}
\item If there is food to be found in the pridelands, then Rafiki will talk about squashed bananas.
\item[] \myanswer{$(F \eif R)$}
\item Rafiki will talk about squashed bananas unless Simba is alive.
\item[] \myanswer{$(R \eor A)$}
\item Rafiki will either talk about squashed bananas or he won't, but there is food to be found in the pridelands regardless.
\item[] \myanswer{$((R \eor \enot R) \eand F)$}
\item Scar will remain as king if and only if there is food to be found in the pridelands.
\item[] \myanswer{$(K \eiff F)$}
\item If Simba is alive, then Scar will not remain as king.
\item[] \myanswer{$(A \eif \enot K)$}
\end{earg}

\problempart
For each argument, write a symbolization key and symbolize all of the sentences of the argument in TFL.
\begin{earg}
\item If Dorothy plays the piano in the morning, then Roger wakes up cranky. Dorothy plays piano in the morning unless she is distracted. So if Roger does not wake up cranky, then Dorothy must be distracted.
\myanswer{\begin{ekey}
\item[P] Dorothy plays the Piano in the morning.
\item[C] Roger wakes up cranky.
\item[D] Dorothy is distracted.
\end{ekey}}
\item[] \myanswer{$(P \eif C)$, $(P \eor D)$, $(\enot C \eif D)$}
\item It will either rain or snow on Tuesday. If it rains, Neville will be sad. If it snows, Neville will be cold. Therefore, Neville will either be sad or cold on Tuesday.
\myanswer{\begin{ekey}
\item[T_1] It rains on Tuesday
\item[T_2] It snows on Tuesday
\item[S] Neville is sad on Tuesday
\item[C] Neville is cold on Tuesday
\end{ekey}}
\item[] \myanswer{$(T_1 \eor T_2)$, $(T_1 \eif S)$, $(T_2 \eif C)$, $(S \eor C)$}
\item If Zoog remembered to do his chores, then things are clean but not neat. If he forgot, then things are neat but not clean. Therefore, things are either neat or clean; but not both.
\myanswer{\begin{ekey}
\item[Z] Zoog remembered to do his chores
\item[C] Things are clean
\item[N] Things are neat
\end{ekey}}
\item[] \myanswer{$(Z \eif (C \eand \enot N))$, $(\enot Z \eif (N \eand \enot C))$, $((N \eor C) \eand \enot (N \eand C))$.}
\end{earg}

\problempart
For each argument, write a symbolization key and translate the argument as well as possible into TFL. The part of the passage in italics is there to provide context for the argument, and doesn't need to be symbolized.
\begin{earg}
\item It is going to rain soon. I know because my leg is hurting, and my leg hurts if it's going to rain.

%{\color{red}
%\begin{ekey}
%\item[A:]
%\item[B:]
%\item[C:]  %\end{ekey}

%begin{\earg}
%\item[1.]
%\item[2.]
%\item[$\therefore$]
%}

\item  \emph{Spider-man tries to figure out the bad guy's plan.} If Doctor Octopus gets the uranium, he will blackmail the city. I am certain of this because if Doctor Octopus gets the uranium, he can make a dirty bomb, and if he can make a dirty bomb, he will blackmail the city.

%{\color{red}
%\begin{ekey}
%\item[A:]
%\item[B:]
%\item[C:]  %\end{ekey}

%begin{\earg}
%\item[1.]
%\item[2.]
%\item[$\therefore$]
%}

\item \emph{A westerner tries to predict the policies of the Chinese government.} If the Chinese government cannot solve the water shortages in Beijing, they will have to move the capital. They don't want to move the capital. Therefore they must solve the water shortage. But the only way to solve the water shortage is to divert almost all the water from the Yangzi river northward. Therefore the Chinese government will go with the project to divert water from the south to the north.

%{\color{red}
%\begin{ekey}
%\item[A:]
%\item[B:]
%\item[C:]  %\end{ekey}

%begin{\earg}
%\item[1.]
%\item[2.]
%\item[$\therefore$]
%}

\end{earg}

\problempart
We symbolized an \emph{exclusive or} using `$\eor$', `$\eand$', and `$\enot$'. How could you symbolize an \emph{exclusive or} using only two connectives? Is there any way to symbolize an \emph{exclusive or} using only one connective?
\\\myanswer{For two connectives, we could offer any of the following:
\begin{center}
$\enot(\metav{A} \eiff \metav{B})$\\
$(\enot\metav{A} \eiff \metav{B})$\\
$(\enot (\enot \metav{A} \eand \enot \metav{B}) \eand \enot (\metav{A} \eand \metav{B}))$
\end{center}
But if we wanted to symbolize it using only one connective, we would have to introduce a new primitive connective.
}

\chapter{Sentences of TFL}\setcounter{ProbPart}{0}
\problempart
\label{pr.wiffTFL}
For each of the following: (a) Is it a sentence of TFL, strictly speaking? (b) Is it a sentence of TFL, allowing for our relaxed bracketing conventions?
\begin{earg}
\item $(A)$\hfill \myanswer{(a) no (b) no}
\item $J_{374} \eor \enot J_{374}$\hfill \myanswer{(a) no (b) yes}
\item $\enot \enot \enot \enot F$\hfill \myanswer{(a) yes (b) yes}
\item $\enot \eand S$\hfill \myanswer{(a) no (b) no}
\item $(G \eand \enot G)$\hfill \myanswer{(a) yes (b) yes}
\item $(A \eif (A \eand \enot F)) \eor (D \eiff E)$\hfill \myanswer{(a) no (b) yes}
\item $[(Z \eiff S) \eif W] \eand [J \eor X]$\hfill \myanswer{(a) no (b) yes}
\item $(F \eiff \enot D \eif J) \eor (C \eand D)$\hfill \myanswer{(a) no (b) no}
\end{earg}

\problempart
Are there any sentences of TFL that contain no atomic sentences? Explain your answer.
\\\myanswer{No. Atomic sentences contain atomic sentences (trivially). And every more complicated sentence is built up out of less complicated sentences, that were in turn built out of less complicated sentences, \ldots, that were ultimately built out of atomic sentences.}\\

\problempart
What is the scope of each connective in the sentence
$$\bigl[(H \eif I) \eor (I \eif H)\bigr] \eand (J \eor K)$$
\myanswer{The scope of the left-most instance of `$\eif$' is `$(H \eif I)$'.\\
The scope of the right-most instance of `$\eif$' is `$(I \eif H)$'.\\
The scope of the left-most instance of `$\eor$ is `$\bigl[(H \eif I) \eor (I \eif H)\bigr]$'\\
The scope of the right-most instance of `$\eor$' is `$(J \eor K)$'\\
The scope of the conjunction is the entire sentence; so conjunction is the main logical connective of the sentence.}

\stepcounter{chapter} % Ambiguity
\stepcounter{chapter} % Use and mention


%\addtocounter{chapter}{-1}
\chapter{Advice for the reader}

\section{Prerequisites}
As explained in the preface,
the main prerequisite is some amount of mathematical maturity.
This means I expect the reader to know how
to read and write a proof, follow logical arguments, and so on.

I also assume the reader is familiar with basic terminology
about sets and functions (e.g.\ ``what is a bijection?'').
If not, one should consult \Cref{ch:sets_functions}.

\section{Deciding what to read}
There is no need to read this book in linear order:
it covers all sorts of areas in mathematics,
and there are many paths you can take.
In \Cref{ch:sales}, I give a short overview for each part
explaining what you might expect to see in that part.

For now, here is a brief chart showing
how the chapters depend on each other;
again see \Cref{ch:sales} for details.
Dependencies are indicated by arrows;
dotted lines are optional dependencies.
\textbf{I suggest that you simply pick a chapter you find interesting,
and then find the shortest path.}
With that in mind, I hope the length of the entire PDF is not intimidating.

\input{tex/frontmatter/digraph}
\newpage

\section{Questions, exercises, and problems}
In this book, there are three hierarchies:
\begin{itemize}
	\ii An inline \vocab{question} is intended to be offensively easy,
	mostly a chance to help you internalize definitions.
	If you find yourself unable to answer one or two of them,
	it probably means I explained it badly and you should complain to me.
	But if you can't answer many,
	you likely missed something important: read back.
	\ii An inline \vocab{exercise} is more meaty than a question,
	but shouldn't have any ``tricky'' steps.
	Often I leave proofs of theorems and propositions as exercises
	if they are instructive and at least somewhat interesting.
	\ii Each chapter features several trickier \vocab{problems} at the end.
	Some are reasonable, but others are legitimately
	difficult olympiad-style problems.
	\gim Harder problems are marked with up to
	three chili peppers (\scalebox{0.7}{\chili}), like this paragraph.

	In addition to difficulty annotations,
	the problems are also marked by how important they are to the big picture.
	\begin{itemize}
		\ii \textbf{Normal problems},
		which are hopefully fun but non-central.
		\ii \textbf{Daggered problems},
		which are (usually interesting) results that one should know,
		but won't be used directly later.
		\ii \textbf{Starred problems},
		which are results which will be used later
		on in the book.\footnote{This is to avoid the classic
			``we are done by PSet 4, Problem 8''
			that happens in college sometimes,
			as if I remembered what that was.}
	\end{itemize}
\end{itemize}
Several hints and solutions can be found in \Cref{app:hints,app:sol}.

\begin{center}
	\includegraphics[width=14cm]{media/abstruse-goose-exercise.png}
	\\ \scriptsize Image from \cite{img:exercise}
\end{center}

% I personally find most exercises to not be that interesting, and I've tried to keep boring ones to a minimum.
% Regardless, I've tried hard to pick problems that are fun to think about and, when possible, to give them
% the kind of flavor you might find on the IMO or Putnam (even when the underlying background is different).

\section{Paper}
At the risk of being blunt,
\begin{moral}
Read this book with pencil and paper.
\end{moral}
Here's why:

\begin{center}
	\includegraphics[width=0.5\textwidth]{media/read-with-pencil.jpg}
	\\ \scriptsize Image from \cite{img:read_with_pencil}
\end{center}
You are not God.
You cannot keep everything in your head.\footnote{
	See also \url{https://usamo.wordpress.com/2015/03/14/writing/}
	and the source above.}
If you've printed out a hard copy, then write in the margins.
If you're trying to save paper,
grab a notebook or something along with the ride.
Somehow, some way, make sure you can write. Thanks.

\section{On the importance of examples}
I am pathologically obsessed with examples.
In this book, I place all examples in large boxes to draw emphasis to them,
which leads to some pages of the book simply consisting of sequences of boxes
one after another. I hope the reader doesn't mind.

I also often highlight a ``prototypical example'' for some sections,
and reserve the color red for such a note.
The philosophy is that any time the reader sees a definition
or a theorem about such an object, they should test it
against the prototypical example.
If the example is a good prototype, it should be immediately clear
why this definition is intuitive, or why the theorem should be true,
or why the theorem is interesting, et cetera.

Let me tell you a secret.  Whenever I wrote a definition or a theorem in this book,
I would have to recall the exact statement from my (quite poor) memory.
So instead I often consider the prototypical example,
and then only after that do I remember what the definition or the theorem is.
Incidentally, this is also how I learned all the definitions in the first place.
I hope you'll find it useful as well.

\section{Conventions and notations}
This part describes some of the less familiar notations and definitions
and settles for once and for all some annoying issues
(``is zero a natural number?'').
Most of these are ``remarks for experts'':
if something doesn't make sense,
you probably don't have to worry about it for now.

A full glossary of notation used can be found in the appendix.

\subsection{Natural numbers are positive}
The set $\NN$ is the set of \emph{positive} integers, not including $0$.
In the set theory chapters, we use $\omega = \{0, 1, \dots\}$
instead, for consistency with the rest of the book.

\subsection{Sets and equivalence relations}
This is brief, intended as a reminder for experts.
Consult \Cref{ch:sets_functions} for full details.

An \vocab{equivalence relation} on a set $X$ is a relation $\sim$
which is symmetric, reflexive, and transitive.
An equivalence relation partitions $X$
into several \vocab{equivalence classes}.
We will denote this by $X / {\sim}$.
An element of such an equivalence class is a
\vocab{representative} of that equivalence class.

I always use $\cong$ for an ``isomorphism''-style relation
(formally: a relation which is an isomorphism in a reasonable category).
The only time $\simeq$ is used in the Napkin is for homotopic paths.

I generally use $\subseteq$ and $\subsetneq$ since these are non-ambiguous,
unlike $\subset$.  I only use $\subset$ on rare occasions in which equality
obviously does not hold yet pointing it out would be distracting.
For example, I write $\QQ \subset \RR$
since ``$\QQ \subsetneq \RR$'' is distracting.

I prefer $S \setminus T$ to $S - T$.

The power set of $S$ (i.e.,\ the set of subsets of $S$),
is denoted either by $2^S$ or $\mathcal P(S)$.

\subsection{Functions}
This is brief, intended as a reminder for experts.
Consult \Cref{ch:sets_functions} for full details.

Let $X \taking f Y$ be a function:
\begin{itemize}
\ii By $f\pre(T)$ I mean the \vocab{pre-image}
\[ f\pre(T) \defeq \left\{ x \in X \mid f(x) \in T \right\}.  \]
This is in contrast to the $f\inv(T)$ used in the rest of the world;
I only use $f\inv$ for an inverse \emph{function}.

By abuse of notation, we may abbreviate $f\pre(\{y\})$ to $f\pre(y)$.
We call $f\pre(y)$ a \vocab{fiber}.

\ii By $f\im(S)$ I mean the \vocab{image}
\[ f\im(S) \defeq \left\{ f(x) \mid x \in S \right\}. \]
Almost everyone else in the world uses $f(S)$
(though $f[S]$ sees some use, and $f``(S)$ is often used in logic)
but this is abuse of notation,
and I prefer $f\im(S)$ for emphasis.
This image notation is \emph{not} standard.

\ii If $S \subseteq X$, then the \vocab{restriction} of $f$ to $S$
is denoted $f \restrict{S}$,
i.e.\ it is the function $f \restrict{S} \colon S \to Y$.

\ii Sometimes functions $f \colon X \to Y$
are \emph{injective} or \emph{surjective};
I may emphasize this sometimes by writing
$f \colon X \injto Y$ or $f \colon X \surjto Y$, respectively.
\end{itemize}

\subsection{Cycle notation for permutations}
\label{subsec:cycle_notation}

Additionally, a permutation on a finite set may be denoted
in \emph{cycle notation},
as described in say \url{https://en.wikipedia.org/wiki/Permutation#Cycle_notation}.
For example the notation $(1 \; 2 \; 3 \; 4)(5 \; 6 \; 7)$
refers to the permutation with
$1 \mapsto 2$, $2 \mapsto 3$, $3 \mapsto 4$, $4 \mapsto 1$,
$5 \mapsto 6$, $6 \mapsto 7$, $7 \mapsto 5$.
Usage of this notation will usually be obvious from context.

\subsection{Rings}
All rings have a multiplicative identity $1$ unless otherwise specified.
We allow $0=1$ in general rings but not in integral domains.

\textbf{All rings are commutative unless otherwise specified.}
There is an elaborate scheme for naming rings which are not commutative,
used only in the chapter on cohomology rings:

\begin{center}
	\small
	\begin{tabular}[h]{|c|cc|}
		\hline
		& Graded & Not Graded \\ \hline
		$1$ not required & graded pseudo-ring & pseudo-ring \\
		Anticommutative, $1$ not required & anticommutative pseudo-ring & N/A \\
		Has $1$ & graded ring & N/A \\
		Anticommutative with $1$ & anticommutative ring & N/A \\
		Commutative with $1$ & commutative graded ring & ring \\ \hline
	\end{tabular}
\end{center}

On the other hand, an \emph{algebra} always has $1$,
but it need not be commutative.

\subsection{Choice}
We accept the Axiom of Choice, and use it freely.

\section{Further reading}
The appendix \Cref{ch:refs} contains a list of resources I like,
and explanations of pedagogical choices that I made for each chapter.
I encourage you to check it out.

In particular, this is where you should go for further reading!
There are some topics that should be covered in the Napkin,
but are not, due to my own ignorance or laziness.
The references provided in this appendix should hopefully help partially
atone for my omissions.