etnms/etnms.tex
author Chengsong
Fri, 10 Apr 2020 11:58:11 +0100
changeset 148 c8ef391dd6f7
parent 145 a7c063981fa5
permissions -rw-r--r--
vunsimp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
Chengsong
parents:
diff changeset
     1
\documentclass[a4paper,UKenglish]{lipics}
Chengsong
parents:
diff changeset
     2
\usepackage{graphic}
Chengsong
parents:
diff changeset
     3
\usepackage{data}
Chengsong
parents:
diff changeset
     4
\usepackage{tikz-cd}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
     5
\usepackage{tikz}
138
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
     6
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
     7
%\usetikzlibrary{graphs}
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
     8
%\usetikzlibrary{graphdrawing}
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
     9
%\usegdlibrary{trees}
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
    10
94
Chengsong
parents:
diff changeset
    11
%\usepackage{algorithm}
Chengsong
parents:
diff changeset
    12
\usepackage{amsmath}
110
Chengsong
parents: 109
diff changeset
    13
\usepackage{xcolor}
94
Chengsong
parents:
diff changeset
    14
\usepackage[noend]{algpseudocode}
Chengsong
parents:
diff changeset
    15
\usepackage{enumitem}
Chengsong
parents:
diff changeset
    16
\usepackage{nccmath}
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
    17
\usepackage{soul}
94
Chengsong
parents:
diff changeset
    18
Chengsong
parents:
diff changeset
    19
\definecolor{darkblue}{rgb}{0,0,0.6}
Chengsong
parents:
diff changeset
    20
\hypersetup{colorlinks=true,allcolors=darkblue}
Chengsong
parents:
diff changeset
    21
\newcommand{\comment}[1]%
Chengsong
parents:
diff changeset
    22
{{\color{red}$\Rightarrow$}\marginpar{\raggedright\small{\bf\color{red}#1}}}
Chengsong
parents:
diff changeset
    23
Chengsong
parents:
diff changeset
    24
% \documentclass{article}
Chengsong
parents:
diff changeset
    25
%\usepackage[utf8]{inputenc}
Chengsong
parents:
diff changeset
    26
%\usepackage[english]{babel}
Chengsong
parents:
diff changeset
    27
%\usepackage{listings}
Chengsong
parents:
diff changeset
    28
% \usepackage{amsthm}
Chengsong
parents:
diff changeset
    29
%\usepackage{hyperref}
Chengsong
parents:
diff changeset
    30
% \usepackage[margin=0.5in]{geometry}
Chengsong
parents:
diff changeset
    31
%\usepackage{pmboxdraw}
Chengsong
parents:
diff changeset
    32
 
Chengsong
parents:
diff changeset
    33
\title{POSIX Regular Expression Matching and Lexing}
Chengsong
parents:
diff changeset
    34
\author{Chengsong Tan}
Chengsong
parents:
diff changeset
    35
\affil{King's College London\\
Chengsong
parents:
diff changeset
    36
London, UK\\
Chengsong
parents:
diff changeset
    37
\texttt{chengsong.tan@kcl.ac.uk}}
Chengsong
parents:
diff changeset
    38
\authorrunning{Chengsong Tan}
Chengsong
parents:
diff changeset
    39
\Copyright{Chengsong Tan}
Chengsong
parents:
diff changeset
    40
Chengsong
parents:
diff changeset
    41
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}%
Chengsong
parents:
diff changeset
    42
\newcommand{\ZERO}{\mbox{\bf 0}}
Chengsong
parents:
diff changeset
    43
\newcommand{\ONE}{\mbox{\bf 1}}
101
Chengsong
parents: 100
diff changeset
    44
\def\erase{\textit{erase}}
94
Chengsong
parents:
diff changeset
    45
\def\bders{\textit{bders}}
Chengsong
parents:
diff changeset
    46
\def\lexer{\mathit{lexer}}
Chengsong
parents:
diff changeset
    47
\def\blexer{\textit{blexer}}
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
    48
\def\fuse{\textit{fuse}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
    49
\def\flatten{\textit{flatten}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
    50
\def\map{\textit{map}}
94
Chengsong
parents:
diff changeset
    51
\def\blexers{\mathit{blexer\_simp}}
95
Chengsong
parents: 94
diff changeset
    52
\def\simp{\mathit{simp}}
94
Chengsong
parents:
diff changeset
    53
\def\mkeps{\mathit{mkeps}}
Chengsong
parents:
diff changeset
    54
\def\bmkeps{\textit{bmkeps}}
Chengsong
parents:
diff changeset
    55
\def\inj{\mathit{inj}}
Chengsong
parents:
diff changeset
    56
\def\Empty{\mathit{Empty}}
Chengsong
parents:
diff changeset
    57
\def\Left{\mathit{Left}}
Chengsong
parents:
diff changeset
    58
\def\Right{\mathit{Right}}
Chengsong
parents:
diff changeset
    59
\def\Stars{\mathit{Stars}}
Chengsong
parents:
diff changeset
    60
\def\Char{\mathit{Char}}
Chengsong
parents:
diff changeset
    61
\def\Seq{\mathit{Seq}}
Chengsong
parents:
diff changeset
    62
\def\Der{\mathit{Der}}
Chengsong
parents:
diff changeset
    63
\def\nullable{\mathit{nullable}}
Chengsong
parents:
diff changeset
    64
\def\Z{\mathit{Z}}
Chengsong
parents:
diff changeset
    65
\def\S{\mathit{S}}
Chengsong
parents:
diff changeset
    66
\def\flex{\textit{flex}}
Chengsong
parents:
diff changeset
    67
\def\rup{r^\uparrow}
Chengsong
parents:
diff changeset
    68
\def\retrieve{\textit{retrieve}}
Chengsong
parents:
diff changeset
    69
\def\AALTS{\textit{AALTS}}
Chengsong
parents:
diff changeset
    70
\def\AONE{\textit{AONE}}
Chengsong
parents:
diff changeset
    71
%\theoremstyle{theorem}
Chengsong
parents:
diff changeset
    72
%\newtheorem{theorem}{Theorem}
Chengsong
parents:
diff changeset
    73
%\theoremstyle{lemma}
Chengsong
parents:
diff changeset
    74
%\newtheorem{lemma}{Lemma}
Chengsong
parents:
diff changeset
    75
%\newcommand{\lemmaautorefname}{Lemma}
Chengsong
parents:
diff changeset
    76
%\theoremstyle{definition}
Chengsong
parents:
diff changeset
    77
%\newtheorem{definition}{Definition}
Chengsong
parents:
diff changeset
    78
\algnewcommand\algorithmicswitch{\textbf{switch}}
Chengsong
parents:
diff changeset
    79
\algnewcommand\algorithmiccase{\textbf{case}}
Chengsong
parents:
diff changeset
    80
\algnewcommand\algorithmicassert{\texttt{assert}}
Chengsong
parents:
diff changeset
    81
\algnewcommand\Assert[1]{\State \algorithmicassert(#1)}%
Chengsong
parents:
diff changeset
    82
% New "environments"
Chengsong
parents:
diff changeset
    83
\algdef{SE}[SWITCH]{Switch}{EndSwitch}[1]{\algorithmicswitch\ #1\ \algorithmicdo}{\algorithmicend\ \algorithmicswitch}%
Chengsong
parents:
diff changeset
    84
\algdef{SE}[CASE]{Case}{EndCase}[1]{\algorithmiccase\ #1}{\algorithmicend\ \algorithmiccase}%
Chengsong
parents:
diff changeset
    85
\algtext*{EndSwitch}%
Chengsong
parents:
diff changeset
    86
\algtext*{EndCase}%
Chengsong
parents:
diff changeset
    87
Chengsong
parents:
diff changeset
    88
Chengsong
parents:
diff changeset
    89
\begin{document}
Chengsong
parents:
diff changeset
    90
Chengsong
parents:
diff changeset
    91
\maketitle
Chengsong
parents:
diff changeset
    92
Chengsong
parents:
diff changeset
    93
\begin{abstract}
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    94
Regular expressions, a useful concept in computer science
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    95
that was initially designed to match string patterns,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    96
need fast matching algorithms.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    97
If we do matching by naively converting
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    98
the regular expression to a
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
    99
Nondeterministic-Finite-Automaton(NFA) and simulating it,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   100
they can run into trouble on certain evil regular expression and string 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   101
pairs.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   102
This necessitates the introudction of a 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   103
method called derivatives of regular expressions\cite{Brzozowski1964}.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   104
With some variation introduced by Sulzmann and Lu\cite{Sulzmann2014},
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   105
it circumvents the problem of 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   106
catastrphoic backtracking elegantly when
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   107
compared to backtracking NFA regex engines.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   108
We believe that such a method can help to address 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   109
the status-quo where badly written code for 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   110
regular expression matching can cause a software grief.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   111
We have come up with a set of simplification rules
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   112
that makes the space and time requirements below a tight bound.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   113
We have proved certain properties of the algorithm 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   114
and simplification.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   115
We have not yet worked out a proof for the correctness
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   116
although test data suggested this.
94
Chengsong
parents:
diff changeset
   117
\end{abstract}
Chengsong
parents:
diff changeset
   118
126
1260b383ae2c forfear
Chengsong
parents: 125
diff changeset
   119
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   120
126
1260b383ae2c forfear
Chengsong
parents: 125
diff changeset
   121
\section{Introduction}
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   122
The following brief introduction gives the background for 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   123
derivatives--how they are originally defined and the 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   124
variety\cite{Sulzmann2014} that is more suitable for lexing.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   125
Regular expressions can be formalized as follows:\\
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   126
\begin{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   127
	$r ::= \ZERO | \ONE | c | r_1 +r_2 | r_1 \cdot r_2 | r^*$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   128
\end{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   129
Derivatives of regular expression can be 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   130
seen as the regular expression that corresponds to
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   131
the language derived by computing
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   132
the left quotient of the original regular language
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   133
w.r.t a character.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   134
Derivative of regular expression is also a 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   135
regular expression because 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   136
the left quotient of a regular language is also regular.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   137
With this we know such a function exist without having
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   138
to worry that it might not be defined.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   139
In fact, regular expressions derivatives
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   140
are not just defined but also simple and elegant.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   141
They are composed of two recursive functions,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   142
and can be easily explained by intuition.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   143
The function
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   144
$\nullable$ defined below,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   145
tests whether the empty string belongs
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   146
to the regular expression being checked.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   147
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   148
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   149
		\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   150
			$\nullable(\ZERO)$     & $\dn$ & $\mathit{false}$ \\  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   151
			$\nullable(\ONE)$      & $\dn$ & $\mathit{true}$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   152
			$\nullable(c)$ 	       & $\dn$ & $\mathit{false}$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   153
			$\nullable(r_1 + r_2)$ & $\dn$ & $\nullable(r_1) \vee \nullable(r_2)$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   154
			$\nullable(r_1\cdot r_2)$  & $\dn$ & $\nullable(r_1) \wedge \nullable(r_2)$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   155
			$\nullable(r^*)$       & $\dn$ & $\mathit{true}$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   156
		\end{tabular}
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   157
\end{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   158
\noindent
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   159
The empty set does not contain any string and
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   160
therefore not the empty string, the empty string 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   161
regular expression contains the empty string
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   162
by definition, the character regular expression
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   163
is the singleton that contains character only,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   164
and therefore does not contain the empty string,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   165
the alternative regular expression(or "or" expression)
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   166
might have one of its children regular expressions
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   167
being nullable and any one of its children being nullable
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   168
would suffice. The sequence regular expression
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   169
would require both children to have the empty string
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   170
to compose an empty string and the Kleene star
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   171
operation naturally introduced the empty string.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   172
All nice and easy.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   173
This definition is used in the derivative operation
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   174
as a condition:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   175
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   176
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   177
\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   178
		$\ZERO \backslash c$ & $\dn$ & $\ZERO$\\  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   179
		$\ONE \backslash c$  & $\dn$ & $\ZERO$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   180
		$d \backslash c$     & $\dn$ & 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   181
		$\mathit{if} \;c = d\;\mathit{then}\;\ONE\;\mathit{else}\;\ZERO$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   182
$(r_1 + r_2)\backslash c$     & $\dn$ & $r_1 \backslash c \,+\, r_2 \backslash c$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   183
$(r_1 \cdot r_2)\backslash c$ & $\dn$ & $\mathit{if} \, nullable(r_1)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   184
	&   & $\mathit{then}\;(r_1\backslash c) \cdot r_2 \,+\, r_2\backslash c$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   185
	&   & $\mathit{else}\;(r_1\backslash c) \cdot r_2$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   186
	$(r^*)\backslash c$           & $\dn$ & $(r\backslash c) \cdot r^*$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   187
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   188
\end{center}
130
Chengsong
parents: 129
diff changeset
   189
\noindent
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   190
\noindent
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   191
The function derivative, written $\backslash c$, 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   192
defines how a regular expression evolves into
130
Chengsong
parents: 129
diff changeset
   193
a new regular expression after all the string it contains
Chengsong
parents: 129
diff changeset
   194
is chopped off a certain head character $c$.
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   195
The most involved cases are the sequence 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   196
and star case.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   197
The sequence case says that if the first regular expression
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   198
contains an empty string then second component of the sequence
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   199
might be chosen as the target regular expression to be chopped
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   200
off its head character.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   201
The star regular expression unwraps the iteration of
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   202
regular expression and attack the star regular expression
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   203
to its back again to make sure there are 0 or more iterations
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   204
following this unfolded iteration.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   205
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   206
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   207
The main property of the derivative operation
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   208
that enables us to reason about the correctness of
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   209
an algorithm using derivatives is 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   210
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   211
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   212
$c\!::\!s \in L(r)$ holds
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   213
if and only if $s \in L(r\backslash c)$.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   214
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   215
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   216
\noindent
108
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   217
We can generalise the derivative operation shown above for single characters
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   218
to strings as follows:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   219
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   220
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   221
\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   222
$r \backslash (c\!::\!s) $ & $\dn$ & $(r \backslash c) \backslash s$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   223
$r \backslash [\,] $ & $\dn$ & $r$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   224
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   225
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   226
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   227
\noindent
108
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   228
and then define Brzozowski's  regular-expression matching algorithm as:
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   229
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   230
\[
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   231
match\;s\;r \;\dn\; nullable(r\backslash s)
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   232
\]
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   233
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   234
\noindent
130
Chengsong
parents: 129
diff changeset
   235
Assuming the a string is given as a sequence of characters, say $c_0c_1..c_n$, 
108
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   236
this algorithm presented graphically is as follows:
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   237
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   238
\begin{equation}\label{graph:*}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   239
\begin{tikzcd}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   240
r_0 \arrow[r, "\backslash c_0"]  & r_1 \arrow[r, "\backslash c_1"] & r_2 \arrow[r, dashed]  & r_n  \arrow[r,"\textit{nullable}?"] & \;\textrm{YES}/\textrm{NO}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   241
\end{tikzcd}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   242
\end{equation}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   243
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   244
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   245
where we start with  a regular expression  $r_0$, build successive
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   246
derivatives until we exhaust the string and then use \textit{nullable}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   247
to test whether the result can match the empty string. It can  be
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   248
relatively  easily shown that this matcher is correct  (that is given
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   249
an $s = c_0...c_{n-1}$ and an $r_0$, it generates YES if and only if $s \in L(r_0)$).
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   250
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   251
Beautiful and simple definition.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   252
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   253
If we implement the above algorithm naively, however,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   254
the algorithm can be excruciatingly slow. For example, when starting with the regular
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   255
expression $(a + aa)^*$ and building 12 successive derivatives
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   256
w.r.t.~the character $a$, one obtains a derivative regular expression
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   257
with more than 8000 nodes (when viewed as a tree). Operations like
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   258
$\backslash$ and $\nullable$ need to traverse such trees and
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   259
consequently the bigger the size of the derivative the slower the
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   260
algorithm. 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   261
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   262
Brzozowski was quick in finding that during this process a lot useless
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   263
$\ONE$s and $\ZERO$s are generated and therefore not optimal.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   264
He also introduced some "similarity rules" such
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   265
as $P+(Q+R) = (P+Q)+R$ to merge syntactically 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   266
different but language-equivalent sub-regexes to further decrease the size
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   267
of the intermediate regexes. 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   268
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   269
More simplifications are possible, such as deleting duplicates
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   270
and opening up nested alternatives to trigger even more simplifications.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   271
And suppose we apply simplification after each derivative step, and compose
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   272
these two operations together as an atomic one: $a \backslash_{simp}\,c \dn
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   273
\textit{simp}(a \backslash c)$. Then we can build
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   274
a matcher without having  cumbersome regular expressions.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   275
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   276
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   277
If we want the size of derivatives in the algorithm to
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   278
stay even lower, we would need more aggressive simplifications.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   279
Essentially we need to delete useless $\ZERO$s and $\ONE$s, as well as
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   280
deleting duplicates whenever possible. For example, the parentheses in
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   281
$(a+b) \cdot c + b\cdot c$ can be opened up to get $a\cdot c + b \cdot c + b
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   282
\cdot c$, and then simplified to just $a \cdot c + b \cdot c$. Another
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   283
example is simplifying $(a^*+a) + (a^*+ \ONE) + (a +\ONE)$ to just
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   284
$a^*+a+\ONE$. Adding these more aggressive simplification rules help us
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   285
to achieve a very tight size bound, namely,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   286
 the same size bound as that of the \emph{partial derivatives}. 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   287
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   288
Building derivatives and then simplify them.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   289
So far so good. But what if we want to 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   290
do lexing instead of just a YES/NO answer?
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   291
This requires us to go back again to the world 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   292
without simplification first for a moment.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   293
Sulzmann and Lu~\cite{Sulzmann2014} first came up with a nice and 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   294
elegant(arguably as beautiful as the original
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   295
derivatives definition) solution for this.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   296
108
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   297
\subsection*{Values and the Lexing Algorithm by Sulzmann and Lu}
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   298
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   299
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   300
They first defined the datatypes for storing the 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   301
lexing information called a \emph{value} or
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   302
sometimes also \emph{lexical value}.  These values and regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   303
expressions correspond to each other as illustrated in the following
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   304
table:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   305
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   306
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   307
	\begin{tabular}{c@{\hspace{20mm}}c}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   308
		\begin{tabular}{@{}rrl@{}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   309
			\multicolumn{3}{@{}l}{\textbf{Regular Expressions}}\medskip\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   310
			$r$ & $::=$  & $\ZERO$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   311
			& $\mid$ & $\ONE$   \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   312
			& $\mid$ & $c$          \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   313
			& $\mid$ & $r_1 \cdot r_2$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   314
			& $\mid$ & $r_1 + r_2$   \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   315
			\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   316
			& $\mid$ & $r^*$         \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   317
		\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   318
		&
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   319
		\begin{tabular}{@{\hspace{0mm}}rrl@{}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   320
			\multicolumn{3}{@{}l}{\textbf{Values}}\medskip\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   321
			$v$ & $::=$  & \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   322
			&        & $\Empty$   \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   323
			& $\mid$ & $\Char(c)$          \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   324
			& $\mid$ & $\Seq\,v_1\, v_2$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   325
			& $\mid$ & $\Left(v)$   \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   326
			& $\mid$ & $\Right(v)$  \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   327
			& $\mid$ & $\Stars\,[v_1,\ldots\,v_n]$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   328
		\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   329
	\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   330
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   331
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   332
\noindent
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   333
One regular expression can have multiple lexical values. For example
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   334
for the regular expression $(a+b)^*$, it has a infinite list of
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   335
values corresponding to it: $\Stars\,[]$, $\Stars\,[\Left(Char(a))]$,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   336
$\Stars\,[\Right(Char(b))]$, $\Stars\,[\Left(Char(a),\,\Right(Char(b))]$,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   337
$\ldots$, and vice versa.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   338
Even for the regular expression matching a certain string, there could 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   339
still be more than one value corresponding to it.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   340
Take the example where $r= (a^*\cdot a^*)^*$ and the string 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   341
$s=\underbrace{aa\ldots a}_\text{n \textit{a}s}$.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   342
The number of different ways of matching 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   343
without allowing any value under a star to be flattened
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   344
to an empty string can be given by the following formula:
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   345
\begin{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   346
	$C_n = (n+1)+n C_1+\ldots + 2 C_{n-1}$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   347
\end{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   348
and a closed form formula can be calculated to be
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   349
\begin{equation}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   350
	C_n =\frac{(2+\sqrt{2})^n - (2-\sqrt{2})^n}{4\sqrt{2}}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   351
\end{equation}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   352
which is clearly in exponential order.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   353
A lexer aimed at getting all the possible values has an exponential
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   354
worst case runtime. Therefore it is impractical to try to generate
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   355
all possible matches in a run. In practice, we are usually 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   356
interested about POSIX values, which by intuition always
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   357
match the leftmost regular expression when there is a choice
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   358
and always match a sub part as much as possible before proceeding
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   359
to the next token. For example, the above example has the POSIX value
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   360
$ \Stars\,[\Seq(Stars\,[\underbrace{\Char(a),\ldots,\Char(a)}_\text{n iterations}], Stars\,[])]$.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   361
The output of an algorithm we want would be a POSIX matching
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   362
encoded as a value.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   363
The contribution of Sulzmann and Lu is an extension of Brzozowski's
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   364
algorithm by a second phase (the first phase being building successive
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   365
derivatives---see \eqref{graph:*}). In this second phase, a POSIX value 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   366
is generated in case the regular expression matches  the string. 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   367
Pictorially, the Sulzmann and Lu algorithm is as follows:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   368
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   369
\begin{ceqn}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   370
\begin{equation}\label{graph:2}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   371
\begin{tikzcd}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   372
r_0 \arrow[r, "\backslash c_0"]  \arrow[d] & r_1 \arrow[r, "\backslash c_1"] \arrow[d] & r_2 \arrow[r, dashed] \arrow[d] & r_n \arrow[d, "mkeps" description] \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   373
v_0           & v_1 \arrow[l,"inj_{r_0} c_0"]                & v_2 \arrow[l, "inj_{r_1} c_1"]              & v_n \arrow[l, dashed]         
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   374
\end{tikzcd}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   375
\end{equation}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   376
\end{ceqn}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   377
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   378
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   379
For convenience, we shall employ the following notations: the regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   380
expression we start with is $r_0$, and the given string $s$ is composed
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   381
of characters $c_0 c_1 \ldots c_{n-1}$. In  the first phase from the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   382
left to right, we build the derivatives $r_1$, $r_2$, \ldots  according
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   383
to the characters $c_0$, $c_1$  until we exhaust the string and obtain
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   384
the derivative $r_n$. We test whether this derivative is
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   385
$\textit{nullable}$ or not. If not, we know the string does not match
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   386
$r$ and no value needs to be generated. If yes, we start building the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   387
values incrementally by \emph{injecting} back the characters into the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   388
earlier values $v_n, \ldots, v_0$. This is the second phase of the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   389
algorithm from the right to left. For the first value $v_n$, we call the
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   390
function $\textit{mkeps}$, which builds a POSIX lexical value
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   391
for how the empty string has been matched by the (nullable) regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   392
expression $r_n$. This function is defined as
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   393
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   394
	\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   395
		\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   396
			$\mkeps(\ONE)$ 		& $\dn$ & $\Empty$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   397
			$\mkeps(r_{1}+r_{2})$	& $\dn$ 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   398
			& \textit{if} $\nullable(r_{1})$\\ 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   399
			& & \textit{then} $\Left(\mkeps(r_{1}))$\\ 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   400
			& & \textit{else} $\Right(\mkeps(r_{2}))$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   401
			$\mkeps(r_1\cdot r_2)$ 	& $\dn$ & $\Seq\,(\mkeps\,r_1)\,(\mkeps\,r_2)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   402
			$mkeps(r^*)$	        & $\dn$ & $\Stars\,[]$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   403
		\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   404
	\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   405
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   406
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   407
\noindent 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   408
After the $\mkeps$-call, we inject back the characters one by one in order to build
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   409
the lexical value $v_i$ for how the regex $r_i$ matches the string $s_i$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   410
($s_i = c_i \ldots c_{n-1}$ ) from the previous lexical value $v_{i+1}$.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   411
After injecting back $n$ characters, we get the lexical value for how $r_0$
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   412
matches $s$. The POSIX value is maintained throught out the process.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   413
For this Sulzmann and Lu defined a function that reverses
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   414
the ``chopping off'' of characters during the derivative phase. The
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   415
corresponding function is called \emph{injection}, written
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   416
$\textit{inj}$; it takes three arguments: the first one is a regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   417
expression ${r_{i-1}}$, before the character is chopped off, the second
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   418
is a character ${c_{i-1}}$, the character we want to inject and the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   419
third argument is the value ${v_i}$, into which one wants to inject the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   420
character (it corresponds to the regular expression after the character
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   421
has been chopped off). The result of this function is a new value. The
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   422
definition of $\textit{inj}$ is as follows: 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   423
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   424
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   425
\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   426
  $\textit{inj}\,(c)\,c\,Empty$            & $\dn$ & $Char\,c$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   427
  $\textit{inj}\,(r_1 + r_2)\,c\,\Left(v)$ & $\dn$ & $\Left(\textit{inj}\,r_1\,c\,v)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   428
  $\textit{inj}\,(r_1 + r_2)\,c\,Right(v)$ & $\dn$ & $Right(\textit{inj}\,r_2\,c\,v)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   429
  $\textit{inj}\,(r_1 \cdot r_2)\,c\,Seq(v_1,v_2)$ & $\dn$  & $Seq(\textit{inj}\,r_1\,c\,v_1,v_2)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   430
  $\textit{inj}\,(r_1 \cdot r_2)\,c\,\Left(Seq(v_1,v_2))$ & $\dn$  & $Seq(\textit{inj}\,r_1\,c\,v_1,v_2)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   431
  $\textit{inj}\,(r_1 \cdot r_2)\,c\,Right(v)$ & $\dn$  & $Seq(\textit{mkeps}(r_1),\textit{inj}\,r_2\,c\,v)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   432
  $\textit{inj}\,(r^*)\,c\,Seq(v,Stars\,vs)$         & $\dn$  & $Stars((\textit{inj}\,r\,c\,v)\,::\,vs)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   433
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   434
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   435
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   436
\noindent This definition is by recursion on the ``shape'' of regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   437
expressions and values. 
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   438
The clauses basically do one thing--identifying the ``holes'' on 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   439
value to inject the character back into.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   440
For instance, in the last clause for injecting back to a value
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   441
that would turn into a new star value that corresponds to a star,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   442
we know it must be a sequence value. And we know that the first 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   443
value of that sequence corresponds to the child regex of the star
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   444
with the first character being chopped off--an iteration of the star
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   445
that had just been unfolded. This value is followed by the already
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   446
matched star iterations we collected before. So we inject the character 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   447
back to the first value and form a new value with this new iteration
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   448
being added to the previous list of iterations, all under the $Stars$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   449
top level.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   450
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   451
We have mentioned before that derivatives without simplification 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   452
can get clumsy, and this is true for values as well--they reflect
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   453
the regular expressions size by definition.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   454
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   455
One can introduce simplification on the regex and values, but have to
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   456
be careful in not breaking the correctness as the injection 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   457
function heavily relies on the structure of the regexes and values
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   458
being correct and match each other.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   459
It can be achieved by recording some extra rectification functions
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   460
during the derivatives step, and applying these rectifications in 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   461
each run during the injection phase.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   462
And we can prove that the POSIX value of how
131
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   463
regular expressions match strings will not be affected---although is much harder
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   464
to establish. Some initial results in this regard have been
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   465
obtained in \cite{AusafDyckhoffUrban2016}. 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   466
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   467
%Brzozowski, after giving the derivatives and simplification,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   468
%did not explore lexing with simplification or he may well be 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   469
%stuck on an efficient simplificaiton with a proof.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   470
%He went on to explore the use of derivatives together with 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   471
%automaton, and did not try lexing using derivatives.
131
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   472
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   473
We want to get rid of complex and fragile rectification of values.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   474
Can we not create those intermediate values $v_1,\ldots v_n$,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   475
and get the lexing information that should be already there while
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   476
doing derivatives in one pass, without a second phase of injection?
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   477
In the meantime, can we make sure that simplifications
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   478
are easily handled without breaking the correctness of the algorithm?
130
Chengsong
parents: 129
diff changeset
   479
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   480
Sulzmann and Lu solved this problem by
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   481
introducing additional informtaion to the 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   482
regular expressions called \emph{bitcodes}.
130
Chengsong
parents: 129
diff changeset
   483
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   484
\subsection*{Bit-coded Algorithm}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   485
Bits and bitcodes (lists of bits) are defined as:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   486
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   487
\begin{center}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   488
		$b ::=   1 \mid  0 \qquad
130
Chengsong
parents: 129
diff changeset
   489
bs ::= [] \mid b::bs    
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   490
$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   491
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   492
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   493
\noindent
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   494
The $1$ and $0$ are not in bold in order to avoid 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   495
confusion with the regular expressions $\ZERO$ and $\ONE$. Bitcodes (or
130
Chengsong
parents: 129
diff changeset
   496
bit-lists) can be used to encode values (or potentially incomplete values) in a
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   497
compact form. This can be straightforwardly seen in the following
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   498
coding function from values to bitcodes: 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   499
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   500
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   501
\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   502
  $\textit{code}(\Empty)$ & $\dn$ & $[]$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   503
  $\textit{code}(\Char\,c)$ & $\dn$ & $[]$\\
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   504
  $\textit{code}(\Left\,v)$ & $\dn$ & $0 :: code(v)$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   505
  $\textit{code}(\Right\,v)$ & $\dn$ & $1 :: code(v)$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   506
  $\textit{code}(\Seq\,v_1\,v_2)$ & $\dn$ & $code(v_1) \,@\, code(v_2)$\\
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   507
  $\textit{code}(\Stars\,[])$ & $\dn$ & $[0]$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   508
  $\textit{code}(\Stars\,(v\!::\!vs))$ & $\dn$ & $1 :: code(v) \;@\;
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   509
                                                 code(\Stars\,vs)$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   510
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   511
\end{center} 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   512
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   513
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   514
Here $\textit{code}$ encodes a value into a bitcodes by converting
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   515
$\Left$ into $0$, $\Right$ into $1$, and marks the start of a non-empty
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   516
star iteration by $1$. The border where a local star terminates
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   517
is marked by $0$. This coding is lossy, as it throws away the information about
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   518
characters, and also does not encode the ``boundary'' between two
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   519
sequence values. Moreover, with only the bitcode we cannot even tell
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
   520
whether the $1$s and $0$s are for $\Left/\Right$ or $\Stars$. The
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   521
reason for choosing this compact way of storing information is that the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   522
relatively small size of bits can be easily manipulated and ``moved
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   523
around'' in a regular expression. In order to recover values, we will 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   524
need the corresponding regular expression as an extra information. This
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   525
means the decoding function is defined as:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   526
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   527
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   528
%\begin{definition}[Bitdecoding of Values]\mbox{}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   529
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   530
\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   531
  $\textit{decode}'\,bs\,(\ONE)$ & $\dn$ & $(\Empty, bs)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   532
  $\textit{decode}'\,bs\,(c)$ & $\dn$ & $(\Char\,c, bs)$\\
115
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   533
  $\textit{decode}'\,(0\!::\!bs)\;(r_1 + r_2)$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   534
     $\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r_1\;\textit{in}\;
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   535
       (\Left\,v, bs_1)$\\
115
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   536
  $\textit{decode}'\,(1\!::\!bs)\;(r_1 + r_2)$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   537
     $\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r_2\;\textit{in}\;
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   538
       (\Right\,v, bs_1)$\\                           
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   539
  $\textit{decode}'\,bs\;(r_1\cdot r_2)$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   540
        $\textit{let}\,(v_1, bs_1) = \textit{decode}'\,bs\,r_1\;\textit{in}$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   541
  & &   $\textit{let}\,(v_2, bs_2) = \textit{decode}'\,bs_1\,r_2$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   542
  & &   \hspace{35mm}$\textit{in}\;(\Seq\,v_1\,v_2, bs_2)$\\
115
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   543
  $\textit{decode}'\,(0\!::\!bs)\,(r^*)$ & $\dn$ & $(\Stars\,[], bs)$\\
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   544
  $\textit{decode}'\,(1\!::\!bs)\,(r^*)$ & $\dn$ & 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   545
         $\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r\;\textit{in}$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   546
  & &   $\textit{let}\,(\Stars\,vs, bs_2) = \textit{decode}'\,bs_1\,r^*$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   547
  & &   \hspace{35mm}$\textit{in}\;(\Stars\,v\!::\!vs, bs_2)$\bigskip\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   548
  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   549
  $\textit{decode}\,bs\,r$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   550
     $\textit{let}\,(v, bs') = \textit{decode}'\,bs\,r\;\textit{in}$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   551
  & & $\textit{if}\;bs' = []\;\textit{then}\;\textit{Some}\,v\;
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   552
       \textit{else}\;\textit{None}$                       
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   553
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   554
\end{center}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   555
%\end{definition}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   556
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   557
Sulzmann and Lu's integrated the bitcodes into regular expressions to
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   558
create annotated regular expressions \cite{Sulzmann2014}.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   559
\emph{Annotated regular expressions} are defined by the following
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   560
grammar:%\comment{ALTS should have  an $as$ in  the definitions, not  just $a_1$ and $a_2$}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   561
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   562
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   563
\begin{tabular}{lcl}
115
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   564
  $\textit{a}$ & $::=$  & $\ZERO$\\
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   565
                  & $\mid$ & $_{bs}\ONE$\\
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   566
                  & $\mid$ & $_{bs}{\bf c}$\\
132
Chengsong
parents: 131
diff changeset
   567
                  & $\mid$ & $_{bs}\sum\,as$\\
115
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   568
                  & $\mid$ & $_{bs}a_1\cdot a_2$\\
5c8afe4a8090 for secu
Chengsong
parents: 114
diff changeset
   569
                  & $\mid$ & $_{bs}a^*$
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   570
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   571
\end{center}  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   572
%(in \textit{ALTS})
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   573
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   574
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   575
where $bs$ stands for bitcodes, $a$  for $\bold{a}$nnotated regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   576
expressions and $as$ for a list of annotated regular expressions.
132
Chengsong
parents: 131
diff changeset
   577
The alternative constructor($\sum$) has been generalized to 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   578
accept a list of annotated regular expressions rather than just 2.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   579
We will show that these bitcodes encode information about
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   580
the (POSIX) value that should be generated by the Sulzmann and Lu
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   581
algorithm.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   582
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   583
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   584
To do lexing using annotated regular expressions, we shall first
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   585
transform the usual (un-annotated) regular expressions into annotated
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   586
regular expressions. This operation is called \emph{internalisation} and
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   587
defined as follows:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   588
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   589
%\begin{definition}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   590
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   591
\begin{tabular}{lcl}
116
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   592
  $(\ZERO)^\uparrow$ & $\dn$ & $\ZERO$\\
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   593
  $(\ONE)^\uparrow$ & $\dn$ & $_{[]}\ONE$\\
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   594
  $(c)^\uparrow$ & $\dn$ & $_{[]}{\bf c}$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   595
  $(r_1 + r_2)^\uparrow$ & $\dn$ &
132
Chengsong
parents: 131
diff changeset
   596
  $_{[]}\sum[\textit{fuse}\,[0]\,r_1^\uparrow,\,
116
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   597
  \textit{fuse}\,[1]\,r_2^\uparrow]$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   598
  $(r_1\cdot r_2)^\uparrow$ & $\dn$ &
116
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   599
         $_{[]}r_1^\uparrow \cdot r_2^\uparrow$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   600
  $(r^*)^\uparrow$ & $\dn$ &
116
dfcad6f19e06 just incase
Chengsong
parents: 115
diff changeset
   601
         $_{[]}(r^\uparrow)^*$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   602
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   603
\end{center}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   604
%\end{definition}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   605
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   606
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   607
We use up arrows here to indicate that the basic un-annotated regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   608
expressions are ``lifted up'' into something slightly more complex. In the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   609
fourth clause, $\textit{fuse}$ is an auxiliary function that helps to
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   610
attach bits to the front of an annotated regular expression. Its
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   611
definition is as follows:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   612
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   613
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   614
\begin{tabular}{lcl}
117
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   615
  $\textit{fuse}\;bs \; \ZERO$ & $\dn$ & $\ZERO$\\
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   616
  $\textit{fuse}\;bs\; _{bs'}\ONE$ & $\dn$ &
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   617
     $_{bs @ bs'}\ONE$\\
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   618
  $\textit{fuse}\;bs\;_{bs'}{\bf c}$ & $\dn$ &
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   619
     $_{bs@bs'}{\bf c}$\\
132
Chengsong
parents: 131
diff changeset
   620
  $\textit{fuse}\;bs\,_{bs'}\sum\textit{as}$ & $\dn$ &
Chengsong
parents: 131
diff changeset
   621
     $_{bs@bs'}\sum\textit{as}$\\
117
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   622
  $\textit{fuse}\;bs\; _{bs'}a_1\cdot a_2$ & $\dn$ &
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   623
     $_{bs@bs'}a_1 \cdot a_2$\\
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   624
  $\textit{fuse}\;bs\,_{bs'}a^*$ & $\dn$ &
0acf6b58236e just incase
Chengsong
parents: 116
diff changeset
   625
     $_{bs @ bs'}a^*$
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   626
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   627
\end{center}  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   628
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   629
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   630
After internalising the regular expression, we perform successive
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   631
derivative operations on the annotated regular expressions. This
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   632
derivative operation is the same as what we had previously for the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   633
basic regular expressions, except that we beed to take care of
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   634
the bitcodes:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   635
109
Chengsong
parents: 108
diff changeset
   636
Chengsong
parents: 108
diff changeset
   637
\iffalse
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   638
 %\begin{definition}{bder}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   639
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   640
  \begin{tabular}{@{}lcl@{}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   641
  $(\textit{ZERO})\,\backslash c$ & $\dn$ & $\textit{ZERO}$\\  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   642
  $(\textit{ONE}\;bs)\,\backslash c$ & $\dn$ & $\textit{ZERO}$\\  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   643
  $(\textit{CHAR}\;bs\,d)\,\backslash c$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   644
        $\textit{if}\;c=d\; \;\textit{then}\;
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   645
         \textit{ONE}\;bs\;\textit{else}\;\textit{ZERO}$\\  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   646
  $(\textit{ALTS}\;bs\,as)\,\backslash c$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   647
  $\textit{ALTS}\;bs\,(as.map(\backslash c))$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   648
  $(\textit{SEQ}\;bs\,a_1\,a_2)\,\backslash c$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   649
     $\textit{if}\;\textit{bnullable}\,a_1$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   650
					       & &$\textit{then}\;\textit{ALTS}\,bs\,List((\textit{SEQ}\,[]\,(a_1\,\backslash c)\,a_2),$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   651
					       & &$\phantom{\textit{then}\;\textit{ALTS}\,bs\,}(\textit{fuse}\,(\textit{bmkeps}\,a_1)\,(a_2\,\backslash c)))$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   652
  & &$\textit{else}\;\textit{SEQ}\,bs\,(a_1\,\backslash c)\,a_2$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   653
  $(\textit{STAR}\,bs\,a)\,\backslash c$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   654
      $\textit{SEQ}\;bs\,(\textit{fuse}\, [\Z] (r\,\backslash c))\,
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   655
       (\textit{STAR}\,[]\,r)$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   656
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   657
\end{center}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   658
%\end{definition}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   659
109
Chengsong
parents: 108
diff changeset
   660
\begin{center}
Chengsong
parents: 108
diff changeset
   661
  \begin{tabular}{@{}lcl@{}}
Chengsong
parents: 108
diff changeset
   662
  $(\textit{ZERO})\,\backslash c$ & $\dn$ & $\textit{ZERO}$\\  
Chengsong
parents: 108
diff changeset
   663
  $(_{bs}\textit{ONE})\,\backslash c$ & $\dn$ & $\textit{ZERO}$\\  
Chengsong
parents: 108
diff changeset
   664
  $(_{bs}\textit{CHAR}\;d)\,\backslash c$ & $\dn$ &
Chengsong
parents: 108
diff changeset
   665
        $\textit{if}\;c=d\; \;\textit{then}\;
Chengsong
parents: 108
diff changeset
   666
         _{bs}\textit{ONE}\;\textit{else}\;\textit{ZERO}$\\  
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   667
  $(_{bs}\textit{ALTS}\;\textit{as})\,\backslash c$ & $\dn$ &
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   668
  $_{bs}\textit{ALTS}\;(\textit{as}.\textit{map}(\backslash c))$\\
109
Chengsong
parents: 108
diff changeset
   669
  $(_{bs}\textit{SEQ}\;a_1\,a_2)\,\backslash c$ & $\dn$ &
Chengsong
parents: 108
diff changeset
   670
     $\textit{if}\;\textit{bnullable}\,a_1$\\
Chengsong
parents: 108
diff changeset
   671
					       & &$\textit{then}\;_{bs}\textit{ALTS}\,List((_{[]}\textit{SEQ}\,(a_1\,\backslash c)\,a_2),$\\
Chengsong
parents: 108
diff changeset
   672
					       & &$\phantom{\textit{then}\;_{bs}\textit{ALTS}\,}(\textit{fuse}\,(\textit{bmkeps}\,a_1)\,(a_2\,\backslash c)))$\\
Chengsong
parents: 108
diff changeset
   673
  & &$\textit{else}\;_{bs}\textit{SEQ}\,(a_1\,\backslash c)\,a_2$\\
Chengsong
parents: 108
diff changeset
   674
  $(_{bs}\textit{STAR}\,a)\,\backslash c$ & $\dn$ &
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   675
      $_{bs}\textit{SEQ}\;(\textit{fuse}\, [0] \; r\,\backslash c )\,
109
Chengsong
parents: 108
diff changeset
   676
       (_{bs}\textit{STAR}\,[]\,r)$
Chengsong
parents: 108
diff changeset
   677
\end{tabular}    
Chengsong
parents: 108
diff changeset
   678
\end{center}    
Chengsong
parents: 108
diff changeset
   679
%\end{definition}
Chengsong
parents: 108
diff changeset
   680
\fi
Chengsong
parents: 108
diff changeset
   681
Chengsong
parents: 108
diff changeset
   682
\begin{center}
Chengsong
parents: 108
diff changeset
   683
  \begin{tabular}{@{}lcl@{}}
Chengsong
parents: 108
diff changeset
   684
  $(\ZERO)\,\backslash c$ & $\dn$ & $\ZERO$\\  
Chengsong
parents: 108
diff changeset
   685
  $(_{bs}\ONE)\,\backslash c$ & $\dn$ & $\ZERO$\\  
Chengsong
parents: 108
diff changeset
   686
  $(_{bs}{\bf d})\,\backslash c$ & $\dn$ &
Chengsong
parents: 108
diff changeset
   687
        $\textit{if}\;c=d\; \;\textit{then}\;
Chengsong
parents: 108
diff changeset
   688
         _{bs}\ONE\;\textit{else}\;\ZERO$\\  
132
Chengsong
parents: 131
diff changeset
   689
  $(_{bs}\sum \;\textit{as})\,\backslash c$ & $\dn$ &
Chengsong
parents: 131
diff changeset
   690
  $_{bs}\sum\;(\textit{as.map}(\backslash c))$\\
109
Chengsong
parents: 108
diff changeset
   691
  $(_{bs}\;a_1\cdot a_2)\,\backslash c$ & $\dn$ &
Chengsong
parents: 108
diff changeset
   692
     $\textit{if}\;\textit{bnullable}\,a_1$\\
132
Chengsong
parents: 131
diff changeset
   693
					       & &$\textit{then}\;_{bs}\sum\,[(_{[]}\,(a_1\,\backslash c)\cdot\,a_2),$\\
Chengsong
parents: 131
diff changeset
   694
					       & &$\phantom{\textit{then},\;_{bs}\sum\,}(\textit{fuse}\,(\textit{bmkeps}\,a_1)\,(a_2\,\backslash c))]$\\
109
Chengsong
parents: 108
diff changeset
   695
  & &$\textit{else}\;_{bs}\,(a_1\,\backslash c)\cdot a_2$\\
Chengsong
parents: 108
diff changeset
   696
  $(_{bs}a^*)\,\backslash c$ & $\dn$ &
119
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   697
      $_{bs}(\textit{fuse}\, [0] \; r\,\backslash c)\cdot
109
Chengsong
parents: 108
diff changeset
   698
       (_{[]}r^*))$
Chengsong
parents: 108
diff changeset
   699
\end{tabular}    
Chengsong
parents: 108
diff changeset
   700
\end{center}    
Chengsong
parents: 108
diff changeset
   701
Chengsong
parents: 108
diff changeset
   702
%\end{definition}
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   703
\noindent
119
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   704
For instance, when we do derivative of  $_{bs}a^*$ with respect to c,
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   705
we need to unfold it into a sequence,
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   706
and attach an additional bit $0$ to the front of $r \backslash c$
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   707
to indicate that there is one more star iteration. Also the sequence clause
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   708
is more subtle---when $a_1$ is $\textit{bnullable}$ (here
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   709
\textit{bnullable} is exactly the same as $\textit{nullable}$, except
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   710
that it is for annotated regular expressions, therefore we omit the
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   711
definition). Assume that $\textit{bmkeps}$ correctly extracts the bitcode for how
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   712
$a_1$ matches the string prior to character $c$ (more on this later),
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   713
then the right branch of alternative, which is $\textit{fuse} \; \bmkeps \;  a_1 (a_2
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   714
\backslash c)$ will collapse the regular expression $a_1$(as it has
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   715
already been fully matched) and store the parsing information at the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   716
head of the regular expression $a_2 \backslash c$ by fusing to it. The
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   717
bitsequence $\textit{bs}$, which was initially attached to the
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   718
first element of the sequence $a_1 \cdot a_2$, has
132
Chengsong
parents: 131
diff changeset
   719
now been elevated to the top-level of $\sum$, as this information will be
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
   720
needed whichever way the sequence is matched---no matter whether $c$ belongs
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   721
to $a_1$ or $ a_2$. After building these derivatives and maintaining all
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   722
the lexing information, we complete the lexing by collecting the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   723
bitcodes using a generalised version of the $\textit{mkeps}$ function
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   724
for annotated regular expressions, called $\textit{bmkeps}$:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   725
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   726
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   727
%\begin{definition}[\textit{bmkeps}]\mbox{}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   728
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   729
\begin{tabular}{lcl}
119
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   730
  $\textit{bmkeps}\,(_{bs}\ONE)$ & $\dn$ & $bs$\\
132
Chengsong
parents: 131
diff changeset
   731
  $\textit{bmkeps}\,(_{bs}\sum a::\textit{as})$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   732
     $\textit{if}\;\textit{bnullable}\,a$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   733
  & &$\textit{then}\;bs\,@\,\textit{bmkeps}\,a$\\
132
Chengsong
parents: 131
diff changeset
   734
  & &$\textit{else}\;bs\,@\,\textit{bmkeps}\,(_{bs}\sum \textit{as})$\\
120
1ca011142964 for fear
Chengsong
parents: 119
diff changeset
   735
  $\textit{bmkeps}\,(_{bs} a_1 \cdot a_2)$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   736
     $bs \,@\,\textit{bmkeps}\,a_1\,@\, \textit{bmkeps}\,a_2$\\
119
cc12352272f2 for fear
Chengsong
parents: 118
diff changeset
   737
  $\textit{bmkeps}\,(_{bs}a^*)$ & $\dn$ &
121
Chengsong
parents: 120
diff changeset
   738
     $bs \,@\, [0]$
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   739
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   740
\end{center}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   741
%\end{definition}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   742
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   743
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   744
This function completes the value information by travelling along the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   745
path of the regular expression that corresponds to a POSIX value and
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   746
collecting all the bitcodes, and using $S$ to indicate the end of star
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   747
iterations. If we take the bitcodes produced by $\textit{bmkeps}$ and
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   748
decode them, we get the value we expect. The corresponding lexing
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   749
algorithm looks as follows:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   750
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   751
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   752
\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   753
  $\textit{blexer}\;r\,s$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   754
      $\textit{let}\;a = (r^\uparrow)\backslash s\;\textit{in}$\\                
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   755
  & & $\;\;\textit{if}\; \textit{bnullable}(a)$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   756
  & & $\;\;\textit{then}\;\textit{decode}\,(\textit{bmkeps}\,a)\,r$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   757
  & & $\;\;\textit{else}\;\textit{None}$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   758
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   759
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   760
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   761
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   762
In this definition $\_\backslash s$ is the  generalisation  of the derivative
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   763
operation from characters to strings (just like the derivatives for un-annotated
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   764
regular expressions).
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   765
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   766
Remember tha one of the important reasons we introduced bitcodes
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   767
is that they can make simplification more structured and therefore guaranteeing
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   768
the correctness.
108
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   769
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   770
\subsection*{Our Simplification Rules}
0a0c551bb368 updated
Christian Urban <urbanc@in.tum.de>
parents: 107
diff changeset
   771
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   772
In this section we introduce aggressive (in terms of size) simplification rules
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   773
on annotated regular expressions
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   774
in order to keep derivatives small. Such simplifications are promising
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   775
as we have
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   776
generated test data that show
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
   777
that a good tight bound can be achieved. Obviously we could only
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   778
partially cover  the search space as there are infinitely many regular
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   779
expressions and strings. 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   780
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   781
One modification we introduced is to allow a list of annotated regular
132
Chengsong
parents: 131
diff changeset
   782
expressions in the $\sum$ constructor. This allows us to not just
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   783
delete unnecessary $\ZERO$s and $\ONE$s from regular expressions, but
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   784
also unnecessary ``copies'' of regular expressions (very similar to
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   785
simplifying $r + r$ to just $r$, but in a more general setting). Another
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   786
modification is that we use simplification rules inspired by Antimirov's
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   787
work on partial derivatives. They maintain the idea that only the first
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   788
``copy'' of a regular expression in an alternative contributes to the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   789
calculation of a POSIX value. All subsequent copies can be pruned away from
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   790
the regular expression. A recursive definition of our  simplification function 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   791
that looks somewhat similar to our Scala code is given below:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   792
%\comment{Use $\ZERO$, $\ONE$ and so on. 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   793
%Is it $ALTS$ or $ALTS$?}\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   794
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   795
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   796
  \begin{tabular}{@{}lcl@{}}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   797
   
121
Chengsong
parents: 120
diff changeset
   798
  $\textit{simp} \; (_{bs}a_1\cdot a_2)$ & $\dn$ & $ (\textit{simp} \; a_1, \textit{simp}  \; a_2) \; \textit{match} $ \\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   799
   &&$\quad\textit{case} \; (\ZERO, \_) \Rightarrow  \ZERO$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   800
   &&$\quad\textit{case} \; (\_, \ZERO) \Rightarrow  \ZERO$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   801
   &&$\quad\textit{case} \;  (\ONE, a_2') \Rightarrow  \textit{fuse} \; bs \;  a_2'$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   802
   &&$\quad\textit{case} \; (a_1', \ONE) \Rightarrow  \textit{fuse} \; bs \;  a_1'$ \\
121
Chengsong
parents: 120
diff changeset
   803
   &&$\quad\textit{case} \; (a_1', a_2') \Rightarrow   _{bs}a_1' \cdot a_2'$ \\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   804
133
0172d422e93e geiwuhanshizhangnuannuanxing
Chengsong
parents: 132
diff changeset
   805
  $\textit{simp} \; (_{bs}\sum \textit{as})$ & $\dn$ & $\textit{distinct}( \textit{flatten} ( \textit{as.map(simp)})) \; \textit{match} $ \\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   806
  &&$\quad\textit{case} \; [] \Rightarrow  \ZERO$ \\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   807
   &&$\quad\textit{case} \; a :: [] \Rightarrow  \textit{fuse bs a}$ \\
132
Chengsong
parents: 131
diff changeset
   808
   &&$\quad\textit{case} \;  as' \Rightarrow _{bs}\sum \textit{as'}$\\ 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   809
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   810
   $\textit{simp} \; a$ & $\dn$ & $\textit{a} \qquad \textit{otherwise}$   
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   811
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   812
\end{center}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   813
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   814
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   815
The simplification does a pattern matching on the regular expression.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   816
When it detected that the regular expression is an alternative or
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   817
sequence, it will try to simplify its children regular expressions
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   818
recursively and then see if one of the children turn into $\ZERO$ or
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   819
$\ONE$, which might trigger further simplification at the current level.
132
Chengsong
parents: 131
diff changeset
   820
The most involved part is the $\sum$ clause, where we use two
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   821
auxiliary functions $\textit{flatten}$ and $\textit{distinct}$ to open up nested
121
Chengsong
parents: 120
diff changeset
   822
alternatives and reduce as many duplicates as possible. Function
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   823
$\textit{distinct}$  keeps the first occurring copy only and remove all later ones
132
Chengsong
parents: 131
diff changeset
   824
when detected duplicates. Function $\textit{flatten}$ opens up nested $\sum$s.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   825
Its recursive definition is given below:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   826
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   827
 \begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   828
  \begin{tabular}{@{}lcl@{}}
132
Chengsong
parents: 131
diff changeset
   829
  $\textit{flatten} \; (_{bs}\sum \textit{as}) :: \textit{as'}$ & $\dn$ & $(\textit{map} \;
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   830
     (\textit{fuse}\;bs)\; \textit{as}) \; @ \; \textit{flatten} \; as' $ \\
121
Chengsong
parents: 120
diff changeset
   831
  $\textit{flatten} \; \ZERO :: as'$ & $\dn$ & $ \textit{flatten} \;  \textit{as'} $ \\
Chengsong
parents: 120
diff changeset
   832
    $\textit{flatten} \; a :: as'$ & $\dn$ & $a :: \textit{flatten} \; \textit{as'}$ \quad(otherwise) 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   833
\end{tabular}    
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   834
\end{center}  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   835
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   836
\noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   837
Here $\textit{flatten}$ behaves like the traditional functional programming flatten
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   838
function, except that it also removes $\ZERO$s. Or in terms of regular expressions, it
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   839
removes parentheses, for example changing $a+(b+c)$ into $a+b+c$.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   840
131
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   841
Having defined the $\simp$ function,
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   842
we can use the previous notation of  natural
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   843
extension from derivative w.r.t.~character to derivative
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   844
w.r.t.~string:%\comment{simp in  the [] case?}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   845
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   846
\begin{center}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   847
\begin{tabular}{lcl}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   848
$r \backslash_{simp} (c\!::\!s) $ & $\dn$ & $(r \backslash_{simp}\, c) \backslash_{simp}\, s$ \\
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   849
$r \backslash_{simp} [\,] $ & $\dn$ & $r$
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   850
\end{tabular}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   851
\end{center}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   852
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   853
\noindent
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   854
to obtain an optimised version of the algorithm:
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   855
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   856
 \begin{center}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   857
\begin{tabular}{lcl}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   858
  $\textit{blexer\_simp}\;r\,s$ & $\dn$ &
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   859
      $\textit{let}\;a = (r^\uparrow)\backslash_{simp}\, s\;\textit{in}$\\                
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   860
  & & $\;\;\textit{if}\; \textit{bnullable}(a)$\\
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   861
  & & $\;\;\textit{then}\;\textit{decode}\,(\textit{bmkeps}\,a)\,r$\\
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   862
  & & $\;\;\textit{else}\;\textit{None}$
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   863
\end{tabular}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   864
\end{center}
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   865
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   866
\noindent
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   867
This algorithm keeps the regular expression size small, for example,
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   868
with this simplification our previous $(a + aa)^*$ example's 8000 nodes
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   869
will be reduced to just 6 and stays constant, no matter how long the
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
   870
input string is.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   871
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   872
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
   873
126
1260b383ae2c forfear
Chengsong
parents: 125
diff changeset
   874
\section{Current Work and Progress}
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   875
For reasons beyond this report, it turns out that a complete set of
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   876
simplification rules depends on values being encoded as
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   877
bitsequences.\footnote{Values are the results the lexing algorithms
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   878
  generate; they encode how a regular expression matched a string.} We
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   879
already know that the lexing algorithm using bitsequences but
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   880
\emph{without} simplification is correct, albeilt horribly
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   881
slow. Therefore in the past 6 months I was trying to prove that the
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   882
algorithm using bitsequences plus our simplification rules is
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   883
also correct. Formally this amounts to show that
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   884
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   885
\begin{equation}\label{mainthm}
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   886
\blexers \; r \; s = \blexer \;r\;s
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   887
\end{equation}
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   888
94
Chengsong
parents:
diff changeset
   889
\noindent
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   890
whereby $\blexers$ simplifies (makes derivatives smaller) in each
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
   891
step. This
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   892
would be an important milestone for my thesis, because we already
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   893
have a very good idea how to establish that our set our simplification
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
   894
rules keep the size of derivatives below a relatively tight bound.
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   895
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   896
In order to prove the main theorem in \eqref{mainthm}, we need to prove that the
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   897
two functions produce the same output. The definition of these two  functions 
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   898
is shown below.
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   899
94
Chengsong
parents:
diff changeset
   900
\begin{center}
Chengsong
parents:
diff changeset
   901
\begin{tabular}{lcl}
Chengsong
parents:
diff changeset
   902
  $\textit{blexer}\;r\,s$ & $\dn$ &
Chengsong
parents:
diff changeset
   903
      $\textit{let}\;a = (r^\uparrow)\backslash s\;\textit{in}$\\                
Chengsong
parents:
diff changeset
   904
  & & $\;\;\textit{if}\; \textit{bnullable}(a)$\\
Chengsong
parents:
diff changeset
   905
  & & $\;\;\textit{then}\;\textit{decode}\,(\textit{bmkeps}\,a)\,r$\\
Chengsong
parents:
diff changeset
   906
  & & $\;\;\textit{else}\;\textit{None}$
Chengsong
parents:
diff changeset
   907
\end{tabular}
Chengsong
parents:
diff changeset
   908
\end{center}
Chengsong
parents:
diff changeset
   909
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   910
\begin{center}
94
Chengsong
parents:
diff changeset
   911
\begin{tabular}{lcl}
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   912
  $\blexers \; r \, s$ &$\dn$ &
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   913
    $\textit{let} \; a = (r^\uparrow)\backslash_{simp}\, s\; \textit{in}$\\
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   914
  & & $\; \; \textit{if} \; \textit{bnullable}(a)$\\
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   915
  & & $\; \; \textit{then} \; \textit{decode}\,(\textit{bmkeps}\,a)\,r$\\
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   916
  & & $\;\;   \textit{else}\;\textit{None}$
94
Chengsong
parents:
diff changeset
   917
\end{tabular}
Chengsong
parents:
diff changeset
   918
\end{center}
Chengsong
parents:
diff changeset
   919
\noindent
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   920
In these definitions $(r^\uparrow)$ is a kind of coding function that
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   921
is the same in each case, similarly the decode and the \textit{bmkeps}
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   922
are functions that are the same in each case. Our main
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   923
theorem~\eqref{mainthm} therefore boils down to proving the following
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   924
two propositions (depending on which branch the if-else clause
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   925
takes). They establish how the derivatives \emph{with} simplification
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   926
do not change the computed result:
94
Chengsong
parents:
diff changeset
   927
Chengsong
parents:
diff changeset
   928
\begin{itemize}
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   929
\item{(a)} If a string $s$ is in the language of $L(r)$, then \\
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   930
$\textit{bmkeps} (r^\uparrow)\backslash_{simp}\,s = \textit{bmkeps} (r^\uparrow)\backslash s$,\\
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   931
\item{(b)} If a string $s$ is in the language $L(r)$, then 
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   932
$\rup \backslash_{simp} \,s$ is not nullable.
94
Chengsong
parents:
diff changeset
   933
\end{itemize}
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   934
94
Chengsong
parents:
diff changeset
   935
\noindent
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   936
We have already proved the second part  in Isabelle. This is actually
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   937
not too difficult because we can show that simplification does not
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   938
change the language of simplified regular expressions.
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   939
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   940
If we can prove the first part, that is the bitsequence algorithm with
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   941
simplification produces the same result as the one without
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   942
simplification, then we are done.  Unfortunately that part requires
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   943
more effort, because simplification does not only need to \emph{not}
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   944
change the language, but also not change the value (that is the
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   945
computed result).
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   946
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   947
%\bigskip\noindent\rule[1.5ex]{\linewidth}{5pt}
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   948
%Do you want to keep this? You essentially want to say that the old
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   949
%method used retrieve, which unfortunately cannot be adopted to 
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   950
%the simplification rules. You could just say that and give an example.
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   951
%However you have to think about how you give the example....nobody knows
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   952
%about AZERO etc yet. Maybe it might be better to use normal regexes
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   953
%like $a + aa$, but annotate bitsequences as subscript like $_1(_0a + _1aa)$.
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   954
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   955
%\bigskip\noindent\rule[1.5ex]{\linewidth}{5pt}
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   956
%REPLY:\\
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   957
%Yes, I am essentially saying that the old method
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   958
%cannot be adopted without adjustments.
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   959
%But this does not mean we should skip
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   960
%the proof of the bit-coded algorithm
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   961
%as it is still the main direction we are looking into
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   962
%to prove things. We are trying to modify
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   963
%the old proof to suit our needs, but not give 
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   964
%up it totally, that is why i believe the old 
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   965
%proof is fundamental in understanding
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   966
%what we are doing in the past 6 months.
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   967
%\bigskip\noindent\rule[1.5ex]{\linewidth}{5pt}
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   968
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   969
\subsubsection*{Existing Proof}
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
   970
134
Chengsong
parents: 133
diff changeset
   971
For this we have started with looking at the proof of
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   972
\begin{equation}\label{lexer}
134
Chengsong
parents: 133
diff changeset
   973
\blexer \; (r^\uparrow)  s = \lexer \;r \;s,
105
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   974
\end{equation}
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   975
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   976
%\noindent
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   977
%might provide us insight into proving 
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   978
%\begin{center}
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   979
%$\blexer \; r^\uparrow \;s = \blexers \; r^\uparrow \;s$
317a7d54ebcc updated
Christian Urban <urbanc@in.tum.de>
parents: 103
diff changeset
   980
%\end{center}
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   981
94
Chengsong
parents:
diff changeset
   982
\noindent
143
Chengsong
parents: 142
diff changeset
   983
which established that the bit-sequence algorithm produces the same
134
Chengsong
parents: 133
diff changeset
   984
result as the original algorithm, which does not use 
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
   985
bit-sequences.
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
   986
The proof uses two ``tricks''. One is that it uses a \flex-function
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   987
94
Chengsong
parents:
diff changeset
   988
\begin{center}
Chengsong
parents:
diff changeset
   989
\begin{tabular}{lcl}
Chengsong
parents:
diff changeset
   990
$\textit{flex} \;r\; f\; (c\!::\!s) $ & $\dn$ & $\textit{flex} \;  (r\backslash c) \;(\lambda v. f (inj \; r \; c \; v)) \;s$ \\
Chengsong
parents:
diff changeset
   991
$\textit{flex} \;r\; f\;  [\,] $ & $\dn$ & $f$
Chengsong
parents:
diff changeset
   992
\end{tabular}
Chengsong
parents:
diff changeset
   993
\end{center}
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   994
94
Chengsong
parents:
diff changeset
   995
\noindent
134
Chengsong
parents: 133
diff changeset
   996
to prove for the right-hand side in \eqref{lexer}
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   997
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
   998
\begin{center}
134
Chengsong
parents: 133
diff changeset
   999
$\lexer \;r\; s = \flex \;\textit{id} \; r\;s \;(\mkeps \; (r\backslash s))$.
Chengsong
parents: 133
diff changeset
  1000
\end{center}
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
  1001
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
  1002
104
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
  1003
e7ba4da53930 merged christian changes
Chengsong
parents: 103
diff changeset
  1004
\noindent
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1005
This property links $\flex$ and $\lexer$,
134
Chengsong
parents: 133
diff changeset
  1006
it essentially does lexing by
Chengsong
parents: 133
diff changeset
  1007
stacking up injection functions while doing derivatives,
94
Chengsong
parents:
diff changeset
  1008
explicitly showing the order of characters being
Chengsong
parents:
diff changeset
  1009
injected back in each step.
106
e0db3242d8b5 added my comments
Christian Urban <urbanc@in.tum.de>
parents: 105 104
diff changeset
  1010
94
Chengsong
parents:
diff changeset
  1011
\noindent
135
Chengsong
parents: 134
diff changeset
  1012
The other trick, which is the crux in the existing proof, 
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1013
is the use of the $\retrieve$-function by Sulzmann and Lu:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1014
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1015
\begin{tabular}{@{}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
110
Chengsong
parents: 109
diff changeset
  1016
  $\textit{retrieve}\,(_{bs}\ONE)\,\Empty$ & $\dn$ & $bs$\\
Chengsong
parents: 109
diff changeset
  1017
  $\textit{retrieve}\,(_{bs}{\bf c})\,(\Char\,d)$ & $\dn$ & $bs$\\
132
Chengsong
parents: 131
diff changeset
  1018
  $\textit{retrieve}\,(_{bs}\sum a::as)\,(\Left\,v)$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1019
     $bs \,@\, \textit{retrieve}\,a\,v$\\
132
Chengsong
parents: 131
diff changeset
  1020
  $\textit{retrieve}\,(_{bs}\sum a::as)\,(\Right\,v)$ & $\dn$ &
Chengsong
parents: 131
diff changeset
  1021
  $\textit{bs} \,@\, \textit{retrieve}\,(_{[]}\sum as)\,v$\\
121
Chengsong
parents: 120
diff changeset
  1022
  $\textit{retrieve}\,(_{bs}a_1\cdot a_2)\,(\Seq\,v_1\,v_2)$ & $\dn$ &
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1023
     $bs \,@\,\textit{retrieve}\,a_1\,v_1\,@\, \textit{retrieve}\,a_2\,v_2$\\
121
Chengsong
parents: 120
diff changeset
  1024
  $\textit{retrieve}\,(_{bs}a^*)\,(\Stars\,[])$ & $\dn$ &
Chengsong
parents: 120
diff changeset
  1025
     $bs \,@\, [0]$\\
Chengsong
parents: 120
diff changeset
  1026
  $\textit{retrieve}\,(_{bs}a^*)\,(\Stars\,(v\!::\!vs))$ & $\dn$ &\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1027
  \multicolumn{3}{l}{
121
Chengsong
parents: 120
diff changeset
  1028
     \hspace{3cm}$bs \,@\, [1] \,@\, \textit{retrieve}\,a\,v\,@\,
Chengsong
parents: 120
diff changeset
  1029
                    \textit{retrieve}\,(_{[]}a^*)\,(\Stars\,vs)$}\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1030
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1031
\end{center}
135
Chengsong
parents: 134
diff changeset
  1032
Chengsong
parents: 134
diff changeset
  1033
\noindent
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1034
This function assembles the bitcode 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1035
using information from both the derivative regular expression and the
135
Chengsong
parents: 134
diff changeset
  1036
value. Sulzmann and Lu proposed this function, but did not prove
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1037
anything about it. Ausaf and Urban made use of the
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1038
fact about $\retrieve$ in their proof:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1039
 
135
Chengsong
parents: 134
diff changeset
  1040
 \begin{center} 
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1041
 $\retrieve\; \rup \backslash c \; v = \retrieve \;  \rup (\inj \;r \;c \; v)$
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1042
 \end{center} 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1043
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1044
\noindent
135
Chengsong
parents: 134
diff changeset
  1045
whereby $r^\uparrow$ stands for the internalised version of $r$.
Chengsong
parents: 134
diff changeset
  1046
This fact, together with the fact of how $\flex$ relates to injection:
Chengsong
parents: 134
diff changeset
  1047
Chengsong
parents: 134
diff changeset
  1048
\begin{equation}\label{flex}
Chengsong
parents: 134
diff changeset
  1049
\flex \; r \; id \; (s@[c]) \; v = \flex \;  r \; id \; s \; (inj \; (r\backslash s) \; c\; v).
Chengsong
parents: 134
diff changeset
  1050
\end{equation}
Chengsong
parents: 134
diff changeset
  1051
Chengsong
parents: 134
diff changeset
  1052
\noindent
Chengsong
parents: 134
diff changeset
  1053
can be used to prove what we want:
Chengsong
parents: 134
diff changeset
  1054
\begin{center} 
Chengsong
parents: 134
diff changeset
  1055
$ \flex \; r\; id\; s\; v = \textit{decode} \;( \textit{bmkeps}\; (\rup \backslash s) ) r$
Chengsong
parents: 134
diff changeset
  1056
\end{center}
Chengsong
parents: 134
diff changeset
  1057
\noindent
Chengsong
parents: 134
diff changeset
  1058
If we state the inductive hypothesis to be
Chengsong
parents: 134
diff changeset
  1059
\begin{center} 
Chengsong
parents: 134
diff changeset
  1060
$ \flex \; r\; id\; s\; v = \textit{decode} \;( \textit{retrieve}\; (\rup \backslash s) \; v \;) r$
Chengsong
parents: 134
diff changeset
  1061
\end{center}
Chengsong
parents: 134
diff changeset
  1062
\noindent
Chengsong
parents: 134
diff changeset
  1063
where $\mkeps(r\backslash s) $ is denoted using $v$,
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1064
then a reverse induction  
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1065
helps with using 
135
Chengsong
parents: 134
diff changeset
  1066
the fact~\eqref{flex} in proving the $n+1$ step:
Chengsong
parents: 134
diff changeset
  1067
\begin{center} 
Chengsong
parents: 134
diff changeset
  1068
$ \flex \; r\; id\; (s@[c])\; v = \textit{decode} \;( \textit{retrieve}\; (\rup \backslash s) \; (\inj \; (r\backslash s) \;c\;v)\;) r$
Chengsong
parents: 134
diff changeset
  1069
\end{center}
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1070
Using a lemma that
135
Chengsong
parents: 134
diff changeset
  1071
\begin{center}
Chengsong
parents: 134
diff changeset
  1072
$\textit{retrieve}\; (\rup \backslash s) \; (\inj \; (r\backslash s) \;c\;v)\; = \textit{retrieve}\; (\rup \backslash s@[c])  \; v\; $
Chengsong
parents: 134
diff changeset
  1073
\end{center}
Chengsong
parents: 134
diff changeset
  1074
we get
Chengsong
parents: 134
diff changeset
  1075
\begin{center} 
Chengsong
parents: 134
diff changeset
  1076
$  \textit{decode} \;( \textit{retrieve}\; (\rup \backslash s) \; (\inj \; (r\backslash s) \;c\;v)\;) r = \textit{decode} \;( \textit{retrieve}\; (\rup \backslash s@[c]) \; v\;) r $
Chengsong
parents: 134
diff changeset
  1077
\end{center}
Chengsong
parents: 134
diff changeset
  1078
and the inductive step is done because
Chengsong
parents: 134
diff changeset
  1079
\begin{center} 
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1080
$ \textit{retrieve}\; (\rup \backslash s@[c]) \; \mkeps(r\backslash s) =  \bmkeps \;(\rup \backslash s@[c])$.
135
Chengsong
parents: 134
diff changeset
  1081
\end{center}
Chengsong
parents: 134
diff changeset
  1082
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1083
\noindent
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1084
To use 
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1085
$ \flex \; r\; id\; s\; v = \textit{decode} \;( \textit{retrieve}\; (\rup \backslash s) \; v \;) r$
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1086
 for our 
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1087
correctness proof, simply replace the $v$ with
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1088
$\mkeps\;(r\backslash s)$, and apply the lemma that
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1089
\begin{center}
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1090
$ \; \bmkeps \; \rup =  (\textit{retrieve} \; \rup \; \mkeps(r))$
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1091
\end{center}
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1092
\noindent
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1093
We get the correctness of our bit-coded algorithm:
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1094
\begin{center}
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1095
$\flex \;r\;  id \; s \; (\mkeps \; (r\backslash s)) = \textit{decode} \; (\bmkeps \; \rup\backslash s) \; r$.
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1096
\end{center}
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1097
\noindent
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1098
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1099
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1100
135
Chengsong
parents: 134
diff changeset
  1101
\subsubsection{Using Retrieve Function In a New Setting}
Chengsong
parents: 134
diff changeset
  1102
 Ausaf
Chengsong
parents: 134
diff changeset
  1103
and Urban used $\retrieve$  to prove  the correctness of bitcoded
Chengsong
parents: 134
diff changeset
  1104
algorithm without simplification.  Our purpose of using it, however,
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1105
is to establish 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1106
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1107
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1108
$ \textit{retrieve} \;
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1109
a \; v \;=\; \textit{retrieve}  \; (\textit{simp}\,a) \; v'.$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1110
\end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1111
The idea is that using $v'$, a simplified version of $v$ that had gone
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1112
through the same simplification step as $\textit{simp}(a)$, we are able
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1113
to extract the bitcode that gives the same lexing information as the
144
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1114
unsimplified one. 
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1115
If we want to use a similar technique as
bc340e8f4165 more changes
Chengsong
parents: 143
diff changeset
  1116
that of the existing proof,
94
Chengsong
parents:
diff changeset
  1117
we face the problem that in the above 
Chengsong
parents:
diff changeset
  1118
equalities,
Chengsong
parents:
diff changeset
  1119
$\retrieve \; a \; v$ is not always defined.
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1120
For example,
100
397b31867ea6 copied christian changes
Chengsong
parents: 95
diff changeset
  1121
$\retrieve \; _0(_1a+_0a) \; \Left(\Empty)$
101
Chengsong
parents: 100
diff changeset
  1122
is defined, but not $\retrieve \; (_{01}a) \;\Left(\Empty)$,
94
Chengsong
parents:
diff changeset
  1123
though we can extract the same POSIX
Chengsong
parents:
diff changeset
  1124
bits from the two annotated regular expressions.
95
Chengsong
parents: 94
diff changeset
  1125
The latter might occur when we try to retrieve from 
Chengsong
parents: 94
diff changeset
  1126
a simplified regular expression using the same value
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1127
underlying the unsimplified one.
95
Chengsong
parents: 94
diff changeset
  1128
This is because $\Left(\Empty)$ corresponds to
101
Chengsong
parents: 100
diff changeset
  1129
the regular expression structure $\ONE+r_2$ instead of
Chengsong
parents: 100
diff changeset
  1130
$\ONE$.
94
Chengsong
parents:
diff changeset
  1131
That means, if we 
Chengsong
parents:
diff changeset
  1132
want to prove that 
Chengsong
parents:
diff changeset
  1133
\begin{center}
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1134
$\bmkeps \; \rup\backslash s = \bmkeps \; \rup\backslash_{simp} s$
94
Chengsong
parents:
diff changeset
  1135
\end{center}
Chengsong
parents:
diff changeset
  1136
\noindent
Chengsong
parents:
diff changeset
  1137
holds by using $\retrieve$,
Chengsong
parents:
diff changeset
  1138
we probably need to prove an equality like below:
Chengsong
parents:
diff changeset
  1139
\begin{center}
Chengsong
parents:
diff changeset
  1140
%$\retrieve \; \rup\backslash_{simp} s \; \mkeps(r\backslash_{simp} s)=\textit{retrieve} \; \rup\backslash s \; \mkeps(r\backslash s)$
101
Chengsong
parents: 100
diff changeset
  1141
$\retrieve \; \rup\backslash_{simp} s \; \mkeps(f(r\backslash s))=\textit{retrieve} \; \rup\backslash s \; \mkeps(r\backslash s)$
94
Chengsong
parents:
diff changeset
  1142
\end{center}
Chengsong
parents:
diff changeset
  1143
\noindent
101
Chengsong
parents: 100
diff changeset
  1144
$f$ rectifies $r\backslash s$ so the value $\mkeps(f(r\backslash s))$ becomes
Chengsong
parents: 100
diff changeset
  1145
 something simpler
94
Chengsong
parents:
diff changeset
  1146
to make the retrieve function defined.\\
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1147
\subsubsection{Ways to Rectify Values}
95
Chengsong
parents: 94
diff changeset
  1148
One way to do this is to prove the following:
Chengsong
parents: 94
diff changeset
  1149
\begin{center}
Chengsong
parents: 94
diff changeset
  1150
$\retrieve \; \rup\backslash_{simp} s \; \mkeps(\simp(r\backslash s))=\textit{retrieve} \; \rup\backslash s \; \mkeps(r\backslash s)$
Chengsong
parents: 94
diff changeset
  1151
\end{center}
Chengsong
parents: 94
diff changeset
  1152
\noindent
101
Chengsong
parents: 100
diff changeset
  1153
The reason why we choose $\simp$ as $f$ is because
Chengsong
parents: 100
diff changeset
  1154
$\rup\backslash_{simp} \, s$ and $\simp(\rup\backslash \, s)$
Chengsong
parents: 100
diff changeset
  1155
have the same shape:
Chengsong
parents: 100
diff changeset
  1156
\begin{center}
Chengsong
parents: 100
diff changeset
  1157
$\erase (\rup\backslash_{simp} \, s) = \erase(\simp(\rup\backslash s))$
Chengsong
parents: 100
diff changeset
  1158
\end{center}
Chengsong
parents: 100
diff changeset
  1159
Chengsong
parents: 100
diff changeset
  1160
\noindent
Chengsong
parents: 100
diff changeset
  1161
$\erase$ in the above equality means to remove the bit-codes
Chengsong
parents: 100
diff changeset
  1162
in an annotated regular expression and only keep the original
Chengsong
parents: 100
diff changeset
  1163
regular expression(just like "erasing" the bits). Its definition is omitted.
Chengsong
parents: 100
diff changeset
  1164
$\rup\backslash_{simp} \, s$ and $\simp(\rup\backslash s)$
Chengsong
parents: 100
diff changeset
  1165
are very closely related, but not identical.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1166
\subsubsection{Example for $\rup\backslash_{simp} \, s \neq \simp(\rup\backslash s)$}
101
Chengsong
parents: 100
diff changeset
  1167
For example, let $r$ be the regular expression
Chengsong
parents: 100
diff changeset
  1168
$(a+b)(a+a*)$ and $s$  be the string $aa$, then
103
Chengsong
parents: 102
diff changeset
  1169
both $\erase (\rup\backslash_{simp} \, s)$ and $\erase (\simp (\rup\backslash s))$
Chengsong
parents: 102
diff changeset
  1170
are $\ONE + a^*$. However, without $\erase$ 
101
Chengsong
parents: 100
diff changeset
  1171
\begin{center}
Chengsong
parents: 100
diff changeset
  1172
$\rup\backslash_{simp} \, s$ is equal to $_0(_0\ONE +_{11}a^*)$
Chengsong
parents: 100
diff changeset
  1173
\end{center}
Chengsong
parents: 100
diff changeset
  1174
\noindent
Chengsong
parents: 100
diff changeset
  1175
whereas
Chengsong
parents: 100
diff changeset
  1176
\begin{center}
103
Chengsong
parents: 102
diff changeset
  1177
$\simp(\rup\backslash  s)$ is equal to $(_{00}\ONE +_{011}a^*)$
101
Chengsong
parents: 100
diff changeset
  1178
\end{center}
103
Chengsong
parents: 102
diff changeset
  1179
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1180
What makes the difference?
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1181
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1182
%Two "rules" might be inferred from the above example.
103
Chengsong
parents: 102
diff changeset
  1183
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1184
%First, after erasing the bits the two regular expressions
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1185
%are exactly the same: both become $1+a^*$. Here the 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1186
%function $\simp$ exhibits the "one in the end equals many times
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1187
%at the front"
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1188
%property: one simplification in the end causes the 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1189
%same regular expression structure as
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1190
%successive simplifications done alongside derivatives.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1191
%$\rup\backslash_{simp} \, s$ unfolds to 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1192
%$\simp((\simp(r\backslash a))\backslash a)$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1193
%and $\simp(\rup\backslash s)$ unfolds to 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1194
%$\simp((r\backslash a)\backslash a)$. The one simplification
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1195
%in the latter causes the resulting regular expression to 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1196
%become $1+a^*$, exactly the same as the former with
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1197
%two simplifications.
103
Chengsong
parents: 102
diff changeset
  1198
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1199
%Second, the bit-codes are different, but they are essentially
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1200
%the same: if we push the outmost bits ${\bf_0}(_0\ONE +_{11}a^*)$ of $\rup\backslash_{simp} \, s$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1201
%inside then we get $(_{00}\ONE +_{011}a^*)$, exactly the 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1202
%same as that of $\rup\backslash \, s$. And this difference 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1203
%does not matter when we try to apply $\bmkeps$ or $\retrieve$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1204
%to it. This seems a good news if we want to use $\retrieve$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1205
%to prove things.
103
Chengsong
parents: 102
diff changeset
  1206
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1207
%If we look into the difference above, we could see that the
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1208
%difference is not fundamental: the bits are just being moved
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1209
%around in a way that does not hurt the correctness.
103
Chengsong
parents: 102
diff changeset
  1210
During the first derivative operation, 
Chengsong
parents: 102
diff changeset
  1211
$\rup\backslash a=(_0\ONE  + \ZERO)(_0a  +  _1a^*)$  is
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1212
in the form of a sequence regular expression with
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1213
two components, the first
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1214
one $\ONE + \ZERO$ being nullable. 
103
Chengsong
parents: 102
diff changeset
  1215
Recall the simplification function definition:
Chengsong
parents: 102
diff changeset
  1216
\begin{center}
Chengsong
parents: 102
diff changeset
  1217
  \begin{tabular}{@{}lcl@{}}
Chengsong
parents: 102
diff changeset
  1218
   
Chengsong
parents: 102
diff changeset
  1219
  $\textit{simp} \; (\textit{SEQ}\;bs\,a_1\,a_2)$ & $\dn$ & $ (\textit{simp} \; a_1, \textit{simp}  \; a_2) \; \textit{match} $ \\
Chengsong
parents: 102
diff changeset
  1220
   &&$\quad\textit{case} \; (\ZERO, \_) \Rightarrow  \ZERO$ \\
Chengsong
parents: 102
diff changeset
  1221
   &&$\quad\textit{case} \; (\_, \ZERO) \Rightarrow  \ZERO$ \\
Chengsong
parents: 102
diff changeset
  1222
   &&$\quad\textit{case} \;  (\ONE, a_2') \Rightarrow  \textit{fuse} \; bs \;  a_2'$ \\
Chengsong
parents: 102
diff changeset
  1223
   &&$\quad\textit{case} \; (a_1', \ONE) \Rightarrow  \textit{fuse} \; bs \;  a_1'$ \\
Chengsong
parents: 102
diff changeset
  1224
   &&$\quad\textit{case} \; (a_1', a_2') \Rightarrow  \textit{SEQ} \; bs \; a_1' \;  a_2'$ \\
Chengsong
parents: 102
diff changeset
  1225
131
b6984212cf87 changes
Chengsong
parents: 130
diff changeset
  1226
  $\textit{simp} \; (\textit{ALTS}\;bs\,as)$ & $\dn$ & $\textit{distinct}( \textit{flatten} ( \textit{as.map(simp)})) \; \textit{match} $ \\
103
Chengsong
parents: 102
diff changeset
  1227
  &&$\quad\textit{case} \; [] \Rightarrow  \ZERO$ \\
Chengsong
parents: 102
diff changeset
  1228
   &&$\quad\textit{case} \; a :: [] \Rightarrow  \textit{fuse bs a}$ \\
Chengsong
parents: 102
diff changeset
  1229
   &&$\quad\textit{case} \;  as' \Rightarrow  \textit{ALTS}\;bs\;as'$\\ 
Chengsong
parents: 102
diff changeset
  1230
Chengsong
parents: 102
diff changeset
  1231
   $\textit{simp} \; a$ & $\dn$ & $\textit{a} \qquad \textit{otherwise}$   
Chengsong
parents: 102
diff changeset
  1232
\end{tabular}    
Chengsong
parents: 102
diff changeset
  1233
\end{center}    
Chengsong
parents: 102
diff changeset
  1234
Chengsong
parents: 102
diff changeset
  1235
\noindent
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1236
132
Chengsong
parents: 131
diff changeset
  1237
and the definition of $\flatten$:
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1238
 \begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1239
 \begin{tabular}{c c c}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1240
 $\flatten \; []$ & $\dn$ & $[]$\\
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1241
 $\flatten \; \ZERO::rs$ & $\dn$ & $rs$\\
132
Chengsong
parents: 131
diff changeset
  1242
 $\flatten \;(_{\textit{bs}_1}\sum \textit{rs}_1 ::rs)$ & $\dn$ & $(\map \, (\fuse \, \textit{bs}_1) \,\textit{rs}_1) ::: \flatten(rs)$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1243
 $\flatten \; r :: rs$ & $\dn$ & $r::\flatten(rs)$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1244
 \end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1245
 \end{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1246
 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1247
 \noindent
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1248
If we call $\simp$ on $\rup\backslash a$, just as $\backslash_{simp}$
132
Chengsong
parents: 131
diff changeset
  1249
requires, then we would go through the third clause of 
103
Chengsong
parents: 102
diff changeset
  1250
the sequence case:$\quad\textit{case} \;  (\ONE, a_2') \Rightarrow  \textit{fuse} \; bs \;  a_2'$.
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1251
The $\ZERO$ of $(_0\ONE  + \ZERO)$ is thrown away 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1252
by $\flatten$ and 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1253
$_0\ONE$ merged into $(_0a  +  _1a^*)$ by simply
103
Chengsong
parents: 102
diff changeset
  1254
putting its bits($_0$) to the front of the second component:
Chengsong
parents: 102
diff changeset
  1255
 ${\bf_0}(_0a  +  _1a^*)$. 
Chengsong
parents: 102
diff changeset
  1256
 After a second derivative operation,
Chengsong
parents: 102
diff changeset
  1257
 namely, $(_0(_0a  +  _1a^*))\backslash a$, we get 
Chengsong
parents: 102
diff changeset
  1258
 $
Chengsong
parents: 102
diff changeset
  1259
 _0(_0 \ONE  +  _1(_1\ONE \cdot a^*))
Chengsong
parents: 102
diff changeset
  1260
 $, and this simplifies to $_0(_0 \ONE  +  _{11} a^*)$
Chengsong
parents: 102
diff changeset
  1261
 by the third clause of the alternative case:
132
Chengsong
parents: 131
diff changeset
  1262
 \begin{center}
Chengsong
parents: 131
diff changeset
  1263
 $\quad\textit{case} \;  as' \Rightarrow  _{bs}\sum{as'}$.
Chengsong
parents: 131
diff changeset
  1264
 \end{center}
Chengsong
parents: 131
diff changeset
  1265
 
Chengsong
parents: 131
diff changeset
  1266
 \noindent
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1267
The outmost bit $_0$ stays with 
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1268
the outermost regular expression, rather than being fused to
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1269
its child regular expressions, as what we will later see happens
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1270
to $\simp(\rup\backslash \, s)$.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1271
If we choose to not simplify in the midst of derivative operations,
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1272
but only do it at the end after the string has been exhausted, 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1273
namely, $\simp(\rup\backslash \, s)=\simp((\rup\backslash a)\backslash a)$,
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1274
then at the {\bf second} derivative of 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1275
$(\rup\backslash a)\bf{\backslash a}$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1276
we will go throught the clause of $\backslash$:
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1277
\begin{center}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1278
\begin{tabular}{lcl}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1279
$(\textit{SEQ}\;bs\,a_1\,a_2)\,\backslash c$ & $\dn$ &
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1280
     $(when \; \textit{bnullable}\,a_1)$\\
133
0172d422e93e geiwuhanshizhangnuannuanxing
Chengsong
parents: 132
diff changeset
  1281
					       & &$_{bs}\sum\,\;[_{[]}((a_1\,\backslash c) \cdot \,a_2),$\\
0172d422e93e geiwuhanshizhangnuannuanxing
Chengsong
parents: 132
diff changeset
  1282
					       & &$(\textit{fuse}\,(\textit{bmkeps}\,a_1)\,(a_2\,\backslash c))]$\\
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1283
\end{tabular}
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1284
\end{center}
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1285
\noindent
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1286
because
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1287
$\rup\backslash a = (_0\ONE  + \ZERO)(_0a  +  _1a^*)$  
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1288
is a sequence
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1289
with the first component being nullable
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1290
(unsimplified, unlike the first round of running$\backslash_{simp}$).
103
Chengsong
parents: 102
diff changeset
  1291
Therefore $((_0\ONE  + \ZERO)(_0a  +  _1a^*))\backslash a$ splits into
Chengsong
parents: 102
diff changeset
  1292
$([(\ZERO + \ZERO)\cdot(_0a  +  _1a^*)] + _0( _0\ONE  + _1[_1\ONE \cdot a^*]))$.
Chengsong
parents: 102
diff changeset
  1293
After these two successive derivatives without simplification,
Chengsong
parents: 102
diff changeset
  1294
we apply $\simp$ to this regular expression, which goes through
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1295
the alternative clause, and each component of 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1296
$([(\ZERO + \ZERO)\cdot(_0a  +  _1a^*)] + _0( _0\ONE  + _1[_1\ONE \cdot a^*]))$ 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1297
will be simplified, giving us the list:$[\ZERO, _0(_0\ONE  + _{11}a^*)]$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1298
This list is then "flattened"--$\ZERO$ will be
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1299
thrown away by $\textit{flatten}$; $ _0(_0\ONE  + _{11}a^*)$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1300
is opened up to make the list consisting of two separate elements 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1301
$_{00}\ONE$ and $_{011}a^*$, note that $flatten$ 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1302
$\fuse$s the bit(s) $_0$ to the front of $_0\ONE $ and $_{11}a^*$.
122
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1303
The order of simplification, which impacts the order that alternatives
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1304
are  opened up, causes
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1305
the bits to be moved differently.
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1306
 
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1307
 \subsubsection{A Failed Attempt To Remedy the Problem Above}
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1308
A simple class of regular expression and string
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1309
pairs $(r, s)$ can be deduced from the above example 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1310
which trigger the difference between 
107
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1311
$\rup\backslash_{simp} \, s$
b1e365afa29c changes
Chengsong
parents: 106
diff changeset
  1312
and  $\simp(\rup\backslash s)$:
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1313
\begin{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1314
\begin{tabular}{lcl}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1315
$D =\{ (r_1 \cdot r_2,\; [c_1c_2]) \mid $ & $\simp(r_2) = r_2, \simp(r_1 \backslash c_1) = \ONE,$\\
132
Chengsong
parents: 131
diff changeset
  1316
 $r_1 \; not \; \nullable, c_2 \in L(r_2),$ & $\exists \textit{rs},\textit{bs}.\;  r_2 \backslash c_2 = _{bs}{\sum rs}$\\
Chengsong
parents: 131
diff changeset
  1317
$\exists \textit{rs}_1. \; \simp(r_2 \backslash c_2) = _{bs}{\sum \textit{rs}_1}$ &  $and \;\simp(r_1 \backslash [c_1c_2]) = \ZERO\}$\\
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1318
\end{tabular}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1319
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1320
We take a pair $(r, \;s)$ from the set $D$.
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1321
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1322
Now we compute $ \rup \backslash_{simp} s$, we get:
110
Chengsong
parents: 109
diff changeset
  1323
\begin{center}
Chengsong
parents: 109
diff changeset
  1324
\begin{tabular}{lcl}
Chengsong
parents: 109
diff changeset
  1325
$(r_1\cdot r_2)\backslash_{simp} \, [c_1c_2]$ & $= \simp\left[ \big(\simp\left[ \left( r_1\cdot r_2 \right) \backslash c_1\right] \big)\backslash c_2\right]$\\
Chengsong
parents: 109
diff changeset
  1326
								      & $= \simp\left[ \big(\simp \left[  \left(r_1 \backslash c_1\right) \cdot r_2 \right] \big) \backslash c_2 \right]$\\
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1327
								      & $= \simp \left[  (\fuse \; \bmkeps(r_1\backslash c_1) \; \simp(r_2) ) \backslash c_2 \right]$,\\
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1328
								      & $= \simp \left[  (\fuse \; \bmkeps(r_1\backslash c_1) \; r_2 ) \backslash c_2 \right]$,
110
Chengsong
parents: 109
diff changeset
  1329
\end{tabular}
Chengsong
parents: 109
diff changeset
  1330
\end{center}
Chengsong
parents: 109
diff changeset
  1331
\noindent
Chengsong
parents: 109
diff changeset
  1332
from the definition of $D$ we know $r_1 \backslash c_1$ is nullable, therefore
Chengsong
parents: 109
diff changeset
  1333
$\bmkeps(r_1\backslash c_1)$  returns a bitcode, we shall call it
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1334
 $\textit{bs}_2$. 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1335
The above term can be rewritten as
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1336
\begin{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1337
$ \simp \left[  \fuse \; \textit{bs}_2\; r_2  \backslash c_2 \right]$,
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1338
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1339
which is equal to 
110
Chengsong
parents: 109
diff changeset
  1340
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1341
$\simp \left[ \fuse \; \textit{bs}_2 \; _{bs}{\sum rs} \right]$\\
Chengsong
parents: 131
diff changeset
  1342
$=\simp \left[  \; _{bs_2++bs}{\sum rs} \right]$\\
Chengsong
parents: 131
diff changeset
  1343
$=  \; _{bs_2++bs}{\sum \textit{rs}_1} $
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1344
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1345
\noindent
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1346
by using the properties from the set $D$ again
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1347
and again(The reason why we set so many conditions 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1348
that the pair $(r,s)$ need to satisfy is because we can
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1349
rewrite them easily to construct the difference.)
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1350
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1351
Now we compute ${\bf \simp(\rup \backslash s)}$:
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1352
\begin{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1353
$\simp \big[(r_1\cdot r_2) \backslash [c_1c_2] \big]= \simp \left[ ((r_1 \cdot r_2 )\backslash c_1) \backslash c_2 \right]$
110
Chengsong
parents: 109
diff changeset
  1354
\end{center}
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1355
\noindent
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1356
Again, using the properties above, we obtain
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1357
the following chain of equalities:
110
Chengsong
parents: 109
diff changeset
  1358
\begin{center}
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1359
$\simp(\rup \backslash s)= \simp \left[ ((r_1 \cdot r_2 )\backslash c_1) \backslash c_2 \right]= \simp\left[    \left(r_1 \backslash c_1\right) \cdot r_2  \big) \backslash c_2 \right]$\\
132
Chengsong
parents: 131
diff changeset
  1360
$= \simp \left[ \sum[\big( \left(r_1 \backslash c_1\right) \backslash c_2 \big) \cdot r_2 \; , \; \fuse \; (\bmkeps \;r_1\backslash c_1) \; r_2 \backslash c_2 ] \right]$,
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1361
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1362
\noindent
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1363
as before, we call the bitcode returned by 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1364
$\bmkeps(r_1\backslash c_1)$ as
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1365
$\textit{bs}_2$. 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1366
Also, $\simp(r_2 \backslash c_2)$ is 
132
Chengsong
parents: 131
diff changeset
  1367
$_{bs}\sum \textit{rs}_1$, 
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1368
and $( \left(r_1 \backslash c_1\right) \backslash c_2  \cdot r_2)$
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1369
simplifies to $\ZERO$,
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1370
so the above term can be expanded as
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1371
\begin{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1372
\begin{tabular}{l}
132
Chengsong
parents: 131
diff changeset
  1373
$\textit{distinct}(\flatten[\ZERO\;, \; _{\textit{bs}_2++\textit{bs}}\sum \textit{rs}_1] ) \; \textit{match} $ \\
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1374
  $\textit{case} \; [] \Rightarrow  \ZERO$ \\
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1375
   $\textit{case} \; a :: [] \Rightarrow  \textit{\fuse \; \textit{bs} a}$ \\
132
Chengsong
parents: 131
diff changeset
  1376
    $\textit{case} \;  as' \Rightarrow  _{[]}\sum as'$\\ 
110
Chengsong
parents: 109
diff changeset
  1377
\end{tabular}
Chengsong
parents: 109
diff changeset
  1378
\end{center}
Chengsong
parents: 109
diff changeset
  1379
\noindent
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1380
Applying the definition of $\flatten$, we get
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1381
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1382
$_{[]}\sum (\textit{map} \; \fuse (\textit{bs}_2 ++ bs) rs_1)$
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1383
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1384
\noindent
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1385
compared to the result 
110
Chengsong
parents: 109
diff changeset
  1386
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1387
$ \; _{bs_2++bs}{\sum \textit{rs}_1} $
110
Chengsong
parents: 109
diff changeset
  1388
\end{center}
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1389
\noindent
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1390
Note how these two regular expressions only
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1391
differ in terms of the position of the bits 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1392
$\textit{bs}_2++\textit{bs}$. They are the same otherwise.
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1393
What caused this difference to happen?
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1394
The culprit is the $\flatten$ function, which spills
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1395
out the bitcodes in the inner alternatives when 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1396
there exists an outer alternative.
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1397
Note how the absence of simplification
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1398
caused $\simp(\rup \backslash s)$ to
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1399
generate the nested alternatives structure:
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1400
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1401
$  \sum[\ZERO \;, \; _{bs}\sum \textit{rs} ]$
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1402
\end{center}
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1403
and this will always trigger the $\flatten$ to 
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1404
spill out the inner alternative's bitcode $\textit{bs}$,
111
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1405
whereas when
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1406
simplification is done along the way, 
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1407
the structure of nested alternatives is never created(we can
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1408
actually prove that simplification function never allows nested
af2c63f9bdf9 refined section a bit
Chengsong
parents: 110
diff changeset
  1409
alternatives to happen, more on this later).
110
Chengsong
parents: 109
diff changeset
  1410
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1411
How about we do not allow the function $\simp$
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1412
to fuse out the bits when it is unnecessary?
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1413
Like, for the above regular expression, we might
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1414
just delete the outer layer of alternative
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1415
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1416
\st{$ {\sum[\ZERO \;,}$} $_{bs}\sum \textit{rs}$ \st{$]$}
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1417
\end{center}
132
Chengsong
parents: 131
diff changeset
  1418
and get $_{bs}\sum \textit{rs}$ instead, without
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1419
fusing the bits $\textit{bs}$ inside to every element 
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1420
of $\textit{rs}$.
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1421
This idea can be realized by making the following
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1422
changes to the $\simp$-function:
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1423
\begin{center}
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1424
  \begin{tabular}{@{}lcl@{}}
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1425
   
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1426
  $\textit{simp}' \; (_{\textit{bs}}(a_1 \cdot a_2))$ & $\dn$ & $\textit{as} \; \simp \; \textit{was} \; \textit{before} $ \\
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1427
132
Chengsong
parents: 131
diff changeset
  1428
  $\textit{simp}' \; (_{bs}\sum as)$ & $\dn$ & \st{$\textit{distinct}( \textit{flatten} ( \textit{map simp as})) \; \textit{match} $} \\
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1429
  &&\st{$\quad\textit{case} \; [] \Rightarrow  \ZERO$} \\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1430
   &&\st{$\quad\textit{case} \; a :: [] \Rightarrow  \textit{fuse bs a}$} \\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1431
   &&\st{$\quad\textit{case} \;  as' \Rightarrow  \textit{ALTS}\;bs\;as'$}\\ 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1432
   &&$\textit{if}(\textit{hollowAlternatives}( \textit{map \; simp \; as}))$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1433
   &&$\textit{then} \; \fuse  \; \textit{bs}\; \textit{extractAlt}(\textit{map} \; \simp \; \textit{as} )$\\
132
Chengsong
parents: 131
diff changeset
  1434
   &&$\textit{else} \; \simp(_{bs} \sum \textit{as})$\\
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1435
   
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1436
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1437
   $\textit{simp}' \; a$ & $\dn$ & $\textit{a} \qquad \textit{otherwise}$   
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1438
\end{tabular}    
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1439
\end{center}    
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1440
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1441
\noindent
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1442
given the definition of $\textit{hollowAlternatives}$ and  $\textit{extractAlt}$ :
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1443
\begin{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1444
$\textit{hollowAlternatives}( \textit{rs}) \dn 
132
Chengsong
parents: 131
diff changeset
  1445
\exists r = (_{\textit{bs}_1}\sum \textit{rs}_1)  \in \textit{rs}.  \forall r' \in \textit{rs}, \;
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1446
\textit{either} \; r' = \ZERO \; \textit{or} \; r' = r $
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1447
$\textit{extractAlt}( \textit{rs}) \dn \textit{if}\big(
132
Chengsong
parents: 131
diff changeset
  1448
\exists r = (_{\textit{bs}_1}\sum \textit{rs}_1)  \in \textit{rs}.  \forall r' \in \textit{rs}, \;
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1449
\textit{either} \; r' = \ZERO \; \textit{or} \; r' = r \big)\; \textit{then} \; \textit{return} \; r$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1450
\end{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1451
\noindent
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1452
Basically, $\textit{hollowAlternatives}$ captures the feature of
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1453
a list of regular expression of the shape 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1454
\begin{center}
132
Chengsong
parents: 131
diff changeset
  1455
$  \sum[\ZERO \;, \; _{bs}\sum \textit{rs} ]$
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1456
\end{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1457
and this means we can simply elevate the 
132
Chengsong
parents: 131
diff changeset
  1458
inner regular expression $_{bs}\sum \textit{rs}$
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1459
 to the outmost
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1460
and throw away the useless $\ZERO$s and
132
Chengsong
parents: 131
diff changeset
  1461
the outer $\sum$ wrapper.
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1462
Using this new definition of simp, 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1463
under the example where  $r$ is the regular expression
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1464
$(a+b)(a+a*)$ and $s$  is the string $aa$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1465
the problem of $\rup\backslash_{simp} \, s \neq \simp(\rup\backslash s)$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1466
is resolved.
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1467
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1468
Unfortunately this causes new problems:
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1469
for the counterexample where 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1470
\begin{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1471
$r$ is the regular expression
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1472
$(ab+(a^*+aa))$ and $s$  is the string $aa$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1473
\end{center}
122
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1474
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1475
\noindent
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1476
$\rup\backslash_{simp} \, s$ is equal to 
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1477
$ _1(_{011}a^* +  _1\ONE)  $ whereas
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1478
$ \simp(\rup\backslash s) = (_{1011}a^* +  _{11}\ONE)$.
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1479
This discrepancy does not appear for the old
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1480
version of $\simp$.
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1481
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1482
Why?
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1483
135
Chengsong
parents: 134
diff changeset
  1484
We shall illustrate in detail  again of what happened in each recursive call of 
Chengsong
parents: 134
diff changeset
  1485
$\backslash$ and $\backslash_{simp}$.
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1486
During the first derivative operation, 
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1487
\begin{center}
135
Chengsong
parents: 134
diff changeset
  1488
$\rup\backslash a=(    _0[ \ONE\cdot {\bf b}] + _1( _0[ _1\ONE \cdot {\bf a}^*] + _1[ \ONE \cdot {\bf a}])      )$,
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1489
\end{center}
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1490
\noindent
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1491
 the second derivative gives us
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1492
 \begin{center}
135
Chengsong
parents: 134
diff changeset
  1493
$(\rup\backslash a)\backslash a=(_0( [\ZERO\cdot {\bf b}] + 0) + _1( _0( [\ZERO\cdot {\bf a}^*] + _1[ _1\ONE \cdot {\bf a}^*]) + _1( [\ZERO \cdot {\bf a}] + \ONE)  ))$,
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1494
\end{center}
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1495
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1496
\noindent
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1497
and this simplifies to
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1498
\begin{center}
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1499
$ _1(_{011}{\bf a}^* +  _1\ONE)  $ 
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1500
\end{center}
135
Chengsong
parents: 134
diff changeset
  1501
because when  $(\rup\backslash a)\backslash a$ goes 
Chengsong
parents: 134
diff changeset
  1502
through simplification, according to our new $\simp$
Chengsong
parents: 134
diff changeset
  1503
clause,
Chengsong
parents: 134
diff changeset
  1504
each component of the list
Chengsong
parents: 134
diff changeset
  1505
$[_0( [\ZERO\cdot {\bf b}] + 0) , _1( _0( [\ZERO\cdot {\bf a}^*] + _1[ _1\ONE \cdot {\bf a}^*]) + _1( [\ZERO \cdot {\bf a}] + \ONE)  )]$
Chengsong
parents: 134
diff changeset
  1506
is simplified into
Chengsong
parents: 134
diff changeset
  1507
$[\ZERO, _1(_{011}{\bf a}^* +  _1\ONE) ]$,
Chengsong
parents: 134
diff changeset
  1508
this fits into the definition of $\textit{hollowAlternatives}$,
Chengsong
parents: 134
diff changeset
  1509
so the structure of the annotated regular expression
Chengsong
parents: 134
diff changeset
  1510
\begin{center}
Chengsong
parents: 134
diff changeset
  1511
$_1(_{011}{\bf a}^* +  _1\ONE) $
Chengsong
parents: 134
diff changeset
  1512
\end{center}
Chengsong
parents: 134
diff changeset
  1513
is preserved, in the sense that the outside bit $_1$
Chengsong
parents: 134
diff changeset
  1514
is not fused inside.
125
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1515
If, after the first derivative we apply simplification we get
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1516
$(_0{\bf b}  + _{101}{\bf  a}^* + _{11}{\bf a}  )$,
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1517
and we do another derivative, getting
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1518
$(\ZERO  + (_{101}(\ONE \cdot _1{\bf a}^*)+_{11}\ONE)$,
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1519
which simplifies to 
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1520
\begin{center}
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1521
$ (_{1011}a^* +  _{11}\ONE)  $ 
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1522
\end{center}
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1523
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1524
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1525
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1526
788f4aa28bc5 added a bit?
Chengsong
parents: 123
diff changeset
  1527
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1528
We have changed the algorithm to avoid the old
122
dc0cdfc5fc66 version
Chengsong
parents: 121
diff changeset
  1529
counterexample, but this gives rise to new counterexamples.
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1530
This dilemma causes this amendment not a successful 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1531
attempt to make $\rup\backslash_{simp} \, s = \simp(\rup\backslash s)$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1532
under every possible regular expression and string.
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1533
\subsection{Properties of the Function $\simp$}
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1534
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1535
We have proved in Isabelle quite a few properties
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1536
of the $\simp$-function, which helps the proof to go forward
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1537
and we list them here to aid comprehension.
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1538
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1539
To start, we need a bit of auxiliary notations,
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1540
which is quite basic and is only written here
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1541
for clarity.
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1542
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1543
$\textit{sub}(r)$ computes the set of the 
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1544
sub-regular expression of $r$:
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1545
\begin{center}
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1546
$\textit{sub}(\ONE) \dn \{\ONE\}$\\
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1547
$\textit{sub}(r_1 \cdot r_2) \dn \textit{sub}(r_1) \cup \textit{sub}(r_2) \cup \{r_1 \cdot r_2\}$\\
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1548
$\textit{sub}(r_1 + r_2) \dn \textit{sub}(r_1) \cup \textit{sub}(r_2) \cup \{r_1+r_2\}$\\
113
8dbc83ecea3b test for talisker address change
Chengsong
parents: 112
diff changeset
  1549
\end{center}
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1550
$\textit{good}(r) \dn r \neq \ZERO \land \\
132
Chengsong
parents: 131
diff changeset
  1551
\forall r' \in \textit{sub}(r), \textit{if} \; r' = _{bs_1}\sum(rs_1), \;
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1552
\textit{then} \nexists r'' \in \textit{rs}_1 \; s.t.\;
132
Chengsong
parents: 131
diff changeset
  1553
r'' = _{bs_2}\sum \textit{rs}_2 $
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1554
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1555
The properties are mainly the ones below:
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1556
\begin{itemize}
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1557
\item
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1558
\begin{center}
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1559
$\simp(\simp(r)) = \simp(r)$
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1560
\end{center}
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1561
\item
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1562
\begin{center}
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1563
$\textit{if}\; r = \simp(r') \textit{then} \; \textit{good}(r) $
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1564
\end{center}
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1565
\end{itemize}
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1566
\subsection{The Contains relation}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1567
$\retrieve$ is a too strong relation in that
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1568
it only extracts one bitcode instead of a set of them.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1569
Therefore we try to define another relation(predicate)
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1570
to capture the fact the regular expression has bits
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1571
being moved around but still has all the bits needed.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1572
The contains symbol, written$\gg$, is  a relation that
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1573
takes two arguments in an infix form 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1574
and returns a truth value. 
112
c19f2d20d92c added section
Chengsong
parents: 111
diff changeset
  1575
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1576
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1577
In other words, from the set of regular expression and 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1578
bitcode pairs 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1579
$\textit{RV} = \{(r, v) \mid r \text{r is a regular expression, v is a value}\}$,
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1580
those that satisfy the following requirements are in the set
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1581
$\textit{RV}_Contains$.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1582
Unlike the $\retrieve$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1583
function, which takes two arguments $r$ and $v$ and 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1584
produces an only answer $\textit{bs}$, it takes only 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1585
one argument $r$ and returns a set of bitcodes that 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1586
can be generated by $r$.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1587
\begin{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1588
\begin{tabular}{llclll}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1589
& & & $_{bs}\ONE$ & $\gg$ & $\textit{bs}$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1590
& & & $_{bs}{\bf c}$ & $\gg$ & $\textit{bs}$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1591
$\textit{if} \; r_1 \gg \textit{bs}_1$ & $r_2 \; \gg \textit{bs}_2$ 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1592
& $\textit{then}$  &
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1593
 $_{bs}{r_1 \cdot r_2}$ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1594
 $\gg$ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1595
 $\textit{bs} @ \textit{bs}_1 @ \textit{bs}_2$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1596
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1597
 $\textit{if} \; r \gg \textit{bs}_1$ &  & $\textit{then}$  &
132
Chengsong
parents: 131
diff changeset
  1598
 $_{bs}{\sum(r :: \textit{rs}})$ & 
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1599
 $\gg$ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1600
 $\textit{bs} @ \textit{bs}_1 $\\ 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1601
132
Chengsong
parents: 131
diff changeset
  1602
 $\textit{if} \; _{bs}(\sum \textit{rs}) \gg \textit{bs} @ \textit{bs}_1$ &  & $\textit{then}$  &
Chengsong
parents: 131
diff changeset
  1603
 $_{bs}{\sum(r :: \textit{rs}})$ & 
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1604
 $\gg$ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1605
 $\textit{bs} @ \textit{bs}_1 $\\  
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1606
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1607
 $\textit{if} \; r \gg \textit{bs}_1\; \textit{and}$ &  $_{bs}r^* \gg \textit{bs} @ \textit{bs}_2$ & $\textit{then}$  &
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1608
 $_{bs}r^* $ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1609
 $\gg$ & 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1610
 $\textit{bs} @ [0] @ \textit{bs}_1@ \textit{bs}_2 $\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1611
 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1612
 & & & $_{bs}r^*$ & $\gg$ & $\textit{bs} @ [1]$\\
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1613
\end{tabular}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1614
\end{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1615
It is a predicate in the sense that given 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1616
a regular expression and a bitcode, it 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1617
returns true or false, depending on whether 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1618
or not the regular expression can actually produce that
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1619
value. If the predicates returns a true, then 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1620
we say that the regular expression $r$ contains
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1621
the bitcode $\textit{bs}$, written 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1622
$r \gg \textit{bs}$.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1623
The $\gg$ operator with the
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1624
regular expression $r$ may also be seen as a 
138
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1625
regular language by itself on the alphabet
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1626
$\Sigma = {0,1}$.
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1627
The definition of contains relation
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1628
is given in an inductive form, similar to that
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1629
of regular expressions, it might not be surprising 
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1630
that the set it denotes contains basically 
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1631
 everything a regular expression can 
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1632
produce during the derivative and lexing process.
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1633
This can be seen in the subsequent lemmas we have
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1634
proved about contains:
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1635
\begin{itemize}
eff05af278c0 contains
Chengsong
parents: 137
diff changeset
  1636
\item
139
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1637
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1638
\begin{equation}\label{contains1}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1639
\textit{if}\; \models v:r \; \textit{then} \; \rup \gg \textit{code}(v)
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1640
\end{equation}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1641
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1642
This lemma states that the set
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1643
$\{\textit{bs}\; | \rup \gg \textit{bs} \}$ 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1644
"contains" all the underlying value $v$ of $r$ in which they are 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1645
in a coded form.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1646
These values include the ones created in the 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1647
lexing process, for example, when the regular
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1648
expression $r$ is nullable, then we have:
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1649
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1650
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1651
$r \gg \textit{bmkeps}(r)$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1652
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1653
This can be seen as a corollary of the previous lemma,
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1654
because $\models \textit{mkeps}((r\downarrow)):(r\downarrow)$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1655
and $\textit{code}(\mkeps((r\downarrow))) = \bmkeps(r)$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1656
Another corollary we have of \eqref{contains1}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1657
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1658
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1659
$\textit{if}\; \models v:r \; \textit{then} \; \rup \gg \textit{retrieve} \; \rup \; v$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1660
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1661
as $\textit{retrieve} \; \rup \; v = \textit{code}(v)$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1662
It says that if you can extract a bitsequence using 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1663
retrieve guided by $v$, then such bitsequence is already there in the set 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1664
$\{\textit{bs}\; | \rup \gg \textit{bs} \}$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1665
This lemma has a slightly different form:
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1666
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1667
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1668
$\textit{if}\; \models v:a\downarrow \; \textit{then} \; a \gg \textit{retrieve} \; a \; v$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1669
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1670
This is almost identical to the previous lemma, except
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1671
this time we might have arbitrary bits attached 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1672
to anywhere of the annotated regular expression $a$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1673
$a$ can be any "made up" annotated regular expressions
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1674
that does not belong to the "natural" ones created by 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1675
internalising an unannotated regular expression.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1676
For example, a regular expression $r = (a+b)$ after internalisation
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1677
becomes $\rup = (_0a+_1b)$. For an underlying value $v = \Left(\Char(a))$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1678
we have $\retrieve \; (_0a+_1b) \;v = 0$ and $(_0a+_1b) \gg 0$. We could 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1679
attach arbitrary bits to the regular expression $\rup$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1680
without breaking the structure,
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1681
 for example  we could make up $a = _{0100111}(_{1011}a+1b)$,
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1682
 and we still have $\models v:a\downarrow$, and
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1683
 therefore  $a \gg \retrieve \; a \; v$, this time the bitsequence
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1684
 being $01001111011$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1685
This shows that the inductive clauses defining $\gg$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1686
simulates what $\retrieve$ does guided by different 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1687
values.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1688
Set $\{\textit{bs}\; | \rup \gg \textit{bs} \}$ contains
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1689
a wide range of values coded as bitsequences,
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1690
the following property can be routinely established 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1691
from the previous lemma
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1692
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1693
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1694
$r \gg \retrieve \; r \; (\inj \; (r\downarrow) \; c \; v) \;\;\; \textit{if} \; \models v: \textit{der} \; c \; (\erase(r))$
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1695
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1696
because $\inj \; (r\downarrow)\; c\; v$ is a value
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1697
underlying $r$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1698
Using this we can get something that looks much
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1699
less obvious:
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1700
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1701
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1702
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1703
\begin{tabular}{c}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1704
$\textit{if} \models v: \erase(r)\backslash c \; \textit{then}$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1705
$r\backslash c \gg \retrieve \; r \; (\inj \; (r\downarrow) \; c \; v) \; \textit{and}$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1706
$r \gg \retrieve \; r \; (\inj \; (r\downarrow) \; c \; v)$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1707
\end{tabular}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1708
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1709
It says that the derivative operation $\backslash c$ is basically
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1710
an operation that does not change the bits an annotated regular
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1711
expression is able to produce, both
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1712
$r\backslash c$ and $r$ can produce 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1713
the bitsequence $\inj \; (r\downarrow) \; c \;v)$.
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1714
This invariance with respect to derivative can be
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1715
further extended to a more surprising property:
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1716
\item
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1717
\begin{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1718
\begin{tabular}{c}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1719
$\textit{if} \models v: \erase(r) \backslash s$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1720
$r\backslash s \gg \retrieve \; r \; (\flex \; (r\downarrow) \; \textit{id} \; s \; v) \; \textit{and}$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1721
$r \gg \retrieve \; r \; (r\downarrow) \; \textit{id} \; s \; v) \; c \; v)$\\
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1722
\end{tabular}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1723
\end{center}
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1724
Here $\gg$ is almost like an $\textit{NFA}$ in the sense that 
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1725
it simulates the lexing process with respect to different strings.
140
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1726
139
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1727
Our hope is that using $\gg$ we can prove the bits
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1728
information are not lost when we simplify a regular expression.
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1729
So we need to relate $\gg$ with simplifcation, for example, 
139
13a42b418eab failsafe
Chengsong
parents: 138
diff changeset
  1730
one of the lemmas we have proved about $\gg$ is that
140
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1731
\item
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1732
\begin{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1733
$\simp \; a \gg \textit{bs} \iff  a \gg \textit{bs}$
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1734
\end{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1735
This could be a step towards our goal, as
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1736
it assures that after simplification none of the 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1737
bitsequence that can be created by
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1738
the original annotated regular expression
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1739
is lost.
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1740
If we could prove the following that would be
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1741
another step towards our proof, 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1742
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1743
\item
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1744
\begin{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1745
$(\simp \;a) \backslash s \gg \textit{bs} \iff  a\backslash s \gg \textit{bs}$
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1746
\end{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1747
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1748
as it says
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1749
the simplified regular expression after derivatives will 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1750
still have the full capacity of producing bitsequences
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1751
as the unsimplified ones-- pretty much
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1752
the intuition we try to establish.
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1753
And if we could prove
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1754
\item
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1755
\begin{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1756
$a \backslash s \gg \textit{bs} \iff  a\backslash_\textit{simp} s \gg \textit{bs}$
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1757
\end{center}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1758
That would be just a stone's throw away
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1759
from $\blexer \; r \; s = \blexers \; r \; s$.
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1760
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1761
\end{itemize}
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1762
What we do after we work out 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1763
the proof of the above lemma 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1764
is still not clear. It is one of the next steps we need to 
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1765
work on.
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1766
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1767
\subsection{The $\textit{ders}_2$ Function}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1768
If we want to prove the result 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1769
\begin{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1770
	$ \textit{blexer}\_{simp}(r, \; s) =  \textit{blexer}(r, \; s)$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1771
\end{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1772
inductively 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1773
on the structure of the regular expression,
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1774
then we need to induct on the  case $r_1 \cdot r_2$,
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1775
it can be good if we could express $(r_1 \cdot r_2) \backslash s$
140
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1776
in terms of $r_1 \backslash s_1$ and $r_2 \backslash s_1$,
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1777
where $s_1$ is a substring of $s$.
31711ca31685 contains section finished
Chengsong
parents: 139
diff changeset
  1778
For this we introduce the $\textit{ders2}$ function,
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1779
which does a "convolution" on $r_1$ and $r_2$ using the string
141
Chengsong
parents: 140
diff changeset
  1780
$s$. We omit the bits here as they are not affecting the 
Chengsong
parents: 140
diff changeset
  1781
structure of the regular expression, and we are mainly 
Chengsong
parents: 140
diff changeset
  1782
focusing on structure here.
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1783
It is based on the observation that the derivative of $r_1 \cdot r_2$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1784
with respect to a string $s$ can actually be written in an "explicit form"
141
Chengsong
parents: 140
diff changeset
  1785
composed of $r_1$ and $r_2$'s derivatives.
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1786
For example, we can look at how $r_1\cdot r_2$ expands
141
Chengsong
parents: 140
diff changeset
  1787
when being derived with a two-character string:
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1788
\begin{center}
141
Chengsong
parents: 140
diff changeset
  1789
\begin{tabular}{lcl}
Chengsong
parents: 140
diff changeset
  1790
	$ (r_1 \cdot r_2) \backslash [c_1c_2]$ & $=$ & $ (\textit{if} \; \nullable(r_1)\;  \textit{then} \; ((r_1 \backslash c_1) \cdot r_2 + r_2 \backslash c_1) \; \textit{else} \; (r_1\backslash c_1) \cdot r_2) \backslash c_2$\\
Chengsong
parents: 140
diff changeset
  1791
	& $=$ & $\textit{if} \; \textit{nullable}(r_1) \;\textit{and} \; \nullable(r_1\backslash c_1) \; \textit{then} \;
Chengsong
parents: 140
diff changeset
  1792
	(((r_1\backslash c_1c_2)\cdot r_2 +( r_1 \backslash c_1 )\cdot r_2\backslash c_2 )+ r_2 \backslash c_1c_2)$\\
Chengsong
parents: 140
diff changeset
  1793
	&& $\textit{else if} \; \nullable(r_1) \textit{and} \;\textit{not} \; \nullable(r_1 \backslash c_1)\; \textit{then} \;
Chengsong
parents: 140
diff changeset
  1794
	((r_1\backslash c_1c_2)\cdot r_2 + r_2 \backslash c_1c_2)$\\
Chengsong
parents: 140
diff changeset
  1795
	&& $\textit{else} \;(r_1\backslash c_1c_2) \cdot r_2$
Chengsong
parents: 140
diff changeset
  1796
\end{tabular}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1797
\end{center}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1798
which can also be written in a "convoluted sum"
141
Chengsong
parents: 140
diff changeset
  1799
format if we omit the order in which the alternatives
Chengsong
parents: 140
diff changeset
  1800
are being nested:
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1801
\begin{center}
141
Chengsong
parents: 140
diff changeset
  1802
\begin{tabular}{lcl}
Chengsong
parents: 140
diff changeset
  1803
	$(r_1 \cdot r_2) \backslash [c_1c_2] $ & $=$ & $\textit{if} \; \textit{nullable}(r_1) \;\textit{and} \; \nullable(r_1\backslash c_1) \; \textit{then} \;
Chengsong
parents: 140
diff changeset
  1804
	(r_1 \backslash c_1c_2) \cdot r_2 + (r_1 \backslash c_1)\cdot (r_2 \backslash c_2) + r_2 \backslash c_1c_2$\\
Chengsong
parents: 140
diff changeset
  1805
	&& $\textit{else if} \; \nullable(r_1) \textit{and} \;\textit{not} \; \nullable(r_1 \backslash c_1)\; \textit{then} \;
Chengsong
parents: 140
diff changeset
  1806
	((r_1\backslash c_1c_2)\cdot r_2 + r_2 \backslash c_1c_2)$\\
Chengsong
parents: 140
diff changeset
  1807
	&& $\textit{else} \;(r_1\backslash c_1c_2) \cdot r_2$\\
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1808
	& $=$ & $(r_1\backslash s) \cdot r_2 + \sum\limits_{s_j=c_2, c_1c_2 }{r_2 \backslash s_j} \; \text{where} \; \nullable(r_1\backslash s_i) \; \text{and} \;s_i @s_j = [c_1c_2]$
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1809
\end{tabular}
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1810
\end{center}
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1811
In a more general form, 
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1812
\begin{center}
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1813
\begin{tabular}{lcl}
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1814
	$(r_1 \cdot r_2) \backslash s $ & $=$ & $(r_1\backslash s) \cdot r_2 + \sum\limits_{s_i }{r_2 \backslash s_j} \; \text{where} \; s_i \; \text{is} \; \text{true prefix}\;  \text{of} \; s \;\text{and} \; s_i @s_j = s \; \text{and} \;\nullable(r_1\backslash s_i)$
141
Chengsong
parents: 140
diff changeset
  1815
\end{tabular}
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1816
\end{center}
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1817
We have formalized and proved the correctness of this 
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1818
alternative definition of derivative and call it $\textit{ders}_2$ to
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1819
make a distinction of it with the $\textit{ders}$-function.
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1820
Note this differentiates from the lexing algorithm  in the sense that
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1821
it calculates the results $r_1\backslash s_i , r_2 \backslash s_j$ first 
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1822
and then glue them together
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1823
into nested alternatives. 
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1824
$\lexer$, on the other hand, can only produce each element of the list
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1825
in the resulting alternatives regular expression 
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1826
altogether in the last derivative step.
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1827
$\lexer$ does lexing in a "breadth first" manner,
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1828
generating all the children nodes simultaneously
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1829
whereas
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1830
$\textit{ders}_2$ does it in a "depth first" manner.
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1831
Using this intuition we can also define the annotated regular expression version of 
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1832
derivative and call it $\textit{bders}_2$ and prove the equivalence with $\textit{bders}$.
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1833
Our hope is to use this alternative definition as a guide
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1834
for our induction.
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1835
Using $\textit{bders}_2$ we have a clearer idea
142
f2aa71c76cba filled ders2
Chengsong
parents: 141
diff changeset
  1836
of what $r\backslash s$ and $\simp(r\backslash s)$ looks like.
114
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1837
\section{Conclusion}
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1838
Under the exhaustive tests we believe the main
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1839
result holds, yet a proof still seems elusive.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1840
We have tried out different approaches, and 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1841
found a lot of properties of the function $\simp$.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1842
The counterexamples where $\rup\backslash_{simp} \, s \neq \simp(\rup\backslash s)$
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1843
are also valuable in the sense that 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1844
we get to know better why they are not equal and what 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1845
are the subtle differences between a 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1846
nested simplified regular expression and a 
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1847
regular expression that is simplified at the final moment.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1848
We are almost there, but a last step is needed to make the proof work.
dd7f719c451d avoid work loss
Chengsong
parents: 113
diff changeset
  1849
Hopefully in the next few weeks we will be able to find one.
145
a7c063981fa5 changes
Chengsong
parents: 144
diff changeset
  1850
This would be an important milestone for my dissertation.
94
Chengsong
parents:
diff changeset
  1851
148
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1852
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1853
\section{Future Plans}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1854
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1855
Before the proof comes out, a plan is needed to make 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1856
sure some progress is happening.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1857
We plan to get
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1858
a practical implementation of our current
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1859
method, which would involve  extending the set of allowed syntax
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1860
to include common regular expression constructs
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1861
such as bounded repitions, negation(complement) 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1862
and character range or even Boolean functions.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1863
Adding these concise way of expressing regular expressions
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1864
while keeping the correctness of the simplification
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1865
makes the work more practical.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1866
For example, using the added constructs we can 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1867
demonstrate that our implementation can actually 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1868
help the cloudflare web-application firewall
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1869
to run smoothly even if it had been fed with 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1870
evil regular expression 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1871
$.*(?:.*=.*)))$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1872
and strings like $x=xxxxxxxxxx....$.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1873
This could help prove that our algorithm is not just 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1874
some nice theory work but is actually competent in reality
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1875
as this regular expression and string pair made the cloudflare
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1876
servers to grind
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1877
to a halt on July 2nd, 2019.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1878
After all, simply the "basic" regular expressions
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1879
we gave in the introduction is really so basic, that
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1880
even Brzozowski's 1964 paper has included more 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1881
varieties than that(Boolean functions instead of 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1882
just alternatives)\cite{Brzozowski1964}.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1883
A function only implementing the basic ones
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1884
would lack practical interests.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1885
Making the algorithm practical also means to make it fast.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1886
Right now the Scala implementation
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1887
is slower than the naive algorithm without bitcodes, even with those
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1888
drastic simplification measures, which is not suggested by theory.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1889
We might need to implement it in other languages such as C
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1890
to see if the problem is language specific.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1891
This is about 3 months' work.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1892
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1893
We believe that there
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1894
is still potential for more simplification as there are a lot
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1895
of rules for regular expression similarity, however,
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1896
this needs to be explored and checked.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1897
Looking for maximal simplification and 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1898
best size bound and proving them would take around 3 months to complete.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1899
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1900
Context-free languages are a bit harder to deal with by derivatives
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1901
when compared with regular expressions.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1902
The main reason is that the child node of a context grammar
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1903
can be the grammar itself--this left-recursion makes 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1904
the computation procedure an impossibility when trying to solve directly.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1905
An example would be the following\cite{might2011cfgder}:
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1906
\begin{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1907
$L = L \cdot x | \ONE$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1908
\end{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1909
then a derivative would give us the following:
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1910
\begin{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1911
$L\backslash x = (L \backslash x)\cdot x | \ONE$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1912
\end{center}
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1913
which is essentially what we have previously.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1914
This recursion can go on forever if we do not use some 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1915
other methods such as introducing methods
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1916
or manually decide that the two equations 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1917
are actually equivalent and $L$ and $L\backslash x$
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1918
denote the same language. And then give a mathematical proof
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1919
that this is actually the case.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1920
This seems well beyond any mechanical algorithm one can 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1921
expect to be able to do.....
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1922
People have tried various ways to deal with the problems
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1923
of looping when computing derivatives of context-free grammars
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1924
such as memoization and laziness, with some degree of success\cite{might2011cfgder}.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1925
However this field seems largely unexplored and further 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1926
optimizations seem possible. It would be great
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1927
if we could find a simple augmentation to the current 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1928
derivative method so that the subset of context free language 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1929
of interest can be handled.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1930
This may take longer than the two previous tasks, but we still
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1931
give it 3 months time and see how it goes.
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1932
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1933
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1934
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1935
 
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1936
c8ef391dd6f7 vunsimp
Chengsong
parents: 145
diff changeset
  1937
94
Chengsong
parents:
diff changeset
  1938
\bibliographystyle{plain}
Chengsong
parents:
diff changeset
  1939
\bibliography{root}
Chengsong
parents:
diff changeset
  1940
Chengsong
parents:
diff changeset
  1941
Chengsong
parents:
diff changeset
  1942
\end{document}
118
c7825cfacc76 lualatex is probably the culprit
Chengsong
parents: 117
diff changeset
  1943