cws/cw01.tex
changeset 966 4189cb63e5db
parent 938 91c20364402b
equal deleted inserted replaced
965:94f5cce73a4f 966:4189cb63e5db
     9 %TEST
     9 %TEST
    10 
    10 
    11 \begin{document}
    11 \begin{document}
    12 \newcolumntype{C}[1]{>{\centering}m{#1}}
    12 \newcolumntype{C}[1]{>{\centering}m{#1}}
    13 
    13 
    14 \section*{Coursework 1}
    14 \section*{Coursework 1 (Update for 2024: CW is OPTIONAL but recommended)}
    15 
    15 
    16 This coursework is worth 5\% and is due on \cwONE{} at 16:00. You are
    16 %You are asked to implement a regular expression matcher and submit a
    17 asked to implement a regular expression matcher and submit a document
    17 %document containing the answers for the questions below. You can do
    18 containing the answers for the questions below. You can do the
    18 %the implementation in any programming language you like, but you need
    19 implementation in any programming language you like, but you need to
    19 %to submit the source code with which you answered the questions,
    20 submit the source code with which you answered the questions,
    20 %otherwise a mark of 0\% will be awarded. You need to submit your
    21 otherwise a mark of 0\% will be awarded. You need to submit your written
    21 %written answers as pdf---see attached questionaire.  Code send as
    22 answers as pdf---see attached questionaire.  Code send as code. If you use
    22 %code. If you use Scala in your code, a good place to start is the file
    23 Scala in your code, a good place to start is the file \texttt{re3.sc}
    23 %\texttt{re3.sc} that is uploaded to Github.
    24 that is uploaded to Github.
       
    25 
    24 
    26 %Please package everything
    25 %Please package everything
    27 %inside a zip-file that creates a directory with the name
    26 %inside a zip-file that creates a directory with the name
    28 %\[\texttt{YournameYourfamilyname}\]
    27 %\[\texttt{YournameYourfamilyname}\]
    29 %
    28 %
    30 %\noindent on my end. Thanks!
    29 %\noindent on my end. Thanks!
    31 
    30 
    32 
    31 
    33 
    32 
    34 \subsubsection*{Disclaimer\alert}
    33 %\subsubsection*{Disclaimer\alert}
    35 
    34 
    36 It should be understood that the work you submit represents
    35 %It should be understood that the work you submit represents
    37 your \textbf{own} effort. You have not copied from anyone else
    36 %your \textbf{own} effort. You have not copied from anyone else
    38 including CoPilot, ChatGPT \& Co. An
    37 %including CoPilot, ChatGPT \& Co. An
    39 exception is the Scala code I showed during the lectures or
    38 %exception is the Scala code I showed during the lectures or
    40 uploaded to KEATS, which you can freely use. Do not
    39 %uploaded to KEATS, which you can freely use. Do not
    41 be tempted to ask Github Copilot for help or do any other
    40 %be tempted to ask Github Copilot for help or do any other
    42 shenanigans like this!\bigskip
    41 %shenanigans like this!\bigskip
    43 
    42 
    44 \noindent
    43 %\noindent
    45 If you have any questions, please send me an email in \textbf{good}
    44 %If you have any questions, please send me an email in \textbf{good}
    46 time!\bigskip
    45 %time!\bigskip
    47 
    46 
    48 \subsection*{Task}
    47 \subsection*{Task}
    49 
    48 
    50 The task is to implement a regular expression matcher based on
    49 The task is to implement a regular expression matcher based on
    51 derivatives of regular expressions. The implementation should
    50 derivatives of regular expressions. The implementation should
    80 classes for
    79 classes for
    81 the extended regular expressions.\footnote{Please call them
    80 the extended regular expressions.\footnote{Please call them
    82   \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{INTER}, \code{NTIMES},
    81   \code{RANGE}, \code{PLUS}, \code{OPTIONAL}, \code{INTER}, \code{NTIMES},
    83   \code{UPTO}, \code{FROM} and \code{BETWEEN}.} 
    82   \code{UPTO}, \code{FROM} and \code{BETWEEN}.} 
    84   That means do not treat the extended regular expressions
    83   That means do not treat the extended regular expressions
    85 by just translating them into the basic ones. See also Question 3,
    84 by just translating them into the basic ones. See also Question 1,
    86 where you are asked to explicitly give the rules for \textit{nullable}
    85 where you are asked to explicitly give the rules for \textit{nullable}
    87 and \textit{der} for the extended regular expressions. Something like
    86 and \textit{der} for the extended regular expressions. Something like
    88 
    87 
    89 \[der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)\]
    88 \[der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)\]
    90 
    89 
    91 \noindent is \emph{not} allowed as answer in Question 3 and \emph{not}
    90 \noindent is \emph{not} allowed as answer in Question 1 and \emph{not}
    92 allowed in your code.\medskip
    91 allowed in your code.\medskip
    93 
    92 
    94 \noindent
    93 \noindent
    95 The meanings of the extended regular expressions are
    94 The meanings of the extended regular expressions are
    96 
    95 
   115 means in effect ``all the strings that $r$ cannot match''.\medskip 
   114 means in effect ``all the strings that $r$ cannot match''.\medskip 
   116 
   115 
   117 \noindent
   116 \noindent
   118 Be careful that your implementation of \textit{nullable} and
   117 Be careful that your implementation of \textit{nullable} and
   119 \textit{der} satisfies for every regular expression $r$ the following
   118 \textit{der} satisfies for every regular expression $r$ the following
   120 two properties (see also Question 3):
   119 two properties (see also Question 1):
   121 
   120 
   122 \begin{itemize}
   121 \begin{itemize}
   123 \item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
   122 \item $\textit{nullable}(r)$ if and only if $[]\in L(r)$
   124 \item $L(der\,c\,r) = Der\,c\,(L(r))$
   123 \item $L(der\,c\,r) = Der\,c\,(L(r))$
   125 \end{itemize}
   124 \end{itemize}
   126 
   125 
   127 
   126 
   128 
   127 
   129 \subsection*{Question 1 (Unmarked)}
   128 %\subsection*{Question 1 (Unmarked)}
   130 
   129 %
   131 What is your King's email address (you will need it in
   130 %What is your King's email address (you will need it in
   132 Question 5)? Also, could you please let me know whether you are
   131 %Question 5)? Also, could you please let me know whether you are
   133 a BSc / MSci and the year you are in (in case of MSci). Thanks!
   132 %a BSc / MSci and the year you are in (in case of MSci). Thanks!
   134 
   133 
   135 
   134 
   136 \subsection*{Question 2 (Unmarked)}
   135 %\subsection*{Question 2 (Unmarked)}
   137 
   136 %
   138 Can you please also list all programming languages in which you have
   137 %Can you please also list all programming languages in which you have
   139 already written programs (include only instances where you have spent
   138 %already written programs (include only instances where you have spent
   140 at least a good working day fiddling with a program)?  This is just
   139 %at least a good working day fiddling with a program)?  This is just
   141 for my curiosity to estimate what your background is.
   140 %for my curiosity to estimate what your background is.
   142 
   141 
   143 \subsection*{Question 3}
   142 \subsection*{Question 1}
   144 
   143 
   145 From the lectures you have seen the definitions for the functions
   144 From the lectures you have seen the definitions for the functions
   146 \textit{nullable} and \textit{der} for the basic regular
   145 \textit{nullable} and \textit{der} for the basic regular
   147 expressions. Implement and \underline{write down} the rules for the
   146 expressions. Implement and \underline{write down} the rules for the
   148 extended regular expressions (see questionaire at the end).
   147 extended regular expressions (see questionaire at the end).
   178 
   177 
   179 \noindent
   178 \noindent
   180 Does your matcher produce the expected results? Make sure you
   179 Does your matcher produce the expected results? Make sure you
   181 also test corner-cases, like $a^{\{0\}}$!
   180 also test corner-cases, like $a^{\{0\}}$!
   182 
   181 
   183 \subsection*{Question 4}
   182 \subsection*{Question 2}
   184 
   183 
   185 As you can see, there are a number of explicit regular expressions
   184 As you can see, there are a number of explicit regular expressions
   186 that deal with single or several characters, for example:
   185 that deal with single or several characters, for example:
   187 
   186 
   188 \begin{center}
   187 \begin{center}
   233 Question 3, or you can implement this questions first
   232 Question 3, or you can implement this questions first
   234 and then use $CFUN$ instead of \code{RANGE} and \code{CHAR} in Question 3.
   233 and then use $CFUN$ instead of \code{RANGE} and \code{CHAR} in Question 3.
   235 In an ideal world one would do this task first, but this might confuse
   234 In an ideal world one would do this task first, but this might confuse
   236 you with what you need to do in the previous question.
   235 you with what you need to do in the previous question.
   237 
   236 
   238 \subsection*{Question 5}
   237 \subsection*{Question 3}
   239 
   238 
   240 Suppose $[a\mbox{-}z0\mbox{-}9\_\,.\mbox{-}]$ stands for the regular expression
   239 Suppose $[a\mbox{-}z0\mbox{-}9\_\,.\mbox{-}]$ stands for the regular expression
   241 
   240 
   242 \[[a,b,c,\ldots,z,0,\dots,9,\_,.,\mbox{-}]\;.\]
   241 \[[a,b,c,\ldots,z,0,\dots,9,\_,.,\mbox{-}]\;.\]
   243 
   242 
   269 notation using parentheses where necessary. That means you
   268 notation using parentheses where necessary. That means you
   270 should use the infix notation $+$, $\cdot$, $^*$ and so on,
   269 should use the infix notation $+$, $\cdot$, $^*$ and so on,
   271 instead of raw code.\bigskip
   270 instead of raw code.\bigskip
   272 
   271 
   273 
   272 
   274 \subsection*{Question 6}
   273 \subsection*{Question 4}
   275 
   274 
   276 Implement the simplification rules in your regular expression matcher.
   275 Implement the simplification rules in your regular expression matcher.
   277 Consider the regular expression $/ \cdot * \cdot
   276 Consider the regular expression $/ \cdot * \cdot
   278 (\sim{}(\textit{ALL}^* \cdot * \cdot / \cdot \textit{ALL}^*)) \cdot *
   277 (\sim{}(\textit{ALL}^* \cdot * \cdot / \cdot \textit{ALL}^*)) \cdot *
   279 \cdot /$ and decide whether the following four strings are matched by
   278 \cdot /$ and decide whether the following four strings are matched by
   284 \item \texttt{"/*foobar*/"}
   283 \item \texttt{"/*foobar*/"}
   285 \item \texttt{"/*test*/test*/"}
   284 \item \texttt{"/*test*/test*/"}
   286 \item \texttt{"/*test/*test*/"}
   285 \item \texttt{"/*test/*test*/"}
   287 \end{enumerate}
   286 \end{enumerate}
   288 
   287 
   289 \subsection*{Question 7}
   288 \subsection*{Question 5}
   290 
   289 
   291 Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
   290 Let $r_1$ be the regular expression $a\cdot a\cdot a$ and $r_2$ be
   292 $(a^{\{19,19\}}) \cdot (a^?)$.\medskip
   291 $(a^{\{19,19\}}) \cdot (a^?)$.\medskip
   293 
   292 
   294 \noindent
   293 \noindent
   337 
   336 
   338 \noindent
   337 \noindent
   339 \uline{\hfill}\bigskip\bigskip
   338 \uline{\hfill}\bigskip\bigskip
   340 
   339 
   341 \noindent
   340 \noindent
   342 \textbf{Question 3:}
   341 \textbf{Question 1:}
   343 
   342 
   344 \begin{center}
   343 \begin{center}
   345 \def\arraystretch{1.6}  
   344 \def\arraystretch{1.6}  
   346 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   345 \begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   347   $\textit{nullable}([c_1,c_2,\ldots,c_n])$  & $\dn$ & \uline{\hspace{8cm}}\\
   346   $\textit{nullable}([c_1,c_2,\ldots,c_n])$  & $\dn$ & \uline{\hspace{8cm}}\\
   377 \end{tabular}
   376 \end{tabular}
   378 \end{center}\bigskip
   377 \end{center}\bigskip
   379 
   378 
   380 
   379 
   381 \noindent
   380 \noindent
   382 \textbf{Question 4:}
   381 \textbf{Question 2:}
   383 
   382 
   384 \begin{center}
   383 \begin{center}
   385 \def\arraystretch{1.6}    
   384 \def\arraystretch{1.6}    
   386 \begin{tabular}{@ {}r@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   385 \begin{tabular}{@ {}r@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
   387   $\textit{nullable}(CFUN(f))$  & $\dn$ & \uline{\hspace{8cm}}\\
   386   $\textit{nullable}(CFUN(f))$  & $\dn$ & \uline{\hspace{8cm}}\\
   397 \end{center}
   396 \end{center}
   398 
   397 
   399 \newpage
   398 \newpage
   400 
   399 
   401 \noindent
   400 \noindent
   402 \textbf{Question 5 (`mathematical' notation):}
   401 \textbf{Question 3 (`mathematical' notation):}
   403 
   402 
   404 \noindent
   403 \noindent
   405 \uline{\hfill}\medskip
   404 \uline{\hfill}\medskip
   406 
   405 
   407 \noindent
   406 \noindent
   415 
   414 
   416 \noindent
   415 \noindent
   417 \uline{\hfill}\bigskip\bigskip
   416 \uline{\hfill}\bigskip\bigskip
   418 
   417 
   419 \noindent
   418 \noindent
   420 \textbf{Question 6:}\medskip
   419 \textbf{Question 4:}\medskip
   421 
   420 
   422 \noindent
   421 \noindent
   423 \textbf{1)}\; Yes / No\qquad
   422 \textbf{1)}\; Yes / No\qquad
   424 \textbf{2)}\; Yes / No\qquad
   423 \textbf{2)}\; Yes / No\qquad
   425 \textbf{3)}\; Yes / No\qquad
   424 \textbf{3)}\; Yes / No\qquad
   426 \textbf{4)}\; Yes / No\bigskip\bigskip
   425 \textbf{4)}\; Yes / No\bigskip\bigskip
   427 
   426 
   428 
   427 
   429 \noindent
   428 \noindent
   430 \textbf{Question 7:}\medskip
   429 \textbf{Question 5:}\medskip
   431 
   430 
   432 \def\arraystretch{1.5}
   431 \def\arraystretch{1.5}
   433 \begin{tabular}{l|c|c}
   432 \begin{tabular}{l|c|c}
   434   & $\quad{}r_1\quad$ & $\quad{}r_2\quad$\\\hline
   433   & $\quad{}r_1\quad$ & $\quad{}r_2\quad$\\\hline
   435   1. & & \\\hline
   434   1. & & \\\hline