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