532
|
1 |
% Chapter Template
|
|
2 |
|
|
3 |
\chapter{Finiteness Bound} % Main chapter title
|
|
4 |
|
|
5 |
\label{Finite}
|
|
6 |
% In Chapter 4 \ref{Chapter4} we give the second guarantee
|
|
7 |
%of our bitcoded algorithm, that is a finite bound on the size of any
|
|
8 |
%regex's derivatives.
|
|
9 |
|
|
10 |
In this chapter we give a guarantee in terms of time complexity:
|
|
11 |
given a regular expression $r$, for any string $s$
|
|
12 |
our algorithm's internal data structure is finitely bounded.
|
543
|
13 |
Note that it is not immediately obvious that $\llbracket \bderssimp{r}{s} \rrbracket$ (the internal
|
|
14 |
data structure used in our $\blexer$)
|
|
15 |
is bounded by a constant $N_r$, where $N$ only depends on the regular expression
|
|
16 |
$r$, not the string $s$.
|
|
17 |
When doing a time complexity analysis of any
|
|
18 |
lexer/parser based on Brzozowski derivatives, one needs to take into account that
|
|
19 |
not only the "derivative steps".
|
|
20 |
|
|
21 |
%TODO: get a grpah for internal data structure growing arbitrary large
|
|
22 |
|
|
23 |
|
532
|
24 |
To obtain such a proof, we need to
|
|
25 |
\begin{itemize}
|
|
26 |
\item
|
|
27 |
Define an new datatype for regular expressions that makes it easy
|
|
28 |
to reason about the size of an annotated regular expression.
|
|
29 |
\item
|
|
30 |
A set of equalities for this new datatype that enables one to
|
|
31 |
rewrite $\bderssimp{r_1 \cdot r_2}{s}$ and $\bderssimp{r^*}{s}$ etc.
|
|
32 |
by their children regexes $r_1$, $r_2$, and $r$.
|
|
33 |
\item
|
|
34 |
Using those equalities to actually get those rewriting equations, which we call
|
|
35 |
"closed forms".
|
|
36 |
\item
|
|
37 |
Bound the closed forms, thereby bounding the original
|
|
38 |
$\blexersimp$'s internal data structures.
|
|
39 |
\end{itemize}
|
|
40 |
|
|
41 |
\section{the $\mathbf{r}$-rexp datatype and the size functions}
|
|
42 |
|
|
43 |
We have a size function for bitcoded regular expressions, written
|
|
44 |
$\llbracket r\rrbracket$, which counts the number of nodes if we regard $r$ as a tree
|
|
45 |
|
|
46 |
\begin{center}
|
|
47 |
\begin{tabular}{ccc}
|
543
|
48 |
$\llbracket _{bs}\ONE \rrbracket$ & $\dn$ & $1$\\
|
|
49 |
$\llbracket \ZERO \rrbracket$ & $\dn$ & $1$ \\
|
|
50 |
$\llbracket _{bs} r_1 \cdot r_2 \rrbracket$ & $\dn$ & $\llbracket r_1 \rrbracket + \llbracket r_2 \rrbracket + 1$\\
|
|
51 |
$\llbracket _{bs}\mathbf{c} \rrbracket $ & $\dn$ & $1$\\
|
|
52 |
$\llbracket _{bs}\sum as \rrbracket $ & $\dn$ & $\map \; (\llbracket \_ \rrbracket)\; as + 1$\\
|
|
53 |
$\llbracket _{bs} a^* \rrbracket $ & $\dn$ & $\llbracket a \rrbracket + 1$
|
|
54 |
\end{tabular}
|
|
55 |
\end{center}
|
|
56 |
|
|
57 |
\noindent
|
|
58 |
Similarly there is a size function for plain regular expressions:
|
|
59 |
\begin{center}
|
|
60 |
\begin{tabular}{ccc}
|
|
61 |
$\llbracket \ONE \rrbracket_p$ & $\dn$ & $1$\\
|
|
62 |
$\llbracket \ZERO \rrbracket_p$ & $\dn$ & $1$ \\
|
|
63 |
$\llbracket r_1 \cdot r_2 \rrbracket_p$ & $\dn$ & $\llbracket r_1 \rrbracket_p + \llbracket r_2 \rrbracket_p + 1$\\
|
|
64 |
$\llbracket \mathbf{c} \rrbracket_p $ & $\dn$ & $1$\\
|
|
65 |
$\llbracket r_1 \cdot r_2 \rrbracket_p $ & $\dn$ & $\llbracket r_1 \rrbracket_p \; + \llbracket r_2 \rrbracket_p + 1$\\
|
|
66 |
$\llbracket a^* \rrbracket_p $ & $\dn$ & $\llbracket a \rrbracket_p + 1$
|
532
|
67 |
\end{tabular}
|
|
68 |
\end{center}
|
|
69 |
|
543
|
70 |
\noindent
|
|
71 |
The idea of obatining a bound for $\llbracket \bderssimp{a}{s} \rrbracket$
|
|
72 |
is to get an equivalent form
|
|
73 |
of something like $\llbracket \bderssimp{a}{s}\rrbracket = f(a, s)$, where $f(a, s)$
|
|
74 |
is easier to estimate than $\llbracket \bderssimp{a}{s}\rrbracket$.
|
|
75 |
We notice that while it is not so clear how to obtain
|
|
76 |
a metamorphic representation of $\bderssimp{a}{s}$ (as we argued in chapter \ref{Bitcoded2},
|
|
77 |
not interleaving the application of the functions $\backslash$ and $\bsimp{\_}$
|
|
78 |
in the order as our lexer will result in the bit-codes dispensed differently),
|
|
79 |
it is possible to get an slightly different representation of the unlifted versions:
|
|
80 |
$ (\bderssimp{a}{s})_\downarrow = (\erase \; \bsimp{a \backslash s})_\downarrow$.
|
|
81 |
This suggest setting the bounding function $f(a, s)$ as
|
|
82 |
$\llbracket (a \backslash s)_\downarrow \rrbracket_p$, the plain size
|
|
83 |
of the erased annotated regular expression.
|
|
84 |
This requires the the regular expression accompanied by bitcodes
|
|
85 |
to have the same size as its plain counterpart after erasure:
|
532
|
86 |
\begin{center}
|
543
|
87 |
$\asize{a} \stackrel{?}{=} \llbracket \erase(a)\rrbracket_p$.
|
532
|
88 |
\end{center}
|
543
|
89 |
\noindent
|
|
90 |
But there is a minor nuisance:
|
|
91 |
the erase function unavoidbly messes with the structure of the regular expression,
|
|
92 |
due to the discrepancy between annotated regular expression's $\sum$ constructor
|
|
93 |
and plain regular expression's $+$ constructor having different arity.
|
532
|
94 |
\begin{center}
|
|
95 |
\begin{tabular}{ccc}
|
543
|
96 |
$\erase \; _{bs}\sum [] $ & $\dn$ & $\ZERO$\\
|
|
97 |
$\erase \; _{bs}\sum [a]$ & $\dn$ & $a$\\
|
|
98 |
$\erase \; _{bs}\sum a :: as$ & $\dn$ & $a + (\erase \; _{[]} \sum as)\quad \text{if $as$ length over 1}$
|
532
|
99 |
\end{tabular}
|
|
100 |
\end{center}
|
543
|
101 |
\noindent
|
532
|
102 |
An alternative regular expression with an empty list of children
|
543
|
103 |
is turned into a $\ZERO$ during the
|
532
|
104 |
$\erase$ function, thereby changing the size and structure of the regex.
|
543
|
105 |
Therefore the equality in question does not hold.
|
532
|
106 |
These will likely be fixable if we really want to use plain $\rexp$s for dealing
|
|
107 |
with size, but we choose a more straightforward (or stupid) method by
|
|
108 |
defining a new datatype that is similar to plain $\rexp$s but can take
|
|
109 |
non-binary arguments for its alternative constructor,
|
|
110 |
which we call $\rrexp$ to denote
|
|
111 |
the difference between it and plain regular expressions.
|
|
112 |
\[ \rrexp ::= \RZERO \mid \RONE
|
|
113 |
\mid \RCHAR{c}
|
|
114 |
\mid \RSEQ{r_1}{r_2}
|
|
115 |
\mid \RALTS{rs}
|
|
116 |
\mid \RSTAR{r}
|
|
117 |
\]
|
|
118 |
For $\rrexp$ we throw away the bitcodes on the annotated regular expressions,
|
|
119 |
but keep everything else intact.
|
|
120 |
It is similar to annotated regular expressions being $\erase$-ed, but with all its structure preserved
|
|
121 |
We denote the operation of erasing the bits and turning an annotated regular expression
|
|
122 |
into an $\rrexp{}$ as $\rerase{}$.
|
|
123 |
\begin{center}
|
|
124 |
\begin{tabular}{lcl}
|
543
|
125 |
$\rerase{\ZERO}$ & $\dn$ & $\RZERO$\\
|
|
126 |
$\rerase{_{bs}\ONE}$ & $\dn$ & $\RONE$\\
|
|
127 |
$\rerase{_{bs}\mathbf{c}}$ & $\dn$ & $\RCHAR{c}$\\
|
|
128 |
$\rerase{_{bs}r_1\cdot r_2}$ & $\dn$ & $\RSEQ{\rerase{r_1}}{\rerase{r_2}}$\\
|
|
129 |
$\rerase{_{bs}\sum as}$ & $\dn$ & $\RALTS{\map \; \rerase{\_} \; as}$\\
|
|
130 |
$\rerase{_{bs} a ^*}$ & $\dn$ & $\rerase{a}^*$
|
532
|
131 |
\end{tabular}
|
|
132 |
\end{center}
|
543
|
133 |
\noindent
|
|
134 |
$\rrexp$ give the exact correspondence between an annotated regular expression
|
|
135 |
and its (r-)erased version:
|
|
136 |
\begin{lemma}
|
|
137 |
$\rsize{\rerase a} = \asize a$
|
|
138 |
\end{lemma}
|
|
139 |
This does not hold for plain $\rexp$s.
|
|
140 |
|
532
|
141 |
Similarly we could define the derivative and simplification on
|
|
142 |
$\rrexp$, which would be identical to those we defined for plain $\rexp$s in chapter1,
|
|
143 |
except that now they can operate on alternatives taking multiple arguments.
|
|
144 |
|
|
145 |
\begin{center}
|
|
146 |
\begin{tabular}{lcr}
|
543
|
147 |
$(\RALTS{rs})\; \backslash c$ & $\dn$ & $\RALTS{\map\; (\_ \backslash c) \;rs}$\\
|
532
|
148 |
(other clauses omitted)
|
543
|
149 |
With the new $\rrexp$ datatype in place, one can define its size function,
|
|
150 |
which precisely mirrors that of the annotated regular expressions:
|
|
151 |
\end{tabular}
|
|
152 |
\end{center}
|
|
153 |
\noindent
|
|
154 |
\begin{center}
|
|
155 |
\begin{tabular}{ccc}
|
|
156 |
$\llbracket _{bs}\ONE \rrbracket_r$ & $\dn$ & $1$\\
|
|
157 |
$\llbracket \ZERO \rrbracket_r$ & $\dn$ & $1$ \\
|
|
158 |
$\llbracket _{bs} r_1 \cdot r_2 \rrbracket_r$ & $\dn$ & $\llbracket r_1 \rrbracket_r + \llbracket r_2 \rrbracket_r + 1$\\
|
|
159 |
$\llbracket _{bs}\mathbf{c} \rrbracket_r $ & $\dn$ & $1$\\
|
|
160 |
$\llbracket _{bs}\sum as \rrbracket_r $ & $\dn$ & $\map \; (\llbracket \_ \rrbracket_r)\; as + 1$\\
|
|
161 |
$\llbracket _{bs} a^* \rrbracket_r $ & $\dn$ & $\llbracket a \rrbracket_r + 1$
|
532
|
162 |
\end{tabular}
|
|
163 |
\end{center}
|
543
|
164 |
\noindent
|
532
|
165 |
|
543
|
166 |
\subsection{Lexing Related Functions for $\rrexp$}
|
|
167 |
Everything else for $\rrexp$ will be precisely the same for annotated expressions,
|
|
168 |
except that they do not involve rectifying and augmenting bit-encoded tokenization information.
|
|
169 |
As expected, most functions are simpler, such as the derivative:
|
|
170 |
\begin{center}
|
|
171 |
\begin{tabular}{@{}lcl@{}}
|
|
172 |
$(\ZERO)\,\backslash_r c$ & $\dn$ & $\ZERO$\\
|
|
173 |
$(\ONE)\,\backslash_r c$ & $\dn$ &
|
|
174 |
$\textit{if}\;c=d\; \;\textit{then}\;
|
|
175 |
\ONE\;\textit{else}\;\ZERO$\\
|
|
176 |
$(\sum \;\textit{rs})\,\backslash_r c$ & $\dn$ &
|
|
177 |
$\sum\;(\textit{map} \; (\_\backslash_r c) \; rs )$\\
|
|
178 |
$(r_1\cdot r_2)\,\backslash_r c$ & $\dn$ &
|
|
179 |
$\textit{if}\;\textit{rnullable}\,r_1$\\
|
|
180 |
& &$\textit{then}\;\sum\,[(r_1\,\backslash_r c)\cdot\,r_2,$\\
|
|
181 |
& &$\phantom{\textit{then},\;\sum\,}((r_2\,\backslash_r c))]$\\
|
|
182 |
& &$\textit{else}\;\,(r_1\,\backslash_r c)\cdot r_2$\\
|
|
183 |
$(r^*)\,\backslash_r c$ & $\dn$ &
|
|
184 |
$( r\,\backslash_r c)\cdot
|
|
185 |
(_{[]}r^*))$
|
|
186 |
\end{tabular}
|
|
187 |
\end{center}
|
|
188 |
\noindent
|
|
189 |
The simplification function is simplified without annotation causing superficial differences.
|
|
190 |
Duplicate removal without an equivalence relation:
|
532
|
191 |
\begin{center}
|
|
192 |
\begin{tabular}{lcl}
|
543
|
193 |
$\rdistinct{[]}{rset} $ & $\dn$ & $[]$\\
|
|
194 |
$\rdistinct{r :: rs}{rset}$ & $\dn$ & $\textit{if}(r \in \textit{rset}) \; \textit{then} \; \rdistinct{rs}{rset}$\\
|
532
|
195 |
& & $\textit{else}\; r::\rdistinct{rs}{(rset \cup \{r\})}$
|
|
196 |
\end{tabular}
|
|
197 |
\end{center}
|
|
198 |
%TODO: definition of rsimp (maybe only the alternative clause)
|
543
|
199 |
\noindent
|
|
200 |
With $\textit{rdistinct}$ one can chain together all the other modules
|
|
201 |
of $\bsimp{\_}$ (removing the functionalities related to bit-sequences)
|
|
202 |
and get $\textit{rsimp}$ and $\rderssimp{\_}{\_}$.
|
|
203 |
We omit these functions, as they are routine. Please refer to the formalisation
|
|
204 |
(in file BasicIdentities.thy) for the exact definition.
|
|
205 |
With $\rrexp$ the size caclulation of annotated regular expressions'
|
|
206 |
simplification and derivatives can be done by the size of their unlifted
|
|
207 |
counterpart with the unlifted version of simplification and derivatives applied.
|
532
|
208 |
\begin{lemma}
|
543
|
209 |
\begin{itemize}
|
|
210 |
\item
|
|
211 |
$\asize{\bsimp{a}} = \rsize{\rsimp{\rerase{a}}}$
|
|
212 |
\item
|
|
213 |
$\asize{\bderssimp{r}{s}} = \rsize{\rderssimp{\rerase{r}}{s}}$
|
|
214 |
\end{itemize}
|
532
|
215 |
\end{lemma}
|
543
|
216 |
\noindent
|
|
217 |
In the following content, we will focus on $\rrexp$'s size bound.
|
|
218 |
We will piece together this bound and show the same bound for annotated regular
|
|
219 |
expressions in the end.
|
532
|
220 |
Unless stated otherwise in this chapter all $\textit{rexp}$s without
|
|
221 |
bitcodes are seen as $\rrexp$s.
|
|
222 |
We also use $r_1 + r_2$ and $\RALTS{[r_1, r_2]}$ interchageably
|
|
223 |
as the former suits people's intuitive way of stating a binary alternative
|
|
224 |
regular expression.
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
%-----------------------------------
|
|
229 |
% SECTION ?
|
|
230 |
%-----------------------------------
|
543
|
231 |
\section{Roadmap to a Finiteness Proof}
|
|
232 |
Now that we have defined the $\rrexp$ datatype, and proven that its size changes
|
|
233 |
w.r.t derivatives and simplifications mirrors precisely those of annotated regular expressions,
|
|
234 |
we aim to bound the size of $r \backslash s$ for any $\rrexp$ $r$.
|
|
235 |
The way we do it is by two steps:
|
|
236 |
\begin{itemize}
|
|
237 |
\item
|
|
238 |
First, we rewrite $r\backslash s$ into something else that is easier
|
|
239 |
to bound. This step is especially important for the inductive case
|
|
240 |
$r_1 \cdot r_2$ and $r^*$, where the derivative can grow and bloat in a wild way,
|
|
241 |
but after simplification they will always be equal or smaller to a form consisting of an alternative
|
|
242 |
list of regular expressions $f \; (g\; (\sum rs))$ with some functions applied to it, where each element will be distinct after the function application.
|
|
243 |
The functions $f$ and $g$ are usually from $\flts$ $\distinctBy$ and other appearing in $\bsimp{_}$.
|
|
244 |
This way we get a different but equivalent way of expressing : $r\backslash s = f \; (g\; (\sum rs))$, we call the
|
|
245 |
right hand side the "closed form" of $r\backslash s$.
|
|
246 |
\item
|
|
247 |
Then, for such a sum list of regular expressions $f\; (g\; (\sum rs))$, we can control its size
|
|
248 |
by estimation, since $\distinctBy$ and $\flts$ are well-behaved and working together would only
|
|
249 |
reduce the size of a regular expression, not adding to it. The closed form $f\; (g\; (\sum rs)) $ is controlled
|
|
250 |
by the size of $rs'$, where every element in $rs'$ is distinct, and each element can be described by som e inductive sub-structures (for example when $r = r_1 \cdot r_2$ then $rs'$ will be solely comprised of $r_1 \backslash s'$ and $r_2 \backslash s''$, $s'$ and $s''$ being sub-strings of $s$), which will have a numeric uppder bound according to inductive hypothesis, which controls $r \backslash s$.
|
|
251 |
\end{itemize}
|
|
252 |
|
|
253 |
\section{Closed Forms}
|
|
254 |
|
|
255 |
\subsection{Basic Properties needed for Closed Forms}
|
|
256 |
|
|
257 |
\subsubsection{$\textit{rdistinct}$'s Deduplicates Successfully}
|
|
258 |
The $\textit{rdistinct}$ function, as its name suggests, will
|
|
259 |
remove duplicates according to the accumulator
|
|
260 |
and leave only one of each different element in a list:
|
|
261 |
\begin{lemma}
|
|
262 |
The function $\textit{rdistinct}$ satisfies the following
|
|
263 |
properties:
|
|
264 |
\begin{itemize}
|
|
265 |
\item
|
|
266 |
If $a \in acc$ then $a \notin (\rdistinct{rs}{acc})$.
|
|
267 |
\item
|
|
268 |
If list $rs'$ is the result of $\rdistinct{rs}{acc}$,
|
|
269 |
All the elements in $rs'$ are unique.
|
|
270 |
\end{itemize}
|
|
271 |
\end{lemma}
|
|
272 |
\begin{proof}
|
|
273 |
The first part is by an induction on $rs$.
|
|
274 |
The second part can be proven by using the
|
|
275 |
induction rules of $\rdistinct{\_}{\_}$.
|
|
276 |
|
|
277 |
\end{proof}
|
|
278 |
|
|
279 |
\noindent
|
|
280 |
$\rdistinct{\_}{\_}$ will cancel out all regular expression terms
|
|
281 |
that are in the accumulator, therefore prepending a list $rs_a$ with an arbitrary
|
|
282 |
list $rs$ whose elements are all from the accumulator, and then call $\rdistinct{\_}{\_}$
|
|
283 |
on the resulting list, the output will be as if we had called $\rdistinct{\_}{\_}$
|
|
284 |
without the prepending of $rs$:
|
|
285 |
\begin{lemma}
|
|
286 |
If $rs \subseteq rset$, then
|
|
287 |
$\rdistinct{rs@rsa }{acc} = \rdistinct{rsa }{acc}$.
|
|
288 |
\end{lemma}
|
|
289 |
\begin{proof}
|
|
290 |
By induction on $rs$.
|
|
291 |
\end{proof}
|
|
292 |
\noindent
|
|
293 |
On the other hand, if an element $r$ does not appear in the input list waiting to be deduplicated,
|
|
294 |
then expanding the accumulator to include that element will not cause the output list to change:
|
|
295 |
\begin{lemma}
|
|
296 |
The accumulator can be augmented to include elements not appearing in the input list,
|
|
297 |
and the output will not change.
|
|
298 |
\begin{itemize}
|
|
299 |
\item
|
|
300 |
If $r \notin rs$, then $\rdistinct{rs}{acc} = \rdistinct{rs}{\{r\} \cup acc}$.
|
|
301 |
\item
|
|
302 |
Particularly, when $acc = \varnothing$ and $rs$ de-duplicated, we have\\
|
|
303 |
\[ \rdistinct{rs}{\varnothing} = rs \]
|
|
304 |
\end{itemize}
|
|
305 |
\end{lemma}
|
|
306 |
\begin{proof}
|
|
307 |
The first half is by induction on $rs$. The second half is a corollary of the first.
|
|
308 |
\end{proof}
|
|
309 |
\noindent
|
|
310 |
The next property gives the condition for
|
|
311 |
when $\rdistinct{\_}{\_}$ becomes an identical mapping
|
|
312 |
for any prefix of an input list, in other words, when can
|
|
313 |
we ``push out" the arguments of $\rdistinct{\_}{\_}$:
|
|
314 |
\begin{lemma}
|
|
315 |
If $rs_1$'s elements are all unique, and not appearing in the accumulator $acc$,
|
|
316 |
then it can be taken out and left untouched in the output:
|
|
317 |
\[\textit{rdistinct}\; rs_1 @ rsa\;\, acc
|
|
318 |
= rs_1@(\textit{rdistinct} rsa \; (acc \cup rs_1)\]
|
|
319 |
\end{lemma}
|
|
320 |
|
|
321 |
\begin{proof}
|
|
322 |
By an induction on $rs_1$, where $rsa$ and $acc$ are allowed to be arbitrary.
|
|
323 |
\end{proof}
|
|
324 |
\subsubsection{The properties of $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS}$}
|
|
325 |
We give in this subsection some properties of how $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS} $ interact with each other and with $@$, the concatenation operator.
|
|
326 |
These will be helpful in later closed form proofs, when
|
|
327 |
we want to transform the ways in which multiple functions involving
|
|
328 |
those are composed together
|
|
329 |
in interleaving derivative and simplification steps.
|
|
330 |
|
|
331 |
When the function $\textit{Rflts}$
|
|
332 |
is applied to the concatenation of two lists, the output can be calculated by first applying the
|
|
333 |
functions on two lists separately, and then concatenating them together.
|
|
334 |
\begin{lemma}
|
|
335 |
The function $\rflts$ has the below properties:\\
|
|
336 |
\begin{itemize}
|
|
337 |
\item
|
|
338 |
$\rflts \; (rs_1 @ rs_2) = \rflts \; rs_1 @ \rflts \; rs_2$
|
|
339 |
\item
|
|
340 |
If $r \neq \RZERO$ and $\nexists rs_1. r = \RALTS{rs}_1$, then $\rflts \; (r::rs) = r :: \rflts \; rs$
|
|
341 |
\end{itemize}
|
|
342 |
\end{lemma}
|
|
343 |
\noindent
|
|
344 |
\begin{proof}
|
|
345 |
By induction on $rs_1$.
|
|
346 |
\end{proof}
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
\subsection{A Closed Form for the Sequence Regular Expression}
|
|
351 |
\begin{quote}\it
|
|
352 |
Claim: For regular expressions $r_1 \cdot r_2$, we claim that
|
|
353 |
\begin{center}
|
|
354 |
$ \rderssimp{r_1 \cdot r_2}{s} =
|
|
355 |
\rsimp{(\sum (r_1 \backslash s \cdot r_2 ) \; :: \;(\map \; \rderssimp{r2}{\_} \;(\vsuf{s}{r_1})))}$
|
|
356 |
\end{center}
|
|
357 |
\end{quote}
|
|
358 |
\noindent
|
|
359 |
|
532
|
360 |
Before we get to the proof that says the intermediate result of our lexer will
|
|
361 |
remain finitely bounded, which is an important efficiency/liveness guarantee,
|
|
362 |
we shall first develop a few preparatory properties and definitions to
|
|
363 |
make the process of proving that a breeze.
|
|
364 |
|
|
365 |
We define rewriting relations for $\rrexp$s, which allows us to do the
|
|
366 |
same trick as we did for the correctness proof,
|
|
367 |
but this time we will have stronger equalities established.
|
|
368 |
\subsection{"hrewrite" relation}
|
|
369 |
List of 1-step rewrite rules for regular expressions simplification without bitcodes:
|
|
370 |
\begin{figure}
|
|
371 |
\caption{the "h-rewrite" rules}
|
|
372 |
\[
|
|
373 |
r_1 \cdot \ZERO \rightarrow_h \ZERO \]
|
|
374 |
|
|
375 |
\[
|
|
376 |
\ZERO \cdot r_2 \rightarrow \ZERO
|
|
377 |
\]
|
|
378 |
\end{figure}
|
|
379 |
And we define an "grewrite" relation that works on lists:
|
|
380 |
\begin{center}
|
|
381 |
\begin{tabular}{lcl}
|
|
382 |
$ \ZERO :: rs$ & $\rightarrow_g$ & $rs$
|
|
383 |
\end{tabular}
|
|
384 |
\end{center}
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
With these relations we prove
|
|
389 |
\begin{lemma}
|
|
390 |
$rs \rightarrow rs' \implies \RALTS{rs} \rightarrow \RALTS{rs'}$
|
|
391 |
\end{lemma}
|
|
392 |
which enables us to prove "closed forms" equalities such as
|
|
393 |
\begin{lemma}
|
|
394 |
$\sflat{(r_1 \cdot r_2) \backslash s} = \RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\suffix \; s \; r_1 ))}$
|
|
395 |
\end{lemma}
|
|
396 |
|
|
397 |
But the most involved part of the above lemma is proving the following:
|
|
398 |
\begin{lemma}
|
|
399 |
$\bsimp{\RALTS{rs @ \RALTS{rs_1} @ rs'}} = \bsimp{\RALTS{rs @rs_1 @ rs'}} $
|
|
400 |
\end{lemma}
|
|
401 |
which is needed in proving things like
|
|
402 |
\begin{lemma}
|
|
403 |
$r \rightarrow_f r' \implies \rsimp{r} \rightarrow \rsimp{r'}$
|
|
404 |
\end{lemma}
|
|
405 |
|
|
406 |
Fortunately this is provable by induction on the list $rs$
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
%-----------------------------------
|
|
411 |
% SECTION 2
|
|
412 |
%-----------------------------------
|
|
413 |
|
|
414 |
\begin{theorem}
|
|
415 |
For any regex $r$, $\exists N_r. \forall s. \; \llbracket{\bderssimp{r}{s}}\rrbracket \leq N_r$
|
|
416 |
\end{theorem}
|
|
417 |
|
|
418 |
\noindent
|
|
419 |
\begin{proof}
|
|
420 |
We prove this by induction on $r$. The base cases for $\AZERO$,
|
|
421 |
$\AONE \textit{bs}$ and $\ACHAR \textit{bs} c$ are straightforward. The interesting case is
|
|
422 |
for sequences of the form $\ASEQ{bs}{r_1}{r_2}$. In this case our induction
|
|
423 |
hypotheses state $\exists N_1. \forall s. \; \llbracket \bderssimp{r}{s} \rrbracket \leq N_1$ and
|
|
424 |
$\exists N_2. \forall s. \; \llbracket \bderssimp{r_2}{s} \rrbracket \leq N_2$. We can reason as follows
|
|
425 |
%
|
|
426 |
\begin{center}
|
|
427 |
\begin{tabular}{lcll}
|
|
428 |
& & $ \llbracket \bderssimp{\ASEQ{bs}{r_1}{r_2} }{s} \rrbracket$\\
|
|
429 |
& $ = $ & $\llbracket bsimp\,(\textit{ALTs}\;bs\;(\ASEQ{nil}{\bderssimp{ r_1}{s}}{ r_2} ::
|
|
430 |
[\bderssimp{ r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)]))\rrbracket $ & (1) \\
|
|
431 |
& $\leq$ &
|
|
432 |
$\llbracket\textit{\distinctWith}\,((\ASEQ{nil}{\bderssimp{r_1}{s}}{r_2}$) ::
|
|
433 |
[$\bderssimp{ r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)])\,\approx\;{}\rrbracket + 1 $ & (2) \\
|
|
434 |
& $\leq$ & $\llbracket\ASEQ{bs}{\bderssimp{ r_1}{s}}{r_2}\rrbracket +
|
|
435 |
\llbracket\textit{distinctWith}\,[\bderssimp{r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)]\,\approx\;{}\rrbracket + 1 $ & (3) \\
|
|
436 |
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 +
|
|
437 |
\llbracket \distinctWith\,[ \bderssimp{r_2}{s'} \;|\; s' \in \textit{Suffix}( r_1, s)] \,\approx\;\rrbracket$ & (4)\\
|
|
438 |
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 + l_{N_{2}} * N_{2}$ & (5)
|
|
439 |
\end{tabular}
|
|
440 |
\end{center}
|
|
441 |
|
|
442 |
|
|
443 |
\noindent
|
|
444 |
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$).
|
|
445 |
The reason why we could write the derivatives of a sequence this way is described in section 2.
|
|
446 |
The term (2) is used to control (1).
|
|
447 |
That is because one can obtain an overall
|
|
448 |
smaller regex list
|
|
449 |
by flattening it and removing $\ZERO$s first before applying $\distinctWith$ on it.
|
|
450 |
Section 3 is dedicated to its proof.
|
|
451 |
In (3) we know that $\llbracket \ASEQ{bs}{(\bderssimp{ r_1}{s}}{r_2}\rrbracket$ is
|
|
452 |
bounded by $N_1 + \llbracket{}r_2\rrbracket + 1$. In (5) we know the list comprehension contains only regular expressions of size smaller
|
|
453 |
than $N_2$. The list length after $\distinctWith$ is bounded by a number, which we call $l_{N_2}$. It stands
|
|
454 |
for the number of distinct regular expressions smaller than $N_2$ (there can only be finitely many of them).
|
|
455 |
We reason similarly for $\STAR$.\medskip
|
|
456 |
\end{proof}
|
|
457 |
|
|
458 |
What guarantee does this bound give us?
|
|
459 |
|
|
460 |
Whatever the regex is, it will not grow indefinitely.
|
|
461 |
Take our previous example $(a + aa)^*$ as an example:
|
|
462 |
\begin{center}
|
|
463 |
\begin{tabular}{@{}c@{\hspace{0mm}}c@{\hspace{0mm}}c@{}}
|
|
464 |
\begin{tikzpicture}
|
|
465 |
\begin{axis}[
|
|
466 |
xlabel={number of $a$'s},
|
|
467 |
x label style={at={(1.05,-0.05)}},
|
|
468 |
ylabel={regex size},
|
|
469 |
enlargelimits=false,
|
|
470 |
xtick={0,5,...,30},
|
|
471 |
xmax=33,
|
|
472 |
ymax= 40,
|
|
473 |
ytick={0,10,...,40},
|
|
474 |
scaled ticks=false,
|
|
475 |
axis lines=left,
|
|
476 |
width=5cm,
|
|
477 |
height=4cm,
|
|
478 |
legend entries={$(a + aa)^*$},
|
|
479 |
legend pos=north west,
|
|
480 |
legend cell align=left]
|
|
481 |
\addplot[red,mark=*, mark options={fill=white}] table {a_aa_star.data};
|
|
482 |
\end{axis}
|
|
483 |
\end{tikzpicture}
|
|
484 |
\end{tabular}
|
|
485 |
\end{center}
|
|
486 |
We are able to limit the size of the regex $(a + aa)^*$'s derivatives
|
|
487 |
with our simplification
|
|
488 |
rules very effectively.
|
|
489 |
|
|
490 |
|
|
491 |
In our proof for the inductive case $r_1 \cdot r_2$, the dominant term in the bound
|
|
492 |
is $l_{N_2} * N_2$, where $N_2$ is the bound we have for $\llbracket \bderssimp{r_2}{s} \rrbracket$.
|
|
493 |
Given that $l_{N_2}$ is roughly the size $4^{N_2}$, the size bound $\llbracket \bderssimp{r_1 \cdot r_2}{s} \rrbracket$
|
|
494 |
inflates the size bound of $\llbracket \bderssimp{r_2}{s} \rrbracket$ with the function
|
|
495 |
$f(x) = x * 2^x$.
|
|
496 |
This means the bound we have will surge up at least
|
|
497 |
tower-exponentially with a linear increase of the depth.
|
|
498 |
For a regex of depth $n$, the bound
|
|
499 |
would be approximately $4^n$.
|
|
500 |
|
|
501 |
Test data in the graphs from randomly generated regular expressions
|
|
502 |
shows that the giant bounds are far from being hit.
|
|
503 |
%a few sample regular experessions' derivatives
|
|
504 |
%size change
|
|
505 |
%TODO: giving regex1_size_change.data showing a few regexes' size changes
|
|
506 |
%w;r;t the input characters number, where the size is usually cubic in terms of original size
|
|
507 |
%a*, aa*, aaa*, .....
|
|
508 |
%randomly generated regexes
|
|
509 |
\begin{center}
|
|
510 |
\begin{tabular}{@{}c@{\hspace{0mm}}c@{\hspace{0mm}}c@{}}
|
|
511 |
\begin{tikzpicture}
|
|
512 |
\begin{axis}[
|
|
513 |
xlabel={number of $a$'s},
|
|
514 |
x label style={at={(1.05,-0.05)}},
|
|
515 |
ylabel={regex size},
|
|
516 |
enlargelimits=false,
|
|
517 |
xtick={0,5,...,30},
|
|
518 |
xmax=33,
|
|
519 |
ymax=1000,
|
|
520 |
ytick={0,100,...,1000},
|
|
521 |
scaled ticks=false,
|
|
522 |
axis lines=left,
|
|
523 |
width=5cm,
|
|
524 |
height=4cm,
|
|
525 |
legend entries={regex1},
|
|
526 |
legend pos=north west,
|
|
527 |
legend cell align=left]
|
|
528 |
\addplot[red,mark=*, mark options={fill=white}] table {regex1_size_change.data};
|
|
529 |
\end{axis}
|
|
530 |
\end{tikzpicture}
|
|
531 |
&
|
|
532 |
\begin{tikzpicture}
|
|
533 |
\begin{axis}[
|
|
534 |
xlabel={$n$},
|
|
535 |
x label style={at={(1.05,-0.05)}},
|
|
536 |
%ylabel={time in secs},
|
|
537 |
enlargelimits=false,
|
|
538 |
xtick={0,5,...,30},
|
|
539 |
xmax=33,
|
|
540 |
ymax=1000,
|
|
541 |
ytick={0,100,...,1000},
|
|
542 |
scaled ticks=false,
|
|
543 |
axis lines=left,
|
|
544 |
width=5cm,
|
|
545 |
height=4cm,
|
|
546 |
legend entries={regex2},
|
|
547 |
legend pos=north west,
|
|
548 |
legend cell align=left]
|
|
549 |
\addplot[blue,mark=*, mark options={fill=white}] table {regex2_size_change.data};
|
|
550 |
\end{axis}
|
|
551 |
\end{tikzpicture}
|
|
552 |
&
|
|
553 |
\begin{tikzpicture}
|
|
554 |
\begin{axis}[
|
|
555 |
xlabel={$n$},
|
|
556 |
x label style={at={(1.05,-0.05)}},
|
|
557 |
%ylabel={time in secs},
|
|
558 |
enlargelimits=false,
|
|
559 |
xtick={0,5,...,30},
|
|
560 |
xmax=33,
|
|
561 |
ymax=1000,
|
|
562 |
ytick={0,100,...,1000},
|
|
563 |
scaled ticks=false,
|
|
564 |
axis lines=left,
|
|
565 |
width=5cm,
|
|
566 |
height=4cm,
|
|
567 |
legend entries={regex3},
|
|
568 |
legend pos=north west,
|
|
569 |
legend cell align=left]
|
|
570 |
\addplot[cyan,mark=*, mark options={fill=white}] table {regex3_size_change.data};
|
|
571 |
\end{axis}
|
|
572 |
\end{tikzpicture}\\
|
|
573 |
\multicolumn{3}{c}{Graphs: size change of 3 randomly generated regexes $w.r.t.$ input string length.}
|
|
574 |
\end{tabular}
|
|
575 |
\end{center}
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
\noindent
|
|
582 |
Most of the regex's sizes seem to stay within a polynomial bound $w.r.t$ the
|
|
583 |
original size.
|
|
584 |
This suggests a link towrads "partial derivatives"
|
|
585 |
introduced by Antimirov \cite{Antimirov95}.
|
|
586 |
|
|
587 |
\section{Antimirov's partial derivatives}
|
|
588 |
The idea behind Antimirov's partial derivatives
|
|
589 |
is to do derivatives in a similar way as suggested by Brzozowski,
|
|
590 |
but maintain a set of regular expressions instead of a single one:
|
|
591 |
|
|
592 |
%TODO: antimirov proposition 3.1, needs completion
|
|
593 |
\begin{center}
|
|
594 |
\begin{tabular}{ccc}
|
|
595 |
$\partial_x(a+b)$ & $=$ & $\partial_x(a) \cup \partial_x(b)$\\
|
|
596 |
$\partial_x(\ONE)$ & $=$ & $\phi$
|
|
597 |
\end{tabular}
|
|
598 |
\end{center}
|
|
599 |
|
|
600 |
Rather than joining the calculated derivatives $\partial_x a$ and $\partial_x b$ together
|
|
601 |
using the alternatives constructor, Antimirov cleverly chose to put them into
|
|
602 |
a set instead. This breaks the terms in a derivative regular expression up,
|
|
603 |
allowing us to understand what are the "atomic" components of it.
|
|
604 |
For example, To compute what regular expression $x^*(xx + y)^*$'s
|
|
605 |
derivative against $x$ is made of, one can do a partial derivative
|
|
606 |
of it and get two singleton sets $\{x^* \cdot (xx + y)^*\}$ and $\{x \cdot (xx + y) ^* \}$
|
|
607 |
from $\partial_x(x^*) \cdot (xx + y) ^*$ and $\partial_x((xx + y)^*)$.
|
|
608 |
To get all the "atomic" components of a regular expression's possible derivatives,
|
|
609 |
there is a procedure Antimirov called $\textit{lf}$, short for "linear forms", that takes
|
|
610 |
whatever character is available at the head of the string inside the language of a
|
|
611 |
regular expression, and gives back the character and the derivative regular expression
|
|
612 |
as a pair (which he called "monomial"):
|
|
613 |
\begin{center}
|
|
614 |
\begin{tabular}{ccc}
|
|
615 |
$\lf(\ONE)$ & $=$ & $\phi$\\
|
|
616 |
$\lf(c)$ & $=$ & $\{(c, \ONE) \}$\\
|
|
617 |
$\lf(a+b)$ & $=$ & $\lf(a) \cup \lf(b)$\\
|
|
618 |
$\lf(r^*)$ & $=$ & $\lf(r) \bigodot \lf(r^*)$\\
|
|
619 |
\end{tabular}
|
|
620 |
\end{center}
|
|
621 |
%TODO: completion
|
|
622 |
|
|
623 |
There is a slight difference in the last three clauses compared
|
|
624 |
with $\partial$: instead of a dot operator $ \textit{rset} \cdot r$ that attaches the regular
|
|
625 |
expression $r$ with every element inside $\textit{rset}$ to create a set of
|
|
626 |
sequence derivatives, it uses the "circle dot" operator $\bigodot$ which operates
|
|
627 |
on a set of monomials (which Antimirov called "linear form") and a regular
|
|
628 |
expression, and returns a linear form:
|
|
629 |
\begin{center}
|
|
630 |
\begin{tabular}{ccc}
|
|
631 |
$l \bigodot (\ZERO)$ & $=$ & $\phi$\\
|
|
632 |
$l \bigodot (\ONE)$ & $=$ & $l$\\
|
|
633 |
$\phi \bigodot t$ & $=$ & $\phi$\\
|
|
634 |
$\{ (x, \ZERO) \} \bigodot t$ & $=$ & $\{(x,\ZERO) \}$\\
|
|
635 |
$\{ (x, \ONE) \} \bigodot t$ & $=$ & $\{(x,t) \}$\\
|
|
636 |
$\{ (x, p) \} \bigodot t$ & $=$ & $\{(x,p\cdot t) \}$\\
|
|
637 |
$\lf(a+b)$ & $=$ & $\lf(a) \cup \lf(b)$\\
|
|
638 |
$\lf(r^*)$ & $=$ & $\lf(r) \cdot \lf(r^*)$\\
|
|
639 |
\end{tabular}
|
|
640 |
\end{center}
|
|
641 |
%TODO: completion
|
|
642 |
|
|
643 |
Some degree of simplification is applied when doing $\bigodot$, for example,
|
|
644 |
$l \bigodot (\ZERO) = \phi$ corresponds to $r \cdot \ZERO \rightsquigarrow \ZERO$,
|
|
645 |
and $l \bigodot (\ONE) = l$ to $l \cdot \ONE \rightsquigarrow l$, and
|
|
646 |
$\{ (x, \ZERO) \} \bigodot t = \{(x,\ZERO) \}$ to $\ZERO \cdot x \rightsquigarrow \ZERO$,
|
|
647 |
and so on.
|
|
648 |
|
|
649 |
With the function $\lf$ one can compute all possible partial derivatives $\partial_{UNIV}(r)$ of a regex $r$ with
|
|
650 |
an iterative procedure:
|
|
651 |
\begin{center}
|
|
652 |
\begin{tabular}{llll}
|
|
653 |
$\textit{while}$ & $(\Delta_i \neq \phi)$ & & \\
|
|
654 |
& $\Delta_{i+1}$ & $ =$ & $\lf(\Delta_i) - \PD_i$ \\
|
|
655 |
& $\PD_{i+1}$ & $ =$ & $\Delta_{i+1} \cup \PD_i$ \\
|
|
656 |
$\partial_{UNIV}(r)$ & $=$ & $\PD$ &
|
|
657 |
\end{tabular}
|
|
658 |
\end{center}
|
|
659 |
|
|
660 |
|
|
661 |
$(r_1 + r_2) \cdot r_3 \longrightarrow (r_1 \cdot r_3) + (r_2 \cdot r_3)$,
|
|
662 |
|
|
663 |
|
|
664 |
However, if we introduce them in our
|
|
665 |
setting we would lose the POSIX property of our calculated values.
|
|
666 |
A simple example for this would be the regex $(a + a\cdot b)\cdot(b\cdot c + c)$.
|
|
667 |
If we split this regex up into $a\cdot(b\cdot c + c) + a\cdot b \cdot (b\cdot c + c)$, the lexer
|
|
668 |
would give back $\Left(\Seq(\Char(a), \Left(\Char(b \cdot c))))$ instead of
|
|
669 |
what we want: $\Seq(\Right(ab), \Right(c))$. Unless we can store the structural information
|
|
670 |
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$
|
|
671 |
occurs, and apply them in the right order once we get
|
|
672 |
a result of the "aggressively simplified" regex, it would be impossible to still get a $\POSIX$ value.
|
|
673 |
This is unlike the simplification we had before, where the rewriting rules
|
|
674 |
such as $\ONE \cdot r \rightsquigarrow r$, under which our lexer will give the same value.
|
|
675 |
We will discuss better
|
|
676 |
bounds in the last section of this chapter.\\[-6.5mm]
|
|
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
|
681 |
%----------------------------------------------------------------------------------------
|
|
682 |
% SECTION ??
|
|
683 |
%----------------------------------------------------------------------------------------
|
|
684 |
|
|
685 |
\section{"Closed Forms" of regular expressions' derivatives w.r.t strings}
|
|
686 |
To embark on getting the "closed forms" of regexes, we first
|
|
687 |
define a few auxiliary definitions to make expressing them smoothly.
|
|
688 |
|
|
689 |
\begin{center}
|
|
690 |
\begin{tabular}{ccc}
|
|
691 |
$\sflataux{\AALTS{ }{r :: rs}}$ & $=$ & $\sflataux{r} @ rs$\\
|
|
692 |
$\sflataux{\AALTS{ }{[]}}$ & $ = $ & $ []$\\
|
|
693 |
$\sflataux r$ & $=$ & $ [r]$
|
|
694 |
\end{tabular}
|
|
695 |
\end{center}
|
|
696 |
The intuition behind $\sflataux{\_}$ is to break up nested regexes
|
|
697 |
of the $(\ldots((r_1 + r_2) + r_3) + \ldots )$(left-associated) shape
|
|
698 |
into a more "balanced" list: $\AALTS{\_}{[r_1,\, r_2 ,\, r_3, \ldots]}$.
|
|
699 |
It will return the singleton list $[r]$ otherwise.
|
|
700 |
|
|
701 |
$\sflat{\_}$ works the same as $\sflataux{\_}$, except that it keeps
|
|
702 |
the output type a regular expression, not a list:
|
|
703 |
\begin{center}
|
|
704 |
\begin{tabular}{ccc}
|
|
705 |
$\sflat{\AALTS{ }{r :: rs}}$ & $=$ & $\sflataux{r} @ rs$\\
|
|
706 |
$\sflat{\AALTS{ }{[]}}$ & $ = $ & $ \AALTS{ }{[]}$\\
|
|
707 |
$\sflat r$ & $=$ & $ [r]$
|
|
708 |
\end{tabular}
|
|
709 |
\end{center}
|
|
710 |
$\sflataux{\_}$ and $\sflat{\_}$ is only recursive in terms of the
|
|
711 |
first element of the list of children of
|
|
712 |
an alternative regex ($\AALTS{ }{rs}$), and is purposefully built for dealing with the regular expression
|
|
713 |
$r_1 \cdot r_2 \backslash s$.
|
|
714 |
|
|
715 |
With $\sflat{\_}$ and $\sflataux{\_}$ we make
|
|
716 |
precise what "closed forms" we have for the sequence derivatives and their simplifications,
|
|
717 |
in other words, how can we construct $(r_1 \cdot r_2) \backslash s$
|
|
718 |
and $\bderssimp{(r_1\cdot r_2)}{s}$,
|
|
719 |
if we are only allowed to use a combination of $r_1 \backslash s'$ ($\bderssimp{r_1}{s'}$)
|
|
720 |
and $r_2 \backslash s'$ ($\bderssimp{r_2}{s'}$), where $s'$ ranges over
|
|
721 |
the substring of $s$?
|
|
722 |
First let's look at a series of derivatives steps on a sequence
|
|
723 |
regular expression, (assuming) that each time the first
|
|
724 |
component of the sequence is always nullable):
|
|
725 |
\begin{center}
|
|
726 |
|
|
727 |
$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$\\
|
|
728 |
$((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
|
|
729 |
\ldots$
|
|
730 |
|
|
731 |
\end{center}
|
|
732 |
%TODO: cite indian paper
|
|
733 |
Indianpaper have come up with a slightly more formal way of putting the above process:
|
|
734 |
\begin{center}
|
|
735 |
$r_1 \cdot r_2 \backslash (c_1 :: c_2 ::\ldots c_n) \myequiv r_1 \backslash (c_1 :: c_2:: \ldots c_n) +
|
|
736 |
\delta(\nullable(r_1 \backslash (c_1 :: c_2 \ldots c_{n-1}) ), r_2 \backslash (c_n)) + \ldots
|
|
737 |
+ \delta (\nullable(r_1), r_2\backslash (c_1 :: c_2 ::\ldots c_n))$
|
|
738 |
\end{center}
|
|
739 |
where $\delta(b, r)$ will produce $r$
|
|
740 |
if $b$ evaluates to true,
|
|
741 |
and $\ZERO$ otherwise.
|
|
742 |
|
|
743 |
But the $\myequiv$ sign in the above equation means language equivalence instead of syntactical
|
|
744 |
equivalence. To make this intuition useful
|
|
745 |
for a formal proof, we need something
|
|
746 |
stronger than language equivalence.
|
|
747 |
With the help of $\sflat{\_}$ we can state the equation in Indianpaper
|
|
748 |
more rigorously:
|
|
749 |
\begin{lemma}
|
|
750 |
$\sflat{(r_1 \cdot r_2) \backslash s} = \RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}$
|
|
751 |
\end{lemma}
|
|
752 |
|
|
753 |
The function $\vsuf{\_}{\_}$ is defined recursively on the structure of the string:
|
|
754 |
|
|
755 |
\begin{center}
|
|
756 |
\begin{tabular}{lcl}
|
|
757 |
$\vsuf{[]}{\_} $ & $=$ & $[]$\\
|
|
758 |
$\vsuf{c::cs}{r_1}$ & $ =$ & $ \textit{if} (\rnullable{r_1}) \textit{then} \; (\vsuf{cs}{(\rder{c}{r_1})}) @ [c :: cs]$\\
|
|
759 |
&& $\textit{else} \; (\vsuf{cs}{(\rder{c}{r_1}) }) $
|
|
760 |
\end{tabular}
|
|
761 |
\end{center}
|
|
762 |
It takes into account which prefixes $s'$ of $s$ would make $r \backslash s'$ nullable,
|
|
763 |
and keep a list of suffixes $s''$ such that $s' @ s'' = s$. The list is sorted in
|
|
764 |
the order $r_2\backslash s''$ appears in $(r_1\cdot r_2)\backslash s$.
|
|
765 |
In essence, $\vsuf{\_}{\_}$ is doing a "virtual derivative" of $r_1 \cdot r_2$, but instead of producing
|
|
766 |
the entire result of $(r_1 \cdot r_2) \backslash s$,
|
|
767 |
it only stores all the $s''$ such that $r_2 \backslash s''$ are occurring terms in $(r_1\cdot r_2)\backslash s$.
|
|
768 |
|
|
769 |
With this we can also add simplifications to both sides and get
|
|
770 |
\begin{lemma}
|
|
771 |
$\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}))}}$
|
|
772 |
\end{lemma}
|
|
773 |
Together with the idempotency property of $\rsimp$,
|
|
774 |
%TODO: state the idempotency property of rsimp
|
|
775 |
\begin{lemma}
|
|
776 |
$\rsimp{r} = \rsimp{\rsimp{r}}$
|
|
777 |
\end{lemma}
|
|
778 |
it is possible to convert the above lemma to obtain a "closed form"
|
|
779 |
for derivatives nested with simplification:
|
|
780 |
\begin{lemma}
|
|
781 |
$\rderssimp{(r_1 \cdot r_2)}{s} = \rsimp{\AALTS{[[]}{ (r_1 \backslash s) \cdot r_2 :: (\map (r_2 \backslash \_) (\vsuf{s}{r_1}))}}$
|
|
782 |
\end{lemma}
|
|
783 |
And now the reason we have (1) in section 1 is clear:
|
|
784 |
$\rsize{\rsimp{\RALTS{ (r_1 \backslash s) \cdot r_2 :: (\map \;(r_2 \backslash \_) \; (\vsuf{s}{r_1}))}}}$,
|
|
785 |
is equal to $\rsize{\rsimp{\RALTS{ ((r_1 \backslash s) \cdot r_2 :: (\map \; (r_2 \backslash \_) \; (\textit{Suffix}(r1, s))))}}}$
|
|
786 |
as $\vsuf{s}{r_1}$ is one way of expressing the list $\textit{Suffix}( r_1, s)$.
|
|
787 |
|
|
788 |
%----------------------------------------------------------------------------------------
|
|
789 |
% SECTION 3
|
|
790 |
%----------------------------------------------------------------------------------------
|
|
791 |
|
|
792 |
\section{interaction between $\distinctWith$ and $\flts$}
|
|
793 |
Note that it is not immediately obvious that
|
|
794 |
\begin{center}
|
|
795 |
$\llbracket \distinctWith (\flts \textit{rs}) = \phi \rrbracket \leq \llbracket \distinctWith \textit{rs} = \phi \rrbracket $.
|
|
796 |
\end{center}
|
|
797 |
The intuition is that if we remove duplicates from the $\textit{LHS}$, at least the same amount of
|
|
798 |
duplicates will be removed from the list $\textit{rs}$ in the $\textit{RHS}$.
|
|
799 |
|
|
800 |
|
|
801 |
%-----------------------------------
|
|
802 |
% SECTION syntactic equivalence under simp
|
|
803 |
%-----------------------------------
|
|
804 |
\section{Syntactic Equivalence Under $\simp$}
|
|
805 |
We prove that minor differences can be annhilated
|
|
806 |
by $\simp$.
|
|
807 |
For example,
|
|
808 |
\begin{center}
|
|
809 |
$\simp \;(\simpALTs\; (\map \;(\_\backslash \; x)\; (\distinct \; \mathit{rs}\; \phi))) =
|
|
810 |
\simp \;(\simpALTs \;(\distinct \;(\map \;(\_ \backslash\; x) \; \mathit{rs}) \; \phi))$
|
|
811 |
\end{center}
|
|
812 |
|
|
813 |
|
|
814 |
%----------------------------------------------------------------------------------------
|
|
815 |
% SECTION ALTS CLOSED FORM
|
|
816 |
%----------------------------------------------------------------------------------------
|
|
817 |
\section{A Closed Form for \textit{ALTS}}
|
|
818 |
Now we prove that $rsimp (rders\_simp (RALTS rs) s) = rsimp (RALTS (map (\lambda r. rders\_simp r s) rs))$.
|
|
819 |
|
|
820 |
|
|
821 |
There are a few key steps, one of these steps is
|
|
822 |
\[
|
|
823 |
rsimp (rsimp\_ALTs (map (rder x) (rdistinct (rflts (map (rsimp \circ (\lambda r. rders\_simp r xs)) rs)) {})))
|
|
824 |
= rsimp (rsimp\_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \circ (\lambda r. rders\_simp r xs)) rs))) {}))
|
|
825 |
\]
|
|
826 |
|
|
827 |
|
|
828 |
One might want to prove this by something a simple statement like:
|
|
829 |
$map (rder x) (rdistinct rs rset) = rdistinct (map (rder x) rs) (rder x) ` rset)$.
|
|
830 |
|
|
831 |
For this to hold we want the $\textit{distinct}$ function to pick up
|
|
832 |
the elements before and after derivatives correctly:
|
|
833 |
$r \in rset \equiv (rder x r) \in (rder x rset)$.
|
|
834 |
which essentially requires that the function $\backslash$ is an injective mapping.
|
|
835 |
|
|
836 |
Unfortunately the function $\backslash c$ is not an injective mapping.
|
|
837 |
|
|
838 |
\subsection{function $\backslash c$ is not injective (1-to-1)}
|
|
839 |
\begin{center}
|
|
840 |
The derivative $w.r.t$ character $c$ is not one-to-one.
|
|
841 |
Formally,
|
|
842 |
$\exists r_1 \;r_2. r_1 \neq r_2 \mathit{and} r_1 \backslash c = r_2 \backslash c$
|
|
843 |
\end{center}
|
|
844 |
This property is trivially true for the
|
|
845 |
character regex example:
|
|
846 |
\begin{center}
|
|
847 |
$r_1 = e; \; r_2 = d;\; r_1 \backslash c = \ZERO = r_2 \backslash c$
|
|
848 |
\end{center}
|
|
849 |
But apart from the cases where the derivative
|
|
850 |
output is $\ZERO$, are there non-trivial results
|
|
851 |
of derivatives which contain strings?
|
|
852 |
The answer is yes.
|
|
853 |
For example,
|
|
854 |
\begin{center}
|
|
855 |
Let $r_1 = a^*b\;\quad r_2 = (a\cdot a^*)\cdot b + b$.\\
|
|
856 |
where $a$ is not nullable.\\
|
|
857 |
$r_1 \backslash c = ((a \backslash c)\cdot a^*)\cdot c + b \backslash c$\\
|
|
858 |
$r_2 \backslash c = ((a \backslash c)\cdot a^*)\cdot c + b \backslash c$
|
|
859 |
\end{center}
|
|
860 |
We start with two syntactically different regexes,
|
|
861 |
and end up with the same derivative result.
|
|
862 |
This is not surprising as we have such
|
|
863 |
equality as below in the style of Arden's lemma:\\
|
|
864 |
\begin{center}
|
|
865 |
$L(A^*B) = L(A\cdot A^* \cdot B + B)$
|
|
866 |
\end{center}
|
|
867 |
|
|
868 |
%----------------------------------------------------------------------------------------
|
|
869 |
% SECTION 4
|
|
870 |
%----------------------------------------------------------------------------------------
|
|
871 |
\section{A Bound for the Star Regular Expression}
|
|
872 |
We have shown how to control the size of the sequence regular expression $r_1\cdot r_2$ using
|
|
873 |
the "closed form" of $(r_1 \cdot r_2) \backslash s$ and then
|
|
874 |
the property of the $\distinct$ function.
|
|
875 |
Now we try to get a bound on $r^* \backslash s$ as well.
|
|
876 |
Again, we first look at how a star's derivatives evolve, if they grow maximally:
|
|
877 |
\begin{center}
|
|
878 |
|
|
879 |
$r^* \quad \longrightarrow_{\backslash c} \quad (r\backslash c) \cdot r^* \quad \longrightarrow_{\backslash c'} \quad
|
|
880 |
r \backslash cc' \cdot r^* + r \backslash c' \cdot r^* \quad \longrightarrow_{\backslash c''} \quad
|
|
881 |
(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'''}
|
|
882 |
\quad \ldots$
|
|
883 |
|
|
884 |
\end{center}
|
|
885 |
When we have a string $s = c :: c' :: c'' \ldots$ such that $r \backslash c$, $r \backslash cc'$, $r \backslash c'$,
|
|
886 |
$r \backslash cc'c''$, $r \backslash c'c''$, $r\backslash c''$ etc. are all nullable,
|
|
887 |
the number of terms in $r^* \backslash s$ will grow exponentially, causing the size
|
|
888 |
of the derivatives $r^* \backslash s$ to grow exponentially, even if we do not
|
|
889 |
count the possible size explosions of $r \backslash c$ themselves.
|
|
890 |
|
|
891 |
Thanks to $\flts$ and $\distinctWith$, we are able to open up regexes like
|
|
892 |
$(r_1 \backslash cc'c'' \cdot r^* + r \backslash c'') + (r \backslash c'c'' \cdot r^* + r \backslash c'' \cdot r^*) $
|
|
893 |
into $\RALTS{[r_1 \backslash cc'c'' \cdot r^*, r \backslash c'', r \backslash c'c'' \cdot r^*, r \backslash c'' \cdot r^*]}$
|
|
894 |
and then de-duplicate terms of the form $r\backslash s' \cdot r^*$ ($s'$ being a substring of $s$).
|
|
895 |
For this we define $\hflataux{\_}$ and $\hflat{\_}$, similar to $\sflataux{\_}$ and $\sflat{\_}$:
|
|
896 |
%TODO: definitions of and \hflataux \hflat
|
|
897 |
\begin{center}
|
|
898 |
\begin{tabular}{ccc}
|
|
899 |
$\hflataux{r_1 + r_2}$ & $=$ & $\hflataux{r_1} @ \hflataux{r_2}$\\
|
|
900 |
$\hflataux r$ & $=$ & $ [r]$
|
|
901 |
\end{tabular}
|
|
902 |
\end{center}
|
|
903 |
|
|
904 |
\begin{center}
|
|
905 |
\begin{tabular}{ccc}
|
|
906 |
$\hflat{r_1 + r_2}$ & $=$ & $\RALTS{\hflataux{r_1} @ \hflataux{r_2}}$\\
|
|
907 |
$\hflat r$ & $=$ & $ r$
|
|
908 |
\end{tabular}
|
|
909 |
\end{center}s
|
|
910 |
Again these definitions are tailor-made for dealing with alternatives that have
|
|
911 |
originated from a star's derivatives, so we don't attempt to open up all possible
|
|
912 |
regexes of the form $\RALTS{rs}$, where $\textit{rs}$ might not contain precisely 2
|
|
913 |
elements.
|
|
914 |
We give a predicate for such "star-created" regular expressions:
|
|
915 |
\begin{center}
|
|
916 |
\begin{tabular}{lcr}
|
|
917 |
& & $\createdByStar{(\RSEQ{ra}{\RSTAR{rb}}) }$\\
|
|
918 |
$\createdByStar{r_1} \land \createdByStar{r_2} $ & $ \Longrightarrow$ & $\createdByStar{(r_1 + r_2)}$
|
|
919 |
\end{tabular}
|
|
920 |
\end{center}
|
|
921 |
|
|
922 |
These definitions allows us the flexibility to talk about
|
|
923 |
regular expressions in their most convenient format,
|
|
924 |
for example, flattened out $\RALTS{[r_1, r_2, \ldots, r_n]} $
|
|
925 |
instead of binary-nested: $((r_1 + r_2) + (r_3 + r_4)) + \ldots$.
|
|
926 |
These definitions help express that certain classes of syntatically
|
|
927 |
distinct regular expressions are actually the same under simplification.
|
|
928 |
This is not entirely true for annotated regular expressions:
|
|
929 |
%TODO: bsimp bders \neq bderssimp
|
|
930 |
\begin{center}
|
|
931 |
$(1+ (c\cdot \ASEQ{bs}{c^*}{c} ))$
|
|
932 |
\end{center}
|
|
933 |
For bit-codes, the order in which simplification is applied
|
|
934 |
might cause a difference in the location they are placed.
|
|
935 |
If we want something like
|
|
936 |
\begin{center}
|
|
937 |
$\bderssimp{r}{s} \myequiv \bsimp{\bders{r}{s}}$
|
|
938 |
\end{center}
|
|
939 |
Some "canonicalization" procedure is required,
|
|
940 |
which either pushes all the common bitcodes to nodes
|
|
941 |
as senior as possible:
|
|
942 |
\begin{center}
|
|
943 |
$_{bs}(_{bs_1 @ bs'}r_1 + _{bs_1 @ bs''}r_2) \rightarrow _{bs @ bs_1}(_{bs'}r_1 + _{bs''}r_2) $
|
|
944 |
\end{center}
|
|
945 |
or does the reverse. However bitcodes are not of interest if we are talking about
|
|
946 |
the $\llbracket r \rrbracket$ size of a regex.
|
|
947 |
Therefore for the ease and simplicity of producing a
|
|
948 |
proof for a size bound, we are happy to restrict ourselves to
|
|
949 |
unannotated regular expressions, and obtain such equalities as
|
|
950 |
\begin{lemma}
|
|
951 |
$\rsimp{r_1 + r_2} = \rsimp{\RALTS{\hflataux{r_1} @ \hflataux{r_2}}}$
|
|
952 |
\end{lemma}
|
|
953 |
|
|
954 |
\begin{proof}
|
|
955 |
By using the rewriting relation $\rightsquigarrow$
|
|
956 |
\end{proof}
|
|
957 |
%TODO: rsimp sflat
|
|
958 |
And from this we obtain a proof that a star's derivative will be the same
|
|
959 |
as if it had all its nested alternatives created during deriving being flattened out:
|
|
960 |
For example,
|
|
961 |
\begin{lemma}
|
|
962 |
$\createdByStar{r} \implies \rsimp{r} = \rsimp{\RALTS{\hflataux{r}}}$
|
|
963 |
\end{lemma}
|
|
964 |
\begin{proof}
|
|
965 |
By structural induction on $r$, where the induction rules are these of $\createdByStar{_}$.
|
|
966 |
\end{proof}
|
|
967 |
% The simplification of a flattened out regular expression, provided it comes
|
|
968 |
%from the derivative of a star, is the same as the one nested.
|
|
969 |
|
|
970 |
|
|
971 |
|
|
972 |
|
|
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
|
|
978 |
One might wonder the actual bound rather than the loose bound we gave
|
|
979 |
for the convenience of an easier proof.
|
|
980 |
How much can the regex $r^* \backslash s$ grow?
|
|
981 |
As earlier graphs have shown,
|
|
982 |
%TODO: reference that graph where size grows quickly
|
|
983 |
they can grow at a maximum speed
|
|
984 |
exponential $w.r.t$ the number of characters,
|
|
985 |
but will eventually level off when the string $s$ is long enough.
|
|
986 |
If they grow to a size exponential $w.r.t$ the original regex, our algorithm
|
|
987 |
would still be slow.
|
|
988 |
And unfortunately, we have concrete examples
|
|
989 |
where such regexes grew exponentially large before levelling off:
|
|
990 |
$(a ^ * + (aa) ^ * + (aaa) ^ * + \ldots +
|
|
991 |
(\underbrace{a \ldots a}_{\text{n a's}})^*$ will already have a maximum
|
|
992 |
size that is exponential on the number $n$
|
|
993 |
under our current simplification rules:
|
|
994 |
%TODO: graph of a regex whose size increases exponentially.
|
|
995 |
\begin{center}
|
|
996 |
\begin{tikzpicture}
|
|
997 |
\begin{axis}[
|
|
998 |
height=0.5\textwidth,
|
|
999 |
width=\textwidth,
|
|
1000 |
xlabel=number of a's,
|
|
1001 |
xtick={0,...,9},
|
|
1002 |
ylabel=maximum size,
|
|
1003 |
ymode=log,
|
|
1004 |
log basis y={2}
|
|
1005 |
]
|
|
1006 |
\addplot[mark=*,blue] table {re-chengsong.data};
|
|
1007 |
\end{axis}
|
|
1008 |
\end{tikzpicture}
|
|
1009 |
\end{center}
|
|
1010 |
|
|
1011 |
For convenience we use $(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$
|
|
1012 |
to express $(a ^ * + (aa) ^ * + (aaa) ^ * + \ldots +
|
|
1013 |
(\underbrace{a \ldots a}_{\text{n a's}})^*$ in the below discussion.
|
|
1014 |
The exponential size is triggered by that the regex
|
|
1015 |
$\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*$
|
|
1016 |
inside the $(\ldots) ^*$ having exponentially many
|
|
1017 |
different derivatives, despite those difference being minor.
|
|
1018 |
$(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*\backslash \underbrace{a \ldots a}_{\text{m a's}}$
|
|
1019 |
will therefore contain the following terms (after flattening out all nested
|
|
1020 |
alternatives):
|
|
1021 |
\begin{center}
|
|
1022 |
$(\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}})^*)$\\
|
|
1023 |
$(1 \leq m' \leq m )$
|
|
1024 |
\end{center}
|
|
1025 |
These terms are distinct for $m' \leq L.C.M.(1, \ldots, n)$ (will be explained in appendix).
|
|
1026 |
With each new input character taking the derivative against the intermediate result, more and more such distinct
|
|
1027 |
terms will accumulate,
|
|
1028 |
until the length reaches $L.C.M.(1, \ldots, n)$.
|
|
1029 |
$\textit{distinctBy}$ will not be able to de-duplicate any two of these terms
|
|
1030 |
$(\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}})^*)^*$\\
|
|
1031 |
|
|
1032 |
$(\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}})^*)^*$\\
|
|
1033 |
where $m' \neq m''$ \\
|
|
1034 |
as they are slightly different.
|
|
1035 |
This means that with our current simplification methods,
|
|
1036 |
we will not be able to control the derivative so that
|
|
1037 |
$\llbracket \bderssimp{r}{s} \rrbracket$ stays polynomial %\leq O((\llbracket r\rrbacket)^c)$
|
|
1038 |
as there are already exponentially many terms.
|
|
1039 |
These terms are similar in the sense that the head of those terms
|
|
1040 |
are all consisted of sub-terms of the form:
|
|
1041 |
$(\underbrace{a \ldots a}_{\text{j a's}})\cdot (\underbrace{a \ldots a}_{\text{i a's}})^* $.
|
|
1042 |
For $\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*$, there will be at most
|
|
1043 |
$n * (n + 1) / 2$ such terms.
|
|
1044 |
For example, $(a^* + (aa)^* + (aaa)^*) ^*$'s derivatives
|
|
1045 |
can be described by 6 terms:
|
|
1046 |
$a^*$, $a\cdot (aa)^*$, $ (aa)^*$,
|
|
1047 |
$aa \cdot (aaa)^*$, $a \cdot (aaa)^*$, and $(aaa)^*$.
|
|
1048 |
The total number of different "head terms", $n * (n + 1) / 2$,
|
|
1049 |
is proportional to the number of characters in the regex
|
|
1050 |
$(\oplus_{i=1}^{n} (\underbrace{a \ldots a}_{\text{i a's}})^*)^*$.
|
|
1051 |
This suggests a slightly different notion of size, which we call the
|
|
1052 |
alphabetic width:
|
|
1053 |
%TODO:
|
|
1054 |
(TODO: Alphabetic width def.)
|
|
1055 |
|
|
1056 |
|
|
1057 |
Antimirov\parencite{Antimirov95} has proven that
|
|
1058 |
$\textit{PDER}_{UNIV}(r) \leq \textit{awidth}(r)$.
|
|
1059 |
where $\textit{PDER}_{UNIV}(r)$ is a set of all possible subterms
|
|
1060 |
created by doing derivatives of $r$ against all possible strings.
|
|
1061 |
If we can make sure that at any moment in our lexing algorithm our
|
|
1062 |
intermediate result hold at most one copy of each of the
|
|
1063 |
subterms then we can get the same bound as Antimirov's.
|
|
1064 |
This leads to the algorithm in the next chapter.
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
|
1068 |
|
|
1069 |
|
|
1070 |
%----------------------------------------------------------------------------------------
|
|
1071 |
% SECTION 1
|
|
1072 |
%----------------------------------------------------------------------------------------
|
|
1073 |
|
|
1074 |
\section{Idempotency of $\simp$}
|
|
1075 |
|
|
1076 |
\begin{equation}
|
|
1077 |
\simp \;r = \simp\; \simp \; r
|
|
1078 |
\end{equation}
|
|
1079 |
This property means we do not have to repeatedly
|
|
1080 |
apply simplification in each step, which justifies
|
|
1081 |
our definition of $\blexersimp$.
|
|
1082 |
It will also be useful in future proofs where properties such as
|
|
1083 |
closed forms are needed.
|
|
1084 |
The proof is by structural induction on $r$.
|
|
1085 |
|
|
1086 |
%-----------------------------------
|
|
1087 |
% SUBSECTION 1
|
|
1088 |
%-----------------------------------
|
|
1089 |
\subsection{Syntactic Equivalence Under $\simp$}
|
|
1090 |
We prove that minor differences can be annhilated
|
|
1091 |
by $\simp$.
|
|
1092 |
For example,
|
|
1093 |
\begin{center}
|
|
1094 |
$\simp \;(\simpALTs\; (\map \;(\_\backslash \; x)\; (\distinct \; \mathit{rs}\; \phi))) =
|
|
1095 |
\simp \;(\simpALTs \;(\distinct \;(\map \;(\_ \backslash\; x) \; \mathit{rs}) \; \phi))$
|
|
1096 |
\end{center}
|
|
1097 |
|