Paper/Paper.thy
author urbanc
Sat, 19 Feb 2011 12:01:16 +0000
changeset 117 22ba25b808c8
parent 116 342983676c8f
child 118 c3fa11ee776e
permissions -rw-r--r--
updated second direction
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
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
    36
  append_rhs_rexp ("_ \<^raw:\ensuremath{\triangleleft}> _" [100, 100] 50) and
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
    37
  uminus ("\<^raw:\ensuremath{\overline{>_\<^raw:}}>" [100] 100)
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
    38
  
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    39
(*>*)
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    40
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
    41
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    42
section {* Introduction *}
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    43
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
    44
text {*
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
    45
  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
    46
  Science, with many beautiful theorems and many useful algorithms. There is a
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    47
  wide range of textbooks on this subject, many of which are aimed at students
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
    48
  and contain very detailed `pencil-and-paper' proofs
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    49
  (e.g.~\cite{Kozen97}). It seems natural to exercise theorem provers by
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
    50
  formalising the theorems and by verifying formally the algorithms.
59
fc35eb54fdc9 more on the intro
urbanc
parents: 58
diff changeset
    51
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    52
  There is however a problem: the typical approach to regular languages is to
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    53
  introduce finite automata and then define everything in terms of them.  For
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    54
  example, a regular language is normally defined as one whose strings are
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    55
  recognised by a finite deterministic automaton. This approach has many
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
    56
  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
    57
  regular languages are closed under complementation: one just has to exchange
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    58
  the accepting and non-accepting states in the corresponding automaton to
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    59
  obtain an automaton for the complement language.  The problem, however, lies with
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
    60
  formalising such reasoning in a HOL-based theorem prover, in our case
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
    61
  Isabelle/HOL. Automata are built up from states and transitions that 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    62
  need to be represented as graphs, matrices or functions, none
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    63
  of which can be defined as inductive datatype. 
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    64
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    65
  In case of graphs and matrices, this means we have to build our own
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    66
  reasoning infrastructure for them, as neither Isabelle/HOL nor HOL4 nor
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    67
  HOLlight support them with libraries. Even worse, reasoning about graphs and
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    68
  matrices can be a real hassle in HOL-based theorem provers.  Consider for
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    69
  example the operation of sequencing two automata, say $A_1$ and $A_2$, by
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
    70
  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
    71
  
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
    72
  \begin{center}
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    73
  \begin{tabular}{ccc}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    74
  \begin{tikzpicture}[scale=0.8]
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    75
  %\draw[step=2mm] (-1,-1) grid (1,1);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    76
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    77
  \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
    78
  \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
    79
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    80
  \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
    81
  \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
    82
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    83
  \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
    84
  \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
    85
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    86
  \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
    87
  \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
    88
  \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
    89
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    90
  \draw (-0.6,0.0) node {\footnotesize$A_1$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    91
  \draw ( 0.6,0.0) node {\footnotesize$A_2$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    92
  \end{tikzpicture}
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
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
    96
  \raisebox{1.1mm}{\bf\Large$\;\;\;\Rightarrow\,\;\;$}
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
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   100
  \begin{tikzpicture}[scale=0.8]
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   101
  %\draw[step=2mm] (-1,-1) grid (1,1);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   102
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   103
  \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
   104
  \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
   105
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   106
  \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
   107
  \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
   108
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   109
  \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
   110
  \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
   111
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   112
  \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
   113
  \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
   114
  \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
   115
  
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   116
  \draw (C) to [very thick, bend left=45] (B);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   117
  \draw (D) to [very thick, bend right=45] (B);
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   118
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   119
  \draw (-0.6,0.0) node {\footnotesize$A_1$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   120
  \draw ( 0.6,0.0) node {\footnotesize$A_2$};
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   121
  \end{tikzpicture}
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   122
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   123
  \end{tabular}
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   124
  \end{center}
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   125
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   126
  \noindent
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   127
  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
   128
  union of the state nodes. Unfortunately in HOL, the standard definition for disjoint 
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   129
  union, namely 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   130
  %
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   131
  \begin{equation}\label{disjointunion}
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   132
  @{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
   133
  \end{equation}
60
fb08f41ca33d a bit more tuning on the introduction
urbanc
parents: 59
diff changeset
   134
61
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   135
  \noindent
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   136
  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
   137
  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
   138
  and hence will not be able to state certain properties about \emph{all}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   139
  automata, since there is no type quantification available in HOL. An
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   140
  alternative, which provides us with a single type for automata, is to give every 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   141
  state node an identity, for example a natural
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   142
  number, and then be careful to rename these identities apart whenever
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   143
  connecting two automata. This results in clunky proofs
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   144
  establishing that properties are invariant under renaming. Similarly,
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   145
  connecting two automata represented as matrices results in very adhoc
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   146
  constructions, which are not pleasant to reason about.
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   147
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   148
  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
   149
  problems as with graphs.  Composing, for example, two non-deterministic automata in parallel
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   150
  requires also the formalisation of disjoint unions. Nipkow \cite{Nipkow98} 
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   151
  dismisses for this the option of using identities, because it leads according to 
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   152
  him to ``messy proofs''. He
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   153
  opts for a variant of \eqref{disjointunion} using bit lists, but writes 
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   154
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   155
  \begin{quote}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   156
  \it%
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   157
  \begin{tabular}{@ {}l@ {}p{0.88\textwidth}@ {}}
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   158
  `` & All lemmas appear obvious given a picture of the composition of automata\ldots
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   159
       Yet their proofs require a painful amount of detail.''
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   160
  \end{tabular}
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   161
  \end{quote}
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   162
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   163
  \noindent
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   164
  and
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   165
  
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   166
  \begin{quote}
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   167
  \it%
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   168
  \begin{tabular}{@ {}l@ {}p{0.88\textwidth}@ {}}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   169
  `` & If the reader finds the above treatment in terms of bit lists revoltingly
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   170
       concrete, I cannot disagree. A more abstract approach is clearly desirable.''
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   171
  \end{tabular}
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   172
  \end{quote}
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   173
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   174
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   175
  \noindent
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   176
  Moreover, it is not so clear how to conveniently impose a finiteness condition 
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   177
  upon functions in order to represent \emph{finite} automata. The best is
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   178
  probably to resort to more advanced reasoning frameworks, such as \emph{locales}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   179
  or \emph{type classes},
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   180
  which are \emph{not} avaiable in all HOL-based theorem provers.
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   181
66
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   182
  Because of these problems to do with representing automata, there seems
828ea293b61f more on the introduction
urbanc
parents: 61
diff changeset
   183
  to be no substantial formalisation of automata theory and regular languages 
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   184
  carried out in HOL-based theorem provers. Nipkow  \cite{Nipkow98} establishes
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   185
  the link between regular expressions and automata in
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   186
  the context of lexing. Berghofer and Reiter \cite{BerghoferReiter09} 
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   187
  formalise automata working over 
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   188
  bit strings in the context of Presburger arithmetic.
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   189
  The only larger formalisations of automata theory 
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   190
  are carried out in Nuprl \cite{Constable00} and in Coq \cite{Filliatre97}.
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   191
  
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   192
  In this paper, we will not attempt to formalise automata theory in
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   193
  Isabelle/HOL, but take a completely different approach to regular
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   194
  languages. Instead of defining a regular language as one where there exists
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   195
  an automaton that recognises all strings of the language, we define a
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   196
  regular language as:
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   197
82
14b12b5de6d3 added coments about functions
urbanc
parents: 79
diff changeset
   198
  \begin{definition}
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   199
  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
   200
  strings of @{text "A"}.
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   201
  \end{definition}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   202
  
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   203
  \noindent
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   204
  The reason is that regular expressions, unlike graphs, matrices and functions, can
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   205
  be easily defined as inductive datatype. Consequently a corresponding reasoning 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   206
  infrastructure comes for free. This has recently been exploited in HOL4 with a formalisation
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   207
  of regular expression matching based on derivatives \cite{OwensSlind08} and
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   208
  with an equivalence checker for regular expressions in Isabelle/HOL \cite{KraussNipkow11}.  
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   209
  The purpose of this paper is to
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   210
  show that a central result about regular languages---the Myhill-Nerode theorem---can 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   211
  be recreated by only using regular expressions. This theorem gives necessary
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   212
  and sufficient conditions for when a language is regular. As a corollary of this
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   213
  theorem we can easily establish the usual closure properties, including 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   214
  complementation, for regular languages.\smallskip
61
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   215
  
070f543e2560 more to the intro
urbanc
parents: 60
diff changeset
   216
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   217
  {\bf Contributions:} 
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   218
  There is an extensive literature on regular languages.
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   219
  To our knowledge, our proof of the Myhill-Nerode theorem is the
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   220
  first that is based on regular expressions, only. We prove the part of this theorem 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   221
  stating that a regular expression has only finitely many partitions using certain 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   222
  tagging-functions. Again to our best knowledge, these tagging functions have
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   223
  not been used before to establish the Myhill-Nerode theorem.
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   224
*}
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
   225
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   226
section {* Preliminaries *}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   227
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   228
text {*
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   229
  Strings in Isabelle/HOL are lists of characters with the \emph{empty string}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   230
  being represented by the empty list, written @{term "[]"}.  \emph{Languages}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   231
  are sets of strings. The language containing all strings is written in
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   232
  Isabelle/HOL as @{term "UNIV::string set"}. The concatenation of two languages 
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   233
  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
   234
  @{term "A \<up> n"}. They are defined as usual
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   235
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   236
  \begin{center}
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   237
  @{thm Seq_def[THEN eq_reflection, where A1="A" and B1="B"]}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   238
  \hspace{7mm}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   239
  @{thm pow.simps(1)[THEN eq_reflection, where A1="A"]}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   240
  \hspace{7mm}
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   241
  @{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
   242
  \end{center}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   243
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   244
  \noindent
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   245
  where @{text "@"} is the list-append operation. The Kleene-star of a language @{text A}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   246
  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
   247
  we will make use of the following properties of these constructions.
58
0d4d5bb321dc a little bit in the introduction
urbanc
parents: 54
diff changeset
   248
  
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   249
  \begin{proposition}\label{langprops}\mbox{}\\
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   250
  \begin{tabular}{@ {}ll}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   251
  (i)   & @{thm star_cases}     \\ 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   252
  (ii)  & @{thm[mode=IfThen] pow_length}\\
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   253
  (iii) & @{thm seq_Union_left} \\ 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   254
  \end{tabular}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   255
  \end{proposition}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   256
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   257
  \noindent
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   258
  In @{text "(ii)"} we use the notation @{term "length s"} for the length of a
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   259
  string; this property states that if @{term "[] \<notin> A"} then the lengths of
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   260
  the strings in @{term "A \<up> (Suc n)"} must be longer than @{text n}.  We omit
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   261
  the proofs for these properties, but invite the reader to consult our
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   262
  formalisation.\footnote{Available at ???}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   263
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   264
  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
   265
  equivalence relation @{term REL} is @{term "A // REL"}. We will write 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   266
  @{text "\<lbrakk>x\<rbrakk>\<^isub>\<approx>"} for the equivalence class defined 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   267
  as @{text "{y | y \<approx> x}"}.
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   268
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   269
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   270
  Central to our proof will be the solution of equational systems
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   271
  involving equivalence classes of languages. For this we will use Arden's lemma \cite{Brzozowski64},
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   272
  which solves equations of the form @{term "X = A ;; X \<union> B"} provided
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   273
  @{term "[] \<notin> A"}. However we will need the following `reverse' 
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   274
  version of Arden's lemma (`reverse' in the sense of changing the order of @{text "\<cdot>"}).
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   275
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   276
  \begin{lemma}[Reverse Arden's Lemma]\label{arden}\mbox{}\\
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   277
  If @{thm (prem 1) arden} then
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   278
  @{thm (lhs) arden} if and only if
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   279
  @{thm (rhs) arden}.
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   280
  \end{lemma}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   281
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   282
  \begin{proof}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   283
  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
   284
  that @{thm (lhs) arden} holds. From Prop.~\ref{langprops}@{text "(i)"} 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   285
  we have @{term "A\<star> = {[]} \<union> A ;; A\<star>"},
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   286
  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
   287
  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
   288
  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
   289
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   290
  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
   291
  on @{text n}, we can establish the property
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   292
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   293
  \begin{center}
86
6457e668dee5 tuned comments and names in Myhill_1
urbanc
parents: 83
diff changeset
   294
  @{text "(*)"}\hspace{5mm} @{thm (concl) arden_helper}
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   295
  \end{center}
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   296
  
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   297
  \noindent
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   298
  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
   299
  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
   300
  of @{text "\<star>"}.
51
6cfb92de4654 some tuning of the paper
urbanc
parents: 50
diff changeset
   301
  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
   302
  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
   303
  we know by Prop.~\ref{langprops}@{text "(ii)"} that 
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   304
  @{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
   305
  (the strings in @{term "X ;; (A \<up> Suc k)"} are all longer). 
53
da85feadb8e3 small typo
urbanc
parents: 52
diff changeset
   306
  From @{text "(*)"} it follows then that
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   307
  @{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
   308
  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
   309
  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
   310
  \end{proof}
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   311
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   312
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   313
  Regular expressions are defined as the inductive datatype
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   314
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   315
  \begin{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   316
  @{text r} @{text "::="}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   317
  @{term NULL}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   318
  @{term EMPTY}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   319
  @{term "CHAR c"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   320
  @{term "SEQ r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   321
  @{term "ALT r r"}\hspace{1.5mm}@{text"|"}\hspace{1.5mm} 
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   322
  @{term "STAR r"}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   323
  \end{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   324
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   325
  \noindent
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   326
  and the language matched by a regular expression is defined as
67
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   327
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   328
  \begin{center}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   329
  \begin{tabular}{c@ {\hspace{10mm}}c}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   330
  \begin{tabular}{rcl}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   331
  @{thm (lhs) L_rexp.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(1)}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   332
  @{thm (lhs) L_rexp.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) L_rexp.simps(2)}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   333
  @{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
   334
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   335
  &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   336
  \begin{tabular}{rcl}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   337
  @{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
   338
       @{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
   339
  @{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
   340
       @{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
   341
  @{thm (lhs) L_rexp.simps(6)[where r="r"]} & @{text "\<equiv>"} &
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   342
      @{thm (rhs) L_rexp.simps(6)[where r="r"]}\\
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   343
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   344
  \end{tabular}
7478be786f87 more intro
urbanc
parents: 66
diff changeset
   345
  \end{center}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   346
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   347
  Given a finite set of regular expressions @{text rs}, we will make use of the operation of generating 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   348
  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
   349
  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
   350
  @{text "\<epsilon>"} to define @{term "\<Uplus>rs"}. This operation, roughly speaking, folds @{const ALT} over the 
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   351
  set @{text rs} with @{const NULL} for the empty set. We can prove that for a finite set @{text rs}
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   352
  %
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   353
  \begin{equation}\label{uplus}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   354
  \mbox{@{thm (lhs) folds_alt_simp} @{text "= \<Union> (\<calL> ` rs)"}}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   355
  \end{equation}
88
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   356
1436fc451bb9 added something about Setalt and folds
urbanc
parents: 86
diff changeset
   357
  \noindent
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   358
  holds, whereby @{text "\<calL> ` rs"} stands for the 
97b783438316 added an example
urbanc
parents: 89
diff changeset
   359
  image of the set @{text rs} under function @{text "\<calL>"}.
50
32bff8310071 revised proof of Ardens lemma
urbanc
parents: 39
diff changeset
   360
*}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   361
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   362
section {* The Myhill-Nerode Theorem, First Part *}
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   363
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   364
text {*
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   365
  The key definition in the Myhill-Nerode theorem is the
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   366
  \emph{Myhill-Nerode relation}, which states that w.r.t.~a language two 
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   367
  strings are related, provided there is no distinguishing extension in this
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   368
  language. This can be defined as tertiary relation.
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   369
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   370
  \begin{definition}[Myhill-Nerode Relation] Given a language @{text A}, two strings @{text x} and
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   371
  @{text y} are related provided
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   372
  \begin{center}
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   373
  @{thm str_eq_def[simplified str_eq_rel_def Pair_Collect]}
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   374
  \end{center}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   375
  \end{definition}
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   376
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   377
  \noindent
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   378
  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
   379
  partitions the set of all strings, @{text "UNIV"}, into a set of disjoint
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   380
  equivalence classes. To illustrate this quotient construction, let us give a simple 
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   381
  example: consider the regular language containing just
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   382
  the string @{text "[c]"}. The relation @{term "\<approx>({[c]})"} partitions @{text UNIV}
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   383
  into three equivalence classes @{text "X\<^isub>1"}, @{text "X\<^isub>2"} and  @{text "X\<^isub>3"}
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   384
  as follows
97b783438316 added an example
urbanc
parents: 89
diff changeset
   385
  
97b783438316 added an example
urbanc
parents: 89
diff changeset
   386
  \begin{center}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   387
  @{text "X\<^isub>1 = {[]}"}\hspace{5mm}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   388
  @{text "X\<^isub>2 = {[c]}"}\hspace{5mm}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   389
  @{text "X\<^isub>3 = UNIV - {[], [c]}"}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   390
  \end{center}
97b783438316 added an example
urbanc
parents: 89
diff changeset
   391
97b783438316 added an example
urbanc
parents: 89
diff changeset
   392
  One direction of the Myhill-Nerode theorem establishes 
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   393
  that if there are finitely many equivalence classes, like in the example above, then 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   394
  the language is regular. In our setting we therefore have to show:
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   395
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   396
  \begin{theorem}\label{myhillnerodeone}
96
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   397
  @{thm[mode=IfThen] Myhill_Nerode1}
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   398
  \end{theorem}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   399
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   400
  \noindent
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   401
  To prove this theorem, we first define the set @{term "finals A"} as those equivalence
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   402
  classes from @{term "UNIV // \<approx>A"} that contain strings of @{text A}, namely
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   403
  %
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   404
  \begin{equation} 
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   405
  @{thm finals_def}
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   406
  \end{equation}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   407
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   408
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   409
  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
   410
  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
   411
  @{thm finals_in_partitions} hold. 
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   412
  Therefore if we know that there exists a regular expression for every
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   413
  equivalence class in \mbox{@{term "finals A"}} (which by assumption must be
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   414
  a finite set), then we can use @{text "\<bigplus>"} to obtain a regular expression 
98
36f9d19be0e6 included comments by Xingyuan
urbanc
parents: 96
diff changeset
   415
  that matches every string in @{text A}.
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   416
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   417
90
97b783438316 added an example
urbanc
parents: 89
diff changeset
   418
  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
   419
  regular expression for \emph{every} equivalence class, not just the ones 
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   420
  in @{term "finals A"}. We
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   421
  first define the notion of \emph{one-character-transition} between 
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   422
  two equivalence classes
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   423
  %
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   424
  \begin{equation} 
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   425
  @{thm transition_def}
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   426
  \end{equation}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   427
71
426070e68b21 more on the paper
urbanc
parents: 70
diff changeset
   428
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   429
  which means that if we concatenate the character @{text c} to the end of all 
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   430
  strings in the equivalence class @{text Y}, we obtain a subset of 
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   431
  @{text X}. Note that we do not define an automaton here, we merely relate two sets
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   432
  (with the help of a character). In our concrete example we have 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   433
  @{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
   434
  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
   435
  
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   436
  Next we build an \emph{initial equational system} that
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   437
  contains an equation for each equivalence class. Suppose we have 
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   438
  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
   439
  contains the empty string @{text "[]"} (since equivalence classes are disjoint).
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   440
  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
   441
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   442
  \begin{center}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   443
  \begin{tabular}{rcl}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   444
  @{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
   445
  @{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
   446
  & $\vdots$ \\
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   447
  @{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
   448
  \end{tabular}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   449
  \end{center}
70
8ab3a06577cf slightly more on the paper
urbanc
parents: 67
diff changeset
   450
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   451
  \noindent
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   452
  where the terms @{text "(Y\<^isub>i\<^isub>j, CHAR c\<^isub>i\<^isub>j)"}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   453
  stand for all transitions @{term "Y\<^isub>i\<^isub>j \<Turnstile>c\<^isub>i\<^isub>j\<Rightarrow>
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   454
  X\<^isub>i"}.   There can only be
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   455
  finitely many such terms in a right-hand side since by assumption there are only finitely many
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   456
  equivalence classes and only finitely many characters.  The term @{text
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   457
  "\<lambda>(EMPTY)"} in the first equation acts as a marker for the equivalence class
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   458
  containing @{text "[]"}.\footnote{Note that we mark, roughly speaking, the
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   459
  single `initial' state in the equational system, which is different from
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   460
  the method by Brzozowski \cite{Brzozowski64}, where he marks the
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   461
  `terminal' states. We are forced to set up the equational system in our
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   462
  way, because the Myhill-Nerode relation determines the `direction' of the
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   463
  transitions. The successor `state' of an equivalence class @{text Y} can
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   464
  be reached by adding characters to the end of @{text Y}. This is also the
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   465
  reason why we have to use our reverse version of Arden's lemma.}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   466
  Overloading the function @{text \<calL>} for the two kinds of terms in the
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   467
  equational system, we have
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   468
  
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   469
  \begin{center}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   470
  @{text "\<calL>(Y, r) \<equiv>"} %
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   471
  @{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
   472
  @{thm L_rhs_item.simps(1)[where r="r", THEN eq_reflection]}
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   473
  \end{center}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   474
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   475
  \noindent
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   476
  and we can prove for @{text "X\<^isub>2\<^isub>.\<^isub>.\<^isub>n"} that the following equations
75
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   477
  %
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   478
  \begin{equation}\label{inv1}
83
f438f4dbaada a bit more on the paper
urbanc
parents: 82
diff changeset
   479
  @{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
   480
  \end{equation}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   481
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   482
  \noindent
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   483
  hold. Similarly for @{text "X\<^isub>1"} we can show the following equation
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   484
  %
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   485
  \begin{equation}\label{inv2}
83
f438f4dbaada a bit more on the paper
urbanc
parents: 82
diff changeset
   486
  @{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
   487
  \end{equation}
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   488
d63baacbdb16 parts of the 3 section
urbanc
parents: 71
diff changeset
   489
  \noindent
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   490
  The reason for adding the @{text \<lambda>}-marker to our initial equational system is 
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   491
  to obtain this equation: it only holds with the marker, since none of 
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   492
  the other terms contain the empty string. The point of the initial equational system is
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   493
  that solving it means we will be able to extract a regular expression for every equivalence class. 
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   494
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   495
  Our representation for the equations in Isabelle/HOL are pairs,
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   496
  where the first component is an equivalence class (a set of strings)
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   497
  and the second component
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   498
  is a set of terms. Given a set of equivalence
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   499
  classes @{text CS}, our initial equational system @{term "Init CS"} is thus 
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   500
  formally defined as
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   501
  %
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   502
  \begin{equation}\label{initcs}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   503
  \mbox{\begin{tabular}{rcl}     
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   504
  @{thm (lhs) Init_rhs_def} & @{text "\<equiv>"} & 
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   505
  @{text "if"}~@{term "[] \<in> X"}\\
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   506
  & & @{text "then"}~@{term "{Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X} \<union> {Lam EMPTY}"}\\
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   507
  & & @{text "else"}~@{term "{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}"}\\
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   508
  @{thm (lhs) Init_def}     & @{text "\<equiv>"} & @{thm (rhs) Init_def}
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   509
  \end{tabular}}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   510
  \end{equation}
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   511
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   512
  
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   513
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   514
  \noindent
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   515
  Because we use sets of terms 
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   516
  for representing the right-hand sides of equations, we can 
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   517
  prove \eqref{inv1} and \eqref{inv2} more concisely as
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   518
  %
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   519
  \begin{lemma}\label{inv}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   520
  If @{thm (prem 1) test} then @{text "X = \<Union> \<calL> ` rhs"}.
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   521
  \end{lemma}
77
63bc9f9d96ba small additions
urbanc
parents: 75
diff changeset
   522
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   523
  \noindent
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   524
  Our proof of Thm.~\ref{myhillnerodeone} will proceed by transforming the
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   525
  initial equational system into one in \emph{solved form} maintaining the invariant
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   526
  in Lem.~\ref{inv}. From the solved form we will be able to read
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   527
  off the regular expressions. 
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   528
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   529
  In order to transform an equational system into solved form, we have two 
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   530
  operations: one that takes an equation of the form @{text "X = rhs"} and removes
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   531
  any recursive occurrences of @{text X} in the @{text rhs} using our variant of Arden's 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   532
  Lemma. The other operation takes an equation @{text "X = rhs"}
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   533
  and substitutes @{text X} throughout the rest of the equational system
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   534
  adjusting the remaining regular expressions appropriately. To define this adjustment 
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   535
  we define the \emph{append-operation} taking a term and a regular expression as argument
89
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   536
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   537
  \begin{center}
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   538
  @{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
   539
  @{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
   540
  \end{center}
42af13d194c9 a bit more on the paper
urbanc
parents: 88
diff changeset
   541
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   542
  \noindent
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   543
  We lift this operation to entire right-hand sides of equations, written as
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   544
  @{thm (lhs) append_rhs_rexp_def[where rexp="r"]}. With this we can define
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   545
  the \emph{arden-operation} for an equation of the form @{text "X = rhs"} as:
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   546
  %
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   547
  \begin{equation}\label{arden_def}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   548
  \mbox{\begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   549
  @{thm (lhs) Arden_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   550
   & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   551
   & & @{text "r' ="}   & @{term "STAR (\<Uplus> {r. Trn X r \<in> rhs})"}\\
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   552
   & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "append_rhs_rexp rhs' r'"}}\\ 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   553
  \end{tabular}}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   554
  \end{equation}
93
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   555
2aa3756dcc9f more on the paper
urbanc
parents: 92
diff changeset
   556
  \noindent
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   557
  In this definition, we first delete all terms of the form @{text "(X, r)"} from @{text rhs};
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   558
  then we calculate the combined regular expressions for all @{text r} coming 
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   559
  from the deleted @{text "(X, r)"}, and take the @{const STAR} of it;
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   560
  finally we append this regular expression to @{text rhs'}. It can be easily seen 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   561
  that this operation mimics Arden's lemma on the level of equations. To ensure
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   562
  the non-emptiness condition of Arden's lemma we say that a right-hand side is
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   563
  \emph{ardenable} provided
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   564
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   565
  \begin{center}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   566
  @{thm ardenable_def}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   567
  \end{center}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   568
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   569
  \noindent
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   570
  This allows us to prove
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   571
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   572
  \begin{lemma}\label{ardenable}
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   573
  Given an equation @{text "X = rhs"}.
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   574
  If @{text "X = \<Union>\<calL> ` rhs"},
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   575
  @{thm (prem 2) Arden_keeps_eq}, and
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   576
  @{thm (prem 3) Arden_keeps_eq}, then
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   577
  @{text "X = \<Union>\<calL> ` (Arden X rhs)"}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   578
  \end{lemma}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   579
  
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   580
  \noindent
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   581
  The \emph{substituion-operation} takes an equation
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   582
  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
   583
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   584
  \begin{center}
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   585
  \begin{tabular}{rc@ {\hspace{2mm}}r@ {\hspace{1mm}}l}
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   586
  @{thm (lhs) Subst_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "let"}}\\ 
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   587
   & & @{text "rhs' ="} & @{term "rhs - {Trn X r | r. Trn X r \<in> rhs}"} \\
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   588
   & & @{text "r' ="}   & @{term "\<Uplus> {r. Trn X r \<in> rhs}"}\\
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   589
   & &  \multicolumn{2}{@ {\hspace{-2mm}}l}{@{text "in"}~~@{term "rhs' \<union> append_rhs_rexp xrhs r'"}}\\ 
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   590
  \end{tabular}
94
5b12cd0a3b3c latest on the paper
urbanc
parents: 93
diff changeset
   591
  \end{center}
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   592
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   593
  \noindent
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   594
  We again delete first all occurrence of @{text "(X, r)"} in @{text rhs}; we then calculate
95
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   595
  the regular expression corresponding to the deleted terms; finally we append this
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   596
  regular expression to @{text "xrhs"} and union it up with @{text rhs'}. When we use
9540c2f2ea77 more things
urbanc
parents: 94
diff changeset
   597
  the substitution operation we will arrange it so that @{text "xrhs"} does not contain
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   598
  any occurrence of @{text X}.
96
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   599
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   600
  With these two operation in place, we can define the operation that removes one equation
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   601
  from an equational systems @{text ES}. The operation @{const Subst_all}
96
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   602
  substitutes an equation @{text "X = xrhs"} throughout an equational system @{text ES}; 
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   603
  @{const Remove} then completely removes such an equation from @{text ES} by substituting 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   604
  it to the rest of the equational system, but first eliminating all recursive occurrences
96
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   605
  of @{text X} by applying @{const Arden} to @{text "xrhs"}.
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   606
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   607
  \begin{center}
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   608
  \begin{tabular}{rcl}
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   609
  @{thm (lhs) Subst_all_def} & @{text "\<equiv>"} & @{thm (rhs) Subst_all_def}\\
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   610
  @{thm (lhs) Remove_def}    & @{text "\<equiv>"} & @{thm (rhs) Remove_def}
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   611
  \end{tabular}
3b9deda4f459 simplified a bit the proof
urbanc
parents: 95
diff changeset
   612
  \end{center}
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   613
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   614
  \noindent
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   615
  Finally, we can define how an equational system should be solved. For this 
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   616
  we will need to iterate the process of eliminating equations until only one equation
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   617
  will be left in the system. However, we not just want to have any equation
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   618
  as being the last one, but the one involving the equivalence class for 
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   619
  which we want to calculate the regular 
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   620
  expression. Let us suppose this equivalence class is @{text X}. 
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   621
  Since @{text X} is the one to be solved, in every iteration step we have to pick an
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   622
  equation to be eliminated that is different from @{text X}. In this way 
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   623
  @{text X} is kept to the final step. The choice is implemented using Hilbert's choice 
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   624
  operator, written @{text SOME} in the definition below.
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   625
  
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   626
  \begin{center}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   627
  \begin{tabular}{rc@ {\hspace{4mm}}r@ {\hspace{1mm}}l}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   628
  @{thm (lhs) Iter_def} & @{text "\<equiv>"}~~\mbox{} & \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "let"}}\\ 
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   629
   & & @{text "(Y, yrhs) ="} & @{term "SOME (Y, yrhs). (Y, yrhs) \<in> ES \<and> X \<noteq> Y"} \\
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   630
   & &  \multicolumn{2}{@ {\hspace{-4mm}}l}{@{text "in"}~~@{term "Remove ES Y yrhs"}}\\ 
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   631
  \end{tabular}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   632
  \end{center}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   633
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   634
  \noindent
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   635
  The last definition we need applies @{term Iter} over and over until a condition 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   636
  @{text Cond} is \emph{not} satisfied anymore. The condition states that there
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   637
  are more than one equation left in the equational system @{text ES}. To solve
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   638
  an equational system we use Isabelle/HOL's @{text while}-operator as follows:
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   639
  
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   640
  \begin{center}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   641
  @{thm Solve_def}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   642
  \end{center}
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   643
101
d3fe0597080a updated paper
urbanc
parents: 100
diff changeset
   644
  \noindent
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   645
  We are not concerned here with the definition of this operator
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   646
  (see Berghofer and Nipkow \cite{BerghoferNipkow00}), but note that we eliminate
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   647
  in each @{const Iter}-step a single equation, and therefore 
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   648
  have a well-founded termination order by taking the cardinality 
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   649
  of the equational system @{text ES}. This enables us to prove
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   650
  properties about our definition of @{const Solve} when we `call' it with
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   651
  the equivalence class @{text X} and the initial equational system 
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   652
  @{term "Init (UNIV // \<approx>A)"} from
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   653
  \eqref{initcs} using the principle:
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   654
  %
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   655
  \begin{equation}\label{whileprinciple}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   656
  \mbox{\begin{tabular}{l}
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   657
  @{term "invariant (Init (UNIV // \<approx>A))"} \\
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   658
  @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> invariant (Iter X ES)"}\\
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   659
  @{term "\<forall>ES. invariant ES \<and> Cond ES \<longrightarrow> card (Iter X ES) < card ES"}\\
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   660
  @{term "\<forall>ES. invariant ES \<and> \<not> Cond ES \<longrightarrow> P ES"}\\
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   661
  \hline
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   662
  \multicolumn{1}{c}{@{term "P (Solve X (Init (UNIV // \<approx>A)))"}}
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   663
  \end{tabular}}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   664
  \end{equation}
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   665
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   666
  \noindent
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   667
  This principle states that given an invariant (which we will specify below) 
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   668
  we can prove a property
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   669
  @{text "P"} involving @{const Solve}. For this we have to discharge the following
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   670
  proof obligations: first the
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   671
  initial equational system satisfies the invariant; second the iteration
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   672
  step @{text "Iter"} preserves the the invariant as long as the condition @{term Cond} holds;
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   673
  third @{text "Iter"} decreases the termination order, and fourth that
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   674
  once the condition does not hold anymore then the property @{text P} must hold.
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   675
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   676
  The property @{term P} in our proof will state that @{term "Solve X (Init (UNIV // \<approx>A))"}
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   677
  returns with a single equation @{text "X = xrhs"} for some @{text "xrhs"}, and
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   678
  that this equational system still satisfies the invariant. In order to get
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   679
  the proof through, the invariant is composed of the following six properties:
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   680
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   681
  \begin{center}
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   682
  \begin{tabular}{@ {}rcl@ {\hspace{-13mm}}l @ {}}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   683
  @{text "invariant ES"} & @{text "\<equiv>"} &
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   684
      @{term "finite ES"} & @{text "(finiteness)"}\\
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   685
  & @{text "\<and>"} & @{thm (rhs) finite_rhs_def} & @{text "(finiteness rhs)"}\\
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   686
  & @{text "\<and>"} & @{text "\<forall>(X, rhs)\<in>ES. X = \<Union>\<calL> ` rhs"} & @{text "(soundness)"}\\
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   687
  & @{text "\<and>"} & @{thm (rhs) distinct_equas_def}\\
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   688
  &             &  & @{text "(distinctness)"}\\
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   689
  & @{text "\<and>"} & @{thm (rhs) ardenable_all_def} & @{text "(ardenable)"}\\   
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   690
  & @{text "\<and>"} & @{thm (rhs) valid_eqs_def} & @{text "(validity)"}\\
103
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   691
  \end{tabular}
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   692
  \end{center}
f460d5f75cb5 updated
urbanc
parents: 101
diff changeset
   693
 
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   694
  \noindent
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   695
  The first two ensure that the equational system is always finite (number of equations
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   696
  and number of terms in each equation); the second makes sure the `meaning' of the 
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   697
  equations is preserved under our transformations. The other properties are a bit more
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   698
  technical, but are needed to get our proof through. Distinctness states that every
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   699
  equation in the system is distinct. Ardenable ensures that we can always
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   700
  apply the arden operation. 
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   701
  The last property states that every @{text rhs} can only contain equivalence classes
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   702
  for which there is an equation. Therefore @{text lhss} is just the set containing 
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   703
  the first components of an equational system,
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   704
  while @{text "rhss"} collects all equivalence classes @{text X} in the terms of the 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   705
  form @{term "Trn X r"}. That means @{thm (lhs) lhss_def}~@{text "\<equiv> {X | (X, rhs) \<in> ES}"} 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   706
  and @{thm (lhs) rhss_def}~@{text "\<equiv> {X | (X, r) \<in> rhs}"}.
108
212bfa431fa5 filled details in one place
urbanc
parents: 107
diff changeset
   707
  
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   708
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   709
  It is straightforward to prove that the initial equational system satisfies the
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   710
  invariant.
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   711
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   712
  \begin{lemma}\label{invzero}
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   713
  @{thm[mode=IfThen] Init_ES_satisfies_invariant}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   714
  \end{lemma}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   715
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   716
  \begin{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   717
  Finiteness is given by the assumption and the way how we set up the 
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   718
  initial equational system. Soundness is proved in Lem.~\ref{inv}. Distinctness
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   719
  follows from the fact that the equivalence classes are disjoint. The ardenable
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   720
  property also follows from the setup of the initial equational system, as does 
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   721
  validity.\qed
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   722
  \end{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   723
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   724
  \noindent
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   725
  Next we show that @{text Iter} preserves the invariant.
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   726
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   727
  \begin{lemma}\label{iterone}
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   728
  @{thm[mode=IfThen] iteration_step_invariant[where xrhs="rhs"]}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   729
  \end{lemma}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   730
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   731
  \begin{proof} 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   732
  This boils down to choosing an equation @{text "Y = yrhs"} to be eliminated
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   733
  and to show that @{term "Subst_all (ES - {(Y, yrhs)}) Y (Arden Y yrhs)"} 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   734
  preserves the invariant.
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   735
  We prove this as follows:
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   736
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   737
  \begin{center}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   738
  @{text "\<forall> ES."} @{thm (prem 1) Subst_all_satisfies_invariant} implies
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   739
  @{thm (concl) Subst_all_satisfies_invariant}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   740
  \end{center}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   741
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   742
  \noindent
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   743
  Finiteness is straightforward, as @{const Subst} and @{const Arden} operations 
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   744
  keep the equational system finite. These operations also preserve soundness 
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   745
  and distinctness (we proved soundness for @{const Arden} in Lem.~\ref{ardenable}).
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   746
  The property ardenable is clearly preserved because the append-operation
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   747
  cannot make a regular expression to match the empty string. Validity is
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   748
  given because @{const Arden} removes an equivalence class from @{text yrhs}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   749
  and then @{const Subst_all} removes @{text Y} from the equational system.
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   750
  Having proved the implication above, we can replace @{text "ES"} with @{text "ES - {(Y, yrhs)}"}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   751
  which matches with our proof-obligation of @{const "Subst_all"}. Since
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   752
  \mbox{@{term "ES = ES - {(Y, yrhs)} \<union> {(Y, yrhs)}"}}, we can use our assumption 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   753
  to complete the proof.\qed 
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   754
  \end{proof}
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   755
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   756
  \noindent
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   757
  We also need the fact that @{text Iter} decreases the termination measure.
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   758
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   759
  \begin{lemma}\label{itertwo}
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   760
  @{thm[mode=IfThen] iteration_step_measure[simplified (no_asm), where xrhs="rhs"]}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   761
  \end{lemma}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   762
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   763
  \begin{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   764
  By assumption we know that @{text "ES"} is finite and has more than one element.
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   765
  Therefore there must be an element @{term "(Y, yrhs) \<in> ES"} with 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   766
  @{term "(Y, yrhs) \<noteq> (X, rhs)"}. Using the distinctness property we can infer
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   767
  that @{term "Y \<noteq> X"}. We further know that @{text "Remove ES Y yrhs"}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   768
  removes the equation @{text "Y = yrhs"} from the system, and therefore 
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   769
  the cardinality of @{const Iter} strictly decreases.\qed
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   770
  \end{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   771
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   772
  \noindent
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   773
  This brings us to our property we want establish for @{text Solve}.
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   774
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   775
104
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   776
  \begin{lemma}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   777
  If @{thm (prem 1) Solve} and @{thm (prem 2) Solve} then there exists
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   778
  a @{text rhs} such that  @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   779
  and @{term "invariant {(X, rhs)}"}.
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   780
  \end{lemma}
5bd73aa805a7 updated paper
urbanc
parents: 103
diff changeset
   781
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   782
  \begin{proof} 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   783
  In order to prove this lemma using \eqref{whileprinciple}, we have to use a slightly
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   784
  stronger invariant since Lem.~\ref{iterone} and \ref{itertwo} have the precondition 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   785
  that @{term "(X, rhs) \<in> ES"} for some @{text rhs}. This precondition is needed
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   786
  in order to choose in the @{const Iter}-step an equation that is not \mbox{@{term "X = rhs"}}.
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   787
  Therefore our invariant cannot be just @{term "invariant ES"}, but must be 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   788
  @{term "invariant ES \<and> (\<exists>rhs. (X, rhs) \<in> ES)"}. By assumption 
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   789
  @{thm (prem 2) Solve} and Lem.~\ref{invzero}, the more general invariant holds for
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   790
  the initial equational system. This is premise 1 of~\eqref{whileprinciple}.
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   791
  Premise 2 is given by Lem.~\ref{iterone} and the fact that @{const Iter} might
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   792
  modify the @{text rhs} in the equation @{term "X = rhs"}, but does not remove it.
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   793
  Premise 3 of~\eqref{whileprinciple} is by Lem.~\ref{itertwo}. Now in premise 4
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   794
  we like to show that there exists a @{text rhs} such that @{term "ES = {(X, rhs)}"}
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   795
  and that @{text "invariant {(X, rhs)}"} holds, provided the condition @{text "Cond"}
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   796
  does not holds. By the stronger invariant we know there exists such a @{text "rhs"}
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   797
  with @{term "(X, rhs) \<in> ES"}. Because @{text Cond} is not true, we know the cardinality
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   798
  of @{text ES} is @{text 1}. This means @{text "ES"} must actually be the equation @{text "X = rhs"},
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   799
  for which the invariant holds. This allows us to conclude that 
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   800
  @{term "Solve X (Init (UNIV // \<approx>A)) = {(X, rhs)}"} and @{term "invariant {(X, rhs)}"} hold,
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   801
  as needed.\qed
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   802
  \end{proof}
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   803
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   804
  \noindent
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   805
  With this lemma in place we can show that for every equivalence class in @{term "UNIV // \<approx>A"}
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   806
  there exists a regular expression.
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   807
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   808
  \begin{lemma}\label{every_eqcl_has_reg}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   809
  @{thm[mode=IfThen] every_eqcl_has_reg}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   810
  \end{lemma}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   811
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   812
  \begin{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   813
  By the preceeding Lemma, we know that there exists a @{text "rhs"} such
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   814
  that @{term "Solve X (Init (UNIV // \<approx>A))"} returns the equation @{text "X = rhs"},
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   815
  and that the invariant holds for this equation. That means we 
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   816
  know @{text "X = \<Union>\<calL> ` rhs"}. We further know that
109
79b37ef9505f minor updated
urbanc
parents: 108
diff changeset
   817
  this is equal to \mbox{@{text "\<Union>\<calL> ` (Arden X rhs)"}} using the properties of the 
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   818
  invariant and Lem.\ref{ardenable}. Using the validity property for the equation @{text "X = rhs"},
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   819
  we can infer that @{term "rhss rhs \<subseteq> {X}"} and because the arden operation
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   820
  removes that @{text X} from @{text rhs}, that @{term "rhss (Arden X rhs) = {}"}.
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   821
  This means the right-hand side @{term "Arden X rhs"} can only consist of terms of the form @{term "Lam r"}.
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   822
  So we can collect those (finitely many) regular expressions and have @{term "X = L (\<Uplus>rs)"}.
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   823
  With this we can conclude the proof.\qed
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   824
  \end{proof}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   825
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   826
  \noindent
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   827
  Lem.~\ref{every_eqcl_has_reg} allows us to finally give a proof for the first direction
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   828
  of the Myhill-Nerode theorem.
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   829
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   830
  \begin{proof}[of Thm.~\ref{myhillnerodeone}]
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   831
  By Lem.~\ref{every_eqcl_has_reg} we know that there exists a regular language for
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   832
  every equivalence class in @{term "UNIV // \<approx>A"}. Since @{text "finals A"} is
110
e500cab16be4 completed first direction
urbanc
parents: 109
diff changeset
   833
  a subset of  @{term "UNIV // \<approx>A"}, we also know that for every equivalence class
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   834
  in @{term "finals A"} there exists a regular language. Moreover by assumption 
106
91dc591de63f updated paper
urbanc
parents: 105
diff changeset
   835
  we know that @{term "finals A"} must be finite, and therefore there must be a finite
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   836
  set of regular expressions @{text "rs"} such that
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   837
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   838
  \begin{center}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   839
  @{term "\<Union>(finals A) = L (\<Uplus>rs)"}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   840
  \end{center}
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   841
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   842
  \noindent
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   843
  Since the left-hand side is equal to @{text A}, we can use @{term "\<Uplus>rs"} 
107
6f4f9b7b9891 updated paper
urbanc
parents: 106
diff changeset
   844
  as the regular expression that is needed in the theorem.\qed
105
ae6ad1363eb9 updated paper
urbanc
parents: 104
diff changeset
   845
  \end{proof}
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   846
*}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   847
100
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   848
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   849
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   850
2409827d8eb8 updated
urbanc
parents: 98
diff changeset
   851
section {* Myhill-Nerode, Second Part *}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   852
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   853
text {*
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   854
  We will prove in this section the second part of the Myhill-Nerode
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   855
  theorem. It can be formulated in our setting as follows.
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   856
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   857
  \begin{theorem}
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   858
  Given @{text "r"} is a regular expressions, then @{thm Myhill_Nerode2}.
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   859
  \end{theorem}  
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   860
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   861
  \noindent
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   862
  The proof will be by induction on the structure of @{text r}. It turns out
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   863
  the base cases are straightforward.
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   864
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   865
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   866
  \begin{proof}[Base Cases]
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   867
  The cases for @{const NULL}, @{const EMPTY} and @{const CHAR} are routine, because 
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   868
  we can easily establish
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   869
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   870
  \begin{center}
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   871
  \begin{tabular}{l}
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   872
  @{thm quot_null_eq}\\
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   873
  @{thm quot_empty_subset}\\
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   874
  @{thm quot_char_subset}
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   875
  \end{tabular}
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   876
  \end{center}
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   877
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   878
  \noindent
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   879
  hold, which shows that @{term "UNIV // \<approx>(L r)"} must be finite.\qed
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   880
  \end{proof}
109
79b37ef9505f minor updated
urbanc
parents: 108
diff changeset
   881
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   882
  \noindent
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   883
  Much more interesting, however, are the inductive cases. They seem hard to be solved 
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   884
  directly. The reader is invited to try. 
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   885
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   886
  Our method will rely on some
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   887
  \emph{tagging} functions of strings. Given the inductive hypothesis, it will 
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   888
  be easy to prove that the range of these tagging functions is finite.
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   889
  With this we will be able to infer that the tagging functions, seen as a relation,
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   890
  give rise to finitely many equivalence classes of @{const UNIV}. Finally we 
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   891
  will show that the tagging relation is more refined than @{term "\<approx>(L r)"}, which
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   892
  implies that @{term "UNIV // \<approx>(L r)"} must also be finite. For this we define the 
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   893
  notion of a \emph{tag-relation} (which is often also called a kernel relation).
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   894
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   895
  \begin{definition}[Tag-Relation] Given a tag-function @{text tag}, then two strings @{text x}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   896
  and @{text y} are tag-related provided
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   897
  \begin{center}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   898
  @{text "x =tag= y \<equiv> tag x = tag y"}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   899
  \end{center}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   900
  \end{definition}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   901
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   902
  \begin{lemma}\label{finone}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   903
  @{thm[mode=IfThen] finite_eq_tag_rel}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   904
  \end{lemma}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   905
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   906
  \begin{proof}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   907
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   908
  \end{proof}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   909
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   910
  \noindent
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   911
  
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   912
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   913
  \begin{lemma}\label{fintwo} 
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   914
  Given two equivalence relations @{text "R\<^isub>1"} and @{text "R\<^isub>2"}, then
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   915
  if @{thm (prem 1) refined_partition_finite[where A="UNIV" and ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   916
  and @{thm (prem 2) refined_partition_finite[where A="UNIV" and ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   917
  then @{thm (concl) refined_partition_finite[where A="UNIV" and ?R1.0="R\<^isub>1" and ?R2.0="R\<^isub>2"]}.
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   918
  \end{lemma}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   919
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   920
  \begin{proof}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   921
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   922
  \end{proof}
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   923
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   924
  \noindent
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   925
  Stringing Lem.~\ref{finone} and \ref{fintwo} together, means in order to show
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   926
  that @{term "UNIV // \<approx>(L r)"} is finite, we have to find a tagging function whose
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   927
  range is finite and whose tagging-relation refines @{term "\<approx>(L r)"}.
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   928
109
79b37ef9505f minor updated
urbanc
parents: 108
diff changeset
   929
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   930
  @{thm tag_str_ALT_def[where ?L1.0="A" and ?L2.0="B"]}
109
79b37ef9505f minor updated
urbanc
parents: 108
diff changeset
   931
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   932
  @{thm tag_str_SEQ_def[where ?L1.0="A" and ?L2.0="B"]}
109
79b37ef9505f minor updated
urbanc
parents: 108
diff changeset
   933
 
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   934
  @{thm tag_str_STAR_def[where ?L1.0="A"]}
39
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   935
*}
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   936
a59473f0229d tuned a little bit the section about finite partitions
urbanc
parents: 37
diff changeset
   937
117
22ba25b808c8 updated second direction
urbanc
parents: 116
diff changeset
   938
54
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   939
section {* Conclusion and Related Work *}
c19d2fc2cc69 a bit more on the paper
urbanc
parents: 53
diff changeset
   940
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   941
text {*
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   942
  In this paper we took the view that a regular language is one where there
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   943
  exists a regular expression that matches all of its strings. Regular
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
   944
  expressions can conveniently be defined as a datatype in a HOL-based theorem
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   945
  prover. For us it was therefore interesting to find out how far we can push
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   946
  this point of view. 
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   947
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   948
  Having formalised the Myhill-Nerode theorem means we
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   949
  pushed quite far. Using this theorem we can obviously prove when a language
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   950
  is \emph{not} regular---by establishing that it has infinitely many
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   951
  equivalence classes generated by the Myhill-Nerode relation (this is usually
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   952
  the purpose of the pumping lemma \cite{Kozen97}).  We can also use it to
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   953
  establish the standard textbook results about closure properties of regular
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   954
  languages. Interesting is the case of closure under complement, because
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   955
  it seems difficult to construct a regular expression for the complement
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   956
  language by direct means. However the existence of such a regular expression
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   957
  can be easily proved using the Myhill-Nerode theorem since 
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
   958
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   959
  \begin{center}
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   960
  @{term "s\<^isub>1 \<approx>A s\<^isub>2"} if and only if @{term "s\<^isub>1 \<approx>(-A) s\<^isub>2"}
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   961
  \end{center}
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   962
 
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   963
  \noindent
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   964
  holds for any strings @{text "s\<^isub>1"} and @{text
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   965
  "s\<^isub>2"}. Therefore @{text A} and the complement language @{term "-A"} give rise to the same
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   966
  partitions.  Proving the existence of such a regular expression via automata would 
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   967
  be quite involved. It includes the
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   968
  steps: regular expression @{text "\<Rightarrow>"} non-deterministic automaton @{text
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   969
  "\<Rightarrow>"} deterministic automaton @{text "\<Rightarrow>"} complement automaton @{text "\<Rightarrow>"}
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   970
  regular expression.
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   971
116
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   972
  While regular expressions are convenient in formalisations, they have some
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   973
  limitations. One is that there seems to be no notion of a minimal regular
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   974
  expression, like there is for automata. For an implementation of a simple
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   975
  regular expression matcher, whose correctness has been formally
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   976
  established, we refer the reader to Owens and Slind \cite{OwensSlind08}.
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   977
342983676c8f included comments by Chunhan
urbanc
parents: 115
diff changeset
   978
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   979
  Our formalisation consists of ??? lines of Isabelle/Isar code for the first
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   980
  direction and ??? for the second. While this might be seen as too large to
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   981
  count as a concise proof pearl, this should be seen in the context of the
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   982
  work done by Constable at al \cite{Constable00} who formalised the
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   983
  Myhill-Nerode theorem in Nuprl using automata. 
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   984
  They write that their
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   985
  four-member team needed something on the magnitute of 18 months for their
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   986
  formalisation. The estimate for our formalisation is that we
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   987
  needed approximately 3 months and this included the time to find our proof
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   988
  arguments. Unlike Constable et al, who were able to follow the proofs from
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
   989
  \cite{HopcroftUllman69}, we had to find our own arguments.  So for us the formalisation
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   990
  was not the bottleneck. It is hard to gauge the size of a formalisation in
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   991
  Nurpl, but from what is shown in the Nuprl Math Library about their
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   992
  development it seems substantially larger than ours. The code of
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   993
  ours can be found under
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   994
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   995
  \begin{center}
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   996
  ???
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   997
  \end{center}
ec774952190c polished everything
urbanc
parents: 112
diff changeset
   998
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
   999
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1000
  Our proof of the first direction is very much inspired by \emph{Brzozowski's
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1001
  algebraic mehod} used to convert a finite automaton to a regular
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1002
  expression \cite{Brzozowski64}. The close connection can be seen by considering the equivalence
111
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1003
  classes as the states of the minimal automaton for the regular language.
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
  1004
  However there are some subtle differences. Since we identify equivalence
111
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1005
  classes with the states of the automaton, then the most natural choice is to
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1006
  characterise each state with the set of strings starting from the initial
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1007
  state leading up to that state. Usually, however, the states are characterised as the
111
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1008
  ones starting from that state leading to the terminal states.  The first
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1009
  choice has consequences how the initial equational system is set up. We have
115
c5f138b5fc88 added comment from Larry
urbanc
parents: 114
diff changeset
  1010
  the $\lambda$-term on our `initial state', while Brzozowski has it on the
111
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1011
  terminal states. This means we also need to reverse the direction of Arden's
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1012
  lemma.
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
  1013
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1014
  We briefly considered using the method Brzozowski presented in the Appendix
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1015
  of~\cite{Brzozowski64} in order to prove the second direction of the
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1016
  Myhill-Nerode theorem. There he calculates the derivatives for regular
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1017
  expressions and shows that there can be only finitely many of them. We could
114
c5eb5f3065ae updated bib
urbanc
parents: 113
diff changeset
  1018
  have used as the tag of a string @{text s} the derivative of a regular expression
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1019
  generated with respect to @{text s}.  Using the fact that two strings are
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1020
  Myhill-Nerode related whenever their derivative is the same together with
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1021
  the fact that there are only finitely many derivatives for a regular
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1022
  expression would give us the same argument as ours. However it seems not so easy to
112
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1023
  calculate the derivatives and then to count them. Therefore we preferred our
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1024
  direct method of using tagging-functions involving equivalence classes. This
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1025
  is also where our method shines, because we can completely side-step the
62fdb4bf7239 more on the conclusion
urbanc
parents: 111
diff changeset
  1026
  standard argument \cite{Kozen97} where automata need to be composed, which
113
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1027
  as stated in the Introduction is not so convenient to formalise in a 
ec774952190c polished everything
urbanc
parents: 112
diff changeset
  1028
  HOL-based theorem prover.
111
d65d071798ff first ideas about conclusion
urbanc
parents: 110
diff changeset
  1029
92
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
  1030
*}
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
  1031
a9ebc410a5c8 more on paper
urbanc
parents: 90
diff changeset
  1032
24
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
  1033
(*<*)
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
  1034
end
f72c82bf59e5 added paper
urbanc
parents:
diff changeset
  1035
(*>*)