Paper/Paper.thy
author urbanc
Thu, 10 Feb 2011 13:10:16 +0000
changeset 95 9540c2f2ea77
parent 94 5b12cd0a3b3c
child 96 3b9deda4f459
permissions -rw-r--r--
more things
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
     1
(*<*)
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
     2
theory Paper
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
     3
imports "../Myhill" "LaTeXsugar" 
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
     4
begin
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
     5
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
     6
declare [[show_question_marks = false]]
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
     7
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
     8
consts
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
     9
 REL :: "(string \<times> string) \<Rightarrow> bool"
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    10
 UPLUS :: "'a set \<Rightarrow> 'a set \<Rightarrow> (nat \<times> 'a) set"
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
    11
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
    12
abbreviation
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
    13
  "EClass x R \<equiv> R `` {x}"
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
    14
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    15
abbreviation 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    16
  "append_rexp2 r_itm r \<equiv> append_rexp r r_itm"
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    17
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    18
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
    19
notation (latex output)
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
    20
  str_eq_rel ("\<approx>\<^bsub>_\<^esub>") and
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
    21
  str_eq ("_ \<approx>\<^bsub>_\<^esub> _") and
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
    22
  Seq (infixr "\<cdot>" 100) and
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
    23
  Star ("_\<^bsup>\<star>\<^esup>") and
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
    24
  pow ("_\<^bsup>_\<^esup>" [100, 100] 100) and
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
    25
  Suc ("_+1" [100] 100) and
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
    26
  quotient ("_ \<^raw:\ensuremath{\!\sslash\!}> _" [90, 90] 90) and
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    27
  REL ("\<approx>") and
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
    28
  UPLUS ("_ \<^raw:\ensuremath{\uplus}> _" [90, 90] 90) and
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    29
  L ("\<^raw:\ensuremath{\cal{L}}>'(_')" [0] 101) and
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
    30
  Lam ("\<lambda>'(_')" [100] 100) and 
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
    31
  Trn ("'(_, _')" [100, 100] 100) and 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
    32
  EClass ("\<lbrakk>_\<rbrakk>\<^bsub>_\<^esub>" [100, 100] 100) and
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
    33
  transition ("_ \<^raw:\ensuremath{\stackrel{\text{>_\<^raw:}}{\Longmapsto}}> _" [100, 100, 100] 100) and
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    34
  Setalt ("\<^raw:\ensuremath{\bigplus}>_" [1000] 999) and
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    35
  append_rexp2 ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 100) and
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
    36
  append_rhs_rexp ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 50)
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
    37
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    38
(*>*)
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    39
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
    40
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    41
section {* Introduction *}
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    42
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    43
text {*
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
    44
  Regular languages are an important and well-understood subject in Computer
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    45
  Science, with many beautiful theorems and many useful algorithms. There is a
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    46
  wide range of textbooks on this subject, many of which are aimed at students
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    47
  and contain very detailed ``pencil-and-paper'' proofs
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    48
  (e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    49
  formalising these theorems and by verifying formally the algorithms.
59
fc35eb54fdc9 more on the intro
urbanc
parents: 58
diff changeset
    50
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    51
  There is however a problem: the typical approach to regular languages is to
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    52
  introduce finite automata and then define everything in terms of them.  For
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    53
  example, a regular language is normally defined as one whose strings are
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    54
  recognised by a finite deterministic automaton. This approach has many
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
    55
  benefits. Among them is the fact that it is easy to convince oneself that
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    56
  regular languages are closed under complementation: one just has to exchange
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    57
  the accepting and non-accepting states in the corresponding automaton to
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    58
  obtain an automaton for the complement language.  The problem, however, lies with
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
    59
  formalising such reasoning in a HOL-based theorem prover, in our case
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
    60
  Isabelle/HOL. Automata are build up from states and transitions that 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    61
  need to be represented as graphs, matrices or functions, none
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    62
  of which can be defined as inductive datatype. 
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    63
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    64
  In case of graphs and matrices, this means we have to build our own
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    65
  reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    66
  HOLlight support them with libraries. Even worse, reasoning about graphs and
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    67
  matrices can be a real hassle in HOL-based theorem provers.  Consider for
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    68
  example the operation of sequencing two automata, say $A_1$ and $A_2$, by
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    69
  connecting the accepting states of $A_1$ to the initial state of $A_2$:  
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    70
  
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    71
  \begin{center}
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    72
  \begin{tabular}{ccc}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    73
  \begin{tikzpicture}[scale=0.8]
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    74
  %\draw[step=2mm] (-1,-1) grid (1,1);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    75
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    76
  \draw[rounded corners=1mm, very thick] (-1.0,-0.3) rectangle (-0.2,0.3);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    77
  \draw[rounded corners=1mm, very thick] ( 0.2,-0.3) rectangle ( 1.0,0.3);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    78
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    79
  \node (A) at (-1.0,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    80
  \node (B) at ( 0.2,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    81
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    82
  \node (C) at (-0.2, 0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    83
  \node (D) at (-0.2,-0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    84
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    85
  \node (E) at (1.0, 0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    86
  \node (F) at (1.0,-0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    87
  \node (G) at (1.0,-0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    88
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    89
  \draw (-0.6,0.0) node {\footnotesize$A_1$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    90
  \draw ( 0.6,0.0) node {\footnotesize$A_2$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    91
  \end{tikzpicture}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    92
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    93
  & 
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    94
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    95
  \raisebox{1.1mm}{\bf\Large$\;\;\;\Rightarrow\,\;\;$}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    96
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    97
  &
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    98
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    99
  \begin{tikzpicture}[scale=0.8]
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   100
  %\draw[step=2mm] (-1,-1) grid (1,1);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   101
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   102
  \draw[rounded corners=1mm, very thick] (-1.0,-0.3) rectangle (-0.2,0.3);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   103
  \draw[rounded corners=1mm, very thick] ( 0.2,-0.3) rectangle ( 1.0,0.3);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   104
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   105
  \node (A) at (-1.0,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   106
  \node (B) at ( 0.2,0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   107
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   108
  \node (C) at (-0.2, 0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   109
  \node (D) at (-0.2,-0.13) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   110
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   111
  \node (E) at (1.0, 0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   112
  \node (F) at (1.0,-0.0) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   113
  \node (G) at (1.0,-0.2) [circle, very thick, draw, fill=white, inner sep=0.4mm] {};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   114
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   115
  \draw (C) to [very thick, bend left=45] (B);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   116
  \draw (D) to [very thick, bend right=45] (B);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   117
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   118
  \draw (-0.6,0.0) node {\footnotesize$A_1$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   119
  \draw ( 0.6,0.0) node {\footnotesize$A_2$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   120
  \end{tikzpicture}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   121
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   122
  \end{tabular}
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   123
  \end{center}
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   124
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   125
  \noindent
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   126
  On ``paper'' we can define the corresponding graph in terms of the disjoint 
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   127
  union of the state nodes. Unfortunately in HOL, the standard definition for disjoint 
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   128
  union, namely 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   129
  %
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   130
  \begin{equation}\label{disjointunion}
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   131
  @{term "UPLUS A\<^isub>1 A\<^isub>2 \<equiv> {(1, x) | x. x \<in> A\<^isub>1} \<union> {(2, y) | y. y \<in> A\<^isub>2}"}
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   132
  \end{equation}
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   133
61
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   134
  \noindent
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   135
  changes the type---the disjoint union is not a set, but a set of pairs. 
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   136
  Using this definition for disjoint unions means we do not have a single type for automata
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   137
  and hence will not be able to state certain properties about \emph{all}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   138
  automata, since there is no type quantification available in HOL. An
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   139
  alternative, which provides us with a single type for automata, is to give every 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   140
  state node an identity, for example a natural
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   141
  number, and then be careful to rename these identities apart whenever
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   142
  connecting two automata. This results in clunky proofs
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   143
  establishing that properties are invariant under renaming. Similarly,
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   144
  connecting two automata represented as matrices results in very adhoc
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   145
  constructions, which are not pleasant to reason about.
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   146
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   147
  Functions are much better supported in Isabelle/HOL, but they still lead to similar
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   148
  problems as with graphs.  Composing, for example, two non-deterministic automata in parallel
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   149
  requires also the formalisation of disjoint unions. Nipkow \cite{Nipkow98} 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   150
  dismisses the option of using identities, because it leads according to him to ``messy proofs''. He
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   151
  opts for a variant of \eqref{disjointunion} using bitlists, but writes
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   152
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   153
  \begin{quote}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   154
  \it%
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   155
  \begin{tabular}{@ {}l@ {}p{0.88\textwidth}@ {}}
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   156
  `` & If the reader finds the above treatment in terms of bit lists revoltingly
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   157
       concrete, I cannot disagree.''\\
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   158
  `` & All lemmas appear obvious given a picture of the composition of automata\ldots
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   159
       Yet their proofs require a painful amount of detail.''
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   160
  \end{tabular}
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   161
  \end{quote}
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   162
  
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   163
  \noindent
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   164
  Moreover, it is not so clear how to conveniently impose a finiteness condition 
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   165
  upon functions in order to represent \emph{finite} automata. The best is
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   166
  probably to resort to more advanced reasoning frameworks, such as \emph{locales}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   167
  or \emph{type classes},
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   168
  which are not avaiable in \emph{all} HOL-based theorem provers.
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   169
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   170
  Because of these problems to do with representing automata, there seems
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   171
  to be no substantial formalisation of automata theory and regular languages 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   172
  carried out in HOL-based theorem provers. Nipkow establishes in 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   173
  \cite{Nipkow98} the link between regular expressions and automata in
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   174
  the restricted context of lexing. The only larger formalisations of automata theory 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   175
  are carried out in Nuprl \cite{Constable00} and in Coq (for example 
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   176
  \cite{Filliatre97}).
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   177
  
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   178
  In this paper, we will not attempt to formalise automata theory in
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   179
  Isabelle/HOL, but take a completely different approach to regular
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   180
  languages. Instead of defining a regular language as one where there exists
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   181
  an automaton that recognises all strings of the language, we define a
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   182
  regular language as:
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   183
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   184
  \begin{definition}
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   185
  A language @{text A} is \emph{regular}, provided there is a regular expression that matches all
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   186
  strings of @{text "A"}.
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   187
  \end{definition}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   188
  
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   189
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   190
  The reason is that regular expressions, unlike graphs, matrices and functons, can
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   191
  be easily defined as inductive datatype. Consequently a corresponding reasoning 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   192
  infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   193
  of regular expression matching based on derivatives \cite{OwensSlind08}.  The purpose of this paper is to
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   194
  show that a central result about regular languages---the Myhill-Nerode theorem---can 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   195
  be recreated by only using regular expressions. This theorem gives necessary
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   196
  and sufficient conditions for when a language is regular. As a corollary of this
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   197
  theorem we can easily establish the usual closure properties, including 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   198
  complementation, for regular languages.\smallskip
61
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   199
  
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   200
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   201
  {\bf Contributions:} 
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   202
  There is an extensive literature on regular languages.
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   203
  To our knowledge, our proof of the Myhill-Nerode theorem is the
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   204
  first that is based on regular expressions, only. We prove the part of this theorem 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   205
  stating that a regular expression has only finitely many partitions using certain 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   206
  tagging-functions. Again to our best knowledge, these tagging functions have
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   207
  not been used before to establish the Myhill-Nerode theorem.
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   208
*}
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   209
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   210
section {* Preliminaries *}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   211
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   212
text {*
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   213
  Strings in Isabelle/HOL are lists of characters with the \emph{empty string}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   214
  being represented by the empty list, written @{term "[]"}.  \emph{Languages}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   215
  are sets of strings. The language containing all strings is written in
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   216
  Isabelle/HOL as @{term "UNIV::string set"}. The concatenation of two languages 
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   217
  is written @{term "A ;; B"} and a language raised to the power @{text n} is written 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   218
  @{term "A \<up> n"}. They are defined as usual
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   219
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   220
  \begin{center}
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   221
  @{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   222
  \hspace{7mm}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   223
  @{thm pow.simps(1)[THEN eq_reflection, where A1="A"]}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   224
  \hspace{7mm}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   225
  @{thm pow.simps(2)[THEN eq_reflection, where A1="A" and n1="n"]}
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   226
  \end{center}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   227
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   228
  \noindent
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   229
  where @{text "@"} is the usual list-append operation. The Kleene-star of a language @{text A}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   230
  is defined as the union over all powers, namely @{thm Star_def}. In the paper
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   231
  we will make use of the following properties of these constructions.
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   232
  
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   233
  \begin{proposition}\label{langprops}\mbox{}\\
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   234
  \begin{tabular}{@ {}ll}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   235
  (i)   & @{thm star_cases}     \\ 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   236
  (ii)  & @{thm[mode=IfThen] pow_length}\\
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   237
  (iii) & @{thm seq_Union_left} \\ 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   238
  \end{tabular}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   239
  \end{proposition}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   240
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   241
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   242
  In @{text "(ii)"} we use the notation @{term "length s"} for the length of a string.
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   243
  We omit the proofs for these properties, but invite the reader to consult
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   244
  our formalisation.\footnote{Available at ???}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   245
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   246
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   247
  The notation in Isabelle/HOL for the quotient of a language @{text A} according to an 
97b783438316 added an example
urbanc
parents: 89
diff changeset
   248
  equivalence relation @{term REL} is @{term "A // REL"}. We will write 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   249
  @{text "\<lbrakk>x\<rbrakk>\<^isub>\<approx>"} for the equivalence class defined 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   250
  as @{text "{y | y \<approx> x}"}.
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   251
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   252
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   253
  Central to our proof will be the solution of equational systems
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   254
  involving sets of languages. For this we will use Arden's lemma \cite{Brzozowski64}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   255
  which solves equations of the form @{term "X = A ;; X \<union> B"} provided
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   256
  @{term "[] \<notin> A"}. However we will need the following ``reverse'' 
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   257
  version of Arden's lemma.
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   258
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   259
  \begin{lemma}[Reverse Arden's Lemma]\label{arden}\mbox{}\\
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   260
  If @{thm (prem 1) arden} then
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   261
  @{thm (lhs) arden} has the unique solution
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   262
  @{thm (rhs) arden}.
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   263
  \end{lemma}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   264
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   265
  \begin{proof}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   266
  For the right-to-left direction we assume @{thm (rhs) arden} and show
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   267
  that @{thm (lhs) arden} holds. From Prop.~\ref{langprops}@{text "(i)"} 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   268
  we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"},
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   269
  which is equal to @{term "A\<star> = {[]} \<union> A\<star> ;; A"}. Adding @{text B} to both 
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   270
  sides gives @{term "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"}, whose right-hand side
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   271
  is equal to @{term "(B ;; A\<star>) ;; A \<union> B"}. This completes this direction. 
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   272
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   273
  For the other direction we assume @{thm (lhs) arden}. By a simple induction
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   274
  on @{text n}, we can establish the property
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   275
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   276
  \begin{center}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   277
  @{text "(*)"}\hspace{5mm} @{thm (concl) arden_helper}
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   278
  \end{center}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   279
  
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   280
  \noindent
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   281
  Using this property we can show that @{term "B ;; (A \<up> n) \<subseteq> X"} holds for
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   282
  all @{text n}. From this we can infer @{term "B ;; A\<star> \<subseteq> X"} using the definition
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   283
  of @{text "\<star>"}.
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   284
  For the inclusion in the other direction we assume a string @{text s}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   285
  with length @{text k} is element in @{text X}. Since @{thm (prem 1) arden}
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   286
  we know by Prop.~\ref{langprops}@{text "(ii)"} that 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   287
  @{term "s \<notin> X ;; (A \<up> Suc k)"} since its length is only @{text k}
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   288
  (the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). 
53
da85feadb8e3 small typo
urbanc
parents: 52
diff changeset
   289
  From @{text "(*)"} it follows then that
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   290
  @{term s} must be element in @{term "(\<Union>m\<in>{0..k}. B ;; (A \<up> m))"}. This in turn
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   291
  implies that @{term s} is in @{term "(\<Union>n. B ;; (A \<up> n))"}. Using Prop.~\ref{langprops}@{text "(iii)"} 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   292
  this is equal to @{term "B ;; A\<star>"}, as we needed to show.\qed
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   293
  \end{proof}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   294
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   295
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   296
  Regular expressions are defined as the inductive datatype
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   297
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   298
  \begin{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   299
  @{text r} @{text "::="}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   300
  @{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   301
  @{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   302
  @{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   303
  @{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   304
  @{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   305
  @{term "STAR r"}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   306
  \end{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   307
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   308
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   309
  and the language matched by a regular expression is defined as
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   310
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   311
  \begin{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   312
  \begin{tabular}{c@ {\hspace{10mm}}c}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   313
  \begin{tabular}{rcl}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   314
  @{thm (lhs) L_rexp.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(1)}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   315
  @{thm (lhs) L_rexp.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(2)}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   316
  @{thm (lhs) L_rexp.simps(3)[where c="c"]} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(3)[where c="c"]}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   317
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   318
  &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   319
  \begin{tabular}{rcl}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   320
  @{thm (lhs) L_rexp.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   321
       @{thm (rhs) L_rexp.simps(4)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   322
  @{thm (lhs) L_rexp.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]} & @{text "\<equiv>"} &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   323
       @{thm (rhs) L_rexp.simps(5)[where ?r1.0="r\<^isub>1" and ?r2.0="r\<^isub>2"]}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   324
  @{thm (lhs) L_rexp.simps(6)[where r="r"]} & @{text "\<equiv>"} &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   325
      @{thm (rhs) L_rexp.simps(6)[where r="r"]}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   326
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   327
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   328
  \end{center}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   329
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   330
  Given a set of regular expressions @{text rs}, we will make use of the operation of generating 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   331
  a regular expression that matches all languages of @{text rs}. We only need to know the existence
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   332
  of such a regular expression and therefore we use Isabelle/HOL's @{const "fold_graph"} and Hilbert's
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   333
  @{text "\<epsilon>"} to define @{term "\<Uplus>rs"}. This operation, roughly speaking, folds @{const ALT} over the 
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   334
  set @{text rs} with @{const NULL} for the empty set. We can prove that for finite sets @{text rs}
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   335
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   336
  \begin{center}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   337
  @{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   338
  \end{center}
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   339
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   340
  \noindent
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   341
  holds, whereby @{text "\<calL> ` rs"} stands for the 
97b783438316 added an example
urbanc
parents: 89
diff changeset
   342
  image of the set @{text rs} under function @{text "\<calL>"}.
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   343
*}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   344
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   345
section {* Finite Partitions Imply Regularity of a Language *}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   346
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   347
text {*
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   348
  The key definition in the Myhill-Nerode theorem is the
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   349
  \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   350
  strings are related, provided there is no distinguishing extension in this
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   351
  language. This can be defined as:
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   352
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   353
  \begin{definition}[Myhill-Nerode Relation]\mbox{}\\
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   354
  @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   355
  \end{definition}
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   356
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   357
  \noindent
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   358
  It is easy to see that @{term "\<approx>A"} is an equivalence relation, which
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   359
  partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   360
  equivalence classes. Let us give an example: consider the regular language containing just
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   361
  the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV}
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   362
  into the three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and  @{text "X\<^isub>3"}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   363
  as follows
97b783438316 added an example
urbanc
parents: 89
diff changeset
   364
  
97b783438316 added an example
urbanc
parents: 89
diff changeset
   365
  \begin{center}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   366
  @{text "X\<^isub>1 = {[]}"}\hspace{5mm}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   367
  @{text "X\<^isub>2 = {[c]}"}\hspace{5mm}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   368
  @{text "X\<^isub>3 = UNIV - {[], [c]}"}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   369
  \end{center}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   370
97b783438316 added an example
urbanc
parents: 89
diff changeset
   371
  One direction of the Myhill-Nerode theorem establishes 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   372
  that if there are finitely many equivalence classes, like in the example above, then 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   373
  the language is regular. In our setting we therefore have to show:
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   374
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   375
  \begin{theorem}\label{myhillnerodeone}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   376
  @{thm[mode=IfThen] hard_direction}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   377
  \end{theorem}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   378
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   379
  \noindent
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   380
  To prove this theorem, we first define the set @{term "finals A"} as those equivalence
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   381
  classes that contain strings of @{text A}, namely
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   382
  %
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   383
  \begin{equation} 
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   384
  @{thm finals_def}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   385
  \end{equation}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   386
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   387
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   388
  In our running example, @{text "X\<^isub>2"} is the only equivalence class in @{term "finals {[c]}"}.
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   389
  It is straightforward to show that in general @{thm lang_is_union_of_finals} and 
79
bba9c80735f9 started to define things more directly
urbanc
parents: 77
diff changeset
   390
  @{thm finals_in_partitions} hold. 
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   391
  Therefore if we know that there exists a regular expression for every
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   392
  equivalence class in @{term "finals A"} (which by assumption must be
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   393
  a finite set), then we can use @{text "\<bigplus>"} to obtain a regular expression 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   394
  using that matches every string in @{text A}.
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   395
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   396
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   397
  Our proof of Thm.~\ref{myhillnerodeone} relies on a method that can calculate a
79
bba9c80735f9 started to define things more directly
urbanc
parents: 77
diff changeset
   398
  regular expression for \emph{every} equivalence class, not just the ones 
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   399
  in @{term "finals A"}. We
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   400
  first define the notion of \emph{one-character-transition} between 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   401
  two equivalence classes
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   402
  %
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   403
  \begin{equation} 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   404
  @{thm transition_def}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   405
  \end{equation}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   406
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   407
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   408
  which means that if we concatenate the character @{text c} to the end of all 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   409
  strings in the equivalence class @{text Y}, we obtain a subset of 
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   410
  @{text X}. Note that we do not define an automaton here, we merely relate two sets
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   411
  (with the help of a regular expression). In our concrete example we have 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   412
  @{term "X\<^isub>1 \<Turnstile>c\<Rightarrow> X\<^isub>2"}, @{term "X\<^isub>1 \<Turnstile>d\<Rightarrow> X\<^isub>3"} with @{text d} being any 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   413
  other character than @{text c}, and @{term "X\<^isub>3 \<Turnstile>d\<Rightarrow> X\<^isub>3"} for any @{text d}.
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   414
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   415
  Next we build an equational system that
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   416
  contains an equation for each equivalence class. Suppose we have 
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   417
  the equivalence classes @{text "X\<^isub>1,\<dots>,X\<^isub>n"}, there must be one and only one that
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   418
  contains the empty string @{text "[]"} (since equivalence classes are disjoint).
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   419
  Let us assume @{text "[] \<in> X\<^isub>1"}. We build the following equational system
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   420
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   421
  \begin{center}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   422
  \begin{tabular}{rcl}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   423
  @{text "X\<^isub>1"} & @{text "="} & @{text "(Y\<^isub>1\<^isub>1, CHAR c\<^isub>1\<^isub>1) + \<dots> + (Y\<^isub>1\<^isub>p, CHAR c\<^isub>1\<^isub>p) + \<lambda>(EMPTY)"} \\
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   424
  @{text "X\<^isub>2"} & @{text "="} & @{text "(Y\<^isub>2\<^isub>1, CHAR c\<^isub>2\<^isub>1) + \<dots> + (Y\<^isub>2\<^isub>o, CHAR c\<^isub>2\<^isub>o)"} \\
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   425
  & $\vdots$ \\
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   426
  @{text "X\<^isub>n"} & @{text "="} & @{text "(Y\<^isub>n\<^isub>1, CHAR c\<^isub>n\<^isub>1) + \<dots> + (Y\<^isub>n\<^isub>q, CHAR c\<^isub>n\<^isub>q)"}\\
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   427
  \end{tabular}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   428
  \end{center}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   429
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   430
  \noindent
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   431
  where the pairs @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"} stand for all transitions 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   432
  @{term "Y\<^isub>i\<^isub>j \<Turnstile>c\<^isub>i\<^isub>j\<Rightarrow> X\<^isub>i"}. Our internal represeantation for the right-hand
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   433
  sides are sets of terms.
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   434
  There can only be finitely many such
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   435
  terms since there are only finitely many equivalence classes 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   436
  and only finitely many characters.
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   437
  The term @{text "\<lambda>(EMPTY)"} in the first equation acts as a marker for the equivalence
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   438
  class containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   439
  single ``initial'' state in the equational system, which is different from
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   440
  the method by Brzozowski \cite{Brzozowski64}, where he marks the ``terminal'' 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   441
  states. We are forced to set up the equational system in our way, because 
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   442
  the Myhill-Nerode relation determines the ``direction'' of the transitions. 
97b783438316 added an example
urbanc
parents: 89
diff changeset
   443
  The successor ``state'' of an equivalence class @{text Y} can be reached by adding 
97b783438316 added an example
urbanc
parents: 89
diff changeset
   444
  characters to the end of @{text Y}. This is also the reason why we have to use 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   445
  our reverse version of Arden's lemma.}
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   446
  Overloading the function @{text \<calL>} for the two kinds of terms in the 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   447
  equational system, we have
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   448
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   449
  \begin{center}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   450
  @{text "\<calL>(Y, r) \<equiv>"} %
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   451
  @{thm (rhs) L_rhs_item.simps(2)[where X="Y" and r="r", THEN eq_reflection]}\hspace{10mm}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   452
  @{thm L_rhs_item.simps(1)[where r="r", THEN eq_reflection]}
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   453
  \end{center}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   454
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   455
  \noindent
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   456
  we can prove for @{text "X\<^isub>2\<^isub>.\<^isub>.\<^isub>n"} that the following equations
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   457
  %
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   458
  \begin{equation}\label{inv1}
83
f438f4dbaada a bit more on the paper
urbanc
parents: 82
diff changeset
   459
  @{text "X\<^isub>i = \<calL>(Y\<^isub>i\<^isub>1, CHAR c\<^isub>i\<^isub>1) \<union> \<dots> \<union> \<calL>(Y\<^isub>i\<^isub>q, CHAR c\<^isub>i\<^isub>q)"}.
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   460
  \end{equation}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   461
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   462
  \noindent
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   463
  hold. Similarly for @{text "X\<^isub>1"} we can show the following equation
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   464
  %
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   465
  \begin{equation}\label{inv2}
83
f438f4dbaada a bit more on the paper
urbanc
parents: 82
diff changeset
   466
  @{text "X\<^isub>1 = \<calL>(Y\<^isub>i\<^isub>1, CHAR c\<^isub>i\<^isub>1) \<union> \<dots> \<union> \<calL>(Y\<^isub>i\<^isub>p, CHAR c\<^isub>i\<^isub>p) \<union> \<calL>(\<lambda>(EMPTY))"}.
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   467
  \end{equation}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   468
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   469
  \noindent
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   470
  The reason for adding the @{text \<lambda>}-marker to our equational system is 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   471
  to obtain this equation: it only holds in this form since none of 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   472
  the other terms contain the empty string. Since we use sets for representing
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   473
  the right-hans side we can write \eqref{inv1} and \eqref{inv2} more
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   474
  concisely for an equation of the form @{text "X = rhs"} as
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   475
  %
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   476
  \begin{equation}\label{inv}
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   477
  \mbox{@{text "X = \<Union> (\<calL> ` rhs)"}}
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   478
  \end{equation}
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   479
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   480
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   481
  Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   482
  equational system into a \emph{solved form} maintaining the invariant
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   483
  \eqref{inv}. From the solved form we will be able to read
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   484
  off the regular expressions. 
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   485
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   486
  In order to transform an equational system into solved form, we have two main 
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   487
  operations: one that takes an equation of the form @{text "X = rhs"} and removes
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   488
  the recursive occurences of @{text X} in the @{text rhs} using our variant of Arden's 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   489
  Lemma. The other operation takes an equation @{text "X = rhs"}
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   490
  and substitutes @{text X} throughout the rest of the equational system
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   491
  adjusting the remaining regular expressions approriately. To define this adjustment 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   492
  we define the \emph{append-operation} 
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   493
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   494
  \begin{center}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   495
  @{thm append_rexp.simps(2)[where X="Y" and r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}\hspace{10mm}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   496
  @{thm append_rexp.simps(1)[where r="r\<^isub>1" and rexp="r\<^isub>2", THEN eq_reflection]}
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   497
  \end{center}
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   498
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   499
  \noindent
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   500
  which we also lift to entire right-hand sides of equations, written as
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   501
  @{thm (lhs) append_rhs_rexp_def[where rexp="r"]}. With this we can define
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   502
  the \emph{arden-operation} for an equation of the form @{text "X = rhs"}:
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   503
  
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   504
  \begin{center}
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   505
  \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   506
  @{thm (lhs) Arden_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   507
   & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   508
   & & @{text "r' ="}   & @{term "STAR (\<Uplus> {r. Trn X r \<in> rhs})"}\\
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   509
   & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "append_rhs_rexp rhs' r'"}}\\ 
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   510
  \end{tabular}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   511
  \end{center}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   512
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   513
  \noindent
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   514
  We first delete all terms of the form @{text "(X, r)"} from @{text rhs};
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   515
  then we calculate the combinded regular expressions for all @{text r} coming 
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   516
  from the deleted @{text "(X, r)"}, and take the @{const STAR} of it;
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   517
  finally we append this regular expression to @{text rhs'}. It can be easily seen 
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   518
  that this operation mimics Arden's lemma on the level of equations.  
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   519
  The \emph{substituion-operation} takes an equation
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   520
  of the form @{text "X = xrhs"} and substitutes it into the right-hand side @{text rhs}.
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   521
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   522
  \begin{center}
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   523
  \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   524
  @{thm (lhs) Subst_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   525
   & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   526
   & & @{text "r' ="}   & @{term "\<Uplus> {r. Trn X r \<in> rhs}"}\\
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   527
   & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ 
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   528
  \end{tabular}
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   529
  \end{center}
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   530
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   531
  \noindent
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   532
  We again delete first all occurence of @{text "(X, r)"} in @{text rhs}; we then calculate
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   533
  the regular expression corresponding to the deleted terms; finally we append this
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   534
  regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   535
  the substitution operation we will arrange it so that @{text "xrhs"} does not contain
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   536
  any occurence of @{text X}.
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   537
*}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   538
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   539
section {* Regular Expressions Generate Finitely Many Partitions *}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   540
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   541
text {*
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   542
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   543
  \begin{theorem}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   544
  Given @{text "r"} is a regular expressions, then @{thm rexp_imp_finite}.
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   545
  \end{theorem}  
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   546
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   547
  \begin{proof}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   548
  By induction on the structure of @{text r}. The cases for @{const NULL}, @{const EMPTY}
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   549
  and @{const CHAR} are straightforward, because we can easily establish
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   550
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   551
  \begin{center}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   552
  \begin{tabular}{l}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   553
  @{thm quot_null_eq}\\
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   554
  @{thm quot_empty_subset}\\
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   555
  @{thm quot_char_subset}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   556
  \end{tabular}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   557
  \end{center}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   558
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   559
  \end{proof}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   560
*}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   561
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   562
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   563
section {* Conclusion and Related Work *}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   564
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   565
text {*
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   566
  In this paper we took the view that a regular language as one where there exists 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   567
  a regular expression that matches all its strings. For us it was important to find 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   568
  out how far we can push this point of view. Having formalised the Myhill-Nerode
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   569
  theorem means pushed very far. Having the Myhill-Nerode theorem means we can 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   570
  formalise much of the textbook results in this subject. 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   571
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   572
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   573
*}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   574
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   575
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   576
(*<*)
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   577
end
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   578
(*>*)