%%% 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{21}                  %% Lecture number
\title{Metalanguage and Domain Constructions}   %% Title of lecture
\author{Michael O'Connor}       %% name of scribe
\date{19 October, 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!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Recall that last time we defined the denotation of the statement $\WHILE~b
~\DO~c$ to be $W = \mbox{fix}(F)$, where 
$F=\lam{w\in\Sigma\to\Sigma_\bot}\lam{\sigma\in\Sigma}
 \mbox{ if } \Tr B{b}\sigma \mbox{ then } w^*(\Tr C{c}\sigma) \mbox{ else } \lfloor\sigma\rfloor$.
 (Note that this is a mathematical object so the if/then here is purely mathematical.
 Also, recall
that if $w$ is a function from a CPO $A$ to a pointed CPO $B$, then $w^*$ is the lift of
the function to a function from $A_\bot$ to $B$, sending $\bot$ to $\bot$ and doing
the same thing as $w$ everywhere else. Also, if $x$ is in a CPO $A$, then
$\lfloor x\rfloor$ is the same object, but considered as an element of the 
CPO $A_\bot$.)

In order to show that this fixed point exists, we have to apply the fixed point
theorem, meaning that we have to show that $D=\Sigma\to\Sigma_\bot$ is a pointed CPO
and $F$ is continuous. 

$D$ is a pointed CPO because $\Sigma_\bot$ is.

\newcommand{\dlt}{\sqsubseteq}

In order to check that $F$ is continuous, let's first check that it's monotonic 
(this will ensure that, when trying to check the definition of continuity, when $d_n$ is a chain, $F(d_n)$ is also a chain, so that $\bigsqcup F(d_n)$ makes sense).  We want
to show that if $d_1 \dlt d_2$ then $F(d_1)\dlt F(d_2)$.  So let $d_1\dlt d_2$ and
we want to show that $F(d_1)\dlt F(d_2)$.  $F(d_i)$ is a function, and the ordering
on functions is pointwise, so we can show this by showing that $F(d_1)\sigma\dlt F(d_2)\sigma$ for each $\sigma$. $F(d_i)\sigma$ is
\begin{displaymath}
\mbox{if } \Tr B{b}\sigma \mbox{ then } d_i^*(\Tr{C}{c}\sigma)
\mbox{ else } \lfloor\sigma\rfloor
\end{displaymath}
In the case that $\Tr B{b}\sigma$ is true, $F(d_i)\sigma$ is $d_i^*(\Tr{C}c\sigma)$,
and since $d_1\dlt d_2$, $d_1^*(\Tr{C}c\sigma)\dlt d_2^*(\Tr{C}c\sigma)$.  (There's
actually a simple case check here, to make sure that it works with $\bot$.)

In the case that $\Tr B{b}\sigma$ is false, $F(d_i)\sigma$ is just $\lfloor \sigma\rfloor$
(which is $\sigma$ considered as an element of $\Sigma_\bot$). Since $\lfloor \sigma\rfloor
\dlt \lfloor\sigma\rfloor$, we are done.

Now let's check that $F$ is continuous.  Let $\{d_n\}$ be an arbitrary chain.
We want to show that $\bigsqcup F(d_n) = F(\bigsqcup d_n)$. We have
\begin{displaymath}
\bigsqcup F(d_n) = \bigsqcup \lam{\sigma}
\mbox{ if } \Tr B{b}\sigma \mbox{ then } d_n^*(\Tr{C}{c}\sigma)
\mbox{ else } \lfloor\sigma\rfloor
\end{displaymath}
Since the ordering on functions is pointwise, so is the least upper bound operator.
So this is
\begin{displaymath}
\lam{\sigma}\bigsqcup
\mbox{ if } \Tr B{b}\sigma \mbox{ then } d_n^*(\Tr{C}{c}\sigma)
\mbox{ else } \lfloor\sigma\rfloor
\end{displaymath}
But $\Tr B{b}\sigma$ does not depend on $n$.  Thus, this is
\begin{displaymath}
\lam{\sigma}
\mbox{ if } \Tr B{b}\sigma \mbox{ then } \bigsqcup d_n^*(\Tr{C}{c}\sigma)
\mbox{ else } \bigsqcup \lfloor\sigma\rfloor
\end{displaymath}
But $\bigsqcup d_n^*(\Tr{C}{c}\sigma) = (\bigsqcup d_n)^*(\Tr{C}{c}\sigma)$
by definition (and a simple case check again, this time
relying on the observation that $\Tr{C}{c}\sigma$ does not 
depend on $n$ (so is always $\bot$ or always not $\bot$)), and $\bigsqcup \lfloor \sigma\rfloor
=\lfloor \sigma\rfloor$, so we are done. 

Now, the question is how can we avoid doing this kind of check over and over again?
The idea that we'll have a restricted ``metalanguage'' which will be a way of writing
mathematical expressions for what we want and which will ensure that the sets we're
talking about are CPOs and the functions are continuous.  So we will define
a set of ``types'' and ``operations'' corresponding to domains and continuous functions
respectively.

The simplest types will be the discrete CPOs: we'll give ourselves names for
$\mathbb{Z}$, $\mathbb{N}$ and $\mathbb{U}$ for the integers, the natural numbers,
and the unit domain respectively.  (The unit domain contains a single element, ``unit.'')
These all have the discrete order, meaning that if $x\dlt y$, then $x=y$.

For any type $A$, we have the domain $A_\bot$, which is $A$ adjoined with a new element
below all the previous elements.  Note that $\bot$ is intended to be a new element,
so we can actually iterate this operation.  Along with this comes the (continuous) operations
$\lfloor \bullet\rfloor$, a function from $D$ to $D_\bot$ for any $D$, and $\bullet^*$,
a function from $D\to E_\bot$ to $D_\bot\to E_\bot$.

Given any types $D$ and $E$, we can form the product type $D\times E$.  
This will consist of all ordered pairs $<d,e>$ of elements of $D$ and
$E$ respectively (i.e., the set-theoretic Cartesian product of $D$ and $E$)
with the ordering $<d_1,e_1> \dlt <d_2,e_2>$ iff $d_1\dlt d_2$ and
$e_1 \dlt e_2$.  Again, this is a CPO if $D$ and $E$ are. It is easy to check
that $\bigsqcup <d_n, e_n> = <\bigsqcup d_n,\bigsqcup e_n>$. We have two operations
$\pi_1$ and $\pi_2$.  $\pi_1(<d,e>) = d$ and likewise for $\pi_2$.  Also, note
that this product can be extended from a binary product to an arbitrary product
in a straightforward manner.

Given any types $D$ and $E$, we can form the sum $D +E$, corresponding to the
disjoint union.  We would like to take the union of the sets $D$ and $E$, but
we need to mark them to make sure we can tell which set the originally came from.
So we'll define $D+E=\{\mathit{in}_1(d)\mid d\in D\}\cup\{\mathit{in}_2(e)\mid e\in E\}$.
We define $\in_i(x)\dlt \in_j(y)$ iff $i=j$ and $x\dlt y$.  As any chain in $D+E$
will be contained in $\mathit{in_1}(D)$ or $\mathit{in_1}(E)$, if $D$ and $E$
are CPOs, $D+E$ is one as well.  We have operations $\mathit{in}_i$
and case statements: case $x$ of $1.e_1 | 2. e_2 $ where $x$ is in $D+E$,
and $e_1$ and $e_2$ are in the same CPO.  An arbitrary sum of CPOs can be defined
in a similar manner.

Given types $D$ and $E$ we can define the CPO $[D\to E]$ of all continuous functions
from $D$ to $E$ with pointwise ordering. Corresponding operations are: 
$\mbox{apply}~f~x$ applying a function to an argument.  apply has type
$[D\to E]\times D\to E$.  We have compose, with type
$[E\to F]\times [D\to E]\to[D\to F]$; curry, with type $[D\times E\to F]\to
[D\to[E\to F]]$; uncurry, with type $[D\to[E\to F]]\to[D\times E\to F]$
and most importantly, fix, with type $[D\to D]\to D$, defined by
$\lam{g\in[D\to D]}\bigsqcup g^n(\bot)$.  fix takes a function and returns
its least fixed point.  Next time we will show that this is continuous.

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