thys/Paper/Paper.thy
changeset 181 162f112b814b
parent 180 42ffaca7c85e
child 182 2e70c1b06ac0
equal deleted inserted replaced
180:42ffaca7c85e 181:162f112b814b
    24   CHAR ("_" [1000] 80) and
    24   CHAR ("_" [1000] 80) and
    25   ALT ("_ + _" [77,77] 78) and
    25   ALT ("_ + _" [77,77] 78) and
    26   SEQ ("_ \<cdot> _" [77,77] 78) and
    26   SEQ ("_ \<cdot> _" [77,77] 78) and
    27   STAR ("_\<^sup>\<star>" [1000] 78) and
    27   STAR ("_\<^sup>\<star>" [1000] 78) and
    28   
    28   
    29   val.Void ("'(')" 79) and
    29   val.Void ("'(')" 1000) and
    30   val.Char ("Char _" [1000] 78) and
    30   val.Char ("Char _" [1000] 78) and
    31   val.Left ("Left _" [79] 78) and
    31   val.Left ("Left _" [79] 78) and
    32   val.Right ("Right _" [79] 78) and
    32   val.Right ("Right _" [1000] 78) and
    33   val.Seq ("Seq _ _" [79,79] 78) and
    33   val.Seq ("Seq _ _" [79,79] 78) and
    34   val.Stars ("Stars _" [79] 78) and
    34   val.Stars ("Stars _" [79] 78) and
    35 
    35 
    36   L ("L'(_')" [10] 78) and
    36   L ("L'(_')" [10] 78) and
    37   der_syn ("_\\_" [79, 1000] 76) and  
    37   der_syn ("_\\_" [79, 1000] 76) and  
   266   inductively by two clauses: @{text "(i)"} the empty string being in
   266   inductively by two clauses: @{text "(i)"} the empty string being in
   267   the star of a language and @{text "(ii)"} if @{term "s\<^sub>1"} is in a
   267   the star of a language and @{text "(ii)"} if @{term "s\<^sub>1"} is in a
   268   language and @{term "s\<^sub>2"} in the star of this language, then also @{term
   268   language and @{term "s\<^sub>2"} in the star of this language, then also @{term
   269   "s\<^sub>1 @ s\<^sub>2"} is in the star of this language. It will also be convenient
   269   "s\<^sub>1 @ s\<^sub>2"} is in the star of this language. It will also be convenient
   270   to use the following notion of a \emph{semantic derivative} (or \emph{left
   270   to use the following notion of a \emph{semantic derivative} (or \emph{left
   271   quotient}) of a language defined as:
   271   quotient}) of a language defined as
   272 
   272   @{thm (lhs) Der_def} $\dn$ @{thm (rhs) Der_def}.
   273   \begin{center}
       
   274   \begin{tabular}{lcl}
       
   275   @{thm (lhs) Der_def} & $\dn$ & @{thm (rhs) Der_def}\\
       
   276   \end{tabular}
       
   277   \end{center}
       
   278   
       
   279   \noindent 
       
   280   For semantic derivatives we have the following equations (for example
   273   For semantic derivatives we have the following equations (for example
   281   mechanically proved in \cite{Krauss2011}):
   274   mechanically proved in \cite{Krauss2011}):
   282 
   275 
   283   \begin{equation}\label{SemDer}
   276   \begin{equation}\label{SemDer}
   284   \begin{array}{lcl}
   277   \begin{array}{lcl}
   327   We may extend this definition to give derivatives w.r.t.~strings:
   320   We may extend this definition to give derivatives w.r.t.~strings:
   328 
   321 
   329   \begin{center}
   322   \begin{center}
   330   \begin{tabular}{lcl}
   323   \begin{tabular}{lcl}
   331   @{thm (lhs) ders.simps(1)} & $\dn$ & @{thm (rhs) ders.simps(1)}\\
   324   @{thm (lhs) ders.simps(1)} & $\dn$ & @{thm (rhs) ders.simps(1)}\\
       
   325   \end{tabular}
       
   326   \hspace{20mm}
       
   327   \begin{tabular}{lcl}
   332   @{thm (lhs) ders.simps(2)} & $\dn$ & @{thm (rhs) ders.simps(2)}\\
   328   @{thm (lhs) ders.simps(2)} & $\dn$ & @{thm (rhs) ders.simps(2)}\\
   333   \end{tabular}
   329   \end{tabular}
   334   \end{center}
   330   \end{center}
   335 
   331 
   336   \noindent Given the equations in \eqref{SemDer}, it is a relatively easy
   332   \noindent Given the equations in \eqref{SemDer}, it is a relatively easy
   344   \end{tabular}
   340   \end{tabular}
   345   \end{proposition}
   341   \end{proposition}
   346 
   342 
   347   \noindent With this in place it is also very routine to prove that the
   343   \noindent With this in place it is also very routine to prove that the
   348   regular expression matcher defined as
   344   regular expression matcher defined as
   349 
   345   %
   350   \begin{center}
   346   \begin{center}
   351   @{thm match_def}
   347   @{thm match_def}
   352   \end{center}
   348   \end{center}
   353 
   349 
   354   \noindent gives a positive answer if and only if @{term "s \<in> L r"}.
   350   \noindent gives a positive answer if and only if @{term "s \<in> L r"}.
   623   POSIX-specific choices into the side-conditions of our rules. Our
   619   POSIX-specific choices into the side-conditions of our rules. Our
   624   definition is inspired by the matching relation given by Vansummeren
   620   definition is inspired by the matching relation given by Vansummeren
   625   \cite{Vansummeren2006}. The relation we define is ternary and written as
   621   \cite{Vansummeren2006}. The relation we define is ternary and written as
   626   \mbox{@{term "s \<in> r \<rightarrow> v"}}, relating strings, regular expressions and
   622   \mbox{@{term "s \<in> r \<rightarrow> v"}}, relating strings, regular expressions and
   627   values.
   623   values.
   628 
   624   %
   629   \begin{center}
   625   \begin{center}\small
   630   \begin{tabular}{c}
   626   \begin{tabular}{c}
   631   @{thm[mode=Axiom] Posix.intros(1)}@{text "P"}@{term "ONE"} \qquad
   627   @{thm[mode=Axiom] Posix.intros(1)}@{text "P"}@{term "ONE"} \qquad
   632   @{thm[mode=Axiom] Posix.intros(2)}@{text "P"}@{term "c"}\bigskip\\
   628   @{thm[mode=Axiom] Posix.intros(2)}@{text "P"}@{term "c"}\medskip\\
   633   @{thm[mode=Rule] Posix.intros(3)[of "s" "r\<^sub>1" "v" "r\<^sub>2"]}@{text "P+L"}\qquad
   629   @{thm[mode=Rule] Posix.intros(3)[of "s" "r\<^sub>1" "v" "r\<^sub>2"]}@{text "P+L"}\qquad
   634   @{thm[mode=Rule] Posix.intros(4)[of "s" "r\<^sub>2" "v" "r\<^sub>1"]}@{text "P+R"}\bigskip\\
   630   @{thm[mode=Rule] Posix.intros(4)[of "s" "r\<^sub>2" "v" "r\<^sub>1"]}@{text "P+R"}\medskip\\
   635   $\mprset{flushleft}
   631   $\mprset{flushleft}
   636    \inferrule
   632    \inferrule
   637    {@{thm (prem 1) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \qquad
   633    {@{thm (prem 1) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \qquad
   638     @{thm (prem 2) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \\\\
   634     @{thm (prem 2) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \\\\
   639     @{thm (prem 3) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}
   635     @{thm (prem 3) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}
   640    {@{thm (concl) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}$@{text "PS"}\\
   636    {@{thm (concl) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}$@{text "PS"}\\
   641   @{thm[mode=Axiom] Posix.intros(7)}@{text "P[]"}\bigskip\\
   637   @{thm[mode=Axiom] Posix.intros(7)}@{text "P[]"}\medskip\\
   642   $\mprset{flushleft}
   638   $\mprset{flushleft}
   643    \inferrule
   639    \inferrule
   644    {@{thm (prem 1) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
   640    {@{thm (prem 1) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
   645     @{thm (prem 2) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
   641     @{thm (prem 2) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad
   646     @{thm (prem 3) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \\\\
   642     @{thm (prem 3) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \\\\
   740   \end{description}
   736   \end{description}
   741   \end{quote}
   737   \end{quote}
   742 
   738 
   743   \noindent For @{text "(a)"} we know @{term "s\<^sub>1 \<in> der c r\<^sub>1 \<rightarrow> v\<^sub>1"} and
   739   \noindent For @{text "(a)"} we know @{term "s\<^sub>1 \<in> der c r\<^sub>1 \<rightarrow> v\<^sub>1"} and
   744   @{term "s\<^sub>2 \<in> r\<^sub>2 \<rightarrow> v\<^sub>2"} as well as
   740   @{term "s\<^sub>2 \<in> r\<^sub>2 \<rightarrow> v\<^sub>2"} as well as
   745   
   741   %
   746   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> s\<^sub>1 @ s\<^sub>3 \<in> L (der c r\<^sub>1) \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   742   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> s\<^sub>1 @ s\<^sub>3 \<in> L (der c r\<^sub>1) \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   747 
   743 
   748   \noindent From the latter we can infer by Prop.~\ref{derprop}(2):
   744   \noindent From the latter we can infer by Prop.~\ref{derprop}(2):
   749 
   745   %
   750   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> (c # s\<^sub>1) @ s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   746   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s\<^sub>2 \<and> (c # s\<^sub>1) @ s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   751 
   747 
   752   \noindent We can use the induction hypothesis for @{text "r\<^sub>1"} to obtain
   748   \noindent We can use the induction hypothesis for @{text "r\<^sub>1"} to obtain
   753   @{term "(c # s\<^sub>1) \<in> r\<^sub>1 \<rightarrow> injval r\<^sub>1 c v\<^sub>1"}. Putting this all together allows us to infer
   749   @{term "(c # s\<^sub>1) \<in> r\<^sub>1 \<rightarrow> injval r\<^sub>1 c v\<^sub>1"}. Putting this all together allows us to infer
   754   @{term "((c # s\<^sub>1) @ s\<^sub>2) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (injval r\<^sub>1 c v\<^sub>1) v\<^sub>2"}. The case @{text "(c)"}
   750   @{term "((c # s\<^sub>1) @ s\<^sub>2) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (injval r\<^sub>1 c v\<^sub>1) v\<^sub>2"}. The case @{text "(c)"}
   756 
   752 
   757   For @{text "(b)"} we know @{term "s \<in> der c r\<^sub>2 \<rightarrow> v\<^sub>1"} and 
   753   For @{text "(b)"} we know @{term "s \<in> der c r\<^sub>2 \<rightarrow> v\<^sub>1"} and 
   758   @{term "s\<^sub>1 @ s\<^sub>2 \<notin> L (SEQ (der c r\<^sub>1) r\<^sub>2)"}. From the former
   754   @{term "s\<^sub>1 @ s\<^sub>2 \<notin> L (SEQ (der c r\<^sub>1) r\<^sub>2)"}. From the former
   759   we have @{term "(c # s) \<in> r\<^sub>2 \<rightarrow> (injval r\<^sub>2 c v\<^sub>1)"} by induction hypothesis
   755   we have @{term "(c # s) \<in> r\<^sub>2 \<rightarrow> (injval r\<^sub>2 c v\<^sub>1)"} by induction hypothesis
   760   for @{term "r\<^sub>2"}. From the latter we can infer
   756   for @{term "r\<^sub>2"}. From the latter we can infer
   761 
   757   %
   762   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   758   \[@{term "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> s\<^sub>3 \<in> L r\<^sub>1 \<and> s\<^sub>4 \<in> L r\<^sub>2)"}\]
   763 
   759 
   764   \noindent By Lem.~\ref{lemmkeps} we know @{term "[] \<in> r\<^sub>1 \<rightarrow> (mkeps r\<^sub>1)"}
   760   \noindent By Lem.~\ref{lemmkeps} we know @{term "[] \<in> r\<^sub>1 \<rightarrow> (mkeps r\<^sub>1)"}
   765   holds. Putting this all together, we can conclude with @{term "(c #
   761   holds. Putting this all together, we can conclude with @{term "(c #
   766   s) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (mkeps r\<^sub>1) (injval r\<^sub>2 c v\<^sub>1)"}, as required.
   762   s) \<in> SEQ r\<^sub>1 r\<^sub>2 \<rightarrow> Seq (mkeps r\<^sub>1) (injval r\<^sub>2 c v\<^sub>1)"}, as required.
   849 
   845 
   850   While the simplification of regular expressions according to 
   846   While the simplification of regular expressions according to 
   851   rules like
   847   rules like
   852 
   848 
   853   \begin{equation}\label{Simpl}
   849   \begin{equation}\label{Simpl}
   854   \begin{array}{lcl}
   850   \begin{array}{lcllcllcllcl}
   855   @{term "ALT ZERO r"} & @{text "\<Rightarrow>"} & @{term r}\\
   851   @{term "ALT ZERO r"} & @{text "\<Rightarrow>"} & @{term r} \hspace{8mm}%\\
   856   @{term "ALT r ZERO"} & @{text "\<Rightarrow>"} & @{term r}\\
   852   @{term "ALT r ZERO"} & @{text "\<Rightarrow>"} & @{term r} \hspace{8mm}%\\
   857   @{term "SEQ ONE r"}  & @{text "\<Rightarrow>"} & @{term r}\\
   853   @{term "SEQ ONE r"}  & @{text "\<Rightarrow>"} & @{term r} \hspace{8mm}%\\
   858   @{term "SEQ r ONE"}  & @{text "\<Rightarrow>"} & @{term r}
   854   @{term "SEQ r ONE"}  & @{text "\<Rightarrow>"} & @{term r}
   859   \end{array}
   855   \end{array}
   860   \end{equation}
   856   \end{equation}
   861 
   857 
   862   \noindent is well understood, there is an obstacle with the POSIX value
   858   \noindent is well understood, there is an obstacle with the POSIX value
   868   a \emph{rectification function} that ``repairs'' the incorrect value.
   864   a \emph{rectification function} that ``repairs'' the incorrect value.
   869   
   865   
   870   The rectification functions can be (slightly clumsily) implemented  in
   866   The rectification functions can be (slightly clumsily) implemented  in
   871   Isabelle/HOL as follows using some auxiliary functions:
   867   Isabelle/HOL as follows using some auxiliary functions:
   872 
   868 
   873   \begin{center}
   869   \begin{center}\small
       
   870   \begin{tabular}{cc}
   874   \begin{tabular}{lcl}
   871   \begin{tabular}{lcl}
   875   @{thm (lhs) F_RIGHT.simps(1)} & $\dn$ & @{text "Right (f v)"}\\
   872   @{thm (lhs) F_RIGHT.simps(1)} & $\dn$ & @{text "Right (f v)"}\\
   876   @{thm (lhs) F_LEFT.simps(1)} & $\dn$ & @{text "Left (f v)"}\\
   873   @{thm (lhs) F_LEFT.simps(1)} & $\dn$ & @{text "Left (f v)"}\\
   877   
   874   
   878   @{thm (lhs) F_ALT.simps(1)} & $\dn$ & @{text "Right (f\<^sub>2 v)"}\\
   875   @{thm (lhs) F_ALT.simps(1)} & $\dn$ & @{text "Right (f\<^sub>2 v)"}\\
   879   @{thm (lhs) F_ALT.simps(2)} & $\dn$ & @{text "Left (f\<^sub>1 v)"}\\
   876   @{thm (lhs) F_ALT.simps(2)} & $\dn$ & @{text "Left (f\<^sub>1 v)"}\\
   880   
   877   
   881   @{thm (lhs) F_SEQ1.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 ()) (f\<^sub>2 v)"}\\
   878   @{thm (lhs) F_SEQ1.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 ()) (f\<^sub>2 v)"}\\
   882   @{thm (lhs) F_SEQ2.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 v) (f\<^sub>2 ())"}\\
   879   @{thm (lhs) F_SEQ2.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 v) (f\<^sub>2 ())"}\\
   883   @{thm (lhs) F_SEQ.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)"}\bigskip\\
   880   @{thm (lhs) F_SEQ.simps(1)} & $\dn$ & @{text "Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)"}%\bigskip\\
   884 
   881   \end{tabular}
       
   882   &
       
   883   \begin{tabular}{lcl}
   885   @{term "simp_ALT (ZERO, DUMMY) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_RIGHT f\<^sub>2)"}\\
   884   @{term "simp_ALT (ZERO, DUMMY) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_RIGHT f\<^sub>2)"}\\
   886   @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (ZERO, DUMMY)"} & $\dn$ & @{term "(r\<^sub>1, F_LEFT f\<^sub>1)"}\\
   885   @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (ZERO, DUMMY)"} & $\dn$ & @{term "(r\<^sub>1, F_LEFT f\<^sub>1)"}\\
   887   @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(ALT r\<^sub>1 r\<^sub>2, F_ALT f\<^sub>1 f\<^sub>2)"}\\
   886   @{term "simp_ALT (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(ALT r\<^sub>1 r\<^sub>2, F_ALT f\<^sub>1 f\<^sub>2)"}\\
   888   @{term "simp_SEQ (ONE, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_SEQ1 f\<^sub>1 f\<^sub>2)"}\\
   887   @{term "simp_SEQ (ONE, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>2, F_SEQ1 f\<^sub>1 f\<^sub>2)"}\\
   889   @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (ONE, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>1, F_SEQ2 f\<^sub>1 f\<^sub>2)"}\\
   888   @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (ONE, f\<^sub>2)"} & $\dn$ & @{term "(r\<^sub>1, F_SEQ2 f\<^sub>1 f\<^sub>2)"}\\
   890   @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(SEQ r\<^sub>1 r\<^sub>2, F_SEQ f\<^sub>1 f\<^sub>2)"}\\
   889   @{term "simp_SEQ (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2)"} & $\dn$ & @{term "(SEQ r\<^sub>1 r\<^sub>2, F_SEQ f\<^sub>1 f\<^sub>2)"}\\
       
   890   \end{tabular}
   891   \end{tabular}
   891   \end{tabular}
   892   \end{center}
   892   \end{center}
   893 
   893 
   894   \noindent
   894   \noindent
   895   The functions @{text "simp\<^bsub>Alt\<^esub>"} and @{text "simp\<^bsub>Seq\<^esub>"} encode the simplification rules
   895   The functions @{text "simp\<^bsub>Alt\<^esub>"} and @{text "simp\<^bsub>Seq\<^esub>"} encode the simplification rules
   928   is then recursively called with the simplified derivative, but before
   928   is then recursively called with the simplified derivative, but before
   929   we inject the character @{term c} into the value @{term v}, we need to rectify
   929   we inject the character @{term c} into the value @{term v}, we need to rectify
   930   @{term v} (that is construct @{term "f\<^sub>r v"}). Before we can establish the correctness
   930   @{term v} (that is construct @{term "f\<^sub>r v"}). Before we can establish the correctness
   931   of @{term "slexer"}, we need to show that simplification preserves the language
   931   of @{term "slexer"}, we need to show that simplification preserves the language
   932   and simplification preserves our POSIX relation once the value is rectified
   932   and simplification preserves our POSIX relation once the value is rectified
   933   (recall @{const "simp"} generates a regular expression, rectification function pair):
   933   (recall @{const "simp"} generates a regular expression / rectification function pair):
   934 
   934 
   935   \begin{lemma}\mbox{}\smallskip\\\label{slexeraux}
   935   \begin{lemma}\mbox{}\smallskip\\\label{slexeraux}
   936   \begin{tabular}{ll}
   936   \begin{tabular}{ll}
   937   (1) & @{thm L_fst_simp[symmetric]}\\
   937   (1) & @{thm L_fst_simp[symmetric]}\\
   938   (2) & @{thm[mode=IfThen] Posix_simp}
   938   (2) & @{thm[mode=IfThen] Posix_simp}
   939   \end{tabular}
   939   \end{tabular}
   940   \end{lemma}
   940   \end{lemma}
   941 
   941 
   942   \begin{proof}
   942   \begin{proof} Both are by induction on @{text r}. There is no
   943   Both are by induction on @{text r}. There is no interesting case for the
   943   interesting case for the first statement. For the second statement,
   944   first statement. For the second statement of interest are the @{term "r = SEQ r\<^sub>1 r\<^sub>2"}
   944   of interest are the @{term "r = ALT r\<^sub>1 r\<^sub>2"} and @{term "r = SEQ r\<^sub>1
   945   and @{term "r = ALT r\<^sub>1 r\<^sub>2"} cases.
   945   r\<^sub>2"} cases. In each case we have to analyse four subcases whether
   946   
   946   @{term "fst (simp r\<^sub>1)"} and @{term "fst (simp r\<^sub>2)"} equals @{const
       
   947   ZERO} (respectively @{const ONE}). For example for @{term "r = ALT
       
   948   r\<^sub>1 r\<^sub>2"}, considder the subcase @{term "fst (simp r\<^sub>1) = ZERO"} and
       
   949   @{term "fst (simp r\<^sub>2) \<noteq> ZERO"}. By assumption we know @{term "s \<in>
       
   950   fst (simp (ALT r\<^sub>1 r\<^sub>2)) \<rightarrow> v"}. From this we can infer @{term "s \<in> fst (simp r\<^sub>2) \<rightarrow> v"}
       
   951   and by IH also (*) @{term "s \<in> r\<^sub>2 \<rightarrow> (snd (simp r\<^sub>2) v)"}. Given @{term "fst (simp r\<^sub>1) = ZERO"}
       
   952   we know @{term "L (fst (simp r\<^sub>1)) = {}"}. By the first statement
       
   953   @{term "L r\<^sub>1"} is the empty set, meaning (**) @{term "s \<notin> L r\<^sub>1"}.
       
   954   Taking (*) and (**) together gives by the \mbox{@{text "P+R"}}-rule 
       
   955   @{term "s \<in> ALT r\<^sub>1 r\<^sub>2 \<rightarrow> Right (snd (simp r\<^sub>2) v)"}. In turn this
       
   956   gives @{term "s \<in> ALT r\<^sub>1 r\<^sub>2 \<rightarrow> snd (simp (ALT r\<^sub>1 r\<^sub>2)) v"} as we need to show.
       
   957   The other cases are similar.\qed
   947   \end{proof}
   958   \end{proof}
   948 
   959 
   949   \noindent We can now prove relatively straightforwardly that the
   960   \noindent We can now prove relatively straightforwardly that the
   950   optimised lexer produce the expected result:
   961   optimised lexer produce the expected result:
   951 
   962 
   997   final form, we make no comment thereon, preferring to give general reasons
  1008   final form, we make no comment thereon, preferring to give general reasons
   998   for our belief that the approach of \cite{Sulzmann2014} is problematic.
  1009   for our belief that the approach of \cite{Sulzmann2014} is problematic.
   999   Their central definition is an ``ordering relation'' defined by the
  1010   Their central definition is an ``ordering relation'' defined by the
  1000   rules (slightly adapted to fit our notation):
  1011   rules (slightly adapted to fit our notation):
  1001 
  1012 
  1002 \begin{center}  
  1013 \begin{center}\small  
  1003 \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}	
  1014 \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}	
  1004 @{thm[mode=Rule] C2[of "v\<^sub>1" "r\<^sub>1" "v\<^sub>1\<iota>" "v\<^sub>2" "r\<^sub>2" "v\<^sub>2\<iota>"]}\,(C2) &
  1015 @{thm[mode=Rule] C2[of "v\<^sub>1" "r\<^sub>1" "v\<^sub>1\<iota>" "v\<^sub>2" "r\<^sub>2" "v\<^sub>2\<iota>"]}\,(C2) &
  1005 @{thm[mode=Rule] C1[of "v\<^sub>2" "r\<^sub>2" "v\<^sub>2\<iota>" "v\<^sub>1" "r\<^sub>1"]}\,(C1)\smallskip\\
  1016 @{thm[mode=Rule] C1[of "v\<^sub>2" "r\<^sub>2" "v\<^sub>2\<iota>" "v\<^sub>1" "r\<^sub>1"]}\,(C1)\smallskip\\
  1006 
  1017 
  1007 @{thm[mode=Rule] A1[of "v\<^sub>1" "v\<^sub>2" "r\<^sub>1" "r\<^sub>2"]}\,(A1) &
  1018 @{thm[mode=Rule] A1[of "v\<^sub>1" "v\<^sub>2" "r\<^sub>1" "r\<^sub>2"]}\,(A1) &