cws/cw01.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 03 Dec 2021 22:07:11 +0000
changeset 857 2b11eb06af76
parent 833 aad5957eb7e4
child 877 43460c7b2010
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 577
diff changeset
     1
% !TEX program = xelatex
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
\documentclass{article}
253
75c469893514 added coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 216
diff changeset
     3
\usepackage{../style}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
     4
\usepackage{../langs}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
     6
\usepackage{array}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
     7
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
     8
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\begin{document}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    10
\newcolumntype{C}[1]{>{\centering}m{#1}}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    12
\section*{Coursework 1}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    14
This coursework is worth 5\% and is due on \cwONE{} at 18:00. You are
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    15
asked to implement a regular expression matcher and submit a document
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    16
containing the answers for the questions below. You can do the
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    17
implementation in any programming language you like, but you need to
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    18
submit the source code with which you answered the questions,
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    19
otherwise a mark of 0\% will be awarded. You can submit your answers
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    20
in a txt-file or pdf.  Code send as code. Please package everything
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    21
inside a zip-file that creates a directory with the name
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    22
\[\texttt{YournameYourfamilyname}\]
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    23
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    24
\noindent on my end. Thanks!
358
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    25
b3129cff41e9 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 351
diff changeset
    26
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    27
750
e93a9e74ca8e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 748
diff changeset
    28
\subsubsection*{Disclaimer\alert}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
    30
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
    31
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
    32
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
    33
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
    34
512
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
    35
\noindent
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
    36
If you have any questions, please send me an email in \textbf{good}
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
    37
time.\bigskip
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    38
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    39
\subsection*{Task}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    40
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    41
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
    42
derivatives of regular expressions. The implementation should
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    43
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
    44
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
\[
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
    46
\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
    47
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
    50
but also with the following extended regular expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
\begin{tabular}{ll}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    54
  $[c_1,c_2,\ldots,c_n]$ & a set of characters---for character ranges\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    55
  $r^+$ & one or more times $r$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    56
  $r^?$ & optional $r$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    57
  $r^{\{n\}}$ & exactly $n$-times\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    58
  $r^{\{..m\}}$ & zero or more times $r$ but no more than $m$-times\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    59
  $r^{\{n..\}}$ & at least $n$-times $r$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    60
  $r^{\{n..m\}}$ & at least $n$-times $r$ but no more than $m$-times\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    61
  $\sim{}r$ & not-regular-expression of $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
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    65
\noindent You can assume that $n$ and $m$ are greater or equal than
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    66
$0$. In the case of $r^{\{n,m\}}$ you can also assume $0 \le n \le m$.\bigskip
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    67
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    68
\noindent {\bf Important!} Your implementation should have explicit
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    69
case classes  for the basic regular expressions, but also explicit case
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    70
classes for
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    71
the extended regular expressions.\footnote{Please call them
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    72
  \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{NTIMES},
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 577
diff changeset
    73
  \code{UPTO}, \code{FROM} and \code{BETWEEN}.} 
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 577
diff changeset
    74
  That means do not treat the extended regular expressions
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    75
by just translating them into the basic ones. See also Question 3,
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
    76
where you are asked to explicitly give the rules for \textit{nullable}
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    77
and \textit{der} for the extended regular expressions. Something like
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    78
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    79
\[der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)\]
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    80
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    81
\noindent is \emph{not} allowed as answer in Question 3 and \emph{not}
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
    82
allowed in your code.\medskip
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    83
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    84
\noindent
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    85
The meanings of the extended regular expressions are
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
\begin{tabular}{r@{\hspace{2mm}}c@{\hspace{2mm}}l}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    89
  $L([c_1,c_2,\ldots,c_n])$ & $\dn$ & $\{[c_1], [c_2], \ldots, [c_n]\}$\\ 
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    90
  $L(r^+)$                  & $\dn$ & $\bigcup_{1\le i}.\;L(r)^i$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    91
  $L(r^?)$                  & $\dn$ & $L(r) \cup \{[]\}$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    92
  $L(r^{\{n\}})$             & $\dn$ & $L(r)^n$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    93
  $L(r^{\{..m\}})$           & $\dn$ & $\bigcup_{0\le i \le m}.\;L(r)^i$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    94
  $L(r^{\{n..\}})$           & $\dn$ & $\bigcup_{n\le i}.\;L(r)^i$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    95
  $L(r^{\{n..m\}})$          & $\dn$ & $\bigcup_{n\le i \le m}.\;L(r)^i$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
    96
  $L(\sim{}r)$              & $\dn$ & $\Sigma^* - L(r)$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   100
\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
   101
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
   102
(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
   103
represented by, say, the type \pcode{Char}). So $\sim{}r$
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   104
means in effect ``all the strings that $r$ cannot match''.\medskip 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   106
\noindent
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   107
Be careful that your implementation of \textit{nullable} and
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   108
\textit{der} satisfies for every regular expression $r$ the following
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   109
two properties (see also Question 3):
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   112
\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
   113
\item $L(der\,c\,r) = Der\,c\,(L(r))$
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
\end{itemize}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   115
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   116
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
512
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
   118
\subsection*{Question 1 (Unmarked)}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   120
What is your King's email address (you will need it in
772
Christian Urban <christian.urban@kcl.ac.uk>
parents: 752
diff changeset
   121
Question 5)? Also could you please let me know from where you will be mainly
833
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 772
diff changeset
   122
studying? (online / in-person, in London / somewhere else) Thanks!
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   123
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   124
\subsection*{Question 2 (Unmarked)}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   125
833
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 772
diff changeset
   126
Can you please also list all programming languages in which you have
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   127
already written programs (include only instances where you have spent
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   128
at least a good working day fiddling with a program)?  This is just
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   129
for my curiosity to estimate what your background is.
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   130
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   131
\subsection*{Question 3}
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   132
473
dc528091eb70 updated
Christian Urban <urbanc@in.tum.de>
parents: 456
diff changeset
   133
From the
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   134
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
   135
\textit{nullable} and \textit{der} for the basic regular
718
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   136
expressions. Implement and write down the rules for the extended
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   137
regular expressions:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   139
\begin{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   140
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   141
  $\textit{nullable}([c_1,c_2,\ldots,c_n])$  & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   142
  $\textit{nullable}(r^+)$                   & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   143
  $\textit{nullable}(r^?)$                   & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   144
  $\textit{nullable}(r^{\{n\}})$              & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   145
  $\textit{nullable}(r^{\{..m\}})$            & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   146
  $\textit{nullable}(r^{\{n..\}})$            & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   147
  $\textit{nullable}(r^{\{n..m\}})$           & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   148
  $\textit{nullable}(\sim{}r)$              & $\dn$ & $?$
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   149
\end{tabular}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   150
\end{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   151
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   152
\begin{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   153
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   154
  $der\, c\, ([c_1,c_2,\ldots,c_n])$  & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   155
  $der\, c\, (r^+)$                   & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   156
  $der\, c\, (r^?)$                   & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   157
  $der\, c\, (r^{\{n\}})$              & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   158
  $der\, c\, (r^{\{..m\}})$           & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   159
  $der\, c\, (r^{\{n..\}})$           & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   160
  $der\, c\, (r^{\{n..m\}})$           & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   161
  $der\, c\, (\sim{}r)$               & $\dn$ & $?$\\
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   162
\end{tabular}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   163
\end{center}
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   164
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   165
\noindent
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   166
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
   167
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   168
\begin{itemize}
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   169
\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
   170
\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
   171
\end{itemize}
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   172
473
dc528091eb70 updated
Christian Urban <urbanc@in.tum.de>
parents: 456
diff changeset
   173
\noindent
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   174
Given the definitions of \textit{nullable} and \textit{der}, it is
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   175
easy to implement a regular expression matcher.  Test your regular
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   176
expression matcher with (at least) the examples:
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   177
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   178
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   179
\begin{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   180
\def\arraystretch{1.2}  
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   181
\begin{tabular}{@{}r|m{3mm}|m{6mm}|m{6mm}|m{10mm}|m{6mm}|m{10mm}|m{10mm}|m{10mm}}
718
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   182
  string & $a^?$ & $\sim{}a$ & $a^{\{3\}}$ & $(a^?)^{\{3\}}$ & $a^{\{..3\}}$ &
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   183
     $(a^?)^{\{..3\}}$ & $a^{\{3..5\}}$ & $(a^?)^{\{3..5\}}$ \\\hline
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   184
  $[]$           &&&&&&& \\\hline 
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   185
  \texttt{a}     &&&&&&& \\\hline 
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   186
  \texttt{aa}    &&&&&&& \\\hline 
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   187
  \texttt{aaa}   &&&&&&& \\\hline 
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   188
  \texttt{aaaaa} &&&&&&& \\\hline 
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   189
  \texttt{aaaaaa}&&&&&&& \\
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   190
\end{tabular}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   191
\end{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   192
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   193
\noindent
718
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   194
Does your matcher produce the expected results? Make sure you
b7f9460c6a1c updated
Christian Urban <urbanc@in.tum.de>
parents: 630
diff changeset
   195
also test corner-cases, like $a^{\{0\}}$!
473
dc528091eb70 updated
Christian Urban <urbanc@in.tum.de>
parents: 456
diff changeset
   196
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   197
\subsection*{Question 4}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
494
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   199
As you can see, there are a number of explicit regular expressions
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   200
that deal with single or several characters, for example:
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   201
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   202
\begin{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   203
\begin{tabular}{ll}
494
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   204
  $c$ & matches a single character\\  
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   205
  $[c_1,c_2,\ldots,c_n]$ & matches a set of characters---for character ranges\\
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   206
  $\textit{ALL}$ & matches any character
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   207
\end{tabular}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   208
\end{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   209
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   210
\noindent
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   211
The latter is useful for matching any string (for example
494
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   212
by using $\textit{ALL}^*$). In order to avoid having an explicit constructor
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   213
for each case, we can generalise all these cases and introduce a single
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   214
constructor $\textit{CFUN}(f)$ where $f$ is a function from characters
576
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   215
to booleans. In Scala code this would look as follows:
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   216
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   217
\begin{lstlisting}[numbers=none]
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   218
abstract class Rexp
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   219
...
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   220
case class CFUN(f: Char => Boolean) extends Rexp 
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   221
\end{lstlisting}\smallskip
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   222
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   223
\noindent
550186034b6e updated
Christian Urban <urbanc@in.tum.de>
parents: 567
diff changeset
   224
The idea is that the function $f$ determines which character(s)
494
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   225
are matched, namely those where $f$ returns \texttt{true}.
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   226
In this question implement \textit{CFUN} and define
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   227
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   228
\begin{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   229
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   230
  $\textit{nullable}(\textit{CFUN}(f))$  & $\dn$ & $?$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   231
  $\textit{der}\,c\,(\textit{CFUN}(f))$  & $\dn$ & $?$
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   232
\end{tabular}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   233
\end{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   234
494
d0fc671bcbbf updated
Christian Urban <urbanc@in.tum.de>
parents: 492
diff changeset
   235
\noindent in your matcher and then also give definitions for
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   236
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   237
\begin{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   238
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   239
  $c$  & $\dn$ & $\textit{CFUN}(?)$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   240
  $[c_1,c_2,\ldots,c_n]$  & $\dn$ & $\textit{CFUN}(?)$\\
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   241
  $\textit{ALL}$  & $\dn$ & $\textit{CFUN}(?)$
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   242
\end{tabular}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   243
\end{center}
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   244
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   245
\noindent
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   246
You can either add the constructor $CFUN$ to your implementation in
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   247
Question 3, or you can implement this questions first
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   248
and then use $CFUN$ instead of \code{RANGE} and \code{CHAR} in Question 3.
833
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 772
diff changeset
   249
In an ideal world one would do this task first, but this might confuse
aad5957eb7e4 cwupdates
Christian Urban <christian.urban@kcl.ac.uk>
parents: 772
diff changeset
   250
you with what you need to do in the previous question.
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   251
545
76a98ed71a2a updated
Christian Urban <urbanc@in.tum.de>
parents: 512
diff changeset
   252
\subsection*{Question 5}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   253
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   254
Suppose $[a\mbox{-}z0\mbox{-}9\_\,.\mbox{-}]$ stands for the regular expression
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   255
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   256
\[[a,b,c,\ldots,z,0,\dots,9,\_,.,\mbox{-}]\;.\]
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   257
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   258
\noindent
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   259
Define in your code the following regular expression for email addresses
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
\[
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   262
([a\mbox{-}z0\mbox{-}9\_\,.-]^+)\cdot @\cdot ([a\mbox{-}z0\mbox{-}9\,.-]^+)\cdot .\cdot ([a\mbox{-}z\,.]^{\{2,6\}})
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
\]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   265
\noindent and calculate the derivative according to your own email
395
e57d3d92b856 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 358
diff changeset
   266
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
   267
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
   268
following 7 simplification rules:
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
\begin{center}
272
1446bc47a294 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   271
\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
   272
$r \cdot \ZERO$ & $\mapsto$ & $\ZERO$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   273
$\ZERO \cdot r$ & $\mapsto$ & $\ZERO$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   274
$r \cdot \ONE$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   275
$\ONE \cdot r$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   276
$r + \ZERO$ & $\mapsto$ & $r$\\ 
7611ace6a93b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 418
diff changeset
   277
$\ZERO + r$ & $\mapsto$ & $r$\\ 
333
8890852e18b7 updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 328
diff changeset
   278
$r + r$ & $\mapsto$ & $r$\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
\end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
418
010c5a03dca2 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 395
diff changeset
   282
\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
   283
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
   284
should use the infix notation $+$, $\cdot$, $^*$ and so on,
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   285
instead of raw code.\bigskip
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   286
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   287
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   288
\subsection*{Question 6}
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   289
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   290
Implement the simplification rules in your regular expression matcher.
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   291
Consider the regular expression $/ \cdot * \cdot
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   292
(\sim{}(\textit{ALL}^* \cdot * \cdot / \cdot \textit{ALL}^*)) \cdot *
630
9b1c15c3eb6f updated
Christian Urban <urbanc@in.tum.de>
parents: 577
diff changeset
   293
\cdot /$ and decide whether the following four strings are matched by
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   294
this regular expression. Answer yes or no.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
\begin{enumerate}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   297
\item \texttt{"/**/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   298
\item \texttt{"/*foobar*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   299
\item \texttt{"/*test*/test*/"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   300
\item \texttt{"/*test/*test*/"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
567
4573d36d0b2f updated
Christian Urban <urbanc@in.tum.de>
parents: 556
diff changeset
   303
\subsection*{Question 7}
512
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
   304
a6aa52ecc1c5 updated
cu
parents: 499
diff changeset
   305
Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
748
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   306
$(a^{\{19,19\}}) \cdot (a^?)$.\medskip
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   307
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   308
\noindent
383f2a5952ce updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 719
diff changeset
   309
Decide whether the following three
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   310
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
   311
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
   312
with yes or no. \medskip
130
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   313
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 129
diff changeset
   314
\noindent
259
e5f4b8ff23b8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 253
diff changeset
   315
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
   316
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
   317
to not introducing any other character.
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
\begin{enumerate}
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   320
\setcounter{enumi}{4}
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   321
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   323
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   324
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   326
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   327
\item \texttt{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\ 
216
f5ec7c597c5b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 133
diff changeset
   329
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
492
39b7ff2cf1bc updated
Christian Urban <urbanc@in.tum.de>
parents: 473
diff changeset
   333
127
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
%%% Local Variables: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
%%% End: