\documentclass{article} \input{exer-defs} %\renewcommand{\thepage}{} \newcommand{\Zero}{\mathsf{zero}} \newcommand{\Succ}{\mathsf{succ}} \newcommand{\NATS}{\mathsf{Nats}} \newcommand{\PLUS}{\mathsf{Plus}} \begin{document} \begin{center}\large\bf CIS 705 --- Programming Languages --- Spring 2009 \end{center} \begin{center}\Large\bf Assignment 1 \end{center} \begin{center}\large\bf Model Answers \end{center} \section*{Exercise 1} \renewcommand{\thesection}{1} \theoremnumber{1} Suppose $t_2\in\NATS$. It will suffice to show that, for all $t_1\in\NATS$, there is a $t_3\in\NATS$ such that $(t_1,t_2,t_3)\in\PLUS$. Let \begin{displaymath} P=\setof{t_1\in\NATS}{\eqtxtr{there is a} t_3\in\NATS\eqtxt{such that}(t_1,t_2,t_3)\in\PLUS} . \end{displaymath} It will suffice to show that, for all $t_1\in\NATS$, $P(t_1)$, and we show this by structural induction on $\NATS$. \begin{description} \item[\quad(Zero)] We must show $P(\Zero)$, i.e., that there is a $t_3\in\NATS$ such that $(\Zero,t_2,t_3)\in\PLUS$. By (Plus-Zero), we have that $t_2\in\NATS$ and $(\Zero,t_2,t_2)\in\PLUS$. \item[\quad(Succ)] Suppose $t_1\in\NATS$, and assume the inductive hypothesis: $P(t_1)$, i.e., that there is a $t_3\in\NATS$ such that $(t_1,t_2,t_3)\in\PLUS$. We must show $P(\Succ\;t_1)$, i.e., that there is a $t'_3\in\NATS$ such that $(\Succ\;t_1,t_2,t'_3)\in\PLUS$. Since $(t_1,t_2,t_3)\in\PLUS$ and by (Plus-Succ), we have that $\Succ\;t_3\in\NATS$ and $(\Succ\;t_1,t_2,\Succ\;t_3)\in\PLUS$. \end{description} \section*{Exercise 2} \renewcommand{\thesection}{2} \theoremnumber{1} Let \begin{displaymath} P = \setof{(t_1,t_2,t_3)\in\NATS\times\NATS\times\NATS}{\eqtxtr{for all} t'_3\in\NATS,\eqtxt{if} (t_1,t_2,t'_3)\in\PLUS,\eqtxt{then}t_3=t'_3} . \end{displaymath} It will suffice to show that, \begin{displaymath} \eqtxtr{for all}t_1,t_2,t_3\in\NATS,\eqtxt{if}(t_1,t_2,t_3)\in\PLUS, \eqtxt{then}P(t_1,t_2,t_3) . \end{displaymath} (Given this result, we would proceed as follows. Suppose $t_1,t_2,t_3,t'_3\in\NATS$, $(t_1,t_2,t_3)\in\PLUS$ and $(t_1,t_2,t'_3)\in\PLUS$. We must show that $t_3=t'_3$. By the result, we have that $P(t_1,t_2,t_3)$, i.e., for all $t'_3\in\NATS$, if $(t_1,t_2,t'_3)\in\PLUS$, then $t_3=t'_3$. But $t'_3\in\NATS$ and $(t_1,t_2,t'_3)\in\PLUS$, so that $t_3=t'_3$.) We proceed by induction on $\PLUS$. \begin{description} \item[\quad(Plus-Zero)] Suppose $t\in\NATS$. We must show that $P(\Zero, t, t)$, i.e., for all $t'_3\in\NATS$, if $(\Zero, t, t'_3)\in\PLUS$, then $t=t'_3$. Suppose $t'_3\in\NATS$ and $(\Zero, t, t'_3)\in\PLUS$. We must show that $t=t'_3$, and this follows by the inversion lemma for $\PLUS$. \item[\quad(Plus-Succ)] Suppose $t_1,t_2,t_3\in\NATS$ and $(t_1,t_2,t_3)\in\PLUS$, and assume the inductive hypothesis: $P(t_1,t_2,t_3)$, i.e., for all $t'_3\in\NATS$, if $(t_1,t_2,t'_3)\in\PLUS$, then $t_3=t'_3$. We must show that $P(\Succ\;t_1,t_2,\Succ\;t_3)$, i.e., for all $t'_3\in\NATS$, if $(\Succ\;t_1,t_2,t'_3)\in\PLUS$, then $\Succ\;t_3=t'_3$. Suppose $t'_3\in\NATS$ and $(\Succ\;t_1,t_2,t'_3)\in\PLUS$. We must show that $\Succ\;t_3=t'_3$. By the inversion lemma for $\PLUS$, we have that there is a $t''_3\in\NATS$ such that $t'_3=\Succ\;t''_3$ and $(t_1,t_2,t''_3)\in\PLUS$. By the inductive hypothesis, we have that $t_3=t''_3$. Thus $\Succ\;t_3=\Succ\;t''_3=t'_3$. \end{description} \section*{Exercise 3} \renewcommand{\thesection}{3} \theoremnumber{1} Let $P$ be the set of all $(t_1,t_2,s_1)\in\NATS\times\NATS\times\NATS$ such that, \begin{displaymath} \eqtxtr{for all} t_3,s_2,s_3\in\NATS, \eqtxt{if} (s_1,t_3,s_2)\in\PLUS \eqtxt{and} (t_2,t_3,s_3)\in\PLUS, \eqtxt{then} (t_1,s_3,s_2)\in\PLUS . \end{displaymath} It will suffice to show that, \begin{displaymath} \eqtxtr{for all}t_1,t_2,s_1\in\NATS,\eqtxt{if}(t_1,t_2,s_1)\in\PLUS, \eqtxt{then}P(t_1,t_2,s_1) . \end{displaymath} (Given this result, we would proceed as follows. Suppose $t_1,t_2,t_3,s_1,s_2,s_3\in\NATS$, $(t_1,t_2,s_1)\in\PLUS$, $(s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$. We must show that $(t_1,s_3,s_2)\in\PLUS$. By the result, we have that $P(t_1,t_2,s_1)$, i.e., for all $t_3,s_2,s_3\in\NATS$, if $(s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, then $(t_1,s_3,s_2)\in\PLUS$. But $t_3,s_2,s_3\in\NATS$, $(s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, and thus we can conclude that $(t_1,s_3,s_2)\in\PLUS$.) We proceed by induction on $\PLUS$. \begin{description} \item[\quad(Plus-Zero)] Suppose $t\in\NATS$. We must show that $P(\Zero, t, t)$, i.e., for all $t_3,s_2,s_3\in\NATS$, if $(t,t_3,s_2)\in\PLUS$ and $(t,t_3,s_3)\in\PLUS$, then $(\Zero,s_3,s_2)\in\PLUS$. Suppose $t_3,s_2,s_3\in\NATS$, $(t,t_3,s_2)\in\PLUS$ and $(t,t_3,s_3)\in\PLUS$. We must show that $(\Zero,s_3,s_2)\in\PLUS$. Since $(t,t_3,s_2)\in\PLUS$ and $(t,t_3,s_3)\in\PLUS$, Exercise~2 tells us that $s_2=s_3$. Thus, by (Plus-Zero), we have that $(\Zero,s_3,s_2)=(\Zero,s_2,s_2)\in\PLUS$. \item[\quad(Plus-Succ)] Suppose $t_1,t_2,s_1\in\NATS$ and $(t_1,t_2,s_1)\in\PLUS$, and assume the inductive hypothesis: $P(t_1,t_2,s_1)$, i.e., for all $t_3,s_2,s_3\in\NATS$, if $(s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, then $(t_1,s_3,s_2)\in\PLUS$. We must show that $P(\Succ\;t_1,t_2,\Succ\;s_1)$, i.e., for all $t_3,s_2,s_3\in\NATS$, if $(\Succ\;s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, then $(\Succ\;t_1,s_3,s_2)\in\PLUS$. Suppose $t_3,s_2,s_3\in\NATS$, $(\Succ\;s_1,t_3,s_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$. We must show that $(\Succ\;t_1,s_3,s_2)\in\PLUS$. Because $(\Succ\;s_1,t_3,s_2)\in\PLUS$, the inversion lemma for $\PLUS$ tells us that there is an $s'_2\in\NATS$ such that $s_2=\Succ\;s'_2$ and $(s_1,t_3,s'_2)\in\PLUS$. By the inductive hypothesis, substituting $s'_2$ for $s_2$, we have that if $(s_1,t_3,s'_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, then $(t_1,s_3,s'_2)\in\PLUS$. But $(s_1,t_3,s'_2)\in\PLUS$ and $(t_2,t_3,s_3)\in\PLUS$, and thus $(t_1,s_3,s'_2)\in\PLUS$. Hence $(\Succ\;t_1,s_3,s_2)=(\Succ\;t_1,s_3,\Succ\;s'_2)\in\PLUS$, by (Plus-Succ). \end{description} \section*{Exercise 4} \renewcommand{\thesection}{4} \theoremnumber{1} First, we prove two lemmas. \begin{lemma} \label{Ex4Lem1} For all $t\in\NATS$, $(t,\Zero,t)\in\PLUS$. \end{lemma} \begin{proof} Let \begin{displaymath} P = \setof{t\in\NATS}{(t,\Zero,t)\in\PLUS}. \end{displaymath} It will suffice to show that, for all $t\in\NATS$, $P(t)$, and we show this by structural induction on $\NATS$. \begin{description} \item[\quad(Zero)] We must show $P(\Zero)$, i.e., that $(\Zero,\Zero,\Zero)\in\PLUS$. And this follows by (Plus-Zero). \item[\quad(Succ)] Suppose $t\in\NATS$, and assume the inductive hypothesis: $P(t)$, i.e., that $(t,\Zero,t)\in\PLUS$. We must show $P(\Succ\;t)$, i.e., $(\Succ\;t,\Zero,\Succ\;t)\in\PLUS$, and this follows from the inductive hypothesis by (Plus-Succ). \end{description} \end{proof} \begin{lemma} \label{Ex4Lem2} For all $t_1,t_2,t_3\in\NATS$, if $(t_1,t_2,t_3)\in\PLUS$, then $(t_1,\Succ\;t_2,\Succ\;t_3)\in\PLUS$. \end{lemma} \begin{proof} Let \begin{displaymath} P = \setof{(t_1,t_2,t_3)\in\NATS\times\NATS\times\NATS}% {(t_1,\Succ\;t_2,\Succ\;t_3)\in\PLUS} . \end{displaymath} It will suffice to show that, \begin{displaymath} \eqtxtr{for all}t_1,t_2,t_3\in\NATS,\eqtxt{if}(t_1,t_2,t_3)\in\PLUS, \eqtxt{then}P(t_1,t_2,t_3) . \end{displaymath} (Given this result, we would proceed as follows. Suppose $t_1,t_2,t_3\in\NATS$ and $(t_1,t_2,t_3)\in\PLUS$. We must show that $(t_1,\Succ\;t_2,\Succ\;t_3)\in\PLUS$. By the result, we have that $P(t_1,t_2,t_3)$, i.e., $(t_1,\Succ\;t_2,\Succ\;t_3)\in\PLUS$.) We proceed by induction on $\PLUS$. \begin{description} \item[\quad(Plus-Zero)] Suppose $t\in\NATS$. We must show that $P(\Zero, t, t)$, i.e., $(\Zero, \Succ\;t, \Succ\;t)\in\PLUS$, and this follows by (Plus-Zero). \item[\quad(Plus-Succ)] Suppose $t_1,t_2,t_3\in\NATS$ and $(t_1,t_2,t_3)\in\PLUS$, and assume the inductive hypothesis: $P(t_1,t_2,t_3)$, i.e., $(t_1, \Succ\;t_2, \Succ\;t_3)\in\PLUS$. We must show that $P(\Succ\;t_1,t_2,\Succ\;t_3)$, i.e., $(\Succ\;t_1, \Succ\;t_2, \Succ(\Succ\;t_3))\in\PLUS$, which follows from the inductive hypothesis by (Plus-Succ). \end{description} \end{proof} Now, we use our lemmas to prove the main result. Let \begin{displaymath} P = \setof{(t_1,t_2,t_3)\in\NATS\times\NATS\times\NATS}% {(t_2,t_1,t_3)\in\PLUS} . \end{displaymath} It will suffice to show that, \begin{displaymath} \eqtxtr{for all}t_1,t_2,t_3\in\NATS,\eqtxt{if}(t_1,t_2,t_3)\in\PLUS, \eqtxt{then}P(t_1,t_2,t_3) . \end{displaymath} (Given this result, we would proceed as follows. Suppose $t_1,t_2,t_3\in\NATS$ and $(t_1,t_2,t_3)\in\PLUS$. We must show that $(t_2,t_1,t_3)\in\PLUS$. By the result, we have that $P(t_1,t_2,t_3)$, i.e., $(t_2,t_1,t_3)\in\PLUS$.) We proceed by induction on $\PLUS$. \begin{description} \item[\quad(Plus-Zero)] Suppose $t\in\NATS$. We must show that $P(\Zero, t, t)$, i.e., $(t, \Zero, t)\in\PLUS$, which follows by Lemma~\ref{Ex4Lem1}. \item[\quad(Plus-Succ)] Suppose $t_1,t_2,t_3\in\NATS$ and $(t_1,t_2,t_3)\in\PLUS$, and assume the inductive hypothesis: $P(t_1,t_2,t_3)$, i.e., $(t_2, t_1, t_3)\in\PLUS$. We must show that $P(\Succ\;t_1,t_2,\Succ\;t_3)$, i.e., $(t_2, \Succ\;t_1, \Succ\;t_3)\in\PLUS$. Since $(t_2, t_1, t_3)\in\PLUS$, Lemma~\ref{Ex4Lem2} tells us that $(t_2, \Succ\;t_1, \Succ\;t_3)\in\PLUS$. \end{description} \end{document}