Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions content/lambda-calculus/church-rosser/beta-eta-reduction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
\olsection{$\beta\eta$-reduction}

The Church--Rosser property holds for
$\beta\eta$-reduction ($\bered$).
$\beta\eta$-reduction ($\bered$). Write $M\beredone N$ when either
$M\bredone N$ or $M\eredone N$; thus $\beredone$ is the union of the
two compatible one-step contraction relations.

\begin{lem}\ollabel{lem:one-par}
If $M \beredone M'$, then $M \beredpar M'$.
\end{lem}

\begin{proof}
By induction on the !!{derivation} of $M \beredone M'$. If $M \bredone
M'$ by $\eta$-conversion (i.e., \olref[syn][eta]{defn:beredone}), we
use \olref[pbe]{thm:refl}. The other cases are as in
\olref[b]{lem:one-par}.
Induct on the compatible one-step contraction derivation. For a
root $\eta$-contraction, $M=\lambd[x][Nx]$, $M'=N$, and
$x\notin\FV{N}$. Use $N\beredpar N$ from
\olref[pbe]{thm:refl}, followed by \olref[pbe]{defn:beredpar5}.
The root $\beta$ case and the abstraction and application contexts
are as in \olref[b]{lem:one-par}.
\end{proof}


Expand Down
11 changes: 9 additions & 2 deletions content/lambda-calculus/church-rosser/beta-reduction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
\begin{lem}\ollabel{lem:one-par}
If $M \bredone M'$, then $M \bredpar M'$.
\end{lem}
\begin{proof} If $M \bredone M'$, then $M$ is
\begin{proof}
Induct on the compatible one-step contraction derivation. In the
root-redex case, $M$ is
$(\lambd[x][N])Q$, $M'$ is $\Subst{N}{Q}{x}$, for some
$x$, $N$, and~$Q$. Since $N \bredpar N$ and $Q \bredpar Q$ by
\olref[pb]{thm:refl}, we immediately have $(\lambd[x][N])Q
\bredpar \Subst{N}{Q}{x}$ by \olref[pb]{defn:bredpar}\olref[pb]{defn:bredpar4}.
For a contraction inside an abstraction, lift the induction
hypothesis by \olref[pb]{defn:bredpar2}. For a contraction in either
child of an application, combine the induction hypothesis with
\olref[pb]{thm:refl} on the unchanged child and use
\olref[pb]{defn:bredpar3}.
\end{proof}

\begin{lem}\ollabel{lem:par-red}
Expand All @@ -40,7 +47,7 @@
by the reduction $Q \bred Q'$.
\item The last rule is \olref[pb]{defn:bredpar4}: $M$ is
$(\lambd[x][N])Q$ and $M'$ is $\Subst{N'}{Q'}{x}$ for some $x$,
$N$, $M'$, $Q$, $Q'$, where $N \bredpar N'$ and $Q \bredpar Q'$.
$N$, $N'$, $Q$, $Q'$, where $N \bredpar N'$ and $Q \bredpar Q'$.
By induction hypothesis we get $Q \bred Q'$ and $N \bred N'$. So
$(\lambd[x][N])Q \bred \Subst{N'}{Q'}{x}$ by $N \bred N'$ followed
by $Q \bred Q'$ and finally contraction of $(\lambd[x][N'])Q'$ to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
inductively defined as follows:
\begin{enumerate}
\item \ollabel{defn:beredpar1} $x \beredpar x$.
\item \ollabel{defn:beredpar2} If $N \xrightarrow{\beta} N'$ then $\lambd[x][N] \beredpar
\item \ollabel{defn:beredpar2} If $N \beredpar N'$ then $\lambd[x][N] \beredpar
\lambd[x][N']$.
\item \ollabel{defn:beredpar3} If $P \beredpar P'$ and $Q \beredpar Q'$ then $PQ \beredpar
P'Q'$.
Expand Down Expand Up @@ -47,7 +47,9 @@
as follows:
\begin{align}
\becd{x} &= x \ollabel{defn:becd1} \\
\becd{(\lambd[x][N])} &= \lambd[x][\becd{N}] \ollabel{defn:becd2}\\
\becd{(\lambd[x][N])} &= \lambd[x][\becd{N}]
&&\text{if $\lambd[x][N]$ is not an $\eta$-redex}
\ollabel{defn:becd2}\\
\becd{(PQ)} &= \becd{P}\becd{Q} && \text{if $P$ is not a $\lambd$-abstract}
\ollabel{defn:becd3} \\
\becd{((\lambd[x][N])Q)} &= \Subst{\becd{N}}{\becd{Q}}{x}
Expand All @@ -67,7 +69,7 @@

The first four cases are exactly like those in \olref[pb]{lem:comp}.
If the last rule is \olref{defn:beredpar5}, then $M$ is
$\lambd[x][Nx]$, $M'$ is $N'$ for some $x$ and~$N'$ where $x \notin
$\lambd[x][Nx]$, $M'$ is $N'$ for some $x$, $N$, and~$N'$ where $x \notin
FV(N)$, and $N \beredpar N'$. We want to show that
$\Subst{(\lambd[x][Nx])}{R}{y} \beredpar \Subst{N'}{R'}{y}$, i.e.,
$\lambd[x][\Subst{N}{R}{y} x] \beredpar \Subst{N'}{R'}{y}$. It
Expand All @@ -80,14 +82,52 @@
\end{lem}

\begin{proof}
By induction on the !!{derivation} of $M \beredpar M'$.

The first four cases are like those in \olref[pb]{lem:cont}. If the
last rule is \olref{defn:beredpar5}, then $M$ is $\lambd[x][Nx]$ and
$M'$ is $N'$ for some $x$, $N$, $N'$ where $x \notin FV(N)$ and $N
\beredpar N'$. We want to show that $N' \beredpar
\becd{(\lambd[x][Nx])}$, i.e., $N' \beredpar \becd{N}$, which is
immediate by induction hypothesis.
Use strong induction on the size of $M$, with representatives chosen
fresh whenever needed. Induction on parallel-reduction derivations
first gives $\FV{A'}\subseteq\FV{A}$ whenever $A\beredpar A'$.
Also $A\beredpar\becd{A}$ follows from the development clauses by
structural induction. These facts preserve every freshness
condition used below.

The variable case is immediate. Suppose $M=\lambd[x][N]$ is not an
$\eta$-redex. Its parallel reduct is $\lambd[x][N']$, where
$N\beredpar N'$. The induction hypothesis and the abstraction rule
give $\lambd[x][N']\beredpar\lambd[x][\becd{N}]=\becd{M}$.

Now suppose $M=\lambd[x][Px]$ with $x\notin\FV{P}$, so that
$\becd{M}=\becd{P}$. An outer $\eta$ step gives a reduct $P'$ of $P$,
and induction gives $P'\beredpar\becd{P}$. An abstraction step gives
$\lambd[x][N']$ where $Px\beredpar N'$. If this body step uses the
application rule, $N'=P'x$, and induction followed by the $\eta$
rule gives $\lambd[x][P'x]\beredpar\becd{P}$. If it uses the
$\beta$ rule, write $P=\lambd[y][T]$ and
$N'=\Subst{T'}{x}{y}$, where $T\beredpar T'$. Since $x$ is fresh,
$\lambd[x][\Subst{T'}{x}{y}]\aeq\lambd[y][T']$.
The latter is a parallel reduct of the smaller term $P$, so induction
again gives a parallel reduction to $\becd{P}$.

Suppose next that $M=PQ$ and $P$ is not an abstraction. Only the
application rule can be last, and induction gives
$P'Q'\beredpar\becd{P}\becd{Q}=\becd{M}$.

Finally let $M=(\lambd[x][N])Q$. If the last rule is the $\beta$
rule, induction and \olref{lem:comp} give
$\Subst{N'}{Q'}{x}\beredpar\Subst{\becd{N}}{\becd{Q}}{x}
=\becd{M}$. If the last rule is application, the reduct is $P'Q'$
with $\lambd[x][N]\beredpar P'$ and $Q\beredpar Q'$.
When the function reduction uses abstraction, $P'=\lambd[x][N']$;
induction and the $\beta$ rule give the same target.

The remaining function reduction uses $\eta$: then $N=Sx$,
$x\notin\FV{S}$, and $S\beredpar P'$. If $S$ is not an abstraction,
the target is $\becd{S}\becd{Q}$, reached from $P'Q'$ by induction
and application. If $S=\lambd[y][T]$, the target is
$\Subst{\becd{T}}{\becd{Q}}{y}$, by the capture-free substitution
identity and freshness of $x$. But $P'Q'$ is a parallel reduct of
$SQ$, a term strictly smaller than the original
$(\lambd[x][Sx])Q$. The strong induction hypothesis for $SQ$ gives
exactly that target. This covers both overlaps between $\beta$ and
$\eta$.
\end{proof}

\begin{thm}\ollabel{thm:cr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Parallel reduction ($\bredpar$) of terms is inductively defined as follows:
\begin{enumerate}
\item \ollabel{defn:bredpar1} $x \bredpar x$.
\item \ollabel{defn:bredpar2} If $N \xrightarrow{\beta} N'$ then $\lambd[x][N] \bredpar
\item \ollabel{defn:bredpar2} If $N \bredpar N'$ then $\lambd[x][N] \bredpar
\lambd[x][N']$.
\item \ollabel{defn:bredpar3} If $P \bredpar P'$ and $Q \bredpar Q'$ then $PQ \bredpar
P'Q'$.
Expand Down Expand Up @@ -86,7 +86,7 @@
$\Subst{(\lambd[x][N])}{R}{y} \bredpar
\Subst{(\lambd[x][N'])}{R'}{y}$, i.e.,
$\lambd[x][\Subst{N}{R}{y}] \bredpar
\lambd[x][\Subst{N'}{R}{y}]$. This follows immediately by
\lambd[x][\Subst{N'}{R'}{y}]$. This follows immediately by
\olref{defn:bredpar2} and the induction hypothesis.
\item The last step is \olref{defn:bredpar3}: Exercise.
\item The last step is \olref{defn:bredpar4}: $M$ is
Expand Down
4 changes: 2 additions & 2 deletions content/lambda-calculus/introduction/basic-pr-lambda.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
\end{lem}

\begin{proof}
$\Zero$ is just
$\lambd[x][\lambd[y][y]]$.
$\Zero$ is !!{lambda defined} by
$\lambd[z][\lambd[x][\lambd[y][y]]]$.

The successor function~$\Succ$, is
defined by $\fn{Succ}(u) = \lambd[x][\lambd[y][x(uxy)]]$. You should
Expand Down
8 changes: 7 additions & 1 deletion content/lambda-calculus/introduction/composition.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
\end{lem}

\begin{proof}
We first prove this for total component functions. The general
partial case follows from the independent computability equivalence
completed in \olref[min]{sec}.
Suppose $f$ is defined by composition from $h$, $g_0,$
\dots,~$g_{k-1}$. Assuming $h$, $g_0$, \dots,~$g_{k-1}$ are
!!{lambda defined} by $H$, $G_0$, \dots,~$G_{k-1}$,
Expand All @@ -24,7 +27,10 @@
\dots, G_{k-1}(x_0, \dots, x_{l-1})).
\]
In other words, the language of the lambda calculus is well suited to
represent composition.
represent composition for total components. For partial components
this term alone need not work: a constant-zero outer term can erase
a nonnormalizing inner term, although strict numeric composition is
then undefined.
\end{proof}

\end{document}
29 changes: 19 additions & 10 deletions content/lambda-calculus/introduction/computable-lambda.tex
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@
\end{thm}

\begin{proof}
We need to show that every partial computable function~$f$ is
!!{lambda defined} by a lambda term~$F$. By Kleene's normal form
theorem, it suffices to show that every primitive recursive function
is !!{lambda defined} by a lambda term, and then that the functions
!!{lambda definable} are closed under suitable compositions and
unbounded search. To show that every primitive recursive function is
!!{lambda defined} by a lambda term, it suffices to show that the
initial functions are !!{lambda definable}, and that the partial
functions that are !!{lambda definable} are closed under
composition, primitive recursion, and unbounded search.
By Kleene's normal form theorem, for every partial computable
function~$f$ there are primitive recursive functions $r$ and $u$ such
that
\[
f(\vec x)\simeq u(\umin{t}{r(\vec x,t)}).
\]
First we represent
the initial functions and prove closure under composition and
primitive recursion for \emph{total} functions. This supplies terms
for $r$ and $u$. We then implement a search that returns the decoded
value $u(t)$ only in its successful branch; the construction at the
end of \olref[min]{sec} also proves that an unsuccessful search has
no normal form. This proves the theorem without assuming that
ordinary lambda application preserves undefinedness.

After this construction, the general partial closure results follow
from the computability of lambda-definable functions
(\olref[cmp]{thm:lambda-computable}) and the corresponding strict
closure operations on partial computable functions.
\end{proof}

We will use a more conventional notation to make the rest of the proof
Expand Down
8 changes: 5 additions & 3 deletions content/lambda-calculus/introduction/currying.tex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
accepts an argument~$x$ and returns the function~$\lambd[y][x]$. The
function $\lambd[y][x]$ accepts another argument~$y$, but drops it,
and always returns~$x$. Let's see what happens when we apply
$\lambd[x][\lambd[y][x]]$ to two arguments:
$\lambd[x][\lambd[y][x]]$ to two arguments, choosing $y$ not free
in $M$ by renaming the bound variable first if necessary:
\begin{align*}
(\lambd[x][\lambd[y][x]])MN
\bredone & (\lambd[y][M])N \\
Expand All @@ -51,7 +52,8 @@
In general, to write a function with parameters $x_1$, \dots,~$x_n$
defined by some term~$N$, we can write
$\lambd[x_1][\lambd[x_2][\ldots\lambd[x_n][N]]]$. If we apply $n$ arguments
to it we get:
to it, first choose the $x_i$ pairwise distinct and not free in any
$M_j$, renaming bound variables as necessary. Then we get:
\begin{multline*}
(\lambd[x_1][\lambd[x_2][\ldots\lambd[x_n][N]]]) M_1 \dots M_n \bredone\\
\begin{aligned}
Expand All @@ -60,7 +62,7 @@
\eqs {} & (\lambd[x_2][\ldots\lambd[x_n][\Subst{N}{M_1}{x_1}]]) M_2
\dots M_n \\
\vdots & \\
\bredone {} &\Subst{\Subst{P}{M_1}{x_1}\ldots}{M_n}{x_n}
\bredone {} &\Subst{\Subst{N}{M_1}{x_1}\ldots}{M_n}{x_n}
\end{aligned}
\end{multline*}
The last line literally means substituting $M_i$ for $x_i$ in the body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
\olsection{Fixed-Point Combinators}

Suppose you have a lambda term $g$, and you want another term $k$ with
the property that $k$ is $\beta$-equivalent to $gk$. Define terms
the property that $k$ is $\beta$-equivalent to $gk$. Choose $x$ not free in
$g$, and define terms
\[
\fn{diag}(x) = xx
\]
Expand Down
4 changes: 2 additions & 2 deletions content/lambda-calculus/introduction/lambda-definability.tex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
\begin{defn}
For each natural number~$n$, define the \emph{Church numeral}
$\num{n}$ to be the lambda term $\lambd[x][\lambd[y][(x(x(x(\dots
x(y)))))]]$, where there are $n$ $x$'s in all.
x(y)))))]]$, where the body contains $n$ occurrences of $x$.
\end{defn}

The terms $\num{n}$ are ``iterators'': on input $f$, $\num{n}$ returns
Expand All @@ -27,7 +27,7 @@
a function on the natural numbers.

\begin{defn}
Let $f(x_0, \dots, x_{k-1})$ be an $n$-ary partial function from $\Nat$
Let $f(x_0, \dots, x_{k-1})$ be a $k$-ary partial function from $\Nat^k$
to $\Nat$. We say a $\lambd$-term~$F$ \emph{!!{lambda define}s}~$f$ iff for every
sequence of natural numbers $n_0$, \dots,~$n_{k-1}$,
\[
Expand Down
57 changes: 47 additions & 10 deletions content/lambda-calculus/introduction/minimization.tex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
\end{lem}

\begin{proof}
First assume that $f$ is total; the arbitrary partial case is proved
at the end. Choose its representative closed, replacing any free
variables by closed terms; since every numeric input reduces to a
closed numeral, this preserves all required values.
The idea is roughly as follows. Given $x$, we will use the fixed-point
lambda term $Y$ to define a function $h_x(n)$ which searches for a~$y$
starting at~$n$; then $g(x)$ is just $h_x(0)$. The function~$h_x$ can
Expand All @@ -30,18 +34,19 @@
\end{cases}
\]

Here are the details. Since $f$ is primitive recursive, it is
Here are the details. By hypothesis, $f$ is
!!{lambda defined} by some term $F$. Remember that we also have a lambda
term~$D$, such that $D(M, N, \bar{0}) \red M$ and $D(M, N, \bar{1})
\red N$. Fixing $x$ for the moment, to !!{lambda define} $h_x$ we want to
find a term~$H$ (depending on~$x$) satisfying
\[
H(\num{n}) \equiv D(\num{n}, H(S(\num{n})), F(x, \num{n})).
H(\num{n}) \equiv D(\num{n}, H(\fn{Succ}(\num{n})), F(x, \num{n})).
\]
We can do this using the fixed-point term~$Y$. First, let $U$ be the
Use Turing's fixed-point term~$Y$ from \olref[fix]{sec}, so that
$YU\red U(YU)$. First, let $U$ be the
term
\[
\lambd[h][\lambd[z][D(z,(h(Sz)),F(x,z))]],
\lambd[h][\lambd[z][D(z,(h(\fn{Succ}(z))),F(x,z))]],
\]
and then let $H$ be the term~$YU$. Notice that the only free variable
in~$H$ is~$x$. Let us show that $H$ satisfies the equation above.
Expand All @@ -53,17 +58,49 @@
In particular, for each natural number~$n$, we have
\begin{align*}
H(\num{n}) & \equiv U(H, \num{n}) \\
& \red D(\num{n}, H(S(\num{n})), F(x, \num{n})),
& \red D(\num{n}, H(\fn{Succ}(\num{n})), F(x, \num{n})),
\end{align*}
as required. Notice that if you substitute a numeral $\num{m}$ for~$x$
in the last line, the expression reduces to $\num{n}$ if $F(\num{m},
\num{n})$ reduces to $\num{0}$, and it reduces to $H(S(\num{n}))$ if
\num{n})$ reduces to $\num{0}$, and it reduces to $H(\fn{Succ}(\num{n}))$ if
$F(\num{m}, \num{n})$ reduces to any other numeral.

To finish off the proof, let $G$ be $\lambd[x][H(\num 0)]$. Then $G$
!!{lambda define}s~$g$; in other words, for every~$m$, $G(\num m)$
reduces to~$\overline {g(m)}$, if $g(m)$ is defined, and has no normal
form otherwise.
To finish the total-input case, let $G$ be $\lambd[x][H(\num 0)]$.
If the search first succeeds at $n$, finitely many unfoldings give
$G(\num m)\red\num n$. If no candidate succeeds, leftmost-outermost
reduction continually evaluates the next test and returns to the
recursive call in head position. It never reaches a normal form.
Here we use the normalization theorem: leftmost-outermost reduction
reaches a $\beta$-normal form whenever one exists.\footnote{For a
proof, see Andrew D. Ker, \emph{Lambda Calculus and Types} (2009),
Theorem 3.2.3, pp.~35--36.} Thus an unsuccessful search has no normal
form. Merely exhibiting some infinite reduction sequence would not
suffice.

We can now complete \olref[lrp]{thm:computable-lambda}, without using
closure under arbitrary partial composition. Let the total
primitive recursive $r$ and $u$ be as in its proof outline, and let
closed terms $R$ and $U_0$ represent them. With fresh variables, put
\[
Q=\lambd[h][\lambd[n][\lambd[\vec x][
D(U_0(n),h(\fn{Succ}(n),\vec x),R(\vec x,n))]]],
\qquad L=YQ.
\]
Then $\lambd[\vec x][L(\num 0,\vec x)]$ represents $f$. If the least
successful test is $n$, the search selects $U_0(\num n)$, which
reduces to the numeral for $u(n)$. If no test succeeds, the same
leftmost-outermost argument gives no normal form. The decoder is
inside the successful branch, so it cannot erase a failed search.

Finally, for arbitrary partial lambda-definable component functions,
\olref[cmp]{thm:lambda-computable} makes them partial computable.
Strict composition computes every inner value before applying the
outer function; strict primitive recursion computes the base and
all earlier values; strict minimization tests candidates in order
and is undefined if a required test is undefined. These are partial
computable procedures, so the theorem just completed supplies
lambda representatives. This proves the general partial versions
of all three closure lemmas.
\end{proof}

\end{document}
Loading
Loading