\chapter{Metatheory and Type Preservation} \label{ch:proofs}

\input{figures/takahashi.tex}

In this chapter, I elaborate on the proofs of the lemmas and theorems listed in \cref{sec:syntactic-model},
culminating in type preservation, which by \cref{thm:overview:consistency} proves the consistency of \lang.
Prior to these proofs, I provide the required metatheoretical properties of both \lang and \CICE.

\section{Metatheory of \lang}

\subsection{Basic properties}

We begin with three basic properties that all judgements satisfy:
\emph{weakening}\index{weakening}, which allows environments to be extended;
\emph{replacement}\index{replacement}, which allows replacing assumptions by subtypes;
and \emph{substitutivity}\index{substitutivity}, which allows the substitution of an assumption by a well-typed term
or a size variable by a size expression.
Because term environments have definitions in addition to assumptions,
substitutivity can only apply to variables that aren't bound to a definition in the environment.
A final property is the congruence of the reflexive, transitive closure of reduction,
which extends congruence of reduction to its closure.

\begin{lemma}[Weakening] \label{lem:weakening}
Let $\Phi$ be a size environment,
let $\Gamma$ and $\Gamma'$ be term environments
where $\Gamma'$ does not shadow any variables of $\Gamma$,
and suppose $\wf{\Phi}{\Gamma, \Gamma'}$.
\begin{enumerate}[noitemsep]
  \item \label{item:weakening:red} If $\red{\Phi; \Gamma}{e_1}{e_2}$ then $\red{\Phi; \Gamma, \Gamma'}{e_1}{e_2}$.
  \item \label{item:weakening:red*} If $\red*{\Phi; \Gamma}{e_1}{e_2}$ then $\red*{\Phi; \Gamma, \Gamma'}{e_1}{e_2}$.
  \item \label{item:weakening:subtype} If $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$ then $\subtype{\Phi; \Gamma, \Gamma'}{\tau_1}{\tau_2}$.
  \item If $\type{\Phi; \Gamma}{e}{\tau}$ then $\type{\Phi; \Gamma, \Gamma'}{e}{\tau}$.
\end{enumerate}
\end{lemma}

\begin{proof} \hfill
\begin{enumerate}[noitemsep]
  \item By induction on the derivation of $\red{\Phi; \Gamma}{e_1}{e_2}$.
  \item By induction on the derivation of $\red*{\Phi; \Gamma}{e_1}{e_2}$,
    using \cref{item:weakening:red} in \rref{red*-once}.
  \item Trivial by \cref{item:weakening:red*} in \rref{subtype-red}.
  \item By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$,
    using \cref{item:weakening:subtype} in \rref{conv}. \qedhere
\end{enumerate}
\end{proof}

\begin{lemma}[Replacement by subtyping] \label{lem:replacement-subtyping}\index{subtyping}
Suppose $\subtype{\Phi; \Gamma_1}{\sigma_1}{\sigma_2}$ where
$\type{\Phi; \Gamma_1}{\sigma_1}{U}$ and $\type{\Phi; \Gamma_1}{\sigma_2}{U}$
for some $U$.
\begin{enumerate}[noitemsep]
  \item \label{item:replacement-subtyping:red}
    If $\red{\Phi; \Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}{e_1}{e_2}$
    then $\red{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{e_1}{e_2}$.
  \item \label{item:replacement-subtyping:red*}
    If $\red*{\Phi; \Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}{e_1}{e_2}$
    then $\red*{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{e_1}{e_2}$.
  \item \label{item:replacement-subtyping:subtyping}
    If $\subtype{\Phi; \Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}{\tau_1}{\tau_2}$
    then $\subtype{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{\tau_1}{\tau_2}$.
  \item
    \begin{enumerate}[noitemsep]
      \item \label{item:replacement-subtyping:typing} If $\type{\Phi; \Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}{e}{\tau}$
        then $\type{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{e}{\tau}$.
      \item \label{item:replacement-subtyping:wf} If $\wf{\Phi}{\Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}$
        then $\wf{\Phi}{\Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}$.
    \end{enumerate}
\end{enumerate}
\end{lemma}

\begin{proof}
  For \crefrange{item:replacement-subtyping:red}{item:replacement-subtyping:subtyping},
  the proof structure is similar to that of \nameref{lem:weakening}.
  \begin{enumerate}[noitemsep] \setcounter{enumi}{3}
    \item By mutual induction on the derivations of
      $\type{\Phi; \Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}{e}{\tau}$ and
      $\wf{\Phi}{\Gamma_1, \annot{x}{\sigma_2}, \Gamma_2}$.
      % For \rref{cons-ass}, if the variable is $x$ (\ie if $\Gamma_2 = \mt$), use $\type{\Phi; \Gamma_1}{\sigma_1}{U}$.
      For \rref{var}, if the variable is $x$, apply \rref{conv}:
      \begin{mathpar}
      \inferrule{
        \type{\Phi; \Gamma_1}{\sigma_1}{U} \\
        \type{\Phi; \Gamma_1}{\sigma_2}{U} \\
        \type{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{x}{\sigma_1} \\
        \subtype{\Phi; \Gamma_1}{\sigma_1}{\sigma_2}
      }{
        \type{\Phi; \Gamma_1, \annot{x}{\sigma_1}, \Gamma_2}{x}{\sigma_2}
      }
      \end{mathpar}
  \end{enumerate}
\end{proof}

\begin{corollary}
\nameref{lem:replacement-subtyping} also applies when the environment contains
$\define{x}{\sigma_2}{e'}$ rather than $\annot{x}{\sigma_2}$
by the exact same arguments.
\end{corollary}

\begin{lemma}[Substitutivity by terms] \label{lem:substitutivity-terms}\index{substitutivity}
Suppose $\type{\Phi; \Gamma_1}{e}{\sigma}$.
\begin{enumerate}[noitemsep]
  \item If $\red{\Phi; \Gamma_1, \annot{x}{\sigma}, \Gamma_2}{e_1}{e_2}$
    then $\red{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e}}{\subst{e_1}{x}{e}}{\subst{e_2}{x}{e}}$
  \item If $\red*{\Phi; \Gamma_1, \annot{x}{\sigma}, \Gamma_2}{e_1}{e_2}$
  then $\red*{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e}}{\subst{e_1}{x}{e}}{\subst{e_2}{x}{e}}$
  \item If $\subtype{\Phi; \Gamma_1, \annot{x}{\sigma}, \Gamma_2}{\tau_1}{\tau_2}$
    then $\subtype{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e}}{\subst{\tau_1}{x}{e}}{\subst{\tau_2}{x}{e}}$
  \item \label{item:substitutivity:typing-wf}
    \begin{enumerate}[noitemsep]
      \item \label{item:substitutivity:typing} If $\type{\Phi; \Gamma_1, \annot{x}{\sigma}, \Gamma_2}{e'}{\tau}$
        then $\type{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e}}{\subst{e'}{x}{e}}{\subst{\tau}{x}{e}}$
      \item \label{item:substitutivity:wf} If $\wf{\Phi}{\Gamma_1, \annot{x}{\sigma}, \Gamma_2}$
        then $\wf{\Phi}{\Gamma_1, \subst{\Gamma_2}{x}{e}}$.
    \end{enumerate}
\end{enumerate}
\end{lemma}

\begin{proof}
The proof structure is similar to that of \nameref{lem:replacement-subtyping}.
For \rref{var} of \cref{item:substitutivity:typing}, if the variable is $x$,
apply \nameref{lem:weakening} to $\type{\Gamma_1}{e}{\sigma}$
using the extended environment from \cref{item:substitutivity:wf}.
\end{proof}

\begin{corollary}
\nameref{lem:substitutivity-terms} also applies when the environment contains $\define{x}{\sigma}{e}$
rather than $\annot{x}{\sigma}$ by the exact same arguments.
Note that the term being substituted in must be the one defined as $x$.
\end{corollary}

\begin{lemma}[Substitutivity by unbounded sizes] \label{lem:substitutivity-unbounded}
Suppose $\wf{\Phi_1}{s}$.
\begin{enumerate}[noitemsep]
  \item \label{item:substitutivity:unbounded:red}
    If $\red{\Phi_1, \alpha, \Phi_2; \Gamma}{e_1}{e_2}$
    then $\red{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \subst{\Gamma}{\alpha}{s}}{\subst{e_1}{\alpha}{s}}{\subst{e_2}{\alpha}{s}}$.
  \item \label{item:substitutivity:unbounded:red*}
    If $\red*{\Phi_1, \alpha, \Phi_2; \Gamma}{e_1}{e_2}$
    then $\red*{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \subst{\Gamma}{\alpha}{s}}{\subst{e_1}{\alpha}{s}}{\subst{e_2}{\alpha}{s}}$.
  \item \label{item:substitutivity:unbounded:subtyping}
    If $\subtype{\Phi_1, \alpha, \Phi_2; \Gamma}{\tau_1}{\tau_2}$
    then $\subtype{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \subst{\Gamma}{\alpha}{s}}{\subst{\tau_1}{\alpha}{s}}{\subst{\tau_2}{\alpha}{s}}$.
  \item \label{item:substitutivity:unbounded:sizing}
    \begin{enumerate}[noitemsep]
      \item If $\wf{\Phi_1, \alpha, \Phi_2}{r}$
        then $\wf{\Phi_1, \subst{\Phi_2}{\alpha}{s}}{\subst{r}{\alpha}{s}}$.
      \item If $\wf{}{\Phi_1, \alpha, \Phi_2}$
        then $\wf{}{\Phi_1, \subst{\Phi_2}{\alpha}{s}}$.
    \end{enumerate}
  \item \label{item:substitutivity:unbounded:subsizing}
    If $\subsize{\Phi_1, \alpha, \Phi_2}{s_1}{s_2}$
    then $\subsize{\Phi_1, \subst{\Phi_2}{\alpha}{s}}{\subst{s_1}{\alpha}{s}}{\subst{s_2}{\alpha}{s}}$.
  \item
    \begin{enumerate}[noitemsep]
      \item If $\type{\Phi_1, \alpha, \Phi_2; \Gamma}{e}{\tau}$
        then $\type{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \subst{\Gamma}{\alpha}{s}}{\subst{e}{\alpha}{s}}{\subst{\tau}{\alpha}{s}}$.
      \item If $\wf{\Phi_1, \alpha, \Phi_2}{\Gamma}$ then $\wf{\Phi_1, \subst{\Phi_2}{\alpha}{s}}{\subst{\Gamma}{\alpha}{s}}$
    \end{enumerate}
\end{enumerate}
\end{lemma}

\begin{proof}
For \crefrange{item:substitutivity:unbounded:red}{item:substitutivity:unbounded:subtyping},
the proof structure is similar to that of \nameref{lem:substitutivity-terms}.
\begin{enumerate}[noitemsep] \setcounter{enumi}{3}
  \item By mutual induction on the derivations of $\wf{\Phi_1, \alpha, \Phi_2}{r}$ and $\wf{}{\Phi_1, \alpha, \Phi_2}$.
    If $r = \alpha$ (\ie $\Phi_2 = \mt$) and $\alpha \in \Phi_1$, use $\wf{\Phi_1}{s}$.
  \item By induction on the derivation of $\subsize{\Phi_1, \alpha, \Phi_2}{s_1}{s_2}$,
    using \cref{item:substitutivity:unbounded:sizing}.
  \item By mutual induction on the derivations of $\type{\Phi_1, \alpha, \Phi_2; \Gamma}{e}{\tau}$
    and $\wf{\Phi_1, \alpha, \Phi_2}{\Gamma}$,
    using \cref{item:substitutivity:unbounded:subtyping} in \rref{conv},
    \cref{item:substitutivity:unbounded:sizing} in \rref{sapp, forall<, slam<},
    and \cref{item:substitutivity:unbounded:subsizing} in \rref{sapp<}.
    \qedhere
\end{enumerate}
\end{proof}

\begin{lemma}[Substitutivity by bounded sizes] \label{lem:substitutivity-bounded}
Suppose $\subsize{\Phi_1}{\sss{r}_1}{r_2}$.
\begin{enumerate}[noitemsep]
  \item \label{item:substitutivity:bounded:red}
    If $\red{\Phi_1, \bound{\alpha}{r_2}, \Phi_2; \Gamma}{e_1}{e_2}$ \\
    then $\red{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}; \subst{\Gamma}{\alpha}{r_1}}{\subst{e_1}{\alpha}{r_1}}{\subst{e_2}{\alpha}{r_1}}$.
  \item \label{item:substitutivity:bounded:red*}
    If $\red*{\Phi_1, \bound{\alpha}{r_2}, \Phi_2; \Gamma}{e_1}{e_2}$ \\
    then $\red*{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}; \subst{\Gamma}{\alpha}{r_1}}{\subst{e_1}{\alpha}{r_1}}{\subst{e_2}{\alpha}{r_1}}$.
  \item \label{item:substitutivity:bounded:subtyping}
    If $\subtype{\Phi_1, \bound{\alpha}{r_2}, \Phi_2; \Gamma}{\tau_1}{\tau_2}$ \\
    then $\subtype{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}; \subst{\Gamma}{\alpha}{r_1}}{\subst{\tau_1}{\alpha}{r_1}}{\subst{\tau_2}{\alpha}{r_1}}$.
  \item \label{item:substitutivity:bounded:sizing}
    \begin{enumerate}[noitemsep]
      \item If $\wf{\Phi_1, \bound{\alpha}{r_2}, \Phi_2}{s}$
        then $\wf{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}}{\subst{s}{\alpha}{r_1}}$.
      \item If $\wf{}{\Phi_1, \bound{\alpha}{r_2}, \Phi_2}$
        then $\wf{}{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}}$.
    \end{enumerate}
  \item \label{item:substitutivity:bounded:subsizing}
    If $\subsize{\Phi_1, \bound{\alpha}{r_2}, \Phi_2}{s_1}{s_2}$
    then $\subsize{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}}{\subst{s_1}{\alpha}{r_1}}{\subst{s_2}{\alpha}{r_1}}$.
  \item
    \begin{enumerate}[noitemsep]
      \item If $\type{\Phi_1, \bound{\alpha}{r_2}, \Phi_2; \Gamma}{e}{\tau}$ \\
        then $\type{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}; \subst{\Gamma}{\alpha}{r_1}}{\subst{e}{\alpha}{r_1}}{\subst{\tau}{\alpha}{r_1}}$.
      \item If $\wf{\Phi_1, \bound{\alpha}{r_2}, \Phi_2}{\Gamma}$ then $\wf{\Phi_1, \subst{\Phi_2}{\alpha}{r_1}}{\subst{\Gamma}{\alpha}{r_1}}$
    \end{enumerate}
\end{enumerate}
\end{lemma}

\begin{proof}
The proof structure is similar to that of \nameref{lem:substitutivity-unbounded}.
For \cref{item:substitutivity:bounded:subsizing},
if $\alpha = r_1$ and $s_2 = r_2$ (\ie $\Phi_2 = \mt$),
use $\subsize{\Phi_1}{\sss{r}_1}{r_2}$.
\end{proof}

\begin{lemma}[Congruence of closure of reduction] \label{lem:congruence}
If $\red*{\Phi'; \Gamma'}{e_1}{e_2}$
then $\red*{\Phi; \Gamma}{\subst{e}{x}{e_1}}{\subst{e}{x}{e_2}}$.
\end{lemma}

\begin{proof}
Either $e_1 = e_2$, making the goal trivial by \rref{red*-refl},
or we can show by induction that $\red*{\Phi'; \Gamma'}{e_1}{e_2}$
can be split into a finite number of reductions
$\Phi'; \Gamma' \vdash e_1 \rhd e'_{1} \rhd \dots \rhd e'_{n} \rhd e_2$.
By \rref{red-cong, red*-once}, we have
$\Phi; \Gamma \vdash \subst{e}{x}{e_1} \rhd^* \subst{e}{x}{e'_{1}} \rhd^* \dots \rhd^* \subst{e}{x}{e'_{n}} \rhd^* \subst{e}{x}{e_2}$,
which can then be chained together using \rref{red*-trans}.
\end{proof}

From here onwards, because it's used so often in uninteresting ways,
I omit explicit references to uses of weakening.

\subsection{Confluence}

\emph{Confluence}\index{confluence} states that if some term
reduces to two different terms, those two terms must eventually
reduce to some common term.
This property is used to prove transitivity of subtyping,
which in turn is used in several proofs throughout.
The technique I use is to first show there is some judgement that satisfies the
\emph{Z property}\index{Z property}~\citep{Z, confluence} for reduction,
so called for the Z shape formed by reduction and its closure.
This is illustrated by \cref{fig:Z},
with the solid arrow representing reduction $\rhd$ and
dashed arrows representing its reflexive, transitive closure $\rhd^*$.
Confluence then follows from the Z property.

\begin{definition}[Z property] \label{def:Z}
The judgement $\develop{\mt}{\mt}{\mt}$ is said to satisfy the Z property
if $\develop{\Phi; \Gamma}{e_i}{e'_i}$ for $i = 1, 2$
and $\red{\Phi; \Gamma}{e_1}{e_2}$
imply that $\red*{\Phi; \Gamma}{e_2}{e'_1}$
and $\red*{\Phi; \Gamma}{e'_1}{e'_2}$ hold.
\end{definition}

\begin{lemma} \label{lem:confluence}
If there exists some judgement satisfying the Z property,
then given $\red*{\Phi; \Gamma}{e}{e_1}$ and $\red*{\Phi; \Gamma}{e}{e_2}$,
there exists some term $e'$ such that
$\red*{\Phi; \Gamma}{e_1}{e'}$ and $\red*{\Phi; \Gamma}{e_2}{e'}$.
\end{lemma}

\vspace{-\baselineskip}
\begin{figure}[h]
\centering
\begin{tikzcd}
  e_1
    \arrow[r, rightarrow]
    \arrow[d, dotted, no head, "\blacktriangledown" description]
  & e_2
    \arrow[d, dotted, no head, "\blacktriangledown" description]
    \arrow[dl, dashrightarrow] \\
  e'_1
    \arrow[r, dashrightarrow]
  & e'_2
\end{tikzcd}
\caption{Diagram illustrating the Z property.}
\label{fig:Z}
\end{figure}

The judgement I use to satisfy the Z property is an extension of the
\emph{complete development}\index{complete development}
used by~\citet{Takahashi},
which in short reduces all visible redexes from the inside out.
The inclusion of the size and term environments are crucial,
since $\delta$-reduction depends on definitions in the environment
and $\mu$-reduction depends on subsizing.
\cref{fig:develop,app:cong:develop}
present the rules for complete development.
The first rule from left to right, top to bottom that applies is used,
making complete development decidable and deterministic (up to subsizing)
given the environments and an initial term.

\FigTakahashi{fig:develop}

To show that the mapping satisfies the Z property,
we first show that it satisfies some properties that will be useful later.

\begin{lemma} \label{lem:develop-compos}
If $\develop{\Phi; \Gamma_1, \annot{x}{\tau}, \Gamma_2}{e_1}{e'_1}$ and
$\develop{\Phi; \Gamma_1}{e_2}{e'_2}$, then
$\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}}{\subst{e_1}{x}{e_2}}{\subst{e'_1}{x}{e'_2}}$.
\end{lemma}

\begin{proof}
By induction on the structure of $e_1$.
The cases not involving a redex are straightforward by the induction hypotheses,
while the ones that do, namely those in \cref{fig:develop},
require some attention to substitution.
I cover only the cases for a $\delta$-redex and a $\zeta$-redex,
as these involve some subtleties with definitions in the environment,
and the remaining redex cases are similar to the latter but without definitions.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $e_1 = y$ and $(\define{y}{\any}{e}) \in \Gamma_1, \annot{x}{\tau}, \Gamma_2$. \\
    We then have that $\subst{e_1}{x}{e_2} = y$ and $e'_1 = e$.
    If $y$ is in $\Gamma_1$, then $x \notin \FV{e}$, so $\subst{e}{x}{e_2} = e$,
    and $\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}}{y}{e}$.
    If $y$ is in $\Gamma_2$, then $(\define{y}{\any}{\subst{e}{x}{e_2}}) \in \subst{\Gamma_2}{x}{e_2}$,
    and $\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}}{y}{\subst{e}{x}{e'_2}}$.
  \item $e_1 = \letin{y}{\tau}{e_3}{e_4}$. \\
    Let $e'_3$, $e'_4$ be the complete developments of $e_3$ and $e_4$, respectively.
    Suppose that $x \neq y$.
    By the induction hypotheses, we have
    \begin{itemize}[noitemsep]
      \item $\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}}{\subst{e_3}{x}{e_2}}{\subst{e'_3}{x}{e'_2}}$ and
      \item $\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}, \define{y}{\subst{\tau}{x}{e_2}}{\subst{e_3}{x}{e_2}}}{\subst{e_4}{x}{e_2}}{\subst{e'_4}{x}{e'_2}}$.
    \end{itemize}
    Then by complete development of $\kw{let}$ expressions, we have
    $\develop{\Phi; \Gamma_1, \subst{\Gamma_2}{x}{e_2}}{\letin{y}{\subst{\tau}{x}{e_2}}{\subst{e_3}{x}{e_2}}{\subst{e_4}{x}{e_2}}}{\subst{(\subst{e'_4}{x}{e'_2})}{y}{\subst{e'_3}{x}{e'_2}}}$. \\
    By the properties of substitution, we have that the right-hand side is
    $\subst{(\subst{e'_4}{y}{e'_3})}{x}{e'_2}$,
    giving us
    $\develop{\Phi; \Gamma}{\subst{(\letin{y}{\tau}{e_3}{e_4})}{x}{e_2}}{\subst{(\subst{e'_4}{y}{e'_3})}{x}{e'_2}}$
    as desired.
    If $x = y$, then $e_2$ and $e'_2$ are never substituted into $e_4$ and $e'_4$, respectively,
    simplifying the above argument. \qedhere
\end{itemize}
\end{proof}

\begin{lemma} \label{lem:develop-compos-size}
If $\develop{\Phi_1, \alpha, \Phi_2; \Gamma}{e}{e'}$ or
$\develop{\Phi_1, \bound{\alpha}{r}, \Phi_2; \Gamma}{e}{e'}$ then
$\develop{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \Gamma}{\subst{e}{\alpha}{s}}{\subst{e'}{\alpha}{s}}$.
\end{lemma}

\begin{proof}
By straightforward induction on the structure of $e$.
Intuitively, since size expressions aren't terms and don't reduce,
the substitution leaves the structure of complete development untouched.
\end{proof}

\begin{lemma} \label{lem:develop-red*}
If $\develop{\Phi; \Gamma}{e}{e'}$
then $\red*{\Phi; \Gamma}{e}{e'}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\develop{\Phi; \Gamma}{e}{e'}$.
Again, the cases not involving a redex are straightforward by the induction hypotheses
using \cref{lem:congruence},
while the ones that do also use the reduction rule for the corresponding redex.
This time, I cover only the cases for a $\delta$-redex and a $\mu$-redex,
with the remaining redex cases similar to the latter.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $e = x$.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      (\define{x}{\tau}{e}) \in \Gamma \\
      \develop{\Phi; \Gamma}{e}{e'}
    }{
      \develop{\Phi; \Gamma}{x}{e'}
    }
    \end{mathpar}
    By the induction hypothesis, we have $\red*{\Phi; \Gamma}{e}{e'}$.
    By $\delta$-reduction, we have $\red{\Phi; \Gamma}{x}{e}$.
    Then by \rref{red*-once, red*-trans}, we have $\red*{\Phi; \Gamma}{x}{e'}$.
  \item $e = \App{\fix{f}{\alpha}{\tau}{e}}{s}$.
    \begin{mathpar}
    \inferrule{
      \subsize{\Phi}{\sss{r}}{s} \\
      \develop{\Phi, \alpha; \Gamma}{\tau}{\tau'} \\
      \develop{\Phi, \alpha; \Gamma, \annot{f}{\Funtype<{\beta}{\alpha}{\subst{\tau}{\alpha}{\beta}}}}{e}{e'}
    }{
      \develop{\Phi; \Gamma}{\App{\fix{f}{\alpha}{\tau}{e}}{s}}{\subst{e'}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\tau'}{e'})}{\beta}}}}
    }
    \end{mathpar}
    By the induction hypotheses, we have
    \begin{itemize}[noitemsep]
      \item $\red*{\Phi, \alpha; \Gamma}{\tau}{\tau'}$ and
      \item $\red*{\Phi, \alpha; \Gamma, \annot{f}{\Funtype<{\beta}{\alpha}{\subst{\tau}{\alpha}{\beta}}}}{e}{e'}$.
    \end{itemize}
    By \cref{lem:congruence}, we have
    \begin{itemize}[noitemsep]
      \item $\red*{\Phi; \Gamma}{\App{\fix{f}{\alpha}{\tau}{e}}{s}}{\App{\fix{f}{\alpha}{\tau}{e'}}{s}}$ and
      \item $\red*{\Phi; \Gamma}{\App{\fix{f}{\alpha}{\tau}{e'}}{s}}{\App{\fix{f}{\alpha}{\tau'}{e'}}{s}}$.
    \end{itemize}
    Finally, by $\mu$-reduction, we have
    $\red*{\Phi; \Gamma}{\App{\fix{f}{\alpha}{\tau'}{e'}}{s}}{\subst{e'}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\tau'}{e'})}{\beta}}}}$.
    Then by \rref{red*-trans}, we have
    $\red*{\Phi; \Gamma}{\App{\fix{f}{\alpha}{\tau}{e}}{s}}{\subst{e'}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\tau'}{e'})}{\beta}}}}$.
    \qedhere
\end{itemize}
\end{proof}

Now we are ready to show that complete development satisfies the Z property.

\begin{lemma} \label{lem:Z-property}
If $\develop{\Phi; \Gamma}{e_i}{e'_1}$ for $i = 1, 2$
and $\red{\Phi; \Gamma}{e_1}{e_2}$
then $\red*{\Phi; \Gamma}{e_2}{e'_1}$
and $\red*{\Phi; \Gamma}{e'_1}{e'_2}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red{\Phi; \Gamma}{e_1}{e_2}$.
For the congruence cases of reduction,
it could start and end with terms that aren't redexes.
Consider bounded size quantification as an example.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \phantom{Never gonna give you up}
  \vspace{-2\baselineskip}
  \begin{mathpar}
  \inferrule{
    \red{\Phi, \bound{\alpha}{s}; \Gamma}{\tau_1}{\tau_2}
  }{
    \red{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\tau_1}}{\Funtype<{\alpha}{s}{\tau_2}}
  }
  \end{mathpar}
  By the induction hypotheses, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi, \bound{\alpha}{s}; \Gamma}{\tau_2}{\tau'_1}$ and
    \item $\red*{\Phi, \bound{\alpha}{s}; \Gamma}{\tau'_1}{\tau'_2}$,
  \end{itemize}
  where $\tau'_1$ and $\tau'_2$ are the corresponding complete developments.
  Then quite straightforwardly, by \cref{lem:congruence}, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\tau_2}}{\Funtype<{\alpha}{s}{\tau'_1}}$ and
    \item $\red*{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\tau'_1}}{\Funtype<{\alpha}{s}{\tau'_2}}$.
  \end{itemize}
\end{itemize}
A congruence case could also start with a term that isn't a redex,
but end with a reducible term.
In this case, consider a size application that steps to an applied bounded size abstraction.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \phantom{Never gonna let you down}
  \vspace{-2\baselineskip}
  \begin{mathpar}
  \inferrule{
    \red{\Phi; \Gamma}{e_1}{\Fun<{\alpha}{r}{e_2}}
  }{
    \red{\Phi; \Gamma}{\App{e_1}{s}}{\App{(\Fun<{\alpha}{r}{e_2})}{s}}
  }
  \end{mathpar}
  By the induction hypotheses, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{\Fun<{\alpha}{r}{e_2}}{e'_1}$ and
    \item $\red*{\Phi; \Gamma}{e'_1}{\Fun<{\alpha}{r}{e'_2}}$,
  \end{itemize}
  where $e'_1$ and $e'_2$ are the corresponding complete developments.
  Again, quite straightforwardly, by \cref{lem:congruence}, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{\App{(\Fun<{\alpha}{r}{e_2})}{s}}{\App{e'_1}{s}}$ and
    \item $\red*{\Phi; \Gamma}{\App{e'_1}{s}}{\App{(\Fun<{\alpha}{r}{e'_2})}{s}}$.
  \end{itemize}
  Since $\red{\Phi; \Gamma}{\App{(\Fun<{\alpha}{r}{e'_2})}{s}}{\subst{e'_2}{\alpha}{s}}$,
  using \rref{red*-once, red*-trans}, we have
  $\red*{\Phi; \Gamma}{\App{e'_1}{s}}{\subst{e'_2}{\alpha}{s}}$,
  where the right-hand side is the complete development of $\App{(\Fun<{\alpha}{r}{e_2})}{s}$.
\end{itemize}
Lastly, a congruence case could start and end with a redex,
as is the case for $\kw{let}$ expressions.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \phantom{Never gonna run around}
  \vspace{-2\baselineskip}
  \begin{mathpar}
  \inferrule{
    \red{\Phi; \Gamma, \define{x}{\tau}{e_1}}{e_2}{e_3}
  }{
    \red{\Phi; \Gamma}{\letin{x}{\tau}{e_1}{e_2}}{\letin{x}{\tau}{e_1}{e_3}}
  }
  \end{mathpar}
  By the induction hypotheses, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma, \define{x}{\tau}{e_1}}{e_3}{e'_2}$ and
    \item $\red*{\Phi; \Gamma, \define{x}{\tau}{e_1}}{e'_2}{e'_3}$,
  \end{itemize}
  where $e'_2$ and $e'_3$ are the corresponding complete developments.
  By \cref{lem:congruence}, we have
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{\letin{x}{\tau}{e_1}{e_3}}{\letin{x}{\tau}{e_1}{e'_2}}$ and
    \item $\red*{\Phi; \Gamma}{\subst{e'_2}{x}{e'_1}}{\subst{e'_3}{x}{e'_1}}$.
  \end{itemize}
  By \cref{lem:develop-red*}, we also have $\red*{\Phi; \Gamma}{e_1}{e'_1}$,
  where $e'_1$ is the corresponding complete development,
  so applying \cref{lem:congruence} again with $\zeta$-reduction and chaining it all up,
  we have $\red*{\Phi; \Gamma}{\letin{x}{\tau}{e_1}{e_3}}{\subst{e'_2}{x}{e'_1}}$.
\end{itemize}
The remaining cases for congruence of reduction not covered here are similar to the above,
falling into one of the three categories.
Meanwhile, the reduction rules involving redexes except $\delta$-reduction
all involve some form of substitution,
so I only cover $\delta$-reduction and $\beta$-reduction for functions,
the latter of which is representative of the remaining cases.
Note that for situations involving substitution of a size expression rather than a term,
\cref{lem:develop-compos-size} is used in place of \cref{lem:develop-compos}.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\red{\Phi; \Gamma}{x}{e}$ when $(\define{x}{\tau}{e}) \in \Gamma$. \\
  Letting $e'$ be the complete development of $e$,
  the goals are then
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{e}{e'}$ and
    \item $\red*{\Phi; \Gamma}{e'}{e'}$,
  \end{itemize}
  which hold by \cref{lem:develop-red*} and \rref{red*-refl} respectively.
  \item $\red{\Phi; \Gamma}{\app{(\fun{x}{\tau}{e_1})}{e_2}}{\subst{e_1}{x}{e_2}}$. \\
  Let $e'_1$ and $e'_2$ be the complete development of $e_1$ and $e_2$ respectively.
  By \cref{lem:develop-compos}, we have
  $\develop{\Phi; \Gamma}{\subst{e_1}{x}{e_2}}{\subst{e'_1}{x}{e'_2}}$.
  Then by \cref{lem:develop-red*} and by \rref{red*-refl}, we have our goals
  \begin{itemize}[noitemsep]
    \item $\red*{\Phi; \Gamma}{\subst{e_1}{x}{e_2}}{\subst{e'_1}{x}{e'_2}}$ and
    \item $\red*{\Phi; \Gamma}{\subst{e'_1}{x}{e'_2}}{\subst{e'_1}{x}{e'_2}}$. \qedhere
  \end{itemize}
\end{itemize}
\end{proof}

\begin{theorem}[Confluence] \label{thm:confluence}
If $\red*{\Phi; \Gamma}{e}{e_1}$ and $\red*{\Phi; \Gamma}{e}{e_2}$
then there is some term $e'$ such that
$\red*{\Phi; \Gamma}{e_1}{e'}$ and $\red*{\Phi; \Gamma}{e_2}{e'}$.
\end{theorem}

\begin{proof}
Since complete development satisfies the Z property by \cref{lem:Z-property},
confluence holds by \cref{lem:confluence}.
See \citet[Theorem 3.10]{confluence} for a complete proof.
\end{proof}

\subsection{Inversion on typing}

\emph{Inversion principles}\index{inversion} on typing
allow for deducing from a typing judgement the necessary premises for a typing derivation,
with one principle for each syntactic form.
In the presence of subtyping, these principles are a little more complex,
relating the type derived from the premises to the desired type by a subtyping judgement.
For concision, I prove all inversion principles for a general typing rule
rather than handling each rule explicitly.

Before we can prove these inversion principles,
we need transitivity of the subtyping judgement,
which in turn requires both confluence and transitivity of $\alpha$-cumulativity\index{$\alpha$-cumulativity},
as well a few inversion principles for the closure of reduction.

\begin{lemma}[Inversion on closure of reduction (\rref{pi})] \label{lem:inversion-red}
If $\red*{\Phi; \Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\tau}$,
then $\tau = \funtype{x}{\sigma_2}{\tau_2}$,
and we have $\red*{\Phi; \Gamma}{\sigma_1}{\sigma_2}$
and $\red*{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_1}{\tau_2}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red*{\Phi; \Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\tau}$.
\begin{itemize}[noitemsep, label=\textbf{Cases}, leftmargin=*, labelindent=\parindent]
  \item \rref*{red*-refl}. Trivial by \rref{red*-refl} on $\sigma_1$ and $\tau_1$.
  \item \rref*{red*-once}. By case analysis on $\red{\Phi; \Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\tau}$,
    the only possible rule is a congruence rule.
    Either $\red{\Phi; \Gamma}{\sigma_1}{\sigma_2}$ and $\tau_1 = \tau_2$,
    so that the goals hold by \rref{red*-once, red*-refl} respectively,
    or $\sigma_1 = \sigma_2$ and $\red{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_1}{\tau_2}$,
    so that the goals hold by \rref{red*-refl, red*-once} respectively.
  \item \rref*{red*-trans}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \red*{\Phi; \Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\tau'} \\
      \red*{\Phi; \Gamma}{\tau'}{\tau}
    }{
      \red*{\Phi; \Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\tau}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\tau' = \funtype{x}{\sigma_2}{\tau_2}$,
        $\red*{\Phi; \Gamma}{\sigma_1}{\sigma_2}$, and
        $\red*{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_1}{\tau_2}$; and
      \item $\tau = \funtype{x}{\sigma_3}{\tau_3}$,
        $\red*{\Phi; \Gamma}{\sigma_2}{\sigma_3}$, and
        $\red*{\Phi; \Gamma, \annot{x}{\sigma_2}}{\tau_2}{\tau_3}$.
    \end{itemize}
    By \rref{red*-refl, acum-refl, subtype-red}, we have $\subtype{\Phi; \Gamma}{\sigma_1}{\sigma_2}$.
    Then by \cref{lem:replacement-subtyping}, we have $\red*{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_2}{\tau_3}$.
    Finally, by \rref{red*-trans} twice, we have
    $\red*{\Phi; \Gamma}{\sigma_1}{\sigma_3}$ and
    $\red*{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_1}{\tau_3}$. \qedhere
\end{itemize}
\end{proof}

\begin{corollary}[Inversion on closure of reduction (\rref{forall, forall<})]
If $\red*{\Phi; \Gamma}{\Funtype{\alpha}{\sigma}}{\tau}$
or $\type{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\sigma}}{\tau}$,
then $\tau = \Funtype{\alpha}{\sigma'}$ or $\tau = \Funtype<{\alpha}{s}{\sigma'}$,
and $\red*{\Phi, \alpha; \Gamma}{\sigma}{\sigma'}$
or $\red*{\Phi, \bound{\alpha}{s}; \Gamma}{\sigma}{\sigma'}$
by the same argument as for \nameref{lem:inversion-red},
using instead the congruence reduction rules for
$\Funtype{\alpha}{\sigma}$ or $\Funtype<{\alpha}{s}{\sigma}$
in the case of \rref*{red*-once}.
\end{corollary}

\begin{lemma}[Transitivity of $\alpha$-cumulativity] \label{lem:transitivity-acum}
If $\acum{e_1}{e_2}$ and $\acum{e_2}{e_3}$ then $\acum{e_1}{e_3}$.
\end{lemma}

\begin{proof}
By nested induction on the derivations of $\acum{e_1}{e_2}$ and $\acum{e_2}{e_3}$.
\begin{enumerate}[noitemsep, label=\textbf{Cases}, leftmargin=*, labelindent=\parindent]
  \item \rref*{acum-refl} and $\mathcal{R}$, $\mathcal{R}$ and \rref*{acum-refl}.
    Trivial by the $\mathcal{R}$ derivation.
  \item \rref*{acum-prop} and \rref*{acum-type}, \rref*{acum-type} and \rref*{acum-type}.
    Trivial by \rref*{acum-prop} or \rref*{acum-type} respectively.
  \item \rref*{acum-pi} and \rref*{acum-pi}, \rref*{acum-forall} and \rref*{acum-forall}, \rref*{acum-forall<} and \rref*{acum-forall<}.
    By \rref*{acum-pi}, \rref*{acum-forall}, or \rref*{acum-forall<}, respectively,
    using the induction hypothesis as premise. \qedhere
\end{enumerate}
\end{proof}

\begin{lemma}[Confluence up to $\alpha$-cumulativity] \label{lem:confluence-acum}
Suppose we have the following:
\begin{itemize}[noitemsep]
  \item $\acum{e_1}{e_2}$,
  \item $\red*{\Phi; \Gamma}{e_1}{e'_1}$, and
  \item $\red*{\Phi; \Gamma}{e_2}{e'_2}$.
\end{itemize}
Then there are terms $e''_1, e''_2$ such that
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma}{e'_1}{e''_1}$,
  \item $\red*{\Phi; \Gamma}{e'_2}{e''_2}$, and
  \item $\acum{e''_1}{e''_2}$.
\end{itemize}
\end{lemma}

\begin{proof}
By induction on the derivation of $\acum{e_1}{e_2}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{acum-refl}. By \nameref{thm:confluence} and \rref*{acum-refl}.
  \item[\textbf{Cases}] \rref*{acum-prop}, \rref*{acum-type}.
    Since $\Prop$ and $\Type{}$ don't reduce any further,
    this is trivial by \rref{acum-prop} or \rref{acum-type} respectively with \rref{red*-refl}.
  \item \rref*{acum-pi}.
    \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \acum{\tau_1}{\tau_2}
      }{
        \acum{\funtype{x}{\sigma}{\tau_1}}{\funtype{x}{\sigma}{\tau_2}}
      }
    \end{mathpar}
    By inversion on the closures of reduction, we have
    \begin{itemize}[noitemsep]
      \item $\red*{\Phi; \Gamma}{\sigma}{\sigma_1}$,
      \item $\red*{\Phi; \Gamma, \annot{x}{\sigma_1}}{\tau_1}{\tau'_1}$,
      \item $\red*{\Phi; \Gamma}{\sigma}{\sigma_2}$, and
      \item $\red*{\Phi; \Gamma, \annot{x}{\sigma_2}}{\tau_2}{\tau'_2}$.
    \end{itemize}
    By \nameref{thm:confluence}, we have $\red*{\Phi; \Gamma}{\sigma}{\sigma'}$
    for some $\sigma'$.
    By \rref{red*-refl, acum-refl, subtype-red},
    we have $\subtype{\Phi; \Gamma}{\sigma'}{\sigma_i}$ for $i = 1, 2$.
    Then by \nameref{lem:replacement-subtyping},
    we have $\red*{\Phi; \Gamma, \annot{x}{\sigma'}}{\tau_i}{\tau'_i}$
    for $i = 1, 2$,
    and we can apply the induction hypothesis to get
    \begin{itemize}[noitemsep]
      \item $\red*{\Phi; \Gamma, \annot{x}{\sigma'}}{\tau'_1}{\tau''_1}$,
      \item $\red*{\Phi; \Gamma, \annot{x}{\sigma'}}{\tau'_2}{\tau''_2}$, and
      \item $\acum{\tau''_1}{\tau''_2}$.
    \end{itemize}
    Finally, by \nameref{lem:congruence}, we have
    \begin{itemize}[noitemsep]
      \item $\red*{\Phi; \Gamma}{\funtype{x}{\sigma}{\tau'_1}}{\funtype{x}{\sigma'}{\tau''_1}}$,
      \item $\red*{\Phi; \Gamma}{\funtype{x}{\sigma}{\tau'_2}}{\funtype{x}{\sigma'}{\tau''_2}}$, and
      \item $\acum{\funtype{x}{\sigma'}{\tau''_1}}{\funtype{x}{\sigma'}{\tau''_2}}$.
    \end{itemize}
  \item[\textbf{Cases}] \rref*{acum-forall}, \rref*{acum-forall<}.
    Similar to the case for \rref*{acum-pi}. \qedhere
\end{itemize}
\end{proof}

\begin{lemma}[Right confluence up to $\alpha$-cumulativity] \label{lem:confluence-acum-right}
If $\acum{e_1}{e_2}$ and $\red*{\Phi; \Gamma}{e_1}{e'_1}$ then there is some term $e'_2$ such that
$\red*{\Phi; \Gamma}{e_2}{e'_2}$ and $\acum{e'_1}{e'_2}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\acum{e_1}{e_2}$.
\begin{enumerate}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{acum-refl}. Trivial by \rref*{acum-refl} with the same reduction judgement.
  \item[\textbf{Cases}] \rref*{acum-prop}, \rref*{acum-type}.
    Since $\Prop$ and $\Type{}$ don't reduce any further,
    trivial by \rref*{acum-prop} or \rref*{acum-type} respectively with \cref{red*-refl}.
  \item \rref*{acum-pi}. \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \acum{\tau_1}{\tau_2}
      }{
        \acum{\funtype{x}{\sigma}{\tau_1}}{\funtype{x}{\sigma}{\tau_2}}
      }
    \end{mathpar}
    By inversion on the closure of reduction, we have
    $\red*{\Phi; \Gamma}{\funtype{x}{\sigma}{\tau_1}}{\funtype{x}{\sigma'}{\tau'_1}}$.
    where $\red*{\Phi; \Gamma}{\sigma}{\sigma'}$ and $\red*{\Phi; \Gamma, \annot{x}{\sigma'}}{\tau_1}{\tau'_1}$.
    By the induction hypothesis, we can conclude that there is some term $\tau'_2$ such that
    $\red*{\Phi; \Gamma, \annot{x}{\sigma'}}{\tau_2}{\tau'_2}$ and $\acum{\tau'_1}{\tau'_2}$.
    Then by \nameref{lem:congruence} we conclude that $\red*{\Phi; \Gamma}{\funtype{x}{\sigma}{\tau_2}}{\funtype{x}{\sigma'}{\tau'_2}}$,
    and by \rref{acum-pi} that $\acum{\funtype{x}{\sigma'}{\tau'_1}}{\funtype{x}{\sigma'}{\tau'_2}}$.
  \item \rref*{acum-forall}, \rref*{acum-forall<}. Similar to the case for \rref*{acum-pi}. \qedhere
\end{enumerate}
\end{proof}

\begin{corollary}[Left confluence up to $\alpha$-cumulativity] \label{lem:confluence-acum-left}
If $\acum{e_1}{e_2}$ and $\red*{\Phi; \Gamma}{e_2}{e'_2}$ then there is some $e'_1$ such that
$\red*{\Phi; \Gamma}{e_1}{e'_1}$ and $\acum{e'_1}{e'_2}$,
using the symmetric argument to \cref{lem:confluence-acum-right}.
\end{corollary}

\begin{theorem}[Transitivity of subtyping] \label{thm:transitivity-subtyping}\index{subtyping}
If $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$ and $\subtype{\Phi; \Gamma}{\tau_2}{\tau_3}$
then $\subtype{\Phi; \Gamma}{\tau_1}{\tau_3}$.
\end{theorem}

\begin{proof}
By cases on the derivations of $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$
and $\subtype{\Phi; \Gamma}{\tau_2}{\tau_3}$.
\begin{mathpar}
\inferrule{
  \acum{\sigma_1}{\sigma_{21}} \\\\
  \red*{\Phi; \Gamma}{\tau_1}{\sigma_1} \\
  \red*{\Phi; \Gamma}{\tau_2}{\sigma_{21}}
}{
  \subtype{\Phi; \Gamma}{\tau_1}{\tau_2}
}
\and
\inferrule{
  \acum{\sigma_{22}}{\sigma_3} \\\\
  \red*{\Phi; \Gamma}{\tau_2}{\sigma_{22}} \\
  \red*{\Phi; \Gamma}{\tau_3}{\sigma_3}
}{
  \subtype{\Phi; \Gamma}{\tau_2}{\tau_3}
}
\end{mathpar}
By \nameref{thm:confluence}, there is some term $\tau'_2$ such that
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma}{\sigma_{21}}{\tau'_2}$ and
  \item $\red*{\Phi; \Gamma}{\sigma_{22}}{\tau'_2}$.
\end{itemize}
By \nameref{lem:confluence-acum-left} and \nameref{lem:confluence-acum-right},
there are terms $\tau'_1$ and $\tau'_3$ such that
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma}{\sigma_1}{\tau'_1}$,
  \item $\acum{\tau'_1}{\tau'_2}$; and
  \item $\red*{\Phi; \Gamma}{\sigma_3}{\tau'_3}$,
  \item $\acum{\tau'_2}{\tau'_3}$.
\end{itemize}
By \rref{red*-trans} and \nameref{lem:transitivity-acum}, we have
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma}{\tau_1}{\tau'_1}$,
  \item $\red*{\Phi; \Gamma}{\tau_3}{\tau'_3}$, and
  \item $\acum{\tau'_1}{\tau'_3}$.
\end{itemize}
Then finally by \rref{subtype-red}, we have $\subtype{\Phi; \Gamma}{\tau_1}{\tau_3}$.
\end{proof}

\begin{figure}[h]
\centering
\begin{tikzcd}
\tau_1
  \arrow[rr, dotted, no head, "\displaystyle\preccurlyeq" description]
  % \arrow[dd, dashrightarrow, bend right]
  \arrow[d, dashrightarrow]
&&\tau_2
  \arrow[rr, dotted, no head, "\displaystyle\preccurlyeq" description]
  \arrow[dl, dashrightarrow]
  \arrow[dr, dashrightarrow]
&&\tau_3
  % \arrow[dd, dashrightarrow, bend left]
  \arrow[d, dashrightarrow] \\
\sigma_1
  \arrow[r, dotted, no head, "\sqsubseteq" description]
  \arrow[d, dashrightarrow]
&\sigma_{21}
  \arrow[dr, dashrightarrow]
&&\sigma_{22}
  \arrow[r, dotted, no head, "\sqsubseteq" description]
  \arrow[dl, dashrightarrow]
&\sigma_3
  \arrow[d, dashrightarrow] \\
\tau'_1
  \arrow[rr, dotted, no head, "\sqsubseteq" description]
  % \arrow[rrrr, dotted, no head, bend right, "\sqsubseteq" description]
&&\tau'_2
  \arrow[rr, dotted, no head, "\sqsubseteq" description]
&&\tau'_3
\end{tikzcd}
\caption{Diagram of proof of \nameref{thm:transitivity-subtyping}.}
\label{fig:transitivity-subtyping}
\end{figure}

A diagram representing the proof is shown in \cref{fig:transitivity-subtyping},
where again the dashed arrows represent closure of reduction $\rhd^*$.

\begin{theorem}[Inversion on typing] \label{thm:inversion}
Given a syntactic form $e$ and a typing rule $\mathcal{R} \neq \text{\upshape \rref*{conv*}}$ for that form,
if $\mathcal{D}$ is a derivation ending in $\type{\Gamma}{e}{\tau}$
and $\mathcal{J}_i$ are the judgement forms in the premises of $\mathcal{R}$,
then there exist derivations $\mathcal{D}_i$ ending in $\mathcal{J}_i$
such that $\mathcal{R}$ builds a derivation ending in $\type{\Gamma}{e}{\sigma}$,
and $\subtype{\Gamma}{\sigma}{\tau}$ holds.
\end{theorem}

\begin{proof}
By induction on the derivation of $\type{\Gamma}{e}{\tau}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\mathcal{R}$. The premises of the derivation are the desired ones,
    building a derivation ending in $\type{\Gamma}{e}{\tau}$,
    and $\subtype{\Gamma}{\tau}{\tau}$ holds by
    \rref{subtype-conv, acum-refl, red*-refl}.
  \item \rref*{conv*}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \type{\Gamma}{d}{\sigma} \\
      \type{\Gamma}{\sigma}{U} \\
      \type{\Gamma}{\tau}{U} \\
      \subtype{\Gamma}{\sigma}{\tau}
    }{
      \type{\Gamma}{e}{\tau}
    }
    \end{mathpar}
    Induction hypothesis: there are derivations $\mathcal{D}_i$ ending in $\mathcal{J}_i$
    such that $\mathcal{R}$ builds a derivation ending in $\type{\Gamma}{e}{\sigma'}$
    and $\subtype{\Gamma}{\sigma'}{\sigma}$ holds. \\
    The desired derivations are $\mathcal{D}_i$, and $\subtype{\Gamma}{\sigma'}{\tau}$
    holds by \nameref{thm:transitivity-subtyping}. \qedhere
\end{itemize}
\end{proof}

With inversion on typing judgements,
we can conclude that the natural premises hold up to subtyping
without having to do case analysis on typing derivations and handle \rref{conv} every single time.
For example, given $\type{\Phi; \Gamma}{\fun{x}{\sigma}{e}}{\tau}$,
we can conclude the following setting $\mathcal{R} = \rref*{lam}$:
\begin{itemize}[noitemsep]
  \item $\type{\Phi; \Gamma}{\sigma}{U}$,
  \item $\type{\Phi; \Gamma, \annot{x}{\sigma}}{e}{\sigma'}$, and
  \item $\subtype{\Phi; \Gamma}{\funtype{x}{\sigma}{\sigma'}}{\tau}$.
\end{itemize}
Uses of inversion on typing will henceforth be referred to simply as inversion,
without backreferences to the theorem statement.

\subsection{Replacement by reduction}

Similar to \nameref{lem:replacement-subtyping}\index{replacement},
where a type annotation in the environment can be replaced by a subtype,
a definition in the environment can also be replaced by a reduct.
In contrast, the proof is more involved and requires \nameref{thm:confluence}.

\begin{lemma} \label{lem:replacement-reduction-1}
If $\red{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e_2}{e'_2}$
and $\red*{\Phi; \Gamma_1}{e_1}{e'_1}$,
then there is some term $e''_2$
such that $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{e_2}{e''_2}$
and $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{e'_2}{e''_2}$.
\end{lemma}

\begin{proof}
By induction on the derivation of
$\red{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e_2}{e'_2}$.
In the case of $\delta$-reduction where
$\red{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{x}{e_1}$,
we have
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{x}{e'_1}$ by $\delta$-reduction and \rref{red*-once}, and
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{e_1}{e'_1}$ by the second hypothesis.
\end{itemize}
For the case of \rref*{red-cong},
the goal holds by the induction hypotheses and \nameref{lem:congruence}.
All other cases are trivial, always reducing to the existing reduct.
\end{proof}

\begin{lemma} \label{lem:replacement-reduction-2}
If $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e_2}{e'_2}$
and $\red*{\Phi; \Gamma_1}{e_1}{e'_1}$,
then there is some term $e''_2$
such that $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{e_2}{e''_2}$
and $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e'_1}, \Gamma_2}{e'_2}{e''_2}$.
\end{lemma}

\begin{proof}
By induction on the derivation of
$\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e_2}{e'_2}$.
The \rref*{red*-once} case holds by \cref{lem:replacement-reduction-1} and
the \rref*{red*-refl} case by \rref{red*-refl}.
The \rref*{red*-trans} case holds using \nameref{thm:confluence}
on the two reducts from the middle term in the transitivity.
\end{proof}

\begin{lemma} \label{lem:replacement-reduction-3}
If $\subtype{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{\tau_1}{\tau_2}$
and $\red*{\Gamma_1}{e_1}{e_2}$
then $\subtype{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau_1}{\tau_2}$.
\end{lemma}

\begin{proof}
By cases on the derivation of
$\subtype{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{\tau_1}{\tau_2}$,
there being only one case.
\begin{mathpar}
\inferrule{
  \red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{\tau_1}{\tau'_1} \\
  \red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{\tau_2}{\tau'_2} \\
  \acum{\tau'_1}{\tau'_2}
}{
  \subtype{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{\tau_1}{\tau_2}
}
\end{mathpar}
By \cref{lem:replacement-reduction-2}, there are two terms $\tau''_1, \tau''_2$ such that
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau_i}{\tau''_i}$ and
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau'_i}{\tau''_i}$
\end{itemize}
for $i = 1, 2$.
By \nameref{lem:confluence-acum} on the latter, there are two terms $\tau'''_1, \tau'''_2$ such that
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau''_1}{\tau'''_1}$,
  \item $\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau''_2}{\tau'''_2}$, and
  \item $\acum{\tau'''_1}{\tau'''_2}$.
\end{itemize}
Finally, by \rref{red*-trans}, we have
$\red*{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau_i}{\tau'''_i}$
for $i = 1, 2$,
and by \rref{subtype-red} we have
$\subtype{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{\tau_1}{\tau_2}$.
\end{proof}

A diagram representing the proof is shown in \cref{fig:replacement-reduction-3},
where again the dashed arrows represent closure of reduction $\rhd^*$.

\begin{lemma}[Replacement by reduction] \label{lem:replacement-reduction}
If $\type{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e}{\tau}$
and $\red*{\Gamma_1}{e_1}{e_2}$
then $\type{\Phi; \Gamma_1, \define{x}{\sigma}{e_2}, \Gamma_2}{e}{\tau}$.
\end{lemma}

\begin{proof}
By induction on the derivation of
$\type{\Phi; \Gamma_1, \define{x}{\sigma}{e_1}, \Gamma_2}{e}{\tau}$,
using \cref{lem:replacement-reduction-3}
for the case of \rref*{conv}.
\end{proof}

\begin{figure}[h]
\centering
\begin{tikzcd}
&\tau_1
  \arrow[dl, dashrightarrow]
  \arrow[d, dashrightarrow]
  \arrow[r, dotted, no head, "\displaystyle\preccurlyeq" description]
&\tau_2
  \arrow[dr, dashrightarrow]
  \arrow[d, dashrightarrow] \\
\tau''_1
  \arrow[dr, dashrightarrow]
&\tau'_1
  \arrow[l, dashrightarrow]
  \arrow[r, dotted, no head, "\sqsubseteq" description]
&\tau'_2
  \arrow[r, dashrightarrow]
&\tau''_2
  \arrow[dl, dashrightarrow] \\
&\tau'''_1
  \arrow[r, dotted, no head, "\sqsubseteq" description]
&\tau'''_2
\end{tikzcd}
\caption{Diagram of proof of \cref{lem:replacement-reduction-3}.}
\label{fig:replacement-reduction-3}
\end{figure}

\subsection{Regularity}

\emph{Regularity}\index{regularity}
states that the types of typing judgements are themselves well-typed.
Proving this requires the substitutivity lemmas as well as a few inversion principles.

\begin{lemma} \label{lem:wf-subsize}
If $\subsize{\Phi}{r}{s}$ then $\wf{\Phi}{r}$ and $\wf{\Phi}{s}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\subsize{\Phi}{r}{s}$.
\end{proof}

\begin{lemma} \label{lem:typed-env}
If $\wf{\Phi}{\Gamma}$ and $(\annot{x}{\tau}) \in \Gamma$
then $\type{\Phi; \Gamma}{\tau}{U}$ for some $U$.
\end{lemma}
\begin{proof}
By induction on the derivation of $\wf{\Phi}{\Gamma}$.
For \rref{cons-ass}, if the variable is $x$, the typing premise is the desired typing judgement.
\end{proof}

\begin{lemma} \label{lem:wf-env}
If $\type{\Phi; \Gamma}{e}{\tau}$ then $\wf{\Phi}{\Gamma}$.
\end{lemma}
\begin{proof}
By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$.
\end{proof}

\begin{lemma} \label{lem:wf-env-size}
If $\wf{\Phi}{\Gamma}$ then $\wf{}{\Phi}$.
\end{lemma}
\begin{proof}
By induction on the derivation of $\wf{\Phi}{\Gamma}$.
\end{proof}

\begin{theorem}[Regularity] \label{thm:regularity}
If $\type{\Phi; \Gamma}{e}{\tau}$ then $\type{\Phi; \Gamma}{\tau}{U}$.
\end{theorem}

\begin{proof}
By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{conv}. Trivial.
  \item \rref*{var}. By \cref{lem:typed-env}.
  \item[\textbf{Cases}] \rref*{univ}, \rref*{pi}, \rref*{forall}, \rref*{forall<}, \rref*{nat}, \rref*{wft}.
    By \rref{univ}, using \cref{lem:wf-env} when needed.
  \item[\textbf{Cases}] \rref*{lam}, \rref*{slam}, \rref*{slam<}.
    By \rref{pi, forall, forall<} respectively,
    using the induction hypothesis as premise.
  \item[\textbf{Cases}] \rref*{zero}, \rref*{succ}, \rref*{sup}.
    By \rref{nat, nat, wft} respectively,
    using \cref{lem:wf-subsize} to get a size judgement from the subsizing premise.
  \item \rref*{app}.
    \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \infer{\Phi; \Gamma}{e_1}{\funtype{x}{\sigma}{\tau}} \\
        \check{\Phi; \Gamma}{e_2}{\sigma}
      }{
        \infer{\Phi; \Gamma}{\app{e_1}{e_2}}{\subst{\tau}{x}{e_1}}
      }
    \end{mathpar}
    By the induction hypothesis, $\funtype{x}{\sigma}{\tau}$ is well typed with some universe $U$.
    By \nameref{thm:inversion} on \rref{pi},
    we have that $\type{\Phi; \Gamma, \annot{x}{\sigma}}{\tau}{U'}$ for some $U'$.
    By \nameref{lem:substitutivity-terms}, we conclude that $\type{\Phi; \Gamma}{\subst{\tau}{x}{e_1}}{U'}$.
  \item[\textbf{Cases}] \rref*{case-nat}, \rref*{case-wft}.
    \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \type{\Phi; \Gamma}{e}{\N{s}} \\
        \type{\Phi; \Gamma, \annot{x}{\N{s}}}{P}{U} \\
        \dots
      }{
        \infer{\Phi; \Gamma}{\match{e}{\fun*{x}{P}}{\any \any}}{\subst{P}{x}{e}}
      }
      \and
      \inferrule{
        \type{\Phi; \Gamma}{e}{\W{x}{\sigma}{\tau}{s}} \\
        \type{\Phi; \Gamma, \annot{x}{\W{x}{\sigma}{\tau}{s}}}{P}{U} \\
        \dots
      }{
        \infer{\Phi; \Gamma}{\match{e}{\fun*{x}{P}}{\any}}{\subst{P}{x}{e}}
      }
    \end{mathpar}
    By \nameref{lem:substitutivity-terms} of $e$ in $P$.
  \item[\textbf{Cases}] \rref*{sapp}, \rref*{sapp<}.
    By the same argument as for case \rref*{app},
    using instead inversion on \rref{forall, forall<} respectively,
    followed by \nameref{lem:substitutivity-unbounded} and \nameref{lem:substitutivity-bounded} respectively.
  \item \rref*{fix}. By \rref{forall} on the first premise. \qedhere
\end{itemize}
\end{proof}

\subsection{Subject reduction}

The final metatheoretical property required is \emph{subject reduction}\index{subject reduction},
which states that what a well-typed term reduces to is also well-typed with the same type.
The proof requires using the replacement lemmas.

\begin{lemma} \label{lem:wf-defs}
If $\wf{\Phi}{\Gamma}$ and $(\define{x}{\tau}{e}) \in \Gamma$ then $\type{\Gamma}{e}{\tau}$.
\end{lemma}
\begin{proof}
By induction on the derivation of $\wf{\Phi}{\Gamma}$,
using the typing premise of \rref{cons-def} when the variable is $x$.
\end{proof}

\begin{lemma}[Subject reduction] \label{lem:sr}
If $\type{\Phi; \Gamma}{e}{\tau}$ and $\red{\Phi; \Gamma}{e}{e'}$ then $\type{\Phi; \Gamma}{e'}{\tau}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red{\Phi; \Gamma}{e}{e'}$ and \nameref{thm:inversion} of the right-hand term.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \textbf{for $\delta$-reduction}. Follows by \cref{lem:wf-env,lem:wf-defs}.
  \item \textbf{for $\beta$-reduction} (application of bounded sizes).
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{~}{
      \red{\Phi; \Gamma}{\App{(\Fun<{\alpha}{r}{e})}{s}}{\subst{e}{\alpha}{s}}
    }
    \end{mathpar}
    By inversion on \rref{sapp<}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\Fun<{\alpha}{r}{e}}{\Funtype<{\alpha}{r}{\sigma}}$,
      \item $\subsize{\Phi}{\sss{s}}{r}$, and
      \item $\subtype{\Phi; \Gamma}{\subst{\sigma}{\alpha}{s}}{\tau}$.
    \end{itemize}
    By inversion again on \rref{slam}, we have
    \begin{itemize}[noitemsep]
      \item $\wf{\Phi}{s}$,
      \item $\type{\Phi, \bound{\alpha}{s}; \Gamma}{e}{\sigma'}$, and
      \item $\subtype{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\sigma'}}{\Funtype<{\alpha}{s}{\sigma}}$.
    \end{itemize}
    By inversion on subtyping, $\alpha$-cumulativity, and closure of reduction,
    we also have $\subtype{\Phi, \bound{\alpha}{s}; \Gamma}{\sigma'}{\sigma}$.
    % TODO: please don't make me explicitly list the inversion principles
    By \nameref{lem:substitutivity-bounded}, we have
    \begin{itemize}[noitemsep]
      \item $\subtype{\Phi; \Gamma}{\subst{\sigma'}{\alpha}{s}}{\subst{\sigma}{\alpha}{s}}$ and
      \item $\type{\Phi; \Gamma}{\subst{e}{\alpha}{s}}{\subst{\sigma'}{\alpha}{s}}$.
    \end{itemize}
    By \nameref{thm:transitivity-subtyping} and \nameref{thm:regularity}, we have
    \begin{itemize}[noitemsep]
      \item $\subtype{\Phi; \Gamma}{\subst{\sigma'}{\alpha}{s}}{\tau}$,
      \item $\type{\Phi; \Gamma}{\subst{\sigma'}{\alpha}{s}}{U_1}$, and
      \item $\type{\Phi; \Gamma}{\tau}{U_2}$.
    \end{itemize}
    By \rref{conv}, both $\subst{\sigma'}{\alpha}{s}$ and $\tau$ have type $\rules{U_1}{U_2}$.
    Finally, by \rref{conv} again, we have $\type{\Phi; \Gamma}{\subst{e}{\alpha}{s}}{\tau}$.
  \item \rref*{red-cong}.
    All of the cases for the congruence rules are similar to one another.
    I cover only the case for reduction of the bound expression in a $\kw{let}$ expression,
    which requires careful handling of definitions in the environment.
    \begin{mathpar}
    \inferrule{
      \red{\Phi; \Gamma}{e_1}{e'_1}
    }{
      \red{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\letin{x}{\sigma}{e'_1}{e_2}}
    }
    \end{mathpar}
    By inversion on \rref{let}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\sigma}{U}$,
      \item $\type{\Phi; \Gamma}{e_1}{\sigma}$, and
      \item $\type{\Phi; \Gamma, \define{x}{\sigma}{e_1}}{e_2}{\tau'}$, and
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e_1}}{\tau}$.
    \end{itemize}
    By the induction hypothesis, we have $\type{\Phi; \Gamma}{e'_1}{\sigma}$.
    By \nameref{lem:replacement-reduction},
    we have $\type{\Phi; \Gamma, \define{x}{\sigma}{e'_1}}{e_2}{\tau'}$.
    By \rref{let}, we have $\type{\Phi; \Gamma}{\letin{x}{\sigma}{e'_1}{e_2}}{\subst{\tau'}{x}{e'_1}}$.
    By \nameref{lem:congruence},
    we have $\red*{\Phi; \Gamma}{\subst{\tau'}{x}{e_1}}{\subst{\tau'}{x}{e'_1}}$.
    Then by \rref{red*-refl, acum-refl, subtype-red}, \nameref{thm:transitivity-subtyping},
    we have $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e'_1}}{\tau}$.
    Finally, by \rref{conv}, we have $\type{\Phi; \Gamma}{\letin{x}{\sigma}{e'_1}{e_2}}{\tau}$.
  \item[\textbf{Cases}] \textbf{remaining}.
    All similar to the case for $\beta$-reduction for application of bounded sizes. \qedhere
\end{itemize}
\end{proof}

\begin{theorem}[Subject reduction] \label{thm:subject-reduction}
If $\type{\Phi; \Gamma}{e}{\tau}$ and $\red*{\Phi; \Gamma}{e}{e'}$ then $\type{\Phi; \Gamma}{e'}{\tau}$.
\end{theorem}

\begin{proof}
By induction on the derivation of $\red*{\Phi; \Gamma}{e}{e'}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{red*-once}. By \cref{lem:sr}.
  \item \rref*{red*-refl}. Trivial.
  \item \rref*{red*-trans}. By the induction hypothesis on the first premise we have
    $\type{\Phi; \Gamma}{e_2}{\tau}$;
    by the induction hypothesis again on the second premise we have
    $\type{\Phi; \Gamma}{e_3}{\tau}$. \qedhere
  \iffalse
  \item \rref*{red*-cong}. The various congruence cases are all similar to one another;
    I cover only the case of \rref*{let} as example.
    \begin{mathpar}
      \inferrule{
        \red*{\Phi; \Gamma}{\sigma}{\sigma'} \\
        \red*{\Phi; \Gamma}{e_1}{e'_1} \\
        \red*{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{e_2}{e'_2}
      }{
        \red*{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\letin{x}{\sigma'}{e'_1}{e'_2}}
      }
    \end{mathpar}
    By \nameref{thm:inversion} on \rref{let}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\sigma}{U}$,
      \item $\type{\Phi; \Gamma}{e_1}{\sigma}$,
      \item $\type{\Phi; \Gamma, \define{x}{\sigma}{e_1}}{e_2}{\tau'}$, and
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e_1}}{\tau}$.
    \end{itemize}
    By \rref{red*-refl, red*-cong, acum-refl, subtype-red} and
    \nameref{thm:transitivity-subtyping}, we have
    \begin{itemize}[noitemsep]
      \item $\subtype{\Phi; \Gamma}{\sigma'}{\sigma}$,
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e'_1}}{\subst{\tau'}{x}{e_1}}$, and
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e'_1}}{\tau}$.
    \end{itemize}
    Then by \nameref{lem:replacement-subtyping} and by \nameref{lem:replacement-reduction},
    we have $\type{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{e_2}{\tau'}$.
    The induction hypotheses then give
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\sigma'}{U}$,
      \item $\type{\Phi; \Gamma}{e'_1}{\sigma}$, and
      \item $\type{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{e'_2}{\tau'}$.
    \end{itemize}
    By \nameref{thm:regularity} and \nameref{lem:substitutivity-terms}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\tau}{U_1}$,
      \item $\type{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{\tau'}{U_2}$, and
      \item $\type{\Phi; \Gamma}{\subst{\tau'}{x}{e'_1}}{U_2}$.
    \end{itemize}
    By \rref{conv}, both $\tau$ and $\subst{\tau'}{x}{e'_1}$ have type $\rules{U_1}{U_2}$.
    Finally, by \rref{let} and by \rref{conv} again,
    we have $\type{\Phi; \Gamma}{\letin{x}{\sigma'}{e'_1}{e'_2}}{\tau}$.
  \fi
\end{itemize}
\end{proof}

\section{Metatheory of \CICE}

Fewer metatheoretical properties of \CICE are required for the type preservation proof,
namely replacement\index{replacement},
substitutivity\index{substitutivity},
the inversion principles\index{inversion},
and subject equivalence\index{subject reduction}.
I don't provide the proofs here, as the properties of CIC,
typed equivalence, and equality reflection are well established,
and they're similar to the proofs for the analogous lemmas for \lang.

\begin{lemma}[Replacement by subtyping] \label{lem:replacement-subtyping*}
Suppose $\subtype{\GammaT_1}{\sigmaT_1}{\sigmaT_2}$ where $\type{\GammaT_1}{\sigmaT_1}{U}$ and $\type{\GammaT_1}{\sigmaT_2}{U}$
for some $U$.
\begin{itemize}[noitemsep]
  \item If $\type{\GammaT_1, \annotT{\xT}{\sigmaT_2}, \GammaT_2}{\eT}{\tauT}$ then $\type{\GammaT_1, \annotT{\xT}{\sigmaT_1}, \GammaT_2}{\eT}{\tauT}$.
  \item If $\subtype{\GammaT_1, \annotT{\xT}{\sigmaT_2}, \GammaT_2}{\tauT_1}{\tauT_2}$ then $\subtype{\GammaT_1, \annotT{\xT}{\sigmaT_1}, \GammaT_2}{\tauT_1}{\tauT_2}$.
  \item If $\defeq{\GammaT_1, \annotT{\xT}{\sigmaT_2}, \GammaT_2}{\eT_1}{\eT_2}{\tauT}$ then $\defeq{\GammaT_1, \annotT{\xT}{\sigmaT_1}, \GammaT_2}{\eT_1}{\eT_2}{\tauT}$.
\end{itemize}
Furthermore, the above also applies when the environment contains $\defineT{\xT}{\sigmaT_2}{\eT}$
rather than $\annotT{\xT}{\sigmaT_2}$.
\end{lemma}

\begin{lemma}[Replacement by equivalence] \label{lem:replacement-equivalence}
Suppose $\defeq{\GammaT_1}{\eT_1}{\eT_2}{\tauT'}$.
\begin{itemize}[noitemsep]
  \item If $\type{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_1}, \GammaT_2}{\eT}{\tauT}$ then $\type{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_2}, \GammaT_2}{\eT}{\tauT}$.
  \item If $\subtype{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_1}, \GammaT_2}{\tauT_1}{\tauT_2}$ then $\subtype{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_2}, \GammaT_2}{\tauT_1}{\tauT_2}$.
  \item If $\defeq{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_1}, \GammaT_2}{\eT_3}{\eT_4}{\tauT}$ then $\defeq{\GammaT_1, \defineT{\xT}{\sigmaT}{\eT_2}, \GammaT_2}{\eT_3}{\eT_4}{\tauT}$.
\end{itemize}
\end{lemma}

\begin{lemma}[Substitutivity]
Suppose $\type{\GammaT_1}{\eT}{\sigmaT}$.
\begin{itemize}[noitemsep]
  \item If $\type{\GammaT_1, \annotT{\xT}{\sigmaT}, \GammaT_2}{\eT'}{\tauT}$ then $\type{\GammaT_1, \subst{\GammaT_2}{\xT}{\eT}}{\subst{\eT'}{\xT}{\eT}}{\subst{\xT}{\tauT}{\eT}}$.
  \item If $\subtype{\GammaT_1, \annotT{\xT}{\sigmaT}, \GammaT_2}{\tauT_1}{\tauT_2}$ then $\type{\GammaT_1, \subst{\GammaT_2}{\xT}{\eT}}{\subst{\tauT_1}{\xT}{\eT}}{\subst{\tauT_2}{\tauT}{\eT}}$.
  \item If $\defeq{\GammaT_1, \annotT{\xT}{\sigmaT}, \GammaT_2}{\eT_1}{\eT_2}{\tauT}$ then $\defeq{\GammaT_1, \subst{\GammaT_2}{\xT}{\eT}}{\subst{\eT_1}{\xT}{\eT}}{\subst{\eT_2}{\tauT}{\eT}}{\subst{\tauT}{\xT}{\eT}}$.
\end{itemize}
Furthermore, the above also applies when the environment contains $\defineT{\xT}{\sigmaT}{\eT}$
rather than $\annotT{\xT}{\sigmaT}$.
\end{lemma}

\begin{theorem}[Inversion]
Given a syntactic form $\eT$ and a typing rule $\mathcal{R} \neq \text{\upshape \rref*{conv*}}$ for that form,
if $\mathcal{D}$ is a derivation ending in $\type{\GammaT}{\eT}{\tauT}$
and $\mathcal{J}_i$ are the judgement forms in the premises of $\mathcal{R}$,
then there exist derivations $\mathcal{D}_i$ ending in $\mathcal{J}_i$
such that $\mathcal{R}$ builds a derivation ending in $\type{\GammaT}{\eT}{\sigmaT}$,
and $\subtype{\GammaT}{\sigmaT}{\tauT}$ holds.
\end{theorem}

\iffalse
\begin{proof}
By induction on the derivation of $\type{\GammaT}{\eT}{\tauT}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\mathcal{R}$. The premises of the derivation are the desired ones,
    building a derivation ending in $\type{\GammaT}{\eT}{\tauT}$,
    and $\subtype{\GammaT}{\tauT}{\tauT}$ holds by well-typedness of $\tauT$,
    \rref{equiv-refl}, and \rref{subtype-conv}.
  \item \rref*{conv*}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \type{\GammaT}{\eT}{\sigmaT} \\
      \type{\GammaT}{\sigmaT}{\UT} \\
      \type{\GammaT}{\tauT}{\UT} \\
      \subtype{\GammaT}{\sigmaT}{\tauT}
    }{
      \type{\GammaT}{\eT}{\tauT}
    }
    \end{mathpar}
    Induction hypothesis: there are derivations $\mathcal{D}_i$ ending in $\mathcal{J}_i$
    such that $\mathcal{R}$ builds a derivation ending in $\type{\GammaT}{\eT}{\sigmaT'}$
    and $\subtype{\GammaT}{\sigmaT'}{\sigmaT}$ holds. \\
    The desired derivations are $\mathcal{D}_i$, and $\subtype{\GammaT}{\sigmaT'}{\tauT}$
    holds by \rref{subtype-trans}.
\end{itemize}
\end{proof}
\fi

\begin{theorem}[Subject equivalence] \label{thm:subject-equivalence}
If $\defeq{\GammaT}{\eT_1}{\eT_2}{\tauT}$
then $\type{\GammaT}{\eT_1}{\tauT}$ and $\type{\GammaT}{\eT_2}{\tauT}$.
\end{theorem}

For completeness I restate the consistency of \CICE, again as a postulate.

\begin{postulate}[Consistency]
There exists no term $\eT$ such that
$\type{\mt}{\eT}{\funtypeT{\PT}{\PropT}{\PT}}$.
\end{postulate}

\section{Proof of Type Preservation}

As was outlined in \cref{sec:syntactic-model},
the proof of type preservation involves an additional five lemmas
demonstrating that the translation respects substitution, reduction,
$\alpha$-cumulativity, the closure of reduction, subtyping, and typing itself.
These lemmas require further sublemmas;
the subsequent subsections group the sublemmas with their lemma or theorem.

Many of these lemmas use the translation of terms $e$ and term environments $\Gamma$
using the shorthand $\compile{e}$ and $\compile{\Gamma}$,
omitting environment extensions for concision.
If not specified, the well-formedness of $\Gamma$ and well-typedness of $e$
needed for the translations are derived when possible
(\eg $\wf{\Phi}{\Gamma}$ and $\type{\Phi; \Gamma}{\tau}{U}$ from $\type{\Phi; \Gamma}{e}{\tau}$
by \cref{lem:wf-env} and \nameref{thm:regularity}, respectively)
and otherwise assumed as hypotheses.

\subsection{Compositionality}

Compositionality\index{compositionality} is the key to proving preservation of reduction in the next section,
since reduction rules are defined in terms of substitution.
In essence, we need to show that the translation commutes with substitution,
so that translating a term with a substitution is the same as
translating both terms and then applying the substitution.
Since there are three different forms of substitution
(substituting a term variable for a term,
a bounded size variable for a size,
and an unbounded size variable for a size),
we need to handle each separately,
and we end up with three individual compositionality lemmas.

\begin{sublemma} \label{sublem:subsize-FV}
If $\subsizeto{\Phi}{s_1}{s_2}{\eT}$ and $x$ is a term variable
then $\xT \notin \FV{\eT}$.
\end{sublemma}

\begin{proof}
By induction on the derivation of $\subsizeto{\Phi}{s_1}{s_2}{\eT}$.
Intuitively, the only variables resulting from translating a size expression
or a subsizing judgement are size variables $\alphaT$ or fresh variables $\alpha^*$,
so they couldn't contain any translated term variables.
\end{proof}

\begin{lemma}[Term compositionality] \label{lem:term-compositionality}
If $\type{\Phi; \Gamma_1, \annot{x}{\tau'}, \Gamma_2}{e}{\tau}$
and $\type{\Phi; \Gamma_1}{e'}{\tau'}$ then
$\subst{\compile{e}}{\xT}{\compile{e'}} = \compile{\subst{e}{x}{e'}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$,
where $\Gamma = \Gamma_1, \annot{x}{\tau'}, \Gamma_2$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{conv}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \dots \\
      \type{\Phi; \Gamma}{e}{\sigma} \\
      \subtype{\Phi; \Gamma}{\sigma}{\tau} \\
    }{
      \type{\Phi; \Gamma}{e}{\tau}
    }
    \end{mathpar}
    Induction hypothesis: $\subst{\compile{e}}{\xT}{\compile{e'}} = \compile{\subst{e}{x}{e'}}$. \\
    Trivial by the induction hypothesis.
  \item \rref*{var}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \wf{\Phi}{\Gamma} \\
      (\annot{y}{\tau}) \in \Gamma
    }{
      \type{\Phi; \Gamma}{y}{\tau}
    }
    \end{mathpar}
    If $x = y$, then $\subst{\xT}{\xT}{\compile{e'}} = \compile{e'} = \compile{\subst{x}{x}{e'}}$. \\
    If $x \neq y$, then $\subst{\yT}{\xT}{\compile{e'}} = \yT = \compile{\subst{y}{x}{e'}}$.
  \item[\textbf{Cases}] \rref*{univ}, \rref*{nat}. Trivial.
  \item[\textbf{Cases}] \rref*{pi}, \rref*{lam}, \rref*{app}, \rref*{let}, \rref*{forall}, \rref*{slam}, \rref*{sapp}, \rref*{forall<}, \rref*{slam<}, \rref*{wft}, \rref*{case-nat}, \rref*{case-wft}.
    Straightforward by the induction hypotheses.
    As example, I prove only the case for \rref*{case-wft}.
    \begin{mathpar}
    \inferrule{
      \infer{\Phi; \Gamma}{e}{\W{y}{\sigma}{\tau}{s}} \\
      z_1, z_2 \notin \FV{P} \\
      \infer{\Phi; \Gamma, \annot{w}{\W{y}{\sigma}{\tau}{s}}}{P}{U} \\
      \check{\Phi, \bound{\alpha}{s}; \Gamma, \annot{z_1}{\sigma}, \annot{z_2}{\arr*{\subst{\tau}{y}{z_1}}{\W{y}{\tau}{\sigma}{\alpha}}}}{e_s}{\subst{P}{w}{\sup{y}{\sigma}{\tau}{s}{\alpha}{z_1}{z_2}}}
    }{
      \infer{\Phi; \Gamma}{\match{e}{\fun*{w}{P}}{(\app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow e_s)}}{\subst{P}{w}{e}}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\subst{\compile{e}}{\xT}{\compile{e'}} = \compile{\subst{e}{x}{e'}}$,
      \item $\subst{\compile{P}}{\xT}{\compile{e'}} = \compile{\subst{P}{x}{e'}}$, and
      \item $\subst{\compile{e_s}}{\xT}{\compile{e'}} = \compile{\subst{e_s}{x}{e'}}$.
    \end{itemize}
    Suppose first that $x \neq w$, $x \neq z_1$, and $x \neq z_2$.
    Then we have
    \begin{align*}
    &\subst{\compile{\match{e}{\fun*{w}{P}}{(\app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow e_s)}}}{\xT}{\compile{e'}} \\
    &= \subst{(\matchT{\compile{e}}{\funT*{\mt}{\wT}{\compile{P}}}{(\app{\supT}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2} \RightarrowT \compile{e_s})})}{\xT}{\compile{e'}} && \textit{by translation} \\
    &= \matchT{\subst{\compile{e}}{\xT}{\compile{e'}}}{\funT*{\mt}{\wT}{\subst{\compile{P}}{\xT}{\compile{e'}}}}{\\ & \quad \qquad \app{\supT}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2} \RightarrowT \subst{\compile{e_s}}{\xT}{\compile{e'}}} && \textit{by substitution} \\
    &= \matchT{\compile{\subst{e}{x}{e'}}}{\funT*{\mt}{\wT}{\compile{\subst{P}{x}{e'}}}}{\\ & \quad \qquad \app{\supT}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2} \RightarrowT \compile{\subst{e_s}{x}{e'}}} && \textit{by IHs} \\
    &= \compile{\match{\subst{e}{x}{e'}}{\fun*{w}{\subst{P}{x}{e'}}}{(\app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow \subst{e_s}{x}{e'})}} && \textit{by translation} \\
    &= \compile{\subst{\match{e}{\fun*{w}{P}}{(\app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow e_s)}}{x}{e'}} && \textit{by substitution}.
    \end{align*}
    If $x$ is any of the binders $w, z_1, z_2$,
    then neither substitution of the subterms in \lang nor in \CICE would occur,
    giving the exact same equality.
  \item[\textbf{Cases}] \rref*{sapp<}, \rref*{zero}, \rref*{succ}, \rref*{sup}.
    Similar to the above, but with an additional term generated from translating subsizing judgements to deal with.
    I prove only the case for \rref*{sapp<} as example.
    \begin{mathpar}
    \inferrule{
      \infer{\Phi; \Gamma}{e}{\Funtype<{\alpha}{r}{\tau}} \\
      \subsize{\Phi}{\sss{s}}{r}
    }{
      \infer{\Phi; \Gamma}{\App{e}{s}}{\subst{\tau}{\alpha}{s}}
    }
    \end{mathpar}
    Induction hypothesis: $\subst{\compile{e}}{\xT}{\compile{e'}} = \compile{\subst{e}{x}{e'}}$. \\
    By the translation, we have $\subsizeto{\Phi}{\sss{s}}{r}{\eT''}$.
    Then we have
    \begin{align*}
    \subst{\compile{\App{e}{s}}}{\xT}{\compile{e'}}
    &= \subst{(\app{\compile{e}}{\compile{s}}{\eT''})}{\xT}{\compile{e'}} && \textit{by translation} \\
    &= \app{(\subst{\compile{e}}{\xT}{\compile{e'}})}{\compile{s}}{(\subst{\eT''}{\xT}{\compile{e'}})} && \textit{by substitution} \\
    &= \app{(\subst{\compile{e}}{\xT}{\compile{e'}})}{\compile{s}}{\eT''} && \textit{by \cref{sublem:subsize-FV}} \\
    &= \app{\compile{\subst{e}{x}{e'}}}{\compile{s}}{\eT''} && \textit{by IH} \\
    &= \compile{\App{\subst{e}{x}{e'}}{s}} && \textit{by translation} \\
    &= \compile{\subst{\App{e}{s}}{x}{e'}} && \textit{by substitution},
    \end{align*}
    noting that substitution of a term variable in the translation of a size expression
    has no effect since they produce no term variables.
  \item \rref*{fix}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \dots \\
      \infer{\Phi, \alpha; \Gamma}{\sigma}{U} \\
      \check{\Phi, \alpha; \Gamma, \annot{f}{\Funtype<{\beta}{\alpha}{\subst{\sigma}{\alpha}{\beta}}}}{e}{\sigma}
    }{
      \infer{\Phi; \Gamma}{\fix{f}{\alpha}{\sigma}{e}}{\Funtype{\alpha}{\sigma}}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\subst{\compile{\sigma}}{\xT}{\compile{e'}} = \compile{\subst{\sigma}{x}{e'}}$ and
      \item $\subst{\compile{e}}{\xT}{\compile{e'}} = \compile{\subst{e}{x}{e'}}$.
    \end{itemize}
    We then have
    \allowdisplaybreaks
    \begin{align*}
    &\subst{\compile{\fix{f}{\alpha}{\sigma}{e}}}{\xT}{\compile{e'}} \\
    &= \subst{(\app{\wfind}{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{ \\
    & \quad \qquad (\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}{\compile{e}}})})}{\xT}{e'} \\
    & \quad \textit{by translation} \\
    &= \app{\wfind}{(\funT{\alphaT}{\SizeT}{\subst{\compile{\sigma}}{\xT}{\compile{e'}}})}{ \\
    & \quad \qquad (\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\xT, \alphaT}{\compile{e'}, \betaT}}}}{\subst{\compile{e}}{\xT}{\compile{e'}}}})} \\
    & \quad \textit{by substitution} \\
    &= \app{\wfind}{(\funT{\alphaT}{\SizeT}{\compile{\subst{\sigma}{x}{e'}}})}{ \\
    & \quad \qquad (\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\subst{\sigma}{x}{e'}}}{\alphaT}{\betaT}}}}{\compile{\subst{e}{x}{e'}}}})} \\
    & \quad \textit{by IHs} \\
    &= \compile{\fix{f}{\alpha}{\subst{\sigma}{x}{e'}}{\subst{e}{x}{e'}}} \quad \textit{by translation} \\
    &= \compile{\subst{\fix{f}{\alpha}{\sigma}{e}}{x}{e'}} \quad \textit{by substitution}.
    \end{align*}
    Substitution of $x$ has no effect on $\wfind$ since it's defined independently of the translation
    and has no variables originating from the source expression. \qedhere
\end{itemize}
\end{proof}

\iffalse % this isn't used anywhere??
\begin{corollary}[Term environment compositionality]
If $\wf{\Phi}{\Gamma_1, \annot{x}{\tau}, \Gamma_2}$ and $\type{\Phi; \Gamma_1}{e}{\tau}$
then $\compile{\Gamma_1}, \subst{\compile{\Gamma_2}}{\xT}{\compile{e}} = \compile{\Gamma_1, \subst{\Gamma_2}{x}{e}}$
by induction on $\wf{\Phi}{\Gamma_1, \annot{x}{\tau}, \Gamma_2}$
using \nameref{lem:term-compositionality}.
\end{corollary}
\fi

In addition to compositionality when substituting terms,
we also need compositionality when substitution sizes.
This is not as simple when substituting bounded sizes into terms,
since a single substitution in the source
would correspond to two substitutions in the target,
the second being a term exhibiting boundedness,
but the proofs have the same structure.

\begin{sublemma}\label{sublem:compos-size}
$\subst{\compile{s}}{\alphaT}{\compile{r}} = \compile{\subst{s}{\alpha}{r}}$.
\end{sublemma}

\begin{proof}
By induction on the structure of $s$.
\end{proof}

\begin{sublemma} \label{sublem:compos-subsize-bounded}
If $\subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s}{r}{\eT}$
and $\subsizeto{\Phi_1}{\sss{s}'}{r'}{\eT'}$
then $\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s}{\alpha}{s'}}{\subst{r}{\alpha}{s'}}{\subst{\eT}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}$.
\end{sublemma}

\begin{proof}
By induction on the derivation of $\subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s}{r}{\eT}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\subsize*{\sss{\beta}}{s}$.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule[]{
      (\bound{\beta}{s}) \in \Phi_1, \bound{\alpha}{r'}, \Phi_2
    }{
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{\sss{\beta}}{s}{\betaT^*}
    }
    \end{mathpar}
    If $\beta = \alpha$, then $\betaT^* = \alphaT^*$ and $s = r'$, and the goal holds by
    $\subsizeto{\Phi_1}{\sss{s}'}{r'}{\eT'}$.
    If $\beta \neq \alpha$ and $\bound{\beta}{s} \in \Phi_1$,
    then $\alpha \notin \FV{s}$ and $\bound{\beta}{s} \in \Phi_1, \subst{\Phi_2}{\alpha}{s}$,
    so we have the following.
    \begin{mathpar}
    \inferrule{
      \bound{\beta}{s} \in \Phi_1, \subst{\Phi_2}{\alpha}{s}
    }{
      \subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s}}{\sss{\beta}}{s}{\betaT^*}
    }
    \end{mathpar}
    Otherwise, if $\bound{\beta}{s} \in \Phi_2$,
    then $\bound{\beta}{\subst{s}{\alpha}{r'}} \in \Phi_1, \subst{\Phi_2}{\alpha}{r'}$,
    and we have the following.
    \begin{mathpar}
    \inferrule[]{
      (\bound{\beta}{\subst{s}{\alpha}{s'}}) \in \Phi_1, \subst{\Phi_2}{\alpha}{r'}
    }{
      \subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{r'}}{\sss{\beta}}{\subst{s}{\alpha}{s'}}{\betaT^*}
    }
    \end{mathpar}
  \item[\textbf{Cases}] $\subsize*{\circ}{s}$, $\subsize*{s}{s}$, $\subsize*{s}{\sss{s}}$.
    By \cref{sublem:compos-size}, noting that the fresh variable $\alphaT^*$
    never appears in the translation of a size expression.
  \item $\subsize*{\sss{s}}{\sss{r}}$.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s}{r}{\eT}
    }{
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{\sss{s}}{\sss{r}}{\app{\monoT}{\compile{s}}{\compile{r}}{\eT}}
    }
    \end{mathpar}
    Induction hypothesis: $$\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s}{\alpha}{s'}}{\subst{r}{\alpha}{s'}}{\subst{\eT}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}.$$
    By the same rule, we can derive
    \begin{align*}
      &\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{\sss{s}}{\alpha}{s'}}{\subst{\sss{r}}{\alpha}{s'}}
      {\\ & \qquad \app{\monoT}{\compile{\subst{s}{\alpha}{s'}}}{\compile{\subst{r}{\alpha}{s'}}}{(\subst{\eT}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}}.
    \end{align*}
    By \cref{sublem:compos-size}, again noting that $\alphaT^*$ never appears in $\compile{s}$ or $\compile{r}$,
    this becomes
    \begin{align*}
      &\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{\sss{s}}{\alpha}{s'}}{\subst{\sss{r}}{\alpha}{s'}}
      {\\ & \qquad \app{\monoT}{\subst{\compile{s}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}{\subst{\compile{r}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}{(\subst{\eT}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}}.
    \end{align*}
    By substitution, the result of translation above is exactly $\subst{(\app{\monoT}{\compile{s}}{\compile{r}}{\eT})}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}$,
    as desired.
  \item \textbf{for transitivity}.
    \begin{mathpar}
    \inferrule{
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s_1}{s_2}{\eT_{12}} \\
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s_2}{s_3}{\eT_{23}}
    }{
      \subsizeto{\Phi_1, \bound{\alpha}{r'}, \Phi_2}{s_1}{s_3}{\app{\transleq}{\compile{s_1}}{\compile{s_2}}{\compile{s_3}}{\eT_{12}}{\eT_{23}}}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s_1}{\alpha}{s'}}{\subst{s_2}{\alpha}{s'}}{\subst{\eT_{12}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}$ and
      \item $\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s_2}{\alpha}{s'}}{\subst{s_3}{\alpha}{s'}}{\subst{\eT_{23}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}$.
    \end{itemize}
    By the same rule, we can derive
    \begin{align*}
    &\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s_1}{\alpha}{s'}}{\subst{s_3}{\alpha}{s'}}
    {\\ & \qquad \app{\transleq}{\compile{\subst{s_1}{\alpha}{s'}}}{\compile{\subst{s_2}{\alpha}{s'}}}{\compile{\subst{s_3}{\alpha}{s'}}}
    {\\ & \qquad \phantom{\app{\transleq}{}} (\subst{\eT_{12}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}{(\subst{\eT_{23}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}}
    \end{align*}
    By \cref{sublem:compos-size}, again noting that $\alphaT^*$ never appears in
    $\compile{s_1}$, $\compile{s_2}$, or $\compile{s_3}$, this becomes
    \begin{align*}
    &\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s_1}{\alpha}{s'}}{\subst{s_3}{\alpha}{s'}}
    {\\ & \qquad \app{\transleq}{\subst{\compile{s_1}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}{\subst{\compile{s_2}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}{\subst{\compile{s_3}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'}}
    {\\ & \qquad \phantom{\app{\transleq}{}} (\subst{\eT_{12}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}{(\subst{\eT_{23}}{\alphaT, \alphaT^*}{\compile{s'}, \eT'})}}
    \end{align*}
    By substitution, the result of translation above is exactly
    $$\subst{(\app{\transleq}{\compile{s_1}}{\compile{s_2}}{\compile{s_3}}{\eT_{12}}{\eT_{23}})}{\alphaT, \alphaT^*}{\compile{s'}, \eT'},$$
    as desired. \qedhere
\end{itemize}
\end{proof}

\begin{sublemma} \label{sublem:compos-subsize-unbounded}
If $\subsizeto{\Phi_1, \alpha, \Phi_2}{s}{r}{\eT}$ and $\wf{\Phi_1}{s'}$ then
$\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s'}}{\subst{s}{\alpha}{s'}}{\subst{r}{\alpha}{s'}}{\subst{\eT}{\alphaT}{\compile{s'}}}$.
\end{sublemma}

\begin{proof}
By induction on the derivation of $\subsizeto{\Phi_1, \alpha, \Phi_2}{s}{r}{\eT}$.
The proof structure follows that of \cref{sublem:compos-subsize-bounded}.
\end{proof}

Just as compositionality for subsizing is split into substitution of bounded and unbounded sizes,
so is size compositionality with respect to terms.
Of note is that the right-hand side only has a single substitution,
while the left-hand side has two,
since the proof $\eT'$ now needs to be handled explicitly.

\begin{lemma}[Size compositionality (bounded)] \label{lem:compos-size-bounded}
If $\type{\Phi_1, \bound{\alpha}{r}, \Phi_2; \Gamma}{e}{\tau}$
and $\subsizeto{\Phi_1}{\sss{s}}{r}{\eT'}$ then
$\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e}{\alpha}{s}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$,
where $\Phi = \Phi_1, \bound{\alpha}{r}, \Phi_2$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{conv}.
    \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \dots \\
        \type{\Phi; \Gamma}{e}{\sigma} \\
        \subtype{\Phi; \Gamma}{\sigma}{\tau}
      }{
        \type{\Phi; \Gamma}{e}{\tau}
      }
    \end{mathpar}
      Induction hypothesis: $\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e}{\alpha}{s}}$.
      Trivial by the induction hypothesis.
  \item[\textbf{Cases}] \rref*{var}, \rref*{univ}. Trivial.
  \item[\textbf{Cases}] \rref*{pi}, \rref*{lam}, \rref*{app}, \rref*{let}.
    Straightforward by the induction hypotheses.
    As example, I prove only the case for \rref*{let}.
    \begin{mathpar}
      \inferrule{
        \type{\Phi; \Gamma}{\sigma}{U} \\
        \type{\Phi; \Gamma}{e_1}{\sigma} \\
        \type{\Phi; \Gamma, \define{x}{\sigma}{e_1}}{e_2}{\tau} \\
      }{
        \type{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\subst{\tau}{x}{e_1}}
      }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\subst{\compile{\sigma}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{\sigma}{\alpha}{s}}$,
      \item $\subst{\compile{e_1}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e_1}{\alpha}{s}}$, and
      \item $\subst{\compile{e_2}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e_2}{\alpha}{s}}$.
    \end{itemize}
    Then we have
    \begin{align*}
    &\subst{\compile{\letin{x}{\sigma}{e_1}{e_2}}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    &= \subst{(\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}})}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    & \quad \textit{by translation} \\
    &= \letinT{\xT}{\subst{\compile{\sigma}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}{\subst{\compile{e_1}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}{\subst{\compile{e_2}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}} \\
    & \quad \textit{by substitution} \\
    &= \letinT{\xT}{\compile{\subst{\sigma}{\alpha}{s}}}{\compile{\subst{e_1}{\alpha}{s}}}{\compile{\subst{e_2}{\alpha}{s}}} \\
    & \quad \textit{by IHs} \\
    &= \compile{\letin{x}{\subst{\sigma}{\alpha}{s}}{\subst{e_1}{\alpha}{s}}{\subst{e_2}{\alpha}{s}}} \\
    & \quad \textit{by translation} \\
    &= \compile{\subst{(\letin{x}{\sigma}{e_1}{e_2})}{\alpha}{s}} \\
    & \quad \textit{by substitution}.
    \end{align*}
  \item[\textbf{Cases}] \rref*{forall}, \rref*{slam}, \rref*{case-nat}, \rref*{case-wft}.
    Similar to the above, taking care to handle shadowing.
    I prove only the case for \rref*{forall} as example.
    \begin{mathpar}
      \inferrule{
        \type{\Phi, \beta; \Gamma}{\tau}{U}
      }{
        \type{\Phi; \Gamma}{\Funtype{\beta}{\tau}}{U}
      }
    \end{mathpar}
    Induction hypothesis: $\subst{\compile{\tau}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{\tau}{\alpha}{s}}$. \\
    Suppose first that $\alpha \neq \beta$. Then we have
    \begin{align*}
    \subst{\compile{\Funtype{\beta}{\tau}}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}
    &= \subst{(\funtypeT{\betaT}{\SizeT}{\compile{\tau}})}{\alphaT, \alphaT^*}{\compile{s}, \eT'}
    && \textit{by translation} \\
    &= \funtypeT{\betaT}{\SizeT}{\subst{\compile{\tau}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}
    && \textit{by substitution} \\
    &= \funtypeT{\betaT}{\SizeT}{\compile{\subst{\tau}{\alpha}{s}}}
    && \textit{by IH} \\
    &= \compile{\Funtype{\beta}{\subst{\tau}{\alpha}{s}}}
    && \textit{by translation} \\
    &= \compile{\subst{(\Funtype{\beta}{\tau})}{\alpha}{s}}
    && \textit{by substitution}.
    \end{align*}
    If $\alpha = \beta$, then the substitutions would never occur, making the goal hold trivially.
  \item[\textbf{Cases}] \rref*{sapp}, \rref*{forall<}, \rref*{slam<}, \rref*{nat}, \rref*{wft}.
    Similar to the above, additionally using \cref{sublem:compos-size} when substituting into size expressions.
    I prove only the case for \rref*{slam<} as example.
    \begin{mathpar}
      \inferrule{
        \wf{\Phi}{r} \\
        \type{\Phi, \bound{\beta}{r}; \Gamma}{e}{\tau}
      }{
        \type{\Phi; \Gamma}{\Fun<{\beta}{r}{e}}{\Funtype<{\beta}{r}{\tau}}
      }
    \end{mathpar}
    Induction hypothesis: $\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e}{\alpha}{s}}$. \\
    Then we have
    \begin{align*}
    &\subst{\compile{\Fun<{\beta}{r}{e}}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    &= \subst{(\funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{r}}{\compile{e}}})}{\alphaT, \alphaT^*}{\compile{s}, \eT'}
    && \textit{by translation} \\
    &= \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \subst{\compile{r}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}{\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}}
    && \textit{by substitution} \\
    &= \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{\subst{r}{\alpha}{s}}}{\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}}
    && \textit{by \cref{sublem:compos-size}, $\alphaT^* \notin \compile{r}$} \\
    &= \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{\subst{r}{\alpha}{s}}}{\compile{\subst{e}{s}{\alpha}}}}
    && \textit{by IH} \\
    &= \compile{\Fun<{\beta}{\subst{r}{\alpha}{s}}{\subst{e}{\alpha}{s}}}
    && \textit{by translation} \\
    &= \compile{\subst{(\Fun<{\beta}{r}{e})}{\alpha}{s}}
    && \textit{by substitition}.
    \end{align*}
  \item[\textbf{Cases}] \rref*{sapp<}, \rref*{zero}, \rref*{succ}, \rref*{sup}.
    In these cases, there are additional terms generated rom translation subsizing judgements;
    here is where we use \cref{sublem:compos-subsize-bounded}.
    I prove only the case of \rref*{sapp<} as example.
    \begin{mathpar}
      \inferrule{
        \type{\Phi; \Gamma}{e}{\Funtype<{\beta}{r'}{\tau}} \\
        \subsize{\Phi}{\sss{r}}{r'}
      }{
        \type{\Phi; \Gamma}{\App{e}{r}}{\subst{\tau}{\beta}{r}}
      }
    \end{mathpar}
    Induction hypothesis: $\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} = \compile{\subst{e}{\alpha}{s}}$. \\
    By the translation, we have $\subsizeto{\Phi; \Gamma}{\sss{r}}{r'}{\eT''}$.
    On the left-hand, side we have
    \begin{align*}
    &\subst{\compile{\App{e}{r}}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    &= \subst{(\app{\compile{e}}{\compile{r}}{\eT''})}{\alphaT, \alphaT^*}{\compile{s}, \eT'}
    && \textit{by translation} \\
    &= \app{(\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}{(\subst{\compile{r}}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}{(\subst{\eT''}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}
    && \textit{by substitution} \\
    &= \app{(\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}{\compile{\subst{r}{\alpha}{s}}}{(\subst{\eT''}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}
    && \textit{by \cref{sublem:compos-size}, $\alpha^* \notin \compile{r}$} \\
    &= \app{\compile{\subst{e}{\alpha}{s}}}{\compile{\subst{r}{\alpha}{s}}}{(\subst{\eT''}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}
    && \textit{by IH}.
    \end{align*}
    Meanwhile, on the right-hand size,
    noting that $\subsizeto{\Phi_1, \subst{\Phi_2}{\alpha}{s}; \Gamma}{\subst{\sss{r}}{\alpha}{s}}{\subst{r'}{\alpha}{s}}{\subst{\eT''}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}$
    by \cref{sublem:compos-subsize-bounded}, we have

    \begin{align*}
    &\compile{\subst{\App{e}{r}}{\alpha}{s}} \\
    &= \compile{\App{\subst{e}{\alpha}{s}}{\subst{r}{\alpha}{s}}}
    && \textit{by substitution} \\
    &= \app{\compile{\subst{e}{\alpha}{s}}}{\compile{\subst{r}{\alpha}{s}}}{(\subst{\eT''}{\alphaT, \alphaT^*}{\compile{s}, \eT'})}
    && \textit{by translation and \nameref{lem:substitutivity-bounded}}.
    \end{align*}
  \item \rref*{fix}.
    \vspace{-\baselineskip}
    \begin{mathpar}
      \inferrule{
        \dots \\
        \infer{\Phi, \alpha; \Gamma}{\sigma}{U} \\
        \check{\Phi, \beta; \Gamma, \annot{f}{\Funtype<{\gamma}{\beta}{\subst{\sigma}{\beta}{\gamma}}}}{e}{\sigma}
      }{
        \infer{\Phi; \Gamma}{\fix{f}{\beta}{\sigma}{e}}{\Funtype{\beta}{\sigma}}
      }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\subst{\compile{\sigma}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}$ and
      \item $\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}$.
    \end{itemize}
    Supposing that $\alpha \neq \beta$, we then have
    \allowdisplaybreaks
    \begin{align*}
    &\subst{\compile{\fix{f}{\beta}{\sigma}{e}}}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    &= \subst{(\app{\wfind}{(\funT{\betaT}{\SizeT}{\compile{\sigma}})}{ \\
    & \quad \qquad (\funT{\betaT}{\SizeT}{\funT{\fT}{\funtypeT{\gammaT}{\SizeT}{\arrT*{\gammaT \szltT \betaT}{\subst{\compile{\sigma}}{\betaT}{\gammaT}}}}{\compile{e}}})})}{\alphaT, \alphaT^*}{\compile{s}, \eT'} \\
    & \quad \textit{by translation} \\
    &= \app{\wfind}{(\funT{\betaT}{\SizeT}{\subst{\compile{\sigma}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}})}{ \\
    & \quad \qquad (\funT{\betaT}{\SizeT}{\funT{\fT}{\funtypeT{\gammaT}{\SizeT}{\arrT*{\gammaT \szltT \betaT}{\subst{\compile{\sigma}}{\alphaT, \alphaT^*, \betaT}{\compile{s}, \eT', \gammaT}}}}{\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}})} \\
    & \quad \textit{by substitution} \\
    &= \app{\wfind}{(\funT{\betaT}{\SizeT}{\compile{\subst{\sigma}{\alpha}{s}}})}{ \\
    & \quad \qquad (\funT{\betaT}{\SizeT}{\funT{\fT}{\funtypeT{\gammaT}{\SizeT}{\arrT*{\gammaT \szltT \betaT}{\subst{\compile{\subst{\sigma}{\alpha}{s}}}{\betaT}{\compile{s}, \eT', \gammaT}}}}{\compile{\subst{e}{\alpha}{s}}}})} \\
    & \quad \textit{by IHs} \\
    &= \compile{\fix{f}{\alpha}{\subst{\sigma}{\alpha}{s}}{\subst{e}{\alpha}{s}}} \quad \textit{by translation} \\
    &= \compile{\subst{\fix{f}{\alpha}{\sigma}{e}}{\alpha}{s}} \quad \textit{by substitution}.
    \end{align*}

    If $\alpha = \beta$, then the substitution for $\alphaT$ would never occur;
    since $\beta$ is an unbound size variable,
    neither $\compile{\sigma}$ nor $\compile{e}$ would contain $\betaT^*$,
    so the substitution for $\alphaT^*$ does nothing. \qedhere
\end{itemize}
\end{proof}

\begin{lemma}[Size compositionality (unbounded)] \label{lem:compos-size-unbounded}
If $\type{\Phi_1, \alpha, \Phi_2; \Gamma}{e}{\tau}$
and $\wf{\Phi_1}{s}$ then
$\subst{\compile{e}}{\alphaT}{\compile{s}} = \compile{\subst{e}{\alpha}{s}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\type{\Phi_1, \alpha, \Phi_2; \Gamma}{e}{\tau}$.
The proof structure follows that of \nameref{lem:compos-size-bounded},
using \cref{sublem:compos-subsize-unbounded} in place of \cref{sublem:compos-subsize-bounded}
where the translation of subsizing is involved.
\end{proof}

\subsection{Preservation of reduction}

We're now ready to prove preservation of reduction,
whose proof uses the various compositionality lemmas
whenever substitution into a translated term is involved.
Our task is to show that if one term reduces to another,
then their translations are equivalent.
Because \CICE's equivalence judgement is typed,
we need typing information for the translated terms
to satisfy its premises.
Note however that we only need \emph{some} typing information,
and that $\tauT$ isn't necessarily $\compile{\tau}$.
To show that it is would require type preservation itself,
which in turn would make our proofs circular.

\begin{lemma}[Preservation of reduction] \label{lem:pres-red}
Suppose we have the following:
\begin{itemize}[noitemsep]
  \item $\red{\Phi; \Gamma}{e}{e'}$,
  \item $\type{\Phi; \Gamma}{e}{\tau}$, and
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\tauT}$.
\end{itemize}
Then $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{e'}}{\tauT}$,
where \nameref{lem:sr} gives us $\type{\Phi; \Gamma}{e'}{\tau}$
in order to translate $\compile{e'}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red{\Phi; \Gamma}{e}{e'}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\red{\Phi; \Gamma}{x}{e}$ when $(\define{x}{\tau}{e}) \in \Gamma$.
    By the definition of $\compile{\Gamma}$, we have
    $(\defineT{\xT}{\compile{\tau}}{\compile{e}}) \in \compile{\Gamma}$.
    By inversion on $\type{\compile{\Phi}, \compile{\Gamma}}{\xT}{\tauT}$,
    we have that $\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau}}{\tauT}$.
    Then $\defeq{\compile{\Phi}, \compile{\Gamma}}{\xT}{\compile{e}}{\compile{\tau}}$
    holds by \rref{equiv-delta, equiv-conv}.
  \item $\red{\Phi; \Gamma}{\app{(\fun{x}{\sigma}{e})}{e'}}{\subst{e}{x}{e'}}$.\\
    By inversion on $\type{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\xT}{\compile{\sigma}}{\compile{e}})}{\compile{e'}}}{\tauT}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\xT}{\compile{\sigma}}{\compile{e}}}{\funtypeT{\xT}{\sigmaT'}{\tauT'}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e'}}{\sigmaT'}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\compile{e'}}}{\tauT}$.
    \end{itemize}
    By inversion once more on $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\xT}{\compile{\sigma}}{\compile{e}}}{\funtypeT{\xT}{\sigmaT'}{\tauT'}}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\compile{\sigma}}}{\compile{e}}{\tauT''}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\xT}{\compile{\sigma}}{\tauT''}}{\funtypeT{\xT}{\sigmaT'}{\tauT'}}$.
    \end{itemize}
    By inversion on $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\xT}{\compile{\sigma}}{\tauT''}}{\funtypeT{\xT}{\sigmaT'}{\tauT'}}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\sigmaT'}{\UT}$ and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\tauT''}{\tauT'}$.
    \end{itemize}
    \rref{conv*} gives us $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\compile{\sigma}}}{\compile{e}}{\tauT'}$,
    and \rref{equiv-sym, subtype-conv} give us
    $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e'}}{\compile{\sigma}}$.
    We can then use \rref{equiv-beta, equiv-conv} to get
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\xT}{\compile{\sigma}}{\compile{e}})}{\compile{e'}}}{\subst{\compile{e}}{\xT}{\compile{e'}}}{\tauT}.$$
    Finally, by \nameref{lem:term-compositionality}, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\app{(\fun{x}{\sigma}{e})}{e'}}}{\compile{\subst{e}{x}{e'}}}{\tauT}$$
  \item $\red{\Phi; \Gamma}{\App{(\Fun{\alpha}{e})}{s}}{\subst{e}{\alpha}{s}}$.\\
    By inversion on $\type{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\compile{e}})}{\compile{s}}}{\tauT}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\alphaT}{\SizeT}{\compile{e}}}{\funtypeT{\alphaT}{\SizeT}{\tauT'}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{s}}{\SizeT}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\alphaT}{\compile{s}}}{\tauT}$.
    \end{itemize}
    By inversion once more on $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\funtypeT{\alphaT}{\SizeT}{\tauT'}}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\compile{e}}{\tauT''}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\tauT''}}{\funtype{\alphaT}{\SizeT}{\tauT'}}$.
    \end{itemize}
    By inversion on $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\tauT''}}{\funtypeT{\alphaT}{\SizeT}{\tauT'}}$,
    we have $\subtype{\compile{\Phi}, \compile{\Gamma}}{\tauT''}{\tauT'}$.
    \rref{conv*} then gives us $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\compile{e}}{\tauT'}$.
    We can then use \rref{equiv-beta, equiv-conv} to get
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\compile{e}})}{\compile{s}}}{\subst{\compile{e}}{\alphaT}{\compile{s}}}{\tauT}.$$
    Finally, by \nameref{lem:compos-size-unbounded}, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\App{(\Fun{\alpha}{e})}{s}}}{\compile{\subst{e}{\alpha}{s}}}{\tauT}$$
  \item $\red{\Phi; \Gamma}{\App{(\Fun<{\alpha}{r}{e})}{s}}{\subst{e}{\alpha}{s}}$.\\
    Let $\subsizeto{\Phi}{\sss{s}}{r}{\eT'}$.
    Then by inversion thrice on $\type{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\funT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{e}}})}{\compile{s}}{\eT'}}{\tauT}$
    and an application of \rref{conv*}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\alphaT \szltT \compile{s}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{s}}}{\compile{e}}{\tauT'}$, and
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}{\tauT}$.
    \end{itemize}
    We can then use \rref{equiv-beta} twice and \rref{equiv-conv} to get
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\funT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{e}}})}{\compile{s}}{\eT'}}{\subst{\compile{e}}{\alphaT, \alphaT^*}{\compile{s}, \eT'}}{\tauT}.$$
    Finally, by \nameref{lem:compos-size-bounded}, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\App{(\Fun<{\alpha}{r}{e})}{s}}}{\compile{\subst{e}{\alpha}{s}}}{\tauT}$$
  \item $\red{\Phi; \Gamma}{\letin{x}{\sigma}{e'}{e}}{\subst{e}{x}{e'}}$.\\
    By inversion on $\type{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e'}}{\compile{e}}}{\tauT}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e'}}{\compile{\sigma}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma}}{\compile{e'}}}{\compile{e}}{\tauT'}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\eT'}}{\tauT}$.
    \end{itemize}
    We can then use \rref{equiv-zeta, equiv-conv} to get
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e'}}{\compile{e}}}{\subst{\compile{e}}{\xT}{\compile{e'}}}{\tauT}.$$
    Finally, by \nameref{lem:term-compositionality}, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\letin{x}{\sigma}{e'}{e}}}{\compile{\subst{x}{e}{e'}}}{\tauT}.$$
  \item[\textbf{Cases}] \textbf{for $\kw{case}$}.
    \setlength{\jot}{-1.5pt}
    Because the three reduction rules for case expressions on $\zero*$, $\succ*$, and $\sup*$ are very similar,
    I cover only $\sup*$ as a representative case.
    $$\red{\Phi; \Gamma}{
      \begin{aligned}
        &\match{\sup{x}{\sigma}{\tau}{r}{s}{e_1}{e_2}}{\fun*{x}{P}}{\\
        &\quad \app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow e}
      \end{aligned}
    }{\subst{e}{\alpha, z_1, z_2}{s, e_1, e_2}}$$
    Let $\subsizeto{\Phi}{\sss{s}}{r}{\eT'}$.
    Then by inversion multiple times on
    $$\type{\compile{\Phi}, \compile{\Gamma}}{
      \begin{aligned}
        &\matchT{\app{\supT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{r}}{\compile{s}}{\eT'}{\compile{e_1}}{\compile{e_2}}}{\funT*{\mt}{\xT}{\compile{P}}}{ \\
        &\quad \app{\supT}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2} \RightarrowT \compile{e}}
      \end{aligned}
    }{\tauT}$$
    and a few applications of \rref{conv*}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\xT}{\compile{\sigma}}{\compile{\tau}}}{\funtypeT{\xT}{\compile{\sigma}}{\UT}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{r}}{\SizeT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{s}}{\SizeT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\eT'}{\compile{s} \szltT \compile{r}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{\sigma}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e_2}}{\arrT*{\app{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{e_1}}}{\app{\WT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{s}}}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\app{\WT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{r}}}}{\compile{P}}{\UT'}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{r}}, \annotT{\zT_1}{\compile{\sigma}}, \annotT{\zT_2}{\app{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\zT_1}}}{\compile{e}}{\subst{\compile{P}}{\xT}{\app{\supT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{r}}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2}}}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\compile{P}}{\xT}{\app{\supT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{r}}{\compile{s}}{\eT'}{\compile{e_1}}{\compile{e_2}}}}{\tauT}$
    \end{itemize}
    We can then use \rref{equiv-iota, equiv-conv} to get
    \begin{align*}
    \defeq{\compile{\Phi}, \compile{\Gamma}}{
      \begin{aligned}
        &\matchT{\app{\supT}{\compile{\sigma}}{(\funT{\xT}{\compile{\sigma}}{\compile{\tau}})}{\compile{r}}{\compile{s}}{\eT'}{\compile{e_1}}{\compile{e_2}}}{\funT*{\mt}{\xT}{\compile{P}}}{ \\
        &\quad \app{\supT}{\alphaT}{\alphaT^*}{\zT_1}{\zT_2} \RightarrowT \compile{e}}
      \end{aligned}
    }{\\ \qquad \subst{\compile{e}}{\alphaT, \alphaT^*, \zT_1, \zT_2}{\compile{s}, \eT', \compile{e_1}, \compile{e_2}}}{\tauT}.
    \end{align*}
    Finally, by \nameref{lem:compos-size-unbounded}, \nameref{lem:compos-size-bounded},
    and \nameref{lem:term-compositionality} twice, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile*{
      \begin{aligned}
        &\match{\sup{x}{\sigma}{\tau}{r}{s}{e_1}{e_2}}{\fun*{x}{P}}{\\
        &\quad \app{\App{\sup*}{\alpha}}{z_1}{z_2} \Rightarrow e}
      \end{aligned}
    }}{\compile{\subst{e}{\alpha, z_1, z_2}{s, e_1, e_2}}}{\tauT}$$
  \item $\red[]{\Phi; \Gamma}{
      \App{(\fix{f}{\alpha}{\sigma}{e})}{s}
    }{
      \subst{e}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\sigma}{e})}{\beta}}}
    }$.\\
    By definition of the translation, we have
    $$\type{\compile{\Phi}, \compile{\Gamma}}{
      \begin{aligned}
      & \app{\wfind}{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\\
      & \quad (\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}{\compile{e}}})}{\compile{s}}
      \end{aligned}
    }{\tauT},$$
    where $\wfind$ (and $\wfacc$) are defined in \cref{fig:defns}.
    Because of the sheer volume of the terms involved in the translation, $\wfind$, and $\wfacc$,
    I omit well-typedness premises when applying equivalence rules,
    especially since all of these terms are known to be well typed.
    Do note, however, that by repeated applications of inversion, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\compile{s}}}{\tauT}$. \\[\baselineskip]
    Let $\sigmaT$ be $\funT{\alphaT}{\SizeT}{\compile{\sigma}}$,
    and let $\eT$ be $\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}{\compile{e}}}$.
    Liberally using \rref{equiv-trans}, for the left-hand side we then have
    \begin{align*}
    \compile{\Phi}, \compile{\Gamma} &\vdash \app{\wfind}{\sigmaT}{\eT}{\compile{s}} \\
    &\equiv \app{\wfacc}{\sigmaT}{\eT}{\compile{s}}{(\app{\accessible}{\compile{s}})} \\
      &\phantom{\equiv} \textit{by $\wfind$ and \rref*{equiv-beta}} \\
    &\equiv \app{(\fixT{1}{\wfacc*}{\funtypeT{\alphaT}{\SizeT}{\arrT*{\app{\AccT}{\alphaT}}{\app{\sigmaT}{\alphaT}}}}{ \\
      &\phantom{\equiv} \quad \funT{\alphaT}{\any}{\funT{\access}{\any}{\app{\eT}{\alphaT}{(\funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \alphaT}{ \\
      &\phantom{\equiv} \qquad \app{\wfacc*}{\betaT}{(\matchT*{\access}{(\app{\accT}{\pT} \Rightarrow \app{\pT}{\betaT}{\betaT^*})})}}})}}}})}{\compile{s}}{(\app{\accessible}{\compile{s}})} \\
      &\phantom{\equiv} \textit{by $\wfacc$ and \rref*{equiv-beta}} \\
    &\equiv \subst{\compile{e}}{\alphaT, \fT}{\compile{s}, \funT{\betaT^*}{\betaT \szltT \compile{s}}{ \\
      &\phantom{\equiv} \quad \app{\wfacc}{\sigmaT}{\eT}{\beta}{(\matchT*{\app{\accessible}{\compile{s}}}{(\app{\accT}{\pT} \Rightarrow \app{\pT}{\betaT}{\betaT^*})})}}} \\
      &\phantom{\equiv} \textit{by \rref*{equiv-mu}, \rref*{equiv-beta}, and $\wfacc$} \\
    &: \app{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\compile{s}}
    \end{align*}
    Meanwhile, for the right-hand side we have
    \begin{align*}
    &\compile{\subst{e}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\sigma}{e})}{\beta}}}} \\
    &= \subst{\compile{e}}{\alphaT, \fT}{\compile{s}, \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{s}}{\app{\compile{\fix{f}{\alpha}{\sigma}{e}}}{\betaT}}}} \\
      &\phantom{=} \textit{by \nameref{lem:compos-size-unbounded} and \nameref{lem:term-compositionality}} \\
    &= \subst{\compile{e}}{\alphaT, \fT}{\compile{s}, \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{s}}{\app{\wfind}{\sigmaT}{\eT}{\betaT}}}} \\
      &\phantom{=} \textit{by definition of translation of $\kw{fix}$} \\
    &= \subst{\compile{e}}{\alphaT, \fT}{\compile{s}, \funT{\betaT}{\SizeT}{\funT{\betaT^*}{\betaT \szltT \compile{s}}{\app{\wfacc}{\sigmaT}{\eT}{\betaT}{(\app{\accessible}{\betaT})}}}} \\
      &\phantom{=} \textit{by $\wfind$}
    \end{align*}
    The only difference between the left- and right-hand sides now
    is the proof of $\app{\AccT}{\betaT}$ for some $\betaT \szltT \compile{s}$,
    but we know that such proofs are propositionally equal to one another.
    From inversion, we know that $\compile{s}$ is well typed with type $\SizeT$.
    Then we can show that
    \begin{align*}
    &\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\betaT}{\SizeT}, \annotT{\betaT^*}{\betaT \szltT \compile{s}}}{\app{\accIsProp}{\betaT}{(\matchT*{\app{\accessible}{\compile{s}}}{(\app{\accT}{\pT} \Rightarrow \app{\pT}{\betaT}{\betaT^*})})}{(\app{\accessible}{\betaT})}}{\\
    &\phantom{\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\betaT}{\SizeT}, \annotT{\betaT^*}{\betaT \szltT \compile{s}}}{}{}}
    \eq{\matchT*{\app{\accessible}{\compile{s}}}{(\app{\accT}{\pT} \Rightarrow \app{\pT}{\betaT}{\betaT^*})}}{\app{\AccT}{\betaT}}{\app{\accessible}{\betaT}}}.
    \end{align*}
    By \rref{equiv-reflect}, we have
    \begin{align*}
    &\defeq{\compile{\Phi}, \compile{\Gamma}, \annotT{\betaT}{\SizeT}, \annotT{\betaT^*}{\betaT \szltT \compile{s}}}{\matchT*{\app{\accessible}{\compile{s}}}{(\app{\accT}{\pT} \Rightarrow \app{\pT}{\betaT}{\betaT^*})}}{\app{\accessible}{\betaT}}{\app{\AccT}{\betaT}}.
    \end{align*}
    Finally, by \rref{equiv-cong}, we can equate the left- and right-hand sides,
    and by \rref{equiv-conv}, we obtain our goal.
    \begin{align*}
    \defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\App{(\fix{f}{\alpha}{\sigma}{e})}{s}}}{\compile{\subst{e}{\alpha, f}{s, \Fun<{\beta}{s}{\App{(\fix{f}{\alpha}{\sigma}{e})}{\beta}}}}}{\tauT}
    \end{align*}
  \item \rref*{red-cong}.
    The various congruence cases are all similar to one another.
    I cover only reduction of the bound expression in $\kw{let}$ expressions as a representative case.
    \begin{mathpar}
    \inferrule{
      \red{\Phi; \Gamma}{e_1}{e'_1}
    }{
      \red{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\letin{x}{\sigma}{e'_1}{e_2}}
    }
    \end{mathpar}
    By inversion on $\type{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\tau}$
    and on $\type{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}}}{\tauT}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\sigma}{U}$,
      \item $\type{\Phi; \Gamma}{e_1}{\sigma}$,
      \item $\type{\Phi; \Gamma, \define{x}{\sigma}{e_1}}{e_2}{\tau'}$,
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e_1}}{\tau}$;
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{\sigma}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma}}{\compile{e_1}}}{\compile{e_2}}{\tauT'}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\compile{e_1}}}{\tauT}$.
    \end{itemize}
    By the induction hypothesis, we have
    $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{e'_1}}{\compile{\sigma}}$.
    Meanwhile, by \rref{equiv-refl}, we have
    \begin{itemize}[noitemsep]
      \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{\sigma}}{\UT}$ and
      \item $\defeq{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma}}{\compile{e_1}}}{\compile{e_2}}{{\compile{e_2}}{\tauT'}}$.
    \end{itemize}
    Then by \rref{equiv-cong}, we have
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}}}{\letinT{\xT}{\compile{\sigma}}{\compile{e'_1}}{\compile{e_2}}}{\subst{\tauT'}{\xT}{\compile{e_1}}}.$$
    Finally, by \rref{equiv-conv}, we obtain our goal.
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}}}{\letinT{\xT}{\compile{\sigma}}{\compile{e'_1}}{\compile{e_2}}}{\tauT}$$
    In general, the proof procedure is to invert on both typing derivations,
    apply the induction hypothesis, construct the goal up to the type annotation via \rref{equiv-cong},
    and finally fix the type annotation using \rref{equiv-conv}.
    \qedhere
\end{itemize}
\end{proof}

\subsection{Preservation of closure of reduction}

The proof of preservation for reduction closed under reflexivity and transitivity is relatively straightforward,
since most of the work was done in the preservation proof for reduction itself.
This, too, requires well-typedness of the translated term as a premise to apply preservation of reduction.

\begin{lemma}[Preservation of reflexive, transitive closure of reduction] \label{lem:pres-red*}
Suppose we have the following:
\begin{itemize}[noitemsep]
  \item $\red*{\Phi; \Gamma}{e}{e'}$,
  \item $\type{\Phi; \Gamma}{e}{\tau}$, and
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\tauT}$.
\end{itemize}
Then $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{e'}}{\tauT}$,
where \nameref{thm:subject-reduction} gives us $\type{\Phi; \Gamma}{e'}{\tau}$
in order to translate $\compile{e'}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red*{\Phi; \Gamma}{e}{e'}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{red*-once}. By \nameref{lem:pres-red}.
  \item \rref*{red*-refl}. Trivial by \rref{equiv-refl}.
  \item \rref*{red*-trans}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \red*{\Phi; \Gamma}{e}{e'} \\
      \red*{\Phi; \Gamma}{e'}{e''} \\
    }{
      \red*{\Phi; \Gamma}{e}{e''}
    }
    \end{mathpar}
    By the induction hypothesis on the first premise,
    we have $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{e'}}{\tauT}$.
    By \nameref{thm:subject-reduction} and \nameref{thm:subject-equivalence}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{e'}{\tau}$ and
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e'}}{\tauT}$.
    \end{itemize}
    Then we can apply the induction hypothesis on the second premise to yield
    $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e'}}{\compile{e''}}{\tauT}$.
    Finally, by \rref{equiv-trans}, we have
    $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{e''}}{\tauT}$. \qedhere
  \iffalse
  \item \rref*{red*-cong}.
    The various congruence cases are all similar to one another;
    I cover only \rref{let} as a representative case.
    \begin{mathpar}
    \inferrule{
      \red*{\Phi; \Gamma}{\sigma}{\sigma'} \\
      \red*{\Phi; \Gamma}{e_1}{e'_1} \\
      \red*{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{e_2}{e'_2}
    }{
      \red*{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\letin{x}{\sigma'}{e'_1}{e'_2}}
    }
    \end{mathpar}
    By inversion on $\type{\Phi; \Gamma}{\letin{x}{\sigma}{e_1}{e_2}}{\tau}$
    and on $\type{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}}}{\compile{\tau}}$,
    we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma}{\sigma}{U}$,
      \item $\type{\Phi; \Gamma}{e_1}{\sigma}$,
      \item $\type{\Phi; \Gamma, \define{x}{\sigma}{e_1}}{e_2}{\tau'}$,
      \item $\subtype{\Phi; \Gamma}{\subst{\tau'}{x}{e_1}}{\tau}$;
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{\sigma}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma}}{\compile{e_1}}}{\compile{e_2}}{\tauT'}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\compile{e_1}}}{\tauT}$.
    \end{itemize}
    Applying the induction hypothesis to the first and second premises, we have
    \begin{itemize}[noitemsep]
      \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{\sigma'}}{\UT}$ and
      \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{e'_1}}{\compile{\sigma}}$.
    \end{itemize}
    By \rref{red*-refl, acum-refl, subtype-red}, we have $\subtype{\Phi; \Gamma}{\sigma}{\sigma'}$.
    Then by \nameref{lem:replacement-subtyping} and \nameref{lem:replacement-reduction},
    we have $\type{\Phi; \Gamma, \define{x}{\sigma'}{e'_1}}{e_2}{\tau'}$.
    Similarly, by \rref{subtype-conv}, we have $\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{\sigma'}}$,
    and by \nameref{lem:replacement-subtyping*} and \nameref{lem:replacement-equivalence},
    we have $\type{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma'}}{\compile{e'_1}}}{\compile{e_2}}{\tauT'}$.
    This lets us to apply the induction hypothesis to the third premise,
    yielding $\defeq{\compile{\Phi}, \compile{\Gamma}, \defineT{\xT}{\compile{\sigma'}}{\compile{e'_1}}}{\compile{e_2}}{\compile{e'_2}}{\tauT'}$.
    By \rref{subtype-conv, equiv-conv, equiv-cong} and \nameref{thm:transitivity-subtyping}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e_1}}{\compile{\sigma'}}$,
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\compile{e'_1}}}{\subst{\tauT'}{\xT}{\compile{e_1}}}$, and
      \item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\subst{\tauT'}{\xT}{\compile{e'_1}}}{\tauT}$.
    \end{itemize}
    Finally, by \rref{equiv-cong, equiv-conv}, we have
    $$\defeq{\compile{\Phi}, \compile{\Gamma}}{\letinT{\xT}{\compile{\sigma}}{\compile{e_1}}{\compile{e_2}}}{\letinT{\xT}{\compile{\sigma'}}{\compile{e'_1}}{\compile{e'_2}}}{\tauT}.$$
  \fi
\end{itemize}
\end{proof}

\subsection{Preservation of \texorpdfstring{$\alpha$}{alpha}-cumulativity}

This lemma is proven independently of compositionality and preservation of (closure of) reduction.
Like preservation of reduction, the well-typedness of the translation of the $\alpha$-cumulative\index{$\alpha$-cumulativity} terms
is required to derive various equivalences,
but their types need not even be the same,
since the \CICE subtyping judgement itself is untyped.

\begin{lemma}[Preservation of $\alpha$-cumulativity] \label{lem:pres-acum}
Suppose we have the following:
\begin{itemize}[noitemsep]
  \item $\acum{\tau_1}{\tau_2}$,
  \item $\type{\Phi; \Gamma}{\tau_1}{U_1}$,
  \item $\type{\Phi; \Gamma}{\tau_2}{U_2}$,
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\UT_1}$, and
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_2}}{\UT_2}$.
\end{itemize}
Then $\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\compile{\tau_2}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\acum{\tau_1}{\tau_2}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{acum-refl}.
    Trivial by \rref{equiv-refl, subtype-conv} using well-typedness of the translated term.
  \item[\textbf{Cases}] \rref*{acum-prop}, \rref*{acum-type}.
    Trivial by \rref{subtype-prop} and \rref{subtype-type}, respectively.
  \item \rref{acum-pi}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \acum{\tau_1}{\tau_2}
    }{
      \acum{\funtype{x}{\sigma}{\tau_1}}{\funtype{x}{\sigma}{\tau_2}}
    }
    \end{mathpar}
    By inversion on $\type{\Phi; \Gamma}{\funtype{x}{\sigma}{\tau_i}}{U_i}$ and on
    $\type{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\xT}{\compile{\sigma}}{\compile{\tau_i}_{\annot{x}{\sigma}}}}{\compile{U_i}}$
    for $i = 1, 2$, omitting unneeded judgements, we have
    \begin{itemize}[noitemsep]
      %\item $\type{\Phi; \Gamma}{\sigma}{U'}$,
      \item $\type{\Phi; \Gamma, \annot{x}{\sigma}}{\tau_i}{U''_i}$,
      %\item $\subtype{\Phi; \Gamma}{\rules{U'}{U''_i}}{U'_i}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\UT'}$, and
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\compile{\sigma}}}{\compile{\tau_i}_{\annot{x}{\sigma}}}{\UT''_i}$.
      %\item $\subtype{\compile{\Phi}, \compile{\Gamma}}{\rules{\UT'}{\UT''_i}}{\UT_i}$.
    \end{itemize}
    By the induction hypothesis on the premise using the above, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\compile{\sigma}}}{\compile{\tau_1}_{\annot{x}{\sigma}}}{\compile{\tau_2}_{\annot{x}{\sigma}}}$.
    By \rref{equiv-refl}, we have $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{\sigma}}{\UT'}$.
    Then by \rref{subtype-pi}, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\xT}{\compile{\sigma}}{\compile{\tau_1}_{\annot{x}{\sigma}}}}{\funtypeT{\xT}{\compile{\sigma}}{\compile{\tau_2}_{\annot{x}{\sigma}}}}$.
  \item \rref{acum-forall}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \acum{\tau_1}{\tau_2}
    }{
      \acum{\Funtype{\alpha}{\tau_1}}{\Funtype{\alpha}{\tau_2}}
    }
    \end{mathpar}
    By inversion on $\type{\Phi; \Gamma}{\Funtype{\alpha}{\tau_i}}{U_i}$ and on
    $\type{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\compile{\tau_i}_{\alpha}}}{\UT_i}$
    for $i = 1, 2$, omitting unneeded judgements, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi, \alpha; \Gamma}{\tau_i}{U''_i}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\UT'}$, and
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\compile{\tau_i}_{\alpha}}{\UT''_i}$.
    \end{itemize}
    By the induction hypothesis on the premise using the above, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\compile{\tau_1}_{\alpha}}{\compile{\tau_2}_{\alpha}}$.
    By \rref{equiv-refl}, we have $\defeq{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\SizeT}{\UT'}$.
    Then by \rref{subtype-pi}, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\compile{\tau_1}_{\alpha}}}{\funtypeT{\alphaT}{\SizeT}{\compile{\tau_2}_{\alpha}}}$.
  \item \rref{acum-forall<}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \acum{\tau_1}{\tau_2}
    }{
      \acum{\Funtype<{\alpha}{s}{\tau_1}}{\Funtype<{\alpha}{s}{\tau_2}}
    }
    \end{mathpar}
    By inversion on $\type{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\tau_i}}{U_i}$ and on
    $\type{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\funtypeT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{\tau_i}_{\bound{\alpha}{s}}}}}{\UT_i}$
    for $i = 1, 2$, omitting unneeded judgements, we have
    \begin{itemize}[noitemsep]
      \item $\type{\Phi; \Gamma, \bound{\alpha}{s}}{\tau_i}{U''_I}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\UT'}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\alphaT \szltT \compile{s}}{\UT''}$, and
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{s}}}{\compile{\tau_i}_{\bound{\alpha}{s}}}{\UT'''_i}$.
    \end{itemize}
    By the induction hypothesis on the premise using the above, we have
    $\subtype{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{s}}}{\compile{\tau_1}_{\bound{\alpha}{s}}}{\compile{\tau_2}_{\bound{\alpha}{s}}}$.
    By \rref{equiv-refl}, we have $\defeq{\compile{\Phi}, \compile{\Gamma}}{\SizeT}{\SizeT}{\UT'}$
    and $\defeq{\compile{\Phi}, \compile{\Gamma}, \annotT{\alphaT}{\SizeT}}{\alphaT \szltT \compile{s}}{\alphaT \szltT \compile{s}}{\UT''}$.
    Then by \rref{subtype-pi} twice, we have
    $$\subtype{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\funtypeT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{\tau_1}_{\bound{\alpha}{s}}}}}{\funtypeT{\alphaT}{\SizeT}{\funtypeT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{\tau_2}_{\bound{\alpha}{s}}}}}.$$
    \qedhere
\end{itemize}
\end{proof}

\subsection{Preservation of subtyping}

Most of the heavy lifting in proving preservation of subtyping\index{subtyping} is done by
preservation of $\alpha$-cumulativity and preservation of the closure of reduction.

\begin{lemma}[Preservation of subtyping] \label{lem:pres-subtyping}
Suppose we have the following:
\begin{itemize}[noitemsep]
  \item $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$,
  \item $\type{\Phi; \Gamma}{\tau_1}{U}$,
  \item $\type{\Phi; \Gamma}{\tau_2}{U}$,
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\compile{U}}$, and
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_2}}{\compile{U}}$.
\end{itemize}
Then $\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\compile{\tau_2}}$.
\end{lemma}

\begin{proof}
By cases on the derivation of $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$,
there being only one case.
\begin{mathpar}
\inferrule{
  \red*{\Phi; \Gamma}{\tau_1}{\sigma_1} \\
  \red*{\Phi; \Gamma}{\tau_2}{\sigma_2} \\
  \acum{\sigma_1}{\sigma_2}
}{
  \subtype{\Phi; \Gamma}{\tau_1}{\tau_2}
}
\end{mathpar}
By \rref{conv, conv*}, we have both $\type{\Phi; \Gamma}{U}{\axioms{U}}$
and $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{U}}{\compile{\axioms{U}}}$.
Then \hyperref[lem:pres-red*]{Preservation of closure of reduction} on the first two premises yields
\begin{itemize}[noitemsep]
  \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\compile{\sigma_1}}{\compile{U}}$ and
  \item $\defeq{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_2}}{\compile{\sigma_2}}{\compile{U}}$.
\end{itemize}
By \nameref{thm:subject-reduction} and \nameref{thm:subject-equivalence}, we have
\begin{itemize}[noitemsep]
  \item $\type{\Phi; \Gamma}{\sigma_1}{U}$,
  \item $\type{\Phi; \Gamma}{\sigma_2}{U}$,
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma_1}}{\compile{U}}$, and
  \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma_2}}{\compile{U}}$.
\end{itemize}
Using the above and the final premise, by \nameref{lem:pres-acum}, we have
$\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma_1}}{\compile{\sigma_2}}$.
Then by \rref{equiv-sym, subtype-conv, subtype-trans}, we have
$\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau_1}}{\compile{\tau_2}}$.
\end{proof}

\subsection{Type preservation}

At last we are able to prove type preservation\index{type preservation},
using preservation of subtyping in the \rref*{conv} case
and preservation of sizes and subsizing,
which are proven independently.

\begin{lemma}[Preservation of sizes] \label{lem:pres-size}
\begin{enumerate}[noitemsep]\hfill
  \item If $\wf{}{\Phi}$ then $\wf{}{\compile{\Phi}}$; and
  \item If $\wf{\Phi}{s}$ then $\type{\compile{\Phi}}{\compile{s}}{\SizeT}$.
\end{enumerate}
\end{lemma}

\begin{proof}
By mutual induction on the derivations of $\wf{}{\Phi}$ and $\wf{\Phi}{s}$.
\begin{enumerate}[noitemsep]
  \item %
    \begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
      \item \rref*{nil}. Trivial.
      \item \rref*{cons-size}. By the induction hypothesis and \rref{ind, cons*-ass}.
      \item \rref*{cons-size<}. By the induction hypotheses and \rref{ind, cons*-ass}.
    \end{itemize}
  \item %
    \begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
      \item $\wf{\Phi}{\alpha}$. By the induction hypothesis and \rref{var*}.
      \item $\wf{\Phi}{\circ}$. By the induction hypothesis and well-typedness of $\baseT$.
      \item $\wf{\Phi}{\sss{s}}$. By the induction hypothesis and \rref{constr}. \qedhere
    \end{itemize}
\end{enumerate}
\end{proof}

\begin{lemma}[Preservation of subsizing] \label{lem:pres-subsize}
If $\subsizeto{\Phi}{r}{s}{\eT}$ then $\type{\compile{\Phi}}{\eT}{\compile{r} \szleT \compile{s}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\subsizeto{\Phi}{r}{s}{\eT}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item $\subsizeto{\Phi}{\sss{\alpha}}{s}{\alphaT^*}$.
    By definition of the translation,
    $(\annotT{\alphaT^*}{\alphaT \szltT \compile{s}}) \in \compile{\Phi}$,
    so $\type{\compile{\Phi}}{\alphaT^*}{\alphaT \szltT \compile{s}}$ by
    the induction hypothesis and \rref{var*}.
  \item $\subsizeto{\Phi}{\circ}{s}{\app{\baseleq}{\compile{s}}}$.
    By the induction hypothesis and well-typedness of $\baseleq$.
  \item $\subsizeto{\Phi}{s}{s}{\app{\reflleq}{\compile{s}}}$.
    By the induction hypothesis and well-typedness of $\reflleq$.
  \item $\subsizeto{\Phi}{s}{\sss{s}}{\app{\sucleq}{\compile{s}}}$.
    By the induction hypothesis and well-typedness of $\sucleq$.
  \item \textbf{for monotonicity}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \subsizeto{\Phi}{r}{s}{\eT}
    }{
      \subsizeto{\Phi}{\sss{r}}{\sss{s}}{\app{\monoT}{\compile{r}}{\compile{s}}{\eT}}
    }
    \end{mathpar}
    By the induction hypothesis,
    $\type{\compile{\Phi}}{\eT}{\compile{r} \szleT \compile{s}}$.
    Then $\type{\compile{\Phi}}{\app{\monoT}{\compile{r}}{\compile{s}}{\eT}}{\app{\sucT}{\compile{r}} \szleT \app{\sucT}{\compile{s}}}$
    by \rref{constr}.
  \item \textbf{for transitivity}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \subsizeto{\Phi}{s_1}{s_2}{\eT_{12}} \\
      \subsizeto{\Phi}{s_2}{s_3}{\eT_{23}}
    }{
      \subsizeto{\Phi}{s_1}{s_3}{\app{\transleq}{\compile{s_1}}{\compile{s_2}}{\compile{s_3}}{\eT_{12}}{\eT_{23}}}
    }
    \end{mathpar}
    By the induction hypotheses,
    $\type{\compile{\Phi}}{\eT_{12}}{\compile{s_1} \szleT \compile{s_2}}$ and
    $\type{\compile{\Phi}}{\eT_{23}}{\compile{s_2} \szleT \compile{s_3}}$.
    Then $\type{\compile{\Phi}}{\app{\transleq}{\compile{s_1}}{\compile{s_2}}{\compile{s_3}}{\eT_{12}}{\eT_{23}}}{\compile{s_1} \szleT \compile{s_3}}$
    by well-typedness of $\transleq$. \qedhere
\end{itemize}
\end{proof}

\begin{theorem}[Type preservation] \label{thm:pres-typing} \hfill
\begin{enumerate}[noitemsep]
  \item If $\wf{\Phi}{\Gamma}$ then $\wf{}{\compile{\Phi}, \compile{\Gamma}}$; and
  \item If $\type{\Phi; \Gamma}{e}{\tau}$ then $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{\tau}}$.
\end{enumerate}
\end{theorem}

\begin{proof}
By mutual induction on the derivations of
$\wf{\Phi}{\Gamma}$ and $\type{\Phi; \Gamma}{e}{\tau}$.
\begin{itemize}[noitemsep, label=\textbf{Case}, leftmargin=*, labelindent=\parindent]
  \item \rref*{nil}. Trivial by \cref*{lem:wf-env-size} and \nameref{lem:pres-size}.
  \item \rref*{cons-ass}. By the induction hypotheses and \rref{cons*-ass}.
  \item \rref*{cons-def}. By the induction hypotheses and \rref{cons*-def}.
  \item \rref*{conv}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \infer{\Phi; \Gamma}{e}{\sigma} \\
      \check{\Phi; \Gamma}{\sigma}{U} \\
      \infer{\Phi; \Gamma}{\tau}{U} \\
      \subtype{\Phi; \Gamma}{\sigma}{\tau}
    }{
      \check{\Phi; \Gamma}{e}{\tau}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{\sigma}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{U}}$, and
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{\tau}}{\compile{U}}$.
    \end{itemize}
    By \nameref{lem:pres-subtyping} on the last premise,
    we have $\subtype{\compile{\Phi}, \compile{\Gamma}}{\compile{\sigma}}{\compile{\tau}}$.
    Then by \rref{conv*}, we have $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\compile{\tau}}$.
  \item \rref*{var}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \wf{\Phi}{\Gamma} \\
      (\annot{x}{\tau}) \in \Gamma
      \textit{ or }
      (\define{x}{\tau}{e}) \in \Gamma
    }{
      \infer{\Phi; \Gamma}{x}{\tau}
    }
    \end{mathpar}
    Induction hypothesis: $\wf{}{\compile{\Phi}, \compile{\Gamma}}$. \\
    By definition of the translation, we have
    $(\annotT{\xT}{\compile{\tau}}) \in \compile{\Gamma}$ or
    $(\defineT{\xT}{\compile{\tau}}{\compile{e}}) \in \compile{\Gamma}$,
    so by \rref{var*}, we have
    $\type{\compile{\Phi}, \compile{\Gamma}}{\xT}{\compile{\tau}}$.
  \item[\textbf{Cases}] \rref*{univ}, \rref*{pi}, \rref*{lam}, \rref*{app}, \rref*{let}.
    Straightforward by their induction hypotheses and \rref{univ*, pi*, lam*, app*, let*}.
  \item \rref{forall<}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \wf{\Phi}{s} \\
      \type{\Phi, \bound{\alpha}{s}; \Gamma}{\tau}{U}
    }{
      \type{\Phi; \Gamma}{\Funtype<{\alpha}{s}{\tau}}{U}
    }
    \end{mathpar}
    Induction hypothesis: $\type{\compile{\Phi}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{s}}, \compile{\Gamma}}{\compile{\tau}}{\compile{U}}$. \\
    By \nameref{lem:pres-size}, we have $\type{\compile{\Phi}}{\compile{s}}{\SizeT}$.
    If $\compile{U} = \TypeT{\iT}$ for some $\iT \geq 1$,
    we have $\type{\compile{\Phi}}{\SizeT}{\compile{U}}$
    and $\type{\compile{\Phi}, \annotT{\alphaT}{\SizeT}}{\alphaT \szltT \compile{s}}{\compile{U}}$
    by \rref{ind, app*},
    so we have $\type{\compile{\Phi}, \compile{\Gamma}}{\funtypeT{\alphaT}{\SizeT}{\funtypeT{\alphaT^*}{\alphaT \szltT \compile{s}}{\compile{\tau}}}}{\compile{U}}$
    by \rref{pi*} twice.
    If $U = \Prop$, $\SizeT$ and $\alphaT \szltT \compile{s}$
    can be typed as any $\TypeT{\iT}$ where $\iT \geq 1$,
    and we still have the goal by \rref{pi*}.
  \item \rref{forall, slam, slam<}. Similar to the case for \rref*{forall<}.
  \item \rref{sapp<}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \infer{\Phi; \Gamma}{e}{\Funtype<{\alpha}{r}{\tau}} \\
      \subsize{\Phi}{\sss{s}}{r}
    }{
      \infer{\Phi; \Gamma}{\App{e}{s}}{\subst{\tau}{\alpha}{s}}
    }
    \end{mathpar}
    Induction hypothesis: $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\funtypeT{\alphaT}{\SizeT}{\funtypeT{\alphaT^*}{\alphaT \szltT \compile{r}}{\compile{\tau}}}}$. \\
    Let $\subsizeto{\Phi}{\sss{s}}{r}{\eT}$.
    By \nameref{lem:pres-subsize}, we have $\type{\compile{\Phi}}{\eT}{\compile{\sss{s}} \szltT \compile{r}}$.
    By \cref{lem:wf-subsize} and \nameref{lem:pres-size}, we have
    $\type{\compile{\Phi}}{\compile{\sss{s}}}{\SizeT}$ and $\type{\compile{\Phi}}{\compile{r}}{\SizeT}$.
    Then by \rref{app*} twice, we have
    $\type{\compile{\Phi}, \compile{\Gamma}}{\app{\compile{e}}{\compile{s}}{\eT}}{\subst{\compile{\tau}}{\alphaT, \alphaT^*}{\compile{s}, \eT}}$.
    Finally, by \nameref{lem:compos-size-bounded},
    the type is equal to $\compile{\subst{\tau}{\alpha}{s}}$ as desired.
  \item[\textbf{Cases}] \rref{zero, succ, sup}. Similar to the case for \rref*{sapp<}.
  \item[\textbf{Cases}] \rref{sapp, nat, wft}. Similar to the case for \rref*{sapp<},
    using only \nameref{lem:pres-size} without \nameref{lem:pres-subsize},
    and \nameref{lem:compos-size-unbounded} in place of \nameref{lem:compos-size-bounded}.
  \item \rref*{case-nat}.
    \setlength{\jot}{-1.5pt}
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \infer{\Phi; \Gamma}{e}{\N{s}} \\
      \infer{\Phi; \Gamma, \annot{x}{\N{s}}}{P}{U} \\
      \check{\Phi, \bound{\alpha}{s}; \Gamma}{e_z}{\subst{P}{x}{\zero{s}{\alpha}}} \\
      \check{\Phi, \bound{\beta}{s}; \Gamma, \annot{z}{\N{\beta}}}{e_s}{\subst{P}{x}{\succ{s}{\beta}{z}}}
    }{
      \infer{\Phi; \Gamma}{\match{e}{\fun*{x}{P}}{(\App{\zero*}{\alpha} \Rightarrow e_z)(\app{\App{\succ*}{\beta}}{z} \Rightarrow e_s)}}{\subst{P}{x}{e}}
    }
    \end{mathpar}
    Induction hypotheses (using \nameref{lem:term-compositionality} in the types of the last two):
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\compile{e}}{\app{\NatT}{\compile{s}}}$,
      \item $\type{\compile{\Phi}, \compile{\Gamma}, \annotT{\xT}{\app{\NatT}{\compile{s}}}}{\compile{P}}{\compile{U}}$,
      \item $\type{\compile{\Phi}, \annotT{\alphaT}{\SizeT}, \annotT{\alphaT^*}{\alphaT \szltT \compile{s}}, \compile{\Gamma}}{\compile{e_z}}{\subst{\compile{P}}{\xT}{\app{\zeroT}{\compile{s}}{\alphaT}{\alphaT^*}}}$, and
      \item $\type{\compile{\Phi}, \annotT{\betaT}{\SizeT}, \annotT{\betaT^*}{\betaT \szltT \compile{s}}, \compile{\Gamma}, \annotT{\zT}{\app{\NatT}{\betaT}}}{\compile{e_s}}{\subst{\compile{P}}{\xT}{\app{\succT}{\compile{s}}{\betaT}{\betaT^*}{\zT}}}$.
    \end{itemize}
    By \rref{case} and \nameref{lem:term-compositionality} once more, we have
    $$\type{\compile{\Phi}, \compile{\Gamma}}{
      \begin{aligned}
      &\matchT{\compile{e}}{\funT*{\mt}{\xT}{\compile{P}}}{ \\
      &\quad \app{\zeroT}{\alphaT}{\alphaT^*} \RightarrowT \compile{e_z} \\
      &\quad \app{\succT}{\betaT}{\betaT^*}{\zT} \RightarrowT \compile{e_s}}
      \end{aligned}
    }{\compile{\subst{P}{x}{e}}}$$
  \item \rref*{case-wft}. Similar to the case for \rref*{case-nat}.
  \item \rref*{fix}.
    \vspace{-\baselineskip}
    \begin{mathpar}
    \inferrule{
      \infer{\Phi, \alpha; \Gamma}{\sigma}{U} \\
      \fresh{\beta} \\
      \check{\Phi, \alpha; \Gamma, \annot{f}{\Funtype<{\beta}{\alpha}{\subst{\sigma}{\alpha}{\beta}}}}{e}{\sigma}
    }{
      \infer{\Phi; \Gamma}{\fix{\fT}{\alpha}{\sigma}{e}}{\Funtype{\alpha}{\sigma}}
    }
    \end{mathpar}
    Induction hypotheses:
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \annotT{\alphaT}{\SizeT}, \compile{\Gamma}}{\compile{\sigma}}{\compile{U}}$ and
      \item $\type{\compile{\Phi}, \annotT{\alphaT}{\SizeT}, \compile{\Gamma}, \annotT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}}{\compile{e}}{\compile{\sigma}}$.
    \end{itemize}
    By \rref{ind, lam*}, we have
    \begin{itemize}[noitemsep]
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\alphaT}{\SizeT}{\compile{\sigma}}}{\arrT*{\SizeT}{\compile{U}}}$ and
      \item $\type{\compile{\Phi}, \compile{\Gamma}}{\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}{\compile{e}}}}{\funtypeT{\alphaT}{\SizeT}{\arrT*{(\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}})}{\compile{\sigma}}}}$.
    \end{itemize}
    Let $\eT$ be $\funT{\alphaT}{\SizeT}{\funT{\fT}{\funtypeT{\betaT}{\SizeT}{\arrT*{\betaT \szltT \alphaT}{\subst{\compile{\sigma}}{\alphaT}{\betaT}}}}{\compile{e}}}$.
    By \rref{app*} twice, we then have
    $\type{\compile{\Phi}, \compile{\Gamma}}{\app{\wfind}{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\eT}}{\funtypeT{\alphaT}{\SizeT}{\app{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\alphaT}}}$.
    By \rref{equiv-beta, equiv-cong, subtype-conv}, we have
    $\defeq{\compile{\Phi}, \compile{\Gamma}}{\app{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\alphaT}}{\funtypeT{\alphaT}{\SizeT}{\compile{\sigma}}}{\compile{U}}$.
    Then finally, by \rref{conv*}, we have
    $\type{\compile{\Phi}, \compile{\Gamma}}{\app{\wfind}{(\funT{\alphaT}{\SizeT}{\compile{\sigma}})}{\eT}}{\funtypeT{\alphaT}{\SizeT}{\compile{\sigma}}}$.
    \qedhere
\end{itemize}
\end{proof}