\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{multicol}
\usepackage{upquote}
\usepackage{url}
\newcommand{\class}{miniHive}
\newcommand{\term}{}
\newcommand{\examnum}{Milestone 1}
\usepackage{fancyvrb}
\newcommand{\examdate}{}

\pagestyle{head}
\firstpageheader{}{}{}
\runningheader{\class}{\examnum\ - Page \thepage\ of \numpages}{}
\runningheadrule

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} r @{\extracolsep{6pt}} l}
\textbf{\class} & \\
\textbf{\term} &&\\
\textbf{\examnum} &&\\
\textbf{\examdate} &&\\
\end{tabular*}\\
\rule[2ex]{\textwidth}{2pt}

\noprintanswers

\noindent

The goal of this coding project is to build
a mini-version of Apache Hive, called {\em miniHive}\/. The first milestone is to write a query compiler that translates simple SQL queries into relational algebra. Later, we will add selection pushing to optimize the query, and then we will compile the relational algebra query into a physical query plan of MapReduce jobs.
But you are not completely on your own with this\dots

\section*{Translating SQL into Relational Algebra}

We consider simple SQL statements of the form
\begin{align*}
    &\mbox{SELECT DISTINCT } A_1, \dots, A_n\\
    &\mbox{FROM } T_1\; t_1, \dots,\; T_m t_m\\
    &\mbox{WHERE } C
\end{align*}
where
\begin{itemize}
    \item $A_1, \dots, A_n$ are attribute names,
    \item $T_1, \dots, T_m$ are  relation names,
    \item $t_1, \dots, t_n$ are optional renamings,
    \item and $C$ is a conjunction of atomic equality conditions of the form $t_i.A = t_j.B$ or $t_i.A = c$, where $c$ is a constant,  and $A$ and $B$ are attribute names.
\end{itemize}

\noindent
The first step in {\em miniHive}\/ is to translate SQL statements into relational algebra. We make use of two existing Python modules:

\begin{itemize}
    \item
We use \verb!sqlparse! to parse SQL statements.

More on this module at
\url{https://github.com/andialbrecht/sqlparse}.

\item
We use \verb!radb! to handle relational algebra statements.

More on this module at
\url{https://github.com/junyang/radb}.

This module requires Python~3.6!

\end{itemize}

\section{Material in Moodle}
\noindent
\begin{itemize}
\item
The file \verb!test_sql2ra.py! contains unit tests. Make sure your implementation passes these tests.
\end{itemize}

\section{What to Submit}

\noindent
Write and submit a module \verb!sql2ra! that takes a parsed SQL statement and performs the canonical translation into relational algebra, using the operators $\sigma$, $\pi$, $\times$, and $\rho$.

\noindent
This is how it should work when you spin up the interactive Python interpreter:

\begin{Verbatim}[frame=single]
>>>import sqlparse
>>>import radb
>>>import sql2ra
>>>
>>> sql = "select distinct name from person where gender='female'"
>>> stmt = sqlparse.parse(sql)[0]
>>>
>>> ra = sql2ra.translate(stmt)
>>>
>>> type(ra) # Important! Do not return a raw String, but a Project object.
<class 'radb.ast.Project'>
>>>
>>> print(ra)
\project_{name} (\select_{gender = 'female'} person)
\end{Verbatim}

\bigskip
\noindent
\rule{\linewidth}{0.5mm}

{\bf Remarks:}
For Milestone 1, you are not asked to find any particular optimizations to make your implementation more efficient. All you are required to provide is a correct and clean implementation.

\noindent
\rule{\linewidth}{0.5mm}

\end{document}


\documentclass[main.tex]{subfiles}
\begin{document}

\section{An overview of early inflationary models}

\marginpar{Monday\\ 2020-11-9, \\ compiled \\ \today}

The main reason to study these despite their issues is that they informed the modern viewpoint on inflation, which we will understand better after studying them.

\subsection{Old inflation}

This is a model first proposed by Guth in 1981.
The idea was to directly link inflationary dynamics to some high temperature SSB phase transition.

We consider the usual SSB potential
%
\begin{align}
V(\varphi ) = \frac{\lambda}{4} \qty(\varphi^2 - \sigma^2)^2
\,,
\end{align}
%
for a real scalar field \(\varphi \): the symmetry \(\varphi \to -\varphi \) is spontaneously broken in the vacuum for positive \(\sigma^2\).
Accounting for one-loop quantum corrections at a finite temperature \(T\), we find the effective potential
%
\begin{align}
V(\varphi , T) = V(\varphi )
+ \alpha  \varphi^2 T^2
+ \gamma (\varphi^2)^{3/2} T
+ \beta T^{4}
\,.
\end{align}

The potential is written in a funny way in order for it to still be explicitly symmetric under \(\varphi \to - \varphi \).
At high temperatures these corrections will dominate over \(V(\varphi )\); at low temperatures the most important correction will be the quadratic one in \(T\).

As the temperature decreases, beyond the minimum at \(\varphi = 0\) we get another one at \(\varphi = \pm \varphi_c\).
This minimum gets lower and lower, and at \(T = T_c\) it goes below \(\varphi (0)\), becoming the true vacuum.

\todo[inline]{Insert figure(s)}

The vacuum at \(\varphi = 0\) is called the ``false vacuum'', while the one at \(\varphi = \pm \sigma \) is called the ``true vacuum''.

Starting at a high temperature, we need to consider the energy density of radiation, which we know is given by
%
\begin{align}
\rho _r (T) = \frac{ \pi^2}{30 } g_* (T) T^{4}
\,,
\end{align}
%
together with the energy density of the scalar field, which is initially trapped at \(\varphi = 0\), so that \(\rho_0 = \lambda \sigma^{4} /4\).
Then, the first Friedmann equation will read
%
\begin{align}
H^2= \frac{8 \pi G}{3} \qty(\rho_0 + \rho _r)
\,,
\end{align}
%
ant the contribution \(\rho_0 \), which acts like an effective cosmological constant, will eventually come to dominate as the temperature decreases: when \(\rho_0 > \rho_r\) inflation starts its De Sitter phase.
As this begins, the energy density of radiation will decrease exponentially.

When the potential barrier becomes low enough, the field \(\varphi \) can undergo quantum tunneling, moving to the true vacuum.
This kind of phase transition is called a \emph{first order} phase transition, as opposed to \emph{second order} ones.\footnote{Roughly speaking, a first-order transition involves a discontinuity in the energy, while in the second-order case it is merely nondifferentiable, while remaining continuous.}

These models have the so-called \textbf{graceful exit problem}.
The transition to the true vacuum will generally take place in bubbles, which are moving in an exponentially-expanding false-vacuum background.
So, they may never meet, thus being unable to explain observations.

Also, after inflation we need reheating: this may be explained by the latent heat of the field having fallen in the true vacuum, \(\Delta V = V(0 ) - V(\sigma )\).
Still, though, this heat is trapped in the bubbles, and the universe cannot thermalize efficiently.

\subsection{New inflation}

These problems were solved by new inflation, proposed by Linde in 1982 and by Albrecht and Steinhardt in the same year.
Here, the transition becomes a \textbf{second order} one: there is no potential barrier.

During the phase transition, as the derivative \(V'' (\varphi =0)\) changes sign the field can start \emph{slow-rolling} towards its minimum.

Since there is no barrier, there is no nucleation of bubbles either.
What happens instead is described by \textbf{spinodal decomposition}: basically, there are different SSB in different domains which then inflate to encompass the universe.

What are the \textbf{problems} of new inflation?
We would like to ask for \(\expval{ \delta \varphi^2} \ll \varphi_0^2\): the fluctuations of the scalar field should be small, in order to be treated perturbatively.
This is hard to ensure. This is reflected in the scale of density perturbations, \(\delta \rho / \rho \).

For these models of inflation we find \(\delta \rho / \rho \sim \order{\lambda^{1/2}}\), where \(\lambda \) is the coupling constant between the inflaton field and the thermal bath.

Typically people considered values for \(\lambda \) between \num{.1} and \num{1}, which means (also accounting for the constant in front) we would get anisotropies of the order of 100:
way too large, since from CMB anisotropies we know that \(\delta \rho / \rho \sim \num{e-5}\).
In order to match this observational value we would need \(\lambda \sim \num{e-10}\), however this is not compatible with us being sure to have thermal equilibrium between the inflaton reheating and its thermal bath.

Thermal equilibrium and sufficiently small density perturbations seem to be in conflict with each other.

This is the reason why \textbf{chaotic inflationary models} (Linde 1983): disconnecting inflation from phase transitions.
Suppose we have a flat potential \(V(\varphi ) \equiv V_0 \).
This would lead to unending De Sitter inflation with \(- \infty < \varphi < \infty \); so instead of it we consider a roughly flat potential \(V(\varphi ) = (\lambda /4) \varphi^{4}\), with \(\lambda \ll 1\).

The constraint we need to require is that \(V(\varphi ) \lesssim M_P^{4}\), which ensures that quantum gravity corrections are not needed.
Then, we must constrain \(\varphi \) to lie between plus and minus \(M_P / \lambda^{1/4}\).
But if \(\lambda \ll 1\), \(\varphi \) will be able to attain initial values larger than the Planck mass: this allows for slow-roll inflation.

These models are called chaotic because the values of \(\varphi \) are taken to be randomly distributed, and in some regions inflation will not take place.
At the Planck time \(t = t_P\) this is required: there, \(\Delta E \Delta T \gtrsim 1\), so the potential \(V(\varphi )\) must have an uncertainty larger or equal than \(M_P\).

Now having \(\lambda \sim \num{e-10}\) is not an issue: the inflaton is not coupled, and we are fine with this.

The high temperature corrections to this potential are negligible.

As an example we consider the \textbf{Coleman-Weinberg potential}:
%
\begin{align}
V(\varphi ) = \frac{B \sigma^{4}}{2}
+ B \varphi^{4} \qty[\log \qty(\frac{\varphi^2}{\sigma^2}) - \frac{1}{2}]
\,,
\end{align}
%
a typical potential which can characterize symmetry breaking.
The peculiarity of this potential is the logarithm: it comes from the one-loop corrections for the interactions between the field and other particles.

This has a minimum at \(\varphi = \sigma \), while near the origin it is quite flat: we can approximate it as
%
\begin{align}
V(\varphi ) \approx \frac{B \sigma^{4}}{2} - \lambda \frac{\varphi^{4}}{4}
\,,
\end{align}
%
where \(\lambda = \abs{4 B \log (\varphi^2 / \sigma^2)} \approx \qty(\num{10} \divisionsymbol \num{100}) B\).

Very close to the origin, we will have \(V(\varphi ) \approx B \sigma^{4} / 2 = \const\), so
%
\begin{align}
H^2 \approx \frac{8 \pi G}{3} V(\varphi ) \approx \frac{4 \pi G}{3} B \sigma^{4}
\,.
\end{align}

In the original model of new inflation, this was considered with \(B \approx \num{e-3}\), and \(B = \frac{25}{16} \alpha^2 _{\text{GUT}}\), and \(\alpha _{\text{GUT}} = g _{\text{GUT}}^2 / 4 \pi \).

Since it pertained to a GUT, we also had \(\sigma \sim T_C \sim \SI{e15}{GeV}\), therefore the Hubble parameter is approximately given by
%
\begin{align}
H^2 \approx \frac{8 \pi }{3 M _{\text{Pl}}^2} V
\approx \frac{4 \pi }{3} B \frac{\sigma^{4}}{M _{\text{Pl}}^2}
\approx \num{e-2} \frac{\qty(\SI{e15}{GeV})^{4}}{\qty(\SI{e19}{GeV})^{2}} \approx \qty(\SI{e10}{GeV})^2
\,.
\end{align}

Do these kinds of models actually work? The first question is: can they solve the horizon problem? The number of \(e\)-folds is given by
%
\begin{align}
N = \int _{t_i}^{t_F} H \dd{t} = \int_{\varphi _i}^{\varphi _f} \frac{H}{\dot{\varphi}} \dd{\varphi }
\,,
\end{align}
%
and recalling \(3 H \dot{\varphi} \approx V' (\varphi )\), plus \(H^2= 8 \pi G V(\varphi ) /3\), we find
%
\begin{align}
N = - 8 \pi G \int_{\varphi _i}^{\varphi _f} \frac{V(\varphi )}{V'(\varphi )} \dd{\varphi }
\,.
\end{align}

Using the near-origin approximation, we get \(V'(\varphi ) \approx - \lambda \varphi^3\), so
%
\begin{align}
N &\approx  - 3 H^2 \int_{\varphi _i}^{\varphi _f} \frac{ \dd{\varphi }}{- \lambda \varphi^3}   \\
&\approx 3 \lambda^{-1} H^2 \int_{\varphi _i}^{\varphi _f} \frac{ \dd{\varphi }}{\varphi^3} = \frac{3}{2} \frac{H^2}{\lambda } \qty( \frac{1}{\varphi _i^2} - \frac{1}{\varphi_f^2})
\,.
\end{align}

When does inflation end?
We know that slow-roll holds as long as \(\abs{V''} < H^2\), so we can say that \(\varphi _f\) is determined by \(\abs{V''(\varphi _f)} \sim 10 H^2\), and we know that \(V''(\varphi ) = - 3 \lambda \varphi^2\):
therefore, \(\abs{\varphi _f} = H / \sqrt{3 \lambda }\).

If \(B \approx \num{e-3}\), this means
%
\begin{align}
\varphi _f^2 \approx \frac{3 H^2}{\lambda } \approx \qty(30 \divisionsymbol 300) H^2 \gtrsim \qty(\SI{e11}{GeV})^2
\,.
\end{align}

Then, an initial condition which works is \(\varphi _i \approx \num{e8} \divisionsymbol \SI{e9}{GeV}\).
This means that \(\varphi _i \sim H / 10\), which means that \(N \gtrsim 1000\) easily.
So, we can solve the horizon and flatness problems without issue.

However, we will see that there are indeed problems with this model.
The amplitude of the primordial fluctuations is too large, the quantum fluctuations of the inflaton are too large, invalidating the semiclassical approach.

\end{document}


\input{../common/header.tex}
\subtitle{Start programming in Python}
\date{2020-04-02}
\input{../common/title.tex}

\begin{frame}
	\tableofcontents
\end{frame}

\section{Intro}

% variables
% functions
% if, for (while)

\section{Homework assignment}

\begin{frame}[fragile]{Homework assignment}

    Write a function, which calculates the number of new infections at time $t$.

    \[
        \frac{e^{-(x-\mu)/s}} {s\left(1+e^{-(x-\mu)/s}\right)^2}
    \]

    Then use the following code to plot it:
    % TODO would be nice to prepare a jupyter notebook with widgets to adjust parameters!
\end{frame}

\end{document}


\section{Tutorial 3: Yue Handling Floats}
Yue is preparing her material for the monthly of math club. She wants to make her material interesting and easy to understand, so she utilizes many figures and tables.

Figures, tables and many other things that occupy an (often large) area of random width and height are treated as \emph{floats} in \LaTeX{}. Floats are common in today's documents, yet they cause great troubles in typesetting. In this section, we will work along with Yue to see how floats are handled in \LaTeX{}.

\subsection{Inserting Images}
To insert images in \LaTeX{}, package graphicx (loaded by the template files) is a good option. It provides the \verb=\includegraphics= that accepts the input image filename and some optional specifiers.
\begin{miniexammar}{.4\textandmarginlen}{
\includegraphics[width=\textwidth]{assets/examplelogo.jpg}
}
\begin{lstlisting}
\includegraphics[width=\textwidth]{assets/examplelogo.jpg}
\end{lstlisting}
\end{miniexammar}

Yue soon finds out that simply using this command is not a good option, because if there is not enough vertical space for the image, it will be placed on the next page, leaving a large vacant area, which is quite ugly. Also, she is unable to provide the image with a caption or to reference it.

So, Yue wraps the image with the figure environment that makes the image a \emph{figure}.
\begin{miniexammar}{.45\textandmarginlen}{
% figure with a caption cannot be placed inside a minipage, so we fake it here.
\includegraphics[width=\textwidth]{assets/examplelogo.jpg}
\begin{center}
\hypertarget{fakedcaption}{Figure 1: Example Logo}
\end{center}
Figure \hyperlink{fakedcaption}{1} shows the figure Yue uses.
}
\begin{lstlisting}
\begin{figure}
\includegraphics[width=\textwidth]{assets/examplelogo.jpg}
\caption{Example Logo}
\label{fig:example}
\end{figure}
Figure \ref{fig:example} shows the figure Yue uses.
\end{lstlisting}
\end{miniexammar}

\LaTeX{} automatically gives a number to it so that Yue is able to reference it. Note that due to implementation reasons, \verb=\label= should only be placed immediately after a \verb=\caption= lest the reference be wrong.

\subsection{Tables}
Even if using figures does require an extra environment, it is still quite simple and Yue soon becomes familiar with it. Dealing with tables, however, is more complex in \LaTeX{}.

To generate a table-like content in \LaTeX, Yue has to use special environments. tabular and array are two specific examples of them. In fact, the two environments are alike in most of the aspects, with one major difference being that array is often used in math mode.

The syntax of array and tabular resembles the one of matrix environments used by Delilah, though here Yue has to explicitly specify the column behavior.
\begin{miniexammar}{.4\textandmarginlen}{
\begin{tabular}{|c|c|}
\hline
Entry 1 & Entry 2\\
\hline
a & b\\
\hline
\end{tabular}
}
\begin{lstlisting}
\begin{tabular}{|c|c|}
\hline
Entry 1 & Entry 2\\
\hline
a & b\\
\hline
\end{tabular}
\end{lstlisting}
\end{miniexammar}

Yue doesn't quite understand what \verb=|c|c|= means, so she searches on the Internet for this. It tells her that this argument passed to tabular specifies each column. The letter c tells tabular that the contents in this column should be centered. And two other alignment specifier l and r are available for ``left'' and ``right'', respectively. The vertical bar indicates that at this place a vertical line should be inserted (c.f. The \verb=\hline= command that instructs a horizontal line to be inserted at the top of the current row)

The width of a column is determined by the width of the contents when either c,l, and r is given. Yue is able to control the width of a column by using another specifier ``p'', in which the content is left-aligned.
\begin{miniexammar}{.4\textandmarginlen}{
\begin{tabular}{|c|p{2cm}|}
\hline
Entry 1 & Entry 2\\
\hline
a & b\\
\hline
\end{tabular}
}
\begin{lstlisting}
\begin{tabular}{|c|p{2cm}|}
\hline
Entry 1 & Entry 2\\
\hline
a & b\\
\hline
\end{tabular}
\end{lstlisting}
\end{miniexammar}

When there is many columns with the same specifier, Yue can use this syntax \verb=*{num}{spe}= to repeat the specifiers, where num is the number of repetitions, and spe is the specifier.
\begin{miniexammar}{.4\textandmarginlen}{
\begin{tabular}{|*{7}{c|}}
\hline
a&a&a&a&a&a&a\\
\hline
a&a&a&a&a&a&a\\
\hline
\end{tabular}
}
\begin{lstlisting}
\begin{tabular}{|*{7}{c|}}
\hline
a&a&a&a&a&a&a\\
\hline
a&a&a&a&a&a&a\\
\hline
\end{tabular}
\end{lstlisting}
\end{miniexammar}

Yue doesn't like line-separated tables because she considers them not tidy. She wants to use space to separate contents. She can use \verb=@{\hspace{}}= between column specifiers to specify the inter-column space and use \verb=\vspace{}= immediately before \verb=\\= to add extra space before the next row.
\begin{miniexammar}{.4\textandmarginlen}{
\begin{tabular}{c@{\hspace{1cm}}cc}
a & b & b\\
a & b & b\vspace{.5cm}\\
c & d & d\vspace{.5cm}\\
\end{tabular}
}
\begin{lstlisting}
\begin{tabular}{c@{\hspace{1cm}}cc}
a & b & b\\
a & b & b\vspace{.5cm}\\
c & d & d\vspace{.5cm}\\
\end{tabular}
\end{lstlisting}
\end{miniexammar}
In fact, inside \verb=@{}= Yue can use not only spaces, but any other contents.
\begin{miniexammar}{.45\textandmarginlen}{
\begin{tabular}{c@{ <POLICE, stay away> }c}
crime scene & people \\
crime scene & people \\
\end{tabular}
}
\begin{lstlisting}
\begin{tabular}{c@{ <POLICE, stay away> }c}
crime scene & people \\
crime scene & people \\
\end{tabular}
\end{lstlisting}
\end{miniexammar}

Like the environment figure, the environment table is designed to accept a table-like content.
\begin{miniexammar}{.4\textandmarginlen}{
\begin{tabular}{cc}
a & b \\
c & d \\
\end{tabular}
\begin{center}
\hypertarget{fakedcaptiontab}{Table 1: Example Table}
\end{center}
Table \hyperlink{fakedcaptiontab}{1} shows a table.
}
\begin{lstlisting}
\begin{table}
\begin{tabular}{cc}
a & b \\
c & d \\
\end{tabular}
\caption{Example Table}
\label{tab:example}
\end{table}
Table \ref{tab:example} shows a table.
\end{lstlisting}
\end{miniexammar}

Now that Yue understands how to manipulate table-like contents in \LaTeX{}, she soon resumes to her work. At some point, she has to create a super big table that contains at least 20 columns, and she finds that it sticks out of the page. When she tries to use \verb=\small= to reduce the size of the texts, she finds that she has to copy it for every entry of the table, which means hundreds times of repetition. To control the overall style, Yue needs to give the controlling commands between the beginning of table and the beginning of tabular.

\begin{miniexammar}{.5\textandmarginlen}{
{
\scriptsize
\begin{tabular}{|*{14}{c|}}
\hline
a&a&a&a&a&a&a&a&a&a&a&a&a&a\\
\hline
a&a&a&a&a&a&a&a&a&a&a&a&a&a\\
\hline
\end{tabular}
}
}
\begin{lstlisting}
\begin{table}
\small
\begin{tabular}{|*{14}{c|}}
\hline
a&a&a&a&a&a&a&a&a&a&a&a&a&a\\
\hline
a&a&a&a&a&a&a&a&a&a&a&a&a&a\\
\hline
\end{tabular}
\end{table}
\end{lstlisting}
\end{miniexammar}

\subsection{Placement of Floats}
Yue used to use Microsoft Word, which places floats wherever the user wants to place it at. Everything had been fine since she had turned to \LaTeX for some time, but now Yue has a problem. A figure ``disappeared'' from the output. After checking her code and the output again and again, she accidentally finds that the figure appears in the next page. This really confuses her. Due to the internal algorithm of \TeX, it is technically impossible to arrange every float at where the user wants to place them. According to \textit{the \LaTeX{} Companion},
\begin{quotation}
``Floats are often problematic in the present version of \LaTeX, because the system was developed at a time when documents contained considerably less graphical material than they do today.''
\end{quotation}

Yet \LaTeX{} does give some option to allow the Yue to control the placement of a float to some extend. For a figure or table environment, Yue is able to pass to it an optional argument that specify the desired placement. There are five placement specifiers and they can be combined together in any order.
\begin{description}
\item[!] Ignores some \LaTeX{} limitation\footnote{\LaTeX{} has some limitations when it tries to place floats. For example, if the height of a float is larger than a degree of page height, then it cannot be placed at the bottom of a page.} when trying to place the float.
\item[h] Tries to place the float exactly at where the the environment is issued. If the attempt fails and no other specifier other that ! is given, the specifier will be changed to t.
\item[t] Tries to place the float at the top of the page.
\item[b] Tries to place the float at the bottom of the page.
\item[p] Tries to place the float at a float page (a page that is generated by \LaTeX{} to place floats)
\end{description}
\LaTeX{} tries to place a float according to the specifiers in the order of the above list from the top to the bottom. Generally all floats of a document can be handled properly. But should a float proves impossible to handle, the author should adjust (probably reduce) its width and height.

\subsection{Table of Floats}
As mentioned at the beginning, in Yue's material, there are many floats. She wonders if there is a way to provide a quick reference to them.

Like \verb=\tableofcontents=, \LaTeX{} provides the following two commands to print a list of all figures and a list of all tables used in a document, respectively.
\begin{verbatim}
\listoffigures and \listoftables
\end{verbatim}
The name of a float that appears on the list is defined by the caption of the float. If the captions appears to be too long, Yue can pass to caption an optional argument that will instead be shown on the list. Also, don't forget to compile the file at least twice for the lists to show properly.

\subsection{A Suggestion About Images}
Yue is suggested to use vector graph for images, as vector graph is lossless when the image is scaled along with the output file.

There are several packages that enables drawing images directly in \LaTeX{}, yet they all require great efforts. It is suggested to use modern tools to generate appropriate images (e.g. Mathematica is able to export the math plots drawn.).


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{CS 598 SM HW1}
\author{Daniel Campos}
\date{September 23rd,2020}

\usepackage{natbib}
\usepackage{graphicx}

\begin{document}

\maketitle
\section{Chebfun Approximation $x * sin(6x)$}
\subsection{$[-\pi, \pi]$ }
As you can see in \ref{fig:-pi2pi} the functions almost match perfectly. There are minor differences in some local maximas and minimas but for the most part agree heavily
\begin{figure}[h!]
\centering
\includegraphics[scale=.2]{-pi2pi.png}
\caption{Function scaled $[-\pi, \pi]$ Red is original function, blue is chebfun}
\label{fig:-pi2pi}
\end{figure}
\subsection{$[-2\pi, 2\pi]$}
As we scale the plot to $-2\pi to 2\pi$ we can start to see how the approximation is becoming less accurate at the extremes.
\begin{figure}[h!]
\centering
\includegraphics[scale=.2]{-2pi22pi.png}
\caption{Function scaled $[-2\pi, 2\pi]$ Red is original function, blue is chebfun}
\label{fig:-pi2pi}
\end{figure}
\subsection{Approximation error on range $[-\pi, \pi]$ }
Looking at the approximation error we can see the trend we mention in the previous subsection where error increases the further we travel from 0.
\begin{figure}[h!]
\centering
\includegraphics[scale=.2]{approxerror.png}
\caption{Approximation error  $[-\pi, \pi]$ Y axis is absolute error, X axis is function input}
\label{fig:approxerror}
\end{figure}

\section{Noisy Functions $tanh(8(x-.5)) + 10^-6*noise$}
Replace tanh with sigmoid.
\subsection{$f(x) $}
When we replace tanh with sigmoid we see similar behavior in the first equation f(x) but can approximate the equation with a lower eps value.. As show in in \ref{fig:-3f} we are able to approximate most of the function with a low eps of 1e-3 and fully match the function with an eps of 1e-9 \ref{fig:-9f}. Moreover, unlike the original f(x), our sigmoid f(x) is able to converge even without the use of eps.
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{fnone.png}
\caption{No eps}
\label{fig:fnone}
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[scale=.5]{-3f.png}
\caption{eps 1e-3}
\label{fig:-3f}
\end{figure}

\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-6f.png}
\caption{eps 1e-6}
\label{fig:-6f}
\end{figure}

\begin{figure}[h!]
\centering
\includegraphics[scale=0.5]{-9f.png}
\caption{eps 1e-9}
\label{fig:-9f}
\end{figure}

\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-12f.png}
\caption{eps 1e-12}
\label{fig:-12f}
\end{figure}

\subsection{$g(x) $}
For g(x) the use of sigmoid behaves much more like the example. With any eps of 1e-3 \ref{fig:-3g} we are unable to capture much of the original function. As we scale the eps we start to capture more of the original function but completely miss the steep drop off around 300 degrees \ref{fig:-9g}. When we scale to 1e-12 we are finally able to capture the drop off in the noisy function in an accurate way.
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{gnone.png}
\caption{No Eps}
\label{fig:gnone}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-3g.png}
\caption{eps 1e-3}
\label{fig:-3g}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-6g.png}
\caption{eps 1e-6}
\label{fig:-6g}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-9g.png}
\caption{eps 1e-9}
\label{fig:-9g}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=.5]{-12g.png}
\caption{eps 1e-12}
\label{fig:-12g}
\end{figure}
\section{Discussion}
This framework can be used to approximate numerical functions that can be expensive and approximation works well like a log function. Since most of these functions tend to saturate and the cost of computing the full values can be very expensive especially if we only need to understand the curve. Obviously just like anything that can have a fractal nature the closer we look(more sample points on the curve) the greater the error will be. \\
We can expect to have problems where the noise introduced is either quite jagged or the nature of the function does not matched the curved shape as Polynomial interpolation(which Chebyshev points are used for) is useful for dense curved data. If we are looking at some kind of data that only has a curve with some type of higher dimension transformation(like much of the data used for machine learning) Chebyshev point are likely to produce bad approximations.
\end{document}


\documentclass[aps,prl,reprint,groupedaddress, showpacs]{revtex4-1}

\usepackage{graphicx}

\begin{document}

% Use the \preprint command to place your local institutional report
% number in the upper righthand corner of the title page in preprint mode.
% Multiple \preprint commands are allowed.
% Use the 'preprintnumbers' class option to override journal defaults
% to display numbers if necessary
\preprint{Demo Paper}

%Title of paper
\title{Demonstration of Scale Invariance at the Critical Point}

\author{Douglas J. Ashton}
\email[]{douglas.j.ashton@gmail.com}
\homepage[]{www.dougashton.net}
%\thanks{}
%\altaffiliation{}
\affiliation{Mango Solutions}

\date{\today}

\begin{abstract}
Critical point phenomena, such as scale invariance, and universality, can be difficult concepts to learn. Partly because it is difficult to visualise. The two dimensional Ising model is a very useful model to illustrate some of these behaviours due to its simplicity. This paper presents large scale, real space simulations of $ \tilde 10^10 $ lattice sites using a slightly modified Wolff algorithm. The configurations generated give a tangible demonstration of scale invariance.
\end{abstract}

% insert suggested PACS numbers in braces on next line
\pacs{1234}
% insert suggested keywords - APS authors don't need to do this
%\keywords{}

%\maketitle must follow title, authors, abstract, \pacs, and \keywords
\maketitle

% body of paper here - Use proper section commands
% References should be done using the \cite, \ref, and \label commands
\section{Introduction}{\label{sec-intro}}
% Put \label in argument of \section for cross-referencing
%\section{\label{}}
%\subsection{Introduction}

Most phase transitions are due to a competition between energy and entropy. On the one hand attractive forces want to pull particles together, and on the other entropy drives the particles to explore more configurations. This balance between energy and entropy is bourne out in the free energy, which may look like the following.

\begin{equation}
F = E - S k_B T
\end{equation}
where $E$ is the internal energy, $S$ the entropy, and $k_B T$ the temperature. High temperature favours entropy, low temperature favours energy.

A first order phase transition occurs when there is a discontinuity in the free energy with respsect to the order parameter. In a liquid-gas transition the order parameter is density. At the point of the discontinuity two very different phases, a high density liquid and a low density gas, have the same free energy and they can co-exist on either side of a phase boundary.

If we heat things up the boundary between the two begins to weaken and fluctuations between the phases grow stronger and stronger. At the critical point the fluctuations diverge. This is also known as a continuous phase, or second order, transition because there is no jump in free energy between the phases.

%% Maybe drop everything above and start below?

The behaviour of a material around its critical point is one of the strangest, and most beautiful results in statistical physics. The divergence in fluctuations creates a scale invariance with no length scale taking priority. This means that the details of what the liquid, or magnet, or other material, are made from becomes less important. The physics is instead driven by much simpler things such as dimensionality and symmtery. Thanks to this universality the critical point is one area where a simple model can produce exact results.

The theory of critical phenomena becomes quickly quite abstract making it difficult for students to gain a good intuition for the basic physical effect. In this paper we aim to demonstrate important consequences of scale invariance using a massive scale, real space simulation of the Ising model at its critical point. For this we use a modified version of the Wolff algorithm, designed to minimise the use of memory.

The paper is organised as follows: In the next section we present the model and simulation method and in the final section we show some key results.

\begin{figure}
\includegraphics[width=\columnwidth]{data/swolff0000.png}
\caption{\label{fig-config} what}
\end{figure}

\section{Method\label{sec-method}}

\subsection{Ising Model}

The simplest model for system with attraction and randomness is the Ising model. The spin $\frac{1}{2}$ Ising model has spins arranged on a lattice able to point up ($\sigma = 1$), or down ($\sigma = -1$. In Fig. \ref{fig-config} these are shown with black or white pixels. The energy prefers spins to line up:

\begin{equation}
E = -J \sum_{i, j} \sigma_i \sigma_j
\end{equation}
where the sum is over all neighbouring pairs.

The two dimensional Ising model is the classic model to demonstrate critical phenomena. While it has been solved analytically in zero field CITE it is also useful for testing theories such as the renormalisation group CITE and demonstrating behaviour such as scale invariance CITE.

\subsection{Simulation Method}

Blah blah Wolff.

\section{Results\label{sec-results}}

Results

\begin{figure}
\includegraphics[width=\columnwidth]{fig-density}
\caption{\label{fig-density} what}
\end{figure}

\begin{figure}
\includegraphics[width=\columnwidth]{fig-clusters}
\caption{\label{fig-clusters} what}
\end{figure}

% If in two-column mode, this environment will change to single-column
% format so that long equations can be displayed. Use
% sparingly.
%\begin{widetext}
% put long equation here
%\end{widetext}

% figures should be put into the text as floats.
% Use the graphics or graphicx packages (distributed with LaTeX2e)
% and the \includegraphics macro defined in those packages.
% See the LaTeX Graphics Companion by Michel Goosens, Sebastian Rahtz,
% and Frank Mittelbach for instance.
%
% Here is an example of the general form of a figure:
% Fill in the caption in the braces of the \caption{} command. Put the label
% that you will use with \ref{} command in the braces of the \label{} command.
% Use the figure* environment if the figure should span across the
% entire page. There is no need to do explicit centering.

% \begin{figure}
% \includegraphics{}%
% \caption{\label{}}
% \end{figure}

% Surround figure environment with turnpage environment for landscape
% figure
% \begin{turnpage}
% \begin{figure}
% \includegraphics{}%
% \caption{\label{}}
% \end{figure}
% \end{turnpage}

% tables should appear as floats within the text
%
% Here is an example of the general form of a table:
% Fill in the caption in the braces of the \caption{} command. Put the label
% that you will use with \ref{} command in the braces of the \label{} command.
% Insert the column specifiers (l, r, c, d, etc.) in the empty braces of the
% \begin{tabular}{} command.
% The ruledtabular enviroment adds doubled rules to table and sets a
% reasonable default table settings.
% Use the table* environment to get a full-width table in two-column
% Add \usepackage{longtable} and the longtable (or longtable*}
% environment for nicely formatted long tables. Or use the the [H]
% placement option to break a long table (with less control than
% in longtable).
% \begin{table}%[H] add [H] placement to break table across pages
% \caption{\label{}}
% \begin{ruledtabular}
% \begin{tabular}{}
% Lines of table here ending with \\
% \end{tabular}
% \end{ruledtabular}
% \end{table}

% Surround table environment with turnpage environment for landscape
% table
% \begin{turnpage}
% \begin{table}
% \caption{\label{}}
% \begin{ruledtabular}
% \begin{tabular}{}
% \end{tabular}
% \end{ruledtabular}
% \end{table}
% \end{turnpage}

% Specify following sections are appendices. Use \appendix* if there
% only one appendix.
%\appendix
%\section{}

% If you have acknowledgments, this puts in the proper section head.
%\begin{acknowledgments}
% put your acknowledgments here.
%\end{acknowledgments}

% Create the reference section using BibTeX:
%\bibliography{basename of .bib file}

\end{document}
%
% ****** End of file apstemplate.tex ******


\documentclass[12pt]{article}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}

\usepackage[margin=0.75in]{geometry}

\title{Rnw Files}
\author{Gaston Sanchez}
\date{\today}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\maketitle

\noindent This is a simple example on how to use Rnw files. At one time, the phrase, You've got mail, was a welcomed, even exciting notification. Our inboxes were usually empty, so we eagerly anticipated the arrival of \dots Read More.

Here's a table displayed with the R package \texttt{"xtable"}

% latex table generated in R 3.2.3 by xtable 1.8-2 package
% Tue Mar  8 17:09:30 2016
\begin{table}[ht]
\centering
\begin{tabular}{rllll}
  \hline
 &  Sepal.Length &  Sepal.Width &  Petal.Length &  Petal.Width \\
  \hline
1 & Min.   :4.300   & Min.   :2.000   & Min.   :1.000   & Min.   :0.100   \\
  2 & 1st Qu.:5.100   & 1st Qu.:2.800   & 1st Qu.:1.600   & 1st Qu.:0.300   \\
  3 & Median :5.800   & Median :3.000   & Median :4.350   & Median :1.300   \\
  4 & Mean   :5.843   & Mean   :3.057   & Mean   :3.758   & Mean   :1.199   \\
  5 & 3rd Qu.:6.400   & 3rd Qu.:3.300   & 3rd Qu.:5.100   & 3rd Qu.:1.800   \\
  6 & Max.   :7.900   & Max.   :4.400   & Max.   :6.900   & Max.   :2.500   \\
   \hline
\end{tabular}
\end{table}

Example of a code chunk:
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# two vectors}
\hlstd{x} \hlkwb{<-} \hlnum{1}\hlopt{:}\hlnum{10}
\hlstd{y} \hlkwb{<-} \hlstd{x}\hlopt{*}\hlnum{2} \hlopt{+} \hlnum{5}
\end{alltt}
\end{kframe}
\end{knitrout}

Here's an example of inline code chunk using \texttt{\textbackslash Sexpr\{\}}: the mean value of \texttt{y} is 16, the median of \texttt{y} is 16, and its length is 10

\section{Plot}

More lines
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot}\hlstd{(x, y)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/plot1-1}

\end{knitrout}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Beamer Presentation
% LaTeX Template
% Version 1.0 (10/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
% Modified by Jeremie Gillet in November 2015 to make an OIST Skill Pill template
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	PACKAGES AND THEMES
%----------------------------------------------------------------------------------------

\documentclass{beamer}

\mode<presentation> {

\usetheme{Madrid}

\definecolor{OISTcolor}{rgb}{0.65,0.16,0.16}
\usecolortheme[named=OISTcolor]{structure}

%\setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line
%\setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line

\setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line
}

\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{textpos} % Use for positioning the Skill Pill logo
\usepackage{fancyvrb}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{subfig}
%\usepackage{enumitem}
%\usepackage{calc}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=python,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

\newcommand*{\lstitem}[1]{
  \setbox0\hbox{\lstinline{#1}}
  \item[\usebox0]
  % \item[\hbox{\lstinline{#1}}]
  \hfill \\
}

%----------------------------------------------------------------------------------------
%	TITLE PAGE
%----------------------------------------------------------------------------------------

\title[Skill Pill]{Skill Pill: Julia} % The short title appears at the bottom of every slide, the full title is only on the title page
\subtitle{Lecture 2: Data Processing and Plotting}

\author{Ankur Dhar \& James Schloss} % Your name
\institute[OIST] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{
	\textit{ankurd@oist.jp} \\ % Your institution for the title page
	\textit{james.schloss@oist.jp} % Your email address
}
\date{July 12, 2019} % Date, can be changed to a custom date

\begin{document}

\setbeamertemplate{background}{\includegraphics[width=\paperwidth]{SPbackground.png}} % Adding the background logo

\begin{frame}
\vspace*{1.4cm}
\titlepage % Print the title page as the first slide
\end{frame}

\setbeamertemplate{background}{} % No background logo after title frame

\addtobeamertemplate{frametitle}{}{% Adding the Skill Pill logo on the title screen after title frame
\begin{textblock*}{100mm}(.92\textwidth,-0.9cm)
\includegraphics[height=0.85cm]{julia.pdf}
\end{textblock*}}

\begin{frame}
  \tableofcontents
\end{frame}
\section{Arrays}
\begin{frame}[fragile]{Creating Arrays}
	Arrays in Julia are defined very similarly to arrays in Matlab, using square brackets to denote them. By default arrays are row vectors, but can be transposed to column vectors.
	\begin{lstlisting}
	julia> x = [1 2 3 4]
	julia> y = collect(1:4)
	julia> z=[1;2;3;4]
	julia> w=x'
	julia> array = Int64[]
	\end{lstlisting}
	In addition sequences of numbers can be generated using the \verb|:| operator (start:step:end). To see all these values expanded out you will need to print them manually or use the \verb|collect| function.
\end{frame}

\begin{frame}[fragile]{Array Generation Functions}
	\begin{description}[leftmargin=*]
		\item[zeros(S)] Makes an array of size S filled with zeros
		\item[ones(S)]  Makes an array of size S filled with ones
		\item[repeat(A,c,r)] Repeats array A column-wise c times and row-wise r times
		\item[rand(S)] Generates array of size S with random numbers between 0 and 1
		\item[Type\textbf{[]}] Creates empty array of type Type
	\end{description}

\end{frame}

\begin{frame}[fragile]{Array Operations}
	Arrays can be indexed by using square brackets after the array. For multidimensional arrays, the first dimension is the row, followed by column and so on. Output of indexing arrays is by default a column. This is crucial when it comes to multiplying arrays by each other.
	\begin{lstlisting}
	julia> data=rand(50,50)
	julia> rowdata=data[1,:]
	julia> inner = x*y
	julia> outer = y*x
	julia> square = x.*x
	\end{lstlisting}
	To execute scaler operations on an array, you can use append a \verb|.| to the operator. This is also applicate to functions which acts on scalars as well.
\end{frame}

\section{Data Handling}

\begin{frame}[fragile]{File Structure}
	To begin working with files, you must know where your working directory is. When launching Julia from an application menu (Windows/MacOS), the default directory is predefined. For Linux it will be the home directory.
	\begin{lstlisting}
	julia> pwd()
	julia> cd("C:\\Users\\M\\Documents\\JuliaStuff")
	julia> readdir()
		\end{lstlisting}
	You can use \verb|pwd()| to print your working directory, and \verb|cd()| to change it to whichever new directory you would like.	Once you are in the directory you want, you can list the files within using \verb|readdir()|.
\end{frame}

\begin{frame}[fragile]{Writing Scripts}
	As we start to get into more complex commands and chain them together, we can use scripts to automatically execute a series of commands at once. To include these commands into the REPL, we simply use the \verb|include()| command
	\begin{lstlisting}
	julia> include("Lesson 2.jl")
	julia> randflips[1];
	\end{lstlisting}
	To help debug in these scripts, you can suppress the direct output from any commands with a \verb|;|, and forcibly print values using \verb|print()| or \verb|println|.
\end{frame}

\begin{frame}[fragile]{Delimited text}
	The simplest data files are often delimited text files or CSV files, which can be manipulated like any other variable in Julia. To load any general delimited file, load the DelimitedFiles package. Reading in these files will automatically generate 1D or 2D arrays depending on the data being read in.
	\begin{lstlisting}
	julia> using DelimitedFiles
	julia> randData=readdlm("Random.txt")
	julia> writedlm(randData,"Random.csv")
	\end{lstlisting}
	Similarly, any 1D or 2D can be written to a file, with the actual delimiter being based on the file extension used (txt for space and csv for comma).
\end{frame}

\begin{frame}[fragile]{CSV files}
	Typical CSV files are a bit more complex than standard delimited files, with headers or labels. For this use case the CSV package is recommended. When reading in a file, the first row will be taken as the header row, but this can be explicitly defined.
	\begin{lstlisting}
	julia> using CSV
	julia> data = CSV.read("simplemaps-worldcities-basic.csv")
	julia> names(data)
	julia> populations = data[:pop]
	\end{lstlisting}
	Once read in, the labels along the header row can also be used to reference each column of data, so numeric indexing is not not necessary.
\end{frame}

\begin{frame}[fragile]{Exercises}
	\begin{block}{Exercise 1}
		Creates a file \verb|squares.txt| consisting of the first 5 square numbers
	\end{block}
	\begin{block}{Exercise 2}
		Write a script which creates a new file called \verb|large_cities.txt|.
		The file should contain one line for each of the cities which have a
		population larger than 10,000,000., formatted as follows:\\
		Buenos Aires, Argentina: population 11862073\\
		Sao Paulo, Brazil: population 14433147.5\\
		...
	\end{block}
\end{frame}

\section{Plotting}
\begin{frame}[fragile]{Plots in a Nutshell}
	\begin{columns}
		\column{.6\linewidth}
			To start with, let's add and load the general Plots package
		\begin{lstlisting}
		(v1.1) pkg> add Plots
		julia> using Plots
		julia> plot(Plots.fakedata(50))
		\end{lstlisting}
		This will let us call the general Plot commands, in this case \verb|plot| plots 1D data as a line plot.

		More information can be found at \url{https://docs.juliaplots.org/latest/}
		\column{.4\linewidth}
		\begin{figure}
			\centering
			\includegraphics[width=\textwidth]{randPlot}
		\end{figure}
	\end{columns}
\end{frame}

\begin{frame}[fragile]{Plotting Commands}
	\begin{description}[leftmargin=*,align=right]
		\item[scatter(X,Y)] Scatter plot data with XY coordinates
		\item[bar(x,y)] Bar plot following similar rules to plot
		\item[histogram(x,bins=n)] Plots histogram of 1D data in n bins.
		\item[plot($\theta$,r,proj=:polar)] Polar plot of data following r and $\theta$
		\item[heatmap(x,y,z)] Plots heatmap following XY axes with intensity array z
		\item[fakedata(L,S)] Generates random S numbers of series data of length L
		\item[savefig(filename)] Saves a generated plot as an image file
	\end{description}

\end{frame}

\begin{frame}[fragile]{Plotting 3D Data}
%%TODO include heatmap, surf, and contour
	\begin{columns}
		\column{.6\textwidth}
		There are a couple of additional options for plotting 3D data:
		\begin{description}[align=right]
			\item[surface(x,y,z)] Draws surface in 3D space
			\item[contour(x,y,z)] Draws contours on 2D plane
		\end{description}
		The plotting commands \verb|plot|,\verb|scatter|,\verb|bar|, and \verb|heatmap| also can accept 3D data.
		\column{.4\textwidth}
		\begin{figure}
			\centering
			\includegraphics[width=\textwidth]{surf}
		\end{figure}
	\end{columns}
\end{frame}

\begin{frame}[fragile]{Plotting Vector Data}
	\begin{columns}
	\column{.5\textwidth}
	For vector data the current option is quiver:
	\begin{lstlisting}
	help?> quiver
	search: quiver quiver!

	quiver(x,y,quiver=(u,v))
	quiver!(x,y,quiver=(u,v))

	Make a quiver (vector field) plot. The ith vector extends from (x[i],y[i]) to (x[i] + u[i], y[i] + v[i]).
	\end{lstlisting}
	\column{.5\textwidth}
	\begin{figure}
		\centering
		\includegraphics[width=\textwidth]{quiver}
	\end{figure}
\end{columns}

\end{frame}

\begin{frame}[fragile]{Plotting Backends}
	\begin{columns}
	\column{.5\linewidth}
	These commands are agnostic to the plotting backend, meaning they will work with a number of plotting engines in similar fashion. Each backend has pros and cons, but most commonly used are GR and PyPlot.

	\begin{figure}[h]
		\centering
		\includegraphics[width=.8\textwidth]{randPlotPy}
		\caption{PyPlot}
	\end{figure}

	\column{.5\linewidth}
	\begin{figure}[h]
		\centering
		\includegraphics[width=.8\textwidth]{randPlotPGF}
		\caption{PGFPlots}
	\end{figure}
	\vspace{-11mm}
	\begin{figure}[h]
		\centering
		\includegraphics[width=.8\textwidth]{randPlotUni}
		\caption{UnicodePlots}
	\end{figure}
	\end{columns}
\end{frame}

\begin{frame}[fragile]{Formatting Commands}
Each of these commands can be expressed in-line with the plotting command or beforehand within a call to the plotting backend.
\begin{description}[leftmargin=*,align=right]
	\item[font(fontname,size)] Defines a Font object with a given size
	\item[size=(X,Y)] Sets size of plot to X by Y pixels
	\item[xlabel=string] Sets X-Y labels to string, also ylabel
	\item[title=string] Sets title to string, also colorbar\_title for heatmap.
	\item[xtickfont=font] Sets the font of x tick marks, also ytickfont,titlefont,guidefont
	\item[left\_margin=length] Sets margin for left side of plot, also top\_margin, bottom\_margin, and right\_margin
	\item[xscale=:log10] Sets x scale to log10, also yscale
\end{description}

\end{frame}

\begin{frame}[fragile]{Exercises}
	\begin{block}{Exercise 3}
		Read data.txt given in the Public Folder and plot the results.
		What do you see?
	\end{block}
	\begin{block}{Exercise 4}
		Plot a histogram of the longitudes of the world's cities. What is the mean and median longitude?
\end{block}

\end{frame}

\begin{frame}{What is next?}
  \begin{description}
    \item[Last Session] Problem Sets with James
    \item[Also next week] Advanced Topics with Valentin!
  \end{description}
\end{frame}
%\begin{frame}[fragile]{Using Fortran and C in Julia}
%
%	Julia allows you to use other languages (such as Fortran or C) by using the \texttt{ccall} function:
%
%	\begin{lstlisting}
%	julia> t = ccall((:clock, "libc"), Int32, ())
%	2292761
%	\end{lstlisting}
%
%	Here, we are calling the \texttt{clock} function from the \texttt{libc} library in C.
%
%\end{frame}
\end{document}