%% LaTeX2e Template by Stephen Iota (https://stepheniota.com/)
%% last updated: May 2019
\documentclass{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage[utf8]{inputenc}
%\usepackage[noadjust]{cite}
\usepackage{lipsum}
\usepackage{amsmath,amssymb,amsfonts,physics}
\usepackage{mathtools} % for boxed answers in align environments
\usepackage{graphicx} % \includegraphics{ }
\usepackage[shortlabels]{enumitem} % change labels in enum/item environments
\usepackage[dvipsnames]{xcolor} % colored links=
%\usepackage[big]{titlesec} % [small,medium,big] << controls size of *section text
%\usepackage{fancyhdr} %http://tug.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/fancyhdr.pdf
\usepackage[
	colorlinks=true,
	citecolor=green!50!black,
	linkcolor=Red,
	urlcolor=green!50!black,
	hypertexnames=false]{hyperref}
 %%%%%%%%%%%%%%%%%%
 %% New Commands %%
 %%%%%%%%%%%%%%%%%%
\newcommand{\email}[1]{\texttt{\href{mailto:#1}{#1}}}
\newcommand{\HH}[0]{\ensuremath{\mathcal{H}}}
%\newcommand{\ave}[1]{$\langle #1 \rangle$}
\renewcommand{\d}[1]{\ensuremath{\operatorname{d}\!{#1}}}

\newenvironment{question}[0]{
\vspace{2mm}
\noindent
\itshape
}

\newenvironment{solution}[0]{
\vspace{2mm}
\noindent
\textbf{Solution:}
}

%%%%%%%%%%%%%%%%%%
%% Front Matter %%
%%%%%%%%%%%%%%%%%%
%\pagenumbering{gobble} % no page numbers
\graphicspath{{figures/}} % set directory for figures
%\setcounter{section}{-1} % start with section 0
\numberwithin{equation}{section}
%%%%%%%%%%%%%
%%% Title %%%
%%%%%%%%%%%%%
\begin{document}

\begin{center}
{\Large \textsc{Statistical Mechanics}: \textbf{Problem Set 3}}
\end{center}
\vspace{.5mm}

%%%%%%%%%%
%% INFO %%
%%%%%%%%%%

\begin{tabular}{rl}
\textsc{Name}:			&		Stephen Iota (\email{siota001@ucr.edu})
\\
\textsc{Course}:		&		Physics 133 (Spring 2019), Prof.~Kuhlman
\\
\textsc{Date}:			&		\today
\end{tabular}
\vspace{2mm}

%%%%%%%%%%%%%%
%% PROBLEMS %%
%%%%%%%%%%%%%%

\noindent
Sethna problems 3.6, 3.8, 5.1 and 5.5.  All final answers are \boxed{\text{boxed}}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CONNECTING TWO MACRO SYSTEMS %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Connecting two macroscopic systems}
An isolated system with energy $E$ is composed of two macroscopic subsystems, each of fixed volume $V$ and number of particles $N$. The subsystems are weakly couples, so the sum of their energies is $E_1 + E_2 = E$. The volume of the energy surface of a system with the Hamiltonian $\mathcal{H}$ is given by
\begin{align}
\Omega(E) &= \int \frac{\d{\mathbb{P}}\d{\mathbb{Q}}}{h^{3N}} \ \delta(E - \mathcal{H}(\mathbb{P},\mathbb{Q}))
\\
					&= \int \frac{\d{\mathbb{P}_1}\d{\mathbb{Q}_1}}{h^{3N_1}}
					\frac{\d{\mathbb{P}_2}\d{\mathbb{Q}_2}}{h^{3N_2}} \
					\delta(E - (\mathcal{H}_1(\mathbb{P}_1,\mathbb{Q}_1)+\mathcal{H}_2(\mathbb{P}_2,\mathbb{Q}_2)).
					\label{omega}
\end{align}

\begin{question}
Derive the formula $\Omega(E) = \int \d{E_1} \ \Omega_1(E_1) \Omega_2(E-E_1),$ for the volume of the energy surface of the energy surface of the whole system using Dirac $\delta$-functions.
\end{question}

\begin{solution}
Beginning with the definition for the volume of the energy surface of a system with Hamiltonian $\HH$ [\ref{omega}], we insert the identity $ \int \d{E_1} \ \delta(E_1 - \HH_1) = 1$. Grouping the integrals together, we notice the definition for $\Omega(E_1)$ where the delta-function picks out $E_1 = \HH_1$. We then do the same for the next integral, where the delta-function now picks out $E - E_1 = \HH_2$.
\begin{align}
\Omega(E) &= \iiint \d{E_1} \ \delta(E_1 - \HH_1) \
				 \frac{\d{\mathbb{P}_1}\d{\mathbb{Q}_1}}{h^{3N_1}}
				 \frac{\d{\mathbb{P}_2}\d{\mathbb{Q}_2}}{h^{3N_2}} \
			 	 \delta(E - (\HH_1+\HH_2))
				 \\
			 &= \int \d{E_1}
			    \int \frac{\d{\mathbb{P}_2}\d{\mathbb{Q}_2}}{h^{3N_2}}\ \delta(E - (\HH_1+\HH_2)
				 \int \frac{\d{\mathbb{P}_1}\d{\mathbb{Q}_1}}{h^{3N_1}}\  \delta(E_1 - \HH_1)
				 \\
			 &= \int \d{E_1} \ \Omega(E_1)
			    \int \frac{\d{\mathbb{P}_2}\d{\mathbb{Q}_2}}{h^{3N_2}}\delta(E - E_1 - \HH_2)
				 \\
\Aboxed{
\Omega(E) &= \int \d{E_1} \ \Omega(E_1) \ \Omega(E - E_1)
}
\end{align}
\end{solution}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MICROCANONICAL ENERGY FLUCT %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Microcanonical energy fluctuations}
For two subsystems with energy $E_1$ and $E_2 = E - E_1$ the probability density of $E_1$ is a Gaussian with variance
\begin{align}
\sigma_{E_1}^{2} &= -k_B/(\pdv[2]{S_1}{E_1} + \pdv[2]{S_{2}}{E_2}). \label{variance}
\end{align}

\begin{question}
\textnormal{\textbf{(a)}}
Show that
				\begin{align}
				\frac{1}{k_B} \pdv[2]{S}{E} &= - \frac{1}{k_BT} \frac{1}{Nc_vT}
				\label{fluctuation}
				\end{align}
				where $c_v$ is the inverse of the total specific heat at constant volume.
\end{question}

\begin{solution}
The equilibrium entropy is $ S = k_B \log(\Omega(E)) $ where temperature is defined as $ 1/T \equiv \partial S / \partial E.$ Using some sleight of hand Leibniz notation\footnote{Mathematicians beware!}:
\begin{align}
\frac{1}{k_B}\pdv[2]{S}{E} &= \frac{1}{k_B}\pdv{E}\pdv{S}{E}
\\
&= \frac{1}{k_B}\pdv{E} \frac{1}{\Omega}\pdv{\Omega}{E}
\\
&= \frac{1}{k_B}\pdv{E} \frac{1}{T}
= \frac{1}{k_B} \pdv{E} \pdv{T}{T} \frac{1}{T}
\\
&= \frac{1}{k_B} \pdv{T}{E} \pdv{\frac{1}{T}}{T}
= -\frac{1}{k_B} \frac{1}{Nc_v} \frac{1}{T^2}
\\
\Aboxed{\frac{1}{k_B}\pdv[2]{S}{E} &= -\frac{1}{k_B T} \frac{1}{Nc_vT}}
\end{align}
where we made use of the specific heat $Nc_v \equiv \partial E / \partial T$.
\end{solution}

\begin{question}
\textnormal{\textbf{(b)}}
If $c_{v1}$ and $c_{v2}$ are the specific heats per particle for two subsystems of $N$ particles each, show using eqns [\ref{variance}] and [\ref{fluctuation}] that
				\begin{align}
				\frac{1}{c_{v1}} + \frac{1}{c_{v2}} = \frac{Nk_BT^2}{\sigma_{E_1}^2}.
				\end{align}
\end{question}
\begin{solution}
This one is pure massaging equations, specifically [\ref{variance}] and [\ref{fluctuation}].
\begin{align}
\sigma_{E_1}^{2} &= -k_B/\bigg(\pdv[2]{S_1}{E_1} + \pdv[2]{S_{2}}{E_2}\bigg)
\\
\pdv[2]{S_1}{E_1} + \pdv[2]{S_{2}}{E_2} &= -k_B/\sigma_{E_1}^{2}
\end{align}
We substitute in the specific heat $Nc_v$ for each subsystem.
\begin{align}
-\frac{1}{NT^2}\bigg( \frac{1}{c_{v1}} + \frac{1}{c_{v2}} \bigg) &= -\frac{k_B}{\sigma_{E_1}^{2}}
\\
\Aboxed{\frac{1}{c_{v1}} + \frac{1}{c_{v2}} &= \frac{Nk_BT^2}{\sigma_{E_1}^{2}}} \label{sum}
\end{align}

\end{solution}

\begin{question}
\textnormal{\textbf{(c)}}
Using the equipartition theorem, write the temperature in terms of $K$. Show that $c_v^{(1)} = 3k_B/2$ for the momentum degrees of freedom. In terms of $K$ and $\sigma_K$, solve for the total specific heat of the molecular dynamics simulation.
\end{question}

\vspace{2mm}
\noindent
\textbf{Solution:}\\
\emph{Temperature in terms of $K$.}
The kinetic energy of a particle moving in a direction $i$ is given by $p_i^2/2m$. The average kinetic energy of a particle depends on the temperature of its system $K = 1/2 k_B T$. A particle has three translational degrees of freedom, each of which contribute equally---on average---to the average to the particle's kinetic energy (equipartition theorem). Thus for a gas of $N$ atoms, its total average kinetic energy is
\begin{align}
K &= \frac{3}{2} N k_B T.\label{kinetic}
\end{align}
This allows us to write the temperature as a function of energy as $\boxed{T(K) = \frac{2}{3}\frac{E}{Nk_B}}$.

\vspace{2mm}
\noindent
\emph{Momentum degrees of freedom.}
Remebering the definition of specific heat, we rewrite energy in terms of temperature to show $c_v^{(1)} = 3k_B/2$ for the momentum degrees of freedom.
\begin{gather}
Nc_{v1} = \pdv{E}{T_1} = \pdv{T_1} \bigg( \frac{3}{2} N k_b T_1 \bigg)
\\
\boxed{c_{v1} = 3/2 k_B}\label{specific_heat}
\end{gather}

\vspace{2mm}
\noindent
\emph{Total specific heat.}
First note that $\sigma_K = \sigma_{E}$.
Let $K = \langle E_1 \rangle$. Since the kinetic energy does not depend on the spacial configuration $\mathbb{Q}$ and potential energy does not depend on momentum configuration $\mathbb{P}$, we can treat our system as two uncoupled-subsystems, where $c_{v1}$ is the kinetic contribution to specific heat and $c_{v2}$ is the configuration contribution. Plug in [\ref{kinetic}] and [\ref{specific_heat}] to [\ref{sum}].
\begin{gather}
\frac{1}{c_{v2}} = \frac{Nk_BT^2}{\sigma^2_{E_1}} - \frac{2}{3}k_BT
\\
\frac{1}{c_{v2}} = \frac{1}{N k_B \sigma^2_{E_1}} \bigg(4K^2 - 6Nk_B^2 \sigma^2_{E_1}  \bigg)
\\
c_{v2} = \frac{N k_B \sigma^2_{E_1}}{4K^2 - 6Nk_B^2 \sigma^2_{E_1}}
c_{v2} = \frac{(k_B N \sigma^2_K)}{4K^2 - 6N\sigma^2_K}
\end{gather}
Then we find that $c_{v1} + c_{v2}$ is
\begin{align}
c_v &= c_{v1} + c_{v2}
\\
&= \frac{(k_B N \sigma^2_K)}{4K^2 - 6N\sigma^2_K} + \frac{3}{2}k_B
\\
\Aboxed{
c_v &= k_B \frac{K^2}{\frac{2}{3}K^2 - N\sigma_K^2}}
\end{align}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% MICROCANONICAL ENERGY FLUCT %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Life and the heat death of the universe}

\emph{Living beings intercept entropy flows}; they use low-entropy sources of energy and emit high-entropy forms of the same energy. Freeman Dyson presumed that an intelligent being generates a fixed entropy $\Delta S$ per thought. Let's investigate how living beings might evolve to cope with the cooling and dimming we expect during the heat death of the Universe.\\
Assume that a being draws heat Q from a hot reservoir at $T_1$ and radiates it away to a cold reservoir at $T_2$.

\begin{question}
\textnormal{\textbf{(a)}}
\textbf{\emph{Energy needed per thought.}}
What is the minimum energy $Q$ needed per thought, in terms of $\Delta S$ and $T_2$?
\end{question}

\begin{solution}
The change in entropy $\Delta S$ is given by
\begin{align}
	\Delta S &= \frac{Q_2}{T_2} - \frac{Q_1}{T_1}\label{entropy}.
\end{align}
If our heat bath $T_1$ is very hot, we can ignore the last tern in [\ref{entropy}] and we're left with
\begin{align}
	\Delta S &= \frac{Q_2}{T_2}
\end{align}
Thus, the minimum energy $Q$ needed per thought is given by
\begin{align}
\Aboxed{	Q &= T_2\Delta S.}\label{Q}
\end{align}
\end{solution}

\begin{question}
\textnormal{\textbf{(b)}}
\textbf{\emph{Time needed per thought to radiate energy.}}
Write an expression for the maximum rate of thoughts per unit time $\dv*{H}{t}$ (the inverse of the time $\Delta t$ per thought), in terms of $\Delta S$, $C$, and $T_2$.
\end{question}

\begin{solution}
Let $H$ be number of thoughts. Dyson shows that power radiated by our intelligent-being-as-entropy-producer is about
$P = C T^3_2$.
It follows that the energy radiated for a thought of time $\tau$ is
$E = C T^3_2 \tau$.

This energy is simply energy $Q$, the heat energy taken from the hot bath $T_1$.
The time-per-thought $\tau$ is
\begin{align}
\tau &= \frac{\Delta S}{C T^2_2}\label{time}
\end{align}
The time needed per thought $\dv*{H}{t}$ is [\ref{time}]'s reciprocal.
\begin{align}
\Aboxed{ \dv{H}{t} &= \frac{C T^2_2}{\Delta S}}
\end{align}
\end{solution}

\begin{question}
\textnormal{\textbf{(c)}}
\textbf{\emph{Number of thoughts for an ecologically efficient being.}}
\emph{Our Universe is expanding ($R \sim t$); the microwave background radiation has a characteristic temperature $\Theta (t) \sim R^{-1}$ which is getting lower as the Universe expands due to the Doppler effect.}
How many thoughts $H$ can an ecologically efficient being have between now and time infinity, in terms of $\Delta S$, $C$, $A$, and the current time $t_0$?
\end{question}

\begin{solution}
An ecologically efficient being wants to radiate as little heat as possible;
we choose $T_2$ to be equal to the microwave background $\Theta(t)$ since it cannot radiate heat at a temperature below this.

We integrate the rate of thoughts with respect to time to get the number of thoughts $H$ for a given time scale, using
$ \Theta(t) \sim A/t$.

\begin{align}
H &= \int_{t_0}^{\infty} \! \d{H}
= \int_{t_0}^{\infty} \! \d{t} \ \dv{H}{t}
=  \int_{t_0}^{\infty} \! \d{t} \ \frac{C T_2^2}{\Delta S}\label{H-integral}
\\
&= \frac{C A^2}{\Delta S} \int_{t_0}^{\infty} \! \d{t} \
\frac{1}{t^2}
= \frac{C A^2}{\Delta S} t^{-1} \bigg|_{\infty}^{t_0}
\end{align}
The number of thoughts an efficient being can have between now and time infinity is
\begin{align}
\Aboxed{H &= \frac{CA^2}{\Delta S}\frac{1}{t_0}}.
\end{align}
\end{solution}

\begin{question}
\textnormal{\textbf{(d)}}
\textbf{\emph{Time without end: greedy beings.}}
\emph{Dyson would like his beings to be able to think an infinite number of thoughts before the Universe ends, but consume a finite amount of energy.
He proposes that beings radiate at a temperature $T_2(t) \sim t^{-3/8}$.} Show that with Dyson's cooling schedule, the total number of $H$ is infinite, but the total energy consumed $U$ is finite.
\end{question}

\begin{solution}
Take $T_2(t) = At^{-3/8}$ and integrate [\ref{H-integral}] to show that the number of thoughts at Dyson's proposed radiation temperature is infinite.

\begin{align}
H &= \int_{t_0}^{\infty}\! \d{t} \ \dv{H}{t} = \frac{CA^2}{\Delta S}\int_{t_0}^{\infty} \! \d{t} \ \Bigg(\frac{1}{t^{3/8}} \Bigg)^2
= \frac{8}{2}\frac{CA^2}{\Delta S}  \ t^{1/4}\ \bigg|_{t = t_0}^{t = \infty} = \boxed{\infty}\label{H}
\end{align}
However, the total energy consumed is still finite. The total energy consumed $U$ is equal to the number of thoughts [\ref{H}] multiplied the energy per thought [\ref{Q}].
\begin{gather}
\dv{U}{t} = Q \dv{H}{t} = T_2\Delta S \dv{H}{t} = CT_2^3
\\
U = CA^3\int_{t_0}^{\infty} \! \d{t} \
\Bigg(\frac{1}{t^{3/8}} \Bigg)^3 = CA^3\int_{t_0}^{\infty} \! \d{t} \ t^{-9/8}
= 8 C A^3 t^{-1/8} \ \bigg|_{\infty}^{t_0}
\end{gather}
We find that the total energy consumed is finite.
\begin{align}
\Aboxed{U &= 8 C A^3 \ t_0^{-1/8}}
\end{align}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%
%% PRESSURE-VOLUME %%
%%%%%%%%%%%%%%%%%%%%%
\newpage
\section{Pressure-volume diagrams}

A monatomic ideal gas in a piston is cycled around the path in the $P-V$ diagram in fig.~\ref{P-V}. Leg \textbf{a} cools at constant volume by connecting to a heat bath at $T_c$; leg \textbf{b} heats at a constant pressure by connecting to a heat bath at $T_h$; leg \textbf{c} compresses at constant temperature while remaining connected to the bath at $T_h$.

\begin{figure}[h!]
\centering
\includegraphics[width=0.3\linewidth]{PSet3_Fig1}
\caption{$P-V$ diagram.\label{P-V}}
\end{figure}

\begin{question}
Which of the following six statements are true?
\end{question}

\begin{enumerate}[(1)]
	\item The cycle is reversible; no net entropy is created in the Universe.
	\\
	\textbf{False.} Leg \textbf{a} and leg \textbf{b} both increase net entropy of the universe. The system is exchanging heat with a cold and hot bath, respectively, leading to an entropy increase of $\Delta S = \Delta Q/T$.

	\item The cycle acts as a refrigerator, using work from the piston to draw energy from the cold bath into the bot bath, cooling the bath.
	\\
	\textbf{False.} In leg \textbf{a}, when the system is in contact with the cold bath, heat energy is being transferred \textit{from} the system \textit{to} the cold bath.

	\item The cycle acts as an engine, transfering heat from the hot bath to the cold bath and doing positive net work on the outside world.
	\\
	\textbf{False.} $W = \int P \d{V} < 0$; the work done on the outside world is negative. Engines do positive work on their environments.

	\item The work done per cycle has magnitude
			$|W| = P_0V_0 |4\log{4-3}|$.
	\\
	\textbf{True.} It can be shown that the area integral $\int P \d{V}$ is equal to 	$P_0V_0 |4\log{4-3}|$ (i did it on the white board in discussion!).
	\item The heat transferred into the cold bath, $Q_c$, has magnitude	$|Q_c| = (9/2)P_0V_0$.
	\\
	\textbf{True.} Consider leg \textbf{a} (where no work is being done). The heat energy transferred is given by $Q = \Delta U - W$. Initially, the potential energy is $U_i = (3/2)NK_bT_h = (3/2)4P_0V_0$. Once the cycle reaching leg \textbf{b}, the potential energy is $U_f = (3/2)NK_bT_c = (3/2)P_0V_0$. Therefore, $Q = \Delta U = (9/2)P_0V_0$.

	\item The heat transferred from the hot bath, $Q_h$, plus the net work $W$ done by the piston onto the gas, equals the heat $Q_c$ transferred into the cold bath.
	\\
	\textbf{True.} This is a statement of total energy conservation in the system.
\end{enumerate}

\end{document}


%!TEX root = ../main.tex

%===============================================================================
%
%    Chapter: math_fundamentals
%
%===============================================================================

\chapter{Math fundamentals}
\label{chapter:math_fundamentals}

In this chapter we'll review the fundamental ideas of mathematics, including numbers, equations, and functions.
To understand college-level textbooks, you need to be comfortable with mathematical calculations.
Many people have trouble with math, however.
Some people say they \emph{hate} math, or could never learn it.
It's not uncommon for children who score poorly on their school math exams to develop math complexes in their grown lives.
If you are carrying any such emotional baggage, you can drop it right here and right now.

Do NOT worry about math!
You are an adult, and you can learn math much more easily than when you were a kid.
We'll review \emph{everything} you need to know about high school math, and by the end of this chapter,
you'll see that math is nothing to worry about.

\smallskip

\begin{figure}[H]
\centering
\! \includegraphics[width=1.01\textwidth]{figures/concept_maps/precalculus.pdf}
	\caption{A concept map showing the mathematical topics that we will cover in this chapter.
			We'll learn how to solve equations using algebra,
			how to model the world using functions,
			and how to think geometrically.
			The material in this chapter is required for your understanding of the more advanced topics in this book.}
\label{fig:precalculus_concept_map}
\end{figure}


\documentclass[11pt]{article}

\usepackage{blindtext}
\usepackage{fullpage}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{fancyhdr}
\usepackage{algorithm}
\usepackage{bm}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{caption2}
\usepackage{subfigure}
\usepackage{float}
\usepackage{extpfeil}
\usepackage{color}
\usepackage{indentfirst}
\usepackage[stable]{footmisc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[noend]{algpseudocode}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{remark}[subsection]{Remark}

%%
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

%% define new symbols
\def\bx{\bm{x}}
\def\bb{\bm{b}}
\def\ba{\bm{a}}
\def\bc{\bm{c}}
\def\bf{\bm{f}}
\def\by{\bm{y}}
\def\bu{\bm{u}}
\def\bv{\bm{v}}
\def\BW{\bm{W}}
\def\BA{\bm{A}}
\def\bz{\bm{z}}
\def\BZ{\bm{Z}}
\def\BH{\bm{H}}
\def\BL{\bm{L}}
\def\BU{\bm{U}}
\def\BV{\bm{V}}
\def\BB{\bm{B}}
\def\BC{\bm{C}}
\def\BD{\bm{D}}
\def\BE{\bm{E}}
\def\BW{\bm{W}}
\def\BQ{\bm{Q}}
\def\BG{\bm{G}}
\def\BA{\bm{A}}
\def\BX{\bm{X}}
\def\BY{\bm{Y}}
\def\BQ{\bm{Q}}
\def\BI{\bm{I}}
\def\BR{\bm{R}}

%% define new brackets
\def\la{\left\langle}
\def\ra{\right\rangle}
\def\ln{\left\|}
\def\rn{\right\|}
\def\lb{\left(}
\def\rb{\right)}
\def\lsb{\left[}
\def\rsb{\right]}
\def\lcb{\left\{}
\def\rcb{\right\}}

%%
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator*{\argmax}{arg\,max}

%%
\title{A Brief Insight into Complex Polynomial Root-finding and Fractals}
\author{Name: Shao Yanjun, Number: 19307110036}

\setlength{\parindent}{1em}

\begin{document}
\maketitle

%------------------------------------
\begin{abstract}
This is Daniel's final project of  "Numerical Algorithms with Case Studies II".
\end{abstract}
%-------------------------------------
%=====================
\section{Julia Set, Mandelbrot Set and Newton Fractals \footnote{Mahanta, Arun \& Sarmah, Hemanta \& Paul, Ranu \& Choudhury, Gautam. (2016). Julia set and some of its properties. 5. 99-124. }}
The modern day interest in Julia sets and related mathematics began in the year 1920, which was initiated by French mathematician Gaston Julia. In 1918 he wrote a paper titled \textit{"M´emoire sur l’iteration des functions rationelles"}\footnote{Julia G.," M'emoire Sur I'iteration des fonctions rationelles" Journal de Math. Pure ET Appl. 8(1918) 47-	245.Republished in Herve M. (ed), Oeuvers de Gaston Julia: Vol.1, Gauthiers-Villars 1968, 121-333.
} (A Note on the Iteration of Rational Functions) where he first introduced the modern idea of a Julia set. Personally, I began my research on this topic when I was watching Numberphile videos on Youtube \footnote{\textit{https://www.youtube.com/watch?v=oCkQ7WK7vuY}}. Comments suggested that the algorithm is not too complicated to implement in Matlab, so I spent a whole afternoon to make it work with animation and relatively high resolution. Hopefully, it works quite well under finite iterations of calculation.

A mapping of the form reading,
\begin{align*}
	f: z\rightarrow z^2+c\qquad c\in\mathbb{C}, |c|\le2
\end{align*}
is defined, so that for different values of the parameter $c$, we can find a
conceptually easiest way to define Julia set.
\begin{definition}
Let c be any complex number. The smallest closed set in the complex plane that contains all fixed points and all periodic points of the map $f_c(z)=z^2+c$ is called Julia set of the map $f_c$, denoted by $J_c$.
\end{definition}

We can also derive a trivial but exciting Lemma for the property of Julia Set. However, I will focus more on the visualization of it instead of paying too much attention on theoretical proof.
\begin{lemma}
	The Julia set $J_c$ of a function $f_c(z)=z^2+c$ is bounded.
\end{lemma}
\begin{proof}
	Choose $r = \max(|c|, 2+\epsilon)$ and let $|z|\ge r$,
	\begin{align*}
		|f_c(z)|&=|z^2+c|\ge |z^2|-|c| \\&\ge (r-1)|z| \ge (1+\epsilon)|z|
	\end{align*}

	With this, we will deduce $f_c^n(z)$ for all $|z|\ge r$,
	\begin{align*}
		f_c^n(z)\ge (1+\epsilon)^n|z|\rightarrow\infty
	\end{align*}

	This will give a bound for $J_c\subset B(0,r)$.
\end{proof}

This Lemma at least gives a sound guarantee that whatever we initialize our iteration on $z\in \mathbb{C}$ and $|z|<r$, a Julia Set can be plot with amazing patterns.

A animated gif is generated in ./fig/Julia.gif directory, and here are some 'one-milion-dollar' glimpses of fixed $c\in \mathbb{C}$. Every pixel in the image represents a complex number $a+bi\in\mathbb{C}$ where $(a,b)\in[-2,2]\times[-2,2]$.
\begin{figure}[H]
	\centering
	\subfigure[$c=-1$]{
		\includegraphics[width=0.2\linewidth]{Julia.jpg}
	}
	\subfigure[$c=i$]{
		\includegraphics[width=0.2\linewidth]{Julia 2.jpg}
	}
	\subfigure[$c=-0.866 + 0.5i$]{
		\includegraphics[width=0.2\linewidth]{Julia 4.jpg}
	}
	\subfigure[$c=0.5i$]{
	\includegraphics[width=0.2\linewidth]{Julia 3.jpg}
	}
\caption{Julia Set}
\end{figure}

Meanwhile, if we fix $z$ and represent every pixel with different $ca+bi\in\mathbb{C}$ where $(a,b)\in[-2,2]\times[-2,2]$, another fancy fractal named Mandelbrot Set can be displayed.
\begin{figure}[H]
	\centering
	\subfigure[z=0]{
		\includegraphics[width=0.3\linewidth]{Mandelbrot.jpg}
	}
	\centering
	\subfigure[z=0.5]{
		\includegraphics[width=0.3\linewidth]{Mandelbrot 2.jpg}
	}
	\subfigure[z=-0.5i (Love)]{
		\includegraphics[width=0.3\linewidth]{Mandelbrot 3.jpg}
	}
\caption{Mandelbrot Set}
\end{figure}

However, historically, the study of iteration of maps begins with the Newton's method. Cayley and Schröder independently studied Newton's method over the complex plane during the 1870s. In 1879 paper \textit{"The Newton-Fourier Imaginary Problem"} by Sir Arthur Cayley\footnote{Peitgen H, Jurgens H., and Saupe D., "Chaos and Fractals: New Frontiers of Science" Springer Verlag, 1992.}, he applied the Newton-Fourier iterative method (also known as the Newton–Raphson method) to find the roots of the equation $f(z)=z^3+c=0$. We can also plot out the Newton Fractals of different polynomial equations, which denotes the convergence regions of the initial points $x_0\in\mathbb{C}$ to different roots on complex Plane.

The iteration rule simply reads,
\begin{align*}
	f: x_{k+1}\leftarrow x_k-\frac{P(x_k)}{P'(x_k)}
\end{align*}

Surprisingly, the convergence regions are not distinctly separated on the complex plane. There are crosses, twists and intersections between the convergence boundaries of each root.

\begin{figure}[H]
	\centering
	\subfigure[$x^3-1=0$]{
		\includegraphics[width=0.35\linewidth]{Newton Fractal 3.jpg}
	}
	\centering
	\subfigure[$x^4-1=0$]{
		\includegraphics[width=0.35\linewidth]{Newton Fractal 4.jpg}
	}
	\subfigure[$x^5-1=0$]{
		\includegraphics[width=0.35\linewidth]{Newton Fractal 5.jpg}
	}
	\subfigure[$x^{12}-1=0$]{
		\includegraphics[width=0.35\linewidth]{Newton Fractal 12.jpg}
	}
	\caption{Newton Fractals}
\end{figure}

Intuitively, we can guess the degree of a polynomial determines the number of regions, which is trivially true because the degree of a polynomial determines the number of its roots.

\section{Newton-Raphson Method and Jenkins-Traub Method \footnote{https://en.wikipedia.org/wiki/Jenkins–Traub\_algorithm}}
Obviously, we may encounter problems with Newton-Raphson method in root-finding if the initial points are ill-chosen and fall in some unexpected regions (i.e the center blue circle of Figure 3(d)). Some global criterion for Newton-Raphson method calls into question. Otherwise, a new algorithm should be designed.

In 1968, Jenkins and Traub published a paper named \textit{"A Three-Stage Variable-Shift Iteration for Polynomial Zeros and Its Relation to Generalized Rayleigh Iteration"}\footnote{M. A. Jenkins and J. F. Traub, A three-stage variable-shift iteration for polynomial zeros in relation to generalized Rayleigh iteration, Numer. Math. 14 (1970), 252-263.} and introduced a new three-stage process for calculating the zeros of a
polynomial with complex coefficients. I will generally introduce this algorithm and give some insights into the convergence properties. Also, what will the Fractal of this algorithm look like? It's also an interesting question to think about.

First, we will clarify some basic definitions,
\begin{definition}
	Consider polynomial $P(z)=\prod_{j=1}^{k}(z-a_j)^{m_j}\in\mathbb{C}[x]$, and its derivative will be $P'(z)=\sum_{j=1}^{k}(m_jP_j(z))$, where $P_j=P(z)/(z-a_j)$.
\end{definition}
\begin{definition}
	Define a serie of auxiliary polynomials $\{H^{(\lambda)}(z)|\lambda\in\mathbb{N}\}$, which satisfies
	\begin{align*}
		H^{(0)}(z)=P'(z)
	\end{align*}
	and
	\begin{align*}
		H^{(\lambda+1)}(z)=\dfrac{1}{z-s_\lambda}[H^{(\lambda)}(z)-\frac{H^{(\lambda)}(s_\lambda)}{P(s_\lambda)}H^{(\lambda)}(z)]
	\end{align*}
\end{definition}
And now we can show the general algorithm of Jenkins-Traub
\begin{algorithm}[H]
	\caption{Jenkins-Traub}
	\begin{algorithmic}[1]
		\Procedure{Phase 1: No-shift process}{}
			\State $H^{(0)}(z)\leftarrow P'(z)$
			\For{$\lambda=1,2,\cdots,M-1$} \Comment{M=5 is empirically good.}
			\State $H^{(\lambda+1)}(z)\leftarrow\dfrac{1}{z}[H^{(\lambda)}(z)-\dfrac{H^{(\lambda)}(0)}{P(0)}H^{(\lambda)}(z)]$
			\EndFor
		\EndProcedure
		\Procedure{Phase 2: Fixed-shift process}{}
		\State Find a fixed random $s$, $s.t.$ $|s|\le\min_{1\le i\le n}(|a_i|)$.
		\State And this will converge to the closest root $|s-a_i|\le|s-a_j| \forall 1\le j\le n$.
		\For{$\lambda=M,M+1,\cdots,L-1$}  \Comment{L is a sufficiently large number.}
		\State $H^{(\lambda+1)}(z)\leftarrow \dfrac{1}{z-s}[H^{(\lambda)}(z)-\dfrac{H^{(\lambda)}(s)}{P(s)}H^{(\lambda)}(z)]$
		\EndFor
		\EndProcedure
		\Procedure{Phase 3: Variable-shift process}{}
		\Repeat
		\State $H^{(\lambda+1)}(z)\leftarrow \dfrac{1}{z-s_\lambda}[H^{(\lambda)}(z)-\dfrac{H^{(\lambda)}(s_\lambda)}{P(s_\lambda)}H^{(\lambda)}(z)]$
		\State $s_{\lambda+1}\leftarrow s_\lambda-\dfrac{P(s_\lambda)}{\overline{H^{(\lambda+1)}}(s_\lambda)}$
		\Until{$|P(s_{\lambda+1})|\le \epsilon$}
		\EndProcedure
	\Return $s_{\lambda+1}$
	\end{algorithmic}
\end{algorithm}

And $s_{\lambda+1}$ will be an arbitrary complex root dependent on the choice of our fixed shift $s$. Continue to factorize $(z-s_{\lambda+1})$ from $P(z)$ to get $P_{k-1}(z)=P_{k}(z)/(z-s_{\lambda+1})$. Repeat Jenkins-Traub until $deg(P)=1$ so that all roots are found.
\begin{algorithm}[H]
	\caption{Root-Finding}
	\begin{algorithmic}[1]
		\Repeat
		\State $root_i\leftarrow$Jenkins-Traub($P_{i}(z)$)
		\State $P_{i-1}(z)\leftarrow P_{i}(z)/(z-root_i)$
		\Until{$deg(P(z))=1$}\\
	\Return $roots$
	\end{algorithmic}
\end{algorithm}

Before diving deep into convergence analysis, we may play with our new algorithm and plot out some random Fractals.
\begin{figure}[H]
	\centering
	\subfigure[A strange peanut]{
		\includegraphics[width=0.45\linewidth]{Comparison2.jpg}
	}
	\centering
	\subfigure[Similar but wierd]{
		\includegraphics[width=0.45\linewidth]{Comparison3.jpg}
	}
	\subfigure[A baby sitter]{
		\includegraphics[width=0.45\linewidth]{Comparison4.jpg}
	}
	\subfigure[Master's painting]{
		\includegraphics[width=0.45\linewidth]{Comparison5.jpg}
	}
	\caption{Newton Fractals}
\end{figure}

Most Fractals of Jenkins-Traub method look ridiculous and make no sense at all, or rather we may simply regard it as a random painting instead of Fractal.

To give an overall view of the algorithm performance, we first give some Lemma and Definitions.
\begin{lemma}
	Denote $H^{(\lambda)}(z)=\sum_{j=1}^{k}c^{(\lambda)}_jP_j(z)$, and $c^{(\lambda+1)}=\dfrac{m_j}{\prod_{t=0}^{\lambda}(s_t-a_j)}$
	\begin{proof}
		Use the iteration form,
		\begin{align*}
			H^{(\lambda+1)}(z)&=\dfrac{1}{z-s_\lambda}[H^{(\lambda)}(z)-\frac{H^{(\lambda)}(s_\lambda)}{P(s_\lambda)}H^{(\lambda)}(z)]\\
			&=\dfrac{P(z)}{z-s_\lambda}[\sum_{j=1}^{k}\dfrac{c^{(\lambda)}_j}{z-a_j}-\sum_{j=1}^{k}\dfrac{c^{(\lambda)}_j}{s_\lambda-a_j}]\\
			&=\sum_{j=1}^{k}\dfrac{c^{(\lambda)}_jP(z)}{(z-a_j)(s_\lambda-a_j)}\\
			&=\sum_{j=1}^{k}\dfrac{c^{(\lambda)}_jP_j(z)}{s_\lambda-a_j}=\sum_{j=1}^{k}c^{(\lambda+1)}_jP_j(z)
		\end{align*}
		So we have,
		\begin{align*}
			c^{(\lambda+1)}=\dfrac{c^{(\lambda)}_j}{s_\lambda-a_j}=\cdots=\dfrac{m_j}{\prod_{t=0}^{\lambda}(s_t-a_j)}
		\end{align*}
	\end{proof}
\end{lemma}
\begin{definition}
	We denote $a_1=\argmin_j(|a_j-s|)$,  $r^{(\lambda)}_j=\dfrac{s_\lambda-a_1}{s_\lambda-a_j}$, $d^{(\lambda)}_j=\dfrac{c^{(\lambda)}_j}{c^{(\lambda)}_1}$, $T_\lambda=|\dfrac{s_{\lambda+1}-a_1}{s_{\lambda}-a_1}|$.
\end{definition}
And finally here gives a simplified Theorem of convergence,
\begin{theorem}
	Given that $s$ is chosen correctly in the algorithm and $L$ is sufficiently large, if $D_L=\sum_{j=2}^{n}|d^{(L)}|< \dfrac{1}{3}$, then we will have $s_\lambda\rightarrow a_1$ when $\lambda\rightarrow\infty$
	\begin{proof}
		Since $A=\prod_{k=0}^{\lambda} T_k=\dfrac{|s_{\lambda}-a_1|}{|s_{0}-a_1|}$, if $T_\lambda<1$, $\forall\lambda\ge L$, we will have $|s_\lambda-a_1|\rightarrow0$. Next we will prove $T_\lambda<1$ using given conditions.
		\begin{align}
			\dfrac{s_{\lambda+1}-a_1}{s_{\lambda}-a_1}&=
			\dfrac{s_\lambda-\dfrac{P(s_\lambda)}{\overline{H^{(\lambda+1)}}(s_\lambda)}-a_1}{s_{\lambda}-a_1}\\
			&=1-\dfrac{P(s_\lambda)}{\overline{H^{(\lambda+1)}}(s_\lambda)(s_\lambda-a_1)}\\
			&=1-\dfrac{P(s_\lambda)\sum_{i=1}^{n}c^{(\lambda)}_j/(s_\lambda-a_j)}{P(s_\lambda)\sum_{i=1}^{n}c^{(\lambda)}_j(s_\lambda-a_1)/(s_\lambda-a_j)^2}\\
			&=1-\dfrac{1+\sum_{j=2}^{n}d^{(\lambda)}_jr^{(\lambda)}_j}{1+\sum_{j=2}^{n}d^{(\lambda)}_j[r^{(\lambda)}_j]^2}\\
			&=\dfrac{\sum_{j=2}^{n}d^{(\lambda)}_j[r^{(\lambda)}_j]^2-\sum_{j=2}^{n}d^{(\lambda)}_jr^{(\lambda)}_j}{1+\sum_{j=2}^{n}d^{(\lambda)}_j[r^{(\lambda)}_j]^2}
		\end{align}
		Since $|r^{(L)}|=|\dfrac{s_\lambda-a_1}{s_\lambda-a_j}|<1$
		\begin{align*}
			T_\lambda&<\dfrac{|\sum_{j=2}^{n}d^{(\lambda)}_j|+|\sum_{j=2}^{n}d^{(\lambda)}_j|}{1+|\sum_{j=2}^{n}d^{(\lambda)}_j|}\\&=\dfrac{2D_\lambda}{1+D_\lambda}<1
		\end{align*}
	\end{proof}
\end{theorem}

Plot out several comparison of convergence between Newton-Raphson method and Jenkins-Traub method, we can't observe as what Jenkins and Traub asserts that there method outperforms traditional Newton-Raphson method. However, they grant a convergence of any solution with polynomial degree up to infinity.
\begin{figure}[H]
	\centering
	\subfigure[]{
		\includegraphics[width=0.33\linewidth]{Convergence3.jpg}
	}
	\centering
	\subfigure[]{
		\includegraphics[width=0.33\linewidth]{Convergence4.jpg}
	}
	\subfigure[]{
		\includegraphics[width=0.33\linewidth]{Convergence1.jpg}
	}
	\subfigure[]{
		\includegraphics[width=0.33\linewidth]{Convergence7.jpg}
	}
	\caption{Convergence}
\end{figure}

This is just a glimpse of some convergence analysis. Thanks to the strong capability of Matlab to conduct complex calculations with really large numbers, we can generally observe the convergence of Newton-Raphson-method (and sometimes it outperforms Jenkins-Traub method). However, if we conduct experiment on C, which is incapable of calculations with large float numbers, Newton-Raphson method will give an error instead of finding a root.

It is worth-noted that the mathematical software Mathematica also apply this Jenkins-Traub method for calculating the zeros of a polynomial with complex coefficients. \footnote{Wankere R. Mekwi, Iterative Methods for Roots of Polynomials, Exeter College, University of Oxford, 2001.} This method, to some extent, is the state-of-art.
\section{Further Discussions and the Companion Matrix}
The above polynomial roots problem can be alternatively turned into the eigenvalues problem of the companion matrix. A polynomial equation $a_nx^n+a_{n-1}x^{n-1}+\cdots+a_1x+a_0=0$ has the following plug-in to a shifted-QR algorithm on the following matrix,
\begin{align*}
	\begin{pmatrix}
		0 & 1 &   &  &\\
		& 0 & 1 &  &\\
		&  &\ddots&\ddots\\
		&  &   &0 &1\\
		-\dfrac{a_0}{a_n} & -\dfrac{a_1}{a_n}  & \cdots & -\dfrac{a_{n-2}}{a_n}&-\dfrac{a_{n-1}}{a_n}
	\end{pmatrix}
\end{align*}

Dekker and Traub\footnote{Dekker, T. J. and Traub, J. F. (1971), The shifted QR algorithm for Hermitian matrices, Lin. Algebra Appl., 4(2), 137–154.} came up with a shifted QR algorithm for calculating the eigenvalues of the Hermitan matrices. The shifts may be viewed as Newton-Raphson iteration on a sequence of rational functions converging to a first degree polynomial.

Also, all stages of the Jenkins–Traub complex algorithm may be represented as a linear algebra problem of determining the eigenvalues of the above companion  matrix. That is an explanation from the higher perspective, but we can easily deduce why the shift $s$ appears in the construction of $H_k(z)$. The three variants of no shift, constant shift and generalized Rayleigh shift directly matches with the three stages of the algorithm.

%-------------------------------------
%=====================
\end{document}


\subsection{Vectors and matrices}

\subsection{Addition}

\subsection{Multiplication}

\subsection{Inverse}

\subsection{Transpose}

\subsection{Scalar multiplication}

\subsection{Matrix decomposition}


\section{The Structural Behavioral Model} \label{sec:2}
\thispagestyle{plain} % surpress header on first page

The SA approach is applied to the DCDP model of the human capital investment decisions presented in \cite{keane1994SolutionEstimationDiscrete} which is briefly described in subsection \ref{sec:2.1}. The uncertain input parameters of the model are described in subsection \ref{sec:2.2} and the quantity of interest is discussed in subsection \ref{sec:2.3}.

\subsection{\cite{keane1994SolutionEstimationDiscrete} model} \label{sec:2.1}

Structural models have been developed to understand individual behavior and inform policy design in labor economics, particularly for DCDP models. DCDP models, as a framework for policy evaluation, have been applied to study a range of sequential individual decisions. A notable example is a work by \cite{keane1994SolutionEstimationDiscrete}, who developed an approximate solution to a large-scale DCDP model of human capital occupational choice. This is an ideal demonstration of how a structural model can evaluate various policies and determine the optimal policy without running many treatments.\\

\noindent
We assume that individuals are forward looking agents who make their occupational choice based on the principle of expected utility maximization. From age 15 to the age 55, the total period of decision is $T=40$ years. As shown in Figure \ref{fig:1}, in each period $t$, individual makes choice among $K=4$ alternatives: occupation one($a_t=1$), occupation two($a_t=2$), schooling($a_t=3$) and staying at home($a_t=4$). We denote the agent's immediate rewards of choosing each alternative in a given period as:

\begin{equation}
r_{t}\left(s_{t}, a_{t}\right)=\left\{\begin{array}{ll}
w_{1 t}=\exp \left\{\alpha_{10}+\alpha_{11} g_{t}+\alpha_{12} e_{1 t}+\alpha_{13} e_{1 t}^{2}+\alpha_{14} e_{2 t}+\alpha_{15} e_{2 t}^{2}+\epsilon_{1 t}\right\} & \text { if } a_{t}=1 \\
w_{2 t}=\exp \left\{\alpha_{20}+\alpha_{21} g_{t}+\alpha_{22} e_{1 t}+\alpha_{23} e_{1 t}^{2}+\alpha_{24} e_{2 t}+\alpha_{25} e_{2 t}^{2}+\epsilon_{2 t}\right\} & \text { if } a_{t}=2 \\
\beta_{0}-\beta_{1} \mathbb{I}\left[g_{t} \geq 12\right]-\beta_{2} \mathbb{I}\left[a_{t-1} \neq 3\right]+\epsilon_{3 t} & \text { if } a_{t}=3 \\
\gamma_{0}+\epsilon_{4 t} & \text { if } a_{t}=4
\end{array}\right.
\end{equation}
$w_{1t}$ and $w_{2t}$ is occupational-specific wage if individual choose either occupation one or two. $\alpha_1$ and $\alpha_1$ are parameters of corresponding wage functions. The primary factors that associated to wages are: years of completed schooling($g_t$), years of working experience in two occupations respectively($e_{1t}$, $e_{2t}$).If the individual does not choose to work($a_t=3$ or $a_4 = 4$), although they are not paid during this period, they still receive rewards from their choices. The variables that influence the choice of schooling are: the consumption value of schooling($\beta_0$), the tuition of post-secondary education($\beta_1$), and the adjustment expenses involved with returning to school. The means return of staying at home that affects the home option is represented by $\gamma_0$. \\

\noindent
The state space $t$ can be represented by
\begin{equation} \label{eq:2}
\left\{g_{t}, e_{1 t}, e_{2 t}, a_{t-1}, \epsilon_{1 t}, \epsilon_{2 t}, \epsilon_{3 t}, \epsilon_{4 t}\right\}
\end{equation}

\noindent
The part of state space observable to both individuals and researchers are $\left\{g_{t}, e_{1 t}, e_{2 t}, a_{t-1}\right\}$. The evolution of those variables follows a Markov chain, which means that the next state at period $t+1$ relies on the current state $t$ and the decision maker's action:

\begin{equation}\label{eq:3}
\begin{aligned}
e_{1, t+1} &=e_{1 t}+\mathbb{I}\left[a_{t}=1\right] \\
e_{2, t+1} &=e_{2 t}+\mathbb{I}\left[a_{t}=2\right] \\
g_{t+1} &=g_{t}+\mathbb{I}\left[a_{t}=3 \right]
\end{aligned}
\end{equation}
The shocks$\{\epsilon_{1t}, \epsilon_{2t},, \epsilon_{3t}, \epsilon_{4t}\}$ are serially independent and observed by individuals but not researchers.They are assumed to be jointly normally distributed. \\

\noindent
The maximized value of the expected remaining lifetime utility at $t$ is defined as:

\begin{equation}\label{eq:4}
V(S(t), t)=\max _{\left\{d_{k}(t)\right\}_{k \in K}} E\left[\sum_{\tau=t}^{T} \delta^{\tau-t} \sum_{k=1}^{K} R_{k}(\tau) d_{k}(\tau) \mid S(t)\right]
\end{equation}
with $0< \beta < 1$ the discount factor. $S(t)$ are state variables that contain information available before decision in period $t$ is made. $R_k$ is the rewards from choose alternative $k$ at period $t$. $d_k$ is individual's decision from among K=4 discrete alternatives. \\

\noindent
Alternatively, this optimization problem can be expressed as a the Bellman equation, which is a necessary condition for optimality associated with dynamic programming\citep{bellman1966DynamicProgramming, eisenhauer2019ApproximateSolutionFinite}:

\begin{equation}
E \max (S(t+1))=E\left[V(S(t+1), t+1) \mid S(t), d_{k}(t)=1\right]
\end{equation}

\subsection{Model parameters} \label{sec:2.2}

For model parametrization, our work takes advantage of the open-source Python package respy\citep{janosgabler2020RespyFrameworkSimulation}, which has greatly simplified the process of simulation and estimation of finite-horizon DCDP models. Table \ref{tab:1} shows the parameter values obtained from the simulation based on Data Set One in \cite{keane1994SolutionEstimationDiscrete}. According to this setting, occupation two requires greater expertise and thus is more beneficial from education. Experience in occupation one also increases the likelihood of increased earnings in another occupation. Thus, a general skill that is useful for both occupations can be obtained through either schooling or work experience, while occupation-specific skills are exclusively obtained through work. In this sense, we will refer to occupation two as white-collar and occupation one as blue-collar henceforth. \\

\noindent
Once parameterization is completed, we are allowed to analyze the economic implications behind it. Firstly, we investigate the correlation between selective model parameters \ref{fig:3}. In general, a large share correlation are prevalent, which emphasizes the importance of using GSA rather than LSA for this model. Because GSA takes into account the interaction between parameters. It is also worth noting that $\hat{\delta}$ and $\hat{\beta_0}$ and beta show a relatively strong negative correlation. \\

\noindent
\subsection{Quantity of Interest(QoI)} \label{sec:2.3}

This paper measures the impact of a 500 USD tuition subsidy on the average number of years a individual spends on pursuing a higher education degree. Figure \ref{fig:2} shows the probability distribution of this quantity of interest. Our simulation results with respy\citep{janosgabler2020RespyFrameworkSimulation} showed a 1.55-year increase in average school years, which is slightly higher than the effect documented by \cite{keane1994SolutionEstimationDiscrete}, that is an increase of 1.44 years. More specifically, Figure \ref{fig:3} shows a comparison of the occupation shares over their relevant life cycle for a sample of 1000 individuals in different sectors. The left panel shows a baseline scenario that without any policy intervention, whereas the right panel shows a counterfactual scenario that all the 500 USD tuition subsidy is implemented. The yellow, green, dark blue and light blue bars represent the percentages of people stay-at-home, pursuing education, blue-collar, white-collar, respectively. With this setting, we are able to access the policy effect without running experiments at real world. \\

\noindent
We noticed the change that, due to the fact that the white-collar industry values education, many agents begin their schooling early and continue to work in the white-collar sector. The positive impact and accumulated blue-collar experience pays off in the white-collar sector as well, leading to this shift from white- to blue-collar. It is nearly on impact due to the overall low level of participation in the household sector. The difference between the education shares for each age group in the right and left graphs, as represented by the red line, is quantified investment. This is because the vertical axis can be thought of as the percentage of time a typical agent spends in the education sector over the course of a year. When we look at both graphs, we can clearly see that tuition subsidies encourage younger people to stay in school longer and older people to pursue white collar works.\\

\noindent
In section \ref{sec:3} and section for \ref{sec:4} I will present how uncertain in model input translate to the variations of model output, in this case, the average change of school years. However, due to the computational burden in the sampling procedure, I restrict my attention to three main parameters: return to an additional year of schooling$\alpha_{11}$, reward for going to college$\beta_1$ and reward of non-market alternatives$\gamma_0$. As what we study is the impact of subsidy, the profit/cost trade-offs involved with the decision whether to pursue continuing education are fully reflected by the return on educational investment. Although $\gamma_0$ seems not explicitly related to our QoI like the previous chosen ones, we include is as a comparison.


\subsubsection{Reversable Processes}
First we need to talk about reversible processes. A reversible process, broadly speaking, is one that can spontaneously take place in both directions. Let's take a look at an example: say we have two large closed chambers of gas in an isolated system. The only way they can interact is via heat flow.
\begin{figure}[h!]
    \centering
\begin{tikzpicture}
\draw[draw = black] (0,0) rectangle (8,4);
\draw[thick] (4,0) -- (4,4);
\draw[text=blue] (2,2) node {$T_1$};
\draw[text=red] (6,2) node {$T_2$};
\draw[fill=blue, draw=blue] (1,1) circle (2pt);
\draw[fill=blue, draw=blue] (3,0.5) circle (2pt);
\draw[fill=blue, draw=blue] (0.5,2.6) circle (2pt);
\draw[fill=blue, draw=blue] (2.6,3.6) circle (2pt);
\draw[fill=blue, draw=blue] (3.5,1.75) circle (2pt);
\draw[fill=blue, draw=blue] (1.75,3) circle (2pt);
\draw[fill=blue, draw=blue] (2,1.5) circle (2pt);
\draw[fill=blue, draw=blue] (2.2, 0.2) circle (2pt);
\draw[fill=blue, draw=blue] (3,3) circle (2pt);
\draw[fill=blue, draw=blue] (0.5, 3.75) circle (2pt);
\draw[fill=red, draw=red] (5,1) circle (2pt);
\draw[fill=red, draw=red] (7,0.5) circle (2pt);
\draw[fill=red, draw=red] (4.5,2.6) circle (2pt);
\draw[fill=red, draw=red] (6.6,3.6) circle (2pt);
\draw[fill=red, draw=red] (7.5,1.75) circle (2pt);
\draw[fill=red, draw=red] (5.75,3) circle (2pt);
\draw[fill=red, draw=red] (6,1.5) circle (2pt);
\draw[fill=red, draw=red] (6.2, 0.2) circle (2pt);
\draw[fill=red, draw=red] (7,3) circle (2pt);
\draw[fill=red, draw=red] (4.5, 3.75) circle (2pt);
\end{tikzpicture}
    \caption{The wonderful box with two closed sections.}
\end{figure}
\\ If one side is at a higher temperature than the other, then we intuitively know that heat will flow from the hot side to the cool side. But what happens if their temperatures are the same? The short answer is: absolutely nothing. But it's an exciting nothing! Let's dig even deeper. \\
\newline
Say we were to zoom in extremely close on that boundary between the two sides of the box. What would we see? Unsurprisingly, a lot of very small particles hitting a very large wall. However, we know that in order for heat to flow across that barrier, the particles need some way of transferring their energy across the wall. How could they do it? Well, there's two possible ways. The first is radiation, which we'll pretend doesn't exist (it makes our lives much easier, and isn't a terrible assumption). The other is through the wall itself. That is, when a particle collides with the wall, a bit of its kinetic energy goes into the wall, which then gives it up to a particle colliding on the other side.
\newline\newline
Here's the key though: particles on both sides of the wall do this, regardless of the temperature difference. Even if we had the right side of the box at $10^{20}\mathrm{K}$ \footnote{Actually at a temperature this high there would be no box.} and the left side at $100\mathrm{K}$, some particles from the left side of the box would hit the wall and give up some energy to the right side. It's just that particles on the right side of the box are
\begin{enumerate}
    \item Giving up way more energy when they hit the wall.
    \item Hitting the wall far more frequently.
    \item And/or both!
\end{enumerate}
So the \textit{net} transfer of energy is from the right side of the box to the left. In a situation like this, where there is a spontaneous net transfer of energy, we'd say that said process is irreversible. However, if the temperature in the box was the same at both sides, we'd expect no net heat transfer to take place. Therefore, we could conclude that
\begin{itemize}
    \item Both sides give up the same amount of energy per collision on average.
    \item Both sides have the same frequency of collision.
\end{itemize}
This is where the symbol $\delta$ comes in. As the profs may or may not have mentioned in lecture, it means a \textit{very very very} small change. Which, it so happens, is the perfect way to describe the change in energy/temperature each side of the box has when one collision occurs. So we have a very small heat flow, and essentially constant temperature. Furthermore we can see that this tiny flow of heat has an equal chance of happening in both directions, and will. Hence, its reversible!
\newline\newline
So now that we have a better idea of what a reversible process is, we can better understand what entropy is. As a quick reminder, we said above that
\begin{equation*}
    dS=\frac{\delta Q_{rev}}{T}
\end{equation*}
With our newfound knowledge we can say that this says: the change in entropy of a system ($dS$) in a \textit{reversible} heat transfer is \textit{directly} proportional to the amount of heat transferred into the system and \textit{inversely} proportional to the temperature of the system.\footnote{Some of you may wonder if this definition still can be applied when the heat transfer is irreverisible. It can, but the equality is replaced by in inequality $dS > \frac{dQ}{T}$. So if you wanted the most general definition would be $dS \geq \frac{dQ}{T}$.}
\newline\newline
We say above that our tiny reversible processes happen between two systems at the same (constant) temperature. Here's the issue though, and the one that causes us to define all our reversible processes (and entropy) as infinitesimals: no reversible process actually exists on a macroscopic scale.
\newline\newline
As an example of why this is, let's take a look at a process that is theoretically reversible, but isn't actually reversible. Say we have a container of a gas with a piston on one face, but insulated such that it cannot exchange heat (or molecules) with its environment. However, it is connected to a neighbouring infinitely large heat bath, where it can exchange heat with (but not molecules).
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\draw[draw=black] (0,0) rectangle (2,2);
\draw[fill = black] (0,2) rectangle (2,2.25);
\draw (0,2) -- (0,3);
\draw (2,2) -- (2,3);
\draw (2,2) -- (5,2);
\draw (2,0) -- (5,0);
\draw[->, thick] (1, 2.25) -- (1, 2.75);
\draw[text=blue] (0.25,1.75) node {$P_1$};
\draw[text=blue] (0.25, 2.75) node {$P_2$};
\draw[text=red] (1,1) node {$T$};
\draw[text=red] (3.5,1) node {$T$};
\draw[magenta, ->] (2.75,1) -- (1.5,1);
\draw[text=magenta] (2.25, 1.25) node {$Q$};
\end{tikzpicture}
\caption{Piston with infinite heat bath to the right.}
\end{figure}
In this situation, we have that $P_{1}>P_{2}$, so the piston will undergo an expansion. Since the heat bath beside it will keep it at the same temperature, the expansion will be isothermal. So since the temperature of the two sides of the piston/heat bath barrier is constant and equal, the heat transfer across it reversible right? Well, not quite. And it has to do with the idea that a perfectly isothermal process doesn't exist either.
\newline\newline
To figure out why, let's break down what happens step by step. Initially, both the gas and the heat bath are at the same temperature, so no net heat flow between them. However, the pressure inside the piston is greater than the pressure outside. So the piston expands. When it does this, it does work on the environment, and loses energy. This in turn causes its temperature to fall. Its temperature dropping causes heat to flow spontaneously across from the heat bath, until the gas returns to its original temperature. Rinse, repeat until the internal and external pressures are equal.
\newline\newline
So we can see that during an isothermal process, the temperature isn't quite constant. However, if we do this process \textit{very} slowly, the heat flow will manage to restore the temperature so quickly (or to put it another way, heat will flow into the system much faster than the system does work) that the temperature be \textit{almost} constant the whole time. This is what we really mean by an isothermal process. It's also why entropy is defined infinitesimally, since we approximate that each of our tiny expansion steps of the piston happen at constant temperature.
\newline\newline
That being said, imagining an ideal, isothermal process is extremely useful, especially at small time scales. It allows us to derive the following formula for the change in entropy:
\begin{equation}
    \label{eqn:(36)}
    \Delta S=n{c_{v}}\ln{\frac{T_1}{T_0}} + nR\ln{\frac{V_1}{V_0}}
\end{equation}
Here, $n$ is the number of mols of gas, $c_v = \frac{\chi}{2}R$ as we defined earlier (for $\chi$ degrees of freedom and the gas constant $R$), $T_0$ and $T_1$ are the initial and final temperatures, and $V_0$ and $V_1$ are the initial and final volumes. First, the change in entropy depends only on the initial and final states of the system (i.e. the final and initial temperatures and volumes), not the path between those states! So \textbf{entropy is function of state}.
\newline\newline
The second thing you should notice is that entropy of a system is dependent on the volume, an \textit{extensive} quantity. Therefore, \textbf{entropy is an extensive quantity}.

\subsubsection{(Optional) Derivation of the Sackur–Tetrode Equation}
Equation \ref{eqn:(36)} as shown above is actually a version of the Sackur-Tetrode equation, which gives the entropy of a monoatomic ideal gas in full. While the derivation of the full equation is far, far out of the scope of this course\footnote{You may consult Wikipedia if you want to see the full equation}, equation \ref{eqn:(36)} can totally be derived with the things we have learned. This derivation is more for your curiousity than anything, and you do already have all the tools required to derive it (so if you're keen, give it a shot!). We start from the definition of entropy (for a reversible heat transfer):
\begin{align*}
    dS = \frac{dQ}{T}
\end{align*}
Now, we consider the first law of Thermodynamics:
\[
    dE = dQ+dW
\]
So let us substitute $dQ = dE-dW$ to obtain:
\[ dS = \frac{dE-dW}{T} = \frac{dE}{T}-\frac{dW}{T}
\]
We apply the (at this point, well-acquainted) formula for change in energy:
\[dE = nc_vdT \]
And we hence obtain:
\[ dS = \frac{nc_vdT}{T} - \frac{dW}{T} \]
We may now use the ideal gas law:
\[T = \frac{PV}{nR} \]
As well as the definition of work:
\[dW = -PdV \]
Substituting these in, we obtain:
\[ dS = \frac{nc_vdT}{T} + \frac{PdV}{\frac{PV}{nR}}\]
Which simplifies to:
\[dS = nc_v\frac{dT}{T} + nR\frac{dV}{V} \]
Now, we integrate from an initial state to a final state (in other words, from a initial entropy/temperature/volume $S_0,T_0,V_0$ to a final entropy/temperature/volume $S_1,T_1,V_1$:
\[\int_{S_0}^{S_1} dS = \int_{T_0}^{T_1}nc_v\frac{dT}{T} + \int_{V_0}^{V_1}nR\frac{dV}{V} \]
Performing the integration, we obtain:
\[ \left.S \right|_{S_0}^{S_1} = nc_v \left. \ln(T) \right|_{T_0}^{T_1} + nR \left. \ln(V) \right|_{V_0}^{V_1} \]
\[ \Delta S = nc_v\ln\left(\frac{T_1}{T_0}\right) + nR \ln\left(\frac{V_1}{V_0}\right) \]
Which is the desired result.


\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{amsmath,amsthm,amsfonts,amssymb,euscript,stmaryrd,graphicx,appendix,enumitem,yhmath,mathrsfs,superbox}
\usepackage{fullpage}
\usepackage{color,psfrag}

\definecolor{ACORRIGER}{rgb}{0.9,0,0}

\def\myqed {{% set up
\parfillskip=0pt % so \par doesnt push \square to left
\widowpenalty=10000 % so we dont break the page before \square
\displaywidowpenalty=10000 % ditto
%\finalhyphendem*erits=0 % TeXbook exercise 14.32
%
% horizontal
\leavevmode % \nobreak means lines not pages
\unskip % remove previous space or glue
\nobreak % don't break lines
\hfil % ragged right if we spill over
\penalty50 % discouragement to do so
\hskip.2em % ensure some space
\null % anchor following \hfill
\hfill % push \square to right
$\square$% % the end-of-proof mark
%
% vertical
\par}} % build paragraph

\newcommand{\footnoteremember}[2]{
 \footnote{#2}
 \newcounter{#1}
 \setcounter{#1}{\value{footnote}}
}
\newcommand{\footnoterecall}[1]{
 \footnotemark[\value{#1}]
}
\def\andcr{%
 \end{tabular}%
 \\
 \begin{tabular}[t]{c}}

\author
{
}

\title{Global Ranking of World Currencies}
\date{}

\newtheorem{theo}{Theorem}[section]
\newtheorem{theodef}{Theorem-Definition}[section]
\newtheorem{prop}[theo]{Proposition}
\newtheorem{coro}[theo]{Corollary}
\newtheorem{remark}{Remark}
\newtheorem{lemm}[theo]{Lemma}
\newtheorem{defi}{Definition}
\newtheorem*{propx}{Proposition}

\newcommand{\1}{\textbf{1}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\K}{\mathbb{K}}

\newcommand{\C}{\mathbb{C}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\vega}{\upsilon}
\newcommand{\Vega}{\mathcal{V}}

\newcommand{\PP}{\mathbb{P}}
\newcommand{\cF}{\mathcal{F}}
\newcommand{\diag}{\operatorname{diag}}
\newcommand{\supp}{\operatorname{supp}}
\newcommand{\card}{\operatorname{card}}
\newcommand{\vect}{\operatorname{vect}}
\newcommand{\sspan}{\operatorname{span}}
\newcommand{\cov}{\operatorname{cov}}
\newcommand{\var}{\operatorname{Var}}
\newcommand{\Proj}{\operatorname{Proj}}
\newcommand{\cell}{\operatorname{cell}}
\newcommand{\LL}{\operatorname{L}}
\newcommand{\Prime}{\operatorname{Prime}}
\newcommand{\Call}{\operatorname{Call}}
\newcommand{\Put}{\operatorname{Put}}
\newcommand{\slab}{\operatorname{slab}}
\newcommand{\tanapprox}{\operatorname{tanapprox}}
\newcommand{\ui}{{\underline{i}}}
\newcommand{\uj}{{\underline{j}}}

\def\independent{{\perp\!\!\!\!\perp}}
\def\simdist{\stackrel{\mathcal{L}}{\sim}}
\def\h1{\hspace{0.1cm}}

% keywords
\def\keywordname{{\bf Keywords:}}

\newcommand{\keywords}[1]{\par\addvspace\baselineskip\noindent\keywordname\enspace\ignorespaces#1}

\bibliographystyle{plain}

\graphicspath{{./}{figures/}}

\begin{document}
\maketitle
\vspace{-1cm}

\begin{center}{\Large \emph{A simple method for ranking currencies based on their relative stability} }\end{center}

\section{Introduction}

\par Using the nominal value of a currency with respect to some reference numeraire is not an appropriate means of ranking them with respect to how "strong" one should consider that currency. For example, the value of the Japanese Yen is lesser than the Brazialian real, while Yen is considered a much stronger currency.

\par A better way to compare a currency to another is to analyse the volatility skew of the pair. For example, a negative skew generally indicates a fatter tail for negative returns than positive returns. Hence, if A-B currency pair has a negative skew, we may consider A to be "lesser" than B.

\section{Creating a currency strength score}

\par Considering the anti-symmetric matrix $M$ of the at-the-money skews of all currency pairs, we seek to approximate it with the outer-difference of a \emph{score} vector $S$, $O_{i, j} = S_i - S_j$. When using the least-square criterion, $\min_{S} \|M - O\|_2^2$, the problem can be formulated as a linear regression.

\par The convention for quoting option prices on currency pairs is specific to foreign exchange market. We recommend you to read up about the FX option quoting convention (Butterfly and Risk Reversal). The 25 Delta risk-reversal can be considered a good proxy for the skew of the considered currency pair.

\section{C++ Computing Project}

\par First, using the C++ programming language (and testing with generated data), produce a routine performing the approximation of an anti-symmetrical matrix with the outer-difference of a score vector.

\par Then, using a real-world snapshot of the 25-Delta risk-reversal values, compute a "score" for a list of at least 15 currencies of the world following the criterion described in the previous section, including precious metals.

\par Provide a careful interpretation of the resulting scores.

\bibliography{biblio}
\end{document}


% This is samplepaper.tex, a sample chapter demonstrating the
% LLNCS macro package for Springer Computer Science proceedings;
% Version 2.20 of 2017/10/04
%
\documentclass[runningheads, orivec]{llncs}

\usepackage[dvipdfmx]{graphicx}
\usepackage{tikz-cd}
\usepackage{mdframed}
\usepackage{amsmath, amssymb}
\makeatletter
\DeclareFontEncoding{LS2}{}{\@noaccents}
\makeatother
\DeclareFontSubstitution{LS2}{stix}{m}{n}

\DeclareSymbolFont{largesymbolsstix}{LS2}{stixex}{m}{n}

\DeclareMathDelimiter{\lbrbrak}{\mathopen}{largesymbolsstix}{"EE}{largesymbolsstix}{"14}
\DeclareMathDelimiter{\rbrbrak}{\mathclose}{largesymbolsstix}{"EF}{largesymbolsstix}{"15}
\newcommand{\newbrak}[2]{\genfrac{\lbrbrak}{\rbrbrak}{0pt}{}{#1}{#2}}

%\let\Bbbk\relax
%\usepackage[T1]{fontenc}
%\usepackage[straightbraces, mtphbi]{mtpro2}
%\usepackage{textcomp}
%\renewcommand{\rmdefault}{ptm}
%\usepackage[scaled=0.92]{helvet}

\usepackage{stmaryrd}
% Used for displaying a sample figure. If possible, figure files should
% be included in EPS format.
%
% If you use the hyperref package, please uncomment the following line
% to display URLs in blue roman font according to Springer's eBook style:
% \renewcommand\UrlFont{\color{blue}\rmfamily}

\begin{document}
%
\title{Advanced program calculation using typeclass in Coq}
%
%\titlerunning{Abbreviated paper title}
% If the paper title is too long for the running head, you can set
% an abbreviated paper title here
%
\author{Kosuke Murata\inst{1} \and
Emoto Kento\inst{1}}
%
\authorrunning{M. Kosuke and K. Emoto}
% First names are abbreviated in the running head.
% If there are more than two authors, 'et al.' is used.
%
\institute{Kyushu Institute of Technology, Japan\\
\email{murata@pl.ai.kyutech.ac.jp, emoto@ai.kyutech.ac.jp}}
%
\maketitle              % typeset the header of the contribution
%
\begin{abstract}
Program calculation, which is a programming technique to derive efficient but elusive programme from accessible but inefficient programme, is an important activity for developing program optimization.

\keywords{Program calculation \and Functional programming \and Coq \and Interactive theorem proving.}
\end{abstract}
%
%
%
\section{Introduction}

Simple programme tend to be easy to implement, but inefficient and useless. On the contrary, efficient programme are useful but they require difficult programming techniques for implementation. Making ``program efficiency'' and ``easiness of implementation'' compatible is important challenge for study of programming.

Program calculation~\cite{Bird:1988,Bird:1997} is programming technique to derive highly technical and efficient programme from simple and inefficient programme by using rules for programme. Of course, preserving semantics of programme is essential for correctness of program calculations. In this paper, correctness of program calculation means preserving semantics of programme.

For certificating correctness of program calculation, Tesson, et al.~\cite{Tesson:2010} designed a tactic library for program calculation in Coq~\cite{}, which is an interactive theorem prover. Their tactic library has provided tactic notations for write Coq scripts like chains of equality, which is common in program calculation. They also formalized theory of lists~\cite{Bird:1988}, which provides a calculation rules for list-function base on Bird-Meertence Formalism (BMF).

However, not only the list but also several algebraic datatypes (ADTs) such as natural numbers, binary trees and more general trees are essential for functional programming in practice. Fortunately, several studies describe calculation rules for arbitrary ADTs\cite{}. In this paper, we call such rules ``ADT-generic rules.'' ADT-generic rules are stated by using \( F \)-initial algebra and \( F \)-terminal coalgebra for modeling algebraic datatypes, and \emph{recursion schemes} such as catamorphism, anamorphism and paramorphism for modeling programs which can be recursively defined on arbitrary ADTs.

The present paper aims to formalize ADT-generic rules described in Uustalu's paper~\cite{Uustalu:99}, which describes basic ADT-generic rules for basic recursion schemes such as catamorphism and anamorphism, and for little advanced recursion schemes such as futumorphism and histmorphism.

In this study, we emphasize on using shallow embedding as much as possible. For proving theorems about programs by using interactive theorem provers, here are two styles to define semantics of domain languages: shallow embedding and deep embedding. The former is using the semantics of a host language as it as the semantics of a domain language, the latter is to construct another semantics of domain language on a host language. Deep embedding is flexible and has high power of expressions, but it tends to need high-cost proof. Unfortunately, depending on the way of constructing a semantics in the host language, it is difficult to get a ``runnable'' program. On the other hands, shallow embedding is less flexible, but the cost of proof tends to be low. Moreover, it is possible to make proof using a program that can be processed by a host language processing system, that is, it is actually runnable. From the perspective of program calculation in Coq, shallow embedding that uses Gallina, which is a core functional language in Coq, as a domain language makes it possible to safely derivation of runnable Gallina programs.

The organization of this paper is as follows. 後で書く．

\section{Preliminaries}\label{sec2}

In this section, we introduce Coq and its tactic library for program calculation proposed by Tesson, et al.~\cite{Tesson:2010}. We also introduce notions in basic category theory for describing ADT-generic theorems.

\subsection{Overview of Coq and an tactic library for program calculation}

Coq~\cite{} is a popular interactive theorem prover. It based on the calculus of inductive constructions, which is a higher-order typed lambda calculus. It is widely used in computer science field, e.g. program verifications. A Coq script consists of definitions for data types, formula of propositions which we want to prove, and their proofs, and more. Coq proof are written using tactics, which are commands for construct proofs. Coq system has a sub-language Ltac for programming original tactics. Ltac provides \textbf{Tactic Notations} commands, which enable us to use various novel notations in Coq. For the details, see Coq reference manual \cite{}.

Tesson, et al.~\cite{Tesson:2010} designed and implemented a tactic library for program calculation in Coq using Ltac. Their tactic library has provided tactic notations which make it possible to write Coq script like equational reasoning, which is common notation in program calculation. In consideration of maintainability, we re-implemented our own tactic library using the same methods as theirs.

The our library mainly for equational reasoning provides the following three tactics:
\begin{description}
\item{\underline{Tactic 1}.} \verb~Left = ~\( \langle\mathit{term}\rangle \)\verb~ {~ \( \langle\mathit{tactic}\rangle \) \verb~}~
\item{\underline{Tactic 2}.} \verb~= ~\( \langle\mathit{term}\rangle \)\verb~ {~ \( \langle\mathit{tactic}\rangle \) \verb~}~
\item{\underline{Tactic 3}.} \verb~= Right~
\end{description}
Fig. \ref{fig:Progress_of_interactive_proof} shows the Coq script using our library, for a proof of
\[
\forall ~ (x ~ y ~ z : \verb~nat~), ~ x = y \to z = x + x \to x + y = z,
\]
and progress of its interactive proof in Coq IDE. For a goal \( t = s \), tactic 1 starts the proof by rewriting LHS \( t \) to the given \( \mathit{term} \) by using the specified tactic \( \mathit{tactic} \), to produce the next goal \( \mathit{term} = y \). This can be seen in the first step in Fig. \ref{fig:Progress_of_interactive_proof}, althought its specified \( \mathit{term} \) is exactly the same as the LHS of the goal and thus the goal is unchanged. Tactic 2 advance the chain in the similar way; see the 2nd through 4th steps in Fig. \ref{fig:Progress_of_interactive_proof}. Tactic 3 finished the chain. It directly proofs the current goal \( s = s \) by using \textbf{reflexivity}. Note that there term ``\( \verb~d := direction Rightwards~ : \mathsf{Prop}\)'' appearing in the Fig. \ref{fig:Progress_of_interactive_proof} is used to memorize the direction of the chain growth.

To make script more shord and more readable, we implement short hands of these tactics. For instance,
\begin{itemize}
\item{\underline{Tactic \( 2' \)}.} \verb~= ~\( \langle\mathit{term}\rangle \)
\end{itemize}
which is equal to \verb~= ~\( \langle \mathit{term} \)\verb~ { easy }~, and
\begin{itemize}
\item{\underline{Tactic \( 2'' \)}.} \verb~= ~\( \langle\mathit{term}\rangle \)\verb~ { by ~\( \langle\mathit{term}\rangle \) \verb~}~
\end{itemize}
which is equal to \verb~= ~\( \langle \mathit{term} \rangle \)\verb~ { rewrite ~\( \langle \mathit{term} \rangle \)\verb~ + rewrite <- ~\( \langle \mathit{term} \rangle \)\verb~ }~.

\begin{figure}[t]
\centering
\includegraphics[width=0.7\linewidth]{figure2.pdf}

\caption{Progress of interactive proof on Coq IDE}
\label{fig:Progress_of_interactive_proof}
\end{figure}
In this paper, in order to improve readability, we write Coq scripts using roman and san serif fonts such as mathematical expressions, instead of typewriter fonts.

\subsection{Basic notions of category theory}

We use basic notions of category theory for describing ADT-generic theorems. We work on the category \( \mathbf{Set} \), which is category of set and functions.

Given two sets \( A \), \( B \), we write \( A * B \) for product (just like \verb~Coq.Init.Datatypes~, the Coq standard library), and \( A + B \) for sum. We write \( \verb~fst~ : A * B \to A \) and \( \verb~snd~ : A * B \to B \) for the left and right projection function, \( \verb~inl~ : A \to A + B \) and \( \verb~inr~ : B \to A + B \) for the constructors for sum.

We use also following notations, which are non-standard in Coq but familiar in program calculation, just like \cite{Uustalu:99}. For \( f : A \to B \) and \( g : A \to C \), we use \( \langle f, g \rangle : A \to B * C \) for unique morphism \( h \) such that \( \verb~fst~ \circ h = f \) and \( \verb~snd~ \circ h = g \). For \( f : A \to C \) and \( g : B \to C \), we use \( [f, g] : A + B \to C \) for unique morphism \( h \) such that \( h \circ \verb~inl~ = f \) and \( h \circ \verb~inr~ = g \). Fig. \ref{fig:def_product_sum_morphisms}. shows the definitions for such morphisms in Coq.

\begin{figure}[t]
\[
\begin{array}{l}
\mathbf{Definition}~\verb~fprod~~\{A~B~C : \mathsf{Type}\}~(f : A \to B)~(g : A \to C) : A \to B * C := \\
~~\lambda~(x : A) \Rightarrow (f~x, g~x).\\
\mathbf{Definition}~\verb~fsum~~\{A~B~C : \mathsf{Type}\}~(f : A \to B)~(g : A \to C) : A + B \to C := \\
~~\lambda ~ (x : A + B) \Rightarrow \begin{array}[t]{l}
\mathbf{match}~x~\mathbf{with}\\
| ~ \verb~inl~~x \Rightarrow f~x \\
| ~ \verb~inr~~x \Rightarrow g~x \\
\mathbf{end}.
\end{array}\\
\mathbf{Notation}~\verb~"~ \langle f,g \rangle\verb~"~ := (\verb~fprod~~f~g).\\
\mathbf{Notation}~\verb~"~ [ f,g ]\verb~"~ := (\verb~fsum~~f~g).
\end{array}
\]

\caption{The definitions for product and sum of morphisms in Coq}
\label{fig:def_product_sum_morphisms}
\end{figure}

\begin{figure}[t]
\[
\begin{array}{lllclll}
\verb~fst~ \circ \langle f, g \rangle &=& f &\quad& {} [f, g] \circ \verb~inl~ &=& f \\
\verb~snd~ \circ \langle f, g \rangle &=& g && {} [f, g] \circ \verb~inr~ &=& g \\
\langle \verb~fst~, \verb~snd~ \rangle &=& \mathit{id} && [\verb~inl~, \verb~inr~] &=& \mathit{id}
\end{array}
\]

\caption{Rules for product and coproduct}
\end{figure}

We use traditional way for modeling datatypes, which use \( F \)-initial algebras and terminal coalgebras where \( F : \mathbf{Set} \to \mathbf{Set} \) is a polynomial functor. For a polynomial functor \( F : \mathbf{Set} \to \mathbf{Set} \), we write \( ( \mu F , \mathsf{in}_F ) \) for the \( F \)-initial algebra, \( (\nu F , \mathsf{out}_F ) \) for the \( F \)-terminal coalgebra. Note that for any polynomial functor \( F : \mathbf{Set} \to \mathbf{Set} \), there exists unique a \( F \)-initial algebra and a \( F \)-terminal coalgebra up to isomorphism. We also use polynomial functors indexed by constant set \( A \); e.g. \( F_A : \mathbf{Set} \to \mathbf{Set} \) such that \( F_A(X) = \mathbf{1} + A * X \). From the aspect of formilization, indexed functors just like \( F_A(X) \) can be assumed that is partial application of bifunctor \( F : \mathbf{Set} \to \mathbf{Set} \to \mathbf{Set} \).

Let \( F \colon \mathbf{Set} \to \mathbf{Set} \) be a polynomial functor, and \( (\mu F, \mathsf{in}_F) \) be an initial \( F \)-algebra. Given a morphism \( \varphi \colon F\,X \to X \), the morphism \( \llparenthesis \varphi \rrparenthesis \colon F\,\mu F \to \mu F \) is \emph{catamorphism}\footnote{The term `catamorphism' is derived from the greek preposition \(\mathit{\kappa\alpha\tau\alpha}\) meaning `downwards'.} if following diagram commutes:
\[
\begin{tikzcd}
F\,\mu F \ar[d, "{F\;\llparenthesis \varphi \rrparenthesis}"']\ar[r, "{\mathsf{in}_F}"] & \mu F \ar[d, "{\llparenthesis \varphi \rrparenthesis}"] \\
F\,X \ar[r, "{\varphi}"'] & X
\end{tikzcd}.
\]
In other words, \( \llparenthesis f \rrparenthesis \) is characterized by the universal property:
\[
f \circ \mathsf{in}_F = \varphi \circ F\,f \iff f = \llparenthesis \varphi \rrparenthesis .
\]
Anamorphism とかについても後で書く．

\section{Modeling Datatypes in Coq}

In this section, we propose a way to models concepts to model datatypes in Coq. Types and functions in Coq can be regarded as object and morphisms in category \( \mathbf{Set} \).

\begin{figure}[tbhp]
\[
\begin{array}{l}
\mathbf{Inductive}~\verb~PolyF~ : \mathsf{Type} := \\
\begin{array}{llll}
| & \verb~zer~ &:& \verb~PolyF~ \\
| & \verb~one~ &:& \verb~PolyF~ \\
| & \verb~arg1~ &:& \verb~PolyF~ \\
| & \verb~arg2~ &:& \verb~PolyF~ \\
| & \verb~Sum~ &:& \verb~PolyF~ \to \verb~PolyF~ \to \verb~PolyF~ \\
| & \verb~Prod~ &:& \verb~PolyF~ \to \verb~PolyF~ \to \verb~PolyF~ .
\end{array}\\
\\
\mathbf{Inductive}~\verb~inst~~(F : \verb~PolyF~)~(A~X : \mathsf{Type}) : \mathsf{Type} := \\
~~ \mathbf{match}~F~\mathbf{with}\\
~~ \begin{array}{llll}
| & \verb~zer~ &\Rightarrow& \verb~Empty_set~ \\
| & \verb~one~ &\Rightarrow& \verb~Unit~ \\
| & \verb~arg1~ &\Rightarrow& A \\
| & \verb~arg2~ &\Rightarrow& X \\
| & \verb~Sum~~F~G &\Rightarrow& (\verb~inst~~F~A~X) + (\verb~inst~~G~A~X) \\
| & \verb~Prod~~F~G &\Rightarrow& (\verb~inst~~F~A~X) * (\verb~inst~~G~A~X)
\end{array}\\
~~\mathbf{end}.\\
\\
\mathbf{Notation}~\verb~"~ \llbracket F \rrbracket \verb~"~ := (\verb~inst~~F).\\
\\
\mathbf{Fixpoint}~\verb~fmap~~(F : \verb~PolyF~)~\{A_0~A_1~X_0~X_1 : \mathsf{Type}\}\\
\qquad (f : A_0 \to A_1)~ (g : X_0 \to X-1) : \llbracket F \rrbracket ~ A_0 ~ X_0 \to \llbracket F \rrbracket ~ A_1 ~ X_1\\
\qquad :=
\begin{array}[t]{l}
\mathbf{match}~F~\mathbf{with} \\
\begin{array}[t]{llll}
\mid & \verb~zer~ &\Rightarrow& \mathrm{id} \\
\mid & \verb~one~ &\Rightarrow& \mathrm{id} \\
\mid & \verb~arg1~ &\Rightarrow& f \\
\mid & \verb~arg2~ &\Rightarrow& g \\
\mid & \verb~Sum~~F~G &\Rightarrow& \lambda x \Rightarrow
\begin{array}[t]{l}
\mathbf{match}~x~\mathbf{with}\\
\begin{array}{lll}
\verb~inl~~x &\Rightarrow& \verb~inl~~(\verb~fmap~~F~f~g~x) \\
\verb~inr~~x &\Rightarrow& \verb~inr~~(\verb~fmap~~F~f~g~x) \\
\mathbf{end}
\end{array}
\end{array}\\
\mid & \verb~Prod~~F~G &\Rightarrow& \lambda x \Rightarrow (\verb~fmap~~f~g~(\verb~fst~~x), \verb~fmap~~G~f~g~x~(\verb~snd~~x))
\end{array}\\
\mathbf{end}.
\end{array}\\
\\
\mathbf{Notation}~\verb~"~ F [ f ] \verb~"~ := (\verb~@fmap~~F~\_~\_~\_~\_~\mathrm{id}~f)~ (\text{at level 10}).
\end{array}
\]

\caption{The definitions for polynomial functor in Coq}
\label{fig:def_of_initial_alg}
\end{figure}

\subsection{Polynomial Functor}

Fig. \ref{fig:def_of_initial_alg}. shows the definitions for polynomial functor in Coq. Functor consists of following two mappings: mappings from object to object, and mappings from morphisms to morphisms. To define polynomial functor inductively, we first define \( \verb~PolyF~ \), which is the type for AST (Abstract Syntax Tree) of polynomial functor, and then use it to define following two mappings:
\begin{itemize}
\item \( \llbracket F \rrbracket : \mathsf{Type} \to \mathsf{Type} \to \mathsf{Type}\)  (\( \verb~inst~~F \)) is to map from types to types.
\item \( F\lbrbrak {-} \rbrbrak [{-}] \colon (A_0 \to A_1) \to (X_0 \to X_1) \to \llbracket F \rrbracket ~ A_0 ~ X_0 \to \llbracket F \rrbracket ~ A_1 ~ X_1 \)(\verb~fmap~) is mapping from morphisms to morphisms.
\end{itemize}
These definitions are for bifunctor, but we can get definitions for functor by partial applications, i.e. \( \llbracket F \rrbracket ~ A \) and \( F[@\mathrm{id}~A]({-}) \) define a functor (indexing by type \( A \)).

Polynomial functors must satisfy the functor laws, so we proved following 2 lemmas for functor laws by using easy induction on \( F \).
\begin{itemize}
\item
\(\begin{array}[t]{l}
\mathbf{Lemma}~ \verb~fmap_functor_distr~ : \\
\quad \forall ~ (F : \verb~PolyF~) ~ \{ A ~ X_0 ~ X_1 ~ X_2 : \mathsf{Type} \} ~ (g_0 : X_0 \to X_1) ~ (g_1 : X_1 \to X_2), \\
\qquad F \lbrbrak @ \mathrm{id}~A \rbrbrak [g_1 \circ g_0] = F [g_1] \circ F [g_0]
\end{array}
\)

\item \(\begin{array}[t]{l}
\mathbf{Lemma}~ \verb~fmap_functor_id~ : \\
\quad \forall ~ (F : \verb~PolyF~) ~ \{ A ~ X : \mathsf{Type} \} ~ (g_0 : X_0 \to X_1) ~ (g_1 : X_1 \to X_2), \\
\qquad F \lbrbrak @ \mathrm{id}~A \rbrbrak [\verb~@~\mathrm{id}~X] = \mathrm{id}
\end{array}
\)
\end{itemize}

Next, we define \( F \)-initial algebras using type class. Fig. \ref{fig:f_initial_alg}. shows the definitions for \( F \)-initial algebras using type class in Coq.

\begin{figure}[t]
\[
\begin{array}{l}
\mathbf{Class}~\begin{array}[t]{l}
\verb~F_initial_algebra~~(F : \verb~PolyF~)~(A : \mathsf{Type})~(\mu F : \mathsf{Type}) \\
(c : \forall ~ (X : \mathsf{Type}), (\llbracket F \rrbracket ~ A ~ X \to X) \to ( \mu F \to X) ) :=
\end{array} \\
~~\{\\
~~~~\begin{array}{lll}
\verb~cata~ := c; \\
\verb~in_~ &:& \llbracket F \rrbracket ~ A ~ \mu F \to \mu F ; \\
\verb~cata_charn~ &:& \forall ~ (X : \mathsf{Type})~(f : \mu F \to X)~ (\varphi : \llbracket F \rrbracket ~ A ~ X \to X),\\
&&~~~~ f \circ \verb~in_~ = \varphi \circ F[f] \leftrightarrow f = \verb~cata~~X~\varphi
\end{array}\\
~~\}.\\
\\
\mathbf{Notation}~\verb~"~\llparenthesis f \rrparenthesis\verb~"~ := (\verb~cata~~\_~\_~f)~(\text{at level 5}).
\end{array}
\]

\caption{Definitions for \( F \)-initial algebras using type class in Coq}
\label{fig:f_initial_alg}
\end{figure}

Initial algebras and catamorphisms satisfy the following 3 properties, where
\[
\mathbf{Variable}~\begin{array}[t]{l}
(F : \verb~PolyF~) ~ (A : \mathsf{Type}) ~ ( \mu F : \mathsf{Type}) \\
(c : \forall ~ (X : \mathsf{Type}), ~ (\llbracket F \rrbracket ~ A ~ X \to X) \to (\mu F \to X) ) \\
(\mathit{ia} : \verb~F_initial_algebra~ ~ F ~ A ~ \mu F ~ c).
\end{array}
\]
\begin{itemize}
\item \(
\begin{array}[t]{l}
\mathbf{Proposition}~\verb~cata_cancel~ : \\
\qquad \forall ~ (X~Y : \mathsf{Type}) ~ (\varphi : \llbracket F \rrbracket ~ A ~ X \to X), \\
\qquad\qquad \llparenthesis \varphi \rrparenthesis \circ \verb~in_~ = \varphi \circ F[\llparenthesis \varphi \rrparenthesis].
\end{array}
\)

\item \(\mathbf{Proposition}~\verb~cata_refl~ : \llparenthesis \verb~in_~ \rrparenthesis = \mathrm{id}\)

\item \(
\begin{array}[t]{l}
\mathbf{Proposition}~\verb~cata_fusion~ : \\
\qquad \forall ~ (X~Y : \mathsf{Type}) ~ (\varphi : \llbracket F \rrbracket ~ A ~ X \to X) ~ (\psi : \llbracket F \rrbracket ~ A ~ Y \to Y) ~ (f : X \to Y ), \\
\qquad\qquad f \circ \varphi = \psi \circ F[f] \to f \circ \llparenthesis \varphi \rrparenthesis = \llparenthesis \psi \rrparenthesis.
\end{array}
\)
\end{itemize}
Fig. \ref{fig:proof_catamorphism} shows the Coq proof of \verb~cata_fusion~.

\begin{figure}[t]
\[
\begin{array}{l}
\mathbf{Proposition}~\verb~cata_fusion~ : \\
\qquad \forall ~ (X~Y : \mathsf{Type}) ~ (\varphi : \llbracket F \rrbracket ~ A ~ X \to X) ~ (\psi : \llbracket F \rrbracket ~ A ~ Y \to Y) ~ (f : X \to Y ), \\
\qquad\qquad f \circ \varphi = \psi \circ F[f] \to f \circ \llparenthesis \varphi \rrparenthesis = \llparenthesis \psi \rrparenthesis.\\
\mathbf{Proof}.\\
\quad \begin{array}[t]{ll}
\verb~intros~; ~ \verb~apply~ ~\verb~cata_charn~. \\
\mathbf{Left} \\
= (f \circ ( \llparenthesis \varphi \rrparenthesis \circ \verb~in_~ )). \\
= ( f \circ \varphi \circ F[\llparenthesis \varphi \rrparenthesis ] ) & \{ \mathbf{by} ~ \verb~cata_cancel~ \}. \\
= ( \psi \circ (F[f] \circ F[\llparenthesis \varphi \rrparenthesis ])) & \{ \mathbf{by} ~ H \}. \\
= ( \psi \circ F[f \circ \llparenthesis \varphi \rrparenthesis ] ) & \{ \mathbf{by} ~ \verb~fmap_functor_distr~ \}. \\
= \mathbf{Right}.\\
\end{array}\\
\mathbf{Qed}.
\end{array}
\]

\caption{A coq proof for catamorphism fusion-law, using tactic libraries}
\label{fig:proof_catamorphism}
\end{figure}

\subsection{Instanciation of the Class for initial algebra}

As a benefit of using type class for definition for initial algebra, it is possible to use the theorems for runnable Coq programs.

First, we give an example of making \verb~nat~ an instance of \verb~F_initial_algebra~, where \verb~nat~ is standard type of natural numbers in Coq. The catamorphism of nat can define as follows:
\[
\begin{array}{l}
\mathbf{Definition}~\verb~cata_nat~~(X : \mathsf{Type})~(f : \verb~unit~ + X \to X) : \verb~nat~ \to X :=\\
\qquad \mathbf{fix}~\verb~cataf~~(n : \verb~nat~) := \begin{array}[t]{l}
       \mathbf{match}~n~\mathbf{with}\\
       \begin{array}{llll}
       | & \verb~O~    &\Rightarrow& f ~ (\verb~inl~ ~ ()) \\
       | & \verb~S~ ~ n' &\Rightarrow& f ~ (\verb~inr~ ~ (\verb~cataf~ ~ n'))
       \end{array}\\
       \mathbf{end}.
       \end{array}
\end{array}
\]
Now, we can define \verb~Nat_IA~, which is an instance of \verb~F_initial_algebra~, as follows.
\[
\begin{array}{l}
\mathbf{Instance}~\verb~Nat_IA~ : \\
\qquad \verb~F_initial_algebra~~(\verb~Sum~~\verb~one~~\verb~arg2~)~\verb~unit~~\verb~cata~~\verb~cata_nat~ :=\\
\qquad \{\\
\qquad \qquad \verb~in_~ := [\lambda ~ x \Rightarrow \verb~O~, ~ \verb~S~];\\
\qquad \}.\\
\end{array}
\]
There are incomplete proofs of \verb~cata_charn~, but the proof is easy to complete (see Appendix). \verb~Nat_IA~ make us possible to evaluate catamorphisms in \verb~nat~, therefore, if Coq system reads following command:
\[
\mathbf{Eval}~\mathrm{cbv}~\mathrm{in}~ (\lambda (y : \verb~nat~) \Rightarrow \llparenthesis [ \lambda \_ \Rightarrow y, S ] \rrparenthesis) ~ 100 ~ 11.
\]
it will return the answer, 111.

\section{More advanced recursion schemes}

\section{Related Work}

Furthermore, some research\cite{} uses interactive theorem prover such as Coq and Agda.

\section{Conclusion and Future Work}

%
% ---- Bibliography ----
%
% BibTeX users should specify bibliography style 'splncs04'.
% References will then be sorted and formatted in the correct style.
%
\bibliographystyle{splncs04}
\bibliography{bibliography}
%

\appendix
\section{Coq Proof for Instantiation of Nat}

{\small
\begin{verbatim}
Instance Nat_ia :
  F_initial_algebra (Sum one arg2) unit nat cata_nat :=
  {
    in_  := [ fun x => O , S ];
  }.
Proof.
  intros X f φ.
  split.
  - intros H. unfold cata_nat.
    extensionality x.
    induction x.
    + specialize (equal_f H (inl tt)) as H0; cbv in H0.
      exact H0.
    + specialize (equal_f H (inr x)) as H1; cbv in H1.
      rewrite <- IHx.
      exact H1.
  - intros H; extensionality x; induction x.
    + rewrite H. induction a. easy.
    + rewrite H; easy.
Qed.
\end{verbatim}
}

\end{document}


\documentclass[12pt]{article}
\usepackage{times}
\usepackage{alltt}

\begin{document}

\title{Machine extraction}
\author{Simon Thompson}
\date{G\"{o}teborg, August 2011}
\maketitle

\section{Overview}

\begin{itemize}
\item Formalise process of traces to QSM state machine
\item Formalise processes from QSM state machine to QuickCheck FSM.
\end{itemize}

\section{Traces to QSM state machine}

\subsection{Basic QSM}

Definition of concrete traces:
\begin{verbatim}
item  ::= {module, function, arguments, result}
trace ::= {pos, item*} | {neg, item*}
\end{verbatim}
If $T$ is a set of traces then \texttt{t} is a positive trace if \texttt{\{pos,t\}}
\ensuremath{\in T}; similarly for negative traces.

An abstraction function is a function
\begin{alltt}
\ensuremath{\alpha} :: \{module, function, arguments, result\} -> \ensuremath{\cal{A}}
\end{alltt}
for some type $\cal{A}$.. The \emph{abstract traces} are given by \texttt{\{pos,map(abs,t)\}} and \texttt{\{neg,map(abs,t)\}}.

A set $T$ of traces is \emph{consistent} iff for all \texttt{\{neg,t\}} \ensuremath{\in T} and for all \texttt{\{pos,t'\}}\ensuremath{\in T}, \texttt{t} is not an initial segment of \texttt{t'}.

The QSM algorithm builds a deterministic state machine from a consistent set of traces. The construction fails if applied to an inconsistent set. The  machine built, ${\cal{M}}_T = <{\cal{S}}, s_0, \cal{F}, \cal{T}>$, has the form
\begin{itemize}
\item
$\cal{S}$ is a non-empty finite set of states,
\item
$s_0 \in \cal{S}$ is the initial state of the system,
\item
$\cal{F} \subseteq \cal{S}$ is a set of failing states, and
\item
$\cal{T}$ is a set of transitions of the form $(s_1,a,s_2)$ where $s_i \in \cal{S}$ and $a \in \cal{A}$.
\end{itemize}
For states $s_1$ and $s_{k+1}$ and a trace \texttt{t} = $a_1{}a_2{}\ldots{}a_k$ we write $s_1 \stackrel{\texttt{t}}{\rightarrow} s_{k+1}$ if for each $i=1\ldots{}k$ there is some $a_i$ so that $(s_i,a_i,s_{i+1}) \in \cal{T}$.

We say that the machine ${\cal{M}}_T$ \emph{accepts} \texttt{t} if $s_0 \stackrel{\texttt{t}}{\rightarrow} s$ with $s \not \in \cal{F}$; the machine \emph{rejects} \texttt{t} if $s_0 \stackrel{\texttt{t}}{\rightarrow} s$ with $s \in \cal{F}$, or there is no path through the machine ${\cal{M}}_T$ labelled by \texttt{t}. Since the machine is deterministic, each trace will either be accepted or rejected by the machine, but not both.

The crucial property of the machine ${\cal{M}}_T$ is that
for all positive traces \texttt{t} in $T$, ${\cal{M}}_T$ accepts \texttt{t}, and
for all negative traces \texttt{t} in $T$, ${\cal{M}}_T$ rejects \texttt{t}. This is true by construction.

\subsection{Abstractions and QSM}

We have written ${\cal{M}}_T$ for the machine inferred from a set of traces $T$, which might be concrete or might arise from an abstraction of a concrete set. In this section we'll work with a fixed set of concrete traces, and use $T_\alpha$ for the set of traces after abstraction and ${\cal{M}}_\alpha$ for the machine generated from $T_\alpha$.

It would be nice to relate machines produced for related abstractions, e.g.\ in the case where an abstraction is a composition of two others, with $ \alpha = \beta \circ \gamma$. However, even in the case of relating machines for concrete and abstract sets of traces, ${\cal M}_{id}$ and ${\cal M}_\alpha$, this is not possible in general since the machines generated by the QSM algorithm are not canonical: depending on the order in which states are handled by the algorithm, different machines result.

\subsection{SM: state machines}

A \emph{state machine} of type $\cal D$ has the form ${\cal{M}} = \;<{\cal{S}}, s_0, {\cal T}, d_0, \eta, \phi, \psi>$
\begin{itemize}
\item
$\cal{S}$ is a non-empty finite set of states,
\item
$s_0 \in \cal{S}$ is the initial state of the system,
\item
$\cal{T}$ is a set of transitions of the form $(s_1,a,s_2)$ where $s_i \in \cal{S}$ and $a \in \cal{A}$.
\item
$d_0 \in \cal D$ is the initial value of the state data,
\item
$\eta$ is a partial function
\[
\eta :: \{{\cal S},{\cal A},{\cal D}\} \rightarrow \cal D
\]
taking a state, an action and the value of the state data before the transition to the value after,
\item
$\phi, \psi$ are partial functions
\[
\phi, \psi :: \{{\cal S},{\cal A},{\cal D}\} \rightarrow \cal B
\]
where $\cal B$ is the Boolean type. These are the pre- and post-conditions of the transition from the given state, action and value of the state data.

\end{itemize}

\end{document}


%\newpage
\section{Conclusion and Future Work} \label{conclusion_and_future_work}

In this work we have proposed a novel sliding window filter for more efficient event detection in time series streams, which replaces computational expensive dissimilarity comparisons by less demanding statistical measures. Furthermore, we have demonstrated that the developed filter is able to recognize gestures in continuous streams of acceleration data with high accuracy, while cutting the number of distance calculations in half.

Possible applications do not only include event detection on mobile device with few hardware resources, but also distributed sensor networks with limited bandwidth that communicate high level information instead of transferring raw data. In future work we plan to investigate a larger variety of statistical measures that exhibit favorable filtering properties for online gesture recognition as well as data streams found in other domains.


\section{Selective functors}\label{sec-selective}

...

\begin{minted}[xleftmargin=10pt]{haskell}
class Applicative f => Selective f where
    select :: f (Either a b) -> f (a -> b) -> f b
\end{minted}


\subsection{Leave-One-Out}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Quick Reference for tswge
%
%
% Sources:
% https://github.com/sjmiller8182/LearningTS/blob/master/notes/tex/tswge_quick_reference.tex
% https://github.com/sjmiller8182/LearningTS/blob/master/notes/tswge_quick_reference.pdf
%
% Provided freely under the MIT license
%
% Feel free to distribute, but keep this and the following referral.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% writeLaTeX Example: A quick guide to LaTeX
%
% Source: Dave Richeson (divisbyzero.com), Dickinson College
%
% A one-size-fits-all LaTeX cheat sheet. Kept to two pages, so it
% can be printed (double-sided) on one piece of paper
%
% Feel free to distribute this example, but please keep the referral
% to divisbyzero.com
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[a4paper]{article}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{multicol,multirow}
\usepackage{calc}
\usepackage{ifthen}
\usepackage[landscape]{geometry}
\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref}

\ifthenelse{\lengthtest { \paperwidth = 11in}}
{ \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
{\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
	{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
	{\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
}

\pagestyle{empty}
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
	{-1ex plus -.5ex minus -.2ex}%
	{0.5ex plus .2ex}%x
	{\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
	{-1explus -.5ex minus -.2ex}%
	{0.5ex plus .2ex}%
	{\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
	{-1ex plus -.5ex minus -.2ex}%
	{1ex plus .2ex}%
	{\normalfont\small\bfseries}}
\makeatother
\setcounter{secnumdepth}{0}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}
% -----------------------------------------------------------------------

\title{tswge Quick Reference}

\begin{document}

	\raggedright
	\footnotesize

	\begin{center}
		\Large{\textbf{\texttt{tswge} Quick Reference}} \\
	\end{center}
	\begin{multicols}{3}
		\setlength{\premulticols}{1pt}
		\setlength{\postmulticols}{1pt}
		\setlength{\multicolsep}{1pt}
		\setlength{\columnsep}{2pt}

		\section{Plotting}

		\begin{itemize}
			\item \texttt{plotts.wge} - plot a realization
			\item \texttt{plotts.sample.wge} - 4 sample plots (realization, parzen window, periodogram, spectral density)
			\item \texttt{plotts.parzen.wge} - parzen window (can be truncated)
			\item \texttt{plotts.true.wge} - true ACF and true spectral density
		\end{itemize}

		\section{Factor Analysis}

		\begin{itemize}
			\item \texttt{factor.wge} - factor characteristic equations into 1st and 2nd order components
			\item \texttt{factor.comp.wge} - decompose a sampled signal into factors
			\item \texttt{mult.wge} - multiply together factors (up to 6)
			\begin{itemize}
				\item Use \texttt{\$model.coef} to access the coefficients
			\end{itemize}
		\end{itemize}

		\section{Simulation}

		\begin{itemize}
			\item \texttt{gen.sigplusnoise.wge} - linear or sinusiod signal with normal noise
			\begin{itemize}
				\item Linear model: \texttt{b0, b1}
				\item Sinusiod: \texttt{coef, freq, psi} (2 component vectors)
				\item AR noise: \texttt{phi}
			\end{itemize}
			\item \texttt{gen.arma.wge} - arma signals
				\begin{itemize}
					\item \texttt{p}: AR vector
					\item \texttt{q} MA vector
				\end{itemize}
			\item \texttt{gen.arima.wge} - arima signals
				\begin{itemize}
					\item \texttt{p}: AR vector
					\item \texttt{q}: MA vector
					\item \texttt{d}: Difference order
				\end{itemize}
			\item \texttt{gen.aruma.wge} - aruma signals
				\begin{itemize}
					\item \texttt{p}: AR vector
					\item \texttt{q}: MA vector
					\item \texttt{d}: Difference order
					\item \texttt{s}: Seasonality
					\item \texttt{lambda}: Other non-stationary components
				\end{itemize}
		\end{itemize}

		\section{Forecast}

		\begin{itemize}
			\item \texttt{fore.arma.wge} - forecast arma signals
			\begin{itemize}
				\item \texttt{x}: The series
				\item \texttt{theta}: MA vector
				\item \texttt{phi}: AR vector
				\item \texttt{n.ahead}: Number of forecast steps
				\item \texttt{lastn}: Use last \texttt{n.ahead} values to validate forecast
			\end{itemize}
			\item \texttt{fore.aruma.wge} - forecast aruma signals
			\begin{itemize}
				\item \texttt{x}: The series
				\item \texttt{theta}: MA vector
				\item \texttt{phi}: AR vector
				\item \texttt{d}: Number of difference factors
				\item \texttt{s}: Seasonality factor
				\item \texttt{n.ahead}: Number of forecast steps
				\item \texttt{lastn}: Use last \texttt{n.ahead} values to validate forecast
			\end{itemize}
		\end{itemize}

		\section{Model Fitting}

		\begin{itemize}
			\item \texttt{aic5.wge} - fit models for given orders and return top 5
				\begin{itemize}
					\item \texttt{x}: The series
					\item \texttt{p}: Vector of orders
					\item \texttt{q}: Vector of orders
					\item \texttt{type}: Penalty \{ \texttt{'AIC'} (default), \texttt{'AICC'}, \texttt{'BIC'} \}
				\end{itemize}
			\item \texttt{est.ar.wge} - fit an AR model
				\begin{itemize}
					\item \texttt{x}: The series
					\item \texttt{p}: AR model to fit
					\item \texttt{type}: Fit method \{ \texttt{'mle'} (default), \texttt{'burg'}, \texttt{'yw'} \}
				\end{itemize}
			\item \texttt{est.arma.wge} - fit an AR model
				\begin{itemize}
					\item \texttt{x}: The series
					\item \texttt{p}: AR order to fit
					\item \texttt{q}: MA order to fit
				\end{itemize}
		\end{itemize}

		\section{Filtering}

		\begin{itemize}
			\item \texttt{artrans.wge} - apply an AR-type transformation to a series
			\begin{itemize}
				\item First order difference: \texttt{artrans.wge(x, phi.tr = 1)}
				\item Subtract monthly difference: \texttt{artrans.wge(x, phi.tr = c(rep(0,11),1))}
			\end{itemize}
			\item \texttt{butterworth.wge} - apply a butterworth filter a time series
			\item \texttt{stats::filter} - general function for filtering e.g.
			5-pt MA Filter: \texttt{stats::filter(X\_t, rep(1,5)/5)}
		\end{itemize}

	\end{multicols}

\end{document}