author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Wed, 06 Apr 2016 11:51:33 +0100 | |
changeset 399 | 5c1fbb39c93e |
parent 394 | 2f9fe225ecc8 |
child 412 | 1cef3924f7a2 |
permissions | -rw-r--r-- |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
\documentclass{article} |
251
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
2 |
\usepackage{../style} |
217
cd6066f1056a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
140
diff
changeset
|
3 |
\usepackage{../langs} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
4 |
\usepackage{../graphics} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
5 |
\usepackage{../data} |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
|
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
7 |
|
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
\begin{document} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
9 |
\fnote{\copyright{} Christian Urban, King's College London, 2014, 2015, 2016} |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
10 |
|
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
|
272
1446bc47a294
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
268
diff
changeset
|
12 |
\section*{Handout 2 (Regular Expression Matching)} |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
14 |
This lecture is about implementing a more efficient regular |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
15 |
expression matcher (the plots on the right)---more efficient |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
16 |
than the matchers from regular expression libraries in Ruby |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
17 |
and Python (the plots on the left). These plots show the |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
18 |
running time for the evil regular expression |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
19 |
$a^?{}^{\{n\}}\cdot a^{\{n\}}$ and strings composed of $n$ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
20 |
\pcode{a}s. We will use this regular expression and strings as |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
21 |
running example. To see the substantial differences in the two |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
22 |
plots below, note the different scales of the $x$-axes. |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
23 |
|
263
92e6985018ae
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
262
diff
changeset
|
24 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
25 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
26 |
\begin{tabular}{@{}cc@{}} |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
27 |
\begin{tikzpicture} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
28 |
\begin{axis}[ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
29 |
xlabel={strings of {\tt a}s}, |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
30 |
ylabel={time in secs}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
31 |
enlargelimits=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
32 |
xtick={0,5,...,30}, |
291
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
33 |
xmax=33, |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
34 |
ymax=35, |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
35 |
ytick={0,5,...,30}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
36 |
scaled ticks=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
37 |
axis lines=left, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
38 |
width=5cm, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
39 |
height=5cm, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
40 |
legend entries={Python,Ruby}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
41 |
legend pos=north west, |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
42 |
legend cell align=left] |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
43 |
\addplot[blue,mark=*, mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
44 |
table {re-python.data}; |
291
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
45 |
\addplot[brown,mark=triangle*, mark options={fill=white}] |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
46 |
table {re-ruby.data}; |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
47 |
\end{axis} |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
48 |
\end{tikzpicture} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
49 |
& |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
50 |
\begin{tikzpicture} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
51 |
\begin{axis}[ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
52 |
xlabel={strings of \texttt{a}s}, |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
53 |
ylabel={time in secs}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
54 |
enlargelimits=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
55 |
xtick={0,3000,...,12000}, |
291
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
56 |
xmax=12500, |
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
57 |
ymax=35, |
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
58 |
ytick={0,5,...,30}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
59 |
scaled ticks=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
60 |
axis lines=left, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
61 |
width=6.5cm, |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
62 |
height=5cm] |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
63 |
\addplot[green,mark=square*,mark options={fill=white}] table {re2b.data}; |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
64 |
\addplot[black,mark=square*,mark options={fill=white}] table {re3.data}; |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
65 |
\end{axis} |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
66 |
\end{tikzpicture} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
67 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
68 |
\end{center}\medskip |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
69 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
70 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
71 |
\noindent Having specified in the previous lecture what |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
72 |
problem our regular expression matcher is supposed to solve, |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
73 |
namely for any given regular expression $r$ and string $s$ |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
74 |
answer \textit{true} if and only if |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
|
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
\[ |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
s \in L(r) |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
\] |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
|
251
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
80 |
\noindent we can look at an algorithm to solve this problem. |
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
81 |
Clearly we cannot use the function $L$ directly for this, |
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
82 |
because in general the set of strings $L$ returns is infinite |
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
83 |
(recall what $L(a^*)$ is). In such cases there is no way we |
5b5a68df6d16
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
217
diff
changeset
|
84 |
can implement an exhaustive test for whether a string is |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
85 |
member of this set or not. In contrast our matching algorithm |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
86 |
will operate on the regular expression $r$ and string $s$, |
334
fd89a63e9db3
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
333
diff
changeset
|
87 |
only, which are both finite objects. Before we come to the matching |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
88 |
algorithm, however, let us have a closer look at what it means |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
89 |
when two regular expressions are equivalent. |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
90 |
|
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
91 |
\subsection*{Regular Expression Equivalences} |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
93 |
We already defined in Handout 1 what it means for two regular |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
94 |
expressions to be equivalent, namely if their meaning is the |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
95 |
same language: |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
96 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
97 |
\[ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
98 |
r_1 \equiv r_2 \;\dn\; L(r_1) = L(r_2) |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
99 |
\] |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
100 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
101 |
\noindent |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
102 |
It is relatively easy to verify that some concrete equivalences |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
103 |
hold, for example |
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
104 |
|
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
105 |
\begin{center} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
106 |
\begin{tabular}{rcl} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
107 |
$(a + b) + c$ & $\equiv$ & $a + (b + c)$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
108 |
$a + a$ & $\equiv$ & $a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
109 |
$a + b$ & $\equiv$ & $b + a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
110 |
$(a \cdot b) \cdot c$ & $\equiv$ & $a \cdot (b \cdot c)$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
111 |
$c \cdot (a + b)$ & $\equiv$ & $(c \cdot a) + (c \cdot b)$\\ |
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
112 |
\end{tabular} |
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
113 |
\end{center} |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
|
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
115 |
\noindent |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
116 |
but also easy to verify that the following regular expressions |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
117 |
are \emph{not} equivalent |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
118 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
119 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
120 |
\begin{tabular}{rcl} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
121 |
$a \cdot a$ & $\not\equiv$ & $a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
122 |
$a + (b \cdot c)$ & $\not\equiv$ & $(a + b) \cdot (a + c)$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
123 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
124 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
125 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
126 |
\noindent I leave it to you to verify these equivalences and |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
127 |
non-equivalences. It is also interesting to look at some |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
128 |
corner cases involving $\ONE$ and $\ZERO$: |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
129 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
130 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
131 |
\begin{tabular}{rcl} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
132 |
$a \cdot \ZERO$ & $\not\equiv$ & $a$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
133 |
$a + \ONE$ & $\not\equiv$ & $a$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
134 |
$\ONE$ & $\equiv$ & $\ZERO^*$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
135 |
$\ONE^*$ & $\equiv$ & $\ONE$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
136 |
$\ZERO^*$ & $\not\equiv$ & $\ZERO$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
137 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
138 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
139 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
140 |
\noindent Again I leave it to you to make sure you agree |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
141 |
with these equivalences and non-equivalences. |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
142 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
143 |
|
318
7975e4f0d4de
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
296
diff
changeset
|
144 |
For our matching algorithm however the following seven |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
145 |
equivalences will play an important role: |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
146 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
147 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
148 |
\begin{tabular}{rcl} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
149 |
$r + \ZERO$ & $\equiv$ & $r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
150 |
$\ZERO + r$ & $\equiv$ & $r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
151 |
$r \cdot \ONE$ & $\equiv$ & $r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
152 |
$\ONE \cdot r$ & $\equiv$ & $r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
153 |
$r \cdot \ZERO$ & $\equiv$ & $\ZERO$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
154 |
$\ZERO \cdot r$ & $\equiv$ & $\ZERO$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
155 |
$r + r$ & $\equiv$ & $r$ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
156 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
157 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
158 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
159 |
\noindent which always hold no matter what the regular |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
160 |
expression $r$ looks like. The first two are easy to verify |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
161 |
since $L(\ZERO)$ is the empty set. The next two are also |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
162 |
easy to verify since $L(\ONE) = \{[]\}$ and appending the |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
163 |
empty string to every string of another set, leaves the set |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
164 |
unchanged. Be careful to fully comprehend the fifth and sixth |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
165 |
equivalence: if you concatenate two sets of strings and one is |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
166 |
the empty set, then the concatenation will also be the empty |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
167 |
set. To see this, check the definition of $\_ @ \_$. The |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
168 |
last equivalence is again trivial. |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
169 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
170 |
What will be important later on is that we can orient these |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
171 |
equivalences and read them from left to right. In this way we |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
172 |
can view them as \emph{simplification rules}. Consider for |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
173 |
example the regular expression |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
174 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
175 |
\begin{equation} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
176 |
(r_1 + \ZERO) \cdot \ONE + ((\ONE + r_2) + r_3) \cdot (r_4 \cdot \ZERO) |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
177 |
\label{big} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
178 |
\end{equation} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
179 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
180 |
\noindent If we can find an equivalent regular expression that |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
181 |
is simpler (smaller for example), then this might potentially |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
182 |
make our matching algorithm run faster. The reason is that |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
183 |
whether a string $s$ is in $L(r)$ or in $L(r')$ with $r\equiv |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
184 |
r'$ will always give the same answer. In the example above you |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
185 |
will see that the regular expression is equivalent to just $r_1$. |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
186 |
You can verify this by iteratively applying the simplification |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
187 |
rules from above: |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
188 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
189 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
190 |
\begin{tabular}{ll} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
191 |
& $(r_1 + \ZERO) \cdot \ONE + ((\ONE + r_2) + r_3) \cdot |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
192 |
(\underline{r_4 \cdot \ZERO})$\smallskip\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
193 |
$\equiv$ & $(r_1 + \ZERO) \cdot \ONE + \underline{((\ONE + r_2) + r_3) \cdot |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
194 |
\ZERO}$\smallskip\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
195 |
$\equiv$ & $\underline{(r_1 + \ZERO) \cdot \ONE} + \ZERO$\smallskip\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
196 |
$\equiv$ & $(\underline{r_1 + \ZERO}) + \ZERO$\smallskip\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
197 |
$\equiv$ & $\underline{r_1 + \ZERO}$\smallskip\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
198 |
$\equiv$ & $r_1$\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
199 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
200 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
201 |
|
296
796b9b81ac8d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
291
diff
changeset
|
202 |
\noindent In each step, I underlined where a simplification |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
203 |
rule is applied. Our matching algorithm in the next section |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
204 |
will often generate such ``useless'' $\ONE$s and |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
205 |
$\ZERO$s, therefore simplifying them away will make the |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
206 |
algorithm quite a bit faster. |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
207 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
208 |
\subsection*{The Matching Algorithm} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
209 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
210 |
The algorithm we will define below consists of two parts. One |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
211 |
is the function $nullable$ which takes a regular expression as |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
212 |
argument and decides whether it can match the empty string |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
213 |
(this means it returns a boolean in Scala). This can be easily |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
214 |
defined recursively as follows: |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
215 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
216 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
217 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
218 |
$nullable(\ZERO)$ & $\dn$ & $\textit{false}$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
219 |
$nullable(\ONE)$ & $\dn$ & $true$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
220 |
$nullable(c)$ & $\dn$ & $\textit{false}$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
221 |
$nullable(r_1 + r_2)$ & $\dn$ & $nullable(r_1) \vee nullable(r_2)$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
222 |
$nullable(r_1 \cdot r_2)$ & $\dn$ & $nullable(r_1) \wedge nullable(r_2)$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
223 |
$nullable(r^*)$ & $\dn$ & $true$ \\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
224 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
225 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
226 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
227 |
\noindent The idea behind this function is that the following |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
228 |
property holds: |
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
229 |
|
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
230 |
\[ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
231 |
nullable(r) \;\;\text{if and only if}\;\; []\in L(r) |
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
232 |
\] |
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
233 |
|
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
234 |
\noindent Note on the left-hand side of the if-and-only-if we |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
235 |
have a function we can implement; on the right we have its |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
236 |
specification (which we cannot implement in a programming |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
237 |
language). |
124
dd8b5a3dac0a
adde
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
123
diff
changeset
|
238 |
|
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
239 |
The other function of our matching algorithm calculates a |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
240 |
\emph{derivative} of a regular expression. This is a function |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
241 |
which will take a regular expression, say $r$, and a |
332
4755ad4b457b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
325
diff
changeset
|
242 |
character, say $c$, as argument and returns a new regular |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
243 |
expression. Be careful that the intuition behind this function |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
244 |
is not so easy to grasp on first reading. Essentially this |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
245 |
function solves the following problem: if $r$ can match a |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
246 |
string of the form $c\!::\!s$, what does the regular |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
247 |
expression look like that can match just $s$? The definition |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
248 |
of this function is as follows: |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
249 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
250 |
\begin{center} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
251 |
\begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
252 |
$der\, c\, (\ZERO)$ & $\dn$ & $\ZERO$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
253 |
$der\, c\, (\ONE)$ & $\dn$ & $\ZERO$ \\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
254 |
$der\, c\, (d)$ & $\dn$ & if $c = d$ then $\ONE$ else $\ZERO$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
255 |
$der\, c\, (r_1 + r_2)$ & $\dn$ & $der\, c\, r_1 + der\, c\, r_2$\\ |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
256 |
$der\, c\, (r_1 \cdot r_2)$ & $\dn$ & if $nullable (r_1)$\\ |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
257 |
& & then $(der\,c\,r_1) \cdot r_2 + der\, c\, r_2$\\ |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
258 |
& & else $(der\, c\, r_1) \cdot r_2$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
259 |
$der\, c\, (r^*)$ & $\dn$ & $(der\,c\,r) \cdot (r^*)$ |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
260 |
\end{tabular} |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
261 |
\end{center} |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
262 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
263 |
\noindent The first two clauses can be rationalised as |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
264 |
follows: recall that $der$ should calculate a regular |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
265 |
expression so that given the ``input'' regular expression can |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
266 |
match a string of the form $c\!::\!s$, we want a regular |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
267 |
expression for $s$. Since neither $\ZERO$ nor $\ONE$ |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
268 |
can match a string of the form $c\!::\!s$, we return |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
269 |
$\ZERO$. In the third case we have to make a |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
270 |
case-distinction: In case the regular expression is $c$, then |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
271 |
clearly it can recognise a string of the form $c\!::\!s$, just |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
272 |
that $s$ is the empty string. Therefore we return the |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
273 |
$\ONE$-regular expression. In the other case we again |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
274 |
return $\ZERO$ since no string of the $c\!::\!s$ can be |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
275 |
matched. Next come the recursive cases, which are a bit more |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
276 |
involved. Fortunately, the $+$-case is still relatively |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
277 |
straightforward: all strings of the form $c\!::\!s$ are either |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
278 |
matched by the regular expression $r_1$ or $r_2$. So we just |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
279 |
have to recursively call $der$ with these two regular |
332
4755ad4b457b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
325
diff
changeset
|
280 |
expressions and compose the results again with $+$. Makes |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
281 |
sense? The $\cdot$-case is more complicated: if $r_1\cdot r_2$ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
282 |
matches a string of the form $c\!::\!s$, then the first part |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
283 |
must be matched by $r_1$. Consequently, it makes sense to |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
284 |
construct the regular expression for $s$ by calling $der$ with |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
285 |
$r_1$ and ``appending'' $r_2$. There is however one exception |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
286 |
to this simple rule: if $r_1$ can match the empty string, then |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
287 |
all of $c\!::\!s$ is matched by $r_2$. So in case $r_1$ is |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
288 |
nullable (that is can match the empty string) we have to allow |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
289 |
the choice $der\,c\,r_2$ for calculating the regular |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
290 |
expression that can match $s$. Therefore we have to add the |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
291 |
regular expression $der\,c\,r_2$ in the result. The $*$-case |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
292 |
is again simple: if $r^*$ matches a string of the form |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
293 |
$c\!::\!s$, then the first part must be ``matched'' by a |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
294 |
single copy of $r$. Therefore we call recursively $der\,c\,r$ |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
295 |
and ``append'' $r^*$ in order to match the rest of $s$. |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
296 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
297 |
If this did not make sense, here is another way to rationalise |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
298 |
the definition of $der$ by considering the following operation |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
299 |
on sets: |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
300 |
|
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
301 |
\begin{equation}\label{Der} |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
302 |
Der\,c\,A\;\dn\;\{s\,|\,c\!::\!s \in A\} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
303 |
\end{equation} |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
304 |
|
291
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
305 |
\noindent This operation essentially transforms a set of |
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
306 |
strings $A$ by filtering out all strings that do not start |
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
307 |
with $c$ and then strips off the $c$ from all the remaining |
201c2c6d8696
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
272
diff
changeset
|
308 |
strings. For example suppose $A = \{f\!oo, bar, f\!rak\}$ then |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
309 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
310 |
\[ Der\,f\,A = \{oo, rak\}\quad,\quad |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
311 |
Der\,b\,A = \{ar\} \quad \text{and} \quad |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
312 |
Der\,a\,A = \{\} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
313 |
\] |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
314 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
315 |
\noindent |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
316 |
Note that in the last case $Der$ is empty, because no string in $A$ |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
317 |
starts with $a$. With this operation we can state the following |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
318 |
property about $der$: |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
319 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
320 |
\[ |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
321 |
L(der\,c\,r) = Der\,c\,(L(r)) |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
322 |
\] |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
323 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
324 |
\noindent |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
325 |
This property clarifies what regular expression $der$ calculates, |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
326 |
namely take the set of strings that $r$ can match (that is $L(r)$), |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
327 |
filter out all strings not starting with $c$ and strip off the $c$ |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
328 |
from the remaining strings---this is exactly the language that |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
329 |
$der\,c\,r$ can match. |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
330 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
331 |
If we want to find out whether the string $abc$ is matched by |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
332 |
the regular expression $r_1$ then we can iteratively apply $der$ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
333 |
as follows |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
334 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
335 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
336 |
\begin{tabular}{rll} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
337 |
Input: $r_1$, $abc$\medskip\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
338 |
Step 1: & build derivative of $a$ and $r_1$ & $(r_2 = der\,a\,r_1)$\smallskip\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
339 |
Step 2: & build derivative of $b$ and $r_2$ & $(r_3 = der\,b\,r_2)$\smallskip\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
340 |
Step 3: & build derivative of $c$ and $r_3$ & $(r_4 = der\,b\,r_3)$\smallskip\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
341 |
Step 4: & the string is exhausted; test & ($nullable(r_4)$)\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
342 |
& whether $r_4$ can recognise the\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
343 |
& empty string\smallskip\\ |
332
4755ad4b457b
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
325
diff
changeset
|
344 |
Output: & result of this test $\Rightarrow true \,\text{or}\, \textit{false}$\\ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
345 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
346 |
\end{center} |
140
1be892087df2
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
347 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
348 |
\noindent Again the operation $Der$ might help to rationalise |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
349 |
this algorithm. We want to know whether $abc \in L(r_1)$. We |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
350 |
do not know yet---but let us assume it is. Then $Der\,a\,L(r_1)$ |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
351 |
builds the set where all the strings not starting with $a$ are |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
352 |
filtered out. Of the remaining strings, the $a$ is stripped |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
353 |
off. Then we continue with filtering out all strings not |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
354 |
starting with $b$ and stripping off the $b$ from the remaining |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
355 |
strings, that means we build $Der\,b\,(Der\,a\,(L(r_1)))$. |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
356 |
Finally we filter out all strings not starting with $c$ and |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
357 |
strip off $c$ from the remaining string. This is |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
358 |
$Der\,c\,(Der\,b\,(Der\,a\,(L(r))))$. Now if $abc$ was in the |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
359 |
original set ($L(r_1)$), then in $Der\,c\,(Der\,b\,(Der\,a\,(L(r))))$ |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
360 |
must be the empty string. If not, then $abc$ was not in the |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
361 |
language we started with. |
140
1be892087df2
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
133
diff
changeset
|
362 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
363 |
Our matching algorithm using $der$ and $nullable$ works |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
364 |
similarly, just using regular expression instead of sets. For |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
365 |
this we need to extend the notion of derivatives from single |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
366 |
characters to strings. This can be done using the following |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
367 |
function, taking a string and regular expression as input and |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
368 |
a regular expression as output. |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
369 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
370 |
\begin{center} |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
371 |
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {\hspace{-10mm}}l@ {}} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
372 |
$\textit{ders}\, []\, r$ & $\dn$ & $r$ & \\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
373 |
$\textit{ders}\, (c\!::\!s)\, r$ & $\dn$ & $\textit{ders}\,s\,(der\,c\,r)$ & \\ |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
374 |
\end{tabular} |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
375 |
\end{center} |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
376 |
|
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
377 |
\noindent This function iterates $der$ taking one character at |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
378 |
the time from the original string until it is exhausted. |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
379 |
Having $ders$ in place, we can finally define our matching |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
380 |
algorithm: |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
381 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
382 |
\[ |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
383 |
matches\,s\,r \dn nullable(ders\,s\,r) |
125
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
384 |
\] |
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
385 |
|
39c75cf4e079
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
124
diff
changeset
|
386 |
\noindent |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
387 |
and we can claim that |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
388 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
389 |
\[ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
390 |
matches\,s\,r\quad\text{if and only if}\quad s\in L(r) |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
391 |
\] |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
392 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
393 |
\noindent holds, which means our algorithm satisfies the |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
394 |
specification. Of course we can claim many things\ldots |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
395 |
whether the claim holds any water is a different question, |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
396 |
which for example is the point of the Strand-2 Coursework. |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
397 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
398 |
This algorithm was introduced by Janus Brzozowski in 1964. Its |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
399 |
main attractions are simplicity and being fast, as well as |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
400 |
being easily extendable for other regular expressions such as |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
401 |
$r^{\{n\}}$, $r^?$, $\sim{}r$ and so on (this is subject of |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
402 |
Strand-1 Coursework 1). |
258
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
403 |
|
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
404 |
\subsection*{The Matching Algorithm in Scala} |
1e4da6d2490c
updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
251
diff
changeset
|
405 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
406 |
Another attraction of the algorithm is that it can be easily |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
407 |
implemented in a functional programming language, like Scala. |
296
796b9b81ac8d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
291
diff
changeset
|
408 |
Given the implementation of regular expressions in Scala shown |
796b9b81ac8d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
291
diff
changeset
|
409 |
in the first lecture and handout, the functions and subfunctions |
796b9b81ac8d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
291
diff
changeset
|
410 |
for \pcode{matches} are shown in Figure~\ref{scala1}. |
126
7c7185cb4f2b
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
125
diff
changeset
|
411 |
|
7c7185cb4f2b
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
125
diff
changeset
|
412 |
\begin{figure}[p] |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
413 |
\lstinputlisting{../progs/app5.scala} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
414 |
\caption{Scala implementation of the nullable and |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
415 |
derivative functions. These functions are easy to |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
416 |
implement in functional languages, because pattern |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
417 |
matching and recursion allow us to mimic the mathematical |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
418 |
definitions very closely.\label{scala1}} |
126
7c7185cb4f2b
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
125
diff
changeset
|
419 |
\end{figure} |
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
420 |
|
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
421 |
For running the algorithm with our favourite example, the evil |
394
2f9fe225ecc8
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
343
diff
changeset
|
422 |
regular expression $a^?{}^{\{n\}}a^{\{n\}}$, we need to implement |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
423 |
the optional regular expression and the exactly $n$-times |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
424 |
regular expression. This can be done with the translations |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
425 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
426 |
\lstinputlisting[numbers=none]{../progs/app51.scala} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
427 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
428 |
\noindent Running the matcher with the example, we find it is |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
429 |
slightly worse then the matcher in Ruby and Python. |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
430 |
Ooops\ldots |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
431 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
432 |
\begin{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
433 |
\begin{tikzpicture} \begin{axis}[ xlabel={\pcode{a}s}, ylabel={time in secs}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
434 |
enlargelimits=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
435 |
xtick={0,5,...,30}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
436 |
xmax=30, ytick={0,5,...,30}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
437 |
scaled ticks=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
438 |
axis lines=left, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
439 |
width=6cm, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
440 |
height=5cm, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
441 |
legend entries={Python,Ruby,Scala V1}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
442 |
legend pos=outer north east, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
443 |
legend cell align=left ] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
444 |
\addplot[blue,mark=*, mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
445 |
table {re-python.data}; |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
446 |
\addplot[brown,mark=pentagon*, mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
447 |
table {re-ruby.data}; |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
448 |
\addplot[red,mark=triangle*,mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
449 |
table {re1.data}; \end{axis} \end{tikzpicture} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
450 |
\end{center} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
451 |
|
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
452 |
\noindent Analysing this failure we notice that for |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
453 |
$a^{\{n\}}$ we generate quite big regular expressions: |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
454 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
455 |
\begin{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
456 |
\begin{tabular}{rl} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
457 |
1: & $a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
458 |
2: & $a\cdot a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
459 |
3: & $a\cdot a\cdot a$\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
460 |
& \ldots\\ |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
461 |
13: & $a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a\cdot a$\\ |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
462 |
& \ldots |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
463 |
\end{tabular} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
464 |
\end{center} |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
465 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
466 |
\noindent Our algorithm traverses such regular expressions at |
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
467 |
least once every time a derivative is calculated. So having |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
468 |
large regular expressions will cause problems. This problem |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
469 |
is aggravated by $a^?$ being represented as $a + \ONE$. |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
470 |
|
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
471 |
We can however fix this by having an explicit constructor for |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
472 |
$r^{\{n\}}$. In Scala we would introduce a constructor like |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
473 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
474 |
\begin{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
475 |
\code{case class NTIMES(r: Rexp, n: Int) extends Rexp} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
476 |
\end{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
477 |
|
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
478 |
\noindent With this fix we have a constant ``size'' regular |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
479 |
expression for our running example no matter how large $n$ is. |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
480 |
This means we have to also add cases for \pcode{NTIMES} in the |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
481 |
functions $nullable$ and $der$. Does the change have any |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
482 |
effect? |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
483 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
484 |
\begin{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
485 |
\begin{tikzpicture} \begin{axis}[ xlabel={\pcode{a}s}, ylabel={time in secs}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
486 |
enlargelimits=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
487 |
xtick={0,100,...,1000}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
488 |
xmax=1000, ytick={0,5,...,30}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
489 |
scaled ticks=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
490 |
axis lines=left, |
263
92e6985018ae
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
262
diff
changeset
|
491 |
width=9.5cm, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
492 |
height=5cm, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
493 |
legend entries={Python,Ruby,Scala V1,Scala V2}, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
494 |
legend pos=outer north east, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
495 |
legend cell align=left ] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
496 |
\addplot[blue,mark=*, mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
497 |
table {re-python.data}; |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
498 |
\addplot[brown,mark=pentagon*, mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
499 |
table {re-ruby.data}; |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
500 |
\addplot[red,mark=triangle*,mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
501 |
table {re1.data}; \addplot[green,mark=square*,mark options={fill=white}] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
502 |
table {re2b.data}; \end{axis} \end{tikzpicture} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
503 |
\end{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
504 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
505 |
\noindent Now we are talking business! The modified matcher |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
506 |
can within 30 seconds handle regular expressions up to |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
507 |
$n = 950$ before a StackOverflow is raised. Python and Ruby |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
508 |
(and our first version) could only handle $n = 27$ or so in 30 |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
509 |
second. |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
510 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
511 |
The moral is that our algorithm is rather sensitive to the |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
512 |
size of regular expressions it needs to handle. This is of |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
513 |
course obvious because both $nullable$ and $der$ frequently |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
514 |
need to traverse the whole regular expression. There seems, |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
515 |
however, one more issue for making the algorithm run faster. |
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
516 |
The derivative function often produces ``useless'' |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
517 |
$\ZERO$s and $\ONE$s. To see this, consider $r = ((a |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
518 |
\cdot b) + b)^*$ and the following two derivatives |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
519 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
520 |
\begin{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
521 |
\begin{tabular}{l} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
522 |
$der\,a\,r = ((\ONE \cdot b) + \ZERO) \cdot r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
523 |
$der\,b\,r = ((\ZERO \cdot b) + \ONE)\cdot r$\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
524 |
$der\,c\,r = ((\ZERO \cdot b) + \ZERO)\cdot r$ |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
525 |
\end{tabular} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
526 |
\end{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
527 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
528 |
\noindent |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
529 |
If we simplify them according to the simple rules from the |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
530 |
beginning, we can replace the right-hand sides by the |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
531 |
smaller equivalent regular expressions |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
532 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
533 |
\begin{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
534 |
\begin{tabular}{l} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
535 |
$der\,a\,r \equiv b \cdot r$\\ |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
536 |
$der\,b\,r \equiv r$\\ |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
537 |
$der\,c\,r \equiv \ZERO$ |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
538 |
\end{tabular} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
539 |
\end{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
540 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
541 |
\noindent I leave it to you to contemplate whether such a |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
542 |
simplification can have any impact on the correctness of our |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
543 |
algorithm (will it change any answers?). Figure~\ref{scala2} |
296
796b9b81ac8d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
291
diff
changeset
|
544 |
gives a simplification function that recursively traverses a |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
545 |
regular expression and simplifies it according to the rules |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
546 |
given at the beginning. There are only rules for $+$, $\cdot$ |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
547 |
and $n$-times (the latter because we added it in the second |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
548 |
version of our matcher). There is no rule for a star, because |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
549 |
empirical data and also a little thought showed that |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
550 |
simplifying under a star is a waste of computation time. The |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
551 |
simplification function will be called after every derivation. |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
552 |
This additional step removes all the ``junk'' the derivative |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
553 |
function introduced. Does this improve the speed? You bet!! |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
554 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
555 |
\begin{figure}[p] |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
556 |
\lstinputlisting{../progs/app6.scala} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
557 |
\caption{The simplification function and modified |
325
794c599cee53
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
318
diff
changeset
|
558 |
\texttt{ders}-function; this function now |
333
8890852e18b7
updated coursework
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
332
diff
changeset
|
559 |
calls \texttt{der} first, but then simplifies |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
560 |
the resulting derivative regular expressions before |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
561 |
building the next derivative, see |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
562 |
Line~\ref{simpline}.\label{scala2}} |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
563 |
\end{figure} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
564 |
|
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
565 |
\begin{center} |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
566 |
\begin{tikzpicture} |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
567 |
\begin{axis}[xlabel={\pcode{a}s},ylabel={time in secs}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
568 |
enlargelimits=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
569 |
xtick={0,2000,...,12000}, |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
570 |
xmax=12000, |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
571 |
ytick={0,5,...,30}, |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
572 |
scaled ticks=false, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
573 |
axis lines=left, |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
574 |
width=9cm, |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
575 |
height=5cm, |
268
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
576 |
legend entries={Scala V2,Scala V3}] |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
577 |
\addplot[green,mark=square*,mark options={fill=white}] table {re2b.data}; |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
578 |
\addplot[black,mark=square*,mark options={fill=white}] table {re3.data}; |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
579 |
\end{axis} |
18bef085a7ca
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
263
diff
changeset
|
580 |
\end{tikzpicture} |
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
581 |
\end{center} |
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
582 |
|
334
fd89a63e9db3
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
333
diff
changeset
|
583 |
\section*{Proofs} |
fd89a63e9db3
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
333
diff
changeset
|
584 |
|
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
585 |
You might not like doing proofs. But they serve a very |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
586 |
important purpose in Computer Science: How can we be sure that |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
587 |
our algorithm matches its specification. We can try to test |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
588 |
the algorithm, but that often overlooks corner cases and an |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
589 |
exhaustive testing is impossible (since there are infinitely |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
590 |
many inputs). Proofs allow us to ensure that an algorithm |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
591 |
really meets its specification. |
338
f16120cb4e19
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
334
diff
changeset
|
592 |
|
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
593 |
For the programs we look at in this module, the proofs will |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
594 |
mostly by some form of induction. Remember that regular |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
595 |
expressions are defined as |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
596 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
597 |
\begin{center} |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
598 |
\begin{tabular}{r@{\hspace{1mm}}r@{\hspace{1mm}}l@{\hspace{13mm}}l} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
599 |
$r$ & $::=$ & $\ZERO$ & null language\\ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
600 |
& $\mid$ & $\ONE$ & empty string / \texttt{""} / []\\ |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
601 |
& $\mid$ & $c$ & single character\\ |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
602 |
& $\mid$ & $r_1 + r_2$ & alternative / choice\\ |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
603 |
& $\mid$ & $r_1 \cdot r_2$ & sequence\\ |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
604 |
& $\mid$ & $r^*$ & star (zero or more)\\ |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
605 |
\end{tabular} |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
606 |
\end{center} |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
607 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
608 |
\noindent If you want to show a property $P(r)$ for all |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
609 |
regular expressions $r$, then you have to follow essentially |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
610 |
the recipe: |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
611 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
612 |
\begin{itemize} |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
613 |
\item $P$ has to hold for $\ZERO$, $\ONE$ and $c$ |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
614 |
(these are the base cases). |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
615 |
\item $P$ has to hold for $r_1 + r_2$ under the assumption |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
616 |
that $P$ already holds for $r_1$ and $r_2$. |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
617 |
\item $P$ has to hold for $r_1 \cdot r_2$ under the |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
618 |
assumption that $P$ already holds for $r_1$ and $r_2$. |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
619 |
\item $P$ has to hold for $r^*$ under the assumption |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
620 |
that $P$ already holds for $r$. |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
621 |
\end{itemize} |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
622 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
623 |
\noindent |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
624 |
A simple proof is for example showing the following |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
625 |
property: |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
626 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
627 |
\begin{equation} |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
628 |
nullable(r) \;\;\text{if and only if}\;\; []\in L(r) |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
629 |
\label{nullableprop} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
630 |
\end{equation} |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
631 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
632 |
\noindent |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
633 |
Let us say that this property is $P(r)$, then the first case |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
634 |
we need to check is whether $P(\ZERO)$ (see recipe |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
635 |
above). So we have to show that |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
636 |
|
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
637 |
\[ |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
638 |
nullable(\ZERO) \;\;\text{if and only if}\;\; |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
639 |
[]\in L(\ZERO) |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
640 |
\] |
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
641 |
|
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
642 |
\noindent whereby $nullable(\ZERO)$ is by definition of |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
643 |
the function $nullable$ always $\textit{false}$. We also have |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
644 |
that $L(\ZERO)$ is by definition $\{\}$. It is |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
645 |
impossible that the empty string $[]$ is in the empty set. |
339
bc395ccfba7f
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
338
diff
changeset
|
646 |
Therefore also the right-hand side is false. Consequently we |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
647 |
verified this case: both sides are false. We would still need |
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
648 |
to do this for $P(\ONE)$ and $P(c)$. I leave this to |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
649 |
you to verify. |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
650 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
651 |
Next we need to check the inductive cases, for example |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
652 |
$P(r_1 + r_2)$, which is |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
653 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
654 |
\begin{equation} |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
655 |
nullable(r_1 + r_2) \;\;\text{if and only if}\;\; |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
656 |
[]\in L(r_1 + r_2) |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
657 |
\label{propalt} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
658 |
\end{equation} |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
659 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
660 |
\noindent The difference to the base cases is that in this |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
661 |
case we can already assume we proved |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
662 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
663 |
\begin{center} |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
664 |
\begin{tabular}{l} |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
665 |
$nullable(r_1) \;\;\text{if and only if}\;\; []\in L(r_1)$ and\\ |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
666 |
$nullable(r_2) \;\;\text{if and only if}\;\; []\in L(r_2)$\\ |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
667 |
\end{tabular} |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
668 |
\end{center} |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
669 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
670 |
\noindent These are the induction hypotheses. To check this |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
671 |
case, we can start from $nullable(r_1 + r_2)$, which by |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
672 |
definition is |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
673 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
674 |
\[ |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
675 |
nullable(r_1) \vee nullable(r_2) |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
676 |
\] |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
677 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
678 |
\noindent Using the two induction hypotheses from above, |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
679 |
we can transform this into |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
680 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
681 |
\[ |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
682 |
[] \in L(r_1) \vee []\in(r_2) |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
683 |
\] |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
684 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
685 |
\noindent We just replaced the $nullable(\ldots)$ parts by |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
686 |
the equivalent $[] \in L(\ldots)$ from the induction |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
687 |
hypotheses. A bit of thinking convinces you that if |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
688 |
$[] \in L(r_1) \vee []\in L(r_2)$ then the empty string |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
689 |
must be in the union $L(r_1)\cup L(r_2)$, that is |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
690 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
691 |
\[ |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
692 |
[] \in L(r_1)\cup L(r_2) |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
693 |
\] |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
694 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
695 |
\noindent but this is by definition of $L$ exactly $[] \in |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
696 |
L(r_1 + r_2)$, which we needed to establish according to |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
697 |
\eqref{propalt}. What we have shown is that starting from |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
698 |
$nullable(r_1 + r_2)$ we have done equivalent transformations |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
699 |
to end up with $[] \in L(r_1 + r_2)$. Consequently we have |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
700 |
established that $P(r_1 + r_2)$ holds. |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
701 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
702 |
In order to complete the proof we would now need to look |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
703 |
at the cases \mbox{$P(r_1\cdot r_2)$} and $P(r^*)$. Again I let you |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
704 |
check the details. |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
705 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
706 |
You might have to do induction proofs over strings. |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
707 |
That means you want to establish a property $P(s)$ for all |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
708 |
strings $s$. For this remember strings are lists of |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
709 |
characters. These lists can be either the empty list or a |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
710 |
list of the form $c::s$. If you want to perform an induction |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
711 |
proof for strings you need to consider the cases |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
712 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
713 |
\begin{itemize} |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
714 |
\item $P$ has to hold for $[]$ (this is the base case). |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
715 |
\item $P$ has to hold for $c::s$ under the assumption |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
716 |
that $P$ already holds for $s$. |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
717 |
\end{itemize} |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
718 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
719 |
\noindent |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
720 |
Given this recipe, I let you show |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
721 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
722 |
\begin{equation} |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
723 |
Ders\,s\,(L(r)) = L(ders\,s\,r) |
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
724 |
\label{dersprop} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
725 |
\end{equation} |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
726 |
|
399
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
727 |
\noindent by induction on $s$. Recall $Der$ is defined for |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
728 |
character---see \eqref{Der}; $Ders$ is similar, but for strings: |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
729 |
|
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
730 |
\[ |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
731 |
Ders\,s\,A\;\dn\;\{s'\,|\,s @ s' \in A\} |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
732 |
\] |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
733 |
|
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
734 |
\noindent In this proof you can assume the following property |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
735 |
for $der$ and $Der$ has already been proved, that is you can |
5c1fbb39c93e
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
394
diff
changeset
|
736 |
assume |
340
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
737 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
738 |
\[ |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
739 |
L(der\,c\,r) = Der\,c\,(L(r)) |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
740 |
\] |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
741 |
|
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
742 |
\noindent holds (this would be of course a property that |
c49122dbcdd1
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
339
diff
changeset
|
743 |
needs to be proved in a side-lemma by induction on $r$). |
338
f16120cb4e19
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
334
diff
changeset
|
744 |
|
343
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
745 |
To sum up, using reasoning like the one shown above allows us |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
746 |
to show the correctness of our algorithm. To see this, |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
747 |
start from the specification |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
748 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
749 |
\[ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
750 |
s \in L(r) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
751 |
\] |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
752 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
753 |
\noindent That is the problem we want to solve. Thinking a |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
754 |
little, you will see that this problem is equivalent to the |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
755 |
following problem |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
756 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
757 |
\begin{equation} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
758 |
[] \in Ders\,s\,(L(r)) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
759 |
\label{dersstep} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
760 |
\end{equation} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
761 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
762 |
\noindent But we have shown above in \eqref{dersprop}, that |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
763 |
the $Ders$ can be replaced by $L(ders\ldots)$. That means |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
764 |
\eqref{dersstep} is equivalent to |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
765 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
766 |
\begin{equation} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
767 |
[] \in L(ders\,s\,r) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
768 |
\label{prefinalstep} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
769 |
\end{equation} |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
770 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
771 |
\noindent We have also shown that testing whether the empty |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
772 |
string is in a language is equivalent to the $nullable$ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
773 |
function; see \eqref{nullableprop}. That means |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
774 |
\eqref{prefinalstep} is equivalent with |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
775 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
776 |
\[ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
777 |
nullable(ders\,s\,r) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
778 |
\] |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
779 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
780 |
\noindent But this is just the definition of $matches$ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
781 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
782 |
\[ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
783 |
matches\,s\,r \dn nullable(ders\,s\,r) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
784 |
\] |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
785 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
786 |
\noindent In effect we have shown |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
787 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
788 |
\[ |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
789 |
matches\,s\,r\;\;\text{if and only if}\;\; |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
790 |
s\in L(r) |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
791 |
\] |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
792 |
|
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
793 |
\noindent which is the property we set out to prove: |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
794 |
our algorithm meets its specification. To have done |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
795 |
so, requires a few induction proofs about strings and |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
796 |
regular expressions. Following the recipes is already a big |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
797 |
step in performing these proofs. |
539b2e88f5b9
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
340
diff
changeset
|
798 |
|
262
ee4304bc6350
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
261
diff
changeset
|
799 |
\end{document} |
261
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
800 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
801 |
|
24531cfaa36a
updated handouts
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
259
diff
changeset
|
802 |
|
123
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
803 |
|
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
804 |
%%% Local Variables: |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
805 |
%%% mode: latex |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
806 |
%%% TeX-master: t |
a75f9c9d8f94
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
807 |
%%% End: |