%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Based on Large Colored Title Article
% LaTeX Template
% Version 1.1 (25/11/12)
%
% Original author:
% Frits Wenneker (http://www.howtotex.com)
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[DIV=calc, paper=a4, 11pt, twocolumn]{scrartcl}

\usepackage[style=phys,citestyle=authoryear,maxcitenames=2]{biblatex}
\addbibresource{stats-report.bib}

\usepackage[page]{appendix}

\usepackage{amsmath,amssymb,commath,mathabx,mathtools,physics,siunitx}
\usepackage{aas_macros}
\usepackage{float,placeins,subcaption}
\usepackage[hidelinks=true]{hyperref}
\usepackage[protrusion=true,expansion=true]{microtype} % Better typography
\usepackage[svgnames]{xcolor} % Enabling colors by their 'svgnames'
\usepackage{fix-cm}	 % Custom font sizes - used for the initial letter in the document

\usepackage{sectsty} % Enables custom section titles
\allsectionsfont{\usefont{OT1}{phv}{b}{n}} % Change the font of all section commands

\usepackage{fancyhdr} % Needed to define custom headers/footers
\pagestyle{fancy} % Enables the custom headers/footers
\usepackage{lastpage} % Used to determine the number of pages in the document (for "Page X of Total")

% Headers - all currently empty
\lhead{}
\chead{}
\rhead{}

% Footers
\lfoot{}
\cfoot{}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}} % "Page 1 of 2"

\renewcommand{\headrulewidth}{0.0pt} % No header rule
\renewcommand{\footrulewidth}{0.4pt} % Thin footer rule

\usepackage{lettrine} % Package to accentuate the first letter of the text
\newcommand{\initial}[1]{ % Defines the command and style for the first letter
\lettrine[lines=3,lhang=0.3,nindent=0em]{
\color{DarkRed}
{\textsf{#1}}}{}}

%% Custom Units %%
\DeclareSIUnit{\parsec}{pc}
\DeclareSIUnit{\Msun}{M_\odot}
\DeclareSIUnit{\Lsun}{L_\odot}

\usepackage{titling} % Allows custom title configuration

\newcommand{\HorRule}{\color{DarkGoldenrod} \rule{\linewidth}{1pt}} % Defines the gold horizontal rule around the title

\pretitle{\vspace{-30pt} \begin{flushleft} \HorRule \fontsize{40}{40} \usefont{OT1}{phv}{b}{n} \color{DarkRed} \selectfont} % Horizontal rule before the title

\title{
\hspace{-0.75cm} Searching in the Dark
\\
Chasing Magnum Opus
}
\posttitle{\par\end{flushleft}\vskip 0.5em} % Whitespace under the title

\preauthor{\begin{flushleft}\large \lineskip 0.5em \usefont{OT1}{phv}{b}{sl} \color{DarkRed}} % Author font configuration

\author{
  Jacob Lange, Chi Nguyen, Daniel Wysocki
}

\postauthor{\footnotesize \usefont{OT1}{phv}{m}{sl} \color{Black} % Configuration for the institution name
Rochester Institute of Technology % Your institution

\par\end{flushleft}\HorRule} % Horizontal rule after the title

\date{
  Statistical Methods for Astrophysical Sciences (ASTP-611)
  \\
  Spring 2016
}

\begin{document}

\maketitle

\thispagestyle{fancy} % Enabling the custom headers/footers for the first page

%%%%%%%%%%%%%%%%
% INTRO
% Everyone
%%%%%%%%%%%%%%%%
\input{sec_intro}

%%%%%%%%%%%%%%%%
% QUESTION 1
% Dan & Chi
%%%%%%%%%%%%%%%%
\section{Chirp Mass Distribution}
\label{sec:dist}

\input{subsec_density_estimation} % Q1.1, Dan
\input{subsec_likelihood} % Q1.2, Chi
\input{subsec_fitting} % Q1.3, Chi

%%%%%%%%%%%%%%%%
% QUESTION 2
% Jake
%%%%%%%%%%%%%%%%

\section{Classification}
\label{sec:classifier}
\input{sec_classification} % Jake

\section{Conclusions}
\label{sec:conclusions}
\input{sec_conclusions}

\printbibliography

\end{document}


\documentclass{beamer}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsrefs}
\usepackage{graphicx}

\mode<presenation>
{ \usetheme{boxes} }

%\AtBeginSection[]{
%  \begin{frame}<beamer>
%  \frametitle{R\'esum\'e}
%  \tableofcontents[currentsection]
%  \end{frame}
%}

\title{Knot thickness computation in parallel}
\author{Mathias Carlen}
\date{11 june 2009}

\begin{document}

\frame{\titlepage}
\frame{\frametitle{Content}\tableofcontents}

%skeleton
%\section{Test}
%\frame{
%  \frametitle{1. titre}
%  \begin{itemize}
%  \item<2-> Bla 1
%  \item<3-> Bla bla 2
%  \end{itemize}
%}

\section{Curves and thickness}

\begin{frame}
\frametitle{Curves and thickness}

\begin{itemize}
 \item<1-> closed curve $\gamma(s)$, with $s$ arclength param.
 \item<2-> knot class
 \item<3-> maximal thick tube $\longrightarrow$ thickness $\Delta$.
\end{itemize}
\vspace{1cm}
\pause
\pause
\pause
\includegraphics[height=2cm]{global.pdf}\hspace{.2cm}
\pause
\includegraphics[height=2cm]{local.pdf}
\pause
\[
\Delta = min ( min_s r(s) , min_{dc} \frac{\gamma(s)-\gamma(t)}{2} )
\]
\end{frame}

\section{Motivation}
\begin{frame}
\frametitle{Motivation}
\begin{itemize}
\item<1-> Why parallelize?
\item<2-> Minimize $L[\gamma]/\Delta[\gamma]$
\item<3-> Monte carlo
\item<4-> Animation
\end{itemize}
\end{frame}

\section{Thickness Algorithm}

\begin{frame}
\frametitle{Thickness Algorithm}
\begin{itemize}
\item[(1)]<1-> Discretize $\gamma$ with biarcs
\item[(2)]<2-> Compute smallest local radius $r_i$
\item[(3)]<3-> Prepare a set of candidate arc pairs $(a_i,b_i)$
\item[(4)]<4-> Compute minimal distance between arcs
\item[(5)]<5-> Double criticality test
\item[(6)]<6-> Distance test
\item[(7)]<7-> Bisect remaining arc pairs ($1$ pair -> $4$ pairs)
\item[(8)]<8-> If not below some tolerance goto 4
\item[(9)]<9-> Return thickness
\end{itemize}
\end{frame}

\section{Parallelization}
%\subsection{Master/Slave work}
%\subsection{MPI}
%\subsection{Implementation details}
%\subsubsection{Custom datatypes}
%\subsubsection{Batching}

\begin{frame}
\frametitle{Parallelization (1)}
\includegraphics[height=.8\textheight]{parallel_algo_flowchart.pdf}
\end{frame}

\begin{frame}
\frametitle{Parallelization (2)}
\begin{itemize}
\item<1-> MPI
\item<2-> custom datatype \texttt{struct Candidate}
\item<3-> batching candidates
\end{itemize}
\end{frame}

\section{Experiments and benchmarks}
%\subsection{Hardware/Software used}
%\subsection{CPUs}
%\subsection{Knot data points}
%\subsection{Batching}
%\subsection{Knot shapes}
%\subsection{Master/slaves timing}

\begin{frame}
\frametitle{Experiments and benchmarks (1)}
Computed on cluster \texttt{lcvmlc2} using \texttt{mpich-mx}. \\
\vspace{.5cm}
\pause
Time vs. number of CPUs \\
\includegraphics[width=.75\textwidth]{time_vs_cpus.pdf}
\end{frame}

\begin{frame}
\frametitle{Experiments and benchmarks (2)}
Time vs. discretization \\
\includegraphics[width=.75\textwidth]{time_vs_nodes.pdf}
\end{frame}

\begin{frame}
\frametitle{Experiments and benchmarks (3)}
Time vs. batching \\
\includegraphics[width=.75\textwidth]{time_vs_batch.pdf}
\end{frame}

\begin{frame}
\frametitle{Experiments and benchmarks (4)}
Time vs. knot type \\
\includegraphics[width=.75\textwidth]{time_vs_knots.pdf}
\end{frame}

\begin{frame}
\frametitle{Experiments and benchmarks (5)}
Master/Slave timing \\[1cm]
\begin{tabular}{lclll}
knot & data points & master (sec) & slaves (sec) & total (sec) \\
j3.1 & 512 & 0.165336 & 2.092650 & 2.258000 \\
k3.1 & 160 & 0.016368 & 0.016206 & 0.032578 \\
k4.1 & 208 & 0.024819 & 0.018046 & 0.042868 \\
k5.1 & 232 & 0.031302 & 0.000165 & 0.031471 \\
k6.1 & 280 & 0.042829 & 0.000162 & 0.042995 \\
\end{tabular}
\end{frame}

\section{Possible improvements}
%\subsection{Master idle or not}
%\subsection{Master computes, interrupt system?}
%\subsection{Best value broadcast}
%\subsection{Optimize master initialization step}

\begin{frame}
\frametitle{Possible improvements}
\begin{itemize}
\item<1-> Master idle/working
\item<2-> Master computing (interrupt system)
\item<3-> Broadcast best current value
\item<4-> Optimize master init step
\end{itemize}
\end{frame}

\end{document}


\section{Gaussian Distributions}

The behaviour of all quantitative traits of the dataset is assumed to adhere to a
Gaussian Distribution.
This assumption is taken due to how the values of the data set are presented.
As shown in Figures
% \ref{fig: sepal length normal distribution},
% \ref{fig: sepal width normal distribution},
\ref{fig: petal length normal distribution} and
\ref{fig: petal width normal distribution}
the distribution for each flower variety follows the
general behaviour of the Gaussian Distribution.

Having confirmed that all quantitative features of the dataset
adhere to Gaussian Distributions, it is possible to proceed with the
development of the classifiers.

% \begin{figure}[htb!]
%  \includegraphics[width=\textwidth]{normSepalLength}
%  \caption{Sepal Length}
%  \label{fig: sepal length normal distribution}
% \end{figure}
%
% \begin{figure}[htb!]
%  \includegraphics[width=\textwidth]{normSepalWidth}
%  \caption{Sepal Width}
%  \label{fig: sepal width normal distribution}
% \end{figure}

\begin{figure}[htb!]
 \includegraphics[width=\textwidth]{normPetalLength}
 \caption{Petal Length}
 \label{fig: petal length normal distribution}
\end{figure}

\begin{figure}[htb!]
 \includegraphics[width=\textwidth]{normPetalWidth}
 \caption{Petal Width}
 \label{fig: petal width normal distribution}
\end{figure}

\pagebreak
\newpage


\documentclass[12pt]{article}
\pdfoutput=24
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{esvect}

\usepackage[toc,page]{appendix}

\usepackage{leftidx}
\usepackage{color}
\usepackage{framed, color}
\usepackage{multirow}
% \usepackage{pdfpages}
\usepackage{multicol}
\usepackage{wrapfig, booktabs}
\usepackage[font=small,skip=0pt]{caption}

\usepackage[utf8]{inputenc}
\usepackage{mathtools, hyperref}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=cyan,
    filecolor=cyan,
    urlcolor=blue,
    citecolor=red,
}

\usepackage{cleveref}
\usepackage{commath}
\usepackage{enumitem}
\usepackage{amssymb}
\renewcommand{\qedsymbol}{$\blacksquare$}
%%%%%%%%%%%
%%%%%%%%%%%  User Defined Commands. (macros)
%%%%%%%%%%%

\definecolor{mgreen}{RGB}{25,147,100}
\definecolor{shadecolor}{rgb}{1,.8,.1}
\definecolor{shadecolor2}{RGB}{245,237,0}
\definecolor{orange}{RGB}{255,137,20}
\definecolor{orange}{RGB}{245,37,100}

%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%        Theorem Styles
%%%%%%%%%%%%%%%%%
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{prop}{Proposition}[section]
\newtheorem{corr}{Corollary}[section]
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{remark}{Remark}[section]
\newtheorem{fact}{Fact}[section]

\usepackage[english]{babel}
\usepackage{babel,blindtext}
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{exmp}{Example}[section]
\usepackage{fullpage}
\usepackage{amsfonts}
\usepackage{lscape}
\usepackage{bbm}

\usepackage[x11names, dvipsnames]{xcolor}

\usepackage{todonotes} % makes problem with xcolor package, if loaded before
\usepackage{cite}
\usepackage{verbatim}
\usepackage{bm}

\DeclareMathOperator*{\argmax}{arg\,max}
\usepackage[ textwidth = 15cm]{geometry}
\providecommand{\keywords}[1]{\textbf{\textit{Keywords:---}} #1}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{authblk}
\usepackage{cite}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Code style
%%%%%%%%%%%%%%%%%
\usepackage{lipsum}
\newlength{\seplinewidth}
\newlength{\seplinesep}
\setlength{\seplinewidth}{1mm}
\setlength{\seplinesep}{2mm}

\colorlet{sepline}{PaleVioletRed3}
\newcommand*{\sepline}{%
  \par
  \vspace{\dimexpr\seplinesep+.5\parskip}%
  \cleaders\vbox{%
    \begingroup % because of color
      \color{sepline}%
      \hrule width\linewidth height\seplinewidth
    \endgroup
  }\vskip\seplinewidth
  \vspace{\dimexpr\seplinesep-.5\parskip}%
}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{}
\lfoot{Page \thepage}
\rfoot{h.noorazar@yahoo.com}
\renewcommand{\footrulewidth}{2pt}
\futurelet\TMPfootrule\def\footrule{{\color{Cerulean}\TMPfootrule}}

%\lhead{Help}
\renewcommand{\headrulewidth}{0pt}
%\futurelet\TMPfootrule\def\headrule{{\color{Cerulean}\TMPfootrule}}
\def\code#1{\textbf{\texttt{#1}}}
\def\vari#1{{\color{Cerulean}{\textbf{\texttt{#1}}}}}
\def\func#1{{\color{Maroon}{\textbf{\texttt{#1}}}}}
\newenvironment{coded}{\color{blue}\code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*{\affaddr}[1]{#1} % No op here. Customize it for different styles.
\newcommand*{\affmark}[1][*]{\textsuperscript{#1}}
%\newcommand*{\email}[1]{\texttt{#1}}

\title{\textbf{How to use code}}
\usepackage{authblk}
% \author[1]{Kirti Rajagopalan \thanks{kirtir@wsu.edu}}
% \affil[1]{CAHNR, Washington State University}
\author{}
\date{}
\providecommand{\keywords}[1]{\textbf{\textit{Keywords:}} #1}

\begin{document}
\maketitle
\begin{abstract}
This model is distributed by the Washington
State University Viticulture  Program,
located at WSU-IAREC, 24106 North Bunn Rd., Prosser, WA 99350, USA.
This model is also currently available at WSU's AgWeatherNet
(weather.wsu.edu).  A login account is required to view the model,
but it is currently free of charge.   More information on cold
hardiness modeling and monitoring can be found at:
\href{http://wine.wsu.edu/research-extension/weather/cold-hardiness}{http://wine.wsu.edu/research-extension/weather/cold-hardiness.}

\end{abstract}

\keywords{}

\section{How to use code part of the excel file}

The WSU cold hardiness model (version 2) developed by
John Ferguson is written in Visual Basic as a macro.
Press Ctl-m to run the model, then press Ctl-g to
graph the output. The model will read the variety-specific
constants from the \vari{input\_parameters} worksheet.
Weather data will be read from the \vari{input\_temps}
 worksheet. All temperatures are in degrees Celsius.
Results will be placed in the \vari{model\_output} worksheet.
Running the model will clear any previous results that are
 in the \vari{model\_output} worksheet.

If you get an error about running macros and security,
you will need to change that setting.

Depending on your version of Excel, you  may need to open
Excel without the model, change the \textbf{Tools > Macro > Security}
to low, click ok, then open the model. Newer
versions  of Excel
will  give a security warning that macros have been
disabled. Select  \textbf{Options > Enable}  this content.

The model code may be viewed and/or edited by
clicking on \textbf{Tools  >  Macro  >  Macros >  model  > Edit. Newer
versions, select View > Macros > View macros > Edit}.

You should modify the pertinent columns of the \vari{input\_temps}
 worksheet to suit your local conditions. The current default data is
 from Prosser, Washington. Change the data in the \vari{input\_parameters}
 worksheet to the variety of interest by copying the pertinent line
 from \vari{variety\_parameters}. If you have any measured cold
 hardiness (Hc) values, put them in column H of
 the \vari{input\_temps} worksheet and change that
 column heading to a correct description of your data.
 Keep all yellow column headings intact. The default
 observed Hc values are for Cabernet Sauvignon in Prosser.

Feel free to play with some of the  values  placed
in the \vari{input\_parameters}  sheet to explore how
the model works , get it to fit your observations,
 or model a variety not listed. If  the model shows
 that deacclimation is delayed  at your location
 it probably means the Ecodormancy\_boundary is too large.

The model uses integer day of year (jday) as the
time variable, typically starting on day 250
(September 7th) and counting past the first of the year to day 500 (May 15th).

\end{document}


\documentclass{scrartcl}

% configuration lifted from chez-sty at https://github.com/chezbgone/chez-sty
\KOMAoptions{paper=letter, fontsize=10pt, usegeometry}

% standard
\usepackage{mathtools, amssymb, amsthm}

% refs
\usepackage{xcolor}
\usepackage[pdftex, colorlinks]{hyperref}
\definecolor{urlcolor}{rgb}{0.9, 0, 0.5}
\definecolor{linkcolor}{rgb}{0, 0.2, 0.8}
\definecolor{citecolor}{rgb}{0, 0.6, 0.3}
\hypersetup{urlcolor=urlcolor, linkcolor=linkcolor, citecolor=citecolor}
\usepackage[nameinlink]{cleveref}

% layout
\usepackage[margin=1.5cm, includefoot]{geometry}
\usepackage[nodisplayskipstretch, onehalfspacing]{setspace}
% section numbers in margin
\RenewDocumentCommand{\sectionlinesformat}{m m m m}{\makebox[0pt][r]{#3}#4}

% typography
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[scaled=0.83]{beramono}
\usepackage{microtype}
\usepackage[shortlabels, inline]{enumitem}
\setlist{nosep, listparindent=\parindent}

% smaller title style
\makeatletter \patchcmd{\@maketitle}{\huge}{\large}{}{} \makeatother
\setkomafont{author}{\normalsize\scshape}
\setkomafont{date}{\normalsize}
\RedeclareSectionCommand[beforeskip=0.4\baselineskip]{paragraph}

% temp config
\definecolor{todocolor}{rgb}{0.8, 0.1, 0.1}
\NewDocumentCommand{\TODO}{o}{\textcolor{todocolor}{TODO\IfNoValueF{#1}{: #1}}}

% % % % % % % % % % % % % % % % % % % % %
% actual content

\title{Schedgehog: a property-based testing library}
\author{Jason Chen \and CJ Quines \and Matthew Ho}

\begin{document}
\maketitle

\section{Overview}

In software engineering, testing code is considered to be a vital part of
delivering quality software. However, writing unit tests is extremely time
consuming, and it is easy for the programmer to miss certain cases for more
complicated functions. Therefore, it is desirable to try to automate this
processes either partially, or entirely.

We present a tool called \textbf{Schedgehog}, based on existing Haskell work
like QuickCheck \cite{quickcheck} or Hedgehog \cite{hedgehog}, that allows
users to formulate properties of programs and then automatically runs tests
based on the properties. Properties that users want to test will be specified
via a DSL embedded in Scheme; these are represented as predicates (functions
returning booleans) along with typing information of the inputs.

Test data is generated based on this typing information. These are checked
against the predicates, and in the case that a failing counterexample is found,
the counterexample is simplified via a build-in extensible rule-based system.

The code is currently available at
\url{https://github.com/chezbgone/schedgehog}.

\section{Basic usage}

\subsection{Defining properties}
Properties are specified with the macro \verb|forall|. Properties are functions
with typed arguments that return a boolean.

\begin{verbatim}
(define prop:addition-commutativity
  (forall ((x integer) (y integer))
          (= (+ x y) (+ y x))))
\end{verbatim}

Primitive types include \verb|integer|, \verb|boolean|, and \verb|float|. A full
list of built-in primitive types are in \verb|src/generator-instances.scm|.
There are also dependent types, like \verb|linear| or \verb|range|, that take
in values as arguments.

\begin{verbatim}
(define prop:addition-bounds
  (forall ((x (range 10 30)) (y (range 10 30)))
          (< 20 (+ x y) 60)))
\end{verbatim}

These types can be combined with type constructors to produce more complex
types. Some examples of type constructors include \verb|pair| and \verb|list|.

\begin{verbatim}
(define prop:sum-linear
  (forall ((xs (list integer)) (factor integer))
          (equal? (* factor (apply + xs))
                  (apply + (map (lambda (x) (* factor x)) xs)))))
\end{verbatim}

\subsection{Checking properties}
The main interface for checking a property is with the function \verb|check|.
This runs the function against several random test cases. It then prints
the result of the test, along with a counterexample if found.

\begin{verbatim}
(check prop:addition-commutativity)
; seed: ...
; ok 100 tests
(check prop:addition-bounds)
; seed: ...
; failed after 82 tests, 0 shrinks:
; ((x 10) (y 10))
\end{verbatim}

The function \verb|check-with-config| allows checking a property with a custom
configuration (which contains the maximum number of shrinks and tests to run),
size (which determines the size of generated inputs), and seed.

\begin{verbatim}
(check-with-config
  (make-config 1000 1000)
  1000
  (make-random-state #t)
  prop:addition-commutativity)
; ok 1000 tests
\end{verbatim}

\section{Generators}\label{sec:generators}
\subsection{Overview}

The file \verb|examples/generator.scm| contains extensive examples of the
library of built-in generators.

A generator represents a source of values for randomly checking a property,
along with the way in which values in the type shrink.
Intuitively, it can be thought of as a structure containing two components:
\begin{itemize}
\item A generating function \verb|(size seed) -> value|
\item A shrinking function \verb|(value) -> [list value]|
\end{itemize}
Internally, a generator is actually a wrapper around just one function
\verb|(size seed) -> [lazy-tree value]|, a function returning a lazy tree of
values. This design decision will be explained in
\cref{sec:trees}.
To create a generator without dealing with lazy tree internals,
we can call library functions that abstract away these details.

% TODO: figure out the hbox here
Suppose one has a generating function \verb|gen|. The simplest way to make a
generator would be to call \verb|(make-generator-without-shrinking gen)|,
which returns a generator object using the generating function that does not
have a shrinker.
\begin{verbatim}
(define gen-1 (make-generator-without-shrinking (lambda (size seed) 1)))
\end{verbatim}

We can then use the generator with the \verb|generate| function,
which optionally receives a size and seed as parameters.
\begin{verbatim}
(print-lazy-tree (generate gen-1))
\end{verbatim}

We can register a generator with a type by calling \verb|set-generator!|. This
allows it to be called with \verb|arbitrary|, a generic function.

\begin{verbatim}
(set-generator! 'type-1 gen-1)
(print-lazy-tree (generate (arbitrary 'type-1)))
(check (forall (x type-1) (= x 1)))
\end{verbatim}

To replace the shrink function of a generator \verb|gen| with a specified shrink
function \verb|shrink|, we call \verb|(replace-shrinking shrink gen)|.

\begin{verbatim}
(define (shrink-fn value) (case value ((1) (list 0)) ((0) (list))))
(define gen-2 ((replace-shrinking shrink-fn) gen-1))
(print-lazy-tree (generate gen-2))
\end{verbatim}

We can also create parametrized generators. The function \verb|arbitrary|, when
given a list of symbols, will instead search for a handler for the first symbol,
to be called on the list of the remaining symbols as arguments, expecting a
generator returned.

\begin{verbatim}
(define (gen-constant val)
  (make-generator-without-shrinking (lambda (size seed) val)))
(set-generator! 'type-constant (lambda (val) (gen-constant val)))
(print-lazy-tree (generate (arbitrary '(type-constant 1))))
\end{verbatim}

\section{Trees}\label{sec:trees}
\subsection{Rationale}
As mentioned in \cref{sec:generators}, a generator for values of type \verb|T|,
denoted as a \verb|(generator T)|,
can be thought of as a pair of functions,
\begin{itemize}
  \item \verb|gen| for value generation
        with type \verb|(size seed) -> T|, and
  \item \verb|shrink| for shrinking with type \verb|(T) -> [list T]|.
\end{itemize}
However, representing a generator as a collection of these two functions,
referred to as \emph{manual shrinking}, has some downsides
\cite{integrated} \cite{integrated2}.

One desired property of a generator is \emph{invariant preservation}.
Many generators represent types with some invariant,
and we want both \verb|gen| and \verb|shrink| to satisfy these invariants.
For instance if we are generating integers between 10 and 20,
\verb|gen| must only generate numbers in this range,
and \verb|shrink| must also return a number in this range.
Both functions trying to satisfy these invariants
often leads to duplicate code, which is tedious to write and
makes it more likely for discrepancies to arise.

Another desired property of a generator is
ease of composition with other functions.
If we have a \verb|(generator T)| and a function \(f\) of type \verb|(T) -> S|,
it seems like we should be able to obtain a \verb|(generator S)| just by
mapping the function over the values that \verb|gen| gives.
This is indeed true, but we cannot do the same thing for \verb|shrink|,
as it takes \verb|T|s as both inputs and outputs.
This is called parameter invariance, which makes composition difficult.

\subsection{Structure}
To solve these issues in the generator structure,
we combine the two functions needed for generation and shrinking.
To do so, whenever we generate a value,
we also generate the values that it shrinks to,
and then recursively generate the values those new values shrink to, and so on.
This results in a generator structure that is a wrapper around a single
function \verb|(size seed) -> [tree T]|.

The type \verb|(tree T)| is a record structure containing
  a value of type \verb|T| and
  a list of children of type \verb|(list (tree T))|s.
In the context of a generator, it represents
  a generated value
  along with the list of shrunk values and their own shrink values.

To make a slight optimization, we can note that the children of the root
of the tree are not actually needed until a generated value is
a failing example of a property.
As a result, we can make the list of children lazy,
since generating the shrunk values is unnecessary until needed in shrinking.

\section{Generator Combinators}

The structure of our generators as described in \ref{sec:trees} allows us to
create new generators out of existing generators very easily.
More specifically, we built a monadic combinator library for generators.
This happens to be extremely useful because the shrinking function is
automatically derived from the existing shrinking functions.
In this section, we will explain what combinators are available.

If we have a generator for a type \verb|T|, and a function \verb|T -> S|,
then we can use \verb|gen:map| to obtain a generator for \verb|S|.
\begin{verbatim}
(define g (gen:map (lambda (n) (list n n)) (arbitrary 'integer)))
(print-lazy-tree (generate g))
; +- (-2 -2)
;    |- (0 0)
;    +- (-1 -1)
;       +- (0 0)
\end{verbatim}
Note that shrinked values are also mapped, so the invariant is preserved.

We can generalize \verb|gen:map| to work with multi-parameter arguments:
\begin{verbatim}
(define g
  (gen:apply (lambda (n val) (make-list n val))
             (arbitrary 'nonnegative-integer)
             (arbitrary 'boolean)))
(print-lazy-tree (generate g))
; +- (#t #t)
;    |- ()
;    |- (#t)
;    |  |- ()
;    |  +- (#f)
;    |     +- ()
;    +- (#f #f)
;       |- ()
;       +- (#f)
;          +- ()
\end{verbatim}
Note that the shrinking happens in all of the arguments provided in the
generators provided to the \verb|gen:apply| combinator.

If we have a value, we can create a generator that always returns
that value with \verb|gen:pure| or \verb|constant-gen|:
\begin{verbatim}
(print-lazy-tree (generate (constant-gen (list 'a 3 #t))))
; +- (a 3 #t)
\end{verbatim}

If there is a list of generators, we can collect them into a generator of a list
via \verb|gen:sequence|:
\begin{verbatim}
(define g
  (gen:sequence (list (arbitrary 'integer)
                      (arbitrary '(range 5 7))
                      (arbitrary 'boolean))))
(print-lazy-tree (generate g))
+- (2 5 #t)
   |- (0 5 #t)
   |  +- (0 5 #f)
   |- (1 5 #t)
   |  |- (0 5 #t)
   |  |  +- (0 5 #f)
   |  +- (1 5 #f)
   |     +- (0 5 #f)
   +- (2 5 #f)
      |- (0 5 #f)
      +- (1 5 #f)
         +- (0 5 #f)
\end{verbatim}

There is a similar function \verb|gen:collect| that takes the generators
as arguments
\begin{verbatim}
(gen:collect (arbitrary 'integer)
             (arbitrary '(range 5 10))
             (arbitrary 'boolean))
\end{verbatim}

We also have the monadic bind combinator \verb|gen:bind|,
also called \verb|gen:then|:
\begin{verbatim}
(define g
  (gen:then (arbitrary '(range 0 5))
            (lambda (n) (gen:sequence (make-list n (arbitrary 'boolean))))))
(print-lazy-tree (generate g))
+- (#f #t #f)
   |- (#t #t)
   |  |- (#f)
   |  |  +- ()
   |  |- (#f #t)
   |  |  +- (#f #f)
   |  +- (#t #f)
   |     +- (#f #f)
   +- (#f #f #f)
\end{verbatim}

Using these combinators, we have written a large collection of
generators for everyday structures.
Schedgehog currently provides generators and arbitrary instances for
\begin{itemize}
  \item \verb|integer|,
  \item \verb|positive-integer|,
  \item \verb|nonnegative-integer|,
  \item \verb|float|,
  \item \verb|linear| (integers from \(0\) through \(n\), shrinking down),
  \item \verb|range| (integers from \(m\) through \(n\), shrinking to \(m\)),
  \item \verb|range-from| (integers from \(m\) through \(n\),
                           shrinking towards some origin \(k\)),
  \item \verb|pair|,
  \item \verb|list|,
  \item \verb|nonempty-list|,
  \item \verb|lengthed-list|,
  \item \verb|subsequence|, and
  \item \verb|permutation|.
\end{itemize}
However, this is just the beginning.
With the combinators provided, user may write their own
generator for custom types of data and structures.

% \section{Extensions}

% idk
% coarbitrary (function types)

\begin{thebibliography}{99}

\bibitem{quickcheck}
Claessen, K., \& Hughes, J. (2011). QuickCheck: a lightweight tool for random
testing of Haskell programs. \textit{ACM SigPlan Notices}, 46(4), 53-64.

\bibitem{integrated}
Debon, J. (2021). Integrated shrinking in QCheck. Retrieved from
\url{https://www.tweag.io/blog/2021-07-21-qcheck2-integrated-shrinking/}.

\bibitem{integrated2}
de Vries, E. (2019). Integrated versus Manual Shrinking. Retrieved from
\url{https://www.well-typed.com/blog/2019/05/integrated-shrinking/}.

\bibitem{hedgehog}
Hedgehog QA. (2019). Hedgehog will eat all your bugs. Retrieved from
\url{https://hedgehog.qa/}.

\end{thebibliography}

\end{document}


\chapter{Model variability in Zorro}
\label{app:zorro_model_uncertainty}

In this chapter, a short investigation into the model uncertainty in Zorro for GCN for sex prediction will be presented. In \cref{fig:zorro_model_uncertainty}, standard deviation in the importance score for each node from two different versions of Zorro are presented. $\sigma_{\rm{subjects}}\left(\mathcal{I}\right)$ refers to the standard deviation when Zorro was run for a single GCN model, where the Zorro results were grouped into 23 different groups of 200 subjects each, with the uncertainty evaluated over the mean importance for each of the 23 different groups. This corresponds to the uncertainty presented for GCN for sex prediction in \cref{sec:results_analysis_sex}. $\sigma_{\rm{models}}\left(\mathcal{I}\right)$ refers to running Zorro for a single group of 200 subjects, but repeated for ten different model initialisations of GCN. Comparing the results, we observe that the uncertainties are of comparable size, but that $\sigma_{\rm{subjects}}\left(\mathcal{I}\right)$ is generally slightly higher except for some nodes. For this reason, we draw the conclusion that the uncertainties in Zorro with regards to varying model, $\sigma_{\rm{models}}\left(\mathcal{I}\right)$, are not negligible but are smaller than the uncertainty when varying subjects, $\sigma_{\rm{subjects}}\left(\mathcal{I}\right)$. Thus, the more interesting uncertainty is the one regarding subject uncertainty, but varying model uncertainty would be interesting to investigate in a possible future work where time is not an issue.

\begin{figure}[ht]
    \centering
    \begin{center}
        \resizebox {0.6\linewidth} {!} {
            \input{appendices/figures/subjects_vs_models_std.pgf}
        }
    \end{center}
    \caption{Zorro uncertainty in the case of varying subjects for a single model, $\sigma_{\rm{subjects}}\left(\mathcal{I}\right)$, and in the case of a single group of subjects but for ten different model initialisation, $\sigma_{\rm{models}}\left(\mathcal{I}\right)$. Observe that $\sigma_{\rm{subjects}}\left(\mathcal{I}\right) > \sigma_{\rm{models}}\left(\mathcal{I}\right)$ for most nodes.}
    \label{fig:zorro_model_uncertainty}
\end{figure}


\documentclass{article}

\usepackage{amsmath,amssymb,amsthm}
\usepackage{url}
\usepackage{comment}
\usepackage{proof}
\usepackage{stmaryrd}
\usepackage{parskip}
\usepackage{fullpage}

\newcommand{\choice}[0]{\zeta}
\newcommand{\elcap}[0]{\cap}
\newcommand{\abs}[4]{{#1}\, #2\! : \! #3.\, #4}
\newcommand{\absu}[3]{{#1}\, #2.\, #3}
\mathchardef\mhyph="2D % Define a "math hyphen"
\newcommand{\interp}[1]{\llbracket #1 \rrbracket}
\newcommand{\tpcheck}[0]{\Leftarrow}
\newcommand{\tpsynth}[0]{\Rightarrow}
\newcommand{\cbe}[0]{c\beta\eta}
\newcommand{\utp}[0]{\mathcal{U}}
\newcommand{\startcase}[1]{\vspace{#1} \noindent\textbf{\underline{Case:}}}

\newtheorem{theorem}{Theorem}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}

\begin{document}

\title{Syntax and Semantics of Cedille}

\author{Aaron Stump \\
  Computer Science \\
  The University of Iowa \\
\texttt{aaron-stump@uiowa.edu}}

\date{}

\maketitle

\section{Introduction}

The type theory of Cedille is called the Calculus of Dependent Lambda
Eliminations (CDLE).  This document presents the version of CDLE as of
June 1, 2018.  We have made many changes from the first paper on CDLE~\cite{stump17},
mostly in the form of dropping constructs we discovered (to our
surprise) could be derived~\cite{stump18}. I have also omitted
\emph{lifting} -- a technique for large eliminations with lambda
encodings -- in this document's version of CDLE.  Some uses of lifting
can be simulated other ways within the system, though the limits of
this are still under investigation.  We also include a construct
$\delta$, for deriving a contradiction from a proof that
lambda-encoded true equals lambda-encoded false.  This also
compensates somewhat for the lack of lifting.

At a high level, CDLE is an extrinsic (i.e., Curry-style) type theory
extending the Calculus of Constructions with three additional
constructs, which allow deriving induction principles within the
theory, for inductive datatypes.  The goal is to support usual
idioms of dependently typed programming and proving as in Agda or
similar tools, but using pure lambda encodings for all data, and
requiring a much smaller core theory.

The current Cedille implementation of CDLE extends the system
described below with a number of features intended to make programming
in the system more convenient and with less redundancy.  These
features all compile away to a slightly simplified version of the
theory presented in this document, called Cedille Core, described
here: \url{https://github.com/astump/cedille-core-spec}.

\section{Classification Rules}

The classification rules are given in
Figures~\ref{fig:superknd},~\ref{fig:knd}, and~\ref{fig:tp}.  For
brevity, we take these figures as implicitly specifying the syntax of
kinds $\kappa$, types $T$, and annotated terms $t$; these may use term
variables $x$ and type variables $X$, which we assume come from
distinct sets.  So terms and types are syntactically distinguished.
The typing rules (Figure~\ref{fig:tp}) are
bidirectional~\cite{pierce+00}, while the kinding and superkinding
rules (Figure~\ref{fig:knd} and~\ref{fig:superknd}) are only
synthesizing.  We write $\Leftrightarrow$ to range over
$\{\tpcheck,\tpsynth\}$. We follow the syntax of our implementation
Cedille, which distinguishes application of a term or type $e$ to a
type ($e \cdot T$), from application to a term ($e\ t$), and
application to an erased term argument ($e\ \mhyph t$).  The rules are
intended, with a few points of nondeterminism, to be read bottom-up
(in a standard way; cf.~\cite{peytonjones07}) as an algorithm for
computing a classifier from a context and an expression ($\tpsynth$)
or checking an expression against a classifier in context
($\tpcheck$).

The classification rules refer to an erasure function, defined in
Figure~\ref{fig:eraser}.  The type theory is \emph{extrinsic} (aka,
Curry-style), and hence we only consider erasures $|t|$ of terms when
testing for $\beta\eta$-equivalence.  This is done by the conversion
relation $T\cong T'$, whose central rules are given in
Figure~\ref{fig:conv}.  That figure omits the various congruence rules
needed to equate bigger expressions by equating subexpressions.  The
main ideas of conversion shown in the figure are to use
$\beta$-equivalence at the type level, and $\beta\eta$-equivalence of
erased terms at the term level.

\begin{figure}
  \[
  \begin{array}{llll}
    \infer{\Gamma \vdash \star}{\ } &
    \infer{\Gamma\vdash\abs{\Pi}{x}{T}{\kappa}}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash\kappa} &
    \infer{\Gamma\vdash\abs{\Pi}{X}{\kappa'}{\kappa}}{\Gamma \vdash \kappa' & \Gamma,X:\kappa'\vdash\kappa}
  \end{array}
  \]
  \caption{Rules for checking that a kind is well-formed ($\Gamma \vdash \kappa$)}
  \label{fig:superknd}
\end{figure}

\begin{figure}
  \[
  \begin{array}{ll}
    \infer{\Gamma \vdash X \tpsynth \kappa}{(X : \kappa) \in \Gamma} &
    \infer{\Gamma\vdash \abs{\forall}{X}{\kappa}{T} \tpsynth \star}{\Gamma \vdash \kappa & \Gamma,X:\kappa\vdash T \tpsynth \star} \\ \\
    \infer{\Gamma\vdash\abs{\forall}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star} &
    \infer{\Gamma\vdash\abs{\Pi}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star} \\ \\
    \infer{\Gamma\vdash\abs{\lambda}{x}{T}{T'} \tpsynth \abs{\Pi}{x}{T}{\kappa}}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T'\tpsynth\kappa} &
    \infer{\Gamma\vdash\abs{\lambda}{X}{\kappa}{T'} \tpsynth \abs{\Pi}{X}{\kappa}{\kappa'}}{\Gamma \vdash \kappa & \Gamma,X:\kappa\vdash T'\tpsynth\kappa'} \\ \\
    \infer{\Gamma\vdash T\ t \tpsynth [t/x]\kappa}{\Gamma\vdash T \tpsynth \abs{\Pi}{x}{T'}{\kappa} & \Gamma\vdash t \tpcheck T'} &
    \infer{\Gamma\vdash T\cdot T' \tpsynth [T'/X]\kappa}{\Gamma\vdash T \tpsynth \abs{\Pi}{X}{\kappa'}{\kappa} & \Gamma\vdash T' \tpsynth \kappa' & \kappa \cong \kappa'} \\ \\
    \infer{\Gamma\vdash\abs{\iota}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star} &
    \infer{\Gamma\vdash \{ t \simeq t' \} : \star}{\textit{FV}(t\ t')\subseteq\textit{dom}(\Gamma)}
  \end{array}
  \]
  \caption{Rules for synthesizing a kind for a type ($\Gamma \vdash T \tpsynth \kappa$)}
  \label{fig:knd}
\end{figure}

\begin{figure}
  \[
  \begin{array}{ll}
    \infer{\Gamma\vdash x\tpsynth T}{(x : t)\in\Gamma} &
    \infer{\Gamma\vdash t\tpcheck T'}{\Gamma\vdash t \tpcheck T & T' \leadsto^*_\beta T} \\ \\
    \infer{\Gamma\vdash t\tpsynth T'}{\Gamma\vdash t \tpsynth T & T \leadsto^*_\beta T'} &
    \infer{\Gamma\vdash t\tpcheck T}{\Gamma\vdash t\tpsynth T' & T' \cong T} \\ \\
    \infer{\Gamma\vdash \absu{\lambda}{x}{t} \tpcheck \abs{\Pi}{x}{T}{T'}}{\Gamma,x:T\vdash t\tpcheck T'} &
    \infer{\Gamma\vdash t\ t' \tpsynth [t'/x]T}{\Gamma\vdash t \tpsynth \abs{\Pi}{x}{T'}{T} & \Gamma\vdash t' \tpcheck T'} \\ \\

    \infer{\Gamma\vdash \absu{\Lambda}{X}{t} \tpcheck \abs{\forall}{X}{\kappa}{T}}{\Gamma,X:\kappa\vdash t \tpcheck T} &
    \infer{\Gamma\vdash t \cdot T' \tpsynth [T'/X]T}
          {\Gamma\vdash t \tpsynth \abs{\forall}{X}{\kappa}{T} & \Gamma\vdash T' \tpcheck\kappa} \\ \\

    \infer{\Gamma\vdash \absu{\Lambda}{x}{t} \tpcheck \abs{\forall}{x}{T'}{T}}{\Gamma,x:T'\vdash t \tpcheck T & x\not\in\textit{FV}(|t|)} &
    \infer{\Gamma\vdash t\ \mhyph t' \tpsynth [t'/x]T}{\Gamma\vdash t \tpsynth \abs{\forall}{x}{T'}{T} & \Gamma\vdash t' \tpcheck T'} \\ \\

    \infer{\Gamma\vdash [ t , t' ] \tpcheck \abs{\iota}{x}{T}{T'}}
          {\Gamma\vdash t \tpcheck T & \Gamma\vdash t' \tpcheck [t/x]T' & |t| =_{\beta\eta} |t'|} &
    \infer{\Gamma\vdash t.1 \tpsynth T}{\Gamma\vdash t \tpsynth \abs{\iota}{x}{T}{T'}} \\ \\
    \infer{\Gamma\vdash t.2 \tpsynth [t.1/x]T'}{\Gamma\vdash t \tpsynth \abs{\iota}{x}{T}{T'}} &

    \infer{\Gamma\vdash \beta\{t'\} \tpcheck \{ t \simeq t \}}{\Gamma\vdash \textit{FV}(t)\subseteq \textit{dom}(\Gamma)}  \\ \\
    \infer{\Gamma\vdash \delta\ t \tpcheck T}{\Gamma\vdash t\tpcheck \{ \absu{\lambda}{x}{\absu{\lambda}{y}{x}} \simeq \absu{\lambda}{x}{\absu{\lambda}{y}{y}}\}}  &
    \infer{\Gamma\vdash \rho\ t'\ \mhyph\ t \Leftrightarrow [t_2/x]T}
          {\Gamma\vdash t' \tpsynth t_1 \simeq t_2 & \Gamma \vdash t \Leftrightarrow [t_1/x]T} \\ \\
    \infer{\Gamma\vdash \chi\ T\ \mhyph\ t \tpcheck T'}
          {\Gamma\vdash T\tpcheck \star & \Gamma\vdash t \tpcheck T & T \cong T'} &
    \infer{\Gamma\vdash \chi\ T\ \mhyph\ t \tpsynth T}
          {\Gamma\vdash T\tpcheck \star & \Gamma\vdash t \tpsynth T' & T \cong T'} \\ \\
    \infer{\Gamma\vdash \phi\ t\ \mhyph\ t'\{t''\} \Leftrightarrow T}
          {\Gamma\vdash t\tpsynth \{t'\simeq t''\} & \Gamma\vdash t' \Leftrightarrow T}  & \
  \end{array}
  \]
\caption{Rules for checking a term against a well-kinded type ($\Gamma \vdash t \tpcheck T$)
           and synthesizing a type for a term ($\Gamma \vdash t \tpsynth T$)}
\label{fig:tp}
\end{figure}

\begin{figure}
  \[
  \begin{array}{lllllll}
    |x| & = & x &\ &
    |\abs{\lambda}{x}{t'}{t}| & = & \absu{\lambda}{x}{|t|} \\
    |t\ t'| & = & |t|\ |t'| &\ &
    |t\cdot T| & = & |t| \\
    |\absu{\Lambda}{x}{t'}{t}| & = & |t| &\ &
    |t\ \mhyph t'| & = & |t| \\
    |[t , t']| & = & |t| &\ &
    |t.1| & = & |t| \\
    |t.2| & = & |t| &\ &
    |\beta\{t\}| & = & |t|\\
    |\delta\ t| & = & |t|&\ &
    |\rho\ t\ \mhyph\ t'| & = & |t'| \\
    |\phi\ t\ \mhyph\ t'\ \{t''\}| & = & |t''| &\ &
    |\chi\ T\ \mhyph\ t'| & = & |t'|
  \end{array}
  \]
  \caption{Erasure for annotated terms}
  \label{fig:eraser}
\end{figure}

\begin{figure}
  \[
  \begin{array}{ll}
    \infer{T \cong T'}{T \leadsto^*_\beta T_1 & T' \leadsto^*_\beta T_2 & T_1\cong^t T_2}  &
    \infer{T \cong T'}{T \cong^t T'} \\ \\
    \infer{T\ t \cong^t T\ t'}{T \cong^t T' & |t| =_{\beta\eta} |t'|} &
    \infer{\{ t_1 \simeq t_2 \} \cong^t \{ t_1'\ \simeq t_2' \}}{|t_1| =_{\beta\eta} |t_1'| & |t_2| =_{\beta\eta} |t_2'|}
  \end{array}
  \]
  \caption{Non-congruence rules for conversion}
  \label{fig:conv}
\end{figure}

\subsection{Overview of the constructs}
\label{sec:overview}

CDLE has as a subsystem the extrinsic Calculus of
Constructions (CC).  We have dependent types
$\abs{\Pi}{x}{T}{T'}$ and kinds $\abs{\Pi}{x}{T}{\kappa}$, as well as
term- and type-level quantification over (possibly higher-kinded)
types $\abs{\forall}{X}{\kappa}{T}$ and
$\abs{\Pi}{X}{\kappa}{\kappa'}$.  We use $\forall$ when the
corresponding argument will be erased, and $\Pi$ when it will be
retained.  Since we do not erase term or type arguments from
type-level applications, we thus write $\abs{\Pi}{X}{\kappa}{\kappa'}$
instead of $\abs{\forall}{X}{\kappa}{\kappa'}$.  We write $\lambda$ to
correspond to $\Pi$ and $\Lambda$ to correspond to $\forall$.  As noted
above, application to a type is denoted with center dot ($\cdot$).

To Curry-style CC, CDLE adds: implicit products, introduced orginially
by Miquel~\cite{miquel01}; a primitive equality type $\{ t \simeq
t'\}$; and dependent intersection types $\abs{\iota}{x}{T}{T'}$,
introduced by Kopylov~\cite{kopylov03}.  Implicit products are used
for erased arguments to functions, found also in systems like Agda
(cf.~\cite{mishraLinger08}).  Dependent intersections are a rather
exotic construct allowing us to assign type $\abs{\iota}{x}{T'}{T}$ to
erased term $t$ when we can assign $T'$ to $t$, and also assign
$[t/x]T$ to $t$.  For an annotated introduction form, we write
$[t,t'$], where $t$ checks against type $T'$, $t'$ checks against
$[t/x]T$, and $t$ and $t'$ have identical (i.e., $\alpha$-equivalent)
erasures.  Dependent intersections thus enable a controlled form of
self-reference in the type.  Previous work showed how to use this to
derive induction for Church-encoded natural numbers~\cite{stump18}.
We will see below further uses of this construct.

The typing rules include conversion checks in a few places; e.g., as
standardly, when switching from checking to synthesizing mode.  Two
rules near the top of Figure~\ref{fig:tp} state that one may (nondeterministically)
$\beta$-reduce the type one is synthesizing or checking, before proceeding.
This allows reduction to head-normal form,
to match the form of type required by other rules.
Finally, we include the construct $\chi\ T\ \mhyph\ t$ to change the
synthesized or checked type $T'$ to $T$, if $T \cong T'$.  This may
be necessary to get the type into a specific form for purposes of rewriting
with the $\rho$ construct.

Finally, we have modified
the rules for equality types $\{ t \simeq t' \}$ so that we require
nothing of $t$ and $t'$ except that the set $\textit{dom}(\Gamma)$ of variables
declared by $\Gamma$ includes their free variables $\textit{FV}(t\ t')$.  Further modifications
over the version of CDLE in~\cite{stump18} are:
\begin{itemize}
\item To prove $\{ t \simeq t\}$, one now writes $\beta\{t'\}$,
  with the critical idea that $|\beta\{t\}|$ erases to $|t|$.  We call this the \textbf{Kleene trick},
  because it goes back to Kleene's numeric realizability, which accepts any number $n$ as a realizer
  of a true equation.  Here, we accept any closed term $t$ as a realizer
  of $\{ t \simeq t\}$.  This means that in Cedille, any such term -- even otherwise untypable
  terms, non-normalizing terms, etc. -- have type $\{ t \simeq t\}$ for any term $t$.
\item The $\rho$ construct allows one to rewrite occurrences of $t_1$ to $t_2$ in the synthesized or
  checked type, where $t_1$ and $t_2$ are provably equal.  In the Cedille implementation, we rewrite
  all matching occurrences.  This may be compared to \verb|rewrite| in Agda, except that it may be
  applied anywhere, not just as part of pattern matching~\cite{agda}.
\item We adopt a strong form of Nuprl's \textbf{direct computation rules}~\cite{constable+86}:
  If we have a term $t'$ of type $T$ and a proof $t$ that $\{ t' \simeq t''\}$, then we may conclude that
  $t''$ has type $T$ by writing the annotated term $\phi\ t\ \mhyph\ t'\{t''\}$, which
  erases to $t''$.
\item Where the previous version of CDLE uses $\beta$-equivalence for (erased) terms, we here adopt $\beta\eta$-equivalence.  This
  allows us to observe in many cases that retyping functions are actually $\beta\eta$-equivalent to $\absu{\lambda}{x}{x}$.
  While $\beta\eta$-equivalence takes more work to incorporate into intrinsic
  type theory~\cite{geuvers92},
  it raises no difficulties for our extrinsic one.
\item In this version, we add an explicit axiom $\delta$ saying that Church-encoded boolean \emph{true} is different from
  \emph{false}.  In the first version of CDLE, such an axiom was derivable from \emph{lifting}, a construct allowing
  simply typable terms to be lifted to the type level~\cite{stump17}.  We omit lifting in this new version of CDLE, because while
  sound, lifting as defined in that previous work is complicated and appears to be incomplete.  Developing a new
  form of lifting remains to future work.
\end{itemize}

The equality type remains \textbf{intensional}: we equate terms iff they are $\beta\eta$-equal.

\subsection{Semantics and metatheory}

Figure~\ref{fig:semtp} gives a realizability semantics for types and
kinds, following the semantics given in the previous papers on
CDLE~\cite{stump18,stump17}.  Details of this semantics are presented
further in Section~\ref{sec:snd} below.  Using the semantics and the
definition in Figure~\ref{fig:semctxt} of $\interp{\Gamma}$, we can
prove the following theorem:
\begin{theorem}[Soundness]
\label{thm:snd}
Suppose $(\sigma,\rho)\in\interp{\Gamma}$.  Then we have:
\begin{enumerate}
\item If $\Gamma\vdash \kappa$, then $\interp{\kappa}_{\sigma,\rho}$ is defined.
\item If $\Gamma\vdash T \tpsynth \kappa$, then $\interp{T}_{\sigma,\rho}\in\interp{\kappa}_{\sigma,\rho}$.
\item If $\Gamma\vdash t \tpsynth T$ then $[\sigma |t|]_{\cbe}\in\interp{T}_{\sigma,\rho}\in \mathcal{R}$.
\item If $\Gamma\vdash t \tpcheck T$ and $\interp{T}_{\sigma,\rho}\in \mathcal{R}$, then
    $[\sigma |t|]_{\cbe}\in\interp{T}_{\sigma,\rho}\in \mathcal{R}$.
\item If $T \cong T'$ or $T \cong^t T'$ and $\interp{T}_{\sigma,\rho}$ and $\interp{T'}_{\sigma,\rho}$ are both defined, then they are equal.
\end{enumerate}
\end{theorem}

An easy corollary, by the semantics of $\forall$-types, is then:

\begin{theorem}[Logical consistency]
\label{thm:consis}
  There is no term $t$ such that $\vdash t : \abs{\forall}{X}{\star}{X}$.
\end{theorem}

It may worry some readers that we have:
\begin{observation}
  There are typable terms $t$ which fail to normalize.
\end{observation}

Defining \verb|Top| to be $\{\absu{\lambda}{x}{x} \simeq
\absu{\lambda}{x}{x}\}$, we may assign \verb|Top| to any closed term \verb|t|,
including non-normalizing ones.  In our annotated syntax, we write \verb|β{t}|.
Even without this, the presence of
$\delta$ in combination with $\phi$ allows us to type non-normalizing
terms assuming an erased argument $x$ of type $\{ \textit{tt} \simeq
\textit{ff} \}$ for Church-encoded booleans \textit{tt} and
\textit{ff}.  For example, $\delta\ x$ has type
\verb|{λ x . x ≃ λ x . x x}|, and with $\phi$ we can use this to type
$\Omega$ by changing the typed term \verb|id · True id|, where
\verb|True| is \verb|∀ X : ★ . X ➔ X|. But failure of normalization
does not impinge on Theorem~\ref{thm:consis}.   Extensional Martin-L\"of type theory (MLTT) is
also non-normalizing, for a very similar reason, but fact
does not contradict its logical soundness~\cite{dybjer16}.  In CDLE, the guarantees one gets about the
behavior of terms are expressed almost entirely in their types.  If
the types are weak, then not much is guaranteed; but stronger types
can guarantee properties like normalization.

Given the lack of normalization, several checks in the typing rules --
for things like $t =_{\beta\eta} t'$ -- are formally undecidable.  In
practice, we simply impose a bound on the number of steps of reduction,
and thus restore formal decidability (we are checking ``typable within
a given budget'').  In practice, the same is done for Coq and Agda,
where type checking is decidable but, in general, infeasible (since one
may write astronomically slow terminating functions).

Finally, in line with ideas recently advocated by Dreyer, we
do not concern ourselves with syntactic
type preservation~\cite{dreyer18}, noting instead that by construction,
semantic types $\interp{T}_{\sigma,\rho}$ are preserved by $\beta\eta$-reduction:

  \begin{theorem}[Semantic type preservation]
    If $t \leadsto_{\beta\eta} t'$ and $t\in\interp{T}_{\sigma,\rho}$, then $t'\in\interp{T}_{\sigma,\rho}$.
    \end{theorem}

  Confluence of $\beta\eta$-reduction for (erased)
  terms is nothing other than confluence of untyped lambda calculus.
  This is because, as easily verified by inspecting
  Figure~\ref{fig:eraser}, the erasure function maps annotated terms
  $t$ to terms $|t|$ of pure untyped lambda calculus.
\begin{comment}
  \begin{lemma}
    If $t$ is an annotated term of CDLE, then $|t|$ is a term of pure untyped lambda calculus.
    \end{lemma}
\end{comment}

\begin{figure}
\[
\begin{array}{lll}
\interp{X}_{\sigma,\rho} & = & \rho(X) \\
\interp{\Pi x : T_1. T_2}_{\sigma,\rho} & = &
    [\{ \lambda x.t\ |\ \forall E\in\interp{T_1}_{\sigma,\rho}.\\
\ &\ &\ \ \ \  [[\choice(E)/x]t]_{\cbe}\in\interp{T_2}_{\sigma[x\mapsto \choice(E)],\rho} \ \wedge\ t = |t|\}]_{\cbe}
 \\
\interp{\forall X:\kappa.T}_{\sigma,\rho} & = &
  \elcap \{ \interp{T}_{\sigma,\rho[X\mapsto S]} |\ S\in\interp{\kappa}_{\sigma,\rho} \}  \\
\interp{\forall x:T.T'}_{\sigma,\rho} & = &
  \elcap_\star \{ \interp{T'}_{\sigma[x\mapsto \choice(E)],\rho}\ |\ E\in\interp{T}_{\sigma,\rho} \} \\
\interp{\iota x:T.T'}_{\sigma,\rho} & = & \{ E\in\interp{T}_{\sigma,\rho} |\ E \in \interp{T'}_{\sigma[x\mapsto \choice(E)],\rho} \} \\
\interp{\lambda X:\kappa.T}_{\sigma,\rho} & = & (S\in\interp{\kappa}_{\sigma,\rho} \mapsto \interp{T}_{\sigma,\rho[X\mapsto S]})
\\
\interp{\lambda x:T.T'}_{\sigma,\rho} & = &
    (E\in\interp{T}_{\sigma,\rho} \mapsto \interp{T'}_{\sigma[x\mapsto \choice(E)],\rho})
\\
\interp{T\ T'}_{\sigma,\rho} & = & \interp{T}_{\sigma,\rho}(\interp{T'}_{\sigma,\rho})
\\
\interp{T\ t}_{\sigma,\rho} & = & \interp{T}_{\sigma,\rho}([\sigma |t|]_{\cbe})
\\
\interp{t \simeq t'}_{\sigma,\rho} & = & [\{ t''\ |\ \sigma |t| =_{\beta\eta} \sigma |t'|\ \wedge\ t'' = |t''| \}]_{\cbe} \\
\ &\ &\ \ \ \textnormal{ if }\textit{FV}(t\ t')\subseteq\textit{dom}(\sigma)
\\
\interp{\star}_{\sigma,\rho} & = & \mathcal{R} \\
\interp{\Pi x:T.\kappa}_{\sigma,\rho} & = &
(E\in\interp{T}_{\sigma,\rho} \to \interp{\kappa}_{\sigma[x\mapsto \choice(E)],\rho}),\\
\ &\ &\ \ \ \textnormal{ if }\interp{T}_{\sigma,\rho}\in\mathcal{R} \\
\interp{\Pi x:\kappa.\kappa'}_{\sigma,\rho} & = & (S\in\interp{\kappa}_{\sigma,\rho} \to \interp{\kappa}_{\sigma,\rho[X\mapsto S]}) \\
\elcap_\star X & = & \left\{\begin{array}{l}
                                         \, \negthinspace\elcap X, \textnormal{ if } X\neq\emptyset\\
                                         \, \negthinspace[\mathcal{L}]_{\cbe},\textnormal{ otherwise}
                                       \end{array}\right. \\
\end{array}
\]
\caption{Semantics for types and kinds}
\label{fig:semtp}
\end{figure}

\begin{figure}
\[
\begin{array}{lll}
(\sigma\uplus[x\mapsto t],\rho)\in\interp{\Gamma,x:T} & \Leftrightarrow & (\sigma,\rho)\in\interp{\Gamma} \ \wedge\
 [t]_{\cbe}\in\interp{T}_{\sigma,\rho}\in\mathcal{R}\ \wedge\ t = |t| \\
(\sigma,\rho\uplus[X\mapsto S])\in\interp{\Gamma,X:\kappa} & \Leftrightarrow & (\sigma,\rho)\in\interp{\Gamma} \ \wedge\
S\in\interp{\kappa}_{\sigma,\rho} \\
(\emptyset,\emptyset)\in\interp{\cdot}
\end{array}
\]
\caption{Semantics of typing contexts $\Gamma$}
\label{fig:semctxt}
\end{figure}

\subsection{Some details about the semantics and the proof of Theorem~\ref{thm:snd}}
\label{sec:snd}

Following the development in~\cite{stump17}, we work with
set-theoretic partial functions for the semantics of higher-kinded
types.  Types are interpreted as $\beta\eta$-closed sets of closed
terms. Let $\mathcal{L}$ be the set of closed terms of pure lambda calculus
(differently from~\cite{stump17}, we include all terms at this point,
even non-normalizing ones).  We
write $=_{\cbe}$ for standard $\beta\eta$-equivalence of pure lambda calculus, restricted to
closed terms; and $[t]_{\cbe}$ for $\{ t'\ |\ t =_{\cbe} t'\}$.  This
is extended to sets $S$ of terms by writing $[S]_{\cbe}$ for
$\{[t]_{\cbe}\ |\ t\in S\}$.  In a few places we write
$\textit{nf}(t)$ for the (unique) $\beta\eta$-normal form of term $t$,
if it has one.  If (in our meta-language) we affirm a statement
involving application of a partial function, then it is to be
understood that that application is defined.

\begin{definition}[Reducibility candidates]
  $\mathcal{R} := \{ [S]_{\cbe}\ |\ S\subseteq \mathcal{L} \}$.
\end{definition}

Throughout the development we find it convenient to use a
\textbf{choice function} $\choice$.  Given any nonempty set $E$ of
terms, $\choice$ returns some element of $E$.  Note that if $a \in A
\in \mathcal{R}$, then $a$ is a nonempty set of terms of pure lambda
calculus; it can also happen that $A \in\mathcal{R}$ is empty.  The
proof of Theorem~\ref{thm:snd} (see appendix) is then a straightforward adaptation of~\cite{stump17}.

\textbf{Acknowledgments.}  This work was partially supported by the US
NSF support under award 1524519, and US DoD support under award
FA9550-16-1-0082 (MURI program).

\begin{thebibliography}{10}

\bibitem{constable+86}
Robert~L. Constable, Stuart~F. Allen, Mark Bromley, Rance Cleaveland, J.~F.
  Cremer, R.~W. Harper, Douglas~J. Howe, Todd~B. Knoblock, N.~P. Mendler,
  Prakash Panangaden, James~T. Sasaki, and Scott~F. Smith.
\newblock {\em Implementing mathematics with the Nuprl proof development
  system}.
\newblock Prentice Hall, 1986.

\bibitem{dreyer18}
Derek Dreyer.
\newblock {The Type Soundness Theorem That You Really Want to Prove (and Now
  You Can)}.
\newblock Milner Award Lecture, delivered at Principles of Programming
  Languages (POPL), 2018.

\bibitem{dybjer16}
Peter Dybjer and Erik Palmgren.
\newblock {Intuitionistic Type Theory}.
\newblock In Edward~N. Zalta, editor, {\em The Stanford Encyclopedia of
  Philosophy}. Metaphysics Research Lab, Stanford University, winter 2016
  edition, 2016.

\bibitem{geuvers92}
Herman Geuvers.
\newblock {The Church-Rosser Property for beta-eta-reduction in Typed
  lambda-Calculi}.
\newblock In {\em Proceedings of the Seventh Annual Symposium on Logic in
  Computer Science {(LICS} '92), Santa Cruz, California, USA, June 22-25,
  1992}, pages 453--460. {IEEE} Computer Society, 1992.

\bibitem{kopylov03}
Alexei Kopylov.
\newblock Dependent intersection: {A} new way of defining records in type
  theory.
\newblock In {\em 18th {IEEE} Symposium on Logic in Computer Science {(LICS)}},
  pages 86--95, 2003.

\bibitem{agda}
\mbox{The Agda development team}.
\newblock {\em Agda}, 2018.
\newblock Version 2.5.4.

\bibitem{miquel01}
Alexandre Miquel.
\newblock {The Implicit Calculus of Constructions Extending Pure Type Systems
  with an Intersection Type Binder and Subtyping}.
\newblock In Samson Abramsky, editor, {\em {Typed Lambda Calculi and
  Applications}}, volume 2044 of {\em Lecture Notes in Computer Science}, pages
  344--359. Springer, 2001.

\bibitem{mishraLinger08}
Nathan Mishra{-}Linger and Tim Sheard.
\newblock {Erasure and Polymorphism in Pure Type Systems}.
\newblock In Roberto~M. Amadio, editor, {\em Foundations of Software Science
  and Computational Structures, 11th International Conference, {FOSSACS} 2008,
  Held as Part of the Joint European Conferences on Theory and Practice of
  Software, {ETAPS} 2008, Budapest, Hungary, March 29 - April 6, 2008.
  Proceedings}, volume 4962 of {\em Lecture Notes in Computer Science}, pages
  350--364. Springer, 2008.

\bibitem{peytonjones07}
Simon Peyton~Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields.
\newblock {Practical Type Inference for Arbitrary-rank Types}.
\newblock {\em J. Funct. Program.}, 17(1):1--82, January 2007.

\bibitem{pierce+00}
Benjamin~C. Pierce and David~N. Turner.
\newblock Local type inference.
\newblock {\em {ACM} Trans. Program. Lang. Syst.}, 22(1):1--44, 2000.

\bibitem{stump17}
Aaron Stump.
\newblock {The Calculus of Dependent Lambda Eliminations}.
\newblock {\em J. Funct. Program.}, 27:e14, 2017.

\bibitem{stump18}
Aaron Stump.
\newblock {From Realizability to Induction via Dependent Intersection}, 2018.
\newblock in press.

\end{thebibliography}

%% Appendix
\appendix

\section{Proof of Theorem~\ref{thm:snd}}

First a few lemmas (easy proofs omitted):

\begin{lemma}
  $\interp{\kappa}_{\sigma,\rho}$ is nonempty if defined.
\end{lemma}

\begin{lemma}
\label{lem:choice}
If $E$ is nonempty, then $[\choice(E)]_{\cbe} = E$
\end{lemma}

\begin{lemma}
  The set $\mathcal{R}$ ordered by subset forms a complete lattice,
  with greatest element $[\mathcal{L}]_{\cbe}$ and greatest lower bound
  of a nonempty set of elements given by
  intersection.  Also, $\emptyset$ is the least element.
\end{lemma}

\begin{lemma}[Term substitution and interpretation]
\label{lem:termsubstinterp}
If $t' =_{\cbe} \sigma |t|$, then:
\begin{itemize}
\item $\interp{T}_{\sigma[x\mapsto t'],\rho} = \interp{[t/x]T}_{\sigma,\rho}$
\item $\interp{\kappa}_{\sigma[x\mapsto t'],\rho} = \interp{[t/x]\kappa}_{\sigma,\rho}$
\end{itemize}
\end{lemma}

\begin{lemma}[Type substitution and interpretation]
\label{lem:tpsubstinterp}
\begin{itemize}
\item $\interp{T}_{\sigma,\rho[X\mapsto\interp{T'}_{\sigma,\rho}]} = \interp{[T'/X]T}_{\sigma,\rho}$
\item $\interp{\kappa}_{\sigma,\rho[X\mapsto\interp{T'}_{\sigma,\rho}]} = \interp{[T'/X]\kappa}_{\sigma,\rho}$
\end{itemize}
\end{lemma}

\begin{lemma}
  \label{lem:interppres}
  If $T \leadsto^*_{\beta} T'$ and $\interp{T}_{\sigma,\rho}$ is defined, then $\interp{T'}_{\sigma,\rho}$ is also defined and equals $\interp{T}_{\sigma,\rho}$.
\end{lemma}
\begin{proof}
  This follows by induction on the reduction derivation, making use of the previous substitution lemmas.
  \end{proof}

\begin{proof}[Soundness (Theorem~\ref{thm:snd})]
  The following proof is adapted from~\cite{stump17}.  It proceeds by
  mutual induction on the assumed typing, kinding, or superkinding
  derivation, for each part of the lemma.  We prove the parts
  successively.

\subsection{Proof of part (1)}

\startcase{.2cm}
\[
\infer{\Gamma \vdash \star }{\ }
\]
$\interp{\star}_{\sigma,\rho}$ is just $\mathcal{R}$, which is
defined.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash\abs{\Pi}{x}{T}{\kappa}}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash\kappa}
\]
By the IH, $\interp{T}_{\sigma,\rho}\in\mathcal{R}$, and so
$\interp{\Pi x : T.\, \kappa}_{\sigma,\rho}$ is
$(E\in\interp{T}_{\sigma,\rho} \to \interp{\kappa}_{\sigma[x\mapsto  \choice(E)],\rho})$.
The latter quantity is defined if for all
$E\in\interp{T}_{\sigma,\rho}$, $\interp{\kappa}_{\sigma[x\mapsto \choice(E)],\rho})$ is, too.  Since
$\interp{T}_{\sigma,\rho}\in\mathcal{R}$, every element $E$ of
$\interp{T}_{\sigma,\rho}$ is nonempty, as noted above,
so $\choice(E)$ is defined.  We may apply the IH to the second
premise, since
$(\sigma[x\mapsto\choice(E)],\rho)\in\interp{\Gamma,x:T}$, because $E\in\interp{T}_{\sigma,\rho}$ (by assumption)
and $[\choice(E)]_{\cbe} = E$.  This gives definedness of the semantics
of the $\Pi$-kind.

\startcase{.2cm}
\[
   \infer{\Gamma\vdash\abs{\Pi}{X}{\kappa'}{\kappa}}{\Gamma \vdash \kappa' & \Gamma,X:\kappa'\vdash\kappa}
\]
We must show $(S\in\interp{\kappa}_{\sigma,\rho} \to \interp{\kappa}_{\sigma,\rho[X\mapsto S]})$ is defined.
This is true if $\interp{\kappa}_{\sigma,\rho}$ is defined, which is the case by
the IH applied to the first premise; and if for all
$S\in\interp{\kappa}_{\sigma,\rho}$,
$\interp{\kappa}_{\sigma,\rho[X\mapsto S]}$ is defined.  The latter is
true by the IH applied to the second premise.

\subsection{Proof of part (2)}

\startcase{.2cm}
\[
\infer{\Gamma \vdash X \tpsynth \kappa}{(X : \kappa) \in \Gamma}
\]
From the definition of $\interp{\Gamma}$, we obtain
$\rho(x)\in\interp{\kappa}_{\sigma,\rho}$.

\startcase{.2cm}
\[
   \infer{\Gamma\vdash\abs{\Pi}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star}
\]
We must show $\interp{\Pi x:T.T'}_{\sigma,\rho}\in\mathcal{R}$. The
semantics defines $\interp{\Pi x:T.T'}_{\sigma,\rho}$ to be
$[A]_{\cbe}$ for a certain $A$, where if $A$ is defined, then
$A\subseteq\mathcal{L}$.  So it suffices to shown definedness. By the IH
for the first premise, $\interp{T}_{\sigma,\rho}\in\mathcal{R}$.  This
means that if $E\in\interp{T}_{\sigma,\rho}$, $\choice(E)$ is defined.
We can then apply the IH to the second premise, since
$\sigma[x\mapsto\choice(E)]\in\interp{\Gamma,x:T}$, to obtain
definedness of $\interp{T'}_{\sigma[x\mapsto\choice(E),\rho}$.

\startcase{.2cm}
\[
   \infer{\Gamma\vdash\abs{\forall}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star}
\]
By the IH for the second premise, $\interp{T_2}_{\sigma[x\mapsto  \choice(E)],\rho}\in\mathcal{R}$, for every
$E\in\interp{T_1}_{\sigma,\rho}$ where
$\interp{T_1}_{\sigma,\rho}\in\mathcal{R}$.  By the IH for the first
premise, we indeed have $\interp{T_1}_{\sigma,\rho}\in\mathcal{R}$.
So if $\interp{T_1}_{\sigma,\rho}$ is non-empty, then the intersection of all the sets
$\interp{T_2}_{\sigma[x\mapsto \choice(E)],\rho}$ where $E\in\interp{T_1}_{\sigma,\rho}$ is a
reducibility candidate, since each of those sets is.  By the semantics
of $\forall$-types quantifying over terms, this is sufficient.  If $\interp{T_1}_{\sigma,\rho}$ is
empty, then the interpretation of the $\forall$-type is $[\mathcal{L}]_{\cbe}$ by the definition
of $\elcap_\star$, and this is in $\mathcal{R}$.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \abs{\forall}{X}{\kappa}{T} \tpsynth \star}{\Gamma \vdash \kappa & \Gamma,X:\kappa\vdash T \tpsynth \star}
\]
Similarly to the previous case: by the IH for the second premise,
$\interp{T_2}_{\sigma,\rho[X\mapsto S}\in\mathcal{R}$, for every
$S\in\interp{\kappa}_{\sigma,\rho}$.  By the IH part for the first
premise, $\interp{\kappa}_{\sigma,\rho}$ is defined.  So the
intersection of all the sets $\interp{T_2}_{\sigma,\rho[X\mapsto S]}$
where $S\in\interp{\kappa}_{\sigma,\rho}$ is a reducibility candidate,
since each of those sets is.  The intersection is nonempty, since $\interp{\kappa}_{\sigma,\rho}$ is (as stated in a lemma above).
By the semantics of $\forall$-types
quantifying over types, this is sufficient.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash\abs{\iota}{x}{T}{T'} \tpsynth \star}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T' \tpsynth \star}
\]
The set $\interp{\iota x:T.T'}_{\sigma,\rho}$ is explicitly defined to
be a subset of $\interp{T}_{\sigma,\rho}$, which is in $\mathcal{R}$,
by the IH applied to the first premise.  Since for any
$A\subseteq\mathcal{L}$, $[A]_{\cbe}$ is in $\mathcal{R}$, to show that
$\interp{\iota x:T.T'}_{\sigma,\rho}$ is also in $\mathcal{R}$ it suffices
to show definedness of $\interp{T'}_{\sigma[x\mapsto \choice(E)],\rho}\}$
(which is used in the predicate picking out the
particular subset of $\interp{T}_{\sigma,\rho}$), for
$E\in\interp{T}_{\sigma,\rho}$.  For such $E$, $\choice(E)$ is defined
(since $\interp{T}_{\sigma,\rho}\in\mathcal{R}$ and hence $E\in\interp{T}_{\sigma,\rho}$ is nonempty)
and in $E$,
so $\sigma[x\mapsto\choice(E)]\in\interp{\Gamma,x:T}$.  So
by the IH for the second premise,
$\interp{T'}_{\sigma[x\mapsto\choice(E),\rho]}$ is defined.

\startcase{.2cm}
\[
 \infer{\Gamma\vdash\abs{\lambda}{x}{T}{T'} \tpsynth \abs{\Pi}{x}{T}{\kappa}}{\Gamma \vdash T \tpsynth \star & \Gamma,x:T\vdash T'\tpsynth\kappa}
\]
By the semantics, $\interp{\lambda x:T.T'}_{\sigma,\rho}$ is
$(E\in\interp{T}_{\sigma,\rho} \mapsto \interp{T'}_{\sigma[x\mapsto
  \choice(E)],\rho})$.  We must show that this (meta-level) function
is in $\interp{\Pi x:T.\kappa}_{\sigma,\rho}$.  By the semantics of
kinds, the latter quantity, if defined, is
$(E\in\interp{T}_{\sigma,\rho} \to_{\cbe}
\interp{\kappa}_{\sigma[x\mapsto \choice(E)],\rho})$.
By the IH for the first premise, $\interp{T}_{\sigma,\rho}\in\mathcal{R}$.
So we must just show that for any $E\in\interp{T}_{\sigma,\rho}$,
$\interp{T'}_{\sigma[x\mapsto
  \choice(E)],\rho}\in\interp{\kappa}_{\sigma[x\mapsto
  \choice(E)],\rho}$.  But this follows by the IH for the second
premise.

\startcase{.2cm}
\[
\infer{\Gamma\vdash\abs{\lambda}{X}{\kappa}{T'} \tpsynth \abs{\Pi}{X}{\kappa}{\kappa'}}
      {\Gamma \vdash \kappa & \Gamma,X:\kappa\vdash T'\tpsynth\kappa'}
\]
This case is an easier version of the previous one.  It suffices to
assume an arbitrary $S\in\interp{\kappa}_{\sigma,\rho}$ and show
$\interp{T'}_{\sigma,\rho[X\mapsto S]}\in\interp{\kappa'}_{\sigma,\rho[X\mapsto S]}$.  But this follows
by the IH applied to the second premise.  And we have definedness of
$\interp{\kappa}_{\sigma,\rho}$ by the IH for the first premise.

\startcase{.2cm}
\[
   \infer{\Gamma\vdash T\ t \tpsynth [t/x]\kappa}{\Gamma\vdash T \tpsynth \abs{\Pi}{x}{T'}{\kappa} & \Gamma\vdash t \tpcheck T'}
\]
By the IH for the first premise,
$\interp{T}_{\sigma,\rho}\in\interp{\Pi x:T'.\kappa}_{\sigma,\rho}$.
By the semantics of $\Pi$-kinds, this means that
$\interp{T}_{\sigma,\rho}$ is a function which given any
$E\in\interp{T'}_{\sigma,\rho}$, will produce a result in
$\interp{\kappa}_{\sigma[x\mapsto \choice(E)],\rho}$.  By the
semantics of type applications, $\interp{T\ t}_{\sigma,\rho}$ is equal
to $\interp{T}_{\sigma,\rho}([\sigma |t|]_{\cbe})$.  This is defined,
since $[\sigma |t|]_{\cbe}\in\interp{T'}_{\sigma,\rho}$, by the IH for
the second premise; note that $\interp{T'}_{\sigma,\rho}$ is defined
since otherwise $\interp{\Pi x:T'.\kappa}_{\sigma,\rho}$ would not be defined.
The result of applying the function is thus indeed
in $\interp{[t/x]\kappa}_{\sigma,\rho}$, since by
Lemma~\ref{lem:termsubstinterp}, this equals
$\interp{\kappa}_{\sigma[x\mapsto \choice([\sigma |t|]_{\cbe})],\rho}$
(the codomain of the function being applied).

\startcase{.2cm}
\[
\infer{\Gamma\vdash T\cdot T' \tpsynth [T'/X]\kappa}
      {\Gamma\vdash T \tpsynth \abs{\Pi}{X}{\kappa'}{\kappa} & \Gamma\vdash T' \tpsynth \kappa' & \kappa \cong \kappa'}
\]
By the IH applied to the first premise,
$\interp{T}_{\sigma,\rho}\in\interp{\abs{\Pi}{X}{\kappa'}{\kappa}}_{\sigma,\rho}$.
By the semantics of $\Pi$-kinds, this means that for any
$S\in\interp{\kappa'}_{\sigma,\rho}$, $\interp{T}_{\sigma,\rho}\ S$ is in
$\interp{\kappa}_{\sigma,\rho[X\mapsto S]}$.  By the IH for the second premise, we have
$\interp{T'}\interp{\kappa'}_{\sigma,\rho}$, and by the IH for the third premise,
we have $\interp{\kappa}_{\sigma,\rho} = \interp{\kappa'}_{\sigma,\rho}$.  So
we get $\interp{T}_{\sigma,\rho}(\interp{T'}_{\sigma,\rho})\in \interp{\kappa}_{\sigma,\rho[X\mapsto \interp{T'}_{\sigma,\rho}]}$,
which suffices by Lemma~\ref{lem:tpsubstinterp}.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \{ t \simeq t' \} : \star}{\textit{FV}(t\ t')\subseteq\textit{dom}(\Gamma)}
\]
Either $\sigma |t| =_{\cbe} \sigma |t'|$ or not.  Either way, the interpretation is defined and in $\mathcal{R}$, since
$\textit{FV}(t\ t')\subseteq\textit{dom}(\sigma)$ (as an easy consequence of $(\sigma,\rho)\in\interp{\Gamma}$).

\subsection{Proof of parts (3) and (4)}

\startcase{.2cm}
\[
    \infer{\Gamma\vdash x\tpsynth T}{(x : t)\in\Gamma}
\]
This follows from the definition of $\interp{\Gamma}$.

\startcase{.2cm}
\[
 \infer{\Gamma\vdash t\tpcheck T'}{\Gamma\vdash t \tpcheck T & T' \leadsto^*_\beta T}
\]
We are assuming $\interp{T'}_{\sigma,\rho}$ is defined, since this is a checking judgment. The desired result then
follows from Lemma~\ref{lem:interppres}.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash t\tpsynth T'}{\Gamma\vdash t \tpsynth T & T \leadsto^*_\beta T'}
\]
This also follows from Lemma~\ref{lem:interppres} and the induction hypothesis for the first premise,
which implies $\interp{T}_{\sigma,\rho}\in\mathcal{R}$ (and hence defined).

\startcase{.2cm}
\[
\infer{\Gamma\vdash t\tpcheck T}{\Gamma\vdash t\tpsynth T' & T' \cong T}
\]
By the IH applied to the first premise, we have
$[\sigma t]_{\cbe}\in\interp{T'}_{\sigma,\rho}\in\mathcal{R}$. By assumption, $\interp{T}_{\sigma,\rho}\in\mathcal{R}$,
and so by the IH applied to the second premise, we have $[\sigma t]_{\cbe}\in\interp{T'}_{\sigma,\rho} = \interp{T}_{\sigma,\rho}$.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \absu{\lambda}{x}{t} \tpcheck \abs{\Pi}{x}{T}{T'}}{\Gamma,x:T\vdash t\tpcheck T'}
\]
To show $[\sigma \lambda x.t]_{\cbe}\in\interp{\Pi  x:T.T'}_{\sigma,\rho}$ (noting that the latter is defined
and in $\mathcal{R}$ by assumption), it suffices to assume an arbitrary
$E\in\interp{T}_{\sigma,\rho}$, and show
$[[\choice(E)/x]\sigma t]_{\cbe}\in\interp{T'}_{\sigma[x\mapsto\choice(E)],\rho}$.  By the IH,
we have
$[\sigma[x\mapsto\choice(E)]t]_{\cbe}\in\interp{T'}_{\sigma[x\mapsto\choice(E)],\rho}$.
But $[\sigma[x\mapsto\choice(E)]t]_{\cbe} = [[\choice(E)/x]\sigma t]_{\cbe}$,
so this is sufficient.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash t\ t' \tpsynth [t'/x]T}{\Gamma\vdash t \tpsynth \abs{\Pi}{x}{T'}{T} & \Gamma\vdash t' \tpcheck T'}
\]
By the IH applied to the first premise, $[\sigma
t]_{\cbe}\in\interp{\Pi x:T'.T}_{\sigma,\rho}\in\mathcal{R}$.  This
means that there exists a $\lambda$-abstraction $\lambda x.\hat{t}$
such that $\lambda x.\hat{t} =_{\cbe} \sigma t$, by the semantics of $\Pi$-types.
Furthermore, for any $E\in\interp{T'}_{\sigma,\rho}$,
$[[\choice(E)/x]\hat{t}]_{\cbe}\in\interp{T}_{\sigma[x\mapsto\choice(E)],\rho}$.
By the IH applied to the second premise, $[\sigma t']_{\cbe}\in\interp{T'}_{\sigma,\rho}$,
so we can instantiate the quantifier in the previous formula to obtain
\[
 [[\choice([\sigma t']_{\cbe})/x]\hat{t}]_{\cbe}\in\interp{T}_{\sigma[x\mapsto\choice([\sigma t']_{\cbe})],\rho}
\]
By Lemma~\ref{lem:termsubstinterp}, this is equivalent to
\[
 [[\choice([\sigma t']_{\cbe})/x]\hat{t}]_{\cbe}\in\interp{[t'/x]T_2}_{\sigma,\rho}
\]
Since $\sigma (t\ t') =_{\cbe} (\lambda x.\hat{t})\ \sigma t' =_{\cbe} [[\choice([\sigma t']_{\cbe})/x]\hat{t}$,
this is sufficient.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \absu{\Lambda}{X}{t} \tpcheck \abs{\forall}{X}{\kappa}{T}}{\Gamma,X:\kappa\vdash t \tpcheck T}
\]
By the IH, $[\sigma |t|]_{\cbe}\in\interp{T}_{\sigma,\rho[X\mapsto S]}$, for all $S\in\interp{\kappa}_{\sigma,\rho}$.
This is sufficient to prove $[\sigma |\absu{\Lambda}{X}{t}|]_{\cbe}\in\interp{\forall X:\kappa.T}_{\sigma,\rho}$, by the semantics
of $\forall$-types and definition of erasure.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash t \cdot T' \tpsynth [T'/X]T}
          {\Gamma\vdash t \tpsynth \abs{\forall}{X}{\kappa}{T} & \Gamma\vdash T' \tpcheck\kappa}
\]
By the semantics of $\forall$-types and the IH applied to the first
premise, we have $[\sigma |t|]_{\cbe}\in\interp{T}_{\sigma,\rho[X\mapsto
  S]}$, for all $S\in\interp{\kappa}_{\sigma,\rho}$.  Since
$\interp{T'}_{\sigma,\rho}\in\interp{\kappa}_{\sigma,\rho}$ by the IH
applied to the second premise, we can derive $[\sigma t]_{\cbe}\in\interp{T}_{\sigma,\rho[X\mapsto \interp{T'}_{\sigma,\rho}]}$.
By Lemma~\ref{lem:tpsubstinterp},
this is equivalent to the required $[\sigma |t|]_{\cbe}\in\interp{[T'/X]T}_{\sigma,\rho}$,
using also the definition of erasure.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \absu{\Lambda}{x}{t} \tpcheck \abs{\forall}{x}{T'}{T}}{\Gamma,x:T'\vdash t \tpcheck T & x\not\in\textit{FV}(|t|)}
\]

By the IH applied to the first premise, we have
$[\sigma[x\mapsto\choice(E)]
t]_{\cbe}\in\interp{T'}_{\sigma[x\mapsto\choice(E)],\rho}$, for any
$E\in\interp{T}_{\sigma,\rho}$.  This is because
$\interp{T}_{\sigma,\rho}\in\mathcal{R}$, since $\interp{\abs{\forall}{x}{T'}{T}}_{\sigma,\rho}$ is in $\mathcal{R}$ and
hence defined, by assumption.  Since $x\not\in\textit{FV}(t)$, we know
$[[\sigma[x\mapsto\choice(E)]t]_{\cbe} = [\sigma t]_{\cbe}$.  By the
semantics of $\forall$-types and definition of erasure, this suffices to show the desired
conclusion.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash t\ \mhyph t' \tpsynth [t'/x]T}{\Gamma\vdash t \tpsynth \abs{\forall}{x}{T'}{T} & \Gamma\vdash t' \tpcheck T'}
\]
The result follows easily by the IH applied to the premises, the
semantics of $\forall$-types, definition of erasure, and Lemma~\ref{lem:termsubstinterp}.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash [ t , t' ] \tpcheck \abs{\iota}{x}{T}{T'}}
          {\Gamma\vdash t \tpcheck T & \Gamma\vdash t' \tpcheck [t/x]T' & |t| =_{\beta\eta} |t'|}
\]
By the IH, we have $[\sigma |t|]_{\cbe}\in\interp{T}_{\sigma,\rho}$ and
$[\sigma |t|]_{\cbe}\in\interp{[t/x]T'}_{\sigma,\rho}$.  By
Lemma~\ref{lem:termsubstinterp}, the latter is equivalent to
$[\sigma t]_{\cbe}\in\interp{T'}_{\sigma[x\mapsto\choice([\sigma t]_{\cbe}),\rho}$.  These two facts about $[\sigma t]_{\cbe}$ are
sufficient, by the semantics of $\iota$-types, for the desired
conclusion, using also the fact (from the third premise) that $\sigma|t| =_{\cbe} \sigma|t'|$.

\startcase{.2cm}
\[
   \infer{\Gamma\vdash t.1 \tpsynth T}{\Gamma\vdash t \tpsynth \abs{\iota}{x}{T}{T'}}
\]
The desired conclusion follows easily from the IH and the semantics of $\iota$-types.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash t.2 \tpsynth [t.1/x]T'}{\Gamma\vdash t \tpsynth \abs{\iota}{x}{T}{T'}}
\]
Similar to the previous case, using Lemma~\ref{lem:termsubstinterp}.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \beta\{t'\} \tpcheck \{ t \simeq t \}}{\Gamma\vdash \textit{FV}(t)\subseteq \textit{dom}(\Gamma)}
\]
$[\sigma|t'|]_{\cbe}\in\interp{\{ t \simeq t \}}_{\sigma,\rho}$ follows directly from the semantics of equality types.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \delta\ t \tpcheck T}{\Gamma\vdash t\tpsynth \{ \absu{\lambda}{x}{\absu{\lambda}{y}{x}} \simeq \absu{\lambda}{x}{\absu{\lambda}{y}{y}}\}}
\]
By the semantics of equality types, $[\sigma|t'|]_{\cbe}$ cannot be in the interpretation of the equation in the premise,
since the two terms in question are closed and not $\beta\eta$-equal.  By the IH applied to the first premise, however,
$[\sigma|t'|]_{\cbe}$ is in the interpretation of that equation.  This is a contradiction.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \rho\ t'\ \mhyph\ t \Leftrightarrow [t_2/x]T}
          {\Gamma\vdash t' \tpsynth t_1 \simeq t_2 & \Gamma \vdash t \Leftrightarrow [t_1/x]T}
\]
By the IH applied to the first premise, $\sigma|t_1| =_{\beta\eta} \sigma|t_2|$.  The result then follows by the IH applied to the second premise,
and Lemma~\ref{lem:termsubstinterp}.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \chi\ T\ \mhyph\ t \tpcheck T'}
          {\Gamma\vdash T\tpcheck \star & \Gamma\vdash t \tpcheck T & T \cong T'}
\]
Using the IH for the first premise and the assumption that $\interp{T'}_{\sigma,\rho}$ is in $\mathcal{R}$ and hence defined,
we can apply the IH to the third premise to get $\interp{T}_{\sigma,\rho} = \interp{T'}_{\sigma,\rho}$.  Using this and the IH for second premise,
we get the desired conclusion, using also the definition of erasure.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \chi\ T\ \mhyph\ t \tpsynth T}
          {\Gamma\vdash T\tpcheck \star & \Gamma\vdash t \tpsynth T' & T \cong T'}
\]
By the IH applied to the second premise, we have $[\sigma|t|]_{\cbe}\in\interp{T'}_{\sigma,\rho}\in\mathcal{R}$.
Using definedness of $\interp{T'}_{\sigma,\rho}$ and the IH applied to the first premise, we can apply the
IH to the third premise to get $\interp{T}_{\sigma,\rho} = \interp{T'}_{\sigma,\rho}$, from which the desired
conclusion follows by definition of erasure.

\startcase{.2cm}
\[
    \infer{\Gamma\vdash \phi\ t\ \mhyph\ t'\{t''\} \Leftrightarrow T}
          {\Gamma\vdash t\tpsynth \{t'\simeq t''\} & \Gamma\vdash t' \Leftrightarrow T}
\]
By the IH for the first premise, $\sigma|t'| =_{\cbe} \sigma|t''|$.  By the IH for the second
premise, $[\sigma|t'|]_{\cbe}\in\interp{T}_{\sigma,\rho}$.  This suffices for the desired conclusion,
using also the definition of erasure ($|\phi\ t\ \mhyph\ t'\{t''\}| = |t''|$).

\subsection*{Proof of part (5) }

\startcase{.2cm}
\[
    \infer{T \cong T'}{T \leadsto^*_\beta T_1 & T' \leadsto^*_\beta T_2 & T_1\cong^t T_2}
\]
By Lemma~\ref{lem:interppres}, we have
\[
\begin{array}{lll}
  \interp{T}_{\sigma,\rho} & = & \interp{T_1}_{\sigma,\rho}\\
  \interp{T'}_{\sigma,\rho} & = & \interp{T_2}_{\sigma,\rho}
\end{array}
\]
By the IH for the third premise, we have $\interp{T_1}_{\sigma,\rho} = \interp{T_2}_{\sigma,\rho}$,
which suffices.

\startcase{.2cm}
\[
    \infer{T \cong T'}{T \cong^t T'}
\]
By the IH.

\startcase{.2cm}
\[
    \infer{T\ t \cong^t T'\ t'}{T \cong^t T' & |t| =_{\beta\eta} |t'|}
\]
By the semantics, $\interp{T\ t}_{\sigma,\rho} =
\interp{T}_{\sigma,\rho}([\sigma|t|]_{\cbe})$.  By the second premise
and the IH for the first premise, this equals
$\interp{T'}_{\sigma,\rho}([\sigma|t'|]_{\cbe})$, as required.

\startcase{.2cm}
\[
    \infer{\{ t_1 \simeq t_2 \} \cong^t \{ t_1'\ \simeq t_2' \}}{|t_1| =_{\beta\eta} |t_1'| & |t_2| =_{\beta\eta} |t_2'|}
\]
This follows easily from the premises and the semantics of equality types.

\end{proof}
\end{document}


\documentclass{article}
\usepackage[english]{babel}
\usepackage{amsmath,amssymb,graphicx,enumerate,latexsym}

%%%%%%%%%% Start TeXmacs macros
\newcommand{\dueto}[1]{\textup{\textbf{(#1) }}}
\newcommand{\longupdownarrow}{{\mbox{\rotatebox[origin=c]{-90}{$\longleftrightarrow$}}}}
\newcommand{\nobracket}{}
\newcommand{\tmaffiliation}[1]{\\ #1}
\newcommand{\tmemail}[1]{\\ \textit{Email:} \texttt{#1}}
\newcommand{\tmop}[1]{\ensuremath{\operatorname{#1}}}
\newenvironment{enumeratenumeric}{\begin{enumerate}[1.] }{\end{enumerate}}
\newenvironment{proof}{\noindent\textbf{Proof\ }}{\hspace*{\fill}$\Box$\medskip}
%%%%%%%%%% End TeXmacs macros

\begin{document}

\title{Topology}

\author{
  Liangchun Xu
  \tmaffiliation{Department of Mechanical Engineering, Tufts University\\
  574 Boston Avenue, Medford, 02155, US}
  \tmemail{liangchun.xu@tufts.edu}
}

\date{March 4, 2019}

\maketitle

{\tableofcontents}

\section{Cardinality and the Axiom of Choice}

{\definition*{{\dueto{number sets}}Throughout these notes we will use the
following notation:
\begin{enumeratenumeric}
  \item $\mathbb{N}= \tmop{the} \tmop{set} \tmop{of} \tmop{natural}
  \tmop{numbers}$ (i.e., the positive integers).

  \item $\mathbb{Z}= \tmop{the} \tmop{set} \tmop{of} \tmop{all}
  \tmop{integers}$.

  \item $\mathbb{Q}= \tmop{the} \tmop{set} \tmop{of} \tmop{rational}
  \tmop{numbers}$.

  \item $\mathbb{R}= \tmop{the} \tmop{set} \tmop{of} \tmop{real}
  \tmop{numbers}$.
\end{enumeratenumeric}}}

{\definition*{{\dueto{cardinality}}Two sets, $A \tmop{and} B$, have the same
cardinality iff there is a 1-1, onto function $f : X \rightarrow \{ 1, 2,
\ldots, n \}$ where $n$ is an element of $\mathbb{N}$. A set that's not finite
is infinite.}}

About the natural numbers $\mathbb{N}$: every non-empty set of natural numbers
has a least element.

{\theorem*{The even positive integers have the same cardinality as the natural
numbers.}}

\begin{proof}
  The even positive integers are
  \begin{eqnarray*}
    \mathbb{E}^+ & = & \{ \nobracket 2 n | n \in \mathbb{N} \}
  \end{eqnarray*}
  Construct function $f : \mathbb{N} \rightarrow \mathbb{E}^+$
  \[ f (n) = 2 n \]
  $f (n)$ is in $\mathbb{E}^+$ by definition. Claim $f$ is 1-1 and onto:

  1-1: Suppose $f (n) = f (n')$, then $2 n = 2 n'$ and $n = n'$;

  onto: Suppose $b \in \mathbb{E}^+$, then $b = 2 n$ for some $n \in
  \mathbb{N}$, $f (n) = 2 n = b$.

  As we have exhibited a $1 - 1$ onto function $f : \mathbb{N} \rightarrow
  \mathbb{E}^+$, $| \mathbb{N} | = | \mathbb{E}^+ |$.
\end{proof}

{\theorem*{$| \mathbb{N} | = | \mathbb{Z} |$.}}

\begin{proof}
  The correpondence is
  \[ \begin{array}{ccccccccccc}
       0 & - 1 & 1 & - 2 & 2 & - 3 & 3 & - 4 & 4 & - 5 & \ldots\\
       \longupdownarrow &  &  &  & \longupdownarrow &  &  &  &  &
       \longupdownarrow & \\
       1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \ldots
     \end{array} \]

  Construct function $f : \mathbb{N} \rightarrow \mathbb{Z}$
  \[ f (n) = \left\{\begin{array}{l}
       \frac{n - 1}{2}, \tmop{if} n \in \mathbb{E}^+\\
       - \frac{n}{2}, \tmop{if} n \in \mathbb{O}^+
     \end{array}\right. \]
  $f (n)$ is in $\mathbb{Z}$ by definition. Claim $f$ is 1-1 and onto:

  1-1: Suppose $f (n) = f (n')$, then
  \[ \left\{\begin{array}{l}
       \frac{n - 1}{2} = \frac{n' - 1}{2}, \tmop{if} n \in \mathbb{E}^+\\
       - \frac{n}{2} = - \frac{n'}{2}, \tmop{if} n \in \mathbb{O}^+
     \end{array}\right. \Rightarrow n = n' \]
  Since $\frac{n - 1}{2} \geqslant 0 \tmop{and} - \frac{n}{2} < 0$, we have
  $\frac{n - 1}{2} \neq - \frac{n'}{2}$; only the above two cases are
  possible.

  onto: Suppose $b \in \mathbb{Z}$, then
  \[ \left\{\begin{array}{l}
       b = \frac{n - 1}{2}, \tmop{if} b \geqslant 0\\
       b = - \frac{n}{2}, \tmop{if} b < 0
     \end{array}\right. \]
  for some $n \in \mathbb{N}$, $f (n) = b$.

  As we have exhibited a $1 - 1$ onto function $f : \mathbb{N} \rightarrow
  \mathbb{Z}$, $| \mathbb{N} | = | \mathbb{Z} |$.
\end{proof}

{\theorem*{{\dueto{pigeon-hole principle}}Suppose that $n$ is a natural number
and you have $n$ pidgeon-holes. If you have $m$ podgeons where $m > n$, and
you put each pidgeon in one of your $n$ pidgeon-holes, there will be some hole
which contains more than 1 pidgeon.}}

\begin{proof}
  Let $q_i$ be the number of pidgeons in each hole, then
  \[ \sum_{i = 1}^n q_i = m \]
  Suppose no hole contains more than 1 pidgeon, which is
  \[ 0 \leqslant q_i \leqslant 1, \applicationspace{1 \tmop{em}} i = 1, 2,
     \ldots n \]
  Then we have
  \[ \sum_{i = 1}^n q_i \leqslant \sum_{i = 1}^n 1 = n \]
  Since $m > n$, then
  \[ \sum_{i = 1}^n q_i < m \]
  which leads to contradiction. Therefore the assumption is not correct. There
  must be some hole which contains more than 1 pidgeon.
\end{proof}

{\theorem*{{\dueto{induction}}For each natural number $n$, let $S (n)$ be a
statement that is either true or false. Then suppose that
\begin{enumeratenumeric}
  \item $S (1)$ is true.

  \item If $S (k)$ is true, then $S (k + 1)$ is true.
\end{enumeratenumeric}
Then $S (n)$ is true for all natural numbers $n$.}}

\begin{proof}
  Suppose there is an non-empty set
  \[ X = \{ n \in \mathbb{N}, S (n) \tmop{is} \tmop{false} \} \]
  There exists a smallest element $x \in X$ since $X \subseteq \mathbb{N}$.

  According to assumption 1 and the definiton of $X$, $x \neq 1 \tmop{and} x
  > 1$.

  According to assumption 2, if $S (x)$ is false, then $S (x - 1)$ is also
  false. Since $x - 1 < x$ and $x - 1 \in \mathbb{N}$, $x - 1$ becomes the
  smallest element in $X$, which is contradictory to the fact that $x$ is the
  smallest element in $X$. Therefore the assumption is wrong. $X$ is empty and
  $S (n)$ is true for all natural numbers $n$.
\end{proof}

{\theorem*{Every subset of $\mathbb{N}$ is either finite or has the same
cardinality as $\mathbb{N}$.}}

\begin{proof}
  Let $X \subseteq \mathbb{N}$, construct function $f : \mathbb{N} \rightarrow
  X$
  \begin{eqnarray*}
    f (1) & = & \min (X)\\
    f (2) & = & \min (X\backslash \{ f (1) \})\\
    & \vdots & \\
    f (n) & = & \min (X\backslash \{ f (1), f (2), \ldots, f (n - 1) \})
  \end{eqnarray*}
  if $X\backslash \{ f (1), f (2), \ldots, f (n - 1) \}$ is empty, then we
  have a 1-1 bijection $f : \{ 1, 2, \ldots, n \} \rightarrow X$, which means
  $X$ is finite. If $X$ is infinite, then claim $f : \mathbb{N} \rightarrow X$
  is $1 - 1$ and onto:

  1-1: Suppose $f (n) = f (n')$, then $n = n'$.

  onto: Suppose $b \in X$, then $b = \min (X\backslash \{ f (1), f (2),
  \ldots, f (n - 1) \})$ for some $n \in \mathbb{N}$, $f (n) = b$.

  As we have exhibited a $1 - 1$ onto function $f : \mathbb{N} \rightarrow X$,
  $| \mathbb{N} | = | X |$.

  Therefore every subset of $\mathbb{N}$ is either finite or has the same
  cardinality as $\mathbb{N}$.
\end{proof}

{\definition*{{\dueto{countable set}}A set that has the same cardinality as a
subset of $\mathbb{N}$ is countable.}}

{\theorem*{Every infinite set has a countably infinite subset.}}

{\theorem*{A set is infinite iff there is a 1-1 function from the set into a
proper subset of itself.}}

{\theorem*{$\mathbb{Q}$ is countable.}}

\begin{proof}
  Construct function $f : \mathbb{N} \rightarrow \mathbb{Q}$

  \[ \begin{array}{lllllllllllll}
       & 0 &  & - 1 &  & 1 &  & - 2 &  & 2 &  & - 3 & \ldots\\
       1 & \frac{0}{1} & \rightarrow & - \frac{1}{1} & \rightarrow &
       \frac{1}{1} &  & - \frac{2}{1} & \rightarrow & \frac{2}{1} &  & -
       \frac{3}{1} & \ldots\\
       &  &  &  & \swarrow &  & \nearrow &  & \swarrow &  & \nearrow &  & \\
       2 &  &  & - \frac{1}{2} &  & \frac{1}{2} &  & - \frac{2}{2} &  &
       \frac{2}{2} &  &  & \\
       &  &  & \downarrow & \nearrow &  & \swarrow &  & \nearrow &  &  &  &
       \\
       3 &  &  & - \frac{1}{3} &  & \frac{1}{3} &  & - \frac{2}{3} &  &  &  &
       & \\
       &  &  &  & \swarrow &  & \nearrow &  &  &  &  &  & \\
       4 &  &  & - \frac{1}{4} &  & \frac{1}{4} &  &  &  &  &  &  & \\
       &  &  & \downarrow & \nearrow &  &  &  &  &  &  &  & \\
       5 &  &  & - \frac{1}{5} &  &  &  &  &  &  &  &  & \\
       \vdots &  &  &  &  &  &  &  &  &  &  &  &
     \end{array} \]

  $f (n)$ is in $\mathbb{Z}$ by definition. Claim $f$ is 1-1 and onto:

  1-1: Suppose $f (n) = f (n')$, then

  onto: Suppose $b \in \mathbb{Z}$, then

  \

  for some $n \in \mathbb{N}$, $f (n) = b$.

  As we have exhibited a $1 - 1$ onto function $f : \mathbb{N} \rightarrow
  \mathbb{Q}$, $| \mathbb{N} | = | \mathbb{Q} |$.
\end{proof}

\end{document}


% !TeX spellcheck = en_US
\documentclass{yLectureNote}

\title{Analyse I}
\subtitle{subtitle}
\author{Harvey Sheppard}
\date{Fall Semester 2016}
\yLanguage{English}

\professor{M. Professor}

\usepackage{lipsum}

\begin{document}
	\titleOne

	\yTableOfContent

	\chapter{Mathematical Argumentation and Proofs}
	\printMarginPartialToc

	\section{Mathematical Argumentation}
	\classDate{13}{9}{2016}
	\nextSerie

	\lipsum[1]

	\marginTips*{Don't remember to practice your math! It is the only way to get through!}

	\subsection{Using Conditions}
	\lipsum[2]
	\marginCritical*{I should reread this part, as I didn't understood it well... Maybe it's because it's in Latin?}

	\lipsum[3]\marginElement{\marginTitle{Title} \lipsum*[7]}

	\checkInfo{Yeaaaah!}{\lipsum[4]\lipsum[2]}

	\section{Mathematical Proofs}
	\begin{theorem}[Pythagoras]
		Assuming we have a rectangle triangle with the hypotenuse named c. Then:
		\[
			a^2 + b^2 = c^2
		\]
	\end{theorem}

	\marginInfo*{This formula is really important:
		\begin{equation}
		a^2 + b^2 = c^2
		\end{equation}
	}

	\yOrnament
\end{document}


\section{MIPS reference}
\textbf{Arithmetic:} <op> \$d, \$s, \$t: <op> = [add(u)| and| nor| or| sub(u)| xor]; <op> \$s, \$t, i: <op> = [add((u)i)| andi| ori| xori]; <op> \$s, \$t: <op> = [div(u)| mult(u)] where result is in hi for div and mod in lo and result for mult in hi and lo;\\
\textbf{Branch:} b[eq|ne] \$s, \$t, label; b[lez|gtz] \$s, label. \textbf{Jump:} j[al] label; j[al]r \$s\\
\textbf{Load} l[b(u)|h(u)|w] \$t, i(\$s) \textbf{datamovement:} m[f|t][hi|lo] \$[d|t]
\subsection*{call codes}
\textbf{print} 1:int, 2:fl, 3:dbl, 4:str, 11:char; \textbf{read} same as before + 1; 10: exit
\subsection*{stackframe}
\textbf{building} sw \$fp, 0(\$sp); move \$fp, \$sp; subu \$sp, \$sp, <size> + 4; sw \$ra, -4(\$fp); sw <reg\_to\_store>, -offset(\$fp)\\
\textbf{destructing} lw <reg\_to\_load>, -<size> + 4(\$fp); lw \$ra, -4(\$fp); move \$sp, \$fp; lw \$fp, 0(\$sp); j \$ra


\subsection{The Euler-Lagrange equations for fields}


\appendix

\section{Appendix: The \texttt{VPINN\_HelmholtzImpedanceRF} Network}
\label{app:deeprf}
\autoref{lst:deeprf} includes the code implementation of the proposed network on top of the parent class. In this architecture, we use a local version of ReLU as the activation function of the first hidden layer, and a sinusoidal (hyperbolic tangent) activation function for other hidden layers. The idea is to impose different behaviors for different regions of the domain. \autoref{fig:deeprftrain} shows that without any other consideration, training such a network fails. The solution of the failed training is shown in \autoref{fig:deeprfsol}. Some other similar architectures have been tried out, which also failed. Among those were putting the ReLU activation function only on the last layer, and non-local ReLU activation functions on the first two layers.

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.48\textwidth]{img/DeepRF-D004N012K038-training.png}
    \caption{Training loss and solution error of the \texttt{VPINN\_HelmholtzImpedanceRF} network with 4 hidden layers for wave number $k=8.0$.}
    \label{fig:deeprftrain}
\end{figure}

\begin{figure}[h!]
    \centering
    \includegraphics[width = 0.7\textwidth]{img/DeepRF-D004N012K038-sol.png}
    \caption{The solution of the \texttt{VPINN\_HelmholtzImpedanceRF} network with 4 hidden layers for wave number $k=8.0$.}
    \label{fig:deeprfsol}
\end{figure}

\lstinputlisting[
    language=Python,
    style=pythonstyle,
    label={lst:deeprf},
    caption={Code snippet of the \texttt{VPINN\_HelmholtzImpedanceRF} class which inherits from the main \texttt{VPINN\_HelmholtzImpedance} class.}
    ]
{lst/VPINN-HelmholtzImpedanceRF.py}

\section{Appendix: Evolution of the Solution}
\label{app:evolutions}
\autoref{fig:evolutionrandinitsol} illustrates the evolution of the solution of a network architecture that converges to the solution in 30000 epochs. We can see that from the initial random initialization, the network is able to capture the main features of the solution in 2000 epochs, and converges to the final solution in the following 28000 epochs. An interesting observation is that there is a bias from left to right which could also be captured in the initial result of the network (epoch 0). We can see that the solution converges faster in the ranges closer to the left boundary.

The same bias to the left boundary could also be observed in \autoref{fig:evolutionlsinitsol} which illustrates the evolution of solution of the same network with least-squares initialization in the initial 2000 epochs. In \autoref{fig:vpinnslsinitk8}, we can see that the solution error of this network does not improve much with least-square initialization after around epoch 2000. Another observation is that the most of the error comes from the imaginary part of the solution, which is not the case with random initialization.

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-00000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-02000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-04000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-08000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-08000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-16000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_randinit/sol-30000.png}
    \end{subfigure}
    \caption{The evolution of the solution during the training of a shallow network with 20 nodes and 20 test functions for $k=8.0$.}
    \label{fig:evolutionrandinitsol}
\end{figure}

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_lsinit/sol-00000.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_lsinit/sol-00350.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_lsinit/sol-00700.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_lsinit/sol-01400.png}
    \end{subfigure}
    \vfill
    \begin{subfigure}[b]{0.85\textwidth}
        \includegraphics[width=\textwidth]{img/evolution_lsinit/sol-02000.png}
    \end{subfigure}
    \caption{The evolution of the solution during the training of a shallow network with 20 nodes and 20 test functions with least-squares initialization (constant weights) for $k=8.0$.}
    \label{fig:evolutionlsinitsol}
\end{figure}