coursework/cw01.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 13 Oct 2016 12:55:42 +0100
changeset 447 68769db65185
parent 439 7611ace6a93b
child 456 2fddf8ab744f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass{article}
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 216
diff changeset
     2
\usepackage{../style}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
     3
\usepackage{../langs}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
     7
\section*{Coursework 1 (Strand 1)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
     9
This coursework is worth 4\% and is due on 20 October at
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    10
16:00. You are asked to implement a regular expression matcher
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    11
and submit a document containing the answers for the questions
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    12
below. You can do the implementation in any programming
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    13
language you like, but you need to submit the source code with
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    14
which you answered the questions, otherwise a mark of 0\% will
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    15
be awarded. You can submit your answers in a txt-file or pdf.
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    16
Code send as code.
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    17
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    18
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    19
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    20
\subsubsection*{Disclaimer}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    22
It should be understood that the work you submit represents
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    23
your own effort. You have not copied from anyone else. An
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    24
exception is the Scala code I showed during the lectures or
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    25
uploaded to KEATS, which you can freely use.\bigskip
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    26
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    27
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    28
\subsubsection*{Task}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    29
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    30
The task is to implement a regular expression matcher based on
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    31
derivatives of regular expressions. The implementation should
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    32
be able to deal with the usual (basic) regular expressions
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\[
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    35
\ZERO,\; \ONE,\; c,\; r_1 + r_2,\; r_1 \cdot r_2,\; r^*
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    39
but also with the following extended regular expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
\begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
$[c_1 c_2 \ldots c_n]$ & a range of characters\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
$r^+$ & one or more times $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
$r^?$ & optional $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
$r^{\{n,m\}}$ & at least $n$-times $r$ but no more than $m$-times\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
$\sim{}r$ & not-regular expression of $r$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    51
\noindent In the case of $r^{\{n,m\}}$ you can assume the
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    52
convention that $0 \le n \le m$. The meanings of the extended
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    53
regular expressions are
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
\begin{tabular}{r@{\hspace{2mm}}c@{\hspace{2mm}}l}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    57
$L([c_1 c_2 \ldots c_n])$ & $\dn$ & $\{[c_1], [c_2], \ldots, [c_n]\}$\\ 
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    58
$L(r^+)$                  & $\dn$ & $\bigcup_{1\le i}. L(r)^i$\\
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    59
$L(r^?)$                  & $\dn$ & $L(r) \cup \{[]\}$\\
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    60
$L(r^{\{n,m\}})$           & $\dn$ & $\bigcup_{n\le i \le m}. L(r)^i$\\
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
    61
$L(\sim{}r)$              & $\dn$ & $\Sigma^* - L(r)$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    65
\noindent whereby in the last clause the set $\Sigma^*$ stands
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    66
for the set of \emph{all} strings over the alphabet $\Sigma$
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    67
(in the implementation the alphabet can be just what is
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    68
represented by, say, the type \pcode{Char}). So $\sim{}r$
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    69
means `all the strings that $r$ cannot match'. 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    71
Be careful that your implementation of \textit{nullable} and
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    72
\textit{der} satisfies for every $r$ the following two
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    73
properties (see also Question 2):
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    76
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    77
\item $L(der\,c\,r) = Der\,c\,(L(r))$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
\end{itemize}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    79
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    80
\noindent {\bf Important!} Your implementation should have
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    81
explicit cases for the basic regular expressions, but also
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    82
explicit cases for the extended regular expressions. That
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    83
means do not treat the extended regular expressions by just
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    84
translating them into the basic ones. See also Question 2,
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    85
where you are asked to explicitly give the rules for
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    86
\textit{nullable} and \textit{der} for the extended regular
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    87
expressions.
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    88
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    90
\subsection*{Question 1}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    92
What is your King's email address (you will need it in
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    93
Question 3)?
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    94
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    95
\subsection*{Question 2}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    96
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    97
This question does not require any implementation. From the
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    98
lectures you have seen the definitions for the functions
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    99
\textit{nullable} and \textit{der} for the basic regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   100
expressions. Give the rules for the extended regular
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   101
expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   103
\begin{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   104
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   105
$\textit{nullable}([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   106
$\textit{nullable}(r^+)$                   & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   107
$\textit{nullable}(r^?)$                   & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   108
$\textit{nullable}(r^{\{n,m\}})$            & $\dn$ & $?$\\
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   109
$\textit{nullable}(\sim{}r)$               & $\dn$ & $?$\medskip\\
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   110
$der\, c\, ([c_1 c_2 \ldots c_n])$  & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   111
$der\, c\, (r^+)$                   & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   112
$der\, c\, (r^?)$                   & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   113
$der\, c\, (r^{\{n,m\}})$            & $\dn$ & $?$\\
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   114
$der\, c\, (\sim{}r)$               & $\dn$ & $?$\\
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   115
\end{tabular}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   116
\end{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   117
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   118
\noindent
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   119
Remember your definitions have to satisfy the two properties
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   120
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   121
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   122
\item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   123
\item $L(der\,c\,r)) = Der\,c\,(L(r))$
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   124
\end{itemize}
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   125
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   126
\subsection*{Question 3}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
Implement the following regular expression for email addresses
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
\[
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
([a\mbox{-}z0\mbox{-}9\_\!\_\,.-]^+)\cdot @\cdot ([a\mbox{-}z0\mbox{-}9\,.-]^+)\cdot .\cdot ([a\mbox{-}z\,.]^{\{2,6\}})
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   134
\noindent and calculate the derivative according to your email
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   135
address. When calculating the derivative, simplify all regular
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   136
expressions as much as possible by applying the
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   137
following 7 simplification rules:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
\begin{center}
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   140
\begin{tabular}{l@{\hspace{2mm}}c@{\hspace{2mm}}ll}
439
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   141
$r \cdot \ZERO$ & $\mapsto$ & $\ZERO$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   142
$\ZERO \cdot r$ & $\mapsto$ & $\ZERO$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   143
$r \cdot \ONE$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   144
$\ONE \cdot r$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   145
$r + \ZERO$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   146
$\ZERO + r$ & $\mapsto$ & $r$\\ 
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   147
$r + r$ & $\mapsto$ & $r$\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   151
\noindent Write down your simplified derivative in a readable
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   152
notation using parentheses where necessary. That means you
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   153
should use the infix notation $+$, $\cdot$, $^*$ and so on,
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   154
instead of code.
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   155
 
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   156
\subsection*{Question 4}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
260
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   158
Suppose \textit{[a-z]} stands for the range regular expression
65d1ea0e989f updated cws
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   159
$[a,b,c,\ldots,z]$.  Consider the regular expression $/ \cdot * \cdot
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   160
(\sim{}([a\mbox{-}z]^* \cdot * \cdot / \cdot [a\mbox{-}z]^*)) \cdot *
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   161
\cdot /$ and decide wether the following four strings are matched by
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   162
this regular expression. Answer yes or no.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
\begin{enumerate}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   165
\item \texttt{"/**/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   166
\item \texttt{"/*foobar*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   167
\item \texttt{"/*test*/test*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   168
\item \texttt{"/*test/*test*/"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   171
\noindent
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   172
Also test your regular expression matcher with the regular
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   173
expression $a^{\{3,5\}}$ and the strings
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   174
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   175
\begin{enumerate}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   176
\setcounter{enumi}{4}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   177
\item \texttt{aa}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   178
\item \texttt{aaa}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   179
\item \texttt{aaaaa}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   180
\item \texttt{aaaaaa}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   181
\end{enumerate}
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   182
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   183
\noindent
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   184
Does your matcher produce the expected results?
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   185
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   186
\subsection*{Question 5}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   188
Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   189
$(a^{\{19,19\}}) \cdot (a^?)$.  Decide whether the following three
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   190
strings consisting of $a$s only can be matched by $(r_1^+)^+$.
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   191
Similarly test them with $(r_2^+)^+$. Again answer in all six cases
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   192
with yes or no. \medskip
130
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   193
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   194
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   195
These are strings are meant to be entirely made up of $a$s. Be careful
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   196
when copy-and-pasting the strings so as to not forgetting any $a$ and
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   197
to not introducing any other character.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
\begin{enumerate}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   200
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   202
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   203
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   205
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   206
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   208
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
%%% End: