cws/cw03.tex
changeset 75 71e463b33a9e
parent 74 fb2d8012ed08
child 78 85f2f75abeeb
--- a/cws/cw03.tex	Sat Nov 26 17:02:52 2016 +0000
+++ b/cws/cw03.tex	Sat Nov 26 19:12:33 2016 +0000
@@ -203,6 +203,33 @@
 \hfill[2 Mark]
 \end{itemize}
 
+\textbf{Background} Although easily implementable in Scala, the idea
+behind the derivative function might not so easy to be seen. To
+understand its purpose better, assume a regular expression $r$ can
+match strings of the form $c::cs$ (that means strings which start with
+a character $c$ and have some rest $cs$). If you now take the
+derivative of $r$ with respect to the character $c$, then you obtain a
+regular expressions that can match all the strings $cs$.  In other
+words the regular expression $\textit{der}\;c\;r$ can match the same
+strings $c::cs$ that can be matched by $r$, except that the $c$ is
+chopped off.
+
+Assume now $r$ can match the string $abc$. If you take the derivative
+according to $a$ then you obtain a regular expression that can match
+$bc$ (it is $abc$ where the $a$ has been chopped off). If you now
+build the derivative $\textit{der}\;b\;(\textit{der}\;a\;r))$ you obtain a regular
+expression that can match the string "c" (it is "bc" where 'b' is
+chopped off). If you finally build the derivative of this according
+'c', that is der('c', der('b', der('a', r))), you obtain a regular
+expression that can match the empty string. You can test this using
+the function nullable, which is what your matcher is doing.
+
+The purpose of the simp function is to keep the regular expression small. Normally the derivative function makes the regular expression bigger (see the SEQ case) and the algorithm would be slower and slower over time. The simp function counters this increase in size and the result is that the algorithm is fast throughout. 
+By the way this whole idea is by Janusz Brzozowski who came up with this in 1964 in his PhD thesis. 
+https://en.wikipedia.org/wiki/Janusz_Brzozowski_(computer_scientist)
+
+
+
 \subsection*{Part 2 (4 Marks)}
 
 Coming soon.