%%% This is the scribe notes template for CS611
%%% There are several comments preceded by CS611: and boxed in %%%%'s
%%% which indicate where macros should be altered to set up the header
%%% for the paper.  Your Notes should go at the comment SCRIBE NOTES GO HERE!.

%%% In the various .sty files that accompany this .tex file you will
%%% find LaTeX macros that make it easier to typeset inference rules
%%% and programming language constructs.  You must make sure that the
%%% file proof.sty is in a path searched by LaTeX when you try to
%%% use this file.  Take a look to see what macros are available--it
%%% will save you time and make the notes look better.  Feel free to
%%% extend the set of macros--post them to the newsgroup and contact
%%% the course staff if you come up with some good ones so they can be
%%% added to the template.

%%% This template includes examples of how to use some of the macros
%%% to give you an idea of how they work.  (Delete the examples when
%%% you do your scribing.)

\documentclass{article} \usepackage{611-lecture}
\usepackage{amsmath, amsfonts}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CS611: Please fill in these macros as appropriate:
\lecture{30}                  %% Lecture number
\title{Types as Propositions}   %% Title of lecture
\author{Mia Minnes, Nam Nguyen}       %% name of scribe
\date{9 November, 2005}     %% Date of lecture, e.g., 1 January 2001
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% See 611.sty for a variety of macros that will be helpful in
% typesetting the lecture. Here are a few of particular interest:
%
% "x"       x in keyword font (e.g., "if", "#t")
% _x_       x in italics
% \nm{n}    n in slanted font (used for abbreviations)
% <e>       e in angle brackets
% \lt       less-than sign
% \gt       greater-than sign
% \SB{x}    x in semantic brackets
% \Tr x{y}  x[[y]] with x in calligraphic font
%           (if x is more than a single character, use \Tr{x}{y})

\begin{document}

\maketitle

\section{Constructive Logic}
In this lecture we investigate the correspondence between the
$\lambda^\rightarrow$ type system and \emph{constructive logic} also
known as \emph{intuitionistic logic}. In constructive logic a
formula is only considered to be true if it can be proved using a restricted
set of proof rules.  Double negation and the law of excluded middle are
no longer allowed. Therefore, the following examples:
\[\Rule{\neg \neg \phi}{\phi} \quad \quad \Rule{}{\neg \phi \vee \phi}\]
are accepted by classical logic but not by constructive logic.

\subsection{The syntax of constructive logic}
\[\phi ::= T \bnf F \bnf \phi_1 \implies \phi_2 \bnf \phi_1 \vee \phi_2 \bnf \phi_1 \wedge \phi_2 \bnf
\neg \phi \bnf \forall X \in S . \phi\]

Note that negation is expressible in terms of implications: $\neg \phi \equiv \phi \implies F$.

\subsection{Natural deduction (Gentzen, 1943)}
We have the following judgement form in constructive logic,
\[\phi_1, \phi_2, ..., \phi_n \proves \phi\]
which means that assuming the propositions $\phi_1, \phi_2, ..., \phi_n$,
 we can prove that proposition $\phi$ holds. In
addition, $\proves \phi$ means that $\phi$ is true (provable).

\medskip
Let $\Gamma$ be a set of (usually assumed to be consistent) assumptions.
Now, we describe the rules for constructive logic, and its corresponding type
judgement in the $\lambda^\rightarrow$ type system.

\medskip
\begin{center}
\begin{tabular}{ccc}
 & Constructive logic rule & $\lambda^\rightarrow$ type system rule \\
\hline \\
weakening rule & \Rule{\Gamma \proves \phi}{\Gamma, \phi'
\proves \phi} & (weakening lemma)\\ \\
axiom & \Rule{}{\Gamma , \phi \proves \phi} & \Rule{}{\Gamma , x:
\tau \proves x:\tau}\\ \\
implication & \Rule{\Gamma , \phi_1 \proves \phi_2}{\Gamma \proves
\phi_1 \implies \phi_2} & \Rule{\Gamma, x:\tau_1 \proves e:
\tau_2}{\Gamma \proves \lam {x:\tau_1} e:\tau_1 \arrow \tau_2}\\
& (introduction rule) \\ \\
& \Rule{\Gamma \proves \phi_1 \implies \phi_2 \quad \Gamma \proves
\phi_1}{\Gamma \proves \phi_2} & \Rule{\Gamma \proves e_0:\tau_1 \arrow \tau_2 \quad \Gamma \proves e_1:\tau_1}{\Gamma \proves e_0~e_1 : \tau_2} \\
& (elimination rule - aka modus ponens) \\ \\
conjunction & \Rule{\Gamma \proves \phi_1 \quad \Gamma \proves \phi_2}{\Gamma \proves \phi_1 \wedge \phi_2} & \Rule{\Gamma \proves e_1:\tau_1 \quad \Gamma \proves e_2:\tau_2}{\Gamma \proves (e_1,e_2):\tau_1*\tau_2} \\
& (introduction rule) \\ \\
& \Rule{\Gamma \proves \phi_1 \wedge \phi_2}{\Gamma \proves \phi_1} \quad \Rule{\Gamma \proves \phi_1 \wedge \phi_2}{\Gamma \proves \phi_2} & \Rule{\Gamma \proves e:\tau_1*\tau_2}{\Gamma \proves \#1e:\tau_1} \quad \Rule{\Gamma \proves e:\tau_1*\tau_2}{\Gamma \proves \#2e:\tau_2} \\
& (elimination rules) \\ \\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{ccc}
disjunction & \Rule{\Gamma \proves \phi_1}{\Gamma \proves \phi_1
\vee \phi_2} \quad \Rule{\Gamma \proves \phi_2}{\Gamma \proves
\phi_1 \vee \phi_2} & \Rule{\Gamma \proves e:\tau_1}{\Gamma \proves
"inl"_{\tau_1+\tau_2}e:\tau_1+\tau_2} \quad \Rule{\Gamma \proves
e:\tau_2}{\Gamma \proves "inr"_{\tau_1+\tau_2}e:\tau_1+\tau_2}\\
& (introduction rules) \\ \\
& \Rule{\Gamma \proves \phi_1 \vee \phi_2 \quad \Gamma \proves
\phi_1 \implies \phi_3 \quad \Gamma \proves \phi_2 \implies
\phi_3}{\Gamma \proves \phi_3} & \Rule{\Gamma \proves
e:\tau_1+\tau_2 \quad \Gamma \proves e_1:\tau_1 \arrow \tau_3 \quad
\Gamma \proves e_2:\tau_2 \arrow \tau_3}{\Gamma \proves "case"~ e_0
~"of" ~ e_1|e_2 : \tau_3}\\
& (elimination rule) \\ \\
universals & \Rule{\Gamma, X\in S \proves \phi \quad X \notin
\Gamma}{\Gamma \proves \forall X \in S. \phi} &
\Rule{\Delta, X::K; \Gamma \proves e:\tau \quad X \notin \Delta}{\Delta; \Gamma \proves \Lambda X::K.e:\forall X::K.\tau}\\
& (introduction rule) \\ \\
& \Rule{\Gamma \proves \forall X \in S.\phi \quad \Gamma \proves A
\in S}{\Gamma \proves \phi\{A/X\}} & \Rule{\Delta; \Gamma \proves
e:\forall X::K.\tau \quad \Delta \proves \tau'::K}{\Delta; \Gamma
\proves e[\tau']: \tau \{\tau'/X\}}\\
& (elimination rule) & (so far we only consider K as "type")
\end{tabular}
\end{center}

\section{Curry-Howard correspondance}
The analogous rules for typing derivations and constructive logic proofs suggest
that if we're given a well-typed term in system F or in $\lambda^{\arrow}$, then
its proof tree will look exactly the same as the proof tree for the corresponding
formula in constructive logic.  This means that every program proves something,
i.e.\ is a theorem in constructive logic.  And, every theorem in constructive
logic corresponds to a program.  Several theorem provers and
proof checkers (e.g., Nuprl: see \texttt{www.nuprl.org}) are based on this idea.

\subsection{The correspondence}

\noindent
\begin{tabular}{cc}
Type & Formula \\
\hline
\arrow & $\implies$ \\
$\ast$ & $\wedge$\\
$+$ & $\vee$ \\
$\forall$ & $\forall$ \\
$1$ (unit) & T \\
$0$ (void) & F \\
$\tau \arrow 0$ ( continuation) & $\neg \phi \equiv \phi \implies F$
\end{tabular}
\bigskip

\subsection{Examples}

Consider the formula expressing transitivity of implication in
constructive logic:
\[
\forall X, Y, Z. ~( X \implies Y) \wedge (Y \implies Z) \implies ( X \implies Z)
\]
By the correspondence above, this is related to the type
\[
\forall X, Y, Z. ~(X \arrow Y) \ast ( Y \arrow Z) \arrow ( X \arrow Z)
\]
So, if we can construct a term of this type, we will have proved the theorem in
constructive logic because we can transform each step of the proof tree
showing that the term is well typed into a proof deriving the logical fact.
How about the expression
\[
\Lam{X,Y,Z}{\lam {p\ty (X \arrow Y) \ast (Y \arrow Z)}{\lam{x \ty X}{(\#2p)( (\#1p)(x))} }  }
\]
For any type variables $X,Y,Z$, this is a function which has a pair of functions as its
argument, and which returns a function from the domain of one to the codomain of the other.
This was exactly what we needed, and so by building and then transforming the proof
tree for this expression being well-typed we can prove the transitivity statement in
constructive logic.

\medskip
Another example is the following formula:
\[
\forall X, Y, Z.~ \left ( (X \wedge Y \implies Z) \iff (X \implies (Y \implies Z))   \right)
\]
Note that in most cases, a formula containing $\iff$ will mean that the corresponding
expression shows the equivalence of two types.  In other words, if two types
are equivalent in this way, it is possible to encode one in terms of another.

The typed expressions corresponding to each side of the formula above are
\[
(X \ast Y \arrow Z) \qquad (X \arrow (Y \arrow Z)).
\]
We know that these two types can be represented in terms of one another: to go
from left to right is {\em currying} and to go from right to left is
{\em uncurrying}.  The equivalence of these two representations of expressions
gives the proof of the logical statement.


\subsection{Negation and CPS}
Sometimes equivalences that can't be proved in constructive logic but which
hold in classical logic can be helpful to get intuition about types.
For example, in  classical logic we could prove the equivalence of the following
progression of statements:
\begin{eqnarray*}
A &\implies& B \\
\neg A & \vee& B \\
\neg ( A &\wedge& \neg B) \\
( A \wedge (B &\implies& F) ) \implies F
\end{eqnarray*}

The type corresponding to the first statement in this progression is $A \arrow B$, and
the type corresponding to the last statements is $(A \ast (B \arrow 0 )) \arrow 0$. But,
recall that $(A \ast (B \arrow 0)) \arrow 0$ is exactly the CPS translation of $A \arrow B$.
This suggests a relationship between some classical logic identity and CPS translation.  To
discover which identity it is, recall the contract for CPS translation:
\[
\SB{ \Gamma \proves e \ty \tau} \ty ( \SB{\tau} \arrow 0) \arrow 0.
\]
The result of CPS translation corresponds to double negation of the formula corresponding to the
type!  Indeed, in classical logic, $\phi \equiv \neg \neg \phi$. So, CPS
translation is capturing some non-constructive behavior
which is valid with respect to classical logic. This is possible only
because CPS turns the entire program inside out; we couldn't
construct a translation based on double negation that operates just
on subexpressions of a program.

\subsection{Other directions}
Some other logics have been used to give more intuition about typing systems.  One example
is linear logic, where one is allowed to apply modus ponens to a premise at most once.  This
would correspond to functions which consume their arguments, and hence might be a good model for
systems with bounded resources.  Also, since the type system captures which arguments have been used,
it might be possible to eliminate the need for a garbage collector.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
