\documentclass[11pt]{article}

\usepackage[margin=1.45in]{geometry}
\usepackage{proof}
\usepackage{amsmath,amsthm,amssymb}
\usepackage[raiselinks=false,colorlinks=true,citecolor=blue,urlcolor=blue,linkcolor=blue,bookmarksopen=true,dvips]{hyperref}

% font{
\usepackage{pxfonts}
%% fix sans serif
\renewcommand\sfdefault{cmss}
\DeclareMathAlphabet{\mathsf}{OT1}{cmss}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{OT1}{cmss}{b}{n}
% }font

\theoremstyle{definition}
\newtheorem{task}{Task}
\newtheorem{ectask}{Extra Credit Task}

\newcommand\pimp{\mathrel{\supset}}
\newcommand\pand{\mathrel{\wedge}}
\newcommand\por{\mathrel{\vee}}
\newcommand\ptrue{\top}
\newcommand\pfalse{\bot}
\newcommand\pspades{\spadesuit}
\newcommand\pforall[3]{\forall #1{:}#2.\, #3}
\newcommand\pexists[3]{\exists #1{:}#2.\, #3}
\newcommand\qtri\blacktriangledown
\newcommand\ptri[3]{\qtri #1{:}#2.\, #3}

\newcommand\eqn{\mathrel{=_N}}
\newcommand\z{\mathsf{0}}
\newcommand\s{\mathsf{s}}
\newcommand\Cases{\mathit{Cases}}

\newcommand\true{\;\textit{true}}
\newcommand\false{\;\textit{false}}
\newcommand\contra{\#}
\newcommand\ddd{\raisebox{0.2em}[1.3em]{$\vdots$}}
\newcommand\com{\raisebox{0.3em}{$\ ,\ \ $}}
\newcommand\hyp[2][]{\infer[#1]{#2}{}}
\newcommand\sub[3]{\infer[#2]{#3}{#1}}

\newcommand{\lred}{\mathrel{\raisebox{0.5em}{$\Longrightarrow_R$}}}
\newcommand{\lexp}{\mathrel{\raisebox{0.5em}{$\Longrightarrow_E$}}}

\newcommand{\DD}{\mathcal{D}}
\newcommand{\EE}{\mathcal{E}}
\newcommand{\FF}{\mathcal{F}}
\newcommand{\GG}{\mathcal{G}}

% some URLs used below
\newcommand\tutchGuideURL{http://www.cs.cmu.edu/~fp/courses/15317-f09/software/tutch/doc/html/tutch_ovr.html}
\newcommand\tutchProofTermsURL{http://www.cs.cmu.edu/~fp/courses/15317-f09/software/tutch/doc/html/tutch_4.html\#SEC18}
\newcommand\tutchProofTermsRefURL{http://www.cs.cmu.edu/~fp/courses/15317-f09/software/tutch/doc/html/tutch_9.html\#SEC28}
\newcommand\tutchArithmeticURL{http://www.cs.cmu.edu/~fp/courses/15317-f09/software/tutch/doc/html/tutch_7.html\#SEC21}

\title{Constructive Logic (15-317), Fall 2009 \\
       Assignment 3: Natural Numbers\\ and Classical Reasoning}
\author{William Lovas \texttt{(wlovas@cs)}}
\date{Out: Thursday, September 17, 2009 \\
      Due: Thursday, September 24, 2009 (before class)}

\begin{document}
\maketitle

This homework assignment aims to help draw connections between the material
in this course and things you may be familiar with from prior mathematical
experience.  Natural numbers and induction are central to many areas of
computer science, and these exercises will help you understand how they are
defined and used from a formal perspective.  Similarly, classical logic is
pervasive in traditional mathematics, and these exercises will give you a
chance to experience formal classical reasoning.

The Tutch portion of your work (Section~\ref{sec:tutch}) should be submitted
electronically using the command
\begin{verbatim}
  $ /afs/andrew/course/15/317/bin/submit -r hw03 <files...>
\end{verbatim}
from any Andrew server.  You may check the status of your submission by
running the command
\begin{verbatim}
  $ /afs/andrew/course/15/317/bin/status hw03
\end{verbatim}
If you have trouble running either of these commands, email William.

The written portion of your work (Section~\ref{sec:classical}) should be
submitted at the beginning of class.  If you are familiar with \LaTeX, you
are encouraged to use this document as a template for typesetting your
solutions, but you may alternatively write your solutions \textit{neatly}
by hand.

\section{Tutch Proofs (20 points)}
\label{sec:tutch}

Recall from recitation that Tutch's notation for the recursor $R(t, M_0,
x.u.\, M_s(x, u))$ is a primitive recursion schema where the recursive copy of
the function is bound locally:
\begin{quote}
\begin{tabbing}
  \verb'rec' $\;t\;$ \=\verb"of f 0 =>" $M_0$ \\
                     \>\verb" | f (s" $x$\verb") =>"
                        $M_s(x, $\verb"f("$x$\verb")"$)$ \\
  \verb'end'
\end{tabbing}
\end{quote}
(Note the \verb'end' keyword.)  Using this, we defined addition as follows:
\begin{verbatim}
  val plus : nat -> nat -> nat =
    fn x => fn y =>
      rec x of p 0 => y
             | p (s x') => s (p x')
      end;
\end{verbatim}
Then we were able to prove properties of addition by induction over natural
numbers, for instance, the property that if its second argument is zero,
the result is the first argument:
\begin{verbatim}
  proof plusN0N : !n:nat. (plus n 0 = n) =
  begin
    [ n:nat;

      %%%% proceed by induction on n
      %% case n = 0.  TS: plus 0 0 = 0
      plus 0 0 = 0;

      %% case n = s n'.  TS: n':nat, plus n' 0 = n'
      %%                          |- plus (s n') 0 = (s n')
      [ n':nat, plus n' 0 = n';
        plus (s n') 0 = s n' ];

      %% apply induction to conclude:
      plus n 0 = n ];

    !n:nat. plus n 0 = n
  end;
\end{verbatim}
As usual, given the premises of an inference rule, Tutch allows you to derive
the rule's conclusion; in this case, we're applying the rule of induction,
$\textsf{nat}E^{n',u}$, with the third premise being given by the
hypothetical frame.  While attempting to conclude an equality between
natural numbers, Tutch reduces terms and employs the following rules of
inference:
  \[
  \infer[{\eqn}I_\z]{\z = \z}{}
  \quad
  \infer[{\eqn}I_\s]{\s\ n = \s\ n}{n = n}
  \qquad
  \infer[{\eqn}E_{\z\s}]{J}{\z = \s\ n}
  \quad
  \infer[{\eqn}E_{\s\z}]{J}{\s\ n = \z}
  \quad
  \infer[{\eqn}E_{\s\s}]{m = n}{\s\ m = \s\ n}
  \]
As usual, you can run Tutch with the \verb'-v' parameter to see which rules
it's using to justify each line.

For more examples involving arithmetic, see
\href{\tutchArithmeticURL}{Chapter~7} of the
\href{\tutchGuideURL}{\textit{Tutch User's Guide}}.

\begin{task}[3 pts]
Define multiplication in terms of addition.
\begin{verbatim}
  val times : nat -> nat -> nat
\end{verbatim}
\end{task}

\begin{task}[3 pts]
Prove by induction that anything multiplied by zero is zero.
\begin{verbatim}
  proof timesN00 : !n:nat. (times n 0 = 0)
\end{verbatim}
\end{task}

To construct a proof term for an equality, you can access the rules above
by using the constants \verb'eq0', \verb'eqS (...)', \verb'eqE0S (...)',
\verb'eqES0 (...)', and \verb'eqESS'.

\begin{task}[2 pts]
Give a proof term for \verb'timesN00' using a recursion schema.
\begin{verbatim}
  term timesN00 : !n:nat. (times n 0 = 0)
\end{verbatim}
\end{task}

\begin{task}[12 pts]
Show that equality on natural numbers is symmetric by proving the following
theorems in Tutch using induction.
\begin{verbatim}
  proof symmEq0 : !n:nat. (0 = n => n = 0)
  proof symmEqS : !m:nat. (!x:nat. m = x => x = m)
                       => !n:nat. (s m = n => n = s m)
  proof symmEq : !m:nat. !n:nat. (m = n => n = m)
\end{verbatim}
\textbf{Pro Tip:} You can use any proposition you've proven as a lemma
simply by stating the proposition in your proof.  In the above, your proof
of \verb'symmEq' can appeal to \verb'symmEq0' and \verb'symmEqS'.
\end{task}

On Andrew machines, you can check your progress against the requirements
file \texttt{/afs/andrew/course/15/317/req/hw03.req} by running the command
\begin{verbatim}
  $ /afs/andrew/course/15/317/bin/tutch -r hw03 <files...>
\end{verbatim}

\section{Classical Logic (20 points)}
\label{sec:classical}

\subsection{Principle of Bivalence}

Since classically, every proposition is either true or false, classical
logicians often make use of the following bivalence principle:
\[
  \infer[\Cases^{u,k}]{J}
        {\deduce[\ddd]{J}{\hyp[u]{A \true}}
       & \deduce[\ddd]{J}{\hyp[k]{A \false}}}
\]
\begin{task}[4 pts]
Show how this principle can be derived using the rules given in lecture.
You may use any rules, including ones we showed derivable.
\end{task}

\subsection{Natural Deduction for Falsehood}
Although we effectively defined $A \false$ as a judgement-level macro
instead of defining it by giving rules to conclude it, many quite
``natural'' inference rules are derivable given our definition.

\begin{task}[10 pts]
Using our definition of falsehood as $A \false = \deduce[\ddd]{\contra}{A
\true}$, show that the following rules are derivable:
\[
  \infer[{\por}_f I]{A \por B \false}{A \false & B \false}
  \qquad\quad
  \infer[{\por}_f E_L]{A \false}{A \por B \false}
  \qquad
  \infer[{\por}_f E_R]{B \false}{A \por B \false}
\]
\[
  \infer[{\pand}_f I_L]{A \pand B \false}{A \false}
  \qquad
  \infer[{\pand}_f I_R]{A \pand B \false}{B \false}
\]
\end{task}

\begin{ectask}[3 extra credit pts]
Can you show the following rule derivable?
\[
  \infer[{\pand}_f E^{k,\ell}]{J}
        {A \pand B \false
       & \deduce[\ddd]{J}{\hyp[k]{A \false}}
       & \deduce[\ddd]{J}{\hyp[\ell]{B \false}}}
\]
If not, can you explain why?
\end{ectask}

\subsection{The Prover's Dilemma}

A humorous example of how classical logic sometimes runs counter to our
intuitions is the Drinker's Paradox:
\begin{quote}
  \textbf{Drinker's Paradox:}
  $\pexists x \tau {(D(x) \pimp \pforall y \tau {D(y)})}$
\end{quote}
In words, there's someone at the pub for whom if he drinks, then everybody
drinks---someone's always the life of the party.

In our setting, we still can't prove this even using classical reasoning,
since our domains of quantification may still be empty.  However, there's a
propositional analogue of the Drinker's Paradox that we might call the
Prover's Dilemma:
\begin{quote}
  \textbf{Prover's Dilemma:} $(A \pimp A \pand B) \por (B \pimp A \pand B)$
\end{quote}
We call it so because we can imagine someone wanting to prove both $A$ and
$B$, and the proposition above seemingly gives the prover a tantalizing
time-saving shortcut: one of the results he requires implies both of
them!  The dilemma is to figure out which.

\begin{task}[3 pts]
Prove a related theorem using classical reasoning:
$(A \pimp B) \por (B \pimp A)$.
\end{task}

\begin{task}[3 pts]
Using the above theorem as a lemma (i.e. assuming a deduction of it), give
a deduction of the Prover's Dilemma: $(A \pimp A \pand B) \por (B \pimp A
\pand B)$.
\end{task}

\end{document}
