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

\glssymboldefn{toe}%
Comment: $\lambda x : \sigma . (Mx) \to_\eta M$ if $x$ is
not free in $M$.

\begin{fcprop}[Curry-Howard for IPC(->)]
  % Proposition 1.3.1
  Assuming:
  - $\Gamma$ is a \gls{cont} for $\lto$
  - $\varphi$ a proposition
  Thens:[(1)]
  - If $\Gamma \trel M : \varphi$, then
  $\range \Gamma = \{\tau \in \stypes : (x :
  \tau) \in \Gamma \text{ for some $x$}\}
  \syn_{\text{IPC($\to$)}} \varphi$
  - If $\range \Gamma \syn_{\text{IPC($\to$)}}
  \varphi$,
  then there is a \gls{stlterm} $M \in \lto$
  such that $\{(x_\psi : \psi) \st
  \psi \in \Gamma\} \trel M : \varphi$.
\end{fcprop}

\begin{proof}
  \phantom{}
  \begin{enumerate}[(1)]
    \item We induct over the derivation of $\Gamma
      \trel M : \varphi$.

      If $x$ is a variable not occurring in
      $\Gamma'$ and the derivation is of the form
      $\Gamma', x : \varphi \trel x : \varphi$,
      then we're supposed to prove that
      $\range{\Gamma', x : \varphi} \syn \varphi$.
      But that follows from $\varphi \syn \varphi$
      as $\range{\Gamma', x : \varphi} =
      \range{\Gamma'} \cup \{\varphi\}$.

      If the derivation has $M$ of the form
      $\lambda x : \sigma . N$ and $\varphi =
      \sigma \to \tau$, then we must have $\Gamma,
      x : \sigma \trel N : \tau$. By the induction
      hypothesis, we have that $\range{\Gamma, x :
      \sigma} \syn \tau$, i.e. $\range{\Gamma},
      \sigma \syn \tau$. But then $\range{\Gamma}
      \syn \sigma \to \tau$ by ($\to$-I).

      If the derivation has the form $\Gamma \trel
      (PQ) : \varphi$, then we must have $\Gamma
      \trel P : (\sigma \to \varphi)$ and $\Gamma
      \trel Q : \sigma$. By the induction
      hypothesis, we have that $\range{\Gamma}
      \syn \sigma \to \varphi$ and $\range{\Gamma}
      \syn \sigma$, so $\range{\Gamma} \syn
      \varphi$ by ($\to$-E).
    \item Again, we induct over the derivation of
      $\Gamma \syn \varphi$. Write $\Delta =
      \{(x_\psi : \psi) \st \psi \in \Gamma\}$.
      Then we only have a few ways to construct a
      proof at a given stage. Say the derivation
      is of the form $\Gamma, \varphi \syn
      \varphi$. If $\varphi \in \Gamma$, then
      clearly $\Delta \trel x_\varphi : \varphi$,
      and if $\varphi \notin \Gamma$ then $\Delta,
      x_\varphi : \varphi \trel x_\varphi :
      \varphi$.

      Suppose the derivation is at a stage of the
      form
      \[
        \frac{\Gamma \syn \varphi \to \psi ~~
        \Gamma \syn \varphi}{\Gamma \syn \psi}
      .\]
      Then by the induction hypothesis, there are
      \glspl{lterm} $M$ and $N$ such that $\Delta
      \trel M : (\varphi \to \psi)$ and $\Delta
      \trel N : \varphi$, from which $\Delta \trel
      (MN) : \varphi$.

      Finally, if the stage is given by
      \[
        \frac{\Gamma, \varphi \syn \psi}{\Gamma
        \syn \varphi \to \psi}
      ,\]
      then we have two sub-cases:
      \begin{itemize}
        \item If $\varphi \in \Gamma$, then the
          induction hypothesis gives $\Delta \trel
          M : \psi$ for some term $M$. By
          weakening, we have $\Delta, x : \varphi
          \trel M : \psi$, where $x$ does not
          occur in $\Delta$. But then $\Delta
          \trel (\lambda x : \varphi . M) :
          (\varphi \to \psi)$ as needed.
        \item If $\varphi \notin \Gamma$, then the
          induction hypothesis gives $\Delta,
          x_\varphi : \varphi \trel M : \psi$ for
          some $M$, thus $\Delta \trel (\lambda
          x_\varphi : \varphi . M) : (\varphi \to
          \psi)$ as needed. \qedhere
      \end{itemize}
  \end{enumerate}
\end{proof}

\begin{example}
  % Example 1.3.2
  Let $\varphi, \psi$ be primitive propositions.
  The \gls{lterm}
  \[
    \lambda f : (\varphi \to \psi) \to \varphi .
    \lambda : \varphi \to \psi .
    \ob{g(\ub{fg}_{\varphi})}^{\psi}
  \]
  has type $((\varphi \to \psi) \to \varphi) \to
  ((\varphi \to \psi) \to \psi)$, and therefore
  encodes a proof of that proposition in
  \gls{ipc}($\to$).

  $g : \varphi \to \psi$, $f : (\varphi \to \psi)
  \to \varphi$.
  \begin{logicproof}
    g : \ass{\varphi \to \psi} \quad f : \ass{(\varphi
    \to \psi) \to \varphi}
    \\(toE)
    fg : \varphi \qquad g : \ass{\varphi \to \psi}
    \\(toE)
    g(fg) : \psi
    \\(toI, \varphi \to \psi)
    \lambda g . g(fg) : (\varphi \to \psi) \to
    \psi
    \\(toI, (\varphi \to \psi) \to \varphi)
    \lambda f . \lambda g . g(fg) : ((\varphi \to
    \psi) \to \varphi) \to ((\varphi \to \psi) \to
    \psi)
  \end{logicproof}
\end{example}

\begin{fcdefn}[Full STlambdaC]
  % Definition 1.3.3
  The types of the full simply typed
  $\lambda$-calculus are generated by the
  following grammar:
  \[
    \Pi \defeq U \mid \Pi \to \Pi \mid \Pi \times
    \Pi \mid \Pi + \Pi \mid 0 \mid 1
  ,\]
  where $U$ is a set of type variables (usually
  countable).

  Its terms are given by $\Lambda_\Pi$ given by:
  \[
    \Lambda_\Pi \defeq V | \lambda V : \Pi .
    \Lambda_\Pi \st \Lambda_\Pi \Lambda_\Pi |
    \Pi_1(\Lambda_\Pi) | \Pi_2(\Lambda_\Pi) |
    \iota_1(\Lambda_\Pi) | \iota_2(\Lambda_\Pi) |
    \case(\Lambda_\Pi; V . \Lambda_\Pi; V .
    \Lambda_\Pi) | * | !_\Pi \Lambda_\Pi
  ,\]
  where $V$ is an infinite set of variables, and
  $*$ is a constant.
\end{fcdefn}
