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

\glssymboldefn{uterms}%
\glsnoundefn{ulterm}{$\lambda$-term}{$\lambda$-terms}%
\glsnoundefn{uterm}{term}{terms}%
The terms of the untyped $\lambda$-calculus
$\Lambda$ are given by the grammar
\[
  \Lambda \defeq V \mid \lambda V . \Lambda \mid
  \Lambda \Lambda
,\]
where $V$ is a (countable) set of variables.

The notions we previously discussed
($\alpha$-equality, $\beta$-reduction,
$\eta$-reduction, etc) apply tit for tat.

\begin{example}
  % Example 2.1.2
  Let $\omega \defeq \lambda x . xx$ and $\Omega
  \defeq \omega \omega$. Then $\Omega = (\lambda x
  . xx) \omega \tob \omega \omega = \Omega$. This
  shows that we can have an infinite reduction
  chain of \glspl{ulterm}.
\end{example}

\textbf{Question:} If $M \tobev N$, $M \tobev N'$, do we
have $N \tobev M'$ and $N' \tobev M'$ for some
$M'$?

\textbf{Idea:} ``Simultaneously reduce'' all the
\glspl{redex} in $M$ to get a term $M^*$. This
might have new \glspl{redex}, so we can iterate
the process to get terms $M^{2*}, M^{3*}, \ldots$.

$M$ should reduce to $M^*$, so we have $M \tobev
M^* \tobev M^{2*}, \ldots$. We'll see that if $M$
reduces to $N$ in $k$ steps, then $N \tobev
M^{k*}$.

Using this, we will show (assuming $s \ge r$):
\begin{picmath}
  \begin{tikzcd}
    & M \ar[ld, "s\beta", swap] \ar[rd, "r\beta"] \\
    N_2 \ar[rdd, two heads, "\beta", swap]
    &
    & N_1 \ar[d, two heads, "\beta"] \\
    &
    & M^{r*} \ar[ld, two heads, "\beta"] \\
    & M^{s*}
  \end{tikzcd}
\end{picmath}

To get there, we want to build $M^*$ with two
properties:
\begin{enumerate}[(1)]
  \item $M \tobev M^*$;
  \item If $M \tobev N$, then $N \tobev M^*$.
\end{enumerate}

\begin{fcdefn}[Takahashi Translation]
  \glssymboldefn{tstar}%
  \glsnoundefn{tt}{Takahashi
  translation}{Takahashi translations}%
  % Definition 2.1.3
  The Takahashi translation $M^*$ of a
  \gls{ulterm} $M$ is recursively defined as
  follows:
  \begin{cenum}[(1)]
    \item $x^* \defeq x$, for $x$ a variable;
    \item If $M = (\lambda x . P) Q$ is a
      \gls{redex}, then $M^* \defeq P^*[x \defeq
      Q^*]$;
    \item If $M = PQ$ is a \gls{lapp}, then $M^*
      \defeq P^* Q^*$;
    \item If $M = \lambda x . P$ is a \gls{lab},
      then $M^* \defeq \lambda x . P^*$.
  \end{cenum}
  These rules are numbered by order of
  precedence, in case of ambiguity. We also
  define $M^{0*} \defeq M$ and $M^{(n + 1)*}
  \defeq (M^{n*})^*$.
\end{fcdefn}

Note that $M^{\tstar}$ is not necessarily in
\gls{bnf}, for example if $M = (\lambda x . xy)
(\lambda y . y)$, then
\[
  M^{\tstar} = (xy)^{\tstar} [x \defeq (\lambda y .
  y)^{\tstar}] = (xy)[x \defeq \lambda y . y] =
  (\lambda y . y) y
.\]

\begin{fclemma}[]
  \label{lemma:2.1.4}
  % Lemma 2.1.4
  Assuming:
  - $M$ and $N$ are \glspl{ulterm}
  Then:
  \begin{cenum}[(1)]
    \item $\FV(M^{\tstar}) \subseteq \FV(M)$;
    \item $M \tobev M^{\tstar}$;
    \item If $M \tob N$, then $N \tobev M^{\tstar}$.
  \end{cenum}
\end{fclemma}

\begin{proof}
  Induction over the structure of \glspl{ulterm}.
\end{proof}

\begin{fclemma}
  \label{lemma:2.1.5}
  % Lemma 2.1.5
  \gls{tt} preserves $\beta$-contraction:
  \[
    ((\lambda x . P) Q)^{\tstar} \tobev (P[x \defeq
    Q])^{\tstar}
  .\]
\end{fclemma}

\begin{proof}
  By definition, $((\lambda x . P) Q)^{\tstar} =
  P^*[x \defeq Q^*]$. By induction over the
  structure of $P$, we can check that:
  \begin{itemize}
    \item If $Q$is not a \gls{lab}, then
      $P^{\tstar[]} [x
      \defeq Q^{\tstar}] = (P[x \defeq
      Q])^{\tstar}$,
    \item If $Q = \lambda y . Q_1$, then
      $P^{\tstar[]} [x \defeq (\lambda y .
      Q_1)^{\tstar}] \tobev (P[x \defeq \lambda y .
      Q_1])^{\tstar}$. \qedhere
  \end{itemize}
\end{proof}
