ChengsongTanPhdThesis/Chapters/Chapter2.tex
author Chengsong
Thu, 26 May 2022 20:51:40 +0100
changeset 518 ff7945a988a3
parent 516 6fecb7fe8cd0
child 519 856d025dbc15
permissions -rwxr-xr-x
more to thesis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
468
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     1
% Chapter Template
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     2
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     3
\chapter{Chapter Title Here} % Main chapter title
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     4
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     5
\label{ChapterX} % Change X to a consecutive number; for referencing this chapter elsewhere, use \ref{ChapterX}
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
     6
500
Chengsong
parents: 468
diff changeset
     7
Chengsong
parents: 468
diff changeset
     8
Chengsong
parents: 468
diff changeset
     9
468
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
    10
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
    11
%-----------------------------------
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
    12
%	SUBSECTION 1
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
    13
%-----------------------------------
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    14
\section{Specifications of Certain Functions to be Used}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
    15
To be completed.
500
Chengsong
parents: 468
diff changeset
    16
Chengsong
parents: 468
diff changeset
    17
Chengsong
parents: 468
diff changeset
    18
Chengsong
parents: 468
diff changeset
    19
507
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    20
%-----------------------------------
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    21
%	SECTION ?
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    22
%-----------------------------------
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    23
\section{preparatory properties for getting a finiteness bound}
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    24
Before we get to the proof that says the intermediate result of our lexer will
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    25
remain finitely bounded, which is an important efficiency/liveness guarantee,
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    26
we shall first develop a few preparatory properties and definitions to 
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    27
make the process of proving that a breeze.
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    28
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    29
We define rewriting relations for $\rrexp$s, which allows us to do the 
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    30
same trick as we did for the correctness proof,
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    31
but this time we will have stronger equalities established.
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    32
\subsection{"hrewrite" relation}
514
036600af4c30 chapter2
Chengsong
parents: 507
diff changeset
    33
List of 1-step rewrite rules for regular expressions simplification without bitcodes:
515
Chengsong
parents: 514
diff changeset
    34
\begin{center}
Chengsong
parents: 514
diff changeset
    35
\begin{tabular}{lcl}
Chengsong
parents: 514
diff changeset
    36
$r_1 \cdot \ZERO$ & $\rightarrow$ & $\ZERO$
Chengsong
parents: 514
diff changeset
    37
\end{tabular}
Chengsong
parents: 514
diff changeset
    38
\end{center}
Chengsong
parents: 514
diff changeset
    39
Chengsong
parents: 514
diff changeset
    40
And we define an "grewrite" relation that works on lists:
Chengsong
parents: 514
diff changeset
    41
\begin{center}
Chengsong
parents: 514
diff changeset
    42
\begin{tabular}{lcl}
Chengsong
parents: 514
diff changeset
    43
$ \ZERO :: rs$ & $\rightarrow_g$ & $rs$
Chengsong
parents: 514
diff changeset
    44
\end{tabular}
Chengsong
parents: 514
diff changeset
    45
\end{center}
507
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    46
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    47
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    48
515
Chengsong
parents: 514
diff changeset
    49
With these relations we prove
Chengsong
parents: 514
diff changeset
    50
\begin{lemma}
Chengsong
parents: 514
diff changeset
    51
$rs \rightarrow rs'  \implies \RALTS{rs} \rightarrow \RALTS{rs'}$
Chengsong
parents: 514
diff changeset
    52
\end{lemma}
Chengsong
parents: 514
diff changeset
    53
which enables us to prove "closed forms" equalities such as
Chengsong
parents: 514
diff changeset
    54
\begin{lemma}
Chengsong
parents: 514
diff changeset
    55
$\sflat{(r_1 \cdot r_2) \backslash s} = \RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}$
Chengsong
parents: 514
diff changeset
    56
\end{lemma}
Chengsong
parents: 514
diff changeset
    57
Chengsong
parents: 514
diff changeset
    58
But the most involved part of the above lemma is proving the following:
Chengsong
parents: 514
diff changeset
    59
\begin{lemma}
Chengsong
parents: 514
diff changeset
    60
$\bsimp{\RALTS{rs @ \RALTS{rs_1} @ rs'}} = \bsimp{\RALTS{rs @rs_1 @ rs'}} $ 
Chengsong
parents: 514
diff changeset
    61
\end{lemma}
Chengsong
parents: 514
diff changeset
    62
which is needed in proving things like 
Chengsong
parents: 514
diff changeset
    63
\begin{lemma}
Chengsong
parents: 514
diff changeset
    64
$r \rightarrow_f r'  \implies \rsimp{r} \rightarrow \rsimp{r'}$
Chengsong
parents: 514
diff changeset
    65
\end{lemma}
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    66
515
Chengsong
parents: 514
diff changeset
    67
Fortunately this is provable by induction on the list $rs$
507
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
    68
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    69
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    70
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    71
%-----------------------------------
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    72
%	SECTION 2
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    73
%-----------------------------------
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    74
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    75
\section{Finiteness Property}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    76
In this section let us describe our argument for why the size of the simplified
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    77
derivatives with the aggressive simplification function is finitely bounded.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    78
 Suppose
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    79
we have a size function for bitcoded regular expressions, written
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    80
$\llbracket r\rrbracket$, which counts the number of nodes if we regard $r$ as a tree
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    81
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    82
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    83
\begin{tabular}{ccc}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    84
$\llbracket \ACHAR{bs}{c} \rrbracket $ & $\dn$ & $1$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    85
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    86
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    87
(TODO: COMPLETE this defn and for $rs$)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    88
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    89
The size is based on a recursive function on the structure of the regex,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    90
not the bitcodes.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    91
Therefore we may as well talk about size of an annotated regular expression 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    92
in their un-annotated form:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    93
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    94
$\asize(a) = \size(\erase(a))$. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    95
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    96
(TODO: turn equals to roughly equals)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    97
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    98
But there is a minor nuisance here:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
    99
the erase function actually messes with the structure of the regular expression:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   100
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   101
\begin{tabular}{ccc}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   102
$\erase(\AALTS{bs}{[]} )$ & $\dn$ & $\ZERO$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   103
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   104
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   105
(TODO: complete this definition with singleton r in alts)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   106
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   107
An alternative regular expression with an empty list of children
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   108
 is turned into an $\ZERO$ during the
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   109
$\erase$ function, thereby changing the size and structure of the regex.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   110
These will likely be fixable if we really want to use plain $\rexp$s for dealing
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   111
with size, but we choose a more straightforward (or stupid) method by 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   112
defining a new datatype that is similar to plain $\rexp$s but can take
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   113
non-binary arguments for its alternative constructor,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   114
 which we call $\rrexp$ to denote
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   115
the difference between it and plain regular expressions. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   116
\[			\rrexp ::=   \RZERO \mid  \RONE
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   117
			 \mid  \RCHAR{c}  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   118
			 \mid  \RSEQ{r_1}{r_2}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   119
			 \mid  \RALTS{rs}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   120
			 \mid \RSTAR{r}        
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   121
\]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   122
For $\rrexp$ we throw away the bitcodes on the annotated regular expressions, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   123
but keep everything else intact.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   124
It is similar to annotated regular expressions being $\erase$-ed, but with all its structure preserved
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   125
(the $\erase$ function unfortunately does not preserve structure in the case of empty and singleton
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   126
$\ALTS$).
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   127
We denote the operation of erasing the bits and turning an annotated regular expression 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   128
into an $\rrexp{}$ as $\rerase{}$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   129
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   130
\begin{tabular}{lcl}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   131
$\rerase{\AZERO}$ & $=$ & $\RZERO$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   132
$\rerase{\ASEQ{bs}{r_1}{r_2}}$ & $=$ & $\RSEQ{\rerase{r_1}}{\rerase{r_2}}$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   133
$\rerase{\AALTS{bs}{rs}}$ & $ =$ & $ \RALTS{rs}$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   134
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   135
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   136
%TODO: FINISH definition of rerase
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   137
Similarly we could define the derivative  and simplification on 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   138
$\rrexp$, which would be identical to those we defined for plain $\rexp$s in chapter1, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   139
except that now they can operate on alternatives taking multiple arguments.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   140
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   141
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   142
\begin{tabular}{lcr}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   143
$\RALTS{rs} \backslash c$ & $=$ &  $\RALTS{map\; (\_ \backslash c) \;rs}$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   144
(other clauses omitted)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   145
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   146
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   147
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   148
Now that $\rrexp$s do not have bitcodes on them, we can do the 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   149
duplicate removal without  an equivalence relation:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   150
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   151
\begin{tabular}{lcl}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   152
$\rdistinct{r :: rs}{rset}$ & $=$ & $\textit{if}(r \in \textit{rset}) \; \textit{then} \; \rdistinct{rs}{rset}$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   153
           			    &        & $\textit{else}\; r::\rdistinct{rs}{(rset \cup \{r\})}$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   154
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   155
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   156
%TODO: definition of rsimp (maybe only the alternative clause)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   157
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   158
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   159
The reason why these definitions  mirror precisely the corresponding operations
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   160
on annotated regualar expressions is that we can calculate sizes more easily:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   161
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   162
\begin{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   163
$\rsize{\rerase a} = \asize a$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   164
\end{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   165
This lemma says that the size of an r-erased regex is the same as the annotated regex.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   166
this does not hold for plain $\rexp$s due to their ways of how alternatives are represented.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   167
\begin{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   168
$\asize{\bsimp{a}} = \rsize{\rsimp{\rerase{a}}}$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   169
\end{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   170
Putting these two together we get a property that allows us to estimate the 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   171
size of an annotated regular expression derivative using its un-annotated counterpart:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   172
\begin{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   173
$\asize{\bderssimp{r}{s}} =  \rsize{\rderssimp{\rerase{r}}{s}}$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   174
\end{lemma}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   175
Unless stated otherwise in this chapter all $\textit{rexp}$s without
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   176
 bitcodes are seen as $\rrexp$s.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   177
 We also use $r_1 + r_2$ and $\RALTS{[r_1, r_2]}$ interchageably
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   178
 as the former suits people's intuitive way of stating a binary alternative
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   179
 regular expression.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   180
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   181
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   182
\begin{theorem}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   183
For any regex $r$, $\exists N_r. \forall s. \; \llbracket{\bderssimp{r}{s}}\rrbracket \leq N_r$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   184
\end{theorem}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   185
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   186
\noindent
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   187
\begin{proof}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   188
We prove this by induction on $r$. The base cases for $\AZERO$,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   189
$\AONE \textit{bs}$ and $\ACHAR \textit{bs} c$ are straightforward. The interesting case is
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   190
for sequences of the form $\ASEQ{bs}{r_1}{r_2}$. In this case our induction
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   191
hypotheses state $\exists N_1. \forall s. \; \llbracket \bderssimp{r}{s} \rrbracket \leq N_1$ and
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   192
$\exists N_2. \forall s. \; \llbracket \bderssimp{r_2}{s} \rrbracket \leq N_2$. We can reason as follows
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   193
%
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   194
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   195
\begin{tabular}{lcll}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   196
& & $ \llbracket   \bderssimp{\ASEQ{bs}{r_1}{r_2} }{s} \rrbracket$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   197
& $ = $ & $\llbracket bsimp\,(\textit{ALTs}\;bs\;(\ASEQ{nil}{\bderssimp{ r_1}{s}}{ r_2} ::
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   198
    [\bderssimp{ r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)]))\rrbracket $ & (1) \\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   199
& $\leq$ &
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   200
    $\llbracket\textit{\distinctWith}\,((\ASEQ{nil}{\bderssimp{r_1}{s}}{r_2}$) ::
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   201
    [$\bderssimp{ r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)])\,\approx\;{}\rrbracket + 1 $ & (2) \\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   202
& $\leq$ & $\llbracket\ASEQ{bs}{\bderssimp{ r_1}{s}}{r_2}\rrbracket +
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   203
             \llbracket\textit{distinctWith}\,[\bderssimp{r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)]\,\approx\;{}\rrbracket + 1 $ & (3) \\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   204
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 +
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   205
      \llbracket \distinctWith\,[ \bderssimp{r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)] \,\approx\;\rrbracket$ & (4)\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   206
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 + l_{N_{2}} * N_{2}$ & (5)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   207
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   208
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   209
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   210
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   211
\noindent
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   212
where in (1) the $\textit{Suffix}( r_1, s)$ are the all the suffixes of $s$ where $\bderssimp{ r_1}{s'}$ is nullable ($s'$ being a suffix of $s$).
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   213
The reason why we could write the derivatives of a sequence this way is described in section 2.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   214
The term (2) is used to control (1). 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   215
That is because one can obtain an overall
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   216
smaller regex list
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   217
by flattening it and removing $\ZERO$s first before applying $\distinctWith$ on it.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   218
Section 3 is dedicated to its proof.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   219
In (3) we know that  $\llbracket \ASEQ{bs}{(\bderssimp{ r_1}{s}}{r_2}\rrbracket$ is 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   220
bounded by $N_1 + \llbracket{}r_2\rrbracket + 1$. In (5) we know the list comprehension contains only regular expressions of size smaller
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   221
than $N_2$. The list length after  $\distinctWith$ is bounded by a number, which we call $l_{N_2}$. It stands
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   222
for the number of distinct regular expressions smaller than $N_2$ (there can only be finitely many of them).
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   223
We reason similarly for  $\STAR$.\medskip
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   224
\end{proof}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   225
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   226
What guarantee does this bound give us?
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   227
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   228
Whatever the regex is, it will not grow indefinitely.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   229
Take our previous example $(a + aa)^*$ as an example:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   230
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   231
\begin{tabular}{@{}c@{\hspace{0mm}}c@{\hspace{0mm}}c@{}}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   232
\begin{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   233
\begin{axis}[
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   234
    xlabel={number of $a$'s},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   235
    x label style={at={(1.05,-0.05)}},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   236
    ylabel={regex size},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   237
    enlargelimits=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   238
    xtick={0,5,...,30},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   239
    xmax=33,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   240
    ymax= 40,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   241
    ytick={0,10,...,40},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   242
    scaled ticks=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   243
    axis lines=left,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   244
    width=5cm,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   245
    height=4cm, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   246
    legend entries={$(a + aa)^*$},  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   247
    legend pos=north west,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   248
    legend cell align=left]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   249
\addplot[red,mark=*, mark options={fill=white}] table {a_aa_star.data};
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   250
\end{axis}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   251
\end{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   252
\end{tabular}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   253
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   254
We are able to limit the size of the regex $(a + aa)^*$'s derivatives
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   255
 with our simplification
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   256
rules very effectively.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   257
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   258
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   259
As the graphs of  some more randomly generated regexes show, the size of 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   260
the derivative might grow quickly at the start of the input,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   261
 but after a sufficiently long  input string, the trend will stop.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   262
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   263
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   264
%a few sample regular experessions' derivatives
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   265
%size change
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   266
%TODO: giving graphs showing a few regexes' size changes 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   267
%w;r;t the input characters number
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   268
%a*, aa*, aaa*, .....
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   269
%randomly generated regexes
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   270
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   271
\begin{tabular}{@{}c@{\hspace{0mm}}c@{\hspace{0mm}}c@{}}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   272
\begin{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   273
\begin{axis}[
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   274
    xlabel={number of $a$'s},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   275
    x label style={at={(1.05,-0.05)}},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   276
    ylabel={regex size},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   277
    enlargelimits=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   278
    xtick={0,5,...,30},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   279
    xmax=33,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   280
    ymax=1000,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   281
    ytick={0,100,...,1000},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   282
    scaled ticks=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   283
    axis lines=left,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   284
    width=5cm,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   285
    height=4cm, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   286
    legend entries={regex1},  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   287
    legend pos=north west,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   288
    legend cell align=left]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   289
\addplot[red,mark=*, mark options={fill=white}] table {regex1_size_change.data};
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   290
\end{axis}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   291
\end{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   292
  &
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   293
\begin{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   294
\begin{axis}[
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   295
    xlabel={$n$},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   296
    x label style={at={(1.05,-0.05)}},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   297
    %ylabel={time in secs},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   298
    enlargelimits=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   299
    xtick={0,5,...,30},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   300
    xmax=33,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   301
    ymax=1000,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   302
    ytick={0,100,...,1000},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   303
    scaled ticks=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   304
    axis lines=left,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   305
    width=5cm,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   306
    height=4cm, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   307
    legend entries={regex2},  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   308
    legend pos=north west,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   309
    legend cell align=left]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   310
\addplot[blue,mark=*, mark options={fill=white}] table {regex2_size_change.data};
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   311
\end{axis}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   312
\end{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   313
  &
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   314
\begin{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   315
\begin{axis}[
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   316
    xlabel={$n$},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   317
    x label style={at={(1.05,-0.05)}},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   318
    %ylabel={time in secs},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   319
    enlargelimits=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   320
    xtick={0,5,...,30},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   321
    xmax=33,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   322
    ymax=1000,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   323
    ytick={0,100,...,1000},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   324
    scaled ticks=false,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   325
    axis lines=left,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   326
    width=5cm,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   327
    height=4cm, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   328
    legend entries={regex3},  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   329
    legend pos=north west,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   330
    legend cell align=left]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   331
\addplot[cyan,mark=*, mark options={fill=white}] table {regex3_size_change.data};
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   332
\end{axis}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   333
\end{tikzpicture}\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   334
\multicolumn{3}{c}{Graphs: size change of 3 randomly generated regexes $w.r.t.$ input string length.}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   335
\end{tabular}    
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   336
\end{center}  
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   337
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   338
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   339
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   340
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   341
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   342
\noindent
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   343
Clearly we give in this finiteness argument (Step (5)) a very loose bound that is
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   344
far from the actual bound we can expect. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   345
In our proof for the inductive case $r_1 \cdot r_2$, the dominant term in the bound
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   346
is $l_{N_2} * N_2$, where $N_2$ is the bound we have for $\llbracket \bderssimp{r_2}{s} \rrbracket$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   347
Given that $l_{N_2}$ is roughly the size $4^{N_2}$, the size bound $\llbracket \bderssimp{r_1 \cdot r_2}{s} \rrbracket$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   348
inflates the size bound of $\llbracket \bderssimp{r_2}{s} \rrbracket$ with the function
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   349
$f(x) = x * 2^x$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   350
This means the bound we have will surge up at least
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   351
tower-exponentially with a linear increase of the depth.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   352
For a regex of depth $n$, the bound
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   353
would be approximately $4^n$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   354
%TODO: change this to tower exponential!
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   355
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   356
We can do better than this, but this does not improve
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   357
the finiteness property we are proving. If we are interested in a polynomial bound,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   358
one would hope to obtain a similar tight bound as for partial
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   359
derivatives introduced by Antimirov \cite{Antimirov95}. After all the idea with
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   360
 $\distinctWith$ is to maintain a ``set'' of alternatives (like the sets in
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   361
partial derivatives). 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   362
To obtain the exact same bound would mean
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   363
we need to introduce simplifications, such as
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   364
 $(r_1 + r_2) \cdot r_3 \longrightarrow (r_1 \cdot r_3) + (r_2 \cdot r_3)$,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   365
which exist for partial derivatives. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   366
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   367
However, if we introduce them in our
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   368
setting we would lose the POSIX property of our calculated values. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   369
A simple example for this would be the regex $(a + a\cdot b)\cdot(b\cdot c + c)$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   370
If we split this regex up into $a\cdot(b\cdot c + c) + a\cdot b \cdot (b\cdot c + c)$, the lexer 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   371
would give back $\Left(\Seq(\Char(a), \Left(\Char(b \cdot c))))$ instead of
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   372
what we want: $\Seq(\Right(ab), \Right(c))$. Unless we can store the structural information
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   373
in all the places where a transformation of the form $(r_1 + r_2)\cdot r \rightarrow r_1 \cdot r + r_2 \cdot r$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   374
occurs, and apply them in the right order once we get 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   375
a result of the "aggressively simplified" regex, it would be impossible to still get a $\POSIX$ value.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   376
This is unlike the simplification we had before, where the rewriting rules 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   377
such  as $\ONE \cdot r \rightsquigarrow r$, under which our lexer will give the same value.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   378
We will discuss better
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   379
bounds in the last section of this chapter.\\[-6.5mm]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   380
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   381
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   382
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   383
468
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
   384
%----------------------------------------------------------------------------------------
507
213220f54a6e thesis section2.2
Chengsong
parents: 506
diff changeset
   385
%	SECTION ??
468
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
   386
%----------------------------------------------------------------------------------------
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
   387
500
Chengsong
parents: 468
diff changeset
   388
\section{"Closed Forms" of regular expressions' derivatives w.r.t strings}
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   389
To embark on getting the "closed forms" of regexes, we first
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   390
define a few auxiliary definitions to make expressing them smoothly.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   391
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   392
 \begin{center}  
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   393
 \begin{tabular}{ccc}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   394
 $\sflataux{\AALTS{ }{r :: rs}}$ & $=$ & $\sflataux{r} @ rs$\\
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   395
$\sflataux{\AALTS{ }{[]}}$ & $ = $ & $ []$\\
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   396
$\sflataux r$ & $=$ & $ [r]$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   397
\end{tabular}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   398
\end{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   399
The intuition behind $\sflataux{\_}$ is to break up nested regexes 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   400
of the $(\ldots((r_1 + r_2) + r_3) + \ldots )$(left-associated) shape
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   401
into a more "balanced" list: $\AALTS{\_}{[r_1,\, r_2 ,\, r_3, \ldots]}$.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   402
It will return the singleton list $[r]$ otherwise.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   403
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   404
$\sflat{\_}$ works the same  as $\sflataux{\_}$, except that it keeps
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   405
the output type a regular expression, not a list:
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   406
 \begin{center} 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   407
 \begin{tabular}{ccc}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   408
 $\sflat{\AALTS{ }{r :: rs}}$ & $=$ & $\sflataux{r} @ rs$\\
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   409
$\sflat{\AALTS{ }{[]}}$ & $ = $ & $ \AALTS{ }{[]}$\\
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   410
$\sflat r$ & $=$ & $ [r]$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   411
\end{tabular}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   412
\end{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   413
$\sflataux{\_}$  and $\sflat{\_}$ is only recursive in terms of the
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   414
 first element of the list of children of
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   415
an alternative regex ($\AALTS{ }{rs}$), and is purposefully built for  dealing with the regular expression
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   416
$r_1 \cdot r_2 \backslash s$.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   417
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   418
With $\sflat{\_}$ and $\sflataux{\_}$ we make 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   419
precise what  "closed forms" we have for the sequence derivatives and their simplifications,
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   420
in other words, how can we construct $(r_1 \cdot r_2) \backslash s$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   421
and $\bderssimp{(r_1\cdot r_2)}{s}$,
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   422
if we are only allowed to use a combination of $r_1 \backslash s'$ ($\bderssimp{r_1}{s'}$)
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   423
and  $r_2 \backslash s'$ ($\bderssimp{r_2}{s'}$), where $s'$  ranges over 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   424
the substring of $s$?
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   425
First let's look at a series of derivatives steps on a sequence 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   426
regular expression,  (assuming) that each time the first
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   427
component of the sequence is always nullable):
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   428
\begin{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   429
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   430
$r_1 \cdot r_2 \quad \longrightarrow_{\backslash c}  \quad   r_1  \backslash c \cdot r_2 + r_2 \backslash c \quad \longrightarrow_{\backslash c'} \quad (r_1 \backslash cc' \cdot r_2 + r_2 \backslash c') + r_2 \backslash cc' \longrightarrow_{\backslash c''} \quad$\\
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   431
$((r_1 \backslash cc'c'' \cdot r_2 + r_2 \backslash c'') + r_2 \backslash c'c'') + r_2 \backslash cc'c''   \longrightarrow_{\backslash c''} \quad
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   432
 \ldots$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   433
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   434
\end{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   435
%TODO: cite indian paper
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   436
Indianpaper have  come up with a slightly more formal way of putting the above process:
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   437
\begin{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   438
$r_1 \cdot r_2 \backslash (c_1 :: c_2 ::\ldots c_n) \myequiv r_1 \backslash (c_1 :: c_2:: \ldots c_n) +
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   439
\delta(\nullable(r_1 \backslash (c_1 :: c_2 \ldots c_{n-1}) ), r_2 \backslash (c_n)) + \ldots
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   440
+ \delta (\nullable(r_1), r_2\backslash (c_1 :: c_2 ::\ldots c_n))$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   441
\end{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   442
where  $\delta(b, r)$ will produce $r$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   443
if $b$ evaluates to true, 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   444
and $\ZERO$ otherwise.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   445
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   446
 But the $\myequiv$ sign in the above equation means language equivalence instead of syntactical
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   447
 equivalence. To make this intuition useful 
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   448
 for a formal proof, we need something
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   449
stronger than language equivalence.
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   450
With the help of $\sflat{\_}$ we can state the equation in Indianpaper
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   451
more rigorously:
500
Chengsong
parents: 468
diff changeset
   452
\begin{lemma}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   453
$\sflat{(r_1 \cdot r_2) \backslash s} = \RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}$
500
Chengsong
parents: 468
diff changeset
   454
\end{lemma}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   455
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   456
The function $\vsuf{\_}{\_}$ is defined recursively on the structure of the string:
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   457
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   458
\begin{center}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   459
\begin{tabular}{lcl}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   460
$\vsuf{[]}{\_} $ & $=$ &  $[]$\\
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   461
$\vsuf{c::cs}{r_1}$ & $ =$ & $ \textit{if} (\rnullable{r_1}) \textit{then} \; (\vsuf{cs}{(\rder{c}{r_1})}) @ [c :: cs]$\\
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   462
                                     && $\textit{else} \; (\vsuf{cs}{(\rder{c}{r_1}) })  $
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   463
\end{tabular}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   464
\end{center}                   
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   465
It takes into account which prefixes $s'$ of $s$ would make $r \backslash s'$ nullable,
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   466
and keep a list of suffixes $s''$ such that $s' @ s'' = s$. The list is sorted in
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   467
the order $r_2\backslash s''$ appears in $(r_1\cdot r_2)\backslash s$.
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   468
In essence, $\vsuf{\_}{\_}$ is doing a "virtual derivative" of $r_1 \cdot r_2$, but instead of producing 
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   469
the entire result of  $(r_1 \cdot r_2) \backslash s$, 
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   470
it only stores all the $s''$ such that $r_2 \backslash s''$  are occurring terms in $(r_1\cdot r_2)\backslash s$.
500
Chengsong
parents: 468
diff changeset
   471
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   472
With this we can also add simplifications to both sides and get
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   473
\begin{lemma}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   474
$\rsimp{\sflat{(r_1 \cdot r_2) \backslash s} }= \rsimp{\AALTS{[[]}{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}}$
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   475
\end{lemma}
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   476
Together with the idempotency property of $\rsimp$,
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   477
%TODO: state the idempotency property of rsimp
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   478
\begin{lemma}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   479
$\rsimp(r) = \rsimp (\rsimp(r))$
503
35b80e37dfe7 new writing
Chengsong
parents: 500
diff changeset
   480
\end{lemma}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   481
it is possible to convert the above lemma to obtain a "closed form"
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   482
for  derivatives nested with simplification:
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   483
\begin{lemma}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   484
$\rderssimp{(r_1 \cdot r_2)}{s} = \rsimp{\AALTS{[[]}{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}}$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   485
\end{lemma}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   486
And now the reason we have (1) in section 1 is clear:
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   487
$\rsize{\rsimp{\RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map \;(r_2 \backslash \_) \; (\vsuf{s}{r_1}))}}}$, 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   488
is equal to $\rsize{\rsimp{\RALTS{ ((r_1 \backslash s) \cdot r_2 :: (\map \; (r_2 \backslash \_) \; (\textit{Suffix}(r1, s))))}}}$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   489
    as $\vsuf{s}{r_1}$ is one way of expressing the list $\textit{Suffix}( r_1, s)$.
500
Chengsong
parents: 468
diff changeset
   490
Chengsong
parents: 468
diff changeset
   491
%----------------------------------------------------------------------------------------
Chengsong
parents: 468
diff changeset
   492
%	SECTION 3
Chengsong
parents: 468
diff changeset
   493
%----------------------------------------------------------------------------------------
Chengsong
parents: 468
diff changeset
   494
Chengsong
parents: 468
diff changeset
   495
\section{interaction between $\distinctWith$ and $\flts$}
Chengsong
parents: 468
diff changeset
   496
Note that it is not immediately obvious that 
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   497
\begin{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   498
$\llbracket \distinctWith (\flts \textit{rs}) = \phi \rrbracket   \leq \llbracket \distinctWith \textit{rs} = \phi \rrbracket  $.
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   499
\end{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   500
The intuition is that if we remove duplicates from the $\textit{LHS}$, at least the same amount of 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   501
duplicates will be removed from the list $\textit{rs}$ in the $\textit{RHS}$. 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   502
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   503
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   504
%----------------------------------------------------------------------------------------
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   505
%	SECTION ALTS CLOSED FORM
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   506
%----------------------------------------------------------------------------------------
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   507
\section{A Closed Form for \textit{ALTS}}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   508
Now we prove that  $rsimp (rders\_simp (RALTS rs) s) = rsimp (RALTS (map (\lambda r. rders\_simp r s) rs))$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   509
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   510
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   511
There are a few key steps, one of these steps is
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   512
$rsimp (rsimp\_ALTs (map (rder x) (rdistinct (rflts (map (rsimp \circ (\lambda r. rders\_simp r xs)) rs)) {})))
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   513
= rsimp (rsimp\_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \circ (\lambda r. rders\_simp r xs)) rs))) {}))$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   514
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   515
One might want to prove this by something a simple statement like: 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   516
$map (rder x) (rdistinct rs rset) = rdistinct (map (rder x) rs) (rder x) ` rset)$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   517
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   518
For this to hold we want the $\textit{distinct}$ function to pick up
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   519
the elements before and after derivatives correctly:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   520
$r \in rset \equiv (rder x r) \in (rder x rset)$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   521
which essentially requires that the function $\backslash$ is an injective mapping.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   522
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   523
Unfortunately the function $\backslash c$ is not an injective mapping.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   524
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   525
\subsection{function $\backslash c$ is not injective (1-to-1)}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   526
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   527
The derivative $w.r.t$ character $c$ is not one-to-one.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   528
Formally,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   529
	$\exists r_1 \;r_2. r_1 \neq r_2 \mathit{and} r_1 \backslash c = r_2 \backslash c$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   530
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   531
This property is trivially true for the
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   532
character regex example:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   533
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   534
	$r_1 = e; \; r_2 = d;\; r_1 \backslash c = \ZERO = r_2 \backslash c$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   535
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   536
But apart from the cases where the derivative
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   537
output is $\ZERO$, are there non-trivial results
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   538
of derivatives which contain strings?
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   539
The answer is yes.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   540
For example,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   541
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   542
	Let $r_1 = a^*b\;\quad r_2 = (a\cdot a^*)\cdot b + b$.\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   543
	where $a$ is not nullable.\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   544
	$r_1 \backslash c = ((a \backslash c)\cdot a^*)\cdot c + b \backslash c$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   545
	$r_2 \backslash c = ((a \backslash c)\cdot a^*)\cdot c + b \backslash c$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   546
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   547
We start with two syntactically different regexes,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   548
and end up with the same derivative result.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   549
This is not surprising as we have such 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   550
equality as below in the style of Arden's lemma:\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   551
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   552
	$L(A^*B) = L(A\cdot A^* \cdot B + B)$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   553
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   554
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   555
%----------------------------------------------------------------------------------------
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   556
%	SECTION 4
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   557
%----------------------------------------------------------------------------------------
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   558
\section{A Bound for the Star Regular Expression}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   559
We have shown how to control the size of the sequence regular expression $r_1\cdot r_2$ using
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   560
the "closed form" of $(r_1 \cdot r_2) \backslash s$ and then 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   561
the property of the $\distinct$ function.
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   562
Now we try to get a bound on $r^* \backslash s$ as well.
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   563
Again, we first look at how a star's derivatives evolve, if they grow maximally: 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   564
\begin{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   565
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   566
$r^* \quad \longrightarrow_{\backslash c}  \quad   (r\backslash c)  \cdot  r^* \quad \longrightarrow_{\backslash c'}  \quad
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   567
r \backslash cc'  \cdot r^* + r \backslash c' \cdot r^*  \quad \longrightarrow_{\backslash c''} \quad 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   568
(r_1 \backslash cc'c'' \cdot r^* + r \backslash c'') + (r \backslash c'c'' \cdot r^* + r \backslash c'' \cdot r^*)   \quad \longrightarrow_{\backslash c'''}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   569
\quad \ldots$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   570
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   571
\end{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   572
When we have a string $s = c :: c' :: c'' \ldots$  such that $r \backslash c$, $r \backslash cc'$, $r \backslash c'$, 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   573
$r \backslash cc'c''$, $r \backslash c'c''$, $r\backslash c''$ etc. are all nullable,
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   574
the number of terms in $r^* \backslash s$ will grow exponentially, causing the size
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   575
of the derivatives $r^* \backslash s$ to grow exponentially, even if we do not 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   576
count the possible size explosions of $r \backslash c$ themselves.
468
a0f27e21b42c all texrelated
Chengsong
parents:
diff changeset
   577
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   578
Thanks to $\flts$ and $\distinctWith$, we are able to open up regexes like
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   579
$(r_1 \backslash cc'c'' \cdot r^* + r \backslash c'') + (r \backslash c'c'' \cdot r^* + r \backslash c'' \cdot r^*) $ 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   580
into $\RALTS{[r_1 \backslash cc'c'' \cdot r^*, r \backslash c'', r \backslash c'c'' \cdot r^*, r \backslash c'' \cdot r^*]}$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   581
and then de-duplicate terms of the form $r\backslash s' \cdot r^*$ ($s'$ being a substring of $s$).
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   582
For this we define $\hflataux{\_}$ and $\hflat{\_}$, similar to $\sflataux{\_}$ and $\sflat{\_}$:
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   583
%TODO: definitions of  and \hflataux \hflat
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   584
 \begin{center}  
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   585
 \begin{tabular}{ccc}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   586
 $\hflataux{r_1 + r_2}$ & $=$ & $\hflataux{r_1} @ \hflataux{r_2}$\\
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   587
$\hflataux r$ & $=$ & $ [r]$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   588
\end{tabular}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   589
\end{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   590
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   591
 \begin{center}  
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   592
 \begin{tabular}{ccc}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   593
 $\hflat{r_1 + r_2}$ & $=$ & $\RALTS{\hflataux{r_1} @ \hflataux{r_2}}$\\
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   594
$\hflat r$ & $=$ & $ r$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   595
\end{tabular}
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   596
\end{center}s
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   597
Again these definitions are tailor-made for dealing with alternatives that have
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   598
originated from a star's derivatives, so we don't attempt to open up all possible 
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   599
regexes of the form $\RALTS{rs}$, where $\textit{rs}$ might not contain precisely 2
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   600
elements.
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   601
We give a predicate for such "star-created" regular expressions:
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   602
\begin{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   603
\begin{tabular}{lcr}
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   604
         &    &       $\createdByStar{(\RSEQ{ra}{\RSTAR{rb}}) }$\\
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   605
 $\createdByStar{r_1} \land \createdByStar{r_2} $ & $ \Longrightarrow$ & $\createdByStar{(r_1 + r_2)}$
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   606
 \end{tabular}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   607
 \end{center}
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   608
 
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   609
 These definitions allows us the flexibility to talk about 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   610
 regular expressions in their most convenient format,
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   611
 for example, flattened out $\RALTS{[r_1, r_2, \ldots, r_n]} $
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   612
 instead of binary-nested: $((r_1 + r_2) + (r_3 + r_4)) + \ldots$.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   613
 These definitions help express that certain classes of syntatically 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   614
 distinct regular expressions are actually the same under simplification.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   615
 This is not entirely true for annotated regular expressions: 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   616
 %TODO: bsimp bders \neq bderssimp
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   617
 \begin{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   618
 $(1+ (c\cdot \ASEQ{bs}{c^*}{c} ))$
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   619
 \end{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   620
 For bit-codes, the order in which simplification is applied
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   621
 might cause a difference in the location they are placed.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   622
 If we want something like
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   623
 \begin{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   624
 $\bderssimp{r}{s} \myequiv \bsimp{\bders{r}{s}}$
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   625
 \end{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   626
 Some "canonicalization" procedure is required,
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   627
 which either pushes all the common bitcodes to nodes
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   628
  as senior as possible:
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   629
  \begin{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   630
  $_{bs}(_{bs_1 @ bs'}r_1 + _{bs_1 @ bs''}r_2) \rightarrow _{bs @ bs_1}(_{bs'}r_1 + _{bs''}r_2) $
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   631
  \end{center}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   632
 or does the reverse. However bitcodes are not of interest if we are talking about
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   633
 the $\llbracket r \rrbracket$ size of a regex.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   634
 Therefore for the ease and simplicity of producing a
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   635
 proof for a size bound, we are happy to restrict ourselves to 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   636
 unannotated regular expressions, and obtain such equalities as
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   637
 \begin{lemma}
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   638
 $\rsimp{r_1 + r_2} = \rsimp{\RALTS{\hflataux{r_1} @ \hflataux{r_2}}}$
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   639
 \end{lemma}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   640
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   641
 \begin{proof}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   642
 By using the rewriting relation $\rightsquigarrow$
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   643
 \end{proof}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   644
 %TODO: rsimp sflat
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   645
And from this we obtain a proof that a star's derivative will be the same
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   646
as if it had all its nested alternatives created during deriving being flattened out:
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   647
 For example,
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   648
 \begin{lemma}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   649
 $\createdByStar{r} \implies \rsimp{r} = \rsimp{\RALTS{\hflataux{r}}}$
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   650
 \end{lemma}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   651
 \begin{proof}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   652
 By structural induction on $r$, where the induction rules are these of $\createdByStar{_}$.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   653
 \end{proof}
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   654
% The simplification of a flattened out regular expression, provided it comes
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   655
%from the derivative of a star, is the same as the one nested.
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   656
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   657
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   658
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   659
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   660
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   661
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   662
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   663
 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   664
 
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   665
One might wonder the actual bound rather than the loose bound we gave
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   666
for the convenience of an easier proof.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   667
How much can the regex $r^* \backslash s$ grow? 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   668
As  earlier graphs have shown,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   669
%TODO: reference that graph where size grows quickly
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   670
 they can grow at a maximum speed
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   671
  exponential $w.r.t$ the number of characters, 
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   672
but will eventually level off when the string $s$ is long enough.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   673
If they grow to a size exponential $w.r.t$ the original regex, our algorithm
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   674
would still be slow.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   675
And unfortunately, we have concrete examples
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   676
where such regexes grew exponentially large before levelling off:
516
6fecb7fe8cd0 blexer2: modified for plotting
Chengsong
parents: 515
diff changeset
   677
$(a ^ * + (aa) ^ * + (aaa) ^ * + \ldots + 
6fecb7fe8cd0 blexer2: modified for plotting
Chengsong
parents: 515
diff changeset
   678
(\underbrace{a \ldots a}_{\text{n a's}})^*$ will already have a maximum
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   679
 size that is  exponential on the number $n$ 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   680
under our current simplification rules:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   681
%TODO: graph of a regex whose size increases exponentially.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   682
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   683
\begin{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   684
    \begin{axis}[
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   685
        height=0.5\textwidth,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   686
        width=\textwidth,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   687
        xlabel=number of a's,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   688
        xtick={0,...,9},
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   689
        ylabel=maximum size,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   690
        ymode=log,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   691
       log basis y={2}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   692
]
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   693
        \addplot[mark=*,blue] table {re-chengsong.data};
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   694
    \end{axis}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   695
\end{tikzpicture}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   696
\end{center}
505
5ce3bd8e5696 thesis chapter2 section 2.4
Chengsong
parents: 503
diff changeset
   697
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   698
For convenience we use $(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   699
to express $(a ^ * + (aa) ^ * + (aaa) ^ * + \ldots + 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   700
(\underbrace{a \ldots a}_{\text{n a's}})^*$ in the below discussion.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   701
The exponential size is triggered by that the regex
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   702
$\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   703
inside the $(\ldots) ^*$ having exponentially many
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   704
different derivatives, despite those difference being minor.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   705
$(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*\backslash \underbrace{a \ldots a}_{\text{m a's}}$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   706
will therefore contain the following terms (after flattening out all nested 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   707
alternatives):
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   708
\begin{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   709
$(\oplus_{i = 1]{n}  (\underbrace{a \ldots a}_{\text{((i - (m' \% i))\%i) a's}})\cdot  (\underbrace{a \ldots a}_{\text{i a's}})^* })\cdot (\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   710
$(1 \leq m' \leq m )$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   711
\end{center}
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   712
These terms are distinct for $m' \leq L.C.M.(1, \ldots, n)$ (will be explained in appendix).
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   713
 With each new input character taking the derivative against the intermediate result, more and more such distinct
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   714
 terms will accumulate, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   715
until the length reaches $L.C.M.(1, \ldots, n)$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   716
$\textit{distinctBy}$ will not be able to de-duplicate any two of these terms 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   717
$(\oplus_{i = 1}^{n}  (\underbrace{a \ldots a}_{\text{((i - (m' \% i))\%i) a's}})\cdot  (\underbrace{a \ldots a}_{\text{i a's}})^* )\cdot (\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$\\
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   718
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   719
$(\oplus_{i = 1}^{n}  (\underbrace{a \ldots a}_{\text{((i - (m'' \% i))\%i) a's}})\cdot  (\underbrace{a \ldots a}_{\text{i a's}})^* )\cdot (\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$\\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   720
 where $m' \neq m''$ \\
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   721
 as they are slightly different.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   722
 This means that with our current simplification methods,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   723
 we will not be able to control the derivative so that
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   724
 $\llbracket \bderssimp{r}{s} \rrbracket$ stays polynomial %\leq O((\llbracket r\rrbacket)^c)$
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   725
 as there are already exponentially many terms.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   726
 These terms are similar in the sense that the head of those terms
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   727
 are all consisted of sub-terms of the form: 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   728
 $(\underbrace{a \ldots a}_{\text{j a's}})\cdot  (\underbrace{a \ldots a}_{\text{i a's}})^* $.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   729
 For  $\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*$, there will be at most
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   730
 $n * (n + 1) / 2$ such terms. 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   731
 For example, $(a^* + (aa)^* + (aaa)^*) ^*$'s derivatives
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   732
 can be described by 6 terms:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   733
 $a^*$, $a\cdot (aa)^*$, $ (aa)^*$, 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   734
 $aa \cdot (aaa)^*$, $a \cdot (aaa)^*$, and $(aaa)^*$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   735
The total number of different "head terms",  $n * (n + 1) / 2$,
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   736
 is proportional to the number of characters in the regex 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   737
$(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   738
This suggests a slightly different notion of size, which we call the 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   739
alphabetic width:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   740
%TODO:
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   741
(TODO: Alphabetic width def.)
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   742
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   743
 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   744
Antimirov\parencite{Antimirov95} has proven that 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   745
$\textit{PDER}_{UNIV}(r) \leq \textit{awidth}(r)$.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   746
where $\textit{PDER}_{UNIV}(r)$ is a set of all possible subterms
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   747
created by doing derivatives of $r$ against all possible strings.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   748
If we can make sure that at any moment in our lexing algorithm our 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   749
intermediate result hold at most one copy of each of the 
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   750
subterms then we can get the same bound as Antimirov's.
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   751
This leads to the algorithm in the next section.
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   752
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   753
%----------------------------------------------------------------------------------------
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   754
%	SECTION 5
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   755
%----------------------------------------------------------------------------------------
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   756
\section{A Stronger Version of Simplification Inspired by Antimirov}
506
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   757
%TODO: search for isabelle proofs of algorithms that check equivalence 
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   758
69ad05398894 thesis chapter 2 section 2.4 2.5
Chengsong
parents: 505
diff changeset
   759
518
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   760
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   761
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   762
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   763
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   764
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   765
ff7945a988a3 more to thesis
Chengsong
parents: 516
diff changeset
   766