\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 11: Hands-on review of the mid-term exam --- due Wednesday 7 March}

Total number of points available is 100, and full credit
is equivalent to 100 points. 


\begin{enumerate}

\item (after Lewis and Papadimitriou)
A nondeterministic finite automaton is a quintuple 
$M = (K, \Sigma, \Delta, s, F)$, 
where $K$ is a finite set of states, 
$\Sigma$ is an alphabet,
$s \in K$ is the initial (or start) state,
$F \subseteq K$ is the set of final states,
and $\Delta$, the transition relation, is a finite subset of
$K \times \Sigma^{\star} \times K$.

Suppose a triple $(q, u, p)$ is in $\Delta$. This means that the
automaton $M$, when in state $q$, may consume a string $u$ from
the input string, and enter state $p$.
Note that the string $u$ can be arbitrarily long.

The automaton accepts a string if there is a sequence of steps,
starting at the initial state, that ends in one of the final states,
with the entire input string consumed.


\item
Write a set of Prolog predicates to simulate the workings of
a nondeterministic finite automaton as described above.

The main predicate \texttt{accepts/1} should be invoked as follows:

\texttt{?- accepts([a,a,b,b,a,b,a,b,a,a]).}

\item
You may assume the existence of predicates 
\texttt{startstate/1}, \texttt{acceptstate/1}, and \texttt{transition/3},
that describe the
states and transitions of a particular nondeterministic finite automaton.
For example, here is a set of Prolog predicates, in the form as above,
that describe a nondeterministic finite automaton
for the language of strings over the alphabet
$\{a,b\}$ that end in $ab$:

\begin{verbatim}
startstate(s1).
acceptstate(s2).
transition(s1, [a], s1).
transition(s1, [b], s1).
transition(s1, [a,b], s2).
\end{verbatim}



\item
You should test your program on at least the following queries, using the
nondeterministic finite automaton defined in the example:

\begin{verbatim}
?- accepts([a,a,b,b,a,b,a,b,a,a]).
?- accepts([a,a,b,b,a,b,a,b,b,a]).
?- accepts([a,a,b,b,a,b,a,b,a,b]).
?- accepts([a,a,b,b,a,b,a,b,b,b]).
\end{verbatim}


\end{enumerate}


\end{document}
