\documentclass[12pt]{article}

\usepackage{times,mathptm}
\pagestyle{myheadings}



\parindent 0in
\setlength{\parindent}{0in}
\setlength{\parskip}{1ex}

\topmargin -0.1in \headheight\baselineskip
\textheight 8.5in         % 1in top and bottom margin
\textwidth 6.5in        % 1in left and right margin
\oddsidemargin 0in
\evensidemargin 0in




%\usepackage{amsmath}
%\usepackage{amssymb}


% \setlength{\itemsep}{0pt}

\markright{\footnotesize CS 451 Programming Paradigms, Spring 2001}

\begin{document}

\section*{Homework set 16: Combinatory reduction --- due Monday 9 April}

Total number of points available on this homework is 300. Full credit
is equivalent to 100 points.

In this homework we look at a way to evaluate $\lambda$-expressions efficiently;
this is the essence of the implementation strategy for functional programming
languages with lazy evaluation, Haskell included. Previously we defined several
combinators as terms in the $\lambda$-calculus, and looked at examples of reduction
of combinators within $\lambda$-calculus. It turns out that $\lambda$-expressions
can be expressed as applications of combinators, and that $\beta$-reductions can
be broken down into reductions of combinators. To evaluate $\lambda$-expressions,
one can first translate to combinatory expressions and then use a virtual machine
to effect combinatory reduction.

\begin{enumerate}

\item   (50 pts.)
Read the handout on combinators.
Augment your $\lambda$-calculus 
code with combinatory expressions over combinator bases 
$\{ \textsf{\textbf{S}},  \textsf{\textbf{K}},  \textsf{\textbf{I}} \}$
and
$\{ \textsf{\textbf{S}},  \textsf{\textbf{K}},  \textsf{\textbf{I}},  
\textsf{\textbf{B}}, \textsf{\textbf{C}} \}$.
Implement the translation of $\lambda$-expressions to combinatory expressions,
with and without $\textsf{\textbf{B}}$ and $\textsf{\textbf{C}}$.

\item   (20 pts.)
Test on the translation of the $\lambda$-expression for $\textsf{\textbf{Y}}$,
as well as a few other $\lambda$-expressions.

\item   (30 pts.)
How is the size of the resultant combinatory expression related to the size
of the input $\lambda$-expression? Answer should be different for the two
combinator bases.

\item   (80 pts. extra credit)
Implement graph reduction as outlined in the handout. Test on various
$\lambda$-programs
you have already 
written, including the merge-sort.
Report how fast the evaluator works for different inputs or input sizes. 
\emph{Careful: have you truly achieved the sharing of graph nodes of the kind
depicted in the handout? If not, what is the obstacle? What are the
repercussions for performance of graph reduction?}

\item   (120 pts. extra credit)
Implement string reduction (as in Project 1) and graph reduction (as above)
using an imperative language from the set \{C, Pascal, Java\} as your 
implementation language. 



\end{enumerate}


\end{document}



