author | Chengsong |
Tue, 05 Jul 2022 00:42:06 +0100 | |
changeset 562 | 57e33978e55d |
parent 502 | 1ab693d6342f |
child 563 | c92a41d9c4da |
permissions | -rw-r--r-- |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
(*<*) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
theory Paper |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
imports |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
"Posix.FBound" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
"HOL-Library.LaTeXsugar" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
begin |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
declare [[show_question_marks = false]] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
notation (latex output) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
If ("(\<^latex>\<open>\\textrm{\<close>if\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textrm{\<close>then\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textrm{\<close>else\<^latex>\<open>}\<close> (_))" 10) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
Cons ("_\<^latex>\<open>\\mbox{$\\,$}\<close>::\<^latex>\<open>\\mbox{$\\,$}\<close>_" [75,73] 73) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
abbreviation |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
"der_syn r c \<equiv> der c r" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
abbreviation |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
"ders_syn r s \<equiv> ders s r" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
abbreviation |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
"bder_syn r c \<equiv> bder c r" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
notation (latex output) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
der_syn ("_\\_" [79, 1000] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
ders_syn ("_\\_" [79, 1000] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
bder_syn ("_\\_" [79, 1000] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
bders ("_\\_" [79, 1000] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
bders_simp ("_\\\<^sub>b\<^sub>s\<^sub>i\<^sub>m\<^sub>p _" [79, 1000] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
ZERO ("\<^bold>0" 81) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
ONE ("\<^bold>1" 81) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
CH ("_" [1000] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
ALT ("_ + _" [77,77] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
SEQ ("_ \<cdot> _" [77,77] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
STAR ("_\<^sup>*" [79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
val.Void ("Empty" 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
val.Char ("Char _" [1000] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
val.Left ("Left _" [79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
val.Right ("Right _" [1000] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
val.Seq ("Seq _ _" [79,79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
val.Stars ("Stars _" [79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
Prf ("\<turnstile> _ : _" [75,75] 75) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
Posix ("'(_, _') \<rightarrow> _" [63,75,75] 75) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
flat ("|_|" [75] 74) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
flats ("|_|" [72] 74) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
injval ("inj _ _ _" [79,77,79] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
mkeps ("mkeps _" [79] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
length ("len _" [73] 73) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
set ("_" [73] 73) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
AZERO ("ZERO" 81) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
AONE ("ONE _" [79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
ACHAR ("CHAR _ _" [79, 79] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
AALTs ("ALTs _ _" [77,77] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
ASEQ ("SEQ _ _ _" [79, 79,79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
ASTAR ("STAR _ _" [79, 79] 78) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
code ("code _" [79] 74) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
intern ("_\<^latex>\<open>\\mbox{$^\\uparrow$}\<close>" [900] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
erase ("_\<^latex>\<open>\\mbox{$^\\downarrow$}\<close>" [1000] 74) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
bnullable ("bnullable _" [1000] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
bsimp_AALTs ("bsimpALT _ _" [10,1000] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
bsimp_ASEQ ("bsimpSEQ _ _ _" [10,1000,1000] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
bmkeps ("bmkeps _" [1000] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
eq1 ("_ \<approx> _" [77,77] 76) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
srewrite ("_\<^latex>\<open>\\mbox{$\\,\\stackrel{s}{\\leadsto}$}\<close> _" [71, 71] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
rrewrites ("_ \<^latex>\<open>\\mbox{$\\,\\leadsto^*$}\<close> _" [71, 71] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
srewrites ("_ \<^latex>\<open>\\mbox{$\\,\\stackrel{s}{\\leadsto}^*$}\<close> _" [71, 71] 80) and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
blexer_simp ("blexer\<^sup>+" 1000) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
lemma better_retrieve: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
shows "rs \<noteq> Nil ==> retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
and "rs \<noteq> Nil ==> retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v" |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
apply (metis list.exhaust retrieve.simps(4)) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
by (metis list.exhaust retrieve.simps(5)) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
84 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
85 |
(*>*) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
86 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
87 |
section {* Introduction *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
88 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
89 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
90 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
91 |
In the last fifteen or so years, Brzozowski's derivatives of regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
92 |
expressions have sparked quite a bit of interest in the functional |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
93 |
programming and theorem prover communities. The beauty of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
94 |
Brzozowski's derivatives \cite{Brzozowski1964} is that they are neatly |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
95 |
expressible in any functional language, and easily definable and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
96 |
reasoned about in theorem provers---the definitions just consist of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
97 |
inductive datatypes and simple recursive functions. Derivatives of a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
98 |
regular expression, written @{term "der c r"}, give a simple solution |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
99 |
to the problem of matching a string @{term s} with a regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
100 |
expression @{term r}: if the derivative of @{term r} w.r.t.\ (in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
101 |
succession) all the characters of the string matches the empty string, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
102 |
then @{term r} matches @{term s} (and {\em vice versa}). We are aware |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
103 |
of a mechanised correctness proof of Brzozowski's derivative-based matcher in HOL4 by |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
Owens and Slind~\cite{Owens2008}. Another one in Isabelle/HOL is part |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
of the work by Krauss and Nipkow~\cite{Krauss2011}. And another one |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
in Coq is given by Coquand and Siles \cite{Coquand2012}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
Also Ribeiro and Du Bois give one in Agda~\cite{RibeiroAgda2017}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
However, there are two difficulties with derivative-based matchers: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
First, Brzozowski's original matcher only generates a yes/no answer |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
112 |
for whether a regular expression matches a string or not. This is too |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
little information in the context of lexing where separate tokens must |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
114 |
be identified and also classified (for example as keywords |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
115 |
or identifiers). Sulzmann and Lu~\cite{Sulzmann2014} overcome this |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
difficulty by cleverly extending Brzozowski's matching |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
algorithm. Their extended version generates additional information on |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
\emph{how} a regular expression matches a string following the POSIX |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
119 |
rules for regular expression matching. They achieve this by adding a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
120 |
second ``phase'' to Brzozowski's algorithm involving an injection |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
121 |
function. In our own earlier work we provided the formal |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
specification of what POSIX matching means and proved in Isabelle/HOL |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
the correctness |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
of Sulzmann and Lu's extended algorithm accordingly |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
\cite{AusafDyckhoffUrban2016}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
126 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
The second difficulty is that Brzozowski's derivatives can |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
grow to arbitrarily big sizes. For example if we start with the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
regular expression \mbox{@{text "(a + aa)\<^sup>*"}} and take |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
successive derivatives according to the character $a$, we end up with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
131 |
a sequence of ever-growing derivatives like |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
133 |
\def\ll{\stackrel{\_\backslash{} a}{\longrightarrow}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
\begin{tabular}{rll} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
$(a + aa)^*$ & $\ll$ & $(\ONE + \ONE{}a) \cdot (a + aa)^*$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
& $\ll$ & $(\ZERO + \ZERO{}a + \ONE) \cdot (a + aa)^* \;+\; (\ONE + \ONE{}a) \cdot (a + aa)^*$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
& $\ll$ & $(\ZERO + \ZERO{}a + \ZERO) \cdot (a + aa)^* + (\ONE + \ONE{}a) \cdot (a + aa)^* \;+\; $\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
& & $\qquad(\ZERO + \ZERO{}a + \ONE) \cdot (a + aa)^* + (\ONE + \ONE{}a) \cdot (a + aa)^*$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
& $\ll$ & \ldots \hspace{15mm}(regular expressions of sizes 98, 169, 283, 468, 767, \ldots) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
141 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
142 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
143 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
144 |
\noindent where after around 35 steps we run out of memory on a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
typical computer (we shall define shortly the precise details of our |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
146 |
regular expressions and the derivative operation). Clearly, the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
147 |
notation involving $\ZERO$s and $\ONE$s already suggests |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
148 |
simplification rules that can be applied to regular regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
149 |
expressions, for example $\ZERO{}\,r \Rightarrow \ZERO$, $\ONE{}\,r |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
150 |
\Rightarrow r$, $\ZERO{} + r \Rightarrow r$ and $r + r \Rightarrow |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
151 |
r$. While such simple-minded simplifications have been proved in our |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
152 |
earlier work to preserve the correctness of Sulzmann and Lu's |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
153 |
algorithm \cite{AusafDyckhoffUrban2016}, they unfortunately do |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
154 |
\emph{not} help with limiting the growth of the derivatives shown |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
155 |
above: the growth is slowed, but the derivatives can still grow rather |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
156 |
quickly beyond any finite bound. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
157 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
158 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
159 |
Sulzmann and Lu overcome this ``growth problem'' in a second algorithm |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
160 |
\cite{Sulzmann2014} where they introduce bitcoded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
161 |
regular expressions. In this version, POSIX values are |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
162 |
represented as bitsequences and such sequences are incrementally generated |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
163 |
when derivatives are calculated. The compact representation |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
164 |
of bitsequences and regular expressions allows them to define a more |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
165 |
``aggressive'' simplification method that keeps the size of the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
166 |
derivatives finitely bounded no matter what the length of the string is. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
167 |
They make some informal claims about the correctness and linear behaviour |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
168 |
of this version, but do not provide any supporting proof arguments, not |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
169 |
even ``pencil-and-paper'' arguments. They write about their bitcoded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
170 |
\emph{incremental parsing method} (that is the algorithm to be formalised |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
171 |
in this paper): |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
172 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
173 |
\begin{quote}\it |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
174 |
``Correctness Claim: We further claim that the incremental parsing |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
175 |
method [..] in combination with the simplification steps [..] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
176 |
yields POSIX parse trees. We have tested this claim |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
177 |
extensively [..] but yet |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
178 |
have to work out all proof details.'' \cite[Page 14]{Sulzmann2014} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
179 |
\end{quote} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
180 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
181 |
\noindent{}\textbf{Contributions:} We have implemented in Isabelle/HOL |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
182 |
the derivative-based lexing algorithm of Sulzmann and Lu |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
183 |
\cite{Sulzmann2014} where regular expressions are annotated with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
184 |
bitsequences. We define the crucial simplification function as a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
185 |
recursive function, without the need of a fix-point operation. One objective of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
186 |
the simplification function is to remove duplicates of regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
187 |
expressions. For this Sulzmann and Lu use in their paper the standard |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
188 |
@{text nub} function from Haskell's list library, but this function |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
189 |
does not achieve the intended objective with bitcoded regular expressions. The |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
190 |
reason is that in the bitcoded setting, each copy generally has a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
191 |
different bitcode annotation---so @{text nub} would never ``fire''. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
192 |
Inspired by Scala's library for lists, we shall instead use a @{text |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
193 |
distinctWith} function that finds duplicates under an ``erasing'' function |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
194 |
which deletes bitcodes before comparing regular expressions. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
195 |
We shall also introduce our own argument and definitions for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
196 |
establishing the correctness of the bitcoded algorithm when |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
197 |
simplifications are included. Finally we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
198 |
establish that the size of derivatives can be finitely bounded.\medskip%\footnote{ In this paper, we shall first briefly introduce the basic notions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
199 |
%of regular expressions and describe the definition |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
200 |
%of POSIX lexing from our earlier work \cite{AusafDyckhoffUrban2016}. This serves |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
201 |
%as a reference point for what correctness means in our Isabelle/HOL proofs. We shall then prove |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
202 |
%the correctness for the bitcoded algorithm without simplification, and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
203 |
%after that extend the proof to include simplification.}\smallskip |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
204 |
%\mbox{}\\[-10mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
205 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
206 |
\noindent In this paper, we shall first briefly introduce the basic notions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
207 |
of regular expressions and describe the definition |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
208 |
of POSIX lexing from our earlier work \cite{AusafDyckhoffUrban2016}. This serves |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
209 |
as a reference point for what correctness means in our Isabelle/HOL proofs. We shall then prove |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
210 |
the correctness for the bitcoded algorithm without simplification, and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
211 |
after that extend the proof to include simplification.\mbox{}\\[-6mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
212 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
213 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
214 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
215 |
section {* Background *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
216 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
217 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
218 |
In our Isabelle/HOL formalisation strings are lists of characters with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
219 |
the empty string being represented by the empty list, written $[]$, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
220 |
and list-cons being written as $\_\!::\!\_\,$; string |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
221 |
concatenation is $\_ \,@\, \_\,$. We often use the usual |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
222 |
bracket notation for lists also for strings; for example a string |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
223 |
consisting of just a single character $c$ is written $[c]$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
224 |
Our regular expressions are defined as usual as the following inductive |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
225 |
datatype:\\[-4mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
226 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
227 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
228 |
@{text "r ::="} \; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
229 |
@{const "ZERO"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
230 |
@{const "ONE"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
231 |
@{term "CH c"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
232 |
@{term "ALT r\<^sub>1 r\<^sub>2"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
233 |
@{term "SEQ r\<^sub>1 r\<^sub>2"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
234 |
@{term "STAR r"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
235 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
236 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
237 |
\noindent where @{const ZERO} stands for the regular expression that does |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
238 |
not match any string, @{const ONE} for the regular expression that matches |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
239 |
only the empty string and @{term c} for matching a character literal. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
240 |
The constructors $+$ and $\cdot$ represent alternatives and sequences, respectively. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
241 |
We sometimes omit the $\cdot$ in a sequence regular expression for brevity. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
242 |
The |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
243 |
\emph{language} of a regular expression, written $L(r)$, is defined as usual |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
244 |
and we omit giving the definition here (see for example \cite{AusafDyckhoffUrban2016}). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
245 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
246 |
Central to Brzozowski's regular expression matcher are two functions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
247 |
called @{text nullable} and \emph{derivative}. The latter is written |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
248 |
$r\backslash c$ for the derivative of the regular expression $r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
249 |
w.r.t.~the character $c$. Both functions are defined by recursion over |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
250 |
regular expressions. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
251 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
252 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
253 |
\begin{tabular}{cc} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
254 |
\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
255 |
@{thm (lhs) der.simps(1)} & $\dn$ & @{thm (rhs) der.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
256 |
@{thm (lhs) der.simps(2)} & $\dn$ & @{thm (rhs) der.simps(2)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
257 |
@{thm (lhs) der.simps(3)} & $\dn$ & @{thm (rhs) der.simps(3)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
258 |
@{thm (lhs) der.simps(4)[of c "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) der.simps(4)[of c "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
259 |
@{thm (lhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{text "if"} @{term "nullable(r\<^sub>1)"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
260 |
& & @{text "then"} @{term "ALT (SEQ (der c r\<^sub>1) r\<^sub>2) (der c r\<^sub>2)"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
261 |
& & @{text "else"} @{term "SEQ (der c r\<^sub>1) r\<^sub>2"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
262 |
% & & @{thm (rhs) der.simps(5)[of c "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
263 |
@{thm (lhs) der.simps(6)} & $\dn$ & @{thm (rhs) der.simps(6)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
264 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
265 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
266 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
267 |
@{thm (lhs) nullable.simps(1)} & $\dn$ & @{thm (rhs) nullable.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
268 |
@{thm (lhs) nullable.simps(2)} & $\dn$ & @{thm (rhs) nullable.simps(2)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
269 |
@{thm (lhs) nullable.simps(3)} & $\dn$ & @{thm (rhs) nullable.simps(3)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
270 |
@{thm (lhs) nullable.simps(4)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) nullable.simps(4)[of "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
271 |
@{thm (lhs) nullable.simps(5)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) nullable.simps(5)[of "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
272 |
@{thm (lhs) nullable.simps(6)} & $\dn$ & @{thm (rhs) nullable.simps(6)}%\medskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
273 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
274 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
275 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
276 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
277 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
278 |
We can extend this definition to give derivatives w.r.t.~strings, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
279 |
namely @{thm (lhs) ders.simps(1)}$\dn$@{thm (rhs) ders.simps(1)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
280 |
and @{thm (lhs) ders.simps(2)}$\dn$@{thm (rhs) ders.simps(2)}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
281 |
Using @{text nullable} and the derivative operation, we can |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
282 |
define a simple regular expression matcher, namely |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
283 |
$@{text "match s r"} \;\dn\; @{term nullable}(r\backslash s)$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
284 |
This is essentially Brzozowski's algorithm from 1964. Its |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
285 |
main virtue is that the algorithm can be easily implemented as a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
286 |
functional program (either in a functional programming language or in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
287 |
a theorem prover). The correctness of @{text match} amounts to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
288 |
establishing the property:%\footnote{It is a fun exercise to formally prove this property in a theorem prover.} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
289 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
290 |
\begin{proposition}\label{matchcorr} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
291 |
@{text "match s r"} \;\;\text{if and only if}\;\; $s \in L(r)$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
292 |
\end{proposition} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
293 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
294 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
295 |
It is a fun exercise to formally prove this property in a theorem prover. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
296 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
297 |
The novel idea of Sulzmann and Lu is to extend this algorithm for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
298 |
lexing, where it is important to find out which part of the string |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
299 |
is matched by which part of the regular expression. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
300 |
For this Sulzmann and Lu presented two lexing algorithms in their paper |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
301 |
\cite{Sulzmann2014}. The first algorithm consists of two phases: first a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
302 |
matching phase (which is Brzozowski's algorithm) and then a value |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
303 |
construction phase. The values encode \emph{how} a regular expression |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
304 |
matches a string. \emph{Values} are defined as the inductive datatype |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
305 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
306 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
307 |
@{text "v ::="} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
308 |
@{const "Void"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
309 |
@{term "val.Char c"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
310 |
@{term "Left v"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
311 |
@{term "Right v"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
312 |
@{term "Seq v\<^sub>1 v\<^sub>2"} $\mid$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
313 |
@{term "Stars vs"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
314 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
315 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
316 |
\noindent where we use @{term vs} to stand for a list of values. The |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
317 |
string underlying a value can be calculated by a @{const flat} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
318 |
function, written @{term "flat DUMMY"}. It traverses a value and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
319 |
collects the characters contained in it \cite{AusafDyckhoffUrban2016}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
320 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
321 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
322 |
Sulzmann and Lu also define inductively an |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
323 |
inhabitation relation that associates values to regular expressions. This |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
324 |
is defined by the following six rules for the values: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
325 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
326 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
327 |
\begin{tabular}{@ {\hspace{-12mm}}c@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
328 |
\begin{tabular}{@ {}c@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
329 |
\\[-8mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
330 |
@{thm[mode=Axiom] Prf.intros(4)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
331 |
@{thm[mode=Axiom] Prf.intros(5)[of "c"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
332 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
333 |
\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
334 |
@{thm[mode=Rule] Prf.intros(2)[of "v\<^sub>1" "r\<^sub>1" "r\<^sub>2"]}\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
335 |
@{thm[mode=Rule] Prf.intros(3)[of "v\<^sub>2" "r\<^sub>2" "r\<^sub>1"]}\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
336 |
@{thm[mode=Rule] Prf.intros(1)[of "v\<^sub>1" "r\<^sub>1" "v\<^sub>2" "r\<^sub>2"]}\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
337 |
@{thm[mode=Rule] Prf.intros(6)[of "vs" "r"]}\mbox{}\hspace{-10mm}\mbox{} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
338 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
339 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
340 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
341 |
\noindent Note that no values are associated with the regular expression |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
342 |
@{term ZERO}, since it cannot match any string. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
343 |
It is routine to establish how values ``inhabiting'' a regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
344 |
expression correspond to the language of a regular expression, namely |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
345 |
@{thm L_flat_Prf}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
346 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
347 |
In general there is more than one value inhabited by a regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
348 |
expression (meaning regular expressions can typically match more |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
349 |
than one string). But even when fixing a string from the language of the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
350 |
regular expression, there are generally more than one way of how the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
351 |
regular expression can match this string. POSIX lexing is about |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
352 |
identifying the unique value for a given regular expression and a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
353 |
string that satisfies the informal POSIX rules (see |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
354 |
\cite{POSIX,Kuklewicz,OkuiSuzuki2010,Sulzmann2014,Vansummeren2006}). |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
355 |
%\footnote{POSIX |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
356 |
% lexing acquired its name from the fact that the corresponding |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
357 |
% rules were described as part of the POSIX specification for |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
358 |
% Unix-like operating systems \cite{POSIX}.} |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
359 |
Sometimes these |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
360 |
informal rules are called \emph{maximal munch rule} and \emph{rule priority}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
361 |
One contribution of our earlier paper is to give a convenient |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
362 |
specification for what POSIX values are (the inductive rules are shown in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
363 |
Figure~\ref{POSIXrules}). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
364 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
365 |
\begin{figure}[t] |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
366 |
\begin{center}\small% |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
367 |
\begin{tabular}{@ {}c@ {}} |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
368 |
\\[-9mm] |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
369 |
@{thm[mode=Axiom] Posix.intros(1)}\<open>P\<close>@{term "ONE"} \quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
370 |
@{thm[mode=Axiom] Posix.intros(2)}\<open>P\<close>@{term "c"}\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
371 |
@{thm[mode=Rule] Posix.intros(3)[of "s" "r\<^sub>1" "v" "r\<^sub>2"]}\<open>P+L\<close>\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
372 |
@{thm[mode=Rule] Posix.intros(4)[of "s" "r\<^sub>2" "v" "r\<^sub>1"]}\<open>P+R\<close>\medskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
373 |
$\mprset{flushleft} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
374 |
\inferrule |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
375 |
{@{thm (prem 1) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
376 |
@{thm (prem 2) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]} \\\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
377 |
@{thm (prem 3) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
378 |
{@{thm (concl) Posix.intros(5)[of "s\<^sub>1" "r\<^sub>1" "v\<^sub>1" "s\<^sub>2" "r\<^sub>2" "v\<^sub>2"]}}$\<open>PS\<close>\medskip\smallskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
379 |
@{thm[mode=Axiom] Posix.intros(7)}\<open>P[]\<close>\qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
380 |
$\mprset{flushleft} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
381 |
\inferrule |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
382 |
{@{thm (prem 1) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
383 |
@{thm (prem 2) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
384 |
@{thm (prem 3) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]} \\\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
385 |
@{thm (prem 4) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
386 |
{@{thm (concl) Posix.intros(6)[of "s\<^sub>1" "r" "v" "s\<^sub>2" "vs"]}}$\<open>P\<star>\<close>\\[-4mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
387 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
388 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
389 |
\caption{The inductive definition of POSIX values taken from our earlier paper \cite{AusafDyckhoffUrban2016}. The ternary relation, written $(s, r) \rightarrow v$, formalises the notion |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
390 |
of given a string $s$ and a regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
391 |
expression $r$ what is the unique value $v$ that satisfies the informal POSIX constraints for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
392 |
regular expression matching.}\label{POSIXrules} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
393 |
\end{figure} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
394 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
395 |
The clever idea by Sulzmann and Lu \cite{Sulzmann2014} in their first algorithm is to define |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
396 |
an injection function on values that mirrors (but inverts) the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
397 |
construction of the derivative on regular expressions. Essentially it |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
398 |
injects back a character into a value. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
399 |
For this they define two functions called @{text mkeps} and @{text inj}: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
400 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
401 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
402 |
\begin{tabular}{@ {}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
403 |
\begin{tabular}{@ {}lcl@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
404 |
@{thm (lhs) mkeps.simps(1)} & $\dn$ & @{thm (rhs) mkeps.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
405 |
@{thm (lhs) mkeps.simps(2)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) mkeps.simps(2)[of "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
406 |
@{thm (lhs) mkeps.simps(3)[of "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & @{thm (rhs) mkeps.simps(3)[of "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
407 |
@{thm (lhs) mkeps.simps(4)} & $\dn$ & @{thm (rhs) mkeps.simps(4)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
408 |
\end{tabular}\smallskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
409 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
410 |
\begin{tabular}{@ {}cc@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
411 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
412 |
@{thm (lhs) injval.simps(1)} & $\dn$ & @{thm (rhs) injval.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
413 |
@{thm (lhs) injval.simps(2)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1"]} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
414 |
@{thm (rhs) injval.simps(2)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
415 |
@{thm (lhs) injval.simps(3)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
416 |
@{thm (rhs) injval.simps(3)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
417 |
@{thm (lhs) injval.simps(7)[of "r" "c" "v" "vs"]} & $\dn$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
418 |
& @{thm (rhs) injval.simps(7)[of "r" "c" "v" "vs"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
419 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
420 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
421 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
422 |
@{thm (lhs) injval.simps(4)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]} & $\dn$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
423 |
& @{thm (rhs) injval.simps(4)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
424 |
@{thm (lhs) injval.simps(5)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]} & $\dn$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
425 |
& @{thm (rhs) injval.simps(5)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>1" "v\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
426 |
@{thm (lhs) injval.simps(6)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]} & $\dn$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
427 |
\multicolumn{3}{@ {}r@ {}}{@{thm (rhs) injval.simps(6)[of "r\<^sub>1" "r\<^sub>2" "c" "v\<^sub>2"]}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
428 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
429 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
430 |
\end{tabular}\smallskip |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
431 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
432 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
433 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
434 |
The function @{text mkeps} is run when the last derivative is nullable, that is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
435 |
the string to be matched is in the language of the regular expression. It generates |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
436 |
a value for how the last derivative can match the empty string. The injection function |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
437 |
then calculates the corresponding value for each intermediate derivative until |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
438 |
a value for the original regular expression is generated. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
439 |
Graphically the algorithm by |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
440 |
Sulzmann and Lu can be illustrated by the following picture %in Figure~\ref{Sulz} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
441 |
where the path from the left to the right involving @{term derivatives}/@{const |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
442 |
nullable} is the first phase of the algorithm (calculating successive |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
443 |
\Brz's derivatives) and @{const mkeps}/@{text inj}, the path from right to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
444 |
left, the second phase. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
445 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
446 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
447 |
\begin{tikzpicture}[scale=0.99,node distance=9mm, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
448 |
every node/.style={minimum size=6mm}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
449 |
\node (r1) {@{term "r\<^sub>1"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
450 |
\node (r2) [right=of r1]{@{term "r\<^sub>2"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
451 |
\draw[->,line width=1mm](r1)--(r2) node[above,midway] {@{term "der a DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
452 |
\node (r3) [right=of r2]{@{term "r\<^sub>3"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
453 |
\draw[->,line width=1mm](r2)--(r3) node[above,midway] {@{term "der b DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
454 |
\node (r4) [right=of r3]{@{term "r\<^sub>4"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
455 |
\draw[->,line width=1mm](r3)--(r4) node[above,midway] {@{term "der c DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
456 |
\draw (r4) node[anchor=west] {\;\raisebox{3mm}{@{term nullable}}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
457 |
\node (v4) [below=of r4]{@{term "v\<^sub>4"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
458 |
\draw[->,line width=1mm](r4) -- (v4); |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
459 |
\node (v3) [left=of v4] {@{term "v\<^sub>3"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
460 |
\draw[->,line width=1mm](v4)--(v3) node[below,midway] {\<open>inj r\<^sub>3 c\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
461 |
\node (v2) [left=of v3]{@{term "v\<^sub>2"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
462 |
\draw[->,line width=1mm](v3)--(v2) node[below,midway] {\<open>inj r\<^sub>2 b\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
463 |
\node (v1) [left=of v2] {@{term "v\<^sub>1"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
464 |
\draw[->,line width=1mm](v2)--(v1) node[below,midway] {\<open>inj r\<^sub>1 a\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
465 |
\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{@{term "mkeps"}}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
466 |
\end{tikzpicture} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
467 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
468 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
469 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
470 |
The picture shows the steps required when a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
471 |
regular expression, say @{text "r\<^sub>1"}, matches the string @{term |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
472 |
"[a,b,c]"}. The first lexing algorithm by Sulzmann and Lu can be defined as:%\\[-8mm] |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
473 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
474 |
% \begin{figure}[t] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
475 |
%\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
476 |
%\begin{tikzpicture}[scale=1,node distance=1cm, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
477 |
% every node/.style={minimum size=6mm}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
478 |
%\node (r1) {@{term "r\<^sub>1"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
479 |
%\node (r2) [right=of r1]{@{term "r\<^sub>2"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
480 |
%\draw[->,line width=1mm](r1)--(r2) node[above,midway] {@{term "der a DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
481 |
%\node (r3) [right=of r2]{@{term "r\<^sub>3"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
482 |
%\draw[->,line width=1mm](r2)--(r3) node[above,midway] {@{term "der b DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
483 |
%\node (r4) [right=of r3]{@{term "r\<^sub>4"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
484 |
%\draw[->,line width=1mm](r3)--(r4) node[above,midway] {@{term "der c DUMMY"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
485 |
%\draw (r4) node[anchor=west] {\;\raisebox{3mm}{@{term nullable}}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
486 |
%\node (v4) [below=of r4]{@{term "v\<^sub>4"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
487 |
%\draw[->,line width=1mm](r4) -- (v4); |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
488 |
%\node (v3) [left=of v4] {@{term "v\<^sub>3"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
489 |
%\draw[->,line width=1mm](v4)--(v3) node[below,midway] {\<open>inj r\<^sub>3 c\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
490 |
%\node (v2) [left=of v3]{@{term "v\<^sub>2"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
491 |
%\draw[->,line width=1mm](v3)--(v2) node[below,midway] {\<open>inj r\<^sub>2 b\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
492 |
%\node (v1) [left=of v2] {@{term "v\<^sub>1"}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
493 |
%\draw[->,line width=1mm](v2)--(v1) node[below,midway] {\<open>inj r\<^sub>1 a\<close>}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
494 |
%\draw (r4) node[anchor=north west] {\;\raisebox{-8mm}{@{term "mkeps"}}}; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
495 |
%\end{tikzpicture} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
496 |
%\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
497 |
%\mbox{}\\[-13mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
498 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
499 |
%\caption{The two phases of the first algorithm by Sulzmann \& Lu \cite{Sulzmann2014}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
500 |
%matching the string @{term "[a,b,c]"}. The first phase (the arrows from |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
501 |
%left to right) is \Brz's matcher building successive derivatives. If the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
502 |
%last regular expression is @{term nullable}, then the functions of the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
503 |
%second phase are called (the top-down and right-to-left arrows): first |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
504 |
%@{term mkeps} calculates a value @{term "v\<^sub>4"} witnessing |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
505 |
%how the empty string has been recognised by @{term "r\<^sub>4"}. After |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
506 |
%that the function @{term inj} ``injects back'' the characters of the string into |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
507 |
%the values. The value @{term "v\<^sub>1"} is the result of the algorithm representing |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
508 |
%the POSIX value for this string and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
509 |
%regular expression. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
510 |
%\label{Sulz}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
511 |
%\end{figure} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
512 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
513 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
514 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
515 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
516 |
\begin{tabular}{lcl} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
517 |
@{thm (lhs) lexer.simps(1)} & $\dn$ & @{thm (rhs) lexer.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
518 |
@{thm (lhs) lexer.simps(2)} & $\dn$ & @{text "case"} @{term "lexer (der c r) s"} @{text of} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
519 |
@{term "None"} @{text "\<Rightarrow>"} @{term None}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
520 |
& & \hspace{24mm}$|\;$ @{term "Some v"} @{text "\<Rightarrow>"} @{term "Some (injval r c v)"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
521 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
522 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
523 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
524 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
525 |
We have shown in our earlier paper \cite{AusafDyckhoffUrban2016} that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
526 |
this algorithm is correct, that is it generates POSIX values. The |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
527 |
central property we established relates the derivative operation to the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
528 |
injection function. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
529 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
530 |
\begin{proposition}\label{Posix2} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
531 |
\textit{If} $(s,\; r\backslash c) \rightarrow v$ \textit{then} $(c :: s,\; r) \rightarrow$ \textit{inj} $r\; c\; v$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
532 |
\end{proposition} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
533 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
534 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
535 |
With this in place we were able to prove: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
536 |
|
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
537 |
\begin{proposition}\mbox{}\label{lexercorrect} |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
538 |
\textrm{(1)} @{thm (lhs) lexer_correct_None} if and only if @{thm (rhs) lexer_correct_None}.\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
539 |
\mbox{\hspace{29mm}}\textrm{(2)}\; @{thm (lhs) lexer_correct_Some} if and only if @{thm (rhs) lexer_correct_Some}. |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
540 |
% |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
541 |
% \smallskip\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
542 |
%\begin{tabular}{ll} |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
543 |
%(1) & @{thm (lhs) lexer_correct_None} if and only if @{thm (rhs) lexer_correct_None}\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
544 |
%(2) & @{thm (lhs) lexer_correct_Some} if and only if @{thm (rhs) lexer_correct_Some}\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
545 |
%\end{tabular} |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
546 |
\end{proposition} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
547 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
548 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
549 |
In fact we have shown that, in the success case, the generated POSIX value $v$ is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
550 |
unique and in the failure case that there is no POSIX value $v$ that satisfies |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
551 |
$(s, r) \rightarrow v$. While the algorithm is correct, it is excruciatingly |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
552 |
slow in cases where the derivatives grow arbitrarily (recall the example from the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
553 |
Introduction). However it can be used as a convenient reference point for the correctness |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
554 |
proof of the second algorithm by Sulzmann and Lu, which we shall describe next. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
555 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
556 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
557 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
558 |
section {* Bitcoded Regular Expressions and Derivatives *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
559 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
560 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
561 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
562 |
In the second part of their paper \cite{Sulzmann2014}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
563 |
Sulzmann and Lu describe another algorithm that also generates POSIX |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
564 |
values but dispenses with the second phase where characters are |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
565 |
injected ``back'' into values. For this they annotate bitcodes to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
566 |
regular expressions, which we define in Isabelle/HOL as the datatype |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
567 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
568 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
569 |
@{term breg} $\;::=\;$ @{term "AZERO"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
570 |
$\;\mid\;$ @{term "AONE bs"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
571 |
$\;\mid\;$ @{term "ACHAR bs c"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
572 |
$\;\mid\;$ @{term "AALTs bs rs"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
573 |
$\;\mid\;$ @{term "ASEQ bs r\<^sub>1 r\<^sub>2"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
574 |
$\;\mid\;$ @{term "ASTAR bs r"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
575 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
576 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
577 |
\noindent where @{text bs} stands for bitsequences; @{text r}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
578 |
@{text "r\<^sub>1"} and @{text "r\<^sub>2"} for bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
579 |
expressions; and @{text rs} for lists of bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
580 |
expressions. The binary alternative @{text "ALT bs r\<^sub>1 r\<^sub>2"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
581 |
is just an abbreviation for \mbox{@{text "ALTs bs [r\<^sub>1, r\<^sub>2]"}}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
582 |
For bitsequences we use lists made up of the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
583 |
constants @{text Z} and @{text S}. The idea with bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
584 |
expressions is to incrementally generate the value information (for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
585 |
example @{text Left} and @{text Right}) as bitsequences. For this |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
586 |
Sulzmann and Lu define a coding |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
587 |
function for how values can be coded into bitsequences. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
588 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
589 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
590 |
\begin{tabular}{cc} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
591 |
\begin{tabular}{lcl} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
592 |
@{thm (lhs) code.simps(1)} & $\dn$ & @{thm (rhs) code.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
593 |
@{thm (lhs) code.simps(2)} & $\dn$ & @{thm (rhs) code.simps(2)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
594 |
@{thm (lhs) code.simps(3)} & $\dn$ & @{thm (rhs) code.simps(3)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
595 |
@{thm (lhs) code.simps(4)} & $\dn$ & @{thm (rhs) code.simps(4)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
596 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
597 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
598 |
\begin{tabular}{lcl} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
599 |
@{thm (lhs) code.simps(5)[of "v\<^sub>1" "v\<^sub>2"]} & $\dn$ & @{thm (rhs) code.simps(5)[of "v\<^sub>1" "v\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
600 |
@{thm (lhs) code.simps(6)} & $\dn$ & @{thm (rhs) code.simps(6)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
601 |
@{thm (lhs) code.simps(7)} & $\dn$ & @{thm (rhs) code.simps(7)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
602 |
\mbox{\phantom{XX}}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
603 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
604 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
605 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
606 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
607 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
608 |
As can be seen, this coding is ``lossy'' in the sense that we do not |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
609 |
record explicitly character values and also not sequence values (for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
610 |
them we just append two bitsequences). However, the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
611 |
different alternatives for @{text Left}, respectively @{text Right}, are recorded as @{text Z} and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
612 |
@{text S} followed by some bitsequence. Similarly, we use @{text Z} to indicate |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
613 |
if there is still a value coming in the list of @{text Stars}, whereas @{text S} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
614 |
indicates the end of the list. The lossiness makes the process of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
615 |
decoding a bit more involved, but the point is that if we have a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
616 |
regular expression \emph{and} a bitsequence of a corresponding value, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
617 |
then we can always decode the value accurately (see Fig.~\ref{decode}). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
618 |
The function \textit{decode} checks whether all of the bitsequence is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
619 |
consumed and returns the corresponding value as @{term "Some v"}; otherwise |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
620 |
it fails with @{text "None"}. We can establish that for a value $v$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
621 |
inhabited by a regular expression $r$, the decoding of its |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
622 |
bitsequence never fails. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
623 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
624 |
%The decoding can be |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
625 |
%defined by using two functions called $\textit{decode}'$ and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
626 |
%\textit{decode}: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
627 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
628 |
\begin{figure} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
629 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
630 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
631 |
\multicolumn{3}{@ {}l}{$\textit{decode}'\,bs\,(\ONE)$ $\;\dn\;$ $(\Empty, bs)$ \quad\qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
632 |
$\textit{decode}'\,bs\,(c)$ $\;\dn\;$ $(\Char\,c, bs)$}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
633 |
$\textit{decode}'\,(\Z\!::\!bs)\;(r_1 + r_2)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
634 |
$\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r_1\;\textit{in}\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
635 |
(\Left\,v, bs_1)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
636 |
$\textit{decode}'\,(\S\!::\!bs)\;(r_1 + r_2)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
637 |
$\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r_2\;\textit{in}\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
638 |
(\Right\,v, bs_1)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
639 |
$\textit{decode}'\,bs\;(r_1\cdot r_2)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
640 |
$\textit{let}\,(v_1, bs_1) = \textit{decode}'\,bs\,r_1\;\textit{in}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
641 |
& & $\textit{let}\,(v_2, bs_2) = \textit{decode}'\,bs_1\,r_2$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
642 |
\hspace{2mm}$\textit{in}\;(\Seq\,v_1\,v_2, bs_2)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
643 |
$\textit{decode}'\,(\Z\!::\!bs)\,(r^*)$ & $\dn$ & $(\Stars\,[], bs)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
644 |
$\textit{decode}'\,(\S\!::\!bs)\,(r^*)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
645 |
$\textit{let}\,(v, bs_1) = \textit{decode}'\,bs\,r\;\textit{in}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
646 |
& & $\textit{let}\,(\Stars\,vs, bs_2) = \textit{decode}'\,bs_1\,r^*$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
647 |
\hspace{2mm}$\textit{in}\;(\Stars\,v\!::\!vs, bs_2)$\medskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
648 |
\multicolumn{3}{l}{$\textit{decode}\,bs\,r$ $\dn$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
649 |
$\textit{let}\,(v, bs') = \textit{decode}'\,bs\,r\;\textit{in}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
650 |
$\;\,\textit{if}\;bs' = []\;\textit{then}\;\textit{Some}\,v\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
651 |
\textit{else}\;\textit{None}$}\\[-4mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
652 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
653 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
654 |
\caption{Two functions, called $\textit{decode}'$ and \textit{decode}, for decoding a value from a bitsequence with the help of a regular expression.\\[-5mm]}\label{decode} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
655 |
\end{figure} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
656 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
657 |
%\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
658 |
%The function \textit{decode} checks whether all of the bitsequence is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
659 |
%consumed and returns the corresponding value as @{term "Some v"}; otherwise |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
660 |
%it fails with @{text "None"}. We can establish that for a value $v$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
661 |
%inhabited by a regular expression $r$, the decoding of its |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
662 |
%bitsequence never fails. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
663 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
664 |
\begin{lemma}\label{codedecode}\it |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
665 |
If $\;\vdash v : r$ then |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
666 |
$\;\textit{decode}\,(\textit{code}\, v)\,r = \textit{Some}\, v$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
667 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
668 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
669 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
670 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
671 |
Sulzmann and Lu define the function \emph{internalise} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
672 |
in order to transform (standard) regular expressions into annotated |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
673 |
regular expressions. We write this operation as $r^\uparrow$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
674 |
This internalisation uses the following |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
675 |
\emph{fuse} function. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
676 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
677 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
678 |
\begin{tabular}{@ {}cc@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
679 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
680 |
$\textit{fuse}\,bs\,(\textit{ZERO})$ & $\dn$ & $\textit{ZERO}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
681 |
$\textit{fuse}\,bs\,(\textit{ONE}\,bs')$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
682 |
$\textit{ONE}\,(bs\,@\,bs')$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
683 |
$\textit{fuse}\,bs\,(\textit{CHAR}\,bs'\,c)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
684 |
$\textit{CHAR}\,(bs\,@\,bs')\,c$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
685 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
686 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
687 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
688 |
$\textit{fuse}\,bs\,(\textit{ALTs}\,bs'\,rs)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
689 |
$\textit{ALTs}\,(bs\,@\,bs')\,rs$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
690 |
$\textit{fuse}\,bs\,(\textit{SEQ}\,bs'\,r_1\,r_2)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
691 |
$\textit{SEQ}\,(bs\,@\,bs')\,r_1\,r_2$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
692 |
$\textit{fuse}\,bs\,(\textit{STAR}\,bs'\,r)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
693 |
$\textit{STAR}\,(bs\,@\,bs')\,r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
694 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
695 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
696 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
697 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
698 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
699 |
A regular expression can then be \emph{internalised} into a bitcoded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
700 |
regular expression as follows: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
701 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
702 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
703 |
\begin{tabular}{@ {}ccc@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
704 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
705 |
$(\ZERO)^\uparrow$ & $\dn$ & $\textit{ZERO}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
706 |
$(\ONE)^\uparrow$ & $\dn$ & $\textit{ONE}\,[]$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
707 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
708 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
709 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
710 |
$(c)^\uparrow$ & $\dn$ & $\textit{CHAR}\,[]\,c$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
711 |
$(r^*)^\uparrow$ & $\dn$ & $\textit{STAR}\;[]\,r^\uparrow$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
712 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
713 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
714 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
715 |
$(r_1 + r_2)^\uparrow$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
716 |
$\textit{ALT}\;[]\,(\textit{fuse}\,[\Z]\,r_1^\uparrow)\, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
717 |
(\textit{fuse}\,[\S]\,r_2^\uparrow)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
718 |
$(r_1\cdot r_2)^\uparrow$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
719 |
$\textit{SEQ}\;[]\,r_1^\uparrow\,r_2^\uparrow$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
720 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
721 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
722 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
723 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
724 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
725 |
There is also an \emph{erase}-function, written $r^\downarrow$, which |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
726 |
transforms a bitcoded regular expression into a (standard) regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
727 |
expression by just erasing the annotated bitsequences. We omit the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
728 |
straightforward definition. For defining the algorithm, we also need |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
729 |
the functions \textit{bnullable} and \textit{bmkeps}(\textit{s}), which are the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
730 |
``lifted'' versions of \textit{nullable} and \textit{mkeps} acting on |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
731 |
bitcoded regular expressions. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
732 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
733 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
734 |
\begin{tabular}{@ {}c@ {\hspace{2mm}}c@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
735 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
736 |
$\textit{bnullable}\,(\textit{ZERO})$ & $\dn$ & $\textit{False}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
737 |
$\textit{bnullable}\,(\textit{ONE}\,bs)$ & $\dn$ & $\textit{True}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
738 |
$\textit{bnullable}\,(\textit{CHAR}\,bs\,c)$ & $\dn$ & $\textit{False}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
739 |
$\textit{bnullable}\,(\textit{ALTs}\,bs\,\rs)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
740 |
$\exists\, r \in \rs. \,\textit{bnullable}\,r$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
741 |
$\textit{bnullable}\,(\textit{SEQ}\,bs\,r_1\,r_2)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
742 |
$\textit{bnullable}\,r_1\wedge \textit{bnullable}\,r_2$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
743 |
$\textit{bnullable}\,(\textit{STAR}\,bs\,r)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
744 |
$\textit{True}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
745 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
746 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
747 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
748 |
$\textit{bmkeps}\,(\textit{ONE}\,bs)$ & $\dn$ & $bs$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
749 |
$\textit{bmkeps}\,(\textit{ALTs}\,bs\,\rs)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
750 |
$bs\,@\,\textit{bmkepss}\,\rs$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
751 |
$\textit{bmkeps}\,(\textit{SEQ}\,bs\,r_1\,r_2)$ & $\dn$ &\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
752 |
\multicolumn{3}{r}{$bs \,@\,\textit{bmkeps}\,r_1\,@\, \textit{bmkeps}\,r_2$}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
753 |
$\textit{bmkeps}\,(\textit{STAR}\,bs\,r)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
754 |
$bs \,@\, [\S]$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
755 |
$\textit{bmkepss}\,(r\!::\!\rs)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
756 |
$\textit{if}\;\textit{bnullable}\,r$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
757 |
& &$\textit{then}\;\textit{bmkeps}\,r$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
758 |
& &$\textit{else}\;\textit{bmkepss}\,\rs$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
759 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
760 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
761 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
762 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
763 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
764 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
765 |
The key function in the bitcoded algorithm is the derivative of a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
766 |
bitcoded regular expression. This derivative function calculates the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
767 |
derivative but at the same time also the incremental part of the bitsequences |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
768 |
that contribute to constructing a POSIX value. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
769 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
770 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
771 |
\begin{tabular}{@ {}lcl@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
772 |
\multicolumn{3}{@ {}l}{$(\textit{ZERO})\backslash c$ $\;\dn\;$ $\textit{ZERO}$ \quad\qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
773 |
$(\textit{ONE}\;bs)\backslash c$ $\;\dn\;$ $\textit{ZERO}$}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
774 |
$(\textit{CHAR}\;bs\,d)\backslash c$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
775 |
$\textit{if}\;c=d\; \;\textit{then}\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
776 |
\textit{ONE}\;bs\;\textit{else}\;\textit{ZERO}$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
777 |
$(\textit{ALTs}\;bs\,\rs)\backslash c$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
778 |
$\textit{ALTs}\,bs\,(\mathit{map}\,(\_\backslash c)\,\rs)$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
779 |
$(\textit{SEQ}\;bs\,r_1\,r_2)\backslash c$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
780 |
$\textit{if}\;\textit{bnullable}\,r_1$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
781 |
& &$\textit{then}\;\textit{ALT}\,bs\;(\textit{SEQ}\,[]\,(r_1\backslash c)\,r_2)$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
782 |
$\;(\textit{fuse}\,(\textit{bmkeps}\,r_1)\,(r_2\backslash c))$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
783 |
& &$\textit{else}\;\textit{SEQ}\,bs\,(r_1\backslash c)\,r_2$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
784 |
$(\textit{STAR}\,bs\,r)\backslash c$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
785 |
$\textit{SEQ}\;bs\,(\textit{fuse}\, [\Z] (r\backslash c))\, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
786 |
(\textit{STAR}\,[]\,r)$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
787 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
788 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
789 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
790 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
791 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
792 |
This function can also be extended to strings, written $r\backslash s$, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
793 |
just like the standard derivative. We omit the details. Finally we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
794 |
can define Sulzmann and Lu's bitcoded lexer, which we call \textit{blexer}: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
795 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
796 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
797 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
798 |
$\textit{blexer}\;r\,s$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
799 |
$\textit{let}\;r_{der} = (r^\uparrow)\backslash s\;\textit{in}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
800 |
$\;\;\textit{if}\; \textit{bnullable}(r_{der}) \;\;\textit{then}\;\textit{decode}\,(\textit{bmkeps}\,r_{der})\,r |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
801 |
\;\;\textit{else}\;\textit{None}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
802 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
803 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
804 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
805 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
806 |
This bitcoded lexer first internalises the regular expression $r$ and then |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
807 |
builds the bitcoded derivative according to $s$. If the derivative is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
808 |
(b)nullable the string is in the language of $r$ and it extracts the bitsequence using the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
809 |
$\textit{bmkeps}$ function. Finally it decodes the bitsequence into a value. If |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
810 |
the derivative is \emph{not} nullable, then $\textit{None}$ is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
811 |
returned. We can show that this way of calculating a value |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
812 |
generates the same result as \textit{lexer}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
813 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
814 |
Before we can proceed we need to define a helper function, called |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
815 |
\textit{retrieve}, which Sulzmann and Lu introduced for the correctness proof. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
816 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
817 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
818 |
\begin{tabular}{lcl} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
819 |
@{thm (lhs) retrieve.simps(1)} & $\dn$ & @{thm (rhs) retrieve.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
820 |
@{thm (lhs) retrieve.simps(2)} & $\dn$ & @{thm (rhs) retrieve.simps(2)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
821 |
@{thm (lhs) retrieve.simps(3)} & $\dn$ & @{thm (rhs) retrieve.simps(3)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
822 |
@{thm (lhs) better_retrieve(1)} & $\dn$ & @{thm (rhs) better_retrieve(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
823 |
@{thm (lhs) better_retrieve(2)} & $\dn$ & @{thm (rhs) better_retrieve(2)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
824 |
@{thm (lhs) retrieve.simps(6)[of _ "r\<^sub>1" "r\<^sub>2" "v\<^sub>1" "v\<^sub>2"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
825 |
& $\dn$ & @{thm (rhs) retrieve.simps(6)[of _ "r\<^sub>1" "r\<^sub>2" "v\<^sub>1" "v\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
826 |
@{thm (lhs) retrieve.simps(7)} & $\dn$ & @{thm (rhs) retrieve.simps(7)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
827 |
@{thm (lhs) retrieve.simps(8)} & $\dn$ & @{thm (rhs) retrieve.simps(8)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
828 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
829 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
830 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
831 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
832 |
The idea behind this function is to retrieve a possibly partial |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
833 |
bitsequence from a bitcoded regular expression, where the retrieval is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
834 |
guided by a value. For example if the value is $\Left$ then we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
835 |
descend into the left-hand side of an alternative in order to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
836 |
assemble the bitcode. Similarly for |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
837 |
$\Right$. The property we can show is that for a given $v$ and $r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
838 |
with $\vdash v : r$, the retrieved bitsequence from the internalised |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
839 |
regular expression is equal to the bitcoded version of $v$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
840 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
841 |
\begin{lemma}\label{retrievecode} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
842 |
If $\vdash v : r$ then $\textit{code}\, v = \textit{retrieve}\,(r^\uparrow)\,v$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
843 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
844 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
845 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
846 |
We also need some auxiliary facts about how the bitcoded operations |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
847 |
relate to the ``standard'' operations on regular expressions. For |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
848 |
example if we build a bitcoded derivative and erase the result, this |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
849 |
is the same as if we first erase the bitcoded regular expression and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
850 |
then perform the ``standard'' derivative operation. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
851 |
|
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
852 |
\begin{lemma}\label{bnullable}%\mbox{}\smallskip\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
853 |
\textit{(1)} $(r\backslash s)^\downarrow = (r^\downarrow)\backslash s$\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
854 |
\mbox{\hspace{22mm}}\textit{(2)} $\textit{bnullable}(r)$ iff $\textit{nullable}(r^\downarrow)$\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
855 |
\mbox{\hspace{22mm}}\textit{(3)} $\textit{bmkeps}(r) = \textit{retrieve}\,r\,(\textit{mkeps}\,(r^\downarrow))$ provided $\textit{nullable}(r^\downarrow)$ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
856 |
%\begin{tabular}{ll} |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
857 |
%\textit{(1)} & $(r\backslash s)^\downarrow = (r^\downarrow)\backslash s$\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
858 |
%\textit{(2)} & $\textit{bnullable}(r)$ iff $\textit{nullable}(r^\downarrow)$\\ |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
859 |
%\textit{(3)} & $\textit{bmkeps}(r) = \textit{retrieve}\,r\,(\textit{mkeps}\,(r^\downarrow))$ provided $\textit{nullable}(r^\downarrow)$. |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
860 |
%\end{tabular} |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
861 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
862 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
863 |
%\begin{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
864 |
% All properties are by induction on annotated regular expressions. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
865 |
% %There are no interesting cases. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
866 |
%\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
867 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
868 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
869 |
The only difficulty left for the correctness proof is that the bitcoded algorithm |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
870 |
has only a ``forward phase'' where POSIX values are generated incrementally. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
871 |
We can achieve the same effect with @{text lexer} (which has two phases) by stacking up injection |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
872 |
functions during the forward phase. An auxiliary function, called $\textit{flex}$, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
873 |
allows us to recast the rules of $\lexer$ in terms of a single |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
874 |
phase and stacked up injection functions. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
875 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
876 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
877 |
\begin{tabular}{@ {}l@ {}c@ {}l@ {\hspace{10mm}}l@ {}c@ {}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
878 |
$\textit{flex}\;r\,f\,[]$ & $\dn$ & $f$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
879 |
$\textit{flex}\;r\,f\,(c\!::\!s)$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
880 |
$\textit{flex}\,(r\backslash c)\,(\lambda v.\,f\,(\inj\,r\,c\,v))\,s$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
881 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
882 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
883 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
884 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
885 |
The point of this function is that when |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
886 |
reaching the end of the string, we just need to apply the stacked up |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
887 |
injection functions to the value generated by @{text mkeps}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
888 |
Using this function we can recast the success case in @{text lexer} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
889 |
as follows: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
890 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
891 |
\begin{lemma}\label{flex} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
892 |
If @{text "lexer r s = Some v"} \;then\; @{text "v = "}$\,\textit{flex}\,r\,id\,s\, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
893 |
(\mkeps (r\backslash s))$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
894 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
895 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
896 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
897 |
Note we did not redefine \textit{lexer}, we just established that the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
898 |
value generated by \textit{lexer} can also be obtained by a different |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
899 |
method. While this different method is not efficient (we essentially |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
900 |
need to traverse the string $s$ twice, once for building the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
901 |
derivative $r\backslash s$ and another time for stacking up injection |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
902 |
functions), it helps us with proving |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
903 |
that incrementally building up values in @{text blexer} generates the same result. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
904 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
905 |
This brings us to our main lemma in this section: if we calculate a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
906 |
derivative, say $r\backslash s$, and have a value, say $v$, inhabited |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
907 |
by this derivative, then we can produce the result @{text lexer} generates |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
908 |
by applying this value to the stacked-up injection functions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
909 |
that $\textit{flex}$ assembles. The lemma establishes that this is the same |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
910 |
value as if we build the annotated derivative $r^\uparrow\backslash s$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
911 |
and then retrieve the corresponding bitcoded version, followed by a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
912 |
decoding step. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
913 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
914 |
\begin{lemma}[Main Lemma]\label{mainlemma}\it |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
915 |
If $\vdash v : r\backslash s$ then |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
916 |
$\textit{Some}\,(\textit{flex}\,r\,\textit{id}\,s\,v) = |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
917 |
\textit{decode}(\textit{retrieve}\,(r^\uparrow \backslash s)\,v)\,r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
918 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
919 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
920 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
921 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
922 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
923 |
%With this lemma in place, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
924 |
We can then prove the correctness of \textit{blexer}---it indeed |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
925 |
produces the same result as \textit{lexer}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
926 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
927 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
928 |
\begin{theorem}\label{thmone} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
929 |
$\textit{lexer}\,r\,s = \textit{blexer}\,r\,s$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
930 |
\end{theorem} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
931 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
932 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
933 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
934 |
\noindent This establishes that the bitcoded algorithm \emph{without} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
935 |
simplification produces correct results. This was |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
936 |
only conjectured by Sulzmann and Lu in their paper |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
937 |
\cite{Sulzmann2014}. The next step is to add simplifications. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
938 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
939 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
940 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
941 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
942 |
section {* Simplification *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
943 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
944 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
945 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
946 |
Derivatives as calculated by Brzozowski’s method are usually more |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
947 |
complex regular expressions than the initial one; the result is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
948 |
that derivative-based matching and lexing algorithms are |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
949 |
often abysmally slow if the ``growth problem'' is not addressed. As Sulzmann and Lu wrote, various |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
950 |
optimisations are possible, such as the simplifications |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
951 |
$\ZERO{}\,r \Rightarrow \ZERO$, $\ONE{}\,r \Rightarrow r$, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
952 |
$\ZERO{} + r \Rightarrow r$ and $r + r \Rightarrow r$. While these |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
953 |
simplifications can considerably speed up the two algorithms in many |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
954 |
cases, they do not solve fundamentally the growth problem with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
955 |
derivatives. To see this let us return to the example from the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
956 |
Introduction that shows the derivatives for \mbox{@{text "(a + aa)\<^sup>*"}}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
957 |
If we delete in the 3rd step all $\ZERO{}s$ and $\ONE$s according to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
958 |
the simplification rules shown above we obtain |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
959 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
960 |
%% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
961 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
962 |
\begin{equation}\def\xll{\xrightarrow{\_\backslash{} [a, a, a]}}\label{derivex} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
963 |
(a + aa)^* \quad\xll\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
964 |
\underbrace{\mbox{$(\ONE + a) \cdot (a + aa)^*$}}_{r} \;+\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
965 |
((a + aa)^* + \underbrace{\mbox{$(\ONE + a) \cdot (a + aa)^*$}}_{r}) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
966 |
\end{equation} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
967 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
968 |
\noindent This is a simpler derivative, but unfortunately we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
969 |
cannot make any further simplifications. This is a problem because |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
970 |
the outermost alternatives contains two copies of the same |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
971 |
regular expression (underlined with $r$). These copies will |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
972 |
spawn new copies in later derivative steps and they in turn even more copies. This |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
973 |
destroys any hope of taming the size of the derivatives. But the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
974 |
second copy of $r$ in \eqref{derivex} will never contribute to a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
975 |
value, because POSIX lexing will always prefer matching a string |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
976 |
with the first copy. So it could be safely removed without affecting the correctness of the algorithm. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
977 |
The dilemma with the simple-minded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
978 |
simplification rules above is that the rule $r + r \Rightarrow r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
979 |
will never be applicable because as can be seen in this example the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
980 |
regular expressions are not next to each other but separated by another regular expression. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
981 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
982 |
But here is where Sulzmann and Lu's representation of generalised |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
983 |
alternatives in the bitcoded algorithm shines: in @{term |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
984 |
"ALTs bs rs"} we can define a more aggressive simplification by |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
985 |
recursively simplifying all regular expressions in @{text rs} and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
986 |
then analyse the resulting list and remove any duplicates. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
987 |
Another advantage with the bitsequences in bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
988 |
expressions is that they can be easily modified such that simplification does not |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
989 |
interfere with the value constructions. For example we can ``flatten'', or |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
990 |
de-nest, or spill out, @{text ALTs} as follows |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
991 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
992 |
\[ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
993 |
@{term "ALTs bs\<^sub>1 ((ALTs bs\<^sub>2 rs\<^sub>2) # rs\<^sub>1)"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
994 |
\quad\xrightarrow{bsimp}\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
995 |
@{term "ALTs bs\<^sub>1 ((map (fuse bs\<^sub>2) rs\<^sub>2) # rs\<^sub>1)"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
996 |
\] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
997 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
998 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
999 |
where we just need to fuse the bitsequence that has accumulated in @{text "bs\<^sub>2"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1000 |
to the alternatives in @{text "rs\<^sub>2"}. As we shall show below this will |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1001 |
ensure that the correct value corresponding to the original (unsimplified) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1002 |
regular expression can still be extracted. %In this way the value construction |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1003 |
%is not affected by simplification. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1004 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1005 |
However there is one problem with the definition for the more |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1006 |
aggressive simplification rules described by Sulzmann and Lu. Recasting |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1007 |
their definition with our syntax they define the step of removing |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1008 |
duplicates as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1009 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1010 |
\[ @{text "bsimp (ALTs bs rs)"} \dn @{text "ALTs |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1011 |
bs (nub (map bsimp rs))"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1012 |
\] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1013 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1014 |
\noindent where they first recursively simplify the regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1015 |
expressions in @{text rs} (using @{text map}) and then use |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1016 |
Haskell's @{text nub}-function to remove potential |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1017 |
duplicates. While this makes sense when considering the example |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1018 |
shown in \eqref{derivex}, @{text nub} is the inappropriate |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1019 |
function in the case of bitcoded regular expressions. The reason |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1020 |
is that in general the elements in @{text rs} will have a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1021 |
different annotated bitsequence and in this way @{text nub} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1022 |
will never find a duplicate to be removed. One correct way to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1023 |
handle this situation is to first \emph{erase} the regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1024 |
expressions when comparing potential duplicates. This is inspired |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1025 |
by Scala's list functions of the form \mbox{@{text "distinctWith rs eq |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1026 |
acc"}} where @{text eq} is an user-defined equivalence relation that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1027 |
compares two elements in @{text rs}. We define this function in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1028 |
Isabelle/HOL as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1029 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1030 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1031 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1032 |
@{thm (lhs) distinctWith.simps(1)} & $\dn$ & @{thm (rhs) distinctWith.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1033 |
@{thm (lhs) distinctWith.simps(2)} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1034 |
@{text "if (\<exists> y \<in> acc. eq x y)"} & @{text "then distinctWith xs eq acc"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1035 |
& & & @{text "else x :: distinctWith xs eq ({x} \<union> acc)"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1036 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1037 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1038 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1039 |
\noindent where we scan the list from left to right (because we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1040 |
have to remove later copies). In @{text distinctWith}, @{text eq} is intended to be an |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1041 |
equivalence relation for annotated regular expressions and @{text acc} is an accumulator for annotated regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1042 |
expressions---essentially a set of regular expressions that we have already seen |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1043 |
while scanning the list. Therefore we delete an element, say @{text x}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1044 |
from the list provided a @{text "y"} with @{text "y"} being equivalent to @{text x} is already in the accumulator; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1045 |
otherwise we keep @{text x} and scan the rest of the list but |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1046 |
add @{text "x"} as another ``seen'' element to @{text acc}. We will use |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1047 |
@{term distinctWith} where @{text eq} is an equivalence that deletes bitsequences from bitcoded regular expressions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1048 |
before comparing the components. One way to define this in Isabelle/HOL is by the following recursive function from |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1049 |
annotated regular expressions to @{text bool}: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1050 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1051 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1052 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1053 |
@{thm (lhs) eq1.simps(1)} & $\dn$ & @{thm (rhs) eq1.simps(1)}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1054 |
@{thm (lhs) eq1.simps(2)[of DUMMY DUMMY]} & $\dn$ & @{thm (rhs) eq1.simps(2)[of DUMMY DUMMY]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1055 |
@{thm (lhs) eq1.simps(3)[of DUMMY "c" DUMMY "d"]} & $\dn$ & @{thm (rhs) eq1.simps(3)[of DUMMY "c" DUMMY "d"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1056 |
@{thm (lhs) eq1.simps(4)[of DUMMY "r\<^sub>1\<^sub>1" "r\<^sub>1\<^sub>2" DUMMY "r\<^sub>2\<^sub>1" "r\<^sub>2\<^sub>2"]} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1057 |
@{thm (rhs) eq1.simps(4)[of DUMMY "r\<^sub>1\<^sub>1" "r\<^sub>1\<^sub>2" DUMMY "r\<^sub>2\<^sub>1" "r\<^sub>2\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1058 |
@{thm (lhs) eq1.simps(5)[of DUMMY DUMMY]} & $\dn$ & @{thm (rhs) eq1.simps(5)[of DUMMY DUMMY]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1059 |
@{thm (lhs) eq1.simps(6)[of DUMMY "r\<^sub>1" "rs\<^sub>1" DUMMY "r\<^sub>2" "rs\<^sub>2"]} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1060 |
@{thm (rhs) eq1.simps(6)[of DUMMY "r\<^sub>1" "rs\<^sub>1" DUMMY "r\<^sub>2" "rs\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1061 |
@{thm (lhs) eq1.simps(7)[of DUMMY "r\<^sub>1" DUMMY "r\<^sub>2"]} & $\dn$ & @{thm (rhs) eq1.simps(7)[of DUMMY "r\<^sub>1" DUMMY "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1062 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1063 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1064 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1065 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1066 |
where all other cases are set to @{text False}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1067 |
This equivalence is clearly a computationally more expensive operation than @{text nub}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1068 |
but is needed in order to make the removal of unnecessary copies |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1069 |
to work properly. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1070 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1071 |
Our simplification function depends on three more helper functions, one is called |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1072 |
@{text flts} and analyses lists of regular expressions coming from alternatives. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1073 |
It is defined as follows: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1074 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1075 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1076 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1077 |
\multicolumn{3}{@ {}c}{@{thm (lhs) flts.simps(1)} $\dn$ @{thm (rhs) flts.simps(1)} \qquad\qquad\qquad\qquad |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1078 |
@{thm (lhs) flts.simps(2)} $\dn$ @{thm (rhs) flts.simps(2)}}\\ |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1079 |
@{thm (lhs) flts.simps(3)[of "bs'" "rs'"]} & $\dn$ & @{thm (rhs) flts.simps(3)[of "bs'" "rs'"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1080 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1081 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1082 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1083 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1084 |
The second clause of @{text flts} removes all instances of @{text ZERO} in alternatives and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1085 |
the third ``de-nests'' alternatives (but retaining the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1086 |
bitsequence @{text "bs'"} accumulated in the inner alternative). There are |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1087 |
some corner cases to be considered when the resulting list inside an alternative is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1088 |
empty or a singleton list. We take care of those cases in the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1089 |
@{text "bsimpALTs"} function; similarly we define a helper function that simplifies |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1090 |
sequences according to the usual rules about @{text ZERO}s and @{text ONE}s: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1091 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1092 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1093 |
\begin{tabular}{c@ {\hspace{5mm}}c} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1094 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1095 |
@{text "bsimpALTs bs []"} & $\dn$ & @{text "ZERO"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1096 |
@{text "bsimpALTs bs [r]"} & $\dn$ & @{text "fuse bs r"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1097 |
@{text "bsimpALTs bs rs"} & $\dn$ & @{text "ALTs bs rs"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1098 |
\mbox{}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1099 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1100 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1101 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1102 |
@{text "bsimpSEQ bs _ ZERO"} & $\dn$ & @{text "ZERO"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1103 |
@{text "bsimpSEQ bs ZERO _"} & $\dn$ & @{text "ZERO"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1104 |
@{text "bsimpSEQ bs\<^sub>1 (ONE bs\<^sub>2) r\<^sub>2"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1105 |
& $\dn$ & @{text "fuse (bs\<^sub>1 @ bs\<^sub>2) r\<^sub>2"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1106 |
@{text "bsimpSEQ bs r\<^sub>1 r\<^sub>2"} & $\dn$ & @{text "SEQ bs r\<^sub>1 r\<^sub>2"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1107 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1108 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1109 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1110 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1111 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1112 |
With this in place we can define our simplification function as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1113 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1114 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1115 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1116 |
@{thm (lhs) bsimp.simps(1)[of "bs" "r\<^sub>1" "r\<^sub>2"]} & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1117 |
@{thm (rhs) bsimp.simps(1)[of "bs" "r\<^sub>1" "r\<^sub>2"]}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1118 |
@{thm (lhs) bsimp.simps(2)[of "bs" _]} & $\dn$ & @{text "bsimpALTs bs (distinctWith (flts (map bsimp rs)) \<approx> \<emptyset>)"}\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1119 |
@{text "bsimp r"} & $\dn$ & @{text r} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1120 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1121 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1122 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1123 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1124 |
We believe our recursive function @{term bsimp} simplifies regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1125 |
expressions as intended by Sulzmann and Lu. There is no point in applying the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1126 |
@{text bsimp} function repeatedly (like the simplification in their paper which needs to be |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1127 |
applied until a fixpoint is reached) because we can show that @{term bsimp} is idempotent, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1128 |
that is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1129 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1130 |
\begin{proposition} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1131 |
@{term "bsimp (bsimp r) = bsimp r"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1132 |
\end{proposition} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1133 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1134 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1135 |
This can be proved by induction on @{text r} but requires a detailed analysis |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1136 |
that the de-nesting of alternatives always results in a flat list of regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1137 |
expressions. We omit the details since it does not concern the correctness proof. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1138 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1139 |
Next we can include simplification after each derivative step leading to the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1140 |
following notion of bitcoded derivatives: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1141 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1142 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1143 |
\begin{tabular}{cc} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1144 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1145 |
@{thm (lhs) bders_simp.simps(1)} & $\dn$ & @{thm (rhs) bders_simp.simps(1)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1146 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1147 |
& |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1148 |
\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1149 |
@{thm (lhs) bders_simp.simps(2)} & $\dn$ & @{thm (rhs) bders_simp.simps(2)} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1150 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1151 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1152 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1153 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1154 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1155 |
and use it in the improved lexing algorithm defined as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1156 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1157 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1158 |
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1159 |
$\textit{blexer}^+\;r\,s$ & $\dn$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1160 |
$\textit{let}\;r_{der} = (r^\uparrow)\backslash_{bsimp}\, s\;\textit{in}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1161 |
$\;\;\textit{if}\; \textit{bnullable}(r_{der}) \;\;\textit{then}\;\textit{decode}\,(\textit{bmkeps}\,r_{der})\,r |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1162 |
\;\;\textit{else}\;\textit{None}$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1163 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1164 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1165 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1166 |
\noindent The remaining task is to show that @{term blexer} and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1167 |
@{term "blexer_simp"} generate the same answers. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1168 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1169 |
When we first |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1170 |
attempted this proof we encountered a problem with the idea |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1171 |
in Sulzmann and Lu's paper where the argument seems to be to appeal |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1172 |
again to the @{text retrieve}-function defined for the unsimplified version |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1173 |
of the algorithm. But |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1174 |
this does not work, because desirable properties such as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1175 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1176 |
\[ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1177 |
@{text "retrieve r v = retrieve (bsimp r) v"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1178 |
\] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1179 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1180 |
\noindent do not hold under simplification---this property |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1181 |
essentially purports that we can retrieve the same value from a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1182 |
simplified version of the regular expression. To start with @{text retrieve} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1183 |
depends on the fact that the value @{text v} corresponds to the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1184 |
structure of the regular expression @{text r}---but the whole point of simplification |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1185 |
is to ``destroy'' this structure by making the regular expression simpler. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1186 |
To see this consider the regular expression @{term "r = ALT r' ZERO"} and a corresponding |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1187 |
value @{text "v = Left v'"}. If we annotate bitcodes to @{text "r"}, then |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1188 |
we can use @{text retrieve} with @{text r} and @{text v} in order to extract a corresponding |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1189 |
bitsequence. The reason that this works is that @{text r} is an alternative |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1190 |
regular expression and @{text v} a corresponding @{text "Left"}-value. However, if we simplify |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1191 |
@{text r}, then @{text v} does not correspond to the shape of the regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1192 |
expression anymore. So unless one can somehow |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1193 |
synchronise the change in the simplified regular expressions with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1194 |
the original POSIX value, there is no hope of appealing to @{text retrieve} in the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1195 |
correctness argument for @{term blexer_simp}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1196 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1197 |
We found it more helpful to introduce the rewriting systems shown in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1198 |
Figure~\ref{SimpRewrites}. The idea is to generate |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1199 |
simplified regular expressions in small steps (unlike the @{text bsimp}-function which |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1200 |
does the same in a big step), and show that each of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1201 |
the small steps preserves the bitcodes that lead to the final POSIX value. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1202 |
The rewrite system is organised such that $\leadsto$ is for bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1203 |
expressions and $\stackrel{s}{\leadsto}$ for lists of bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1204 |
expressions. The former essentially implements the simplifications of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1205 |
@{text "bsimpSEQ"} and @{text flts}; while the latter implements the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1206 |
simplifications in @{text "bsimpALTs"}. We can show that any bitcoded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1207 |
regular expression reduces in zero or more steps to the simplified |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1208 |
regular expression generated by @{text bsimp}: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1209 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1210 |
\begin{lemma}\label{lemone} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1211 |
@{thm[mode=IfThen] rewrites_to_bsimp} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1212 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1213 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1214 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1215 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1216 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1217 |
We can show that this rewrite system preserves @{term bnullable}, that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1218 |
is simplification does not affect nullability: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1219 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1220 |
\begin{lemma}\label{lembnull} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1221 |
@{thm[mode=IfThen] bnullable0(1)[of "r\<^sub>1" "r\<^sub>2"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1222 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1223 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1224 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1225 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1226 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1227 |
From this, we can show that @{text bmkeps} will produce the same bitsequence |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1228 |
as long as one of the bitcoded regular expressions in $\leadsto$ is nullable (this lemma |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1229 |
establishes the missing fact we were not able to establish using @{text retrieve}, as suggested |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1230 |
in the paper by Sulzmannn and Lu). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1231 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1232 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1233 |
\begin{lemma}\label{lemthree} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1234 |
@{thm[mode=IfThen] rewrite_bmkeps_aux(1)[of "r\<^sub>1" "r\<^sub>2"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1235 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1236 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1237 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1238 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1239 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1240 |
Crucial is also the fact that derivative steps and simplification steps can be interleaved, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1241 |
which is shown by the fact that $\leadsto$ is preserved under derivatives. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1242 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1243 |
\begin{lemma}\label{bderlem} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1244 |
@{thm[mode=IfThen] rewrite_preserves_bder(1)[of "r\<^sub>1" "r\<^sub>2"]} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1245 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1246 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1247 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1248 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1249 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1250 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1251 |
Using this fact together with Lemma~\ref{lemone} allows us to prove the central lemma |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1252 |
that the unsimplified |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1253 |
derivative (with a string @{term s}) reduces to the simplified derivative (with the same string). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1254 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1255 |
\begin{lemma}\label{lemtwo} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1256 |
@{thm[mode=IfThen] central} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1257 |
\end{lemma} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1258 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1259 |
%\begin{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1260 |
%By reverse induction on @{term s} generalising over @{text r}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1261 |
%\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1262 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1263 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1264 |
With these lemmas in place we can finally establish that @{term "blexer_simp"} and @{term "blexer"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1265 |
generate the same value, and using Theorem~\ref{thmone} from the previous section that this value |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1266 |
is indeed the POSIX value. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1267 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1268 |
\begin{theorem} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1269 |
@{thm[mode=IfThen] main_blexer_simp} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1270 |
\end{theorem} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1271 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1272 |
%\begin{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1273 |
%By unfolding the definitions and using Lemmas~\ref{lemtwo} and \ref{lemthree}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1274 |
%\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1275 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1276 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1277 |
This means that if the algorithm is called with a regular expression @{term r} and a string |
498
ab626b60ee64
fixed tiny typo in the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
496
diff
changeset
|
1278 |
@{term s} with $@{term s} \in L(@{term r})$, it will return @{term "Some v"} for the unique |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1279 |
@{term v} we defined by the POSIX relation $(@{term s}, @{term r}) \rightarrow @{term v}$; otherwise |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1280 |
the algorithm returns @{term "None"} when $s \not\in L(r)$ and no such @{text v} exists. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1281 |
This completes the correctness proof for the second POSIX lexing algorithm by Sulzmann and Lu. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1282 |
The interesting point of this algorithm is that the sizes of derivatives do not grow arbitrarily big but |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1283 |
can be finitely bounded, which |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1284 |
we shall show next. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1285 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1286 |
\begin{figure}[t] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1287 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1288 |
\begin{tabular}{@ {\hspace{-8mm}}c@ {}} |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1289 |
\\[-7mm] |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1290 |
@{thm[mode=Axiom] bs1[of _ "r\<^sub>2"]}$S\ZERO{}_l$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1291 |
@{thm[mode=Axiom] bs2[of _ "r\<^sub>1"]}$S\ZERO{}_r$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1292 |
@{thm[mode=Axiom] bs3[of "bs\<^sub>1" "bs\<^sub>2"]}$S\ONE$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1293 |
@{thm[mode=Rule] bs4[of "r\<^sub>1" "r\<^sub>2" _ "r\<^sub>3"]}SL\qquad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1294 |
@{thm[mode=Rule] bs5[of "r\<^sub>3" "r\<^sub>4" _ "r\<^sub>1"]}SR\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1295 |
@{thm[mode=Axiom] bs6}$A0$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1296 |
@{thm[mode=Axiom] bs7}$A1$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1297 |
@{thm[mode=Rule] bs10[of "rs\<^sub>1" "rs\<^sub>2"]}$AL$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1298 |
@{thm[mode=Rule] ss2[of "rs\<^sub>1" "rs\<^sub>2"]}$LT$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1299 |
@{thm[mode=Rule] ss3[of "r\<^sub>1" "r\<^sub>2"]}$LH$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1300 |
@{thm[mode=Axiom] ss4}$L\ZERO$\quad |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1301 |
@{thm[mode=Axiom] ss5[of "bs" "rs\<^sub>1" "rs\<^sub>2"]}$LS$\medskip\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1302 |
@{thm[mode=Rule] ss6[of "r\<^sub>2" "r\<^sub>1" "rs\<^sub>1" "rs\<^sub>2" "rs\<^sub>3"]}$LD$\\[-5mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1303 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1304 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1305 |
\caption{The rewrite rules that generate simplified regular expressions |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1306 |
in small steps: @{term "rrewrite r\<^sub>1 r\<^sub>2"} is for bitcoded regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1307 |
expressions and @{term "srewrite rs\<^sub>1 rs\<^sub>2"} for \emph{lists} of bitcoded |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1308 |
expressions. Interesting is the $LD$ rule that allows copies of regular |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1309 |
expressions to be removed provided a regular expression earlier in the list can |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1310 |
match the same strings.}\label{SimpRewrites} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1311 |
\end{figure} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1312 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1313 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1314 |
section {* Finiteness of Derivatives *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1315 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1316 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1317 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1318 |
In this section let us sketch our argument for why the size of the simplified |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1319 |
derivatives with the aggressive simplification function can be finitely bounded. Suppose |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1320 |
we have a size function for bitcoded regular expressions, written |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1321 |
$\llbracket r\rrbracket$, which counts the number of nodes if we regard $r$ as a tree |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1322 |
(we omit the precise definition; ditto for lists $\llbracket r\!s\rrbracket$). For this we show that for every $r$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1323 |
there exists a bound $N$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1324 |
such that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1325 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1326 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1327 |
$\forall s. \; \llbracket@{term "bders_simp r s"}\rrbracket \leq N$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1328 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1329 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1330 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1331 |
We prove this by induction on $r$. The base cases for @{term AZERO}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1332 |
@{term "AONE bs"} and @{term "ACHAR bs c"} are straightforward. The interesting case is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1333 |
for sequences of the form @{term "ASEQ bs r\<^sub>1 r\<^sub>2"}. In this case our induction |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1334 |
hypotheses state $\exists N_1. \forall s. \; \llbracket{}@{term "bders_simp r\<^sub>1 s"}\rrbracket \leq N_1$ and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1335 |
$\exists N_2. \forall s. \; \llbracket@{term "bders_simp r\<^sub>2 s"}\rrbracket \leq N_2$. We can reason as follows |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1336 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1337 |
\begin{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1338 |
\begin{tabular}{lcll} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1339 |
& & $ \llbracket@{term "bders_simp (ASEQ bs r\<^sub>1 r\<^sub>2) s"}\rrbracket$\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1340 |
& $ = $ & $\llbracket bsimp\,(\textit{ALTs}\;bs\;((@{term "ASEQ [] (bders_simp r\<^sub>1 s) r\<^sub>2"}) :: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1341 |
[@{term "bders_simp r\<^sub>2 s'"} \;|\; s' \in \textit{Suffix}(@{text r}_1, s)]))\rrbracket $ & (1) \\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1342 |
& $\leq$ & |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1343 |
$\llbracket\textit{distinctWith}\,((@{term "ASEQ [] (bders_simp r\<^sub>1 s) r\<^sub>2"}) :: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1344 |
[@{term "bders_simp r\<^sub>2 s'"} \;|\; s' \in \textit{Suffix}(@{text r}_1, s)])\,\approx\;@{term "{}"}\rrbracket + 1 $ & (2) \\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1345 |
& $\leq$ & $\llbracket@{term "ASEQ [] (bders_simp r\<^sub>1 s) r\<^sub>2"}\rrbracket + |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1346 |
\llbracket\textit{distinctWith}\,[@{term "bders_simp r\<^sub>2 s'"} \;|\; s' \in \textit{Suffix}(@{text r}_1, s)]\,\approx\;@{term "{}"}\rrbracket + 1 $ & (3) \\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1347 |
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 + |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1348 |
\llbracket\textit{distinctWith}\,[@{term "bders_simp r\<^sub>2 s'"} \;|\; s' \in \textit{Suffix}(@{text r}_1, s)]\,\approx\;@{term "{}"}\rrbracket$ & (4)\\ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1349 |
& $\leq$ & $N_1 + \llbracket r_2\rrbracket + 2 + l_{N_{2}} * N_{2}$ & (5) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1350 |
\end{tabular} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1351 |
\end{center} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1352 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1353 |
% tell Chengsong about Indian paper of closed forms of derivatives |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1354 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1355 |
\noindent |
502
1ab693d6342f
fixed a small typo in the Papaer.thy
Christian Urban <christian.urban@kcl.ac.uk>
parents:
499
diff
changeset
|
1356 |
where in (1) the $\textit{Suffix}(@{text "r"}_1, s)$ are all the suffixes of $s$ where @{term "bders_simp r\<^sub>1 s'"} is nullable ($s'$ being a suffix of $s$). |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1357 |
In (3) we know that $\llbracket@{term "ASEQ [] (bders_simp r\<^sub>1 s) r\<^sub>2"}\rrbracket$ is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1358 |
bounded by $N_1 + \llbracket{}r_2\rrbracket + 1$. In (5) we know the list comprehension contains only regular expressions of size smaller |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1359 |
than $N_2$. The list length after @{text distinctWith} is bounded by a number, which we call $l_{N_2}$. It stands |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1360 |
for the number of distinct regular expressions smaller than $N_2$ (there can only be finitely many of them). |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1361 |
We reason similarly for @{text STAR}.\smallskip |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1362 |
|
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1363 |
|
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1364 |
Clearly we give in this finiteness argument (Step (5)) a very loose bound that is |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1365 |
far from the actual bound we can expect. We can do better than this, but this does not improve |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1366 |
the finiteness property we are proving. If we are interested in a polynomial bound, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1367 |
one would hope to obtain a similar tight bound as for partial |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1368 |
derivatives introduced by Antimirov \cite{Antimirov95}. After all the idea with |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1369 |
@{text distinctWith} is to maintain a ``set'' of alternatives (like the sets in |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1370 |
partial derivatives). Unfortunately to obtain the exact same bound would mean |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1371 |
we need to introduce simplifications, such as |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1372 |
$(r_1 + r_2) \cdot r_3 \longrightarrow (r_1 \cdot r_3) + (r_2 \cdot r_3)$, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1373 |
which exist for partial derivatives. However, if we introduce them in our |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1374 |
setting we would lose the POSIX property of our calculated values. We leave better |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1375 |
bounds for future work.\\[-6.5mm] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1376 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1377 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1378 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1379 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1380 |
section {* Conclusion *} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1381 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1382 |
text {* |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1383 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1384 |
We set out in this work to prove in Isabelle/HOL the correctness of |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1385 |
the second POSIX lexing algorithm by Sulzmann and Lu |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1386 |
\cite{Sulzmann2014}. This follows earlier work where we established |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1387 |
the correctness of the first algorithm |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1388 |
\cite{AusafDyckhoffUrban2016}. In the earlier work we needed to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1389 |
introduce our own specification about what POSIX values are, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1390 |
because the informal definition given by Sulzmann and Lu did not |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1391 |
stand up to a formal proof. Also for the second algorithm we needed |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1392 |
to introduce our own definitions and proof ideas in order to establish the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1393 |
correctness. Our interest in the second algorithm |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1394 |
lies in the fact that by using bitcoded regular expressions and an aggressive |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1395 |
simplification method there is a chance that the derivatives |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1396 |
can be kept universally small (we established in this paper that |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1397 |
they can be kept finitely bounded for any string). |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1398 |
%This is important if one is after |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1399 |
%an efficient POSIX lexing algorithm based on derivatives. |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1400 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1401 |
Having proved the correctness of the POSIX lexing algorithm, which |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1402 |
lessons have we learned? Well, we feel this is a very good example |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1403 |
where formal proofs give further insight into the matter at |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1404 |
hand. For example it is very hard to see a problem with @{text nub} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1405 |
vs @{text distinctWith} with only experimental data---one would still |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1406 |
see the correct result but find that simplification does not simplify in well-chosen, but not |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1407 |
obscure, examples. |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1408 |
%We found that from an implementation |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1409 |
%point-of-view it is really important to have the formal proofs of |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1410 |
%the corresponding properties at hand. |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1411 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1412 |
We have also developed a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1413 |
healthy suspicion when experimental data is used to back up |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1414 |
efficiency claims. For example Sulzmann and Lu write about their |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1415 |
equivalent of @{term blexer_simp} \textit{``...we can incrementally compute |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1416 |
bitcoded parse trees in linear time in the size of the input''} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1417 |
\cite[Page 14]{Sulzmann2014}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1418 |
Given the growth of the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1419 |
derivatives in some cases even after aggressive simplification, this |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1420 |
is a hard to believe claim. A similar claim about a theoretical runtime |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1421 |
of @{text "O(n\<^sup>2)"} is made for the Verbatim lexer, which calculates |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1422 |
tokens according to POSIX rules~\cite{verbatim}. For this Verbatim uses Brzozowski's |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1423 |
derivatives like in our work. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1424 |
The authors write: \textit{``The results of our empirical tests [..] confirm that Verbatim has |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1425 |
@{text "O(n\<^sup>2)"} time complexity.''} \cite[Section~VII]{verbatim}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1426 |
While their correctness proof for Verbatim is formalised in Coq, the claim about |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1427 |
the runtime complexity is only supported by some emperical evidence obtained |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1428 |
by using the code extraction facilities of Coq. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1429 |
Given our observation with the ``growth problem'' of derivatives, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1430 |
we |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1431 |
tried out their extracted OCaml code with the example |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1432 |
\mbox{@{text "(a + aa)\<^sup>*"}} as a single lexing rule, and it took for us around 5 minutes to tokenise a |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1433 |
string of 40 $a$'s and that increased to approximately 19 minutes when the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1434 |
string is 50 $a$'s long. Taking into account that derivatives are not simplified in the Verbatim |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1435 |
lexer, such numbers are not surprising. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1436 |
Clearly our result of having finite |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1437 |
derivatives might sound rather weak in this context but we think such effeciency claims |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1438 |
really require further scrutiny. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1439 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1440 |
The contribution of this paper is to make sure |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1441 |
derivatives do not grow arbitrarily big (universially) In the example \mbox{@{text "(a + aa)\<^sup>*"}}, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1442 |
\emph{all} derivatives have a size of 17 or less. The result is that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1443 |
lexing a string of, say, 50\,000 a's with the regular expression \mbox{@{text "(a + aa)\<^sup>*"}} takes approximately |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1444 |
10 seconds with our Scala implementation |
499
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1445 |
of the presented algorithm. Our Isabelle code including the results from Sec.~5 is available from \url{https://github.com/urbanchr/posix}. |
6a100d32314c
updated the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
498
diff
changeset
|
1446 |
%\\[-10mm] |
496
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1447 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1448 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1449 |
%%\bibliographystyle{plain} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1450 |
\bibliography{root} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1451 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1452 |
\appendix |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1453 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1454 |
\section{Some Proofs} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1455 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1456 |
While we have formalised \emph{all} results in Isabelle/HOL, below we shall give some |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1457 |
rough details of our reasoning in ``English''. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1458 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1459 |
\begin{proof}[Proof of Lemma~\ref{codedecode}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1460 |
This follows from the property that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1461 |
$\textit{decode}'\,((\textit{code}\,v) \,@\, bs)\,r = (v, bs)$ holds |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1462 |
for any bit-sequence $bs$ and $\vdash v : r$. This property can be |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1463 |
easily proved by induction on $\vdash v : r$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1464 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1465 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1466 |
\begin{proof}[Proof of Lemma~\ref{mainlemma}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1467 |
This can be proved by induction on $s$ and generalising over |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1468 |
$v$. The interesting point is that we need to prove this in the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1469 |
reverse direction for $s$. This means instead of cases $[]$ and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1470 |
$c\!::\!s$, we have cases $[]$ and $s\,@\,[c]$ where we unravel the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1471 |
string from the back.\footnote{Isabelle/HOL provides an induction principle |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1472 |
for this way of performing the induction.} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1473 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1474 |
The case for $[]$ is routine using Lemmas~\ref{codedecode} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1475 |
and~\ref{retrievecode}. In the case $s\,@\,[c]$, we can infer from |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1476 |
the assumption that $\vdash v : (r\backslash s)\backslash c$ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1477 |
holds. Hence by Prop.~\ref{Posix2} we know that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1478 |
(*) $\vdash \inj\,(r\backslash s)\,c\,v : r\backslash s$ holds too. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1479 |
By definition of $\textit{flex}$ we can unfold the left-hand side |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1480 |
to be |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1481 |
\[ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1482 |
\textit{Some}\,(\textit{flex}\;r\,\textit{id}\,(s\,@\,[c])\,v) = |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1483 |
\textit{Some}\,(\textit{flex}\;r\,\textit{id}\,s\,(\inj\,(r\backslash s)\,c\,v)) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1484 |
\] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1485 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1486 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1487 |
By IH and (*) we can rewrite the right-hand side to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1488 |
$\textit{decode}\,(\textit{retrieve}\,(r^\uparrow\backslash s)\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1489 |
(\inj\,(r\backslash s)\,c\,\,v))\,r$ which is equal to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1490 |
$\textit{decode}\,(\textit{retrieve}\, (r^\uparrow\backslash |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1491 |
(s\,@\,[c]))\,v)\,r$ as required. The last rewrite step is possible |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1492 |
because we generalised over $v$ in our induction. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1493 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1494 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1495 |
\begin{proof}[Proof of Theorem~\ref{thmone}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1496 |
We can first expand both sides using Lem.~\ref{flex} and the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1497 |
definition of \textit{blexer}. This gives us two |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1498 |
\textit{if}-statements, which we need to show to be equal. By |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1499 |
Lemma~\ref{bnullable}\textit{(2)} we know the \textit{if}-tests coincide: |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1500 |
$\textit{bnullable}(r^\uparrow\backslash s) \;\textit{iff}\; |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1501 |
\nullable(r\backslash s)$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1502 |
For the \textit{if}-branch suppose $r_d \dn r^\uparrow\backslash s$ and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1503 |
$d \dn r\backslash s$. We have (*) @{text "nullable d"}. We can then show |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1504 |
by Lemma~\ref{bnullable}\textit{(3)} that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1505 |
% |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1506 |
\[ |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1507 |
\textit{decode}(\textit{bmkeps}\:r_d)\,r = |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1508 |
\textit{decode}(\textit{retrieve}\,r_d\,(\textit{mkeps}\,d))\,r |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1509 |
\] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1510 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1511 |
\noindent |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1512 |
where the right-hand side is equal to |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1513 |
$\textit{Some}\,(\textit{flex}\,r\,\textit{id}\,s\,(\textit{mkeps}\, |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1514 |
d))$ by Lemma~\ref{mainlemma} (we know |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1515 |
$\vdash \textit{mkeps}\,d : d$ by (*)). This shows the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1516 |
\textit{if}-branches return the same value. In the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1517 |
\textit{else}-branches both \textit{lexer} and \textit{blexer} return |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1518 |
\textit{None}. Therefore we can conclude the proof. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1519 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1520 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1521 |
\begin{proof}[Proof of Lemma~\ref{lemone}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1522 |
By induction on @{text r}. For this we can use the properties |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1523 |
@{thm fltsfrewrites} and @{text "rs"}$\;\stackrel{s}{\leadsto}^*$@{text "distinctWith rs \<approx>"} @{term "{}"}. The latter uses |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1524 |
repeated applications of the $LD$ rule which allows the removal |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1525 |
of duplicates that can recognise the same strings. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1526 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1527 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1528 |
\begin{proof}[Proof of Lemma~\ref{lembnull}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1529 |
Straightforward mutual induction on the definition of $\leadsto$ and $\stackrel{s}{\leadsto}$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1530 |
The only interesting case is the rule $LD$ where the property holds since by the side-conditions of that rule the empty string will |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1531 |
be in both @{text "L (rs\<^sub>a @ [r\<^sub>1] @ rs\<^sub>b @ [r\<^sub>2] @ rs\<^sub>c)"} and |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1532 |
@{text "L (rs\<^sub>a @ [r\<^sub>1] @ rs\<^sub>b @ rs\<^sub>c)"}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1533 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1534 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1535 |
\begin{proof}[Proof of Lemma \ref{lemthree}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1536 |
By straightforward mutual induction on the definition of $\leadsto$ and $\stackrel{s}{\leadsto}$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1537 |
Again the only interesting case is the rule $LD$ where we need to ensure that |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1538 |
@{text "bmkeps (rs\<^sub>a @ [r\<^sub>1] @ rs\<^sub>b @ [r\<^sub>2] @ rs\<^sub>c) = |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1539 |
bmkeps (rs\<^sub>a @ [r\<^sub>1] @ rs\<^sub>b @ rs\<^sub>c)"} holds. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1540 |
This is indeed the case because according to the POSIX rules the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1541 |
generated bitsequence is determined by the first alternative that can match the |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1542 |
string (in this case being nullable). |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1543 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1544 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1545 |
\begin{proof}[Proof of Lemma~\ref{bderlem}] |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1546 |
By straightforward mutual induction on the definition of $\leadsto$ and $\stackrel{s}{\leadsto}$. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1547 |
The case for $LD$ holds because @{term "L (erase (bder c r\<^sub>2)) \<subseteq> L (erase (bder c r\<^sub>1))"} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1548 |
if and only if @{term "L (erase (r\<^sub>2)) \<subseteq> L (erase (r\<^sub>1))"}. |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1549 |
\end{proof} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1550 |
*} |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1551 |
|
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1552 |
(*<*) |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1553 |
end |
f493a20feeb3
updated to include the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1554 |
(*>*) |