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