\documentclass{article} \input{exer-defs} \newcommand{\nats}{\mathbb{N}} %\renewcommand{\thepage}{} \begin{document} \begin{center}\large\bf CIS 705 --- Programming Languages --- Spring 2009 \end{center} \begin{center}\Large\bf Assignment 4 \end{center} \begin{center}\large\bf Model Answers to Exercise 1 \end{center} \section*{Exercise 1} \renewcommand{\thesection}{1} \theoremnumber{1} Note that, if $v$ is a closed value, then $\overline{v} = v$. Thus, if $t$ is a closed term that converges, then $\overline{\overline{t}} = \overline{t}$. \subsection*{Proposition D} \begin{lemma} \label{PropDLem} For all closed terms $t$ and $t'$, closed values $v$ and $n,m\in\nats$, if $t\fun^n v$ and $t\fun^m t'$, then $m\leq n$ and $t'\fun^{n-m}v$. \end{lemma} \begin{proof} Suppose, toward a contradiction, that $m > n$. Thus $m-n>0$ and $n + (m-n) = m$. Hence, because $t\fun^m t'$, we have that $t\fun^{n+(m-n)}t'$, so that there is a closed term $u$ such that $t\fun^n u\fun^{m-n}t'$. Since $t\fun^n v$ and $t\fun^n u$, we have that $v=u\fun^{m-n}t'$. But $m-n>0$, so that there is a $u'$ such that $v\fun u'$, contradicting the fact that $v$ is a value. Thus $m\leq n$. Since $m\leq n$, it follows that $n-m\geq 0$ and $n = m + (n-m)$. Because $t\fun^n v$, we have that $t\fun^{m + (n-m)}v$, so that there is a closed term $u$ such that $t\fun^m u\fun^{n-m}v$. But $t\fun^m t'$, so that $t'=u\fun^{n-m}v$. \end{proof} Suppose $t_1$ and $t_2$ are closed terms and $t_1\,t_2$ converges. We must show that $t_1$, $t_2$ and $\overline{t_1}\;\overline{t_2}$ converge and $\overline{t_1t_2} = \overline{\overline{t_1}\;\overline{t_2}}$. Because $t_1\,t_2$ converges and is closed, there is a closed value $v$ such that $t_1\,t_2\fun^*v$. Thus $\overline{t_1\,t_2}=v$, and there is an $n\in\nats$ such that $t_1\,t_2\fun^n v$. Suppose, toward a contraction, that $t_1$ diverges. Thus, by Proposition~C, there is a closed term $t'_1$ such that $t_1\fun^{n+1}t'_1$. Thus $t_1\,t_2\fun^{n+1}t'_1\,t_2$, by Proposition~A(1). But $t_1\,t_2\fun^n v$, so that $n+1\leq n$, by Lemma~\ref{PropDLem}---contradiction. Thus $t_1$ converges, so that there is a closed value $v_1$ such that $t_1\fun^*v_1$ and $\overline{t_1}=v_1$. Thus $t_1\fun^{n_1}v_1$ for some $n_1\in\nats$, so that $t_1\,t_2\fun^{n_1}v_1\,t_2$, by Proposition~A(1). But $t_1\,t_2\fun^n v$, so that $n_1\leq n$ and $v_1\,t_2\fun^{n-n_1}v$, by Lemma~\ref{PropDLem}. Suppose, toward a contradiction, that $t_2$ diverges. Thus, by Proposition~C, there is a closed term $t'_2$ such that $t_2\fun^{n-n_1+1}t'_2$, so that $v_1\,t_2\fun^{n-n_1+1}v_1\,t'_2$, by Proposition~A(2). But $v_1\,t_2\fun^{n-n_1}v$, so that $n-n_1+1\leq n-n_1$, by Lemma~\ref{PropDLem}---contradiction. Thus $t_2$ converges, so that there is a closed value $v_2$ such that $t_2\fun^*v_2$ and $\overline{t_2}=v_2$. Hence $t_2\fun^{n_2}v_2$ for some $n_2\in\nats$, so that $v_1\,t_2\fun^{n_2}v_1\,v_2$, by Proposition~A(2). But $v_1\,t_2\fun^{n-n_1}v$, so that $n_2\leq n-n_1$ and $v_1\,v_2\fun^{n-n_1-n_2}v$, by Lemma~\ref{PropDLem}. Thus $v_1\,v_2\fun^*v$. We showed above that $t_1$ and $t_2$ converge, $\overline{t_1}=v_1$ and $\overline{t_2}=v_2$. And $\overline{t_1}\;\overline{t_2} = v_1\,v_2\fun^*v$, showing that $\overline{t_1}\;\overline{t_2}$ converges and $\overline{\overline{t_1}\;\overline{t_2}} = v$. Finally, we have that $\overline{t_1\,t_2} = v = \overline{\overline{t_1}\;\overline{t_2}}$. \subsection*{Proposition E} Suppose $t_1$ and $t_2$ are closed, and $t_1$, $t_2$ and $\overline{t_1}\;\overline{t_2}$ converge. We must show that $t_1\,t_2$ converges and $\overline{t_1t_2} = \overline{\overline{t_1}\;\overline{t_2}}$. Because $t_1$ converges, there is a closed value $v_1$ such that $t_1\fun^*v_1$, so that $\overline{t_1} = v_1$. Because $t_2$ converges, there is a closed value $v_2$ such that $t_2\fun^*v_2$, so that $\overline{t_2}=v_2$. Thus, $v_1\,v_2=\overline{t_1}\;\overline{t_2}$ converges, so that there is a closed value $v$ such that $v_1\,v_2\fun^* v$. By Proposition~B(1), because $t_1\fun^*v_1$, we have that $t_1\,t_2\fun^*v_1\,t_2$. And, by Proposition~B(2), because $v_1$ is a value and $t_2\fun^*v_2$, we have that $v_1\,t_2\fun^*v_1\,v_2$. Finally, because $t_1\,t_2\fun^*v_1\,t_2\fun^*v_1\,v_2\fun^*v$, we have that $t_1\,t_2\fun^*v$. Thus $t_1\,t_2$ converges and, since $t_1\,t_2\fun^*v$ and $v_1\,v_2\fun^* v$, it follows that \begin{displaymath} \overline{t_1\,t_2} = v = \overline{v_1\;v_2} = \overline{\overline{t_1}\;\overline{t_2}} . \end{displaymath} \subsection*{Proposition F} Let $P$ be the set of all $n\in\nats$ such that, if $n\geq 2$, then, for all closed terms $t_1$, \ldots, $t_n$, if $t_1\,\cdots\,t_n$ converges, then $t_1$, \ldots, $t_n$ and $\overline{t_1}\;\cdots\;\overline{t_n}$ converge and $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$. It will suffice to use ordinary induction to prove that, for all $n\in\nats$, $P(n)$. \begin{itemize} \item (Basis Step)\quad $P(0)$ holds vacuously, because $0\geq 2$ is false. \item (Inductive Step)\quad Suppose $n\in\nats$, and assume the inductive hypothesis, $P(n)$. We must show that $P(n+1)$. Suppose $n+1\geq 2$, $t_1$, \ldots, $t_{n+1}$ are closed terms, and $t_1\,\cdots\,t_{n+1}$ converges. We must show that $t_1$, \ldots, $t_{n+1}$ and $\overline{t_1}\;\cdots\;\overline{t_{n+1}}$ converge and $\overline{t_1\,\cdots\,t_{n+1}} = \overline{\overline{t_1}\;\cdots\;\overline{t_{n+1}}}$. Since $n+1\geq 2$, we have that $n\geq 1$. Hence there are two cases to consider. \begin{itemize} \item Suppose $n=1$. Thus $n+1=2$, so that $t_1$ and $t_2$ are closed terms, and $t_1\,t_2$ converges. We must show that $t_1$, $t_2$ and $\overline{t_1}\;\overline{t_2}$ converge, and that $\overline{t_1\,t_2} = \overline{\overline{t_1}\;\overline{t_2}}$, and this follows by Proposition~D. \item Suppose $n\geq 2$. Thus $t_1$, \ldots, $t_n$, $t_{n+1}$ are closed terms, and $t_1\,\cdots\,t_n\,t_{n+1}$ converges. We must show that $t_1$, \ldots, $t_n$, $t_{n+1}$ and $\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}$ converge and $\overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}}$. Because $(t_1\,\cdots\,t_n)t_{n+1} = t_1\,\cdots\,t_n\,t_{n+1}$ converges, Proposition~D tells us that $t_1\,\cdots\,t_n$, $t_{n+1}$ and $\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}$ converge and \begin{displaymath} \overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{(t_1\,\cdots\,t_n)t_{n+1}} = \overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} . \end{displaymath} Because $n\geq 2$ and $t_1\,\cdots\,t_n$ converges, the inductive hypothesis tells us that $t_1$, \ldots, $t_n$ and $\overline{t_1}\;\cdots\;\overline{t_n}$ converge and $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$. So, we have that $t_1$, \ldots, $t_n$ and $t_{n+1}$ converge. Because $\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}$ converges, $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$ and $\overline{t_{n+1}} = \overline{\overline{t_{n+1}}}$, it follows that $\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\; \overline{\overline{t_{n+1}}}$ converges. Since $\overline{t_1}\;\cdots\;\overline{t_n}$, $\overline{t_{n+1}}$ and $\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\; \overline{\overline{t_{n+1}}}$ converge, Proposition~E tells us that $\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}} = (\overline{t_1}\;\cdots\;\overline{t_n})\overline{t_{n+1}}$ converges and \begin{displaymath} \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}} = \overline{(\overline{t_1}\;\cdots\;\overline{t_n})\overline{t_{n+1}}} = \overline{\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\;\overline{\overline{t_{n+1}}}} . \end{displaymath} Since $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$ and $\overline{t_{n+1}} = \overline{\overline{t_{n+1}}}$, it follows that \begin{displaymath} \overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} = \overline{\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\;\overline{\overline{t_{n+1}}}} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}} . \end{displaymath} Finally, \begin{displaymath} \overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}} . \end{displaymath} \end{itemize} \end{itemize} \subsection*{Proposition G} Let $P$ be the set of all $n\in\nats$ such that, if $n\geq 2$, then, for all closed terms $t_1$, \ldots, $t_n$, if $t_1$, \ldots, $t_n$ and $\overline{t_1}\;\cdots\;\overline{t_n}$ converge, then $t_1\,\cdots\,t_n$ converges and $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$. It will suffice to use ordinary induction to prove that, for all $n\in\nats$, $P(n)$. \begin{itemize} \item (Basis Step)\quad $P(0)$ holds vacuously, because $0\geq 2$ is false. \item (Inductive Step)\quad Suppose $n\in\nats$ and assume the inductive hypothesis, $P(n)$. We must show that $P(n+1)$. Suppose $n+1\geq 2$, $t_1$, \ldots, $t_{n+1}$ are closed terms, and $t_1$, \ldots, $t_{n+1}$ and $\overline{t_1}\;\cdots\;\overline{t_{n+1}}$ converge. We must show that $t_1\,\cdots\,t_{n+1}$ converges and $\overline{t_1\,\cdots\,t_{n+1}} = \overline{\overline{t_1}\;\cdots\;\overline{t_{n+1}}}$. Since $n+1\geq 2$, we have that $n\geq 1$. Hence there are two cases to consider. \begin{itemize} \item Suppose $n=1$. Thus $n+1=2$, so that $t_1$ and $t_2$ are closed terms, $t_1$, $t_2$ and $\overline{t_1}\;\overline{t_2}$ converge. We must show that $t_1\,t_2$ converges and $\overline{t_1\,t_2} = \overline{\overline{t_1}\;\overline{t_2}}$, and this follows by Proposition~E. \item Suppose $n\geq 2$. Thus $t_1$, \ldots, $t_n$, $t_{n+1}$ are closed terms, and $t_1$, \ldots, $t_n$, $t_{n+1}$ and $\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}$ converge. We must show that $t_1\,\cdots\,t_n\,t_{n+1}$ converges and $\overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}}$. Because $(\overline{t_1}\;\cdots\;\overline{t_n})\overline{t_{n+1}} = \overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}$ converges, Proposition~D tells us that $\overline{t_1}\;\cdots\;\overline{t_n}$, $\overline{t_{n+1}}$ and $\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\; \overline{\overline{t_{n+1}}}$ converge, and \begin{displaymath} \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}} = \overline{(\overline{t_1}\;\cdots\;\overline{t_n})\overline{t_{n+1}}} = \overline{\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\; \overline{\overline{t_{n+1}}}} . \end{displaymath} Since $n\geq 2$, and $t_1$, \ldots, $t_n$ and $\overline{t_1}\;\cdots\;\overline{t_n}$ converge, the inductive hypothesis tells us that $t_1\,\cdots\,t_n$ converges and $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$. So, we have that $t_1\,\cdots\,t_n$ and $t_{n+1}$ converge. Because $\overline{\overline{t_1}\;\cdots\;\overline{t_n}}\; \overline{\overline{t_{n+1}}}$ converges, $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$ and $\overline{t_{n+1}} = \overline{\overline{t_{n+1}}}$, it follows that $\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}$ converges. Since $t_1\,\cdots\,t_n$, $t_{n+1}$ and $\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}$ converge, Proposition~E tells us that $t_1\,\cdots\,t_n\,t_{n+1} = (t_1\,\cdots\,t_n)t_{n+1}$ converges and \begin{displaymath} \overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{(t_1\,\cdots\,t_n)t_{n+1}} = \overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} . \end{displaymath} Since $\overline{t_1\,\cdots\,t_n} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}}$ and $\overline{t_{n+1}} = \overline{\overline{t_{n+1}}}$, we have that $\overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} = \overline{\overline{\overline{t_1}\;\cdots\overline{t_n}}\; \overline{\overline{t_{n+1}}}}$. Hence, we have that \begin{displaymath} \overline{t_1\,\cdots\,t_n\,t_{n+1}} = \overline{\overline{t_1\,\cdots\,t_n}\;\overline{t_{n+1}}} = \overline{\overline{\overline{t_1}\;\cdots\overline{t_n}}\; \overline{\overline{t_{n+1}}}} = \overline{\overline{t_1}\;\cdots\;\overline{t_n}\;\overline{t_{n+1}}} . \end{displaymath} \end{itemize} \end{itemize} \end{document}