hws/hw04.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 27 Oct 2013 20:07:10 +0000
changeset 166 ef48e378c44e
parent 146 9da175d5eb63
child 264 4deef8ac5d72
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}
146
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
     6
\usepackage{tikz}
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
     7
\usetikzlibrary{automata}
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
     8
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    10
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    11
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
\begin{document}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
\section*{Homework 4}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
\begin{enumerate}
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    17
\item Why is every finite set of strings a regular language?
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    18
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    19
\item What is the language recognised by the regular expressions $(\varnothing^*)^*$.
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    20
166
ef48e378c44e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 146
diff changeset
    21
\item If a regular expression $r$ does not contain any occurrence of $\varnothing$,  
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    22
is it possible for $L(r)$ to be empty?
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    23
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    24
\item Assume that $s^{-1}$ stands for the operation of reversing a
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    25
string $s$. Given the following \emph{reversing} function on regular 
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    26
expressions
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    27
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    28
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    29
\begin{tabular}{r@{\hspace{1mm}}c@{\hspace{1mm}}l}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    30
$rev(\varnothing)$   & $\dn$ & $\varnothing$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    31
$rev(\epsilon)$         & $\dn$ & $\epsilon$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    32
$rev(c)$                      & $\dn$ & $c$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    33
$rev(r_1 + r_2)$        & $\dn$ & $rev(r_1) + rev(r_2)$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    34
$rev(r_1 \cdot r_2)$  & $\dn$ & $rev(r_2) \cdot rev(r_1)$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    35
$rev(r^*)$                   & $\dn$ & $rev(r)^*$\\
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    36
\end{tabular}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    37
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    38
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    39
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    40
and the set
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    41
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
\begin{center}
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    43
$Rev\,A \dn \{s^{-1} \;|\; s \in A\}$
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
\end{center}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
34
Christian Urban <urbanc@in.tum.de>
parents: 32
diff changeset
    46
prove whether
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    47
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
\begin{center}
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    49
$L(rev(r)) = Rev (L(r))$
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
\end{center}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
32
d085fe0c086f started
Christian Urban <urbanc@in.tum.de>
parents: 31
diff changeset
    52
holds.
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    54
\item Give a regular expression over the alphabet $\{a,b\}$ recognising all strings 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    55
that do not contain any substring $bb$ and end in $a$.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    56
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    57
\item Assume the delimiters for comments are \texttt{$\slash$*} and \texttt{*$\slash$}.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    58
Give a regular expression that can recognise comments
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    59
of the form 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    60
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    61
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    62
\texttt{$\slash$*~\ldots{}~*$\slash$} 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    63
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    64
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    65
where the three dots stand for arbitrary characters, but not comment delimiters.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    66
(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
    67
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
    68
the complement of a regular expression.)
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    69
45
Christian Urban <urbanc@in.tum.de>
parents: 43
diff changeset
    70
\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
    71
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
    72
function is given by
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    73
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    74
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    75
\begin{tabular}{l}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    76
$(q_0, a) \rightarrow q_0$\\
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    77
$(q_0, b) \rightarrow q_1$\\
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    78
$(q_1, b) \rightarrow q_1$
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    79
\end{tabular}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    80
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    81
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    82
What is the languages recognised by this automaton?
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    83
146
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    84
\item Give a non-deterministic finite automaton that can recognise 
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    85
the language $L(a\cdot (a + b)^* \cdot c)$. 
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
    86
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
146
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    88
\item Given the following deterministic finite automaton over the alphabet $\{0, 1\}$,
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    89
find the corresponding minimal automaton. In case states can be merged,
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    90
state clearly which states can
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    91
be merged.
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
146
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    93
\begin{center}
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    94
\begin{tikzpicture}[scale=3, line width=0.7mm]
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    95
  \node[state, initial]        (q0) at ( 0,1) {$q_0$};
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    96
  \node[state]                    (q1) at ( 1,1) {$q_1$};
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    97
  \node[state, accepting] (q4) at ( 2,1) {$q_4$};
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    98
  \node[state]                    (q2) at (0.5,0) {$q_2$};
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
    99
  \node[state]                    (q3) at (1.5,0) {$q_3$};
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   100
  \path[->] (q0) edge node[above] {$0$} (q1)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   101
                  (q0) edge node[right] {$1$} (q2)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   102
                  (q1) edge node[above] {$0$} (q4)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   103
                  (q1) edge node[right] {$1$} (q2)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   104
                  (q2) edge node[above] {$0$} (q3)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   105
                  (q2) edge [loop below] node {$1$} ()
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   106
                  (q3) edge node[left] {$0$} (q4)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   107
                  (q3) edge [bend left=95, looseness = 2.2] node [left=2mm] {$1$} (q0)
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   108
                  (q4) edge [loop right] node {$0, 1$} ()
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   109
                  ;
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   110
\end{tikzpicture}
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   111
\end{center}
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   112
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   113
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   114
%\item (Optional) The tokenizer in \texttt{regexp3.scala} takes as
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   115
%argument a string and a list of rules. The result is a list of tokens. Improve this tokenizer so 
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   116
%that it filters out all comments and whitespace from the result.
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   117
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   118
%\item (Optional) Modify the tokenizer in \texttt{regexp2.scala} so that it
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   119
%implements the \texttt{findAll} function. This function takes a regular
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   120
%expressions and a string, and returns all substrings in this string that 
9da175d5eb63 added new hws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   121
%match the regular expression.
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
\end{enumerate}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
42
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   124
% explain what is a context-free grammar and the language it generates 
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   125
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   126
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   127
% Define the language L(M) accepted by a deterministic finite automaton M.
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   128
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   129
%
Christian Urban <urbanc@in.tum.de>
parents: 34
diff changeset
   130
% does (a + b)*b+ and (a*b+) + (b*b+) define the same language
43
Christian Urban <urbanc@in.tum.de>
parents: 42
diff changeset
   131
31
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
\end{document}
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
%%% Local Variables: 
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
%%% mode: latex
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
%%% TeX-master: t
e22ba348b209 added hw04
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
%%% End: