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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CS611: Please fill in these macros as appropriate:
\lecture{6}                  		%% Lecture number
\title{Well Founded Induction}   	%% Title of lecture
\author{James Worthington, Soam Vasani} %% name of scribe
\date{9 September, 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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CS611: SCRIBE NOTES GO HERE!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section {Summary}

In this lecture we will

\begin{enumerate}
\item Define well-founded induction
\item Show that our definition of free variables gives us a well-defined $FV(e)$
\item Take another look at inference rules
\end{enumerate}

\section {Introduction}

Recall that some of the substitution rules mentioned the function $FV$.\\

$(\lambda y.e_0)\{e_1/x\} = \lambda y. e_0\{e_1/x\}$,   where ($y \neq x \land y \notin FV(e_1))$.

$(\lambda y.e_0) \{e_1/x\} = \lambda y'.e_0\{y'/y\} \{e_1/x\}$, 
where $(y' \neq x \land y' \notin FV(e_0) \land y' \notin FV(e_1))$\\

\noindent Let's examine the definition of the free variable function.\\

$FV(x) = \{x\}$

$FV(e_1$ $e_2) = FV(e_1) \cup FV(e_2)$

$FV(\lambda x. e) = FV(e) - \{x\}$\\

However, how do we know that this defintion does what we want it to do?  $FV$ is
a function from abstract syntax trees to sets of variables - but is it well
defined?  Intuition suggests that when evaluating $FV$ on an expression, $e$, we
will not get stuck in an infinite loop, and that $FV$ uniquely defines a value
for each expression.  But how do we prove this?\\

We need to use the idea underlying this definition, which is called induction on
well-founded relations.\\

A {\it well-founded relation} $\prec$ on a set $A$ is a relation that has no
infinite descending chains. A (descending) {\it chain} of elements of $A$ is a
sequence of elements $\{a_i| i \in \mathbb{N} \}$ such that $a_1 \succ a_2 \succ
\cdots$\\ 
$A$ is known as the {\it carrier set} of the relation.  
Note that a well-founded relation can't be reflexive.\\

Some examples of well-founded relations:\\

$(\mathbb{N}, \prec)$ where $m \prec n$ if $m + 1 = n$.

$(\mathbb{N}, \lt )$ where \lt is the less-than relation.

(The class of all sets, $\in$).  ZF set theory assumes the Axiom of Foundation
(or Regularity) which asserts that $\in$ is a well-founded relation.  This
prevents (among other things) a set from being a member of itself.\\

The following are _not_ well-founded relations:\\

$(\mathbb{N}, \gt)$

$([0,\infty], \lt)$ is not well-founded because, for example, $1 \lt \frac{1}{2} \lt
\frac{1}{4} \lt \frac{1}{8} \lt ...$\\


\section{Well-Founded Induction}

Suppose that $A$ is the carrier set of a well-founded relation.  Then 
%a property $P$ holds for all $a \in A$\\
if $P$ is some property,

\[
(\forall a \in A . P(a)) \Longleftrightarrow \forall a \in A.([\forall b \prec a.P(b)] \rightarrow P(a))
\]

For $(\mathbb{N}, \lt)$, this reduces to the familiar notion of ({\it strong} or
{\it course-of-values}) induction on the natural numbers:

Assuming $P(0),P(1),...,P(n-1)$, prove $P(n)$.  When $n = 0$, the induction
hypothesis is vacuously true, which means we need to deal with the base case
separately.

Now let's define a well-founded relation on the set of all expressions: $e \lt e'$
if $e$ is a {\bf strict} sub-expression of $e'$.  If we think of expressions as
syntax trees, then $e'$ is a tree which has $e$ as a subtree.  Since these trees
are finite, the relation is is well-founded.  Induction on this relation is
called _structural induction_.

We can now show that $FV(e)$ is uniquely defined for any expression $e$:\\

Look at the grammar of expressions: one and only one case in the definition of
$FV$ applies to any $e$.  All references in the definition of $FV$ are to
subexpressions.  $FV$ is uniquely defined for the basis case of the smallest
expression.  So $FV(e)$ is uniquely defined for any expression $e$.

In general, an inductive definition of a function satisfies the following
conditions:

\begin{enumerate}
\item one pattern applies to any given argument
\item RHS is defined in terms of arguments that are predecessors.
\end{enumerate}

If a function definition satisfies these two conditions, then the function is
well-defined; otherwise, it may or may not be well-defined.

\section {Inference rules}

Recall how we defined small-step semantics, big-step semantics, etc. using
inference rules.  We'd like to prove that the rules that we wrote down do in
fact work.

First, lets change our view of reduction and look at it as just another
relation:\\

$e \stepsone e'$ means that $(e,e') \in $ some $\nm{reduces-to}$ relation, which
is a subset of $\nm{Expr} \times \nm{Expr}$.\\

$<c,\sigma> \stepsone <c',\sigma'>$ means that $(c,\sigma, c',\sigma') \in$
some other $\nm{reduces-to}$ relation, which is a subset of \\
$\nm{Command} \times \nm{Expr} \times \nm{Command} \times \nm{Expr}$.

Our goal with these inference rules is to define such relations.

Here's an example of the kind of the rules we've been looking at so far:

\[
\infer[|a_1| \gt 0]{(a_1 + a_2)\stepsone(a'_1 + a_2)}{a_1\stepsone a'_1}
\]

$a_1$, $a_2$ etc. are _metavariables_. The stuff above the line is the
_premise_, the stuff below is the _conclusion_.  The stuff on the right side is
a _side condition_.\\

When you do a consistent substitution for all the metavariables, and the side
condition is satisfied, you get a {\it rule instance}.  For example, this is an
instance of the above rule:

\[
\infer[|3*4| \gt 0]{(3 * 4 + 1)\stepsone(12 + 1)}{3 * 4\stepsone 12}
\]

with the substitutions $a_1 = 3*4$, $a'_1 = 12$, $a_2 = 1$.\\

However, this is also a valid instance of the rule:
\[
\infer[|3*4| \gt 0]{(3 * 4 + 1)\stepsone(11 + 1)}{3 * 4\stepsone 11}
\]
with the substitutions $a_1 = 3*4$, $a'_1 = 11$, $a_2 = 1$.  (There's nothing in
the premise or side conditions that would make these substitutions invalid.)\\

With rules like the one above, we are trying to define a relation $A \subseteq
S$.  Our example rule could be part of the definition of some reduces-to
relation, $\nm{reduces-to} \subseteq \nm{Expr} \times \nm{Expr}$\\

In general, a rule instance is of the form
\[
\infer{X}{X_1 X_2 \dots X_n}
\]

where $X_1, X_2, \dots, X_n$ are members of the relation, and $X$ is the ``new''
member of the relation added by this rule.\\

Here's the difference between a premise and a side condition: the side condition
is not part of the relation that the rule is trying to define, while the
premises are members of it.  The side condition is something else that we are
bringing into the definition of the relation.  In this sense, the premises are
the recursive part of the definition, and the side conditions are the
non-recursive part.  (Note that in the side condition we didn't write $a_1 \gt 0$,
because $a_1$ is just a piece of syntax and writing that doesn't make sense; so
we wrote $|a_1| \gt 0$.)\\

So suppose we have written down a set of rules.  How do we know whether the
relation that the rules are trying to define is well-defined ?\\

We can try to define $A$ like this:

\[
A = \Bigg\{ X \Bigg| \{ X_1, X_2, \dots, X_n \} \subseteq A \land 
            \infer{X}{X_1 X_2 \dots X_n} \mbox{  is a rule instance} \Bigg\}
\]

But this is not a very clear definition.  What do we put in $A$ to start with?
If there is a rule $\infer{X}{X}$ what do we add to $A$ for this rule?  The whole
$S$?  Nothing?\\

Define a _rule operator_ $R$ as follows:

\[
R(B) = \Bigg\{ X \Bigg| \lbrace X_1, X_2, \dots, X_n \rbrace \subseteq B \land
              \infer{X}{X_1 X_2 \dots X_n} \mbox{  is a rule instance} \Bigg\}
\]

\noindent Then,
\begin{itemize}
\item $R(B)$ is the set of members of the relation that can be inferred from the
members of set B.
\item $R(\emptyset)$ is what we can infer from nothing; that is, the set of axioms.\\
\item $R(R(\emptyset))$ contains the things that we can derive in one step, and
the axioms.  (The axioms are in this set because they derive from the empty set,
which is a subset of $R(\emptyset)$.)
\end{itemize}

In the next lecture we will use this $R$ operator to precisely define the
relation.

\end{document}
