\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}
\usepackage{tabls}

%\setlength{\inferLineSkip}{4pt}

% 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}

\newtheorem*{theorem}{Theorem}
\newtheorem*{lemma}{Lemma}

\newcommand\pimp{\mathrel{\supset}}
\newcommand\pand{\mathrel{\wedge}}
\newcommand\por{\mathrel{\vee}}
\newcommand\ptrue{\top}
\newcommand\pfalse{\bot}
\newcommand\pnot{\neg}
\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{z}}
\newcommand\s{\mathsf{s}}
\newcommand\Cases{\mathit{Cases}}
\newcommand\ii{\mathsf{i}}
\newcommand\oo{\mathsf{o}}

\newcommand\true{\;\textit{true}}
\newcommand\false{\;\textit{false}}
\newcommand\contra{\ \,\#\,\ }
\newcommand\seq{\longrightarrow}
\newcommand\Seq{\Longrightarrow}
\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\dec{{:}}
\newcommand\has{:}
\newcommand\semi{\,;\,}

\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\twelfWithEmacsURL{http://twelf.plparty.org/wiki/Twelf_with_Emacs}
\newcommand\twelfWithoutEmacsURL{http://twelf.plparty.org/wiki/Twelf_without_Emacs}
\newcommand\twelfWikiURL{http://twelf.plparty.org/wiki/Main_Page}

\title{Constructive Logic (15-317), Fall 2009 \\
       Assignment 9: Proving Metatheorems in Twelf}
\author{William Lovas \texttt{(wlovas@cs)}}
\date{Out: Thursday, November 12, 2009 \\
      Due: Thursday, November 19, 2009 (before class)}

\begin{document}
\maketitle

In this assignment, you'll review an important metatheorem, the Identity
Theorem, and see how its proof is represented in Twelf as a well-moded
total logic program.  You should submit the written portion of your work
(Section~\ref{sec:paper}) at the beginning of class, and you should submit
your Twelf code (Section~\ref{sec:twelf}) by copying it to the directory
\begin{verbatim}
  /afs/andrew/course/15/317/submit/<userid>/hw09
\end{verbatim}
where \verb'<userid>' is replaced with your Andrew ID\@.  Submit a file
with the same name as the starter code, \verb'identity.elf', which is
available from the course website.

Some tutorial notes are available via the web on
\href{\twelfWithEmacsURL}{using Twelf with Emacs} and
\href{\twelfWithoutEmacsURL}{using Twelf without Emacs}.  These are part of
the \href{\twelfWikiURL}{Twelf Wiki}, a resource that you may find helpful
while learning Twelf.

\section{Identity Theorem on Paper (10 points)}
\label{sec:paper}

In Figure~\ref{fig:rules}, you will find the rules we gave earlier for the
classical sequent calculus.  Recall that a sequent $\Gamma \contra \Delta$
can be interpreted in two ways:
\begin{enumerate}
  \item If every proposition in $\Gamma$ is true and every proposition in
      $\Delta$ is false, then they are in contradiction.
  \item If every proposition in $\Gamma$ is true, then at least one
      proposition in $\Delta$ is true.
\end{enumerate}
Under the first interpretation, the Identity Theorem says that if $A$ is
both true and false, we have a contradiction.  Under the second, it says
that $A$ follows from itself.

\begin{figure}
\begin{center}
  \[
  \begin{array}{cc}
    \multicolumn{2}{c}{
    \infer[\mathrm{init}]{\Gamma, P \contra P, \Delta}{}
    }
    \\[1em]
    \infer[{\por}R]
          {\Gamma \contra A \por B, \Delta}
          {\Gamma \contra A, B, \Delta}
    \quad\qquad & \qquad\quad
    \infer[{\por}L]
          {\Gamma, A \por B \contra \Delta}
          {\Gamma, A \contra \Delta & \Gamma, B \contra \Delta}
    \\[1em]
    \infer[{\pnot}R]
          {\Gamma \contra \pnot A, \Delta}
          {\Gamma, A \contra \Delta}
    \quad\qquad & \qquad\quad
    \infer[{\pnot}L]
          {\Gamma, \pnot A \contra \Delta}
          {\Gamma \contra A, \Delta}
  \end{array}
  \]
\caption{Classical sequent calculus.}
\label{fig:rules}
\end{center}
\end{figure}

\begin{task}[10 pts]
Prove the Identity Theorem for the classical sequent calculus: for any
proposition $A$, we can derive $A \contra A$.
\end{task}

\section{Identity Theorem in Twelf (30 points)}
\label{sec:twelf}

On the course website, you will find a file of starter code
\verb'identity.elf' defining the syntax of propositions and the
rules of inference.  Recall that we represent propositions $A$ in $\Gamma$
as hypotheses \verb'true A' and propositions $B$ in $\Delta$ as hypotheses
\verb'false B'.

\begin{figure}
\begin{center}
  \[
  \begin{array}{rcl}
  \infer[{\pimp}R]
        {\Gamma \contra A \pimp B}
        {\Gamma, A \contra B, \Delta}
  &
  \raisebox{0.6em}{\ =\ }
  &
  \infer[{\por}R]
        {\Gamma \contra \pnot A \por B, \Delta}
        {\infer[{\pnot}R]
               {\Gamma \contra \pnot A, B, \Delta}
               {\Gamma, A \contra B, \Delta}}
  \\[1em]
  \infer[{\pimp}L]
        {\Gamma, A \pimp B \contra \Delta}
        {\Gamma \contra A, \Delta
       & \Gamma, B \contra \Delta}
  &
  \raisebox{0.6em}{\ =\ }
  &
  \infer[{\por}L]
        {\Gamma, \pnot A \por B \contra \Delta}
        {\infer[{\pnot}L]
               {\Gamma, \pnot A \contra \Delta}
               {\Gamma \contra A, \Delta}
       & \Gamma, B \contra \Delta}
  \end{array}
  \]
\caption{Derived rules for classical implication.}
\label{fig:derived}
\end{center}
\end{figure}

\begin{task}[10 pts]
Classically, $A \pimp B \triangleq \pnot A \por B$.
Encode implication and its derived inference rules (see
Figure~\ref{fig:derived}) as notational definitions in Twelf.  (For Twelf
examples of defined connectives and derived rules, see the code for Lecture
19:
\href{http://www.cs.cmu.edu/~fp/courses/15317-f09/lectures/19-verif/prop.elf}
     {prop.elf},
\href{http://www.cs.cmu.edu/~fp/courses/15317-f09/lectures/19-verif/verif.elf}
     {verif.elf}.)
\end{task}

The Identity Theorem can be stated as a judgement relating
each proposition to a contradiction under two new hypotheses:
\begin{verbatim}
  identity : {A:prop} (true A -> false A -> contra) -> type.
  %mode idenity +A -D.

  %worlds () (identity A D).
  %total A (identity A D).
\end{verbatim}

\begin{task}[20 pts]
Prove the Identity Theorem in Twelf by giving clauses defining the
\verb'identity' relation as a well-moded total logic program.
\end{task}

\end{document}
