\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 5: Prolog --- due Monday 19 February}

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

%\small

\begin{enumerate}



\item (20 pts.) 
Define numerals as follows, rendering Peano's axioms in Prolog:
\begin{verbatim}
%% num(X) means: X is a numeral.
num(0).
num(s(X)) :- num(X).

%% sum(X, Y, Z) means: X, Y, Z are numerals 
%%         such that Z is the sum of X and Y.
sum(X, 0, X) :- num(X).
sum(X, s(Y), s(Z)) :- sum(X, Y, Z).
\end{verbatim}

Why can't we write simply \texttt{sum(X, 0, X).} for the first rule?

What are the answers to the following queries:
\begin{enumerate}
\item \texttt{?- sum(s(s(0)), s(s(s(0))), Z).}
\item \texttt{?- sum(X, Y, s(s(s(0)))).}
\end{enumerate}

\item (20 pts.) 
Continuing the preceding exercise, write the rules for 
multiplication \texttt{mult(X, Y, Z)}, meaning that
\texttt{Z} is the product of \texttt{X} and \texttt{Y}. Multiplication
is defined by the following axioms:
\begin{itemize}
\item $x \cdot 0 = 0$
\item $x \cdot s (y) = (x \cdot y) + x$
\end{itemize}










\item (60 pts.) 
The following are the rules for \texttt{list(L)}, which means 
that \texttt{L} is a list.
\begin{verbatim}
list([]).
list([_|T]) :- list(T).
\end{verbatim}

\begin{enumerate}

\item (10 pts.) 
Write the rules for \texttt{len(L, X)}, which means that \texttt{X}, a numeral
as defined in the preceding exercises, is the length of the list \texttt{L}.

\item (20 pts.) 
Write the rules for \texttt{append(L1, L2, L3)}, which means that
the concatenation of lists \texttt{L1} and \texttt{L2} is the same
as list \texttt{L3}.

\item (20 pts.) 
Write the rules for \texttt{reverse(L1, L2)}, which means that
list \texttt{L2} is the reverse of list \texttt{L1}.

\item (10 pts.) 
Write the rules for \texttt{palindrome(L)}, which means that
list \texttt{L} is a palindrome.

\end{enumerate}






\end{enumerate}


\end{document}

