thys2/Journal/Paper.tex
changeset 384 f5866f1d6a59
child 386 0efa7ffd96ff
equal deleted inserted replaced
383:aa0a2a3f90a0 384:f5866f1d6a59
       
     1 %
       
     2 \begin{isabellebody}%
       
     3 \setisabellecontext{Paper}%
       
     4 %
       
     5 \isadelimtheory
       
     6 %
       
     7 \endisadelimtheory
       
     8 %
       
     9 \isatagtheory
       
    10 %
       
    11 \endisatagtheory
       
    12 {\isafoldtheory}%
       
    13 %
       
    14 \isadelimtheory
       
    15 %
       
    16 \endisadelimtheory
       
    17 %
       
    18 \isadelimproof
       
    19 %
       
    20 \endisadelimproof
       
    21 %
       
    22 \isatagproof
       
    23 %
       
    24 \endisatagproof
       
    25 {\isafoldproof}%
       
    26 %
       
    27 \isadelimproof
       
    28 %
       
    29 \endisadelimproof
       
    30 %
       
    31 \isadelimproof
       
    32 %
       
    33 \endisadelimproof
       
    34 %
       
    35 \isatagproof
       
    36 %
       
    37 \endisatagproof
       
    38 {\isafoldproof}%
       
    39 %
       
    40 \isadelimproof
       
    41 %
       
    42 \endisadelimproof
       
    43 %
       
    44 \isadelimdocument
       
    45 %
       
    46 \endisadelimdocument
       
    47 %
       
    48 \isatagdocument
       
    49 %
       
    50 \isamarkupsection{Core of the proof%
       
    51 }
       
    52 \isamarkuptrue%
       
    53 %
       
    54 \endisatagdocument
       
    55 {\isafolddocument}%
       
    56 %
       
    57 \isadelimdocument
       
    58 %
       
    59 \endisadelimdocument
       
    60 %
       
    61 \begin{isamarkuptext}%
       
    62 This paper builds on previous work by Ausaf and Urban using 
       
    63 regular expression'd bit-coded derivatives to do lexing that 
       
    64 is both fast and satisfies the POSIX specification.
       
    65 In their work, a bit-coded algorithm introduced by Sulzmann and Lu
       
    66 was formally verified in Isabelle, by a very clever use of
       
    67 flex function and retrieve to carefully mimic the way a value is 
       
    68 built up by the injection funciton.
       
    69 
       
    70 In the previous work, Ausaf and Urban established the below equality:
       
    71 \begin{lemma}
       
    72 \isa{{\normalsize{}If\,}\ v\ {\isacharcolon}{\kern0pt}\ r{\isacharbackslash}{\kern0pt}s\ {\normalsize \,then\,}\ Some\ {\isacharparenleft}{\kern0pt}flex\ r\ id\ s\ v{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ decode\ {\isacharparenleft}{\kern0pt}retrieve\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}\mbox{$\bbslash$}s{\isacharparenright}{\kern0pt}\ v{\isacharparenright}{\kern0pt}\ r{\isachardot}{\kern0pt}}
       
    73 \end{lemma}
       
    74 
       
    75 This lemma establishes a link with the lexer without bit-codes.
       
    76 
       
    77 With it we get the correctness of bit-coded algorithm.
       
    78 \begin{lemma}
       
    79 \isa{lexer\mbox{$_b$}\ r\ s\ {\isacharequal}{\kern0pt}\ lexer\ r\ s}
       
    80 \end{lemma}
       
    81 
       
    82 However what is not certain is whether we can add simplification
       
    83 to the bit-coded algorithm, without breaking the correct lexing output.
       
    84 
       
    85 
       
    86 The reason that we do need to add a simplification phase
       
    87 after each derivative step of  $\textit{blexer}$ is
       
    88 because it produces intermediate
       
    89 regular expressions that can grow exponentially.
       
    90 For example, the regular expression $(a+aa)^*$ after taking
       
    91 derivative against just 10 $a$s will have size 8192.
       
    92 
       
    93 %TODO: add figure for this?
       
    94 
       
    95 
       
    96 Therefore, we insert a simplification phase
       
    97 after each derivation step, as defined below:
       
    98 \begin{lemma}
       
    99 \isa{blexer{\isacharunderscore}{\kern0pt}simp\ r\ s\ {\isasymequiv}\ \textrm{if}\ nullable\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}bders{\isacharunderscore}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}{\isacharparenright}{\kern0pt}\ s{\isacharparenright}{\kern0pt}\ \textrm{then}\ decode\ {\isacharparenleft}{\kern0pt}mkeps\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}bders{\isacharunderscore}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}{\isacharparenright}{\kern0pt}\ s{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ r\ \textrm{else}\ None}
       
   100 \end{lemma}
       
   101 
       
   102 The simplification function is given as follows:
       
   103 
       
   104 \begin{center}
       
   105   \begin{tabular}{lcl}
       
   106   \isa{bsimp\ {\isacharparenleft}{\kern0pt}ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{bsimp{\isacharunderscore}{\kern0pt}ASEQ\ bs\ {\isacharparenleft}{\kern0pt}bsimp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}bsimp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   107   \isa{bsimp\ {\isacharparenleft}{\kern0pt}AALTs\ bs{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ rs{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{bsimp{\isacharunderscore}{\kern0pt}AALTs\ bs{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isacharparenleft}{\kern0pt}distinctBy\ {\isacharparenleft}{\kern0pt}flts\ {\isacharparenleft}{\kern0pt}map\ bsimp\ rs{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ erase\ {\isasymemptyset}{\isacharparenright}{\kern0pt}}\\
       
   108   \isa{bsimp\ AZERO} & $\dn$ & \isa{AZERO}\\
       
   109 
       
   110 \end{tabular}
       
   111 \end{center}
       
   112 
       
   113 And the two helper functions are:
       
   114 \begin{center}
       
   115   \begin{tabular}{lcl}
       
   116   \isa{bsimp{\isacharunderscore}{\kern0pt}AALTs\ bs\isactrlsub {\isadigit{1}}\ {\isacharbrackleft}{\kern0pt}r{\isacharbrackright}{\kern0pt}} & $\dn$ & \isa{bsimp{\isacharunderscore}{\kern0pt}ASEQ\ bs\isactrlsub {\isadigit{1}}\ {\isacharparenleft}{\kern0pt}bsimp\ r{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}bsimp\ r{\isadigit{2}}{\isachardot}{\kern0pt}{\isadigit{0}}{\isacharparenright}{\kern0pt}}\\
       
   117   \isa{bsimp{\isacharunderscore}{\kern0pt}AALTs\ bs{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isacharbrackleft}{\kern0pt}r{\isacharbrackright}{\kern0pt}} & $\dn$ & \isa{bsimp{\isacharunderscore}{\kern0pt}AALTs\ bs{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isacharparenleft}{\kern0pt}distinctBy\ {\isacharparenleft}{\kern0pt}flts\ {\isacharparenleft}{\kern0pt}map\ bsimp\ rs{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ erase\ {\isasymemptyset}{\isacharparenright}{\kern0pt}}\\
       
   118   \isa{bsimp{\isacharunderscore}{\kern0pt}AALTs\ bs{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isacharparenleft}{\kern0pt}v\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vb\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vc{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{AZERO}\\
       
   119 
       
   120 \end{tabular}
       
   121 \end{center}
       
   122 
       
   123 
       
   124 This might sound trivial in the case of producing a YES/NO answer,
       
   125 but once we require a lexing output to be produced (which is required
       
   126 in applications like compiler front-end, malicious attack domain extraction, 
       
   127 etc.), it is not straightforward if we still extract what is needed according
       
   128 to the POSIX standard.
       
   129 
       
   130 
       
   131 
       
   132 
       
   133 
       
   134 By simplification, we mean specifically the following rules:
       
   135 
       
   136 \begin{center}
       
   137   \begin{tabular}{lcl}
       
   138   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{ASEQ\ bs\ AZERO\ r\isactrlsub {\isadigit{2}}\ {\isasymleadsto}\ AZERO}}}\\
       
   139   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ AZERO\ {\isasymleadsto}\ AZERO}}}\\
       
   140   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{ASEQ\ bs\ {\isacharparenleft}{\kern0pt}AONE\ bs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymleadsto}\ fuse\ {\isacharparenleft}{\kern0pt}bs\ {\isacharat}{\kern0pt}\ bs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}}}\\
       
   141   \isa{\mbox{}\inferrule{\mbox{r\isactrlsub {\isadigit{1}}\ {\isasymleadsto}\ r\isactrlsub {\isadigit{2}}}}{\mbox{ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{3}}\ {\isasymleadsto}\ ASEQ\ bs\ r\isactrlsub {\isadigit{2}}\ r\isactrlsub {\isadigit{3}}}}}\\
       
   142   \isa{\mbox{}\inferrule{\mbox{r\isactrlsub {\isadigit{3}}\ {\isasymleadsto}\ r\isactrlsub {\isadigit{4}}}}{\mbox{ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{3}}\ {\isasymleadsto}\ ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{4}}}}}\\
       
   143   \isa{\mbox{}\inferrule{\mbox{r\ {\isasymleadsto}\ r{\isacharprime}{\kern0pt}}}{\mbox{AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}r{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymleadsto}\ AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}r{\isacharprime}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}}}\\
       
   144   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}AZERO{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub b{\isacharparenright}{\kern0pt}\ {\isasymleadsto}\ AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ rs\isactrlsub b{\isacharparenright}{\kern0pt}}}}\\
       
   145   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}AALTs\ bs\isactrlsub {\isadigit{1}}\ rs\isactrlsub {\isadigit{1}}{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub b{\isacharparenright}{\kern0pt}\ {\isasymleadsto}\ AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ map\ {\isacharparenleft}{\kern0pt}fuse\ bs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ rs\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ rs\isactrlsub b{\isacharparenright}{\kern0pt}}}}\\
       
   146   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{AALTs\ {\isacharparenleft}{\kern0pt}bs\ {\isacharat}{\kern0pt}\ bs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ rs\ {\isasymleadsto}\ AALTs\ bs\ {\isacharparenleft}{\kern0pt}map\ {\isacharparenleft}{\kern0pt}fuse\ bs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ rs{\isacharparenright}{\kern0pt}}}}\\
       
   147   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{AALTs\ bs\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymleadsto}\ AZERO}}}\\
       
   148   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{AALTs\ bs\ {\isacharbrackleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbrackright}{\kern0pt}\ {\isasymleadsto}\ fuse\ bs\ r\isactrlsub {\isadigit{1}}}}}\\
       
   149   \isa{\mbox{}\inferrule{\mbox{a\isactrlsub {\isadigit{1}}\mbox{$^\downarrow$}\ {\isacharequal}{\kern0pt}\ a\isactrlsub {\isadigit{2}}\mbox{$^\downarrow$}}}{\mbox{AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}a\isactrlsub {\isadigit{1}}{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub b\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}a\isactrlsub {\isadigit{2}}{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub c{\isacharparenright}{\kern0pt}\ {\isasymleadsto}\ AALTs\ bs\ {\isacharparenleft}{\kern0pt}rs\isactrlsub a\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}a\isactrlsub {\isadigit{1}}{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ rs\isactrlsub b\ {\isacharat}{\kern0pt}\ rs\isactrlsub c{\isacharparenright}{\kern0pt}}}}\\
       
   150 
       
   151   \end{tabular}
       
   152 \end{center}
       
   153 
       
   154 
       
   155 And these can be made compact by the following simplification function:
       
   156 
       
   157 where the function $\mathit{bsimp_AALTs}$
       
   158 
       
   159 The core idea of the proof is that two regular expressions,
       
   160 if "isomorphic" up to a finite number of rewrite steps, will
       
   161 remain "isomorphic" when we take the same sequence of
       
   162 derivatives on both of them.
       
   163 This can be expressed by the following rewrite relation lemma:
       
   164 \begin{lemma}
       
   165 \isa{{\isacharparenleft}{\kern0pt}r\mbox{$\bbslash$}s{\isacharparenright}{\kern0pt}\ {\isasymleadsto}{\isacharasterisk}{\kern0pt}\ bders{\isacharunderscore}{\kern0pt}simp\ r\ s}
       
   166 \end{lemma}
       
   167 
       
   168 This isomorphic relation implies a property that leads to the 
       
   169 correctness result: 
       
   170 if two (nullable) regular expressions are "rewritable" in many steps
       
   171 from one another, 
       
   172 then a call to function $\textit{bmkeps}$ gives the same
       
   173 bit-sequence :
       
   174 \begin{lemma}
       
   175 \isa{{\normalsize{}If\,}\ \mbox{r{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isasymleadsto}{\isacharasterisk}{\kern0pt}\ r{\isadigit{2}}{\isachardot}{\kern0pt}{\isadigit{0}}}\ {\normalsize \,and\,}\ \mbox{nullable\mbox{$_b$}\ r{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}}\ {\normalsize \,then\,}\ mkeps\mbox{$_b$}\ r{\isadigit{1}}{\isachardot}{\kern0pt}{\isadigit{0}}\ {\isacharequal}{\kern0pt}\ mkeps\mbox{$_b$}\ r{\isadigit{2}}{\isachardot}{\kern0pt}{\isadigit{0}}{\isachardot}{\kern0pt}}
       
   176 \end{lemma}
       
   177 
       
   178 Given the same bit-sequence, the decode function
       
   179 will give out the same value, which is the output
       
   180 of both lexers:
       
   181 \begin{lemma}
       
   182 \isa{lexer\mbox{$_b$}\ r\ s\ {\isasymequiv}\ \textrm{if}\ nullable\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}\mbox{$\bbslash$}s{\isacharparenright}{\kern0pt}\ \textrm{then}\ decode\ {\isacharparenleft}{\kern0pt}mkeps\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}\mbox{$\bbslash$}s{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ r\ \textrm{else}\ None}
       
   183 \end{lemma}
       
   184 
       
   185 \begin{lemma}
       
   186 \isa{blexer{\isacharunderscore}{\kern0pt}simp\ r\ s\ {\isasymequiv}\ \textrm{if}\ nullable\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}bders{\isacharunderscore}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}{\isacharparenright}{\kern0pt}\ s{\isacharparenright}{\kern0pt}\ \textrm{then}\ decode\ {\isacharparenleft}{\kern0pt}mkeps\mbox{$_b$}\ {\isacharparenleft}{\kern0pt}bders{\isacharunderscore}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\mbox{$^\uparrow$}{\isacharparenright}{\kern0pt}\ s{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ r\ \textrm{else}\ None}
       
   187 \end{lemma}
       
   188 
       
   189 And that yields the correctness result:
       
   190 \begin{lemma}
       
   191 \isa{lexer\ r\ s\ {\isacharequal}{\kern0pt}\ blexer{\isacharunderscore}{\kern0pt}simp\ r\ s}
       
   192 \end{lemma}
       
   193 
       
   194 The nice thing about the above%
       
   195 \end{isamarkuptext}\isamarkuptrue%
       
   196 %
       
   197 \isadelimdocument
       
   198 %
       
   199 \endisadelimdocument
       
   200 %
       
   201 \isatagdocument
       
   202 %
       
   203 \isamarkupsection{Additional Simp Rules?%
       
   204 }
       
   205 \isamarkuptrue%
       
   206 %
       
   207 \endisatagdocument
       
   208 {\isafolddocument}%
       
   209 %
       
   210 \isadelimdocument
       
   211 %
       
   212 \endisadelimdocument
       
   213 %
       
   214 \begin{isamarkuptext}%
       
   215 One question someone would ask is:
       
   216 can we add more "atomic" simplification/rewriting rules,
       
   217 so the simplification is even more aggressive, making
       
   218 the intermediate results smaller, and therefore more space-efficient? 
       
   219 For example, one might want to do open up alternatives who is a child
       
   220 of a sequence:
       
   221 
       
   222 \begin{center}
       
   223   \begin{tabular}{lcl}
       
   224     \isa{ASEQ\ bs\ {\isacharparenleft}{\kern0pt}AALTs\ bs{\isadigit{1}}\ rs{\isacharparenright}{\kern0pt}\ r\ {\isasymleadsto}{\isacharquery}{\kern0pt}\ AALTs\ {\isacharparenleft}{\kern0pt}bs\ {\isacharat}{\kern0pt}\ bs{\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}map\ {\isacharparenleft}{\kern0pt}{\isasymlambda}r{\isacharprime}{\kern0pt}{\isachardot}{\kern0pt}\ ASEQ\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ r{\isacharprime}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ rs{\isacharparenright}{\kern0pt}}\\
       
   225   \end{tabular}
       
   226 \end{center}
       
   227 
       
   228 This rule allows us to simplify \mbox{\isa{{\isacharparenleft}{\kern0pt}a\ {\isacharplus}{\kern0pt}\ b{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ c\ {\isacharplus}{\kern0pt}\ a\ {\isasymcdot}\ c}}
       
   229  into  \mbox{\isa{a\ {\isasymcdot}\ c\ {\isacharplus}{\kern0pt}\ b\ {\isasymcdot}\ c}},
       
   230 which  cannot be done under the rrewrite rule because only alternatives which are
       
   231 children of another alternative can be spilled out.%
       
   232 \end{isamarkuptext}\isamarkuptrue%
       
   233 %
       
   234 \isadelimdocument
       
   235 %
       
   236 \endisadelimdocument
       
   237 %
       
   238 \isatagdocument
       
   239 %
       
   240 \isamarkupsection{Introduction%
       
   241 }
       
   242 \isamarkuptrue%
       
   243 %
       
   244 \endisatagdocument
       
   245 {\isafolddocument}%
       
   246 %
       
   247 \isadelimdocument
       
   248 %
       
   249 \endisadelimdocument
       
   250 %
       
   251 \begin{isamarkuptext}%
       
   252 Brzozowski \cite{Brzozowski1964} introduced the notion of the {\em
       
   253 derivative} \isa{r{\isacharbackslash}{\kern0pt}c} of a regular expression \isa{r} w.r.t.\
       
   254 a character~\isa{c}, and showed that it gave a simple solution to the
       
   255 problem of matching a string \isa{s} with a regular expression \isa{r}: if the derivative of \isa{r} w.r.t.\ (in succession) all the
       
   256 characters of the string matches the empty string, then \isa{r}
       
   257 matches \isa{s} (and {\em vice versa}). The derivative has the
       
   258 property (which may almost be regarded as its specification) that, for
       
   259 every string \isa{s} and regular expression \isa{r} and character
       
   260 \isa{c}, one has \isa{cs\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}} if and only if \mbox{\isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}}}. 
       
   261 The beauty of Brzozowski's derivatives is that
       
   262 they are neatly expressible in any functional language, and easily
       
   263 definable and reasoned about in theorem provers---the definitions just
       
   264 consist of inductive datatypes and simple recursive functions. A
       
   265 mechanised correctness proof of Brzozowski's matcher in for example HOL4
       
   266 has been mentioned by Owens and Slind~\cite{Owens2008}. Another one in
       
   267 Isabelle/HOL is part of the work by Krauss and Nipkow \cite{Krauss2011}.
       
   268 And another one in Coq is given by Coquand and Siles \cite{Coquand2012}.
       
   269 
       
   270 If a regular expression matches a string, then in general there is more
       
   271 than one way of how the string is matched. There are two commonly used
       
   272 disambiguation strategies to generate a unique answer: one is called
       
   273 GREEDY matching \cite{Frisch2004} and the other is POSIX
       
   274 matching~\cite{POSIX,Kuklewicz,OkuiSuzuki2010,Sulzmann2014,Vansummeren2006}.
       
   275 For example consider the string \isa{xy} and the regular expression
       
   276 \mbox{\isa{{\isacharparenleft}{\kern0pt}x\ {\isacharplus}{\kern0pt}\ y\ {\isacharplus}{\kern0pt}\ xy{\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}}}. Either the string can be
       
   277 matched in two `iterations' by the single letter-regular expressions
       
   278 \isa{x} and \isa{y}, or directly in one iteration by \isa{xy}. The
       
   279 first case corresponds to GREEDY matching, which first matches with the
       
   280 left-most symbol and only matches the next symbol in case of a mismatch
       
   281 (this is greedy in the sense of preferring instant gratification to
       
   282 delayed repletion). The second case is POSIX matching, which prefers the
       
   283 longest match.
       
   284 
       
   285 In the context of lexing, where an input string needs to be split up
       
   286 into a sequence of tokens, POSIX is the more natural disambiguation
       
   287 strategy for what programmers consider basic syntactic building blocks
       
   288 in their programs.  These building blocks are often specified by some
       
   289 regular expressions, say \isa{r\isactrlbsub key\isactrlesub } and \isa{r\isactrlbsub id\isactrlesub } for recognising keywords and identifiers,
       
   290 respectively. There are a few underlying (informal) rules behind
       
   291 tokenising a string in a POSIX \cite{POSIX} fashion:
       
   292 
       
   293 \begin{itemize} 
       
   294 \item[$\bullet$] \emph{The Longest Match Rule} (or \emph{``{M}aximal {M}unch {R}ule''}):
       
   295 The longest initial substring matched by any regular expression is taken as
       
   296 next token.\smallskip
       
   297 
       
   298 \item[$\bullet$] \emph{Priority Rule:}
       
   299 For a particular longest initial substring, the first (leftmost) regular expression
       
   300 that can match determines the token.\smallskip
       
   301 
       
   302 \item[$\bullet$] \emph{Star Rule:} A subexpression repeated by ${}^\star$ shall 
       
   303 not match an empty string unless this is the only match for the repetition.\smallskip
       
   304 
       
   305 \item[$\bullet$] \emph{Empty String Rule:} An empty string shall be considered to 
       
   306 be longer than no match at all.
       
   307 \end{itemize}
       
   308 
       
   309 \noindent Consider for example a regular expression \isa{r\isactrlbsub key\isactrlesub } for recognising keywords such as \isa{if},
       
   310 \isa{then} and so on; and \isa{r\isactrlbsub id\isactrlesub }
       
   311 recognising identifiers (say, a single character followed by
       
   312 characters or numbers).  Then we can form the regular expression
       
   313 \isa{{\isacharparenleft}{\kern0pt}r\isactrlbsub key\isactrlesub \ {\isacharplus}{\kern0pt}\ r\isactrlbsub id\isactrlesub {\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}}
       
   314 and use POSIX matching to tokenise strings, say \isa{iffoo} and
       
   315 \isa{if}.  For \isa{iffoo} we obtain by the Longest Match Rule
       
   316 a single identifier token, not a keyword followed by an
       
   317 identifier. For \isa{if} we obtain by the Priority Rule a keyword
       
   318 token, not an identifier token---even if \isa{r\isactrlbsub id\isactrlesub }
       
   319 matches also. By the Star Rule we know \isa{{\isacharparenleft}{\kern0pt}r\isactrlbsub key\isactrlesub \ {\isacharplus}{\kern0pt}\ r\isactrlbsub id\isactrlesub {\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}} matches \isa{iffoo},
       
   320 respectively \isa{if}, in exactly one `iteration' of the star. The
       
   321 Empty String Rule is for cases where, for example, the regular expression 
       
   322 \isa{{\isacharparenleft}{\kern0pt}a\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}} matches against the
       
   323 string \isa{bc}. Then the longest initial matched substring is the
       
   324 empty string, which is matched by both the whole regular expression
       
   325 and the parenthesised subexpression.
       
   326 
       
   327 
       
   328 One limitation of Brzozowski's matcher is that it only generates a
       
   329 YES/NO answer for whether a string is being matched by a regular
       
   330 expression.  Sulzmann and Lu~\cite{Sulzmann2014} extended this matcher
       
   331 to allow generation not just of a YES/NO answer but of an actual
       
   332 matching, called a [lexical] {\em value}. Assuming a regular
       
   333 expression matches a string, values encode the information of
       
   334 \emph{how} the string is matched by the regular expression---that is,
       
   335 which part of the string is matched by which part of the regular
       
   336 expression. For this consider again the string \isa{xy} and
       
   337 the regular expression \mbox{\isa{{\isacharparenleft}{\kern0pt}x\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}y\ {\isacharplus}{\kern0pt}\ xy{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}}}
       
   338 (this time fully parenthesised). We can view this regular expression
       
   339 as tree and if the string \isa{xy} is matched by two Star
       
   340 `iterations', then the \isa{x} is matched by the left-most
       
   341 alternative in this tree and the \isa{y} by the right-left alternative. This
       
   342 suggests to record this matching as
       
   343 
       
   344 \begin{center}
       
   345 \isa{Stars\ {\isacharbrackleft}{\kern0pt}Left\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}{\isacharcomma}{\kern0pt}\ Right\ {\isacharparenleft}{\kern0pt}Left\ {\isacharparenleft}{\kern0pt}Char\ y{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharbrackright}{\kern0pt}}
       
   346 \end{center}
       
   347 
       
   348 \noindent where \isa{Stars}, \isa{Left}, \isa{Right} and \isa{Char} are constructors for values. \isa{Stars} records how many
       
   349 iterations were used; \isa{Left}, respectively \isa{Right}, which
       
   350 alternative is used. This `tree view' leads naturally to the idea that
       
   351 regular expressions act as types and values as inhabiting those types
       
   352 (see, for example, \cite{HosoyaVouillonPierce2005}).  The value for
       
   353 matching \isa{xy} in a single `iteration', i.e.~the POSIX value,
       
   354 would look as follows
       
   355 
       
   356 \begin{center}
       
   357 \isa{Stars\ {\isacharbrackleft}{\kern0pt}Seq\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}Char\ y{\isacharparenright}{\kern0pt}{\isacharbrackright}{\kern0pt}}
       
   358 \end{center}
       
   359 
       
   360 \noindent where \isa{Stars} has only a single-element list for the
       
   361 single iteration and \isa{Seq} indicates that \isa{xy} is matched 
       
   362 by a sequence regular expression.
       
   363 
       
   364 %, which we will in what follows 
       
   365 %write more formally as \isa{x\ {\isasymcdot}\ y}.
       
   366 
       
   367 
       
   368 Sulzmann and Lu give a simple algorithm to calculate a value that
       
   369 appears to be the value associated with POSIX matching.  The challenge
       
   370 then is to specify that value, in an algorithm-independent fashion,
       
   371 and to show that Sulzmann and Lu's derivative-based algorithm does
       
   372 indeed calculate a value that is correct according to the
       
   373 specification.  The answer given by Sulzmann and Lu
       
   374 \cite{Sulzmann2014} is to define a relation (called an ``order
       
   375 relation'') on the set of values of \isa{r}, and to show that (once
       
   376 a string to be matched is chosen) there is a maximum element and that
       
   377 it is computed by their derivative-based algorithm. This proof idea is
       
   378 inspired by work of Frisch and Cardelli \cite{Frisch2004} on a GREEDY
       
   379 regular expression matching algorithm. However, we were not able to
       
   380 establish transitivity and totality for the ``order relation'' by
       
   381 Sulzmann and Lu.  There are some inherent problems with their approach
       
   382 (of which some of the proofs are not published in
       
   383 \cite{Sulzmann2014}); perhaps more importantly, we give in this paper
       
   384 a simple inductive (and algorithm-independent) definition of what we
       
   385 call being a {\em POSIX value} for a regular expression \isa{r} and
       
   386 a string \isa{s}; we show that the algorithm by Sulzmann and Lu
       
   387 computes such a value and that such a value is unique. Our proofs are
       
   388 both done by hand and checked in Isabelle/HOL.  The experience of
       
   389 doing our proofs has been that this mechanical checking was absolutely
       
   390 essential: this subject area has hidden snares. This was also noted by
       
   391 Kuklewicz \cite{Kuklewicz} who found that nearly all POSIX matching
       
   392 implementations are ``buggy'' \cite[Page 203]{Sulzmann2014} and by
       
   393 Grathwohl et al \cite[Page 36]{CrashCourse2014} who wrote:
       
   394 
       
   395 \begin{quote}
       
   396 \it{}``The POSIX strategy is more complicated than the greedy because of 
       
   397 the dependence on information about the length of matched strings in the 
       
   398 various subexpressions.''
       
   399 \end{quote}
       
   400 
       
   401 
       
   402 
       
   403 \noindent {\bf Contributions:} We have implemented in Isabelle/HOL the
       
   404 derivative-based regular expression matching algorithm of
       
   405 Sulzmann and Lu \cite{Sulzmann2014}. We have proved the correctness of this
       
   406 algorithm according to our specification of what a POSIX value is (inspired
       
   407 by work of Vansummeren \cite{Vansummeren2006}). Sulzmann
       
   408 and Lu sketch in \cite{Sulzmann2014} an informal correctness proof: but to
       
   409 us it contains unfillable gaps.\footnote{An extended version of
       
   410 \cite{Sulzmann2014} is available at the website of its first author; this
       
   411 extended version already includes remarks in the appendix that their
       
   412 informal proof contains gaps, and possible fixes are not fully worked out.}
       
   413 Our specification of a POSIX value consists of a simple inductive definition
       
   414 that given a string and a regular expression uniquely determines this value.
       
   415 We also show that our definition is equivalent to an ordering 
       
   416 of values based on positions by Okui and Suzuki \cite{OkuiSuzuki2010}.
       
   417 
       
   418 %Derivatives as calculated by Brzozowski's method are usually more complex
       
   419 %regular expressions than the initial one; various optimisations are
       
   420 %possible. We prove the correctness when simplifications of \isa{\isactrlbold {\isadigit{0}}\ {\isacharplus}{\kern0pt}\ r}, 
       
   421 %\isa{r\ {\isacharplus}{\kern0pt}\ \isactrlbold {\isadigit{0}}}, \isa{\isactrlbold {\isadigit{1}}\ {\isasymcdot}\ r} and \isa{r\ {\isasymcdot}\ \isactrlbold {\isadigit{1}}} to
       
   422 %\isa{r} are applied. 
       
   423 
       
   424 We extend our results to ??? Bitcoded version??%
       
   425 \end{isamarkuptext}\isamarkuptrue%
       
   426 %
       
   427 \isadelimdocument
       
   428 %
       
   429 \endisadelimdocument
       
   430 %
       
   431 \isatagdocument
       
   432 %
       
   433 \isamarkupsection{Preliminaries%
       
   434 }
       
   435 \isamarkuptrue%
       
   436 %
       
   437 \endisatagdocument
       
   438 {\isafolddocument}%
       
   439 %
       
   440 \isadelimdocument
       
   441 %
       
   442 \endisadelimdocument
       
   443 %
       
   444 \begin{isamarkuptext}%
       
   445 \noindent Strings in Isabelle/HOL are lists of characters with
       
   446 the empty string being represented by the empty list, written \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}, and list-cons being written as \isa{\underline{\hspace{2mm}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}\underline{\hspace{2mm}}}. Often
       
   447 we use the usual bracket notation for lists also for strings; for
       
   448 example a string consisting of just a single character \isa{c} is
       
   449 written \isa{{\isacharbrackleft}{\kern0pt}c{\isacharbrackright}{\kern0pt}}. We use the usual definitions for 
       
   450 \emph{prefixes} and \emph{strict prefixes} of strings.  By using the
       
   451 type \isa{char} for characters we have a supply of finitely many
       
   452 characters roughly corresponding to the ASCII character set. Regular
       
   453 expressions are defined as usual as the elements of the following
       
   454 inductive datatype:
       
   455 
       
   456   \begin{center}
       
   457   \isa{r\ {\isacharcolon}{\kern0pt}{\isacharequal}{\kern0pt}}
       
   458   \isa{\isactrlbold {\isadigit{0}}} $\mid$
       
   459   \isa{\isactrlbold {\isadigit{1}}} $\mid$
       
   460   \isa{c} $\mid$
       
   461   \isa{r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}} $\mid$
       
   462   \isa{r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}} $\mid$
       
   463   \isa{r\isactrlsup {\isasymstar}} 
       
   464   \end{center}
       
   465 
       
   466   \noindent where \isa{\isactrlbold {\isadigit{0}}} stands for the regular expression that does
       
   467   not match any string, \isa{\isactrlbold {\isadigit{1}}} for the regular expression that matches
       
   468   only the empty string and \isa{c} for matching a character literal. The
       
   469   language of a regular expression is also defined as usual by the
       
   470   recursive function \isa{L} with the six clauses:
       
   471 
       
   472   \begin{center}
       
   473   \begin{tabular}{l@ {\hspace{4mm}}rcl}
       
   474   \textit{(1)} & \isa{L{\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{0}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isasymemptyset}}\\
       
   475   \textit{(2)} & \isa{L{\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}\\
       
   476   \textit{(3)} & \isa{L{\isacharparenleft}{\kern0pt}c{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}c{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}\\
       
   477   \textit{(4)} & \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & 
       
   478         \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharat}{\kern0pt}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   479   \textit{(5)} & \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & 
       
   480         \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymunion}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   481   \textit{(6)} & \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isasymstar}}\\
       
   482   \end{tabular}
       
   483   \end{center}
       
   484   
       
   485   \noindent In clause \textit{(4)} we use the operation \isa{\underline{\hspace{2mm}}\ {\isacharat}{\kern0pt}\ \underline{\hspace{2mm}}} for the concatenation of two languages (it is also list-append for
       
   486   strings). We use the star-notation for regular expressions and for
       
   487   languages (in the last clause above). The star for languages is defined
       
   488   inductively by two clauses: \isa{{\isacharparenleft}{\kern0pt}i{\isacharparenright}{\kern0pt}} the empty string being in
       
   489   the star of a language and \isa{{\isacharparenleft}{\kern0pt}ii{\isacharparenright}{\kern0pt}} if \isa{s\isactrlsub {\isadigit{1}}} is in a
       
   490   language and \isa{s\isactrlsub {\isadigit{2}}} in the star of this language, then also \isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}} is in the star of this language. It will also be convenient
       
   491   to use the following notion of a \emph{semantic derivative} (or \emph{left
       
   492   quotient}) of a language defined as
       
   493   %
       
   494   \begin{center}
       
   495   \isa{Der\ c\ A\ {\isasymequiv}\ {\isacharbraceleft}{\kern0pt}s\ \mbox{\boldmath$\mid$}\ c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\ {\isasymin}\ A{\isacharbraceright}{\kern0pt}}\;.
       
   496   \end{center}
       
   497  
       
   498   \noindent
       
   499   For semantic derivatives we have the following equations (for example
       
   500   mechanically proved in \cite{Krauss2011}):
       
   501   %
       
   502   \begin{equation}\label{SemDer}
       
   503   \begin{array}{lcl}
       
   504   \isa{Der\ c\ {\isasymemptyset}}  & \dn & \isa{{\isasymemptyset}}\\
       
   505   \isa{Der\ c\ {\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}  & \dn & \isa{{\isasymemptyset}}\\
       
   506   \isa{Der\ c\ {\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}d{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}  & \dn & \isa{\textrm{if}\ c\ {\isacharequal}{\kern0pt}\ d\ \textrm{then}\ {\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ \textrm{else}\ {\isasymemptyset}}\\
       
   507   \isa{Der\ c\ {\isacharparenleft}{\kern0pt}A\ {\isasymunion}\ B{\isacharparenright}{\kern0pt}}  & \dn & \isa{Der\ c\ A\ {\isasymunion}\ Der\ c\ B}\\
       
   508   \isa{Der\ c\ {\isacharparenleft}{\kern0pt}A\ {\isacharat}{\kern0pt}\ B{\isacharparenright}{\kern0pt}}  & \dn & \isa{{\isacharparenleft}{\kern0pt}Der\ c\ A\ {\isacharat}{\kern0pt}\ B{\isacharparenright}{\kern0pt}\ {\isasymunion}\ {\isacharparenleft}{\kern0pt}\textrm{if}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymin}\ A\ \textrm{then}\ Der\ c\ B\ \textrm{else}\ {\isasymemptyset}{\isacharparenright}{\kern0pt}}\\
       
   509   \isa{Der\ c\ {\isacharparenleft}{\kern0pt}A{\isasymstar}{\isacharparenright}{\kern0pt}}  & \dn & \isa{Der\ c\ A\ {\isacharat}{\kern0pt}\ A{\isasymstar}}
       
   510   \end{array}
       
   511   \end{equation}
       
   512 
       
   513 
       
   514   \noindent \emph{\Brz's derivatives} of regular expressions
       
   515   \cite{Brzozowski1964} can be easily defined by two recursive functions:
       
   516   the first is from regular expressions to booleans (implementing a test
       
   517   when a regular expression can match the empty string), and the second
       
   518   takes a regular expression and a character to a (derivative) regular
       
   519   expression:
       
   520 
       
   521   \begin{center}
       
   522   \begin{tabular}{lcl}
       
   523   \isa{nullable\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{0}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{False}\\
       
   524   \isa{nullable\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{True}\\
       
   525   \isa{nullable\ {\isacharparenleft}{\kern0pt}c{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{False}\\
       
   526   \isa{nullable\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{nullable\ r\isactrlsub {\isadigit{1}}\ {\isasymor}\ nullable\ r\isactrlsub {\isadigit{2}}}\\
       
   527   \isa{nullable\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{nullable\ r\isactrlsub {\isadigit{1}}\ {\isasymand}\ nullable\ r\isactrlsub {\isadigit{2}}}\\
       
   528   \isa{nullable\ {\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{True}\medskip\\
       
   529 
       
   530 %  \end{tabular}
       
   531 %  \end{center}
       
   532 
       
   533 %  \begin{center}
       
   534 %  \begin{tabular}{lcl}
       
   535 
       
   536   \isa{\isactrlbold {\isadigit{0}}{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{\isactrlbold {\isadigit{0}}}\\
       
   537   \isa{\isactrlbold {\isadigit{1}}{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{\isactrlbold {\isadigit{0}}}\\
       
   538   \isa{d{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{\textrm{if}\ c\ {\isacharequal}{\kern0pt}\ d\ \textrm{then}\ \isactrlbold {\isadigit{1}}\ \textrm{else}\ \isactrlbold {\isadigit{0}}}\\
       
   539   \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}}\\
       
   540   \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{\textrm{if}\ nullable\ r\isactrlsub {\isadigit{1}}\ \textrm{then}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ \textrm{else}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}\\
       
   541   \isa{{\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsup {\isasymstar}}
       
   542   \end{tabular}
       
   543   \end{center}
       
   544  
       
   545   \noindent
       
   546   We may extend this definition to give derivatives w.r.t.~strings:
       
   547 
       
   548   \begin{center}
       
   549   \begin{tabular}{lcl}
       
   550   \isa{r{\isacharbackslash}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} & $\dn$ & \isa{r}\\
       
   551   \isa{r{\isacharbackslash}{\kern0pt}{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}s}\\
       
   552   \end{tabular}
       
   553   \end{center}
       
   554 
       
   555   \noindent Given the equations in \eqref{SemDer}, it is a relatively easy
       
   556   exercise in mechanical reasoning to establish that
       
   557 
       
   558   \begin{proposition}\label{derprop}\mbox{}\\ 
       
   559   \begin{tabular}{ll}
       
   560   \textit{(1)} & \isa{nullable\ r} if and only if
       
   561   \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}}, and \\ 
       
   562   \textit{(2)} & \isa{L{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ Der\ c\ {\isacharparenleft}{\kern0pt}L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}}.
       
   563   \end{tabular}
       
   564   \end{proposition}
       
   565 
       
   566   \noindent With this in place it is also very routine to prove that the
       
   567   regular expression matcher defined as
       
   568   %
       
   569   \begin{center}
       
   570   \isa{match\ r\ s\ {\isasymequiv}\ nullable\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}s{\isacharparenright}{\kern0pt}}
       
   571   \end{center}
       
   572 
       
   573   \noindent gives a positive answer if and only if \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}}.
       
   574   Consequently, this regular expression matching algorithm satisfies the
       
   575   usual specification for regular expression matching. While the matcher
       
   576   above calculates a provably correct YES/NO answer for whether a regular
       
   577   expression matches a string or not, the novel idea of Sulzmann and Lu
       
   578   \cite{Sulzmann2014} is to append another phase to this algorithm in order
       
   579   to calculate a [lexical] value. We will explain the details next.%
       
   580 \end{isamarkuptext}\isamarkuptrue%
       
   581 %
       
   582 \isadelimdocument
       
   583 %
       
   584 \endisadelimdocument
       
   585 %
       
   586 \isatagdocument
       
   587 %
       
   588 \isamarkupsection{POSIX Regular Expression Matching\label{posixsec}%
       
   589 }
       
   590 \isamarkuptrue%
       
   591 %
       
   592 \endisatagdocument
       
   593 {\isafolddocument}%
       
   594 %
       
   595 \isadelimdocument
       
   596 %
       
   597 \endisadelimdocument
       
   598 %
       
   599 \begin{isamarkuptext}%
       
   600 There have been many previous works that use values for encoding 
       
   601   \emph{how} a regular expression matches a string.
       
   602   The clever idea by Sulzmann and Lu \cite{Sulzmann2014} is to 
       
   603   define a function on values that mirrors (but inverts) the
       
   604   construction of the derivative on regular expressions. \emph{Values}
       
   605   are defined as the inductive datatype
       
   606 
       
   607   \begin{center}
       
   608   \isa{v\ {\isacharcolon}{\kern0pt}{\isacharequal}{\kern0pt}}
       
   609   \isa{Empty} $\mid$
       
   610   \isa{Char\ c} $\mid$
       
   611   \isa{Left\ v} $\mid$
       
   612   \isa{Right\ v} $\mid$
       
   613   \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} $\mid$ 
       
   614   \isa{Stars\ vs} 
       
   615   \end{center}  
       
   616 
       
   617   \noindent where we use \isa{vs} to stand for a list of
       
   618   values. (This is similar to the approach taken by Frisch and
       
   619   Cardelli for GREEDY matching \cite{Frisch2004}, and Sulzmann and Lu
       
   620   for POSIX matching \cite{Sulzmann2014}). The string underlying a
       
   621   value can be calculated by the \isa{flat} function, written
       
   622   \isa{{\isacharbar}{\kern0pt}\underline{\hspace{2mm}}{\isacharbar}{\kern0pt}} and defined as:
       
   623 
       
   624   \begin{center}
       
   625   \begin{tabular}[t]{lcl}
       
   626   \isa{{\isacharbar}{\kern0pt}Empty{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}\\
       
   627   \isa{{\isacharbar}{\kern0pt}Char\ c{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbrackleft}{\kern0pt}c{\isacharbrackright}{\kern0pt}}\\
       
   628   \isa{{\isacharbar}{\kern0pt}Left\ v{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}}\\
       
   629   \isa{{\isacharbar}{\kern0pt}Right\ v{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}}
       
   630   \end{tabular}\hspace{14mm}
       
   631   \begin{tabular}[t]{lcl}
       
   632   \isa{{\isacharbar}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharat}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}}\\
       
   633   \isa{{\isacharbar}{\kern0pt}Stars\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}\\
       
   634   \isa{{\isacharbar}{\kern0pt}Stars\ {\isacharparenleft}{\kern0pt}v\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs{\isacharparenright}{\kern0pt}{\isacharbar}{\kern0pt}} & $\dn$ & \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isacharat}{\kern0pt}\ {\isacharbar}{\kern0pt}Stars\ vs{\isacharbar}{\kern0pt}}\\
       
   635   \end{tabular}
       
   636   \end{center}
       
   637 
       
   638   \noindent We will sometimes refer to the underlying string of a
       
   639   value as \emph{flattened value}.  We will also overload our notation and 
       
   640   use \isa{{\isacharbar}{\kern0pt}vs{\isacharbar}{\kern0pt}} for flattening a list of values and concatenating
       
   641   the resulting strings.
       
   642   
       
   643   Sulzmann and Lu define
       
   644   inductively an \emph{inhabitation relation} that associates values to
       
   645   regular expressions. We define this relation as
       
   646   follows:\footnote{Note that the rule for \isa{Stars} differs from
       
   647   our earlier paper \cite{AusafDyckhoffUrban2016}. There we used the
       
   648   original definition by Sulzmann and Lu which does not require that
       
   649   the values \isa{v\ {\isasymin}\ vs} flatten to a non-empty
       
   650   string. The reason for introducing the more restricted version of
       
   651   lexical values is convenience later on when reasoning about an
       
   652   ordering relation for values.}
       
   653 
       
   654   \begin{center}
       
   655   \begin{tabular}{c@ {\hspace{12mm}}c}\label{prfintros}
       
   656   \\[-8mm]
       
   657   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{Empty\ {\isacharcolon}{\kern0pt}\ \isactrlbold {\isadigit{1}}}}} & 
       
   658   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{Char\ c\ {\isacharcolon}{\kern0pt}\ c}}}\\[4mm]
       
   659   \isa{\mbox{}\inferrule{\mbox{v\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}}{\mbox{Left\ v\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}}} &
       
   660   \isa{\mbox{}\inferrule{\mbox{v\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}}{\mbox{Right\ v\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{2}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}}}\\[4mm]
       
   661   \isa{\mbox{}\inferrule{\mbox{v\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}\\\ \mbox{v\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}}{\mbox{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}}}  &
       
   662   \isa{\mbox{}\inferrule{\mbox{{\isasymforall}v{\isasymin}vs{\isachardot}{\kern0pt}\ v\ {\isacharcolon}{\kern0pt}\ r\ {\isasymand}\ {\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}}{\mbox{Stars\ vs\ {\isacharcolon}{\kern0pt}\ r\isactrlsup {\isasymstar}}}}
       
   663   \end{tabular}
       
   664   \end{center}
       
   665 
       
   666   \noindent where in the clause for \isa{Stars} we use the
       
   667   notation \isa{v\ {\isasymin}\ vs} for indicating that \isa{v} is a
       
   668   member in the list \isa{vs}.  We require in this rule that every
       
   669   value in \isa{vs} flattens to a non-empty string. The idea is that
       
   670   \isa{Stars}-values satisfy the informal Star Rule (see Introduction)
       
   671   where the $^\star$ does not match the empty string unless this is
       
   672   the only match for the repetition.  Note also that no values are
       
   673   associated with the regular expression \isa{\isactrlbold {\isadigit{0}}}, and that the
       
   674   only value associated with the regular expression \isa{\isactrlbold {\isadigit{1}}} is
       
   675   \isa{Empty}.  It is routine to establish how values ``inhabiting''
       
   676   a regular expression correspond to the language of a regular
       
   677   expression, namely
       
   678 
       
   679   \begin{proposition}\label{inhabs}
       
   680   \isa{L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbraceleft}{\kern0pt}{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ \mbox{\boldmath$\mid$}\ v\ {\isacharcolon}{\kern0pt}\ r{\isacharbraceright}{\kern0pt}}
       
   681   \end{proposition}
       
   682 
       
   683   \noindent
       
   684   Given a regular expression \isa{r} and a string \isa{s}, we define the 
       
   685   set of all \emph{Lexical Values} inhabited by \isa{r} with the underlying string 
       
   686   being \isa{s}:\footnote{Okui and Suzuki refer to our lexical values 
       
   687   as \emph{canonical values} in \cite{OkuiSuzuki2010}. The notion of \emph{non-problematic
       
   688   values} by Cardelli and Frisch \cite{Frisch2004} is related, but not identical
       
   689   to our lexical values.}
       
   690   
       
   691   \begin{center}
       
   692   \isa{LV\ r\ s\ {\isasymequiv}\ {\isacharbraceleft}{\kern0pt}v\ \mbox{\boldmath$\mid$}\ v\ {\isacharcolon}{\kern0pt}\ r\ {\isasymand}\ {\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ s{\isacharbraceright}{\kern0pt}}
       
   693   \end{center}
       
   694 
       
   695   \noindent The main property of \isa{LV\ r\ s} is that it is alway finite.
       
   696 
       
   697   \begin{proposition}
       
   698   \isa{finite\ {\isacharparenleft}{\kern0pt}LV\ r\ s{\isacharparenright}{\kern0pt}}
       
   699   \end{proposition}
       
   700 
       
   701   \noindent This finiteness property does not hold in general if we
       
   702   remove the side-condition about \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} in the
       
   703   \isa{Stars}-rule above. For example using Sulzmann and Lu's
       
   704   less restrictive definition, \isa{LV\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} would contain
       
   705   infinitely many values, but according to our more restricted
       
   706   definition only a single value, namely \isa{LV\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbraceleft}{\kern0pt}Stars\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}.
       
   707 
       
   708   If a regular expression \isa{r} matches a string \isa{s}, then
       
   709   generally the set \isa{LV\ r\ s} is not just a singleton set.  In
       
   710   case of POSIX matching the problem is to calculate the unique lexical value
       
   711   that satisfies the (informal) POSIX rules from the Introduction.
       
   712   Graphically the POSIX value calculation algorithm by Sulzmann and Lu
       
   713   can be illustrated by the picture in Figure~\ref{Sulz} where the
       
   714   path from the left to the right involving \isa{derivatives}/\isa{nullable} is the first phase of the algorithm
       
   715   (calculating successive \Brz's derivatives) and \isa{mkeps}/\isa{inj}, the path from right to left, the second
       
   716   phase. This picture shows the steps required when a regular
       
   717   expression, say \isa{r\isactrlsub {\isadigit{1}}}, matches the string \isa{{\isacharbrackleft}{\kern0pt}a{\isacharcomma}{\kern0pt}\ b{\isacharcomma}{\kern0pt}\ c{\isacharbrackright}{\kern0pt}}. We first build the three derivatives (according to
       
   718   \isa{a}, \isa{b} and \isa{c}). We then use \isa{nullable}
       
   719   to find out whether the resulting derivative regular expression
       
   720   \isa{r\isactrlsub {\isadigit{4}}} can match the empty string. If yes, we call the
       
   721   function \isa{mkeps} that produces a value \isa{v\isactrlsub {\isadigit{4}}}
       
   722   for how \isa{r\isactrlsub {\isadigit{4}}} can match the empty string (taking into
       
   723   account the POSIX constraints in case there are several ways). This
       
   724   function is defined by the clauses:
       
   725 
       
   726 \begin{figure}[t]
       
   727 \begin{center}
       
   728 \begin{tikzpicture}[scale=2,node distance=1.3cm,
       
   729                     every node/.style={minimum size=6mm}]
       
   730 \node (r1)  {\isa{r\isactrlsub {\isadigit{1}}}};
       
   731 \node (r2) [right=of r1]{\isa{r\isactrlsub {\isadigit{2}}}};
       
   732 \draw[->,line width=1mm](r1)--(r2) node[above,midway] {\isa{\underline{\hspace{2mm}}{\isacharbackslash}{\kern0pt}a}};
       
   733 \node (r3) [right=of r2]{\isa{r\isactrlsub {\isadigit{3}}}};
       
   734 \draw[->,line width=1mm](r2)--(r3) node[above,midway] {\isa{\underline{\hspace{2mm}}{\isacharbackslash}{\kern0pt}b}};
       
   735 \node (r4) [right=of r3]{\isa{r\isactrlsub {\isadigit{4}}}};
       
   736 \draw[->,line width=1mm](r3)--(r4) node[above,midway] {\isa{\underline{\hspace{2mm}}{\isacharbackslash}{\kern0pt}c}};
       
   737 \draw (r4) node[anchor=west] {\;\raisebox{3mm}{\isa{nullable}}};
       
   738 \node (v4) [below=of r4]{\isa{v\isactrlsub {\isadigit{4}}}};
       
   739 \draw[->,line width=1mm](r4) -- (v4);
       
   740 \node (v3) [left=of v4] {\isa{v\isactrlsub {\isadigit{3}}}};
       
   741 \draw[->,line width=1mm](v4)--(v3) node[below,midway] {\isa{inj\ r\isactrlsub {\isadigit{3}}\ c}};
       
   742 \node (v2) [left=of v3]{\isa{v\isactrlsub {\isadigit{2}}}};
       
   743 \draw[->,line width=1mm](v3)--(v2) node[below,midway] {\isa{inj\ r\isactrlsub {\isadigit{2}}\ b}};
       
   744 \node (v1) [left=of v2] {\isa{v\isactrlsub {\isadigit{1}}}};
       
   745 \draw[->,line width=1mm](v2)--(v1) node[below,midway] {\isa{inj\ r\isactrlsub {\isadigit{1}}\ a}};
       
   746 \draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{\isa{mkeps}}};
       
   747 \end{tikzpicture}
       
   748 \end{center}
       
   749 \mbox{}\\[-13mm]
       
   750 
       
   751 \caption{The two phases of the algorithm by Sulzmann \& Lu \cite{Sulzmann2014},
       
   752 matching the string \isa{{\isacharbrackleft}{\kern0pt}a{\isacharcomma}{\kern0pt}\ b{\isacharcomma}{\kern0pt}\ c{\isacharbrackright}{\kern0pt}}. The first phase (the arrows from 
       
   753 left to right) is \Brz's matcher building successive derivatives. If the 
       
   754 last regular expression is \isa{nullable}, then the functions of the 
       
   755 second phase are called (the top-down and right-to-left arrows): first 
       
   756 \isa{mkeps} calculates a value \isa{v\isactrlsub {\isadigit{4}}} witnessing
       
   757 how the empty string has been recognised by \isa{r\isactrlsub {\isadigit{4}}}. After
       
   758 that the function \isa{inj} ``injects back'' the characters of the string into
       
   759 the values.
       
   760 \label{Sulz}}
       
   761 \end{figure} 
       
   762 
       
   763   \begin{center}
       
   764   \begin{tabular}{lcl}
       
   765   \isa{mkeps\ \isactrlbold {\isadigit{1}}} & $\dn$ & \isa{Empty}\\
       
   766   \isa{mkeps\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Seq\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   767   \isa{mkeps\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{\textrm{if}\ nullable\ r\isactrlsub {\isadigit{1}}\ \textrm{then}\ Left\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ \textrm{else}\ Right\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   768   \isa{mkeps\ {\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Stars\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}\\
       
   769   \end{tabular}
       
   770   \end{center}
       
   771 
       
   772   \noindent Note that this function needs only to be partially defined,
       
   773   namely only for regular expressions that are nullable. In case \isa{nullable} fails, the string \isa{{\isacharbrackleft}{\kern0pt}a{\isacharcomma}{\kern0pt}\ b{\isacharcomma}{\kern0pt}\ c{\isacharbrackright}{\kern0pt}} cannot be matched by \isa{r\isactrlsub {\isadigit{1}}} and the null value \isa{None} is returned. Note also how this function
       
   774   makes some subtle choices leading to a POSIX value: for example if an
       
   775   alternative regular expression, say \isa{r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}, can
       
   776   match the empty string and furthermore \isa{r\isactrlsub {\isadigit{1}}} can match the
       
   777   empty string, then we return a \isa{Left}-value. The \isa{Right}-value will only be returned if \isa{r\isactrlsub {\isadigit{1}}} cannot match the empty
       
   778   string.
       
   779 
       
   780   The most interesting idea from Sulzmann and Lu \cite{Sulzmann2014} is
       
   781   the construction of a value for how \isa{r\isactrlsub {\isadigit{1}}} can match the
       
   782   string \isa{{\isacharbrackleft}{\kern0pt}a{\isacharcomma}{\kern0pt}\ b{\isacharcomma}{\kern0pt}\ c{\isacharbrackright}{\kern0pt}} from the value how the last derivative, \isa{r\isactrlsub {\isadigit{4}}} in Fig.~\ref{Sulz}, can match the empty string. Sulzmann and
       
   783   Lu achieve this by stepwise ``injecting back'' the characters into the
       
   784   values thus inverting the operation of building derivatives, but on the level
       
   785   of values. The corresponding function, called \isa{inj}, takes three
       
   786   arguments, a regular expression, a character and a value. For example in
       
   787   the first (or right-most) \isa{inj}-step in Fig.~\ref{Sulz} the regular
       
   788   expression \isa{r\isactrlsub {\isadigit{3}}}, the character \isa{c} from the last
       
   789   derivative step and \isa{v\isactrlsub {\isadigit{4}}}, which is the value corresponding
       
   790   to the derivative regular expression \isa{r\isactrlsub {\isadigit{4}}}. The result is
       
   791   the new value \isa{v\isactrlsub {\isadigit{3}}}. The final result of the algorithm is
       
   792   the value \isa{v\isactrlsub {\isadigit{1}}}. The \isa{inj} function is defined by recursion on regular
       
   793   expressions and by analysing the shape of values (corresponding to 
       
   794   the derivative regular expressions).
       
   795   %
       
   796   \begin{center}
       
   797   \begin{tabular}{l@ {\hspace{5mm}}lcl}
       
   798   \textit{(1)} & \isa{inj\ d\ c\ {\isacharparenleft}{\kern0pt}Empty{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Char\ d}\\
       
   799   \textit{(2)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Left\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}} & $\dn$ & 
       
   800       \isa{Left\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}\\
       
   801   \textit{(3)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Right\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & 
       
   802       \isa{Right\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{2}}\ c\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   803   \textit{(4)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ 
       
   804       & \isa{Seq\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ v\isactrlsub {\isadigit{2}}}\\
       
   805   \textit{(5)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Left\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}} & $\dn$ 
       
   806       & \isa{Seq\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ v\isactrlsub {\isadigit{2}}}\\
       
   807   \textit{(6)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Right\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ 
       
   808       & \isa{Seq\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{2}}\ c\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
   809   \textit{(7)} & \isa{inj\ {\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Seq\ v\ {\isacharparenleft}{\kern0pt}Stars\ vs{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}} & $\dn$ 
       
   810       & \isa{Stars\ {\isacharparenleft}{\kern0pt}inj\ r\ c\ v\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs{\isacharparenright}{\kern0pt}}\\
       
   811   \end{tabular}
       
   812   \end{center}
       
   813 
       
   814   \noindent To better understand what is going on in this definition it
       
   815   might be instructive to look first at the three sequence cases (clauses
       
   816   \textit{(4)} -- \textit{(6)}). In each case we need to construct an ``injected value'' for
       
   817   \isa{r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}. This must be a value of the form \isa{Seq\ \underline{\hspace{2mm}}\ \underline{\hspace{2mm}}}\,. Recall the clause of the \isa{derivative}-function
       
   818   for sequence regular expressions:
       
   819 
       
   820   \begin{center}
       
   821   \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} $\dn$ \isa{\textrm{if}\ nullable\ r\isactrlsub {\isadigit{1}}\ \textrm{then}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ \textrm{else}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}
       
   822   \end{center}
       
   823 
       
   824   \noindent Consider first the \isa{else}-branch where the derivative is \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}. The corresponding value must therefore
       
   825   be of the form \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}}, which matches the left-hand
       
   826   side in clause~\textit{(4)} of \isa{inj}. In the \isa{if}-branch the derivative is an
       
   827   alternative, namely \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}}. This means we either have to consider a \isa{Left}- or
       
   828   \isa{Right}-value. In case of the \isa{Left}-value we know further it
       
   829   must be a value for a sequence regular expression. Therefore the pattern
       
   830   we match in the clause \textit{(5)} is \isa{Left\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}},
       
   831   while in \textit{(6)} it is just \isa{Right\ v\isactrlsub {\isadigit{2}}}. One more interesting
       
   832   point is in the right-hand side of clause \textit{(6)}: since in this case the
       
   833   regular expression \isa{r\isactrlsub {\isadigit{1}}} does not ``contribute'' to
       
   834   matching the string, that means it only matches the empty string, we need to
       
   835   call \isa{mkeps} in order to construct a value for how \isa{r\isactrlsub {\isadigit{1}}}
       
   836   can match this empty string. A similar argument applies for why we can
       
   837   expect in the left-hand side of clause \textit{(7)} that the value is of the form
       
   838   \isa{Seq\ v\ {\isacharparenleft}{\kern0pt}Stars\ vs{\isacharparenright}{\kern0pt}}---the derivative of a star is \isa{{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsup {\isasymstar}}. Finally, the reason for why we can ignore the second argument
       
   839   in clause \textit{(1)} of \isa{inj} is that it will only ever be called in cases
       
   840   where \isa{c\ {\isacharequal}{\kern0pt}\ d}, but the usual linearity restrictions in patterns do
       
   841   not allow us to build this constraint explicitly into our function
       
   842   definition.\footnote{Sulzmann and Lu state this clause as \isa{inj\ c\ c\ {\isacharparenleft}{\kern0pt}Empty{\isacharparenright}{\kern0pt}} $\dn$ \isa{Char\ c},
       
   843   but our deviation is harmless.}
       
   844 
       
   845   The idea of the \isa{inj}-function to ``inject'' a character, say
       
   846   \isa{c}, into a value can be made precise by the first part of the
       
   847   following lemma, which shows that the underlying string of an injected
       
   848   value has a prepended character \isa{c}; the second part shows that
       
   849   the underlying string of an \isa{mkeps}-value is always the empty
       
   850   string (given the regular expression is nullable since otherwise
       
   851   \isa{mkeps} might not be defined).
       
   852 
       
   853   \begin{lemma}\mbox{}\smallskip\\\label{Prf_injval_flat}
       
   854   \begin{tabular}{ll}
       
   855   (1) & \isa{{\normalsize{}If\,}\ v\ {\isacharcolon}{\kern0pt}\ r{\isacharbackslash}{\kern0pt}c\ {\normalsize \,then\,}\ {\isacharbar}{\kern0pt}inj\ r\ c\ v{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}{\isachardot}{\kern0pt}}\\
       
   856   (2) & \isa{{\normalsize{}If\,}\ nullable\ r\ {\normalsize \,then\,}\ {\isacharbar}{\kern0pt}mkeps\ r{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isachardot}{\kern0pt}}
       
   857   \end{tabular}
       
   858   \end{lemma}
       
   859 
       
   860   \begin{proof}
       
   861   Both properties are by routine inductions: the first one can, for example,
       
   862   be proved by induction over the definition of \isa{derivatives}; the second by
       
   863   an induction on \isa{r}. There are no interesting cases.\qed
       
   864   \end{proof}
       
   865 
       
   866   Having defined the \isa{mkeps} and \isa{inj} function we can extend
       
   867   \Brz's matcher so that a value is constructed (assuming the
       
   868   regular expression matches the string). The clauses of the Sulzmann and Lu lexer are
       
   869 
       
   870   \begin{center}
       
   871   \begin{tabular}{lcl}
       
   872   \isa{lexer\ r\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} & $\dn$ & \isa{\textrm{if}\ nullable\ r\ \textrm{then}\ Some\ {\isacharparenleft}{\kern0pt}mkeps\ r{\isacharparenright}{\kern0pt}\ \textrm{else}\ None}\\
       
   873   \isa{lexer\ r\ {\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{case} \isa{lexer\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ s} \isa{of}\\
       
   874                      & & \phantom{$|$} \isa{None}  \isa{{\isasymRightarrow}} \isa{None}\\
       
   875                      & & $|$ \isa{Some\ v} \isa{{\isasymRightarrow}} \isa{Some\ {\isacharparenleft}{\kern0pt}inj\ r\ c\ v{\isacharparenright}{\kern0pt}}                          
       
   876   \end{tabular}
       
   877   \end{center}
       
   878 
       
   879   \noindent If the regular expression does not match the string, \isa{None} is
       
   880   returned. If the regular expression \emph{does}
       
   881   match the string, then \isa{Some} value is returned. One important
       
   882   virtue of this algorithm is that it can be implemented with ease in any
       
   883   functional programming language and also in Isabelle/HOL. In the remaining
       
   884   part of this section we prove that this algorithm is correct.
       
   885 
       
   886   The well-known idea of POSIX matching is informally defined by some
       
   887   rules such as the Longest Match and Priority Rules (see
       
   888   Introduction); as correctly argued in \cite{Sulzmann2014}, this
       
   889   needs formal specification. Sulzmann and Lu define an ``ordering
       
   890   relation'' between values and argue that there is a maximum value,
       
   891   as given by the derivative-based algorithm.  In contrast, we shall
       
   892   introduce a simple inductive definition that specifies directly what
       
   893   a \emph{POSIX value} is, incorporating the POSIX-specific choices
       
   894   into the side-conditions of our rules. Our definition is inspired by
       
   895   the matching relation given by Vansummeren~\cite{Vansummeren2006}. 
       
   896   The relation we define is ternary and
       
   897   written as \mbox{\isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}}, relating
       
   898   strings, regular expressions and values; the inductive rules are given in 
       
   899   Figure~\ref{POSIXrules}.
       
   900   We can prove that given a string \isa{s} and regular expression \isa{r}, the POSIX value \isa{v} is uniquely determined by \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}.
       
   901 
       
   902   %
       
   903   \begin{figure}[t]
       
   904   \begin{center}
       
   905   \begin{tabular}{c}
       
   906   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{{\isacharparenleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharcomma}{\kern0pt}\ \isactrlbold {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Empty}}}\isa{P}\isa{\isactrlbold {\isadigit{1}}} \qquad
       
   907   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{{\isacharparenleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}c{\isacharbrackright}{\kern0pt}{\isacharcomma}{\kern0pt}\ c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Char\ c}}}\isa{P}\isa{c}\medskip\\
       
   908   \isa{\mbox{}\inferrule{\mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}}{\mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Left\ v}}}\isa{P{\isacharplus}{\kern0pt}L}\qquad
       
   909   \isa{\mbox{}\inferrule{\mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}\\\ \mbox{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}}{\mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Right\ v}}}\isa{P{\isacharplus}{\kern0pt}R}\medskip\\
       
   910   $\mprset{flushleft}
       
   911    \inferrule
       
   912    {\isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}} \qquad
       
   913     \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{2}}} \\\\
       
   914     \isa{{\isasymnexists}s\isactrlsub {\isadigit{3}}\ s\isactrlsub {\isadigit{4}}{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{4}}\ {\isacharequal}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isasymand}\ s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{4}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}}
       
   915    {\isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}}}$\isa{PS}\\
       
   916   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{{\isacharparenleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharcomma}{\kern0pt}\ r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Stars\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}}}\isa{P{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}\medskip\\
       
   917   $\mprset{flushleft}
       
   918    \inferrule
       
   919    {\isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v} \qquad
       
   920     \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Stars\ vs} \qquad
       
   921     \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} \\\\
       
   922     \isa{{\isasymnexists}s\isactrlsub {\isadigit{3}}\ s\isactrlsub {\isadigit{4}}{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{4}}\ {\isacharequal}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isasymand}\ s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{4}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}}}
       
   923    {\isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Stars\ {\isacharparenleft}{\kern0pt}v\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs{\isacharparenright}{\kern0pt}}}$\isa{P{\isasymstar}}
       
   924   \end{tabular}
       
   925   \end{center}
       
   926   \caption{Our inductive definition of POSIX values.}\label{POSIXrules}
       
   927   \end{figure}
       
   928 
       
   929    
       
   930 
       
   931   \begin{theorem}\mbox{}\smallskip\\\label{posixdeterm}
       
   932   \begin{tabular}{ll}
       
   933   (1) & If \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v} then \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}} and \isa{{\isacharbar}{\kern0pt}v{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ s}.\\
       
   934   (2) & \isa{{\normalsize{}If\,}\ \mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}\ {\normalsize \,and\,}\ \mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}}\ {\normalsize \,then\,}\ v\ {\isacharequal}{\kern0pt}\ v{\isacharprime}{\kern0pt}{\isachardot}{\kern0pt}}
       
   935   \end{tabular}
       
   936   \end{theorem}
       
   937 
       
   938   \begin{proof} Both by induction on the definition of \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}. 
       
   939   The second parts follows by a case analysis of \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}} and
       
   940   the first part.\qed
       
   941   \end{proof}
       
   942 
       
   943   \noindent
       
   944   We claim that our \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v} relation captures the idea behind the four
       
   945   informal POSIX rules shown in the Introduction: Consider for example the
       
   946   rules \isa{P{\isacharplus}{\kern0pt}L} and \isa{P{\isacharplus}{\kern0pt}R} where the POSIX value for a string
       
   947   and an alternative regular expression, that is \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}},
       
   948   is specified---it is always a \isa{Left}-value, \emph{except} when the
       
   949   string to be matched is not in the language of \isa{r\isactrlsub {\isadigit{1}}}; only then it
       
   950   is a \isa{Right}-value (see the side-condition in \isa{P{\isacharplus}{\kern0pt}R}).
       
   951   Interesting is also the rule for sequence regular expressions (\isa{PS}). The first two premises state that \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}}
       
   952   are the POSIX values for \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}} and \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}
       
   953   respectively. Consider now the third premise and note that the POSIX value
       
   954   of this rule should match the string \mbox{\isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}}}. According to the
       
   955   Longest Match Rule, we want that the \isa{s\isactrlsub {\isadigit{1}}} is the longest initial
       
   956   split of \mbox{\isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}}} such that \isa{s\isactrlsub {\isadigit{2}}} is still recognised
       
   957   by \isa{r\isactrlsub {\isadigit{2}}}. Let us assume, contrary to the third premise, that there
       
   958   \emph{exist} an \isa{s\isactrlsub {\isadigit{3}}} and \isa{s\isactrlsub {\isadigit{4}}} such that \isa{s\isactrlsub {\isadigit{2}}}
       
   959   can be split up into a non-empty string \isa{s\isactrlsub {\isadigit{3}}} and a possibly empty
       
   960   string \isa{s\isactrlsub {\isadigit{4}}}. Moreover the longer string \isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{3}}} can be
       
   961   matched by \isa{r\isactrlsub {\isadigit{1}}} and the shorter \isa{s\isactrlsub {\isadigit{4}}} can still be
       
   962   matched by \isa{r\isactrlsub {\isadigit{2}}}. In this case \isa{s\isactrlsub {\isadigit{1}}} would \emph{not} be the
       
   963   longest initial split of \mbox{\isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}}} and therefore \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} cannot be a POSIX value for \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}. 
       
   964   The main point is that our side-condition ensures the Longest 
       
   965   Match Rule is satisfied.
       
   966 
       
   967   A similar condition is imposed on the POSIX value in the \isa{P{\isasymstar}}-rule. Also there we want that \isa{s\isactrlsub {\isadigit{1}}} is the longest initial
       
   968   split of \isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}} and furthermore the corresponding value
       
   969   \isa{v} cannot be flattened to the empty string. In effect, we require
       
   970   that in each ``iteration'' of the star, some non-empty substring needs to
       
   971   be ``chipped'' away; only in case of the empty string we accept \isa{Stars\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} as the POSIX value. Indeed we can show that our POSIX values
       
   972   are lexical values which exclude those \isa{Stars} that contain subvalues 
       
   973   that flatten to the empty string.
       
   974 
       
   975   \begin{lemma}\label{LVposix}
       
   976   \isa{{\normalsize{}If\,}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\ {\normalsize \,then\,}\ v\ {\isasymin}\ LV\ r\ s{\isachardot}{\kern0pt}}
       
   977   \end{lemma}
       
   978 
       
   979   \begin{proof}
       
   980   By routine induction on \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}.\qed 
       
   981   \end{proof}
       
   982 
       
   983   \noindent
       
   984   Next is the lemma that shows the function \isa{mkeps} calculates
       
   985   the POSIX value for the empty string and a nullable regular expression.
       
   986 
       
   987   \begin{lemma}\label{lemmkeps}
       
   988   \isa{{\normalsize{}If\,}\ nullable\ r\ {\normalsize \,then\,}\ {\isacharparenleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ mkeps\ r{\isachardot}{\kern0pt}}
       
   989   \end{lemma}
       
   990 
       
   991   \begin{proof}
       
   992   By routine induction on \isa{r}.\qed 
       
   993   \end{proof}
       
   994 
       
   995   \noindent
       
   996   The central lemma for our POSIX relation is that the \isa{inj}-function
       
   997   preserves POSIX values.
       
   998 
       
   999   \begin{lemma}\label{Posix2}
       
  1000   \isa{{\normalsize{}If\,}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\ {\normalsize \,then\,}\ {\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ r\ c\ v{\isachardot}{\kern0pt}}
       
  1001   \end{lemma}
       
  1002 
       
  1003   \begin{proof}
       
  1004   By induction on \isa{r}. We explain two cases.
       
  1005 
       
  1006   \begin{itemize}
       
  1007   \item[$\bullet$] Case \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}. There are
       
  1008   two subcases, namely \isa{{\isacharparenleft}{\kern0pt}a{\isacharparenright}{\kern0pt}} \mbox{\isa{v\ {\isacharequal}{\kern0pt}\ Left\ v{\isacharprime}{\kern0pt}}} and \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}}; and \isa{{\isacharparenleft}{\kern0pt}b{\isacharparenright}{\kern0pt}} \isa{v\ {\isacharequal}{\kern0pt}\ Right\ v{\isacharprime}{\kern0pt}}, \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}} and \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}}. In \isa{{\isacharparenleft}{\kern0pt}a{\isacharparenright}{\kern0pt}} we
       
  1009   know \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}}, from which we can infer \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ r\isactrlsub {\isadigit{1}}\ c\ v{\isacharprime}{\kern0pt}} by induction hypothesis and hence \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ c\ {\isacharparenleft}{\kern0pt}Left\ v{\isacharprime}{\kern0pt}{\isacharparenright}{\kern0pt}} as needed. Similarly
       
  1010   in subcase \isa{{\isacharparenleft}{\kern0pt}b{\isacharparenright}{\kern0pt}} where, however, in addition we have to use
       
  1011   Proposition~\ref{derprop}(2) in order to infer \isa{c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}} from \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}}.\smallskip
       
  1012 
       
  1013   \item[$\bullet$] Case \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}}. There are three subcases:
       
  1014   
       
  1015   \begin{quote}
       
  1016   \begin{description}
       
  1017   \item[\isa{{\isacharparenleft}{\kern0pt}a{\isacharparenright}{\kern0pt}}] \isa{v\ {\isacharequal}{\kern0pt}\ Left\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} and \isa{nullable\ r\isactrlsub {\isadigit{1}}} 
       
  1018   \item[\isa{{\isacharparenleft}{\kern0pt}b{\isacharparenright}{\kern0pt}}] \isa{v\ {\isacharequal}{\kern0pt}\ Right\ v\isactrlsub {\isadigit{1}}} and \isa{nullable\ r\isactrlsub {\isadigit{1}}} 
       
  1019   \item[\isa{{\isacharparenleft}{\kern0pt}c{\isacharparenright}{\kern0pt}}] \isa{v\ {\isacharequal}{\kern0pt}\ Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} and \isa{{\isasymnot}\ nullable\ r\isactrlsub {\isadigit{1}}} 
       
  1020   \end{description}
       
  1021   \end{quote}
       
  1022 
       
  1023   \noindent For \isa{{\isacharparenleft}{\kern0pt}a{\isacharparenright}{\kern0pt}} we know \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}} and
       
  1024   \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{2}}} as well as
       
  1025   %
       
  1026   \[\isa{{\isasymnexists}s\isactrlsub {\isadigit{3}}\ s\isactrlsub {\isadigit{4}}{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{4}}\ {\isacharequal}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isasymand}\ s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{4}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\]
       
  1027 
       
  1028   \noindent From the latter we can infer by Proposition~\ref{derprop}(2):
       
  1029   %
       
  1030   \[\isa{{\isasymnexists}s\isactrlsub {\isadigit{3}}\ s\isactrlsub {\isadigit{4}}{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{4}}\ {\isacharequal}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isasymand}\ c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{4}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\]
       
  1031 
       
  1032   \noindent We can use the induction hypothesis for \isa{r\isactrlsub {\isadigit{1}}} to obtain
       
  1033   \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}}. Putting this all together allows us to infer
       
  1034   \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Seq\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ v\isactrlsub {\isadigit{2}}}. The case \isa{{\isacharparenleft}{\kern0pt}c{\isacharparenright}{\kern0pt}}
       
  1035   is similar.
       
  1036 
       
  1037   For \isa{{\isacharparenleft}{\kern0pt}b{\isacharparenright}{\kern0pt}} we know \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}} and 
       
  1038   \isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}. From the former
       
  1039   we have \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ r\isactrlsub {\isadigit{2}}\ c\ v\isactrlsub {\isadigit{1}}} by induction hypothesis
       
  1040   for \isa{r\isactrlsub {\isadigit{2}}}. From the latter we can infer
       
  1041   %
       
  1042   \[\isa{{\isasymnexists}s\isactrlsub {\isadigit{3}}\ s\isactrlsub {\isadigit{4}}{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ s\isactrlsub {\isadigit{3}}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{4}}\ {\isacharequal}{\kern0pt}\ c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\ {\isasymand}\ s\isactrlsub {\isadigit{3}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymand}\ s\isactrlsub {\isadigit{4}}\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\]
       
  1043 
       
  1044   \noindent By Lemma~\ref{lemmkeps} we know \isa{{\isacharparenleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ mkeps\ r\isactrlsub {\isadigit{1}}}
       
  1045   holds. Putting this all together, we can conclude with \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Seq\ {\isacharparenleft}{\kern0pt}mkeps\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}inj\ r\isactrlsub {\isadigit{2}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}, as required.
       
  1046 
       
  1047   Finally suppose \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\isactrlsup {\isasymstar}}. This case is very similar to the
       
  1048   sequence case, except that we need to also ensure that \isa{{\isacharbar}{\kern0pt}inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isasymnoteq}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}. This follows from \isa{{\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ inj\ r\isactrlsub {\isadigit{1}}\ c\ v\isactrlsub {\isadigit{1}}}  (which in turn follows from \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}} and the induction hypothesis).\qed
       
  1049   \end{itemize}
       
  1050   \end{proof}
       
  1051 
       
  1052   \noindent
       
  1053   With Lemma~\ref{Posix2} in place, it is completely routine to establish
       
  1054   that the Sulzmann and Lu lexer satisfies our specification (returning
       
  1055   the null value \isa{None} iff the string is not in the language of the regular expression,
       
  1056   and returning a unique POSIX value iff the string \emph{is} in the language):
       
  1057 
       
  1058   \begin{theorem}\mbox{}\smallskip\\\label{lexercorrect}
       
  1059   \begin{tabular}{ll}
       
  1060   (1) & \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}} if and only if \isa{lexer\ r\ s\ {\isacharequal}{\kern0pt}\ None}\\
       
  1061   (2) & \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}} if and only if \isa{{\isasymexists}v{\isachardot}{\kern0pt}\ lexer\ r\ s\ {\isacharequal}{\kern0pt}\ Some\ v\ {\isasymand}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}\\
       
  1062   \end{tabular}
       
  1063   \end{theorem}
       
  1064 
       
  1065   \begin{proof}
       
  1066   By induction on \isa{s} using Lemma~\ref{lemmkeps} and \ref{Posix2}.\qed  
       
  1067   \end{proof}
       
  1068 
       
  1069   \noindent In \textit{(2)} we further know by Theorem~\ref{posixdeterm} that the
       
  1070   value returned by the lexer must be unique.   A simple corollary 
       
  1071   of our two theorems is:
       
  1072 
       
  1073   \begin{corollary}\mbox{}\smallskip\\\label{lexercorrectcor}
       
  1074   \begin{tabular}{ll}
       
  1075   (1) & \isa{lexer\ r\ s\ {\isacharequal}{\kern0pt}\ None} if and only if \isa{{\isasymnexists}v{\isachardot}{\kern0pt}a{\isachardot}{\kern0pt}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}\\ 
       
  1076   (2) & \isa{lexer\ r\ s\ {\isacharequal}{\kern0pt}\ Some\ v} if and only if \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}\\
       
  1077   \end{tabular}
       
  1078   \end{corollary}
       
  1079 
       
  1080   \noindent This concludes our correctness proof. Note that we have
       
  1081   not changed the algorithm of Sulzmann and Lu,\footnote{All
       
  1082   deviations we introduced are harmless.} but introduced our own
       
  1083   specification for what a correct result---a POSIX value---should be.
       
  1084   In the next section we show that our specification coincides with
       
  1085   another one given by Okui and Suzuki using a different technique.%
       
  1086 \end{isamarkuptext}\isamarkuptrue%
       
  1087 %
       
  1088 \isadelimdocument
       
  1089 %
       
  1090 \endisadelimdocument
       
  1091 %
       
  1092 \isatagdocument
       
  1093 %
       
  1094 \isamarkupsection{Ordering of Values according to Okui and Suzuki%
       
  1095 }
       
  1096 \isamarkuptrue%
       
  1097 %
       
  1098 \endisatagdocument
       
  1099 {\isafolddocument}%
       
  1100 %
       
  1101 \isadelimdocument
       
  1102 %
       
  1103 \endisadelimdocument
       
  1104 %
       
  1105 \begin{isamarkuptext}%
       
  1106 While in the previous section we have defined POSIX values directly
       
  1107   in terms of a ternary relation (see inference rules in Figure~\ref{POSIXrules}),
       
  1108   Sulzmann and Lu took a different approach in \cite{Sulzmann2014}:
       
  1109   they introduced an ordering for values and identified POSIX values
       
  1110   as the maximal elements.  An extended version of \cite{Sulzmann2014}
       
  1111   is available at the website of its first author; this includes more
       
  1112   details of their proofs, but which are evidently not in final form
       
  1113   yet. Unfortunately, we were not able to verify claims that their
       
  1114   ordering has properties such as being transitive or having maximal
       
  1115   elements. 
       
  1116  
       
  1117   Okui and Suzuki \cite{OkuiSuzuki2010,OkuiSuzukiTech} described
       
  1118   another ordering of values, which they use to establish the
       
  1119   correctness of their automata-based algorithm for POSIX matching.
       
  1120   Their ordering resembles some aspects of the one given by Sulzmann
       
  1121   and Lu, but overall is quite different. To begin with, Okui and
       
  1122   Suzuki identify POSIX values as minimal, rather than maximal,
       
  1123   elements in their ordering. A more substantial difference is that
       
  1124   the ordering by Okui and Suzuki uses \emph{positions} in order to
       
  1125   identify and compare subvalues. Positions are lists of natural
       
  1126   numbers. This allows them to quite naturally formalise the Longest
       
  1127   Match and Priority rules of the informal POSIX standard.  Consider
       
  1128   for example the value \isa{v}
       
  1129 
       
  1130   \begin{center}
       
  1131   \isa{v\ {\isasymequiv}\ Stars\ {\isacharbrackleft}{\kern0pt}Seq\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}Char\ y{\isacharparenright}{\kern0pt}{\isacharcomma}{\kern0pt}\ Char\ z{\isacharbrackright}{\kern0pt}}
       
  1132   \end{center}
       
  1133 
       
  1134   \noindent
       
  1135   At position \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{0}}{\isacharcomma}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}} of this value is the
       
  1136   subvalue \isa{Char\ y} and at position \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}} the
       
  1137   subvalue \isa{Char\ z}.  At the `root' position, or empty list
       
  1138   \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}}, is the whole value \isa{v}. Positions such as \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{0}}{\isacharcomma}{\kern0pt}{\isadigit{1}}{\isacharcomma}{\kern0pt}{\isadigit{0}}{\isacharbrackright}{\kern0pt}} or \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{2}}{\isacharbrackright}{\kern0pt}} are outside of \isa{v}. If it exists, the subvalue of \isa{v} at a position \isa{p}, written \isa{v\mbox{$\downharpoonleft$}\isactrlbsub p\isactrlesub }, can be recursively defined by
       
  1139   
       
  1140   \begin{center}
       
  1141   \begin{tabular}{r@ {\hspace{0mm}}lcl}
       
  1142   \isa{v} &  \isa{{\isasymdownharpoonleft}\isactrlbsub {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\isactrlesub } & \isa{{\isasymequiv}}& \isa{v}\\
       
  1143   \isa{Left\ v} & \isa{{\isasymdownharpoonleft}\isactrlbsub {\isadigit{0}}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}ps\isactrlesub } & \isa{{\isasymequiv}}& \isa{v\mbox{$\downharpoonleft$}\isactrlbsub ps\isactrlesub }\\
       
  1144   \isa{Right\ v} & \isa{{\isasymdownharpoonleft}\isactrlbsub {\isadigit{1}}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}ps\isactrlesub } & \isa{{\isasymequiv}} & 
       
  1145   \isa{v\mbox{$\downharpoonleft$}\isactrlbsub ps\isactrlesub }\\
       
  1146   \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} & \isa{{\isasymdownharpoonleft}\isactrlbsub {\isadigit{0}}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}ps\isactrlesub } & \isa{{\isasymequiv}} & 
       
  1147   \isa{v\isactrlsub {\isadigit{1}}\mbox{$\downharpoonleft$}\isactrlbsub ps\isactrlesub } \\
       
  1148   \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} & \isa{{\isasymdownharpoonleft}\isactrlbsub {\isadigit{1}}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}ps\isactrlesub }
       
  1149   & \isa{{\isasymequiv}} & 
       
  1150   \isa{v\isactrlsub {\isadigit{2}}\mbox{$\downharpoonleft$}\isactrlbsub ps\isactrlesub } \\
       
  1151   \isa{Stars\ vs} & \isa{{\isasymdownharpoonleft}\isactrlbsub n{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}ps\isactrlesub } & \isa{{\isasymequiv}}& \isa{vs\ensuremath{_{[\mathit{n}]}}\mbox{$\downharpoonleft$}\isactrlbsub ps\isactrlesub }\\
       
  1152   \end{tabular} 
       
  1153   \end{center}
       
  1154 
       
  1155   \noindent In the last clause we use Isabelle's notation \isa{vs\ensuremath{_{[\mathit{n}]}}} for the
       
  1156   \isa{n}th element in a list.  The set of positions inside a value \isa{v},
       
  1157   written \isa{Pos\ v}, is given by 
       
  1158 
       
  1159   \begin{center}
       
  1160   \begin{tabular}{lcl}
       
  1161   \isa{Pos\ {\isacharparenleft}{\kern0pt}Empty{\isacharparenright}{\kern0pt}} & \isa{{\isasymequiv}} & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}\\
       
  1162   \isa{Pos\ {\isacharparenleft}{\kern0pt}Char\ c{\isacharparenright}{\kern0pt}} & \isa{{\isasymequiv}} & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}}\\
       
  1163   \isa{Pos\ {\isacharparenleft}{\kern0pt}Left\ v{\isacharparenright}{\kern0pt}} & \isa{{\isasymequiv}} & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymunion}\ {\isacharbraceleft}{\kern0pt}{\isadigit{0}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\ \mbox{\boldmath$\mid$}\ ps\ {\isasymin}\ Pos\ v{\isacharbraceright}{\kern0pt}}\\
       
  1164   \isa{Pos\ {\isacharparenleft}{\kern0pt}Right\ v{\isacharparenright}{\kern0pt}} & \isa{{\isasymequiv}} & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymunion}\ {\isacharbraceleft}{\kern0pt}{\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\ \mbox{\boldmath$\mid$}\ ps\ {\isasymin}\ Pos\ v{\isacharbraceright}{\kern0pt}}\\
       
  1165   \isa{Pos\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}
       
  1166   & \isa{{\isasymequiv}} 
       
  1167   & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymunion}\ {\isacharbraceleft}{\kern0pt}{\isadigit{0}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\ \mbox{\boldmath$\mid$}\ ps\ {\isasymin}\ Pos\ v\isactrlsub {\isadigit{1}}{\isacharbraceright}{\kern0pt}\ {\isasymunion}\ {\isacharbraceleft}{\kern0pt}{\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\ \mbox{\boldmath$\mid$}\ ps\ {\isasymin}\ Pos\ v\isactrlsub {\isadigit{2}}{\isacharbraceright}{\kern0pt}}\\
       
  1168   \isa{Pos\ {\isacharparenleft}{\kern0pt}Stars\ vs{\isacharparenright}{\kern0pt}} & \isa{{\isasymequiv}} & \isa{{\isacharbraceleft}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymunion}\ {\isacharparenleft}{\kern0pt}{\isasymUnion}n\ {\isacharless}{\kern0pt}\ len\ vs\ {\isacharbraceleft}{\kern0pt}n\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\ \mbox{\boldmath$\mid$}\ ps\ {\isasymin}\ Pos\ vs\ensuremath{_{[\mathit{n}]}}{\isacharbraceright}{\kern0pt}{\isacharparenright}{\kern0pt}}\\
       
  1169   \end{tabular}
       
  1170   \end{center}
       
  1171 
       
  1172   \noindent 
       
  1173   whereby \isa{len} in the last clause stands for the length of a list. Clearly
       
  1174   for every position inside a value there exists a subvalue at that position.
       
  1175  
       
  1176 
       
  1177   To help understanding the ordering of Okui and Suzuki, consider again 
       
  1178   the earlier value
       
  1179   \isa{v} and compare it with the following \isa{w}:
       
  1180 
       
  1181   \begin{center}
       
  1182   \begin{tabular}{l}
       
  1183   \isa{v\ {\isasymequiv}\ Stars\ {\isacharbrackleft}{\kern0pt}Seq\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}Char\ y{\isacharparenright}{\kern0pt}{\isacharcomma}{\kern0pt}\ Char\ z{\isacharbrackright}{\kern0pt}}\\
       
  1184   \isa{w\ {\isasymequiv}\ Stars\ {\isacharbrackleft}{\kern0pt}Char\ x{\isacharcomma}{\kern0pt}\ Char\ y{\isacharcomma}{\kern0pt}\ Char\ z{\isacharbrackright}{\kern0pt}}  
       
  1185   \end{tabular}
       
  1186   \end{center}
       
  1187 
       
  1188   \noindent Both values match the string \isa{xyz}, that means if
       
  1189   we flatten these values at their respective root position, we obtain
       
  1190   \isa{xyz}. However, at position \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{0}}{\isacharbrackright}{\kern0pt}}, \isa{v} matches
       
  1191   \isa{xy} whereas \isa{w} matches only the shorter \isa{x}. So
       
  1192   according to the Longest Match Rule, we should prefer \isa{v},
       
  1193   rather than \isa{w} as POSIX value for string \isa{xyz} (and
       
  1194   corresponding regular expression). In order to
       
  1195   formalise this idea, Okui and Suzuki introduce a measure for
       
  1196   subvalues at position \isa{p}, called the \emph{norm} of \isa{v}
       
  1197   at position \isa{p}. We can define this measure in Isabelle as an
       
  1198   integer as follows
       
  1199   
       
  1200   \begin{center}
       
  1201   \isa{{\isasymparallel}v{\isasymparallel}\isactrlbsub p\isactrlesub \ {\isasymequiv}\ \textrm{if}\ p\ {\isasymin}\ Pos\ v\ \textrm{then}\ len\ {\isacharbar}{\kern0pt}v\mbox{$\downharpoonleft$}\isactrlbsub p\isactrlesub {\isacharbar}{\kern0pt}\ \textrm{else}\ {\isacharminus}{\kern0pt}\ {\isadigit{1}}}
       
  1202   \end{center}
       
  1203 
       
  1204   \noindent where we take the length of the flattened value at
       
  1205   position \isa{p}, provided the position is inside \isa{v}; if
       
  1206   not, then the norm is \isa{{\isacharminus}{\kern0pt}{\isadigit{1}}}. The default for outside
       
  1207   positions is crucial for the POSIX requirement of preferring a
       
  1208   \isa{Left}-value over a \isa{Right}-value (if they can match the
       
  1209   same string---see the Priority Rule from the Introduction). For this
       
  1210   consider
       
  1211 
       
  1212   \begin{center}
       
  1213   \isa{v\ {\isasymequiv}\ Left\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}} \qquad and \qquad \isa{w\ {\isasymequiv}\ Right\ {\isacharparenleft}{\kern0pt}Char\ x{\isacharparenright}{\kern0pt}}
       
  1214   \end{center}
       
  1215 
       
  1216   \noindent Both values match \isa{x}. At position \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{0}}{\isacharbrackright}{\kern0pt}}
       
  1217   the norm of \isa{v} is \isa{{\isadigit{1}}} (the subvalue matches \isa{x}),
       
  1218   but the norm of \isa{w} is \isa{{\isacharminus}{\kern0pt}{\isadigit{1}}} (the position is outside
       
  1219   \isa{w} according to how we defined the `inside' positions of
       
  1220   \isa{Left}- and \isa{Right}-values).  Of course at position
       
  1221   \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}}, the norms \isa{{\isasymparallel}v{\isasymparallel}\isactrlbsub {\isacharbrackleft}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}\isactrlesub } and \isa{{\isasymparallel}w{\isasymparallel}\isactrlbsub {\isacharbrackleft}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}\isactrlesub } are reversed, but the point is that subvalues
       
  1222   will be analysed according to lexicographically ordered
       
  1223   positions. According to this ordering, the position \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{0}}{\isacharbrackright}{\kern0pt}}
       
  1224   takes precedence over \isa{{\isacharbrackleft}{\kern0pt}{\isadigit{1}}{\isacharbrackright}{\kern0pt}} and thus also \isa{v} will be 
       
  1225   preferred over \isa{w}.  The lexicographic ordering of positions, written
       
  1226   \isa{\underline{\hspace{2mm}}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ \underline{\hspace{2mm}}}, can be conveniently formalised
       
  1227   by three inference rules
       
  1228 
       
  1229   \begin{center}
       
  1230   \begin{tabular}{ccc}
       
  1231   \isa{\mbox{}\inferrule{\mbox{}}{\mbox{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps}}}\hspace{1cm} &
       
  1232   \isa{\mbox{}\inferrule{\mbox{p\isactrlsub {\isadigit{1}}\ {\isacharless}{\kern0pt}\ p\isactrlsub {\isadigit{2}}}}{\mbox{p\isactrlsub {\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p\isactrlsub {\isadigit{2}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\isactrlsub {\isadigit{2}}}}}\hspace{1cm} &
       
  1233   \isa{\mbox{}\inferrule{\mbox{ps\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ ps\isactrlsub {\isadigit{2}}}}{\mbox{p\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}ps\isactrlsub {\isadigit{2}}}}}
       
  1234   \end{tabular}
       
  1235   \end{center}
       
  1236 
       
  1237   With the norm and lexicographic order in place,
       
  1238   we can state the key definition of Okui and Suzuki
       
  1239   \cite{OkuiSuzuki2010}: a value \isa{v\isactrlsub {\isadigit{1}}} is \emph{smaller at position \isa{p}} than
       
  1240   \isa{v\isactrlsub {\isadigit{2}}}, written \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub p\isactrlesub \ v\isactrlsub {\isadigit{2}}}, 
       
  1241   if and only if  $(i)$ the norm at position \isa{p} is
       
  1242   greater in \isa{v\isactrlsub {\isadigit{1}}} (that is the string \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}\mbox{$\downharpoonleft$}\isactrlbsub p\isactrlesub {\isacharbar}{\kern0pt}} is longer 
       
  1243   than \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}\mbox{$\downharpoonleft$}\isactrlbsub p\isactrlesub {\isacharbar}{\kern0pt}}) and $(ii)$ all subvalues at 
       
  1244   positions that are inside \isa{v\isactrlsub {\isadigit{1}}} or \isa{v\isactrlsub {\isadigit{2}}} and that are
       
  1245   lexicographically smaller than \isa{p}, we have the same norm, namely
       
  1246 
       
  1247  \begin{center}
       
  1248  \begin{tabular}{c}
       
  1249  \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub p\isactrlesub \ v\isactrlsub {\isadigit{2}}} 
       
  1250  \isa{{\isasymequiv}} 
       
  1251  $\begin{cases}
       
  1252  (i) & \isa{{\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub p\isactrlesub \ {\isacharless}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub p\isactrlesub }   \quad\text{and}\smallskip \\
       
  1253  (ii) & \isa{{\isasymforall}q{\isasymin}Pos\ v\isactrlsub {\isadigit{1}}\ {\isasymunion}\ Pos\ v\isactrlsub {\isadigit{2}}{\isachardot}{\kern0pt}\ q\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p\ {\isasymlongrightarrow}\ {\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub q\isactrlesub \ {\isacharequal}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub q\isactrlesub }
       
  1254  \end{cases}$
       
  1255  \end{tabular}
       
  1256  \end{center}
       
  1257 
       
  1258  \noindent The position \isa{p} in this definition acts as the
       
  1259   \emph{first distinct position} of \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}}, where both values match strings of different length
       
  1260   \cite{OkuiSuzuki2010}.  Since at \isa{p} the values \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}} match different strings, the
       
  1261   ordering is irreflexive. Derived from the definition above
       
  1262   are the following two orderings:
       
  1263   
       
  1264   \begin{center}
       
  1265   \begin{tabular}{l}
       
  1266   \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}\ {\isasymequiv}\ {\isasymexists}p{\isachardot}{\kern0pt}\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\isactrlbsub p\isactrlesub \ v\isactrlsub {\isadigit{2}}}\\
       
  1267   \isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}\ {\isasymequiv}\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}\ {\isasymor}\ v\isactrlsub {\isadigit{1}}\ {\isacharequal}{\kern0pt}\ v\isactrlsub {\isadigit{2}}}
       
  1268   \end{tabular}
       
  1269   \end{center}
       
  1270 
       
  1271  While we encountered a number of obstacles for establishing properties like
       
  1272  transitivity for the ordering of Sulzmann and Lu (and which we failed
       
  1273  to overcome), it is relatively straightforward to establish this
       
  1274  property for the orderings
       
  1275  \isa{\underline{\hspace{2mm}}\ {\isasymprec}\ \underline{\hspace{2mm}}} and \isa{\underline{\hspace{2mm}}\ \mbox{$\preccurlyeq$}\ \underline{\hspace{2mm}}}  
       
  1276  by Okui and Suzuki.
       
  1277 
       
  1278  \begin{lemma}[Transitivity]\label{transitivity}
       
  1279  \isa{{\normalsize{}If\,}\ \mbox{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}}\ {\normalsize \,and\,}\ \mbox{v\isactrlsub {\isadigit{2}}\ {\isasymprec}\ v\isactrlsub {\isadigit{3}}}\ {\normalsize \,then\,}\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{3}}{\isachardot}{\kern0pt}} 
       
  1280  \end{lemma}
       
  1281 
       
  1282  \begin{proof} From the assumption we obtain two positions \isa{p}
       
  1283  and \isa{q}, where the values \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}} (respectively \isa{v\isactrlsub {\isadigit{2}}} and \isa{v\isactrlsub {\isadigit{3}}}) are `distinct'.  Since \isa{{\isasymprec}\isactrlbsub lex\isactrlesub } is trichotomous, we need to consider
       
  1284  three cases, namely \isa{p\ {\isacharequal}{\kern0pt}\ q}, \isa{p\ {\isasymprec}\isactrlbsub lex\isactrlesub \ q} and
       
  1285  \isa{q\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p}. Let us look at the first case.  Clearly
       
  1286  \isa{{\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub p\isactrlesub \ {\isacharless}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub p\isactrlesub } and \isa{{\isasymparallel}v\isactrlsub {\isadigit{3}}{\isasymparallel}\isactrlbsub p\isactrlesub \ {\isacharless}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub p\isactrlesub } imply \isa{{\isasymparallel}v\isactrlsub {\isadigit{3}}{\isasymparallel}\isactrlbsub p\isactrlesub \ {\isacharless}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub p\isactrlesub }.  It remains to show
       
  1287  that for a \isa{p{\isacharprime}{\kern0pt}\ {\isasymin}\ Pos\ v\isactrlsub {\isadigit{1}}\ {\isasymunion}\ Pos\ v\isactrlsub {\isadigit{3}}}
       
  1288  with \isa{p{\isacharprime}{\kern0pt}\ {\isasymprec}\isactrlbsub lex\isactrlesub \ p} that \isa{{\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub \ {\isacharequal}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{3}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub } holds.  Suppose \isa{p{\isacharprime}{\kern0pt}\ {\isasymin}\ Pos\ v\isactrlsub {\isadigit{1}}}, then we can infer from the first assumption that \isa{{\isasymparallel}v\isactrlsub {\isadigit{1}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub \ {\isacharequal}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub }.  But this means
       
  1289  that \isa{p{\isacharprime}{\kern0pt}} must be in \isa{Pos\ v\isactrlsub {\isadigit{2}}} too (the norm
       
  1290  cannot be \isa{{\isacharminus}{\kern0pt}{\isadigit{1}}} given \isa{p{\isacharprime}{\kern0pt}\ {\isasymin}\ Pos\ v\isactrlsub {\isadigit{1}}}).  
       
  1291  Hence we can use the second assumption and
       
  1292  infer \isa{{\isasymparallel}v\isactrlsub {\isadigit{2}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub \ {\isacharequal}{\kern0pt}\ {\isasymparallel}v\isactrlsub {\isadigit{3}}{\isasymparallel}\isactrlbsub p{\isacharprime}{\kern0pt}\isactrlesub },
       
  1293  which concludes this case with \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{3}}}.  The reasoning in the other cases is similar.\qed
       
  1294  \end{proof}
       
  1295 
       
  1296  \noindent 
       
  1297  The proof for $\preccurlyeq$ is similar and omitted.
       
  1298  It is also straightforward to show that \isa{{\isasymprec}} and
       
  1299  $\preccurlyeq$ are partial orders.  Okui and Suzuki furthermore show that they
       
  1300  are linear orderings for lexical values \cite{OkuiSuzuki2010} of a given
       
  1301  regular expression and given string, but we have not formalised this in Isabelle. It is
       
  1302  not essential for our results. What we are going to show below is
       
  1303  that for a given \isa{r} and \isa{s}, the orderings have a unique
       
  1304  minimal element on the set \isa{LV\ r\ s}, which is the POSIX value
       
  1305  we defined in the previous section. We start with two properties that
       
  1306  show how the length of a flattened value relates to the \isa{{\isasymprec}}-ordering.
       
  1307 
       
  1308  \begin{proposition}\mbox{}\smallskip\\\label{ordlen}
       
  1309  \begin{tabular}{@ {}ll}
       
  1310  (1) &
       
  1311  \isa{{\normalsize{}If\,}\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}\ {\normalsize \,then\,}\ len\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\isasymle}\ len\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}{\isachardot}{\kern0pt}}\\
       
  1312  (2) &
       
  1313  \isa{{\normalsize{}If\,}\ len\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\isacharless}{\kern0pt}\ len\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\normalsize \,then\,}\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}{\isachardot}{\kern0pt}} 
       
  1314  \end{tabular} 
       
  1315  \end{proposition}
       
  1316  
       
  1317  \noindent Both properties follow from the definition of the ordering. Note that
       
  1318  \textit{(2)} entails that a value, say \isa{v\isactrlsub {\isadigit{2}}}, whose underlying 
       
  1319  string is a strict prefix of another flattened value, say \isa{v\isactrlsub {\isadigit{1}}}, then
       
  1320  \isa{v\isactrlsub {\isadigit{1}}} must be smaller than \isa{v\isactrlsub {\isadigit{2}}}. For our proofs it
       
  1321  will be useful to have the following properties---in each case the underlying strings 
       
  1322  of the compared values are the same: 
       
  1323 
       
  1324   \begin{proposition}\mbox{}\smallskip\\\label{ordintros}
       
  1325   \begin{tabular}{ll}
       
  1326   \textit{(1)} & 
       
  1327   \isa{{\normalsize{}If\,}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\normalsize \,then\,}\ Left\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ Right\ v\isactrlsub {\isadigit{2}}{\isachardot}{\kern0pt}}\\
       
  1328   \textit{(2)} & If
       
  1329   \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;then\;
       
  1330   \isa{Left\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ Left\ v\isactrlsub {\isadigit{2}}} \;iff\;
       
  1331   \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}}\\
       
  1332   \textit{(3)} & If
       
  1333   \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;then\;
       
  1334   \isa{Right\ v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ Right\ v\isactrlsub {\isadigit{2}}} \;iff\;
       
  1335   \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}}\\
       
  1336   \textit{(4)} & If
       
  1337   \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}w\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;then\;
       
  1338   \isa{Seq\ v\ v\isactrlsub {\isadigit{2}}\ {\isasymprec}\ Seq\ v\ w\isactrlsub {\isadigit{2}}} \;iff\;
       
  1339   \isa{v\isactrlsub {\isadigit{2}}\ {\isasymprec}\ w\isactrlsub {\isadigit{2}}}\\
       
  1340   \textit{(5)} & If
       
  1341   \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharat}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}w\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharat}{\kern0pt}\ {\isacharbar}{\kern0pt}w\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;and\;
       
  1342   \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ w\isactrlsub {\isadigit{1}}} \;then\;
       
  1343   \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}\ {\isasymprec}\ Seq\ w\isactrlsub {\isadigit{1}}\ w\isactrlsub {\isadigit{2}}}\\
       
  1344   \textit{(6)} & If
       
  1345   \isa{{\isacharbar}{\kern0pt}vs\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}vs\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;then\;
       
  1346   \isa{Stars\ {\isacharparenleft}{\kern0pt}vs\ {\isacharat}{\kern0pt}\ vs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymprec}\ Stars\ {\isacharparenleft}{\kern0pt}vs\ {\isacharat}{\kern0pt}\ vs\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} \;iff\;
       
  1347   \isa{Stars\ vs\isactrlsub {\isadigit{1}}\ {\isasymprec}\ Stars\ vs\isactrlsub {\isadigit{2}}}\\  
       
  1348   
       
  1349   \textit{(7)} & If
       
  1350   \isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \;and\;
       
  1351   \isa{v\isactrlsub {\isadigit{1}}\ {\isasymprec}\ v\isactrlsub {\isadigit{2}}} \;then\;
       
  1352    \isa{Stars\ {\isacharparenleft}{\kern0pt}v\isactrlsub {\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isasymprec}\ Stars\ {\isacharparenleft}{\kern0pt}v\isactrlsub {\isadigit{2}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1353   \end{tabular} 
       
  1354   \end{proposition}
       
  1355 
       
  1356   \noindent One might prefer that statements \textit{(4)} and \textit{(5)} 
       
  1357   (respectively \textit{(6)} and \textit{(7)})
       
  1358   are combined into a single \textit{iff}-statement (like the ones for \isa{Left} and \isa{Right}). Unfortunately this cannot be done easily: such
       
  1359   a single statement would require an additional assumption about the
       
  1360   two values \isa{Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}} and \isa{Seq\ w\isactrlsub {\isadigit{1}}\ w\isactrlsub {\isadigit{2}}}
       
  1361   being inhabited by the same regular expression. The
       
  1362   complexity of the proofs involved seems to not justify such a
       
  1363   `cleaner' single statement. The statements given are just the properties that
       
  1364   allow us to establish our theorems without any difficulty. The proofs 
       
  1365   for Proposition~\ref{ordintros} are routine.
       
  1366  
       
  1367 
       
  1368   Next we establish how Okui and Suzuki's orderings relate to our
       
  1369   definition of POSIX values.  Given a \isa{POSIX} value \isa{v\isactrlsub {\isadigit{1}}}
       
  1370   for \isa{r} and \isa{s}, then any other lexical value \isa{v\isactrlsub {\isadigit{2}}} in \isa{LV\ r\ s} is greater or equal than \isa{v\isactrlsub {\isadigit{1}}}, namely:
       
  1371 
       
  1372 
       
  1373   \begin{theorem}\label{orderone}
       
  1374   \isa{{\normalsize{}If\,}\ \mbox{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}}\ {\normalsize \,and\,}\ \mbox{v\isactrlsub {\isadigit{2}}\ {\isasymin}\ LV\ r\ s}\ {\normalsize \,then\,}\ v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}{\isachardot}{\kern0pt}}
       
  1375   \end{theorem}
       
  1376 
       
  1377   \begin{proof} By induction on our POSIX rules. By
       
  1378   Theorem~\ref{posixdeterm} and the definition of \isa{LV}, it is clear
       
  1379   that \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}} have the same
       
  1380   underlying string \isa{s}.  The three base cases are
       
  1381   straightforward: for example for \isa{v\isactrlsub {\isadigit{1}}\ {\isacharequal}{\kern0pt}\ Empty}, we have
       
  1382   that \isa{v\isactrlsub {\isadigit{2}}\ {\isasymin}\ LV\ \isactrlbold {\isadigit{1}}\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} must also be of the form
       
  1383   \mbox{\isa{v\isactrlsub {\isadigit{2}}\ {\isacharequal}{\kern0pt}\ Empty}}. Therefore we have \isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}}.  The inductive cases for
       
  1384   \isa{r} being of the form \isa{r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}} and
       
  1385   \isa{r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}} are as follows:
       
  1386 
       
  1387 
       
  1388   \begin{itemize} 
       
  1389 
       
  1390   \item[$\bullet$] Case \isa{P{\isacharplus}{\kern0pt}L} with \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Left\ w\isactrlsub {\isadigit{1}}}: In this case the value 
       
  1391   \isa{v\isactrlsub {\isadigit{2}}} is either of the
       
  1392   form \isa{Left\ w\isactrlsub {\isadigit{2}}} or \isa{Right\ w\isactrlsub {\isadigit{2}}}. In the
       
  1393   latter case we can immediately conclude with \mbox{\isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}}} since a \isa{Left}-value with the
       
  1394   same underlying string \isa{s} is always smaller than a
       
  1395   \isa{Right}-value by Proposition~\ref{ordintros}\textit{(1)}.  
       
  1396   In the former case we have \isa{w\isactrlsub {\isadigit{2}}\ {\isasymin}\ LV\ r\isactrlsub {\isadigit{1}}\ s} and can use the induction hypothesis to infer
       
  1397   \isa{w\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ w\isactrlsub {\isadigit{2}}}. Because \isa{w\isactrlsub {\isadigit{1}}} and \isa{w\isactrlsub {\isadigit{2}}} have the same underlying string
       
  1398   \isa{s}, we can conclude with \isa{Left\ w\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ Left\ w\isactrlsub {\isadigit{2}}} using
       
  1399   Proposition~\ref{ordintros}\textit{(2)}.\smallskip
       
  1400 
       
  1401   \item[$\bullet$] Case \isa{P{\isacharplus}{\kern0pt}R} with \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Right\ w\isactrlsub {\isadigit{1}}}: This case similar to the previous
       
  1402   case, except that we additionally know \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}. This is needed when \isa{v\isactrlsub {\isadigit{2}}} is of the form
       
  1403   \mbox{\isa{Left\ w\isactrlsub {\isadigit{2}}}}. Since \mbox{\isa{{\isacharbar}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}w\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}} \isa{{\isacharequal}{\kern0pt}\ s}} and \isa{w\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}}, we can derive a contradiction for \mbox{\isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}} using
       
  1404   Proposition~\ref{inhabs}. So also in this case \mbox{\isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}}}.\smallskip
       
  1405 
       
  1406   \item[$\bullet$] Case \isa{PS} with \isa{{\isacharparenleft}{\kern0pt}s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Seq\ w\isactrlsub {\isadigit{1}}\ w\isactrlsub {\isadigit{2}}}: We can assume \isa{v\isactrlsub {\isadigit{2}}\ {\isacharequal}{\kern0pt}\ Seq\ u\isactrlsub {\isadigit{1}}\ u\isactrlsub {\isadigit{2}}} with \isa{u\isactrlsub {\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{1}}} and \mbox{\isa{u\isactrlsub {\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}}. We have \isa{s\isactrlsub {\isadigit{1}}\ {\isacharat}{\kern0pt}\ s\isactrlsub {\isadigit{2}}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}u\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}\ {\isacharat}{\kern0pt}\ {\isacharbar}{\kern0pt}u\isactrlsub {\isadigit{2}}{\isacharbar}{\kern0pt}}.  By the side-condition of the
       
  1407   \isa{PS}-rule we know that either \isa{s\isactrlsub {\isadigit{1}}\ {\isacharequal}{\kern0pt}\ {\isacharbar}{\kern0pt}u\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}} or that \isa{{\isacharbar}{\kern0pt}u\isactrlsub {\isadigit{1}}{\isacharbar}{\kern0pt}} is a strict prefix of
       
  1408   \isa{s\isactrlsub {\isadigit{1}}}. In the latter case we can infer \isa{w\isactrlsub {\isadigit{1}}\ {\isasymprec}\ u\isactrlsub {\isadigit{1}}} by
       
  1409   Proposition~\ref{ordlen}\textit{(2)} and from this \isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}} by Proposition~\ref{ordintros}\textit{(5)}
       
  1410   (as noted above \isa{v\isactrlsub {\isadigit{1}}} and \isa{v\isactrlsub {\isadigit{2}}} must have the
       
  1411   same underlying string).
       
  1412   In the former case we know
       
  1413   \isa{u\isactrlsub {\isadigit{1}}\ {\isasymin}\ LV\ r\isactrlsub {\isadigit{1}}\ s\isactrlsub {\isadigit{1}}} and \isa{u\isactrlsub {\isadigit{2}}\ {\isasymin}\ LV\ r\isactrlsub {\isadigit{2}}\ s\isactrlsub {\isadigit{2}}}. With this we can use the
       
  1414   induction hypotheses to infer \isa{w\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ u\isactrlsub {\isadigit{1}}} and \isa{w\isactrlsub {\isadigit{2}}\ \mbox{$\preccurlyeq$}\ u\isactrlsub {\isadigit{2}}}. By
       
  1415   Proposition~\ref{ordintros}\textit{(4,5)} we can again infer 
       
  1416   \isa{v\isactrlsub {\isadigit{1}}\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{2}}}.
       
  1417 
       
  1418   \end{itemize}
       
  1419 
       
  1420   \noindent The case for \isa{P{\isasymstar}} is similar to the \isa{PS}-case and omitted.\qed
       
  1421   \end{proof}
       
  1422 
       
  1423   \noindent This theorem shows that our \isa{POSIX} value for a
       
  1424   regular expression \isa{r} and string \isa{s} is in fact a
       
  1425   minimal element of the values in \isa{LV\ r\ s}. By
       
  1426   Proposition~\ref{ordlen}\textit{(2)} we also know that any value in
       
  1427   \isa{LV\ r\ s{\isacharprime}{\kern0pt}}, with \isa{s{\isacharprime}{\kern0pt}} being a strict prefix, cannot be
       
  1428   smaller than \isa{v\isactrlsub {\isadigit{1}}}. The next theorem shows the
       
  1429   opposite---namely any minimal element in \isa{LV\ r\ s} must be a
       
  1430   \isa{POSIX} value. This can be established by induction on \isa{r}, but the proof can be drastically simplified by using the fact
       
  1431   from the previous section about the existence of a \isa{POSIX} value
       
  1432   whenever a string \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}}.
       
  1433 
       
  1434 
       
  1435   \begin{theorem}
       
  1436   \isa{{\normalsize{}If\,}\ \mbox{v\isactrlsub {\isadigit{1}}\ {\isasymin}\ LV\ r\ s}\ {\normalsize \,and\,}\ \mbox{{\isasymforall}v\isactrlsub {\isadigit{2}}{\isasymin}LV\ r\ s{\isachardot}{\kern0pt}\ v\isactrlsub {\isadigit{2}}\ \mbox{$\not\prec$}\ v\isactrlsub {\isadigit{1}}}\ {\normalsize \,then\,}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub {\isadigit{1}}{\isachardot}{\kern0pt}} 
       
  1437   \end{theorem}
       
  1438 
       
  1439   \begin{proof} 
       
  1440   If \isa{v\isactrlsub {\isadigit{1}}\ {\isasymin}\ LV\ r\ s} then 
       
  1441   \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}} by Proposition~\ref{inhabs}. Hence by Theorem~\ref{lexercorrect}(2) 
       
  1442   there exists a
       
  1443   \isa{POSIX} value \isa{v\isactrlsub P} with \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\isactrlsub P}
       
  1444   and by Lemma~\ref{LVposix} we also have \mbox{\isa{v\isactrlsub P\ {\isasymin}\ LV\ r\ s}}.
       
  1445   By Theorem~\ref{orderone} we therefore have 
       
  1446   \isa{v\isactrlsub P\ \mbox{$\preccurlyeq$}\ v\isactrlsub {\isadigit{1}}}. If \isa{v\isactrlsub P\ {\isacharequal}{\kern0pt}\ v\isactrlsub {\isadigit{1}}} then
       
  1447   we are done. Otherwise we have \isa{v\isactrlsub P\ {\isasymprec}\ v\isactrlsub {\isadigit{1}}}, which 
       
  1448   however contradicts the second assumption about \isa{v\isactrlsub {\isadigit{1}}} being the smallest
       
  1449   element in \isa{LV\ r\ s}. So we are done in this case too.\qed
       
  1450   \end{proof}
       
  1451 
       
  1452   \noindent
       
  1453   From this we can also show 
       
  1454   that if \isa{LV\ r\ s} is non-empty (or equivalently \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}}) then 
       
  1455   it has a unique minimal element:
       
  1456 
       
  1457   \begin{corollary}
       
  1458   \isa{{\normalsize{}If\,}\ LV\ r\ s\ {\isasymnoteq}\ {\isasymemptyset}\ {\normalsize \,then\,}\ {\isasymexists}{\isacharbang}{\kern0pt}vmin{\isachardot}{\kern0pt}\ vmin\ {\isasymin}\ LV\ r\ s\ {\isasymand}\ {\isacharparenleft}{\kern0pt}{\isasymforall}v{\isasymin}LV\ r\ s{\isachardot}{\kern0pt}\ vmin\ \mbox{$\preccurlyeq$}\ v{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}}
       
  1459   \end{corollary}
       
  1460 
       
  1461 
       
  1462 
       
  1463   \noindent To sum up, we have shown that the (unique) minimal elements 
       
  1464   of the ordering by Okui and Suzuki are exactly the \isa{POSIX}
       
  1465   values we defined inductively in Section~\ref{posixsec}. This provides
       
  1466   an independent confirmation that our ternary relation formalises the
       
  1467   informal POSIX rules.%
       
  1468 \end{isamarkuptext}\isamarkuptrue%
       
  1469 %
       
  1470 \isadelimdocument
       
  1471 %
       
  1472 \endisadelimdocument
       
  1473 %
       
  1474 \isatagdocument
       
  1475 %
       
  1476 \isamarkupsection{Bitcoded Lexing%
       
  1477 }
       
  1478 \isamarkuptrue%
       
  1479 %
       
  1480 \endisatagdocument
       
  1481 {\isafolddocument}%
       
  1482 %
       
  1483 \isadelimdocument
       
  1484 %
       
  1485 \endisadelimdocument
       
  1486 %
       
  1487 \begin{isamarkuptext}%
       
  1488 Incremental calculation of the value. To simplify the proof we first define the function
       
  1489 \isa{flex} which calculates the ``iterated'' injection function. With this we can 
       
  1490 rewrite the lexer as
       
  1491 
       
  1492 \begin{center}
       
  1493 \isa{lexer\ r\ s\ {\isacharequal}{\kern0pt}\ {\isacharparenleft}{\kern0pt}\textrm{if}\ nullable\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}s{\isacharparenright}{\kern0pt}\ \textrm{then}\ Some\ {\isacharparenleft}{\kern0pt}flex\ r\ id\ s\ {\isacharparenleft}{\kern0pt}mkeps\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}s{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ \textrm{else}\ None{\isacharparenright}{\kern0pt}}
       
  1494 \end{center}%
       
  1495 \end{isamarkuptext}\isamarkuptrue%
       
  1496 %
       
  1497 \isadelimdocument
       
  1498 %
       
  1499 \endisadelimdocument
       
  1500 %
       
  1501 \isatagdocument
       
  1502 %
       
  1503 \isamarkupsection{Optimisations%
       
  1504 }
       
  1505 \isamarkuptrue%
       
  1506 %
       
  1507 \endisatagdocument
       
  1508 {\isafolddocument}%
       
  1509 %
       
  1510 \isadelimdocument
       
  1511 %
       
  1512 \endisadelimdocument
       
  1513 %
       
  1514 \begin{isamarkuptext}%
       
  1515 Derivatives as calculated by \Brz's method are usually more complex
       
  1516   regular expressions than the initial one; the result is that the
       
  1517   derivative-based matching and lexing algorithms are often abysmally slow.
       
  1518   However, various optimisations are possible, such as the simplifications
       
  1519   of \isa{\isactrlbold {\isadigit{0}}\ {\isacharplus}{\kern0pt}\ r}, \isa{r\ {\isacharplus}{\kern0pt}\ \isactrlbold {\isadigit{0}}}, \isa{\isactrlbold {\isadigit{1}}\ {\isasymcdot}\ r} and
       
  1520   \isa{r\ {\isasymcdot}\ \isactrlbold {\isadigit{1}}} to \isa{r}. These simplifications can speed up the
       
  1521   algorithms considerably, as noted in \cite{Sulzmann2014}. One of the
       
  1522   advantages of having a simple specification and correctness proof is that
       
  1523   the latter can be refined to prove the correctness of such simplification
       
  1524   steps. While the simplification of regular expressions according to 
       
  1525   rules like
       
  1526 
       
  1527   \begin{equation}\label{Simpl}
       
  1528   \begin{array}{lcllcllcllcl}
       
  1529   \isa{\isactrlbold {\isadigit{0}}\ {\isacharplus}{\kern0pt}\ r} & \isa{{\isasymRightarrow}} & \isa{r} \hspace{8mm}%\\
       
  1530   \isa{r\ {\isacharplus}{\kern0pt}\ \isactrlbold {\isadigit{0}}} & \isa{{\isasymRightarrow}} & \isa{r} \hspace{8mm}%\\
       
  1531   \isa{\isactrlbold {\isadigit{1}}\ {\isasymcdot}\ r}  & \isa{{\isasymRightarrow}} & \isa{r} \hspace{8mm}%\\
       
  1532   \isa{r\ {\isasymcdot}\ \isactrlbold {\isadigit{1}}}  & \isa{{\isasymRightarrow}} & \isa{r}
       
  1533   \end{array}
       
  1534   \end{equation}
       
  1535 
       
  1536   \noindent is well understood, there is an obstacle with the POSIX value
       
  1537   calculation algorithm by Sulzmann and Lu: if we build a derivative regular
       
  1538   expression and then simplify it, we will calculate a POSIX value for this
       
  1539   simplified derivative regular expression, \emph{not} for the original (unsimplified)
       
  1540   derivative regular expression. Sulzmann and Lu \cite{Sulzmann2014} overcome this obstacle by
       
  1541   not just calculating a simplified regular expression, but also calculating
       
  1542   a \emph{rectification function} that ``repairs'' the incorrect value.
       
  1543   
       
  1544   The rectification functions can be (slightly clumsily) implemented  in
       
  1545   Isabelle/HOL as follows using some auxiliary functions:
       
  1546 
       
  1547   \begin{center}
       
  1548   \begin{tabular}{lcl}
       
  1549   \isa{F\isactrlbsub Right\isactrlesub \ f\ v} & $\dn$ & \isa{Right\ {\isacharparenleft}{\kern0pt}f\ v{\isacharparenright}{\kern0pt}}\\
       
  1550   \isa{F\isactrlbsub Left\isactrlesub \ f\ v} & $\dn$ & \isa{Left\ {\isacharparenleft}{\kern0pt}f\ v{\isacharparenright}{\kern0pt}}\\
       
  1551   
       
  1552   \isa{F\isactrlbsub Alt\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}\ {\isacharparenleft}{\kern0pt}Right\ v{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Right\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v{\isacharparenright}{\kern0pt}}\\
       
  1553   \isa{F\isactrlbsub Alt\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}\ {\isacharparenleft}{\kern0pt}Left\ v{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Left\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v{\isacharparenright}{\kern0pt}}\\
       
  1554   
       
  1555   \isa{F\isactrlbsub Seq{\isadigit{1}}\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}\ v} & $\dn$ & \isa{Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ {\isacharparenleft}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v{\isacharparenright}{\kern0pt}}\\
       
  1556   \isa{F\isactrlbsub Seq{\isadigit{2}}\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}\ v} & $\dn$ & \isa{Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ {\isacharparenleft}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}}\\
       
  1557   \isa{F\isactrlbsub Seq\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}\ {\isacharparenleft}{\kern0pt}Seq\ v\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\medskip\\
       
  1558   %\end{tabular}
       
  1559   %
       
  1560   %\begin{tabular}{lcl}
       
  1561   \isa{simp\isactrlbsub Alt\isactrlesub \ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{0}}{\isacharcomma}{\kern0pt}\ \underline{\hspace{2mm}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Right\isactrlesub \ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1562   \isa{simp\isactrlbsub Alt\isactrlesub \ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{0}}{\isacharcomma}{\kern0pt}\ \underline{\hspace{2mm}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Left\isactrlesub \ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}\\
       
  1563   \isa{simp\isactrlbsub Alt\isactrlesub \ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Alt\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1564   \isa{simp\isactrlbsub Seq\isactrlesub \ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Seq{\isadigit{1}}\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1565   \isa{simp\isactrlbsub Seq\isactrlesub \ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}\isactrlbold {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Seq{\isadigit{2}}\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1566   \isa{simp\isactrlbsub Seq\isactrlesub \ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F\isactrlbsub Seq\isactrlesub \ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1567   \end{tabular}
       
  1568   \end{center}
       
  1569 
       
  1570   \noindent
       
  1571   The functions \isa{simp\isactrlbsub Alt\isactrlesub } and \isa{simp\isactrlbsub Seq\isactrlesub } encode the simplification rules
       
  1572   in \eqref{Simpl} and compose the rectification functions (simplifications can occur
       
  1573   deep inside the regular expression). The main simplification function is then 
       
  1574 
       
  1575   \begin{center}
       
  1576   \begin{tabular}{lcl}
       
  1577   \isa{simp\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{simp\isactrlbsub Alt\isactrlesub \ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1578   \isa{simp\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} & $\dn$ & \isa{simp\isactrlbsub Seq\isactrlesub \ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}}\\
       
  1579   \isa{simp\ r} & $\dn$ & \isa{{\isacharparenleft}{\kern0pt}r{\isacharcomma}{\kern0pt}\ id{\isacharparenright}{\kern0pt}}\\
       
  1580   \end{tabular}
       
  1581   \end{center} 
       
  1582 
       
  1583   \noindent where \isa{id} stands for the identity function. The
       
  1584   function \isa{simp} returns a simplified regular expression and a corresponding
       
  1585   rectification function. Note that we do not simplify under stars: this
       
  1586   seems to slow down the algorithm, rather than speed it up. The optimised
       
  1587   lexer is then given by the clauses:
       
  1588   
       
  1589   \begin{center}
       
  1590   \begin{tabular}{lcl}
       
  1591   \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} & $\dn$ & \isa{\textrm{if}\ nullable\ r\ \textrm{then}\ Some\ {\isacharparenleft}{\kern0pt}mkeps\ r{\isacharparenright}{\kern0pt}\ \textrm{else}\ None}\\
       
  1592   \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\ {\isacharparenleft}{\kern0pt}c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s{\isacharparenright}{\kern0pt}} & $\dn$ & 
       
  1593                          \isa{let\ {\isacharparenleft}{\kern0pt}r\isactrlsub s{\isacharcomma}{\kern0pt}\ f\isactrlsub r{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ simp\ {\isacharparenleft}{\kern0pt}r}$\backslash$\isa{c{\isacharparenright}{\kern0pt}\ in}\\
       
  1594                      & & \isa{case} \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\isactrlsub s\ s} \isa{of}\\
       
  1595                      & & \phantom{$|$} \isa{None}  \isa{{\isasymRightarrow}} \isa{None}\\
       
  1596                      & & $|$ \isa{Some\ v} \isa{{\isasymRightarrow}} \isa{Some\ {\isacharparenleft}{\kern0pt}inj\ r\ c\ {\isacharparenleft}{\kern0pt}f\isactrlsub r\ v{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}}                          
       
  1597   \end{tabular}
       
  1598   \end{center}
       
  1599 
       
  1600   \noindent
       
  1601   In the second clause we first calculate the derivative \isa{r{\isacharbackslash}{\kern0pt}c}
       
  1602   and then simpli
       
  1603 
       
  1604 text \isa{\ \ Incremental\ calculation\ of\ the\ value{\isachardot}{\kern0pt}\ To\ simplify\ the\ proof\ we\ first\ define\ the\ function\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ flex{\isacharbraceright}{\kern0pt}\ which\ calculates\ the\ {\isacharbackquote}{\kern0pt}{\isacharbackquote}{\kern0pt}iterated{\isacharprime}{\kern0pt}{\isacharprime}{\kern0pt}\ injection\ function{\isachardot}{\kern0pt}\ With\ this\ we\ can\ rewrite\ the\ lexer\ as\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ lexer{\isacharunderscore}{\kern0pt}flex{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}v\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}v\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{7}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ code{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{7}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ areg{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}{\isacharequal}{\kern0pt}{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}AZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}mid{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}AONE\ bs{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}mid{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ACHAR\ bs\ c{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}mid{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}AALT\ bs\ r{\isadigit{1}}\ r{\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}mid{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ASEQ\ bs\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}mid{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ASTAR\ bs\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ intern{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ erase{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ Some\ simple\ facts\ about\ erase\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}lemma{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}mbox{\isacharbraceleft}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ erase{\isacharunderscore}{\kern0pt}bder{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ erase{\isacharunderscore}{\kern0pt}intern{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}lemma{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bnullable{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}medskip{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ \ {\isacharpercent}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharpercent}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharpercent}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharpercent}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ \ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{5}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bder{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{6}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{3}}{\isacharparenright}{\kern0pt}{\isacharbrackleft}{\kern0pt}of\ bs\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}\ {\isachardoublequote}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ bmkeps{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{4}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}medskip{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ \ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharbrackleft}{\kern0pt}mode{\isacharequal}{\kern0pt}IfThen{\isacharbrackright}{\kern0pt}\ bder{\isacharunderscore}{\kern0pt}retrieve{\isacharbraceright}{\kern0pt}\ \ By\ induction\ on\ {\isasymopen}r{\isasymclose}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}{\isacharbrackleft}{\kern0pt}Main\ Lemma{\isacharbrackright}{\kern0pt}{\isacharbackslash}{\kern0pt}mbox{\isacharbraceleft}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharbrackleft}{\kern0pt}mode{\isacharequal}{\kern0pt}IfThen{\isacharbrackright}{\kern0pt}\ MAIN{\isacharunderscore}{\kern0pt}decode{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ Definition\ of\ the\ bitcoded\ lexer\ \ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ blexer{\isacharunderscore}{\kern0pt}def{\isacharbraceright}{\kern0pt}\ \ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ blexer{\isacharunderscore}{\kern0pt}correctness{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}\ \ }
       
  1605 
       
  1606 section \isa{Optimisations}
       
  1607 
       
  1608 text \isa{\ \ Derivatives\ as\ calculated\ by\ {\isacharbackslash}{\kern0pt}Brz{\isacharprime}{\kern0pt}s\ method\ are\ usually\ more\ complex\ regular\ expressions\ than\ the\ initial\ one{\isacharsemicolon}{\kern0pt}\ the\ result\ is\ that\ the\ derivative{\isacharminus}{\kern0pt}based\ matching\ and\ lexing\ algorithms\ are\ often\ abysmally\ slow{\isachardot}{\kern0pt}\ However{\isacharcomma}{\kern0pt}\ various\ optimisations\ are\ possible{\isacharcomma}{\kern0pt}\ such\ as\ the\ simplifications\ of\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ALT\ ZERO\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ALT\ r\ ZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}SEQ\ ONE\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}SEQ\ r\ ONE{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ to\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ These\ simplifications\ can\ speed\ up\ the\ algorithms\ considerably{\isacharcomma}{\kern0pt}\ as\ noted\ in\ {\isacharbackslash}{\kern0pt}cite{\isacharbraceleft}{\kern0pt}Sulzmann{\isadigit{2}}{\isadigit{0}}{\isadigit{1}}{\isadigit{4}}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ One\ of\ the\ advantages\ of\ having\ a\ simple\ specification\ and\ correctness\ proof\ is\ that\ the\ latter\ can\ be\ refined\ to\ prove\ the\ correctness\ of\ such\ simplification\ steps{\isachardot}{\kern0pt}\ While\ the\ simplification\ of\ regular\ expressions\ according\ to\ rules\ like\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}equation{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}label{\isacharbraceleft}{\kern0pt}Simpl{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}array{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcllcllcllcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ALT\ ZERO\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}hspace{\isacharbraceleft}{\kern0pt}{\isadigit{8}}mm{\isacharbraceright}{\kern0pt}{\isacharpercent}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}ALT\ r\ ZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}hspace{\isacharbraceleft}{\kern0pt}{\isadigit{8}}mm{\isacharbraceright}{\kern0pt}{\isacharpercent}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}SEQ\ ONE\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ \ {\isacharampersand}{\kern0pt}\ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}hspace{\isacharbraceleft}{\kern0pt}{\isadigit{8}}mm{\isacharbraceright}{\kern0pt}{\isacharpercent}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}SEQ\ r\ ONE{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ \ {\isacharampersand}{\kern0pt}\ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}array{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}equation{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ is\ well\ understood{\isacharcomma}{\kern0pt}\ there\ is\ an\ obstacle\ with\ the\ POSIX\ value\ calculation\ algorithm\ by\ Sulzmann\ and\ Lu{\isacharcolon}{\kern0pt}\ if\ we\ build\ a\ derivative\ regular\ expression\ and\ then\ simplify\ it{\isacharcomma}{\kern0pt}\ we\ will\ calculate\ a\ POSIX\ value\ for\ this\ simplified\ derivative\ regular\ expression{\isacharcomma}{\kern0pt}\ {\isacharbackslash}{\kern0pt}emph{\isacharbraceleft}{\kern0pt}not{\isacharbraceright}{\kern0pt}\ for\ the\ original\ {\isacharparenleft}{\kern0pt}unsimplified{\isacharparenright}{\kern0pt}\ derivative\ regular\ expression{\isachardot}{\kern0pt}\ Sulzmann\ and\ Lu\ {\isacharbackslash}{\kern0pt}cite{\isacharbraceleft}{\kern0pt}Sulzmann{\isadigit{2}}{\isadigit{0}}{\isadigit{1}}{\isadigit{4}}{\isacharbraceright}{\kern0pt}\ overcome\ this\ obstacle\ by\ not\ just\ calculating\ a\ simplified\ regular\ expression{\isacharcomma}{\kern0pt}\ but\ also\ calculating\ a\ {\isacharbackslash}{\kern0pt}emph{\isacharbraceleft}{\kern0pt}rectification\ function{\isacharbraceright}{\kern0pt}\ that\ {\isacharbackquote}{\kern0pt}{\isacharbackquote}{\kern0pt}repairs{\isacharprime}{\kern0pt}{\isacharprime}{\kern0pt}\ the\ incorrect\ value{\isachardot}{\kern0pt}\ \ The\ rectification\ functions\ can\ be\ {\isacharparenleft}{\kern0pt}slightly\ clumsily{\isacharparenright}{\kern0pt}\ implemented\ \ in\ Isabelle{\isacharslash}{\kern0pt}HOL\ as\ follows\ using\ some\ auxiliary\ functions{\isacharcolon}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}RIGHT{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Right\ {\isacharparenleft}{\kern0pt}f\ v{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}LEFT{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Left\ {\isacharparenleft}{\kern0pt}f\ v{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ \ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}ALT{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Right\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}ALT{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Left\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ \ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ{\isadigit{1}}{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ {\isacharparenleft}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ{\isadigit{2}}{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ {\isacharparenleft}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}Seq\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{1}}\ v\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}f\isactrlsub {\isadigit{2}}\ v\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isasymclose}{\isacharbackslash}{\kern0pt}medskip{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharpercent}{\kern0pt}{\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharpercent}{\kern0pt}\ {\isacharpercent}{\kern0pt}{\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}ALT\ {\isacharparenleft}{\kern0pt}ZERO{\isacharcomma}{\kern0pt}\ DUMMY{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}RIGHT\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}ALT\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}ZERO{\isacharcomma}{\kern0pt}\ DUMMY{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}LEFT\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}ALT\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}ALT\ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}SEQ\ {\isacharparenleft}{\kern0pt}ONE{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ{\isadigit{1}}\ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}SEQ\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}ONE{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ{\isadigit{2}}\ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}SEQ\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}SEQ\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharcomma}{\kern0pt}\ F{\isacharunderscore}{\kern0pt}SEQ\ f\isactrlsub {\isadigit{1}}\ f\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ The\ functions\ {\isasymopen}simp\isactrlbsub Alt\isactrlesub {\isasymclose}\ and\ {\isasymopen}simp\isactrlbsub Seq\isactrlesub {\isasymclose}\ encode\ the\ simplification\ rules\ in\ {\isacharbackslash}{\kern0pt}eqref{\isacharbraceleft}{\kern0pt}Simpl{\isacharbraceright}{\kern0pt}\ and\ compose\ the\ rectification\ functions\ {\isacharparenleft}{\kern0pt}simplifications\ can\ occur\ deep\ inside\ the\ regular\ expression{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}\ The\ main\ simplification\ function\ is\ then\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}ALT\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}SEQ\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp{\isacharunderscore}{\kern0pt}SEQ\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}simp\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharparenleft}{\kern0pt}r{\isacharcomma}{\kern0pt}\ id{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ where\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}id{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ stands\ for\ the\ identity\ function{\isachardot}{\kern0pt}\ The\ function\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ simp{\isacharbraceright}{\kern0pt}\ returns\ a\ simplified\ regular\ expression\ and\ a\ corresponding\ rectification\ function{\isachardot}{\kern0pt}\ Note\ that\ we\ do\ not\ simplify\ under\ stars{\isacharcolon}{\kern0pt}\ this\ seems\ to\ slow\ down\ the\ algorithm{\isacharcomma}{\kern0pt}\ rather\ than\ speed\ it\ up{\isachardot}{\kern0pt}\ The\ optimised\ lexer\ is\ then\ given\ by\ the\ clauses{\isacharcolon}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}lcl{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ slexer{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}rhs{\isacharparenright}{\kern0pt}\ slexer{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ {\isacharparenleft}{\kern0pt}lhs{\isacharparenright}{\kern0pt}\ slexer{\isachardot}{\kern0pt}simps{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}dn{\isachardollar}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}let\ {\isacharparenleft}{\kern0pt}r\isactrlsub s{\isacharcomma}{\kern0pt}\ f\isactrlsub r{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ simp\ {\isacharparenleft}{\kern0pt}r\ {\isasymclose}{\isachardollar}{\kern0pt}{\isacharbackslash}{\kern0pt}backslash{\isachardollar}{\kern0pt}{\isasymopen}\ c{\isacharparenright}{\kern0pt}\ in{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isasymopen}case{\isasymclose}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}slexer\ r\isactrlsub s\ s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymopen}of{\isasymclose}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharbackslash}{\kern0pt}phantom{\isacharbraceleft}{\kern0pt}{\isachardollar}{\kern0pt}{\isacharbar}{\kern0pt}{\isachardollar}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}None{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ \ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ None{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isachardollar}{\kern0pt}{\isacharbar}{\kern0pt}{\isachardollar}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}Some\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ {\isasymopen}{\isasymRightarrow}{\isasymclose}\ {\isasymopen}Some\ {\isacharparenleft}{\kern0pt}inj\ r\ c\ {\isacharparenleft}{\kern0pt}f\isactrlsub r\ v{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isasymclose}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}center{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ In\ the\ second\ clause\ we\ first\ calculate\ the\ derivative\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}der\ c\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ then\ simplify\ the\ result{\isachardot}{\kern0pt}\ This\ gives\ us\ a\ simplified\ derivative\ {\isasymopen}r\isactrlsub s{\isasymclose}\ and\ a\ rectification\ function\ {\isasymopen}f\isactrlsub r{\isasymclose}{\isachardot}{\kern0pt}\ The\ lexer\ is\ then\ recursively\ called\ with\ the\ simplified\ derivative{\isacharcomma}{\kern0pt}\ but\ before\ we\ inject\ the\ character\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ c{\isacharbraceright}{\kern0pt}\ into\ the\ value\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ v{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ we\ need\ to\ rectify\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ v{\isacharbraceright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}that\ is\ construct\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}f\isactrlsub r\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}\ Before\ we\ can\ establish\ the\ correctness\ of\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}slexer{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ we\ need\ to\ show\ that\ simplification\ preserves\ the\ language\ and\ simplification\ preserves\ our\ POSIX\ relation\ once\ the\ value\ is\ rectified\ {\isacharparenleft}{\kern0pt}recall\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ {\isachardoublequote}{\kern0pt}simp{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ generates\ a\ {\isacharparenleft}{\kern0pt}regular\ expression{\isacharcomma}{\kern0pt}\ rectification\ function{\isacharparenright}{\kern0pt}\ pair{\isacharparenright}{\kern0pt}{\isacharcolon}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}lemma{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}mbox{\isacharbraceleft}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}smallskip{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}label{\isacharbraceleft}{\kern0pt}slexeraux{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}{\isacharbraceleft}{\kern0pt}ll{\isacharbraceright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ L{\isacharunderscore}{\kern0pt}fst{\isacharunderscore}{\kern0pt}simp{\isacharbrackleft}{\kern0pt}symmetric{\isacharbrackright}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharbackslash}{\kern0pt}{\isacharbackslash}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isacharampersand}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm{\isacharbrackleft}{\kern0pt}mode{\isacharequal}{\kern0pt}IfThen{\isacharbrackright}{\kern0pt}\ Posix{\isacharunderscore}{\kern0pt}simp{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}tabular{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}lemma{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}proof{\isacharbraceright}{\kern0pt}\ Both\ are\ by\ induction\ on\ {\isasymopen}r{\isasymclose}{\isachardot}{\kern0pt}\ There\ is\ no\ interesting\ case\ for\ the\ first\ statement{\isachardot}{\kern0pt}\ For\ the\ second\ statement{\isacharcomma}{\kern0pt}\ of\ interest\ are\ the\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}r\ {\isacharequal}{\kern0pt}\ ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}r\ {\isacharequal}{\kern0pt}\ SEQ\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ cases{\isachardot}{\kern0pt}\ In\ each\ case\ we\ have\ to\ analyse\ four\ subcases\ whether\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ equals\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ ZERO{\isacharbraceright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}respectively\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ ONE{\isacharbraceright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}\ For\ example\ for\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}r\ {\isacharequal}{\kern0pt}\ ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ consider\ the\ subcase\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ ZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymnoteq}\ ZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ By\ assumption\ we\ know\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ fst\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ From\ this\ we\ can\ infer\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ by\ IH\ also\ {\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ r\isactrlsub {\isadigit{2}}\ {\isasymrightarrow}\ {\isacharparenleft}{\kern0pt}snd\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ v{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ Given\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ ZERO{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ we\ know\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}L\ {\isacharparenleft}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isacharbraceleft}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ By\ the\ first\ statement\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}L\ r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ is\ the\ empty\ set{\isacharcomma}{\kern0pt}\ meaning\ {\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymnotin}\ L\ r\isactrlsub {\isadigit{1}}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ Taking\ {\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ and\ {\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ together\ gives\ by\ the\ {\isacharbackslash}{\kern0pt}mbox{\isacharbraceleft}{\kern0pt}{\isasymopen}P{\isacharplus}{\kern0pt}R{\isasymclose}{\isacharbraceright}{\kern0pt}{\isacharminus}{\kern0pt}rule\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}\ {\isasymrightarrow}\ Right\ {\isacharparenleft}{\kern0pt}snd\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ v{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ In\ turn\ this\ gives\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}\ {\isasymrightarrow}\ snd\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}ALT\ r\isactrlsub {\isadigit{1}}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ as\ we\ need\ to\ show{\isachardot}{\kern0pt}\ The\ other\ cases\ are\ similar{\isachardot}{\kern0pt}{\isacharbackslash}{\kern0pt}qed\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}proof{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}noindent\ We\ can\ now\ prove\ relatively\ straightforwardly\ that\ the\ optimised\ lexer\ produces\ the\ expected\ result{\isacharcolon}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}thm\ slexer{\isacharunderscore}{\kern0pt}correctness{\isacharbraceright}{\kern0pt}\ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}theorem{\isacharbraceright}{\kern0pt}\ \ {\isacharbackslash}{\kern0pt}begin{\isacharbraceleft}{\kern0pt}proof{\isacharbraceright}{\kern0pt}\ By\ induction\ on\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ s{\isacharbraceright}{\kern0pt}\ generalising\ over\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ The\ case\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ is\ trivial{\isachardot}{\kern0pt}\ For\ the\ cons{\isacharminus}{\kern0pt}case\ suppose\ the\ string\ is\ of\ the\ form\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}c\ {\isacharhash}{\kern0pt}\ s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ By\ induction\ hypothesis\ we\ know\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}slexer\ r\ s\ {\isacharequal}{\kern0pt}\ lexer\ r\ s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ holds\ for\ all\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ r{\isacharbraceright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}in\ particular\ for\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ being\ the\ derivative\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}der\ c\ r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}\ Let\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}r\isactrlsub s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ be\ the\ simplified\ derivative\ regular\ expression{\isacharcomma}{\kern0pt}\ that\ is\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharcomma}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}f\isactrlsub r{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ be\ the\ rectification\ function{\isacharcomma}{\kern0pt}\ that\ is\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}snd\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ \ We\ distinguish\ the\ cases\ whether\ {\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ L\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ or\ not{\isachardot}{\kern0pt}\ In\ the\ first\ case\ we\ have\ by\ Theorem{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}lexercorrect{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}\ a\ value\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ so\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}lexer\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}\ s\ {\isacharequal}{\kern0pt}\ Some\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ der\ c\ r\ {\isasymrightarrow}\ v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ hold{\isachardot}{\kern0pt}\ By\ Lemma{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}slexeraux{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}\ we\ can\ also\ infer\ from{\isachartilde}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isacharasterisk}{\kern0pt}{\isacharparenright}{\kern0pt}\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ L\ r\isactrlsub s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ holds{\isachardot}{\kern0pt}\ \ Hence\ we\ know\ by\ Theorem{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}lexercorrect{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}\ that\ there\ exists\ a\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}v{\isacharprime}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ with\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}lexer\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ Some\ v{\isacharprime}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ r\isactrlsub s\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ From\ the\ latter\ we\ know\ by\ Lemma{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}slexeraux{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{2}}{\isacharparenright}{\kern0pt}\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymin}\ der\ c\ r\ {\isasymrightarrow}\ {\isacharparenleft}{\kern0pt}f\isactrlsub r\ v{\isacharprime}{\kern0pt}{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ holds{\isachardot}{\kern0pt}\ By\ the\ uniqueness\ of\ the\ POSIX\ relation\ {\isacharparenleft}{\kern0pt}Theorem{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}posixdeterm{\isacharbraceright}{\kern0pt}{\isacharparenright}{\kern0pt}\ we\ can\ infer\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ v{\isacharbraceright}{\kern0pt}\ is\ equal\ to\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}f\isactrlsub r\ v{\isacharprime}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isacharminus}{\kern0pt}{\isacharminus}{\kern0pt}{\isacharminus}{\kern0pt}that\ is\ the\ rectification\ function\ applied\ to\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}v{\isacharprime}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ produces\ the\ original\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}v{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ \ Now\ the\ case\ follows\ by\ the\ definitions\ of\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ lexer{\isacharbraceright}{\kern0pt}\ and\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}const\ slexer{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ \ In\ the\ second\ case\ where\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymnotin}\ L\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ we\ have\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}lexer\ {\isacharparenleft}{\kern0pt}der\ c\ r{\isacharparenright}{\kern0pt}\ s\ {\isacharequal}{\kern0pt}\ None{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ by\ Theorem{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}lexercorrect{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}\ \ We\ also\ know\ by\ Lemma{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}slexeraux{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}\ that\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}s\ {\isasymnotin}\ L\ r\isactrlsub s{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ Hence\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}lexer\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ None{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}\ by\ Theorem{\isachartilde}{\kern0pt}{\isacharbackslash}{\kern0pt}ref{\isacharbraceleft}{\kern0pt}lexercorrect{\isacharbraceright}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isadigit{1}}{\isacharparenright}{\kern0pt}\ and\ by\ IH\ then\ also\ {\isacharat}{\kern0pt}{\isacharbraceleft}{\kern0pt}term\ {\isachardoublequote}{\kern0pt}slexer\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ None{\isachardoublequote}{\kern0pt}{\isacharbraceright}{\kern0pt}{\isachardot}{\kern0pt}\ With\ this\ we\ can\ conclude\ in\ this\ case\ too{\isachardot}{\kern0pt}{\isacharbackslash}{\kern0pt}qed\ \ {\isacharbackslash}{\kern0pt}end{\isacharbraceleft}{\kern0pt}proof{\isacharbraceright}{\kern0pt}\ \ }
       
  1609 fy the result. This gives us a simplified derivative
       
  1610   \isa{r\isactrlsub s} and a rectification function \isa{f\isactrlsub r}. The lexer
       
  1611   is then recursively called with the simplified derivative, but before
       
  1612   we inject the character \isa{c} into the value \isa{v}, we need to rectify
       
  1613   \isa{v} (that is construct \isa{f\isactrlsub r\ v}). Before we can establish the correctness
       
  1614   of \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}}, we need to show that simplification preserves the language
       
  1615   and simplification preserves our POSIX relation once the value is rectified
       
  1616   (recall \isa{simp} generates a (regular expression, rectification function) pair):
       
  1617 
       
  1618   \begin{lemma}\mbox{}\smallskip\\\label{slexeraux}
       
  1619   \begin{tabular}{ll}
       
  1620   (1) & \isa{L{\isacharparenleft}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ L{\isacharparenleft}{\kern0pt}r{\isacharparenright}{\kern0pt}}\\
       
  1621   (2) & \isa{{\normalsize{}If\,}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ fst\ {\isacharparenleft}{\kern0pt}simp\ r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v\ {\normalsize \,then\,}\ {\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ snd\ {\isacharparenleft}{\kern0pt}simp\ r{\isacharparenright}{\kern0pt}\ v{\isachardot}{\kern0pt}}
       
  1622   \end{tabular}
       
  1623   \end{lemma}
       
  1624 
       
  1625   \begin{proof} Both are by induction on \isa{r}. There is no
       
  1626   interesting case for the first statement. For the second statement,
       
  1627   of interest are the \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}} and \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isasymcdot}\ r\isactrlsub {\isadigit{2}}} cases. In each case we have to analyse four subcases whether
       
  1628   \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}} and \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}} equals \isa{\isactrlbold {\isadigit{0}}} (respectively \isa{\isactrlbold {\isadigit{1}}}). For example for \isa{r\ {\isacharequal}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}}, consider the subcase \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ \isactrlbold {\isadigit{0}}} and
       
  1629   \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymnoteq}\ \isactrlbold {\isadigit{0}}}. By assumption we know \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ fst\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}. From this we can infer \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v}
       
  1630   and by IH also (*) \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ snd\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ v}. Given \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ \isactrlbold {\isadigit{0}}}
       
  1631   we know \isa{L{\isacharparenleft}{\kern0pt}fst\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharequal}{\kern0pt}\ {\isasymemptyset}}. By the first statement
       
  1632   \isa{L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}} is the empty set, meaning (**) \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}{\isacharparenright}{\kern0pt}}.
       
  1633   Taking (*) and (**) together gives by the \mbox{\isa{P{\isacharplus}{\kern0pt}R}}-rule 
       
  1634   \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ Right\ {\isacharparenleft}{\kern0pt}snd\ {\isacharparenleft}{\kern0pt}simp\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ v{\isacharparenright}{\kern0pt}}. In turn this
       
  1635   gives \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ snd\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\ {\isacharplus}{\kern0pt}\ r\isactrlsub {\isadigit{2}}{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ v} as we need to show.
       
  1636   The other cases are similar.\qed
       
  1637   \end{proof}
       
  1638 
       
  1639   \noindent We can now prove relatively straightforwardly that the
       
  1640   optimised lexer produces the expected result:
       
  1641 
       
  1642   \begin{theorem}
       
  1643   \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\ s\ {\isacharequal}{\kern0pt}\ lexer\ r\ s}
       
  1644   \end{theorem}
       
  1645 
       
  1646   \begin{proof} By induction on \isa{s} generalising over \isa{r}. The case \isa{{\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}} is trivial. For the cons-case suppose the
       
  1647   string is of the form \isa{c\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}s}. By induction hypothesis we
       
  1648   know \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\ s\ {\isacharequal}{\kern0pt}\ lexer\ r\ s} holds for all \isa{r} (in
       
  1649   particular for \isa{r} being the derivative \isa{r{\isacharbackslash}{\kern0pt}c}). Let \isa{r\isactrlsub s} be the simplified derivative regular expression, that is \isa{fst\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}}, and \isa{f\isactrlsub r} be the rectification
       
  1650   function, that is \isa{snd\ {\isacharparenleft}{\kern0pt}simp\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}}.  We distinguish the cases
       
  1651   whether (*) \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}} or not. In the first case we
       
  1652   have by Theorem~\ref{lexercorrect}(2) a value \isa{v} so that \isa{lexer\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ s\ {\isacharequal}{\kern0pt}\ Some\ v} and \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v} hold.
       
  1653   By Lemma~\ref{slexeraux}(1) we can also infer from~(*) that \isa{s\ {\isasymin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub s{\isacharparenright}{\kern0pt}} holds.  Hence we know by Theorem~\ref{lexercorrect}(2) that
       
  1654   there exists a \isa{v{\isacharprime}{\kern0pt}} with \isa{lexer\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ Some\ v{\isacharprime}{\kern0pt}} and
       
  1655   \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r\isactrlsub s{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ v{\isacharprime}{\kern0pt}}. From the latter we know by
       
  1656   Lemma~\ref{slexeraux}(2) that \isa{{\isacharparenleft}{\kern0pt}s{\isacharcomma}{\kern0pt}\ r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymrightarrow}\ f\isactrlsub r\ v{\isacharprime}{\kern0pt}} holds.
       
  1657   By the uniqueness of the POSIX relation (Theorem~\ref{posixdeterm}) we
       
  1658   can infer that \isa{v} is equal to \isa{f\isactrlsub r\ v{\isacharprime}{\kern0pt}}---that is the 
       
  1659   rectification function applied to \isa{v{\isacharprime}{\kern0pt}}
       
  1660   produces the original \isa{v}.  Now the case follows by the
       
  1661   definitions of \isa{lexer} and \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}}.
       
  1662 
       
  1663   In the second case where \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}} we have that
       
  1664   \isa{lexer\ {\isacharparenleft}{\kern0pt}r{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ s\ {\isacharequal}{\kern0pt}\ None} by Theorem~\ref{lexercorrect}(1).  We
       
  1665   also know by Lemma~\ref{slexeraux}(1) that \isa{s\ {\isasymnotin}\ L{\isacharparenleft}{\kern0pt}r\isactrlsub s{\isacharparenright}{\kern0pt}}. Hence
       
  1666   \isa{lexer\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ None} by Theorem~\ref{lexercorrect}(1) and
       
  1667   by IH then also \isa{lexer\isactrlsup {\isacharplus}{\kern0pt}\ r\isactrlsub s\ s\ {\isacharequal}{\kern0pt}\ None}. With this we can
       
  1668   conclude in this case too.\qed   
       
  1669 
       
  1670   \end{proof}%
       
  1671 \end{isamarkuptext}\isamarkuptrue%
       
  1672 %
       
  1673 \isadelimdocument
       
  1674 %
       
  1675 \endisadelimdocument
       
  1676 %
       
  1677 \isatagdocument
       
  1678 %
       
  1679 \isamarkupsection{HERE%
       
  1680 }
       
  1681 \isamarkuptrue%
       
  1682 %
       
  1683 \endisatagdocument
       
  1684 {\isafolddocument}%
       
  1685 %
       
  1686 \isadelimdocument
       
  1687 %
       
  1688 \endisadelimdocument
       
  1689 %
       
  1690 \begin{isamarkuptext}%
       
  1691 \begin{lemma}
       
  1692   \isa{{\normalsize{}If\,}\ v\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c\ {\normalsize \,then\,}\ retrieve\ {\isacharparenleft}{\kern0pt}r\mbox{$\bbslash$}c{\isacharparenright}{\kern0pt}\ v\ {\isacharequal}{\kern0pt}\ retrieve\ r\ {\isacharparenleft}{\kern0pt}inj\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\ c\ v{\isacharparenright}{\kern0pt}{\isachardot}{\kern0pt}}
       
  1693   \end{lemma}
       
  1694 
       
  1695   \begin{proof}
       
  1696   By induction on the definition of \isa{r\mbox{$^\downarrow$}}. The cases for rule 1) and 2) are
       
  1697   straightforward as \isa{\isactrlbold {\isadigit{0}}{\isacharbackslash}{\kern0pt}c} and \isa{\isactrlbold {\isadigit{1}}{\isacharbackslash}{\kern0pt}c} are both equal to 
       
  1698   \isa{\isactrlbold {\isadigit{0}}}. This means \isa{v\ {\isacharcolon}{\kern0pt}\ \isactrlbold {\isadigit{0}}} cannot hold. Similarly in case of rule 3)
       
  1699   where \isa{r} is of the form \isa{ACHAR\ d} with \isa{c\ {\isacharequal}{\kern0pt}\ d}. Then by assumption
       
  1700   we know \isa{v\ {\isacharcolon}{\kern0pt}\ \isactrlbold {\isadigit{1}}}, which implies \isa{v\ {\isacharequal}{\kern0pt}\ Empty}. The equation follows by 
       
  1701   simplification of left- and right-hand side. In  case \isa{c\ {\isasymnoteq}\ d} we have again
       
  1702   \isa{v\ {\isacharcolon}{\kern0pt}\ \isactrlbold {\isadigit{0}}}, which cannot  hold. 
       
  1703 
       
  1704   For rule 4a) we have again \isa{v\ {\isacharcolon}{\kern0pt}\ \isactrlbold {\isadigit{0}}}. The property holds by IH for rule 4b).
       
  1705   The  induction hypothesis is 
       
  1706   \[
       
  1707   \isa{retrieve\ {\isacharparenleft}{\kern0pt}r\mbox{$\bbslash$}c{\isacharparenright}{\kern0pt}\ v\ {\isacharequal}{\kern0pt}\ retrieve\ r\ {\isacharparenleft}{\kern0pt}inj\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\ c\ v{\isacharparenright}{\kern0pt}}
       
  1708   \]
       
  1709   which is what left- and right-hand side simplify to.  The slightly more interesting case
       
  1710   is for 4c). By assumption  we have 
       
  1711   \isa{v\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isacharplus}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}AALTs\ bs\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}rs{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}}. This means we 
       
  1712   have either (*) \isa{v{\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{1}}\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} with \isa{v\ {\isacharequal}{\kern0pt}\ Left\ v{\isadigit{1}}} or
       
  1713   (**) \isa{v{\isadigit{2}}\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}AALTs\ bs\ {\isacharparenleft}{\kern0pt}r\isactrlsub {\isadigit{2}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}rs{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c} with \isa{v\ {\isacharequal}{\kern0pt}\ Right\ v{\isadigit{2}}}.
       
  1714   The former  case is straightforward by simplification. The second case is \ldots TBD.
       
  1715 
       
  1716   Rule 5) TBD.
       
  1717 
       
  1718   Finally for rule 6) the reasoning is as follows:   By assumption we  have
       
  1719   \isa{v\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c{\isacharparenright}{\kern0pt}\ {\isasymcdot}\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}}. This means we also have
       
  1720   \isa{v\ {\isacharequal}{\kern0pt}\ Seq\ v{\isadigit{1}}\ v{\isadigit{2}}}, \isa{v{\isadigit{1}}\ {\isacharcolon}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}{\isacharbackslash}{\kern0pt}c}  and \isa{v{\isadigit{2}}\ {\isacharequal}{\kern0pt}\ Stars\ vs}.
       
  1721   We want to prove
       
  1722   \begin{align}
       
  1723   & \isa{retrieve\ {\isacharparenleft}{\kern0pt}ASEQ\ bs\ {\isacharparenleft}{\kern0pt}fuse\ {\isacharbrackleft}{\kern0pt}Z{\isacharbrackright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\mbox{$\bbslash$}c{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}ASTAR\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ r{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ v}\\
       
  1724   &= \isa{retrieve\ {\isacharparenleft}{\kern0pt}ASTAR\ bs\ r{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}inj\ {\isacharparenleft}{\kern0pt}{\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\isactrlsup {\isasymstar}{\isacharparenright}{\kern0pt}\ c\ v{\isacharparenright}{\kern0pt}}
       
  1725   \end{align}
       
  1726   The right-hand side \isa{inj}-expression is equal to 
       
  1727   \isa{Stars\ {\isacharparenleft}{\kern0pt}inj\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\ c\ v{\isadigit{1}}\mbox{$\,$}{\isacharcolon}{\kern0pt}{\isacharcolon}{\kern0pt}\mbox{$\,$}vs{\isacharparenright}{\kern0pt}}, which means the \isa{retrieve}-expression
       
  1728   simplifies to 
       
  1729   \[
       
  1730   \isa{bs\ {\isacharat}{\kern0pt}\ {\isacharbrackleft}{\kern0pt}Z{\isacharbrackright}{\kern0pt}\ {\isacharat}{\kern0pt}\ retrieve\ r\ {\isacharparenleft}{\kern0pt}inj\ {\isacharparenleft}{\kern0pt}r\mbox{$^\downarrow$}{\isacharparenright}{\kern0pt}\ c\ v{\isadigit{1}}{\isacharparenright}{\kern0pt}\ {\isacharat}{\kern0pt}\ retrieve\ {\isacharparenleft}{\kern0pt}ASTAR\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}Stars\ vs{\isacharparenright}{\kern0pt}}
       
  1731   \]
       
  1732   The left-hand side (3) above simplifies to 
       
  1733   \[
       
  1734   \isa{bs\ {\isacharat}{\kern0pt}\ retrieve\ {\isacharparenleft}{\kern0pt}fuse\ {\isacharbrackleft}{\kern0pt}Z{\isacharbrackright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}r\mbox{$\bbslash$}c{\isacharparenright}{\kern0pt}{\isacharparenright}{\kern0pt}\ v{\isadigit{1}}\ {\isacharat}{\kern0pt}\ retrieve\ {\isacharparenleft}{\kern0pt}ASTAR\ {\isacharbrackleft}{\kern0pt}{\isacharbrackright}{\kern0pt}\ r{\isacharparenright}{\kern0pt}\ {\isacharparenleft}{\kern0pt}Stars\ vs{\isacharparenright}{\kern0pt}} 
       
  1735   \]
       
  1736   We can move out the \isa{fuse\ {\isacharbrackleft}{\kern0pt}Z{\isacharbrackright}{\kern0pt}} and then use the IH to show that left-hand side
       
  1737   and right-hand side are equal. This completes the proof. 
       
  1738   \end{proof}   
       
  1739 
       
  1740    
       
  1741 
       
  1742   \bibliographystyle{plain}
       
  1743   \bibliography{root}%
       
  1744 \end{isamarkuptext}\isamarkuptrue%
       
  1745 %
       
  1746 \isadelimtheory
       
  1747 %
       
  1748 \endisadelimtheory
       
  1749 %
       
  1750 \isatagtheory
       
  1751 %
       
  1752 \endisatagtheory
       
  1753 {\isafoldtheory}%
       
  1754 %
       
  1755 \isadelimtheory
       
  1756 \isanewline
       
  1757 %
       
  1758 \endisadelimtheory
       
  1759 \isanewline
       
  1760 \isanewline
       
  1761 %
       
  1762 \end{isabellebody}%
       
  1763 \endinput
       
  1764 %:%file=~/Dropbox/Workspace/journalpaper/lexing/thys2/Journal/Paper.thy%:%
       
  1765 %:%50=134%:%
       
  1766 %:%62=136%:%
       
  1767 %:%63=137%:%
       
  1768 %:%64=138%:%
       
  1769 %:%65=139%:%
       
  1770 %:%66=140%:%
       
  1771 %:%67=141%:%
       
  1772 %:%68=142%:%
       
  1773 %:%69=143%:%
       
  1774 %:%70=144%:%
       
  1775 %:%71=145%:%
       
  1776 %:%72=146%:%
       
  1777 %:%73=147%:%
       
  1778 %:%74=148%:%
       
  1779 %:%75=149%:%
       
  1780 %:%76=150%:%
       
  1781 %:%77=151%:%
       
  1782 %:%78=152%:%
       
  1783 %:%79=153%:%
       
  1784 %:%80=154%:%
       
  1785 %:%81=155%:%
       
  1786 %:%82=156%:%
       
  1787 %:%83=157%:%
       
  1788 %:%84=158%:%
       
  1789 %:%85=159%:%
       
  1790 %:%86=160%:%
       
  1791 %:%87=161%:%
       
  1792 %:%88=162%:%
       
  1793 %:%89=163%:%
       
  1794 %:%90=164%:%
       
  1795 %:%91=165%:%
       
  1796 %:%92=166%:%
       
  1797 %:%93=167%:%
       
  1798 %:%94=168%:%
       
  1799 %:%95=169%:%
       
  1800 %:%96=170%:%
       
  1801 %:%97=171%:%
       
  1802 %:%98=172%:%
       
  1803 %:%99=173%:%
       
  1804 %:%100=174%:%
       
  1805 %:%101=175%:%
       
  1806 %:%102=176%:%
       
  1807 %:%103=177%:%
       
  1808 %:%104=178%:%
       
  1809 %:%105=179%:%
       
  1810 %:%106=180%:%
       
  1811 %:%107=181%:%
       
  1812 %:%108=182%:%
       
  1813 %:%109=183%:%
       
  1814 %:%110=184%:%
       
  1815 %:%111=185%:%
       
  1816 %:%112=186%:%
       
  1817 %:%113=187%:%
       
  1818 %:%114=188%:%
       
  1819 %:%115=189%:%
       
  1820 %:%116=190%:%
       
  1821 %:%117=191%:%
       
  1822 %:%118=192%:%
       
  1823 %:%119=193%:%
       
  1824 %:%120=194%:%
       
  1825 %:%121=195%:%
       
  1826 %:%122=196%:%
       
  1827 %:%123=197%:%
       
  1828 %:%124=198%:%
       
  1829 %:%125=199%:%
       
  1830 %:%126=200%:%
       
  1831 %:%127=201%:%
       
  1832 %:%128=202%:%
       
  1833 %:%129=203%:%
       
  1834 %:%130=204%:%
       
  1835 %:%131=205%:%
       
  1836 %:%132=206%:%
       
  1837 %:%133=207%:%
       
  1838 %:%134=208%:%
       
  1839 %:%135=209%:%
       
  1840 %:%136=210%:%
       
  1841 %:%137=211%:%
       
  1842 %:%138=212%:%
       
  1843 %:%139=213%:%
       
  1844 %:%140=214%:%
       
  1845 %:%141=215%:%
       
  1846 %:%142=216%:%
       
  1847 %:%143=217%:%
       
  1848 %:%144=218%:%
       
  1849 %:%145=219%:%
       
  1850 %:%146=220%:%
       
  1851 %:%147=221%:%
       
  1852 %:%148=222%:%
       
  1853 %:%149=223%:%
       
  1854 %:%150=224%:%
       
  1855 %:%151=225%:%
       
  1856 %:%152=226%:%
       
  1857 %:%153=227%:%
       
  1858 %:%154=228%:%
       
  1859 %:%155=229%:%
       
  1860 %:%156=230%:%
       
  1861 %:%157=231%:%
       
  1862 %:%158=232%:%
       
  1863 %:%159=233%:%
       
  1864 %:%160=234%:%
       
  1865 %:%161=235%:%
       
  1866 %:%162=236%:%
       
  1867 %:%163=237%:%
       
  1868 %:%164=238%:%
       
  1869 %:%165=239%:%
       
  1870 %:%166=240%:%
       
  1871 %:%167=241%:%
       
  1872 %:%168=242%:%
       
  1873 %:%169=243%:%
       
  1874 %:%170=244%:%
       
  1875 %:%171=245%:%
       
  1876 %:%172=246%:%
       
  1877 %:%173=247%:%
       
  1878 %:%174=248%:%
       
  1879 %:%175=249%:%
       
  1880 %:%176=250%:%
       
  1881 %:%177=251%:%
       
  1882 %:%178=252%:%
       
  1883 %:%179=253%:%
       
  1884 %:%180=254%:%
       
  1885 %:%181=255%:%
       
  1886 %:%182=256%:%
       
  1887 %:%183=257%:%
       
  1888 %:%184=258%:%
       
  1889 %:%185=259%:%
       
  1890 %:%186=260%:%
       
  1891 %:%187=261%:%
       
  1892 %:%188=262%:%
       
  1893 %:%189=263%:%
       
  1894 %:%190=264%:%
       
  1895 %:%191=265%:%
       
  1896 %:%192=266%:%
       
  1897 %:%193=267%:%
       
  1898 %:%194=268%:%
       
  1899 %:%203=272%:%
       
  1900 %:%215=276%:%
       
  1901 %:%216=277%:%
       
  1902 %:%217=278%:%
       
  1903 %:%218=279%:%
       
  1904 %:%219=280%:%
       
  1905 %:%220=281%:%
       
  1906 %:%221=282%:%
       
  1907 %:%222=283%:%
       
  1908 %:%223=284%:%
       
  1909 %:%224=285%:%
       
  1910 %:%225=286%:%
       
  1911 %:%226=287%:%
       
  1912 %:%227=288%:%
       
  1913 %:%228=289%:%
       
  1914 %:%229=290%:%
       
  1915 %:%230=291%:%
       
  1916 %:%231=292%:%
       
  1917 %:%240=299%:%
       
  1918 %:%252=305%:%
       
  1919 %:%253=306%:%
       
  1920 %:%254=307%:%
       
  1921 %:%255=308%:%
       
  1922 %:%255=309%:%
       
  1923 %:%256=310%:%
       
  1924 %:%257=311%:%
       
  1925 %:%258=312%:%
       
  1926 %:%259=313%:%
       
  1927 %:%260=314%:%
       
  1928 %:%261=315%:%
       
  1929 %:%262=316%:%
       
  1930 %:%263=317%:%
       
  1931 %:%264=318%:%
       
  1932 %:%265=319%:%
       
  1933 %:%266=320%:%
       
  1934 %:%267=321%:%
       
  1935 %:%268=322%:%
       
  1936 %:%269=323%:%
       
  1937 %:%270=324%:%
       
  1938 %:%271=325%:%
       
  1939 %:%272=326%:%
       
  1940 %:%273=327%:%
       
  1941 %:%274=328%:%
       
  1942 %:%275=329%:%
       
  1943 %:%276=330%:%
       
  1944 %:%277=331%:%
       
  1945 %:%278=332%:%
       
  1946 %:%279=333%:%
       
  1947 %:%280=334%:%
       
  1948 %:%281=335%:%
       
  1949 %:%282=336%:%
       
  1950 %:%283=337%:%
       
  1951 %:%284=338%:%
       
  1952 %:%285=339%:%
       
  1953 %:%286=340%:%
       
  1954 %:%287=341%:%
       
  1955 %:%288=342%:%
       
  1956 %:%289=343%:%
       
  1957 %:%290=344%:%
       
  1958 %:%291=345%:%
       
  1959 %:%292=346%:%
       
  1960 %:%293=347%:%
       
  1961 %:%294=348%:%
       
  1962 %:%295=349%:%
       
  1963 %:%296=350%:%
       
  1964 %:%297=351%:%
       
  1965 %:%298=352%:%
       
  1966 %:%299=353%:%
       
  1967 %:%300=354%:%
       
  1968 %:%301=355%:%
       
  1969 %:%302=356%:%
       
  1970 %:%303=357%:%
       
  1971 %:%304=358%:%
       
  1972 %:%305=359%:%
       
  1973 %:%306=360%:%
       
  1974 %:%307=361%:%
       
  1975 %:%308=362%:%
       
  1976 %:%309=363%:%
       
  1977 %:%310=364%:%
       
  1978 %:%311=365%:%
       
  1979 %:%312=366%:%
       
  1980 %:%313=367%:%
       
  1981 %:%314=368%:%
       
  1982 %:%315=369%:%
       
  1983 %:%316=370%:%
       
  1984 %:%317=371%:%
       
  1985 %:%318=372%:%
       
  1986 %:%319=373%:%
       
  1987 %:%319=374%:%
       
  1988 %:%320=375%:%
       
  1989 %:%321=376%:%
       
  1990 %:%322=377%:%
       
  1991 %:%323=378%:%
       
  1992 %:%324=379%:%
       
  1993 %:%325=380%:%
       
  1994 %:%326=381%:%
       
  1995 %:%327=382%:%
       
  1996 %:%328=383%:%
       
  1997 %:%329=384%:%
       
  1998 %:%330=385%:%
       
  1999 %:%331=386%:%
       
  2000 %:%332=387%:%
       
  2001 %:%333=388%:%
       
  2002 %:%334=389%:%
       
  2003 %:%335=390%:%
       
  2004 %:%336=391%:%
       
  2005 %:%337=392%:%
       
  2006 %:%338=393%:%
       
  2007 %:%339=394%:%
       
  2008 %:%340=395%:%
       
  2009 %:%341=396%:%
       
  2010 %:%342=397%:%
       
  2011 %:%343=398%:%
       
  2012 %:%344=399%:%
       
  2013 %:%345=400%:%
       
  2014 %:%346=401%:%
       
  2015 %:%347=402%:%
       
  2016 %:%348=403%:%
       
  2017 %:%349=404%:%
       
  2018 %:%350=405%:%
       
  2019 %:%351=406%:%
       
  2020 %:%352=407%:%
       
  2021 %:%353=408%:%
       
  2022 %:%354=409%:%
       
  2023 %:%355=410%:%
       
  2024 %:%356=411%:%
       
  2025 %:%357=412%:%
       
  2026 %:%358=413%:%
       
  2027 %:%359=414%:%
       
  2028 %:%360=415%:%
       
  2029 %:%361=416%:%
       
  2030 %:%362=417%:%
       
  2031 %:%363=418%:%
       
  2032 %:%364=419%:%
       
  2033 %:%365=420%:%
       
  2034 %:%366=421%:%
       
  2035 %:%367=422%:%
       
  2036 %:%368=423%:%
       
  2037 %:%369=424%:%
       
  2038 %:%370=425%:%
       
  2039 %:%371=426%:%
       
  2040 %:%372=427%:%
       
  2041 %:%373=428%:%
       
  2042 %:%374=429%:%
       
  2043 %:%375=430%:%
       
  2044 %:%376=431%:%
       
  2045 %:%377=432%:%
       
  2046 %:%378=433%:%
       
  2047 %:%379=434%:%
       
  2048 %:%380=435%:%
       
  2049 %:%381=436%:%
       
  2050 %:%382=437%:%
       
  2051 %:%383=438%:%
       
  2052 %:%384=439%:%
       
  2053 %:%385=440%:%
       
  2054 %:%386=441%:%
       
  2055 %:%387=442%:%
       
  2056 %:%388=443%:%
       
  2057 %:%389=444%:%
       
  2058 %:%390=445%:%
       
  2059 %:%391=446%:%
       
  2060 %:%392=447%:%
       
  2061 %:%393=448%:%
       
  2062 %:%394=449%:%
       
  2063 %:%395=450%:%
       
  2064 %:%396=451%:%
       
  2065 %:%397=452%:%
       
  2066 %:%398=453%:%
       
  2067 %:%399=454%:%
       
  2068 %:%400=455%:%
       
  2069 %:%401=456%:%
       
  2070 %:%402=457%:%
       
  2071 %:%403=458%:%
       
  2072 %:%404=459%:%
       
  2073 %:%405=460%:%
       
  2074 %:%406=461%:%
       
  2075 %:%407=462%:%
       
  2076 %:%408=463%:%
       
  2077 %:%409=464%:%
       
  2078 %:%410=465%:%
       
  2079 %:%411=466%:%
       
  2080 %:%412=467%:%
       
  2081 %:%413=468%:%
       
  2082 %:%414=469%:%
       
  2083 %:%415=470%:%
       
  2084 %:%416=471%:%
       
  2085 %:%417=472%:%
       
  2086 %:%418=473%:%
       
  2087 %:%419=474%:%
       
  2088 %:%420=475%:%
       
  2089 %:%421=476%:%
       
  2090 %:%422=477%:%
       
  2091 %:%423=478%:%
       
  2092 %:%424=479%:%
       
  2093 %:%433=486%:%
       
  2094 %:%445=488%:%
       
  2095 %:%446=489%:%
       
  2096 %:%446=490%:%
       
  2097 %:%447=491%:%
       
  2098 %:%448=492%:%
       
  2099 %:%449=493%:%
       
  2100 %:%450=494%:%
       
  2101 %:%451=495%:%
       
  2102 %:%452=496%:%
       
  2103 %:%453=497%:%
       
  2104 %:%454=498%:%
       
  2105 %:%455=499%:%
       
  2106 %:%456=500%:%
       
  2107 %:%457=501%:%
       
  2108 %:%458=502%:%
       
  2109 %:%459=503%:%
       
  2110 %:%460=504%:%
       
  2111 %:%461=505%:%
       
  2112 %:%462=506%:%
       
  2113 %:%463=507%:%
       
  2114 %:%464=508%:%
       
  2115 %:%465=509%:%
       
  2116 %:%466=510%:%
       
  2117 %:%467=511%:%
       
  2118 %:%468=512%:%
       
  2119 %:%469=513%:%
       
  2120 %:%470=514%:%
       
  2121 %:%471=515%:%
       
  2122 %:%472=516%:%
       
  2123 %:%473=517%:%
       
  2124 %:%474=518%:%
       
  2125 %:%475=519%:%
       
  2126 %:%476=520%:%
       
  2127 %:%477=521%:%
       
  2128 %:%478=522%:%
       
  2129 %:%479=523%:%
       
  2130 %:%480=524%:%
       
  2131 %:%481=525%:%
       
  2132 %:%482=526%:%
       
  2133 %:%483=527%:%
       
  2134 %:%484=528%:%
       
  2135 %:%485=529%:%
       
  2136 %:%485=530%:%
       
  2137 %:%486=531%:%
       
  2138 %:%487=532%:%
       
  2139 %:%488=533%:%
       
  2140 %:%489=534%:%
       
  2141 %:%490=535%:%
       
  2142 %:%490=536%:%
       
  2143 %:%491=537%:%
       
  2144 %:%492=538%:%
       
  2145 %:%493=539%:%
       
  2146 %:%494=540%:%
       
  2147 %:%495=541%:%
       
  2148 %:%496=542%:%
       
  2149 %:%497=543%:%
       
  2150 %:%498=544%:%
       
  2151 %:%499=545%:%
       
  2152 %:%500=546%:%
       
  2153 %:%501=547%:%
       
  2154 %:%502=548%:%
       
  2155 %:%503=549%:%
       
  2156 %:%504=550%:%
       
  2157 %:%505=551%:%
       
  2158 %:%506=552%:%
       
  2159 %:%507=553%:%
       
  2160 %:%508=554%:%
       
  2161 %:%509=555%:%
       
  2162 %:%510=556%:%
       
  2163 %:%511=557%:%
       
  2164 %:%512=558%:%
       
  2165 %:%513=559%:%
       
  2166 %:%514=560%:%
       
  2167 %:%515=561%:%
       
  2168 %:%516=562%:%
       
  2169 %:%517=563%:%
       
  2170 %:%518=564%:%
       
  2171 %:%519=565%:%
       
  2172 %:%520=566%:%
       
  2173 %:%521=567%:%
       
  2174 %:%522=568%:%
       
  2175 %:%523=569%:%
       
  2176 %:%524=570%:%
       
  2177 %:%525=571%:%
       
  2178 %:%526=572%:%
       
  2179 %:%527=573%:%
       
  2180 %:%528=574%:%
       
  2181 %:%529=575%:%
       
  2182 %:%530=576%:%
       
  2183 %:%531=577%:%
       
  2184 %:%532=578%:%
       
  2185 %:%533=579%:%
       
  2186 %:%534=580%:%
       
  2187 %:%535=581%:%
       
  2188 %:%536=582%:%
       
  2189 %:%537=583%:%
       
  2190 %:%538=584%:%
       
  2191 %:%539=585%:%
       
  2192 %:%540=586%:%
       
  2193 %:%541=587%:%
       
  2194 %:%542=588%:%
       
  2195 %:%543=589%:%
       
  2196 %:%544=590%:%
       
  2197 %:%545=591%:%
       
  2198 %:%546=592%:%
       
  2199 %:%547=593%:%
       
  2200 %:%548=594%:%
       
  2201 %:%549=595%:%
       
  2202 %:%550=596%:%
       
  2203 %:%551=597%:%
       
  2204 %:%552=598%:%
       
  2205 %:%553=599%:%
       
  2206 %:%554=600%:%
       
  2207 %:%555=601%:%
       
  2208 %:%556=602%:%
       
  2209 %:%557=603%:%
       
  2210 %:%558=604%:%
       
  2211 %:%559=605%:%
       
  2212 %:%560=606%:%
       
  2213 %:%561=607%:%
       
  2214 %:%562=608%:%
       
  2215 %:%563=609%:%
       
  2216 %:%564=610%:%
       
  2217 %:%565=611%:%
       
  2218 %:%566=612%:%
       
  2219 %:%567=613%:%
       
  2220 %:%568=614%:%
       
  2221 %:%569=615%:%
       
  2222 %:%570=616%:%
       
  2223 %:%571=617%:%
       
  2224 %:%572=618%:%
       
  2225 %:%573=619%:%
       
  2226 %:%574=620%:%
       
  2227 %:%575=621%:%
       
  2228 %:%576=622%:%
       
  2229 %:%577=623%:%
       
  2230 %:%578=624%:%
       
  2231 %:%579=625%:%
       
  2232 %:%588=629%:%
       
  2233 %:%600=633%:%
       
  2234 %:%601=634%:%
       
  2235 %:%602=635%:%
       
  2236 %:%603=636%:%
       
  2237 %:%604=637%:%
       
  2238 %:%605=638%:%
       
  2239 %:%606=639%:%
       
  2240 %:%607=640%:%
       
  2241 %:%608=641%:%
       
  2242 %:%609=642%:%
       
  2243 %:%610=643%:%
       
  2244 %:%611=644%:%
       
  2245 %:%612=645%:%
       
  2246 %:%613=646%:%
       
  2247 %:%614=647%:%
       
  2248 %:%615=648%:%
       
  2249 %:%616=649%:%
       
  2250 %:%617=650%:%
       
  2251 %:%618=651%:%
       
  2252 %:%619=652%:%
       
  2253 %:%620=653%:%
       
  2254 %:%621=654%:%
       
  2255 %:%622=655%:%
       
  2256 %:%623=656%:%
       
  2257 %:%624=657%:%
       
  2258 %:%625=658%:%
       
  2259 %:%626=659%:%
       
  2260 %:%627=660%:%
       
  2261 %:%628=661%:%
       
  2262 %:%629=662%:%
       
  2263 %:%630=663%:%
       
  2264 %:%631=664%:%
       
  2265 %:%632=665%:%
       
  2266 %:%633=666%:%
       
  2267 %:%634=667%:%
       
  2268 %:%635=668%:%
       
  2269 %:%636=669%:%
       
  2270 %:%637=670%:%
       
  2271 %:%638=671%:%
       
  2272 %:%639=672%:%
       
  2273 %:%640=673%:%
       
  2274 %:%641=674%:%
       
  2275 %:%642=675%:%
       
  2276 %:%643=676%:%
       
  2277 %:%644=677%:%
       
  2278 %:%645=678%:%
       
  2279 %:%646=679%:%
       
  2280 %:%647=680%:%
       
  2281 %:%648=681%:%
       
  2282 %:%649=682%:%
       
  2283 %:%650=683%:%
       
  2284 %:%651=684%:%
       
  2285 %:%652=685%:%
       
  2286 %:%653=686%:%
       
  2287 %:%654=687%:%
       
  2288 %:%655=688%:%
       
  2289 %:%656=689%:%
       
  2290 %:%657=690%:%
       
  2291 %:%658=691%:%
       
  2292 %:%659=692%:%
       
  2293 %:%660=693%:%
       
  2294 %:%661=694%:%
       
  2295 %:%662=695%:%
       
  2296 %:%663=696%:%
       
  2297 %:%664=697%:%
       
  2298 %:%665=698%:%
       
  2299 %:%666=699%:%
       
  2300 %:%667=700%:%
       
  2301 %:%668=701%:%
       
  2302 %:%669=702%:%
       
  2303 %:%670=703%:%
       
  2304 %:%671=704%:%
       
  2305 %:%672=705%:%
       
  2306 %:%673=706%:%
       
  2307 %:%674=707%:%
       
  2308 %:%675=708%:%
       
  2309 %:%676=709%:%
       
  2310 %:%677=710%:%
       
  2311 %:%678=711%:%
       
  2312 %:%679=712%:%
       
  2313 %:%680=713%:%
       
  2314 %:%681=714%:%
       
  2315 %:%682=715%:%
       
  2316 %:%683=716%:%
       
  2317 %:%684=717%:%
       
  2318 %:%685=718%:%
       
  2319 %:%686=719%:%
       
  2320 %:%687=720%:%
       
  2321 %:%688=721%:%
       
  2322 %:%689=722%:%
       
  2323 %:%690=723%:%
       
  2324 %:%691=724%:%
       
  2325 %:%692=725%:%
       
  2326 %:%693=726%:%
       
  2327 %:%694=727%:%
       
  2328 %:%695=728%:%
       
  2329 %:%696=729%:%
       
  2330 %:%697=730%:%
       
  2331 %:%698=731%:%
       
  2332 %:%699=732%:%
       
  2333 %:%700=733%:%
       
  2334 %:%701=734%:%
       
  2335 %:%702=735%:%
       
  2336 %:%703=736%:%
       
  2337 %:%704=737%:%
       
  2338 %:%705=738%:%
       
  2339 %:%706=739%:%
       
  2340 %:%707=740%:%
       
  2341 %:%708=741%:%
       
  2342 %:%709=742%:%
       
  2343 %:%710=743%:%
       
  2344 %:%711=744%:%
       
  2345 %:%712=745%:%
       
  2346 %:%713=746%:%
       
  2347 %:%714=747%:%
       
  2348 %:%714=748%:%
       
  2349 %:%715=749%:%
       
  2350 %:%715=750%:%
       
  2351 %:%716=751%:%
       
  2352 %:%717=752%:%
       
  2353 %:%717=753%:%
       
  2354 %:%718=754%:%
       
  2355 %:%719=755%:%
       
  2356 %:%720=756%:%
       
  2357 %:%721=757%:%
       
  2358 %:%722=758%:%
       
  2359 %:%723=759%:%
       
  2360 %:%724=760%:%
       
  2361 %:%725=761%:%
       
  2362 %:%726=762%:%
       
  2363 %:%727=763%:%
       
  2364 %:%728=764%:%
       
  2365 %:%729=765%:%
       
  2366 %:%730=766%:%
       
  2367 %:%731=767%:%
       
  2368 %:%732=768%:%
       
  2369 %:%733=769%:%
       
  2370 %:%734=770%:%
       
  2371 %:%735=771%:%
       
  2372 %:%736=772%:%
       
  2373 %:%737=773%:%
       
  2374 %:%738=774%:%
       
  2375 %:%739=775%:%
       
  2376 %:%740=776%:%
       
  2377 %:%741=777%:%
       
  2378 %:%742=778%:%
       
  2379 %:%743=779%:%
       
  2380 %:%744=780%:%
       
  2381 %:%745=781%:%
       
  2382 %:%746=782%:%
       
  2383 %:%747=783%:%
       
  2384 %:%748=784%:%
       
  2385 %:%749=785%:%
       
  2386 %:%750=786%:%
       
  2387 %:%751=787%:%
       
  2388 %:%752=788%:%
       
  2389 %:%753=789%:%
       
  2390 %:%754=790%:%
       
  2391 %:%755=791%:%
       
  2392 %:%756=792%:%
       
  2393 %:%757=793%:%
       
  2394 %:%758=794%:%
       
  2395 %:%759=795%:%
       
  2396 %:%760=796%:%
       
  2397 %:%761=797%:%
       
  2398 %:%762=798%:%
       
  2399 %:%763=799%:%
       
  2400 %:%764=800%:%
       
  2401 %:%765=801%:%
       
  2402 %:%766=802%:%
       
  2403 %:%767=803%:%
       
  2404 %:%768=804%:%
       
  2405 %:%769=805%:%
       
  2406 %:%770=806%:%
       
  2407 %:%771=807%:%
       
  2408 %:%772=808%:%
       
  2409 %:%773=809%:%
       
  2410 %:%773=810%:%
       
  2411 %:%773=811%:%
       
  2412 %:%774=812%:%
       
  2413 %:%775=813%:%
       
  2414 %:%776=814%:%
       
  2415 %:%777=815%:%
       
  2416 %:%778=816%:%
       
  2417 %:%779=817%:%
       
  2418 %:%780=818%:%
       
  2419 %:%781=819%:%
       
  2420 %:%782=820%:%
       
  2421 %:%782=821%:%
       
  2422 %:%783=822%:%
       
  2423 %:%784=823%:%
       
  2424 %:%785=824%:%
       
  2425 %:%786=825%:%
       
  2426 %:%787=826%:%
       
  2427 %:%788=827%:%
       
  2428 %:%789=828%:%
       
  2429 %:%790=829%:%
       
  2430 %:%791=830%:%
       
  2431 %:%792=831%:%
       
  2432 %:%793=832%:%
       
  2433 %:%794=833%:%
       
  2434 %:%795=834%:%
       
  2435 %:%796=835%:%
       
  2436 %:%797=836%:%
       
  2437 %:%798=837%:%
       
  2438 %:%799=838%:%
       
  2439 %:%800=839%:%
       
  2440 %:%801=840%:%
       
  2441 %:%802=841%:%
       
  2442 %:%803=842%:%
       
  2443 %:%804=843%:%
       
  2444 %:%805=844%:%
       
  2445 %:%806=845%:%
       
  2446 %:%807=846%:%
       
  2447 %:%808=847%:%
       
  2448 %:%809=848%:%
       
  2449 %:%810=849%:%
       
  2450 %:%811=850%:%
       
  2451 %:%812=851%:%
       
  2452 %:%813=852%:%
       
  2453 %:%814=853%:%
       
  2454 %:%815=854%:%
       
  2455 %:%816=855%:%
       
  2456 %:%817=856%:%
       
  2457 %:%817=857%:%
       
  2458 %:%818=858%:%
       
  2459 %:%819=859%:%
       
  2460 %:%820=860%:%
       
  2461 %:%821=861%:%
       
  2462 %:%822=862%:%
       
  2463 %:%823=863%:%
       
  2464 %:%824=864%:%
       
  2465 %:%824=865%:%
       
  2466 %:%825=866%:%
       
  2467 %:%826=867%:%
       
  2468 %:%827=868%:%
       
  2469 %:%827=869%:%
       
  2470 %:%828=870%:%
       
  2471 %:%829=871%:%
       
  2472 %:%830=872%:%
       
  2473 %:%831=873%:%
       
  2474 %:%832=874%:%
       
  2475 %:%833=875%:%
       
  2476 %:%834=876%:%
       
  2477 %:%835=877%:%
       
  2478 %:%836=878%:%
       
  2479 %:%837=879%:%
       
  2480 %:%838=880%:%
       
  2481 %:%838=881%:%
       
  2482 %:%839=882%:%
       
  2483 %:%840=883%:%
       
  2484 %:%841=884%:%
       
  2485 %:%842=885%:%
       
  2486 %:%842=886%:%
       
  2487 %:%843=887%:%
       
  2488 %:%844=888%:%
       
  2489 %:%845=889%:%
       
  2490 %:%846=890%:%
       
  2491 %:%847=891%:%
       
  2492 %:%848=892%:%
       
  2493 %:%849=893%:%
       
  2494 %:%850=894%:%
       
  2495 %:%851=895%:%
       
  2496 %:%852=896%:%
       
  2497 %:%853=897%:%
       
  2498 %:%854=898%:%
       
  2499 %:%855=899%:%
       
  2500 %:%856=900%:%
       
  2501 %:%857=901%:%
       
  2502 %:%858=902%:%
       
  2503 %:%859=903%:%
       
  2504 %:%860=904%:%
       
  2505 %:%861=905%:%
       
  2506 %:%862=906%:%
       
  2507 %:%863=907%:%
       
  2508 %:%864=908%:%
       
  2509 %:%865=909%:%
       
  2510 %:%866=910%:%
       
  2511 %:%867=911%:%
       
  2512 %:%868=912%:%
       
  2513 %:%869=913%:%
       
  2514 %:%870=914%:%
       
  2515 %:%871=915%:%
       
  2516 %:%872=916%:%
       
  2517 %:%873=917%:%
       
  2518 %:%874=918%:%
       
  2519 %:%875=919%:%
       
  2520 %:%876=920%:%
       
  2521 %:%877=921%:%
       
  2522 %:%878=922%:%
       
  2523 %:%879=923%:%
       
  2524 %:%880=924%:%
       
  2525 %:%881=925%:%
       
  2526 %:%882=926%:%
       
  2527 %:%883=927%:%
       
  2528 %:%884=928%:%
       
  2529 %:%885=929%:%
       
  2530 %:%886=930%:%
       
  2531 %:%887=931%:%
       
  2532 %:%888=932%:%
       
  2533 %:%889=933%:%
       
  2534 %:%890=934%:%
       
  2535 %:%891=935%:%
       
  2536 %:%892=936%:%
       
  2537 %:%893=937%:%
       
  2538 %:%894=938%:%
       
  2539 %:%895=939%:%
       
  2540 %:%896=940%:%
       
  2541 %:%897=941%:%
       
  2542 %:%898=942%:%
       
  2543 %:%899=943%:%
       
  2544 %:%900=944%:%
       
  2545 %:%900=945%:%
       
  2546 %:%901=946%:%
       
  2547 %:%902=947%:%
       
  2548 %:%903=948%:%
       
  2549 %:%904=949%:%
       
  2550 %:%905=950%:%
       
  2551 %:%906=951%:%
       
  2552 %:%907=952%:%
       
  2553 %:%908=953%:%
       
  2554 %:%909=954%:%
       
  2555 %:%910=955%:%
       
  2556 %:%911=956%:%
       
  2557 %:%912=957%:%
       
  2558 %:%913=958%:%
       
  2559 %:%914=959%:%
       
  2560 %:%915=960%:%
       
  2561 %:%916=961%:%
       
  2562 %:%917=962%:%
       
  2563 %:%918=963%:%
       
  2564 %:%919=964%:%
       
  2565 %:%920=965%:%
       
  2566 %:%921=966%:%
       
  2567 %:%922=967%:%
       
  2568 %:%923=968%:%
       
  2569 %:%924=969%:%
       
  2570 %:%925=970%:%
       
  2571 %:%926=971%:%
       
  2572 %:%927=972%:%
       
  2573 %:%928=973%:%
       
  2574 %:%929=974%:%
       
  2575 %:%930=975%:%
       
  2576 %:%931=976%:%
       
  2577 %:%932=977%:%
       
  2578 %:%933=978%:%
       
  2579 %:%933=979%:%
       
  2580 %:%934=980%:%
       
  2581 %:%935=981%:%
       
  2582 %:%936=982%:%
       
  2583 %:%937=983%:%
       
  2584 %:%938=984%:%
       
  2585 %:%939=985%:%
       
  2586 %:%940=986%:%
       
  2587 %:%941=987%:%
       
  2588 %:%942=988%:%
       
  2589 %:%943=989%:%
       
  2590 %:%944=990%:%
       
  2591 %:%945=991%:%
       
  2592 %:%946=992%:%
       
  2593 %:%947=993%:%
       
  2594 %:%948=994%:%
       
  2595 %:%949=995%:%
       
  2596 %:%950=996%:%
       
  2597 %:%951=997%:%
       
  2598 %:%952=998%:%
       
  2599 %:%953=999%:%
       
  2600 %:%954=1000%:%
       
  2601 %:%955=1001%:%
       
  2602 %:%956=1002%:%
       
  2603 %:%957=1003%:%
       
  2604 %:%958=1004%:%
       
  2605 %:%959=1005%:%
       
  2606 %:%960=1006%:%
       
  2607 %:%961=1007%:%
       
  2608 %:%962=1008%:%
       
  2609 %:%963=1009%:%
       
  2610 %:%963=1010%:%
       
  2611 %:%964=1011%:%
       
  2612 %:%965=1012%:%
       
  2613 %:%966=1013%:%
       
  2614 %:%967=1014%:%
       
  2615 %:%968=1015%:%
       
  2616 %:%969=1016%:%
       
  2617 %:%970=1017%:%
       
  2618 %:%971=1018%:%
       
  2619 %:%971=1019%:%
       
  2620 %:%972=1020%:%
       
  2621 %:%973=1021%:%
       
  2622 %:%974=1022%:%
       
  2623 %:%975=1023%:%
       
  2624 %:%976=1024%:%
       
  2625 %:%977=1025%:%
       
  2626 %:%978=1026%:%
       
  2627 %:%979=1027%:%
       
  2628 %:%980=1028%:%
       
  2629 %:%981=1029%:%
       
  2630 %:%982=1030%:%
       
  2631 %:%983=1031%:%
       
  2632 %:%984=1032%:%
       
  2633 %:%985=1033%:%
       
  2634 %:%986=1034%:%
       
  2635 %:%987=1035%:%
       
  2636 %:%988=1036%:%
       
  2637 %:%989=1037%:%
       
  2638 %:%990=1038%:%
       
  2639 %:%991=1039%:%
       
  2640 %:%992=1040%:%
       
  2641 %:%993=1041%:%
       
  2642 %:%994=1042%:%
       
  2643 %:%995=1043%:%
       
  2644 %:%996=1044%:%
       
  2645 %:%997=1045%:%
       
  2646 %:%998=1046%:%
       
  2647 %:%999=1047%:%
       
  2648 %:%1000=1048%:%
       
  2649 %:%1001=1049%:%
       
  2650 %:%1002=1050%:%
       
  2651 %:%1003=1051%:%
       
  2652 %:%1004=1052%:%
       
  2653 %:%1005=1053%:%
       
  2654 %:%1006=1054%:%
       
  2655 %:%1007=1055%:%
       
  2656 %:%1008=1056%:%
       
  2657 %:%1008=1057%:%
       
  2658 %:%1008=1058%:%
       
  2659 %:%1009=1059%:%
       
  2660 %:%1009=1060%:%
       
  2661 %:%1009=1061%:%
       
  2662 %:%1010=1062%:%
       
  2663 %:%1011=1063%:%
       
  2664 %:%1011=1064%:%
       
  2665 %:%1012=1065%:%
       
  2666 %:%1013=1066%:%
       
  2667 %:%1014=1067%:%
       
  2668 %:%1015=1068%:%
       
  2669 %:%1016=1069%:%
       
  2670 %:%1017=1070%:%
       
  2671 %:%1018=1071%:%
       
  2672 %:%1019=1072%:%
       
  2673 %:%1020=1073%:%
       
  2674 %:%1021=1074%:%
       
  2675 %:%1022=1075%:%
       
  2676 %:%1023=1076%:%
       
  2677 %:%1024=1077%:%
       
  2678 %:%1025=1078%:%
       
  2679 %:%1026=1079%:%
       
  2680 %:%1027=1080%:%
       
  2681 %:%1028=1081%:%
       
  2682 %:%1029=1082%:%
       
  2683 %:%1030=1083%:%
       
  2684 %:%1031=1084%:%
       
  2685 %:%1032=1085%:%
       
  2686 %:%1033=1086%:%
       
  2687 %:%1034=1087%:%
       
  2688 %:%1035=1088%:%
       
  2689 %:%1036=1089%:%
       
  2690 %:%1037=1090%:%
       
  2691 %:%1038=1091%:%
       
  2692 %:%1039=1092%:%
       
  2693 %:%1040=1093%:%
       
  2694 %:%1041=1094%:%
       
  2695 %:%1042=1095%:%
       
  2696 %:%1043=1096%:%
       
  2697 %:%1044=1097%:%
       
  2698 %:%1045=1098%:%
       
  2699 %:%1045=1099%:%
       
  2700 %:%1046=1100%:%
       
  2701 %:%1047=1101%:%
       
  2702 %:%1048=1102%:%
       
  2703 %:%1048=1103%:%
       
  2704 %:%1048=1104%:%
       
  2705 %:%1048=1105%:%
       
  2706 %:%1049=1106%:%
       
  2707 %:%1050=1107%:%
       
  2708 %:%1051=1108%:%
       
  2709 %:%1052=1109%:%
       
  2710 %:%1053=1110%:%
       
  2711 %:%1054=1111%:%
       
  2712 %:%1055=1112%:%
       
  2713 %:%1056=1113%:%
       
  2714 %:%1057=1114%:%
       
  2715 %:%1058=1115%:%
       
  2716 %:%1059=1116%:%
       
  2717 %:%1060=1117%:%
       
  2718 %:%1061=1118%:%
       
  2719 %:%1062=1119%:%
       
  2720 %:%1063=1120%:%
       
  2721 %:%1064=1121%:%
       
  2722 %:%1065=1122%:%
       
  2723 %:%1066=1123%:%
       
  2724 %:%1067=1124%:%
       
  2725 %:%1068=1125%:%
       
  2726 %:%1069=1126%:%
       
  2727 %:%1070=1127%:%
       
  2728 %:%1071=1128%:%
       
  2729 %:%1072=1129%:%
       
  2730 %:%1073=1130%:%
       
  2731 %:%1074=1131%:%
       
  2732 %:%1075=1132%:%
       
  2733 %:%1076=1133%:%
       
  2734 %:%1077=1134%:%
       
  2735 %:%1078=1135%:%
       
  2736 %:%1079=1136%:%
       
  2737 %:%1080=1137%:%
       
  2738 %:%1081=1138%:%
       
  2739 %:%1082=1139%:%
       
  2740 %:%1083=1140%:%
       
  2741 %:%1084=1141%:%
       
  2742 %:%1085=1142%:%
       
  2743 %:%1094=1146%:%
       
  2744 %:%1106=1150%:%
       
  2745 %:%1107=1151%:%
       
  2746 %:%1108=1152%:%
       
  2747 %:%1109=1153%:%
       
  2748 %:%1110=1154%:%
       
  2749 %:%1111=1155%:%
       
  2750 %:%1112=1156%:%
       
  2751 %:%1113=1157%:%
       
  2752 %:%1114=1158%:%
       
  2753 %:%1115=1159%:%
       
  2754 %:%1116=1160%:%
       
  2755 %:%1117=1161%:%
       
  2756 %:%1118=1162%:%
       
  2757 %:%1119=1163%:%
       
  2758 %:%1120=1164%:%
       
  2759 %:%1121=1165%:%
       
  2760 %:%1122=1166%:%
       
  2761 %:%1123=1167%:%
       
  2762 %:%1124=1168%:%
       
  2763 %:%1125=1169%:%
       
  2764 %:%1126=1170%:%
       
  2765 %:%1127=1171%:%
       
  2766 %:%1128=1172%:%
       
  2767 %:%1129=1173%:%
       
  2768 %:%1130=1174%:%
       
  2769 %:%1131=1175%:%
       
  2770 %:%1132=1176%:%
       
  2771 %:%1133=1177%:%
       
  2772 %:%1134=1178%:%
       
  2773 %:%1135=1179%:%
       
  2774 %:%1136=1180%:%
       
  2775 %:%1137=1181%:%
       
  2776 %:%1138=1182%:%
       
  2777 %:%1139=1183%:%
       
  2778 %:%1140=1184%:%
       
  2779 %:%1141=1185%:%
       
  2780 %:%1142=1186%:%
       
  2781 %:%1143=1187%:%
       
  2782 %:%1144=1188%:%
       
  2783 %:%1145=1189%:%
       
  2784 %:%1146=1190%:%
       
  2785 %:%1147=1191%:%
       
  2786 %:%1148=1192%:%
       
  2787 %:%1149=1193%:%
       
  2788 %:%1150=1194%:%
       
  2789 %:%1151=1195%:%
       
  2790 %:%1152=1196%:%
       
  2791 %:%1153=1197%:%
       
  2792 %:%1154=1198%:%
       
  2793 %:%1155=1199%:%
       
  2794 %:%1156=1200%:%
       
  2795 %:%1157=1201%:%
       
  2796 %:%1158=1202%:%
       
  2797 %:%1159=1203%:%
       
  2798 %:%1160=1204%:%
       
  2799 %:%1161=1205%:%
       
  2800 %:%1162=1206%:%
       
  2801 %:%1163=1207%:%
       
  2802 %:%1164=1208%:%
       
  2803 %:%1165=1209%:%
       
  2804 %:%1166=1210%:%
       
  2805 %:%1167=1211%:%
       
  2806 %:%1168=1212%:%
       
  2807 %:%1169=1213%:%
       
  2808 %:%1170=1214%:%
       
  2809 %:%1171=1215%:%
       
  2810 %:%1172=1216%:%
       
  2811 %:%1173=1217%:%
       
  2812 %:%1174=1218%:%
       
  2813 %:%1175=1219%:%
       
  2814 %:%1176=1220%:%
       
  2815 %:%1177=1221%:%
       
  2816 %:%1178=1222%:%
       
  2817 %:%1179=1223%:%
       
  2818 %:%1180=1224%:%
       
  2819 %:%1181=1225%:%
       
  2820 %:%1182=1226%:%
       
  2821 %:%1183=1227%:%
       
  2822 %:%1184=1228%:%
       
  2823 %:%1185=1229%:%
       
  2824 %:%1186=1230%:%
       
  2825 %:%1187=1231%:%
       
  2826 %:%1188=1232%:%
       
  2827 %:%1189=1233%:%
       
  2828 %:%1190=1234%:%
       
  2829 %:%1191=1235%:%
       
  2830 %:%1192=1236%:%
       
  2831 %:%1193=1237%:%
       
  2832 %:%1194=1238%:%
       
  2833 %:%1195=1239%:%
       
  2834 %:%1196=1240%:%
       
  2835 %:%1197=1241%:%
       
  2836 %:%1198=1242%:%
       
  2837 %:%1199=1243%:%
       
  2838 %:%1200=1244%:%
       
  2839 %:%1201=1245%:%
       
  2840 %:%1202=1246%:%
       
  2841 %:%1203=1247%:%
       
  2842 %:%1204=1248%:%
       
  2843 %:%1205=1249%:%
       
  2844 %:%1206=1250%:%
       
  2845 %:%1207=1251%:%
       
  2846 %:%1208=1252%:%
       
  2847 %:%1209=1253%:%
       
  2848 %:%1210=1254%:%
       
  2849 %:%1211=1255%:%
       
  2850 %:%1212=1256%:%
       
  2851 %:%1213=1257%:%
       
  2852 %:%1214=1258%:%
       
  2853 %:%1215=1259%:%
       
  2854 %:%1216=1260%:%
       
  2855 %:%1217=1261%:%
       
  2856 %:%1218=1262%:%
       
  2857 %:%1219=1263%:%
       
  2858 %:%1220=1264%:%
       
  2859 %:%1221=1265%:%
       
  2860 %:%1221=1266%:%
       
  2861 %:%1222=1267%:%
       
  2862 %:%1223=1268%:%
       
  2863 %:%1224=1269%:%
       
  2864 %:%1225=1270%:%
       
  2865 %:%1226=1271%:%
       
  2866 %:%1227=1272%:%
       
  2867 %:%1228=1273%:%
       
  2868 %:%1229=1274%:%
       
  2869 %:%1230=1275%:%
       
  2870 %:%1231=1276%:%
       
  2871 %:%1232=1277%:%
       
  2872 %:%1232=1278%:%
       
  2873 %:%1233=1279%:%
       
  2874 %:%1234=1280%:%
       
  2875 %:%1235=1281%:%
       
  2876 %:%1236=1282%:%
       
  2877 %:%1237=1283%:%
       
  2878 %:%1238=1284%:%
       
  2879 %:%1239=1285%:%
       
  2880 %:%1240=1286%:%
       
  2881 %:%1241=1287%:%
       
  2882 %:%1242=1288%:%
       
  2883 %:%1243=1289%:%
       
  2884 %:%1244=1290%:%
       
  2885 %:%1245=1291%:%
       
  2886 %:%1246=1292%:%
       
  2887 %:%1247=1293%:%
       
  2888 %:%1248=1294%:%
       
  2889 %:%1249=1295%:%
       
  2890 %:%1250=1296%:%
       
  2891 %:%1251=1297%:%
       
  2892 %:%1252=1298%:%
       
  2893 %:%1253=1299%:%
       
  2894 %:%1254=1300%:%
       
  2895 %:%1255=1301%:%
       
  2896 %:%1256=1302%:%
       
  2897 %:%1257=1303%:%
       
  2898 %:%1258=1304%:%
       
  2899 %:%1259=1305%:%
       
  2900 %:%1260=1306%:%
       
  2901 %:%1261=1307%:%
       
  2902 %:%1262=1308%:%
       
  2903 %:%1263=1309%:%
       
  2904 %:%1264=1310%:%
       
  2905 %:%1265=1311%:%
       
  2906 %:%1266=1312%:%
       
  2907 %:%1267=1313%:%
       
  2908 %:%1268=1314%:%
       
  2909 %:%1269=1315%:%
       
  2910 %:%1270=1316%:%
       
  2911 %:%1271=1317%:%
       
  2912 %:%1272=1318%:%
       
  2913 %:%1273=1319%:%
       
  2914 %:%1274=1320%:%
       
  2915 %:%1275=1321%:%
       
  2916 %:%1276=1322%:%
       
  2917 %:%1277=1323%:%
       
  2918 %:%1278=1324%:%
       
  2919 %:%1279=1325%:%
       
  2920 %:%1280=1326%:%
       
  2921 %:%1281=1327%:%
       
  2922 %:%1282=1328%:%
       
  2923 %:%1283=1329%:%
       
  2924 %:%1284=1330%:%
       
  2925 %:%1285=1331%:%
       
  2926 %:%1286=1332%:%
       
  2927 %:%1286=1333%:%
       
  2928 %:%1286=1334%:%
       
  2929 %:%1287=1335%:%
       
  2930 %:%1288=1336%:%
       
  2931 %:%1288=1337%:%
       
  2932 %:%1288=1338%:%
       
  2933 %:%1288=1339%:%
       
  2934 %:%1289=1340%:%
       
  2935 %:%1290=1341%:%
       
  2936 %:%1291=1342%:%
       
  2937 %:%1292=1343%:%
       
  2938 %:%1293=1344%:%
       
  2939 %:%1293=1345%:%
       
  2940 %:%1294=1346%:%
       
  2941 %:%1295=1347%:%
       
  2942 %:%1296=1348%:%
       
  2943 %:%1297=1349%:%
       
  2944 %:%1298=1350%:%
       
  2945 %:%1299=1351%:%
       
  2946 %:%1300=1352%:%
       
  2947 %:%1301=1353%:%
       
  2948 %:%1302=1354%:%
       
  2949 %:%1303=1355%:%
       
  2950 %:%1304=1356%:%
       
  2951 %:%1305=1357%:%
       
  2952 %:%1306=1358%:%
       
  2953 %:%1307=1359%:%
       
  2954 %:%1308=1360%:%
       
  2955 %:%1309=1361%:%
       
  2956 %:%1310=1362%:%
       
  2957 %:%1311=1363%:%
       
  2958 %:%1312=1364%:%
       
  2959 %:%1313=1365%:%
       
  2960 %:%1314=1366%:%
       
  2961 %:%1315=1367%:%
       
  2962 %:%1316=1368%:%
       
  2963 %:%1317=1369%:%
       
  2964 %:%1318=1370%:%
       
  2965 %:%1319=1371%:%
       
  2966 %:%1320=1372%:%
       
  2967 %:%1321=1373%:%
       
  2968 %:%1322=1374%:%
       
  2969 %:%1323=1375%:%
       
  2970 %:%1324=1376%:%
       
  2971 %:%1325=1377%:%
       
  2972 %:%1326=1378%:%
       
  2973 %:%1327=1379%:%
       
  2974 %:%1328=1380%:%
       
  2975 %:%1329=1381%:%
       
  2976 %:%1330=1382%:%
       
  2977 %:%1331=1383%:%
       
  2978 %:%1332=1384%:%
       
  2979 %:%1333=1385%:%
       
  2980 %:%1334=1386%:%
       
  2981 %:%1335=1387%:%
       
  2982 %:%1336=1388%:%
       
  2983 %:%1337=1389%:%
       
  2984 %:%1338=1390%:%
       
  2985 %:%1339=1391%:%
       
  2986 %:%1340=1392%:%
       
  2987 %:%1341=1393%:%
       
  2988 %:%1341=1394%:%
       
  2989 %:%1342=1395%:%
       
  2990 %:%1342=1396%:%
       
  2991 %:%1343=1397%:%
       
  2992 %:%1343=1398%:%
       
  2993 %:%1344=1399%:%
       
  2994 %:%1345=1400%:%
       
  2995 %:%1346=1401%:%
       
  2996 %:%1347=1402%:%
       
  2997 %:%1348=1403%:%
       
  2998 %:%1349=1404%:%
       
  2999 %:%1350=1405%:%
       
  3000 %:%1350=1406%:%
       
  3001 %:%1351=1407%:%
       
  3002 %:%1351=1408%:%
       
  3003 %:%1352=1409%:%
       
  3004 %:%1352=1410%:%
       
  3005 %:%1353=1411%:%
       
  3006 %:%1354=1412%:%
       
  3007 %:%1355=1413%:%
       
  3008 %:%1356=1414%:%
       
  3009 %:%1357=1415%:%
       
  3010 %:%1358=1416%:%
       
  3011 %:%1359=1417%:%
       
  3012 %:%1360=1418%:%
       
  3013 %:%1361=1419%:%
       
  3014 %:%1362=1420%:%
       
  3015 %:%1363=1421%:%
       
  3016 %:%1364=1422%:%
       
  3017 %:%1365=1423%:%
       
  3018 %:%1366=1424%:%
       
  3019 %:%1367=1425%:%
       
  3020 %:%1368=1426%:%
       
  3021 %:%1369=1427%:%
       
  3022 %:%1370=1428%:%
       
  3023 %:%1371=1429%:%
       
  3024 %:%1372=1430%:%
       
  3025 %:%1373=1431%:%
       
  3026 %:%1374=1432%:%
       
  3027 %:%1375=1433%:%
       
  3028 %:%1376=1434%:%
       
  3029 %:%1377=1435%:%
       
  3030 %:%1378=1436%:%
       
  3031 %:%1379=1437%:%
       
  3032 %:%1380=1438%:%
       
  3033 %:%1381=1439%:%
       
  3034 %:%1382=1440%:%
       
  3035 %:%1383=1441%:%
       
  3036 %:%1383=1442%:%
       
  3037 %:%1384=1443%:%
       
  3038 %:%1385=1444%:%
       
  3039 %:%1386=1445%:%
       
  3040 %:%1387=1446%:%
       
  3041 %:%1388=1447%:%
       
  3042 %:%1389=1448%:%
       
  3043 %:%1390=1449%:%
       
  3044 %:%1390=1450%:%
       
  3045 %:%1391=1451%:%
       
  3046 %:%1392=1452%:%
       
  3047 %:%1393=1453%:%
       
  3048 %:%1393=1454%:%
       
  3049 %:%1394=1455%:%
       
  3050 %:%1395=1456%:%
       
  3051 %:%1396=1457%:%
       
  3052 %:%1396=1458%:%
       
  3053 %:%1397=1459%:%
       
  3054 %:%1397=1460%:%
       
  3055 %:%1398=1461%:%
       
  3056 %:%1398=1462%:%
       
  3057 %:%1399=1463%:%
       
  3058 %:%1400=1464%:%
       
  3059 %:%1401=1465%:%
       
  3060 %:%1401=1466%:%
       
  3061 %:%1402=1467%:%
       
  3062 %:%1402=1468%:%
       
  3063 %:%1403=1469%:%
       
  3064 %:%1403=1470%:%
       
  3065 %:%1403=1471%:%
       
  3066 %:%1403=1472%:%
       
  3067 %:%1404=1473%:%
       
  3068 %:%1404=1474%:%
       
  3069 %:%1405=1475%:%
       
  3070 %:%1406=1476%:%
       
  3071 %:%1406=1478%:%
       
  3072 %:%1406=1479%:%
       
  3073 %:%1406=1480%:%
       
  3074 %:%1406=1481%:%
       
  3075 %:%1406=1482%:%
       
  3076 %:%1407=1483%:%
       
  3077 %:%1407=1484%:%
       
  3078 %:%1408=1485%:%
       
  3079 %:%1408=1486%:%
       
  3080 %:%1409=1487%:%
       
  3081 %:%1409=1488%:%
       
  3082 %:%1410=1489%:%
       
  3083 %:%1411=1490%:%
       
  3084 %:%1412=1491%:%
       
  3085 %:%1413=1492%:%
       
  3086 %:%1413=1493%:%
       
  3087 %:%1414=1494%:%
       
  3088 %:%1414=1495%:%
       
  3089 %:%1415=1496%:%
       
  3090 %:%1416=1497%:%
       
  3091 %:%1416=1498%:%
       
  3092 %:%1417=1499%:%
       
  3093 %:%1418=1500%:%
       
  3094 %:%1419=1501%:%
       
  3095 %:%1420=1502%:%
       
  3096 %:%1421=1503%:%
       
  3097 %:%1422=1504%:%
       
  3098 %:%1423=1505%:%
       
  3099 %:%1424=1506%:%
       
  3100 %:%1425=1507%:%
       
  3101 %:%1426=1508%:%
       
  3102 %:%1427=1509%:%
       
  3103 %:%1428=1510%:%
       
  3104 %:%1429=1511%:%
       
  3105 %:%1430=1512%:%
       
  3106 %:%1431=1513%:%
       
  3107 %:%1432=1514%:%
       
  3108 %:%1433=1515%:%
       
  3109 %:%1434=1516%:%
       
  3110 %:%1435=1517%:%
       
  3111 %:%1436=1518%:%
       
  3112 %:%1437=1519%:%
       
  3113 %:%1438=1520%:%
       
  3114 %:%1439=1521%:%
       
  3115 %:%1440=1522%:%
       
  3116 %:%1441=1523%:%
       
  3117 %:%1442=1524%:%
       
  3118 %:%1443=1525%:%
       
  3119 %:%1444=1526%:%
       
  3120 %:%1445=1527%:%
       
  3121 %:%1446=1528%:%
       
  3122 %:%1447=1529%:%
       
  3123 %:%1448=1530%:%
       
  3124 %:%1449=1531%:%
       
  3125 %:%1450=1532%:%
       
  3126 %:%1451=1533%:%
       
  3127 %:%1452=1534%:%
       
  3128 %:%1453=1535%:%
       
  3129 %:%1454=1536%:%
       
  3130 %:%1455=1537%:%
       
  3131 %:%1456=1538%:%
       
  3132 %:%1457=1539%:%
       
  3133 %:%1458=1540%:%
       
  3134 %:%1459=1541%:%
       
  3135 %:%1460=1542%:%
       
  3136 %:%1461=1543%:%
       
  3137 %:%1462=1544%:%
       
  3138 %:%1463=1545%:%
       
  3139 %:%1464=1546%:%
       
  3140 %:%1465=1547%:%
       
  3141 %:%1466=1548%:%
       
  3142 %:%1467=1549%:%
       
  3143 %:%1476=1553%:%
       
  3144 %:%1488=1560%:%
       
  3145 %:%1489=1561%:%
       
  3146 %:%1490=1562%:%
       
  3147 %:%1491=1563%:%
       
  3148 %:%1492=1564%:%
       
  3149 %:%1493=1565%:%
       
  3150 %:%1494=1566%:%
       
  3151 %:%1503=1571%:%
       
  3152 %:%1515=1575%:%
       
  3153 %:%1516=1576%:%
       
  3154 %:%1517=1577%:%
       
  3155 %:%1518=1578%:%
       
  3156 %:%1519=1579%:%
       
  3157 %:%1520=1580%:%
       
  3158 %:%1521=1581%:%
       
  3159 %:%1522=1582%:%
       
  3160 %:%1523=1583%:%
       
  3161 %:%1524=1584%:%
       
  3162 %:%1525=1585%:%
       
  3163 %:%1526=1586%:%
       
  3164 %:%1527=1587%:%
       
  3165 %:%1528=1588%:%
       
  3166 %:%1529=1589%:%
       
  3167 %:%1530=1590%:%
       
  3168 %:%1531=1591%:%
       
  3169 %:%1532=1592%:%
       
  3170 %:%1533=1593%:%
       
  3171 %:%1534=1594%:%
       
  3172 %:%1535=1595%:%
       
  3173 %:%1536=1596%:%
       
  3174 %:%1537=1597%:%
       
  3175 %:%1538=1598%:%
       
  3176 %:%1539=1599%:%
       
  3177 %:%1540=1600%:%
       
  3178 %:%1541=1601%:%
       
  3179 %:%1542=1602%:%
       
  3180 %:%1543=1603%:%
       
  3181 %:%1544=1604%:%
       
  3182 %:%1545=1605%:%
       
  3183 %:%1546=1606%:%
       
  3184 %:%1547=1607%:%
       
  3185 %:%1548=1608%:%
       
  3186 %:%1549=1609%:%
       
  3187 %:%1550=1610%:%
       
  3188 %:%1551=1611%:%
       
  3189 %:%1552=1612%:%
       
  3190 %:%1553=1613%:%
       
  3191 %:%1554=1614%:%
       
  3192 %:%1555=1615%:%
       
  3193 %:%1556=1616%:%
       
  3194 %:%1557=1617%:%
       
  3195 %:%1558=1618%:%
       
  3196 %:%1559=1619%:%
       
  3197 %:%1560=1620%:%
       
  3198 %:%1561=1621%:%
       
  3199 %:%1562=1622%:%
       
  3200 %:%1563=1623%:%
       
  3201 %:%1564=1624%:%
       
  3202 %:%1565=1625%:%
       
  3203 %:%1566=1626%:%
       
  3204 %:%1567=1627%:%
       
  3205 %:%1568=1628%:%
       
  3206 %:%1569=1629%:%
       
  3207 %:%1570=1630%:%
       
  3208 %:%1571=1631%:%
       
  3209 %:%1572=1632%:%
       
  3210 %:%1573=1633%:%
       
  3211 %:%1574=1634%:%
       
  3212 %:%1575=1635%:%
       
  3213 %:%1576=1636%:%
       
  3214 %:%1577=1637%:%
       
  3215 %:%1578=1638%:%
       
  3216 %:%1579=1639%:%
       
  3217 %:%1580=1640%:%
       
  3218 %:%1581=1641%:%
       
  3219 %:%1582=1642%:%
       
  3220 %:%1583=1643%:%
       
  3221 %:%1584=1644%:%
       
  3222 %:%1585=1645%:%
       
  3223 %:%1586=1646%:%
       
  3224 %:%1587=1647%:%
       
  3225 %:%1588=1648%:%
       
  3226 %:%1589=1649%:%
       
  3227 %:%1590=1650%:%
       
  3228 %:%1591=1651%:%
       
  3229 %:%1592=1652%:%
       
  3230 %:%1593=1653%:%
       
  3231 %:%1594=1654%:%
       
  3232 %:%1595=1655%:%
       
  3233 %:%1596=1656%:%
       
  3234 %:%1597=1657%:%
       
  3235 %:%1598=1658%:%
       
  3236 %:%1599=1659%:%
       
  3237 %:%1600=1660%:%
       
  3238 %:%1601=1661%:%
       
  3239 %:%1602=1662%:%
       
  3240 %:%1603=1663%:%
       
  3241 %:%1604=1664%:%
       
  3242 %:%1604=1780%:%
       
  3243 %:%1605=1781%:%
       
  3244 %:%1606=1782%:%
       
  3245 %:%1607=1783%:%
       
  3246 %:%1608=1784%:%
       
  3247 %:%1608=1945%:%
       
  3248 %:%1609=1946%:%
       
  3249 %:%1610=1947%:%
       
  3250 %:%1611=1948%:%
       
  3251 %:%1612=1949%:%
       
  3252 %:%1613=1950%:%
       
  3253 %:%1614=1951%:%
       
  3254 %:%1615=1952%:%
       
  3255 %:%1616=1953%:%
       
  3256 %:%1617=1954%:%
       
  3257 %:%1618=1955%:%
       
  3258 %:%1619=1956%:%
       
  3259 %:%1620=1957%:%
       
  3260 %:%1621=1958%:%
       
  3261 %:%1622=1959%:%
       
  3262 %:%1623=1960%:%
       
  3263 %:%1624=1961%:%
       
  3264 %:%1625=1962%:%
       
  3265 %:%1626=1963%:%
       
  3266 %:%1627=1964%:%
       
  3267 %:%1627=1965%:%
       
  3268 %:%1628=1966%:%
       
  3269 %:%1628=1967%:%
       
  3270 %:%1628=1968%:%
       
  3271 %:%1629=1969%:%
       
  3272 %:%1629=1970%:%
       
  3273 %:%1630=1971%:%
       
  3274 %:%1631=1972%:%
       
  3275 %:%1632=1973%:%
       
  3276 %:%1633=1974%:%
       
  3277 %:%1634=1975%:%
       
  3278 %:%1635=1976%:%
       
  3279 %:%1636=1977%:%
       
  3280 %:%1637=1978%:%
       
  3281 %:%1638=1979%:%
       
  3282 %:%1639=1980%:%
       
  3283 %:%1640=1981%:%
       
  3284 %:%1641=1982%:%
       
  3285 %:%1642=1983%:%
       
  3286 %:%1643=1984%:%
       
  3287 %:%1644=1985%:%
       
  3288 %:%1645=1986%:%
       
  3289 %:%1646=1987%:%
       
  3290 %:%1646=1988%:%
       
  3291 %:%1647=1989%:%
       
  3292 %:%1648=1990%:%
       
  3293 %:%1649=1991%:%
       
  3294 %:%1649=1992%:%
       
  3295 %:%1649=1993%:%
       
  3296 %:%1650=1994%:%
       
  3297 %:%1651=1995%:%
       
  3298 %:%1652=1996%:%
       
  3299 %:%1652=1997%:%
       
  3300 %:%1653=1998%:%
       
  3301 %:%1653=1999%:%
       
  3302 %:%1654=2000%:%
       
  3303 %:%1655=2001%:%
       
  3304 %:%1656=2002%:%
       
  3305 %:%1657=2003%:%
       
  3306 %:%1658=2004%:%
       
  3307 %:%1659=2005%:%
       
  3308 %:%1660=2006%:%
       
  3309 %:%1661=2007%:%
       
  3310 %:%1662=2008%:%
       
  3311 %:%1663=2009%:%
       
  3312 %:%1664=2010%:%
       
  3313 %:%1665=2011%:%
       
  3314 %:%1666=2012%:%
       
  3315 %:%1667=2013%:%
       
  3316 %:%1668=2014%:%
       
  3317 %:%1669=2015%:%
       
  3318 %:%1670=2016%:%
       
  3319 %:%1679=2021%:%
       
  3320 %:%1691=2025%:%
       
  3321 %:%1692=2026%:%
       
  3322 %:%1693=2027%:%
       
  3323 %:%1694=2028%:%
       
  3324 %:%1695=2029%:%
       
  3325 %:%1696=2030%:%
       
  3326 %:%1697=2031%:%
       
  3327 %:%1698=2032%:%
       
  3328 %:%1699=2033%:%
       
  3329 %:%1700=2034%:%
       
  3330 %:%1701=2035%:%
       
  3331 %:%1702=2036%:%
       
  3332 %:%1703=2037%:%
       
  3333 %:%1704=2038%:%
       
  3334 %:%1705=2039%:%
       
  3335 %:%1706=2040%:%
       
  3336 %:%1707=2041%:%
       
  3337 %:%1708=2042%:%
       
  3338 %:%1709=2043%:%
       
  3339 %:%1710=2044%:%
       
  3340 %:%1711=2045%:%
       
  3341 %:%1712=2046%:%
       
  3342 %:%1713=2047%:%
       
  3343 %:%1714=2048%:%
       
  3344 %:%1715=2049%:%
       
  3345 %:%1716=2050%:%
       
  3346 %:%1717=2051%:%
       
  3347 %:%1718=2052%:%
       
  3348 %:%1719=2053%:%
       
  3349 %:%1720=2054%:%
       
  3350 %:%1721=2055%:%
       
  3351 %:%1722=2056%:%
       
  3352 %:%1723=2057%:%
       
  3353 %:%1724=2058%:%
       
  3354 %:%1725=2059%:%
       
  3355 %:%1726=2060%:%
       
  3356 %:%1727=2061%:%
       
  3357 %:%1728=2062%:%
       
  3358 %:%1729=2063%:%
       
  3359 %:%1730=2064%:%
       
  3360 %:%1731=2065%:%
       
  3361 %:%1732=2066%:%
       
  3362 %:%1733=2067%:%
       
  3363 %:%1734=2068%:%
       
  3364 %:%1735=2069%:%
       
  3365 %:%1736=2070%:%
       
  3366 %:%1737=2071%:%
       
  3367 %:%1738=2072%:%
       
  3368 %:%1739=2073%:%
       
  3369 %:%1740=2074%:%
       
  3370 %:%1741=2075%:%
       
  3371 %:%1742=2076%:%
       
  3372 %:%1743=2077%:%
       
  3373 %:%1756=2083%:%
       
  3374 %:%1759=2084%:%
       
  3375 %:%1760=2085%:%