cws/cw04.tex
author Christian Urban <urbanc@in.tum.de>
Tue, 27 Nov 2018 21:41:59 +0000
changeset 218 22705d22c105
parent 111 cd6b9fe4bce5
child 221 9e7897f25e13
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass{article}
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
     2
\usepackage{../style}
78
85f2f75abeeb updated
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
     3
\usepackage{../langs}
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     4
\usepackage{disclaimer}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     5
\usepackage{tikz}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     6
\usepackage{pgf}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     7
\usepackage{pgfplots}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     8
\usepackage{stackengine}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
     9
%% \usepackage{accents}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    10
\newcommand\barbelow[1]{\stackunder[1.2pt]{#1}{\raisebox{-4mm}{\boldmath$\uparrow$}}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    11
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    12
\begin{filecontents}{re-python2.data}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    13
1 0.033
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    14
5 0.036
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    15
10 0.034
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    16
15 0.036
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    17
18 0.059
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    18
19 0.084 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    19
20 0.141
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    20
21 0.248
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    21
22 0.485
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    22
23 0.878
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    23
24 1.71
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    24
25 3.40
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    25
26 7.08
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    26
27 14.12
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    27
28 26.69
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    28
\end{filecontents}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    29
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    30
\begin{filecontents}{re-java.data}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    31
5  0.00298
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    32
10  0.00418
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    33
15  0.00996
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    34
16  0.01710
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    35
17  0.03492
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    36
18  0.03303
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    37
19  0.05084
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    38
20  0.10177
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    39
21  0.19960
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    40
22  0.41159
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    41
23  0.82234
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    42
24  1.70251
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    43
25  3.36112
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    44
26  6.63998
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    45
27  13.35120
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    46
28  29.81185
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    47
\end{filecontents}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    48
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    49
\begin{filecontents}{re-java9.data}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    50
1000  0.01410
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    51
2000  0.04882
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    52
3000  0.10609
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    53
4000  0.17456
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    54
5000  0.27530
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    55
6000  0.41116
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    56
7000  0.53741
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    57
8000  0.70261
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    58
9000  0.93981
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    59
10000 0.97419
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    60
11000 1.28697
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    61
12000 1.51387
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    62
14000 2.07079
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    63
16000 2.69846
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    64
20000 4.41823
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    65
24000 6.46077
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    66
26000 7.64373
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    67
30000 9.99446
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    68
34000 12.966885
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    69
38000 16.281621
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    70
42000 19.180228
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    71
46000 21.984721
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    72
50000 26.950203
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    73
60000 43.0327746
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    74
\end{filecontents}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    75
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
\begin{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    79
% BF IDE
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    80
% https://www.microsoft.com/en-us/p/brainf-ck/9nblgggzhvq5
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    81
  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    82
\section*{Coursework 8 (Regular Expressions and Brainf***)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    84
This coursework is worth 10\%. It is about regular expressions,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    85
pattern matching and an interpreter. The first part is due on 30
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    86
November at 11pm; the second, more advanced part, is due on 21
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    87
December at 11pm. In the first part, you are asked to implement a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    88
regular expression matcher based on derivatives of regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    89
expressions. The reason is that regular expression matching in Java
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    90
and Python can sometimes be extremely slow. The advanced part is about
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    91
an interpreter for a very simple programming language.\bigskip
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    92
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    93
\IMPORTANT{}
62
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
    94
2151c77e1e24 updated
Christian Urban <urbanc@in.tum.de>
parents: 6
diff changeset
    95
\noindent
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    96
Also note that the running time of each part will be restricted to a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    97
maximum of 30 seconds on my laptop.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    98
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
    99
\DISCLAIMER{}
86
f8a781322499 updated
Christian Urban <urbanc@in.tum.de>
parents: 79
diff changeset
   100
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   102
\subsection*{Part 1 (6 Marks)}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   103
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   104
The task is to implement a regular expression matcher that is based on
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   105
derivatives of regular expressions. Most of the functions are defined by
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   106
recursion over regular expressions and can be elegantly implemented
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   107
using Scala's pattern-matching. The implementation should deal with the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   108
following regular expressions, which have been predefined in the file
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   109
\texttt{re.scala}:
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   111
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   112
\begin{tabular}{lcll}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   113
  $r$ & $::=$ & $\ZERO$     & cannot match anything\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   114
      &   $|$ & $\ONE$      & can only match the empty string\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   115
      &   $|$ & $c$         & can match a single character (in this case $c$)\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   116
      &   $|$ & $r_1 + r_2$ & can match a string either with $r_1$ or with $r_2$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   117
  &   $|$ & $r_1\cdot r_2$ & can match the first part of a string with $r_1$ and\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   118
          &  & & then the second part with $r_2$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   119
      &   $|$ & $r^*$       & can match zero or more times $r$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   120
\end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   121
\end{center}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   123
\noindent 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   124
Why? Knowing how to match regular expressions and strings will let you
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   125
solve a lot of problems that vex other humans. Regular expressions are
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   126
one of the fastest and simplest ways to match patterns in text, and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   127
are endlessly useful for searching, editing and analysing data in all
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   128
sorts of places (for example analysing network traffic in order to
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   129
detect security breaches). However, you need to be fast, otherwise you
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   130
will stumble over problems such as recently reported at
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   131
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   132
{\small
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   133
\begin{itemize}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   134
\item[$\bullet$] \url{http://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   135
\item[$\bullet$] \url{https://vimeo.com/112065252}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   136
\item[$\bullet$] \url{http://davidvgalbraith.com/how-i-fixed-atom/}  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   137
\end{itemize}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   138
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   139
\subsubsection*{Tasks (file re.scala)}
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   141
The file \texttt{re.scala} has already a definition for regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   142
expressions and also defines some handy shorthand notation for
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   143
regular expressions. The notation in this document matches up
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   144
with the code in the file as follows:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   145
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   146
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   147
  \begin{tabular}{rcl@{\hspace{10mm}}l}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   148
    & & code: & shorthand:\smallskip \\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   149
  $\ZERO$ & $\mapsto$ & \texttt{ZERO}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   150
  $\ONE$  & $\mapsto$ & \texttt{ONE}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   151
  $c$     & $\mapsto$ & \texttt{CHAR(c)}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   152
  $r_1 + r_2$ & $\mapsto$ & \texttt{ALT(r1, r2)} & \texttt{r1 | r2}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   153
  $r_1 \cdot r_2$ & $\mapsto$ & \texttt{SEQ(r1, r2)} & \texttt{r1 $\sim$ r2}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   154
  $r^*$ & $\mapsto$ &  \texttt{STAR(r)} & \texttt{r.\%}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   155
\end{tabular}    
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   156
\end{center}  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   157
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   158
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   159
\begin{itemize}
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   160
\item[(1a)] Implement a function, called \textit{nullable}, by
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   161
  recursion over regular expressions. This function tests whether a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   162
  regular expression can match the empty string. This means given a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   163
  regular expression it either returns true or false. The function
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   164
  \textit{nullable}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   165
  is defined as follows:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   166
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   167
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   168
\begin{tabular}{lcl}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   169
$\textit{nullable}(\ZERO)$ & $\dn$ & $\textit{false}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   170
$\textit{nullable}(\ONE)$  & $\dn$ & $\textit{true}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   171
$\textit{nullable}(c)$     & $\dn$ & $\textit{false}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   172
$\textit{nullable}(r_1 + r_2)$ & $\dn$ & $\textit{nullable}(r_1) \vee \textit{nullable}(r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   173
$\textit{nullable}(r_1 \cdot r_2)$ & $\dn$ & $\textit{nullable}(r_1) \wedge \textit{nullable}(r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   174
$\textit{nullable}(r^*)$ & $\dn$ & $\textit{true}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   175
\end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   176
\end{center}~\hfill[1 Mark]
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   177
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   178
\item[(1b)] Implement a function, called \textit{der}, by recursion over
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   179
  regular expressions. It takes a character and a regular expression
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   180
  as arguments and calculates the derivative regular expression according
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   181
  to the rules:
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   182
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   183
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   184
\begin{tabular}{lcl}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   185
$\textit{der}\;c\;(\ZERO)$ & $\dn$ & $\ZERO$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   186
$\textit{der}\;c\;(\ONE)$  & $\dn$ & $\ZERO$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   187
$\textit{der}\;c\;(d)$     & $\dn$ & $\textit{if}\; c = d\;\textit{then} \;\ONE \; \textit{else} \;\ZERO$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   188
$\textit{der}\;c\;(r_1 + r_2)$ & $\dn$ & $(\textit{der}\;c\;r_1) + (\textit{der}\;c\;r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   189
$\textit{der}\;c\;(r_1 \cdot r_2)$ & $\dn$ & $\textit{if}\;\textit{nullable}(r_1)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   190
      & & $\textit{then}\;((\textit{der}\;c\;r_1)\cdot r_2) + (\textit{der}\;c\;r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   191
      & & $\textit{else}\;(\textit{der}\;c\;r_1)\cdot r_2$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   192
$\textit{der}\;c\;(r^*)$ & $\dn$ & $(\textit{der}\;c\;r)\cdot (r^*)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   193
\end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   194
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   195
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   196
For example given the regular expression $r = (a \cdot b) \cdot c$, the derivatives
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   197
w.r.t.~the characters $a$, $b$ and $c$ are
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   198
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   199
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   200
  \begin{tabular}{lcll}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   201
    $\textit{der}\;a\;r$ & $=$ & $(\ONE \cdot b)\cdot c$ & ($= r'$)\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   202
    $\textit{der}\;b\;r$ & $=$ & $(\ZERO \cdot b)\cdot c$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   203
    $\textit{der}\;c\;r$ & $=$ & $(\ZERO \cdot b)\cdot c$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   204
  \end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   205
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   206
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   207
Let $r'$ stand for the first derivative, then taking the derivatives of $r'$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   208
w.r.t.~the characters $a$, $b$ and $c$ gives
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   209
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   210
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   211
  \begin{tabular}{lcll}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   212
    $\textit{der}\;a\;r'$ & $=$ & $((\ZERO \cdot b) + \ZERO)\cdot c$ \\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   213
    $\textit{der}\;b\;r'$ & $=$ & $((\ZERO \cdot b) + \ONE)\cdot c$ & ($= r''$)\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   214
    $\textit{der}\;c\;r'$ & $=$ & $((\ZERO \cdot b) + \ZERO)\cdot c$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   215
  \end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   216
\end{center}
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   217
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   218
One more example: Let $r''$ stand for the second derivative above,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   219
then taking the derivatives of $r''$ w.r.t.~the characters $a$, $b$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   220
and $c$ gives
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   221
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   222
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   223
  \begin{tabular}{lcll}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   224
    $\textit{der}\;a\;r''$ & $=$ & $((\ZERO \cdot b) + \ZERO) \cdot c + \ZERO$ \\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   225
    $\textit{der}\;b\;r''$ & $=$ & $((\ZERO \cdot b) + \ZERO) \cdot c + \ZERO$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   226
    $\textit{der}\;c\;r''$ & $=$ & $((\ZERO \cdot b) + \ZERO) \cdot c + \ONE$ &
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   227
    (is $\textit{nullable}$)                      
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   228
  \end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   229
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   230
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   231
Note, the last derivative can match the empty string, that is it is \textit{nullable}.\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   232
\mbox{}\hfill\mbox{[1 Mark]}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   233
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   234
\item[(1c)] Implement the function \textit{simp}, which recursively
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   235
  traverses a regular expression from the inside to the outside, and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   236
  on the way simplifies every regular expression on the left (see
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   237
  below) to the regular expression on the right, except it does not
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   238
  simplify inside ${}^*$-regular expressions.
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   239
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   240
  \begin{center}
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   241
\begin{tabular}{l@{\hspace{4mm}}c@{\hspace{4mm}}ll}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   242
$r \cdot \ZERO$ & $\mapsto$ & $\ZERO$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   243
$\ZERO \cdot r$ & $\mapsto$ & $\ZERO$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   244
$r \cdot \ONE$ & $\mapsto$ & $r$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   245
$\ONE \cdot r$ & $\mapsto$ & $r$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   246
$r + \ZERO$ & $\mapsto$ & $r$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   247
$\ZERO + r$ & $\mapsto$ & $r$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   248
$r + r$ & $\mapsto$ & $r$\\ 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   249
\end{tabular}
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   250
  \end{center}
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   251
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   252
  For example the regular expression
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   253
  \[(r_1 + \ZERO) \cdot \ONE + ((\ONE + r_2) + r_3) \cdot (r_4 \cdot \ZERO)\]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   254
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   255
  simplifies to just $r_1$. \textbf{Hint:} Regular expressions can be
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   256
  seen as trees and there are several methods for traversing
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   257
  trees. One of them corresponds to the inside-out traversal, which is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   258
  sometimes also called post-order traversal. Furthermore,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   259
  remember numerical expressions from school times: there you had expressions
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   260
  like $u + \ldots + (1 \cdot x) - \ldots (z + (y \cdot 0)) \ldots$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   261
  and simplification rules that looked very similar to rules
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   262
  above. You would simplify such numerical expressions by replacing
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   263
  for example the $y \cdot 0$ by $0$, or $1\cdot x$ by $x$, and then
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   264
  look whether more rules are applicable. If you organise the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   265
  simplification in an inside-out fashion, it is always clear which
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   266
  rule should be applied next.\hfill[2 Marks]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   267
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   268
\item[(1d)] Implement two functions: The first, called \textit{ders},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   269
  takes a list of characters and a regular expression as arguments, and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   270
  builds the derivative w.r.t.~the list as follows:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   271
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   272
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   273
\begin{tabular}{lcl}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   274
$\textit{ders}\;(Nil)\;r$ & $\dn$ & $r$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   275
  $\textit{ders}\;(c::cs)\;r$  & $\dn$ &
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   276
    $\textit{ders}\;cs\;(\textit{simp}(\textit{der}\;c\;r))$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   277
\end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   278
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   279
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   280
Note that this function is different from \textit{der}, which only
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   281
takes a single character.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   282
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   283
The second function, called \textit{matcher}, takes a string and a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   284
regular expression as arguments. It builds first the derivatives
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   285
according to \textit{ders} and after that tests whether the resulting
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   286
derivative regular expression can match the empty string (using
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   287
\textit{nullable}).  For example the \textit{matcher} will produce
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   288
true for the regular expression $(a\cdot b)\cdot c$ and the string
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   289
$abc$, but false if you give it the string $ab$. \hfill[1 Mark]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   290
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   291
\item[(1e)] Implement a function, called \textit{size}, by recursion
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   292
  over regular expressions. If a regular expression is seen as a tree,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   293
  then \textit{size} should return the number of nodes in such a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   294
  tree. Therefore this function is defined as follows:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   295
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   296
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   297
\begin{tabular}{lcl}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   298
$\textit{size}(\ZERO)$ & $\dn$ & $1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   299
$\textit{size}(\ONE)$  & $\dn$ & $1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   300
$\textit{size}(c)$     & $\dn$ & $1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   301
$\textit{size}(r_1 + r_2)$ & $\dn$ & $1 + \textit{size}(r_1) + \textit{size}(r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   302
$\textit{size}(r_1 \cdot r_2)$ & $\dn$ & $1 + \textit{size}(r_1) + \textit{size}(r_2)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   303
$\textit{size}(r^*)$ & $\dn$ & $1 + \textit{size}(r)$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   304
\end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   305
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   306
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   307
You can use \textit{size} in order to test how much the `evil' regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   308
expression $(a^*)^* \cdot b$ grows when taking successive derivatives
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   309
according the letter $a$ without simplification and then compare it to
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   310
taking the derivative, but simplify the result.  The sizes
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   311
are given in \texttt{re.scala}. \hfill[1 Mark]
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   312
\end{itemize}
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   313
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   314
\subsection*{Background}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   315
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   316
Although easily implementable in Scala, the idea behind the derivative
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   317
function might not so easy to be seen. To understand its purpose
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   318
better, assume a regular expression $r$ can match strings of the form
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   319
$c\!::\!cs$ (that means strings which start with a character $c$ and have
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   320
some rest, or tail, $cs$). If you take the derivative of $r$ with
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   321
respect to the character $c$, then you obtain a regular expression
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   322
that can match all the strings $cs$.  In other words, the regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   323
expression $\textit{der}\;c\;r$ can match the same strings $c\!::\!cs$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   324
that can be matched by $r$, except that the $c$ is chopped off.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   325
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   326
Assume now $r$ can match the string $abc$. If you take the derivative
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   327
according to $a$ then you obtain a regular expression that can match
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   328
$bc$ (it is $abc$ where the $a$ has been chopped off). If you now
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   329
build the derivative $\textit{der}\;b\;(\textit{der}\;a\;r)$ you
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   330
obtain a regular expression that can match the string $c$ (it is $bc$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   331
where $b$ is chopped off). If you finally build the derivative of this
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   332
according $c$, that is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   333
$\textit{der}\;c\;(\textit{der}\;b\;(\textit{der}\;a\;r))$, you obtain
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   334
a regular expression that can match the empty string. You can test
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   335
whether this is indeed the case using the function nullable, which is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   336
what your matcher is doing.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   337
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   338
The purpose of the $\textit{simp}$ function is to keep the regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   339
expressions small. Normally the derivative function makes the regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   340
expression bigger (see the SEQ case and the example in (1b)) and the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   341
algorithm would be slower and slower over time. The $\textit{simp}$
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   342
function counters this increase in size and the result is that the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   343
algorithm is fast throughout.  By the way, this algorithm is by Janusz
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   344
Brzozowski who came up with the idea of derivatives in 1964 in his PhD
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   345
thesis.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   346
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   347
\begin{center}\small
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   348
\url{https://en.wikipedia.org/wiki/Janusz_Brzozowski_(computer_scientist)}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   349
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   350
105
67ce930b5935 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   351
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   352
If you want to see how badly the regular expression matchers do in
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   353
Java\footnote{Version 8 and below; Version 9 does not seem to be as
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   354
  catastrophic, but still worse than the regular expression matcher
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   355
based on derivatives.} and in Python with the `evil' regular
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   356
expression $(a^*)^*\cdot b$, then have a look at the graphs below (you
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   357
can try it out for yourself: have a look at the file
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   358
\texttt{catastrophic.java} and \texttt{catastrophic.py} on
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   359
KEATS). Compare this with the matcher you have implemented. How long
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   360
can the string of $a$'s be in your matcher and still stay within the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   361
30 seconds time limit?
78
85f2f75abeeb updated
Christian Urban <urbanc@in.tum.de>
parents: 75
diff changeset
   362
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   363
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   364
\begin{tabular}{@{}cc@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   365
\multicolumn{2}{c}{Graph: $(a^*)^*\cdot b$ and strings 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   366
           $\underbrace{a\ldots a}_{n}$}\bigskip\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   367
  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   368
\begin{tikzpicture}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   369
\begin{axis}[
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   370
    xlabel={$n$},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   371
    x label style={at={(1.05,0.0)}},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   372
    ylabel={time in secs},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   373
    y label style={at={(0.06,0.5)}},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   374
    enlargelimits=false,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   375
    xtick={0,5,...,30},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   376
    xmax=33,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   377
    ymax=45,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   378
    ytick={0,5,...,40},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   379
    scaled ticks=false,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   380
    axis lines=left,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   381
    width=6cm,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   382
    height=5.5cm, 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   383
    legend entries={Python, Java 8},  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   384
    legend pos=north west]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   385
\addplot[blue,mark=*, mark options={fill=white}] table {re-python2.data};
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   386
\addplot[cyan,mark=*, mark options={fill=white}] table {re-java.data};
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   387
\end{axis}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   388
\end{tikzpicture}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   389
  & 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   390
\begin{tikzpicture}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   391
\begin{axis}[
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   392
    xlabel={$n$},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   393
    x label style={at={(1.05,0.0)}},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   394
    ylabel={time in secs},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   395
    y label style={at={(0.06,0.5)}},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   396
    %enlargelimits=false,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   397
    %xtick={0,5000,...,30000},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   398
    xmax=65000,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   399
    ymax=45,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   400
    ytick={0,5,...,40},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   401
    scaled ticks=false,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   402
    axis lines=left,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   403
    width=6cm,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   404
    height=5.5cm, 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   405
    legend entries={Java 9},  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   406
    legend pos=north west]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   407
\addplot[cyan,mark=*, mark options={fill=white}] table {re-java9.data};
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   408
\end{axis}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   409
\end{tikzpicture}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   410
\end{tabular}  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   411
\end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   412
\newpage
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   413
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   414
\subsection*{Part 2 (4 Marks)}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   415
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   416
Coming from Java or C++, you might think Scala is a quite esoteric
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   417
programming language.  But remember, some serious companies have built
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   418
their business on
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   419
Scala.\footnote{\url{https://en.wikipedia.org/wiki/Scala_(programming_language)\#Companies}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   420
And there are far, far more esoteric languages out there. One is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   421
called \emph{brainf***}. You are asked in this part to implement an
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   422
interpreter for this language.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   423
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   424
Urban M\"uller developed brainf*** in 1993.  A close relative of this
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   425
language was already introduced in 1964 by Corado B\"ohm, an Italian
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   426
computer pioneer, who unfortunately died a few months ago. The main
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   427
feature of brainf*** is its minimalistic set of instructions---just 8
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   428
instructions in total and all of which are single characters. Despite
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   429
the minimalism, this language has been shown to be Turing
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   430
complete\ldots{}if this doesn't ring any bell with you: it roughly
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   431
means that every algorithm we know can, in principle, be implemented in
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   432
brainf***. It just takes a lot of determination and quite a lot of
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   433
memory resources. Some relatively sophisticated sample programs in
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   434
brainf*** are given in the file \texttt{bf.scala}.\bigskip
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   435
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   436
\noindent
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   437
As mentioned above, brainf*** has 8 single-character commands, namely
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   438
\texttt{'>'}, \texttt{'<'}, \texttt{'+'}, \texttt{'-'}, \texttt{'.'},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   439
\texttt{','}, \texttt{'['} and \texttt{']'}. Every other character is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   440
considered a comment.  Brainf*** operates on memory cells containing
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   441
integers. For this it uses a single memory pointer that points at each
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   442
stage to one memory cell. This pointer can be moved forward by one
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   443
memory cell by using the command \texttt{'>'}, and backward by using
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   444
\texttt{'<'}. The commands \texttt{'+'} and \texttt{'-'} increase,
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   445
respectively decrease, by 1 the content of the memory cell to which
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   446
the memory pointer currently points to. The commands for input/output
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   447
are \texttt{','} and \texttt{'.'}. Output works by reading the content
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   448
of the memory cell to which the memory pointer points to and printing
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   449
it out as an ASCII character. Input works the other way, taking some
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   450
user input and storing it in the cell to which the memory pointer
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   451
points to. The commands \texttt{'['} and \texttt{']'} are looping
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   452
constructs. Everything in between \texttt{'['} and \texttt{']'} is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   453
repeated until a counter (memory cell) reaches zero.  A typical
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   454
program in brainf*** looks as follows:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   455
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   456
\begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   457
\begin{verbatim}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   458
 ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   459
 ..+++.>>.<-.<.+++.------.--------.>>+.>++.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   460
\end{verbatim}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   461
\end{center}  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   462
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   463
\noindent
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   464
This one prints out Hello World\ldots{}obviously. 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   465
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   466
\subsubsection*{Tasks (file bf.scala)}
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   467
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   468
\begin{itemize}
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   469
\item[(2a)] Brainf*** memory is represented by a \texttt{Map} from
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   470
  integers to integers. The empty memory is represented by
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   471
  \texttt{Map()}, that is nothing is stored in the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   472
  memory. \texttt{Map(0 -> 1, 2 -> 3)} clearly stores \texttt{1} at
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   473
  memory location \texttt{0}; at \texttt{2} it stores \texttt{3}. The
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   474
  convention is that if we query the memory at a location that is
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   475
  \emph{not} defined in the \texttt{Map}, we return \texttt{0}. Write
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   476
  a function, \texttt{sread}, that takes a memory (a \texttt{Map}) and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   477
  a memory pointer (an \texttt{Int}) as argument, and safely reads the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   478
  corresponding memory location. If the \texttt{Map} is not defined at
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   479
  the memory pointer, \texttt{sread} returns \texttt{0}.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   480
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   481
  Write another function \texttt{write}, which takes a memory, a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   482
  memory pointer and an integer value as argument and updates the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   483
  \texttt{Map} with the value at the given memory location. As usual
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   484
  the \texttt{Map} is not updated `in-place' but a new map is created
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   485
  with the same data, except the value is stored at the given memory
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   486
  pointer.\hfill[1 Mark]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   487
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   488
\item[(2b)] Write two functions, \texttt{jumpRight} and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   489
  \texttt{jumpLeft} that are needed to implement the loop constructs
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   490
  of brainf***. They take a program (a \texttt{String}) and a program
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   491
  counter (an \texttt{Int}) as argument and move right (respectively
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   492
  left) in the string in order to find the \textbf{matching}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   493
  opening/closing bracket. For example, given the following program
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   494
  with the program counter indicated by an arrow:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   495
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   496
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   497
  \texttt{--[\barbelow{.}.+>--],>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   498
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   499
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   500
  then the matching closing bracket is in 9th position (counting from 0) and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   501
  \texttt{jumpRight} is supposed to return the position just after this
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   502
  
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   503
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   504
  \texttt{--[..+>--]\barbelow{,}>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   505
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   506
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   507
  meaning it jumps to after the loop. Similarly, if you are in 8th position
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   508
  then \texttt{jumpLeft} is supposed to jump to just after the opening
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   509
  bracket (that is jumping to the beginning of the loop):
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   510
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   511
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   512
    \texttt{--[..+>-\barbelow{-}],>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   513
    \qquad$\stackrel{\texttt{jumpLeft}}{\longrightarrow}$\qquad
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   514
    \texttt{--[\barbelow{.}.+>--],>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   515
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   516
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   517
  Unfortunately we have to take into account that there might be
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   518
  other opening and closing brackets on the `way' to find the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   519
  matching bracket. For example in the brainf*** program
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   520
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   521
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   522
  \texttt{--[\barbelow{.}.[+>]--],>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   523
  \end{center}
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   524
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   525
  we do not want to return the index for the \texttt{'-'} in the 9th
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   526
  position, but the program counter for \texttt{','} in 12th
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   527
  position. The easiest to find out whether a bracket is matched is by
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   528
  using levels (which are the third argument in \texttt{jumpLeft} and
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   529
  \texttt{jumpLeft}). In case of \texttt{jumpRight} you increase the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   530
  level by one whenever you find an opening bracket and decrease by
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   531
  one for a closing bracket. Then in \texttt{jumpRight} you are looking
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   532
  for the closing bracket on level \texttt{0}. For \texttt{jumpLeft} you
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   533
  do the opposite. In this way you can find \textbf{matching} brackets
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   534
  in strings such as
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   535
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   536
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   537
  \texttt{--[\barbelow{.}.[[-]+>[.]]--],>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   538
  \end{center}
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   539
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   540
  for which \texttt{jumpRight} should produce the position:
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   541
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   542
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   543
  \texttt{--[..[[-]+>[.]]--]\barbelow{,}>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   544
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   545
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   546
  It is also possible that the position returned by \texttt{jumpRight} or
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   547
  \texttt{jumpLeft} is outside the string in cases where there are
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   548
  no matching brackets. For example
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   549
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   550
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   551
  \texttt{--[\barbelow{.}.[[-]+>[.]]--,>,++}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   552
  \qquad$\stackrel{\texttt{jumpRight}}{\longrightarrow}$\qquad
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   553
  \texttt{--[..[[-]+>[.]]-->,++\barbelow{\;\phantom{+}}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   554
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   555
  \hfill[1 Mark]
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   556
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   557
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   558
\item[(2c)] Write a recursive function \texttt{run} that executes a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   559
  brainf*** program. It takes a program, a program counter, a memory
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   560
  pointer and a memory as arguments. If the program counter is outside
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   561
  the program string, the execution stops and \texttt{run} returns the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   562
  memory. If the program counter is inside the string, it reads the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   563
  corresponding character and updates the program counter \texttt{pc},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   564
  memory pointer \texttt{mp} and memory \texttt{mem} according to the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   565
  rules shown in Figure~\ref{comms}. It then calls recursively
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   566
  \texttt{run} with the updated data.
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   567
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   568
  Write another function \texttt{start} that calls \texttt{run} with a
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   569
  given brainfu** program and memory, and the program counter and memory pointer
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   570
  set to~$0$. Like \texttt{run} it returns the memory after the execution
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   571
  of the program finishes. You can test your brainf**k interpreter with the
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   572
  Sierpinski triangle or the Hello world programs or have a look at
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   573
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   574
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   575
  \url{https://esolangs.org/wiki/Brainfuck}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   576
  \end{center}\hfill[2 Marks]
109
293ea84d82ca updated
Christian Urban <urbanc@in.tum.de>
parents: 105
diff changeset
   577
  
218
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   578
  \begin{figure}[p]
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   579
  \begin{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   580
    \begin{tabular}{|@{}p{0.8cm}|l|}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   581
      \hline
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   582
      \hfill\texttt{'>'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   583
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   584
                       $\bullet$ & $\texttt{mp} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   585
                       $\bullet$ & \texttt{mem} unchanged
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   586
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   587
      \hfill\texttt{'<'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   588
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   589
                       $\bullet$ & $\texttt{mp} - 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   590
                       $\bullet$ & \texttt{mem} unchanged
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   591
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   592
      \hfill\texttt{'+'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   593
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   594
                       $\bullet$ & $\texttt{mp}$ unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   595
                       $\bullet$ & \texttt{mem} updated with \texttt{mp -> mem(mp) + 1}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   596
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   597
      \hfill\texttt{'-'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   598
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   599
                       $\bullet$ & $\texttt{mp}$ unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   600
                       $\bullet$ & \texttt{mem} updated with \texttt{mp -> mem(mp) - 1}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   601
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   602
      \hfill\texttt{'.'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   603
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   604
                       $\bullet$ & $\texttt{mp}$ and \texttt{mem} unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   605
                       $\bullet$ & print out \,\texttt{mem(mp)} as a character\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   606
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   607
      \hfill\texttt{','} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   608
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   609
                       $\bullet$ & $\texttt{mp}$ unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   610
                       $\bullet$ & \texttt{mem} updated with \texttt{mp -> \textrm{input}}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   611
                       \multicolumn{2}{@{}l}{the input is given by \texttt{Console.in.read().toByte}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   612
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   613
      \hfill\texttt{'['} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   614
                       \multicolumn{2}{@{}l}{if \texttt{mem(mp) == 0} then}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   615
                       $\bullet$ & $\texttt{pc = jumpRight(prog, pc + 1, 0)}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   616
                       $\bullet$ & $\texttt{mp}$ and \texttt{mem} unchanged\medskip\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   617
                       \multicolumn{2}{@{}l}{otherwise if \texttt{mem(mp) != 0} then}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   618
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   619
                       $\bullet$ & $\texttt{mp}$ and \texttt{mem} unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   620
                     \end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   621
                     \\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   622
      \hfill\texttt{']'} & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   623
                       \multicolumn{2}{@{}l}{if \texttt{mem(mp) != 0} then}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   624
                       $\bullet$ & $\texttt{pc = jumpLeft(prog, pc - 1, 0)}$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   625
                       $\bullet$ & $\texttt{mp}$ and \texttt{mem} unchanged\medskip\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   626
                       \multicolumn{2}{@{}l}{otherwise if \texttt{mem(mp) == 0} then}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   627
                       $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   628
                       $\bullet$ & $\texttt{mp}$ and \texttt{mem} unchanged\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   629
                     \end{tabular}\\\hline   
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   630
      any other char & \begin{tabular}[t]{@{}l@{\hspace{2mm}}l@{}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   631
                         $\bullet$ & $\texttt{pc} + 1$\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   632
                         $\bullet$ & \texttt{mp} and \texttt{mem} unchanged
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   633
                       \end{tabular}\\
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   634
      \hline                 
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   635
    \end{tabular}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   636
  \end{center}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   637
  \caption{The rules for how commands in the brainf*** language update the program counter \texttt{pc},
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   638
    memory pointer \texttt{mp} and memory \texttt{mem}.\label{comms}}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   639
  \end{figure}
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   640
\end{itemize}\bigskip  
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   641
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   642
22705d22c105 updated
Christian Urban <urbanc@in.tum.de>
parents: 111
diff changeset
   643
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   644
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   645
\end{document}
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   646
68
8da9e0c16194 updated
Christian Urban <urbanc@in.tum.de>
parents: 62
diff changeset
   647
6
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   648
%%% Local Variables: 
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   649
%%% mode: latex
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   650
%%% TeX-master: t
aae256985251 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   651
%%% End: