handouts/ho04.tex
changeset 286 19020b75d75e
parent 285 8a222559278f
child 287 2c50b8b5886c
--- a/handouts/ho04.tex	Fri Oct 17 13:44:50 2014 +0100
+++ b/handouts/ho04.tex	Fri Oct 17 14:18:15 2014 +0100
@@ -404,9 +404,56 @@
 
 \noindent In essence we need to apply in this case 
 the appropriate rectification function to the inner part
-of the value $v$, wherevy $v$ can only be of the form 
+of the value $v$, whereby $v$ can only be of the form 
 $Right(\_)$ or $Left(\_)$.
 
+The other interesting case with simplification is the 
+sequence case. Here the main simplification function 
+is as follows
+
+\begin{center}
+\begin{tabular}{l}
+$simp(r)$:\qquad\qquad (continued)\\
+\quad case $r = r_1 \cdot r_2$\\
+\qquad let $(r_{1s}, f_{1s}) = simp(r_1)$\\
+\qquad \phantom{let} $(r_{2s}, f_{2s}) = simp(r_2)$\smallskip\\
+\qquad case $r_{1s} = \varnothing$: 
+       return $(\varnothing, f_{error})$\\
+\qquad case $r_{2s} = \varnothing$: 
+       return $(\varnothing, f_{error})$\\
+\qquad case $r_{1s} = \epsilon$: 
+return $(r_{2s}, \lambda v. \,Seq(f_{1s}(Empty), f_{2s}(v)))$\\
+\qquad case $r_{2s} = \epsilon$: 
+return $(r_{1s}, \lambda v. \,Seq(f_{1s}(v), f_{2s}(Empty)))$\\
+\qquad otherwise: 
+       return $(r_{1s} \cdot r_{2s}, f_{seq}(f_{1s}, f_{2s}))$\\
+\end{tabular}
+\end{center}
+
+\noindent whereby $f_{seq}$ is again pushing the two 
+rectification functions into the two components of
+the Seq-value:
+
+\begin{center}
+\begin{tabular}{l@{\hspace{1mm}}l}
+$f_{seq}(f_1, f_2) \dn$\\
+\qquad $\lambda v.\,$ case $v = Seq(v_1, v_2)$: 
+      & return $Seq(f_1(v_1), f_2(v_2))$\\
+\end{tabular}
+\end{center}
+
+\noindent Note that in the case of $r_{1s}$ (similarly $r_{2s}$)
+we use the function $f_{error}$ for rectification. If you 
+think carefully, then you will see that this function will
+actually never been called. Because a sequence with 
+$\varnothing$ will never recognise any string and therefore
+the second phase of the algorithm would never been called.
+The simplification function still expects us to give a 
+function. So in my own implementation I just returned 
+a function which raises an error. 
+
+
+
 \subsubsection*{Records and Tokenisation}
 
 \newpage