\documentclass[11pt]{article}
\usepackage{fullpage}
\usepackage{pslatex}
\usepackage{amsmath,proof,amsthm,amssymb}

%% part of a problem
\newcommand{\task}[2]
  {\bigskip \noindent
   {\bf Task #1} (#2 pts).}

\newcommand{\ectask}[1]
  {\bigskip \noindent
   {\bf Task #1} (Extra Credit).}

\newcommand{\dsd}[1]{\ensuremath{\mathsf{#1}}}
\newcommand{\irl}[1]{\texttt{#1}}
\newcommand{\ttt}[1]{\texttt{#1}}
\newcommand{\true}[1]{\ensuremath{#1 \, \dsd{true}}}
\newcommand{\even}[1]{\ensuremath{\dsd{even}(#1)}}
\newcommand{\odd}[1]{\ensuremath{\dsd{odd}(#1)}}
\newcommand{\suc}[1]{\ensuremath{\dsd{s} \: #1}}

\title{Assignment 5: \\
       Arithmetic}
\author{15-317: Constructive Logic}
\date{Out: Thursday, October 9, 2008 \\
Due: Thursday, October 16, 2008, before class}

\begin{document}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\maketitle

\section{Tutch Proofs (10 pts)}

In Tutch, the recursor \ttt{R(t,M0,x.u.M1(x,u))}
is written as a primitive recursion schema:

\begin{verbatim}
   rec t of f 0 => M0 
          | f (s x) => M1(x,f(x)) end;
\end{verbatim}

For example, here is a defintion of addition:

\begin{verbatim}
val plus : nat -> nat -> nat =
fn x => rec x of 
   p 0 => fn y => y
 | p (s n) => fn y => s (p n y)
 end;
\end{verbatim}

Here's an example of a proof that uses induction over natural numbers.
\begin{verbatim}
proof plus0R : (!m:nat. m = plus m 0) =
begin
[m : nat;
 
 % the 0 case
 0 = plus 0 0;

 % the s case; note that it binds two assumptions
 [x : nat , x = plus x 0;
  s x = plus (s x) 0];

 m = plus m 0];
(!m:nat. m = plus m 0);
end;
\end{verbatim}

\task{1}{15} Your task is to prove transitivity of equality.  Hint: this
will be longer than any Tutch proof you have done so far.  

\begin{verbatim}
proof eqtrans : !x:nat. !y:nat. !z:nat. (x = y) => (y = z) => (x = z);
\end{verbatim}

\section{Proof terms (10 pts)}

Here is an example proof term:

\begin{verbatim}
term plus0R : (!m:nat. m = plus m 0) =
fn m => rec m of 
          p 0 => eq0
        | p (s x) => eqS (p x)
end; 
\end{verbatim}

\task{1}{10} Prove the following:

\begin{verbatim}
term eqrefl : (!m:nat. m = m);
term plusSR : (!m:nat. !n:nat. s (plus m n) = plus m (s n));
\end{verbatim}

Hint: you will need to use \ttt{eqrefl} as a lemma to prove
\ttt{plusSR}.

The rules for equality are named as follows:
\[
\infer{\ttt{eq0 : (0 = 0)}}{}
\quad
\infer{\ttt{eqSS M : (s t = s t')}}{\ttt{M : (t = t')}}
\quad
\infer{\ttt{eqESS M : (t = t')}}{\ttt{M : (s t = s t')}}
\quad
\infer{\ttt{eqE0S M : J}}{\ttt{M : 0 = s t}}
\quad
\infer{\ttt{eqES0 M : J}}{\ttt{M : s t = 0}}
\]

\section{Even and Odd (20 pts)}

Consider the following rules for even and odd:

\[
\infer[evI_0]{\true{\even{0}}}{}
\qquad
\infer[evI_S]{\true{\even{\suc{n}}}}{\true{\odd{n}}}
\qquad
\infer[oddI_S]{\true{\odd{\suc{n}}}}{\true{\even{n}}}
\]

\[
\infer[oddE_0]{J}{\true{\odd{0}}}
\qquad
\infer[evE_S]{\true{\odd{n}}}{\true{\even{\suc{n}}}}
\qquad
\infer[oddE_S]{\true{\even{n}}}{\true{\odd{\suc{n}}}}
\]

\task{1}{5} Prove that these rules are locally sound.

\task{2}{5} Give a natural deduction derivation of the following:

\[
\true{(\forall x:\dsd{nat}.\even{x} \vee \odd{x})} 
\]

Be sure to label each inference with the rule used.

\task{3}{10} Give a natural deduction derivation for the following:

\[
\true{(\forall x:\dsd{nat}.(\even{x} \supset \exists m:\dsd{nat}.(x = 2
  * m)) \wedge (\odd{x} \supset \exists m:\dsd{nat}.(x = 2 * m + 1)))}
\]

Be sure to label each inference with the rule used.  State what
properties of addition and multiplication you need to complete the
derivation (e.g., $2m + 2 = 2(m+1)$), but you do not need to give
derivations for these equalities.

\section{Handin Instructions}

\begin{itemize}
\item 
To run Tutch with the requirements files, run

\begin{verbatim}
/afs/andrew/course/15/317/bin/tutch -r hw05.req <your file>
\end{verbatim}

This uses the requirements file
\verb|/afs/andrew/course/15/317/req/hw05.req|.

\item To submit your Tutch proofs, run

\begin{verbatim}
/afs/andrew/course/15/317/bin/submit -r hw05.req <your file>
\end{verbatim}

To check the status of your submission, run
\verb|/afs/andrew/course/15/317/bin/status hw05|.

\item Submit your written work at the beginning of class, or, if you
  wish to do an electronic handin, copy a PDF to 

\begin{verbatim}
/afs/andrew/course/15/317/submit/<yourid>/hw05.pdf
\end{verbatim}

\end{itemize}

\end{document}
