\documentclass{article}
\newif\ifhandout
%\handouttrue
\handoutfalse
%% Packages
\usepackage{xspace}
\usepackage{mathpartir}

%% Local definitions
\newcommand{\irr}[3]{\inferrule*[right={\scriptsize{#1}},leftskip=3mm,rightskip=3mm]{#2}{#3}}

%% Header
\title{Homework 1 \hspace{3cm} Due: October 7, 2008}
\author{Matthias Blume}

\begin{document}

\maketitle
%% Main

\begin{enumerate}

\item  Consider the rules:
\label{qone}

\begin{mathpar}
\irr{zero}
{ }
{ \mathbf{zero}~\mathbf{nat} }
%
\and
%
\irr{succ}
{ n~\mathbf{nat} }
{ \mathbf{succ}(n)~\mathbf{nat} }
%
\and
%
\irr{nil}
{ }
{ \mathbf{nil}~\mathbf{list} }
%
\and
%
\irr{cons}
{ n~\mathbf{nat} \\ l~\mathbf{list} }
{ \mathbf{cons}(n,l)~\mathbf{list} }
\end{mathpar}

These rules define a set of terms $\mathbf{nat}$ representing natural
numbers in Peano encoding and a set of terms $\mathbf{list}$
representing lists of such numbers.

We can inductively (i.e., recursively) define the following
$\mathit{append}$ function on lists:

\begin{eqnarray*}
\mathit{append}(\mathbf{nil},m) &=& m \\
\mathit{append}(\mathbf{cons}(n,l),m) &=& \mathbf{cons}(n,\mathit{append}(l,m))
\end{eqnarray*}

\begin{enumerate}
\item Represent $\mathit{append}$ as a ternary relation and give its
  definition inductively.
\item Write down a set of inference rules that defines the same
  ternary relation.
\item Prove that the so-defined relation is single-valued, i.e., that
  it represents a binary function.
\end{enumerate}

\item (See Chapter~2.1) Let $s \mapsto s'$ be some arbitrary binary
  relation and let $\mapsto^{*}$ be defined by the following two
  inference rules:

\begin{mathpar}
\irr{refl}
{ }
{ s \mapsto^{*} s }
%
\and
%
\irr{trans}
{ s \mapsto s' \\ s' \mapsto^{*} s'' }
{ s \mapsto^{*} s'' }
\end{mathpar}

Prove that $\mapsto^{*}$ is indeed transitive, i.e., that
$\forall s, s', s'' .~ s \mapsto^{*} s' \wedge s' \mapsto^{*} s''
\Rightarrow s \mapsto^{*} s''$.

\item Consider a language where all values are Peano-encoded natural
  numbers given by the $\mathbf{nat}$ judgment from
  question~\ref{qone}.  The expressions $e$ of the language shall be
  of one of the following forms: $\mathbf{zero}$ representing the
  constant $0$, $\mathbf{succ}(e)$ representing the operation of
  producing the successor of a given argument, $\mathbf{pred}(e)$
  representing the operation of producing the \emph{natural}
  predecessor \footnote{The natural predecessor of $n+1$ is $n$, and
    the natural predecessor of $0$ is taken to be $0$.}  of a given
  argument, and $\mathbf{if0}(e_1,e_2,e_3)$ representing a tests
  of $e_1$ for being $0$, returning the result of $e_2$ if it is or
  the result of $e_3$ if it is not.
  
  \begin{enumerate}
    \item Give a definition of $e$ in BNF style.
    \item Give equivalent inference rules for a judgment
      $e~\mathbf{exp}$ which holds if $e$ is an expression of the
      language.
    \item Give a set of inference rules for judgments of the form $e
      \Rightarrow n$ where $e$ is an expression and $n$ is a natural
      number (in Peano-encoding).  The judgment should express the
      ``evaluates-to'' relation in the style of a big-step operational
      semantics and must correspond to the informal description given
      above.
    \item Prove that if $e \Rightarrow n$ is derivable, then so is
      $e~\mathbf{exp}$ as well as $n~\mathbf{nat}$.
    \item Prove that the relation $\Rightarrow$ defined
      by your rules is single-valued.
  \end{enumerate}
  
\end{enumerate}

\end{document}

