content/lambda-calculus/church-rosser/church-rosser.tex
1% Part: lambda-calculus2% Chapter: church-rosser34\documentclass[../../../include/open-logic-chapter]{subfiles}56\begin{document}78\olchapter{lam}{cr}{The Church--Rosser Property}910\olimport{definitions-and-properties}11\olimport{parallel-beta-reduction}12\olimport{beta-reduction}13\olimport{parallel-beta-eta-reduction}14\olimport{beta-eta-reduction}1516\OLEndChapterHook1718\end{document}19
content/lambda-calculus/church-rosser/definitions-and-properties.tex
1% Part: lambda-calculus2% Chapter: church-rosser3% Section: definitions-and-properties45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{lam}{cr}{dap}1011\olsection{Definition and Properties}1213In this chapter we introduce the concept of Church--Rosser property and14some common properties of this property.1516\begin{defn}[Church--Rosser property, CR] A relation $\xredone$ on17 terms is said to satisfy the \emph{Church--Rosser property} iff,18 whenever $M \xredone P$ and $M \xredone Q$, then there exists19 some~$N$ such that $P \xredone N$ and $Q \xredone N$.20\end{defn}2122We can view the lambda calculus as a model of computation in which23terms in normal form are ``values'' and a reducibility relation on24terms are the ``calculation rules.'' The Church--Rosser property states25is that when there is more than one way to proceed with a calculation,26there is still only a single value of the expression.2728To take an example from elementary algebra, there's more than one way29to calculate $4 \times (1+2) + 3$. It can either be reduced to $430\times 3+3$ (if we first reduce $1+2$ to~$3$) or to $4 \times 1+431\times 2+3$ (if we first reduce $4 \times (1+2)$ using32distributivity). Both of these, however, can be further reduced to33$12+3$.3435If we take $\xredone$ to be $\beta$-reduction, we easily see that a36consequence of the Church--Rosser property is that if a term has a37normal form, then it is unique. For suppose $M$ can be reduced to $P$38and $Q$, both of which are normal forms. By the Church--Rosser property,39there exists some $N$ such that both $P$ and $Q$ reduce to it. Since40by assumption $P$ and $Q$ are normal forms, the reduction of $P$ and41$Q$ to $N$ can only be the trivial reduction, i.e., $P$, $Q$, and $N$42are identical. This justifies our speaking of \emph{the} normal form43of a term.4445In viewing the lambda calculus as a model of computation, then, the46normal form of a term can be thought of as the ``final result'' of the47computation starting with that term. The above corollary means there's48only one, if any, final result of a computation, just like there is49only one result of computing $4 \times (1+2)+3$, namely~$15$.5051\begin{thm} \ollabel{thm:str}52 If a relation $\xredone$ satisfies the Church--Rosser property, and $\xred$ is the53 smallest transitive relation containing $\xredone$, then $\xred$ satisfies54 the Church--Rosser property too.55\end{thm}5657\begin{proof}58 Suppose 59 \begin{align*}60 M & \xredone P_1 \xredone \dots \xredone P_m \text{ and}\\61 M & \xredone Q_1 \xredone \dots \xredone Q_n.62 \end{align*}63 We will prove the theorem by constructing a grid $N$ of terms of64 height is $m + 1$ and width $n + 1$. We use $N_{i,j}$ to denote the65 term in the $i$-th row and $j$-th column.66 67 We construct $N$ in such a way that $N_{i,j} \xredone N_{i+1,j}$ and68 $N_{i,j} \xredone N_{i,j+1}$. It is defined as follows:69 \begin{align*}70 N_{0,0} &= M \\71 N_{i,0} &= P_i && \text{if } 1 \le i \le m \\72 N_{0,j} &= Q_j && \text{if } 1 \le j \le n \\73 \intertext{and otherwise:}74 N_{i,j} &= R75 \end{align*}76 where $R$ is a term such that $N_{i-1,j} \xredone R$ and $N_{i,j-1}77 \xredone R$. By the Church--Rosser property of $\xredone$, such a78 term always exists.7980 Now we have $N_{m,0} \xredone \dots \xredone N_{m,n}$ and $N_{0,n}81 \xredone \dots \xredone N_{m,n}$. Note $N_{m,0}$ is $P$ and $N_{0,n}$82 is $Q$. By definition of $\xred$ the theorem follows.83\end{proof}8485\end{document}
content/lambda-calculus/church-rosser/parallel-beta-reduction.tex
1% Part: lambda-calculus2% Chapter: church-rosser3% Section: parallel-beta-reduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{lam}{cr}{pb}1011\olsection{Parallel $\beta$-reduction}1213We introduce the notion of \emph{parallel $\beta$-reduction}, and14prove the it has the Church--Rosser property.1516\begin{defn}[parallel $\beta$-reduction, $\bredpar$] \ollabel{defn:bredpar}17 Parallel reduction ($\bredpar$) of terms is inductively defined as follows:18 \begin{enumerate}19 \item \ollabel{defn:bredpar1} $x \bredpar x$.20 \item \ollabel{defn:bredpar2} If $N \xrightarrow{\beta} N'$ then $\lambd[x][N] \bredpar21 \lambd[x][N']$.22 \item \ollabel{defn:bredpar3} If $P \bredpar P'$ and $Q \bredpar Q'$ then $PQ \bredpar23 P'Q'$.24 \item \ollabel{defn:bredpar4} If $N \bredpar N'$ and $Q \bredpar Q'$ then25 $(\lambd[x][N])Q \bredpar \Subst{N'}{Q'}{x}$.26 \end{enumerate}27\end{defn}2829Parallel $\beta$-reduction allows us to reduce any number of redices in a30term in one step. It is different from $\beta$-reduction in the sense that we31can only contract redices that occur in the original term, but not redices32arising from parallel $\beta$-reduction. For example, the term33$(\lambd[f][fx])(\lambd[y][y])$ can only be parallel $\beta$-reduced34to itself or to $(\lambd[y][y])x$, but not further to~$x$, although it35$\beta$-reduces to~$x$, because this redex arises only after one step 36of parallel $\beta$-reduction. A second parallel $\beta$-reduction37step yields~$x$, though.3839\begin{thm}\ollabel{thm:refl}40 $M \bredpar M$.41\end{thm}4243\begin{proof}44 Exercise.45\end{proof}4647\begin{prob}48 Prove \olref[lam][cr][pb]{thm:refl}.49\end{prob}5051\begin{defn}[$\beta$-complete development]\ollabel{defn:bcd}52 The \emph{$\beta$-complete development}~$\bcd{M}$ of $M$ is defined53 inductively as follows:54 \begin{align}55 \bcd{x} &= x \ollabel{defn:bcd1} \\56 \bcd{(\lambd[x][N])} &= \lambd[x][\bcd{N}] \ollabel{defn:bcd2}\\57 \bcd{(PQ)} &= \bcd{P}\bcd{Q} && \text{if $P$ is not a $\lambd$-abstract} 58 \ollabel{defn:bcd3} \\59 \bcd{((\lambd[x][N])Q)} &= \Subst{\bcd{N}}{\bcd{Q}}{x} \ollabel{defn:bcd4}60 \end{align}61\end{defn}6263The $\beta$-complete development of a term, as its name suggests, is a64``complete parallel reduction.'' While for parallel $\beta$-reduction we still65can choose to not contract a redex, for complete development we have66no choice but to contract all of them. Thus the complete development67of $(\lambd[f][fx])(\lambd[y][y])$ is $(\lambd[y][y])x$, not itself.6869\begin{editorial}70 This definition has the problem that we haven't introduced how to71 define functions on ($\lambd$-)terms recursively. Will fix in future.72\end{editorial}7374\begin{lem}\ollabel{lem:comp}75 If $M \bredpar M'$ and $R \bredpar R'$, then $\Subst{M}{R}{y}76 \bredpar \Subst{M'}{R'}{y}$.77\end{lem}7879\begin{proof}80 By induction on the !!{derivation} of $M \bredpar M'$.81 \begin{enumerate}82 \item The last step is \olref{defn:bredpar1}: Exercise.83 \item The last step is \olref{defn:bredpar2}: Then $M$ is 84 $\lambd[x][N]$ and $M'$ is $\lambd[x][N']$,85 where $N \bredpar N'$. We want to prove that86 $\Subst{(\lambd[x][N])}{R}{y} \bredpar87 \Subst{(\lambd[x][N'])}{R'}{y}$, i.e.,88 $\lambd[x][\Subst{N}{R}{y}] \bredpar89 \lambd[x][\Subst{N'}{R}{y}]$. This follows immediately by90 \olref{defn:bredpar2} and the induction hypothesis.91 \item The last step is \olref{defn:bredpar3}: Exercise.92 \item The last step is \olref{defn:bredpar4}: $M$ is93 $(\lambd[x][N])Q$ and $M'$ is $\Subst{N'}{Q'}{x}$. We want to94 prove that $\Subst{((\lambd[x][N])Q)}{R}{y} \bredpar95 \Subst{\Subst{N'}{Q'}{x}}{R'}{y}$, i.e.,96 $(\lambd[x][\Subst{N}{R}{y}])\Subst{Q}{R}{y} \bredpar97 \Subst{\Subst{N'}{R'}{y}}{\Subst{Q'}{R'}{y}}{x}$. This follows98 by \olref{defn:bredpar4} and the induction hypothesis.99 \end{enumerate}100\end{proof}101102\begin{prob}103 Complete the proof of \olref[lam][cr][pb]{lem:comp}.104\end{prob}105106\begin{lem}\ollabel{lem:cont}107 If $M \bredpar M'$ then $M' \bredpar \bcd{M}$.108\end{lem}109\begin{proof}110 By induction on the !!{derivation} of $M \bredpar M'$.111 \begin{enumerate}112 \item The last rule is \olref{defn:bredpar1}: Exercise.113 \item The last rule is \olref{defn:bredpar2}: $M$ is 114 $\lambd[x][N]$ and $M'$ is $\lambd[x][N']$ with115 $N \bredpar N'$. We want to show that $\lambd[x][N'] \bredpar116 \bcd{(\lambd[x][N])}$, i.e., $\lambd[x][N'] \bredpar117 \lambd[x][\bcd{N}]$ by \olref{defn:bcd2}. It follows by118 \olref{defn:bredpar2} and the induction hypothesis.119 \item The last rule is \olref{defn:bredpar3}:$M$ is $PQ$ and $M'$120 is $P'Q'$ for some $P$, $Q$, $P'$ and $Q'$, with $P \bredpar P'$121 and $Q \bredpar Q'$. By induction hypothesis, we have $P'122 \bredpar \bcd{P}$ and $Q' \bredpar \bcd{Q}$.123 \begin{enumerate}124 \item If $P$ is $\lambd[x][N]$ for some $x$ and $N$, then125 $P'$ must be $\lambd[x][N']$ for some $N'$ with 126 $N \bredpar N'$. By induction hypothesis we have $N' \bredpar \bcd{N}$ and127 $Q' \bredpar \bcd{Q}$. Then $(\lambd[x][N'])Q' \bredpar128 \Subst{\bcd{N}}{\bcd{Q}}{x}$ by \olref{defn:bredpar4}.129 \item If $P$ is not a $\lambd$-abstract, then $P'Q' \bredpar130 \bcd{P}\bcd{Q}$ by \olref{defn:bredpar3}, and the right-hand131 side is $\bcd{PQ}$ by \olref{defn:bcd3}.132 \end{enumerate}133 \item The last rule is \olref{defn:bredpar4}: $M$ is134 $(\lambd[x][N])Q$ and $M'$ is $\Subst{N'}{Q'}{x}$ for some $x$,135 $N$, $Q$, $N'$, and~$Q'$, with $N \bredpar N'$ and $Q \bredpar136 Q'$. By induction hypothesis we know $N' \bredpar \bcd{N}$ and137 $Q' \bredpar \bcd{Q}$. By \olref{lem:comp} we have138 $\Subst{N'}{Q'}{x} \bredpar \Subst{\bcd{N}}{\bcd{Q}}{x}$, the139 right-hand side of which is exactly $\bcd{((\lambd[x][N])Q)}$.140 \end{enumerate}141\end{proof}142143\begin{prob}144 Complete the proof of \olref[lam][cr][pb]{lem:cont}.145\end{prob}146147\begin{thm}\ollabel{thm:cr}148 $\bredpar$ has the Church--Rosser property.149\end{thm}150151\begin{proof}152 Immediate from \olref{lem:cont}.153\end{proof}154155\end{document}156
content/lambda-calculus/church-rosser/beta-reduction.tex
1% Part: lambda-calculus2% Chapter: church-rosser3% Section: beta-reduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{lam}{cr}{b}1011\olsection{$\beta$-reduction}1213\begin{lem}\ollabel{lem:one-par}14 If $M \bredone M'$, then $M \bredpar M'$.15\end{lem}16\begin{proof} If $M \bredone M'$, then $M$ is17 $(\lambd[x][N])Q$, $M'$ is $\Subst{N}{Q}{x}$, for some18 $x$, $N$, and~$Q$. Since $N \bredpar N$ and $Q \bredpar Q$ by19 \olref[pb]{thm:refl}, we immediately have $(\lambd[x][N])Q20 \bredpar \Subst{N}{Q}{x}$ by \olref[pb]{defn:bredpar}\olref[pb]{defn:bredpar4}.21\end{proof}2223\begin{lem}\ollabel{lem:par-red}24 If $M \bredpar M'$, then $M \bred M'$.25\end{lem}2627\begin{proof} By induction on the !!{derivation} of $M \bredpar M'$.28 \begin{enumerate}29 \item The last rule is \olref[pb]{defn:bredpar1}: Then $M$ and $M'$30 are just $x$, and $x \bred x$.31 \item The last rule is \olref[pb]{defn:bredpar2}: $M$ is 32 $\lambd[x][N]$ and $M'$ is $\lambd[x][N']$ for some $x$, $N$, $N'$, where33 $N \bredpar N'$. By induction hypothesis we have $N \bred N'$. Then34 $\lambd[x][N] \bred \lambd[x][N']$ (by the same series of35 $\bredone$ contractions as $N \bred N'$).36 \item The last rule is \olref[pb]{defn:bredpar3}: $M$ is 37 $PQ$ and $M'$ is $P'Q'$ for some $P$, $Q$, $P'$, $Q'$, where $P \bredpar P'$38 and $Q \bredpar Q'$. By induction hypothesis we have $P \bred P'$ and $Q \bred39 Q'$. So $PQ \bred P'Q'$ by the reduction sequence $P \bred P'$ followed40 by the reduction $Q \bred Q'$.41 \item The last rule is \olref[pb]{defn:bredpar4}: $M$ is42 $(\lambd[x][N])Q$ and $M'$ is $\Subst{N'}{Q'}{x}$ for some $x$,43 $N$, $M'$, $Q$, $Q'$, where $N \bredpar N'$ and $Q \bredpar Q'$.44 By induction hypothesis we get $Q \bred Q'$ and $N \bred N'$. So45 $(\lambd[x][N])Q \bred \Subst{N'}{Q'}{x}$ by $N \bred N'$ followed46 by $Q \bred Q'$ and finally contraction of $(\lambd[x][N'])Q'$ to47 $\Subst{N'}{Q'}{x}$.48 \end{enumerate}49\end{proof}5051\begin{lem}\ollabel{lem:str}52 $\bred$ is the smallest transitive relation containing $\bredpar$.53\end{lem}5455\begin{proof}56 Let $\xred$ be the smallest transitive relation containing57 $\bredpar$.5859 $\bred \subseteq \xred$: Suppose $M \bred M'$, i.e., $M \ident M_160 \bredone \dots \bredone M_k \ident M'$. By \olref{lem:one-par}, $M61 \ident M_1 \bredpar \dots \bredpar M_k \ident M'$. Since is $\xred$62 contains $\bredpar$ and is transitive, $M \xred M'$.6364 $\xred \subseteq \bred$: Suppose $M \xred M'$, i.e., $M65 \ident M_1 \bredpar \dots \bredpar M_k \ident M'$. By \olref{lem:par-red}, $M \ident M_166 \bred \dots \bred M_k \ident M'$. Since $\bred$ is transitive, $M67 \bred M'$.68\end{proof}6970\begin{thm}\ollabel{thm:cr}71 $\bred$ satisfies the Church--Rosser property.72\end{thm}7374\begin{proof}75 Immediate from \olref[dap]{thm:str}, \olref[pb]{thm:cr}, and \olref{lem:str}.76\end{proof}7778\end{document}
content/lambda-calculus/church-rosser/parallel-beta-eta-reduction.tex
1% Part: lambda-calculus2% Chapter: church-rosser3% Section: parallel-beta-eta-reduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{lam}{cr}{pbe}1011\olsection{Parallel $\beta\eta$-reduction}1213In this section we prove the Church-Rosser property for parallel14$\beta\eta$-reduction, the parallel reduction notion corresponding to15$\beta\eta$-reduction. 1617\begin{defn}[Parallel $\beta\eta$-reduction, $\beredpar$] \ollabel{defn:beredpar}18 \emph{Parallel $\beta\eta$-reduction} ($\beredpar$) on terms is19 inductively defined as follows:20 \begin{enumerate}21 \item \ollabel{defn:beredpar1} $x \beredpar x$.22 \item \ollabel{defn:beredpar2} If $N \xrightarrow{\beta} N'$ then $\lambd[x][N] \beredpar23 \lambd[x][N']$.24 \item \ollabel{defn:beredpar3} If $P \beredpar P'$ and $Q \beredpar Q'$ then $PQ \beredpar25 P'Q'$.26 \item \ollabel{defn:beredpar4} If $N \beredpar N'$ and $Q \beredpar Q'$ then27 $(\lambd[x][N])Q \beredpar \Subst{N'}{Q'}{x}$.28 \item \ollabel{defn:beredpar5} If $N \beredpar N'$ then $\lambd[x][Nx]29 \beredpar N'$, provided $x \notin FV(N)$.30 \end{enumerate}31\end{defn}3233\begin{thm}\ollabel{thm:refl}34 $M \beredpar M$.35\end{thm}3637\begin{proof}38 Exercise.39\end{proof}4041\begin{prob}42 Prove \olref[lam][cr][pbe]{thm:refl}.43\end{prob}4445\begin{defn}[$\beta\eta$-complete development]\ollabel{defn:becd}46 The \emph{$\beta\eta$-complete development}~$\becd{M}$ of~$M$ is defined47 as follows:48 \begin{align}49 \becd{x} &= x \ollabel{defn:becd1} \\50 \becd{(\lambd[x][N])} &= \lambd[x][\becd{N}] \ollabel{defn:becd2}\\51 \becd{(PQ)} &= \becd{P}\becd{Q} && \text{if $P$ is not a $\lambd$-abstract} 52 \ollabel{defn:becd3} \\53 \becd{((\lambd[x][N])Q)} &= \Subst{\becd{N}}{\becd{Q}}{x}54 \ollabel{defn:becd4} \\55 \becd{(\lambd[x][Nx])} &= \becd{N} \ollabel{defn:becd5} & \text{if $x56 \notin FV(N)$}57 \end{align}58\end{defn}5960\begin{lem}\ollabel{lem:comp}61 If $M \beredpar M'$ and $R \beredpar R'$, then $\Subst{M}{R}{y}62 \beredpar \Subst{M'}{R'}{y}$.63\end{lem}6465\begin{proof}66 By induction on the !!{derivation} of $M \beredpar M'$.6768 The first four cases are exactly like those in \olref[pb]{lem:comp}.69 If the last rule is \olref{defn:beredpar5}, then $M$ is70 $\lambd[x][Nx]$, $M'$ is $N'$ for some $x$ and~$N'$ where $x \notin71 FV(N)$, and $N \beredpar N'$. We want to show that72 $\Subst{(\lambd[x][Nx])}{R}{y} \beredpar \Subst{N'}{R'}{y}$, i.e.,73 $\lambd[x][\Subst{N}{R}{y} x] \beredpar \Subst{N'}{R'}{y}$. It74 follows by \olref{defn:beredpar}\olref{defn:beredpar5} and the75 induction hypothesis.76\end{proof}7778\begin{lem}\ollabel{lem:cont}79 If $M \beredpar M'$ then $M' \beredpar \becd{M}$.80\end{lem}8182\begin{proof}83 By induction on the !!{derivation} of $M \beredpar M'$.8485 The first four cases are like those in \olref[pb]{lem:cont}. If the86 last rule is \olref{defn:beredpar5}, then $M$ is $\lambd[x][Nx]$ and87 $M'$ is $N'$ for some $x$, $N$, $N'$ where $x \notin FV(N)$ and $N88 \beredpar N'$. We want to show that $N' \beredpar89 \becd{(\lambd[x][Nx])}$, i.e., $N' \beredpar \becd{N}$, which is90 immediate by induction hypothesis.91\end{proof}9293\begin{thm}\ollabel{thm:cr}94 $\beredpar$ has the Church-Rosser property.95\end{thm}9697\begin{proof}98 Immediate from \olref{lem:cont}.99\end{proof}100101\end{document}
content/lambda-calculus/church-rosser/beta-eta-reduction.tex
1% Part: lambda-calculus2% Chapter: church-rosser3% Section: beta-eta-reduction45\documentclass[../../../include/open-logic-section]{subfiles}67\begin{document}89\olfileid{lam}{cr}{be}1011\olsection{$\beta\eta$-reduction}1213The Church--Rosser property holds for14$\beta\eta$-reduction ($\bered$).1516\begin{lem}\ollabel{lem:one-par}17 If $M \beredone M'$, then $M \beredpar M'$.18\end{lem}1920\begin{proof} 21 By induction on the !!{derivation} of $M \beredone M'$. If $M \bredone22 M'$ by $\eta$-conversion (i.e., \olref[syn][eta]{defn:beredone}), we23 use \olref[pbe]{thm:refl}. The other cases are as in24 \olref[b]{lem:one-par}.25\end{proof}262728\begin{lem}\ollabel{lem:par-red}29 If $M \beredpar M'$, then $M \bered M'$.30\end{lem}3132\begin{proof} Induction on the !!{derivation} of $M \beredpar M'$.3334 If the last rule is \olref[pbe]{defn:beredpar5}, then $M$ is35 $\lambd[x][Nx]$ and $M'$ is $N'$ for some $x$, $N$, $N'$ where $x36 \notin FV(N)$ and $N \beredpar N'$. Thus we can first reduce37 $\lambd[x][Nx]$ to $N$ by $\eta$-conversion, followed38 by the series of $\beredone$ steps that show that $N \bered N'$,39 which holds by induction hypothesis.40\end{proof}414243\begin{lem}\ollabel{lem:str}44 $\bered$ is the smallest transitive relation containing $\beredpar$.45\end{lem}4647\begin{proof}48 As in \olref[b]{lem:str}49\end{proof}5051\begin{thm}\ollabel{thm:cr}52 $\bered$ satisfies Church--Rosser property.53\end{thm}5455\begin{proof}56 By \olref[dap]{thm:str}, \olref[pbe]{thm:cr} and \olref{lem:str}.57\end{proof}58\end{document}