%! TEX root = LC.tex
% vim: tw=50
% 16/10/2024 11AM

\begin{fcdefn}[Simply typed lambda-term]
  % Definition 1.2.1
  \glssymboldefn{lterms}%
  \glsnoundefn{cont}{context}{contexts}%
  \glsnoundefn{lterm}{$\lambda$-term}{$\lambda$-terms}%
  \glsnoundefn{stlterm}{simply typed
  $\lambda$-term}{simply typed $\lambda$-terms}%
  \glsnoundefn{term}{term}{terms}%
  \glssymboldefn{range}%
  \glsnoundefn{lab}{$\lambda$-abstraction}{$\lambda$-abstractions}%
  \glsnoundefn{lapp}{$\lambda$-application}{$\lambda$-application}%
  The set $\Lambda_{\stypes}$ of simply typed
  $\lambda$-terms is defined by the grammar
  \[
    \Lambda_{\stypes} \defeq \ub{V}_{\text{variables}} |
    \ub{\lambda V : \stypes .
    \Lambda_{\stypes}}_{\text{$\lambda$-abstraction}} |
    \ub{\Lambda_{\stypes}
    \Lambda_{\stypes}}_{\text{$\lambda$-application}}
  .\]
  A \emph{context} is a set of pairs $\{x_1 :
  \tau_1, \ldots, x_n : \tau_n\}$ where the $x_i$
  are (distinct) variables and each $\tau_i \in
  \stypes$. We write $C$ for the set of all possible
  contexts. Given a context $\Gamma \in C$, we
  also write $\Gamma, x : \tau$ for the context
  $\Gamma \cup \{x : \tau\}$ (if $x$ does not
  appear in $\Gamma$).

  The domain of $\Gamma$ is the set of variables
  that occur in it, and the range $|\Gamma|$ is
  the set of \glspl{type} that it manifests.
\end{fcdefn}

\begin{fcdefn}[Typability relation]
  % Definition 1.2.2
  \glssymboldefn{trel}%
  \glsnoundefn{trel}{typability relation}{N/A}%
  We define the \emph{typability relation} $\Vdash
  \subseteq C \times \lterms \times \stypes$ via:
  \begin{cenum}[(1)]
    \item For every \gls{cont} $\Gamma$, and
      variable $x$ not occurring in $\Gamma$, and
      \gls{type} $\tau$, we have $\Gamma, x : \tau
      \Vdash x : \tau$.
    \item Let $\Gamma$ be a \gls{cont}, $x$ a
      variable not occurring in $\Gamma$, and let
      $\sigma, \tau \in \stypes$ be \glspl{type}, and $M$
      be a \gls{lterm}. If $\Gamma, x : \sigma
      \Vdash M : \tau$, then $\Gamma \Vdash
      (\lambda x : \sigma . M) : (\sigma \to
      \tau)$.
    \item Let $\Gamma$ be a context, $\sigma, \tau
      \in \stypes$ be types, and $M, N \in
      \lterms$ be \glspl{term}. If $\Gamma \Vdash
      M : (\sigma \to \tau)$ and $\Gamma \Vdash N
      : \sigma$, then $\Gamma \Vdash (MN) :
      \tau$.
  \end{cenum}
\end{fcdefn}

\begin{notation*}
  \glssymboldefn{lto}%
  We will refer to the $\lambda$-calculus of
  $\lterms$ with this \gls{trel} as
  $\lambda(\to)$.
\end{notation*}

\glsadjdefn{aleq}{$\alpha$-equivalent}{\glspl{term}}%
A variable $x$ occurring in a  \gls{lab} $\lambda
\underline{x} : \sigma . M$ is \emph{bound}, and
it is \emph{free} otherwise. We say that
\glspl{term} $M$ and $N$ are
\emph{$\alpha$-equivalent} if they differ only in the
names of the bound variables.

\glssymboldefn{subst}%
If $M$ and $N$ are \glspl{lterm} and $x$ is a
variable, then we define the \emph{substitution of
$N$ for $x$ in $M$} by:
\begin{itemize}
  \item $x[x \defeq N] = N$;
  \item $y[x \defeq N] = y$ if $x \neq y$;
  \item $(PQ)[x \defeq N] = P[x \defeq N] Q[x
    \defeq N]$ for \glspl{lterm} $P, Q$;
  \item $(\lambda y : \sigma . P)[x \defeq N] =
    \lambda y : \sigma . (P[x \defeq N])$, where
    $x \neq y$ and $y$ is not free in $N$.
\end{itemize}

\begin{fcdefn}[beta-reduction]
  % Definition 1.2.3
  \glssymboldefn{tob}%
  \glsnoundefn{red}{reduces}{NA}%
  \glsnoundefn{breduc}{$\beta$-reduction}{$\beta$-reductions}%
  \glsnoundefn{reduc}{reduction}{reductions}%
  The $\beta$-reduction relation is the smallest
  relation $\to_\beta$ on $\lterms$ closed under
  the following rules:
  \begin{citems}
    \item $(\lambda x : \sigma . P)Q \to_\beta
      P\subst[x \defeq Q]$,
    \item if $P \to_\beta P'$, then for all
      variables $x$ and types $\sigma \in
      \stypes$, we have $\lambda x : \sigma . P
      \to_\beta \lambda x : \sigma . P'$,
    \item $P \to_\beta P'$ and $z$ as a
      \gls{lterm}, then $PZ \to_\beta P' Z$ and
      $ZP \to_\beta ZP'$.
  \end{citems}
  We also define $\beta$-equivalence
  $\equiv_\beta$ as the smallest equivalence
  relation containing $\to_\beta$.
\end{fcdefn}

\begin{example}[Informal]
  % Example 1.2.4
  We have $(\lambda x : \Zbb . (\lambda y : \tau .
  x)) Z \tob (\lambda y : \tau . Z)$.
\end{example}

\glsnoundefn{bred}{$\beta$-redex}{$\beta$-redexes}%
\glsnoundefn{redex}{redex}{redexes}%
\glsnoundefn{bcont}{$\beta$-contraction}{$\beta$-contractions}%
When we reduce $(\lambda x : \sigma . P) Q$, the
term being reduced is called a $\beta$-redex, and
the result is its $\beta$-contraction.

\begin{fclemma}[Free variables lemma]
  % Lemma 1.2.5
  Assuming:
  - $\Gamma \trel M : \sigma$
  Thens:[(1)]
  - If $\Gamma \subseteq \Gamma'$, then
  $\Gamma' \trel M : \sigma$.
  - The free variables of $M$ occur in
  $\Gamma$.
  - There is a context $\Gamma^* \subseteq
  \Gamma$ comprising exactly the free
  variables in $M$, with $\Gamma^* \trel M :
  \sigma$.
\end{fclemma}

\noproof

\begin{proof}
  Exercise.
\end{proof}
