527
|
1 |
% Chapter Template
|
|
2 |
|
|
3 |
% Main chapter title
|
|
4 |
\chapter{Correctness of Bit-coded Algorithm without Simplification}
|
|
5 |
|
|
6 |
\label{ChapterBitcoded1} % Change X to a consecutive number; for referencing this chapter elsewhere, use \ref{ChapterX}
|
|
7 |
%Then we illustrate how the algorithm without bitcodes falls short for such aggressive
|
|
8 |
%simplifications and therefore introduce our version of the bitcoded algorithm and
|
|
9 |
%its correctness proof in
|
|
10 |
%Chapter 3\ref{Chapter3}.
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
%----------------------------------------------------------------------------------------
|
|
16 |
% SECTION common identities
|
|
17 |
%----------------------------------------------------------------------------------------
|
|
18 |
\section{Common Identities In Simplification-Related Functions}
|
|
19 |
Need to prove these before starting on the big correctness proof.
|
|
20 |
|
|
21 |
%-----------------------------------
|
|
22 |
% SUBSECTION
|
|
23 |
%-----------------------------------
|
|
24 |
\subsection{Idempotency of $\simp$}
|
|
25 |
|
|
26 |
\begin{equation}
|
|
27 |
\simp \;r = \simp\; \simp \; r
|
|
28 |
\end{equation}
|
|
29 |
This property means we do not have to repeatedly
|
|
30 |
apply simplification in each step, which justifies
|
|
31 |
our definition of $\blexersimp$.
|
|
32 |
It will also be useful in future proofs where properties such as
|
|
33 |
closed forms are needed.
|
|
34 |
The proof is by structural induction on $r$.
|
|
35 |
|
|
36 |
%-----------------------------------
|
|
37 |
% SUBSECTION
|
|
38 |
%-----------------------------------
|
|
39 |
\subsection{Syntactic Equivalence Under $\simp$}
|
|
40 |
We prove that minor differences can be annhilated
|
|
41 |
by $\simp$.
|
|
42 |
For example,
|
|
43 |
\begin{center}
|
|
44 |
$\simp \;(\simpALTs\; (\map \;(\_\backslash \; x)\; (\distinct \; \mathit{rs}\; \phi))) =
|
|
45 |
\simp \;(\simpALTs \;(\distinct \;(\map \;(\_ \backslash\; x) \; \mathit{rs}) \; \phi))$
|
|
46 |
\end{center}
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
%----------------------------------------------------------------------------------------
|
528
|
54 |
% SECTION correctness proof
|
527
|
55 |
%----------------------------------------------------------------------------------------
|
528
|
56 |
\section{Correctness of Bit-coded Algorithm (Without Simplification)}
|
|
57 |
We now give the proof the correctness of the algorithm with bit-codes.
|
|
58 |
|
|
59 |
Ausaf and Urban cleverly defined an auxiliary function called $\flex$,
|
|
60 |
defined as
|
|
61 |
\[
|
|
62 |
\flex \; r \; f \; [] \; v \; = \; f\; v
|
|
63 |
\flex \; r \; f \; c :: s \; v = \flex r \; \lambda v. \, f (\inj \; r\; c\; v)\; s \; v
|
|
64 |
\]
|
|
65 |
which accumulates the characters that needs to be injected back,
|
|
66 |
and does the injection in a stack-like manner (last taken derivative first injected).
|
|
67 |
$\flex$ is connected to the $\lexer$:
|
|
68 |
\begin{lemma}
|
|
69 |
$\flex \; r \; \textit{id}\; s \; \mkeps (r\backslash s) = \lexer \; r \; s$
|
|
70 |
\end{lemma}
|
|
71 |
$\flex$ provides us a bridge between $\lexer$ and $\blexer$.
|
|
72 |
What is even better about $\flex$ is that it allows us to
|
|
73 |
directly operate on the value $\mkeps (r\backslash v)$,
|
|
74 |
which is pivotal in the definition of $\lexer $ and $\blexer$, but not visible as an argument.
|
|
75 |
When the value created by $\mkeps$ becomes available, one can
|
|
76 |
prove some stepwise properties of lexing nicely:
|
|
77 |
\begin{lemma}\label{flexStepwise}
|
|
78 |
$\textit{flex} \; r \; f \; s@[c] \; v= \flex \; r \; f\; s \; (\inj \; (r\backslash s) \; c \; v) $
|
|
79 |
\end{lemma}
|
|
80 |
|
|
81 |
And for $\blexer$ we have a function with stepwise properties like $\flex$ as well,
|
|
82 |
called $\retrieve$\ref{retrieveDef}.
|
|
83 |
$\retrieve$ takes bit-codes from annotated regular expressions
|
|
84 |
guided by a value.
|
|
85 |
$\retrieve$ is connected to the $\blexer$ in the following way:
|
|
86 |
\begin{lemma}\label{blexer_retrieve}
|
|
87 |
$\blexer \; r \; s = \decode \; (\retrieve \; (\internalise \; r) \; (\mkeps \; (r \backslash s) )) \; r$
|
|
88 |
\end{lemma}
|
|
89 |
If you take derivative of an annotated regular expression,
|
|
90 |
you can $\retrieve$ the same bit-codes as before the derivative took place,
|
|
91 |
provided that you use the corresponding value:
|
|
92 |
|
|
93 |
\begin{lemma}\label{retrieveStepwise}
|
|
94 |
$\retrieve \; (r \backslash c) \; v= \retrieve \; r \; (\inj \; r\; c\; v)$
|
|
95 |
\end{lemma}
|
|
96 |
The other good thing about $\retrieve$ is that it can be connected to $\flex$:
|
|
97 |
%centralLemma1
|
|
98 |
\begin{lemma}\label{flex_retrieve}
|
|
99 |
$\flex \; r \; \textit{id}\; s\; v = \decode \; (\retrieve \; (r\backslash s )\; v) \; r$
|
|
100 |
\end{lemma}
|
|
101 |
\begin{proof}
|
|
102 |
By induction on $s$. The induction tactic is reverse induction on strings.
|
|
103 |
$v$ is allowed to be arbitrary.
|
|
104 |
The crucial point is to rewrite
|
|
105 |
\[
|
|
106 |
\retrieve \; (r \backslash s@[c]) \; \mkeps (r \backslash s@[c])
|
|
107 |
\]
|
|
108 |
as
|
|
109 |
\[
|
|
110 |
\retrieve \; (r \backslash s) \; (\inj \; (r \backslash s) \; c\; \mkeps (r \backslash s@[c]))
|
|
111 |
\].
|
|
112 |
This enables us to equate
|
|
113 |
\[
|
|
114 |
\retrieve \; (r \backslash s@[c]) \; \mkeps (r \backslash s@[c])
|
|
115 |
\]
|
|
116 |
with
|
|
117 |
\[
|
|
118 |
\flex \; r \; \textit{id} \; s \; (\inj \; (r\backslash s) \; c\; (\mkeps (r\backslash s@[c])))
|
|
119 |
\],
|
|
120 |
which in turn can be rewritten as
|
|
121 |
\[
|
|
122 |
\flex \; r \; \textit{id} \; s@[c] \; (\mkeps (r\backslash s@[c]))
|
|
123 |
\].
|
|
124 |
\end{proof}
|
|
125 |
|
|
126 |
With the above lemma we can now link $\flex$ and $\blexer$.
|
|
127 |
|
|
128 |
\begin{lemma}\label{flex_blexer}
|
|
129 |
$\textit{flex} \; r \; \textit{id} \; s \; \mkeps(r \backslash s) = \blexer \; r \; s$
|
|
130 |
\end{lemma}
|
|
131 |
\begin{proof}
|
|
132 |
Using two of the above lemmas: \ref{flex_retrieve} and \ref{blexer_retrieve}.
|
|
133 |
\end{proof}
|
|
134 |
Finally
|
|
135 |
|
|
136 |
|