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