hw04.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 23 Nov 2012 14:08:31 +0000
changeset 71 7717f20f0504
parent 55 cceed8d66b28
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
\usepackage{charter}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
\usepackage{hyperref}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
\usepackage{amssymb}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{amsmath}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
     7
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
     8
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\begin{document}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\section*{Homework 4}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\begin{enumerate}
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    14
\item Why is every finite set of strings a regular language?
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    15
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    16
\item What is the language recognised by the regular expressions $(\varnothing^*)^*$.
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    17
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    18
\item If a regular expression $r$ does not contain any occurrence of $\varnothing$ 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    19
is it possible for $L(r)$ to be empty?
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    20
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    21
\item Assume that $s^{-1}$ stands for the operation of reversing a
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    22
string $s$. Given the following \emph{reversing} function on regular 
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    23
expressions
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    24
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    25
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    26
\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    27
$rev(\varnothing)$   & $\dn$ & $\varnothing$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    28
$rev(\epsilon)$         & $\dn$ & $\epsilon$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    29
$rev(c)$                      & $\dn$ & $c$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    30
$rev(r_1 + r_2)$        & $\dn$ & $rev(r_1) + rev(r_2)$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    31
$rev(r_1 \cdot r_2)$  & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    32
$rev(r^*)$                   & $\dn$ & $rev(r)^*$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    33
\end{tabular}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    34
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    35
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    36
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    37
and the set
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    38
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
\begin{center}
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    40
$Rev\,A \dn \{s^{-1} \;|\; s \in A\}$
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
\end{center}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    43
prove whether
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    44
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
\begin{center}
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    46
$L(rev(r)) = Rev (L(r))$
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
\end{center}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    49
holds.
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    51
\item Give a regular expression over the alphabet $\{a,b\}$ recognising all strings 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    52
that do not contain any substring $bb$ and end in $a$.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    53
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    54
\item Assume the delimiters for comments are \texttt{$\slash$*} and \texttt{*$\slash$}.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    55
Give a regular expression that can recognise comments
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    56
of the form 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    57
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    58
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    59
\texttt{$\slash$*~\ldots{}~*$\slash$} 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    60
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    61
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    62
where the three dots stand for arbitrary characters, but not comment delimiters.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    63
(Hint: You can assume you are already given a regular expression written \texttt{ALL},
55
cceed8d66b28 updated
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
    64
that can recognise any character, and a regular expression \texttt{NOT} that recognises
cceed8d66b28 updated
Christian Urban <urbanc@in.tum.de>
parents: 45
diff changeset
    65
the complement of a regular expression.)
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    66
45
Christian Urban <urbanc@in.tum.de>
parents: 43
diff changeset
    67
\item Given the alphabet $\{a,b\}$. Draw the automaton that has two states, say  $q_0$ and $q_1$.
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    68
The starting state is $q_0$ and the final state is $q_1$. The transition
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    69
function is given by
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    70
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    71
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    72
\begin{tabular}{l}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    73
$(q_0, a) \rightarrow q_0$\\
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    74
$(q_0, b) \rightarrow q_1$\\
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    75
$(q_1, b) \rightarrow q_1$
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    76
\end{tabular}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    77
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    78
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    79
What is the languages recognised by this automaton?
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    80
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    81
\item Give a deterministic finite automaton that can recognise 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    82
the language $L(a^*\cdot b\cdot b^*)$. 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    83
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
\item (Optional) The tokenizer in \texttt{regexp3.scala} takes as
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
argument a string and a list of rules. The result is a list of tokens. Improve this tokenizer so 
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
that it filters out all comments and whitespace from the result.
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
\item (Optional) Modify the tokenizer in \texttt{regexp2.scala} so that it
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
implements the \texttt{findAll} function. This function takes a regular
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
expressions and a string, and returns all substrings in this string that 
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
match the regular expression.
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
\end{enumerate}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    95
% explain what is a context-free grammar and the language it generates 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    96
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    97
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    98
% Define the language L(M) accepted by a deterministic finite automaton M.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    99
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   100
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   101
% does (a + b)*b+ and (a*b+) + (b*b+) define the same language
43
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   102
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
\end{document}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
%%% Local Variables: 
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
%%% mode: latex
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
%%% TeX-master: t
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
%%% End: